-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgfxutil.asm
383 lines (355 loc) · 5.11 KB
/
gfxutil.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
;Airaki! - FSE 2014
;Released under the GPL V3, see LICENSE.TXT
clearsprites:
call wait_vbl
ld hl,$FE00 ;Empties OAM
ld b,40*4
clspr:
ld (hl),$00
inc l ;Avoids hardware bug
dec b
jr nz,clspr
ld hl,OAMCOPY
ld bc,$A0
call clear
ret
;Clears VRAM from HL to HL+BC
clear_w:
ldh a,($FF)
push af
xor a
ldh ($FF),a
-:
call wait_write
xor a
ldi (hl),a
dec bc
ld a,c
or b
jr nz,-
pop af
ldh ($FF),a
ret
;a=first tile
;bc=width/height
;hl=vram
mapinc:
ld d,a
mapinc_:
ldh a,($FF)
push af
xor a
ldh ($FF),a
push de
push hl
ld a,d
mapib:
ld d,b
mapia:
ldi (hl),a
inc a
dec d
jr nz,mapia
pop hl
ld de,32
add hl,de
push hl
dec c
jr nz,mapib
pop hl
pop de
pop af
ldh ($FF),a
ret
;a=first tile
;bc=width/height
;hl=vram
mapinc_w:
ld d,a
ldh a,($40)
bit 7,a
jr z,mapinc_
ldh a,($FF)
push af
xor a
ldh ($FF),a
ld a,d
push de
push hl
ld de,32
--:
ld d,b
-:
push af ;Is VRAM available ?
---:
ldh a,($41)
and 3
cp 3
jr nz,---
---:
ldh a,($41)
and 3
cp 3
jr z,---
pop af
ldi (hl),a
inc a
dec d
jr nz,-
pop hl
add hl,de
push hl
dec c
jr nz,--
pop hl
pop de
pop af
ldh ($FF),a
ret
;a=palette
;bc=width/height
;hl=vram
settilepal:
push de
push hl
push af
ld a,(GBCOLOR)
or a
jr z,++
ld a,1
ldh ($4F),a
pop af
ld de,32
--:
ld d,b
-:
push af
ldh a,($40)
bit 7,a
jr z,+
---:
ldh a,($41)
and 3
cp 3
jr nz,---
---:
ldh a,($41)
and 3
cp 3
jr z,---
+:
pop af
ldi (hl),a
dec d
jr nz,-
pop hl
add hl,de
push hl
dec c
jr nz,--
xor a
ldh ($4F),a
pop hl
pop de
ret
++:
pop af
pop hl
pop de
ret
;de=text
;hl=vram
;b=ASCII index (32 ?)
maptext:
ldh a,($FF)
push af
xor a
ldh ($FF),a
push hl
maptextlp:
ld a,(de)
cp $FF
jr nz,+
pop hl
pop af
ldh ($FF),a
ret
+:
cp $FE
jr nz,+
pop hl
push de
ld de,32
add hl,de
pop de
push hl
inc de
jr maptextlp
+:
sub b
push af ;Is VRAM available ?
ldh a,($40)
bit 7,a
jr z,+
---:
ldh a,($41)
and 3
cp 3
jr nz,---
---:
ldh a,($41)
and 3
cp 3
jr z,---
+:
pop af
ldi (hl),a
inc de
jr maptextlp
;a=first tile
;hl=map
;de=vram
map:
ld (MAP_FIRST),a
ldi a,(hl)
ld (MAP_W),a
ldi a,(hl)
ld c,a
push de
mapb:
ld a,(MAP_W)
ld b,a
mapa:
ldi a,(hl)
push hl
ld hl,MAP_FIRST
add (hl)
pop hl
call wait_write
ld (de),a
inc de
dec b
jr nz,mapa
pop de
ld a,e
add 32
jr nc,+
inc d
+:
ld e,a
push de
dec c
jr nz,mapb
pop de
ret
wait_vbl:
ldh a,($40)
rlca
ret nc
wait_vbll:
ldh a,($44) ;Wait for Vblank start
cp 144
jr c,wait_vbll
ret
clearbkg:
ld de,32*32 ;Clear BG map
ld hl,$9800
-:
xor a
ldi (hl),a
dec de
ld a,e
or d
jr nz,-
ld de,32*32 ;Clear window map
ld hl,$9C00
-:
xor a
ldi (hl),a
dec de
ld a,e
or d
jr nz,-
ret
writeDE:
ld a,d
swap a
and $F
call checkhex
add 16
call wait_write
ldi (hl),a
ld a,d
and $F
call checkhex
add 16
call wait_write
ldi (hl),a
ld a,e
swap a
and $F
call checkhex
add 16
call wait_write
ldi (hl),a
ld a,e
and $F
call checkhex
add 16
call wait_write
ldi (hl),a
ret
checkhex:
cp $0A
ret c
add 7
ret
wait_write:
push af
-:
ldh a,($41)
bit 1,a
jr nz,-
pop af
ret
wait_hblank:
push af
ldh a,($40)
rlca
jr c,+
pop af
ret
+:
-:
ldh a,($41)
and 3
jr z,-
-:
ldh a,($41)
and 3
jr nz,-
pop af
ret
;Copy DMA routine to HRAM
RAMtoOAM:
ld hl,doDMA
ld de,$FF80
ld b,doDMAend-doDMA
ldhram:
ldi a,(hl)
ld (de),a
inc de
dec b
jr nz,ldhram
call $FF80 ;DMA start
ret
doDMA:
ld a,$DF
ldh ($46),a ;Start DMA from $DF00
ld a,$28 ;Wait...
-:
dec a
jr nz,-
ret
doDMAend:
.INCLUDE "loadtile.asm"