Skip to content

Commit

Permalink
TSX opcode
Browse files Browse the repository at this point in the history
  • Loading branch information
Shachar committed Sep 12, 2023
1 parent 9aa6793 commit d5b1eb9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
34 changes: 25 additions & 9 deletions c6502.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void c6502::handleInstruction() {
case 0x86: op_stx( addrmode_zp() ); break;
case 0x88: op_dey( addrmode_implicit() ); break;
case 0x89: op_bit( addrmode_immediate() ); break;
case 0x8a: op_txa( addrmode_implicit() ); break;
case 0x8a: op_txa(); break;
case 0x8c: op_sty( addrmode_abs() ); break;
case 0x8d: op_sta( addrmode_abs() ); break;
case 0x8e: op_stx( addrmode_abs() ); break;
Expand All @@ -138,9 +138,9 @@ void c6502::handleInstruction() {
case 0x94: op_sty( addrmode_zp_x() ); break;
case 0x95: op_sta( addrmode_zp_x() ); break;
case 0x96: op_stx( addrmode_zp_y() ); break;
case 0x98: op_tya( addrmode_implicit() ); break;
case 0x98: op_tya(); break;
case 0x99: op_sta( addrmode_abs_y(true) ); break;
case 0x9a: op_txs( addrmode_implicit() ); break;
case 0x9a: op_txs(); break;
case 0x9d: op_sta( addrmode_abs_x(true) ); break;
case 0xa0: op_ldy( addrmode_immediate() ); break;
case 0xa2: op_ldx( addrmode_immediate() ); break;
Expand All @@ -160,6 +160,7 @@ void c6502::handleInstruction() {
case 0xb6: op_ldx( addrmode_zp_y() ); break;
case 0xb8: op_clv( addrmode_implicit() ); break;
case 0xb9: op_lda( addrmode_abs_y() ); break;
case 0xba: op_tsx(); break;
case 0xbc: op_ldy( addrmode_abs_x() ); break;
case 0xbd: op_lda( addrmode_abs_x() ); break;
case 0xbe: op_ldx( addrmode_abs_y() ); break;
Expand Down Expand Up @@ -842,22 +843,37 @@ void c6502::op_tay() {
updateNZ( regA );
}

void c6502::op_txa(Addr addr) {
regA = regX;
void c6502::op_tsx() {
read( pc() );

updateNZ( regA );
regX = regSp;

updateNZ( regX );
}

void c6502::op_tya(Addr addr) {
regA = regY;

void c6502::op_txa() {
read( pc() );

regA = regX;

updateNZ( regA );
}

void c6502::op_txs(Addr addr) {
void c6502::op_txs() {
read( pc() );

regSp = regX;
}

void c6502::op_tya() {
read( pc() );

regA = regY;

updateNZ( regA );
}

void c6502::updateNZ(uint8_t val) {
ccSet( CC::Negative, val & 0x80 );
ccSet( CC::Zero, val == 0 );
Expand Down
7 changes: 4 additions & 3 deletions c6502.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,10 @@ class c6502 {
void op_sty(Addr addr);
void op_tax();
void op_tay();
void op_txa(Addr addr);
void op_txs(Addr addr);
void op_tya(Addr addr);
void op_tsx();
void op_txa();
void op_txs();
void op_tya();

void updateNZ(uint8_t val);
};

0 comments on commit d5b1eb9

Please sign in to comment.