The best place for machine language routines on the Commodore 64 is from $C000-$CFFF, assuming the routines are smaller than 4K bytes long. This section of memory is not disturbed by BASIC.
If for some reason it's not possible or desirable to put the machine language routine at $C000, for instance if the routine is larger than 4K bytes, it then becomes necessary to reserve an area at the top of memory from BASIC for the routine. The top of memory is normally $9FFF. The top of memory can be changed through the KERNAL routine MEMTOP, or by the following BASIC statements:
10 POKE51,L:POKE52,H:POKE55,1:POKE56,H:CLRWhere H and L are the high and low portions, respectively, of the new top of memory. For example, to reserve the area from $9000 to $9FFF for machine language, use the following:
There are 3 common methods to add the machine language programs to a BASIC program. They are:
By READing DATA statements, and POKEing the values into memory at the start of the program, machine language routines can be added. This is the easiest method. No special methods are needed to save the two parts of the program, and it is fairly easy to debug. The drawbacks include taking up more memory space, and the wait while the program is POKEd in. Therefore, this method is better for smaller routines. EXAMPLE:
10 RESTORE:FORX=1T09:READA:POKE12*4096+X,A:NEXT . . . BASIC PROGRAM . . . 1000 DATA 161,1,204,204,204,204,204,204,96
|This page has been created by Sami Rautiainen.|
|Read the small print.||Last updated December 17, 2002.|