Commit 37b610da authored by Tim Allen's avatar Tim Allen

Update to v106r83 release.

byuu says:

Changelog:

  - reverted nall/inline-if.hpp usage for now, since the
    nall/primitives.hpp math operators still cast to (u)int64_t
  - improved nall/primitives.hpp more; integer8 x = -128; print(-x) will
    now print 128 (unary operator+ and - cast to (u)int64_t)
  - renamed processor/lr35902 to processor/sm83; after the Sharp SM83
    CPU core [gekkio discovered the name]
  - a few bugfixes to the TLCS900H CPU core
  - completed the disassembler for the TLCS900H core

As a result of reverting most of the inline if stuff, I guess the
testing priority has been reduced. Which is probably a good thing,
considering I seem to have a smaller pool of testers these days.

Indeed, the TLCS900H core has ended up at 131KiB compared to the M68000
core at 128KiB. So it's now the largest CPU core in all of higan. It's
even more ridiculous because the M68000 core would ordinarily be quite a
bit smaller, had I not gone overboard with the extreme templating to
reduce instruction decoding overhead (you kind of have to do this for
RISC CPUs, and the inverted design of the TLCS900H kind of makes it
infeasible to do the same there.)

This CPU core is bound to have dozens of extremely difficult CPU bugs,
and there's no easy way for me to test them. I would greatly appreciate
any help in looking over the core for bugs. A fresh pair of eyes to spot
a mistake could save me up to several days of tedious debugging work.

