This repository has been archived by the owner on Nov 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 482
/
GWMAIN.ASM
3568 lines (3392 loc) · 106 KB
/
GWMAIN.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
; [ This translation created 10-Feb-83 by Version 4.3 ]
.RADIX 8 ; To be safe
CSEG SEGMENT PUBLIC 'CODESG'
ASSUME CS:CSEG
INCLUDE BINTRP.H
TITLE GWMAIN Copied from BINTRP.MAC
.RADIX 10
COMMENT *
--------- ---- -- ---- ----- --- ---- -----
COPYRIGHT 1975 BY BILL GATES AND PAUL ALLEN
--------- ---- -- ---- ----- --- ---- -----
ORIGINALLY WRITTEN ON THE PDP-10 FROM
FEBRUARY 9 TO APRIL 9 1975
BILL GATES WROTE A LOT OF STUFF.
PAUL ALLEN WROTE A LOT OF OTHER STUFF AND FAST CODE.
MONTE DAVIDOFF WROTE THE MATH PACKAGE (F4I.MAC).
*
.XLIST
FETOK=0 ;For FE extended tokens
FDTOK=0 ;For FD tokens too. (Must have
;FETOK==1.)
;tokens.
INTDEX=0 ;For Intelledex version.
NMPAGE=1 ;Number of text pages (for GW
;Multi-page)
;KPOS, etc.
LNREAD=0 ;For LINE READ statement
MELCO=0 ;Mitsubishi Electronics Co.
SIRIUS=0
MCI=0
ZENITH=0 ;ZENITH 8086
TETRA=0
CPM86=0
HAL=0
GENFLS=0
PANDBL=0
TSHIBA=0
SGS=0
ALPS=0
ALPCPM=0
GENWID=0
NNECBS=0
CAN8=0
PC8A=0
FN2SW=0 ;IBMTOK versions dispatch from IBMRES.MAC
LABEL=PC8A
HLPEDT=PC8A
OKI=0
BUBL=0
NORNF=0
IEESLV=0
TRSHHC=0
OLVPPC=0
NECPPC=0
USA=0 ;For HHC-USA version
EUROPE=0 ;For HHC-EUROPE version
.LIST
;Local Switches
;
LTRACE=ALPCPM ;trace output selectable
LABEL=PC8A
HLPEDT=PC8A
UCEMSG=NNECBS ;Upper case error messages.
OLD86=MELCO AND CPM86 ;For "old" 8086 error messages (prior
;to alignment for IBM compatibility).
OLDBLD=ALPCPM OR ALPS OR OKI OR HAL OR PC8A OR BUBL OR GW OR TSHIBA
INCLUDE GIO86U
INCLUDE MSDOSU ;MSDOS constants
EXTRN INIT:NEAR
EXTRN SETGSB:NEAR
DSEG SEGMENT PUBLIC 'DATASG'
ASSUME DS:DSEG
EXTRN ONGSBF:WORD
DSEG ENDS
BUFOFS=0
BUFOFS=2 ;MUST CRUNCH INTO ERALIER PLACE FOR
; SINGLE QUOTE
KBFLEN=BUFLEN+(BUFLEN/4) ;MAKE KRUNCH BUFFER SOMEWHAT
; LARGER THAN SOURCE BUFFER (BUF)
EXTRN NAME:NEAR
EXTRN INLIN:NEAR,CRDO:NEAR,CRDONZ:NEAR,STRCMP:NEAR,PPSWRT:NEAR
EXTRN OUTDO:NEAR
EXTRN BLTU:NEAR,CLEARC:NEAR,GTMPRT:NEAR,ISLET:NEAR,ISLET2:NEAR
EXTRN PTRGET:NEAR
EXTRN QINLIN:NEAR,SCRTCH:NEAR,STKINI:NEAR,RUNC:NEAR,RESFIN:NEAR
EXTRN PTRGT2:NEAR,STPEND:NEAR
EXTRN SYNCHR:NEAR
EXTRN SIGN:NEAR
EXTRN PRGFIN:NEAR,FILIND:NEAR
EXTRN FILINP:NEAR,INDSKC:NEAR
EXTRN LRUN:NEAR
EXTRN INXHRT:NEAR
EXTRN ZERO:NEAR,MOVE:NEAR,FOUT:NEAR,FIN:NEAR,PUSHF:NEAR
EXTRN MOVFR:NEAR,MOVRF:NEAR,MOVRM:NEAR,INPRT:NEAR,LINPRT:NEAR
EXTRN MOVFM:NEAR,MOVMF:NEAR
EXTRN INRART:NEAR,NEG:NEAR
EXTRN FREFAC:NEAR,FRETMS:NEAR,STRCPY:NEAR,GETSTK:NEAR
EXTRN STRLIT:NEAR,STRLT2:NEAR,STRLT3:NEAR,STRLTI:NEAR,STROUT:NEAR
EXTRN STRPRT:NEAR,STROUI:NEAR
EXTRN GETSPA:NEAR,PUTNEW:NEAR,STOP:NEAR,OMERR:NEAR,REASON:NEAR
EXTRN INSTR:NEAR
EXTRN PRINUS:NEAR,PUTTMP:NEAR
EXTRN FOUTH:NEAR,FOUTO:NEAR,STRO$:NEAR,STRH$:NEAR
EXTRN STRNG$:NEAR
EXTRN TON:NEAR,TOFF:NEAR
EXTRN SPACE$:NEAR
EXTRN SIGNS:NEAR
EXTRN UMULT:NEAR
EXTRN SIGNC:NEAR,POPHRT:NEAR
EXTRN FINLPT:NEAR
EXTRN VMOVFA:NEAR,VMOVAF:NEAR,ISIGN:NEAR,VSIGN:NEAR,VDFACS:NEAR
EXTRN VMOVMF:NEAR,VMOVFM:NEAR,FRCINT:NEAR,FRCDBL:NEAR,FRCSNG:NEAR
EXTRN VNEG:NEAR,PUFOUT:NEAR,DCXBRT:NEAR,IADD:NEAR
EXTRN FINDBL:NEAR
EXTRN VMOVE:NEAR,VALINT:NEAR,VALSNG:NEAR,FRCSTR:NEAR,CHKSTR:NEAR
EXTRN MAKINT:NEAR
EXTRN MOVE1:NEAR
EXTRN SCNSEM:NEAR
EXTRN WHILE:NEAR,WEND:NEAR
EXTRN CALLS:NEAR
EXTRN PROCHK:NEAR
EXTRN WRITE:NEAR
;The following block of externals was added on Dec 19, 1982 when BINTRP was
; Split up after the freeze of GW-BASIC Version 1.0
; This Split-up was not reflected in the PS1:<BASIC>BINTRP.MAC source.
; See Tom Corbett if you have any questions.
;
DSEG SEGMENT PUBLIC 'DATASG'
EXTRN MEMSIZ:WORD,FRETOP:WORD,VARTAB:WORD,STREND:WORD,TXTTAB:WORD
EXTRN ARYTAB:WORD
EXTRN CURLIN:WORD,DOT:WORD,DATLIN:WORD,NLONLY:WORD,ERRLIN:WORD
EXTRN ERRTXT:WORD
EXTRN MRGFLG:WORD,CHNFLG:WORD
EXTRN SAVSTK:WORD,SAVTXT:WORD,OLDLIN:WORD,NXTLIN:WORD,OLDTXT:WORD
EXTRN ONELIN:WORD,ONEFLG:WORD
EXTRN CNTOFL:WORD,TRCFLG:WORD,CONSAV:WORD,CONTXT:WORD,CONTYP:WORD
EXTRN NUMCON:WORD,CONLO:WORD
EXTRN AUTFLG:WORD,AUTLIN:WORD,AUTINC:WORD
EXTRN KBUF:WORD,BUFMIN:WORD,BUF:WORD
EXTRN PTRFIL:WORD,PTRFLG:WORD,DORES:WORD,VALTYP:WORD,FACLO:WORD
EXTRN DFACLO:WORD,FAC:WORD
EXTRN TEMP:WORD,TEMP2:WORD,TEMP3:WORD,TEMPA:WORD
EXTRN DSCTMP:WORD,TEMPST:WORD
EXTRN OPRTYP:WORD
EXTRN SUBFLG:WORD,FVALSV:WORD,DEFTBL:WORD,FLGINP:WORD,FLGSCN:WORD
EXTRN OVCSTR:WORD,INPPAS:WORD
EXTRN USRTAB:WORD,DONUM:WORD,ENDPRG:WORD,ENDFOR:WORD,DATPTR:WORD
EXTRN FLGOVC:WORD
EXTRN ERRFLG:WORD,SAVSEG:WORD,PRMLN2:WORD,PRMSIZ:WORD,PARM2:WORD
EXTRN PRMLEN:WORD,PRMSTK:WORD,PARM1:WORD
EXTRN FUNACT:WORD,NOFUNS:WORD,OPTVAL:WORD,OPTFLG:WORD,RNDX:WORD
DSEG ENDS
EXTRN INEG2:NEAR,FADD:NEAR
EXTRN $OVMSG:NEAR,ERRTAB:NEAR,LSTERR:NEAR,DSKERR:NEAR,NONDSK:NEAR
EXTRN REDDY:NEAR
EXTRN ERRSN:NEAR,ERRDV0:NEAR,ERRRE:NEAR,ERROV:NEAR,ERRMO:NEAR
EXTRN ERRTM:NEAR,ERRNF:NEAR
EXTRN ERRNR:NEAR,ERRLBO:NEAR,ERRDD:NEAR,ERRUF:NEAR,ERRFC:NEAR
EXTRN ERRIFN:NEAR,ERRFNO:NEAR,ERRDNA:NEAR,ERRFDR:NEAR,ERRRAD:NEAR
EXTRN ERRDFL:NEAR
EXTRN ERRIOE:NEAR,ERRBFM:NEAR,ERRFNF:NEAR,ERRBFN:NEAR,ERRIER:NEAR
EXTRN ERRRPE:NEAR
EXTRN ERRFAO:NEAR,ERRNMF:NEAR,ERRWH:NEAR,ERRBRN:NEAR,ERRFOV:NEAR
EXTRN ERRTMF:NEAR
EXTRN ERRFAE:NEAR,ERRUS:NEAR,ERRRG:NEAR,ERROD:NEAR,ERRFN:NEAR
EXTRN ERRUE1:NEAR ;ERRUE+DSKERR-NONDSK
EXTRN DSKER1:NEAR ;DSKERR-NONDSK
;The following externs are defined in GWEVAL.MAC
;
EXTRN MAKUPL:NEAR,MAKUPS:NEAR,GETYPR:NEAR,OCTCNS:NEAR,DOCNVF:NEAR
EXTRN ISMID$:NEAR
EXTRN FRMEVL:NEAR,FRMCHK:NEAR,GETINT:NEAR,GETBYT:NEAR,GETIN2:NEAR
EXTRN SNGFLT:NEAR
;The following externs are defined in GWLIST.MAC
;
EXTRN DELETE:NEAR,DEL:NEAR,TSTANM:NEAR,PLOOP2:NEAR
SUBTTL ROM VERSION INITALIZATION, AND CONSTANTS
;
; The reserved word tables are in another module. Consequently
; many things must be declared external. All of these things
; are in the code segement or are absolutes (like tokens).
; I.e., they are not in the data segment.
;
EXTRN ALPTAB:NEAR
EXTRN EQULTK:NEAR
EXTRN STMDSP:NEAR
EXTRN GREATK:NEAR
EXTRN INSRTK:NEAR
EXTRN LESSTK:NEAR,LSTOPK:NEAR
EXTRN MIDTK:NEAR,MINUTK:NEAR
EXTRN NMREL:NEAR,NOTTK:NEAR,NUMCMD:NEAR
EXTRN ONEFUN:NEAR
EXTRN POS:NEAR,PLUSTK:NEAR,PRINT:NEAR
EXTRN RESLST:NEAR
EXTRN SNGQTK:NEAR,SPCTAB:NEAR,SQRTK:NEAR,STEPTK:NEAR
EXTRN THENTK:NEAR
EXTRN USRTK:NEAR
EXTRN $AUTO:NEAR
EXTRN $DATA:NEAR,$DATCO:NEAR,$DELETE:NEAR
EXTRN $EDIT:NEAR,$ELSE:NEAR,$END:NEAR,$ERL:NEAR,$ERROR:NEAR
EXTRN $FN:NEAR,$FOR:NEAR
EXTRN $GOSUB:NEAR,$GOTO:NEAR
EXTRN $IF:NEAR,$INKEY$:NEAR,$INPUT:NEAR
EXTRN $LIST:NEAR,$LLIST:NEAR
EXTRN $NEXT:NEAR
EXTRN $POINT:NEAR,$PRINT:NEAR
EXTRN $REM:NEAR,$REMCO:NEAR,$RENUM:NEAR,$RESTORE:NEAR,$RESUME:NEAR
EXTRN $RETURN:NEAR,$RND:NEAR,$RUN:NEAR
EXTRN $SCREEN:NEAR,$STOP:NEAR,$STRING$:NEAR
EXTRN $THEN:NEAR,$TO:NEAR
EXTRN $USR:NEAR
EXTRN $VARPTR:NEAR
EXTRN $WEND:NEAR,$WHILE:NEAR
;
; Since the dispatch table is also no longer in BINTRP many
; addresses need to be declared internal.
;
PUBLIC AUTO
PUBLIC DATAS,DEFDBL,DEFINT,DEFREA,DEFSTR
PUBLIC ELSES,ERRORS
PUBLIC FOR
PUBLIC GOSUB,GOTO
PUBLIC IFS,INPUT
PUBLIC LET,LINE
PUBLIC ONGOTO,OPTION
PUBLIC PEEK,POKE
PUBLIC RANDOM,READ,REM,RESEQ,RESUME,RETURN,RUN
SUBTTL GENERAL STORAGE MANAGEMENT ROUTINES - FNDFOR, BLTU, GETSTK
;
; FIND A "FOR" ENTRY ON THE STACK WITH THE VARIABLE POINTER
; PASSED IN [D,E].
;
PUBLIC FNDFOR
FNDFOR: MOV BX,OFFSET 4+0 ;IGNORING EVERYONES "NEWSTT"
;AND THE RETURN ADDRESS OF THIS
ADD BX,SP ;SUBROUTINE, SET [H,L]=SP
LOOPER:
INC BX ;8086 USES TWO BYTE ENTRIES
MOV AL,BYTE PTR [BX] ;SEE WHAT TYPE OF THING IS ON THE STACK
INC BX
WHLSIZ=6
CMP AL,LOW OFFSET $WHILE
JNZ SHORT STKSRC
MOV CX,OFFSET WHLSIZ
ADD BX,CX
JMP SHORT LOOPER
STKSRC:
CMP AL,LOW OFFSET $FOR ;IS THIS STACK ENTRY A "FOR"?
JZ SHORT $+3
RET ;NO SO OK
MOV CL,BYTE PTR [BX]
INC BX ;DO EQUIVALENT OF PUSHM / XTHL
MOV CH,BYTE PTR [BX]
INC BX
PUSH BX ;PUT H ON
MOV BX,CX
OR DX,DX ;"NEXT" STATMENT WITHOUT AN ARGUMENT ?
;WE MATCH ON ANYTHING
XCHG BX,DX ;MAKE SURE WE RETURN [D,E]
JZ SHORT POPGOF ;POINTING TO THE VARIABLE
XCHG BX,DX
CMP BX,DX
FORSIZ=16
FORSIZ=17
FORSIZ=FORSIZ+2 ;For text pointer into NEXT.
;
; Note - 8086 versions force stack entries to be an even length
; so stack accesses won't cross word boundaries. This is done
; for speed. To accomplish this, an extra byte is pushed on
; top of the FOR token. This extra byte is NOT reflected in
; the value of FORSIZ but is taken care of by the code.
;
PUBLIC FORSZC
FORSZC=0+FORSIZ
POPGOF: MOV CX,OFFSET FORSZC-3 ;TO WIPE OUT A "FOR" ENTRY
;Note that the pointer has already
;been incremented three times.
POP BX
JNZ SHORT $+3
RET ;IF VARIABLE IN THIS ENTRY MATCHES
;RETURN WITH [H,L] POINTING THE BOTTOM
;OF THE ENTRY
ADD BX,CX
JMP SHORT LOOPER ;NOW POINTING TO THE START OF THE NEXT
;ENTRY. SEE IF ITS A "FOR" ENTRY
;AND IF THE VARIABLE MATCHES
SUBTTL ERROR HANDLING
;
; THIS ROUTINE IS CALLED TO RESET THE STACK IF BASIC IS
; EXTERNALLY STOPPED AND THEN RESTARTED.
;
PUBLIC READYR
READYR: MOV CX,OFFSET STPRDY ;ADDRESS GO TO, ALSO POP OFF GARBAGE STACK ENTRY.
JMP ERESET ;RESET STACK, GOTO READY.
PRGEND:
MOV BX,CURLIN ;GET CURRENT LINE #
MOV AL,BH ;SEE IF DIRECT
AND AL,BL ;AND TOGETHER
INC AL ;SET CC'S
JZ SHORT ENDCNJ ;IF DIRECT DONE, ALLOW FOR DEBUGGING PURPOSES
MOV AL,BYTE PTR ONEFLG ;SEE IF IN ON ERROR
OR AL,AL ;SET CC
MOV DL,LOW OFFSET ERRNR ;"NO RESUME" ERROR
JNZ SHORT ERROR ;YES, FORGOT RESUME
EXTRN ENDCON:NEAR
ENDCNJ: JMP ENDCON ;NO, LET IT END
DERMAK IFN ;"Illegal File Name"
DERMAK FNO ;"File Not Open"
DERMAK DNA ;"Device not available"
DERMAK FDR ;"Direct statement in file"
DERMAK RAD ;"Rename across disk"
DERMAK DFL ;"DISK FULL"
DERMAK IOE ;"DISK I/O ERROR"
DERMAK BFM ;"BAD FILE MODE"
DERMAK FNF ;"FILE NOT FOUND"
DERMAK BFN ;"BAD FILE NUMBER"
DERMAK IER ;"INTERNAL ERROR"
DERMAK RPE ;"READ PAST END"
DERMAK FAO ;"FILE ALREADY OPEN"
DERMAK NMF ;"BAD FILE NAME"
DERMAK BRN ;"BAD RECORD NUMBER"
DERMAK FOV ;"FIELD OVERFLOW"
DERMAK TMF ;"TOO MANY FILES"
DERMAK FAE ;"FILE ALREADY EXISTS"
ORG $-1
JMP SHORT ERROR
DATSNE: MOV BX,DATLIN ;GET DATA LINE
MOV CURLIN,BX ;MAKE IT CURRENT LINE
PUBLIC $SNERR
$SNERR:
PUBLIC SNERR
SNERR: MOV DL,LOW OFFSET ERRSN ;"SYNTAX ERROR"
DB 271O ; SKIP ;"LXI B," OVER THE NEXT 2
PUBLIC DV0ERR
DV0ERR: MOV DL,LOW OFFSET ERRDV0 ;DIVISION BY ZERO
DB 271O ; SKIP ;"LXI B," OVER THE NEXT 2
PUBLIC NFERR
NFERR: MOV DL,LOW OFFSET ERRNF ;"NEXT WITHOUT FOR" ERROR
DB 271O ; SKIP ;"LXI B," OVER THE NEXT TWO BYTES
PUBLIC DDERR
DDERR: MOV DL,LOW OFFSET ERRDD ;"REDIMENSIONED VARIABLE"
DB 271O ; SKIP ;"LXI B," OVER THE NEXT 2 BYTES
PUBLIC UFERR
UFERR: MOV DL,LOW OFFSET ERRUF ;"UNDEFINED FUNCTION" ERROR
DB 271O ; SKIP ;"LXI B," OVER THE NEXT TWO
REERR: MOV DL,LOW OFFSET ERRRE ;"RESUME WITHOUT ERROR"
DB 271O ; SKIP ;"LXI B," OVER THE NEXT TWO
PUBLIC $OVERR
$OVERR:
PUBLIC OVERR
OVERR: MOV DL,LOW OFFSET ERROV ;SET OVERFLOW ERROR CODE
DB 271O ; SKIP ;"LXI B," OVER NEXT TWO
PUBLIC MOERR
MOERR: MOV DL,LOW OFFSET ERRMO ;MISSING OPERAND ERROR
DB 271O ; SKIP ;"LXI B," OVER THE NEXT TWO
PUBLIC $TMERR
$TMERR:
PUBLIC TMERR
TMERR: MOV DL,LOW OFFSET ERRTM ;TYPE MISMATCH ERROR
PUBLIC ERROR
ERROR:
XOR AL,AL
MOV BYTE PTR NLONLY,AL ;Clear Don't close files flag
DSEG SEGMENT PUBLIC 'DATASG'
EXTRN INITFG:WORD
DSEG ENDS
EXTRN CMDERR:NEAR
MOV AL,BYTE PTR INITFG
OR AL,AL ;0 implies initialization is incomplete
JZ SHORT ??L000
JMP INITOK ;Initialization has completed
??L000:
JMP CMDERR ;Execute command line error routine
;which returns to the OS
INITOK:
HLPEDT=PC8A
MOV BX,CURLIN ;GET CURRENT LINE NUMBER
MOV ERRLIN,BX ;SAVE IT FOR ERL VARIABLE
XOR AL,AL ;CLEAR CHAIN FLAG IN CASE OF ERROR
MOV BYTE PTR MRGFLG,AL ;ALSO MERGE FLAG
MOV BYTE PTR CHNFLG,AL ;SO IT DOESNT TRY TO CHAIN
MOV AL,BH ;ONLY SET UP DOT IF IT ISNT DIRECT
AND AL,BL
INC AL
JZ SHORT ERRESM
MOV DOT,BX ;SAVE IT FOR EDIT OR LIST
ERRESM: MOV CX,OFFSET ERRMOR ;GET RETURN ADDRESS IN [B,C]
EXTRN STKERR:NEAR
PUBLIC ERESET
ERESET: MOV BX,SAVSTK ;GET A GOOD STACK BACK
JMP STKERR ;JUMP INTO STKINI
ERRMOR: POP CX ;POP OFF FNDFOR STOPPER
MOV AL,DL ;[A]=ERROR NUMBER
MOV CL,DL ;ALSO SAVE IT FOR LATER RESTORE
MOV BYTE PTR ERRFLG,AL ;SAVE IT SO WE KNOW WHETHER TO CALL "EDIT"
MOV BX,SAVTXT ;GET SAVED TEXT POINTER
MOV ERRTXT,BX ;SAVE FOR RESUME.
XCHG BX,DX ;SAVE SAVTXT PTR
MOV BX,ERRLIN ;GET ERROR LINE #
MOV AL,BH ;TEST IF DIRECT LINE
AND AL,BL ;SET CC'S
INC AL ;SETS ZERO IF DIRECT LINE (65535)
JZ SHORT NTMDCN ;IF DIRECT, DONT MODIFY OLDTXT & OLDLIN
MOV OLDLIN,BX ;SET OLDLIN=ERRLIN.
XCHG BX,DX ;GET BACK SAVTXT
MOV OLDTXT,BX ;SAVE IN OLDTXT.
NTMDCN: MOV BX,ONELIN ;SEE IF WE ARE TRAPPING ERRORS.
OR BX,BX ;BY CHECKING FOR LINE ZERO.
XCHG BX,DX ;PUT LINE TO GO TO IN [D,E]
MOV BX,OFFSET ONEFLG ;POINT TO ERROR FLAG
JZ SHORT NOTRAP ;SORRY, NO TRAPPING...
AND AL,BYTE PTR [BX] ;A IS NON-ZERO, SETZERO IF ONEFLG ZERO
JNZ SHORT NOTRAP ;IF FLAG ALREADY SET, FORCE ERROR
DEC BYTE PTR [BX] ;IF ALREADY IN ERROR ROUTINE, FORCE ERROR
XCHG BX,DX ;GET LINE POINTER IN [H,L]
JMP GONE4 ;GO DIRECTLY TO NEWSTT CODE
NOTRAP: XOR AL,AL ;A MUST BE ZERO FOR CONTRO
MOV BYTE PTR [BX],AL ;RESET ONEFLG
MOV DL,CL ;GET BACK ERROR CODE
MOV BYTE PTR CNTOFL,AL ;FORCE OUTPUT
CALL CRDONZ ;CRLF
MOV BX,OFFSET ERRTAB ;GET START OF ERROR TABLE
MOV AL,DL ;GET ERROR CODE
CMP AL,LOW OFFSET LSTERR ;IS IT PAST LAST ERROR?
JAE SHORT UPERR ;YES, TOO BIG TO PRINT
CMP AL,LOW OFFSET DSKERR+1 ;DISK ERROR?
JAE SHORT NTDER2 ;YES
CMP AL,LOW OFFSET NONDSK+1 ;IS IT BETWEEN LAST NORMAL & FIRST DISK?
JB SHORT NTDERR ;YES, OK TO PRINT IT
UPERR: MOV AL,LOW OFFSET ERRUE1 ;PRINT "UNPRINTABLE ERROR"
NTDER2: SUB AL,LOW OFFSET DSKER1 ;FIX OFFSET INTO TABLE OF MESSAGES
MOV DL,AL ;SAVE BACK ERROR CODE
NTDERR:
;ON "SYNTAX ERROR"S
LEPSKP: INS86 56 ;CODE SEGMENT FETCH
MOV AL,BYTE PTR [BX]
INC BX ;POINT TO NEXT CHARACTER
OR AL,AL
JZ SHORT ??L001
JMP LEPSKP
??L001:
DEC BX
INC BX ;SKIP OVER THIS ERROR MESSAGE
DEC DL ;DECREMENT ERROR COUNT
JNZ SHORT LEPSKP ;SKIP SOME MORE
PUSH BX ;SAVE TEXT POINTER
MOV BX,ERRLIN ;GET ERROR LINE NUMBER
POP SI ;XTHL
XCHG SI,BX
PUSH SI ;GET BACK ERROR TEXT POINTER
PUBLIC ERRFIN
ERRFIN:
INS86 56 ;CODE SEGMENT OVERRIDE FOR 8086 BASIC
MOV AL,BYTE PTR [BX] ;GET 1ST CHAR OF ERROR
CMP AL,LOW "?" ;PADDED ERROR?
JNZ SHORT ERRFN1 ;NO,PRINT
POP BX ;GET LINE # OFF STACK
MOV BX,OFFSET ERRTAB
JMP SHORT UPERR ;MAKE UNPRINTABLE ERROR
ERRFN1:
CALL STROUT ;PRINT MESSAGE
POP BX ;RESTORE LINE NUMBER
MOV DX,65534 ;IS INIT EXECUTING?
CMP BX,DX
JNZ SHORT ??L002
CALL CRDO ;DO CRLF
??L002:
EXTRN SYSTME:NEAR
JNZ SHORT ??L003
JMP SYSTME ;SYSTEM error exit
??L003:
MOV AL,BH ;SEE IF IN DIRECT MODE
AND AL,BL
INC AL ;ZERO SAYS DIRECT MODE
JZ SHORT ??L004
CALL INPRT ;PRINT LINE NUMBER IN [H,L]
??L004:
MOV AL,LOW 377O
CALL OUTDO ;FLAG AS NOT USER INPUT
; NOW FALL INTO MAIN INTERPRETER LOOP
PAGE
SUBTTL STPRDY, READY, MAIN, CHEAD
;
; FOR "LIST" COMMAND STOPPING
; AND FOR RETURNING FROM A FAILED "CVER"
; AND TO CORRECT A DIRECT GOSUB WHICH DOES INPUT
;
DB 260O ; SKIP ;SKIP THE NEXT BYTE WITH "MVI A,0"
PUBLIC STPRDY
STPRDY: POP CX
PUBLIC READY
READY:
CALL FINLPT ;PRINT ANY LEFT OVERS
XOR AL,AL
MOV BYTE PTR CNTOFL,AL ;FORCE OUTPUT
CALL PRGFIN ;FINISH OUTPUT OF A FILE
CALL CRDONZ ;IF NOT ALREADY AT LEFT, SEND CRLF
MOV BX,OFFSET REDDY ;"OK" CRLF
REPINI:
CALL STROUT
MOV AL,BYTE PTR ERRFLG ;SEE IF IT WAS A "SYNTAX ERROR"
SUB AL,LOW OFFSET ERRSN
EXTRN ERREDT:NEAR
JNZ SHORT ??L005
CALL ERREDT ;"EDIT" THE BAD LINE
??L005:
PUBLIC MAIN
MAIN:
MOV BX,65535
MOV CURLIN,BX ;SETUP CURLIN FOR DIRECT MODE
MOV BX,OFFSET ENDPRG
MOV SAVTXT,BX ;SAVTXT POINTS AT FAKE END OF PROGRAM
MOV AL,BYTE PTR AUTFLG ;IN AN AUTO COMMAND?
OR AL,AL ;SET CC'S
JZ SHORT NTAUTO ;NO, REUGLAR MODE
MOV BX,AUTLIN ;GET CURRENT AUTO LINE
PUSH BX ;SAVE AWAY FOR LATER USE
CALL LINPRT ;PRINT THE LINE #
POP DX ;GET IT BACK
PUSH DX ;SAVE BACK AGAIN
CALL FNDLIN ;SEE IF IT EXISTS
MOV AL,LOW "*" ;CHAR TO PRINT IF LINE ALREADY EXISTS
JB SHORT AUTELN ;DOESNT EXIST
MOV AL,LOW " " ;PRINT SPACE
AUTELN: CALL OUTDO ;PRINT CHAR
MOV BYTE PTR AUTFLG,AL ;SAVE WHETHER HAVE ASTERISK OR NOT
NTAUTO:
EXTRN PINLIN:NEAR
CALL PINLIN ;GET PROGRAM LINE INPUT
JAE SHORT NTSTOP
XOR AL,AL
MOV BYTE PTR AUTFLG,AL ;IN CASE OF AUTO, CLEAR IT
JMP MAIN
NTSTOP:
CALL CHRGTR ;GET THE FIRST
INC AL ;SEE IF 0 SAVING THE CARRY FLAG
DEC AL
JZ SHORT MAIN ;IF SO, A BLANK LINE WAS INPUT
PUSHF ;SAVE STATUS INDICATOR FOR 1ST CHARACTER
CALL LINGET ;READ IN A LINE #
JAE SHORT MAINBX ;ANOTHER DIGIT AFTER LINE#?
CALL ISFLIO ;AND COMING FROM TERMINAL?
JNZ SHORT ??L006
JMP SNERR ;IF SO, BAD INPUT
??L006:
MAINBX:
CALL BAKSP ;BACK UP THE POINTER
MOV AL,BYTE PTR AUTFLG
OR AL,AL
JZ SHORT NTASTC ;NOT AUTO, DON'T CHECK FOR ASTERISK
CMP AL,LOW "*"
JNZ SHORT NTASTC ;AUTO DID NOT APPEND ASTERISK
CMP AL,BYTE PTR [BX] ;DO WE HAVE ASTERISK?
JNZ SHORT ??L007
CALL INXHRT ;YES, SKIP IT
??L007:
NTASTC:
OR DX,DX
JNZ SHORT ??L008
JMP EDENT ;BRIF no line number, don't skip space
??L008:
MOV AL,BYTE PTR [BX] ;GET THE CHAR
CMP AL,LOW " " ;CHARACTER A SPACE?
JNZ SHORT ??L009
CALL INXHRT ;THEN EAT PAST IT
??L009:
;ONE SPACE ALWAYS PRINTED AFTER LINE #
PUBLIC EDENT
EDENT:
PUSH DX ;SAVE LINE #
CALL CRUNCH ;CRUNCH THE LINE DOWN
POP DX ;RESTORE LINE #
POPF ;WAS THERE A LINE #?
MOV SAVTXT,BX ;FOR RESUMING A DIRECT STMT
EXTRN DIRDO:NEAR
JNAE SHORT ??L010
JMP DIRDO ;MAKE SURE WE'RE NOT READING A FILE
??L010:
PUSH DX
PUSH CX ;SAVE LINE # AND CHARACTER COUNT
CALL PROCHK ;DONT ALLOW ANY FUNNY BUSINESS WITH EXISTING PGM
CALL CHRGTR ;REMEMBER IF THIS LINE IS
OR AL,AL ;SET THE ZERO FLAG ON ZERO
;LINES THAT START WITH ":" SHOULD NOT BE
;IGNORED
PUSHF ;BLANK SO WE DON'T INSERT IT
MOV DOT,DX ;SAVE THIS LINE # IN DOT
MOV BX,AUTINC ;GET INCREMENT
ADD BX,DX ;ADD INCREMENT TO THIS LINE
JB SHORT AUTRES ;CHECK FOR PATHETIC CASE
PUSH DX ;SAVE LINE NUMBER #
MOV DX,65530D ;CHECK FOR LINE # TOO BIG
CMP BX,DX
POP DX ;GET BACK LINE #
JAE SHORT AUTRES ;IF TOO BIG, QUIT
MOV AUTLIN,BX ;SAVE IN NEXT LINE
JMP SHORT AUTGOD
AUTRES: XOR AL,AL
MOV BYTE PTR AUTFLG,AL ;LINE NUMBER TOO BIG, QUIT
AUTGOD:
CALL FNDLIN ;GET A POINTER TO THE LINE
JB SHORT LEXIST ;LINE EXISTS, DELETE IT
POPF ;GET FLAG SAYS WHETHER LINE BLANK
PUSHF ;SAVE BACK
JZ SHORT ??L011
JMP LXISTS ;Line exists - OK
??L011:
MOV AL,BYTE PTR AUTFLG
OR AL,AL ;If not AUTO mode then error.
JNZ SHORT ??L012
JMP USERR ;TRYING TO DELETE NON-EXISTANT LINE, ERROR
??L012:
PUSH CX ;Prepare to leave
JMP FINI
LXISTS: OR AL,AL ;CLEAR FLAG THAT SAYS LINE EXISTS
JMP SHORT INONLY
LEXIST: ;SAVE THE POINTER
POPF ;Don't erase line on null input when
PUSHF ; in AUTO mode.
JZ SHORT ??L013
JMP ERAINS ;Line not null - go erase/insert
??L013:
MOV AL,BYTE PTR AUTFLG
OR AL,AL ;AUTO mode?
JNZ SHORT ??L014
JMP ERAINS ;No - go erase/insert
??L014:
PUSH CX ;Prepare to exit
JMP FINI
ERAINS: STC
INONLY:
PUSH CX
PUSHF ;SAVE REGISTERS
PUSH BX ;SAVE [H,L]
CALL DEPTR ;GET RID OF PTRS IN PGM
POP BX ;GET BACK POINTER TO NEXT LINE
POPF ;GET BACK PSW
POP CX ;RESTORE POINTER TO THIS LINE
PUSH CX ;SAVE BACK AGAIN
JNB SHORT ??L015
CALL DEL
??L015:
NODEL: POP DX ;POP POINTER AT PLACE TO INSERT
POPF ;SEE IF THIS LINE HAD
;ANYTHING ON IT
PUSH DX ;SAVE PLACE TO START FIXING LINKS
JZ SHORT FINI ;IF NOT DON'T INSERT
POP DX ;GET RID OF START OF LINK FIX
MOV AL,BYTE PTR CHNFLG ;ONLY CHANGET FRETOP IF NOT CHAINING
OR AL,AL
JNZ SHORT LEVFRE ;LEAVE FRETOP ALONE
MOV BX,MEMSIZ ;DELETE ALL STRINGS
MOV FRETOP,BX ;SO REASON DOESNT USE THEM
LEVFRE:
MOV BX,0 ;Clear error trap before inserting
MOV ONELIN,BX ; to prevent OM error from being trapped
MOV BX,VARTAB ;CURRENT END
POP SI ;XTHL
XCHG SI,BX
PUSH SI ;[H,L]=CHARACTER COUNT. VARTAB
;ONTO THE STACK
POP CX ;[B,C]=OLD VARTAB
PUSH BX ;Save count of chars to move
ADD BX,CX
PUSH BX ;SAVE NEW VARTAB
CALL BLTU
POP BX ;POP OFF VARTAB
MOV VARTAB,BX ;UPDATE VARTAB
XCHG BX,DX
MOV BYTE PTR [BX],BH ;FOOL CHEAD WITH NON-ZERO LINK
POP CX ;Restore count of chars to move
POP DX ;GET LINE # OFF STACK
PUSH BX ;SAVE START OF PLACE TO FIX LINKS
INC BX ;SO IT DOESN'T THINK
;THIS LINK IS THE
;END OF THE PROGRAM
INC BX
MOV [BX],DX
INC BX
INC BX ;PUT DOWN LINE #
MOV DX,OFFSET KBUF ;MOVE LINE FRM KBUF TO PROGRAM AREA
DEC CX ;FIX UP COUNT OF CHARS TO MOVE
DEC CX ;(DONT INCLUDE LINE # & LINK)
DEC CX ;
DEC CX
MLOOPR: MOV SI,DX
MOV AL,[SI] ;NOW TRANSFERING LINE
;IN FROM BUF
MOV BYTE PTR [BX],AL
INC BX
INC DX
DEC CX ;DECREMENT CHAR COUNT BY 1
MOV AL,CL ;TEST FOR COUNT EXHAUSTED
OR AL,CH ;BY SEEING IF [B,C]=0
JNZ SHORT MLOOPR
PUBLIC FINI
FINI:
EDTXIT: POP DX ;GET START OF LINK FIXING AREA
CALL CHEAD ;FIX LINKS
CALL RUNC ;DO CLEAR & SET UP STACK
JMP MAIN ;GO TO MAIN CODE
PUBLIC LINKER
LINKER:
MOV BX,TXTTAB
XCHG BX,DX
;
; CHEAD GOES THROUGH PROGRAM STORAGE AND FIXES
; UP ALL THE LINKS. THE END OF EACH
; LINE IS FOUND BY SEARCHING FOR THE ZERO AT THE END.
; THE DOUBLE ZERO LINK IS USED TO DETECT THE END OF THE PROGRAM
;
PUBLIC CHEAD
CHEAD: MOV BH,DH ;[H,L]=[D,E]
MOV BL,DL
MOV AL,BYTE PTR [BX] ;SEE IF END OF CHAIN
INC BX ;BUMP POINTER
OR AL,BYTE PTR [BX] ;2ND BYTE
JNZ SHORT $+3
RET
INC BX ;FIX H TO START OF TEXT
INC BX
CZLOOP: INC BX ;BUMP POINTER
MOV AL,BYTE PTR [BX] ;GET BYTE
CZLOO2: OR AL,AL ;SET CC'S
JZ SHORT CZLIN ;END OF LINE, DONE.
CMP AL,LOW OFFSET DBLCON+1 ;EMBEDDED CONSTANT?
JAE SHORT CZLOOP ;NO, GET NEXT
CMP AL,LOW 11 ;IS IT LINEFEED OR BELOW?
JB SHORT CZLOOP ;THEN SKIP PAST
CALL CHRGT2 ;GET CONSTANT
CALL CHRGTR ;GET OVER IT
JMP SHORT CZLOO2 ;GO BACK FOR MORE
CZLIN: INC BX ;MAKE [H,L] POINT AFTER TEXT
XCHG BX,DX ;SWITCH TEMP
MOV [BX],DX ;STORE FIXUP
JMP SHORT CHEAD ;KEEP CHAINING TIL DONE
PAGE
SUBTTL SCNLIN, FNDLIN - SCAN LINE RANGE AND FIND LINE # IN PROGRAM
;
; SCNLIN SCANS A LINE RANGE OF
; THE FORM #-# OR # OR #- OR -# OR BLANK
; AND THEN FINDS THE FIRST LINE IN THE RANGE
;
PUBLIC SCNLIN
SCNLIN: MOV DX,0 ;ASSUME START LIST AT ZERO
PUSH DX ;SAVE INITIAL ASSUMPTION
JZ SHORT ALLLST ;IF FINISHED, LIST IT ALL
CMP AL,LOW 44D ;COMMA IS OK
JZ SHORT ALLLST ;Maybe list all to Gen Device.
POP DX ;WE ARE GOING TO GRAB A #
CALL LINSPC ;GET A LINE #. IF NONE, RETURNS ZERO
PUSH DX ;SAVE FIRST
JZ SHORT SNGLIN ;IF ONLY # THEN DONE.
CMP AL,LOW 44D ;COMMA IS OK
JZ SHORT SNGLIN ;Maybe only one to Gen Device.
CALL SYNCHR
DB OFFSET MINUTK ;MUST BE A DASH.
JZ SHORT ALLLST ;Brif EOS.
CMP AL,LOW 44D ; else must be comma or number.
ALLLST: MOV DX,65530 ;ASSUME MAX END OF RANGE
JZ SHORT ??L016
CALL LINSPC ;GET THE END OF RANGE
??L016:
JZ SHORT SNGLIN ;Brif EOS.
CMP AL,LOW 44D
JZ SHORT ??L017
JMP SNERR ;MUST BE TERMINATOR
??L017:
SNGLIN:
MOV TEMP,BX ; save Text pointer.
XCHG BX,DX ;[H,L] = FINAL
POP DX ;GET INITIAL IN [D,E]
FNDLN1: POP SI ;XTHL
XCHG SI,BX
PUSH SI ;PUT MAX ON STACK, RETURN ADDR TO [H,L]
PUSH BX ;SAVE RETURN ADDRESS BACK
;
; FNDLIN SEARCHES THE PROGRAM TEXT FOR THE LINE
; WHOSE LINE # IS PASSED IN [D,E]. [D,E] IS PRESERVED.
; THERE ARE THREE POSSIBLE RETURNS:
;
; 1) ZERO FLAG SET. CARRY NOT SET. LINE NOT FOUND.
; NO LINE IN PROGRAM GREATER THAN ONE SOUGHT.
; [B,C] POINTS TO TWO ZERO BYTES AT END OF PROGRAM.
; [H,L]=[B,C]
;
; 2) ZERO, CARRY SET.
; [B,C] POINTS TO THE LINK FIELD IN THE LINE
; WHICH IS THE LINE SEARCHED FOR.
; [H,L] POINTS TO THE LINK FIELD IN THE NEXT LINE.
;
; 3) NON-ZERO, CARRY NOT SET.
; LINE NOT FOUND, [B,C] POINTS TO LINE IN PROGRAM
; GREATER THAN ONE SEARCHED FOR.
; [H,L] POINTS TO THE LINK FIELD IN THE NEXT LINE.
;
PUBLIC FNDLIN
FNDLIN:
MOV BX,TXTTAB ;GET POINTER TO START OF TEXT
LOOP:
MOV CX,BX ;IF EXITING BECAUSE OF END OF PROGRAM,
;SET [B,C] TO POINT TO DOUBLE ZEROES.
MOV AL,BYTE PTR [BX] ;GET WORD POINTER TO
INC BX ;BUMP POINTER
OR AL,BYTE PTR [BX] ;GET 2ND BYTE
LAHF
DEC BX ;GO BACK
SAHF
JNZ SHORT $+3
RET ;IF ZERO THEN DONE
INC BX ;SKIP PAST AND GET THE LINE #
INC BX
MOV BX,[BX] ;INTO [H,L] FOR COMPARISON WITH
;THE LINE # BEING SEARCHED FOR
;WHICH IS IN [D,E]
CMP BX,DX ;SEE IF IT MATCHES OR IF WE'VE GONE TOO FAR
MOV BX,CX ;MAKE [H,L] POINT TO THE START OF THE
;LINE BEYOND THIS ONE, BY PICKING
MOV BX,[BX] ;UP THE LINK THAT [B,C] POINTS AT
CMC ;TURN CARRY ON
JNZ SHORT $+3
RET ;EQUAL RETURN
CMC ;MAKE CARRY ZERO
JNAE SHORT $+3
RET ;NO MATCH RETURN (GREATER)
JMP SHORT LOOP ;KEEP LOOPING
PAGE
SUBTTL PRE FAST CRUNCH - COMPACTIFICATION
PAGE
PAGE
SUBTTL FAST CRUNCH - COMPACTIFICATION
;
; ALL "RESERVED" WORDS ARE TRANSLATED INTO SINGLE
; ONE OR TWO (IF TWO, FIRST IS ALWAYS 377 OCTAL)
; BYTES WITH THE MSB ON. THIS SAVES SPACE AND TIME
; BY ALLOWING FOR TABLE DISPATCH DURING EXECUTION.
; THEREFORE ALL STATEMENTS APPEAR TOGETHER IN THE
; RESERVED WORD LIST IN THE SAME
; ORDER THEY APPEAR IN IN STMDSP.
;
; NUMERIC CONSTANTS ARE ALSO CONVERTED TO THEIR INTERNAL
; BINARY REPRESENTATION TO IMPROVE EXECUTION SPEED
; LINE NUMBERS ARE ALSO PRECEEDED BY A SPECIAL TOKEN
; SO THAT LINE NUMBERS CAN BE CONVERTED TO POINTERS AT EXECUTION
; TIME.
;
PUBLIC CRUNCH
CRUNCH:
XOR AL,AL ;SAY EXPECTING FLOATING NUMBERS
MOV BYTE PTR DONUM,AL ;SET FLAG ACORDINGLY
MOV BYTE PTR DORES,AL ;ALLOW CRUNCHING
MOV CX,OFFSET KBFLEN-3 ;GET LENGTH OF KRUNCH BUFFER
;MINUS THREE BECAUSE OF ZEROS AT END
MOV DX,OFFSET KBUF ;SETUP DESTINATION POINTER
KLOOP: MOV AL,BYTE PTR [BX] ;GET CHARACTER FROM BUF
OR AL,AL ;END OF LINE?
JNZ SHORT NCRDON ;NO, CONTINUE
CRDONE:
MOV BX,OFFSET KBFLEN+2 ;GET OFFSET
MOV AL,BL ;GET COUNT TO SUBTRACT FROM
SUB AL,CL ;SUBTRACT
MOV CL,AL
MOV AL,BH
SBB AL,CH
MOV CH,AL ;BC:=# OF CHARS CRUNCHED
MOV BX,OFFSET KBUF-1 ;GET POINTER TO CHAR BEFORE KBUF
;AS "GONE" DOES A CHRGET
XOR AL,AL ;GET A ZERO
MOV DI,DX
STOSB ;NEED THREE 0'S ON THE END
INC DX ;ONE FOR END-OF-LINE
MOV DI,DX
STOSB ;AND 2 FOR A ZERO LINK
INC DX ;SINCE IF THIS IS A DIRECT STATEMENT
MOV DI,DX
STOSB ;ITS END MUST LOOK LIKE THE END OF A PROGRAM
RET ;END OF CRUNCHING
;
PAGE
NCRDON: CMP AL,LOW 34 ;QUOTE SIGN?
JNZ SHORT ??L018
JMP STRNG ;YES, GO TO SPECIAL STRING HANDLING
??L018:
CMP AL,LOW " " ;SPACE?
JZ SHORT STUFFH ;JUST STUFF AWAY
MOV AL,BYTE PTR DORES ;IN DATA STATEMENT AND NO CRUNCH?
OR AL,AL
MOV AL,BYTE PTR [BX] ;GET THE CHARACTER AGAIN
JZ SHORT NTDATA ;IF NO CRUNCHING JUST STORE
;THE CHARACTER
STUFFH: INC BX ;ENTRY TO BUMP [H,L]
PUSH AX ;SAVE CHAR AS KRNSAV CLOBBERS
CALL KRNSAV ;SAVE CHAR IN KRUNCH BUFFER
POP AX ;RESTORE CHAR
SUB AL,LOW ":" ;SEE IF IT IS A COLON
JZ SHORT COLIS ;IF SO ALLOW CRUNCHING AGAIN
CMP AL,LOW OFFSET $DATCO
JNZ SHORT NODATT ;SEE IF IT IS A DATA TOKEN
MOV AL,LOW 1 ;SET LINE NUMBER ALLOWED FLAG
;KLUDGE AS HAS TO BE NON-ZERO.