It is currently Fri Oct 20, 2017 12:59 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 30 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: 6502 Illegal Opcodes
PostPosted: Mon Nov 18, 2013 9:05 pm 
Offline

Joined: Mon Mar 27, 2006 5:23 pm
Posts: 1338
Has the NES scene decided upon a consistent and pseudo-official (say, NESdev official) set of names for all of the opcodes yet?

Last time I looked, there were 4-5 variants for each unofficial opcode.

If not, I'd strongly recommend doing so. I don't care what they are (so long as there are no overlaps; such that any can be specified distinctly with an assembler), I'd just like everyone to have the same name for each one.


Top
 Profile  
 
 Post subject: Re: 6502 Illegal Opcodes
PostPosted: Mon Nov 18, 2013 9:46 pm 
Online

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19110
Location: NE Indiana, USA (NTSC)
byuu wrote:
Has the NES scene decided upon a consistent and pseudo-official (say, NESdev official) set of names for all of the opcodes yet?

In the wiki's pages about the opcode matrix and uses of the stable unofficial opcodes, I used the names from the 6502X section of the ca65 Users Guide, which got them from Graham of Oxyron. I used the same mnemonics in my reimplementation of 6502 opcodes as ca65 macros.


Top
 Profile  
 
 Post subject: Re: 6502 Illegal Opcodes
PostPosted: Tue Nov 19, 2013 10:19 am 
Offline
User avatar

Joined: Fri Mar 08, 2013 9:55 pm
Posts: 349
Location: Linköping, Sweden
Another document you should be aware of is http://www.ffd2.com/fridge/docs/6502-NMOS.extra.opcodes . I used that one along with the one you linked when I implemented the unofficial opcodes. IIRC, the 6502-NMOS.extra.opcodes version tends to be correct for instructions where they differ.

The instruction logic in nesalizer should be pretty easy to read if you don't mind looking at some code. Search for "Core instruction logic" in https://github.com/ulfalizer/nesalizer/ ... er/cpu.cpp . It passes Kevtris' and blargg's unofficial instruction test ROMs.


Top
 Profile  
 
 Post subject: Re: 6502 Illegal Opcodes
PostPosted: Tue Nov 19, 2013 10:24 am 
Offline
User avatar

Joined: Fri Mar 08, 2013 9:55 pm
Posts: 349
Location: Linköping, Sweden
And yeah, it would be nice there were agreed-upon mnemonics. I probably have a mix of them from different sources.


Top
 Profile  
 
 Post subject: Re: 6502 Illegal Opcodes
PostPosted: Tue Nov 19, 2013 12:13 pm 
Offline

Joined: Thu Sep 15, 2005 9:23 am
Posts: 1194
Location: Behind you with a knife!
Just tested Visual6502 and SXA, 9E doesn't increment that high byte of the argument by 1.

Visual6502

DataBus = (X & ((temp >> 8) + 0));

What we are told

DataBus = (X & ((temp >> 8) + 1));

_________________
http://www.jamesturner.de/


Top
 Profile  
 
 Post subject: Re: 6502 Illegal Opcodes
PostPosted: Tue Nov 19, 2013 1:58 pm 
Offline
User avatar

Joined: Fri Mar 08, 2013 9:55 pm
Posts: 349
Location: Linköping, Sweden
The behavior of 9C and 9E depends on whether you get a page crossing or not, see viewtopic.php?f=3&t=3831&start=30#p113343 . Should probably add to the wiki. :?


Top
 Profile  
 
 Post subject: Re: 6502 Illegal Opcodes
PostPosted: Tue Nov 19, 2013 2:04 pm 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6287
Location: Seattle
I just threw this in visual 6502:
Code:
LDX #$FF
LDY #$80
.byte $9E, $80, 0
And it stored 1 to $0100, and took 5 cycles.

I then threw this is visual 6502:
Code:
LDX #$FF
LDY #$40
.byte $9E, $80, 0
And it stored 1 to $00C0, and took 5 cycles.
So ... dunno??


Top
 Profile  
 
 Post subject: Re: 6502 Illegal Opcodes
PostPosted: Tue Nov 19, 2013 2:24 pm 
Offline
User avatar

Joined: Fri Mar 08, 2013 9:55 pm
Posts: 349
Location: Linköping, Sweden
lidnariq wrote:
I just threw this in visual 6502:
Code:
LDX #$FF
LDY #$80
.byte $9E, $80, 0
And it stored 1 to $0100, and took 5 cycles.

I then threw this is visual 6502:
Code:
LDX #$FF
LDY #$40
.byte $9E, $80, 0
And it stored 1 to $00C0, and took 5 cycles.
So ... dunno??


Looks correct. Both the value (of X in this case) and the high byte of the target address are corrupted when there's a page crossing. When there's no page crossing, only the value is corrupted.

What I think is going is that the CPU always calculates the high address byte + 1 in case it's needed and puts it on bus B (arbitrary name). Due to a bus conflict, the value (of X in this case) is also put on bus B, which gives the &. When there's a page crossing, the CPU also tries to get the corrected high address byte from bus B, and so gets the same corrupted value there.

