#include "cp.h"

union printerIO
{
	struct IOStdReq    ios;
	struct IODRPReq    iodrp;
	struct IOPrtCmdReq iopc;
};

WORD Dump() 
{
union printerIO *PrintIO;
struct MsgPort  *PrintMP;
WORD   error;
LONG  modeID;
struct PrinterData *PD;
struct PrinterExtendedData *PED;
char Mes[64];

	if ((PrintMP = CreateMsgPort()))
	  {
		if ((PrintIO = (union printerIO *)CreateIORequest( PrintMP, max(sizeof(union printerIO *),1024))))  /* 1024 fixes mungwall problem ? */
		  {
		  	if ((NULL == OpenDevice("printer.device",0,(struct IORequest *)PrintIO,0)))
			  {
			  	PD  = (struct PrinterData *)PrintIO-> iodrp.io_Device;
			  	PED = (struct PrinterExtendedData *) &PD->pd_SegmentData->ps_PED;
			  
			  	if ((modeID = GetVPModeID(vp)) != INVALID_ID)
			  	  {
			  	  
				  	PrintIO-> iodrp.io_Command   = PRD_DUMPRPORT;
		  			PrintIO-> iodrp.io_RastPort  = rp;
			  		PrintIO-> iodrp.io_ColorMap  = vp-> ColorMap;
  					PrintIO-> iodrp.io_Modes     = modeID;
			  		PrintIO-> iodrp.io_SrcX      = 0;
		  			PrintIO-> iodrp.io_SrcY      = 0;
			  		PrintIO-> iodrp.io_SrcWidth  = PlotWindowWnd-> Width /*-1*/;
  					PrintIO-> iodrp.io_SrcHeight = PlotWindowWnd-> Height - (CPANEL ? (cPFont->ta_YSize * 3) : 0);
				  	PrintIO-> iodrp.io_DestCols  = 0;
  					PrintIO-> iodrp.io_DestRows  = 0;
				  	PrintIO-> iodrp.io_Special   = SPECIAL_NOPRINT;

				  	error = DoIO((struct IORequest *) PrintIO);

                         sprintf(Mes,"Printing ... destC %ld destR %ld  maxX %ld maxY %ld",PrintIO->iodrp.io_DestCols,PrintIO->iodrp.io_DestRows,PED->ped_MaxXDots,PED->ped_MaxYDots);
					SetWindowTitles( PlotWindowWnd, Mes,Mes );

				  	if ( PrintIO->iodrp.io_Error == 0 )
				  	  {
					  	PrintIO-> iodrp.io_Special   &= ~SPECIAL_NOPRINT;

					  	if ( FEED == FALSE )
					  		PrintIO-> iodrp.io_Special   |= SPECIAL_NOFORMFEED;

					  	error = DoIO((struct IORequest *) PrintIO);
					  }

					SetWindowTitles( PlotWindowWnd, "Done Printing !","Done Printing !" );
			  	  }
			  	  else error = 104;
				CloseDevice((struct IORequest *)PrintIO);
			  }
			  else  error = 103;
			DeleteIORequest((struct IORequest *)PrintIO);
		  }
		  else  error = 102;
	     DeleteMsgPort(PrintMP);
	  }
	  else error = 101;
			
	return ( error );
}
  
