Page 1 of 1

ZX81, Alternate Register Pair HL' Used By System?

Posted: Fri Aug 21, 2015 11:17 am
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')?

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

Posted: Fri Aug 21, 2015 11:52 am
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

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

Posted: Fri Aug 21, 2015 12:13 pm
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 :)

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

Posted: Fri Aug 21, 2015 12:47 pm
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.

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

Posted: Fri Aug 21, 2015 1:32 pm
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 :)

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

Posted: Fri Aug 21, 2015 2:27 pm
by Andy Rea
You can use all the registers except iy, ix, af'

Are you sure your not corrupting the stack?

Regards andy

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

Posted: Thu Mar 07, 2024 6:04 pm
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.

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

Posted: Thu Mar 07, 2024 6:23 pm
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!

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

Posted: Thu Mar 07, 2024 8:28 pm
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.

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

Posted: Fri Mar 08, 2024 5:41 am
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).