/*
 * $Date: $
 * $Source: $
 * $Revision: $
 * $State: $
 *
 * $Log: $
 */

#ifndef _DOSEMU_H
#define _DOSEMU_H

#include <unistd.h>
#include <stdio.h>

#include "emu_defs.h"
#include "base/cpu.h"
#include "base/debug.h"
#include "base/signals.h"

/*
 * Speaker constants
 */
#define SPKR_OFF	0
#define SPKR_NATIVE	1
#define SPKR_EMULATED	2

/*
 * Version constants
 */

EXTERN int         version        INIT(VERSION);
EXTERN int         patchlevel     INIT(PATCHLEVEL);
EXTERN int         sublevel       INIT(SUBLEVEL);
EXTERN const char *version_str    INIT(VERSION_STR);
EXTERN const char *arch_str       INIT(ARCH_STR);
EXTERN const char *emulator_str   INIT(EMULATOR_STR);
EXTERN const char *config_host    INIT(CONFIG_HOST);
EXTERN const char *config_time    INIT(CONFIG_TIME);
EXTERN const char *bios_str       INIT(BIOS_STR);

/*
 * X-Windows globals
 */

EXTERN int         keypipe;                  /* X-pipes */
EXTERN int         mousepipe;

/*
 * Standard globals
 */
EXTERN int         terminal_pipe;
EXTERN int         terminal_fd INIT(-1);
EXTERN int         selfmem_fd  INIT(-1);     /* /dev/selfmem file descriptor */
EXTERN int         mem_fd      INIT(-1);     /* /dev/mem file descriptor */
EXTERN int         kbd_fd      INIT(-1);     /* the fd for the keyboard */ 
EXTERN Boolean     i_am_root   INIT(FALSE);  /* Running as root? */
EXTERN char       *tmpdir;                   /* temporary directory ptr */
EXTERN int         max_page    INIT(7);      /* highest video page-1 */
EXTERN Boolean     in_vm86     INIT(FALSE);  /* Are we inside vm86()? */

/* would like to have this in memory.h (emu.h is included before memory.h) */
#define HARDWARE_RAM_START 0xc8000
#define HARDWARE_RAM_STOP  0xf0000

typedef struct config_info {
  int    hdiskboot;

  /* for video */
  Boolean  console;
  Boolean  console_video;
  Boolean  graphics;
  Boolean  vga;
  Boolean  X;
  Bit16u   cardtype;
  Bit16u   chipset;
  Bit16u   gfxmemsize;		/* for SVGA card, in K */

  Bit16u   term_color;		/* Terminal color support on or off */
  Bit16u   term_updatefreq;	/* Terminal update frequency */
  Bit16u   term_charset;	/* Terminal Character set */
  Bit16u   term_esc_char;	/* ASCII value used to get slang help screen */
  Bit16u   X_updatelines;       /* Amount to update at a time */
  Bit16u   X_updatefreq;        /* X update frequency */
  const char *X_display;           /* X server to use (":0") */
  const char *X_title;             /* X window title */
  const char *X_icon_name;
  const char *X_font;
  int      X_blinkrate;
  Boolean  fullrestore;
  Boolean  dualmon;
  
  Bit16u   usesX;  		/* !=0 if dosemu owns an X window */
  
  Boolean  console_keyb;
  Boolean  kbd_tty;
  Boolean  X_keycode;		/* use keycode field of event structure */
  Boolean  exitearly;
  Boolean  mathco;
  Boolean  ipxsup;
  Boolean  keybint;
  Boolean  dosbanner;
  Boolean  allowvideoportaccess;
  Boolean  timers;
  Boolean  mouse_flag;
  Boolean  mapped_bios;		/* video BIOS */
  Boolean  mapped_sbios;	/* system BIOS */
  char    *vbios_file;		/* loaded VBIOS file */
  Boolean  vbios_copy;
  Bit16u   vbios_seg;           /* VGA-BIOS-segment for mapping */
  Bit32u   vbios_size;          /* size of VGA-BIOS (64K for vbios_seg=0xe000
				   32K for vbios_seg=0xc000) */
  
  Boolean  bootdisk;		/* Special bootdisk defined */
  int      fastfloppy;
  const char *emusys;		/* map CONFIG.SYS to CONFIG.xxx */
  const char *emubat;		/* map AUTOEXEC.BAT to AUTOEXEC.xxx */
  const char *emuini;		/* map SYSTEM.INI to SYSTEM.xxx */
  
  Bit16u   speaker;		/* 0 off, 1 native, 2 emulated */
  Bit16u   fdisks, hdisks;
  Bit16u   num_lpt;
  Bit16u   num_ser;
  Bit16u   num_mice;

  int      pktflags;		/* global flags for packet driver */
  
  Bit16u   hogthreshold;
  
  Bit16u   mem_size, xms_size, ems_size, dpmi, sys_mem;
  Bit16u   ems_frame;
  Boolean  must_spare_hardware_ram;
  Boolean  hardware_pages[ ((HARDWARE_RAM_STOP-HARDWARE_RAM_START) >> 12)+1 ];
    
  int sillyint;            /* IRQ numbers for Silly Interrupt Generator 
			      (bitmask, bit3..15 ==> IRQ3 .. IRQ15) */
  
  int keyboard;
  int detach;
  const unsigned char *key_map;     /* pointer to the correct keyboard-map */
  const unsigned char *shift_map;
  const unsigned char *alt_map;
  const unsigned char *num_table;
  unsigned char *debugout;
  
  /* Lock File business */
  const char *tty_lockdir;  	/* The Lock directory  */
  const char *tty_lockfile;	/* Lock file pretext ie LCK.. */
  Boolean  tty_lockbinary;	/* Binary lock files ? */
  
} config_t;

/* 
 * DANG_BEGIN_REMARK
 * DOSEMU keeps system wide configuration status in a structure
 * called config.
 * DANG_END_REMARK
 */
EXTERN struct config_info config;

/*
 * DANG_BEGIN_REMARK
 * The var `fatalerr` can be given a true value at any time to have DOSEMU
 * exit on the next return from vm86 mode.
 * DANG_END_REMARK
 */
EXTERN int fatalerr;

extern int   mfs_redirector(void);
extern int   mfs_inte6(void);

extern void  p_dos_str(const char *,...) FORMAT(printf, 1, 2);
extern void  char_out(u_char, int);

extern void  leavedos(int) NORETURN;

extern void  dos_ctrlc(void);
extern void  dos_ctrl_alt_del(void);

#endif /* EMU_H */
