johanberntsson / ozmoo

A Z-machine interpreter for the Commodore 64 and similar computers
GNU General Public License v2.0
117 stars 19 forks source link

Move parse_terminating_characters to discardable init code in Z-machine stack #53

Closed ZornsLemma closed 1 year ago

ZornsLemma commented 2 years ago

I think parse_terminating_characters is only called once during initialisation, so 48 bytes can be saved for Z5+ games by moving it into the Z-machine stack. I've just done this on the Acorn port and it seems to work fine after five minutes' testing and I don't see any obvious reason this wouldn't work on the Commodore either. Maybe I've overlooked something, but this seems a nice little saving if I haven't...

fredrikr commented 2 years ago

Thanks for the idea!

We have a bit of a complex mess of build options, so depending on those, we may or may not have 48 bytes to spare in stack space.

E.g. If you build a z5 game for C64 with full error checking enabled (option -re), there's just 39 unused bytes in stack space.

Thus, we're careful about adding more code there.

We really should be putting together a test suite that builds a bunch of different games with different options, to make us more confident that additions and changes don't break something else.

ZornsLemma commented 2 years ago

Thanks Fredrik, that makes sense - I forgot how tight space can be in the Z-machine stack during initialisation. And I definitely know the feeling of having a complex mess of build options to worry about. :-)