git.y1.nz

gbdk-2020

GameBoy Development Kit
download: https://git.y1.nz/archives/gbdk.tar.gz
README | Files | Log | Refs | LICENSE

gbdk-lib/libc/targets/z80/gg/pad_ex.s

      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$
     16 1$:
     17         cp #(.JOYPAD_COUNT + 1)
     18         jr c, 2$
     19         ld a, #.JOYPAD_COUNT
     20 2$:
     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         inc hl                  ; hl = joypads[]
     49         in a, (.GG_STATE)
     50         cpl
     51         and #.GGSTATE_STT
     52         rrca                    ; .START = .GGSTATE_STT
     53         ld b, a
     54         ld c, #.JOY_PORT1
     55         in e, (c)
     56         inc c
     57         in d, (c)
     58         ld a, e
     59         rla
     60         rl d
     61         rla
     62         rl d
     63         ld a, e
     64         cpl
     65         and #(.JOY_P1_UP | .JOY_P1_DOWN | .JOY_P1_LEFT | .JOY_P1_RIGHT | .JOY_P1_SW1 | .JOY_P1_SW2)
     66         ld e, a
     67         and #.JOY_P1_SW2
     68         rlca
     69         rlca
     70         or e
     71         or b
     72         ld (hl), a              ; joypads[0] = buttons1
     73         inc hl
     74 
     75         ld a, d
     76         cpl
     77         and #(.JOY_P1_UP | .JOY_P1_DOWN | .JOY_P1_LEFT | .JOY_P1_RIGHT | .JOY_P1_SW1 | .JOY_P1_SW2)
     78         ld d, a
     79         and #(.JOY_P1_SW1 | .JOY_P1_SW2)
     80         rlca
     81         rlca
     82         or d
     83         ld (hl), a              ; joypads[1] = buttons2
     84 
     85         ret

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.