CPCWiki forum

General Category => Emulators => Topic started by: aidano on 15:30, 26 November 22

Title: Z80 instructions - subset implemented by 464 rom?
Post by: aidano on 15:30, 26 November 22
I'm trying to find out what subset of the full z80 instruction set is used by the CPC 464 rom. Is it documented anywhere?

For context, I'm writing an emulator and am partially into the laborious stage of implementing the instruction set. Doing every single instruction up front will probably destroy me :) so my strategy is to take a loaded 464 rom, and begin interpreting each instruction that's not currently understood by my runtime. I realize that knowing the answer won't change the amount of work, but I would like to know what's ahead of me for this phase of the project.
Title: Re: Z80 instructions - subset implemented by 464 rom?
Post by: Bryce on 15:45, 26 November 22
https://www.cpcwiki.eu/index.php/Soft968:_CPC_464/664/6128_Firmware

Bryce.
Title: Re: Z80 instructions - subset implemented by 464 rom?
Post by: aidano on 18:12, 26 November 22
Thanks @Bryce - are the instructions enumerated in there anywhere? I took a quick look through but didn't see it, but could just have missed something obvious.

This may not exist in the from I'm seeking (outside of other CPC emulator source code which has chosen a similar path to only implement a subset of instructions, but I'm looking to completely avoid looking at any other emulator implementation).
Title: Re: Z80 instructions - subset implemented by 464 rom?
Post by: Gryzor on 18:19, 26 November 22
I think you mean @Bryce  🙂
Title: Re: Z80 instructions - subset implemented by 464 rom?
Post by: Bryce on 18:41, 26 November 22
Quote from: Gryzor on 18:19, 26 November 22I think you mean @Bryce  🙂

So we're not interchangeable?? :o

Bryce.
Title: Re: Z80 instructions - subset implemented by 464 rom?
Post by: aidano on 18:43, 26 November 22
Quote from: Gryzor on 18:19, 26 November 22I think you mean @Bryce  🙂
Oops! Sorry for the summons!
Title: Re: Z80 instructions - subset implemented by 464 rom?
Post by: Gryzor on 18:48, 26 November 22
Quote from: Bryce on 18:41, 26 November 22
Quote from: Gryzor on 18:19, 26 November 22I think you mean @Bryce  🙂

So we're not interchangeable?? :o

Bryce.

You do the hardware, I'll do the (messing up of) the forum database. 
Title: Re: Z80 instructions - subset implemented by 464 rom?
Post by: Gryzor on 18:49, 26 November 22
Quote from: aidano on 18:43, 26 November 22
Quote from: Gryzor on 18:19, 26 November 22I think you mean @Bryce  🙂
Oops! Sorry for the summons!
No worries, I actually meant to read your thread and the quote notification prompted me to finally open it 🙂
Title: Re: Z80 instructions - subset implemented by 464 rom?
Post by: Bryce on 18:52, 26 November 22
Quote from: Gryzor on 18:48, 26 November 22
Quote from: Bryce on 18:41, 26 November 22
Quote from: Gryzor on 18:19, 26 November 22I think you mean @Bryce  🙂

So we're not interchangeable?? :o

Bryce.

You do the hardware, I'll do the (messing up of) the forum database.

A small (evil) part of me wants to see you soldering an 0201 resistor without messing it up.

Bryce.
Title: Re: Z80 instructions - subset implemented by 464 rom?
Post by: Gryzor on 19:19, 26 November 22
I'll need new glasses for that one. I can do a 0603 though -oh you said without messing it up? That's unfair. I'll give it a try when you fix the quotes query that randomly makes the CPU spike for a minute or so. 
Title: Re: Z80 instructions - subset implemented by 464 rom?
Post by: Prodatron on 12:01, 27 November 22
Back to topic:

Quote from: aidano on 15:30, 26 November 22I'm trying to find out what subset of the full z80 instruction set is used by the CPC 464 rom. Is it documented anywhere?

For context, I'm writing an emulator and am partially into the laborious stage of implementing the instruction set. Doing every single instruction up front will probably destroy me :) so my strategy is to take a loaded 464 rom, and begin interpreting each instruction that's not currently understood by my runtime. I realize that knowing the answer won't change the amount of work, but I would like to know what's ahead of me for this phase of the project.
I think there is no clean, sorted list of the used Z80 instructions in the 464 ROM.
Maybe a ROM listing may help you:

https://www.cpcwiki.eu/index.php/ROM-Listing_CPC_464/664/6128

It starts at page 217, where the complete ROM is disassembled (sorry, comments in german, but I guess just the instructions are the thing you are looking for).

