Tidy a couple of MC6809 niggles:

1) Move the stdafx.h to the correct place (out of the include search path)
2) Simplify long branch extra cycle handling
3) Rename derived flag handling, to remove B prefix
4) Make interrupt mask flag handling a little easier to read

Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon
2018-09-22 10:54:05 +01:00
parent 7c03521025
commit d45401d9b1
5 changed files with 54 additions and 49 deletions

View File

@@ -254,18 +254,21 @@ namespace EightBit {
// Flag checking
int fastInterruptMasked() { return CC() & FF; }
int interruptMasked() { return CC() & IF; }
int negative() { return CC() & NF; }
int zero() { return CC() & ZF; }
int overflow() { return CC() & VF; }
int carry() { return CC() & CF; }
int halfCarry() { return CC() & HF; }
bool BLS() { return carry() | (zero() >> 2); } // (C OR Z)
bool BHI() { return !BLS(); } // !(C OR Z)
bool BLT() { return (negative() >> 1) ^ overflow(); } // (N XOR V)
bool BGE() { return !BLT(); } // !(N XOR V)
bool BLE() { return (zero() >> 2) & ((negative() >> 3) ^ (overflow() >> 1)); } // (Z OR (N XOR V))
bool BGT() { return !BLE(); } // !(Z OR (N XOR V))
bool LS() { return carry() | (zero() >> 2); } // (C OR Z)
bool HI() { return !LS(); } // !(C OR Z)
bool LT() { return (negative() >> 1) ^ overflow(); } // (N XOR V)
bool GE() { return !LT(); } // !(N XOR V)
bool LE() { return (zero() >> 2) & ((negative() >> 3) ^ (overflow() >> 1)); } // (Z OR (N XOR V))
bool GT() { return !LE(); } // !(Z OR (N XOR V))
// Branching
@@ -275,12 +278,13 @@ namespace EightBit {
return !!condition;
}
bool branchShort(int condition) {
return branch(Address_relative_byte(), condition);
void branchShort(int condition) {
branch(Address_relative_byte(), condition);
}
bool branchLong(int condition) {
return branch(Address_relative_word(), condition);
void branchLong(int condition) {
if (branch(Address_relative_word(), condition))
addCycle();
}
// Miscellaneous

Binary file not shown.

View File

@@ -21,7 +21,7 @@
<ItemGroup>
<ClInclude Include="..\inc\Disassembly.h" />
<ClInclude Include="..\inc\mc6809.h" />
<ClInclude Include="..\inc\stdafx.h" />
<ClInclude Include="stdafx.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="Disassembly.cpp" />

View File

@@ -11,15 +11,15 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\inc\stdafx.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\inc\mc6809.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\inc\Disassembly.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="stdafx.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">

View File

@@ -24,9 +24,9 @@ int EightBit::mc6809::step() {
handleRESET();
else if (UNLIKELY(lowered(NMI())))
handleNMI();
else if (UNLIKELY(lowered(FIRQ()) && !(CC() & FF)))
else if (UNLIKELY(lowered(FIRQ()) && !fastInterruptMasked()))
handleFIRQ();
else if (UNLIKELY(lowered(IRQ()) && !(CC() & IF)))
else if (UNLIKELY(lowered(IRQ()) && !interruptMasked()))
handleIRQ();
else
execute(fetchByte());
@@ -454,8 +454,8 @@ void EightBit::mc6809::executeUnprefixed(const uint8_t opcode) {
case 0x17: addCycles(9); jsr(Address_relative_word()); break; // BSR (LBSR relative)
case 0x20: addCycles(3); jump(Address_relative_byte()); break; // BRA (relative)
case 0x21: addCycles(3); Address_relative_byte(); break; // BRN (relative)
case 0x22: addCycles(3); branchShort(BHI()); break; // BHI (relative)
case 0x23: addCycles(3); branchShort(BLS()); break; // BLS (relative)
case 0x22: addCycles(3); branchShort(HI()); break; // BHI (relative)
case 0x23: addCycles(3); branchShort(LS()); break; // BLS (relative)
case 0x24: addCycles(3); branchShort(!carry()); break; // BCC (relative)
case 0x25: addCycles(3); branchShort(carry()); break; // BCS (relative)
case 0x26: addCycles(3); branchShort(!zero()); break; // BNE (relative)
@@ -464,10 +464,10 @@ void EightBit::mc6809::executeUnprefixed(const uint8_t opcode) {
case 0x29: addCycles(3); branchShort(overflow()); break; // BVS (relative)
case 0x2a: addCycles(3); branchShort(!negative()); break; // BPL (relative)
case 0x2b: addCycles(3); branchShort(negative()); break; // BMI (relative)
case 0x2c: addCycles(3); branchShort(BGE()); break; // BGE (relative)
case 0x2d: addCycles(3); branchShort(BLT()); break; // BLT (relative)
case 0x2e: addCycles(3); branchShort(BGT()); break; // BGT (relative)
case 0x2f: addCycles(3); branchShort(BLE()); break; // BLE (relative)
case 0x2c: addCycles(3); branchShort(GE()); break; // BGE (relative)
case 0x2d: addCycles(3); branchShort(LT()); break; // BLT (relative)
case 0x2e: addCycles(3); branchShort(GT()); break; // BGT (relative)
case 0x2f: addCycles(3); branchShort(LE()); break; // BLE (relative)
case 0x8d: addCycles(7); jsr(Address_relative_byte()); break; // BSR (relative)
@@ -514,20 +514,20 @@ void EightBit::mc6809::execute10(const uint8_t opcode) {
// Branching
case 0x21: addCycles(5); Address_relative_word(); break; // BRN (LBRN relative)
case 0x22: addCycles(5); if (branchLong(BHI())) addCycle(); break; // BHI (LBHI relative)
case 0x23: addCycles(5); if (branchLong(BLS())) addCycle(); break; // BLS (LBLS relative)
case 0x24: addCycles(5); if (branchLong(!carry())) addCycle(); break; // BCC (LBCC relative)
case 0x25: addCycles(5); if (branchLong(carry())) addCycle(); break; // BCS (LBCS relative)
case 0x26: addCycles(5); if (branchLong(!zero())) addCycle(); break; // BNE (LBNE relative)
case 0x27: addCycles(5); if (branchLong(zero())) addCycle(); break; // BEQ (LBEQ relative)
case 0x28: addCycles(5); if (branchLong(!overflow())) addCycle(); break; // BVC (LBVC relative)
case 0x29: addCycles(5); if (branchLong(overflow())) addCycle(); break; // BVS (LBVS relative)
case 0x2a: addCycles(5); if (branchLong(!negative())) addCycle(); break; // BPL (LBPL relative)
case 0x2b: addCycles(5); if (branchLong(negative())) addCycle(); break; // BMI (LBMI relative)
case 0x2c: addCycles(5); if (branchLong(BGE())) addCycle(); break; // BGE (LBGE relative)
case 0x2d: addCycles(5); if (branchLong(BLT())) addCycle(); break; // BLT (LBLT relative)
case 0x2e: addCycles(5); if (branchLong(BGT())) addCycle(); break; // BGT (LBGT relative)
case 0x2f: addCycles(5); if (branchLong(BLE())) addCycle(); break; // BLE (LBLE relative)
case 0x22: addCycles(5); branchLong(HI()); break; // BHI (LBHI relative)
case 0x23: addCycles(5); branchLong(LS()); break; // BLS (LBLS relative)
case 0x24: addCycles(5); branchLong(!carry()); break; // BCC (LBCC relative)
case 0x25: addCycles(5); branchLong(carry()); break; // BCS (LBCS relative)
case 0x26: addCycles(5); branchLong(!zero()); break; // BNE (LBNE relative)
case 0x27: addCycles(5); branchLong(zero()); break; // BEQ (LBEQ relative)
case 0x28: addCycles(5); branchLong(!overflow()); break; // BVC (LBVC relative)
case 0x29: addCycles(5); branchLong(overflow()); break; // BVS (LBVS relative)
case 0x2a: addCycles(5); branchLong(!negative()); break; // BPL (LBPL relative)
case 0x2b: addCycles(5); branchLong(negative()); break; // BMI (LBMI relative)
case 0x2c: addCycles(5); branchLong(GE()); break; // BGE (LBGE relative)
case 0x2d: addCycles(5); branchLong(LT()); break; // BLT (LBLT relative)
case 0x2e: addCycles(5); branchLong(GT()); break; // BGT (LBGT relative)
case 0x2f: addCycles(5); branchLong(LE()); break; // BLE (LBLE relative)
// STS
case 0xdf: addCycles(6); Processor::setWord(Address_direct(), st(S())); break; // ST (STS direct)
@@ -1057,7 +1057,8 @@ void EightBit::mc6809::rts() {
void EightBit::mc6809::swi() {
saveEntireRegisterState();
setFlag(CC(), (IF | FF));
setFlag(CC(), IF); // Disable IRQ
setFlag(CC(), FF); // Disable FIRQ
jump(getWordPaged(0xff, SWIvector));
}