mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2025-01-22 12:30:44 +00:00
A few minor consistency tweaks to the i8080 and z80 processors.
Signed-off-by: Adrian.Conlon <adrian.conlon@gmail.com>
This commit is contained in:
parent
8f57fac3ee
commit
6af1857cb0
@ -79,8 +79,7 @@ namespace EightBit {
|
||||
}
|
||||
|
||||
void adjustReservedFlags() {
|
||||
F() &= ~(Bit5 | Bit3);
|
||||
F() |= Bit1;
|
||||
F() = (F() | Bit1) & ~(Bit5 | Bit3);
|
||||
}
|
||||
|
||||
static void adjustAuxiliaryCarryAdd(uint8_t& f, uint8_t before, uint8_t value, int calculation) {
|
||||
@ -150,9 +149,9 @@ namespace EightBit {
|
||||
|
||||
void dad(uint16_t value) {
|
||||
auto& f = F();
|
||||
uint32_t sum = HL().word + value;
|
||||
setFlag(f, CF, sum > 0xffff);
|
||||
HL().word = (uint16_t)sum;
|
||||
auto sum = HL().word + value;
|
||||
setFlag(f, CF, sum & Bit16);
|
||||
HL().word = sum;
|
||||
}
|
||||
|
||||
void sub(uint8_t& operand, uint8_t value, int carry = 0) {
|
||||
@ -527,13 +526,11 @@ namespace EightBit {
|
||||
}
|
||||
|
||||
void sbi() {
|
||||
auto value = fetchByte();
|
||||
sbb(value);
|
||||
sbb(fetchByte());
|
||||
}
|
||||
|
||||
void sui() {
|
||||
auto value = fetchByte();
|
||||
sub(value);
|
||||
sub(fetchByte());
|
||||
}
|
||||
|
||||
// logical
|
||||
@ -603,35 +600,31 @@ namespace EightBit {
|
||||
void rlc() {
|
||||
auto& a = A();
|
||||
auto carry = a & Bit7;
|
||||
a <<= 1;
|
||||
carry ? a |= Bit0 : a &= ~Bit0;
|
||||
a = (a << 1) | (carry >> 7);
|
||||
setFlag(F(), CF, carry);
|
||||
}
|
||||
|
||||
void rrc() {
|
||||
auto& a = A();
|
||||
auto carry = a & Bit0;
|
||||
a >>= 1;
|
||||
carry ? a |= Bit7 : a &= ~Bit7;
|
||||
a = (a >> 1) | (carry << 7);
|
||||
setFlag(F(), CF, carry);
|
||||
}
|
||||
|
||||
void ral() {
|
||||
auto& a = A();
|
||||
auto& f = F();
|
||||
auto carry = a & Bit7;
|
||||
a <<= 1;
|
||||
a |= (f & CF);
|
||||
setFlag(f, CF, carry);
|
||||
const auto carry = f & CF;
|
||||
setFlag(f, CF, a & Bit7);
|
||||
a = (a << 1) | carry;
|
||||
}
|
||||
|
||||
void rar() {
|
||||
auto& a = A();
|
||||
auto& f = F();
|
||||
auto carry = a & 1;
|
||||
a >>= 1;
|
||||
a |= (f & CF) << 7;
|
||||
setFlag(f, CF, carry);
|
||||
const auto carry = f & CF;
|
||||
setFlag(f, CF, a & Bit0);
|
||||
a = (a >> 1) | (carry << 7);
|
||||
}
|
||||
|
||||
// specials
|
||||
|
@ -221,6 +221,8 @@ namespace EightBit {
|
||||
}
|
||||
|
||||
register16_t& RP(int rp) {
|
||||
__assume(rp < 4);
|
||||
__assume(rp >= 0);
|
||||
switch (rp) {
|
||||
case 3:
|
||||
return SP();
|
||||
@ -241,6 +243,8 @@ namespace EightBit {
|
||||
}
|
||||
|
||||
register16_t& RP2(int rp) {
|
||||
__assume(rp < 4);
|
||||
__assume(rp >= 0);
|
||||
switch (rp) {
|
||||
case 3:
|
||||
return AF();
|
||||
|
@ -148,6 +148,8 @@ bool EightBit::Z80::jrConditionalFlag(uint8_t& f, int flag) {
|
||||
return jrConditional(!(f & SF));
|
||||
case 7: // M
|
||||
return jrConditional(f & SF);
|
||||
default:
|
||||
__assume(0);
|
||||
}
|
||||
throw std::logic_error("Unhandled JR conditional");
|
||||
}
|
||||
@ -170,6 +172,8 @@ bool EightBit::Z80::jumpConditionalFlag(uint8_t& f, int flag) {
|
||||
return jumpConditional(!(f & SF));
|
||||
case 7: // M
|
||||
return jumpConditional(f & SF);
|
||||
default:
|
||||
__assume(0);
|
||||
}
|
||||
throw std::logic_error("Unhandled JP conditional");
|
||||
}
|
||||
@ -201,6 +205,8 @@ bool EightBit::Z80::returnConditionalFlag(uint8_t& f, int flag) {
|
||||
return returnConditional(!(f & SF));
|
||||
case 7: // M
|
||||
return returnConditional(f & SF);
|
||||
default:
|
||||
__assume(0);
|
||||
}
|
||||
throw std::logic_error("Unhandled RET conditional");
|
||||
}
|
||||
@ -223,6 +229,8 @@ bool EightBit::Z80::callConditionalFlag(uint8_t& f, int flag) {
|
||||
return callConditional(!(f & SF));
|
||||
case 7: // M
|
||||
return callConditional(f & SF);
|
||||
default:
|
||||
__assume(0);
|
||||
}
|
||||
throw std::logic_error("Unhandled CALL conditional");
|
||||
}
|
||||
@ -435,7 +443,7 @@ uint8_t& EightBit::Z80::srl(uint8_t& f, uint8_t& operand) {
|
||||
uint8_t& EightBit::Z80::bit(uint8_t& f, int n, uint8_t& operand) {
|
||||
setFlag(f, HC);
|
||||
clearFlag(f, NF);
|
||||
const uint8_t discarded = operand & (1 << n);
|
||||
const auto discarded = operand & (1 << n);
|
||||
adjustSZXY<Z80>(f, discarded);
|
||||
clearFlag(f, PF, discarded);
|
||||
return operand;
|
||||
@ -543,8 +551,7 @@ void EightBit::Z80::blockCompare(uint8_t a, uint8_t& f) {
|
||||
adjustHalfCarrySub(f, a, value, result);
|
||||
setFlag(f, NF);
|
||||
|
||||
if (f & HC)
|
||||
result -= 1;
|
||||
result -= ((f & HC) >> 4);
|
||||
|
||||
setFlag(f, YF, result & Bit1);
|
||||
setFlag(f, XF, result & Bit3);
|
||||
@ -825,18 +832,18 @@ void EightBit::Z80::executeCB(int x, int y, int z) {
|
||||
adjustSZP<Z80>(f, m_displaced ? R2(z, a) = srl(f, DISPLACED()) : srl(f, R(z, a)));
|
||||
break;
|
||||
}
|
||||
cycles += 8;
|
||||
if (!m_displaced) {
|
||||
cycles += 8;
|
||||
if (z == 6)
|
||||
cycles += 7;
|
||||
} else {
|
||||
cycles += 23;
|
||||
cycles += 15;
|
||||
}
|
||||
break;
|
||||
case 1: // BIT y, r[z]
|
||||
cycles += 8;
|
||||
if (!m_displaced) {
|
||||
auto operand = bit(f, y, R(z, a));
|
||||
cycles += 8;
|
||||
if (z == 6) {
|
||||
adjustXY<Z80>(f, MEMPTR().high);
|
||||
cycles += 4;
|
||||
@ -846,29 +853,29 @@ void EightBit::Z80::executeCB(int x, int y, int z) {
|
||||
} else {
|
||||
bit(f, y, DISPLACED());
|
||||
adjustXY<Z80>(f, MEMPTR().high);
|
||||
cycles += 20;
|
||||
cycles += 12;
|
||||
}
|
||||
break;
|
||||
case 2: // RES y, r[z]
|
||||
cycles += 8;
|
||||
if (!m_displaced) {
|
||||
res(y, R(z, a));
|
||||
cycles += 8;
|
||||
if (z == 6)
|
||||
cycles += 7;
|
||||
} else {
|
||||
R2(z, a) = res(y, DISPLACED());
|
||||
cycles += 23;
|
||||
cycles += 15;
|
||||
}
|
||||
break;
|
||||
case 3: // SET y, r[z]
|
||||
cycles += 8;
|
||||
if (!m_displaced) {
|
||||
set(y, R(z, a));
|
||||
cycles += 8;
|
||||
if (z == 6)
|
||||
cycles += 7;
|
||||
} else {
|
||||
R2(z, a) = set(y, DISPLACED());
|
||||
cycles += 23;
|
||||
cycles += 15;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -19,24 +19,3 @@
|
||||
#include <bitset>
|
||||
|
||||
#include <boost/format.hpp>
|
||||
|
||||
//#include <SDL.h>
|
||||
//#include <SDL_mixer.h>
|
||||
//
|
||||
//#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
||||
//#define HOST_LITTLE_ENDIAN
|
||||
//#endif
|
||||
//
|
||||
//#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
||||
//#define HOST_BIG_ENDIAN
|
||||
//#endif
|
||||
//
|
||||
//#define RUN_TESTS
|
||||
////#define RUN_CPM
|
||||
////#define RUN_INVADERS
|
||||
//
|
||||
//#ifdef _MSC_VER
|
||||
//#pragma comment(lib, "SDL2.lib")
|
||||
//#pragma comment(lib, "SDL2main.lib")
|
||||
//#pragma comment(lib, "SDL2_mixer.lib")
|
||||
//#endif
|
||||
|
@ -54,7 +54,7 @@ namespace EightBit {
|
||||
}
|
||||
|
||||
template<class T> static void adjustParity(uint8_t& f, uint8_t value) {
|
||||
static const uint8_t lookup[0x10] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 };
|
||||
static const int lookup[0x10] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 };
|
||||
auto set = lookup[highNibble(value)] + lookup[lowNibble(value)];
|
||||
clearFlag(f, T::PF, set % 2);
|
||||
}
|
||||
@ -87,16 +87,19 @@ namespace EightBit {
|
||||
//
|
||||
|
||||
static int buildHalfCarryIndex(uint8_t before, uint8_t value, int calculation) {
|
||||
__assume(calculation < 0x1ffff);
|
||||
return ((before & 0x88) >> 1) | ((value & 0x88) >> 2) | ((calculation & 0x88) >> 3);
|
||||
}
|
||||
|
||||
static bool calculateHalfCarryAdd(uint8_t before, uint8_t value, int calculation) {
|
||||
__assume(calculation < 0x1ffff);
|
||||
static std::array<bool, 8> m_halfCarryTableAdd = { { false, false, true, false, true, false, true, true } };
|
||||
auto index = buildHalfCarryIndex(before, value, calculation);
|
||||
return m_halfCarryTableAdd[index & Mask3];
|
||||
}
|
||||
|
||||
static bool calculateHalfCarrySub(uint8_t before, uint8_t value, int calculation) {
|
||||
__assume(calculation < 0x1ffff);
|
||||
std::array<bool, 8> m_halfCarryTableSub = { { false, true, true, true, false, false, false, true } };
|
||||
auto index = buildHalfCarryIndex(before, value, calculation);
|
||||
return m_halfCarryTableSub[index & Mask3];
|
||||
|
Loading…
x
Reference in New Issue
Block a user