Edit: In this case I guess the target address is never corrupted though, since X if $FF. :?


Top
 Profile  
 
 Post subject: Re: 6502 Illegal Opcodes
PostPosted: Tue Nov 19, 2013 2:44 pm 
Offline
User avatar

Joined: Fri Mar 08, 2013 9:55 pm
Posts: 349
Location: Linköping, Sweden
WedNESday wrote:
Just tested Visual6502 and SXA, 9E doesn't increment that high byte of the argument by 1.

Visual6502

DataBus = (X & ((temp >> 8) + 0));

What we are told

DataBus = (X & ((temp >> 8) + 1));


What's temp there? If it's the target address (after the high address byte has been corrected), then it's what I'd expect if there's a page crossing.


Top
 Profile  
 
 Post subject: Re: 6502 Illegal Opcodes
PostPosted: Tue Nov 19, 2013 2:58 pm 
Offline

Joined: Thu Sep 15, 2005 9:23 am
Posts: 1194
Location: Behind you with a knife!
temp = low + high + X or Y;

_________________
http://www.jamesturner.de/


Last edited by WedNESday on Tue Nov 19, 2013 2:58 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: 6502 Illegal Opcodes
PostPosted: Tue Nov 19, 2013 2:58 pm 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6287
Location: Seattle
ulfalizer wrote:
Edit: In this case I guess the target address is never corrupted though, since X if $FF. :?
Ahah.
X=$FD, Y=$F0, .byte $9e, $f0, $02 ultimately writes 1 to $01e0, instead of writing 3 to $03e0.
And replacing Y with $0 writes 1 to $02f0


Top
 Profile  
 
 Post subject: Re: 6502 Illegal Opcodes
PostPosted: Tue Nov 19, 2013 5:07 pm 
Offline

Joined: Thu Sep 15, 2005 9:23 am
Posts: 1194
Location: Behind you with a knife!
SXA now passes all test ROMs.

Code:
if (low + Y > 0xFF)
   low += (((high & X) << 8) + Y);
else
   low += ((high << 8) + Y);

DataBus = (X & (high + 1));


Thanks for the help guys.

_________________
http://www.jamesturner.de/


Top
 Profile  
 
 Post subject: Re: 6502 Illegal Opcodes
PostPosted: Tue Nov 19, 2013 7:42 pm 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6287
Location: Seattle
WedNESday wrote:
address = (((high & X) << 8) + Y) + low;
That looks wrong. Shouldn't it be address = (((high+1)&X) << 8) + ((Y+low)&255)?
For example, if the sequence were
X=$FD, Y=$F0, .byte $9e, $f0, $01, what you have would write 0 to $02e0, but it should write 0 to $00e0.


Top
 Profile  
 
 Post subject: Re: 6502 Illegal Opcodes
PostPosted: Sun Apr 10, 2016 6:52 pm 
Offline
Formerly Fx3
User avatar

Joined: Fri Nov 12, 2004 4:59 pm
Posts: 3064
Location: Brazil
Sorry for the bump, but I can't figure out the SHY/SHX ($9C,$9E) opcode timing diagram AND operation.
Could someone make it crystal clear, plz? ^_^;;


Top
 Profile  
 
 Post subject: Re: 6502 Illegal Opcodes
PostPosted: Sun Apr 10, 2016 8:32 pm 
Offline
User avatar

Joined: Mon Dec 29, 2014 1:46 pm
Posts: 710
Location: New York, NY
Zepper wrote:
Sorry for the bump, but I can't figure out the SHY/SHX ($9C,$9E) opcode timing diagram AND operation.
Could someone make it crystal clear, plz? ^_^;;


Code:
 

  // 1
  opcode = read(PC);
  incrementPC();

  // ...

  private void ABSOLUTE_INDEXED_WRITE() {
    // 2
    int value = read(PC);
    incrementPC();
    // 3
    final int offset;
    value |= read(PC) << 8;
    switch(opcode) {
      case 0x9C: // *SHY $A5B6,X
      case 0x9D: // STA $A5B6,X
        offset = X;
        break;
      default:
        offset = Y;
        break;
    }
    int address = (value + offset) & 0xFFFF;
    value = (value & 0xFF00) | (address & 0x00FF);
    incrementPC();       
    // 4
    read(value);
    // 5       
    switch(opcode) {
      case 0x99: // STA $A5B6,Y
      case 0x9D: // STA $A5B6,X
        write(address, A);
        break;
      case 0x9C: // *SHY $A5B6,X
        if ((value >> 8) != (address >> 8)) {
          value &= Y << 8;
        }
        write(value, Y & ((value >> 8) + 1));
        break;
      case 0x9E: // *SHX $A5B6,Y
        if ((value >> 8) != (address >> 8)) {
          value &= X << 8;
        }
        write(value, X & ((value >> 8) + 1));
        break;
      case 0x9F: // *SHA $A5B6,Y
        if ((value >> 8) != (address >> 8)) {
          value &= (X & A) << 8;
        }
        write(address, X & A & ((address >> 8) + 1));
        break;
    }
  }


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 30 posts ]  Go to page Previous  1, 2

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 5 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