IF scr -> KLUDGE KLUDGE KLUDGE (but aren't all screen-change detection routines?!??)
osw:=scr.width
osh:=scr.height
osb:=scr.bitmap
osbd:=osb.depth
osli:=scr.layerinfo
osf:=scr.font
osvp:=scr.viewport
osbh:=scr.barheight
osrp:=scr.rastport
osrpf:=osrp.font
UnlockPubScreen(0,scr);oldscr:=scr;scr:=0
IF (fport=0) THEN fport:=CreateMsgPort()
IF (fport)
fnotify.name:='env:sys/screenmode.prefs'
fnotify.flags:=NRF_SEND_MESSAGE
fnotify.port:=fport
snotify.name:='env:sys/font.prefs'
snotify.flags:=NRF_SEND_MESSAGE
snotify.port:=fport
pnotify.name:=source
pnotify.flags:=NRF_SEND_MESSAGE
pnotify.port:=fport
IF ((StartNotify(fnotify)) AND (StartNotify(snotify)) AND (StartNotify(pnotify)))
IF (tryagain=0) THEN sig:=Wait(SIGBREAKF_CTRL_C OR (Shl(1,fport.sigbit)))
IF (sig AND SIGBREAKF_CTRL_C)
notifyloop:=FALSE
ENDIF
IF (sig AND Shl(1,fport.sigbit))
IF ((fmsg:=GetMsg(fport)) OR (tryagain<>0))
tryagain:=0
IF (fmsg) THEN ReplyMsg(fmsg)
tries:=0
Delay(60) -> Wait a bit, then we begin to bang on intuition...
REPEAT
Forbid()
scr:=LockPubScreen({work})
IF (scr)
sw:=scr.width
sh:=scr.height
sb:=scr.bitmap
sbd:=sb.depth
sli:=scr.layerinfo
sf:=scr.font
svp:=scr.viewport
sbh:=scr.barheight
srp:=scr.rastport
srpf:=osrp.font
UnlockPubScreen(0,scr)
Permit()
ELSE
Permit()
Delay(30)
ENDIF
tries:=tries+1
UNTIL (((scr>0) AND (oldscr<>scr)) OR (tries>=16) OR (sw<>osw) OR (sh<>osh) OR (sb<>osb) OR (sli<>osli) OR (sf<>osf) OR (svp<>osvp) OR (sbh<>osbh) OR (srp<>osrp) OR (srpf<>osrpf) OR (sbd<>osbd))
IF (tries>=14) THEN tryagain:=TRUE
scr:=0
IF (wbverlauf)
wbverlauftask:=FindTask('WBVerlauf')
IF (wbverlauftask)
Signal(wbverlauftask,$FFFF0FFF)
ENDIF
ENDIF
ENDIF
ENDIF
EndNotify(fnotify)
EndNotify(snotify)
EndNotify(pnotify)
ENDIF
IF CtrlC()
notifyloop:=FALSE
ENDIF
ELSE
notifyloop:=FALSE
ENDIF
ENDIF
ENDIF
IF CtrlC() THEN (notifyloop:=FALSE)
ENDWHILE
EXCEPT DO
IF ((notify) AND (quiet=FALSE)) THEN WriteF('***BREAK\n')
IF (fport)
IF (fnotify) THEN EndNotify(fnotify)
IF (snotify) THEN EndNotify(snotify)
IF (pnotify) THEN EndNotify(pnotify)
DeleteMsgPort(fport)
ENDIF
END fnotify,snotify,pnotify
IF scr THEN UnlockPubScreen(0,scr)
IF (iff)
CloseIFF(iff)
IF (iff.stream) THEN Close(iff.stream)
FreeIFF(iff)
ENDIF
IF iffparsebase THEN CloseLibrary(iffparsebase)
IF ((exception) AND (quiet=FALSE)) THEN WriteF('ShoveColors Failed.\n')
ENDPROC
PROC getrgb32(cm,fc,nc,tab)
DEF ret
MOVE.L cm,A0
MOVE.L fc,D0
MOVE.L nc,D1
MOVE.L tab,A1
MOVE.L gfxbase,A6
JSR -$384(A6)
MOVE.L D0,ret
ENDPROC ret
PROC setrgb32(vp,pen,red,green,blue)
MOVE.L vp,A0
MOVE.L pen,D0
MOVE.L red,D1
SWAP D1
LSL.L #8,D1
MOVE.L green,D2
SWAP D2
LSL.L #8,D2
MOVE.L blue,D3
SWAP D3
LSL.L #8,D3
MOVE.L gfxbase,A6
JSR -$354(A6)
ENDPROC
PROC obtainpen(cm,n,r,g,b,f)
DEF ret
MOVE.L gfxbase,A6
MOVE.L n,D0
MOVE.L r,D1
SWAP D1
LSL.L #8,D1
MOVE.L g,D2
SWAP D2
LSL.L #8,D2
MOVE.L b,D3
SWAP D3
LSL.L #8,D3
MOVE.L cm,A0
MOVE.L f,D4
JSR -$3BA(A6)
MOVE.L D0,ret
ENDPROC ret
PROC releasepen(cm,n)
MOVE.L cm,A0
MOVE.L n,D0
MOVE.L gfxbase,A6
JSR -$3B4(A6)
ENDPROC
PROC lockpen(pn,mode)
DEF cmtable,red,green,blue,dummy
cmtable:=[0,0,0,0,0,0]:LONG
getrgb32(cm,pn,1,cmtable)
red:=Char(cmtable)
green:=Char(cmtable+4)
blue:=Char(cmtable+8)
dummy:=obtainpen(cm,pn,red,green,blue,0)
IF dummy<0
lock[pn]:=TRUE /* Pen was unavailable, so DON'T release/change! */
ELSE
IF (mode=0) /* Was able to lock, but it needs to be *free* */