-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.asm
164 lines (140 loc) · 2.35 KB
/
main.asm
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
156
157
158
159
160
161
162
163
164
; Sprite Objects Library example.
INCLUDE "hardware.inc"
SECTION "VBlank Vector", ROM0[$40]
push af
push bc
push de
push hl
jp VBlankHandler
SECTION "Entry", ROM0[$100]
jp Init
ds $150 - @
SECTION "Main", ROM0
Init:
; Wait for VBlank
ld a, [rLY]
cp a, 144
jr c, Init
; Disable screen
xor a, a
ld [rLCDC], a
; Set palettes
ld a, %11100100
ldh [rBGP], a
ldh [rOBP0], a
ldh [rOBP1], a
; Initilize Sprite Object Library.
call InitSprObjLib
; Reset hardware OAM
xor a, a
ld b, 160
ld hl, _OAMRAM
.resetOAM
ld [hli], a
dec b
jr nz, .resetOAM
; Copy Graphics
ld bc, GfxCat.end - GfxCat
ld de, GfxCat
ld hl, $8000
call MemCopy
; Reset Positions
ld c, 4
ld hl, wSimplePosition
xor a, a
: ld [hli], a
dec c
jr nz, :-
; Enable VBlank interrupt
ld a, IEF_VBLANK
ldh [rIE], a
; Clear pending interrupts
xor a, a
ldh [rIF], a
; Enable screen
ld a, LCDCF_BGON | LCDCF_OBJON | LCDCF_OBJ8 | LCDCF_ON
ldh [rLCDC], a
ei
Main:
call ResetShadowOAM
ld de, $0000
ld a, [wSimplePosition]
ld c, a
ld b, 0
call RenderSimpleSprite
sla c
ld b, 16
call RenderSimpleSprite
sla c
ld b, 32
call RenderSimpleSprite
sla c
ld b, 48
call RenderSimpleSprite
ld bc, (96.0 >> 12) & $FFFF
ld a, [wMetaspritePosition]
ld e, a
ld a, [wMetaspritePosition + 1]
ld d, a
ld hl, CatMetasprite
call RenderMetasprite
ld hl, wSimplePosition
inc [hl]
ld hl, wMetaspriteVelocity
inc [hl]
ld a, (2.0 >> 12) & $FF
cp a, [hl]
jr nz, .skip
ld [hl], 0
.skip
ld a, [wMetaspritePosition]
add a, [hl]
ld [wMetaspritePosition], a
ld a, [wMetaspritePosition + 1]
adc a, 0
ld [wMetaspritePosition + 1], a
halt
jr Main
MemCopy::
dec bc
inc b
inc c
.loop:
ld a, [de]
ld [hli], a
inc de
dec c
jr nz, .loop
dec b
jr nz, .loop
ret
SECTION "VBlank Handler", ROM0
VBlankHandler:
; Push sprites to OAM
ld a, HIGH(wShadowOAM)
call hOAMDMA
pop hl
pop de
pop bc
pop af
reti
SECTION "Graphics", ROM0
GfxCat:
INCBIN "cat.2bpp"
.end::
CatMetasprite:
db 16, 8, 0, 0
db 12, 16, 0, 0
db 20, 20, 0, 0
db 24, 12, 0, 0
db 128
SECTION "Position Vars", WRAM0
; 8-bit X position
wSimplePosition:
ds 1
; Q12.4 fixed-point X posiition
wMetaspritePosition:
dw
; Q4.4 fixed-point velocity
wMetaspriteVelocity::
db