2020-03-07 12:13:15 -05:00
|
|
|
; A dictionary entry has this structure:
|
2020-03-09 19:50:51 -04:00
|
|
|
; - 7b name (zero-padded)
|
2020-03-07 12:13:15 -05:00
|
|
|
; - 2b prev pointer
|
2020-03-12 11:39:27 -04:00
|
|
|
; - 1b flags (bit 0: IMMEDIATE. bit 1: UNWORD)
|
2020-03-07 12:13:15 -05:00
|
|
|
; - 2b code pointer
|
2020-03-07 17:09:45 -05:00
|
|
|
; - Parameter field (PF)
|
2020-03-07 12:13:15 -05:00
|
|
|
;
|
|
|
|
; The code pointer point to "word routines". These routines expect to be called
|
2020-03-07 17:09:45 -05:00
|
|
|
; with IY pointing to the PF. They themselves are expected to end by jumping
|
2020-03-13 16:01:09 -04:00
|
|
|
; to the address at (IP). They will usually do so with "jp next".
|
2020-03-12 11:39:27 -04:00
|
|
|
;
|
|
|
|
; That's for "regular" words (words that are part of the dict chain). There are
|
2020-03-12 21:16:20 -04:00
|
|
|
; also "special words", for example NUMBER, LIT, FBR, that have a slightly
|
2020-03-12 11:39:27 -04:00
|
|
|
; different structure. They're also a pointer to an executable, but as for the
|
|
|
|
; other fields, the only one they have is the "flags" field.
|
2020-03-07 12:13:15 -05:00
|
|
|
|
2020-03-13 16:01:09 -04:00
|
|
|
; This routine is jumped to at the end of every word. In it, we jump to current
|
|
|
|
; IP, but we also take care of increasing it my 2 before jumping
|
|
|
|
next:
|
|
|
|
; Before we continue: are stacks within bounds?
|
2020-03-17 14:56:08 -04:00
|
|
|
call chkPS
|
|
|
|
call chkRS
|
2020-03-13 16:01:09 -04:00
|
|
|
ld de, (IP)
|
|
|
|
ld h, d
|
|
|
|
ld l, e
|
|
|
|
inc de \ inc de
|
|
|
|
ld (IP), de
|
|
|
|
; HL is an atom list pointer. We need to go into it to have a wordref
|
|
|
|
ld e, (hl)
|
|
|
|
inc hl
|
|
|
|
ld d, (hl)
|
|
|
|
push de
|
|
|
|
jp EXECUTE+2
|
|
|
|
|
|
|
|
|
2020-03-07 17:09:45 -05:00
|
|
|
; Execute a word containing native code at its PF address (PFA)
|
2020-03-07 12:13:15 -05:00
|
|
|
nativeWord:
|
|
|
|
jp (iy)
|
|
|
|
|
2020-03-13 16:01:09 -04:00
|
|
|
; Execute a list of atoms, which always end with EXIT.
|
|
|
|
; IY points to that list. What do we do:
|
|
|
|
; 1. Push current IP to RS
|
|
|
|
; 2. Set new IP to the second atom of the list
|
|
|
|
; 3. Execute the first atom of the list.
|
2020-03-07 12:13:15 -05:00
|
|
|
compiledWord:
|
2020-03-13 16:01:09 -04:00
|
|
|
ld hl, (IP)
|
|
|
|
call pushRS
|
2020-03-07 12:13:15 -05:00
|
|
|
push iy \ pop hl
|
|
|
|
inc hl
|
|
|
|
inc hl
|
2020-03-13 16:01:09 -04:00
|
|
|
ld (IP), hl
|
|
|
|
; IY still is our atom reference...
|
2020-03-07 12:13:15 -05:00
|
|
|
ld l, (iy)
|
|
|
|
ld h, (iy+1)
|
2020-03-13 16:01:09 -04:00
|
|
|
push hl ; argument for EXECUTE
|
|
|
|
jp EXECUTE+2
|
2020-03-07 12:13:15 -05:00
|
|
|
|
2020-03-07 17:09:45 -05:00
|
|
|
; Pushes the PFA directly
|
|
|
|
cellWord:
|
|
|
|
push iy
|
2020-03-13 16:01:09 -04:00
|
|
|
jp next
|
2020-03-07 17:09:45 -05:00
|
|
|
|
|
|
|
; Pushes the address in the first word of the PF
|
|
|
|
sysvarWord:
|
|
|
|
ld l, (iy)
|
|
|
|
ld h, (iy+1)
|
|
|
|
push hl
|
2020-03-13 16:01:09 -04:00
|
|
|
jp next
|
2020-03-07 17:09:45 -05:00
|
|
|
|
2020-03-07 22:18:14 -05:00
|
|
|
; The word was spawned from a definition word that has a DOES>. PFA+2 (right
|
|
|
|
; after the actual cell) is a link to the slot right after that DOES>.
|
|
|
|
; Therefore, what we need to do push the cell addr like a regular cell, then
|
|
|
|
; follow the link from the PFA, and then continue as a regular compiledWord.
|
|
|
|
doesWord:
|
|
|
|
push iy ; like a regular cell
|
|
|
|
ld l, (iy+2)
|
|
|
|
ld h, (iy+3)
|
|
|
|
push hl \ pop iy
|
|
|
|
jr compiledWord
|
|
|
|
|
2020-03-07 19:25:55 -05:00
|
|
|
; This is not a word, but a number literal. This works a bit differently than
|
|
|
|
; others: PF means nothing and the actual number is placed next to the
|
|
|
|
; numberWord reference in the compiled word list. What we need to do to fetch
|
2020-03-13 16:01:09 -04:00
|
|
|
; that number is to play with the IP.
|
2020-03-07 19:25:55 -05:00
|
|
|
numberWord:
|
2020-03-13 16:01:09 -04:00
|
|
|
ld hl, (IP) ; (HL) is out number
|
2020-03-07 19:25:55 -05:00
|
|
|
ld e, (hl)
|
|
|
|
inc hl
|
|
|
|
ld d, (hl)
|
|
|
|
inc hl
|
2020-03-13 16:01:09 -04:00
|
|
|
ld (IP), hl ; advance IP by 2
|
2020-03-07 19:25:55 -05:00
|
|
|
push de
|
2020-03-13 16:01:09 -04:00
|
|
|
jp next
|
2020-03-12 11:39:27 -04:00
|
|
|
|
|
|
|
.db 0b10 ; Flags
|
2020-03-07 19:25:55 -05:00
|
|
|
NUMBER:
|
|
|
|
.dw numberWord
|
|
|
|
|
2020-03-09 08:49:51 -04:00
|
|
|
; Similarly to numberWord, this is not a real word, but a string literal.
|
|
|
|
; Instead of being followed by a 2 bytes number, it's followed by a
|
2020-03-15 22:46:17 -04:00
|
|
|
; null-terminated string. When called, puts the string's address on PS
|
2020-03-09 08:49:51 -04:00
|
|
|
litWord:
|
2020-03-13 16:01:09 -04:00
|
|
|
ld hl, (IP)
|
2020-03-15 22:46:17 -04:00
|
|
|
push hl
|
|
|
|
call strskip
|
|
|
|
inc hl ; after null termination
|
|
|
|
ld (IP), hl
|
|
|
|
jp next
|
2020-03-12 11:39:27 -04:00
|
|
|
|
|
|
|
.db 0b10 ; Flags
|
2020-03-09 08:49:51 -04:00
|
|
|
LIT:
|
|
|
|
.dw litWord
|
2020-03-07 19:25:55 -05:00
|
|
|
|
2020-03-13 16:01:09 -04:00
|
|
|
; Pop previous IP from Return stack and execute it.
|
2020-03-07 12:13:15 -05:00
|
|
|
; ( R:I -- )
|
2020-03-13 16:40:55 -04:00
|
|
|
.db "EXIT"
|
|
|
|
.fill 3
|
|
|
|
.dw 0
|
|
|
|
.db 0
|
2020-03-09 15:12:44 -04:00
|
|
|
EXIT:
|
2020-03-07 12:13:15 -05:00
|
|
|
.dw nativeWord
|
2020-03-17 17:29:03 -04:00
|
|
|
call popRSIP
|
2020-03-13 16:01:09 -04:00
|
|
|
jp next
|
2020-03-07 12:13:15 -05:00
|
|
|
|
2020-03-07 17:09:45 -05:00
|
|
|
; ( R:I -- )
|
2020-03-09 19:50:51 -04:00
|
|
|
.db "QUIT"
|
2020-03-12 11:39:27 -04:00
|
|
|
.fill 3
|
2020-03-07 17:09:45 -05:00
|
|
|
.dw EXIT
|
2020-03-12 11:39:27 -04:00
|
|
|
.db 0
|
2020-03-09 15:12:44 -04:00
|
|
|
QUIT:
|
2020-03-07 17:09:45 -05:00
|
|
|
.dw nativeWord
|
2020-03-09 08:49:51 -04:00
|
|
|
jp forthRdLine
|
2020-03-07 20:20:11 -05:00
|
|
|
|
2020-03-09 19:50:51 -04:00
|
|
|
.db "ABORT"
|
2020-03-12 11:39:27 -04:00
|
|
|
.fill 2
|
2020-03-07 20:20:11 -05:00
|
|
|
.dw QUIT
|
2020-03-12 11:39:27 -04:00
|
|
|
.db 0
|
2020-03-09 15:12:44 -04:00
|
|
|
ABORT:
|
2020-03-07 20:20:11 -05:00
|
|
|
.dw nativeWord
|
|
|
|
abort:
|
2020-03-15 22:46:17 -04:00
|
|
|
; flush rest of input
|
|
|
|
ld hl, (INPUTPOS)
|
|
|
|
xor a
|
|
|
|
ld (hl), a
|
2020-03-13 16:01:09 -04:00
|
|
|
; Reinitialize PS (RS is reinitialized in forthInterpret)
|
2020-03-07 20:20:11 -05:00
|
|
|
ld sp, (INITIAL_SP)
|
2020-03-13 16:01:09 -04:00
|
|
|
jp forthRdLineNoOk
|
2020-03-15 22:46:17 -04:00
|
|
|
|
|
|
|
; prints msg in (HL) then aborts
|
|
|
|
abortMsg:
|
|
|
|
call printstr
|
|
|
|
jr abort
|
|
|
|
|
|
|
|
abortUnknownWord:
|
|
|
|
ld hl, .msg
|
|
|
|
jr abortMsg
|
|
|
|
.msg:
|
|
|
|
.db "unknown word", 0
|
2020-03-07 17:09:45 -05:00
|
|
|
|
2020-03-17 14:56:08 -04:00
|
|
|
abortUnderflow:
|
|
|
|
ld hl, .msg
|
|
|
|
jr abortMsg
|
|
|
|
.msg:
|
|
|
|
.db "stack underflow", 0
|
|
|
|
|
2020-03-17 15:30:57 -04:00
|
|
|
.db "ABORT", '"'
|
|
|
|
.fill 1
|
|
|
|
.dw ABORT
|
|
|
|
.db 1 ; IMMEDIATE
|
|
|
|
ABORTI:
|
|
|
|
.dw compiledWord
|
|
|
|
.dw PRINTI
|
|
|
|
.dw .private
|
|
|
|
.dw EXIT
|
|
|
|
|
|
|
|
.db 0b10 ; UNWORD
|
|
|
|
.private:
|
|
|
|
.dw nativeWord
|
|
|
|
ld hl, (HERE)
|
|
|
|
ld de, ABORT
|
|
|
|
call DEinHL
|
|
|
|
ld (HERE), hl
|
|
|
|
jp next
|
|
|
|
|
2020-03-07 13:15:19 -05:00
|
|
|
.db "BYE"
|
2020-03-12 11:39:27 -04:00
|
|
|
.fill 4
|
2020-03-17 15:30:57 -04:00
|
|
|
.dw ABORTI
|
2020-03-12 11:39:27 -04:00
|
|
|
.db 0
|
2020-03-09 15:12:44 -04:00
|
|
|
BYE:
|
2020-03-07 13:15:19 -05:00
|
|
|
.dw nativeWord
|
2020-03-09 08:49:51 -04:00
|
|
|
; Goodbye Forth! Before we go, let's restore the stack
|
|
|
|
ld sp, (INITIAL_SP)
|
|
|
|
; unwind stack underflow buffer
|
|
|
|
pop af \ pop af \ pop af
|
|
|
|
; success
|
|
|
|
xor a
|
|
|
|
ret
|
2020-03-07 13:15:19 -05:00
|
|
|
|
2020-03-07 12:13:15 -05:00
|
|
|
; ( c -- )
|
2020-03-09 19:50:51 -04:00
|
|
|
.db "EMIT"
|
2020-03-12 11:39:27 -04:00
|
|
|
.fill 3
|
2020-03-07 13:15:19 -05:00
|
|
|
.dw BYE
|
2020-03-12 11:39:27 -04:00
|
|
|
.db 0
|
2020-03-09 15:12:44 -04:00
|
|
|
EMIT:
|
2020-03-07 12:13:15 -05:00
|
|
|
.dw nativeWord
|
|
|
|
pop hl
|
2020-03-17 14:56:08 -04:00
|
|
|
call chkPS
|
2020-03-07 12:13:15 -05:00
|
|
|
ld a, l
|
|
|
|
call stdioPutC
|
2020-03-13 16:01:09 -04:00
|
|
|
jp next
|
2020-03-07 12:13:15 -05:00
|
|
|
|
2020-03-17 15:22:13 -04:00
|
|
|
.db "(print)"
|
|
|
|
.dw EMIT
|
|
|
|
.db 0
|
|
|
|
PRINT:
|
|
|
|
.dw nativeWord
|
|
|
|
pop hl
|
|
|
|
call chkPS
|
|
|
|
call printstr
|
|
|
|
jp next
|
|
|
|
|
|
|
|
|
|
|
|
.db '.', '"'
|
|
|
|
.fill 5
|
|
|
|
.dw PRINT
|
|
|
|
.db 1 ; IMMEDIATE
|
|
|
|
PRINTI:
|
|
|
|
.dw nativeWord
|
|
|
|
ld hl, (HERE)
|
|
|
|
ld de, LIT
|
|
|
|
call DEinHL
|
|
|
|
ex de, hl ; (HERE) now in DE
|
|
|
|
ld hl, (INPUTPOS)
|
|
|
|
.loop:
|
|
|
|
ld a, (hl)
|
|
|
|
or a ; null? not cool
|
|
|
|
jp z, abort
|
|
|
|
cp '"'
|
|
|
|
jr z, .loopend
|
|
|
|
ld (de), a
|
|
|
|
inc hl
|
|
|
|
inc de
|
|
|
|
jr .loop
|
|
|
|
.loopend:
|
|
|
|
inc hl ; inputpos to char afterwards
|
|
|
|
ld (INPUTPOS), hl
|
|
|
|
; null-terminate LIT
|
|
|
|
inc de
|
|
|
|
xor a
|
|
|
|
ld (de), a
|
|
|
|
ex de, hl ; (HERE) in HL
|
|
|
|
ld de, PRINT
|
|
|
|
call DEinHL
|
|
|
|
ld (HERE), hl
|
|
|
|
jp next
|
|
|
|
|
2020-03-10 13:00:57 -04:00
|
|
|
; ( c port -- )
|
|
|
|
.db "PC!"
|
2020-03-12 11:39:27 -04:00
|
|
|
.fill 4
|
2020-03-17 15:22:13 -04:00
|
|
|
.dw PRINTI
|
2020-03-12 11:39:27 -04:00
|
|
|
.db 0
|
2020-03-10 13:00:57 -04:00
|
|
|
PSTORE:
|
|
|
|
.dw nativeWord
|
|
|
|
pop bc
|
|
|
|
pop hl
|
2020-03-17 14:56:08 -04:00
|
|
|
call chkPS
|
2020-03-10 13:00:57 -04:00
|
|
|
out (c), l
|
2020-03-13 16:01:09 -04:00
|
|
|
jp next
|
2020-03-10 13:00:57 -04:00
|
|
|
|
|
|
|
; ( port -- c )
|
|
|
|
.db "PC@"
|
2020-03-12 11:39:27 -04:00
|
|
|
.fill 4
|
2020-03-10 13:00:57 -04:00
|
|
|
.dw PSTORE
|
2020-03-12 11:39:27 -04:00
|
|
|
.db 0
|
2020-03-10 13:00:57 -04:00
|
|
|
PFETCH:
|
|
|
|
.dw nativeWord
|
|
|
|
pop bc
|
2020-03-17 14:56:08 -04:00
|
|
|
call chkPS
|
2020-03-10 13:00:57 -04:00
|
|
|
ld h, 0
|
|
|
|
in l, (c)
|
|
|
|
push hl
|
2020-03-13 16:01:09 -04:00
|
|
|
jp next
|
2020-03-10 13:00:57 -04:00
|
|
|
|
2020-03-17 17:29:03 -04:00
|
|
|
.db ","
|
|
|
|
.fill 6
|
|
|
|
.dw PFETCH
|
|
|
|
.db 0
|
|
|
|
WR:
|
|
|
|
.dw nativeWord
|
|
|
|
pop de
|
|
|
|
call chkPS
|
|
|
|
ld hl, (HERE)
|
|
|
|
call DEinHL
|
|
|
|
ld (HERE), hl
|
|
|
|
jp next
|
|
|
|
|
|
|
|
|
2020-03-07 12:13:15 -05:00
|
|
|
; ( addr -- )
|
2020-03-09 19:50:51 -04:00
|
|
|
.db "EXECUTE"
|
2020-03-17 17:29:03 -04:00
|
|
|
.dw WR
|
2020-03-12 11:39:27 -04:00
|
|
|
.db 0
|
2020-03-09 15:12:44 -04:00
|
|
|
EXECUTE:
|
2020-03-07 12:13:15 -05:00
|
|
|
.dw nativeWord
|
2020-03-09 15:12:44 -04:00
|
|
|
pop iy ; is a wordref
|
2020-03-17 14:56:08 -04:00
|
|
|
call chkPS
|
2020-03-07 12:13:15 -05:00
|
|
|
ld l, (iy)
|
|
|
|
ld h, (iy+1)
|
|
|
|
; HL points to code pointer
|
|
|
|
inc iy
|
|
|
|
inc iy
|
|
|
|
; IY points to PFA
|
|
|
|
jp (hl) ; go!
|
|
|
|
|
2020-03-13 16:40:55 -04:00
|
|
|
|
2020-03-16 21:31:43 -04:00
|
|
|
.db "[COMPIL"
|
2020-03-14 17:48:24 -04:00
|
|
|
.dw EXECUTE
|
|
|
|
.db 1 ; IMMEDIATE
|
|
|
|
COMPILE:
|
2020-03-17 17:29:03 -04:00
|
|
|
.dw compiledWord
|
|
|
|
.dw FIND_
|
|
|
|
.dw CSKIP
|
|
|
|
.dw .maybeNum
|
|
|
|
.dw DUP
|
|
|
|
.dw ISIMMED
|
|
|
|
.dw CSKIP
|
|
|
|
.dw .word
|
|
|
|
; is immediate. just execute.
|
|
|
|
.dw EXECUTE
|
|
|
|
.dw EXIT
|
|
|
|
|
|
|
|
.db 0b10 ; UNWORD
|
|
|
|
.word:
|
|
|
|
.dw compiledWord
|
|
|
|
.dw WR
|
|
|
|
.dw R2P ; exit COMPILE
|
|
|
|
.dw DROP
|
|
|
|
.dw EXIT
|
|
|
|
|
|
|
|
.db 0b10 ; UNWORD
|
2020-03-14 17:48:24 -04:00
|
|
|
.maybeNum:
|
2020-03-17 17:29:03 -04:00
|
|
|
.dw compiledWord
|
2020-03-17 21:19:56 -04:00
|
|
|
.dw PARSEI
|
2020-03-17 17:29:03 -04:00
|
|
|
.dw LITN
|
|
|
|
.dw R2P ; exit COMPILE
|
|
|
|
.dw DROP
|
|
|
|
.dw EXIT
|
|
|
|
|
|
|
|
|
2020-03-15 22:46:17 -04:00
|
|
|
.db ":"
|
2020-03-13 16:40:55 -04:00
|
|
|
.fill 6
|
2020-03-14 17:48:24 -04:00
|
|
|
.dw COMPILE
|
2020-03-15 22:46:17 -04:00
|
|
|
.db 1 ; IMMEDIATE
|
2020-03-09 15:12:44 -04:00
|
|
|
DEFINE:
|
2020-03-07 18:53:20 -05:00
|
|
|
.dw nativeWord
|
|
|
|
call entryhead
|
|
|
|
ld de, compiledWord
|
2020-03-13 16:01:09 -04:00
|
|
|
call DEinHL
|
2020-03-15 22:46:17 -04:00
|
|
|
ld (HERE), hl
|
2020-03-07 18:53:20 -05:00
|
|
|
.loop:
|
2020-03-15 22:46:17 -04:00
|
|
|
; did we reach ";"?
|
2020-03-16 22:09:23 -04:00
|
|
|
call toword
|
2020-03-15 22:46:17 -04:00
|
|
|
ld a, (hl)
|
|
|
|
cp ';'
|
|
|
|
jr nz, .compile
|
|
|
|
inc hl
|
|
|
|
ld a, (hl)
|
|
|
|
cp ' '+1
|
|
|
|
jr c, .loopend ; whitespace, we have semicol. end
|
|
|
|
.compile:
|
2020-03-13 16:01:09 -04:00
|
|
|
ld hl, (IP)
|
2020-03-15 22:46:17 -04:00
|
|
|
call pushRS
|
|
|
|
ld hl, .retRef
|
2020-03-13 16:01:09 -04:00
|
|
|
ld (IP), hl
|
2020-03-15 22:46:17 -04:00
|
|
|
ld hl, COMPILE
|
|
|
|
push hl
|
|
|
|
jp EXECUTE+2
|
|
|
|
.loopend:
|
|
|
|
; Advance (INPUTPOS) to after semicol. HL is already there.
|
|
|
|
ld (INPUTPOS), hl
|
|
|
|
; write EXIT and return
|
|
|
|
ld hl, (HERE)
|
|
|
|
ld de, EXIT
|
|
|
|
call DEinHL
|
|
|
|
ld (HERE), hl
|
2020-03-13 16:01:09 -04:00
|
|
|
jp next
|
2020-03-15 22:46:17 -04:00
|
|
|
.retRef:
|
|
|
|
.dw $+2
|
|
|
|
.dw $+2
|
2020-03-17 17:29:03 -04:00
|
|
|
call popRSIP
|
2020-03-15 22:46:17 -04:00
|
|
|
jr .loop
|
2020-03-07 18:53:20 -05:00
|
|
|
|
2020-03-09 22:13:11 -04:00
|
|
|
|
2020-03-09 19:50:51 -04:00
|
|
|
.db "DOES>"
|
2020-03-12 11:39:27 -04:00
|
|
|
.fill 2
|
2020-03-07 22:18:14 -05:00
|
|
|
.dw DEFINE
|
2020-03-12 11:39:27 -04:00
|
|
|
.db 0
|
2020-03-09 15:12:44 -04:00
|
|
|
DOES:
|
2020-03-07 22:18:14 -05:00
|
|
|
.dw nativeWord
|
|
|
|
; We run this when we're in an entry creation context. Many things we
|
|
|
|
; need to do.
|
|
|
|
; 1. Change the code link to doesWord
|
|
|
|
; 2. Leave 2 bytes for regular cell variable.
|
2020-03-13 16:01:09 -04:00
|
|
|
; 3. Write down IP+2 to entry.
|
|
|
|
; 3. exit. we're done here.
|
2020-03-19 16:36:54 -04:00
|
|
|
ld hl, (CURRENT)
|
|
|
|
ld de, doesWord
|
|
|
|
call DEinHL
|
|
|
|
inc hl \ inc hl ; cell variable space
|
|
|
|
ld de, (IP)
|
|
|
|
call DEinHL
|
|
|
|
ld (HERE), hl
|
2020-03-13 16:01:09 -04:00
|
|
|
jp EXIT+2
|
2020-03-07 22:18:14 -05:00
|
|
|
|
2020-03-09 22:13:11 -04:00
|
|
|
|
|
|
|
.db "IMMEDIA"
|
|
|
|
.dw DOES
|
2020-03-12 11:39:27 -04:00
|
|
|
.db 0
|
2020-03-09 22:13:11 -04:00
|
|
|
IMMEDIATE:
|
|
|
|
.dw nativeWord
|
|
|
|
ld hl, (CURRENT)
|
|
|
|
dec hl
|
2020-03-12 11:39:27 -04:00
|
|
|
set FLAG_IMMED, (hl)
|
2020-03-13 16:01:09 -04:00
|
|
|
jp next
|
2020-03-09 22:13:11 -04:00
|
|
|
|
2020-03-17 17:29:03 -04:00
|
|
|
|
|
|
|
.db "IMMED?"
|
|
|
|
.fill 1
|
|
|
|
.dw IMMEDIATE
|
|
|
|
.db 0
|
|
|
|
ISIMMED:
|
|
|
|
.dw nativeWord
|
|
|
|
pop hl
|
|
|
|
call chkPS
|
|
|
|
dec hl
|
|
|
|
ld de, 0
|
|
|
|
bit FLAG_IMMED, (hl)
|
|
|
|
jr z, .notset
|
|
|
|
inc de
|
|
|
|
.notset:
|
|
|
|
push de
|
|
|
|
jp next
|
|
|
|
|
2020-03-09 22:13:11 -04:00
|
|
|
; ( n -- )
|
2020-03-15 22:46:17 -04:00
|
|
|
.db "LITN"
|
|
|
|
.fill 3
|
2020-03-17 17:29:03 -04:00
|
|
|
.dw ISIMMED
|
2020-03-18 20:04:44 -04:00
|
|
|
.db 0
|
2020-03-15 22:46:17 -04:00
|
|
|
LITN:
|
2020-03-09 22:13:11 -04:00
|
|
|
.dw nativeWord
|
2020-03-12 13:08:11 -04:00
|
|
|
ld hl, (HERE)
|
2020-03-09 22:13:11 -04:00
|
|
|
ld de, NUMBER
|
2020-03-10 21:37:06 -04:00
|
|
|
call DEinHL
|
2020-03-09 22:13:11 -04:00
|
|
|
pop de ; number from stack
|
2020-03-17 14:56:08 -04:00
|
|
|
call chkPS
|
2020-03-10 21:37:06 -04:00
|
|
|
call DEinHL
|
2020-03-12 13:08:11 -04:00
|
|
|
ld (HERE), hl
|
2020-03-13 16:01:09 -04:00
|
|
|
jp next
|
2020-03-09 22:13:11 -04:00
|
|
|
|
2020-03-15 22:46:17 -04:00
|
|
|
.db "LITS"
|
|
|
|
.fill 3
|
|
|
|
.dw LITN
|
|
|
|
.db 1 ; IMMEDIATE
|
|
|
|
LITS:
|
|
|
|
.dw nativeWord
|
|
|
|
ld hl, (HERE)
|
|
|
|
ld de, LIT
|
|
|
|
call DEinHL
|
|
|
|
ex de, hl ; (HERE) in DE
|
|
|
|
call readword
|
|
|
|
call strcpyM
|
|
|
|
ld (HERE), de
|
|
|
|
jp next
|
2020-03-12 21:16:20 -04:00
|
|
|
|
2020-03-17 16:02:01 -04:00
|
|
|
.db "(find)"
|
|
|
|
.fill 1
|
2020-03-15 22:46:17 -04:00
|
|
|
.dw LITS
|
2020-03-12 21:16:20 -04:00
|
|
|
.db 0
|
2020-03-17 16:02:01 -04:00
|
|
|
FIND_:
|
2020-03-12 21:16:20 -04:00
|
|
|
.dw nativeWord
|
2020-03-15 22:46:17 -04:00
|
|
|
call readword
|
2020-03-12 21:16:20 -04:00
|
|
|
call find
|
2020-03-17 15:54:17 -04:00
|
|
|
jr z, .found
|
|
|
|
; not found
|
2020-03-17 16:02:01 -04:00
|
|
|
push hl
|
2020-03-17 15:54:17 -04:00
|
|
|
ld de, 0
|
2020-03-17 16:02:01 -04:00
|
|
|
push de
|
|
|
|
jp next
|
2020-03-17 15:54:17 -04:00
|
|
|
.found:
|
2020-03-12 21:16:20 -04:00
|
|
|
push de
|
2020-03-17 16:02:01 -04:00
|
|
|
ld de, 1
|
|
|
|
push de
|
2020-03-13 16:01:09 -04:00
|
|
|
jp next
|
2020-03-12 21:16:20 -04:00
|
|
|
|
2020-03-17 16:02:01 -04:00
|
|
|
.db "'"
|
|
|
|
.fill 6
|
|
|
|
.dw FIND_
|
|
|
|
.db 0
|
|
|
|
FIND:
|
|
|
|
.dw compiledWord
|
|
|
|
.dw FIND_
|
|
|
|
.dw CSKIP
|
|
|
|
.dw FINDERR
|
|
|
|
.dw EXIT
|
|
|
|
|
2020-03-12 21:16:20 -04:00
|
|
|
.db "[']"
|
|
|
|
.fill 4
|
2020-03-17 15:54:17 -04:00
|
|
|
.dw FIND
|
2020-03-12 21:16:20 -04:00
|
|
|
.db 0b01 ; IMMEDIATE
|
2020-03-17 15:54:17 -04:00
|
|
|
FINDI:
|
2020-03-17 16:02:01 -04:00
|
|
|
.dw compiledWord
|
|
|
|
.dw FIND_
|
|
|
|
.dw CSKIP
|
|
|
|
.dw FINDERR
|
|
|
|
.dw LITN
|
|
|
|
.dw EXIT
|
|
|
|
|
|
|
|
.db 0b10 ; UNWORD
|
|
|
|
FINDERR:
|
|
|
|
.dw compiledWord
|
|
|
|
.dw DROP ; Drop str addr, we don't use it
|
|
|
|
.dw LIT
|
2020-03-12 21:16:20 -04:00
|
|
|
.db "word not found", 0
|
2020-03-17 16:02:01 -04:00
|
|
|
.dw PRINT
|
|
|
|
.dw ABORT
|
2020-03-12 21:16:20 -04:00
|
|
|
|
2020-03-07 12:13:15 -05:00
|
|
|
; ( -- c )
|
2020-03-07 17:09:45 -05:00
|
|
|
.db "KEY"
|
2020-03-12 11:39:27 -04:00
|
|
|
.fill 4
|
2020-03-17 15:54:17 -04:00
|
|
|
.dw FINDI
|
2020-03-12 11:39:27 -04:00
|
|
|
.db 0
|
2020-03-09 15:12:44 -04:00
|
|
|
KEY:
|
2020-03-07 12:13:15 -05:00
|
|
|
.dw nativeWord
|
|
|
|
call stdioGetC
|
|
|
|
ld h, 0
|
|
|
|
ld l, a
|
|
|
|
push hl
|
2020-03-13 16:01:09 -04:00
|
|
|
jp next
|
2020-03-07 12:13:15 -05:00
|
|
|
|
2020-03-13 16:40:55 -04:00
|
|
|
.db "WORD"
|
|
|
|
.fill 3
|
|
|
|
.dw KEY
|
|
|
|
.db 0
|
|
|
|
WORD:
|
|
|
|
.dw nativeWord
|
|
|
|
call readword
|
|
|
|
push hl
|
|
|
|
jp next
|
|
|
|
|
2020-03-17 17:46:58 -04:00
|
|
|
|
|
|
|
.db "(parsed"
|
|
|
|
.dw WORD
|
|
|
|
.db 0
|
|
|
|
PARSED:
|
|
|
|
.dw nativeWord
|
|
|
|
pop hl
|
|
|
|
call chkPS
|
|
|
|
call parseDecimal
|
|
|
|
jr z, .success
|
|
|
|
; error
|
|
|
|
ld de, 0
|
|
|
|
push de ; dummy
|
|
|
|
push de ; flag
|
|
|
|
jp next
|
|
|
|
.success:
|
|
|
|
push de
|
|
|
|
ld de, 1 ; flag
|
|
|
|
push de
|
|
|
|
jp next
|
|
|
|
|
|
|
|
|
|
|
|
.db "(parse)"
|
2020-03-17 21:19:56 -04:00
|
|
|
.dw PARSED
|
2020-03-17 17:46:58 -04:00
|
|
|
.db 0
|
|
|
|
PARSE:
|
|
|
|
.dw compiledWord
|
|
|
|
.dw PARSED
|
|
|
|
.dw CSKIP
|
|
|
|
.dw .error
|
|
|
|
; success, stack is already good, we can exit
|
|
|
|
.dw EXIT
|
|
|
|
|
|
|
|
.db 0b10 ; UNWORD
|
|
|
|
.error:
|
|
|
|
.dw compiledWord
|
|
|
|
.dw LIT
|
|
|
|
.db "unknown word", 0
|
|
|
|
.dw PRINT
|
|
|
|
.dw ABORT
|
|
|
|
|
|
|
|
|
2020-03-17 21:19:56 -04:00
|
|
|
; Indirect parse caller. Reads PARSEPTR and calls
|
|
|
|
.db 0b10 ; UNWORD
|
|
|
|
PARSEI:
|
|
|
|
.dw compiledWord
|
|
|
|
.dw PARSEPTR_
|
|
|
|
.dw FETCH
|
|
|
|
.dw EXECUTE
|
|
|
|
.dw EXIT
|
|
|
|
|
|
|
|
|
2020-03-09 19:50:51 -04:00
|
|
|
.db "CREATE"
|
2020-03-12 11:39:27 -04:00
|
|
|
.fill 1
|
2020-03-17 17:46:58 -04:00
|
|
|
.dw PARSE
|
2020-03-12 11:39:27 -04:00
|
|
|
.db 0
|
2020-03-09 15:12:44 -04:00
|
|
|
CREATE:
|
2020-03-07 17:09:45 -05:00
|
|
|
.dw nativeWord
|
2020-03-07 18:53:20 -05:00
|
|
|
call entryhead
|
2020-03-07 17:09:45 -05:00
|
|
|
ld de, cellWord
|
|
|
|
ld (hl), e
|
|
|
|
inc hl
|
|
|
|
ld (hl), d
|
|
|
|
inc hl
|
|
|
|
ld (HERE), hl
|
2020-03-13 16:01:09 -04:00
|
|
|
jp next
|
2020-03-07 17:09:45 -05:00
|
|
|
|
|
|
|
.db "HERE"
|
2020-03-12 11:39:27 -04:00
|
|
|
.fill 3
|
2020-03-07 17:09:45 -05:00
|
|
|
.dw CREATE
|
2020-03-12 11:39:27 -04:00
|
|
|
.db 0
|
2020-03-09 15:12:44 -04:00
|
|
|
HERE_: ; Caution: conflicts with actual variable name
|
2020-03-07 17:09:45 -05:00
|
|
|
.dw sysvarWord
|
|
|
|
.dw HERE
|
|
|
|
|
2020-03-09 19:50:51 -04:00
|
|
|
.db "CURRENT"
|
2020-03-07 22:18:14 -05:00
|
|
|
.dw HERE_
|
2020-03-12 11:39:27 -04:00
|
|
|
.db 0
|
2020-03-09 15:12:44 -04:00
|
|
|
CURRENT_:
|
2020-03-07 22:18:14 -05:00
|
|
|
.dw sysvarWord
|
|
|
|
.dw CURRENT
|
|
|
|
|
2020-03-17 21:19:56 -04:00
|
|
|
.db "(parse*"
|
|
|
|
.dw CURRENT_
|
|
|
|
.db 0
|
|
|
|
PARSEPTR_:
|
|
|
|
.dw sysvarWord
|
|
|
|
.dw PARSEPTR
|
|
|
|
|
2020-03-14 19:10:39 -04:00
|
|
|
.db "IN>"
|
|
|
|
.fill 4
|
2020-03-17 21:19:56 -04:00
|
|
|
.dw PARSEPTR_
|
2020-03-14 19:10:39 -04:00
|
|
|
.db 0
|
|
|
|
INP:
|
|
|
|
.dw sysvarWord
|
|
|
|
.dw INPUTPOS
|
|
|
|
|
2020-03-07 17:09:45 -05:00
|
|
|
; ( n a -- )
|
|
|
|
.db "!"
|
2020-03-12 11:39:27 -04:00
|
|
|
.fill 6
|
2020-03-17 12:26:28 -04:00
|
|
|
.dw INP
|
2020-03-12 11:39:27 -04:00
|
|
|
.db 0
|
2020-03-09 15:12:44 -04:00
|
|
|
STORE:
|
2020-03-07 17:09:45 -05:00
|
|
|
.dw nativeWord
|
|
|
|
pop iy
|
|
|
|
pop hl
|
2020-03-17 14:56:08 -04:00
|
|
|
call chkPS
|
2020-03-07 17:09:45 -05:00
|
|
|
ld (iy), l
|
|
|
|
ld (iy+1), h
|
2020-03-13 16:01:09 -04:00
|
|
|
jp next
|
2020-03-07 17:09:45 -05:00
|
|
|
|
2020-03-11 22:11:54 -04:00
|
|
|
; ( n a -- )
|
|
|
|
.db "C!"
|
2020-03-12 11:39:27 -04:00
|
|
|
.fill 5
|
2020-03-11 22:11:54 -04:00
|
|
|
.dw STORE
|
2020-03-12 11:39:27 -04:00
|
|
|
.db 0
|
2020-03-11 22:11:54 -04:00
|
|
|
CSTORE:
|
|
|
|
.dw nativeWord
|
|
|
|
pop hl
|
|
|
|
pop de
|
2020-03-17 14:56:08 -04:00
|
|
|
call chkPS
|
2020-03-11 22:11:54 -04:00
|
|
|
ld (hl), e
|
2020-03-13 16:01:09 -04:00
|
|
|
jp next
|
2020-03-11 22:11:54 -04:00
|
|
|
|
2020-03-07 17:09:45 -05:00
|
|
|
; ( a -- n )
|
|
|
|
.db "@"
|
2020-03-12 11:39:27 -04:00
|
|
|
.fill 6
|
2020-03-11 22:11:54 -04:00
|
|
|
.dw CSTORE
|
2020-03-12 11:39:27 -04:00
|
|
|
.db 0
|
2020-03-09 15:12:44 -04:00
|
|
|
FETCH:
|
2020-03-07 17:09:45 -05:00
|
|
|
.dw nativeWord
|
|
|
|
pop hl
|
2020-03-17 14:56:08 -04:00
|
|
|
call chkPS
|
2020-03-07 17:09:45 -05:00
|
|
|
call intoHL
|
|
|
|
push hl
|
2020-03-13 16:01:09 -04:00
|
|
|
jp next
|
2020-03-07 19:42:07 -05:00
|
|
|
|
2020-03-11 22:11:54 -04:00
|
|
|
; ( a -- c )
|
|
|
|
.db "C@"
|
2020-03-12 11:39:27 -04:00
|
|
|
.fill 5
|
2020-03-11 22:11:54 -04:00
|
|
|
.dw FETCH
|
2020-03-12 11:39:27 -04:00
|
|
|
.db 0
|
2020-03-11 22:11:54 -04:00
|
|
|
CFETCH:
|
|
|
|
.dw nativeWord
|
|
|
|
pop hl
|
2020-03-17 14:56:08 -04:00
|
|
|
call chkPS
|
2020-03-11 22:11:54 -04:00
|
|
|
ld l, (hl)
|
|
|
|
ld h, 0
|
|
|
|
push hl
|
2020-03-13 16:01:09 -04:00
|
|
|
jp next
|
2020-03-11 22:11:54 -04:00
|
|
|
|
2020-03-14 17:48:24 -04:00
|
|
|
; ( a -- )
|
|
|
|
.db "DROP"
|
|
|
|
.fill 3
|
2020-03-15 22:46:17 -04:00
|
|
|
.dw CFETCH
|
2020-03-14 17:48:24 -04:00
|
|
|
.db 0
|
|
|
|
DROP:
|
|
|
|
.dw nativeWord
|
|
|
|
pop hl
|
|
|
|
jp next
|
|
|
|
|
2020-03-07 21:12:30 -05:00
|
|
|
; ( a b -- b a )
|
|
|
|
.db "SWAP"
|
2020-03-12 11:39:27 -04:00
|
|
|
.fill 3
|
2020-03-14 17:48:24 -04:00
|
|
|
.dw DROP
|
2020-03-12 11:39:27 -04:00
|
|
|
.db 0
|
2020-03-09 15:12:44 -04:00
|
|
|
SWAP:
|
2020-03-07 21:12:30 -05:00
|
|
|
.dw nativeWord
|
|
|
|
pop hl
|
2020-03-17 14:56:08 -04:00
|
|
|
call chkPS
|
2020-03-07 21:12:30 -05:00
|
|
|
ex (sp), hl
|
|
|
|
push hl
|
2020-03-13 16:01:09 -04:00
|
|
|
jp next
|
2020-03-07 21:12:30 -05:00
|
|
|
|
2020-03-11 21:58:16 -04:00
|
|
|
; ( a b c d -- c d a b )
|
|
|
|
.db "2SWAP"
|
2020-03-12 11:39:27 -04:00
|
|
|
.fill 2
|
2020-03-11 21:58:16 -04:00
|
|
|
.dw SWAP
|
2020-03-12 11:39:27 -04:00
|
|
|
.db 0
|
2020-03-11 21:58:16 -04:00
|
|
|
SWAP2:
|
|
|
|
.dw nativeWord
|
|
|
|
pop de ; D
|
|
|
|
pop hl ; C
|
|
|
|
pop bc ; B
|
2020-03-17 14:56:08 -04:00
|
|
|
call chkPS
|
2020-03-11 21:58:16 -04:00
|
|
|
|
|
|
|
ex (sp), hl ; A in HL
|
|
|
|
push de ; D
|
|
|
|
push hl ; A
|
|
|
|
push bc ; B
|
2020-03-13 16:01:09 -04:00
|
|
|
jp next
|
2020-03-11 21:58:16 -04:00
|
|
|
|
2020-03-07 21:12:30 -05:00
|
|
|
; ( a -- a a )
|
|
|
|
.db "DUP"
|
2020-03-12 11:39:27 -04:00
|
|
|
.fill 4
|
2020-03-11 21:58:16 -04:00
|
|
|
.dw SWAP2
|
2020-03-12 11:39:27 -04:00
|
|
|
.db 0
|
2020-03-09 15:12:44 -04:00
|
|
|
DUP:
|
2020-03-07 21:12:30 -05:00
|
|
|
.dw nativeWord
|
|
|
|
pop hl
|
2020-03-17 14:56:08 -04:00
|
|
|
call chkPS
|
2020-03-07 21:12:30 -05:00
|
|
|
push hl
|
|
|
|
push hl
|
2020-03-13 16:01:09 -04:00
|
|
|
jp next
|
2020-03-07 21:12:30 -05:00
|
|
|
|
2020-03-11 21:58:16 -04:00
|
|
|
; ( a b -- a b a b )
|
|
|
|
.db "2DUP"
|
2020-03-12 11:39:27 -04:00
|
|
|
.fill 3
|
2020-03-11 21:58:16 -04:00
|
|
|
.dw DUP
|
2020-03-12 11:39:27 -04:00
|
|
|
.db 0
|
2020-03-11 21:58:16 -04:00
|
|
|
DUP2:
|
|
|
|
.dw nativeWord
|
|
|
|
pop hl ; B
|
|
|
|
pop de ; A
|
2020-03-17 14:56:08 -04:00
|
|
|
call chkPS
|
2020-03-11 21:58:16 -04:00
|
|
|
push de
|
|
|
|
push hl
|
|
|
|
push de
|
|
|
|
push hl
|
2020-03-13 16:01:09 -04:00
|
|
|
jp next
|
2020-03-11 21:58:16 -04:00
|
|
|
|
2020-03-07 21:12:30 -05:00
|
|
|
; ( a b -- a b a )
|
|
|
|
.db "OVER"
|
2020-03-12 11:39:27 -04:00
|
|
|
.fill 3
|
2020-03-11 21:58:16 -04:00
|
|
|
.dw DUP2
|
2020-03-12 11:39:27 -04:00
|
|
|
.db 0
|
2020-03-09 15:12:44 -04:00
|
|
|
OVER:
|
2020-03-07 21:12:30 -05:00
|
|
|
.dw nativeWord
|
|
|
|
pop hl ; B
|
|
|
|
pop de ; A
|
2020-03-17 14:56:08 -04:00
|
|
|
call chkPS
|
2020-03-07 21:12:30 -05:00
|
|
|
push de
|
|
|
|
push hl
|
|
|
|
push de
|
2020-03-13 16:01:09 -04:00
|
|
|
jp next
|
2020-03-07 21:12:30 -05:00
|
|
|
|
2020-03-11 21:58:16 -04:00
|
|
|
; ( a b c d -- a b c d a b )
|
|
|
|
.db "2OVER"
|
2020-03-12 11:39:27 -04:00
|
|
|
.fill 2
|
2020-03-11 21:58:16 -04:00
|
|
|
.dw OVER
|
2020-03-12 11:39:27 -04:00
|
|
|
.db 0
|
2020-03-11 21:58:16 -04:00
|
|
|
OVER2:
|
|
|
|
.dw nativeWord
|
|
|
|
pop hl ; D
|
|
|
|
pop de ; C
|
|
|
|
pop bc ; B
|
|
|
|
pop iy ; A
|
2020-03-17 14:56:08 -04:00
|
|
|
call chkPS
|
2020-03-11 21:58:16 -04:00
|
|
|
push iy ; A
|
|
|
|
push bc ; B
|
|
|
|
push de ; C
|
|
|
|
push hl ; D
|
|
|
|
push iy ; A
|
|
|
|
push bc ; B
|
2020-03-13 16:01:09 -04:00
|
|
|
jp next
|
2020-03-11 21:58:16 -04:00
|
|
|
|
2020-03-13 16:40:55 -04:00
|
|
|
.db ">R"
|
|
|
|
.fill 5
|
|
|
|
.dw OVER2
|
|
|
|
.db 0
|
|
|
|
P2R:
|
|
|
|
.dw nativeWord
|
|
|
|
pop hl
|
2020-03-17 14:56:08 -04:00
|
|
|
call chkPS
|
2020-03-13 16:40:55 -04:00
|
|
|
call pushRS
|
|
|
|
jp next
|
|
|
|
|
|
|
|
.db "R>"
|
|
|
|
.fill 5
|
|
|
|
.dw P2R
|
|
|
|
.db 0
|
|
|
|
R2P:
|
|
|
|
.dw nativeWord
|
|
|
|
call popRS
|
|
|
|
push hl
|
|
|
|
jp next
|
|
|
|
|
|
|
|
.db "I"
|
|
|
|
.fill 6
|
|
|
|
.dw R2P
|
|
|
|
.db 0
|
|
|
|
I:
|
|
|
|
.dw nativeWord
|
|
|
|
ld l, (ix)
|
|
|
|
ld h, (ix+1)
|
|
|
|
push hl
|
|
|
|
jp next
|
|
|
|
|
|
|
|
.db "I'"
|
|
|
|
.fill 5
|
|
|
|
.dw I
|
|
|
|
.db 0
|
|
|
|
IPRIME:
|
|
|
|
.dw nativeWord
|
|
|
|
ld l, (ix-2)
|
|
|
|
ld h, (ix-1)
|
|
|
|
push hl
|
|
|
|
jp next
|
|
|
|
|
|
|
|
.db "J"
|
|
|
|
.fill 6
|
|
|
|
.dw IPRIME
|
|
|
|
.db 0
|
|
|
|
J:
|
|
|
|
.dw nativeWord
|
|
|
|
ld l, (ix-4)
|
|
|
|
ld h, (ix-3)
|
|
|
|
push hl
|
|
|
|
jp next
|
|
|
|
|
2020-03-07 19:42:07 -05:00
|
|
|
; ( a b -- c ) A + B
|
|
|
|
.db "+"
|
2020-03-12 11:39:27 -04:00
|
|
|
.fill 6
|
2020-03-13 16:40:55 -04:00
|
|
|
.dw J
|
2020-03-12 11:39:27 -04:00
|
|
|
.db 0
|
2020-03-09 15:12:44 -04:00
|
|
|
PLUS:
|
2020-03-07 19:42:07 -05:00
|
|
|
.dw nativeWord
|
|
|
|
pop hl
|
|
|
|
pop de
|
2020-03-17 14:56:08 -04:00
|
|
|
call chkPS
|
2020-03-07 19:42:07 -05:00
|
|
|
add hl, de
|
|
|
|
push hl
|
2020-03-13 16:01:09 -04:00
|
|
|
jp next
|
2020-03-07 19:42:07 -05:00
|
|
|
|
|
|
|
; ( a b -- c ) A - B
|
|
|
|
.db "-"
|
2020-03-12 11:39:27 -04:00
|
|
|
.fill 6
|
2020-03-07 19:42:07 -05:00
|
|
|
.dw PLUS
|
2020-03-12 11:39:27 -04:00
|
|
|
.db 0
|
2020-03-09 15:12:44 -04:00
|
|
|
MINUS:
|
2020-03-07 19:42:07 -05:00
|
|
|
.dw nativeWord
|
|
|
|
pop de ; B
|
|
|
|
pop hl ; A
|
2020-03-17 14:56:08 -04:00
|
|
|
call chkPS
|
2020-03-07 19:42:07 -05:00
|
|
|
or a ; reset carry
|
|
|
|
sbc hl, de
|
|
|
|
push hl
|
2020-03-13 16:01:09 -04:00
|
|
|
jp next
|
2020-03-07 19:42:07 -05:00
|
|
|
|
|
|
|
; ( a b -- c ) A * B
|
|
|
|
.db "*"
|
2020-03-12 11:39:27 -04:00
|
|
|
.fill 6
|
2020-03-07 19:42:07 -05:00
|
|
|
.dw MINUS
|
2020-03-12 11:39:27 -04:00
|
|
|
.db 0
|
2020-03-09 15:12:44 -04:00
|
|
|
MULT:
|
2020-03-07 19:42:07 -05:00
|
|
|
.dw nativeWord
|
|
|
|
pop de
|
|
|
|
pop bc
|
2020-03-17 14:56:08 -04:00
|
|
|
call chkPS
|
2020-03-07 19:42:07 -05:00
|
|
|
call multDEBC
|
|
|
|
push hl
|
2020-03-13 16:01:09 -04:00
|
|
|
jp next
|
2020-03-07 19:42:07 -05:00
|
|
|
|
2020-03-16 22:36:29 -04:00
|
|
|
|
|
|
|
.db "/MOD"
|
|
|
|
.fill 3
|
2020-03-07 19:42:07 -05:00
|
|
|
.dw MULT
|
2020-03-12 11:39:27 -04:00
|
|
|
.db 0
|
2020-03-16 22:36:29 -04:00
|
|
|
DIVMOD:
|
2020-03-07 19:42:07 -05:00
|
|
|
.dw nativeWord
|
|
|
|
pop de
|
|
|
|
pop hl
|
2020-03-17 14:56:08 -04:00
|
|
|
call chkPS
|
2020-03-07 19:42:07 -05:00
|
|
|
call divide
|
2020-03-16 22:36:29 -04:00
|
|
|
push hl
|
2020-03-07 19:42:07 -05:00
|
|
|
push bc
|
2020-03-13 16:01:09 -04:00
|
|
|
jp next
|
2020-03-07 19:42:07 -05:00
|
|
|
|
2020-03-10 16:02:40 -04:00
|
|
|
; ( a1 a2 -- b )
|
|
|
|
.db "SCMP"
|
2020-03-12 11:39:27 -04:00
|
|
|
.fill 3
|
2020-03-16 22:36:29 -04:00
|
|
|
.dw DIVMOD
|
2020-03-12 11:39:27 -04:00
|
|
|
.db 0
|
2020-03-10 16:02:40 -04:00
|
|
|
SCMP:
|
|
|
|
.dw nativeWord
|
|
|
|
pop de
|
|
|
|
pop hl
|
2020-03-17 14:56:08 -04:00
|
|
|
call chkPS
|
2020-03-10 16:02:40 -04:00
|
|
|
call strcmp
|
|
|
|
call flagsToBC
|
|
|
|
push bc
|
2020-03-13 16:01:09 -04:00
|
|
|
jp next
|
2020-03-10 16:02:40 -04:00
|
|
|
|
|
|
|
; ( n1 n2 -- f )
|
|
|
|
.db "CMP"
|
2020-03-12 11:39:27 -04:00
|
|
|
.fill 4
|
2020-03-10 16:02:40 -04:00
|
|
|
.dw SCMP
|
2020-03-12 11:39:27 -04:00
|
|
|
.db 0
|
2020-03-10 16:02:40 -04:00
|
|
|
CMP:
|
|
|
|
.dw nativeWord
|
|
|
|
pop hl
|
|
|
|
pop de
|
2020-03-17 14:56:08 -04:00
|
|
|
call chkPS
|
2020-03-10 16:02:40 -04:00
|
|
|
or a ; clear carry
|
|
|
|
sbc hl, de
|
|
|
|
call flagsToBC
|
|
|
|
push bc
|
2020-03-13 16:01:09 -04:00
|
|
|
jp next
|
2020-03-10 16:02:40 -04:00
|
|
|
|
2020-03-14 09:23:58 -04:00
|
|
|
.db "SKIP?"
|
|
|
|
.fill 2
|
|
|
|
.dw CMP
|
|
|
|
.db 0
|
|
|
|
CSKIP:
|
|
|
|
.dw nativeWord
|
|
|
|
pop hl
|
2020-03-17 14:56:08 -04:00
|
|
|
call chkPS
|
2020-03-14 09:23:58 -04:00
|
|
|
ld a, h
|
|
|
|
or l
|
|
|
|
jp z, next ; False, do nothing.
|
|
|
|
ld hl, (IP)
|
|
|
|
call compSkip
|
|
|
|
ld (IP), hl
|
|
|
|
jp next
|
|
|
|
|
2020-03-12 21:16:20 -04:00
|
|
|
; This word's atom is followed by 1b *relative* offset (to the cell's addr) to
|
|
|
|
; where to branch to. For example, The branching cell of "IF THEN" would
|
|
|
|
; contain 3. Add this value to RS.
|
|
|
|
.db "(fbr)"
|
|
|
|
.fill 2
|
2020-03-14 09:23:58 -04:00
|
|
|
.dw CSKIP
|
2020-03-12 21:16:20 -04:00
|
|
|
.db 0
|
|
|
|
FBR:
|
|
|
|
.dw nativeWord
|
|
|
|
push de
|
2020-03-13 16:01:09 -04:00
|
|
|
ld hl, (IP)
|
2020-03-12 21:16:20 -04:00
|
|
|
ld a, (hl)
|
|
|
|
call addHL
|
2020-03-13 16:01:09 -04:00
|
|
|
ld (IP), hl
|
2020-03-12 21:16:20 -04:00
|
|
|
pop de
|
2020-03-13 16:01:09 -04:00
|
|
|
jp next
|
2020-03-12 21:16:20 -04:00
|
|
|
|
2020-03-15 22:46:17 -04:00
|
|
|
.db "(bbr)"
|
|
|
|
.fill 2
|
|
|
|
.dw FBR
|
|
|
|
.db 0
|
|
|
|
BBR:
|
|
|
|
.dw nativeWord
|
|
|
|
ld hl, (IP)
|
|
|
|
ld d, 0
|
|
|
|
ld e, (hl)
|
|
|
|
or a ; clear carry
|
|
|
|
sbc hl, de
|
|
|
|
ld (IP), hl
|
|
|
|
jp next
|
2020-03-10 16:02:40 -04:00
|
|
|
|
2020-03-15 22:46:17 -04:00
|
|
|
LATEST:
|
|
|
|
.dw BBR
|