all repos — mgba @ ecb1939ff1ecbb190a28a9eb3544c2a58d210305

mGBA Game Boy Advance Emulator

Move common headers to common.h, remove util and debugger from being first class include directories
Jeffrey Pfau jeffrey@endrift.com
Wed, 02 Apr 2014 23:50:20 -0700
commit

ecb1939ff1ecbb190a28a9eb3544c2a58d210305

parent

73d32e7cc700ced48b747cbbf3c57eaefd7b4643

M CMakeLists.txtCMakeLists.txt

@@ -16,8 +16,7 @@ source_group("GBA board" FILES ${GBA_SRC} ${RENDERER_SRC})

source_group("Utilities" FILES ${UTIL_SRC}) include_directories(${CMAKE_SOURCE_DIR}/src/arm) include_directories(${CMAKE_SOURCE_DIR}/src/gba) -include_directories(${CMAKE_SOURCE_DIR}/src/debugger) -include_directories(${CMAKE_SOURCE_DIR}/src/util) +include_directories(${CMAKE_SOURCE_DIR}/src) if(WIN32) add_definitions(-D_WIN32_WINNT=0x0600)
M src/arm/arm.csrc/arm/arm.c

@@ -4,8 +4,6 @@ #include "isa-arm.h"

#include "isa-inlines.h" #include "isa-thumb.h" -#include <limits.h> - static inline enum RegisterBank _ARMSelectBank(enum PrivilegeMode); void ARMSetPrivilegeMode(struct ARMCore* cpu, enum PrivilegeMode mode) {
M src/arm/arm.hsrc/arm/arm.h

@@ -1,19 +1,7 @@

#ifndef ARM_H #define ARM_H -#include <stdint.h> - -#ifdef __POWERPC__ -#define LOAD_32(DEST, ADDR, ARR) asm("lwbrx %0, %1, %2" : "=r"(DEST) : "r"(ADDR), "r"(ARR)) -#define LOAD_16(DEST, ADDR, ARR) asm("lhbrx %0, %1, %2" : "=r"(DEST) : "r"(ADDR), "r"(ARR)) -#define STORE_32(SRC, ADDR, ARR) asm("stwbrx %0, %1, %2" : : "r"(SRC), "r"(ADDR), "r"(ARR)) -#define STORE_16(SRC, ADDR, ARR) asm("sthbrx %0, %1, %2" : : "r"(SRC), "r"(ADDR), "r"(ARR)) -#else -#define LOAD_32(DEST, ADDR, ARR) DEST = ((uint32_t*) ARR)[(ADDR) >> 2] -#define LOAD_16(DEST, ADDR, ARR) DEST = ((uint16_t*) ARR)[(ADDR) >> 1] -#define STORE_32(SRC, ADDR, ARR) ((uint32_t*) ARR)[(ADDR) >> 2] = SRC -#define STORE_16(SRC, ADDR, ARR) ((uint16_t*) ARR)[(ADDR) >> 1] = SRC -#endif +#include "common.h" enum { ARM_SP = 13,
A src/arm/common.h

@@ -0,0 +1,26 @@

+#ifndef COMMON_H +#define COMMON_H + +#include <limits.h> +#include <math.h> +#include <stdarg.h> +#include <stddef.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#ifdef __POWERPC__ +#define LOAD_32(DEST, ADDR, ARR) asm("lwbrx %0, %1, %2" : "=r"(DEST) : "r"(ADDR), "r"(ARR)) +#define LOAD_16(DEST, ADDR, ARR) asm("lhbrx %0, %1, %2" : "=r"(DEST) : "r"(ADDR), "r"(ARR)) +#define STORE_32(SRC, ADDR, ARR) asm("stwbrx %0, %1, %2" : : "r"(SRC), "r"(ADDR), "r"(ARR)) +#define STORE_16(SRC, ADDR, ARR) asm("sthbrx %0, %1, %2" : : "r"(SRC), "r"(ADDR), "r"(ARR)) +#else +#define LOAD_32(DEST, ADDR, ARR) DEST = ((uint32_t*) ARR)[(ADDR) >> 2] +#define LOAD_16(DEST, ADDR, ARR) DEST = ((uint16_t*) ARR)[(ADDR) >> 1] +#define STORE_32(SRC, ADDR, ARR) ((uint32_t*) ARR)[(ADDR) >> 2] = SRC +#define STORE_16(SRC, ADDR, ARR) ((uint16_t*) ARR)[(ADDR) >> 1] = SRC +#endif + +#endif
M src/arm/isa-arm.hsrc/arm/isa-arm.h

