Tali Forth for the 65c02

Topics relating to various Forth models on the 6502, 65816, and related microprocessors and microcontrollers.
Post Reply
nyef
Posts: 235
Joined: 28 Jul 2013

Re: Introducing Tali Forth for the 65c02 (ALPHA)

Post by nyef »

LEAVE seems fairly obvious to me for some reason.

Given an implementation of DO as:

Code: Select all

: *do 2>R ;
: DO [COMPILE] *do 0 HERE ; IMMEDIATE
And LEAVE as:

Code: Select all

: LEAVE [COMPILE] UNLOOP >R >R AHEAD R> 1+ R> ; IMMEDIATE;
You then have a point when compiling LOOP and +LOOP where you have ( orig1 .. orign n ) on the data stack (each orig from calling AHEAD) and need to invoke THEN n times to resolve each orig... Which you basically have to do for END-CASE anyway. There is sample code in section A.3.2.3.2 of the ANS standard for the CASE-related bits.

This is an untested implementation sketch: My current Forth implementation contains neither DO .. LOOP nor CASE .. END-CASE at this point.
User avatar
barrym95838
Posts: 2056
Joined: 30 Jun 2013
Location: Sacramento, CA, USA

Re: Introducing Tali Forth for the 65c02 (ALPHA)

Post by barrym95838 »

theGSman wrote:
... Cleaning up the stack is a common necessity at the end of a word.
I suppose it could be argued that "better" factoring would make that necessity much less common, but I can see your point, even through the eyes of a n00b.

Mike B.
theGSman
Posts: 85
Joined: 26 Jan 2015

Re: Introducing Tali Forth for the 65c02 (ALPHA)

Post by theGSman »

nyef wrote:

Code: Select all

: LEAVE [COMPILE] UNLOOP >R >R AHEAD R> 1+ R> ; IMMEDIATE;
It seems to me that a SWAP would also be in order since the usual context of this word is IF LEAVE THEN and we don't want the stack to be messed up when coding the THEN statement.

I still don't see how it would work if you were using LEAVE from within a nested IF statement.
theGSman
Posts: 85
Joined: 26 Jan 2015

Re: Introducing Tali Forth for the 65c02 (ALPHA)

Post by theGSman »

barrym95838 wrote:
I suppose it could be argued that "better" factoring would make that necessity much less common, but I can see your point, even through the eyes of a n00b.
Factoring may reduce the number of stack items you have to handle at any one time but it is unlikely to change the cleanup requirements at the end of a word.

It is true however that you can keep stack cleanup to a minimum if you code carefully.
User avatar
GARTHWILSON
Forum Moderator
Posts: 8774
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: Introducing Tali Forth for the 65c02 (ALPHA)

Post by GARTHWILSON »

Quote:
I still don't see how it would work if you were using LEAVE from within a nested IF statement.
Compiler security checking would have to be left out. I do leave it out, and I'm just careful, and have never had a problem.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
scotws
Posts: 576
Joined: 07 Jan 2013
Location: Just outside Berlin, Germany
Contact:

Re: Introducing Tali Forth for the 65c02 (ALPHA)

Post by scotws »

(In case somebody is reading this thread and wondering where the rest of the discussion went: How to do DO/LEAVE/IF etc was handled in viewtopic.php?f=9&t=3176 with code.)
scotws
Posts: 576
Joined: 07 Jan 2013
Location: Just outside Berlin, Germany
Contact:

Re: Introducing Tali Forth for the 65c02 (ALPHA)

Post by scotws »

With the addition of RECURSE, I've decided to consider Tali Forth "feature complete" and now in BETA. Yippie! This means no more new words for now, because we start optimizing and hunting bugs.

The "frozen" word set is:

Code: Select all

ACTION-OF IS REPEAT WHILE UNTIL ELSE IF WORDS DROP 2DROP ! @ ? 2R> 2R@ 2>R >R R> R@ OVER 2OVER DUP ?DUP 2DUP SWAP 2SWAP NIP TUCK ROT -ROT PICK DEPTH 1- 1+ FALSE TRUE BRANCH (BRANCH) 0BRANCH (0BRANCH) BEGIN AGAIN THEN DO ?DO (DO) (?DO) I J UNLOOP LOOP +LOOP (+LOOP) LEAVE RECURSE ABS DABS + - * / */ */MOD UM* M* UM/MOD UD/MOD SM/REM FM/MOD MOD /MOD M+ AND OR XOR INVERT NEGATE DNEGATE MAX MIN LSHIFT RSHIFT S>D D>S D+ D- <# # #S HOLD SIGN #> U. U.R UD. . .R D. D.R 2 1 0 < = > 0= 0< COUNT >IN TYPE EMIT CHAR [CHAR] TOUPPER KEY BASE HERE PAD UNUSED MARKER ERASE FILL CELL+ CELLS CHAR+ CHARS C, C! C@ CMOVE CMOVE> MOVE ALIGN ALIGNED ALLOT , DEFER@ DEFER! DEFER ' ['] >BODY >NAME EXECUTE EVALUATE STATE COMPILE, : ; ] [ POSTPONE IMMEDIATE COMPILE-ONLY NATIVE-COMPILE CREATE DOES> (DOES>) VARIABLE 2VARIABLE TO VALUE CONSTANT +! SOURCE DECIMAL HEX BINARY DIGIT>NUMBER NUMBER >NUMBER BL CR SPACE SPACES AT-XY PAGE BOLD REGULAR BELL ." S" .( ( \ /STRING -TRAILING FIND ACCEPT PARSE PARSE-NAME WORD .S SEE DUMP (ABORT") ABORT" QUIT ABORT LITERAL (LITERAL) COLD BYE
GitHub has the code to browse at https://github.com/scotws/TaliForth , and the ophis.bin file should run with py65 as described in README.txt . As always, I'm very grateful for any suggestions, corrections, and feedback.
theGSman
Posts: 85
Joined: 26 Jan 2015

