|
|
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: * emreadmod
18: *
19: * SYNOPSIS
20: * emreadmod(key)
21: * int key;
22: *
23: * DESCRIPTION
24: * emreadmod is called by emulate when a 'read modified' function is
25: * to be emulated. aid_val contains the aid code to send to the host
26: * which indicates which key was pressed, causing the read
27: * modified condition: ENTER, PF1-12, PA1-3, CLEAR, TESTREQ.
28: * key indicates the key which was pressed.
29: * A series of buffers is prepared, containing all modified fields
30: * if the keystroke was ENTER or PF1-12, or a short read buffer to
31: * take care of PA1-3, CLEAR, and TEST REQUEST.
32: *
33: */
34: #include <em.h>
35: #include "local.h"
36: #include <bsc/bscio.h>
37: #include <errno.h>
38: #include <sys/time.h>
39:
40: #define GOZINTA(x) x/64
41: #define LEFTOVER(x) x%64
42: #define SBA 0x11
43: #define YES 1
44: #define NO 0
45:
46: extern int ascii;
47: char aadr_tbl[64] = { /* ASCII hex cursor address encoding table */
48: 0x20,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x5b,0x2e,
49: 0x3c,0x28,0x2b,0x21,0x26,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,
50: 0x51,0x52,0x5d,0x24,0x2a,0x29,0x3b,0x5e,0x2d,0x2f,0x53,0x54,
51: 0x55,0x56,0x57,0x58,0x59,0x5a,0x7c,0x2c,0x25,0x5f,0x3e,0x3f,
52: 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x23,
53: 0x40,0x27,0x3d,0x22};
54: char eadr_tbl[] = { /* EBCDIC hex cursor address encoding table */
55: 0x40,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0x4a,0x4b,
56: 0x4c,0x4d,0x4e,0x4f,0x50,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,
57: 0xd8,0xd9,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f,0x60,0x61,0xe2,0xe3,
58: 0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,
59: 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0x7a,0x7b,
60: 0x7c,0x7d,0x7e,0x7f};
61:
62: char aaid_tbl[18] = { /* ASCII hex attention id character table */
63: 0x27,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x23,
64: 0x40,0x25,0x3e,0x2c,0x5f,0x30};
65: char eaid_tbl[18] = { /* EBCDIC hex attention id character table */
66: 0x7d,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0x7a,0x7b,
67: 0x7c,0x6c,0x6e,0x6b,0x6d,0xf0};
68:
69: unsigned sleep();
70: extern int devfd;
71: extern int errno;
72: extern struct bscio p;
73: extern int stationid;
74: extern char termid;
75: extern int pt_to_pt;
76: int xmitfd;
77:
78: #ifndef lint
79: static char sccsid[] = "@(#)emreadmod.c 1.11 REL";
80: #endif
81: extern char aid_val;
82:
83: emreadmod(key)
84: int key;
85: {
86: char x;
87: register char *chrptr;
88:
89: /* common buffer prelude */
90: if (pt_to_pt == BSCMPT) { /* multipoint - send addrs */
91: if (key != TESTREQ) { /* testreq msg has no addr to start */
92: /* ttl 5/10/85 */
93: if (bput(termid)<0) return; /* cluster address */
94: if (bput(stationid)<0) return; /* subdevice address */
95: }
96: }
97: /* Output the `Read Header' - all read types except Test Request */
98: if (key != TESTREQ) {
99: if (bput(aid_val)< 0) return;
100: if (bput((ascii?aadr_tbl:eadr_tbl)[GOZINTA(cursaddr)])<0)
101: return;
102: if (bput((ascii?aadr_tbl:eadr_tbl)[LEFTOVER(cursaddr)])<0)
103: return;
104: } else { /* output Test Request Read header */
105: /**** if (bput(0x01) < 0) return; ****/ /* SOH */
106: ioctl(devfd,BSCSOH,0); /* put in SOH using ioctl.ttl 5/10/85 */
107: if (bput((ascii?'%':0x6c)) < 0) return;
108: if (bput((ascii?'/':0x61)) < 0) return;
109: if (bput(0x02) < 0) return; /* STX */
110: }
111:
112: /* read modified processing */
113: if (key != PA1 && key != PA2 && key != PA3 && key != CLEAR) {
114: if (totfields > 0) {
115: /* search for fields with modified data tag (mdt) bit set */
116: register int *startptr, *maxptr;
117: register char *attrptr, *lastattr, *lastchr;
118: for (attrptr = fldattr,
119: startptr = fldstart,
120: maxptr = fldmax,
121: lastattr = &fldattr[totfields-1];
122: attrptr <= lastattr;
123: ++attrptr, ++startptr, ++maxptr) {
124: if (!(*attrptr & ATTRMDT))
125: continue;
126: /* output SBA, address, field */
127: if (bput(SBA)<0) return;
128: if (bput((ascii?
129: aadr_tbl:
130: eadr_tbl)[GOZINTA(*startptr)])<0)
131: return;
132: if (bput((ascii?
133: aadr_tbl:
134: eadr_tbl)[LEFTOVER(*startptr)])<0)
135: return;
136:
137: lastchr = &scrn_image[((*maxptr-1) +
138: *startptr)%MAXSCREENSIZE];
139: chrptr = &scrn_image[*startptr];
140: while (1) {
141: if (*chrptr != '\0') {
142: x = *chrptr;
143: if (!ascii)
144: ascebc(&x,1);
145: if (bput(x)<0) return;
146: }
147: if (chrptr == lastchr)
148: break;
149: if(++chrptr>=&scrn_image[MAXSCREENSIZE])
150: chrptr = scrn_image;
151: }
152: }
153: } else {/* Unformatted screen */
154: for (chrptr = scrn_image;
155: chrptr < &scrn_image[MAXSCREENSIZE];
156: ++chrptr)
157: if (*chrptr) {
158: x = *chrptr;
159: if (!ascii)
160: ascebc(&x,1);
161: if (bput(x)<0) return;
162: }
163: }
164: }
165: /* Flush out leftover bytes */
166: ioctl(devfd,BSCLAST,0);
167: flushbuf();
168: if (key == TESTREQ) /* disable SOH mode ttl 5/10/85 */
169: ioctl(devfd,BSCNSOH,0);
170: }
171:
172: /* put a character in the transmit buffer */
173: char xmitbuf[254], *xmitnext = xmitbuf;
174: bput(c)
175: register char c;
176: {
177: register int needed; /* # of characters needed for this character
178: sequence; 3 for SBA (set buffer address),
179: 1 for everything else */
180: needed = (c == SBA)? 3: 1;
181:
182: if (sizeof xmitbuf - (int)(xmitnext-xmitbuf) < needed)
183: if (flushbuf()<0) return(-1);
184: *xmitnext++ = c;
185: return(0);
186: }
187:
188: /* flush the transmit buffer -- write to transmit device */
189: extern int tb_ctr; /* transmitted blocks counter */
190:
191: flushbuf()
192: {
193: register int l;
194: l = xmitnext - xmitbuf;
195: xmitnext = xmitbuf;
196: errno = 0;
197:
198: if (write(devfd,xmitbuf,l) != l && get_errors())
199: return(-1);
200: ++tb_ctr;
201: return(0);
202: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.