Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pret
GitHub Repository: pret/pokered
Path: blob/master/engine/battle/scale_sprites.asm
1271 views
1
; scales both uncompressed sprite chunks by two in every dimension (creating 2x2 output pixels per input pixel)
2
; assumes that input sprite chunks are 4x4 tiles, and the rightmost and bottommost 4 pixels will be ignored
3
; resulting in a 7*7 tile output sprite chunk
4
ScaleSpriteByTwo:
5
ld de, sSpriteBuffer1 + (4*4*8) - 5 ; last byte of input data, last 4 rows already skipped
6
ld hl, sSpriteBuffer0 + SPRITEBUFFERSIZE - 1 ; end of destination buffer
7
call ScaleLastSpriteColumnByTwo ; last tile column is special case
8
call ScaleFirstThreeSpriteColumnsByTwo ; scale first 3 tile columns
9
ld de, sSpriteBuffer2 + (4*4*8) - 5 ; last byte of input data, last 4 rows already skipped
10
ld hl, sSpriteBuffer1 + SPRITEBUFFERSIZE - 1 ; end of destination buffer
11
call ScaleLastSpriteColumnByTwo ; last tile column is special case
12
13
ScaleFirstThreeSpriteColumnsByTwo:
14
ld b, $3 ; 3 tile columns
15
.columnLoop
16
ld c, 4*8 - 4 ; $1c, 4 tiles minus 4 unused rows
17
.columnInnerLoop
18
push bc
19
ld a, [de]
20
ld bc, -(7*8)+1 ; -$37, scale lower nybble and seek to previous output column
21
call ScalePixelsByTwo
22
ld a, [de]
23
dec de
24
swap a
25
ld bc, 7*8+1-2 ; $37, scale upper nybble and seek back to current output column and to the next 2 rows
26
call ScalePixelsByTwo
27
pop bc
28
dec c
29
jr nz, .columnInnerLoop
30
dec de
31
dec de
32
dec de
33
dec de
34
ld a, b
35
ld bc, -7*8 ; -$38, skip one output column (which has already been written along with the current one)
36
add hl, bc
37
ld b, a
38
dec b
39
jr nz, .columnLoop
40
ret
41
42
ScaleLastSpriteColumnByTwo:
43
ld a, 4*8 - 4 ; $1c, 4 tiles minus 4 unused rows
44
ldh [hSpriteInterlaceCounter], a
45
ld bc, -1
46
.columnInnerLoop
47
ld a, [de]
48
dec de
49
swap a ; only high nybble contains information
50
call ScalePixelsByTwo
51
ldh a, [hSpriteInterlaceCounter]
52
dec a
53
ldh [hSpriteInterlaceCounter], a
54
jr nz, .columnInnerLoop
55
dec de ; skip last 4 rows of new column
56
dec de
57
dec de
58
dec de
59
ret
60
61
; scales the given 4 bits in a (4x1 pixels) to 2 output bytes (8x2 pixels)
62
; hl: destination pointer
63
; bc: destination pointer offset (added after the two bytes have been written)
64
ScalePixelsByTwo:
65
push hl
66
and $f
67
ld hl, DuplicateBitsTable
68
add l
69
ld l, a
70
jr nc, .noCarry
71
inc h
72
.noCarry
73
ld a, [hl]
74
pop hl
75
ld [hld], a ; write output byte twice to make it 2 pixels high
76
ld [hl], a
77
add hl, bc ; add offset
78
ret
79
80
; repeats each input bit twice, e.g. DuplicateBitsTable[%0101] = %00110011
81
DuplicateBitsTable:
82
FOR n, 16
83
db (n & 1) * 3 + (n & 2) * 6 + (n & 4) * 12 + (n & 8) * 24
84
ENDR
85
86