home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 9
/
MEDIASHARE_09.ISO
/
comm
/
ykh121.zip
/
YKHSRC.ZIP
/
VIDIO.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-11-15
|
11KB
|
566 lines
#pragma inline
#include "gfxlib.h"
#include "graph.h"
#define NORMAL 0x0
#define BLINKY 0x1
#define REVERSE 0x2
#define UNDERLINE 0x4
#define BOLD 0x8
#define ASCII 0
#define UK 1
#define SPECIAL 2
#define ROMAN 3
#define JIS_ASCII 4
#define JIS_ROMAN 5
#define OLD_JIS 6
#define NEW_JIS 7
#define EUC 8
#define SHIFT_JIS 9
int cursx; /* X cursor position */
int cursy; /* Y cursor position */
/****************************************************************************/
/* External variables */
extern unsigned originmode; /* Origin mode, relative or absolute */
extern unsigned insertmode; /* Insert mode, off or on */
extern unsigned autowrap; /* Automatic wrap mode, off or on */
extern unsigned newline; /* Newline mode, off or on, GLOBAL data!*/
extern unsigned cursorvisible; /* Cursor visibility, on or hidden */
extern unsigned reversebackground;/* Reverse background attribute, on or off*/
extern unsigned screenwid; /* Absolute screen width */
extern int eight_encoding,encoding,sixteen_encoding;
/***************************************************************************/
/* Local static data */
static unsigned char screentop; /* Absolute top of screen */
static unsigned char screenbot; /* Absolute bottom of screen */
static unsigned char scrolltop; /* Top row of scrolling region */
static unsigned char scrollbot; /* Bottom row of scrolling region */
static unsigned char video_state; /* State of video, reversed or normal */
static unsigned char scbattr; /* Video attribute of empty video cell */
static unsigned char curattr; /* Video attribute of displayable chars */
static unsigned char baseattr; /* Base attribute for video attributes */
static unsigned char extrattr; /* Extra attribute for video attributes */
static unsigned char att_reverse; /* Reverse attribute bits */
static unsigned char att_normal; /* Normal attribute bits */
static unsigned char att_low_mask = 0x6; /* Low attribute mask */
static unsigned char att_underline = 0x1; /* Underlined attribute bit */
static unsigned char att_intensity = 0x8; /* Bold attribute bit */
static unsigned char att_BLINKY = 0x80; /* BLINKYing attribute bit */
static unsigned columns; /* Columns on logical terminal screen */
static unsigned lines; /* Lines on logical terminal screen */
static char tabs[132]; /* active tab stops */
static char deftabs[132]; /* default tab stops, 9,17,26 .... */
static int G0 = ASCII; /* Character set G0 */
static int G1 = ASCII; /* Character set G1 */
static int *GL = &G0; /* Pointer to current mapped character set*/
/* starts at 95 */
static char special_chars[32] = { /*Special characters*/
32,4,176,26,30,27,24,248,241,177,23,217,191,218,192,197,196,196,
196,196,196,195,180,193,194,179,243,242,20,247,156,250
} ;
static struct SaveCursorStruct { /* Structure to save cursor description */
int cursx; /* X cursor position, column */
int cursy; /* Y cursor position, row */
int *GL; /* pointer to mapped character set */
int G0; /* character set G0 */
int G1; /* character set G1 */
int mode; /* origin mode */
} save = { 1, 1, &G0, ASCII, ASCII , 0 } ;
int vidinit(char* s)
{
char t[80];
char *u;
columns=80;
lines =25;
screenbot = lines - 1;
screentop = 1;
screenwid = 80;
u=t;
while (*s)
*u++=*s++;
while (*u!='\\')
u--;
u++;
*u++='J';
*u++='I';
*u++='S';
*u++='.';
*u++='1';
*u++='6';
*u++=0;
return (*graph_init)(400,GFX_WHITE,GFX_BLUE,t);
}
void logoinit(void) {
(*graph_clear)(0,0,25,80);
}
void vidclose(void)
{
(*graph_deinit)();
}
void dosprint(char* near s)
{
asm mov dx,s;
asm mov ah,9;
asm int 21h;
}
void setvattr(unsigned char attr) {curattr=attr;}
void addvattr(unsigned char attr) {curattr|=attr;}
void subvattr(unsigned char attr) {curattr&=(!attr);}
void clearbox( unsigned char left, unsigned char top,
unsigned char right, unsigned char bottom, unsigned char attr )
{
if (attr&REVERSE)
(*graph_set)(top,(left-1),((bottom-top)+1),(right-1)-(left-1)+1);
else
(*graph_clear)(top,(left-1),((bottom-top)+1),(right-1)-(left-1)+1);
}
void clearscreen()
{
clearbox(1, screentop, columns, screenbot, scbattr);
}
void cleareol()
{
clearbox(cursx, cursy, columns, cursy, NORMAL);
}
void clearbol()
{
clearbox(1, cursy, cursx, cursy, NORMAL);
}
void cleareos()
{
cleareol();
if (cursy < screenbot)
clearbox(1,cursy + 1,columns, screenbot, NORMAL);
}
void clearbos()
{
clearbol();
if (cursy > screentop)
clearbox(1,screentop,columns, cursy - 1, NORMAL);
}
void singlewidth(void)
{
}
void doublewidth(void)
{
}
void doubleheighttop(void)
{
}
void doubleheightbottom(void)
{
}
void chrwrite( unsigned char chr )
{
if (*GL == ASCII)
;
else if (*GL == SPECIAL)
{
if (chr > 94 && chr < 128)
chr = special_chars[ chr - 95];
}
else if (*GL == UK)
{
if (chr == '#')
chr = '£';
}
if (insertmode)
(*graph_bcopy)(cursy,(cursx-1),cursy,(cursx-1)+1,1,79-(cursx-1));
if (cursx > screenwid)
{
if (autowrap)
{
ScrollUp();
SetCurs(1,0);
}
else
cursx=screenwid;
}
if (cursy > 24) cursy=24;
(*graph_ascii_put)(chr,cursy,cursx-1);
if (curattr&UNDERLINE) (*graph_underline)(cursy,cursx-1,1,1);
if (curattr&BOLD) (*graph_bold8) (cursy,cursx-1,1,1);
if (curattr&REVERSE || curattr&BLINKY) (*graph_xor) (cursy,cursx-1,1,1);
cursx++;
}
void jiswrite(unsigned byte1, unsigned byte2)
{
unsigned j;
if (insertmode)
(*graph_bcopy)(cursy,(cursx-1),cursy,(cursx-1)+2,1,78-(cursx-1));
if (cursx > screenwid)
{
if (autowrap)
{
ScrollUp();
SetCurs(1,0);
}
else
cursx=screenwid;
}
if (cursy > 24 ) cursy=24;
if (byte1 >= '0') byte1-=8;
j =(byte1-'!'); j*=94;
j+=(byte2-'!');
(*graph_put)(j,cursy,cursx-1);
if (curattr&UNDERLINE) (*graph_underline) (cursy,cursx-1,1,2);
if (curattr&REVERSE || curattr&BLINKY) (*graph_xor) (cursy,cursx-1,1,2);
cursx+=2;
}
void setscroll( register int top, register int bottom)
{
if (top == 0) top = 1;
if (bottom == 0) bottom = screenbot;
if (top > 0 && top <= screenbot && bottom >= top && bottom <= screenbot)
{
scrolltop = top;
scrollbot = bottom;
SetCurs(1,1);
}
}
void scrolldown()
{
if (cursy == scrolltop)
IndexDown();
else
cursy--;
}
void scrollup( )
{
if (cursy == scrollbot)
IndexUp();
else
cursy++;
}
void indexdown( )
{
int y;
y=cursy;
cursy=scrolltop;
InsertLine(1);
cursy=y;
}
void indexup( )
{
int y;
y=cursy;
cursy=scrolltop;
DeleteLine(1);
cursy=y;
}
void insertline(int num)
{
(*graph_bcopy)(cursy,0,(cursy+num),0,(scrollbot-(cursy+num)+1),80);
(*graph_clear)(cursy,0,num,80);
}
void deleteline(int num)
{
(*graph_fcopy)((cursy+num),0,cursy,0,(scrollbot-(cursy+num)+1),80);
(*graph_clear)((scrollbot-num+1),0,num,80);
}
void deletechar(int num)
{
int i;
for (i=0; i<num; i++)
(*graph_fcopy)(cursy,(cursx-1)+1,cursy,(cursx-1),1,79-(cursx-1));
if (curattr&REVERSE)
(*graph_set)(cursy,79,1,1);
else
(*graph_clear)(cursy,79,1,1);
}
void setcurs(register int col, register int row)
{
if (col == 0) col = cursx;
if (row == 0) row = cursy;
if (originmode)
{
row += (scrolltop - 1);
if (row < scrolltop || row > scrollbot)
return;
}
if (col <= screenwid && row <= screenbot )
{
cursx = col;
cursy = row;
}
}
void setrelcurs(register int col, register int row)
{
if (col == 0)
col = cursx;
else
col += cursx;
if (row == 0)
row = cursy;
else
row += cursy;
if (originmode)
{
row += (scrolltop - 1);
if (row < scrolltop || row > scrollbot)
return;
}
if (col > 0 && col <= screenwid && row > 0 && row <= screenbot)
{
cursy = row;
cursx = col;
}
}
void mapcharset( int charset )
{
if (charset == 0)
GL = &G0;
else
if (charset == 1)
GL = &G1;
}
void setcharset( int gset, unsigned char set)
{
int *charset;
if (gset == 0)
charset = &G0;
else
if (gset == 1)
charset = &G1;
else
return;
switch(set)
{
case 'J':
*charset = ROMAN;
encoding=eight_encoding=JIS_ROMAN;
break;
case 'B':
*charset = ASCII;
encoding=eight_encoding=JIS_ASCII;
break;
case 'A':
*charset = UK;
break;
case '0':
*charset = SPECIAL;
break;
default:;
}
}
void savecursor()
{
save.cursx = cursx; /* Save the X cursor position */
save.cursy = cursy; /* Save the Y cursor position */
save.GL = GL; /* Save the current mapped character set */
save.G0 = G0; /* Save G0 character set */
save.G1 = G1; /* Save G1 character set */
save.mode = originmode; /* Also save the origin mode */
}
void restorecursor()
{
cursx = save.cursx; /* Restore the saved X cursor position */
cursy = save.cursy; /* Restore the saved Y cursor position */
GL = save.GL; /* Restore the saved mapped character set */
G0 = save.G0; /* Restore the saved G0 character set */
G1 = save.G1; /* Restore the saved G1 character set */
originmode = save.mode; /* Also restore the saved origin mode */
}
void setcursorvisibility( int mode )
{
if (mode)
{
cursorvisible = 1;
SetCurs(0,0);
}
else
cursorvisible = 0;
}
void setbackground( int mode )
{
int reverse_screen = 0;
register int i;
if (mode)
{
if (reversebackground != 1)
{
reverse_screen = 1;
reversebackground = 1;
}
}
else
{
if (reversebackground != 0)
{
reverse_screen = 1;
reversebackground = 0;
}
}
if (reverse_screen)
{
(*graph_xor)(1,0,24,80);
if (curattr&REVERSE)
SubVattr(REVERSE);
else
AddVattr(REVERSE);
}
}
void inittabs()
{
register int i;
for( i = 1; i < 131; i++)
if ( i % 8 ) /* 9, 17, 26 .... */
deftabs[i+1] = tabs[i+1] = 0; /* Zero indicates no tab here */
else
deftabs[i+1] = tabs[i+1] = 1; /* One indicates a tab stop */
}
void dotab()
{
int i;
for (i = cursx + 1; i <= screenwid; i++)
{
if ( tabs[i] == 1 )
{
SetCurs(i,cursy);
return;
}
}
}
void settabstop() {tabs[cursx] = 1;}
void cleartabstop() {tabs[cursx] = 0;}
void clearalltabs()
{
memset(tabs,'\0',sizeof(tabs));
}
void setscreenwidth(int width)
{
switch(width)
{
case 80 :
case 132:screenwid=width;
}
ClearScreen();
originmode = 0;
SetScroll(0,0);
SetCurs(1,1);
}
void xorcursor(void)
{
(*graph_xor)(cursy,cursx-1,1,1);
}