all repos — mgba @ f9120b842fb148d61b0212d5581a6f7144be1828

mGBA Game Boy Advance Emulator

ARM: Create component hotplugging and use it for attaching and detaching the debugger
Jeffrey Pfau jeffrey@endrift.com
Wed, 07 Jan 2015 02:05:04 -0800
commit

f9120b842fb148d61b0212d5581a6f7144be1828

parent

30c28f225916338c75c7fa516a0bb4edbde81392

5 files changed, 30 insertions(+), 9 deletions(-)

jump to
M src/arm/arm.csrc/arm/arm.c

@@ -73,7 +73,9 @@ void ARMInit(struct ARMCore* cpu) {

cpu->master->init(cpu, cpu->master); int i; for (i = 0; i < cpu->numComponents; ++i) { - cpu->components[i]->init(cpu, cpu->components[i]); + if (cpu->components[i] && cpu->components[i]->init) { + cpu->components[i]->init(cpu, cpu->components[i]); + } } }

@@ -83,7 +85,7 @@ cpu->master->deinit(cpu->master);

} int i; for (i = 0; i < cpu->numComponents; ++i) { - if (cpu->components[i]->deinit) { + if (cpu->components[i] && cpu->components[i]->deinit) { cpu->components[i]->deinit(cpu->components[i]); } }

@@ -95,6 +97,19 @@ cpu->numComponents = extra;

cpu->components = extras; } +void ARMHotplugAttach(struct ARMCore* cpu, int slot) { + if (slot >= cpu->numComponents) { + return; + } + cpu->components[slot]->init(cpu, cpu->components[slot]); +} + +void ARMHotplugDetach(struct ARMCore* cpu, int slot) { + if (slot >= cpu->numComponents) { + return; + } + cpu->components[slot]->init(cpu, cpu->components[slot]); +} void ARMReset(struct ARMCore* cpu) { int i;
M src/arm/arm.hsrc/arm/arm.h

@@ -165,6 +165,8 @@

void ARMInit(struct ARMCore* cpu); void ARMDeinit(struct ARMCore* cpu); void ARMSetComponents(struct ARMCore* cpu, struct ARMComponent* master, int extra, struct ARMComponent** extras); +void ARMHotplugAttach(struct ARMCore* cpu, int slot); +void ARMHotplugDetach(struct ARMCore* cpu, int slot); void ARMReset(struct ARMCore* cpu); void ARMSetPrivilegeMode(struct ARMCore*, enum PrivilegeMode);
M src/gba/gba-thread.csrc/gba/gba-thread.c

@@ -108,13 +108,8 @@ struct GBA gba;

struct ARMCore cpu; struct Patch patch; struct GBAThread* threadContext = context; - struct ARMComponent* components[1] = {}; - int numComponents = 0; - - if (threadContext->debugger) { - components[numComponents] = &threadContext->debugger->d; - ++numComponents; - } + struct ARMComponent* components[GBA_COMPONENT_MAX] = {}; + int numComponents = GBA_COMPONENT_MAX; #if !defined(_WIN32) && defined(USE_PTHREADS) sigset_t signals;
M src/gba/gba.csrc/gba/gba.c

@@ -434,10 +434,14 @@ }

void GBAAttachDebugger(struct GBA* gba, struct ARMDebugger* debugger) { gba->debugger = debugger; + gba->cpu->components[GBA_COMPONENT_DEBUGGER] = &debugger->d; + ARMHotplugAttach(gba->cpu, GBA_COMPONENT_DEBUGGER); } void GBADetachDebugger(struct GBA* gba) { gba->debugger = 0; + ARMHotplugDetach(gba->cpu, GBA_COMPONENT_DEBUGGER); + gba->cpu->components[GBA_COMPONENT_DEBUGGER] = 0; } void GBALoadROM(struct GBA* gba, struct VFile* vf, struct VFile* sav, const char* fname) {
M src/gba/gba.hsrc/gba/gba.h

@@ -75,6 +75,11 @@ GBA_KEY_MAX,

GBA_KEY_NONE = -1 }; +enum GBAComponent { + GBA_COMPONENT_DEBUGGER, + GBA_COMPONENT_MAX +}; + struct GBA; struct GBARotationSource; struct Patch;