-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflt-04-awsm.asm
More file actions
475 lines (386 loc) · 18.1 KB
/
flt-04-awsm.asm
File metadata and controls
475 lines (386 loc) · 18.1 KB
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
;
; This version is slightly optimized in many areas, moving around code
; where it makes sense. In addtion I added lots of comments
;
;==========================================================
; main entry
;==========================================================
* = CODE_START
sei
lda # >irq
sta $0315 ; IRQ vector routine high byte
lda # <irq
sta $0314 ; IRQ vector routine low byte
lda #$0
sta $d012 ; raster line
lda #$01
sta $d01a ; interrupt control
lda #$7f
sta $dc0d ; CIA #1 - interrupt control and status
lda #$1b
sta $d011 ; screen control register #1, vertical scroll
lda #$94
sta $dd00 ; CIA #2 - port A, serial bus access
lda #$12
sta $d018 ; memory setup
;==========================================================
; set colors of the whole screen in color RAM
;==========================================================
lda #$09 ; set color ram for the logo
ldx #$00 ; x = 0
-
sta $d800,x ; store 9 at $d800+x
inx ; x = x + 1
bne - ; loop until x wrapped to 0
ldx #$20 ; x = 20
-
sta $d900,x ; store 20 at $d900+x
dex ; x = x - 1
bne - ; loop until x = 0
lda #$01 ; $01 = white
-
sta $d920,x ; store 1 at $d920+x
sta $da00,x ; store 1 at $da00+x
sta $db00,x ; store 1 at $db00+x
inx ; x = x + 1
bne - ; loop until x = 0
ldx #$c0 ; sets color of text over the raster bars to
lda #$00 ; $00 = black
-
sta $da40,x
dex
bne -
lda #$00
sta $d020 ; border color
sta $d021 ; background color
lda #$07
sta $d023 ; extra background color #2
lda #$02
sta $d022 ; extra background color #1
lda #$d8
sta $d016 ; screen control register #2, horizontal scroll, multicolor, screenwidth
;==========================================================
; Init all sprites and position them as one fake raster bar
;==========================================================
lda #$ff
sta $d015 ; sprite enable/disable
lda #$18
sta $d000 ; sprite #0 X position (bits 0-7)
lda #$18 + 1*48
sta $d002 ; sprite #1 X position (bits 0-7)
lda #$18 + 2*48
sta $d004 ; sprite #2 X position (bits 0-7)
lda #$18 + 3*48
sta $d006 ; sprite #3 X position (bits 0-7)
lda #$18 + 4*48
sta $d008 ; sprite #4 X position (bits 0-7)
lda #$08
sta $d00a ; sprite #5 X position (bits 0-7)
lda #$08 + 1*48
sta $d00c ; sprite #6 X position (bits 0-7)
lda #$60
sta $d010 ; sprites 5+6 X position (bit 8)
lda #$ff
sta $d01c ; sprite multicolor mode
sta $d01d ; sprite double width
;==========================================================
; set all sprite colors
;==========================================================
lda #$0e ; $0d = light green
ldx #$06 ; 0-7 sprites
-
sta $d027,x ; sprite color
dex
bpl - ; loop until all sprite colors have been set
lda #$06 ; $05 = green
sta $d025 ; sprite extra color #1
lda #$03 ; $01 = white
sta $d026 ; sprite extra color #2
lda #$00 ; set address $02 to 0
sta $02 ; which is the position of the sinus table for the sprite raster bar
jsr music_init
lda #$10
sta set_volume +1 ; set the volume level
lda # >scrolltext ; store the address of the scrolltext
sta $3a ; at zero page $39, $3a
lda # <scrolltext
sta $39
ldx #$00
-
lda color_wash,x ; writes the colory cycle effect into color RAM
sta $db20,x
inx
cpx #$28
bne -
lda #$00 ; set $c5 and $c6 (keyboard matrix and buffer) to 0
sta $c6
sta $c5
cli
endless_loop
jmp * ; endless loop, all code is done in IRQ routine
;==========================================================
; IRQ entrypoint
; to get a reliable stable raster, code from this
; excellent german article was used:
; https://www.retro-programming.de/programming/nachschlagewerk/interrupts/der-rasterzeileninterrupt/raster-irq-endlich-stabil/
;
; everything in here is only used to make sure the exact
; needed amount of cycles are count so that the real
; raster routine can be stable
;==========================================================
irq
lda #<double_irq ; 2 cycles create 2nd raster irq
sta $0314 ; 4 cycles
lda #>double_irq ; 2 cycles
sta $0315 ; 4 cycles
tsx ; 2 cycles
stx double_irq+1 ; 4 cycles
nop ; 2 cycles
nop ; 2 cycles
nop ; 2 cycles
lda #%00000001 ; 2 cycles
; = 26 cycles
inc $d012 ; 6 cycles
sta $d019 ; 4 cycles acknowledge irq
cli ; 2 cycles
ldx #$08 ; 2 cycles
-
dex ; 8 * 2 cycles = 16 cycles
bne - ; 7 * 3 cycles = 21 cycles
; 1 * 2 cycles = 2 cycles
; = 41 cycles
nop ; 2 cycles (56)
nop ; 2 cycles (58)
nop ; 2 cycles (60)
nop ; 2 cycles (62)
nop ; 2 cycles (64)
nop ; 2 cycles (66)
double_irq
ldx #$00 ; 2 cycles Placycleshalter für 1. Stackpointer
txs ; 2 cycles Stackpointer vom 1. IRQ wiederherstellen
nop ; 2 cycles
nop ; 2 cycles
nop ; 2 cycles
nop ; 2 cycles
nop ; 2 cycles
bit $01 ; 3 cycles
ldx $d012 ; 4 cycles
cpx $d012 ; 4 cycles
; = 25 cycles = 63 or 64 cycles
beq main_irq ; 3 cycles waste 1 cycle or
; 2 cycles just continue
;==========================================================
; the main raster routine
;==========================================================
main_irq
lda #$a9 ; start position of raster bars
ldx #$00
-
cmp $d012 ; raster line
bne -
draw_rasterbars
lda raster_color,x ; fetch a color from the table
tay
lda $d012 ; raster line
-
cmp $d012 ; raster line
beq -
sty $d021 ; background color
inx
cpx #raster_color_end - raster_color
bne draw_rasterbars
inc $02
ldx $02
cpx #table_sprite_y_pos_end - table_sprite_y_pos -1 ; end of sprite y pos table?
bne +
lda #$00
sta $02
+
lda table_sprite_y_pos,x
ldy #$0e ; $0e is double the amount of sprites
-
sta $d001,y ; but we skip every second address here with 2 deys
dey ; effectively only changing the y pos of each sprite - clever
dey
bpl -
lda $d001 ; sprite #0 Y position
cmp #50 ; is our raster bar at the topmost position?
bne +
lda #$00 ; then we change the
-
sta $d01b ; sprite priority foreground/background
jmp set_volume
+
cmp #123 ; is our raster bar at the bottom position?
bne +
lda #$ff ; yes, so change priority foreground/background value again
sta $d01b ; sprite priority foreground/background
jmp set_volume
+
cmp #$33
bne set_volume
lda set_volume +1 ; load volume
cmp #$1f ; is it loud enough already?
beq set_volume ; yes, move on
inc set_volume +1 ; no, increase it
set_volume
lda #$1f
sta $d418 ; volume and filter modes
;==========================================================
; set raster line for the scrolltext
;==========================================================
lda #$d2 ; raster line
-
cmp $d012
bne -
lda $09
sta $d016 ; screen control register #2, horizontal scroll, multicolor, screenwidth
ldx #$64
-
dex
bne -
lda #$d8
sta $d016 ; screen control register #2, horizontal scroll, multicolor, screenwidth
dec $09
lda $09
cmp #$ff
bne color_cycle
lda #$07
sta $09
ldx #$00 ; x = 0
-
lda scrollline+1,x ; get character at scrolline+1+x
sta scrollline,x ; copy it to scrolline+x, moving it 1 char to the left
inx ; x=x+1
cpx #$27 ; have we copied the full line already?
bne - ; no, keep going
-
ldx #$00 ; yes, x = 0
lda ($39,x) ; fetch a new character
cmp #$00 ; is the current byte = $00?
bne + ; yes, then reset the scrolltext
lda # >scrolltext ; set high byte to start of scrolltext again
sta $3a
lda # <scrolltext ; set low byte to start of scrolltext again
sta $39
jmp - ; and loop text
+
sta last_character ; store it at the last character pos
inc $39 ; increase address position
lda $39 ; and read it
cmp #$00 ; is it 0?
bne color_cycle ; no, jump to next section
inc $3a ; yes, increase high byte of address position
jmp color_cycle
color_cycle
lda $db20 ; get color value at $db20
pha ; push it on the stack
ldx #$00 ; x=0
-
lda $db21,x ; load color value at $db21+x
sta $db20,x ; save it at $db20+x
inx ; x=x+1
cpx #$27 ; have cycled through a full line?
bne - ; no, keep going
pla ; yes, get initial value from stack
sta $db47 ; put it at the end of the line
jsr music_play
asl $d019 ; acknowlege IRQ interrupt status
lda set_volume +1 ; selfmod
cmp #$1f ; do not allow pressing space key before music is at full volume :)
bne +
jsr $ffe4 ; GETIN
cmp #$20 ; check for space key
bne + ; pressed?
jmp exit ; yes, exit intro
+
jsr $ffe4 ; GETIN
jmp $ea31 ; KERNAL's standard interrupt routine
exit
sei
lda #$ea ; $ea31 = original IRQ vector
sta $0315 ; IRQ vector routine high byte
lda #$31
sta $0314 ; IRQ vector routine low byte
jsr $ff81 ; SCINIT
lda #$97
sta $dd00 ; CIA #2 - port A, serial bus access
cli
jmp $fce2 ; clean up IRQ and reset
;==========================================================
; color wash effect table
;==========================================================
color_wash
!byte $06, $06, $06, $06, $0e, $06, $0e, $0e, $03, $0e, $03, $03, $01, $03, $01, $07, $07, $01, $01, $01
!byte $01, $01, $07, $07, $01, $03, $01, $03, $03, $0e, $03, $0e, $0e, $06, $0e, $06, $06, $06, $06, $06
;==========================================================
; color for the red and blue rasters
;==========================================================
raster_color
!byte $09, $08, $07, $01, $07, $08, $08, $09
!byte $00, $00, $00, $00, $00, $00
!byte $06, $0e, $03, $01, $03, $0e, $0e, $06
!byte $00
raster_color_end
;==========================================================
; sinus table for the sprite rasterbar
;==========================================================
table_sprite_y_pos
!byte 87, 89, 92, 95, 97, 100, 102, 105, 107, 109, 111, 113, 115, 116, 118, 119, 120, 121, 122, 122, 123, 123, 123, 123, 122, 122, 121, 120, 119, 117, 116, 114, 112, 110, 108, 106, 103, 101, 98, 96, 93, 91, 88, 85, 82, 80, 77, 75, 72, 70, 67, 65, 63, 61, 59, 57, 56, 54, 53, 52, 51, 51, 50, 50, 50, 50, 51, 51, 52, 53, 54, 55, 57, 58, 60, 62, 64, 66, 68, 71, 73, 76, 78, 81, 84, 87
table_sprite_y_pos_end
;==========================================================
; the sprite
;==========================================================
* = SPRITE_DATA
sprite_data
; sprite data (why is it not called from anywhere)
; 3 bytes per horizontal line
; 21 lines
!byte $55, $55, $55
!byte $55, $55, $55
!byte $aa, $aa, $aa
!byte $55, $55, $55
!byte $aa, $aa, $aa
!byte $aa, $aa, $aa
!byte $aa, $aa, $aa
!byte $ff, $ff, $ff
!byte $aa, $aa, $aa
!byte $ff, $ff, $ff
!byte $ff, $ff, $ff
!byte $ff, $ff, $ff
!byte $aa, $aa, $aa
!byte $ff, $ff, $ff
!byte $aa, $aa, $aa
!byte $aa, $aa, $aa
!byte $aa, $aa, $aa
!byte $55, $55, $55
!byte $aa, $aa, $aa
!byte $55, $55, $55
!byte $55, $55, $55
;==========================================================
; all logo and text on the screen
;==========================================================
* = SCREEN
!source "code/screen-text-awsm.asm"
;==========================================================
; sprite pointers
;==========================================================
* = SPRITE_POINTERS
!byte $0f, $0f, $0f, $0f, $0f, $0f, $0f, $0f
;==========================================================
; the charset in both assembly and binary format
;==========================================================
* = CHARACTER
;!source "code/charset.asm"
!bin "code/charset.bin"
;==========================================================
; the scrolltext
;==========================================================
scrolltext
!scr "disassembled by awsm of mayday during many boring evenings of the covid 19 lockdown in 2021... check out my github account for the fully commented source code at https://github.com/esshahn/c64-fairlight greetings go out to... drumroll... fairlight see you next time... "
!byte $00
;==========================================================
; music player and data
;==========================================================
* = MUSIC
!source "code/music.asm"