first working example from Boriel’s ZXBasic Compiler, finally

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
boriel
Posts: 2
Joined: Tue Jun 21, 2016 4:31 pm

Re: first working example from Boriel’s ZXBasic Compiler, finally

Post by boriel »

Hi, Boriel here
PokeMon wrote:Yes - if the compiler creates an application it must be loaded somehow on the ZX81. Usually it can only read "BASIC programs" which may contain assembly code as well. As the stack pointer is initialized before a program is loaded (how else would you start LOAD "") I wouldn't care about changing the stack pointer manually.
PokeMon wrote:If you are more familiar with assembly then you may use other tools as well. Don't know Boriel's language used.
The compiler is targeted to Z80 (ZX Spectrum CPU).
PokeMon wrote: HL' (has to be restored before returning to BASIC)
IY (may be used in FAST mode with display turned off but should be restored when returning)
IX (may be used in FAST mode with display turned off but should be restored when returning)
AF' (may be used in FAST mode with display turned off but should be restored when returning)
I (may be used in SLOW mode but disturbs the picture until restored)
R (unlikely to use for general applications)
ZX Basic compiled programs restore IX, SP, and HL' upon return. But AF' might be changed.
The compiler generates an "EXIT TO BASIC" (for ZX Spectrum) sequence at the end.
PokeMon wrote:If you need a temporary additional register using the stack with PUSH and followed by EX SP,(HL) is quite useful as well. This instruction swaps HL and top of stack and a second instruction changes back.
The compiler uses all of these tricks when generating code. Actually, the original SP is saved in memory (in a static location) and restored upon return.
I and R are not used by the compiler.
The idea in mind is to have a generic Z80 compiler for the Z80 family (ala z88dk in C). But I moved into another city 2yrs ago and have really little time. Having said that, the project is alive.
What I lack is hardware info for those machines. I need to design an scheme to easily allow 3rd developers to do what nitrofurano is doing by hand: generating code for 3rd architectures.
User avatar
siggi
Posts: 988
Joined: Thu May 08, 2008 9:30 am
Location: Wetterau, Germany
Contact:

Re: first working example from Boriel’s ZXBasic Compiler, finally

Post by siggi »

Hi Boriel,
I think, that compiled code must also run during SLOW mode of the ZX81. So all previously given limitations about register usage by the ZX81 during SLOW mode must be fulfilled. Here some addional information:
boriel wrote: ZX Basic compiled programs restore IX, SP, and HL' upon return. But AF' might be changed.
During SLOW mode the AF' is decremented during each NMI-cycle. So if the compiled code uses the AF' register, its content is destroyed, when an NMI occurs (AFAIK normally every 207 machine cycles).

The IX-register holds the address of the video-routine and may never be changed during SLOW mode (except when you want to use your own video-routine, like z88dk does)

The IY-Register is used by the standard videoroutine during SLOW mode. If you want to use it, you must use your own video routine (like z88dk does).
The compiler generates an "EXIT TO BASIC" (for ZX Spectrum) sequence at the end.
For ZX81, that could be

Code: Select all

RST 08
DEFB $FF
Regards
Siggi

PS: do you know MCODER 2?
My ZX81 web-server: online since 2007, running since dec. 2020 using ZeddyNet hardware
http://zx81.ddns.net/ZxTeaM
boriel
Posts: 2
Joined: Tue Jun 21, 2016 4:31 pm

Re: first working example from Boriel’s ZXBasic Compiler, finally

Post by boriel »

:o Sorry.
I completely overlook this message. Sorry!! :cry:
5 years later here you are the answer:
at that time nope, I didn't. Nowadays I'm aware of MCODER 2 compiler, but 've never used it.
Post Reply