Repository navigation
Expand file tree
/
Copy pathsh.asm
More file actions
1382 lines (1289 loc) · 27.4 KB
/
Copy pathsh.asm
File metadata and controls
1382 lines (1289 loc) · 27.4 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
keep obj/sh
mcopy sh.macros
title 'ORCA/M Shell 2.0 Source ** CONFIDENTIAL **'
****************************************************************
*
* ORCA/M SHELL 2.0
* APW SHELL 2.0
* November 1988
*
* By Phil Montoya and Mike Westerfield
*
* Copyright 1986-1988
* By the Byte Works, Inc.
*
* The source code for APW is protected by trade secret. It
* cannot be released or used in any way except for building
* APW and archiving the source without the written permission
* of the Byte Works, Inc.
*
****************************************************************
*
main start
copy sh.dp
using common
phb save old data bank reg
phk set data bank register
plb
sta user_id save my user ID
sta ~user_id
tsc save stack pointer
sta sh_my_stack
sub2 sh_my_stack,#$2FE,sh_low_stack compute stack boundries
add2 sh_low_stack,#$100,sh_min_stack
tdc save location of my DP
sta sh_my_dp
jsr Initialize initialize the shell
brl Monitor enter command processor
~user_id entry
ds 2
traceMode entry
dc i'0'
end
****************************************************************
*
* StackFrame - this segment is the stack frame for the shell
*
****************************************************************
*
StackFrame start Stack
kind $0012
ds 1024
end
****************************************************************
*
* Variables
*
* Variables are nested, with each EXEC file level having its
* own set of variables. For that reason, the variables are
* implemented as a linked list of variable files.
*
* The global variable V_POINTER is the pointer to the active
* variable file.
*
* Each variable file is a series of variable records. One for
* each variable. The structure of the record is as follows:
*
* Byte Length Use
* ---- ------ ---
* 0 4 pointer to next variable
* 4 4 pointer to null terminated name of variable
* 8 4 pointer to null terminated value of variable
* 12 2 export flag
*
* Since each call has it's own variable table the V_NEXT is the
* pointer to the next variable pointer record. This is important
* inorder to clean up and restore level 0 variable table after a
* restet.
*
****************************************************************
eject
****************************************************************
*
* COMMON - Common Data Area
*
****************************************************************
*
Common data
;
; Constants
;
buffSize equ $2004 max size of a GS/OS path name
optionBuffSize equ $404 max size of a GS/OS option list
max_dcb equ 56 Maximum length of DCB (must be even)
outofmem equ $0201 out of memory error
RETURN equ $0D RETURN key code
TAB equ $09 TAB key code
ins_stack_size equ 256 size of instruction stack
eline_len equ 2048 expanded line length
max_lines equ 20 # lines in line buffer (must be even)
pro_entry equ $E100A8 ProDOS entry point
pro_stack_entry equ $E100B0 ProDOS stack entry point
! file type names and numbers
TXT equ $04
SRC equ $B0
OBJ equ $B1
LIB gequ $B2
! define set constants
lclc &c
lclc &a
lcla &i
lcla &n
&a setc abcdefghijklmnopqrstuvwxyz
&i seta 1
.common1
&c amid &a,&i,1
&n seta +($40000000|-(&i-1))|1
set_&c equ &n
&i seta &i+1
aif &i<=26,^common1
! Statement control loop
endsy equ 0 end of stack pointer
loopsy equ 1 loop node
ifsy equ 2 if node
forsy equ 3 for node
! Displacements into command table entry
disp_restart gequ 0 reastartable flag
disp_user_id gequ 2 last known user ID
disp_cnum gequ 4 command number
disp_name gequ 6 name (length byte followed by ascii)
;
; File types and thier associated identifiers
;
typecode dt 01,BAD
dt 02,PCD
dt 03,PTX
dt 04,TXT
dt 05,PDA
dt 06,BIN
dt 07,FNT
dt 08,FOT
dt 09,BA3
dt 0A,DA3
dt 0B,WPF
dt 0C,SOS
dt 0F,DIR
dt 10,RPD
dt 11,RPI
dt 12,AFD
dt 13,AFM
dt 14,AFR
dt 15,SCL
dt 16,PFS
dt 19,ADB
dt 1A,AWP
dt 1B,ASP
dt 20,TDM
dt 2A,8SC
dt 2B,8OB
dt 2C,8IC
dt 2D,8LD
dt 2E,P8C
dt 42,FTD
dt 50,GWP
dt 51,GSS
dt 52,GDB
dt 53,DRW
dt 54,GDP
dt 55,HMD
dt 56,EDU
dt 57,STN
dt 58,HLP
dt 59,COM
dt 5A,CFG
dt 5B,ANM
dt 5C,MUM
dt 5D,ENT
dt 5E,DVU
dt 6B,BIO
dt 6D,TDR
dt 6E,PRE
dt 6F,HDV
dt A0,WPC
dt AB,GSB
dt AC,TDF
dt AD,BDF
dt AF,TOK
dt B0,SRC
dt B1,OBJ
dt B2,LIB
dt B3,S16
dt B4,RTL
dt B5,EXE
dt B6,PIF
dt B7,TIF
dt B8,NDA
dt B9,CDA
dt BA,TOL
dt BB,DRV
dt BC,LDF
dt BD,FST
dt BF,DOC
dt C0,PNT
dt C1,PIC
dt C2,ANI
dt C3,PAL
dt C5,OOG
dt C6,SCR
dt C7,CDV
dt C8,FON
dt C9,FND
dt CA,ICN
dt D5,MUS
dt D6,INS
dt D7,MDI
dt D8,SND
dt DB,DBM
dt E0,LBR
dt E2,ATK
dt EE,R16
dt EF,PAS
dt F0,CMD
dt F5,DMP
dt F9,OS6
dt FA,INT
dt FB,IVR
dt FC,BAS
dt FD,VAR
dt FE,REL
dt FF,SYS
dc i1'0'
;
; Local Storage
;
application_id ds 2 application's ID
appName ds 17 application name buffer (15 char max)
caseSensitive ds 2 is CompareOSStrings case sensitive?
reset_app ds 2 reset application?
clang dc i'3' current language number
cline ds 2 disp into 20 line line buffer
cthandle ds 4 command table handle
ctlast ds 4 pointer to last command table
! entry found by FindCommand
ctpointer ds 4 pointer to command table
exec_exit ds 2 exit EXEC early?
exec_level ds 2 exec file level
exec_return ds 2 EXEC return code for early exit
executeCmd ds 2 EXECUTE command?
stop_flag ds 2 stop (abort) exec flag
filelist ds 4 head of list of fastfile files
o_error ds 2 error number for redirected output
lastStatus ds 2 last status value set
line_num ds 4 line counter used by type
line_hand ds 4 handle of 20 line line buffer
non_ascii ds 2 non_ascii allowed from type?
one dc i'1' for exit compares by RETURN
osVersion ds 2 GS/OS version
regs ds 28 DP storage for shell routines
setUsed ds 2 has a shell variable been set?
sh_apstk ds 2 application stack space
sh_my_dp ds 2 my DP storage location
sh_my_stack ds 2 my STACK location
sh_low_stack ds 2 lowest STACK location
sh_min_stack ds 2 minimum threshold for shell call
skipping ds 2 print lines during echo?
systabl dw SYSTABL command table name
tabLanguage ds 2 tab language
tabs ds 256 current tab line
user_call_stack ds 2 S at call to user program (for QUIT)
user_id ds 2 shell's user id #
volumeName dc i'35,0',31c' ' general use volume name area
waitFlag ds 2 wait on keypress in Pause?
;
; Large buffers reserved for general use
;
buff1 ds line_len GP work buffer 1
ds 1
;
; wildcard list work areas
;
wcfileList ds 4 ptr to 1st file list entry
wcLength equ 54 length of a record
wcNext ds 4 next entry
wcPath ds 4 ptr to full path name
wcAccess ds 2 access attribute
wcFileType ds 2 file type
wcAuxType ds 4 aux type
wcStorageType ds 2 storage type
wcCreateDateTime ds 8 create date
wcModDateTime ds 8 mod date
wcOptionList ds 4 option list pointer
wcEOF ds 4 EOF
wcBlocksUsed ds 4 blocks used
wcResourceEOF ds 4 resource fork EOF
wcResourceBlocks ds 4 resource fork block count
nxRec dc i'12' 12 entries total
nxPath ds 4 ptr to full path name
nxAccess ds 2 access attribute
nxFileType ds 2 file type
nxAuxType ds 4 aux type
nxStorageType ds 2 storage type
nxCreateDateTime ds 8 create date
nxModDateTime ds 8 mod date
nxOptionList ds 4 option list pointer
nxEOF ds 4 EOF
nxBlocksUsed ds 4 blocks used
nxResourceEOF ds 4 resource fork EOF
nxResourceBlocks ds 4 resource fork block count
;
; Language info interface section
;
ldpList ds 4 langauge dependent parameter list
li_dcb dc i'11' Linfo DCB
li_saddr ds 4 addr of source file name
li_oaddr ds 4 addr of output file name
li_paddr ds 4 addr of parameter list
li_laddr ds 4 addr of language specific input string
li_merr dc i1'0' max error level allowed
li_merrf dc i1'0' max error level found
li_ops dc b'0000 0100' operations flag
li_keep dc i1'0' keep flag
li_minus ds 4 set of letters selected with -
li_plus ds 4 set of letters selected with +
li_org dc i4'0' origin
;
; User modifyable vectors
;
edit_vector dc i1'$5C',a3'EDIT_ENTRY' edit command processor
cout_vector dc i1'$5C',a3'ChOut' console out vector
mntr_vector dc i1'$5C',a3'MNTR_ENTRY' error entry for monitor
;
; Multiple compile names variables
;
firsttime ds 2 first time through flag
expkeep ds 2 explicit keep defined
multiple ds 2 multple names flag
nameListPtr ds 4 list of names to compile
objPtr ds 4 list of object file names
;
; File names
;
bs dosw ':BLANK' default name for new disk
console dosw .CONSOLE console device name
editor dosw '15:EDITOR' system editor
helpDir dosw '17:HELP:' help file directory
linker dosw '16:LINKER' command line linker
linked dosw '16:LINKED' scriptable linker
prefix0 dosw '8:' current prefix
systabs dosw '15:SYSTABS' system tab file
util dosw '17:' utility prefix
;
; Shell variable names
;
command dosw Command name of last command
echoStr dosw ECHO echo command lines?
exitStr dosw Exit exit on non-zero {Status}?
In dosw IN IN string; used in for loops
insert dosw Insert Insert mode flag
linkName dosw LinkName default linker keep name
keepName dosw KeepName default compiler keep name
parameters dosw Parameters name of parameters variable
pound dosw '#' #; set to # of exec paramaters
prompt dosw Prompt command line prompt
scroll dosw Scroll scroll lines variable
separator dosw Separator path name separator
status dosw Status status of last command
trueStr dosw True boolean true
;
; Multi-use constant DCB's
;
svRec dc i'3',a4'exitStr,trueStr',i'0' "set exit true"
end
****************************************************************
*
* RECCOM - Common Data Area for Reset Records
*
****************************************************************
*
RecCom data
type_ptr ds 4 type buffer pointer
;
; DCBs
;
exec_next ds 4 pointer to next exec record
exec_ptr ds 4 pointer to exec string
exec_disp ds 2 displacement into exec string
ins_next ds 4 pointer to next instruction stack record
ins_ptr ds 4 pointer to instruction stack
ins_disp ds 2 disp in instruction stack
ins_size ds 2 current size of instruction stack
ex_next ds 4 pointer to next exec file record
ex_ptr ds 4 pointer to exec file
v_next ds 4 pointer to next variable record
v_pointer ds 4 pointer to variable list
a_next ds 4 pointer to next alias record
a_pointer ds 4 pointer to alias list
end
****************************************************************
*
* DoLogin - Read and execute the LOGIN command file
*
****************************************************************
*
DoLogin private
debug DoLogin
using Common
using RecCom
;
; Read the LOGIN file.
;
OSSet svRec set EXIT to true
lla op_path,login open the command table file
open op_dcb
jcs done
lda op_ref save ref #
sta cl_ref
sta rd_ref
sta gt_ref
get_eof gt_dcb find spot for file
jcs err1
lda gt_mark
ldx gt_mark+2
clc
adc #2
bcc lb1
inx
lb1 jsl MLalloc
sta fhandle
stx fhandle+2
ora fhandle+2
jeq err1
move4 fhandle,rd_data
move4 gt_mark,rd_req read the file
read rd_dcb
jcs err
close cl_dcb
add4 rd_data,gt_mark,r0 set eof mark
lda #0
sta [r0]
;
; Execute the commands
;
move4 rd_data,exec_cmn set addr of buffer
stz exec_flag
execute exec_dcb do it
free fhandle get rid of file
PushVariables 0 export LOGIN variables
stz v_next set level to zero
stz v_next+2
jsr PushAlias push the alias's
stz a_next set level to zero
stz a_next+2
done rts
;
; Handle errors.
;
err free fhandle
err1 close cl_dcb
err2 puts #'Error processing LOGIN file:',cr=t,errout=t
rts
;
; Local data
;
fhandle ds 4 file handle
login dw '15:LOGIN'
exec_dcb anop execute DCB
exec_flag ds 2 flags
exec_cmn ds 4 address of commands
cl_dcb anop close DCB
cl_ref ds 2
gt_dcb anop get EOF DCB
gt_ref ds 2
gt_mark ds 4
rd_dcb anop read DCB
rd_ref ds 2
rd_data ds 4
rd_req ds 4
rd_tran ds 4
op_dcb anop open DCB
op_ref ds 2
op_path ds 4
op_buf ds 4
end
****************************************************************
*
* Initialize - Initialize The ORCA Shell
*
****************************************************************
*
Initialize private
debug Initialize
using Common
using RecCom
OSGet_Version vrRec get the version number
jcs error
lda vrVersion check the version number
and #$7FFF
sta osVersion
cmp #$0300
bge lb1
puts #'Requires version 3.0 or later of GS/OS.',cr=t
jmp TermError
lb1 jsr InitTools initialize the tools
jsr InitMM initialize our memory manager
lda #-1 no tab line, yet
sta tabLanguage
stz reset_app not in an application
stz caseSensitive string compares are not case sensitive
stz skipping not skipping to an end
stz exec_level no exec files, yet
stz ex_next ex_next = nil
stz ex_next+2
stz v_next v_next = nil
stz v_next+2
stz a_next a_next = nil
stz a_next+2
stz exec_next exec_next = nil
stz exec_next+2
stz ins_next ins_next = nil
stz ins_next+2
stz type_ptr type_ptr = nil
stz type_ptr+2
stz fileList fileList = nil
stz fileList+2
stz ldpList ldpList = nil
stz ldpList+2
stz li_saddr li_saddr = nil
stz li_saddr+2
stz li_oaddr li_oaddr = nil
stz li_oaddr+2
stz li_paddr li_paddr = nil
stz li_paddr+2
stz li_laddr li_laddr = nil
stz li_laddr+2
stz nameListPtr nameListPtr = nil
stz nameListPtr+2
lda #1 be sure to set {status}
sta setUsed
stz lastStatus
sta waitFlag wait on keypress in Pause
stz lp initialize the line handler
stz lp+2
stz ep
stz ep+2
lda #9 get prefix 9
sta pr1Num
ph4 #pr1
jsr GetPrefix
tax
jne error
move4 pr1Name,r0 if it is not set then
lda [r0]
bne lb2
free pr1Name free the name buffer
lda #1 get prefix 1
sta pr1Num
ph4 #pr1
jsr GetPrefix
tax
jne error
lda #9 set prefix 9 to the value of prefix 1
sta pr1Num
OSSet_Prefix pr1
jcs error
lb2 free pr1Name free the name buffer
lda #7 set prefixes 0 to 7 to null
sta prNull+2
lb3 OSSet_Prefix prNull
jcs error
dec prNull+2
bpl lb3
OSSet_Prefix pr0 set the system prefixes
jcs error
OSSet_Prefix pr2
jcs error
OSSet_Prefix pr3
jcs error
OSSet_Prefix pr4
jcs error
OSSet_Prefix pr5
bcs error
OSSet_Prefix pr6
bcs error
OSSet_Prefix pr7
bcs error
jsr TrapProDOS trap the ProDOS vector
jsr IOInit initialize the I/O handler
malloc #max_lines*(line_len+1) reserve a line buffer
sta line_hand
sta r0
stx line_hand+2
stx r2
ora r2
bne in0
lda #outofmem
brl error
in0 move4 line_hand,r0 set it to 0
ldy #max_lines*(line_len+1)-2
lda #0
in1 sta [r0],Y
dey
dey
bpl in1
jsr InitConsole initialize console drivers
bcs error
stz a_pointer initialize alias list
stz a_pointer+2
jsr SplashScreen bring up the screen
lla r0,cName read in the command table
jsr ReadSYSCMND
jsr DoLogin execute the LOGIN file
OSSet svRec set EXIT to true
rts
error jsl SysError load error
jmp TermError
;
; Local data area
;
pr1 dc i'2' for setting prefix 9
pr1Num ds 2
pr1Name ds 4
prNull dc i'2,0',a4'null' for zeroing a prefix
null dc i'0'
pr0 dc i'2,8',a4'work' standard prefixes
pr2 dc i'2,13',a4'libraries'
pr3 dc i'2,14',a4'work'
pr4 dc i'2,15',a4'system'
pr5 dc i'2,16',a4'languages'
pr6 dc i'2,17',a4'utilities'
pr7 dc i'2,18',a4'work'
system dosw '9:SHELL' default prefix values
utilities dosw '9:UTILITIES'
languages dosw '9:LANGUAGES'
libraries dosw '9:LIBRARIES'
work dosw '9:'
vrRec dc i'1' OSGet_Version record
vrVersion ds 2
cName dosw '15:SYSCMND' name of the command table
end
****************************************************************
*
* InitTools - Initialize toolkits
*
* Outputs:
* C - set if error
*
****************************************************************
*
InitTools private
debug InitTools
using Common
_TLStartup start up tool locator
ph2 #0 set up memory manager
_MMStartup
pla
ora #$100 make sure we use aux ID
sta User_id
sta ~User_id
rts
end
****************************************************************
*
* MakeRoom - make room at the bottom of the screen
*
* Notes: This is a work-around to a bug in 5.0.4. It can be
* removed once 5.0.4 is no longer in use.
*
****************************************************************
*
MakeRoom private
debug MakeRoom
using Common
using IOCom
ldx #14 save those critical values
lb0 lda r0,X
sta tr0,X
dex
dex
bpl lb0
move4 p1,tp1
lda #4 default count is 4
sta count
lla r12,scroll if {Scroll} <> nil then
jsr FindVariable
lda r0
ora r2
beq lb1
lda [r8] if length({Prompt}) = "1" then
cmp #1
bne lb1
ldy #2 if isDigit({Prompt}) then
lda [r8],Y
and #$00FF
cmp #'0'
blt lb1
cmp #'9'+1
bge lb1
and #$000F set count
sta count
lb1 lda consoleRefnum print count down arrows
sta dnRefnum
sta upRefnum
lda count
beq lb4
sta loop
lb2 ~OSWrite dnRec
dec loop
bne lb2
lb3 ~OSWrite upRec print count up arrows
dec count
bne lb3
lb4 move4 tp1,p1 restore DP values
ldx #14
lb5 lda tr0,X
sta r0,X
dex
dex
bpl lb5
rts
;
; Local data
;
dnRec dc i'4' write DCB for down arrow
dnRefnum ds 2
dc a4'down'
dc i4'1'
ds 4
down dc i1'$0A'
upRec dc i'4' write DCB for up arrow
upRefnum ds 2
dc a4'up'
dc i4'1'
ds 4
up dc i1'$1F'
count ds 2 line counter
loop ds 2 loop counter
tr0 ds 16 temp dp area
tp1 ds 4 temp p1 area
end
****************************************************************
*
* Monitor - Line editor and command processor
*
****************************************************************
*
Monitor start
debug Monitor
using Common
mn2 stz stop_flag initialize the stop flag
jsr StopSpin stop the spinner
putcr start with a fresh line
lla r12,prompt if {prompt} <> nil then
jsr FindVariable
lda r0
ora r2
beq lb2
lda [r8] if {prompt} <> "#" then
cmp #1
bne lb1
ldy #2
lda [r8],Y
and #$00FF
cmp #'#'
beq lb3
lb1 ph4 r8 print({prompt})
ph2 #$2000
jsl PrintOSName
bra lb3 else
lb2 cout #'#' write out the prompt character
lb3 la r0,line+1 read the line
jsr ReadLine
putcr
lda line+1 nul terminate the line
and #$00FF
tay
lda #0
sta line+2,y
lla exec_cmn,line+2 set up the execute DCB
stz exec_flag
stz exec_level
Execute exec_dcb execute the line
brl mn2
line dc i1'line_len,0'
ds line_len+2
exec_dcb anop execute DCB
exec_flag ds 2 flags
exec_cmn ds 4 address of commands
end
****************************************************************
*
* ReadLine - Get A Line
*
* Inputs:
* outLine - addr to place line read
*
* Note: This routine makes shell calls which disrupt the
* direct page. Be sure and save/restore critical values
* before calling the shell!
*
****************************************************************
*
ReadLine private
debug ReadLine
using Common
using IOCom
up_arrow equ $0B key codes
down_arrow equ $0A
right_arrow equ $15
outLine equ r0 addr of line
wp1 equ r2 work pointer
;
; Initialization
;
lda cline eline := cline
sta eline
lda osVersion if osVersion <= 3.03 then
cmp #$0304
bge in1
jsr MakeRoom
in1 anop endif
;
; Read a line
;
lda tlNum include up/down arrows in terminator list
sta ntNum
~OSD_Control ntDCB
lda #$8001 get the current input port values
sta code
~OSD_Status dvDCB
short M use a blank fill
lda #' '
sta list
stz list+3 don't beep me in! (God, how I hate beeps!)
stz entry_type initial entry
lda list+2 use overstrike, disable control charactes
ora #$01
and #$BF
sta list+1
sta list+2
long M
ldx #14 if insert <> nil then
fv1 lda r0,X
sta tr0,X
dex
dex
bpl fv1
move4 p1,tp1
lla r12,insert
jsr FindVariable
lda r0
ora r2
beq fv2
lda list+1 use insert mode
and #$FEFE
sta list+1
fv2 move4 tp1,p1
ldx #14
fv3 lda tr0,X
sta r0,X
dex
dex
bpl fv3
lda #$8000 set the parameters
sta code
~OSD_Control dvDCB
~OSD_Control frDCB do a formatted read
lb0 lda outLine read a line
inc A
sta rdLine
lda #^ReadLine
sta rdLine+2
lla rdLen,254
~OSD_Read rdDCB
short I,M set the length of the line
lda rdTrans
sta (outLine)
long I,M
;
; Handle the various terminators
;
lda #$8001 get the input port values
sta code
~OSD_Status dvDCB
lda last_Term if last_Term = RETURN then
and #$007F
cmp #RETURN
bne tr2
lda (outline) if length(outLine) > 0 then
and #$00FF
cmp #1
blt rt0
jsr SaveLine save the line
lda cline ++cline
jsr IncLines
sta cline
rt0 lda cursor_pos move to the end of the line
and #$00FF
sta cnt
lda (outLine)
and #$00FF
sec
sbc cnt
beq rt2
bmi rt2
sta cnt
lda consoleRefnum
sta mrRefnum
rt1 ~OSWrite mrRec
dec cnt
bne rt1
rt2 anop
bra fn1 exit
tr2 cmp #down_arrow else if last_Term = down_arrow then
bne tr3
jsr Clear clear the characters typed
lda cline if cline = eline then
cmp eline
bne tr2a
jsr SaveLine save the current line
tr2a lda eline ++eline
jsr IncLines
sta eline
jsr SetLine set the default line
brl lb0 go get the new input
tr3 cmp #up_arrow else if last_Term = up_arrow then
bne tr5
jsr Clear clear the characters typed
lda cline if cline = eline then
cmp eline
bne tr3a
jsr SaveLine save the current line
tr3a sec --eline
lda eline
sbc #line_len+1
bpl tr4
lda #(line_len+1)*(max_lines-1)