cscg22-gearboy

CSCG 2022 Challenge 'Gearboy'
git clone https://git.sinitax.com/sinitax/cscg22-gearboy
Log | Files | Refs | sfeed.txt

pad.s (1378B)


      1        .include        "global.s"
      2
      3        .title  "JOYPad utilities"
      4        .module JOYPad
      5        .area   _HOME
      6
      7	;; Get Keypad Button Status
      8_joypad::
      9.jpad::
     10        ld a, #0x06     ; ... <code> <caps> <graph> <ctrl> <shift>
     11        out (.KBD_SELECT_ROW), a
     12        in a, (.KBD_INPUT)
     13        cpl
     14
     15        rrca
     16        rl l
     17        rrca
     18        rrca
     19        rl l            ; shift graph
     20
     21        ld a, #0x07     ; <ret>, ...
     22        out (.KBD_SELECT_ROW), a
     23        in a, (.KBD_INPUT)
     24        cpl
     25
     26        rlca
     27        rl l
     28        rl l
     29        ld a, #0b00001110
     30        and l
     31        ld l, a
     32
     33        ld a, #0x08     ; <r><d><u><l><del><ins><home><space>
     34        out (.KBD_SELECT_ROW), a
     35        in a, (.KBD_INPUT)
     36        cpl
     37        and #0b11110001
     38
     39        or l
     40        ld l, a         ; <r><d><u><l><shift><graph><enter><space>
     41
     42        ret
     43
     44	;; Wait until all buttons have been released
     45.padup::
     46_waitpadup::
     471$:
     48        ld h,#0x7f      ; wait for .jpad return zero 127 times in a row
     492$:
     50        call .jpad
     51        or a            ; have all buttons been released?
     52        jr nz,1$        ; not yet
     53
     54        dec h
     55        jr nz,2$
     56        
     57        ret
     58
     59        ;; Wait for the key to be pressed
     60_waitpad::
     61.wait_pad::
     621$:
     63        call .jpad      ; read pad
     64        and l           ; compare with mask?
     65        jr z,1$         ; loop if no intersection
     66        ret