Login
zeros2dots
Title:zeros2dots
Category:Utility/Programming
Release Date:
Language:(none)
Size:16K
Machine:PAL & NTSC
Code Type:Machine code
Distribution:Freeware
Code by:RoePipi
Notes: 
No votes yet.
zeros2dots Screenshot


Description
Purpose
-------
ZEROS2DOTS helps making BASIC programs faster by replacing all "0" characters to "." characters where applicable (not inside double quotes, and not as part of numbers or variables). It doesn't do other modifications. The program length remains the same. Of course, you can do other optimizations, like the ones in Basic Tricks.

Measurements show that using this method can make your BASIC programs run up to 30% faster. To prove it, try these commands:
TI$="000000":FOR A=1 TO 1000:B=0:NEXT:PRINT TI
TI$="000000":FOR A=1 TO 1000:B=.:NEXT:PRINT TI

The only difference is the "0" and "." character after "B=".
You can see the running times yourself (in 1/60th seconds).

Note that all single 0s in DATA lines are replaced, too. Normally it doesn't break the BASIC program's functioning.

Also note that running this program is fully your responsibility. Always make backups before doing presumably undoable changes. I've tested it on various (quite long, like Castle Matcher) programs of mine, and it worked flawlessly.

Thanks to Csabo for letting me know about this possibility.

Usage
-----
The BASIC program can be loaded before or after ZEROS2DOTS, just make sure you don't mess up the BASIC program pointers ($2D-$32). It's recommended to load it BEFORE loading your program, or, in MONITOR mode, with the L"ZEROS2DOTS",8 command to the default location ($0609). If you wish to transfer it to another location, use the command T 0609 0675 xxxx. Then, exit to BASIC with the command X.

To run, enter: SYS 1545 (or SYS DEC("xxxx") if you transferred it)
After a moment, "READY." is displayed. Replace is done, you can compare your new BASIC code with the original, e.g. using Plus4HTML by Istvan Bozsik.

Used memory locations
---------------------
$0609-$0675: code, freely replaceable (doesn't use absolute jumps).

$D1-$D2: actual BASIC line address vector
$D3-$D4: next BASIC line address vector
$D5: double quotes switch

Lines
-----
$0609 Disable interrupts
$060A Disable ROM (to access the whole BASIC area)
$060D Store address of starting BASIC line as next line
$0615 Set next BASIC line as actual
$061D Set double quotes switch to off
$0621 Store address of next BASIC line
$062A If high byte is 0, enable ROM and interrupts, exit
$0631 Skip BASIC line number, also used to advance the pointer the correct number of bytes
$0634 Fetch next byte
$0636 If 0 (BASIC line end), go to next line ($0615)
$0638 If double quotes, switch $D5 and go to next byte ($0633)
$0645 If not "0" character, go to next byte ($0633)
$0649 If double quotes switch is on, go to next byte ($0633)
$064D Go back one byte (examining the character before "0")
$064E If number ("0"-"9") or letter ("A"-"Z"), skip and go to next byte ($0632)
$0660 Go forward two bytes (to the next character after "0")
$0662 If number ("0"-"9"), treat it as the next byte to examine ($0634)
$066F Go back one byte and place a "." character, go to next byte ($0633)

Copyright © Plus/4 World Team, 2001-2024