-
Notifications
You must be signed in to change notification settings - Fork 2
/
basic68k.asm
9576 lines (7525 loc) · 282 KB
/
basic68k.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
*************************************************************************************
* *
* Enhanced BASIC for the Motorola MC680xx *
* *
* This version is for Merlin FPGA Computer. *
* Matt Pearce *
* *
*************************************************************************************
* *
* Enhanced BASIC for the Motorola MC680xx *
* *
* This version is for the TS2 single board computer. *
* Jeff Tranter ([email protected]) *
* *
*************************************************************************************
* *
* Copyright(C) 2002-12 by Lee Davison. This program may be freely distributed *
* for personal use only. All commercial rights are reserved. *
* *
* More 68000 and other projects can be found on my website at .. *
* *
* http://mycorner.no-ip.org/index.html *
* *
* mail : [email protected] *
* *
*************************************************************************************
* Ver 3.54
* Ver 3.54 adds experimental support for LOAD/SAVE using Hobbytronics
* USB Flash Drive Host Board
* Ver 3.53 fixes math error that affected exponentiation ("^") and
* EXP() function. Thanks to joelang for fix.
* Ver 3.52 stops USING$() from reading beyond the end of the format string
* Ver 3.51 fixes the UCASE$() and LCASE$() functions for null strings
* Ver 3.50 unary minus in concatenate generates a type mismatch error
* Ver 3.49 doesn't tokenise 'DEF' or 'DEC' within a hex value
* Ver 3.48 allows scientific notation underflow in the USING$() function
* Ver 3.47 traps the use of array elements as the FOR loop variable
* Ver 3.46 updates function and function variable handling
*************************************************************************************
*
* Ver 3.45 makes the handling of non existant variables consistent and gives the
* option of not returning an error for a non existant variable. If this is the
* behaviour you want just change novar to some non zero value
XREF outbyte
XREF inbyte_noecho
XREF havebyte
XDEF main
* Set the symbol FLASH_SUPPORT to 1 if you want to enable experimental
* support for LOAD/SAVE using a Hobbytronics USB Flash Drive Host
* Board.
novar EQU 0 * non existant variables cause errors
* Set the symbol FLASH_SUPPORT to 1 if you want to enable experimental
* support for LOAD/SAVE using a Hobbytronics USB Flash Drive Host
* Board.
FLASH_SUPPORT EQU 0
*************************************************************************************
* Ver 3.44 adds overflow indication to the USING$() function
* Ver 3.43 removes an undocumented feature of concatenating null strings
* Ver 3.42 reimplements backspace so that characters are overwritten with [SPACE]
* Ver 3.41 removes undocumented features of the USING$() function
* Ver 3.40 adds the USING$() function
* Ver 3.33 adds the file requester to LOAD and SAVE
* Ver 3.32 adds the optional ELSE clause to IF .. THEN
*************************************************************************************
*
* Version 3.25 adds the option to change the behaviour of INPUT so that a null
* response does not cause a program break. If this is the behaviour you want just
* change nobrk to some non zero value.
nobrk EQU 0 * null response to INPUT causes a break
*************************************************************************************
*
* Version 3.xx replaces the fixed RAM addressing from previous versions with a RAM
* pointer in a3. this means that this could now be run as a task on a multitasking
* system where memory resources may change.
*************************************************************************************
* This lot is in RAM
* OFFSET 0 * start of RAM
ram_strt ds.l $100 * allow 1K for the stack, this should be plenty
* for any BASIC program that doesn't do something
* silly, it could even be much less.
ram_base
LAB_WARM ds.w 1 * BASIC warm start entry point
Wrmjpv ds.l 1 * BASIC warm start jump vector
Usrjmp ds.w 1 * USR function JMP address
Usrjpv ds.l 1 * USR function JMP vector
* system dependant i/o vectors
* these are in RAM and are set at start-up
V_INPT ds.w 1 * non halting scan input device entry point
V_INPTv ds.l 1 * non halting scan input device jump vector
V_OUTP ds.w 1 * send byte to output device entry point
V_OUTPv ds.l 1 * send byte to output device jump vector
V_LOAD ds.w 1 * load BASIC program entry point
V_LOADv ds.l 1 * load BASIC program jump vector
V_SAVE ds.w 1 * save BASIC program entry point
V_SAVEv ds.l 1 * save BASIC program jump vector
V_CTLC ds.w 1 * save CTRL-C check entry point
V_CTLCv ds.l 1 * save CTRL-C check jump vector
Itemp ds.l 1 * temporary integer (for GOTO etc)
Smeml ds.l 1 * start of memory (start of program)
* the program is stored as a series of lines each line having the following format
*
* ds.l 1 * pointer to the next line or $00000000 if [EOT]
* ds.l 1 * line number
* ds.b n * program bytes
* dc.b $00 * [EOL] marker, there will be a second $00 byte, if
* * needed, to pad the line to an even number of bytes
Sfncl ds.l 1 * start of functions (end of Program)
* the functions are stored as function name, function execute pointer and function
* variable name
*
* ds.l 1 * name
* ds.l 1 * execute pointer
* ds.l 1 * function variable
Svarl ds.l 1 * start of variables (end of functions)
* the variables are stored as variable name, variable value
*
* ds.l 1 * name
* ds.l 1 * packed float or integer value
Sstrl ds.l 1 * start of strings (end of variables)
* the strings are stored as string name, string pointer and string length
*
* ds.l 1 * name
* ds.l 1 * string pointer
* ds.w 1 * string length
Sarryl ds.l 1 * start of arrays (end of strings)
* the arrays are stored as array name, array size, array dimensions count, array
* dimensions upper bounds and array elements
*
* ds.l 1 * name
* ds.l 1 * size including this header
* ds.w 1 * dimensions count
* ds.w 1 * 1st dimension upper bound
* ds.w 1 * 2nd dimension upper bound
* ... * ...
* ds.w 1 * nth dimension upper bound
*
* then (i1+1)*(i2+1)...*(in+1) of either ..
*
* ds.l 1 * packed float or integer value
*
* .. if float or integer, or ..
*
* ds.l 1 * string pointer
* ds.w 1 * string length
*
* .. if string
Earryl ds.l 1 * end of arrays (start of free mem)
Sstorl ds.l 1 * string storage (moving down)
Ememl ds.l 1 * end of memory (upper bound of RAM)
Sutill ds.l 1 * string utility ptr
Clinel ds.l 1 * current line (Basic line number)
Blinel ds.l 1 * break line (Basic line number)
Cpntrl ds.l 1 * continue pointer
Dlinel ds.l 1 * current DATA line
Dptrl ds.l 1 * DATA pointer
Rdptrl ds.l 1 * read pointer
Varname ds.l 1 * current var name
Cvaral ds.l 1 * current var address
Lvarpl ds.l 1 * variable pointer for LET and FOR/NEXT
des_sk_e ds.l 6 * descriptor stack end address
des_sk * descriptor stack start address
* use a4 for the descriptor pointer
ds.w 1
Ibuffs ds.l $40 * start of input buffer
Ibuffe
* end of input buffer
FAC1_m ds.l 1 * FAC1 mantissa1
FAC1_e ds.w 1 * FAC1 exponent
FAC1_s EQU FAC1_e+1 * FAC1 sign (b7)
ds.w 1
FAC2_m ds.l 1 * FAC2 mantissa1
FAC2_e ds.l 1 * FAC2 exponent
FAC2_s EQU FAC2_e+1 * FAC2 sign (b7)
FAC_sc EQU FAC2_e+2 * FAC sign comparison, Acc#1 vs #2
flag EQU FAC2_e+3 * flag byte for divide routine
PRNlword ds.l 1 * PRNG seed long word
ut1_pl ds.l 1 * utility pointer 1
Asptl ds.l 1 * array size/pointer
Astrtl ds.l 1 * array start pointer
numexp EQU Astrtl * string to float number exponent count
expcnt EQU Astrtl+1 * string to float exponent count
expneg EQU Astrtl+3 * string to float eval exponent -ve flag
func_l ds.l 1 * function pointer
* these two need to be a word aligned pair !
Defdim ds.w 1 * default DIM flag
cosout EQU Defdim * flag which CORDIC output (re-use byte)
Dtypef EQU Defdim+1 * data type flag, $80=string, $40=integer, $00=float
Binss ds.l 4 * number to bin string start (32 chrs)
Decss ds.l 1 * number to decimal string start (16 chrs)
ds.w 1 *
Usdss ds.w 1 * unsigned decimal string start (10 chrs)
Hexss ds.l 2 * number to hex string start (8 chrs)
BHsend ds.w 1 * bin/decimal/hex string end
prstk ds.b 1 * stacked function index
tpower ds.b 1 * remember CORDIC power
Asrch ds.b 1 * scan-between-quotes flag, alt search character
Dimcnt ds.b 1 * # of dimensions
Breakf ds.b 1 * break flag, $00=END else=break
Oquote ds.b 1 * open quote flag (Flag: DATA; LIST; memory)
Gclctd ds.b 1 * garbage collected flag
Sufnxf ds.b 1 * subscript/FNX flag, 1xxx xxx = FN(0xxx xxx)
Imode ds.b 1 * input mode flag, $00=INPUT, $98=READ
Cflag ds.b 1 * comparison evaluation flag
TabSiz ds.b 1 * TAB step size
comp_f ds.b 1 * compare function flag, bits 0,1 and 2 used
* bit 2 set if >
* bit 1 set if =
* bit 0 set if <
Nullct ds.b 1 * nulls output after each line
TPos ds.b 1 * BASIC terminal position byte
TWidth ds.b 1 * BASIC terminal width byte
Iclim ds.b 1 * input column limit
ccflag ds.b 1 * CTRL-C check flag
ccbyte ds.b 1 * CTRL-C last received byte
ccnull ds.b 1 * CTRL-C last received byte 'life' timer
* these variables for simulator load/save routines
file_byte ds.b 1 * load/save data byte
file_id ds.l 1 * load/save file ID
dc.w 0 * dummy even value and zero pad byte
main
prg_strt
ram_addr EQU $80000 * RAM start address
ram_size EQU $aF0000 * RAM size
ACIA_1 EQU $00010040 * Console ACIA base address
ACIA_2 EQU $00010041 * Auxiliary ACIA base address
BRA code_start * For convenience, so you can start from first address
*************************************************************************************
*
* the following code is simulator specific, change to suit your system
* Output character to the console from register d0.b
VEC_OUT
jsr outbyte
RTS
* Output character to the second (aux) serial port from register d0.b
ifne FLASH_SUPPORT
VEC_OUT2
MOVEM.L A0/D1,-(A7) * Save working registers
LEA.L ACIA_2,A0 * A0 points to console ACIA
TXNOTREADY1
MOVE.B (A0),D1 * Read ACIA status
BTST #1,D1 * Test TDRE bit
BEQ.s TXNOTREADY1 * Until ACIA Tx ready
MOVE.B D0,2(A0) * Write character to send
MOVEM.L (A7)+,A0/D1 * Restore working registers
RTS
* Output null terminated string pointed to by A0 to first serial port.
PRINTSTRING1
MOVEM.L A0/D0,-(A7) * Save working registers
LP1 CMP.B #0,(A0) * Is it null?
BEQ RET1 * If so, return
MOVE.B (A0)+,D0 * Get character and advance pointer
JSR VEC_OUT * Output it
BRA LP1 * Continue for rest of string
RET1 MOVEM.L (A7)+,A0/D0 * Restore working registers
RTS * Return
* Output null terminated string pointed to by A0 to second serial port.
PRINTSTRING2
MOVEM.L A0/D0,-(A7) * Save working registers
LP2 CMP.B #0,(A0) * Is it null?
BEQ RET2 * If so, return
MOVE.B (A0)+,D0 * Get character and advance pointer
JSR VEC_OUT2 * Output it
BRA LP2 * Continue for rest of string
RET2 MOVEM.L (A7)+,A0/D0 * Restore working registers
RTS * Return
endc
*************************************************************************************
*
* input a character from the console into register d0
* else return Cb=0 if there's no character available
VEC_IN
jsr havebyte
CMP #0,D0
BEQ.s RXNOTREADY
jsr inbyte_noecho
ORI.B #1,CCR * Set the carry, flag we got a byte
RTS * Return
RXNOTREADY
ANDI.B #$FE,CCR * Clear the carry, flag character not available
RTS
* Input routine used in LOAD mode to read file from USB flash storage.
ifne FLASH_SUPPORT
VEC_IN2
MOVEM.L A0/D1,-(A7) * Save working registers
LEA.L VEC_OUT2,A0 * Redirect output to aux. port.
MOVE.L A0,V_OUTPv(a3)
* The first time, send READ <filename> 1 1
* Subsequent times, send READ <filename> n 1
LEA LAB_READN(pc),A0 * Send READ command string
BSR PRINTSTRING2 * Print null terminated string
LEA load_filename(A3),A0 * Send filename string
BSR PRINTSTRING2 * Print null terminated string
MOVE.B #' ',D0 * Send space
JSR VEC_OUT2
CMP.B #1,load_first(A3) * First time?
BNE NOTFIRST1
MOVE.B #'1',D0 * Send '1'
CLR.B load_first(A3) * Clear first flag
BRA SENDCMD1
NOTFIRST1
MOVE.B #'n',D0 * Send 'n'
SENDCMD1
JSR VEC_OUT2
MOVE.B #' ',D0 * Send space
JSR VEC_OUT2
MOVE.B #'1',D0 * Send '1'
JSR VEC_OUT2
MOVE.B #$0D,D0 * Send <Return>
JSR VEC_OUT2
LEA.L VEC_OUT,A0 * Redirect output back to console port.
MOVE.L A0,V_OUTPv(a3)
* Read one byte from USB host
LEA.L ACIA_2,A0 * A0 points to console ACIA
RXNOTREADY2
MOVE.B (A0),D1 * Read ACIA status
BTST #0,D1 * Test RDRF bit
BEQ.S RXNOTREADY2 * Branch if ACIA Rx not ready
MOVE.B 2(A0),D0 * Read character received
* Check for end of file character ('~') and if found, redirect
* input back to console port.
CMP.B #'~',D0 * End of file marker?
BNE NOTEOF
MOVE.B #$0D,D0 * Convert '~' to a Return
LEA.L VEC_IN,A0 * Redirect input back to console port.
MOVE.L A0,V_INPTv(a3)
NOTEOF
MOVEM.L (A7)+,A0/D1 * Restore working registers
ORI.b #1,CCR * Set the carry, flag we got a byte
RTS * Return
endc
*************************************************************************************
*
* LOAD routine for the TS2 computer (not implemented)
ifeq FLASH_SUPPORT
VEC_LD
MOVEQ #$2E,d7 * error code $2E "Not implemented" error
BRA LAB_XERR * do error #d7, then warm start
endc
* LOAD routine for the TS2 computer. Supports a Hobbytronics USB Flash
* Drive Host Board connected to the auxiliary serial port.
ifne FLASH_SUPPORT
VEC_LD LEA LAB_FILENAME(PC),A0 * Prompt for filename.
BSR PRINTSTRING1 * Print null terminated string
MOVE.L A3,A2 * Save pointer to RAM variables
GETFN1 JSR VEC_IN * Get character
BCC GETFN1 * Go back if carry clear, indicating no key pressed
JSR VEC_OUT * Echo the character
CMP.B #$0D,D0 * Was it <Return>?
BEQ ENDLN1 * If so, branch
CMP.B #$7F,D0 * Was it <Delete>?
BEQ DELETE1 * If so, handle delete
CMP.B #$08,D0 * Was it <Backspace?
BEQ DELETE1 * If so, handle as delete
MOVE.B D0,load_filename(A2) * Save in buffer
ADDQ.L #1,A2 * Advance string pointer
BRA GETFN1 * Go back and get next character
DELETE1 SUBQ.L #1,A2 * Delete last character entered
BRA GETFN1 * Go back and get next character
ENDLN1 MOVE.B #0,load_filename(A2) * Add terminating null to filename
LEA.L VEC_IN2,A0 * Redirect input from aux. port.
MOVE.L A0,V_INPTv(a3)
MOVE.B #1,load_first(A3) * Set load_first flag
* Input routine will detect end of file and redirect input back to
* console port.
RTS
endc
*************************************************************************************
*
* SAVE routine for the TS2 computer (not implemented)
ifeq FLASH_SUPPORT
VEC_SV
MOVEQ #$2E,d7 * error code $2E "Not implemented" error
BRA LAB_XERR * do error #d7, then warm start
endc
ifne FLASH_SUPPORT
* SAVE routine for the TS2 computer. Supports a Hobbytronics USB Flash
* Drive Host Board connected to the auxiliary serial port.
* TODO: Make configurable at build time
VEC_SV LEA LAB_FILENAME(PC),A0 * Prompt for filename.
BSR PRINTSTRING1 * Print null terminated string
MOVE.L A3,A2 * Save pointer to RAM variables
GETFN JSR VEC_IN * Get character
BCC GETFN * Go back if carry clear, indicating no key pressed
JSR VEC_OUT * Echo the character
CMP.B #$0D,D0 * Was it <Return>?
BEQ ENDLN * If so, branch
CMP.B #$7F,D0 * Was it <Delete>?
BEQ DELETE * If so, handle delete
CMP.B #$08,D0 * Was it <Backspace?
BEQ DELETE * If so, handle as delete
MOVE.B D0,load_filename(A2) * Save in buffer
ADDQ.L #1,A2 * Advance string pointer
BRA GETFN * Go back and get next character
DELETE SUBQ.L #1,A2 * Delete last character entered
BRA GETFN * Go back and get next character
ENDLN MOVE.B #0,load_filename(A2) * Add terminating null to filename
LEA.L VEC_OUT2,A0 * Redirect output to aux. port.
MOVE.L A0,V_OUTPv(a3)
LEA LAB_WRITE(pc),A0 * Send WRITE command string
BSR PRINTSTRING2 * Print null terminated string
LEA load_filename(A3),A0 * Send filename string
BSR PRINTSTRING2 * Print null terminated string
MOVE.B #$0D,D0 * Send <Return>
JSR VEC_OUT2
MOVE.l #356000,d0 * Delay approx. 1 second to allow USB to create file
DELAY SUBQ.l #1,d0
BNE DELAY
MOVEQ #0,d0 * Tells LIST no arguments
ANDI.b #$FE,CCR * Clear carry
BSR LAB_LIST * Call LIST routine
MOVEQ #'~',d0 * Send tilde symbol indicate end of file (used when loading)
BSR LAB_PRNA
MOVEQ #26,d0 * Send Control-Z to indicate end of file save operation
BSR LAB_PRNA
LEA.L VEC_OUT,A0 * Redirect output back to console port.
MOVE.L A0,V_OUTPv(a3)
RTS * Return
LAB_WRITE
dc.b '$WRITE ',$00
LAB_READN
dc.b '$READ ',$00
LAB_FILENAME
dc.b 'Filename? ',$00
endc
even
*************************************************************************************
code_start
* Set up ACIA parameters
LEA.L ACIA_1,A0 * A0 points to console ACIA
MOVE.B #$15,(A0) * Set up ACIA1 constants (no IRQ,
* RTS* low, 8 bit, no parity, 1 stop)
LEA.L ACIA_2,A0 * A0 points to aux. ACIA
MOVE.B #$15,(A0) * Set up ACIA2 constants (no IRQ,
* RTS* low, 8 bit, no parity, 1 stop)
* to tell EhBASIC where and how much RAM it has pass the address in a0 and the size
* in d0. these values are at the end of the .inc file
MOVEA.l #ram_addr,a0 * tell BASIC where RAM starts
MOVE.l #ram_size,d0 * tell BASIC how big RAM is
* end of simulator specific code
****************************************************************************************
****************************************************************************************
****************************************************************************************
****************************************************************************************
*
* Register use :- (must improve this !!)
*
* a6 - temp Bpntr * temporary BASIC execute pointer
* a5 - Bpntr * BASIC execute (get byte) pointer
* a4 - des_sk * descriptor stack pointer
* a3 - ram_strt * start of RAM. all RAM references are offsets
* * from this value
*
*************************************************************************************
*
* BASIC cold start entry point. assume entry with RAM address in a0 and RAM length
* in d0
LAB_COLD
CMP.l #$4000,d0 * compare size with 16k
BGE.s LAB_sizok * branch if >= 16k
MOVEQ #5,d0 * error 5 - not enough RAM
move.b #228,D7 * Go to TUTOR function
trap #14 * Call TRAP14 handler
LAB_sizok
MOVEA.l a0,a3 * copy RAM base to a3
ADDA.l d0,a0 * a0 is top of RAM
MOVE.l a0,Ememl(a3) * set end of mem
LEA ram_base(a3),sp * set stack to RAM start + 1k
MOVE.w #$4EF9,d0 * JMP opcode
MOVEA.l sp,a0 * point to start of vector table
MOVE.w d0,(a0)+ * LAB_WARM
LEA LAB_COLD(pc),a1 * initial warm start vector
MOVE.l a1,(a0)+ * set vector
MOVE.w d0,(a0)+ * Usrjmp
LEA LAB_FCER(pc),a1 * initial user function vector
* "Function call" error
MOVE.l a1,(a0)+ * set vector
MOVE.w d0,(a0)+ * V_INPT JMP opcode
LEA VEC_IN(pc),a1 * get byte from input device vector
MOVE.l a1,(a0)+ * set vector
MOVE.w d0,(a0)+ * V_OUTP JMP opcode
LEA VEC_OUT(pc),a1 * send byte to output device vector
MOVE.l a1,(a0)+ * set vector
MOVE.w d0,(a0)+ * V_LOAD JMP opcode
LEA VEC_LD(pc),a1 * load BASIC program vector
MOVE.l a1,(a0)+ * set vector
MOVE.w d0,(a0)+ * V_SAVE JMP opcode
LEA VEC_SV(pc),a1 * save BASIC program vector
MOVE.l a1,(a0)+ * set vector
MOVE.w d0,(a0)+ * V_CTLC JMP opcode
LEA VEC_CC(pc),a1 * save CTRL-C check vector
MOVE.l a1,(a0)+ * set vector
* set-up start values
*##LAB_GMEM
MOVEQ #$00,d0 * clear d0
MOVE.b d0,Nullct(a3) * default NULL count
MOVE.b d0,TPos(a3) * clear terminal position
MOVE.b d0,ccflag(a3) * allow CTRL-C check
MOVE.w d0,prg_strt-2(a3) * clear start word
MOVE.w d0,BHsend(a3) * clear value to string end word
MOVE.b #$50,TWidth(a3) * default terminal width byte for simulator
MOVE.b #$0E,TabSiz(a3) * save default tab size = 14
MOVE.b #$38,Iclim(a3) * default limit for TAB = 14 for simulator
LEA des_sk(a3),a4 * set descriptor stack start
LEA prg_strt(a3),a0 * get start of mem
MOVE.l a0,Smeml(a3) * save start of mem
BSR LAB_1463 * do "NEW" and "CLEAR"
BSR LAB_CRLF * print CR/LF
MOVE.l Ememl(a3),d0 * get end of mem
SUB.l Smeml(a3),d0 * subtract start of mem
BSR LAB_295E * print d0 as unsigned integer (bytes free)
LEA LAB_SMSG(pc),a0 * point to start message
BSR LAB_18C3 * print null terminated string from memory
LEA LAB_RSED(pc),a0 * get pointer to value
BSR LAB_UFAC * unpack memory (a0) into FAC1
LEA LAB_1274(pc),a0 * get warm start vector
MOVE.l a0,Wrmjpv(a3) * set warm start vector
BSR LAB_RND * initialise
JMP LAB_WARM(a3) * go do warm start
*************************************************************************************
*
* do format error
LAB_FOER
MOVEQ #$2C,d7 * error code $2C "Format" error
BRA.s LAB_XERR * do error #d7, then warm start
*************************************************************************************
*
* do address error
LAB_ADER
MOVEQ #$2A,d7 * error code $2A "Address" error
BRA.s LAB_XERR * do error #d7, then warm start
*************************************************************************************
*
* do wrong dimensions error
LAB_WDER
MOVEQ #$28,d7 * error code $28 "Wrong dimensions" error
BRA.s LAB_XERR * do error #d7, then warm start
*************************************************************************************
*
* do undimensioned array error
LAB_UDER
MOVEQ #$26,d7 * error code $26 "undimensioned array" error
BRA.s LAB_XERR * do error #d7, then warm start
*************************************************************************************
*
* do undefined variable error
LAB_UVER
* if you do want a non existant variable to return an error then leave the novar
* value at the top of this file set to zero
ifeq novar
MOVEQ #$24,d7 * error code $24 "undefined variable" error
BRA.s LAB_XERR * do error #d7, then warm start
endc
* if you want a non existant variable to return a null value then set the novar
* value at the top of this file to some non zero value
ifne novar
ADD.l d0,d0 * .......$ .......& ........ .......0
SWAP d0 * ........ .......0 .......$ .......&
ROR.b #1,d0 * ........ .......0 .......$ &.......
LSR.w #1,d0 * ........ .......0 0....... $&.....�.
AND.b #$C0,d0 * mask the type bits
MOVE.b d0,Dtypef(a3) * save the data type
MOVEQ #0,d0 * clear d0 and set the zero flag
MOVEA.l d0,a0 * return a null address
RTS
endc
*************************************************************************************
*
* do loop without do error
LAB_LDER
MOVEQ #$22,d7 * error code $22 "LOOP without DO" error
BRA.s LAB_XERR * do error #d7, then warm start
*************************************************************************************
*
* do undefined function error
LAB_UFER
MOVEQ #$20,d7 * error code $20 "Undefined function" error
BRA.s LAB_XERR * do error #d7, then warm start
*************************************************************************************
*
* do can't continue error
LAB_CCER
MOVEQ #$1E,d7 * error code $1E "Can't continue" error
BRA.s LAB_XERR * do error #d7, then warm start
*************************************************************************************
*
* do string too complex error
LAB_SCER
MOVEQ #$1C,d7 * error code $1C "String too complex" error
BRA.s LAB_XERR * do error #d7, then warm start
*************************************************************************************
*
* do string too long error
LAB_SLER
MOVEQ #$1A,d7 * error code $1A "String too long" error
BRA.s LAB_XERR * do error #d7, then warm start
*************************************************************************************
*
* do type missmatch error
LAB_TMER
MOVEQ #$18,d7 * error code $18 "Type mismatch" error
BRA.s LAB_XERR * do error #d7, then warm start
*************************************************************************************
*
* do illegal direct error
LAB_IDER
MOVEQ #$16,d7 * error code $16 "Illegal direct" error
BRA.s LAB_XERR * do error #d7, then warm start
*************************************************************************************
*
* do divide by zero error
LAB_DZER
MOVEQ #$14,d7 * error code $14 "Divide by zero" error
BRA.s LAB_XERR * do error #d7, then warm start
*************************************************************************************
*
* do double dimension error
LAB_DDER
MOVEQ #$12,d7 * error code $12 "Double dimension" error
BRA.s LAB_XERR * do error #d7, then warm start
*************************************************************************************
*
* do array bounds error
LAB_ABER
MOVEQ #$10,d7 * error code $10 "Array bounds" error
BRA.s LAB_XERR * do error #d7, then warm start
*************************************************************************************
*
* do undefined satement error
LAB_USER
MOVEQ #$0E,d7 * error code $0E "Undefined statement" error
BRA.s LAB_XERR * do error #d7, then warm start
*************************************************************************************
*
* do out of memory error
LAB_OMER
MOVEQ #$0C,d7 * error code $0C "Out of memory" error
BRA.s LAB_XERR * do error #d7, then warm start
*************************************************************************************
*
* do overflow error
LAB_OFER
MOVEQ #$0A,d7 * error code $0A "Overflow" error
BRA.s LAB_XERR * do error #d7, then warm start
*************************************************************************************
*
* do function call error
LAB_FCER
MOVEQ #$08,d7 * error code $08 "Function call" error
BRA.s LAB_XERR * do error #d7, then warm start
*************************************************************************************
*
* do out of data error
LAB_ODER
MOVEQ #$06,d7 * error code $06 "Out of DATA" error
BRA.s LAB_XERR * do error #d7, then warm start
*************************************************************************************
*
* do return without gosub error
LAB_RGER
MOVEQ #$04,d7 * error code $04 "RETURN without GOSUB" error
BRA.s LAB_XERR * do error #d7, then warm start
*************************************************************************************
*
* do syntax error
LAB_SNER
MOVEQ #$02,d7 * error code $02 "Syntax" error
BRA.s LAB_XERR * do error #d7, then warm start
*************************************************************************************
*
* do next without for error
LAB_NFER
MOVEQ #$00,d7 * error code $00 "NEXT without FOR" error
*************************************************************************************
*
* do error #d7, then warm start
LAB_XERR
BSR LAB_1491 * flush stack & clear continue flag
BSR LAB_CRLF * print CR/LF
LEA LAB_BAER(pc),a1 * start of error message pointer table
MOVE.w (a1,d7.w),d7 * get error message offset
LEA (a1,d7.w),a0 * get error message address
BSR LAB_18C3 * print null terminated string from memory
LEA LAB_EMSG(pc),a0 * point to " Error" message
LAB_1269
BSR LAB_18C3 * print null terminated string from memory
MOVE.l Clinel(a3),d0 * get current line
BMI.s LAB_1274 * go do warm start if -ve # (was immediate mode)
* else print line number
BSR LAB_2953 * print " in line [LINE #]"
* BASIC warm start entry point, wait for Basic command
LAB_1274
LEA LAB_RMSG(pc),a0 * point to "Ready" message
BSR LAB_18C3 * go do print string
* wait for Basic command - no "Ready"
LAB_127D
MOVEQ #-1,d1 * set to -1
MOVE.l d1,Clinel(a3) * set current line #
MOVE.b d1,Breakf(a3) * set break flag
LEA Ibuffs(a3),a5 * set basic execute pointer ready for new line
LAB_127E
BSR LAB_1357 * call for BASIC input
BSR LAB_GBYT * scan memory
BEQ.s LAB_127E * loop while null
* got to interpret input line now ....
BCS.s LAB_1295 * branch if numeric character, handle new
* BASIC line
* no line number so do immediate mode, a5
* points to the buffer start
BSR LAB_13A6 * crunch keywords into Basic tokens
* crunch from (a5), output to (a0)
* returns ..
* d2 is length, d1 trashed, d0 trashed,
* a1 trashed
BRA LAB_15F6 * go scan & interpret code
*************************************************************************************
*
* handle a new BASIC line
LAB_1295
BSR LAB_GFPN * get fixed-point number into temp integer & d1
BSR LAB_13A6 * crunch keywords into Basic tokens
* crunch from (a5), output to (a0)
* returns .. d2 is length,
* d1 trashed, d0 trashed, a1 trashed
MOVE.l Itemp(a3),d1 * get required line #
BSR LAB_SSLN * search BASIC for d1 line number
* returns pointer in a0
BCS.s LAB_12E6 * branch if not found
* aroooogah! line # already exists! delete it
MOVEA.l (a0),a1 * get start of block (next line pointer)
MOVE.l Sfncl(a3),d0 * get end of block (start of functions)
SUB.l a1,d0 * subtract start of block ( = bytes to move)
LSR.l #1,d0 * /2 (word move)
SUBQ.l #1,d0 * adjust for DBF loop
SWAP d0 * swap high word to low word
MOVEA.l a0,a2 * copy destination
LAB_12AE
SWAP d0 * swap high word to low word
LAB_12B0
MOVE.w (a1)+,(a2)+ * copy word
DBF d0,LAB_12B0 * decrement low count and loop until done
SWAP d0 * swap high word to low word