/* 
   Pcm: a PC eMulator
   Copyright (C) 1992 Electronetics, Inc.  All rights reserved.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include "sim.h"

extern unsigned char intmask;

unsigned char *i_e4(pc)
unsigned char *pc; {
  unsigned char port;
  port = *pc++;
  rport(port, 1);
  return pc;
}

unsigned char *i_e5(pc)
unsigned char *pc; {
  unsigned char port;
  port = *pc++;
  rport(port, 2);
  return pc;
}

unsigned char *i_e6(pc)
unsigned char *pc; {
  unsigned char port;
  port = *pc++;
  wport(port, AL, 1);
  return pc;
}

unsigned char *i_ec(pc)
unsigned char *pc; {
  rport(DX, 1);
  return pc;  
}

unsigned char *i_ed(pc)
unsigned char *pc; {
  rport(DX, 2);
  return pc;  
}

unsigned char *i_ee(pc)
unsigned char *pc; {
  wport(DX, AL, 1);
  return pc;  
}

unsigned char *i_ef(pc)
unsigned char *pc; {
  wport(DX, AL, 2);
  return pc;  
}

wport(port, val, size)
unsigned short port, val; 
unsigned int size; {
  switch(port) {
  case 0x20: break;
  case 0x61: break;
  default:
#ifndef TTY
    fprintf(stderr,"wportb: 0x%x to port 0x%x\n",val,port);
#endif /* TTY */
  break;
  }
}

rport(port, size)
unsigned short port;
unsigned int size; {
  switch (port) {
  case 0x21: /* Programmable interrupt controller mask */
    AL = intmask;
  break;
  case 0x60: /* keyboard data */
    AL = readchar();
  break;
  case 0x61: /* keyboard status */
  break;
  default: 
    printf("warning: reading unknown port 0x%x\n",port);
    AL = 0xff;
  break;
  }
}
