aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Isom <kyle@tyrfingr.is>2014-01-29 14:21:11 -0700
committerKyle Isom <kyle@tyrfingr.is>2014-01-29 14:21:11 -0700
commit398d2c6999acc8c37807f80a366cb80160e183f9 (patch)
tree633b12f9b3f58e47c192b35c09072dd2ee413a85
parent4c3f4858de323f983628a9889fac1fe09de70c2a (diff)
downloadk6502-398d2c6999acc8c37807f80a366cb80160e183f9.tar.gz
k6502-398d2c6999acc8c37807f80a366cb80160e183f9.tar.bz2
k6502-398d2c6999acc8c37807f80a366cb80160e183f9.zip
JSR/RTS and DMA added.
-rw-r--r--src/cpu.cc66
-rw-r--r--src/cpu.h8
2 files changed, 73 insertions, 1 deletions
diff --git a/src/cpu.cc b/src/cpu.cc
index 6d00eb2..b0fa63e 100644
--- a/src/cpu.cc
+++ b/src/cpu.cc
@@ -660,6 +660,49 @@ CPU::BEQ(uint8_t n)
}
+void
+CPU::JMP()
+{
+ debug("OP: JMP");
+ uint16_t addr = this->read_addr1(C01_MODE_ABS);
+ std::cerr << "[DEBUG] JMP ADDR: " << std::setw(4)
+ << std::hex << std::setfill('0')
+ << addr << std::endl;
+ this->pc = addr;
+}
+
+
+static uint16_t
+stack_addr(uint8_t sp)
+{
+ return (1 << 8) + sp;
+}
+
+
+void
+CPU::JSR()
+{
+ debug("OP: JSR");
+ uint16_t jaddr = this->read_addr1(C01_MODE_ABS);
+ uint16_t addr = this->pc-1;
+
+ this->ram.poke(stack_addr(this->s--), (uint8_t)(addr >> 8));
+ this->ram.poke(stack_addr(this->s--), (uint8_t)(addr << 8 >> 8));
+ this->pc = jaddr;
+}
+
+
+void
+CPU::RTS()
+{
+ debug("OP: RTS");
+ uint16_t addr;
+ addr = this->ram.peek(stack_addr(++this->s));
+ addr += (this->ram.peek(stack_addr(++this->s)) << 8);
+ this->pc = addr+1;
+}
+
+
/*
* Stack instructions.
*/
@@ -704,15 +747,24 @@ CPU::step()
case 0x10: // BPL
this->BPL(this->read_immed());
return true;
+ case 0x20: // JSR
+ this->JSR();
+ return true;
case 0x30: // BMI
this->BMI(this->read_immed());
return true;
case 0x48: // PHA
this->PHA();
return true;
+ case 0x4C: // JMP
+ this->JMP();
+ return true;
case 0x50: // BVC
this->BVC(this->read_immed());
return true;
+ case 0x60: // RTS
+ this->RTS();
+ return true;
case 0x68: // PLA
this->PLA();
return true;
@@ -954,3 +1006,17 @@ CPU::read_addr0(uint8_t mode)
<< std::hex << addr << std::endl;
return addr;
}
+
+
+uint8_t
+CPU::DMA(uint16_t loc)
+{
+ return this->ram.peek(loc);
+}
+
+
+void
+CPU::DMA(uint16_t loc, uint8_t val)
+{
+ this->ram.poke(loc, val);
+}
diff --git a/src/cpu.h b/src/cpu.h
index 4b4a12e..91e1f1f 100644
--- a/src/cpu.h
+++ b/src/cpu.h
@@ -94,7 +94,7 @@ class CPU {
void TAX(void);
void TXA(void);
- // Branching
+ // Branching / jumping
void BPL(uint8_t);
void BMI(uint8_t);
void BVC(uint8_t);
@@ -103,6 +103,9 @@ class CPU {
void BCS(uint8_t);
void BNE(uint8_t);
void BEQ(uint8_t);
+ void JMP(void);
+ void JSR(void);
+ void RTS(void);
// Stack
void PHA(void);
@@ -122,6 +125,9 @@ class CPU {
void load(const void *, uint16_t, uint16_t);
void store(void *, uint16_t, uint16_t);
+ uint8_t DMA(uint16_t);
+ void DMA(uint16_t, uint8_t);
+
};