diff --git a/a2bejwld.xcodeproj/project.pbxproj b/a2bejwld.xcodeproj/project.pbxproj index 960ca9a..d9a817c 100644 --- a/a2bejwld.xcodeproj/project.pbxproj +++ b/a2bejwld.xcodeproj/project.pbxproj @@ -9,6 +9,8 @@ /* Begin PBXFileReference section */ 9D3A9FB81D455CCF004C5897 /* joystick.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = joystick.h; sourceTree = ""; }; 9D3A9FB91D455CD8004C5897 /* joystick.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = joystick.c; sourceTree = ""; }; + 9D4D1AA31D6D0E9B00D20BB8 /* machine.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = machine.c; sourceTree = ""; }; + 9D4D1AA41D6D0E9B00D20BB8 /* machine.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = machine.h; sourceTree = ""; }; 9D509F911D654F9900161DDC /* mouseWrapper.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = mouseWrapper.c; sourceTree = ""; }; 9D509F921D654F9900161DDC /* mouseWrapper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mouseWrapper.h; sourceTree = ""; }; 9D509F941D66AE2800161DDC /* a2e.stdmou.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = a2e.stdmou.s; sourceTree = ""; }; @@ -79,6 +81,8 @@ 9D6B473F1D3FB5C800F6D704 /* dbllores.h */, 9D6B47451D426E6300F6D704 /* vbl.s */, 9D6B47471D42709200F6D704 /* vbl.h */, + 9D4D1AA31D6D0E9B00D20BB8 /* machine.c */, + 9D4D1AA41D6D0E9B00D20BB8 /* machine.h */, 9D6B47481D4270EC00F6D704 /* anim.c */, 9D6B47491D4270EC00F6D704 /* anim.h */, 9D6B472F1D3FB16F00F6D704 /* Makefile */, diff --git a/a2bejwld/anim.c b/a2bejwld/anim.c index 057da37..41e166a 100644 --- a/a2bejwld/anim.c +++ b/a2bejwld/anim.c @@ -7,7 +7,6 @@ // -#include #include #include #include @@ -17,7 +16,7 @@ #include "anim.h" #include "dbllores.h" #include "game.h" -#include "vbl.h" +#include "machine.h" #include "ui.h" @@ -72,13 +71,8 @@ typedef struct tDropGemAnimState { typedef void __fastcall__ (*tClearGemHandler)(tSquare square); -typedef void (*tVblWaitFunction)(void); - - // Globals -static tVblWaitFunction gVblWait = vblWait; - static tStarAnimState gStarAnimState; static tClearGemAnimState gClearGemAnimState; static tDropGemAnimState gDropGemAnimState; @@ -118,25 +112,6 @@ static tClearGemHandler gClearGemHandler[] = { // Implementation -void animInit(void) -{ - switch (get_ostype()) { - case APPLE_IIC: - case APPLE_IIC35: - case APPLE_IICEXP: - case APPLE_IICREV: - case APPLE_IICPLUS: - gVblWait = vblWait2c; - break; - - case APPLE_IIGS: - case APPLE_IIGS1: - case APPLE_IIGS3: - vblInit2gs(); - break; - } -} - void drawGemAtSquare(tSquare square) { diff --git a/a2bejwld/dbllores.s b/a2bejwld/dbllores.s index c7065dd..88093d7 100644 --- a/a2bejwld/dbllores.s +++ b/a2bejwld/dbllores.s @@ -648,7 +648,7 @@ square: .BYTE $0 ; A is a number from 0 to 24 tay ldx #24 - lda #$22 + lda #$dd sta color sta LOWSCR @L1: @@ -656,7 +656,7 @@ square: .BYTE $0 bmi @L2 cpy #0 bne @L3 - lda #$aa + lda #$22 sta color @L3: dey diff --git a/a2bejwld/machine.c b/a2bejwld/machine.c new file mode 100644 index 0000000..fdfed8a --- /dev/null +++ b/a2bejwld/machine.c @@ -0,0 +1,103 @@ +// +// machine.c +// a2bejwld +// +// Created by Jeremy Rand on 2016-08-23. +// Copyright © 2016 Jeremy Rand. All rights reserved. +// + + +#include +#include +#include + +#include "machine.h" +#include "vbl.h" + + +// Typedefs +typedef enum { + GS_SPEED_SLOW, + GS_SPEED_FAST +} tMachineGSSpeed; + + +// Globals + +tVblWaitFunction gVblWait = vblWait; + +static tMachineGSSpeed gOldSpeed = GS_SPEED_SLOW; + + +// Implementation + + +static bool machineIs2c(void) +{ + switch (get_ostype()) { + case APPLE_IIC: + case APPLE_IIC35: + case APPLE_IICEXP: + case APPLE_IICREV: + case APPLE_IICPLUS: + return true; + } + + return false; +} + + +static bool machineIs2GS(void) +{ + switch (get_ostype()) { + case APPLE_IIGS: + case APPLE_IIGS1: + case APPLE_IIGS3: + return true; + } + + return false; +} + + +static tMachineGSSpeed setGSSpeed(tMachineGSSpeed newSpeed) +{ + uint8_t *speedRegister = (uint8_t *)0xc036; + uint8_t value = *speedRegister; + tMachineGSSpeed oldSpeed; + + if ((value & 0x80) != 0) + oldSpeed = GS_SPEED_FAST; + else + oldSpeed = GS_SPEED_SLOW; + + if (oldSpeed != newSpeed) { + if (newSpeed == GS_SPEED_FAST) { + value |= 0x80; + } else { + value &= 0x7f; + } + *speedRegister = value; + } + + return oldSpeed; +} + + +void initMachine(void) +{ + if (machineIs2c()) { + gVblWait = vblWait2c; + } else if (machineIs2GS()) { + vblInit2gs(); + gOldSpeed = setGSSpeed(GS_SPEED_SLOW); + } +} + + +void uninitMachine(void) +{ + if (machineIs2GS()) { + setGSSpeed(gOldSpeed); + } +} \ No newline at end of file diff --git a/a2bejwld/machine.h b/a2bejwld/machine.h new file mode 100644 index 0000000..d6b0124 --- /dev/null +++ b/a2bejwld/machine.h @@ -0,0 +1,30 @@ +// +// machine.h +// a2bejwld +// +// Created by Jeremy Rand on 2016-08-23. +// Copyright © 2016 Jeremy Rand. All rights reserved. +// + +#ifndef __a2bejwld__machine__ +#define __a2bejwld__machine__ + + + +// Typedefs + +typedef void (*tVblWaitFunction)(void); + + +// Globals + +extern tVblWaitFunction gVblWait; + + +// API + +extern void initMachine(void); +extern void uninitMachine(void); + + +#endif /* defined(__a2bejwld__machine__) */ diff --git a/a2bejwld/ui.c b/a2bejwld/ui.c index e7ececb..bd0e5f4 100644 --- a/a2bejwld/ui.c +++ b/a2bejwld/ui.c @@ -17,13 +17,14 @@ #include "dbllores.h" #include "game.h" #include "joystick.h" +#include "machine.h" #include "mouseWrapper.h" // Defines #define SAVE_OPTIONS_FILE "a2bejwld.opts" -#define VERSION "v1.2b1" +#define VERSION "v1.2b2" // Typedefs @@ -330,6 +331,9 @@ static void quitGame(void) videomode(VIDEOMODE_40x24); clrscr(); shutdownMouse(); + + uninitMachine(); + exit(0); } @@ -479,10 +483,11 @@ static void endGame(void) { mixedTextMode(); videomode(VIDEOMODE_80x24); - cputsxy(0, 20, " No more moves - GAME OVER!!"); - gotoxy(0,21); - cprintf( " You made it to level %u", getLevel()); - cputsxy(0,23, " Play again (Y/N)?"); + + printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + printf(" No more moves - GAME OVER!!\n"); + printf(" You made it to level %u\n\n", getLevel()); + printf(" Play again (Y/N)?"); while (true) { switch (cgetc()) { @@ -522,9 +527,10 @@ static void refreshLevel(tLevel level) mixedTextMode(); videomode(VIDEOMODE_80x24); - gotoxy(0, 20); - cprintf( " Completed level %u!!", level); - cputsxy(0,22, " Press space to continue to the next level..."); + + printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); + printf(" Completed level %u!!\n", level); + printf(" Press space to continue to the next level..."); while (waiting) { switch (cgetc()) { @@ -555,10 +561,11 @@ void initUI(void) { bool optionsLoaded; + initMachine(); + optionsLoaded = loadOptions(); initGameEngine(&gCallbacks); - animInit(); if ((!optionsLoaded) || (gGameOptions.enableMouse)) {