Saturn: Black screen that doesn't work

This commit is contained in:
UnknownShadow200 2024-04-18 19:18:05 +10:00
parent dbbcf8bcd8
commit ce7d07944a
8 changed files with 715 additions and 12 deletions

2
.gitignore vendored
View file

@ -31,6 +31,8 @@ build-switch/
classicube.nds
# SEGA console build results
build-dc/
build-saturn/
cd/
# Microsoft console build results
build-360/
# Sony console build results

View file

@ -139,6 +139,8 @@ irix:
# separate makefiles to avoid having one giant messy makefile
dreamcast:
$(MAKE) -f misc/dreamcast/Makefile
saturn:
$(MAKE) -f misc/saturn/Makefile
psp:
$(MAKE) -f misc/psp/Makefile
vita:

28
misc/saturn/Makefile Normal file
View file

@ -0,0 +1,28 @@
ifeq ($(strip $(YAUL_INSTALL_ROOT)),)
$(error Undefined YAUL_INSTALL_ROOT (install root directory))
endif
SH_BUILD_DIR := build-saturn
include $(YAUL_INSTALL_ROOT)/share/build.pre.mk
# Each asset follows the format: <path>;<symbol>. Duplicates are removed
BUILTIN_ASSETS=
SH_PROGRAM := ClassiCube
SH_SRCS := $(wildcard src/*.c)
SH_CFLAGS+= -Os -I. -DPLAT_SATURN
SH_LDFLAGS+=
IP_VERSION:= V1.000
IP_RELEASE_DATE:= 20160101
IP_AREAS:= JTUBKAEL
IP_PERIPHERALS:= JAMKST
IP_TITLE:= VDP1 drawing
IP_MASTER_STACK_ADDR:= 0x06004000
IP_SLAVE_STACK_ADDR:= 0x06001E00
IP_1ST_READ_ADDR:= 0x06004000
IP_1ST_READ_SIZE:= 0
include $(YAUL_INSTALL_ROOT)/share/build.post.iso-cue.mk

View file

@ -375,6 +375,16 @@ typedef cc_uint8 cc_bool;
#define CC_BUILD_SDL2
#define CC_BUILD_CURL
#define CC_BUILD_FREETYPE
#elif defined PLAT_SATURN
#define CC_BUILD_SATURN
#define CC_BUILD_CONSOLE
#define CC_BUILD_LOWMEM
#define CC_BUILD_COOPTHREADED
#define CC_BUILD_NOMUSIC
#define CC_BUILD_NOSOUNDS
#undef CC_BUILD_RESOURCES
#undef CC_BUILD_NETWORKING
#undef CC_BUILD_ANIMATIONS /* Very costly in FPU less system */
#endif
#endif

View file

@ -4,22 +4,37 @@
/* For abs(x) function */
#include <stdlib.h>
#if defined PLAT_PS1
#include <psxgte.h>
float Math_AbsF(float x) { return __builtin_fabsf(x); }
/* Sega saturn is missing these intrinsics */
#ifdef CC_BUILD_SATURN
#include <stdint.h>
extern int32_t fix16_sqrt(int32_t value);
static int abs(int x) { return x < 0 ? -x : x; }
float Math_SqrtF(float x) {
int fp_x = (int)(x * (1 << 12));
fp_x = SquareRoot12(fp_x);
return (float)fp_x / (1 << 12);
}
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 <psxgte.h>
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 */
/* Defined in .h using builtins */
#else
#include <math.h>
#include <math.h>
float Math_AbsF(float x) { return fabsf(x); /* MSVC intrinsic */ }
float Math_SqrtF(float x) { return sqrtf(x); /* MSVC intrinsic */ }
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); */ }

276
src/Graphics_Saturn.c Normal file
View file

@ -0,0 +1,276 @@
#include "Core.h"
#if defined CC_BUILD_SATURN
#include "_GraphicsBase.h"
#include "Errors.h"
#include "Window.h"
#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#include <yaul.h>
static GfxResourceID white_square;
void Gfx_RestoreState(void) {
InitDefaultResources();
// 2x2 dummy white texture
struct Bitmap bmp;
BitmapCol pixels[4] = { BitmapColor_RGB(255, 0, 0), BITMAPCOLOR_WHITE, BITMAPCOLOR_WHITE, BITMAPCOLOR_WHITE };
Bitmap_Init(bmp, 2, 2, pixels);
white_square = Gfx_CreateTexture(&bmp, 0, false);
}
void Gfx_FreeState(void) {
FreeDefaultResources();
Gfx_DeleteTexture(&white_square);
}
void Gfx_Create(void) {
Gfx.MaxTexWidth = 128;
Gfx.MaxTexHeight = 128;
Gfx.Created = true;
}
void Gfx_Free(void) {
Gfx_FreeState();
}
/*########################################################################################################################*
*---------------------------------------------------------Textures--------------------------------------------------------*
*#########################################################################################################################*/
static GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, cc_uint8 flags, cc_bool mipmaps) {
return NULL;
}
void Gfx_BindTexture(GfxResourceID texId) {
}
void Gfx_DeleteTexture(GfxResourceID* texId) {
}
void Gfx_UpdateTexture(GfxResourceID texId, int x, int y, struct Bitmap* part, int rowWidth, cc_bool mipmaps) {
// TODO
}
void Gfx_UpdateTexturePart(GfxResourceID texId, int x, int y, struct Bitmap* part, cc_bool mipmaps) {
Gfx_UpdateTexture(texId, x, y, part, part->width, mipmaps);
}
void Gfx_EnableMipmaps(void) { }
void Gfx_DisableMipmaps(void) { }
/*########################################################################################################################*
*------------------------------------------------------State management---------------------------------------------------*
*#########################################################################################################################*/
void Gfx_SetFog(cc_bool enabled) { }
void Gfx_SetFogCol(PackedCol col) { }
void Gfx_SetFogDensity(float value) { }
void Gfx_SetFogEnd(float value) { }
void Gfx_SetFogMode(FogFunc func) { }
void Gfx_SetFaceCulling(cc_bool enabled) {
// TODO
}
void Gfx_SetAlphaTest(cc_bool enabled) {
}
void Gfx_SetAlphaBlending(cc_bool enabled) {
}
void Gfx_SetAlphaArgBlend(cc_bool enabled) { }
void Gfx_ClearBuffers(GfxBuffers buffers) {
}
void Gfx_ClearColor(PackedCol color) {
// TODO
}
void Gfx_SetDepthTest(cc_bool enabled) {
}
void Gfx_SetDepthWrite(cc_bool enabled) {
// TODO
}
static void SetColorWrite(cc_bool r, cc_bool g, cc_bool b, cc_bool a) {
// TODO
}
void Gfx_DepthOnlyRendering(cc_bool depthOnly) {
cc_bool enabled = !depthOnly;
SetColorWrite(enabled & gfx_colorMask[0], enabled & gfx_colorMask[1],
enabled & gfx_colorMask[2], enabled & gfx_colorMask[3]);
}
/*########################################################################################################################*
*-------------------------------------------------------Index buffers-----------------------------------------------------*
*#########################################################################################################################*/
GfxResourceID Gfx_CreateIb2(int count, Gfx_FillIBFunc fillFunc, void* obj) {
return (void*)1;
}
void Gfx_BindIb(GfxResourceID ib) { }
void Gfx_DeleteIb(GfxResourceID* ib) { }
/*########################################################################################################################*
*-------------------------------------------------------Vertex buffers----------------------------------------------------*
*#########################################################################################################################*/
static void* gfx_vertices;
static GfxResourceID Gfx_AllocStaticVb(VertexFormat fmt, int count) {
return Mem_TryAlloc(count, strideSizes[fmt]);
}
void Gfx_BindVb(GfxResourceID vb) { gfx_vertices = vb; }
void Gfx_DeleteVb(GfxResourceID* vb) {
GfxResourceID data = *vb;
if (data) Mem_Free(data);
*vb = 0;
}
void* Gfx_LockVb(GfxResourceID vb, VertexFormat fmt, int count) {
return vb;
}
void Gfx_UnlockVb(GfxResourceID vb) {
gfx_vertices = vb;
}
static GfxResourceID Gfx_AllocDynamicVb(VertexFormat fmt, int maxVertices) {
return Mem_TryAlloc(maxVertices, strideSizes[fmt]);
}
void Gfx_BindDynamicVb(GfxResourceID vb) { Gfx_BindVb(vb); }
void* Gfx_LockDynamicVb(GfxResourceID vb, VertexFormat fmt, int count) {
return vb;
}
void Gfx_UnlockDynamicVb(GfxResourceID vb) {
gfx_vertices = vb;
}
void Gfx_DeleteDynamicVb(GfxResourceID* vb) { Gfx_DeleteVb(vb); }
/*########################################################################################################################*
*---------------------------------------------------------Matrices--------------------------------------------------------*
*#########################################################################################################################*/
static struct Matrix _view, _proj, mvp;
void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) {
if (type == MATRIX_VIEW) _view = *matrix;
if (type == MATRIX_PROJECTION) _proj = *matrix;
Matrix_Mul(&mvp, &_view, &_proj);
}
void Gfx_LoadIdentityMatrix(MatrixType type) {
Gfx_LoadMatrix(type, &Matrix_Identity);
}
void Gfx_EnableTextureOffset(float x, float y) {
// TODO
}
void Gfx_DisableTextureOffset(void) {
// TODO
}
void Gfx_CalcOrthoMatrix(struct Matrix* matrix, float width, float height, float zNear, float zFar) {
/* Source https://learn.microsoft.com/en-us/windows/win32/direct3d9/d3dxmatrixorthooffcenterrh */
/* The simplified calculation below uses: L = 0, R = width, T = 0, B = height */
/* NOTE: This calculation is shared with Direct3D 11 backend */
*matrix = Matrix_Identity;
matrix->row1.x = 2.0f / width;
matrix->row2.y = -2.0f / height;
matrix->row3.z = 1.0f / (zNear - zFar);
matrix->row4.x = -1.0f;
matrix->row4.y = 1.0f;
matrix->row4.z = zNear / (zNear - zFar);
}
static double Cotangent(double x) { return Math_Cos(x) / Math_Sin(x); }
void Gfx_CalcPerspectiveMatrix(struct Matrix* matrix, float fov, float aspect, float zFar) {
float zNear = 0.01f;
/* Source https://learn.microsoft.com/en-us/windows/win32/direct3d9/d3dxmatrixperspectivefovrh */
float c = (float)Cotangent(0.5f * fov);
*matrix = Matrix_Identity;
matrix->row1.x = c / aspect;
matrix->row2.y = c;
matrix->row3.z = zFar / (zNear - zFar);
matrix->row3.w = -1.0f;
matrix->row4.z = (zNear * zFar) / (zNear - zFar);
matrix->row4.w = 0.0f;
}
/*########################################################################################################################*
*---------------------------------------------------------Rendering-------------------------------------------------------*
*#########################################################################################################################*/
void Gfx_SetVertexFormat(VertexFormat fmt) {
gfx_format = fmt;
gfx_stride = strideSizes[fmt];
}
void Gfx_DrawVb_Lines(int verticesCount) {
}
void Gfx_DrawVb_IndexedTris_Range(int verticesCount, int startVertex) {
}
void Gfx_DrawVb_IndexedTris(int verticesCount) {
}
void Gfx_DrawIndexedTris_T2fC4b(int verticesCount, int startVertex) {
}
/*########################################################################################################################*
*---------------------------------------------------------Other/Misc------------------------------------------------------*
*#########################################################################################################################*/
cc_result Gfx_TakeScreenshot(struct Stream* output) {
return ERR_NOT_SUPPORTED;
}
cc_bool Gfx_WarnIfNecessary(void) {
return false;
}
void Gfx_BeginFrame(void) {
}
void Gfx_EndFrame(void) {
if (gfx_minFrameMs) LimitFPS();
}
void Gfx_SetFpsLimit(cc_bool vsync, float minFrameMs) {
gfx_minFrameMs = minFrameMs;
gfx_vsync = vsync;
}
void Gfx_OnWindowResize(void) {
// TODO
}
void Gfx_GetApiInfo(cc_string* info) {
String_AppendConst(info, "-- Using Saturn --\n");
PrintMaxTextureInfo(info);
}
cc_bool Gfx_TryRestoreContext(void) { return true; }
#endif

