Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pret
GitHub Repository: pret/pokered
Path: blob/master/home/pics.asm
1270 views
1
; uncompresses the front or back sprite of the specified mon
2
; assumes the corresponding mon header is already loaded
3
; hl contains offset to sprite pointer ($b for front or $d for back)
4
UncompressMonSprite::
5
ld bc, wMonHeader
6
add hl, bc
7
ld a, [hli]
8
ld [wSpriteInputPtr], a ; fetch sprite input pointer
9
ld a, [hl]
10
ld [wSpriteInputPtr+1], a
11
; define (by index number) the bank that a pokemon's image is in
12
; index = MEW: bank $1
13
; index = FOSSIL_KABUTOPS: bank $B
14
; index < $1F: bank $9 ("Pics 1")
15
; $1F index < $4A: bank $A ("Pics 2")
16
; $4A index < $74: bank $B ("Pics 3")
17
; $74 index < $99: bank $C ("Pics 4")
18
; $99 index: bank $D ("Pics 5")
19
ld a, [wCurPartySpecies]
20
ld b, a
21
cp MEW
22
ld a, BANK(MewPicFront)
23
jr z, .GotBank
24
ld a, b
25
cp FOSSIL_KABUTOPS
26
ld a, BANK(FossilKabutopsPic)
27
jr z, .GotBank
28
ld a, b
29
cp TANGELA + 1
30
ld a, BANK("Pics 1")
31
jr c, .GotBank
32
ld a, b
33
cp MOLTRES + 1
34
ld a, BANK("Pics 2")
35
jr c, .GotBank
36
ld a, b
37
cp BEEDRILL + 2
38
ld a, BANK("Pics 3")
39
jr c, .GotBank
40
ld a, b
41
cp STARMIE + 1
42
ld a, BANK("Pics 4")
43
jr c, .GotBank
44
ld a, BANK("Pics 5")
45
.GotBank
46
jp UncompressSpriteData
47
48
; de: destination location
49
LoadMonFrontSprite::
50
push de
51
ld hl, wMonHFrontSprite - wMonHeader
52
call UncompressMonSprite
53
ld hl, wMonHSpriteDim
54
ld a, [hli]
55
ld c, a
56
pop de
57
; fall through
58
59
; postprocesses uncompressed sprite chunks to a 2bpp sprite and loads it into video ram
60
; calculates alignment parameters to place both sprite chunks in the center of the 7*7 tile sprite buffers
61
; de: destination location
62
; a,c: sprite dimensions (in tiles of 8x8 each)
63
LoadUncompressedSpriteData::
64
push de
65
and $f
66
ldh [hSpriteWidth], a ; each byte contains 8 pixels (in 1bpp), so tiles=bytes for width
67
ld b, a
68
ld a, $7
69
sub b ; 7-w
70
inc a ; 8-w
71
srl a ; (8-w)/2 ; horizontal center (in tiles, rounded up)
72
ld b, a
73
add a
74
add a
75
add a
76
sub b ; 7*((8-w)/2) ; skip for horizontal center (in tiles)
77
ldh [hSpriteOffset], a
78
ld a, c
79
swap a
80
and $f
81
ld b, a
82
add a
83
add a
84
add a ; 8*tiles is height in bytes
85
ldh [hSpriteHeight], a
86
ld a, $7
87
sub b ; 7-h ; skip for vertical center (in tiles, relative to current column)
88
ld b, a
89
ldh a, [hSpriteOffset]
90
add b ; 7*((8-w)/2) + 7-h ; combined overall offset (in tiles)
91
add a
92
add a
93
add a ; 8*(7*((8-w)/2) + 7-h) ; combined overall offset (in bytes)
94
ldh [hSpriteOffset], a
95
xor a
96
ld [rRAMB], a
97
ld hl, sSpriteBuffer0
98
call ZeroSpriteBuffer ; zero buffer 0
99
ld de, sSpriteBuffer1
100
ld hl, sSpriteBuffer0
101
call AlignSpriteDataCentered ; copy and align buffer 1 to 0 (containing the MSB of the 2bpp sprite)
102
ld hl, sSpriteBuffer1
103
call ZeroSpriteBuffer ; zero buffer 1
104
ld de, sSpriteBuffer2
105
ld hl, sSpriteBuffer1
106
call AlignSpriteDataCentered ; copy and align buffer 2 to 1 (containing the LSB of the 2bpp sprite)
107
pop de
108
jp InterlaceMergeSpriteBuffers
109
110
; copies and aligns the sprite data properly inside the sprite buffer
111
; sprite buffers are 7*7 tiles in size, the loaded sprite is centered within this area
112
AlignSpriteDataCentered::
113
ldh a, [hSpriteOffset]
114
ld b, $0
115
ld c, a
116
add hl, bc
117
ldh a, [hSpriteWidth]
118
.columnLoop
119
push af
120
push hl
121
ldh a, [hSpriteHeight]
122
ld c, a
123
.columnInnerLoop
124
ld a, [de]
125
inc de
126
ld [hli], a
127
dec c
128
jr nz, .columnInnerLoop
129
pop hl
130
ld bc, 7*8 ; 7 tiles
131
add hl, bc ; advance one full column
132
pop af
133
dec a
134
jr nz, .columnLoop
135
ret
136
137
; fills the sprite buffer (pointed to in hl) with zeros
138
ZeroSpriteBuffer::
139
ld bc, SPRITEBUFFERSIZE
140
.nextByteLoop
141
xor a
142
ld [hli], a
143
dec bc
144
ld a, b
145
or c
146
jr nz, .nextByteLoop
147
ret
148
149
; combines the (7*7 tiles, 1bpp) sprite chunks in buffer 0 and 1 into a 2bpp sprite located in buffer 1 through 2
150
; in the resulting sprite, the rows of the two source sprites are interlaced
151
; de: output address
152
InterlaceMergeSpriteBuffers::
153
xor a
154
ld [rRAMB], a
155
push de
156
ld hl, sSpriteBuffer2 + (SPRITEBUFFERSIZE - 1) ; destination: end of buffer 2
157
ld de, sSpriteBuffer1 + (SPRITEBUFFERSIZE - 1) ; source 2: end of buffer 1
158
ld bc, sSpriteBuffer0 + (SPRITEBUFFERSIZE - 1) ; source 1: end of buffer 0
159
ld a, SPRITEBUFFERSIZE/2 ; $c4
160
ldh [hSpriteInterlaceCounter], a
161
.interlaceLoop
162
ld a, [de]
163
dec de
164
ld [hld], a ; write byte of source 2
165
ld a, [bc]
166
dec bc
167
ld [hld], a ; write byte of source 1
168
ld a, [de]
169
dec de
170
ld [hld], a ; write byte of source 2
171
ld a, [bc]
172
dec bc
173
ld [hld], a ; write byte of source 1
174
ldh a, [hSpriteInterlaceCounter]
175
dec a
176
ldh [hSpriteInterlaceCounter], a
177
jr nz, .interlaceLoop
178
ld a, [wSpriteFlipped]
179
and a
180
jr z, .notFlipped
181
ld bc, 2*SPRITEBUFFERSIZE
182
ld hl, sSpriteBuffer1
183
.swapLoop
184
swap [hl] ; if flipped swap nybbles in all bytes
185
inc hl
186
dec bc
187
ld a, b
188
or c
189
jr nz, .swapLoop
190
.notFlipped
191
pop hl
192
ld de, sSpriteBuffer1
193
ld c, (2*SPRITEBUFFERSIZE)/16 ; $31, number of 16 byte chunks to be copied
194
ldh a, [hLoadedROMBank]
195
ld b, a
196
jp CopyVideoData
197
198