forked from jbrandwood/teos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
osfunc.s
1109 lines (877 loc) · 24.2 KB
/
osfunc.s
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
TOS_OK = $00
TOS_BAD_HUCARD = $A1
TOS_WRONG_SIZE = $A2
.bss
FILES_PER_PAGE = 20
MAX_NUM_PAGES = 99
MAX_NAME_LENGTH = 64 ; 120 if scrolling.
; Current selection path, here in the OS itself so that
; it is can persist in TED2 RAM while a cart is run.
tos_file_count: ds 2
tos_show_page: ds 1 ; Only for onscreen display.
tos_num_pages: ds 1
tos_num_files: ds 1
tos_name_length:ds FILES_PER_PAGE * 1
tos_1st_cluster:ds FILES_PER_PAGE * 4
tos_file_length:ds FILES_PER_PAGE * 4
tos_file_type: ds FILES_PER_PAGE * 1
.code
; ****************************************************************************
; ****************************************************************************
;
; tos_decompress - Decompress data fron the aPLib file container.
;
; Args: Y - chunk offset into container file (4 or 8 for 1st 2 files).
;
tos_decompress: clc
lda apl_font_data + 0,y
adc #<apl_font_data
sta <apl_srcptr + 0
lda apl_font_data + 1,y
adc #>apl_font_data
and #$1F
ora #$60
sta <apl_srcptr + 1
lda #BANK(apl_font_data) + 1
tam3
lda #>$3000
stz <apl_dstptr + 0
sta <apl_dstptr + 1
jsr apl_decompress
rts
; ***************************************************************************
; ***************************************************************************
;
; tos_screen_mode - Change screen mode.
;
; Args X reg = Lo-byte of address of screen definition table.
; Args A reg = Hi-byte of address of screen definition table.
;
tos_screen_mode:pha
lda #$08 ; BKG & SPR off, VSYNC IRQ on.
sta <vdc_crl
jsr wait_vsync
pla
jsr init_vdc
lda #$88 ; BKG on, VSYNC IRQ on.
sta <vdc_crl
rts
; ****************************************************************************
; ****************************************************************************
;
; tos_scan_dir - Change directory and update UI info for the new directory.
;
tos_scan_dir: lda #$FF ; Find out how many selectable
sta <__ax + 0 ; entries there are in this
sta <__ax + 1 ; directory.
jsr tos_fastfwd_dir
lda <__ax + 0 ; Xvert the return value into
eor #$FF ; a file count.
sta <__ax + 0
sta tos_file_count + 0
lda <__ax + 1
eor #$FF
sta <__ax + 1
sta tos_file_count + 1
lda #FILES_PER_PAGE ; Find out how many pages of
sta <__cl ; entries in this directory.
jsr tos_div16_7u
lda <__dl + 0 ; Add a page for the remainder.
beq .skip1
inc <__ax + 0
bne .skip1
inc <__ax + 1
.skip1: ldx <__ax + 0 ; Limit the # of pages shown.
cpx #MAX_NUM_PAGES + 1
lda <__ax + 1
sbc #0
bcc .skip2
ldx #MAX_NUM_PAGES ; Too many pages!
.skip2: stx tos_num_pages
ldx #TOS_OK
.exit: rts
; ***************************************************************************
; ***************************************************************************
;
; tos_show_files - Show the current list of files/directories on this page.
;
tos_show_files: stz tos_num_files ; # of files on this page.
lda #3 ; First line on page.
sta tos_tty_ypos
stz tos_tty_xpos
stz tos_tty_xyok
.nxt_entry: jsr f32_nxt_entry ; Get nxt name in the directory.
beq .got_entry
.rest: tai .space, f32_long_name, 63 * 2
.rest_loop: lda tos_tty_ypos ; Blank out the rest of the
cmp #23 ; BRAM files in the box.
bcs .finished
lda #' '
jsr tos_tty_write
tia f32_long_name, VDC_DL, 63 * 2
stz tos_tty_xpos
inc tos_tty_ypos
stz tos_tty_xyok
bra .rest_loop
.space: dw $0120
.finished: rts
.got_entry: lda [__bp] ; End of Directory?
beq .rest
cmp #$E5 ; Empty entry?
beq .nxt_entry
cmp #'.' ; Skip ".." and "." entries.
beq .nxt_entry
.show_entry: ldy #DIR_Attr ; What type of entry is this?
lda [__bp],y
bit #ATTR_System + ATTR_Hidden
bne .nxt_entry ; Skip SYSTEM or HIDDEN files.
and #ATTR_Type_Mask
beq .valid_type ; It is a file.
cmp #ATTR_Directory
bne .nxt_entry ; It is a directory.
.valid_type: pha ; Preserve file type.
ldx tos_num_files ; # of files on this page.
sta tos_file_type,x
txa
asl a
asl a
tax
phx
ldy #DIR_FileSize
.copy_length: lda [__bp],y
sta tos_file_length,x
inx
iny
cpy #DIR_FileSize + 4
bne .copy_length
plx
ldy #DIR_FstClusLO
bsr .cluster_word
ldy #DIR_FstClusHI
bsr .cluster_word
ldx f32_name_length ; Clamp name length to the
cpx #MAX_NAME_LENGTH ; size that we can scroll.
bcc .name_ok
ldx #MAX_NAME_LENGTH ; Name too long,
.name_ok: pla ; Restore file type.
beq .skip_slash
lda #'/' ; Add a slash to directory
sta f32_long_name,x ; names.
inx
stx f32_name_length
.skip_slash: lda #' ' ; Pad the name out to the
.pad_string: cpx #64 ; screen width so it wipes
bcs .show_name ; out the previous contents.
sta f32_long_name,x
inx
bra .pad_string
.show_name: stz f32_long_name,x ; Terminate the string.
stz tos_tty_xpos
stz tos_tty_xyok
lda #' '
jsr tos_tty_write
; PUTS f32_long_name ; Write the name to VRAM.
PUTS .filename ; Write the name to VRAM.
stz tos_tty_xpos
inc tos_tty_ypos
stz tos_tty_xyok
ldx tos_num_files ; Store the name length.
lda f32_name_length
sta tos_name_length,x
inx ; # of files on this page.
stx tos_num_files
cpx #FILES_PER_PAGE
beq .page_full
jmp .nxt_entry
.page_full: rts
;
.cluster_word: lda [__bp],y
sta tos_1st_cluster,x
inx
iny
lda [__bp],y
sta tos_1st_cluster,x
inx
rts
.filename: db "%r"
dw f32_long_name
db "%s",0
; ****************************************************************************
; ****************************************************************************
;
; tos_fastfwd_dir - Goto (n)th selectable *short* entry in the current dir.
;
; The filename for the entry is not copied to f32_long_name.
;
; This is used to skip to the entry prior to the one that you want to read
; the long name from and display next.
;
; Args __ax = Entry # to go to 1..65536, corresponding to index # 0..65535.
; Uses __bp = Pointer to directory entry in cache.
;
; It can also be used to count the number of selectable entries in a dir ...
;
; lda #$FF
; sta <__ax + 0
; sta <__ax + 1
; jsr tos_fastfwd_dir
; lda <__ax + 0
; eor #$FF
; sta tos_file_count + 0
; lda <__ax + 1
; eor #$FF
; sta tos_file_count + 1
;
tos_fastfwd_dir:jsr f32_rewind_dir ; Goto 1st cluster in directory.
beq .get_entry
rts ; Return the error code.
.nxt_entry: clc ; Inc directory pointer.
lda <__bp + 0
adc #32
sta <__bp + 0
lda <__bp + 1
adc #0
sta <__bp + 1
cmp #>(f32_cache_buf + 512) ; Any entries left in cache?
bne .tst_entry
jsr f32_nxt_sector ; Increment the sector.
bcc .get_entry ; Still within the cluster?
jsr f32_nxt_cluster ; Increment the cluster.
beq .get_entry
rts ; Return the error code.
; Refresh the directory cache.
.get_entry: jsr f32_load_cache ; Load a directory sector.
beq .loaded
rts ; Return the error code.
.loaded: stz <__bp + 0 ; Reset directory pointer.
lda #>f32_cache_buf
sta <__bp + 1
lda <__ax + 0
ora <__ax + 1
beq .finished
; Test the current directory entry.
.tst_entry: lda [__bp] ; End of Directory?
beq .finished
cmp #$E5 ; Empty entry?
beq .nxt_entry
cmp #'.' ; Skip ".." and "." entries.
beq .nxt_entry
ldy #DIR_Attr ; Skip SYSTEM or HIDDEN files.
lda [__bp],y
bit #ATTR_System + ATTR_Hidden
bne .nxt_entry
and #ATTR_Long_Mask ; Part of a long name?
cmp #ATTR_Long_Name
beq .nxt_entry
and #ATTR_Type_Mask
beq .valid ; Is it a file?
cmp #ATTR_Directory
bne .nxt_entry ; Is it a directory?
.valid: lda <__al ; Decrement counter of files
bne .skip ; and directories found.
dec <__ah
.skip: dec <__al
bne .nxt_entry
lda <__ah
bne .nxt_entry
; The counter just hit zero!
.finished: ldx #SDC_OK
rts
; ***************************************************************************
; ***************************************************************************
;
; tos_load_hucard - Load a HuCard image from an open file into TED memory.
;
; Uses: f32_file_length = Length of file.
; Uses: f32_file_map = Data buffer containing the file map.
; Uses: f32_file_pos = Current fragment within the file map.
;
; N.B. The hack to skip the 1st sector on files with a header is
; nasty, and relies on internal details of fat32.s, yuk!!!!
;
.bss
tos_card_size: ds 1 ; Rounded size in 128KB.
tos_128k_card: ds 1 ; Exactly 384KB if == 3!
.code
tos_load_hucard:lda f32_file_length + 3 ; Reject file length >= 16MB.
bne .bad_hucard
clc ; Xvert length to block cnt.
lda f32_file_length + 0
adc #$FF
lda f32_file_length + 1
adc #$01
tax
lda f32_file_length + 2
adc #$00
ror a
sta <__ax + 1 ; Hi-byte of # blocks in file.
sta tos_card_size ; HuCard size in 128KB chunks.
sta tos_128k_card ; Z if not, else 128KB chunks.
sax
ror a
sta <__ax + 0 ; Lo-byte of # blocks in file.
bit #$0E ; Reject HuCard not a multiple
bne .bad_hucard ; of 8KB (+ 512 byte header).
bit #$F0 ; Is the HuCard a multiple of
beq .check_min ; 128KB?
stz tos_128k_card ; Signal not 128KB-aligned.
inc tos_card_size ; Round up to next 128KB.
.check_min: cpx #$00 ; Is the file size < 8KB?
bne .check_max
cmp #$10
bcc .bad_hucard ; Reject HuCard size < 8KB.
.check_max: sec ; Is the file size > 2.5MB?
sbc #$01
txa
sbc #$14
bcc .check_header ; Reject HuCard size > 2.5MB.
.bad_hucard: ldx #TOS_BAD_HUCARD ; Return error code.
jmp .close
.check_header: bbr0 <__ax + 0, .starting_bank
lda f32_sec2cls_cnt ; Sanity Check that the math
cmp #2 ; below won't fail. KRIKzz
bcc .bad_hucard ; enforces a min of 8 anyway.
dec <__ax + 0 ; *HACK* odd # blocks if header.
inc f32_file_pos + 0 ; *HACK* addr of 1st fragment.
dec f32_file_pos + 4 ; *HACK* size of 1st fragment.
.starting_bank: lda #$40 ; Start at HuCard bank $00.
cpx #$03 ; If this a 384KB HuCard, then
bne .set_1st_bank ; start at the mirrored 256KB.
lda #$60 ; Start at HuCard bank $20.
.set_1st_bank: tam3
stz <sdc_data_addr + 0
lda #$60
sta <sdc_data_addr + 1
lda #$4F ; Map in TED2 512KB bank 4.
sta sdc_data_bank
sta TED_BASE_ADDR + TED_REG_MAP
jsr f32_file_read ; Load the file into memory.
bne .close
lda tos_128k_card ; Z if not, else 128KB chunks.
cmp #$03 ; Did we load a 384KB HuCard?
bne .success
lda #$4F ; Map in TED2 512KB bank 4.
sta TED_BASE_ADDR + TED_REG_MAP
jsr wait_vsync ; Wait for the screen.
php ; Disable interrupts.
sei
clc ; Copy bank $60-$7F to $40-$5F.
lda #$60
.copy_bank: tam3
adc #$E0 ; Assumes CC, will set C.
tam2
tii $6000,$4000,$2000
adc #$21-1 ; Assumes CS, will clr C.
bpl .copy_bank
lda VDC_SR ; Clear any pending VDC irq.
cla ; Restore TED hardware bank.
tam2
plp ; Restore interrupts.
.success: ldx #TOS_OK
.close: jmp f32_close_file ; Close the file & set N & Z.
; ***************************************************************************
; ***************************************************************************
;
; tos_fix_region - Search for and patch the TurboGrafx region test.
;
; Takes 219 cycles if the code is found, less if it is not.
;
tos_fix_region: lda #$4F ; Map in TED2 512KB bank 4.
sta TED_BASE_ADDR + TED_REG_MAP
lda #$40 ; Select bank 0 of the HuCard
tam3 ; image in TED2 memory.
clc ; Try 6 bytes after the reset
lda #6 ; vector.
adc $7FFE
sta <__bp + 0
cla
adc $7FFF
and #$1F
ora #$60
sta <__bp + 1
bsr .find_start ; Test for the code sequence.
lda #<$6391 ; Try $E391 in HuCard bank 0.
sta <__bp + 0
lda #>$6391
sta <__bp + 1
.find_start: lda [__bp] ; 1st byte of region code?
cmp #$AD
bne .finished
cly
.test_loop: iny ; Check for the rest of the
lda [__bp],y ; code sequence.
cmp .sequence - 1,y
bne .finished
cpy #$0A
bne .test_loop
.patch: lda #$80 ; Patch in BRA instruction.
ldy #$05
sta [__bp],y
.finished: rts
.sequence: db $00,$10,$29,$40,$F0,$0C,$A9,$90
db $53,$04
; ***************************************************************************
; ***************************************************************************
;
; tos_exec_hucard - Execute the HuCard that we've got loaded in memory.
;
; Bit 0 : cfg_regs_oe_off : Bank 0 mapping (0=FPGA, 1=RAM)
; Bit 1 : cfg_regs_we_off : FPGA Registers (0=access, 1=locked)
; Bit 2 : cfg_usb_boot : unknown (leave zero)
; Bit 3 : cfg_skip_eep : Normally set by KRIKzz : unknown (set to 1)
; Bit 4 : cfg_ram_we_off : RAM Read-Only? (0=writable, 1=read-only)
; Bit 5 : : SF2 2MB mapper (0=disabled, 1=enabled) Only $1ff0-$1ff3.
; Bit 6 : : unknown (leave zero)
; Bit 7 : : unknown (leave zero)
;
tos_exec_hucard:lda #$4F ; Map in TED2 512KB bank 4.
sta TED_BASE_ADDR + TED_REG_MAP
lda #$40 ; Select bank 0 of the HuCard
tam3 ; image in TED2 memory.
jsr tos_fix_region ; Fix TurboGrafx to run on PCE.
; Check for HuCards that need special handling.
lda tos_128k_card ; Skip the test if the HuCard
beq .test_done ; is not aligned to 128KB.
lda #<.hucard_tbl ; Table of signatures of images
sta <__al ; that need special handling.
lda #>.hucard_tbl
sta <__ah
ldx #4-1 ; # of signatures to search for.
.test_card: ldy #15-1
lda [__ax],y ; Does the HuCard size match?
dey
cmp tos_128k_card ; Z if not, else 128KB chunks.
bne .fail
lda [__ax],y ; Get ptr to card's test area.
dey
sta <__bh
lda [__ax],y
dey
sta <__bl
.test_loop: lda [__ax],y ; Compare signature with 12
cmp [__bx],y ; bytes of data from the card.
bne .fail
dey
bpl .test_loop
.found: txa ; Found a matching HuCard!
asl a
tax
jsr .vector_jmp ; Call a routine to provide
bra .execute ; the special handling.
.fail: clc ; Not a match, try the next
lda <__al ; signature.
adc #15
sta <__al
bcc .test_next
inc <__ah
.test_next: dex
bpl .test_card
; If it's not a special case HuCard, then run it as a ROM.
.test_done: ldy #%00011011 ; FPGA=off+locked, RAM=readonly.
lda tos_card_size ; Enable SF2 mapper if the
cmp #8+1 ; HuCard is > 1MBytes.
bcc .execute
ldy #%00111011 ; SF2=enabled.
.execute: sei ; Definitely disable interrupts!
phy ; Preserve FPGA flags to write.
ldx #<video_mode_nul ; Set VDC registers to safe
lda #>video_mode_nul ; values, with RCR for sync.
jsr init_vdc
lda #$4F ; Set 512KB mapping for HuCard.
sta TED_BASE_ADDR + TED_REG_MAP
lda #$40
tam3
ply ; Restore FPGA flags to write.
lda #$F8 ; Map in regular PCE RAM.
tam1
tii .trampoline, $2200, (.trampoline_end - .trampoline)
; Fix "Order of the Griffon" uninitialized palette issue.
;
; Reset final background graphics palette entry to #$1FF
; to resemble 'uninitialized' state
lda #$FF
sta VCE_CTA + 0
stz VCE_CTA + 1
sta VCE_CTW + 0
lda #$01
sta VCE_CTW + 1
; Fix "Tower of Druaga" initialization timing issue.
;
; Wait twice to ensure that a vblank occurs between the
; two, and that the screen is definitely blank.
.wait_rcr1: lda VDC_SR ; Wait for the RCR at line 0.
bit #$04
beq .wait_rcr1
.wait_rcr2: lda VDC_SR ; Wait for the RCR at line 0.
bit #$04
beq .wait_rcr2
st0 #$05 ; Disable RCR interrupt.
st1 #$00
jmp $2200 ; Exec the trampoline in RAM.
; This stub gets copied to PCE RAM and run from there.
.trampoline: lda #%00011000 ; FPGA=on+writable, RAM=readonly.
sta TED_BASE_ADDR + TED_REG_CFG
lda #$04 ; Set 512KB mapping for HuCard.
sta TED_BASE_ADDR + TED_REG_MAP
; Set HuCard-specific config.
sty TED_BASE_ADDR + TED_REG_CFG
cla ; Put Bank $00 in MPR7.
tam7
csl ; Simulate a reset.
jmp [$FFFE]
.trampoline_end:
;
.vector_jmp: jmp [.vector_tbl,x]
.vector_tbl: ;dw .found_stft2 ; #0
dw .found_romram ; #0
dw .found_tennokoe ; #1
dw tos_patch_usa30 ; #2 - Call function to patch.
dw tos_patch_jpn30 ; #3 - Call function to patch.
; Tennokoe is a ROMRAM HuCard, and needs writable RAM.
; Populous is a ROMRAM HuCard, and needs writable RAM.
.found_tennokoe:jsr tos_patch_tbank ; Patch Tennokoe Bank HuCard.
jsr tos_load_tbank ; Load Tennokoe Bank SRAM file.
inc tos_tennokoe ; Signal that it needs saving.
.found_romram: ldy #%00001011 ; FPGA=off+locked, RAM=writable.
rts
; Street Fighter II needs the TED2's SF2 mapper enabled.
.found_stft2: ldy #%00111011 ; FPGA=off+locked, RAM=readonly,
rts ; SF2=enabled.
.hucard_tbl: ; #3 - 256KB System Card 3.0 PCE @ Location $1FF4
db $68,$80,$36,$E7,$70,$E8,$B3,$E6,$A9,$E6,$F3,$E0
dw $7FF4
db $02 ; 256KB size.
; #2 - 256KB System Card 3.0 TGX @ Location $1FF4
db $68,$80,$4F,$E7,$89,$E8,$CC,$E6,$C2,$E6,$F3,$E0
dw $7FF4
db $02 ; 256KB size.
; #1 - 128KB Tennokoe Bank @ Location $1FD0
db $93,$56,$82,$CC,$90,$BA,$83,$6F,$83,$93,$83,$4E
dw $7FD0
db $01 ; 128KB size.
; #0 - 512KB Populous @ Location $1F25
db " POPULOUS "
dw $7F25
db $04 ; 512KB size.
; ; #0 - 2.5MB Street Fighter II @ Location $1FF4
; db $20,$48,$BC,$E1,$C1,$E1,$60,$3C,$BD,$E1,$00,$E0
; dw $7FF4
; db $14 ; 2.5MB size.
; ****************************************************************************
; ****************************************************************************
;
; tos_set_hilite - Set the BAT for the tiles on the current line to hilite.
; tos_clr_hilite - Set the BAT for the tiles on the current line to normal.
;
tos_set_hilite: stz tos_hilite_idx
bsr selected_line
ldx #127
lda #$10
ldy #'>'
sty VDC_DL
tsb VDC_DH
.loop: ldy VDC_DL
sty VDC_DL
tsb VDC_DH
dex
bne .loop
rts
tos_clr_hilite: bsr selected_line
ldx #127
lda #$10
ldy #' '
sty VDC_DL
tsb VDC_DH
.loop: ldy VDC_DL
sty VDC_DL
trb VDC_DH
dex
bne .loop
rts
selected_line: php
sei
ldx tos_cur_depth
lda tos_cur_file,x
inc a
inc a
inc a
lsr a
tax
cla
ror a
st0 #VDC_MARR
sta VDC_DL
st0 #VDC_MAWR
sta VDC_DL
st0 #VDC_MARR
stx VDC_DH
st0 #VDC_MAWR
stx VDC_DH
vreg #VDC_VRR
plp
rts
; ****************************************************************************
; ****************************************************************************
;
; tos_pulse_color - Color cycle the palette index used for highlighted items.
;
tos_pulse_color:lda tos_hilite_idx
inc a
and #$7F
sta tos_hilite_idx
lsr a
lsr a
lsr a
tax
lda tos_hilite_tbl,x
asl a
asl a
asl a
ora tos_hilite_tbl,x
asl a
asl a
asl a
ora tos_hilite_tbl,x
tax
cla
rol a
ldy #$1E ; Hilite for 8x8 text.
sty VCE_CTA + 0
stz VCE_CTA + 1
stx VCE_CTW + 0
sta VCE_CTW + 1
ldy #$1A ; Hilite for 8x12 text.
sty VCE_CTA + 0
stz VCE_CTA + 1
stx VCE_CTW + 0
sta VCE_CTW + 1
rts
if 1
tos_hilite_tbl: db 6,6,6,6,6,6,6,6
db 6,6,6,5,4,3,4,5
else
tos_hilite_tbl: db 6,6,6,6,6,6,6,6
db 6,5,4,3,2,3,4,5
tos_hilite_tbl: db 7,7,7,7,7,7,7,7
db 7,7,7,6,5,4,5,6
tos_hilite_tbl: db 7,7,7,7,7,7,7,7
db 7,7,7,7,7,6,5,6
endif
.bss
tos_hilite_idx: ds 1
.code
; ***************************************************************************
; ***************************************************************************
;
; tos_init_crc16 - Initialize the CRC16 lookup tables in RAM.
;
; By Paul Guertin. See http://6502.org/source/integers/crc.htm
;
; CCITT CRC-16 as used by ZMODEM/YMODEM/XMODEM/etc.
;
; Takes 60942 cycles to create the tables.
;
; name polynomial initial val
; CCITT 1021 FFFF
; XModem 1021 0000
;
crc16_tbl_lo: = $3700 ; 256-bytes
crc16_tbl_hi: = $3800 ; 256-bytes
tos_init_crc16: clx ; X counts from 0 to 255
.byte_loop: cla ; Lo 8 bits of the CRC-16
stx <__al ; Hi 8 bits of the CRC-16
ldy #8 ; Y counts bits in a byte
.bit_loop: asl a
rol <__al ; Shift CRC left
bcc .no_add ; Do nothing if no overflow
eor #$21 ; else add CRC-16 polynomial $1021
pha ; Save low byte
lda <__al ; Do high byte
eor #$10
sta <__al
pla ; Restore low byte
.no_add: dey
bne .bit_loop ; Do next bit
sta crc16_tbl_lo,x ; Save CRC into table, low byte
lda <__al ; then high byte
sta crc16_tbl_hi,x
inx
bne .byte_loop ; Do next byte
rts
;
updcrc16: eor <__ax + 1 ; Quick CRC computation with lookup tables
tax
lda <__ax + 1
eor crc16_tbl_hi,x
sta <__ax + 1
lda crc16_tbl_lo,x
sta <__ax + 0
rts
; Example: Computing the CRC-16 of 256 bytes of data in $1000-$10FF.
jsr tos_init_crc16
ldy #$FF
sty <__ax + 0
sty <__ax + 1
iny
.loop: lda $1000,y
jsr updcrc16
iny
bne .loop
rts
; ***************************************************************************
; ***************************************************************************
;
; tos_init_crc32 - Initialize the CRC32 lookup tables in RAM.
;
; By Paul Guertin. See http://6502.org/source/integers/crc.htm
;
; CRC-32 as used by ZIP/PNG/ZMODEM/etc.
;
; Takes 112654 cycles to create the tables.
;
crc32_tbl_b0 = $3900 ; 256-bytes
crc32_tbl_b1 = $3A00 ; 256-bytes
crc32_tbl_b2 = $3B00 ; 256-bytes
crc32_tbl_b3 = $3C00 ; 256-bytes
tos_init_crc32: clx ; X counts from 0 to 255
.byte_loop: cla ; A contains the high byte of the CRC-32
sta <__ax + 2 ; The other three bytes are in memory
sta <__ax + 1
stx <__ax + 0
ldy #8 ; Y counts bits in a byte
.bit_loop: lsr a ; The CRC-32 algorithm is similar to CRC-16
ror <__ax + 2 ; except that it is reversed (originally for
ror <__ax + 1 ; hardware reasons). This is why we shift
ror <__ax + 0 ; right instead of left here.
bcc .no_add ; Do nothing if no overflow
eor #$ED ; else add CRC-32 polynomial $EDB88320
pha ; Save high byte while we do others
lda <__ax + 2
eor #$B8 ; Most reference books give the CRC-32 poly
sta <__ax + 2 ; as $04C11DB7. This is actually the same if
lda <__ax + 1 ; you write it in binary and read it right-
eor #$83 ; to-left instead of left-to-right. Doing it
sta <__ax + 1 ; this way means we won't have to explicitly
lda <__ax + 0 ; reverse things afterwards.
eor #$20
sta <__ax + 0
pla ; Restore high byte.
.no_add: dey
bne .bit_loop ; Do next bit
sta crc32_tbl_b3,x ; Save CRC into table, high to low bytes.
lda <__ax + 2
sta crc32_tbl_b2,x
lda <__ax + 1
sta crc32_tbl_b1,x
lda <__ax + 0
sta crc32_tbl_b0,x
inx
bne .byte_loop ; Do next byte
rts
updcrc32: eor <__ax + 0 ; Quick CRC-32 computation with lookup tables
tax
lda <__ax + 1
eor crc32_tbl_b0,x
sta <__ax + 0
lda <__ax + 2
eor crc32_tbl_b1,x
sta <__ax + 1
lda <__ax + 3
eor crc32_tbl_b2,x
sta <__ax + 2
lda crc32_tbl_b3,x
sta <__ax + 3
rts
; Example: Computing the CRC-32 of 256 bytes of data in $1000-$10FF.
jsr tos_init_crc32
ldy #$FF
sty <__ax + 0