##############################################################################
# WARNING: THIS FILE IS NOT USED BY DEFAULT. ADJUST dosemu.users OR USE -F.
#
# This file is global.conf. By default a compiled-in copy is used. If you
# make custom changes to the settings in this file, then you need to use
# the -F switch or change dosemu.users; the custom file is then parsed
# after the built-in copy.
#
# Linux dosemu  configuration  for parser versions >= 3 (dosemu-0.97.0.1)
#
# ./doc/README-tech.txt (chapter 2.) contains a description of the syntax
# and the usage. However, you normally won't edit this file !!
#
# NOTES:
#
# 1. The file dosemu.conf (and optionally ~/.dosemurc) contains variable
#    settings, that are included by global.conf for doing the
#    most reasonable configuration.
#    The file dosemu.conf (and optionally ~/.dosemurc) is what gets
#    updated by the menu driven 'setup-dosemu' tool.
#
# 2. We strongly recommend you to edit ONLY dosemu.conf.
#    If you change global.conf, you are at your own and could break
#    'setup-dosemu'.  You really need to know a lot of DOSEMU
#    internals before you fiddle with editing global.conf.
#    However, some very special cases can only be handled in global.conf.
#
# 3. The file global.conf (this one) is either
#      - the one compiled into dosemu.bin.
#      - specified by the config_script option in dosemu.users ("builtin"
#        by default)
#      - or given via the -F option (from root login, else only on
#        non-suid-root DOSEMU)
#
# 4. The only compiled-in path is /etc/dosemu.users (or if not found
#    /etc/dosemu/dosemu.users), however, this can be overridden by
#    --Fusers, if not running suid-root. All other paths are configurable
#    and the dosemu binaries can reside everywhere in the system.
#
# This file (global.conf) may also serve as an example file for
#      .dosrc            ( old style user configuration file )
#      option -I         ( configuration via commandline, see man/dos.1 )
#
# Access rights for suid-root running DOSEMU sessions are defined in
#
#      /etc/dosemu.users or /etc/dosemu/dosemu.users
#
##############################################################################

ifdef u_forceold
  undef parser_version_3
  define version_3_style_used
endif

ifndef parser_version_3
  # normally won't come here, because older DOSEMUs don't use this file
  # ... but if using -F option ...
  include "/etc/dosemu.conf"
else
  # we are on version 3 parser

  ## we set some vital variable

  if (!strlen($DOSEMU_LIB_DIR))
    abort "DOSEMU_LIB_DIR not set";
  endif
  if (!strlen($DOSEMU_IMAGE_DIR))
    $DOSEMU_IMAGE_DIR = $DOSEMU_LIB_DIR;
  endif
  # make sure we have absolute paths
  if (!test_d($DOSEMU_IMAGE_DIR))
    abort "DOSEMU_IMAGE_DIR does not exist ", $DOSEMU_IMAGE_DIR;
  endif
  $DOSEMU_IMAGE_DIR = realpath($DOSEMU_IMAGE_DIR);
  if (test_d($DOSEMU_LIB_DIR))
    $DOSEMU_LIB_DIR = realpath($DOSEMU_LIB_DIR);
  endif

  $CONFIG_VERSION = ( (1 << 24) | (1 << 16) | (4 << 8) | 0)
  #                    ^           ^           ^         ^
  if ( $DOSEMU_VERSION_CODE < $CONFIG_VERSION )
    abort "
