-- card: 3178 from stack: in -- bmap block id: 0 -- flags: 0000 -- background id: 2564 -- name: Source -- part 1 (field) -- low flags: 00 -- high flags: 0007 -- rect: left=0 top=0 right=309 bottom=512 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 0 -- font id: 4 -- text size: 9 -- style flags: 0 -- line height: 12 -- part name: -- part contents for card part 1 ----- text ----- ; Safe shutdown and restart XCMDs for HyperCard. ; Earle R. Horton Sunday, October 8, 1989 ; ; It is unsafe to shutdown or restart the machine from within an XCMD ; because HyperCard may have left a stack in an inconsistent state. ; (HyperCard updates the disk image of a stack at idle time.) ; These XCMDs work by patching _ExitToShell. The idea is to call ; the XCMD from within a script, then to quit HyperCard right ; afterwards. HyperCard flushes everything to disk, then ; calls the trap. We wait for the trap call, then shutdown or ; restart the machine. ; ; As far as HyperCard and its stacks are concerned, everything is ; hunky-dory now. This is not a perfect solution to the problem, ; since if MultiFinder is active, other processes get the rug pulled ; out from under them. ; ; This is the source to ShutdownRestart.a. ; include 'ShutDownEqu.a' include 'Traps.a' EXITTRAPNUM equ $01F4 ; ; This procedure patches _ExitToShell to shut down the Mac instead. ; ShutDownXCMD proc export import doShutdown,doShutdownEnd movem.l a3-a4,-(sp) link a6,#0 lea doShutdownEnd-doShutdown,a4 move.l a4,d0 beq done _NewPtr move.l a0,a3 move.l a0,a1 move.l a4,d0 lea doShutdown,a0 _BlockMove move.w #EXITTRAPNUM,d0 move.l a3,a0 _SetTrapAddress done unlk a6 movem.l (sp)+,a3-a4 move.l (sp)+,a0 adda.l #4,sp jmp (a0) ; ; Patch to _ExitToShell. Shut down the machine. ; doShutdown proc export export doShutdownEnd _SDPowerOff rts doShutdownEnd endp ; ; This is the same as the shutdown XCMD code, except it restarts the machine. RestartXCMD proc export import doRestart,doRestartEnd movem.l a3-a4,-(sp) link a6,#0 lea doRestartEnd-doRestart,a4 move.l a4,d0 beq done _NewPtr move.l a0,a3 move.l a0,a1 move.l a4,d0 lea doRestart,a0 _BlockMove move.w #EXITTRAPNUM,d0 move.l a3,a0 _SetTrapAddress done unlk a6 movem.l (sp)+,a3-a4 move.l (sp)+,a0 adda.l #4,sp jmp (a0) doRestart proc export export doRestartEnd _SDRestart rts doRestartEnd endp end