1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-27 19:18:06 +11:00

sms/pad: easily detect change in button config

This commit is contained in:
Virgil Dupras 2019-07-02 10:47:59 -04:00
parent 9eb80d5eac
commit c5a0a6ff54

View File

@ -18,12 +18,23 @@
; *** Variables *** ; *** Variables ***
; ;
; Previous result of padStatusA
.equ PAD_PREVSTAT_A PAD_RAMSTART
.equ PAD_RAMEND PAD_PREVSTAT_A+1
; *** Code *** ; *** Code ***
padInit:
ld a, 0xff
ld (PAD_PREVSTAT_A), a
ret
; Put status for port A in register A. Bits, from MSB to LSB: ; Put status for port A in register A. Bits, from MSB to LSB:
; Start - A - C - B - Right - Left - Down - Up ; Start - A - C - B - Right - Left - Down - Up
; Each bit is high when button is unpressed and low if button is pressed. For ; Each bit is high when button is unpressed and low if button is pressed. For
; example, when no button is pressed, 0xff is returned. ; example, when no button is pressed, 0xff is returned.
; Moreover, sets Z according to whether the status changed since the last call.
; Z is set if status is the same, unset if different.
padStatusA: padStatusA:
; This logic below is for the Genesis controller, which is modal. TH is ; This logic below is for the Genesis controller, which is modal. TH is
; an output pin that swiches the meaning of TL and TR. When TH is high ; an output pin that swiches the meaning of TL and TR. When TH is high
@ -44,6 +55,13 @@ padStatusA:
sla a sla a
sla a sla a
or b or b
; we're good now!
pop bc pop bc
; set Z according to whether status has change. Also, update saved
; status.
push hl
ld hl, PAD_PREVSTAT_A
cp (hl) ; Sets Z to proper value
ld (hl), a
pop hl
ret ret