Intial work on a FORTH interpreter
This commit is contained in:
parent
6fb93429cc
commit
e8fa4a2d95
@ -14,14 +14,46 @@
|
||||
; You should have received a copy of the GNU General Public License
|
||||
; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
R1 EQU 1
|
||||
R2 EQU 2
|
||||
R7 EQU 7
|
||||
R0 EQU $00
|
||||
R1 EQU $01
|
||||
R2 EQU $02
|
||||
R3 EQU $03
|
||||
R4 EQU $04
|
||||
R5 EQU $05
|
||||
R7 EQU $07
|
||||
RE EQU $0D
|
||||
|
||||
STACK EQU 7F6FH
|
||||
CALL EQU 8ADBH
|
||||
RETURN EQU 8AEDH
|
||||
|
||||
MON_INPUT EQU 8005H
|
||||
MON_OUTSTR EQU 8526H
|
||||
|
||||
CPU 1802
|
||||
; ORG $0000
|
||||
|
||||
; Setup code to initialize the stack and SCRT registers
|
||||
; SETUP R2 (Stack)
|
||||
LDI HIGH STACK
|
||||
PHI R2
|
||||
LDI LOW STACK
|
||||
PLO R2 ;STACK = 7F6FH
|
||||
SEX R2 ;X = 2
|
||||
|
||||
; SETUP R4 (CALL PC)
|
||||
LDI HIGH CALL
|
||||
PHI R4
|
||||
LDI LOW CALL
|
||||
PLO R4 ;R4 = PC FOR CALL SUBROUTINE
|
||||
|
||||
LDI HIGH RETURN
|
||||
PHI R5
|
||||
LDI LOW RETURN
|
||||
PLO R5 ;R5 = PC FOR RETURN SUBROUTINE
|
||||
|
||||
ORG 0000H
|
||||
BEGIN
|
||||
SEQ ; announce running
|
||||
SEX R7
|
||||
|
||||
INKEY
|
||||
BN4 INKEY
|
||||
REQ
|
||||
@ -44,11 +76,23 @@ DECR
|
||||
|
||||
DONE
|
||||
REQ
|
||||
; LOAD R7, NullByte
|
||||
; SEP R4
|
||||
; DW MON_OUTSTR
|
||||
LOAD R7, NOLED
|
||||
OUT 4
|
||||
SEP R1
|
||||
LOAD R7, BYETXT
|
||||
SEP R4
|
||||
DW MON_OUTSTR
|
||||
LDI $8B
|
||||
PHI R0
|
||||
LDI $5E
|
||||
PLO R0
|
||||
SEX R0
|
||||
SEP R0
|
||||
|
||||
ALLLED BYTE 255
|
||||
ALLLED BYTE $FF
|
||||
NOLED BYTE 0
|
||||
|
||||
BYETXT BYTE "$", 0
|
||||
NullByte BYTE 0
|
||||
END
|
||||
|
95
src/z80/forth.asm
Normal file
95
src/z80/forth.asm
Normal file
@ -0,0 +1,95 @@
|
||||
; forth.asm - a TIL implementation of FORTH for Z80
|
||||
; Copyright (C) 2023 William R. Moore
|
||||
;
|
||||
; This program is free software: you can redistribute it and/or modify
|
||||
; it under the terms of the GNU General Public License as published by
|
||||
; the Free Software Foundation, either version 3 of the License, or
|
||||
; (at your option) any later version.
|
||||
;
|
||||
; This program is distributed in the hope that it will be useful,
|
||||
; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
; GNU General Public License for more details.
|
||||
;
|
||||
; You should have received a copy of the GNU General Public License
|
||||
; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
STACK EQU 2 ; stack pointer
|
||||
PC EQU 3 ; program counter
|
||||
CALLR EQU 4 ; call register
|
||||
RETR EQU 5 ; return register
|
||||
TXTPTR EQU 7 ; text pointer
|
||||
INBUF EQU 8 ; Input line buffer pointer register.
|
||||
; ; TIL registers
|
||||
IP EQU 10 ; Instruction Pointer
|
||||
WA EQU 11 ; Word Address
|
||||
TPC EQU 12 ; TIL Program Counter
|
||||
|
||||
; Input Restrictions
|
||||
BUFFER_SIZE EQU 255
|
||||
|
||||
CR EQU 0DH
|
||||
LF EQU 0AH
|
||||
DOLLAR EQU 24H
|
||||
ESC EQU 27
|
||||
|
||||
; Screen print calls
|
||||
WRITESTR EQU 9H
|
||||
PRTCHR EQU 02H
|
||||
BDOS EQU 5H
|
||||
|
||||
ORG 100h
|
||||
|
||||
MAIN:
|
||||
LD DE, GREET
|
||||
CALL PUTS
|
||||
|
||||
READING:
|
||||
CALL INPUT
|
||||
JP READING
|
||||
|
||||
INPUT:
|
||||
LD C,11 ; C_STAT
|
||||
LD DE,0
|
||||
CALL BDOS
|
||||
OR A
|
||||
JR Z,INPUT
|
||||
|
||||
LD C,6
|
||||
LD DE,-1
|
||||
CALL BDOS
|
||||
OR A
|
||||
JP Z,INPUT
|
||||
|
||||
CP 03H
|
||||
JP Z, EXIT
|
||||
|
||||
CP 0DH
|
||||
JP Z, EXIT
|
||||
|
||||
LD D, A
|
||||
LD E, A
|
||||
CALL PUTC
|
||||
RET
|
||||
|
||||
; Print a string
|
||||
PUTS:
|
||||
LD C, WRITESTR
|
||||
CALL BDOS
|
||||
RET
|
||||
|
||||
; Print a character
|
||||
PUTC:
|
||||
LD C, PRTCHR
|
||||
CALL BDOS
|
||||
RET
|
||||
|
||||
CL: DB ESC,"[H",ESC,"[2J$"
|
||||
BUFFER: DS BUFFER_SIZE
|
||||
GREET: DB "William Moore's FORTH TIL!", CR, LF, 0H
|
||||
PROMPT: DB ESC, ESC, "$ ", 0H
|
||||
|
||||
EXIT:
|
||||
JP 0h
|
||||
|
||||
END
|
Loading…
Reference in New Issue
Block a user