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.s

      1         .include        "global.s"
      2 
      3         .title  "JOYPad utilities"
      4         .module JOYPad
      5         .area   _HOME
      6 
      7 ; Get Keypad Button Status
      8 ; return result in l
      9 ;
     10 ;uint8_t joypad(void) OLDCALL PRESERVES_REGS(b, c, d, e, iyh, iyl);
     11 _joypad::
     12 .jpad::
     13         in a, (.JOY_PORT1)
     14         cpl
     15         and #(.JOY_P1_UP | .JOY_P1_DOWN | .JOY_P1_LEFT | .JOY_P1_RIGHT | .JOY_P1_SW1 | .JOY_P1_SW2)
     16         ld l, a
     17         and #.JOY_P1_SW2
     18         rlca
     19         rlca
     20         or l            ; .SELECT = .JOY_P1_SW2
     21         ld l, a
     22         in a, (.GG_STATE)
     23         cpl
     24         and #.GGSTATE_STT
     25         rrca
     26         or l            ; .START = .GGSTATE_STT
     27         ld l, a
     28         ret
     29 
     30 ; Wait until all buttons have been released
     31 ;
     32 ; void waitpadup(void) PRESERVES_REGS(d, e, iyh, iyl);
     33 .padup::
     34 _waitpadup::
     35 1$:
     36         ld c, #0x7f     ; wait for .jpad return zero 127 times in a row
     37 2$:
     38         call .jpad
     39         or a            ; have all buttons been released?
     40         jr nz, 1$       ; not yet
     41 
     42         dec c
     43         jr nz, 2$
     44 
     45         ret
     46 
     47 ; Wait for the key to be pressed
     48 ;
     49 ; uint8_t waitpad(uint8_t mask) Z88DK_FASTCALL PRESERVES_REGS(d, e, iyh, iyl);
     50 _waitpad::
     51 .wait_pad::
     52         ld c, l
     53 1$:
     54         call .jpad      ; read pad
     55         and c           ; compare with mask?
     56         jr z, 1$        ; loop if no intersection
     57         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.