ZX81 Basic programs loading from shadow ROM

Discussion about ZX80 / ZX81 Software
User avatar
Pip
Posts: 6
Joined: Tue May 19, 2020 6:54 pm

ZX81 Basic programs loading from shadow ROM

Post by Pip »

Hi
I am new to this forum, so first of all hello to all :)

I am currently doing a little project where I want to pimp my old ZX81. I am doing the internal 16k static RAM mod, no need for that wobbly blue tacked fizzing RAM pack anymore.

I am also replacing the ROM with a 27C512 with a simple latch circuit to give me 4 banks of 16k blocks sitting $0000- $3fff

I need a bit of help and or guidance on how to load programs up to RAM from images stored in the lower memory areas.
Using machine code, I am currently at the point where I am can copy down programs from the RAM into the shadow ROM area at $2000 and then bringing them back up into RAM by calling little machine code copy routines. I have got this working fine, but feel that I need to get my head round how to do things a bit better, as until now it has been a bit hit and miss.

Ideally what I want to do it replicate a load command under machine code that will load a p file or similar from memory, and then run in the same manner that it was saved, and from where it left off. I am having trouble working out the entry points in the old ROM after copying the saved file into RAM.

I am not wanting to get into the world of the ZXpand, RAMDOS and the like, I just want to hard code a few programs to load at boot via a simple menu

Can anyone offer me some pointers as to how to achieve the loading of basic programs under machine code.

Cheers

-Pip
User avatar
mrtinb
Posts: 1282
Joined: Fri Nov 06, 2015 5:44 pm
Location: Denmark
Contact:

Re: ZX81 Basic programs loading from shadow ROM

Post by mrtinb »

It is quite cumbersome to add new commands. Modifying the ROM breaks a lot of software.

Therefore most hardware extensions are called e.g. with RAND USR 8192.

The ROM is full as it is, so adding a new keyword is not possible. But if you insist, the keyword COPY is probably the less used, and you could modify it's vector in ROM, to point to address 8192 (knowing it will affect pseudo hires programs).
Martin
ZX81, Lambda 8300, Commodore 64, Mac G4 Cube
User avatar
Pip
Posts: 6
Joined: Tue May 19, 2020 6:54 pm

Re: ZX81 Basic programs loading from shadow ROM

Post by Pip »

mrtinb wrote: Wed May 20, 2020 8:35 am It is quite cumbersome to add new commands. Modifying the ROM breaks a lot of software.

Therefore most hardware extensions are called e.g. with RAND USR 8192.

The ROM is full as it is, so adding a new keyword is not possible. But if you insist, the keyword COPY is probably the less used, and you could modify it's vector in ROM, to point to address 8192 (knowing it will affect pseudo hires programs).
Hi Martin

I am not confined by the size restraint in the original ROM, as my first page of the new ROM (the default) will be 16K in size, so it is an easy job to vector from the old/existing ROM into plenty of free space at $2000. AS you say like a USR 8192, I can then copy any code up into RAM before switching the lower ROM banks to access the stored programs from the other banks, copy them up to RAM, then page back to the BASIC ROM bank and then RUN.

Also I don't need to add any commands, as the menu selection for the program to load will be done by a small block of code called at power up by modifying the first few bytes in the BASIC ROM to vector up to the little menu program stored somewhere in the $2000 block of memory.

It's the then RUN bit I am needing help on. How to copy a block of code into ram and then vector into the ROM in the correct manner and get the program running properly. It's getting the stacks and flags right and knowing where to jump back into the ROM for execution of the said code. As I said in my original post, mimic how a LOAD "Program" would do this.

This is all being done in machine code, the BASIC programs can be considered as data in this case.

Hope this makes sense?

-Pip
Last edited by Pip on Wed May 20, 2020 11:57 am, edited 1 time in total.
User avatar
1024MAK
Posts: 3252
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: ZX81 Basic programs loading from shadow ROM

Post by 1024MAK »

When you load a program from tape, most of the system variables get overwritten, it is this action that allows a BASIC program to auto-run. I think you do need to have some of the Z80 registers with certain values.

Mark
dr beep
Posts: 1303
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: ZX81 Basic programs loading from shadow ROM

Post by dr beep »

Pip wrote: Tue May 19, 2020 11:44 pm Hi
I am new to this forum, so first of all hello to all :)

I am currently doing a little project where I want to pimp my old ZX81. I am doing the internal 16k static RAM mod, no need for that wobbly blue tacked fizzing RAM pack anymore.

I am also replacing the ROM with a 27C512 with a simple latch circuit to give me 4 banks of 16k blocks sitting $0000- $3fff

I need a bit of help and or guidance on how to load programs up to RAM from images stored in the lower memory areas.
Using machine code, I am currently at the point where I am can copy down programs from the RAM into the shadow ROM area at $2000 and then bringing them back up into RAM by calling little machine code copy routines. I have got this working fine, but feel that I need to get my head round how to do things a bit better, as until now it has been a bit hit and miss.

