-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmdbasic.asm
More file actions
9442 lines (9332 loc) · 232 KB
/
Copy pathmdbasic.asm
File metadata and controls
9442 lines (9332 loc) · 232 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
; ***MDBASIC***
; by Mark D Bowren
; (c)1985-2026 Bowren Consulting, Inc. (www.bowren.com)
;
;zero-page registers
R6510 = $01 ;LORAM/HIRAM/CHAREN RAM/ROM selection and cassette control reg
CHARAC = $07 ;Search Character for Scanning BASIC Text Input
ENDCHR = $08 ;Search Character for Statement Termination or Quote
TRMPOS = $09 ;Column position of the Cursor before the Last TAB or SPC
VERCK = $0a ;flag for BASIC LOAD=0, VERIFY=1
COUNT = $0b ;general counter
VALTYP = $0d ;Type of Data (255=String, 0=Numeric)
INTFLG = $0e ;Type of Numeric Data (128=Integer, 0=Floating Point)
GARBFL = $0f ;Flag for LIST, Garbage Collection, and Program Tokenization
INPFLG = $11 ;Flag: Is Data Input to GET, READ or INPUT?
CHANNL = $13 ;Current I/O Channel (CMD Logical File) Number
LINNUM = $14 ;Integer Line Number Value
VARTAB = $2d ;Pointer to the Start of the BASIC Variable Storage Area
TXTTAB = $2b ;Pointer to the Start of BASIC Program Text
ARYTAB = $2f ;Pointer to the Start of the BASIC Array Storage Area
STREND = $31 ;Pointer to Start of Free BASIC RAM
FREETOP= $33 ;Pointer to the Bottom of the String Text Storage Area
FRESPC = $35 ;Temporary Pointer for Strings
CURLIN = $39 ;Current BASIC Line Number (lobyte)
OLDLIN = $3b ;Previous BASIC Line Number (lobyte)
OLDTXT = $3d ;Pointer to the Address of the Current BASIC Statement
DATPTR = $41 ;Pointer to the Address of the Current DATA Item
VARPNT = $47 ;Pointer to the Current BASIC Variable Value
FACSGN = $66 ;Sign of FAC1, 0=positive, otherwise negative
FACEXP = $61 ;Exponent of FAC1 (Base 2)
TXTPTR = $7a ;Pointer to the Address of the Current BASIC text char
STATUS = $90 ;Kernal I/O Status Word (ST)
XSAV = $97 ;Temporary .X Register Save Area
LDTND = $98 ;Number of Open I/O Files/Index to the End of File Tables
MSGFLG = $9d ;Msg Ctrl: 0=none, $40=Kernal, $80=CTRL, $C0=Kernal & CTRL
EAL = $ae ;vector to I/O end address of last loaded file
FNLEN = $b7 ;Length of Current Filename
LA = $b8 ;Current Logical File Number
SA = $b9 ;Current Secondary Address
FA = $ba ;Current Device Number
;0=keybrd,1=tape,2=rs232,3=screen,4-5=printer,8=11=disk
STAL = $c1 ;vector to I/O start address
LSTX = $c5 ;Matrix Coordinate of Last Key Pressed, 64=None Pressed
NDX = $c6 ;number of keys in keyboard buffer
RVS = $c7 ;Flag: Print Reverse Characters? 0=No
BLNSW = $cc ;Cursor Blink Disabled: 0=No, 1=Yes
SFDX = $cb ;Matrix Coordinate of Current Key Pressed
BLNCT = $cd ;Timer: Countdown to Blink Cursor
GDBLN = $ce ;ASCII value of char under csr (when blinking)
BLNON = $cf ;Flag: Was Last Cursor Blink on or off?
PNTR = $d3 ;Logical Cursor Column on Current Line
QTSW = $d4 ;Flag: Editor in Quote Mode? 0=No
LNMX = $d5 ;Maximum Length of Physical Screen Line (39 or 79)
TBLX = $d6 ;Current Cursor Physical Line Number
TMPASC = $d7 ;ASCII value of last character printed to screen
INSRT = $d8 ;Editor Current Insert Character Count
KEYTAB = $f5 ;vector to keyboard decode table
BASZPT = $ff ;BASIC Temporary Data for Floating Point to ASCII Conversion
;BASIC and Kernal work registers
BAD = $0100 ;Tape Input Error Log and string work area
BUF = $0200 ;BASIC Line Editor Input Buffer
KEYD = $0277 ;Keyboard Buffer (Queue)
COLOR = $0286 ;Current Foreground Color for Text
GDCOL = $0287 ;Color of Character under Cursor
HIBASE = $0288 ;Top Page of Screen Memory
RPTFLAG= $028a ;which keys repeat
;0=cursor, insert, delete and spacebar, 64=none, 128=all
SHFLAG = $028d ;SHIFT/CTRL/Logo Keypress flags
;bit0 SHIFT, bit1 Commodore Logo Key, bit2 Ctrl Key
PALNTSC= $02a6 ;PAL/NTSC TV Standard Flag: 0=NTSC, 1=PAL
;Kernal Tables for File Management
LAT = $0259 ;Table of Logical Active File Numbers
FAT = $0263 ;Table of Device Numbers for Each Logical File
SAT = $026d ;Table of Secondary Addresses for Each Logical File
;RS-232 Mock 6551 Registers
M51CTR = $0293 ;CTR
M51CDR = $0294 ;CDR
M51AJB = $0295 ;Non-Std Bit Timing lobyte, $0296 hibyte
RSSTAT = $0297 ;Status
BITNUM = $0298 ;Number of Bits Left to be Sent/Received
RIDBE = $029b ;Index to End of Receive Buffer
RIDBS = $029c ;Index to Start of Receive Buffer
RODBS = $029d ;Index to Start of Transmit Buffer
RODBE = $029e ;Index to End of Transmit Buffer
ENABL = $02a1 ;IRQ Statuses, 1=Transmittinging, 2=Receiving, 16=Waiting
;Memory-Mapped I/O Registers
SP0X = $d000 ;Sprite 0 Horizontal Position
SP0Y = $d001 ;Sprite 0 Vertical Position
MSIGX = $d010 ;Most Significant Bits of Sprites 0-7 Horizontal Position
SCROLY = $d011 ;Vertical Fine Scrolling and Control Register
;Bits 0-2 Fine scroll display vertically by X scan lines (0-7)
;Bit 3 Select a 24-row or 25-row text display (1=25 rows, 0=24 rows)
;Bit 4 Blank the entire screen to the same color as the background (0=blank)
;Bit 5 Enable bitmap graphics mode (1=enable)
;Bit 6 Enable extended background color mode (1=enable)
;Bit 7 High bit (Bit 8) of raster compare register at 53266 ($D012)
;
LPENX = $d013 ;Light Pen Horizontal Position (0-160) must by multiplied by 2
SPENA = $d015 ;Sprites 0-7 Enable Register (1=on, 0=off)
SCROLX = $d016 ;Horizontal Fine Scrolling and Multicolor Control Register
;Bits 0-2 Fine scroll display horizontally by X dot positions (0-7)
;Bit 3 Select a 38-column or 40-column text display (1=40 columns, 0=38 cols)
;Bit 4 Enable multicolor text or bitmap mode (1=on, 0=off)
;Bit 5 Video chip reset (0=normal operations, 1=video completely off)
;Bits 6-7 Unused
;
YXPAND = $d017 ;Sprites 0-7 Vertical Expansion Register (1=2x, 0=normal)
VMCSB = $d018 ;VIC-II Chip Memory Control Register
;Bit 0 Unused
;Bits 1-3 Text char dot-data base address in VIC-II 16K addressable memory.
; The default is %100 (4) = 4 * 1K = $1000 (4096) the address of Dot-Data.
; Uppercase chars are the first 2K. The alternate charset which contains both
; upper and lowercase chars are in the second 2K. To shift to the alternate
; charset, change this nybble to %110 (6) = 6 * 1K = $1800 (6144).
;
;Bits 4-7 Video matrix base address within VIC-II 16K addressable memory
; The default is %0001 (1) = 1 * 1K = $0400 (1024).
; Select which 1K area of memory will have screen codes for text on screen.
; The last 8 bytes of this 1K area are used as pointers to select the 64-byte
; block of memory for each sprite.
;
SPBGPR = $d01b ;Sprite to Foreground Display Priority Register
SPMC = $d01c ;Sprite Multicolor Registers
XXPAND = $d01d ;Sprite Horizontal Expansion Register
EXTCOL = $d020 ;Border Color Register
BGCOL0 = $d021 ;Bkgnd Color 0 for text, sprites and mc bitmap (default 6=blue)
BGCOL1 = $d022 ;Bkgnd Color 1 mc mode bits 6,7 bit-pair 01 (default 1=white)
;for screen codes 64-127
BGCOL2 = $d023 ;Bkgnd Color 2 mc mode bits 6,7 bit-pair 10 (default 2=red)
;for screen codes 128-191
BGCOL3 = $d024 ;Bkgnd Color 3 mc mode bits 6,7 bit-pair 11 (default 3=cyan)
;for screen codes 192-255
SPMC0 = $d025 ;Sprite Multicolor Register 0 (01 bit-pair)
SPMC1 = $d026 ;Sprite Multicolor Register 1 (11 bit-pair)
SP0COL = $d027 ;Sprite 0 Color Register (the default color value is 1, white)
;SID registers
FRELO1 = $d400 ;Voice 1 Frequency Control (low byte
FREHI1 = $d401 ;Voice 1 Frequency Control (high byte)
PWLO1 = $d402 ;Voice 1 Pulse Waveform Width (low byte)
PWHI1 = $d403 ;Voice 1 Pulse Waveform Width (high nybble)
VCREG1 = $d404 ;Voice 1 Control Register
ATDCY1 = $d405 ;Voice 1 Attack/Decay Register
SUREL1 = $d406 ;Voice 1 Sustain/Release Control Register
CUTLO = $d415 ;Filter Cutoff Frequency (3-bit lobyte)
CUTHI = $d416 ;Filter Cutoff Frequency (8-bit hibyte)
RESON = $d417 ;Filter Control (bits 0-3) and Resonance (bits 4-7) Register
SIGVOL = $d418 ;Volume (bits 0-3) and Filter Select (bits 4-6) Register
POTX = $d419 ;Read Game Paddle 1 or 3, POTX+1 ($d41a) = Paddle 2 or 4
;Complex Interface Adapter (CIA) #1 Registers ($DC00-$DC0F)
CIAPRA = $dc00 ;Data Port Register A
CIAPRB = $dc01 ;Data Port Register B
CIDDRA = $dc02 ;Data Direction Register A
CIACRA = $dc0e ;Control Register A
;Complex Interface Adapter (CIA) #2 Registers ($DD00-$DD0F)
CI2PRA = $dd00 ;Data Port Register A
;Bits 0-1 Select VIC-II 16K addressable memory bank (0-3)
; 00 Bank 3 ($C000-$FFFF) 16K RAM / Memory mapped I/O, char ROM, 4K Kernal
; 01 Bank 2 ($8000-$BFFF) 16K RAM / BASIC text, 8K BASIC interpreter ROM
; 10 Bank 1 ($4000-$7FFF) 16K RAM / BASIC text
; 11 Bank 0 ($0000-$3FFF) 16K RAM / system variables, screen RAM, BASIC text
;*See zero-page memory location $01 bits 0 & 1 for RAM/ROM switching
CI2PRB = $dd01 ;Data Port Register B
C2DDRA = $dd02 ;Data Direction Register for port A (CI2PRA)
;CIA #2 Timer A
TI2ALO = $dd04 ;Timer A (lo byte)
TI2AHI = $dd05 ;Timer A (hi byte)
;
;TOD #2 Registers
TO2TEN = $dd08 ;TOD clock tenths of a seconds in BCD format (lower nybble)
TO2SEC = $dd09 ;TOD clock seconds in BCD format
TO2MIN = $dd0a ;TOD clock minutes in BCD format
TO2HRS = $dd0b ;TOD clock hours in BCD format
CI2ICR = $dd0d ;Interrupt Control Register
CI2CRA = $dd0e ;Control Register A
CI2CRB = $dd0f ;Control Register B
;Bit7: Select TOD or Alarm Time
; 0=writing to TOD registers sets clock
; 1=writing to ROD registers sets alarm
;Vectors to various subroutines
KEYLOG = $028f ;Keyboard Table Setup Routine
IERROR = $0300 ;Print BASIC Error Message Routine
IMAIN = $0302 ;Main BASIC Program Loop
ICRNCH = $0304 ;Crunches ASCII to Tokens
IQPLOP = $0306 ;Lists BASIC Program Token as ASCII Text
IGONE = $0308 ;Executes the Next BASIC Program Token
IEVAL = $030a ;Evaluates a Single-Term Arithmetic Expression
SAREG = $030c ;Storage Area for processor registers A,X,Y,P for SYS
CINV = $0314 ;IRQ Interrupt Routine
CBINV = $0316 ;BRK Instruction Interrupt
ILOAD = $0330 ;Kernal LOAD Routine
ISAVE = $0332 ;Kernal SAVE Routine
ISTOP = $0328 ;Vector to Kernal STOP Routine
;MDBASIC IRQ management
MDBIRQ = $0313 ;MDBASIC IRQ Control Register
;bit0=play, bit1=playsprite, bit2=key, bit3=spritecolor16
TMPIRQ = $0334 ;2-byte temp storage for original IRQ vector
;misc vectors (2-bytes each)
TMPERR = $0336 ;original error handling vector
TMPERRP= $0338 ;TXTPTR of statement for ON ERR GOTO line#
TMPKEYP= $033a ;TXTPTR of statement for ON KEY GOSUB line#
;CBM command line functions
CHRGET = $0073 ;Get Next BASIC Text Character
CHRGOT = $0079 ;Get Current BASIC Text Character
;CBM BASIC subroutines
GETSTK = $a3fb ;check for space on stack
REASON = $a408 ;check for space in memory
READY = $a474 ;print READY
LINKPRG= $a533 ;relink lines of tokenized program text
INLIN = $a560 ;input a line to buffer from keyboard (max 88 chars)
FINDLN = $a613 ;search for line number using ptr TXTTAB
SCRTCH = $a642 ;perform NEW
CLEAR = $a65e ;perform CLR
RUNC = $a68e ;reset ptr of current text char to the beginning of prg text
LIST = $a69c ;perform LIST
FOR = $a742 ;perform FOR
NEWSTT = $a7ae ;setup next statement for execution
RESTORE= $a81d ;perform RESTORE
END = $a831 ;perform END
CONT = $a857 ;perform CONT
RUN = $a871 ;perform RUN
GOSUB = $a883 ;perform GOSUB
GOTO = $a8a0 ;perform GOTO
RETURN = $a8d2 ;perform RETURN
DATA = $a8f8 ;perform DATA
DATAN = $a906 ;search BASIC text for the end of the current statement
REM = $a93b ;perform REM
ONGOTO = $a94b ;perform ON
LINGET = $a96b ;convert an ASCII decimal number to a 2-byte binary line number
LET = $a9a5 ;perform LET
PRINTN = $aa80 ;perform PRINT#
CMD = $aa86 ;perform CMD
PRINT = $aaa0 ;perform PRINT
STROUT = $ab1e ;print msg from ptr in Y (hi byte) and A (lo byte) registers
GET = $ab7b ;perform GET
INPUTN = $aba5 ;perform INPUT#
INPUT = $abbf ;perform INPUT
READ = $ac06 ;perform READ
NEXT = $ad1e ;perform NEXT
FRMNUM = $ad8a ;evaluate numeric expression and check data type, result in FAC1
TESTNUM= $ad8d ;test last expression was numeric, if not, type mismatch error
FRMEVL = $ad9e ;evaluate expression
PIVAL = $aea8 ;PI as 5-byte float
PARCHK = $aef1 ;eval expr inside parentheses
CHKCLS = $aef7 ;check for and skip closing parentheses
CHKOPN = $aefa ;check for and skip opening parentheses
CHKCOM = $aefd ;check for and skip comma
ISVAR = $af28 ;get the value of a variable into FAC1
DIM = $b081 ;perform DIM
PTRGET = $b08b ;search for a variable & setup if not found
GIVAYF = $b391 ;convert 16-bit signed int to floating-point (a=hibyte y=lobyte)
ERRDIR = $b3a6 ;check if prg is running in direct mode/cause error
DEF = $b3b3 ;perform DEF
STRLIT = $b487 ;scan and setup ptrs to a str in memory ptr A lobyte, Y hibyte
GETSPA = $b4f4 ;alloc space in mem for string
FRESTR = $b6a3 ;discard a temporary string
GETBYTC= $b79b ;input an 8-bit unsigned int parameter with result in X reg
VAL = $b7ad ;perform VAL
GETADR = $b7f7 ;convert FAC1 to unsigned 16-bit integer in LINNUM
POKE = $b824 ;perform POKE
WAIT = $b82d ;perform WAIT
FADDH = $b849 ;add 0.5 to FAC1
FADD = $b867 ;add a number in memory to FAC1
DIV10 = $bafe ;divide FAC1 by 10
MUL10 = $bae2 ;multiply FAC1 by 10
FSUB = $b850 ;subtract FAC1 from a number in memory
FMULT = $ba28 ;copy mem pointed by Y(hi),A(lo) to FAC2 then FAC1=FAC1*FAC2
FDIV = $bb0F ;divide a number in memory by FAC1
MOVFM = $bba2 ;copy a 5-byte float from memory to FAC1, A=lobyte, Y=hibyte
MOV2F = $bbc7 ;copy a 5-byte float from FAC1 to memory, $57-$5B
MOVEF = $bc0f ;copy FAC1 to FAC2 without rounding
ROUND = $bc1b ;round FAC1 by adjusting the rounding byte
SIGN = $bc2b ;put the sign of FAC1 into accumulator
QINT = $bc9b ;convert FAC1 into a 4-byte (32-bit) signed integer within FAC1
INT = $bccc ;perform INT
FIN = $bcf3 ;convert ASCII string to a float in FAC1
FINLOG = $bd7e ;add signed integer to FAC1
INPRT = $bdc2 ;print IN followed by a line number
LINPRT = $bdcd ;print 16-bit unsigned int in A (hibyte), X (lobyte)
FOUT = $bddd ;convert contents of FAC1 to ASCII String
;CBM BASIC routines to raise a specific error
NOGOSUB= $a8e0 ;return without gosub
UNDEFST= $a8e3 ;undef'd statement error
TMERR = $ad99 ;type mismatch error
SNERR = $af08 ;syntax error
BSERR = $b245 ;bad subscript error
FCERR = $b248 ;illegal quanity error
OVERR = $b97e ;overflow error
LODERR = $e19c ;load error
;Commodore 64 Kernal functions
SYS = $e12a ;perform SYS
VERIFY = $e165 ;perform VERIFY
FPARAMS= $e1d4 ;get params for load, verify or save statements
INIT = $e3bf ;initialize BASIC
LP2 = $e5b4 ;get a character from the keyboard buffer
CLS = $e544 ;init screen line link table and clear the screen
;Commodore 64 Kernal API
CINT = $ff81 ;initialize screen editor and video chip
RAMTAS = $ff87 ;initialize RAM, tape buffer, screen
RESTOR = $ff8a ;restore default I/O vectors
IOINIT = $ff84 ;initialize CIA I/O devices ($fda3)
SETMSG = $ff90 ;set kernal msg ctrl flag
TKSA = $ff96 ;send secondary address after TALK
ACPTR = $ffa5 ;input byte from serial bus
TALK = $ffb4 ;command serial bus device to TALK
READST = $ffb7 ;read I/O status word
SETLFS = $ffba ;set logical file parameters
SETNAM = $ffbd ;set file name parameters
OPEN = $ffc0 ;open a logical file
CLOSE = $ffc3 ;close a logical file
CHKIN = $ffc6 ;define an input channel
CHKOUT = $ffc9 ;define an output channel
CLRCHN = $ffcc ;restore default devices
CHRIN = $ffcf ;input a character
CHROUT = $ffd2 ;output a char to the current output device
LOAD = $ffd5 ;load from a device
STOP = $ffe1 ;test the stop key
PLOT = $fff0 ;Read/Set Location of the Cursor
RESLST = $a09e ;$A09E-$A19D List of Keywords
TOKEN_NEXT = $82
TOKEN_DATA = $83
TOKEN_INPUTN = $84
TOKEN_INPUT = $85
TOKEN_DIM = $86
TOKEN_READ = $87
TOKEN_GOTO = $89
TOKEN_RUN = $8a
TOKEN_IF = $8b
TOKEN_RESTORE = $8c
TOKEN_GOSUB = $8d
TOKEN_RETURN = $8e
TOKEN_STOP = $90
TOKEN_ON = $91
TOKEN_WAIT = $92
TOKEN_OPEN = $9f
TOKEN_CLOSE = $a0
TOKEN_PRINT = $99
TOKEN_LIST = $9b
TOKEN_CLR = $9c
TOKEN_SYS = $9e
TOKEN_GET = $a1
TOKEN_NEW = $a2
TOKEN_TO = $a4
TOKEN_THEN = $a7
TOKEN_AND = $af
TOKEN_EQUAL = $b2
TOKEN_EXP = $bd
TOKEN_VAL = $c5
FIRST_CMD_TOK = $cb ;first MDBASIC token
TOKEN_OFF = $cb ;OFF keyword token
TOKEN_ELSE = $cc
TOKEN_VARS = $cf
TOKEN_FILL = $d1
TOKEN_DELETE = $d6
TOKEN_FILES = $d7
TOKEN_COLOR = $d8
TOKEN_SPRITE = $da
TOKEN_TRACE = $df
TOKEN_TEXT = $e6
TOKEN_SCREEN = $e7
TOKEN_RESUME = $e8
TOKEN_VOICE = $eb
FIRST_FUN_TOK = $f2 ;first MDBASIC function
TOKEN_ERR = $f2
TOKEN_KEY = $f3
TOKEN_TIME = $f4
TOKEN_PI = $ff ;PI symbol token
*=$8000 ;"MDBASIC RAM Memory Block"
;cartridge identifier
.word resvec,runstp ;new reset and runstop vectors
.text "CBM80"
;
mesge
.text "mdbasic 26.07.04"
.byte 13,0
;
;Text for New Commands
;string values of command w/ last chr having bit 7 = on
newcmd
;keywords
.shift "off" ;OFF keyword token $CB
.shift "else"
;keywords for statements and commands
.shift "merge"
.shift "dump"
.shift "vars"
.shift "circle"
.shift "fill"
.shift "scroll"
.shift "swap"
.shift "cursor"
.shift "disk"
.shift "delete"
.shift "files"
.shift "color"
.shift "move"
.shift "sprite"
.shift "sprcol"
.shift "find"
.shift "serial"
.shift "design"
.shift "trace"
.shift "mapcol"
.shift "plot"
.shift "line"
.shift "paint"
.shift "draw"
.shift "renum"
.shift "text"
.shift "screen"
.shift "resume"
.shift "envelope"
.shift "wave"
.shift "voice"
.shift "pulse"
.shift "vol"
.shift "filter"
.shift "play"
.shift "auto"
.shift "old"
;keywords that are statements and functions
.shift "err"
keystr .shift "key"
.shift "time"
;keywords that are only functions
.shift "round"
.shift "trim"
.shift "mod"
.shift "ptr"
.shift "inf"
.shift "pen"
.shift "joy"
.shift "pot"
.shift "hex$"
.shift "instr"
.byte 0 ;needed terminator
;
;Command Dispatch Table
cmdtab
;CBM BASIC
.rta END ;$80
.rta FOR ;$81
.rta NEXT ;$82
.rta DATA ;$83
.rta INPUTN ;$84 INPUT#
.rta INPUT ;$85
.rta DIM ;$86
.rta READ ;$87
.rta LET ;$88
.rta GOTO ;$89
.rta newrun ;$8a RUN augmented
.rta if ;$8b IF augmented
.rta restor ;$8c RESTORE augmented
.rta GOSUB ;$8d
.rta return ;$8e RETURN augmented
.rta REM ;$8f
.rta stop ;$90 STOP augmented
.rta on ;$91 ON augmented
.rta wait ;$92 WAIT augmented
.rta $e168 ;$93 LOAD
.rta bsave ;$94 SAVE augmented
.rta VERIFY ;$95
.rta DEF ;$96
.rta poke ;$97 POKE augmented
.rta PRINTN ;$98 PRINT#
.rta PRINT ;$99
.rta CONT ;$9a
.rta LIST ;$9b
.rta clr ;$9c CLR augmented
.rta CMD ;$9d
.rta sys ;$9e SYS augmented
.rta $e1be ;$9f OPEN
.rta close ;$a0 CLOSE augmented
.rta GET ;$a1
.rta new ;$a2 NEW augmented
;Commodore 64 BASIC Keyword Tokens
;$a3 TAB(
;$a4 TO
;$a5 FN
;$a6 SPC(
;$a7 THEN
;$a8 NOT
;$a9 STEP
;Commodore 64 BASIC Operator Tokens
;$aa + $b86a ADD
;$ab - $b853 SUBTRACT
;$ac * $ba2b MULTIPLY
;$ad / $bb12 DIVIDE
;$ae ^ $bf7b EXPONENTIATE
;$af AND $afe9 LOGICAL AND
;$b0 OR $afe6 LOGICAL OR
;$b1 > $bfb4 GREATER THAN
;$b2 = $aed4 EQUAL TO
;$b3 < $b016 LESS THAN
;Commodore 64 BASIC Function Tokens
;$b4 SGN $bc39
;$b5 INT $bccc
;$b6 ABS $bc58
;$b7 USR $0310
;$b8 FRE $b37d
;$b9 POS $b39e
;$ba SQR $bf71
;$bb RND $e097
;$bc LOG $b9ea
;$bd EXP $bfed
;$be COS $e264
;$bf SIN $e26b
;$c0 TAN $e2b4
;$c1 ATN $e30e
;$c2 PEEK $b80d
;$c3 LEN $b77c
;$c4 STR$ $b465
;$c5 VAL $b7ad
;$c6 ASC $b78b
;$c7 CHR$ $b6ec
;$c8 LEFT$ $b700
;$c9 RIGHT$ $b72c
;$ca MID$ $b737
;$cb GO *This is a keyword used to support syntax GO TO instead of GOTO
;MDBASIC Keyword Tokens
;$cb token was GO now OFF (keyword only)
.rta REM ;$cc ELSE token - using this cmd by itself behaves like REM
.rta merge ;$cd
.rta dump ;$ce
.rta vars ;$cf
.rta circle ;$d0
.rta fill ;$d1
.rta scroll ;$d2
.rta swap ;$d3
.rta cursor ;$d4
.rta disk ;$d5
.rta delete ;$d6
.rta files ;$d7
.rta color ;$d8
.rta move ;$d9
.rta sprite ;$da
.rta sprcol ;$db
.rta find ;$dc
.rta serial ;$dd
.rta design ;$de
.rta trace ;$df
.rta mapcol ;$e0
.rta plot ;$e1
.rta line ;$e2
.rta paint ;$e3
.rta draw ;$e4
.rta renum ;$e5
.rta text ;$e6
.rta screen ;$e7
.rta resume ;$e8
.rta adsr ;$e9
.rta wave ;$ea
.rta voice ;$eb
.rta pulse ;$ec
.rta vol ;$ed
.rta filter ;$ee
.rta play ;$ef
.rta auto ;$f0
.rta old ;$f1
;statements & functions
.rta error ;$f2 cmd and func
.rta key ;$f3 cmd & func
.rta time ;$f4 cmd & func
;
;MDBASIC Function Dispatch Table
funtab
.rta fnerr, fnkey, fntime ;$f2,$f3,$f4
.rta fnround, trim, mod ;$f5,$f6,$f7
.rta ptr, inf, pen ;$f8,$f9,$fa
.rta joy, pot, hex ;$fb,$fc,$fd
.rta instr, pi ;$fe,$ff (PI Constant)
;
;*** error messages ***
;To invoke, load x register with error# then jmp ($0300)
;CBM BASIC ERROR MESSAGES:
; 1 TOO MANY FILES
; 2 FILE OPEN
; 3 FILE NOT OPEN
; 4 FILE NOT FOUND
; 5 DEVICE NOT PRESENT
; 6 NOT INPUT FILE
; 7 NOT OUTPUT FILE
; 8 MISSING FILENAME
; 9 ILLEGAL DEVICE NUMBER
;10 NEXT WITHOUT FOR
;11 SYNTAX
;12 RETURN WITHOUT GOSUB
;13 OUT OF DATA
;14 ILLEGAL QUANTITY
;15 OVERFLOW
;16 OUT OF MEMORY
;17 UNDEF'D STATEMENT
;18 BAD SUBSCRIPT
;19 REDIM'D ARRAY
;20 DIVISION BY ZERO
;21 ILLEGAL DIRECT
;22 TYPE MISMATCH
;23 STRING TOO LONG
;24 FILE DATA
;25 FORMULA TOO COMPLEX
;26 CAN'T CONTINUE
;27 UNDEF'D FUNCTION
;28 VERIFY
;29 LOAD
;30 BREAK
;
;MDBASIC ERROR MESSAGES:
misop .shift "missing operand" ;31
ilvne .shift "illegal voice number" ;32
illspr .shift "illegal sprite number" ;33
ilcoor .shift "illegal coordinate" ;34
cantre .shift "resume without err" ;35
stkovr .shift "stack overflow" ;36
usrerr .shift "user defined" ;37 to 127 and 0
;
erradd .word misop, ilvne, illspr, ilcoor, cantre, stkovr, usrerr
;
;Program Tokenization process - text to tokens via vector ICRNCH ($0304)
;
toknew ldx TXTPTR
ldy #$04
sty GARBFL
nxtchr lda BUF,x
bpl norma ;bit 7 indicates a token value
cmp #TOKEN_PI ;pi token?
beq takchr
inx
bne nxtchr
norma cmp #" " ;space character?
beq takchr
sta ENDCHR ;search char for statement terminator or quote
cmp #"""
beq savech
bit GARBFL ;variable used by Program Tokenization process
bvs takchr
cmp #"?" ;replace ? with PRINT token
bne skip
lda #TOKEN_PRINT
bne takchr
skip
cmp #"'" ;alternate REM
bne skipp
lda #0
beq rem
skipp
cmp #"0"
bcc skip1
cmp #"<"
bcc takchr
skip1 sty $71
lda #FIRST_CMD_TOK
sta COUNT ;current token
ldy #$ff
stx TXTPTR
dex
cmplop iny
inx
tstnxt lda BUF,x
sec
sbc newcmd,y
beq cmplop
cmp #$80 ;last letter?
bne nxtcmd
ora COUNT
tachr1 ldy $71
takchr inx
iny
sta BUF-5,y
cmp #0
beq endln
sbc #":" ;ascii $3a
beq skip2
cmp #TOKEN_DATA-":" ;data token $83 minus $3a equals $49
bne skip3
skip2 sta GARBFL
skip3 sec
sbc #$55 ;rem token $8f minus $3a equals $55
bne nxtchr
rem
sta ENDCHR
remlop lda BUF,x
beq takchr
cmp ENDCHR
beq takchr
savech iny
sta BUF-5,y
inx
bne remlop
nxtcmd ldx TXTPTR
inc COUNT ;next token
contin iny
lda newcmd-1,y
bpl contin
lda newcmd,y
bne tstnxt
beq oldtok
notfou lda BUF,x
bpl tachr1
endln sta BUF-3,y
dec TXTPTR+1
lda #$ff
sta TXTPTR
rts
oldtok ldy #0
sty COUNT
lda RESLST,y ;list of cbm keywords
bne oldtst
oldcmp iny
inx
oldtst lda BUF,x
sec
sbc RESLST,y ;list of cbm keywords
beq oldcmp
cmp #$80
bne nxtold
ora COUNT
bne tachr1
nxtold ldx TXTPTR
inc COUNT
cont1 iny
lda RESLST-1,y
bpl cont1
lda RESLST,y
bne oldtst
beq notfou
;
;Evaluate tokens via vector IGONE ($0308)
;
exccmd
jsr trace1
execut
jsr CHRGET
beq nocmd ;occurs when line ends with a colon
xcmd jsr tstcmd
;if key trapping is enabled then proccess it
ldy keyflag ;0=off,1=on,2=pause
beq nocmd ;key trapping is off
dey
bne nocmd ;key trapping is paused
ldy CURLIN+1 ;when current line num hibyte is $FF (invalid) then immed mode
iny ;if y goes to 0 then immediate mode
beq nocmd ;otherwise program mode
lda NDX ;num chars in keyboard buffer
beq nocmd
sei
jsr LP2 ;get char in keyboard buffer
sta keyentry ;use K=KEY to get value
inc keyflag ;pause key trapping
lda #3 ;actually is 5 since this jsr counts for 2
jsr GETSTK ;check for space on stack
lda #>onkey1-1
pha
lda #<onkey1-1
pha
lda TXTPTR+1 ;save basic text ptr
pha ;of the statement to execute
lda TXTPTR ;after returning from subroutine
pha ;and it's
lda CURLIN+1 ;basic line# to RETURN
pha
lda CURLIN
pha
lda #TOKEN_GOSUB ;flag for RETURN with GOSUB
pha
lda TMPKEYP
ldy TMPKEYP+1
sta TXTPTR
sty TXTPTR+1
lda keyline
ldy keyline+1
setline
sta CURLIN
sty CURLIN+1
nocmd
jmp NEWSTT ;find beginning of next statement and execute
;
;after ON KEY RETURN re-enable key trapping
onkey1
lda keyflag ;if key trapping turned off manually during subroutine
beq nocmd ;then no need to switch pause to on
dec keyflag ;otherwise switch from paused (2) to on (1)
jmp NEWSTT ;find beginning of next statement and execute
;
remm jmp REM
let cmp #"'"-$80
beq remm
jmp LET ;perform LET
tstcmd
sbc #$80
bcc let
cmp #$a3-$80 ;lower than TAB( token $A3?
bcc oldcmd ;normal CBM BASIC cmd
cmp #FIRST_CMD_TOK+1-$80 ;token $cc is first executable
bcc badtok
sbc #FIRST_CMD_TOK-$80-$22 ;index of first executable token $cc is 35
oldcmd
asl ;index * 2 for word pointer indexing
tax
lda cmdtab+1,x ;hibyte
pha
lda cmdtab,x ;lobyte
pha
jmp CHRGET
;
vall
jsr CHRGET
valll
jsr PARCHK ;Evaluate Expression Within Parentheses
jmp VAL ;perform VAL
;
valfn
jsr getchr ;advance TXTPTR one byte
cmp #"b"
bcc valll
sta $c3 ;save fn type for later
jsr vall ;use VAL to determine TXTPTR
ldy $23 ;result of VAL is not used
ldx $22 ;set TXTPTR to first char in string
bne back1 ;backup 1 char to prepare for CHRGET
dey
back1
dex
stx TXTPTR
sty TXTPTR+1
;push onto stack the byte after the string
ldy #0
lda ($24),y
pha
;null-terminate the string for val calculation
tya
sta ($24),y
;push onto stack the return address $b7dd-1 to restore byte and TXTPTR
lda #$b7
pha
lda #$dc
pha
lda $c3 ;recall fn type
;determine VAL function
cmp #"h" ;hexadecimal
beq base16
cmp #"b" ;binary
beq base2
cmp #"o" ;octal
beq base8
badtok
jmp SNERR
;
;Evalutate functions via vector IEVAL ($030A) originally pointing to EVAL $AE86
newfun lda #$00 ;0=number, 255=string - all funcs take one numeric param
sta VALTYP ;Flag Type of Data (String or Numeric) to enforce data type
jsr CHRGET
bcc isnum ;numeric digit 0 to 9
jsr $b113 ;Check If .A Register Holds Alphabetic ASCII Character
bcs isvari ;is alpha
cmp #"@"
beq base8 ;octal value
bcs funtok ;probably token
cmp #"%" ;binary value literal?
beq base2
bcs oldfun ;probably a parenthesis or decimal point
cmp #"$" ;hex value literal?
beq base16
cmp #"!" ;NOT short-hand
beq not ;otherwise probably a quote
oldfun jmp $aead ;execute CBM BASIC function
not jmp $aed0 ;perform NOT
isvari jmp ISVAR ;get value of variable
isnum jmp FIN ;convert ASCII numerals into float with result in FAC1
funtok
cmp #TOKEN_VAL
beq valfn
cmp #FIRST_FUN_TOK ;CBM basic max token for functions?
bcc oldfun ;bad func token - will raise error
sbc #FIRST_FUN_TOK
asl ;index * 2 for word pointer indexing
tay ;prepare for direct indexing
lda funtab+1,y ;hibyte value of address for function
pha ;hibyte for indirect addressing
lda funtab,y ;lobyte value of address for function
pha ;lobyte for indirect addressing
jmp getchr ;get next TXTPTR then execute function
;
;evaluate inline binary, octal or hex value
;exponent increment: binary=1, octal=3, hex=4; shifted right = 0,1,2
base2
lda #1
.byte $2c
base8
lda #3
.byte $2c
base16
lda #4
;
sta BASZPT ;exponent of 2^x
jsr clrfac ;clear numeric work area
nxtdig
lda BASZPT ;convert base2 exponents 1,3,4
lsr ;into index 0,1,2 for table facexpo
tax ;to check max+1 digit value 2,8,16
;
jsr CHRGET ;get next literal digit char
beq end1
bcc digit ;carry clear when numeral 0-9
;non digit, check literal type is hex
cpx #2 ;hex?
bne end1 ;if not then stop now
sbc #7 ;'0'=0,'1'=1,...'A'=10,...'F'=15
digit
sec
sbc #"0"
bmi end1
cmp facexpo,x ;did digit value exceed highest value?
bcs end1 ;if so stop now otherwise keep going
tax
lda FACEXP
beq zero3
adc BASZPT ;increase by 2^x where x is 1,3 or 4
bcs over
sta FACEXP
zero3 txa
beq nxtdig
jsr FINLOG ;add signed int to FAC1
jmp nxtdig
;
over jmp OVERR
;clear num work area, FAC1 and FAC2
clrfac ldx #$13
lda #0
loop sta $5d,x
dex
bpl loop
end1 rts
;
;----------------
; TIME CLR reset time to all zeros
; TIME$ = T$ set the time start, format="00:00:00"
time
tax
jsr CHRGET
cpx #TOKEN_CLR
beq timeclr
cpx #"$"
bne badtime
;set the clock
cmp #TOKEN_EQUAL
bne badtime
jsr getstr
dec R6510
jsr settime
inc R6510
bcs badtime2
rts
;
badtime jmp SNERR
badtime2 jmp TMERR
;reset clock to 12AM
timeclr
lda #%10010010 ;BCD 12 (am/pm flag=1 since it flips on write when hour is 12)
sta TO2HRS ;writing this reg stops time reg updates
lda #0
sta TO2MIN
sta TO2SEC
sta TO2TEN ;writing this reg resumes time reg updates
rts
;
; T$ = TIME$ get current time as string value
; T = TIME get current time as float number of seconds since start
fntime
dec R6510
cmp #"$"
bne time2
;get time as a string
jsr getimstr
inc R6510