Tuesday, March 27, 2018

Taking advantage of the new MC-10 ROM Part 2

You really don't have to do anything else software wise to speed up your code with the new ROM.  It speeds up everything around 5%.  However, there are some things you can do to make programs faster, most of which work with all MC-10 BASICs. 

Using ELSE will make some code a little faster, especially if you make the default condition the most often executed condition.

Example:
IF A=1 most.executed ELSE everything.else

You may have to reverse the logic:
IF A <= 1 least.executed ELSE most.executed

Becomes:
IF A > 1 most.executed ELSE least.executed

The reason for this is that the interpreter has to spend less time dealing with new lines, searching for lines, and less time searching for the end of a line.  The difference is small, but it adds up.
In this case, the > requires slightly less parsing than <= so that also makes the code slightly faster.


Things that will speed up all versions of MC-10 BASIC.

Declare your variables at the top of the program in order from most used to least used.  Just assign them to zero or whatever.  This places them in order in the variable table based on when they are created, and it will make the most use variables quicker to find when BASIC has to search through the table.  This is something common to all Microsoft BASICs I've looked at.  This can speed up some programs by several percent.

Remove all spaces and do not execute lines with REM statements.  This reduces the number of characters BASIC has to parse.  It is especially true of Microcolor BASIC.  Microsoft BASIC has a subroutine in RAM that searches for keyword tokens or other characters that it returns to the code that called it, and it skips spaces.  The MC-10 didn't have enough room in low RAM (the direct page) for all of the code, so it executes part of the code in RAM, then jumps to ROM to test what character was read.  If it's a token or other character it's looking for, it returns that.  If it's a space, it jumps back to the code in RAM to parse the next character.  So each space result in two two jumps and multiple tests of the character that aren't necessary if you simply delete the spaces.

The patch I posted that can be embedded in your program places the test for the most common item the parser finds (tokens) into RAM so it doesn't have to jump to the ROM as much, but spaces are still costly.  The patch does not work with MCX-BASIC, as that uses the addresses required for the patch.


Hardware changes.

The other thing you can do to take advantage of the new ROM is add a RAM expansion that places RAM immediately following the direct page.  This is hex address $100 on.  This allows the ROM to install the entire parse subroutine into RAM.  If no RAM exists at that address, it only installs the code to check for tokens like the patch.  The more of the subroutine that resides in RAM, the faster the interpreter runs.  Sadly, the Radio Shack RAM expansion does not support this.

No comments:

Post a Comment