Maya Grab [Day 18] – Every byte counts

Couple of days passed without journal updates because I was mainly busy on freeing up memory for the interpreter. Various tests had to be done, which parts of the code can be removed or optimized and also how the interpreter will work in the first place and how much space it will need. Practically I’ve learned nothing new, or what’s already mentioned in this very good article here.

First step was to remove all the comments from the code, it was clear already on the first day of coding that they are eating too much space. After that, wrapping up all data for sprites and machine code into less lines; each line can have up to 80 characters, so far I was using only 40 (makes the code easier to read). Same goes for the room drawing, and additionally I’ve added loops while drawing, even if a same line needs to be drawn only two times. It’s amazing who many bytes can be saved by doing a couple of quick fixes. Let’s see some numbers that I’ve written down during the process:

– removing start comments (lines 100-170)
  570 bytes saved
– removing interpreter usage comments (lines 20005-20115)
  426 bytes saved
– removing scope definition comments (eg. lines 55005-55015)
  700 bytes saved (100 bytes per scope)
– removing routine definition comments (eg. lines 55100-55110)
  3200 bytes saved (50 bytes per definition)
– removing double colons for separating chunks of code
  492 bytes saved
– removing adverbs definitions, interpreter has only a verb + noun parser
  694 bytes saved
– removing unused subroutines (wait and print free mem)
  154 bytes saved
– writing sprite data 12 bytes per line (earlier only 6)
  313 bytes saved
– writing machine code data 16 bytes per line (earlier only 4)
  242 bytes saved
– writing room rendering using 1 PRINT per line (earlier 2 or even 3)
  approx. 150 bytes saved per room

With less lines of code now calling subroutines or jumping works also much faster. There is still potential for shrinking the code further (and make it more ugly), but currently I’ve freed enough space for the upcoming things I have on my mind.

Nevertheless, the code that I’ll continue to include here will still have all the comments and colon separated lines, for easier reading and understanding.

* * * * *