It is currently Sat Jan 20, 2018 8:15 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Mon May 04, 2015 6:25 pm 
Offline
User avatar

Joined: Mon Dec 22, 2008 10:45 pm
Posts: 311
Location: Argentina
Is there an undocumented opcodes list with byte lengths and cycle count?
I don't need to know how the actual instructions work or what status flags it affects, as I don't plan to implement any undocumented opcodes, but In the case that an undocumented opcode is found I want my emulator be able to just skip it correctly and hope it won't disrupt (much) the game execution. (instead of just halting)


Top
 Profile  
 
PostPosted: Mon May 04, 2015 6:41 pm 
Offline
User avatar

Joined: Sat Jul 12, 2014 3:04 pm
Posts: 953
http://www.oxyron.de/html/opcodes02.html

Byte length is determined solely by addressing mode, so...


Top
 Profile  
 
PostPosted: Mon May 04, 2015 7:25 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5984
Location: Canada
Myask wrote:
Byte length is determined solely by addressing mode, so...


This rule of thumb works well for most things, but BRK and maybe some multi-byte NOP instructions are a little bit unintuitive this way.


Top
 Profile  
 
PostPosted: Mon May 04, 2015 11:58 pm 
Offline
User avatar

Joined: Sun Sep 19, 2004 9:28 pm
Posts: 3195
Location: Mountain View, CA, USA
To expand on rainwarrior's comment a little more: unofficial opcodes that are "effectively" the same as NOP, but usually do not take 2 cycles like the real NOP -- instead, they tends to vary given what the CPU is actually doing under the hood.

There is also no official notation for illegal opcode mnemonics. People will tell you "ca65 has them as blah blah blah", but that isn't official (don't let them convince you otherwise). So if you're going to print them/show them in a debugger or something like that, I tend to recommend you just display them as "???" or things like ".db $xx" statements, since there's no standard.

P.S. -- In your emulator, you should implement this as a toggleable feature to stop/halt the emulator if an invalid opcode is encountered, or to skip them. Skipping may be tricky given the aforementioned cycle concerns (I'm not sure if any of the games which use illegal opcodes are "timing-sensitive" or not).


Top
 Profile  
 
PostPosted: Tue May 05, 2015 5:33 am 
Offline
User avatar

Joined: Sat Jul 12, 2014 3:04 pm
Posts: 953
rainwarrior wrote:
Myask wrote:
Byte length is determined solely by addressing mode, so...


This rule of thumb works well for most things, but BRK and maybe some multi-byte NOP instructions are a little bit unintuitive this way.

BRK I'll grant, even though it's not an undocumented opcode, but the NOP(/IGN/SKB/SKW)s are still determined by addressing mode. It's just that it feels odd to have a do-nothing that takes an argument; hence the alternate mnemonic "IGNore".


Top
 Profile  
 
PostPosted: Tue May 05, 2015 6:26 am 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5984
Location: Canada
koitsu wrote:
In your emulator, you should implement this as a toggleable feature to stop/halt the emulator if an invalid opcode is encountered, or to skip them. Skipping may be tricky given the aforementioned cycle concerns (I'm not sure if any of the games which use illegal opcodes are "timing-sensitive" or not).

What use would anyone have for skipping illegal opcodes? There'd be zero expectation that the code would run correctly after the skip (timing isn't even remotely a concern at this point). It also wouldn't match the behaviour of any 6502-compatible hardware... What would this be for?

(i.e. if you want to leave them unimplemented, the method you do it is pretty much irrelevant. There's no "correct" way to skip an instruction.)


Top
 Profile  
 
PostPosted: Tue May 05, 2015 7:26 am 
Offline
User avatar

Joined: Mon Dec 22, 2008 10:45 pm
Posts: 311
Location: Argentina
Myask wrote:
http://www.oxyron.de/html/opcodes02.html
Byte length is determined solely by addressing mode, so...
Right, thanks!

koitsu wrote:
In your emulator, you should implement this as a toggleable feature to stop/halt the emulator if an invalid opcode is encountered, or to skip them.
Good idea.

rainwarrior wrote:
There'd be zero expectation that the code would run correctly after the skip [...] What would this be for?
Well the expectation that the code would run correctly is certainly not 100% but it's not 0% either. Interpreting illegal opcodes wrongly or not at all could have, in some occasions, no adverse effect on the flow of the program or may have a recoverable effect, like say, drawing some garbage to the screen but still not disrupting the flow. I mean, I know it's not ideal, but any glitch, even the most awful ones are not worse than just halting the emulation.

rainwarrior wrote:
(i.e. if you want to leave them unimplemented, the method you do it is pretty much irrelevant. There's no "correct" way to skip an instruction.)
You're right, what I meant by correct is at least knowing how many bytes to skip in order to interpret the following instruction correctly and not landing on a 2nd or 3rd byte of the next instruction which would really break many following instructions.


Top
 Profile  
 
PostPosted: Tue May 05, 2015 7:46 am 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5984
Location: Canada
Sure, keeping the instruction lengths correct would be more likely to keep you in a recoverable state, though just treating every unknown instruction as a 1-byte NOP is somewhat effective toward the same goal. If the instructions aren't implemented, a warning to the user when the first bad opcode is hit at least would let them know that behaviour past this point is not expected to be correct.

I suppose implementing just the lengths is a mostly correct implementation of all the NOP instructions, at least. The Wiki has a very short list of some games using illegal opcodes, and a lot of them are just using nonstandard NOPs.


Top
 Profile  
 
PostPosted: Tue May 05, 2015 9:06 am 
Offline
User avatar

Joined: Mon Dec 22, 2008 10:45 pm
Posts: 311
Location: Argentina
rainwarrior wrote:
If the instructions aren't implemented, a warning to the user when the first bad opcode is hit at least would let them know that behaviour past this point is not expected to be correct.
Oh yes, totally.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group