iigs-game-engine/demos/chrisv/test.c

118 lines
2.9 KiB
C
Raw Normal View History

2022-08-27 20:53:02 +00:00
#include <loader.h>
#include <locator.h>
2022-08-28 00:24:07 +00:00
#include <memory.h>
2022-08-27 20:53:02 +00:00
#include <misctool.h>
#include <types.h>
/* #define GTE_IS_SYSTEM_TOOLS_INSTALL 1 */
#include "gte.h"
#ifdef GTE_IS_SYSTEM_TOOLS_INSTALL
#define ENGINE_STARTUP_MODE 0x0000
#else
#define ENGINE_STARTUP_MODE ENGINE_MODE_USER_TOOL
#endif
/* toolbox fail handler */
#define TOOLFAIL(string) if (toolerror()) SysFailMgr(toolerror(), "\p" string "\n\r Error Code -> $");
/* path to the local GTE toolset */
Str32 toolPath = {9, "1/Tool160" };
/* Helper function to load GTE as a user tool or system tool */
#ifdef GTE_IS_SYSTEM_TOOLS_INSTALL
void LoadGTEToolSet(Word unused) {
LoadOneTool(160, 0);
TOOLFAIL("Unable to load GTE toolset");
}
#else
void LoadGTEToolSet(Word userId) {
InitialLoadOutputRec loadRec;
2022-08-28 00:24:07 +00:00
2022-08-27 20:53:02 +00:00
// Load the tool from the local directory
loadRec = InitialLoad(userId, (Pointer) (&toolPath), 1);
TOOLFAIL("Unable to load Tool160 from local path");
// Install the tool using the user tool vector
SetTSPtr(0x8000, 160, loadRec.startAddr);
TOOLFAIL("Could not install tool");
}
#endif // GTE_IS_SYSTEM_TOOLS_INSTALL
#ifdef GTE_IS_SYSTEM_TOOLS_INSTALL
void UnloadGTEToolSet() {
UnloadOneTool(160);
TOOLFAIL("Unable to unload GTE toolset");
}
#else
void UnloadGTEToolSet() {
}
#endif // GTE_IS_SYSTEM_TOOLS_INSTALL
2022-08-28 00:24:07 +00:00
extern Byte tiles[];
extern Word tilesPalette[16];
2022-08-27 20:53:02 +00:00
void main(void) {
Word userId;
2022-08-28 00:24:07 +00:00
Word tileId;
2022-08-27 20:53:02 +00:00
Word controlMask, keyPress;
Handle dpHandle;
Word dpAddr;
int a, b;
TLStartUp();
2022-08-28 00:24:07 +00:00
TOOLFAIL("Unable to start tool locator");
2022-08-27 20:53:02 +00:00
userId = MMStartUp();
2022-08-28 00:24:07 +00:00
TOOLFAIL("Unable to start memory manager");
2022-08-27 20:53:02 +00:00
MTStartUp();
2022-08-28 00:24:07 +00:00
TOOLFAIL("Unable to start misc tools");
LoadGTEToolSet(userId);
2022-08-27 20:53:02 +00:00
dpHandle = NewHandle(0x200L, userId, attrBank + attrPage + attrFixed + attrLocked + attrNoCross, 0);
TOOLFAIL("Could not allocate direct page memory for GTE");
dpAddr = (Word) (*dpHandle);
GTEStartUp(dpAddr, (Word) ENGINE_STARTUP_MODE, userId);
2022-08-28 00:24:07 +00:00
/* GTESetScreenMode(160, 200); /* 160x200 is the default screen mode */
GTESetPalette(0, (Pointer)tilesPalette);
2022-08-28 00:51:31 +00:00
GTELoadTileSet(0, 160, tiles); /* Load in the tiles */
2022-08-27 20:53:02 +00:00
GTEFillTileStore(1);
GTERender(0);
for (a = 3; a < 18; a++) {
2022-08-28 00:51:31 +00:00
GTESetTile(a, a, 5);
2022-08-27 20:53:02 +00:00
}
GTESetTile(1, 0, 34);
GTESetTile(2, 0, 33);
GTERender(0);
GTESetTile(0, 3, 3);
GTESetTile(0, 4, 4);
for (b = 4; b < 6; b++) {
for (a = 1; a < 10; a++) {
GTESetBG0Origin(a, b);
2022-08-28 00:51:31 +00:00
tileId = (((b - 1) * 32) + a) | TILE_SOLID_BIT | TILE_HFLIP_BIT;
2022-08-28 00:24:07 +00:00
GTESetTile(a, b, tileId);
2022-08-27 20:53:02 +00:00
GTERender(0);
}
}
do {
controlMask = GTEReadControl();
keyPress = controlMask & 0x007F;
2022-08-28 00:24:07 +00:00
} while (keyPress != 'Q');
2022-08-27 20:53:02 +00:00
GTEShutDown();
UnloadGTEToolSet();
DisposeHandle(dpHandle);
MTShutDown();
MMShutDown(userId);
TLShutDown();
}