.key NOGUI/S,GUI/S,DEFSCR/S,PUBSCR/S,REQSCR/S,SM/K,DEPTH/K,LORES/S,HIRES/S,NODITHER/S,GRAY/S,FRAMERATE/K,FASTBLIT/S,CHIP/K,SLOWFAST/K,Z2RAM/K,Z3RAM/K,NOSOUND/S,DF0/K,DF1/K,DF2/K,DF3/K,ROMFILE/K,MOUNT/K
.bra {
.ket }

; $VER: UAEWB 0.4 (01.12.2004) by Richard Drummond

Failat 21

; ==============================================
; NOGUI forces the interpretation of CMDLINE arg
; ==============================================
IF NOT {NOGUI}
  Skip DO_GUI
ENDIF

; ===============
; Analyse CMDLINE
; ===============

FAILAT 20

; ============================================
; Ensure IXEMUL will use the ENV:UAESM we want
; ============================================
Delete >NIL: ENV:UAESM
Avail >NIL: flush

; ==================
; SCREEN TYPE OPTION
; ==================
Set HOPT " -H1"
If {DEFSCR}
   Set HOPT " -H0"
Endif
If {PUBSCR}
   Set HOPT " -H1"
Endif
If {REQSCR}
   Set HOPT " -H2"
Endif
Set tmp1 `eval {DEPTH}+0`
Set tmp2 `eval {SM}+0`
If $tmp1 GT 0
   If $tmp2 GT 0
        SetEnv UAESM $tmp2:$tmp1
        Set HOPT " -H2"
   ELSE
      Echo "Error: Missing SM=<num> argument"
      Quit 10
   Endif
ELSE
  If $tmp2 GT 0
      Echo "Error: Missing DEPTH=<num> argument"
      Quit 10
  Endif
Endif

; ===========
; WINDOW SIZE
; ===========
Set OOPT " -O640:512:XYd"
If {LORES}
   Set OOPT " -O320:256:XYl"
Endif
If {HIRES}
   Set OOPT " -O640:512:XYd"
Endif

; ========
; RAM SIZE
; ========
Set RAMOPT ""
If {CHIP}
   Set tmp1 `eval {CHIP}/256`
   If $tmp1 GT 0
      Set RAMOPT "$RAMOPT -c$tmp1"
   ELSE
      Echo "Error: CHIP=256 or 512 or 1024 or 2048"
      Quit 10
   Endif
Endif
If {Z2RAM}
   Set tmp1 `eval {Z2RAM}/1024`
   If $tmp1 GT 0
      Set RAMOPT "$RAMOPT -F$tmp1"
   ELSE
      Echo "Error: Z2RAM=1024 or 2048 or ... or 8192"
      Quit 10
   Endif
Endif
If {Z3RAM}
   Set tmp1 `eval {Z3RAM}/1024`
   If $tmp1 GT 0
      Set RAMOPT "$RAMOPT -Z$tmp1"
   ELSE
      Echo "Error: Z3RAM=1024 or 2048 or ..."
      Quit 10
   Endif
Endif
If {SLOWFAST}
   Set tmp1 `eval {SLOWFAST}/256`
   If $tmp1 GT 0
      Set RAMOPT "$RAMOPT -s$tmp1"
   ELSE
      Echo "Error: SLOWFAST=512 or 1024"
      Quit 10
   Endif
Endif

; =====
; DISKS
; =====
Set DISKS ""
If {DF0}
  Set DISKS "$DISKS -0{DF0}"
Endif
If {DF1}
  Set DISKS "$DISKS -1{DF1}"
Endif
If {DF2}
  Set DISKS "$DISKS -2{DF2}"
Endif
If {DF3}
  Set DISKS "$DISKS -3{DF3}"
Endif
If {ROMFILE}
  Set DISKS "$DISKS -r{ROMFILE}"
Endif
If {KEYFILE}
  Set DISKS "$DISKS -K{KEYFILE}"
Endif

; =====
; SOUND
; =====
Set SOUND " -S2"
If {NOSOUND}
  Set SOUND " -S0"
Endif

; ====
; MISC
; ====
Set MISC ""
If {NODITHER}
  Set MISC "$MISC -x"
Endif
If {GRAY}
  Set MISC "$MISC -T"
Endif
If {FASTBLIT}
  Set MISC "$MISC -n3i"
Endif
Set tmp1 `eval {FRAMERATE}+0`
If $tmp1 GT 0
  Set MISC "$MISC -f$tmp1"
Endif

; ===============
; VOLUME MOUNTING
; ===============
Set MOUNT ""
If {MOUNT}
  Set MOUNT "-m{MOUNT}"
Endif

; ============
; Launch GUI ?
; ============
If {GUI}
   Set tmp1 "UAEGUI.rexx"
   If EXISTS $tmp1
      Run >nil: rx $tmp1
   ELSE
   Set tmp1 "src/UAEGUI.rexx"
   If EXISTS $tmp1
      Run >nil: rx $tmp1
   ELSE
   Set tmp1 "amiga/UAEGUI.rexx"
   If EXISTS $tmp1
      Run >nil: rx $tmp1
   ELSE
      Echo "Warning: Can not find UAEGUI.rexx."
   Endif
   Endif
   Endif
Endif

Stack >NIL: 32000

echo "Running *"uae$HOPT$OOPT$RAMOPT$SOUND$MISC$DISKS$MOUNT*""

If EXISTS uae.aos
   UAE.aos $HOPT$OOPT$RAMOPT$SOUND$MISC$DISKS$MOUNT
ELSE
   UAE $HOPT$OOPT$RAMOPT$SOUND$MISC$DISKS$MOUNT
Endif

Quit $RC

; ====================
; Run the GUI Launcher
; ====================
Lab DO_GUI
; in some case on my setup, I have a deadlock if this is not loaded
Version >NIL: LIBS:compressors/xpkGZIP.library

; check for MUIREXX
Which >NIL: MuiRexx
If WARN
   Set Title "UAEWB: Error!"
   Set Body  "Can't find MUIRexx! (UAE needs at least MUIRexx 3.0)"
   If EXISTS c:RequestChoice
      c:RequestChoice "$Title" "$Body" "Ok"
   Else
      Echo >"CON://320/50/$Title/WAIT/CLOSE" "$Body"
   Endif
   Quit 10
Endif

;check for ixemul
;Version >NIL: ixemul.library 47
;If WARN
;   Set Title "UAEWB: Error!"
;   Set Body  "Can't find ixemul.library v47!"
;   If EXISTS c:RequestChoice
;      c:RequestChoice "$Title" "$Body" "Ok"
;   Else
;      Echo >"CON://320/50/$Title/WAIT/CLOSE" "$Body"
;   Endif
;   Quit 10
;Endif

; 32Kb stack should be enough
Stack >NIL: 32000
rx >NIL: UAEWB.rexx
