| RISC OS Select Boot sequence - run from command line
| [BootScripts 1.16 (16 Oct 2002)]

| Run from the desktop ? Stop right now for our own protection
If "<Wimp$State>" = "desktop" Then Error BootRun may only be run outside the desktop

| Disable break and escape
FX 247 2_10101010
FX 229 1

| Set up the library path
/Boot:Library.ScanLibs

| Load MemFix for Kinetic cards (only runs on 4.03)
SetEval Boot$NeedMemFix 0
RMEnsure UtilityModule 4.04 SetEval Boot$NeedMemFix 1
RMEnsure UtilityModule 4.03 SetEval Boot$NeedMemFix 0
If <Boot$OSVersion> = 400 AND <Boot$NeedMemFix> = 1 Then X RMLoad Boot:Utils.MemFix
Unset Boot$NeedMemFix

| Softload now
/Boot:Utils.FreePool
IfThere Boot:Softload.!Softload Then /Boot:Softload.!Softload

| Modules we definately require
RMEnsure VProtect     3.80 RMLoad Boot:Utils.VProtect
RMEnsure AppPatcher   0.03 RMLoad Boot:Utils.PatchApp
RMEnsure BootLog      0.03 RMLoad Boot:Utils.BootLog
RMEnsure ErrorLog     1.13 RMLoad Boot:Utils.ErrorLog
RMEnsure LibaryHelp   0.02 RMLoad Boot:Utils.LibraryHlp

| If we're using pre-Select (no softload) we need to load the patches
If Boot$OSVersion = 400 Then /Boot:Utils.RO4Patches.!Run

| The choices paths and related things
WimpSlot -next 256K
/Boot:Utils.FreePool
Obey -c Boot:Utils.SetChoices

| If we didn't shutdown cleanly, do a check
If "<Boot$ShutdownState>" = "failpowerlost" OR "<Boot$ShutdownState>" = "unclean" Then /Boot:Utils.FileCoreCk

| If there's a territory manager, load that
IfThere <Boot$Dir>.^.!Territory Then /<Boot$Dir>.^.!Territory

| The aliases for pre-desktop initialisation
Set Alias$BootLoad Echo %%*0|mLoad %%*0|mEcho |<11>|<23>|<8>|<5>|<6>|<0>|<0>|<0>|<0>|<0>|<0>|<11>|m
Set Alias$BootRun  Echo %%*0|m/%%*0|mEcho |<11>|<23>|<8>|<5>|<6>|<0>|<0>|<0>|<0>|<0>|<0>|<11>|m
| Log level for errors reported through BootError is lower than for messages
Set Alias$BootError SetEval Boot$ErrorCount Boot$ErrorCount + 1|mSysLog Boot 80 %%*0|m
RMEnsure SysLog 0.00 Set Alias$BootError Echo %%*0
Set Alias$BootObey Obey -c %%*0
Set Alias$@LoadType_FEB BootObey %%*0
Set Alias$@LoadType_FF8 /%%*0
Set Alias$@LoadType_FF9 IconSprites %%*0
Set Alias$@LoadType_FFA RMLoad %%*0
Set Alias$@LoadType_FFB BASIC -quit %%*0
Set Alias$@LoadType_FFC /%%*0

| Zero the error counter, so that we don't issue warnings unnecessarily
SetEval Boot$ErrorCount 0

| Pre-desktop initialisation
/Boot:Utils.HOn
/Boot:Utils.AddToRMA 256

| Set up for booting resources
Set Alias$BootRes IfThere %%0.!Boot Then Run %%0.!Boot
Set BootResources$Dir <Boot$Dir>.Resources

| Set up the path to hook directories - nothing before RO 4 is supported
Set BootResources$Path <BootResources$Dir>.
PrepPath BootResources$Path <Boot$Dir>.RO400Hook.Res.
If Boot$OSVersion >= 420 Then PrepPath BootResources$Path <Boot$Dir>.RO420Hook.Res.
If Boot$OSVersion >= 430 Then PrepPath BootResources$Path <Boot$Dir>.RO430Hook.Res.
| <additional OS versions go here>

| Setup System, Scrap, and Fonts
/<BootResources$Dir>.!System.!Run
/<BootResources$Dir>.!Scrap.!Run
/<BootResources$Dir>.!Fonts.!Run

| Unplug toolbox - we can't load other toolbox modules otherwise
BootRun Boot:Utils.UnplugTbox

| AddApp any applications we require from the resources
If Boot$OSVersion = 400 Then IfThere Boot:RO400Hook.Res.!Configure Then AddApp Boot:RO400Hook.Res.!Configure
If Boot$OSVersion >= 420 Then IfThere Boot:RO420Hook.Apps Then AddApp Boot:RO420Hook.Apps.!*
If Boot$OSVersion >= 430 Then IfThere Boot:RO430Hook.Apps Then AddApp Boot:RO430Hook.Apps.!*
| <additional OS versions go here>


| Setup up aliases required by the PreDesktop boot system
Set Alias$Alias Set Alias$%%0 %%*1
Alias UnAlias Unset Alias$%%0
Alias Path Set %%0$Path %%1
Alias PathMacro SetMacro %%0$Path %%1

Alias Logon SafeLogon %%*0
Alias Desktop_SetPalette ||%%*0


| Now the progressive boot - hardware first
IfThere <Boot$Hardware$ToBeLoaded>.^.PreDesktop Then Run <Boot$Hardware$ToBeLoaded>.^.PreDesktop
IfThere <Boot$Hardware$ToBeLoaded> Then Repeat BootLoad <Boot$Hardware$ToBeLoaded> -files
IfThere <Boot$Hardware$ToBeLoaded> Then Repeat BootRun  <Boot$Hardware$ToBeLoaded> -directories
|                          - default boot for everyone
IfThere <Boot$Default$ToBeLoaded>.^.PreDesktop Then Run <Boot$Default$ToBeLoaded>.^.PreDesktop
IfThere <Boot$Default$ToBeLoaded> Then Repeat BootLoad <Boot$Default$ToBeLoaded> -files
IfThere <Boot$Default$ToBeLoaded> Then Repeat BootRun  <Boot$Default$ToBeLoaded> -directories
|                          - and finally user
IfThere <Boot$ToBeLoaded>.^.PreDesktop Then Run <Boot$ToBeLoaded>.^.PreDesktop
IfThere <Boot$ToBeLoaded> Then Repeat BootLoad <Boot$ToBeLoaded> -files
IfThere <Boot$ToBeLoaded> Then Repeat BootRun  <Boot$ToBeLoaded> -directories

| Now reset the variables to their original state
Unset Alias$@LoadType_FEB
Unset Alias$@LoadType_FF8
Set   Alias$@LoadType_FF9 SLoad %%0
Set   Alias$@LoadType_FFA RMLoad %%*0
Set   Alias$@LoadType_FFB Basic -load |"%%0|" %%*1
Unset Alias$@LoadType_FFC
Unset Alias$BootLoad
Unset Alias$BootRun
Unset Alias$BootObey

| Set the BootError command to do nothing on 4.02
RMEnsure SysLog 0.00 Set Alias$BootError ||

| Reduce RMA back to its smallest level
/Boot:Utils.ShrinkRMA

| Re-enabled break and escape
FX 247 1
FX 229 0

| Reconfigure the mouse if no driver has been supplied
/Boot:Utils.CheckMouse

| Boot to the desktop
/Boot:Utils.Desktop