Re: Compiling TaliForth2 on Windows
Posted: Thu Feb 06, 2020 4:37 pm
Here are some replacement DO group words for Tali that generate smaller inline code. They have been lightly tested.
The same code fragment as above is then compiled using the replacement words & disassembled using current standard Tali.
The same code fragment as above is then compiled using the replacement words & disassembled using current standard Tali.
Code: Select all
Tali Forth 2 kernel for 65816s (5 Jan 2020)
Tali Forth 2 for the 65c02
Version 1.0 24. Jan 2020
Copyright 2014-2020 Scot W. Stevenson
Tali Forth 2 comes with absolutely NO WARRANTY
Type 'bye' to exit
A=0002 X=0076 Y=0000 S=01F9 EnvMXdIzc D=0000 B=00 4A90FB02 00e014 lsr a
.@f_zz2.txt
.g
\ Replacement DO words for Tali that generate smaller inline code ok
\ 65c02 code done without Tali's assembler, so this will run on small Tali. ok
ok
decimal ok
5 nc-limit ! \ inline code up to 5 bytes ok
true strip-underflow ! \ remove underflow checking ok
ok
\ Labels for unlabelled Tali internal variables ok
0 constant User0 ok
User0 36 + constant tmp1 \ temporary storage ok
User0 38 + constant tmp2 \ temporary storage ok
User0 40 + constant tmp3 \ temporary storage (especially for print) ok
ok
hex ok
ok
: Branch, ( addr opcode -- ) \ compile a short or long 6502 branch compiled
over 1- 1- here - dup ff7f u> if compiled
swap c, c, drop \ opcode & displacement compiled
else compiled
drop 20 xor c, 3 c, \ opcode with reversed sense to branch around jmp compiled
4c c, , \ jmp compiled
then compiled
; ok
ok
: Do_Run [ ( limit start -- ) ( R: -- limit start ) \ DO runtime ok
7a68 , \ pla ply \ pop rts addr ok
1a c, 01d0 , c8 c, \ inc.a 1 bne iny ok
85 c, tmp2 c, 84 c, tmp2 1+ c, \ tmp2 sta.z tmp2 1+ sty.z ok
38 c, 00a9 , 02f5 , a8 c, \ sec 0 lda.# 2 sbc.zx tay \ push limit ok
80a9 , 03f5 , 85 c, tmp3 c, 5a48 , \ 80 lda.# 3 sbc.zx tmp3 sta.z pha phy ok
1898 , 0075 , a8 c, \ tya clc 0 adc.zx tay \ push index ok
01b5 , 65 c, tmp3 c, 5a48 , \ 1 lda.zx tmp3 adc.z pha phy ok
e8e8 , e8e8 , \ inx inx inx inx \ discard params ok
6c c, tmp2 , \ tmp2 jmp.i ok
] ; ok
ok
variable Do_Leave \ current LEAVE chain anchor ok
ok
: Do compiled
\ https://forth-standard.org/standard/core/DO compiled
Do_Leave @ \ save old leave ptr compiled
0 Do_Leave ! \ init compiled
['] Do_Run compile, compiled
here \ save do_addr to patch LOOP later compiled
; immediate compile-only redefined do ok
ok
: ?Do compiled
abort \ incomplete compiled
; immediate compile-only redefined ?do ok
ok
: Leave compiled
4c c, here Do_Leave @ , Do_Leave ! ; immediate compile-only redefined leave ok
ok
: +Loop_Run [ ( n -- ) \ +LOOP runtime ok
bada , a88a , fa c, \ phx tsx txa tay plx \ Y=S-1 ok
b918 , 104 , 0075 , 99 c, 104 , \ clc 104 lda.y 0 adc.zx 104 sta.y \ add to index ok
b9 c, 105 , 0175 , 99 c, 105 , \ 105 lda.y 1 adc.zx 105 sta.y ok
e8e8 , \ inx inx \ drop n ok
] ; never-native ok
ok
: Loop_Run [ \ LOOP runtime ok
bada , \ phx tsx ok
bd18 , 104 , 0169 , 9d c, 104 , \ clc 104 lda.x 1 adc.# 104 sta.x \ add to index ok
bd c, 105 , 0069 , 9d c, 105 , \ 105 lda.x 0 adc.# 105 sta.x ok
fa c, \ plx ok
] ; never-native ok
ok
: LoopEnd ( OldLeave do_addr -- ) compiled
50 Branch, \ bvc do_addr compiled
Do_Leave @ begin dup while \ patch leave chain compiled
dup @ swap here swap ! repeat drop compiled
Do_Leave ! \ restore OldLeave compiled
6868 , 6868 , \ pla pla pla pla discard loop variables compiled
; ok
: Loop compiled
['] Loop_Run compile, LoopEnd ; IMMEDIATE COMPILE-ONLY redefined loop ok
: +Loop compiled
['] +Loop_Run compile, LoopEnd ; IMMEDIATE COMPILE-ONLY redefined +loop ok
ok
: I [ ( -- n ) ok
bada , \ phx tsx ok
bd38 , 104 , fd c, 106 , a8 c, \ sec 104 lda.x 106 sbc.x tay ok
bd c, 105 , fd c, 107 , \ 105 lda.x 107 sbc.x ok
fa c, \ plx ok
caca , 0195 , 0094 , \ dex dex 1 sta.zx 0 sty.zx ok
] ; never-native redefined i ok
ok
: J [ ( -- n ) ok
bada , \ phx tsx ok
bd38 , 108 , fd c, 10a , a8 c, \ sec 108 lda.x 10a sbc.x tay ok
bd c, 109 , fd c, 10b , \ 109 lda.x 10b sbc.x ok
fa c, \ plx ok
caca , 0195 , 0094 , \ dex dex 1 sta.zx 0 sty.zx ok
] ; never-native redefined j ok
ok
decimal ok
here ' User0 - . \ display size of this part 598 ok
eof
ok
A=0002 X=0076 Y=0000 S=01F9 EnvMXdIzc D=0000 B=00 4A90FB02 00e014 lsr a
.@f_drozyak1.txt
.g
\ http://forum.6502.org/viewtopic.php?f=9&t=5911&start=30 ok
5 nc-limit ! \ limit inline code to <=5 bytes per word ok
true strip-underflow ! \ omit underflow checking code ok
ok
: 3drop drop 2drop ; ok
: r>> r> r> ; ok
create tiles 20 allot ok
create tile_colors 20 allot ok
ok
ok
: TileID> ( ID -- addr) \ look up tile address from ID. tiles is list of pointers to tile data compiled
cells tiles + @ ; ok
see tileID>
nt: AD6 xt: AE5
flags (CO AN IM NN UF HC): 0 0 0 1 0 1
size (decimal): 12
0AE5 20 CC A3 20 95 0A 20 65 99 20 70 8F .. .. e . p.
AE5 A3CC jsr cells
AE8 A95 jsr tiles
AEB 9965 jsr +
AEE 8F70 jsr @
ok
ok
: TileHW ( addr -- addr+2 w h) \ generate pointer to pixel data. fetch width and height compiled
dup c@ >r 1+ \ get width compiled
dup c@ >r 1+ \ get height compiled
r>> swap ; ok
see TileHW
nt: AF2 xt: B00
flags (CO AN IM NN UF HC): 0 0 0 1 0 1
size (decimal): 30
0B00 20 9F 8D 20 FB 85 20 EC A2 20 9F 97 20 9F 8D 20 .. .. . . .. ..
0B10 FB 85 20 EC A2 20 9F 97 20 81 0A 20 2A A1 .. .. .. .. *.
B00 8D9F jsr dup
B03 85FB jsr c@
B06 A2EC jsr >r
B09 979F jsr 1+
B0C 8D9F jsr dup
B0F 85FB jsr c@
B12 A2EC jsr >r
B15 979F jsr 1+
B18 A81 jsr r>>
B1B A12A jsr swap
ok
ok
: ColorID> ( ID -- addr ) \ look up color address from ID. tile_colors is list of pointers to color tables compiled
cells tile_colors + @ ; ok
see ColorID>
nt: B1F xt: B2F
flags (CO AN IM NN UF HC): 0 0 0 1 0 1
size (decimal): 12
0B2F 20 CC A3 20 BF 0A 20 65 99 20 70 8F .. .. e . p.
B2F A3CC jsr cells
B32 ABF jsr tile_colors
B35 9965 jsr +
B38 8F70 jsr @
ok
ok
: ColorTile ( tileID colorID -- ) compiled
ColorID> \ get address of color table from ID compiled
1+ dup c@ \ fetch length of color table compiled
swap 1+ \ point to color pairs compiled
rot compiled
TileID> TileHW nip \ stack: colorsize colorpair_addr tileaddr height compiled
0 do \ loop through all rows compiled
begin compiled
dup c@ \ get first byte of length,color pair compiled
swap 1+ swap \ increment tile pointer compiled
while compiled
rot dup >r -rot \ get size of color table compiled
r> 0 do \ loop through pairs in color table. stack: colorsize colorpairs tileaddr compiled
2dup c@ \ get color from tile compiled
swap i 2 * + dup >r c@ \ look up match color in color pair and save address compiled
= if \ if pair matches pixel from tile compiled
r> 1+ c@ \ get color to change pixel to from pair compiled
over c! \ store in tile compiled
leave \ color found so stop looping compiled
then compiled
r> drop \ get rid of unused address compiled
loop compiled
repeat compiled
loop compiled
3drop ; \ clean up stack ok
see ColorTile
nt: B3C xt: B4D
flags (CO AN IM NN UF HC): 0 0 0 1 0 1
size (decimal): 162
0B4D 20 2F 0B 20 9F 97 20 9F 8D 20 FB 85 20 2A A1 20 /. .. . . .. *.
0B5D 9F 97 20 D9 9A 20 E5 0A 20 00 0B 20 32 96 20 23 .. .. .. .. 2. #
0B6D A7 20 B2 08 20 9F 8D 20 FB 85 20 2A A1 20 9F 97 . .. .. .. *. ..
0B7D 20 2A A1 20 04 92 E3 0B 20 D9 9A 20 9F 8D 20 EC *. .... .. .. .
0B8D A2 20 5E 96 20 14 9A 20 23 A7 20 B2 08 20 34 A3 . ^. .. #. .. 4.
0B9D 20 FB 85 20 2A A1 20 2A 0A 20 23 A3 20 DC A0 20 .. *. * . #. ..
0BAD 65 99 20 9F 8D 20 EC A2 20 FB 85 20 BE 8E 20 04 e. .. .. .. .. .
0BBD 92 D2 0B 20 14 9A 20 9F 97 20 FB 85 20 15 98 20 ... .. . . .. ..
0BCD 05 86 4C DC 0B 20 14 9A E8 E8 20 88 09 50 BE 68 ..L.. .. .. ..P.h
0BDD 68 68 68 4C 71 0B 20 88 09 50 89 68 68 68 68 20 hhhLq. . .P.hhhh
0BED 70 0A p.
B4D B2F jsr ColorID>
B50 979F jsr 1+
B53 8D9F jsr dup
B56 85FB jsr c@
B59 A12A jsr swap
B5C 979F jsr 1+
B5F 9AD9 jsr rot
B62 AE5 jsr TileID>
B65 B00 jsr TileHW
B68 9632 jsr nip
B6B A723 jsr 0
B6E 8B2 jsr do
begin
B71 8D9F jsr dup
B74 85FB jsr c@
B77 A12A jsr swap
B7A 979F jsr 1+
B7D A12A jsr swap
B80 9204 jsr while
B83 ?
B84 ?
B85 9AD9 jsr rot
B88 8D9F jsr dup
B8B A2EC jsr >r
B8E 965E jsr -rot
B91 9A14 jsr r>
B94 A723 jsr 0
B97 8B2 jsr do
B9A A334 jsr 2dup
B9D 85FB jsr c@
BA0 A12A jsr swap
BA3 A2A jsr i
BA6 A323 jsr 2
BA9 A0DC jsr *
BAC 9965 jsr +
BAF 8D9F jsr dup
BB2 A2EC jsr >r
BB5 85FB jsr c@
BB8 8EBE jsr =
BBB 9204 jsr if
BBE B cmp.zi
BC0 9A14 jsr r>
BC3 979F jsr 1+
BC6 85FB jsr c@
BC9 9815 jsr over
BCC 8605 jsr c!
BCF BDC jmp leave
then
BD2 9A14 jsr r>
BD5 inx drop
BD6 inx
BD7 988 jsr loop
BDA BE bvc
BDC pla
BDD pla
BDE pla
BDF pla
BE0 B71 jmp repeat
BE3 988 jsr loop
BE6 89 bvc
BE8 pla
BE9 pla
BEA pla
BEB pla
BEC A70 jsr 3drop
ok
eof