Core: Merge ARMComponent and LR35902Component
@@ -90,7 +90,7 @@ }
} } -void ARMSetComponents(struct ARMCore* cpu, struct ARMComponent* master, int extra, struct ARMComponent** extras) { +void ARMSetComponents(struct ARMCore* cpu, struct mCPUComponent* master, int extra, struct mCPUComponent** extras) { cpu->master = master; cpu->numComponents = extra; cpu->components = extras;
@@ -8,6 +8,8 @@ #define ARM_H
#include "util/common.h" +#include "core/cpu.h" + enum { ARM_SP = 13, ARM_LR = 14,@@ -129,12 +131,6 @@
void (*hitStub)(struct ARMCore* cpu, uint32_t opcode); }; -struct ARMComponent { - uint32_t id; - void (*init)(struct ARMCore* cpu, struct ARMComponent* component); - void (*deinit)(struct ARMComponent* component); -}; - struct ARMCore { int32_t gprs[16]; union PSR cpsr;@@ -157,15 +153,15 @@
struct ARMMemory memory; struct ARMInterruptHandler irqh; - struct ARMComponent* master; + struct mCPUComponent* master; size_t numComponents; - struct ARMComponent** components; + struct mCPUComponent** components; }; void ARMInit(struct ARMCore* cpu); void ARMDeinit(struct ARMCore* cpu); -void ARMSetComponents(struct ARMCore* cpu, struct ARMComponent* master, int extra, struct ARMComponent** extras); +void ARMSetComponents(struct ARMCore* cpu, struct mCPUComponent* master, int extra, struct mCPUComponent** extras); void ARMHotplugAttach(struct ARMCore* cpu, size_t slot); void ARMHotplugDetach(struct ARMCore* cpu, size_t slot);
@@ -0,0 +1,17 @@
+/* Copyright (c) 2013-2016 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifndef M_CPU_H +#define M_CPU_H + +#include "util/common.h" + +struct mCPUComponent { + uint32_t id; + void (*init)(void* cpu, struct mCPUComponent* component); + void (*deinit)(struct mCPUComponent* component); +}; + +#endif
@@ -43,8 +43,8 @@ };
ARMDebuggerEnter(debugger, DEBUGGER_ENTER_BREAKPOINT, &info); } -static void ARMDebuggerInit(struct ARMCore*, struct ARMComponent*); -static void ARMDebuggerDeinit(struct ARMComponent*); +static void ARMDebuggerInit(void* cpu, struct mCPUComponent*); +static void ARMDebuggerDeinit(struct mCPUComponent*); void ARMDebuggerCreate(struct ARMDebugger* debugger) { debugger->d.id = ARM_DEBUGGER_ID;@@ -52,11 +52,11 @@ debugger->d.init = ARMDebuggerInit;
debugger->d.deinit = ARMDebuggerDeinit; } -void ARMDebuggerInit(struct ARMCore* cpu, struct ARMComponent* component) { +void ARMDebuggerInit(void* cpu, struct mCPUComponent* component) { struct ARMDebugger* debugger = (struct ARMDebugger*) component; debugger->cpu = cpu; debugger->state = DEBUGGER_RUNNING; - debugger->originalMemory = cpu->memory; + debugger->originalMemory = debugger->cpu->memory; debugger->currentBreakpoint = 0; DebugBreakpointListInit(&debugger->breakpoints, 0); DebugBreakpointListInit(&debugger->swBreakpoints, 0);@@ -66,7 +66,7 @@ debugger->init(debugger);
} } -void ARMDebuggerDeinit(struct ARMComponent* component) { +void ARMDebuggerDeinit(struct mCPUComponent* component) { struct ARMDebugger* debugger = (struct ARMDebugger*) component; debugger->deinit(debugger); DebugBreakpointListDeinit(&debugger->breakpoints);
@@ -75,7 +75,7 @@ DEBUGGER_LOG_ERROR = 0x08
}; struct ARMDebugger { - struct ARMComponent d; + struct mCPUComponent d; enum DebuggerState state; struct ARMCore* cpu;
@@ -21,7 +21,7 @@ const uint32_t GB_COMPONENT_MAGIC = 0x400000;
mLOG_DEFINE_CATEGORY(GB, "GB"); -static void GBInit(struct LR35902Core* cpu, struct LR35902Component* component); +static void GBInit(void* cpu, struct mCPUComponent* component); static void GBInterruptHandlerInit(struct LR35902InterruptHandler* irqh); static void GBProcessEvents(struct LR35902Core* cpu); static void GBSetInterrupts(struct LR35902Core* cpu, bool enable);@@ -34,11 +34,11 @@ gb->d.init = GBInit;
gb->d.deinit = 0; } -static void GBInit(struct LR35902Core* cpu, struct LR35902Component* component) { +static void GBInit(void* cpu, struct mCPUComponent* component) { struct GB* gb = (struct GB*) component; gb->cpu = cpu; - GBInterruptHandlerInit(&cpu->irqh); + GBInterruptHandlerInit(&gb->cpu->irqh); GBMemoryInit(gb); gb->video.p = gb;
@@ -42,7 +42,7 @@ };
struct mCoreSync; struct GB { - struct LR35902Component d; + struct mCPUComponent d; struct LR35902Core* cpu; struct GBMemory memory;
@@ -99,8 +99,8 @@ cheats->romPatches[i].applied = false;
} } -static void GBACheatDeviceInit(struct ARMCore*, struct ARMComponent*); -static void GBACheatDeviceDeinit(struct ARMComponent*); +static void GBACheatDeviceInit(void*, struct mCPUComponent*); +static void GBACheatDeviceDeinit(struct mCPUComponent*); void GBACheatDeviceCreate(struct GBACheatDevice* device) { device->d.id = GBA_CHEAT_DEVICE_ID;@@ -557,9 +557,9 @@ ++newSet->hook->refs;
} } -void GBACheatDeviceInit(struct ARMCore* cpu, struct ARMComponent* component) { +void GBACheatDeviceInit(void* cpu, struct mCPUComponent* component) { struct GBACheatDevice* device = (struct GBACheatDevice*) component; - device->p = (struct GBA*) cpu->master; + device->p = (struct GBA*) ((struct ARMCore*) cpu)->master; size_t i; for (i = 0; i < GBACheatSetsSize(&device->cheats); ++i) { struct GBACheatSet* cheats = *GBACheatSetsGetPointer(&device->cheats, i);@@ -568,7 +568,7 @@ _patchROM(device, cheats);
} } -void GBACheatDeviceDeinit(struct ARMComponent* component) { +void GBACheatDeviceDeinit(struct mCPUComponent* component) { struct GBACheatDevice* device = (struct GBACheatDevice*) component; size_t i; for (i = GBACheatSetsSize(&device->cheats); i--;) {
@@ -182,7 +182,7 @@
DECLARE_VECTOR(GBACheatSets, struct GBACheatSet*); struct GBACheatDevice { - struct ARMComponent d; + struct mCPUComponent d; struct GBA* p; struct GBACheatSets cheats;
@@ -19,7 +19,7 @@ struct GBACore {
struct mCore d; struct GBAVideoSoftwareRenderer renderer; int keys; - struct ARMComponent* components[GBA_COMPONENT_MAX]; + struct mCPUComponent* components[GBA_COMPONENT_MAX]; }; static bool _GBACoreInit(struct mCore* core) {
@@ -32,7 +32,7 @@ static const uint8_t GBA_ROM_MAGIC[] = { 0xEA };
static const size_t GBA_MB_MAGIC_OFFSET = 0xC0; -static void GBAInit(struct ARMCore* cpu, struct ARMComponent* component); +static void GBAInit(void* cpu, struct mCPUComponent* component); static void GBAInterruptHandlerInit(struct ARMInterruptHandler* irqh); static void GBAProcessEvents(struct ARMCore* cpu); static int32_t GBATimersProcessEvents(struct GBA* gba, int32_t cycles);@@ -55,13 +55,13 @@ gba->d.init = GBAInit;
gba->d.deinit = 0; } -static void GBAInit(struct ARMCore* cpu, struct ARMComponent* component) { +static void GBAInit(void* cpu, struct mCPUComponent* component) { struct GBA* gba = (struct GBA*) component; gba->cpu = cpu; gba->debugger = 0; gba->sync = 0; - GBAInterruptHandlerInit(&cpu->irqh); + GBAInterruptHandlerInit(&gba->cpu->irqh); GBAMemoryInit(gba); GBASavedataInit(&gba->memory.savedata, 0);@@ -936,7 +936,7 @@ MutexUnlock(&thread->stateMutex);
} } -void GBASetBreakpoint(struct GBA* gba, struct ARMComponent* component, uint32_t address, enum ExecutionMode mode, uint32_t* opcode) { +void GBASetBreakpoint(struct GBA* gba, struct mCPUComponent* component, uint32_t address, enum ExecutionMode mode, uint32_t* opcode) { size_t immediate; for (immediate = 0; immediate < gba->cpu->numComponents; ++immediate) { if (gba->cpu->components[immediate] == component) {
@@ -78,7 +78,7 @@ GBATimerFlags flags;
}; struct GBA { - struct ARMComponent d; + struct mCPUComponent d; struct ARMCore* cpu; struct GBAMemory memory;@@ -169,7 +169,7 @@
void GBAAttachDebugger(struct GBA* gba, struct ARMDebugger* debugger); void GBADetachDebugger(struct GBA* gba); -void GBASetBreakpoint(struct GBA* gba, struct ARMComponent* component, uint32_t address, enum ExecutionMode mode, +void GBASetBreakpoint(struct GBA* gba, struct mCPUComponent* component, uint32_t address, enum ExecutionMode mode, uint32_t* opcode); void GBAClearBreakpoint(struct GBA* gba, uint32_t address, enum ExecutionMode mode, uint32_t opcode);
@@ -151,7 +151,7 @@ struct ARMCore cpu;
struct Patch patch; struct GBACheatDevice cheatDevice; struct GBAThread* threadContext = context; - struct ARMComponent* components[GBA_COMPONENT_MAX] = { 0 }; + struct mCPUComponent* components[GBA_COMPONENT_MAX] = { 0 }; struct GBARRContext* movie = 0; int numComponents = GBA_COMPONENT_MAX;
@@ -29,7 +29,7 @@ }
} } -void LR35902SetComponents(struct LR35902Core* cpu, struct LR35902Component* master, int extra, struct LR35902Component** extras) { +void LR35902SetComponents(struct LR35902Core* cpu, struct mCPUComponent* master, int extra, struct mCPUComponent** extras) { cpu->master = master; cpu->numComponents = extra; cpu->components = extras;
@@ -8,6 +8,7 @@ #define LR35902_H
#include "util/common.h" +#include "core/cpu.h" #include "lr35902/isa-lr35902.h" struct LR35902Core;@@ -67,13 +68,6 @@ void (*hitIllegal)(struct LR35902Core* cpu);
void (*hitStub)(struct LR35902Core* cpu); }; -// TODO: Merge with ARMComponent? -struct LR35902Component { - uint32_t id; - void (*init)(struct LR35902Core* cpu, struct LR35902Component* component); - void (*deinit)(struct LR35902Component* component); -}; - struct LR35902Core { #pragma pack(push, 1) union {@@ -125,10 +119,10 @@
struct LR35902Memory memory; struct LR35902InterruptHandler irqh; - struct LR35902Component* master; + struct mCPUComponent* master; size_t numComponents; - struct LR35902Component** components; + struct mCPUComponent** components; }; static inline uint16_t LR35902ReadHL(struct LR35902Core* cpu) {@@ -163,7 +157,7 @@ }
void LR35902Init(struct LR35902Core* cpu); void LR35902Deinit(struct LR35902Core* cpu); -void LR35902SetComponents(struct LR35902Core* cpu, struct LR35902Component* master, int extra, struct LR35902Component** extras); +void LR35902SetComponents(struct LR35902Core* cpu, struct mCPUComponent* master, int extra, struct mCPUComponent** extras); void LR35902HotplugAttach(struct LR35902Core* cpu, size_t slot); void LR35902HotplugDetach(struct LR35902Core* cpu, size_t slot);