home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / pcmagazi / 1992 / 04 / screen.h < prev    next >
C/C++ Source or Header  |  1992-01-03  |  6KB  |  244 lines

  1. // screen.h RHS 7/28/91
  2.  
  3. #if !defined(SCREEN_H)
  4. #define SCREEN_H
  5.  
  6. #include<malloc.h>
  7. #include"stddefs.h"
  8.  
  9. inline BYTE MakeBG(BYTE byte)    
  10.     {
  11.     return (byte << 4);
  12.     }
  13.  
  14. inline WORD MakeCell(BYTE c, BYTE color)
  15.     {
  16.     return (WORD)((color << 8)+c);
  17.     }
  18.  
  19. inline DWORD MakePosition(BYTE top, BYTE left, BYTE height, BYTE width)
  20.     {
  21.     WORD hi = MAKEWORD(top,left);
  22.     WORD lo = MAKEWORD(height,width);
  23.     return MAKEDWORD(hi,lo);
  24.     }
  25.  
  26. inline void GetPosition(DWORD position, BYTE& top, BYTE& left, 
  27.         BYTE& height, BYTE& width)
  28.     {
  29.     WORD w = HIWORD(position);
  30.     top = HIBYTE(w);
  31.     left = LOBYTE(w);
  32.     w = LOWORD(position);
  33.     height = HIBYTE(w);
  34.     width = LOBYTE(w);
  35.     }
  36.  
  37. const VIDSETMODE = 0; 
  38. const VIDSETCURSIZE = 1; 
  39. const VIDSETCURPOS = 2; 
  40. const VIDGETCURPOS = 3;
  41.     
  42. const VIDGETLIGHTPEN = 4; 
  43. const VIDSETPAGE = 5; 
  44. const VIDSCROLLUP = 6; 
  45. const VIDSCROLLDN = 7; 
  46. const VIDGETCHARATT = 8;
  47.     
  48. const VIDPUTCHARATT = 9; 
  49. const VIDPUTCHARS = 10; 
  50. const VIDSETCOLOR = 11; 
  51. const VIDSETPIXEL = 12; 
  52. const VIDGETPIXEL = 13;
  53.     
  54. const VIDPUTCHARTTY = 14; 
  55. const VIDGETMODE = 15; 
  56. const VIDSETPAL = 16; 
  57. const VIDCHARTBL = 17; 
  58. const VIDSYSCFG = 18; 
  59. const VIDPUTSTR = 19;
  60.     
  61. const VIDDISPCOMBO = 0x1a; 
  62. const VIDBIOS = 0x1b; 
  63. const VIDSTATE = 0x1c;
  64.  
  65. const SCRMONO = 0;
  66. const SCRCGA = 1;
  67. const SCREGA = 2;
  68. const SCRVGA = 3;
  69.  
  70. const VID_BLACK = 0;
  71. const VID_BLUE = 1;
  72. const VID_GREEN = 2;
  73. const VID_CYAN = 3;
  74. const VID_RED = 4;
  75. const VID_MAGENTA = 5;
  76. const VID_BROWN = 6;
  77. const VID_LIGHTGRAY = 7;
  78. const VID_DARKGRAY = 8;
  79. const VID_LIGHTBLUE = 9;
  80. const VID_LIGHTGREEN = 10;
  81. const VID_LIGHTCYAN = 11;
  82. const VID_LIGHTRED = 12;
  83. const VID_LIGHTMAGENTA = 13;
  84. const VID_YELLOW = 14;
  85. const VID_WHITE = 15;
  86.  
  87. const VIDMODE_DEFAULT = -1;
  88. const VIDMODE_BW40 = 0;
  89. const VIDMODE_C40 = 1;
  90. const VIDMODE_BW80 = 2;
  91. const VIDMODE_C80 = 3;
  92. const VIDMODE_MONO = 7;
  93. const VIDMODE_EGAVGA = 64;
  94.  
  95. const SCR_CURSOR_ON = 1;
  96. const SCR_CURSOR_OFF = 0;
  97.  
  98. const BYTE SCR_DEFAULT_FILLCHAR = 176;
  99. const BYTE SCR_DEFAULT_DESKTOPCOLORS = (MakeBG(VID_LIGHTGRAY)+VID_BLUE);
  100. const BYTE SCR_DEFAULT_COLORS = (MakeBG(VID_BLUE)+VID_WHITE);
  101.  
  102. const BYTE SCR_MENU_BAR     = 0x01;
  103. const BYTE SCR_STATUS_BAR   = 0x02;
  104. const BYTE SCR_SYSTEM_ICON  = 0x04;
  105. const BYTE SCR_ABOUT_BOX    = 0x08;
  106. const BYTE SCR_DEFAULT_ATTRIBUTES = (SCR_MENU_BAR | SCR_STATUS_BAR);
  107.  
  108. class ScrDeskTop
  109.     {
  110.     friend class Screen;
  111.  
  112.     BYTE    color;
  113.     BYTE    attributes;
  114.     BYTE    clientheight;
  115.     BYTE    clientwidth;
  116.     BYTE    fillchar;
  117.  
  118. public:
  119.     ScrDeskTop( 
  120.         BYTE color = SCR_DEFAULT_DESKTOPCOLORS, 
  121.         BYTE attribute = SCR_DEFAULT_ATTRIBUTES, 
  122.         BYTE fillchar = SCR_DEFAULT_FILLCHAR);
  123.     BOOL pascal Paint(void);
  124.     };
  125.  
  126. typedef struct _screenparams
  127.     {
  128.     int numlines;
  129.     int numcols;
  130.     char far *screenBuf;
  131.     WORD far *curpos;
  132.     WORD cursorSize;
  133.     unsigned char currAttr;
  134.     BYTE mode;
  135.     BYTE currow;
  136.     BYTE curcol;
  137.     } SCRPARAMS;
  138.  
  139.  
  140. class OrgScreen
  141.     {
  142.     friend class Screen;
  143.  
  144. #ifdef OLD
  145.     int numlines;
  146.     int numcols;
  147.     char far *screenBuf;
  148.     unsigned far *curpos;
  149.     unsigned char currAttr;
  150.     BYTE mode;
  151. #else
  152.     SCRPARAMS params;
  153. #endif
  154. public:
  155.     OrgScreen(void)
  156.         {
  157.         }
  158.     };
  159.  
  160. class Screen
  161.     {
  162.     static OrgScreen orgScreen;
  163.     static ScrDeskTop *DeskTop;
  164. protected:
  165. #ifdef OLD
  166.     static int numlines;
  167.     static int numcols;
  168.     static char far *screenBuf;
  169.     static unsigned far *curpos;
  170.     static BYTE currAttr;
  171.     static BYTE mode;
  172. #else
  173.     static SCRPARAMS params;
  174. #endif
  175.     static BOOL wait_for_retrace;
  176.     static BOOL buffered;
  177.     static unsigned bufsize;
  178.     static char far *buffer;
  179.     static char *workbuffer;
  180. private:
  181.     static char *workbuf2;
  182.     static void far *org_screen_image;
  183.     static WORD org_screen_size;
  184.     static WORD org_screen_curpos;
  185. protected:
  186.  
  187.     void near pascal VidRamAccess(void far *dst, void far *src, int len);
  188.     BOOL near pascal CheckSysCopyRight(char far *ROMaddress, char *Copyright);
  189.     SCRPARAMS GetVidModeParams(BYTE *cols);
  190.  
  191. public:
  192.     Screen(void);
  193.     void Init(int newmode = VIDMODE_DEFAULT, 
  194.         BYTE desktop_colors = SCR_DEFAULT_DESKTOPCOLORS, 
  195.         BYTE screen_colors = SCR_DEFAULT_COLORS);
  196.     ~Screen(void);
  197.     void Paint(void);
  198.     void SetTextMode(int newmode);
  199.     void Write(char *str,WORD clr = params.currAttr);
  200.     void Write(unsigned char *str, WORD clr, int len);
  201.     void Read(char *str);
  202.     void Read(char *str, int len);
  203.     WORD far *Cursor(int x, int y);
  204.     void Cursor(BOOL on_off);
  205.     void Buffering(BOOL on_off);
  206.     void FlushBuffer(void);
  207.     void cdecl Printf(char *fmt, ...);
  208.     void SetForeGround(unsigned char c);
  209.     void SetBackGround(unsigned char c);
  210.     void Clear(void) { Clear(0,0,params.numlines,params.numcols); }
  211.     void Clear(int row, int col, int erow, int ecol, BYTE colors = params.currAttr);
  212.     void cdecl AtSay(int x, int y, char *fmt, ...);
  213.     int Lines(void) { return params.numlines;  }
  214.     int Columns(void) { return params.numcols; }
  215.     void SetAttribute(unsigned char c) { params.currAttr = c; }
  216.     unsigned char GetAttribute(void) { return params.currAttr; }
  217.     void WriteRaw(void far *buf, int len);
  218.     void ReadRaw(void far *buf, int len);
  219.     WORD far *GotoXY(int row, int col) { return Cursor(row,col); }
  220.     int GetMode(void) { return params.mode; };
  221.     void Exec(char *command, char *args[], char *message = NULL);
  222.  
  223.     friend class ScrDeskTop;
  224.     };
  225.  
  226. extern Screen *ScreenPtr;
  227.  
  228. void near pascal SetWords(void far *addr, unsigned val, unsigned len);
  229. void near pascal CpyWords(void far *dst, void far *src, unsigned n);
  230. BYTE near pascal VidGetMode(BYTE *cols);
  231. void near pascal VidSetMode(BYTE mode);
  232. BOOL near pascal IsEgaVga(void);
  233.  
  234. #endif
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.