// // 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 }
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 MM_GetPtr (memptr *baseptr,id0_unsigned_long_t size) { mmblocktype *scan, *lastscan, *endscan, *purge, *next; id0_int_t search; id0_unsigned_t needed,startseg; needed = (size+15)/16; // convert size from bytes to paragraphs // Formerly known as GETNEWBLOCK if( !(mmnew=mmfree) ) { Quit("MM_GETNEWBLOCK: No free blocks!"); } mmfree=mmfree->next; // fill in start and next after a spot is found mmnew->length = needed; mmnew->useptr = baseptr; mmnew->attributes = BASEATTRIBUTES; for (search = 0; search<3; search++) { // // first search: try to allocate right after the rover, then on up // second search: search from the head pointer up to the rover // third search: compress memory, then scan from start if (search == 1 && mmrover == mmhead) search++; switch (search) { case 0: lastscan = mmrover; scan = mmrover->next; endscan = nullptr; break; case 1: lastscan = mmhead; scan = mmhead->next; endscan = mmrover; break; case 2: MM_SortMem (); lastscan = mmhead; scan = mmhead->next; endscan = nullptr; break; } startseg = lastscan->start + lastscan->length; while (scan != endscan) { if (scan->start - startseg >= needed) { // // got enough space between the end of lastscan and // the start of scan, so throw out anything in the middle // and allocate the new block // purge = lastscan->next; lastscan->next = mmnew; mmnew->start = startseg; *baseptr = EMULATED_SEG_TO_PTR(startseg); mmnew->next = scan; while ( purge != scan) { // free the purgable block next = purge->next; FREEBLOCK(purge); purge = next; // purge another if not at scan } mmrover = mmnew; return; // good allocation! } // // if this block is purge level zero or locked, skip past it // if ( (scan->attributes & LOCKBIT) || !(scan->attributes & PURGEBITS) ) { lastscan = scan; startseg = lastscan->start + lastscan->length; } scan=scan->next; // look at next line } } #ifdef REFKEEN_VER_KDREAMS_CGA_ALL Quit ("MM_GetPtr: Out of memory!"); #elif defined REFKEEN_VER_KDREAMS_ANYEGA_ALL Quit ("Out of memory! Please make sure you have enough free memory."); #endif }
void MM_GetPtr (memptr *baseptr,id0_unsigned_long_t size) { mmblocktype id0_far *scan,id0_far *lastscan,id0_far *endscan ,id0_far *purge,id0_far *next; id0_int_t search; id0_unsigned_t needed,startseg; needed = (size+15)/16; // convert size from bytes to paragraphs GETNEWBLOCK; // fill in start and next after a spot is found mmnew->length = needed; mmnew->useptr = baseptr; mmnew->attributes = BASEATTRIBUTES; for (search = 0; search<3; search++) { // // first search: try to allocate right after the rover, then on up // second search: search from the head pointer up to the rover // third search: compress memory, then scan from start if (search == 1 && mmrover == mmhead) search++; switch (search) { case 0: lastscan = mmrover; scan = mmrover->next; endscan = NULL; break; case 1: lastscan = mmhead; scan = mmhead->next; endscan = mmrover; break; case 2: MM_SortMem (); lastscan = mmhead; scan = mmhead->next; endscan = NULL; break; } startseg = lastscan->start + lastscan->length; while (scan != endscan) { if ((refkeen_current_gamever == BE_GAMEVER_KDREAMS2015) || (scan->start - startseg >= needed)) { // // got enough space between the end of lastscan and // the start of scan, so throw out anything in the middle // and allocate the new block // purge = lastscan->next; lastscan->next = mmnew; if (refkeen_current_gamever == BE_GAMEVER_KDREAMS2015) { // Add a few more bytes as a workaround for vanilla bugs // in places like CA_HuffExpand *baseptr = malloc(size+16); if (*baseptr == NULL) Quit ("Out of memory! Please make sure you have enough free memory."); } else { mmnew->start /*= *(id0_unsigned_t *)baseptr*/ = startseg; *baseptr = EMULATED_SEG_TO_PTR(startseg); } mmnew->next = scan; while ( purge != scan) { // free the purgable block next = purge->next; FREEBLOCK(purge); purge = next; // purge another if not at scan } mmrover = mmnew; return; // good allocation! } // // if this block is purge level zero or locked, skip past it // if ( (scan->attributes & LOCKBIT) || !(scan->attributes & PURGEBITS) ) { lastscan = scan; startseg = lastscan->start + lastscan->length; } scan=scan->next; // look at next line } } Quit ((current_gamever_int < 110) ? "MM_GetPtr: Out of memory!" : "Out of memory! Please make sure you have enough free memory."); }
void ClearMemory (void) { PM_UnlockMainMem(); SD_StopDigitized(); MM_SortMem (); }