home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / comm / ykh121.zip / YKHSRC.ZIP / VIDIO.C < prev    next >
C/C++ Source or Header  |  1992-11-15  |  11KB  |  566 lines

  1. #pragma inline
  2. #include "gfxlib.h"
  3. #include "graph.h"
  4.  
  5. #define NORMAL    0x0
  6. #define BLINKY    0x1
  7. #define REVERSE   0x2
  8. #define UNDERLINE 0x4
  9. #define BOLD      0x8
  10.  
  11. #define ASCII         0
  12. #define UK            1
  13. #define SPECIAL       2
  14. #define ROMAN         3
  15. #define JIS_ASCII     4
  16. #define JIS_ROMAN     5
  17.  
  18. #define OLD_JIS   6
  19. #define NEW_JIS   7
  20. #define EUC       8
  21. #define SHIFT_JIS 9
  22.  
  23. int cursx;                 /* X cursor position */
  24. int cursy;                 /* Y cursor position */
  25.  
  26. /****************************************************************************/
  27. /* External variables                                                       */
  28.  
  29. extern unsigned originmode;       /* Origin mode, relative or absolute */
  30. extern unsigned insertmode;       /* Insert mode, off or on */
  31. extern unsigned autowrap;         /* Automatic wrap mode, off or on */
  32. extern unsigned newline;          /* Newline mode, off or on,  GLOBAL data!*/
  33. extern unsigned cursorvisible;    /* Cursor visibility, on or hidden */
  34. extern unsigned reversebackground;/* Reverse background attribute, on or off*/
  35. extern unsigned screenwid;        /* Absolute screen width */
  36.  
  37. extern int eight_encoding,encoding,sixteen_encoding;
  38.  
  39. /***************************************************************************/
  40. /* Local static data                                                       */
  41.  
  42. static unsigned char screentop;   /* Absolute top of screen */
  43. static unsigned char screenbot;   /* Absolute bottom of screen */
  44. static unsigned char scrolltop;   /* Top row of scrolling region */
  45. static unsigned char scrollbot;   /* Bottom row of scrolling region */
  46.  
  47. static unsigned char video_state; /* State of video, reversed or normal */
  48. static unsigned char scbattr;     /* Video attribute of empty video cell */
  49. static unsigned char curattr;     /* Video attribute of displayable chars */
  50. static unsigned char baseattr;    /* Base attribute for video attributes */
  51. static unsigned char extrattr;    /* Extra attribute for video attributes */
  52.  
  53. static unsigned char att_reverse;          /* Reverse attribute bits */
  54. static unsigned char att_normal;           /* Normal attribute bits */
  55. static unsigned char att_low_mask  = 0x6;  /* Low attribute mask */
  56. static unsigned char att_underline = 0x1;  /* Underlined attribute bit */
  57. static unsigned char att_intensity = 0x8;  /* Bold attribute bit */
  58. static unsigned char att_BLINKY     = 0x80; /* BLINKYing attribute bit */
  59.  
  60.  
  61. static unsigned columns;          /* Columns on logical terminal screen */
  62. static unsigned lines;            /* Lines on logical terminal screen */
  63.  
  64. static char tabs[132];            /* active tab stops */
  65. static char deftabs[132];         /* default tab stops, 9,17,26 .... */
  66.  
  67. static int G0 = ASCII;            /* Character set G0 */
  68. static int G1 = ASCII;            /* Character set G1 */
  69. static int *GL = &G0;             /* Pointer to current mapped character set*/
  70.  
  71. /* starts at 95 */
  72. static char special_chars[32] = {  /*Special characters*/
  73.    32,4,176,26,30,27,24,248,241,177,23,217,191,218,192,197,196,196,
  74.    196,196,196,195,180,193,194,179,243,242,20,247,156,250
  75.    } ;
  76.  
  77. static struct SaveCursorStruct {  /* Structure to save cursor description */
  78.    int cursx;                        /* X cursor position, column */
  79.    int cursy;                        /* Y cursor position, row */
  80.    int *GL;                          /* pointer to mapped character set */
  81.    int G0;                           /* character set G0 */
  82.    int G1;                           /* character set G1 */
  83.    int mode;                         /* origin mode */
  84.    } save = { 1, 1, &G0, ASCII, ASCII , 0 } ;
  85.  
  86.  
  87.  
  88. int vidinit(char* s)
  89. {
  90. char t[80];
  91. char *u;
  92.  
  93. columns=80;
  94. lines  =25;
  95. screenbot = lines - 1;
  96. screentop =  1;
  97. screenwid = 80;
  98.  
  99. u=t;
  100. while (*s)
  101.   *u++=*s++;
  102. while (*u!='\\')
  103.   u--;
  104. u++;
  105. *u++='J';
  106. *u++='I';
  107. *u++='S';
  108. *u++='.';
  109. *u++='1';
  110. *u++='6';
  111. *u++=0;
  112.  
  113. return (*graph_init)(400,GFX_WHITE,GFX_BLUE,t);
  114. }
  115.  
  116. void logoinit(void) {
  117. (*graph_clear)(0,0,25,80);
  118. }
  119.  
  120. void vidclose(void)
  121. {
  122. (*graph_deinit)();
  123. }
  124.  
  125. void dosprint(char* near s)
  126. {
  127. asm mov dx,s;
  128. asm mov ah,9;
  129. asm int 21h;
  130. }
  131.  
  132. void setvattr(unsigned char attr) {curattr=attr;}
  133. void addvattr(unsigned char attr) {curattr|=attr;}
  134. void subvattr(unsigned char attr) {curattr&=(!attr);}
  135.  
  136.  
  137. void clearbox( unsigned char left, unsigned char top,
  138. unsigned char right, unsigned char bottom, unsigned char attr )
  139. {
  140. if (attr&REVERSE)
  141.   (*graph_set)(top,(left-1),((bottom-top)+1),(right-1)-(left-1)+1);
  142.   else
  143.   (*graph_clear)(top,(left-1),((bottom-top)+1),(right-1)-(left-1)+1);
  144. }
  145.  
  146.  
  147. void clearscreen()
  148. {
  149. clearbox(1, screentop, columns, screenbot, scbattr);
  150. }
  151.  
  152.  
  153. void cleareol()
  154. {
  155. clearbox(cursx, cursy, columns, cursy, NORMAL);
  156. }
  157.  
  158.  
  159. void clearbol()
  160. {
  161. clearbox(1, cursy, cursx, cursy, NORMAL);
  162. }
  163.  
  164.  
  165. void cleareos()
  166. {
  167. cleareol();
  168. if (cursy < screenbot)
  169.   clearbox(1,cursy + 1,columns, screenbot, NORMAL);
  170. }
  171.  
  172.  
  173. void clearbos()
  174. {
  175. clearbol();
  176. if (cursy > screentop)
  177.   clearbox(1,screentop,columns, cursy - 1, NORMAL);
  178. }
  179.  
  180.  
  181. void singlewidth(void)
  182. {
  183. }
  184.  
  185.  
  186. void doublewidth(void)
  187. {
  188. }
  189.  
  190.  
  191. void doubleheighttop(void)
  192. {
  193. }
  194.  
  195.  
  196. void doubleheightbottom(void)
  197. {
  198. }
  199.  
  200.  
  201. void chrwrite( unsigned char chr )
  202. {
  203. if (*GL == ASCII)
  204.   ;
  205.   else if (*GL == SPECIAL)
  206.     {
  207.     if (chr > 94 && chr < 128)
  208.       chr = special_chars[ chr - 95];
  209.     }
  210.     else if (*GL == UK)
  211.       {
  212.       if (chr == '#')
  213.         chr = '£';
  214.       }
  215.  
  216. if (insertmode)
  217.   (*graph_bcopy)(cursy,(cursx-1),cursy,(cursx-1)+1,1,79-(cursx-1));
  218.  
  219. if (cursx > screenwid)
  220.   {
  221.   if (autowrap)
  222.     {
  223.     ScrollUp();
  224.     SetCurs(1,0);
  225.     }
  226.     else
  227.     cursx=screenwid;
  228.     }
  229. if (cursy > 24) cursy=24;
  230.  
  231. (*graph_ascii_put)(chr,cursy,cursx-1);
  232.  
  233. if (curattr&UNDERLINE)                 (*graph_underline)(cursy,cursx-1,1,1);
  234. if (curattr&BOLD)                      (*graph_bold8)    (cursy,cursx-1,1,1);
  235. if (curattr&REVERSE || curattr&BLINKY) (*graph_xor)      (cursy,cursx-1,1,1);
  236.  
  237. cursx++;
  238. }
  239.  
  240.  
  241. void jiswrite(unsigned byte1, unsigned byte2)
  242. {
  243. unsigned j;
  244.  
  245. if (insertmode)
  246.   (*graph_bcopy)(cursy,(cursx-1),cursy,(cursx-1)+2,1,78-(cursx-1));
  247.  
  248. if (cursx > screenwid)
  249.   {
  250.   if (autowrap)
  251.     {
  252.     ScrollUp();
  253.     SetCurs(1,0);
  254.     }
  255.     else
  256.     cursx=screenwid;
  257.     }
  258. if (cursy >  24 ) cursy=24;
  259. if (byte1 >= '0') byte1-=8;
  260.  
  261. j =(byte1-'!'); j*=94;
  262. j+=(byte2-'!');
  263.  
  264. (*graph_put)(j,cursy,cursx-1);
  265.  
  266. if (curattr&UNDERLINE)                 (*graph_underline) (cursy,cursx-1,1,2);
  267. if (curattr&REVERSE || curattr&BLINKY) (*graph_xor)       (cursy,cursx-1,1,2);
  268.  
  269. cursx+=2;
  270. }
  271.  
  272.  
  273. void setscroll( register int top, register int bottom)
  274. {
  275. if (top    == 0) top = 1;
  276. if (bottom == 0) bottom = screenbot;
  277.  
  278. if (top > 0 && top <= screenbot && bottom >= top && bottom <= screenbot)
  279.   {
  280.   scrolltop = top;
  281.   scrollbot = bottom;
  282.   SetCurs(1,1);
  283.   }
  284. }
  285.  
  286.  
  287. void scrolldown()
  288. {
  289. if (cursy == scrolltop)
  290.   IndexDown();
  291.   else
  292.   cursy--;
  293. }
  294.  
  295.  
  296. void scrollup( )
  297. {
  298. if (cursy == scrollbot)
  299.    IndexUp();
  300.    else
  301.    cursy++;
  302. }
  303.  
  304.  
  305. void indexdown( )
  306. {
  307. int y;
  308.  
  309. y=cursy;
  310. cursy=scrolltop;
  311. InsertLine(1);
  312. cursy=y;
  313. }
  314.  
  315.  
  316. void indexup( )
  317. {
  318. int y;
  319.  
  320. y=cursy;
  321. cursy=scrolltop;
  322. DeleteLine(1);
  323. cursy=y;
  324. }
  325.  
  326.  
  327. void insertline(int num)
  328. {
  329. (*graph_bcopy)(cursy,0,(cursy+num),0,(scrollbot-(cursy+num)+1),80);
  330. (*graph_clear)(cursy,0,num,80);
  331. }
  332.  
  333.  
  334. void deleteline(int num)
  335. {
  336. (*graph_fcopy)((cursy+num),0,cursy,0,(scrollbot-(cursy+num)+1),80);
  337. (*graph_clear)((scrollbot-num+1),0,num,80);
  338. }
  339.  
  340.  
  341. void deletechar(int num)
  342. {
  343. int i;
  344. for (i=0; i<num; i++)
  345.   (*graph_fcopy)(cursy,(cursx-1)+1,cursy,(cursx-1),1,79-(cursx-1));
  346. if (curattr&REVERSE)
  347.   (*graph_set)(cursy,79,1,1);
  348.   else
  349.   (*graph_clear)(cursy,79,1,1);
  350. }
  351.  
  352.  
  353. void setcurs(register int col, register int row)
  354. {
  355. if (col == 0) col = cursx;
  356. if (row == 0) row = cursy;
  357.  
  358. if (originmode)
  359.   {
  360.   row += (scrolltop - 1);
  361.   if (row < scrolltop || row > scrollbot)
  362.     return;
  363.   }
  364.  
  365. if (col <= screenwid && row <= screenbot )
  366.   {
  367.   cursx = col;
  368.   cursy = row;
  369.   }
  370. }
  371.  
  372.  
  373. void setrelcurs(register int col, register int row)
  374. {
  375. if (col == 0)
  376.   col  = cursx;
  377.   else
  378.   col += cursx;
  379.  
  380. if (row == 0)
  381.   row  = cursy;
  382.   else
  383.   row += cursy;
  384.  
  385. if (originmode)
  386.   {
  387.   row += (scrolltop - 1);
  388.   if (row < scrolltop || row > scrollbot)
  389.     return;
  390.   }
  391.  
  392. if (col > 0 && col <= screenwid && row > 0 && row <= screenbot)
  393.   {
  394.   cursy = row;
  395.   cursx = col;
  396.   }
  397. }
  398.  
  399.  
  400. void mapcharset( int charset )
  401. {
  402. if (charset == 0)
  403.   GL = &G0;
  404.   else
  405.   if (charset == 1)
  406.     GL = &G1;
  407. }
  408.  
  409.  
  410. void setcharset( int gset, unsigned char set)
  411. {
  412. int *charset;
  413.  
  414. if (gset == 0)
  415.    charset = &G0;
  416.    else
  417.    if (gset == 1)
  418.      charset = &G1;
  419.      else
  420.      return;
  421.  
  422. switch(set)
  423.   {
  424.   case 'J':
  425.      *charset = ROMAN;
  426.      encoding=eight_encoding=JIS_ROMAN;
  427.      break;
  428.   case 'B':
  429.      *charset = ASCII;
  430.      encoding=eight_encoding=JIS_ASCII;
  431.      break;
  432.   case 'A':
  433.      *charset = UK;
  434.      break;
  435.   case '0':
  436.      *charset = SPECIAL;
  437.      break;
  438.   default:;
  439.   }
  440. }
  441.  
  442.  
  443. void savecursor()
  444. {
  445. save.cursx = cursx;              /* Save the X cursor position */
  446. save.cursy = cursy;              /* Save the Y cursor position */
  447. save.GL = GL;                    /* Save the current mapped character set */
  448. save.G0 = G0;                    /* Save G0 character set */
  449. save.G1 = G1;                    /* Save G1 character set */
  450. save.mode = originmode;          /* Also save the origin mode */
  451. }
  452.  
  453.  
  454. void restorecursor()
  455. {
  456. cursx = save.cursx;              /* Restore the saved X cursor position */
  457. cursy = save.cursy;              /* Restore the saved Y cursor position */
  458. GL = save.GL;                    /* Restore the saved mapped character set */
  459. G0 = save.G0;                    /* Restore the saved G0 character set */
  460. G1 = save.G1;                    /* Restore the saved G1 character set */
  461. originmode = save.mode;          /* Also restore the saved origin mode */
  462. }
  463.  
  464.  
  465. void setcursorvisibility( int mode )
  466. {
  467. if (mode)
  468.   {
  469.   cursorvisible = 1;
  470.   SetCurs(0,0);
  471.   }
  472.   else
  473.   cursorvisible = 0;
  474. }
  475.  
  476.  
  477. void setbackground( int mode )
  478. {
  479. int reverse_screen = 0;
  480. register int i;
  481.  
  482. if (mode)
  483.   {
  484.   if (reversebackground != 1)
  485.     {
  486.     reverse_screen = 1;
  487.     reversebackground = 1;
  488.     }
  489.   }
  490.   else
  491.   {
  492.   if (reversebackground != 0)
  493.     {
  494.     reverse_screen = 1;
  495.     reversebackground = 0;
  496.     }
  497.   }
  498.  
  499. if (reverse_screen)
  500.   {
  501.   (*graph_xor)(1,0,24,80);
  502.  
  503.   if (curattr&REVERSE)
  504.     SubVattr(REVERSE);
  505.     else
  506.     AddVattr(REVERSE);
  507.   }
  508. }
  509.  
  510.  
  511. void inittabs()
  512. {
  513. register int i;
  514.  
  515. for( i = 1; i < 131; i++)
  516.   if ( i % 8 )                /* 9, 17, 26 .... */
  517.     deftabs[i+1] = tabs[i+1] = 0; /* Zero indicates no tab here */
  518.     else
  519.     deftabs[i+1] = tabs[i+1] = 1; /* One indicates a tab stop */
  520. }
  521.  
  522.  
  523. void dotab()
  524. {
  525. int i;
  526.  
  527. for (i = cursx + 1; i <= screenwid; i++)
  528.   {
  529.    if ( tabs[i] == 1 )
  530.      {
  531.      SetCurs(i,cursy);
  532.      return;
  533.      }
  534.   }
  535. }
  536.  
  537.  
  538. void settabstop()   {tabs[cursx] = 1;}
  539. void cleartabstop() {tabs[cursx] = 0;}
  540.  
  541. void clearalltabs()
  542. {
  543. memset(tabs,'\0',sizeof(tabs));
  544. }
  545.  
  546. void setscreenwidth(int width)
  547. {
  548. switch(width)
  549.   {
  550.   case 80 :
  551.   case 132:screenwid=width;
  552.   }
  553. ClearScreen();
  554. originmode = 0;
  555. SetScroll(0,0);
  556. SetCurs(1,1);
  557. }
  558.  
  559.  
  560. void xorcursor(void)
  561. {
  562. (*graph_xor)(cursy,cursx-1,1,1);
  563. }
  564.  
  565.  
  566.