home *** CD-ROM | disk | FTP | other *** search
- #include <MacTypes.h>
- #include <MemoryMgr.h>
- #include <OSUtil.h>
- #include <QuickDraw.h>
- #include <HyperXCmd.h>
-
- extern Byte CPUflag : 0x12F;
-
- /*
- * SetCache entry point. This is a XFCN that allows you to switch the cache on and off. The current/new
- * cache setting is returned.
- * Warning: The on and off strings are hardwired. Lacking an owned resources method of
- * carrying STR resources around with this XFCN, this is inevitable (unless I
- * go to the hassle of passing strings or resource IDs through as arguments).
- */
-
- pascal void
- main(paramPtr)
- register XCmdBlockPtr paramPtr;
- {
- Str255 str;
- short toggle;
- Byte cacheOn;
-
- /* SysEnvirons is overkill for this! */
- if (CPUflag != 2) {
- /* Calling SetCache for a 68000?! . Might be a 68030 I suppose, but who knows what the CACR
- * is like on that processor. Take no chances, and return OFF.
- */
- cacheOn = 0;
- } else {
- /* Find out what the current cache state is... */
- asm {
- clr.l d0
- dc.w 0x4E7A /* movec CACR, d0 */
- dc.w 0x2
- move.b d0,cacheOn
- }
-
- /* Are there any parameters? This is a bit of a kluge, but if SetCache is called without any parameters, it returns the
- * current cache bit status in "result". Saves having separate XFCN and XCMD resources.
- */
- if (paramPtr->paramCount != 0) {
- /* First (and only) param is on/off. Convert it to a pascal string */
- ZeroToPas(paramPtr,*(paramPtr->params[0]), str);
-
- toggle = (StringEqual(paramPtr, (Str31 *)str, (Str31 *)"\pOff") == TRUE) ? 0 : 1;
-
- /* And clamp it. */
- if (toggle != 0) toggle = 1;
-
- if (cacheOn != toggle) { /* Need to toggle the values. */
- cacheOn ^= 1;
-
- /* Toggle the cache control bit. */
- asm {
- clr.l d0
- dc.w 0x4E7A
- dc.w 0x2 /* A movec CACR, d0 */
- eori #1,d0
- dc.w 0x4E7B /* movec d0,CACR */
- dc.w 0x2
- }
- }
- }
- }
-
- /* And return the current cache value. */
- paramPtr->returnValue = (cacheOn == 0) ? PasToZero(paramPtr, (StringPtr)"\pOff") :
- PasToZero(paramPtr, (StringPtr)"\pOn");
- }
-