-
Notifications
You must be signed in to change notification settings - Fork 6
/
tiles.acme
350 lines (300 loc) · 7.27 KB
/
tiles.acme
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
!macro copy_tile_char .char {
ldy #0
lda TILE_CLR+(.char*TILES), x
sta (CLR_POS_LO_T), y
lda TILE_SCR+(.char*TILES), x
sta (SCR_POS_LO_T), y
lda #ALL_RAM
sta RAM_ROM_SELECTION
!for .row, 0, 7 {
lda TILE_PIX+(.char*8*TILES)+(.row*TILES), x
sta (PIX_POS_LO_T), y
!if .row != 7 {
iny
}
}
lda #ALL_RAM_WITH_IO
sta RAM_ROM_SELECTION
rts
}
copy_tile_char0 !zone { +copy_tile_char 0 }
copy_tile_char1 !zone { +copy_tile_char 1 }
copy_tile_char2 !zone { +copy_tile_char 2 }
copy_tile_char3 !zone { +copy_tile_char 3 }
copy_tile_char4 !zone { +copy_tile_char 4 }
copy_tile_char5 !zone { +copy_tile_char 5 }
!macro iterate_source_pointers .cols, .map_pos {
!if .cols = 1 {
!set .tile_char = C_TILE_COL
} else {
!set .tile_char = R_TILE_ROW
}
!if .cols = 1 or TILE_ROWS != 2 {
lda .tile_char
adc #1
!if .cols = 1 {
cmp #TILE_COLS
} else {
cmp #TILE_ROWS
}
sta .tile_char
bcc +
clc
lda #0
sta .tile_char
}
!if .cols = 1 {
inc .map_pos + 1
} else {
!if TILE_ROWS = 2 {
lda .tile_char
adc #1
and #1
sta .tile_char
bne +
}
inc .map_pos + 2
}
+
}
!macro iterate_destination_pointers .cols {
; pixel pointer
lda PIX_POS_LO_T
adc #(8*.cols % 256) ; + 64
sta PIX_POS_LO_T
!if .cols = 1 {
bcc+
}
lda PIX_POS_HI_T
adc #(8*.cols / 256) ; + 256
and #%11011111 ; modulo 8192 (but keep upper bits)
sta PIX_POS_HI_T ; next pixel position to start from
+
; color pointers
lda SCR_POS_LO_T
adc #.cols
sta SCR_POS_LO_T ; next screen position to start from
sta CLR_POS_LO_T
bcc +
lda CLR_POS_HI_T
adc #0
and #%11111011 ; modulo 1024 (but keep upper bits)
sta CLR_POS_HI_T
adc #%00001000
sta SCR_POS_HI_T
+
}
; depends on TILE_COLS and TILE_ROWS
;select_and_copy_tile_char !zone {
; !for .char, 0, 5 {
; !if .char != 5 {
; !if .char != 0 {
; cmp #.char
; }
; bne +
; }
; !if .char = 0 { jsr copy_tile_char0 }
; !if .char = 1 { jsr copy_tile_char1 }
; !if .char = 2 { jsr copy_tile_char2 }
; !if .char = 3 { jsr copy_tile_char3 }
; !if .char = 4 { jsr copy_tile_char4 }
; !if .char = 5 { jsr copy_tile_char5 }
; rts
;+
; }
;}
!macro init_pointers .cols {
!if .cols = 1 {
!set .tile_col = C_TILE_COL
!set .tile_row = C_TILE_ROW
!set .map_pos_lo = C_MAP_POS_LO
!set .map_pos_hi = C_MAP_POS_HI
!set .pix_pos_lo = C_PIX_POS_LO
!set .pix_pos_hi = C_PIX_POS_HI
!set .scr_pos_lo = C_SCR_POS_LO
!set .scr_pos_hi = C_SCR_POS_HI
!set .map_pos_lo_t = C_MAP_POS_LO_T
!set .map_pos_hi_t = C_MAP_POS_HI_T
!set .pix_pos_lo_t = C_PIX_POS_LO_T
!set .pix_pos_hi_t = C_PIX_POS_HI_T
!set .scr_pos_lo_t = C_SCR_POS_LO_T
!set .scr_pos_hi_t = C_SCR_POS_HI_T
!set .clr_pos_hi_t = C_CLR_POS_HI_T
} else {
!set .tile_col = R_TILE_COL
!set .tile_row = R_TILE_ROW
!set .map_pos_lo = R_MAP_POS_LO
!set .map_pos_hi = R_MAP_POS_HI
!set .pix_pos_lo = R_PIX_POS_LO
!set .pix_pos_hi = R_PIX_POS_HI
!set .scr_pos_lo = R_SCR_POS_LO
!set .scr_pos_hi = R_SCR_POS_HI
!set .map_pos_lo_t = R_MAP_POS_LO_T
!set .map_pos_hi_t = R_MAP_POS_HI_T
!set .pix_pos_lo_t = R_PIX_POS_LO_T
!set .pix_pos_hi_t = R_PIX_POS_HI_T
!set .scr_pos_lo_t = R_SCR_POS_LO_T
!set .scr_pos_hi_t = R_SCR_POS_HI_T
!set .clr_pos_hi_t = R_CLR_POS_HI_T
}
lda TILE_COL
sta .tile_col
lda TILE_ROW
sta .tile_row
lda .map_pos_lo
sta .map_pos_lo_t
clc
lda .map_pos_hi
adc #>TILE_MAP
clc
sta .map_pos_hi_t
lda .pix_pos_hi
adc #>HIRES
sta .pix_pos_hi_t
lda .pix_pos_lo
sta .pix_pos_lo_t
lda .scr_pos_hi
adc #>SCREEN
sta .scr_pos_hi_t
lda .scr_pos_hi
adc #>COLOR_RAM
sta .clr_pos_hi_t
lda .scr_pos_lo
sta .scr_pos_lo_t
}
!macro copy_tile_chars .cols, .count {
!if .cols = 1 {
!set .tile_col_t = C_TILE_COL
!set .tile_row_t = C_TILE_ROW
!set .map_pos_lo_t = C_MAP_POS_LO_T
!set .map_pos_hi_t = C_MAP_POS_HI_T
!set .pix_pos_lo_t = C_PIX_POS_LO_T
!set .pix_pos_hi_t = C_PIX_POS_HI_T
!set .scr_pos_lo_t = C_SCR_POS_LO_T
!set .scr_pos_hi_t = C_SCR_POS_HI_T
!set .clr_pos_hi_t = C_CLR_POS_HI_T
} else {
!set .tile_col_t = R_TILE_COL
!set .tile_row_t = R_TILE_ROW
!set .map_pos_lo_t = R_MAP_POS_LO_T
!set .map_pos_hi_t = R_MAP_POS_HI_T
!set .pix_pos_lo_t = R_PIX_POS_LO_T
!set .pix_pos_hi_t = R_PIX_POS_HI_T
!set .scr_pos_lo_t = R_SCR_POS_LO_T
!set .scr_pos_hi_t = R_SCR_POS_HI_T
!set .clr_pos_hi_t = R_CLR_POS_HI_T
}
lda .map_pos_lo_t
sta .next_tile_char + 1
lda .map_pos_hi_t
sta .next_tile_char + 2
lda .scr_pos_lo_t
sta SCR_POS_LO_T
sta CLR_POS_LO_T
lda .scr_pos_hi_t
sta SCR_POS_HI_T
lda .clr_pos_hi_t
sta CLR_POS_HI_T
lda .pix_pos_lo_t
sta PIX_POS_LO_T
lda .pix_pos_hi_t
sta PIX_POS_HI_T
lda #.count
sta ITERATIONS
clc
.next_tile_char
ldx TILE_MAP
; pixel pointer
lda .tile_row_t
beq +
lda #TILE_COLS ; a = TILE_COLS * tile_row (TILE_ROWS = 2)
+
adc .tile_col_t
; jsr select_and_copy_tile_char
!for .char, 0, 5 {
!if .char != 5 {
!if .char != 0 {
cmp #.char
}
bne +
}
!if .char = 0 { jsr copy_tile_char0 }
!if .char = 1 { jsr copy_tile_char1 }
!if .char = 2 { jsr copy_tile_char2 }
!if .char = 3 { jsr copy_tile_char3 }
!if .char = 4 { jsr copy_tile_char4 }
!if .char = 5 { jsr copy_tile_char5 }
!if .char != 5 { bne .iterate_pointers }
+
}
.iterate_pointers
clc
+iterate_source_pointers .cols, .next_tile_char
+iterate_destination_pointers .cols
dec ITERATIONS
bne .next_tile_char
.exit
lda .next_tile_char + 1
sta .map_pos_lo_t
lda .next_tile_char + 2
sta .map_pos_hi_t
lda SCR_POS_LO_T
sta .scr_pos_lo_t
lda SCR_POS_HI_T
sta .scr_pos_hi_t
lda CLR_POS_HI_T
sta .clr_pos_hi_t
lda PIX_POS_LO_T
sta .pix_pos_lo_t
lda PIX_POS_HI_T
sta .pix_pos_hi_t
}
copy_col_tiles1 !zone {
+init_pointers 1
+copy_tile_chars 1, SCROLL_COLS / COPY_COL_FRAMES
rts
}
copy_col_tiles2 !zone {
+copy_tile_chars 1, SCROLL_COLS / COPY_COL_FRAMES + ((SCROLL_COLS % COPY_COL_FRAMES) != 0)
rts
}
copy_row_tiles1 !zone {
+init_pointers SCR_COLS
+copy_tile_chars SCR_COLS, SCROLL_ROWS / COPY_ROW_FRAMES
rts
}
copy_row_tiles2 !zone {
+copy_tile_chars SCR_COLS, SCROLL_ROWS / COPY_ROW_FRAMES + ((SCROLL_ROWS % COPY_ROW_FRAMES) != 0)
rts
}
COPY_TILES !zone {
ldy C_COPY
bne .check_copy_col_tiles1
jsr COPY_ROW_TILES
rts
.check_copy_col_tiles1
dey
sty C_COPY
cpy #COPY_COL_FRAMES-1
bne .check_copy_col_tiles2
jsr copy_col_tiles1
rts
.check_copy_col_tiles2
jsr copy_col_tiles2
rts
}
COPY_ROW_TILES !zone {
ldy R_COPY
bne .check_copy_row_tiles1
rts
.check_copy_row_tiles1
dey
sty R_COPY
cpy #COPY_ROW_FRAMES-1
bne .check_copy_row_tiles2
jsr copy_row_tiles1
rts
.check_copy_row_tiles2
jsr copy_row_tiles2
rts
}