@@ -1,7 +1,7 @@

#ifndef ISA_ARM_H #define ISA_ARM_H -#include <stdint.h> +#include "common.h" #define ARM_PREFETCH_CYCLES (1 + cpu->memory->activePrefetchCycles32)
M src/arm/isa-inlines.hsrc/arm/isa-inlines.h

@@ -1,6 +1,8 @@

#ifndef ISA_INLINES_H #define ISA_INLINES_H +#include "common.h" + #include "arm.h" #define UNUSED(V) (void)(V)
M src/arm/isa-thumb.hsrc/arm/isa-thumb.h

@@ -1,7 +1,7 @@

#ifndef ISA_THUMB_H #define ISA_THUMB_H -#include <stdint.h> +#include "common.h" struct ARMCore;
M src/debugger/cli-debugger.csrc/debugger/cli-debugger.c

@@ -1,11 +1,6 @@

#include "cli-debugger.h" #include <signal.h> -#include <stdarg.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> #ifdef USE_PTHREADS #include <pthread.h>
M src/debugger/cli-debugger.hsrc/debugger/cli-debugger.h

@@ -1,6 +1,8 @@

#ifndef CLI_DEBUGGER_H #define CLI_DEBUGGER_H +#include "common.h" + #include "debugger.h" #include <histedit.h>
M src/debugger/debugger.csrc/debugger/debugger.c

@@ -4,8 +4,6 @@ #include "arm.h"

#include "memory-debugger.h" -#include <stdlib.h> - static void _checkBreakpoints(struct ARMDebugger* debugger) { struct DebugBreakpoint* breakpoint; int instructionLength;
M src/debugger/debugger.hsrc/debugger/debugger.h

@@ -1,6 +1,8 @@

#ifndef DEBUGGER_H #define DEBUGGER_H +#include "common.h" + #include "arm.h" enum DebuggerState {
M src/debugger/gdb-stub.csrc/debugger/gdb-stub.c

@@ -1,8 +1,6 @@

#include "gdb-stub.h" #include <errno.h> -#include <signal.h> -#include <string.h> enum GDBError { GDB_NO_ERROR = 0x00,
M src/debugger/gdb-stub.hsrc/debugger/gdb-stub.h

@@ -1,8 +1,11 @@

#ifndef GDB_STUB_H #define GDB_STUB_H -#include "debugger.h" -#include "socket.h" +#include "common.h" + +#include "debugger/debugger.h" + +#include "util/socket.h" #define GDB_STUB_MAX_LINE 1200
M src/debugger/memory-debugger.csrc/debugger/memory-debugger.c

@@ -2,8 +2,6 @@ #include "memory-debugger.h"

#include "debugger.h" -#include <string.h> - static void ARMDebuggerShim_store32(struct ARMMemory*, uint32_t address, int32_t value, int* cycleCounter); static void ARMDebuggerShim_store16(struct ARMMemory*, uint32_t address, int16_t value, int* cycleCounter); static void ARMDebuggerShim_store8(struct ARMMemory*, uint32_t address, int8_t value, int* cycleCounter);
M src/debugger/memory-debugger.hsrc/debugger/memory-debugger.h

@@ -1,6 +1,8 @@

#ifndef MEMORY_DEBUGGER_H #define MEMORY_DEBUGGER_H +#include "common.h" + #include "arm.h" struct ARMDebugger;
M src/gba/gba-audio.csrc/gba/gba-audio.c

@@ -5,9 +5,6 @@ #include "gba-io.h"

#include "gba-serialize.h" #include "gba-thread.h" -#include <limits.h> -#include <math.h> - const unsigned GBA_AUDIO_SAMPLES = 512; const unsigned GBA_AUDIO_FIFO_SIZE = 8 * sizeof(int32_t); #define SWEEP_CYCLES (GBA_ARM7TDMI_FREQUENCY / 128)
M src/gba/gba-audio.hsrc/gba/gba-audio.h

@@ -1,9 +1,9 @@

#ifndef GBA_AUDIO_H #define GBA_AUDIO_H -#include "circle-buffer.h" +#include "common.h" -#include <stdint.h> +#include "util/circle-buffer.h" struct GBADMA;
M src/gba/gba-bios.csrc/gba/gba-bios.c

@@ -4,9 +4,6 @@ #include "gba.h"

