//========================================================================
//
// AComm.h
//
// Copyright 1999 Emmanuel Lesueur
//
//========================================================================

#ifndef ACOMM_H
#define ACOMM_H

#define VMAGIC      100

#define st_unchanged 0
#define st_changed   1
#define st_url       2
#define st_run       3


#ifdef POWERUP

typedef void PPCMsg;
typedef void PPCPort;
typedef void PPCPortList;
typedef void PPCTask;

#ifdef DEBUGMSG

#include <stdio.h>

#ifdef __PPC__
#   define ID "PPC"
#else
#   define ID "68k"
#endif

static void* myPPCGetMessage(void* p) {
    void* m=PPCGetMessage(p);
    if(m)
	printf(ID": got msg %x (%d) at port %x\n",m,PPCGetMessageAttr(m,PPCMSGTAG_MSGID),p);
    else
	printf(ID": got no msg at port %x\n",p);
    return m;
}

#define PPCSendMessage(p,m,d,l,i) \
    (printf(ID": sending msg %x (%d) to port %x\n",m,i,p), \
     PPCSendMessage(p,m,d,l,i))
#define PPCReplyMessage(m) \
    (printf(ID": replying to msg %x\n",m), \
     PPCReplyMessage(m))
#define PPCWaitPort(p) \
    (printf(ID": waiting at port %x\n",p), \
     PPCWaitPort(p))
#define PPCWaitPortList(p) \
    (printf(ID": waiting for ports\n"), \
     PPCWaitPortList(p))
#define PPCGetMessage(p) myPPCGetMessage(p)

#endif


struct StartupData {
    void* port;
    int in;
    int out;
    int err;
    int status;
    int flags;
    int colors;
    int id;
    char gzipcmd[1];
};

struct msg_base {
    int success;
/*#if DEBUGMSG
    char id[40];
#endif*/
};

struct msg_create_output_dev {
    struct msg_base base;
    struct ColorMap* colormap;
    int depth;
};

struct msg_info {
    struct msg_base base;
    int num_pages;
};

struct msg_pagesize {
    struct msg_base base;
    int page;
    int width;
    int height;
};

struct msg_page {
    struct msg_base base;
    int page_num;
    int zoom;
};

struct msg_createdoc {
    struct msg_base base;
    long dir;
    size_t cachesz;
    size_t blocsz;
    char filename[256];
};

struct msg_find {
    struct msg_base base;
    int xmin;
    int xmax;
    int ymin;
    int ymax;
    int top;
    int bottom;
    int page;
    char str[100];
};

struct msg_chklink {
    struct msg_base base;
    int x;
    int y;
    void* action;
    char str[256];
};


struct msg_dolink {
    struct msg_base base;
    int x;
    int y;
    int state;
    int page;
    char str[256];
};

struct msg_write {
    struct msg_base base;
    int first_page;
    int last_page;
    int zoom;
    int rotate;
    int type;
    char filename[256];
};

struct msg_gettext {
    struct msg_base base;
    int xmin;
    int xmax;
    int ymin;
    int ymax;
    int size;
};

struct msg_showfonts {
    struct msg_base base;
    int flag;
};

struct msg_fontmap {
    struct msg_base base;
    char pdffont[128];
    char afont[128];
    int m;
    int style;
    int encoding;
};

struct msg_scan_fonts {
    struct msg_base base;
    int first_page;
    int last_page;
};

union msg_max {
    struct msg_create_output_dev m1;
    struct msg_info m2;
    struct msg_page m3;
    struct msg_createdoc m4;
    struct msg_find m5;
    struct msg_dolink m6;
    struct msg_chklink m7;
    struct msg_write m8;
    struct msg_gettext m9;
    struct msg_showfonts m10;
    struct msg_fontmap m11;
    struct msg_scan_fonts m12;
};

#define MSGID_SYNC            0
#define MSGID_QUIT            1
#define MSGID_GFX             2
#define MSGID_INFO            3
#define MSGID_PAGE            4
#define MSGID_CREATEOUTPUTDEV 5
#define MSGID_DELETEOUTPUTDEV 6
#define MSGID_CREATEDOC       7
#define MSGID_DELETEDOC       8
#define MSGID_FIND            9
#define MSGID_CHKLINK         10
#define MSGID_DOLINK          11
#define MSGID_SIMPLEFIND      12
#define MSGID_WRITE           13
#define MSGID_GFXPIPE         14
#define MSGID_GFXSYNC         15
#define MSGID_GETTEXT         16
#define MSGID_SHOWFONTS       17
#define MSGID_ADDFONTMAP      18
/*#define MSGID_REMFONTMAP      19*/
#define MSGID_CLEARFONTMAP    20
/*#define MSGID_SETFONTMAP      21*/
#define MSGID_SCANFONTS       22
#define MSGID_ENDSCANFONTS    23
#define MSGID_GETFONT         24
#define MSGID_DEFAULTFONTS    25
#define MSGID_PAGESIZE        26
#define MSGID_INITFIND        27
#define MSGID_ENDFIND         28
#define MSGID_INITWRITE       29
#define MSGID_ENDWRITE        30
#define MSGID_INITSCAN        31

#endif


#endif

