head	1.2;
access;
symbols
	OCT93:1.2;
locks;
comment	@ * @;


1.2
date	93.06.11.16.29.21;	author Rhialto;	state Exp;
branches;
next	1.1;

1.1
date	93.06.11.15.08.07;	author Rhialto;	state Exp;
branches;
next	;


desc
@Initialisation code and message passing interface
@


1.2
log
@First real RCS checkin
@
text
@/* $Id$
 * $Log$
 */

/*
 *  INIT.C
 */

#include "defs.h"
#include <clib/alib_protos.h>
#include <clib/asl_protos.h>

Prototype __geta4 long DevInit(PrinterData *);
Prototype __geta4 long DevExpunge(void);
Prototype __geta4 long DevOpen(void);
Prototype __geta4 long DevClose(void);
Prototype __geta4 long MsgRender(long ct, long x, long y, long status);
Prototype __geta4 void PrinterProc(void);
Prototype void FakeSeg(void);
Prototype CreateProc(char *, ULONG, ULONG, ULONG);

Prototype PrinterData *PD;
Prototype PrinterExtendedData *PED;
Prototype void *AslBase;
Prototype struct FileRequester *FileReq;

PrinterData    *PD;
PrinterExtendedData *PED;
void	       *AslBase;
void	       *DOSBase;
struct FileRequester *FileReq;

const struct TagItem frtags[] = {
    ASL_Hail,	(ULONG)"Select file to write FAX data in",
    ASL_Dir,	(ULONG)"FAX:",
    ASL_File,	(ULONG)"faxrastportdump",
    TAG_DONE
};

/*
 * The message interface.
 */

struct PrtMsg {
    struct Message  pm_Msg;
    long	    pm_Type;
#define PM_RENDER   1
#define PM_INIT     2
#define PM_EXPUNGE  3
};
#define pm_rc	    pm_Type

struct RenderMsg {
    struct PrtMsg   rm_PrtMsg;
    long	    rm_ct;
    long	    rm_x;
    long	    rm_y;
    long	    rm_status;
};

struct MsgPort *ProcPort;

long
SyncMsg(struct PrtMsg *m)
{
    m->pm_Msg.mn_ReplyPort = FindTask(NULL);
    PutMsg(ProcPort, &m->pm_Msg);

    do {
	Wait(SIGF_SINGLE);
    } while (m->pm_Msg.mn_Node.ln_Type != NT_REPLYMSG);

    return m->pm_rc;
}

__geta4 long
DevInit(pd)
PrinterData *pd;
{
    struct PrtMsg   pm;
#ifdef DEBUG
    initsyslog();
    debug(("DevInit %08x\n", pd));
#endif
    DOSBase = OpenLibrary("dos.library", 0L);
    ProcPort = CreatePort(NULL, 0L);
    ProcPort->mp_Flags = PA_IGNORE;
    FreeSignal(ProcPort->mp_SigBit);
    debug(("CreateProc...\n"));
    CreateProc("ElCheapoFaxPrinterDriver Process", 0, ((ULONG)FakeSeg)>>2, 4096);

    PD = pd;
    PED= &PEDData;

    pm.pm_Type = PM_INIT;
    return SyncMsg(&pm);
}

__geta4 long
DevExpunge(void)
{
    struct PrtMsg   pm;

    debug(("DevExpunge\n"));
    pm.pm_Type = PM_EXPUNGE;
    SyncMsg(&pm);

    if (DOSBase) {
	CloseLibrary(DOSBase);
	DOSBase = NULL;
    }
#ifdef DEBUG
    uninitsyslog();
#endif
    return 0;
}

__geta4 long
DevOpen(void)
{
    debug(("DevOpen\n"));
    if (DOSBase == NULL)
	return -1;		/* VERY wrong!! */
    return 0;
}

__geta4 long
DevClose(void)
{
    debug(("DevClose\n"));
    return 0;
}

__geta4 long
MsgRender(long ct, long x, long y, long status)
{
    struct RenderMsg rm;

    rm.rm_PrtMsg.pm_Type = PM_RENDER;
    rm.rm_ct = ct;
    rm.rm_x = x;
    rm.rm_y = y;
    rm.rm_status = status;

    return SyncMsg(&rm.rm_PrtMsg);
}

void
chkabort(void)
{
    /* don't abort */
}

__geta4 void
PrinterProc(void)
{
    int 	    done = 0;
    debug(("PrinterProc started\n"));

    /* First finish that MsgPort */
    ProcPort->mp_SigTask = FindTask(NULL);
    ProcPort->mp_SigBit = AllocSignal(-1L);
    ProcPort->mp_Flags = PA_SIGNAL;

    for (;!done;) {
	struct PrtMsg *pm;

	WaitPort(ProcPort);
	while (pm = GetMsg(ProcPort)) {
	    switch (pm->pm_Type) {
	    case PM_RENDER:
#define rm  ((struct RenderMsg *)pm)
		pm->pm_rc = Render(rm->rm_ct, rm->rm_x, rm->rm_y, rm->rm_status);
		break;
	    case PM_INIT:
		AslBase = OpenLibrary("asl.library", 0);
		if (AslBase) {
		    FileReq = AllocAslRequest(ASL_FileRequest, frtags);
		}
		debug(("DOSBase %08lx AslBase %08lx FReq %08lx\n", DOSBase, AslBase, FileReq));
		pm->pm_rc = 0;
		break;
	    case PM_EXPUNGE:
		if (AslBase) {
		    if (FileReq) {
			FreeAslRequest(FileReq);
			FileReq = NULL;
		    }
		    CloseLibrary(AslBase);
		    AslBase = NULL;
		}
		done = 1;
	    }
	    pm->pm_Msg.mn_Node.ln_Type = NT_REPLYMSG;
	    Signal((struct Task *)pm->pm_Msg.mn_ReplyPort, SIGF_SINGLE);
	}
    }
}
@


1.1
log
@Initial revision
@
text
@d1 3
@
