kosarev / zx

ZX Spectrum emulator written in a mix of Python and C++
https://twitter.com/z80tools
MIT License
21 stars 1 forks source link

Support the ZX basic compiler directly #11

Closed kosarev closed 4 years ago

kosarev commented 4 years ago

It might be a good idea to add a direct support for the https://github.com/boriel/zxbasic compiler in the emulator.

Benefits

What needs to be done

Jose @boriel, what do you think?

boriel commented 4 years ago

Not yet done, but it can be done.

Anyway, I'll improve the API so a more direct approach can be used.

kosarev commented 4 years ago

@boriel Yep, that at least may work as a prototype solution. Will give it a try. Thanks!

boriel commented 4 years ago

the origin of the compile code (ORG) is, by default, 32768, but can be set to any other location with ['--org', '25000'] for example.

Also, bear in mind that tzx and tap files contains a Sinclair BASIC loader which sets the RAMTOP below that ORG (i.e. for 32768 you will see CLEAR 32767 in the BASIC listing). This will signal the ROM not to use the RAM above that location. Otherwise writing the binary data directly might corrupt the ROM BASIC interpreter Stack and hang the machine.

A solution for this could be starting with a machine state where the RAMTOP is already set to, for example, 32767 and then load the .bin raw binary above that location.

What do you think?

kosarev commented 4 years ago

@boriel Yes, I think we could start with using the default ORG and set RAMTOP up in the resulting snapshot respectively (and thanks for reminding about it, by the way :-) ). But doesn't that .bin file has the RAMTOP value set as necessary already?

As to how to support other ORG values, maybe for now it would make sense to rely purely on #pragma org? I believe I saw something like this line in some of your .bas files. In that case on the emulator side we would need a way to pull the ORG value from the compiler somehow. Or, can I just look into RAMTOP in the .bin file?

boriel commented 4 years ago

#pragma org will also work. However this just means the assembled code is set to run in that location (with the jumps resolved, etc). But before that a empty ram file with the ramtop set for 32767 should be preloaded. For example: executing CLEAR 32767 in an empty RAM emulation will leave the state ready.

Then to that RAM we should overwrite with the contents of the .bin file starting a 32768.

kosarev commented 4 years ago

@boriel Looks like with https://github.com/boriel/zxbasic/commit/8821becf3cdba9f3ef2393a50ec1b7da34cf8184 and https://github.com/kosarev/zx/commit/c837fbdc36cc8c2096a13e00e832afe41e912fc7 in place the emulator has all the necessary info.

One more question, though. Can you please confirm it explicitly that the way the emulator uses the https://github.com/boriel/zxbasic compiler does not violate its license? The emulator is available under the MIT license and the compiler seems to be GPL'ed, so it might be worth some clarification. :-) Thanks!

boriel commented 4 years ago

GPLv3 basically allows you to do everything, except that the sources should always be available and that if you make a modification on the compiler you should publish it to the community (that is, the compiler .py itself; the .asm / bas library are under MIT / BSD licenses)

If you need to distribute the compiler or a variation in a closed source manner, I can relicense it under MIT. anyway.

kosarev commented 4 years ago

GPLv3 basically allows you to do everything, except that the sources should always be available and that if you make a modification on the compiler you should publish it to the community (that is, the compiler .py itself; the .asm / bas library are under MIT / BSD licenses)

If you need to distribute the compiler or a variation in a closed source manner, I can relicense it under MIT. anyway.

Perfect, thanks for the clarification!

The emulator doesn't currently specify the compiler as its dependency, and checks it dynamically if it is installed. And if it's not, exits gracefully with a message explaining the situation. (By the way, any improvements to the message, such ones that provide more details on how to install the compiler, etc. are very welcome. :-) ) So looks like the license matters are settled for now.

kosarev commented 4 years ago

Supported via: 9f33d4b [#11] Advertise the support for ZX Basic compiler sources. c837fbd [#11] Translate ZX Basic compiler sources on the fly.