**************************************************************************
*                                SYSRESET.S                              *
*                                                                        *
*  Written using Hisoft Devpac-2                                         *
*                                                                        *
*  Example VDT file, which adds the option to reset the system           *
*  This program is rather verbose in places...!                          *
*                                                                        *
*  Version 1.00 11th September 1989                                      *
*  Added new VTOS calls - Version 1.01 27th May 1990                     *
*                                                                        *
**************************************************************************

               opt o+,w-,x+               *  Optimisation on
               output .VDT                *  Override default .PRG
        
               section text

* The CallVTOS macro is quite handy.  Feel free to use it in your own
* programs.

CallVTOS:       macro
                clr.l -(sp)             *  Dummy argument
                move.l a0,-(sp)         *  Store register
                move.l VtosBase,a0      *  Base of table
                move.l \1*4(a0),4(sp)   *  Store jump
                move.l (sp)+,a0         *  Retrieve register
                rts                     *  Indirect jump to routine
                endm

*  This is where the program code starts.  First we must define the 
*  VTOS header.

                dc.w $abcd              *  This is a VTOS module
                dc.l Setup              *  Initialisation
                dc.l ResetMenu          *  Menu option
                dc.l 0                  *  No chain

*  Note the above value may be altered.  To put more than one module in
*  a single file use the 'chain' value to define where the next header
*  is.

*  Initialisation - Must not alter registers a0-a5 or d0-d7

Setup:          movem.l a0-a5/d0-d7,-(sp)
                move.l a0,VtosBase      *  VTOS base address
                move.l a1,VtosBss       *  VTOS BSS address
                move.l a1,a6            *  Set base pointer

*  Put your initialisation here!
*  A6 is not altered by any VTOS routines, and by convention points to the
*  VTOS BSS address.  Alter this at your peril!

               movem.l (sp)+,a0-a5/d0-d7
               rts
        
Reset:         move.b $26(a6),d0       *  Fetch mouse button status
               and.b #$fc,d0           *  Wait for mouse to be stopped
               bne Reset               *  Wait for it...!

*  The next bit is a pretty standard system-reset routine
*  The purpose of waiting for both mouse buttons to be lifted is because
*  the IKBD controller gets confused if you hold down a mouse button during
*  a system reset.

               clr.l -(sp)             *  SSP=USP
               move.w #$20,-(sp)       *  Supervisor/User mode toggle
               trap #1
               move.l $4f2,a0          *  System reset PC address
               move.l (a0),-(sp)       *  Fetch reset value
               rts                     *  Jump into it!

*  Although not used by this program, VTOS calls are defined as follows.
*  See VTOS technical manual for further details on each routine

PrintCharacter: CallVTOS 0
DisplayChar:    CallVTOS 1
RxCharacter:    CallVTOS 2
TxCharacter:    CallVTOS 3
ConfigRS232:    CallVTOS 4
GotoBackground: CallVTOS 5
GotoOnline:     CallVTOS 6
EraseCursor:    CallVTOS 7
DisplayCursor:  CallVTOS 8
MoveCursor:     CallVTOS 9
StepToNext:     CallVTOS 10
StoreCharacter: CallVTOS 11
ControlAction:  CallVTOS 12
GetColour:      CallVTOS 13
MouseOn:        CallVTOS 14
MouseOff:       CallVTOS 15
LoadRelocate:   CallVTOS 16
GetKey:         CallVTOS 17
GetString:      CallVTOS 18
AllocateBlock:  CallVTOS 19
RemoveBlock:    CallVTOS 20
FindBlock:      CallVTOS 21
FindNext:       CallVTOS 22
RfshScreen:     CallVTOS 23
ClearBottom:    CallVTOS 24
FileSelector:   CallVTOS 25
DialComputer:   CallVTOS 26
UseColour:      CallVTOS 27
UseTopLine:     CallVTOS 28
RaiseDTR:       CallVTOS 29
DropDTR:        CallVTOS 30
DoResponse:     CallVTOS 31
ConvertField:   CallVTOS 32
FetchTime:      CallVTOS 33
RapidDisplay:   CallVTOS 34
ReadCookie:     CallVTOS 35
WriteCookie:    CallVTOS 36

               section data

*  The menus are defined here

ResetMenu:     dc.b 1,'Reset System '  *  Enabled, goes to menu
               dc.l ResetSubMenu       *  Address of menu

ResetSubMenu:  dc.w 1                  *  Just one option
               dc.l ResetSubTitle      *  Title string
               dc.l ResetSubOpt1       *  Option 1
        
ResetSubTitle: dc.b 'Reset system',0   *  Title string

               even

*  Note the line below is the same format as 'ResetMenu'
*  Remember each option string must be of an odd length.

ResetSubOpt1:  dc.b 3,'Yes Please '    *  Enabled, executes
               dc.l Reset              *  Routine address

               section bss
        
VtosBase:      ds.l 1                  *  VTOS jump-table address
VtosBss:       ds.l 1                  *  VTOS system variables
