cscg22-gearboy

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

pad_ex.s (1381B)


      1        .include        "global.s"
      2
      3        .title  "JOYPad utilities"
      4        .module JOYPad
      5        .area   _HOME
      6
      7; uint8_t joypad_init(uint8_t npads, joypads_t * joypads) __z88dk_callee;
      8_joypad_init::
      9        ld hl, #2
     10        add hl, sp
     11        ld a, (hl)
     12        or a
     13        jr nz, 1$
     14        ld a, #1
     15        jr 2$
     161$:
     17        cp #(.JOYPAD_COUNT + 1)
     18        jr c, 2$
     19        ld a, #.JOYPAD_COUNT
     202$:
     21        inc hl
     22        ld e, (hl)
     23        inc hl
     24        ld d, (hl)
     25        
     26        inc hl
     27        pop bc          ; pop return address
     28        ld sp, hl       ; dispose params
     29        push bc         ; push return address back 
     30        
     31        ld (de), a      ; number of joypads
     32        ld l, a         ; return number of joypads in l
     33        xor a
     34        inc de
     35        ld (de), a        
     36        inc de
     37        ld (de), a        
     38        inc de
     39        ld (de), a        
     40        inc de
     41        ld (de), a
     42
     43        ret
     44
     45;void joypad_ex(joypads_t * joypads) __z88dk_fastcall;
     46
     47_joypad_ex::
     48        ld c, #.JOY_PORT1
     49        in e, (c)
     50        inc c
     51        in d, (c)
     52        ld a, e
     53        rla
     54        rl d
     55        rla
     56        rl d
     57        ld a, e
     58        cpl
     59        and #0b00111111
     60        ld e, a
     61        ld a, d
     62        cpl
     63        and #0b01111111
     64        ld d, a
     65        
     66        inc hl
     67        ld (hl), e
     68        inc hl
     69        ld (hl), d
     70        
     71        ret