2020-06-11 01:47:00 +00:00
|
|
|
/*
|
|
|
|
* main.c
|
|
|
|
* BuGS
|
|
|
|
*
|
|
|
|
* Created by Jeremy Rand on 2020-06-10.
|
|
|
|
* Copyright (c) 2020 Jeremy Rand. All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2020-07-15 04:32:14 +00:00
|
|
|
#include <stdlib.h>
|
2020-06-11 01:47:00 +00:00
|
|
|
|
|
|
|
#include <Memory.h>
|
|
|
|
#include <Locator.h>
|
|
|
|
#include <MiscTool.h>
|
2020-12-09 06:38:03 +00:00
|
|
|
#include <Resources.h>
|
|
|
|
#include <Sound.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
2020-06-11 01:47:00 +00:00
|
|
|
|
|
|
|
#include "main.h"
|
2020-07-15 04:32:14 +00:00
|
|
|
#include "game.h"
|
2020-11-05 03:48:18 +00:00
|
|
|
#include "tileData.h"
|
2020-06-11 01:47:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Defines and macros */
|
|
|
|
|
|
|
|
#define TOOLFAIL(string) \
|
|
|
|
if (toolerror()) SysFailMgr(toolerror(), "\p" string "\n\r Error Code -> $");
|
|
|
|
|
|
|
|
|
|
|
|
/* Globals */
|
|
|
|
|
|
|
|
unsigned int userid;
|
2020-07-19 19:15:45 +00:00
|
|
|
unsigned int randomSeed;
|
2020-06-11 01:47:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Implementation */
|
|
|
|
|
|
|
|
|
2020-11-05 03:48:18 +00:00
|
|
|
word randomMushroomOffset(void)
|
2020-11-03 05:11:22 +00:00
|
|
|
{
|
|
|
|
/* We do not put mushrooms in the bottom tile so we subtract the width here to find
|
|
|
|
a tile number above that last line */
|
2020-11-05 03:48:18 +00:00
|
|
|
return (rand() % (NUM_GAME_TILES - GAME_NUM_TILES_WIDE)) * SIZEOF_TILE_INFO;
|
2020-11-03 05:11:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-17 05:35:56 +00:00
|
|
|
void loadSpiderSound(word addr)
|
2020-12-09 06:38:03 +00:00
|
|
|
{
|
2020-12-17 05:35:56 +00:00
|
|
|
Handle handle = LoadResource(rRawSound, SPIDER_SOUND);
|
2020-12-09 06:38:03 +00:00
|
|
|
HLock(handle);
|
2020-12-17 05:35:56 +00:00
|
|
|
WriteRamBlock(*handle, addr, GetHandleSize(handle));
|
|
|
|
HUnlock(handle);
|
|
|
|
}
|
2020-12-09 06:38:03 +00:00
|
|
|
|
2020-12-17 05:35:56 +00:00
|
|
|
|
|
|
|
void loadDeathSound(word addr)
|
|
|
|
{
|
|
|
|
Handle handle = LoadResource(rRawSound, DEATH_SOUND);
|
|
|
|
HLock(handle);
|
|
|
|
WriteRamBlock(*handle, addr, GetHandleSize(handle));
|
2020-12-16 17:00:56 +00:00
|
|
|
HUnlock(handle);
|
2020-12-09 06:38:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-17 05:35:56 +00:00
|
|
|
void loadSegmentsSound(word addr)
|
2020-12-09 06:38:03 +00:00
|
|
|
{
|
2020-12-17 05:35:56 +00:00
|
|
|
Handle handle = LoadResource(rRawSound, SEGMENTS_SOUND);
|
|
|
|
HLock(handle);
|
|
|
|
WriteRamBlock(*handle, addr, GetHandleSize(handle));
|
|
|
|
HUnlock(handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void loadBonusSound(word addr)
|
|
|
|
{
|
|
|
|
Handle handle = LoadResource(rRawSound, BONUS_SOUND);
|
|
|
|
HLock(handle);
|
|
|
|
WriteRamBlock(*handle, addr, GetHandleSize(handle));
|
|
|
|
HUnlock(handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void loadKillSound(word addr)
|
|
|
|
{
|
|
|
|
Handle handle = LoadResource(rRawSound, KILL_SOUND);
|
|
|
|
HLock(handle);
|
|
|
|
WriteRamBlock(*handle, addr, GetHandleSize(handle));
|
|
|
|
HUnlock(handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void loadFireSound(word addr)
|
|
|
|
{
|
|
|
|
Handle handle = LoadResource(rRawSound, FIRE_SOUND);
|
|
|
|
HLock(handle);
|
|
|
|
WriteRamBlock(*handle, addr, GetHandleSize(handle));
|
|
|
|
HUnlock(handle);
|
2020-12-09 06:38:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-18 05:50:01 +00:00
|
|
|
void loadExtraLifeSound(word addr)
|
|
|
|
{
|
|
|
|
Handle handle = LoadResource(rRawSound, EXTRA_LIFE_SOUND);
|
|
|
|
HLock(handle);
|
|
|
|
WriteRamBlock(*handle, addr, GetHandleSize(handle));
|
|
|
|
HUnlock(handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-11 01:47:00 +00:00
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
int event;
|
|
|
|
Ref toolStartupRef;
|
|
|
|
|
|
|
|
userid = MMStartUp();
|
|
|
|
TOOLFAIL("Unable to start memory manager");
|
|
|
|
|
|
|
|
TLStartUp();
|
|
|
|
TOOLFAIL("Unable to start tool locator");
|
|
|
|
|
|
|
|
toolStartupRef = StartUpTools(userid, refIsResource, TOOL_STARTUP);
|
|
|
|
TOOLFAIL("Unable to start tools");
|
|
|
|
|
2020-06-11 03:51:53 +00:00
|
|
|
CompactMem();
|
2020-06-23 03:45:25 +00:00
|
|
|
/* Allocate $1000 extra before the SHR screen so I can write sprites above the start of the
|
|
|
|
screen without overwriting memory I do not own. */
|
|
|
|
NewHandle(0x9000, userid, attrLocked | attrFixed | attrAddr | attrBank, (Pointer)0x011000);
|
2020-06-11 03:51:53 +00:00
|
|
|
TOOLFAIL("Unable to allocate SHR screen");
|
2020-06-11 01:47:00 +00:00
|
|
|
|
2020-07-19 19:15:45 +00:00
|
|
|
randomSeed = (int)time(NULL);
|
|
|
|
if (randomSeed == 0)
|
|
|
|
randomSeed = 1;
|
|
|
|
srand(randomSeed);
|
|
|
|
randInit();
|
2020-07-15 04:32:14 +00:00
|
|
|
|
2020-10-29 03:46:32 +00:00
|
|
|
InitMouse(0);
|
|
|
|
SetMouse(transparent);
|
2020-11-05 03:48:18 +00:00
|
|
|
|
2020-06-11 03:51:53 +00:00
|
|
|
game();
|
2020-06-11 01:47:00 +00:00
|
|
|
|
|
|
|
ShutDownTools(refIsHandle, toolStartupRef);
|
|
|
|
TOOLFAIL("Unable to shutdown tools");
|
|
|
|
|
|
|
|
TLShutDown();
|
|
|
|
TOOLFAIL("Unable to shutdown tool locator");
|
|
|
|
|
|
|
|
MMShutDown(userid);
|
|
|
|
TOOLFAIL("Unable to shutdown memory manager");
|
|
|
|
}
|