-
Notifications
You must be signed in to change notification settings - Fork 1
/
wiz3.a
2129 lines (1608 loc) · 39.3 KB
/
wiz3.a
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
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; Compile with :
; acme wiz.a
; dskalyzer.exe -with-disk BAD_APPLE.DSK -file-put wiz3#0x0C00.o
; wine-development ~/.wine/drive_c/Program\ Files\ \(x86\)/faddenSoft/CiderPress/CiderPress.exe
; mame apple2p -skip_gameinfo -window -nomax -flop1 NEW.DSK -flop2 cstripes.dsk
; c:\port-stc\opt\mame\mame64 apple2p -skip_gameinfo -window -nomax -flop1 NEW.DSK -flop2 cstripes.dsk -rp bios
; mame apple2p -skip_gameinfo -window -nomax -flop1 NEW.DSK -flop2 cstripes.dsk -aviwrite z.avi
; ffmpeg -i ~/.mame/snap/z.avi -vf "scale=iw*.5:ih,format=gray" o.avi
;; java -jar ~/Downloads/AppleCommander-1.3.5.13-ac.jar -d NEW.DSK STARTUP
;; java -jar ~/Downloads/AppleCommander-1.3.5.13-ac.jar -p NEW.DSK STARTUP BIN 0x0C00 < STARTUP
; 1 side x 35 Tracks/side x 16 Sectors/Trk x 256 Bytes/Sec = 143,360 Bytes.
; 2200 pictures => 2200/35=62 frames per track
!cpu 6502
!sl "listing.txt"
!to "STARTUP",plain
;; !to "STARTUP#060C00",plain ; The stuff at '#' is for CiderPress to
;; ; set up file attributes : 06=BIN file,
;; ; 0C00 = load address in RAM
; to "wiz3#0x0C00.o",plain ; The stuff at '#' is for Diskalayzer to
; ; set up file attributes : 06=BIN file,
; ; 0C00 = load address in RAM
; My goal is to use the Apple Drive as a timer. It produces a « tick
; » each time a sector is read. Reading a sector is 0. Drive is 300
; RPM, so 5 RPS, since there are 16 sectors per track, that’s 80
; sectors per second => 1 sector = 0.0125 second = 12500 cycles. So a tick every
; 0.0125 second.
; Since reading sectors and processing data must be interleaved and
; data processing is hard to estimate, I’ll track the number of sector
; « passed by » from time to time (instead of trying to « race » the
; disk on each sectors). This can be done using rdaddr16 which
; indicates the number of the sector it finds.
; Every 0.1 second, I need to display a frame of the
; video. Interestingly, 0.1 = 0.0125 (sector tick) * 8 => I need to
; display a frame of the video every 8 sectors. Also, everytime I
; have read 16 sectors, I must advance one track. This action takes «
; some » time.
; I store at least one frame per sector. So I can read up to 8
; sectors while I display one frame.
; The problem is when there's one sector left to be read
; on a track. In that case, the worst case scenario is to pass
; 16-1=15 sectors before reaching the one we're interested in.
; If, for example, I do nothing while waiting, then that
; time is wasted. So the whole idea is to wait in a active maner.
; The best way to do that is to process some data and poll the
; drive from time to time to know if I'm close or not a sector
; I have to read. If I'm close, then I wait. If I'm far, then
; I process some more data an poll the drive later on.
; The difficulty of course is to estimate the time it takes
; to "process some data". I'll use heuristics in a first
; approach. I could count the cycles but that's very tricky.
; Read sector address
; how far is the next sector that must be read ?
; More than 2 sectors away : process some data.
; Less than 2 sectors away : wait for that sector, then read it.
; If sector_passed MOD 8 == 7 : time to show a frame.
; If all sectors are read, advance track.
; Process data = decompress stripes up to 4 frames ahead (1 frame in tiles = 40*48/4 = 480 tiles = 480 bytes); I decrunch one sector at a time
; Decrunching a frame takes 30000 cycles so far, reading a sectors
; takes +/- 12500 cycles => decrunching a full frames takes around 3
; sectors.
; Untiling and copying frames takes, say, 25000 cycles
; Imagine we work on a sector basis (harder because huffman encodes
; stuff that can be on both sides of sector boundaries)
; halfTrack = 8 sectors
; halfTrack[i] == 0 : to read, 2 : to process, 1 : processed
; when sum(halfTrack) >= 1* len(halfTrack) : start reading sector on another halfTrack (if other halfTrack is ready to read)
; when sum(halfTrack) == 2* len(halfTrack) : mark this half track ready to read (reset statuses to 0).
; processed_half_track; read_halftrack
!macro add_a_to_16 .target {
; Add A to .target
; A is destroyed
CLC ; 2 c
ADC .target ; 3 zp or 4 absolute
STA .target ; 3 zp or 4 absolute
LDA #0 ; 2
ADC .target + 1 ; 3 or 4
STA .target + 1 ; 3 or 4 => 16 or 20 cycles
}
; increase 16-bit counters
; no register touched
!macro inc16 .target {
inc .target ; 5+
bne .j ; "bne * + 5" would not work in zp ; 2+
inc .target + 1 ; 5+ => total 12 or 15 cycles
.j
}
; decrease 16-bit counters
; A destroyed
!macro dec16 .target {
LDA .target
BNE .j ; "bne * + 5" would not work in zp
DEC .target + 1
.j
DEC .target ; low byte
}
!macro store_16 .target, .const {
lda #<.const
sta .target
lda #>.const
sta .target + 1
}
!macro store_8 .target, .const {
lda #.const
sta .target
}
; 16 bit word := 16 bit word - 16 bit const
!macro sub_const_from_16 .target, .const {
SEC
LDA .target
SBC #<.const
STA .target
LDA .target + 1
SBC #>.const
STA .target + 1
}
; 16 bit word := 16 bit word + 16 bit const
!macro add_const_to_16 .target, .const {
CLC
LDA .target ; low byte
ADC #<.const
STA .target
LDA .target+1 ; high byte
ADC #>.const
STA .target+1
}
!macro writeln .msg {
LDA #(< .msg)
STA println_self_mod + 1
LDA #(> .msg)
STA println_self_mod + 2
JSR println
}
DRAW_STATUS = 0
LZ = 1
NOCOMP = 0
compression = LZ ; LZ or NOCOMP
TOTAL_FRAMES = 1971 ; Number of frames in the movie
TRANSPARENT_TILE = $7E
VERTICAL_TILES = 20 ; equiv C64 = 20*8 = 160
HORIZONTAL_TILES = 24 ; equiv C64 = 24*8 = 192
GETLNZ = $FD67
GETLNZ_PROMPT = $33
COUT = $FDED ; The Apple II character output func.
GR_RAM = $400
GR2_RAM = $800
HGR_RAM = $2000
MLI = $BF00
SPKR = $C030
MOTOR_ON = $C089
DRV2_SLCT = $C08B ; Select drive 2
LC_RAM_SELECT = $C08B
DRIVE_SELECT = $0 ; 0 == drive 1; $80 = drive 2
SLOT_SELECT = $60 ; 0 (drive 1) 110 (slot 6) 0000
PRODOS_MLI_READ = $CA
PRODOS_MLI_OPEN = $C8
TRACKS_PER_SIDE = 35
BYTES_PER_SECTOR = 256
SECTORS_PER_TRACK = 16
; Zero page locations
; -------------------
end_hgr_line_pointer = 220
hgr_tile = 222
pointer = 224
pointer2 = 226
;; lo_hi_bits_reverse_ptr = 226
stripe_ptr = 228
tile_pointer = 230
stripe_index = 232
count1 = 234
count2 = 235
count3 = 236
remaining_bytes_on_line = 236
command_byte = 238
line_split = 239
expand_pixels_table1_ptr = 240
expand_pixels_table2_ptr = 242
rle_pointer = 244
screen_pointer = 246
cmd_pointer = 248
screen_line_ptr = 250
screen_pointer_plus_one = 252
filler_ptr = 252
dummy_ptr = 254
; Other constants
disk_buffers_base = $DA00 ; you'll need 64kb RAM to do that (language card!)
; Prodos stuff
wtemp = $3a
midnib1 = wtemp+1
midnib2 = wtemp+2
lstnib = wtemp+3
slotz = wtemp + 4
yend = wtemp+5
buf = $44
*= $C00
; 83*256 = 21248 / 0xC000 - 0x4000 = 36864
+store_8 rs_sectors_to_read, 83
+store_8 target_track, 27
+store_8 target_sector, 13
+store_8 target_bank, $40
jsr read_sect
LDA #(' '+$80)
JSR clear_screen
+writeln msg
LDA #('>' + $80)
STA GETLNZ_PROMPT
;; Activate 64k in read/write mode
LDA LC_RAM_SELECT
LDA LC_RAM_SELECT
SECTORS_PRELOAD = 32
;; + 1 for the extra bytes which must be outside the buffer !!!
BEGIN_PRELOAD_BUFFER = disk_buffers_base + (2*SECTORS_PER_TRACK-SECTORS_PRELOAD+1)*BYTES_PER_SECTOR
+store_8 rs_sectors_to_read, SECTORS_PRELOAD
+store_8 target_track, 33
+store_8 target_sector, 0
+store_8 target_bank, >BEGIN_PRELOAD_BUFFER
jsr read_sect
+store_16 pointer, BEGIN_PRELOAD_BUFFER
jsr init_preload
!if DRIVE_SELECT = 0 {
LDX #0
print_flip_disk:
LDA flip_disk,X
CMP #0
BEQ wait_kbd
STA $750, X
INX
JMP print_flip_disk
wait_kbd:
STA $C010
wait_kbd_loop:
LDA $C000
BPL wait_kbd_loop
STA $C010
}
zgood:
;; +store_16 pop_path, datafile
;; JSR MLI
;; !byte PRODOS_MLI_OPEN
;; !word prodos_open_params ; $0E0C
;; LDA pop_ref
;; STA prp_ref
;; +store_16 prp_adr, $4000
;; JSR MLI
;; !byte PRODOS_MLI_READ ; Operation ($80=READ_BLOCK, $81=write)
;; !word prodos_read_params ; $0E0C
JMP zorglub
;; JMP main_start
flip_disk:
!byte $46,$4C,$49,$50,$60,$44,$49,$53,$4B,$60,$41,$4E,$44,$60,$48,$49,$54,$60,$41,$60,$4B,$45,$59
!byte 0
prodos_params:
!byte 3 ; 3 parameters
!byte SLOT_SELECT + DRIVE_SELECT
!word GR2_RAM ; Memory buffer, make sure it's not in ProDos's stuff
block_read !word $0001 ; Block to read
prodos_read_params:
!byte 4
prp_ref !byte 0
prp_adr !word 0
prp_len !word 4096
prp_alen !word 0
prodos_open_params:
!byte 3
pop_path !word 0
pop_buffer !word $9A00
pop_ref !byte 0
datafile !byte 6
!text "BADATA"
next_track_trigger !byte 64
next_read_sector !byte 32
current_sector !byte 0
stripe_n !byte 0
track_seek_countdown_value = 10
track_seek_countdown !byte track_seek_countdown_value
; ####################################################################
; ### MAIN START
; ####################################################################
hgr_tile_data:
;; lo bits are aligned on the left
!byte 255,127,63,31,15,7,3,1
!byte 255,255,255,255,255,255,255,255
!byte 255,255,255,255,0,0,0,0
!byte %00111110
!byte %01000011
!byte %01000101
!byte %01001001
!byte %01010001
!byte %01100001
!byte %01010001
!byte %00111110
tiles_hgr:
!for i,127 {
!word tiles + (i-1)*8 - 1
}
hgr_strip:
!byte 0,1,2,3,2,1,0,0,1,2,3,2,1,0,0,1,2,3,2,1,0,0,1,2,3,2,1,0,0,1,2,3,2,1,0
CENTERING = (40 - HORIZONTAL_TILES) >> 1
hgr_lines_offsets = * + (( (192/8) - VERTICAL_TILES) / 2) * 2
!for i,8 {
!word HGR_RAM + (i-1)*$80 + CENTERING
}
!for i,8 {
!word HGR_RAM + $28 + (i-1)*$80 + CENTERING
}
!for i,8 {
!word HGR_RAM + $50 + (i-1)*$80 + CENTERING
}
!macro setup_hgr_line_pointers {
;; Compute beginnig and end of the first line of the tile on the screen
LDA hgr_current_line ; From 0 to 23 (x8 to have pixels => 0-184)
ASL ; bit 7 shifted into carry; sinc evalue is small, carry is cleared
TAY
;; The hi-byte of count determines the line; the low byte gives offset in the line
LDA hgr_lines_offsets,Y
STA screen_pointer
LDA hgr_lines_offsets + 1,Y
STA screen_pointer + 1
;; Compute the end of the line
LDA hgr_lines_offsets,Y
CLC ; FIXME useless
ADC #HORIZONTAL_TILES ; 40*7 = 280 pixels
STA end_hgr_line_pointer
}
!macro advance_screen_pointers_right {
!zone {
;; Next tile (on screen)
clc
lda screen_pointer
adc #1
sta screen_pointer
cmp end_hgr_line_pointer
bne .still_in_line
inc hgr_current_line
+setup_hgr_line_pointers
.still_in_line:
}
}
current_offset !word $2020 ;32
hgr_current_line !byte 3
hgr_line_end !word $2028
stripe_len !byte 12
scount1 !byte 0
scount2 !byte 0
;; main_start:
;; jsr set_hgr_mode
;; jsr clear_screen
;; jsr clear_hgr
;; lda #0
;; sta hgr_current_line
;; +store_16 stripe_ptr, hgr_strip
;; +setup_hgr_line_pointers
;; LDA screen_pointer
;; ADC #30
;; STA screen_pointer
;; LDA #10+3
;; STA count3
;; .hgr_tile_loop1:
;; LDY count3
;; LDA (stripe_ptr),Y ; From tile number...
;; ASL
;; LDA #$FF
;; JSR hgr_mono_tile_expander
;; ;; JSR hgr_tile_expander
;; DEC count3
;; BNE .hgr_tile_loop1
;; JSR GETLNZ
;; JMP zorglub
;; ;; ---------------------------------------------------------------------
;; ;; Split stripe if necessary
;; lda current_offset ; tiles to write
;; clc
;; adc stripe_len
;; cmp hgr_line_end
;; bmi no_split
;; ; current_ofs + stripe_len < hgr_line_end
;; ;; eor #$FF
;; ;; clc
;; ;; adc #$1
;; lda stripe_len
;; sta count1
;; lda #0
;; sta count2
;; no_split:
;; lda hgr_line_end
;; sec
;; sbc current_offset
;; sta count1
;; lda stripe_len
;; sec
;; sbc count1
;; sta count2
;; ---------------------------------------------------------------------
zorglub:
;; jsr load_current_stripe
;; jsr read_bits
;; clc
;; inc debug
;; lda #$EE
;; cmp debug
;; bne zorglub
;; lda pointer
;; lda pointer + 1
;; rol data
;; rol data + 1
;; jmp zorglub
;; debug !byte 0
lda #' '+$80
jsr clear_screen
jsr clear_hgr
jsr set_hgr_mode
;; LDA #0
;; JSR clear_screen
;; JSR init_disk_read
!if DRIVE_SELECT = $80 {
LDX #SLOT_SELECT
LDA DRV2_SLCT, X
}
LDA #SLOT_SELECT
JSR sector_zero
LDA #0
STA hgr_current_line
+store_16 screen_pointer, HGR_RAM
+setup_hgr_line_pointers
jmp main_control
; ----------------------------------------------------------------------------
TRACK_DATA_BANK = disk_buffers_base >> 8
TRACK_DATA_BANK_OUT = (disk_buffers_base+2*SECTORS_PER_TRACK*BYTES_PER_SECTOR) >> 8
stay_on_first_track !byte 0
read_disk_delay !byte 0
track_buffer !byte 0 ; (0 or 16) Track buffer being read into
track_status !fill SECTORS_PER_TRACK*2,0
sectors_to_read !byte SECTORS_PER_TRACK
main_control:
;; jsr preload_sectors
;; jsr copy_compressed
.main_control_loop:
!if DRAW_STATUS = 1 {
jsr draw_status
}
ldx #SLOT_SELECT
jsr rdadr16
bcs .main_control_loop ; Cheap retry
;; From now on, time is ticking, we must do
;; as much as we can before the read latch
;; comes on the sector data.
; Decide what to do next
PAUSE = 4 ; ok for applewin
LDA sectors_passed
CMP #PAUSE ; Decrunching a picture takes up to 4 sectors "long". With this timeing, I reach roughly 3min 40s which is the time we look for.
BMI .noframe
SEC
SBC #PAUSE
STA sectors_passed
; Read a sector before drawing, else we always miss that sector
; because the synchronisation with the disk is very clean
jsr read_sector_if_necessary
jsr process_a_frame
jmp .main_control_loop
.noframe:
lda sectors_to_read
cmp #0
beq .wait_processing
lda sect
clc
adc track_buffer
tay
LDA track_status,Y
CMP #0 ; Sector is yet to be read
beq .read_a_sector
bne .main_control_loop
.read_a_sector:
jsr read_any_sector
bcs .main_control_loop
.wait_processing:
jsr change_track_if_necessary
.unexpected_sector:
jmp .main_control_loop
.error:
RTS
read_unread_sector:
!zone {
ldx #SLOT_SELECT
jsr rdadr16
bcs .error
read_sector_if_necessary:
lda sect
clc
adc track_buffer
tay
lda track_status, Y
cmp #0
beq read_any_sector
rts
read_any_sector:
;; lda read_disk_delay
;; cmp #0
;; bne .success
; Prepare RWTS buffer
lda #0
sta buf
lda sect
clc
adc track_buffer
clc
adc #TRACK_DATA_BANK
sta buf + 1
; Read the sector
ldx #SLOT_SELECT
jsr read16
bcs .error
lda sect
clc
adc track_buffer
tay
; Defensive programming
lda track_status, Y
cmp #0
bne .error ; unexpected sector
; mark sector as read
lda #1
sta track_status, Y
dec sectors_to_read
!if compression = LZ {
;; Allow some wraping
lda sect
clc
adc track_buffer
cmp #0
bne .no_wrap
LDA TRACK_DATA_BANK << 8
STA TRACK_DATA_BANK_OUT << 8
LDA (TRACK_DATA_BANK << 8) + 1
STA (TRACK_DATA_BANK_OUT << 8) + 1
LDA (TRACK_DATA_BANK << 8) + 2
STA (TRACK_DATA_BANK_OUT << 8) + 2
.no_wrap:
}
.success:
CLC
RTS
.error:
SEC
RTS
}
; ----------------------------------------------------------------------------
still_in_memory !byte 1
in_memory_process:
!zone {
lda pointer + 1
cmp #TRACK_DATA_BANK + SECTORS_PER_TRACK
bmi .not_yet
lda #0
sta still_in_memory
lda #0
sta track_buffer
lda #SECTORS_PER_TRACK
sta sectors_to_read
JSR clear_read_status
.not_yet:
RTS
}
change_track_if_necessary:
lda #0
cmp still_in_memory
bne in_memory_process
.regular_process:
; Are all sectors read?
lda sectors_to_read
cmp #0
bne .no_track_change
; Are all other sectors data processed ?
lda track_buffer
eor #SECTORS_PER_TRACK
clc
adc #TRACK_DATA_BANK
clc
adc #SECTORS_PER_TRACK ; first sector after the end of buffer
!if compression = LZ {
cmp pointer + 1
} else {
cmp stripe_index + 1
}
bne .no_track_change
change_track:
; Track advance and buffer swap
jsr advance_drive_latch
bcc track_advanced
SEC
RTS
track_advanced:
;; Set pointer (attention! we only reset the pointer when at the end of BOTH the buffers)
lda #TRACK_DATA_BANK_OUT
cmp pointer + 1
bne .not_at_end
;; jsr huff_pointer_at_end
;; bcc .not_at_end
+sub_const_from_16 pointer, 2*SECTORS_PER_TRACK*BYTES_PER_SECTOR
.not_at_end:
; switch track buffer
lda track_buffer
eor #SECTORS_PER_TRACK
sta track_buffer
lda #SECTORS_PER_TRACK
sta sectors_to_read
JSR clear_read_status
; Set stripe index
lda #0
sta stripe_index
lda track_buffer
eor #SECTORS_PER_TRACK
clc
adc #TRACK_DATA_BANK
sta stripe_index + 1
.no_track_change:
CLC
RTS
; ----------------------------------------------------------------------------
check_stripe_at_end:
lda track_buffer
eor #SECTORS_PER_TRACK
clc
adc #TRACK_DATA_BANK
clc
adc #SECTORS_PER_TRACK ; Last sector + 1 (ie one sector too far)
cmp stripe_index + 1 ; Hi byte of stripe index beacuse a sector is 256 bytes.
beq .at_end
CLC
RTS
.at_end:
SEC
RTS
; ----------------------------------------------------------------------------
clear_read_status:
!zone {
lda #0
ldy track_buffer
ldx #0
.loop:
sta track_status,y
iny
inx
cpx #SECTORS_PER_TRACK
bne .loop
}
rts
; ----------------------------------------------------------------------------
!macro pixel {
CMP #1
BEQ .sector_read
CMP #2
BEQ .sector_preloaded
LDA #'.' + $80
JMP .go_on
.sector_preloaded:
LDA #'!' + $80
JMP .go_on
.sector_read:
LDA #'-' + $80
.go_on:
}
!if DRAW_STATUS = 1 {
STATUS_BUFFER = $7D0 ; $750 $650
STATUS_BUFFER2 = $750
STATUS_BUFFER3 = HGR_RAM + $800
draw_status:
;; Draw the track status
lda #0
ldy #0
draw_status0:
LDA track_status, Y ; 0 or 1
+pixel
STA STATUS_BUFFER,Y
INY
CPY #SECTORS_PER_TRACK*2
BNE draw_status0
LDA #' ' + $80
draw_status1:
STA STATUS_BUFFER, Y
INY
CPY #40
BNE draw_status1
LDY #0
draw_status2:
TYA
CMP #10
BMI under10
CLC
ADC #'A'+$80 - 10
jmp hexband
under10:
CLC
ADC #'0'+$80
hexband:
STA STATUS_BUFFER2, Y
INY
CPY #SECTORS_PER_TRACK
BNE draw_status2
;; Draw the memory pointer
LDA pointer+1
SEC
SBC #TRACK_DATA_BANK
BCC .no_mem_draw
TAY
LDA #$0D ; M inverse
CLC
ADC still_in_memory
;; ORA STATUS_BUFFER2,Y
STA STATUS_BUFFER,Y
.no_mem_draw:
;; Draw the disk head
lda sect
clc
adc track_buffer
tay
lda STATUS_BUFFER,Y
and #$7F ; flashing
sta STATUS_BUFFER,Y
;; Draw the skipped sectors
;; lda sectors_passed
;; tay
;; lda #%01110101
;; sta STATUS_BUFFER3,Y
RTS
}
; ----------------------------------------------------------------------------
; -----------------------------------------------------------------------------
;; end_picture_reached !byte 0
frame_number !word 0
half_frame !byte 0
process_a_frame:
lda frame_number
cmp #(TOTAL_FRAMES & $FF)
bne .frames_left
lda frame_number + 1
cmp #(TOTAL_FRAMES >> 8)
bne .frames_left
sec
rts
.frames_left:
lda half_frame
and #1
bne process_a_frame_loop
;; jsr sound
process_a_frame_loop2:
JSR load_current_stripe
BCS .end2
JSR draw_a_stripe
;; !if compression != LZ {
LDA #2
+add_a_to_16 stripe_index