Move common headers to common.h, remove util and debugger from being first class include directories
jump to
@@ -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)
@@ -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) {
@@ -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,
@@ -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
@@ -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)
@@ -1,6 +1,8 @@
#ifndef ISA_INLINES_H #define ISA_INLINES_H +#include "common.h" + #include "arm.h" #define UNUSED(V) (void)(V)
@@ -1,7 +1,7 @@
#ifndef ISA_THUMB_H #define ISA_THUMB_H -#include <stdint.h> +#include "common.h" struct ARMCore;
@@ -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>
@@ -1,6 +1,8 @@
#ifndef CLI_DEBUGGER_H #define CLI_DEBUGGER_H +#include "common.h" + #include "debugger.h" #include <histedit.h>
@@ -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;
@@ -1,6 +1,8 @@
#ifndef DEBUGGER_H #define DEBUGGER_H +#include "common.h" + #include "arm.h" enum DebuggerState {
@@ -1,8 +1,6 @@
#include "gdb-stub.h" #include <errno.h> -#include <signal.h> -#include <string.h> enum GDBError { GDB_NO_ERROR = 0x00,
@@ -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
@@ -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);
@@ -1,6 +1,8 @@
#ifndef MEMORY_DEBUGGER_H #define MEMORY_DEBUGGER_H +#include "common.h" + #include "arm.h" struct ARMDebugger;
@@ -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)
@@ -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;
@@ -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;
@@ -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);
@@ -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)
@@ -1,6 +1,8 @@
#ifndef GBA_IO_H #define GBA_IO_H +#include "common.h" + #include "gba.h" enum GBAIORegisters {
@@ -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);
@@ -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,
@@ -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);
@@ -1,7 +1,7 @@
#ifndef GBA_SAVEDATA_H #define GBA_SAVEDATA_H -#include <stdint.h> +#include "common.h" enum SavedataType { SAVEDATA_NONE = 0,
@@ -1,7 +1,7 @@
#ifndef GBA_SENSORS_H #define GBA_SENSORS_H -#include <stdint.h> +#include "common.h" struct GBARotationSource { void (*sample)(struct GBARotationSource*);
@@ -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;
@@ -1,6 +1,8 @@
#ifndef GBA_SERIALIZE_H #define GBA_SERIALIZE_H +#include "common.h" + #include "gba.h" const uint32_t GBA_SAVESTATE_MAGIC;
@@ -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:
@@ -1,7 +1,7 @@
#ifndef GBA_SIO_H #define GBA_SIO_H -#include <stdint.h> +#include "common.h" enum GBASIOMode { SIO_NORMAL_8 = 0,
@@ -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
@@ -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);
@@ -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);
@@ -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,
@@ -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;
@@ -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;
@@ -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[];
@@ -1,6 +1,8 @@
#ifndef VIDEO_GLSL_H #define VIDEO_GLSL_H +#include "common.h" + #include "gba-video.h" #include <pthread.h>
@@ -3,8 +3,6 @@
#include "gba.h" #include "gba-io.h" -#include <string.h> - #define UNUSED(X) (void) (X) static const int _objSizes[32] = {
@@ -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;
@@ -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);
@@ -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);
@@ -1,4 +1,4 @@
-#include "memory.h" +#include "util/memory.h" #include <sys/mman.h>
@@ -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;
@@ -1,4 +1,4 @@
-#include "cli-debugger.h" +#include "debugger/cli-debugger.h" #include "gba-thread.h" #include "gba.h" #include "sdl-audio.h"
@@ -1,6 +1,8 @@
#ifndef SDL_AUDIO_H #define SDL_AUDIO_H +#include "common.h" + #include <SDL.h> struct GBASDLAudio {
@@ -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"
@@ -1,6 +1,8 @@
#ifndef SDL_EVENTS_H #define SDL_EVENTS_H +#include "common.h" + #include "gba-thread.h" #include <SDL.h>
@@ -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;
@@ -1,4 +1,4 @@
-#include "memory.h" +#include "util/memory.h" #include <io.h> #include <Windows.h>
@@ -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) {
@@ -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;
@@ -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
@@ -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
@@ -1,6 +1,7 @@
#ifndef THREADING_H #define THREADING_H +#include "common.h" #ifdef USE_PTHREADS #include <pthread.h>