mirror of
https://github.com/jeremysrand/BuGS.git
synced 2025-01-01 01:30:27 +00:00
Add code to load Marinetti and the Hash tool if present and bring up the network if possible.
This commit is contained in:
parent
8d95d0a674
commit
4b76293125
@ -92,6 +92,11 @@ gameLoop anop
|
||||
lda #1
|
||||
sta shouldPreloadSound
|
||||
gameLoop_skipPreload anop
|
||||
lda gameState
|
||||
bne gameLoop_skipNetwork
|
||||
jsl pollNetwork
|
||||
gameLoop_skipNetwork anop
|
||||
|
||||
jsl checkKeyboard
|
||||
|
||||
jsl waitForVbl
|
||||
|
@ -6,13 +6,18 @@
|
||||
* Copyright © 2021 Jeremy Rand. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <Hash.h>
|
||||
#include <locator.h>
|
||||
#include <misctool.h>
|
||||
#include <stdint.h>
|
||||
#include <tcpip.h>
|
||||
#include <types.h>
|
||||
|
||||
#include "globalScores.h"
|
||||
|
||||
|
||||
// Defines
|
||||
|
||||
#define REQUEST_TYPE_GET_HIGH_SCORES 0
|
||||
#define REQUEST_TYPE_SET_SCORE 1
|
||||
|
||||
@ -21,6 +26,8 @@
|
||||
#define RESPONSE_TYPE_STATUS 2
|
||||
|
||||
|
||||
// Types
|
||||
|
||||
typedef struct tSessionSecrets {
|
||||
uint32_t secret;
|
||||
uint32_t nonce;
|
||||
@ -70,6 +77,22 @@ typedef struct tStatusResponse {
|
||||
} tStatusResponse;
|
||||
|
||||
|
||||
typedef enum tGameNetworkState {
|
||||
GAME_NETWORK_CONNECT_FAILED = 0,
|
||||
GAME_NETWORK_UNCONNECTED,
|
||||
GAME_NETWORK_CONNECTED,
|
||||
} tGameNetworkState;
|
||||
|
||||
|
||||
// Globals
|
||||
|
||||
Boolean networkToolsStarted = FALSE;
|
||||
Boolean networkStartedConnected = FALSE;
|
||||
tGameNetworkState gameNetworkState = GAME_NETWORK_UNCONNECTED;
|
||||
|
||||
|
||||
// Implementation
|
||||
|
||||
#if 0
|
||||
Word blah(void)
|
||||
{
|
||||
@ -79,3 +102,86 @@ Word blah(void)
|
||||
return ReadBParam(hrtz50or60);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void initNetwork(void)
|
||||
{
|
||||
networkToolsStarted = FALSE;
|
||||
LoadOneTool(54, 0x200); // Load Marinetti
|
||||
if (toolerror())
|
||||
return;
|
||||
|
||||
LoadOneTool(128, 0x103); // Load the Hash toolset
|
||||
if (toolerror()) {
|
||||
UnloadOneTool(54);
|
||||
return;
|
||||
}
|
||||
|
||||
TCPIPStartUp();
|
||||
if (toolerror()) {
|
||||
UnloadOneTool(128);
|
||||
UnloadOneTool(54);
|
||||
return;
|
||||
}
|
||||
|
||||
hashStartUp();
|
||||
if (toolerror()) {
|
||||
TCPIPShutDown();
|
||||
UnloadOneTool(128);
|
||||
UnloadOneTool(54);
|
||||
return;
|
||||
}
|
||||
|
||||
networkToolsStarted = TRUE;
|
||||
|
||||
networkStartedConnected = TCPIPGetConnectStatus();
|
||||
if (networkStartedConnected) {
|
||||
gameNetworkState = GAME_NETWORK_CONNECTED;
|
||||
} else {
|
||||
gameNetworkState = GAME_NETWORK_UNCONNECTED;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void shutdownNetwork(void)
|
||||
{
|
||||
if (!networkToolsStarted)
|
||||
return;
|
||||
|
||||
if ((!networkStartedConnected) &&
|
||||
(gameNetworkState > GAME_NETWORK_UNCONNECTED)) {
|
||||
TCPIPDisconnect(TRUE, NULL);
|
||||
}
|
||||
|
||||
hashShutDown();
|
||||
TCPIPShutDown();
|
||||
UnloadOneTool(128); // Unload the Hash toolset
|
||||
UnloadOneTool(54); // Unload Marinetti
|
||||
}
|
||||
|
||||
|
||||
void pollNetwork(void)
|
||||
{
|
||||
if (!networkToolsStarted)
|
||||
return;
|
||||
|
||||
switch (gameNetworkState) {
|
||||
case GAME_NETWORK_CONNECT_FAILED:
|
||||
// If Marinetti cannot connect to the network, then nothing more to do...
|
||||
break;
|
||||
|
||||
case GAME_NETWORK_UNCONNECTED:
|
||||
TCPIPConnect(NULL); // TODO - Perhaps no feedback here is not a good user experience and I should provide some kind of display function.
|
||||
if ((!toolerror()) &&
|
||||
(TCPIPGetConnectStatus())) {
|
||||
gameNetworkState = GAME_NETWORK_CONNECTED;
|
||||
} else {
|
||||
gameNetworkState = GAME_NETWORK_CONNECT_FAILED;
|
||||
}
|
||||
break;
|
||||
|
||||
case GAME_NETWORK_CONNECTED:
|
||||
// TODO - Write more code to make network requests.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -18,4 +18,9 @@ typedef struct tHighScore
|
||||
} tHighScore;
|
||||
|
||||
|
||||
extern void initNetwork(void);
|
||||
extern void pollNetwork(void);
|
||||
extern void shutdownNetwork(void);
|
||||
|
||||
|
||||
#endif /* define _GUARD_PROJECTBuGS_FILEglobalScores_ */
|
||||
|
@ -347,11 +347,15 @@ int main(void)
|
||||
InitMouse(0);
|
||||
SetMouse(transparent);
|
||||
|
||||
initNetwork();
|
||||
|
||||
if (!loadSettings())
|
||||
saveSettings();
|
||||
|
||||
game();
|
||||
|
||||
shutdownNetwork();
|
||||
|
||||
ShutDownTools(refIsHandle, toolStartupRef);
|
||||
TOOLFAIL("Unable to shutdown tools");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user