aboutsummaryrefslogtreecommitdiff
path: root/src/example/gb.asm
blob: ddefadbd006081909330b30dea102734939a9bb0 (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
	
	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
BGRDPAL	equ	$ff47
OBJ0PAL	equ	$ff48
OBJ1PAL	equ	$ff49
CURLINE	equ	$ff44

READY	equ	$ff81
XPOS	equ	$ff82

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

	endm


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

	di
	xor	a
	ldh	(READY),a
	ld	sp,$fffe

	; Set LCD so only sprites show
	;
	VBLANK

	ld	a,$81
	ldh	(LCDC),a
	ld	a,$10
	ldh	(STAT),a
	ld	a,$e4
	ldh	(BGRDPAL),a
	ldh	(OBJ0PAL),a
	ldh	(OBJ1PAL),a

	; Copy to VRAM
	;
	ld	hl,VRAM
	ld	de,sprite
	ld	a,16

	VBLANK

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

	ld	a,1
	ldh	(READY),a

.idle
	ei
	halt
	nop
	jr	idle

vbl_code:
	ldh	a,(READY)
	or	a
	jr	z,finish

	ldh	a,(XPOS)
	inc	a
	ldh	(XPOS),a
	ld	(OAM),a
	ld	(OAM+1),a
	xor	a
	ld	(OAM+2),a
	ld	(OAM+3),a

.finish
	reti

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