/*
* epson.c - epson printer module
*
*/
#include <slos_protos.h>
#include <stdio.h>
#include <string.h>
#include "app.h"
/********************************* Global data ******************************************/
LISTHANDLE mlh;
#ifdef AMIGA
#define __USE_SYSBASE
#include <proto/exec.h>
#include <exec/execbase.h>
struct Library *SoftLogikOSBase = 0;
#endif
//commands the this module understands and the routines to handle them
struct TagItem cmd[]=
{
MACT_EndStrip, (ULONG)&endstrip,
MACT_BeginTile, (ULONG)&begintile,
MACT_EndTile, (ULONG)&endtile,
MACT_OpenOutput, (ULONG)&openoutput,
MACT_CloseOutput, (ULONG)&closeoutput,
MACT_ShowGUI, (ULONG)&showgui,
MACT_OutputQ, (ULONG)&outputq,
MACT_Cleanup, (ULONG)&cleanup,
TAG_DONE
};
//tags that define this module
struct TagItem mi[] =
{
MOD_ModuleType, MTYPE_PRINTER,
MOD_DataType, DTYPE_BITMAP,
MOD_ModuleName, (ULONG)APP_NAME,
MOD_ActionSet, (ULONG)cmd,
MOD_GUIName, (ULONG)APP_GUINAME,
MOD_Author, (ULONG)APP_AUTHOR,
MOD_Copyright, (ULONG)APP_COPYRIGHT,
TAG_DONE
};
//tags for SL_ModuleInitA
struct TagItem modtags[] =
{
APPATTR_Name, (ULONG)APP_NAME,
APPATTR_Author, (ULONG)APP_AUTHOR,
APPATTR_Copyright, (ULONG)APP_COPYRIGHT,
APPATTR_Version, (ULONG)rev_version,
APPATTR_Date, (ULONG)rev_date,
APPATTR_DefaultDirectory, (ULONG)SOFTLOGIK_PRINTERSPATH,
#ifndef NOINTRSRC
APPATTR_RsrcArray, (ULONG)internal_rsrc_array,
#endif
TAG_DONE
};
char **str_table = 0;
ULONG str_table_count = 0;
char *spottype[] = {"Donut", "Dot", "Line", "NewDot", "Propeller", "Ring", "Triangle"};
UWORD dithertype[] = {DITHERTYPE_ORDERED_64, DITHERTYPE_HALFTONE_64, DITHERTYPE_FLOYDSTEINBERG, DITHERTYPE_THRESHOLD};
/********************************* Local functions **************************************/
static void initrequester(struct XPD_Model *, struct modguidata *, WINHANDLE);
static void updategui_newmodel(struct XPD_Model *, struct modguidata *, WINHANDLE);
static void setnewpaper(struct modguidata *, WINHANDLE);
static void updategui_newscreen(struct modguidata *mgd);
static void updategui_newcolorcorrection(struct modguidata *mgd);
static void updategui_screencustom(struct modguidata *mgd);
static void updategui_colorcustom(struct modguidata *mgd);
static void defaultmad(struct modacceptdata *);
static void getmad(APPHANDLE, struct modacceptdata *);
static void setmad(APPHANDLE, struct modacceptdata *);
//
static int printstrip(struct output *, ULONG);
static int sendbitimage(struct output *);
static int sendraster(struct output *);
static BOOL advanceprinthead(struct output *);
static int allocprintbuff(struct output *);
static void freeprintbuff(struct output *);
//
static int compress_pkbits(UBYTE *to, UBYTE *from, ULONG count);
/********************************* Init and Cleanup actions ****************************/
SL_CALLBACK struct TagItem *init(ULONG cookie)
{
mlh = 0;
if (SL_SystemInit())
{
if (cookie == MODULE_INIT_COOKIE)
{
#ifdef AMIGA
if (SysBase->AttnFlags & AFF_68882)
{
SoftLogikOSBase = OpenLibrary(SOFTLOGIK_OS_FPU_LIBRARY_NAME, 4);
}
if (!SoftLogikOSBase)
{
SoftLogikOSBase = OpenLibrary(SOFTLOGIK_OS_LIBRARY_NAME, 4);
}
if (!SoftLogikOSBase)
{
return (0);
}
#endif
if (SL_GetStringTableA(&str_table, &str_table_count, 102, modtags))
{
if ((mlh = XPD_CreateModelList("EpsonModels")))
{
return (mi);
}
SL_FreeStringTable(&str_table, &str_table_count);
}
#ifdef AMIGA
CloseLibrary(SoftLogikOSBase);
#endif
}
SL_SystemCleanup();
}
return (0);
}
SL_CALLBACK void cleanup(void)
{
if (mlh)
{
XPD_DestroyModelList(mlh);
mlh = 0;
}
SL_FreeStringTable(&str_table, &str_table_count);
#ifdef AMIGA
if (SoftLogikOSBase)
{
CloseLibrary(SoftLogikOSBase);
SoftLogikOSBase = 0;
}
#endif
SL_SystemCleanup();
}
/********************************* ShowGUI action ***************************************/
SL_CALLBACK ULONG showgui(APPHANDLE ah, struct TagItem *tags)
{
WINHANDLE wh;
struct TagItem *tag;
struct modacceptdata *mad;
struct modguidata *mgd;
struct XPD_Model *m;
//get the gui action
if ((tag = SL_FindTagItem(MOD_GUIAction, tags)))
{
switch (tag->ti_Data)
{
case GACT_Init:
if ((mgd = SL_MAlloc(ah, sizeof(struct modguidata))))
{
//CRASH;
mgd->ah = ah;
mgd->hmsys = INCHES;
if ((tag = SL_FindTagItem(MOD_HMSYS, tags)))
{
mgd->hmsys = tag->ti_Data;
}
mgd->vmsys = INCHES;
if ((tag = SL_FindTagItem(MOD_VMSYS, tags)))
{
mgd->vmsys = tag->ti_Data;
}
if ((mgd->mh = SL_ModuleInitA(ah, modtags)))
{
if ((wh = SL_CreateSubRequester(mgd->mh, 100)))
{
if ((mgd->screencustom = SL_CreateRequester(mgd->mh, 102)))
{
if ((mgd->screenbuiltin = SL_CreateRequester(mgd->mh, 103)))
{
if ((mgd->colorcustom = SL_CreateRequester(mgd->mh, 104)))
{
if ((mgd->colorbuiltin = SL_CreateRequester(mgd->mh, 105)))
{
mad = 0;
if ((tag = SL_FindTagItem(MOD_GUIAcceptData, tags)))
{
mad = (struct modacceptdata *)tag->ti_Data;
}
if (mad)
{
memcpy(&mgd->mad, (char *)mad, sizeof(struct modacceptdata));
m = mad->model;
mgd->mad.printer = XPD_DuplicatePrinter(mad->printer);
}
else
{
defaultmad(&mgd->mad);
m = 0;
}
initrequester(m, mgd, wh);
return ((ULONG)wh);
}
SL_FreeRequester(mgd->colorcustom);
}
SL_FreeRequester(mgd->screenbuiltin);
}
SL_FreeRequester(mgd->screencustom);
}
SL_FreeSubRequester(wh);
}
SL_ModuleCleanup(mgd->mh);
}
SL_MFree(mgd);
}
break;
case GACT_Cleanup:
if ((tag = SL_FindTagItem(MOD_GUIReqhandle, tags)))
{
if ((wh = (WINHANDLE)tag->ti_Data))
{
mgd = (struct modguidata *)SL_GetWindowAttr(wh, WINATTR_UserData);
if (mgd->mad.printer)
{
XPD_DestroyPrinter(mgd->mad.printer);
}
if (mgd->screencustom)
{
SL_FreeRequester(mgd->screencustom);
}
if (mgd->screenbuiltin)
{
SL_FreeRequester(mgd->screenbuiltin);
}
if (mgd->colorcustom)
{
SL_FreeRequester(mgd->colorcustom);
}
if (mgd->colorbuiltin)
{
SL_FreeRequester(mgd->colorbuiltin);
}
SL_FreeSubRequester(wh);
SL_ModuleCleanup(mgd->mh);
SL_MFree(mgd);
return (1);
}
}
break;
case GACT_Accept:
if ((tag = SL_FindTagItem(MOD_GUIReqhandle, tags)))
{
if ((wh = (WINHANDLE)tag->ti_Data))
{
if ((mad = SL_MAlloc(ah, sizeof(struct modacceptdata))))
{
mgd = (struct modguidata *)SL_GetWindowAttr(wh, WINATTR_UserData);
//copy the mad values from the mgd mad
*mad = mgd->mad;
mad->printer = XPD_DuplicatePrinter(mgd->mad.printer);
//get the values from the requester for these
mad->paperwidth = SL_AtoC((char *)SL_GetReqObjAttr(wh, 132, CTRLATTR_String), mgd->hmsys, 0,0);
mad->paperheight = SL_AtoC((char *)SL_GetReqObjAttr(wh, 133, CTRLATTR_String), mgd->vmsys, 0,0);
mad->offsethorz = SL_AtoC((char *)SL_GetReqObjAttr(wh, 171, CTRLATTR_String), mgd->hmsys, 0,0);
mad->offsetvert = SL_AtoC((char *)SL_GetReqObjAttr(wh, 172, CTRLATTR_String), mgd->vmsys, 0,0);
mad->orient = SL_GetReqObjAttr(wh, 138, CTRLATTR_Current);
mad->offsettype = SL_GetReqObjAttr(wh, 170, CTRLATTR_Current);
mad->papertype = SL_GetReqObjAttr(wh, 130, CTRLATTR_Current);
mad->devtype = SL_GetReqObjAttr(wh, 150, CTRLATTR_Current);
strcpy(mad->devname, (char *)SL_GetReqObjAttr(wh, 151, CTRLATTR_String));
mad->dithertype = dithertype[SL_GetReqObjAttr(wh, 180, CTRLATTR_Current)];