6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri May 10, 2024 6:33 pm

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: IceForth for NES/Famicom
PostPosted: Tue Jul 09, 2019 2:08 am 
Offline

Joined: Tue Feb 06, 2018 7:39 pm
Posts: 3
IceForth is a Forth dialect I created for the NES. The idea is that NES programs could be developed on a special cartridge that has a 32kb battery-backed RAM chip with a Forth interpreter pre-loaded. The user defines new words in an interactive environment through an IO port on the NES until they are satisfied, then executes the word "freeze". This captures the state of the NES RAM, storing it in the cartridge memory to be restored. The contents of the development cartridge RAM can then be programmed into a ROM chip, and the ROM chip will startup with the word "thaw", which restores the state of the machine, and starts execution as if returning from freeze.

To simulate this workflow, I created an emulator for the NES processor with an additional IO port at an unused address. A write to this address will print a character to the console, and a read will return the next character of the last input line, blocking (perhaps unrealistically) if there are no lines of input available. If you ran this on a real NES (perhaps with the Family Basic Keyboard), you could of course change the definitions of these words to show on screen and read from the input device.

Some highlights:
- Uses subroutine threaded code. The dictionary grows downward from the end of memory and is at fixed addresses, while the word implementations grow upward from the start of cartridge space, and are theoretically relocatable.
- Many words have inline assembly
- Includes a postfix assembler and disassembler using something similar to Typist's assembler notation. The assembler instructions have both runtime and compile time semantics, so assembler macros are as simple as ": POP INX INX ;".
- Includes support for defining words in different dictionaries. Many of the words which are not probably relevant at the final run-time are defined in a memory area that is not included on the cartridge.
- I ported some of the neslib library which is written for CC65 C code, so that simple NES programs are fairly easy to write.
- I created a visualization which shows the memory space as a grid of pixels, and uses the emulator logs to replay the process of the memory space filling as the user compiles new words.

The initial implementation was based on Jones Forth, since it was a very clear explanation of how to bootstrap a Forth, but consequently it's not very compliant with ANS Forth.

I spent some time trying to work this whole thing into a literate file and get it running in the browser with interactivity, but I wasn't satisfied with the literate tool I was working with, and developing in a 5000 line file was too difficult. But it does contain some commentary on my implementation.

I haven't worked on this for almost a year now, but I figured I should put it out there in case anyone can learn something from it. Maybe someday I'll return to it.


Top
 Profile  
Reply with quote  
PostPosted: Tue Jul 09, 2019 6:48 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10800
Location: England
Oh, nice - is this is the first Jones Forth for the 6502?


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron