summaryrefslogtreecommitdiff
path: root/engine/events/print_unown_2.asm
blob: aae80b11c6d664602fe4789327273a16669a3233 (plain)
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
RotateUnownFrontpic:
; something to do with Unown printer
	push de
	xor a ; BANK(sScratch)
	call OpenSRAM
	ld hl, sScratch
	ld bc, 0
.loop
	push bc
	push hl
	push bc
	ld de, wPrintedUnownTileSource
	call .Copy
	call .Rotate
	ld hl, UnownPrinter_GBPrinterRectangle
	pop bc
	add hl, bc
	add hl, bc
	ld a, [hli]
	ld e, a
	ld d, [hl]
	ld hl, wPrintedUnownTileDest
	call .Copy
	pop hl
	ld bc, LEN_2BPP_TILE
	add hl, bc
	pop bc
	inc c
	ld a, c
	cp 7 * 7
	jr c, .loop

	ld hl, wGameboyPrinter2bppSource
	ld de, sScratch
	ld bc, 7 * 7 tiles
	call CopyBytes
	pop hl
	ld de, sScratch
	ld c, 7 * 7
	ldh a, [hROMBank]
	ld b, a
	call Get2bpp
	call CloseSRAM
	ret

.Copy:
	ld c, LEN_2BPP_TILE
.loop_copy
	ld a, [hli]
	ld [de], a
	inc de
	dec c
	jr nz, .loop_copy
	ret

.Rotate:
	ld hl, wPrintedUnownTileDest
	ld e, %10000000
	ld d, 8
.loop_decompress
	push hl
	ld hl, wPrintedUnownTileSource
	call .CountSetBit
	pop hl
	ld a, b
	ld [hli], a
	push hl
	ld hl, wPrintedUnownTileSource + 1
	call .CountSetBit
	pop hl
	ld a, b
	ld [hli], a
	srl e
	dec d
	jr nz, .loop_decompress
	ret

.CountSetBit:
	ld b, 0
	ld c, 8
.loop_count
	ld a, [hli]
	and e
	jr z, .clear
	scf
	jr .apply

.clear
	and a

.apply
	rr b
	inc hl
	dec c
	jr nz, .loop_count
	ret

UnownPrinter_GBPrinterRectangle:
for y, 7
for x, 7 - 1, -1, -1
	dw wGameboyPrinter2bppSource tile (x * 7 + y)
endr
endr