Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Use of Z80 in C128
2023-12-09 07:25
Repose

Registered: Oct 2010
Posts: 222
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
2023-12-09 11:11
Mr SQL

Registered: Feb 2023
Posts: 114
Related question - is there a way to use both simultaneously as co-processors?
2023-12-09 13:51
Krill

Registered: Apr 2002
Posts: 2844
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.
2023-12-09 17:21
Repose

Registered: Oct 2010
Posts: 222
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.
2023-12-09 19:33
chatGPZ

Registered: Dec 2001
Posts: 11116
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.
2023-12-10 08:57
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.
2023-12-10 10:07
Repose

Registered: Oct 2010
Posts: 222
Since the CPUs must share the RAM, it doesn't seem possible they could run at the same time.
2023-12-10 15:57
wil

Registered: Jan 2019
Posts: 42
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.
2023-12-10 18:48
Repose

Registered: Oct 2010
Posts: 222
That was the kind of answer I was looking for! Thanks for your input.
2023-12-10 22:19
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.
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Laurent
Grue/Extend
Guests online: 123
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Comaland 100%  (9.6)
6 No Bounds  (9.6)
7 Uncensored  (9.6)
8 Wonderland XIV  (9.6)
9 Memento Mori  (9.6)
10 Bromance  (9.5)
Top onefile Demos
1 It's More Fun to Com..  (9.7)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 TRSAC, Gabber & Pebe..  (9.5)
6 Rainbow Connection  (9.5)
7 Wafer Demo  (9.5)
8 Dawnfall V1.1  (9.5)
9 Quadrants  (9.5)
10 Daah, Those Acid Pil..  (9.5)
Top Groups
1 Oxyron  (9.3)
2 Nostalgia  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Crackers
1 Mr. Z  (9.9)
2 S!R  (9.9)
3 Antitrack  (9.8)
4 Mr Zero Page  (9.8)
5 OTD  (9.8)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.052 sec.