fastbasic icon indicating copy to clipboard operation
fastbasic copied to clipboard

Enhancement Request: BLOAD

Open MariusAtarius opened this issue 1 year ago • 3 comments

Usually I combine assembler created objects with Basic. BLOAD would make life easier if you still want to combine Basic with external binary objects. Sure it still is possible to do a BGET, skip the first 6 bytes, and then BGET the rest of the file, but everytime when I make updates to the .OBJ file I have to adapt the routine in FastBasic to let FastBasic know how many bytes should be loaded. With just a BLOAD it would be a lot easier.

MariusAtarius avatar Sep 29 '24 09:09 MariusAtarius

Just don't skip those 6 bytes but use them as parameters for the BGET statement.

vitococl avatar Jan 05 '25 12:01 vitococl

Just don't skip those 6 bytes but use them as parameters for the BGET statement.

Unbelievable how I didn't come up with this. It is actually a very good idea. But then again: is it possible to use variables after the BGET command? I guess yes, but i try to visualize it. Thanks for the brilliant idea, it will fix the absence of a BLOAD command.

MariusAtarius avatar Jan 05 '25 13:01 MariusAtarius

This is a sample program:

' Create sample OBJ file:
OPEN #1,8,0,"D:TEST.OBJ"
? #1,""$FF$FF$00$06$06$06$06$48$65$6C$6C$6F$21;
CLOSE #1

' Read the file:
FIRST=0
LAST=0
OPEN #1,4,0,"D:TEST.OBJ"
BGET #1,&FIRST,2:' discard $FFFF
BGET #1,&FIRST,2
BGET #1,&LAST,2
BGET #1,FIRST,LAST-FIRST+1
CLOSE #1
? FIRST
? LAST
? $($600)

The first part creates a sample object file with binary headers to be loaded at page 6. It contains just a FastBasic string to be printed, no assembled code. I know, there are too many $06 bytes in this file ;-)

The &() function in the first parameter of some BGET is to make it fill the respective variables from the file header words, which are then used to load the OBJ data. &() is the same than ADR(), and parentheses can be omited. $() function returns the string stored at any memory location.

This example will load only the first block of data at a given memory address. If there are more blocks in the file or the INIT or RUN vectors are present, those will be ignored, You might need to do a loop to read many blocks using ERR() function as a stop condition to read up to the end of the file.

vitococl avatar Jan 05 '25 14:01 vitococl