johanberntsson / ozmoo

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

Optimise mempointer use in read_byte_at_z_address #25

Closed ZornsLemma closed 3 years ago

ZornsLemma commented 3 years ago

By keeping the low byte of mempointer permanently zero and using the Y register to hold it instead, we can save (on a C64 VMEM build) five cycles in the "same page" case at the cost of one cycle in the "not same page" case.

If you accept this pull request, please double-check the zero page addresses I've chosen (marked with TODO: comments) are actually safe. I also just noticed the comment I added in constants-c128.asm incorrectly says mempointer_y takes 2 bytes; it should say 1 byte.

fredrikr commented 3 years ago

Looks good.

I suggest using address $08 on all platforms. It's a single, free address. $96 is free, but so is $97, so these might come in handy for a word value instead.

And write it just before $09 in the constant files.

And make sure the comment says it's a one-byte value.

ZornsLemma commented 3 years ago

Thanks Fredrik, I've pushed a commit to the same branch with those changes. I think this will give you the option to just click to pull the extra changes but if I need to raise a separate pull request just let me know.