forked from hperaza/RSX280
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathksys.mac
2906 lines (2540 loc) · 71.4 KB
/
ksys.mac
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
; KSYS.MAC
; KERMIT - (Celtic for "FREE")
;
; This is the RSX180/280 implementation of the Columbia University
; KERMIT file transfer protocol. (C) 2021-2022, Hector Peraza.
;
; Version 4.0
;
; Derived from Kermit-80, originally written by Bill Catchings of the
; Columbia University Center for Computing Activities, 612 W. 115th St.,
; New York, NY 10025. with contributions by Frank da Cruz, Daphne Tzoar,
; Bernie Eiben, Bruce Tanner, Nick Bush, Greg Small, Kimmo Laaksonen,
; Jeff Damens, and many others.
;
; Copyright June 1981,1982,1983,1984,1985 Columbia University
;
; This file constains mostly RSX180-specific routines, and also
; implements the DIRECTORY, ERASE, RENAME and COPY commands.
;
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; Revision history (latest first):
;
; edit 21, 4-Dec-2021 by H. Peraza: add VFC parameter to QIO blocks as
; required by RSX180/280 V6.31 and up.
;
; edit 20, 18-May-2022 by H. Peraza: fix remote operation (line set to TI:).
;
; edit 19, 22-May-2021 by H. Peraza: when selecting a new line, update the
; SPEED variable with the value obtained from device characteristics.
;
; edit 18, 28-Mar-2021 by H. Peraza: the DIR routine now uses OUTCHR and
; OUTSTR for thext output. In server mode, the routines capture the
; output of DIR and sends it as a series of D-packets to the remote
; client.
;
; edit 17, 22-Mar-2021 by H. Peraza: added function to flush modem output,
; as required for proper working of the CONNECT command.
;
; edit 16, 21-Mar-2021 by H. Peraza: close all files at exit. Use PRTERR
; routine to output error messages. New get/send/server screen layout.
;
; edit 15, 9-Jan-2021 by H. Peraza: converted to Z80, rewritten almost
; completely for the RSX180/280 system. All I/O is now done here,
; so there are no more system calls (previously BDOS calls) scattered
; through the code. The DIRECTORY command now outputs file attributes
; and creation date in addition to file sizes when the listing mode
; is set to LONG, so it looks similar to PIP's output. The TC.ANS
; terminal characteristics byte is used to select between VT100 and
; VT52 screen control sequences. Modem I/O routines are buffered,
; with input timeout. Terminal input uses unsolicited-char AST.
;
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; Old Kermit-80 4.11 revision history:
;
; edit 14, 1-Apr-1991 by MF. Correct a bug which crept in with edit 13 which
; caused any control-key other than ^Y or ^Z to act like ^X after a key
; had been depressed to halt output of the TYPE/PRINT commands.
;
; edit 13, 25-Mar-1991 by MF. Make the TYPE command always abort to Kermit
; command-level if ^C is entered on the console even if multiple files
; are being typed via wild-cards. Make ^X typed on the console abort
; typeout of the current file and begin typeout of the next file,
; if any, otherwise go back to Kermit command-level.
; The foregoing also applies to the PRINT command.
;
; edit 12, 14-Feb-1991 by MF. Call "clrtop" in TYPE command at "type1"
; rather than sending a <ff> directly to the terminal as some
; terminals don't respond to <ff> characters. Thus the screen will be
; cleared (if the terminal allows) before each file is typed.
; Also use "getfil" rather than the bdos "openf" call to open
; files for typing (label "type2"). This tightens up the code.
; Zero "fcbcnt" before starting to type files (label "type0b").
; This apparently fixes a phantom bug which caused incorrect lookup (and
; hence garbage typeout) of files occassionally after a new disk
; was inserted and a SET DEFAULT-DISK was performed to reset the disk
; system. (It looked like parts of other files were being typed, as
; if the directory had been misread or had not been reset.)
;
; edit 11, 8-Feb-1991 by MF. Cause the bdos call for direct console input
; in "ckchr" **not** to go thru the bdos trap but to call bdos at 0005h
; directly. This corrects a bug wherein if commands such as INPUT
; (which check to see if a keyboard key has been pressed) were executed
; from a TAKE-file, the character following the terminator of such
; commands was being interpreted as that keyboard input, thus causing
; the next command in the TAKE-file to be unrecognized since its
; first character had been eaten as a result of the keyboard check.
; This bug **may** be the cause of a report received by Dr. Martin
; J. Carter of Nottingham University in the U.K. in which Kermit
; was reported to have read a character beyond a command terminator
; in a TAKE-file, making the subsequent command unrecognizable since
; its first character was missing.
;
; edit 10, 29-Jan-1991 by MF. Use the big buffer for TYPE/PRINT commands.
; Thus, edit 9 has been superseded.
;
; edit 9, 29-Jan-1991 by MF. Corrected EOF check in TYPE command routine
; following label "type20". a READF call, if successful, gives A=0
; (not A=0FFH) and A not zero if failure. Thus the "INR A" instruction
; checking for EOF was **always** nonzero. The reason the TYPE command
; worked is that CP/M text files indicate the text end-of-file with a
; Control-Z, in which case the TYPE routine branched correctly. In
; other words, this edit is more for aesthetic purposes to satisfy
; purists than something brought about by dire necessity!
;
; edit 8, 28-Jan-1991 by MF. Added code courtesy of Dr. Martin J. Carter
; of Nottingham University, UK, to use the big buffer for the COPY
; command.
;
; edit 7, 18-Sep-1990 by MF. Added RENAME routine to implement the
; RENAME (FRENAME) command to rename a CP/M file.
; Modified COPY routine to explicitly reject wild-carded filenames
; by using COMND function CMOFI rather than functions CMIFI and
; CMIFIN to get input and output filenames.
; Modified ERA and COPY routines to not act upon the respective
; commands until a "confirm" is typed. This prevents these
; routines from taking off upon recognition of action characters
; like "?", which can be quite annoying if one is an inexperienced user.
;
; edit 6, March 11, 1987 by OBSchou. Added in the TYPE and PRINT commands
; Both type to the screen, print also echoes to printer.
;
; edit 5 20 June, 1986. Added support for multiple file FCB buffering.
;
; edit 4: June 16, 1986 OBSchou at Loughborough University, UK
; added in a test to prevent a DIR command issued from a TAKE command
; being interruped by the next character in the take command buffer.
; Also added code for USER nn. (Well, its OS related,is it not?)
;
; edit 3: July 8, 1984 (CJC)
; Merge modifications from Toad Hall: support LASM (linked by CPSTT,
; links to CPSWLD), use prcrlf where appropriate.
;
; edit 2: June 5, 1984 (CJC)
; documentation and formatting; delete unused code (dir13); add module
; version string.
;
; edit 1: May, 1984 (CJC)
; extracted from CPMBASE.M80 version 3.9; modifications are described in
; the accompanying .UPD file.
.Z80
ident /21/
include KDEF.INC
include SYSFN.INC
include QIO.INC
include DCB.INC
include TCB.INC
include FCB.INC
include BDRATES.INC
include ERRORS.INC
public SYSINIT,SYSEXIT,PRTSTR,SELCON,SELMDM,OUTCON,OUTMDM
public SYSSCR,SCRNP,SCRNRT,SCRFLN,CLRTOP,CLREOL,CSRPOS
public SCRERR,SCRST,RPPOS,SPPOS,SCREND,SYSCON,SYSCLS
public SYSINH,INHLPS,SYSINT,SYSFLT,MDMFLT,PRTFLT,SYSBYE
public SYSSPD,SPDTBL,SPHTBL,SYSPRT,INPCON,INPMDM,LPTSTAT
public GETCON,FLSCON,FLSMDM,OUTLPT,DELCHR,CLRLIN,TTAB
public PURMDM,TTYTYP,DELAY,EXTERN
public SYSVER,DIR,DIR2,ERA,COPY,RENAME,TYPE,CKCHR,MFINIT
public MFNAME,MFEND,SFCB,FCB,FCB2,OPENR,OPENRW,CREATF
public CLOSEF,CLOSE2,READF,READF2,SEEK2,WRITEF,DELET2
public OPENTK,READTK,CLSETK,SETFCB,ALUN,CHDIR,DSKFRE
public ERMS15,SFCB,HIDEFS,FREBKS
extrn KERMIT,COMND,NOUT,GETFIL,INBUF,PRCRLF,PRNFL,STRLEN
extrn STRCPY,CPYNAM,RSKP,DEVSTR,DIRSTR,OUTPRN,PRTERR
extrn OUTCHR,OUTSTR
extrn VERSION,BANNER,RSXVER,CURDEV,CURDIR,$MEMRY,BUFADR
extrn BUFSEC,BUFLEN,BUFPNT,MAXBSC,DBGFLG,HOSTNM,PORT
extrn TEMP1,NUMBER,CHRCNT,TAKFLG,TAKBUF,TAKFCB,FNBUF
extrn FCBS2,SRVFLG,SPEED,OPMODE
extrn ATTACH,DETACH,PUTCH,PUTSTR,TTLUN,TTFLSH,UCASE
extrn CPHLDE,CVTBD,CVTLD,BCD2BIN,CVTBH
; Terminal input queue offsets (see QGET and QPUT routines)
TQ.IP equ 0 ; input pointer
TQ.OP equ TQ.IP+1 ; output pointer
TQ.BUF equ TQ.OP+1 ; buffer
; File open bit numbers (see FOPNFL)
DFBIT equ 0 ; directory open bit flag
RFBIT equ 1 ; read file open bit flag
WFBIT equ 2 ; write file open bit flag
TFBIT equ 3 ; TAK file open bit flag
SFBIT equ 4 ; system file open bit flag
cseg
SYSVER: defb 'KSYS (21) 18-May-2022',0 ; name, edit number, date
; System-dependent initialization
; Called once at program start.
SYSINIT:
ld hl,0
ld de,GTKBUF
SC .GTSK ; get task information
ld hl,TCKSEC
ld c,I.TCKS
SC .GIN ; get ticks/sec for delay function
ld hl,HOSTNM
ld c,I.HOST
SC .GIN ; get host name
ld hl,CURDIR
ld c,GD.TI
SC .GDIR ; get current directory name
ld hl,RSXVER
ld c,I.VERS
SC .GIN ; get system type and version
ld de,'TI'
ld c,0
ld a,LUNTI
ld (TTLUN),a
ld b,a
SC .ALUN ; assign LUN to terminal
ld de,ASTCON ; terminal AST routine address
ld c,LUNTI
call ATTACH ; attach terminal with ASTs
ret c
ld hl,QIOSTC
SC .QIO ; put terminal in binary mode
ld ix,TTQ
call QINIT ; init terminal input queue
xor a
ld (OCNT),a ; clear comm line input
ld (ICNT),a ; and output char counters
ld hl,OBUF
ld (OPTR),hl ; reset input...
ld hl,IBUF
ld (IPTR),hl ; ...and output buffer pointers
ld (OPMODE),a ; default mode is Remote
ld (MDMSET),a ; no comm line attached yet
ld a,(TC.ANS+1) ; get terminal type
or a ; ANSI?
ld hl,VT100 ; use VT100 sequences if yes
jr nz,SINIT1
ld hl,VT52 ; else assume VT52
SINIT1: ld de,TTBLK
ld bc,TTSIZE
ldir ; setup terminal definition block
ld de,BANNER ; build banner string
ld hl,VERSION ; copy Kermit version
call STRCPY
ld hl,SYSMSG ; "on RSX"
call STRCPY
ld a,(RSXVER+2)
cp 2
ld a,'2'
jr z,SINIT2
ld a,'1'
SINIT2: ld (de),a ; store system type
inc de
inc hl
call STRCPY
ld hl,(RSXVER)
ex de,hl ; convert system version number to string
ld a,d ; major number
call CVTBD
ld (hl),'.' ; add a dot separator
inc hl
ld a,e ; minor number
call CVTBD
ld (hl),' '
inc hl
ld (hl),'('
inc hl
ld de,HOSTNM ; append host name
ld b,9
call CPYNAM
ld (hl),')'
inc hl
ld (hl),0 ; null ends string
; locate large buffer for multi-sector I/O: space between $MEMRY
; and the top of task memory is available for buffering, except
; we don't want to use more than NBUF buffers (if we use too many,
; the remote end could time out while we're writing to disk).
; NBUF is system-dependent, but for now we'll just use 8Kbytes.
; If you get retransmissions and other protocol errors after
; transferring the first NBUF sectors, lower the value with the
; SET BUFFER-SIZE command.
; Note: MAXBUF must be a multiple of BUFSIZ
NBUF equ 8*1024 ; 8K
NSEC equ NBUF/BUFSIZ ; 8K / number of bytes per sector
ld hl,(GTKBUF+GT.END) ; get top of available memory
ld de,($MEMRY) ; get start of buffer
ld (BUFADR),de ; store it
or a
sbc hl,de ; obtain size of free memory space
jr c,SINIT7 ; should not happen
ld b,0
ld de,BUFSIZ
or a
SINIT3: sbc hl,de ; see how many disk blocks we can fit in
jr c,SINIT4
inc b ; count
jr SINIT3 ; and loop
SINIT4: ld a,b
or a ; zero means no space for buffers
jr z,SINIT7 ; so exit
ld (MAXBSC),a ; save for SET BUFFER use to compare
cp NSEC ; initially limit the buffer size to this
jr c,SINIT5
ld a,NSEC
SINIT5: ld (BUFSEC),a ; how many disk blocks we can fit in buffer
ld hl,0 ; now compute buffer size
SINIT6: add hl,de ; as multiple of BUFSIZ
djnz SINIT6
ld (BUFLEN),hl ; store buffer size in bytes
ret ; return from system-dependent routine
SINIT7: ld de,NOROOM ; not enough room for buffers
call PRTSTR ; complain about it
xor a
ld (TTCHR1+1),a
ld hl,QIOSTC
SC .QIO ; restore terminal mode
ld hl,EX.SEV ; and return with error status
SC .EXIT
NOROOM: defb LF,'KER -- Not enough room',CR,0
SYSMSG: defb 'on RSX',0,'80 V',0
; System-dependent termination.
SYSEXIT:
call CLOSEF ; paranoia check (a file may remain open
call CLOSE2 ; after an Error or Abort condition)
call MFEND
call TTFLSH ; flush terminal output
ld a,(MDMSET)
or a ; comm line attached?
jr z,sysx1 ; no
ld hl,MDMRST
SC .QIO ; restore original comm line settings
ld c,LUNMDM
call DETACH ; detach from comm line
xor a
ld (MDMSET),a
ld (OPMODE),a
sysx1: xor a
ld (TTCHR1+1),a
ld hl,QIOSTC
SC .QIO ; restore terminal mode
ld c,LUNTI
call DETACH ; detach from terminal
ret
; Delay routine. Called with time (seconds) in HL. Aborts delay if a
; key is pressed.
; Destroys BC
DELAY: push hl
push de
call INPCON ; terminal input available?
jr nz,D1 ; yes, return
ld d,2 ; units = seconds, magnitude in HL
ld e,EFNTM
ld bc,0 ; no AST
SC .MRKT ; mark time
ld e,EFNTM
SC .WTSE ; wait for event flag
ld bc,0
ld e,EFNTM
SC .CMKT ; cancel timeout event if still pending
call INPCON ; drop char, if any
D1: pop de
pop hl
ret
; +----|----|----|----|----|----|----|...
; 1 |
; 2 | Kermit-180 V4.0 on RSX180 Vx.y (hostname)
; 3 |
; 4 | Packet number: ____
; 5 | Retries: ____
; 6 | File name: ____________
; 7 |
; 8 | Status: ______
; 9 | Last error: ______
; 10 |
; 11 | RPack: ___(if debugging)...
; 12 |
; 13 | SPack: ___(if debugging)...
; 14 |
; 15 |Kermit-180 SY0:[USER]> (when finished)
HDLIN equ 2
NPPOS equ 4*100h+18
RTPOS equ 5*100h+18
FNPOS equ 6*100h+18
ERPOS equ 9*100h+18
STPOS equ 8*100h+18
RPKPOS equ 11*100h+18
SPKPOS equ 13*100h+18
PRPLIN equ 15
; Set up screen display for file transfer
; Called with kermit version in DE
SYSSCR: call CLRTOP ; clear screen
ld hl,BANNER ; get banner string
push hl ; save address for a bit
call STRLEN ; compute length
ld a,80 ; screen width
sub b ; subtract length
rra ; and divide by 2 (carry should be clear)
ld c,a ; set column
ld b,HDLIN ; get header row
call CSRPOS ; position cursor
pop de ; get banner string
call PRTSTR ; print it
ld de,OUTLIN ; print field names
call XYSTR
ld a,(DBGFLG) ; is debugging enabled?
or a
ret z ; finished if no debugging
inc de ; set up debugging fields
XYSTR: ld a,(de) ; get column
or a ; zero?
ret z ; yes, return
ld c,a ; get column into reg C
inc de ; advance pointer
ld a,(de) ; get row
ld b,a ; into reg B
push de
call CSRPOS ; position cursor
pop de
inc de ; point to message
call PRTSTR ; output string
inc de ; skip trailing null
jr XYSTR ; and loop to process next
OUTLIN: defb 3,4,'Packet number:',0
defb 9,5,'Retries:',0
defb 7,6,'File name:',0
defb 10,8,'Status:',0
defb 6,9,'Last error:',0
defb 0
defb 11,11,'Rpack:',0
defb 11,13,'Spack:',0
defb 0
SCRNP: ld bc,NPPOS ; position cursor to output number of packets
jp CSRPOS
SCRNRT: ld bc,RTPOS ; position cursor to output number of retries
jp CSRPOS
SCRFLN: ld bc,FNPOS ; position cursor to output file name
call CSRPOS
CLREOL: ld de,TK ; erase line
jp PRTSTR
SCRERR: ld bc,ERPOS
call CSRPOS ; position cursor on error line
jp CLREOL ; erase line
SCRST: ld bc,STPOS
call CSRPOS ; position cursor on status line
jp CLREOL ; erase line
RPPOS: ld bc,RPKPOS
call CSRPOS ; position cursor on read packet line
jp CLREOL ; erase line
SPPOS: ld bc,SPKPOS
call CSRPOS ; position cursor on sent packet line
jp CLREOL ; erase line
; Modify SCREND to make the cursor line conditional on use of debugging.
SCREND: ld a,(DBGFLG)
or a
jr z,SCR1ND
ld bc,PRPLIN*100h+1; debugging in use
jr SCR2ND
SCR1ND: ld bc,RPKPOS ; no debugging
ld c,1
SCR2ND: call CSRPOS ; position cursor
CLREOS: ld de,TJ
jp PRTSTR ; erase to end of screen
; Output string in DE
PRTSTR: ex de,hl
call PUTSTR ; send it to terminal
call TTFLSH
ex de,hl
ret
; System-dependent processing for start of CONNECT command
SYSCON:
ret
; System-dependent close routine, called when exiting transparent session.
SYSCLS:
ret
; Help for system-dependent special functions.
; Called in response to <escape>?, after listing all the system-independent
; escape sequences.
SYSINH:
ld de,INHLPS ; we got options...
call PRTSTR ; print them.
ret
; Additional, system-dependent help for transparent mode (two-character
; escape sequences)
INHLPS:
defb CR,LF,'B Transmit a BREAK'
defb 0
; System dependent special functions
; Called when transparent escape character has been typed; the second
; character of the sequence is in A (and in B).
; Returns:
; non-skip: sequence has been processed
; skip: sequence was not recognized
SYSINT: call UCASE ; convert lower case to upper, for testing...
cp 'B' ; send break?
jp z,SENDBR ; yes, go do it. return nonskip when through.
jp RSKP ; take skip return - command not recognized.
; Officially, a "break" is 300 milliseconds of "space" (idle line is
; "mark"). (or maybe 200 milliseconds; I forget.) The timing isn't
; usually that critical, but we'll make an attempt, at least. Sending
; too long a break can cause some modems to hang up.
SENDBR:
ret
; System-dependent filter
; Called with character in E.
; If this character should not be printed, return with A = zero.
; Preserves BC, DE, HL.
; Note: <xon>,<xoff>,<del>, and <nul> are always discarded.
SYSFLT: ld a,e ; return non-zero
ret
; Modem filter
; Called with character to be sent to modem in E with parity set as
; appropriate.
; Return with accumulator = 0 to do nothing, <> 0 to send char in E.
MDMFLT: ld a,e ; return non-zero
ret
; Printer filter
; Called with character to be sent to printer in E
; Returns with A = 0 to do nothing, <> 0 to print it.
;
; This routine is for those printers that automatically insert
; a LF on CR, or CR for LF.
PRTFLT: ld a,e ; return non-zero
ret
; System-dependent processing for BYE command (e.g. to hang up the phone.)
SYSBYE:
ret
; Set baud rate, code in E.
SYSSPD: ld a,e ; get the parsed value
SETBD: ld (MDSPD+1),a ; store it
ld hl,MDMSPD
SC .QIO ; TODO: timeout?
ret c
ld a,(IOSB)
or a
ret z
scf
ret
; Speed tables
; (Note that speed tables MUST be in *alphabetical* order for later
; lookup procedures, and must begin with a value showing the total
; number of entries. The speed help tables are just for us poor
; humans.
; db string length,string,code (2 identical bytes or 1 word)
SPDTBL: defb 23 ; 23 entries
defb 3,'110',0, S.110, S.110
defb 6,'115200',0, S.115K2,S.115K2
defb 4,'1200',0, S.1200, S.1200
defb 5,'134.5',0, S.134, S.134
defb 5,'14400',0, S.14K4, S.14K4
defb 3,'150',0, S.150, S.150
defb 4,'1800',0, S.1800, S.1800
defb 5,'19200',0, S.19K2, S.19K2
defb 3,'200',0, S.200, S.200
defb 4,'2000',0, S.2000, S.2000
defb 4,'2400',0, S.2400, S.2400
defb 5,'28800',0, S.28K8, S.28K8
defb 3,'300',0, S.300, S.300
defb 4,'3600',0, S.3600, S.3600
defb 5,'38400',0, S.38K4, S.38K4
defb 4,'4800',0, S.4800, S.4800
defb 2,'50',0, S.50, S.50
defb 5,'57600',0, S.57K6, S.57K6
defb 3,'600',0, S.600, S.600
defb 4,'7200',0, S.7200, S.7200
defb 2,'75',0, S.75, S.75
defb 5,'76800',0, S.76K8, S.76K8
defb 4,'9600',0, S.9600, S.9600
SPHTBL: defb CR,LF,' 50 75 110 134.5 150 200 300 600'
defb CR,LF,' 1200 1800 2000 2400 3600 4800 7200 9600'
defb CR,LF,'14400 19200 28800 38400 57600 76800 115200'
defb 0
; This is the system-dependent SET PORT command.
SYSPRT: ld a,(MDMSET)
or a ; comm line attached?
jr z,SYSP1 ; no
ld hl,MDMRST
SC .QIO ; else restore original comm line settings
;jr c,...
ld c,LUNMDM
call DETACH ; detach from previous line
xor a
ld (MDMSET),a
SYSP1: ld hl,PORT ; get a pointer to name of new comm line
ld b,LUNMDM
call ALUN ; assign LUN and get device info
ret c ; on error, return
xor a
ld (ICNT),a ; reset I/O counters and pointers
ld (OCNT),a
push hl
ld hl,OBUF
ld (OPTR),hl
ld hl,IBUF
ld (IPTR),hl
pop hl
ld de,GTKBUF+GT.TI
call CMPDEV ; new line same as current terminal?
jr z,SYSP2 ; yes, don't change settings
;*TODO: attach with timeout, else the program will be
; blocked here until the terminal is detached.
ld de,0 ; no ASTs
ld c,LUNMDM
call ATTACH ; attach to comm line
ret c
ld a,0FFh
ld (MDMSET),a ; set flag
ld (OPMODE),a ; now in Local mode
ld hl,MDMGTC
SC .QIO ; remember original settings
;jr c,... ; don't return on error, but try instead
; to set characteristics that make sense?
ld a,(OLDSPD+1)
ld (SPEED),a ; update serial speed variable
ld hl,MDMSTC
SC .QIO ; slave terminal, disable echo
ret c
ld a,(IOSB)
or a
ret z
scf
ret
SYSP2: xor a
ld (MDMSET),a
ld (OPMODE),a ; now in Remote mode
ret
CMPDEV: ld b,3
cmp1: ld a,(de)
cp (hl)
ret nz
inc hl
inc de
djnz cmp1
ret
; Select modem port, called before using INPMDM or OUTMDM
; Preserves BC, DE, HL.
SELMDM: ld a,(MDMSET)
or a ; modem line already attached?
ret nz ; yes, return
push hl
push de
push bc
ld de,0 ; no ASTs
ld c,LUNMDM
call ATTACH ; (re)attach to comm line
jr c,selm1
ld a,0FFh
ld (MDMSET),a ; set flag
ld hl,MDMGTC
SC .QIO ; remember original settings
ld hl,MDMSTC
SC .QIO ; slave terminal, disable echo
selm1: pop bc
pop de
pop hl
ret
; Select console port, called before using INPCON or OUTCON
; Preserves BC, DE, HL.
SELCON: ; postpone operation until next console read
ret
RESCON: ld a,(MDMSET)
or a ; modem line attached?
ret z ; no, return
ld a,(OPMODE)
or a ; are we in Local mode?
ret nz ; yes, return
push hl
push de
push bc
ld de,ASTCON ; terminal AST routine address
ld c,LUNTI
call ATTACH ; (re)attach terminal with ASTs
jr c,selc1
ld hl,MDMRST
SC .QIO ; restore original comm line settings
xor a
ld (MDMSET),a ; clear flag
selc1: pop bc
pop de
pop hl
ret
; Get character from console, or return zero.
; Result is returned in A. Destroys DE, HL.
INPCON: call RESCON
push ix
call TTFLSH ; flush terminal output
ld ix,TTQ
call QGET ; fetch char, if available
pop ix
ret nc ; here it is
xor a ; else return zero
ret
; Wait for and get character from console.
; Result is returned in A. Destroys DE, HL.
GETCON: call RESCON
push ix
push bc
call TTFLSH ; flush terminal output
GC1: ld e,EFNGC
SC .CLEF ; clear event flag before accessing queue
ld ix,TTQ
call QGET ; fetch char
jr nc,GC2 ; if available, return
ld e,EFNGC
SC .WTSE ; else wait for character to arrive
jr GC1 ; loop to get char
GC2: or a
jr z,GC1 ; ignore null chars
pop ix
pop bc
ret
; Output character in E to the console.
; Destroys C, preserves E.
OUTCON: ld c,e
call PUTCH ; use SYSLIB routine
or a
ret
; Flush any pending console output.
FLSCON: jp TTFLSH ; use SYSLIB routine
; Unsolicited console input AST routine
ASTCON: ex (sp),hl ; fetch argument
push de
push bc
push ix
ld ix,TTQ
ld c,l
ld a,c ; get char
cp CTRLC ; Control-C?
call z,QINIT ; yes, purge input queue
call QPUT ; store char in queue
ld e,EFNGC
SC .SETF ; and set event flag
ld e,EFNTM
SC .SETF ; abort delay, if running
pop ix
pop bc
pop de
pop hl
SC .ASTX ; exit AST
; Reset input queue
QINIT: xor a
ld (ix+TQ.IP),a ; reset input
ld (ix+TQ.OP),a ; and output counters
ret
; Fetch character from queue. Returns with Carry set if queue is empty.
QGET: ld a,(ix+TQ.OP) ; get output pointer
cp (ix+TQ.IP) ; same as input pointer?
scf
ret z ; yes, queue empty, return with Carry set
ld e,a ; get output pointer into E
inc a ; advance output pointer for next op
and 3Fh ; wrap around
ld (ix+TQ.OP),a ; store new value
ld d,0 ; make 16-bit offset
push ix
add ix,de ; add to queue address
ld a,(ix+TQ.BUF) ; fetch char from buffer
pop ix
or a ; success, return with Carry clear
ret
; Store character in queue. Returns with Carry set if the queue is full.
QPUT: ld a,(ix+TQ.IP) ; get input pointer
ld e,a ; save it
inc a ; advance for next op
and 3Fh ; wrap around
cp (ix+TQ.OP) ; same as output pointer?
scf
ret z ; yes, queue full, return with Carry set
ld (ix+TQ.IP),a ; store new value
ld d,0 ; make 16-bit offset
push ix
add ix,de ; add to queue address
ld (ix+TQ.BUF),c ; store char in buffer
pop ix
or a ; success, return with Carry clear
ret
; Returns Z if queue is empty.
QEMPTY: ld a,(ix+TQ.IP) ; are input
sub (ix+TQ.OP) ; and output pointers equal?
or a ; set flags and return
ret
; Output character in E to the modem.
; The parity bit has been set as necessary.
; Returns nonskip; BC, DE, HL preserved.
OUTMDM: push hl ; save registers
push de
push bc
call OUTMD ; output char
pop bc
pop de
pop hl ; restore registers
ret ; and return
OUTMD: ld hl,(OPTR) ; load output buffer pointer
ld (hl),e ; store character
inc hl ; advance pointer
ld (OPTR),hl ; save it back
ld a,(OCNT) ; get char counter
inc a ; increase it
ld (OCNT),a ; save it back
cp 128 ; is buffer full?
jr z,FLSMDM ; yes, send it
ld a,e ; no, check character
cp CR ; carriage return?
ret nz ; no, return
;...
; Flush modem output.
; Destroys HL.
FLSMDM: ld a,(OCNT) ; get number of characters in buffer
or a
ret z
ld l,a
ld h,0 ; make it a 16-bit word
ld (QIOMWR+Q.LEN),hl ; save for QIO request
xor a
ld (OCNT),a ; clear character count
ld hl,OBUF
ld (OPTR),hl ; and reset output buffer pointer
ld hl,QIOMWR
SC .QIO ; send request
ret c ; error, queuing failed
ld a,(OSB) ; check return code
or a ; success?
ret z ; yes
scf ; no, set Carry and return
ret
; Get character from modem; return zero if none available.
; Destroys BC, DE, HL.
INPMDM: ld a,(ICNT) ; get input character count
or a ; anything in input buffer?
jr z,INPM2 ; no, time to read
INPM1: dec a ; yes, decrement character count
ld (ICNT),a ; store it back
ld hl,(IPTR) ; load input buffer pointer
ld a,(hl) ; fetch the character
inc hl ; advance pointer
ld (IPTR),hl ; store it back
or a ; return success
ret
INPM2: ld hl,IBUF
ld (IPTR),hl
ld d,1 ; set a timeout; units = ticks
ld hl,10 ; HL = magnitude
ld e,EFNMD ; use QIO event number
ld bc,0 ; no AST
SC .MRKT ; mark time
ld hl,QIOMRD ; try reading from modem port
SC .QIO ; queue operation and wait
push af
ld bc,0
ld e,EFNMD
SC .CMKT ; cancel timeout event if still pending
pop af
jr c,INPM4 ; request failed, return zero
ld a,(ISB) ; check read status
or a ; complete?
jr z,INPM3 ; yes
cp E.PEND ; request pending (timeout)?
jr nz,INPM4 ; no: something else, return zero
ld hl,QIOMKI
SC .QIO ; else kill the pending read operation
; (we still get a partial read)
ld a,(ISB) ; check read status
or a ; completed meanwhile?
jr z,INPM3 ; yes
cp E.ABOP ; no, read aborted?
jr nz,INPM4 ; no, return zero
INPM3: ld hl,(ISB+2) ; else process what we got
ld a,h ; check length
or l ; anything?
ret z ; no, return zero
ld a,l ; else get character count in A
jp INPM1 ; and go to fetch character and return
INPM4: xor a ; here on error, return zero
ret
; Purge comm input line.
; Modem is selected.
; Currently, just gets characters until none are available.
PURMDM: call INPMDM ; try to get a character