-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsubs.asm
2992 lines (2771 loc) · 53.2 KB
/
subs.asm
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
keep obj/subs
mcopy subs.macros
****************************************************************
*
* Subs
*
* This module contains general purpose and utility subroutine
* used throughout the shell.
*
****************************************************************
copy sh.dp
eject
****************************************************************
*
* SpinnerCommon - common data area for the spinner subroutines
*
****************************************************************
*
SpinnerCommon privdata
spinSpeed equ 3 calls before one spinner move
spinning dc i'0' are we spinning now?
spinDisp dc i'0' disp to the spinner character
spinCount ds 2 spin loop counter
spinner dc i1'$7C,$2F,$2D,$5C' spinner characters
end
****************************************************************
*
* shortName - used to find the length of a GS/OS name
*
****************************************************************
*
shortName private
buffSize equ 1 buffer size; should be zero
dc i'buffSize+4,0'
ds buffSize
end
****************************************************************
*
* shortName2 - used to find the length of a GS/OS option list
*
****************************************************************
*
shortName2 private
buffSize equ 1 buffer size; should be zero
dc i'buffSize+4,0'
ds buffSize
end
****************************************************************
*
* AppendOSNames - append two GS/OS path names
*
* Inputs:
* p1,p2 - pointers to input format GS/OS names
* flags -
* 0 - return an input string
* 1 - return an output string
*
* Outputs:
* X-A - nil for out of memory, otherwise a pointer to the string
*
* Notes:
* This subroutine reserves a memory buffer based on
* the actual length of the expanded path name. The
* caller is responsible for disposing of the memory.
*
****************************************************************
*
AppendOSNames start seg2
out equ 1 return pointer
chars equ 5 pointer to input format portion of out
lsub (4:p1,4:p2,2:flags),8
clc find the length of the buffer
lda [p1]
adc [p2]
inc A
inc A
ldx flags
beq lb1
inc A
inc A
sta chars
lb1 jsl Malloc allocate the memory
sta out
stx out+2
ora out
beq lb7
lda flags if flags then
beq lb2
lda chars set the length of the buffer
sta [out]
add4 out,#2,chars chars = out+2
bra lb3 else
lb2 move4 out,chars chars = out
lb3 anop endif
clc set the length
lda [p1]
adc [p2]
sta [chars]
lda [p1] move in the first string
beq lb4a
tax
ldy #2
short M
lb4 lda [p1],Y
sta [chars],Y
iny
dex
bne lb4
long M
lb4a clc update chars
lda [p1]
adc chars
sta chars
bcc lb5
inc chars+2
lb5 lda [p2] move in the second string
beq lb7
tax
ldy #2
short M
lb6 lda [p2],Y
sta [chars],Y
iny
dex
bne lb6
long M
lb7 lret 4:out
end
****************************************************************
*
* ColonToSlash - substitutes slashes for colons in GS/OS path names
*
* Inputs:
* ptr - pointer to the GS/OS input name
*
****************************************************************
*
ColonToSlash start seg2
lsub (4:ptr),0
lda [ptr]
beq lb3
tax
ldy #2
short M
lb1 lda [ptr],Y
cmp #':'
bne lb2
lda #'/'
sta [ptr],Y
lb2 iny
dex
bne lb1
long M
lb3 lret
end
****************************************************************
*
* CompareOSStrings - compare two GS/OS path names
*
* Inputs:
* p1,p2 - pointers to input format GS/OS names
* caseSensitive - are compares case sensitive?
*
* Outputs:
* A - 0 if equal, 1 if not equal
*
****************************************************************
*
CompareOSStrings start seg2
using Common
val equ 1 return value
ch equ 3 temp character value
lsub (4:p1,4:p2),4
lda #1 assume the strings are not equal
sta val
lda [p1] not equal if lengths differ
cmp [p2]
bne lb7
tax
beq lb5
short M
ldy #2 Y is disp into strings
lda >caseSensitive if not case sensitive then
bne lb2
lb1 lda [p1],Y do a case insensitive compare
jsl ToUpper
sta ch
lda [p2],Y
jsl ToUpper
cmp ch
bne lb6
iny
dex
bne lb1
stz val
bra lb6 else
lb2 lda [p1],Y do a case sensitive compare
cmp [p2],Y
bne lb6
iny
dex
bne lb2
lb5 stz val
lb6 long M endif
lb7 lret 2:val
end
****************************************************************
*
* ConvertPrefix - convert old to new prefixes
*
* Inputs:
* ptr - address of the input path name to convert
*
* Outputs:
* X-A - pointer to path name; nil if no conversion needed
*
* Notes:
* This subroutine checks to see if the path name starts
* with a numbered prefix from 0-7. If so, and if the
* current prefix 0 is null, a path with the prefix
* number converted to the new, GS/OS equivalent is
* returned. If no conversion is needed, a nil pointer
* is returned.
*
* If a pointer is returned, it has been allocated from
* dynamic memory, and it is up to the caller to dispose
* of the memory.
*
****************************************************************
*
ConvertPrefix private seg2
nptr equ 1 new prefix pointer
lsub (4:ptr),4
stz nptr assume no conversion is necessary
stz nptr+2
lda [ptr] if length = 1
beq lb3
cmp #1
beq lb1
ldy #3 or ptr^.string[2] in [':','/'] then
lda [ptr],Y
and #$00FF
cmp #'/'
beq lb1
cmp #':'
bne lb3
lb1 ldy #2 if ptr^.string[1] in ['0'..'7'] then
lda [ptr],Y
and #$00FF
cmp #'0'
blt lb3
cmp #'8'
bge lb3
lda #0 if length(prefix(0)) = 0 then
sta >prName+2
OSGet_Prefix prRec
lda >prName+2
bne lb3
clc allocate space for the new buffer
lda [ptr]
adc #3
jsl Malloc
sta nptr
stx nptr+2
ora nptr+2
beq lb3
lda [ptr] set the length
inc A
sta [nptr]
ldy #2 set the prefix number
lda [ptr],Y
and #$000F
asl A
tax
lda >nums,X
sta [nptr],Y
lda [ptr] copy over the remaining chars
dec A
beq lb3
tax
ldy #3
short M
lb2 lda [ptr],Y
iny
sta [nptr],Y
dex
bne lb2
long M
lb3 lret 4:nptr return the new prefix pointer
prRec dc i'2' GetPrefix record
dc i'0'
dc a4'prName'
prName dc i'4,0' prefix name buffer
nums dc c'08' prefix equivalents table
dc c'09'
dc c'13'
dc c'14'
dc c'15'
dc c'16'
dc c'17'
dc c'18'
end
****************************************************************
*
* CtoOSString - convert a C string to an OS string
*
* Inputs:
* cstr - pointer to the C string
*
* Outputs:
* X-A - nil for out of memory, otherwise a pointer to the string
*
* Notes:
* This subroutine reserves a memory buffer based on
* the length of the string. The caller is responsible
* for disposing of the memory.
*
****************************************************************
*
CtoOSString start seg2
str equ 1 pointer to duplicate string
str2 equ 7 pointer to duplicate string + 2
len equ 5 length of the string
lsub (4:cstr),10
ldy #0 find the length of the C string
short M
lb1 lda [cstr],Y
beq lb2
iny
bne lb1
lb2 long M
tya allocate space for the string
sta len
inc A
inc A
jsl Malloc
sta str
stx str+2
ora str+2
beq lb5
lda len set the length
sta [str]
add4 str,#2,str2 copy over the string characters
ldy len
beq lb5
short M
dey
beq lb4
lb3 lda [cstr],Y
sta [str2],Y
dey
bne lb3
lb4 lda [cstr]
sta [str2]
long M
lb5 lret 4:str
end
****************************************************************
*
* DuplicateOSString - create a duplicate of an O/S string
*
* Inputs:
* p - pointers to string to duplicate
*
* Outputs:
* X-A - nil for out of memory, otherwise a pointer to the string
*
* Notes:
* This subroutine reserves a memory buffer based on
* the length of the string. The caller is responsible
* for disposing of the memory.
*
****************************************************************
*
DuplicateOSString start seg2
str equ 1 pointer to duplicate string
lsub (4:p),4
lda [p] reserve a buffer
inc A
inc A
jsl Malloc
sta str
stx str+2
ora str+2 branch if out of memory
beq lb2
lda [p] move the string
inc A
tay
short M
lb1 lda [p],Y
sta [str],Y
dey
bpl lb1
long M
lb2 lret 4:str
end
****************************************************************
*
* ExpandDevice - Expand devices (shell call)
*
* Inputs:
* dcb - address of the parameter block
*
* Outputs:
* A - error code; 0 if no error occurred
*
* Notes:
* This subroutine reserves a memory buffer based on
* the actual length of the expanded path name. The
* address of the buffer is returned in the appropriate
* spot in the parameter block. The caller is
* responsible for disposing of the memory. No memory
* is reserved if an error occurs.
*
****************************************************************
*
ExpandDevice start
buffPtr equ 1 pointer to the file name buffer
err equ 5 error
pathPtr equ 7 input path pointer
sub (4:dcb),10
stz err assume we will succeed
stz pathPtr pathPtr = nil
stz pathPtr+2
ldy #2 fetch the input path name
lda [dcb],Y
sta rec+2
iny
iny
lda [dcb],Y
sta rec+4
ph4 rec+2 convert prefixes 0-7
jsl ConvertPrefix
sta pathPtr
stx pathPtr+2
ora pathPtr+2
beq cp1
move4 pathPtr,rec+2
cp1 lda #0 get the length of the buffer
sta shortName+2
OSExpandDevices rec
lda shortName+2 reserve a block of memory
bne lb0
lda #$0044 no path - return a path not found error
sta err
bra lb2
lb0 clc
adc #4
jsl Malloc
ldy #6 save the pointer to the memory
sta [dcb],Y
sta buffPtr
iny
iny
txa
sta [dcb],Y
sta buffPtr+2
ora buffPtr check for out of memory condition
bne lb1
dec err (err = -1)
bra lb2
lb1 lda shortName+2 set the length of the buffer
clc
adc #4
sta [buffPtr]
ldy #4 save the input name pointer
lda [dcb],Y set converted name pointer
pha
lda rec+4
sta [dcb],Y
dey
dey
lda [dcb],Y
pha
lda rec+2
sta [dcb],Y
move4 dcb,addr get the volume name
jsl $E100A8
dc i'$0154'
addr ds 4
bcc lb1a branch if no error occured
sta err save the error number
free buffPtr dispose of the buffer
ldy #6
lda #0
sta [dcb],Y
iny
iny
sta [dcb],Y
lb1a ldy #2 restore input name pointer
pla
sta [dcb],Y
iny
iny
pla
sta [dcb],Y
lb2 free pathPtr free converted path, if any
ret 2:err return the error code
rec dc i'2' ExpandDevices record
ds 4 input path name
dc a4'shortName' output path name
end
****************************************************************
*
* ExpandPath - Expand a path name
*
* Inputs:
* dcb - address of the parameter block
*
* Outputs:
* A - error code; 0 if no error occurred
*
* Notes:
* This subroutine reserves a memory buffer based on
* the actual length of the expanded path name. The
* address of the buffer is returned in the appropriate
* spot in the parameter block. The caller is
* responsible for disposing of the memory. No memory
* is reserved if an error occurs.
*
****************************************************************
*
ExpandPath start
buffPtr equ 1 pointer to the file name buffer
err equ 5 error
pathPtr equ 7 input path pointer
sub (4:dcb),10
stz err assume we will succeed
stz pathPtr pathPtr = nil
stz pathPtr+2
ldy #2 fetch the input path name
lda [dcb],Y
sta rec+2
iny
iny
lda [dcb],Y
sta rec+4
ph4 rec+2 convert prefixes 0-7
jsl ConvertPrefix
sta pathPtr
stx pathPtr+2
ora pathPtr+2
beq cp1
move4 pathPtr,rec+2
cp1 lda #0 get the length of the buffer
sta shortName+2
OSExpand_Path rec
bcc la1
cmp #$4F
beq la1
sta err
bra lb2
la1 lda shortName+2 reserve a block of memory
clc
adc #4
jsl Malloc
ldy #6 save the pointer to the memory
sta [dcb],Y
sta buffPtr
iny
iny
txa
sta [dcb],Y
sta buffPtr+2
ora buffPtr check for out of memory condition
bne lb1
dec err (err = -1)
bra lb2
lb1 lda shortName+2 set the length of the buffer
clc
adc #4
sta [buffPtr]
ldy #4 save the input name pointer
lda [dcb],Y set converted name pointer
pha
lda rec+4
sta [dcb],Y
dey
dey
lda [dcb],Y
pha
lda rec+2
sta [dcb],Y
ph4 dcb get the volume name
ph2 #$200E
jsl $E100B0
bcc lb1a branch if no error occured
sta err save the error number
free buffPtr dispose of the buffer
ldy #6
lda #0
sta [dcb],Y
iny
iny
sta [dcb],Y
lb1a ldy #2 restore input name pointer
pla
sta [dcb],Y
iny
iny
pla
sta [dcb],Y
lb2 free pathPtr free converted path, if any
ret 2:err return the error code
rec dc i'3' ExpandPath record
ds 4 input path name
dc a4'shortName' output path name
dc i'0' don't uppercase the name
end
****************************************************************
*
* FindAlias - find an alias
* FindVaraible - find a variable
*
* Inputs:
* R12 - pointer to name of variable
* V_POINTER - pointer to variable table
*
* Outputs:
* R0 - pointer to token entry (0 if no string found)
* R4 - pointer to variable name
* R8 - pointer to variable string
* P1 - pointer to last node in list (used by unset, 0 if first entry)
*
****************************************************************
*
FindVariable start
debug FindVariable
using Common
using RecCom
jsr FirstVariable get the first variable entry
bra fv
FindAlias entry
jsr FirstAlias get the first alias entry
fv stz p1 initialize last node
stz p1+2
fv1 lda r0 quit if no more
ora r0+2
beq rts
ph4 r4 see if names match
ph4 r12
jsl CompareOSStrings
tax
beq rts
move4 r0,p1 next entry
jsr NextAlias
bra fv1
rts rts
end
****************************************************************
*
* FindCommand - Identify a command
*
* Inputs:
* LINE - input line with the command as the first entry
*
* Outputs:
* A - command number; 0 for a language
* Y - language number (if A=0)
* C - set if the line contains a command
* R0 - address of command table entry
* CTLAST - pointer to command table entry of command, if found
*
****************************************************************
*
FindCommand start
debug FindCommand
using Common
;
; Read the command name.
;
stz ctlast ctlast = nil
stz ctlast+2
jsr SkipBlanks remove leading blanks
short M
ldy #2 place command in BUFF1
ldx #0
rc3 jsr NextChar
cmp #RETURN
beq rc4
jsl IsWhite
bcs rc4
jsl ToUpper
sta buff1,Y
iny
cpy #16
blt rc3
bra err
rc4 dey save length of command
dey
sty buff1
long M
tya quit if there was no command
bne st0
err clc
rts
;
; Scan the table for the command.
;
st0 move4 ctpointer,r0
st1 ldy #disp_cnum+1 quit if at end of table
lda [r0],Y
beq bad
ldy #disp_cnum branch if its a utility
lda [r0],Y
beq st4
ldy #disp_name get length of name
lda [r0],Y
and #$00FF
cmp buff1 branch if its different from what we
bne st4 want
sta r6 compare the names
ldx #2
iny
short M
st2 lda [r0],Y
cmp buff1,X
bne st3
iny
inx
dbne r6,st2
st3 long M
beq ln1 branch if names match
st4 ldy #disp_name get next command
lda [r0],Y
and #$00FF
clc
adc #disp_name+1
adc r0
sta r0
bcc st1
inc r2
bra st1
bad clc
rts
;
; If the command is a language, return a command number of 0; otherwise
; return the command number.
;
ln1 ldy #disp_cnum branch if not a language
lda [r0],Y
bpl ln2
and #$7FFF set language number
tay
lda #0 set command number
ln2 pha set command name
phy
move4 r0,ctlast
lla r0,buff1
jsr SetCommandName
ply
pla
sec successful search
rts
end
****************************************************************
*
* FindCommand2 - Find a command by command number
*
* Inputs:
* A - command or language number to search for
*
* Outputs:
* C - set if language is in command table
* R0 - if C is set, points to language name
* CTLAST - points to command
*
****************************************************************
*
FindCommand2 start
debug FindCommand2
using Common
sta r4 save language number
move4 ctpointer,r0
st1 ldy #disp_cnum+1 quit if at end of table
lda [r0],Y
beq err
dey branch if not a language
lda [r0],Y
cmp r4 continue search if not one we want
beq st3
ldy #disp_name get next command
lda [r0],Y
and #$00FF
clc
adc #disp_name+1
adc r0
sta r0
bcc st1
inc r2
bra st1
st3 move4 r0,ctlast allow restartable languages
add4 r0,#disp_name R0 points to language name
sec found it
rts
err clc language not found
rts
end
****************************************************************
*
* FirstAlias - Get the first alias entry
* FirstVariable - Get the first variable entry
* NexatAlias - Get next alias entry
* NextVariable - Get next variable entry
*
* Inputs:
* V_POINTER - pointer to variable table
* A_POINTER - pointer to alias table
* R0 - points to current variable
*
* Outputs:
* R0 - points to next variable,alias (0 if none)
* R4 - points to variable,alias name
* R8 - points to variable,alias string
*
****************************************************************
*
FirstVariable start
debug FirstVariable
using Common
using RecCom
move4 v_pointer,r0 get the variable table pointer
bra nv1
FirstAlias entry
move4 a_pointer,r0 get the alias table pointer
bra nv1
NextVariable entry
NextAlias entry
lda [r0] next entry
tax
ldy #2
lda [r0],Y
stx r0
sta r0+2
nv1 ldy #10 move the name and value pointer
ldx #6
nv2 lda [r0],Y
sta r4,X
dey
dey
dex
dbpl X,nv2
rts rts
end
****************************************************************
*
* GetBootVol - Get the boot volume
*
* Inputs:
* dcb - address of the parameter block
*
* Outputs:
* A - error code; 0 if no error occurred
*
* Notes:
* This subroutine reserves a memory buffer based on
* the actual length of the boot volume name. The
* address of the buffer is returned in the appropriate
* spot in the parameter block. The caller is
* responsible for disposing of the memory. No memory
* is reserved if an error occurs.
*
****************************************************************
*
GetBootVol start
buffPtr equ 1 pointer to the file name buffer
err equ 5 error
sub (4:dcb),6
stz err assume we will succeed
lda #0 get the length of the buffer
sta shortName+2
OSGet_Boot_Vol shortPrm
lda shortName+2 reserve a block of memory
clc
adc #4
jsl Malloc
ldy #2 save the pointer to the memory
sta [dcb],Y
sta buffPtr
iny
iny
txa
sta [dcb],Y
sta buffPtr+2
ora buffPtr check for out of memory condition
bne lb1
dec err (err = -1)
bra lb2
lb1 lda shortName+2 set the length of the buffer
clc
adc #4
sta [buffPtr]
ph4 dcb get the volume name
ph2 #$2028
jsl $E100B0
bcc lb2 branch if no error occured
sta err save the error number
free buffPtr dispose of the buffer
lb2 ret 2:err return the error code
shortPrm dc i'1',a4'shortName' parm for Get_Boot_Vol
end
****************************************************************
*
* GetDirEntry - Get a directory entry
*
* Inputs:
* dcb - address of the parameter block
*
* Outputs:
* A - error code; 0 if no error occurred
*
* Notes:
* This subroutine reserves memory buffers based on
* the actual length of the file path name and the
* option list. The address of the buffers are returned
* in the appropriate spot in the parameter block. The
* caller is responsible for disposing of the memory.
*
* No memory is reserved if an error occurs.
*
* Nil is returned for the optionList parameter if the
* length of the option list is 0.