about a MSXBASIC compiler?

Page 1/7
| 2 | 3 | 4 | 5 | 6

By PingPong

Prophet (3898)

PingPong's picture

16-10-2007, 19:57

I think it's possible to make a msxbasic compiler starting from the tokenized form of a saved msxbasic program.
In my mind, those program should load a msxbasic tokenized form and output a true .bin file, in bloadable form
( alike xbasic kun, that however does not have the option 'make bloadable form' )
however there is a thing that is unclear to me...
most gw basic alike interpreters, in order to improve the goto jump speed convert the goto xxxx references into pseudo - memory pointers. for example: during run-time execution the the goto 130 become goto (memadr). what is unclear to me is how can this approach can work in msxbasic? the starting memory for a basic program is not fixed, so are those goto addresses relative?

When The process how changing line number references into addresses is done?

during load?
during editing?
just before starting execution of a basic program (after the immediate mode run?)
on demand? (i do not think... too much complicated)

How can a basic program saved on a 64k machine work in a 16k machine if line addresses are changed in pointers?

Any one know about?
thx

Login or register to post comments

By Yukio

Paragon (1540)

Yukio's picture

16-10-2007, 20:20

I don't know how is the approach of each compiler or if it is a two or three steeps compiler. Maybe they use a similar method that is used for substitute constants in memory, a fixed address that has a pointer in memory. Pointers and memory reference could be weird to use, this even 'confuses' some "beginner" programmers.

I think that the MSX standard dictates a search for the RAM map in the slot and sub-slots. Software that fail to locate the RAM and initialize the slots configuration is not "MSX" Standard compatible and will not work in machines with RAM localized on sub-slots either ...

By PingPong

Prophet (3898)

PingPong's picture

16-10-2007, 21:05

Thanks, yukio, for the reply... but my issue is not on slot or any kind of similar thing. It's only on the start address of a basic program in memory.
My idea is to make a basic -> asm compiler, in the first step maybe passing from kind of 'c' source buildable on sdcc.

somewhat like:
10 INPUT A%
20 IF A%=0 THEN END
30 GOTO 10

should became:

static int a;

void main()
{
1:
basic_input ("", &a);
if (a==0) goto end;
goto 1;
end:

}

basic_input is a helper library function that perform the INPUT A%

that compiled could became a binary-high efficient code.

By Yukio

Paragon (1540)

Yukio's picture

16-10-2007, 21:24

A assembler parser?

Like the software in other platforms that will generate a ASM list of a BASIC program to be compiled with a generic Assembler?

Their use this method for converting BASIC or C language into ASM code.
Would work with Pascal and other languages too.

If you just wanted BASIC I/O without graphics or sound enhancement it should be possible to use some spare code from other formats. The lexical analyses and interpreter could be very similar, at least the basic words ...

By NYYRIKKI

Enlighted (5939)

NYYRIKKI's picture

16-10-2007, 21:50

( alike xbasic kun, that however does not have the option 'make bloadable form' )
No, there is no option to do that, but with some tricking you can compile the program to custom address. After that you need to add only variable init and change the program end routine to RET. Ofcource you need the XBASIC in memory anyway, but you can get rid of the original MSX-BASIC program.

the starting memory for a basic program is not fixed, so are those goto addresses relative?
No

When The process how changing line number references into addresses is done?

during load?
during editing?
just before starting execution of a basic program (after the immediate mode run?)
on demand? (i do not think... too much complicated)

Last one is correct and if you think of it, it is not that complicated. When GOTO or GOSUB is first time used it will be converted to address. So next time the command is faster to execute. When you edit program linenumbers are always stored as linenumbers. In header of BASIC line pointer to next line is always stored as absolute address. These absolute addresses are calculated on editing and loading, so it does not actually matter from what address the program is stored from.

You may want to check out explanation part of the replacement for "OLD" that I wrote:
http://www.msx.org/forumtopic4678.html

By arnold_m

Master (173)

arnold_m's picture

16-10-2007, 21:51

Changing between line numbers and line pointers is not so complicated on an MSX, both forms take three bytes:
line address: 0Dh lsb msb
line number: 0Eh lsb msb

Whenever the interpreter needs to jump to line number it searches the program for the line and it stores the address of the line in the place of the line number. When the program is changed or saved in tokenised form any line addresses are converted back to line numbers, so programs on disk have line numbers in them, not addresses. This avoids problems with loading programs on a different starting address than from which they were saved, and makes the life of a compiler writer a bit easier.

For a listing or when saving the basic as ascii text the line addresses are translated back to numbers during detokenising, without changing the program in memory.

By PingPong

Prophet (3898)

PingPong's picture

16-10-2007, 22:12

thx, to all. My idea is to initially create a simple from basic to 'c' converter, filling the msx basic support routine with my own library calls. then by compiling the 'c' source we can get the binary (of course this translate into asm code, by it's a matter of sdcc).

In a last phase would be good to skip the basic to 'c' pass, generating directly asm code.
So from what is see i need to only implement some kind of expression evaluator for basic expressions like mid$(a$+c$,2,3) + a set of my library support routines, for example string management.

the final goal is as said to have some kind of binary form that could run without any support sw.
Another nice thing will be to 'move' the library support routines in a free slot, thus freeing the max memory (64k?) for the compiled basic, handling trasparently some interslot calls to the library routines.

By PingPong

Prophet (3898)

PingPong's picture

16-10-2007, 22:13

to do this, however i need to have the exact knowledge of a msxbasic format on disk. anyone have detailed infos?

By Vincent van Dam

Hero (513)

Vincent van Dam's picture

16-10-2007, 22:27

A long time ago, I made a viewer for basic files. You can get the c-source here, maybe that helps.

By Trebmint

Champion (294)

Trebmint's picture

17-10-2007, 00:09

Not sure if it would help but the last version of symstudio has a working basic compiler (minus some commands) and a built in assembler to which the source can be found at http://www.dread-donkey.com/downloads/symstudiocomplete.zip . It's written in Blitz basic so should be easy to read. Might help with the parsing especially the expression and converting to RVP. Also there are several files including library source, like string, math and command (though this is of limited use since msx basic and symbasic were pretty different)

Oh and forgive me for the bad coding, cos its very spagetti. Hope its of some use, trebmint

By Vampier

Prophet (2397)

Vampier's picture

17-10-2007, 06:01

http://www.msx.org/forumtopicl7883.html

Check this topic aswell, I'm working on something fun.

Page 1/7
| 2 | 3 | 4 | 5 | 6