Rearrange the 6809 code such that I can fire memory events.

Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon 2018-08-19 00:55:59 +01:00
parent ab1d84703b
commit 15e1258f40
3 changed files with 34 additions and 14 deletions

View File

@ -71,9 +71,10 @@ namespace EightBit {
const uint8_t SWI3vector = 0xf2;
const uint8_t RESERVEDvector = 0xf0;
uint8_t& AM_direct() {
//
void Address_direct() {
BUS().ADDRESS() = register16_t(fetchByte(), DP());
return BUS().reference();
}
register16_t& RR(int which) {
@ -93,7 +94,7 @@ namespace EightBit {
}
}
uint8_t& AM_indexed() {
void Address_indexed() {
const auto type = fetchByte();
auto& rr = RR(type & (Bit6 | Bit5));
switch (type & Bit7) {
@ -167,16 +168,33 @@ namespace EightBit {
default:
UNREACHABLE;
}
return BUS().reference();
}
uint8_t& AM_extended() {
void Address_extended() {
BUS().ADDRESS() = fetchWord();
return BUS().reference();
}
//
uint8_t AM_direct() {
Address_direct();
return BUS().read();
}
uint8_t AM_indexed() {
Address_indexed();
return BUS().read();
}
uint8_t AM_extended() {
AM_extended();
return BUS().read();
}
//
void abx();
void neg(uint8_t& operand);
uint8_t neg(uint8_t operand);
register16_t m_d;
register16_t m_x;

View File

@ -31,14 +31,14 @@ int EightBit::mc6809::execute(uint8_t cell) {
switch (cell) {
// ABX
case 0x3a: addCycles(3); abx(); break; // ABX (inherent)
case 0x3a: addCycles(3); abx(); break; // ABX (inherent)
// NEG
case 0x00: addCycles(6); neg(AM_direct()); break; // NEG (direct)
case 0x40: addCycles(2); neg(A()); break; // NEG (NEGA, inherent)
case 0x50: addCycles(2); neg(B()); break; // NEG (NEGB, inherent)
case 0x60: addCycles(6); neg(AM_indexed()); break; // NEG (indexed)
case 0x70: addCycles(7); neg(AM_extended()); break; // NEG (extended)
case 0x00: addCycles(6); BUS().write(neg(AM_direct())); break; // NEG (direct)
case 0x40: addCycles(2); A() = neg(A()); break; // NEG (NEGA, inherent)
case 0x50: addCycles(2); B() = neg(B()); break; // NEG (NEGB, inherent)
case 0x60: addCycles(6); BUS().write(neg(AM_indexed())); break; // NEG (indexed)
case 0x70: addCycles(7); BUS().write(neg(AM_extended())); break; // NEG (extended)
default:
ASSUME(false);
@ -54,11 +54,12 @@ void EightBit::mc6809::abx() {
X() += B();
}
void EightBit::mc6809::neg(uint8_t& operand) {
uint8_t EightBit::mc6809::neg(uint8_t operand) {
setFlag(CC(), VF, operand == Bit7);
const register16_t result = 0 - operand;
operand = result.low;
setFlag(CC(), NF, operand & Bit7);
setFlag(CC(), ZF, operand == 0);
setFlag(CC(), CF, result.word & Bit8);
return operand;
}

View File

@ -43,6 +43,7 @@ namespace EightBit {
write(value);
}
protected:
virtual uint8_t& reference(uint16_t address) = 0;
uint8_t& reference() { return reference(ADDRESS().word); }