Post by mas on Apr 25, 2024 12:08:51 GMT
So, we've all had the issue. We're about 95% complete with whatever we're coding and we hit that, "on the limit of available memory, things start acting crazy" issue. I've heard/ read that some people will manually hack at the engine.asm code to knock out code for routines they know their programme isn't using. (Common ones being things like the particle field, menu and inventory). Doing the same thing myself on my current game looks to have clawed back about 1K extra, which should be enough to complete it.
However, manually editing the engine.asm is a little error prone. I am no expert on z80 assembler, but I did have the "mastering machine code" book by Toni Baker (still have it... if only I could remember where I put it...) and the main thing that sticks in my brain is "C9 ret" .. so my hacking tends to be:
1. Follow the well commented source code (really appreciate good comments)
2. Find a routine I know I'm not using - e.g. the pop up menu and inventory
3. Comment the routine out (by preceeding the line with the semi colon;)
4. Add labels for the labels I've commented out in the asm that simply ret
e.g.
;;; don't think we're using this box routine
dbox ret
dbox0 ret
dbox1 ret
dbox ret
dbox0 ret
dbox1 ret
...
... etc.
5. recompile my game and check all the bits still work. Sometimes routines are "borrowed" by other functions. An example being something that ties the shrapnel to the ticker routine. (I'm expecting it's because the characters are added to the screen 1 pixel at a time it's using the plotting parts of it). Assuming everything works I continue. If it doesn't, I uncomment the assembler code and remove any labels I'd added.
6. check through the asm code and look for any jumps to the label. In many cases these can also be commented out. Some may well be in the code already commented out (and therefore not important)
7. check the game still works again.
8. remove the commented out code. (It's okay, I always keep a backup of the original engine for "next time" or "terrible code deletion" put it back, put it back...)
9. check the game still works.
10. Carry on working in MPAGD and hope the 1K-2Kish I've clawed back is enough or I'll have to repeat the process again.
What I'd like to see, however, is some sort or asm pre-processor that gets triggered during the build process intelligently looks at the functions you're using and only compiles the engine code you need to support them.
Is this "optimization" fuction already available?
Are there any tools out there that already do this?
I feel there isn't (or it would already be packaged with the MPAGD application). I also feel that my method of "hack and hope" isn't the most efficient and could potentially introduce unexpected behaviours if the wrong line is commented out, but not called often enough for me to notice during normal playtesting.
I'm assuming the problem with any auto-optimizer is it has to know how to strip out unnecessary bits of the engine; so I'm assuming it would have to load the engine.asm code and the MPAGD generated.asm code, and work out which bits of the MPAGD code is calling which bits of the engine, and then generate a temporary engine.asm with only the used functions + functions required to support those.
Has anyone produced something like this already?
Does it seem like something that would be viable to look into?
Is it just not possible because it would require an overhaul of the engine.asm code to support a more moduler approach to each of the functions - ie. a sort of "include inv, menu, shrapnel" identification and then within the main engine code, some sort of macros that go "if exists inv, menu, etc. add in an engine check here, else ignore"
This is definitely a "nice if it could" type of request rather than an "it must do this" type of request.
Do people just do the same as me?
I wonder what the "minimum" amount of engine.asm code is needed to allow a game to still work. How stripped back can it go?