Compile a 32K program to the ZX81

ZX80, ZX 81, ZX Spectrum, TS2068 and other clones
Post Reply
DarwinNE
Member
Posts: 18
Joined: Sat Dec 21, 2019 8:33 pm

Compile a 32K program to the ZX81

Post by DarwinNE »

Dear all,
it's my first post here.

I am currently developing a text adventure game. I am obtaining a relatively large C source file that I then cross compile towards different targets using several compilers. Among those, I use and appreciate z88dk and I could obtain ZX Spectrum, CP/M, CPC and MSX executables with little effort.

I've been asked to port the program towards the ZX81. I know that I require the 32K RAM expansion, that seems to be present in different configurations. A friend on Twitter said to me "There seem to be a few options for the ZX81. The 16K is nearly always 4000-7FFF, but 32K varies. I went for 2000-9FFF, but I've seen 4000-BFFF and 4000-7FFF/C000-FFFF."

I tried to compile my software with the following command line:

Code: Select all

zcc +zx81 -lm -create-app -zorg=8192 mysoftware.c -o mysoftware
but with no success. I got two files but apparently they don't work once loaded on an emulator.

Reading that page:

https://github.com/z88dk/z88dk/wiki/Pla ... clair-ZX81

I'm a little concerned about the sentence "Programs cannot easily be run over the first 16K memory limit: the RAMTOP is not positioned automatically over it. There is also a further problem when running in HRG mode, a special character vector declared in the startup code need to be kept in that limit too." as my program will require about 28 KB of memory.

Unfortunately, I have a ZXSpectrum, but my knowledge of the ZX81 is almost equal to zero...

Cheers,
D.
User avatar
dom
Well known member
Posts: 1302
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

There's a suggestion online that poking RAMTOP at 16389 should allow things to be loaded: eg POKE 16389,192 for 32k of RAM.

However I've not been able to get that to behave with my test programs - maybe you'll have more luck?
DarwinNE
Member
Posts: 18
Joined: Sat Dec 21, 2019 8:33 pm

Post by DarwinNE »

Thank you very much, I'll give it a try!
stefano
Well known member
Posts: 1628
Joined: Mon Jul 16, 2007 7:39 pm

Post by stefano »

The memory space above 32k is not normally usable to run machine code. The video circuit tricks the CPU when in execution mode. There is some HW workaround (M1NOT?) which could fix, but in general it is advisable to put only data on the higher half.
DarwinNE
Member
Posts: 18
Joined: Sat Dec 21, 2019 8:33 pm

Post by DarwinNE »

Hi Stefano, thank you!
Do you think I might try to arrange the segments so that only data is placed above 32k?
Can this be done with command line options?

Code: Select all

-pragma-define:CRT_ORG_CODE=0x2000 \
-pragma-define:CRT_ORG_DATA=0x8000 \
or possibly get CRT_ORG_DATA=0x8000 lower if there is space available, just to be sure that no code is run above 0x8000.

I don't know very much the ZX81, where do you think is a good starting point for understanding this kind of things? I mean manuals, docs, books, etc...

Thank you very much!

D.
Post Reply