Better interpreter, IO, DUMP-IMAGE
diff --git a/FORTH.ASM b/FORTH.ASM
index 6ec3fcd..5dd77a7 100644
--- a/FORTH.ASM
+++ b/FORTH.ASM
@@ -107,11 +107,11 @@
%ENDMACRO
- %MACRO DEFCONST 3
+ %MACRO DEFCONST 2
DEFWORD_RAW %1, %2
- PUSH CONST_%1
+ PUSH WORD [CONST_%1]
NEXT
- CONST_%1 EQU %3
+CONST_%1:
%ENDMACRO
@@ -135,8 +135,9 @@
_START:
;; Progran begins
MOV BP, SP
- SUB BP, 1024 ; why can't I use SP as a base for
- ; load effective address?
+ SUB BP, 1024
+ MOV WORD [CONST_SP_INITIAL], SP
+
MOV SI, INDIRECT_START
NEXT
@@ -192,8 +193,7 @@
JMP DOT_INT
- ;; TODO: should not be immediate, that's just for debugging
- DEFWORD_RAW_IMMEDIATE BYE, 'BYE'
+ DEFWORD_RAW BYE, 'BYE'
FLUSH
QUIT_PROC
@@ -241,6 +241,23 @@
NEXT
+ DEFWORD_RAW SLASHMOD, '/MOD'
+ POP DX
+ POP AX
+ IDIV DX
+ PUSH DX ; Remainder
+ PUSH AX ; Quotient
+ NEXT
+
+
+ DEFWORD_RAW _TIMES, '*'
+ POP AX
+ POP DX
+ IMUL DX
+ PUSH AX
+ NEXT
+
+
DEFWORD_RAW AND, 'AND'
POP AX
POP DX
@@ -287,6 +304,41 @@
PUSH BX
PUSH AX
NEXT
+
+
+ DEFWORD_RAW TEST_WRITE_FILE, 'TEST-WRITE-FILE'
+ MOV AL, F_WRITE
+ MOV DX, DUMP
+ OPENF
+ JC .OPEN
+
+ MOV BX, AX ; Handle
+ MOV CX, 4
+ MOV DX, DUMP
+ WRITEF
+ JC .WRITE
+
+ CLOSEF
+ JC .CLOSE
+
+ NEXT
+
+.OPEN:
+ MOV DX, MSG_OPENF_FAILED
+ WRITESOUT
+ NEXT
+
+.WRITE:
+ ;; 06h - invalid handle
+ PUSH AX
+ MOV DX, MSG_WRITEF_FAILED
+ WRITESOUT
+ NEXT
+
+.CLOSE:
+ MOV DX, MSG_CLOSEF_FAILED
+ WRITESOUT
+ NEXT
%INCLUDE "IOWORDS.ASM"
@@ -300,6 +352,10 @@
DEFVAR HERE, 'HERE'
DW HERE_START
+
+ DEFCONST SP_INITIAL, 'S0'
+ DW 0
+
;; LATEST must be the last word defined in FORTH.ASM!
DEFVAR LATEST, 'LATEST'
@@ -308,6 +364,11 @@
;;; PROGRAM DATA ;;;
MSG DB 'DOS FORTH', 0Dh, 0Ah, '$'
+ DUMP DB 'DUMP.COM', 0
+ DUMP_LEN EQU 8
+
+ MSG_CLOSEF_FAILED DB 'CLOSEF FAILED', 0Dh, 0Ah, '$'
+ MSG_WRITEF_FAILED DB 'WRITEF FAILED', 0Dh, 0Ah, '$'
ALIGN 4