All pastes #258932 Raw Edit

Tyler

public c v1 · immutable
#258932 ·published 2006-11-26 23:03 UTC
rendered paste body
// C Source File// Created 11/26/2006; 2:52:38 PM// Star Blaster by Tyler Cassidy// Version 1.00// Email: tyler@tylerc.org || altadogsledder89@yahoo.ca//  This program is free software; you can redistribute it and/or modify//  it under the terms of the GNU General Public License as published by//  the Free Software Foundation; either version 2 of the License, or//  (at your option) any later version.//  This program is distributed in the hope that it will be useful,//  but WITHOUT ANY WARRANTY; without even the implied warranty of//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the//  GNU General Public License for more details.#include <tigcclib.h>#include "include.h"GAMESCORES *Scores;GAMEPROFILES *Profiles;GAMESETTINGS *Settings;/* Allocate Space for Scores, Settings and Profiles */short SaveAlloc(void){	Scores = malloc(sizeof(GAMESCORES));	if (!Scores) return 0;	Profiles = malloc(sizeof(GAMEPROFILES));	if (!Profiles) return 0;	Settings = malloc(sizeof(GAMESETTINGS));	if (!Settings) return 0;		memset(&Scores, 0, sizeof(GAMESCORES));	memset(&Profiles, 0, sizeof(GAMEPROFILES));	memset(&Settings, 0, sizeof(GAMESETTINGS));		return 1;}/* Load Save File */void LoadSaveFile(void){	GAMESAVE *LoadData;	SYM_ENTRY *LoadEntry;		LoadEntry = SymFindPtr(SYMSTR("starbsav"), 0);		// Error Testing	if (!LoadEntry) return;	if (!LoadEntry->handle) return;		LoadData = HeapDeref(LoadEntry->handle);	memcpy(&Scores, &LoadData->Scores, sizeof(GAMESCORES));	memcpy(&Profiles, &LoadData->Profiles, sizeof(GAMEPROFILES));	memcpy(&Settings, &LoadData->Settings, sizeof(GAMESETTINGS));}short WriteSaveFile(void){	GAMESAVE *WriteData;	HSym SaveSym; // VAT Symbol	SYM_ENTRY *SaveEntry; // File Information	HANDLE SaveHandle; // File Data		// Delete old Savefile it exists	if ((SaveSym = SymFind(SYMSTR("starbsav"))).folder)	{		if (DerefSym(SaveSym)->flags.bits.archived)		  EM_moveSymFromExtMem(NULL, SaveSym); // Unarchive		SymDel(SYMSTR("starbsav"));	}		// Start new VAT Symbol	SaveSym = SymAdd(SYMSTR("starbsav"));	if (!SaveSym.folder) return 0;		// Allocate Space in Heap	SaveHandle = HeapAlloc(sizeof(GAMESAVE));	if (!SaveHandle)	{		SymDel(SYMSTR("starbsav"));		return 0;	}	WriteData = HeapDeref(SaveHandle);		// Get size than save	WriteData->size = sizeof(GAMESCORES) + sizeof(GAMEPROFILES) + sizeof(GAMESETTINGS) + 7;	memcpy(&WriteData->Scores, &Scores, sizeof(GAMESCORES));	memcpy(&WriteData->Profiles, &Profiles, sizeof(GAMEPROFILES));	memcpy(&WriteData->Settings, &Settings, sizeof(GAMESETTINGS));	memcpy(&WriteData->othtag, "\0STAR\0\xF8", 7);		// Save to Heap now	SaveEntry = DerefSym(SaveSym);	SaveEntry->handle = SaveHandle;		// Archive	SetIntLevel(HIGH_LVL);	memcpy(GameGfx.HiddenDark, GameGfx.ActiveDark, LCD_SIZE);	memcpy(GameGfx.HiddenLight, GameGfx.ActiveLight, LCD_SIZE);	EM_moveSymToExtMem(NULL, SaveSym); // Archive File	memcpy(GameGfx.ActiveDark, GameGfx.HiddenDark, LCD_SIZE);	memcpy(GameGfx.ActiveLight, GameGfx.HiddenLight, LCD_SIZE);		return 1;}/* Free Allocated Structures */void SaveFree(void){	free(Scores);	free(Profiles);	free(Settings);}