This patch removes some obsolete code that provides code segment management on older 68k Macintoshes. Specifically, one would need the segment management only if: 1. You are compiling the code yourself. Most Macintosh players use the precompiled official binaries, which are built with Metrowerks Codewarrior using the large memory model. 2. You are compiling for an 68k Macintosh using a small memory model. If your Mac has enough memory to load in the entire game, you might as well build using the large memory model. Newer PowerPC Macintoshes do not have segments, nor a segment model. This patch should be archived as the file sys/mac/old/macsegs. diff -c -r old/include/extern.h new/include/extern.h *** old/include/extern.h Mon Jun 7 21:46:55 1999 --- new/include/extern.h Mon Jun 21 12:52:04 1999 *************** *** 820,831 **** E int FDECL(macwrite, (int,void *,unsigned)); E long FDECL(macseek, (int,long,short)); - /* ### macmain.c ### */ - - #ifdef MAC68K - E void NDECL(UnloadAllSegments); - #endif - /* ### macsnd.c ### */ E void FDECL(mac_speaker, (struct obj *,char *)); --- 820,825 ---- diff -c -r old/src/allmain.c new/src/allmain.c *** old/src/allmain.c Mon Jun 7 21:45:57 1999 --- new/src/allmain.c Mon Jun 21 12:51:36 1999 *************** *** 62,70 **** #ifdef CLIPPING cliparound(u.ux, u.uy); #endif - #if defined(MAC68K) && defined(MAC_MPW32) && !defined(MODEL_FAR) - UnloadAllSegments(); /* Marks non-resident segments as purgeable */ - #endif get_nh_event(); #ifdef POSITIONBAR do_positionbar(); --- 62,67 ---- diff -c -r old/include/macwin.h new/include/macwin.h *** old/include/macwin.h Tue Apr 27 12:29:27 1999 --- new/include/macwin.h Mon Jun 21 12:57:46 1999 *************** *** 180,189 **** /* ### macmain.c ### */ - #ifdef MAC68K - /* extern void UnloadAllSegments( void ); declared in extern.h */ - extern void InitSegMgmt( void * ); /* called from macwin.c */ - #endif extern void NDECL ( finder_file_request ) ; /* ### mactty.c ### */ --- 180,185 ---- diff -c -r old/sys/mac/macmain.c new/sys/mac/macmain.c *** old/sys/mac/macmain.c Thu Apr 29 12:43:46 1999 --- new/sys/mac/macmain.c Mon Jun 21 12:56:40 1999 *************** *** 31,39 **** int NDECL(main); - #ifdef MAC68K - static void FDECL(IsResident,(void *)); - #endif static void NDECL(process_options); static void NDECL(whoami); --- 31,36 ---- *************** *** 147,171 **** UndimMenuBar ( ) ; /* Yes, this is the place for it (!) */ - attemptingto("proceed"); - #if defined(MAC68K) && defined(MAC_MPW32) && !defined(MODEL_FAR) - UnloadAllSegments(); /* Do this before naming residents */ - IsResident( (Ptr) um_dist ); /* Sample resident segments */ - IsResident( (Ptr) flush_screen ); - IsResident( (Ptr) rhack ); - IsResident( (Ptr) remove_cadavers ); - IsResident( (Ptr) dog_move ); - IsResident( (Ptr) gethungry ); - IsResident( (Ptr) engr_at ); - IsResident( (Ptr) domove ); - IsResident( (Ptr) carried ); - IsResident( (Ptr) movemon ); - IsResident( (Ptr) attacktype ) ; - IsResident( (Ptr) mac_get_nh_event ) ; - IsResident( (Ptr) dosounds ) ; - IsResident( (Ptr) t_at ) ; - IsResident( (Ptr) nh_timeout ) ; - #endif moveloop(); exit(EXIT_SUCCESS); /*NOTREACHED*/ --- 144,149 ---- *************** *** 452,639 **** } #endif /* MAC68K */ } - - - - /*------------------- UnloadAllSegments and support stuff --------------------------*/ - /* Derived from MacApp source */ - - /* - * Don't unload segments unless you are exactly controlling the file - * placement in each of the segments you plan to unload. - * - * The 68K MetroWerks compile is done with automatic segment placement, so - * don't mess with this stuff... - */ - #if defined(MAC68K) && !defined(__MWERKS__) /* segments only make sense on 68K macs */ - - typedef Handle **HandleListHandle; - typedef Boolean **BoolListHandle; - typedef short *ShortPtr, **ShortHandle; - - #if defined(MAC_MPW32) || defined(THINK_C) - pascal long GetA5(void) = { 0x2E8D }; /* MOVE.L A5,(A7) */ - pascal short GetCurJTOffset(void) = { 0x3EB8, 0x934 }; /* MOVE.W CurJTOffset,(SP) */ - #endif - - static void NDECL(ListGUnloads); - static short FDECL(GetSegNumber, (ShortPtr)); - static void FDECL(NotResident, (void *)); - - short pMaxSegNum = 0, /* Highest segment number */ - gCodeRefNum; /* rsrc refnum of the application */ - HandleListHandle gCodeSegs; /* List of code seg handles */ - BoolListHandle gIsResidentSeg; /* Resident flags */ - - #define kLoaded 0x4EF9 /* if loaded then a JMP instruction */ - #define kUnLoaded 0x3F3C /* if unloaded then a LoadSeg trap */ - /* Note: probably incorrect for -model far! */ - - /* #define TRACKSEGS /* Utility to print a trace of segment load frequencies. */ - - #ifdef TRACKSEGS - - long gUnloads[120]; - char gSegNames[120][16]; - - void ListGUnloads(void) - { - int i; - FILE *f; - - f = fopen("unloads","w"); - fprintf(f,"%d calls to UnloadAllSegments\n\n",gUnloads[0]); - for (i=1; i<=pMaxSegNum; i++) { - fprintf(f,"Unloaded %10s, segment %2d, %6d times\n",gSegNames[i],i,gUnloads[i]); - } - fclose(f); - } - - #endif - - short GetSegNumber(ShortPtr aProc) - /* Derives seg number from a procedure ptr */ - - { - if (*aProc == kLoaded) /* loaded segment */ - return(*--aProc); - else if (*aProc == kUnLoaded) /* unloaded segment */ - return(*++aProc); - else { - progerror("GetSegNumber was not passed an jump table address"); - return(1); - } - } - - void InitSegMgmt(void * mainSeg) - /* Initialise a list of handles to all the CODE segments and mark the mainseg as resident */ - { - short i, - lastRsrc, - rsrcID, - oldResFile; - Handle seg; - ResType rsrcType; - Str255 rsrcName; - - gCodeRefNum = HomeResFile(GetResource('CODE', 1)); - oldResFile = CurResFile(); - UseResFile(gCodeRefNum); - - /* Discover the highest CODE rsrc ID: be ready for noncontiguous IDs */ - lastRsrc = Count1Resources('CODE'); - SetResLoad(false); - for (i=1; i<=lastRsrc; i++) - if (seg = Get1IndResource('CODE', i)) { - GetResInfo(seg, &rsrcID, &rsrcType, rsrcName); - if (rsrcID > pMaxSegNum) pMaxSegNum = rsrcID; - } - - /* Make handles of appropriate size to keep flags/segment handles */ - SetResLoad(true); /* In case we fail */ - gCodeSegs = (HandleListHandle) NewHandle((pMaxSegNum+1) * sizeof(Handle)); - mustwork(MemError()); - gIsResidentSeg = (BoolListHandle) NewHandle((pMaxSegNum+1) * sizeof(Boolean)); - mustwork(MemError()); - SetResLoad(false); - - #ifdef TRACKSEGS - atexit(&ListGUnloads); - gUnloads[0]=0; - #endif - for (i=1; i<=pMaxSegNum; i++) { - (*gIsResidentSeg)[i] = false; - (*gCodeSegs)[i] = Get1Resource('CODE',i); /* Will be NIL if it doesn't exist */ - #ifdef TRACKSEGS - { /* Go get the segment name and save it */ - short id; - ResType rType; - Str255 name; - char *cptr; - - GetResInfo((*gCodeSegs)[i],&id,&rType,&name); - if (name[0]>15) name[0]=15; - cptr = p2cstr(&name); - cptr = strcpy(&gSegNames[i], &name); - gUnloads[i] = 0; - } - #endif - } - SetResLoad(true); - (*gIsResidentSeg)[GetSegNumber((ShortPtr)mainSeg)] = true; - UseResFile(oldResFile); - } - - - void UnloadAllSegments(void) - { - short i, - oldResFile; - Handle seg; - long jumpTablePtr; - - jumpTablePtr = GetA5() + GetCurJTOffset(); - oldResFile = CurResFile(); - UseResFile(gCodeRefNum); - #ifdef TRACKSEGS - gUnloads[0]++; - #endif - for (i=1; i<=pMaxSegNum; i++) - if (!(*gIsResidentSeg)[i]) { - seg = (*gCodeSegs)[i]; - if ((seg != (Handle) nil) && (*seg != (Ptr) nil)) /* Check it exists and hasn't been purged */ - if (HGetState(seg) & 0x80) { /* Is it locked? => loaded */ - #ifdef TRACKSEGS - gUnloads[i]++; - #endif - UnloadSeg( (void *) (jumpTablePtr + **(ShortHandle)seg + 2) ); - } - } - - UseResFile(oldResFile); - } - - static void IsResident( void * routineaddr ) - /* We want to move this high up in the heap as it won't be shifted again, so... */ - { - int segnum; - Handle theseg; - - segnum = GetSegNumber((ShortPtr)routineaddr); - theseg = (*gCodeSegs)[segnum]; - UnloadSeg( routineaddr ); - if (*theseg != nil) { - MoveHHi( theseg ); /* If it has been purged we can't do this */ - HLock( theseg ); - } - (*gIsResidentSeg)[segnum] = true; - } - - static void NotResident( void * routineaddr ) - { - (*gIsResidentSeg)[GetSegNumber((ShortPtr)routineaddr)] = false; - } - - #endif /* MAC68K */ /*macmain.c*/ --- 430,434 ---- diff -c -r old/sys/mac/macwin.c new/sys/mac/macwin.c *** old/sys/mac/macwin.c Mon Jun 7 21:46:52 1999 --- new/sys/mac/macwin.c Mon Jun 21 12:57:30 1999 *************** *** 307,317 **** long l ; long applLimit; - #ifdef MAC68K - #ifdef applec - UnloadSeg((Ptr) _DataInit); - #endif - #endif if ( LMGetDefltStack() < 50 * 1024L ) { applLimit = (long) LMGetCurStackBase() - (50 * 1024L); --- 307,312 ---- *************** *** 327,338 **** InitMenus ( ) ; InitDialogs ( ( ResumeProcPtr ) 0L ) ; TEInit ( ) ; - - #if defined(MAC68K) && !defined(__MWERKS__) - InitSegMgmt( itworked ); /* itworked is always in the main segment */ - #endif - - attemptingto("start up"); if ( Gestalt ( gestaltOSAttr , & l ) ) { macFlags . processes = 0 ; --- 322,327 ----