diff --git a/bsnes/Makefile b/bsnes/Makefile index 97fbab0a..e4fd0e0e 100755 --- a/bsnes/Makefile +++ b/bsnes/Makefile @@ -1,9 +1,9 @@ include nall/Makefile -nes := nes -snes := snes -gb := gb -gba := gba +fc := fc +sfc := sfc +gb := gb +gba := gba profile := accuracy target := ui diff --git a/bsnes/base/base.hpp b/bsnes/base/base.hpp index a1f28e37..842afd6b 100755 --- a/bsnes/base/base.hpp +++ b/bsnes/base/base.hpp @@ -1,7 +1,7 @@ #ifndef BASE_HPP #define BASE_HPP -static const char Version[] = "088.04"; +static const char Version[] = "088.07"; #include #include @@ -14,6 +14,7 @@ static const char Version[] = "088.04"; #include #include #include +#include #include #include #include diff --git a/bsnes/fc/Makefile b/bsnes/fc/Makefile new file mode 100755 index 00000000..ce5bad53 --- /dev/null +++ b/bsnes/fc/Makefile @@ -0,0 +1,16 @@ +fc_objects := fc-interface fc-system fc-scheduler fc-input +fc_objects += fc-memory fc-cartridge fc-cpu fc-apu fc-ppu +fc_objects += fc-cheat fc-video +objects += $(fc_objects) + +obj/fc-interface.o: $(fc)/interface/interface.cpp $(call rwildcard,$(fc)/interface/) +obj/fc-system.o: $(fc)/system/system.cpp $(call rwildcard,$(fc)/system/) +obj/fc-scheduler.o: $(fc)/scheduler/scheduler.cpp $(call rwildcard,$(fc)/scheduler/) +obj/fc-input.o: $(fc)/input/input.cpp $(call rwildcard,$(fc)/input/) +obj/fc-memory.o: $(fc)/memory/memory.cpp $(call rwildcard,$(fc)/memory/) +obj/fc-cartridge.o: $(fc)/cartridge/cartridge.cpp $(call rwildcard,$(fc)/cartridge/) +obj/fc-cpu.o: $(fc)/cpu/cpu.cpp $(call rwildcard,$(fc)/cpu/) +obj/fc-apu.o: $(fc)/apu/apu.cpp $(call rwildcard,$(fc)/apu/) +obj/fc-ppu.o: $(fc)/ppu/ppu.cpp $(call rwildcard,$(fc)/ppu/) +obj/fc-cheat.o: $(fc)/cheat/cheat.cpp $(call rwildcard,$(fc)/cheat/) +obj/fc-video.o: $(fc)/video/video.cpp $(call rwildcard,$(fc)/video/) diff --git a/bsnes/nes/apu/apu.cpp b/bsnes/fc/apu/apu.cpp similarity index 99% rename from bsnes/nes/apu/apu.cpp rename to bsnes/fc/apu/apu.cpp index faac54fb..66a10934 100755 --- a/bsnes/nes/apu/apu.cpp +++ b/bsnes/fc/apu/apu.cpp @@ -1,4 +1,4 @@ -#include +#include namespace Famicom { diff --git a/bsnes/nes/apu/apu.hpp b/bsnes/fc/apu/apu.hpp similarity index 100% rename from bsnes/nes/apu/apu.hpp rename to bsnes/fc/apu/apu.hpp diff --git a/bsnes/nes/apu/dmc.cpp b/bsnes/fc/apu/dmc.cpp similarity index 100% rename from bsnes/nes/apu/dmc.cpp rename to bsnes/fc/apu/dmc.cpp diff --git a/bsnes/nes/apu/dmc.hpp b/bsnes/fc/apu/dmc.hpp similarity index 100% rename from bsnes/nes/apu/dmc.hpp rename to bsnes/fc/apu/dmc.hpp diff --git a/bsnes/nes/apu/envelope.cpp b/bsnes/fc/apu/envelope.cpp similarity index 100% rename from bsnes/nes/apu/envelope.cpp rename to bsnes/fc/apu/envelope.cpp diff --git a/bsnes/nes/apu/envelope.hpp b/bsnes/fc/apu/envelope.hpp similarity index 100% rename from bsnes/nes/apu/envelope.hpp rename to bsnes/fc/apu/envelope.hpp diff --git a/bsnes/nes/apu/noise.cpp b/bsnes/fc/apu/noise.cpp similarity index 100% rename from bsnes/nes/apu/noise.cpp rename to bsnes/fc/apu/noise.cpp diff --git a/bsnes/nes/apu/noise.hpp b/bsnes/fc/apu/noise.hpp similarity index 100% rename from bsnes/nes/apu/noise.hpp rename to bsnes/fc/apu/noise.hpp diff --git a/bsnes/nes/apu/pulse.cpp b/bsnes/fc/apu/pulse.cpp similarity index 100% rename from bsnes/nes/apu/pulse.cpp rename to bsnes/fc/apu/pulse.cpp diff --git a/bsnes/nes/apu/pulse.hpp b/bsnes/fc/apu/pulse.hpp similarity index 100% rename from bsnes/nes/apu/pulse.hpp rename to bsnes/fc/apu/pulse.hpp diff --git a/bsnes/nes/apu/serialization.cpp b/bsnes/fc/apu/serialization.cpp similarity index 100% rename from bsnes/nes/apu/serialization.cpp rename to bsnes/fc/apu/serialization.cpp diff --git a/bsnes/nes/apu/sweep.cpp b/bsnes/fc/apu/sweep.cpp similarity index 100% rename from bsnes/nes/apu/sweep.cpp rename to bsnes/fc/apu/sweep.cpp diff --git a/bsnes/nes/apu/sweep.hpp b/bsnes/fc/apu/sweep.hpp similarity index 100% rename from bsnes/nes/apu/sweep.hpp rename to bsnes/fc/apu/sweep.hpp diff --git a/bsnes/nes/apu/triangle.cpp b/bsnes/fc/apu/triangle.cpp similarity index 100% rename from bsnes/nes/apu/triangle.cpp rename to bsnes/fc/apu/triangle.cpp diff --git a/bsnes/nes/apu/triangle.hpp b/bsnes/fc/apu/triangle.hpp similarity index 100% rename from bsnes/nes/apu/triangle.hpp rename to bsnes/fc/apu/triangle.hpp diff --git a/bsnes/nes/cartridge/board/bandai-fcg.cpp b/bsnes/fc/cartridge/board/bandai-fcg.cpp similarity index 100% rename from bsnes/nes/cartridge/board/bandai-fcg.cpp rename to bsnes/fc/cartridge/board/bandai-fcg.cpp diff --git a/bsnes/nes/cartridge/board/board.cpp b/bsnes/fc/cartridge/board/board.cpp similarity index 100% rename from bsnes/nes/cartridge/board/board.cpp rename to bsnes/fc/cartridge/board/board.cpp diff --git a/bsnes/nes/cartridge/board/board.hpp b/bsnes/fc/cartridge/board/board.hpp similarity index 100% rename from bsnes/nes/cartridge/board/board.hpp rename to bsnes/fc/cartridge/board/board.hpp diff --git a/bsnes/nes/cartridge/board/konami-vrc1.cpp b/bsnes/fc/cartridge/board/konami-vrc1.cpp similarity index 100% rename from bsnes/nes/cartridge/board/konami-vrc1.cpp rename to bsnes/fc/cartridge/board/konami-vrc1.cpp diff --git a/bsnes/nes/cartridge/board/konami-vrc2.cpp b/bsnes/fc/cartridge/board/konami-vrc2.cpp similarity index 100% rename from bsnes/nes/cartridge/board/konami-vrc2.cpp rename to bsnes/fc/cartridge/board/konami-vrc2.cpp diff --git a/bsnes/nes/cartridge/board/konami-vrc3.cpp b/bsnes/fc/cartridge/board/konami-vrc3.cpp similarity index 100% rename from bsnes/nes/cartridge/board/konami-vrc3.cpp rename to bsnes/fc/cartridge/board/konami-vrc3.cpp diff --git a/bsnes/nes/cartridge/board/konami-vrc4.cpp b/bsnes/fc/cartridge/board/konami-vrc4.cpp similarity index 100% rename from bsnes/nes/cartridge/board/konami-vrc4.cpp rename to bsnes/fc/cartridge/board/konami-vrc4.cpp diff --git a/bsnes/nes/cartridge/board/konami-vrc6.cpp b/bsnes/fc/cartridge/board/konami-vrc6.cpp similarity index 100% rename from bsnes/nes/cartridge/board/konami-vrc6.cpp rename to bsnes/fc/cartridge/board/konami-vrc6.cpp diff --git a/bsnes/nes/cartridge/board/konami-vrc7.cpp b/bsnes/fc/cartridge/board/konami-vrc7.cpp similarity index 100% rename from bsnes/nes/cartridge/board/konami-vrc7.cpp rename to bsnes/fc/cartridge/board/konami-vrc7.cpp diff --git a/bsnes/nes/cartridge/board/nes-axrom.cpp b/bsnes/fc/cartridge/board/nes-axrom.cpp similarity index 100% rename from bsnes/nes/cartridge/board/nes-axrom.cpp rename to bsnes/fc/cartridge/board/nes-axrom.cpp diff --git a/bsnes/nes/cartridge/board/nes-bnrom.cpp b/bsnes/fc/cartridge/board/nes-bnrom.cpp similarity index 100% rename from bsnes/nes/cartridge/board/nes-bnrom.cpp rename to bsnes/fc/cartridge/board/nes-bnrom.cpp diff --git a/bsnes/nes/cartridge/board/nes-cnrom.cpp b/bsnes/fc/cartridge/board/nes-cnrom.cpp similarity index 100% rename from bsnes/nes/cartridge/board/nes-cnrom.cpp rename to bsnes/fc/cartridge/board/nes-cnrom.cpp diff --git a/bsnes/nes/cartridge/board/nes-exrom.cpp b/bsnes/fc/cartridge/board/nes-exrom.cpp similarity index 100% rename from bsnes/nes/cartridge/board/nes-exrom.cpp rename to bsnes/fc/cartridge/board/nes-exrom.cpp diff --git a/bsnes/nes/cartridge/board/nes-fxrom.cpp b/bsnes/fc/cartridge/board/nes-fxrom.cpp similarity index 100% rename from bsnes/nes/cartridge/board/nes-fxrom.cpp rename to bsnes/fc/cartridge/board/nes-fxrom.cpp diff --git a/bsnes/nes/cartridge/board/nes-gxrom.cpp b/bsnes/fc/cartridge/board/nes-gxrom.cpp similarity index 100% rename from bsnes/nes/cartridge/board/nes-gxrom.cpp rename to bsnes/fc/cartridge/board/nes-gxrom.cpp diff --git a/bsnes/nes/cartridge/board/nes-hkrom.cpp b/bsnes/fc/cartridge/board/nes-hkrom.cpp similarity index 100% rename from bsnes/nes/cartridge/board/nes-hkrom.cpp rename to bsnes/fc/cartridge/board/nes-hkrom.cpp diff --git a/bsnes/nes/cartridge/board/nes-nrom.cpp b/bsnes/fc/cartridge/board/nes-nrom.cpp similarity index 100% rename from bsnes/nes/cartridge/board/nes-nrom.cpp rename to bsnes/fc/cartridge/board/nes-nrom.cpp diff --git a/bsnes/nes/cartridge/board/nes-pxrom.cpp b/bsnes/fc/cartridge/board/nes-pxrom.cpp similarity index 100% rename from bsnes/nes/cartridge/board/nes-pxrom.cpp rename to bsnes/fc/cartridge/board/nes-pxrom.cpp diff --git a/bsnes/nes/cartridge/board/nes-sxrom.cpp b/bsnes/fc/cartridge/board/nes-sxrom.cpp similarity index 100% rename from bsnes/nes/cartridge/board/nes-sxrom.cpp rename to bsnes/fc/cartridge/board/nes-sxrom.cpp diff --git a/bsnes/nes/cartridge/board/nes-txrom.cpp b/bsnes/fc/cartridge/board/nes-txrom.cpp similarity index 100% rename from bsnes/nes/cartridge/board/nes-txrom.cpp rename to bsnes/fc/cartridge/board/nes-txrom.cpp diff --git a/bsnes/nes/cartridge/board/nes-uxrom.cpp b/bsnes/fc/cartridge/board/nes-uxrom.cpp similarity index 100% rename from bsnes/nes/cartridge/board/nes-uxrom.cpp rename to bsnes/fc/cartridge/board/nes-uxrom.cpp diff --git a/bsnes/nes/cartridge/board/sunsoft-5b.cpp b/bsnes/fc/cartridge/board/sunsoft-5b.cpp similarity index 100% rename from bsnes/nes/cartridge/board/sunsoft-5b.cpp rename to bsnes/fc/cartridge/board/sunsoft-5b.cpp diff --git a/bsnes/nes/cartridge/cartridge.cpp b/bsnes/fc/cartridge/cartridge.cpp similarity index 98% rename from bsnes/nes/cartridge/cartridge.cpp rename to bsnes/fc/cartridge/cartridge.cpp index 02c4821a..39348a42 100755 --- a/bsnes/nes/cartridge/cartridge.cpp +++ b/bsnes/fc/cartridge/cartridge.cpp @@ -1,4 +1,4 @@ -#include +#include namespace Famicom { diff --git a/bsnes/nes/cartridge/cartridge.hpp b/bsnes/fc/cartridge/cartridge.hpp similarity index 100% rename from bsnes/nes/cartridge/cartridge.hpp rename to bsnes/fc/cartridge/cartridge.hpp diff --git a/bsnes/nes/cartridge/chip/chip.cpp b/bsnes/fc/cartridge/chip/chip.cpp similarity index 100% rename from bsnes/nes/cartridge/chip/chip.cpp rename to bsnes/fc/cartridge/chip/chip.cpp diff --git a/bsnes/nes/cartridge/chip/chip.hpp b/bsnes/fc/cartridge/chip/chip.hpp similarity index 100% rename from bsnes/nes/cartridge/chip/chip.hpp rename to bsnes/fc/cartridge/chip/chip.hpp diff --git a/bsnes/nes/cartridge/chip/mmc1.cpp b/bsnes/fc/cartridge/chip/mmc1.cpp similarity index 100% rename from bsnes/nes/cartridge/chip/mmc1.cpp rename to bsnes/fc/cartridge/chip/mmc1.cpp diff --git a/bsnes/nes/cartridge/chip/mmc3.cpp b/bsnes/fc/cartridge/chip/mmc3.cpp similarity index 100% rename from bsnes/nes/cartridge/chip/mmc3.cpp rename to bsnes/fc/cartridge/chip/mmc3.cpp diff --git a/bsnes/nes/cartridge/chip/mmc5.cpp b/bsnes/fc/cartridge/chip/mmc5.cpp similarity index 100% rename from bsnes/nes/cartridge/chip/mmc5.cpp rename to bsnes/fc/cartridge/chip/mmc5.cpp diff --git a/bsnes/nes/cartridge/chip/mmc6.cpp b/bsnes/fc/cartridge/chip/mmc6.cpp similarity index 100% rename from bsnes/nes/cartridge/chip/mmc6.cpp rename to bsnes/fc/cartridge/chip/mmc6.cpp diff --git a/bsnes/nes/cartridge/chip/vrc1.cpp b/bsnes/fc/cartridge/chip/vrc1.cpp similarity index 100% rename from bsnes/nes/cartridge/chip/vrc1.cpp rename to bsnes/fc/cartridge/chip/vrc1.cpp diff --git a/bsnes/nes/cartridge/chip/vrc2.cpp b/bsnes/fc/cartridge/chip/vrc2.cpp similarity index 100% rename from bsnes/nes/cartridge/chip/vrc2.cpp rename to bsnes/fc/cartridge/chip/vrc2.cpp diff --git a/bsnes/nes/cartridge/chip/vrc3.cpp b/bsnes/fc/cartridge/chip/vrc3.cpp similarity index 100% rename from bsnes/nes/cartridge/chip/vrc3.cpp rename to bsnes/fc/cartridge/chip/vrc3.cpp diff --git a/bsnes/nes/cartridge/chip/vrc4.cpp b/bsnes/fc/cartridge/chip/vrc4.cpp similarity index 100% rename from bsnes/nes/cartridge/chip/vrc4.cpp rename to bsnes/fc/cartridge/chip/vrc4.cpp diff --git a/bsnes/nes/cartridge/chip/vrc6.cpp b/bsnes/fc/cartridge/chip/vrc6.cpp similarity index 100% rename from bsnes/nes/cartridge/chip/vrc6.cpp rename to bsnes/fc/cartridge/chip/vrc6.cpp diff --git a/bsnes/nes/cartridge/chip/vrc7.cpp b/bsnes/fc/cartridge/chip/vrc7.cpp similarity index 100% rename from bsnes/nes/cartridge/chip/vrc7.cpp rename to bsnes/fc/cartridge/chip/vrc7.cpp diff --git a/bsnes/nes/cheat/cheat.cpp b/bsnes/fc/cheat/cheat.cpp similarity index 99% rename from bsnes/nes/cheat/cheat.cpp rename to bsnes/fc/cheat/cheat.cpp index d94a563d..b2f5b133 100755 --- a/bsnes/nes/cheat/cheat.cpp +++ b/bsnes/fc/cheat/cheat.cpp @@ -1,4 +1,4 @@ -#include +#include namespace Famicom { diff --git a/bsnes/nes/cheat/cheat.hpp b/bsnes/fc/cheat/cheat.hpp similarity index 100% rename from bsnes/nes/cheat/cheat.hpp rename to bsnes/fc/cheat/cheat.hpp diff --git a/bsnes/nes/cpu/cpu.cpp b/bsnes/fc/cpu/cpu.cpp similarity index 97% rename from bsnes/nes/cpu/cpu.cpp rename to bsnes/fc/cpu/cpu.cpp index 7b9faea1..b95d80bf 100755 --- a/bsnes/nes/cpu/cpu.cpp +++ b/bsnes/fc/cpu/cpu.cpp @@ -1,4 +1,4 @@ -#include +#include namespace Famicom { @@ -37,7 +37,7 @@ void CPU::add_clocks(unsigned clocks) { } void CPU::power() { - RP2A03::power(); + R6502::power(); for(unsigned addr = 0; addr < 0x0800; addr++) ram[addr] = 0xff; ram[0x0008] = 0xf7; @@ -47,7 +47,7 @@ void CPU::power() { } void CPU::reset() { - RP2A03::reset(); + R6502::reset(); create(CPU::Enter, 21477272); regs.pc = bus.read(0xfffc) << 0; diff --git a/bsnes/nes/cpu/cpu.hpp b/bsnes/fc/cpu/cpu.hpp similarity index 96% rename from bsnes/nes/cpu/cpu.hpp rename to bsnes/fc/cpu/cpu.hpp index b875caaf..a2b20bac 100755 --- a/bsnes/nes/cpu/cpu.hpp +++ b/bsnes/fc/cpu/cpu.hpp @@ -1,4 +1,4 @@ -struct CPU : Processor::RP2A03, Thread { +struct CPU : Processor::R6502, Thread { uint8 ram[0x0800]; struct Status { diff --git a/bsnes/nes/cpu/serialization.cpp b/bsnes/fc/cpu/serialization.cpp similarity index 95% rename from bsnes/nes/cpu/serialization.cpp rename to bsnes/fc/cpu/serialization.cpp index 617b1182..fca19ef9 100755 --- a/bsnes/nes/cpu/serialization.cpp +++ b/bsnes/fc/cpu/serialization.cpp @@ -1,5 +1,5 @@ void CPU::serialize(serializer &s) { - RP2A03::serialize(s); + R6502::serialize(s); Thread::serialize(s); s.array(ram); diff --git a/bsnes/nes/cpu/timing.cpp b/bsnes/fc/cpu/timing.cpp similarity index 100% rename from bsnes/nes/cpu/timing.cpp rename to bsnes/fc/cpu/timing.cpp diff --git a/bsnes/nes/nes.hpp b/bsnes/fc/fc.hpp similarity index 61% rename from bsnes/nes/nes.hpp rename to bsnes/fc/fc.hpp index e73fbef8..3dd6b613 100755 --- a/bsnes/nes/nes.hpp +++ b/bsnes/fc/fc.hpp @@ -1,13 +1,13 @@ -#ifndef NES_HPP -#define NES_HPP +#ifndef FC_HPP +#define FC_HPP #include -#include +#include namespace Famicom { namespace Info { static const char Name[] = "bnes"; - static const unsigned SerializerVersion = 1; + static const unsigned SerializerVersion = 2; } } @@ -46,17 +46,17 @@ namespace Famicom { } }; - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include } #endif diff --git a/bsnes/nes/input/input.cpp b/bsnes/fc/input/input.cpp similarity index 97% rename from bsnes/nes/input/input.cpp rename to bsnes/fc/input/input.cpp index 2069cdcb..31c6b156 100755 --- a/bsnes/nes/input/input.cpp +++ b/bsnes/fc/input/input.cpp @@ -1,4 +1,4 @@ -#include +#include namespace Famicom { diff --git a/bsnes/nes/input/input.hpp b/bsnes/fc/input/input.hpp similarity index 100% rename from bsnes/nes/input/input.hpp rename to bsnes/fc/input/input.hpp diff --git a/bsnes/nes/input/serialization.cpp b/bsnes/fc/input/serialization.cpp similarity index 100% rename from bsnes/nes/input/serialization.cpp rename to bsnes/fc/input/serialization.cpp diff --git a/bsnes/nes/interface/interface.cpp b/bsnes/fc/interface/interface.cpp similarity index 95% rename from bsnes/nes/interface/interface.cpp rename to bsnes/fc/interface/interface.cpp index 409de5a3..caeb205e 100755 --- a/bsnes/nes/interface/interface.cpp +++ b/bsnes/fc/interface/interface.cpp @@ -1,4 +1,4 @@ -#include +#include namespace Famicom { diff --git a/bsnes/nes/interface/interface.hpp b/bsnes/fc/interface/interface.hpp similarity index 100% rename from bsnes/nes/interface/interface.hpp rename to bsnes/fc/interface/interface.hpp diff --git a/bsnes/nes/memory/memory.cpp b/bsnes/fc/memory/memory.cpp similarity index 97% rename from bsnes/nes/memory/memory.cpp rename to bsnes/fc/memory/memory.cpp index f1f0d5f0..22176d15 100755 --- a/bsnes/nes/memory/memory.cpp +++ b/bsnes/fc/memory/memory.cpp @@ -1,4 +1,4 @@ -#include +#include namespace Famicom { diff --git a/bsnes/nes/memory/memory.hpp b/bsnes/fc/memory/memory.hpp similarity index 100% rename from bsnes/nes/memory/memory.hpp rename to bsnes/fc/memory/memory.hpp diff --git a/bsnes/nes/ppu/ppu.cpp b/bsnes/fc/ppu/ppu.cpp similarity index 99% rename from bsnes/nes/ppu/ppu.cpp rename to bsnes/fc/ppu/ppu.cpp index d2f0f5d8..70b4c7d3 100755 --- a/bsnes/nes/ppu/ppu.cpp +++ b/bsnes/fc/ppu/ppu.cpp @@ -1,4 +1,4 @@ -#include +#include namespace Famicom { diff --git a/bsnes/nes/ppu/ppu.hpp b/bsnes/fc/ppu/ppu.hpp similarity index 100% rename from bsnes/nes/ppu/ppu.hpp rename to bsnes/fc/ppu/ppu.hpp diff --git a/bsnes/nes/ppu/serialization.cpp b/bsnes/fc/ppu/serialization.cpp similarity index 100% rename from bsnes/nes/ppu/serialization.cpp rename to bsnes/fc/ppu/serialization.cpp diff --git a/bsnes/nes/scheduler/scheduler.cpp b/bsnes/fc/scheduler/scheduler.cpp similarity index 94% rename from bsnes/nes/scheduler/scheduler.cpp rename to bsnes/fc/scheduler/scheduler.cpp index 51505843..ee565a26 100755 --- a/bsnes/nes/scheduler/scheduler.cpp +++ b/bsnes/fc/scheduler/scheduler.cpp @@ -1,4 +1,4 @@ -#include +#include namespace Famicom { diff --git a/bsnes/nes/scheduler/scheduler.hpp b/bsnes/fc/scheduler/scheduler.hpp similarity index 100% rename from bsnes/nes/scheduler/scheduler.hpp rename to bsnes/fc/scheduler/scheduler.hpp diff --git a/bsnes/nes/system/serialization.cpp b/bsnes/fc/system/serialization.cpp similarity index 76% rename from bsnes/nes/system/serialization.cpp rename to bsnes/fc/system/serialization.cpp index d22ab8f8..8db2dcc8 100755 --- a/bsnes/nes/system/serialization.cpp +++ b/bsnes/fc/system/serialization.cpp @@ -1,13 +1,14 @@ serializer System::serialize() { serializer s(serialize_size); - unsigned signature = 0x31545342, version = Info::SerializerVersion, crc32 = 0; - char description[512]; + unsigned signature = 0x31545342, version = Info::SerializerVersion; + char hash[64], description[512]; + memcpy(&hash, (const char*)cartridge.sha256(), 64); memset(&description, 0, sizeof description); s.integer(signature); s.integer(version); - s.integer(crc32); + s.array(hash); s.array(description); serialize_all(s); @@ -15,17 +16,16 @@ serializer System::serialize() { } bool System::unserialize(serializer &s) { - unsigned signature, version, crc32; - char description[512]; + unsigned signature, version; + char hash[64], description[512]; s.integer(signature); s.integer(version); - s.integer(crc32); + s.array(hash); s.array(description); if(signature != 0x31545342) return false; if(version != Info::SerializerVersion) return false; -//if(crc32 != 0) return false; power(); serialize_all(s); @@ -47,12 +47,12 @@ void System::serialize_all(serializer &s) { void System::serialize_init() { serializer s; - unsigned signature = 0, version = 0, crc32 = 0; - char description[512]; + unsigned signature = 0, version = 0; + char hash[64], description[512]; s.integer(signature); s.integer(version); - s.integer(crc32); + s.array(hash); s.array(description); serialize_all(s); diff --git a/bsnes/nes/system/system.cpp b/bsnes/fc/system/system.cpp similarity index 98% rename from bsnes/nes/system/system.cpp rename to bsnes/fc/system/system.cpp index 5fb91236..95639eea 100755 --- a/bsnes/nes/system/system.cpp +++ b/bsnes/fc/system/system.cpp @@ -1,4 +1,4 @@ -#include +#include namespace Famicom { diff --git a/bsnes/nes/system/system.hpp b/bsnes/fc/system/system.hpp similarity index 100% rename from bsnes/nes/system/system.hpp rename to bsnes/fc/system/system.hpp diff --git a/bsnes/nes/video/video.cpp b/bsnes/fc/video/video.cpp similarity index 98% rename from bsnes/nes/video/video.cpp rename to bsnes/fc/video/video.cpp index c3efba53..0da191b5 100755 --- a/bsnes/nes/video/video.cpp +++ b/bsnes/fc/video/video.cpp @@ -1,4 +1,4 @@ -#include +#include #define VIDEO_CPP namespace Famicom { diff --git a/bsnes/nes/video/video.hpp b/bsnes/fc/video/video.hpp similarity index 100% rename from bsnes/nes/video/video.hpp rename to bsnes/fc/video/video.hpp diff --git a/bsnes/gb/system/serialization.cpp b/bsnes/gb/system/serialization.cpp index 306f8274..88cfe6bf 100755 --- a/bsnes/gb/system/serialization.cpp +++ b/bsnes/gb/system/serialization.cpp @@ -3,13 +3,14 @@ serializer System::serialize() { serializer s(serialize_size); - unsigned signature = 0x31545342, version = Info::SerializerVersion, crc32 = 0; - char description[512]; + unsigned signature = 0x31545342, version = Info::SerializerVersion; + char hash[64], description[512]; + memcpy(&hash, (const char*)cartridge.sha256(), 64); memset(&description, 0, sizeof description); s.integer(signature); s.integer(version); - s.integer(crc32); + s.array(hash); s.array(description); serialize_all(s); @@ -17,17 +18,16 @@ serializer System::serialize() { } bool System::unserialize(serializer &s) { - unsigned signature, version, crc32; - char description[512]; + unsigned signature, version; + char hash[64], description[512]; s.integer(signature); s.integer(version); - s.integer(crc32); + s.array(hash); s.array(description); if(signature != 0x31545342) return false; if(version != Info::SerializerVersion) return false; -//if(crc32 != 0) return false; power(); serialize_all(s); @@ -50,11 +50,11 @@ void System::serialize_init() { serializer s; unsigned signature = 0, version = 0, crc32 = 0; - char description[512]; + char hash[64], description[512]; s.integer(signature); s.integer(version); - s.integer(crc32); + s.array(hash); s.array(description); serialize_all(s); diff --git a/bsnes/gba/cartridge/cartridge.cpp b/bsnes/gba/cartridge/cartridge.cpp index fd03ad6d..cf8e253e 100755 --- a/bsnes/gba/cartridge/cartridge.cpp +++ b/bsnes/gba/cartridge/cartridge.cpp @@ -100,18 +100,42 @@ void Cartridge::write(uint8 *data, uint32 addr, uint32 size, uint32 word) { } } +#define RAM_ANALYZE + uint32 Cartridge::read(uint32 addr, uint32 size) { + #ifdef RAM_ANALYZE + if((addr & 0x0e000000) == 0x0e000000) { + static bool once = true; + if(once) once = false, print("* SRAM/FlashROM read detected\n"); + } + #endif + if(has_sram && (addr & 0x0e000000 ) == 0x0e000000 ) return read(ram.data, addr & ram.mask, size); if(has_eeprom && (addr & eeprom.mask) == eeprom.test) return eeprom.read(); - if(has_flashrom && (addr & 0x0f000000 ) == 0x0e000000 ) return flashrom.read(addr); + if(has_flashrom && (addr & 0x0e000000 ) == 0x0e000000 ) return flashrom.read(addr); if(addr < 0x0e000000) return read(rom.data, addr & 0x01ffffff, size); return cpu.pipeline.fetch.instruction; } void Cartridge::write(uint32 addr, uint32 size, uint32 word) { + #ifdef RAM_ANALYZE + if((addr & 0x0e000000) == 0x0e000000) { + static bool once = true; + if(once) once = false, print("* SRAM/FlashROM write detected\n"); + } + if((addr & 0x0f000000) == 0x0d000000) { + static bool once = true; + if(once) once = false, print("* EEPROM write detected\n"); + } + if((addr & 0x0e00ffff) == 0x0e005555 && (word & 0xff) == 0xaa) { + static bool once = true; + if(once) once = false, print("* FlashROM write detected\n"); + } + #endif + if(has_sram && (addr & 0x0e000000 ) == 0x0e000000 ) return write(ram.data, addr & ram.mask, size, word); if(has_eeprom && (addr & eeprom.mask) == eeprom.test) return eeprom.write(word & 1); - if(has_flashrom && (addr & 0x0f000000 ) == 0x0e000000 ) return flashrom.write(addr, word); + if(has_flashrom && (addr & 0x0e000000 ) == 0x0e000000 ) return flashrom.write(addr, word); } Cartridge::Cartridge() { diff --git a/bsnes/gba/gba.hpp b/bsnes/gba/gba.hpp index e853a2d4..1cec507a 100755 --- a/bsnes/gba/gba.hpp +++ b/bsnes/gba/gba.hpp @@ -7,7 +7,7 @@ namespace GameBoyAdvance { namespace Info { static const char Name[] = "bgba"; - static const unsigned SerializerVersion = 1; + static const unsigned SerializerVersion = 2; } } diff --git a/bsnes/gba/system/serialization.cpp b/bsnes/gba/system/serialization.cpp index cd5f21bf..b553509b 100755 --- a/bsnes/gba/system/serialization.cpp +++ b/bsnes/gba/system/serialization.cpp @@ -1,13 +1,14 @@ serializer System::serialize() { serializer s(serialize_size); - unsigned signature = 0x31545342, version = Info::SerializerVersion, crc32 = 0; - char description[512]; + unsigned signature = 0x31545342, version = Info::SerializerVersion; + char hash[64], description[512]; + memcpy(&hash, (const char*)cartridge.sha256(), 64); memset(&description, 0, sizeof description); s.integer(signature); s.integer(version); - s.integer(crc32); + s.array(hash); s.array(description); serialize_all(s); @@ -15,17 +16,16 @@ serializer System::serialize() { } bool System::unserialize(serializer &s) { - unsigned signature, version, crc32; - char description[512]; + unsigned signature, version; + char hash[64], description[512]; s.integer(signature); s.integer(version); - s.integer(crc32); + s.array(hash); s.array(description); if(signature != 0x31545342) return false; if(version != Info::SerializerVersion) return false; -//if(crc32 != 0) return false; power(); serialize_all(s); @@ -49,12 +49,12 @@ void System::serialize_all(serializer &s) { void System::serialize_init() { serializer s; - unsigned signature = 0, version = 0, crc32 = 0; - char description[512]; + unsigned signature = 0, version = 0; + char hash[64], description[512]; s.integer(signature); s.integer(version); - s.integer(crc32); + s.array(hash); s.array(description); serialize_all(s); diff --git a/bsnes/nall/Makefile b/bsnes/nall/Makefile index c1437d14..e4b0fd1c 100755 --- a/bsnes/nall/Makefile +++ b/bsnes/nall/Makefile @@ -35,9 +35,9 @@ ifeq ($(compiler),) ifeq ($(platform),win) compiler := gcc else ifeq ($(platform),osx) - compiler := gcc-mp-4.6 + compiler := gcc-mp-4.7 else - compiler := gcc-4.6 + compiler := gcc-4.7 endif endif diff --git a/bsnes/nall/stream/file.hpp b/bsnes/nall/stream/file.hpp index 3fc45d33..1d559395 100755 --- a/bsnes/nall/stream/file.hpp +++ b/bsnes/nall/stream/file.hpp @@ -6,6 +6,9 @@ namespace nall { struct filestream : stream { + using stream::read; + using stream::write; + bool seekable() const { return true; } bool readable() const { return true; } bool writable() const { return pwritable; } diff --git a/bsnes/nall/stream/gzip.hpp b/bsnes/nall/stream/gzip.hpp index a6aecfff..0c270a72 100755 --- a/bsnes/nall/stream/gzip.hpp +++ b/bsnes/nall/stream/gzip.hpp @@ -6,6 +6,9 @@ namespace nall { struct gzipstream : memorystream { + using stream::read; + using stream::write; + gzipstream(const stream &stream) { unsigned size = stream.size(); uint8_t *data = new uint8_t[size]; diff --git a/bsnes/nall/stream/http.hpp b/bsnes/nall/stream/http.hpp index 63ed6efc..2f9e45dd 100755 --- a/bsnes/nall/stream/http.hpp +++ b/bsnes/nall/stream/http.hpp @@ -6,6 +6,9 @@ namespace nall { struct httpstream : stream { + using stream::read; + using stream::write; + bool seekable() const { return true; } bool readable() const { return true; } bool writable() const { return true; } diff --git a/bsnes/nall/stream/memory.hpp b/bsnes/nall/stream/memory.hpp index 4fdb5e69..cf49b3b2 100755 --- a/bsnes/nall/stream/memory.hpp +++ b/bsnes/nall/stream/memory.hpp @@ -6,6 +6,9 @@ namespace nall { struct memorystream : stream { + using stream::read; + using stream::write; + bool seekable() const { return true; } bool readable() const { return true; } bool writable() const { return pwritable; } diff --git a/bsnes/nall/stream/mmap.hpp b/bsnes/nall/stream/mmap.hpp index c204f469..784f2b35 100755 --- a/bsnes/nall/stream/mmap.hpp +++ b/bsnes/nall/stream/mmap.hpp @@ -6,6 +6,9 @@ namespace nall { struct mmapstream : stream { + using stream::read; + using stream::write; + bool seekable() const { return true; } bool readable() const { return true; } bool writable() const { return pwritable; } diff --git a/bsnes/nall/stream/stream.hpp b/bsnes/nall/stream/stream.hpp index 5cd65f8e..d2ef44c5 100755 --- a/bsnes/nall/stream/stream.hpp +++ b/bsnes/nall/stream/stream.hpp @@ -44,7 +44,7 @@ struct stream { return data; } - virtual void read(uint8_t *data, unsigned length) const { + void read(uint8_t *data, unsigned length) const { while(length--) *data++ = read(); } diff --git a/bsnes/nall/stream/vector.hpp b/bsnes/nall/stream/vector.hpp index 0fa78f7d..59f36c02 100755 --- a/bsnes/nall/stream/vector.hpp +++ b/bsnes/nall/stream/vector.hpp @@ -7,6 +7,9 @@ namespace nall { struct vectorstream : stream { + using stream::read; + using stream::write; + bool seekable() const { return true; } bool readable() const { return true; } bool writable() const { return pwritable; } diff --git a/bsnes/nall/stream/zip.hpp b/bsnes/nall/stream/zip.hpp index cad44380..b91b8604 100755 --- a/bsnes/nall/stream/zip.hpp +++ b/bsnes/nall/stream/zip.hpp @@ -6,6 +6,9 @@ namespace nall { struct zipstream : memorystream { + using stream::read; + using stream::write; + zipstream(const stream &stream, const string &filter = "*") { unsigned size = stream.size(); uint8_t *data = new uint8_t[size]; diff --git a/bsnes/nes/Makefile b/bsnes/nes/Makefile deleted file mode 100755 index ef680573..00000000 --- a/bsnes/nes/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -nes_objects := nes-interface nes-system nes-scheduler nes-input -nes_objects += nes-memory nes-cartridge nes-cpu nes-apu nes-ppu -nes_objects += nes-cheat nes-video -objects += $(nes_objects) - -obj/nes-interface.o: $(nes)/interface/interface.cpp $(call rwildcard,$(nes)/interface/) -obj/nes-system.o: $(nes)/system/system.cpp $(call rwildcard,$(nes)/system/) -obj/nes-scheduler.o: $(nes)/scheduler/scheduler.cpp $(call rwildcard,$(nes)/scheduler/) -obj/nes-input.o: $(nes)/input/input.cpp $(call rwildcard,$(nes)/input/) -obj/nes-memory.o: $(nes)/memory/memory.cpp $(call rwildcard,$(nes)/memory/) -obj/nes-cartridge.o: $(nes)/cartridge/cartridge.cpp $(call rwildcard,$(nes)/cartridge/) -obj/nes-cpu.o: $(nes)/cpu/cpu.cpp $(call rwildcard,$(nes)/cpu/) -obj/nes-apu.o: $(nes)/apu/apu.cpp $(call rwildcard,$(nes)/apu/) -obj/nes-ppu.o: $(nes)/ppu/ppu.cpp $(call rwildcard,$(nes)/ppu/) -obj/nes-cheat.o: $(nes)/cheat/cheat.cpp $(call rwildcard,$(nes)/cheat/) -obj/nes-video.o: $(nes)/video/video.cpp $(call rwildcard,$(nes)/video/) diff --git a/bsnes/processor/Makefile b/bsnes/processor/Makefile index 30ae8abc..28140ada 100755 --- a/bsnes/processor/Makefile +++ b/bsnes/processor/Makefile @@ -1,14 +1,20 @@ processor_objects := processor_objects += $(if $(findstring arm,$(processors)),processor-arm) +processor_objects += $(if $(findstring gsu,$(processors)),processor-gsu) processor_objects += $(if $(findstring hg51b,$(processors)),processor-hg51b) processor_objects += $(if $(findstring lr35902,$(processors)),processor-lr35902) -processor_objects += $(if $(findstring rp2a03,$(processors)),processor-rp2a03) +processor_objects += $(if $(findstring r6502,$(processors)),processor-r6502) +processor_objects += $(if $(findstring r65816,$(processors)),processor-r65816) +processor_objects += $(if $(findstring spc700,$(processors)),processor-spc700) processor_objects += $(if $(findstring upd96050,$(processors)),processor-upd96050) objects += $(processor_objects) processor := processor obj/processor-arm.o: $(processor)/arm/arm.cpp $(call rwildcard,$(processor)/arm) +obj/processor-gsu.o: $(processor)/gsu/gsu.cpp $(call rwildcard,$(processor)/gsu) obj/processor-hg51b.o: $(processor)/hg51b/hg51b.cpp $(call rwildcard,$(processor)/hg51b) obj/processor-lr35902.o: $(processor)/lr35902/lr35902.cpp $(call rwildcard,$(processor)/lr35902) -obj/processor-rp2a03.o: $(processor)/rp2a03/rp2a03.cpp $(call rwildcard,$(processor)/rp2a03) +obj/processor-r6502.o: $(processor)/r6502/r6502.cpp $(call rwildcard,$(processor)/r6502) +obj/processor-r65816.o: $(processor)/r65816/r65816.cpp $(call rwildcard,$(processor)/r65816) +obj/processor-spc700.o: $(processor)/spc700/spc700.cpp $(call rwildcard,$(processor)/spc700) obj/processor-upd96050.o: $(processor)/upd96050/upd96050.cpp $(call rwildcard,$(processor)/upd96050) diff --git a/bsnes/processor/gsu/gsu.cpp b/bsnes/processor/gsu/gsu.cpp new file mode 100755 index 00000000..a1233f72 --- /dev/null +++ b/bsnes/processor/gsu/gsu.cpp @@ -0,0 +1,33 @@ +#include +#include "gsu.hpp" + +namespace Processor { + +#include "instructions.cpp" +#include "table.cpp" +#include "serialization.cpp" + +void GSU::power() { +} + +void GSU::reset() { + for(auto &r : regs.r) r = 0x0000; + regs.sfr = 0x0000; + regs.pbr = 0x00; + regs.rombr = 0x00; + regs.rambr = 0; + regs.cbr = 0x0000; + regs.scbr = 0x00; + regs.scmr = 0x00; + regs.colr = 0x00; + regs.por = 0x00; + regs.bramr = 0; + regs.vcr = 0x04; + regs.cfgr = 0x00; + regs.clsr = 0; + regs.pipeline = 0x01; //nop + regs.ramaddr = 0x0000; + regs.reset(); +} + +} diff --git a/bsnes/processor/gsu/gsu.hpp b/bsnes/processor/gsu/gsu.hpp new file mode 100755 index 00000000..f847f125 --- /dev/null +++ b/bsnes/processor/gsu/gsu.hpp @@ -0,0 +1,118 @@ +#ifndef PROCESSOR_GSU_HPP +#define PROCESSOR_GSU_HPP + +namespace Processor { + +struct GSU { + #include "registers.hpp" + + virtual void step(unsigned clocks) = 0; + + virtual void stop() = 0; + virtual uint8 color(uint8 source) = 0; + virtual void plot(uint8 x, uint8 y) = 0; + virtual uint8 rpix(uint8 x, uint8 y) = 0; + + virtual uint8 pipe() = 0; + virtual void rombuffer_sync() = 0; + virtual uint8 rombuffer_read() = 0; + virtual void rambuffer_sync() = 0; + virtual uint8 rambuffer_read(uint16 addr) = 0; + virtual void rambuffer_write(uint16 addr, uint8 data) = 0; + virtual void cache_flush() = 0; + + void power(); + void reset(); + void serialize(serializer&); + + //table.cpp + void (GSU::*opcode_table[1024])(); + void initialize_opcode_table(); + + //instructions.cpp + template void op_adc_i(); + template void op_adc_r(); + template void op_add_i(); + template void op_add_r(); + void op_alt1(); + void op_alt2(); + void op_alt3(); + template void op_and_i(); + template void op_and_r(); + void op_asr(); + void op_bge(); + void op_bcc(); + void op_bcs(); + void op_beq(); + template void op_bic_i(); + template void op_bic_r(); + void op_blt(); + void op_bmi(); + void op_bne(); + void op_bpl(); + void op_bra(); + void op_bvc(); + void op_bvs(); + void op_cache(); + void op_cmode(); + template void op_cmp_r(); + void op_color(); + template void op_dec_r(); + void op_div2(); + void op_fmult(); + template void op_from_r(); + void op_getb(); + void op_getbl(); + void op_getbh(); + void op_getbs(); + void op_getc(); + void op_hib(); + template void op_ibt_r(); + template void op_inc_r(); + template void op_iwt_r(); + template void op_jmp_r(); + template void op_ldb_ir(); + template void op_ldw_ir(); + template void op_link(); + template void op_ljmp_r(); + template void op_lm_r(); + template void op_lms_r(); + void op_lmult(); + void op_lob(); + void op_loop(); + void op_lsr(); + void op_merge(); + template void op_mult_i(); + template void op_mult_r(); + void op_nop(); + void op_not(); + template void op_or_i(); + template void op_or_r(); + void op_plot(); + void op_ramb(); + void op_rol(); + void op_romb(); + void op_ror(); + void op_rpix(); + template void op_sbc_r(); + void op_sbk(); + void op_sex(); + template void op_sm_r(); + template void op_sms_r(); + template void op_stb_ir(); + void op_stop(); + template void op_stw_ir(); + template void op_sub_i(); + template void op_sub_r(); + void op_swap(); + template void op_to_r(); + template void op_umult_i(); + template void op_umult_r(); + template void op_with_r(); + template void op_xor_i(); + template void op_xor_r(); +}; + +} + +#endif diff --git a/bsnes/snes/chip/superfx/core/opcodes.cpp b/bsnes/processor/gsu/instructions.cpp similarity index 79% rename from bsnes/snes/chip/superfx/core/opcodes.cpp rename to bsnes/processor/gsu/instructions.cpp index 7d2f13a2..d6b20631 100755 --- a/bsnes/snes/chip/superfx/core/opcodes.cpp +++ b/bsnes/processor/gsu/instructions.cpp @@ -1,10 +1,8 @@ -#ifdef SUPERFX_CPP - //$00 stop -void SuperFX::op_stop() { +void GSU::op_stop() { if(regs.cfgr.irq == 0) { regs.sfr.irq = 1; - cpu.regs.irq = 1; + stop(); } regs.sfr.g = 0; @@ -13,12 +11,12 @@ void SuperFX::op_stop() { } //$01 nop -void SuperFX::op_nop() { +void GSU::op_nop() { regs.reset(); } //$02 cache -void SuperFX::op_cache() { +void GSU::op_cache() { if(regs.cbr != (regs.r[15] & 0xfff0)) { regs.cbr = regs.r[15] & 0xfff0; cache_flush(); @@ -27,7 +25,7 @@ void SuperFX::op_cache() { } //$03 lsr -void SuperFX::op_lsr() { +void GSU::op_lsr() { regs.sfr.cy = (regs.sr() & 1); regs.dr() = regs.sr() >> 1; regs.sfr.s = (regs.dr() & 0x8000); @@ -36,7 +34,7 @@ void SuperFX::op_lsr() { } //$04 rol -void SuperFX::op_rol() { +void GSU::op_rol() { bool carry = (regs.sr() & 0x8000); regs.dr() = (regs.sr() << 1) | regs.sfr.cy; regs.sfr.s = (regs.dr() & 0x8000); @@ -46,73 +44,73 @@ void SuperFX::op_rol() { } //$05 bra e -void SuperFX::op_bra() { +void GSU::op_bra() { regs.r[15] += (int8)pipe(); } //$06 blt e -void SuperFX::op_blt() { +void GSU::op_blt() { int e = (int8)pipe(); if((regs.sfr.s ^ regs.sfr.ov) == 0) regs.r[15] += e; } //$07 bge e -void SuperFX::op_bge() { +void GSU::op_bge() { int e = (int8)pipe(); if((regs.sfr.s ^ regs.sfr.ov) == 1) regs.r[15] += e; } //$08 bne e -void SuperFX::op_bne() { +void GSU::op_bne() { int e = (int8)pipe(); if(regs.sfr.z == 0) regs.r[15] += e; } //$09 beq e -void SuperFX::op_beq() { +void GSU::op_beq() { int e = (int8)pipe(); if(regs.sfr.z == 1) regs.r[15] += e; } //$0a bpl e -void SuperFX::op_bpl() { +void GSU::op_bpl() { int e = (int8)pipe(); if(regs.sfr.s == 0) regs.r[15] += e; } //$0b bmi e -void SuperFX::op_bmi() { +void GSU::op_bmi() { int e = (int8)pipe(); if(regs.sfr.s == 1) regs.r[15] += e; } //$0c bcc e -void SuperFX::op_bcc() { +void GSU::op_bcc() { int e = (int8)pipe(); if(regs.sfr.cy == 0) regs.r[15] += e; } //$0d bcs e -void SuperFX::op_bcs() { +void GSU::op_bcs() { int e = (int8)pipe(); if(regs.sfr.cy == 1) regs.r[15] += e; } //$0e bvc e -void SuperFX::op_bvc() { +void GSU::op_bvc() { int e = (int8)pipe(); if(regs.sfr.ov == 0) regs.r[15] += e; } //$0f bvs e -void SuperFX::op_bvs() { +void GSU::op_bvs() { int e = (int8)pipe(); if(regs.sfr.ov == 1) regs.r[15] += e; } //$10-1f(b0): to rN //$10-1f(b1): move rN -template void SuperFX::op_to_r() { +template void GSU::op_to_r() { if(regs.sfr.b == 0) { regs.dreg = n; } else { @@ -122,14 +120,14 @@ template void SuperFX::op_to_r() { } //$20-2f: with rN -template void SuperFX::op_with_r() { +template void GSU::op_with_r() { regs.sreg = n; regs.dreg = n; regs.sfr.b = 1; } //$30-3b(alt0): stw (rN) -template void SuperFX::op_stw_ir() { +template void GSU::op_stw_ir() { regs.ramaddr = regs.r[n]; rambuffer_write(regs.ramaddr ^ 0, regs.sr() >> 0); rambuffer_write(regs.ramaddr ^ 1, regs.sr() >> 8); @@ -137,14 +135,14 @@ template void SuperFX::op_stw_ir() { } //$30-3b(alt1): stb (rN) -template void SuperFX::op_stb_ir() { +template void GSU::op_stb_ir() { regs.ramaddr = regs.r[n]; rambuffer_write(regs.ramaddr, regs.sr()); regs.reset(); } //$3c loop -void SuperFX::op_loop() { +void GSU::op_loop() { regs.r[12]--; regs.sfr.s = (regs.r[12] & 0x8000); regs.sfr.z = (regs.r[12] == 0); @@ -153,26 +151,26 @@ void SuperFX::op_loop() { } //$3d alt1 -void SuperFX::op_alt1() { +void GSU::op_alt1() { regs.sfr.b = 0; regs.sfr.alt1 = 1; } //$3e alt2 -void SuperFX::op_alt2() { +void GSU::op_alt2() { regs.sfr.b = 0; regs.sfr.alt2 = 1; } //$3f alt3 -void SuperFX::op_alt3() { +void GSU::op_alt3() { regs.sfr.b = 0; regs.sfr.alt1 = 1; regs.sfr.alt2 = 1; } //$40-4b(alt0): ldw (rN) -template void SuperFX::op_ldw_ir() { +template void GSU::op_ldw_ir() { regs.ramaddr = regs.r[n]; uint16_t data; data = rambuffer_read(regs.ramaddr ^ 0) << 0; @@ -182,21 +180,21 @@ template void SuperFX::op_ldw_ir() { } //$40-4b(alt1): ldb (rN) -template void SuperFX::op_ldb_ir() { +template void GSU::op_ldb_ir() { regs.ramaddr = regs.r[n]; regs.dr() = rambuffer_read(regs.ramaddr); regs.reset(); } //$4c(alt0): plot -void SuperFX::op_plot() { +void GSU::op_plot() { plot(regs.r[1], regs.r[2]); regs.r[1]++; regs.reset(); } //$4c(alt1): rpix -void SuperFX::op_rpix() { +void GSU::op_rpix() { regs.dr() = rpix(regs.r[1], regs.r[2]); regs.sfr.s = (regs.dr() & 0x8000); regs.sfr.z = (regs.dr() == 0); @@ -204,7 +202,7 @@ void SuperFX::op_rpix() { } //$4d: swap -void SuperFX::op_swap() { +void GSU::op_swap() { regs.dr() = (regs.sr() >> 8) | (regs.sr() << 8); regs.sfr.s = (regs.dr() & 0x8000); regs.sfr.z = (regs.dr() == 0); @@ -212,19 +210,19 @@ void SuperFX::op_swap() { } //$4e(alt0): color -void SuperFX::op_color() { +void GSU::op_color() { regs.colr = color(regs.sr()); regs.reset(); } //$4e(alt1): cmode -void SuperFX::op_cmode() { +void GSU::op_cmode() { regs.por = regs.sr(); regs.reset(); } //$4f: not -void SuperFX::op_not() { +void GSU::op_not() { regs.dr() = ~regs.sr(); regs.sfr.s = (regs.dr() & 0x8000); regs.sfr.z = (regs.dr() == 0); @@ -232,7 +230,7 @@ void SuperFX::op_not() { } //$50-5f(alt0): add rN -template void SuperFX::op_add_r() { +template void GSU::op_add_r() { int r = regs.sr() + regs.r[n]; regs.sfr.ov = ~(regs.sr() ^ regs.r[n]) & (regs.r[n] ^ r) & 0x8000; regs.sfr.s = (r & 0x8000); @@ -243,7 +241,7 @@ template void SuperFX::op_add_r() { } //$50-5f(alt1): adc rN -template void SuperFX::op_adc_r() { +template void GSU::op_adc_r() { int r = regs.sr() + regs.r[n] + regs.sfr.cy; regs.sfr.ov = ~(regs.sr() ^ regs.r[n]) & (regs.r[n] ^ r) & 0x8000; regs.sfr.s = (r & 0x8000); @@ -254,7 +252,7 @@ template void SuperFX::op_adc_r() { } //$50-5f(alt2): add #N -template void SuperFX::op_add_i() { +template void GSU::op_add_i() { int r = regs.sr() + n; regs.sfr.ov = ~(regs.sr() ^ n) & (n ^ r) & 0x8000; regs.sfr.s = (r & 0x8000); @@ -265,7 +263,7 @@ template void SuperFX::op_add_i() { } //$50-5f(alt3): adc #N -template void SuperFX::op_adc_i() { +template void GSU::op_adc_i() { int r = regs.sr() + n + regs.sfr.cy; regs.sfr.ov = ~(regs.sr() ^ n) & (n ^ r) & 0x8000; regs.sfr.s = (r & 0x8000); @@ -276,7 +274,7 @@ template void SuperFX::op_adc_i() { } //$60-6f(alt0): sub rN -template void SuperFX::op_sub_r() { +template void GSU::op_sub_r() { int r = regs.sr() - regs.r[n]; regs.sfr.ov = (regs.sr() ^ regs.r[n]) & (regs.sr() ^ r) & 0x8000; regs.sfr.s = (r & 0x8000); @@ -287,7 +285,7 @@ template void SuperFX::op_sub_r() { } //$60-6f(alt1): sbc rN -template void SuperFX::op_sbc_r() { +template void GSU::op_sbc_r() { int r = regs.sr() - regs.r[n] - !regs.sfr.cy; regs.sfr.ov = (regs.sr() ^ regs.r[n]) & (regs.sr() ^ r) & 0x8000; regs.sfr.s = (r & 0x8000); @@ -298,7 +296,7 @@ template void SuperFX::op_sbc_r() { } //$60-6f(alt2): sub #N -template void SuperFX::op_sub_i() { +template void GSU::op_sub_i() { int r = regs.sr() - n; regs.sfr.ov = (regs.sr() ^ n) & (regs.sr() ^ r) & 0x8000; regs.sfr.s = (r & 0x8000); @@ -309,7 +307,7 @@ template void SuperFX::op_sub_i() { } //$60-6f(alt3): cmp rN -template void SuperFX::op_cmp_r() { +template void GSU::op_cmp_r() { int r = regs.sr() - regs.r[n]; regs.sfr.ov = (regs.sr() ^ regs.r[n]) & (regs.sr() ^ r) & 0x8000; regs.sfr.s = (r & 0x8000); @@ -319,7 +317,7 @@ template void SuperFX::op_cmp_r() { } //$70: merge -void SuperFX::op_merge() { +void GSU::op_merge() { regs.dr() = (regs.r[7] & 0xff00) | (regs.r[8] >> 8); regs.sfr.ov = (regs.dr() & 0xc0c0); regs.sfr.s = (regs.dr() & 0x8080); @@ -329,7 +327,7 @@ void SuperFX::op_merge() { } //$71-7f(alt0): and rN -template void SuperFX::op_and_r() { +template void GSU::op_and_r() { regs.dr() = regs.sr() & regs.r[n]; regs.sfr.s = (regs.dr() & 0x8000); regs.sfr.z = (regs.dr() == 0); @@ -337,7 +335,7 @@ template void SuperFX::op_and_r() { } //$71-7f(alt1): bic rN -template void SuperFX::op_bic_r() { +template void GSU::op_bic_r() { regs.dr() = regs.sr() & ~regs.r[n]; regs.sfr.s = (regs.dr() & 0x8000); regs.sfr.z = (regs.dr() == 0); @@ -345,7 +343,7 @@ template void SuperFX::op_bic_r() { } //$71-7f(alt2): and #N -template void SuperFX::op_and_i() { +template void GSU::op_and_i() { regs.dr() = regs.sr() & n; regs.sfr.s = (regs.dr() & 0x8000); regs.sfr.z = (regs.dr() == 0); @@ -353,7 +351,7 @@ template void SuperFX::op_and_i() { } //$71-7f(alt3): bic #N -template void SuperFX::op_bic_i() { +template void GSU::op_bic_i() { regs.dr() = regs.sr() & ~n; regs.sfr.s = (regs.dr() & 0x8000); regs.sfr.z = (regs.dr() == 0); @@ -361,56 +359,56 @@ template void SuperFX::op_bic_i() { } //$80-8f(alt0): mult rN -template void SuperFX::op_mult_r() { +template void GSU::op_mult_r() { regs.dr() = (int8)regs.sr() * (int8)regs.r[n]; regs.sfr.s = (regs.dr() & 0x8000); regs.sfr.z = (regs.dr() == 0); regs.reset(); - if(!regs.cfgr.ms0) add_clocks(2); + if(!regs.cfgr.ms0) step(2); } //$80-8f(alt1): umult rN -template void SuperFX::op_umult_r() { +template void GSU::op_umult_r() { regs.dr() = (uint8)regs.sr() * (uint8)regs.r[n]; regs.sfr.s = (regs.dr() & 0x8000); regs.sfr.z = (regs.dr() == 0); regs.reset(); - if(!regs.cfgr.ms0) add_clocks(2); + if(!regs.cfgr.ms0) step(2); } //$80-8f(alt2): mult #N -template void SuperFX::op_mult_i() { +template void GSU::op_mult_i() { regs.dr() = (int8)regs.sr() * (int8)n; regs.sfr.s = (regs.dr() & 0x8000); regs.sfr.z = (regs.dr() == 0); regs.reset(); - if(!regs.cfgr.ms0) add_clocks(2); + if(!regs.cfgr.ms0) step(2); } //$80-8f(alt3): umult #N -template void SuperFX::op_umult_i() { +template void GSU::op_umult_i() { regs.dr() = (uint8)regs.sr() * (uint8)n; regs.sfr.s = (regs.dr() & 0x8000); regs.sfr.z = (regs.dr() == 0); regs.reset(); - if(!regs.cfgr.ms0) add_clocks(2); + if(!regs.cfgr.ms0) step(2); } //$90: sbk -void SuperFX::op_sbk() { +void GSU::op_sbk() { rambuffer_write(regs.ramaddr ^ 0, regs.sr() >> 0); rambuffer_write(regs.ramaddr ^ 1, regs.sr() >> 8); regs.reset(); } //$91-94: link #N -template void SuperFX::op_link() { +template void GSU::op_link() { regs.r[11] = regs.r[15] + n; regs.reset(); } //$95: sex -void SuperFX::op_sex() { +void GSU::op_sex() { regs.dr() = (int8)regs.sr(); regs.sfr.s = (regs.dr() & 0x8000); regs.sfr.z = (regs.dr() == 0); @@ -418,7 +416,7 @@ void SuperFX::op_sex() { } //$96(alt0): asr -void SuperFX::op_asr() { +void GSU::op_asr() { regs.sfr.cy = (regs.sr() & 1); regs.dr() = (int16_t)regs.sr() >> 1; regs.sfr.s = (regs.dr() & 0x8000); @@ -427,7 +425,7 @@ void SuperFX::op_asr() { } //$96(alt1): div2 -void SuperFX::op_div2() { +void GSU::op_div2() { regs.sfr.cy = (regs.sr() & 1); regs.dr() = ((int16_t)regs.sr() >> 1) + ((regs.sr() + 1) >> 16); regs.sfr.s = (regs.dr() & 0x8000); @@ -436,7 +434,7 @@ void SuperFX::op_div2() { } //$97: ror -void SuperFX::op_ror() { +void GSU::op_ror() { bool carry = (regs.sr() & 1); regs.dr() = (regs.sfr.cy << 15) | (regs.sr() >> 1); regs.sfr.s = (regs.dr() & 0x8000); @@ -446,13 +444,13 @@ void SuperFX::op_ror() { } //$98-9d(alt0): jmp rN -template void SuperFX::op_jmp_r() { +template void GSU::op_jmp_r() { regs.r[15] = regs.r[n]; regs.reset(); } //$98-9d(alt1): ljmp rN -template void SuperFX::op_ljmp_r() { +template void GSU::op_ljmp_r() { regs.pbr = regs.r[n] & 0x7f; regs.r[15] = regs.sr(); regs.cbr = regs.r[15] & 0xfff0; @@ -461,7 +459,7 @@ template void SuperFX::op_ljmp_r() { } //$9e: lob -void SuperFX::op_lob() { +void GSU::op_lob() { regs.dr() = regs.sr() & 0xff; regs.sfr.s = (regs.dr() & 0x80); regs.sfr.z = (regs.dr() == 0); @@ -469,18 +467,18 @@ void SuperFX::op_lob() { } //$9f(alt0): fmult -void SuperFX::op_fmult() { +void GSU::op_fmult() { uint32_t result = (int16_t)regs.sr() * (int16_t)regs.r[6]; regs.dr() = result >> 16; regs.sfr.s = (regs.dr() & 0x8000); regs.sfr.cy = (result & 0x8000); regs.sfr.z = (regs.dr() == 0); regs.reset(); - add_clocks(4 + (regs.cfgr.ms0 << 2)); + step(4 + (regs.cfgr.ms0 << 2)); } //$9f(alt1): lmult -void SuperFX::op_lmult() { +void GSU::op_lmult() { uint32_t result = (int16_t)regs.sr() * (int16_t)regs.r[6]; regs.r[4] = result; regs.dr() = result >> 16; @@ -488,17 +486,17 @@ void SuperFX::op_lmult() { regs.sfr.cy = (result & 0x8000); regs.sfr.z = (regs.dr() == 0); regs.reset(); - add_clocks(4 + (regs.cfgr.ms0 << 2)); + step(4 + (regs.cfgr.ms0 << 2)); } //$a0-af(alt0): ibt rN,#pp -template void SuperFX::op_ibt_r() { +template void GSU::op_ibt_r() { regs.r[n] = (int8)pipe(); regs.reset(); } //$a0-af(alt1): lms rN,(yy) -template void SuperFX::op_lms_r() { +template void GSU::op_lms_r() { regs.ramaddr = pipe() << 1; uint16_t data; data = rambuffer_read(regs.ramaddr ^ 0) << 0; @@ -508,7 +506,7 @@ template void SuperFX::op_lms_r() { } //$a0-af(alt2): sms (yy),rN -template void SuperFX::op_sms_r() { +template void GSU::op_sms_r() { regs.ramaddr = pipe() << 1; rambuffer_write(regs.ramaddr ^ 0, regs.r[n] >> 0); rambuffer_write(regs.ramaddr ^ 1, regs.r[n] >> 8); @@ -517,7 +515,7 @@ template void SuperFX::op_sms_r() { //$b0-bf(b0): from rN //$b0-bf(b1): moves rN -template void SuperFX::op_from_r() { +template void GSU::op_from_r() { if(regs.sfr.b == 0) { regs.sreg = n; } else { @@ -530,7 +528,7 @@ template void SuperFX::op_from_r() { } //$c0: hib -void SuperFX::op_hib() { +void GSU::op_hib() { regs.dr() = regs.sr() >> 8; regs.sfr.s = (regs.dr() & 0x80); regs.sfr.z = (regs.dr() == 0); @@ -538,7 +536,7 @@ void SuperFX::op_hib() { } //$c1-cf(alt0): or rN -template void SuperFX::op_or_r() { +template void GSU::op_or_r() { regs.dr() = regs.sr() | regs.r[n]; regs.sfr.s = (regs.dr() & 0x8000); regs.sfr.z = (regs.dr() == 0); @@ -546,7 +544,7 @@ template void SuperFX::op_or_r() { } //$c1-cf(alt1): xor rN -template void SuperFX::op_xor_r() { +template void GSU::op_xor_r() { regs.dr() = regs.sr() ^ regs.r[n]; regs.sfr.s = (regs.dr() & 0x8000); regs.sfr.z = (regs.dr() == 0); @@ -554,7 +552,7 @@ template void SuperFX::op_xor_r() { } //$c1-cf(alt2): or #N -template void SuperFX::op_or_i() { +template void GSU::op_or_i() { regs.dr() = regs.sr() | n; regs.sfr.s = (regs.dr() & 0x8000); regs.sfr.z = (regs.dr() == 0); @@ -562,7 +560,7 @@ template void SuperFX::op_or_i() { } //$c1-cf(alt3): xor #N -template void SuperFX::op_xor_i() { +template void GSU::op_xor_i() { regs.dr() = regs.sr() ^ n; regs.sfr.s = (regs.dr() & 0x8000); regs.sfr.z = (regs.dr() == 0); @@ -570,7 +568,7 @@ template void SuperFX::op_xor_i() { } //$d0-de: inc rN -template void SuperFX::op_inc_r() { +template void GSU::op_inc_r() { regs.r[n]++; regs.sfr.s = (regs.r[n] & 0x8000); regs.sfr.z = (regs.r[n] == 0); @@ -578,27 +576,27 @@ template void SuperFX::op_inc_r() { } //$df(alt0): getc -void SuperFX::op_getc() { +void GSU::op_getc() { regs.colr = color(rombuffer_read()); regs.reset(); } //$df(alt2): ramb -void SuperFX::op_ramb() { +void GSU::op_ramb() { rambuffer_sync(); regs.rambr = regs.sr(); regs.reset(); } //$df(alt3): romb -void SuperFX::op_romb() { +void GSU::op_romb() { rombuffer_sync(); regs.rombr = regs.sr() & 0x7f; regs.reset(); } //$e0-ee: dec rN -template void SuperFX::op_dec_r() { +template void GSU::op_dec_r() { regs.r[n]--; regs.sfr.s = (regs.r[n] & 0x8000); regs.sfr.z = (regs.r[n] == 0); @@ -606,31 +604,31 @@ template void SuperFX::op_dec_r() { } //$ef(alt0): getb -void SuperFX::op_getb() { +void GSU::op_getb() { regs.dr() = rombuffer_read(); regs.reset(); } //$ef(alt1): getbh -void SuperFX::op_getbh() { +void GSU::op_getbh() { regs.dr() = (rombuffer_read() << 8) | (regs.sr() & 0x00ff); regs.reset(); } //$ef(alt2): getbl -void SuperFX::op_getbl() { +void GSU::op_getbl() { regs.dr() = (regs.sr() & 0xff00) | (rombuffer_read() << 0); regs.reset(); } //$ef(alt3): getbs -void SuperFX::op_getbs() { +void GSU::op_getbs() { regs.dr() = (int8)rombuffer_read(); regs.reset(); } //$f0-ff(alt0): iwt rN,#xx -template void SuperFX::op_iwt_r() { +template void GSU::op_iwt_r() { uint16_t data; data = pipe() << 0; data |= pipe() << 8; @@ -639,7 +637,7 @@ template void SuperFX::op_iwt_r() { } //$f0-ff(alt1): lm rN,(xx) -template void SuperFX::op_lm_r() { +template void GSU::op_lm_r() { regs.ramaddr = pipe() << 0; regs.ramaddr |= pipe() << 8; uint16_t data; @@ -650,12 +648,10 @@ template void SuperFX::op_lm_r() { } //$f0-ff(alt2): sm (xx),rN -template void SuperFX::op_sm_r() { +template void GSU::op_sm_r() { regs.ramaddr = pipe() << 0; regs.ramaddr |= pipe() << 8; rambuffer_write(regs.ramaddr ^ 0, regs.r[n] >> 0); rambuffer_write(regs.ramaddr ^ 1, regs.r[n] >> 8); regs.reset(); } - -#endif diff --git a/bsnes/snes/chip/superfx/core/registers.hpp b/bsnes/processor/gsu/registers.hpp similarity index 98% rename from bsnes/snes/chip/superfx/core/registers.hpp rename to bsnes/processor/gsu/registers.hpp index ac193a8a..070bf729 100755 --- a/bsnes/snes/chip/superfx/core/registers.hpp +++ b/bsnes/processor/gsu/registers.hpp @@ -1,11 +1,11 @@ //accepts a callback binding so r14 writes can trigger ROM buffering transparently struct reg16_t { uint16 data; - function on_modify; + function modify; inline operator unsigned() const { return data; } inline uint16 assign(uint16 i) { - if(on_modify) on_modify(i); + if(modify) modify(i); else data = i; return data; } diff --git a/bsnes/snes/chip/superfx/serialization.cpp b/bsnes/processor/gsu/serialization.cpp similarity index 85% rename from bsnes/snes/chip/superfx/serialization.cpp rename to bsnes/processor/gsu/serialization.cpp index 0ee45ff9..86bfa1bf 100755 --- a/bsnes/snes/chip/superfx/serialization.cpp +++ b/bsnes/processor/gsu/serialization.cpp @@ -1,13 +1,4 @@ -#ifdef SUPERFX_CPP - -void SuperFX::serialize(serializer &s) { - Thread::serialize(s); - - //superfx.hpp - s.integer(clockmode); - s.integer(instruction_counter); - - //core/registers.hpp +void GSU::serialize(serializer &s) { s.integer(regs.pipeline); s.integer(regs.ramaddr); @@ -86,11 +77,4 @@ void SuperFX::serialize(serializer &s) { s.integer(pixelcache[i].bitpend); s.array(pixelcache[i].data); } - - //timing/timing.hpp - s.integer(cache_access_speed); - s.integer(memory_access_speed); - s.integer(r15_modified); } - -#endif diff --git a/bsnes/snes/chip/superfx/core/opcode_table.cpp b/bsnes/processor/gsu/table.cpp similarity index 94% rename from bsnes/snes/chip/superfx/core/opcode_table.cpp rename to bsnes/processor/gsu/table.cpp index 79082531..7d3c96b9 100755 --- a/bsnes/snes/chip/superfx/core/opcode_table.cpp +++ b/bsnes/processor/gsu/table.cpp @@ -1,6 +1,4 @@ -#ifdef SUPERFX_CPP - -void SuperFX::initialize_opcode_table() { +void GSU::initialize_opcode_table() { #define op4(id, name) \ op(id+ 0, name< 1>) op(id+ 1, name< 2>) op(id+ 2, name< 3>) op(id+ 3, name< 4>) @@ -35,7 +33,7 @@ void SuperFX::initialize_opcode_table() { // ALT0 //====== - #define op(id, name) opcode_table[ 0 + id] = &SuperFX::op_##name; + #define op(id, name) opcode_table[ 0 + id] = &GSU::op_##name; op (0x00, stop) op (0x01, nop) op (0x02, cache) @@ -92,7 +90,7 @@ void SuperFX::initialize_opcode_table() { // ALT1 //====== - #define op(id, name) opcode_table[256 + id] = &SuperFX::op_##name; + #define op(id, name) opcode_table[256 + id] = &GSU::op_##name; op (0x00, stop) op (0x01, nop) op (0x02, cache) @@ -149,7 +147,7 @@ void SuperFX::initialize_opcode_table() { // ALT2 //====== - #define op(id, name) opcode_table[512 + id] = &SuperFX::op_##name; + #define op(id, name) opcode_table[512 + id] = &GSU::op_##name; op (0x00, stop) op (0x01, nop) op (0x02, cache) @@ -206,7 +204,7 @@ void SuperFX::initialize_opcode_table() { // ALT3 //====== - #define op(id, name) opcode_table[768 + id] = &SuperFX::op_##name; + #define op(id, name) opcode_table[768 + id] = &GSU::op_##name; op (0x00, stop) op (0x01, nop) op (0x02, cache) @@ -266,5 +264,3 @@ void SuperFX::initialize_opcode_table() { #undef op15h #undef op16 } - -#endif diff --git a/bsnes/processor/rp2a03/disassembler.cpp b/bsnes/processor/r6502/disassembler.cpp similarity index 99% rename from bsnes/processor/rp2a03/disassembler.cpp rename to bsnes/processor/r6502/disassembler.cpp index ddfe04b4..2537e063 100755 --- a/bsnes/processor/rp2a03/disassembler.cpp +++ b/bsnes/processor/r6502/disassembler.cpp @@ -1,4 +1,4 @@ -string RP2A03::disassemble() { +string R6502::disassemble() { string output = { hex<4>(regs.pc), " " }; auto abs = [&]() -> string { return { "$", hex<2>(debugger_read(regs.pc + 2)), hex<2>(debugger_read(regs.pc + 1)) }; }; diff --git a/bsnes/processor/rp2a03/instructions.cpp b/bsnes/processor/r6502/instructions.cpp similarity index 71% rename from bsnes/processor/rp2a03/instructions.cpp rename to bsnes/processor/r6502/instructions.cpp index aaab14ae..73e3c5b7 100755 --- a/bsnes/processor/rp2a03/instructions.cpp +++ b/bsnes/processor/r6502/instructions.cpp @@ -1,7 +1,7 @@ //opcode functions //================ -void RP2A03::opf_adc() { +void R6502::opf_adc() { signed result = regs.a + rd + regs.p.c; regs.p.v = ~(regs.a ^ rd) & (regs.a ^ result) & 0x80; regs.p.c = (result > 0xff); @@ -10,96 +10,96 @@ void RP2A03::opf_adc() { regs.a = result; } -void RP2A03::opf_and() { +void R6502::opf_and() { regs.a &= rd; regs.p.n = (regs.a & 0x80); regs.p.z = (regs.a == 0); } -void RP2A03::opf_asl() { +void R6502::opf_asl() { regs.p.c = rd & 0x80; rd <<= 1; regs.p.n = (rd & 0x80); regs.p.z = (rd == 0); } -void RP2A03::opf_bit() { +void R6502::opf_bit() { regs.p.n = (rd & 0x80); regs.p.v = (rd & 0x40); regs.p.z = ((rd & regs.a) == 0); } -void RP2A03::opf_cmp() { +void R6502::opf_cmp() { signed r = regs.a - rd; regs.p.n = (r & 0x80); regs.p.z = (uint8)(r == 0); regs.p.c = (r >= 0); } -void RP2A03::opf_cpx() { +void R6502::opf_cpx() { signed r = regs.x - rd; regs.p.n = (r & 0x80); regs.p.z = (uint8)(r == 0); regs.p.c = (r >= 0); } -void RP2A03::opf_cpy() { +void R6502::opf_cpy() { signed r = regs.y - rd; regs.p.n = (r & 0x80); regs.p.z = (uint8)(r == 0); regs.p.c = (r >= 0); } -void RP2A03::opf_dec() { +void R6502::opf_dec() { rd--; regs.p.n = (rd & 0x80); regs.p.z = (rd == 0); } -void RP2A03::opf_eor() { +void R6502::opf_eor() { regs.a ^= rd; regs.p.n = (regs.a & 0x80); regs.p.z = (regs.a == 0); } -void RP2A03::opf_inc() { +void R6502::opf_inc() { rd++; regs.p.n = (rd & 0x80); regs.p.z = (rd == 0); } -void RP2A03::opf_lda() { +void R6502::opf_lda() { regs.a = rd; regs.p.n = (regs.a & 0x80); regs.p.z = (regs.a == 0); } -void RP2A03::opf_ldx() { +void R6502::opf_ldx() { regs.x = rd; regs.p.n = (regs.x & 0x80); regs.p.z = (regs.x == 0); } -void RP2A03::opf_ldy() { +void R6502::opf_ldy() { regs.y = rd; regs.p.n = (regs.y & 0x80); regs.p.z = (regs.y == 0); } -void RP2A03::opf_lsr() { +void R6502::opf_lsr() { regs.p.c = rd & 0x01; rd >>= 1; regs.p.n = (rd & 0x80); regs.p.z = (rd == 0); } -void RP2A03::opf_ora() { +void R6502::opf_ora() { regs.a |= rd; regs.p.n = (regs.a & 0x80); regs.p.z = (regs.a == 0); } -void RP2A03::opf_rla() { +void R6502::opf_rla() { unsigned carry = (unsigned)regs.p.c; regs.p.c = regs.a & 0x80; regs.a = (regs.a << 1) | carry; @@ -107,7 +107,7 @@ void RP2A03::opf_rla() { regs.p.z = (regs.a == 0); } -void RP2A03::opf_rol() { +void R6502::opf_rol() { unsigned carry = (unsigned)regs.p.c; regs.p.c = rd & 0x80; rd = (rd << 1) | carry; @@ -115,7 +115,7 @@ void RP2A03::opf_rol() { regs.p.z = (rd == 0); } -void RP2A03::opf_ror() { +void R6502::opf_ror() { unsigned carry = (unsigned)regs.p.c << 7; regs.p.c = rd & 0x01; rd = carry | (rd >> 1); @@ -123,7 +123,7 @@ void RP2A03::opf_ror() { regs.p.z = (rd == 0); } -void RP2A03::opf_rra() { +void R6502::opf_rra() { unsigned carry = (unsigned)regs.p.c << 7; regs.p.c = regs.a & 0x01; regs.a = carry | (regs.a >> 1); @@ -131,19 +131,19 @@ void RP2A03::opf_rra() { regs.p.z = (regs.a == 0); } -void RP2A03::opf_sbc() { +void R6502::opf_sbc() { rd ^= 0xff; return opf_adc(); } -void RP2A03::opf_sla() { +void R6502::opf_sla() { regs.p.c = regs.a & 0x80; regs.a <<= 1; regs.p.n = (regs.a & 0x80); regs.p.z = (regs.a == 0); } -void RP2A03::opf_sra() { +void R6502::opf_sra() { regs.p.c = regs.a & 0x01; regs.a >>= 1; regs.p.n = (regs.a & 0x80); @@ -153,7 +153,7 @@ void RP2A03::opf_sra() { //opcode implementations //====================== -void RP2A03::opi_branch(bool condition) { +void R6502::opi_branch(bool condition) { if(condition == false) { L rd = op_readpci(); } else { @@ -165,26 +165,26 @@ L op_readpc(); } } -void RP2A03::opi_clear_flag(bool &flag) { +void R6502::opi_clear_flag(bool &flag) { L op_readpc(); flag = 0; } -void RP2A03::opi_decrement(uint8 &r) { +void R6502::opi_decrement(uint8 &r) { L op_readpc(); r--; regs.p.n = (r & 0x80); regs.p.z = (r == 0); } -void RP2A03::opi_increment(uint8 &r) { +void R6502::opi_increment(uint8 &r) { L op_readpc(); r++; regs.p.n = (r & 0x80); regs.p.z = (r == 0); } -void RP2A03::opi_pull(uint8 &r) { +void R6502::opi_pull(uint8 &r) { op_readpc(); op_readpc(); L r = op_readsp(); @@ -192,21 +192,21 @@ L r = op_readsp(); regs.p.z = (r == 0); } -void RP2A03::opi_push(uint8 &r) { +void R6502::opi_push(uint8 &r) { op_readpc(); L op_writesp(r); } -template -void RP2A03::opi_read_absolute() { +template +void R6502::opi_read_absolute() { abs.l = op_readpci(); abs.h = op_readpci(); L rd = op_read(abs.w); call(op); } -template -void RP2A03::opi_read_absolute_x() { +template +void R6502::opi_read_absolute_x() { abs.l = op_readpci(); abs.h = op_readpci(); op_page(abs.w, abs.w + regs.x); @@ -214,8 +214,8 @@ L rd = op_read(abs.w + regs.x); call(op); } -template -void RP2A03::opi_read_absolute_y() { +template +void R6502::opi_read_absolute_y() { abs.l = op_readpci(); abs.h = op_readpci(); op_page(abs.w, abs.w + regs.y); @@ -223,14 +223,14 @@ L rd = op_read(abs.w + regs.y); call(op); } -template -void RP2A03::opi_read_immediate() { +template +void R6502::opi_read_immediate() { L rd = op_readpci(); call(op); } -template -void RP2A03::opi_read_indirect_zero_page_x() { +template +void R6502::opi_read_indirect_zero_page_x() { zp = op_readpci(); op_readzp(zp); abs.l = op_readzp(zp++ + regs.x); @@ -239,8 +239,8 @@ L rd = op_read(abs.w); call(op); } -template -void RP2A03::opi_read_indirect_zero_page_y() { +template +void R6502::opi_read_indirect_zero_page_y() { rd = op_readpci(); abs.l = op_readzp(rd++); abs.h = op_readzp(rd++); @@ -249,31 +249,31 @@ L rd = op_read(abs.w + regs.y); call(op); } -template -void RP2A03::opi_read_zero_page() { +template +void R6502::opi_read_zero_page() { zp = op_readpci(); L rd = op_readzp(zp); call(op); } -template -void RP2A03::opi_read_zero_page_x() { +template +void R6502::opi_read_zero_page_x() { zp = op_readpci(); op_readzp(zp); L rd = op_readzp(zp + regs.x); call(op); } -template -void RP2A03::opi_read_zero_page_y() { +template +void R6502::opi_read_zero_page_y() { zp = op_readpci(); op_readzp(zp); L rd = op_readzp(zp + regs.y); call(op); } -template -void RP2A03::opi_rmw_absolute() { +template +void R6502::opi_rmw_absolute() { abs.l = op_readpci(); abs.h = op_readpci(); rd = op_read(abs.w); @@ -282,8 +282,8 @@ void RP2A03::opi_rmw_absolute() { L op_write(abs.w, rd); } -template -void RP2A03::opi_rmw_absolute_x() { +template +void R6502::opi_rmw_absolute_x() { abs.l = op_readpci(); abs.h = op_readpci(); op_page_always(abs.w, abs.w + regs.x); @@ -293,8 +293,8 @@ void RP2A03::opi_rmw_absolute_x() { L op_write(abs.w + regs.x, rd); } -template -void RP2A03::opi_rmw_zero_page() { +template +void R6502::opi_rmw_zero_page() { zp = op_readpci(); rd = op_readzp(zp); op_writezp(zp, rd); @@ -302,8 +302,8 @@ void RP2A03::opi_rmw_zero_page() { L op_writezp(zp, rd); } -template -void RP2A03::opi_rmw_zero_page_x() { +template +void R6502::opi_rmw_zero_page_x() { zp = op_readpci(); op_readzp(zp); rd = op_readzp(zp + regs.x); @@ -312,38 +312,38 @@ void RP2A03::opi_rmw_zero_page_x() { L op_writezp(zp + regs.x, rd); } -void RP2A03::opi_set_flag(bool &flag) { +void R6502::opi_set_flag(bool &flag) { L op_readpc(); flag = 1; } -template -void RP2A03::opi_shift() { +template +void R6502::opi_shift() { L op_readpc(); call(op); } -void RP2A03::opi_store_absolute(uint8 &r) { +void R6502::opi_store_absolute(uint8 &r) { abs.l = op_readpci(); abs.h = op_readpci(); L op_write(abs.w, r); } -void RP2A03::opi_store_absolute_x(uint8 &r) { +void R6502::opi_store_absolute_x(uint8 &r) { abs.l = op_readpci(); abs.h = op_readpci(); op_page_always(abs.w, abs.w + regs.x); L op_write(abs.w + regs.x, r); } -void RP2A03::opi_store_absolute_y(uint8 &r) { +void R6502::opi_store_absolute_y(uint8 &r) { abs.l = op_readpci(); abs.h = op_readpci(); op_page_always(abs.w, abs.w + regs.y); L op_write(abs.w + regs.y, r); } -void RP2A03::opi_store_indirect_zero_page_x(uint8 &r) { +void R6502::opi_store_indirect_zero_page_x(uint8 &r) { zp = op_readpci(); op_readzp(zp); abs.l = op_readzp(zp++ + regs.x); @@ -351,7 +351,7 @@ void RP2A03::opi_store_indirect_zero_page_x(uint8 &r) { L op_write(abs.w, r); } -void RP2A03::opi_store_indirect_zero_page_y(uint8 &r) { +void R6502::opi_store_indirect_zero_page_y(uint8 &r) { rd = op_readpci(); abs.l = op_readzp(rd++); abs.h = op_readzp(rd++); @@ -359,24 +359,24 @@ void RP2A03::opi_store_indirect_zero_page_y(uint8 &r) { L op_write(abs.w + regs.y, r); } -void RP2A03::opi_store_zero_page(uint8 &r) { +void R6502::opi_store_zero_page(uint8 &r) { zp = op_readpci(); L op_writezp(zp, r); } -void RP2A03::opi_store_zero_page_x(uint8 &r) { +void R6502::opi_store_zero_page_x(uint8 &r) { zp = op_readpci(); op_readzp(zp); L op_writezp(zp + regs.x, r); } -void RP2A03::opi_store_zero_page_y(uint8 &r) { +void R6502::opi_store_zero_page_y(uint8 &r) { zp = op_readpci(); op_readzp(zp); L op_writezp(zp + regs.y, r); } -void RP2A03::opi_transfer(uint8 &s, uint8 &d, bool flag) { +void R6502::opi_transfer(uint8 &s, uint8 &d, bool flag) { L op_readpc(); d = s; if(flag == false) return; @@ -387,7 +387,7 @@ L op_readpc(); //opcodes //======= -void RP2A03::op_brk() { +void R6502::op_brk() { op_readpci(); op_writesp(regs.pc >> 8); op_writesp(regs.pc >> 0); @@ -399,13 +399,13 @@ L abs.h = op_read(0xffff); regs.pc = abs.w; } -void RP2A03::op_jmp_absolute() { +void R6502::op_jmp_absolute() { abs.l = op_readpci(); L abs.h = op_readpci(); regs.pc = abs.w; } -void RP2A03::op_jmp_indirect_absolute() { +void R6502::op_jmp_indirect_absolute() { abs.l = op_readpci(); abs.h = op_readpci(); iabs.l = op_read(abs.w); abs.l++; @@ -413,7 +413,7 @@ L iabs.h = op_read(abs.w); abs.l++; regs.pc = iabs.w; } -void RP2A03::op_jsr_absolute() { +void R6502::op_jsr_absolute() { abs.l = op_readpci(); abs.h = op_readpci(); op_readpc(); @@ -423,22 +423,22 @@ L op_writesp(regs.pc >> 0); regs.pc = abs.w; } -void RP2A03::op_nop() { +void R6502::op_nop() { L op_readpc(); } -void RP2A03::op_php() { +void R6502::op_php() { op_readpc(); L op_writesp(regs.p | 0x30); } -void RP2A03::op_plp() { +void R6502::op_plp() { op_readpc(); op_readpc(); L regs.p = op_readsp(); } -void RP2A03::op_rti() { +void R6502::op_rti() { op_readpc(); op_readpc(); regs.p = op_readsp(); @@ -447,7 +447,7 @@ L abs.h = op_readsp(); regs.pc = abs.w; } -void RP2A03::op_rts() { +void R6502::op_rts() { op_readpc(); op_readpc(); abs.l = op_readsp(); @@ -459,7 +459,7 @@ L op_readpc(); //illegal opcodes //=============== -void RP2A03::opill_arr_immediate() { +void R6502::opill_arr_immediate() { L rd = op_readpci(); regs.a &= rd; regs.a = (regs.p.c << 7) | (regs.a >> 1); @@ -469,33 +469,33 @@ L rd = op_readpci(); regs.p.v = regs.p.c ^ ((regs.a >> 5) & 1); } -void RP2A03::opill_nop_absolute() { +void R6502::opill_nop_absolute() { abs.l = op_readpci(); abs.h = op_readpci(); L op_readpc(); } -void RP2A03::opill_nop_absolute_x() { +void R6502::opill_nop_absolute_x() { abs.l = op_readpci(); abs.h = op_readpci(); op_page(abs.w, abs.w + regs.x); L op_readpc(); } -void RP2A03::opill_nop_immediate() { +void R6502::opill_nop_immediate() { L rd = op_readpc(); } -void RP2A03::opill_nop_implied() { +void R6502::opill_nop_implied() { L op_readpc(); } -void RP2A03::opill_nop_zero_page() { +void R6502::opill_nop_zero_page() { zp = op_readpci(); L op_readzp(zp); } -void RP2A03::opill_nop_zero_page_x() { +void R6502::opill_nop_zero_page_x() { zp = op_readpci(); op_readzp(zp); L op_readzp(zp + regs.x); diff --git a/bsnes/processor/rp2a03/memory.cpp b/bsnes/processor/r6502/memory.cpp similarity index 51% rename from bsnes/processor/rp2a03/memory.cpp rename to bsnes/processor/r6502/memory.cpp index c42037c2..ec0529e7 100755 --- a/bsnes/processor/rp2a03/memory.cpp +++ b/bsnes/processor/r6502/memory.cpp @@ -1,35 +1,35 @@ -uint8 RP2A03::op_readpc() { +uint8 R6502::op_readpc() { return op_read(regs.pc); } -uint8 RP2A03::op_readpci() { +uint8 R6502::op_readpci() { return op_read(regs.pc++); } -uint8 RP2A03::op_readsp() { +uint8 R6502::op_readsp() { return op_read(0x0100 | ++regs.s); } -uint8 RP2A03::op_readzp(uint8 addr) { +uint8 R6502::op_readzp(uint8 addr) { return op_read(addr); } // -void RP2A03::op_writesp(uint8 data) { +void R6502::op_writesp(uint8 data) { op_write(0x0100 | regs.s--, data); } -void RP2A03::op_writezp(uint8 addr, uint8 data) { +void R6502::op_writezp(uint8 addr, uint8 data) { op_write(addr, data); } // -void RP2A03::op_page(uint16 x, uint16 y) { +void R6502::op_page(uint16 x, uint16 y) { if((x & 0xff00) != (y & 0xff00)) op_read((x & 0xff00) | (y & 0x00ff)); } -void RP2A03::op_page_always(uint16 x, uint16 y) { +void R6502::op_page_always(uint16 x, uint16 y) { op_read((x & 0xff00) | (y & 0x00ff)); } diff --git a/bsnes/processor/r6502/r6502.cpp b/bsnes/processor/r6502/r6502.cpp new file mode 100755 index 00000000..b5600595 --- /dev/null +++ b/bsnes/processor/r6502/r6502.cpp @@ -0,0 +1,241 @@ +#include +#include "r6502.hpp" + +namespace Processor { + +#define I +#define L last_cycle(); +#define call(op) (this->*op)() + +#include "memory.cpp" +#include "instructions.cpp" +#include "disassembler.cpp" +#include "serialization.cpp" + +uint8 R6502::mdr() const { + return regs.mdr; +} + +void R6502::power() { + regs.a = 0x00; + regs.x = 0x00; + regs.y = 0x00; + regs.s = 0x00; + regs.p = 0x04; +} + +void R6502::reset() { + regs.mdr = 0x00; + regs.s -= 3; + regs.p.i = 1; +} + +void R6502::interrupt() { + op_readpc(); + op_readpc(); + op_writesp(regs.pc >> 8); + op_writesp(regs.pc >> 0); + op_writesp(regs.p | 0x20); + uint16 vector = 0xfffe; //IRQ + nmi(vector); + abs.l = op_read(vector++); + regs.p.i = 1; + regs.p.d = 0; +L abs.h = op_read(vector++); + regs.pc = abs.w; +} + +void R6502::exec() { + uint8 opcode = op_readpci(); + switch(opcode) { + case 0x00: return op_brk(); + case 0x01: return opi_read_indirect_zero_page_x<&R6502::opf_ora>(); +I case 0x04: return opill_nop_zero_page(); + case 0x05: return opi_read_zero_page<&R6502::opf_ora>(); + case 0x06: return opi_rmw_zero_page<&R6502::opf_asl>(); + case 0x08: return op_php(); + case 0x09: return opi_read_immediate<&R6502::opf_ora>(); + case 0x0a: return opi_shift<&R6502::opf_sla>(); +I case 0x0c: return opill_nop_absolute(); + case 0x0d: return opi_read_absolute<&R6502::opf_ora>(); + case 0x0e: return opi_rmw_absolute<&R6502::opf_asl>(); + case 0x10: return opi_branch(regs.p.n == 0); + case 0x11: return opi_read_indirect_zero_page_y<&R6502::opf_ora>(); +I case 0x14: return opill_nop_zero_page_x(); + case 0x15: return opi_read_zero_page_x<&R6502::opf_ora>(); + case 0x16: return opi_rmw_zero_page_x<&R6502::opf_asl>(); + case 0x18: return opi_clear_flag(regs.p.c); + case 0x19: return opi_read_absolute_y<&R6502::opf_ora>(); +I case 0x1a: return opill_nop_implied(); +I case 0x1c: return opill_nop_absolute_x(); + case 0x1d: return opi_read_absolute_x<&R6502::opf_ora>(); + case 0x1e: return opi_rmw_absolute_x<&R6502::opf_asl>(); + case 0x20: return op_jsr_absolute(); + case 0x21: return opi_read_indirect_zero_page_x<&R6502::opf_and>(); + case 0x24: return opi_read_zero_page<&R6502::opf_bit>(); + case 0x25: return opi_read_zero_page<&R6502::opf_and>(); + case 0x26: return opi_rmw_zero_page<&R6502::opf_rol>(); + case 0x28: return op_plp(); + case 0x29: return opi_read_immediate<&R6502::opf_and>(); + case 0x2a: return opi_shift<&R6502::opf_rla>(); + case 0x2c: return opi_read_absolute<&R6502::opf_bit>(); + case 0x2d: return opi_read_absolute<&R6502::opf_and>(); + case 0x2e: return opi_rmw_absolute<&R6502::opf_rol>(); + case 0x30: return opi_branch(regs.p.n == 1); + case 0x31: return opi_read_indirect_zero_page_y<&R6502::opf_and>(); +I case 0x34: return opill_nop_zero_page_x(); + case 0x35: return opi_read_zero_page_x<&R6502::opf_and>(); + case 0x36: return opi_rmw_zero_page_x<&R6502::opf_rol>(); + case 0x38: return opi_set_flag(regs.p.c); + case 0x39: return opi_read_absolute_y<&R6502::opf_and>(); +I case 0x3a: return opill_nop_implied(); +I case 0x3c: return opill_nop_absolute_x(); + case 0x3d: return opi_read_absolute_x<&R6502::opf_and>(); + case 0x3e: return opi_rmw_absolute_x<&R6502::opf_rol>(); + case 0x40: return op_rti(); + case 0x41: return opi_read_indirect_zero_page_x<&R6502::opf_eor>(); +I case 0x44: return opill_nop_zero_page(); + case 0x45: return opi_read_zero_page<&R6502::opf_eor>(); + case 0x46: return opi_rmw_zero_page<&R6502::opf_lsr>(); + case 0x48: return opi_push(regs.a); + case 0x49: return opi_read_immediate<&R6502::opf_eor>(); + case 0x4a: return opi_shift<&R6502::opf_sra>(); + case 0x4c: return op_jmp_absolute(); + case 0x4d: return opi_read_absolute<&R6502::opf_eor>(); + case 0x4e: return opi_rmw_absolute<&R6502::opf_lsr>(); + case 0x50: return opi_branch(regs.p.v == 0); + case 0x51: return opi_read_indirect_zero_page_y<&R6502::opf_eor>(); +I case 0x54: return opill_nop_zero_page_x(); + case 0x55: return opi_read_zero_page_x<&R6502::opf_eor>(); + case 0x56: return opi_rmw_zero_page_x<&R6502::opf_lsr>(); + case 0x58: return opi_clear_flag(regs.p.i); + case 0x59: return opi_read_absolute_y<&R6502::opf_eor>(); +I case 0x5a: return opill_nop_implied(); +I case 0x5c: return opill_nop_absolute_x(); + case 0x5d: return opi_read_absolute_x<&R6502::opf_eor>(); + case 0x5e: return opi_rmw_absolute_x<&R6502::opf_lsr>(); + case 0x60: return op_rts(); + case 0x61: return opi_read_indirect_zero_page_x<&R6502::opf_adc>(); +I case 0x64: return opill_nop_zero_page(); + case 0x65: return opi_read_zero_page<&R6502::opf_adc>(); + case 0x66: return opi_rmw_zero_page<&R6502::opf_ror>(); + case 0x68: return opi_pull(regs.a); + case 0x69: return opi_read_immediate<&R6502::opf_adc>(); + case 0x6a: return opi_shift<&R6502::opf_rra>(); +I case 0x6b: return opill_arr_immediate(); + case 0x6c: return op_jmp_indirect_absolute(); + case 0x6d: return opi_read_absolute<&R6502::opf_adc>(); + case 0x6e: return opi_rmw_absolute<&R6502::opf_ror>(); + case 0x70: return opi_branch(regs.p.v == 1); +I case 0x74: return opill_nop_zero_page_x(); + case 0x71: return opi_read_indirect_zero_page_y<&R6502::opf_adc>(); + case 0x75: return opi_read_zero_page_x<&R6502::opf_adc>(); + case 0x76: return opi_rmw_zero_page_x<&R6502::opf_ror>(); + case 0x78: return opi_set_flag(regs.p.i); + case 0x79: return opi_read_absolute_y<&R6502::opf_adc>(); +I case 0x7a: return opill_nop_implied(); +I case 0x7c: return opill_nop_absolute_x(); + case 0x7d: return opi_read_absolute_x<&R6502::opf_adc>(); + case 0x7e: return opi_rmw_absolute_x<&R6502::opf_ror>(); +I case 0x80: return opill_nop_absolute(); + case 0x81: return opi_store_indirect_zero_page_x(regs.a); +I case 0x82: return opill_nop_immediate(); + case 0x84: return opi_store_zero_page(regs.y); + case 0x85: return opi_store_zero_page(regs.a); + case 0x86: return opi_store_zero_page(regs.x); + case 0x88: return opi_decrement(regs.y); +I case 0x89: return opill_nop_immediate(); + case 0x8a: return opi_transfer(regs.x, regs.a, 1); + case 0x8c: return opi_store_absolute(regs.y); + case 0x8d: return opi_store_absolute(regs.a); + case 0x8e: return opi_store_absolute(regs.x); + case 0x90: return opi_branch(regs.p.c == 0); + case 0x91: return opi_store_indirect_zero_page_y(regs.a); + case 0x94: return opi_store_zero_page_x(regs.y); + case 0x95: return opi_store_zero_page_x(regs.a); + case 0x96: return opi_store_zero_page_y(regs.x); + case 0x98: return opi_transfer(regs.y, regs.a, 1); + case 0x99: return opi_store_absolute_y(regs.a); + case 0x9a: return opi_transfer(regs.x, regs.s, 0); + case 0x9d: return opi_store_absolute_x(regs.a); + case 0xa0: return opi_read_immediate<&R6502::opf_ldy>(); + case 0xa1: return opi_read_indirect_zero_page_x<&R6502::opf_lda>(); + case 0xa2: return opi_read_immediate<&R6502::opf_ldx>(); + case 0xa4: return opi_read_zero_page<&R6502::opf_ldy>(); + case 0xa5: return opi_read_zero_page<&R6502::opf_lda>(); + case 0xa6: return opi_read_zero_page<&R6502::opf_ldx>(); + case 0xa8: return opi_transfer(regs.a, regs.y, 1); + case 0xa9: return opi_read_immediate<&R6502::opf_lda>(); + case 0xaa: return opi_transfer(regs.a, regs.x, 1); + case 0xac: return opi_read_absolute<&R6502::opf_ldy>(); + case 0xad: return opi_read_absolute<&R6502::opf_lda>(); + case 0xae: return opi_read_absolute<&R6502::opf_ldx>(); + case 0xb0: return opi_branch(regs.p.c == 1); + case 0xb1: return opi_read_indirect_zero_page_y<&R6502::opf_lda>(); + case 0xb4: return opi_read_zero_page_x<&R6502::opf_ldy>(); + case 0xb5: return opi_read_zero_page_x<&R6502::opf_lda>(); + case 0xb6: return opi_read_zero_page_y<&R6502::opf_ldx>(); + case 0xb8: return opi_clear_flag(regs.p.v); + case 0xb9: return opi_read_absolute_y<&R6502::opf_lda>(); + case 0xba: return opi_transfer(regs.s, regs.x, 1); + case 0xbc: return opi_read_absolute_x<&R6502::opf_ldy>(); + case 0xbd: return opi_read_absolute_x<&R6502::opf_lda>(); + case 0xbe: return opi_read_absolute_y<&R6502::opf_ldx>(); + case 0xc0: return opi_read_immediate<&R6502::opf_cpy>(); + case 0xc1: return opi_read_indirect_zero_page_x<&R6502::opf_cmp>(); +I case 0xc2: return opill_nop_immediate(); + case 0xc4: return opi_read_zero_page<&R6502::opf_cpy>(); + case 0xc5: return opi_read_zero_page<&R6502::opf_cmp>(); + case 0xc6: return opi_rmw_zero_page<&R6502::opf_dec>(); + case 0xc8: return opi_increment(regs.y); + case 0xc9: return opi_read_immediate<&R6502::opf_cmp>(); + case 0xca: return opi_decrement(regs.x); + case 0xcc: return opi_read_absolute<&R6502::opf_cpy>(); + case 0xcd: return opi_read_absolute<&R6502::opf_cmp>(); + case 0xce: return opi_rmw_absolute<&R6502::opf_dec>(); + case 0xd0: return opi_branch(regs.p.z == 0); + case 0xd1: return opi_read_indirect_zero_page_y<&R6502::opf_cmp>(); +I case 0xd4: return opill_nop_zero_page_x(); + case 0xd5: return opi_read_zero_page_x<&R6502::opf_cmp>(); + case 0xd6: return opi_rmw_zero_page_x<&R6502::opf_dec>(); + case 0xd8: return opi_clear_flag(regs.p.d); + case 0xd9: return opi_read_absolute_y<&R6502::opf_cmp>(); +I case 0xda: return opill_nop_implied(); +I case 0xdc: return opill_nop_absolute_x(); + case 0xdd: return opi_read_absolute_x<&R6502::opf_cmp>(); + case 0xde: return opi_rmw_absolute_x<&R6502::opf_dec>(); + case 0xe0: return opi_read_immediate<&R6502::opf_cpx>(); + case 0xe1: return opi_read_indirect_zero_page_x<&R6502::opf_sbc>(); +I case 0xe2: return opill_nop_immediate(); + case 0xe4: return opi_read_zero_page<&R6502::opf_cpx>(); + case 0xe5: return opi_read_zero_page<&R6502::opf_sbc>(); + case 0xe6: return opi_rmw_zero_page<&R6502::opf_inc>(); + case 0xe8: return opi_increment(regs.x); + case 0xe9: return opi_read_immediate<&R6502::opf_sbc>(); + case 0xea: return op_nop(); +I case 0xeb: return opi_read_immediate<&R6502::opf_sbc>(); + case 0xec: return opi_read_absolute<&R6502::opf_cpx>(); + case 0xed: return opi_read_absolute<&R6502::opf_sbc>(); + case 0xee: return opi_rmw_absolute<&R6502::opf_inc>(); + case 0xf0: return opi_branch(regs.p.z == 1); + case 0xf1: return opi_read_indirect_zero_page_y<&R6502::opf_sbc>(); +I case 0xf4: return opill_nop_zero_page_x(); + case 0xf5: return opi_read_zero_page_x<&R6502::opf_sbc>(); + case 0xf6: return opi_rmw_zero_page_x<&R6502::opf_inc>(); + case 0xf8: return opi_set_flag(regs.p.d); + case 0xf9: return opi_read_absolute_y<&R6502::opf_sbc>(); +I case 0xfa: return opill_nop_implied(); +I case 0xfc: return opill_nop_absolute_x(); + case 0xfd: return opi_read_absolute_x<&R6502::opf_sbc>(); + case 0xfe: return opi_rmw_absolute_x<&R6502::opf_inc>(); + } + + //unimplemented opcode + return op_nop(); +} + +#undef I +#undef L +#undef call + +} diff --git a/bsnes/processor/rp2a03/rp2a03.hpp b/bsnes/processor/r6502/r6502.hpp similarity index 69% rename from bsnes/processor/rp2a03/rp2a03.hpp rename to bsnes/processor/r6502/r6502.hpp index 1a511c8b..f34b5ee2 100755 --- a/bsnes/processor/rp2a03/rp2a03.hpp +++ b/bsnes/processor/r6502/r6502.hpp @@ -1,12 +1,13 @@ -#ifndef PROCESSOR_RP2A03_HPP -#define PROCESSOR_RP2A03_HPP +#ifndef PROCESSOR_R6502_HPP +#define PROCESSOR_R6502_HPP namespace Processor { -//Ricoh RP2A03 -//Ricoh RP2A07 +//Ricoh 6502 +//* Ricoh 2A03 +//* Ricoh 2A07 -struct RP2A03 { +struct R6502 { #include "registers.hpp" virtual uint8 op_read(uint16 addr) = 0; @@ -65,21 +66,21 @@ struct RP2A03 { void opi_increment(uint8 &r); void opi_pull(uint8 &r); void opi_push(uint8 &r); - template void opi_read_absolute(); - template void opi_read_absolute_x(); - template void opi_read_absolute_y(); - template void opi_read_immediate(); - template void opi_read_indirect_zero_page_x(); - template void opi_read_indirect_zero_page_y(); - template void opi_read_zero_page(); - template void opi_read_zero_page_x(); - template void opi_read_zero_page_y(); - template void opi_rmw_absolute(); - template void opi_rmw_absolute_x(); - template void opi_rmw_zero_page(); - template void opi_rmw_zero_page_x(); + template void opi_read_absolute(); + template void opi_read_absolute_x(); + template void opi_read_absolute_y(); + template void opi_read_immediate(); + template void opi_read_indirect_zero_page_x(); + template void opi_read_indirect_zero_page_y(); + template void opi_read_zero_page(); + template void opi_read_zero_page_x(); + template void opi_read_zero_page_y(); + template void opi_rmw_absolute(); + template void opi_rmw_absolute_x(); + template void opi_rmw_zero_page(); + template void opi_rmw_zero_page_x(); void opi_set_flag(bool &flag); - template void opi_shift(); + template void opi_shift(); void opi_store_absolute(uint8 &r); void opi_store_absolute_x(uint8 &r); void opi_store_absolute_y(uint8 &r); diff --git a/bsnes/processor/rp2a03/registers.hpp b/bsnes/processor/r6502/registers.hpp similarity index 100% rename from bsnes/processor/rp2a03/registers.hpp rename to bsnes/processor/r6502/registers.hpp diff --git a/bsnes/processor/rp2a03/serialization.cpp b/bsnes/processor/r6502/serialization.cpp similarity index 90% rename from bsnes/processor/rp2a03/serialization.cpp rename to bsnes/processor/r6502/serialization.cpp index fdd58890..1bb8652c 100755 --- a/bsnes/processor/rp2a03/serialization.cpp +++ b/bsnes/processor/r6502/serialization.cpp @@ -1,4 +1,4 @@ -void RP2A03::serialize(serializer &s) { +void R6502::serialize(serializer &s) { s.integer(regs.mdr); s.integer(regs.pc); s.integer(regs.a); diff --git a/bsnes/snes/cpu/core/algorithms.cpp b/bsnes/processor/r65816/algorithms.cpp similarity index 81% rename from bsnes/snes/cpu/core/algorithms.cpp rename to bsnes/processor/r65816/algorithms.cpp index 9b6ba032..e100782e 100755 --- a/bsnes/snes/cpu/core/algorithms.cpp +++ b/bsnes/processor/r65816/algorithms.cpp @@ -1,6 +1,4 @@ -#ifdef CPUCORE_CPP - -inline void CPUcore::op_adc_b() { +inline void R65816::op_adc_b() { int result; if(!regs.p.d) { @@ -21,7 +19,7 @@ inline void CPUcore::op_adc_b() { regs.a.l = result; } -inline void CPUcore::op_adc_w() { +inline void R65816::op_adc_w() { int result; if(!regs.p.d) { @@ -48,133 +46,133 @@ inline void CPUcore::op_adc_w() { regs.a.w = result; } -inline void CPUcore::op_and_b() { +inline void R65816::op_and_b() { regs.a.l &= rd.l; regs.p.n = regs.a.l & 0x80; regs.p.z = regs.a.l == 0; } -inline void CPUcore::op_and_w() { +inline void R65816::op_and_w() { regs.a.w &= rd.w; regs.p.n = regs.a.w & 0x8000; regs.p.z = regs.a.w == 0; } -inline void CPUcore::op_bit_b() { +inline void R65816::op_bit_b() { regs.p.n = rd.l & 0x80; regs.p.v = rd.l & 0x40; regs.p.z = (rd.l & regs.a.l) == 0; } -inline void CPUcore::op_bit_w() { +inline void R65816::op_bit_w() { regs.p.n = rd.w & 0x8000; regs.p.v = rd.w & 0x4000; regs.p.z = (rd.w & regs.a.w) == 0; } -inline void CPUcore::op_cmp_b() { +inline void R65816::op_cmp_b() { int r = regs.a.l - rd.l; regs.p.n = r & 0x80; regs.p.z = (uint8)r == 0; regs.p.c = r >= 0; } -inline void CPUcore::op_cmp_w() { +inline void R65816::op_cmp_w() { int r = regs.a.w - rd.w; regs.p.n = r & 0x8000; regs.p.z = (uint16)r == 0; regs.p.c = r >= 0; } -inline void CPUcore::op_cpx_b() { +inline void R65816::op_cpx_b() { int r = regs.x.l - rd.l; regs.p.n = r & 0x80; regs.p.z = (uint8)r == 0; regs.p.c = r >= 0; } -inline void CPUcore::op_cpx_w() { +inline void R65816::op_cpx_w() { int r = regs.x.w - rd.w; regs.p.n = r & 0x8000; regs.p.z = (uint16)r == 0; regs.p.c = r >= 0; } -inline void CPUcore::op_cpy_b() { +inline void R65816::op_cpy_b() { int r = regs.y.l - rd.l; regs.p.n = r & 0x80; regs.p.z = (uint8)r == 0; regs.p.c = r >= 0; } -inline void CPUcore::op_cpy_w() { +inline void R65816::op_cpy_w() { int r = regs.y.w - rd.w; regs.p.n = r & 0x8000; regs.p.z = (uint16)r == 0; regs.p.c = r >= 0; } -inline void CPUcore::op_eor_b() { +inline void R65816::op_eor_b() { regs.a.l ^= rd.l; regs.p.n = regs.a.l & 0x80; regs.p.z = regs.a.l == 0; } -inline void CPUcore::op_eor_w() { +inline void R65816::op_eor_w() { regs.a.w ^= rd.w; regs.p.n = regs.a.w & 0x8000; regs.p.z = regs.a.w == 0; } -inline void CPUcore::op_lda_b() { +inline void R65816::op_lda_b() { regs.a.l = rd.l; regs.p.n = regs.a.l & 0x80; regs.p.z = regs.a.l == 0; } -inline void CPUcore::op_lda_w() { +inline void R65816::op_lda_w() { regs.a.w = rd.w; regs.p.n = regs.a.w & 0x8000; regs.p.z = regs.a.w == 0; } -inline void CPUcore::op_ldx_b() { +inline void R65816::op_ldx_b() { regs.x.l = rd.l; regs.p.n = regs.x.l & 0x80; regs.p.z = regs.x.l == 0; } -inline void CPUcore::op_ldx_w() { +inline void R65816::op_ldx_w() { regs.x.w = rd.w; regs.p.n = regs.x.w & 0x8000; regs.p.z = regs.x.w == 0; } -inline void CPUcore::op_ldy_b() { +inline void R65816::op_ldy_b() { regs.y.l = rd.l; regs.p.n = regs.y.l & 0x80; regs.p.z = regs.y.l == 0; } -inline void CPUcore::op_ldy_w() { +inline void R65816::op_ldy_w() { regs.y.w = rd.w; regs.p.n = regs.y.w & 0x8000; regs.p.z = regs.y.w == 0; } -inline void CPUcore::op_ora_b() { +inline void R65816::op_ora_b() { regs.a.l |= rd.l; regs.p.n = regs.a.l & 0x80; regs.p.z = regs.a.l == 0; } -inline void CPUcore::op_ora_w() { +inline void R65816::op_ora_w() { regs.a.w |= rd.w; regs.p.n = regs.a.w & 0x8000; regs.p.z = regs.a.w == 0; } -inline void CPUcore::op_sbc_b() { +inline void R65816::op_sbc_b() { int result; rd.l ^= 0xff; @@ -196,7 +194,7 @@ inline void CPUcore::op_sbc_b() { regs.a.l = result; } -inline void CPUcore::op_sbc_w() { +inline void R65816::op_sbc_w() { int result; rd.w ^= 0xffff; @@ -224,59 +222,59 @@ inline void CPUcore::op_sbc_w() { regs.a.w = result; } -inline void CPUcore::op_inc_b() { +inline void R65816::op_inc_b() { rd.l++; regs.p.n = rd.l & 0x80; regs.p.z = rd.l == 0; } -inline void CPUcore::op_inc_w() { +inline void R65816::op_inc_w() { rd.w++; regs.p.n = rd.w & 0x8000; regs.p.z = rd.w == 0; } -inline void CPUcore::op_dec_b() { +inline void R65816::op_dec_b() { rd.l--; regs.p.n = rd.l & 0x80; regs.p.z = rd.l == 0; } -inline void CPUcore::op_dec_w() { +inline void R65816::op_dec_w() { rd.w--; regs.p.n = rd.w & 0x8000; regs.p.z = rd.w == 0; } -inline void CPUcore::op_asl_b() { +inline void R65816::op_asl_b() { regs.p.c = rd.l & 0x80; rd.l <<= 1; regs.p.n = rd.l & 0x80; regs.p.z = rd.l == 0; } -inline void CPUcore::op_asl_w() { +inline void R65816::op_asl_w() { regs.p.c = rd.w & 0x8000; rd.w <<= 1; regs.p.n = rd.w & 0x8000; regs.p.z = rd.w == 0; } -inline void CPUcore::op_lsr_b() { +inline void R65816::op_lsr_b() { regs.p.c = rd.l & 1; rd.l >>= 1; regs.p.n = rd.l & 0x80; regs.p.z = rd.l == 0; } -inline void CPUcore::op_lsr_w() { +inline void R65816::op_lsr_w() { regs.p.c = rd.w & 1; rd.w >>= 1; regs.p.n = rd.w & 0x8000; regs.p.z = rd.w == 0; } -inline void CPUcore::op_rol_b() { +inline void R65816::op_rol_b() { unsigned carry = (unsigned)regs.p.c; regs.p.c = rd.l & 0x80; rd.l = (rd.l << 1) | carry; @@ -284,7 +282,7 @@ inline void CPUcore::op_rol_b() { regs.p.z = rd.l == 0; } -inline void CPUcore::op_rol_w() { +inline void R65816::op_rol_w() { unsigned carry = (unsigned)regs.p.c; regs.p.c = rd.w & 0x8000; rd.w = (rd.w << 1) | carry; @@ -292,7 +290,7 @@ inline void CPUcore::op_rol_w() { regs.p.z = rd.w == 0; } -inline void CPUcore::op_ror_b() { +inline void R65816::op_ror_b() { unsigned carry = (unsigned)regs.p.c << 7; regs.p.c = rd.l & 1; rd.l = carry | (rd.l >> 1); @@ -300,7 +298,7 @@ inline void CPUcore::op_ror_b() { regs.p.z = rd.l == 0; } -inline void CPUcore::op_ror_w() { +inline void R65816::op_ror_w() { unsigned carry = (unsigned)regs.p.c << 15; regs.p.c = rd.w & 1; rd.w = carry | (rd.w >> 1); @@ -308,24 +306,22 @@ inline void CPUcore::op_ror_w() { regs.p.z = rd.w == 0; } -inline void CPUcore::op_trb_b() { +inline void R65816::op_trb_b() { regs.p.z = (rd.l & regs.a.l) == 0; rd.l &= ~regs.a.l; } -inline void CPUcore::op_trb_w() { +inline void R65816::op_trb_w() { regs.p.z = (rd.w & regs.a.w) == 0; rd.w &= ~regs.a.w; } -inline void CPUcore::op_tsb_b() { +inline void R65816::op_tsb_b() { regs.p.z = (rd.l & regs.a.l) == 0; rd.l |= regs.a.l; } -inline void CPUcore::op_tsb_w() { +inline void R65816::op_tsb_w() { regs.p.z = (rd.w & regs.a.w) == 0; rd.w |= regs.a.w; } - -#endif diff --git a/bsnes/snes/cpu/core/disassembler/disassembler.cpp b/bsnes/processor/r65816/disassembler.cpp similarity index 98% rename from bsnes/snes/cpu/core/disassembler/disassembler.cpp rename to bsnes/processor/r65816/disassembler.cpp index 8aa6e527..9f8c4137 100755 --- a/bsnes/snes/cpu/core/disassembler/disassembler.cpp +++ b/bsnes/processor/r65816/disassembler.cpp @@ -1,22 +1,20 @@ -#ifdef CPUCORE_CPP - -uint8 CPUcore::dreadb(uint32 addr) { +uint8 R65816::dreadb(uint32 addr) { if((addr & 0x40ffff) >= 0x2000 && (addr & 0x40ffff) <= 0x5fff) { //$[00-3f|80-bf]:[2000-5fff] //do not read MMIO registers within debugger return 0x00; } - return bus.read(addr); + return disassembler_read(addr); } -uint16 CPUcore::dreadw(uint32 addr) { +uint16 R65816::dreadw(uint32 addr) { uint16 r; r = dreadb((addr + 0) & 0xffffff) << 0; r |= dreadb((addr + 1) & 0xffffff) << 8; return r; } -uint32 CPUcore::dreadl(uint32 addr) { +uint32 R65816::dreadl(uint32 addr) { uint32 r; r = dreadb((addr + 0) & 0xffffff) << 0; r |= dreadb((addr + 1) & 0xffffff) << 8; @@ -24,7 +22,7 @@ uint32 CPUcore::dreadl(uint32 addr) { return r; } -uint32 CPUcore::decode(uint8 offset_type, uint32 addr) { +uint32 R65816::decode(uint8 offset_type, uint32 addr) { uint32 r = 0; switch(offset_type) { @@ -104,7 +102,7 @@ uint32 CPUcore::decode(uint8 offset_type, uint32 addr) { return(r & 0xffffff); } -void CPUcore::disassemble_opcode(char *output, uint32 addr) { +void R65816::disassemble_opcode(char *output, uint32 addr) { static reg24_t pc; char t[256]; char *s = output; @@ -427,10 +425,8 @@ void CPUcore::disassemble_opcode(char *output, uint32 addr) { } strcat(s, t); - strcat(s, " "); +//strcat(s, " "); - sprintf(t, "V:%3d H:%4d", cpu.vcounter(), cpu.hcounter()); +//sprintf(t, "V:%3d H:%4d", cpu.vcounter(), cpu.hcounter()); strcat(s, t); } - -#endif diff --git a/bsnes/snes/cpu/core/disassembler/disassembler.hpp b/bsnes/processor/r65816/disassembler.hpp similarity index 97% rename from bsnes/snes/cpu/core/disassembler/disassembler.hpp rename to bsnes/processor/r65816/disassembler.hpp index a57ca635..48457068 100755 --- a/bsnes/snes/cpu/core/disassembler/disassembler.hpp +++ b/bsnes/processor/r65816/disassembler.hpp @@ -1,4 +1,4 @@ -enum { +enum : unsigned { OPTYPE_DP = 0, //dp OPTYPE_DPX, //dp,x OPTYPE_DPY, //dp,y diff --git a/bsnes/snes/cpu/core/memory.hpp b/bsnes/processor/r65816/memory.hpp similarity index 56% rename from bsnes/snes/cpu/core/memory.hpp rename to bsnes/processor/r65816/memory.hpp index 49926578..590b8922 100755 --- a/bsnes/snes/cpu/core/memory.hpp +++ b/bsnes/processor/r65816/memory.hpp @@ -1,33 +1,33 @@ -alwaysinline uint8_t op_readpc() { +alwaysinline uint8 op_readpc() { return op_read((regs.pc.b << 16) + regs.pc.w++); } -alwaysinline uint8_t op_readstack() { +alwaysinline uint8 op_readstack() { regs.e ? regs.s.l++ : regs.s.w++; return op_read(regs.s.w); } -alwaysinline uint8_t op_readstackn() { +alwaysinline uint8 op_readstackn() { return op_read(++regs.s.w); } -alwaysinline uint8_t op_readaddr(uint32_t addr) { +alwaysinline uint8 op_readaddr(uint32 addr) { return op_read(addr & 0xffff); } -alwaysinline uint8_t op_readlong(uint32_t addr) { +alwaysinline uint8 op_readlong(uint32 addr) { return op_read(addr & 0xffffff); } -alwaysinline uint8_t op_readdbr(uint32_t addr) { +alwaysinline uint8 op_readdbr(uint32 addr) { return op_read(((regs.db << 16) + addr) & 0xffffff); } -alwaysinline uint8_t op_readpbr(uint32_t addr) { +alwaysinline uint8 op_readpbr(uint32 addr) { return op_read((regs.pc.b << 16) + (addr & 0xffff)); } -alwaysinline uint8_t op_readdp(uint32_t addr) { +alwaysinline uint8 op_readdp(uint32 addr) { if(regs.e && regs.d.l == 0x00) { return op_read((regs.d & 0xff00) + ((regs.d + (addr & 0xffff)) & 0xff)); } else { @@ -35,36 +35,36 @@ alwaysinline uint8_t op_readdp(uint32_t addr) { } } -alwaysinline uint8_t op_readsp(uint32_t addr) { +alwaysinline uint8 op_readsp(uint32 addr) { return op_read((regs.s + (addr & 0xffff)) & 0xffff); } -alwaysinline void op_writestack(uint8_t data) { +alwaysinline void op_writestack(uint8 data) { op_write(regs.s.w, data); regs.e ? regs.s.l-- : regs.s.w--; } -alwaysinline void op_writestackn(uint8_t data) { +alwaysinline void op_writestackn(uint8 data) { op_write(regs.s.w--, data); } -alwaysinline void op_writeaddr(uint32_t addr, uint8_t data) { +alwaysinline void op_writeaddr(uint32 addr, uint8 data) { op_write(addr & 0xffff, data); } -alwaysinline void op_writelong(uint32_t addr, uint8_t data) { +alwaysinline void op_writelong(uint32 addr, uint8 data) { op_write(addr & 0xffffff, data); } -alwaysinline void op_writedbr(uint32_t addr, uint8_t data) { +alwaysinline void op_writedbr(uint32 addr, uint8 data) { op_write(((regs.db << 16) + addr) & 0xffffff, data); } -alwaysinline void op_writepbr(uint32_t addr, uint8_t data) { +alwaysinline void op_writepbr(uint32 addr, uint8 data) { op_write((regs.pc.b << 16) + (addr & 0xffff), data); } -alwaysinline void op_writedp(uint32_t addr, uint8_t data) { +alwaysinline void op_writedp(uint32 addr, uint8 data) { if(regs.e && regs.d.l == 0x00) { op_write((regs.d & 0xff00) + ((regs.d + (addr & 0xffff)) & 0xff), data); } else { @@ -72,6 +72,6 @@ alwaysinline void op_writedp(uint32_t addr, uint8_t data) { } } -alwaysinline void op_writesp(uint32_t addr, uint8_t data) { +alwaysinline void op_writesp(uint32 addr, uint8 data) { op_write((regs.s + (addr & 0xffff)) & 0xffff, data); } diff --git a/bsnes/snes/cpu/core/opcode_misc.cpp b/bsnes/processor/r65816/opcode_misc.cpp similarity index 76% rename from bsnes/snes/cpu/core/opcode_misc.cpp rename to bsnes/processor/r65816/opcode_misc.cpp index 8087fe66..7d17b6fb 100755 --- a/bsnes/snes/cpu/core/opcode_misc.cpp +++ b/bsnes/processor/r65816/opcode_misc.cpp @@ -1,14 +1,12 @@ -#ifdef CPUCORE_CPP - -void CPUcore::op_nop() { +void R65816::op_nop() { L op_io_irq(); } -void CPUcore::op_wdm() { +void R65816::op_wdm() { L op_readpc(); } -void CPUcore::op_xba() { +void R65816::op_xba() { op_io(); L op_io(); regs.a.l ^= regs.a.h; @@ -18,7 +16,7 @@ L op_io(); regs.p.z = (regs.a.l == 0); } -template void CPUcore::op_move_b() { +template void R65816::op_move_b() { dp = op_readpc(); sp = op_readpc(); regs.db = dp; @@ -31,7 +29,7 @@ L op_io(); if(regs.a.w--) regs.pc.w -= 3; } -template void CPUcore::op_move_w() { +template void R65816::op_move_w() { dp = op_readpc(); sp = op_readpc(); regs.db = dp; @@ -44,7 +42,7 @@ L op_io(); if(regs.a.w--) regs.pc.w -= 3; } -template void CPUcore::op_interrupt_e() { +template void R65816::op_interrupt_e() { op_readpc(); op_writestack(regs.pc.h); op_writestack(regs.pc.l); @@ -57,7 +55,7 @@ L rd.h = op_readlong(vectorE + 1); regs.pc.w = rd.w; } -template void CPUcore::op_interrupt_n() { +template void R65816::op_interrupt_n() { op_readpc(); op_writestack(regs.pc.b); op_writestack(regs.pc.h); @@ -71,13 +69,13 @@ L rd.h = op_readlong(vectorN + 1); regs.pc.w = rd.w; } -void CPUcore::op_stp() { +void R65816::op_stp() { while(regs.wai = true) { L op_io(); } } -void CPUcore::op_wai() { +void R65816::op_wai() { regs.wai = true; while(regs.wai) { L op_io(); @@ -85,7 +83,7 @@ L op_io(); op_io(); } -void CPUcore::op_xce() { +void R65816::op_xce() { L op_io_irq(); bool carry = regs.p.c; regs.p.c = regs.e; @@ -101,12 +99,12 @@ L op_io_irq(); update_table(); } -template void CPUcore::op_flag() { +template void R65816::op_flag() { L op_io_irq(); regs.p = (regs.p & ~mask) | value; } -template void CPUcore::op_pflag_e() { +template void R65816::op_pflag_e() { rd.l = op_readpc(); L op_io(); regs.p = (mode ? regs.p | rd.l : regs.p & ~rd.l); @@ -118,7 +116,7 @@ L op_io(); update_table(); } -template void CPUcore::op_pflag_n() { +template void R65816::op_pflag_n() { rd.l = op_readpc(); L op_io(); regs.p = (mode ? regs.p | rd.l : regs.p & ~rd.l); @@ -129,94 +127,94 @@ L op_io(); update_table(); } -template void CPUcore::op_transfer_b() { +template void R65816::op_transfer_b() { L op_io_irq(); regs.r[to].l = regs.r[from].l; regs.p.n = (regs.r[to].l & 0x80); regs.p.z = (regs.r[to].l == 0); } -template void CPUcore::op_transfer_w() { +template void R65816::op_transfer_w() { L op_io_irq(); regs.r[to].w = regs.r[from].w; regs.p.n = (regs.r[to].w & 0x8000); regs.p.z = (regs.r[to].w == 0); } -void CPUcore::op_tcs_e() { +void R65816::op_tcs_e() { L op_io_irq(); regs.s.l = regs.a.l; } -void CPUcore::op_tcs_n() { +void R65816::op_tcs_n() { L op_io_irq(); regs.s.w = regs.a.w; } -void CPUcore::op_tsx_b() { +void R65816::op_tsx_b() { L op_io_irq(); regs.x.l = regs.s.l; regs.p.n = (regs.x.l & 0x80); regs.p.z = (regs.x.l == 0); } -void CPUcore::op_tsx_w() { +void R65816::op_tsx_w() { L op_io_irq(); regs.x.w = regs.s.w; regs.p.n = (regs.x.w & 0x8000); regs.p.z = (regs.x.w == 0); } -void CPUcore::op_txs_e() { +void R65816::op_txs_e() { L op_io_irq(); regs.s.l = regs.x.l; } -void CPUcore::op_txs_n() { +void R65816::op_txs_n() { L op_io_irq(); regs.s.w = regs.x.w; } -template void CPUcore::op_push_b() { +template void R65816::op_push_b() { op_io(); L op_writestack(regs.r[n].l); } -template void CPUcore::op_push_w() { +template void R65816::op_push_w() { op_io(); op_writestack(regs.r[n].h); L op_writestack(regs.r[n].l); } -void CPUcore::op_phd_e() { +void R65816::op_phd_e() { op_io(); op_writestackn(regs.d.h); L op_writestackn(regs.d.l); regs.s.h = 0x01; } -void CPUcore::op_phd_n() { +void R65816::op_phd_n() { op_io(); op_writestackn(regs.d.h); L op_writestackn(regs.d.l); } -void CPUcore::op_phb() { +void R65816::op_phb() { op_io(); L op_writestack(regs.db); } -void CPUcore::op_phk() { +void R65816::op_phk() { op_io(); L op_writestack(regs.pc.b); } -void CPUcore::op_php() { +void R65816::op_php() { op_io(); L op_writestack(regs.p); } -template void CPUcore::op_pull_b() { +template void R65816::op_pull_b() { op_io(); op_io(); L regs.r[n].l = op_readstack(); @@ -224,7 +222,7 @@ L regs.r[n].l = op_readstack(); regs.p.z = (regs.r[n].l == 0); } -template void CPUcore::op_pull_w() { +template void R65816::op_pull_w() { op_io(); op_io(); regs.r[n].l = op_readstack(); @@ -233,7 +231,7 @@ L regs.r[n].h = op_readstack(); regs.p.z = (regs.r[n].w == 0); } -void CPUcore::op_pld_e() { +void R65816::op_pld_e() { op_io(); op_io(); regs.d.l = op_readstackn(); @@ -243,7 +241,7 @@ L regs.d.h = op_readstackn(); regs.s.h = 0x01; } -void CPUcore::op_pld_n() { +void R65816::op_pld_n() { op_io(); op_io(); regs.d.l = op_readstackn(); @@ -252,7 +250,7 @@ L regs.d.h = op_readstackn(); regs.p.z = (regs.d.w == 0); } -void CPUcore::op_plb() { +void R65816::op_plb() { op_io(); op_io(); L regs.db = op_readstack(); @@ -260,7 +258,7 @@ L regs.db = op_readstack(); regs.p.z = (regs.db == 0); } -void CPUcore::op_plp_e() { +void R65816::op_plp_e() { op_io(); op_io(); L regs.p = op_readstack() | 0x30; @@ -271,7 +269,7 @@ L regs.p = op_readstack() | 0x30; update_table(); } -void CPUcore::op_plp_n() { +void R65816::op_plp_n() { op_io(); op_io(); L regs.p = op_readstack(); @@ -282,7 +280,7 @@ L regs.p = op_readstack(); update_table(); } -void CPUcore::op_pea_e() { +void R65816::op_pea_e() { aa.l = op_readpc(); aa.h = op_readpc(); op_writestackn(aa.h); @@ -290,14 +288,14 @@ L op_writestackn(aa.l); regs.s.h = 0x01; } -void CPUcore::op_pea_n() { +void R65816::op_pea_n() { aa.l = op_readpc(); aa.h = op_readpc(); op_writestackn(aa.h); L op_writestackn(aa.l); } -void CPUcore::op_pei_e() { +void R65816::op_pei_e() { dp = op_readpc(); op_io_cond2(); aa.l = op_readdp(dp + 0); @@ -307,7 +305,7 @@ L op_writestackn(aa.l); regs.s.h = 0x01; } -void CPUcore::op_pei_n() { +void R65816::op_pei_n() { dp = op_readpc(); op_io_cond2(); aa.l = op_readdp(dp + 0); @@ -316,7 +314,7 @@ void CPUcore::op_pei_n() { L op_writestackn(aa.l); } -void CPUcore::op_per_e() { +void R65816::op_per_e() { aa.l = op_readpc(); aa.h = op_readpc(); op_io(); @@ -326,7 +324,7 @@ L op_writestackn(rd.l); regs.s.h = 0x01; } -void CPUcore::op_per_n() { +void R65816::op_per_n() { aa.l = op_readpc(); aa.h = op_readpc(); op_io(); @@ -334,5 +332,3 @@ void CPUcore::op_per_n() { op_writestackn(rd.h); L op_writestackn(rd.l); } - -#endif diff --git a/bsnes/snes/cpu/core/opcode_pc.cpp b/bsnes/processor/r65816/opcode_pc.cpp similarity index 83% rename from bsnes/snes/cpu/core/opcode_pc.cpp rename to bsnes/processor/r65816/opcode_pc.cpp index 3b4543f3..22fccc8e 100755 --- a/bsnes/snes/cpu/core/opcode_pc.cpp +++ b/bsnes/processor/r65816/opcode_pc.cpp @@ -1,6 +1,4 @@ -#ifdef CPUCORE_CPP - -template void CPUcore::op_branch() { +template void R65816::op_branch() { if((bool)(regs.p & bit) != val) { L rd.l = op_readpc(); } else { @@ -12,7 +10,7 @@ L op_io(); } } -void CPUcore::op_bra() { +void R65816::op_bra() { rd.l = op_readpc(); aa.w = regs.pc.d + (int8)rd.l; op_io_cond6(aa.w); @@ -20,27 +18,27 @@ L op_io(); regs.pc.w = aa.w; } -void CPUcore::op_brl() { +void R65816::op_brl() { rd.l = op_readpc(); rd.h = op_readpc(); L op_io(); regs.pc.w = regs.pc.d + (int16)rd.w; } -void CPUcore::op_jmp_addr() { +void R65816::op_jmp_addr() { rd.l = op_readpc(); L rd.h = op_readpc(); regs.pc.w = rd.w; } -void CPUcore::op_jmp_long() { +void R65816::op_jmp_long() { rd.l = op_readpc(); rd.h = op_readpc(); L rd.b = op_readpc(); regs.pc.d = rd.d & 0xffffff; } -void CPUcore::op_jmp_iaddr() { +void R65816::op_jmp_iaddr() { aa.l = op_readpc(); aa.h = op_readpc(); rd.l = op_readaddr(aa.w + 0); @@ -48,7 +46,7 @@ L rd.h = op_readaddr(aa.w + 1); regs.pc.w = rd.w; } -void CPUcore::op_jmp_iaddrx() { +void R65816::op_jmp_iaddrx() { aa.l = op_readpc(); aa.h = op_readpc(); op_io(); @@ -57,7 +55,7 @@ L rd.h = op_readpbr(aa.w + regs.x.w + 1); regs.pc.w = rd.w; } -void CPUcore::op_jmp_iladdr() { +void R65816::op_jmp_iladdr() { aa.l = op_readpc(); aa.h = op_readpc(); rd.l = op_readaddr(aa.w + 0); @@ -66,7 +64,7 @@ L rd.b = op_readaddr(aa.w + 2); regs.pc.d = rd.d & 0xffffff; } -void CPUcore::op_jsr_addr() { +void R65816::op_jsr_addr() { aa.l = op_readpc(); aa.h = op_readpc(); op_io(); @@ -76,7 +74,7 @@ L op_writestack(regs.pc.l); regs.pc.w = aa.w; } -void CPUcore::op_jsr_long_e() { +void R65816::op_jsr_long_e() { aa.l = op_readpc(); aa.h = op_readpc(); op_writestackn(regs.pc.b); @@ -89,7 +87,7 @@ L op_writestackn(regs.pc.l); regs.s.h = 0x01; } -void CPUcore::op_jsr_long_n() { +void R65816::op_jsr_long_n() { aa.l = op_readpc(); aa.h = op_readpc(); op_writestackn(regs.pc.b); @@ -101,7 +99,7 @@ L op_writestackn(regs.pc.l); regs.pc.d = aa.d & 0xffffff; } -void CPUcore::op_jsr_iaddrx_e() { +void R65816::op_jsr_iaddrx_e() { aa.l = op_readpc(); op_writestackn(regs.pc.h); op_writestackn(regs.pc.l); @@ -113,7 +111,7 @@ L rd.h = op_readpbr(aa.w + regs.x.w + 1); regs.s.h = 0x01; } -void CPUcore::op_jsr_iaddrx_n() { +void R65816::op_jsr_iaddrx_n() { aa.l = op_readpc(); op_writestackn(regs.pc.h); op_writestackn(regs.pc.l); @@ -124,7 +122,7 @@ L rd.h = op_readpbr(aa.w + regs.x.w + 1); regs.pc.w = rd.w; } -void CPUcore::op_rti_e() { +void R65816::op_rti_e() { op_io(); op_io(); regs.p = op_readstack() | 0x30; @@ -133,7 +131,7 @@ L rd.h = op_readstack(); regs.pc.w = rd.w; } -void CPUcore::op_rti_n() { +void R65816::op_rti_n() { op_io(); op_io(); regs.p = op_readstack(); @@ -148,7 +146,7 @@ L rd.b = op_readstack(); update_table(); } -void CPUcore::op_rts() { +void R65816::op_rts() { op_io(); op_io(); rd.l = op_readstack(); @@ -157,7 +155,7 @@ L op_io(); regs.pc.w = ++rd.w; } -void CPUcore::op_rtl_e() { +void R65816::op_rtl_e() { op_io(); op_io(); rd.l = op_readstackn(); @@ -168,7 +166,7 @@ L rd.b = op_readstackn(); regs.s.h = 0x01; } -void CPUcore::op_rtl_n() { +void R65816::op_rtl_n() { op_io(); op_io(); rd.l = op_readstackn(); @@ -177,5 +175,3 @@ L rd.b = op_readstackn(); regs.pc.b = rd.b; regs.pc.w = ++rd.w; } - -#endif diff --git a/bsnes/snes/cpu/core/opcode_read.cpp b/bsnes/processor/r65816/opcode_read.cpp similarity index 68% rename from bsnes/snes/cpu/core/opcode_read.cpp rename to bsnes/processor/r65816/opcode_read.cpp index 61a7feb3..63832c6a 100755 --- a/bsnes/snes/cpu/core/opcode_read.cpp +++ b/bsnes/processor/r65816/opcode_read.cpp @@ -1,35 +1,33 @@ -#ifdef CPUCORE_CPP - -template void CPUcore::op_read_const_b() { +template void R65816::op_read_const_b() { L rd.l = op_readpc(); call(op); } -template void CPUcore::op_read_const_w() { +template void R65816::op_read_const_w() { rd.l = op_readpc(); L rd.h = op_readpc(); call(op); } -void CPUcore::op_read_bit_const_b() { +void R65816::op_read_bit_const_b() { L rd.l = op_readpc(); regs.p.z = ((rd.l & regs.a.l) == 0); } -void CPUcore::op_read_bit_const_w() { +void R65816::op_read_bit_const_w() { rd.l = op_readpc(); L rd.h = op_readpc(); regs.p.z = ((rd.w & regs.a.w) == 0); } -template void CPUcore::op_read_addr_b() { +template void R65816::op_read_addr_b() { aa.l = op_readpc(); aa.h = op_readpc(); L rd.l = op_readdbr(aa.w); call(op); } -template void CPUcore::op_read_addr_w() { +template void R65816::op_read_addr_w() { aa.l = op_readpc(); aa.h = op_readpc(); rd.l = op_readdbr(aa.w + 0); @@ -37,7 +35,7 @@ L rd.h = op_readdbr(aa.w + 1); call(op); } -template void CPUcore::op_read_addrx_b() { +template void R65816::op_read_addrx_b() { aa.l = op_readpc(); aa.h = op_readpc(); op_io_cond4(aa.w, aa.w + regs.x.w); @@ -45,7 +43,7 @@ L rd.l = op_readdbr(aa.w + regs.x.w); call(op); } -template void CPUcore::op_read_addrx_w() { +template void R65816::op_read_addrx_w() { aa.l = op_readpc(); aa.h = op_readpc(); op_io_cond4(aa.w, aa.w + regs.x.w); @@ -54,7 +52,7 @@ L rd.h = op_readdbr(aa.w + regs.x.w + 1); call(op); } -template void CPUcore::op_read_addry_b() { +template void R65816::op_read_addry_b() { aa.l = op_readpc(); aa.h = op_readpc(); op_io_cond4(aa.w, aa.w + regs.y.w); @@ -62,7 +60,7 @@ L rd.l = op_readdbr(aa.w + regs.y.w); call(op); } -template void CPUcore::op_read_addry_w() { +template void R65816::op_read_addry_w() { aa.l = op_readpc(); aa.h = op_readpc(); op_io_cond4(aa.w, aa.w + regs.y.w); @@ -71,7 +69,7 @@ L rd.h = op_readdbr(aa.w + regs.y.w + 1); call(op); } -template void CPUcore::op_read_long_b() { +template void R65816::op_read_long_b() { aa.l = op_readpc(); aa.h = op_readpc(); aa.b = op_readpc(); @@ -79,7 +77,7 @@ L rd.l = op_readlong(aa.d); call(op); } -template void CPUcore::op_read_long_w() { +template void R65816::op_read_long_w() { aa.l = op_readpc(); aa.h = op_readpc(); aa.b = op_readpc(); @@ -88,7 +86,7 @@ L rd.h = op_readlong(aa.d + 1); call(op); } -template void CPUcore::op_read_longx_b() { +template void R65816::op_read_longx_b() { aa.l = op_readpc(); aa.h = op_readpc(); aa.b = op_readpc(); @@ -96,7 +94,7 @@ L rd.l = op_readlong(aa.d + regs.x.w); call(op); } -template void CPUcore::op_read_longx_w() { +template void R65816::op_read_longx_w() { aa.l = op_readpc(); aa.h = op_readpc(); aa.b = op_readpc(); @@ -105,14 +103,14 @@ L rd.h = op_readlong(aa.d + regs.x.w + 1); call(op); } -template void CPUcore::op_read_dp_b() { +template void R65816::op_read_dp_b() { dp = op_readpc(); op_io_cond2(); L rd.l = op_readdp(dp); call(op); } -template void CPUcore::op_read_dp_w() { +template void R65816::op_read_dp_w() { dp = op_readpc(); op_io_cond2(); rd.l = op_readdp(dp + 0); @@ -120,7 +118,7 @@ L rd.h = op_readdp(dp + 1); call(op); } -template void CPUcore::op_read_dpr_b() { +template void R65816::op_read_dpr_b() { dp = op_readpc(); op_io_cond2(); op_io(); @@ -128,7 +126,7 @@ L rd.l = op_readdp(dp + regs.r[n].w); call(op); } -template void CPUcore::op_read_dpr_w() { +template void R65816::op_read_dpr_w() { dp = op_readpc(); op_io_cond2(); op_io(); @@ -137,7 +135,7 @@ L rd.h = op_readdp(dp + regs.r[n].w + 1); call(op); } -template void CPUcore::op_read_idp_b() { +template void R65816::op_read_idp_b() { dp = op_readpc(); op_io_cond2(); aa.l = op_readdp(dp + 0); @@ -146,7 +144,7 @@ L rd.l = op_readdbr(aa.w); call(op); } -template void CPUcore::op_read_idp_w() { +template void R65816::op_read_idp_w() { dp = op_readpc(); op_io_cond2(); aa.l = op_readdp(dp + 0); @@ -156,7 +154,7 @@ L rd.h = op_readdbr(aa.w + 1); call(op); } -template void CPUcore::op_read_idpx_b() { +template void R65816::op_read_idpx_b() { dp = op_readpc(); op_io_cond2(); op_io(); @@ -166,7 +164,7 @@ L rd.l = op_readdbr(aa.w); call(op); } -template void CPUcore::op_read_idpx_w() { +template void R65816::op_read_idpx_w() { dp = op_readpc(); op_io_cond2(); op_io(); @@ -177,7 +175,7 @@ L rd.h = op_readdbr(aa.w + 1); call(op); } -template void CPUcore::op_read_idpy_b() { +template void R65816::op_read_idpy_b() { dp = op_readpc(); op_io_cond2(); aa.l = op_readdp(dp + 0); @@ -187,7 +185,7 @@ L rd.l = op_readdbr(aa.w + regs.y.w); call(op); } -template void CPUcore::op_read_idpy_w() { +template void R65816::op_read_idpy_w() { dp = op_readpc(); op_io_cond2(); aa.l = op_readdp(dp + 0); @@ -198,7 +196,7 @@ L rd.h = op_readdbr(aa.w + regs.y.w + 1); call(op); } -template void CPUcore::op_read_ildp_b() { +template void R65816::op_read_ildp_b() { dp = op_readpc(); op_io_cond2(); aa.l = op_readdp(dp + 0); @@ -208,7 +206,7 @@ L rd.l = op_readlong(aa.d); call(op); } -template void CPUcore::op_read_ildp_w() { +template void R65816::op_read_ildp_w() { dp = op_readpc(); op_io_cond2(); aa.l = op_readdp(dp + 0); @@ -219,7 +217,7 @@ L rd.h = op_readlong(aa.d + 1); call(op); } -template void CPUcore::op_read_ildpy_b() { +template void R65816::op_read_ildpy_b() { dp = op_readpc(); op_io_cond2(); aa.l = op_readdp(dp + 0); @@ -229,7 +227,7 @@ L rd.l = op_readlong(aa.d + regs.y.w); call(op); } -template void CPUcore::op_read_ildpy_w() { +template void R65816::op_read_ildpy_w() { dp = op_readpc(); op_io_cond2(); aa.l = op_readdp(dp + 0); @@ -240,14 +238,14 @@ L rd.h = op_readlong(aa.d + regs.y.w + 1); call(op); } -template void CPUcore::op_read_sr_b() { +template void R65816::op_read_sr_b() { sp = op_readpc(); op_io(); L rd.l = op_readsp(sp); call(op); } -template void CPUcore::op_read_sr_w() { +template void R65816::op_read_sr_w() { sp = op_readpc(); op_io(); rd.l = op_readsp(sp + 0); @@ -255,7 +253,7 @@ L rd.h = op_readsp(sp + 1); call(op); } -template void CPUcore::op_read_isry_b() { +template void R65816::op_read_isry_b() { sp = op_readpc(); op_io(); aa.l = op_readsp(sp + 0); @@ -265,7 +263,7 @@ L rd.l = op_readdbr(aa.w + regs.y.w); call(op); } -template void CPUcore::op_read_isry_w() { +template void R65816::op_read_isry_w() { sp = op_readpc(); op_io(); aa.l = op_readsp(sp + 0); @@ -275,5 +273,3 @@ template void CPUcore::op_read_isry_w() { L rd.h = op_readdbr(aa.w + regs.y.w + 1); call(op); } - -#endif diff --git a/bsnes/snes/cpu/core/opcode_rmw.cpp b/bsnes/processor/r65816/opcode_rmw.cpp similarity index 75% rename from bsnes/snes/cpu/core/opcode_rmw.cpp rename to bsnes/processor/r65816/opcode_rmw.cpp index fed939e1..3aa4f9af 100755 --- a/bsnes/snes/cpu/core/opcode_rmw.cpp +++ b/bsnes/processor/r65816/opcode_rmw.cpp @@ -1,20 +1,18 @@ -#ifdef CPUCORE_CPP - -template void CPUcore::op_adjust_imm_b() { +template void R65816::op_adjust_imm_b() { L op_io_irq(); regs.r[n].l += adjust; regs.p.n = (regs.r[n].l & 0x80); regs.p.z = (regs.r[n].l == 0); } -template void CPUcore::op_adjust_imm_w() { +template void R65816::op_adjust_imm_w() { L op_io_irq(); regs.r[n].w += adjust; regs.p.n = (regs.r[n].w & 0x8000); regs.p.z = (regs.r[n].w == 0); } -void CPUcore::op_asl_imm_b() { +void R65816::op_asl_imm_b() { L op_io_irq(); regs.p.c = (regs.a.l & 0x80); regs.a.l <<= 1; @@ -22,7 +20,7 @@ L op_io_irq(); regs.p.z = (regs.a.l == 0); } -void CPUcore::op_asl_imm_w() { +void R65816::op_asl_imm_w() { L op_io_irq(); regs.p.c = (regs.a.w & 0x8000); regs.a.w <<= 1; @@ -30,7 +28,7 @@ L op_io_irq(); regs.p.z = (regs.a.w == 0); } -void CPUcore::op_lsr_imm_b() { +void R65816::op_lsr_imm_b() { L op_io_irq(); regs.p.c = (regs.a.l & 0x01); regs.a.l >>= 1; @@ -38,7 +36,7 @@ L op_io_irq(); regs.p.z = (regs.a.l == 0); } -void CPUcore::op_lsr_imm_w() { +void R65816::op_lsr_imm_w() { L op_io_irq(); regs.p.c = (regs.a.w & 0x0001); regs.a.w >>= 1; @@ -46,7 +44,7 @@ L op_io_irq(); regs.p.z = (regs.a.w == 0); } -void CPUcore::op_rol_imm_b() { +void R65816::op_rol_imm_b() { L op_io_irq(); bool carry = regs.p.c; regs.p.c = (regs.a.l & 0x80); @@ -55,7 +53,7 @@ L op_io_irq(); regs.p.z = (regs.a.l == 0); } -void CPUcore::op_rol_imm_w() { +void R65816::op_rol_imm_w() { L op_io_irq(); bool carry = regs.p.c; regs.p.c = (regs.a.w & 0x8000); @@ -64,7 +62,7 @@ L op_io_irq(); regs.p.z = (regs.a.w == 0); } -void CPUcore::op_ror_imm_b() { +void R65816::op_ror_imm_b() { L op_io_irq(); bool carry = regs.p.c; regs.p.c = (regs.a.l & 0x01); @@ -73,7 +71,7 @@ L op_io_irq(); regs.p.z = (regs.a.l == 0); } -void CPUcore::op_ror_imm_w() { +void R65816::op_ror_imm_w() { L op_io_irq(); bool carry = regs.p.c; regs.p.c = (regs.a.w & 0x0001); @@ -82,7 +80,7 @@ L op_io_irq(); regs.p.z = (regs.a.w == 0); } -template void CPUcore::op_adjust_addr_b() { +template void R65816::op_adjust_addr_b() { aa.l = op_readpc(); aa.h = op_readpc(); rd.l = op_readdbr(aa.w); @@ -91,7 +89,7 @@ template void CPUcore::op_adjust_addr_b() { L op_writedbr(aa.w, rd.l); } -template void CPUcore::op_adjust_addr_w() { +template void R65816::op_adjust_addr_w() { aa.l = op_readpc(); aa.h = op_readpc(); rd.l = op_readdbr(aa.w + 0); @@ -102,7 +100,7 @@ template void CPUcore::op_adjust_addr_w() { L op_writedbr(aa.w + 0, rd.l); } -template void CPUcore::op_adjust_addrx_b() { +template void R65816::op_adjust_addrx_b() { aa.l = op_readpc(); aa.h = op_readpc(); op_io(); @@ -112,7 +110,7 @@ template void CPUcore::op_adjust_addrx_b() { L op_writedbr(aa.w + regs.x.w, rd.l); } -template void CPUcore::op_adjust_addrx_w() { +template void R65816::op_adjust_addrx_w() { aa.l = op_readpc(); aa.h = op_readpc(); op_io(); @@ -124,7 +122,7 @@ template void CPUcore::op_adjust_addrx_w() { L op_writedbr(aa.w + regs.x.w + 0, rd.l); } -template void CPUcore::op_adjust_dp_b() { +template void R65816::op_adjust_dp_b() { dp = op_readpc(); op_io_cond2(); rd.l = op_readdp(dp); @@ -133,7 +131,7 @@ template void CPUcore::op_adjust_dp_b() { L op_writedp(dp, rd.l); } -template void CPUcore::op_adjust_dp_w() { +template void R65816::op_adjust_dp_w() { dp = op_readpc(); op_io_cond2(); rd.l = op_readdp(dp + 0); @@ -144,7 +142,7 @@ template void CPUcore::op_adjust_dp_w() { L op_writedp(dp + 0, rd.l); } -template void CPUcore::op_adjust_dpx_b() { +template void R65816::op_adjust_dpx_b() { dp = op_readpc(); op_io_cond2(); op_io(); @@ -154,7 +152,7 @@ template void CPUcore::op_adjust_dpx_b() { L op_writedp(dp + regs.x.w, rd.l); } -template void CPUcore::op_adjust_dpx_w() { +template void R65816::op_adjust_dpx_w() { dp = op_readpc(); op_io_cond2(); op_io(); @@ -165,5 +163,3 @@ template void CPUcore::op_adjust_dpx_w() { op_writedp(dp + regs.x.w + 1, rd.h); L op_writedp(dp + regs.x.w + 0, rd.l); } - -#endif diff --git a/bsnes/snes/cpu/core/opcode_write.cpp b/bsnes/processor/r65816/opcode_write.cpp similarity index 77% rename from bsnes/snes/cpu/core/opcode_write.cpp rename to bsnes/processor/r65816/opcode_write.cpp index de85e672..c23208ef 100755 --- a/bsnes/snes/cpu/core/opcode_write.cpp +++ b/bsnes/processor/r65816/opcode_write.cpp @@ -1,26 +1,24 @@ -#ifdef CPUCORE_CPP - -template void CPUcore::op_write_addr_b() { +template void R65816::op_write_addr_b() { aa.l = op_readpc(); aa.h = op_readpc(); L op_writedbr(aa.w, regs.r[n]); } -template void CPUcore::op_write_addr_w() { +template void R65816::op_write_addr_w() { aa.l = op_readpc(); aa.h = op_readpc(); op_writedbr(aa.w + 0, regs.r[n] >> 0); L op_writedbr(aa.w + 1, regs.r[n] >> 8); } -template void CPUcore::op_write_addrr_b() { +template void R65816::op_write_addrr_b() { aa.l = op_readpc(); aa.h = op_readpc(); op_io(); L op_writedbr(aa.w + regs.r[i], regs.r[n]); } -template void CPUcore::op_write_addrr_w() { +template void R65816::op_write_addrr_w() { aa.l = op_readpc(); aa.h = op_readpc(); op_io(); @@ -28,14 +26,14 @@ template void CPUcore::op_write_addrr_w() { L op_writedbr(aa.w + regs.r[i] + 1, regs.r[n] >> 8); } -template void CPUcore::op_write_longr_b() { +template void R65816::op_write_longr_b() { aa.l = op_readpc(); aa.h = op_readpc(); aa.b = op_readpc(); L op_writelong(aa.d + regs.r[i], regs.a.l); } -template void CPUcore::op_write_longr_w() { +template void R65816::op_write_longr_w() { aa.l = op_readpc(); aa.h = op_readpc(); aa.b = op_readpc(); @@ -43,27 +41,27 @@ template void CPUcore::op_write_longr_w() { L op_writelong(aa.d + regs.r[i] + 1, regs.a.h); } -template void CPUcore::op_write_dp_b() { +template void R65816::op_write_dp_b() { dp = op_readpc(); op_io_cond2(); L op_writedp(dp, regs.r[n]); } -template void CPUcore::op_write_dp_w() { +template void R65816::op_write_dp_w() { dp = op_readpc(); op_io_cond2(); op_writedp(dp + 0, regs.r[n] >> 0); L op_writedp(dp + 1, regs.r[n] >> 8); } -template void CPUcore::op_write_dpr_b() { +template void R65816::op_write_dpr_b() { dp = op_readpc(); op_io_cond2(); op_io(); L op_writedp(dp + regs.r[i], regs.r[n]); } -template void CPUcore::op_write_dpr_w() { +template void R65816::op_write_dpr_w() { dp = op_readpc(); op_io_cond2(); op_io(); @@ -71,7 +69,7 @@ template void CPUcore::op_write_dpr_w() { L op_writedp(dp + regs.r[i] + 1, regs.r[n] >> 8); } -void CPUcore::op_sta_idp_b() { +void R65816::op_sta_idp_b() { dp = op_readpc(); op_io_cond2(); aa.l = op_readdp(dp + 0); @@ -79,7 +77,7 @@ void CPUcore::op_sta_idp_b() { L op_writedbr(aa.w, regs.a.l); } -void CPUcore::op_sta_idp_w() { +void R65816::op_sta_idp_w() { dp = op_readpc(); op_io_cond2(); aa.l = op_readdp(dp + 0); @@ -88,7 +86,7 @@ void CPUcore::op_sta_idp_w() { L op_writedbr(aa.w + 1, regs.a.h); } -void CPUcore::op_sta_ildp_b() { +void R65816::op_sta_ildp_b() { dp = op_readpc(); op_io_cond2(); aa.l = op_readdp(dp + 0); @@ -97,7 +95,7 @@ void CPUcore::op_sta_ildp_b() { L op_writelong(aa.d, regs.a.l); } -void CPUcore::op_sta_ildp_w() { +void R65816::op_sta_ildp_w() { dp = op_readpc(); op_io_cond2(); aa.l = op_readdp(dp + 0); @@ -107,7 +105,7 @@ void CPUcore::op_sta_ildp_w() { L op_writelong(aa.d + 1, regs.a.h); } -void CPUcore::op_sta_idpx_b() { +void R65816::op_sta_idpx_b() { dp = op_readpc(); op_io_cond2(); op_io(); @@ -116,7 +114,7 @@ void CPUcore::op_sta_idpx_b() { L op_writedbr(aa.w, regs.a.l); } -void CPUcore::op_sta_idpx_w() { +void R65816::op_sta_idpx_w() { dp = op_readpc(); op_io_cond2(); op_io(); @@ -126,7 +124,7 @@ void CPUcore::op_sta_idpx_w() { L op_writedbr(aa.w + 1, regs.a.h); } -void CPUcore::op_sta_idpy_b() { +void R65816::op_sta_idpy_b() { dp = op_readpc(); op_io_cond2(); aa.l = op_readdp(dp + 0); @@ -135,7 +133,7 @@ void CPUcore::op_sta_idpy_b() { L op_writedbr(aa.w + regs.y.w, regs.a.l); } -void CPUcore::op_sta_idpy_w() { +void R65816::op_sta_idpy_w() { dp = op_readpc(); op_io_cond2(); aa.l = op_readdp(dp + 0); @@ -145,7 +143,7 @@ void CPUcore::op_sta_idpy_w() { L op_writedbr(aa.w + regs.y.w + 1, regs.a.h); } -void CPUcore::op_sta_ildpy_b() { +void R65816::op_sta_ildpy_b() { dp = op_readpc(); op_io_cond2(); aa.l = op_readdp(dp + 0); @@ -154,7 +152,7 @@ void CPUcore::op_sta_ildpy_b() { L op_writelong(aa.d + regs.y.w, regs.a.l); } -void CPUcore::op_sta_ildpy_w() { +void R65816::op_sta_ildpy_w() { dp = op_readpc(); op_io_cond2(); aa.l = op_readdp(dp + 0); @@ -164,20 +162,20 @@ void CPUcore::op_sta_ildpy_w() { L op_writelong(aa.d + regs.y.w + 1, regs.a.h); } -void CPUcore::op_sta_sr_b() { +void R65816::op_sta_sr_b() { sp = op_readpc(); op_io(); L op_writesp(sp, regs.a.l); } -void CPUcore::op_sta_sr_w() { +void R65816::op_sta_sr_w() { sp = op_readpc(); op_io(); op_writesp(sp + 0, regs.a.l); L op_writesp(sp + 1, regs.a.h); } -void CPUcore::op_sta_isry_b() { +void R65816::op_sta_isry_b() { sp = op_readpc(); op_io(); aa.l = op_readsp(sp + 0); @@ -186,7 +184,7 @@ void CPUcore::op_sta_isry_b() { L op_writedbr(aa.w + regs.y.w, regs.a.l); } -void CPUcore::op_sta_isry_w() { +void R65816::op_sta_isry_w() { sp = op_readpc(); op_io(); aa.l = op_readsp(sp + 0); @@ -195,5 +193,3 @@ void CPUcore::op_sta_isry_w() { op_writedbr(aa.w + regs.y.w + 0, regs.a.l); L op_writedbr(aa.w + regs.y.w + 1, regs.a.h); } - -#endif diff --git a/bsnes/snes/cpu/core/core.cpp b/bsnes/processor/r65816/r65816.cpp similarity index 80% rename from bsnes/snes/cpu/core/core.cpp rename to bsnes/processor/r65816/r65816.cpp index e63da01b..eb05aeca 100755 --- a/bsnes/snes/cpu/core/core.cpp +++ b/bsnes/processor/r65816/r65816.cpp @@ -1,11 +1,11 @@ -#include +#include +#include "r65816.hpp" -#define CPUCORE_CPP -namespace SuperFamicom { +namespace Processor { -#include "serialization.cpp" #include "algorithms.cpp" -#include "disassembler/disassembler.cpp" +#include "disassembler.cpp" +#include "serialization.cpp" #define L last_cycle(); #define A 0 @@ -40,7 +40,7 @@ namespace SuperFamicom { // tcd, tcs, tdc, tsc, tsx, txs, // inc, inx, iny, dec, dex, dey, // asl, lsr, rol, ror, nop, xce. -alwaysinline void CPUcore::op_io_irq() { +alwaysinline void R65816::op_io_irq() { if(interrupt_pending()) { //modify I/O cycle to bus read cycle, do not increment PC op_read(regs.pc.d); @@ -49,25 +49,25 @@ alwaysinline void CPUcore::op_io_irq() { } } -alwaysinline void CPUcore::op_io_cond2() { +alwaysinline void R65816::op_io_cond2() { if(regs.d.l != 0x00) { op_io(); } } -alwaysinline void CPUcore::op_io_cond4(uint16 x, uint16 y) { +alwaysinline void R65816::op_io_cond4(uint16 x, uint16 y) { if(!regs.p.x || (x & 0xff00) != (y & 0xff00)) { op_io(); } } -alwaysinline void CPUcore::op_io_cond6(uint16 addr) { +alwaysinline void R65816::op_io_cond6(uint16 addr) { if(regs.e && (regs.pc.w & 0xff00) != (addr & 0xff00)) { op_io(); } } -void CPUcore::op_irq() { +void R65816::op_irq() { op_read(regs.pc.d); op_io(); if(!regs.e) op_writestack(regs.pc.b); @@ -82,7 +82,7 @@ void CPUcore::op_irq() { regs.pc.w = rd.w; } -CPUcore::CPUcore() { +R65816::R65816() { initialize_opcode_table(); } diff --git a/bsnes/snes/cpu/core/core.hpp b/bsnes/processor/r65816/r65816.hpp similarity index 62% rename from bsnes/snes/cpu/core/core.hpp rename to bsnes/processor/r65816/r65816.hpp index 964bd128..29a77b24 100755 --- a/bsnes/snes/cpu/core/core.hpp +++ b/bsnes/processor/r65816/r65816.hpp @@ -1,7 +1,16 @@ -struct CPUcore { +#ifndef PROCESSOR_R65816_HPP +#define PROCESSOR_R65816_HPP + +namespace Processor { + +//WDC 65C816 CPU core +//* Ricoh 5A22 +//* Nintendo SA-1 + +struct R65816 { #include "registers.hpp" #include "memory.hpp" - #include "disassembler/disassembler.hpp" + #include "disassembler.hpp" regs_t regs; reg24_t aa, rd; @@ -14,6 +23,8 @@ struct CPUcore { virtual bool interrupt_pending() = 0; virtual void op_irq(); + virtual uint8 disassembler_read(uint32 addr) { return 0u; } + void op_io_irq(); void op_io_cond2(); void op_io_cond4(uint16 x, uint16 y); @@ -61,38 +72,38 @@ struct CPUcore { void op_tsb_b(); void op_tsb_w(); - template void op_read_const_b(); - template void op_read_const_w(); + template void op_read_const_b(); + template void op_read_const_w(); void op_read_bit_const_b(); void op_read_bit_const_w(); - template void op_read_addr_b(); - template void op_read_addr_w(); - template void op_read_addrx_b(); - template void op_read_addrx_w(); - template void op_read_addry_b(); - template void op_read_addry_w(); - template void op_read_long_b(); - template void op_read_long_w(); - template void op_read_longx_b(); - template void op_read_longx_w(); - template void op_read_dp_b(); - template void op_read_dp_w(); - template void op_read_dpr_b(); - template void op_read_dpr_w(); - template void op_read_idp_b(); - template void op_read_idp_w(); - template void op_read_idpx_b(); - template void op_read_idpx_w(); - template void op_read_idpy_b(); - template void op_read_idpy_w(); - template void op_read_ildp_b(); - template void op_read_ildp_w(); - template void op_read_ildpy_b(); - template void op_read_ildpy_w(); - template void op_read_sr_b(); - template void op_read_sr_w(); - template void op_read_isry_b(); - template void op_read_isry_w(); + template void op_read_addr_b(); + template void op_read_addr_w(); + template void op_read_addrx_b(); + template void op_read_addrx_w(); + template void op_read_addry_b(); + template void op_read_addry_w(); + template void op_read_long_b(); + template void op_read_long_w(); + template void op_read_longx_b(); + template void op_read_longx_w(); + template void op_read_dp_b(); + template void op_read_dp_w(); + template void op_read_dpr_b(); + template void op_read_dpr_w(); + template void op_read_idp_b(); + template void op_read_idp_w(); + template void op_read_idpx_b(); + template void op_read_idpx_w(); + template void op_read_idpy_b(); + template void op_read_idpy_w(); + template void op_read_ildp_b(); + template void op_read_ildp_w(); + template void op_read_ildpy_b(); + template void op_read_ildpy_w(); + template void op_read_sr_b(); + template void op_read_sr_w(); + template void op_read_isry_b(); + template void op_read_isry_w(); template void op_write_addr_b(); template void op_write_addr_w(); @@ -129,14 +140,14 @@ struct CPUcore { void op_rol_imm_w(); void op_ror_imm_b(); void op_ror_imm_w(); - template void op_adjust_addr_b(); - template void op_adjust_addr_w(); - template void op_adjust_addrx_b(); - template void op_adjust_addrx_w(); - template void op_adjust_dp_b(); - template void op_adjust_dp_w(); - template void op_adjust_dpx_b(); - template void op_adjust_dpx_w(); + template void op_adjust_addr_b(); + template void op_adjust_addr_w(); + template void op_adjust_addrx_b(); + template void op_adjust_addrx_w(); + template void op_adjust_dp_b(); + template void op_adjust_dp_w(); + template void op_adjust_dpx_b(); + template void op_adjust_dpx_w(); template void op_branch(); void op_bra(); @@ -199,8 +210,8 @@ struct CPUcore { void op_per_e(); void op_per_n(); - void (CPUcore::**opcode_table)(); - void (CPUcore::*op_table[256 * 5])(); + void (R65816::**opcode_table)(); + void (R65816::*op_table[5 * 256])(); void initialize_opcode_table(); void update_table(); @@ -212,6 +223,10 @@ struct CPUcore { table_mx = 1024, //16-bit accumulator, 16-bit index }; - void core_serialize(serializer&); - CPUcore(); + void serialize(serializer&); + R65816(); }; + +} + +#endif diff --git a/bsnes/snes/cpu/core/registers.hpp b/bsnes/processor/r65816/registers.hpp similarity index 100% rename from bsnes/snes/cpu/core/registers.hpp rename to bsnes/processor/r65816/registers.hpp diff --git a/bsnes/snes/cpu/core/serialization.cpp b/bsnes/processor/r65816/serialization.cpp similarity index 88% rename from bsnes/snes/cpu/core/serialization.cpp rename to bsnes/processor/r65816/serialization.cpp index 81753e96..06db3cb4 100755 --- a/bsnes/snes/cpu/core/serialization.cpp +++ b/bsnes/processor/r65816/serialization.cpp @@ -1,6 +1,4 @@ -#ifdef CPUCORE_CPP - -void CPUcore::core_serialize(serializer &s) { +void R65816::serialize(serializer &s) { s.integer(regs.pc.d); s.integer(regs.a.w); @@ -33,5 +31,3 @@ void CPUcore::core_serialize(serializer &s) { update_table(); } - -#endif diff --git a/bsnes/snes/cpu/core/table.cpp b/bsnes/processor/r65816/table.cpp similarity index 77% rename from bsnes/snes/cpu/core/table.cpp rename to bsnes/processor/r65816/table.cpp index 6575a4db..7a7a5e6c 100755 --- a/bsnes/snes/cpu/core/table.cpp +++ b/bsnes/processor/r65816/table.cpp @@ -1,21 +1,19 @@ -#ifdef CPUCORE_CPP - -void CPUcore::initialize_opcode_table() { - #define opA( id, name ) op_table[table_EM + id] = op_table[table_MX + id] = op_table[table_Mx + id] = op_table[table_mX + id] = op_table[table_mx + id] = &CPUcore::op_##name; - #define opAII(id, name, x, y ) op_table[table_EM + id] = op_table[table_MX + id] = op_table[table_Mx + id] = op_table[table_mX + id] = op_table[table_mx + id] = &CPUcore::op_##name; - #define opE( id, name ) op_table[table_EM + id] = &CPUcore::op_##name##_e; op_table[table_MX + id] = op_table[table_Mx + id] = op_table[table_mX + id] = op_table[table_mx + id] = &CPUcore::op_##name##_n; - #define opEI( id, name, x ) op_table[table_EM + id] = &CPUcore::op_##name##_e; op_table[table_MX + id] = op_table[table_Mx + id] = op_table[table_mX + id] = op_table[table_mx + id] = &CPUcore::op_##name##_n; - #define opEII(id, name, x, y ) op_table[table_EM + id] = &CPUcore::op_##name##_e; op_table[table_MX + id] = op_table[table_Mx + id] = op_table[table_mX + id] = op_table[table_mx + id] = &CPUcore::op_##name##_n; - #define opM( id, name ) op_table[table_EM + id] = op_table[table_MX + id] = op_table[table_Mx + id] = &CPUcore::op_##name##_b; op_table[table_mX + id] = op_table[table_mx + id] = &CPUcore::op_##name##_w; - #define opMI( id, name, x ) op_table[table_EM + id] = op_table[table_MX + id] = op_table[table_Mx + id] = &CPUcore::op_##name##_b; op_table[table_mX + id] = op_table[table_mx + id] = &CPUcore::op_##name##_w; - #define opMII(id, name, x, y ) op_table[table_EM + id] = op_table[table_MX + id] = op_table[table_Mx + id] = &CPUcore::op_##name##_b; op_table[table_mX + id] = op_table[table_mx + id] = &CPUcore::op_##name##_w; - #define opMF( id, name, fn ) op_table[table_EM + id] = op_table[table_MX + id] = op_table[table_Mx + id] = &CPUcore::op_##name##_b<&CPUcore::op_##fn##_b>; op_table[table_mX + id] = op_table[table_mx + id] = &CPUcore::op_##name##_w<&CPUcore::op_##fn##_w>; - #define opMFI(id, name, fn, x) op_table[table_EM + id] = op_table[table_MX + id] = op_table[table_Mx + id] = &CPUcore::op_##name##_b<&CPUcore::op_##fn##_b, x>; op_table[table_mX + id] = op_table[table_mx + id] = &CPUcore::op_##name##_w<&CPUcore::op_##fn##_w, x>; - #define opX( id, name ) op_table[table_EM + id] = op_table[table_MX + id] = op_table[table_mX + id] = &CPUcore::op_##name##_b; op_table[table_Mx + id] = op_table[table_mx + id] = &CPUcore::op_##name##_w; - #define opXI( id, name, x ) op_table[table_EM + id] = op_table[table_MX + id] = op_table[table_mX + id] = &CPUcore::op_##name##_b; op_table[table_Mx + id] = op_table[table_mx + id] = &CPUcore::op_##name##_w; - #define opXII(id, name, x, y ) op_table[table_EM + id] = op_table[table_MX + id] = op_table[table_mX + id] = &CPUcore::op_##name##_b; op_table[table_Mx + id] = op_table[table_mx + id] = &CPUcore::op_##name##_w; - #define opXF( id, name, fn ) op_table[table_EM + id] = op_table[table_MX + id] = op_table[table_mX + id] = &CPUcore::op_##name##_b<&CPUcore::op_##fn##_b>; op_table[table_Mx + id] = op_table[table_mx + id] = &CPUcore::op_##name##_w<&CPUcore::op_##fn##_w>; - #define opXFI(id, name, fn, x) op_table[table_EM + id] = op_table[table_MX + id] = op_table[table_mX + id] = &CPUcore::op_##name##_b<&CPUcore::op_##fn##_b, x>; op_table[table_Mx + id] = op_table[table_mx + id] = &CPUcore::op_##name##_w<&CPUcore::op_##fn##_w, x>; +void R65816::initialize_opcode_table() { + #define opA( id, name ) op_table[table_EM + id] = op_table[table_MX + id] = op_table[table_Mx + id] = op_table[table_mX + id] = op_table[table_mx + id] = &R65816::op_##name; + #define opAII(id, name, x, y ) op_table[table_EM + id] = op_table[table_MX + id] = op_table[table_Mx + id] = op_table[table_mX + id] = op_table[table_mx + id] = &R65816::op_##name; + #define opE( id, name ) op_table[table_EM + id] = &R65816::op_##name##_e; op_table[table_MX + id] = op_table[table_Mx + id] = op_table[table_mX + id] = op_table[table_mx + id] = &R65816::op_##name##_n; + #define opEI( id, name, x ) op_table[table_EM + id] = &R65816::op_##name##_e; op_table[table_MX + id] = op_table[table_Mx + id] = op_table[table_mX + id] = op_table[table_mx + id] = &R65816::op_##name##_n; + #define opEII(id, name, x, y ) op_table[table_EM + id] = &R65816::op_##name##_e; op_table[table_MX + id] = op_table[table_Mx + id] = op_table[table_mX + id] = op_table[table_mx + id] = &R65816::op_##name##_n; + #define opM( id, name ) op_table[table_EM + id] = op_table[table_MX + id] = op_table[table_Mx + id] = &R65816::op_##name##_b; op_table[table_mX + id] = op_table[table_mx + id] = &R65816::op_##name##_w; + #define opMI( id, name, x ) op_table[table_EM + id] = op_table[table_MX + id] = op_table[table_Mx + id] = &R65816::op_##name##_b; op_table[table_mX + id] = op_table[table_mx + id] = &R65816::op_##name##_w; + #define opMII(id, name, x, y ) op_table[table_EM + id] = op_table[table_MX + id] = op_table[table_Mx + id] = &R65816::op_##name##_b; op_table[table_mX + id] = op_table[table_mx + id] = &R65816::op_##name##_w; + #define opMF( id, name, fn ) op_table[table_EM + id] = op_table[table_MX + id] = op_table[table_Mx + id] = &R65816::op_##name##_b<&R65816::op_##fn##_b>; op_table[table_mX + id] = op_table[table_mx + id] = &R65816::op_##name##_w<&R65816::op_##fn##_w>; + #define opMFI(id, name, fn, x) op_table[table_EM + id] = op_table[table_MX + id] = op_table[table_Mx + id] = &R65816::op_##name##_b<&R65816::op_##fn##_b, x>; op_table[table_mX + id] = op_table[table_mx + id] = &R65816::op_##name##_w<&R65816::op_##fn##_w, x>; + #define opX( id, name ) op_table[table_EM + id] = op_table[table_MX + id] = op_table[table_mX + id] = &R65816::op_##name##_b; op_table[table_Mx + id] = op_table[table_mx + id] = &R65816::op_##name##_w; + #define opXI( id, name, x ) op_table[table_EM + id] = op_table[table_MX + id] = op_table[table_mX + id] = &R65816::op_##name##_b; op_table[table_Mx + id] = op_table[table_mx + id] = &R65816::op_##name##_w; + #define opXII(id, name, x, y ) op_table[table_EM + id] = op_table[table_MX + id] = op_table[table_mX + id] = &R65816::op_##name##_b; op_table[table_Mx + id] = op_table[table_mx + id] = &R65816::op_##name##_w; + #define opXF( id, name, fn ) op_table[table_EM + id] = op_table[table_MX + id] = op_table[table_mX + id] = &R65816::op_##name##_b<&R65816::op_##fn##_b>; op_table[table_Mx + id] = op_table[table_mx + id] = &R65816::op_##name##_w<&R65816::op_##fn##_w>; + #define opXFI(id, name, fn, x) op_table[table_EM + id] = op_table[table_MX + id] = op_table[table_mX + id] = &R65816::op_##name##_b<&R65816::op_##fn##_b, x>; op_table[table_Mx + id] = op_table[table_mx + id] = &R65816::op_##name##_w<&R65816::op_##fn##_w, x>; opEII(0x00, interrupt, 0xfffe, 0xffe6) opMF (0x01, read_idpx, ora) @@ -291,7 +289,7 @@ void CPUcore::initialize_opcode_table() { #undef opXFI } -void CPUcore::update_table() { +void R65816::update_table() { if(regs.e) { opcode_table = &op_table[table_EM]; } else if(regs.p.m) { @@ -308,5 +306,3 @@ void CPUcore::update_table() { } } } - -#endif diff --git a/bsnes/processor/rp2a03/rp2a03.cpp b/bsnes/processor/rp2a03/rp2a03.cpp deleted file mode 100755 index 2cb39374..00000000 --- a/bsnes/processor/rp2a03/rp2a03.cpp +++ /dev/null @@ -1,241 +0,0 @@ -#include -#include "rp2a03.hpp" - -namespace Processor { - -#define I -#define L last_cycle(); -#define call(op) (this->*op)() - -#include "memory.cpp" -#include "instructions.cpp" -#include "disassembler.cpp" -#include "serialization.cpp" - -uint8 RP2A03::mdr() const { - return regs.mdr; -} - -void RP2A03::power() { - regs.a = 0x00; - regs.x = 0x00; - regs.y = 0x00; - regs.s = 0x00; - regs.p = 0x04; -} - -void RP2A03::reset() { - regs.mdr = 0x00; - regs.s -= 3; - regs.p.i = 1; -} - -void RP2A03::interrupt() { - op_readpc(); - op_readpc(); - op_writesp(regs.pc >> 8); - op_writesp(regs.pc >> 0); - op_writesp(regs.p | 0x20); - uint16 vector = 0xfffe; //IRQ - nmi(vector); - abs.l = op_read(vector++); - regs.p.i = 1; - regs.p.d = 0; -L abs.h = op_read(vector++); - regs.pc = abs.w; -} - -void RP2A03::exec() { - uint8 opcode = op_readpci(); - switch(opcode) { - case 0x00: return op_brk(); - case 0x01: return opi_read_indirect_zero_page_x<&RP2A03::opf_ora>(); -I case 0x04: return opill_nop_zero_page(); - case 0x05: return opi_read_zero_page<&RP2A03::opf_ora>(); - case 0x06: return opi_rmw_zero_page<&RP2A03::opf_asl>(); - case 0x08: return op_php(); - case 0x09: return opi_read_immediate<&RP2A03::opf_ora>(); - case 0x0a: return opi_shift<&RP2A03::opf_sla>(); -I case 0x0c: return opill_nop_absolute(); - case 0x0d: return opi_read_absolute<&RP2A03::opf_ora>(); - case 0x0e: return opi_rmw_absolute<&RP2A03::opf_asl>(); - case 0x10: return opi_branch(regs.p.n == 0); - case 0x11: return opi_read_indirect_zero_page_y<&RP2A03::opf_ora>(); -I case 0x14: return opill_nop_zero_page_x(); - case 0x15: return opi_read_zero_page_x<&RP2A03::opf_ora>(); - case 0x16: return opi_rmw_zero_page_x<&RP2A03::opf_asl>(); - case 0x18: return opi_clear_flag(regs.p.c); - case 0x19: return opi_read_absolute_y<&RP2A03::opf_ora>(); -I case 0x1a: return opill_nop_implied(); -I case 0x1c: return opill_nop_absolute_x(); - case 0x1d: return opi_read_absolute_x<&RP2A03::opf_ora>(); - case 0x1e: return opi_rmw_absolute_x<&RP2A03::opf_asl>(); - case 0x20: return op_jsr_absolute(); - case 0x21: return opi_read_indirect_zero_page_x<&RP2A03::opf_and>(); - case 0x24: return opi_read_zero_page<&RP2A03::opf_bit>(); - case 0x25: return opi_read_zero_page<&RP2A03::opf_and>(); - case 0x26: return opi_rmw_zero_page<&RP2A03::opf_rol>(); - case 0x28: return op_plp(); - case 0x29: return opi_read_immediate<&RP2A03::opf_and>(); - case 0x2a: return opi_shift<&RP2A03::opf_rla>(); - case 0x2c: return opi_read_absolute<&RP2A03::opf_bit>(); - case 0x2d: return opi_read_absolute<&RP2A03::opf_and>(); - case 0x2e: return opi_rmw_absolute<&RP2A03::opf_rol>(); - case 0x30: return opi_branch(regs.p.n == 1); - case 0x31: return opi_read_indirect_zero_page_y<&RP2A03::opf_and>(); -I case 0x34: return opill_nop_zero_page_x(); - case 0x35: return opi_read_zero_page_x<&RP2A03::opf_and>(); - case 0x36: return opi_rmw_zero_page_x<&RP2A03::opf_rol>(); - case 0x38: return opi_set_flag(regs.p.c); - case 0x39: return opi_read_absolute_y<&RP2A03::opf_and>(); -I case 0x3a: return opill_nop_implied(); -I case 0x3c: return opill_nop_absolute_x(); - case 0x3d: return opi_read_absolute_x<&RP2A03::opf_and>(); - case 0x3e: return opi_rmw_absolute_x<&RP2A03::opf_rol>(); - case 0x40: return op_rti(); - case 0x41: return opi_read_indirect_zero_page_x<&RP2A03::opf_eor>(); -I case 0x44: return opill_nop_zero_page(); - case 0x45: return opi_read_zero_page<&RP2A03::opf_eor>(); - case 0x46: return opi_rmw_zero_page<&RP2A03::opf_lsr>(); - case 0x48: return opi_push(regs.a); - case 0x49: return opi_read_immediate<&RP2A03::opf_eor>(); - case 0x4a: return opi_shift<&RP2A03::opf_sra>(); - case 0x4c: return op_jmp_absolute(); - case 0x4d: return opi_read_absolute<&RP2A03::opf_eor>(); - case 0x4e: return opi_rmw_absolute<&RP2A03::opf_lsr>(); - case 0x50: return opi_branch(regs.p.v == 0); - case 0x51: return opi_read_indirect_zero_page_y<&RP2A03::opf_eor>(); -I case 0x54: return opill_nop_zero_page_x(); - case 0x55: return opi_read_zero_page_x<&RP2A03::opf_eor>(); - case 0x56: return opi_rmw_zero_page_x<&RP2A03::opf_lsr>(); - case 0x58: return opi_clear_flag(regs.p.i); - case 0x59: return opi_read_absolute_y<&RP2A03::opf_eor>(); -I case 0x5a: return opill_nop_implied(); -I case 0x5c: return opill_nop_absolute_x(); - case 0x5d: return opi_read_absolute_x<&RP2A03::opf_eor>(); - case 0x5e: return opi_rmw_absolute_x<&RP2A03::opf_lsr>(); - case 0x60: return op_rts(); - case 0x61: return opi_read_indirect_zero_page_x<&RP2A03::opf_adc>(); -I case 0x64: return opill_nop_zero_page(); - case 0x65: return opi_read_zero_page<&RP2A03::opf_adc>(); - case 0x66: return opi_rmw_zero_page<&RP2A03::opf_ror>(); - case 0x68: return opi_pull(regs.a); - case 0x69: return opi_read_immediate<&RP2A03::opf_adc>(); - case 0x6a: return opi_shift<&RP2A03::opf_rra>(); -I case 0x6b: return opill_arr_immediate(); - case 0x6c: return op_jmp_indirect_absolute(); - case 0x6d: return opi_read_absolute<&RP2A03::opf_adc>(); - case 0x6e: return opi_rmw_absolute<&RP2A03::opf_ror>(); - case 0x70: return opi_branch(regs.p.v == 1); -I case 0x74: return opill_nop_zero_page_x(); - case 0x71: return opi_read_indirect_zero_page_y<&RP2A03::opf_adc>(); - case 0x75: return opi_read_zero_page_x<&RP2A03::opf_adc>(); - case 0x76: return opi_rmw_zero_page_x<&RP2A03::opf_ror>(); - case 0x78: return opi_set_flag(regs.p.i); - case 0x79: return opi_read_absolute_y<&RP2A03::opf_adc>(); -I case 0x7a: return opill_nop_implied(); -I case 0x7c: return opill_nop_absolute_x(); - case 0x7d: return opi_read_absolute_x<&RP2A03::opf_adc>(); - case 0x7e: return opi_rmw_absolute_x<&RP2A03::opf_ror>(); -I case 0x80: return opill_nop_absolute(); - case 0x81: return opi_store_indirect_zero_page_x(regs.a); -I case 0x82: return opill_nop_immediate(); - case 0x84: return opi_store_zero_page(regs.y); - case 0x85: return opi_store_zero_page(regs.a); - case 0x86: return opi_store_zero_page(regs.x); - case 0x88: return opi_decrement(regs.y); -I case 0x89: return opill_nop_immediate(); - case 0x8a: return opi_transfer(regs.x, regs.a, 1); - case 0x8c: return opi_store_absolute(regs.y); - case 0x8d: return opi_store_absolute(regs.a); - case 0x8e: return opi_store_absolute(regs.x); - case 0x90: return opi_branch(regs.p.c == 0); - case 0x91: return opi_store_indirect_zero_page_y(regs.a); - case 0x94: return opi_store_zero_page_x(regs.y); - case 0x95: return opi_store_zero_page_x(regs.a); - case 0x96: return opi_store_zero_page_y(regs.x); - case 0x98: return opi_transfer(regs.y, regs.a, 1); - case 0x99: return opi_store_absolute_y(regs.a); - case 0x9a: return opi_transfer(regs.x, regs.s, 0); - case 0x9d: return opi_store_absolute_x(regs.a); - case 0xa0: return opi_read_immediate<&RP2A03::opf_ldy>(); - case 0xa1: return opi_read_indirect_zero_page_x<&RP2A03::opf_lda>(); - case 0xa2: return opi_read_immediate<&RP2A03::opf_ldx>(); - case 0xa4: return opi_read_zero_page<&RP2A03::opf_ldy>(); - case 0xa5: return opi_read_zero_page<&RP2A03::opf_lda>(); - case 0xa6: return opi_read_zero_page<&RP2A03::opf_ldx>(); - case 0xa8: return opi_transfer(regs.a, regs.y, 1); - case 0xa9: return opi_read_immediate<&RP2A03::opf_lda>(); - case 0xaa: return opi_transfer(regs.a, regs.x, 1); - case 0xac: return opi_read_absolute<&RP2A03::opf_ldy>(); - case 0xad: return opi_read_absolute<&RP2A03::opf_lda>(); - case 0xae: return opi_read_absolute<&RP2A03::opf_ldx>(); - case 0xb0: return opi_branch(regs.p.c == 1); - case 0xb1: return opi_read_indirect_zero_page_y<&RP2A03::opf_lda>(); - case 0xb4: return opi_read_zero_page_x<&RP2A03::opf_ldy>(); - case 0xb5: return opi_read_zero_page_x<&RP2A03::opf_lda>(); - case 0xb6: return opi_read_zero_page_y<&RP2A03::opf_ldx>(); - case 0xb8: return opi_clear_flag(regs.p.v); - case 0xb9: return opi_read_absolute_y<&RP2A03::opf_lda>(); - case 0xba: return opi_transfer(regs.s, regs.x, 1); - case 0xbc: return opi_read_absolute_x<&RP2A03::opf_ldy>(); - case 0xbd: return opi_read_absolute_x<&RP2A03::opf_lda>(); - case 0xbe: return opi_read_absolute_y<&RP2A03::opf_ldx>(); - case 0xc0: return opi_read_immediate<&RP2A03::opf_cpy>(); - case 0xc1: return opi_read_indirect_zero_page_x<&RP2A03::opf_cmp>(); -I case 0xc2: return opill_nop_immediate(); - case 0xc4: return opi_read_zero_page<&RP2A03::opf_cpy>(); - case 0xc5: return opi_read_zero_page<&RP2A03::opf_cmp>(); - case 0xc6: return opi_rmw_zero_page<&RP2A03::opf_dec>(); - case 0xc8: return opi_increment(regs.y); - case 0xc9: return opi_read_immediate<&RP2A03::opf_cmp>(); - case 0xca: return opi_decrement(regs.x); - case 0xcc: return opi_read_absolute<&RP2A03::opf_cpy>(); - case 0xcd: return opi_read_absolute<&RP2A03::opf_cmp>(); - case 0xce: return opi_rmw_absolute<&RP2A03::opf_dec>(); - case 0xd0: return opi_branch(regs.p.z == 0); - case 0xd1: return opi_read_indirect_zero_page_y<&RP2A03::opf_cmp>(); -I case 0xd4: return opill_nop_zero_page_x(); - case 0xd5: return opi_read_zero_page_x<&RP2A03::opf_cmp>(); - case 0xd6: return opi_rmw_zero_page_x<&RP2A03::opf_dec>(); - case 0xd8: return opi_clear_flag(regs.p.d); - case 0xd9: return opi_read_absolute_y<&RP2A03::opf_cmp>(); -I case 0xda: return opill_nop_implied(); -I case 0xdc: return opill_nop_absolute_x(); - case 0xdd: return opi_read_absolute_x<&RP2A03::opf_cmp>(); - case 0xde: return opi_rmw_absolute_x<&RP2A03::opf_dec>(); - case 0xe0: return opi_read_immediate<&RP2A03::opf_cpx>(); - case 0xe1: return opi_read_indirect_zero_page_x<&RP2A03::opf_sbc>(); -I case 0xe2: return opill_nop_immediate(); - case 0xe4: return opi_read_zero_page<&RP2A03::opf_cpx>(); - case 0xe5: return opi_read_zero_page<&RP2A03::opf_sbc>(); - case 0xe6: return opi_rmw_zero_page<&RP2A03::opf_inc>(); - case 0xe8: return opi_increment(regs.x); - case 0xe9: return opi_read_immediate<&RP2A03::opf_sbc>(); - case 0xea: return op_nop(); -I case 0xeb: return opi_read_immediate<&RP2A03::opf_sbc>(); - case 0xec: return opi_read_absolute<&RP2A03::opf_cpx>(); - case 0xed: return opi_read_absolute<&RP2A03::opf_sbc>(); - case 0xee: return opi_rmw_absolute<&RP2A03::opf_inc>(); - case 0xf0: return opi_branch(regs.p.z == 1); - case 0xf1: return opi_read_indirect_zero_page_y<&RP2A03::opf_sbc>(); -I case 0xf4: return opill_nop_zero_page_x(); - case 0xf5: return opi_read_zero_page_x<&RP2A03::opf_sbc>(); - case 0xf6: return opi_rmw_zero_page_x<&RP2A03::opf_inc>(); - case 0xf8: return opi_set_flag(regs.p.d); - case 0xf9: return opi_read_absolute_y<&RP2A03::opf_sbc>(); -I case 0xfa: return opill_nop_implied(); -I case 0xfc: return opill_nop_absolute_x(); - case 0xfd: return opi_read_absolute_x<&RP2A03::opf_sbc>(); - case 0xfe: return opi_rmw_absolute_x<&RP2A03::opf_inc>(); - } - - //unimplemented opcode - return op_nop(); -} - -#undef I -#undef L -#undef call - -} diff --git a/bsnes/snes/smp/core/algorithms.cpp b/bsnes/processor/spc700/algorithms.cpp similarity index 68% rename from bsnes/snes/smp/core/algorithms.cpp rename to bsnes/processor/spc700/algorithms.cpp index 69504cdf..65451cc2 100755 --- a/bsnes/snes/smp/core/algorithms.cpp +++ b/bsnes/processor/spc700/algorithms.cpp @@ -1,6 +1,4 @@ -#ifdef SMPCORE_CPP - -uint8 SMPcore::op_adc(uint8 x, uint8 y) { +uint8 SPC700::op_adc(uint8 x, uint8 y) { int r = x + y + regs.p.c; regs.p.n = r & 0x80; regs.p.v = ~(x ^ y) & (x ^ r) & 0x80; @@ -10,14 +8,14 @@ uint8 SMPcore::op_adc(uint8 x, uint8 y) { return r; } -uint8 SMPcore::op_and(uint8 x, uint8 y) { +uint8 SPC700::op_and(uint8 x, uint8 y) { x &= y; regs.p.n = x & 0x80; regs.p.z = x == 0; return x; } -uint8 SMPcore::op_asl(uint8 x) { +uint8 SPC700::op_asl(uint8 x) { regs.p.c = x & 0x80; x <<= 1; regs.p.n = x & 0x80; @@ -25,7 +23,7 @@ uint8 SMPcore::op_asl(uint8 x) { return x; } -uint8 SMPcore::op_cmp(uint8 x, uint8 y) { +uint8 SPC700::op_cmp(uint8 x, uint8 y) { int r = x - y; regs.p.n = r & 0x80; regs.p.z = (uint8)r == 0; @@ -33,34 +31,34 @@ uint8 SMPcore::op_cmp(uint8 x, uint8 y) { return x; } -uint8 SMPcore::op_dec(uint8 x) { +uint8 SPC700::op_dec(uint8 x) { x--; regs.p.n = x & 0x80; regs.p.z = x == 0; return x; } -uint8 SMPcore::op_eor(uint8 x, uint8 y) { +uint8 SPC700::op_eor(uint8 x, uint8 y) { x ^= y; regs.p.n = x & 0x80; regs.p.z = x == 0; return x; } -uint8 SMPcore::op_inc(uint8 x) { +uint8 SPC700::op_inc(uint8 x) { x++; regs.p.n = x & 0x80; regs.p.z = x == 0; return x; } -uint8 SMPcore::op_ld(uint8 x, uint8 y) { +uint8 SPC700::op_ld(uint8 x, uint8 y) { regs.p.n = y & 0x80; regs.p.z = y == 0; return y; } -uint8 SMPcore::op_lsr(uint8 x) { +uint8 SPC700::op_lsr(uint8 x) { regs.p.c = x & 0x01; x >>= 1; regs.p.n = x & 0x80; @@ -68,14 +66,14 @@ uint8 SMPcore::op_lsr(uint8 x) { return x; } -uint8 SMPcore::op_or(uint8 x, uint8 y) { +uint8 SPC700::op_or(uint8 x, uint8 y) { x |= y; regs.p.n = x & 0x80; regs.p.z = x == 0; return x; } -uint8 SMPcore::op_rol(uint8 x) { +uint8 SPC700::op_rol(uint8 x) { unsigned carry = regs.p.c << 0; regs.p.c = x & 0x80; x = (x << 1) | carry; @@ -84,7 +82,7 @@ uint8 SMPcore::op_rol(uint8 x) { return x; } -uint8 SMPcore::op_ror(uint8 x) { +uint8 SPC700::op_ror(uint8 x) { unsigned carry = regs.p.c << 7; regs.p.c = x & 0x01; x = carry | (x >> 1); @@ -93,17 +91,17 @@ uint8 SMPcore::op_ror(uint8 x) { return x; } -uint8 SMPcore::op_sbc(uint8 x, uint8 y) { +uint8 SPC700::op_sbc(uint8 x, uint8 y) { return op_adc(x, ~y); } -uint8 SMPcore::op_st(uint8 x, uint8 y) { +uint8 SPC700::op_st(uint8 x, uint8 y) { return y; } // -uint16 SMPcore::op_adw(uint16 x, uint16 y) { +uint16 SPC700::op_adw(uint16 x, uint16 y) { uint16 r; regs.p.c = 0; r = op_adc(x, y); @@ -112,7 +110,7 @@ uint16 SMPcore::op_adw(uint16 x, uint16 y) { return r; } -uint16 SMPcore::op_cpw(uint16 x, uint16 y) { +uint16 SPC700::op_cpw(uint16 x, uint16 y) { int r = x - y; regs.p.n = r & 0x8000; regs.p.z = (uint16)r == 0; @@ -120,13 +118,13 @@ uint16 SMPcore::op_cpw(uint16 x, uint16 y) { return x; } -uint16 SMPcore::op_ldw(uint16 x, uint16 y) { +uint16 SPC700::op_ldw(uint16 x, uint16 y) { regs.p.n = y & 0x8000; regs.p.z = y == 0; return y; } -uint16 SMPcore::op_sbw(uint16 x, uint16 y) { +uint16 SPC700::op_sbw(uint16 x, uint16 y) { uint16 r; regs.p.c = 1; r = op_sbc(x, y); @@ -134,5 +132,3 @@ uint16 SMPcore::op_sbw(uint16 x, uint16 y) { regs.p.z = r == 0; return r; } - -#endif diff --git a/bsnes/snes/smp/core/disassembler.cpp b/bsnes/processor/spc700/disassembler.cpp similarity index 98% rename from bsnes/snes/smp/core/disassembler.cpp rename to bsnes/processor/spc700/disassembler.cpp index e1b1d89a..9c95d2e1 100755 --- a/bsnes/snes/smp/core/disassembler.cpp +++ b/bsnes/processor/spc700/disassembler.cpp @@ -1,10 +1,6 @@ -#ifdef SMPCORE_CPP - -string SMPcore::disassemble_opcode(uint16 addr) { +string SPC700::disassemble_opcode(uint16 addr) { auto read = [&](uint16 addr) -> uint8 { - if((addr & 0xfff0) == 0x00f0) return 0x00; - if((addr & 0xffc0) == 0xffc0) return smp.iplrom[addr & 0x3f]; - return smp.apuram[addr]; + return disassembler_read(addr); }; auto relative = [&](unsigned length, int8 offset) -> uint16 { @@ -307,5 +303,3 @@ string SMPcore::disassemble_opcode(uint16 addr) { return output; } - -#endif diff --git a/bsnes/snes/smp/core/opcodes.cpp b/bsnes/processor/spc700/instructions.cpp similarity index 72% rename from bsnes/snes/smp/core/opcodes.cpp rename to bsnes/processor/spc700/instructions.cpp index 95b9844f..101661da 100755 --- a/bsnes/snes/smp/core/opcodes.cpp +++ b/bsnes/processor/spc700/instructions.cpp @@ -1,14 +1,13 @@ -#ifdef SMPCORE_CPP #define call (this->*op) -template -void SMPcore::op_adjust(uint8 &r) { +template +void SPC700::op_adjust(uint8 &r) { op_io(); r = call(r); } -template -void SMPcore::op_adjust_addr() { +template +void SPC700::op_adjust_addr() { dp.l = op_readpc(); dp.h = op_readpc(); rd = op_read(dp); @@ -16,15 +15,15 @@ void SMPcore::op_adjust_addr() { op_write(dp, rd); } -template -void SMPcore::op_adjust_dp() { +template +void SPC700::op_adjust_dp() { dp = op_readpc(); rd = op_readdp(dp); rd = call(rd); op_writedp(dp, rd); } -void SMPcore::op_adjust_dpw(signed n) { +void SPC700::op_adjust_dpw(signed n) { dp = op_readpc(); rd.w = op_readdp(dp) + n; op_writedp(dp++, rd.l); @@ -34,8 +33,8 @@ void SMPcore::op_adjust_dpw(signed n) { regs.p.z = rd == 0; } -template -void SMPcore::op_adjust_dpx() { +template +void SPC700::op_adjust_dpx() { dp = op_readpc(); op_io(); rd = op_readdp(dp + regs.x); @@ -43,7 +42,7 @@ void SMPcore::op_adjust_dpx() { op_writedp(dp + regs.x, rd); } -void SMPcore::op_branch(bool condition) { +void SPC700::op_branch(bool condition) { rd = op_readpc(); if(condition == false) return; op_io(); @@ -51,7 +50,7 @@ void SMPcore::op_branch(bool condition) { regs.pc += (int8)rd; } -void SMPcore::op_branch_bit() { +void SPC700::op_branch_bit() { dp = op_readpc(); sp = op_readdp(dp); rd = op_readpc(); @@ -62,28 +61,28 @@ void SMPcore::op_branch_bit() { regs.pc += (int8)rd; } -void SMPcore::op_pull(uint8 &r) { +void SPC700::op_pull(uint8 &r) { op_io(); op_io(); r = op_readsp(); } -void SMPcore::op_push(uint8 r) { +void SPC700::op_push(uint8 r) { op_io(); op_io(); op_writesp(r); } -template -void SMPcore::op_read_addr(uint8 &r) { +template +void SPC700::op_read_addr(uint8 &r) { dp.l = op_readpc(); dp.h = op_readpc(); rd = op_read(dp); r = call(r, rd); } -template -void SMPcore::op_read_addri(uint8 &r) { +template +void SPC700::op_read_addri(uint8 &r) { dp.l = op_readpc(); dp.h = op_readpc(); op_io(); @@ -91,38 +90,38 @@ void SMPcore::op_read_addri(uint8 &r) { regs.a = call(regs.a, rd); } -template -void SMPcore::op_read_const(uint8 &r) { +template +void SPC700::op_read_const(uint8 &r) { rd = op_readpc(); r = call(r, rd); } -template -void SMPcore::op_read_dp(uint8 &r) { +template +void SPC700::op_read_dp(uint8 &r) { dp = op_readpc(); rd = op_readdp(dp); r = call(r, rd); } -template -void SMPcore::op_read_dpi(uint8 &r, uint8 &i) { +template +void SPC700::op_read_dpi(uint8 &r, uint8 &i) { dp = op_readpc(); op_io(); rd = op_readdp(dp + i); r = call(r, rd); } -template -void SMPcore::op_read_dpw() { +template +void SPC700::op_read_dpw() { dp = op_readpc(); rd.l = op_readdp(dp++); - if(op != &SMPcore::op_cpw) op_io(); + if(op != &SPC700::op_cpw) op_io(); rd.h = op_readdp(dp++); regs.ya = call(regs.ya, rd); } -template -void SMPcore::op_read_idpx() { +template +void SPC700::op_read_idpx() { dp = op_readpc() + regs.x; op_io(); sp.l = op_readdp(dp++); @@ -131,8 +130,8 @@ void SMPcore::op_read_idpx() { regs.a = call(regs.a, rd); } -template -void SMPcore::op_read_idpy() { +template +void SPC700::op_read_idpy() { dp = op_readpc(); op_io(); sp.l = op_readdp(dp++); @@ -141,14 +140,14 @@ void SMPcore::op_read_idpy() { regs.a = call(regs.a, rd); } -template -void SMPcore::op_read_ix() { +template +void SPC700::op_read_ix() { op_io(); rd = op_readdp(regs.x); regs.a = call(regs.a, rd); } -void SMPcore::op_set_addr_bit() { +void SPC700::op_set_addr_bit() { dp.l = op_readpc(); dp.h = op_readpc(); bit = dp >> 13; @@ -183,19 +182,19 @@ void SMPcore::op_set_addr_bit() { } } -void SMPcore::op_set_bit() { +void SPC700::op_set_bit() { dp = op_readpc(); rd = op_readdp(dp) & ~(1 << (opcode >> 5)); op_writedp(dp, rd | (!(opcode & 0x10) << (opcode >> 5))); } -void SMPcore::op_set_flag(bool &flag, bool data) { +void SPC700::op_set_flag(bool &flag, bool data) { op_io(); if(&flag == ®s.p.i) op_io(); flag = data; } -void SMPcore::op_test_addr(bool set) { +void SPC700::op_test_addr(bool set) { dp.l = op_readpc(); dp.h = op_readpc(); rd = op_read(dp); @@ -205,7 +204,7 @@ void SMPcore::op_test_addr(bool set) { op_write(dp, set ? rd | regs.a : rd & ~regs.a); } -void SMPcore::op_transfer(uint8 &from, uint8 &to) { +void SPC700::op_transfer(uint8 &from, uint8 &to) { op_io(); to = from; if(&to == ®s.s) return; @@ -213,14 +212,14 @@ void SMPcore::op_transfer(uint8 &from, uint8 &to) { regs.p.z = (to == 0); } -void SMPcore::op_write_addr(uint8 &r) { +void SPC700::op_write_addr(uint8 &r) { dp.l = op_readpc(); dp.h = op_readpc(); op_read(dp); op_write(dp, r); } -void SMPcore::op_write_addri(uint8 &i) { +void SPC700::op_write_addri(uint8 &i) { dp.l = op_readpc(); dp.h = op_readpc(); op_io(); @@ -229,50 +228,50 @@ void SMPcore::op_write_addri(uint8 &i) { op_write(dp, regs.a); } -void SMPcore::op_write_dp(uint8 &r) { +void SPC700::op_write_dp(uint8 &r) { dp = op_readpc(); op_readdp(dp); op_writedp(dp, r); } -void SMPcore::op_write_dpi(uint8 &r, uint8 &i) { +void SPC700::op_write_dpi(uint8 &r, uint8 &i) { dp = op_readpc() + i; op_io(); op_readdp(dp); op_writedp(dp, r); } -template -void SMPcore::op_write_dp_const() { +template +void SPC700::op_write_dp_const() { rd = op_readpc(); dp = op_readpc(); wr = op_readdp(dp); wr = call(wr, rd); - op != &SMPcore::op_cmp ? op_writedp(dp, wr) : op_io(); + op != &SPC700::op_cmp ? op_writedp(dp, wr) : op_io(); } -template -void SMPcore::op_write_dp_dp() { +template +void SPC700::op_write_dp_dp() { sp = op_readpc(); rd = op_readdp(sp); dp = op_readpc(); - if(op != &SMPcore::op_st) wr = op_readdp(dp); + if(op != &SPC700::op_st) wr = op_readdp(dp); wr = call(wr, rd); - op != &SMPcore::op_cmp ? op_writedp(dp, wr) : op_io(); + op != &SPC700::op_cmp ? op_writedp(dp, wr) : op_io(); } -template -void SMPcore::op_write_ix_iy() { +template +void SPC700::op_write_ix_iy() { op_io(); rd = op_readdp(regs.y); wr = op_readdp(regs.x); wr = call(wr, rd); - op != &SMPcore::op_cmp ? op_writedp(regs.x, wr) : op_io(); + op != &SPC700::op_cmp ? op_writedp(regs.x, wr) : op_io(); } // -void SMPcore::op_bne_dp() { +void SPC700::op_bne_dp() { dp = op_readpc(); sp = op_readdp(dp); rd = op_readpc(); @@ -283,7 +282,7 @@ void SMPcore::op_bne_dp() { regs.pc += (int8)rd; } -void SMPcore::op_bne_dpdec() { +void SPC700::op_bne_dpdec() { dp = op_readpc(); wr = op_readdp(dp); op_writedp(dp, --wr); @@ -294,7 +293,7 @@ void SMPcore::op_bne_dpdec() { regs.pc += (int8)rd; } -void SMPcore::op_bne_dpx() { +void SPC700::op_bne_dpx() { dp = op_readpc(); op_io(); sp = op_readdp(dp + regs.x); @@ -306,7 +305,7 @@ void SMPcore::op_bne_dpx() { regs.pc += (int8)rd; } -void SMPcore::op_bne_ydec() { +void SPC700::op_bne_ydec() { rd = op_readpc(); op_io(); op_io(); @@ -316,7 +315,7 @@ void SMPcore::op_bne_ydec() { regs.pc += (int8)rd; } -void SMPcore::op_brk() { +void SPC700::op_brk() { rd.l = op_read(0xffde); rd.h = op_read(0xffdf); op_io(); @@ -329,19 +328,19 @@ void SMPcore::op_brk() { regs.p.i = 0; } -void SMPcore::op_clv() { +void SPC700::op_clv() { op_io(); regs.p.v = 0; regs.p.h = 0; } -void SMPcore::op_cmc() { +void SPC700::op_cmc() { op_io(); op_io(); regs.p.c = !regs.p.c; } -void SMPcore::op_daa() { +void SPC700::op_daa() { op_io(); op_io(); if(regs.p.c || (regs.a) > 0x99) { @@ -355,7 +354,7 @@ void SMPcore::op_daa() { regs.p.z = (regs.a == 0); } -void SMPcore::op_das() { +void SPC700::op_das() { op_io(); op_io(); if(!regs.p.c || (regs.a) > 0x99) { @@ -369,7 +368,7 @@ void SMPcore::op_das() { regs.p.z = (regs.a == 0); } -void SMPcore::op_div_ya_x() { +void SPC700::op_div_ya_x() { op_io(); op_io(); op_io(); @@ -400,13 +399,13 @@ void SMPcore::op_div_ya_x() { regs.p.z = (regs.a == 0); } -void SMPcore::op_jmp_addr() { +void SPC700::op_jmp_addr() { rd.l = op_readpc(); rd.h = op_readpc(); regs.pc = rd; } -void SMPcore::op_jmp_iaddrx() { +void SPC700::op_jmp_iaddrx() { dp.l = op_readpc(); dp.h = op_readpc(); op_io(); @@ -416,7 +415,7 @@ void SMPcore::op_jmp_iaddrx() { regs.pc = rd; } -void SMPcore::op_jsp_dp() { +void SPC700::op_jsp_dp() { rd = op_readpc(); op_io(); op_io(); @@ -425,7 +424,7 @@ void SMPcore::op_jsp_dp() { regs.pc = 0xff00 | rd; } -void SMPcore::op_jsr_addr() { +void SPC700::op_jsr_addr() { rd.l = op_readpc(); rd.h = op_readpc(); op_io(); @@ -436,7 +435,7 @@ void SMPcore::op_jsr_addr() { regs.pc = rd; } -void SMPcore::op_jst() { +void SPC700::op_jst() { dp = 0xffde - ((opcode >> 4) << 1); rd.l = op_read(dp++); rd.h = op_read(dp++); @@ -448,7 +447,7 @@ void SMPcore::op_jst() { regs.pc = rd; } -void SMPcore::op_lda_ixinc() { +void SPC700::op_lda_ixinc() { op_io(); regs.a = op_readdp(regs.x++); op_io(); @@ -456,7 +455,7 @@ void SMPcore::op_lda_ixinc() { regs.p.z = regs.a == 0; } -void SMPcore::op_mul_ya() { +void SPC700::op_mul_ya() { op_io(); op_io(); op_io(); @@ -473,17 +472,17 @@ void SMPcore::op_mul_ya() { regs.p.z = (regs.y == 0); } -void SMPcore::op_nop() { +void SPC700::op_nop() { op_io(); } -void SMPcore::op_plp() { +void SPC700::op_plp() { op_io(); op_io(); regs.p = op_readsp(); } -void SMPcore::op_rti() { +void SPC700::op_rti() { regs.p = op_readsp(); rd.l = op_readsp(); rd.h = op_readsp(); @@ -492,7 +491,7 @@ void SMPcore::op_rti() { regs.pc = rd; } -void SMPcore::op_rts() { +void SPC700::op_rts() { rd.l = op_readsp(); rd.h = op_readsp(); op_io(); @@ -500,7 +499,7 @@ void SMPcore::op_rts() { regs.pc = rd; } -void SMPcore::op_sta_idpx() { +void SPC700::op_sta_idpx() { sp = op_readpc() + regs.x; op_io(); dp.l = op_readdp(sp++); @@ -509,7 +508,7 @@ void SMPcore::op_sta_idpx() { op_write(dp, regs.a); } -void SMPcore::op_sta_idpy() { +void SPC700::op_sta_idpy() { sp = op_readpc(); dp.l = op_readdp(sp++); dp.h = op_readdp(sp++); @@ -519,33 +518,33 @@ void SMPcore::op_sta_idpy() { op_write(dp, regs.a); } -void SMPcore::op_sta_ix() { +void SPC700::op_sta_ix() { op_io(); op_readdp(regs.x); op_writedp(regs.x, regs.a); } -void SMPcore::op_sta_ixinc() { +void SPC700::op_sta_ixinc() { op_io(); op_io(); op_writedp(regs.x++, regs.a); } -void SMPcore::op_stw_dp() { +void SPC700::op_stw_dp() { dp = op_readpc(); op_readdp(dp); op_writedp(dp++, regs.a); op_writedp(dp++, regs.y); } -void SMPcore::op_wait() { +void SPC700::op_wait() { while(true) { op_io(); op_io(); } } -void SMPcore::op_xcn() { +void SPC700::op_xcn() { op_io(); op_io(); op_io(); @@ -556,4 +555,3 @@ void SMPcore::op_xcn() { } #undef call -#endif diff --git a/bsnes/snes/smp/core/memory.hpp b/bsnes/processor/spc700/memory.hpp similarity index 100% rename from bsnes/snes/smp/core/memory.hpp rename to bsnes/processor/spc700/memory.hpp diff --git a/bsnes/snes/smp/core/registers.hpp b/bsnes/processor/spc700/registers.hpp similarity index 100% rename from bsnes/snes/smp/core/registers.hpp rename to bsnes/processor/spc700/registers.hpp diff --git a/bsnes/snes/smp/core/serialization.cpp b/bsnes/processor/spc700/serialization.cpp similarity index 85% rename from bsnes/snes/smp/core/serialization.cpp rename to bsnes/processor/spc700/serialization.cpp index c25e2294..b47087e4 100755 --- a/bsnes/snes/smp/core/serialization.cpp +++ b/bsnes/processor/spc700/serialization.cpp @@ -1,6 +1,4 @@ -#ifdef SMPCORE_CPP - -void SMPcore::core_serialize(serializer &s) { +void SPC700::serialize(serializer &s) { s.integer(regs.pc); s.integer(regs.a); s.integer(regs.x); @@ -23,5 +21,3 @@ void SMPcore::core_serialize(serializer &s) { s.integer(bit.w); s.integer(ya.w); } - -#endif diff --git a/bsnes/processor/spc700/spc700.cpp b/bsnes/processor/spc700/spc700.cpp new file mode 100755 index 00000000..e172da83 --- /dev/null +++ b/bsnes/processor/spc700/spc700.cpp @@ -0,0 +1,272 @@ +#include +#include "spc700.hpp" + +namespace Processor { + +#include "algorithms.cpp" +#include "instructions.cpp" +#include "disassembler.cpp" +#include "serialization.cpp" + +void SPC700::op_step() { + switch(opcode = op_readpc()) { + case 0x00: return op_nop(); + case 0x01: return op_jst(); + case 0x02: return op_set_bit(); + case 0x03: return op_branch_bit(); + case 0x04: return op_read_dp<&SPC700::op_or>(regs.a); + case 0x05: return op_read_addr<&SPC700::op_or>(regs.a); + case 0x06: return op_read_ix<&SPC700::op_or>(); + case 0x07: return op_read_idpx<&SPC700::op_or>(); + case 0x08: return op_read_const<&SPC700::op_or>(regs.a); + case 0x09: return op_write_dp_dp<&SPC700::op_or>(); + case 0x0a: return op_set_addr_bit(); + case 0x0b: return op_adjust_dp<&SPC700::op_asl>(); + case 0x0c: return op_adjust_addr<&SPC700::op_asl>(); + case 0x0d: return op_push(regs.p); + case 0x0e: return op_test_addr(1); + case 0x0f: return op_brk(); + case 0x10: return op_branch(regs.p.n == 0); + case 0x11: return op_jst(); + case 0x12: return op_set_bit(); + case 0x13: return op_branch_bit(); + case 0x14: return op_read_dpi<&SPC700::op_or>(regs.a, regs.x); + case 0x15: return op_read_addri<&SPC700::op_or>(regs.x); + case 0x16: return op_read_addri<&SPC700::op_or>(regs.y); + case 0x17: return op_read_idpy<&SPC700::op_or>(); + case 0x18: return op_write_dp_const<&SPC700::op_or>(); + case 0x19: return op_write_ix_iy<&SPC700::op_or>(); + case 0x1a: return op_adjust_dpw(-1); + case 0x1b: return op_adjust_dpx<&SPC700::op_asl>(); + case 0x1c: return op_adjust<&SPC700::op_asl>(regs.a); + case 0x1d: return op_adjust<&SPC700::op_dec>(regs.x); + case 0x1e: return op_read_addr<&SPC700::op_cmp>(regs.x); + case 0x1f: return op_jmp_iaddrx(); + case 0x20: return op_set_flag(regs.p.p, 0); + case 0x21: return op_jst(); + case 0x22: return op_set_bit(); + case 0x23: return op_branch_bit(); + case 0x24: return op_read_dp<&SPC700::op_and>(regs.a); + case 0x25: return op_read_addr<&SPC700::op_and>(regs.a); + case 0x26: return op_read_ix<&SPC700::op_and>(); + case 0x27: return op_read_idpx<&SPC700::op_and>(); + case 0x28: return op_read_const<&SPC700::op_and>(regs.a); + case 0x29: return op_write_dp_dp<&SPC700::op_and>(); + case 0x2a: return op_set_addr_bit(); + case 0x2b: return op_adjust_dp<&SPC700::op_rol>(); + case 0x2c: return op_adjust_addr<&SPC700::op_rol>(); + case 0x2d: return op_push(regs.a); + case 0x2e: return op_bne_dp(); + case 0x2f: return op_branch(true); + case 0x30: return op_branch(regs.p.n == 1); + case 0x31: return op_jst(); + case 0x32: return op_set_bit(); + case 0x33: return op_branch_bit(); + case 0x34: return op_read_dpi<&SPC700::op_and>(regs.a, regs.x); + case 0x35: return op_read_addri<&SPC700::op_and>(regs.x); + case 0x36: return op_read_addri<&SPC700::op_and>(regs.y); + case 0x37: return op_read_idpy<&SPC700::op_and>(); + case 0x38: return op_write_dp_const<&SPC700::op_and>(); + case 0x39: return op_write_ix_iy<&SPC700::op_and>(); + case 0x3a: return op_adjust_dpw(+1); + case 0x3b: return op_adjust_dpx<&SPC700::op_rol>(); + case 0x3c: return op_adjust<&SPC700::op_rol>(regs.a); + case 0x3d: return op_adjust<&SPC700::op_inc>(regs.x); + case 0x3e: return op_read_dp<&SPC700::op_cmp>(regs.x); + case 0x3f: return op_jsr_addr(); + case 0x40: return op_set_flag(regs.p.p, 1); + case 0x41: return op_jst(); + case 0x42: return op_set_bit(); + case 0x43: return op_branch_bit(); + case 0x44: return op_read_dp<&SPC700::op_eor>(regs.a); + case 0x45: return op_read_addr<&SPC700::op_eor>(regs.a); + case 0x46: return op_read_ix<&SPC700::op_eor>(); + case 0x47: return op_read_idpx<&SPC700::op_eor>(); + case 0x48: return op_read_const<&SPC700::op_eor>(regs.a); + case 0x49: return op_write_dp_dp<&SPC700::op_eor>(); + case 0x4a: return op_set_addr_bit(); + case 0x4b: return op_adjust_dp<&SPC700::op_lsr>(); + case 0x4c: return op_adjust_addr<&SPC700::op_lsr>(); + case 0x4d: return op_push(regs.x); + case 0x4e: return op_test_addr(0); + case 0x4f: return op_jsp_dp(); + case 0x50: return op_branch(regs.p.v == 0); + case 0x51: return op_jst(); + case 0x52: return op_set_bit(); + case 0x53: return op_branch_bit(); + case 0x54: return op_read_dpi<&SPC700::op_eor>(regs.a, regs.x); + case 0x55: return op_read_addri<&SPC700::op_eor>(regs.x); + case 0x56: return op_read_addri<&SPC700::op_eor>(regs.y); + case 0x57: return op_read_idpy<&SPC700::op_eor>(); + case 0x58: return op_write_dp_const<&SPC700::op_eor>(); + case 0x59: return op_write_ix_iy<&SPC700::op_eor>(); + case 0x5a: return op_read_dpw<&SPC700::op_cpw>(); + case 0x5b: return op_adjust_dpx<&SPC700::op_lsr>(); + case 0x5c: return op_adjust<&SPC700::op_lsr>(regs.a); + case 0x5d: return op_transfer(regs.a, regs.x); + case 0x5e: return op_read_addr<&SPC700::op_cmp>(regs.y); + case 0x5f: return op_jmp_addr(); + case 0x60: return op_set_flag(regs.p.c, 0); + case 0x61: return op_jst(); + case 0x62: return op_set_bit(); + case 0x63: return op_branch_bit(); + case 0x64: return op_read_dp<&SPC700::op_cmp>(regs.a); + case 0x65: return op_read_addr<&SPC700::op_cmp>(regs.a); + case 0x66: return op_read_ix<&SPC700::op_cmp>(); + case 0x67: return op_read_idpx<&SPC700::op_cmp>(); + case 0x68: return op_read_const<&SPC700::op_cmp>(regs.a); + case 0x69: return op_write_dp_dp<&SPC700::op_cmp>(); + case 0x6a: return op_set_addr_bit(); + case 0x6b: return op_adjust_dp<&SPC700::op_ror>(); + case 0x6c: return op_adjust_addr<&SPC700::op_ror>(); + case 0x6d: return op_push(regs.y); + case 0x6e: return op_bne_dpdec(); + case 0x6f: return op_rts(); + case 0x70: return op_branch(regs.p.v == 1); + case 0x71: return op_jst(); + case 0x72: return op_set_bit(); + case 0x73: return op_branch_bit(); + case 0x74: return op_read_dpi<&SPC700::op_cmp>(regs.a, regs.x); + case 0x75: return op_read_addri<&SPC700::op_cmp>(regs.x); + case 0x76: return op_read_addri<&SPC700::op_cmp>(regs.y); + case 0x77: return op_read_idpy<&SPC700::op_cmp>(); + case 0x78: return op_write_dp_const<&SPC700::op_cmp>(); + case 0x79: return op_write_ix_iy<&SPC700::op_cmp>(); + case 0x7a: return op_read_dpw<&SPC700::op_adw>(); + case 0x7b: return op_adjust_dpx<&SPC700::op_ror>(); + case 0x7c: return op_adjust<&SPC700::op_ror>(regs.a); + case 0x7d: return op_transfer(regs.x, regs.a); + case 0x7e: return op_read_dp<&SPC700::op_cmp>(regs.y); + case 0x7f: return op_rti(); + case 0x80: return op_set_flag(regs.p.c, 1); + case 0x81: return op_jst(); + case 0x82: return op_set_bit(); + case 0x83: return op_branch_bit(); + case 0x84: return op_read_dp<&SPC700::op_adc>(regs.a); + case 0x85: return op_read_addr<&SPC700::op_adc>(regs.a); + case 0x86: return op_read_ix<&SPC700::op_adc>(); + case 0x87: return op_read_idpx<&SPC700::op_adc>(); + case 0x88: return op_read_const<&SPC700::op_adc>(regs.a); + case 0x89: return op_write_dp_dp<&SPC700::op_adc>(); + case 0x8a: return op_set_addr_bit(); + case 0x8b: return op_adjust_dp<&SPC700::op_dec>(); + case 0x8c: return op_adjust_addr<&SPC700::op_dec>(); + case 0x8d: return op_read_const<&SPC700::op_ld>(regs.y); + case 0x8e: return op_plp(); + case 0x8f: return op_write_dp_const<&SPC700::op_st>(); + case 0x90: return op_branch(regs.p.c == 0); + case 0x91: return op_jst(); + case 0x92: return op_set_bit(); + case 0x93: return op_branch_bit(); + case 0x94: return op_read_dpi<&SPC700::op_adc>(regs.a, regs.x); + case 0x95: return op_read_addri<&SPC700::op_adc>(regs.x); + case 0x96: return op_read_addri<&SPC700::op_adc>(regs.y); + case 0x97: return op_read_idpy<&SPC700::op_adc>(); + case 0x98: return op_write_dp_const<&SPC700::op_adc>(); + case 0x99: return op_write_ix_iy<&SPC700::op_adc>(); + case 0x9a: return op_read_dpw<&SPC700::op_sbw>(); + case 0x9b: return op_adjust_dpx<&SPC700::op_dec>(); + case 0x9c: return op_adjust<&SPC700::op_dec>(regs.a); + case 0x9d: return op_transfer(regs.s, regs.x); + case 0x9e: return op_div_ya_x(); + case 0x9f: return op_xcn(); + case 0xa0: return op_set_flag(regs.p.i, 1); + case 0xa1: return op_jst(); + case 0xa2: return op_set_bit(); + case 0xa3: return op_branch_bit(); + case 0xa4: return op_read_dp<&SPC700::op_sbc>(regs.a); + case 0xa5: return op_read_addr<&SPC700::op_sbc>(regs.a); + case 0xa6: return op_read_ix<&SPC700::op_sbc>(); + case 0xa7: return op_read_idpx<&SPC700::op_sbc>(); + case 0xa8: return op_read_const<&SPC700::op_sbc>(regs.a); + case 0xa9: return op_write_dp_dp<&SPC700::op_sbc>(); + case 0xaa: return op_set_addr_bit(); + case 0xab: return op_adjust_dp<&SPC700::op_inc>(); + case 0xac: return op_adjust_addr<&SPC700::op_inc>(); + case 0xad: return op_read_const<&SPC700::op_cmp>(regs.y); + case 0xae: return op_pull(regs.a); + case 0xaf: return op_sta_ixinc(); + case 0xb0: return op_branch(regs.p.c == 1); + case 0xb1: return op_jst(); + case 0xb2: return op_set_bit(); + case 0xb3: return op_branch_bit(); + case 0xb4: return op_read_dpi<&SPC700::op_sbc>(regs.a, regs.x); + case 0xb5: return op_read_addri<&SPC700::op_sbc>(regs.x); + case 0xb6: return op_read_addri<&SPC700::op_sbc>(regs.y); + case 0xb7: return op_read_idpy<&SPC700::op_sbc>(); + case 0xb8: return op_write_dp_const<&SPC700::op_sbc>(); + case 0xb9: return op_write_ix_iy<&SPC700::op_sbc>(); + case 0xba: return op_read_dpw<&SPC700::op_ldw>(); + case 0xbb: return op_adjust_dpx<&SPC700::op_inc>(); + case 0xbc: return op_adjust<&SPC700::op_inc>(regs.a); + case 0xbd: return op_transfer(regs.x, regs.s); + case 0xbe: return op_das(); + case 0xbf: return op_lda_ixinc(); + case 0xc0: return op_set_flag(regs.p.i, 0); + case 0xc1: return op_jst(); + case 0xc2: return op_set_bit(); + case 0xc3: return op_branch_bit(); + case 0xc4: return op_write_dp(regs.a); + case 0xc5: return op_write_addr(regs.a); + case 0xc6: return op_sta_ix(); + case 0xc7: return op_sta_idpx(); + case 0xc8: return op_read_const<&SPC700::op_cmp>(regs.x); + case 0xc9: return op_write_addr(regs.x); + case 0xca: return op_set_addr_bit(); + case 0xcb: return op_write_dp(regs.y); + case 0xcc: return op_write_addr(regs.y); + case 0xcd: return op_read_const<&SPC700::op_ld>(regs.x); + case 0xce: return op_pull(regs.x); + case 0xcf: return op_mul_ya(); + case 0xd0: return op_branch(regs.p.z == 0); + case 0xd1: return op_jst(); + case 0xd2: return op_set_bit(); + case 0xd3: return op_branch_bit(); + case 0xd4: return op_write_dpi(regs.a, regs.x); + case 0xd5: return op_write_addri(regs.x); + case 0xd6: return op_write_addri(regs.y); + case 0xd7: return op_sta_idpy(); + case 0xd8: return op_write_dp(regs.x); + case 0xd9: return op_write_dpi(regs.x, regs.y); + case 0xda: return op_stw_dp(); + case 0xdb: return op_write_dpi(regs.y, regs.x); + case 0xdc: return op_adjust<&SPC700::op_dec>(regs.y); + case 0xdd: return op_transfer(regs.y, regs.a); + case 0xde: return op_bne_dpx(); + case 0xdf: return op_daa(); + case 0xe0: return op_clv(); + case 0xe1: return op_jst(); + case 0xe2: return op_set_bit(); + case 0xe3: return op_branch_bit(); + case 0xe4: return op_read_dp<&SPC700::op_ld>(regs.a); + case 0xe5: return op_read_addr<&SPC700::op_ld>(regs.a); + case 0xe6: return op_read_ix<&SPC700::op_ld>(); + case 0xe7: return op_read_idpx<&SPC700::op_ld>(); + case 0xe8: return op_read_const<&SPC700::op_ld>(regs.a); + case 0xe9: return op_read_addr<&SPC700::op_ld>(regs.x); + case 0xea: return op_set_addr_bit(); + case 0xeb: return op_read_dp<&SPC700::op_ld>(regs.y); + case 0xec: return op_read_addr<&SPC700::op_ld>(regs.y); + case 0xed: return op_cmc(); + case 0xee: return op_pull(regs.y); + case 0xef: return op_wait(); + case 0xf0: return op_branch(regs.p.z == 1); + case 0xf1: return op_jst(); + case 0xf2: return op_set_bit(); + case 0xf3: return op_branch_bit(); + case 0xf4: return op_read_dpi<&SPC700::op_ld>(regs.a, regs.x); + case 0xf5: return op_read_addri<&SPC700::op_ld>(regs.x); + case 0xf6: return op_read_addri<&SPC700::op_ld>(regs.y); + case 0xf7: return op_read_idpy<&SPC700::op_ld>(); + case 0xf8: return op_read_dp<&SPC700::op_ld>(regs.x); + case 0xf9: return op_read_dpi<&SPC700::op_ld>(regs.x, regs.y); + case 0xfa: return op_write_dp_dp<&SPC700::op_st>(); + case 0xfb: return op_read_dpi<&SPC700::op_ld>(regs.y, regs.x); + case 0xfc: return op_adjust<&SPC700::op_inc>(regs.y); + case 0xfd: return op_transfer(regs.a, regs.y); + case 0xfe: return op_bne_ydec(); + case 0xff: return op_wait(); + } +} + +} diff --git a/bsnes/snes/smp/core/core.hpp b/bsnes/processor/spc700/spc700.hpp similarity index 58% rename from bsnes/snes/smp/core/core.hpp rename to bsnes/processor/spc700/spc700.hpp index 6adf6f6b..5ff3a40a 100755 --- a/bsnes/snes/smp/core/core.hpp +++ b/bsnes/processor/spc700/spc700.hpp @@ -1,9 +1,16 @@ -struct SMPcore { +#ifndef PROCESSOR_SPC700_HPP +#define PROCESSOR_SPC700_HPP + +namespace Processor { + +struct SPC700 { virtual void op_io() = 0; virtual uint8 op_read(uint16 addr) = 0; virtual void op_write(uint16 addr, uint8 data) = 0; void op_step(); + virtual uint8 disassembler_read(uint16 addr) = 0; + #include "registers.hpp" #include "memory.hpp" @@ -11,7 +18,7 @@ struct SMPcore { word_t dp, sp, rd, wr, bit, ya; uint8 opcode; - void core_serialize(serializer&); + void serialize(serializer&); string disassemble_opcode(uint16 addr); protected: @@ -34,24 +41,24 @@ protected: uint16 op_ldw(uint16, uint16); uint16 op_sbw(uint16, uint16); - template void op_adjust(uint8&); - template void op_adjust_addr(); - template void op_adjust_dp(); + template void op_adjust(uint8&); + template void op_adjust_addr(); + template void op_adjust_dp(); void op_adjust_dpw(signed); - template void op_adjust_dpx(); + template void op_adjust_dpx(); void op_branch(bool); void op_branch_bit(); void op_pull(uint8&); void op_push(uint8); - template void op_read_addr(uint8&); - template void op_read_addri(uint8&); - template void op_read_const(uint8&); - template void op_read_dp(uint8&); - template void op_read_dpi(uint8&, uint8&); - template void op_read_dpw(); - template void op_read_idpx(); - template void op_read_idpy(); - template void op_read_ix(); + template void op_read_addr(uint8&); + template void op_read_addri(uint8&); + template void op_read_const(uint8&); + template void op_read_dp(uint8&); + template void op_read_dpi(uint8&, uint8&); + template void op_read_dpw(); + template void op_read_idpx(); + template void op_read_idpy(); + template void op_read_ix(); void op_set_addr_bit(); void op_set_bit(); void op_set_flag(bool&, bool); @@ -61,9 +68,9 @@ protected: void op_write_addri(uint8&); void op_write_dp(uint8&); void op_write_dpi(uint8&, uint8&); - template void op_write_dp_const(); - template void op_write_dp_dp(); - template void op_write_ix_iy(); + template void op_write_dp_const(); + template void op_write_dp_dp(); + template void op_write_ix_iy(); void op_bne_dp(); void op_bne_dpdec(); @@ -94,3 +101,7 @@ protected: void op_wait(); void op_xcn(); }; + +} + +#endif diff --git a/bsnes/sfc/Makefile b/bsnes/sfc/Makefile new file mode 100755 index 00000000..b48f3466 --- /dev/null +++ b/bsnes/sfc/Makefile @@ -0,0 +1,56 @@ +sfc_objects := sfc-interface sfc-system sfc-controller +sfc_objects += sfc-cartridge sfc-cheat +sfc_objects += sfc-memory sfc-cpu sfc-smp sfc-dsp sfc-ppu +sfc_objects += sfc-icd2 sfc-nss sfc-superfx sfc-sa1 +sfc_objects += sfc-necdsp sfc-hitachidsp sfc-armdsp +sfc_objects += sfc-bsx sfc-srtc sfc-sdd1 sfc-spc7110 +sfc_objects += sfc-obc1 sfc-sufamiturbo +sfc_objects += sfc-msu1 sfc-link +objects += $(sfc_objects) + +ifeq ($(profile),accuracy) + flags += -DPROFILE_ACCURACY + sfccpu := $(sfc)/cpu + sfcsmp := $(sfc)/smp + sfcdsp := $(sfc)/dsp + sfcppu := $(sfc)/ppu +else ifeq ($(profile),compatibility) + flags += -DPROFILE_COMPATIBILITY + sfccpu := $(sfc)/cpu + sfcsmp := $(sfc)/smp + sfcdsp := $(sfc)/alt/dsp + sfcppu := $(sfc)/alt/ppu-compatibility +else ifeq ($(profile),performance) + flags += -DPROFILE_PERFORMANCE + sfccpu := $(sfc)/alt/cpu + sfcsmp := $(sfc)/alt/smp + sfcdsp := $(sfc)/alt/dsp + sfcppu := $(sfc)/alt/ppu-performance +endif + +obj/sfc-interface.o : $(sfc)/interface/interface.cpp $(call rwildcard,$(sfc)/interface) +obj/sfc-system.o : $(sfc)/system/system.cpp $(call rwildcard,$(sfc)/system/) +obj/sfc-controller.o: $(sfc)/controller/controller.cpp $(call rwildcard,$(sfc)/controller/) +obj/sfc-memory.o : $(sfc)/memory/memory.cpp $(call rwildcard,$(sfc)/memory/) +obj/sfc-cpu.o : $(sfccpu)/cpu.cpp $(call rwildcard,$(sfccpu)/) +obj/sfc-smp.o : $(sfcsmp)/smp.cpp $(call rwildcard,$(sfcsmp)/) +obj/sfc-dsp.o : $(sfcdsp)/dsp.cpp $(call rwildcard,$(sfcdsp)/) +obj/sfc-ppu.o : $(sfcppu)/ppu.cpp $(call rwildcard,$(sfcppu)/) +obj/sfc-cartridge.o : $(sfc)/cartridge/cartridge.cpp $(sfc)/cartridge/* +obj/sfc-cheat.o : $(sfc)/cheat/cheat.cpp $(sfc)/cheat/* + +obj/sfc-nss.o : $(sfc)/chip/nss/nss.cpp $(call rwildcard,$(sfc)/chip/nss/) +obj/sfc-icd2.o : $(sfc)/chip/icd2/icd2.cpp $(call rwildcard,$(sfc)/chip/icd2/) +obj/sfc-superfx.o : $(sfc)/chip/superfx/superfx.cpp $(call rwildcard,$(sfc)/chip/superfx/) +obj/sfc-sa1.o : $(sfc)/chip/sa1/sa1.cpp $(call rwildcard,$(sfc)/chip/sa1/) +obj/sfc-necdsp.o : $(sfc)/chip/necdsp/necdsp.cpp $(call rwildcard,$(sfc)/chip/necdsp/) +obj/sfc-hitachidsp.o : $(sfc)/chip/hitachidsp/hitachidsp.cpp $(call rwildcard,$(sfc)/chip/hitachidsp/) +obj/sfc-armdsp.o : $(sfc)/chip/armdsp/armdsp.cpp $(call rwildcard,$(sfc)/chip/armdsp/) +obj/sfc-bsx.o : $(sfc)/chip/bsx/bsx.cpp $(call rwildcard,$(sfc)/chip/bsx/) +obj/sfc-srtc.o : $(sfc)/chip/srtc/srtc.cpp $(sfc)/chip/srtc/* +obj/sfc-sdd1.o : $(sfc)/chip/sdd1/sdd1.cpp $(sfc)/chip/sdd1/* +obj/sfc-spc7110.o : $(sfc)/chip/spc7110/spc7110.cpp $(sfc)/chip/spc7110/* +obj/sfc-obc1.o : $(sfc)/chip/obc1/obc1.cpp $(sfc)/chip/obc1/* +obj/sfc-sufamiturbo.o: $(sfc)/chip/sufamiturbo/sufamiturbo.cpp $(sfc)/chip/sufamiturbo/* +obj/sfc-msu1.o : $(sfc)/chip/msu1/msu1.cpp $(sfc)/chip/msu1/* +obj/sfc-link.o : $(sfc)/chip/link/link.cpp $(sfc)/chip/link/* diff --git a/bsnes/snes/alt/cpu/cpu.cpp b/bsnes/sfc/alt/cpu/cpu.cpp similarity index 99% rename from bsnes/snes/alt/cpu/cpu.cpp rename to bsnes/sfc/alt/cpu/cpu.cpp index 9e3b29ce..de6bc178 100755 --- a/bsnes/snes/alt/cpu/cpu.cpp +++ b/bsnes/sfc/alt/cpu/cpu.cpp @@ -1,4 +1,4 @@ -#include +#include #define CPU_CPP namespace SuperFamicom { diff --git a/bsnes/snes/alt/cpu/cpu.hpp b/bsnes/sfc/alt/cpu/cpu.hpp similarity index 96% rename from bsnes/snes/alt/cpu/cpu.hpp rename to bsnes/sfc/alt/cpu/cpu.hpp index 49736c24..61c7067b 100755 --- a/bsnes/snes/alt/cpu/cpu.hpp +++ b/bsnes/sfc/alt/cpu/cpu.hpp @@ -1,8 +1,8 @@ -struct CPU : Thread, public CPUcore, public PPUcounter { +struct CPU : Processor::R65816, Thread, public PPUcounter { uint8 wram[128 * 1024]; enum : bool { Threaded = true }; - array coprocessors; + vector coprocessors; alwaysinline void step(unsigned clocks); alwaysinline void synchronize_smp(); void synchronize_ppu(); diff --git a/bsnes/snes/alt/cpu/dma.cpp b/bsnes/sfc/alt/cpu/dma.cpp similarity index 100% rename from bsnes/snes/alt/cpu/dma.cpp rename to bsnes/sfc/alt/cpu/dma.cpp diff --git a/bsnes/snes/alt/cpu/memory.cpp b/bsnes/sfc/alt/cpu/memory.cpp similarity index 100% rename from bsnes/snes/alt/cpu/memory.cpp rename to bsnes/sfc/alt/cpu/memory.cpp diff --git a/bsnes/snes/alt/cpu/mmio.cpp b/bsnes/sfc/alt/cpu/mmio.cpp similarity index 100% rename from bsnes/snes/alt/cpu/mmio.cpp rename to bsnes/sfc/alt/cpu/mmio.cpp diff --git a/bsnes/snes/alt/cpu/serialization.cpp b/bsnes/sfc/alt/cpu/serialization.cpp similarity index 98% rename from bsnes/snes/alt/cpu/serialization.cpp rename to bsnes/sfc/alt/cpu/serialization.cpp index e9f4dd57..002c6624 100755 --- a/bsnes/snes/alt/cpu/serialization.cpp +++ b/bsnes/sfc/alt/cpu/serialization.cpp @@ -1,8 +1,8 @@ #ifdef CPU_CPP void CPU::serialize(serializer &s) { + R65816::serialize(s); Thread::serialize(s); - CPUcore::core_serialize(s); PPUcounter::serialize(s); s.array(wram); diff --git a/bsnes/snes/alt/cpu/timing.cpp b/bsnes/sfc/alt/cpu/timing.cpp similarity index 100% rename from bsnes/snes/alt/cpu/timing.cpp rename to bsnes/sfc/alt/cpu/timing.cpp diff --git a/bsnes/snes/alt/dsp/SPC_DSP.cpp b/bsnes/sfc/alt/dsp/SPC_DSP.cpp similarity index 100% rename from bsnes/snes/alt/dsp/SPC_DSP.cpp rename to bsnes/sfc/alt/dsp/SPC_DSP.cpp diff --git a/bsnes/snes/alt/dsp/SPC_DSP.h b/bsnes/sfc/alt/dsp/SPC_DSP.h similarity index 100% rename from bsnes/snes/alt/dsp/SPC_DSP.h rename to bsnes/sfc/alt/dsp/SPC_DSP.h diff --git a/bsnes/snes/alt/dsp/blargg_common.h b/bsnes/sfc/alt/dsp/blargg_common.h similarity index 100% rename from bsnes/snes/alt/dsp/blargg_common.h rename to bsnes/sfc/alt/dsp/blargg_common.h diff --git a/bsnes/snes/alt/dsp/blargg_config.h b/bsnes/sfc/alt/dsp/blargg_config.h similarity index 100% rename from bsnes/snes/alt/dsp/blargg_config.h rename to bsnes/sfc/alt/dsp/blargg_config.h diff --git a/bsnes/snes/alt/dsp/blargg_endian.h b/bsnes/sfc/alt/dsp/blargg_endian.h similarity index 100% rename from bsnes/snes/alt/dsp/blargg_endian.h rename to bsnes/sfc/alt/dsp/blargg_endian.h diff --git a/bsnes/snes/alt/dsp/blargg_source.h b/bsnes/sfc/alt/dsp/blargg_source.h similarity index 100% rename from bsnes/snes/alt/dsp/blargg_source.h rename to bsnes/sfc/alt/dsp/blargg_source.h diff --git a/bsnes/snes/alt/dsp/dsp.cpp b/bsnes/sfc/alt/dsp/dsp.cpp similarity index 98% rename from bsnes/snes/alt/dsp/dsp.cpp rename to bsnes/sfc/alt/dsp/dsp.cpp index f176f2dc..7974b7d3 100755 --- a/bsnes/snes/alt/dsp/dsp.cpp +++ b/bsnes/sfc/alt/dsp/dsp.cpp @@ -1,4 +1,4 @@ -#include +#include #define DSP_CPP namespace SuperFamicom { diff --git a/bsnes/snes/alt/dsp/dsp.hpp b/bsnes/sfc/alt/dsp/dsp.hpp similarity index 100% rename from bsnes/snes/alt/dsp/dsp.hpp rename to bsnes/sfc/alt/dsp/dsp.hpp diff --git a/bsnes/snes/alt/dsp/serialization.cpp b/bsnes/sfc/alt/dsp/serialization.cpp similarity index 100% rename from bsnes/snes/alt/dsp/serialization.cpp rename to bsnes/sfc/alt/dsp/serialization.cpp diff --git a/bsnes/snes/alt/ppu-compatibility/memory/memory.cpp b/bsnes/sfc/alt/ppu-compatibility/memory/memory.cpp similarity index 100% rename from bsnes/snes/alt/ppu-compatibility/memory/memory.cpp rename to bsnes/sfc/alt/ppu-compatibility/memory/memory.cpp diff --git a/bsnes/snes/alt/ppu-compatibility/memory/memory.hpp b/bsnes/sfc/alt/ppu-compatibility/memory/memory.hpp similarity index 100% rename from bsnes/snes/alt/ppu-compatibility/memory/memory.hpp rename to bsnes/sfc/alt/ppu-compatibility/memory/memory.hpp diff --git a/bsnes/snes/alt/ppu-compatibility/mmio/mmio.cpp b/bsnes/sfc/alt/ppu-compatibility/mmio/mmio.cpp similarity index 100% rename from bsnes/snes/alt/ppu-compatibility/mmio/mmio.cpp rename to bsnes/sfc/alt/ppu-compatibility/mmio/mmio.cpp diff --git a/bsnes/snes/alt/ppu-compatibility/mmio/mmio.hpp b/bsnes/sfc/alt/ppu-compatibility/mmio/mmio.hpp similarity index 100% rename from bsnes/snes/alt/ppu-compatibility/mmio/mmio.hpp rename to bsnes/sfc/alt/ppu-compatibility/mmio/mmio.hpp diff --git a/bsnes/snes/alt/ppu-compatibility/ppu.cpp b/bsnes/sfc/alt/ppu-compatibility/ppu.cpp similarity index 99% rename from bsnes/snes/alt/ppu-compatibility/ppu.cpp rename to bsnes/sfc/alt/ppu-compatibility/ppu.cpp index c7df8370..56a76109 100755 --- a/bsnes/snes/alt/ppu-compatibility/ppu.cpp +++ b/bsnes/sfc/alt/ppu-compatibility/ppu.cpp @@ -1,4 +1,4 @@ -#include +#include #define PPU_CPP namespace SuperFamicom { diff --git a/bsnes/snes/alt/ppu-compatibility/ppu.hpp b/bsnes/sfc/alt/ppu-compatibility/ppu.hpp similarity index 100% rename from bsnes/snes/alt/ppu-compatibility/ppu.hpp rename to bsnes/sfc/alt/ppu-compatibility/ppu.hpp diff --git a/bsnes/snes/alt/ppu-compatibility/render/addsub.cpp b/bsnes/sfc/alt/ppu-compatibility/render/addsub.cpp similarity index 100% rename from bsnes/snes/alt/ppu-compatibility/render/addsub.cpp rename to bsnes/sfc/alt/ppu-compatibility/render/addsub.cpp diff --git a/bsnes/snes/alt/ppu-compatibility/render/bg.cpp b/bsnes/sfc/alt/ppu-compatibility/render/bg.cpp similarity index 100% rename from bsnes/snes/alt/ppu-compatibility/render/bg.cpp rename to bsnes/sfc/alt/ppu-compatibility/render/bg.cpp diff --git a/bsnes/snes/alt/ppu-compatibility/render/cache.cpp b/bsnes/sfc/alt/ppu-compatibility/render/cache.cpp similarity index 100% rename from bsnes/snes/alt/ppu-compatibility/render/cache.cpp rename to bsnes/sfc/alt/ppu-compatibility/render/cache.cpp diff --git a/bsnes/snes/alt/ppu-compatibility/render/line.cpp b/bsnes/sfc/alt/ppu-compatibility/render/line.cpp similarity index 93% rename from bsnes/snes/alt/ppu-compatibility/render/line.cpp rename to bsnes/sfc/alt/ppu-compatibility/render/line.cpp index c7e870fe..181174fc 100755 --- a/bsnes/snes/alt/ppu-compatibility/render/line.cpp +++ b/bsnes/sfc/alt/ppu-compatibility/render/line.cpp @@ -91,7 +91,7 @@ inline void PPU::render_line_output() { if(!regs.pseudo_hires && regs.bg_mode != 5 && regs.bg_mode != 6) { for(unsigned x = 0; x < 256; x++) { curr = (regs.display_brightness << 15) | get_pixel_normal(x); - *ptr++ = curr; + *ptr++ = video.palette[curr]; } } else { for(unsigned x = 0, prev = 0; x < 256; x++) { @@ -99,11 +99,11 @@ inline void PPU::render_line_output() { //blending code is left for reference purposes curr = (regs.display_brightness << 15) | get_pixel_swap(x); - *ptr++ = curr; //(prev + curr - ((prev ^ curr) & 0x0421)) >> 1; + *ptr++ = video.palette[curr]; //(prev + curr - ((prev ^ curr) & 0x0421)) >> 1; //prev = curr; curr = (regs.display_brightness << 15) | get_pixel_normal(x); - *ptr++ = curr; //(prev + curr - ((prev ^ curr) & 0x0421)) >> 1; + *ptr++ = video.palette[curr]; //(prev + curr - ((prev ^ curr) & 0x0421)) >> 1; //prev = curr; } } diff --git a/bsnes/snes/alt/ppu-compatibility/render/mode7.cpp b/bsnes/sfc/alt/ppu-compatibility/render/mode7.cpp similarity index 100% rename from bsnes/snes/alt/ppu-compatibility/render/mode7.cpp rename to bsnes/sfc/alt/ppu-compatibility/render/mode7.cpp diff --git a/bsnes/snes/alt/ppu-compatibility/render/oam.cpp b/bsnes/sfc/alt/ppu-compatibility/render/oam.cpp similarity index 100% rename from bsnes/snes/alt/ppu-compatibility/render/oam.cpp rename to bsnes/sfc/alt/ppu-compatibility/render/oam.cpp diff --git a/bsnes/snes/alt/ppu-compatibility/render/render.cpp b/bsnes/sfc/alt/ppu-compatibility/render/render.cpp similarity index 100% rename from bsnes/snes/alt/ppu-compatibility/render/render.cpp rename to bsnes/sfc/alt/ppu-compatibility/render/render.cpp diff --git a/bsnes/snes/alt/ppu-compatibility/render/render.hpp b/bsnes/sfc/alt/ppu-compatibility/render/render.hpp similarity index 100% rename from bsnes/snes/alt/ppu-compatibility/render/render.hpp rename to bsnes/sfc/alt/ppu-compatibility/render/render.hpp diff --git a/bsnes/snes/alt/ppu-compatibility/render/windows.cpp b/bsnes/sfc/alt/ppu-compatibility/render/windows.cpp similarity index 100% rename from bsnes/snes/alt/ppu-compatibility/render/windows.cpp rename to bsnes/sfc/alt/ppu-compatibility/render/windows.cpp diff --git a/bsnes/snes/alt/ppu-compatibility/serialization.cpp b/bsnes/sfc/alt/ppu-compatibility/serialization.cpp similarity index 100% rename from bsnes/snes/alt/ppu-compatibility/serialization.cpp rename to bsnes/sfc/alt/ppu-compatibility/serialization.cpp diff --git a/bsnes/snes/alt/ppu-performance/background/background.cpp b/bsnes/sfc/alt/ppu-performance/background/background.cpp similarity index 100% rename from bsnes/snes/alt/ppu-performance/background/background.cpp rename to bsnes/sfc/alt/ppu-performance/background/background.cpp diff --git a/bsnes/snes/alt/ppu-performance/background/background.hpp b/bsnes/sfc/alt/ppu-performance/background/background.hpp similarity index 100% rename from bsnes/snes/alt/ppu-performance/background/background.hpp rename to bsnes/sfc/alt/ppu-performance/background/background.hpp diff --git a/bsnes/snes/alt/ppu-performance/background/mode7.cpp b/bsnes/sfc/alt/ppu-performance/background/mode7.cpp similarity index 100% rename from bsnes/snes/alt/ppu-performance/background/mode7.cpp rename to bsnes/sfc/alt/ppu-performance/background/mode7.cpp diff --git a/bsnes/snes/alt/ppu-performance/cache/cache.cpp b/bsnes/sfc/alt/ppu-performance/cache/cache.cpp similarity index 100% rename from bsnes/snes/alt/ppu-performance/cache/cache.cpp rename to bsnes/sfc/alt/ppu-performance/cache/cache.cpp diff --git a/bsnes/snes/alt/ppu-performance/cache/cache.hpp b/bsnes/sfc/alt/ppu-performance/cache/cache.hpp similarity index 100% rename from bsnes/snes/alt/ppu-performance/cache/cache.hpp rename to bsnes/sfc/alt/ppu-performance/cache/cache.hpp diff --git a/bsnes/snes/alt/ppu-performance/mmio/mmio.cpp b/bsnes/sfc/alt/ppu-performance/mmio/mmio.cpp similarity index 100% rename from bsnes/snes/alt/ppu-performance/mmio/mmio.cpp rename to bsnes/sfc/alt/ppu-performance/mmio/mmio.cpp diff --git a/bsnes/snes/alt/ppu-performance/mmio/mmio.hpp b/bsnes/sfc/alt/ppu-performance/mmio/mmio.hpp similarity index 100% rename from bsnes/snes/alt/ppu-performance/mmio/mmio.hpp rename to bsnes/sfc/alt/ppu-performance/mmio/mmio.hpp diff --git a/bsnes/snes/alt/ppu-performance/ppu.cpp b/bsnes/sfc/alt/ppu-performance/ppu.cpp similarity index 99% rename from bsnes/snes/alt/ppu-performance/ppu.cpp rename to bsnes/sfc/alt/ppu-performance/ppu.cpp index 48e8c6a8..47bc7dfc 100755 --- a/bsnes/snes/alt/ppu-performance/ppu.cpp +++ b/bsnes/sfc/alt/ppu-performance/ppu.cpp @@ -1,4 +1,4 @@ -#include +#include #define PPU_CPP namespace SuperFamicom { diff --git a/bsnes/snes/alt/ppu-performance/ppu.hpp b/bsnes/sfc/alt/ppu-performance/ppu.hpp similarity index 100% rename from bsnes/snes/alt/ppu-performance/ppu.hpp rename to bsnes/sfc/alt/ppu-performance/ppu.hpp diff --git a/bsnes/snes/alt/ppu-performance/screen/screen.cpp b/bsnes/sfc/alt/ppu-performance/screen/screen.cpp similarity index 93% rename from bsnes/snes/alt/ppu-performance/screen/screen.cpp rename to bsnes/sfc/alt/ppu-performance/screen/screen.cpp index 7939f243..43185a4b 100755 --- a/bsnes/snes/alt/ppu-performance/screen/screen.cpp +++ b/bsnes/sfc/alt/ppu-performance/screen/screen.cpp @@ -120,12 +120,12 @@ void PPU::Screen::render() { if(!self.regs.pseudo_hires && self.regs.bgmode != 5 && self.regs.bgmode != 6) { for(unsigned i = 0; i < 256; i++) { - data[i] = (self.regs.display_brightness << 15) | get_pixel_main(i); + data[i] = video.palette[self.regs.display_brightness << 15 | get_pixel_main(i)]; } } else { for(unsigned i = 0; i < 256; i++) { - *data++ = (self.regs.display_brightness << 15) | get_pixel_sub(i); - *data++ = (self.regs.display_brightness << 15) | get_pixel_main(i); + *data++ = video.palette[self.regs.display_brightness << 15 | get_pixel_sub(i)]; + *data++ = video.palette[self.regs.display_brightness << 15 | get_pixel_main(i)]; } } } diff --git a/bsnes/snes/alt/ppu-performance/screen/screen.hpp b/bsnes/sfc/alt/ppu-performance/screen/screen.hpp similarity index 100% rename from bsnes/snes/alt/ppu-performance/screen/screen.hpp rename to bsnes/sfc/alt/ppu-performance/screen/screen.hpp diff --git a/bsnes/snes/alt/ppu-performance/serialization.cpp b/bsnes/sfc/alt/ppu-performance/serialization.cpp similarity index 100% rename from bsnes/snes/alt/ppu-performance/serialization.cpp rename to bsnes/sfc/alt/ppu-performance/serialization.cpp diff --git a/bsnes/snes/alt/ppu-performance/sprite/sprite.cpp b/bsnes/sfc/alt/ppu-performance/sprite/sprite.cpp similarity index 100% rename from bsnes/snes/alt/ppu-performance/sprite/sprite.cpp rename to bsnes/sfc/alt/ppu-performance/sprite/sprite.cpp diff --git a/bsnes/snes/alt/ppu-performance/sprite/sprite.hpp b/bsnes/sfc/alt/ppu-performance/sprite/sprite.hpp similarity index 100% rename from bsnes/snes/alt/ppu-performance/sprite/sprite.hpp rename to bsnes/sfc/alt/ppu-performance/sprite/sprite.hpp diff --git a/bsnes/snes/alt/ppu-performance/window/window.cpp b/bsnes/sfc/alt/ppu-performance/window/window.cpp similarity index 100% rename from bsnes/snes/alt/ppu-performance/window/window.cpp rename to bsnes/sfc/alt/ppu-performance/window/window.cpp diff --git a/bsnes/snes/alt/ppu-performance/window/window.hpp b/bsnes/sfc/alt/ppu-performance/window/window.hpp similarity index 100% rename from bsnes/snes/alt/ppu-performance/window/window.hpp rename to bsnes/sfc/alt/ppu-performance/window/window.hpp diff --git a/bsnes/snes/alt/smp/algorithms.cpp b/bsnes/sfc/alt/smp/algorithms.cpp similarity index 100% rename from bsnes/snes/alt/smp/algorithms.cpp rename to bsnes/sfc/alt/smp/algorithms.cpp diff --git a/bsnes/snes/alt/smp/core.cpp b/bsnes/sfc/alt/smp/core.cpp similarity index 100% rename from bsnes/snes/alt/smp/core.cpp rename to bsnes/sfc/alt/smp/core.cpp diff --git a/bsnes/snes/alt/smp/core/cc.sh b/bsnes/sfc/alt/smp/core/cc.sh similarity index 100% rename from bsnes/snes/alt/smp/core/cc.sh rename to bsnes/sfc/alt/smp/core/cc.sh diff --git a/bsnes/snes/alt/smp/core/generate.cpp b/bsnes/sfc/alt/smp/core/generate.cpp similarity index 100% rename from bsnes/snes/alt/smp/core/generate.cpp rename to bsnes/sfc/alt/smp/core/generate.cpp diff --git a/bsnes/snes/alt/smp/core/op_misc.b b/bsnes/sfc/alt/smp/core/op_misc.b similarity index 100% rename from bsnes/snes/alt/smp/core/op_misc.b rename to bsnes/sfc/alt/smp/core/op_misc.b diff --git a/bsnes/snes/alt/smp/core/op_misc.cpp b/bsnes/sfc/alt/smp/core/op_misc.cpp similarity index 100% rename from bsnes/snes/alt/smp/core/op_misc.cpp rename to bsnes/sfc/alt/smp/core/op_misc.cpp diff --git a/bsnes/snes/alt/smp/core/op_mov.b b/bsnes/sfc/alt/smp/core/op_mov.b similarity index 100% rename from bsnes/snes/alt/smp/core/op_mov.b rename to bsnes/sfc/alt/smp/core/op_mov.b diff --git a/bsnes/snes/alt/smp/core/op_mov.cpp b/bsnes/sfc/alt/smp/core/op_mov.cpp similarity index 100% rename from bsnes/snes/alt/smp/core/op_mov.cpp rename to bsnes/sfc/alt/smp/core/op_mov.cpp diff --git a/bsnes/snes/alt/smp/core/op_pc.b b/bsnes/sfc/alt/smp/core/op_pc.b similarity index 100% rename from bsnes/snes/alt/smp/core/op_pc.b rename to bsnes/sfc/alt/smp/core/op_pc.b diff --git a/bsnes/snes/alt/smp/core/op_pc.cpp b/bsnes/sfc/alt/smp/core/op_pc.cpp similarity index 100% rename from bsnes/snes/alt/smp/core/op_pc.cpp rename to bsnes/sfc/alt/smp/core/op_pc.cpp diff --git a/bsnes/snes/alt/smp/core/op_read.b b/bsnes/sfc/alt/smp/core/op_read.b similarity index 100% rename from bsnes/snes/alt/smp/core/op_read.b rename to bsnes/sfc/alt/smp/core/op_read.b diff --git a/bsnes/snes/alt/smp/core/op_read.cpp b/bsnes/sfc/alt/smp/core/op_read.cpp similarity index 100% rename from bsnes/snes/alt/smp/core/op_read.cpp rename to bsnes/sfc/alt/smp/core/op_read.cpp diff --git a/bsnes/snes/alt/smp/core/op_rmw.b b/bsnes/sfc/alt/smp/core/op_rmw.b similarity index 100% rename from bsnes/snes/alt/smp/core/op_rmw.b rename to bsnes/sfc/alt/smp/core/op_rmw.b diff --git a/bsnes/snes/alt/smp/core/op_rmw.cpp b/bsnes/sfc/alt/smp/core/op_rmw.cpp similarity index 100% rename from bsnes/snes/alt/smp/core/op_rmw.cpp rename to bsnes/sfc/alt/smp/core/op_rmw.cpp diff --git a/bsnes/snes/alt/smp/core/opcycle_misc.cpp b/bsnes/sfc/alt/smp/core/opcycle_misc.cpp similarity index 100% rename from bsnes/snes/alt/smp/core/opcycle_misc.cpp rename to bsnes/sfc/alt/smp/core/opcycle_misc.cpp diff --git a/bsnes/snes/alt/smp/core/opcycle_mov.cpp b/bsnes/sfc/alt/smp/core/opcycle_mov.cpp similarity index 100% rename from bsnes/snes/alt/smp/core/opcycle_mov.cpp rename to bsnes/sfc/alt/smp/core/opcycle_mov.cpp diff --git a/bsnes/snes/alt/smp/core/opcycle_pc.cpp b/bsnes/sfc/alt/smp/core/opcycle_pc.cpp similarity index 100% rename from bsnes/snes/alt/smp/core/opcycle_pc.cpp rename to bsnes/sfc/alt/smp/core/opcycle_pc.cpp diff --git a/bsnes/snes/alt/smp/core/opcycle_read.cpp b/bsnes/sfc/alt/smp/core/opcycle_read.cpp similarity index 100% rename from bsnes/snes/alt/smp/core/opcycle_read.cpp rename to bsnes/sfc/alt/smp/core/opcycle_read.cpp diff --git a/bsnes/snes/alt/smp/core/opcycle_rmw.cpp b/bsnes/sfc/alt/smp/core/opcycle_rmw.cpp similarity index 100% rename from bsnes/snes/alt/smp/core/opcycle_rmw.cpp rename to bsnes/sfc/alt/smp/core/opcycle_rmw.cpp diff --git a/bsnes/snes/alt/smp/disassembler.cpp b/bsnes/sfc/alt/smp/disassembler.cpp similarity index 100% rename from bsnes/snes/alt/smp/disassembler.cpp rename to bsnes/sfc/alt/smp/disassembler.cpp diff --git a/bsnes/snes/alt/smp/memory.cpp b/bsnes/sfc/alt/smp/memory.cpp similarity index 100% rename from bsnes/snes/alt/smp/memory.cpp rename to bsnes/sfc/alt/smp/memory.cpp diff --git a/bsnes/snes/alt/smp/smp.cpp b/bsnes/sfc/alt/smp/smp.cpp similarity index 99% rename from bsnes/snes/alt/smp/smp.cpp rename to bsnes/sfc/alt/smp/smp.cpp index 2ebbf917..d6f33d19 100755 --- a/bsnes/snes/alt/smp/smp.cpp +++ b/bsnes/sfc/alt/smp/smp.cpp @@ -1,6 +1,6 @@ #define CYCLE_ACCURATE -#include +#include #define SMP_CPP namespace SuperFamicom { diff --git a/bsnes/snes/alt/smp/smp.hpp b/bsnes/sfc/alt/smp/smp.hpp similarity index 100% rename from bsnes/snes/alt/smp/smp.hpp rename to bsnes/sfc/alt/smp/smp.hpp diff --git a/bsnes/snes/alt/smp/timing.cpp b/bsnes/sfc/alt/smp/timing.cpp similarity index 100% rename from bsnes/snes/alt/smp/timing.cpp rename to bsnes/sfc/alt/smp/timing.cpp diff --git a/bsnes/snes/cartridge/cartridge.cpp b/bsnes/sfc/cartridge/cartridge.cpp similarity index 92% rename from bsnes/snes/cartridge/cartridge.cpp rename to bsnes/sfc/cartridge/cartridge.cpp index 0ce11140..0fd8af16 100755 --- a/bsnes/snes/cartridge/cartridge.cpp +++ b/bsnes/sfc/cartridge/cartridge.cpp @@ -1,7 +1,4 @@ -#include - -#include -#include +#include #define CARTRIDGE_CPP namespace SuperFamicom { @@ -46,8 +43,6 @@ void Cartridge::load(Mode cartridge_mode, const string &markup) { rom.write_protect(true); ram.write_protect(false); - crc32 = crc32_calculate(rom.data(), rom.size()); - switch((Mode)mode) { case Mode::Normal: case Mode::BsxSlotted: diff --git a/bsnes/snes/cartridge/cartridge.hpp b/bsnes/sfc/cartridge/cartridge.hpp similarity index 98% rename from bsnes/snes/cartridge/cartridge.hpp rename to bsnes/sfc/cartridge/cartridge.hpp index 6fa795bc..5b3df94f 100755 --- a/bsnes/snes/cartridge/cartridge.hpp +++ b/bsnes/sfc/cartridge/cartridge.hpp @@ -25,7 +25,6 @@ struct Cartridge : property { MappedRAM ram; readonly loaded; - readonly crc32; readonly sha256; readonly mode; diff --git a/bsnes/snes/cartridge/markup.cpp b/bsnes/sfc/cartridge/markup.cpp similarity index 100% rename from bsnes/snes/cartridge/markup.cpp rename to bsnes/sfc/cartridge/markup.cpp diff --git a/bsnes/snes/cartridge/serialization.cpp b/bsnes/sfc/cartridge/serialization.cpp similarity index 100% rename from bsnes/snes/cartridge/serialization.cpp rename to bsnes/sfc/cartridge/serialization.cpp diff --git a/bsnes/snes/cheat/cheat.cpp b/bsnes/sfc/cheat/cheat.cpp similarity index 99% rename from bsnes/snes/cheat/cheat.cpp rename to bsnes/sfc/cheat/cheat.cpp index b118feab..82a77ea8 100755 --- a/bsnes/snes/cheat/cheat.cpp +++ b/bsnes/sfc/cheat/cheat.cpp @@ -1,4 +1,4 @@ -#include +#include #define CHEAT_CPP namespace SuperFamicom { diff --git a/bsnes/snes/cheat/cheat.hpp b/bsnes/sfc/cheat/cheat.hpp similarity index 100% rename from bsnes/snes/cheat/cheat.hpp rename to bsnes/sfc/cheat/cheat.hpp diff --git a/bsnes/snes/chip/armdsp/armdsp.cpp b/bsnes/sfc/chip/armdsp/armdsp.cpp similarity index 98% rename from bsnes/snes/chip/armdsp/armdsp.cpp rename to bsnes/sfc/chip/armdsp/armdsp.cpp index 20d8e2a4..313bd8ba 100755 --- a/bsnes/snes/chip/armdsp/armdsp.cpp +++ b/bsnes/sfc/chip/armdsp/armdsp.cpp @@ -1,4 +1,4 @@ -#include +#include #define ARMDSP_CPP namespace SuperFamicom { diff --git a/bsnes/snes/chip/armdsp/armdsp.hpp b/bsnes/sfc/chip/armdsp/armdsp.hpp similarity index 100% rename from bsnes/snes/chip/armdsp/armdsp.hpp rename to bsnes/sfc/chip/armdsp/armdsp.hpp diff --git a/bsnes/snes/chip/armdsp/memory.cpp b/bsnes/sfc/chip/armdsp/memory.cpp similarity index 100% rename from bsnes/snes/chip/armdsp/memory.cpp rename to bsnes/sfc/chip/armdsp/memory.cpp diff --git a/bsnes/snes/chip/armdsp/registers.hpp b/bsnes/sfc/chip/armdsp/registers.hpp similarity index 100% rename from bsnes/snes/chip/armdsp/registers.hpp rename to bsnes/sfc/chip/armdsp/registers.hpp diff --git a/bsnes/snes/chip/armdsp/serialization.cpp b/bsnes/sfc/chip/armdsp/serialization.cpp similarity index 100% rename from bsnes/snes/chip/armdsp/serialization.cpp rename to bsnes/sfc/chip/armdsp/serialization.cpp diff --git a/bsnes/snes/chip/bsx/bsx.cpp b/bsnes/sfc/chip/bsx/bsx.cpp similarity index 85% rename from bsnes/snes/chip/bsx/bsx.cpp rename to bsnes/sfc/chip/bsx/bsx.cpp index 7ea3f695..2a384db0 100755 --- a/bsnes/snes/chip/bsx/bsx.cpp +++ b/bsnes/sfc/chip/bsx/bsx.cpp @@ -1,4 +1,4 @@ -#include +#include #define BSX_CPP namespace SuperFamicom { diff --git a/bsnes/snes/chip/bsx/bsx.hpp b/bsnes/sfc/chip/bsx/bsx.hpp similarity index 100% rename from bsnes/snes/chip/bsx/bsx.hpp rename to bsnes/sfc/chip/bsx/bsx.hpp diff --git a/bsnes/snes/chip/bsx/cartridge/cartridge.cpp b/bsnes/sfc/chip/bsx/cartridge/cartridge.cpp similarity index 100% rename from bsnes/snes/chip/bsx/cartridge/cartridge.cpp rename to bsnes/sfc/chip/bsx/cartridge/cartridge.cpp diff --git a/bsnes/snes/chip/bsx/cartridge/cartridge.hpp b/bsnes/sfc/chip/bsx/cartridge/cartridge.hpp similarity index 100% rename from bsnes/snes/chip/bsx/cartridge/cartridge.hpp rename to bsnes/sfc/chip/bsx/cartridge/cartridge.hpp diff --git a/bsnes/snes/chip/bsx/flash/flash.cpp b/bsnes/sfc/chip/bsx/flash/flash.cpp similarity index 100% rename from bsnes/snes/chip/bsx/flash/flash.cpp rename to bsnes/sfc/chip/bsx/flash/flash.cpp diff --git a/bsnes/snes/chip/bsx/flash/flash.hpp b/bsnes/sfc/chip/bsx/flash/flash.hpp similarity index 100% rename from bsnes/snes/chip/bsx/flash/flash.hpp rename to bsnes/sfc/chip/bsx/flash/flash.hpp diff --git a/bsnes/snes/chip/bsx/satellaview/satellaview.cpp b/bsnes/sfc/chip/bsx/satellaview/satellaview.cpp similarity index 100% rename from bsnes/snes/chip/bsx/satellaview/satellaview.cpp rename to bsnes/sfc/chip/bsx/satellaview/satellaview.cpp diff --git a/bsnes/snes/chip/bsx/satellaview/satellaview.hpp b/bsnes/sfc/chip/bsx/satellaview/satellaview.hpp similarity index 100% rename from bsnes/snes/chip/bsx/satellaview/satellaview.hpp rename to bsnes/sfc/chip/bsx/satellaview/satellaview.hpp diff --git a/bsnes/sfc/chip/chip.hpp b/bsnes/sfc/chip/chip.hpp new file mode 100755 index 00000000..3903b4bd --- /dev/null +++ b/bsnes/sfc/chip/chip.hpp @@ -0,0 +1,31 @@ +struct Coprocessor : Thread { + alwaysinline void step(unsigned clocks); + alwaysinline void synchronize_cpu(); +}; + +#if defined(GAMEBOY) +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +void Coprocessor::step(unsigned clocks) { + clock += clocks * (uint64)cpu.frequency; +} + +void Coprocessor::synchronize_cpu() { + if(clock >= 0 && scheduler.sync != Scheduler::SynchronizeMode::All) co_switch(cpu.thread); +} diff --git a/bsnes/snes/chip/hitachidsp/hitachidsp.cpp b/bsnes/sfc/chip/hitachidsp/hitachidsp.cpp similarity index 97% rename from bsnes/snes/chip/hitachidsp/hitachidsp.cpp rename to bsnes/sfc/chip/hitachidsp/hitachidsp.cpp index b8686808..948f4da9 100755 --- a/bsnes/snes/chip/hitachidsp/hitachidsp.cpp +++ b/bsnes/sfc/chip/hitachidsp/hitachidsp.cpp @@ -1,4 +1,4 @@ -#include +#include #define HITACHIDSP_CPP namespace SuperFamicom { diff --git a/bsnes/snes/chip/hitachidsp/hitachidsp.hpp b/bsnes/sfc/chip/hitachidsp/hitachidsp.hpp similarity index 100% rename from bsnes/snes/chip/hitachidsp/hitachidsp.hpp rename to bsnes/sfc/chip/hitachidsp/hitachidsp.hpp diff --git a/bsnes/snes/chip/hitachidsp/memory.cpp b/bsnes/sfc/chip/hitachidsp/memory.cpp similarity index 100% rename from bsnes/snes/chip/hitachidsp/memory.cpp rename to bsnes/sfc/chip/hitachidsp/memory.cpp diff --git a/bsnes/snes/chip/hitachidsp/mmio.hpp b/bsnes/sfc/chip/hitachidsp/mmio.hpp similarity index 100% rename from bsnes/snes/chip/hitachidsp/mmio.hpp rename to bsnes/sfc/chip/hitachidsp/mmio.hpp diff --git a/bsnes/snes/chip/hitachidsp/serialization.cpp b/bsnes/sfc/chip/hitachidsp/serialization.cpp similarity index 100% rename from bsnes/snes/chip/hitachidsp/serialization.cpp rename to bsnes/sfc/chip/hitachidsp/serialization.cpp diff --git a/bsnes/snes/chip/icd2/icd2.cpp b/bsnes/sfc/chip/icd2/icd2.cpp similarity index 98% rename from bsnes/snes/chip/icd2/icd2.cpp rename to bsnes/sfc/chip/icd2/icd2.cpp index 3e3856b9..a6101469 100755 --- a/bsnes/snes/chip/icd2/icd2.cpp +++ b/bsnes/sfc/chip/icd2/icd2.cpp @@ -1,6 +1,6 @@ #if defined(GAMEBOY) -#include +#include #define ICD2_CPP namespace SuperFamicom { diff --git a/bsnes/snes/chip/icd2/icd2.hpp b/bsnes/sfc/chip/icd2/icd2.hpp similarity index 100% rename from bsnes/snes/chip/icd2/icd2.hpp rename to bsnes/sfc/chip/icd2/icd2.hpp diff --git a/bsnes/snes/chip/icd2/interface/interface.cpp b/bsnes/sfc/chip/icd2/interface/interface.cpp similarity index 100% rename from bsnes/snes/chip/icd2/interface/interface.cpp rename to bsnes/sfc/chip/icd2/interface/interface.cpp diff --git a/bsnes/snes/chip/icd2/interface/interface.hpp b/bsnes/sfc/chip/icd2/interface/interface.hpp similarity index 100% rename from bsnes/snes/chip/icd2/interface/interface.hpp rename to bsnes/sfc/chip/icd2/interface/interface.hpp diff --git a/bsnes/snes/chip/icd2/mmio/mmio.cpp b/bsnes/sfc/chip/icd2/mmio/mmio.cpp similarity index 100% rename from bsnes/snes/chip/icd2/mmio/mmio.cpp rename to bsnes/sfc/chip/icd2/mmio/mmio.cpp diff --git a/bsnes/snes/chip/icd2/mmio/mmio.hpp b/bsnes/sfc/chip/icd2/mmio/mmio.hpp similarity index 100% rename from bsnes/snes/chip/icd2/mmio/mmio.hpp rename to bsnes/sfc/chip/icd2/mmio/mmio.hpp diff --git a/bsnes/snes/chip/icd2/serialization.cpp b/bsnes/sfc/chip/icd2/serialization.cpp similarity index 100% rename from bsnes/snes/chip/icd2/serialization.cpp rename to bsnes/sfc/chip/icd2/serialization.cpp diff --git a/bsnes/snes/chip/link/link.cpp b/bsnes/sfc/chip/link/link.cpp similarity index 97% rename from bsnes/snes/chip/link/link.cpp rename to bsnes/sfc/chip/link/link.cpp index 45412a0d..f71853cb 100755 --- a/bsnes/snes/chip/link/link.cpp +++ b/bsnes/sfc/chip/link/link.cpp @@ -1,4 +1,4 @@ -#include +#include #define LINK_HPP namespace SuperFamicom { diff --git a/bsnes/snes/chip/link/link.hpp b/bsnes/sfc/chip/link/link.hpp similarity index 100% rename from bsnes/snes/chip/link/link.hpp rename to bsnes/sfc/chip/link/link.hpp diff --git a/bsnes/snes/chip/msu1/msu1.cpp b/bsnes/sfc/chip/msu1/msu1.cpp similarity index 99% rename from bsnes/snes/chip/msu1/msu1.cpp rename to bsnes/sfc/chip/msu1/msu1.cpp index dd4a727b..7a5c9e0a 100755 --- a/bsnes/snes/chip/msu1/msu1.cpp +++ b/bsnes/sfc/chip/msu1/msu1.cpp @@ -1,4 +1,4 @@ -#include +#include #define MSU1_CPP namespace SuperFamicom { diff --git a/bsnes/snes/chip/msu1/msu1.hpp b/bsnes/sfc/chip/msu1/msu1.hpp similarity index 100% rename from bsnes/snes/chip/msu1/msu1.hpp rename to bsnes/sfc/chip/msu1/msu1.hpp diff --git a/bsnes/snes/chip/msu1/serialization.cpp b/bsnes/sfc/chip/msu1/serialization.cpp similarity index 100% rename from bsnes/snes/chip/msu1/serialization.cpp rename to bsnes/sfc/chip/msu1/serialization.cpp diff --git a/bsnes/snes/chip/necdsp/necdsp.cpp b/bsnes/sfc/chip/necdsp/necdsp.cpp similarity index 98% rename from bsnes/snes/chip/necdsp/necdsp.cpp rename to bsnes/sfc/chip/necdsp/necdsp.cpp index 15b4d1ad..05bc0450 100755 --- a/bsnes/snes/chip/necdsp/necdsp.cpp +++ b/bsnes/sfc/chip/necdsp/necdsp.cpp @@ -1,4 +1,4 @@ -#include +#include #define NECDSP_CPP namespace SuperFamicom { diff --git a/bsnes/snes/chip/necdsp/necdsp.hpp b/bsnes/sfc/chip/necdsp/necdsp.hpp similarity index 100% rename from bsnes/snes/chip/necdsp/necdsp.hpp rename to bsnes/sfc/chip/necdsp/necdsp.hpp diff --git a/bsnes/snes/chip/necdsp/serialization.cpp b/bsnes/sfc/chip/necdsp/serialization.cpp similarity index 100% rename from bsnes/snes/chip/necdsp/serialization.cpp rename to bsnes/sfc/chip/necdsp/serialization.cpp diff --git a/bsnes/snes/chip/nss/nss.cpp b/bsnes/sfc/chip/nss/nss.cpp similarity index 96% rename from bsnes/snes/chip/nss/nss.cpp rename to bsnes/sfc/chip/nss/nss.cpp index 1439be5b..c4866732 100755 --- a/bsnes/snes/chip/nss/nss.cpp +++ b/bsnes/sfc/chip/nss/nss.cpp @@ -1,4 +1,4 @@ -#include +#include #define NSS_CPP namespace SuperFamicom { diff --git a/bsnes/snes/chip/nss/nss.hpp b/bsnes/sfc/chip/nss/nss.hpp similarity index 100% rename from bsnes/snes/chip/nss/nss.hpp rename to bsnes/sfc/chip/nss/nss.hpp diff --git a/bsnes/snes/chip/obc1/obc1.cpp b/bsnes/sfc/chip/obc1/obc1.cpp similarity index 98% rename from bsnes/snes/chip/obc1/obc1.cpp rename to bsnes/sfc/chip/obc1/obc1.cpp index e9ff879f..accdd87d 100755 --- a/bsnes/snes/chip/obc1/obc1.cpp +++ b/bsnes/sfc/chip/obc1/obc1.cpp @@ -1,4 +1,4 @@ -#include +#include #define OBC1_CPP namespace SuperFamicom { diff --git a/bsnes/snes/chip/obc1/obc1.hpp b/bsnes/sfc/chip/obc1/obc1.hpp similarity index 100% rename from bsnes/snes/chip/obc1/obc1.hpp rename to bsnes/sfc/chip/obc1/obc1.hpp diff --git a/bsnes/snes/chip/obc1/serialization.cpp b/bsnes/sfc/chip/obc1/serialization.cpp similarity index 100% rename from bsnes/snes/chip/obc1/serialization.cpp rename to bsnes/sfc/chip/obc1/serialization.cpp diff --git a/bsnes/snes/chip/sa1/bus/bus.cpp b/bsnes/sfc/chip/sa1/bus/bus.cpp similarity index 100% rename from bsnes/snes/chip/sa1/bus/bus.cpp rename to bsnes/sfc/chip/sa1/bus/bus.cpp diff --git a/bsnes/snes/chip/sa1/bus/bus.hpp b/bsnes/sfc/chip/sa1/bus/bus.hpp similarity index 100% rename from bsnes/snes/chip/sa1/bus/bus.hpp rename to bsnes/sfc/chip/sa1/bus/bus.hpp diff --git a/bsnes/snes/chip/sa1/dma/dma.cpp b/bsnes/sfc/chip/sa1/dma/dma.cpp similarity index 100% rename from bsnes/snes/chip/sa1/dma/dma.cpp rename to bsnes/sfc/chip/sa1/dma/dma.cpp diff --git a/bsnes/snes/chip/sa1/dma/dma.hpp b/bsnes/sfc/chip/sa1/dma/dma.hpp similarity index 100% rename from bsnes/snes/chip/sa1/dma/dma.hpp rename to bsnes/sfc/chip/sa1/dma/dma.hpp diff --git a/bsnes/snes/chip/sa1/memory/memory.cpp b/bsnes/sfc/chip/sa1/memory/memory.cpp similarity index 100% rename from bsnes/snes/chip/sa1/memory/memory.cpp rename to bsnes/sfc/chip/sa1/memory/memory.cpp diff --git a/bsnes/snes/chip/sa1/memory/memory.hpp b/bsnes/sfc/chip/sa1/memory/memory.hpp similarity index 100% rename from bsnes/snes/chip/sa1/memory/memory.hpp rename to bsnes/sfc/chip/sa1/memory/memory.hpp diff --git a/bsnes/snes/chip/sa1/mmio/mmio.cpp b/bsnes/sfc/chip/sa1/mmio/mmio.cpp similarity index 100% rename from bsnes/snes/chip/sa1/mmio/mmio.cpp rename to bsnes/sfc/chip/sa1/mmio/mmio.cpp diff --git a/bsnes/snes/chip/sa1/mmio/mmio.hpp b/bsnes/sfc/chip/sa1/mmio/mmio.hpp similarity index 100% rename from bsnes/snes/chip/sa1/mmio/mmio.hpp rename to bsnes/sfc/chip/sa1/mmio/mmio.hpp diff --git a/bsnes/snes/chip/sa1/sa1.cpp b/bsnes/sfc/chip/sa1/sa1.cpp similarity index 99% rename from bsnes/snes/chip/sa1/sa1.cpp rename to bsnes/sfc/chip/sa1/sa1.cpp index 4a1d1a42..8cc8735a 100755 --- a/bsnes/snes/chip/sa1/sa1.cpp +++ b/bsnes/sfc/chip/sa1/sa1.cpp @@ -1,4 +1,4 @@ -#include +#include #define SA1_CPP namespace SuperFamicom { @@ -149,7 +149,7 @@ void SA1::reset() { regs.mdr = 0x00; regs.wai = false; regs.vector = 0x0000; - CPUcore::update_table(); + R65816::update_table(); status.tick_counter = 0; diff --git a/bsnes/snes/chip/sa1/sa1.hpp b/bsnes/sfc/chip/sa1/sa1.hpp similarity index 91% rename from bsnes/snes/chip/sa1/sa1.hpp rename to bsnes/sfc/chip/sa1/sa1.hpp index 732b2a85..e6d9d3bc 100755 --- a/bsnes/snes/chip/sa1/sa1.hpp +++ b/bsnes/sfc/chip/sa1/sa1.hpp @@ -1,5 +1,4 @@ -class SA1 : public Coprocessor, public CPUcore { -public: +struct SA1 : Processor::R65816, public Coprocessor { #include "bus/bus.hpp" #include "dma/dma.hpp" #include "memory/memory.hpp" diff --git a/bsnes/snes/chip/sa1/serialization.cpp b/bsnes/sfc/chip/sa1/serialization.cpp similarity index 98% rename from bsnes/snes/chip/sa1/serialization.cpp rename to bsnes/sfc/chip/sa1/serialization.cpp index 58ad1172..04377f7f 100755 --- a/bsnes/snes/chip/sa1/serialization.cpp +++ b/bsnes/sfc/chip/sa1/serialization.cpp @@ -1,8 +1,8 @@ #ifdef SA1_CPP void SA1::serialize(serializer &s) { + R65816::serialize(s); Thread::serialize(s); - CPUcore::core_serialize(s); //sa1.hpp s.integer(status.tick_counter); diff --git a/bsnes/snes/chip/sdd1/decomp.cpp b/bsnes/sfc/chip/sdd1/decomp.cpp similarity index 100% rename from bsnes/snes/chip/sdd1/decomp.cpp rename to bsnes/sfc/chip/sdd1/decomp.cpp diff --git a/bsnes/snes/chip/sdd1/decomp.hpp b/bsnes/sfc/chip/sdd1/decomp.hpp similarity index 100% rename from bsnes/snes/chip/sdd1/decomp.hpp rename to bsnes/sfc/chip/sdd1/decomp.hpp diff --git a/bsnes/snes/chip/sdd1/sdd1.cpp b/bsnes/sfc/chip/sdd1/sdd1.cpp similarity index 99% rename from bsnes/snes/chip/sdd1/sdd1.cpp rename to bsnes/sfc/chip/sdd1/sdd1.cpp index 8416cb62..c778dc84 100755 --- a/bsnes/snes/chip/sdd1/sdd1.cpp +++ b/bsnes/sfc/chip/sdd1/sdd1.cpp @@ -1,4 +1,4 @@ -#include +#include #define SDD1_CPP namespace SuperFamicom { diff --git a/bsnes/snes/chip/sdd1/sdd1.hpp b/bsnes/sfc/chip/sdd1/sdd1.hpp similarity index 100% rename from bsnes/snes/chip/sdd1/sdd1.hpp rename to bsnes/sfc/chip/sdd1/sdd1.hpp diff --git a/bsnes/snes/chip/sdd1/serialization.cpp b/bsnes/sfc/chip/sdd1/serialization.cpp similarity index 100% rename from bsnes/snes/chip/sdd1/serialization.cpp rename to bsnes/sfc/chip/sdd1/serialization.cpp diff --git a/bsnes/snes/chip/spc7110/decomp.cpp b/bsnes/sfc/chip/spc7110/decomp.cpp similarity index 100% rename from bsnes/snes/chip/spc7110/decomp.cpp rename to bsnes/sfc/chip/spc7110/decomp.cpp diff --git a/bsnes/snes/chip/spc7110/decomp.hpp b/bsnes/sfc/chip/spc7110/decomp.hpp similarity index 100% rename from bsnes/snes/chip/spc7110/decomp.hpp rename to bsnes/sfc/chip/spc7110/decomp.hpp diff --git a/bsnes/snes/chip/spc7110/serialization.cpp b/bsnes/sfc/chip/spc7110/serialization.cpp similarity index 100% rename from bsnes/snes/chip/spc7110/serialization.cpp rename to bsnes/sfc/chip/spc7110/serialization.cpp diff --git a/bsnes/snes/chip/spc7110/spc7110.cpp b/bsnes/sfc/chip/spc7110/spc7110.cpp similarity index 99% rename from bsnes/snes/chip/spc7110/spc7110.cpp rename to bsnes/sfc/chip/spc7110/spc7110.cpp index b7a7f5a7..80c9a2b7 100755 --- a/bsnes/snes/chip/spc7110/spc7110.cpp +++ b/bsnes/sfc/chip/spc7110/spc7110.cpp @@ -1,4 +1,4 @@ -#include +#include #define SPC7110_CPP namespace SuperFamicom { diff --git a/bsnes/snes/chip/spc7110/spc7110.hpp b/bsnes/sfc/chip/spc7110/spc7110.hpp similarity index 100% rename from bsnes/snes/chip/spc7110/spc7110.hpp rename to bsnes/sfc/chip/spc7110/spc7110.hpp diff --git a/bsnes/snes/chip/srtc/serialization.cpp b/bsnes/sfc/chip/srtc/serialization.cpp similarity index 100% rename from bsnes/snes/chip/srtc/serialization.cpp rename to bsnes/sfc/chip/srtc/serialization.cpp diff --git a/bsnes/snes/chip/srtc/srtc.cpp b/bsnes/sfc/chip/srtc/srtc.cpp similarity index 99% rename from bsnes/snes/chip/srtc/srtc.cpp rename to bsnes/sfc/chip/srtc/srtc.cpp index ce50f873..cad4e399 100755 --- a/bsnes/snes/chip/srtc/srtc.cpp +++ b/bsnes/sfc/chip/srtc/srtc.cpp @@ -1,4 +1,4 @@ -#include +#include #define SRTC_CPP namespace SuperFamicom { diff --git a/bsnes/snes/chip/srtc/srtc.hpp b/bsnes/sfc/chip/srtc/srtc.hpp similarity index 100% rename from bsnes/snes/chip/srtc/srtc.hpp rename to bsnes/sfc/chip/srtc/srtc.hpp diff --git a/bsnes/snes/chip/sufamiturbo/serialization.cpp b/bsnes/sfc/chip/sufamiturbo/serialization.cpp similarity index 100% rename from bsnes/snes/chip/sufamiturbo/serialization.cpp rename to bsnes/sfc/chip/sufamiturbo/serialization.cpp diff --git a/bsnes/snes/chip/sufamiturbo/sufamiturbo.cpp b/bsnes/sfc/chip/sufamiturbo/sufamiturbo.cpp similarity index 97% rename from bsnes/snes/chip/sufamiturbo/sufamiturbo.cpp rename to bsnes/sfc/chip/sufamiturbo/sufamiturbo.cpp index 196d7a49..b1d16338 100755 --- a/bsnes/snes/chip/sufamiturbo/sufamiturbo.cpp +++ b/bsnes/sfc/chip/sufamiturbo/sufamiturbo.cpp @@ -1,4 +1,4 @@ -#include +#include #define SUFAMITURBO_CPP namespace SuperFamicom { diff --git a/bsnes/snes/chip/sufamiturbo/sufamiturbo.hpp b/bsnes/sfc/chip/sufamiturbo/sufamiturbo.hpp similarity index 100% rename from bsnes/snes/chip/sufamiturbo/sufamiturbo.hpp rename to bsnes/sfc/chip/sufamiturbo/sufamiturbo.hpp diff --git a/bsnes/snes/chip/superfx/bus/bus.cpp b/bsnes/sfc/chip/superfx/bus/bus.cpp similarity index 100% rename from bsnes/snes/chip/superfx/bus/bus.cpp rename to bsnes/sfc/chip/superfx/bus/bus.cpp diff --git a/bsnes/snes/chip/superfx/bus/bus.hpp b/bsnes/sfc/chip/superfx/bus/bus.hpp similarity index 100% rename from bsnes/snes/chip/superfx/bus/bus.hpp rename to bsnes/sfc/chip/superfx/bus/bus.hpp diff --git a/bsnes/snes/chip/superfx/core/core.cpp b/bsnes/sfc/chip/superfx/core/core.cpp similarity index 95% rename from bsnes/snes/chip/superfx/core/core.cpp rename to bsnes/sfc/chip/superfx/core/core.cpp index 92c2afd6..a15c65db 100755 --- a/bsnes/snes/chip/superfx/core/core.cpp +++ b/bsnes/sfc/chip/superfx/core/core.cpp @@ -1,7 +1,8 @@ #ifdef SUPERFX_CPP -#include "opcodes.cpp" -#include "opcode_table.cpp" +void SuperFX::stop() { + cpu.regs.irq = 1; +} uint8 SuperFX::color(uint8 source) { if(regs.por.highnibble) return (regs.colr & 0xf0) | (source >> 4); @@ -65,7 +66,7 @@ uint8 SuperFX::rpix(uint8 x, uint8 y) { for(unsigned n = 0; n < bpp; n++) { unsigned byte = ((n >> 1) << 4) + (n & 1); // = [n]{ 0, 1, 16, 17, 32, 33, 48, 49 }; - add_clocks(memory_access_speed); + step(memory_access_speed); data |= ((bus_read(addr + byte) >> x) & 1) << n; } @@ -93,11 +94,11 @@ void SuperFX::pixelcache_flush(pixelcache_t &cache) { uint8 data = 0x00; for(unsigned x = 0; x < 8; x++) data |= ((cache.data[x] >> n) & 1) << x; if(cache.bitpend != 0xff) { - add_clocks(memory_access_speed); + step(memory_access_speed); data &= cache.bitpend; data |= bus_read(addr + byte) & ~cache.bitpend; } - add_clocks(memory_access_speed); + step(memory_access_speed); bus_write(addr + byte, data); } diff --git a/bsnes/sfc/chip/superfx/core/core.hpp b/bsnes/sfc/chip/superfx/core/core.hpp new file mode 100755 index 00000000..66afbef9 --- /dev/null +++ b/bsnes/sfc/chip/superfx/core/core.hpp @@ -0,0 +1,5 @@ +void stop(); +uint8 color(uint8 source); +void plot(uint8 x, uint8 y); +uint8 rpix(uint8 x, uint8 y); +void pixelcache_flush(pixelcache_t &cache); diff --git a/bsnes/snes/chip/superfx/disasm/disasm.cpp b/bsnes/sfc/chip/superfx/disasm/disasm.cpp similarity index 100% rename from bsnes/snes/chip/superfx/disasm/disasm.cpp rename to bsnes/sfc/chip/superfx/disasm/disasm.cpp diff --git a/bsnes/snes/chip/superfx/disasm/disasm.hpp b/bsnes/sfc/chip/superfx/disasm/disasm.hpp similarity index 100% rename from bsnes/snes/chip/superfx/disasm/disasm.hpp rename to bsnes/sfc/chip/superfx/disasm/disasm.hpp diff --git a/bsnes/snes/chip/superfx/memory/memory.cpp b/bsnes/sfc/chip/superfx/memory/memory.cpp similarity index 92% rename from bsnes/snes/chip/superfx/memory/memory.cpp rename to bsnes/sfc/chip/superfx/memory/memory.cpp index 06b62db4..9c7f5216 100755 --- a/bsnes/snes/chip/superfx/memory/memory.cpp +++ b/bsnes/sfc/chip/superfx/memory/memory.cpp @@ -3,7 +3,7 @@ uint8 SuperFX::bus_read(unsigned addr) { if((addr & 0xc00000) == 0x000000) { //$00-3f:0000-7fff, $00-3f:8000-ffff while(!regs.scmr.ron && scheduler.sync != Scheduler::SynchronizeMode::All) { - add_clocks(6); + step(6); synchronize_cpu(); } return cartridge.rom.read((((addr & 0x3f0000) >> 1) | (addr & 0x7fff)) & rom_mask); @@ -11,7 +11,7 @@ uint8 SuperFX::bus_read(unsigned addr) { if((addr & 0xe00000) == 0x400000) { //$40-5f:0000-ffff while(!regs.scmr.ron && scheduler.sync != Scheduler::SynchronizeMode::All) { - add_clocks(6); + step(6); synchronize_cpu(); } return cartridge.rom.read(addr & rom_mask); @@ -19,7 +19,7 @@ uint8 SuperFX::bus_read(unsigned addr) { if((addr & 0xe00000) == 0x600000) { //$60-7f:0000-ffff while(!regs.scmr.ran && scheduler.sync != Scheduler::SynchronizeMode::All) { - add_clocks(6); + step(6); synchronize_cpu(); } return cartridge.ram.read(addr & ram_mask); @@ -29,7 +29,7 @@ uint8 SuperFX::bus_read(unsigned addr) { void SuperFX::bus_write(unsigned addr, uint8 data) { if((addr & 0xe00000) == 0x600000) { //$60-7f:0000-ffff while(!regs.scmr.ran && scheduler.sync != Scheduler::SynchronizeMode::All) { - add_clocks(6); + step(6); synchronize_cpu(); } return cartridge.ram.write(addr & ram_mask, data); @@ -43,12 +43,12 @@ uint8 SuperFX::op_read(uint16 addr) { unsigned dp = offset & 0xfff0; unsigned sp = (regs.pbr << 16) + ((regs.cbr + dp) & 0xfff0); for(unsigned n = 0; n < 16; n++) { - add_clocks(memory_access_speed); + step(memory_access_speed); cache.buffer[dp++] = bus_read(sp++); } cache.valid[offset >> 4] = true; } else { - add_clocks(cache_access_speed); + step(cache_access_speed); } return cache.buffer[offset]; } @@ -56,12 +56,12 @@ uint8 SuperFX::op_read(uint16 addr) { if(regs.pbr <= 0x5f) { //$[00-5f]:[0000-ffff] ROM rombuffer_sync(); - add_clocks(memory_access_speed); + step(memory_access_speed); return bus_read((regs.pbr << 16) + addr); } else { //$[60-7f]:[0000-ffff] RAM rambuffer_sync(); - add_clocks(memory_access_speed); + step(memory_access_speed); return bus_read((regs.pbr << 16) + addr); } } diff --git a/bsnes/snes/chip/superfx/memory/memory.hpp b/bsnes/sfc/chip/superfx/memory/memory.hpp similarity index 100% rename from bsnes/snes/chip/superfx/memory/memory.hpp rename to bsnes/sfc/chip/superfx/memory/memory.hpp diff --git a/bsnes/snes/chip/superfx/mmio/mmio.cpp b/bsnes/sfc/chip/superfx/mmio/mmio.cpp similarity index 100% rename from bsnes/snes/chip/superfx/mmio/mmio.cpp rename to bsnes/sfc/chip/superfx/mmio/mmio.cpp diff --git a/bsnes/snes/chip/superfx/mmio/mmio.hpp b/bsnes/sfc/chip/superfx/mmio/mmio.hpp similarity index 100% rename from bsnes/snes/chip/superfx/mmio/mmio.hpp rename to bsnes/sfc/chip/superfx/mmio/mmio.hpp diff --git a/bsnes/sfc/chip/superfx/serialization.cpp b/bsnes/sfc/chip/superfx/serialization.cpp new file mode 100755 index 00000000..a2c7d60a --- /dev/null +++ b/bsnes/sfc/chip/superfx/serialization.cpp @@ -0,0 +1,15 @@ +#ifdef SUPERFX_CPP + +void SuperFX::serialize(serializer &s) { + GSU::serialize(s); + Thread::serialize(s); + + s.integer(clockmode); + s.integer(instruction_counter); + + s.integer(cache_access_speed); + s.integer(memory_access_speed); + s.integer(r15_modified); +} + +#endif diff --git a/bsnes/snes/chip/superfx/superfx.cpp b/bsnes/sfc/chip/superfx/superfx.cpp similarity index 65% rename from bsnes/snes/chip/superfx/superfx.cpp rename to bsnes/sfc/chip/superfx/superfx.cpp index a22a5181..dca09904 100755 --- a/bsnes/snes/chip/superfx/superfx.cpp +++ b/bsnes/sfc/chip/superfx/superfx.cpp @@ -1,4 +1,4 @@ -#include +#include #define SUPERFX_CPP namespace SuperFamicom { @@ -22,7 +22,7 @@ void SuperFX::enter() { } if(regs.sfr.g == 0) { - add_clocks(6); + step(6); synchronize_cpu(); continue; } @@ -39,8 +39,8 @@ void SuperFX::enter() { void SuperFX::init() { initialize_opcode_table(); - regs.r[14].on_modify = { &SuperFX::r14_modify, this }; - regs.r[15].on_modify = { &SuperFX::r15_modify, this }; + regs.r[14].modify = { &SuperFX::r14_modify, this }; + regs.r[15].modify = { &SuperFX::r15_modify, this }; } void SuperFX::load() { @@ -50,31 +50,14 @@ void SuperFX::unload() { } void SuperFX::power() { + GSU::power(); clockmode = config.superfx.speed; } void SuperFX::reset() { + GSU::reset(); create(SuperFX::Enter, system.cpu_frequency()); instruction_counter = 0; - - for(unsigned n = 0; n < 16; n++) regs.r[n] = 0x0000; - regs.sfr = 0x0000; - regs.pbr = 0x00; - regs.rombr = 0x00; - regs.rambr = 0; - regs.cbr = 0x0000; - regs.scbr = 0x00; - regs.scmr = 0x00; - regs.colr = 0x00; - regs.por = 0x00; - regs.bramr = 0; - regs.vcr = 0x04; - regs.cfgr = 0x00; - regs.clsr = 0; - regs.pipeline = 0x01; //nop - regs.ramaddr = 0x0000; - regs.reset(); - memory_reset(); timing_reset(); } diff --git a/bsnes/snes/chip/superfx/superfx.hpp b/bsnes/sfc/chip/superfx/superfx.hpp similarity index 87% rename from bsnes/snes/chip/superfx/superfx.hpp rename to bsnes/sfc/chip/superfx/superfx.hpp index cf28952b..6cd9b9ea 100755 --- a/bsnes/snes/chip/superfx/superfx.hpp +++ b/bsnes/sfc/chip/superfx/superfx.hpp @@ -1,5 +1,4 @@ -class SuperFX : public Coprocessor { -public: +struct SuperFX : Processor::GSU, Coprocessor { #include "bus/bus.hpp" #include "core/core.hpp" #include "memory/memory.hpp" @@ -16,7 +15,7 @@ public: void reset(); void serialize(serializer&); -private: +privileged: unsigned clockmode; unsigned instruction_counter; }; diff --git a/bsnes/snes/chip/superfx/timing/timing.cpp b/bsnes/sfc/chip/superfx/timing/timing.cpp similarity index 92% rename from bsnes/snes/chip/superfx/timing/timing.cpp rename to bsnes/sfc/chip/superfx/timing/timing.cpp index 52765649..d34ba4cd 100755 --- a/bsnes/snes/chip/superfx/timing/timing.cpp +++ b/bsnes/sfc/chip/superfx/timing/timing.cpp @@ -1,6 +1,6 @@ #ifdef SUPERFX_CPP -void SuperFX::add_clocks(unsigned clocks) { +void SuperFX::step(unsigned clocks) { if(regs.romcl) { regs.romcl -= min(clocks, regs.romcl); if(regs.romcl == 0) { @@ -16,12 +16,12 @@ void SuperFX::add_clocks(unsigned clocks) { } } - step(clocks); + Coprocessor::step(clocks); synchronize_cpu(); } void SuperFX::rombuffer_sync() { - if(regs.romcl) add_clocks(regs.romcl); + if(regs.romcl) step(regs.romcl); } void SuperFX::rombuffer_update() { @@ -35,7 +35,7 @@ uint8 SuperFX::rombuffer_read() { } void SuperFX::rambuffer_sync() { - if(regs.ramcl) add_clocks(regs.ramcl); + if(regs.ramcl) step(regs.ramcl); } uint8 SuperFX::rambuffer_read(uint16 addr) { diff --git a/bsnes/snes/chip/superfx/timing/timing.hpp b/bsnes/sfc/chip/superfx/timing/timing.hpp similarity index 91% rename from bsnes/snes/chip/superfx/timing/timing.hpp rename to bsnes/sfc/chip/superfx/timing/timing.hpp index 9ae7e8d4..6d88fcd9 100755 --- a/bsnes/snes/chip/superfx/timing/timing.hpp +++ b/bsnes/sfc/chip/superfx/timing/timing.hpp @@ -2,7 +2,7 @@ unsigned cache_access_speed; unsigned memory_access_speed; bool r15_modified; -void add_clocks(unsigned clocks); +void step(unsigned clocks); void rombuffer_sync(); void rombuffer_update(); diff --git a/bsnes/snes/config/config.cpp b/bsnes/sfc/config/config.cpp similarity index 100% rename from bsnes/snes/config/config.cpp rename to bsnes/sfc/config/config.cpp diff --git a/bsnes/snes/config/config.hpp b/bsnes/sfc/config/config.hpp similarity index 100% rename from bsnes/snes/config/config.hpp rename to bsnes/sfc/config/config.hpp diff --git a/bsnes/snes/controller/controller.cpp b/bsnes/sfc/controller/controller.cpp similarity index 98% rename from bsnes/snes/controller/controller.cpp rename to bsnes/sfc/controller/controller.cpp index 83ae5910..92f1d77e 100755 --- a/bsnes/snes/controller/controller.cpp +++ b/bsnes/sfc/controller/controller.cpp @@ -1,4 +1,4 @@ -#include +#include #define CONTROLLER_CPP namespace SuperFamicom { diff --git a/bsnes/snes/controller/controller.hpp b/bsnes/sfc/controller/controller.hpp similarity index 100% rename from bsnes/snes/controller/controller.hpp rename to bsnes/sfc/controller/controller.hpp diff --git a/bsnes/snes/controller/gamepad/gamepad.cpp b/bsnes/sfc/controller/gamepad/gamepad.cpp similarity index 100% rename from bsnes/snes/controller/gamepad/gamepad.cpp rename to bsnes/sfc/controller/gamepad/gamepad.cpp diff --git a/bsnes/snes/controller/gamepad/gamepad.hpp b/bsnes/sfc/controller/gamepad/gamepad.hpp similarity index 100% rename from bsnes/snes/controller/gamepad/gamepad.hpp rename to bsnes/sfc/controller/gamepad/gamepad.hpp diff --git a/bsnes/snes/controller/justifier/justifier.cpp b/bsnes/sfc/controller/justifier/justifier.cpp similarity index 100% rename from bsnes/snes/controller/justifier/justifier.cpp rename to bsnes/sfc/controller/justifier/justifier.cpp diff --git a/bsnes/snes/controller/justifier/justifier.hpp b/bsnes/sfc/controller/justifier/justifier.hpp similarity index 100% rename from bsnes/snes/controller/justifier/justifier.hpp rename to bsnes/sfc/controller/justifier/justifier.hpp diff --git a/bsnes/snes/controller/mouse/mouse.cpp b/bsnes/sfc/controller/mouse/mouse.cpp similarity index 100% rename from bsnes/snes/controller/mouse/mouse.cpp rename to bsnes/sfc/controller/mouse/mouse.cpp diff --git a/bsnes/snes/controller/mouse/mouse.hpp b/bsnes/sfc/controller/mouse/mouse.hpp similarity index 100% rename from bsnes/snes/controller/mouse/mouse.hpp rename to bsnes/sfc/controller/mouse/mouse.hpp diff --git a/bsnes/snes/controller/multitap/multitap.cpp b/bsnes/sfc/controller/multitap/multitap.cpp similarity index 100% rename from bsnes/snes/controller/multitap/multitap.cpp rename to bsnes/sfc/controller/multitap/multitap.cpp diff --git a/bsnes/snes/controller/multitap/multitap.hpp b/bsnes/sfc/controller/multitap/multitap.hpp similarity index 100% rename from bsnes/snes/controller/multitap/multitap.hpp rename to bsnes/sfc/controller/multitap/multitap.hpp diff --git a/bsnes/snes/controller/superscope/superscope.cpp b/bsnes/sfc/controller/superscope/superscope.cpp similarity index 100% rename from bsnes/snes/controller/superscope/superscope.cpp rename to bsnes/sfc/controller/superscope/superscope.cpp diff --git a/bsnes/snes/controller/superscope/superscope.hpp b/bsnes/sfc/controller/superscope/superscope.hpp similarity index 100% rename from bsnes/snes/controller/superscope/superscope.hpp rename to bsnes/sfc/controller/superscope/superscope.hpp diff --git a/bsnes/snes/controller/usart/usart.cpp b/bsnes/sfc/controller/usart/usart.cpp similarity index 100% rename from bsnes/snes/controller/usart/usart.cpp rename to bsnes/sfc/controller/usart/usart.cpp diff --git a/bsnes/snes/controller/usart/usart.hpp b/bsnes/sfc/controller/usart/usart.hpp similarity index 100% rename from bsnes/snes/controller/usart/usart.hpp rename to bsnes/sfc/controller/usart/usart.hpp diff --git a/bsnes/snes/cpu/cpu.cpp b/bsnes/sfc/cpu/cpu.cpp similarity index 99% rename from bsnes/snes/cpu/cpu.cpp rename to bsnes/sfc/cpu/cpu.cpp index b7d23fd8..d9c602d7 100755 --- a/bsnes/snes/cpu/cpu.cpp +++ b/bsnes/sfc/cpu/cpu.cpp @@ -1,4 +1,4 @@ -#include +#include #define CPU_CPP namespace SuperFamicom { diff --git a/bsnes/snes/cpu/cpu.hpp b/bsnes/sfc/cpu/cpu.hpp similarity index 97% rename from bsnes/snes/cpu/cpu.hpp rename to bsnes/sfc/cpu/cpu.hpp index 268760fb..6b4b6b16 100755 --- a/bsnes/snes/cpu/cpu.hpp +++ b/bsnes/sfc/cpu/cpu.hpp @@ -1,4 +1,4 @@ -struct CPU : Thread, public CPUcore, public PPUcounter { +struct CPU : Processor::R65816, Thread, public PPUcounter { uint8 wram[128 * 1024]; enum : bool { Threaded = true }; diff --git a/bsnes/snes/cpu/dma/dma.cpp b/bsnes/sfc/cpu/dma/dma.cpp similarity index 100% rename from bsnes/snes/cpu/dma/dma.cpp rename to bsnes/sfc/cpu/dma/dma.cpp diff --git a/bsnes/snes/cpu/dma/dma.hpp b/bsnes/sfc/cpu/dma/dma.hpp similarity index 100% rename from bsnes/snes/cpu/dma/dma.hpp rename to bsnes/sfc/cpu/dma/dma.hpp diff --git a/bsnes/snes/cpu/memory/memory.cpp b/bsnes/sfc/cpu/memory/memory.cpp similarity index 92% rename from bsnes/snes/cpu/memory/memory.cpp rename to bsnes/sfc/cpu/memory/memory.cpp index 7e5c0c69..f47d3205 100755 --- a/bsnes/snes/cpu/memory/memory.cpp +++ b/bsnes/sfc/cpu/memory/memory.cpp @@ -42,4 +42,8 @@ unsigned CPU::speed(unsigned addr) const { return 12; } +uint8 CPU::disassembler_read(uint32 addr) { + return bus.read(addr); +} + #endif diff --git a/bsnes/snes/cpu/memory/memory.hpp b/bsnes/sfc/cpu/memory/memory.hpp similarity index 77% rename from bsnes/snes/cpu/memory/memory.hpp rename to bsnes/sfc/cpu/memory/memory.hpp index c7329690..aacd2c5a 100755 --- a/bsnes/snes/cpu/memory/memory.hpp +++ b/bsnes/sfc/cpu/memory/memory.hpp @@ -2,3 +2,5 @@ void op_io(); uint8 op_read(uint32 addr); void op_write(uint32 addr, uint8 data); alwaysinline unsigned speed(unsigned addr) const; + +uint8 disassembler_read(uint32 addr); diff --git a/bsnes/snes/cpu/mmio/mmio.cpp b/bsnes/sfc/cpu/mmio/mmio.cpp similarity index 100% rename from bsnes/snes/cpu/mmio/mmio.cpp rename to bsnes/sfc/cpu/mmio/mmio.cpp diff --git a/bsnes/snes/cpu/mmio/mmio.hpp b/bsnes/sfc/cpu/mmio/mmio.hpp similarity index 100% rename from bsnes/snes/cpu/mmio/mmio.hpp rename to bsnes/sfc/cpu/mmio/mmio.hpp diff --git a/bsnes/snes/cpu/serialization.cpp b/bsnes/sfc/cpu/serialization.cpp similarity index 98% rename from bsnes/snes/cpu/serialization.cpp rename to bsnes/sfc/cpu/serialization.cpp index 464d122d..8d8fc253 100755 --- a/bsnes/snes/cpu/serialization.cpp +++ b/bsnes/sfc/cpu/serialization.cpp @@ -1,8 +1,8 @@ #ifdef CPU_CPP void CPU::serialize(serializer &s) { + R65816::serialize(s); Thread::serialize(s); - CPUcore::core_serialize(s); PPUcounter::serialize(s); s.array(wram); diff --git a/bsnes/snes/cpu/timing/irq.cpp b/bsnes/sfc/cpu/timing/irq.cpp similarity index 100% rename from bsnes/snes/cpu/timing/irq.cpp rename to bsnes/sfc/cpu/timing/irq.cpp diff --git a/bsnes/snes/cpu/timing/joypad.cpp b/bsnes/sfc/cpu/timing/joypad.cpp similarity index 100% rename from bsnes/snes/cpu/timing/joypad.cpp rename to bsnes/sfc/cpu/timing/joypad.cpp diff --git a/bsnes/snes/cpu/timing/timing.cpp b/bsnes/sfc/cpu/timing/timing.cpp similarity index 100% rename from bsnes/snes/cpu/timing/timing.cpp rename to bsnes/sfc/cpu/timing/timing.cpp diff --git a/bsnes/snes/cpu/timing/timing.hpp b/bsnes/sfc/cpu/timing/timing.hpp similarity index 100% rename from bsnes/snes/cpu/timing/timing.hpp rename to bsnes/sfc/cpu/timing/timing.hpp diff --git a/bsnes/snes/dsp/brr.cpp b/bsnes/sfc/dsp/brr.cpp similarity index 100% rename from bsnes/snes/dsp/brr.cpp rename to bsnes/sfc/dsp/brr.cpp diff --git a/bsnes/snes/dsp/counter.cpp b/bsnes/sfc/dsp/counter.cpp similarity index 100% rename from bsnes/snes/dsp/counter.cpp rename to bsnes/sfc/dsp/counter.cpp diff --git a/bsnes/snes/dsp/dsp.cpp b/bsnes/sfc/dsp/dsp.cpp similarity index 99% rename from bsnes/snes/dsp/dsp.cpp rename to bsnes/sfc/dsp/dsp.cpp index 21e93885..088fce59 100755 --- a/bsnes/snes/dsp/dsp.cpp +++ b/bsnes/sfc/dsp/dsp.cpp @@ -1,4 +1,4 @@ -#include +#include #define DSP_CPP namespace SuperFamicom { diff --git a/bsnes/snes/dsp/dsp.hpp b/bsnes/sfc/dsp/dsp.hpp similarity index 100% rename from bsnes/snes/dsp/dsp.hpp rename to bsnes/sfc/dsp/dsp.hpp diff --git a/bsnes/snes/dsp/echo.cpp b/bsnes/sfc/dsp/echo.cpp similarity index 100% rename from bsnes/snes/dsp/echo.cpp rename to bsnes/sfc/dsp/echo.cpp diff --git a/bsnes/snes/dsp/envelope.cpp b/bsnes/sfc/dsp/envelope.cpp similarity index 100% rename from bsnes/snes/dsp/envelope.cpp rename to bsnes/sfc/dsp/envelope.cpp diff --git a/bsnes/snes/dsp/gaussian.cpp b/bsnes/sfc/dsp/gaussian.cpp similarity index 100% rename from bsnes/snes/dsp/gaussian.cpp rename to bsnes/sfc/dsp/gaussian.cpp diff --git a/bsnes/snes/dsp/misc.cpp b/bsnes/sfc/dsp/misc.cpp similarity index 100% rename from bsnes/snes/dsp/misc.cpp rename to bsnes/sfc/dsp/misc.cpp diff --git a/bsnes/snes/dsp/moduloarray.hpp b/bsnes/sfc/dsp/moduloarray.hpp similarity index 100% rename from bsnes/snes/dsp/moduloarray.hpp rename to bsnes/sfc/dsp/moduloarray.hpp diff --git a/bsnes/snes/dsp/serialization.cpp b/bsnes/sfc/dsp/serialization.cpp similarity index 100% rename from bsnes/snes/dsp/serialization.cpp rename to bsnes/sfc/dsp/serialization.cpp diff --git a/bsnes/snes/dsp/voice.cpp b/bsnes/sfc/dsp/voice.cpp similarity index 100% rename from bsnes/snes/dsp/voice.cpp rename to bsnes/sfc/dsp/voice.cpp diff --git a/bsnes/snes/interface/interface.cpp b/bsnes/sfc/interface/interface.cpp similarity index 95% rename from bsnes/snes/interface/interface.cpp rename to bsnes/sfc/interface/interface.cpp index e36765e4..586d28b6 100755 --- a/bsnes/snes/interface/interface.cpp +++ b/bsnes/sfc/interface/interface.cpp @@ -1,4 +1,4 @@ -#include +#include namespace SuperFamicom { diff --git a/bsnes/snes/interface/interface.hpp b/bsnes/sfc/interface/interface.hpp similarity index 100% rename from bsnes/snes/interface/interface.hpp rename to bsnes/sfc/interface/interface.hpp diff --git a/bsnes/snes/memory/memory-inline.hpp b/bsnes/sfc/memory/memory-inline.hpp similarity index 80% rename from bsnes/snes/memory/memory-inline.hpp rename to bsnes/sfc/memory/memory-inline.hpp index 70503bea..cf9e726b 100755 --- a/bsnes/snes/memory/memory-inline.hpp +++ b/bsnes/sfc/memory/memory-inline.hpp @@ -20,7 +20,7 @@ StaticRAM::~StaticRAM() { delete[] data_; } void MappedRAM::reset() { if(data_) { delete[] data_; - data_ = 0; + data_ = nullptr; } size_ = 0; write_protect_ = false; @@ -32,12 +32,12 @@ void MappedRAM::map(uint8 *source, unsigned length) { size_ = data_ ? length : 0; } -void MappedRAM::copy(const uint8 *data, unsigned size) { - if(!data_) { - size_ = (size & ~255) + ((bool)(size & 255) << 8); - data_ = new uint8[size_](); - } - memcpy(data_, data, min(size_, size)); +void MappedRAM::copy(const stream &memory) { + if(data_) delete[] data_; + //round size up to multiple of 256-bytes + size_ = (memory.size() & ~255) + ((bool)(memory.size() & 255) << 8); + data_ = new uint8[size_](); + memory.read(data_, memory.size()); } void MappedRAM::write_protect(bool status) { write_protect_ = status; } @@ -47,7 +47,7 @@ unsigned MappedRAM::size() const { return size_; } uint8 MappedRAM::read(unsigned addr) { return data_[addr]; } void MappedRAM::write(unsigned addr, uint8 n) { if(!write_protect_) data_[addr] = n; } const uint8& MappedRAM::operator[](unsigned addr) const { return data_[addr]; } -MappedRAM::MappedRAM() : data_(0), size_(0), write_protect_(false) {} +MappedRAM::MappedRAM() : data_(nullptr), size_(0), write_protect_(false) {} //Bus diff --git a/bsnes/snes/memory/memory.cpp b/bsnes/sfc/memory/memory.cpp similarity index 98% rename from bsnes/snes/memory/memory.cpp rename to bsnes/sfc/memory/memory.cpp index 510f7a2b..ae2a4bf9 100755 --- a/bsnes/snes/memory/memory.cpp +++ b/bsnes/sfc/memory/memory.cpp @@ -1,4 +1,4 @@ -#include +#include #define MEMORY_CPP namespace SuperFamicom { diff --git a/bsnes/snes/memory/memory.hpp b/bsnes/sfc/memory/memory.hpp similarity index 97% rename from bsnes/snes/memory/memory.hpp rename to bsnes/sfc/memory/memory.hpp index 634e0717..237e9498 100755 --- a/bsnes/snes/memory/memory.hpp +++ b/bsnes/sfc/memory/memory.hpp @@ -24,7 +24,7 @@ private: struct MappedRAM : Memory { inline void reset(); inline void map(uint8*, unsigned); - inline void copy(const uint8*, unsigned); + inline void copy(const stream &memory); inline void write_protect(bool status); inline uint8* data(); diff --git a/bsnes/snes/ppu/background/background.cpp b/bsnes/sfc/ppu/background/background.cpp similarity index 100% rename from bsnes/snes/ppu/background/background.cpp rename to bsnes/sfc/ppu/background/background.cpp diff --git a/bsnes/snes/ppu/background/background.hpp b/bsnes/sfc/ppu/background/background.hpp similarity index 100% rename from bsnes/snes/ppu/background/background.hpp rename to bsnes/sfc/ppu/background/background.hpp diff --git a/bsnes/snes/ppu/background/mode7.cpp b/bsnes/sfc/ppu/background/mode7.cpp similarity index 100% rename from bsnes/snes/ppu/background/mode7.cpp rename to bsnes/sfc/ppu/background/mode7.cpp diff --git a/bsnes/snes/ppu/counter/counter-inline.hpp b/bsnes/sfc/ppu/counter/counter-inline.hpp similarity index 100% rename from bsnes/snes/ppu/counter/counter-inline.hpp rename to bsnes/sfc/ppu/counter/counter-inline.hpp diff --git a/bsnes/snes/ppu/counter/counter.hpp b/bsnes/sfc/ppu/counter/counter.hpp similarity index 100% rename from bsnes/snes/ppu/counter/counter.hpp rename to bsnes/sfc/ppu/counter/counter.hpp diff --git a/bsnes/snes/ppu/mmio/mmio.cpp b/bsnes/sfc/ppu/mmio/mmio.cpp similarity index 100% rename from bsnes/snes/ppu/mmio/mmio.cpp rename to bsnes/sfc/ppu/mmio/mmio.cpp diff --git a/bsnes/snes/ppu/mmio/mmio.hpp b/bsnes/sfc/ppu/mmio/mmio.hpp similarity index 100% rename from bsnes/snes/ppu/mmio/mmio.hpp rename to bsnes/sfc/ppu/mmio/mmio.hpp diff --git a/bsnes/snes/ppu/ppu.cpp b/bsnes/sfc/ppu/ppu.cpp similarity index 99% rename from bsnes/snes/ppu/ppu.cpp rename to bsnes/sfc/ppu/ppu.cpp index 51dc3d4c..4770c311 100755 --- a/bsnes/snes/ppu/ppu.cpp +++ b/bsnes/sfc/ppu/ppu.cpp @@ -1,4 +1,4 @@ -#include +#include #define PPU_CPP namespace SuperFamicom { diff --git a/bsnes/snes/ppu/ppu.hpp b/bsnes/sfc/ppu/ppu.hpp similarity index 100% rename from bsnes/snes/ppu/ppu.hpp rename to bsnes/sfc/ppu/ppu.hpp diff --git a/bsnes/snes/ppu/screen/screen.cpp b/bsnes/sfc/ppu/screen/screen.cpp similarity index 100% rename from bsnes/snes/ppu/screen/screen.cpp rename to bsnes/sfc/ppu/screen/screen.cpp diff --git a/bsnes/snes/ppu/screen/screen.hpp b/bsnes/sfc/ppu/screen/screen.hpp similarity index 100% rename from bsnes/snes/ppu/screen/screen.hpp rename to bsnes/sfc/ppu/screen/screen.hpp diff --git a/bsnes/snes/ppu/serialization.cpp b/bsnes/sfc/ppu/serialization.cpp similarity index 100% rename from bsnes/snes/ppu/serialization.cpp rename to bsnes/sfc/ppu/serialization.cpp diff --git a/bsnes/snes/ppu/sprite/list.cpp b/bsnes/sfc/ppu/sprite/list.cpp similarity index 100% rename from bsnes/snes/ppu/sprite/list.cpp rename to bsnes/sfc/ppu/sprite/list.cpp diff --git a/bsnes/snes/ppu/sprite/sprite.cpp b/bsnes/sfc/ppu/sprite/sprite.cpp similarity index 100% rename from bsnes/snes/ppu/sprite/sprite.cpp rename to bsnes/sfc/ppu/sprite/sprite.cpp diff --git a/bsnes/snes/ppu/sprite/sprite.hpp b/bsnes/sfc/ppu/sprite/sprite.hpp similarity index 100% rename from bsnes/snes/ppu/sprite/sprite.hpp rename to bsnes/sfc/ppu/sprite/sprite.hpp diff --git a/bsnes/snes/ppu/window/window.cpp b/bsnes/sfc/ppu/window/window.cpp similarity index 100% rename from bsnes/snes/ppu/window/window.cpp rename to bsnes/sfc/ppu/window/window.cpp diff --git a/bsnes/snes/ppu/window/window.hpp b/bsnes/sfc/ppu/window/window.hpp similarity index 100% rename from bsnes/snes/ppu/window/window.hpp rename to bsnes/sfc/ppu/window/window.hpp diff --git a/bsnes/sfc/profile-accuracy.hpp b/bsnes/sfc/profile-accuracy.hpp new file mode 100755 index 00000000..e336c9e3 --- /dev/null +++ b/bsnes/sfc/profile-accuracy.hpp @@ -0,0 +1,8 @@ +namespace Info { + static const char Profile[] = "Accuracy"; +} + +#include +#include +#include +#include diff --git a/bsnes/sfc/profile-compatibility.hpp b/bsnes/sfc/profile-compatibility.hpp new file mode 100755 index 00000000..6eedd4ed --- /dev/null +++ b/bsnes/sfc/profile-compatibility.hpp @@ -0,0 +1,8 @@ +namespace Info { + static const char Profile[] = "Compatibility"; +} + +#include +#include +#include +#include diff --git a/bsnes/snes/profile-performance.hpp b/bsnes/sfc/profile-performance.hpp similarity index 53% rename from bsnes/snes/profile-performance.hpp rename to bsnes/sfc/profile-performance.hpp index 1d379fdc..658bcd46 100755 --- a/bsnes/snes/profile-performance.hpp +++ b/bsnes/sfc/profile-performance.hpp @@ -6,7 +6,7 @@ namespace Info { #error "bsnes: debugger not supported with performance profile." #endif -#include -#include -#include -#include +#include +#include +#include +#include diff --git a/bsnes/snes/random/random.cpp b/bsnes/sfc/random/random.cpp similarity index 100% rename from bsnes/snes/random/random.cpp rename to bsnes/sfc/random/random.cpp diff --git a/bsnes/snes/random/random.hpp b/bsnes/sfc/random/random.hpp similarity index 100% rename from bsnes/snes/random/random.hpp rename to bsnes/sfc/random/random.hpp diff --git a/bsnes/snes/scheduler/scheduler.cpp b/bsnes/sfc/scheduler/scheduler.cpp similarity index 100% rename from bsnes/snes/scheduler/scheduler.cpp rename to bsnes/sfc/scheduler/scheduler.cpp diff --git a/bsnes/snes/scheduler/scheduler.hpp b/bsnes/sfc/scheduler/scheduler.hpp similarity index 100% rename from bsnes/snes/scheduler/scheduler.hpp rename to bsnes/sfc/scheduler/scheduler.hpp diff --git a/bsnes/snes/snes.hpp b/bsnes/sfc/sfc.hpp similarity index 67% rename from bsnes/snes/snes.hpp rename to bsnes/sfc/sfc.hpp index cbba2450..4fba9e7b 100755 --- a/bsnes/snes/snes.hpp +++ b/bsnes/sfc/sfc.hpp @@ -1,15 +1,18 @@ -#ifndef SNES_HPP -#define SNES_HPP +#ifndef SFC_HPP +#define SFC_HPP #include #include +#include #include +#include +#include #include namespace SuperFamicom { namespace Info { static const char Name[] = "bsnes"; - static const unsigned SerializerVersion = 24; + static const unsigned SerializerVersion = 25; } } @@ -52,10 +55,8 @@ namespace SuperFamicom { } }; - #include - #include - #include - #include + #include + #include #if defined(PROFILE_ACCURACY) #include "profile-accuracy.hpp" @@ -65,15 +66,15 @@ namespace SuperFamicom { #include "profile-performance.hpp" #endif - #include - #include - #include - #include - #include - #include + #include + #include + #include + #include + #include + #include - #include - #include + #include + #include } #endif diff --git a/bsnes/snes/smp/memory/memory.cpp b/bsnes/sfc/smp/memory.cpp similarity index 95% rename from bsnes/snes/smp/memory/memory.cpp rename to bsnes/sfc/smp/memory.cpp index ecbab1be..5827809f 100755 --- a/bsnes/snes/smp/memory/memory.cpp +++ b/bsnes/sfc/smp/memory.cpp @@ -198,4 +198,10 @@ void SMP::op_write(uint16 addr, uint8 data) { cycle_edge(); } +uint8 SMP::disassembler_read(uint16 addr) { + if((addr & 0xfff0) == 0x00f0) return 0x00; + if((addr & 0xffc0) == 0xffc0 && status.iplrom_enable) return iplrom[addr & 0x3f]; + return apuram[addr]; +} + #endif diff --git a/bsnes/snes/smp/serialization.cpp b/bsnes/sfc/smp/serialization.cpp similarity index 97% rename from bsnes/snes/smp/serialization.cpp rename to bsnes/sfc/smp/serialization.cpp index aab528b4..339df26d 100755 --- a/bsnes/snes/smp/serialization.cpp +++ b/bsnes/sfc/smp/serialization.cpp @@ -1,8 +1,8 @@ #ifdef SMP_CPP void SMP::serialize(serializer &s) { + SPC700::serialize(s); Thread::serialize(s); - SMPcore::core_serialize(s); s.array(apuram); diff --git a/bsnes/snes/smp/smp.cpp b/bsnes/sfc/smp/smp.cpp similarity index 96% rename from bsnes/snes/smp/smp.cpp rename to bsnes/sfc/smp/smp.cpp index 15576604..84881245 100755 --- a/bsnes/snes/smp/smp.cpp +++ b/bsnes/sfc/smp/smp.cpp @@ -1,13 +1,13 @@ -#include +#include #define SMP_CPP namespace SuperFamicom { SMP smp; +#include "memory.cpp" +#include "timing.cpp" #include "serialization.cpp" -#include "memory/memory.cpp" -#include "timing/timing.cpp" void SMP::step(unsigned clocks) { clock += clocks * (uint64)cpu.frequency; diff --git a/bsnes/snes/smp/smp.hpp b/bsnes/sfc/smp/smp.hpp similarity index 56% rename from bsnes/snes/smp/smp.hpp rename to bsnes/sfc/smp/smp.hpp index e67d9ff7..f1299cda 100755 --- a/bsnes/snes/smp/smp.hpp +++ b/bsnes/sfc/smp/smp.hpp @@ -1,4 +1,4 @@ -struct SMP : Thread, public SMPcore { +struct SMP : Processor::SPC700, Thread { uint8 iplrom[64]; uint8 apuram[64 * 1024]; @@ -19,9 +19,6 @@ struct SMP : Thread, public SMPcore { ~SMP(); privileged: - #include "memory/memory.hpp" - #include "timing/timing.hpp" - struct { //timing unsigned clock_counter; @@ -56,6 +53,41 @@ privileged: hook op_read; hook op_write; } debugger; + + //memory.cpp + uint8 ram_read(uint16 addr); + void ram_write(uint16 addr, uint8 data); + + uint8 op_busread(uint16 addr); + void op_buswrite(uint16 addr, uint8 data); + + void op_io(); + uint8 op_read(uint16 addr); + void op_write(uint16 addr, uint8 data); + + uint8 disassembler_read(uint16 addr); + + //timing.cpp + template + struct Timer { + uint8 stage0_ticks; + uint8 stage1_ticks; + uint8 stage2_ticks; + uint4 stage3_ticks; + bool current_line; + bool enable; + uint8 target; + + void tick(); + void synchronize_stage1(); + }; + + Timer<192> timer0; + Timer<192> timer1; + Timer< 24> timer2; + + alwaysinline void add_clocks(unsigned clocks); + alwaysinline void cycle_edge(); }; extern SMP smp; diff --git a/bsnes/snes/smp/timing/timing.cpp b/bsnes/sfc/smp/timing.cpp similarity index 100% rename from bsnes/snes/smp/timing/timing.cpp rename to bsnes/sfc/smp/timing.cpp diff --git a/bsnes/snes/system/audio.cpp b/bsnes/sfc/system/audio.cpp similarity index 100% rename from bsnes/snes/system/audio.cpp rename to bsnes/sfc/system/audio.cpp diff --git a/bsnes/snes/system/audio.hpp b/bsnes/sfc/system/audio.hpp similarity index 100% rename from bsnes/snes/system/audio.hpp rename to bsnes/sfc/system/audio.hpp diff --git a/bsnes/snes/system/input.cpp b/bsnes/sfc/system/input.cpp similarity index 100% rename from bsnes/snes/system/input.cpp rename to bsnes/sfc/system/input.cpp diff --git a/bsnes/snes/system/input.hpp b/bsnes/sfc/system/input.hpp similarity index 100% rename from bsnes/snes/system/input.hpp rename to bsnes/sfc/system/input.hpp diff --git a/bsnes/snes/system/serialization.cpp b/bsnes/sfc/system/serialization.cpp similarity index 86% rename from bsnes/snes/system/serialization.cpp rename to bsnes/sfc/system/serialization.cpp index f746c3a8..3ac7b883 100755 --- a/bsnes/snes/system/serialization.cpp +++ b/bsnes/sfc/system/serialization.cpp @@ -3,15 +3,16 @@ serializer System::serialize() { serializer s(serialize_size); - unsigned signature = 0x31545342, version = Info::SerializerVersion, crc32 = cartridge.crc32(); - char description[512], profile[16]; + unsigned signature = 0x31545342, version = Info::SerializerVersion; + char hash[64], description[512], profile[16]; + memcpy(&hash, (const char*)cartridge.sha256(), 64); memset(&description, 0, sizeof description); memset(&profile, 0, sizeof profile); strmcpy(profile, Info::Profile, sizeof profile); s.integer(signature); s.integer(version); - s.integer(crc32); + s.array(hash); s.array(description); s.array(profile); @@ -20,18 +21,17 @@ serializer System::serialize() { } bool System::unserialize(serializer &s) { - unsigned signature, version, crc32; - char description[512], profile[16]; + unsigned signature, version; + char hash[64], description[512], profile[16]; s.integer(signature); s.integer(version); - s.integer(crc32); + s.array(hash); s.array(description); s.array(profile); if(signature != 0x31545342) return false; if(version != Info::SerializerVersion) return false; -//if(crc32 != cartridge.crc32()) return false; if(strcmp(profile, Info::Profile)) return false; power(); @@ -79,12 +79,12 @@ void System::serialize_all(serializer &s) { void System::serialize_init() { serializer s; - unsigned signature = 0, version = 0, crc32 = 0; - char profile[16], description[512]; + unsigned signature = 0, version = 0; + char hash[64], profile[16], description[512]; s.integer(signature); s.integer(version); - s.integer(crc32); + s.array(hash); s.array(profile); s.array(description); diff --git a/bsnes/snes/system/system.cpp b/bsnes/sfc/system/system.cpp similarity index 98% rename from bsnes/snes/system/system.cpp rename to bsnes/sfc/system/system.cpp index d97b3709..a8965690 100755 --- a/bsnes/snes/system/system.cpp +++ b/bsnes/sfc/system/system.cpp @@ -1,13 +1,13 @@ -#include +#include #define SYSTEM_CPP namespace SuperFamicom { System system; -#include -#include -#include +#include +#include +#include #include "video.cpp" #include "audio.cpp" diff --git a/bsnes/snes/system/system.hpp b/bsnes/sfc/system/system.hpp similarity index 90% rename from bsnes/snes/system/system.hpp rename to bsnes/sfc/system/system.hpp index 56eb37a1..3bb08aef 100755 --- a/bsnes/snes/system/system.hpp +++ b/bsnes/sfc/system/system.hpp @@ -46,8 +46,8 @@ private: #include "audio.hpp" #include "input.hpp" -#include -#include -#include +#include +#include +#include extern System system; diff --git a/bsnes/snes/system/video.cpp b/bsnes/sfc/system/video.cpp similarity index 100% rename from bsnes/snes/system/video.cpp rename to bsnes/sfc/system/video.cpp diff --git a/bsnes/snes/system/video.hpp b/bsnes/sfc/system/video.hpp similarity index 100% rename from bsnes/snes/system/video.hpp rename to bsnes/sfc/system/video.hpp diff --git a/bsnes/snes/Makefile b/bsnes/snes/Makefile deleted file mode 100755 index 7d19c4a9..00000000 --- a/bsnes/snes/Makefile +++ /dev/null @@ -1,59 +0,0 @@ -snes_objects := snes-interface snes-system snes-controller -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-icd2 snes-nss snes-superfx snes-sa1 -snes_objects += snes-necdsp snes-hitachidsp snes-armdsp -snes_objects += snes-bsx snes-srtc snes-sdd1 snes-spc7110 -snes_objects += snes-obc1 snes-sufamiturbo -snes_objects += snes-msu1 snes-link -objects += $(snes_objects) - -ifeq ($(profile),accuracy) - flags += -DPROFILE_ACCURACY - snescpu := $(snes)/cpu - snessmp := $(snes)/smp - snesdsp := $(snes)/dsp - snesppu := $(snes)/ppu -else ifeq ($(profile),compatibility) - flags += -DPROFILE_COMPATIBILITY - snescpu := $(snes)/cpu - snessmp := $(snes)/smp - snesdsp := $(snes)/alt/dsp - snesppu := $(snes)/alt/ppu-compatibility -else ifeq ($(profile),performance) - flags += -DPROFILE_PERFORMANCE - snescpu := $(snes)/alt/cpu - snessmp := $(snes)/alt/smp - snesdsp := $(snes)/alt/dsp - snesppu := $(snes)/alt/ppu-performance -endif - -obj/snes-interface.o : $(snes)/interface/interface.cpp $(call rwildcard,$(snes)/interface) -obj/snes-system.o : $(snes)/system/system.cpp $(call rwildcard,$(snes)/system/) -obj/snes-controller.o: $(snes)/controller/controller.cpp $(call rwildcard,$(snes)/controller/) -obj/snes-memory.o : $(snes)/memory/memory.cpp $(call rwildcard,$(snes)/memory/) -obj/snes-cpucore.o : $(snes)/cpu/core/core.cpp $(call rwildcard,$(snes)/cpu/core/) -obj/snes-smpcore.o : $(snes)/smp/core/core.cpp $(call rwildcard,$(snes)/smp/core/) -obj/snes-cpu.o : $(snescpu)/cpu.cpp $(call rwildcard,$(snescpu)/) -obj/snes-smp.o : $(snessmp)/smp.cpp $(call rwildcard,$(snessmp)/) -obj/snes-dsp.o : $(snesdsp)/dsp.cpp $(call rwildcard,$(snesdsp)/) -obj/snes-ppu.o : $(snesppu)/ppu.cpp $(call rwildcard,$(snesppu)/) -obj/snes-cartridge.o : $(snes)/cartridge/cartridge.cpp $(snes)/cartridge/* -obj/snes-cheat.o : $(snes)/cheat/cheat.cpp $(snes)/cheat/* - -obj/snes-nss.o : $(snes)/chip/nss/nss.cpp $(call rwildcard,$(snes)/chip/nss/) -obj/snes-icd2.o : $(snes)/chip/icd2/icd2.cpp $(call rwildcard,$(snes)/chip/icd2/) -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-armdsp.o : $(snes)/chip/armdsp/armdsp.cpp $(call rwildcard,$(snes)/chip/armdsp/) -obj/snes-bsx.o : $(snes)/chip/bsx/bsx.cpp $(call rwildcard,$(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-obc1.o : $(snes)/chip/obc1/obc1.cpp $(snes)/chip/obc1/* -obj/snes-sufamiturbo.o: $(snes)/chip/sufamiturbo/sufamiturbo.cpp $(snes)/chip/sufamiturbo/* -obj/snes-msu1.o : $(snes)/chip/msu1/msu1.cpp $(snes)/chip/msu1/* -obj/snes-link.o : $(snes)/chip/link/link.cpp $(snes)/chip/link/* diff --git a/bsnes/snes/chip/chip.hpp b/bsnes/snes/chip/chip.hpp deleted file mode 100755 index fbb82195..00000000 --- a/bsnes/snes/chip/chip.hpp +++ /dev/null @@ -1,31 +0,0 @@ -struct Coprocessor : Thread { - alwaysinline void step(unsigned clocks); - alwaysinline void synchronize_cpu(); -}; - -#if defined(GAMEBOY) - #include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -void Coprocessor::step(unsigned clocks) { - clock += clocks * (uint64)cpu.frequency; -} - -void Coprocessor::synchronize_cpu() { - if(clock >= 0 && scheduler.sync != Scheduler::SynchronizeMode::All) co_switch(cpu.thread); -} diff --git a/bsnes/snes/chip/superfx/core/core.hpp b/bsnes/snes/chip/superfx/core/core.hpp deleted file mode 100755 index 1c13f1ce..00000000 --- a/bsnes/snes/chip/superfx/core/core.hpp +++ /dev/null @@ -1,92 +0,0 @@ -#include "registers.hpp" - -uint8 color(uint8 source); -void plot(uint8 x, uint8 y); -uint8 rpix(uint8 x, uint8 y); -void pixelcache_flush(pixelcache_t &cache); - -void (SuperFX::*opcode_table[1024])(); -void initialize_opcode_table(); - -//opcodes.cpp -template void op_adc_i(); -template void op_adc_r(); -template void op_add_i(); -template void op_add_r(); -void op_alt1(); -void op_alt2(); -void op_alt3(); -template void op_and_i(); -template void op_and_r(); -void op_asr(); -void op_bge(); -void op_bcc(); -void op_bcs(); -void op_beq(); -template void op_bic_i(); -template void op_bic_r(); -void op_blt(); -void op_bmi(); -void op_bne(); -void op_bpl(); -void op_bra(); -void op_bvc(); -void op_bvs(); -void op_cache(); -void op_cmode(); -template void op_cmp_r(); -void op_color(); -template void op_dec_r(); -void op_div2(); -void op_fmult(); -template void op_from_r(); -void op_getb(); -void op_getbl(); -void op_getbh(); -void op_getbs(); -void op_getc(); -void op_hib(); -template void op_ibt_r(); -template void op_inc_r(); -template void op_iwt_r(); -template void op_jmp_r(); -template void op_ldb_ir(); -template void op_ldw_ir(); -template void op_link(); -template void op_ljmp_r(); -template void op_lm_r(); -template void op_lms_r(); -void op_lmult(); -void op_lob(); -void op_loop(); -void op_lsr(); -void op_merge(); -template void op_mult_i(); -template void op_mult_r(); -void op_nop(); -void op_not(); -template void op_or_i(); -template void op_or_r(); -void op_plot(); -void op_ramb(); -void op_rol(); -void op_romb(); -void op_ror(); -void op_rpix(); -template void op_sbc_r(); -void op_sbk(); -void op_sex(); -template void op_sm_r(); -template void op_sms_r(); -template void op_stb_ir(); -void op_stop(); -template void op_stw_ir(); -template void op_sub_i(); -template void op_sub_r(); -void op_swap(); -template void op_to_r(); -template void op_umult_i(); -template void op_umult_r(); -template void op_with_r(); -template void op_xor_i(); -template void op_xor_r(); diff --git a/bsnes/snes/profile-accuracy.hpp b/bsnes/snes/profile-accuracy.hpp deleted file mode 100755 index 7b6dded8..00000000 --- a/bsnes/snes/profile-accuracy.hpp +++ /dev/null @@ -1,8 +0,0 @@ -namespace Info { - static const char Profile[] = "Accuracy"; -} - -#include -#include -#include -#include diff --git a/bsnes/snes/profile-compatibility.hpp b/bsnes/snes/profile-compatibility.hpp deleted file mode 100755 index bbf3582d..00000000 --- a/bsnes/snes/profile-compatibility.hpp +++ /dev/null @@ -1,8 +0,0 @@ -namespace Info { - static const char Profile[] = "Compatibility"; -} - -#include -#include -#include -#include diff --git a/bsnes/snes/smp/core/core.cpp b/bsnes/snes/smp/core/core.cpp deleted file mode 100755 index 6c7825b8..00000000 --- a/bsnes/snes/smp/core/core.cpp +++ /dev/null @@ -1,272 +0,0 @@ -#include - -#define SMPCORE_CPP -namespace SuperFamicom { - -#include "algorithms.cpp" -#include "opcodes.cpp" -#include "disassembler.cpp" -#include "serialization.cpp" - -void SMPcore::op_step() { - switch(opcode = op_readpc()) { - case 0x00: return op_nop(); - case 0x01: return op_jst(); - case 0x02: return op_set_bit(); - case 0x03: return op_branch_bit(); - case 0x04: return op_read_dp<&SMPcore::op_or>(regs.a); - case 0x05: return op_read_addr<&SMPcore::op_or>(regs.a); - case 0x06: return op_read_ix<&SMPcore::op_or>(); - case 0x07: return op_read_idpx<&SMPcore::op_or>(); - case 0x08: return op_read_const<&SMPcore::op_or>(regs.a); - case 0x09: return op_write_dp_dp<&SMPcore::op_or>(); - case 0x0a: return op_set_addr_bit(); - case 0x0b: return op_adjust_dp<&SMPcore::op_asl>(); - case 0x0c: return op_adjust_addr<&SMPcore::op_asl>(); - case 0x0d: return op_push(regs.p); - case 0x0e: return op_test_addr(1); - case 0x0f: return op_brk(); - case 0x10: return op_branch(regs.p.n == 0); - case 0x11: return op_jst(); - case 0x12: return op_set_bit(); - case 0x13: return op_branch_bit(); - case 0x14: return op_read_dpi<&SMPcore::op_or>(regs.a, regs.x); - case 0x15: return op_read_addri<&SMPcore::op_or>(regs.x); - case 0x16: return op_read_addri<&SMPcore::op_or>(regs.y); - case 0x17: return op_read_idpy<&SMPcore::op_or>(); - case 0x18: return op_write_dp_const<&SMPcore::op_or>(); - case 0x19: return op_write_ix_iy<&SMPcore::op_or>(); - case 0x1a: return op_adjust_dpw(-1); - case 0x1b: return op_adjust_dpx<&SMPcore::op_asl>(); - case 0x1c: return op_adjust<&SMPcore::op_asl>(regs.a); - case 0x1d: return op_adjust<&SMPcore::op_dec>(regs.x); - case 0x1e: return op_read_addr<&SMPcore::op_cmp>(regs.x); - case 0x1f: return op_jmp_iaddrx(); - case 0x20: return op_set_flag(regs.p.p, 0); - case 0x21: return op_jst(); - case 0x22: return op_set_bit(); - case 0x23: return op_branch_bit(); - case 0x24: return op_read_dp<&SMPcore::op_and>(regs.a); - case 0x25: return op_read_addr<&SMPcore::op_and>(regs.a); - case 0x26: return op_read_ix<&SMPcore::op_and>(); - case 0x27: return op_read_idpx<&SMPcore::op_and>(); - case 0x28: return op_read_const<&SMPcore::op_and>(regs.a); - case 0x29: return op_write_dp_dp<&SMPcore::op_and>(); - case 0x2a: return op_set_addr_bit(); - case 0x2b: return op_adjust_dp<&SMPcore::op_rol>(); - case 0x2c: return op_adjust_addr<&SMPcore::op_rol>(); - case 0x2d: return op_push(regs.a); - case 0x2e: return op_bne_dp(); - case 0x2f: return op_branch(true); - case 0x30: return op_branch(regs.p.n == 1); - case 0x31: return op_jst(); - case 0x32: return op_set_bit(); - case 0x33: return op_branch_bit(); - case 0x34: return op_read_dpi<&SMPcore::op_and>(regs.a, regs.x); - case 0x35: return op_read_addri<&SMPcore::op_and>(regs.x); - case 0x36: return op_read_addri<&SMPcore::op_and>(regs.y); - case 0x37: return op_read_idpy<&SMPcore::op_and>(); - case 0x38: return op_write_dp_const<&SMPcore::op_and>(); - case 0x39: return op_write_ix_iy<&SMPcore::op_and>(); - case 0x3a: return op_adjust_dpw(+1); - case 0x3b: return op_adjust_dpx<&SMPcore::op_rol>(); - case 0x3c: return op_adjust<&SMPcore::op_rol>(regs.a); - case 0x3d: return op_adjust<&SMPcore::op_inc>(regs.x); - case 0x3e: return op_read_dp<&SMPcore::op_cmp>(regs.x); - case 0x3f: return op_jsr_addr(); - case 0x40: return op_set_flag(regs.p.p, 1); - case 0x41: return op_jst(); - case 0x42: return op_set_bit(); - case 0x43: return op_branch_bit(); - case 0x44: return op_read_dp<&SMPcore::op_eor>(regs.a); - case 0x45: return op_read_addr<&SMPcore::op_eor>(regs.a); - case 0x46: return op_read_ix<&SMPcore::op_eor>(); - case 0x47: return op_read_idpx<&SMPcore::op_eor>(); - case 0x48: return op_read_const<&SMPcore::op_eor>(regs.a); - case 0x49: return op_write_dp_dp<&SMPcore::op_eor>(); - case 0x4a: return op_set_addr_bit(); - case 0x4b: return op_adjust_dp<&SMPcore::op_lsr>(); - case 0x4c: return op_adjust_addr<&SMPcore::op_lsr>(); - case 0x4d: return op_push(regs.x); - case 0x4e: return op_test_addr(0); - case 0x4f: return op_jsp_dp(); - case 0x50: return op_branch(regs.p.v == 0); - case 0x51: return op_jst(); - case 0x52: return op_set_bit(); - case 0x53: return op_branch_bit(); - case 0x54: return op_read_dpi<&SMPcore::op_eor>(regs.a, regs.x); - case 0x55: return op_read_addri<&SMPcore::op_eor>(regs.x); - case 0x56: return op_read_addri<&SMPcore::op_eor>(regs.y); - case 0x57: return op_read_idpy<&SMPcore::op_eor>(); - case 0x58: return op_write_dp_const<&SMPcore::op_eor>(); - case 0x59: return op_write_ix_iy<&SMPcore::op_eor>(); - case 0x5a: return op_read_dpw<&SMPcore::op_cpw>(); - case 0x5b: return op_adjust_dpx<&SMPcore::op_lsr>(); - case 0x5c: return op_adjust<&SMPcore::op_lsr>(regs.a); - case 0x5d: return op_transfer(regs.a, regs.x); - case 0x5e: return op_read_addr<&SMPcore::op_cmp>(regs.y); - case 0x5f: return op_jmp_addr(); - case 0x60: return op_set_flag(regs.p.c, 0); - case 0x61: return op_jst(); - case 0x62: return op_set_bit(); - case 0x63: return op_branch_bit(); - case 0x64: return op_read_dp<&SMPcore::op_cmp>(regs.a); - case 0x65: return op_read_addr<&SMPcore::op_cmp>(regs.a); - case 0x66: return op_read_ix<&SMPcore::op_cmp>(); - case 0x67: return op_read_idpx<&SMPcore::op_cmp>(); - case 0x68: return op_read_const<&SMPcore::op_cmp>(regs.a); - case 0x69: return op_write_dp_dp<&SMPcore::op_cmp>(); - case 0x6a: return op_set_addr_bit(); - case 0x6b: return op_adjust_dp<&SMPcore::op_ror>(); - case 0x6c: return op_adjust_addr<&SMPcore::op_ror>(); - case 0x6d: return op_push(regs.y); - case 0x6e: return op_bne_dpdec(); - case 0x6f: return op_rts(); - case 0x70: return op_branch(regs.p.v == 1); - case 0x71: return op_jst(); - case 0x72: return op_set_bit(); - case 0x73: return op_branch_bit(); - case 0x74: return op_read_dpi<&SMPcore::op_cmp>(regs.a, regs.x); - case 0x75: return op_read_addri<&SMPcore::op_cmp>(regs.x); - case 0x76: return op_read_addri<&SMPcore::op_cmp>(regs.y); - case 0x77: return op_read_idpy<&SMPcore::op_cmp>(); - case 0x78: return op_write_dp_const<&SMPcore::op_cmp>(); - case 0x79: return op_write_ix_iy<&SMPcore::op_cmp>(); - case 0x7a: return op_read_dpw<&SMPcore::op_adw>(); - case 0x7b: return op_adjust_dpx<&SMPcore::op_ror>(); - case 0x7c: return op_adjust<&SMPcore::op_ror>(regs.a); - case 0x7d: return op_transfer(regs.x, regs.a); - case 0x7e: return op_read_dp<&SMPcore::op_cmp>(regs.y); - case 0x7f: return op_rti(); - case 0x80: return op_set_flag(regs.p.c, 1); - case 0x81: return op_jst(); - case 0x82: return op_set_bit(); - case 0x83: return op_branch_bit(); - case 0x84: return op_read_dp<&SMPcore::op_adc>(regs.a); - case 0x85: return op_read_addr<&SMPcore::op_adc>(regs.a); - case 0x86: return op_read_ix<&SMPcore::op_adc>(); - case 0x87: return op_read_idpx<&SMPcore::op_adc>(); - case 0x88: return op_read_const<&SMPcore::op_adc>(regs.a); - case 0x89: return op_write_dp_dp<&SMPcore::op_adc>(); - case 0x8a: return op_set_addr_bit(); - case 0x8b: return op_adjust_dp<&SMPcore::op_dec>(); - case 0x8c: return op_adjust_addr<&SMPcore::op_dec>(); - case 0x8d: return op_read_const<&SMPcore::op_ld>(regs.y); - case 0x8e: return op_plp(); - case 0x8f: return op_write_dp_const<&SMPcore::op_st>(); - case 0x90: return op_branch(regs.p.c == 0); - case 0x91: return op_jst(); - case 0x92: return op_set_bit(); - case 0x93: return op_branch_bit(); - case 0x94: return op_read_dpi<&SMPcore::op_adc>(regs.a, regs.x); - case 0x95: return op_read_addri<&SMPcore::op_adc>(regs.x); - case 0x96: return op_read_addri<&SMPcore::op_adc>(regs.y); - case 0x97: return op_read_idpy<&SMPcore::op_adc>(); - case 0x98: return op_write_dp_const<&SMPcore::op_adc>(); - case 0x99: return op_write_ix_iy<&SMPcore::op_adc>(); - case 0x9a: return op_read_dpw<&SMPcore::op_sbw>(); - case 0x9b: return op_adjust_dpx<&SMPcore::op_dec>(); - case 0x9c: return op_adjust<&SMPcore::op_dec>(regs.a); - case 0x9d: return op_transfer(regs.s, regs.x); - case 0x9e: return op_div_ya_x(); - case 0x9f: return op_xcn(); - case 0xa0: return op_set_flag(regs.p.i, 1); - case 0xa1: return op_jst(); - case 0xa2: return op_set_bit(); - case 0xa3: return op_branch_bit(); - case 0xa4: return op_read_dp<&SMPcore::op_sbc>(regs.a); - case 0xa5: return op_read_addr<&SMPcore::op_sbc>(regs.a); - case 0xa6: return op_read_ix<&SMPcore::op_sbc>(); - case 0xa7: return op_read_idpx<&SMPcore::op_sbc>(); - case 0xa8: return op_read_const<&SMPcore::op_sbc>(regs.a); - case 0xa9: return op_write_dp_dp<&SMPcore::op_sbc>(); - case 0xaa: return op_set_addr_bit(); - case 0xab: return op_adjust_dp<&SMPcore::op_inc>(); - case 0xac: return op_adjust_addr<&SMPcore::op_inc>(); - case 0xad: return op_read_const<&SMPcore::op_cmp>(regs.y); - case 0xae: return op_pull(regs.a); - case 0xaf: return op_sta_ixinc(); - case 0xb0: return op_branch(regs.p.c == 1); - case 0xb1: return op_jst(); - case 0xb2: return op_set_bit(); - case 0xb3: return op_branch_bit(); - case 0xb4: return op_read_dpi<&SMPcore::op_sbc>(regs.a, regs.x); - case 0xb5: return op_read_addri<&SMPcore::op_sbc>(regs.x); - case 0xb6: return op_read_addri<&SMPcore::op_sbc>(regs.y); - case 0xb7: return op_read_idpy<&SMPcore::op_sbc>(); - case 0xb8: return op_write_dp_const<&SMPcore::op_sbc>(); - case 0xb9: return op_write_ix_iy<&SMPcore::op_sbc>(); - case 0xba: return op_read_dpw<&SMPcore::op_ldw>(); - case 0xbb: return op_adjust_dpx<&SMPcore::op_inc>(); - case 0xbc: return op_adjust<&SMPcore::op_inc>(regs.a); - case 0xbd: return op_transfer(regs.x, regs.s); - case 0xbe: return op_das(); - case 0xbf: return op_lda_ixinc(); - case 0xc0: return op_set_flag(regs.p.i, 0); - case 0xc1: return op_jst(); - case 0xc2: return op_set_bit(); - case 0xc3: return op_branch_bit(); - case 0xc4: return op_write_dp(regs.a); - case 0xc5: return op_write_addr(regs.a); - case 0xc6: return op_sta_ix(); - case 0xc7: return op_sta_idpx(); - case 0xc8: return op_read_const<&SMPcore::op_cmp>(regs.x); - case 0xc9: return op_write_addr(regs.x); - case 0xca: return op_set_addr_bit(); - case 0xcb: return op_write_dp(regs.y); - case 0xcc: return op_write_addr(regs.y); - case 0xcd: return op_read_const<&SMPcore::op_ld>(regs.x); - case 0xce: return op_pull(regs.x); - case 0xcf: return op_mul_ya(); - case 0xd0: return op_branch(regs.p.z == 0); - case 0xd1: return op_jst(); - case 0xd2: return op_set_bit(); - case 0xd3: return op_branch_bit(); - case 0xd4: return op_write_dpi(regs.a, regs.x); - case 0xd5: return op_write_addri(regs.x); - case 0xd6: return op_write_addri(regs.y); - case 0xd7: return op_sta_idpy(); - case 0xd8: return op_write_dp(regs.x); - case 0xd9: return op_write_dpi(regs.x, regs.y); - case 0xda: return op_stw_dp(); - case 0xdb: return op_write_dpi(regs.y, regs.x); - case 0xdc: return op_adjust<&SMPcore::op_dec>(regs.y); - case 0xdd: return op_transfer(regs.y, regs.a); - case 0xde: return op_bne_dpx(); - case 0xdf: return op_daa(); - case 0xe0: return op_clv(); - case 0xe1: return op_jst(); - case 0xe2: return op_set_bit(); - case 0xe3: return op_branch_bit(); - case 0xe4: return op_read_dp<&SMPcore::op_ld>(regs.a); - case 0xe5: return op_read_addr<&SMPcore::op_ld>(regs.a); - case 0xe6: return op_read_ix<&SMPcore::op_ld>(); - case 0xe7: return op_read_idpx<&SMPcore::op_ld>(); - case 0xe8: return op_read_const<&SMPcore::op_ld>(regs.a); - case 0xe9: return op_read_addr<&SMPcore::op_ld>(regs.x); - case 0xea: return op_set_addr_bit(); - case 0xeb: return op_read_dp<&SMPcore::op_ld>(regs.y); - case 0xec: return op_read_addr<&SMPcore::op_ld>(regs.y); - case 0xed: return op_cmc(); - case 0xee: return op_pull(regs.y); - case 0xef: return op_wait(); - case 0xf0: return op_branch(regs.p.z == 1); - case 0xf1: return op_jst(); - case 0xf2: return op_set_bit(); - case 0xf3: return op_branch_bit(); - case 0xf4: return op_read_dpi<&SMPcore::op_ld>(regs.a, regs.x); - case 0xf5: return op_read_addri<&SMPcore::op_ld>(regs.x); - case 0xf6: return op_read_addri<&SMPcore::op_ld>(regs.y); - case 0xf7: return op_read_idpy<&SMPcore::op_ld>(); - case 0xf8: return op_read_dp<&SMPcore::op_ld>(regs.x); - case 0xf9: return op_read_dpi<&SMPcore::op_ld>(regs.x, regs.y); - case 0xfa: return op_write_dp_dp<&SMPcore::op_st>(); - case 0xfb: return op_read_dpi<&SMPcore::op_ld>(regs.y, regs.x); - case 0xfc: return op_adjust<&SMPcore::op_inc>(regs.y); - case 0xfd: return op_transfer(regs.a, regs.y); - case 0xfe: return op_bne_ydec(); - case 0xff: return op_wait(); - } -} - -} diff --git a/bsnes/snes/smp/memory/memory.hpp b/bsnes/snes/smp/memory/memory.hpp deleted file mode 100755 index 72691f0e..00000000 --- a/bsnes/snes/smp/memory/memory.hpp +++ /dev/null @@ -1,9 +0,0 @@ -uint8 ram_read(uint16 addr); -void ram_write(uint16 addr, uint8 data); - -uint8 op_busread(uint16 addr); -void op_buswrite(uint16 addr, uint8 data); - -void op_io(); -uint8 op_read(uint16 addr); -void op_write(uint16 addr, uint8 data); diff --git a/bsnes/snes/smp/timing/timing.hpp b/bsnes/snes/smp/timing/timing.hpp deleted file mode 100755 index 2c282455..00000000 --- a/bsnes/snes/smp/timing/timing.hpp +++ /dev/null @@ -1,21 +0,0 @@ -template -class Timer { -public: - uint8 stage0_ticks; - uint8 stage1_ticks; - uint8 stage2_ticks; - uint4 stage3_ticks; - bool current_line; - bool enable; - uint8 target; - - void tick(); - void synchronize_stage1(); -}; - -Timer<192> timer0; -Timer<192> timer1; -Timer< 24> timer2; - -alwaysinline void add_clocks(unsigned clocks); -alwaysinline void cycle_edge(); diff --git a/bsnes/target-debugger/Makefile b/bsnes/target-debugger/Makefile index 6ca37350..987f636b 100755 --- a/bsnes/target-debugger/Makefile +++ b/bsnes/target-debugger/Makefile @@ -1,9 +1,9 @@ options += debugger -processors := arm hg51b upd96050 +processors := arm gsu hg51b r65816 spc700 upd96050 include processor/Makefile -include $(snes)/Makefile +include $(sfc)/Makefile name := laevateinn ui_objects := ui-main ui-settings ui-interface ui-debugger ui-tracer ui-window diff --git a/bsnes/target-debugger/base.hpp b/bsnes/target-debugger/base.hpp index 138a1558..dc54dd99 100755 --- a/bsnes/target-debugger/base.hpp +++ b/bsnes/target-debugger/base.hpp @@ -2,14 +2,16 @@ #error "debugger is only compatible with accuracy profile" #endif -#include -namespace SNES = SuperFamicom; +#include +namespace SFC = SuperFamicom; #include #include #include #include #include +#include +#include #include using namespace nall; diff --git a/bsnes/target-debugger/breakpoint/breakpoint.cpp b/bsnes/target-debugger/breakpoint/breakpoint.cpp index f73bf6d0..c51a9739 100755 --- a/bsnes/target-debugger/breakpoint/breakpoint.cpp +++ b/bsnes/target-debugger/breakpoint/breakpoint.cpp @@ -174,7 +174,7 @@ bool BreakpointEditor::testExecSMP(uint16 addr) { bool BreakpointEditor::testReadVRAM(uint16 addr) { for(auto &bp : breakpointReadVRAM) { if(bp.addr == addr) { - if(bp.compare && bp.data != SNES::ppu.vram[addr]) continue; + if(bp.compare && bp.data != SFC::ppu.vram[addr]) continue; debugger->print("Breakpoint #", bp.id, " hit\n"); return true; } @@ -196,7 +196,7 @@ bool BreakpointEditor::testWriteVRAM(uint16 addr, uint8 data) { bool BreakpointEditor::testReadOAM(uint16 addr) { for(auto &bp : breakpointReadOAM) { if(bp.addr == addr) { - if(bp.compare && bp.data != SNES::ppu.oam[addr]) continue; + if(bp.compare && bp.data != SFC::ppu.oam[addr]) continue; debugger->print("Breakpoint #", bp.id, " hit\n"); return true; } @@ -218,7 +218,7 @@ bool BreakpointEditor::testWriteOAM(uint16 addr, uint8 data) { bool BreakpointEditor::testReadCGRAM(uint16 addr) { for(auto &bp : breakpointReadCGRAM) { if(bp.addr == addr) { - if(bp.compare && bp.data != SNES::ppu.cgram[addr]) continue; + if(bp.compare && bp.data != SFC::ppu.cgram[addr]) continue; debugger->print("Breakpoint #", bp.id, " hit\n"); return true; } diff --git a/bsnes/target-debugger/console/console.cpp b/bsnes/target-debugger/console/console.cpp index e48dad83..306ba666 100755 --- a/bsnes/target-debugger/console/console.cpp +++ b/bsnes/target-debugger/console/console.cpp @@ -90,12 +90,12 @@ ConsoleWindow::ConsoleWindow() { }; menuEmulationPowerCycle.onActivate = [&] { - SNES::system.power(); + SFC::system.power(); print("System power cycled\n"); }; menuEmulationReset.onActivate = [&] { - SNES::system.reset(); + SFC::system.reset(); print("System reset\n"); }; diff --git a/bsnes/target-debugger/cpu/cpu.cpp b/bsnes/target-debugger/cpu/cpu.cpp index af798259..454a91b3 100755 --- a/bsnes/target-debugger/cpu/cpu.cpp +++ b/bsnes/target-debugger/cpu/cpu.cpp @@ -11,14 +11,14 @@ uint24 CPUDebugger::mirror(uint24 addr) { uint8 CPUDebugger::read(uint24 addr) { if((addr & 0x40e000) == 0x2000) return ~0; //$00-3f|80-bf:2000-3fff MMIO if((addr & 0x40e000) == 0x4000) return ~0; //$00-3f|80-bf:4000-5fff MMIO - return SNES::bus.read(mirror(addr)); + return SFC::bus.read(mirror(addr)); } void CPUDebugger::write(uint24 addr, uint8 data) { if((addr & 0x40e000) == 0x2000) return; //$00-3f|80-bf:2000-3fff MMIO if((addr & 0x40e000) == 0x4000) return; //$00-3f|80-bf:4000-5fff MMIO if((addr & 0x40e000) == 0x0000) addr = 0x7e0000 | (addr & 0x1fff); //$00-3f:80-bf:0000-1fff WRAM - return SNES::bus.write(mirror(addr), data); + return SFC::bus.write(mirror(addr), data); } unsigned CPUDebugger::opcodeLength(uint24 addr) { @@ -46,9 +46,9 @@ unsigned CPUDebugger::opcodeLength(uint24 addr) { 2, 2, 2, 2, 3, 2, 2, 2, 1, 3, 1, 1, 3, 3, 3, 4, }; - unsigned length = lengthTable[SNES::bus.read(addr)]; - if(length == M) return 3 - (SNES::cpu.regs.e | SNES::cpu.regs.p.m); - if(length == X) return 3 - (SNES::cpu.regs.e | SNES::cpu.regs.p.x); + unsigned length = lengthTable[SFC::bus.read(addr)]; + if(length == M) return 3 - (SFC::cpu.regs.e | SFC::cpu.regs.p.m); + if(length == X) return 3 - (SFC::cpu.regs.e | SFC::cpu.regs.p.x); return length; #undef M #undef X @@ -58,7 +58,7 @@ void CPUDebugger::updateDisassembly() { string line[15]; char text[512]; - SNES::cpu.disassemble_opcode(text, opcodePC); + SFC::cpu.disassemble_opcode(text, opcodePC); text[29] = 0; line[7] = { "> ", text }; @@ -67,7 +67,7 @@ void CPUDebugger::updateDisassembly() { for(signed b = 1; b <= 4; b++) { if(addr - b >= 0 && (debugger->cpuUsage.data[addr - b] & Usage::Exec)) { addr -= b; - SNES::cpu.disassemble_opcode(text, addr); + SFC::cpu.disassemble_opcode(text, addr); text[29] = 0; line[o] = { " ", text }; break; @@ -80,7 +80,7 @@ void CPUDebugger::updateDisassembly() { for(signed b = 1; b <= 4; b++) { if(addr + b <= 0xffffff && (debugger->cpuUsage.data[addr + b] & Usage::Exec)) { addr += b; - SNES::cpu.disassemble_opcode(text, addr); + SFC::cpu.disassemble_opcode(text, addr); text[29] = 0; line[o] = { " ", text }; break; @@ -97,13 +97,13 @@ void CPUDebugger::updateDisassembly() { disassembly.setText(output); registers.setText({ - "A:", hex<4>(SNES::cpu.regs.a), " X:", hex<4>(SNES::cpu.regs.x), " Y:", hex<4>(SNES::cpu.regs.y), - " S:", hex<4>(SNES::cpu.regs.s), " D:", hex<4>(SNES::cpu.regs.d), " DB:", hex<2>(SNES::cpu.regs.db), " ", - SNES::cpu.regs.p.n ? "N" : "n", SNES::cpu.regs.p.v ? "V" : "v", - SNES::cpu.regs.e ? (SNES::cpu.regs.p.m ? "1" : "0") : (SNES::cpu.regs.p.m ? "M" : "m"), - SNES::cpu.regs.e ? (SNES::cpu.regs.p.x ? "B" : "b") : (SNES::cpu.regs.p.x ? "X" : "x"), - SNES::cpu.regs.p.d ? "D" : "d", SNES::cpu.regs.p.i ? "I" : "i", - SNES::cpu.regs.p.z ? "Z" : "z", SNES::cpu.regs.p.c ? "C" : "c", + "A:", hex<4>(SFC::cpu.regs.a), " X:", hex<4>(SFC::cpu.regs.x), " Y:", hex<4>(SFC::cpu.regs.y), + " S:", hex<4>(SFC::cpu.regs.s), " D:", hex<4>(SFC::cpu.regs.d), " DB:", hex<2>(SFC::cpu.regs.db), " ", + SFC::cpu.regs.p.n ? "N" : "n", SFC::cpu.regs.p.v ? "V" : "v", + SFC::cpu.regs.e ? (SFC::cpu.regs.p.m ? "1" : "0") : (SFC::cpu.regs.p.m ? "M" : "m"), + SFC::cpu.regs.e ? (SFC::cpu.regs.p.x ? "B" : "b") : (SFC::cpu.regs.p.x ? "X" : "x"), + SFC::cpu.regs.p.d ? "D" : "d", SFC::cpu.regs.p.i ? "I" : "i", + SFC::cpu.regs.p.z ? "Z" : "z", SFC::cpu.regs.p.c ? "C" : "c", }); } diff --git a/bsnes/target-debugger/cpu/registers.cpp b/bsnes/target-debugger/cpu/registers.cpp index 496cd10f..a3d8ceaf 100755 --- a/bsnes/target-debugger/cpu/registers.cpp +++ b/bsnes/target-debugger/cpu/registers.cpp @@ -68,38 +68,38 @@ CPURegisterEditor::CPURegisterEditor() { } void CPURegisterEditor::loadRegisters() { - regAValue.setText(hex<4>(SNES::cpu.regs.a)); - regXValue.setText(hex<4>(SNES::cpu.regs.x)); - regYValue.setText(hex<4>(SNES::cpu.regs.y)); - regSValue.setText(hex<4>(SNES::cpu.regs.s)); - regDValue.setText(hex<4>(SNES::cpu.regs.d)); - regDBValue.setText(hex<2>(SNES::cpu.regs.db)); - flagN.setChecked(SNES::cpu.regs.p.n); - flagV.setChecked(SNES::cpu.regs.p.v); - flagM.setChecked(SNES::cpu.regs.p.m); - flagX.setChecked(SNES::cpu.regs.p.x); - flagD.setChecked(SNES::cpu.regs.p.d); - flagI.setChecked(SNES::cpu.regs.p.i); - flagZ.setChecked(SNES::cpu.regs.p.z); - flagC.setChecked(SNES::cpu.regs.p.c); - flagE.setChecked(SNES::cpu.regs.e); + regAValue.setText(hex<4>(SFC::cpu.regs.a)); + regXValue.setText(hex<4>(SFC::cpu.regs.x)); + regYValue.setText(hex<4>(SFC::cpu.regs.y)); + regSValue.setText(hex<4>(SFC::cpu.regs.s)); + regDValue.setText(hex<4>(SFC::cpu.regs.d)); + regDBValue.setText(hex<2>(SFC::cpu.regs.db)); + flagN.setChecked(SFC::cpu.regs.p.n); + flagV.setChecked(SFC::cpu.regs.p.v); + flagM.setChecked(SFC::cpu.regs.p.m); + flagX.setChecked(SFC::cpu.regs.p.x); + flagD.setChecked(SFC::cpu.regs.p.d); + flagI.setChecked(SFC::cpu.regs.p.i); + flagZ.setChecked(SFC::cpu.regs.p.z); + flagC.setChecked(SFC::cpu.regs.p.c); + flagE.setChecked(SFC::cpu.regs.e); } void CPURegisterEditor::saveRegisters() { - SNES::cpu.regs.a = hex(regAValue.text()); - SNES::cpu.regs.x = hex(regXValue.text()); - SNES::cpu.regs.y = hex(regYValue.text()); - SNES::cpu.regs.s = hex(regSValue.text()); - SNES::cpu.regs.d = hex(regDValue.text()); - SNES::cpu.regs.db = hex(regDBValue.text()); - SNES::cpu.regs.p.n = flagN.checked(); - SNES::cpu.regs.p.v = flagV.checked(); - SNES::cpu.regs.p.m = flagM.checked(); - SNES::cpu.regs.p.x = flagX.checked(); - SNES::cpu.regs.p.d = flagD.checked(); - SNES::cpu.regs.p.i = flagI.checked(); - SNES::cpu.regs.p.z = flagZ.checked(); - SNES::cpu.regs.p.c = flagC.checked(); - SNES::cpu.regs.e = flagE.checked(); - SNES::cpu.update_table(); //cache E/M/X flags + SFC::cpu.regs.a = hex(regAValue.text()); + SFC::cpu.regs.x = hex(regXValue.text()); + SFC::cpu.regs.y = hex(regYValue.text()); + SFC::cpu.regs.s = hex(regSValue.text()); + SFC::cpu.regs.d = hex(regDValue.text()); + SFC::cpu.regs.db = hex(regDBValue.text()); + SFC::cpu.regs.p.n = flagN.checked(); + SFC::cpu.regs.p.v = flagV.checked(); + SFC::cpu.regs.p.m = flagM.checked(); + SFC::cpu.regs.p.x = flagX.checked(); + SFC::cpu.regs.p.d = flagD.checked(); + SFC::cpu.regs.p.i = flagI.checked(); + SFC::cpu.regs.p.z = flagZ.checked(); + SFC::cpu.regs.p.c = flagC.checked(); + SFC::cpu.regs.e = flagE.checked(); + SFC::cpu.update_table(); //cache E/M/X flags } diff --git a/bsnes/target-debugger/debugger/debugger.cpp b/bsnes/target-debugger/debugger/debugger.cpp index 4f983364..51cfd86b 100755 --- a/bsnes/target-debugger/debugger/debugger.cpp +++ b/bsnes/target-debugger/debugger/debugger.cpp @@ -10,7 +10,7 @@ void Debugger::run() { return; } - SNES::system.run(); + SFC::system.run(); if(cpuDebugger->autoUpdate.checked()) cpuDebugger->updateDisassembly(); if(smpDebugger->autoUpdate.checked()) smpDebugger->updateDisassembly(); if(memoryEditor->autoUpdate.checked()) memoryEditor->updateView(); @@ -54,23 +54,23 @@ Debugger::Debugger() { cpuUsage.allocate(16 * 1024 * 1024); apuUsage.allocate(64 * 1024); - SNES::cpu.debugger.op_exec = { &Debugger::cpu_op_exec, this }; - SNES::cpu.debugger.op_read = { &Debugger::cpu_op_read, this }; - SNES::cpu.debugger.op_write = { &Debugger::cpu_op_write, this }; + SFC::cpu.debugger.op_exec = {&Debugger::cpu_op_exec, this}; + SFC::cpu.debugger.op_read = {&Debugger::cpu_op_read, this}; + SFC::cpu.debugger.op_write = {&Debugger::cpu_op_write, this}; - SNES::cpu.debugger.op_nmi = { &Debugger::cpu_op_nmi, this }; - SNES::cpu.debugger.op_irq = { &Debugger::cpu_op_irq, this }; + SFC::cpu.debugger.op_nmi = {&Debugger::cpu_op_nmi, this}; + SFC::cpu.debugger.op_irq = {&Debugger::cpu_op_irq, this}; - SNES::smp.debugger.op_exec = { &Debugger::smp_op_exec, this }; - SNES::smp.debugger.op_read = { &Debugger::smp_op_read, this }; - SNES::smp.debugger.op_write = { &Debugger::smp_op_write, this }; + SFC::smp.debugger.op_exec = {&Debugger::smp_op_exec, this}; + SFC::smp.debugger.op_read = {&Debugger::smp_op_read, this}; + SFC::smp.debugger.op_write = {&Debugger::smp_op_write, this}; - SNES::ppu.debugger.vram_read = { &Debugger::ppu_vram_read, this }; - SNES::ppu.debugger.vram_write = { &Debugger::ppu_vram_write, this }; + SFC::ppu.debugger.vram_read = {&Debugger::ppu_vram_read, this}; + SFC::ppu.debugger.vram_write = {&Debugger::ppu_vram_write, this}; - SNES::ppu.debugger.oam_read = { &Debugger::ppu_oam_read, this }; - SNES::ppu.debugger.oam_write = { &Debugger::ppu_oam_write, this }; + SFC::ppu.debugger.oam_read = {&Debugger::ppu_oam_read, this}; + SFC::ppu.debugger.oam_write = {&Debugger::ppu_oam_write, this}; - SNES::ppu.debugger.cgram_read = { &Debugger::ppu_cgram_read, this }; - SNES::ppu.debugger.cgram_write = { &Debugger::ppu_cgram_write, this }; + SFC::ppu.debugger.cgram_read = {&Debugger::ppu_cgram_read, this}; + SFC::ppu.debugger.cgram_write = {&Debugger::ppu_cgram_write, this}; } diff --git a/bsnes/target-debugger/debugger/hook.cpp b/bsnes/target-debugger/debugger/hook.cpp index 86f17284..025c2e52 100755 --- a/bsnes/target-debugger/debugger/hook.cpp +++ b/bsnes/target-debugger/debugger/hook.cpp @@ -12,7 +12,7 @@ void Debugger::cpu_op_exec(uint24 addr) { || breakpointHit ) { char text[512]; - SNES::cpu.disassemble_opcode(text, addr); + SFC::cpu.disassemble_opcode(text, addr); if(debug.cpu && tracer->enabled()) tracer->print(text, "\n"); if((debug.cpu && flags.step) || flags.cpu.stepInto || breakpointHit) { @@ -25,7 +25,7 @@ void Debugger::cpu_op_exec(uint24 addr) { cpuDebugger->updateDisassembly(); } suspend(); - SNES::scheduler.debug(); + SFC::scheduler.debug(); } } } @@ -36,11 +36,11 @@ void Debugger::cpu_op_read(uint24 addr) { if(breakpointHit) { char text[512]; - SNES::cpu.disassemble_opcode(text, cpuDebugger->opcodePC); + SFC::cpu.disassemble_opcode(text, cpuDebugger->opcodePC); print(text, "\n"); suspend(); - SNES::scheduler.debug(); + SFC::scheduler.debug(); } } @@ -50,11 +50,11 @@ void Debugger::cpu_op_write(uint24 addr, uint8 data) { if(breakpointHit) { char text[512]; - SNES::cpu.disassemble_opcode(text, cpuDebugger->opcodePC); + SFC::cpu.disassemble_opcode(text, cpuDebugger->opcodePC); print(text, "\n"); suspend(); - SNES::scheduler.debug(); + SFC::scheduler.debug(); } } @@ -85,7 +85,7 @@ void Debugger::smp_op_exec(uint16 addr) { || flags.smp.stepInto || breakpointHit ) { - string text = SNES::smp.disassemble_opcode(addr); + string text = SFC::smp.disassemble_opcode(addr); if(debug.smp && tracer->enabled()) tracer->print(text, "\n"); if((debug.smp && flags.step) || flags.smp.stepInto || breakpointHit) { @@ -98,7 +98,7 @@ void Debugger::smp_op_exec(uint16 addr) { smpDebugger->updateDisassembly(); } suspend(); - SNES::scheduler.debug(); + SFC::scheduler.debug(); } } } @@ -108,9 +108,9 @@ void Debugger::smp_op_read(uint16 addr) { bool breakpointHit = breakpointEditor->testReadSMP(addr); if(breakpointHit) { - print(SNES::smp.disassemble_opcode(smpDebugger->opcodePC), "\n"); + print(SFC::smp.disassemble_opcode(smpDebugger->opcodePC), "\n"); suspend(); - SNES::scheduler.debug(); + SFC::scheduler.debug(); } } @@ -119,9 +119,9 @@ void Debugger::smp_op_write(uint16 addr, uint8 data) { bool breakpointHit = breakpointEditor->testWriteSMP(addr, data); if(breakpointHit) { - print(SNES::smp.disassemble_opcode(smpDebugger->opcodePC), "\n"); + print(SFC::smp.disassemble_opcode(smpDebugger->opcodePC), "\n"); suspend(); - SNES::scheduler.debug(); + SFC::scheduler.debug(); } } @@ -133,11 +133,11 @@ void Debugger::ppu_vram_read(uint16 addr) { if(breakpointHit) { char text[512]; - SNES::cpu.disassemble_opcode(text, cpuDebugger->opcodePC); + SFC::cpu.disassemble_opcode(text, cpuDebugger->opcodePC); print(text, "\n"); suspend(); - SNES::scheduler.debug(); + SFC::scheduler.debug(); } } @@ -146,11 +146,11 @@ void Debugger::ppu_vram_write(uint16 addr, uint8 data) { if(breakpointHit) { char text[512]; - SNES::cpu.disassemble_opcode(text, cpuDebugger->opcodePC); + SFC::cpu.disassemble_opcode(text, cpuDebugger->opcodePC); print(text, "\n"); suspend(); - SNES::scheduler.debug(); + SFC::scheduler.debug(); } } @@ -159,11 +159,11 @@ void Debugger::ppu_oam_read(uint16 addr) { if(breakpointHit) { char text[512]; - SNES::cpu.disassemble_opcode(text, cpuDebugger->opcodePC); + SFC::cpu.disassemble_opcode(text, cpuDebugger->opcodePC); print(text, "\n"); suspend(); - SNES::scheduler.debug(); + SFC::scheduler.debug(); } } @@ -172,11 +172,11 @@ void Debugger::ppu_oam_write(uint16 addr, uint8 data) { if(breakpointHit) { char text[512]; - SNES::cpu.disassemble_opcode(text, cpuDebugger->opcodePC); + SFC::cpu.disassemble_opcode(text, cpuDebugger->opcodePC); print(text, "\n"); suspend(); - SNES::scheduler.debug(); + SFC::scheduler.debug(); } } @@ -185,11 +185,11 @@ void Debugger::ppu_cgram_read(uint16 addr) { if(breakpointHit) { char text[512]; - SNES::cpu.disassemble_opcode(text, cpuDebugger->opcodePC); + SFC::cpu.disassemble_opcode(text, cpuDebugger->opcodePC); print(text, "\n"); suspend(); - SNES::scheduler.debug(); + SFC::scheduler.debug(); } } @@ -198,10 +198,10 @@ void Debugger::ppu_cgram_write(uint16 addr, uint8 data) { if(breakpointHit) { char text[512]; - SNES::cpu.disassemble_opcode(text, cpuDebugger->opcodePC); + SFC::cpu.disassemble_opcode(text, cpuDebugger->opcodePC); print(text, "\n"); suspend(); - SNES::scheduler.debug(); + SFC::scheduler.debug(); } } diff --git a/bsnes/target-debugger/interface/interface.cpp b/bsnes/target-debugger/interface/interface.cpp index 24aace99..04a1e94b 100755 --- a/bsnes/target-debugger/interface/interface.cpp +++ b/bsnes/target-debugger/interface/interface.cpp @@ -2,13 +2,12 @@ Interface *interface = nullptr; bool Interface::loadCartridge(const string &foldername) { - uint8_t *data; - unsigned size; - if(file::read({ foldername, "program.rom" }, data, size) == false) return false; + auto memory = file::read({foldername, "program.rom"}); + if(memory.empty()) return false; - if(SNES::cartridge.loaded()) { + if(SFC::cartridge.loaded()) { saveMemory(); - SNES::cartridge.unload(); + SFC::cartridge.unload(); debugger->print("Cartridge unloaded\n"); } @@ -16,20 +15,19 @@ bool Interface::loadCartridge(const string &foldername) { mkdir(string(pathName, "debug/"), 0755); string markup; - markup.readfile({ pathName, "manifest.xml" }); - if(markup.empty()) markup = SuperFamicomCartridge(data, size).markup; + markup.readfile({pathName, "manifest.xml"}); + if(markup.empty()) markup = SuperFamicomCartridge(memory.data(), memory.size()).markup; - SNES::cartridge.rom.copy(data, size); - SNES::cartridge.load(SNES::Cartridge::Mode::Normal, markup); - SNES::system.power(); + SFC::cartridge.rom.copy(vectorstream{memory}); + SFC::cartridge.load(SFC::Cartridge::Mode::Normal, markup); + SFC::system.power(); string name = pathName; name.rtrim<1>("/"); name = notdir(name); - delete[] data; videoWindow->setTitle(name); - SNES::video.generate(SNES::Video::Format::RGB24); + SFC::video.generate_palette(); debugger->print("Loaded ", pathName, "program.rom\n"); loadMemory(); debugger->print(markup, "\n"); @@ -38,15 +36,12 @@ bool Interface::loadCartridge(const string &foldername) { } void Interface::loadMemory() { - for(auto &memory : SNES::cartridge.nvram) { + for(auto &memory : SFC::cartridge.nvram) { if(memory.size == 0) continue; - string filename = { pathName, memory.id }; - uint8_t *data; - unsigned size; - if(file::read(filename, data, size)) { + string filename = {pathName, memory.id}; + if(auto content = file::read(filename)) { debugger->print("Loaded ", filename, "\n"); - memcpy(memory.data, data, min(memory.size, size)); - delete[] data; + memcpy(memory.data, content.data(), min(memory.size, content.size())); } } @@ -54,7 +49,7 @@ void Interface::loadMemory() { } void Interface::saveMemory() { - for(auto &memory : SNES::cartridge.nvram) { + for(auto &memory : SFC::cartridge.nvram) { if(memory.size == 0) continue; string filename = { pathName, memory.id }; if(file::write(filename, memory.data, memory.size)) { @@ -66,21 +61,19 @@ void Interface::saveMemory() { } bool Interface::loadState(unsigned slot) { - string filename = { pathName, "state-", slot, ".bst" }; - uint8_t *data; - unsigned size; - if(file::read(filename, data, size) == false) return false; - serializer s(data, size); - bool result = SNES::system.unserialize(s); - delete[] data; + string filename = {pathName, "state-", slot, ".bst"}; + auto memory = file::read(filename); + if(memory.empty()) return false; + serializer s(memory.data(), memory.size()); + bool result = SFC::system.unserialize(s); if(result) debugger->print("Loaded state from ", filename, "\n"); return result; } bool Interface::saveState(unsigned slot) { - SNES::system.runtosave(); - serializer s = SNES::system.serialize(); - string filename = { pathName, "state-", slot, ".bst" }; + SFC::system.runtosave(); + serializer s = SFC::system.serialize(); + string filename = {pathName, "state-", slot, ".bst"}; bool result = file::write(filename, s.data(), s.size()); if(result) debugger->print("Saved state to ", filename, "\n"); return result; @@ -97,8 +90,8 @@ void Interface::videoRefresh(const uint32_t *data, bool hires, bool interlace, b const uint32_t *sp = data + y * 1024; uint32_t *dp0 = output + y * 1024, *dp1 = dp0 + 512; for(unsigned x = 0; x < 512; x++) { - *dp0++ = SNES::video.palette[*sp]; - *dp1++ = SNES::video.palette[*sp++]; + *dp0++ = SFC::video.palette[*sp]; + *dp1++ = SFC::video.palette[*sp++]; } } } else { @@ -106,7 +99,7 @@ void Interface::videoRefresh(const uint32_t *data, bool hires, bool interlace, b const uint32_t *sp = data + y * 512; uint32_t *dp = output + y * 512; for(unsigned x = 0; x < 512; x++) { - *dp++ = SNES::video.palette[*sp++]; + *dp++ = SFC::video.palette[*sp++]; } } } @@ -119,25 +112,25 @@ void Interface::audioSample(int16_t lsample, int16_t rsample) { audio.sample(lsample, rsample); } -int16_t Interface::inputPoll(bool port, SNES::Input::Device device, unsigned index, unsigned id) { +int16_t Interface::inputPoll(bool port, SFC::Input::Device device, unsigned index, unsigned id) { if(videoWindow->focused() == false) return 0; auto keyboardState = phoenix::Keyboard::state(); if(port == 0) { - if(device == SNES::Input::Device::Joypad) { - switch((SNES::Input::JoypadID)id) { - case SNES::Input::JoypadID::Up: return keyboardState[(unsigned)phoenix::Keyboard::Scancode::Up]; - case SNES::Input::JoypadID::Down: return keyboardState[(unsigned)phoenix::Keyboard::Scancode::Down]; - case SNES::Input::JoypadID::Left: return keyboardState[(unsigned)phoenix::Keyboard::Scancode::Left]; - case SNES::Input::JoypadID::Right: return keyboardState[(unsigned)phoenix::Keyboard::Scancode::Right]; - case SNES::Input::JoypadID::B: return keyboardState[(unsigned)phoenix::Keyboard::Scancode::Z]; - case SNES::Input::JoypadID::A: return keyboardState[(unsigned)phoenix::Keyboard::Scancode::X]; - case SNES::Input::JoypadID::Y: return keyboardState[(unsigned)phoenix::Keyboard::Scancode::A]; - case SNES::Input::JoypadID::X: return keyboardState[(unsigned)phoenix::Keyboard::Scancode::S]; - case SNES::Input::JoypadID::L: return keyboardState[(unsigned)phoenix::Keyboard::Scancode::D]; - case SNES::Input::JoypadID::R: return keyboardState[(unsigned)phoenix::Keyboard::Scancode::C]; - case SNES::Input::JoypadID::Select: return keyboardState[(unsigned)phoenix::Keyboard::Scancode::Apostrophe]; - case SNES::Input::JoypadID::Start: return keyboardState[(unsigned)phoenix::Keyboard::Scancode::Return]; + if(device == SFC::Input::Device::Joypad) { + switch((SFC::Input::JoypadID)id) { + case SFC::Input::JoypadID::Up: return keyboardState[(unsigned)phoenix::Keyboard::Scancode::Up]; + case SFC::Input::JoypadID::Down: return keyboardState[(unsigned)phoenix::Keyboard::Scancode::Down]; + case SFC::Input::JoypadID::Left: return keyboardState[(unsigned)phoenix::Keyboard::Scancode::Left]; + case SFC::Input::JoypadID::Right: return keyboardState[(unsigned)phoenix::Keyboard::Scancode::Right]; + case SFC::Input::JoypadID::B: return keyboardState[(unsigned)phoenix::Keyboard::Scancode::Z]; + case SFC::Input::JoypadID::A: return keyboardState[(unsigned)phoenix::Keyboard::Scancode::X]; + case SFC::Input::JoypadID::Y: return keyboardState[(unsigned)phoenix::Keyboard::Scancode::A]; + case SFC::Input::JoypadID::X: return keyboardState[(unsigned)phoenix::Keyboard::Scancode::S]; + case SFC::Input::JoypadID::L: return keyboardState[(unsigned)phoenix::Keyboard::Scancode::D]; + case SFC::Input::JoypadID::R: return keyboardState[(unsigned)phoenix::Keyboard::Scancode::C]; + case SFC::Input::JoypadID::Select: return keyboardState[(unsigned)phoenix::Keyboard::Scancode::Apostrophe]; + case SFC::Input::JoypadID::Start: return keyboardState[(unsigned)phoenix::Keyboard::Scancode::Return]; } } } @@ -145,8 +138,8 @@ int16_t Interface::inputPoll(bool port, SNES::Input::Device device, unsigned ind return 0; } -string Interface::path(SNES::Cartridge::Slot slot, const string &hint) { - return { pathName, hint }; +string Interface::path(SFC::Cartridge::Slot slot, const string &hint) { + return {pathName, hint}; } void Interface::message(const string &text) { @@ -154,13 +147,9 @@ void Interface::message(const string &text) { } Interface::Interface() { - SNES::interface = this; - SNES::system.init(); + SFC::interface = this; + SFC::system.init(); - uint8_t *data; - unsigned size; - if(file::read({application->userpath, "Super Famicom.sys/spc700.rom"}, data, size)) { - memcpy(SNES::smp.iplrom, data, min(64u, size)); - delete[] data; - } + filestream fs{{application->userpath, "Super Famicom.sys/spc700.rom"}}; + fs.read(SFC::smp.iplrom, min(64u, fs.size())); } diff --git a/bsnes/target-debugger/interface/interface.hpp b/bsnes/target-debugger/interface/interface.hpp index 0c4fe1bf..4b61446d 100755 --- a/bsnes/target-debugger/interface/interface.hpp +++ b/bsnes/target-debugger/interface/interface.hpp @@ -1,4 +1,4 @@ -struct Interface : SNES::Interface { +struct Interface : SFC::Interface { string pathName; bool loadCartridge(const string &foldername); @@ -9,9 +9,9 @@ struct Interface : SNES::Interface { void videoRefresh(const uint32_t *data, bool hires, bool interlace, bool overscan); void audioSample(int16_t lsample, int16_t rsample); - int16_t inputPoll(bool port, SNES::Input::Device device, unsigned index, unsigned id); + int16_t inputPoll(bool port, SFC::Input::Device device, unsigned index, unsigned id); - string path(SNES::Cartridge::Slot slot, const string &hint); + string path(SFC::Cartridge::Slot slot, const string &hint); void message(const string &text); Interface(); diff --git a/bsnes/target-debugger/memory/memory.cpp b/bsnes/target-debugger/memory/memory.cpp index 9b151599..09d9b15e 100755 --- a/bsnes/target-debugger/memory/memory.cpp +++ b/bsnes/target-debugger/memory/memory.cpp @@ -43,37 +43,37 @@ MemoryEditor::MemoryEditor() { } uint8_t MemoryEditor::read(unsigned addr) { - if(SNES::cartridge.loaded() == false) return 0x00; + if(SFC::cartridge.loaded() == false) return 0x00; switch(source.selection()) { case 0: return cpuDebugger->read(addr); case 1: return smpDebugger->read(addr); - case 2: return SNES::ppu.vram[addr & 0xffff]; - case 3: return SNES::ppu.oam[addr % 544]; - case 4: return SNES::ppu.cgram[addr & 0x01ff]; + case 2: return SFC::ppu.vram[addr & 0xffff]; + case 3: return SFC::ppu.oam[addr % 544]; + case 4: return SFC::ppu.cgram[addr & 0x01ff]; } return ~0; } void MemoryEditor::write(unsigned addr, uint8_t data) { - if(SNES::cartridge.loaded() == false) return; + if(SFC::cartridge.loaded() == false) return; switch(source.selection()) { case 0: - SNES::cartridge.rom.write_protect(false); + SFC::cartridge.rom.write_protect(false); cpuDebugger->write(addr, data); - SNES::cartridge.rom.write_protect(true); + SFC::cartridge.rom.write_protect(true); break; case 1: smpDebugger->write(addr, data); break; case 2: - SNES::ppu.vram[addr & 0xffff] = data; + SFC::ppu.vram[addr & 0xffff] = data; break; case 3: - SNES::ppu.oam[addr % 544] = data; - SNES::ppu.sprite.synchronize(); //cache OAM changes internally + SFC::ppu.oam[addr % 544] = data; + SFC::ppu.sprite.synchronize(); //cache OAM changes internally break; case 4: - SNES::ppu.cgram[addr & 0x01ff] = data; + SFC::ppu.cgram[addr & 0x01ff] = data; break; } } @@ -104,9 +104,9 @@ void MemoryEditor::exportMemoryToDisk() { switch(source.selection()) { case 0: for(unsigned addr = 0; addr <= 0xffffff; addr++) fp.write(cpuDebugger->read(addr)); break; case 1: for(unsigned addr = 0; addr <= 0xffff; addr++) fp.write(smpDebugger->read(addr)); break; - case 2: for(unsigned addr = 0; addr <= 0xffff; addr++) fp.write(SNES::ppu.vram[addr]); break; - case 3: for(unsigned addr = 0; addr <= 0x021f; addr++) fp.write(SNES::ppu.oam[addr]); break; - case 4: for(unsigned addr = 0; addr <= 0x01ff; addr++) fp.write(SNES::ppu.cgram[addr]); break; + case 2: for(unsigned addr = 0; addr <= 0xffff; addr++) fp.write(SFC::ppu.vram[addr]); break; + case 3: for(unsigned addr = 0; addr <= 0x021f; addr++) fp.write(SFC::ppu.oam[addr]); break; + case 4: for(unsigned addr = 0; addr <= 0x01ff; addr++) fp.write(SFC::ppu.cgram[addr]); break; } debugger->print("Exported memory to ", filename, "\n"); } diff --git a/bsnes/target-debugger/properties/properties.cpp b/bsnes/target-debugger/properties/properties.cpp index 344bfa30..23e5002b 100755 --- a/bsnes/target-debugger/properties/properties.cpp +++ b/bsnes/target-debugger/properties/properties.cpp @@ -31,78 +31,78 @@ void PropertiesViewer::updateProperties() { string output; output.append("$2100 INIDISP\n" - " Display Disable = ", SNES::ppu.regs.display_disable, "\n", - " Display Brightness = ", SNES::ppu.regs.display_brightness, "\n", + " Display Disable = ", SFC::ppu.regs.display_disable, "\n", + " Display Brightness = ", SFC::ppu.regs.display_brightness, "\n", "\n" ); output.append("$2101 OBSEL\n" - " Base Size = ", SNES::ppu.sprite.regs.base_size, "\n", - " Name Select = $", hex<4>(SNES::ppu.sprite.regs.nameselect << 13), "\n", - " Tiledata Address = $", hex<4>(SNES::ppu.sprite.regs.tiledata_addr), "\n", + " Base Size = ", SFC::ppu.sprite.regs.base_size, "\n", + " Name Select = $", hex<4>(SFC::ppu.sprite.regs.nameselect << 13), "\n", + " Tiledata Address = $", hex<4>(SFC::ppu.sprite.regs.tiledata_addr), "\n", "\n" ); output.append("$2102 OAMADDL\n" "$2103 OAMADDH\n" - " Base Address = $", hex<4>(SNES::ppu.regs.oam_baseaddr), "\n", - " Priority = ", SNES::ppu.regs.oam_priority, "\n", + " Base Address = $", hex<4>(SFC::ppu.regs.oam_baseaddr), "\n", + " Priority = ", SFC::ppu.regs.oam_priority, "\n", "\n" ); output.append("$2105 BGMODE\n" - " Mode = ", SNES::ppu.regs.bgmode, "\n", - " BG3 Priority = ", SNES::ppu.regs.bg3_priority, "\n", - " BG1 Tile Size = ", SNES::ppu.bg1.regs.tile_size ? "16x16" : "8x8", "\n", - " BG2 Tile Size = ", SNES::ppu.bg2.regs.tile_size ? "16x16" : "8x8", "\n", - " BG3 Tile Size = ", SNES::ppu.bg3.regs.tile_size ? "16x16" : "8x8", "\n", - " BG4 Tile Size = ", SNES::ppu.bg4.regs.tile_size ? "16x16" : "8x8", "\n", + " Mode = ", SFC::ppu.regs.bgmode, "\n", + " BG3 Priority = ", SFC::ppu.regs.bg3_priority, "\n", + " BG1 Tile Size = ", SFC::ppu.bg1.regs.tile_size ? "16x16" : "8x8", "\n", + " BG2 Tile Size = ", SFC::ppu.bg2.regs.tile_size ? "16x16" : "8x8", "\n", + " BG3 Tile Size = ", SFC::ppu.bg3.regs.tile_size ? "16x16" : "8x8", "\n", + " BG4 Tile Size = ", SFC::ppu.bg4.regs.tile_size ? "16x16" : "8x8", "\n", "\n" ); output.append("$2106 MOSAIC\n" - " BG1 Mosaic = ", 1u + SNES::ppu.bg1.regs.mosaic, "x", 1u + SNES::ppu.bg1.regs.mosaic, "\n", - " BG2 Mosaic = ", 1u + SNES::ppu.bg2.regs.mosaic, "x", 1u + SNES::ppu.bg2.regs.mosaic, "\n", - " BG3 Mosaic = ", 1u + SNES::ppu.bg3.regs.mosaic, "x", 1u + SNES::ppu.bg3.regs.mosaic, "\n", - " BG4 Mosaic = ", 1u + SNES::ppu.bg4.regs.mosaic, "x", 1u + SNES::ppu.bg4.regs.mosaic, "\n", + " BG1 Mosaic = ", 1u + SFC::ppu.bg1.regs.mosaic, "x", 1u + SFC::ppu.bg1.regs.mosaic, "\n", + " BG2 Mosaic = ", 1u + SFC::ppu.bg2.regs.mosaic, "x", 1u + SFC::ppu.bg2.regs.mosaic, "\n", + " BG3 Mosaic = ", 1u + SFC::ppu.bg3.regs.mosaic, "x", 1u + SFC::ppu.bg3.regs.mosaic, "\n", + " BG4 Mosaic = ", 1u + SFC::ppu.bg4.regs.mosaic, "x", 1u + SFC::ppu.bg4.regs.mosaic, "\n", "\n" ); lstring screenSizes = { "32x32", "32x64", "64x32", "64x64" }; output.append("$2107 BG1SC\n" - " BG1 Screen Address = $", hex<4>(SNES::ppu.bg1.regs.screen_addr), "\n", - " BG1 Screen Size = ", screenSizes[SNES::ppu.bg1.regs.screen_size], "\n", + " BG1 Screen Address = $", hex<4>(SFC::ppu.bg1.regs.screen_addr), "\n", + " BG1 Screen Size = ", screenSizes[SFC::ppu.bg1.regs.screen_size], "\n", "\n" ); output.append("$2108 BG2SC\n" - " BG2 Screen Address = $", hex<4>(SNES::ppu.bg2.regs.screen_addr), "\n", - " BG2 Screen Size = ", screenSizes[SNES::ppu.bg2.regs.screen_size], "\n", + " BG2 Screen Address = $", hex<4>(SFC::ppu.bg2.regs.screen_addr), "\n", + " BG2 Screen Size = ", screenSizes[SFC::ppu.bg2.regs.screen_size], "\n", "\n" ); output.append("$2109 BG3SC\n" - " BG3 Screen Address = $", hex<4>(SNES::ppu.bg3.regs.screen_addr), "\n", - " BG3 Screen Size = ", screenSizes[SNES::ppu.bg3.regs.screen_size], "\n", + " BG3 Screen Address = $", hex<4>(SFC::ppu.bg3.regs.screen_addr), "\n", + " BG3 Screen Size = ", screenSizes[SFC::ppu.bg3.regs.screen_size], "\n", "\n" ); output.append("$210a BG4SC\n" - " BG4 Screen Address = $", hex<4>(SNES::ppu.bg4.regs.screen_addr), "\n", - " BG4 Screen Size = ", screenSizes[SNES::ppu.bg4.regs.screen_size], "\n", + " BG4 Screen Address = $", hex<4>(SFC::ppu.bg4.regs.screen_addr), "\n", + " BG4 Screen Size = ", screenSizes[SFC::ppu.bg4.regs.screen_size], "\n", "\n" ); output.append("$210b BG12NBA\n" - " BG1 Tiledata Address = $", hex<4>(SNES::ppu.bg1.regs.tiledata_addr), "\n", - " BG2 Tiledata Address = $", hex<4>(SNES::ppu.bg2.regs.tiledata_addr), "\n", + " BG1 Tiledata Address = $", hex<4>(SFC::ppu.bg1.regs.tiledata_addr), "\n", + " BG2 Tiledata Address = $", hex<4>(SFC::ppu.bg2.regs.tiledata_addr), "\n", "\n" ); output.append("$210c BG34NBA\n" - " BG3 Tiledata Address = $", hex<4>(SNES::ppu.bg3.regs.tiledata_addr), "\n", - " BG4 Tiledata Address = $", hex<4>(SNES::ppu.bg4.regs.tiledata_addr), "\n", + " BG3 Tiledata Address = $", hex<4>(SFC::ppu.bg3.regs.tiledata_addr), "\n", + " BG4 Tiledata Address = $", hex<4>(SFC::ppu.bg4.regs.tiledata_addr), "\n", "\n" ); diff --git a/bsnes/target-debugger/smp/registers.cpp b/bsnes/target-debugger/smp/registers.cpp index 9a5c95b9..027b1789 100755 --- a/bsnes/target-debugger/smp/registers.cpp +++ b/bsnes/target-debugger/smp/registers.cpp @@ -58,31 +58,31 @@ SMPRegisterEditor::SMPRegisterEditor() { } void SMPRegisterEditor::loadRegisters() { - regAValue.setText(hex<2>(SNES::smp.regs.a)); - regXValue.setText(hex<2>(SNES::smp.regs.x)); - regYValue.setText(hex<2>(SNES::smp.regs.y)); - regSValue.setText(hex<2>(SNES::smp.regs.s)); - flagN.setChecked(SNES::smp.regs.p.n); - flagV.setChecked(SNES::smp.regs.p.v); - flagP.setChecked(SNES::smp.regs.p.p); - flagB.setChecked(SNES::smp.regs.p.b); - flagH.setChecked(SNES::smp.regs.p.h); - flagI.setChecked(SNES::smp.regs.p.i); - flagZ.setChecked(SNES::smp.regs.p.z); - flagC.setChecked(SNES::smp.regs.p.c); + regAValue.setText(hex<2>(SFC::smp.regs.a)); + regXValue.setText(hex<2>(SFC::smp.regs.x)); + regYValue.setText(hex<2>(SFC::smp.regs.y)); + regSValue.setText(hex<2>(SFC::smp.regs.s)); + flagN.setChecked(SFC::smp.regs.p.n); + flagV.setChecked(SFC::smp.regs.p.v); + flagP.setChecked(SFC::smp.regs.p.p); + flagB.setChecked(SFC::smp.regs.p.b); + flagH.setChecked(SFC::smp.regs.p.h); + flagI.setChecked(SFC::smp.regs.p.i); + flagZ.setChecked(SFC::smp.regs.p.z); + flagC.setChecked(SFC::smp.regs.p.c); } void SMPRegisterEditor::saveRegisters() { - SNES::smp.regs.a = hex(regAValue.text()); - SNES::smp.regs.x = hex(regXValue.text()); - SNES::smp.regs.y = hex(regYValue.text()); - SNES::smp.regs.s = hex(regSValue.text()); - SNES::smp.regs.p.n = flagN.checked(); - SNES::smp.regs.p.v = flagV.checked(); - SNES::smp.regs.p.p = flagP.checked(); - SNES::smp.regs.p.b = flagB.checked(); - SNES::smp.regs.p.h = flagH.checked(); - SNES::smp.regs.p.i = flagI.checked(); - SNES::smp.regs.p.z = flagZ.checked(); - SNES::smp.regs.p.c = flagC.checked(); + SFC::smp.regs.a = hex(regAValue.text()); + SFC::smp.regs.x = hex(regXValue.text()); + SFC::smp.regs.y = hex(regYValue.text()); + SFC::smp.regs.s = hex(regSValue.text()); + SFC::smp.regs.p.n = flagN.checked(); + SFC::smp.regs.p.v = flagV.checked(); + SFC::smp.regs.p.p = flagP.checked(); + SFC::smp.regs.p.b = flagB.checked(); + SFC::smp.regs.p.h = flagH.checked(); + SFC::smp.regs.p.i = flagI.checked(); + SFC::smp.regs.p.z = flagZ.checked(); + SFC::smp.regs.p.c = flagC.checked(); } diff --git a/bsnes/target-debugger/smp/smp.cpp b/bsnes/target-debugger/smp/smp.cpp index 70f1efb8..6f9e2692 100755 --- a/bsnes/target-debugger/smp/smp.cpp +++ b/bsnes/target-debugger/smp/smp.cpp @@ -5,25 +5,25 @@ SMPDebugger *smpDebugger = nullptr; uint8 SMPDebugger::read(uint16 addr) { if((addr & 0xfff0) == 0x00f0) return ~0; //$00f0-00ff MMIO - return SNES::smp.op_busread(addr); + return SFC::smp.op_busread(addr); } void SMPDebugger::write(uint16 addr, uint8 data) { if((addr & 0xfff0) == 0x00f0) return; //$00f0-00ff MMIO - return SNES::smp.op_buswrite(addr, data); + return SFC::smp.op_buswrite(addr, data); } unsigned SMPDebugger::opcodeLength(uint16 addr) { static unsigned lengthTable[256] = { 0 }; - return lengthTable[SNES::smp.op_busread(addr)]; + return lengthTable[SFC::smp.op_busread(addr)]; } void SMPDebugger::updateDisassembly() { string line[15]; - line[7] = { "> ", SNES::smp.disassemble_opcode(opcodePC) }; + line[7] = { "> ", SFC::smp.disassemble_opcode(opcodePC) }; line[7][31] = 0; signed addr = opcodePC; @@ -31,7 +31,7 @@ void SMPDebugger::updateDisassembly() { for(signed b = 1; b <= 3; b++) { if(addr - b >= 0 && (debugger->apuUsage.data[addr - b] & Usage::Exec)) { addr -= b; - line[o] = { " ", SNES::smp.disassemble_opcode(addr) }; + line[o] = { " ", SFC::smp.disassemble_opcode(addr) }; line[o][31] = 0; break; } @@ -43,7 +43,7 @@ void SMPDebugger::updateDisassembly() { for(signed b = 1; b <= 3; b++) { if(addr - b <= 0xffff && (debugger->apuUsage.data[addr + b] & Usage::Exec)) { addr += b; - line[o] = { " ", SNES::smp.disassemble_opcode(addr) }; + line[o] = { " ", SFC::smp.disassemble_opcode(addr) }; line[o][31] = 0; break; } @@ -59,13 +59,13 @@ void SMPDebugger::updateDisassembly() { disassembly.setText(output); registers.setText({ - "YA:", hex<2>(SNES::smp.regs.y), hex<2>(SNES::smp.regs.a), - " A:", hex<2>(SNES::smp.regs.a), " X:", hex<2>(SNES::smp.regs.x), - " Y:", hex<2>(SNES::smp.regs.y), " S:01", hex<2>(SNES::smp.regs.s), " ", - SNES::smp.regs.p.n ? "N" : "n", SNES::smp.regs.p.v ? "V" : "v", - SNES::smp.regs.p.p ? "P" : "p", SNES::smp.regs.p.b ? "B" : "b", - SNES::smp.regs.p.h ? "H" : "h", SNES::smp.regs.p.i ? "I" : "i", - SNES::smp.regs.p.z ? "Z" : "z", SNES::smp.regs.p.c ? "C" : "c", + "YA:", hex<2>(SFC::smp.regs.y), hex<2>(SFC::smp.regs.a), + " A:", hex<2>(SFC::smp.regs.a), " X:", hex<2>(SFC::smp.regs.x), + " Y:", hex<2>(SFC::smp.regs.y), " S:01", hex<2>(SFC::smp.regs.s), " ", + SFC::smp.regs.p.n ? "N" : "n", SFC::smp.regs.p.v ? "V" : "v", + SFC::smp.regs.p.p ? "P" : "p", SFC::smp.regs.p.b ? "B" : "b", + SFC::smp.regs.p.h ? "H" : "h", SFC::smp.regs.p.i ? "I" : "i", + SFC::smp.regs.p.z ? "Z" : "z", SFC::smp.regs.p.c ? "C" : "c", }); } diff --git a/bsnes/target-debugger/vram/vram.cpp b/bsnes/target-debugger/vram/vram.cpp index 811f2f87..36d596de 100755 --- a/bsnes/target-debugger/vram/vram.cpp +++ b/bsnes/target-debugger/vram/vram.cpp @@ -51,7 +51,7 @@ void VRAMViewer::updateTiles() { } } dp = canvas.data(); - const uint8_t *sp = SNES::ppu.vram; + const uint8_t *sp = SFC::ppu.vram; if(modeSelection.selection() == 0) { for(unsigned tileY = 0; tileY < 64; tileY++) { diff --git a/bsnes/target-debugger/window/window.cpp b/bsnes/target-debugger/window/window.cpp index 81ad9f76..3353fec3 100755 --- a/bsnes/target-debugger/window/window.cpp +++ b/bsnes/target-debugger/window/window.cpp @@ -2,15 +2,15 @@ WindowManager *windowManager = nullptr; void WindowManager::append(Window *window, const string &name) { - windowList.append({ window, name, window->geometry().text() }); + windowList.append({window, name, window->geometry().text()}); } void WindowManager::loadGeometry() { for(auto &window : windowList) { config.append(window.geometry, window.name); } - config.load({ application->userpath, "geometry.cfg" }); - config.save({ application->userpath, "geometry.cfg" }); + config.load({application->userpath, "geometry.cfg"}); + config.save({application->userpath, "geometry.cfg"}); for(auto &window : windowList) { window.window->setGeometry(window.geometry); } @@ -21,5 +21,5 @@ void WindowManager::saveGeometry() { window.geometry = window.window->geometry().text(); window.window->setVisible(false); } - config.save({ application->userpath, "geometry.cfg" }); + config.save({application->userpath, "geometry.cfg"}); } diff --git a/bsnes/target-ui/Makefile b/bsnes/target-ui/Makefile index e3ae8924..8c3d2635 100755 --- a/bsnes/target-ui/Makefile +++ b/bsnes/target-ui/Makefile @@ -1,8 +1,8 @@ -processors := arm hg51b lr35902 rp2a03 upd96050 +processors := arm gsu hg51b lr35902 r6502 r65816 spc700 upd96050 include processor/Makefile -include $(nes)/Makefile -include $(snes)/Makefile +include $(fc)/Makefile +include $(sfc)/Makefile include $(gb)/Makefile include $(gba)/Makefile name := bsnes diff --git a/bsnes/target-ui/base.hpp b/bsnes/target-ui/base.hpp index c9cfd363..e03e1433 100755 --- a/bsnes/target-ui/base.hpp +++ b/bsnes/target-ui/base.hpp @@ -1,12 +1,12 @@ -#include -#include +#include +#include #include #include -namespace NES = Famicom; -namespace SNES = SuperFamicom; -namespace GB = GameBoy; -namespace GBA = GameBoyAdvance; +namespace FC = Famicom; +namespace SFC = SuperFamicom; +namespace GB = GameBoy; +namespace GBA = GameBoyAdvance; #include #include diff --git a/bsnes/target-ui/general/dip-switches.cpp b/bsnes/target-ui/general/dip-switches.cpp index 38bfab16..c0513b53 100755 --- a/bsnes/target-ui/general/dip-switches.cpp +++ b/bsnes/target-ui/general/dip-switches.cpp @@ -1,8 +1,8 @@ DipSwitches *dipSwitches = nullptr; DipSwitch::DipSwitch() { - append(name, { ~0, 0 }, 5); - append(value, { ~0, 0 }, 0); + append(name, {~0, 0}, 5); + append(value, {~0, 0}, 0); } DipSwitches::DipSwitches() { @@ -13,22 +13,22 @@ DipSwitches::DipSwitches() { append(layout); for(unsigned n = 0; n < 8; n++) - layout.append(dip[n], { ~0, 0 }, 5); - layout.append(controlLayout, { ~0, 0 }, 5); - controlLayout.append(spacer, { ~0, 0 }, 0); - controlLayout.append(acceptButton, { 0, 0 }, 0); + layout.append(dip[n], {~0, 0}, 5); + layout.append(controlLayout, {~0, 0}, 5); + controlLayout.append(spacer, {~0, 0}, 0); + controlLayout.append(acceptButton, { 0, 0}, 0); - setGeometry({ 128, 128, 400, layout.minimumGeometry().height }); + setGeometry({128, 128, 400, layout.minimumGeometry().height}); windowManager->append(this, "DipSwitches"); acceptButton.onActivate = { &DipSwitches::accept, this }; } void DipSwitches::load() { - if(interface->mode() != Interface::Mode::SNES || SNES::cartridge.has_nss_dip() == false) return; + if(interface->mode() != Interface::Mode::SFC || SFC::cartridge.has_nss_dip() == false) return; application->pause = true; - auto info = SNES::cartridge.information.nss; + auto info = SFC::cartridge.information.nss; unsigned count = info.setting.size(); for(unsigned n = 0; n < min(8, count); n++) { @@ -55,7 +55,7 @@ void DipSwitches::load() { } void DipSwitches::accept() { - auto info = SNES::cartridge.information.nss; + auto info = SFC::cartridge.information.nss; unsigned count = info.setting.size(); unsigned result = 0x0000; @@ -64,6 +64,6 @@ void DipSwitches::accept() { } setVisible(false); - SNES::nss.set_dip(result); + SFC::nss.set_dip(result); application->pause = false; } diff --git a/bsnes/target-ui/input/snes.cpp b/bsnes/target-ui/input/snes.cpp index efc2231b..0b558510 100755 --- a/bsnes/target-ui/input/snes.cpp +++ b/bsnes/target-ui/input/snes.cpp @@ -1,17 +1,17 @@ int16_t SnesGamepad::poll(unsigned n) { - switch((SNES::Input::JoypadID)n) { - case SNES::Input::JoypadID::Up: return up.poll() & !down.poll(); - case SNES::Input::JoypadID::Down: return down.poll() & !up.poll(); - case SNES::Input::JoypadID::Left: return left.poll() & !right.poll(); - case SNES::Input::JoypadID::Right: return right.poll() & !left.poll(); - case SNES::Input::JoypadID::B: return b.poll() | bTurbo.poll(); - case SNES::Input::JoypadID::A: return a.poll() | aTurbo.poll(); - case SNES::Input::JoypadID::Y: return y.poll() | yTurbo.poll(); - case SNES::Input::JoypadID::X: return x.poll() | xTurbo.poll(); - case SNES::Input::JoypadID::L: return l.poll() | lTurbo.poll(); - case SNES::Input::JoypadID::R: return r.poll() | rTurbo.poll(); - case SNES::Input::JoypadID::Select: return select.poll(); - case SNES::Input::JoypadID::Start: return start.poll(); + switch((SFC::Input::JoypadID)n) { + case SFC::Input::JoypadID::Up: return up.poll() & !down.poll(); + case SFC::Input::JoypadID::Down: return down.poll() & !up.poll(); + case SFC::Input::JoypadID::Left: return left.poll() & !right.poll(); + case SFC::Input::JoypadID::Right: return right.poll() & !left.poll(); + case SFC::Input::JoypadID::B: return b.poll() | bTurbo.poll(); + case SFC::Input::JoypadID::A: return a.poll() | aTurbo.poll(); + case SFC::Input::JoypadID::Y: return y.poll() | yTurbo.poll(); + case SFC::Input::JoypadID::X: return x.poll() | xTurbo.poll(); + case SFC::Input::JoypadID::L: return l.poll() | lTurbo.poll(); + case SFC::Input::JoypadID::R: return r.poll() | rTurbo.poll(); + case SFC::Input::JoypadID::Select: return select.poll(); + case SFC::Input::JoypadID::Start: return start.poll(); } return 0; } @@ -47,11 +47,11 @@ SnesGamepad::SnesGamepad(const string &name, bool defaultBindings) { // int16_t SnesMouse::poll(unsigned n) { - switch((SNES::Input::MouseID)n) { - case SNES::Input::MouseID::X: return xaxis.poll(); - case SNES::Input::MouseID::Y: return yaxis.poll(); - case SNES::Input::MouseID::Left: return left.poll(); - case SNES::Input::MouseID::Right: return right.poll(); + switch((SFC::Input::MouseID)n) { + case SFC::Input::MouseID::X: return xaxis.poll(); + case SFC::Input::MouseID::Y: return yaxis.poll(); + case SFC::Input::MouseID::Left: return left.poll(); + case SFC::Input::MouseID::Right: return right.poll(); } return 0; } @@ -75,13 +75,13 @@ SnesMouse::SnesMouse(const string &name, bool defaultBindings) { // int16_t SnesSuperScope::poll(unsigned n) { - switch((SNES::Input::SuperScopeID)n) { - case SNES::Input::SuperScopeID::X: return xaxis.poll(); - case SNES::Input::SuperScopeID::Y: return yaxis.poll(); - case SNES::Input::SuperScopeID::Trigger: return trigger.poll(); - case SNES::Input::SuperScopeID::Cursor: return cursor.poll(); - case SNES::Input::SuperScopeID::Turbo: return turbo.poll(); - case SNES::Input::SuperScopeID::Pause: return pause.poll(); + switch((SFC::Input::SuperScopeID)n) { + case SFC::Input::SuperScopeID::X: return xaxis.poll(); + case SFC::Input::SuperScopeID::Y: return yaxis.poll(); + case SFC::Input::SuperScopeID::Trigger: return trigger.poll(); + case SFC::Input::SuperScopeID::Cursor: return cursor.poll(); + case SFC::Input::SuperScopeID::Turbo: return turbo.poll(); + case SFC::Input::SuperScopeID::Pause: return pause.poll(); } return 0; } @@ -107,11 +107,11 @@ SnesSuperScope::SnesSuperScope(const string &name, bool defaultBindings) { // int16_t SnesJustifier::poll(unsigned n) { - switch((SNES::Input::JustifierID)n) { - case SNES::Input::JustifierID::X: return xaxis.poll(); - case SNES::Input::JustifierID::Y: return yaxis.poll(); - case SNES::Input::JustifierID::Trigger: return trigger.poll(); - case SNES::Input::JustifierID::Start: return start.poll(); + switch((SFC::Input::JustifierID)n) { + case SFC::Input::JustifierID::X: return xaxis.poll(); + case SFC::Input::JustifierID::Y: return yaxis.poll(); + case SFC::Input::JustifierID::Trigger: return trigger.poll(); + case SFC::Input::JustifierID::Start: return start.poll(); } return 0; } diff --git a/bsnes/target-ui/interface/gb/gb.cpp b/bsnes/target-ui/interface/gb/gb.cpp index 1c27967d..035e9ba1 100755 --- a/bsnes/target-ui/interface/gb/gb.cpp +++ b/bsnes/target-ui/interface/gb/gb.cpp @@ -40,10 +40,8 @@ bool InterfaceGB::loadCartridge(GB::System::Revision revision, const string &fil GB::system.power(); if(GB::cartridge.ramsize) { - filemap fp; - if(fp.open(interface->base.filename("save.ram", ".sav"), filemap::mode::read)) { - memcpy(GB::cartridge.ramdata, fp.data(), min(GB::cartridge.ramsize, fp.size())); - } + filestream fs{interface->base.filename("save.ram", ".sav")}; + fs.read(GB::cartridge.ramdata, min(GB::cartridge.ramsize, fs.size())); } GB::interface = this; diff --git a/bsnes/target-ui/interface/gba/gba.cpp b/bsnes/target-ui/interface/gba/gba.cpp index 4d85586f..b8b6ba70 100755 --- a/bsnes/target-ui/interface/gba/gba.cpp +++ b/bsnes/target-ui/interface/gba/gba.cpp @@ -38,10 +38,8 @@ bool InterfaceGBA::loadCartridge(const string &filename) { GBA::system.power(); if(GBA::cartridge.ram_size()) { - filemap fp; - if(fp.open(interface->base.filename("save.ram", ".sav"), filemap::mode::read)) { - memcpy(GBA::cartridge.ram_data(), fp.data(), min(GBA::cartridge.ram_size(), fp.size())); - } + filestream fs{interface->base.filename("save.ram", ".sav")}; + fs.read(GBA::cartridge.ram_data(), min(GBA::cartridge.ram_size(), fs.size())); } GBA::video.generate_palette(); diff --git a/bsnes/target-ui/interface/interface.cpp b/bsnes/target-ui/interface/interface.cpp index b28c8a7f..cc5298cb 100755 --- a/bsnes/target-ui/interface/interface.cpp +++ b/bsnes/target-ui/interface/interface.cpp @@ -42,12 +42,12 @@ string CartridgePath::title() const { void Interface::bindControllers() { switch(mode()) { - case Mode::NES: + case Mode::FC: nes.setController(0, config->nes.controllerPort1Device); nes.setController(1, config->nes.controllerPort2Device); break; - case Mode::SNES: + case Mode::SFC: snes.setController(0, config->snes.controllerPort1Device); snes.setController(1, config->snes.controllerPort2Device); break; @@ -56,8 +56,8 @@ void Interface::bindControllers() { void Interface::setController(unsigned port, unsigned device) { switch(mode()) { - case Mode::NES: return nes.setController(port, device); - case Mode::SNES: return snes.setController(port, device); + case Mode::FC: return nes.setController(port, device); + case Mode::SFC: return snes.setController(port, device); } } @@ -72,10 +72,10 @@ void Interface::updateDSP() { dspaudio.setVolume(config->audio.mute == false ? (double)config->audio.volume / 100.0 : 0.0); switch(mode()) { - case Mode::NES: return dspaudio.setFrequency(config->audio.frequencyNES); - case Mode::SNES: return dspaudio.setFrequency(config->audio.frequencySNES); - case Mode::GB: return dspaudio.setFrequency(config->audio.frequencyGB); - case Mode::GBA: return dspaudio.setFrequency(config->audio.frequencyGBA); + case Mode::FC: return dspaudio.setFrequency(config->audio.frequencyNES); + case Mode::SFC: return dspaudio.setFrequency(config->audio.frequencySNES); + case Mode::GB: return dspaudio.setFrequency(config->audio.frequencyGB); + case Mode::GBA: return dspaudio.setFrequency(config->audio.frequencyGBA); } } @@ -91,11 +91,11 @@ bool Interface::cartridgeLoaded() { void Interface::loadCartridge(Mode mode) { switch(mode) { - case Mode::NES: core = &nes; break; - case Mode::SNES: core = &snes; break; - case Mode::GB: core = &gb; break; - case Mode::GBA: core = &gba; break; - default: core = nullptr; break; + case Mode::FC: core = &nes; break; + case Mode::SFC: core = &snes; break; + case Mode::GB: core = &gb; break; + case Mode::GBA: core = &gba; break; + default: core = nullptr; break; } utility->setMode(this->mode = mode); @@ -185,19 +185,19 @@ void Interface::setCheatCodes(const lstring &list) { void Interface::updatePalette() { switch(mode()) { - case Mode::NES: return NES::video.generate_palette(); - case Mode::SNES: return SNES::video.generate_palette(); - case Mode::GB: return GB::video.generate_palette(); - case Mode::GBA: return GBA::video.generate_palette(); + case Mode::FC: return FC::video.generate_palette(); + case Mode::SFC: return SFC::video.generate_palette(); + case Mode::GB: return GB::video.generate_palette(); + case Mode::GBA: return GBA::video.generate_palette(); } } string Interface::sha256() { switch(mode()) { - case Mode::NES: return NES::cartridge.sha256(); - case Mode::SNES: return SNES::cartridge.sha256(); - case Mode::GB: return GB::cartridge.sha256(); - case Mode::GBA: return GBA::cartridge.sha256(); + case Mode::FC: return FC::cartridge.sha256(); + case Mode::SFC: return SFC::cartridge.sha256(); + case Mode::GB: return GB::cartridge.sha256(); + case Mode::GBA: return GBA::cartridge.sha256(); } return "{None}"; } @@ -252,7 +252,7 @@ void Interface::videoRefresh(const uint32_t *input, unsigned inputPitch, unsigne memcpy(output + y * outputPitch, input + y * inputPitch, width * sizeof(uint32_t)); } - if(config->video.maskOverscan && (mode() == Mode::NES || mode() == Mode::SNES)) { + if(config->video.maskOverscan && (mode() == Mode::FC || mode() == Mode::SFC)) { unsigned h = config->video.maskOverscanHorizontal; unsigned v = config->video.maskOverscanVertical; diff --git a/bsnes/target-ui/interface/interface.hpp b/bsnes/target-ui/interface/interface.hpp index e4584669..86552931 100755 --- a/bsnes/target-ui/interface/interface.hpp +++ b/bsnes/target-ui/interface/interface.hpp @@ -44,7 +44,7 @@ struct Filter : public library { extern Filter filter; struct Interface : property { - enum class Mode : unsigned { None, SNES, NES, GB, GBA }; + enum class Mode : unsigned { None, FC, SFC, GB, GBA }; readonly mode; void bindControllers(); diff --git a/bsnes/target-ui/interface/nes/nes.cpp b/bsnes/target-ui/interface/nes/nes.cpp index 4b97d33a..d4346952 100755 --- a/bsnes/target-ui/interface/nes/nes.cpp +++ b/bsnes/target-ui/interface/nes/nes.cpp @@ -1,10 +1,10 @@ void InterfaceNES::initialize() { - NES::interface = this; - NES::system.init(); + FC::interface = this; + FC::system.init(); } string InterfaceNES::markup() { - return NES::cartridge.information.markup; + return FC::cartridge.information.markup; } void InterfaceNES::setController(bool port, unsigned device) { @@ -12,18 +12,18 @@ void InterfaceNES::setController(bool port, unsigned device) { if(port == 1) config->nes.controllerPort2Device = device; if(port == 0) switch(device) { - case 0: return NES::input.connect(0, NES::Input::Device::None); - case 1: return NES::input.connect(0, NES::Input::Device::Joypad); + case 0: return FC::input.connect(0, FC::Input::Device::None); + case 1: return FC::input.connect(0, FC::Input::Device::Joypad); } if(port == 1) switch(device) { - case 0: return NES::input.connect(1, NES::Input::Device::None); - case 1: return NES::input.connect(1, NES::Input::Device::Joypad); + case 0: return FC::input.connect(1, FC::Input::Device::None); + case 1: return FC::input.connect(1, FC::Input::Device::Joypad); } } bool InterfaceNES::cartridgeLoaded() { - return NES::cartridge.loaded(); + return FC::cartridge.loaded(); } bool InterfaceNES::loadCartridge(const string &filename) { @@ -47,69 +47,67 @@ bool InterfaceNES::loadCartridge(const string &filename) { markup.readfile(interface->base.filename("manifest.xml", ".xml")); if(markup.empty()) markup = FamicomCartridge(memory.data(), memory.size()).markup; - NES::cartridge.load(markup, vectorstream{memory}); - NES::system.power(); + FC::cartridge.load(markup, vectorstream{memory}); + FC::system.power(); - if(NES::cartridge.ram_size()) { - filemap fp; - if(fp.open(interface->base.filename("save.ram", ".sav"), filemap::mode::read)) { - memcpy(NES::cartridge.ram_data(), fp.data(), min(NES::cartridge.ram_size(), fp.size())); - } + if(FC::cartridge.ram_size()) { + filestream fs{interface->base.filename("save.ram", ".sav")}; + fs.read(FC::cartridge.ram_data(), min(FC::cartridge.ram_size(), fs.size())); } - interface->loadCartridge(::Interface::Mode::NES); - NES::video.generate_palette(); + interface->loadCartridge(::Interface::Mode::FC); + FC::video.generate_palette(); return true; } void InterfaceNES::unloadCartridge() { - if(NES::cartridge.ram_size()) { - file::write(interface->base.filename("save.ram", ".sav"), NES::cartridge.ram_data(), NES::cartridge.ram_size()); + if(FC::cartridge.ram_size()) { + file::write(interface->base.filename("save.ram", ".sav"), FC::cartridge.ram_data(), FC::cartridge.ram_size()); } - NES::cartridge.unload(); + FC::cartridge.unload(); interface->base.name = ""; } // void InterfaceNES::power() { - NES::system.power(); + FC::system.power(); } void InterfaceNES::reset() { - NES::system.reset(); + FC::system.reset(); } void InterfaceNES::run() { - NES::system.run(); + FC::system.run(); } // serializer InterfaceNES::serialize() { - NES::system.runtosave(); - return NES::system.serialize(); + FC::system.runtosave(); + return FC::system.serialize(); } bool InterfaceNES::unserialize(serializer &s) { - return NES::system.unserialize(s); + return FC::system.unserialize(s); } // void InterfaceNES::setCheats(const lstring &list) { - NES::cheat.reset(); + FC::cheat.reset(); for(auto &code : list) { lstring codelist; codelist.split("+", code); for(auto &part : codelist) { unsigned addr, data, comp; - if(NES::Cheat::decode(part, addr, data, comp)) { - NES::cheat.append({ addr, data, comp }); + if(FC::Cheat::decode(part, addr, data, comp)) { + FC::cheat.append({ addr, data, comp }); } } } - NES::cheat.synchronize(); + FC::cheat.synchronize(); } // diff --git a/bsnes/target-ui/interface/nes/nes.hpp b/bsnes/target-ui/interface/nes/nes.hpp index c3b3343d..c9ae14c3 100755 --- a/bsnes/target-ui/interface/nes/nes.hpp +++ b/bsnes/target-ui/interface/nes/nes.hpp @@ -1,4 +1,4 @@ -struct InterfaceNES : InterfaceCore, NES::Interface { +struct InterfaceNES : InterfaceCore, FC::Interface { void initialize(); string markup(); diff --git a/bsnes/target-ui/interface/snes/snes.cpp b/bsnes/target-ui/interface/snes/snes.cpp index fea9249c..09529ecc 100755 --- a/bsnes/target-ui/interface/snes/snes.cpp +++ b/bsnes/target-ui/interface/snes/snes.cpp @@ -1,12 +1,12 @@ void InterfaceSNES::initialize() { - loadFirmware("Super Famicom.sys/manifest.xml", "system.smp", SNES::smp.iplrom, 64u); + loadFirmware("Super Famicom.sys/manifest.xml", "system.smp", SFC::smp.iplrom, 64u); - SNES::interface = this; - SNES::system.init(); + SFC::interface = this; + SFC::system.init(); } string InterfaceSNES::markup() { - return SNES::cartridge.information.markup; + return SFC::cartridge.information.markup; } void InterfaceSNES::setController(bool port, unsigned device) { @@ -14,27 +14,27 @@ void InterfaceSNES::setController(bool port, unsigned device) { if(port == 1) config->snes.controllerPort2Device = device; if(port == 0) switch(device) { default: - case 0: return SNES::input.connect(0, SNES::Input::Device::None); - case 1: return SNES::input.connect(0, SNES::Input::Device::Joypad); - case 2: return SNES::input.connect(0, SNES::Input::Device::Multitap); - case 3: return SNES::input.connect(0, SNES::Input::Device::Mouse); - case 4: return SNES::input.connect(0, SNES::Input::Device::USART); + case 0: return SFC::input.connect(0, SFC::Input::Device::None); + case 1: return SFC::input.connect(0, SFC::Input::Device::Joypad); + case 2: return SFC::input.connect(0, SFC::Input::Device::Multitap); + case 3: return SFC::input.connect(0, SFC::Input::Device::Mouse); + case 4: return SFC::input.connect(0, SFC::Input::Device::USART); } if(port == 1) switch(device) { default: - case 0: return SNES::input.connect(1, SNES::Input::Device::None); - case 1: return SNES::input.connect(1, SNES::Input::Device::Joypad); - case 2: return SNES::input.connect(1, SNES::Input::Device::Multitap); - case 3: return SNES::input.connect(1, SNES::Input::Device::Mouse); - case 4: return SNES::input.connect(1, SNES::Input::Device::SuperScope); - case 5: return SNES::input.connect(1, SNES::Input::Device::Justifier); - case 6: return SNES::input.connect(1, SNES::Input::Device::Justifiers); - case 7: return SNES::input.connect(1, SNES::Input::Device::USART); + case 0: return SFC::input.connect(1, SFC::Input::Device::None); + case 1: return SFC::input.connect(1, SFC::Input::Device::Joypad); + case 2: return SFC::input.connect(1, SFC::Input::Device::Multitap); + case 3: return SFC::input.connect(1, SFC::Input::Device::Mouse); + case 4: return SFC::input.connect(1, SFC::Input::Device::SuperScope); + case 5: return SFC::input.connect(1, SFC::Input::Device::Justifier); + case 6: return SFC::input.connect(1, SFC::Input::Device::Justifiers); + case 7: return SFC::input.connect(1, SFC::Input::Device::USART); } } bool InterfaceSNES::cartridgeLoaded() { - return SNES::cartridge.loaded(); + return SFC::cartridge.loaded(); } vector InterfaceSNES::loadCartridge(const string &filename, CartridgePath &cartridge) { @@ -66,13 +66,13 @@ bool InterfaceSNES::loadCartridge(string basename) { markup.readfile(interface->base.filename("manifest.xml", ".xml")); if(markup.empty()) markup = SuperFamicomCartridge(memory.data(), memory.size()).markup; - SNES::cartridge.rom.copy(memory.data(), memory.size()); - SNES::cartridge.load(SNES::Cartridge::Mode::Normal, markup); - SNES::system.power(); + SFC::cartridge.rom.copy(vectorstream{memory}); + SFC::cartridge.load(SFC::Cartridge::Mode::Normal, markup); + SFC::system.power(); loadMemory(); - interface->loadCartridge(::Interface::Mode::SNES); - SNES::video.generate_palette(); + interface->loadCartridge(::Interface::Mode::SFC); + SFC::video.generate_palette(); return true; } @@ -91,14 +91,14 @@ bool InterfaceSNES::loadSatellaviewSlottedCartridge(string basename, string slot markup.readfile(interface->base.filename("manifest.xml", ".xml")); if(markup.empty()) markup = SuperFamicomCartridge(memory.data(), memory.size()).markup; - SNES::cartridge.rom.copy(memory.data(), memory.size()); - if(memoryBS) SNES::bsxflash.memory.copy(memoryBS.data(), memoryBS.size()); - SNES::cartridge.load(SNES::Cartridge::Mode::BsxSlotted, markup); - SNES::system.power(); + SFC::cartridge.rom.copy(vectorstream{memory}); + if(memoryBS) SFC::bsxflash.memory.copy(vectorstream{memoryBS}); + SFC::cartridge.load(SFC::Cartridge::Mode::BsxSlotted, markup); + SFC::system.power(); loadMemory(); - interface->loadCartridge(::Interface::Mode::SNES); - SNES::video.generate_palette(); + interface->loadCartridge(::Interface::Mode::SFC); + SFC::video.generate_palette(); return true; } @@ -117,14 +117,14 @@ bool InterfaceSNES::loadSatellaviewCartridge(string basename, string slotname) { markup.readfile(interface->base.filename("manifest.xml", ".xml")); if(markup.empty()) markup = SuperFamicomCartridge(memory.data(), memory.size()).markup; - SNES::cartridge.rom.copy(memory.data(), memory.size()); - if(memoryBS) SNES::bsxflash.memory.copy(memoryBS.data(), memoryBS.size()); - SNES::cartridge.load(SNES::Cartridge::Mode::Bsx, markup); - SNES::system.power(); + SFC::cartridge.rom.copy(vectorstream{memory}); + if(memoryBS) SFC::bsxflash.memory.copy(vectorstream{memoryBS}); + SFC::cartridge.load(SFC::Cartridge::Mode::Bsx, markup); + SFC::system.power(); loadMemory(); - interface->loadCartridge(::Interface::Mode::SNES); - SNES::video.generate_palette(); + interface->loadCartridge(::Interface::Mode::SFC); + SFC::video.generate_palette(); return true; } @@ -148,15 +148,15 @@ bool InterfaceSNES::loadSufamiTurboCartridge(string basename, string slotAname, markup.readfile(interface->base.filename("manifest.xml", ".xml")); if(markup.empty()) markup = SuperFamicomCartridge(memory.data(), memory.size()).markup; - SNES::cartridge.rom.copy(memory.data(), memory.size()); - if(memorySTA) SNES::sufamiturbo.slotA.rom.copy(memory.data(), memory.size()); - if(memorySTB) SNES::sufamiturbo.slotB.rom.copy(memory.data(), memory.size()); - SNES::cartridge.load(SNES::Cartridge::Mode::SufamiTurbo, markup); - SNES::system.power(); + SFC::cartridge.rom.copy(vectorstream{memory}); + if(memorySTA) SFC::sufamiturbo.slotA.rom.copy(vectorstream{memory}); + if(memorySTB) SFC::sufamiturbo.slotB.rom.copy(vectorstream{memory}); + SFC::cartridge.load(SFC::Cartridge::Mode::SufamiTurbo, markup); + SFC::system.power(); loadMemory(); - interface->loadCartridge(::Interface::Mode::SNES); - SNES::video.generate_palette(); + interface->loadCartridge(::Interface::Mode::SFC); + SFC::video.generate_palette(); return true; } @@ -179,53 +179,53 @@ bool InterfaceSNES::loadSuperGameBoyCartridge(string basename, string slotname) gbMarkup.readfile(interface->slot[0].filename("manifest.xml", ".xml")); if(gbMarkup.empty()) gbMarkup = GameBoyCartridge(memoryGB.data(), memoryGB.size()).markup; - SNES::cartridge.rom.copy(memory.data(), memory.size()); + SFC::cartridge.rom.copy(vectorstream{memory}); GB::cartridge.load(GB::System::Revision::SuperGameBoy, gbMarkup, vectorstream{memoryGB}); - SNES::cartridge.load(SNES::Cartridge::Mode::SuperGameBoy, markup); - SNES::system.power(); + SFC::cartridge.load(SFC::Cartridge::Mode::SuperGameBoy, markup); + SFC::system.power(); loadMemory(); - interface->loadCartridge(::Interface::Mode::SNES); - SNES::video.generate_palette(); + interface->loadCartridge(::Interface::Mode::SFC); + SFC::video.generate_palette(); return true; } void InterfaceSNES::unloadCartridge() { saveMemory(); - SNES::cartridge.unload(); + SFC::cartridge.unload(); } void InterfaceSNES::power() { - SNES::system.power(); + SFC::system.power(); } void InterfaceSNES::reset() { - SNES::system.reset(); + SFC::system.reset(); } void InterfaceSNES::run() { - SNES::system.run(); + SFC::system.run(); } -string InterfaceSNES::memoryName(SNES::Cartridge::NonVolatileRAM &memory) { - if(memory.slot == SNES::Cartridge::Slot::Base) { +string InterfaceSNES::memoryName(SFC::Cartridge::NonVolatileRAM &memory) { + if(memory.slot == SFC::Cartridge::Slot::Base) { if(memory.id == "save.ram") return interface->base.filename("save.ram", ".srm"); if(memory.id == "rtc.ram") return interface->base.filename("rtc.ram", ".rtc"); if(memory.id == "upd96050.ram") return interface->base.filename("upd96050.ram", ".nec"); if(memory.id == "bsx.ram") return interface->base.filename("bsx.ram", ".bss"); if(memory.id == "bsx.psram") return interface->base.filename("bsx.psram", ".bsp"); } - if(memory.slot == SNES::Cartridge::Slot::SufamiTurboA) { + if(memory.slot == SFC::Cartridge::Slot::SufamiTurboA) { if(memory.id == "save.ram") return interface->slot[0].filename("save.ram", ".sts"); } - if(memory.slot == SNES::Cartridge::Slot::SufamiTurboB) { + if(memory.slot == SFC::Cartridge::Slot::SufamiTurboB) { if(memory.id == "save.ram") return interface->slot[1].filename("save.ram", ".sts"); } return ""; } void InterfaceSNES::loadMemory() { - for(auto &memory : SNES::cartridge.nvram) { + for(auto &memory : SFC::cartridge.nvram) { if(memory.size == 0) continue; string filename = memoryName(memory); @@ -236,17 +236,16 @@ void InterfaceSNES::loadMemory() { } } - if(SNES::cartridge.mode() == SNES::Cartridge::Mode::SuperGameBoy) { + if(SFC::cartridge.mode() == SFC::Cartridge::Mode::SuperGameBoy) { if(GB::cartridge.ramsize) { - if(auto read = file::read(interface->slot[0].filename("save.ram", ".sav"))) { - memcpy(GB::cartridge.ramdata, read.data(), min(GB::cartridge.ramsize, read.size())); - } + filestream fs{interface->slot[0].filename("save.ram", ".sav")}; + fs.read(GB::cartridge.ramdata, min(GB::cartridge.ramsize, fs.size())); } } } void InterfaceSNES::saveMemory() { - for(auto &memory : SNES::cartridge.nvram) { + for(auto &memory : SFC::cartridge.nvram) { if(memory.size == 0) continue; string filename = memoryName(memory); @@ -255,7 +254,7 @@ void InterfaceSNES::saveMemory() { file::write(filename, memory.data, memory.size); } - if(SNES::cartridge.mode() == SNES::Cartridge::Mode::SuperGameBoy) { + if(SFC::cartridge.mode() == SFC::Cartridge::Mode::SuperGameBoy) { if(GB::cartridge.ramsize) { file::write(interface->slot[0].filename("save.ram", ".sav"), GB::cartridge.ramdata, GB::cartridge.ramsize @@ -265,16 +264,16 @@ void InterfaceSNES::saveMemory() { } serializer InterfaceSNES::serialize() { - SNES::system.runtosave(); - return SNES::system.serialize(); + SFC::system.runtosave(); + return SFC::system.serialize(); } bool InterfaceSNES::unserialize(serializer &s) { - return SNES::system.unserialize(s); + return SFC::system.unserialize(s); } void InterfaceSNES::setCheats(const lstring &list) { - if(SNES::cartridge.mode() == SNES::Cartridge::Mode::SuperGameBoy) { + if(SFC::cartridge.mode() == SFC::Cartridge::Mode::SuperGameBoy) { GB::cheat.reset(); for(auto &code : list) { lstring codelist; @@ -290,18 +289,18 @@ void InterfaceSNES::setCheats(const lstring &list) { return; } - SNES::cheat.reset(); + SFC::cheat.reset(); for(auto &code : list) { lstring codelist; codelist.split("+", code); for(auto &part : codelist) { unsigned addr, data; - if(SNES::Cheat::decode(part, addr, data)) { - SNES::cheat.append({ addr, data }); + if(SFC::Cheat::decode(part, addr, data)) { + SFC::cheat.append({ addr, data }); } } } - SNES::cheat.synchronize(); + SFC::cheat.synchronize(); } // @@ -331,30 +330,30 @@ void InterfaceSNES::audioSample(int16_t lsample, int16_t rsample) { } } -int16_t InterfaceSNES::inputPoll(bool port, SNES::Input::Device device, unsigned index, unsigned id) { +int16_t InterfaceSNES::inputPoll(bool port, SFC::Input::Device device, unsigned index, unsigned id) { if(port == 0) { - if(device == SNES::Input::Device::Joypad) return inputManager->snes.port1.gamepad.poll(id); - if(device == SNES::Input::Device::Multitap) { + if(device == SFC::Input::Device::Joypad) return inputManager->snes.port1.gamepad.poll(id); + if(device == SFC::Input::Device::Multitap) { if(index == 0) return inputManager->snes.port1.multitap1.poll(id); if(index == 1) return inputManager->snes.port1.multitap2.poll(id); if(index == 2) return inputManager->snes.port1.multitap3.poll(id); if(index == 3) return inputManager->snes.port1.multitap4.poll(id); } - if(device == SNES::Input::Device::Mouse) return inputManager->snes.port1.mouse.poll(id); + if(device == SFC::Input::Device::Mouse) return inputManager->snes.port1.mouse.poll(id); } if(port == 1) { - if(device == SNES::Input::Device::Joypad) return inputManager->snes.port2.gamepad.poll(id); - if(device == SNES::Input::Device::Multitap) { + if(device == SFC::Input::Device::Joypad) return inputManager->snes.port2.gamepad.poll(id); + if(device == SFC::Input::Device::Multitap) { if(index == 0) return inputManager->snes.port2.multitap1.poll(id); if(index == 1) return inputManager->snes.port2.multitap2.poll(id); if(index == 2) return inputManager->snes.port2.multitap3.poll(id); if(index == 3) return inputManager->snes.port2.multitap4.poll(id); } - if(device == SNES::Input::Device::Mouse) return inputManager->snes.port2.mouse.poll(id); - if(device == SNES::Input::Device::SuperScope) return inputManager->snes.port2.superScope.poll(id); - if(device == SNES::Input::Device::Justifier) return inputManager->snes.port2.justifier1.poll(id); - if(device == SNES::Input::Device::Justifiers) { + if(device == SFC::Input::Device::Mouse) return inputManager->snes.port2.mouse.poll(id); + if(device == SFC::Input::Device::SuperScope) return inputManager->snes.port2.superScope.poll(id); + if(device == SFC::Input::Device::Justifier) return inputManager->snes.port2.justifier1.poll(id); + if(device == SFC::Input::Device::Justifiers) { if(index == 0) return inputManager->snes.port2.justifier1.poll(id); if(index == 1) return inputManager->snes.port2.justifier2.poll(id); } @@ -363,8 +362,8 @@ int16_t InterfaceSNES::inputPoll(bool port, SNES::Input::Device device, unsigned return 0; } -string InterfaceSNES::path(SNES::Cartridge::Slot slot, const string &hint) { - if(slot == SNES::Cartridge::Slot::Base) { +string InterfaceSNES::path(SFC::Cartridge::Slot slot, const string &hint) { + if(slot == SFC::Cartridge::Slot::Base) { if(hint == "msu1.rom") return interface->base.filename("msu1.rom", ".msu"); if(hint.wildcard("track-*.pcm")) { string track = hint; diff --git a/bsnes/target-ui/interface/snes/snes.hpp b/bsnes/target-ui/interface/snes/snes.hpp index 642c31fe..77ada301 100755 --- a/bsnes/target-ui/interface/snes/snes.hpp +++ b/bsnes/target-ui/interface/snes/snes.hpp @@ -1,4 +1,4 @@ -struct InterfaceSNES : InterfaceCore, SNES::Interface { +struct InterfaceSNES : InterfaceCore, SFC::Interface { void initialize(); string markup(); @@ -18,7 +18,7 @@ struct InterfaceSNES : InterfaceCore, SNES::Interface { void reset(); void run(); - string memoryName(SNES::Cartridge::NonVolatileRAM &memory); + string memoryName(SFC::Cartridge::NonVolatileRAM &memory); void loadMemory(); void saveMemory(); @@ -30,8 +30,8 @@ struct InterfaceSNES : InterfaceCore, SNES::Interface { uint32_t videoColor(uint19_t source, uint16_t red, uint16_t green, uint16_t blue); void videoRefresh(const uint32_t *data, bool hires, bool interlace, bool overscan); void audioSample(int16_t lsample, int16_t rsample); - int16_t inputPoll(bool port, SNES::Input::Device device, unsigned index, unsigned id); + int16_t inputPoll(bool port, SFC::Input::Device device, unsigned index, unsigned id); - string path(SNES::Cartridge::Slot slot, const string &hint); + string path(SFC::Cartridge::Slot slot, const string &hint); void message(const string &text); }; diff --git a/bsnes/target-ui/utility/utility.cpp b/bsnes/target-ui/utility/utility.cpp index cd3dcb2c..e11137f9 100755 --- a/bsnes/target-ui/utility/utility.cpp +++ b/bsnes/target-ui/utility/utility.cpp @@ -17,13 +17,13 @@ void Utility::setMode(Interface::Mode mode) { stateManager->reset(); } - else if(mode == Interface::Mode::NES) { + else if(mode == Interface::Mode::FC) { mainWindow->setTitle(interface->cartridgeTitle); mainWindow->nesMenu.setVisible(true); dspaudio.setChannels(1); } - else if(mode == Interface::Mode::SNES) { + else if(mode == Interface::Mode::SFC) { mainWindow->setTitle(interface->cartridgeTitle); mainWindow->snesMenu.setVisible(true); dspaudio.setChannels(2); @@ -56,15 +56,15 @@ void Utility::resizeMainWindow(bool shrink) { switch(interface->mode()) { case Interface::Mode::None: return mainWindow->viewport.setGeometry({ 0, 0, 1, 1 }); - case Interface::Mode::NES: width = 256, height = 240; break; - case Interface::Mode::SNES: width = 256, height = 240; break; + case Interface::Mode::FC: width = 256, height = 240; break; + case Interface::Mode::SFC: width = 256, height = 240; break; case Interface::Mode::GB: width = 160, height = 144; break; case Interface::Mode::GBA: width = 240, height = 160; break; } if(config->video.correctAspectRatio) { - if(interface->mode() == Interface::Mode::NES - || interface->mode() == Interface::Mode::SNES + if(interface->mode() == Interface::Mode::FC + || interface->mode() == Interface::Mode::SFC ) width = (double)width * 8.0 / 7.0; }