*** sorry, your ", $DOSEMU_LIB_DIR, "/global.conf doesn't match this dosemu version
"
  endif

  $LIST_DELIM = " ,	"	#delimiters for lists <tab>, blank, comma

  # for non-suid-root we can switch off restricted checking.
  if (strlen($DOSEMU_LAX_CHECKING))
    undef restricted
    undef guest
  endif

  if (strlen($_mapping)) $xxx = $_mapping else $xxx = "auto" endif
  mappingdriver $xxx;

  if (strlen($_debug))
    debug $_debug ;
  else
    debug { off }
  endif
  if (strlen($_trace_ports)) trace ports { $$_trace_ports } endif
  if (strlen($_trace_mmio)) trace_mmio { $$_trace_mmio } endif

  cpuspeed $_cpuspeed

  timer 0
  mathco $_mathco
  ignore_fpe $_ignore_fpe
  $xxx = "cpu ", $_cpu;
  $$xxx
  cpuemu $$_cpuemu
  $xxx = "cpu_vm ", $_cpu_vm;
  $$xxx
  $xxx = "cpu_vm_dpmi ", $_cpu_vm_dpmi;
  $$xxx
  if ($_ems)
    ems {
          ems_size $_ems
          ems_frame $_ems_frame
          ems_uma_pages $_ems_uma_pages
          ems_conv_pages $_ems_conv_pages
        }
  else
    ems off
  endif
  umb_a0 $_umb_a0
  umb_b0 $_umb_b0
  umb_b8 $_umb_b8
  umb_f0 $_umb_f0
  hma $_hma
  dos_up $_dos_up
  dpmi $_dpmi
  dpmi_base $_dpmi_base
  pm_dos_api 1
  ignore_djgpp_null_derefs $_ignore_djgpp_null_derefs
  dosmem $_dosmem
  ext_mem $_ext_mem
  xms $_xms

  if ($_emusys ne "") emusys $_emusys endif

  ## terminal stuff, we check a lot to insure proper operation

  terminal { color $_term_color escchar $_escchar size $_fixed_term_size }
  xterm_title $_xterm_title
  video { vga }
  if ($_external_char_set ne "")
    charset { external $$_external_char_set }
  endif
  if ($_internal_char_set ne "")
    charset { internal $$_internal_char_set }
  endif

  ## X param settings
    $xxx = ""
    if ($_X_sharecmap) $xxx = $xxx, " sharecmap" endif
    if ($_X_aspect_43) $xxx = $xxx, " aspect_43" endif
    if ($_X_lin_filt) $xxx = $xxx, " lin_filt"  endif
    if ($_X_bilin_filt) $xxx = $xxx, " bilin_filt" endif
    $xxx = $xxx, " mode13fact ", $_X_mode13fact
    $xxx = $xxx, " gamma ", (int($_X_gamma * 100))
    $xxx = $xxx, " font '", $_X_font, "'"
    if (strlen($_X_winsize))
      $yyy = (strstr($_X_winsize,","))
      $yyy = " winsize (", strdel($_X_winsize,$yyy,999), ") , (",
              strsplit($_X_winsize,$yyy+1,999), ")"
      $xxx = $xxx, $yyy
    endif

    if (strlen($_X_vesamode))
      foreach $yyy (" 	", $_X_vesamode)
        $zzz = (strchr($yyy,","))
        $xxx = $xxx, " vesamode (", strdel($yyy,$zzz,999), "),(",
                      strsplit($yyy,$zzz+1,999), ") "
      done
    endif
    $xxx = $xxx, ' mgrab_key "', $_X_mgrab_key, '"'
    X {
      title $_X_title title_show_appname $_X_title_show_appname
      icon_name $_X_icon_name
      blinkrate $_X_blinkrate
      fixed_aspect $_X_fixed_aspect vgaemu_memsize $_X_vgaemu_memsize
      lfb $_X_lfb  pm_interface $_X_pm_interface mitshm $_X_mitshm
      background_pause $_X_background_pause fullscreen $_X_fullscreen
      noclose $_X_noclose
      noresize $_X_noresize
      $$xxx
    }

  ## SDL settings
  SDL { sdl_hwrend $_SDL_hwrend sdl_fonts $_SDL_fonts sdl_wcontrols $_SDL_wcontrols sdl_clip_native $_SDL_clip_native }

  # video settings
  vga_fonts $$_force_vga_fonts
  if ($DOSEMU_STDIN_IS_CONSOLE eq "1")
    warn "dosemu running on console"
    $xxx = $_video
    if ($_console) $xxx = $xxx, " console"
       if ($_console == auto) $xxx = $xxx, " auto" endif
    endif
    if ($_graphics) $xxx = $xxx, " graphics"
       if ($_graphics == auto) $xxx = $xxx, " auto" endif
    endif
    $xxx = $xxx, " vbios_seg ", $_vbios_seg, " vbios_size ",
	        $_vbios_size, " memsize ", $_vmemsize
    if (strlen($_chipset)) $yyy = $_chipset else $yyy = "plainvga" endif
    $xxx = $xxx, " chipset ", $yyy
    if ($_vbios_post) $xxx = $xxx, " vbios_post " endif
    if ($_dualmon) $xxx = $xxx, " dualmon" endif
    if (strlen($_vbios_file)) $xxx = $xxx, " vgaemubios_file ", $_vbios_file endif
    video { $$xxx }
  else
    warn "dosemu not running on console"
    $xxx = $_video
    if (strlen($_vbios_file)) $xxx = $xxx, " vgaemubios_file ", $_vbios_file endif
    if ($_dualmon) $xxx = $xxx, " dualmon " endif
    if (strlen($xxx)) video { $$xxx } endif
  endif

  ## sound settings
  sound $_sound
  sound_emu { sb_base $_sb_base
	        sb_irq $_sb_irq
		sb_dma $_sb_dma
		sb_hdma $_sb_hdma
		mpu_base $_mpu_base
		mpu_base_mt32 $_mpu_base_mt32
		midi_synth $_midi_synth
		mpu_irq $_mpu_irq
		mpu_irq_mt32 $_mpu_irq_mt32
		sound_driver $_sound_driver
		midi_driver $_midi_driver
		fluid_sfont $_fluid_sfont
		fluid_volume $_fluid_volume
		munt_roms $_munt_roms
		opl2lpt_dev $_opl2lpt_dev
		opl2lpt_type $_opl2lpt_type
		snd_plugin_params $_snd_plugin_params
		pcm_hpf $_pcm_hpf
		midi_file $_midi_file
		wav_file $_wav_file
  }

  ## joystick settings
  joystick_emu { joy_device $_joy_device joy_dos_min $_joy_dos_min
	joy_dos_max $_joy_dos_max joy_granularity $_joy_granularity
	joy_latency $_joy_latency }

  ## hacks
  cli_timeout $_cli_timeout
  timemode $_timemode
  timer_tweaks $_timer_tweaks

  file_lock_limit $$_file_lock_limit
  lfn_support $_lfn_support
  force_int_revect $_force_int_revect
  set_int_hooks $_set_int_hooks
  trace_irets $_trace_irets
  force_fs_redirect $_force_fs_redirect

  ## serial
  $xxx = "'", $_ttylocks, "'"
  ttylocks { directory $$xxx namestub LCK.. }
  if (1) # no idea why but we need this...
    foreach $xxx (" ", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16")
      $zzz = "$_com", $xxx
      $zzz = $$zzz
      if (strlen($zzz))
        serial { com $xxx $$zzz }
      endif
    done
  endif

  ## mouse settings
  if ($_mouse_internal)
    $xxx = ""
    if ($_mouse_baud)
      $xxx = "baudrate ", $_mouse_baud
    endif
    $xxx = $xxx, " device '", $_mouse_dev, "'"
    mouse { $$_mouse $$_mouse_flags $$xxx internaldriver mouse_ungrab_tweak $_mouse_ungrab_tweak }
  else
    $xxx = "'", $_mouse_dev, "'"
    mouse { $$_mouse device $$xxx }
  endif

  hogthreshold $_hogthreshold

  ## keyboard setting
  if ($DOSEMU_STDIN_IS_CONSOLE ne "1") $_rawkeyboard = (off) endif
  if ( strstr($_layout, "load") <0 )
      # we use the builtin keytables
      if (strlen($_layout)) $yyy = $_layout else $yyy = "us" endif
      keyboard { layout $yyy  rawkeyboard $_rawkeyboard }
  else
      # we have to load a keytable
      $yyy = ""
      if (1) # no idea why (see com as well) but we need this...
        foreach $zzz ($LIST_DELIM, $_layout)
          if ($zzz ne "load")
            $yyy = $zzz
          endif
        done
      endif
      if (!strlen($yyy))
        abort "no keytable name in $_layout"
      endif
      if (!test_f($DOSEMU_LIB_DIR, "/keymap/", $yyy))
        abort "keytable ",$yyy, " not found in ", $DOSEMU_LIB_DIR, "/keymap/*"
	      endif
      $_layout = 'include "keymap/', $yyy, '"' ;
      $$_layout
      keyboard { rawkeyboard $_rawkeyboard }
  endif

  bootdrive $_bootdrive
  swap_bootdrive $_swap_bootdrive

  if (strlen($_floppy_a))
    $fpath = strsplit($_floppy_a, 0, strstr($_floppy_a, ":"))
    if (strlen($fpath))
      $ftype = strsplit($_floppy_a, strstr($_floppy_a, ":")+1, 999)
    else
      $fpath = $_floppy_a
      $ftype = ""
    endif

    $zzz = $fpath
    if (strlen($zzz))
      if ((strchr($zzz, "/") != 0) && (strchr($zzz, "~") != 0))
        $izzz = $DOSEMU_IMAGE_DIR, "/", $zzz
        if (test_r($izzz))
          $zzz = $izzz
        endif
      endif
      if (!test_r($zzz))
        warn "**** Warning: floppy ", $zzz, " not accessible, disabled";
      else
        if (!test_d($zzz))
          floppy { device $$zzz $$ftype }
        else
          floppy { directory $$zzz $$ftype }
        endif
      endif
    endif
  endif
  if (strlen($_floppy_b))
    $fpath = strsplit($_floppy_b, 0, strstr($_floppy_b, ":"))
    if (strlen($fpath))
      $ftype = strsplit($_floppy_b, strstr($_floppy_b, ":")+1, 999)
    else
      $fpath = $_floppy_b
      $ftype = ""
    endif

    $zzz = $fpath
    if (strlen($zzz))
      if ((strchr($zzz, "/") != 0) && (strchr($zzz, "~") != 0))
        $izzz = $DOSEMU_IMAGE_DIR, "/", $zzz
        if (test_r($izzz))
          $zzz = $izzz
        endif
      endif
      if (!test_r($zzz))
        warn "**** Warning: floppy ", $zzz, " not accessible, disabled";
      else
        if (!test_d($zzz))
          floppy { device $$zzz $$ftype }
        else
          floppy { directory $$zzz $$ftype }
        endif
      endif
    endif
  endif
  fastfloppy 1

  ## setting up hdimages
  if (strlen($_hdimage))
    foreach $xxxx ($LIST_DELIM, $_hdimage)
      $xxx_pref = ""
      $xxx_suff = ""
      if (strchr($xxxx, "*") != -1)
        $xxx_pref = strdel($xxxx, strchr($xxxx, "*"), 999);
        $xxx_suff = strsplit($xxxx, strchr($xxxx, "*") + 1, 999);
        if (strchr($xxx_pref, "/") == 0)
          $xxxx = ls($xxx_pref)
        else
          $xxxx = ls($DOSEMU_IMAGE_DIR, "/", $xxx_pref)
        endif
        if ($DOSEMU_SHELL_RETURN)
          abort "**** directory ", $xxx_pref, " not accessible";
        endif
      endif
      if (strchr($xxxx, "+") == 0)
        default_drives strtol(strdel($xxxx, 0, 1))
      else if (strchr($xxxx, "-") == 0)
        skip_drives strtol(strdel($xxxx, 0, 1))
      else if (strlen($xxxx))
        foreach $xxx ($LIST_DELIM, $xxxx)
          $xxx = $xxx_pref, $xxx, $xxx_suff
          if (!strncmp($xxx, "/dev/", 4))
            $yyy = strdel($xxx, strstr($xxx, ":"), 999);
            $zzz = strsplit($xxx, strstr($xxx, ":"), 999);
            if (strtol(strdel($xxx,0,8)) > 0)
              disk { partition $yyy $$zzz };
            else
              disk { wholedisk $yyy $$zzz };
            endif
          else
            $yyy = strdel($xxx, strstr($xxx, ":"), 999);
            $zzz = strsplit($xxx, strstr($xxx, ":"), 999);
            if (strchr($yyy, "/") != 0)
              $yyyy = $DOSEMU_IMAGE_DIR, "/", $yyy
              $yyy = $yyyy
            endif
            if (test_d($yyy))
              disk { directory $yyy $$zzz };
            else
              if (test_f($yyy))
                disk { image $yyy $$zzz };
              else
                abort "hdimage ", $yyy, " not found"
              endif
            endif
          endif
        done
      endif endif endif
    done
  endif

  ## setting up CDROM devices
  if (strlen($_cdrom))
    foreach $xxx ($LIST_DELIM, $_cdrom)
      cdrom { $xxx }
    done
  endif

  ## setting up ASPI devices
  ifndef restricted
    if (strlen($_aspi))
      foreach $xxx ($LIST_DELIM, $_aspi)
        $zz = (1);
        $yy2 = ""; $yy3 = (-1);
        if(strlen($xxx))
         foreach $yyy (":", $xxx)
          $zzz = "$yy", $zz, " = $yyy";
          $zz = ($zz + 1);
          $$zzz
         done;
        endif;
        aspi { $yy1 devicetype $yy2 target $yy3 };
      done
    endif
  endif

  ipxsupport $_ipxsupport
  ipx_network $_ipx_network
  novell_hack $_novell_hack
  if (1) # no idea why but we need this...
    foreach $xxx (" ", "1 2 3 4 5 6 7 8 9")
      $zzz = "$_lpt", $xxx
      $zzz = $$zzz
      if ((strstr($zzz, "direct") != -1) && (strchr($zzz, ' ') != -1))
        $zzz = strdel($zzz, 0, strchr($zzz, ' ') + 1)
        printer { lpt $xxx file $zzz timeout $_printer_timeout }
      else if (strlen($zzz))
        $zzz = "'", $zzz, "'"
        printer { lpt $xxx command $$zzz timeout $_printer_timeout }
      endif
    done
  endif

  if (strlen($_speaker))
    $xxx = "speaker ", $_speaker;
    $$xxx
  else
    speaker off
  endif
  ifdef restricted
    ## /etc/dosemu.users defined 'restricted' for this login
    define c_normal
    undef c_all
    if ($_vnet eq "vde" || !$_pktdriver)
      vdeswitch $_vdeswitch
      slirpargs $_slirpargs
      vnet $_vnet
      pktdriver $_pktdriver
    endif
    if ($_pci)
      pci auto
    endif
  else
    # here are the root requiring options
    if (strlen($_irqpassing))
      $yyy = "irqpassing { "
      if (strlen($_irqpassing))
        foreach $xxx (" ", $_irqpassing)
          $yyy = $yyy, "use_sigio ", $xxx
        done
      endif
      $yyy = $yyy, " }";
      $$yyy
    else
      irqpassing off
    endif
    if (strlen($_hardware_ram))
      hardware_ram { $$_hardware_ram }
    endif
    ethdev $_ethdev
    tapdev $_tapdev
    vdeswitch $_vdeswitch
    slirpargs $_slirpargs
    netsock $_netsock
    vnet $_vnet
    pktdriver $_pktdriver
    tcpdriver $_tcpdriver
    ne2k $_ne2k
    if (strlen($_ports)) ports { $$_ports } endif
    pci $_pci
  endif

  if (strlen($_unix_exec))
    unix_exec $_unix_exec
  endif
  if (strlen($_lredir_paths))
    lredir_paths $_lredir_paths
  endif
  if (strlen($_hostfs_drives))
    hostfs_drives $_hostfs_drives
  endif

  ## setting up the features list
  if ( (  ($DOSEMU_VERSION_CODE >= ((98 << 16) | (3 << 8) | 3))
             && ($DOSEMU_VERSION_CODE < (99 << 16)) )
       || ($DOSEMU_VERSION_CODE > ((99 << 16) | (5 << 8))) )
    if (strlen($_features))
      foreach $xxx ($LIST_DELIM, $_features)
        $yyy = strdel($xxx, strstr($xxx, ":"), 999);
        $zzz = strsplit($xxx, strstr($xxx, ":"), 999);
        if (strlen($zzz))
          $zzz = strsplit($zzz, 1, 999);
        else
          $zzz = (0);
        endif
        feature { $yyy = $zzz };
      done
    endif
  endif

endif
#############################################################################
