File:  [Power 6/32 Unix Tahoe 4.2BSD] / cci / usr / src / usr.bin / bsc / cmd / 3270 / emreadmod.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Sun Jul 28 12:26:11 2019 UTC (7 years ago) by root
Branches: bsd, MAIN
CVS tags: v121, HEAD
Power 6/32 Unix version 1.21

/*	D.L.Buck and Associates, Inc. - May, 1984
 *
 *	COPYRIGHT NOTICE:
 *		Copyright c 1984 - An unpublished work by
 *		D.L.Buck and Associates, Inc.
 *
 *	PROPRIETARY RIGHTS NOTICE:
 *		All rights reserved. This document and program contains
 *		proprietary information of D.L.Buck and Associates,Inc.
 *		of San Jose, California, U.S.A., embodying confidential
 *		information,  ideas, and expressions,  no part of which
 *		may be reproduced, or transmitted in any form or by any
 *		means,	electronic,  mechanical,  or otherwise, without
 *		the written permission of D.L.Buck and Associates, Inc.
 *
 * NAME
 *	emreadmod
 *
 * SYNOPSIS
 *	emreadmod(key)
 *	int key;
 *
 * DESCRIPTION
 *	emreadmod is called by emulate when a 'read modified' function is
 *	to be emulated. aid_val contains the aid code to send to the host
 *	which indicates which key was pressed, causing the read
 *	modified condition: ENTER, PF1-12, PA1-3, CLEAR, TESTREQ.
 *	key indicates the key which was pressed.
 *	A series of buffers is prepared, containing all modified fields
 *	if the keystroke was ENTER or PF1-12, or a short read buffer to
 *	take care of PA1-3, CLEAR, and TEST REQUEST.
 *
 */
#include <em.h>
#include "local.h"
#include <bsc/bscio.h>
#include <errno.h>
#include <sys/time.h>

#define GOZINTA(x) x/64
#define LEFTOVER(x)  x%64
#define SBA 0x11
#define YES	1
#define	NO	0

extern int ascii;
char aadr_tbl[64] = {	/* ASCII hex cursor address encoding table */
	0x20,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x5b,0x2e,
	0x3c,0x28,0x2b,0x21,0x26,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,
	0x51,0x52,0x5d,0x24,0x2a,0x29,0x3b,0x5e,0x2d,0x2f,0x53,0x54,
	0x55,0x56,0x57,0x58,0x59,0x5a,0x7c,0x2c,0x25,0x5f,0x3e,0x3f,
	0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x23,
	0x40,0x27,0x3d,0x22};
char eadr_tbl[] = {	/* EBCDIC hex cursor address encoding table */
	0x40,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0x4a,0x4b,
	0x4c,0x4d,0x4e,0x4f,0x50,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,
	0xd8,0xd9,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f,0x60,0x61,0xe2,0xe3,
	0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,
	0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0x7a,0x7b,
	0x7c,0x7d,0x7e,0x7f};

char aaid_tbl[18] = {	/* ASCII hex attention id character table */
	0x27,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x23,
	0x40,0x25,0x3e,0x2c,0x5f,0x30};
char eaid_tbl[18] = {	/* EBCDIC hex attention id character table */
	0x7d,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0x7a,0x7b,
	0x7c,0x6c,0x6e,0x6b,0x6d,0xf0};

unsigned sleep();
extern int devfd;
extern int errno;
extern struct bscio p;
extern int stationid;
extern char termid;
extern int pt_to_pt;
int xmitfd;

#ifndef lint
static char sccsid[] = "@(#)emreadmod.c	1.11 REL";
#endif
extern char aid_val;

