ZX81, Alternate Register Pair HL' Used By System?

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
Post Reply
IanB
Posts: 60
Joined: Mon Jul 27, 2015 5:40 am
Location: Northampton UK

ZX81, Alternate Register Pair HL' Used By System?

Post by IanB »

Hopefully a simple question for the experts here-

It seems changing the value in the hl' (alternate) register pair causes the ZX81 to crash. I thought the prime registers were safe to use, except af' which is used by the screen display routines. Is hl' used, what for, and is there a particular value it should contain on return to BASIC? Any of the others (bc' de')?
dr beep
Posts: 2079
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: ZX81, Alternate Register Pair HL' Used By System?

Post by dr beep »

Wild guess:

Call to MC uses FP-calc which need the value of HL' on return.

So

EXX
PUSH HL

before running code
And on end

POP HL
EXX

Before RET to BASIC

http://www.wearmouth.demon.co.uk/zx81.htm#L0028
IanB
Posts: 60
Joined: Mon Jul 27, 2015 5:40 am
Location: Northampton UK

Re: ZX81, Alternate Register Pair HL' Used By System?

Post by IanB »

Ah okay, that makes sense. It's just a normal RAND USR 16514 type thing, but I guess that decoding the address from the program line uses the FP calculator.

I won't be using BASIC in the finished program, but it's quite handy to have it working for testing :)
User avatar
PokeMon
Posts: 2264
Joined: Sat Sep 17, 2011 6:48 pm

Re: ZX81, Alternate Register Pair HL' Used By System?

Post by PokeMon »

Normally you can use all registers with EXX freely in your programs as well as long as you do not use specific ROM code.
If you want to program a driver cooperating with the rest you should avoid these double registers.
But when the control goes back from your routine to BASIC (asm code is finished) it is no problem to use the EXX registers.
But you can not assume that your registers are saved when calling your code in a kind of BASIC loop.
IanB
Posts: 60
Joined: Mon Jul 27, 2015 5:40 am
Location: Northampton UK

Re: ZX81, Alternate Register Pair HL' Used By System?

Post by IanB »

Strange, I'm not doing any calls to ROM. Still, it crashes if HL' is changed. It appears to be okay to use BC' though. So far :)
User avatar
Andy Rea
Posts: 1606
Joined: Fri May 09, 2008 2:48 pm
Location: Planet Earth
Contact:

Re: ZX81, Alternate Register Pair HL' Used By System?

Post by Andy Rea »

You can use all the registers except iy, ix, af'

Are you sure your not corrupting the stack?

Regards andy
what's that Smell.... smells like fresh flux and solder fumes...
stroebeljc
Posts: 67
Joined: Thu Apr 23, 2020 6:02 am

Re: ZX81, Alternate Register Pair HL' Used By System?

Post by stroebeljc »

HL' is used by the FP calculator when machine code is launched using USR in BASIC. So you need to do what dr beep says and save-and-restore it.
John
dr beep
Posts: 2079
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: ZX81, Alternate Register Pair HL' Used By System?

Post by dr beep »

stroebeljc wrote: Thu Mar 07, 2024 6:04 pm HL' is used by the FP calculator when machine code is launched using USR in BASIC. So you need to do what dr beep says and save-and-restore it.
Wow.... a 2015 thread revived!
Well if it helps anyone, why not!
stroebeljc
Posts: 67
Joined: Thu Apr 23, 2020 6:02 am

Re: ZX81, Alternate Register Pair HL' Used By System?

Post by stroebeljc »

I think it interesting that this detail is conspicuously missing from the ZX81 User Manual, especially when it addresses which registers not to mess with. It doesn't seem like such a minor detail to me.
John
dr beep
Posts: 2079
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: ZX81, Alternate Register Pair HL' Used By System?

Post by dr beep »

stroebeljc wrote: Thu Mar 07, 2024 8:28 pm I think it interesting that this detail is conspicuously missing from the ZX81 User Manual, especially when it addresses which registers not to mess with. It doesn't seem like such a minor detail to me.
The manual also doesn't mention the use of IX or A' which you can only use in a special way.

IX to activate your own hires or intruptroutine and A' only to delay screenupdates when you initialize data and you need a very small stack ( use it in my code).
Post Reply