things
This commit is contained in:
@@ -2,46 +2,49 @@
|
||||
#include <Scheduler.hpp>
|
||||
|
||||
namespace n64 {
|
||||
Core::Core() : cpu{new Interpreter} {
|
||||
Core::Core() {
|
||||
if(SDL_GameControllerAddMappingsFromFile("resources/gamecontrollerdb.txt") < 0) {
|
||||
Util::warn("Failed to load game controller DB");
|
||||
}
|
||||
}
|
||||
|
||||
void Core::Stop() {
|
||||
cpu->Reset();
|
||||
cpu->mem.Reset();
|
||||
cpu.Reset();
|
||||
cpu.mem.Reset();
|
||||
pause = true;
|
||||
romLoaded = false;
|
||||
}
|
||||
|
||||
void Core::LoadROM(const std::string& rom_) {
|
||||
rom = rom_;
|
||||
cpu->Reset();
|
||||
cpu.Reset();
|
||||
pause = false;
|
||||
romLoaded = true;
|
||||
|
||||
auto extension = fs::path(rom).extension().string();
|
||||
bool isArchive = false;
|
||||
for(const auto i : ARCHIVE_TYPES) {
|
||||
if(extension == i) {
|
||||
isArchive = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool isArchive = std::any_of(std::begin(ARCHIVE_TYPES), std::end(ARCHIVE_TYPES), [&](auto i) {
|
||||
return extension == i;
|
||||
});
|
||||
|
||||
cpu->mem.LoadROM(isArchive, rom);
|
||||
GameDB::match(cpu->mem);
|
||||
cpu->mem.mmio.vi.isPal = cpu->mem.IsROMPAL();
|
||||
cpu->mem.mmio.si.pif.InitDevices(cpu->mem.saveType);
|
||||
cpu->mem.mmio.si.pif.LoadMempak(rom);
|
||||
cpu->mem.mmio.si.pif.LoadEeprom(cpu->mem.saveType, rom);
|
||||
cpu->mem.flash.Load(cpu->mem.saveType, rom);
|
||||
cpu->mem.LoadSRAM(cpu->mem.saveType, rom);
|
||||
PIF::ExecutePIF(cpu->mem, cpu->regs);
|
||||
cpu.mem.LoadROM(isArchive, rom);
|
||||
GameDB::match(cpu.mem);
|
||||
cpu.mem.mmio.vi.isPal = cpu.mem.IsROMPAL();
|
||||
cpu.mem.mmio.si.pif.InitDevices(cpu.mem.saveType);
|
||||
cpu.mem.mmio.si.pif.LoadMempak(rom);
|
||||
cpu.mem.mmio.si.pif.LoadEeprom(cpu.mem.saveType, rom);
|
||||
cpu.mem.flash.Load(cpu.mem.saveType, rom);
|
||||
cpu.mem.LoadSRAM(cpu.mem.saveType, rom);
|
||||
PIF::ExecutePIF(cpu.mem, cpu.regs);
|
||||
}
|
||||
|
||||
void Core::Run(float volumeL, float volumeR) {
|
||||
Mem& mem = cpu->mem;
|
||||
Mem& mem = cpu.mem;
|
||||
MMIO& mmio = mem.mmio;
|
||||
Registers& regs = cpu->regs;
|
||||
Registers& regs = cpu.regs;
|
||||
|
||||
for (int field = 0; field < mmio.vi.numFields; field++) {
|
||||
int frameCycles = 0;
|
||||
@@ -53,7 +56,7 @@ void Core::Run(float volumeL, float volumeR) {
|
||||
}
|
||||
|
||||
for(; cycles < mem.mmio.vi.cyclesPerHalfline; cycles++, frameCycles++) {
|
||||
int taken = cpu->Step();
|
||||
int taken = cpu.Step();
|
||||
static int cpuSteps = 0;
|
||||
cpuSteps += taken;
|
||||
if(mmio.rsp.spStatus.halt) {
|
||||
@@ -83,7 +86,7 @@ void Core::Run(float volumeL, float volumeR) {
|
||||
InterruptRaise(mmio.mi, regs, Interrupt::VI);
|
||||
}
|
||||
|
||||
mmio.ai.Step(cpu->mem, regs, frameCycles, volumeL, volumeR);
|
||||
mmio.ai.Step(cpu.mem, regs, frameCycles, volumeL, volumeR);
|
||||
scheduler.tick(frameCycles, mem, regs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,13 +8,13 @@ struct Window;
|
||||
|
||||
namespace n64 {
|
||||
struct Core {
|
||||
~Core() { Stop(); delete cpu; }
|
||||
~Core() { Stop(); }
|
||||
Core();
|
||||
void Stop();
|
||||
void LoadROM(const std::string&);
|
||||
void Run(float volumeL, float volumeR);
|
||||
void TogglePause() { pause = !pause; }
|
||||
[[nodiscard]] VI& GetVI() const { return cpu->mem.mmio.vi; }
|
||||
[[nodiscard]] VI& GetVI() { return cpu.mem.mmio.vi; }
|
||||
|
||||
u32 breakpoint = 0;
|
||||
|
||||
@@ -22,6 +22,6 @@ struct Core {
|
||||
int cycles = 0;
|
||||
bool romLoaded = false;
|
||||
std::string rom;
|
||||
Interpreter* cpu = nullptr;
|
||||
Interpreter cpu;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ App::App() : window(core) {
|
||||
|
||||
void App::Run() {
|
||||
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
|
||||
n64::SI& si = core.cpu->mem.mmio.si;
|
||||
n64::SI& si = core.cpu.mem.mmio.si;
|
||||
|
||||
while (!window.done) {
|
||||
if(core.romLoaded) {
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace fs = std::filesystem;
|
||||
|
||||
Window::Window(n64::Core& core) : settings() {
|
||||
InitSDL();
|
||||
InitParallelRDP(core.cpu->mem.GetRDRAM(), window);
|
||||
InitParallelRDP(core.cpu.mem.GetRDRAM(), window);
|
||||
InitImgui();
|
||||
NFD::Init();
|
||||
}
|
||||
@@ -152,7 +152,7 @@ ImDrawData* Window::Present(n64::Core& core) {
|
||||
void Window::LoadROM(n64::Core& core, const std::string &path) {
|
||||
if(!path.empty()) {
|
||||
core.LoadROM(path);
|
||||
gameName = core.cpu->mem.rom.gameNameDB;
|
||||
gameName = core.cpu.mem.rom.gameNameDB;
|
||||
|
||||
if(gameName.empty()) {
|
||||
gameName = fs::path(path).stem().string();
|
||||
@@ -181,13 +181,13 @@ void Window::RenderMainMenuBar(n64::Core &core) {
|
||||
}
|
||||
}
|
||||
if (ImGui::MenuItem("Dump RDRAM")) {
|
||||
core.cpu->mem.DumpRDRAM();
|
||||
core.cpu.mem.DumpRDRAM();
|
||||
}
|
||||
if (ImGui::MenuItem("Dump IMEM")) {
|
||||
core.cpu->mem.DumpIMEM();
|
||||
core.cpu.mem.DumpIMEM();
|
||||
}
|
||||
if (ImGui::MenuItem("Dump DMEM")) {
|
||||
core.cpu->mem.DumpDMEM();
|
||||
core.cpu.mem.DumpDMEM();
|
||||
}
|
||||
if (ImGui::MenuItem("Exit")) {
|
||||
done = true;
|
||||
@@ -232,8 +232,8 @@ void Window::Render(n64::Core& core) {
|
||||
static u32 lastFrame = 0;
|
||||
if(!core.pause && lastFrame < ticks - 1000) {
|
||||
lastFrame = ticks;
|
||||
windowTitle += fmt::format(" | {:02d} VI/s", core.cpu->mem.mmio.vi.swaps);
|
||||
core.cpu->mem.mmio.vi.swaps = 0;
|
||||
windowTitle += fmt::format(" | {:02d} VI/s", core.cpu.mem.mmio.vi.swaps);
|
||||
core.cpu.mem.mmio.vi.swaps = 0;
|
||||
SDL_SetWindowTitle(window, windowTitle.c_str());
|
||||
windowTitle = shadowWindowTitle;
|
||||
}
|
||||
|
||||
@@ -2,16 +2,18 @@
|
||||
#include <MupenMovie.hpp>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
App app;
|
||||
App* app = new App;
|
||||
|
||||
if(argc > 1) {
|
||||
if(argc > 2) {
|
||||
LoadTAS(argv[2]);
|
||||
}
|
||||
app.LoadROM(argv[1]);
|
||||
app->LoadROM(argv[1]);
|
||||
}
|
||||
|
||||
app.Run();
|
||||
app->Run();
|
||||
|
||||
delete app;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user