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/sm83/pad.s

      1 	.include	"global.s"
      2 
      3 	.area	_HOME
      4 
      5 	;; Wait until all buttons have been released
      6 .padup::
      7 _waitpadup::
      8 	PUSH	AF		; Save modified registers
      9 	PUSH	DE
     10 1$:
     11 	LD	D,#0x7F		; wait for .jpad return zero 127 times in a row
     12 2$:
     13 	CALL	.jpad
     14 	OR	A		; Have all buttons been released?
     15 	JR	NZ,1$		; Not yet
     16 
     17 	DEC	D
     18 	JR	NZ,2$
     19 	
     20 	POP	DE
     21 	POP	AF
     22 	RET
     23 
     24 	;; Get Keypad Button Status
     25 	;; The following bits are set if pressed:
     26 	;;   0x80 - Start   0x08 - Down
     27 	;;   0x40 - Select  0x04 - Up
     28 	;;   0x20 - B	    0x02 - Left
     29 	;;   0x10 - A	    0x01 - Right
     30 _joypad::
     31 .jpad::
     32 	LD	A,#.P15
     33 	LDH	(.P1),A		; Turn on P15
     34 
     35 	LDH	A,(.P1)		; Delay
     36 	LDH	A,(.P1)
     37 	AND	#0x0F
     38 	LD	E,A
     39 	LD	A,#.P14
     40 	LDH	(.P1),A		; Turn on P14
     41 	LDH	A,(.P1)		; Delay
     42 	LDH	A,(.P1)
     43 	LDH	A,(.P1)
     44 	LDH	A,(.P1)
     45 	LDH	A,(.P1)
     46 	LDH	A,(.P1)
     47 	AND	#0x0F
     48 	SWAP	A
     49 	OR	E
     50 	CPL
     51 	LD	E,A
     52 	LD	A,#(.P14 | .P15)
     53 	LDH	(.P1),A		; Turn off P14 and P15 (reset joypad)
     54 	LD	A,E
     55 	RET
     56 
     57 	;; Wait for the key to be pressed
     58 _waitpad::
     59 	LD	D,A
     60 	;; Wait for the key in D to be pressed
     61 .wait_pad::
     62 1$:
     63 	CALL	.jpad		; Read pad
     64 	AND	D		; Compare with mask?
     65 	JR	Z,1$		; Loop if no intersection
     66 	RET
     67 

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