Remove redundancy, fix bug with closing popped file handle
diff --git a/FORTH.ASM b/FORTH.ASM
index b03d9cb..25324fe 100644
--- a/FORTH.ASM
+++ b/FORTH.ASM
@@ -203,16 +203,9 @@
DEFWORD_RAW BYE, 'BYE'
MOV DX, .BYE_MSG
WRITESOUT
- FLUSH
QUIT_PROC
-.BYE_MSG:
- DB 'Bye!', 0Dh, 0Ah, '$'
-
-
- DEFWORD_THREADED IMG_DUMPED, 'IMG-DUMPED'
- INCLUDE_STRING 'Image dumped!'
- DW TYPE, CR, EXIT
+.BYE_MSG DOS_STRING 'Bye'
DEFWORD_RAW LIT, 'LIT'
@@ -235,13 +228,8 @@
;; a b -- a b a
- DEFWORD_RAW OVER, 'OVER'
- POP BX
- POP AX
- PUSH AX
- PUSH BX
- PUSH AX
- NEXT
+ DEFWORD_THREADED OVER, 'OVER'
+ DW TO_RET, DUP, FROM_RET, SWAP, EXIT
DEFWORD_RAW DUP, 'DUP'
@@ -265,14 +253,8 @@
;; ( a b c -- b c a )
- DEFWORD_RAW ROT, 'ROT'
- POP CX
- POP BX
- POP AX
- PUSH BX
- PUSH CX
- PUSH AX
- NEXT
+ DEFWORD_THREADED ROT, 'ROT'
+ DW TO_RET, SWAP, FROM_RET, SWAP, EXIT
DEFWORD_RAW PLUS, '+'
diff --git a/IOWORDS.ASM b/IOWORDS.ASM
index 81313bb..f273d3f 100644
--- a/IOWORDS.ASM
+++ b/IOWORDS.ASM
@@ -4,9 +4,7 @@
;;; INPUT & OUTPUT ROUTINES ;;;
;; Stack of input file pointers
- DEFVAR INP_S0, 'INP-S0'
-KEY_INP_STACK:
- TIMES 32 DW 0
+KEY_INP_STACK TIMES 32 DW 0
;; Top of the stack
DEFVAR INP_SP, 'INP-SP'
@@ -58,11 +56,7 @@
PUSH AX
NEXT
-KEY_ERR_MSG DOS_STRING 'CF set'
-KEY_END_MSG DOS_STRING 'EOF'
-KEY_NO_ERR_MSG DOS_STRING 'No error'
-KEY_GOT_CHAR_MSG DOS_STRING ' Read'
-
+
;; This routine returns the key in AL, but Forth wants it on the
;; stack, so we have a helper function.
;;
@@ -87,9 +81,8 @@
RET
.READ_ERR:
- MOV BX, [KEY_INP_STACKP]
+ ;; BX already holds the file handle
CLOSEF ; Close the input stream
- MOV [BX], WORD 0 ; Reset **inp-sp 0
MOV BX, [KEY_INP_STACKP]
SUB BX, 2 ; Pop off input stack
MOV [KEY_INP_STACKP], BX