Messing with SP in a ZX81 in SLOW mode

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
Post Reply
leiradel
Posts: 15
Joined: Sat Mar 02, 2013 4:55 pm

Messing with SP in a ZX81 in SLOW mode

Post by leiradel »

Hi,

I'm developing a stack-based VM in Z80 machine code. The VM supports multiple coroutines (cooperative multi-threading) and each coroutine has its own operands stack.

I'm trying to use the SP register to handle the operands stacks. When testing the VM using a Z80 emulator, things run just fine. When I try to run it in a ZX81 emulator, it crashes.

So my question is: can I mess with SP in a ZX81?

DE is the VM's program counter, IY points to the current coroutine (I'm using an alternative video interrupt to free it), and HL and BC are used in calculations etc., so I'd really like to use SP to handle the operand stack.

If that's not possible, I'll write alternative code to use HL as the operand stack pointer, but it will result in slower code since I'll have to save/restore it in almost all VM instruction implementations, not counting "pop bc" vs. "ld c,(hl) : inc hl : id b,(hl) : inc hl".

Of course the SP is saved and restored when a coroutine enters/exists, and I've tried a 1024 bytes stack for the coroutines and it still crashes, so it's not a problem of memory stomping. Again, the VM works in a pure Z80 emulation, where I set up a 32Kb ROM followed by 32Kb RAM. The tests run and output info (using "out") just fine.

Also, I'd really love to hear about emulators with good debug modes. EightyOne's not that good, No$zx81's a little better, but it becomes slower and slower as I use it and it finally crashes after a while.

Thanks in advance,

Andre
User avatar
dbolli
Posts: 5
Joined: Thu Nov 15, 2012 10:52 pm
Location: Sydney, Australia
Contact:

Re: Messing with SP in a ZX81 in SLOW mode

Post by dbolli »

Hi Andre,

I think IY is the issue as various ZX81 ROM routines assume IY is $4000 and use to access System Variables.

If you change IY with interrupts enabled (IM 1) your program will probably crash. The same issue occurs
on a ZX Spectrum if IY is not pointing to $5C3A.

I would suggest running your routines with interrupts disabled (via DI) and see what happens
as this will prevent ZX81 ROM routines from executing.

Or alternatively substitute another register for IY (e.g. IX).

See http://www.old-computers.com/download/t ... sembly.pdf
for more details.

Regards,
Derek Bolli
North Sydney, Australia.
Last edited by dbolli on Sat Mar 02, 2013 9:35 pm, edited 1 time in total.
1985: ZX Spectrum+ 48K Interface 1 ZX81 16KB ASZMIC/SP ROM Philips 12" B/W TV Epson Dot Matrix Printer ZX Printer
Now: Late 2012 iMac 27" 3.4GHz i7 16GB RAM OS X 10.10.4 1TB Fusion Drive USB 3 HDs Ext iPad Air 32GB iPhone 6 64GB Apple TV v2
leiradel
Posts: 15
Joined: Sat Mar 02, 2013 4:55 pm

Re: Messing with SP in a ZX81 in SLOW mode

Post by leiradel »

Hi Derek,

I'm using an alternative video interrupt that frees IY. This was tested with a sprite blit routine in a ZX81 emulator even before I started working on the VM and works just fine.

Thanks,

Andre
User avatar
dbolli
Posts: 5
Joined: Thu Nov 15, 2012 10:52 pm
Location: Sydney, Australia
Contact:

Re: Messing with SP in a ZX81 in SLOW mode

Post by dbolli »

Have you tried the vb81_XuR emulator for windoze?
(I run it using Wine emulator in OS X)
http://zx81.vb81.free.fr

It has a binary editor/memory viewer in the Tools->Binary Editor
menu and also emulates Memotech 64K RAM mode.

Regards,
Derek.
1985: ZX Spectrum+ 48K Interface 1 ZX81 16KB ASZMIC/SP ROM Philips 12" B/W TV Epson Dot Matrix Printer ZX Printer
Now: Late 2012 iMac 27" 3.4GHz i7 16GB RAM OS X 10.10.4 1TB Fusion Drive USB 3 HDs Ext iPad Air 32GB iPhone 6 64GB Apple TV v2
Post Reply