Convert a Basic program to Rom file easly

Page 1/2
| 2

By gdx

Prophet (3436)

gdx's picture

22-02-2020, 12:52

Tip:

Add the following line at the start of your program.

1 '01234567

Save the program with SAVE"NAME.ROM" and check that the file does not exceed 16384 (4000h) bytes.

Open the file with an Hexa editor to replace the first 16 bytes:

FF 11 80 04 00 3A 8F E6 30 31 32 33 34 35 36 37

by

41 42 00 00 00 00 00 00 10 80 00 00 00 00 00 00

If the file is smaller than 16384 (4000h) bytes, fill with FFh behind the program.
Save and your Rom is ready. Running Naked in a Field of Flowers

Login or register to post comments

By NYYRIKKI

Enlighted (5508)

NYYRIKKI's picture

22-02-2020, 14:23

I have to add some remarks though...

  • You should run your program and test all the features before save... Other ways your GOTO and GOSUB commands are likely to fail.
  • This way you can only store BASIC files that are small enough to run with 12kB of RAM... the file size must be <16kB.
  • For machines with 32kB of RAM or more it is better to transfer the BASIC program to RAM before execution.

By tfh

Prophet (2188)

tfh's picture

22-02-2020, 14:50

Cool Smile Smile
Now I can enter my "Shooting Stars" 10 Liner BASIC challenge for MSXdev'20 (and finish last...) Running Naked in a Field of Flowers Running Naked in a Field of Flowers Running Naked in a Field of Flowers

By Pencioner

Scribe (1097)

Pencioner's picture

22-02-2020, 15:17

I think if you do

POKE &HF677,&H80
POKE &HF676,&H11
POKE &H8010, 0
LOAD "PROGRAM.BAS"
SAVE "PROG1111.BAS"

Then you don't need to add a line with remark (1 '01234567) and you can then just add 16 bytes (41 42 00 00 00 00 00 00 10 80 00 00 00 00 00 00) at the beginning to PROG1111.BAS and fill up to 16K with &HFF bytes to make it a ROM

P.S. After some searching i found this old topic, and there's an openMSX TCL script which does like that and automatically makes your basic program a rom file! - https://www.msx.org/forum/development/cross-development/pc-t...

By gdx

Prophet (3436)

gdx's picture

22-02-2020, 16:38

Pencioner, we have to know the pokes with your method. Line with remark avoids us that.

NYYRIKKI wrote:

You should run your program and test all the features before save... Other ways your GOTO and GOSUB commands are likely to fail.

No problem if you follow exactly the tutorial.

NYYRIKKI wrote:

This way you can only store BASIC files that are small enough to run with 12kB of RAM... the file size must be <16kB.

Yes but common Rom size for Basic program is 8kB or 16kB only.

NYYRIKKI wrote:

For machines with 32kB of RAM or more it is better to transfer the BASIC program to RAM before execution.

Yes but the method is less simple. Otherwise, I even think that it is feasible for MSXs with 16KB of Ram by adding the part that exceeds into the RAM with a routine in language machine.

Edit: Yes, it's feasible!
https://mon-partage.fr/f/0iyCDrsA/
:)

By NYYRIKKI

Enlighted (5508)

NYYRIKKI's picture

22-02-2020, 20:45

gdx wrote:

No problem if you follow exactly the tutorial.

I do disagree... Adding the 1st line will convert pointers to line numbers and that is the source of trouble... BASIC can't reconvert them to addresses anymore when the code is in ROM.

By Pencioner

Scribe (1097)

Pencioner's picture

22-02-2020, 21:30

NYYRIKKI wrote:
gdx wrote:

No problem if you follow exactly the tutorial.

I do disagree... Adding the 1st line will convert pointers to line numbers and that is the source of trouble... BASIC can't reconvert them to addresses anymore when the code is in ROM.

Yes i remember once i faced that problem in the past, that's why i suggest to poke the start of BASIC program first, save it after it was loaded from that adress so pointers are modified correctly by BASIC interpreter, then just add ROM header at the beginning. But i guess it is quite easy to convert pointer addresses in tokenized BASIC program on the fly with small Python script as well to automate making ROMs (hmmmm....)

UPDATE(EDIT): now i remembered, i did it without adding the line with comment (just added 16 bytes with program which was loaded at &h8000), but with that line pointers will be correct - this line already shifts everything in memory properly 16 bytes ahead, so it should work as @gdx said too

EDIT #2: But for 10-liners, which use low line numbers to save chars it might be impossible to use line number 1. At other side, converting 10-liner to ROM for MSXDev will remove that limitation, so you can renum and then so it Wink

By NYYRIKKI

Enlighted (5508)

NYYRIKKI's picture

22-02-2020, 21:45

Pencioner wrote:

with that line pointers will be correct - this line already shifts everything in memory properly 16 bytes ahead, so it should work as @gdx said too

Yes, the program is shifted correctly, no problem on that. What I try to explain is that due to added line the pointers will be automatically converted to line numbers (if not such already) and since the BASIC can't fix them to memory addresses on the fly the result is a program crash when GOTO/GOSUB happens. You can try to prevent that problem by running the program after adding the 1st line and before saving it as ROM.

By gdx

Prophet (3436)

gdx's picture

23-02-2020, 02:13

I have never encountered this issue. Maybe it's because I often display the program with LIST? If it is, it's better than running the program because this can also cause problems.

By gdx

Prophet (3436)

gdx's picture

23-02-2020, 09:21

Well I tested making a Rom with the following ways on emulated Turbo R then compared the resulting files.

1/ By following my tutorial.
2/ By following my tutorial then partial LIST before to save.
3/ By following my tutorial then full LIST before to save.
4/ By following my tutorial then RUN before to save.
5/ By using the classic way indicated Pencioner above.

I obtain exactly the same files with the 1 to 4 methods, but with the 5, only the first byte of the program differs. It's FFh instead of 00h, and it doesn't works ("Syntax error in 0") if we don't replace it by 00h. Once this byte replaced, the file becomes the same as the others.

I conclude that some versions of Basic interpreter are probably buggy because it should work. Yet mystery of Basic.

I also noticed that we have to remove a byte from the remark if the number of the line to add is 0 instead of another.

For example:
0 '0123456
instead of
1 '01234567

By NYYRIKKI

Enlighted (5508)

NYYRIKKI's picture

24-02-2020, 01:51

I tried to repeat the line number problem as I remembered it, but it seems I was unable to do so... I think you must be right and I've just managed to somehow mess up the addresses or something like that since now when I tested, I could not get any trouble no matter if the GOTOs were stored as line numbers or line pointers... The generated ROM seems to work anyway.

When BASIC program is saved with SAVE-command it seems that all GOTOs are converted to line numbers...
Therefore to improve this idea I would recommend to replace the 2nd step (SAVE "NAME.ROM") with:
DEFUSR=&H54F6:A=USR(0):BSAVE"NAME.ROM",&H8007,&HBFFF

This will make sure all the line numbers are replaced with line pointers and that will improve the BASIC program performance when the program is executed from ROM... (The actual performance boost depends very much of the program it self)

Page 1/2
| 2