xref: /csrg-svn/usr.bin/tn3270/ctlr/screen.h (revision 33816)
130024Sminshall /*
2*33816Sbostic  * Copyright (c) 1988 Regents of the University of California.
3*33816Sbostic  * All rights reserved.
4*33816Sbostic  *
5*33816Sbostic  * Redistribution and use in source and binary forms are permitted
6*33816Sbostic  * provided that this notice is preserved and that due credit is given
7*33816Sbostic  * to the University of California at Berkeley. The name of the University
8*33816Sbostic  * may not be used to endorse or promote products derived from this
9*33816Sbostic  * software without specific prior written permission. This software
10*33816Sbostic  * is provided ``as is'' without express or implied warranty.
11*33816Sbostic  *
12*33816Sbostic  *	@(#)screen.h	3.3 (Berkeley) 03/28/88
1330024Sminshall  */
1430024Sminshall 
1530024Sminshall #define	INCLUDED_SCREEN
1630024Sminshall 
1730024Sminshall /* defines and defines to describe how to deal with the screen */
1830024Sminshall 
1931134Sminshall #if	!defined(MSDOS)
2030024Sminshall #define	MAXNUMBERLINES		43		/* 3278-4 */
2130024Sminshall #define	MAXNUMBERCOLUMNS	132		/* 3278-5 */
2230024Sminshall #define	MAXSCREENSIZE		3564		/* (27*132) 3278-5 */
2331134Sminshall #else	/* !defined(MSDOS) */	/* MSDOS has memory constraints */
2431134Sminshall #define	MAXNUMBERLINES		25		/* XXX */
2531134Sminshall #define	MAXNUMBERCOLUMNS	80
2631134Sminshall #define	MAXSCREENSIZE		(MAXNUMBERLINES*MAXNUMBERCOLUMNS)
2731134Sminshall #endif	/* !defined(MSDOS) */	/* MSDOS has memory constraints */
2830024Sminshall #define LowestScreen()	0
2930024Sminshall #define HighestScreen()	(ScreenSize-1)
3030024Sminshall 
3130024Sminshall #define ScreenLineOffset(x)	((x)%NumberColumns)
3230024Sminshall #define ScreenLine(x)	((int)((x)/NumberColumns))
3330024Sminshall #define ScreenInc(x)	(((x)==HighestScreen())? LowestScreen():x+1)
3430024Sminshall #define ScreenDec(x)	(((x)==LowestScreen())? HighestScreen():x-1)
3530024Sminshall #define ScreenUp(x)	(((x)+(ScreenSize-NumberColumns))%ScreenSize)
3630024Sminshall #define ScreenDown(x)	(((x)+NumberColumns)%ScreenSize)
3730024Sminshall #define	IsOrder(x)	(Orders[x])
3830024Sminshall #define BAIC(x)		((x)&0x3f)
3930024Sminshall #define CIAB(x)		(CIABuffer[(x)&0x3f])
4030024Sminshall #define BufferTo3270_0(x)	(CIABuffer[(int)((x)/0x40)])
4130024Sminshall #define BufferTo3270_1(x)	(CIABuffer[(x)&0x3f])
4230024Sminshall #define Addr3270(x,y)	(BAIC(x)*64+BAIC(y))
4330024Sminshall #define SetBufferAddress(x,y)	((x)*NumberColumns+(y))
4430024Sminshall 
4530024Sminshall /* These know how fields are implemented... */
4630024Sminshall 
4730024Sminshall #define WhereAttrByte(p)	(IsStartField(p)? p: FieldDec(p))
4830024Sminshall #define	WhereHighByte(p)	ScreenDec(FieldInc(p))
4930024Sminshall #define WhereLowByte(p)		ScreenInc(WhereAttrByte(p))
5031146Sminshall #define FieldAttributes(x)	(IsStartField(x)? GetHost(x) : \
5131146Sminshall 				    GetHost(WhereAttrByte(x)))
5231146Sminshall #define FieldAttributesPointer(p)	(IsStartFieldPointer(p)? \
5331146Sminshall 				    GetHostPointer(p): \
5431146Sminshall 				    GetHost(WhereAttrByte((p)-&Host[0])))
5530024Sminshall 
5633752Sminshall /*
5733752Sminshall  * The MDT functions need to protect against the case where the screen
5833752Sminshall  * is unformatted (sigh).
5933752Sminshall  */
6033752Sminshall 
6133752Sminshall /* Turn off the Modified Data Tag */
6233752Sminshall #define TurnOffMdt(x) \
6333752Sminshall     if (HasMdt(WhereAttrByte(x))) { \
6433752Sminshall 	ModifyMdt(x, 0); \
6533752Sminshall     }
6633752Sminshall 
6733752Sminshall /* Turn on the Modified Data Tag */
6833752Sminshall #define TurnOnMdt(x) \
6933752Sminshall     if (!HasMdt(WhereAttrByte(x))) { \
7033752Sminshall 	ModifyMdt(x, 1); \
7133752Sminshall     }
7233752Sminshall 
7333752Sminshall /* If this location has the MDT bit turned on (implies start of field) ... */
7433752Sminshall #define HasMdt(x) \
7533752Sminshall     ((GetHost(x)&(ATTR_MDT|ATTR_MASK)) == (ATTR_MDT|ATTR_MASK))
7633752Sminshall 
7730024Sminshall 	/*
7830024Sminshall 	 * Is the screen formatted?  Some algorithms change depending
7930024Sminshall 	 * on whether there are any attribute bytes lying around.
8030024Sminshall 	 */
8130024Sminshall #define	FormattedScreen() \
8231146Sminshall 	    ((WhereAttrByte(0) != 0) || ((GetHost(0)&ATTR_MASK) == ATTR_MASK))
8330024Sminshall 
8430053Sminshall 					    /* field starts here */
8531146Sminshall #define IsStartField(x)	((GetHost(x)&ATTR_MASK) == ATTR_MASK)
8631146Sminshall #define IsStartFieldPointer(p)	((GetHostPointer(p)&ATTR_MASK) == ATTR_MASK)
8730053Sminshall 
8831146Sminshall #define NewField(p,a)	SetHost(p, (a)|ATTR_MASK)
8931146Sminshall #define DeleteField(p)	SetHost(p, 0)
9031066Sminshall #define	DeleteAllFields()
9130024Sminshall 
9230024Sminshall /* The following are independent of the implementation of fields */
9330024Sminshall #define IsProtectedAttr(p,a)	(IsStartField(p) || ((a)&ATTR_PROT))
9430024Sminshall #define IsProtected(p)	IsProtectedAttr(p,FieldAttributes(p))
9530024Sminshall 
9630024Sminshall #define IsUnProtected(x)	(!IsProtected(x))
9730024Sminshall 
9830024Sminshall #define IsAutoSkip(x)	(FieldAttributes(x)&ATTR_AUTO_SKIP)
9930024Sminshall 
10030024Sminshall #define IsNonDisplayAttr(c)	(((c)&ATTR_DSPD_MASK) == ATTR_DSPD_NONDISPLAY)
10130024Sminshall #define	IsNonDisplay(p)	IsNonDisplayAttr(FieldAttributes(p))
10230024Sminshall 
10330024Sminshall #define IsHighlightedAttr(c) \
10430024Sminshall 		(((c)&ATTR_DSPD_MASK) == ATTR_DSPD_HIGH)
10530024Sminshall #define	IsHighlighted(p) \
10630024Sminshall 		(IsHighlightedAttr(FieldAttributes(p)) && !IsStartField(p))
10730024Sminshall 
10830024Sminshall 
10930024Sminshall #define MAX(x,y)	((x)<(y)? (y):(x))
11030024Sminshall #define MIN(x,y)	((x)<(y)? x:(y))
11130024Sminshall 
11231146Sminshall typedef unsigned char ScreenImage;
11330024Sminshall 
11430024Sminshall extern int
11530024Sminshall 	FieldFind();
11630024Sminshall 
11730024Sminshall extern char
11830024Sminshall 	CIABuffer[];
11930024Sminshall 
12031146Sminshall #define	GetGeneric(i,h)		(h)[i]
12131146Sminshall #define	GetGenericPointer(p)	(*(p))
12231146Sminshall #define	SetGeneric(i,c,h)	((h)[i] = (c))
12331146Sminshall #define	ModifyGeneric(i,what,h)	{(h)[i] what;}
12431146Sminshall 
12531146Sminshall #define GetHost(i)		GetGeneric(i,Host)
12631146Sminshall #define GetHostPointer(p)	GetGenericPointer(p)
12731146Sminshall #define	SetHost(i,c)		SetGeneric(i,c,Host)
12831146Sminshall #define	ModifyHost(i,what)	ModifyGeneric(i,what,Host)
129