cscg22-gearboy

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

cgb_palettes.s (1087B)


      1	.include	"global.s"
      2
      3	.title	"CGB support"
      4	.module	CGB
      5
      6	.area	_CODE
      7
      8_set_sprite_palette::		; Non-banked
      9	PUSH	BC
     10	LD	C,#.OCPS
     11	JR	.set_palette
     12
     13_set_bkg_palette::		; Non-banked
     14	PUSH	BC
     15	LD	C,#.BCPS
     16
     17.set_palette::
     18	LDA	HL,4(SP)	; Skip return address and registers
     19	LD	A,(HL+)		; first_palette
     20	ADD	A		; A *= 8
     21	ADD	A
     22	ADD	A
     23	OR	#0x80		; Set auto-increment
     24	LDH	(C),A
     25	INC	C
     26	LD	A,(HL+)		; D = nb_palettes
     27	ADD	A		; A *= 8
     28	ADD	A
     29	ADD	A
     30	LD	B,A		; Number of bytes
     31	LD	A,(HL+)		; rgb_data
     32	LD	H,(HL)
     33	LD	L,A
     341$:	
     35	WAIT_STAT
     36
     37	LD	A,(HL+)
     38	LDH	(C),A
     39	DEC	B
     40	JR	NZ,1$
     41
     42	POP	BC
     43	RET
     44
     45_set_sprite_palette_entry::	; Banked
     46	PUSH	BC
     47	LD	C,#.OCPS
     48	JR	.set_palette_entry
     49
     50_set_bkg_palette_entry::	; Banked
     51	PUSH	BC
     52	LD	C,#.BCPS
     53
     54.set_palette_entry::
     55	LDA	HL,4(SP); Skip return address and registers
     56	LD	A,(HL+)		; first_palette
     57	ADD	A		; A *= 4
     58	ADD	A
     59	LD	B,A
     60	LD	A,(HL+)		; pal_entry
     61	ADD	B		; A += first_palette * 4
     62	ADD	A		; A *= 2
     63	OR	#0x80		; Set auto-increment
     64	LDH	(C),A
     65	INC	C
     66	LD	A,(HL+)		; rgb_data
     67	LD	H,(HL)
     68	LD	L,A
     69
     70	WAIT_STAT
     71
     72	LD	A,L
     73	LDH	(C),A
     74	LD	A,H
     75	LDH	(C),A
     76
     77	POP	BC
     78	RET