Ideally what I want to do it replicate a load command under machine code that will load a p file or similar from memory, and then run in the same manner that it was saved, and from where it left off. I am having trouble working out the entry points in the old ROM after copying the saved file into RAM.

I am not wanting to get into the world of the ZXpand, RAMDOS and the like, I just want to hard code a few programs to load at boot via a simple menu

Can anyone offer me some pointers as to how to achieve the loading of basic programs under machine code.

Cheers

-Pip
A LOAD “” loads data in memory. After the LOAD a simpel RET is all that is needed. The LOAD however does this through DISPLAY6, after LDIR your .P from elsewhere over right memory you only need to JP DISPLAY6 ( see ROM-disassembly)
NOTE: a simple RET will work for over 99% of the games but not for my 1K games that NEED 1 decrement in FRAMES to run code hidden in the sysvar in the right way.
User avatar
Pip
Posts: 6
Joined: Tue May 19, 2020 6:54 pm

Re: ZX81 Basic programs loading from shadow ROM

Post by Pip »

mrtinb wrote: Wed May 20, 2020 8:35 am It is quite cumbersome to add new commands. Modifying the ROM breaks a lot of software.

Therefore most hardware extensions are called e.g. with RAND USR 8192.

The ROM is full as it is, so adding a new keyword is not possible. But if you insist, the keyword COPY is probably the less used, and you could modify it's vector in ROM, to point to address 8192 (knowing it will affect pseudo hires programs).
Yes I am aware of this. In fact the SAVE command saves data from the system variable VERSN right up to E_LINE. This includes the whole of the screen memory. You can work out the size of the BASIC and Variables from the system variables.

I think one has to make space for the loading data else risk overwriting the stacks. I am not sure what to do if there is already a program in memory. 1) Start afresh by initializing, or 2) collapse the memory down to no program present state, then make room and load the new program in.

Again I feel that I need to have the stacks in the right place and pointed to by the correct system variables, else the computer will crash.
User avatar
Pip
Posts: 6
Joined: Tue May 19, 2020 6:54 pm

Re: ZX81 Basic programs loading from shadow ROM

Post by Pip »

dr beep wrote: Wed May 20, 2020 8:23 pm A LOAD “” loads data in memory. After the LOAD a simple RET is all that is needed. The LOAD however does this through DISPLAY6, after LDIR your .P from elsewhere over right memory you only need to JP DISPLAY6 ( see ROM-disassembly)
NOTE: a simple RET will work for over 99% of the games but not for my 1K games that NEED 1 decrement in FRAMES to run code hidden in the sysvar in the right way.
Thanks for your input, however DISPLAY-6 is wait for key?

I still need to understand how the load works, particularity with the moment of the stacks. If I use an LDIR block move as you suggest, then this does nothing to manage the stack postilions and/or pointers, so I think the program will probably crash.

I can't return, as I have not been called by anything, so the return address will not be on the CPU stack.

Cheers

-Pip
Last edited by Pip on Wed May 20, 2020 11:28 pm, edited 1 time in total.
dr beep
Posts: 1303
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: ZX81 Basic programs loading from shadow ROM

Post by dr beep »

After LDIR just jump to #3E5
See LOAD at #340 and jump at #361.


https://k1.spdns.de/Vintage/Sinclair/80 ... Hara).html
User avatar
mrtinb
Posts: 1282
Joined: Fri Nov 06, 2015 5:44 pm
Location: Denmark
Contact:

Re: ZX81 Basic programs loading from shadow ROM

Post by mrtinb »

When the ZX81 is booted the memory is counted up to 16k, and the stack is placed at the top of 16k that is just below address 32k.

So now you can load a program with the max size just below 16k.

If you need to load a program with a size greater than 16k, you need to POKE in a larger RAMTOP, and do a NEW. The NEW command moves the stack just below RAMTOP. You then have room to load a larger program.

LOAD does not move the stack. NEW does. That's why you need to move RAMTOP and call NEW before loading a large program.
Martin
ZX81, Lambda 8300, Commodore 64, Mac G4 Cube
User avatar
Pip
Posts: 6
Joined: Tue May 19, 2020 6:54 pm

Re: ZX81 Basic programs loading from shadow ROM

Post by Pip »

dr beep wrote: Thu May 21, 2020 9:57 am After LDIR just jump to #3E5
See LOAD at #340 and jump at #361.


https://k1.spdns.de/Vintage/Sinclair/80 ... Hara).html
#3E5 calls the INITIALIZATION routine. This would destroy all the variables and program. It's like typing NEW. Try it, PRINT USR 997

So I am not sure what you are proposing here?
Post Reply