-
Notifications
You must be signed in to change notification settings - Fork 0
/
prorwts2.a
executable file
·3936 lines (3610 loc) · 120 KB
/
prorwts2.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
; Dec 29, 2022 - FM
; forked from below with some tweaks by qkumba
; 'fix end detection' commit 56f76d4045ad4c0d7daefa853899535f829bb87a
; @peterferrie committed Oct 7, 2022
; https://github.com/peterferrie/prorwts2
;license:BSD-3-Clause
;extended open/read/write binary file in ProDOS filesystem, with random access
;copyright (c) Peter Ferrie 2013-2022
;assemble using ACME
ver_02 = 1
!if ver_02 = 1 {
!cpu 6502
} else { ;ver_02 = 0
!cpu 65c02
} ;ver_02
;!to "prorwts2#060800",plain
;*=$800
;place no code before init label below.
;user-defined options
verbose_info = 1 ;set to 1 to enable display of memory usage
enable_floppy= 0 ;set to 1 to enable floppy drive support
poll_drive = 0 ;set to 1 to check if disk is in drive, recommended if allow_multi is enabled
use_smartport= 1 ;set to 1 to enable support for more than two MicroDrive (or more than four CFFA) partitions
override_adr = 1 ;set to 1 to require an explicit load address
aligned_read = 0 ;set to 1 if all reads can be a multiple of block size (required for RWTS mode)
enable_readseq=1 ;set to 1 to enable reading multiple sequential times from the same file without seek
;(exposes a fixed address that can be called for either floppy or hard disk support)
;requires fast_subindex
;can also be used for sequential writes, but size must be 512-aligned
enable_write = 0 ;set to 1 to enable write support
;file must exist already and its size cannot be altered
;writes occur in multiples of block size
enable_format= 0 ;used only by RWTS mode, requires enable_write and fast_subindex
enable_seek = 0 ;set to 1 to enable seek support
;seeking with aligned_read=1 requires non-zero offset
allow_multi = 0 ;set to 1 to allow multiple floppies
allow_zerovol= 0 ;set to 1 to support volume 0 (=last used volume)
check_chksum = 0 ;set to 1 to enforce checksum verification for floppies
allow_subdir = 0 ;set to 1 to allow opening subdirectories to access files
might_exist = 0 ;set to 1 if file is not known to always exist already
;makes use of status to indicate success or failure
many_files = 0 ;set to 1 to support more than 256 files in a directory
detect_wp = 0 ;detect write-protected floppy during writes
allow_aux = 1 ;set to 1 to allow read/write directly to/from aux memory
;requires load_high to be set for arbitrary memory access
;else driver must be running from same memory target
;i.e. running from main if accessing main, running from aux if accessing aux
allow_saplings=0 ;enable support for saplings
allow_trees = 1 ;enable support for tree files, as opposed to only seedlings and saplings
;required in RWTS mode if file > 128kb
fast_trees = 1 ;keep tree block in memory, requires an additional 512 bytes of RAM
always_trees = 1 ;set to 1 if the only file access involves tree files
;not compatible with allow_subdir, allow_saplings
;required in RWTS mode if allow_trees is enabled
detect_treof = 1 ;detect EOF during read of tree files
fast_subindex= 1 ;keep subindex block in memory, requires an additional 512 bytes of RAM
;halves the disk access for double the speed (ideal for RWTS mode)
allow_sparse = 0 ;enable support for reading sparse files
write_sparse = 0 ;enable support for writing to sparse files (blocks are allocated even if empty)
;used only by RWTS mode, writing to sparse files in non-RWTS mode will corrupt the file!
bounds_check = 0 ;set to 1 to prevent access beyond the end of the file
;but limits file size to 64k-2 bytes.
return_size = 0 ;set to 1 to receive file size on open in read-only mode
one_shot = 0 ;set to 1 to load entire file in one pass (avoids the need to specify size)
no_interrupts= 0 ;set to 1 to disable interrupts across calls
detect_err = 0 ;set to 1 to to detect errors in no_interrupts mode
swap_zp = 0 ;set to 1 to include code to preserve zpage
;used only by RWTS mode
swap_scrn = 0 ;set to 1 to preserve screen hole contents across SmartPort calls
;recommended if allow_aux is used, to avoid device reset
;requires 64 bytes to save all holes
read_scrn = 0 ;set to 1 to support reading into screen memory
;requires swap_scrn
rwts_mode = 0 ;set to 1 to enable emulation of DOS RWTS when running from hard disk
;uses a one-time open of a tree file, no other file access allowed
;use unique volume numbers to distinguish between images in the same file
;requires override_adr, allow_trees, always_trees
;or fast_subindex if file is smaller than a tree
;not compatible with enable_floppy, allow_subdir, might_exist, bounds_check
mem_swap = 0 ;set to 1 if zpage can be swapped between main and aux, and swap_zp is unsuitable
;(caches index registers in code instead of zpage)
write_ffff = 0 ;set to 1 if there might be reads to $FFxx and allow_sparse=1
load_high = 0 ;set to 1 to load to top of RAM (either main or banked, enables a himem check)
load_aux = 0 ;load to aux memory
load_banked = 0 ;set to 1 to load into banked RAM instead of main RAM (can be combined with load_aux for aux banked)
lc_bank = 1 ;load into specified bank (1 or 2) if load_banked=1
one_page = 0 ;set to 1 if verbose mode says that you should (smaller code)
two_pages = 1 ;default size
three_pages = 0 ;set to 1 if verbose mode says that you should (code is larger than two pages)
;user-defined driver load address
!if load_banked = 1 {
!if load_high = 1 {
!ifdef PASS2 {
} else { ;PASS2 not defined
reloc = $ff00 ;page-aligned, as high as possible, the ideal value will be shown on mismatch
} ;PASS2
} else { ;load_high = 0
reloc = $d000 ;page-aligned, but otherwise wherever you want
} ;load_high = 1
} else { ;load_banked = 0
!if load_high = 1 {
!ifdef PASS2 {
} else { ;PASS2 not defined
reloc = $bf00 ;page-aligned, as high as possible, the ideal value will be shown on mismatch
} ;PASS2
} else { ;load_high = 0
reloc = $1000 ;page-aligned, but otherwise wherever you want ($BC00 is common for rwts_mode)
} ;load_high = 1
} ;load_banked = 1
;there are also buffers that can be moved if necessary:
;dirbuf, encbuf, treebuf (and corresponding hdd* versions that load to the same place)
;they are independent of each other so they can be placed separately
;see near EOF for those
;note that hddencbuf must be even-page-aligned in RWTS-mode
;zpage usage, arbitrary selection except for the "ProDOS constant" ones
;feel free to move them around
!if (might_exist + poll_drive + detect_wp) > 0 {
status = $50 ;returns non-zero on error
} ;might_exist = 1 or poll_drive = 1 or detect_wp = 1
!if allow_aux = 1 {
auxreq = $51 ;set to 1 to read/write aux memory, else main memory is used
} ;allow_aux = 1
sizelo = $52 ;set if enable_write=1 and writing, or reading, or if enable_seek=1 and seeking
sizehi = $53 ;set if enable_write=1 and writing, or reading, or if enable_seek=1 and seeking
!if (enable_write + enable_seek + allow_multi + rwts_mode) > 0 {
reqcmd = $54 ;set (read/write/seek) if enable_write=1 or enable_seek=1
;if allow_multi=1, bit 7 selects floppy drive in current slot (clear=drive 1, set=drive 2) during open call
;bit 7 must be clear for read/write/seek on opened file
} ;enable_write = 1 or enable_seek = 1 or allow_multi = 1 or rwts_mode = 1
ldrlo = $55 ;set to load address if override_adr=1
ldrhi = $56 ;set to load address if override_adr=1
namlo = $57 ;name of file to access
namhi = $58 ;name of file to access
!set last_zp = $58 ;highest address to save if swap_zp enabled (max 127 entries later)
!if write_sparse = 1 {
sparseblk = $59 ;(internal) last-read block was sparse if zero
!set last_zp = $59 ;highest address to save if swap_zp enabled (max 127 entries later)
} ;write_sparse = 1
!if enable_floppy = 1 {
tmpsec = $3c ;(internal) sector number read from disk
reqsec = $3d ;(internal) requested sector number
curtrk = $40 ;(internal) track number read from disk
} ;enable_floppy = 1
command = $42 ;ProDOS constant
unit = $43 ;ProDOS constant
adrlo = $44 ;ProDOS constant
adrhi = $45 ;ProDOS constant
bloklo = $46 ;ProDOS constant
blokhi = $47 ;ProDOS constant
scratchlo = $48 ;(internal)
scratchhi = $49 ;(internal)
entries = $3f ;(internal) total number of entries in directory
!if many_files = 1 {
entrieshi = $3b ;(internal) total number of entries in directory
} ;many_files = 1
!if mem_swap = 0 {
!if rwts_mode = 1 {
lasttree = $5a ;(internal) last used index in tree buffer
} ;rwts_mode = 1
!if allow_trees = 1 {
treeidx = $5b ;(internal) index into tree block
!set last_zp = $5b ;highest address to save if swap_zp enabled (max 127 entries later)
!if always_trees = 0 {
istree = $5c ;(internal) flag to indicate tree file
} ;always_trees = 0
!if fast_trees = 0 {
treeblklo = $5d
treeblkhi = $5e
!set last_zp = $5e ;highest address to save if swap_zp enabled (max 127 entries later)
} ;fast_trees = 0
} ;allow_trees = 1
blkidx = $5f ;(internal) index into sapling block list
!if rwts_mode = 1 {
lastblk = $60 ;(internal) previous index into sapling block list
!set last_zp = $60 ;highest address to save if swap_zp enabled (max 127 entries later)
} ;rwts_mode = 1
!if ((bounds_check or return_size) > 0) and ((rwts_mode or one_shot) = 0) {
bleftlo = $61 ;(internal) bytes left in file
} ;(bounds_check = 1 or return_size = 1) and (rwts_mode = 0 and one_shot = 0)
!if ((bounds_check or return_size or aligned_read) > 0) and ((rwts_mode or one_shot) = 0) {
blefthi = $62 ;(internal) bytes left in file
!set last_zp = $62 ;highest address to save if swap_zp enabled (max 127 entries later)
} ;(bounds_check = 1 or return_size = 1 or aligned_read = 1) and (rwts_mode and one_shot = 0)
!if aligned_read = 0 {
blkofflo = $63 ;(internal) offset within cache block
blkoffhi = $64 ;(internal) offset within cache block
!set last_zp = $64 ;highest address to save if swap_zp enabled (max 127 entries later)
} ;aligned_read = 0
} ;mem_swap = 0
!if enable_floppy = 1 {
step = $65 ;(internal) state for stepper motor
tmptrk = $66 ;(internal) temporary copy of current track
phase = $67 ;(internal) current phase for seek
!set last_zp = $67 ;highest address to save if swap_zp enabled (max 127 entries later)
} ;enable_floppy = 1
;constants
cmdseek = 0 ;requires enable_seek=1
cmdread = 1 ;requires enable_write=1
cmdwrite = 2 ;requires enable_write=1
SETKBD = $fe89
SETVID = $fe93
DEVNUM = $bf30
PHASEOFF = $c080
PHASEON = $c081
MOTOROFF = $c088
MOTORON = $c089
DRV0EN = $c08a
Q6L = $c08c
Q6H = $c08d
Q7L = $c08e
Q7H = $c08f
MLI = $bf00
NAME_LENGTH = $4 ;ProDOS constant
MASK_SUBDIR = $d0 ;ProDOS constant
MASK_ALL = $f0 ;ProDOS constant
KEY_POINTER = $11 ;ProDOS constant
EOF_LO = $15 ;ProDOS constant
EOF_HI = $16 ;ProDOS constant
AUX_TYPE = $1f ;ProDOS constant
ENTRY_SIZE = $27 ;ProDOS constant
NEXT_BLOCK_LO = $2 ;ProDOS constant
NEXT_BLOCK_HI = $3 ;ProDOS constant
SAPLING = $20 ;ProDOS constant
FILE_COUNT = $25 ;ProDOS constant
DEVADR01HI = $bf11 ;ProDOS constant
ROMIN = $c081
LCBANK2 = $c08b
CLRAUXRD = $c002
CLRAUXWR = $c004
SETAUXWR = $c005
CLRAUXZP = $c008
SETAUXZP = $c009
first_zp = $40 ;lowest address to save if swap_zp enabled
;last_zp is calculated automatically
D1S1 = 1 ;disk 1 side 1 volume ID if rwts_mode enabled
init jsr SETKBD
jsr SETVID
lda DEVNUM
sta x80_parms + 1
sta unrunit1 + 1
and #$70
!if (enable_floppy + enable_write) > 1 {
sta unrslot1 + 1
sta unrslot2 + 1
sta unrslot3 + 1
sta unrslot4 + 1
} ;enable_floppy = 1 and enable_write = 1
pha
!if enable_floppy = 1 {
ora #<PHASEOFF
sta unrseek + 1
ora #<MOTOROFF
sta unrdrvoff1 + 1
!if no_interrupts = 1 {
sta unrdrvoff2 + 1
} else { ;no_interrupts = 0
sta unrdrvoff4 + 1
!if ((aligned_read xor 1) and one_shot) = 1 {
sta unrdrvoff5 + 1
} ;aligned_read = 0 and one_shot = 1
} ;no_interrupts = 1
!if (might_exist + poll_drive) > 0 {
sta unrdrvoff3 + 1
} ;might_exist = 1 or poll_drive = 1
tax
inx ;MOTORON
stx unrdrvon1 + 1
stx unrdrvon2 + 1
inx ;DRV0EN
!if allow_multi = 1 {
stx unrdrvsel1 + 1
stx unrdrvsel2 + 1
stx unrdrvsel3 + 1
} ;allow_multi = 1
inx
inx ;Q6L
stx unrread1 + 1
stx unrread2 + 1
stx unrread3 + 1
stx unrread4 + 1
stx unrread5 + 1
!if check_chksum = 1 {
stx unrread6 + 1
} ;check_chksum = 1
} ;enable_floppy = 1
ldx #1
stx namlo
inx
stx namhi
;fetch path, if any
jsr MLI
!byte $c7
!word c7_parms
ldx $200
dex
stx sizelo
sec
bmi +++
;find current directory name in directory
php
readblock jsr MLI
!byte $80
!word x80_parms
lda #<(readbuff + NAME_LENGTH)
sta scratchlo
lda #>(readbuff + NAME_LENGTH)
sta scratchhi
inextent ldy #0
lda (scratchlo), y
pha
and #$0f
tax
-- iny
lda (scratchlo), y
cmp (namlo), y
beq ifoundname
;match failed, move to next directory in this block, if possible
- pla
skiphdr clc
lda scratchlo
adc #ENTRY_SIZE
sta scratchlo
bcc +
;there can be only one page crossed, so we can increment instead of adc
inc scratchhi
+ cmp #<(readbuff + NAME_LENGTH + ($27 * $0d))
lda scratchhi
sbc #>(readbuff + NAME_LENGTH + ($27 * $0d))
bcc inextent
;read next directory block when we reach the end of this block
lda readbuff + NEXT_BLOCK_LO
ldx readbuff + NEXT_BLOCK_HI
bcs +
ifoundname dex
bne --
;parse path until last directory is seen
iny
lda (namlo), y
cmp #'/'
bne -
pla
and #$20 ;Volume Directory Header XOR subdirectory
beq adjpath
pla
clc
php
lsr
bcc skiphdr
inx
adjpath tya
eor #$ff
adc sizelo
sta sizelo
clc
tya
adc namlo
sta namlo
dex
beq ++
;cache block number of current directory
;as starting position for subsequent searches
ldy #(KEY_POINTER + 1)
lda (scratchlo), y
tax
dey
lda (scratchlo), y
!if enable_floppy = 1 {
sta unrblocklo + 1
stx unrblockhi + 1
} ;enable_floppy = 1
sta unrhddblocklo + 1
stx unrhddblockhi + 1
+ sta x80_parms + 4
stx x80_parms + 5
++ lda sizelo
bne readblock
pla
;unit to slot for ProDOS interface
;accept if slot code matches unit number
+++ pla
lsr
lsr
lsr
tay
lsr
ora #$c0
tax
cmp DEVADR01HI, y
clc
beq set_slot
!if enable_floppy = 1 {
;check if current device is floppy
stx scratchhi
ldy #0
sty scratchlo
iny
lda (scratchlo), y
cmp #$20
bne not_floppy
iny
iny
lda (scratchlo), y
bne not_floppy
iny
iny
lda (scratchlo), y
cmp #3
bne not_floppy
ldy #$ff
lda (scratchlo), y
beq set_slot
not_floppy
} ;enable_floppy = 1
ldx #$c8
;find SmartPort device for basic MicroDrive, BOOTi support
;the BOOTi can load floppy .po images via the SmartPort interface
;but the virtual slot behaviour differs slightly from regular ProDOS
;so we scan for the SmartPort interface in all cases
iterdevice
- dex
stx scratchhi
ldy #0
sty scratchlo
iny
lda (scratchlo), y
cmp #$20
bne -
iny
iny
lda (scratchlo), y
bne -
iny
iny
lda (scratchlo), y
cmp #3
bne -
ldy #$ff
lda (scratchlo), y
beq -
set_slot stx slot + 2
stx unrentry + 2
slot ldx $cfff
stx unrentry + 1
!if enable_floppy = 1 {
php
} ;enable_floppy = 1
!if use_smartport = 1 {
!if enable_floppy = 1 {
beq +
bcs ++
+ jmp bankram
++
} else { ;enable_floppy = 0
bcs +
jmp bankram
} ;enable_floppy = 1
ldy #$8c ;STY
!if (rwts_mode + enable_write) > 1 {
sty unrcommand1
} ;rwts_mode = 1 and enable_write = 1
sty unrcommand3
lda #<pcommand
!if (rwts_mode + enable_write) > 1 {
sta unrcommand1 + 1
} ;rwts_mode = 1 and enable_write = 1
!if (rwts_mode + aligned_read + (enable_write xor 1)) = 0 {
sta unrcommand2 + 1
} ;rwts_mode = 0 and aligned_read = 0 and enable_write = 1
sta unrcommand3 + 1
lda #>pcommand
!if (rwts_mode + enable_write) > 1 {
sta unrcommand1 + 2
} ;rwts_mode = 1 and enable_write = 1
!if (rwts_mode + aligned_read + (enable_write xor 1)) = 0 {
sta unrcommand2 + 2
} ;rwts_mode = 0 and aligned_read = 0 and enable_write = 1
sta unrcommand3 + 2
iny ;STA
sty unrblokhi1
sty unrunit1 + 2
iny ;STX
!if (rwts_mode + aligned_read + (enable_write xor 1)) = 0 {
sty unrcommand2
} ;rwts_mode = 0 and aligned_read = 0 and enable_write = 1
sty unrbloklo1
lda #>pblock
pblock_enabled=1
sta unrbloklo1 + 2
!if (rwts_mode + write_sparse) > 1 {
sta unrbloklo2 + 2
} ;rwts_mode = 1 and write_sparse = 1
;;lda #>(pblock + 1)
;;pblock1_enabled=1
sta unrblokhi1 + 2
!if (rwts_mode + write_sparse) > 1 {
sta unrblokhi2 + 2
sta unrblokhi3 + 2
} ;rwts_mode = 1 and write_sparse = 1
lda #>paddr
sta unrunit1 + 4
ldy #<pblock
sty unrbloklo1 + 1
!if (rwts_mode + write_sparse) > 1 {
sty unrbloklo2 + 1
} ;rwts_mode = 1 and write_sparse = 1
iny
sty unrblokhi1 + 1
!if (rwts_mode + write_sparse) > 1 {
sty unrblokhi2 + 1
sty unrblokhi3 + 1
} ;rwts_mode = 1 and write_sparse = 1
lda #$a5 ;LDA
sta unrunit1
!if (rwts_mode + write_sparse) > 1 {
lda #$ee ;INC
sta unrblokhi2
ldy #$ad ;LDA
sty unrblokhi3
iny ;LDX
sty unrbloklo2
} ;rwts_mode = 1 and write_sparse = 1
lda #adrlo
sta unrunit1 + 1
lda #<paddr
sta unrunit1 + 3
;use SmartPort entrypoint instead
inx
inx
inx
stx unrentry + 1
ldx #2
stx x80_parms + 4
lda #0
sta x80_parms + 5
jsr MLI
!byte $80
!word x80_parms
lda #cmdread
sta unrpcommand
lda #$ea
sta hackstar
iterunit inc unrunit2
bne +
ldx slot + 2
jmp iterdevice
+ jsr unrentrysei
+ ldy #$10
- lda readbuff + 3, y
cmp readbuff + $203, y
bne iterunit
dey
bne -
lda #$68
sta hackstar
lda #<packet
sta unrppacket
lda #>packet
sta unrppacket + 1
} ;use_smartport = 1
bankram
!if load_banked = 1 {
lda LCBANK2 - ((lc_bank - 1) * 8) - (rwts_mode * 2)
lda LCBANK2 - ((lc_bank - 1) * 8) - (rwts_mode * 2)
} ;load_banked = 1
!if enable_floppy = 1 {
ldx #>unrelocdsk
ldy #<unrelocdsk
plp
php
beq copydrv
ldx #>unrelochdd
ldy #<unrelochdd
copydrv stx scratchhi
sty scratchlo
ldx #>((codeend - rdwrpart) + $ff)
ldy #0
!if (load_aux and (load_banked xor 1)) = 1 {
sta SETAUXWR
} ;load_aux = 1 and load_banked = 0
- lda (scratchlo), y
!if (load_aux + load_banked) > 1 {
sta SETAUXZP
} ;load_aux = 1 and load_banked = 1
reladr sta reloc, y
!if (load_aux + load_banked) > 1 {
sta CLRAUXZP
} ;load_aux = 1 and load_banked = 1
iny
bne -
inc scratchhi
!if (load_aux and (load_banked xor 1)) = 1 {
sta CLRAUXWR
} ;load_aux = 1 and load_banked = 0
inc reladr + 2
!if (load_aux and (load_banked xor 1)) = 1 {
sta SETAUXWR
} ;load_aux = 1 and load_banked = 0
dex
bne -
plp
!if (load_aux + load_banked) > 1 {
sta SETAUXZP
} ;load_aux = 1 and load_banked = 1
!if swap_scrn = 1 {
beq +
jsr saveslot
lda #$91
sta initpatch
} ;swap_scrn = 1
bne ++
+
;build 6-and-2 denibbilisation table
ldx #$16
-- stx scratchlo
txa
asl
bit scratchlo
beq +
ora scratchlo
eor #$ff
and #$7e
- bcs +
lsr
bne -
tya
sta nibtbl - $16, x
!if enable_write = 1 {
;and 6-and-2 nibbilisation table if writing
txa
ora #$80
sta xlattbl, y
} ;enable_write = 1
iny
+ inx
bpl --
unrdrvon1 lda MOTORON
jsr readadr
lda curtrk
sta trackd1
!if allow_multi = 1 {
lda unrunit1 + 1
asl
lda #0
rol
sta driveind + 1
pha
eor #1
tay
unrdrvsel1 lda DRV0EN, y
jsr spinup
jsr poll
beq +
inc twodrives + 1
lda #0
sta phase
ldx #$22
jsr seek
+ pla
tay
unrdrvsel2 lda DRV0EN, y
} ;allow_multi = 1
unrdrvoff1 lda MOTOROFF
++
} else { ;enable_floppy = 0
!ifdef PASS2 {
!if (hddcodeend - reloc) > $100 {
!if one_page = 1 {
!error "one_page must be 0"
} ;one_page = 0
!if (hddcodeend - reloc) > $200 {
!if three_pages = 0 {
!error "three_pages must be 1"
} ;three_pages = 0
} ;hddcodeend
} ;hddcodeend
} ;PASS2
!if three_pages = 1 {
ldx #>(hddcodeend + $ff - reloc)
} ;three_pages = 1
ldy #0
!if load_aux = 1 {
sta SETAUXWR + (load_banked * 4) ;SETAUXWR or SETAUXZP
} ;load_aux = 1
multicopy
- lda unrelochdd, y
sta reloc, y
!if three_pages = 0 {
!if two_pages = 1 {
lda unrelochdd + $100, y
sta reloc + $100, y
} ;two_pages = 1
} ;three_pages = 0
iny
bne -
!if three_pages = 1 {
!if (load_aux and (load_banked xor 1)) = 1 {
sta CLRAUXWR
} ;load_aux = 1 and load_banked = 0
inc multicopy + 2
inc multicopy + 5
!if (load_aux and (load_banked xor 1)) = 1 {
sta SETAUXWR
} ;load_aux = 1 and load_banked = 0
dex
bne multicopy
} ;three_pages = 1
!if (fast_subindex + swap_zp) > 1 {
sty zp_array + adrlo - first_zp
} ;fast_subindex = 1 and swap_zp = 1
!if swap_scrn = 1 {
jsr saveslot
lda #$91
sta initpatch
} ;swap_scrn = 1
} ;enable_floppy = 1
!if rwts_mode = 1 {
;read volume directory key block
;self-modified by init code
hddopendir
unrhddblocklo = *
ldx #2
unrhddblockhi = *
lda #0
hddreaddir1 jsr hddreaddirsel
lda #NAME_LENGTH + ENTRY_SIZE
hddfirstent sta scratchlo
lda #>(hdddirbuf - 1)
sta scratchhi
;there can be only one page crossed, so we can increment here
hddnextent1 inc scratchhi
hddnextent ldy #0
;match name lengths before attempting to match names
lda (scratchlo), y
and #$0f
tax
inx
- cmp filename, y
beq hddfoundname
;match failed, move to next entry in this block, if possible
+ clc
lda scratchlo
adc #ENTRY_SIZE
sta scratchlo
bcs hddnextent1
cmp #<(NAME_LENGTH + ($27 * $0d))
bne hddnextent
;read next directory block when we reach the end of this block
ldx hdddirbuf + NEXT_BLOCK_LO
lda hdddirbuf + NEXT_BLOCK_HI
jsr hddreaddirsec
lda #NAME_LENGTH
bne hddfirstent
hddfoundname iny
lda (scratchlo), y
dex
bne -
!if ((swap_zp xor 1) + mem_swap) > 0 {
!if allow_trees = 1 {
stx treeidx
sty lasttree ;guarantee no match
} ;allow_trees = 1
stx blkidx
sty lastblk ;guarantee no match
} else { ;swap_zp = 1 and mem_swap = 0
!if allow_trees = 1 {
stx zp_array + treeidx - first_zp
sty zp_array + lasttree - first_zp ;guarantee no match
} ;allow_trees = 0
stx zp_array + blkidx - first_zp
sty zp_array + lastblk - first_zp ;guarantee no match
} ;swap_zp = 0 or mem_swap = 1
!if (allow_trees + fast_subindex) > 0 {
;fetch KEY_POINTER
ldy #KEY_POINTER
lda (scratchlo), y
!if (fast_trees + fast_subindex) = 0 {
!if ((swap_zp xor 1) + mem_swap) > 0 {
sta treeblklo
} else { ;swap_zp = 1 and mem_swap = 0
sta zp_array + treeblklo - first_zp
} ;swap_zp = 0 or mem_swap = 1
} else { ;fast_trees = 1 or fast_subindex = 1
tax
} ;fast_trees = 0 and fast_subindex = 0
iny
lda (scratchlo), y
!if (fast_trees + fast_subindex) = 0 {
!if ((swap_zp xor 1) + mem_swap) > 0 {
sta treeblkhi
} else { ;swap_zp = 1 and mem_swap = 0
sta zp_array + treeblkhi - first_zp
} ;swap_zp = 0 or mem_swap = 1
} else { ;fast_trees = 1 or fast_subindex = 1
!if fast_trees = 1 {
ldy #>hddtreebuf
} ;fast_trees = 1;
jsr hddreaddirsect
} ;fast_trees = 0 and fast_subindex = 0
} ;allow_trees = 1 or fast_subindex = 1
lda #>iob
ldy #<iob
jsr reloc
inc sect
inc addr + 1
lda #>iob
ldy #<iob
jsr reloc
lda #9
sta sect
lda #$bf
sta addr + 1
lda #>iob
ldy #<iob
jsr reloc
ldx #$60
jmp $b700
filename !byte filename_e-filename_b
filename_b !text "DISKIMAGE"
filename_e
iob !byte 0, 0, 0, 0
trak !byte 0
sect !byte 0
!byte 0, 0
addr !byte 0, $b6
!byte 0, 0, 1, 0, 0
} else { ;rwts_mode = 0
!if load_aux = 1 {
sta CLRAUXWR + (load_banked * 4) ;CLRAUXWR or CLRAUXZP
} ;load_aux = 1
!if load_banked = 1 {
lda ROMIN
} ;load_banked = 1
rts
} ;rwts_mode = 1
c7_parms !byte 1
!word $200
x80_parms !byte 3, $d1
!word readbuff, 2
!if enable_floppy = 1 {
unrelocdsk
!pseudopc reloc {
rdwrpart
!if (enable_readseq + allow_subdir) > 0 {
jmp rdwrfile
} ;enable_readseq = 1 or allow_subdir = 1
opendir
!if no_interrupts = 1 {
!if detect_err = 1 {
clc
} ;detect_err = 1
php
sei
jsr +
!if detect_err = 1 {
pla
adc #0
pha
} ;detect_err = 1
plp
unrdrvoff2 = unrelocdsk + (* - reloc)
lda MOTOROFF
rts
+
} ;no_interrupts = 1
jsr prepdrive
;read volume directory key block
;self-modified by init code
unrblocklo = unrelocdsk + (* - reloc)
ldx #2
unrblockhi = unrelocdsk + (* - reloc)
lda #0
jsr readdirsel
readdir
!if allow_subdir = 1 {
jsr prepdrive
} ;allow_subdir = 1
!if might_exist = 1 {
lda dirbuf + FILE_COUNT ;assuming only 256 files per subdirectory
sta entries
!if many_files = 1 {
lda dirbuf + FILE_COUNT + 1
sta entrieshi
} ;many_files = 1
} ;might_exist = 1
lda #NAME_LENGTH + ENTRY_SIZE
firstent sta scratchlo
lda #>(dirbuf - 1)
sta scratchhi
;there can be only one page crossed, so we can increment here
nextent1 inc scratchhi
nextent ldy #0
!if (might_exist + allow_subdir + allow_saplings + (allow_trees xor always_trees)) > 0 {
lda (scratchlo), y
!if might_exist = 1 {
;skip deleted entries without counting
and #MASK_ALL
beq +
} ;might_exist = 1
!if (allow_subdir + allow_saplings + (allow_trees xor always_trees)) > 0 {
;remember type
;now bits 5-4 are represented by carry (subdirectory), sign (sapling)
asl
asl