; *****************************************************************
; *              *                                                *
; * TaskersFlush *                                                *
; *              * (c)1997-1999 Sallin Nicolas, aka Henes/Taskers *
; * Big version  *                                                *
; *              *                                                *
; *****************************************************************
;
; ***********************
; *                     *
; * Default TimeOut=10s *
; *                     *
; ***********************

; v1.0 (27.06.97) I've lost his source !

; v1.1 (05.11.97) No more timer.device -> Delay()
;                 Delay controlable from the shell
;                 No more 'Avail FLUSH' -> AllocMem()

; v2.0 (03.02.98) Optimized to easily create TaskersFlushTiny !

; v2.1 (16.04.98) Delay recontrolable from the shell
;                 Readded MsgPort part to avoid two TaskersFlush simultaneous.
;                 Better display of the messages in the shell

; v2.2 (26.04.98) Modified according to PoolMem on how to flush (block size increased)
;                 Control from the shell changed a bit to gain some bytes...

; v2.3 (15.02.99) Used NewCommandSet (NWBStartup, etc...) but it increase the executable size !
;                 Removed all commande line interface.
;                 Next, I will add commodity support !

; v2.3b(24.02.99) Some modification inspired by the ReFlux code (Hi James !):
;                 - The #SIGBREAKF_CTRL_C value is no more specified
;                   (already done in AmigaLibs.res, I think)
;                 - AllocMem() repeated 10 times
;                   (because "Avail FLUSH" does it as show by MemPatch)
;                 Changed the requester title from "Request" to "TaskersFlush"
;                 Readded commande line interface ! I'm a fool :)
;                 Swapped delay/flush parts -> now, flush then delay (best way to do) -> it will crash immediatly !
;                 Swapped the removal of MsgPort with exit message -> free all the resources THEN exits
;                 Removed all call to NCS -> nothing was working ;(
;                 Flush part replaced by 100% asm (from tiny version)
;                 Modified info in the shell
;                 Some internal changes and optimizations...

; v2.3b2(31.03.99) Only one AllocMem() by flush:
;                  less overhead and less chance to have a low memory situation

; v2.3b3(04.04.99) Enclosed the AllocMem in a Forbid/Permit paire
;                  I hope no badly written prog will crash under low memory situation, now.
;                  But I think I have read somewere (not in PoolMem) that you mustn't use that
;                  trick, so...
;                  Well, it's a beta...

; v2.4 (13.04.99) Pumped the version for the Aminet release
;                 The source code is unchanged as it seems to work great. No more IBrowse crash.

; Todo: - Check if delay not too big
;       - Add a note saying that it could crash under very low memory situation. I may handle this one of this days.

; Open: - Can I use a Forbid/Permit pair(s) ?
;       - What must be the priority of the MsgPort ?
;       - The library used by MPLS_Patch and VirusZ(xfdmaster) was expunged at boottime !
;       - The dignet.library from Napalm was expunged and crashed !!! Napalm is really a big shit !
;         (and it doesn't render in the VRAM -> slooooooow)
                                                                                                              
; NB: Remember to always add BlitzLibs:AmigaLibs.res in the Compiler/CompilerOptions panel !

Goto SkipVer
Dc.b "$VER: TaskersFlush 2.4 (13.04.99) Big version"
Even
SkipVer

NoCli
WBStartup

; ****************
; *              *
; * Already here ***************************************************************************************************************
; *              *
; ****************

name$="TaskersFlush"
Forbid_
*ExistMP.MsgPort=FindPort_(name$)
Permit_

If *ExistMP
  If FromCLI
    PutStr_ "TaskersFlush is already running."+Chr$(10)
  Else
    Request name$,"TaskersFlush is already running.","Sorry" ; If yes, we advice that we exit.
  EndIf
  End
Else
  *ExistMP.MsgPort=CreateMsgPort_()                          ;
  *ExistMP\mp_Node\ln_Name=&name$                            ; Else, we install our resources.
  *ExistMP\mp_Node\ln_Pri=1                                  ;
  sucport.l=AddPort_(*ExistMP)                               ;
EndIf

; **************
; *            *
; * ReadArgs() *****************************************************************************************************************
; *            *
; **************

PutStr_ "TaskersFlush v2.4 (c)1997-99 SALLIN Nicolas aka Henes/Taskers"+Chr$(10)

If Par$(1)="?"
  PutStr_"DELAY/N"+Chr$(10)
  End
Else
  delay.w=Val(Par$(1))
EndIf

If delay<1 Then delay=10

PutStr_"Delay is "+Str$(delay)+" second(s)."+Chr$(10)+"Ctrl-C to abort."+Chr$(10)

delay*50 ; hehehe !

; ********
; *      *
; * Main ***********************************************************************************************************************
; *      *
; ********

Repeat
  Forbid_
  MOVE.l 4,a6                                       ;  \
  MOVE.l  #$07ffffff0,d0 ; som gigas of ram, please ;   - The Flush
  MOVEQ #0,d1                                       ;  /
  JSR -198(a6)  ; AllocMem()                        ; /
  ;err=AllocMem_($07ffffff0,0)
  Permit_
  Delay_(delay)
Until (SetSignal_(0,#SIGBREAKF_CTRL_C) & #SIGBREAKF_CTRL_C)

; **********
; *        *
; * Cassos ***************************************************************************************************************
; *        *
; **********

RemPort_(*ExistMP)
DeleteMsgPort_(*ExistMP)

If FromCLI
  PutStr_ "TaskersFlush was here."+Chr$(10)
Else
  Request "TaskersFlush","TaskersFlush was here.","Quit"
EndIf

;Forbid_ ; Why ???
End
