Schrijver
| How safe is to use undocumented Z80 instructions?
|
Chardson msx lover Berichten: 93 | Geplaatst: 17 April 2007, 10:03   |
Hi all,
I was modifing a routine I found on the web to work with some programs I am doing. But my modifications needed more two 8 bit registers. So, to avoid a lot of pushs and pops, I was thinking about using IXl and IXh (specially because of their accumulator properties). But I was wondering if it would turn to be a big trouble, compatibility-wise.
At first, it appears to be pretty safe, since some Master System games (Codemasters') and even some MSX games/software uses it. But, as asking won't hurt none, how was your general experience with using those kind of instructions? Should I avoid them at all cost?
Thanks all!
|
|
multi msx lover Berichten: 67 | Geplaatst: 17 April 2007, 11:54   |
on the turbo-r cpu (R800) a lot of undocumented instructions are replaced to do nothing (NOP). i think all the new feature adding instructions with IX & IY do work though. so the instructions you mention would be safe to use on even a R800 cpu (although testing it to be a 100% sure would be better then trusting me...)
also the R800 has undocumented instructions, i think they are maybe some MUL or DIV like instructions, but never really took the time to get into them (think it is only 1, but it's a long time ago).
|
|
sjoerd msx addict Berichten: 444 | Geplaatst: 17 April 2007, 12:16   |
On Z80 all undocumented instructions are safe.
Instructions using ixh, ixl, iyl and iyh are official instructions on R800, so no problem. But undocumented Z80 instructions like sll, out (c),0 and others don't work on R800. Don't know about set 7,(ix+0),b and the like on R800, but I don't think anybody uses those.
|
|
Chardson msx lover Berichten: 93 | Geplaatst: 17 April 2007, 23:14   |
Hmm, I haven't looked other undocumented instructions, but knowing that I can freely use IX and IY is very good! Thanks folks!
|
|
AuroraMSX
 msx master Berichten: 1228 | Geplaatst: 21 April 2007, 11:27   |
Quote:
| Hi all,
I was modifing a routine I found on the web to work with some programs I am doing. But my modifications needed more two 8 bit registers. So, to avoid a lot of pushs and pops, I was thinking about using IXl and IXh (specially because of their accumulator properties). But I was wondering if it would turn to be a big trouble, compatibility-wise.
|
And there's always the option to use the alternative register set - 100% documented and safe  |
|
GhostwriterP msx addict Berichten: 305 | Geplaatst: 21 April 2007, 11:52   |
At the point I start using ixh and ixl that alternative register set is also already in use.  |
|
AuroraMSX
 msx master Berichten: 1228 | Geplaatst: 21 April 2007, 12:11   |
Quote:
| At the point I start using ixh and ixl that alternative register set is also already in use. 
|
But you're not Chardson  |
|
nikodr msx addict Berichten: 453 | Geplaatst: 21 April 2007, 14:42   |
Is there a command that can be used under basic that can switch from z80 to r800 mode ?If not then could someone post an assembly code that i could insert as data in a basic program and call it?(Actually i am just fooling around with turbo-r emulators on pc i do not have a real turbo-r0.
|
|
nikodr msx addict Berichten: 453 | Geplaatst: 21 April 2007, 14:42   |
Sorry for double post!Please delete it....
|
|
NYYRIKKI msx master Berichten: 1503 | Geplaatst: 21 April 2007, 15:22   |
@nikodr No, there is no internal command, but you can use this BASIC line in middle of your program:
8728 DEFUSR=39+PEEK(-2385)+PEEK(-2384)*256:IFUSR(0)THENLINE>1COPY0&H80F6OR384ALLYOURBASEAREBELONGTOUS!
Change number after "LINE>" like this:
0 = Z80 (ROM)
1 = R800 (ROM)
2 = R800 (DRAM)
If you type only this one line and save it with .COM extension you can use this program also in DOS.
Example:
SAVE"Z80.COM"
_SYSTEM
Z80
|
|
nikodr msx addict Berichten: 453 | Geplaatst: 21 April 2007, 17:42   |
thanks will try it later 
Regards |
|
Chardson msx lover Berichten: 93 | Geplaatst: 22 April 2007, 08:21   |
Quote:
| Quote:
| Hi all,
I was modifing a routine I found on the web to work with some programs I am doing. But my modifications needed more two 8 bit registers. So, to avoid a lot of pushs and pops, I was thinking about using IXl and IXh (specially because of their accumulator properties). But I was wondering if it would turn to be a big trouble, compatibility-wise.
|
And there's always the option to use the alternative register set - 100% documented and safe 
|
Yeah, I could use them, but this routine belongs to a lib I am doing while I work on the main program. And I don't think it is good for a "general" routine to use exx. If so, every "general" routine should use them and main programs should never.  |
|
AuroraMSX
 msx master Berichten: 1228 | Geplaatst: 22 April 2007, 12:58   |
Quote:
| Yeah, I could use them, but this routine belongs to a lib I am doing while I work on the main program. And I don't think it is good for a "general" routine to use exx. If so, every "general" routine should use them and main programs should never. 
|
Documentation is the key here. You're also using the normal registers - all of them, apparently. Does that imply that main programs should never do that? No, it means that if the main program uses the registers, it has the responsibility to save their values somewhere - e.g. on the stack - before calling your lib function, and restore them afterwards. The same holds for the alternative register set: if the main program uses it, it will have the responsibility to save the contents.
Your lib documentation will just note that this particular routine uses the alternative registers and you're done
But that's just my 2cts... (Plus: who else is going to use that lib and which other program than the one you're currently working on uses this lib?  ) |
|
Edwin msx professional Berichten: 593 | Geplaatst: 22 April 2007, 13:56   |
In my experience, exx is rarely a solution for the problem because you lose the current values of bc, de, hl as well. Which you don't really want because you were out of registers for a reason. In that case it's a very good solution to use ixl, ixh, iyl and iyh for storage of 8 bit values or counters. In many cases it's the faster solution. I use them quite a lot myself. Much more than exx. I haven't heard of any compatibility issue with any msx machine.
|
|
wolf_
 msx legend Berichten: 4658 | Geplaatst: 22 April 2007, 14:34   |
NYYRIKKI: do you obfuscate your tax forms as well, like that?  |
|
|
|
|