// // END ARTICLES // void EndText (void) { int artnum; char *text; memptr layout; ClearMemory (); CA_UpLevel (); MM_SortMem (); #ifdef JAPAN ShowArticle(gamestate.episode + 1); VW_FadeOut(); SETFONTCOLOR(0,15); IN_ClearKeysDown(); if (MousePresent) Mouse(MDelta); // Clear accumulated mouse movement FreeMusic (); CA_DownLevel (); MM_SortMem (); #else #ifdef ARTSEXTERN artnum = endextern+gamestate.episode; CA_CacheGrChunk (artnum); text = (char *)grsegs[artnum]; MM_SetLock (&grsegs[artnum], True); #else endfilename[6] = '1'+gamestate.episode; CA_LoadFile (endfilename,&layout); text = (char *)layout; MM_SetLock (&layout, True); #endif ShowArticle (text); #ifdef ARTSEXTERN MM_FreePtr (&grsegs[artnum]); #else MM_FreePtr (&layout); #endif VW_FadeOut(); SETFONTCOLOR(0,15); IN_ClearKeysDown(); //if (MousePresent) // PORT // Mouse(MDelta); // Clear accumulated mouse movement //FreeMusic (); CA_DownLevel (); MM_SortMem (); #endif }
id0_boolean_t SaveTheGame(BE_FILE_T file) { id0_word_t i,compressed,expanded; objtype *o; memptr bigbuffer; if (BE_Cross_writeInt16LE(file, &FreezeTime) != 2) //if (!CA_FarWrite(file,(void id0_far *)&FreezeTime,sizeof(FreezeTime))) return(false); // (REFKEEN) Writing fields one-by-one in a cross-platform manner if (!SaveGameState(file, &gamestate)) //if (!CA_FarWrite(file,(void id0_far *)&gamestate,sizeof(gamestate))) return(false); if (BE_Cross_write_boolean_To16LE(file, &EASYMODEON) != 2) //if (!CA_FarWrite(file,(void id0_far *)&EASYMODEON,sizeof(EASYMODEON))) return(false); expanded = mapwidth * mapheight * 2; MM_GetPtr (&bigbuffer,expanded); for (i = 0;i < 3;i+=2) // Write planes 0 and 2 { // // leave a word at start of compressed data for compressed length // compressed = (id0_unsigned_t)CA_RLEWCompress ((id0_unsigned_t id0_huge *)mapsegs[i] ,expanded,((id0_unsigned_t id0_huge *)bigbuffer)+1,RLETAG); *(id0_unsigned_t id0_huge *)bigbuffer = compressed; if (BE_Cross_writeInt16LEBuffer(file, bigbuffer, compressed+2) != (id0_word_t)(compressed+2)) //if (!CA_FarWrite(file,(id0_byte_t id0_far *)bigbuffer,compressed+2) ) { MM_FreePtr (&bigbuffer); return(false); } } for (o = player;o;o = o->next) // (REFKEEN) Writing fields one-by-one in a cross-platform manner if (!SaveObject(file, o)) //if (!CA_FarWrite(file,(void id0_far *)o,sizeof(objtype))) { MM_FreePtr (&bigbuffer); return(false); } MM_FreePtr (&bigbuffer); return(true); }
void HelpScreens (void) { int artnum; char *text; memptr layout; CA_UpLevel (); MM_SortMem (); #ifdef JAPAN ShowArticle (0); VW_FadeOut(); FreeMusic (); CA_DownLevel (); MM_SortMem (); #else #ifdef ARTSEXTERN artnum = helpextern; CA_CacheGrChunk (artnum); text = (char *)grsegs[artnum]; MM_SetLock (&grsegs[artnum], True); #else CA_LoadFile (helpfilename,&layout); text = (char *)layout; MM_SetLock (&layout, True); #endif ShowArticle (text); #ifdef ARTSEXTERN MM_FreePtr (&grsegs[artnum]); #else MM_FreePtr (&layout); #endif VW_FadeOut(); //FreeMusic (); // PORT CA_DownLevel (); MM_SortMem (); #endif }
void FinishDemoRecord (void) { long length,level; demorecord = false; length = demoptr - (char far *)demobuffer; demoptr = ((char far *)demobuffer)+1; *(unsigned far *)demoptr = length; CenterWindow(24,3); PrintY+=6; US_Print(" Demo number (0-9):"); VW_UpdateScreen(); if (US_LineInput (px,py,str,NULL,true,2,0)) { level = atoi (str); if (level>=0 && level<=9) { demoname[4] = '0'+level; CA_WriteFile (demoname,(void far *)demobuffer,length); } } MM_FreePtr (&demobuffer); }
void SetupScaleWall (id0_unsigned_t picnum) { id0_int_t x,y; id0_unsigned_t scnum; id0_byte_t id0_far *dest; if (picnum == 1) return; scnum = picnum-FIRSTWALLPIC; if (walldirectory[scnum]) { MM_SetPurge (&walldirectory[scnum],0); return; // allready in memory } CA_CacheGrChunk (picnum); DeplanePic (picnum); MM_GetPtr(&walldirectory[scnum],64*64); dest = (id0_byte_t id0_far *)walldirectory[scnum]; for (x=0;x<64;x++) for (y=0;y<64;y++) *dest++ = spotvis[y][x]; grneeded[picnum]&= ~ca_levelbit; MM_FreePtr (&grsegs[picnum]); }
void PlayDemo (int demonumber) { int length; #ifdef DEMOSEXTERN // debug: load chunk #ifndef SPEARDEMO int dems[4]={T_DEMO0,T_DEMO1,T_DEMO2,T_DEMO3}; #else int dems[1]={T_DEMO0}; #endif CA_CacheGrChunk(dems[demonumber]); demoptr = grsegs[dems[demonumber]]; MM_SetLock (&grsegs[dems[demonumber]],true); #else demoname[4] = '0'+demonumber; CA_LoadFile (demoname,&demobuffer); MM_SetLock (&demobuffer,true); demoptr = (char far *)demobuffer; #endif NewGame (1,0); gamestate.mapon = *demoptr++; gamestate.difficulty = gd_hard; length = *((unsigned far *)demoptr)++; demoptr++; lastdemoptr = demoptr-4+length; VW_FadeOut (); SETFONTCOLOR(0,15); DrawPlayScreen (); VW_FadeIn (); startgame = false; demoplayback = true; SetupGameLevel (); StartMusic (); PM_CheckMainMem (); fizzlein = true; PlayLoop (); #ifdef DEMOSEXTERN UNCACHEGRCHUNK(dems[demonumber]); #else MM_FreePtr (&demobuffer); #endif demoplayback = false; StopMusic (); VW_FadeOut (); ClearMemory (); }
/////////////////////////////////////////////////////////////////////////// // // US_RestoreSaveWindow() - Restores the background of the size of the // current window from the memory specified by save // /////////////////////////////////////////////////////////////////////////// void US_RestoreSaveWindow(memptr *save) { word screen; screen = bufferofs + panadjust + ylookup[WindowY] + (WindowX * CHARWIDTH); VW_MemToScreen(*save,screen,WindowW * CHARWIDTH,WindowH); MM_FreePtr(save); }
void FreeVGMFile(VGM_FILE* vgmFile, global_game_variables_t *gvar) { //if(vgmFile->data){ free(vgmFile->data); vgmFile->data = NULL; } MM_FreePtr(MEMPTRCONV gvar->ca.audiosegs[0], gvar); if(vgmFile->data) free(vgmFile->data); vgmFile->dataLen = 0; // return; }
void VW_FreeCursor (void) { if (cursornumber) { MM_SetLock (&grsegs[cursornumber],false); MM_SetPurge (&grsegs[cursornumber],3); MM_SetLock (&cursorsave,false); MM_FreePtr (&cursorsave); cursornumber = 0; } }
void CA_CacheMap(int mapnum) { long pos,compressed; int plane; byte *source; memptr buffer2seg; long expanded; mapon = mapnum; /* load the planes into the already allocated buffers */ for (plane = 0; plane < MAPPLANES; plane++) { pos = mapheaderseg[mapnum]->planestart[plane]; compressed = mapheaderseg[mapnum]->planelength[plane]; ReadSeek(maphandle, pos, SEEK_SET); MM_GetPtr((void *)&source, compressed); ReadBytes(maphandle, (byte *)source, compressed); expanded = source[0] | (source[1] << 8); MM_GetPtr(&buffer2seg, expanded); /* NOTE: CarmackExpand implicitly fixes endianness, a RLEW'd only map would (likely) need to be swapped in CA_RLEWexpand Wolfenstein 3D/Spear of Destiny maps are always Carmack'd so this case is OK. CA_RLEWexpand would need to be adjusted for Blake Stone and the like. */ CAL_CarmackExpand(source+2, (word *)buffer2seg, expanded); MM_FreePtr((void *)&source); expanded = 64*64*2; CA_RLEWexpand(((word *)buffer2seg)+1, mapsegs[plane], expanded, RLEWtag); MM_FreePtr(&buffer2seg); } }
void CA_UnCacheAudioChunk(int chunk) { if (w0 == true || w1 == true){ if (audiosegsWL6[chunk] == 0) { fprintf(stderr, "Trying to free null audio chunk %d!\n", chunk); return; } } else { if (audiosegsSOD[chunk] == 0) { fprintf(stderr, "Trying to free null audio chunk %d!\n", chunk); return; } } if (w0 == true || w1 == true){ MM_FreePtr((memptr *)&audiosegsWL6[chunk]); audiosegsWL6[chunk] = 0; } else { MM_FreePtr((memptr *)&audiosegsSOD[chunk]); audiosegsSOD[chunk] = 0; } }
static void PML_ClosePageFile() { if (PageFile != -1) CloseRead(PageFile); if (PMPages) { int i; for (i = 0; i < ChunksInFile; i++) { PageListStruct *page; page = &PMPages[i]; if (page->addr != NULL) { MM_FreePtr((memptr)&page->addr); } } MM_SetLock((memptr)&PMPages,false); MM_FreePtr((memptr)&PMPages); } }
void CA_UnCacheGrChunk(int chunk) { if (w0 == true){ if (grsegsWL1[chunk] == 0) { fprintf(stderr, "Trying to free null pointer %d!\n", chunk); return; } MM_FreePtr((memptr)&grsegsWL1[chunk]); grsegsWL1[chunk] = NULL; }else if (w1 == true){ if (grsegsWL6[chunk] == 0) { fprintf(stderr, "Trying to free null pointer %d!\n", chunk); return; } MM_FreePtr((memptr)&grsegsWL6[chunk]); grsegsWL6[chunk] = NULL; }else if (s0 == true){ if (grsegsSDM[chunk] == 0) { fprintf(stderr, "Trying to free null pointer %d!\n", chunk); return; } MM_FreePtr((memptr)&grsegsSDM[chunk]); grsegsSDM[chunk] = NULL; }else{ if (grsegsSOD[chunk] == 0) { fprintf(stderr, "Trying to free null pointer %d!\n", chunk); return; } MM_FreePtr((memptr)&grsegsSOD[chunk]); grsegsSOD[chunk] = NULL; } }
void PM_FreePage(int pagenum) { PageListStruct *page; if (pagenum >= ChunksInFile) Quit("PM_FreePage: Invalid page request"); page = &PMPages[pagenum]; if (page->addr != NULL) { MM_FreePtr((memptr)&page->addr); page->addr = NULL; } }
void CA_CacheGrChunk(int chunk) { long pos, compressed; byte *source; if (grhandle == -1) return; if (w0 == true){ if (grsegsWL1[chunk]) { return; } }else if (w1 == true){ if (grsegsWL6[chunk]) { return; } }else if (s0 == true){ if (grsegsSDM[chunk]) { return; } }else{ if (grsegsSOD[chunk]) { return; } } /* load the chunk into a buffer */ pos = grstarts[chunk]; compressed = grstarts[chunk+1]-pos; ReadSeek(grhandle, pos, SEEK_SET); MM_GetPtr((memptr)&source, compressed); ReadBytes(grhandle, source, compressed); if (w0 == true){ CAL_ExpandGrChunkWL1(chunk, source); } else if (w1 == true){ CAL_ExpandGrChunkWL6(chunk, source); }else if (s0 == true){ CAL_ExpandGrChunkSDM(chunk, source); }else{ CAL_ExpandGrChunkSOD(chunk, source); } MM_FreePtr((memptr)&source); }
void VW_SetCursor (id0_int_t spritenum) { if (cursornumber) { MM_SetLock (&grsegs[cursornumber],false); MM_FreePtr (&cursorsave); } cursornumber = spritenum; CA_CacheGrChunk (spritenum); MM_SetLock (&grsegs[cursornumber],true); cursorwidth = spritetable[spritenum-STARTSPRITES].width+1; cursorheight = spritetable[spritenum-STARTSPRITES].height; MM_GetPtr (&cursorsave,cursorwidth*cursorheight*5); }
void SetupScalePic (id0_unsigned_t picnum) { id0_unsigned_t scnum; scnum = picnum-FIRSTSCALEPIC; if (shapedirectory[scnum]) { MM_SetPurge ((memptr *)&shapedirectory[scnum],0); return; // allready in memory } CA_CacheGrChunk (picnum); DeplanePic (picnum); shapesize[scnum] = BuildCompShape (&shapedirectory[scnum]); grneeded[picnum]&= ~ca_levelbit; MM_FreePtr (&grsegs[picnum]); }
//-------------------------------------------------------------------------- // BLoad() -- THIS HAS NOT BEEN FULLY TESTED! // // NOTICE : This version of BLOAD is compatable with JAMPak V3.0 and the // new fileformat... //-------------------------------------------------------------------------- id0_unsigned_long_t BLoad(const id0_char_t *SourceFile, memptr *DstPtr) { BE_FILE_T handle; memptr SrcPtr; //id0_unsigned_long_t i, j, k, r, c; //id0_word_t flags; id0_byte_t Buffer[8]; id0_unsigned_long_t SrcLen,DstLen; struct CMP1Header CompHeader; id0_boolean_t Compressed = false; memset((void *)&CompHeader,0,sizeof(struct CMP1Header)); // // Open file to load.... // if (!BE_Cross_IsFileValid(handle = BE_Cross_open_for_reading(SourceFile))) //if ((handle = open(SourceFile, O_RDONLY|O_BINARY)) == -1) return(0); // // Look for JAMPAK headers // BE_Cross_readInt8LEBuffer(handle,Buffer,4); //read(handle,Buffer,4); if (!strncmp((char *)Buffer,COMP,4)) { // // Compressed under OLD file format // Compressed = true; SrcLen = Verify(SourceFile); BE_Cross_readInt32LE(handle, &CompHeader.OrginalLen); //read(handle,(void *)&CompHeader.OrginalLen,4); CompHeader.CompType = ct_LZW; MM_GetPtr(DstPtr,CompHeader.OrginalLen); if (!*DstPtr) return(0); } else if (!strncmp((char *)Buffer,CMP1,4)) { // // Compressed under new file format... // Compressed = true; SrcLen = Verify(SourceFile); BE_Cross_readInt8LEBuffer(handle,(void *)&CompHeader,sizeof(struct CMP1Header)); //read(handle,(void *)&CompHeader,sizeof(struct CMP1Header)); // REFKEEN - Big Endian support #ifdef REFKEEN_ARCH_BIG_ENDIAN CompHeader.CompType = BE_Cross_Swap16LE(CompHeader.CompType); CompHeader.OrginalLen = BE_Cross_Swap32LE(CompHeader.OrginalLen); CompHeader.CompressLen = BE_Cross_Swap32LE(CompHeader.CompressLen); #endif MM_GetPtr(DstPtr,CompHeader.OrginalLen); if (!*DstPtr) return(0); } else DstLen = Verify(SourceFile); // // Load the file in memory... // if (Compressed) { DstLen = CompHeader.OrginalLen; // REFKEEN - Looks like this is an unsigned comparison in original EXE if (((id0_unsigned_long_t)MM_TotalFree() < SrcLen) && (CompHeader.CompType)) { if (!InitBufferedIO(handle,&lzwBIO)) Quit("No memory for buffered I/O."); switch (CompHeader.CompType) { #if LZW_SUPPORT case ct_LZW: //lzwDecompress(&lzwBIO,MK_FP(*DstPtr,0),CompHeader.OrginalLen,(SRC_BFILE|DEST_MEM)); lzwDecompress(&lzwBIO,*DstPtr,CompHeader.OrginalLen,(SRC_BFILE|DEST_MEM)); break; #endif #if LZH_SUPPORT case ct_LZH: //lzhDecompress(&lzwBIO,MK_FP(*DstPtr,0),CompHeader.OrginalLen,CompHeader.CompressLen,(SRC_BFILE|DEST_MEM)); lzhDecompress(&lzwBIO,*DstPtr,CompHeader.OrginalLen,CompHeader.CompressLen,(SRC_BFILE|DEST_MEM)); break; #endif default: Quit("BLoad() - Unrecognized/Supported compression"); break; } FreeBufferedIO(&lzwBIO); } else { // REFKEEN - Better close the current file handle before re-opening here BE_Cross_close(handle); // CA_LoadFile(SourceFile,&SrcPtr); switch (CompHeader.CompType) { #if LZW_SUPPORT case ct_LZW: //lzwDecompress(MK_FP(SrcPtr,8),MK_FP(*DstPtr,0),CompHeader.OrginalLen,(SRC_MEM|DEST_MEM)); lzwDecompress((id0_byte_t *)SrcPtr + 8,*DstPtr,CompHeader.OrginalLen,(SRC_MEM|DEST_MEM)); break; #endif #if LZH_SUPPORT case ct_LZH: //lzhDecompress(MK_FP(SrcPtr,8),MK_FP(*DstPtr,0),CompHeader.OrginalLen,CompHeader.CompressLen,(SRC_MEM|DEST_MEM)); lzhDecompress((id0_byte_t *)SrcPtr + 8,*DstPtr,CompHeader.OrginalLen,CompHeader.CompressLen,(SRC_MEM|DEST_MEM)); break; #endif default: Quit("BLoad() - Unrecognized/Supported compression"); break; } MM_FreePtr(&SrcPtr); // REFKEEN - File handle already closed return(DstLen); } } else { // REFKEEN - Again we close the current file handle first, then load and finally return DstLen without re-closing file handle BE_Cross_close(handle); CA_LoadFile(SourceFile,DstPtr); return(DstLen); } BE_Cross_close(handle); return(DstLen); }
static void CAL_SetupGrFile() { char fname[13]; int handle; byte *grtemp; int i; /* load vgadict.ext (huffman dictionary for graphics files) */ strcpy(fname, gdictname); strcat(fname, extension); handle = OpenRead(fname); if (handle == -1) CA_CannotOpen(fname); for (i = 0; i < 256; i++) { grhuffman[i].bit0 = ReadInt16(handle); grhuffman[i].bit1 = ReadInt16(handle); } CloseRead(handle); /* load the data offsets from vgahead.ext */ if (w0 == true){ MM_GetPtr((memptr)&grstarts, (NUMCHUNKSWL1+1)*4); MM_GetPtr((memptr)&grtemp, (NUMCHUNKSWL1+1)*3); }else if (w1 == true){ MM_GetPtr((memptr)&grstarts, (NUMCHUNKSWL6+1)*4); MM_GetPtr((memptr)&grtemp, (NUMCHUNKSWL6+1)*3); }else if (s0 == true){ MM_GetPtr((memptr)&grstarts, (NUMCHUNKSSDM+1)*4); MM_GetPtr((memptr)&grtemp, (NUMCHUNKSSDM+1)*3); }else{ MM_GetPtr((memptr)&grstarts, (NUMCHUNKSSOD+1)*4); MM_GetPtr((memptr)&grtemp, (NUMCHUNKSSOD+1)*3); } strcpy(fname, gheadname); strcat(fname, extension); handle = OpenRead(fname); if (handle == -1) CA_CannotOpen(fname); if (w0 == true){ ReadBytes(handle, grtemp, (NUMCHUNKSWL1+1)*3); for (i = 0; i < NUMCHUNKSWL1+1; i++) grstarts[i] = (grtemp[i*3+0]<<0)|(grtemp[i*3+1]<<8)|(grtemp[i*3+2]<<16); }else if (w1 == true){ ReadBytes(handle, grtemp, (NUMCHUNKSWL6+1)*3); for (i = 0; i < NUMCHUNKSWL6+1; i++) grstarts[i] = (grtemp[i*3+0]<<0)|(grtemp[i*3+1]<<8)|(grtemp[i*3+2]<<16); }else if (s0 == true){ ReadBytes(handle, grtemp, (NUMCHUNKSSDM+1)*3); for (i = 0; i < NUMCHUNKSSDM+1; i++) grstarts[i] = (grtemp[i*3+0]<<0)|(grtemp[i*3+1]<<8)|(grtemp[i*3+2]<<16); }else{ ReadBytes(handle, grtemp, (NUMCHUNKSSOD+1)*3); for (i = 0; i < NUMCHUNKSSOD+1; i++) grstarts[i] = (grtemp[i*3+0]<<0)|(grtemp[i*3+1]<<8)|(grtemp[i*3+2]<<16); } MM_FreePtr((memptr)&grtemp); CloseRead(handle); /* Open the graphics file, leaving it open until the game is finished */ strcpy(fname, gfilename); strcat(fname, extension); grhandle = OpenRead(fname); if (grhandle == -1) CA_CannotOpen(fname); /* load the pic headers into pictable */ CA_CacheGrChunk(STRUCTPIC); if (w0 == true){ grtemp = grsegsWL1[STRUCTPIC]; for (i = 0; i < NUMPICSWL1; i++) { pictableWL1[i].width = grtemp[i*4+0] | (grtemp[i*4+1] << 8); pictableWL1[i].height = grtemp[i*4+2] | (grtemp[i*4+3] << 8); } }else if (w1 == true){ grtemp = grsegsWL6[STRUCTPIC]; for (i = 0; i < NUMPICSWL6; i++) { pictableWL6[i].width = grtemp[i*4+0] | (grtemp[i*4+1] << 8); pictableWL6[i].height = grtemp[i*4+2] | (grtemp[i*4+3] << 8); } }else if (s0 == true){ grtemp = grsegsSDM[STRUCTPIC]; for (i = 0; i < NUMPICSSDM; i++) { pictableSDM[i].width = grtemp[i*4+0] | (grtemp[i*4+1] << 8); pictableSDM[i].height = grtemp[i*4+2] | (grtemp[i*4+3] << 8); } }else{ grtemp = grsegsSOD[STRUCTPIC]; for (i = 0; i < NUMPICSSOD; i++) { pictableSOD[i].width = grtemp[i*4+0] | (grtemp[i*4+1] << 8); pictableSOD[i].height = grtemp[i*4+2] | (grtemp[i*4+3] << 8); } } CA_UnCacheGrChunk(STRUCTPIC); }
id0_boolean_t LoadTheGame(BE_FILE_T file) { id0_unsigned_t i,x,y; objtype /**obj,*/*prev,*next,*followed; id0_unsigned_t compressed,expanded; id0_unsigned_t id0_far *map,tile; memptr bigbuffer; // (REFKEEN) Reading fields one-by-one in a cross-platform manner if (!LoadGameState(file, &gamestate)) //if (!CA_FarRead(file,(void id0_far *)&gamestate,sizeof(gamestate))) return(false); SetupGameLevel (); // load in and cache the base old level expanded = mapwidth * mapheight * 2; MM_GetPtr (&bigbuffer,expanded); for (i = 0;i < 3;i+=2) // Read planes 0 and 2 { if (BE_Cross_readInt16LE(file, &compressed) != 2) //if (!CA_FarRead(file,(id0_byte_t id0_far *)&compressed,sizeof(compressed)) ) { MM_FreePtr (&bigbuffer); return(false); } if (BE_Cross_readInt16LEBuffer(file, bigbuffer, compressed) != compressed) //if (!CA_FarRead(file,(id0_byte_t id0_far *)bigbuffer,compressed) ) { MM_FreePtr (&bigbuffer); return(false); } CA_RLEWexpand ((id0_unsigned_t id0_huge *)bigbuffer, (id0_unsigned_t id0_huge *)mapsegs[i],expanded,RLETAG); } MM_FreePtr (&bigbuffer); // // copy the wall data to a data segment array again, to handle doors and // bomb walls that are allready opened // memset (tilemap,0,sizeof(tilemap)); memset (actorat,0,sizeof(actorat)); map = mapsegs[0]; for (y=0;y<mapheight;y++) for (x=0;x<mapwidth;x++) { tile = *map++; if (tile<NUMFLOORS) { tilemap[x][y] = tile; if (tile>0) actorat[x][y] = tile; //(id0_unsigned_t)actorat[x][y] = tile; } } // Read the object list back in - assumes at least one object in list InitObjList (); newobj = player; while (true) { prev = newobj->prev; next = newobj->next; // (REFKEEN) Reading fields one-by-one in a cross-platform manner if (!LoadObject(file, newobj)) //if (!CA_FarRead(file,(void id0_far *)newobj,sizeof(objtype))) return(false); followed = newobj->next; newobj->prev = prev; newobj->next = next; actorat[newobj->tilex][newobj->tiley] = COMPAT_OBJ_CONVERT_OBJ_PTR_TO_DOS_PTR(newobj); // drop a new marker //actorat[newobj->tilex][newobj->tiley] = newobj; // drop a new marker if (followed) GetNewObj (false); else break; } return(true); }
id0_boolean_t SaveTheGame(BE_FILE_T file) { id0_word_t i,compressed,expanded; objtype *o; memptr bigbuffer; // save the sky and ground colors // REFKEEN - But not before converting to original 16-bit pointers (reusing i variable) i = GetSkyGndColorDOSPtrFromNativePointer(skycolor); if (BE_Cross_writeInt16LE(file, &i) != 2) //if (!CA_FarWrite(file,(void id0_far *)&skycolor,sizeof(skycolor))) return(false); i = GetSkyGndColorDOSPtrFromNativePointer(groundcolor); if (BE_Cross_writeInt16LE(file, &i) != 2) //if (!CA_FarWrite(file,(void id0_far *)&groundcolor,sizeof(groundcolor))) return(false); if (BE_Cross_writeInt16LE(file, &FreezeTime) != 2) //if (!CA_FarWrite(file,(void id0_far *)&FreezeTime,sizeof(FreezeTime))) return(false); // (REFKEEN) Writing fields one-by-one in a cross-platform manner if (!SaveGameState(file, &gamestate)) //if (!CA_FarWrite(file,(void id0_far *)&gamestate,sizeof(gamestate))) return(false); if (BE_Cross_write_boolean_To16LE(file, &EASYMODEON) != 2) //if (!CA_FarWrite(file,(void id0_far *)&EASYMODEON,sizeof(EASYMODEON))) return(false); expanded = mapwidth * mapheight * 2; MM_GetPtr (&bigbuffer,expanded); for (i = 0;i < 3;i+=2) // Write planes 0 and 2 { // // leave a word at start of compressed data for compressed length // compressed = (id0_unsigned_t)CA_RLEWCompress ((id0_unsigned_t id0_huge *)mapsegs[i] ,expanded,((id0_unsigned_t id0_huge *)bigbuffer)+1,RLETAG); *(id0_unsigned_t id0_huge *)bigbuffer = compressed; if (BE_Cross_writeInt16LEBuffer(file, bigbuffer, compressed+2) != (id0_word_t)(compressed+2)) //if (!CA_FarWrite(file,(id0_byte_t id0_far *)bigbuffer,compressed+2) ) { MM_FreePtr (&bigbuffer); return(false); } } for (o = player;o;o = o->next) // (REFKEEN) Writing fields one-by-one in a cross-platform manner if (!SaveObject(file, o)) //if (!CA_FarWrite(file,(void id0_far *)o,sizeof(objtype))) { MM_FreePtr (&bigbuffer); return(false); } MM_FreePtr (&bigbuffer); return(true); }
id0_boolean_t LoadGame(BE_FILE_T file) { id0_word_t i/*,j,size*/; //objtype *o; //id0_int_t orgx,orgy; objtype *prev,*next,*followed; id0_unsigned_t compressed,expanded; memptr bigbuffer; // (REFKEEN) Reading fields one-by-one in a cross-platform manner if (!LoadGameState(file, &gamestate)) //if (!CA_FarRead(file,(void id0_far *)&gamestate,sizeof(gamestate))) return(false); // drop down a cache level and mark everything, so when the option screen // is exited it will be cached ca_levelbit >>= 1; ca_levelnum--; SetupGameLevel (false); // load in and cache the base old level titleptr[ca_levelnum] = levelnames[mapon]; ca_levelbit <<= 1; ca_levelnum ++; expanded = mapwidth * mapheight * 2; MM_GetPtr (&bigbuffer,expanded); for (i = 0;i < 3;i++) // Read all three planes of the map { if (BE_Cross_readInt16LE(file, &compressed) != 2) //if (!CA_FarRead(file,(id0_byte_t id0_far *)&compressed,sizeof(compressed)) ) { MM_FreePtr (&bigbuffer); return(false); } if (BE_Cross_readInt16LEBuffer(file, bigbuffer, compressed) != compressed) //if (!CA_FarRead(file,(id0_byte_t id0_far *)bigbuffer,compressed) ) { MM_FreePtr (&bigbuffer); return(false); } CA_RLEWexpand ((id0_unsigned_t id0_huge *)bigbuffer, (id0_unsigned_t id0_huge *)mapsegs[i],compressed,RLETAG); } MM_FreePtr (&bigbuffer); // Read the object list back in - assumes at least one object in list InitObjArray (); newobj = player; prev = newobj->prev; next = newobj->next; // (REFKEEN) Reading fields one-by-one in a cross-platform manner if (!LoadObject(file, newobj)) //if (!CA_FarRead(file,(void id0_far *)newobj,sizeof(objtype))) return(false); newobj->prev = prev; newobj->next = next; newobj->needtoreact = true; newobj->sprite = NULL; newobj = scoreobj; while (true) { prev = newobj->prev; next = newobj->next; // And again if (!LoadObject(file, newobj)) //if (!CA_FarRead(file,(void id0_far *)newobj,sizeof(objtype))) return(false); followed = newobj->next; newobj->prev = prev; newobj->next = next; newobj->needtoreact = true; newobj->sprite = NULL; if (followed) GetNewObj (false); else break; } scoreobj->temp1 = scoreobj->temp2 = -1; // force score to be updated scoreobj->temp3 = -1; // and flower power scoreobj->temp4 = -1; // and lives #if 0 *((id0_long_t *)&(scoreobj->temp1)) = -1; // force score to be updated scoreobj->temp3 = -1; // and flower power scoreobj->temp4 = -1; // and lives #endif return(true); }
unsigned BuildCompScale (int height, memptr *finalspot) { t_compscale _seg *work; byte far *code; int i; long fix,step; unsigned src,totalscaled,totalsize; int startpix,endpix,toppix; MM_GetPtr (&(memptr)work,20000); step = ((long)height<<16) / 64; code = &work->code[0]; toppix = (viewheight-height)/2; fix = 0; for (src=0;src<=64;src++) { startpix = fix>>16; fix += step; endpix = fix>>16; work->start[src] = startpix; if (endpix>startpix) work->width[src] = endpix-startpix; else work->width[src] = 0; // // mark the start of the code // work->codeofs[src] = FP_OFF(code); // // compile some code if the source pixel generates any screen pixels // startpix+=toppix; endpix+=toppix; if (startpix == endpix || endpix < 0 || startpix >= VIEWHEIGHT || src == 64) continue; // // mov al,[si+src] // *code++ = 0x8a; *code++ = 0x44; *code++ = src; for (;startpix<endpix;startpix++) { if (startpix >= VIEWHEIGHT) break; // off the bottom of the view area if (startpix < 0) continue; // not into the view area // // and [es:di+heightofs],al // *code++ = 0x26; *code++ = 0x20; *code++ = 0x85; *((unsigned far *)code)++ = startpix*screenbwide; } } // // retf // *code++ = 0xcb; totalsize = FP_OFF(code); MM_GetPtr (finalspot,totalsize); _fmemcpy ((byte _seg *)(*finalspot),(byte _seg *)work,totalsize); MM_FreePtr (&(memptr)work); return totalsize; }
//-------------------------------------------------------------------------- // BLoad() -- THIS HAS NOT BEEN FULLY TESTED! // // NOTICE : This version of BLOAD is compatable with JAMPak V3.0 and the // new fileformat... //-------------------------------------------------------------------------- unsigned long BLoad(char *SourceFile, memptr *DstPtr) { int handle; memptr SrcPtr; unsigned long i, j, k, r, c; word flags; byte Buffer[8]; unsigned long SrcLen,DstLen; struct CMP1Header CompHeader; boolean Compressed = false; memset((void *)&CompHeader,0,sizeof(struct CMP1Header)); // // Open file to load.... // if ((handle = open(SourceFile, O_RDONLY|O_BINARY)) == -1) return(0); // // Look for JAMPAK headers // read(handle,Buffer,4); if (!strncmp(Buffer,COMP,4)) { // // Compressed under OLD file format // Compressed = true; SrcLen = Verify(SourceFile); read(handle,(void *)&CompHeader.OrginalLen,4); CompHeader.CompType = ct_LZW; MM_GetPtr(DstPtr,CompHeader.OrginalLen); if (!*DstPtr) return(0); } else if (!strncmp(Buffer,CMP1,4)) { // // Compressed under new file format... // Compressed = true; SrcLen = Verify(SourceFile); read(handle,(void *)&CompHeader,sizeof(struct CMP1Header)); MM_GetPtr(DstPtr,CompHeader.OrginalLen); if (!*DstPtr) return(0); } else DstLen = Verify(SourceFile); // // Load the file in memory... // if (Compressed) { DstLen = CompHeader.OrginalLen; if ((MM_TotalFree() < SrcLen) && (CompHeader.CompType)) { if (!InitBufferedIO(handle,&lzwBIO)) Quit("No memory for buffered I/O."); switch (CompHeader.CompType) { #if LZW_SUPPORT case ct_LZW: lzwDecompress(&lzwBIO,MK_FP(*DstPtr,0),CompHeader.OrginalLen,(SRC_BFILE|DEST_MEM)); break; #endif #if LZH_SUPPORT case ct_LZH: lzhDecompress(&lzwBIO,MK_FP(*DstPtr,0),CompHeader.OrginalLen,CompHeader.CompressLen,(SRC_BFILE|DEST_MEM)); break; #endif default: Quit("BLoad() - Unrecognized/Supported compression"); break; } FreeBufferedIO(&lzwBIO); } else { CA_LoadFile(SourceFile,&SrcPtr); switch (CompHeader.CompType) { #if LZW_SUPPORT case ct_LZW: lzwDecompress(MK_FP(SrcPtr,8),MK_FP(*DstPtr,0),CompHeader.OrginalLen,(SRC_MEM|DEST_MEM)); break; #endif #if LZH_SUPPORT case ct_LZH: lzhDecompress(MK_FP(SrcPtr,8),MK_FP(*DstPtr,0),CompHeader.OrginalLen,CompHeader.CompressLen,(SRC_MEM|DEST_MEM)); break; #endif default: Quit("BLoad() - Unrecognized/Supported compression"); break; } MM_FreePtr(&SrcPtr); } } else CA_LoadFile(SourceFile,DstPtr); close(handle); return(DstLen); }
id0_boolean_t LoadTheGame(BE_FILE_T file) { id0_unsigned_t i,x,y; objtype /**obj,*/*prev,*next,*followed; id0_unsigned_t compressed,expanded; id0_unsigned_t id0_far *map,tile; memptr bigbuffer; screenpage = 0; FreeUpMemory(); playstate = ex_loadedgame; // load the sky and ground colors // REFKEEN - But not before converting from original 16-bit pointers (reusing i variable) if (BE_Cross_readInt16LE(file, &i) != 2) //if (!CA_FarRead(file,(void id0_far *)&skycolor,sizeof(skycolor))) return(false); skycolor = GetSkyGndColorPtrFromDOSPointer(i); if (BE_Cross_readInt16LE(file, &i) != 2) //if (!CA_FarRead(file,(void id0_far *)&groundcolor,sizeof(groundcolor))) return(false); groundcolor = GetSkyGndColorPtrFromDOSPointer(i); if (BE_Cross_readInt16LE(file, &FreezeTime) != 2) //if (!CA_FarRead(file,(void id0_far *)&FreezeTime,sizeof(FreezeTime))) return(false); // (REFKEEN) Reading fields one-by-one in a cross-platform manner if (!LoadGameState(file, &gamestate)) //if (!CA_FarRead(file,(void id0_far *)&gamestate,sizeof(gamestate))) return(false); if (BE_Cross_read_boolean_From16LE(file, &EASYMODEON) != 2) //if (!CA_FarRead(file,(void id0_far *)&EASYMODEON,sizeof(EASYMODEON))) return(false); SetupGameLevel (); // load in and cache the base old level // (REFKEEN) DIFFERENCE FROM VANILLA CATACOMB ADVENTURES: // Don't do this check, we've already opened the file anyway // and this can lead to unexpected behaviors! #if 0 if (!FindRewritableFile(Filename,"SAVE GAME",-1)) Quit("Error: Can't find saved game file!"); #endif expanded = mapwidth * mapheight * 2; MM_GetPtr (&bigbuffer,expanded); for (i = 0;i < 3;i+=2) // Read planes 0 and 2 { if (BE_Cross_readInt16LE(file, &compressed) != 2) //if (!CA_FarRead(file,(id0_byte_t id0_far *)&compressed,sizeof(compressed)) ) { MM_FreePtr (&bigbuffer); return(false); } if (BE_Cross_readInt16LEBuffer(file, bigbuffer, compressed) != compressed) //if (!CA_FarRead(file,(id0_byte_t id0_far *)bigbuffer,compressed) ) { MM_FreePtr (&bigbuffer); return(false); } CA_RLEWexpand ((id0_unsigned_t id0_huge *)bigbuffer, (id0_unsigned_t id0_huge *)mapsegs[i],expanded,RLETAG); } MM_FreePtr (&bigbuffer); // // copy the wall data to a data segment array again, to handle doors and // bomb walls that are allready opened // memset (tilemap,0,sizeof(tilemap)); memset (actorat,0,sizeof(actorat)); map = mapsegs[0]; for (y=0;y<mapheight;y++) for (x=0;x<mapwidth;x++) { tile = *map++; if (tile<NUMFLOORS) { if (tile != INVISIBLEWALL) tilemap[x][y] = tile; if (tile>0) actorat[x][y] = tile; //(id0_unsigned_t)actorat[x][y] = tile; } } // Read the object list back in - assumes at least one object in list InitObjList (); newobj = player; while (true) { prev = newobj->prev; next = newobj->next; // (REFKEEN) Reading fields one-by-one in a cross-platform manner if (!LoadObject(file, newobj)) //if (!CA_FarRead(file,(void id0_far *)newobj,sizeof(objtype))) return(false); followed = newobj->next; newobj->prev = prev; newobj->next = next; actorat[newobj->tilex][newobj->tiley] = COMPAT_OBJ_CONVERT_OBJ_PTR_TO_DOS_PTR(newobj); // drop a new marker //actorat[newobj->tilex][newobj->tiley] = newobj; // drop a new marker if (followed) GetNewObj (false); else break; } return(true); }