aboutsummaryrefslogtreecommitdiff
path: root/src/example/gb.asm
blob: 2f52e0e8e596ce273f8442a971a64fda0110d0d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
	;
	; This example is poor, and leaves lots of junk lymg in memory.
	; Still, it works enough to test
	;
	
	cpu	gameboy

	option	output-file,gb.gb
	option	output-format,gameboy

	option	gameboy-irq,vbl,vbl_code

VRAM	equ	$8000
SCRN	equ	$9800
OAM	equ	$fe00
LCDC	equ	$ff40
STAT	equ	$ff41
ISWITCH	equ	$ffff
BGRDPAL	equ	$ff47
OBJ0PAL	equ	$ff48
OBJ1PAL	equ	$ff49
CURLINE	equ	$ff44

XPOS	equ	$ff82

VBLANK	macro
	push	af
.wait
	ldh	a,(CURLINE)
	cp	144
	jr	nz,wait

	pop	af

	endm


	;
	; **********
	; CODE START
	; **********
	;
	org	$150

	di
	ld	sp,$fffe

	; Switch of display during setup
	;
	VBLANK
	xor	a
	ld	(LCDC),a

	ld	(XPOS),a

	ld	a,$e4
	ldh	(OBJ0PAL),a
	ldh	(OBJ1PAL),a

	swap	a
	ldh	(BGRDPAL),a

	; Copy to VRAM and set up
	;
	ld	hl,VRAM
	ld	de,sprite
	ld	c,16

.copy
	ld	a,(de)
	ld	(hl+),a
	inc	de
	dec	c
	jr	nz,copy


	; Set sprite numbers
	;
	xor	a
	ld	(OAM+2),a
	ld	(OAM+6),a
	ld	(OAM+10),a

	; Set sprite flags
	;
	ld	a,$80
	ld	(OAM+3),a
	ld	(OAM+7),a
	ld	(OAM+11),a

	; Set LCD back on
	;
	ld	a,$83
	ldh	(LCDC),a

	; Activate VBL
	;
	ld	a,1
	ldh	(ISWITCH),a

	ei

.idle
	halt
	nop
	jr	idle

vbl_code:
	ldh	a,(XPOS)
	inc	a
	ldh	(XPOS),a

	ld	(OAM),a
	ld	(OAM+1),a

	add	20
	ld	(OAM+4),a
	ld	(OAM+5),a

	add	33
	ld	(OAM+8),a
	ld	(OAM+9),a

	reti

sprite:
	defb	$ff,$ff
	defb	$00,00
	defb	$ff,$ff
	defb	$00,00
	defb	$ff,$ff
	defb	$00,00
	defb	$ff,$ff
	defb	$00,00
	defb	$ff,$ff
	defb	$00,00

	;
	; Assembly checks
	;
	stop
	swap	a
	swap	b
	swap	c
	swap	d
	swap	e
	swap	h
	swap	l
	swap	(hl)
	ld	a,(hl+)
	ld	a,(hli)
	ldi	a,(hl)
	ld	a,(hl-)
	ld	a,(hld)
	ldd	a,(hl)