diff --git a/nall/snes/cartridge.hpp b/nall/snes/cartridge.hpp
index 48d3272..dc08f36 100644
--- a/nall/snes/cartridge.hpp
+++ b/nall/snes/cartridge.hpp
@@ -158,6 +158,17 @@ SNESCartridge::SNESCartridge(const uint8_t *data, unsigned size) {
xml << " \n";
xml << " \n";
xml << " \n";
+ } else if(has_cx4) {
+ xml << " \n";
+ xml << " \n";
+ xml << " \n";
+ xml << " \n";
+ xml << " \n";
+ xml << " \n";
+ xml << " \n";
+ xml << " \n";
+ xml << " \n";
+ xml << " \n";
} else if(has_spc7110) {
xml << " \n";
xml << " \n";
@@ -399,13 +410,6 @@ SNESCartridge::SNESCartridge(const uint8_t *data, unsigned size) {
xml << " \n";
}
- if(has_cx4) {
- xml << " \n";
- xml << " \n";
- xml << " \n";
- xml << " \n";
- }
-
if(has_dsp1) {
xml << " \n";
if(dsp1_mapper == DSP1LoROM1MB) {
diff --git a/snes/Makefile b/snes/Makefile
index 039708d..cf3b96c 100644
--- a/snes/Makefile
+++ b/snes/Makefile
@@ -3,8 +3,8 @@ snes_objects += snes-system
snes_objects += snes-cartridge snes-cheat
snes_objects += snes-memory snes-cpucore snes-smpcore
snes_objects += snes-cpu snes-smp snes-dsp snes-ppu
-snes_objects += snes-nss snes-icd2 snes-superfx snes-sa1 snes-necdsp
-snes_objects += snes-bsx snes-srtc snes-sdd1 snes-spc7110 snes-sufamiturbo snes-cx4
+snes_objects += snes-nss snes-icd2 snes-superfx snes-sa1 snes-necdsp snes-hitachidsp
+snes_objects += snes-bsx snes-srtc snes-sdd1 snes-spc7110 snes-sufamiturbo
snes_objects += snes-obc1 snes-st0018
snes_objects += snes-msu1 snes-serial snes-link
snes_objects += $(gameboy_objects)
@@ -50,11 +50,11 @@ obj/snes-icd2.o : $(snes)/chip/icd2/icd2.cpp $(call rwildcard,$(snes)/chip/ic
obj/snes-superfx.o : $(snes)/chip/superfx/superfx.cpp $(call rwildcard,$(snes)/chip/superfx/)
obj/snes-sa1.o : $(snes)/chip/sa1/sa1.cpp $(call rwildcard,$(snes)/chip/sa1/)
obj/snes-necdsp.o : $(snes)/chip/necdsp/necdsp.cpp $(call rwildcard,$(snes)/chip/necdsp/)
+obj/snes-hitachidsp.o : $(snes)/chip/hitachidsp/hitachidsp.cpp $(call rwildcard,$(snes)/chip/hitachidsp/)
obj/snes-bsx.o : $(snes)/chip/bsx/bsx.cpp $(snes)/chip/bsx/*
obj/snes-srtc.o : $(snes)/chip/srtc/srtc.cpp $(snes)/chip/srtc/*
obj/snes-sdd1.o : $(snes)/chip/sdd1/sdd1.cpp $(snes)/chip/sdd1/*
obj/snes-spc7110.o : $(snes)/chip/spc7110/spc7110.cpp $(snes)/chip/spc7110/*
-obj/snes-cx4.o : $(snes)/chip/cx4/cx4.cpp $(snes)/chip/cx4/*
obj/snes-obc1.o : $(snes)/chip/obc1/obc1.cpp $(snes)/chip/obc1/*
obj/snes-st0018.o : $(snes)/chip/st0018/st0018.cpp $(snes)/chip/st0018/*
obj/snes-msu1.o : $(snes)/chip/msu1/msu1.cpp $(snes)/chip/msu1/*
diff --git a/snes/cartridge/cartridge.cpp b/snes/cartridge/cartridge.cpp
index 274126c..bc5536d 100644
--- a/snes/cartridge/cartridge.cpp
+++ b/snes/cartridge/cartridge.cpp
@@ -21,11 +21,11 @@ void Cartridge::load(Mode::e cartridge_mode, const lstring &xml_list) {
has_superfx = false;
has_sa1 = false;
has_necdsp = false;
+ has_hitachidsp = false;
has_srtc = false;
has_sdd1 = false;
has_spc7110 = false;
has_spc7110rtc = false;
- has_cx4 = false;
has_obc1 = false;
has_st0018 = false;
has_msu1 = false;
diff --git a/snes/cartridge/cartridge.hpp b/snes/cartridge/cartridge.hpp
index e33337a..f9366a0 100644
--- a/snes/cartridge/cartridge.hpp
+++ b/snes/cartridge/cartridge.hpp
@@ -41,11 +41,11 @@ public:
readonly has_superfx;
readonly has_sa1;
readonly has_necdsp;
+ readonly has_hitachidsp;
readonly has_srtc;
readonly has_sdd1;
readonly has_spc7110;
readonly has_spc7110rtc;
- readonly has_cx4;
readonly has_obc1;
readonly has_st0018;
readonly has_msu1;
@@ -108,13 +108,13 @@ private:
void xml_parse_superfx(xml_element&);
void xml_parse_sa1(xml_element&);
void xml_parse_necdsp(xml_element&);
+ void xml_parse_hitachidsp(xml_element&);
void xml_parse_bsx(xml_element&);
void xml_parse_sufamiturbo(xml_element&);
void xml_parse_supergameboy(xml_element&);
void xml_parse_srtc(xml_element&);
void xml_parse_sdd1(xml_element&);
void xml_parse_spc7110(xml_element&);
- void xml_parse_cx4(xml_element&);
void xml_parse_obc1(xml_element&);
void xml_parse_setarisc(xml_element&);
void xml_parse_msu1(xml_element&);
diff --git a/snes/cartridge/xml.cpp b/snes/cartridge/xml.cpp
index 5d174aa..f33987b 100644
--- a/snes/cartridge/xml.cpp
+++ b/snes/cartridge/xml.cpp
@@ -40,12 +40,12 @@ void Cartridge::parse_xml_cartridge(const char *data) {
if(node.name == "superfx") xml_parse_superfx(node);
if(node.name == "sa1") xml_parse_sa1(node);
if(node.name == "necdsp") xml_parse_necdsp(node);
+ if(node.name == "hitachidsp") xml_parse_hitachidsp(node);
if(node.name == "bsx") xml_parse_bsx(node);
if(node.name == "sufamiturbo") xml_parse_sufamiturbo(node);
if(node.name == "srtc") xml_parse_srtc(node);
if(node.name == "sdd1") xml_parse_sdd1(node);
if(node.name == "spc7110") xml_parse_spc7110(node);
- if(node.name == "cx4") xml_parse_cx4(node);
if(node.name == "obc1") xml_parse_obc1(node);
if(node.name == "setarisc") xml_parse_setarisc(node);
if(node.name == "msu1") xml_parse_msu1(node);
@@ -372,6 +372,81 @@ void Cartridge::xml_parse_necdsp(xml_element &root) {
}
}
+void Cartridge::xml_parse_hitachidsp(xml_element &root) {
+ has_hitachidsp = true;
+ hitachidsp.frequency = 20000000;
+
+ for(unsigned n = 0; n < 1024; n++) hitachidsp.dataROM[n] = 0x000000;
+
+ string program, sha256;
+
+ foreach(attr, root.attribute) {
+ if(attr.name == "frequency") {
+ hitachidsp.frequency = decimal(attr.content);
+ } else if(attr.name == "program") {
+ program = attr.content;
+ } else if(attr.name == "sha256") {
+ sha256 = attr.content;
+ }
+ }
+
+ string path = string( dir(system.interface->path(Slot::Base, ".dsp")), program );
+ file fp;
+ if(fp.open(path, file::mode_read) == false) {
+ system.interface->message(string( "Warning: Hitachi DSP program ", program, " is missing." ));
+ } else if(fp.size() != 1024 * 3) {
+ system.interface->message(string( "Warning: Hitachi DSP program ", program, " is of the wrong file size." ));
+ fp.close();
+ } else {
+ for(unsigned n = 0; n < 1024; n++) hitachidsp.dataROM[n] = fp.readl(3);
+
+ if(sha256 != "") {
+ //XML file specified SHA256 sum for program. Verify file matches the hash.
+ fp.seek(0);
+ uint8 data[3072];
+ fp.read(data, 3072);
+
+ sha256_ctx sha;
+ uint8 hash[32];
+ sha256_init(&sha);
+ sha256_chunk(&sha, data, 3072);
+ sha256_final(&sha);
+ sha256_hash(&sha, hash);
+
+ string filehash;
+ foreach(n, hash) filehash.append(hex<2>(n));
+
+ if(sha256 != filehash) {
+ system.interface->message(string( "Warning: Hitachi DSP program ", program, " SHA256 sum is incorrect." ));
+ }
+ }
+
+ fp.close();
+ }
+
+ foreach(node, root.element) {
+ if(node.name == "rom") foreach(leaf, node.element) {
+ if(leaf.name == "map") {
+ Mapping m(function( &HitachiDSP::rom_read, &hitachidsp ), function( &HitachiDSP::rom_write, &hitachidsp ));
+ foreach(attr, leaf.attribute) {
+ if(attr.name == "address") xml_parse_address(m, attr.content);
+ if(attr.name == "mode") xml_parse_mode(m, attr.content);
+ if(attr.name == "offset") m.offset = hex(attr.content);
+ if(attr.name == "size") m.size = hex(attr.content);
+ }
+ mapping.append(m);
+ }
+ }
+ if(node.name == "mmio") foreach(leaf, node.element) {
+ Mapping m(function( &HitachiDSP::dsp_read, &hitachidsp ), function( &HitachiDSP::dsp_write, &hitachidsp ));
+ foreach(attr, leaf.attribute) {
+ if(attr.name == "address") xml_parse_address(m, attr.content);
+ }
+ mapping.append(m);
+ }
+ }
+}
+
void Cartridge::xml_parse_bsx(xml_element &root) {
if(mode.i != Mode::BsxSlotted && mode.i != Mode::Bsx) return;
@@ -580,20 +655,6 @@ void Cartridge::xml_parse_spc7110(xml_element &root) {
}
}
-void Cartridge::xml_parse_cx4(xml_element &root) {
- has_cx4 = true;
-
- foreach(node, root.element) {
- if(node.name == "map") {
- Mapping m(function( &Cx4::read, &cx4 ), function( &Cx4::write, &cx4 ));
- foreach(attr, node.attribute) {
- if(attr.name == "address") xml_parse_address(m, attr.content);
- }
- mapping.append(m);
- }
- }
-}
-
void Cartridge::xml_parse_obc1(xml_element &root) {
has_obc1 = true;
diff --git a/snes/chip/.chip.hpp.rej.swp b/snes/chip/.chip.hpp.rej.swp
deleted file mode 100644
index 0b15a9b..0000000
Binary files a/snes/chip/.chip.hpp.rej.swp and /dev/null differ
diff --git a/snes/chip/hitachidsp/hitachidsp.cpp b/snes/chip/hitachidsp/hitachidsp.cpp
index 62f4bfa..c94db95 100644
--- a/snes/chip/hitachidsp/hitachidsp.cpp
+++ b/snes/chip/hitachidsp/hitachidsp.cpp
@@ -13,11 +13,11 @@ void HitachiDSP::Enter() { hitachidsp.enter(); }
void HitachiDSP::enter() {
while(true) {
- if(scheduler.sync == Scheduler::SynchronizeMode::All) {
+ if(scheduler.sync.i == Scheduler::SynchronizeMode::All) {
scheduler.exit(Scheduler::ExitReason::SynchronizeEvent);
}
- switch(state) {
+ switch(state.i) {
case State::Idle:
step(1);
break;
@@ -26,7 +26,7 @@ void HitachiDSP::enter() {
bus.write(regs.dma_target + n, bus.read(regs.dma_source + n));
step(2);
}
- state = State::Idle;
+ state.i = State::Idle;
break;
case State::Execute:
unsigned offset = regs.program_offset + regs.pc * 2;
@@ -57,7 +57,7 @@ void HitachiDSP::power() {
void HitachiDSP::reset() {
create(HitachiDSP::Enter, frequency);
- state = State::Idle;
+ state.i = State::Idle;
regs.n = 0;
regs.z = 0;
diff --git a/snes/chip/hitachidsp/hitachidsp.hpp b/snes/chip/hitachidsp/hitachidsp.hpp
index 40853c0..6279ff7 100644
--- a/snes/chip/hitachidsp/hitachidsp.hpp
+++ b/snes/chip/hitachidsp/hitachidsp.hpp
@@ -8,7 +8,7 @@ public:
uint8 dataRAM[3072];
uint24 stack[8];
uint16 opcode;
- enum class State : unsigned { Idle, DMA, Execute } state;
+ struct State { enum e { Idle, DMA, Execute } i; } state;
#include "registers.hpp"
static void Enter();
diff --git a/snes/chip/hitachidsp/memory.cpp b/snes/chip/hitachidsp/memory.cpp
index 3c9c3af..e024a3c 100644
--- a/snes/chip/hitachidsp/memory.cpp
+++ b/snes/chip/hitachidsp/memory.cpp
@@ -11,7 +11,7 @@ void HitachiDSP::bus_write(unsigned addr, uint8 data) {
uint8 HitachiDSP::rom_read(unsigned addr) {
if(co_active() == cpu.thread) {
- if(state == State::Idle) return cartridge.rom.read(addr);
+ if(state.i == State::Idle) return cartridge.rom.read(addr);
if((addr & 0x40ffe0) == 0x00ffe0) return regs.vector[addr & 0x1f];
return cpu.regs.mdr;
}
@@ -56,7 +56,7 @@ uint8 HitachiDSP::dsp_read(unsigned addr) {
case 0x1f53: case 0x1f54: case 0x1f55: case 0x1f56:
case 0x1f57: case 0x1f58: case 0x1f59: case 0x1f5a:
case 0x1f5b: case 0x1f5c: case 0x1f5d: case 0x1f5e:
- case 0x1f5f: return ((state != State::Idle) << 6) | ((state == State::Idle) << 1);
+ case 0x1f5f: return ((state.i != State::Idle) << 6) | ((state.i == State::Idle) << 1);
}
//Vector
@@ -93,7 +93,7 @@ void HitachiDSP::dsp_write(unsigned addr, uint8 data) {
case 0x1f45: regs.dma_target = (regs.dma_target & 0xffff00) | (data << 0); return;
case 0x1f46: regs.dma_target = (regs.dma_target & 0xff00ff) | (data << 8); return;
case 0x1f47: regs.dma_target = (regs.dma_target & 0x00ffff) | (data << 16);
- if(state == State::Idle) state = State::DMA;
+ if(state.i == State::Idle) state.i = State::DMA;
return;
case 0x1f48: regs.r1f48 = data & 0x01; return;
case 0x1f49: regs.program_offset = (regs.program_offset & 0xffff00) | (data << 0); return;
@@ -103,9 +103,9 @@ void HitachiDSP::dsp_write(unsigned addr, uint8 data) {
case 0x1f4d: regs.page_number = (regs.page_number & 0x7f00) | ((data & 0xff) << 0); return;
case 0x1f4e: regs.page_number = (regs.page_number & 0x00ff) | ((data & 0x7f) << 8); return;
case 0x1f4f: regs.program_counter = data;
- if(state == State::Idle) {
+ if(state.i == State::Idle) {
regs.pc = regs.page_number * 256 + regs.program_counter;
- state = State::Execute;
+ state.i = State::Execute;
}
return;
case 0x1f50: regs.r1f50 = data & 0x77; return;
diff --git a/snes/chip/hitachidsp/opcodes.cpp b/snes/chip/hitachidsp/opcodes.cpp
index 2ace5a3..8d2158b 100644
--- a/snes/chip/hitachidsp/opcodes.cpp
+++ b/snes/chip/hitachidsp/opcodes.cpp
@@ -341,12 +341,12 @@ void HitachiDSP::exec() {
else if((opcode & 0xffff) == 0xfc00) {
//1111 1100 0000 0000
//halt
- state = State::Idle;
+ state.i = State::Idle;
}
else {
print("Hitachi DSP: invalid opcode @ ", hex<4>(regs.pc - 1), " = ", hex<4>(opcode), "\n");
- state = State::Idle;
+ state.i = State::Idle;
}
}
diff --git a/snes/snes.hpp b/snes/snes.hpp
index 258ea40..7bb1d87 100644
--- a/snes/snes.hpp
+++ b/snes/snes.hpp
@@ -1,8 +1,8 @@
namespace SNES {
namespace Info {
static const char Name[] = "bsnes";
- static const char Version[] = "079.03";
- static const unsigned SerializerVersion = 20;
+ static const char Version[] = "079.04";
+ static const unsigned SerializerVersion = 21;
}
}
@@ -43,6 +43,8 @@ namespace SNES {
typedef int32_t int32;
typedef int64_t int64;
+ typedef int_t<24> int24;
+
typedef uint8_t uint8;
typedef uint16_t uint16;
typedef uint32_t uint32;
diff --git a/snes/system/serialization.cpp b/snes/system/serialization.cpp
index dfaa204..43c5d57 100644
--- a/snes/system/serialization.cpp
+++ b/snes/system/serialization.cpp
@@ -62,10 +62,10 @@ void System::serialize_all(serializer &s) {
if(cartridge.has_superfx()) superfx.serialize(s);
if(cartridge.has_sa1()) sa1.serialize(s);
if(cartridge.has_necdsp()) necdsp.serialize(s);
+ if(cartridge.has_hitachidsp()) hitachidsp.serialize(s);
if(cartridge.has_srtc()) srtc.serialize(s);
if(cartridge.has_sdd1()) sdd1.serialize(s);
if(cartridge.has_spc7110()) spc7110.serialize(s);
- if(cartridge.has_cx4()) cx4.serialize(s);
if(cartridge.has_obc1()) obc1.serialize(s);
if(cartridge.has_msu1()) msu1.serialize(s);
if(cartridge.has_serial()) serial.serialize(s);
diff --git a/snes/system/system.cpp b/snes/system/system.cpp
index d8cf989..33751aa 100644
--- a/snes/system/system.cpp
+++ b/snes/system/system.cpp
@@ -74,13 +74,13 @@ void System::init(Interface *interface_) {
superfx.init();
sa1.init();
necdsp.init();
+ hitachidsp.init();
bsxsatellaview.init();
bsxcartridge.init();
bsxflash.init();
srtc.init();
sdd1.init();
spc7110.init();
- cx4.init();
obc1.init();
st0018.init();
msu1.init();
@@ -117,10 +117,10 @@ void System::load() {
if(cartridge.has_superfx()) superfx.load();
if(cartridge.has_sa1()) sa1.load();
if(cartridge.has_necdsp()) necdsp.load();
+ if(cartridge.has_hitachidsp()) hitachidsp.load();
if(cartridge.has_srtc()) srtc.load();
if(cartridge.has_sdd1()) sdd1.load();
if(cartridge.has_spc7110()) spc7110.load();
- if(cartridge.has_cx4()) cx4.load();
if(cartridge.has_obc1()) obc1.load();
if(cartridge.has_st0018()) st0018.load();
if(cartridge.has_msu1()) msu1.load();
@@ -142,10 +142,10 @@ void System::unload() {
if(cartridge.has_superfx()) superfx.unload();
if(cartridge.has_sa1()) sa1.unload();
if(cartridge.has_necdsp()) necdsp.unload();
+ if(cartridge.has_hitachidsp()) hitachidsp.unload();
if(cartridge.has_srtc()) srtc.unload();
if(cartridge.has_sdd1()) sdd1.unload();
if(cartridge.has_spc7110()) spc7110.unload();
- if(cartridge.has_cx4()) cx4.unload();
if(cartridge.has_obc1()) obc1.unload();
if(cartridge.has_st0018()) st0018.unload();
if(cartridge.has_msu1()) msu1.unload();
@@ -179,10 +179,10 @@ void System::power() {
if(cartridge.has_superfx()) superfx.power();
if(cartridge.has_sa1()) sa1.power();
if(cartridge.has_necdsp()) necdsp.power();
+ if(cartridge.has_hitachidsp()) hitachidsp.power();
if(cartridge.has_srtc()) srtc.power();
if(cartridge.has_sdd1()) sdd1.power();
if(cartridge.has_spc7110()) spc7110.power();
- if(cartridge.has_cx4()) cx4.power();
if(cartridge.has_obc1()) obc1.power();
if(cartridge.has_st0018()) st0018.power();
if(cartridge.has_msu1()) msu1.power();
@@ -217,10 +217,10 @@ void System::reset() {
if(cartridge.has_superfx()) superfx.reset();
if(cartridge.has_sa1()) sa1.reset();
if(cartridge.has_necdsp()) necdsp.reset();
+ if(cartridge.has_hitachidsp()) hitachidsp.reset();
if(cartridge.has_srtc()) srtc.reset();
if(cartridge.has_sdd1()) sdd1.reset();
if(cartridge.has_spc7110()) spc7110.reset();
- if(cartridge.has_cx4()) cx4.reset();
if(cartridge.has_obc1()) obc1.reset();
if(cartridge.has_st0018()) st0018.reset();
if(cartridge.has_msu1()) msu1.reset();