I think they used nearly all "official" Z80 instructions. What they didn't use are stuff like IXL, IXH, IYL, IYH or OUT (C),0
IIRC the 2nd register set is only used during interrupt handling.
Title: Re: Z80 instructions - subset implemented by 464 rom?
Post by: BSC on 12:23, 27 November 22
Quote from: aidano on 15:30, 26 November 22For context, I'm writing an emulator and am partially into the laborious stage of implementing the instruction set. Doing every single instruction up front will probably destroy me
Honestly, I don't think you should spend (waste) your time on finding that subset. Eventually you will have to implement the whole set of instructions anyway, otherwise software will randomly work or not work. Also there are already working implementations of a Z80 emulation in a lot of languages. Unless you really want to roll your own, you could resort to one of those. But the time you already spent on researching that ROM issue could have been spent on implementing a not so tiny part of the instruction set, I suppose :) Finally, to add to Prodatron's comment, which I agree with, the lower ROM alone would not give you a running CPC, for that the Basic ROM also needs to be present and I am pretty sure that the vast majority of the instruction set is used in both ROMs combined.
Title: Re: Z80 instructions - subset implemented by 464 rom?
Post by: aidano on 16:18, 27 November 22
Quote from: Prodatron on 12:01, 27 November 22Back to topic:

Quote from: aidano on 15:30, 26 November 22I'm trying to find out what subset of the full z80 instruction set is used by the CPC 464 rom. Is it documented anywhere?

For context, I'm writing an emulator and am partially into the laborious stage of implementing the instruction set. Doing every single instruction up front will probably destroy me :) so my strategy is to take a loaded 464 rom, and begin interpreting each instruction that's not currently understood by my runtime. I realize that knowing the answer won't change the amount of work, but I would like to know what's ahead of me for this phase of the project.
I think there is no clean, sorted list of the used Z80 instructions in the 464 ROM.
Maybe a ROM listing may help you:

https://www.cpcwiki.eu/index.php/ROM-Listing_CPC_464/664/6128

It starts at page 217, where the complete ROM is disassembled (sorry, comments in german, but I guess just the instructions are the thing you are looking for).

I think they used nearly all "official" Z80 instructions. What they didn't use are stuff like IXL, IXH, IYL, IYH or OUT (C),0
IIRC the 2nd register set is only used during interrupt handling.
Thanks, that's helpful to at least follow along as my runtime proceeds through the code. Clearly I was off-base in my guess that some non-trivial number of instructions weren't used. What a useful little chip the Z80 was :)
Title: Re: Z80 instructions - subset implemented by 464 rom?
Post by: aidano on 16:23, 27 November 22
Quote from: BSC on 12:23, 27 November 22
Quote from: aidano on 15:30, 26 November 22For context, I'm writing an emulator and am partially into the laborious stage of implementing the instruction set. Doing every single instruction up front will probably destroy me
Honestly, I don't think you should spend (waste) your time on finding that subset. Eventually you will have to implement the whole set of instructions anyway, otherwise software will randomly work or not work. Also there are already working implementations of a Z80 emulation in a lot of languages. Unless you really want to roll your own, you could resort to one of those. But the time you already spent on researching that ROM issue could have been spent on implementing a not so tiny part of the instruction set, I suppose :) Finally, to add to Prodatron's comment, which I agree with, the lower ROM alone would not give you a running CPC, for that the Basic ROM also needs to be present and I am pretty sure that the vast majority of the instruction set is used in both ROMs combined.
Thanks, makes sense. I was under the false assumption that there would be some kind of 80/20 rule at play here with the instructions that the firmware and most games would use.

And yes, I could for sure look for existing implementations, but my goal is an exploration of writing an emulator/learning a new language, while looking out for opportunities to see tangible progress.
Title: Re: Z80 instructions - subset implemented by 464 rom?
Post by: andycadley on 20:15, 27 November 22
If you want to try and get away with a subset implementation, just have the whole thing stop on hitting an instruction you haven't implented. Then add that and see how much further it goes. Like others say though, it'll probably hit the majority of them.
Title: Re: Z80 instructions - subset implemented by 464 rom?
Post by: aidano on 20:54, 27 November 22
Quote from: andycadley on 20:15, 27 November 22If you want to try and get away with a subset implementation, just have the whole thing stop on hitting an instruction you haven't implented. Then add that and see how much further it goes. Like others say though, it'll probably hit the majority of them.
That's precisely what I'm doing :)
Powered by SMFPacks Menu Editor Mod