The core still isn't ready to actually be tested: I have to hook up
cartridge loading, a memory bus, interrupts, timers, and the micro DMA
controller before it's likely that anything happens at all.
parent 2d9ce59e
Pipeline #43957567 passed with stage
in 13 minutes and 30 seconds
......@@ -30,7 +30,7 @@ using namespace nall;
namespace Emulator {
static const string Name = "higan";
static const string Version = "106.82";
static const string Version = "106.83";
static const string Author = "byuu";
static const string License = "GPLv3";
static const string Website = "https://byuu.org/";
......
processors += lr35902
processors += sm83
objects += gb-interface gb-system
objects += gb-memory gb-cartridge
......
......@@ -86,7 +86,7 @@ auto CPU::stop() -> bool {
auto CPU::power() -> void {
create(Enter, 4 * 1024 * 1024);
LR35902::power();
SM83::power();
for(uint n = 0xc000; n <= 0xdfff; n++) bus.mmio[n] = this; //WRAM
for(uint n = 0xe000; n <= 0xfdff; n++) bus.mmio[n] = this; //WRAM (mirror)
......
struct CPU : Processor::LR35902, Thread, MMIO {
struct CPU : Processor::SM83, Thread, MMIO {
enum class Interrupt : uint { Vblank, Stat, Timer, Serial, Joypad };
static auto Enter() -> void;
......
auto CPU::serialize(serializer& s) -> void {
LR35902::serialize(s);
SM83::serialize(s);
Thread::serialize(s);
s.array(wram);
......
......@@ -8,7 +8,7 @@
#include <emulator/scheduler.hpp>
#include <emulator/cheat.hpp>
#include <processor/lr35902/lr35902.hpp>
#include <processor/sm83/sm83.hpp>
namespace GameBoy {
#define platform Emulator::platform
......
......@@ -104,7 +104,7 @@ auto PPU::Background::affine(uint x, uint y) -> void {
}
uint screenSize = 16 << io.screenSize;
uint screenWrap = (1 << if(io.affineWrap, 7 + io.screenSize, 20)) - 1;
uint screenWrap = (1 << (io.affineWrap ? 7 + io.screenSize : 20)) - 1;
uint cx = (fx >> 8) & screenWrap;
uint cy = (fy >> 8) & screenWrap;
......@@ -148,7 +148,7 @@ auto PPU::Background::bitmap(uint x, uint y) -> void {
uint height = io.mode == 5 ? 128 : 160;
uint mode = depth ? Half : Byte;
uint baseAddress = if(io.mode == 3, 0, 0xa000 * io.frame);
uint baseAddress = io.mode == 3 ? 0 : 0xa000 * io.frame;
uint px = fx >> 8;
uint py = fy >> 8;
......
......@@ -8,7 +8,7 @@ auto PPU::Objects::scanline(uint y) -> void {
if(object.affine == 0 && object.affineSize == 1) continue; //hidden
if(py >= object.height << object.affineSize) continue; //offscreen
uint rowSize = if(io.mapping == 0, 32 >> object.colors, object.width >> 3);
uint rowSize = io.mapping == 0 ? 32 >> object.colors : object.width >> 3;
uint baseAddress = object.character << 5;
if(object.mosaic && io.mosaicHeight) {
......
#include <gba/gba.hpp>
#include <nall/inline-if.hpp>
//pixel: 4 cycles
......
......@@ -70,7 +70,7 @@ auto VDP::Background::run(uint x, uint y) -> void {
uint16 tileData = vdp.vram.read(tileAddress);
uint4 color = tileData >> (((pixelX & 3) ^ 3) << 2);
output.color = if(color, tileAttributes.bits(13,14) << 4 | color, 0);
output.color = color ? tileAttributes.bits(13,14) << 4 | color : 0;
output.priority = tileAttributes.bit(15);
}
......
#include <md/md.hpp>
#include <nall/inline-if.hpp>
namespace MegaDrive {
......
......@@ -27,7 +27,7 @@ auto YM2612::Channel::Operator::trigger(bool state) -> void {
}
auto YM2612::Channel::Operator::runEnvelope() -> void {
uint sustain = if(envelope.sustainLevel < 15, envelope.sustainLevel << 5, 0x3f0);
uint sustain = envelope.sustainLevel < 15 ? envelope.sustainLevel << 5 : 0x3f0;
if(ym2612.envelope.clock & (1 << envelope.divider) - 1) return;
uint value = ym2612.envelope.clock >> envelope.divider;
......@@ -121,7 +121,7 @@ auto YM2612::Channel::Operator::updatePhase() -> void {
phase.delta = pitch.value + (pm >> 10 - msb) << 6 >> 7 - octave.value;
phase.delta = (!detune.bit(2) ? phase.delta + tuning : phase.delta - tuning) & 0x1ffff;
phase.delta = if(multiple, phase.delta * multiple, phase.delta >> 1) & 0xfffff;
phase.delta = (multiple ? phase.delta * multiple : phase.delta >> 1) & 0xfffff;
}
auto YM2612::Channel::Operator::updateLevel() -> void {
......
#include <md/md.hpp>
#include <nall/inline-if.hpp>
namespace MegaDrive {
......@@ -65,7 +64,7 @@ auto YM2612::sample() -> void {
auto wave = [&](uint n, uint modulation) -> int {
int x = (modulation >> 1) + (op[n].phase.value >> 10);
int y = sine[x & 0x3ff] + op[n].outputLevel;
return if(y < 0x2000, pow2[y & 0x1ff] << 2 >> (y >> 9), 0);
return y < 0x2000 ? pow2[y & 0x1ff] << 2 >> (y >> 9) : 0;
};
int feedback = modMask & op[0].output + op[0].prior >> 9 - channel.feedback;
......
......@@ -4,9 +4,9 @@ objects += $(if $(findstring arm7tdmi,$(processors)),processor-arm7tdmi)
objects += $(if $(findstring gsu,$(processors)),processor-gsu)
objects += $(if $(findstring hg51b,$(processors)),processor-hg51b)
objects += $(if $(findstring huc6280,$(processors)),processor-huc6280)
objects += $(if $(findstring lr35902,$(processors)),processor-lr35902)
objects += $(if $(findstring m68k,$(processors)),processor-m68k)
objects += $(if $(findstring mos6502,$(processors)),processor-mos6502)
objects += $(if $(findstring sm83,$(processors)),processor-sm83)
objects += $(if $(findstring spc700,$(processors)),processor-spc700)
objects += $(if $(findstring tlcs900h,$(processors)),processor-tlcs900h)
objects += $(if $(findstring upd96050,$(processors)),processor-upd96050)
......@@ -18,9 +18,9 @@ obj/processor-arm7tdmi.o: processor/arm7tdmi/arm7tdmi.cpp
obj/processor-gsu.o: processor/gsu/gsu.cpp
obj/processor-hg51b.o: processor/hg51b/hg51b.cpp
obj/processor-huc6280.o: processor/huc6280/huc6280.cpp
obj/processor-lr35902.o: processor/lr35902/lr35902.cpp
obj/processor-m68k.o: processor/m68k/m68k.cpp
obj/processor-mos6502.o: processor/mos6502/mos6502.cpp
obj/processor-sm83.o: processor/sm83/sm83.cpp
obj/processor-spc700.o: processor/spc700/spc700.cpp
obj/processor-tlcs900h.o: processor/tlcs900h/tlcs900h.cpp
obj/processor-upd96050.o: processor/upd96050/upd96050.cpp
......
......@@ -13,8 +13,8 @@ auto ARM7TDMI::ADD(uint32 source, uint32 modify, bool carry) -> uint32 {
auto ARM7TDMI::ASR(uint32 source, uint8 shift) -> uint32 {
carry = cpsr().c;
if(shift == 0) return source;
carry = if(shift > 32, source & 1 << 31, source & 1 << shift - 1);
source = if(shift > 31, (int32)source >> 31, (int32)source >> shift);
carry = shift > 32 ? source & 1 << 31 : source & 1 << shift - 1;
source = shift > 31 ? (int32)source >> 31 : (int32)source >> shift;
return source;
}
......@@ -30,16 +30,16 @@ auto ARM7TDMI::BIT(uint32 result) -> uint32 {
auto ARM7TDMI::LSL(uint32 source, uint8 shift) -> uint32 {
carry = cpsr().c;
if(shift == 0) return source;
carry = if(shift > 32, 0, source & 1 << 32 - shift);
source = if(shift > 31, 0, source << shift);
carry = shift > 32 ? 0 : source & 1 << 32 - shift;
source = shift > 31 ? 0 : source << shift;
return source;
}
auto ARM7TDMI::LSR(uint32 source, uint8 shift) -> uint32 {
carry = cpsr().c;
if(shift == 0) return source;
carry = if(shift > 32, 0, source & 1 << shift - 1);
source = if(shift > 31, 0, source >> shift);
carry = shift > 32 ? 0 : source & 1 << shift - 1;
source = shift > 31 ? 0 : source >> shift;
return source;
}
......
#include <processor/processor.hpp>
#include <nall/inline-if.hpp>
#include "arm7tdmi.hpp"
namespace Processor {
......
auto LR35902::ADD(uint8 target, uint8 source, bool carry) -> uint8 {
auto SM83::ADD(uint8 target, uint8 source, bool carry) -> uint8 {
uint16 x = target + source + carry;
uint16 y = (uint4)target + (uint4)source + carry;
CF = x > 0xff;
......@@ -8,7 +8,7 @@ auto LR35902::ADD(uint8 target, uint8 source, bool carry) -> uint8 {
return x;
}
auto LR35902::AND(uint8 target, uint8 source) -> uint8 {
auto SM83::AND(uint8 target, uint8 source) -> uint8 {
target &= source;
CF = 0;
HF = 1;
......@@ -17,13 +17,13 @@ auto LR35902::AND(uint8 target, uint8 source) -> uint8 {
return target;
}
auto LR35902::BIT(uint3 index, uint8 target) -> void {
auto SM83::BIT(uint3 index, uint8 target) -> void {
HF = 1;
NF = 0;
ZF = target.bit(index) == 0;
}
auto LR35902::CP(uint8 target, uint8 source) -> void {
auto SM83::CP(uint8 target, uint8 source) -> void {
uint16 x = target - source;
uint16 y = (uint4)target - (uint4)source;
CF = x > 0xff;
......@@ -32,7 +32,7 @@ auto LR35902::CP(uint8 target, uint8 source) -> void {
ZF = (uint8)x == 0;
}
auto LR35902::DEC(uint8 target) -> uint8 {
auto SM83::DEC(uint8 target) -> uint8 {
target--;
HF = (uint4)target == 0x0f;
NF = 1;
......@@ -40,7 +40,7 @@ auto LR35902::DEC(uint8 target) -> uint8 {
return target;
}
auto LR35902::INC(uint8 target) -> uint8 {
auto SM83::INC(uint8 target) -> uint8 {
target++;
HF = (uint4)target == 0x00;
NF = 0;
......@@ -48,14 +48,14 @@ auto LR35902::INC(uint8 target) -> uint8 {
return target;
}
auto LR35902::OR(uint8 target, uint8 source) -> uint8 {
auto SM83::OR(uint8 target, uint8 source) -> uint8 {
target |= source;
CF = HF = NF = 0;
ZF = target == 0;
return target;
}
auto LR35902::RL(uint8 target) -> uint8 {
auto SM83::RL(uint8 target) -> uint8 {
bool carry = target.bit(7);
target = target << 1 | CF;
CF = carry;
......@@ -64,7 +64,7 @@ auto LR35902::RL(uint8 target) -> uint8 {
return target;
}
auto LR35902::RLC(uint8 target) -> uint8 {
auto SM83::RLC(uint8 target) -> uint8 {
target = target << 1 | target >> 7;
CF = target.bit(0);
HF = NF = 0;
......@@ -72,7 +72,7 @@ auto LR35902::RLC(uint8 target) -> uint8 {
return target;
}
auto LR35902::RR(uint8 target) -> uint8 {
auto SM83::RR(uint8 target) -> uint8 {
bool carry = target.bit(0);
target = CF << 7 | target >> 1;
CF = carry;
......@@ -81,7 +81,7 @@ auto LR35902::RR(uint8 target) -> uint8 {
return target;
}
auto LR35902::RRC(uint8 target) -> uint8 {
auto SM83::RRC(uint8 target) -> uint8 {
target = target << 7 | target >> 1;
CF = target.bit(7);
HF = NF = 0;
......@@ -89,7 +89,7 @@ auto LR35902::RRC(uint8 target) -> uint8 {
return target;
}
auto LR35902::SLA(uint8 target) -> uint8 {
auto SM83::SLA(uint8 target) -> uint8 {
bool carry = target.bit(7);
target <<= 1;
CF = carry;
......@@ -98,7 +98,7 @@ auto LR35902::SLA(uint8 target) -> uint8 {
return target;
}
auto LR35902::SRA(uint8 target) -> uint8 {
auto SM83::SRA(uint8 target) -> uint8 {
bool carry = target.bit(0);
target = (int8)target >> 1;
CF = carry;
......@@ -107,7 +107,7 @@ auto LR35902::SRA(uint8 target) -> uint8 {
return target;
}
auto LR35902::SRL(uint8 target) -> uint8 {
auto SM83::SRL(uint8 target) -> uint8 {
bool carry = target.bit(0);
target >>= 1;
CF = carry;
......@@ -116,7 +116,7 @@ auto LR35902::SRL(uint8 target) -> uint8 {
return target;
}
auto LR35902::SUB(uint8 target, uint8 source, bool carry) -> uint8 {
auto SM83::SUB(uint8 target, uint8 source, bool carry) -> uint8 {
uint16 x = target - source - carry;
uint16 y = (uint4)target - (uint4)source - carry;
CF = x > 0xff;
......@@ -126,14 +126,14 @@ auto LR35902::SUB(uint8 target, uint8 source, bool carry) -> uint8 {
return x;
}
auto LR35902::SWAP(uint8 target) -> uint8 {
auto SM83::SWAP(uint8 target) -> uint8 {
target = target << 4 | target >> 4;
CF = HF = NF = 0;
ZF = target == 0;
return target;
}
auto LR35902::XOR(uint8 target, uint8 source) -> uint8 {
auto SM83::XOR(uint8 target, uint8 source) -> uint8 {
target ^= source;
CF = HF = NF = 0;
ZF = target == 0;
......
auto LR35902::disassemble(uint16 pc) -> string {
auto SM83::disassemble(uint16 pc) -> string {
return {
hex(pc, 4L), " ",
pad(disassembleOpcode(pc), -16, ' '), " ",
......@@ -10,7 +10,7 @@ auto LR35902::disassemble(uint16 pc) -> string {
};
}
auto LR35902::disassembleOpcode(uint16 pc) -> string {
auto SM83::disassembleOpcode(uint16 pc) -> string {
auto opcode = readDebugger(pc);
auto lo = readDebugger(pc + 1);
auto hi = readDebugger(pc + 2);
......@@ -267,7 +267,7 @@ auto LR35902::disassembleOpcode(uint16 pc) -> string {
return {"xx"};
}
auto LR35902::disassembleOpcodeCB(uint16 pc) -> string {
auto SM83::disassembleOpcodeCB(uint16 pc) -> string {
auto opcode = readDebugger(pc);
switch(opcode) {
......
auto LR35902::interrupt(uint16 vector) -> void {
auto SM83::interrupt(uint16 vector) -> void {
idle();
idle();
idle();
......@@ -9,7 +9,7 @@ auto LR35902::interrupt(uint16 vector) -> void {
#define op(id, name, ...) case id: return instruction##name(__VA_ARGS__);
auto LR35902::instruction() -> void {
auto SM83::instruction() -> void {
auto opcode = operand();
switch(opcode) {
......@@ -261,7 +261,7 @@ auto LR35902::instruction() -> void {
}
}
auto LR35902::instructionCB() -> void {
auto SM83::instructionCB() -> void {
auto opcode = operand();
switch(opcode) {
......
auto LR35902::instructionADC_Direct_Data(uint8& target) -> void {
auto SM83::instructionADC_Direct_Data(uint8& target) -> void {
target = ADD(target, operand(), CF);
}
auto LR35902::instructionADC_Direct_Direct(uint8& target, uint8& source) -> void {
auto SM83::instructionADC_Direct_Direct(uint8& target, uint8& source) -> void {
target = ADD(target, source, CF);
}
auto LR35902::instructionADC_Direct_Indirect(uint8& target, uint16& source) -> void {
auto SM83::instructionADC_Direct_Indirect(uint8& target, uint16& source) -> void {
target = ADD(target, read(source), CF);
}
auto LR35902::instructionADD_Direct_Data(uint8& target) -> void {
auto SM83::instructionADD_Direct_Data(uint8& target) -> void {
target = ADD(target, operand());
}
auto LR35902::instructionADD_Direct_Direct(uint8& target, uint8& source) -> void {
auto SM83::instructionADD_Direct_Direct(uint8& target, uint8& source) -> void {
target = ADD(target, source);
}
auto LR35902::instructionADD_Direct_Direct(uint16& target, uint16& source) -> void {
auto SM83::instructionADD_Direct_Direct(uint16& target, uint16& source) -> void {
idle();
uint32 x = target + source;
uint32 y = (uint12)target + (uint12)source;
......@@ -28,11 +28,11 @@ auto LR35902::instructionADD_Direct_Direct(uint16& target, uint16& source) -> vo
NF = 0;
}
auto LR35902::instructionADD_Direct_Indirect(uint8& target, uint16& source) -> void {
auto SM83::instructionADD_Direct_Indirect(uint8& target, uint16& source) -> void {
target = ADD(target, read(source));
}
auto LR35902::instructionADD_Direct_Relative(uint16& target) -> void {
auto SM83::instructionADD_Direct_Relative(uint16& target) -> void {
auto data = operand();
idle();
idle();
......@@ -42,28 +42,28 @@ auto LR35902::instructionADD_Direct_Relative(uint16& target) -> void {
target += (int8)data;
}
auto LR35902::instructionAND_Direct_Data(uint8& target) -> void {
auto SM83::instructionAND_Direct_Data(uint8& target) -> void {
target = AND(target, operand());
}
auto LR35902::instructionAND_Direct_Direct(uint8& target, uint8& source) -> void {
auto SM83::instructionAND_Direct_Direct(uint8& target, uint8& source) -> void {
target = AND(target, source);
}
auto LR35902::instructionAND_Direct_Indirect(uint8& target, uint16& source) -> void {
auto SM83::instructionAND_Direct_Indirect(uint8& target, uint16& source) -> void {
target = AND(target, read(source));
}
auto LR35902::instructionBIT_Index_Direct(uint3 index, uint8& data) -> void {
auto SM83::instructionBIT_Index_Direct(uint3 index, uint8& data) -> void {
BIT(index, data);
}
auto LR35902::instructionBIT_Index_Indirect(uint3 index, uint16& address) -> void {
auto SM83::instructionBIT_Index_Indirect(uint3 index, uint16& address) -> void {
auto data = read(address);
BIT(index, data);
}
auto LR35902::instructionCALL_Condition_Address(bool take) -> void {
auto SM83::instructionCALL_Condition_Address(bool take) -> void {
auto address = operands();
if(!take) return;
idle();
......@@ -71,29 +71,29 @@ auto LR35902::instructionCALL_Condition_Address(bool take) -> void {
PC = address;
}
auto LR35902::instructionCCF() -> void {
auto SM83::instructionCCF() -> void {
CF = !CF;
HF = NF = 0;
}
auto LR35902::instructionCP_Direct_Data(uint8& target) -> void {
auto SM83::instructionCP_Direct_Data(uint8& target) -> void {
CP(target, operand());
}
auto LR35902::instructionCP_Direct_Direct(uint8& target, uint8& source) -> void {
auto SM83::instructionCP_Direct_Direct(uint8& target, uint8& source) -> void {
CP(target, source);
}
auto LR35902::instructionCP_Direct_Indirect(uint8& target, uint16& source) -> void {
auto SM83::instructionCP_Direct_Indirect(uint8& target, uint16& source) -> void {
CP(target, read(source));
}
auto LR35902::instructionCPL() -> void {
auto SM83::instructionCPL() -> void {
A = ~A;
HF = NF = 1;
}
auto LR35902::instructionDAA() -> void {
auto SM83::instructionDAA() -> void {
uint16 a = A;
if(!NF) {
if(HF || (uint4)a > 0x09) a += 0x06;
......@@ -111,95 +111,95 @@ auto LR35902::instructionDAA() -> void {
ZF = A == 0;
}
auto LR35902::instructionDEC_Direct(uint8& data) -> void {
auto SM83::instructionDEC_Direct(uint8& data) -> void {
data = DEC(data);
}
auto LR35902::instructionDEC_Direct(uint16& data) -> void {
auto SM83::instructionDEC_Direct(uint16& data) -> void {
idle();
data--;
}
auto LR35902::instructionDEC_Indirect(uint16& address) -> void {
auto SM83::instructionDEC_Indirect(uint16& address) -> void {
auto data = read(address);
write(address, DEC(data));
}
auto LR35902::instructionDI() -> void {
auto SM83::instructionDI() -> void {
r.ime = 0;
}
auto LR35902::instructionEI() -> void {
auto SM83::instructionEI() -> void {
r.ei = 1;
}
auto LR35902::instructionHALT() -> void {
auto SM83::instructionHALT() -> void {
r.halt = 1;
while(r.halt) idle();
}
auto LR35902::instructionINC_Direct(uint8& data) -> void {
auto SM83::instructionINC_Direct(uint8& data) -> void {
data = INC(data);
}
auto LR35902::instructionINC_Direct(uint16& data) -> void {
auto SM83::instructionINC_Direct(uint16& data) -> void {
idle();
data++;
}
auto LR35902::instructionINC_Indirect(uint16& address) -> void {
auto SM83::instructionINC_Indirect(uint16& address) -> void {
auto data = read(address);
write(address, INC(data));
}
auto LR35902::instructionJP_Condition_Address(bool take) -> void {
auto SM83::instructionJP_Condition_Address(bool take) -> void {
auto address = operands();
if(!take) return;
idle();
PC = address;
}
auto LR35902::instructionJP_Direct(uint16& data) -> void {
auto SM83::instructionJP_Direct(uint16& data) -> void {
PC = data;
}
auto LR35902::instructionJR_Condition_Relative(bool take) -> void {
auto SM83::instructionJR_Condition_Relative(bool take) -> void {
auto data = operand();
if(!take) return;
idle();
PC += (int8)data;