Unit REWSleep; { This is a modified version of my REWSleep library unit. It's real simple to use. You just create the procedures you want called, then pass them into the init function. When you're done, call the finish function to remove the procedures. The procedures you pass in are basic, with no arguments; my code handles the details of calling the right one. I'm not sure how this will behave under 680x0; you may have to do things like reset A5 to get your globals. Also, this is designed to be used in a program that's running when the sleep procedure is called (most likely an FBA). If you want to install and quit, you have to load the procedure into the system heap, which means you probably need to load it from a code resource. Oh, and due to the way we use it, the unit's designed to call your procedures on equivalent doze states. For instance, if you install a wake procedure, it gets called at both sleep wake and doze wake. You'll see how to change this in the code if you want--it's pretty straightforward. July 1999, by Bob Williams } Interface Uses Power, Types, GestaltEqu; Type gtSleepProc = procedure; Function REWCanSleep: Boolean; {pass in nil for those you don't want to use; note that these are called on equivalent doze states, too} Procedure REWInitSleep (sleepRequestProc, sleepDemandProc, sleepWakeUpProc, sleepRevokeProc: gtSleepProc); Procedure REWFinishSleep; Implementation Var gMySleepQRec: SleepQRec; gProcList: Array[1..4] Of gtSleepProc; Procedure REWSleepNow; Begin REWGoToSleep; End; {REWSleepNow} Function REWCanSleep: Boolean; Var myErr: OSErr; response: LongInt; Begin myErr := Gestalt(gestaltPowerMgrAttr, response); REWCanSleep := BAnd(response, gestaltPMgrCPUIdle) <> 0; End; {REWCanSleep} Procedure REWFinishSleep; Begin SleepQRemove(@gMySleepQRec); End; {REWFinishSleep} Function MySleepProc(message: LongInt; qRecPtr: SleepQRecPtr): LongInt; Begin {$UNUSED qRecPtr} Case message Of sleepRequest, dozeRequest: begin If gProcList[1] <> Nil Then gProcList[1]; MySleepProc := 0; end; {sleepRequest} sleepDemand, dozeDemand: begin If gProcList[2] <> Nil Then gProcList[2]; MySleepProc := 0; end; {sleepRequest} sleepWakeUp, dozeWakeUp: begin If gProcList[3] <> Nil Then gProcList[3]; MySleepProc := 0; end; {sleepRequest} sleepRevoke: begin If gProcList[4] <> Nil Then gProcList[4]; MySleepProc := 0; end; {sleepRequest} otherwise ; {Case} End; End; {MySleepProc} Procedure REWInitSleep (sleepRequestProc, sleepDemandProc, sleepWakeUpProc, sleepRevokeProc: gtSleepProc); Begin gProcList[1] := sleepRequestProc; gProcList[2] := sleepDemandProc; gProcList[3] := sleepWakeUpProc; gProcList[4] := sleepRevokeProc; gMySleepQRec.sleepQLink := nil; gMySleepQRec.sleepQType := sleepQType; gMySleepQRec.sleepQProc := NewSleepQProc(@MySleepProc); gMySleepQRec.sleepQFlags := 0; SleepQInstall(@gMySleepQRec); End; {REWInitSleep} End. {REWSleep}