properly reset a lot of the emulator state

This commit is contained in:
SimoneN64
2024-06-21 22:25:50 +02:00
parent 3e36dbc4bb
commit f4a4aebbee
22 changed files with 71 additions and 31 deletions

View File

@@ -13,8 +13,8 @@ void AI::Reset() {
dmaCount = 0;
dmaAddrCarry = false;
cycles = 0;
memset(dmaLen, 0, 2);
memset(dmaAddr, 0, 2);
dmaLen = {};
dmaAddr = {};
dac = {44100, N64_CPU_FREQ / dac.freq, 16};
}

View File

@@ -1,6 +1,5 @@
#pragma once
#include <common.hpp>
#include <core/mmio/Interrupt.hpp>
#include <core/mmio/Audio.hpp>
namespace n64 {
@@ -17,8 +16,8 @@ struct AI {
u16 dacRate{};
u8 bitrate{};
int dmaCount{};
u32 dmaLen[2]{};
u32 dmaAddr[2]{};
std::array<u32, 2> dmaLen{};
std::array<u32, 2> dmaAddr{};
bool dmaAddrCarry{};
u32 cycles{};
AudioDevice device;

View File

@@ -1,4 +1,3 @@
#include <core/mmio/Interrupt.hpp>
#include <core/mmio/MI.hpp>
#include <core/registers/Registers.hpp>

View File

@@ -1,9 +0,0 @@
#pragma once
#include <common.hpp>
#include <core/mmio/MI.hpp>
namespace n64 {
struct Registers;
}

View File

@@ -1,7 +1,6 @@
#include <core/mmio/MI.hpp>
#include <core/registers/Registers.hpp>
#include <log.hpp>
#include <core/mmio/Interrupt.hpp>
#define MI_VERSION_REG 0x02020102

View File

@@ -9,6 +9,7 @@ PI::PI(Mem& mem, Registers& regs) : mem(mem), regs(regs) {
}
void PI::Reset() {
toCart = false;
dmaBusy = false;
ioBusy = false;
latch = 0;

View File

@@ -1,6 +1,5 @@
#pragma once
#include <common.hpp>
#include <core/mmio/Interrupt.hpp>
namespace n64 {

View File

@@ -10,9 +10,9 @@
namespace n64 {
void PIF::Reset() {
memset(joybusDevices, 0, sizeof(JoybusDevice) * 6);
memset(bootrom, 0, PIF_BOOTROM_SIZE);
memset(ram, 0, PIF_RAM_SIZE);
joybusDevices = {};
bootrom = {};
ram = {};
std::error_code error;
if(mempak.is_mapped()) {
mempak.sync(error);
@@ -26,6 +26,7 @@ void PIF::Reset() {
}
mempakOpen = false;
channel = 0;
}
void PIF::MaybeLoadMempak() {
@@ -630,11 +631,11 @@ std::vector<u8> PIF::Serialize() {
sizeof(int));
u32 index = 0;
memcpy(res.data() + index, joybusDevices, 6*sizeof(JoybusDevice));
memcpy(res.data() + index, joybusDevices.data(), 6*sizeof(JoybusDevice));
index += 6*sizeof(JoybusDevice);
memcpy(res.data() + index, bootrom, PIF_BOOTROM_SIZE);
memcpy(res.data() + index, bootrom.data(), PIF_BOOTROM_SIZE);
index += PIF_BOOTROM_SIZE;
memcpy(res.data() + index, ram, PIF_RAM_SIZE);
memcpy(res.data() + index, ram.data(), PIF_RAM_SIZE);
index += PIF_RAM_SIZE;
memcpy(res.data() + index, mempak.data(), mempak.size());
index += mempak.size();

View File

@@ -4,6 +4,7 @@
#include <filesystem>
#include <mio/mmap.hpp>
#include <vector>
#include <array>
#include "MupenMovie.hpp"
namespace fs = std::filesystem;
@@ -178,8 +179,9 @@ struct PIF {
}
bool mempakOpen = false;
JoybusDevice joybusDevices[6]{};
u8 bootrom[PIF_BOOTROM_SIZE]{}, ram[PIF_RAM_SIZE]{};
std::array<JoybusDevice, 6> joybusDevices{};
std::array<u8, PIF_BOOTROM_SIZE> bootrom{};
std::array<u8, PIF_RAM_SIZE> ram{};
mio::mmap_sink mempak, eeprom;
int channel = 0;
std::string mempakPath{}, eepromPath{};

View File

@@ -11,6 +11,7 @@ void SI::Reset() {
status.raw = 0;
dramAddr = 0;
pifAddr = 0;
toDram = false;
pif.Reset();
}

View File

@@ -1,6 +1,5 @@
#pragma once
#include <common.hpp>
#include <core/mmio/Interrupt.hpp>
#include <core/mmio/MI.hpp>
#include <core/mmio/PIF.hpp>

View File

@@ -2,7 +2,6 @@
#include <log.hpp>
#include <core/registers/Registers.hpp>
#include <core/Mem.hpp>
#include <core/mmio/Interrupt.hpp>
namespace n64 {
VI::VI (Mem& mem, Registers& regs) : mem(mem), regs(regs) {
@@ -20,6 +19,11 @@ void VI::Reset() {
numHalflines = 262;
numFields = 1;
cyclesPerHalfline = 1000;
xscale = {}, yscale = {};
hsyncLeap = {}, burst = {}, vburst = {};
hstart = {}, vstart = {};
isPal = false;
swaps = {};
}
u32 VI::Read(u32 paddr) const {