/*
 * DANG_BEGIN_MODULE
 *
 * Description:
 *  Fake video port emulation for TERMINAL and the CONSOLE non-vga modes.
 * 
 * DANG_END_MODULE
 *
 * $Date: $
 * $Source: $
 * $Revision: $
 * $State: $
 *
 * $Log: $
 */

#include "dosemu.h"
#include "base/port.h"
#include "env/video.h"

static Bit8u fake_video_inb(Bit32u port)
{
  static Bit8u cga_r = 0;

  switch (port) {
    case 0x3ba :  /* vertical retrace -- used to avoid CGA snow */
    case 0x3da :
      return (cga_r ^= 1) ? 0xcf : 0xc6;
    case 0x3cc :  /* color screen */
      return 0x01;
    case 0x3db :  /* light pen */
      return 0x00;
  }
  return 0x00;
}

static void fake_video_outb(Bit32u port, Bit8u byte)
{
}

void fake_video_port_init(void)
{
  emu_iodev_t  io_device;

  /* register our port handler */
  io_device.read_portb   = fake_video_inb;
  io_device.write_portb  = fake_video_outb;
  io_device.read_portw   = NULL;
  io_device.write_portw  = NULL;
  io_device.handler_name = "fake video";
  io_device.irq          = EMU_NO_IRQ;
  io_device.start_addr   = 0x3b0;
  io_device.end_addr     = 0x3bb;
  port_register_handler(io_device);

  io_device.start_addr   = 0x3c0;
  io_device.end_addr     = 0x3df;
  port_register_handler(io_device);
}

void fake_video_port_reset(void)
{
}

