/*
* MonitorExch.c
*/
/* from DataExch.c */
#include "Monitor.h"
typedef struct {
unsigned size;
unsigned type;
unsigned data1;
unsigned data2;
} HeaderRec; /* 16 bytes */
typedef struct {
unsigned lastWrittenPacket;
unsigned lastRedPacket;
HeaderRec header;
char (buffer[MSGSIZE]);
} IOZoneRec;
typedef IOZoneRec (*IOZone);
} MonRegistration[32];
IOZone myMonZone = (IOZone) MONBACKDOOR;
IOZone hisMonZone = (IOZone) (MONBACKDOOR+ZONESIZE);
static ClearZones()
{
long i, *p, *start, lengh;
start = (long *) myMonZone;
lengh = ZONESIZE/2; /* ZONESIZE is in bytes */
p = start;
for (i = lengh; i != 0; i--) {
*p = 0;
p++;
}
}
static void Pause(ms)
unsigned ms;
{
unsigned i, dummy;
dummy = 0;
for (i = ms; i != 0; i--) {
dummy = dummy+1;
}
};
static void CopyTo(from, start, len, to)
char *from;
unsigned start;
unsigned len;
char *to;
{
char *p1, *p2, *p3;
if (len==0) return;
p1 = from+start;
p2 = p1+len;
while (p1<p2) *to++ =*p1++;
}
static void CopyFrom(to, start, len, from)
char *to;
unsigned start;
unsigned len;
char *from;
{
char *p1, *p2, *p3;
if (len==0) return;
p1 = to+start;
p2 = p2+len;
while ( p1<p2) *p1++ =*from++;
}
void MonPutPacket(type, data1, data2, r, len)
unsigned type;
unsigned data1;
unsigned data2;
char *r;
unsigned len;
{
unsigned h;
unsigned myLastWrittenPacket;
h = myMonZone->lastWrittenPacket;
while (h > hisMonZone->lastRedPacket) Pause(outputWaitingTime);
myMonZone->header.size = len;
myMonZone->header.type = type;
myMonZone->header.data1 = data1;
myMonZone->header.data2 = data2;
if (len > 0) (void) CopyTo(r, 0, len, myMonZone->buffer);
myMonZone->lastWrittenPacket = h+1;
}
void MonWatchPacketsIn()
{
ActionProc *aProc;
HeaderRec hVal;
while (1) {
while (hisMonZone->lastWrittenPacket==myMonZone->lastRedPacket) Pause(inputWaitingTime);
hVal = hisMonZone->header;
if (hVal.type==QUIT) {myMonZone->lastRedPacket = hisMonZone->lastWrittenPacket; return;};
aProc = MonRegistration[hVal.type].a;
(*aProc)(hisMonZone->buffer, hVal.size, hVal.type, hVal.data1, hVal.data2);
myMonZone->lastRedPacket = hisMonZone->lastWrittenPacket;
};
}