-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenchr.inc
411 lines (362 loc) · 8.21 KB
/
genchr.inc
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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
#importonce
.filenamespace genchr
#import "pseudocommands.inc"
#import "delay.inc"
#import "init.inc"
#import "common.inc"
// Make cell references always positive
.const XPAD = 1
.const YPAD = 1
.segment GenchrZeroPage [start=ZP_START, min=ZP_START, max=$ff, hide]
tmp: .byte 0
tmp_lo: .byte 0
tmp_hi: .byte 0
// genchr:
table_nr: .byte 0
char_nr: .byte 0
m11_lo:
m00_lo: .byte 0
m11_hi:
m00_hi: .byte 0
m01_lo: .byte 0
m01_hi: .byte 0
m10_lo: .byte 0
m10_hi: .byte 0
max: .byte 0, 0, 0
char: .word 0
// for mirroring:
xxx: .byte 0
yyy: .byte 0
plain_x: .byte 0
plain_y: .byte 0
inverted_x: .byte 0
inverted_y: .byte 0
progress: .word $0500 - ALZ_GAP + NUM_CIRCLES + NUM_LINES - $a0
.segment Code
.macro ADD_SLOPES(dxlo, dxhi, dylo, dyhi) {
lda x_lo, y
clc
adc dxlo
sta x_lo, x
lda x_hi, y
adc dxhi
sta x_hi, x
lda y_lo, y
clc
adc dylo
sta y_lo, x
lda y_hi, y
adc dyhi
sta y_hi, x
}
// --------------------------------------------------------------------
// GENERATE_CHARSET macro
// --------------------------------------------------------------------
.macro @GENERATE_CHARSET() {
ldx #ZP_START
!:
lda genchr_zp-ZP_START, x
sta $00, x
inx
bne !-
// --------------------------------------------------------------------
// Loop over all characters
// --------------------------------------------------------------------
charset_loop:
lda #$a0
tay
sta (progress), y
iny
sta (progress), y
iny
sta (progress), y
lda progress
clc
adc #$03
sta progress
lda progress+1
adc #$00
sta progress+1
// --------------------------------------------------------------------
// Look up slopes
// --------------------------------------------------------------------
lda char_nr
lsr
lsr
lsr
lsr
lsr
lsr
tax
// TODO: shift less and copy a whole block
lda m00_lo_per_angle, x
sta m00_lo
lda m00_hi_per_angle, x
sta m00_hi
lda m01_lo_per_angle, x
sta m01_lo
eor #$ff
clc
adc #$01
sta m10_lo
lda #$00
sta m01_hi
lda #$ff
adc #$00
sta m10_hi
// --------------------------------------------------------------------
// Generate the positions within the texture
// --------------------------------------------------------------------
lax char_nr
and #$07
ora #YPAD*8
sta y_hi
txa
lsr
lsr
alr #$07<<1
ora #XPAD*8
sta x_hi
ldx #$00
stx x_lo
stx y_lo
ldy #$00
inx
!:
ADD_SLOPES(m00_lo, m00_hi, m01_lo, m01_hi)
iny
inx
cpx #$08
bne !-
ldy #$00
!:
ADD_SLOPES(m10_lo, m10_hi, m11_lo, m11_hi)
iny
inx
cpx #$40
bne !-
// --------------------------------------------------------------------
// Compute the direction vectors and count occurrences
// --------------------------------------------------------------------
ldx #11
lda #$00
!:
sta count, x
dex
bpl !-
ldy #$3f
!:
lda x_hi, y
lsr
and #$fc
sta tmp
lda y_hi, y
lsr
lsr
alr #$0f << 1
// A = 1..3
ora tmp
sta dir, y
tax
inc count, x
dey
bpl !-
// --------------------------------------------------------------------
// Find the maximum occurrences
// --------------------------------------------------------------------
ldy #$00
max_loop:
lax #$00
!:
cmp count, x
bcs not_more
txa
sta max, y
lda count, x
not_more:
inx
cpx #12
bne !-
ldx max, y
lda #$00
sta count, x
iny // TODO: dey
cpy #$03
bne max_loop
// --------------------------------------------------------------------
// Make the bitmap
// --------------------------------------------------------------------
ldx #$3f
mask_loop:
// pattern
/* TODO (shifts pattern by 1):
lda x_hi, x
ora y_hi, x
and #$07
cmp #$01
bcc store_zero */
lda x_hi, x
and #$07
tay
lda pattern, y
beq store_zero
lda y_hi, x
and #$07
tay
lda pattern, y
beq store_zero
lda dir, x
ldy #$00
cmp max+0
beq pixel1
cmp max+1
beq pixel2
cmp max+2
beq pixel3
store_zero:
ldy #-3
pixel3: iny
pixel2: iny
pixel1: iny
tya
sta bitmap, x
dex
bpl mask_loop
// --------------------------------------------------------------------
// Compute the character
// --------------------------------------------------------------------
// TODO: fold into loop above
lax #$00
char_loop:
asl
asl
ora bitmap, x
sta bitmap, x
inx
inx
cpx #$40
bne char_loop
lda #(>CHARSET) + 7
sta char+1
// TODO: consider folding this into the loop above, as well.
ldx #$3e
ldy char_nr
!:
lda bitmap, x
sta (char), y
dec char+1
txa
axs #$08
bcs !-
// --------------------------------------------------------------------
// Store the relative positions
// --------------------------------------------------------------------
tya // char_nr
ldx #$07
sax yyy
lsr
lsr
lsr
sax xxx
lda #$02
sta table_nr
xy_loop:
ldy table_nr
lax max, y
lsr
lsr
clc
adc #2-XPAD
sta plain_x
eor #$ff
ldy xxx
cpy #$01
adc #2*2
sta inverted_x
txa
and #$03
clc
adc #2-YPAD
sta plain_y
eor #$ff
ldy yyy
cpy #$01
adc #2*2
sta inverted_y
lda table_nr
asl
asl
adc #>XYTABLES
sta tmp_hi
ldy char_nr
lda plain_x
sta (tmp_lo), y
inc tmp_hi
lda plain_y
sta (tmp_lo), y
inc tmp_hi
lda inverted_x
sta (tmp_lo), y
inc tmp_hi
lda inverted_y
sta (tmp_lo), y
inc tmp_hi
dec table_nr
bpl xy_loop
// --------------------------------------------------------------------
// Process the next character
// --------------------------------------------------------------------
inc char_nr
bne_far charset_loop
.label col0_x_00 = XYTABLES + $0000
.label col0_y_00 = XYTABLES + $0100
.label col0_ix_00 = XYTABLES + $0200
.label col0_iy_00 = XYTABLES + $0300
.label col1_x_00 = XYTABLES + $0400
.label col1_y_00 = XYTABLES + $0500
.label col1_ix_00 = XYTABLES + $0600
.label col1_iy_00 = XYTABLES + $0700
.label col2_x_00 = XYTABLES + $0800
.label col2_y_00 = XYTABLES + $0900
.label col2_ix_00 = XYTABLES + $0a00
.label col2_iy_00 = XYTABLES + $0b00
.label col0_x_80 = XYTABLES + $0c00 + $0000
.label col0_y_80 = XYTABLES + $0c00 + $0100
.label col0_ix_80 = XYTABLES + $0c00 + $0200
.label col0_iy_80 = XYTABLES + $0c00 + $0300
ldx #$00
!:
// delta compressable
lda col0_x_00, x
ora #$80
sta col0_x_80, x
lda col0_y_00, x
ora #$80
sta col0_y_80, x
lda col0_ix_00, x
ora #$80
sta col0_ix_80, x
lda col0_iy_00, x
ora #$80
sta col0_iy_80, x
inx
bne !-
}
.segment Tables
genchr_zp:
.segmentout [segments="GenchrZeroPage"]
pattern: .byte 0, 1, 1, 1, 1, 1, 1, 0
m00_lo_per_angle: .byte $00, 236, 181, 98
m00_hi_per_angle: .byte $01, 0, 0, 0
m01_lo_per_angle: .byte $00, 98, 181, 236
//m01_hi_per_angle: .byte $00, 0, 0, 0
.segment GenChrScratch
.align 256
count: .fill 256, 0
.align 256
x_lo: .fill 64, 0
x_hi: .fill 64, 0
y_lo: .fill 64, 0
y_hi: .fill 64, 0
dir: .fill 64, 0
bitmap: .fill 64, 0