#include "gba-io.h" #include "gba-memory.h" -#include <math.h> -#include <stdlib.h> - const uint32_t GBA_BIOS_CHECKSUM = 0xBAAE187F; const uint32_t GBA_DS_BIOS_CHECKSUM = 0xBAAE1880;
M src/gba/gba-bios.hsrc/gba/gba-bios.h

@@ -1,9 +1,9 @@

#ifndef GBA_BIOS_H #define GBA_BIOS_H -#include "arm.h" +#include "common.h" -#include <string.h> +#include "arm.h" void GBASwi16(struct ARMBoard* board, int immediate); void GBASwi32(struct ARMBoard* board, int immediate);
M src/gba/gba-gpio.hsrc/gba/gba-gpio.h

@@ -1,7 +1,7 @@

#ifndef GBA_GPIO_H #define GBA_GPIO_H -#include <stdint.h> +#include "common.h" #define IS_GPIO_REGISTER(reg) ((reg) == GPIO_REG_DATA || (reg) == GPIO_REG_DIRECTION || (reg) == GPIO_REG_CONTROL)
M src/gba/gba-io.hsrc/gba/gba-io.h

@@ -1,6 +1,8 @@

#ifndef GBA_IO_H #define GBA_IO_H +#include "common.h" + #include "gba.h" enum GBAIORegisters {
M src/gba/gba-memory.csrc/gba/gba-memory.c

@@ -4,11 +4,7 @@ #include "gba-gpio.h"

#include "gba-io.h" #include "gba-serialize.h" #include "hle-bios.h" -#include "memory.h" - -#include <limits.h> -#include <stdlib.h> -#include <string.h> +#include "util/memory.h" static void GBASetActiveRegion(struct ARMMemory* memory, uint32_t region); static int GBAWaitMultiple(struct ARMMemory* memory, uint32_t startAddress, int count);
M src/gba/gba-memory.hsrc/gba/gba-memory.h

@@ -1,12 +1,12 @@

#ifndef GBA_MEMORY_H #define GBA_MEMORY_H +#include "common.h" + #include "arm.h" #include "gba-gpio.h" #include "gba-savedata.h" - -#include <string.h> enum GBAMemoryRegion { REGION_BIOS = 0x0,
M src/gba/gba-savedata.csrc/gba/gba-savedata.c

@@ -1,12 +1,11 @@

#include "gba-savedata.h" #include "gba.h" -#include "memory.h" + +#include "util/memory.h" #include <errno.h> #include <fcntl.h> -#include <string.h> -#include <unistd.h> static void _flashSwitchBank(struct GBASavedata* savedata, int bank); static void _flashErase(struct GBASavedata* savedata);
M src/gba/gba-savedata.hsrc/gba/gba-savedata.h

@@ -1,7 +1,7 @@

#ifndef GBA_SAVEDATA_H #define GBA_SAVEDATA_H -#include <stdint.h> +#include "common.h" enum SavedataType { SAVEDATA_NONE = 0,
M src/gba/gba-sensors.hsrc/gba/gba-sensors.h

@@ -1,7 +1,7 @@

#ifndef GBA_SENSORS_H #define GBA_SENSORS_H -#include <stdint.h> +#include "common.h" struct GBARotationSource { void (*sample)(struct GBARotationSource*);
M src/gba/gba-serialize.csrc/gba/gba-serialize.c

@@ -3,13 +3,10 @@

#include "gba-audio.h" #include "gba-io.h" #include "gba-thread.h" -#include "memory.h" + +#include "util/memory.h" #include <fcntl.h> -#include <limits.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> const uint32_t GBA_SAVESTATE_MAGIC = 0x01000000;
M src/gba/gba-serialize.hsrc/gba/gba-serialize.h

@@ -1,6 +1,8 @@

#ifndef GBA_SERIALIZE_H #define GBA_SERIALIZE_H +#include "common.h" + #include "gba.h" const uint32_t GBA_SAVESTATE_MAGIC;
M src/gba/gba-sio.csrc/gba/gba-sio.c

@@ -2,8 +2,6 @@ #include "gba-sio.h"

#include "gba-io.h" -#include <limits.h> - static struct GBASIODriver* _lookupDriver(struct GBASIO* sio, enum GBASIOMode mode) { switch (mode) { case SIO_NORMAL_8:
M src/gba/gba-sio.hsrc/gba/gba-sio.h

@@ -1,7 +1,7 @@

