cscg22-gearboy

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

pad_ex.s (1474B)


      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        in a, (.GG_STATE)
     49        cpl
     50        and #.GGSTATE_STT
     51        ld b, a
     52        ld c, #.JOY_PORT1
     53        in e, (c)
     54        inc c
     55        in d, (c)
     56        ld a, e
     57        rla
     58        rl d
     59        rla
     60        rl d
     61        ld a, e
     62        cpl
     63        and #0b00111111
     64        or b
     65        ld e, a
     66        ld a, d
     67        cpl
     68        and #0b00111111
     69        ld d, a
     70        
     71        inc hl
     72        ld (hl), e
     73        inc hl
     74        ld (hl), d
     75        
     76        ret