-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic11m.asm
More file actions
6906 lines (6026 loc) · 288 KB
/
basic11m.asm
File metadata and controls
6906 lines (6026 loc) · 288 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
;*******************************************************************************
;* Program : BASIC11M.ASM
;* Programmer: Tony Papadimitriou, MS <tonyp@acm.org>
;* Purpose : Modified BASIC interpreter for the 68HC11
;* Language : Motorola/Freescale/NXP 68HC11 Assembly Language (aspisys.com/ASM11)
;* Note(s) : Based on BASIC interpreter for the 68HC11 by Gordon Doughman
;*******************************************************************************
#ListOff
#Uses mcu.inc
#ListOn
#Macro
;*******************************************************************************
; Macros
;*******************************************************************************
Title macro
mset 0,~@~
#Message Processing \@~text~\@
endm
;*******************************************************************************
title DEFINES
;-------------------------------------------------------------------------------
; HC11EVB defines
;-------------------------------------------------------------------------------
SWPRE equ 2 ; SOFTWARE PRESCALER VALUE.
;SBASBEG equ 0
SBASEND equ 2
SVARBEG equ 4
SVAREND equ 6
;SHILINE equ 8
AUTOSTF equ 10
SSTART equ 11
;-------------------------------------------------------------------------------
; HC11 (device-dependant) defines
;-------------------------------------------------------------------------------
EEPBASAD equ $B600 ; EEPROM base address
MAXEESUB equ 255 ; maximum EEP subscript
;-------------------------------------------------------------------------------
; I/O Register Offsets From The Base Address
;-------------------------------------------------------------------------------
PPROG def $3B ; EEPROM programing control register
ADCTL def $30 ; A-TO-D control/status register
ADR1 def $31 ; A/D result register 1
ADR2 def $32 ; A/D result register 2
ADR3 def $33 ; A/D result register 3
ADR4 def $34 ; A/D result register 4
PORTAIO def $00 ; PORTA I/O register
PORTBIO def $04 ; PORTB I/O register
PORTCIO def $03 ; PORTC I/O register
PORTDIO def $08 ; PORTD I/O register
PORTEIO def $0A ; PORTE I/O register
TCNT def $0E ; TIMER/COUNTER register
TOC1REG def $16 ; TIMER Output Compare 1 register
TFLAG1 def $23 ; TIMER Flag #1 register
TMSK1 def $22 ; TIMER Mask #1 register
TMSK2 def $24 ; TIMER Mask #2 register
OPTION def $39 ; OPTION select register
BAUD def $2B ; SCI baud rate select register
SCCR1 def $2C ; SCI control register #1
SCCR2 def $2D ; SCI control register #2
SCSR def $2E ; SCI status register
SCDR def $2F ; SCI transmit/recieve data register
PACNT def $27 ; PACC count register
PACTL def $26 ; PACC control register
TFLG2 def $25 ; TIMER Flag #2 register
INIT def $3D ; INIT (Base address of RAM & I/O Regs) Register
;-------------------------------------------------------------------------------
; Miscellaneous defines
;-------------------------------------------------------------------------------
EOL def 13 ; end of line marker
CR def 13 ; same as EOL
LF def 10 ; linefeed character
BS def 8 ; backspace character
SPC equ 32 ; space character
MIDEOL equ ':' ; mid EOL character
COMMA equ ',' ; comma
SEMI equ ';' ; semicolin
NUM equ 1 ; getvar return flag
STRING equ 2 ; getvar return flag
NULL def 0 ; null value
CNTRLC equ 3 ; control-c (break character)
IBUFLEN equ 80 ; input buffer max length
TBUFLEN equ 128 ; token buffer max length
SWSTKSize equ 592
OPSLEN equ 30 ; operator stack length
NUMSLEN equ 60 ; operand stack length
FORSLEN equ 80 ; FOR..NEXT stack length
WHSLEN equ 16 ; WHILE..ENDWH stack length
GOSLEN equ 16 ; GOSUB stack length
;-------------------------------------------------------------------------------
; Error codes
;-------------------------------------------------------------------------------
#temp 1
LINRANG next :temp ; line number range error
SYTXERR next :temp ; syntax error
IVEXPERR next :temp ; invalid expression error
UPARNERR next :temp ; unbalanced parentheses error
DTMISERR next :temp ; data type mismatch error
OPRTRERR next :temp ; illegal operator error
ILVARERR next :temp ; illegal variable error
ILTOKERR next :temp ; illegal token error
OMEMERR next :temp ; out of memory error
INTOVERR next :temp ; integer overflow error
IVHEXERR next :temp ; invalid hex digit error
HEXOVERR next :temp ; hex number overflow
MISQUERR next :temp ; missing quote error
MPARNERR next :temp ; missing open or closing parenthisis
IONSYERR next :temp ; "ON" syntax error
MTHENERR next :temp ; missing "THEN" in "IF" statement
MTOERR next :temp ; missing "TO" in "FOR" statement
LINENERR next :temp ; line number error
IDTYERR next :temp ; illegal data type error
EXPCXERR next :temp ; expression too complex (xlator token buff ovf.)
MCOMAERR next :temp ; missing comma
MCMSMERR next :temp ; missing comma or semicolin
MSTKOERR next :temp ; math stack overflow error
UNDIMERR next :temp ; undimentioned array error
SUBORERR next :temp ; subscript out of range error
ZDIVERR next :temp ; divide by zero error
LNFERR next :temp ; line not found error
GOSOVERR next :temp ; too many nested GOSUB's
RWOGERR next :temp ; RETURN w/o GOSUB error
WHSOVERR next :temp ; too many active WHILE's
ENDWHERR next :temp ; ENDWH statement w/o WHILE
ONARGERR next :temp ; ON argument is negative, zero, or too large
NOSUBERR next :temp ; non-subscriptable variable found in DIM statem.
REDIMERR next :temp ; variable has already been DIMensioned
FORNXERR next :temp ; too many active FOR -- NEXT loops active
MFRNXERR next :temp ; mismatched FOR -- NEXT statements.
CNTCNERR next :temp ; can't continue
ODRDERR next :temp ; out of data in read or restore statement
NEGSUBER next :temp ; negative subscripts not allowed
EESUBERR next :temp ; EEP() subscript negative or > 200
PRFUNERR next :temp ; function only allowed in print statement
TABARGER next :temp ; argument <0 or >255 in TAB() function
CHRARGER next :temp ; argument <0 or >255 in CHR$() function
OVDV0ERR next :temp ; overflow or /0 error in FDIV() function
INVCHERR next :temp ; invalid channel number in ADC() function
PRTASERR next :temp ; tried to assign a value <0 or >255 to PORT(X)
ILPRTERR next :temp ; illegal port error
ILLIOERR next :temp ; illegal I/O vector number <0 or >7
UNINIERR next :temp ; uninitalized I/O vector
HEX2AERR next :temp ; argument <0 or >255 in HEX2 function
NOTALERR next :temp ; statement not allowed in direct mode
NOTINTER next :temp ; an RETI statement executed when not in interrupt
PACCARGE next :temp ; tried to assign a value of <0 or >255 to PACC
INTMODER next :temp ; interrupt or count mode error in ONPACC
EETOSMAL next :temp ; program storage EEPROM is Too Small
;-------------------------------------------------------------------------------
; Mathematical operator tokens
;-------------------------------------------------------------------------------
#temp $10
OPARNTOK next :temp ; '('
CPARNTOK next :temp ; ')'
#temp $20
ANDTOK next :temp ; 'AND'
ORTOK next :temp ; 'OR'
EORTOK next :temp ; 'EOR'
#temp $30
LTTOK next :temp ; '<'
GTTOK next :temp ; '>
LTEQTOK next :temp ; '<='
GTEQTOK next :temp ; '>='
EQTOK next :temp ; '='
NOTEQTOK next :temp ; '<>'
#temp $40
PLUSTOK next :temp ; '+'
MINUSTOK next :temp ; '-'
SPLUSTOK next :temp ; '+'
#temp $50
MULTTOK next :temp ; '*'
DIVTOK next :temp ; '/'
MODTOK next :temp ; '%'
#temp $60
PWRTOK next :temp ; '^'
#temp $70
INDIRTOK next :temp ; '@'
NOTTOK next :temp ; 'NOT'
NEGTOK next :temp ; '-' (unary minus)
;-------------------------------------------------------------------------------
; Keyword tokens
;-------------------------------------------------------------------------------
#temp $01
LETTOK next :temp ; LET
IMLETTOK next :temp ; implied LET
PRINTTOK next :temp ; PRINT
FORTOK next :temp ; FOR
NEXTTOK next :temp ; NEXT
TRONTOK next :temp ; TRON
TROFFTOK next :temp ; TROFF
POKETOK next :temp ; POKE
DIMTOK next :temp ; DIM
REMTOK next :temp ; REM
PACCTOK next :temp ; PACC
DATATOK next :temp ; DATA
READTOK next :temp ; READ
RESTRTOK next :temp ; RESTORE
GOSUBTOK next :temp ; GOSUB
#temp $12
GOTOTOK next :temp ; GOTO
ONTOK next :temp ; ON
RETNTOK next :temp ; RETURN
IFTOK next :temp ; IF
INPUTTOK next :temp ; INPUT
STOPTOK next :temp ; STOP
ENDTOK next :temp ; END
WHILETOK next :temp ; WHILE
ENDWHTOK next :temp ; ENDWH
EEPTOK next :temp ; EEP
PORTATOK next :temp ; PORTA
PORTBTOK next :temp ; PORTB
PORTCTOK next :temp ; PORTC
PORTDTOK next :temp ; PORTD
#temp $23
INBYTTOK next :temp ; INBYTE
TIMETOK next :temp ; TIME
ONTIMTOK next :temp ; ONTIME
ONIRQTOK next :temp ; ONIRQ
RETITOK next :temp ; RETI
ONPACTOK next :temp ; ONPACC
SLEEPTOK next :temp ; SLEEP
RTIMETOK next :temp ; RTIME
#temp $36
FUNCTFLG next :temp ; function flag byte
TOTOK next :temp ; TO
THENTOK next :temp ; THEN
ELSETOK next :temp ; ELSE
STEPTOK next :temp ; STEP
;-------------------------------------------------------------------------------
; Function tokens
;-------------------------------------------------------------------------------
#temp 1
FDIVTOK next :temp ; FDIV
CHRTOK next :temp ; CHR$
ADCTOK next :temp ; ADC
ABSTOK next :temp ; ABS
RNDTOK next :temp ; RND
SGNTOK next :temp ; SGN
TABTOK next :temp ; TAB
CALLTOK next :temp ; CALL
PEEKTOK next :temp ; PEEK
FEEPTOK next :temp ; EEP
HEXTOK next :temp ; HEX
FPRTATOK next :temp ; PORTA
FPRTBTOK next :temp ; PORTB
FPRTCTOK next :temp ; PORTC
FPRTDTOK next :temp ; PORTD
FPRTETOK next :temp ; PORTE
FTIMETOK next :temp ; TIME
HEX2TOK next :temp ; HEX2
FPACCTOK next :temp ; PACC
;-------------------------------------------------------------------------------
; Numerical/variable tokens
;-------------------------------------------------------------------------------
FVARTOK equ $81 ; floating point variable address
SVARTOK equ $82 ; string variable address
IVARTOK equ $84 ; integer variable address
FAVARTOK equ $91 ; floating point array
SAVARTOK equ $92 ; string array
IAVARTOK equ $94 ; integer array
FCONTOK equ $A1 ; floating point constant
SCONTOK equ $A2 ; string constant
LCONTOK equ $A8 ; line # constant
ICONTOK equ $A4 ; integer constant
ISIZ equ 2 ; number of bytes in integer variable
SSIZ equ 3 ; number of bytes in string variable
FSIZ equ 5 ; number of bytes in f.p. variable
ASIZ equ 2 ; number of bytes for array variable in dictionary
;-------------------------------------------------------------------------------
; Misc. tokens
;-------------------------------------------------------------------------------
#temp $78
PNUMTOK next :temp ; '#'
EQUALTOK next :temp ; '='
MEOLTOK next :temp ; :
SEMITOK next :temp ; ;
COMMATOK next :temp ; ,
EOLTOK next :temp ; end of line token
SSCNTOK next :temp ; single space token
MSCNTOK next :temp ; multiple space count token
JMPOP equ $7E ; OP-CODE FOR "JMP" (USED TO INITIALIZE INTERRUPT TABLE)
;*******************************************************************************
; Variables
;*******************************************************************************
#RAM
; char
IBUFPTR rmb 2 ; input buffer pointer
TBUFPTR rmb 2 ; token buffer pointer
; the next 5 variables must remain grouped togeather
BASBEG rmb 2 ; start of basic program area
BASEND rmb 2 ; end of basic program
VARBEGIN rmb 2 ; start of variable storage area
VAREND rmb 2 ; end of variable storage area
HILINE rmb 2 ; highest line number in program buffer
BASMEND rmb 2 ; physical end of basic program memory
VARMEND rmb 2 ; physical end of variable memory
; int
FIRSTLIN rmb 2 ; first line to list
LASTLIN rmb 2 ; last line to list
INTPTR rmb 2 ; integer pointer
; short
ERRCODE rmb 1 ; error code status byte
IMMID rmb 1 ; immidiate mode flag
BREAKCNT equ * ; also use for break check count
COUNT equ * ; count used in ESAVE & ELOAD routines
IFWHFLAG rmb 1 ; translating IF flag
TRFLAG rmb 1 ; trace mode flag
CONTFLAG rmb 1 ; continue flag
RUNFLAG rmb 1 ; indicates we are in the run mode
PRINTPOS rmb 1 ; current print position
NUMSTACK rmb 2 ; numeric operand stack pointer
OPSTACK rmb 2 ; operator stack pointer
FORSTACK rmb 2 ; FOR stack pointer
WHSTACK rmb 2 ; WHILE stack pointer
GOSTACK rmb 2 ; GOSUB stack pointer
CURLINE rmb 2 ; line # that we are currently interpreting
ADRNXLIN rmb 2 ; address of the next line
STRASTG rmb 2 ; dynamic string/array pool pointer
FENCE rmb 2 ; varend fence in case of an error in xlation
IPSAVE rmb 2 ; interpretive pointer save for "BREAK"
DATAPTR rmb 2 ; pointer to data for read statement
RANDOM rmb 2 ; random number/seed
DEVNUM rmb 1 ; I/O device number
TIMEREG rmb 2 ; TIME register
TIMECMP rmb 2 ; TIME compare register
TIMEPRE rmb 1 ; software prescaler for TIME
ONTIMLIN rmb 2 ; ONTIME line number to goto
ONIRQLIN rmb 2 ; ONIRQ line number to goto
ONPACLIN rmb 2 ; ONPACC line number to goto
XONCH rmb 1 ; XON character for printer
XOFFCH rmb 1 ; XOFF character for printer
SCURLINE rmb 2 ; used to save CURLINE during int. processing
SADRNXLN rmb 2 ; used to save ADRNXLIN during int. processing
INBUFFS rmb 2 ; pointer to the start of the input buffer
TKNBUFS rmb 2 ; pointer to the start of the token buffer
EOPSTK rmb 2 ; end of operator stack
STOPS rmb 2 ; start of operator stack
ENUMSTK rmb 2 ; end of operand stack
STNUMS rmb 2 ; start of operand stack
EFORSTK rmb 2 ; end of FOR - NEXT stack
STFORSTK rmb 2 ; start of FOR - NEXT stack
EWHSTK rmb 2 ; end of WHILE stack
STWHSTK rmb 2 ; start of WHILE stack
EGOSTK rmb 2 ; end of GOSUB stack
STGOSTK rmb 2 ; start of GOSUB stack
DNAME rmb 3 ; Place to put the variable name when doing a dump command
SUBMAX rmb 2 ;
SUBCNT rmb 2 ;
TOKPTR rmb 2 ; token pointer (used for list command)
VarSize rmb 2 ; used by the line editor. size of the variable table
; org $009E
CONSTAT rmb 3 ; GET CONSOLE STATUS FOR BREAK ROUTINE.
INCONNE rmb 3 ; GET BYTE DIRECTLY FROM CONSOLE FOR BREAK ROUTINE.
; org $00A4
INTABLE rmb 8*2 ; RESERVE SPACE FOR 8 DIFFERENT INPUT ROUTINES.
OUTABLE rmb 8*2 ; RESERVE SPACE FOR 8 DIFFERENT OUTPUT ROUTINES.
; org $00C4 ; START OF RAM INTERRUPT VECTORS.
RAMVECTS equ *
SCISS rmb 3 ; SCI SERIAL SYSTEM.
SPITC rmb 3 ; SPI TRANSFER COMPLETE.
PACCIE rmb 3 ; PULSE ACCUMULATOR INPUT EDGE.
PACCOVF rmb 3 ; PULSE ACCUMULATOR OVERFLOW.
TIMEROVF rmb 3 ; TIMER OVERFLOW.
vTOC5 rmb 3 ; TIMER OUTPUT COMPARE 5.
vTOC4 rmb 3 ; TIMER OUTPUT COMPARE 4.
vTOC3 rmb 3 ; TIMER OUTPUT COMPARE 3.
vTOC2 rmb 3 ; TIMER OUTPUT COMPARE 2.
vTOC1 rmb 3 ; TIMER OUTPUT COMPARE 1.
vTIC3 rmb 3 ; TIMER INPUT CAPTURE 3.
vTIC2 rmb 3 ; TIMER INPUT CAPTURE 2.
vTIC1 rmb 3 ; TIMER INPUT CAPTURE 1.
REALTIMI rmb 3 ; REAL TIME INTERRUPT.
IRQI rmb 3 ; IRQ INTERRUPT.
XIRQ rmb 3 ; XIRQ INTERRUPT.
SWII rmb 3 ; SOFTWARE INTERRUPT.
ILLOP rmb 3 ; ILLEGAL OPCODE TRAP.
COP rmb 3 ; WATCH DOG TIMER FAIL.
CMF rmb 3 ; CLOCK MONITOR FAIL.
#ROM
title BASICLB1
;*******************************************************************************
; MC68HC11 BASIC INTERPRETER
; WRITTEN BY:
; GORDON DOUGHMAN
; COPYRIGHT 1985-1990 BY
; GORDON DOUGHMAN
;*******************************************************************************
; include "1.DEFINES.C"
;
; *main()
; *{
; initvars(); initalize all variables & pointers
; outheader(); send startup message to console
; outrdy(); output ready message
;*******************************************************************************
MAIN proc
jsr INITVARS ; INITALIZE ALL INTERNAL VARIABLES.
ldx EEStart
lda AUTOSTF,x ; get the auto start flag.
cmpa #$55
bne PrintHeader@@
cli ; ALLOW ALL INTERRUPTS TO BE SERVICED.
jsr CRUN
PrintHeader@@ bsr OUTHEADR ; PRINT HEADER.
TopLoop ldd RAMStart ; RESET STACK VALUE.
addd RAMSize
xgdx
txs
cli ; (J.I.C.)
clrd
std TIMECMP ; DON'T ALLOW "ONTIME" INTERRUPTS TO OCCUR.
std ONIRQLIN ; DON'T ALLOW "ONIRQ" INTERRUPTS TO OCCUR.
std ONPACLIN ; DON'T ALLOW "PACC" INTERRUPTS TO OCCUR.
jsr OUTRDY ; PRINT READY MESSAGE.
; while(1) do forever
; {
; outprmpt(); output prompt
; getline(); getline from console
; skipspcs(); ignore leading spaces in input buffer
; if(chckcmds()) continue; check for commands
; parse(); translate/execute line
; if(errcode) rpterr(); if an error occured somewhere, report it.
; errcode=0; clear error status
; }
; *}
MainLoop clr IMMID ; CLEAR THE IMMIDIATE MODE FLAG.
clr ERRCODE ; CLEAR THE ERROR CODE BYTE.
clr RUNFLAG ; CLEAR THE RUN MODE FLAG.
jsr OUTPRMPT ; SEND PROMPT TO CONSOLE.
jsr GETLINE ; GO GET LINE FROM OPERATOR.
bsr SKIPSPCS ; SKIP ANY LEADING SPACES.
jsr CHCKCMDS ; GO CHECK FOR ANY COMMANDS.
cpd #0 ; WERE THERE ANY?
bne TopLoop ; YES. CONTINUE.
ldx VAREND ; SAVE CURRENT END OF VARIABLE AREA IN CASE LINE
stx FENCE ; HAS AN ERROR IN IT. (SO NO SPURIOUS VARIABLES
; ARE ALLOCATED)
jsr PARSE
tst IMMID ; DID WE EXECUTE IN IMMIDATE MODE?
bne TopLoop ; YES. PRINT READY MESSAGE.
bra MainLoop ; NO. JUST PRINT PROMPT.
TopCont ldx FENCE ; GET THE VAREND FENCE.
clr ,x ; MARK "OLD" END OF VARIABLE AREA IN CASE ANY
; VARIABLES WERE ALLOCATED.
stx VAREND ; RESTORE THE POINTER.
bra TopLoop ; CONTINUE AFTER ERROR.
;*******************************************************************************
; ***** skipspcs() *****
;
; *skipspcs()
; *{
; while(*ibufptr==SPC) ++ibufptr;
; return;
; *}
SKIPSPCS proc
Loop@@ jsr GETCHR
cmpa #SPC
bne Done@@
jsr INCIBP
bra Loop@@
Done@@ rts
;*******************************************************************************
; ***** outheader *****
;
; *outheader()
; *{
; pl("BASIC11 v1.1");
; nl();
; nl();
; pl("Written by Gordon Doughman");
; nl();
; *}
OUTHEADR proc
ldx #Msg@@
jmp PL
Msg@@ fcb CR,LF,CR,LF
fcc "BASIC11 v1.55",CR,LF
fcc "Copyright 1985-1990 by",CR,LF
fcs "Gordon Doughman",CR,LF
;*******************************************************************************
; ***** outrdy() *****
;
; *outrdy()
; *{
; nl();
; pl("READY");
; return;
; *}
OUTRDY proc
ldx #Msg@@
bra PL
Msg@@ fcs CR,LF,"READY",CR,LF
;*******************************************************************************
; ***** getline() *****
; *getline()
; *{
; short chrcnt;
; char c;
; chrcnt=IBUFLEN;
; ibufptr=inbuff;
GETLINE proc
ldb #IBUFLEN-1
ldx INBUFFS
; while((c=inbyte())!=EOL && (chrcnt>0))
; {
Loop@@ jsr INBYTE
cmpa #EOL
beq Done@@
tstb
beq Done@@
; if(c==BS)
; {
; if(ibufptr!=inbuff)
; {
; ibufptr-=1; point to previous buffer location
; outbyte(SPC); erase character on screen
; outbyte(BS); back cursor up
; chrcnt+=1;
; }
; else
; continue;
; }
cmpa #BS
bne Break?@@
cmpb #IBUFLEN-1
beq Done@@
dex
lda #SPC
jsr OUTBYTE
lda #BS
jsr OUTBYTE
incb
; if(c < SPC) continue; ignore all other control characters
Break?@@ cmpa #CNTRLC ; IS IT A "BREAK"?
bne Char@@ ; NO. GO PROCESS THE CHARACTER.
inc CONTFLAG ; DONT ALLOW A "CONT".
jmp CHCKBRK2 ; GO DO A BREAK.
Char@@ cmpa #SPC
blo Loop@@
; *ibufptr=c; save character in input buffer
; ibufptr+=1; point to next location
; chrcnt-=1;
; }
sta ,x
inx
decb
bne Loop@@
; *ibufptr=EOL; put EOL in input buffer
; ibufptr=inbuff; initalize the input buffer pointer
; return;
; *}
Done@@ lda #EOL
sta ,x
ldx INBUFFS
stx IBUFPTR
rts
;*******************************************************************************
ToUpper proc
cmpa #'a' ; is the character less than a lower case 'a'?
blo Done@@
cmpa #'z'
bhi Done@@
anda #$df
Done@@ rts
;*******************************************************************************
; ***** outprmpt() *****
; *outprmpt()
; *{
; nl(); go to new line
; outbyte('#'); send prompt to console
; return;
; *}
OUTPRMPT proc
ldx #Msg@@
bra PL
Msg@@ fcs CR,LF,"#"
;*******************************************************************************
; ***** nl() *****
; nl() send CR/LF to console
; *{
; outbyte(CR);
; outbyte(LF);
; return;
; *}
NL2 proc
bsr NL
;===============================================================================
NL proc
ldx #Msg@@
bsr PL
clr PRINTPOS ; SET THE CURRENT PRINT POSITION TO 0.
rts
Msg@@ fcs $0A,$0D
;*******************************************************************************
; ***** pl() *****
;
; *pl(ptr) send line to console
; *char *ptr;
; *{
; int k; char c;
; k=0;
; while(c=ptr[k++]) outbyte(c);
; return;
; *}
PL proc
Loop@@ lda ,x
beq Done@@
jsr OUTBYTE
inx
bra Loop@@
Done@@ equ :AnRTS
;*******************************************************************************
; ***** parse() *****
; *parse()
; *{
; int num;
; tbufptr=tknbuf; initalize the token buffer pointer
PARSE proc
ldx TKNBUFS ; Get the start of the token buffer
stx TBUFPTR
; if(num=getlinum()) get line number if present
; {
; if(*ibufptr==EOL) was line # followed by CR?
; { yes.
; delline(num); go delete the line from the prog buffer
; return;
; }
; immid=0; flag as not immidiate
; putlinum(num); put line number in buffer
; }
; else immid=1; if no line # flag as immidiate*/
bsr GETLINUM
bcc Immediate@@
psha
jsr GETCHR
cmpa #EOL
pula
bne Lined@@
jsr DELLINE
ldx VAREND
inx
stx STRASTG
Exit@@ rts
Lined@@ clr IMMID
ImmLoop@@ bsr PUTLINUM
bra Done@@
Immediate@@ jsr GETCHR
cmpa #EOL
beq Exit@@
lda #1
sta IMMID
clrd
bra ImmLoop@@
; if(errcode) return; if line number error, return
; xlate(); if translation error, return
; if(errcode) return;
; if(immid) runline(); if immidiate mode run 1 line
; else storlin(); if not store pgm line
; return; go get next line
; *}
Done@@ jsr XLATE
tst IMMID
beq Store@@
jmp RUNLINE ; GO RUN THE LINE & RETURN.
Store@@ jsr STORLIN ; GO STORE LINE & RETURN.
ldx VAREND
inx
stx STRASTG
rts
;*******************************************************************************
; ***** getlinum *****
; *getlinum()
; *{
; int num;
; num=0;
GETLINUM proc
pshy
clra
psha:2
tsy
; if(numeric(*ibufptr)==0) return(0); if 1st char not numeric, rtn 0
ldx IBUFPTR
lda ,x
bsr NUMERIC
bcc Done@@
; while(numeric(*ibufptr)) while *ibufptr is numeric
; {
; num=num*10+(*ibufptr-'0'); get a digit
; ibufptr++; advance input buffer pointer
; if(num<=0) { errcode=LINRANG; return(0); }
; }
; return(num);
; *}
Loop@@ lda ,x
bsr NUMERIC
bcs Number@@
sec
ldd ,y
bne Done@@
lda #LINENERR
bra Error@@
Done@@ ins:2
puly
stx IBUFPTR
rts
Number@@ bsr ADDDIG
bpl Loop@@
lda #LINRANG
Error@@ jmp RPTERR
;*******************************************************************************
ADDDIG proc
ldd ,y
asld:2
addd ,y
asld
std ,y
ldb ,x
inx
subb #'0'
clra
addd ,y
std ,y
rts
;*******************************************************************************
; ***** putlinum *****
; *putlinum(lnum)
; *int lnum;
; *{
; putint(lnum); put line # in token buffer
; *tbufptr++=0; hold place for length of line
; return;
; *}
PUTLINUM proc
jsr PUTDTOK
clra
jmp PUTTOK
;*******************************************************************************
; ***** numeric() *****
; *numeric(c)
; *char c;
; *{
; c=c&127;
; return((c>='0')&(c<='9'));
; *}
NUMERIC proc
cmpa #'0'
blo No@@
cmpa #'9'
bhi No@@
sec
rts
No@@ clc
rts
;*******************************************************************************
; ***** alpha() *****
; *alpha(c)
; *char c;
; *{
; c=c&127;
; return((c>='A')&(c<='Z'));
; *}
ALPHA proc
cmpa #'A'
blo No@@
cmpa #'Z'
bls Yes@@
cmpa #'a'
blo No@@
cmpa #'z'
bhi No@@
Yes@@ sec
rts
No@@ clc
rts
;*******************************************************************************
; ***** alphanum *****
; *alphanum(c)
; *char c;
; *{ return ((alpha(c)) | (numeric(c))); }
ALPHANUM proc
bsr ALPHA
bcc NUMERIC
rts
;*******************************************************************************
;*****************************************
; xlate()
; translate the input buffer into tokenized
; form placing the results into tknbuf
;******************************************/
;
; *xlate()
; *{
; while(*ibufptr!=EOL)
; {
; ifwhflag=0; set IF flag to zero
; blanks(); skip all blanks
; if(match("DATA")) xdata();
; else if(match("LET")) xlet();
; else if(match("READ")) xread();
; else if(match("RESTORE")) xrestore();
; else if(match("GOSUB")) xgosub();
; else if(match("GOTO")) xgoto();
; else if(match("ON")) xon();
; else if(match("RETURN")) xreturn();
; else if(match("IF")) xif();
; else if(match("INPUT")) xinput();
; else if(match("PRINT")) xprint();
; else if(match("FOR")) xfor();
; else if(match("NEXT")) xnext();
; else if(match("STOP")) xstop();
; else if(match("ENDWH")) xendwh();
; else if(match("END")) xend();
; else if(match("REM")) xrem();
;*else if(match("SWAP")) xswap();*/
; else if(match("TRON")) xtron();
; else if(match("TROFF")) xtroff();
; else if(match("WHILE")) xwhile();
;*else if(match("ONIRQ")) xonirq();*/
; else ximplet(); if no keyword, assume implied LET
; if(errcode) return;
; blanks();
; if(*ibufptr==MIDEOL) { xmideol(); continue; }
; if(*ibufptr!=EOL) { errcode=SYTXERR; return; }
; }
; *tbufptr=EOLTOK; put token eol in token buffer
; tknbuf[2]=tbufptr-tknbuf+1; put line length into tokenized line
; return;
; *}
XLATE proc
jsr GETCHR ; GET NEXT CHAR.
cmpa #EOL ; AT THE END OF THE LINE?
beq Done@@ ; YES.
clr IFWHFLAG ; NOT XLATING "IF" OR "WHILE"
jsr BLANKS ; SKIP BLANKS.
ldx #KEYWORDS ; POINT TO KEYWORD TABLE.
Loop@@ jsr STREQ ; IS KEYWORD IS IN THE INPUT BUFFER?
bcs Go@@ ; YES GO PROCESS IT.
ToEnd@@ inx ; NO. POINT TO NEXT CHAR.
lda ,x ; AT THE END OF THIS KEYWORD?
bne ToEnd@@ ; NO.
ldb #4 ; NUMBER OF BYTES TO SKIP.
abx
tst ,x ; AT THE END OF THE TABLE?
bne Loop@@ ; NO. CHCK FOR NEXT KEYWORD.
lda #IMLETTOK ; ASSUME AN IMPLIED LET.
; jsr PUTTOK ; PUT TOKEN IN BUFFER.
ldx #XIMPLET ; GET ADDR OF XLATION ROUTINE.
; jsr ,x ; GO DO IT.
; bra SkipBlanks@@ ; GO FINISH UP.
bra SaveToken@@
Go@@ lda 1,x ; GET KEYWORD TOKEN.
ldx 2,x ; GET ADDR OF XLATION ROUTINE.
SaveToken@@ jsr PUTTOK ; PUT TOKEN IN BUFFER.
cmpa #DATATOK ; SPECIAL CASE, DONT SKIP BLANKS AFTER KEYWORD.
beq DoToken@@
cmpa #REMTOK ; SAME SPECIAL CASE AS FOR DATA.
beq DoToken@@
jsr BLANKS ; SKIP BLANKS BETWEEN KEYWORD & NEXT OBJECT.
DoToken@@ jsr ,x ; GO DO IT.
SkipBlanks@@ jsr BLANKS ; SKIP BLANKS.
jsr GETNXCHR ; GET NEXT CHAR.
cmpa #MIDEOL ; IS IT A MID EOL?
bne Eol?@@ ; NO. CHCK FOR EOL.
lda #MEOLTOK ; GET MID EOL TOKEN.
jsr PUTTOK ; PUT IT IN BUFFER.
bra XLATE ; CONTINUE.
Eol?@@ cmpa #EOL ; EOL?
beq Done@@ ; YES. FINISH UP.