diff --git a/Makefile b/Makefile index 03227d223..e6597518f 100644 --- a/Makefile +++ b/Makefile @@ -245,6 +245,8 @@ xbox360: $(MAKE) -f misc/xbox360/Makefile n64: $(MAKE) -f misc/n64/Makefile +gba: + $(MAKE) -f misc/gba/Makefile ds: $(MAKE) -f misc/ds/Makefile 3ds: diff --git a/misc/32x/main_32x.c b/misc/32x/main_32x.c index 8716dbe2a..d05c505de 100644 --- a/misc/32x/main_32x.c +++ b/misc/32x/main_32x.c @@ -1,7 +1,4 @@ -#include - -#include "32x.h" -#include "hw_32x.h" +#include int32_t fix16_sqrt(int32_t value) { diff --git a/misc/gba/Makefile b/misc/gba/Makefile new file mode 100644 index 000000000..004ae2f95 --- /dev/null +++ b/misc/gba/Makefile @@ -0,0 +1,138 @@ +#--------------------------------------------------------------------------------- +.SUFFIXES: +#--------------------------------------------------------------------------------- + +ifeq ($(strip $(DEVKITARM)),) +$(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") +endif + +include $(DEVKITARM)/gba_rules + +#--------------------------------------------------------------------------------- +# the LIBGBA path is defined in gba_rules, but we have to define LIBTONC ourselves +#--------------------------------------------------------------------------------- +LIBTONC := $(DEVKITPRO)/libtonc + +#--------------------------------------------------------------------------------- +# TARGET is the name of the output +# BUILD is the directory where object files & intermediate files will be placed +# SOURCES is a list of directories containing source code +# INCLUDES is a list of directories containing extra header files +# DATA is a list of directories containing binary data +# GRAPHICS is a list of directories containing files to be processed by grit +# +# All directories are specified relative to the project directory where +# the makefile is found +# +#--------------------------------------------------------------------------------- +TARGET := ClassiCube-gba +BUILD := build-gba +SOURCES := src +INCLUDES := include +DATA := +MUSIC := +GRAPHICS := graphics + +#--------------------------------------------------------------------------------- +# options for code generation +#--------------------------------------------------------------------------------- +ARCH := -mthumb -mthumb-interwork + +CFLAGS := -g -Wall -O2 -DPLAT_GBA \ + -mcpu=arm7tdmi -mtune=arm7tdmi\ + $(ARCH) + +CFLAGS += $(INCLUDE) + +CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions + +ASFLAGS := -g $(ARCH) +LDFLAGS = -g $(ARCH) -Wl,-Map,$(notdir $*.map) + +#--------------------------------------------------------------------------------- +# any extra libraries we wish to link with the project +#--------------------------------------------------------------------------------- +LIBS := -lmm -ltonc + + +#--------------------------------------------------------------------------------- +# list of directories containing libraries, this must be the top level containing +# include and lib. +# the LIBGBA path should remain in this list if you want to use maxmod +#--------------------------------------------------------------------------------- +LIBDIRS := $(LIBGBA) $(LIBTONC) + +#--------------------------------------------------------------------------------- +# no real need to edit anything past this point unless you need to add additional +# rules for different file extensions +#--------------------------------------------------------------------------------- + + +ifneq ($(BUILD),$(notdir $(CURDIR))) +#--------------------------------------------------------------------------------- + +export OUTPUT := $(CURDIR)/$(TARGET) + +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ + $(foreach dir,$(DATA),$(CURDIR)/$(dir)) + +export DEPSDIR := $(CURDIR)/$(BUILD) + +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) + +export LD := $(CC) + +export OFILES_BIN := $(addsuffix .o,$(BINFILES)) + +export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) + +export OFILES_GRAPHICS := $(PNGFILES:.png=.o) + +export OFILES := $(OFILES_BIN) $(OFILES_SOURCES) $(OFILES_GRAPHICS) + +export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES))) $(PNGFILES:.png=.h) + +export INCLUDE := $(foreach dir,$(INCLUDES),-iquote $(CURDIR)/$(dir)) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + -I$(CURDIR)/$(BUILD) + +export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) + +.PHONY: $(BUILD) clean + +all: $(BUILD) + $(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/misc/gba/Makefile + +#--------------------------------------------------------------------------------- +$(BUILD): + mkdir -p $@ + +#--------------------------------------------------------------------------------- +clean: + echo clean ... + rm -fr $(BUILD) $(TARGET).elf $(TARGET).gba + + +#--------------------------------------------------------------------------------- +else + +#--------------------------------------------------------------------------------- +# main targets +#--------------------------------------------------------------------------------- + +$(OUTPUT).gba : $(OUTPUT).elf + +$(OUTPUT).elf : $(OFILES) + +$(OFILES_SOURCES) : $(HFILES) + +# make likes to delete intermediate files. This prevents it from deleting the +# files generated by grit after building the GBA ROM. +.SECONDARY: + +-include $(DEPSDIR)/*.d +#--------------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------------- diff --git a/src/Bitmap.h b/src/Bitmap.h index 7b36393f4..dd9f25ea0 100644 --- a/src/Bitmap.h +++ b/src/Bitmap.h @@ -23,7 +23,7 @@ struct Stream; #define BITMAPCOLOR_G_SHIFT 5 #define BITMAPCOLOR_R_SHIFT 10 #define BITMAPCOLOR_A_SHIFT 15 -#elif defined CC_BUILD_PS1 || defined CC_BUILD_SATURN || defined CC_BUILD_NDS || defined CC_BUILD_32X +#elif defined CC_BUILD_PS1 || defined CC_BUILD_SATURN || defined CC_BUILD_NDS || defined CC_BUILD_32X || defined CC_BUILD_GBA #define BITMAPCOLOR_R_SHIFT 0 #define BITMAPCOLOR_G_SHIFT 5 #define BITMAPCOLOR_B_SHIFT 10 diff --git a/src/Core.h b/src/Core.h index c84546fcb..f2476aadb 100644 --- a/src/Core.h +++ b/src/Core.h @@ -426,6 +426,24 @@ typedef cc_uint8 cc_bool; #define DEFAULT_NET_BACKEND CC_NET_BACKEND_BUILTIN #define DEFAULT_SSL_BACKEND CC_SSL_BACKEND_BEARSSL #define DEFAULT_AUD_BACKEND CC_AUD_BACKEND_OPENAL +#elif defined PLAT_GBA + #define CC_BUILD_GBA + #define CC_BUILD_CONSOLE + #define CC_BUILD_LOWMEM + #define CC_BUILD_TINYMEM + #define CC_BUILD_COOPTHREADED + #define CC_BUILD_NOMUSIC + #define CC_BUILD_NOSOUNDS + #define CC_BUILD_SMALLSTACK + #define CC_BUILD_NOFPU + #define DEFAULT_NET_BACKEND CC_NET_BACKEND_BUILTIN + #define CC_DISABLE_ANIMATIONS /* Very costly in FPU less system */ + #define CC_DISABLE_HELDBLOCK /* Very costly in FPU less system */ + #undef CC_BUILD_ADVLIGHTING + #undef CC_BUILD_FILESYSTEM + #define CC_GFX_BACKEND CC_GFX_BACKEND_SOFTGPU + #define CC_DISABLE_EXTRA_MODELS + #define SOFTGPU_DISABLE_ZBUFFER #elif defined PLAT_NDS #define CC_BUILD_NDS #define CC_BUILD_CONSOLE diff --git a/src/Platform_GBA.c b/src/Platform_GBA.c new file mode 100644 index 000000000..a9ac03fee --- /dev/null +++ b/src/Platform_GBA.c @@ -0,0 +1,246 @@ +#include "Core.h" +#if defined CC_BUILD_GBA +#include "_PlatformBase.h" +#include "Stream.h" +#include "ExtMath.h" +#include "Funcs.h" +#include "Window.h" +#include "Utils.h" +#include "Errors.h" +#include "Options.h" +#include "Animations.h" + +#include +#include +#include +#include +#include +#include +#include +#include "_PlatformConsole.h" +extern int nocash_puts(const char *str); + +const cc_result ReturnCode_FileShareViolation = 1000000000; // not used +const cc_result ReturnCode_FileNotFound = ENOENT; +const cc_result ReturnCode_DirectoryExists = EEXIST; +const cc_result ReturnCode_SocketInProgess = EINPROGRESS; +const cc_result ReturnCode_SocketWouldBlock = EWOULDBLOCK; +const cc_result ReturnCode_SocketDropped = EPIPE; + +const char* Platform_AppNameSuffix = " GBA"; +cc_bool Platform_ReadonlyFilesystem; + + +/*########################################################################################################################* +*------------------------------------------------------Logging/Time-------------------------------------------------------* +*#########################################################################################################################*/ +cc_uint64 Stopwatch_ElapsedMicroseconds(cc_uint64 beg, cc_uint64 end) { + if (end < beg) return 0; + + return end - beg; +} + +cc_uint64 Stopwatch_Measure(void) { + return 0; +} + +void Platform_Log(const char* msg, int len) { + // Can only be up to 120 bytes total + char buffer[120]; + len = min(len, 118); + + Mem_Copy(buffer, msg, len); + buffer[len + 0] = '\n'; + buffer[len + 1] = '\0'; + nocash_puts(buffer); +} + +TimeMS DateTime_CurrentUTC(void) { + return 0; +} + +void DateTime_CurrentLocal(struct cc_datetime* t) { + memset(t, 0, sizeof(*t)); +} + + +/*########################################################################################################################* +*-------------------------------------------------------Crash handling----------------------------------------------------* +*#########################################################################################################################*/ +void CrashHandler_Install(void) { +} + +void Process_Abort2(cc_result result, const char* raw_msg) { + Platform_LogConst(raw_msg); + _exit(0); +} + + +/*########################################################################################################################* +*-----------------------------------------------------Directory/File------------------------------------------------------* +*#########################################################################################################################*/ +void Platform_EncodePath(cc_filepath* dst, const cc_string* path) { + char* str = dst->buffer; + String_EncodeUtf8(str, path); +} + +cc_result Directory_Create(const cc_filepath* path) { + return ERR_NOT_SUPPORTED; +} + +int File_Exists(const cc_filepath* path) { + return false; +} + +cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCallback callback) { + return ERR_NOT_SUPPORTED; +} + +cc_result File_Open(cc_file* file, const cc_filepath* path) { + return ERR_NOT_SUPPORTED; +} + +cc_result File_Create(cc_file* file, const cc_filepath* path) { + return ERR_NOT_SUPPORTED; +} + +cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) { + return ERR_NOT_SUPPORTED; +} + +cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) { + return ERR_NOT_SUPPORTED; +} + +cc_result File_Write(cc_file file, const void* data, cc_uint32 count, cc_uint32* bytesWrote) { + return ERR_NOT_SUPPORTED; +} + +cc_result File_Close(cc_file file) { + return ERR_NOT_SUPPORTED; +} + +cc_result File_Seek(cc_file file, int offset, int seekType) { + return ERR_NOT_SUPPORTED; +} + +cc_result File_Position(cc_file file, cc_uint32* pos) { + return ERR_NOT_SUPPORTED; +} + +cc_result File_Length(cc_file file, cc_uint32* len) { + return ERR_NOT_SUPPORTED; +} + + +/*########################################################################################################################* +*--------------------------------------------------------Threading--------------------------------------------------------* +*#########################################################################################################################*/ +// !!! NOTE: PSP uses cooperative multithreading (not preemptive multithreading) !!! +void Thread_Sleep(cc_uint32 milliseconds) { + //swiDelay(8378 * milliseconds); // TODO probably wrong +} + +void Thread_Run(void** handle, Thread_StartFunc func, int stackSize, const char* name) { + *handle = NULL; +} + +void Thread_Detach(void* handle) { +} + +void Thread_Join(void* handle) { +} + +void* Mutex_Create(const char* name) { + return NULL; +} + +void Mutex_Free(void* handle) { +} + +void Mutex_Lock(void* handle) { +} + +void Mutex_Unlock(void* handle) { +} + +void* Waitable_Create(const char* name) { + return NULL; +} + +void Waitable_Free(void* handle) { +} + +void Waitable_Signal(void* handle) { +} + +void Waitable_Wait(void* handle) { +} + +void Waitable_WaitFor(void* handle, cc_uint32 milliseconds) { +} + + +/*########################################################################################################################* +*---------------------------------------------------------Socket----------------------------------------------------------* +*#########################################################################################################################*/ +cc_result Socket_ParseAddress(const cc_string* address, int port, cc_sockaddr* addrs, int* numValidAddrs) { + return ERR_NOT_SUPPORTED; +} + +cc_result Socket_Create(cc_socket* s, cc_sockaddr* addr, cc_bool nonblocking) { + return ERR_NOT_SUPPORTED; +} + +cc_result Socket_Connect(cc_socket s, cc_sockaddr* addr) { + return ERR_NOT_SUPPORTED; +} + +cc_result Socket_Read(cc_socket s, cc_uint8* data, cc_uint32 count, cc_uint32* modified) { + return ERR_NOT_SUPPORTED; +} + +cc_result Socket_Write(cc_socket s, const cc_uint8* data, cc_uint32 count, cc_uint32* modified) { + return ERR_NOT_SUPPORTED; +} + +void Socket_Close(cc_socket s) { +} + +cc_result Socket_CheckReadable(cc_socket s, cc_bool* readable) { + return ERR_NOT_SUPPORTED; +} + +cc_result Socket_CheckWritable(cc_socket s, cc_bool* writable) { + return ERR_NOT_SUPPORTED; +} + + +/*########################################################################################################################* +*--------------------------------------------------------Platform---------------------------------------------------------* +*#########################################################################################################################*/ +void Platform_Init(void) { + +} +void Platform_Free(void) { } + +cc_bool Platform_DescribeError(cc_result res, cc_string* dst) { + return false; +} + +cc_bool Process_OpenSupported = false; +cc_result Process_StartOpen(const cc_string* args) { + return ERR_NOT_SUPPORTED; +} + + +/*########################################################################################################################* +*-------------------------------------------------------Encryption--------------------------------------------------------* +*#########################################################################################################################*/ +#define MACHINE_KEY "GBA_GBA_GBA_GBA_" + +static cc_result GetMachineID(cc_uint32* key) { + Mem_Copy(key, MACHINE_KEY, sizeof(MACHINE_KEY) - 1); + return 0; +} +#endif diff --git a/src/Window_GBA.c b/src/Window_GBA.c new file mode 100644 index 000000000..30ecc2637 --- /dev/null +++ b/src/Window_GBA.c @@ -0,0 +1,168 @@ +#include "Core.h" +#if defined CC_BUILD_GBA +#include "Window.h" +#include "Platform.h" +#include "Input.h" +#include "Event.h" +#include "Graphics.h" +#include "String.h" +#include "Funcs.h" +#include "Bitmap.h" +#include "Errors.h" +#include "ExtMath.h" +#include "Camera.h" +#include + +typedef volatile uint8_t vu8; +typedef volatile uint16_t vu16; +typedef volatile uint32_t vu32; + +#define SCREEN_WIDTH 240 +#define SCREEN_HEIGHT 160 + +#define DCNT_MODE3 0x0003 +#define DCNT_BG2 0x0400 + +#define MEM_IO 0x04000000 + +#define REG_DISPCNT *(vu32*)(MEM_IO+0x0000) + + +/*########################################################################################################################* +*------------------------------------------------------General data-------------------------------------------------------* +*#########################################################################################################################*/ +struct _DisplayData DisplayInfo; +struct cc_window WindowInfo; + +void Window_PreInit(void) { + REG_DISPCNT = DCNT_MODE3 | DCNT_BG2; +} + +void Window_Init(void) { + DisplayInfo.Width = SCREEN_WIDTH; + DisplayInfo.Height = SCREEN_HEIGHT; + DisplayInfo.ScaleX = 0.5f; + DisplayInfo.ScaleY = 0.5f; + + Window_Main.Width = DisplayInfo.Width; + Window_Main.Height = DisplayInfo.Height; + Window_Main.Focused = true; + + Window_Main.Exists = true; + Window_Main.UIScaleX = DEFAULT_UI_SCALE_X; + Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y; +} + +void Window_Free(void) { } + +void Window_Create2D(int width, int height) { +} + +void Window_Create3D(int width, int height) { +} + +void Window_Destroy(void) { } + +void Window_SetTitle(const cc_string* title) { } +void Clipboard_GetText(cc_string* value) { } +void Clipboard_SetText(const cc_string* value) { } + +int Window_GetWindowState(void) { return WINDOW_STATE_FULLSCREEN; } +cc_result Window_EnterFullscreen(void) { return 0; } +cc_result Window_ExitFullscreen(void) { return 0; } +int Window_IsObscured(void) { return 0; } + +void Window_Show(void) { } +void Window_SetSize(int width, int height) { } + +void Window_RequestClose(void) { + Event_RaiseVoid(&WindowEvents.Closing); +} + + +/*########################################################################################################################* +*----------------------------------------------------Input processing-----------------------------------------------------* +*#########################################################################################################################*/ +void Window_ProcessEvents(float delta) { + +} + +void Cursor_SetPosition(int x, int y) { } // Makes no sense for PSP +void Window_EnableRawMouse(void) { Input.RawMode = true; } +void Window_DisableRawMouse(void) { Input.RawMode = false; } + +void Window_UpdateRawMouse(void) { } + + +/*########################################################################################################################* +*-------------------------------------------------------Gamepads----------------------------------------------------------* +*#########################################################################################################################*/ +void Gamepads_Init(void) { + Input.Sources |= INPUT_SOURCE_GAMEPAD; +} + +void Gamepads_Process(float delta) { + int port = Gamepad_Connect(0x5BA, PadBind_Defaults); +} + + +/*########################################################################################################################* +*------------------------------------------------------Framebuffer--------------------------------------------------------* +*#########################################################################################################################*/ +void Window_AllocFramebuffer(struct Bitmap* bmp, int width, int height) { + bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, BITMAPCOLOR_SIZE, "window pixels"); + bmp->width = width; + bmp->height = height; +} + +#define MEM_VRAM 0x06000000 + +void Window_DrawFramebuffer(Rect2D r, struct Bitmap* bmp) { + vu16* base = (vu16*)MEM_VRAM; + + for (int y = r.y; y < r.y + r.height; y++) + { + BitmapCol* src = Bitmap_GetRow(bmp, y); + vu16* dst = base + SCREEN_WIDTH * y; + + for (int x = r.x; x < r.x + r.width; x++) + { + dst[x] = src[x]; + } + } +} + +void Window_FreeFramebuffer(struct Bitmap* bmp) { + Mem_Free(bmp->scan0); +} + + +/*########################################################################################################################* +*------------------------------------------------------Soft keyboard------------------------------------------------------* +*#########################################################################################################################*/ +void OnscreenKeyboard_Open(struct OpenKeyboardArgs* args) { +} + +void OnscreenKeyboard_SetText(const cc_string* text) { } + +void OnscreenKeyboard_Close(void) { +} + + +/*########################################################################################################################* +*-------------------------------------------------------Misc/Other--------------------------------------------------------* +*#########################################################################################################################*/ +void Window_ShowDialog(const char* title, const char* msg) { + /* TODO implement */ + Platform_LogConst(title); + Platform_LogConst(msg); +} + +cc_result Window_OpenFileDialog(const struct OpenFileDialogArgs* args) { + return ERR_NOT_SUPPORTED; +} + +cc_result Window_SaveFileDialog(const struct SaveFileDialogArgs* args) { + return ERR_NOT_SUPPORTED; +} +#endif