/**************************************************************************
 *			MAND9.C - Print Dragon (HardCopy)
 *	     	      Mandelbrot Self-Squared Dragon Generator
 *			     For the Commodore Amiga
 *				  Version 2.05
 *
 *		       Copyright (C) 1986, Scott D. Ballantyne
 *			      Placed in the Public Domain
 *
 *	This program may be distributed free of charge as long as the above
 *	notice is retained.  You may extract any or all information contained
 *	in this file for use in your own programs
 *
 **************************************************************************/

#include "mand.h"
#include <devices/printer.h>
#include <libraries/dosextens.h>

/* Graphics definitions */
extern struct GfxBase		*GfxBase;
extern struct IntuitionBase	*IntuitionBase;
 
extern struct RastPort		*rp;
extern struct ViewPort		*vp;
 
extern struct Window		*w, *ColorWindow;
extern struct Screen  		*screen;
extern struct IntuiMessage	*message;
 
extern SHORT			last_color;
extern BOOL			SettingCenter, SettingBoxSize;
/*----------------------------------*/
/* Miscellaneous Global Definitions */
extern FLOAT	start_r, end_r, start_i, end_i;	/* Block bounds for set */
extern int	max_x, max_y;
extern int	max_count, color_inc, color_offset;
extern int	color_set, color_mode, color_div;
extern int	color_inset, func_num;
extern UWORD	*color_table;
extern FILE	*console, *redir_fp;
 
extern SHORT			ZoomCenterX, ZoomCenterY, ZoomBoxSizeX, ZoomBoxSizeY;
extern SHORT			ZoomBoxStartX, ZoomBoxStartY;
extern BOOL			Resume;
extern struct NewScreen		ns;
extern struct NewWindow		nw;

extern LONG			*PictModes, *PictBody, *MandelHeader;
extern struct PaintingHeader	PaintingHeader;
extern struct Menu		MainMenu[MENU_COUNT];

#define PRT_FLAGS      (SPECIAL_FULLCOLS | SPECIAL_FULLROWS | SPECIAL_ASPECT)

VOID PrintMand()
{
	LONG			OpenDevice();
	struct IODRPReq		*CreateExtIO();
	struct MsgPort		*CreatePort();

	struct MsgPort		*printerport = NULL;
	struct IODRPReq		*printer_message = NULL;
	APTR			old_window;
	struct Process		*mandelbrot, *FindTask();

	mandelbrot = FindTask(0L);
	old_window = mandelbrot->pr_WindowPtr;
	mandelbrot->pr_WindowPtr = (APTR)w;

	if (!(printerport = CreatePort(0L, 0L)))
		goto ERROR;
	if (!(printer_message =
		    CreateExtIO(printerport, (LONG)sizeof(struct IODRPReq))))
		goto ERROR;

	if (OpenDevice("printer.device", 0L, printer_message, 0L))
		goto ERROR;

	
	printer_message->io_Command = PRD_DUMPRPORT;
	printer_message->io_RastPort = rp;
	printer_message->io_ColorMap = vp->ColorMap;
	printer_message->io_Modes = vp->Modes;
	printer_message->io_SrcX = 0;
	printer_message->io_SrcY = 0;
	printer_message->io_SrcWidth = max_x;
	printer_message->io_SrcHeight = max_y;
	printer_message->io_DestCols = 0;
	printer_message->io_DestRows = 0;
	printer_message->io_Special = PRT_FLAGS;

	DoIO(printer_message);
	CloseDevice(printer_message);
ERROR:
	if (printer_message)
		DeleteExtIO(printer_message, (LONG)sizeof(struct IODRPReq));
	if (printerport)
		DeletePort(printerport);
	mandelbrot->pr_WindowPtr = old_window;
}

