1: /* $Header: packet.c,v 10.3 86/02/01 15:47:08 tony Rel $ */
   2: /* packet.c	Routines to allocate, free, and use packets
   3:  *
   4:  *	OpenDisplay		Open it
   5:  *	InitDisplay		Download it
   6:  *	DisplayDead		Check if dead
   7:  *	PacketInit		Set things up
   8:  *	WritePacket		Buffers a packet for writing
   9:  *	SynchWrites		Wait for completion of all pending writes
  10:  *	AllocateSpace		Allocate some temporary storage
  11:  *	AllocateCopy		Copy data to temporary storage
  12:  *	DeallocateSpace		Flush space of unsent packet
  13:  *
  14:  */
  15: 
  16: /****************************************************************************
  17:  *									    *
  18:  *  Copyright (c) 1983, 1984 by						    *
  19:  *  DIGITAL EQUIPMENT CORPORATION, Maynard, Massachusetts.		    *
  20:  *  All rights reserved.						    *
  21:  * 									    *
  22:  *  This software is furnished on an as-is basis and may be used and copied *
  23:  *  only with inclusion of the above copyright notice. This software or any *
  24:  *  other copies thereof may be provided or otherwise made available to     *
  25:  *  others only for non-commercial purposes.  No title to or ownership of   *
  26:  *  the software is hereby transferred.					    *
  27:  * 									    *
  28:  *  The information in this software is  subject to change without notice   *
  29:  *  and  should  not  be  construed as  a commitment by DIGITAL EQUIPMENT   *
  30:  *  CORPORATION.							    *
  31:  * 									    *
  32:  *  DIGITAL assumes no responsibility for the use  or  reliability of its   *
  33:  *  software on equipment which is not supplied by DIGITAL.		    *
  34:  * 									    *
  35:  *									    *
  36:  ****************************************************************************/
  37: 
  38: #include "vs100.h"
  39: #include <fcntl.h>
  40: #include <errno.h>
  41: #include <sys/ioctl.h>
  42: #include "vsioctl.h"
  43: #include <vaxuba/vsreg.h>
  44: #include "reason.h"
  45: 
  46: extern int errno;
  47: extern BitMap screen;
  48: 
  49: char *ErrorString(), *strcpy(), *strcat();
  50: 
  51: int vsdev;
  52: 
  53: int VSReloc;
  54: 
  55: vsIoAddr *VSAddr;
  56: caddr_t VSBuf;
  57: int VSBuflen;
  58: caddr_t VSBufLim;
  59: short *IOReg;
  60: short *VSResponse;
  61: 
  62: int active;
  63: int upper;
  64: caddr_t limptr, curptr;
  65: 
  66: /* Open the display */
  67: 
  68: OpenDisplay (vsNumber)
  69:     char *vsNumber;
  70: {
  71:     char vsname[10];
  72:     strcpy (vsname, "/dev/vs");
  73:     strcat (vsname, vsNumber);
  74: 
  75:     return (vsdev = open (vsname, O_RDWR|O_NDELAY));
  76: }
  77: 
  78: /* Do vs100 specific initialization */
  79: 
  80: InitDisplay (info)
  81:     register DEVICE *info;
  82: {
  83:     if (DownLoad ())
  84:         return (-1);
  85:     info->id = XDEV_VS100;
  86:     info->width = screen.bm_width;
  87:     info->height = screen.bm_height;
  88:     info->planes = 1;
  89:     info->entries = 0;
  90:     info->mouse = &VSAddr->mouse;
  91:     info->mbox = &VSAddr->mbox;
  92:     info->queue = (vsEventQueue *) &VSAddr->ibuff;
  93:     return (0);
  94: }
  95: 
  96: /* Check if display is dead */
  97: 
  98: DisplayDead ()
  99: {
 100:     int ver;
 101: 
 102:     return(ioctl(vsdev, (int) VSIOGETVER, (caddr_t) &ver));
 103: }
 104: 
 105: PacketInit()
 106: {
 107:     if (ioctl (vsdev, (int) VSIOGETIOA, (caddr_t) &VSAddr) ||
 108:         ioctl (vsdev, (int) VSIOINIT, (caddr_t) NULL))
 109:         return (-1);
 110:     VSBuf = VSAddr->obuff;
 111:     VSBuflen = VSAddr->obufflen;
 112:     VSBufLim = VSBuf + VSBuflen;
 113:     IOReg = (short *) VSAddr->ioreg;
 114:     VSReloc = VSAddr->reloc - (int) VSBuf;
 115:     VSResponse = (short *) &VSAddr->status;
 116:         *VSResponse = 0;
 117:     IOReg[0] &= ~VS_FCN;
 118:     active = 0;
 119:     curptr = VSBufLim;
 120:     limptr = VSBuf;
 121:     upper = 1;
 122:     return (0);
 123: }
 124: 
 125: WritePacket (pkt)
 126:     caddr_t pkt;
 127: {
 128:     register int ret;
 129:     register short *ioreg;
 130: 
 131:     pkt += VSReloc;
 132:     limptr = curptr;
 133:     if (upper) {
 134:         curptr = VSBuf;
 135:         upper = 0;
 136:     } else {
 137:         curptr = VSBufLim;
 138:         upper = 1;
 139:     }
 140:     if (ret = active) {
 141:         if (!(*VSResponse)) {
 142:         if (ret = ioctl(vsdev, (int) VSIOWAITGO, (caddr_t) &pkt))
 143:             VSError ();
 144:         return (ret);
 145:         }
 146:         if ((ret = *VSResponse) & VS_ERROR) {
 147:         errno = ret & VS_REASON + INT_ERR;
 148:         VSError ();
 149:         ret = -1;
 150:         } else
 151:         ret = 0;
 152:     }
 153:     ioreg = IOReg;  /* C sucks */
 154:     ioreg[3] = ((short *)&pkt)[0];
 155:     ioreg[4] = ((short *)&pkt)[1];
 156:     ioreg[0] &= ~VS_FCN;
 157:     *VSResponse = 0;
 158:     ioreg[0] |= VS_IE | (VS_SEND << VS_FCSHIFT) | VS_GO;
 159:     active = 1;
 160:     return (ret);
 161: }
 162: 
 163: SynchWrites ()
 164: {
 165:     register int ret;
 166: 
 167:     if (!active) return (0);
 168:     if (!(*VSResponse) && ioctl(vsdev, (int) VSIOUSERWAIT, (caddr_t) NULL))
 169:         VSError ();
 170:     if ((ret = *VSResponse) & VS_ERROR) {
 171:         errno = ret & VS_REASON + INT_ERR;
 172:         VSError ();
 173:         ret = -1;
 174:     } else
 175:         ret = 0;
 176:     *VSResponse = 0;
 177:     active = 0;
 178:     if (upper)
 179:         limptr = VSBuf;
 180:     else
 181:         limptr = VSBufLim;
 182:     return (ret);
 183: }
 184: 
 185: caddr_t AllocateSpace (size)
 186:     register int size;
 187: {
 188:     register caddr_t ptr;
 189: 
 190:     if (size & 1) size++;
 191: 
 192:     if (upper) {
 193:         if ((curptr -= size) >= limptr)
 194:         return (curptr);
 195:         SynchWrites ();
 196:         if (curptr >= limptr)
 197:         return (curptr);
 198:         curptr = VSBufLim;
 199:     } else {
 200:         ptr = curptr;
 201:         if ((curptr += size) <= limptr)
 202:         return (ptr);
 203:         SynchWrites ();
 204:         if (curptr <= limptr)
 205:         return (ptr);
 206:         curptr = VSBuf;
 207:     }
 208:     errno = ENOMEM;
 209:     VSError ();
 210:     return (NULL);
 211: }
 212: 
 213: caddr_t AllocateCopy (buf, size)
 214:     caddr_t buf;
 215:     register int size;
 216: {
 217:     register caddr_t ptr;
 218: 
 219:     if (size & 1) size++;
 220: 
 221:     if (upper) {
 222:         if ((curptr -= size) < limptr) {
 223:         SynchWrites ();
 224:         if (curptr < limptr) {
 225:             curptr = VSBufLim;
 226:             errno = ENOMEM;
 227:             return (NULL);
 228:         }
 229:         }
 230:         ptr = curptr;
 231:     } else {
 232:         ptr = curptr;
 233:         if ((curptr += size) > limptr) {
 234:         SynchWrites ();
 235:         if (curptr > limptr) {
 236:             curptr = VSBuf;
 237:             errno = ENOMEM;
 238:             VSError ();
 239:             return (NULL);
 240:         }
 241:         }
 242:     }
 243:     bcopy (buf, ptr, size);
 244:     return (ptr);
 245: }
 246: 
 247: DeallocateSpace ()
 248: {
 249:     if (upper)
 250:         curptr = VSBufLim;
 251:     else
 252:         curptr = VSBuf;
 253: }
 254: 
 255: VSError ()
 256: {
 257:     DeviceError (ErrorString (errno));
 258: }

Defined functions

DisplayDead defined in line 98; never used
InitDisplay defined in line 80; never used
OpenDisplay defined in line 68; never used
PacketInit defined in line 105; used 1 times
VSError defined in line 255; used 7 times

Defined variables

IOReg defined in line 59; used 3 times
VSAddr defined in line 55; used 9 times
VSBuflen defined in line 57; used 2 times
VSResponse defined in line 60; used 8 times
active defined in line 62; used 5 times
upper defined in line 63; used 8 times
vsdev defined in line 51; used 9 times
Last modified: 1986-02-01
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1477
Valid CSS Valid XHTML 1.0 Strict