home *** CD-ROM | disk | FTP | other *** search
/ Boldly Go Collection / version40.iso / TS / 17A / DRWIN101.ZIP / SCRUTIL.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-01  |  20.1 KB  |  393 lines

  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <dos.h>
  4. #include <conio.h>
  5.  
  6. #include "scrutil.hpp"
  7.  
  8. WORD far *scrseg=NULL;
  9.  
  10.  
  11. /****************************************************************************/
  12. /*  ptrcmp                                                                  */
  13. /****************************************************************************/
  14. /*-----------------------------Description----------------------------------*/
  15. /*  This function determines if two pointers are equal.  It is necessary    */
  16. /*  under the Intel 80x86 bullshit segmenting.                              */
  17. /*-----------------------------Arguments------------------------------------*/
  18. /*  void *p            first pointer to compare                             */
  19. /*  void *q            second pointer to compare                            */
  20. /*-----------------------------Return value---------------------------------*/
  21. /*  ptrcmp() returns 1 if the args point to the same place, 0 otherwise.    */
  22. /*-----------------------------Global constants-----------------------------*/
  23. /*-------------------Mod-------Global variables-----------------------------*/
  24. /*-----------------------------Functions called-----------------------------*/
  25. /*-----------------------------Constraints/Gotchas--------------------------*/
  26. /*--Date--------Programmer----------Comments--------------------------------*/
  27. /*  1990.01.01  D. Rogers           initial code                            */
  28. /****************************************************************************/
  29. int  ptrcmp(void far *p,void far *q)
  30. {
  31.   LWORD lp,lq;
  32.   lp=(LWORD)p;
  33.   lq=(LWORD)q;
  34.   lp=((lp>>12)&0x000FFFF0L)+(lp&0x0000FFFFL);   /*shift down segment and add*/
  35.   lq=((lq>>12)&0x000FFFF0L)+(lq&0x0000FFFFL);   /*shift down segment and add*/
  36.   return(lp==lq);
  37. }   /*ptrcmp*/
  38. /****************************************************************************/
  39.  
  40.  
  41. /****************************************************************************/
  42. /*  memcpynf, memcpyfn                                                      */
  43. /****************************************************************************/
  44. /*-----------------------------Description----------------------------------*/
  45. /*  These function are analogous to memcpy, but for mixed near:far or       */
  46. /*  far:near pointers.                                                      */
  47. /*-----------------------------Arguments------------------------------------*/
  48. /*-----------------------------Return value---------------------------------*/
  49. /*-----------------------------Global constants-----------------------------*/
  50. /*-------------------Mod-------Global variables-----------------------------*/
  51. /*-----------------------------Functions called-----------------------------*/
  52. /*-----------------------------Constraints/Gotchas--------------------------*/
  53. /*--Date--------Programmer----------Comments--------------------------------*/
  54. /*  1990.01.01  D. Rogers           initial code                            */
  55. /****************************************************************************/
  56. void memcpynf(void near *n,void far *f,WORD k)    /*copies to near from far*/
  57. {
  58.   BYTE far *bf;
  59.   BYTE near *bn;
  60.   bf=(BYTE far *)f;
  61.   bn=(BYTE near *)n;
  62.   while (k-->0) *bn++=*bf++;
  63. }   /*memcpynf*/
  64.  
  65. void memcpyfn(void far *f,void near *n,WORD k)    /*copies to far from near*/
  66. {
  67.   BYTE far *bf;
  68.   BYTE near *bn;
  69.   bf=(BYTE far *)f;
  70.   bn=(BYTE near *)n;
  71.   while (k-->0) *bf++=*bn++;
  72. }   /*memcpyfn*/
  73. /****************************************************************************/
  74.  
  75.  
  76. /****************************************************************************/
  77. /*  getkey                                                                  */
  78. /****************************************************************************/
  79. /*-----------------------------Description----------------------------------*/
  80. /*  This function returns the key pressed.  If a special function key is    */
  81. /*  pressed, it returns the scan code of the key + 256.                     */
  82. /*  Constants are defined in [cutil.h] for use with this function.          */
  83. /*-----------------------------Arguments------------------------------------*/
  84. /*-----------------------------Return value---------------------------------*/
  85. /*  Returns 256+scan code for special keys, ASCII value for others.         */
  86. /*-----------------------------Global constants-----------------------------*/
  87. /*-------------------Mod-------Global variables-----------------------------*/
  88. /*-----------------------------Functions called-----------------------------*/
  89. /*-----------------------------Constraints----------------------------------*/
  90. /*--Date--------Programmer---------Comments---------------------------------*/
  91. /*  1990.01.01  D. Rogers          initial code                             */
  92. /****************************************************************************/
  93. int getkey(void)
  94. {
  95.   int c;
  96.   c=getch();
  97.   if (c)
  98.     return(c);
  99.   else
  100.     return(0x0100+getch());
  101. }   /*getkey*/
  102. /****************************************************************************/
  103.  
  104.  
  105. /****************************************************************************/
  106. /*  getcrow                                                                 */
  107. /****************************************************************************/
  108. /*-----------------------------Description----------------------------------*/
  109. /*  This function returns the current absolute cursor row.                  */
  110. /*-----------------------------Arguments------------------------------------*/
  111. /*-----------------------------Return value---------------------------------*/
  112. /*  getcrow() returns the current row as an unsigned int.                   */
  113. /*-----------------------------Global constants-----------------------------*/
  114. /*-------------------Mod-------Global variables-----------------------------*/
  115. /*-----------------------------Functions called-----------------------------*/
  116. /*-----------------------------Constraints/Gotchas--------------------------*/
  117. /*  Rows normally range from 0-24.                                          */
  118. /*--Date--------Programmer----------Comments--------------------------------*/
  119. /*  1990.01.01  D. Rogers           initial code                            */
  120. /****************************************************************************/
  121. WORD getcrow(void)
  122. {
  123.   union REGS r;
  124.  
  125.   r.x.bx=0;                            /*assume page 0*/
  126.   r.h.ah=0x03;                         /*indicate get-cursor-info*/
  127.   int86(0x10,&r,&r);                   /*call Video Services interrupt*/
  128.   return (r.h.dh);                     /*return row (0=first row)*/
  129. }   /*getcrow*/
  130. /****************************************************************************/
  131.  
  132.  
  133. /****************************************************************************/
  134. /*  getccol                                                                 */
  135. /****************************************************************************/
  136. /*-----------------------------Description----------------------------------*/
  137. /*  This function returns the current absolute cursor column.               */
  138. /*-----------------------------Arguments------------------------------------*/
  139. /*-----------------------------Return value---------------------------------*/
  140. /*  getccol() return the absolute cursor column as an unsigned int.         */
  141. /*-----------------------------Global constants-----------------------------*/
  142. /*-------------------Mod-------Global variables-----------------------------*/
  143. /*-----------------------------Functions called-----------------------------*/
  144. /*-----------------------------Constraints/Gotchas--------------------------*/
  145. /*  Columns usually range from 0-79.                                        */
  146. /*--Date--------Programmer----------Comments--------------------------------*/
  147. /*  1990.01.01  D. Rogers           initial code                            */
  148. /****************************************************************************/
  149. WORD getccol(void)
  150. {
  151.   union REGS r;
  152.  
  153.   r.x.bx=0;                            /*assume page 0*/
  154.   r.h.ah=0x03;                         /*indicate get-cursor-info*/
  155.   int86(0x10,&r,&r);                   /*call Video Services interrupt*/
  156.   return (r.h.dl);                     /*return column (0=first row)*/
  157. }   /*getccol*/
  158. /****************************************************************************/
  159.  
  160.  
  161. /****************************************************************************/
  162. /*  setcpos                                                                 */
  163. /****************************************************************************/
  164. /*-----------------------------Description----------------------------------*/
  165. /*  This function sets the current absolute cursor position to the row and  */
  166. /*  column specified.                                                       */
  167. /*-----------------------------Arguments------------------------------------*/
  168. /*  WORD row           absolute cursor row on screen (usually 0-24)         */
  169. /*  WORD col           absolute cursor column on screen (usually 0-79)      */
  170. /*-----------------------------Return value---------------------------------*/
  171. /*-----------------------------Global constants-----------------------------*/
  172. /*-------------------Mod-------Global variables-----------------------------*/
  173. /*-----------------------------Functions called-----------------------------*/
  174. /*-----------------------------Constraints/Gotchas--------------------------*/
  175. /*--Date--------Programmer----------Comments--------------------------------*/
  176. /*  1990.01.01  D. Rogers           initial code                            */
  177. /****************************************************************************/
  178. void setcpos(WORD row,WORD col)
  179. {
  180.   union REGS r;
  181.  
  182.   r.x.bx=0;                            /*assume page 0*/
  183.   r.h.dh=row;                          /*cursor row*/
  184.   r.h.dl=col;                          /*cursor col*/
  185.   r.h.ah=0x02;                         /*indicate set-cursor-position*/
  186.   int86(0x10,&r,&r);                   /*call Video Services interrupt*/
  187. }   /*setcpos*/
  188. /****************************************************************************/
  189.  
  190.  
  191. /****************************************************************************/
  192. /*  getcsiz                                                                 */
  193. /****************************************************************************/
  194. /*-----------------------------Description----------------------------------*/
  195. /*  This function finds out how big the current cursor is on the screen.    */
  196. /*-----------------------------Arguments------------------------------------*/
  197. /*-----------------------------Return value---------------------------------*/
  198. /*  getcsiz() returns the cursor size in an unsigned int whose most         */
  199. /*  significant byte contains the first scan line of the cursor and whose   */
  200. /*  least significant byte contains the last scan line of the cursor.       */
  201. /*-----------------------------Global constants-----------------------------*/
  202. /*-------------------Mod-------Global variables-----------------------------*/
  203. /*-----------------------------Functions called-----------------------------*/
  204. /*-----------------------------Constraints/Gotchas--------------------------*/
  205. /*--Date--------Programmer----------Comments--------------------------------*/
  206. /*  1990.01.01  D. Rogers           initial code                            */
  207. /****************************************************************************/
  208. WORD getcsiz(void)
  209. {
  210.   union REGS r;
  211.  
  212.   r.x.bx=0;                            /*assume page 0*/
  213.   r.h.ah=0x03;                         /*indicate get-cursor-info*/
  214.   int86(0x10,&r,&r);                   /*call Video Services interrupt*/
  215.   return (r.x.cx);                     /*return cursor scan lines*/
  216. }   /*getcsiz*/
  217. /****************************************************************************/
  218.  
  219.  
  220. /****************************************************************************/
  221. /*  setcsiz                                                                 */
  222. /****************************************************************************/
  223. /*-----------------------------Description----------------------------------*/
  224. /*  This function sets the cursor size using the same format as is          */
  225. /*  returned by getcsiz().                                                  */
  226. /*-----------------------------Arguments------------------------------------*/
  227. /*  WORD siz           cursor size (MSB: 1st scan line, LSB: last)          */
  228. /*-----------------------------Return value---------------------------------*/
  229. /*-----------------------------Global constants-----------------------------*/
  230. /*-------------------Mod-------Global variables-----------------------------*/
  231. /*-----------------------------Functions called-----------------------------*/
  232. /*-----------------------------Constraints/Gotchas--------------------------*/
  233. /*--Date--------Programmer----------Comments--------------------------------*/
  234. /*  1990.01.01  D. Rogers           initial code                            */
  235. /****************************************************************************/
  236. void setcsiz(WORD siz)
  237. {
  238.   union REGS r;
  239.  
  240.   r.x.bx=0;                            /*assume page 0*/
  241.   r.x.cx=siz;                          /*cursor size (start/stop scan line)*/
  242.   r.h.ah=0x01;                         /*indicate set-cursor-size*/
  243.   int86(0x10,&r,&r);                   /*call Video Services interrupt*/
  244. }   /*setcsiz*/
  245.  
  246.  
  247. /****************************************************************************/
  248. /*  getsmod                                                                 */
  249. /****************************************************************************/
  250. /*-----------------------------Description----------------------------------*/
  251. /*  This function returns the current video mode of the PC by making a      */
  252. /*  call to the DOS Video Services interrupt.                               */
  253. /*-----------------------------Arguments------------------------------------*/
  254. /*-----------------------------Return value---------------------------------*/
  255. /*  getsmod() returns the video mode as an unsigned int.                    */
  256. /*-----------------------------Global constants-----------------------------*/
  257. /*-------------------Mod-------Global variables-----------------------------*/
  258. /*-----------------------------Functions called-----------------------------*/
  259. /*-----------------------------Constraints/Gotchas--------------------------*/
  260. /*--Date--------Programmer----------Comments--------------------------------*/
  261. /*  1990.01.01  D. Rogers           initial code                            */
  262. /****************************************************************************/
  263. WORD getsmod(void)
  264. {
  265.   union REGS ir,or;                    /*register structs*/
  266.   WORD mode;                           /*mode value*/
  267.  
  268.   ir.x.bx=0;                           /*assume page 0*/
  269.   ir.h.ah=0x0F;                        /*indicate get-screen-mode*/
  270.   int86(0x10,&ir,&or);                 /*call Video Services interrupt*/
  271.   mode=or.h.al;                        /*see about mode*/
  272.  
  273.   if (or.h.al==TEXT_80_25) {           /*see if need to check for special*/
  274.     ir.x.bx=0x0003;
  275.     ir.x.ax=0x1130;
  276.     int86(0x10,&ir,&or);
  277.     switch(or.h.dl+1) {                /*look at rows..*/
  278.     case 43:
  279.     case 50:
  280.       mode=TEXT_80_HI;
  281.       break;
  282.     default: ;
  283.     }   /*switch*/
  284.   }   /*if checking for special*/
  285.   return mode;                         /*return video mode*/
  286. }   /*getsmod*/
  287.  
  288.  
  289. /****************************************************************************/
  290. /*  setsmod                                                                 */
  291. /****************************************************************************/
  292. /*-----------------------------Description----------------------------------*/
  293. /*  This function sets the current video mode of the PC by making a call    */
  294. /*  to the DOS Video Services interrupt.                                    */
  295. /*-----------------------------Arguments------------------------------------*/
  296. /*  WORD mod           video mode to be set                                 */
  297. /*-----------------------------Return value---------------------------------*/
  298. /*-----------------------------Global constants-----------------------------*/
  299. /*-------------------Mod-------Global variables-----------------------------*/
  300. /*-----------------------------Functions called-----------------------------*/
  301. /*-----------------------------Constraints/Gotchas--------------------------*/
  302. /*--Date--------Programmer----------Comments--------------------------------*/
  303. /*  1990.01.01  D. Rogers           initial code                            */
  304. /****************************************************************************/
  305. void setsmod(WORD mod)
  306. {
  307.   union REGS r;
  308.  
  309.   if (mod>0x1000) {                    /*if special mode..*/
  310.     r.x.bx=0;                          /*..*/
  311.     r.x.ax=TEXT_80_25;                 /*..first force to text mode*/
  312.     int86(0x10,&r,&r);                 /*..call video services interrupt*/
  313.   }   /*if higher mode*/
  314.   r.x.bx=0;                            /*force page 0*/
  315.   r.x.ax=mod;                          /*video mode to set*/
  316.   int86(0x10,&r,&r);                   /*call Video Services interrupt*/
  317. }   /*setsmod*/
  318.  
  319.  
  320. WORD getsrows(void)
  321. {
  322.   union REGS r;                        /*register-holding union*/
  323.  
  324.   switch (getsmod()) {                 /*go rows via mode*/
  325.   case TEXT_40_25_BW:
  326.   case TEXT_40_25:
  327.   case TEXT_80_25_BW:
  328.   case TEXT_80_25:
  329.   case MONO_80_25:
  330.     return 25;
  331.   case TEXT_80_HI:
  332.     r.x.ax=0x1130;                     /*.*/
  333.     r.x.bx=0x0003;                     /*.*/
  334.     int86(0x10,&r,&r);                 /*call video services interrupt*/
  335.     return r.h.dl+1;                   /*return number of rows on screen*/
  336.   default: ;
  337.   }   /*switch*/
  338.   return 0;                            /*must be in a text mode*/
  339. }   /*getsrows*/
  340.  
  341.  
  342. WORD getscols(void)
  343. {
  344.   return *((WORD far *)SCRCOLUMN);     /*columns per row*/
  345. }   /*getscols*/
  346.  
  347.  
  348. WORD getsrowscols(void)
  349. {
  350.   union REGS r;                        /*register-holding union*/
  351.   r.x.ax=0x1130;                       /*.*/
  352.   r.x.bx=0x0003;                       /*.*/
  353.   int86(0x10,&r,&r);                   /*call video services interrupt*/
  354.   r.h.dh=*((BYTE far *)SCRCOLUMN);     /*columns per row*/
  355.   return r.x.dx+1;                     /*return number of rows & columns*/
  356. }   /*getsrows*/
  357.  
  358.  
  359. /****************************************************************************/
  360. /*  setscrseg                                                               */
  361. /****************************************************************************/
  362. /*-----------------------------Description----------------------------------*/
  363. /*  This function sets the screen (video) segment variable, scrseg,         */
  364. /*  according to the video monitor available.                               */
  365. /*-----------------------------Arguments------------------------------------*/
  366. /*-----------------------------Return value---------------------------------*/
  367. /*-----------------------------Global constants-----------------------------*/
  368. /*-------------------Mod-------Global variables-----------------------------*/
  369. /*-----------------------------Functions called-----------------------------*/
  370. /*-----------------------------Constraints/Gotchas--------------------------*/
  371. /*--Date--------Programmer----------Comments--------------------------------*/
  372. /*  1990.01.01  A. Turing           initial code                            */
  373. /****************************************************************************/
  374. WORD far *setscrseg(void)
  375. {
  376.   switch (getsmod()) {                 /*go rows via mode*/
  377.   case MONO_80_25:
  378.     scrseg=(WORD far*)SCRSEG_MONO;
  379.     break;
  380.   case TEXT_40_25_BW:
  381.   case TEXT_40_25:
  382.   case TEXT_80_25_BW:
  383.   case TEXT_80_25:
  384.   case TEXT_80_HI:
  385.     scrseg=(WORD far*)SCRSEG_COLOR;
  386.     break;
  387.   default:
  388.     scrseg=NULL;
  389.   }   /*switch*/
  390.   return scrseg;
  391. }   /*setscrseg*/
  392.  
  393.