z88dk forums

z80 Development Kit

You are not logged in.

#1 2011-11-16 13:50:53

siggi
Well known member
Registered: 2007-07-26
Posts: 159

[Z88dk-users] ZX81: Questions about ORG, memory ...

I could not find that info in WIKI, so I ask here:

1) Is the compiler option -zorg (to set ORG) also implemented for a ZX81?

2) Is it possible to make relocatable code for a ZX81 (raw binary data). How?

3) Are there any public labels, which "surround" the program?

I would like to detect by the C progam, where it is running and where is the start and the end of the program is (at which memory address) to use memory "around" the program for other things (to load device drivers, to use it for malloc() , ...)

Siggi



------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1


My ZX81 web-server, compiled with Z88DK V1.7:
http://zx81-siggi.endoftheinternet.org/index.html smile
Online since 2007 ...

Offline

 

#2 2011-11-16 18:26:26

stefano
Administrator
Registered: 2007-07-16
Posts: 696

Re: [Z88dk-users] ZX81: Questions about ORG, memory ...

Siggi,
the short answer for both those questions is "no".
At the moment the ZX81 memory model is thought for the default ZX81 loader which is quite static, as you surely know. lol    By the way..

1 - Ok, I've just enabled the '-zorg' parameter in the zx81mode too, but the resulting packaged program will not work when different location is specified.   You'll need to manage the intermediate 'a.bin' file.

2 - Z80ASM *IS* able to generate relocatable code (it will be slightly bigger).  It can be done, and I did it for the Spectrum (see the bin2bas-rem tool in the "support" folder), but it is not an easy task.  If you show it is really useful I can provide a similar tool.

3 - I'm not aware of an easy way to know at which location the program begins/ends, I agree the absolute ending position after the linkage could be very useful, but this is the price we pay for that powerful incremental linker, I'm afraid.   You can obviously compile the program a first time, look at its lenght, compute the first free byte position and update a local program constant by hand.
Honestly I think the ZX81 is the machine getting the higher benefits from hand optimizations: isn't the higher memory half available for data only ?  There are similar tricks for the ROM locations too (see ARX816).



------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure
contains a definitive record of customers, application performance,
security threats, fraudulent activity, and more. Splunk takes this
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d

Offline

 

#3 2011-11-17 08:43:03

siggi
Well known member
Registered: 2007-07-26
Posts: 159

Re: [Z88dk-users] ZX81: Questions about ORG, memory ...

1 - Ok, I've just enabled the '-zorg' parameter in the zx81mode too, but the resulting packaged program will not work when different location is specified.   You'll need to manage the intermediate 'a.bin' file.

That would be ok for me. I currently don't use the -create-app option and use directly the .bin file (I wrote about "raw binary data" above).

2 - Z80ASM *IS* able to generate relocatable code (it will be slightly bigger).  It can be done, and I did it for the Spectrum (see the bin2bas-rem tool in the "support" folder), but it is not an easy task.  If you show it is really useful I can provide a similar tool.

Is there really another tool necessary, when using the only .bin file? I also have MEFISDOS and can load binary data from MMC into ZX81 memory without any loader.

3 - I'm not aware of an easy way to know at which location the program begins/ends, I agree the absolute ending position after the linkage could be very useful, but this is the price we pay for that powerful incremental linker, I'm afraid.   You can obviously compile the program a first time, look at its lenght, compute the first free byte position and update a local program constant by hand.
Honestly I think the ZX81 is the machine getting the higher benefits from hand optimizations: isn't the higher memory half available for data only ?

Only the highest 16K (from 48 to 64K) cannot be used for M/C, but for data. 32K-48K can be used for M/C, if you have a "M1-NOT" modification done in the ZX81 (most of us have that done).

My thoughts are:
I wrote a new user interface (UFM: USB File Manager) for the USB driver, used in the German ZX-Team:
http://forum.tlienhard.com/phpBB3/viewt … 4101#p4098

With the driver a BASIC program  or data (also binary code) can be loaded from USB stick to any region of the ZX81 memory. So depending on the destination of the loaded data, the driver/UFM must not run at the same location, where the loaded data are written to.

So I compiled UFM for adresses:
11182 (regionb 8K-16K)
35678 (region 32-40K)
and a version for region 40-48K is also requested. smile
So my first idea was, to have a relocatable UFM. That would make life easier wink

My next idea was, that the UFM could itself load the USB driver (must also be relocatable) to a free memory location behind or before the UFM. Therefor UFM must know its beginning and end.

But having a relocatable UFM only would be fine ...

Siggi



------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure
contains a definitive record of customers, application performance,
security threats, fraudulent activity, and more. Splunk takes this
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d


My ZX81 web-server, compiled with Z88DK V1.7:
http://zx81-siggi.endoftheinternet.org/index.html smile
Online since 2007 ...

Offline

 

#4 2011-11-17 12:44:30

stefano
Administrator
Registered: 2007-07-16
Posts: 696

Re: [Z88dk-users] ZX81: Questions about ORG, memory ...

Ok,
try in this way:

- Edit ZX81_CRT0 and add the following line

Code:

  start:
ld ix, 16384    ; fix IY after relocator's job (IXIY swap)

- Compile your program by adding the '-Ca-R' parameter in the command line.

- Edit the resulting program with a binary editor (hexedit, debug.com..) and change the first 4 bytes of the resulting binary with: C5, C5, FD, E1
Load and run it with "RAND USR...".     It assumes that BC holds the start address on entry, which is what happens when an USR command is issued.



------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure
contains a definitive record of customers, application performance,
security threats, fraudulent activity, and more. Splunk takes this
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d

