*************************************************************************
*                                                                       *
*               R       E       S       E       T                       *
*                                                                       *
*       A  program  by  Martin  Schlodder   begun   on  ??              *
*                                     Version 1.0   on  30-Dec-1991     *
*                                     Version 2.0   on   8-Aug-1992     *
*                                     Version 2.01  on   8-Sep-1992     *
*                                     Version 2.02  on  21-Sep-1992     *
*                                                                       *
*       Usage: Reset [?|simple|cold|kick]                               *
*                                                                       *
*       This program resets the System either as if you were pressing   *
*       the three keys (option: "simple","s" or none), or additionally  *
*       removes the exec.library and with that everything that tries    *
*       to be resident (option: "cold" or "c"), or it removes the Kick- *
*       start when run on an AMIGA 1000 (option: "kick" or "k").        *
*       "?" will bring up some information.                             *
*       Any option may be abbreviated.                                  *
*                                                                       *
*       Version-Report:                                                 *
*                                                                       *
*         V1.0:  First version. (Doesn't run under OS 2.0)              *
*         V2.0:  Works now under OS 2.0 (ColdReboot).                   *
*         V2.01: Tests for FastMem before removing KickStart.           *
*         V2.02: Now Errors may be displayed in German.                 *
*                                                                       *
*************************************************************************

CALL            MACRO
                IFEQ NARG-2
                move.l  \2,a6
                ENDC
                IFLE NARG-2
                jsr     _LVO\1(a6)
                MEXIT
                ENDC
                FAIL    CALL MACRO ERROR
                ENDM

SysBase         EQU     4
VER_ALL         EQU     0
VER_20          EQU     36
;ENGLISH         EQU     0                       ;english by removing comment sign

                INCLUDE "lvo/exec.i"
                INCLUDE "lvo/dos.i"
                INCLUDE "exec/execbase.i"

_main           tst.l   a0                      ;is there any command line?
                beq     SimpleReset             ;from WB -> simply reset
                move.b  (a0)+,d0                ;first char
                cmp.b   #' ',d0                 ;is space ?
                beq     _main                   ;if so, look for next
                cmp.b   #'?',d0
                beq     ShowInfo                ;about
                cmp.b   #10,d0
                beq     SimpleReset             ;eol -> simply reset
                cmp.b   #13,d0
                beq     SimpleReset             ;$13 as eol
                and.b   #%11011111,d0           ;UCase
                cmp.b   #'S',d0
                beq     SimpleReset             ;simply reset ('simple')
                cmp.b   #'C',d0
                beq     ColdReset               ;kill system ('cold')
                cmp.b   #'K',d0
                beq     KillKick                ;remove kickstart ('kick')

WrongOption     lea     WrongText,a0            ;errortext
                bra     WriteText
LoMem           lea     LoMemText,a0            ;can't remove kickstart
                bra     WriteText
ShowInfo        lea     PrgInfo,a0              ;only information
WriteText       moveq   #0,d7
                moveq   #0,d3
                move.w  (a0)+,d3                ;length
                move.l  a0,d4                   ;string
                lea     DosName,a1
                move.l  #VER_ALL,d0
                CALL    OpenLibrary,SysBase     ;open doslib
                move.l  d0,d6
                bne     GoOn1
                moveq   #20,d7
                bra     EndWrite
GoOn1           exg     d6,a6
                CALL    Output                  ;get cli-handle
                move.l  d0,d1
                bne     GoOn2
                moveq   #20,d7
                bra     CloseDos
GoOn2           move.l  d4,d2
                CALL    Write                   ;write text
                cmp.l   d0,d3
                beq     CloseDos
                moveq   #20,d7
CloseDos        move.l  a6,a1
                move.l  d6,a6
                CALL    CloseLibrary            ;close library
EndWrite        move.l  d7,d0
                rts

KillKick        lea     KillKick,a0             ;kill kickstart
                cmp.l   #$200000,a0
                blt     LoMem
                CALL    SuperState,SysBase
                reset
                clr.l   $fc003c                 ;checksum of ROM
                move.w  #$4000,$dff09a          ;disable interrupt
                move.b  #0,$bfe401              ;timer-a lo-byte
                move.b  #0,$bfe501              ;timer-a hi-byte
                move.b  #%01010001,$bfee01      ;controllregister a
                move.b  d0,$bfec01              ;serial portregister
Wait            bra.s   Wait

ColdReset       CALL    Disable,SysBase         ;kill multitasking
                ;clr.w  LowMemChkSum(a6)
                ;clr.l  ChkBase(a6)
                clr.w   ChkSum(a6)

SimpleReset     move.l  $4,a6
                cmp.w   #VER_20,LIB_VERSION(a6)
                bmi     K13Reset
                CALL    ColdReboot              ;OS2.0-function
K13Reset        CALL    Disable                 ;kill multitasking
                lea     $fc0002,a0              ;and reset
                move.l  a0,$20
                reset
                jsr     (a0)

SysStack        dc.l    0

DosName         dc.b    'dos.library',0


                IFD     ENGLISH

MyVer           dc.b    0,"$VER: Reset 2.02 (21.9.1992)",0
                CNOP    0,2
PrgInfo         dc.w    Pe-Ps
Ps              dc.b    10,13,"Reset 2.02 on 21-Sep-1992 by Martin Schlodder",10,13,10,13
                dc.b    "Usage: Reset [?|simple|cold|kick]",10,13,10,13
                dc.b    "It resets the system. No option or 'simple' will simply reset the system;",10,13
                dc.b    "'cold' will remove everything from memory; 'kick' removes the Kickstart",10,13
                dc.b    "from A1000's WOM.",10,13,10,13
Pe              CNOP    0,2
WrongText       dc.w    We-Ws
Ws              dc.b    10,13,"Unknown Argument! Type 'Reset ?' for more information.",10,13,10,13
We              CNOP    0,2
LoMemText       dc.w    Le-Ls
Ls              dc.b    10,13,"This program must be in FastMem to remove Kickstart from WOM.",10,13,10,13
Le              CNOP    0,2

                ELSE

MyVer           dc.b    0,"$VER: Reset 2.02 (21.9.1992)",0
                CNOP    0,2
PrgInfo         dc.w    Pe1-Ps1
Ps1             dc.b    10,13,"Reset 2.02 am 21.9.1992 von Martin Schlodder",10,13,10,13
                dc.b    "Aufruf: Reset [?|simple|cold|kick]",10,13,10,13
                dc.b    "Das System wird zurückgesetzt. Keine Option oder 'simple' erzeugt einen",10,13
                dc.b    "einfachen Hardreset, 'cold' entfernt alles Resetfeste aus dem Speicher",10,13
                dc.b    "während 'kick' das Kickstart aus dem WOM des A1000 entfernt.",10,13,10,13
Pe1             CNOP    0,2
WrongText       dc.w    We1-Ws1
Ws1             dc.b    10,13,"Unbekannte Option! Geben Sie 'Reset ?' ein für mehr Information.",10,13,10,13
We1             CNOP    0,2
LoMemText       dc.w    Le1-Ls1
Ls1             dc.b    10,13,"Dieses Programm muß im FastMem laufen, um das Kickstart entfernen zu können!.",10,13,10,13
Le1

                ENDC


                END

