; ; This Mailstation test app demonstrates that bit 7 of port 3 is ; associated with the power button, by enabling the "New Mail" LED ; when pressed. ; ; This code must be loaded into slot8000, and begins at #8000. You ; could probably change the ORG without a problem, however. ; ; The interrupt is being redirected using interrupt mode 2 and a jump ; table, by default going to #c1c1, but this can be changed by setting ; "interruptbytes" to a value you assume will never be changed. Both ; bytes MUST be identical or it won't work. The contents of the ; "interruptjump" function below are copied to this location, which ; by default, is just a three byte sequence of a JP instruction ; pointing to "interruptroutine". ; ; IMPORTANT: This must be assembled with optimizations disabled, ; otherwise the JP at "interruptjump" will be "optimized" into a JR, ; and break everything. ; ; The interrupt routine has been stripped down, but will still ac- ; knowledge each interrupt individually. Only interrupt 7 is enabled ; in the interrupt mask however, so this should be the only one that ; triggers. When triggered, it enables the LED. ; ; The port 2 and 3 shadow bytes used here are for the v3.03a firmware. ; They are NOT the same in other firmware versions. For the more common ; v2.53 firmware, they're: ; ; p2shadow equ #dba1 ; p3shadow equ #dba2 ; ; You should change them accordingly. I'm unaware of the locations for ; other versions of the firmware. ; ; - FyberOptic (fyberoptic@gmail.com) ; p2shadow equ #dba5 p3shadow equ #dba6 interruptbytes equ #c1c1 ; somewhere in the lcd buffer ;------------------------------------------------------------------------------ ;-CODE------------------------------------------------------------------------- ;------------------------------------------------------------------------------ code org #8000 di xor a ; clear interrupt mask set 7, a ; except interrupt 7 ld (p3shadow), a out (#03), a ; copy interruptjump into memory at interruptbytes ld hl, interruptjump ld de, interruptbytes ld bc, interruptjump_end - interruptjump + 1 ldir ; setup interrupt mode 2 ld hl, interrupttable ld a, h ld i, a im 2 ei ; endless loop jp $ ;------------------------------------------------------------------------------ interruptroutine: push af push bc push de push hl push ix push iy in a, (#03) bit 4, a jp nz, interrupt_time16 bit 1, a jp nz, interrupt_keyboard bit 0, a jr nz, interrupt_0 bit 2, a jr nz, interrupt_2 bit 3, a jr nz, interrupt_3 bit 5, a jr nz, interrupt_5 bit 6, a jr nz, interrupt_6 bit 7, a jr nz, interrupt_7 jp interrupt_end interrupt_0: ld a, (p3shadow) res 0, a out (#03), a ld a, (p3shadow) out (#03), a jp interrupt_end interrupt_2: ; triggers when a key is pressed ld a, (p3shadow) res 2, a out (#03), a ld a, (p3shadow) out (#03), a jr interrupt_end interrupt_3: ld a, (p3shadow) res 3, a out (#03), a ld a, (p3shadow) out (#03), a jr interrupt_end interrupt_5: ld a, (p3shadow) res 5, a out (#03), a ld a, (p3shadow) out (#03), a jr interrupt_end interrupt_6: ld a, (p3shadow) res 6, a out (#03), a ld a, (p3shadow) out (#03), a jr interrupt_end interrupt_7: ; power button (unbounced) ld a, (p3shadow) res 7, a out (#03), a ld a, (p2shadow) ; enable LED set 4, a ld (p2shadow), a out (#02), a ld a, (p3shadow) out (#03), a jr interrupt_end interrupt_time16: ld a, (p3shadow) res 4, a out (#03), a ld a, (p3shadow) out (#03), a jr interrupt_end interrupt_keyboard: ld a, (p3shadow) res 1, a out (#03), a ld a, (p3shadow) out (#03), a jr interrupt_end interrupt_end: pop iy pop ix pop hl pop de pop bc pop af ei reti ;------------------------------------------------------------------------------ interruptjump: jp interruptroutine interruptjump_end: ;------------------------------------------------------------------------------ ;-DATA------------------------------------------------------------------------- ;------------------------------------------------------------------------------ align 256 interrupttable: dw interruptbytes, interruptbytes, interruptbytes, interruptbytes dw interruptbytes, interruptbytes, interruptbytes, interruptbytes dw interruptbytes, interruptbytes, interruptbytes, interruptbytes dw interruptbytes, interruptbytes, interruptbytes, interruptbytes dw interruptbytes, interruptbytes, interruptbytes, interruptbytes dw interruptbytes, interruptbytes, interruptbytes, interruptbytes dw interruptbytes, interruptbytes, interruptbytes, interruptbytes dw interruptbytes, interruptbytes, interruptbytes, interruptbytes dw interruptbytes, interruptbytes, interruptbytes, interruptbytes dw interruptbytes, interruptbytes, interruptbytes, interruptbytes dw interruptbytes, interruptbytes, interruptbytes, interruptbytes dw interruptbytes, interruptbytes, interruptbytes, interruptbytes dw interruptbytes, interruptbytes, interruptbytes, interruptbytes dw interruptbytes, interruptbytes, interruptbytes, interruptbytes dw interruptbytes, interruptbytes, interruptbytes, interruptbytes dw interruptbytes, interruptbytes, interruptbytes, interruptbytes dw interruptbytes, interruptbytes, interruptbytes, interruptbytes dw interruptbytes, interruptbytes, interruptbytes, interruptbytes dw interruptbytes, interruptbytes, interruptbytes, interruptbytes dw interruptbytes, interruptbytes, interruptbytes, interruptbytes dw interruptbytes, interruptbytes, interruptbytes, interruptbytes dw interruptbytes, interruptbytes, interruptbytes, interruptbytes dw interruptbytes, interruptbytes, interruptbytes, interruptbytes dw interruptbytes, interruptbytes, interruptbytes, interruptbytes dw interruptbytes, interruptbytes, interruptbytes, interruptbytes dw interruptbytes, interruptbytes, interruptbytes, interruptbytes dw interruptbytes, interruptbytes, interruptbytes, interruptbytes dw interruptbytes, interruptbytes, interruptbytes, interruptbytes dw interruptbytes, interruptbytes, interruptbytes, interruptbytes dw interruptbytes, interruptbytes, interruptbytes, interruptbytes dw interruptbytes, interruptbytes, interruptbytes, interruptbytes dw interruptbytes, interruptbytes, interruptbytes, interruptbytes dw interruptbytes, interruptbytes, interruptbytes, interruptbytes dw interruptbytes, interruptbytes, interruptbytes, interruptbytes