How to make an ML routine part of a BASIC image

Basic and Machine Language

Moderator: Moderators

Post Reply
wimoos
Vic 20 Afficionado
Posts: 347
Joined: Tue Apr 14, 2009 8:15 am
Website: http://wimbasic.webs.com
Location: Netherlands
Occupation: farmer

How to make an ML routine part of a BASIC image

Post by wimoos »

If you have an ML routine that needs to be part of a BASIC program (in order to speed things up or some other reason), and the ML routine is relocatable, then you can do the following:

Determine the number of bytes that the routine needs.
Bump the pointer in 45:46 by that number of bytes.
Put the routine in that space.

SAVEing the program will include the ML routine.
Adding, modifying or deleting lines will not destroy your ML code, it stays there as long as you don't do a NEW.

Determine entry points of your routine relative to the contents of 45:46.

For an example check out the routine I developed for Jeff-20 at http://sleepingelephant.com/ipw-web/bul ... 5688#65688

The routine is relocatable and is 60 bytes long. The entry point is at the first location.

Load the routine first into e.g. the tapebuffer at 828.

Code: Select all

LOAD"PKW.PRG",8,1
Start with a clean slate

Code: Select all

NEW
Bump 45:46 by 60 bytes

Code: Select all

X=PEEK(45)+256*PEEK(46)
?X
(returns 1027 for example, remember it)

X=X+60:PRINT X AND 255; INT(X/256)
(results in 63 and 4 for example)

POKE 45,63:POKE 46,4:CLR
Copy your routine there

Code: Select all

FOR I=0 to 59:POKE 1027+I,PEEK(828+I):NEXT
During the initialisation of your program do the following:

Code: Select all

10 X=PEEK(45)+256*PEEK(46)-60
20 POKE1,XAND255:POKE2,X/256
Then, in your program you can use

Code: Select all

110 K$=USR(131)
Editing the BASIC program is without constraints, except when you do a NEW. Saveing the program will happily save the BASIC part plus the ML part. Loading again will put it all back in place.

Regards,

Wim
Last edited by wimoos on Mon Apr 30, 2012 11:24 am, edited 7 times in total.
VICE; selfwritten 65asmgen; tasm; maintainer of WimBasic
User avatar
Witzo
Vic 20 Afficionado
Posts: 381
Joined: Thu Dec 01, 2011 9:14 am
Location: The Hague

Post by Witzo »

I will remember this for future reference.
Post Reply