-
Notifications
You must be signed in to change notification settings - Fork 2
/
snes_graphics.asm
200 lines (177 loc) · 2.19 KB
/
snes_graphics.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
; Recommended usage: call decode_snes_gfx then blocks_to_linear2.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; decodes 4bpp snes gfx to raw format.
; note that dest is double size of source.
; $00-$02: source
; $03-$05: destination
; $06-$07: size
decode_snes_gfx:
REP #$30
DEC $03
SEP #$20
LDY #$0000
.loop
PHY
LDY #$0000
.loop2
PHX
LDX #$0007
.loop3
PHY
PHX
REP #$20
INC $03
LDY #$0010
LDA [$00],y
STA $08
LDY #$0000
LDA [$00],y
STA $0A
CPX #$0000
BEQ .no_shift
.shift_loop
LSR $08
LSR $0A
DEX
BNE .shift_loop
.no_shift
LDA #$FEFE
TRB $0A
TRB $08
SEP #$20
LDA $09
ASL
ORA $08
ASL
ORA $0B
ASL
ORA $0A
STA [$03]
PLX
PLY
DEX
BPL .loop3
PLX
REP #$20
LDA $00
CLC
ADC #$0002
STA $00
SEP #$20
INY
INY
CPY #$0010
BNE .loop2
PLY
REP #$20
TYA
CLC
ADC #$0010
TAY
LDA $00
CLC
ADC #$0010
STA $00
SEP #$20
CPY $06
BNE .loop
SEP #$10
RTL
;Converts the source gfx from "tile" to "linear" format.
;$00-$02: source
;$03-$05: destination
;$06-$07: number of tiles
blocks_to_linear:
REP #$31
STZ $08
STZ $0C
.loop2
LDA $0C ;if "page bound" is out of width, then go to another page
BEQ .no_wrap
BIT #$007F
BNE .no_wrap
ADC #$0380
STA $0C
.no_wrap
STZ $0A
LDX #$003F
.loop
LDA $0A ;de interleave stuff
AND #$0007
STA $0E
LDA $0A
AND.w #~$F007
ASL #4
ORA $0E
ADC $0C
STA $0E
LDA $08
ASL #6
ADC $0A
TAY
SEP #$20
LDA [$00],y
LDY $0E
STA [$03],y
REP #$21
INC $0A
DEX
BPL .loop
LDA $0C
ADC #$0008
STA $0C
INC $08
LDA $08
CMP $06
BNE .loop2
SEP #$30
RTL
;Converts the source gfx from "tile" to "linear" format.
;$00-$02: source
;$03-$05: destination
;$06-$07: number of tiles
blocks_to_linear2:
REP #$31
STZ $08
STZ $0C
.loop2
LDA $0C ;if "page bound" is out of width, then go to another page
BEQ .no_wrap
BIT #$001F
BNE .no_wrap
ADC #$00E0
STA $0C
.no_wrap
STZ $0A
LDX #$003F
.loop
LDA $0A ;de interleave stuff
AND #$0007
STA $0E
LDA $0A
AND.w #~$C007
ASL #2
ORA $0E
ADC $0C
STA $0E
LDA $08
ASL #6
ADC $0A
TAY
SEP #$20
LDA [$00],y
LDY $0E
STA [$03],y
REP #$21
INC $0A
DEX
BPL .loop
LDA $0C
ADC #$0008
STA $0C
INC $08
LDA $08
CMP $06
BNE .loop2
SEP #$30
RTL