/* 
   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.
 */

/*
 * routines to manage writing to PC memory
 */
#include "sim.h"

/*
 * Handle block copy (possibly overlapping)
 * 8086 style, foward and backward block copy
 */
void fblcopy(src, dest, count, wordp)
unsigned char *src, *dest;
int count, wordp; {
  register unsigned char c1, c2;
  if (!wordp) { /* bytes */
    while (count-- > 0) {
      *dest++ = *src++;
    }
  }
  else {
    while (count-- > 0) {
      c1 = *src++;
      c2 = *src++;
      *dest++ = c1;
      *dest++ = c2;
      count--;
    }
  }
}

void bblcopy(src, dest, count, wordp)
unsigned char *src, *dest;
int count, wordp; {
  register unsigned char c1, c2;
  if (!wordp) { /* bytes */
    while (count-- > 0) {
      *dest-- = *src--;
    }
  }
  else {
    src++;
    dest++;
    while (count-- > 0) {
      c1 = *src--;
      c2 = *src--;
      *dest-- = c1;
      *dest-- = c2;
      count--;
    }
  }
}
