2 ms·
Oddly enough I discovered Forth when I was developing a game a few years ago. The idea for the game was that you pilot a space ship, but your only interface wa
by fpgaminer 7y ago
Oddly enough I discovered Forth when I was developing a game a few years ago.
The idea for the game was that you pilot a space ship, but your only interface was a C64-like clone. You'd have to write programs to navigate, make jumps, and explore the galaxy. Connect to space stations using a modem, and dial into their local BBS for buying and selling goods.
So I built a 6502 emulator and emulated hardware for all the subsystems (display, disk, engines, modem, etc). It really was a legit emulated system ... just that some of the addressable hardware was a space ship :P
I started out using a modified KERNAL ROM with BASIC, but ran into problems. In the first iterations of the game all the subsystems were a bit too realistic. For sensors you'd have to manually move the sensor beam around and read out results constantly. For the engines you have to manually adjust the engine thrust and read back velocity information. Same with the jump mechanic.
I figured making the subsystems realistic, as if they were real hardware that you had to write firmware for, would be interesting. But coding the "firmware" in BASIC was a nightmare, and so slow. The jump subsystem was especially problematic, because the velocity was so high. The program would point your ship at a space station in the local system, engage jump drives, and then constantly monitor distance to the station and try to disengage once you got close enough. But because of the high speeds and the need for large integers to represent the distances, the program just couldn't PEEK and react fast enough. I could never get it accurate enough to drop out of jump close to the station. So you'd spend 10 minutes crawling over there with your sub-lightspeed drives the jump.
And on top of those speed issues, BASIC was too much of a PITA when you had to do a lot of hardware manipulation and processing of large numbers (like the vast distances of space...).
So after hacking on that for awhile I looked for a better alternative. That's when I stumbled into Forth. There's an actively developed Forth for C64 (https://github.com/jkotlinski/durexforth https://github.com/jkotlinski/durexforth) which even included a Vi implementation. So I could get a nicer, faster language and an editor in one package!
A bit of hacking later, and it really was a massive improvement. It was especially nice having VI.
I ended up ditching a lot of the hardcore realism in the subsystems. Even with DurexForth, which was significantly faster and handled the math better, it was still problematic coding what should be fundamental programs in this game. And it certainly wasn't fun (if a game like this could ever be considered fun).
But the journey gave me a lot of exposure to Forth, and it is such an interesting language. I definitely recommend playing with Forth, at least for a weekend, just for fun and to expand your mind a little.
P.S. As for the game, it's collecting dust. One of these days I'd like to dust it off and get back to it; I find the idea of it terribly seductive. It's like a new genre: 6502-Punk :P But I'm half tempted to drop back to BASIC, since Forth is such a foreign experience. I'd probably continue simplifying the subsystems, add a floating point co-processor, and mod BASIC to use large hardware backed floats, just to make everything easy.