GBA BIOS: Implement SoftReset
Jeffrey Pfau jeffrey@endrift.com
Wed, 07 Jan 2015 22:33:16 -0800
4 files changed,
36 insertions(+),
7 deletions(-)
M
CHANGES
→
CHANGES
@@ -14,7 +14,7 @@ - Game Pak overrides dialog for setting savetype and sensor values
- Support for games using the tilt sensor - Remappable shortcuts for keyboard and gamepad - Rewinding of emulation - - Implemented BIOS routines RegisterRamReset, Diff8bitUnFilterWram, Diff8bitUnFilterVram, and Diff16bitUnFilter + - Implemented BIOS routines SoftReset, RegisterRamReset, Diff8bitUnFilterWram, Diff8bitUnFilterVram, and Diff16bitUnFilter Bugfixes: - Qt: Fix issue with set frame sizes being the wrong height - Qt: Fix emulator crashing when full screen if a game is not running
M
src/gba/gba-bios.c
→
src/gba/gba-bios.c
@@ -8,6 +8,7 @@
#include "gba.h" #include "gba-io.h" #include "gba-memory.h" +#include "isa-inlines.h" const uint32_t GBA_BIOS_CHECKSUM = 0xBAAE187F; const uint32_t GBA_DS_BIOS_CHECKSUM = 0xBAAE1880;@@ -16,6 +17,31 @@ static void _unLz77(struct GBA* gba, int width);
static void _unHuffman(struct GBA* gba); static void _unRl(struct GBA* gba, int width); static void _unFilter(struct GBA* gba, int inwidth, int outwidth); + +static void _SoftReset(struct GBA* gba) { + struct ARMCore* cpu = gba->cpu; + ARMSetPrivilegeMode(cpu, MODE_IRQ); + cpu->spsr.packed = 0; + cpu->gprs[ARM_LR] = 0; + cpu->gprs[ARM_SP] = SP_BASE_IRQ; + ARMSetPrivilegeMode(cpu, MODE_SUPERVISOR); + cpu->spsr.packed = 0; + cpu->gprs[ARM_LR] = 0; + cpu->gprs[ARM_SP] = SP_BASE_SUPERVISOR; + ARMSetPrivilegeMode(cpu, MODE_SYSTEM); + cpu->gprs[ARM_LR] = 0; + cpu->gprs[ARM_SP] = SP_BASE_SYSTEM; + int8_t flag = ((int8_t*) gba->memory.iwram)[0x7FFA]; + memset(((int8_t*) gba->memory.iwram) + SIZE_WORKING_IRAM - 0x200, 0, 0x200); + if (flag) { + cpu->gprs[ARM_PC] = BASE_WORKING_RAM; + } else { + cpu->gprs[ARM_PC] = BASE_CART0; + } + _ARMSetMode(cpu, MODE_ARM); + int currentCycles = 0; + ARM_WRITE_PC; +} static void _RegisterRamReset(struct GBA* gba) { uint32_t registers = gba->cpu->gprs[0];@@ -156,6 +182,9 @@ ARMRaiseSWI(cpu);
return; } switch (immediate) { + case 0x0: + _SoftReset(gba); + break; case 0x1: _RegisterRamReset(gba); break;
M
src/gba/gba.c
→
src/gba/gba.c
@@ -24,12 +24,6 @@
static const size_t GBA_ROM_MAGIC_OFFSET = 2; static const uint8_t GBA_ROM_MAGIC[] = { 0x00, 0xEA }; -enum { - SP_BASE_SYSTEM = 0x03FFFF00, - SP_BASE_IRQ = 0x03FFFFA0, - SP_BASE_SUPERVISOR = 0x03FFFFE0 -}; - struct GBACartridgeOverride { const char id[4]; enum SavedataType type;
M
src/gba/gba.h
→
src/gba/gba.h
@@ -75,6 +75,12 @@ GBA_COMPONENT_DEBUGGER,
GBA_COMPONENT_MAX }; +enum { + SP_BASE_SYSTEM = 0x03007F00, + SP_BASE_IRQ = 0x03007FA0, + SP_BASE_SUPERVISOR = 0x03007FE0 +}; + struct GBA; struct GBARotationSource; struct Patch;