1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-10-03 10:54:46 +00:00

Merge pull request #766 from TomHarte/6502CleanUp

Standardises 6502 casts.
This commit is contained in:
Thomas Harte 2020-03-06 22:03:37 -05:00 committed by GitHub
commit 2ee24d29e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 38 deletions

View File

@ -127,24 +127,24 @@ class ConcreteMachine:
m6502_.set_reset_line(isPressed); m6502_.set_reset_line(isPressed);
break; break;
#define ShiftedKey(source, dest) \ #define FuncShiftedKey(source, dest) \
case source: \ case source: \
set_key_state(KeyShift, isPressed); \ set_key_state(KeyFunc, isPressed); \
set_key_state(dest, isPressed); \ set_key_state(dest, isPressed); \
break; break;
ShiftedKey(KeyF1, Key1); FuncShiftedKey(KeyF1, Key1);
ShiftedKey(KeyF2, Key2); FuncShiftedKey(KeyF2, Key2);
ShiftedKey(KeyF3, Key3); FuncShiftedKey(KeyF3, Key3);
ShiftedKey(KeyF4, Key4); FuncShiftedKey(KeyF4, Key4);
ShiftedKey(KeyF5, Key5); FuncShiftedKey(KeyF5, Key5);
ShiftedKey(KeyF6, Key6); FuncShiftedKey(KeyF6, Key6);
ShiftedKey(KeyF7, Key7); FuncShiftedKey(KeyF7, Key7);
ShiftedKey(KeyF8, Key8); FuncShiftedKey(KeyF8, Key8);
ShiftedKey(KeyF9, Key9); FuncShiftedKey(KeyF9, Key9);
ShiftedKey(KeyF0, Key0); FuncShiftedKey(KeyF0, Key0);
#undef ShiftedKey #undef FuncShiftedKey
} }
} }

View File

