-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTEC-1ROM10.z80.lst
2423 lines (2421 loc) · 120 KB
/
TEC-1ROM10.z80.lst
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
0000 .ENGINE mycomputer
0000 ;
0000 TEC_1: EQU 1
0000 RC2014: EQU 0
0000 EXTENDED: EQU 0
0000 IF RC2014
; Configuration for RC2014
ROMSTART: EQU $8000
RAMSTART: EQU $8800
LOADER: EQU 0
BITBANG: EQU 0
0000 ENDIF
0000 IF TEC_1
0000 ; Configuration for TEC-1
0000 LOADER: EQU 0
0000 BITBANG: EQU 0
0000 ROMSTART: EQU $0000
0000 RAMSTART: EQU $0800
0000 ROMSIZE: EQU $0800
0000 RAMSIZE: EQU $0800
0000 ;TEC-1D SC 8k rom/ram
0000 ; ROMSTART .equ $0000
0000 ; RAMSTART .equ $2000
0000 ; ROMSIZE .equ 8192
0000 ; RAMSIZE .equ 8192
0000 ENDIF
0000 ; ROM code
0000 ; Targets:
0000 ; TEC-1,TEC-1D,TEC-1F,Southern Cross,RC2014
0000 ; Memory Map: 2k ROM/RAM, 8K ROM/RAM, RC2014
0000 ; Serial: Bit Bang, 6850 ACIA
0000 ;
0000 IF TEC_1
0000 IF BITBANG
;
; bit bang baud rate constants @ 4MHz
B300: EQU 0220H
B1200: EQU 0080H
B2400: EQU 003FH
B4800: EQU 001BH
B9600: EQU 000BH
;
0000 ELSE ;6850
0000 ;
0000 ;
0000 ; 6850 ACIA registers
0000 ;----------------------
0000 CONTROL: EQU $80 ;(write)
0000 STATUS: EQU $80 ;(read)
0000 TDR: EQU $81 ;(write)
0000 RDR: EQU $81 ;(read)
0000 ;
0000 ; control register bits
0000 ;----------------------
0000 ;
0000 ;clock divisor
0000 ;
0000 MRESET: EQU $03 ;master reset the ACIA
0000 ; DIV_0 .EQU $00 ;CLOCK/1
0000 ; DIV_16 .EQU $01 ;CLOCK/16
0000 DIV_64: EQU $02 ;CLOCK/64
0000 ;
0000 ; format select
0000 ;
0000 F7E2: EQU $00 ;7 data bits, EVEN parity, 2 stop bits (1+7+1+2= 11 bits)
0000 F7O2: EQU $04 ;7 data bits, ODD parity, 2 stop bits (1+7+1+2= 11 bits)
0000 F7E1: EQU $08 ;7 data bits, EVEN parity, 1 stop bit (1+7+1+1= 10 bits)
0000 F7O1: EQU $0C ;7 data bits, ODD parity, 1 stop bit (1+7+1+1= 10 bits)
0000 F8N2: EQU $10 ;8 data bits, NO parity, 2 stop bits (1+8+0+2= 11 bits)
0000 F8N1: EQU $14 ;8 data bits, NO parity, 1 stop bit (1+8+0+1= 10 bits)
0000 F8E1: EQU $18 ;8 data bits, EVEN parity, 1 stop bit (1+8+1+1= 11 bits)
0000 F8O1: EQU $1C ;8 data bits, ODD parity,1 stop bit (1+8+1+1= 11 bits)
0000 ;
0000 ; transmitter control
0000 ;
0000 RTSLID: EQU $00 ;RTS LOW, transmit interrupt disabled
0000 RTSLIE: EQU $20 ;RTS LOW, transmit interrupt enabled
0000 RTSHID: EQU $40 ;RTS HIGH, transmit interrupt disabled
0000 RTSLIDB: EQU $60 ;RTS LOW, transmit interrupt disabled and "break" transmitted
0000 ;
0000 ; receiver interrupt
0000 ;
0000 RIE: EQU $80 ;receiver interrupt enabled
0000 ;
0000 ; status register bits
0000 ;---------------------
0000 RDRF: EQU 0 ;receive data register full
0000 TDRE: EQU 1 ;transmit data register empty
0000 DCD: EQU 2 ;data carrier detect
0000 CTS: EQU 3 ;clear to send
0000 FE: EQU 4 ;framing error
0000 OVRN: EQU 5 ;overrun
0000 PE: EQU 6 ;parity error
0000 IRQ: EQU 7 ;interrupt request
0000 ;
0000 ENDIF
0000 ENDIF
0000 ;
0000 ; I/O port addresses
0000 ;
0000 IF TEC_1
0000 KEYBUF: EQU 00H ;MM74C923N KEYBOARD ENCODER
0000 SCAN: EQU 01H ;DISPLAY SCAN LATCH
0000 DISPLY: EQU 02H ;DISPLAY LATCH
0000 PORT3: EQU 03H ;ST3 (8X8), STROBE (RELAY BOARD) DATLATCH (DAT BOARD)
0000 PORT4: EQU 04H ;ST4 (8X8), LCD "E" (DAT BOARD)
0000 PORT5: EQU 05H
0000 PORT6: EQU 06H
0000 PORT7: EQU 07H ;ENABLE/DISABLE SINGLE STEPPER (IF INSTALLED)
0000 ELSE ;SC
IO0: EQU 80H ;IO PORT 0
IO1: EQU 81H ;IO PORT 1
IO2: EQU 82H ;IO PORT 2
IO3: EQU 83H ;IO PORT 3
DISPLY: EQU 84H ;DISPLAY LATCH
SCAN: EQU 85H ;DISPLAY SCAN LATCH
KEYBUF: EQU 86H ;KEYBOARD BUFFER
IO7: EQU 87H ;ENABLE/DISABLE SINGLE STEPPER (IF INSTALLED)
0000 ENDIF
0000 ;
0000 ; ASCII codes
0000 ESC: EQU 1BH
0000 CR: EQU 0DH
0000 LF: EQU 0AH
0000 ;
0000 .ORG ROMSTART
0000 ;reset
0000 RSTVEC:
0000 C3 96 00 JP RESET
0003 ;
0003 RST1:
0008 .ORG ROMSTART+$08
0008 2E 01 LD l,1
000A C3 8B 00 JP ISR
000D ;
000D RST2:
0010 .ORG ROMSTART+$10
0010 2E 02 LD l,2
0012 C3 8B 00 JP ISR
0015 ;
0015 RST3:
0018 .ORG ROMSTART+$18
0018 2E 03 LD l,3
001A C3 8B 00 JP ISR
001D ;
001D RST4:
0020 .ORG ROMSTART+$20
0020 2E 04 LD l,4
0022 C3 8B 00 JP ISR
0025 ;
0025 RST5:
0028 .ORG ROMSTART+$28
0028 2E 05 LD l,5
002A C3 8B 00 JP ISR
002D ;
002D RST6:
0030 .ORG ROMSTART+$30
0030 2E 06 LD l,6
0032 C3 8B 00 JP ISR
0035 ;
0035 ;RST 7 Interrupt
0038 .ORG ROMSTART+$38
0038 ;
0038 IF BITBANG
;
LD l,7
JP ISR
0038 ELSE
0038 ;
0038 C9 RET
0039 ;
0039 ENDIF
0039 ;
0040 .ORG ROMSTART+$40
0040 ;
0040 ;hexadecimal to 7 segment display code table
0040 IF TEC_1
0040 ;
0040 SEVENSEGMENT:
0040 EB 28 CD AD DB 0EBH,28H,0CDH,0ADH ;0,1,2,3
0044 2E A7 E7 29 DB 2EH,0A7H,0E7H,29H ;4,5,6,7
0048 EF 2F 6F E6 DB 0EFH,2FH,6FH,0E6H ;8,9,A,B
004C C3 EC C7 47 DB 0C3H,0ECH,0C7H,47H ;C,D,E,F
0050 ELSE ;SC
;
SEVENSEGMENT:
DB 3FH,06H,5BH,4FH ;0,1,2,3
DB 66H,6DH,7DH,07H ;4,5,6,7
DB 7FH,6FH,77H,7CH ;8,9,A,B
DB 39H,5EH,79H,71H ;C,D,E,F
0050 ENDIF
0050 ;
0050 ;
0050 ;---------------
0050 ; BIT TIME DELAY
0050 ;---------------
0050 ;DELAY FOR ONE SERIAL BIT TIME
0050 ;ENTRY : HL = DELAY TIME
0050 ; NO REGISTERS MODIFIED
0050 ;
0050 PWRUP:
0050 21 00 20 LD hl,$2000
0053 BITIME:
0053 E5 PUSH HL
0054 D5 PUSH DE
0055 11 01 00 LD DE,0001H
0058 BITIM1:
0058 ED 52 SBC HL,DE
005A D2 58 00 JP NC,BITIM1
005D D1 POP DE
005E E1 POP HL
005F INTRET:
005F C9 RET
0060 ;
0060 ;RST 8 Non Maskable Interrupt
0066 .ORG ROMSTART+$66
0066 ; PUSH HL
0066 ; LD HL,(NMIVEC)
0066 ; JP (HL)
0066 ;
0066 2E 08 LD l,8
0068 C3 8B 00 JP ISR
006B ;
006B ;
006B IF BITBANG
;
;------------------------
; SERIAL TRANSMIT ROUTINE
;------------------------
;TRANSMIT BYTE SERIALLY ON DOUT
;
; ENTRY : A = BYTE TO TRANSMIT
; EXIT : NO REGISTERS MODIFIED
;
;
TXCHAR:
TXDATA:
PUSH AF
PUSH BC
PUSH HL
LD HL,(BAUD)
LD C,A
;
; TRANSMIT START BIT
;
XOR A
OUT (SCAN),A
CALL BITIME
;
; TRANSMIT DATA
;
LD B,08H
RRC C
NXTBIT:
RRC C ;SHIFT BITS TO D6,
LD A,C ;LSB FIRST AND OUTPUT
AND 40H ;THEM FOR ONE BIT TIME.
OUT (SCAN),A
CALL BITIME
DJNZ NXTBIT
;
; SEND STOP BITS
;
LD A,40H
OUT (SCAN),A
CALL BITIME
CALL BITIME
POP HL
POP BC
POP AF
RET
;-----------------------
; SERIAL RECEIVE ROUTINE
;-----------------------
;RECEIVE SERIAL BYTE FROM DIN
;
; ENTRY : NONE
; EXIT : A= RECEIVED BYTE IF CARRY CLEAR
;
; REGISTERS MODIFIED A AND F
;
RXCHAR:
RXDATA:
PUSH BC
PUSH HL
;
; WAIT FOR START BIT
;
RXDAT1: IN A,(KEYBUF)
BIT 7,A
JR NZ,RXDAT1 ;NO START BIT
;
; DETECTED START BIT
;
LD HL,(BAUD)
SRL H
RR L ;DELAY FOR HALF BIT TIME
CALL BITIME
IN A,(KEYBUF)
BIT 7,A
JR NZ,RXDAT1 ;START BIT NOT VALID
;
; DETECTED VALID START BIT,READ IN DATA
;
LD B,08H
RXDAT2:
LD HL,(BAUD)
CALL BITIME ;DELAY ONE BIT TIME
IN A,(KEYBUF)
RL A
RR C ;SHIFT BIT INTO DATA REG
DJNZ RXDAT2
LD A,C
OR A ;CLEAR CARRY FLAG
POP HL
POP BC
RET
;
006B ELSE ;6850
006B ;
006B ; transmit a character in a
006B ;--------------------------
006B TXDATA:
006B TXCHAR:
006B C5 PUSH bc
006C 47 LD b,a ;save the character for later
006D TXCHAR1:
006D DB 80 IN a,(STATUS) ;get the ACIA status
006F CB 4F BIT 1,a
0071 ; bit TDRE,a ;is the TDRE bit high?
0071 28 FA JR z,TxChar1 ;no, the TDR is not empty
0073 78 LD a,b ;yes, get the character
0074 D3 81 OUT (TDR),a ;and put it in the TDR
0076 C1 POP bc
0077 C9 RET
0078 ;
0078 ; receive a character in a
0078 ;---------------------------------
0078 RXDATA:
0078 RXCHAR:
0078 DB 80 IN a,(STATUS) ;get the ACIA status
007A CB 47 BIT 0,a
007C ; bit RDRF,a ;is the RDRF bit high?
007C 28 FA JR z,RxChar ;no, the RDR is empty
007E DB 81 IN a,(RDR) ;yes, read the received char
0080 C9 RET
0081 ENDIF
0081 ;
0081 IF LOADER
; .ORG ROMSTART + $0700
;-----------------------
; RECEIVE INTEL HEX FILE
;-----------------------
INTELH:
LD IX,BUF
;
; WAIT FOR RECORD MARK
;
INTEL1:
XOR A
LD (IX+3),A ;CLEAR CHECKSUM
CALL RXDATA ;WAIT FOR THE RECORD MARK
CP ":" ;TO BE TRANSMITTED
JR NZ,INTEL1 ;NOT RECORD MARK
;
; GET RECORD LENGTH
;
CALL GETBYT
LD (IX+0),A ;NUMBER OF DATA BYTES
;
; GET ADDRESS FIELD
;
CALL GETBYT
LD (IX+2),A ;LOAD ADDRESS HIGH BYTE
CALL GETBYT
LD (IX+1),A ;LOAD ADDRESS LOW BYTE
;
; GET RECORD TYPE
;
CALL GETBYT
JR NZ,INTEL4 ;END OF FILE RECORD
;
; READ IN THE DATA
;
LD B,(IX+0) ;NUMBER OF DATA BYTES
LD H,(IX+2) ;LOAD ADDRESS HIGH BYTE
LD L,(IX+1) ;LOAD ADDRESS LOW BYTE
;
INTEL2:
CALL GETBYT ;GET DATA BYTE
LD (HL),A ;STORE DATA BYTE
INC HL
DJNZ INTEL2 ;LOAD MORE BYTES
;
; GET CHECKSUM AND COMPARE
;
LD A,(IX+3) ;CONVERT CHECKSUM TO
NEG ;TWO'S COMPLEMENT
LD (IX+4),A ;SAVE COMPUTED CHECKSUM
CALL GETBYT
LD (IX+3),A ;SAVE RECORD CHECKSUM
CP (IX+4) ;COMPARE CHECKSUM
JR Z,INTEL1 ;CHECKSUM OK,NEXT RECORD
RET ;NZ=CHECKSUM ERROR
;
; END OF FILE RECORD
;
INTEL4:
LD A,(IX+3) ;CONVERT CHECKSUM TO
NEG ;TWO'S COMPLEMENT
LD (IX+4),A ;SAVE COMPUTED CHECKSUM
CALL GETBYT
LD (IX+3),A ;SAVE EOF CHECKSUM
CP (IX+4) ;COMPARE CHECKSUM
RET ;NZ=CHECKSUM ERROR
;--------------------------
; GET BYTE FROM SERIAL PORT
;--------------------------
GETBYT:
PUSH BC
CALL RXDATA
BIT 6,A
JR Z,GETBT1
ADD A,09H
GETBT1:
AND 0FH
SLA A
SLA A
SLA A
SLA A
LD C,A
;
; GET LOW NYBBLE
;
CALL RXDATA
BIT 6,A
JR Z,GETBT2
ADD A,09H
GETBT2: AND 0FH
OR C
LD B,A
ADD A,(IX+3)
LD (IX+3),A ;ADD TO CHECKSUM
LD A,B
AND A ;CLEAR CARRY
POP BC
RET
0081 ENDIF
0081 ;
0081 ; in this example code just wait for an INTEL Hex file download
0081 ;just going to send a char to let you know I'm here
0081 IF LOADER
;
LOAD:
LD a,"L" ; L for load
CALL TxChar
CALL INTELH
JP z,RAMSTART ;assume the downloaded code starts here
LD a,"0" ;0 is false
CALL TxChar
JR load ;if at first you don't succeed...
0081 ENDIF
0081 ;
0081 GETCHAR:
0081 2A 18 0A LD HL,(GETCVEC)
0084 E9 JP (HL)
0085 ;
0085 PUTCHAR:
0085 E5 PUSH HL
0086 2A 1A 0A LD HL,(PUTCVEC)
0089 E3 EX (SP),HL
008A C9 RET
008B ;
008B ISR:
008B 26 00 LD h,0
008D 22 92 0C LD (vIntID),hl
0090 CD BD 03 CALL enter
0093 5A 00 .CSTR "Z"
0095 C9 RET
0096 ;
0096 RESET:
0096 31 00 0A LD SP,stack
0099 21 5F 00 LD HL,IntRet
009C 22 06 0A LD (RST08),HL
009F 22 08 0A LD (RST10),HL
00A2 22 0A 0A LD (RST18),HL
00A5 22 0C 0A LD (RST20),HL
00A8 22 0E 0A LD (RST28),HL
00AB 22 10 0A LD (RST30),HL
00AE 22 14 0A LD (INTVEC),HL
00B1 22 16 0A LD (NMIVEC),HL
00B4 ;
00B4 21 78 00 LD HL,RXDATA
00B7 22 18 0A LD (GETCVEC),HL
00BA 21 6B 00 LD HL,TXDATA
00BD 22 1A 0A LD (PUTCVEC),HL
00C0 ;
00C0 IF TEC_1
00C0 IF BITBANG = 0
00C0 ;
00C0 3E 03 LD a,MRESET
00C2 D3 80 OUT (CONTROL),a ;reset the ACIA
00C4 ;
00C4 ENDIF
00C4 ENDIF
00C4 ;
00C4 CD 50 00 CALL PWRUP
00C7 ED 56 IM 1
00C9 FB EI
00CA ;
00CA IF TEC_1
00CA IF BITBANG
;
;inline serial initialisation
LD A,$40
LD C,SCAN
OUT (C),A
LD HL,B4800
LD (BAUD),HL
;
00CA ELSE ;6850
00CA ;
00CA 3E 12 LD a,RTSLID+F8N2+DIV_64
00CC D3 80 OUT (CONTROL),a ;initialise ACIA 8 bit word, No parity 2 stop divide by 64 for 115200 baud
00CE ;
00CE ENDIF
00CE ENDIF
00CE ;
00CE ;
00CE ;
00CE C3 18 02 JP start ; into #180 of the prog
00D1 ;
00D1 ; *************************************************************************
00D1 ;
00D1 ; MINT 2.0 Minimal Interpreter for the Z80
00D1 ;
00D1 ; John Hardy and Ken Boak
00D1 ; incorporates bit-bang serial routines by Craig Jones
00D1 ;
00D1 ; GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007
00D1 ;
00D1 ; see the LICENSE file in this repo for more information
00D1 ;
00D1 ; *****************************************************************************
00D1 TRUE: EQU -1
00D1 FALSE: EQU 0
00D1 UNLIMITED: EQU -1
00D1 CTRL_C: EQU 3
00D1 CTRL_E: EQU 5
00D1 CTRL_H: EQU 8
00D1 CTRL_L: EQU 12
00D1 CTRL_R: EQU 18
00D1 CTRL_S: EQU 19
00D1 BSLASH: EQU $5c
00D1 .macro LITDAT,len
00D1 ;
00D1 db len
00D1 .endm
00D1
00D1 .macro REPDAT,len,data
00D1 ;
00D1 db (len | $80)
00D1 db data
00D1 .endm
00D1
00D1 .macro ENDDAT,
00D1 ;
00D1 db 0
00D1 .endm
00D1
00D1 ; **************************************************************************
00D1 ; Page 0 Initialisation
00D1 ; **************************************************************************
0180 .ORG ROMSTART + $180 ; 0+180 put mint code from here
0180 ; **************************************************************************
0180 ; Macros must be written in Mint and end with ;
0180 ; this code must not span pages
0180 ; **************************************************************************
0180 MACROS:
0180 REEDIT_:
0180 2F 7A 2F 5A 3B DB "/z/Z;" ; remembers last line edited
0185 EDIT_:
0185 60 3F 60 2F 4B 2F 50 2F 5A 3B 00 .CSTR "`?`/K/P/Z;"
0190 LIST_:
0190 2F 4E 32 36 28 2F 69 36 35 2B 2F 5A 2F 6B 30 3E 28 2F 4E 29 29 2F 50 3B 00 .CSTR "/N26(/i65+/Z/k0>(/N))/P;"
01A9 PRINTSTACK_:
01A9 60 3D 3E 20 60 2F 73 32 2D 20 2F 44 31 2D 28 22 2C 32 2D 29 27 2F 4E 2F 50 3B 00 .CSTR "`=> `/s2- /D1-(",$22,",2-)'/N/P;"
01C4 IOPCODES:
01C4 ;*Macro unroll: LITDAT 15
01C4 0F DB 15
01C5 1D DB lsb(bang_) ; !
01C6 71 DB lsb(dquote_) ; "
01C7 EE DB lsb(hash_) ; #
01C8 92 DB lsb(dollar_) ; $
01C9 79 DB lsb(percent_) ; %
01CA 2D DB lsb(amper_) ; &
01CB 00 DB lsb(quote_) ; '
01CC E9 DB lsb(lparen_) ; (
01CD E0 DB lsb(rparen_) ; )
01CE F0 DB lsb(star_) ; *
01CF 4F DB lsb(plus_) ; +
01D0 6B DB lsb(comma_) ; ,
01D1 96 DB lsb(minus_) ; -
01D2 60 DB lsb(dot_) ; .
01D3 F2 DB lsb(slash_) ; /
01D4 ;*Macro unroll: REPDAT 10, lsb(num_) ; 10 x repeat lsb of add to the num routine
01D4 8A DB (10 | $80) ; 10 x repeat lsb of add to the num routine
01D5 DD DB lsb(num_)
01D6 ;*Macro unroll: LITDAT 7
01D6 07 DB 7
01D7 E6 DB lsb(colon_) ; :
01D8 80 DB lsb(semi_) ; ;
01D9 BA DB lsb(lt_) ; <
01DA AB DB lsb(eq_) ; =
01DB B6 DB lsb(gt_) ; >
01DC EC DB lsb(question_) ; ?
01DD 01 DB lsb(at_) ; @
01DE ;*Macro unroll: REPDAT 26, lsb(call_) ; call a command a, B ....Z
01DE 9A DB (26 | $80) ; call a command a, B ....Z
01DF 56 DB lsb(call_)
01E0 ;*Macro unroll: LITDAT 6
01E0 06 DB 6
01E1 D4 DB lsb(lbrack_) ; [
01E2 03 DB lsb(bslash_) ; \
01E3 E3 DB lsb(rbrack_) ; ]
01E4 41 DB lsb(caret_) ; ^
01E5 01 DB lsb(underscore_) ; _
01E6 C5 DB lsb(grave_) ; ` ; for printing `hello`
01E7 ;*Macro unroll: REPDAT 26, lsb(var_) ; a b c .....z
01E7 9A DB (26 | $80) ; a b c .....z
01E8 05 DB lsb(var_)
01E9 ;*Macro unroll: LITDAT 4
01E9 04 DB 4
01EA 87 DB lsb(lbrace_) ; {
01EB 38 DB lsb(pipe_) ; |
01EC 8B DB lsb(rbrace_) ; }
01ED 4A DB lsb(tilde_) ; ~ ( a b c -- b c a ) rotate
01EE IALTCODES:
01EE ;*Macro unroll: LITDAT 26
01EE 1A DB 26
01EF 00 DB lsb(alloc_) ;A allocate some heap memory
01F0 09 DB lsb(aNop_) ;B
01F1 34 DB lsb(printChar_) ;C print a char
01F2 23 DB lsb(depth_) ;D depth of stack
01F3 3B DB lsb(else_) ;E else
01F4 31 DB lsb(falsex_) ;F false condition
01F5 53 DB lsb(go_) ;G go execute mint code
01F6 09 DB lsb(aNop_) ;H
01F7 70 DB lsb(inPort_) ;I input from port
01F8 09 DB lsb(aNop_) ;J
01F9 68 DB lsb(key_) ;K read a char from input
01FA 09 DB lsb(aNop_) ;L
01FB 09 DB lsb(aNop_) ;M
01FC 7A DB lsb(newln_) ;N prints a newline to output
01FD 7F DB lsb(outPort_) ;O output to port
01FE 4E DB lsb(prompt_) ;P print MINT prompt
01FF 09 DB lsb(aNop_) ;Q
0200 09 DB lsb(aNop_) ;R
0201 0B DB lsb(arrSize_) ;S array size
0202 88 DB lsb(truex_) ;T true condition
0203 8B DB lsb(unlimit_) ;U unlimited loop
0204 90 DB lsb(varAccess_) ;V address of last access
0205 13 DB lsb(while_) ;W conditional break from loop
0206 41 DB lsb(exec_) ;X execute machine code
0207 09 DB lsb(aNop_) ;Y
0208 49 DB lsb(editDef_) ;Z edit line
0209 ;*Macro unroll: ENDDAT
0209 00 DB 0
020A BACKSPACE:
020A 79 LD a,c
020B B0 OR b
020C 28 27 JR z,interpret2
020E 0B DEC bc
020F CD 92 03 CALL printStr
0212 08 20 08 00 .CSTR "\b \b"
0216 18 1D JR interpret2
0218 START:
0218 31 00 0A LD SP,DSTACK ; start of MINT
021B CD DE 02 CALL init ; setups
021E CD 92 03 CALL printStr ; prog count to stack, put code line 235 on stack then call print
0221 4D 49 4E 54 32 2E 30 0D 0A 00 .CSTR "MINT2.0\r\n"
022B INTERPRET:
022B CD 82 03 CALL prompt
022E 01 00 00 LD bc,0 ; load bc with offset into TIB, decide char into tib or execute or control
0231 ED 43 7C 0C LD (vTIBPtr),bc
0235 INTERPRET2: ; calc nesting (a macro might have changed it)
0235 1E 00 LD E,0 ; initilize nesting value
0237 C5 PUSH bc ; save offset into TIB,
0238 ; bc is also the count of chars in TIB
0238 21 00 08 LD hl,TIB ; hl is start of TIB
023B 18 06 JR interpret4
023D INTERPRET3:
023D 7E LD a,(hl) ; A = char in TIB
023E 23 INC hl ; inc pointer into TIB
023F 0B DEC bc ; dec count of chars in TIB
0240 CD 5B 03 CALL nesting ; update nesting value
0243 INTERPRET4:
0243 79 LD a,C ; is count zero?
0244 B0 OR B
0245 20 F6 JR NZ,interpret3 ; if not loop
0247 C1 POP bc ; restore offset into TIB
0248 WAITCHAR:
0248 CD 81 00 CALL getchar ; loop around waiting for character from serial port
024B FE 20 CP $20 ; compare to space
024D 30 39 JR NC,waitchar1 ; if >= space, if below 20 set cary flag
024F FE 00 CP $0 ; is it end of string? null end of string
0251 28 59 JR Z,waitchar4
0253 FE 0D CP "\r" ; carriage return? ascii 13
0255 28 3F JR Z,waitchar3 ; if anything else its macro/control
0257 FE 08 CP CTRL_H
0259 28 AF JR z,backSpace
025B 16 01 LD d,msb(macros)
025D FE 05 CP CTRL_E
025F 1E 85 LD e,lsb(edit_)
0261 28 14 JR z,macro
0263 FE 12 CP CTRL_R
0265 1E 80 LD e,lsb(reedit_)
0267 28 0E JR z,macro
0269 FE 0C CP CTRL_L
026B 1E 90 LD e,lsb(list_)
026D 28 08 JR z,macro
026F FE 13 CP CTRL_S
0271 1E A9 LD e,lsb(printStack_)
0273 28 02 JR z,macro
0275 18 BE JR interpret2
0277 MACRO:
0277 ED 43 7C 0C LD (vTIBPtr),bc
027B D5 PUSH de
027C CD BD 03 CALL ENTER ;mint go operation and jump to it
027F 2F 47 00 .CSTR "/G"
0282 ED 4B 7C 0C LD bc,(vTIBPtr)
0286 18 AD JR interpret2
0288 WAITCHAR1:
0288 21 00 08 LD hl,TIB
028B 09 ADD hl,bc
028C 77 LD (hl),A ; store the character in textbuf
028D 03 INC bc
028E CD 85 00 CALL putchar ; echo character to screen
0291 CD 5B 03 CALL nesting
0294 18 B2 JR waitchar ; wait for next character
0296 WAITCHAR3:
0296 21 00 08 LD hl,TIB
0299 09 ADD hl,bc
029A 36 0D LD (hl),"\r" ; store the crlf in textbuf
029C 23 INC hl
029D 36 0A LD (hl),"\n"
029F 23 INC hl ; ????
02A0 03 INC bc
02A1 03 INC bc
02A2 CD 8B 03 CALL crlf ; echo character to screen
02A5 7B LD a,E ; if zero nesting append and ETX after \r
02A6 B7 OR A
02A7 20 9F JR NZ,waitchar
02A9 36 03 LD (hl),$03 ; store end of text ETX in text buffer
02AB 03 INC bc
02AC WAITCHAR4:
02AC ED 43 7C 0C LD (vTIBPtr),bc
02B0 01 00 08 LD bc,TIB ; Instructions stored on heap at address HERE, we pressed enter
02B3 0B DEC bc
02B4 NEXT:
02B4 03 INC bc ; Increment the IP
02B5 0A LD a,(bc) ; Get the next character and dispatch
02B6 B7 OR a ; is it NUL?
02B7 28 0F JR z,exit
02B9 FE 03 CP CTRL_C
02BB 28 15 JR z,etx
02BD D6 21 SUB "!"
02BF 38 F3 JR c,NEXT
02C1 6F LD L,A ; Index into table
02C2 26 0B LD H,msb(opcodes) ; Start address of jump table
02C4 6E LD L,(hl) ; get low jump address
02C5 26 04 LD H,msb(page4) ; Load H with the 1st page address
02C7 E9 JP (hl) ; Jump to routine
02C8 EXIT:
02C8 03 INC bc ; store offests into a table of bytes, smaller
02C9 50 59 LD de,bc
02CB CD AD 03 CALL rpop ; Restore Instruction pointer
02CE 44 4D LD bc,hl
02D0 EB EX de,hl
02D1 E9 JP (hl)
02D2 ETX:
02D2 21 00 F6 LD hl,-DSTACK ; check if stack pointer is underwater
02D5 39 ADD hl,SP
02D6 30 03 JR NC,etx1
02D8 31 00 0A LD SP,DSTACK
02DB ETX1:
02DB C3 2B 02 JP interpret
02DE INIT:
02DE DD 21 80 09 LD IX,RSTACK
02E2 FD 21 B4 02 LD IY,NEXT ; IY provides a faster jump to NEXT
02E6 21 00 0C LD hl,vars
02E9 54 5D LD de,hl
02EB 13 INC de
02EC 36 00 LD (hl),0
02EE 01 9C 00 LD bc,VARS_SIZE * 3 ; init vars, defs and altVars
02F1 ED B0 LDIR
02F3 21 00 0A LD hl,dStack
02F6 22 8C 0C LD (vStkStart),hl
02F9 21 41 00 LD hl,65
02FC 22 9A 0C LD (vLastDef),hl
02FF 21 A0 0C LD hl,HEAP
0302 22 76 0C LD (vHeapPtr),hl
0305 INITOPS:
0305 21 C4 01 LD hl,iOpcodes
0308 11 00 0B LD de,opcodes
030B 01 78 00 LD bc,$80-32-1-1+26
030E INITOPS1:
030E 7E LD a,(hl)
030F 23 INC hl
0310 CB 27 SLA A
0312 C8 RET Z
0313 38 09 JR C,initOps2
0315 CB 3F SRL A
0317 4F LD C,A
0318 06 00 LD B,0
031A ED B0 LDIR
031C 18 F0 JR initOps1
031E INITOPS2:
031E CB 3F SRL A
0320 47 LD B,A
0321 7E LD a,(hl)
0322 23 INC hl
0323 INITOPS2A:
0323 12 LD (de),A
0324 13 INC de
0325 10 FC DJNZ initOps2a
0327 18 E5 JR initOps1
0329 LOOKUPREF0:
0329 21 34 0C LD hl,defs
032C D6 41 SUB "A"
032E 18 02 JR lookupRef1
0330 LOOKUPREF:
0330 D6 61 SUB "a"
0332 LOOKUPREF1:
0332 87 ADD a,a
0333 85 ADD a,l
0334 6F LD l,a
0335 3E 00 LD a,0
0337 8C ADC a,h
0338 67 LD h,a
0339 AF XOR a
033A B3 OR e ; sets Z flag if A-Z
033B C9 RET
033C PRINTHEX:
033C ; Display hl as a 16-bit number in hex.
033C C5 PUSH bc ; preserve the IP
033D 7C LD a,H
033E CD 47 03 CALL printhex2
0341 7D LD a,L
0342 CD 47 03 CALL printhex2
0345 C1 POP bc
0346 C9 RET
0347 PRINTHEX2:
0347 4F LD C,A
0348 1F RRA
0349 1F RRA
034A 1F RRA
034B 1F RRA
034C CD 50 03 CALL printhex3
034F 79 LD a,C
0350 PRINTHEX3:
0350 E6 0F AND 0x0F
0352 C6 90 ADD a,0x90
0354 27 DAA
0355 CE 40 ADC a,0x40
0357 27 DAA
0358 C3 85 00 JP putchar
035B ; **************************************************************************
035B ; calculate nesting value
035B ; A is char to be tested,
035B ; E is the nesting value (initially 0)
035B ; E is increased by ( and [
035B ; E is decreased by ) and ]
035B ; E has its bit 7 toggled by `
035B ; limited to 127 levels
035B ; **************************************************************************
035B NESTING:
035B FE 60 CP "`"
035D 20 05 JR NZ,nesting1
035F 3E 80 LD a,$80
0361 AB XOR e
0362 5F LD e,a
0363 C9 RET
0364 NESTING1:
0364 CB 7B BIT 7,E
0366 C0 RET NZ
0367 FE 3A CP ":"
0369 28 08 JR Z,nesting2
036B FE 5B CP "["
036D 28 04 JR Z,nesting2
036F FE 28 CP "("
0371 20 02 JR NZ,nesting3
0373 NESTING2:
0373 1C INC E
0374 C9 RET
0375 NESTING3:
0375 FE 3B CP ";"
0377 28 07 JR Z,nesting4
0379 FE 5D CP "]"
037B 28 03 JR Z,nesting4
037D FE 29 CP ")"
037F C0 RET NZ
0380 NESTING4:
0380 1D DEC E
0381 C9 RET
0382 PROMPT:
0382 CD 92 03 CALL printStr
0385 0D 0A 3E 20 00 .CSTR "\r\n> "
038A C9 RET
038B CRLF:
038B CD 92 03 CALL printStr
038E 0D 0A 00 .CSTR "\r\n"
0391 C9 RET
0392 PRINTSTR:
0392 E3 EX (SP),hl ; swap
0393 CD 9D 03 CALL putStr
0396 23 INC hl ; inc past null
0397 E3 EX (SP),hl ; put it back
0398 C9 RET
0399 PUTSTR0:
0399 CD 85 00 CALL putchar
039C 23 INC hl
039D PUTSTR:
039D 7E LD a,(hl)
039E B7 OR A
039F 20 F8 JR NZ,putStr0
03A1 C9 RET
03A2 RPUSH:
03A2 DD 2B DEC IX
03A4 DD 74 00 LD (IX+0),H
03A7 DD 2B DEC IX
03A9 DD 75 00 LD (IX+0),L
03AC C9 RET
03AD RPOP:
03AD DD 6E 00 LD L,(IX+0)
03B0 DD 23 INC IX
03B2 DD 66 00 LD H,(IX+0)
03B5 DD 23 INC IX
03B7 RPOP2:
03B7 C9 RET
03B8 WRITECHAR:
03B8 77 LD (hl),A
03B9 23 INC hl
03BA C3 85 00 JP putchar
03BD ENTER:
03BD 60 69 LD hl,bc
03BF CD A2 03 CALL rpush ; save Instruction Pointer
03C2 C1 POP bc
03C3 0B DEC bc
03C4 FD E9 JP (iy)
03C6 CARRY:
03C6 21 00 00 LD hl,0
03C9 CB 15 RL l
03CB 22 6C 0C LD (vCarry),hl
03CE FD E9 JP (iy)
03D0 SETBYTEMODE:
03D0 3E FF LD a,$FF
03D2 18 01 JR assignByteMode
03D4 RESETBYTEMODE:
03D4 AF XOR a
03D5 ASSIGNBYTEMODE:
03D5 32 6A 0C LD (vByteMode),a
03D8 32 6B 0C LD (vByteMode+1),a
03DB FD E9 JP (iy)
03DD FALSE_:
03DD 21 00 00 LD hl,FALSE
03E0 18 03 JR true1
03E2 TRUE_:
03E2 21 FF FF LD hl,TRUE
03E5 TRUE1:
03E5 E5 PUSH hl
03E6 FD E9 JP (iy)
03E8 ; **********************************************************************
03E8 ; Page 4 primitive routines
03E8 ; **********************************************************************
03E8 ALIGN $100
0400 PAGE4:
0400 QUOTE_: ; Discard the top member of the stack
0400 E1 POP hl
0401 AT_:
0401 UNDERSCORE_:
0401 FD E9 JP (iy)
0403 BSLASH_:
0403 18 CB JR setByteMode
0405 VAR_:
0405 0A LD a,(bc)
0406 21 00 0C LD hl,vars
0409 CD 30 03 CALL lookupRef
040C VAR1:
040C 22 9C 0C LD (vPointer),hl
040F 16 00 LD d,0
0411 5E LD e,(hl)
0412 3A 6A 0C LD a,(vByteMode)
0415 3C INC a ; is it byte?
0416 28 02 JR z,var2
0418 23 INC hl
0419 56 LD d,(hl)
041A VAR2:
041A D5 PUSH de
041B 18 B7 JR resetByteMode