cscg22-gearboy

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

pad.s (1142B)


      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
     101$:
     11	LD	D,#0x7F		; wait for .jpad return zero 127 times in a row
     122$:
     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	LDA	HL,2(SP)	; Skip return address
     60	LD	D,(HL)
     61	;; Wait for the key in D to be pressed
     62.wait_pad::
     631$:
     64	CALL	.jpad		; Read pad
     65	AND	D		; Compare with mask?
     66	JR	Z,1$		; Loop if no intersection
     67	RET
     68