cscg22-gearboy

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

pad_ex.s (1386B)


      1	.include	"global.s"
      2
      3	.MLT_REQ	= 0x11
      4
      5	.area	_HOME
      6
      7_joypad_init::	
      8	call	.sgb_check
      9	ld	a, e
     10	inc     e
     11	or	a
     12
     13	jr	Z, 1$
     14
     15	ldhl	sp, #0x02
     16	ld	e, (hl)
     17
     18	add	sp, #-0x10
     19	ldhl	sp, #0
     20	ld	c, #0x10
     21	xor 	a
     22	rst	0x28
     23
     24	ldhl	sp, #0
     25	ld	a, #((.MLT_REQ << 3) | 1)
     26	ld	(hl+), a
     27
     28	ld	a, e
     29
     30	cp	a, #0x02
     31	jr	Z, 3$
     32	cp	a, #0x04
     33	jr	Z, 4$
     34	jr	5$
     35
     363$:
     37	ld	a, #0x01
     38	ld	(hl-), a
     39	call	.sgb_transfer
     40	ld	e, #0x02
     41	jr	2$
     42
     434$:
     44	ld	a, #0x03
     45	ld	(hl-), a
     46	call	.sgb_transfer
     47	ld	e, #0x04
     48	jr	2$
     495$:
     50	ld	a, #0x00
     51	ld	(hl-), a
     52	call	.sgb_transfer
     53	ld	e, #0x01
     542$:
     55	add	sp, #0x10
     561$:
     57	ldhl	sp, #3
     58	ld	a, (hl+)
     59	ld	h, (hl)
     60	ld	l, a
     61	ld	a, e
     62	ld	(hl+), a
     63	xor	a
     64	ld	(hl+), a
     65	ld	(hl+), a
     66	ld	(hl+), a
     67	ld	(hl), a	
     68	ret
     69
     70_joypad_ex::
     71	lda	hl, 2(sp)
     72	ld	a, (hl+)
     73	ld	e, a
     74	ld	d, (hl)
     75
     76.joypad_ex::
     77	ld	a, (de)
     78	inc	de
     79	or	a
     80	jr	z, 2$
     81
     82	dec	a
     83	and	#3
     84	inc	a
     852$:
     86	push	bc
     87	ld	b, a
     881$:
     89	ld	a, #(.P14 | .P15)
     90	ldh	(#.P1), a
     91	ldh	a, (#.P1)
     92	ldh	a, (#.P1)
     93	ldh	a, (#.P1)
     94	ldh	a, (#.P1)
     95	and	#0x0f
     96	sub	#0x0f
     97	cpl
     98	inc	a		; A contains joypad number
     99
    100	and	#0x03		; buffer overrun protection
    101
    102	add	e		; HL = DE + A
    103	ld	l, a
    104	adc	d
    105	sub	l
    106	ld	h, a
    107
    108	ld	a, #.P15
    109	ldh	(#.P1), a
    110	ldh	a, (#.P1)
    111	ldh	a, (#.P1)
    112	and	#0x0f
    113	ld	c, a
    114	ld	a, #.P14
    115	ldh	(#.P1), a
    116	ldh	a, (#.P1)
    117	ldh	a, (#.P1)
    118	ldh	a, (#.P1)
    119	ldh	a, (#.P1)
    120	ldh	a, (#.P1)
    121	ldh	a, (#.P1)
    122	and	#0x0f
    123	swap	a
    124	or	c
    125	cpl
    126	ld	(hl), a
    127
    128	dec	b
    129	jr	nz, 1$
    130	pop	bc
    131
    132	ret