diff --git a/Makefile b/Makefile index 5c656e1b4..58774631a 100644 --- a/Makefile +++ b/Makefile @@ -146,6 +146,12 @@ ifeq ($(PLAT),dos) BUILD_DIR = build-dos endif +ifeq ($(PLAT),amiga_68k) + CC = m68k-amiga-elf-gcc + CFLAGS += -DPLAT_AMIGA + BUILD_DIR = build-amiga_68k +endif + ifdef SDL2 CFLAGS += -DCC_WIN_BACKEND=CC_WIN_BACKEND_SDL2 @@ -208,6 +214,8 @@ irix: $(MAKE) $(TARGET) PLAT=irix dos: $(MAKE) $(TARGET) PLAT=dos +amiga_68k: + $(MAKE) $(TARGET) PLAT=amiga_68k # Default overrides sdl2: $(MAKE) $(TARGET) SDL2=1 diff --git a/src/Core.h b/src/Core.h index c42548045..008c7507f 100644 --- a/src/Core.h +++ b/src/Core.h @@ -221,9 +221,19 @@ typedef cc_uint8 cc_bool; #define CC_BUILD_MSDOS #define CC_BUILD_COOPTHREADED #define CC_BUILD_LOWMEM + #define CC_BUILD_NOMUSIC + #define CC_BUILD_NOSOUNDS + #define DEFAULT_NET_BACKEND CC_NET_BACKEND_BUILTIN + #define DEFAULT_GFX_BACKEND CC_GFX_BACKEND_SOFTGPU +#elif defined PLAT_AMIGA + #undef CC_BUILD_FREETYPE + #define CC_BUILD_AMIGA + #define CC_BUILD_COOPTHREADED + #define CC_BUILD_LOWMEM + #define CC_BUILD_NOMUSIC + #define CC_BUILD_NOSOUNDS #define DEFAULT_NET_BACKEND CC_NET_BACKEND_BUILTIN #define DEFAULT_GFX_BACKEND CC_GFX_BACKEND_SOFTGPU - #define DEFAULT_AUD_BACKEND CC_AUD_BACKEND_OPENAL #elif defined __linux__ #define CC_BUILD_LINUX #define CC_BUILD_POSIX diff --git a/src/ExtMath.c b/src/ExtMath.c index 48a621e75..7b38fe76f 100644 --- a/src/ExtMath.c +++ b/src/ExtMath.c @@ -1,8 +1,7 @@ #include "ExtMath.h" #include "Platform.h" #include "Utils.h" -/* For abs(x) function */ -#include + #define PI 3.141592653589793238462643383279502884197169399 static const cc_uint64 _DBL_NAN = 0x7FF8000000000000ULL; @@ -10,62 +9,6 @@ static const cc_uint64 _DBL_NAN = 0x7FF8000000000000ULL; static const cc_uint64 _POS_INF = 0x7FF0000000000000ULL; #define POS_INF *((double*)&_POS_INF) -/* Sega 32x is missing these intrinsics */ -#if defined CC_BUILD_32X -#include -extern int32_t fix16_sqrt(int32_t value); - -float sqrtf(float x) { - int32_t fp_x = (int32_t)(x * (1 << 16)); - fp_x = fix16_sqrt(fp_x); - return (float)fp_x / (1 << 16); - } -#endif - - -/* Sega saturn is missing these intrinsics */ -#if defined CC_BUILD_SATURN -#include -extern int32_t fix16_sqrt(int32_t value); -static int abs(int x) { return x < 0 ? -x : x; } - -float sqrtf(float x) { - int32_t fp_x = (int32_t)(x * (1 << 16)); - fp_x = fix16_sqrt(fp_x); - return (float)fp_x / (1 << 16); - } -#endif - - -#if defined CC_BUILD_PS1 - /* PS1 is missing these intrinsics */ - #include - float Math_AbsF(float x) { return __builtin_fabsf(x); } - - float Math_SqrtF(float x) { - int fp_x = (int)(x * (1 << 12)); - fp_x = SquareRoot12(fp_x); - return (float)fp_x / (1 << 12); - } -#elif defined __GNUC__ - /* Defined in .h using builtins */ -#elif defined __TINYC__ - /* Older versions of TinyC don't support fabsf or sqrtf */ - /* Those can be used though if compiling with newer TinyC */ - /* versions for a very small performance improvement */ - #include - - float Math_AbsF(float x) { return fabs(x); } - float Math_SqrtF(float x) { return sqrt(x); } -#else - #include - - float Math_AbsF(float x) { return fabsf(x); /* MSVC intrinsic */ } - float Math_SqrtF(float x) { return sqrtf(x); /* MSVC intrinsic */ } -#endif - -float Math_Mod1(float x) { return x - (int)x; /* fmodf(x, 1); */ } -int Math_AbsI(int x) { return abs(x); /* MSVC intrinsic */ } int Math_Floor(float value) { int valueI = (int)value; @@ -125,6 +68,74 @@ cc_bool Math_IsPowOf2(int value) { return value != 0 && (value & (value - 1)) == 0; } +float Math_Mod1(float x) { return x - (int)x; /* fmodf(x, 1); */ } + + +/*########################################################################################################################* +*-------------------------------------------------------Math intrinsics---------------------------------------------------* +*#########################################################################################################################*/ +/* For abs(x) function */ +#if defined CC_BUILD_AMIGA || defined CC_BUILD_SATURN +static int abs(int x) { return x < 0 ? -x : x; } +#else +#include +#endif + +/* Sega 32x is missing these intrinsics */ +#if defined CC_BUILD_32X +#include +extern int32_t fix16_sqrt(int32_t value); + +float sqrtf(float x) { + int32_t fp_x = (int32_t)(x * (1 << 16)); + fp_x = fix16_sqrt(fp_x); + return (float)fp_x / (1 << 16); +} +#endif + + +/* Sega saturn is missing these intrinsics */ +#if defined CC_BUILD_SATURN +#include +extern int32_t fix16_sqrt(int32_t value); + +float sqrtf(float x) { + int32_t fp_x = (int32_t)(x * (1 << 16)); + fp_x = fix16_sqrt(fp_x); + return (float)fp_x / (1 << 16); +} +#endif + + +#if defined CC_BUILD_PS1 + /* PS1 is missing these intrinsics */ + #include + float Math_AbsF(float x) { return __builtin_fabsf(x); } + + float Math_SqrtF(float x) { + int fp_x = (int)(x * (1 << 12)); + fp_x = SquareRoot12(fp_x); + return (float)fp_x / (1 << 12); + } +#elif defined __GNUC__ + /* Defined in .h using builtins */ +#elif defined __TINYC__ + /* Older versions of TinyC don't support fabsf or sqrtf */ + /* Those can be used though if compiling with newer TinyC */ + /* versions for a very small performance improvement */ + #include + + float Math_AbsF(float x) { return fabs(x); } + float Math_SqrtF(float x) { return sqrt(x); } +#else + #include + + float Math_AbsF(float x) { return fabsf(x); /* MSVC intrinsic */ } + float Math_SqrtF(float x) { return sqrtf(x); /* MSVC intrinsic */ } +#endif + +int Math_AbsI(int x) { return abs(x); /* MSVC intrinsic */ } + /*########################################################################################################################* *--------------------------------------------------Random number generator------------------------------------------------* @@ -169,7 +180,7 @@ float Random_Float(RNGState* seed) { /*########################################################################################################################* -*--------------------------------------------------Transcendental functions-----------------------------------------------* +*--------------------------------------------------Trigonometric functions-----------------------------------------------* *#########################################################################################################################*/ #if defined CC_BUILD_DREAMCAST #include diff --git a/src/ExtMath.h b/src/ExtMath.h index bfe31e763..193dc5cf3 100644 --- a/src/ExtMath.h +++ b/src/ExtMath.h @@ -19,12 +19,12 @@ CC_BEGIN_HEADER #if defined __GNUC__ && defined __APPLE__ && defined _ARCH_PPC /* fabsf is single intrinsic instructions in gcc/clang */ /* (sqrtf doesn't seem to exist in 10.3 and earlier SDKs) */ - #define Math_AbsF(x) __builtin_fabsf(x) + #define Math_AbsF(x) __builtin_fabsf(x) #define Math_SqrtF(x) __builtin_sqrt(x) #elif defined __GNUC__ && !defined CC_PLAT_PS1 /* fabsf/sqrtf are single intrinsic instructions in gcc/clang */ /* (sqrtf is only when -fno-math-errno though) */ - #define Math_AbsF(x) __builtin_fabsf(x) + #define Math_AbsF(x) __builtin_fabsf(x) #define Math_SqrtF(x) __builtin_sqrtf(x) #else float Math_AbsF(float x); diff --git a/src/Platform_Amiga.c b/src/Platform_Amiga.c new file mode 100644 index 000000000..c9712fbdb --- /dev/null +++ b/src/Platform_Amiga.c @@ -0,0 +1,372 @@ +#include "Core.h" +#if defined CC_BUILD_AMIGA + +#include "_PlatformBase.h" +#include "Stream.h" +#include "ExtMath.h" +#include "SystemFonts.h" +#include "Funcs.h" +#include "Window.h" +#include "Utils.h" +#include "Errors.h" +#include "PackedCol.h" + +#include +#include +#include +#include +#include +#include + +const cc_result ReturnCode_FileShareViolation = 1000000000; +const cc_result ReturnCode_FileNotFound = 1000000; +const cc_result ReturnCode_DirectoryExists = 1000000; +const cc_result ReturnCode_SocketInProgess = 1000000; +const cc_result ReturnCode_SocketWouldBlock = 1000000; +const cc_result ReturnCode_SocketDropped = 1000000; + +const char* Platform_AppNameSuffix = " Amiga"; +cc_bool Platform_ReadonlyFilesystem; +cc_bool Platform_SingleProcess = true; + +/*########################################################################################################################* +*---------------------------------------------------------Memory----------------------------------------------------------* +*#########################################################################################################################*/ +void* Mem_Set(void* dst, cc_uint8 value, unsigned numBytes) { return memset( dst, value, numBytes); } +void* Mem_Copy(void* dst, const void* src, unsigned numBytes) { return memcpy( dst, src, numBytes); } +void* Mem_Move(void* dst, const void* src, unsigned numBytes) { return memmove(dst, src, numBytes); } + +void* Mem_TryAlloc(cc_uint32 numElems, cc_uint32 elemsSize) { + cc_uint32 size = CalcMemSize(numElems, elemsSize); + return size ? AllocVec(size, MEMF_ANY) : NULL; +} + +void* Mem_TryAllocCleared(cc_uint32 numElems, cc_uint32 elemsSize) { + cc_uint32 size = CalcMemSize(numElems, elemsSize); + return size ? AllocVec(size, MEMF_ANY | MEMF_CLEAR) : NULL; +} + +void* Mem_TryRealloc(void* mem, cc_uint32 numElems, cc_uint32 elemsSize) { + return NULL; // TODO +} + +void Mem_Free(void* mem) { + if (mem) FreeVec(mem); +} + + +/*########################################################################################################################* +*------------------------------------------------------Logging/Time-------------------------------------------------------* +*#########################################################################################################################*/ +void Platform_Log(const char* msg, int len) { + Write(Output(), msg, len); + Write(Output(), "\n", 1); +} + +TimeMS DateTime_CurrentUTC(void) { + ULONG secs, micro; + CurrentTime(&secs, µ); + // TODO epoch adjustment + return secs; +} + +void DateTime_CurrentLocal(struct cc_datetime* t) { + // TODO +} + + +/*########################################################################################################################* +*--------------------------------------------------------Stopwatch--------------------------------------------------------* +*#########################################################################################################################*/ +#define US_PER_SEC 1000000ULL + +cc_uint64 Stopwatch_Measure(void) { + ULONG secs, micro; + CurrentTime(&secs, µ); + return secs * US_PER_SEC + micro; +} + +cc_uint64 Stopwatch_ElapsedMicroseconds(cc_uint64 beg, cc_uint64 end) { + if (end < beg) return 0; + return end - beg; +} + + +/*########################################################################################################################* +*-----------------------------------------------------Directory/File------------------------------------------------------* +*#########################################################################################################################*/ +void Platform_EncodePath(cc_filepath* dst, const cc_string* path) { + char* buf = dst->buffer; + char* str = dst->buffer; + + // Amiga OS uses : to separate directories + for (int i = 0; i < path->length; i++) + { + char c = (char)path->buffer[i]; + if (c == '/') c = ':'; + *str++ = c; + } + *str = '\0'; + // TODO +} + + +void Directory_GetCachePath(cc_string* path) { } + +cc_result Directory_Create(const cc_filepath* path) { + return ERR_NOT_SUPPORTED; // TODO +} + +int File_Exists(const cc_filepath* path) { + return false; // TODO +} + +cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCallback callback) { + return ERR_NOT_SUPPORTED; // TODO +} + +cc_result File_Open(cc_file* file, const cc_filepath* path) { + return ERR_NOT_SUPPORTED; // TODO +} + +cc_result File_Create(cc_file* file, const cc_filepath* path) { + return ERR_NOT_SUPPORTED; // TODO +} + +cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) { + return ERR_NOT_SUPPORTED; // TODO +} + +cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) { + return ERR_NOT_SUPPORTED; // TODO +} + +cc_result File_Write(cc_file file, const void* data, cc_uint32 count, cc_uint32* bytesWrote) { + return ERR_NOT_SUPPORTED; // TODO +} + +cc_result File_Close(cc_file file) { + return ERR_NOT_SUPPORTED; // TODO +} + +cc_result File_Seek(cc_file file, int offset, int seekType) { + return ERR_NOT_SUPPORTED; // TODO +} + +cc_result File_Position(cc_file file, cc_uint32* pos) { + return ERR_NOT_SUPPORTED; // TODO +} + +cc_result File_Length(cc_file file, cc_uint32* len) { + return ERR_NOT_SUPPORTED; // TODO +} + + +/*########################################################################################################################* +*--------------------------------------------------------Threading--------------------------------------------------------* +*#########################################################################################################################*/ +void Thread_Sleep(cc_uint32 milliseconds) { + cc_uint32 ticks = milliseconds * 50 / 1000; + // per documentation, Delay works in 50 ticks/second + Delay(ticks); +} + +void Thread_Run(void** handle, Thread_StartFunc func, int stackSize, const char* name) { + *handle = NULL; + // TODO +} + +void Thread_Detach(void* handle) { + // TODO +} + +void Thread_Join(void* handle) { + // TODO +} + +void* Mutex_Create(const char* name) { + return NULL; +} + +void Mutex_Free(void* handle) { + // TODO +} + +void Mutex_Lock(void* handle) { + // TODO +} + +void Mutex_Unlock(void* handle) { + // TODO +} + +void* Waitable_Create(const char* name) { + return NULL; +} + +void Waitable_Free(void* handle) { + // TODO +} + +void Waitable_Signal(void* handle) { + // TODO +} + +void Waitable_Wait(void* handle) { + // TODO +} + +void Waitable_WaitFor(void* handle, cc_uint32 milliseconds) { + // TODO +} + + +/*########################################################################################################################* +*---------------------------------------------------------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; +} + + +/*########################################################################################################################* +*-----------------------------------------------------Process/Module------------------------------------------------------* +*#########################################################################################################################*/ +cc_bool Process_OpenSupported = false; +static char gameArgs[GAME_MAX_CMDARGS][STRING_SIZE]; +static int gameNumArgs; + +int Platform_GetCommandLineArgs(int argc, STRING_REF char** argv, cc_string* args) { + int count = gameNumArgs; + for (int i = 0; i < count; i++) + { + args[i] = String_FromRawArray(gameArgs[i]); + } + + // clear arguments so after game is closed, launcher is started + gameNumArgs = 0; + return count; +} + +cc_result Platform_SetDefaultCurrentDirectory(int argc, char **argv) { + return 0; +} + +cc_result Process_StartGame2(const cc_string* args, int numArgs) { + for (int i = 0; i < numArgs; i++) + { + String_CopyToRawArray(gameArgs[i], &args[i]); + } + + gameNumArgs = numArgs; + return 0; +} + +void Process_Exit(cc_result code) { + Exit(code); + for(;;) { } +} + +cc_result Process_StartOpen(const cc_string* args) { + return ERR_NOT_SUPPORTED; +} + + +/*########################################################################################################################* +*--------------------------------------------------------Updater----------------------------------------------------------* +*#########################################################################################################################*/ +cc_bool Updater_Supported = false; +cc_bool Updater_Clean(void) { return true; } + +const struct UpdaterInfo Updater_Info = { "&eCompile latest source code to update", 0 }; + +cc_result Updater_Start(const char** action) { + return ERR_NOT_SUPPORTED; +} + +cc_result Updater_GetBuildTime(cc_uint64* timestamp) { + return ERR_NOT_SUPPORTED; +} + +cc_result Updater_MarkExecutable(void) { + return ERR_NOT_SUPPORTED; +} + +cc_result Updater_SetNewBuildTime(cc_uint64 timestamp) { + return ERR_NOT_SUPPORTED; +} + + +/*########################################################################################################################* +*-------------------------------------------------------Dynamic lib-------------------------------------------------------* +*#########################################################################################################################*/ +const cc_string DynamicLib_Ext = String_FromConst(".dylib"); + +void* DynamicLib_Load2(const cc_string* path) { + return NULL; +} + +void* DynamicLib_Get2(void* lib, const char* name) { + return NULL; +} + +cc_bool DynamicLib_DescribeError(cc_string* dst) { + return false; +} + + +/*########################################################################################################################* +*--------------------------------------------------------Platform---------------------------------------------------------* +*#########################################################################################################################*/ +void Platform_Free(void) { } + +cc_bool Platform_DescribeError(cc_result res, cc_string* dst) { + // TODO + return false; +} + +void Platform_Init(void) { + SysBase = *((struct Library **)4UL); + DOSBase = OpenLibrary("dos.library", 0); +} + +cc_result Platform_Encrypt(const void* data, int len, cc_string* dst) { + return ERR_NOT_SUPPORTED; +} + +cc_result Platform_Decrypt(const void* data, int len, cc_string* dst) { + return ERR_NOT_SUPPORTED; +} + +cc_result Platform_GetEntropy(void* data, int len) { + return ERR_NOT_SUPPORTED; +} +#endif diff --git a/src/Platform_MacClassic.c b/src/Platform_MacClassic.c index 39497435f..b6f757e08 100644 --- a/src/Platform_MacClassic.c +++ b/src/Platform_MacClassic.c @@ -142,14 +142,14 @@ void DateTime_CurrentLocal(struct cc_datetime* t) { /*########################################################################################################################* *--------------------------------------------------------Stopwatch--------------------------------------------------------* *#########################################################################################################################*/ -#define MS_PER_SEC 1000000ULL +#define US_PER_SEC 1000000ULL cc_uint64 Stopwatch_Measure(void) { cc_uint64 count; if (sysVersion < 0x7000) { // 60 ticks a second count = TickCount(); - return count * MS_PER_SEC / 60; + return count * US_PER_SEC / 60; } Microseconds(&count);