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/sms/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         ld c, #.JOY_PORT1
     50         in e, (c)
     51         inc c
     52         in d, (c)
     53         ld a, e
     54         rla
     55         rl d
     56         rla
     57         rl d
     58         ld a, e
     59         cpl
     60         and #(.JOY_P1_UP | .JOY_P1_DOWN | .JOY_P1_LEFT | .JOY_P1_RIGHT | .JOY_P1_SW1 | .JOY_P1_SW2)
     61         ld e, a
     62         and #(.JOY_P1_SW1 | .JOY_P1_SW2)
     63         rlca
     64         rlca
     65         or e
     66         ld (hl), a              ; joypads[0] = buttons1
     67         inc hl
     68 
     69         ld a, d
     70         cpl
     71         and #(.JOY_P1_UP | .JOY_P1_DOWN | .JOY_P1_LEFT | .JOY_P1_RIGHT | .JOY_P1_SW1 | .JOY_P1_SW2)
     72         ld d, a
     73         and #(.JOY_P1_SW1 | .JOY_P1_SW2)
     74         rlca
     75         rlca
     76         or d
     77         ld (hl), a              ; joypads[1] = buttons2
     78 
     79         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.