Offline

 

#5 2011-11-17 13:29:19

siggi
Well known member
Registered: 2007-07-26
Posts: 159

Re: [Z88dk-users] ZX81: Questions about ORG, memory ...

It works smile

Thanks!!!

One additional question:
when the program has been started, relocatged and finished:
if I save that relocated program and load that changed program back to another location: will it there run again?

I want to hold setup-values in the program, which should be available at the next start anywhere (see old thread of SUPERSTATIC variables).

Siggi



------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure
contains a definitive record of customers, application performance,
security threats, fraudulent activity, and more. Splunk takes this
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d


My ZX81 web-server, compiled with Z88DK V1.7:
http://zx81-siggi.endoftheinternet.org/index.html smile
Online since 2007 ...

Offline

 

#6 2011-11-17 17:48:24

stefano
Administrator
Registered: 2007-07-16
Posts: 696

Re: [Z88dk-users] ZX81: Questions about ORG, memory ...

> It works smile


Wow, I was not so sure big_smile


I think it can be moved and run everywhere you like, every time you want, but I'm not 100% sure.
The relocator should have a provided offset table, and it should just patch all the static positions basing on that table and adding the current location.



------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure
contains a definitive record of customers, application performance,
security threats, fraudulent activity, and more. Splunk takes this
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d

Offline

 

#7 2011-11-17 18:20:30

siggi
Well known member
Registered: 2007-07-26
Posts: 159

Re: [Z88dk-users] ZX81: Questions about ORG, memory ...

I played a little bit with a relocated program and saved and reloaded it to another location, but it did not run there.
It seems that the relocator patches its own entry, so that the program is relocated only one times .... sad

Siggi



------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure
contains a definitive record of customers, application performance,
security threats, fraudulent activity, and more. Splunk takes this
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d


My ZX81 web-server, compiled with Z88DK V1.7:
http://zx81-siggi.endoftheinternet.org/index.html smile
Online since 2007 ...

Offline

 

#8 2011-11-18 11:38:49

siggi
Well known member
Registered: 2007-07-26
Posts: 159

Re: [Z88dk-users] ZX81: Questions about ORG, memory ...

Hi Stefano

2 more questions:

- Edit the resulting program with a binary editor (hexedit, debug.com..) and change the first 4 bytes of the resulting binary with: C5, C5, FD, E1
Load and run it with "RAND USR...".     It assumes that BC holds the start address on entry, which is what happens when an USR command is issued.

What is to be done, if the call is done using "JP (HL)" instead of USR (like MEFISDOS does, when loading and running an "autostart" M/C): would 2 "PUSH HL" instead of "PUSH BC" be ok?

And a question to zx81_ctr0.asm:
is a call to "l_dcal" allowed?
I want to do a "call (hl)" by loading HL and calling "l_dcal". But why are there 2 "jp (hl)" at "l_dcal"? Is this location patched sometimes?

Siggi



------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure
contains a definitive record of customers, application performance,
security threats, fraudulent activity, and more. Splunk takes this
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d


My ZX81 web-server, compiled with Z88DK V1.7:
http://zx81-siggi.endoftheinternet.org/index.html smile
Online since 2007 ...

Offline

 

#9 2011-11-21 09:10:47

stefano
Administrator
Registered: 2007-07-16
Posts: 696

Re: [Z88dk-users] ZX81: Questions about ORG, memory ...

The 'second' push is the key one.  The trick is to set IY with the current location, so:

Code:

push bc
push hl
pop iy

..should work;  btw since we are not passing parameters on those registers I think it is not that horrible thing to alter BC or HL on entry, choose your favourite way.


>And a question to zx81_ctr0.asm:
>is a call to "l_dcal" allowed?
>I want to do a "call (hl)" by loading HL and calling "l_dcal". But why are there 2 "jp (hl)" >at "l_dcal"? Is this location patched sometimes?

I don't remember of tricks on it, probably it is just an error  hmm



------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure
contains a definitive record of customers, application performance,
security threats, fraudulent activity, and more. Splunk takes this
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d

Offline

 

#10 2011-11-21 21:16:31

siggi
Well known member
Registered: 2007-07-26
Posts: 159

Re: [Z88dk-users] ZX81: Questions about ORG, memory ...

Hi Stefano
could you add the -R option to the standard features for ZX81 (to generate at compile time the appopriate PUSH BC, PUSH BC, POP IY for standard USR calls).
I noticed, that -Ca is not necessary to generate the relocation table (-R seems to be sufficient). So the compiler itself will know, that it has to do the "patch" for ZX81.

Siggi



------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure
contains a definitive record of customers, application performance,
security threats, fraudulent activity, and more. Splunk takes this
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d


My ZX81 web-server, compiled with Z88DK V1.7:
http://zx81-siggi.endoftheinternet.org/index.html smile
Online since 2007 ...

Offline

 

#11 2011-11-24 14:16:24

siggi
Well known member
Registered: 2007-07-26
Posts: 159

Re: [Z88dk-users] ZX81: Questions about ORG, memory ...

Hi Stefano

something is a little bit strange, when a relocated ZX81 program is runnig the first time (and relocation is processed): the C program (after RAND USR xxx) then comes back to BASIC with error 4/0 (out of memory).
If it is started again (so no more relocation is done), it returns without error: 0/0

Siggi



------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure
contains a definitive record of customers, application performance,
security threats, fraudulent activity, and more. Splunk takes this
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d


My ZX81 web-server, compiled with Z88DK V1.7:
http://zx81-siggi.endoftheinternet.org/index.html smile
Online since 2007 ...

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson