Merge pull request #1205 from EGAMatsu/master

Preliminary MacOS Classic Work (It runs, just not good)
This commit is contained in:
UnknownShadow200 2024-06-03 17:25:30 +10:00 committed by GitHub
commit 6fbc7a6301
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 110 additions and 13 deletions

View file

@ -30,8 +30,8 @@ const cc_result ReturnCode_SocketInProgess = EINPROGRESS;
const cc_result ReturnCode_SocketWouldBlock = EWOULDBLOCK;
const cc_result ReturnCode_DirectoryExists = EEXIST;
const char* Platform_AppNameSuffix = "";
cc_bool Platform_SingleProcess;
const char* Platform_AppNameSuffix = "MAC68k";
cc_bool Platform_SingleProcess = true;
/*########################################################################################################################*
*---------------------------------------------------------Memory----------------------------------------------------------*
@ -76,8 +76,8 @@ void Mem_Free(void* mem) {
*------------------------------------------------------Logging/Time-------------------------------------------------------*
*#########################################################################################################################*/
void Platform_Log(const char* msg, int len) {
write(STDOUT_FILENO, msg, len);
write(STDOUT_FILENO, "\n", 1);
//write(STDOUT_FILENO, msg, len);
//write(STDOUT_FILENO, "\n", 1);
}
TimeMS DateTime_CurrentUTC(void) {
@ -115,6 +115,12 @@ cc_uint64 Stopwatch_ElapsedMicroseconds(cc_uint64 beg, cc_uint64 end) {
return (end - beg) / 1000;
}
void Stopwatch_Init(void) {
//TODO
cc_uint64 doSomething = Stopwatch_Measure();
}
/*########################################################################################################################*
*-----------------------------------------------------Directory/File------------------------------------------------------*
@ -188,7 +194,7 @@ cc_result File_Length(cc_file file, cc_uint32* len) {
*--------------------------------------------------------Threading--------------------------------------------------------*
*#########################################################################################################################*/
void Thread_Sleep(cc_uint32 milliseconds) {
// TODO Delay API
// TODO Delay API
}
void Thread_Run(void** handle, Thread_StartFunc func, int stackSize, const char* name) {
@ -307,6 +313,7 @@ static cc_result Process_RawStart(const char* path, char** argv) {
static cc_result Process_RawGetExePath(char* path, int* len);
/*
cc_result Process_StartGame2(const cc_string* args, int numArgs) {
char raw[GAME_MAX_CMDARGS][NATIVE_STR_LEN];
char path[NATIVE_STR_LEN];
@ -326,6 +333,24 @@ cc_result Process_StartGame2(const cc_string* args, int numArgs) {
argv[j] = NULL;
return Process_RawStart(path, argv);
}
*/
static char gameArgs[GAME_MAX_CMDARGS][STRING_SIZE];
static int gameNumArgs;
static cc_bool gameHasArgs;
cc_result Process_StartGame2(const cc_string* args, int numArgs) {
for (int i = 0; i < numArgs; i++)
{
String_CopyToRawArray(gameArgs[i], &args[i]);
}
Platform_LogConst("START CLASSICUBE");
gameHasArgs = true;
gameNumArgs = numArgs;
return 0;
}
void Process_Exit(cc_result code) { exit(code); }
cc_result Process_StartOpen(const cc_string* args) {
@ -412,8 +437,16 @@ cc_bool Platform_DescribeError(cc_result res, cc_string* dst) {
}
#endif
void Platform_Init(void) {
static void Platform_InitSpecific(void) {
Platform_SingleProcess = true;
}
void Platform_Init(void) {
printf("Macintosh ClassiCube has started to init.\n"); // Test, just to see if it's actually *running* at all.
Platform_LoadSysFonts();
Stopwatch_Init();
Platform_ReadonlyFilesystem = true;
}
cc_result Platform_Encrypt(const void* data, int len, cc_string* dst) {

View file

@ -13,14 +13,34 @@
#include <Quickdraw.h>
#include <Dialogs.h>
#include <Fonts.h>
#include <Events.h>
static WindowPtr win;
Rect r;
BitMap bitmapScreen;
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 224
static cc_bool launcherMode = true;
/*########################################################################################################################*
*--------------------------------------------------Public implementation--------------------------------------------------*
*#########################################################################################################################*/
void Window_PreInit(void) { }
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;
InitGraf(&qd.thePort);
InitFonts();
InitWindows();
@ -30,16 +50,21 @@ void Window_Init(void) {
void Window_Free(void) { }
static void DoCreateWindow(int width, int height) {
Rect r = qd.screenBits.bounds;
r = qd.screenBits.bounds;
Rect windR;
/* TODO: Make less-crap method of getting center. */
int centerX = r.right/2; int centerY = r.bottom/2;
int ww = (SCREEN_WIDTH/2); int hh = (SCREEN_HEIGHT/2);
SetRect(&bitmapScreen.bounds, 0, 0, width, height);
// TODO
SetRect(&r, r.left + 5, r.top + 45, r.right - 5, r.bottom - 5);
win = NewWindow(NULL, &r, "\pClassiCube", true, 0, (WindowPtr)-1, false, 0);
SetRect(&windR, centerX-ww, centerY-hh, centerX+ww, centerY+hh);
win = NewWindow(NULL, &windR, "\pClassiCube", true, 0, (WindowPtr)-1, false, 0);
SetPort(win);
}
void Window_Create2D(int width, int height) { DoCreateWindow(width, height); }
void Window_Create3D(int width, int height) { DoCreateWindow(width, height); }
void Window_Create2D(int width, int height) { launcherMode=true; DoCreateWindow(width, height); }
void Window_Create3D(int width, int height) { launcherMode=false; DoCreateWindow(width, height); }
void Window_SetTitle(const cc_string* title) {
// TODO
@ -86,7 +111,20 @@ void Window_ProcessEvents(float delta) {
// TODO
}
void Window_ProcessGamepads(float delta) { }
short isPressed(unsigned short k) {
unsigned char km[16];
GetKeys((long *)km);
return ((km[k>>3] >> (k&7) ) &1);
}
int theKeys;
void Window_ProcessGamepads(float delta) {
GetKeys(theKeys);
Gamepad_SetButton(0, CCPAD_UP, isPressed(0x0D));
Gamepad_SetButton(0, CCPAD_DOWN, isPressed(0x01));
Gamepad_SetButton(0, CCPAD_START, isPressed(0x24));
}
static void Cursor_GetRawPos(int* x, int* y) {
// TODO
@ -118,8 +156,34 @@ void Window_AllocFramebuffer(struct Bitmap* bmp) {
bmp->scan0 = (BitmapCol*)Mem_Alloc(bmp->width * bmp->height, 4, "window pixels");
}
#define GetWindowPort(w) w
void Window_DrawFramebuffer(Rect2D r, struct Bitmap* bmp) {
// TODO
// Grab Window port.
GrafPtr thePort = GetWindowPort(win);
int ww = bmp->width;
int hh = bmp->height;
// Iterate through each pixel
for (int y = r.y; y < r.y + r.height; ++y) {
BitmapCol* row = Bitmap_GetRow(bmp, y);
for (int x = r.x; x < r.x + r.width; ++x) {
// TODO optimise
BitmapCol col = row[x];
cc_uint8 R = BitmapCol_R(col);
cc_uint8 G = BitmapCol_G(col);
cc_uint8 B = BitmapCol_B(col);
// Set the pixel color in the window
RGBColor pixelColor;
pixelColor.red = R * 256;
pixelColor.green = G * 256;
pixelColor.blue = B * 256;
RGBForeColor(&pixelColor);
MoveTo(x, y);
Line(0, 0);
}
}
}
void Window_FreeFramebuffer(struct Bitmap* bmp) {