#include	"vogle.h"

#ifdef WATCOM
#include <graph.h>
#endif

/* 
 * Note, vga can't do double buffering by page swapping...`
 */

#define	V_PIX_ASPECT	1.0

static	int	old_mode;

#ifndef WATCOM
extern	unsigned	int	_buffer_segment;
extern	unsigned	int	_buffer_offset;
#endif
/*
  extern	int
  vega_char(),
  vega_clear(),
  vega_color(),
  vega_draw(),
  vega_setpal(),
  pc_fill(),
  vega_font(),
  pc_getkey(),
  pc_checkkey(),
  pc_locator(),
  vega_string(),
  setmode();
*/

vga_init()
{
#ifdef WATCOM
  old_mode = setmode(_VRES16COLOR);
#else
  old_mode= setmode(18);
#endif
  vdevice.sizeX = 479 * V_PIX_ASPECT;
  vdevice.sizeY = 479;
  vdevice.sizeSx = 640;
  vdevice.sizeSy = 479;
  vdevice.depth = 4;
#ifndef WATCOM
  _buffer_segment = 0xA000;
  _buffer_offset = 0;
  pc_locinit(vdevice.sizeSx, vdevice.sizeSy);
#endif
  zsetup();
  vega_setpal();
  return (1);
}

/*
 * vga_exit
 *
 *	Sets the display back to text mode.
 */
vga_exit()
{
#ifdef WATCOM
  _setvideomode(_TEXTC80);
#else
  (void)setmode(old_mode); 
#endif
  return (1);
}

static	int
  noop()
{
  return (-1);
}

static DevEntry vgadev = {
  "vga",
  "large",
  "small",
  noop,
  vega_char,
  pc_checkkey,
  vega_clear,
  vega_color,
  vega_draw,
  vga_exit,
  pc_fill,
  vega_font,
  noop,
  pc_getkey,
  vga_init,
  pc_locator,
  noop,
  vega_string,
  noop,
  noop
  };

/*
 * _vga_devcpy
 *
 *	copy the pc device into vdevice.dev.
 */
void _vga_devcpy()
{
  vdevice.dev = vgadev;
}


#ifdef WATCOM

/*
  Add some super vga modes for WATCOM C
  */

int svga_init()
{
  old_mode = setmode(_SVRES16COLOR);
  vdevice.sizeX = 599 * V_PIX_ASPECT;
  vdevice.sizeY = 599;
  vdevice.sizeSx = 799;
  vdevice.sizeSy = 599;
  vdevice.depth = 4;
  pc_locinit(vdevice.sizeSx, vdevice.sizeSy); 
  zsetup();
  vega_setpal();
  return (1);
}

static DevEntry svgadev = {
  "svga",
  "large",
  "small",
  noop,
  vega_char,
  pc_checkkey,
  vega_clear,
  vega_color,
  vega_draw,
  vga_exit,
  pc_fill,
  vega_font,
  noop,
  pc_getkey,
  svga_init,
  pc_locator,
  noop,
  vega_string,
  noop,
  noop
  };

/*
 * _svga_devcpy
 *
 *      copy the pc device into vdevice.dev.
 */
void _svga_devcpy()
{
  vdevice.dev = svgadev;
}

int svga2_init()
{
  old_mode = setmode(_XRES16COLOR);
  vdevice.sizeX = 767 * V_PIX_ASPECT;
  vdevice.sizeY = 767;
  vdevice.sizeSx = 1023;
  vdevice.sizeSy = 767;
  vdevice.depth = 4;
  pc_locinit(vdevice.sizeSx, vdevice.sizeSy); 
  zsetup();
  vega_setpal();
  return (1);
}

static DevEntry svga2dev = {
  "svga2",
  "large",
  "small",
  noop,
  vega_char,
  pc_checkkey,
  vega_clear,
  vega_color,
  vega_draw,
  vga_exit,
  pc_fill,
  vega_font,
  noop,
  pc_getkey,
  svga_init,
  pc_locator,
  noop,
  vega_string,
  noop,
  noop
  };

/*
 * _svga2_devcpy
 *
 *      copy the pc device into vdevice.dev.
 */
void _svga2_devcpy()
{
  vdevice.dev = svga2dev;
}

#endif