Re: Introducing Tali Forth for the 65c02 (ALPHA)

Post by theGSman »

scotws wrote:
With the addition of RECURSE, ..............
RECURSIVEness was the easiest thing for me to do.

While the current word is being defined, a "smudge" bit is set in the name so that the word wont be found during a word search. Thus, if another word of the same name exists, it will be found instead.

To make the current word that is being defined recursive, all I need is a compiler word named RECURSIVE that removes the smudge bit. Interestingly, RECURSIVE can be placed anywhere within the current word prior to the word being called although placing it just after the name of the word aids readability.

Example:

Code: Select all

: FACTORIAL ( n -- n! ) RECURSIVE
    DUP 1 <= IF EXIT THEN
    DUP 1 - FACTORIAL *
;
mstram
Posts: 39
Joined: 26 Dec 2009

Re: Introducing Tali Forth for the 65c02 (ALPHA)

Post by mstram »

As you know Scott, I just got Taliforth running on py65mon, thanks to some very quick bug fixes by the py65mon author.

I was thinking of trying to get it running on the Vice emulator.

Are there any "challenges" with that ?

And if not, I'm wondering why you didn't target that emulator from the beginning ?

Seems to me to be much more "feature-full" than py65mon.

Mike
scotws
Posts: 576
Joined: 07 Jan 2013
Location: Just outside Berlin, Germany
Contact:

Re: Introducing Tali Forth for the 65c02 (ALPHA)

Post by scotws »

I wasn't looking for something full-featured, I was looking for something that was simple to use and that would work from the command line in OS X and Linux. Also, the web page of Vice said something about "last release 2012" (still does, see http://vice-emu.sourceforge.net/ ) so I figured it wasn't being developed any more.

Py65mon has been fantastic for me, except for the part with the magic numbers for the getc and putc ports. I still don't understand why that is not in a config file or a value from the command line.
Martin_H
Posts: 837
Joined: 08 Jan 2014

Re: Introducing Tali Forth for the 65c02 (ALPHA)

Post by Martin_H »

I finally got around to installing the ophis assembler and built Tali Forth. I then adjusted the RAM size to fit my machine, and then changed the 6522 VIA address. I have a 6551 ACIA instead of a 6850 ACIA UART, so that looks like the biggest source of incompatibility.

Quick question. Is the output format of Ophis in the same format as the output of the TASS assembler? If so then my home brew EEPROM programmer is compatible.
Martin_H
Posts: 837
Joined: 08 Jan 2014

Re: Introducing Tali Forth for the 65c02 (ALPHA)

Post by Martin_H »

I was able to change the serial code to use the 6551 ACIA, which only took me about an hour. It wasn't much work, but I double checked everything because I wanted the best shot of getting it to work first time. I then tried the Ophis bin file with my home brew EEPROM programmer and it is compatible with Intel hex file format. So I was able to use my home brew EEPROM programmer.

I then put the EEPROM into my 6502 machine, turned it on and was greeted with the Forth ok prompt. I typed 1 2 + . and it output 3, so success. There's only one small problem with each new line being indented from the last. I'll need to figure that out, but that seems small.
scotws
Posts: 576
Joined: 07 Jan 2013
Location: Just outside Berlin, Germany
Contact:

Re: Introducing Tali Forth for the 65c02 (ALPHA)

Post by scotws »

Great to hear, I'm glad it's working for you! Please let me know if you have any suggestions ...
rwiker
Posts: 294
Joined: 03 Mar 2011

Re: Introducing Tali Forth for the 65c02 (ALPHA)

Post by rwiker »

Since scotws in another thread asked for suggestions for the rewrite of Tali Forth:

1) Move the handling of multiple I/O channels out from the common sources (Tali-Forth.asm), and into the platform-dependent part (Tali-Kernel-<platform>.asm). That will remove one of the few remaining platform dependencies from Tali-Forth.asm.

2) Add an I/O driver for reading characters from memory. This could then be used for reading/parsing/compiling the high-level Forth words from memory at startup in a slightly less complex way than the current implementation. (Possibly using a newline-separated sequence of definitions, with a "bye" at the end to close the channel and return to the initalization code.)
scotws
Posts: 576
Joined: 07 Jan 2013
Location: Just outside Berlin, Germany
Contact:

Re: Introducing Tali Forth for the 65c02 (ALPHA)

Post by scotws »

Thanks for both suggestions. Suggestion 2 is already realized in Liara Forth (65816), and works a lot better. Suggestion 1 is a major reason I want to rewrite it - again, Liara Forth does this so much better in an ANSI fashion.

I'll be opening a new repository for work on Tali 2 in the next couple of days I hope.
Post Reply