#include #include #include #include #define EOF -1 #define GRAPHICS_OLDREV 29 #define INTUITION_OLDREV 29 #define GRAPHICS_REV 33 #define INTUITION_REV 33 #define INTUITION_OPEN 1 #define GRAPHICS_OPEN INTUITION_OPEN << 1 #define WINDOW_OPEN GRAPHICS_OPEN << 1 #define TMPRAS_OPEN WINDOW_OPEN << 1 #define READPORT_OPEN TMPRAS_OPEN << 1 #define CONREADER_OPEN READPORT_OPEN << 1 #define CONDEVICE_OPEN CONREADER_OPEN << 1 #define RP mywindow->RPort /* make life easy, since I use it a lot */ void myexit(), mysetup(), myprintf(), queueread(); int mygetc(), myscanf(); char *mygets(); extern struct IntuitionBase *IntuitionBase; struct GfxBase *GfxBase; static struct IOStdReq *conreader, conrequest; static struct MsgPort *conreadport; struct Window *mywindow; static struct TmpRas TRas; static PLANEPTR TBuf; extern char WindowTitle[]; extern char FillFlag; static char buff[513]; static char conchar; static int myflags; char FillFlag; /* whether or not to fill graphic objects */ static char Color; /* drawing/filling color */ static char OldFlag; /* using graphics.library before 1.2 */ static struct NewWindow NewWindow = { 0,1,640,199,-1,-1, /* left, top, width, height, detail, block pen */ CLOSEWINDOW, WINDOWDEPTH | WINDOWDRAG | ACTIVATE, NULL, NULL, WindowTitle, NULL, NULL, 0, 0, 0, 0, /* Min & Max size don't matter with no size gadget */ WBENCHSCREEN }; /* initialize the window so we can read and write to it */ void mysetup() { OldFlag = 0; if ((IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", INTUITION_REV)) == NULL) { if ((IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", INTUITION_OLDREV)) == NULL) myexit(1); else OldFlag = 1; } myflags |= INTUITION_OPEN; if (OldFlag) { if ((GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", GRAPHICS_OLDREV)) == NULL) myexit(2); } else { if ((GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", GRAPHICS_REV)) == NULL) myexit(2); } myflags |= GRAPHICS_OPEN; if ((mywindow = (struct Window *)OpenWindow(&NewWindow)) == NULL) myexit(3); myflags |= WINDOW_OPEN; /* create a TmpRas so we can do FloodFill calls */ if ((TBuf = (PLANEPTR)AllocRaster(640,200)) == NULL) myexit(4); RP->TmpRas = (struct TmpRas *)InitTmpRas(&TRas,TBuf,RASSIZE(640,200)); myflags |= TMPRAS_OPEN; /* create a port to receive messages about completed operations */ if ((conreadport = CreatePort("my.con.read", 0)) == NULL) myexit(5); myflags |= READPORT_OPEN; /* construct a request for that port */ if ((conreader = CreateStdIO(conreadport)) == NULL) myexit(6); myflags |= CONREADER_OPEN; conreader->io_Data = (APTR)mywindow; conreader->io_Length = sizeof(*mywindow); if (OpenDevice("console.device", 0, conreader, 0) != 0) myexit(7); myflags |= CONDEVICE_OPEN; /* copy so we have a read request structure */ conrequest.io_Device = conreader->io_Device; conrequest.io_Unit = conreader->io_Unit; queueread(); } void myputc(c) /* write a single character to our window */ char c; { if (mywindow == NULL) mysetup(); conrequest.io_Command = CMD_WRITE; conrequest.io_Data = (APTR)&c; conrequest.io_Length = 1; DoIO(&conrequest); } void queueread() { conreader->io_Command = CMD_READ; conreader->io_Data = &conchar; conreader->io_Length = 1; SendIO(conreader); } int mygetc() { struct IntuiMessage *GetMsg(); char c = 0; if (mywindow == NULL) mysetup(); /* if there hasn't been a response to the last read request, wait for it */ while((GetMsg(conreadport) == NULL)) WaitPort(conreadport); /* get what the response character was */ c = conchar; /* and queue up for another one */ queueread(); return((c == 0x1c) ? EOF : c); } char *mygets() { static char DELCHR[] = "\b \b"; /* String to DELete a CHaRacter */ register char inchar; register int i,j; register int count = 0; register int ScrCount; int LnCount, MaxLnCount = 0; int InitCount = 0; if (mywindow == NULL) mysetup(); myprintf("\x9b6n"); /* 6n - get current cursor pos */ while (mygetc() != ';'); /* returned as "row;columnR" */ /* row & column returned as ASCII */ while ((inchar = mygetc()) != 'R') InitCount = (InitCount * 10) + (inchar - '0'); LnCount = ScrCount = InitCount; myprintf("\x9b q"); /* q - window status request */ for (i=0;i<3;i++) /* returns window bounds in printable */ while (mygetc() != ';'); /* characters, format: */ /* top line,first char,bottom line,last charr */ while ((inchar = mygetc()) != ' ') MaxLnCount = (MaxLnCount * 10) + (inchar - '0'); mygetc(); /* throw away the 'r' */ buff[0] = NULL; do { switch (inchar = mygetc()) { case '\b' : /* Backspace handling */ if (count == 0) break; if (buff[--count] == '\t') { i = buff[--count]; ScrCount -= i; LnCount = ((LnCount - i) >= 0) ? (MaxLnCount - i) : (LnCount - i); for(j=i;j>0;j--) myprintf("%s",DELCHR); } else { ScrCount--; LnCount = ((LnCount - 1) >= 0) ? MaxLnCount : 0; myprintf("%s", DELCHR); /* Got to use myprintf to avoid newline */ } break; case '\t' : /* tab character */ if (count < 256) { i = 9-(LnCount%8); if ((LnCount + i) > MaxLnCount) { i = MaxLnCount - LnCount + 1; LnCount = 1; } else LnCount += i; ScrCount += i; buff[count++] = i; buff[count++] = '\t'; for(j=0;j InitCount; ScrCount--) myprintf("%s", DELCHR); myprintf("\x9b p"); /* turn cursor on */ count = 0; LnCount = InitCount; buff[0] = NULL; break; default : if ((count < 256) && (inchar > 31)) { myputc(inchar); ScrCount++; LnCount = ((LnCount + 1) > MaxLnCount) ? 0 : (LnCount + 1); buff[count++] = inchar; } } } while (inchar != '\r'); buff[count] = '\0'; for(i=count-1;i>0;i--) if(buff[i] == '\t') { for(j=i-1;j= 0) { WritePixel(RP,cx+dx,cy-(dy/2)); WritePixel(RP,cx+dy,cy+(dx/2)); WritePixel(RP,cx-dx,cy+(dy/2)); WritePixel(RP,cx-dy,cy-(dx/2)); if (change <= 0) { delta = 2*change+2*dy-1; dx++; change = change+2*dx+1; if (delta > 0) { dy--; change = change-2*dy+1; } } else { delta = 2*change-2*dx-1; dy--; change = change-2*dy+1; if (delta <= 0) { dx++; change = change+2*dx+1; } } } } if (FillFlag) Fill(cx,cy,c); else { if (FillFlag) AreaEllipse(RP,cx,cy,r,r/2); else DrawEllipse(RP,cx,cy,r,r/2); } } Box(tlx,tly,brx,bry,c) /* draw a box with top left corner at (tlx,tly) */ int tlx,tly,brx,bry; /* and bottom right corner at (brx,bry) */ char c; { if(c != Color) SetAPen(RP,(Color = c)); if (FillFlag) { RectFill(RP,tlx,tly,brx,bry); } else { Move(RP,tlx,tly); Draw(RP,tlx,bry); Draw(RP,brx,bry); Draw(RP,brx,tly); Draw(RP,tlx,tly); } } Fill(x,y,c) /* flood fill an area with (x,y) as the center */ SHORT x,y; char c; { if(c != Color) SetAPen(RP,(Color = c)); Flood(RP,1,x,y); } PSet(x,y,c) /* set point at (x,y) */ int x,y; char c; { if(c != Color) SetAPen(RP,(Color = c)); WritePixel(RP,x,y); } PReset(x,y) /* reset a point at (x,y) to background color */ int x,y; { SetAPen(RP,0); WritePixel(RP,x,y); Color = 0; }