Showing posts with label Tali Forth 2. Show all posts
Showing posts with label Tali Forth 2. Show all posts

Sunday, December 11, 2022

Tali Forth 2 on Linux

When people on IRC have questions about Forth or I can't remember how a particular word works, it's nice to have a Forth handy to try things out on. For this, I usually open Tali Forth 2 in a browser window on my website. Even though it's a 6502 Forth running in a JavaScript 6502 emulator rather than a native x86 Forth like Gforth, it works just fine for experimenting. Since most of my programming is on Linux now, it seemed like a good idea to have a way to do my tests in a terminal.

There were several choices for getting Tali Forth 2 running on Linux. One of the easiest ways is to use an existing emulator like Py65 since Tali Forth 2 comes with a pre-compiled binary ready to be emulated. However, this was less interesting than using one of my own emulators. Another option was the JavaScript 6502 emulator running on my website. As mentioned in the post about my 6507 calculator, this also runs in a terminal thanks to node.js. Another option was to extract the emulation engine from my 6502 Interactive Assembler, although it seemed this would be time consuming to untangle since the emulator was not designed to work without the assembler. In the end, it was the most convenient to use the 6502 emulator written in MIPS assembly I've been working on for another project using the tools mentioned in my post about MIPS development in Linux. As mentioned in that post, a binary compiled for MIPS will run right from the Ubuntu command line as if it were native thanks to QEMU and also have access to the terminal through Linux syscalls. Going with this emulator was also an opportunity to double check my MIPS code emulates the 6502 correctly.

Thursday, July 9, 2020

Robot Game: 65C02 C, assembly, and Forth Comparison

The last six months or so, I have been working on a project to compare the performance of C, assembly, and Forth on the 65C02. This week I finally finished everything and published the results on my website. A few days later, the project was featured on Hackaday!

To compare the performance between the languages, I made a simple game called Robot Game in Python in order to have something to port. The C version is compiled with CC65 and the Forth version with Tali Forth 2. There are two assembly versions. One is plain 65C02 assembly using the X register as a data stack and the other uses the Assembly Optimizer I have been working on to get slightly better performance by putting locals in zero page at fixed addresses. All four version of the game work in my JavaScript-based emulator and can be played on my website. The source code for all the versions of the game, the emulator, and optimizer are now on my GitHub page.

Porting the four games was a challenge and also a lot of fun! I learned a lot about how C and especially Forth work internally. After I had the games ported, I looked at 28 different tasks the game does internally and compared performance across languages. Here are the results where traditional assembly is normalized at 100%:


The optimizer adds up to 10% performance and 25% in one very short routine. C was about 2-3 times slower than regular assembly in the tests and Forth was usually around 10-20 times slower. One of the really interesting things was figuring out why Forth is so much slower despite Forth fans claiming it's much better than C.