-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic11.asm
More file actions
6982 lines (6166 loc) · 293 KB
/
basic11.asm
File metadata and controls
6982 lines (6166 loc) · 293 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 : BASIC11.ASM
;* Programmer: Gordon Doughman
;* Purpose : BASIC interpreter for the 68HC11
;* Language : Motorola/Freescale/NXP 68HC11 Assembly Language (aspisys.com/ASM11)
;* Note(s) : This version has no object code differences from the original
;* : [Bug(s) not removed unless assembled with BUGFIX conditional.]
;*******************************************************************************
; Adapted to ASM11 by Tony Papadimitriou <tonyp@acm.org> and did the following:
;
; 1. Combined all files into (this) one
; 2. Added macros to emulate all unknown directives of the original assembler
; 3. Reformatted using FASM.EXE utility (http://aspisys.com/fasm.exe)
; 4. Manually improved formatting further
; 5. Changed IF ELSE ENDIF FAIL to ASM11 syntax (#IF #ELSE #ENDIF #FATAL)
; 6. Corrected case for a few symbols, so it also compiles with case-sensitivity
; 7. Replaced some instruction sequences with ASM11 internal macros for clarity
; 8. Added CRC verification display message at the end of this file
; 9. Slowly converting to 100% ASM11 idiomatic syntax [WORK-IN-PROGRESS]
;10. Placed on GitHub https://github.com/tonypdmtr/BASIC11/blob/master/basic11.asm
;===============================================================================
; I have had many, many requests from M68HC11 users over the
; years for the source code for BASIC11. I was very reluctant to
; release the source code for a number of reasons. First, because
; BASIC11 was nothing more than a skunk works project, most of
; the programming was done late at night and on weekends
; Consequently, no documentation exists on the internal operation
; of the interpreter and proper source code documentation
; practices were completely ignored. I would not approach a
; project like this in a similar manner today
;
; Second, because my job as a Field Applications Engineer is to
; provide support to a specific group of customers, I feared that
; releasing the source code would produce an avalanche of support
; questions that I would not have time to answer. In turn this
; might upset the customers whose questions I could not answer
;
; However, after much consideration, I have decided to release
; the BASIC11 source code to the public. Please understand that I
; cannot provide any help or assistance in adapting BASIC11 to
; another hardware environment or provide help in understanding
; the internal workings of BASIC11. You're on your own
;
; Regards,
; Gordon Doughman
;===============================================================================
#ifdef ?
#Hint +===================================================
#Hint | Available conditionals (for use with -Dx option)
#Hint +===================================================
#Hint | BUGFIX: Fix any known bugs
#Hint +===================================================
#Fatal Run ASM11 -Dx (where x is any of the above)
#endif
#Macro
#SpacesOff
#ExtraOn
#CaseOn
#OptRelOff
#OptRtsOff
Title macro
mset #
#Message Processing \@~1~\@
#Page
endm
;*******************************************************************************
; Macros
;*******************************************************************************
token macro ['String'],Token,Subroutine
mreq 1,2:['String'],Token,Subroutine
#if :nn = 3
fcs ~1~
mdel 1
#endif
#ifstr ~1~
fcs ~1~
#else
fcb ~1~
#endif
fdb ~2~
endm
;*******************************************************************************
VERSION equ 155
BUS_KHZ def 2000
;*******************************************************************************
HC11 def 1
; include 'defines.inc'
title DEFINES
#ifnz HC11 ;HC11EVB defines
ROMBEG equ $E000
ACIAST equ $9800
#else ;6809/FLEX development defines
ROMBEG equ $8000
ACIAST equ $E010
#endif
ROMSIZE equ $2000
ACIADT equ ACIAST+1
SWPRE equ 2 ;SOFTWARE PRESCALER VALUE
#temp
next :temp,2 ;SBASBEG
SBASEND next :temp,2
SVARBEG next :temp,2
SVAREND next :temp,2
next :temp,2 ;SHILINE
AUTOSTF next :temp
SSTART next :temp
;-------------------------------------------------------------------------------
; 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 equ $3B ;EEPROM programming control register
ADCTL equ $30 ;A-TO-D control/status register
ADR1 equ $31 ;A/D result register 1
ADR2 equ $32 ;A/D result register 2
ADR3 equ $33 ;A/D result register 3
ADR4 equ $34 ;A/D result register 4
PORTAIO equ $00 ;PORTA I/O register
PORTBIO equ $04 ;PORTB I/O register
PORTCIO equ $03 ;PORTC I/O register
PORTDIO equ $08 ;PORTD I/O register
PORTEIO equ $0A ;PORTE I/O register
TCNT equ $0E ;TIMER/COUNTER register
TOC1REG equ $16 ;TIMER Output Compare 1 register
TFLAG1 equ $23 ;TIMER Flag #1 register
TMSK1 equ $22 ;TIMER Mask #1 register
TMSK2 equ $24 ;TIMER Mask #2 register
OPTION equ $39 ;OPTION select register
BAUD equ $2B ;SCI baud rate select register
SCCR1 equ $2C ;SCI control register #1
SCCR2 equ $2D ;SCI control register #2
SCSR equ $2E ;SCI status register
SCDR equ $2F ;SCI transmit/recieve data register
PACNT equ $27 ;PACC count register
PACTL equ $26 ;PACC control register
TFLG2 equ $25 ;TIMER Flag #2 register
INIT equ $3D ;INIT (Base address of RAM & I/O Regs) Register
;-------------------------------------------------------------------------------
; Miscellaneous defines
;-------------------------------------------------------------------------------
EOL equ 13 ;end of line marker
CR equ 13 ;same as EOL
LF equ 10 ;linefeed character
BS equ 8 ;backspace character
NUM equ 1 ;getvar return flag
STRING equ 2 ;getvar return flag
NULL equ 0 ;null value
CTRL_C 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 semicolon
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 ;uninitialized 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
;-------------------------------------------------------------------------------
OPARNTOK equ $10 ;'('
CPARNTOK equ $11 ;')'
ANDTOK equ $20 ;'AND'
ORTOK equ $21 ;'OR'
EORTOK equ $22 ;'EOR'
LTTOK equ $30 ;'<'
GTTOK equ $31 ;'>
LTEQTOK equ $32 ;'<='
GTEQTOK equ $33 ;'>='
EQTOK equ $34 ;'='
NOTEQTOK equ $35 ;'<>'
PLUSTOK equ $40 ;'+'
MINUSTOK equ $41 ;'-'
SPLUSTOK equ $42 ;'+'
MULTTOK equ $50 ;'*'
DIVTOK equ $51 ;'/'
MODTOK equ $52 ;'%'
PWRTOK equ $60 ;'^'
INDIRTOK equ $70 ;'@'
NOTTOK equ $71 ;'NOT'
NEGTOK equ $72 ;'-' (uniary minus)
;-------------------------------------------------------------------------------
; Keyword tokens
;-------------------------------------------------------------------------------
LETTOK equ $01 ;LET
IMLETTOK equ $02 ;implied LET
PRINTTOK equ $03 ;PRINT
FORTOK equ $04 ;FOR
NEXTTOK equ $05 ;NEXT
TRONTOK equ $06 ;TRON
TROFFTOK equ $07 ;TROFF
POKETOK equ $08 ;POKE
DIMTOK equ $09 ;DIM
REMTOK equ $0A ;REM
PACCTOK equ $0B ;PACC
DATATOK equ $0C ;DATA
READTOK equ $0D ;READ
RESTRTOK equ $0E ;RESTORE
GOSUBTOK equ $0F ;GOSUB
GOTOTOK equ $12 ;GOTO
ONTOK equ $13 ;ON
RETNTOK equ $14 ;RETURN
IFTOK equ $15 ;IF
INPUTTOK equ $16 ;INPUT
STOPTOK equ $17 ;STOP
ENDTOK equ $18 ;END
WHILETOK equ $19 ;WHILE
ENDWHTOK equ $1A ;ENDWH
EEPTOK equ $1B ;EEP
PORTATOK equ $1C ;PORTA
PORTBTOK equ $1D ;PORTB
PORTCTOK equ $1E ;PORTC
PORTDTOK equ $1F ;PORTD
INBYTTOK equ $23 ;INBYTE
TIMETOK equ $24 ;TIME
ONTIMTOK equ $25 ;ONTIME
ONIRQTOK equ $26 ;ONIRQ
RETITOK equ $27 ;RETI
ONPACTOK equ $28 ;ONPACC
SLEEPTOK equ $29 ;SLEEP
RTIMETOK equ $2A ;RTIME
FUNCTFLG equ $36 ;function flag byte
TOTOK equ $37 ;TO
THENTOK equ $38 ;THEN
ELSETOK equ $39 ;ELSE
STEPTOK equ $3A ;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
;-------------------------------------------------------------------------------
; Miscellaneous tokens
;-------------------------------------------------------------------------------
MSCNTOK equ $7F ;multiple space count token
SSCNTOK equ $7E ;single space token
EOLTOK equ $7D ;end of line token
COMMATOK equ $7C ;,
SEMITOK equ $7B ;;
MEOLTOK equ $7A ;:
EQUALTOK equ $79 ;'='
PNUMTOK equ $78 ;'#'
JMPOP equ $7E ;OP-CODE FOR "JMP" (USED TO INITIALIZE INTERRUPT TABLE)
;*******************************************************************************
#RAM 0 ;define variables
;*******************************************************************************
;-------------------------------------- ;char
IBUFPTR rmb 2 ;input buffer pointer
TBUFPTR rmb 2 ;token buffer pointer
;--------------------------------------
;next 5 variables must remain grouped together
;--------------------------------------
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
IMMED rmb 1 ;immediate mode flag
BREAKCNT equ *,1 ;also use for break check count
COUNT equ *,1 ;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
IOBaseV rmb 2 ;Address vector for I/O Registers
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
;--------------------------------------
#temp $100-{20*3+38} ;20 3-byte vectors + IN/OUTABLE + CONSTAT + INCONNE
#if * > :temp
#Fatal Ran out of zero-page RAM
#else
#Message Zero-page RAM remaining: {:temp-:RAM} bytes
#endif
org :temp
;--------------------------------------
CONSTAT rmb 3 ;GET CONSOLE STATUS FOR BREAK ROUTINE
INCONNE rmb 3 ;GET BYTE DIRECTLY FROM CONSOLE FOR BREAK ROUTINE
INTABLE rmb 2*8 ;RESERVE SPACE FOR 8 DIFFERENT INPUT ROUTINES
OUTABLE rmb 2*8 ;RESERVE SPACE FOR 8 DIFFERENT OUTPUT ROUTINES
;-------------------------------------- ;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
TOC5 rmb 3 ;TIMER OUTPUT COMPARE 5
TOC4 rmb 3 ;TIMER OUTPUT COMPARE 4
TOC3 rmb 3 ;TIMER OUTPUT COMPARE 3
TOC2 rmb 3 ;TIMER OUTPUT COMPARE 2
TOC1 rmb 3 ;TIMER OUTPUT COMPARE 1
TIC3 rmb 3 ;TIMER INPUT CAPTURE 3
TIC2 rmb 3 ;TIMER INPUT CAPTURE 2
TIC1 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
; include 'basiclb1.mod'
;*******************************************************************************
#ROM ROMBEG
;*******************************************************************************
title BASICLB1
;*******************************************************************************
; *
; MC68HC11 BASIC INTERPRETER *
; *
; WRITTEN BY: *
; *
; GORDON DOUGHMAN *
; *
; COPYRIGHT 1985-1990 BY *
; *
; GORDON DOUGHMAN *
; *
;*******************************************************************************
;
;
;
; include "1.DEFINES.C"
;
; *main()
; *{
; initvars(); initialize all variables & pointers
; outheader(); send startup message to console
; outrdy(); output ready message
jmp POWERUP
;*******************************************************************************
MAIN proc
jsr INITVARS ;INITIALIZE ALL INTERNAL VARIABLES
ldx EEStart
lda AUTOSTF,x ;get the auto start flag
cmpa #$55
bne NormalStart@@
cli ;ALLOW ALL INTERRUPTS TO BE SERVICED
jsr CRUN
NormalStart@@ jsr OUTHEADR ;PRINT HEADER
MainLoop equ *
Loop@@ 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
; }
; *}
Prompt@@ clr IMMED ;CLEAR THE IMMEDIATE 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
jsr SKIPSPCS ;SKIP ANY LEADING SPACES
jsr CHCKCMDS ;GO CHECK FOR ANY COMMANDS
cpd #0 ;WERE THERE ANY?
bne Loop@@ ;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 IMMED ;DID WE EXECUTE IN IMMEDIATE MODE?
bne Loop@@ ;YES. PRINT READY MESSAGE
bra Prompt@@ ;NO. JUST PRINT PROMPT
MAIN3 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 Loop@@ ;CONTINUE AFTER ERROR
;*******************************************************************************
; ***** skipspcs() *****
;
; *skipspcs()
; *{
; while(*ibufptr==SPC) ++ibufptr;
; return;
; *}
SKIPSPCS proc
Loop@@ jsr GETCHR
cmpa #' '
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 v{VERSION(2)}',CR,LF
fcc 'Copyright 1985-1990 by',CR,LF
fcs 'Gordon Doughman',CR,LF
;*******************************************************************************
; ***** outrdy() *****
;
; *outrdy()
; *{
; nl();
; pl("READY");
; return;
; *}
OUTRDY proc
ldx #Msg@@
jmp 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 #' '
jsr OUTBYTE
lda #BS
jsr OUTBYTE
incb
; if(c < SPC) continue; ignore all other control characters
Break?@@ cmpa #CTRL_C ;IS IT A "BREAK"?
bne Go@@ ;NO. GO PROCESS THE CHARACTER
inc CONTFLAG ;DONT ALLOW A "CONT"
jmp ?DoBreak ;GO DO A BREAK
Go@@ cmpa #' '
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; initialize 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 #%11011111
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
; bra NL
;*******************************************************************************
NL proc
ldx #Msg@@
bsr PL
clr PRINTPOS ;SET THE CURRENT PRINT POSITION TO 0
rts
Msg@@ fcs LF,CR
;*******************************************************************************
; ***** 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@@ rts
;*******************************************************************************
; ***** parse() *****
; *parse()
; *{
; int num;
; tbufptr=tknbuf; initialize 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;
; }
; immed=0; flag as not immediate
; putlinum(num); put line number in buffer
; }
; else immed=1; if no line # flag as immediate*/
bsr GETLINUM
bcc Eol?@@
psha
jsr GETCHR
cmpa #EOL
pula
bne Go@@
jsr DELLINE
ldx VAREND
inx
stx STRASTG
Done@@ rts
Go@@ clr IMMED
Loop@@ bsr PUTLINUM
bra RunOrSave@@
Eol?@@ jsr GETCHR
cmpa #EOL
beq Done@@
lda #1
sta IMMED
ldd #0
bra Loop@@
; if(errcode) return; if line number error, return
; xlate(); if translation error, return
; if(errcode) return;
; if(immed) runline(); if immediate mode run 1 line
; else storlin(); if not store pgm line
; return; go get next line
; *}
RunOrSave@@ jsr XLATE
tst IMMED
beq Save@@
jmp RUNLINE ;GO RUN THE LINE & RETURN
Save@@ 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 NotNum@@
; 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 Cont@@
sec
ldd ,y
bne NotNum@@
lda #LINENERR
bra Fail@@
NotNum@@ ins:2
puly
stx IBUFPTR
rts
Cont@@ bsr ADDDIG
bpl Loop@@
lda #LINRANG
Fail@@ 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
Numeric@@ bra NUMERIC
;*******************************************************************************
; 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();