;; program 1
org &8000

;; disable interrupts
di

;; unlock asic to gain access to asic registers
ld b,&bc
ld hl,sequence
ld e,17
.seq 
ld a,(hl)
out (c),a
inc hl
dec e
jr nz,seq

;; page-in asic registers
ld bc,&7fb8
out (c),c

;; set z80 interrupt mode 0
im 0

;; set 8-bit interrupt vector (bits 7..3).
;; bit 0 = automatically clear interrupts
ld a,0
ld (&6805),a

;; page-out asic registers
ld bc,&7fa8
out (c),c

;; enable interrupts
ei
;; wait for next interrupt
halt        ;; the halt instruction will wait for a interrupt-request. When this is received, the
            ;; program counter is advanced to the next instruction before the interrupt is executed.
            ;; So after "halt" has been executed, the program counter will be pointing
            ;; to the "LD D,E" instruction.
;; a "dummy" instruction
ld d,e


di          ;; disable interrupts so we can change interrupt mode safely
im 1        ;; set Z80 interrupt mode 1 (see comment for "BRK" below)
brk         ;; this is a special instruction provided by the Maxam assembler/dissassembler/monitor
            ;; when executed a dump of the register values is displayed. This instruction assembles
            ;; to a RST 30H. This instruction uses the Amstrad firmware to execute, and the Amstrad
            ;; firmware requires interrupt mode 1.

;; this is the sequence to unlock the ASIC extra features
.sequence
defb &ff,&00,&ff,&77,&b3,&51,&a8,&d4,&62,&39,&9c,&46,&2b,&15,&8a,&cd,&ee