@ -258,17 +258,17 @@ template <Personality personality, typename T, bool uses_ready_line> void Proces
case OperationCMP: { case OperationCMP: {
const uint16_t temp16 = a_ - operand_; const uint16_t temp16 = a_ - operand_;
negative_result_ = zero_result_ = static_cast<uint8_t>(temp16); negative_result_ = zero_result_ = uint8_t(temp16);
carry_flag_ = ((~temp16) >> 8)&1; carry_flag_ = ((~temp16) >> 8)&1;
} continue; } continue;
case OperationCPX: { case OperationCPX: {
const uint16_t temp16 = x_ - operand_; const uint16_t temp16 = x_ - operand_;
negative_result_ = zero_result_ = static_cast<uint8_t>(temp16); negative_result_ = zero_result_ = uint8_t(temp16);
carry_flag_ = ((~temp16) >> 8)&1; carry_flag_ = ((~temp16) >> 8)&1;
} continue; } continue;
case OperationCPY: { case OperationCPY: {
const uint16_t temp16 = y_ - operand_; const uint16_t temp16 = y_ - operand_;
negative_result_ = zero_result_ = static_cast<uint8_t>(temp16); negative_result_ = zero_result_ = uint8_t(temp16);
carry_flag_ = ((~temp16) >> 8)&1; carry_flag_ = ((~temp16) >> 8)&1;
} continue; } continue;
@ -307,7 +307,7 @@ template <Personality personality, typename T, bool uses_ready_line> void Proces
case OperationSBC: case OperationSBC:
if(decimal_flag_ && has_decimal_mode(personality)) { if(decimal_flag_ && has_decimal_mode(personality)) {
const uint16_t notCarry = carry_flag_ ^ 0x1; const uint16_t notCarry = carry_flag_ ^ 0x1;
const uint16_t decimalResult = static_cast<uint16_t>(a_) - static_cast<uint16_t>(operand_) - notCarry; const uint16_t decimalResult = uint16_t(a_) - uint16_t(operand_) - notCarry;
uint16_t temp16; uint16_t temp16;
temp16 = (a_&0xf) - (operand_&0xf) - notCarry; temp16 = (a_&0xf) - (operand_&0xf) - notCarry;
@ -316,13 +316,13 @@ template <Personality personality, typename T, bool uses_ready_line> void Proces
temp16 += (a_&0xf0) - (operand_&0xf0); temp16 += (a_&0xf0) - (operand_&0xf0);
overflow_flag_ = ( ( (decimalResult^a_)&(~decimalResult^operand_) )&0x80) >> 1; overflow_flag_ = ( ( (decimalResult^a_)&(~decimalResult^operand_) )&0x80) >> 1;
negative_result_ = static_cast<uint8_t>(temp16); negative_result_ = uint8_t(temp16);
zero_result_ = static_cast<uint8_t>(decimalResult); zero_result_ = uint8_t(decimalResult);
if(temp16 > 0xff) temp16 -= 0x60; if(temp16 > 0xff) temp16 -= 0x60;
carry_flag_ = (temp16 > 0xff) ? 0 : Flag::Carry; carry_flag_ = (temp16 > 0xff) ? 0 : Flag::Carry;
a_ = static_cast<uint8_t>(temp16); a_ = uint8_t(temp16);
if(is_65c02(personality)) { if(is_65c02(personality)) {
negative_result_ = zero_result_ = a_; negative_result_ = zero_result_ = a_;
@ -337,18 +337,18 @@ template <Personality personality, typename T, bool uses_ready_line> void Proces
// deliberate fallthrough // deliberate fallthrough
case OperationADC: case OperationADC:
if(decimal_flag_ && has_decimal_mode(personality)) { if(decimal_flag_ && has_decimal_mode(personality)) {
const uint16_t decimalResult = static_cast<uint16_t>(a_) + static_cast<uint16_t>(operand_) + static_cast<uint16_t>(carry_flag_); const uint16_t decimalResult = uint16_t(a_) + uint16_t(operand_) + uint16_t(carry_flag_);
uint8_t low_nibble = (a_ & 0xf) + (operand_ & 0xf) + carry_flag_; uint8_t low_nibble = (a_ & 0xf) + (operand_ & 0xf) + carry_flag_;
if(low_nibble >= 0xa) low_nibble = ((low_nibble + 0x6) & 0xf) + 0x10; if(low_nibble >= 0xa) low_nibble = ((low_nibble + 0x6) & 0xf) + 0x10;
uint16_t result = static_cast<uint16_t>(a_ & 0xf0) + static_cast<uint16_t>(operand_ & 0xf0) + static_cast<uint16_t>(low_nibble); uint16_t result = uint16_t(a_ & 0xf0) + uint16_t(operand_ & 0xf0) + uint16_t(low_nibble);
negative_result_ = static_cast<uint8_t>(result); negative_result_ = uint8_t(result);
overflow_flag_ = (( (result^a_)&(result^operand_) )&0x80) >> 1; overflow_flag_ = (( (result^a_)&(result^operand_) )&0x80) >> 1;
if(result >= 0xa0) result += 0x60; if(result >= 0xa0) result += 0x60;
carry_flag_ = (result >> 8) ? 1 : 0; carry_flag_ = (result >> 8) ? 1 : 0;
a_ = static_cast<uint8_t>(result); a_ = uint8_t(result);
zero_result_ = static_cast<uint8_t>(decimalResult); zero_result_ = uint8_t(decimalResult);
if(is_65c02(personality)) { if(is_65c02(personality)) {
negative_result_ = zero_result_ = a_; negative_result_ = zero_result_ = a_;
@ -356,9 +356,9 @@ template <Personality personality, typename T, bool uses_ready_line> void Proces
break; break;
} }
} else { } else {
const uint16_t result = static_cast<uint16_t>(a_) + static_cast<uint16_t>(operand_) + static_cast<uint16_t>(carry_flag_); const uint16_t result = uint16_t(a_) + uint16_t(operand_) + uint16_t(carry_flag_);
overflow_flag_ = (( (result^a_)&(result^operand_) )&0x80) >> 1; overflow_flag_ = (( (result^a_)&(result^operand_) )&0x80) >> 1;
negative_result_ = zero_result_ = a_ = static_cast<uint8_t>(result); negative_result_ = zero_result_ = a_ = uint8_t(result);
carry_flag_ = (result >> 8)&1; carry_flag_ = (result >> 8)&1;
} }
@ -382,13 +382,13 @@ template <Personality personality, typename T, bool uses_ready_line> void Proces
continue; continue;
case OperationROL: { case OperationROL: {
const uint8_t temp8 = static_cast<uint8_t>((operand_ << 1) | carry_flag_); const uint8_t temp8 = uint8_t((operand_ << 1) | carry_flag_);
carry_flag_ = operand_ >> 7; carry_flag_ = operand_ >> 7;
operand_ = negative_result_ = zero_result_ = temp8; operand_ = negative_result_ = zero_result_ = temp8;
} continue; } continue;
case OperationRLA: { case OperationRLA: {
const uint8_t temp8 = static_cast<uint8_t>((operand_ << 1) | carry_flag_); const uint8_t temp8 = uint8_t((operand_ << 1) | carry_flag_);
carry_flag_ = operand_ >> 7; carry_flag_ = operand_ >> 7;
operand_ = temp8; operand_ = temp8;
a_ &= operand_; a_ &= operand_;
@ -416,13 +416,13 @@ template <Personality personality, typename T, bool uses_ready_line> void Proces
continue; continue;
case OperationROR: { case OperationROR: {
const uint8_t temp8 = static_cast<uint8_t>((operand_ >> 1) | (carry_flag_ << 7)); const uint8_t temp8 = uint8_t((operand_ >> 1) | (carry_flag_ << 7));
carry_flag_ = operand_ & 1; carry_flag_ = operand_ & 1;
operand_ = negative_result_ = zero_result_ = temp8; operand_ = negative_result_ = zero_result_ = temp8;
} continue; } continue;
case OperationRRA: { case OperationRRA: {
const uint8_t temp8 = static_cast<uint8_t>((operand_ >> 1) | (carry_flag_ << 7)); const uint8_t temp8 = uint8_t((operand_ >> 1) | (carry_flag_ << 7));
carry_flag_ = operand_ & 1; carry_flag_ = operand_ & 1;
operand_ = temp8; operand_ = temp8;
} continue; } continue;
@ -582,7 +582,7 @@ template <Personality personality, typename T, bool uses_ready_line> void Proces
#undef BRA #undef BRA
case CycleAddSignedOperandToPC: case CycleAddSignedOperandToPC:
nextAddress.full = static_cast<uint16_t>(pc_.full + (int8_t)operand_); nextAddress.full = uint16_t(pc_.full + int8_t(operand_));
pc_.halves.low = nextAddress.halves.low; pc_.halves.low = nextAddress.halves.low;
if(nextAddress.halves.high != pc_.halves.high) { if(nextAddress.halves.high != pc_.halves.high) {
uint16_t halfUpdatedPc = pc_.full; uint16_t halfUpdatedPc = pc_.full;
@ -598,18 +598,18 @@ template <Personality personality, typename T, bool uses_ready_line> void Proces
continue; continue;
case CycleFetchFromHalfUpdatedPC: { case CycleFetchFromHalfUpdatedPC: {
uint16_t halfUpdatedPc = static_cast<uint16_t>(((pc_.halves.low + (int8_t)operand_) & 0xff) | (pc_.halves.high << 8)); uint16_t halfUpdatedPc = uint16_t(((pc_.halves.low + int8_t(operand_)) & 0xff) | (pc_.halves.high << 8));
throwaway_read(halfUpdatedPc); throwaway_read(halfUpdatedPc);
} break; } break;
case OperationAddSignedOperandToPC16: case OperationAddSignedOperandToPC16:
pc_.full = static_cast<uint16_t>(pc_.full + (int8_t)operand_); pc_.full = uint16_t(pc_.full + int8_t(operand_));
continue; continue;
case OperationBBRBBS: { case OperationBBRBBS: {
// To reach here, the 6502 has (i) read the operation; (ii) read the first operand; // To reach here, the 6502 has (i) read the operation; (ii) read the first operand;
// and (iii) read from the corresponding zero page. // and (iii) read from the corresponding zero page.
const uint8_t mask = static_cast<uint8_t>(1 << ((operation_ >> 4)&7)); const uint8_t mask = uint8_t(1 << ((operation_ >> 4)&7));
if((operand_ & mask) == ((operation_ & 0x80) ? mask : 0)) { if((operand_ & mask) == ((operation_ & 0x80) ? mask : 0)) {
static const MicroOp do_branch[] = { static const MicroOp do_branch[] = {
CycleFetchOperand, // Fetch offset. CycleFetchOperand, // Fetch offset.
@ -643,7 +643,7 @@ template <Personality personality, typename T, bool uses_ready_line> void Proces
if(decimal_flag_) { if(decimal_flag_) {
a_ &= operand_; a_ &= operand_;
uint8_t unshiftedA = a_; uint8_t unshiftedA = a_;
a_ = static_cast<uint8_t>((a_ >> 1) | (carry_flag_ << 7)); a_ = uint8_t((a_ >> 1) | (carry_flag_ << 7));
zero_result_ = negative_result_ = a_; zero_result_ = negative_result_ = a_;
overflow_flag_ = (a_^(a_ << 1))&Flag::Overflow; overflow_flag_ = (a_^(a_ << 1))&Flag::Overflow;
@ -653,7 +653,7 @@ template <Personality personality, typename T, bool uses_ready_line> void Proces
if(carry_flag_) a_ += 0x60; if(carry_flag_) a_ += 0x60;
} else { } else {
a_ &= operand_; a_ &= operand_;
a_ = static_cast<uint8_t>((a_ >> 1) | (carry_flag_ << 7)); a_ = uint8_t((a_ >> 1) | (carry_flag_ << 7));
negative_result_ = zero_result_ = a_; negative_result_ = zero_result_ = a_;
carry_flag_ = (a_ >> 6)&1; carry_flag_ = (a_ >> 6)&1;
overflow_flag_ = (a_^(a_ << 1))&Flag::Overflow; overflow_flag_ = (a_^(a_ << 1))&Flag::Overflow;
@ -663,7 +663,7 @@ template <Personality personality, typename T, bool uses_ready_line> void Proces
case OperationSBX: case OperationSBX:
x_ &= a_; x_ &= a_;
uint16_t difference = x_ - operand_; uint16_t difference = x_ - operand_;
x_ = static_cast<uint8_t>(difference); x_ = uint8_t(difference);
negative_result_ = zero_result_ = x_; negative_result_ = zero_result_ = x_;
carry_flag_ = ((difference >> 8)&1)^1; carry_flag_ = ((difference >> 8)&1)^1;
continue; continue;