int _SP,_BP;
/**********************************************************
kern.c
v. 1.0 10/jul/93
you may need change sizeofpoint (now 30)
SIZEST (now 40)
15/jul/93 – front of queue wasn’t going around +++01
*/
#include <alloc.h>
#include <mem.h>
#include <kern.h>
#include <stdio.h>
#include <stdlib.h>
extern int _ScanTodVector; /* from here global variables */
/* are stored */
#define point ((&_ScanTodVector)+3) /* inspect *.map file */
#define sizeofpoint 30 /* size of point data */
#define SIZEST 40 /* size of stack (ant) data */
#define SAVE ant.sp= (void*)_SP; ant.bp= _BP; memmove(ant.stack,ant.sp,SIZEST);
#define RESTORE _SP= (int)ant.sp; _BP= ant.bp; memmove(ant.sp,ant.stack,SIZEST);
typedef struct {
int p;
int bp;
void *sp;
int stack[SIZEST];
} antstr;
static antstr ant;
static antstr antqueue [MAXSPACE];
static antstr *front = antqueue;
static antstr *back = antqueue;
static void *space[MAXSPACE];
static int flag= 0;
static int s;
int currentpoint= 0;
static void enqueue(void);
static void dequeue(void);
void tx(int r) /* expansion from current point p */
{ /* to points p and p+r */
SAVE;
s= 0; enqueue();
s= r; enqueue();
dequeue();
RESTORE;
}
void o(void) /* quit */
{
SAVE;
if (front == back) exit(0);
if (space[currentpoint]== NULL) space[currentpoint]= malloc(sizeofpoint);
memmove (space[currentpoint],point,sizeofpoint);
dequeue ();
RESTORE;
}
void t(int r) /* transfer */
{
SAVE;
s= r; enqueue (); dequeue ();
RESTORE;
}
void enqueue (void)
{
int i;
if (flag == 0) {
for (i= 0; i< MAXSPACE; space[i]= NULL,i++);
flag= 1;
}
if (space[currentpoint]== NULL)
space[currentpoint]= malloc(sizeofpoint);
memmove (space[currentpoint],point,sizeofpoint);
currentpoint= currentpoint ^ s;
if (space[currentpoint]== NULL)
space[currentpoint]= malloc(sizeofpoint);
ant.p = currentpoint;
memmove (back,&ant,sizeof(ant));
if (back == & antqueue [MAXSPACE-1] )
back = antqueue;
else
back++;
}
void dequeue (void)
{
memmove (&ant,front,sizeof(ant));
if (front== &antqueue[MAXSPACE-1]) /* +++01 */
front= antqueue; /* +++01 */
else /* +++01 */
front++;
currentpoint= ant.p;
memmove (point,space[currentpoint],sizeofpoint);
}