// Filename : LOADSAVE.C // Coded by : Scott Evans // Created/Modified : 21/7/98 // Description : Load and save game routines #include "loadsave.h" // Externals extern GAME_DATA gd; extern PROGRAM_DATA pd; extern HIGHSCORE highscore_table[]; extern SprHeader *map_blocks_header; // Load/save buffer u_byte ls_buffer[LS_BUFFER_SIZE]; // Filename used for loading/saving u_byte ls_filename[MC_MAX_FILENAME_CHARACTERS]; // The validation string u_byte validation_string[]={"Bouncer 2 Version 1.0"}; // Game data to load/save LSGAME_DATA lsgd; // Memory card animation sprites u_byte mc_anim_data[]={ #include "..\\sprites\\mc_anim.dat" }; SprHeader *mc_anim=(SprHeader *)&mc_anim_data[0]; // Function : SaveGame() // Coded by : Scott Evans // Created/Modified : 21/7/98 // Description : Saves game data to memory card // Parameters : slot - memory card to use // Returns : 1 for success, 0 for error // Notes : None u_byte SaveGame(u_byte slot) { long no_bytes,filesize; MC_IMAGE_INFO *mci; // Find a memory card that can be used if(FindMemoryCard(slot)!=MC_SLOT_NOTFOUND) { CreateMemoryCardFilename("B2",ls_filename,slot); // Delete the file if it already exists DeleteFile(ls_filename); // Create a new file if(CreateFile(ls_filename,LS_FILE_BLOCKS)) { // Get information about textures used in animation mci=GetMCImageInfo(mc_anim,0,1,2); // Set up the file header InitMCFileHeader((MCFILE_HEADER *)&ls_buffer[0],mci,LS_FILE_BLOCKS,"Bouncer 2 Save Game"); filesize=mci->header_size; // Put in a validation string memcpy((u_byte *)&ls_buffer[filesize],&validation_string[0],strlen(validation_string)+1); filesize+=strlen(validation_string)+1; // Make sure our next block of data starts on a 4 byte boundary filesize=((filesize>>2)<<2)+4; // Copy the highscore table data memcpy((u_byte *)&ls_buffer[filesize],(u_byte *)&highscore_table[0],sizeof(HIGHSCORE)*HIGHSCORE_TABLE_SIZE); filesize+=sizeof(HIGHSCORE)*HIGHSCORE_TABLE_SIZE; // Make sure our next block of data starts on a 4 byte boundary filesize=((filesize>>2)<<2)+4; // Copy the game data lsgd.level_no=gd.last_level; lsgd.difficulty=gd.difficulty; // Screen position lsgd.sx=pd.screen_xoff; lsgd.sy=pd.screen_yoff; // Cheat modes lsgd.cheats_on=gd.cheats_on; // Number of lives and bombs lsgd.lives=gd.no_lives; lsgd.bombs=gd.no_bombs; #ifdef DEBUG_INFO sprintf(fm_string,"Level=%d Difficulty=%d\n",gd.last_level,gd.difficulty); PrintFM(fm_string); sprintf(fm_string,"Lives=%d Bombs=%d Level=%d\n",gd.no_lives,gd.no_bombs,gd.last_level); PrintFM(fm_string); #endif memcpy((u_byte *)&ls_buffer[filesize],(u_byte *)&lsgd,sizeof(LSGAME_DATA)); filesize+=sizeof(LSGAME_DATA); // Make sure data size is a multiple of MC_SECTOR_SIZE filesize=((filesize/MC_SECTOR_SIZE)*MC_SECTOR_SIZE)+MC_SECTOR_SIZE; // Write the data to the memory card no_bytes=WriteBlock(ls_filename,&ls_buffer[0],filesize); if(no_bytes==-1 || no_bytes>2)<<2)+4; // Copy the highscore data memcpy((u_byte *)&highscore_table[0],(u_byte *)&ls_buffer[filesize],sizeof(HIGHSCORE)*HIGHSCORE_TABLE_SIZE); // Move on to next block of data filesize+=sizeof(HIGHSCORE)*HIGHSCORE_TABLE_SIZE; // Make sure our next block of data starts on a 4 byte boundary filesize=((filesize>>2)<<2)+4; // Get the game data memcpy((u_byte *)&lsgd,(u_byte *)&ls_buffer[filesize],sizeof(LSGAME_DATA)); // Set the game data gd.start_level=lsgd.level_no; gd.last_level=gd.start_level; gd.difficulty=lsgd.difficulty; gd.cheats_on=lsgd.cheats_on; //gd.no_lives=lsgd.lives; //gd.no_bombs=lsgd.bombs; #ifdef DEBUG_INFO sprintf(fm_string,"Lives=%d Bombs=%d Level=%d\n",gd.no_lives,gd.no_bombs,gd.start_level); PrintFM(fm_string); #endif return(1); } #ifdef DEBUG_INFO sprintf(fm_string,"Validation string incorrect (%s)\n",&ls_buffer[filesize]); PrintFM(fm_string); #endif return(0); } return(0); } PrintFM("Memory card not found\n"); return(0); } // Function : InitLSGameData() // Coded by : Scott Evans // Created/Modified : 22/7/98 // Description : Set up sensible defaults for save game data // Parameters : None // Returns : None // Notes : None void InitLSGameData(void) { // Clear out structure bzero((u_byte *)&lsgd,sizeof(LSGAME_DATA)); lsgd.difficulty=gd.difficulty; lsgd.sx=pd.screen_xoff; lsgd.sy=pd.screen_yoff; }