[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: woz' original "brick out" - source code , paddles



In article <47225216$0$27120$9b4e6d93@newsspool1.arcor-online.net>,
Linards Ticmanis  <ticmanis@gmx.de> wrote:

> BluPhoenyx wrote:
> 
>> There are several ways to improve Applesoft speed without resorting to
>> assembly. Removing REM statements will help with both speed and size.
>> How much depends on how many REM statements exist and where they are in
>> the code.
>> 
>> Another useful trick is putting the most branched to lines at the front
>> of the program. Again, how much speed is gained depends on the program
>> and how much branching it uses.
>> 
>> Another minor trick is defining variables to ensure certain ones are
>> listed early in the variable table. However, this usually doesn't apply
>> to string variables. Yet again, this depends on the program.
> 
> One more: store all numbers that are used more than once in variables.
> Parsing numerical constants is quite slow in Applesoft, compared to a
> variable lookup.

If one switches to Apple CP/M and runs MBASIC v5 instead, several of those
problems vanishes:

MBASIC stores all numerical constants in binary format, making the
access to a constant faster than looking up variables in the variable
table.  It also distinguishes between integer constants and
floating-point constants (the f.p. constants comes in two flavors:
single precision and double precision, and you can specify which one
of them any particular f.p. xconstant should be).  And very small
integers (up to 10 or so) are stored in a particularly compact binary
format, making the access to these constants faster still.

When executing a GOTO or GOSUB, the MBASIC interpreter scans for the
target program line only once.  When the target line has been found,
the GOTO/GOSUB instruction is modified such that it contains the
machine address of the target program line rather than its line
number.  This of course makes listing the program slightly slower
since then the machine address needs to be converted back to a line
number, but that doesn't matter much.  If the program is modified in
some way (i.e. if a line is added, deleted, or modified), the MBASIC
interpreter scans through the whole program, converting GOTO/GOSUB
target machine address back to program lines before modifying the
program.  Finally, if the program is executed, making its GOTO/GOSUB
statements having their target lines converted to target machine
addresses, and if the program then is stored on disk in binary format
(the default format), the next time the MBASIC program is loaded from
disk, its GOTO/GOSUB statements will already have its targets as
machine addresses rather than as program lines!!!


The MBASIC which comes with Apple CP/M was MBASIC ver 5.  It comes in two
flavors: MBASIC.COM which is pretty much like the generic version of
MBASIC ver 5, and GBASIC.COM which has hi-res graphics routines added.

Applesoft is really MBASIC ver 2, the 6502 version, with additions and
modifications (such as the graphics routines) added by Apple.  Similar
interpreters were present in the Commodore PET, Vic-20, and 64: they
too were based om the 6502 version of MBASIC ver 2.

No MBASIC version later than ver 2 was ever available in a 6502
version.

-- 
----------------------------------------------------------------
Paul Schlyter,  Grev Turegatan 40,  SE-114 38 Stockholm,  SWEDEN
e-mail:  pausch at stockholm dot bostream dot se
WWW:     http://stjarnhimlen.se/