| |
Repose
Registered: Oct 2010 Posts: 227 |
Use of Z80 in C128
I had a few questions; practically, how fast can you switch between CPUs? Fast enough to make use of those routines that the Z80 is potentially faster at? Does each CPU retain its registers between swaps? Is there anything the Z80 is faster at than the 6502? And even so, are there any inefficiencies in the implementation of the Z80 in the C128? Finally, besides CP/M, has any software or demos made use of the Z80?
Thanks |
|
| |
Mr SQL
Registered: Feb 2023 Posts: 143 |
Related question - is there a way to use both simultaneously as co-processors? |
| |
Krill
Registered: Apr 2002 Posts: 2997 |
C-128's Z80 is clocked at 2 MHz as well, which makes it roughly equivalent to a 6502 running at half a MHz.
Better addressing modes and 16-bit index registers or not, i'd be impressed if someone made something on that Z80 achieving things faster than the 2-MHz 6502 in the same system.
Parallel execution seems to be ruled out, though, and i think the Z80 doesn't even have proper access to system peripherals and I/O. |
| |
Repose
Registered: Oct 2010 Posts: 227 |
I believe the 6502 is about twice as fast as the Z80 in terms of clock cycles. The instruction times of the Z80 are 4-12. If the Z80 ran at 4MHz and the 6502 at 2MHz, they should be overall equivalent. However, in some of the best cases, the Z80 could be faster. I believe that pushing 16-bit values to the stack on the Z80 could be a bit faster.
There was a thread on comp.sys.cbm (a topic of USENET newsgroup discussion) at one point in the 90s where a kind of competition occurred, and I believe Steve Judd participated as well. That would be one good source of info, but I haven't been able to find it yet. |
| |
chatGPZ
Registered: Dec 2001 Posts: 11433 |
Graham did test things with Z80 years ago - it's not worth it at all. You'll have a hard time making things equally fast as with 6502. |
| |
Pararaum
Registered: Sep 2018 Posts: 11 |
Quote: Related question - is there a way to use both simultaneously as co-processors?
No, it is one or the other AFAIK. |
| |
Repose
Registered: Oct 2010 Posts: 227 |
Since the CPUs must share the RAM, it doesn't seem possible they could run at the same time. |
| |
wil
Registered: Jan 2019 Posts: 64 |
Quote: I had a few questions; practically, how fast can you switch between CPUs? Fast enough to make use of those routines that the Z80 is potentially faster at? Does each CPU retain its registers between swaps? Is there anything the Z80 is faster at than the 6502? And even so, are there any inefficiencies in the implementation of the Z80 in the C128? Finally, besides CP/M, has any software or demos made use of the Z80?
Thanks
To enter the Z80 mode, you need to place a Z80 program at address $ffee and make the bank with the code visible. I usually put a "JP z80prgaddress" there and have the full z80 elsewhere at z80prgaddress. Then, putting $b0 into register $D505 makes the Z80 take over.
To go back, I use "JP $ffe0". At startup, the Kernal has placed in all RAM banks the code of a Z80 routine that makes the execution return to after where the "sta $d505" happened. The should be a NOP after "sta $d505" for stabilization.
Using this approach, a round trip takes around 70 1MHz clock ticks. A considerable loss of time, that only pays off if you have a lot of business in the Z80 land.
Thinking about Z80 mode at C128, there are not many practical uses that come to my mind, but some are:
- Sizecoding: the Z80 is slower, but its code density is much better than with the 6502. If you can get away with not counting the initialization code to get into Z80 mode, you might have a competitive advantage in sizecoding events like Lovebyte or VCCC
- Coding preferences: in case your brain thinks in Z80 code and you have a hard time writing the same algorithm in 6502 code. For me, it is exactly the opposite though.
- Running legacy software: This would be mostly limited to text-based or pure number-crunching applications. A text adventure Z-engine terp comes to my mind here.
- Small code: could help in a large project where compact code is important. But usually, memory is less of a problem on a C128. |
| |
Repose
Registered: Oct 2010 Posts: 227 |
That was the kind of answer I was looking for! Thanks for your input. |
| |
YTM
Registered: Apr 2021 Posts: 3 |
Quote: C-128's Z80 is clocked at 2 MHz as well, which makes it roughly equivalent to a 6502 running at half a MHz.
Better addressing modes and 16-bit index registers or not, i'd be impressed if someone made something on that Z80 achieving things faster than the 2-MHz 6502 in the same system.
Parallel execution seems to be ruled out, though, and i think the Z80 doesn't even have proper access to system peripherals and I/O.
Just one remark: Z80 does have full access to I/O. It's possible to load/store bytes there (when I/O is memory-mapped - enabled in MMU in $Dxxx space) or use IN/OUT into Z80 ports.
The first method bleeds data into underlying RAM on stores, the second method takes up more cycles. |