240
src/Platform_Saturn.c Normal file
View file

@ -0,0 +1,240 @@
#include "Core.h"
#if defined PLAT_SATURN
#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 "PackedCol.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <yaul.h>
void* calloc(size_t num, size_t size) {
void* ptr = malloc(num * size);
if (ptr) memset(ptr, 0, num * size);
return ptr;
}
#include "_PlatformConsole.h"
const cc_result ReturnCode_FileShareViolation = 1000000000; // not used
const cc_result ReturnCode_FileNotFound = 99999;
const cc_result ReturnCode_DirectoryExists = 99999;
const cc_result ReturnCode_SocketInProgess = -1;
const cc_result ReturnCode_SocketWouldBlock = -1;
const char* Platform_AppNameSuffix = " Saturn";
/*########################################################################################################################*
*------------------------------------------------------Logging/Time-------------------------------------------------------*
*#########################################################################################################################*/
void Platform_Log(const char* msg, int len) {
char tmp[2048 + 1];
len = min(len, 2048);
Mem_Copy(tmp, msg, len); tmp[len] = '\0';
dbgio_printf("%s\n", tmp);
dbgio_flush();
}
TimeMS DateTime_CurrentUTC(void) {
return 0;
}
void DateTime_CurrentLocal(struct DateTime* t) {
Mem_Set(t, 0, sizeof(struct DateTime));
}
/*########################################################################################################################*
*--------------------------------------------------------Stopwatch--------------------------------------------------------*
*#########################################################################################################################*/
static volatile cc_uint32 overflow_count;
cc_uint64 Stopwatch_Measure(void) {
return cpu_frt_count_get() + (overflow_count * 65536);
}
cc_uint64 Stopwatch_ElapsedMicroseconds(cc_uint64 beg, cc_uint64 end) {
if (end < beg) return 0;
return (end - beg); // TODO measure time
}
static void ovf_handler(void) { overflow_count++; }
static void Stopwatch_Init(void) {
cpu_frt_init(CPU_FRT_CLOCK_DIV_8);
cpu_frt_ovi_set(ovf_handler);
cpu_frt_interrupt_priority_set(15);
cpu_frt_count_set(0);
}
/*########################################################################################################################*
*-----------------------------------------------------Directory/File------------------------------------------------------*
*#########################################################################################################################*/
cc_result Directory_Create(const cc_string* path) {
return ERR_NOT_SUPPORTED;
}
int File_Exists(const cc_string* path) {
return ERR_NOT_SUPPORTED;
}
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_string* path) {
return ERR_NOT_SUPPORTED;
}
cc_result File_Create(cc_file* file, const cc_string* path) {
return ERR_NOT_SUPPORTED;
}
cc_result File_OpenOrCreate(cc_file* file, const cc_string* 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--------------------------------------------------------*
*#########################################################################################################################*/
void Thread_Sleep(cc_uint32 milliseconds) {
// TODO sleep a bit
}
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(void) {
return NULL;
}
void Mutex_Free(void* handle) {
}
void Mutex_Lock(void* handle) {
}
void Mutex_Unlock(void* handle) {
}
void* Waitable_Create(void) {
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_Connect(cc_socket* s, cc_sockaddr* addr, cc_bool nonblocking) {
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) {
dbgio_init();
dbgio_dev_default_init(DBGIO_DEV_VDP2_ASYNC);
dbgio_dev_font_load();
Stopwatch_Init();
Options_SetBool(OPT_USE_CHAT_FONT, true);
}
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--------------------------------------------------------*
*#########################################################################################################################*/
static cc_result GetMachineID(cc_uint32* key) {
return ERR_NOT_SUPPORTED;
}
#endif

130
src/Window_Saturn.c Normal file
View file

@ -0,0 +1,130 @@
#include "Core.h"
#if defined CC_BUILD_SATURN
#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 "Logger.h"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <yaul.h>
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 224
static cc_bool launcherMode;
struct _DisplayData DisplayInfo;
struct _WindowData WindowInfo;
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;
Input.Sources = INPUT_SOURCE_GAMEPAD;
DisplayInfo.ContentOffsetX = 10;
DisplayInfo.ContentOffsetY = 10;
vdp2_tvmd_display_res_set(VDP2_TVMD_INTERLACE_NONE, VDP2_TVMD_HORZ_NORMAL_A, VDP2_TVMD_VERT_224);
vdp2_scrn_back_color_set(VDP2_VRAM_ADDR(3, 0x01FFFE), RGB1555(1, 0, 3, 15));
vdp2_tvmd_display_set();
}
void Window_Free(void) { }
void Window_Create3D(int width, int height) {
launcherMode = false;
}
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(double delta) {
}
void Cursor_SetPosition(int x, int y) { } // Makes no sense for PS Vita
void Window_EnableRawMouse(void) { Input.RawMode = true; }
void Window_UpdateRawMouse(void) { }
void Window_DisableRawMouse(void) { Input.RawMode = false; }
/*########################################################################################################################*
*------------------------------------------------------Framebuffer--------------------------------------------------------*
*#########################################################################################################################*/
void Window_Create2D(int width, int height) {
launcherMode = true;
}
void Window_AllocFramebuffer(struct Bitmap* bmp) {
bmp->scan0 = (BitmapCol*)Mem_Alloc(bmp->width * bmp->height, 4, "window pixels");
}
void Window_DrawFramebuffer(Rect2D r, struct Bitmap* bmp) {
vdp2_sync();
vdp2_sync_wait();
}
void Window_FreeFramebuffer(struct Bitmap* bmp) {
Mem_Free(bmp->scan0);
}
/*########################################################################################################################*
*------------------------------------------------------Soft keyboard------------------------------------------------------*
*#########################################################################################################################*/
void OnscreenKeyboard_Open(struct OpenKeyboardArgs* args) { /* TODO implement */ }
void OnscreenKeyboard_SetText(const cc_string* text) { }
void OnscreenKeyboard_Draw2D(Rect2D* r, struct Bitmap* bmp) { }
void OnscreenKeyboard_Draw3D(void) { }
void OnscreenKeyboard_Close(void) { /* TODO implement */ }
/*########################################################################################################################*
*-------------------------------------------------------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