From 2b34308d8dcf11d82bfc0155d5e3efdd97c74da7 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 30 Sep 2023 13:44:27 +1000 Subject: [PATCH] Dreamcast: Hopefully get github actions build to work --- .github/workflows/build_dreamcast.yml | 9 ++++++++- src/IsometricDrawer.c | 1 - src/Platform_Dreamcast.c | 25 +++++++++++++++++++++++-- third_party/gldc/Makefile | 2 +- third_party/gldc/src/matrix.c | 27 --------------------------- third_party/gldc/src/sh4.c | 6 +++--- 6 files changed, 35 insertions(+), 35 deletions(-) delete mode 100644 third_party/gldc/src/matrix.c diff --git a/.github/workflows/build_dreamcast.yml b/.github/workflows/build_dreamcast.yml index 572731d16..72d2b881c 100644 --- a/.github/workflows/build_dreamcast.yml +++ b/.github/workflows/build_dreamcast.yml @@ -17,6 +17,7 @@ jobs: id: compile run: | source /opt/toolchains/dc/kos/environ.sh + export PATH=/opt/toolchains/dc/kos/utils/img4dc/build/cdi4dc/:$PATH make dreamcast - uses: ./.github/actions/notify_failure @@ -24,7 +25,13 @@ jobs: with: NOTIFY_MESSAGE: 'Failed to compile Dreamcast build' WEBHOOK_URL: '${{ secrets.WEBHOOK_URL }}' - + + - uses: ./.github/actions/upload_build + if: ${{ always() && steps.compile.outcome == 'success' }} + with: + SOURCE_FILE: 'ClassiCube-dc.elf' + DEST_NAME: 'ClassiCube-dc.elf' + - uses: ./.github/actions/upload_build if: ${{ always() && steps.compile.outcome == 'success' }} with: diff --git a/src/IsometricDrawer.c b/src/IsometricDrawer.c index 471ed49ec..ea65bf284 100644 --- a/src/IsometricDrawer.c +++ b/src/IsometricDrawer.c @@ -124,7 +124,6 @@ void IsometricDrawer_BeginBatch(struct VertexTextured* vertices, int* state) { } void IsometricDrawer_AddBatch(BlockID block, float size, float x, float y) { - struct VertexTextured* beg = iso_vertices; if (Blocks.Draw[block] == DRAW_GAS) return; iso_posX = x; iso_posY = y; diff --git a/src/Platform_Dreamcast.c b/src/Platform_Dreamcast.c index 8486ee76d..62bc23ea6 100644 --- a/src/Platform_Dreamcast.c +++ b/src/Platform_Dreamcast.c @@ -36,10 +36,31 @@ cc_uint64 Stopwatch_ElapsedMicroseconds(cc_uint64 beg, cc_uint64 end) { if (end < beg) return 0; return (end - beg) / 1000; } +// Borrowed from kos/kernel/arch/dreamcast/kernel/timer.c so it compiles +// with older toolchain versions +#define _PMCR_CTRL_0 ( *((volatile uint16*)(0xff000084)) ) +#define _PMCTR_HIGH_0 ( *((volatile uint32*)(0xff100004)) ) +#define _PMCTR_LOW_0 ( *((volatile uint32*)(0xff100008)) ) +#define _PMCR_CLR 0x2000 +#define _PMCR_PMENABLE 0x8000 +#define _PMCR_RUN 0xc000 +#define _PMCR_PMM_MASK 0x003f +#define _PMCR_CLOCK_TYPE_SHIFT 8 +#define _NS_PER_CYCLE 5 +#define _PMCR_COUNT_CPU_CYCLES 0 +#define _PMCR_ELAPSED_TIME_MODE 0x23 cc_uint64 Stopwatch_Measure(void) { - return timer_ns_gettime64(); + uint64 cycles = (uint64)(_PMCTR_HIGH_0 & 0xFFFF) << 32 | _PMCTR_LOW_0; + return cycles * _NS_PER_CYCLE; } +static void Stopwatch_Init(void) { + _PMCR_CTRL_0 &= ~(_PMCR_PMM_MASK | _PMCR_PMENABLE); + _PMCR_CTRL_0 |= _PMCR_CLR; + _PMCR_CTRL_0 = _PMCR_RUN | _PMCR_ELAPSED_TIME_MODE | (_PMCR_COUNT_CPU_CYCLES << _PMCR_CLOCK_TYPE_SHIFT); +} +// NOTE: If using newer toolchain versions, only need this: +// cc_uint64 Stopwatch_Measure(void) { return timer_ns_gettime64(); } void Platform_Log(const char* msg, int len) { fs_write(STDOUT_FILENO, msg, len); @@ -420,7 +441,7 @@ cc_result Process_StartOpen(const cc_string* args) { } void Platform_Init(void) { - /*pspDebugSioInit();*/ + Stopwatch_Init(); char cwd[600] = { 0 }; char* ptr = getcwd(cwd, 600); diff --git a/third_party/gldc/Makefile b/third_party/gldc/Makefile index 1cf2e82d0..09f3181ae 100644 --- a/third_party/gldc/Makefile +++ b/third_party/gldc/Makefile @@ -3,7 +3,7 @@ SOURCE_DIRS := src src/yalloc C_FILES := $(foreach dir,$(SOURCE_DIRS),$(wildcard $(dir)/*.c)) OBJS := $(notdir $(C_FILES:%.c=%.o)) -C_FLAGS = -O3 -DNDEBUG -mfsrra -mfsca -ffp-contract=fast -ffast-math -O3 -mpretend-cmove -fexpensive-optimizations -fomit-frame-pointer -finline-functions -ml -m4-single-only -ffunction-sections -fdata-sections -std=gnu99 +C_FLAGS = -O3 -DNDEBUG -mfsrra -mfsca -fno-math-errno -ffp-contract=fast -ffast-math -O3 -mpretend-cmove -fexpensive-optimizations -fomit-frame-pointer -finline-functions -ml -m4-single-only -ffunction-sections -fdata-sections -std=gnu99 C_DEFINES = -DDREAMCAST -DNDEBUG -D__DREAMCAST__ -D__arch_dreamcast -D_arch_dreamcast -D_arch_sub_pristine diff --git a/third_party/gldc/src/matrix.c b/third_party/gldc/src/matrix.c deleted file mode 100644 index d0771fb17..000000000 --- a/third_party/gldc/src/matrix.c +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include -#include - -#include "private.h" - -Viewport VIEWPORT = { - 0, 0, 640, 480, 320.0f, 240.0f, 320.0f, 240.0f -}; - -void _glInitMatrices() { - const VideoMode* vid_mode = GetVideoMode(); - - glViewport(0, 0, vid_mode->width, vid_mode->height); -} - -/* Set the GL viewport */ -void APIENTRY glViewport(GLint x, GLint y, GLsizei width, GLsizei height) { - VIEWPORT.x = x; - VIEWPORT.y = y; - VIEWPORT.width = width; - VIEWPORT.height = height; - VIEWPORT.hwidth = ((GLfloat) VIEWPORT.width) * 0.5f; - VIEWPORT.hheight = ((GLfloat) VIEWPORT.height) * 0.5f; - VIEWPORT.x_plus_hwidth = VIEWPORT.x + VIEWPORT.hwidth; - VIEWPORT.y_plus_hheight = VIEWPORT.y + VIEWPORT.hheight; -} diff --git a/third_party/gldc/src/sh4.c b/third_party/gldc/src/sh4.c index 693f57dc6..1ee0f2304 100644 --- a/third_party/gldc/src/sh4.c +++ b/third_party/gldc/src/sh4.c @@ -37,7 +37,7 @@ void InitGPU(_Bool autosort, _Bool fsaa) { } GL_FORCE_INLINE float _glFastInvert(float x) { - return (1.f / __builtin_sqrtf(x * x)); + return MATH_fsrra(x * x); } GL_FORCE_INLINE void _glPerspectiveDivideVertex(Vertex* vertex, const float h) { @@ -92,7 +92,7 @@ static inline void _glClipEdge(const Vertex* const v1, const Vertex* const v2, V const static float o = 0.003921569f; // 1 / 255 const float d0 = v1->w + v1->xyz[2]; const float d1 = v2->w + v2->xyz[2]; - const float t = (fabs(d0) * (1.0f / sqrtf((d1 - d0) * (d1 - d0)))) + 0.000001f; + const float t = (fabs(d0) * MATH_fsrra((d1 - d0) * (d1 - d0))) + 0.000001f; const float invt = 1.0f - t; vout->xyz[0] = invt * v1->xyz[0] + t * v2->xyz[0]; @@ -434,4 +434,4 @@ void SceneListSubmit(Vertex* v2, int n) { } _glFlushBuffer(); -} +} \ No newline at end of file