diff --git a/src/GameEngine.h b/src/GameEngine.h index 6206946..ebd84ef 100644 --- a/src/GameEngine.h +++ b/src/GameEngine.h @@ -16,7 +16,7 @@ extern const uint16_t PerfectScore; typedef struct GameEngine { - int8_t Level; + int8_t Level; uint32_t Lights; uint16_t Par; uint16_t Moves; diff --git a/src/GameWindow.c b/src/GameWindow.c new file mode 100644 index 0000000..fd6e848 --- /dev/null +++ b/src/GameWindow.c @@ -0,0 +1,29 @@ +// Copyright (c) Jon Thysell +// Licensed under the MIT License. + +#include "GameWindow.h" + +void GameWindow_Init(GameWindow *gameWindow) +{ + if (gameWindow->Window != nil) + { + ShowError("\pGameWindow already initialized!", false); + } + + gameWindow->Window = GetNewWindow(kBaseResID, nil, kMoveToFront); + + if (gameWindow->Window == nil) + { + ShowError("\pGameWindow resource WIND kBaseResID missing!", true); + } + + CenterWindow(gameWindow->Window); + + ShowWindow(gameWindow->Window); + SetPort(gameWindow->Window); + + MoveTo(10, 20); + DrawString("\pHello MacLO"); +} + + diff --git a/src/GameWindow.h b/src/GameWindow.h new file mode 100644 index 0000000..42a9034 --- /dev/null +++ b/src/GameWindow.h @@ -0,0 +1,16 @@ +// Copyright (c) Jon Thysell +// Licensed under the MIT License. + +#ifndef GAMEWINDOW_H +#define GAMEWINDOW_H + +#include "MacCommon.h" + +typedef struct GameWindow +{ + WindowPtr Window; +} GameWindow; + +void GameWindow_Init(GameWindow *gameWindow); + +#endif diff --git a/src/MacCommon.c b/src/MacCommon.c new file mode 100644 index 0000000..8a0d4ba --- /dev/null +++ b/src/MacCommon.c @@ -0,0 +1,26 @@ +// Copyright (c) Jon Thysell +// Licensed under the MIT License. + +#include "MacCommon.h" + +void CenterWindow(WindowPtr window) +{ + +} + +Boolean IsCompactDisplay() +{ + return screenBits.bounds.right == 512 + && screenBits.bounds.bottom == 342; +} + +void ShowError(Str255 message, Boolean isFatal) +{ + ParamText(message, kEmptyString, kEmptyString, kEmptyString); + StopAlert(kErrorAlertID, kNilFilterProc); + + if (isFatal) + { + ExitToShell(); + } +} diff --git a/src/MacCommon.h b/src/MacCommon.h index 865a0d0..c7b5ec9 100644 --- a/src/MacCommon.h +++ b/src/MacCommon.h @@ -4,7 +4,16 @@ #ifndef MACCOMMON_H #define MACCOMMON_H -#define kBaseResID 128 -#define kMoveToFront (WindowPtr)-1L +#define kBaseResID 128 +#define kMoveToFront (WindowPtr)-1L + +#define kEmptyString "\p" +#define kNilFilterProc nil + +#define kErrorAlertID kBaseResID + +void CenterWindow(WindowPtr window); +Boolean IsCompactDisplay(); +void ShowError(Str255 message, Boolean isFatal); #endif diff --git a/src/MacLO.c b/src/MacLO.c index e1fed4d..71f0ee6 100644 --- a/src/MacLO.c +++ b/src/MacLO.c @@ -1,10 +1,12 @@ // Copyright (c) Jon Thysell // Licensed under the MIT License. -#include "MacCommon.h" +#include "GameWindow.h" #include "MacLO.h" -void InitToolBox() +GameWindow gGameWindow; + +void MacLO_InitToolBox() { InitGraf(&thePort); InitFonts(); @@ -16,26 +18,12 @@ void InitToolBox() InitCursor(); } -void InitMainWindow() +void MacLO_InitWindows() { - WindowPtr window; - - window = GetNewWindow(kBaseResID, nil, kMoveToFront); - - if (window == nil) - { - SysBeep(0); - ExitToShell(); - } - - ShowWindow(window); - SetPort(window); - - MoveTo(30, 50); - DrawString("\pHello MacLO"); + GameWindow_Init(&gGameWindow); } -void ProcessEvents() +void MacLO_MainLoop() { while (!Button()) { } } diff --git a/src/MacLO.h b/src/MacLO.h index ac9d94e..7e9e1c6 100644 --- a/src/MacLO.h +++ b/src/MacLO.h @@ -4,8 +4,8 @@ #ifndef MACLO_H #define MACLO_H -void InitToolBox(); -void InitMainWindow(); -void ProcessEvents(); +void MacLO_InitToolBox(); +void MacLO_InitWindows(); +void MacLO_MainLoop(); #endif diff --git a/src/MacLO.pi.bin b/src/MacLO.pi.bin index 7c30880..2684838 100644 Binary files a/src/MacLO.pi.bin and b/src/MacLO.pi.bin differ diff --git a/src/MacLO.pi.rsrc.bin b/src/MacLO.pi.rsrc.bin index 8930783..6d5ece6 100644 Binary files a/src/MacLO.pi.rsrc.bin and b/src/MacLO.pi.rsrc.bin differ diff --git a/src/main.c b/src/main.c index e0ef647..d982b44 100644 --- a/src/main.c +++ b/src/main.c @@ -5,7 +5,7 @@ void main(void) { - InitToolBox(); - InitMainWindow(); - ProcessEvents(); + MacLO_InitToolBox(); + MacLO_InitWindows(); + MacLO_MainLoop(); } diff --git a/src/stdbool.h b/src/stdbool.h index 9152796..624d7ca 100644 --- a/src/stdbool.h +++ b/src/stdbool.h @@ -4,10 +4,6 @@ #ifndef STDBOOL_H #define STDBOOL_H -#ifndef true -typedef char bool; -#define true 1 -#define false 0 -#endif +typedef Boolean bool; #endif