Manual
User Manual:
Open the PDF directly: View PDF .
Page Count: 42





kernel
Tali Forth 2 default kernel for py65mon (18. Feb 2018)
Tali Forth 2 for the 65c02
Version ALPHA 07. Mar 2018
Copyright 2014-2018 Scot W. Stevenson
Tali Forth 2 comes with absolutely NO WARRANTY
Type ’bye’ to exit
forth_words.fs
user_words.fs
dump
see within to d.r d. ud.r ud. .r u.r */mod */ mod /mod /
action-of is defer@ defer! while until repeat else then
if .( ( drop dup swap ! @ over >r r> r@ nip rot -rot tuck
, c@ c! +! execute emit type . u. ? false true space 0 1
2 2dup ?dup + - abs dabs and or xor rshift lshift pick char
[char] char+ chars cells cell+ here 1- 1+ 2* = <> < > 0=
0<> 0> 0< min max 2drop 2swap 2over 2variable 2r@ 2r> 2>r
invert negate dnegate c, bounds spaces bl -trailing /string
refill accept unused depth key allot create does> variable
constant value s>d d>s d- d+ erase blank fill find-name ’
[’] name>int int>name name>string >body defer latestxt
latestnt parse-name parse source source-id : ; compile, [ ]

0branch branch literal sliteral ." s" postpone immediate
compile-only never-native always-native nc-limit abort
abort" do ?do i j loop +loop exit unloop leave recurse quit
begin again state evaluate base digit? number >number hex
decimal count m* um* * um/mod ud/mod sm/rem fm/mod \ move
cmove> cmove pad >in <# # #s #> hold sign output input cr
page at-xy marker words wordsize aligned align bell dump .s
find word cold bye
words
drop bye drop
see
CONTROL-p CONTROL-n
bounds
nc-limit
•0branch (f–)
if cs-pick cs-roll
•0(–0)
•1(–1)
•2(–2)
•always-native(–)
•bell (–)
•branch( – ) if
cs-pick cs-roll
•compile-only (–)
•digit? (char–uf|charf)
•input ( – addr )
emit
•int>name (xt–nt)

•latestnt (–nt)
latest
•nc-limit( – addr )
nc-limit ?
•never-native (–)
•number ( addr u – u | d ) s>number?
•output ( – addr )
emit
•uf-strip ( – addr )
uf-strip ?
•wordsize (nt–u)
nc-limit
nc-limit ?
40 nc-limit !
uf-strip
true
cold



definitions.asm
$0100
$007f
$78 $7F
dsp0
dsp0
dex
+--------------+
| ... |
+- -+
| | ...
+- (empty) -+
| | FE,X
+- -+
... | | FF,X
+==============+
$0076 | LSB| 00,X <-- DSP (X Register)
+- TOS -+
$0077 | MSB| 01,X
+==============+
$0078 | (garbage) | 02,X <-- DSP0
+--------------+
$0079 | | 03,X
+ (floodplain) +
$007A | | 04,X
+--------------+

02,X
04,X
cpx #dsp0-1
bmi okay
jmp underflow
okay:
(...)
+---------------+
| |
+===============+
| LSB| $0,x <-- DSP (X Register)
+-+ Top Cell -+
|S| MSB| $1,x
+-+-------------+
| LSB| $2,x
+- Bottom Cell -+
| MSB| $3,x
+===============+

8 bit 8 bit
LSB MSB
nt_word -> +--------+--------+
+0 | Length | Status |
+--------+--------+
+2 | Next Header | nt_next_word
+-----------------+
+4 | Start of Code | xt_word
+-----------------+
+6 | End of Code | z_word
+--------+--------+
+8 | Name | |
+--------+--------+
|||
+--------+--------+
| | ... |
+n +--------+--------+
name token nt_word
status byte
definitions.asm
0000
bye
xt_word
z_word
native_words.asm
user_words.asm
drop
bye
words

$0000 +-------------------+ ram_start, zpage, user0
| User varliables |
+-------------------+
| |
| ^ Data Stack | <-- dsp
| | |
$0078 +-------------------+ dsp0, stack
| |
| (Reserved for |
| kernel) |
| |
$0100 +===================+
| |
| ^ Return Stack | <-- rsp
| | |
$0200 +-------------------+ rsp0, buffer, buffer0
| | |
| v Input Buffer |
| |
$0300 +-------------------+ cp0
| | |
| v Dictionary |
| (RAM) |
| |
~~~~~~~~~~~~~~~~~~~~~ <-- cp
| |
| |
+-------------------+
| |
| ACCEPT history |
| |
$7FFF ##################### ram_end
$8000 | | forth, code0
| |
| |
| Tali Forth |
| (24 KiB) |
| |
| |
$E000 +-------------------+
| | kernel_putc, kernel_getc
| Kernel |
| |
$F000 +-------------------+
| I/O addresses |
+-------------------+
| |
| Kernel |
| |
$FFFA +-------------------+
| 65c02 vectors |
$FFFF +-------------------+
definitions.txt

CREATE DOES>
constant
constant
jsr CREATE
jsr COMMA
jsr (DOES>) ; from DOES>
a: jsr DODOES ; from DOES>
b: jsr FETCH
rts
does>
(does>)
dodoes dovar
defer
: defer create [’] abort , does> @ execute ;
defer
(does>) dodoes does>
constant life
42 constant life
rts
(1) RTS ; to main routine
constant
(Header "LIFE")
jsr DOVAR ; in CFA, from LIFE’s CREATE
4200 ; in PFA (little-endian)
jsr (does>)
constant
(2) RTS to CONSTANT ("a")
(1) RTS to main routine
(does>) dovar
jsr life
(Header "LIFE")
jsr a ; in CFA, modified by (DOES>)
c: 4200 ; in PFA (little-endian)
(does>) rts rtrs
constant dodoes fetch
life
life
(does>)

CREATE DOES>
jsr LIFE
(1) RTS to main
life constant rts
life
(2) RTS to LIFE ("c")
(1) RTS to main
jsr dodoes constant
(3) RTS to CONSTANT ("b")
(2) RTS to LIFE ("c")
(1) RTS to main
dodoes
dodoes rts life
life dodoes
dovar
rts
[1] RTS to main
constant
constant fetch
does> jmp
jsr
jmp (z)
constant fetch
fetch
constant rts
does> (does>) dodoes
(does>) dodoes constant
dovar life
dodoes constant
life jmp
jsr
rts jsr
inc z
bne +
inc z+1
* (...)
create/does>

if/then
0branch
then
0branch if
then
0branch
: if postpone 0branch here 0 , ; immediate
: then here swap ! ; immediate
then
if else
branch if
: else postpone branch here 0 , here rot ! ; immediate
then
else if
do ?do loop +loop unloop leave
loop +loop
?do leave
leave ?do
if/then
do loop
do
•here
•
•do
•here loop
do
•
loop +loop
cs-pick cs-roll branch

loop
•(+loop)
•
•unloop
•
do
•
loop (+loop)
•
•
unloop
pla do
leave pla
[char]
: [char] char postpone literal ; immediate
jsr xt_char
jsr xt_literal
jsr/rts
drop
inx
inx
drop
cpx #dsp0-1
bmi +
lda #11 ; error code for underflow
jmp error
*
inx
inx

nc-
limit
nc-limit
: aaa 0 drop ;
see
see aaa
nt: 7CD xt: 7D8
size (decimal): 6
07D8 20 52 99 20 6B 88 ok
aaa
drop
20 nc-limit ! ok
: bbb 0 drop ; ok
see bbb
nt: 7DF xt: 7EA
size (decimal): 17
07EA CA CA 74 00 74 01 E0 77 30 05 A9 0B 4C C7 AC E8
07FA E8 ok
bbb aaa
drop
words&sizes
user_words.fs
: words&sizes ( -- )
latestnt
begin
dup
0<> while
dup name>string type space
dup wordsize u. cr
2+@
repeat
drop ;
see
nc-limit
r> >r r@ 2r> 2>r
>r
xt_r_from:
pla
sta tmptos

ply
; --- CUT FOR NATIVE CODING ---
dex
dex
pla
sta 0,x
pla
sta 1,x
; --- CUT FOR NATIVE CODING ---
phy
lda tmptos
pha
z_r_from: rts
compile,
uf-strip true
>r
xt_to_r:
pla
sta tmptos
ply
; --- CUT HERE FOR NATIVE CODING ---
cpx #dsp0-1
bmi +
jmp underflow
*
lda 1,x
pha
lda 0,x
pha
inx
inx
; --- CUT HERE FOR NATIVE CODING ---
phy
lda tmptos
pha
z_to_r: rts

CMOVE, CMOVE> MOVE
cmove, cmove> move
cmove cmove> move
cmove cmove>
move
cmove cmove>
move
create testbuf char a c, char b c, char c c, char d c, ( ok )
testbuf 4 type ( abcd ok )
testbuf dup char+ 3 cmove ( ok )
testbuf 4 type ( aaaa ok )
move
testbuf dup char+ 3 move ( ok )
testbuf 4 type ( aabc ok )
move

+--------------+
| ... |
+- -+
| | ...
+- (empty) -+
| | FE,X
+- -+
... | | FF,X
+==============+
$0076 | LSB| 00,X <-- DSP (X Register)
+- TOS -+
$0077 | MSB| 01,X
+==============+
$0078 | (garbage) | 02,X <-- DSP0
+--------------+
$0079 | | 03,X
+ (floodplain) +
$007A | | 04,X
+--------------+
drop
inx
inx
push
dex
dex
lda $<LSB> ; or pla, jsr kernel_getc, etc.
sta 0,x
lda $<LSB> ; or pla, jsr kernel_getc, etc.
sta 1,x
pop
lda 0,x
sta $<LSB> ; or pha, jsr kernel_putc, etc
lda 1,x
sta $<MSB> ; or pha, jsr kernel_putc, etc
inx
inx

#
~/.vimrc .asm
ab drop# inx<tab><tab>; drop<cr>inx<cr><left>
ab push# dex<tab><tab>; push<cr>dex<cr>lda $<LSB><cr>sta $00,x<cr>lda
$<MSB><cr>sta $01,x<cr><up><up><up><up><end>
ab pop# lda $00,x<tab><tab>; pop<cr>sta $<LSB><cr>lda $01,x<cr>sta $<
MSB><cr>inx<cr>inx<cr><up><up><up><up><up><end>


tests
talitest.py
Talitest.py pexpect