all repos — mgba @ 6835ac8a81288301ddc852b20d6d9c3e93969df6

mGBA Game Boy Advance Emulator

GBA: Better const correctness for serialization
Jeffrey Pfau jeffrey@endrift.com
Thu, 05 Mar 2015 20:43:18 -0800
commit

6835ac8a81288301ddc852b20d6d9c3e93969df6

parent

826569fdf7a69c620b6df66e3afd52bffa7274a8

M src/gba/hardware.csrc/gba/hardware.c

@@ -424,7 +424,7 @@ }

// == Serialization -void GBAHardwareSerialize(struct GBACartridgeHardware* hw, struct GBASerializedState* state) { +void GBAHardwareSerialize(const struct GBACartridgeHardware* hw, struct GBASerializedState* state) { state->hw.readWrite = hw->readWrite; state->hw.pinState = hw->pinState; state->hw.pinDirection = hw->direction;

@@ -440,7 +440,7 @@ state->hw.lightSample = hw->lightSample;

state->hw.lightEdge = hw->lightEdge; } -void GBAHardwareDeserialize(struct GBACartridgeHardware* hw, struct GBASerializedState* state) { +void GBAHardwareDeserialize(struct GBACartridgeHardware* hw, const struct GBASerializedState* state) { hw->readWrite = state->hw.readWrite; hw->pinState = state->hw.pinState; hw->direction = state->hw.pinDirection;
M src/gba/hardware.hsrc/gba/hardware.h

@@ -149,7 +149,7 @@ void GBAHardwareTiltWrite(struct GBACartridgeHardware* gpio, uint32_t address, uint8_t value);

uint8_t GBAHardwareTiltRead(struct GBACartridgeHardware* gpio, uint32_t address); struct GBASerializedState; -void GBAHardwareSerialize(struct GBACartridgeHardware* gpio, struct GBASerializedState* state); -void GBAHardwareDeserialize(struct GBACartridgeHardware* gpio, struct GBASerializedState* state); +void GBAHardwareSerialize(const struct GBACartridgeHardware* gpio, struct GBASerializedState* state); +void GBAHardwareDeserialize(struct GBACartridgeHardware* gpio, const struct GBASerializedState* state); #endif
M src/gba/io.csrc/gba/io.c

@@ -675,7 +675,7 @@ memcpy(state->timers, gba->timers, sizeof(state->timers));

GBAHardwareSerialize(&gba->memory.hw, state); } -void GBAIODeserialize(struct GBA* gba, struct GBASerializedState* state) { +void GBAIODeserialize(struct GBA* gba, const struct GBASerializedState* state) { int i; for (i = 0; i < REG_MAX; i += 2) { if (_isSpecialRegister[i >> 1]) {
M src/gba/io.hsrc/gba/io.h

@@ -161,6 +161,6 @@ uint16_t GBAIORead(struct GBA* gba, uint32_t address);

struct GBASerializedState; void GBAIOSerialize(struct GBA* gba, struct GBASerializedState* state); -void GBAIODeserialize(struct GBA* gba, struct GBASerializedState* state); +void GBAIODeserialize(struct GBA* gba, const struct GBASerializedState* state); #endif
M src/gba/memory.csrc/gba/memory.c

@@ -1461,12 +1461,12 @@ }

cpu->cycles += cycles; } -void GBAMemorySerialize(struct GBAMemory* memory, struct GBASerializedState* state) { +void GBAMemorySerialize(const struct GBAMemory* memory, struct GBASerializedState* state) { memcpy(state->wram, memory->wram, SIZE_WORKING_RAM); memcpy(state->iwram, memory->iwram, SIZE_WORKING_IRAM); } -void GBAMemoryDeserialize(struct GBAMemory* memory, struct GBASerializedState* state) { +void GBAMemoryDeserialize(struct GBAMemory* memory, const struct GBASerializedState* state) { memcpy(memory->wram, state->wram, SIZE_WORKING_RAM); memcpy(memory->iwram, state->iwram, SIZE_WORKING_IRAM); }
M src/gba/memory.hsrc/gba/memory.h

@@ -172,7 +172,7 @@ void GBAMemoryUpdateDMAs(struct GBA* gba, int32_t cycles);

int32_t GBAMemoryRunDMAs(struct GBA* gba, int32_t cycles); struct GBASerializedState; -void GBAMemorySerialize(struct GBAMemory* memory, struct GBASerializedState* state); -void GBAMemoryDeserialize(struct GBAMemory* memory, struct GBASerializedState* state); +void GBAMemorySerialize(const struct GBAMemory* memory, struct GBASerializedState* state); +void GBAMemoryDeserialize(struct GBAMemory* memory, const struct GBASerializedState* state); #endif
M src/gba/serialize.csrc/gba/serialize.c

@@ -55,7 +55,7 @@ gba->rr->stateSaved(gba->rr, state);

} } -void GBADeserialize(struct GBA* gba, struct GBASerializedState* state) { +void GBADeserialize(struct GBA* gba, const struct GBASerializedState* state) { if (state->versionMagic != GBA_SAVESTATE_MAGIC) { GBALog(gba, GBA_LOG_WARN, "Invalid or too new savestate"); return;
M src/gba/serialize.hsrc/gba/serialize.h

@@ -292,7 +292,7 @@ struct VDir;

struct GBAThread; void GBASerialize(struct GBA* gba, struct GBASerializedState* state); -void GBADeserialize(struct GBA* gba, struct GBASerializedState* state); +void GBADeserialize(struct GBA* gba, const struct GBASerializedState* state); bool GBASaveState(struct GBAThread* thread, struct VDir* dir, int slot, bool screenshot); bool GBALoadState(struct GBAThread* thread, struct VDir* dir, int slot);
M src/gba/video.csrc/gba/video.c

@@ -235,7 +235,7 @@ // Nothing to do

} -void GBAVideoSerialize(struct GBAVideo* video, struct GBASerializedState* state) { +void GBAVideoSerialize(const struct GBAVideo* video, struct GBASerializedState* state) { memcpy(state->vram, video->renderer->vram, SIZE_VRAM); memcpy(state->oam, video->oam.raw, SIZE_OAM); memcpy(state->pram, video->palette, SIZE_PALETTE_RAM);

@@ -249,7 +249,7 @@ state->video.nextVcounterIRQ = video->nextVcounterIRQ;

state->video.frameCounter = video->frameCounter; } -void GBAVideoDeserialize(struct GBAVideo* video, struct GBASerializedState* state) { +void GBAVideoDeserialize(struct GBAVideo* video, const struct GBASerializedState* state) { memcpy(video->renderer->vram, state->vram, SIZE_VRAM); int i; for (i = 0; i < SIZE_OAM; i += 2) {
M src/gba/video.hsrc/gba/video.h

@@ -201,7 +201,7 @@

void GBAVideoWriteDISPSTAT(struct GBAVideo* video, uint16_t value); struct GBASerializedState; -void GBAVideoSerialize(struct GBAVideo* video, struct GBASerializedState* state); -void GBAVideoDeserialize(struct GBAVideo* video, struct GBASerializedState* state); +void GBAVideoSerialize(const struct GBAVideo* video, struct GBASerializedState* state); +void GBAVideoDeserialize(struct GBAVideo* video, const struct GBASerializedState* state); #endif