-
Notifications
You must be signed in to change notification settings - Fork 0
/
gfxutil.asm
122 lines (116 loc) · 1.83 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
clear_sprites:
call wait_vbl
ld hl,$FE00 ; Empties OAM
ld b,40*4
-:
ld (hl),$00
inc l ; Avoids hardware bug
dec b
jr nz,-
ret
; HL = data address
; DE = VRAM address
load_tiles:
; BP0
push de
call decompress
pop de
inc de
; BP1
jr decompress ; call + ret
decompress:
ldi a,(hl)
or a
ret z ; End of data
bit 7,a ; "Compressed" flag
jr nz,compressed
and $7F ; Clear flag
ld b,a
-:
ldi a,(hl)
ld (de),a
inc de ; Skip a bitplane (loaded later)
inc de
dec b
jr nz,-
jr decompress
compressed:
and $7F ; Clear flag
ld b,a
ldi a,(hl)
-:
ld (de),a
inc de ; Skip a bitplane (loaded later)
inc de
dec b
jr nz,-
jr decompress
; A = First tile
; BC = Width/Height
; HL = VRAM address
map_inc:
ld d,a
ldh a,($FF)
push af
xor a
ldh ($FF),a
push de
push hl
ld a,d
--:
ld d,b
-:
ldi (hl),a
inc a
dec d
jr nz,-
pop hl
ld de,32
add hl,de
push hl
dec c
jr nz,--
pop hl
pop de
pop af
ldh ($FF),a
ret
wait_vbl:
ldh a,($40) ; Screen disabled ?
rlca
ret nc
-:
ldh a,($44) ; Wait for v-blank end
cp 144
jr nc,-
-:
ldh a,($44) ; Wait for v-blank start
cp 144
jr c,-
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