#ifndef GBA_SIO_H #define GBA_SIO_H -#include <stdint.h> +#include "common.h" enum GBASIOMode { SIO_NORMAL_8 = 0,
M src/gba/gba-thread.csrc/gba/gba-thread.c

@@ -1,11 +1,11 @@

#include "gba-thread.h" #include "arm.h" -#include "debugger.h" #include "gba.h" #include "gba-serialize.h" -#include <stdlib.h> +#include "debugger/debugger.h" + #include <signal.h> #ifdef USE_PTHREADS
M src/gba/gba-thread.hsrc/gba/gba-thread.h

@@ -1,8 +1,11 @@

#ifndef GBA_THREAD_H #define GBA_THREAD_H +#include "common.h" + #include "gba.h" -#include "threading.h" + +#include "util/threading.h" struct GBAThread; typedef void (*ThreadCallback)(struct GBAThread* threadContext);
M src/gba/gba-video.csrc/gba/gba-video.c

@@ -4,10 +4,8 @@ #include "gba.h"

#include "gba-io.h" #include "gba-serialize.h" #include "gba-thread.h" -#include "memory.h" -#include <limits.h> -#include <string.h> +#include "util/memory.h" static void GBAVideoDummyRendererInit(struct GBAVideoRenderer* renderer); static void GBAVideoDummyRendererDeinit(struct GBAVideoRenderer* renderer);
M src/gba/gba-video.hsrc/gba/gba-video.h

@@ -1,9 +1,9 @@

#ifndef GBA_VIDEO_H #define GBA_VIDEO_H -#include "gba-memory.h" +#include "common.h" -#include <stdint.h> +#include "gba-memory.h" enum { VIDEO_CYCLES_PER_PIXEL = 4,
M src/gba/gba.csrc/gba/gba.c

@@ -4,14 +4,11 @@ #include "gba-bios.h"

#include "gba-io.h" #include "gba-sio.h" #include "gba-thread.h" -#include "memory.h" + +#include "util/memory.h" -#include "debugger.h" +#include "debugger/debugger.h" -#include <limits.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> #include <sys/stat.h> const uint32_t GBA_ARM7TDMI_FREQUENCY = 0x1000000;
M src/gba/gba.hsrc/gba/gba.h

@@ -1,15 +1,15 @@

#ifndef GBA_H #define GBA_H +#include "common.h" + #include "arm.h" -#include "debugger.h" +#include "debugger/debugger.h" #include "gba-memory.h" #include "gba-video.h" #include "gba-audio.h" #include "gba-sio.h" - -#include <stdarg.h> extern const uint32_t GBA_ARM7TDMI_FREQUENCY;
M src/gba/hle-bios.hsrc/gba/hle-bios.h

@@ -1,8 +1,7 @@

#ifndef HLE_BIOS_H #define HLE_BIOS_H -#include <stdint.h> -#include <string.h> +#include "common.h" extern const size_t hleBiosLength; extern const uint8_t hleBios[];
M src/gba/renderers/video-glsl.hsrc/gba/renderers/video-glsl.h

@@ -1,6 +1,8 @@

#ifndef VIDEO_GLSL_H #define VIDEO_GLSL_H +#include "common.h" + #include "gba-video.h" #include <pthread.h>
M src/gba/renderers/video-software.csrc/gba/renderers/video-software.c

@@ -3,8 +3,6 @@

#include "gba.h" #include "gba-io.h" -#include <string.h> - #define UNUSED(X) (void) (X) static const int _objSizes[32] = {
M src/gba/renderers/video-software.hsrc/gba/renderers/video-software.h

@@ -1,9 +1,9 @@

#ifndef VIDEO_SOFTWARE_H #define VIDEO_SOFTWARE_H -#include "gba-video.h" +#include "common.h" -#include <pthread.h> +#include "gba-video.h" #ifdef COLOR_16_BIT typedef uint16_t color_t;
M src/platform/glsl-main.csrc/platform/glsl-main.c

@@ -15,7 +15,6 @@ #include <fcntl.h>

#include <errno.h> #include <signal.h> #include <sys/time.h> -#include <unistd.h> static int _GBASDLInit(void); static void _GBASDLDeinit(void);
M src/platform/perf-main.csrc/platform/perf-main.c

@@ -5,9 +5,6 @@

#include <fcntl.h> #include <signal.h> #include <sys/time.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> static void _GBAPerfRunloop(struct GBAThread* context, int* frames); static void _GBAPerfShutdown(int signal);
M src/platform/posix/memory.csrc/platform/posix/memory.c