emreadmod(key)
int key;
{
	char x;
	register char *chrptr;

	/* common buffer prelude */
	if (pt_to_pt == BSCMPT) {	/* multipoint - send addrs */
            if (key != TESTREQ) {       /* testreq msg has no addr to start */
                                        /* ttl 5/10/85 */
		if (bput(termid)<0) return;		/* cluster address */
		if (bput(stationid)<0) return;	/* subdevice address */
            }				
	}
	/* Output the `Read Header' - all read types except Test Request */
	if (key != TESTREQ)	{
		if (bput(aid_val)< 0) return;
		if (bput((ascii?aadr_tbl:eadr_tbl)[GOZINTA(cursaddr)])<0)
			return;
		if (bput((ascii?aadr_tbl:eadr_tbl)[LEFTOVER(cursaddr)])<0)
			return;
	} else {	/* output Test Request Read header */
	/****	if (bput(0x01) < 0) return;    ****/	/* SOH */
                ioctl(devfd,BSCSOH,0);	/* put in SOH using ioctl.ttl 5/10/85 */
		if (bput((ascii?'%':0x6c)) < 0) return;
		if (bput((ascii?'/':0x61)) < 0) return;
		if (bput(0x02) < 0) return;	/* STX */
	}

	/* read modified processing */
	if (key != PA1 && key != PA2 && key != PA3 && key != CLEAR)	{
		if (totfields > 0)	{
		/* search for fields with modified data tag (mdt) bit set */
			register int *startptr, *maxptr;
			register char *attrptr, *lastattr, *lastchr;
			for (attrptr = fldattr,
			     startptr = fldstart,
			     maxptr = fldmax,
			     lastattr = &fldattr[totfields-1];
			     attrptr <= lastattr;
			     ++attrptr, ++startptr, ++maxptr) {
				if (!(*attrptr & ATTRMDT))
					continue;
				/* output SBA, address, field */
				if (bput(SBA)<0) return;
				if (bput((ascii?
					 aadr_tbl:
					 eadr_tbl)[GOZINTA(*startptr)])<0)
					return;
				if (bput((ascii?
					 aadr_tbl:
					 eadr_tbl)[LEFTOVER(*startptr)])<0)
					return;

				lastchr = &scrn_image[((*maxptr-1) +
					*startptr)%MAXSCREENSIZE];
				chrptr = &scrn_image[*startptr];
				while (1)	{
					if (*chrptr != '\0') {
						x = *chrptr;
						if (!ascii)
							ascebc(&x,1);
						if (bput(x)<0) return;
					}
					if (chrptr == lastchr)
						break;
					if(++chrptr>=&scrn_image[MAXSCREENSIZE])
						chrptr = scrn_image;
				}
			}
		} else	{/* Unformatted screen */
			for (chrptr = scrn_image;
			     chrptr < &scrn_image[MAXSCREENSIZE];
			     ++chrptr)
				if (*chrptr) {
					x = *chrptr;
					if (!ascii)
						ascebc(&x,1);
					if (bput(x)<0) return;
				}
		}
	}
	/* Flush out leftover bytes */
	ioctl(devfd,BSCLAST,0);
	flushbuf();
        if (key == TESTREQ) /* disable SOH mode  ttl 5/10/85 */
            ioctl(devfd,BSCNSOH,0);
}

/* put a character in the transmit buffer */
char xmitbuf[254], *xmitnext = xmitbuf;
bput(c)
register char c;
{
	register int needed;	/* # of characters needed for this character
				   sequence; 3 for SBA (set buffer address),
				   1 for everything else */
	needed = (c == SBA)? 3: 1;

	if (sizeof xmitbuf - (int)(xmitnext-xmitbuf) < needed)
		if (flushbuf()<0) return(-1);
	*xmitnext++ = c;
	return(0);
}

/* flush the transmit buffer -- write to transmit device */
extern int tb_ctr;	/* transmitted blocks counter */

flushbuf()
{
	register int l;
	l = xmitnext - xmitbuf;
	xmitnext = xmitbuf;
	errno = 0;

	if (write(devfd,xmitbuf,l) != l && get_errors())
		return(-1);
	++tb_ctr;
	return(0);
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.