Quote:
Can you do that? I don't think it will be easy, but I think you can. You are essentially asking if you can metacompile (using one forth to target another system). This is often done to use forth on one system to compile itself for another (different) system, but it can also be used to generate a headerless executable. There have been Forths that can strip all of the header info and leave just a binary, but I haven't used any of them. I will warn you that you might be looking down a rather deep rabbit hole. Perhaps some of the others here will chime in if they have done anything like you are asking (compile a separate headerless binary).
Ok, down the rabbit hole I go. Let's see how far I get.
Quote:
Maybe it might be useful to switch off (or severely reduce) native compilation?
How do you mean? The inlining size?
Quote:
I'd quite like to understand what's going on with this game which makes it so large: it is certain that the game can't be more compact? (Having said which, how much memory are we talking about?)
My plan was to wait until all the versions were finished then show everything at once, but I can show what I have so far in case you have some suggestions for making things smaller. Here's a barebones
GitHub repo with the original version in Python, the CC65 version and the Tali Forth 2 version that I'm still working on (documentation and more comments to follow later.)
You can try the
CC65 version and
Tali Forth 2 versions in your browser at my website.
Keys:
WASD - move
space - mine/harvest/attack
c - character menu
k - skill menu
r - resource menu
The C version takes 27.4k of ROM and a few k of RAM. Because only 16k of ROM is visible at a time, several k of graphics data is copied from ROM to RAM in addition to the few k the game uses. Also, the key handling logic is in the bank of ROM that is normally hidden which holds the graphics to be copied into RAM since any updates to the screen can be done after the key logic is finished and the bank with that code is switched back to pointing at graphics memory.
The Forth version has three dictionaries: one in main ram, one in bank 2 that normally points to graphics memory but can be banked in when needed (just like the CC65 version above) and a third one at the end of ROM in the left over space not used by Tali. When you go to the page, you will see that bank 2 shows only 2k free, but this can be increased by another 16k by banking in the other bank that usually points to graphics memory, so there is no danger of running out of room there. The problem is that the 18k for code there can't draw to the screen, so I need to implement the menu system you see by pressing c, k, or r in the C version in the 3.6k left in main ram and main rom in the Forth version. Note that all the graphics data is loaded in the Forth version, so I just need to squeeze the rest of the code in.
There are a couple of obvious places to save code size. There are two 800 byte arrays in each version (the map is 40x20) with one byte for each map square. One holds the index of a monster if it exists on that square and the other holds the index of crystals. These could be combined to save 800 bytes, but then I would need extra code to separate them and extra time to do the processing, which would make it hard to compare that directly to the C version. If that 800 bytes were enough to hold the remaining code, I would consider it, but it will probably take a lot more than that, so I'll save that change for last. Also, the green selector box is technically the same 32x32 size as the robot and background tiles with transparency on all sides. Eliminating the transparency and shrinking the size then adding an offset would save maybe 50 bytes.
The graphics data is RLE encoded in pairs where one byte is the length and the next is the color. There is a 0 byte at the end of each row (ie pair with length zero and no color byte) which shows that row is finished. I could save a handful of bytes by eliminating those zeroes and changing the code to keep track of how many pixels have been drawn in the row, but I'm not sure it would be much of a gain. Some of the other data like the skill icons is stored with 1 bit per pixel.
Please let me know if anything is unclear. I plan to add more comments when the project is finished.