-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathmain.asm
2026 lines (2026 loc) · 27.5 KB
/
main.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
; TITLE BBC BASIC (C) R.T.RUSSELL 1987
;
;BBC BASIC INTERPRETER - Z80 VERSION
;COMMAND, ERROR AND LEXICAL ANALYSIS MODULE - "MAIN"
;(C) COPYRIGHT R.T.RUSSELL 1984
;VERSION 2.3, 07-05-1984
;VERSION 3.0, 01-03-1987
;
EXTERN XEQ
EXTERN RUN0
EXTERN CHAIN0
EXTERN TERMQ
EXTERN MUL16
EXTERN X4OR5
EXTERN FILL
EXTERN ESCAPE
EXTERN CHECK
EXTERN SEARCH
;
EXTERN OSWRCH
EXTERN OSLINE
EXTERN OSINIT
EXTERN OSLOAD
EXTERN OSSAVE
EXTERN OSBGET
EXTERN OSBPUT
EXTERN OSSHUT
EXTERN OSSTAT
EXTERN PROMPT
EXTERN LTRAP
EXTERN OSCLI
EXTERN RESET
;
EXTERN COMMA
EXTERN BRAKET
EXTERN NXT
EXTERN ZERO
EXTERN ITEMI
EXTERN EXPRI
EXTERN EXPRS
EXTERN DECODE
EXTERN LOADN
EXTERN SFIX
;
PUBLIC START
PUBLIC OUTCHR
PUBLIC OUT
PUBLIC ERROR
PUBLIC EXTERR
PUBLIC REPORT
PUBLIC CLOOP
PUBLIC WARM
PUBLIC NEW
PUBLIC OLD
PUBLIC LOAD
PUBLIC SAVE
PUBLIC RENUM
PUBLIC AUTO
PUBLIC CLEAR
PUBLIC CRLF
PUBLIC SAYLN
PUBLIC LOAD0
PUBLIC TELL
PUBLIC FINDL
PUBLIC SETLIN
PUBLIC LIST
PUBLIC DELETE
PUBLIC GETVAR
PUBLIC PUTVAR
PUBLIC GETDEF
PUBLIC CREATE
PUBLIC PBCDL
PUBLIC LEXAN2
PUBLIC RANGE
;
EXTERN PAGE
EXTERN ACCS
EXTERN BUFFER
EXTERN LINENO
EXTERN LOMEM
EXTERN HIMEM
EXTERN COUNT
EXTERN WIDTH
EXTERN TOP
EXTERN FREE
EXTERN STAVAR
EXTERN DYNVAR
EXTERN ERRTXT
EXTERN ERR
EXTERN ERL
EXTERN ERRLIN
EXTERN ERRTRP
EXTERN FNPTR
EXTERN PROPTR
EXTERN AUTONO
EXTERN INCREM
EXTERN LISTON
EXTERN TRACEN
;
ORG 100H
;
TERROR: EQU 85H
LINE: EQU 86H
ELSE: EQU 8BH
THEN: EQU 8CH
LINO: EQU 8DH
FN: EQU 0A4H
TO: EQU 0B8H
REN: EQU 0CCH
DATA: EQU 0DCH
DIM: EQU 0DEH
FOR: EQU 0E3H
GOSUB: EQU 0E4H
GOTO: EQU 0E5H
TIF: EQU 0E7H
LOCAL: EQU 0EAH
NEXT: EQU 0EDH
ON: EQU 0EEH
PROC: EQU 0F2H
REM: EQU 0F4H
REPEAT: EQU 0F5H
RESTOR: EQU 0F7H
TRACE: EQU 0FCH
UNTIL: EQU 0FDH
;
TOKLO: EQU 8FH
TOKHI: EQU 93H
OFFSET: EQU 0CFH-TOKLO
;
START: JP COLD
JP WARM
JP ESCAPE
JP EXTERR
JP TELL
JP TEXT
JP SETTOP
JP CLEAR
JP RUN0
JP OSCLI
JP OSBGET
JP OSBPUT
JP OSSTAT
JP OSSHUT
COLD: LD HL,STAVAR ;COLD START
LD SP,HL
LD (HL),10
INC L
LD (HL),9
INC L
XOR A
PURGE: LD (HL),A ;CLEAR SCRATCHPAD
INC L
JR NZ,PURGE
LD A,37H ;V3.0
LD (LISTON),A
LD HL,NOTICE
LD (ERRTXT),HL
CALL OSINIT
LD (HIMEM),DE
LD (PAGE),HL
CALL NEWIT
JP NZ,CHAIN0 ;AUTO-RUN
CALL TELL
DEFM "BBC BASIC (Z80) Version 3.00 "
DEFB CR
DEFB LF
NOTICE: DEFM "(C) Copyright R.T.Russell 1987"
DEFB CR
DEFB LF
DEFB 0
WARM: DEFB 0F6H
CLOOP: SCF
LD SP,(HIMEM)
CALL PROMPT ;PROMPT USER
LD HL,LISTON
LD A,(HL)
AND 0FH ;LISTO
OR 30H ;OPT 3
LD (HL),A
SBC HL,HL ;HL <- 0 (V3.0)
LD (ERRTRP),HL
LD (ERRLIN),HL
LD HL,(AUTONO)
LD (LINENO),HL
LD A,H
OR L
JR Z,NOAUTO
PUSH HL
CALL PBCD ;AUTO NUMBER
POP HL
LD BC,(INCREM)
LD B,0
ADD HL,BC
JP C,TOOBIG
LD (AUTONO),HL
LD A,' '
CALL OUTCHR
NOAUTO: LD HL,ACCS
CALL OSLINE ;GET CONSOLE INPUT
XOR A
LD (COUNT),A
LD IY,ACCS
CALL LINNUM
CALL NXT
LD A,H
OR L
JR Z,LNZERO ;FOR AUTO (NON-MAPPED)
LD (LINENO),HL
LNZERO: LD DE,BUFFER
LD C,1 ;LEFT MODE
CALL LEXAN2 ;LEXICAL ANALYSIS
LD (DE),A ;TERMINATOR
XOR A
LD B,A
LD C,E ;BC=LINE LENGTH
INC DE
LD (DE),A ;ZERO NEXT
LD HL,(LINENO)
LD A,H
OR L
LD IY,BUFFER ;FOR XEQ
JP Z,XEQ ;DIRECT MODE
PUSH BC
PUSH HL
CALL SETTOP ;SET TOP
POP HL
CALL FINDL
CALL Z,DEL
POP BC
LD A,C
OR A
JP Z,CLOOP ;DELETE LINE ONLY
ADD A,4
LD C,A ;LENGTH INCLUSIVE
PUSH DE ;LINE NUMBER
PUSH BC ;SAVE LINE LENGTH
EX DE,HL
LD HL,(TOP)
PUSH HL
ADD HL,BC
PUSH HL
INC H
XOR A
SBC HL,SP
POP HL
JP NC,ERROR ;"No room"
LD (TOP),HL
EX (SP),HL
PUSH HL
INC HL
OR A
SBC HL,DE
LD B,H ;BC=AMOUNT TO MOVE
LD C,L
POP HL
POP DE
JR Z,ATEND
LDDR ;MAKE SPACE
ATEND: POP BC ;LINE LENGTH
POP DE ;LINE NUMBER
INC HL
LD (HL),C ;STORE LENGTH
INC HL
LD (HL),E ;STORE LINE NUMBER
INC HL
LD (HL),D
INC HL
LD DE,BUFFER
EX DE,HL
DEC C
DEC C
DEC C
LDIR ;ADD LINE
CALL CLEAN
JP CLOOP
;
;LIST OF TOKENS AND KEYWORDS.
;I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 0
DEFB 0F5H
DEFM "REPEAT"
DEFB 0F6H
DEFM "REPORT"
DEFB 0
DEFB 0F3H
DEFM "READ"
DEFB 0F4H
DEFM "REM"
DEFB 0F9H
DEFM "RUN"
DEFB 0
DEFB 0B2H
DEFM "RAD"
DEFB 0F7H
DEFM "RESTORE"
DEFB 0C2H
DEFM "RIGHT$("
DEFB 0B3H
DEFM "RND"
DEFB 0
DEFB 0CCH
DEFM "RENUMBER"
DEFB 88H
DEFM "STEP"
DEFB 0CDH
DEFM "SAVE"
DEFB 0B4H
DEFM "SGN"
DEFB 0B5H
DEFM "SIN"
DEFB 0B6H
DEFM "SQR"
DEFB 89H
DEFM "SPC"
DEFB 0C3H
DEFM "STR$"
DEFB 0C4H
DEFM "STRING$("
DEFB 0D4H
DEFM "SOUND"
DEFB 0FAH
DEFM "STOP"
DEFB 0
DEFB 0B7H
DEFM "TAN"
DEFB 8CH
DEFM "THEN"
DEFB 0B8H
DEFM "TO"
DEFB 8AH
DEFM "TAB("
DEFB 0FCH
DEFM "TRACE"
DEFB 91H
DEFM "TIME"
DEFB 0
DEFB 0B9H
DEFM "TRUE"
DEFB 0
DEFB 0FDH
DEFM "UNTIL"
DEFB 0BAH
DEFM "USR"
DEFB 0EFH
DEFM "VDU"
DEFB 0BBH
DEFM "VAL"
DEFB 0BCH
DEFM "VPOS"
DEFB 0
DEFB 0FEH
DEFM "WIDTH"
DEFB 0D3H
DEFM "HIMEM"
DEFB 0D2H
DEFM "LOMEM"
DEFB 0D0H
DEFM "PAGE"
DEFB 0CFH
DEFM "PTR"
DEFB 0D1H
DEFM "TIME"
DEFB 1
DEFM "Missing "
DEFB 2
DEFM "No such "
DEFB 3
DEFM "Bad "
DEFB 4
DEFM " range"
DEFB 5
DEFM "variable"
DEFB 6
DEFM "Out of"
DEFB 7
DEFM "No "
DEFB 8
DEFM " space"
KEYWDL EQU $-KEYWDS
DEFW -1
;
;ERROR MESSAGES:
;
ERRWDS: DEFB 7
DEFM "room"
DEFB 0
DEFB 6
DEFB 4
DEFB 0
DEFW 0
DEFM "Mistake"
DEFB 0
DEFB 1
DEFM ","
DEFB 0
DEFM "Type mismatch"
DEFB 0
DEFB 7
DEFB FN
DEFW 0
DEFB 1
DEFM '"'
DEFB 0
DEFB 3
DEFB DIM
DEFB 0
DEFB DIM
DEFB 8
DEFB 0
DEFM "Not "
DEFB LOCAL
DEFB 0
DEFB 7
DEFB PROC
DEFB 0
DEFM "Array"
DEFB 0
DEFM "Subscript"
DEFB 0
DEFM "Syntax error"
DEFB 0
DEFM "Escape"
DEFB 0
DEFM "Division by zero"
DEFB 0
DEFM "String too long"
DEFB 0
DEFM "Too big"
DEFB 0
DEFM "-ve root"
DEFB 0
DEFM "Log"
DEFB 4
DEFB 0
DEFM "Accuracy lost"
DEFB 0
DEFM "Exp"
DEFB 4
DEFW 0
DEFB 2
DEFB 5
DEFB 0
DEFB 1
DEFM ")"
DEFB 0
DEFB 3
DEFM "HEX"
DEFB 0
DEFB 2
DEFB FN
DEFM "/"
DEFB PROC
DEFB 0
DEFB 3
DEFM "call"
DEFB 0
DEFM "Arguments"
DEFB 0
DEFB 7
DEFB FOR
DEFB 0
DEFM "Can't match "
DEFB FOR
DEFB 0
DEFB FOR
DEFM " "
DEFB 5
DEFW 0
DEFB 7
DEFB TO
DEFW 0
DEFB 7
DEFB GOSUB
DEFB 0
DEFB ON
DEFM " syntax"
DEFB 0
DEFB ON
DEFB 4
DEFB 0
DEFB 2
DEFM "line"
DEFB 0
DEFB 6
DEFM " "
DEFB DATA
DEFB 0
DEFB 7
DEFB REPEAT
DEFW 0
DEFB 1
DEFM "#"
DEFB 0
;
;COMMANDS:
;
;DELETE line,line
;
DELETE: CALL SETTOP ;SET TOP
CALL DLPAIR
DELET1: LD A,(HL)
OR A
JR Z,WARMNC
INC HL
LD E,(HL)
INC HL
LD D,(HL)
LD A,D
OR E
JR Z,CLOOP1 ;LINE NUMBER ZERO
DEC HL
DEC HL
EX DE,HL
SCF
SBC HL,BC
EX DE,HL
JR NC,WARMNC
PUSH BC
CALL DEL
POP BC
JR DELET1
;
;LISTO expr
;
LISTO: INC IY ;SKIP "O"
CALL EXPRI
EXX
LD A,L
LD (LISTON),A
CLOOP1: JP CLOOP
;
;LIST
;LIST line
;LIST line,line [IF string]
;LIST ,line
;LIST line,
;
LIST: CP 'O'
JR Z,LISTO
CALL DLPAIR
CALL NXT
CP TIF ;IF CLAUSE ?
LD A,0 ;INIT IF-CLAUSE LENGTH
JR NZ,LISTB
INC IY ;SKIP IF
CALL NXT ;SKIP SPACES (IF ANY)
EX DE,HL
PUSH IY
POP HL ;HL ADDRESSES IF CLAUSE
LD A,CR
PUSH BC
LD BC,256
CPIR ;LOCATE CR
LD A,C
CPL ;A = SUBSTRING LENGTH
POP BC
EX DE,HL
LISTB: LD E,A ;IF-CLAUSE LENGTH
LD A,B
OR C
JR NZ,LISTA
DEC BC
LISTA: EXX
LD IX,LISTON
LD BC,0 ;INDENTATION COUNT
EXX
LD A,20
;
LISTC: PUSH BC ;SAVE HIGH LINE NUMBER
PUSH DE ;SAVE IF-CLAUSE LENGTH
PUSH HL ;SAVE PROGRAM POINTER
EX AF,AF'
LD A,(HL)
OR A
JR Z,WARMNC
;
;CHECK IF PAST TERMINATING LINE NUMBER:
;
LD A,E ;A = IF-CLAUSE LENGTH
INC HL
LD E,(HL)
INC HL
LD D,(HL) ;DE = LINE NUMBER
DEC HL
DEC HL
PUSH DE ;SAVE LINE NUMBER
EX DE,HL
SCF
SBC HL,BC
EX DE,HL
POP DE ;RESTORE LINE NUMBER
WARMNC: JP NC,WARM
LD C,(HL) ;C = LINE LENGTH + 4
LD B,A ;B = IF-CLAUSE LENGTH
;
;CHECK IF "UNLISTABLE":
;
LD A,D
OR E
JP Z,CLOOP
;
;CHECK FOR IF CLAUSE:
;
INC HL
INC HL
INC HL ;HL ADDRESSES LINE TEXT
DEC C
DEC C
DEC C
DEC C ;C = LINE LENGTH
PUSH DE ;SAVE LINE NUMBER
PUSH HL ;SAVE LINE ADDRESS
XOR A ;A <- 0
CP B ;WAS THERE AN IF-CLAUSE
PUSH IY
POP DE ;DE ADDRESSES IF-CLAUSE
CALL NZ,SEARCH ;SEARCH FOR IF CLAUSE
POP HL ;RESTORE LINE ADDRESS
POP DE ;RESTORE LINE NUMBER
PUSH IY
CALL Z,LISTIT ;LIST IF MATCH
POP IY
;
EX AF,AF'
DEC A
CALL LTRAP
POP HL ;RESTORE POINTER
LD E,(HL)
LD D,0
ADD HL,DE ;ADDRESS NEXT LINE
POP DE ;RESTORE IF-CLAUSE LEN
POP BC ;RESTORE HI LINE NUMBER
JR LISTC
;
;RENUMBER
;RENUMBER start
;RENUMBER start,increment
;RENUMBER ,increment
;
RENUM: CALL CLEAR ;USES DYNAMIC AREA
CALL PAIR ;LOAD HL,BC
EXX
LD HL,(PAGE)
LD DE,(LOMEM)
RENUM1: LD A,(HL) ;BUILD TABLE
OR A
JR Z,RENUM2
INC HL
LD C,(HL) ;OLD LINE NUMBER
INC HL
LD B,(HL)
LD A,B
OR C
JP Z,CLOOP ;LINE NUMBER ZERO
EX DE,HL
LD (HL),C
INC HL
LD (HL),B
INC HL
EXX
PUSH HL
ADD HL,BC ;ADD INCREMENT
JP C,TOOBIG ;"Too big"
EXX
POP BC
LD (HL),C
INC HL
LD (HL),B
INC HL
EX DE,HL
DEC HL
DEC HL
XOR A
LD B,A
LD C,(HL)
ADD HL,BC ;NEXT LINE
EX DE,HL
PUSH HL
INC H
SBC HL,SP
POP HL
EX DE,HL
JR C,RENUM1 ;CONTINUE
CALL EXTERR ;"RENUMBER space"
DEFB REN
DEFB 8
DEFB 0
;
RENUM2: EX DE,HL
LD (HL),-1
INC HL
LD (HL),-1
LD DE,(LOMEM)
EXX
LD HL,(PAGE)
RENUM3: LD C,(HL)
LD A,C
OR A
JP Z,WARM
EXX
EX DE,HL
INC HL
INC HL
LD E,(HL)
INC HL
LD D,(HL)
INC HL
PUSH DE
EX DE,HL
LD (LINENO),HL
EXX
POP DE
INC HL
LD (HL),E ;NEW LINE NUMBER
INC HL
LD (HL),D
INC HL
DEC C
DEC C
DEC C
LD B,0
RENUM7: LD A,LINO
CPIR ;SEARCH FOR LINE NUMBER
JR NZ,RENUM3
PUSH BC
PUSH HL
PUSH HL
POP IY
EXX
CALL DECODE ;DECODE LINE NUMBER
EXX
LD B,H
LD C,L
LD HL,(LOMEM)
RENUM4: LD E,(HL) ;CROSS-REFERENCE TABLE
INC HL
LD D,(HL)
INC HL
EX DE,HL
OR A ;CLEAR CARRY
SBC HL,BC
EX DE,HL
LD E,(HL) ;NEW NUMBER
INC HL
LD D,(HL)
INC HL
JR C,RENUM4
EX DE,HL
JR Z,RENUM5 ;FOUND
CALL TELL
DEFM "Failed at "
DEFB 0
LD HL,(LINENO)
CALL PBCDL
CALL CRLF
JR RENUM6
RENUM5: POP DE
PUSH DE
DEC DE
CALL ENCODE ;RE-WRITE NUMBER
RENUM6: POP HL
POP BC
JR RENUM7
;
;AUTO
;AUTO start,increment
;AUTO start
;AUTO ,increment
;
AUTO: CALL PAIR
LD (AUTONO),HL
LD A,C
LD (INCREM),A
JR CLOOP0
;
;BAD
;NEW
;
BAD: CALL TELL ;"Bad program"
DEFB 3
DEFM "program"
DEFB CR
DEFB LF
DEFB 0
NEW: CALL NEWIT
JR CLOOP0
;
;OLD
;
OLD: LD HL,(PAGE)
PUSH HL
INC HL
INC HL
INC HL
LD BC,252