|
|
1.1 root 1: /* D.L.Buck and Associates, Inc. - May, 1984
2: *
3: * COPYRIGHT NOTICE:
4: * Copyright c 1984 - An unpublished work by
5: * D.L.Buck and Associates, Inc.
6: *
7: * PROPRIETARY RIGHTS NOTICE:
8: * All rights reserved. This document and program contains
9: * proprietary information of D.L.Buck and Associates,Inc.
10: * of San Jose, California, U.S.A., embodying confidential
11: * information, ideas, and expressions, no part of which
12: * may be reproduced, or transmitted in any form or by any
13: * means, electronic, mechanical, or otherwise, without
14: * the written permission of D.L.Buck and Associates, Inc.
15: *
16: * NAME
17: * emprocbuf
18: * SYNOPSIS
19: * emprocbuf(buf,count)
20: * char *buf; address of received buffer
21: * register int count; number of characters in buffer
22: * DESCRIPTION
23: * The received buffer should have the format of a received
24: * 3277-style buffer, and contain commands, orders, and
25: * buffer data for the 3277 screen. This routine processes
26: * the commands, orders, and buffer data, creating or updating
27: * the information in the external variables mentioned in
28: * em.h which comprise the virtual 3277 screen.
29: */
30: static char s_emproc[] = "@(#)emprocbuf.c 1.14 REL";
31:
32: #include <em.h>
33: #include <ctype.h>
34: #define NUL '\0'
35:
36: #define CMDPRE 033 /* Indicates command code follows */
37: /* command codes: (Ascii) */
38: #define EWRITE '5' /* Erase/Write */
39: #define WRITE '1' /* Write */
40: #define COPY '7' /* Copy (3271 only) */
41: #define EAU '?' /* Erase All Unprotected */
42: #define RDBUF '2' /* Read Buffer */
43: #define RDMOD '6' /* Read Modified */
44:
45: /* WRITE and EWRITE are followed by a WCC ... */
46: char wcc;
47:
48: /* Order Definitions: Name: Followed by: */
49: #define SF 0x1d /* Start Field Attr. char */
50: #define SBA 0x11 /* Set Buffer Address 2-byte addr. */
51: #define IC 0x13 /* Insert Cursor (nothing) */
52: #define PT 0x09 /* Program Tab (nothing) */
53: #define RA 0x14 /* Repeat to Addr. 2-byte addr. */
54: #define EUA 0x12 /* Erase Unprot. to Addr. 2-byte addr. */
55:
56: #define DATA 1000 /* last thing was data */
57: #define FUNNYPT 1001 /* last thing was PT that wrapped */
58:
59: extern char aid_val;
60: extern int lastkey; /* last AID key entered */
61:
62: emprocbuf(buf,count)
63: register char *buf; /* address of received buffer */
64: register int count; /* number of characters it contains */
65: {
66: extern int SG; /* # blanks left by SO or SE */
67: extern int ascii; /* ascii or ebcdic code flag */
68: extern char aadr_tbl[]; /* ascii hex cursor address encoding table */
69: extern char eadr_tbl[]; /* ebcdic hex cursor address encoding table */
70: extern char *index();
71: extern char *SO; /* Standout sequence */
72: static int ncarry; /* number of characters carried over */
73: static char carrybuf[5];/* carried over characters */
74: static char lastthing; /* last thing we did */
75: register char *p; /* work pointer */
76: register int *ip; /* work pointer */
77: char newchar;
78: char clearflag;
79: int newbufaddr;
80: char *tr_tbl; /* ascii or ebcdic address transl. tbl */
81: long upf;
82:
83: tr_tbl = ascii?aadr_tbl:eadr_tbl;
84: unfiximage(); /* Convert screen image to work mode */
85: while (ncarry) { /* if chars were left over from last block, */
86: *--buf = carrybuf[--ncarry]; /* prefix them to given block */
87: ++count;
88: }
89:
90: while (--count >= 0) /* for all characters in buffer, */
91: {
92: if (!ascii) /* translate to ascii if necessary */
93: ebcasc(buf,1);
94: switch (*buf) {
95: case CMDPRE: /* start of command */
96: fiximage(0);
97: unfiximage();
98: if (count < 1) {
99: ncarry = 1; /* save ESC */
100: goto abort;
101: }
102: ++buf; --count; /* next is command code */
103: if (!ascii) /* deal with ascii only */
104: ebcasc(buf,1);
105: lastthing = *buf; /* this is a command */
106: switch (*buf) {
107: case EWRITE: /* erase screen, then write */
108: cursaddr = 0; /* clear screen variables */
109: bufaddr = 0;
110: curfield = 0;
111: totfields = 0;
112: for (p = scrn_image;
113: p < &scrn_image[MAXSCREENSIZE];
114: *p++ = NUL) ;
115: for (ip = scrn_xref;
116: ip < &scrn_xref[MAXSCREENSIZE];
117: *ip++ = 0) ;
118: wmove(vterm_scr,0,0);
119: werase(vterm_scr);
120: wrefresh(vterm_scr);
121:
122: /* reset aid value and last aid key hit */
123: aid_val = ascii?0x2d:0x60;
124: lastkey = 0;
125: case WRITE:
126: updstat (status | SYS_AVAIL);
127: if (count < 1) { /* need wcc, too */
128: ncarry = 2; /* save ESC, cmd */
129: goto abort;
130: }
131: ++buf; --count;
132: wcc = *buf; /* save wcc */
133: if (ascii)
134: wcc = eadr_tbl[index(aadr_tbl,wcc)-
135: aadr_tbl];
136: /* reset MDT bits; they were saved in scrn_xref */
137: if (wcc & WCCMDTRST)
138: for (ip=scrn_xref;
139: ip<&scrn_xref[MAXSCREENSIZE];
140: ++ip)
141: *ip &= ~ATTRMDT;
142: if (lastthing == 0 || lastthing == COPY ||
143: lastthing == EAU)
144: bufaddr = cursaddr;
145: break;
146: case EAU: /* erase all unprotected */
147: updstat (status | SYS_AVAIL);
148: lastthing = EAU;
149:
150: /*++buf; --count;*/
151: /* erase unprotected positions 0 to
152: MAXSCREENSIZE-1 and reset the MDT bit */
153: upf = eua(0, 0, 1);
154: if (upf) {
155: bufaddr = cursaddr = fldstart[upf];
156: }
157: else { bufaddr = cursaddr = 0; }
158: /* Enable keyboard */
159: updstat ((status | SYS_AVAIL) & ~INPUT_INH);
160: /* reset the aid value */
161: aid_val = ascii?0x2d:0x60;
162: lastkey = 0;
163: break;
164: case COPY: /* UNSUPPORTED */
165: if (count < 1) {
166: ncarry = 2;
167: goto abort;
168: }
169: ++buf; --count;
170: lastthing = COPY;
171: updstat (status | SYS_AVAIL);
172: break;
173: }
174: break;
175: case SF: /* Start Field - followed by attr. char. */
176: if (count < 1) { /* need 1-char attr. */
177: ncarry = 1; /* carry SF forward */
178: goto abort;
179: }
180: lastthing = SF;
181: ++buf; --count;
182: scrn_image[bufaddr] = ATTRCODE; /* mark screen image */
183: newchar = *buf;
184: if (ascii)
185: newchar = eadr_tbl[index(aadr_tbl,newchar)-
186: aadr_tbl];
187: scrn_xref[bufaddr] = newchar;
188: ++bufaddr;
189: if (bufaddr >= MAXSCREENSIZE)
190: bufaddr = 0;
191: break;
192:
193: case SBA: /* Set Buffer Address - followed by addr */
194: if (count < 2) { /* need 2-char addr */
195: ncarry = 1;
196: goto abort;
197: }
198: lastthing = SBA;
199: newbufaddr = ((index(tr_tbl,buf[1])-tr_tbl) << 6) |
200: (index(tr_tbl,buf[2])-tr_tbl);
201: buf += 2;
202: count -= 2;
203: if (newbufaddr < 0 || newbufaddr >= MAXSCREENSIZE)
204: break;
205: bufaddr = newbufaddr;
206: break;
207:
208: case IC: /* Set Cursor Address */
209: lastthing = IC;
210: cursaddr = bufaddr;
211: break;
212:
213: case PT: /* Program Tab */
214: if (!totfields) {
215: bufaddr = 0;
216: break;
217: }
218: clearflag = (lastthing == 0 || lastthing == DATA ||
219: lastthing == FUNNYPT);
220: lastthing = FUNNYPT;
221: /*** while (bufaddr < MAXSCREENSIZE) { ***/
222: for(;;) { /* scan till hit a field */
223: if (scrn_image[bufaddr] == ATTRCODE) {
224: clearflag = 0;
225: if (!(prot_attr(scrn_xref[bufaddr]))) {
226: ++bufaddr;
227: lastthing = PT;
228: break;
229: }
230: } else if (clearflag)
231: scrn_image[bufaddr] = '\0';
232: /*** ++bufaddr; ***/
233: if (++bufaddr >= MAXSCREENSIZE)
234: bufaddr = 0;
235: /*++bufaddr;*/
236: }
237: if (bufaddr >= MAXSCREENSIZE)
238: bufaddr = 0;
239: break;
240:
241: case RA: /* Repeat to Address - followed by addr */
242: if (count < 3) { /* need 2-byte addr, char */
243: ncarry = 1;
244: goto abort;
245: }
246: lastthing = RA;
247: newbufaddr = ((index(tr_tbl,buf[1])-tr_tbl) << 6) |
248: (index(tr_tbl,buf[2])-tr_tbl);
249: newchar = buf[3]; /* char to be repeated */
250: if (!ascii)
251: ebcasc(&newchar,1);
252: buf += 3;
253: count -= 3;
254: if (newbufaddr < 0 || newbufaddr >= MAXSCREENSIZE)
255: break;
256: do {
257: scrn_image[bufaddr] = newchar;
258: if (++bufaddr >= MAXSCREENSIZE)
259: bufaddr = 0;
260: } while (bufaddr != newbufaddr);
261: break;
262:
263: case EUA: /* erase unprotected to (following) addr */
264: if (count < 2) { /* need 2-char addr */
265: ncarry = 1;
266: goto abort;
267: }
268: lastthing = EUA;
269: newbufaddr = ((index(tr_tbl,buf[1])-tr_tbl) << 6) |
270: (index(tr_tbl,buf[2])-tr_tbl);
271: buf += 2;
272: count -= 2;
273: if (newbufaddr < 0 || newbufaddr >= MAXSCREENSIZE)
274: break;
275: eua(bufaddr, newbufaddr, 0);
276: bufaddr = newbufaddr;
277: break;
278:
279: default:
280: lastthing = DATA;
281: scrn_image[bufaddr] = *buf;
282: if (++bufaddr >= MAXSCREENSIZE)
283: bufaddr = 0;
284: break;
285: }
286: ++buf;
287: }
288: fiximage(1);
289: return;
290:
291: abort: /* ncarry characters need to be saved in carrybuf */
292: buf -= ncarry;
293: strncpy(carrybuf,buf,ncarry+count);
294: if (!ascii)
295: ascebc(carrybuf,ncarry+count);
296: }
297:
298: /*
299: * NAME
300: * fiximage
301: * SYNOPSIS
302: * fiximage(do_all)
303: * int do_all; update screen image or not
304: * DESCRIPTION
305: * Fix up all screen image data structures based on current
306: * copy of scrn_image and scrn_xref.
307: * ALGORITHM
308: * Examine scrn_image and scrn_xref; build correct values
309: * for: totfields
310: * fldstart
311: * fldmax
312: * fldattr
313: * Examine cursaddr; build correct value for: curfield
314: *
315: * When an ATTRCODE is found, start a new field:
316: * 1) Incr. totfields
317: * 2) Set fldstart
318: * 3) Copy fldattr from scrn_xref
319: * 4) if do_screen, move to starting location,
320: * set/clear highlight mode.
321: *
322: * For a character:
323: * 1) Incr. fldmax
324: * 2) If do_screen, update screen image
325: * 3) assign current field # to scrn_xref
326: */
327: #include "local.h"
328: #include <bsc/bscio.h>
329: int unprotected; /* number of unprotected fields on the screen */
330:
331: extern int ascii;
332: extern int pt_to_pt;
333: extern int stationid;
334: extern int devfd;
335: extern int tb_ctr;
336:
337: extern char termid;
338: extern struct bscio gp;
339:
340: /* printer status messages */
341: #define STX 0x02
342:
343: /* device busy message */
344: char adbsptpt[] = {'%','R',STX,0x48,' '}; /* ascii, point to point */
345: char edbsptpt[] = {0x6c,0xd9,STX,0xc8,0x40}; /* ebcdic, point to point */
346: char adbsmpt[] = {'%','R',STX,0,0,0x48,' '}; /* ascii, multipoint */
347: char edbsmpt[] = {0x6c,0xd9,STX,0,0,0xc8,0x40}; /* ebcdic, multipoint */
348:
349: /* device end message */
350: char ascsptpt[] = {'%','R',STX,'B',' '}; /* ascii, point to point */
351: char ebcsptpt[] = {0x6c,0xd9,STX,0xc2,0x40}; /* ebcdic, point to point */
352: char ascsmpt[] = {'%','R',STX,0,0,'B',' '}; /* ascii, multipoint */
353: char ebcsmpt[] = {0x6c,0xd9,STX,0,0,0xc2,0x40}; /* ebcdic, multipoint */
354:
355: extern int controller; /* 3271 or 3275 control unit */
356:
357: fiximage(do_all)
358: int do_all;
359: {
360: register int i, cf;
361: register char *sp;
362: register int count;
363:
364: cf = -1;
365: totfields = 0;
366: unprotected = 0;
367: fldstart[0] = 0;
368: fldattr[0] = 0;
369: fldmax[0] = 0;
370:
371: for (sp = scrn_image; sp<&scrn_image[MAXSCREENSIZE]; ++sp)
372: if (*sp == (char)ATTRCODE)
373: break;
374: if (sp >= &scrn_image[MAXSCREENSIZE]) {
375: sp = scrn_image;
376: cf = 0;
377: }
378: for (i=sp-scrn_image,count=0;count<MAXSCREENSIZE;++count,++i,++sp) {
379: if (i>= MAXSCREENSIZE) {
380: i = 0;
381: sp = scrn_image;
382: }
383: /* attribute char. or end of screen */
384: if (*sp==(char)ATTRCODE) {
385: ++cf;
386: ++totfields;
387: fldstart[cf] = (i >= MAXSCREENSIZE-1)? 0 : i+1;
388: fldattr[cf] = scrn_xref[i];
389: if (!prot_attr(fldattr[cf]))
390: ++unprotected;
391: fldmax[cf] = 0;
392: if (do_all && do_screen) {
393: wmove(vterm_scr,i/SCREENWIDTH,
394: i%SCREENWIDTH);
395: if (hl_attr(fldattr[cf]))
396: wstandout(vterm_scr);
397: else wstandend(vterm_scr);
398: if ((SG == 0 || SO == (char *)0) &&
399: i<MAXSCREENSIZE-1)
400: mvwaddch(vterm_scr,
401: i/SCREENWIDTH,
402: i%SCREENWIDTH,' ');
403: }
404: } else { /* data character */
405: ++fldmax[cf];
406: if (do_all && do_screen &&
407: sp < &scrn_image[MAXSCREENSIZE])
408: if (*sp && !invis_attr(fldattr[cf]))
409: mvwaddch(vterm_scr,i/SCREENWIDTH,
410: i%SCREENWIDTH,*sp);
411: else
412: mvwaddch(vterm_scr,i/SCREENWIDTH,
413: i%SCREENWIDTH,' ');
414: }
415: scrn_xref[i] = cf;
416: }
417: curfield = scrn_xref[cursaddr];
418:
419: if (!do_all) return;
420: if (do_screen) {
421: wmove(vterm_scr,ROW,COL);
422: wrefresh(vterm_scr);
423: if (walarm(wcc))
424: write (1, "\007",1); /* send alarm */
425: }
426: if (stprt(wcc) && controller == 3275) {
427: /* send device busy status */
428: #ifndef DEBUG
429: ioctl(devfd,BSCSOH,0); /* set SOH mode */
430: ioctl(devfd,BSCLAST,0); /* set LAST message flag */
431: if (pt_to_pt == BSCMPT) {
432: ioctl (devfd, BSCID, &stationid);
433: if (ascii) {
434: adbsmpt[3] = termid; /* poll addr */
435: adbsmpt[4] = stationid; /* subdev addr */
436: i = write(devfd, adbsmpt, sizeof adbsmpt);
437: } else {
438: edbsmpt[3] = termid; /* poll addr */
439: edbsmpt[4] = stationid; /* subdev addr */
440: i = write(devfd, edbsmpt, sizeof edbsmpt);
441: }
442: } else
443: /* Send status message for pt-pt */
444: i= write(devfd,ascii?adbsptpt:edbsptpt,sizeof adbsptpt);
445:
446: ioctl(devfd,BSCNSOH,0); /* end SOH mode */
447: ++tb_ctr; /* increment transmitted block counter
448: for stats */
449: /* ignore any errors from the write */
450: if (i < 0) ioctl(devfd, BSCGET, &gp);
451: #endif
452:
453: /* print screen as is */
454: emprint(1);
455:
456: #ifndef DEBUG
457: /* send device end status */
458: ioctl(devfd,BSCSOH,0); /* set SOH mode */
459: ioctl(devfd,BSCLAST,0); /* set LAST message flag */
460: if (pt_to_pt == BSCMPT) {
461: ioctl (devfd, BSCID, &stationid);
462: if (ascii) {
463: ascsmpt[3] = termid; /* poll addr */
464: ascsmpt[4] = stationid; /* subdev addr */
465: i = write(devfd, ascsmpt, sizeof ascsmpt);
466: } else {
467: ebcsmpt[3] = termid; /* poll addr */
468: ebcsmpt[4] = stationid; /* subdev addr */
469: i = write(devfd, ebcsmpt, sizeof ebcsmpt);
470: }
471: } else
472: /* Send status message for pt-pt */
473: i= write(devfd,ascii?ascsptpt:ebcsptpt,sizeof ascsptpt);
474:
475: ioctl(devfd,BSCNSOH,0); /* end SOH mode */
476: ++tb_ctr; /* increment transmitted block counter
477: for stats */
478: /* ignore any errors from the write */
479: if (i < 0) ioctl(devfd, BSCGET, &gp);
480: #endif
481: }
482:
483: if (kbdrst(wcc)) { /* reset keyboard */
484: updstat(status & ~INPUT_INH);
485: aid_val = ascii?0x2d:0x60;
486: }
487: }
488:
489: /* NAME
490: * eua
491: *
492: * SYNOPSIS
493: * eua(start,end,clrmdt)
494: * register int start; starting erase buffer address
495: * register int end; ending erase buffer address
496: * register int clrmdt; clear mdt flag
497: *
498: * DESCRIPTION
499: * eua erases unprotected fields beginning at "start" buffer address
500: * and ending at "end" buffer address. If clrmdt flag is set, the
501: * mdt bits of unprotected attributes to be erased are reset.
502: */
503:
504: eua(start,end,clrmdt)
505: register int start,end,clrmdt;
506: {
507: register long first_uf = 0;
508:
509: fiximage(0);
510:
511: do {
512: curfield = scrn_xref[start];
513: if (!prot_attr(fldattr[curfield])) {
514: if (scrn_image[start] == ATTRCODE) {
515: /* Set return value to 1st unprotected
516: field encountered.
517: */
518: if (!first_uf) first_uf = curfield;
519: if (clrmdt)
520: fldattr[curfield] &= ~ATTRMDT;
521: }
522: else
523: scrn_image[start] = NUL;
524:
525: }
526: if (++start >= MAXSCREENSIZE) start = 0;
527: }
528: while (start != end);
529: unfiximage();
530: return(first_uf);
531: }
532:
533: /* make temp. attr. save as we may mess up scrn_xref */
534: unfiximage()
535: {
536: register char *p;
537: register int *ip;
538:
539: for (p = fldattr, ip = fldstart; p < &fldattr[totfields]; ++p,++ip)
540: scrn_xref[*ip?*ip - 1:MAXSCREENSIZE-1] = *p;
541: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.