/*
 * lpportio.cc
 * 
 * Parallel port (lp port) lowest level driver for various 
 * boards connected to the parallel port. 
 * 
 * Copyright (c) 2003 by Wolfgang Wieser (wwieser@gmx.de) 
 * 
 * This file may be distributed and/or modified under the terms of the 
 * GNU General Public License version 2 as published by the Free Software 
 * Foundation. 
 * 
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 * 
 */

#include "lpportio.h"

#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <assert.h>


int _do_debug_delay=0;

void LPPortIO::_stack_error()
{
	assert(!"stack error");
	abort();
}


LPPortIO::LPPortIO(size_t parport_baseaddr,int *failflag)
{
	// Need sufficient permissions for that: 
	if(ioperm(parport_baseaddr,4,1))
	{
		if(failflag)
		{  --(*failflag);  }
		else
		{  fprintf(stderr,"While attempting ioperm(%u,4,1): %s\n",
			parport_baseaddr,strerror(errno));  exit(1);  }
	}
	
	port_outdata=parport_baseaddr;
	port_status =parport_baseaddr+1;
	port_control=parport_baseaddr+2;
	port_indata =parport_baseaddr;  // NOT +3 (no EPP)
	
	//control_bits=0x0^C_INVMASK;
	control_bits=do_inb(port_control)^C_INVMASK;
	odata_bits=0x0;
	
	odata_stack_top=0;
}

LPPortIO::~LPPortIO()
{
	// Cleanup: 
	ioperm(port_outdata,4,0);
}
