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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
|
;
; 6502 Assembler Demo.
; Copyright (C) 2007 Daniel Serpell <daniel.serpell@gmail.com>
;
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions are met:
;
; 1. Redistributions of source code must retain the above copyright notice,
; this list of conditions and the following disclaimer.
;
; 2. Redistributions in binary form must reproduce the above copyright notice,
; this list of conditions and the following disclaimer in the documentation
; and/or other materials provided with the distribution.
;
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
; ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
; POSSIBILITY OF SUCH DAMAGE.
;
; Variable definitions
temp0 = $20
temp1 = $21
temp2 = $22
temp3 = $23
temp4 = $24
temp5 = $25
param0 = $10
param1 = $11
param2 = $12
param3 = $13
; Output file
!to "all.bin", plain
; Start of code
*= $600
jmp main
; Used in "gira" and "circ"
gira_pos = $30
gira_scr = $200
circ_pos = $30
circ_scr = $210
show_pos = $31
show_source = $a000
show_dest = $500
text_state = $40
text_scr = $a000
; text_scr = $480
moire_buf = $a000
moire_scr = $200
moire_temp = $20
; Include routines and macros
: ===========================================================================
: !source "fillRect.asm"
: ===========================================================================
!zone {
; Uses the following:
; params: param0, param1
; temps: temp0
; Locals
.color = temp0
; Params
fillRect_buffer = param0
.buf = fillRect_buffer
; fillRect:
; Fill a rectangle of 8x8 pixels with a color.
; input: A = color index
; .buffer = output buffer (address)
!macro fillRect .buffer {
ldx #<.buffer
stx fillRect_buffer
ldx #>.buffer
stx fillRect_buffer+1
jsr fillRect_code
}
; fillRect:
; Fill a rectangle of 8x8 pixels with a color.
; input: .color = color index
; .buffer = output buffer (address)
!macro fillRect .buffer, .color {
lda #.color
+fillRect .buffer
}
fillRect_code:
sta .color
ldx #8
--
ldy #8
-
sta (.buf),y
dey
bne -
lda .buf
clc
adc #32
sta .buf
lda .buf+1
adc #0
sta .buf+1
lda .color
dex
bne --
rts
}
: ===========================================================================
: !source "gira.asm"
: ===========================================================================
!zone {
;
; define "gira_pos" and "gira_scr" before including
;
.pos = gira_pos
.scr00 = gira_scr
.scr01 = gira_scr + $8
.scr10 = gira_scr + $100
.scr11 = gira_scr + $108
; gira:
!macro gira {
jsr gira_code
}
; init code:
!macro giraInit {
+fillRect gira_scr-1, 1
+fillRect gira_scr+7, 2
+fillRect gira_scr+$107, 3
}
gira_code:
inc .pos
lda .pos
and #63
sta .pos
tax
lda .tabla,x
tax
lda .scr11,x
adc #1
and #3
sta .scr11,x
txa
eor #$E7
tax
lda .scr00,x
adc #1
and #3
sta .scr00,x
lda .pos
eor #63
tax
lda .tabla,x
eor #$E0
tax
lda .scr01,x
adc #1
and #3
sta .scr01,x
txa
eor #$E7
tax
lda .scr10,x
adc #1
and #3
sta .scr10,x
rts
.tabla
!byte 224, 192, 160, 128, 96, 225, 64, 193, 161, 226, 129, 32, 194, 97, 162, 227
!byte 195, 130, 228, 65, 163, 196, 98, 229, 131, 164, 197, 230, 231, 132, 165, 198
!byte 99, 66, 33, 0, 199, 166, 133, 100, 167, 67, 134, 101, 135, 34, 68, 102
!byte 103, 69, 35, 70, 71, 36, 1, 37, 38, 39, 2, 3, 4, 5, 6, 7
}
: ===========================================================================
: !source "circ.asm"
: ===========================================================================
!zone {
;
; define "circ_pos" before including
;
.pos = circ_pos
.scr00 = circ_scr
.scr01 = circ_scr + $8
.scr10 = circ_scr + $100
.scr11 = circ_scr + $108
; circ:
!macro circ {
jsr circ_code
}
circ_code:
ldx .pos
lda .tabla,x
tax
inc .scr11,x
eor #07
tax
inc .scr10,x
eor #$e7
tax
inc .scr01,x
eor #07
tax
inc .scr00,x
rts
.tabla
!byte 0, 32, 1, 33, 64, 2, 65, 34, 96, 66, 3, 97, 35, 98, 67, 128
!byte 4, 129, 36, 99, 130, 68, 160, 5, 161, 131, 100, 37, 162, 69, 132, 192
!byte 163, 101, 6, 193, 38, 194, 70, 164, 133, 195, 102, 224, 7, 225, 39, 165
!byte 226, 196, 134, 71, 227, 103, 197, 166, 228, 135, 198, 229, 167, 230, 199, 231
}
: ===========================================================================
!source "mapcopy.asm"
: ===========================================================================
!zone {
;
; define "show_pos" and "show_scr" before including
;
.pos = show_pos
.source = show_source
.dest = show_dest
; show:
!macro show {
jsr show_code
}
show_code
ldx .pos
lda .tabla,x
tax
.source_label
lda .source,x
.dest_label
sta .dest,x
inc .pos
rts
show_source_addr = .source_label + 1
show_dest_addr = .dest_label + 1
.tabla
!byte 195, 227, 194, 162, 228, 97, 226, 128, 129, 130, 225, 64, 161, 163, 224, 96
!byte 160, 193, 196, 32, 98, 192, 65, 0, 131, 229, 164, 33, 99, 197, 66, 132
!byte 1, 230, 34, 165, 67, 100, 198, 2, 3, 68, 6, 35, 133, 166, 5, 101
!byte 4, 199, 7, 36, 231, 69, 134, 167, 37, 38, 102, 135, 70, 232, 71, 39
!byte 103, 136, 200, 168, 8, 11, 10, 169, 233, 104, 9, 12, 137, 201, 13, 40
!byte 44, 72, 43, 170, 42, 45, 41, 105, 73, 202, 14, 138, 234, 74, 75, 106
!byte 203, 76, 171, 46, 77, 235, 107, 139, 15, 108, 172, 174, 140, 173, 141, 142
!byte 204, 109, 206, 207, 205, 78, 175, 47, 236, 239, 143, 237, 238, 110, 240, 241
!byte 111, 208, 16, 79, 176, 209, 242, 48, 144, 243, 80, 177, 244, 112, 210, 17
!byte 49, 178, 179, 52, 53, 147, 18, 81, 211, 145, 19, 146, 51, 85, 180, 20
!byte 54, 113, 148, 22, 50, 84, 212, 21, 55, 115, 245, 83, 114, 116, 23, 82
!byte 86, 88, 89, 87, 118, 117, 119, 149, 213, 56, 57, 181, 214, 90, 121, 122
!byte 150, 151, 182, 183, 215, 246, 58, 120, 247, 24, 153, 184, 152, 216, 25, 26
!byte 59, 91, 248, 123, 185, 27, 60, 217, 154, 28, 92, 249, 29, 155, 186, 61
!byte 218, 93, 124, 250, 187, 30, 251, 62, 156, 94, 125, 219, 188, 31, 252, 254
!byte 220, 253, 63, 126, 255, 157, 221, 95, 159, 191, 222, 127, 189, 223, 158, 190
}
: ===========================================================================
!source "text.asm"
: ===========================================================================
!zone {
;
; define:
; "text_state": 8 bytes of internal state
; "text_scr" : output screen address
; "text_data" : text character data
;
text_char = text_state + 0
.fps = text_state + 1
text_pixel = text_state + 2
text_skip = text_state + 3
.cb = text_state + 4
.fsz = text_state + 5
text_endFlag = text_state + 6
.scr = text_scr
.data = text_data
; abbreviations
.pos = text_char
.cxy = text_pixel
.skp = text_skip
; "pos" pointer to the next character
; "cxy" screen position
; "fps" position in font data of current character
; "fsz" remaining bytes of current character
; "skp" skip data, used in spaces, begining and ending
; "cb" current output byte (8 bits, one column)
; text:
!macro text {
jsr text_code
}
!macro textInit1 {
lda #$1f
sta text_pixel
lda #0
sta text_endFlag
sta text_skip
sta text_char
lda #1
sta text_base_color
lda #<text_scr
sta text_dest_addr
lda #>text_scr
sta text_dest_addr+1
}
!macro textInit2 .scrOut {
lda #$1f
sta text_pixel
lda #0
sta text_endFlag
sta text_skip
sta text_base_color
lda #<.scrOut
sta text_dest_addr
lda #>.scrOut
sta text_dest_addr+1
}
text_code
lda .cxy
and #$e0
bne .putpixel ; If we have more pixels, put them
; To next x coord
lda .cxy
clc
adc #1
and #$1f
sta .cxy
; If we are in "skip" mode, skip :-)
lda .skp
beq .noskip
.doSkip
; skip this step (filling with blanks)
dec .skp
.storeColumn0
lda #0
jmp .storeColumn
.noskip
; Continue font data
dec .fsz
; Skip just one column if just at the end of character
beq .storeColumn0
bpl .nextcolumn ; More columns
; Get next character
ldx .pos
inc .pos
lda .data, x
bpl .fontdata
; A > 128, skip "A-128" characters
and #$7F
sta .skp
; If skip == 127 (value=255), signal the end of text data
eor #$7F
bne .storeColumn0
lda #1
sta text_endFlag
jmp .storeColumn0
.fontdata
tax
lda .font_size,x
sta .fsz
dec .fsz
lda .font_pos,x
sta .fps
.nextcolumn
ldx .fps
inc .fps
lda .font_data, x
.storeColumn
sta .cb
; skip over to putpixel
.putpixel
lda .cxy
clc
adc #$e0
sta .cxy
ldx .cxy
.base_color
lda #1
ror .cb
rol
.dest_label
sta .scr,x
rts
text_base_color = .base_color + 1
text_dest_addr = .dest_label + 1
; font
.font_size:
!byte 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3, 2, 3, 3, 3, 3, 3, 1, 2, 3, 1
!byte 5, 3, 3, 3, 3, 3, 2, 2, 3, 3, 5, 4, 3, 3, 5, 4, 4, 4, 3, 3, 4, 4
!byte 1, 3, 4, 3, 5, 5, 5, 4, 5, 4, 4, 3, 4, 4, 7, 4, 4, 4, 2, 1
.font_pos:
!byte 0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 32, 35
!byte 35, 38, 40, 43, 46, 49, 50, 52, 4, 55, 55, 60, 63
!byte 65, 68, 71, 73, 75, 78, 78, 33, 83, 86, 89, 94, 98
!byte 102, 106, 109, 112, 116, 94, 120, 123, 127, 130, 134, 139, 144
!byte 148, 153, 157, 161, 164, 167, 171, 178, 171, 182, 186, 5
.font_data:
!byte 56, 68, 56, 36,124, 4, 76, 84, 36, 68, 84, 40, 24, 40,124,100
!byte 84, 88, 56, 84, 72, 76, 80, 96, 40, 84, 40, 36, 84, 56, 44, 28
!byte 124, 36, 24, 24, 36,124, 24, 52, 16, 60, 80, 24, 37, 30,124, 32
!byte 28,188, 1,190,124, 24, 36, 60, 32, 28, 32, 28, 24, 36, 24, 63
!byte 36, 24, 36, 63, 60, 16, 32, 52, 44,120, 36, 56, 4, 60, 56, 4
!byte 56, 4, 56, 57, 6, 56, 44, 52, 36, 12, 48,208, 48, 12,252,164
!byte 164, 88,120,132,132, 72,252,132,132,120,252,164,132,252,160,128
!byte 120,132,164, 56,252, 32, 32,252, 8, 4,248,252, 48, 80,140,252
!byte 4, 4, 252, 64, 60, 64,252, 64, 48, 8,252,120,132,132,132,120
!byte 252,144,144, 96,120,132,134,133,120,252,144,144,108, 68,164,164
!byte 152,128,252,128,248, 4, 4,248, 4, 8,240,224, 28, 16,224, 28
!byte 16,224,204, 48, 48,204,140,148,164,196, 0, 0
text_data
!byte (128+5), 41, 10, 28, 29, 63, 63, 63
!byte (128+8), 15, 10, 28, 29, 14, 27, 63, 63, 63
!byte (128+4), 55, 17, 18, 28, 62, 18, 28, 62, 10
!byte (128+8), 27, 14, 10, 21, 21, 34
!byte (128+15), 15, 10, 28, 29
!byte (128+14), 39, 40, 48, 50
!byte (128+21)
!byte (128+17), 10, 23, 13, 62, 23, 24, 32
!byte (128+8), 28, 24, 22, 14
!byte (128+8), 11, 14, 10, 30, 29, 18, 15, 30, 21
!byte (128+0), 14, 15, 15, 14, 12, 29, 28, 63, 63, 63
!byte (128+16)
!byte (128+31)
!byte 255
!byte 55, 17, 18, 28, 62, 18, 28, 62, 10, 21, 21
!byte (128+1), 15, 24, 27, 62, 23, 24, 32
!byte (128+8), 11, 34, 14, 63, 63, 63
!byte (128+13), 63, 63, 63, 11, 34, 14
!byte (128+22)
!byte (128+31)
!byte (128+15), 11, 34, 62, 39, 48, 54, 38
!byte 2, 0, 0, 7, 63, 5, 63, 2, 9
!byte 11, 34, 62, 39, 48, 54, 38
!byte 2, 0, 0, 7, 63, 5, 63, 2, 9
!byte 11, 34, 62, 39, 48, 54, 38
!byte 2, 0, 0, 7, 63, 5, 63, 2, 9
!byte (128+15)
!byte (128+31)
!byte 255
}
: ===========================================================================
!source "moireSmooth.asm"
: ===========================================================================
!zone {
; Parameters (consts)
.scr = moire_scr
.buf = moire_buf
; Variables
.p1 = moire_temp
.o1 = moire_temp + 2
.o2 = moire_temp + 4
.o3 = moire_temp + 6
.o4 = moire_temp + 8
.iter = moire_temp + 10
.valStartX = moire_temp + 11
.deltaX = moire_temp + 12
.deltaY = moire_temp + 13
.yPos = moire_temp + 14
; moire!:
!macro moire {
jsr moire_code
}
!macro add16 .var, .value {
lda .var
clc
adc #<.value
sta .var
lda .var+1
adc #>.value
sta .var+1
}
!macro sto16 .var, .value {
lda #<.value
sta .var
lda #>.value
sta .var+1
}
moire_code:
lda #0
sta .iter
.loop:
lda #1
sta .deltaX
sta .deltaY
+sto16 .p1, .buf
lda .iter
sta .valStartX
ldx #15
--
ldy #15
-
sta (.p1),y
clc
adc .deltaX
inc .deltaX
dey
bpl -
+add16 .p1, $0020
lda #1
sta .deltaX
lda .valStartX
clc
adc .deltaY
sta .valStartX
inc .deltaY
dex
bpl --
; update screen
+sto16 .p1, .buf
+sto16 .o1, .scr + $01E0
+sto16 .o2, .scr + $0200
+sto16 .o3, .scr + $01F0
+sto16 .o4, .scr + $0210
lda #15
sta .yPos
--
ldy #15
-
lda (.p1),y
lsr
lsr
lsr
lsr
tax
lda .tabCol,x
cmp (.o1),y
beq .noCopy
sta (.o1),y
sta (.o2),y
tax
tya
eor #15
tay
txa
sta (.o3),y
sta (.o4),y
tya
eor #15
tay
.noCopy:
dey
bpl -
+add16 .p1, $0020
+add16 .o1, $FFE0
+add16 .o2, $0020
+add16 .o3, $FFE0
+add16 .o4, $0020
dec .yPos
bpl --
inc .iter
lda .iter
and #$3f
beq +
jmp .loop
+
rts
.tabCol
!byte 0,11,12,15,1,15,12,11
!byte 0,11,12,15,1,15,12,11
!byte 0,11,12,15,1,15,12,11
!byte 0,11,12,15,1,15,12,11
}
: ===========================================================================
; Main loop
main
+giraInit
+textInit1
lda #63
sta gira_pos
; Start show-pos from middle of screen
lda #128
sta show_pos
; First color is 3
lda #3
sta text_base_color
; Clear old text image
lda #0
tax
-
sta text_scr,x
inx
bne -
loop
+gira
+circ
+show
+text
lda text_pixel
eor #$1f
bne notChangeTextColor
lda text_base_color
clc
adc #2
and #3
adc #3
sta text_base_color
notChangeTextColor
lda show_pos
bne loop
lda show_dest_addr+1
eor #1
sta show_dest_addr+1
lda text_endFlag
beq loop
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End of first text, do moire!
jsr clearScr
+moire
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; End of moire, do ending text
+textInit2 $300
jsr clearScr
; loop text output
-
+text
lda text_pixel
eor #$1f
bne -
lda text_dest_addr+1
eor #7
sta text_dest_addr+1
lda text_endFlag
beq -
jmp main
clearScr
; Clear screen
lda #0
tax
-
sta $200,x
sta $300,x
sta $400,x
sta $500,x
inx
bne -
rts
|