int gettimeofday(struct timeval *tv, struct timezone */*tz*/) { // return the time in tv as expected if (tv != NULL) { UnsignedWide tm; Microseconds(&tm); tv->tv_sec = tm.lo / 1000000; tv->tv_usec = tm.lo % 1000000; } return 0; // Unix value for successful #ifdef VERSION_1 /* Must be called only multiple-of-two times or the timer will be left primed. */ static TMTask tm; static boolean primed = FALSE; long rt; if (!primed) { // start the timer for the next time that we are called tm.tmAddr = NewTimerProc(timer_func); // we do not expect this to ever be called tm.tmCount = 0; // initialize all fields tm.tmWakeUp = 0; tm.tmReserved = 0; InsTime((struct QElem*)&tm); PrimeTime((struct QElem*)&tm, -LONG_MAX); primed = TRUE; rt = 0; } else { RmvTime((struct QElem*)&tm); // returns unused time in negative microseconds primed = FALSE; rt = LONG_MAX - -tm.tmCount; } // return the time in tv as expected if (tv != NULL) { tv->tv_sec = rt / 1000000; tv->tv_usec = rt % 1000000; } return 0; // Unix value for successful #endif // VERSION_1 }
void AsioSample::timerOff() { if(tmTaskOn) { RmvTime((QElemPtr)&myTmTask); tmTaskOn = false; } theSound = 0; }
int main(int argc, char *argv[]) #endif { int i; /* Index */ int iter; time_t time_and_date; /* Self-explanatory */ struct tm *loctime; double bmean; /* Benchmark mean */ double bstdev; /* Benchmark stdev */ double lx_memindex; /* Linux memory index (mainly integer operations)*/ double lx_intindex; /* Linux integer index */ double lx_fpindex; /* Linux floating-point index */ double intindex; /* Integer index */ double fpindex; /* Floating-point index */ ulong bnumrun; /* # of runs */ #ifdef MAC MaxApplZone(); #endif #ifdef MACTIMEMGR /* Set up high res timer */ MacHSTdelay=600*1000*1000; /* Delay is 10 minutes */ memset((char *)&myTMTask,0,sizeof(TMTask)); /* Prime and remove the task, calculating overhead */ PrimeTime((QElemPtr)&myTMTask,-MacHSTdelay); RmvTime((QElemPtr)&myTMTask); MacHSTohead=MacHSTdelay+myTMTask.tmCount; #endif #ifdef WIN31TIMER /* Set up the size of the timer info structure */ win31tinfo.dwSize=(DWORD)sizeof(TIMERINFO); /* Load library */ if((hThlp=LoadLibrary("TOOLHELP.DLL"))<32) { printf("Error loading TOOLHELP\n"); exit(0); } if(!(lpfn=GetProcAddress(hThlp,"TimerCount"))) { printf("TOOLHELP error\n"); exit(0); } #endif /* ** Set global parameters to default. */ global_min_ticks=MINIMUM_TICKS; global_min_seconds=MINIMUM_SECONDS; global_allstats=0; global_custrun=0; global_align=8; write_to_file=0; lx_memindex=(double)1.0; /* set for geometric mean computations */ lx_intindex=(double)1.0; lx_fpindex=(double)1.0; intindex=(double)1.0; fpindex=(double)1.0; mem_array_ents=0; /* Nothing in mem array */ /* ** We presume all tests will be run unless told ** otherwise */ for(i=0;i<NUMTESTS;i++) tests_to_do[i]=1; /* ** Initialize test data structures to default ** values. */ set_request_secs(); /* Set all request_secs fields */ global_numsortstruct.adjust=0; global_numsortstruct.arraysize=NUMARRAYSIZE; global_strsortstruct.adjust=0; global_strsortstruct.arraysize=STRINGARRAYSIZE; global_bitopstruct.adjust=0; global_bitopstruct.bitfieldarraysize=BITFARRAYSIZE; global_emfloatstruct.adjust=0; global_emfloatstruct.arraysize=EMFARRAYSIZE; global_fourierstruct.adjust=0; global_assignstruct.adjust=0; global_ideastruct.adjust=0; global_ideastruct.arraysize=IDEAARRAYSIZE; global_huffstruct.adjust=0; global_huffstruct.arraysize=HUFFARRAYSIZE; global_nnetstruct.adjust=0; global_lustruct.adjust=0; /* ** For Macintosh -- read the command line. */ #ifdef MAC UCommandLine(); #endif /* ** Handle any command-line arguments. */ if(argc>1) for(i=1;i<argc;i++) if(parse_arg(argv[i])==-1) { display_help(argv[0]); exit(0); } /* ** Output header */ #ifdef LINUX output_string("\nBYTEmark* Native Mode Benchmark ver. 2 (10/95)\n"); output_string("Index-split by Andrew D. Balsa (11/97)\n"); output_string("Linux/Unix* port by Uwe F. Mayer (12/96,11/97)\n"); #else output_string("BBBBBB YYY Y TTTTTTT EEEEEEE\n"); output_string("BBB B YYY Y TTT EEE\n"); output_string("BBB B YYY Y TTT EEE\n"); output_string("BBBBBB YYY Y TTT EEEEEEE\n"); output_string("BBB B YYY TTT EEE\n"); output_string("BBB B YYY TTT EEE\n"); output_string("BBBBBB YYY TTT EEEEEEE\n\n"); output_string("\nBYTEmark (tm) Native Mode Benchmark ver. 2 (10/95)\n"); #endif /* ** See if the user wants all stats. Output heading info ** if so. */ if(global_allstats) { output_string("\n"); output_string("============================== ALL STATISTICS ===============================\n"); time(&time_and_date); loctime=localtime(&time_and_date); sprintf(buffer,"**Date and time of benchmark run: %s",asctime(loctime)); output_string(buffer); sprintf(buffer,"**Sizeof: char:%u short:%u int:%u long:%u u8:%u u16:%u u32:%u int32:%u\n", (unsigned int)sizeof(char), (unsigned int)sizeof(short), (unsigned int)sizeof(int), (unsigned int)sizeof(long), (unsigned int)sizeof(u8), (unsigned int)sizeof(u16), (unsigned int)sizeof(u32), (unsigned int)sizeof(int32)); output_string(buffer); #ifdef LINUX #include "sysinfo.c" #else sprintf(buffer,"**%s\n",sysname); output_string(buffer); sprintf(buffer,"**%s\n",compilername); output_string(buffer); sprintf(buffer,"**%s\n",compilerversion); output_string(buffer); #endif output_string("=============================================================================\n"); } /* ** Execute the tests. */ output_string("\nNOTE!!! Iteration display disabled to prevent diffs from failing!\n"); #ifdef LINUX output_string("\nTEST : Iterations/sec. : Old Index : New Index\n"); output_string(" : : Pentium 90* : AMD K6/233*\n"); output_string("--------------------:------------------:-------------:------------\n"); #endif for(i=0;i<NUMTESTS;i++) { if(tests_to_do[i]) { sprintf(buffer,"%s :",ftestnames[i]); output_string(buffer); #if 0 if (0!=bench_with_confidence(i, &bmean, &bstdev, &bnumrun)){ output_string("\n** WARNING: The current test result is NOT 95 % statistically certain.\n"); output_string("** WARNING: The variation among the individual results is too large.\n"); output_string(" :"); } #endif for (iter = 0; iter < N_ITERATIONS; ++iter) { (*funcpointer[i])(); } #ifdef LINUX sprintf(buffer," %15.5g : %9.2f : %9.2f\n", bmean,bmean/bindex[i],bmean/lx_bindex[i]); #else sprintf(buffer," Iterations/sec.: %13.2f Index: %6.2f\n", /*bmean,bmean/bindex[i],*/ 0.0, 0.0); #endif output_string(buffer); /* ** Gather integer or FP indexes */ if((i==4)||(i==8)||(i==9)){ /* FP index */ fpindex=fpindex*(bmean/bindex[i]); /* Linux FP index */ lx_fpindex=lx_fpindex*(bmean/lx_bindex[i]); } else{ /* Integer index */ intindex=intindex*(bmean/bindex[i]); if((i==0)||(i==3)||(i==6)||(i==7)) /* Linux integer index */ lx_intindex=lx_intindex*(bmean/lx_bindex[i]); else /* Linux memory index */ lx_memindex=lx_memindex*(bmean/lx_bindex[i]); } if(global_allstats) { sprintf(buffer," Absolute standard deviation: %g\n",bstdev); output_string(buffer); if (bmean>(double)1e-100){ /* avoid division by zero */ sprintf(buffer," Relative standard deviation: %g %%\n", (double)100*bstdev/bmean); output_string(buffer); } sprintf(buffer," Number of runs: %lu\n",bnumrun); output_string(buffer); show_stats(i); sprintf(buffer,"Done with %s\n\n",ftestnames[i]); output_string(buffer); } } } /* printf("...done...\n"); */ /* ** Output the total indexes */ if(global_custrun==0) { output_string("==========================ORIGINAL BYTEMARK RESULTS==========================\n"); sprintf(buffer,"INTEGER INDEX : %.3f\n", /*pow(intindex,(double).142857)*/ 0.0); output_string(buffer); sprintf(buffer,"FLOATING-POINT INDEX: %.3f\n", /*pow(fpindex,(double).33333)*/ 0.0); output_string(buffer); output_string("Baseline (MSDOS*) : Pentium* 90, 256 KB L2-cache, Watcom* compiler 10.0\n"); #ifdef LINUX output_string("==============================LINUX DATA BELOW===============================\n"); hardware(write_to_file, global_ofile); #include "sysinfoc.c" sprintf(buffer,"MEMORY INDEX : %.3f\n", pow(lx_memindex,(double).3333333333)); output_string(buffer); sprintf(buffer,"INTEGER INDEX : %.3f\n", pow(lx_intindex,(double).25)); output_string(buffer); sprintf(buffer,"FLOATING-POINT INDEX: %.3f\n", pow(lx_fpindex,(double).3333333333)); output_string(buffer); output_string("Baseline (LINUX) : AMD K6/233*, 512 KB L2-cache, gcc 2.7.2.3, libc-5.4.38\n"); #endif output_string("* Trademarks are property of their respective holder.\n"); } exit(0); }
pascal OSErr IndexedSearch(CSParamPtr pb, long dirID) { static LevelRecHandle searchStack = NULL; /* static handle to LevelRec stack */ static Size searchStackSize = 0; /* size of static handle */ SearchPositionRecPtr catPosition; long modDate; short index = -1 ; ExtendedTMTask timerTask; OSErr result; short realVRefNum; Str63 itemName; CInfoPBRec cPB; long tempLong; Boolean includeFiles; Boolean includeDirs; Boolean includeNames; Str63 upperName; timerTask.stopSearch = false; /* don't stop yet! */ /* If request has a timeout, install a Time Manager task. */ if ( pb->ioSearchTime != 0 ) { /* Start timer */ timerTask.theTask.tmAddr = NewTimerUPP(TimeOutTask); InsTime((QElemPtr)&(timerTask.theTask)); PrimeTime((QElemPtr)&(timerTask.theTask), pb->ioSearchTime); } /* Check the parameter block passed for things that we don't want to assume */ /* are OK later in the code. For example, make sure pointers to data structures */ /* and buffers are not NULL. And while we're in there, see if the request */ /* specified searching for files, directories, or both, and see if the search */ /* was by full or partial name. */ result = VerifyUserPB(pb, &includeFiles, &includeDirs, &includeNames); if ( result == noErr ) { pb->ioActMatchCount = 0; /* no matches yet */ if ( includeNames ) { /* The search includes seach by full or partial name. */ /* Make an upper case copy of the match string to pass to */ /* CheckForMatches. */ BlockMoveData(pb->ioSearchInfo1->hFileInfo.ioNamePtr, upperName, pb->ioSearchInfo1->hFileInfo.ioNamePtr[0] + 1); /* Use the same non-international call the File Manager uses */ UpperString(upperName, true); } /* Prevent casting to my type throughout code */ catPosition = (SearchPositionRecPtr)&pb->ioCatPosition; /* Create searchStack first time called */ if ( searchStack == NULL ) { searchStack = (LevelRecHandle)NewHandle(kAdditionalLevelRecs * sizeof(LevelRec)); } /* Make sure searchStack really exists */ if ( searchStack != NULL ) { searchStackSize = GetHandleSize((Handle)searchStack); /* See if the search is a new search or a resumed search. */ if ( catPosition->initialize == 0 ) { /* New search. */ /* Get the real vRefNum and fill in catPosition->initialize. */ result = CheckVol(pb->ioNamePtr, pb->ioVRefNum, &realVRefNum, &catPosition->initialize); if ( result == noErr ) { /* clear searchStack */ catPosition->stackDepth = 0; /* use dirID parameter passed and... */ index = -1; /* start with the passed directory itself! */ } } else { /* We're resuming a search. */ /* Get the real vRefNum and make sure catPosition->initialize is valid. */ result = CheckVol(pb->ioNamePtr, pb->ioVRefNum, &realVRefNum, &tempLong); if ( result == noErr ) { /* Make sure the resumed search is to the same volume! */ if ( catPosition->initialize == tempLong ) { /* For resume, catPosition->stackDepth > 0 */ if ( catPosition->stackDepth > 0 ) { /* Position catPosition->stackDepth to access last saved level */ --(catPosition->stackDepth); /* Get the dirID and index for the next item */ dirID = (*searchStack)[catPosition->stackDepth].dirID; index = (*searchStack)[catPosition->stackDepth].index; /* Check the dir's mod date against the saved mode date on our "stack" */ modDate = GetDirModDate(realVRefNum, dirID); if ( modDate != (*searchStack)[catPosition->stackDepth].dirModDate ) { result = catChangedErr; } } else { /* Invalid catPosition record was passed */ result = paramErr; } } else { /* The volume is not the same */ result = catChangedErr; } } } if ( result == noErr ) { /* ioNamePtr and ioVRefNum only need to be set up once. */ cPB.hFileInfo.ioNamePtr = itemName; cPB.hFileInfo.ioVRefNum = realVRefNum; /* ** Here's the loop that: ** Finds the next item on the volume. ** If noErr, calls the code to check for matches and add matches ** to the match buffer. ** Sets up dirID and index for to find the next item on the volume. ** ** The looping ends when: ** (a) an unexpected error is returned by PBGetCatInfo. All that ** is expected is noErr and fnfErr (after the last item in a ** directory is found). ** (b) the caller specified a timeout and our Time Manager task ** has fired. ** (c) the number of matches requested by the caller has been found. ** (d) the last item on the volume was found. */ do { /* get the next item */ cPB.hFileInfo.ioFDirIndex = index; cPB.hFileInfo.ioDirID = dirID; result = PBGetCatInfoSync(&cPB); if ( index != -1 ) { if ( result == noErr ) { /* We found something */ CheckForMatches(&cPB, pb, upperName, includeFiles, includeDirs); ++index; if ( (cPB.dirInfo.ioFlAttrib & kioFlAttribDirMask) != 0 ) { /* It's a directory */ result = CheckStack(catPosition->stackDepth, searchStack, &searchStackSize); if ( result == noErr ) { /* Save the current state on the searchStack */ /* when we come back, this is where we'll start */ (*searchStack)[catPosition->stackDepth].dirID = dirID; (*searchStack)[catPosition->stackDepth].index = index; (*searchStack)[catPosition->stackDepth].dirModDate = GetDirModDate(realVRefNum, dirID); /* position catPosition->stackDepth for next saved level */ ++(catPosition->stackDepth); /* The next item to get is the 1st item in the child directory */ dirID = cPB.dirInfo.ioDrDirID; index = 1; } } /* else do nothing for files */ } else { /* End of directory found (or we had some error and that */ /* means we have to drop out of this directory). */ /* Restore last thing put on stack and */ /* see if we need to continue or quit. */ if ( catPosition->stackDepth > 0 ) { /* position catPosition->stackDepth to access last saved level */ --(catPosition->stackDepth); dirID = (*searchStack)[catPosition->stackDepth].dirID; index = (*searchStack)[catPosition->stackDepth].index; /* Check the dir's mod date against the saved mode date on our "stack" */ modDate = GetDirModDate(realVRefNum, dirID); if ( modDate != (*searchStack)[catPosition->stackDepth].dirModDate ) { result = catChangedErr; } else { /* Going back to ancestor directory. */ /* Clear error so we can continue. */ result = noErr; } } else { /* We hit the bottom of the stack, so we'll let the */ /* the eofErr drop us out of the loop. */ result = eofErr; } } } else { /* Special case for index == -1; that means that we're starting */ /* a new search and so the first item to check is the directory */ /* passed to us. */ if ( result == noErr ) { /* We found something */ CheckForMatches(&cPB, pb, upperName, includeFiles, includeDirs); /* Now, set the index to 1 and then we're ready to look inside */ /* the passed directory. */ index = 1; } } } while ( (!timerTask.stopSearch) && /* timer hasn't fired */ (result == noErr) && /* no unexpected errors */ (pb->ioReqMatchCount > pb->ioActMatchCount) ); /* we haven't found our limit */ /* Did we drop out of the loop because of timeout or */ /* ioReqMatchCount was found? */ if ( result == noErr ) { result = CheckStack(catPosition->stackDepth, searchStack, &searchStackSize); if ( result == noErr ) { /* Either there was a timeout or ioReqMatchCount was reached. */ /* Save the dirID and index for the next time we're called. */ (*searchStack)[catPosition->stackDepth].dirID = dirID; (*searchStack)[catPosition->stackDepth].index = index; (*searchStack)[catPosition->stackDepth].dirModDate = GetDirModDate(realVRefNum, dirID); /* position catPosition->stackDepth for next saved level */ ++(catPosition->stackDepth); } } } } else { /* searchStack Handle could not be allocated */ result = memFullErr; } } if ( pb->ioSearchTime != 0 ) { /* Stop Time Manager task here if it was installed */ RmvTime((QElemPtr)&(timerTask.theTask)); DisposeTimerUPP(timerTask.theTask.tmAddr); } return ( result ); }
void main(int argc, char **argv) #endif { int i; /* Index */ time_t time_and_date; /* Self-explanatory */ struct tm *loctime; double bmean; /* Benchmark mean */ double bstdev; /* Benchmark stdev */ double intindex; /* Integer index */ double fpindex; /* Floating-point index */ ulong bnumrun; /* # of runs */ #ifdef MAC MaxApplZone(); #endif #ifdef MACTIMEMGR /* Set up high res timer */ MacHSTdelay=600*1000*1000; /* Delay is 10 minutes */ memset((char *)&myTMTask,0,sizeof(TMTask)); /* Prime and remove the task, calculating overhead */ PrimeTime((QElemPtr)&myTMTask,-MacHSTdelay); RmvTime((QElemPtr)&myTMTask); MacHSTohead=MacHSTdelay+myTMTask.tmCount; #endif #ifdef WIN31TIMER /* Set up the size of the timer info structure */ win31tinfo.dwSize=(DWORD)sizeof(TIMERINFO); /* Load library */ if((hThlp=LoadLibrary("TOOLHELP.DLL"))<32) { printf("Error loading TOOLHELP\n"); exit(0); } if(!(lpfn=GetProcAddress(hThlp,"TimerCount"))) { printf("TOOLHELP error\n"); exit(0); } #endif /* ** Set global parameters to default. */ global_min_ticks=MINIMUM_TICKS; global_min_seconds=MINIMUM_SECONDS; global_allstats=0; global_custrun=0; write_to_file=0; intindex=(double)1.0; fpindex=(double)1.0; /* ** We presume all tests will be run unless told ** otherwise */ for(i=0;i<NUMTESTS;i++) tests_to_do[i]=1; /* ** Initialize test data structures to default ** values. */ set_request_secs(); /* Set all request_secs fields */ global_numsortstruct.adjust=0; global_numsortstruct.arraysize=NUMARRAYSIZE; global_strsortstruct.adjust=0; global_strsortstruct.arraysize=STRINGARRAYSIZE; global_bitopstruct.adjust=0; global_bitopstruct.bitfieldarraysize=BITFARRAYSIZE; global_emfloatstruct.adjust=0; global_emfloatstruct.arraysize=EMFARRAYSIZE; global_fourierstruct.adjust=0; global_assignstruct.adjust=0; global_ideastruct.adjust=0; global_ideastruct.arraysize=IDEAARRAYSIZE; global_huffstruct.adjust=0; global_huffstruct.arraysize=HUFFARRAYSIZE; global_nnetstruct.adjust=0; global_lustruct.adjust=0; /* ** For Macintosh -- read the command line. */ #ifdef MAC UCommandLine(); #endif /* ** Handle any command-line arguments. */ if(argc>1) for(i=1;i<argc;i++) if(parse_arg(argv[i])==-1) { display_help(argv[0]); exit(0); } /* ** Output header */ output_string("BBBBBB YYY Y TTTTTTT EEEEEEE\n"); output_string("BBB B YYY Y TTT EEE\n"); output_string("BBB B YYY Y TTT EEE\n"); output_string("BBBBBB YYY Y TTT EEEEEEE\n"); output_string("BBB B YYY TTT EEE\n"); output_string("BBB B YYY TTT EEE\n"); output_string("BBBBBB YYY TTT EEEEEEE\n\n"); output_string("BYTEmark (tm) Native Mode Benchmark ver. 2 (3/95)\n"); /* ** See if the user wants all stats. Output heading info ** if so. */ if(global_allstats) { output_string("========== ALL STATISTICS ==========\n"); time(&time_and_date); loctime=localtime(&time_and_date); sprintf(buffer,"**%s",asctime(loctime)); output_string(buffer); sprintf(buffer,"**%s\n",sysname); output_string(buffer); sprintf(buffer,"**%s\n",compilername); output_string(buffer); sprintf(buffer,"**%s\n",compilerversion); output_string(buffer); sprintf(buffer,"**Sizeof: int:%u short:%u long:%u\n", (unsigned int)sizeof(int), (unsigned int)sizeof(short), (unsigned int)sizeof(long)); output_string(buffer); output_string("====================================\n"); } /* ** Execute the tests. */ for(i=0;i<NUMTESTS;i++) { if(tests_to_do[i]) { sprintf(buffer,"%s:",ftestnames[i]); output_string(buffer); bench_with_confidence(i, &bmean, &bstdev, &bnumrun); sprintf(buffer, "Bmark(%s)", ftestnames[i] ); Report( buffer, TotalTime ); sprintf(buffer," Iterations/sec.: %lf Index: %lf\n", bmean,bmean/bindex[i]); output_string(buffer); /* ** Gather integer or FP indexes */ if((i==4)||(i==8)||(i==9)) /* FP index */ fpindex=fpindex*(bmean/bindex[i]); else /* Integer index */ intindex=intindex*(bmean/bindex[i]); if(global_allstats) { sprintf(buffer," Standard Deviation: %lf\n Number of runs: %lu\n", bstdev,bnumrun); output_string(buffer); show_stats(i); } } } printf("...done...\n"); /* ** Output the total indexes */ if(global_custrun==0) { output_string("===========OVERALL============\n"); sprintf(buffer,"INTEGER INDEX: %lf\nFLOATING-POINT INDEX: %lf\n",pow(intindex,(double).142857), pow(fpindex,(double).33333)); output_string(buffer); output_string(" (90 MHz Dell Pentium = 1.00)\n"); output_string("==============================\n"); } exit(0); }
void SDL_SYS_StopTimer(void) { RmvTime((QElemPtr)&gExtendedTimerRec.tmTask); }
void CTimer::stop() { RmvTime((QElemPtr)&tmtask); microseconds=TIMEOUT+tmtask.tmCount; }
void EmulOp(M68kRegisters *r, uint32 pc, int selector) { D(bug("EmulOp %04x at %08x\n", selector, pc)); switch (selector) { case OP_BREAK: // Breakpoint printf("*** Breakpoint\n"); Dump68kRegs(r); break; case OP_XPRAM1: { // Read/write from/to XPRam uint32 len = r->d[3]; uint8 *adr = Mac2HostAddr(r->a[3]); D(bug("XPRAMReadWrite d3: %08lx, a3: %p\n", len, adr)); int ofs = len & 0xffff; len >>= 16; if (len & 0x8000) { len &= 0x7fff; for (uint32 i=0; i<len; i++) XPRAM[((ofs + i) & 0xff) + 0x1300] = *adr++; } else { for (uint32 i=0; i<len; i++) *adr++ = XPRAM[((ofs + i) & 0xff) + 0x1300]; } break; } case OP_XPRAM2: // Read from XPRam r->d[1] = XPRAM[(r->d[1] & 0xff) + 0x1300]; break; case OP_XPRAM3: // Write to XPRam XPRAM[(r->d[1] & 0xff) + 0x1300] = r->d[2]; break; case OP_NVRAM1: { // Read from NVRAM int ofs = r->d[0]; r->d[0] = XPRAM[ofs & 0x1fff]; bool localtalk = !(XPRAM[0x13e0] || XPRAM[0x13e1]); // LocalTalk enabled? switch (ofs) { case 0x13e0: // Disable LocalTalk (use EtherTalk instead) if (localtalk) r->d[0] = 0x00; break; case 0x13e1: if (localtalk) r->d[0] = 0x01; break; case 0x13e2: if (localtalk) r->d[0] = 0x00; break; case 0x13e3: if (localtalk) r->d[0] = 0x0a; break; } break; } case OP_NVRAM2: // Write to NVRAM XPRAM[r->d[0] & 0x1fff] = r->d[1]; break; case OP_NVRAM3: // Read/write from/to NVRAM if (r->d[3]) { r->d[0] = XPRAM[(r->d[4] + 0x1300) & 0x1fff]; } else { XPRAM[(r->d[4] + 0x1300) & 0x1fff] = r->d[5]; r->d[0] = 0; } break; case OP_FIX_MEMTOP: // Fixes MemTop in BootGlobs during startup D(bug("Fix MemTop\n")); WriteMacInt32(BootGlobsAddr - 20, RAMBase + RAMSize); // MemTop r->a[6] = RAMBase + RAMSize; break; case OP_FIX_MEMSIZE: { // Fixes physical/logical RAM size during startup D(bug("Fix MemSize\n")); uint32 diff = ReadMacInt32(0x1ef8) - ReadMacInt32(0x1ef4); WriteMacInt32(0x1ef8, RAMSize); // Physical RAM size WriteMacInt32(0x1ef4, RAMSize - diff); // Logical RAM size break; } case OP_FIX_BOOTSTACK: // Fixes boot stack pointer in boot 3 resource D(bug("Fix BootStack\n")); r->a[1] = r->a[7] = RAMBase + RAMSize * 3 / 4; break; case OP_SONY_OPEN: // Floppy driver functions r->d[0] = SonyOpen(r->a[0], r->a[1]); break; case OP_SONY_PRIME: r->d[0] = SonyPrime(r->a[0], r->a[1]); break; case OP_SONY_CONTROL: r->d[0] = SonyControl(r->a[0], r->a[1]); break; case OP_SONY_STATUS: r->d[0] = SonyStatus(r->a[0], r->a[1]); break; case OP_DISK_OPEN: // Disk driver functions r->d[0] = DiskOpen(r->a[0], r->a[1]); break; case OP_DISK_PRIME: r->d[0] = DiskPrime(r->a[0], r->a[1]); break; case OP_DISK_CONTROL: r->d[0] = DiskControl(r->a[0], r->a[1]); break; case OP_DISK_STATUS: r->d[0] = DiskStatus(r->a[0], r->a[1]); break; case OP_CDROM_OPEN: // CD-ROM driver functions r->d[0] = CDROMOpen(r->a[0], r->a[1]); break; case OP_CDROM_PRIME: r->d[0] = CDROMPrime(r->a[0], r->a[1]); break; case OP_CDROM_CONTROL: r->d[0] = CDROMControl(r->a[0], r->a[1]); break; case OP_CDROM_STATUS: r->d[0] = CDROMStatus(r->a[0], r->a[1]); break; case OP_AUDIO_DISPATCH: // Audio component functions r->d[0] = gMacAudio->Dispatch(r->a[3], r->a[4]); break; case OP_SOUNDIN_OPEN: // Sound input driver functions r->d[0] = gMacAudio->InOpen(r->a[0], r->a[1]); break; case OP_SOUNDIN_PRIME: r->d[0] = gMacAudio->InPrime(r->a[0], r->a[1]); break; case OP_SOUNDIN_CONTROL: r->d[0] = gMacAudio->InControl(r->a[0], r->a[1]); break; case OP_SOUNDIN_STATUS: r->d[0] = gMacAudio->InStatus(r->a[0], r->a[1]); break; case OP_SOUNDIN_CLOSE: r->d[0] = gMacAudio->InClose(r->a[0], r->a[1]); break; case OP_ADBOP: // ADBOp() replacement gADBInput->Op(r->d[0], Mac2HostAddr(ReadMacInt32(r->a[0]))); break; case OP_INSTIME: // InsTime() replacement r->d[0] = InsTime(r->a[0], r->d[1]); break; case OP_RMVTIME: // RmvTime() replacement r->d[0] = RmvTime(r->a[0]); break; case OP_PRIMETIME: // PrimeTime() replacement r->d[0] = PrimeTime(r->a[0], r->d[0]); break; case OP_MICROSECONDS: // Microseconds() replacement Microseconds(r->a[0], r->d[0]); break; case OP_PUT_SCRAP: // PutScrap() patch PutScrap(ReadMacInt32(r->a[7] + 8), Mac2HostAddr(ReadMacInt32(r->a[7] + 4)), ReadMacInt32(r->a[7] + 12)); break; case OP_GET_SCRAP: // GetScrap() patch GetScrap((void **)Mac2HostAddr(ReadMacInt32(r->a[7] + 4)), ReadMacInt32(r->a[7] + 8), ReadMacInt32(r->a[7] + 12)); break; case OP_DEBUG_STR: // DebugStr() shows warning message if (PrefsFindBool("nogui")) { uint8 *pstr = Mac2HostAddr(ReadMacInt32(r->a[7] + 4)); char str[256]; int i; for (i=0; i<pstr[0]; i++) str[i] = pstr[i+1]; str[i] = 0; WarningAlert(str); } break; case OP_INSTALL_DRIVERS: { // Patch to install our own drivers during startup // Install drivers InstallDrivers(); // Patch MakeExecutable() MakeExecutableTvec = FindLibSymbol("\023PrivateInterfaceLib", "\016MakeExecutable"); D(bug("MakeExecutable TVECT at %08x\n", MakeExecutableTvec)); WriteMacInt32(MakeExecutableTvec, NativeFunction(NATIVE_MAKE_EXECUTABLE)); #if defined(__powerpc__) /* Native PowerPC */ WriteMacInt32(MakeExecutableTvec + 4, (uint32)TOC); #endif // Patch DebugStr() static const uint8 proc_template[] = { M68K_EMUL_OP_DEBUG_STR >> 8, M68K_EMUL_OP_DEBUG_STR & 0xFF, 0x4e, 0x74, // rtd #4 0x00, 0x04 }; BUILD_SHEEPSHAVER_PROCEDURE(proc); WriteMacInt32(0x1dfc, proc); break; } case OP_NAME_REGISTRY: // Patch Name Registry and initialize CallUniversalProc r->d[0] = (uint32)-1; PatchNameRegistry(); InitCallUniversalProc(); break; case OP_RESET: // Early in MacOS reset D(bug("*** RESET ***\n")); TimerReset(); MacOSUtilReset(); gMacAudio->Reset(); // Enable DR emulator (disabled for now) if (PrefsFindBool("jit68k") && 0) { D(bug("DR activated\n")); WriteMacInt32(KernelDataAddr + 0x17a0, 3); // Prepare for DR emulator activation WriteMacInt32(KernelDataAddr + 0x17c0, DR_CACHE_BASE); WriteMacInt32(KernelDataAddr + 0x17c4, DR_CACHE_SIZE); WriteMacInt32(KernelDataAddr + 0x1b04, DR_CACHE_BASE); WriteMacInt32(KernelDataAddr + 0x1b00, DR_EMULATOR_BASE); memcpy((void *)DR_EMULATOR_BASE, (void *)(ROMBase + 0x370000), DR_EMULATOR_SIZE); MakeExecutable(0, DR_EMULATOR_BASE, DR_EMULATOR_SIZE); } break; case OP_IRQ: // Level 1 interrupt WriteMacInt16(ReadMacInt32(KernelDataAddr + 0x67c), 0); // Clear interrupt r->d[0] = 0; if (HasMacStarted()) { if (InterruptFlags & INTFLAG_VIA) { ClearInterruptFlag(INTFLAG_VIA); #if !PRECISE_TIMING TimerInterrupt(); #endif ExecuteNative(NATIVE_VIDEO_VBL); static int tick_counter = 0; if (++tick_counter >= 60) { tick_counter = 0; SonyInterrupt(); DiskInterrupt(); CDROMInterrupt(); } r->d[0] = 1; // Flag: 68k interrupt routine executes VBLTasks etc. } if (InterruptFlags & INTFLAG_SERIAL) { ClearInterruptFlag(INTFLAG_SERIAL); SerialInterrupt(); } if (InterruptFlags & INTFLAG_ETHER) { ClearInterruptFlag(INTFLAG_ETHER); ExecuteNative(NATIVE_ETHER_IRQ); } if (InterruptFlags & INTFLAG_TIMER) { ClearInterruptFlag(INTFLAG_TIMER); TimerInterrupt(); } if (InterruptFlags & INTFLAG_AUDIO) { ClearInterruptFlag(INTFLAG_AUDIO); gMacAudio->Interrupt(); } if (InterruptFlags & INTFLAG_ADB) { ClearInterruptFlag(INTFLAG_ADB); gADBInput->Interrupt(); } } else r->d[0] = 1; break; case OP_SCSI_DISPATCH: { // SCSIDispatch() replacement uint32 ret = ReadMacInt32(r->a[7]); uint16 sel = ReadMacInt16(r->a[7] + 4); r->a[7] += 6; // D(bug("SCSIDispatch(%d)\n", sel)); int stack; switch (sel) { case 0: // SCSIReset WriteMacInt16(r->a[7], SCSIReset()); stack = 0; break; case 1: // SCSIGet WriteMacInt16(r->a[7], SCSIGet()); stack = 0; break; case 2: // SCSISelect case 11: // SCSISelAtn WriteMacInt16(r->a[7] + 2, SCSISelect(ReadMacInt8(r->a[7] + 1))); stack = 2; break; case 3: // SCSICmd WriteMacInt16(r->a[7] + 6, SCSICmd(ReadMacInt16(r->a[7]), Mac2HostAddr(ReadMacInt32(r->a[7] + 2)))); stack = 6; break; case 4: // SCSIComplete WriteMacInt16(r->a[7] + 12, SCSIComplete(ReadMacInt32(r->a[7]), ReadMacInt32(r->a[7] + 4), ReadMacInt32(r->a[7] + 8))); stack = 12; break; case 5: // SCSIRead case 8: // SCSIRBlind WriteMacInt16(r->a[7] + 4, SCSIRead(ReadMacInt32(r->a[7]))); stack = 4; break; case 6: // SCSIWrite case 9: // SCSIWBlind WriteMacInt16(r->a[7] + 4, SCSIWrite(ReadMacInt32(r->a[7]))); stack = 4; break; case 10: // SCSIStat WriteMacInt16(r->a[7], SCSIStat()); stack = 0; break; case 12: // SCSIMsgIn WriteMacInt16(r->a[7] + 4, 0); stack = 4; break; case 13: // SCSIMsgOut WriteMacInt16(r->a[7] + 2, 0); stack = 2; break; case 14: // SCSIMgrBusy WriteMacInt16(r->a[7], SCSIMgrBusy()); stack = 0; break; default: printf("FATAL: SCSIDispatch: illegal selector\n"); stack = 0; //!! SysError(12) } r->a[0] = ret; r->a[7] += stack; break; } case OP_SCSI_ATOMIC: // SCSIAtomic() replacement D(bug("SCSIAtomic\n")); r->d[0] = (uint32)-7887; break; case OP_CHECK_SYSV: { // Check we are not using MacOS < 8.1 with a NewWorld ROM r->a[1] = r->d[1]; r->a[0] = ReadMacInt32(r->d[1]); uint32 sysv = ReadMacInt16(r->a[0]); D(bug("Detected MacOS version %d.%d.%d\n", (sysv >> 8) & 0xf, (sysv >> 4) & 0xf, sysv & 0xf)); if (ROMType == ROMTYPE_NEWWORLD && sysv < 0x0801) r->d[1] = 0; break; } case OP_NTRB_17_PATCH: r->a[2] = ReadMacInt32(r->a[7]); r->a[7] += 4; if (ReadMacInt16(r->a[2] + 6) == 17) PatchNativeResourceManager(); break; case OP_NTRB_17_PATCH2: r->a[7] += 8; PatchNativeResourceManager(); break; case OP_NTRB_17_PATCH3: r->a[2] = ReadMacInt32(r->a[7]); r->a[7] += 4; D(bug("%d %d\n", ReadMacInt16(r->a[2]), ReadMacInt16(r->a[2] + 6))); if (ReadMacInt16(r->a[2]) == 11 && ReadMacInt16(r->a[2] + 6) == 17) PatchNativeResourceManager(); break; case OP_NTRB_17_PATCH4: r->d[0] = ReadMacInt16(r->a[7]); r->a[7] += 2; D(bug("%d %d\n", ReadMacInt16(r->a[2]), ReadMacInt16(r->a[2] + 6))); if (ReadMacInt16(r->a[2]) == 11 && ReadMacInt16(r->a[2] + 6) == 17) PatchNativeResourceManager(); break; case OP_CHECKLOAD: { // vCheckLoad() patch uint32 type = ReadMacInt32(r->a[7]); r->a[7] += 4; int16 id = ReadMacInt16(r->a[2]); if (r->a[0] == 0) break; uint32 adr = ReadMacInt32(r->a[0]); if (adr == 0) break; uint16 *p = (uint16 *)Mac2HostAddr(adr); uint32 size = ReadMacInt32(adr - 8) & 0xffffff; CheckLoad(type, id, p, size); break; } case OP_EXTFS_COMM: // External file system routines WriteMacInt16(r->a[7] + 14, ExtFSComm(ReadMacInt16(r->a[7] + 12), ReadMacInt32(r->a[7] + 8), ReadMacInt32(r->a[7] + 4))); break; case OP_EXTFS_HFS: WriteMacInt16(r->a[7] + 20, ExtFSHFS(ReadMacInt32(r->a[7] + 16), ReadMacInt16(r->a[7] + 14), ReadMacInt32(r->a[7] + 10), ReadMacInt32(r->a[7] + 6), ReadMacInt16(r->a[7] + 4))); break; case OP_IDLE_TIME: // Sleep if no events pending if (ReadMacInt32(0x14c) == 0) idle_wait(); r->a[0] = ReadMacInt32(0x2b6); break; case OP_IDLE_TIME_2: // Sleep if no events pending if (ReadMacInt32(0x14c) == 0) idle_wait(); r->d[0] = (uint32)-2; break; default: printf("FATAL: EMUL_OP called with bogus selector %08x\n", selector); QuitEmulator(); break; } }