-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhost.fst.aii
More file actions
1142 lines (898 loc) · 16 KB
/
host.fst.aii
File metadata and controls
1142 lines (898 loc) · 16 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
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
include 'gsos.equ'
include 'fst.equ'
include 'fst.macros'
include 'records.equ'
longa on
longi on
string asis
entry app_entry
entry sys_entry
entry rtl_no_error
entry sys_startup
entry sys_shutdown
entry check_path1, check_path2
entry build_vcr
entry fd_op_ro
entry create
entry destroy
entry change_path
entry set_file_info
entry get_file_info
entry judge_name
entry volume
entry open
entry close
entry read
entry write
entry flush
entry get_mark
entry set_mark
entry get_eof
entry set_eof
entry get_dir_entry
entry get_dev_num
entry format
entry erase_disk
macro
&lab call_host
&lab dc.b $42, $ff
endm
macro
&lab host_print
&lab dc.b $42, $a0
endm
macro
&lab host_hexdump
&lab dc.b $42, $a1
endm
header proc
str 'FST '
dc.l app_entry
dc.l sys_entry
dc.w fst_id
dc.w fst_attr ; attributes
dc.w $0100 ; version
dc.w $0200 ; block size
dc.l $007FFFFF ; maximum volume size
dc.l 1 ; min volume size
dc.l $FFFFFFFF ; max file size
dc.l 0 ; reserved
str.b 'Host' ; name
str.b 'Host FST v01.00' ; comment
dc.w 0 ; reserved
; credits
str.b 'Host FST written by Kelvin W Sherlock.'
endp
data record
export dev_id
; device id of the .host driver.
dev_id dc.w 0
export colon_host, colon_HOST, colon_Host
colon_host str.w ':host'
colon_Host str.w ':Host'
colon_HOST str.w ':HOST'
endr
sys_entry proc
phk
plb
long m,x
if 0 then
; debug
pha
phx
phy
lda #$8001
ldx #debugstr
ldy #^debugstr
host_print
lda #$18
ldx #$bd30
ldy #$0000
host_hexdump
ply
plx
pla
endif
cpx #max_sys_call+1
bge rtl_no_error
jmp (@sys_table,x)
@sys_table
dc.w rtl_no_error
dc.w sys_startup
dc.w sys_shutdown
dc.w rtl_no_error ; remove vcr
dc.w rtl_no_error ; deferred flush
max_sys_call equ *-@sys_table-2
debugstr str.b 'sys_entry'
endp
rtl_no_error proc
lda #0
clc
rtl
endp
rtl_invalid_fst_op proc
lda #invalid_fst_op
sec
rtl
endp
rtl_bad_system_call proc
lda #bad_system_call
sec
rtl
endp
rtl_invalid_pcount proc
lda #invalid_pcount
sec
rtl
endp
find_host_device proc
with dev_parms
; find .host device. if no .host, returns to gs/os.
; entry via jsr
; exit via rts (success) / sys_exit (fail).
lda dev_id
beq @search
bmi @fail
rts
@fail plx
lda #unknown_vol
sec
jml sys_exit
@search
lda #-1
sta dev_id
lda #1
sta dev_dev_id
stz dev_num
@loop
lda #drvr_get_dib
sta dev_callnum
jsl dev_dispatcher
bcs @fail
ldy #$34 ; dib device id
lda [dev_dib_ptr],y
cmp #$10 ; file server
bne @next
short m
ldy #$0e ; name $04 H O S T
lda [dev_dib_ptr],y
cmp #$04
bne @next
iny
lda [dev_dib_ptr],y
cmp #'H'
bne @next
iny
lda [dev_dib_ptr],y
cmp #'O'
bne @next
iny
lda [dev_dib_ptr],y
cmp #'S'
bne @next
iny
lda [dev_dib_ptr],y
cmp #'T'
bne @next
long m
lda dev_dev_id
sta dev_id
clc
rts
@next
long m
; try the next one.
inc dev_dev_id
bra @loop
endp
sys_startup proc
stz dev_id
; sanity check that the global buffer location
; is where I expect it.
jsl get_sys_gbuf
cpy #$0000
bne no
cpx #$9a00
bne no
; check if host wdm active.
lda #0
sec
ldx #$8001
call_host
; wdm will clear carry if active.
; if carry set, a <> 0, gs/os halts
; "Sorry, system error $xxxx occurred while loading the FST file xxx"
lda #0
rtl
no
sec ; unload me!
lda #0
rtl
endp
sys_shutdown proc
lda #0
clc
ldx #$8002
call_host
rtl
endp
app_entry proc
with dp
with fst_parms
phk
plb
long m,x
if 0 then
; debug
pha
phx
phy
lda #$8001
ldx #debugstr
ldy #^debugstr
host_print
lda #$18
ldx #$bd30
ldy #$0000
host_hexdump
lda path_flag
and #$4000
beq @xx
lda #32
ldx path1_ptr
ldy path1_ptr+2
host_hexdump
@xx
ply
plx
pla
;
endif
; x = call number * 2
; y = call class * 2
sty <call_class
stx <tmp
; debug saves all registers.
IF DEBUG_S16 THEN
jsr debug
ENDIF
; check the class 0 or 1 only.
cpy #2+1
bge @bad_system_call
cpx #max_app_call+1 ; 66+1
bge @bad_system_call
; class 1 -- check the pcount maximum.
cpy #2
bne @ok
lda table,x
and #$00ff
cmp [param_blk_ptr]
; gs/os already checks the minimum and verifies non-null names, etc.
bcc @invalid_pcount
@ok
stz my_fcr
stz my_fcr+2
stz my_vcr
stz my_vcr+2
stz cookie
; check fcr bit.
; n = fcr/vcr-based
; v = path-based
bit table,x
bmi @vcr
bvc @call
@path
; path checking...
jsr find_host_device
jsr check_path1
bcc @call
jml sys_exit
@vcr
; deref vcr and fcr.
ldx fcr_ptr
ldy fcr_ptr+2
jsl deref
stx my_fcr
sty my_fcr+2
ldy #fcr.cookie
lda [my_fcr],y
sta cookie
ldx vcr_ptr
ldy vcr_ptr+2
jsl deref
stx my_vcr
sty my_vcr+2
@call
; fake an rtl address for sys_exit
; otherwise, would need to jml sys_exit from functions.
pea |(sys_exit-1)>>8
phb
lda #<sys_exit-1
sta 1,s
; call it...
ldx <tmp
jmp (app_table,x)
@bad_system_call
lda #bad_system_call
sec
jml sys_exit
@invalid_pcount
lda #invalid_pcount
sec
jml sys_exit
@vol_not_found
lda #vol_not_found
sec
jml sys_exit
app_table
dc.w rtl_bad_system_call ;
dc.w create ; ($01) Create
dc.w destroy ; ($02) Destroy
dc.w rtl_bad_system_call ; ($03) OS Shutdown
dc.w change_path ; ($04) Change Path
dc.w set_file_info ; ($05) Set File Info
dc.w get_file_info ; ($06) Get File Info
dc.w judge_name ; ($07) Judge Name
dc.w volume ; ($08) Volume
dc.w rtl_bad_system_call ; ($09) Set Prefix
dc.w rtl_bad_system_call ; ($0A) Get Prefix
dc.w rtl_invalid_fst_op ; ($0B) Clear Backup Bit
dc.w rtl_bad_system_call ; ($0C) Set Sys Prefs
dc.w rtl_no_error ; ($0D) Null
dc.w rtl_bad_system_call ; ($0E) Expand Path
dc.w rtl_bad_system_call ; ($0F) Get Sys Prefs
dc.w open ; ($10) Open
dc.w rtl_bad_system_call ; ($11) NewLine
dc.w read ; ($12) Read
dc.w write ; ($13) Write
dc.w close ; ($14) Close
dc.w flush ; ($15) Flush
dc.w set_mark ; ($16) Set Mark
dc.w get_mark ; ($17) Get Mark
dc.w set_eof ; ($18) Set EOF
dc.w get_eof ; ($19) Get EOF
dc.w rtl_bad_system_call ; ($1A) Set Level
dc.w rtl_bad_system_call ; ($1B) Get Level
dc.w get_dir_entry ; ($1C) Get Dir Entry
dc.w rtl_bad_system_call ; ($1D) Begin Session
dc.w rtl_bad_system_call ; ($1E) End Session
dc.w rtl_bad_system_call ; ($1F) Session Status
dc.w get_dev_num ; ($20) Get Dev Num
dc.w rtl_bad_system_call ; ($21) Get Last Dev
dc.w rtl_bad_system_call ; ($22) Read Block
dc.w rtl_bad_system_call ; ($23) Write Block
dc.w format ; ($24) Format
dc.w erase_disk ; ($25) Erase Disk
dc.w rtl_bad_system_call ; ($26) Reset Cache
dc.w rtl_bad_system_call ; ($27) Get Name
dc.w rtl_bad_system_call ; ($28) Get Boot Vol
dc.w rtl_bad_system_call ; ($29) Quit
dc.w rtl_bad_system_call ; ($2A) Get Version
dc.w rtl_bad_system_call ; ($2B) Get FST Info
dc.w rtl_bad_system_call ; ($2C) D_INFO
dc.w rtl_bad_system_call ; ($2D) D_STATUS
dc.w rtl_bad_system_call ; ($2E) D_CONTROL
dc.w rtl_bad_system_call ; ($2F) D_READ
dc.w rtl_bad_system_call ; ($30) D_WRITE
dc.w rtl_bad_system_call ; ($31) Alloc Interrupt
dc.w rtl_bad_system_call ; ($32) Dealloc Interrupt
dc.w rtl_invalid_fst_op ; ($33) FST Specific
max_app_call equ *-app_table-2
; insight - vcr and fcr always go together.
vcr_used equ $8000
fcr_used equ $0000
path_used equ $4000
table ; stores max pcount + 1
dc.w 0
dc.w 8+path_used ; ($01) Create
dc.w 2+path_used ; ($02) Destroy
dc.w 0 ; ($03) OS Shutdown
dc.w 4+path_used ; ($04) Change Path
dc.w 13+path_used ; ($05) Set File Info
dc.w 13+path_used ; ($06) Get File Info
dc.w 7 ; ($07) Judge Name
dc.w 7 ; ($08) Volume
dc.w 0 ; ($09) Set Prefix
dc.w 0 ; ($0A) Get Prefix
dc.w 2+path_used ; ($0B) Clear Backup Bit
dc.w 0 ; ($0C) Set Sys Prefs
dc.w 0 ; ($0D) Null
dc.w 0 ; ($0E) Expand Path
dc.w 0 ; ($0F) Get Sys Prefs
dc.w 16+path_used ; ($10) Open
dc.w 0 ; ($11) NewLine
dc.w 6+vcr_used+fcr_used ; ($12) Read
dc.w 6+vcr_used+fcr_used ; ($13) Write
dc.w 2+vcr_used+fcr_used ; ($14) Close
dc.w 3+vcr_used+fcr_used ; ($15) Flush
dc.w 4+vcr_used+fcr_used ; ($16) Set Mark
dc.w 3+vcr_used+fcr_used ; ($17) Get Mark
dc.w 4+vcr_used+fcr_used ; ($18) Set EOF
dc.w 3+vcr_used+fcr_used ; ($19) Get EOF
dc.w 0 ; ($1A) Set Level
dc.w 0 ; ($1B) Get Level
dc.w 18+vcr_used+fcr_used ; ($1C) Get Dir Entry
dc.w 0 ; ($1D)
dc.w 0 ; ($1E)
dc.w 0 ; ($1F)
dc.w 3+path_used ; ($20) Get Dev Num
dc.w 0 ; ($21) Get Last Dev
dc.w 0 ; ($22) Read Block
dc.w 0 ; ($23) Write Block
dc.w 7+path_used ; ($24) Format
dc.w 7+path_used ; ($25) Erase Disk
dc.w 0 ; ($26)
dc.w 0 ; ($27) Get Name
dc.w 0 ; ($28) Get Boot Vol
dc.w 0 ; ($29) Quit
dc.w 0 ; ($2A) Get Version
dc.w 0 ; ($2B) Get FST Info
dc.w 0 ; ($2C) D_INFO
dc.w 0 ; ($2D) D_STATUS
dc.w 0 ; ($2E) D_CONTROL
dc.w 0 ; ($2F) D_READ
dc.w 0 ; ($30) D_WRITE
dc.w 0 ; ($31) Alloc Interrupt
dc.w 0 ; ($32) Dealloc Interrupt
dc.w 0 ; ($33) FST Specific
debugstr str.b 'app_entry'
endp
close proc
with dp, fst_parms
lda #invalid_fst_op
ldx call_number
ldy cookie
sec
call_host
bcc @ok
rtl
@ok
; destroy the fcr
lda [my_fcr]
jsl release_fcr
; decrement vcr
ldx vcr_ptr
ldy vcr_ptr+2
jsl deref
stx my_vcr
sty my_vcr+2
ldy #vcr.open_count
lda [my_vcr],y
beq fatal
dec a
sta [my_vcr],y
lda #0
clc
rtl
fatal
lda #vcr_unusable
jml sys_death
endp
read proc
with dp, fst_parms
; slightly special since newline mode may be in effect.
ldy #fcr.mask
lda [my_fcr],y
sta >$009a00 ; hardcoded...
beq fd_op_ro
; zero-out the table.
ldx #256-2
lda #0
@zloop
sta >$009a00+2,x
dex
dex
bpl @zloop
; newline list is a virtual pointer.
ldy #fcr.newline
lda [my_fcr],y
tax
iny
iny
lda [my_fcr],y
tay
jsl deref
stx ptr
sty ptr+2
ldy #fcr.newline_length
lda [my_fcr],y
tay
dey
ldx #0
lda #0
short m
nloop
lda [ptr],y
tax
lda #$ff
sta >$009a00+2,x
dey
bpl nloop
long m
bra fd_op_ro
endp
macro
&lab global
export &lab
&lab
endm
fd_op_ro proc
get_eof global
get_mark global
flush global
get_dir_entry global
with dp, fst_parms
; read, write, truncate, etc.
; everything (except close) that uses an fcr.
lda #invalid_fst_op
ldx call_number
ldy cookie
sec
call_host
rtl
endp
fd_op_rw proc
write global
set_eof global
set_mark global
with dp, fst_parms
; read, write, truncate, etc.
; everything (except close) that uses an fcr.
lda #invalid_fst_op
ldx call_number
ldy cookie
sec
call_host
post_event
rtl
endp
path_op_ro proc
get_file_info global
with dp, fst_parms
lda #invalid_fst_op
ldx call_number
sec
call_host
rtl
endp
path_op_rw proc
set_file_info global
create global
destroy global
erase_disk global
format global
with dp, fst_parms
lda #invalid_fst_op
ldx call_number
sec
call_host
post_event
rtl
endp
judge_name proc
with dp, fst_parms
; handle syntax message here. Need to return text pointer.
lda [param_blk_ptr]
cmp #3
bcc @no_syntax
ldy #JudgeNameRecGS.syntax
lda #syntax
sta [param_blk_ptr],y
iny
iny
lda #^syntax
sta [param_blk_ptr],y
@no_syntax
lda #invalid_fst_op
ldx call_number
sec
call_host
rtl
syntax str.b 'Names may contain any character except colon (:) or slash (/).'
endp
change_path proc
with dp, fst_parms
; todo -- verify both paths are on the device...
jsr check_path1
bcs exit
jsr check_path2
bcs exit
lda #invalid_fst_op
ldx call_number
sec
call_host
post_event
exit
rtl
endp
volume proc
; check if a volume is ours, create vcr if necessary.
with dp, fst_parms
;
; volume requires a device id. it doesn't fit
; into the standard table so we check for the
; .host device here.
;
jsr find_host_device
lda dev1_num
beq no
cmp dev_id
bne no
; yes!
lda #unknown_vol
ldx call_number
sec
call_host
bcc @ok
rtl
@ok
; name is hardcoded to Host.
jsr build_vcr
rtl
no
lda #unknown_vol
sec
rtl
endp
build_vcr proc
; for now, volume hard coded as 'Host'.
with dp
ldx #host_name
ldy #^host_name
lda #0
jsl find_vcr
bcs create_vcr
stx my_vcr_ptr
sty my_vcr_ptr+2
jsl deref
stx my_vcr
sty my_vcr+2
ldy #vcr.fst_id
lda [my_vcr],y
cmp #fst_id
bne dump_vcr
ldy #vcr.status
lda [my_vcr],y
and #vcr_swapped
beq @exit
and #vcr_swapped_in
sta [my_vcr],y
;lda device
lda dev_id
ldy #vcr.device
sta [my_vcr],y
@exit
lda #0
clc
rts
dump_vcr
; vcr exists for the filename but it's not mine.
; if inactive, kick it out. otherwise, return dup error.
;
; todo -- prodos fst has kludge for change path which
; allows duplicates if using a device name or something...
;
ldy #vcr.open_count
lda [my_vcr],y
beq @dump
lda #dup_volume
sec
rts
@dump
ldy #vcr.id
lda [my_vcr],y
jsl release_vcr
; drop through.
create_vcr
lda #vcr.__sizeof
ldx #host_name
ldy #^host_name
jsl alloc_vcr
stx my_vcr_ptr
sty my_vcr_ptr+2
lda #out_of_mem
bcs exit
jsl deref
stx my_vcr
sty my_vcr+2
lda #0
ldy #vcr.status
sta [my_vcr],y
ldy #vcr.open_count
sta [my_vcr],y
lda #fst_id
ldy #vcr.fst_id
sta [my_vcr],y
lda dev_id
ldy #vcr.device
sta [my_vcr],y
lda #0
clc
exit
rts
host_name
str.w 'Host'
endp
get_dev_num proc
with dp, fst_parms
; have already verified path is valid.
lda dev_id
ldx call_class
ldy table,x
sta [param_blk_ptr],y
lda #0
clc
rtl
table
dc.w DevNumRec.devNum, DevNumRecGS.devNum
endp
;
; verify this path is for us
; (via dev number or :Host:)
;
check_path1 proc
with dp, fst_parms
lda dev1_num
beq path
cmp dev_id
beq ok
vnf
long m
lda #unknown_vol
sec
rts
bps
long m
lda #bad_path_syntax
sec
rts
ok
long m
lda #0
clc
rts
path
lda path_flag
and #$4000
beq bps
ldy #2
ldx #0
lda #0
short m
loop
lda [path1_ptr],y
cmp colon_host,y
beq @next
cmp colon_HOST,y
beq @next
bra vnf
@next
iny
cpy #5+2
bne loop
; check for trailing null / :
lda [path1_ptr],y
beq @ok
cmp #':'
beq @ok
bra vnf
@ok
bra ok
longa on
longi on
endp
check_path2 proc
with dp, fst_parms
lda dev2_num
beq path