@@ -1,4 +1,4 @@

-#include "memory.h" +#include "util/memory.h" #include <sys/mman.h>
M src/platform/sdl/egl-main.csrc/platform/sdl/egl-main.c

@@ -1,4 +1,4 @@

-#include "debugger.h" +#include "debugger/debugger.h" #include "gba-thread.h" #include "gba.h" #include "renderers/video-software.h"

@@ -16,7 +16,6 @@ #include <fcntl.h>

#include <malloc.h> #include <signal.h> #include <sys/time.h> -#include <unistd.h> struct GBAVideoEGLRenderer { struct GBAVideoSoftwareRenderer d;
M src/platform/sdl/gl-main.csrc/platform/sdl/gl-main.c

@@ -1,4 +1,4 @@

-#include "cli-debugger.h" +#include "debugger/cli-debugger.h" #include "gba-thread.h" #include "gba.h" #include "sdl-audio.h"
M src/platform/sdl/sdl-audio.hsrc/platform/sdl/sdl-audio.h

@@ -1,6 +1,8 @@

#ifndef SDL_AUDIO_H #define SDL_AUDIO_H +#include "common.h" + #include <SDL.h> struct GBASDLAudio {
M src/platform/sdl/sdl-events.csrc/platform/sdl/sdl-events.c

@@ -1,6 +1,6 @@

#include "sdl-events.h" -#include "debugger.h" +#include "debugger/debugger.h" #include "gba-io.h" #include "gba-serialize.h" #include "gba-video.h"
M src/platform/sdl/sdl-events.hsrc/platform/sdl/sdl-events.h

@@ -1,6 +1,8 @@

#ifndef SDL_EVENTS_H #define SDL_EVENTS_H +#include "common.h" + #include "gba-thread.h" #include <SDL.h>
M src/platform/sdl/sw-main.csrc/platform/sdl/sw-main.c

@@ -1,4 +1,4 @@

-#include "debugger.h" +#include "debugger/debugger.h" #include "gba-thread.h" #include "gba.h" #include "renderers/video-software.h"

@@ -11,7 +11,6 @@ #include <fcntl.h>

#include <errno.h> #include <signal.h> #include <sys/time.h> -#include <unistd.h> struct SoftwareRenderer { struct GBAVideoSoftwareRenderer d;
M src/platform/windows/memory.csrc/platform/windows/memory.c

@@ -1,4 +1,4 @@

-#include "memory.h" +#include "util/memory.h" #include <io.h> #include <Windows.h>
M src/util/circle-buffer.csrc/util/circle-buffer.c

@@ -1,8 +1,5 @@

#include "circle-buffer.h" -#include <stddef.h> -#include <stdlib.h> - #ifndef NDEBUG static int _checkIntegrity(struct CircleBuffer* buffer) { if ((int8_t*) buffer->writePtr - (int8_t*) buffer->readPtr == buffer->size) {
M src/util/circle-buffer.hsrc/util/circle-buffer.h

@@ -1,8 +1,7 @@

#ifndef CIRCLE_BUFFER_H #define CIRCLE_BUFFER_H -#include <stdint.h> -#include <string.h> +#include "common.h" struct CircleBuffer { void* data;
M src/util/memory.hsrc/util/memory.h

@@ -1,7 +1,7 @@

#ifndef MEMORY_H #define MEMORY_H -#include <unistd.h> +#include "common.h" #define MEMORY_READ 1 #define MEMORY_WRITE 2

@@ -10,4 +10,4 @@ void* anonymousMemoryMap(size_t size);

void* fileMemoryMap(int fd, size_t size, int flags); void mappedMemoryFree(void* memory, size_t size); -#endif+#endif
M src/util/socket.hsrc/util/socket.h

@@ -1,6 +1,8 @@

#ifndef SOCKET_H #define SOCKET_H +#include "common.h" + #ifdef _WIN32 #include <winsock2.h>

@@ -9,9 +11,7 @@ #else

#include <fcntl.h> #include <netinet/in.h> #include <netinet/tcp.h> -#include <stdio.h> #include <sys/socket.h> -#include <unistd.h> typedef int Socket; #endif
M src/util/threading.hsrc/util/threading.h

@@ -1,6 +1,7 @@

#ifndef THREADING_H #define THREADING_H +#include "common.h" #ifdef USE_PTHREADS #include <pthread.h>