#
#include "mmr.h"
#include "bufferdfn.h"
#include "filesys.h"

/* move a part of the a.out file into some part of real memory via the
 * buffer
 */

/* what string*/
char *__mvhwht "@(#)mv_hunk.c	1.9";
char *__mvhbuf BUFFERWHAT;
char *__mvhmmr MMRWHAT;




mv_hunk(init_par, size, off, bno, fp)
	unsigned int init_par;  /* initial value of par used to store into real memory*/
	unsigned int size;      /* of hunk to move*/
	int off;                /* where hunk starts within block*/
	long int bno;           /* block number of file where hunk starts*/
	struct filep *fp;       /* which file */
{
	register char * buf_ptr, *t_ptr; /*from and to pointers for move*/
	register unsigned int resid;             /*residual value of hunk, how much left to move*/

	if (size == 0) return;

/* set up the initial values for the target mmrs*/
	TAR_PAR = init_par;
	TAR_PDR = BUFPDRPROTO;



/* initialize movement pointers and counters*/
	buf_ptr = BUFFER + off;
	t_ptr = TARGET;

/* this is proably an extra I/O, but who cares!*/
	get_file_block(fp, bno);

/* now the main work of moving bytes from the file to the target area*/
	while ( size --){
		*t_ptr = *buf_ptr;

		/* update the ptrs, getting more data and moving target as need be*/
		if ((++t_ptr) >= TARGET +512) {
			TAR_PAR += 010;  /* 512 bytes incr for a par*/
			t_ptr = TARGET;
		}

		if ((++buf_ptr) >= BUFFER + 512){
			bno++;
			if (get_file_block(fp, bno) < 0)
			{
				printf("Trouble reading file\n");
				return -1;
			}
			buf_ptr = BUFFER;
		}
	}       /* of while*/
} /* of mv_hunk*/
