home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume27 / sfs / part02 < prev    next >
Encoding:
Text File  |  1991-12-27  |  55.2 KB  |  2,277 lines

  1. Newsgroups: comp.sources.misc
  2. From: tcamp@hercules.acpub.duke.edu (Ted Campbell)
  3. Subject:  v27i002:  sfs - Space Flight Simulator, Part02/21
  4. Message-ID: <1991Dec24.045100.29424@sparky.imd.sterling.com>
  5. X-Md4-Signature: aaf99196513687f129d79722a80533a3
  6. Date: Tue, 24 Dec 1991 04:51:00 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: tcamp@hercules.acpub.duke.edu (Ted Campbell)
  10. Posting-number: Volume 27, Issue 2
  11. Archive-name: sfs/part02
  12. Environment: IBMPC && EGA/VGA, UNIX-PC && MGR, UNIX && X,
  13.  
  14. #!/bin/sh
  15. # do not concatenate these parts, unpack them in order with /bin/sh
  16. # file io/gr/gr_def.c continued
  17. #
  18. if test ! -r _shar_seq_.tmp; then
  19.     echo 'Please unpack part 1 first!'
  20.     exit 1
  21. fi
  22. (read Scheck
  23.  if test "$Scheck" != 2; then
  24.     echo Please unpack part "$Scheck" next!
  25.     exit 1
  26.  else
  27.     exit 0
  28.  fi
  29. ) < _shar_seq_.tmp || exit 1
  30. if test ! -f _shar_wnt_.tmp; then
  31.     echo 'x - still skipping io/gr/gr_def.c'
  32. else
  33. echo 'x - continuing file io/gr/gr_def.c'
  34. sed 's/^X//' << 'SHAR_EOF' >> 'io/gr/gr_def.c' &&
  35. X    def_circle( GR_PRIMARY, x * 5, y * 5, (y/2)*3, WHITE, HATCH );
  36. X   gr_text( GR_PRIMARY, x * 10, y * 5, "Hatch circle", WHITE, BLACK );
  37. X
  38. X   kb_rx();
  39. X   kb_deinit();
  40. X   gr_deinit();
  41. X   }
  42. X
  43. #endif
  44. X
  45. /****************************************************************
  46. X
  47. X    def_line()
  48. X
  49. ****************************************************************/
  50. X
  51. def_line( screen, x1, y1, x2, y2, color, style )
  52. X   int screen;
  53. X   int x1, y1, x2, y2;
  54. X   int color, style;
  55. X   {
  56. X   register int t, dist;
  57. X   int xerr, yerr, dx, dy, incx, incy;
  58. X   int x_val, y_val;
  59. X
  60. #if CHECK_PARAMS
  61. X   if ( ( x1 < 0 ) || ( x1 > main_window.xmax ))
  62. X      {
  63. X      sprintf( bw_ebuf, "[pr:] gr_line(): x1 value is %d", x1 );
  64. X      bw_error( bw_ebuf );
  65. X      return BW_ERROR;
  66. X      }
  67. X   if ( ( x2 < 0 ) || ( x2 > main_window.xmax ))
  68. X      {
  69. X      sprintf( bw_ebuf, "[pr:] gr_line(): x2 value is %d", x2 );
  70. X      bw_error( bw_ebuf );
  71. X      return BW_ERROR;
  72. X      }
  73. X   if ( ( y1 < 0 ) || ( y1 > main_window.ymax ))
  74. X      {
  75. X      sprintf( bw_ebuf, "[pr:] gr_line(): y1 value is %d", y1 );
  76. X      bw_error( bw_ebuf );
  77. X      return BW_ERROR;
  78. X      }
  79. X   if ( ( y2 < 0 ) || ( y2 > main_window.ymax ))
  80. X      {
  81. X      sprintf( bw_ebuf, "[pr:] gr_line(): y2 value is %d", y2 );
  82. X      bw_error( bw_ebuf );
  83. X      return BW_ERROR;
  84. X      }
  85. #endif
  86. X
  87. X   xerr = yerr = 0;
  88. X   dx = x2 - x1;
  89. X   dy = y2 - y1;
  90. X   x_val = x1;
  91. X   y_val = y1;
  92. X
  93. X   if ( dx > 0 )
  94. X      {
  95. X      incx = 1;
  96. X      }
  97. X   else if ( dx == 0 )
  98. X      {
  99. X      incx = 0;
  100. X      }
  101. X   else
  102. X      {
  103. X      incx = -1;
  104. X      }
  105. X
  106. X   if ( dy > 0 )
  107. X      {
  108. X      incy = 1;
  109. X      }
  110. X   else if ( dy == 0 )
  111. X      {
  112. X      incy = 0;
  113. X      }
  114. X   else
  115. X      {
  116. X      incy = -1;
  117. X      }
  118. X
  119. X   dx = abs(dx);
  120. X   dy = abs(dy);
  121. X
  122. X   dist = (dx > dy) ? dx : dy;
  123. X
  124. X   for ( t = 0; t <= ( dist + 1 ); t++ )
  125. X      {
  126. X      switch( style )
  127. X     {
  128. X     case HOLLOW:
  129. X        gr_pixel( screen, x_val, y_val, BLACK );
  130. X        break;
  131. X     case SOLID:
  132. X        gr_pixel( screen, x_val, y_val, color );
  133. X        break;
  134. X     case GRID:
  135. X     case HATCH:
  136. X        if ( ( ( x_val + y_val ) % 2 ) == 1 )
  137. X           {
  138. X           gr_pixel( screen, x_val, y_val, color );
  139. X           }
  140. X        break;
  141. X     }
  142. X      xerr += dx;
  143. X      yerr += dy;
  144. X      if ( xerr > dist )
  145. X     {
  146. X     xerr -= dist;
  147. X     x_val += incx;
  148. X     }
  149. X      if ( yerr > dist )
  150. X     {
  151. X     yerr -= dist;
  152. X     y_val += incy;
  153. X     }
  154. X      }
  155. X   }
  156. X
  157. /****************************************************************
  158. X
  159. X    def_rectangle()
  160. X
  161. ****************************************************************/
  162. X
  163. def_rectangle( screen, x1, y1, x2, y2, color, style )
  164. X   int screen;
  165. X   int x1, y1, x2, y2;
  166. X   int color, style;
  167. X   {
  168. X   register int x_val, y_val;
  169. X
  170. #if CHECK_PARAMS
  171. X   if ( ( x1 < 0 ) || ( x1 > main_window.xmax ))
  172. X      {
  173. X      sprintf( bw_ebuf, "[pr:] gr_rectangle(): x1 value is %d", x1 );
  174. X      bw_error( bw_ebuf );
  175. X      return BW_ERROR;
  176. X      }
  177. X   if ( ( x2 < 0 ) || ( x2 > main_window.xmax ))
  178. X      {
  179. X      sprintf( bw_ebuf, "[pr:] gr_rectangle(): x2 value is %d", x2 );
  180. X      bw_error( bw_ebuf );
  181. X      return BW_ERROR;
  182. X      }
  183. X   if ( ( y1 < 0 ) || ( y1 > main_window.ymax ))
  184. X      {
  185. X      sprintf( bw_ebuf, "[pr:] gr_rectangle(): y1 value is %d", y1 );
  186. X      bw_error( bw_ebuf );
  187. X      return BW_ERROR;
  188. X      }
  189. X   if ( ( y2 < 0 ) || ( y2 > main_window.ymax ))
  190. X      {
  191. X      sprintf( bw_ebuf, "[pr:] gr_rectangle(): y2 value is %d", y2 );
  192. X      bw_error( bw_ebuf );
  193. X      return BW_ERROR;
  194. X      }
  195. #endif
  196. X
  197. X   /*  First draw border around the rectangle */
  198. X
  199. X   gr_line( screen, x1, y1, x2, y1, color, SOLID );
  200. X   gr_line( screen, x2, y1, x2, y2, color, SOLID );
  201. X   gr_line( screen, x1, y1, x1, y2, color, SOLID );
  202. X   gr_line( screen, x1, y2, x2, y2, color, SOLID );
  203. X
  204. X   switch( style )
  205. X      {
  206. X      case HOLLOW:
  207. X     break;
  208. X      case SOLID:
  209. X     for ( y_val = y1 + 1; y_val < y2; ++y_val )
  210. X        {
  211. X        gr_line( screen, x1 + 1, y_val, x2 - 1, y_val, color, SOLID );
  212. X        }
  213. X     break;
  214. X      case GRID:
  215. X     for ( y_val = y1 + 1; y_val < y2; ++y_val )
  216. X        {
  217. X        gr_line( screen, x1 + 1, y_val, x2 - 1, y_val, color, GRID );
  218. X        }
  219. X     break;
  220. X      case HATCH:
  221. X     for ( y_val = y1 + 1; y_val < y2; ++y_val )
  222. X        {
  223. X        if ( ( y_val % 3 ) == 1 )
  224. X           {
  225. X           gr_line( screen, x1 + 1, y_val, x2 - 1, y_val, color, SOLID );
  226. X           }
  227. X        }
  228. X     for ( x_val = x1 + 1; x_val < x2; ++x_val )
  229. X        {
  230. X        if ( ( x_val % 3 ) == 1 )
  231. X           {
  232. X           gr_line( screen, x_val, y1 + 1, x_val, y2 - 1, color, SOLID );
  233. X           }
  234. X        }
  235. X     break;
  236. X      }
  237. X
  238. X   }
  239. X
  240. /****************************************************************
  241. X
  242. X   def_circle()    Draw circle using gr line routines
  243. X
  244. ****************************************************************/
  245. X
  246. def_circle( screen, x, y, radius, color, style )
  247. X   int screen;
  248. X   int x, y, radius;
  249. X   int color, style;
  250. X   {
  251. X   register int y_val;
  252. X   int top_y, bot_y, prev_ty, prev_by;
  253. X   int x1, x2, prev_x1, prev_x2;
  254. X   int width, x_val;
  255. X   double angle, y_cor;
  256. X
  257. #ifdef  OLD_DEBUG
  258. X   sprintf( bw_ebuf, "circle: r %d, y %d, x %d   ",
  259. X      radius, y, x );
  260. X   bw_error( bw_ebuf );
  261. #endif
  262. #if CHECK_PARAMS
  263. X   if ( ( x < 0 ) || ( x > main_window.xmax ))
  264. X      {
  265. X      sprintf( bw_ebuf, "[pr:] def_circle(): x value is %d", x );
  266. X      bw_error( bw_ebuf );
  267. X      return BW_ERROR;
  268. X      }
  269. X   if ( ( y < 0 ) || ( y > main_window.ymax ))
  270. X      {
  271. X      sprintf( bw_ebuf, "[pr:] def_circle(): y value is %d", y );
  272. X      bw_error( bw_ebuf );
  273. X      return BW_ERROR;
  274. X      }
  275. #endif
  276. X
  277. X   width = ( radius * gr_pysize * ACCURACY ) / ( gr_pxsize * ACCURACY );
  278. X   prev_by = prev_ty = bot_y = top_y = y;
  279. X   prev_x1 = x1 = x - width;
  280. X   prev_x2 = x2 = x + width;
  281. X
  282. X   switch( style )
  283. X      {
  284. X      case HOLLOW:
  285. X     break;
  286. X      case SOLID:
  287. X     gr_line( screen, x1 + 1, top_y, x2 - 1, top_y, color, SOLID );
  288. X     gr_line( screen, x1 + 1, bot_y, x2 - 1, bot_y, color, SOLID );
  289. X     break;
  290. X      case GRID:
  291. X     gr_line( screen, x1 + 1, top_y, x2 - 1, top_y, color, GRID );
  292. X     gr_line( screen, x1 + 1, bot_y, x2 - 1, bot_y, color, GRID );
  293. X     break;
  294. X      case HATCH:
  295. X     if ( ( top_y % 2 ) == 1 )
  296. X        {
  297. X        gr_line( screen, x1 + 1, top_y, x2 - 1, top_y, color, SOLID );
  298. X        gr_line( screen, x1 + 1, bot_y, x2 - 1, bot_y, color, SOLID );
  299. X        }
  300. X     break;
  301. X      }
  302. X   for ( y_val = 1; y_val <= ( radius - 1 ); ++y_val )
  303. X      {
  304. X      top_y = y + y_val;
  305. X      bot_y = y - y_val;
  306. X
  307. X      y_cor = ( y_val * gr_pysize * ACCURACY ) / ( gr_pxsize * ACCURACY );
  308. X      angle = asin( ( y_cor ) / ((double) width ) );
  309. X
  310. #ifdef  OLD_DEBUG
  311. X      sprintf( bw_ebuf, "angle %.2lf deg   ",
  312. X     angle * RAD_DEG );
  313. X      bw_error( bw_ebuf );
  314. #endif
  315. X
  316. #ifdef  OLD_DEBUG
  317. X      sprintf( bw_ebuf, "tan( angle ) %.2lf deg   ",
  318. X     tan( angle ) );
  319. X      bw_error( bw_ebuf );
  320. #endif
  321. X      x_val = (int) ( y_cor / tan( angle ));
  322. #ifdef  OLD_DEBUG
  323. X      sprintf( bw_ebuf, "angle %.2lf deg, y %d, x %d   ",
  324. X     angle * RAD_DEG, y_val, x_val );
  325. X      bw_error( bw_ebuf );
  326. #endif
  327. X
  328. X      x1 = x - x_val;
  329. X      x2 = x + x_val;
  330. X
  331. X      gr_line( screen, x2, top_y, prev_x2, prev_ty, color, SOLID );
  332. X      gr_line( screen, x1, top_y, prev_x1, prev_ty, color, SOLID );
  333. X      gr_line( screen, x2, bot_y, prev_x2, prev_by, color, SOLID );
  334. X      gr_line( screen, x1, bot_y, prev_x1, prev_by, color, SOLID );
  335. X
  336. X      switch( style )
  337. X     {
  338. X     case HOLLOW:
  339. X        break;
  340. X     case SOLID:
  341. X        gr_line( screen, x1 + 1, top_y, x2 - 1, top_y, color, SOLID );
  342. X        gr_line( screen, x1 + 1, bot_y, x2 - 1, bot_y, color, SOLID );
  343. X        break;
  344. X     case GRID:
  345. X        gr_line( screen, x1 + 1, top_y, x2 - 1, top_y, color, GRID );
  346. X        gr_line( screen, x1 + 1, bot_y, x2 - 1, bot_y, color, GRID );
  347. X        break;
  348. X     case HATCH:
  349. X        if ( ( top_y % 2 ) == 1 )
  350. X           {
  351. X           gr_line( screen, x1 + 1, top_y, x2 - 1, top_y, color, SOLID );
  352. X           gr_line( screen, x1 + 1, bot_y, x2 - 1, bot_y, color, SOLID );
  353. X           }
  354. X        break;
  355. X     }
  356. X
  357. X      prev_x1 = x1;
  358. X      prev_x2 = x2;
  359. X      prev_ty = top_y;
  360. X      prev_by = bot_y;
  361. X
  362. X      }
  363. X
  364. X   x2 = x1 = x;
  365. X   top_y = y + radius;
  366. X   bot_y = y - radius;
  367. X
  368. X   gr_line( screen, x2, top_y, prev_x2, prev_ty, color, SOLID );
  369. X   gr_line( screen, x1, top_y, prev_x1, prev_ty, color, SOLID );
  370. X   gr_line( screen, x2, bot_y, prev_x2, prev_by, color, SOLID );
  371. X   gr_line( screen, x1, bot_y, prev_x1, prev_by, color, SOLID );
  372. X   }
  373. X
  374. #ifdef  STANDALONE
  375. X
  376. bw_error( s )
  377. X   char *s;
  378. X   {
  379. X   gr_text( GR_PRIMARY, 10, 10, s, WHITE, BLACK );
  380. X   kb_rx();
  381. X   }
  382. X
  383. #endif
  384. X
  385. SHAR_EOF
  386. echo 'File io/gr/gr_def.c is complete' &&
  387. chmod 0644 io/gr/gr_def.c ||
  388. echo 'restore of io/gr/gr_def.c failed'
  389. Wc_c="`wc -c < 'io/gr/gr_def.c'`"
  390. test 12686 -eq "$Wc_c" ||
  391.     echo 'io/gr/gr_def.c: original size 12686, current size' "$Wc_c"
  392. rm -f _shar_wnt_.tmp
  393. fi
  394. # ============= io/gr/gr_ibmpc.c ==============
  395. if test -f 'io/gr/gr_ibmpc.c' -a X"$1" != X"-c"; then
  396.     echo 'x - skipping io/gr/gr_ibmpc.c (File already exists)'
  397.     rm -f _shar_wnt_.tmp
  398. else
  399. > _shar_wnt_.tmp
  400. echo 'x - extracting io/gr/gr_ibmpc.c (Text)'
  401. sed 's/^X//' << 'SHAR_EOF' > 'io/gr/gr_ibmpc.c' &&
  402. /****************************************************************
  403. X
  404. X    gr_ibmpc.c      Implementation of Bywater Graphics Interface
  405. X            for IBM PC (tm) and compatibles
  406. X            utilizing Microsoft QuickC (tm)
  407. X
  408. X            Copyright (c) 1991, Ted A. Campbell
  409. X
  410. X            Bywater Software
  411. X            P. O. Box 4023 
  412. X            Duke Station 
  413. X            Durham, NC  27706
  414. X
  415. X            email: tcamp@hercules.acpub.duke.edu
  416. X
  417. X    Copyright and Permissions Information:
  418. X
  419. X    All U.S. and international copyrights are claimed by the
  420. X    author. The author grants permission to use this code
  421. X    and software based on it under the following conditions:
  422. X    (a) in general, the code and software based upon it may be 
  423. X    used by individuals and by non-profit organizations; (b) it
  424. X    may also be utilized by governmental agencies in any country,
  425. X    with the exception of military agencies; (c) the code and/or
  426. X    software based upon it may not be sold for a profit without
  427. X    an explicit and specific permission from the author, except
  428. X    that a minimal fee may be charged for media on which it is
  429. X    copied, and for copying and handling; (d) the code must be 
  430. X    distributed in the form in which it has been released by the
  431. X    author; and (e) the code and software based upon it may not 
  432. X    be used for illegal activities. 
  433. X
  434. ****************************************************************/
  435. X
  436. #include "stdio.h"
  437. #include "dos.h"
  438. #include "graph.h"
  439. #include "bw.h"
  440. #include "gr.h"
  441. #include "malloc.h"
  442. X
  443. /*#define DEBUG */          /* Include Debugging info */
  444. #define SET_MONOVGA     FALSE
  445. #define CHECK_PARAMS    TRUE
  446. #define LINE_BLIT       TRUE
  447. #define SIGNON          FALSE
  448. #define DEF_LINE        FALSE
  449. #define DEF_RECTANGLE   FALSE
  450. #define DEF_CIRCLE      FALSE
  451. #define HMP_RATIO       8             /* Horizontal Mickey/Pixel Ratio */
  452. #define VMP_RATIO       16            /* Vertical Mickey/Pixel Ratio */
  453. #define ACC             30
  454. #define IMAGES          64
  455. X
  456. int     gr_screens;
  457. int    gr_colors;
  458. int    gr_pxsize;
  459. int    gr_pysize;
  460. int    gr_ismouse;
  461. int     gr_clipping = TRUE;
  462. int     gr_blitting;
  463. int     gr_saving = TRUE;
  464. X
  465. struct gr_window *ibm_window;   /* structure for window info    */
  466. int ibm_px;             /* relative size of pixel, x axis       */
  467. int ibm_py;             /* relative size of pixel, y axis       */
  468. int ibm_vmode;          /* video mode for IBM equipment         */
  469. int ibm_imode;          /* initial video mode */
  470. int ibm_ishidden = FALSE; /* boolean: is display "hidden"       */
  471. struct videoconfig
  472. X    ibm_vc;         /* internal structure for video configuration */
  473. int msm_exist = FALSE;  /* boolean:  is there a mouse?          */
  474. long    miaddr;                 /* mouse interupt routine address */
  475. union   REGS ibm_registers;     /* cpu register for use of DOS calls */
  476. struct  SREGS segreg;           /* cpu segment registers             */
  477. static  int msm_buttons;        /* number of buttons on the mouse */
  478. char    far *hgc_location;      /* location to change for Hercules */
  479. static  int msm_oldbut;         /* previous state of mouse buttons */
  480. static  int msm_showcounter;    /* keep track of mouse show status */
  481. static  int m_col, m_row;       /* current column, row */
  482. static  int m_but;              /* right button depressed */
  483. char    fontfile[12] = "*.fon";
  484. char    *ibm_images[ IMAGES ];  /* array of pointers to image buffers */
  485. X
  486. #if     LINE_BLIT
  487. char far *xfr_mem;
  488. #else
  489. char huge *xfr_mem;
  490. #endif
  491. X
  492. unsigned char fs[ 20 ];
  493. X
  494. unsigned char fr[ 40 ];
  495. X
  496. struct  _fontinfo fi;
  497. X
  498. /***    Define fill grids ***/
  499. X
  500. char _fill_blank[ 8 ] = {   0,   0,   0,   0,   0,   0,   0,   0 };
  501. char _fill_grid[ 8 ]  = { 170,  85, 170,  85, 170,  85, 170,  85 };
  502. char _fill_full[ 8 ]  = { 255, 255, 255, 255, 255, 255, 255, 255 };
  503. char _fill_hatch[ 8 ] = {  17, 255,  68,  68,  68, 255,  17,  17 };
  504. X
  505. /****************************************************************
  506. X
  507. X    gr_init()
  508. X
  509. ****************************************************************/
  510. X
  511. gr_init( window, font_path )
  512. X   struct gr_window *window;
  513. X   char *font_path;
  514. X   {
  515. X   int font_ret;
  516. X   static char ff[ 64 ];
  517. X   register int i;
  518. X
  519. X   ibm_window = window;
  520. X
  521. X   /* Set font */
  522. X
  523. X   if ( font_path != NULL )
  524. X      {
  525. X      sprintf( ff, "%s%s", font_path, fontfile );
  526. X      }
  527. X   else
  528. X      {
  529. X      strcpy( ff, fontfile );
  530. X      }
  531. X
  532. X   if ( ( font_ret = _registerfonts( ff ) ) <= 0 )
  533. X      {
  534. X      strcpy ( ff, "../../fonts" );
  535. X      if ( ( font_ret = _registerfonts( ff ) ) <= 0 )
  536. X     {
  537. X     fprintf( stderr, "Can't find font files (path: %s).\n", ff );
  538. X     exit( 0 );
  539. X     }
  540. X      }
  541. X
  542. X   /* Get the video configuration to learn about hardware */
  543. X
  544. X   _getvideoconfig( &ibm_vc );
  545. X   ibm_imode = ibm_vc.mode;
  546. X
  547. X   switch( ibm_vc.adapter )
  548. X      {
  549. X      case _HGC:
  550. X         ibm_vmode = _HERCMONO;
  551. X         ibm_px = 30;
  552. X         ibm_py = 45;
  553. X         break;
  554. X      case _CGA:
  555. X      case _OCGA:
  556. X         ibm_vmode = _HRESBW;
  557. X         ibm_px = 29;
  558. X         ibm_py = 69;
  559. X         break;
  560. X      case _VGA:
  561. X      case _OVGA:
  562. X      case _MCGA:
  563. X      case _EGA:
  564. X      case _OEGA:
  565. X         ibm_vmode = _ERESCOLOR;
  566. #ifdef OLD_DEBUG
  567. X     fprintf( stderr, "VGA: monitor is %d \n", ibm_vc.adapter );
  568. X     getchar();
  569. #endif
  570. X     ibm_px = 40;
  571. X         ibm_py = 50;
  572. X         break;
  573. X      default:
  574. X         printf( "An appropriate video mode could not be located\n" );
  575. X         exit( 0 );
  576. X         break;
  577. X      }
  578. X
  579. X   /* If there is a mouse, initialize it now */
  580. X
  581. X   msm_init();
  582. X
  583. X   /* set the video mode */
  584. X
  585. X   if ( ibm_imode != ibm_vmode )
  586. X      {
  587. X     _setvideomode( ibm_vmode );
  588. #ifdef OLD_DEBUG
  589. X      fprintf( stderr, "INIT....." );
  590. X      getchar();
  591. #endif
  592. X      }
  593. X   else
  594. X      {
  595. #ifdef OLD_DEBUG
  596. X      fprintf( stderr, "No need to initialize....." );
  597. X      getchar();
  598. #endif
  599. X      }
  600. X
  601. X   /* Get the video configuration again */
  602. X
  603. X   _getvideoconfig( &ibm_vc );
  604. X
  605. X   /* allocate transfer memory area */
  606. X
  607. #if     LINE_BLIT
  608. X   if ( ( xfr_mem = malloc( (size_t) _imagesize( 0, 0,
  609. X      ibm_vc.numxpixels, 1 ) )) == NULL )
  610. #else
  611. X   if ( ( xfr_mem
  612. X      = halloc( (long) 1, (size_t) _imagesize( 0, ibm_vc.numypixels,
  613. X      ibm_vc.numxpixels, 0 ) )) == NULL )
  614. #endif
  615. X      {
  616. X      gr_deinit();
  617. X      fprintf( stderr,
  618. X     "gr: failed to allocate memory for transfer buffer\n" );
  619. X      exit( 0 );
  620. X      }
  621. X
  622. X   /* Reset mouse cursor lines + columns */
  623. X
  624. X   if ( msm_exist == TRUE )
  625. X      {
  626. #ifdef WHYDOTHIS
  627. X      msm_position( 0, 0 );
  628. #endif
  629. X      msm_showcounter = -1;
  630. X      msm_show();
  631. X      gr_ismouse = TRUE;
  632. #ifdef  OLD_DEBUG
  633. X      fprintf( stderr, "yes, virginia, there is a mouse...\n" );
  634. X      kb_rx();
  635. #endif
  636. X      }
  637. X   else
  638. X      {
  639. X      gr_ismouse = FALSE;
  640. X      }
  641. X
  642. #ifdef REALLYLETSDONTDOTHIS
  643. X    _setactivepage ( 0 );
  644. X    _clearscreen( _GCLEARSCREEN );
  645. X    _setactivepage ( 1 );
  646. X    _clearscreen( _GCLEARSCREEN );
  647. #endif
  648. X    _setactivepage ( 0 );
  649. X    _setvisualpage ( 0 );
  650. X
  651. X   /* Transfer video configuration information to the gr_window struct */
  652. X
  653. X   window->initialized = TRUE;
  654. X   window->xmax = ibm_vc.numxpixels - 1;
  655. X   window->ymax = ibm_vc.numypixels - 1;
  656. X   gr_screens = ibm_vc.numvideopages;
  657. X   if ( gr_screens > 1 )
  658. X      {
  659. X      gr_blitting = TRUE;
  660. X      }
  661. X   else
  662. X      {
  663. X      gr_blitting = FALSE;
  664. X      }
  665. X
  666. #if SET_MONOVGA
  667. X   if ( ( ibm_vmode == _ERESCOLOR ) && ( ibm_vc.adapter == _ANALOGMONO ))
  668. X      {
  669. X      gr_colors = 2;                 /* for mono VGA */
  670. X      }
  671. X   else
  672. X      {
  673. X      gr_colors = ibm_vc.numcolors;
  674. X      }
  675. #else
  676. X   gr_colors = ibm_vc.numcolors;
  677. #endif
  678. X
  679. X   gr_pxsize = ibm_px;
  680. X   gr_pysize = ibm_py;
  681. X
  682. X   /* gr signon message */
  683. X
  684. #if SIGNON
  685. X
  686. X   printf( "Bywater Graphics Interface Standard Implementation\n" );
  687. X   printf( "Copyright (c) 1990, Ted A. Campbell\n" );
  688. X   switch( ibm_vmode )
  689. X      {
  690. X      case _HERCMONO:
  691. X         printf( "Hercules (tm) " );
  692. X         break;
  693. X      case _HRESBW:
  694. X         printf( "CGA " );
  695. X         break;
  696. X      case _ERESCOLOR:
  697. X         printf( "EGA or VGA " );
  698. X         break;
  699. X      }
  700. X   printf( "or compatible graphics detected\n" );
  701. X   printf( "%dx%d pixels resolution in %d colors\n",
  702. X      ibm_vc.numxpixels, ibm_vc.numypixels, ibm_vc.numcolors );
  703. X   printf( "%d kbytes of video RAM in %d video page(s)\n",
  704. X      ibm_vc.memory, ibm_vc.numvideopages );
  705. X   if ( msm_exist != FALSE )
  706. X      {
  707. X      printf( "Mouse device detected. \n" );
  708. X      }
  709. X   printf( "Please wait while font is loaded...\n" );
  710. X
  711. #endif
  712. X
  713. X   /* set image buffer pointers to NULL */
  714. X
  715. X   for ( i = 0; i < IMAGES; ++i )
  716. X      {
  717. X      ibm_images[ i ] = NULL;
  718. X      }
  719. X
  720. X   ibm_screen( GR_PRIMARY );
  721. X   gr_font( GR_PRIMARY, F_DEFAULT, ibm_vc.numypixels / 25 );
  722. X
  723. X   }
  724. X
  725. /****************************************************************
  726. X
  727. X    gr_deinit()
  728. X
  729. ****************************************************************/
  730. X
  731. gr_deinit()
  732. X   {
  733. #if     LINE_BLIT
  734. X   _ffree( xfr_mem );
  735. #else
  736. X   hfree( xfr_mem );
  737. #endif
  738. X
  739. X   /* hide the mouse in case we are returning to a graphics-based
  740. X      program that uses the mouse */
  741. X
  742. X   msm_hide();
  743. X
  744. X   /* reset video mode if necessary */
  745. X
  746. X   if ( ibm_vmode != ibm_imode )
  747. X      {
  748. X      _setvideomode( _DEFAULTMODE );
  749. #ifdef OLD_DEBUG
  750. X      fprintf( stderr, "Deinitialized....." );
  751. X      getchar();
  752. #endif
  753. X      }
  754. X   else
  755. X      {
  756. #ifdef OLD_DEBUG
  757. X      fprintf( stderr, "No need to deinitialize....." );
  758. X      getchar();
  759. #endif
  760. X      }
  761. X   }
  762. X
  763. /****************************************************************
  764. X
  765. X    gr_cls()
  766. X
  767. ****************************************************************/
  768. X
  769. gr_cls( screen )
  770. X   int screen;
  771. X   {
  772. X   ibm_screen( screen );
  773. X   if ( screen != GR_HIDDEN )
  774. X      {
  775. X      msm_hide();
  776. X      }
  777. X   _clearscreen( _GCLEARSCREEN );
  778. X   if ( screen != GR_HIDDEN )
  779. X      {
  780. X      msm_show();
  781. X      }
  782. X   }
  783. X
  784. /****************************************************************
  785. X
  786. X    gr_pixel()
  787. X
  788. ****************************************************************/
  789. X
  790. gr_pixel( screen, x, y, color )
  791. X   int screen;
  792. X   int x, y;
  793. X   int color;
  794. X   {
  795. X
  796. #if CHECK_PARAMS
  797. X   if ( ( x < 0 ) || ( x > ibm_window->xmax ))
  798. X      {
  799. X      sprintf( bw_ebuf, "[pr:] gr_pixel(): x value is %d", x );
  800. X      bw_error( bw_ebuf );
  801. X      return BW_ERROR;
  802. X      }
  803. X   if ( ( y < 0 ) || ( y > ibm_window->ymax ))
  804. X      {
  805. X      sprintf( bw_ebuf, "[pr:] gr_pixel(): y value is %d", y );
  806. X      bw_error( bw_ebuf );
  807. X      return BW_ERROR;
  808. X      }
  809. #endif
  810. X
  811. X   ibm_screen( screen );
  812. X   if ( screen != GR_HIDDEN )
  813. X      {
  814. X      msm_hide();
  815. X      }
  816. X   _setcolor( ibm_color( color ) );
  817. X   _setpixel( x, ibm_window->ymax - y );
  818. X   if ( screen != GR_HIDDEN )
  819. X      {
  820. X      msm_show();
  821. X      }
  822. X   }
  823. X         
  824. /****************************************************************
  825. X
  826. X    gr_line()
  827. X
  828. ****************************************************************/
  829. X
  830. gr_line( screen, x1, y1, x2, y2, color, style )
  831. X   int screen;
  832. X   int x1, y1, x2, y2;
  833. X   int color, style;
  834. X   {
  835. X
  836. #if CHECK_PARAMS
  837. X   if ( ( x1 < 0 ) || ( x1 > ibm_window->xmax ))
  838. X      {
  839. X      sprintf( bw_ebuf, "[pr:] gr_line(): x1 value is %d", x1 );
  840. X      bw_error( bw_ebuf );
  841. X      return BW_ERROR;
  842. X      }
  843. X   if ( ( x2 < 0 ) || ( x2 > ibm_window->xmax ))
  844. X      {
  845. X      sprintf( bw_ebuf, "[pr:] gr_line(): x2 value is %d", x2 );
  846. X      bw_error( bw_ebuf );
  847. X      return BW_ERROR;
  848. X      }
  849. X   if ( ( y1 < 0 ) || ( y1 > ibm_window->ymax ))
  850. X      {
  851. X      sprintf( bw_ebuf, "[pr:] gr_line(): y1 value is %d", y1 );
  852. X      bw_error( bw_ebuf );
  853. X      return BW_ERROR;
  854. X      }
  855. X   if ( ( y2 < 0 ) || ( y2 > ibm_window->ymax ))
  856. X      {
  857. X      sprintf( bw_ebuf, "[pr:] gr_line(): y2 value is %d", y2 );
  858. X      bw_error( bw_ebuf );
  859. X      return BW_ERROR;
  860. X      }
  861. #endif
  862. X
  863. #if     DEF_LINE
  864. X   def_line( screen, x1, y1, x2, y2, color, style );
  865. #else
  866. X   ibm_screen( screen );
  867. X   _setcolor( ibm_color( color ));
  868. X   switch( style )
  869. X      {
  870. X      case HOLLOW:
  871. X         _setlinestyle( 0 );
  872. X         break;
  873. X      case GRID:
  874. X      case HATCH:
  875. X         _setlinestyle( 85 + (256*85) );
  876. X         break;
  877. X      default:                        /* SOLID is default     */
  878. X         _setlinestyle( 0xffff );
  879. X         break;
  880. X      }
  881. X   _moveto( x1, ibm_window->ymax - y1 );
  882. X   if ( screen != GR_HIDDEN )
  883. X      {
  884. X      msm_hide();
  885. X      }
  886. X   _lineto( x2, ibm_window->ymax - y2 );
  887. X   if ( screen != GR_HIDDEN )
  888. X      {
  889. X      msm_show();
  890. X      }
  891. #endif
  892. X   }
  893. X
  894. /****************************************************************
  895. X
  896. X    gr_text()
  897. X
  898. ****************************************************************/
  899. X
  900. gr_text( screen, x, y, string, foreground, background )
  901. X   int screen;
  902. X   int x, y;
  903. X   int foreground, background;
  904. X   char *string;
  905. X   {
  906. X
  907. #if CHECK_PARAMS
  908. X   if ( ( x < 0 ) || ( x > ibm_window->xmax ))
  909. X      {
  910. X      sprintf( bw_ebuf, "[pr:] gr_text(): x value is %d", x );
  911. X      bw_error( bw_ebuf );
  912. X      return BW_ERROR;
  913. X      }
  914. X   if ( ( y < 0 ) || ( y > ibm_window->ymax ))
  915. X      {
  916. X      sprintf( bw_ebuf, "[pr:] gr_text(): y value is %d", y );
  917. X      bw_error( bw_ebuf );
  918. X      return BW_ERROR;
  919. X      }
  920. #endif
  921. X
  922. X   ibm_screen( screen );
  923. X
  924. X   _setcolor( ibm_color( background ) );
  925. X   _setbkcolor( (long) ibm_color( background ) );
  926. X   _setfillmask( _fill_full );
  927. X   _setlinestyle( 0xffff );
  928. X
  929. X   if ( screen != GR_HIDDEN )
  930. X      {
  931. X      msm_hide();
  932. X      }
  933. X
  934. X   _rectangle( _GFILLINTERIOR, x,
  935. X      ibm_window->ymax - ( y + ibm_window->fysize ),
  936. X      x + ((int) _getgtextextent( ((unsigned char far *) string ) )) + 1,
  937. X      ibm_window->ymax - ( y ) );
  938. X   _moveto( x, ibm_window->ymax - ( y + ibm_window->fysize ) );
  939. X   _setcolor( ibm_color( foreground ) );
  940. X   _outgtext( string );
  941. X
  942. X   if ( screen != GR_HIDDEN )
  943. X      {
  944. X      msm_show();
  945. X      }
  946. X   }
  947. X
  948. /****************************************************************
  949. X
  950. X    gr_strlen()
  951. X
  952. ****************************************************************/
  953. X
  954. unsigned int
  955. gr_strlen( string )
  956. X   char *string;
  957. X   {
  958. X   int r;
  959. X
  960. X   r = (unsigned int) _getgtextextent( ((unsigned char far *) string ) );
  961. #ifdef  DEBUG
  962. X   if ( r < 0 )
  963. X      {
  964. X      sprintf( bw_ebuf, "_getgtextent() returned error, string [%s]",
  965. X     string );
  966. X      bw_error( bw_ebuf );
  967. X      }
  968. #endif
  969. X   return r;
  970. X   }
  971. X
  972. /****************************************************************
  973. X
  974. X    gr_rectangle()
  975. X
  976. ****************************************************************/
  977. X
  978. gr_rectangle( screen, x1, y1, x2, y2, color, style )
  979. X   int screen;
  980. X   int x1, y1, x2, y2;
  981. X   int color, style;
  982. X   {
  983. X   static short _control;
  984. X   char *_fill_interior;
  985. X
  986. #if CHECK_PARAMS
  987. X   if ( ( x1 < 0 ) || ( x1 > ibm_window->xmax ))
  988. X      {
  989. X      sprintf( bw_ebuf, "[pr:] gr_rectangle(): x1 value is %d", x1 );
  990. X      bw_error( bw_ebuf );
  991. X      return BW_ERROR;
  992. X      }
  993. X   if ( ( x2 < 0 ) || ( x2 > ibm_window->xmax ))
  994. X      {
  995. X      sprintf( bw_ebuf, "[pr:] gr_rectangle(): x2 value is %d", x2 );
  996. X      bw_error( bw_ebuf );
  997. X      return BW_ERROR;
  998. X      }
  999. X   if ( ( y1 < 0 ) || ( y1 > ibm_window->ymax ))
  1000. X      {
  1001. X      sprintf( bw_ebuf, "[pr:] gr_rectangle(): y1 value is %d", y1 );
  1002. X      bw_error( bw_ebuf );
  1003. X      return BW_ERROR;
  1004. X      }
  1005. X   if ( ( y2 < 0 ) || ( y2 > ibm_window->ymax ))
  1006. X      {
  1007. X      sprintf( bw_ebuf, "[pr:] gr_rectangle(): y2 value is %d", y2 );
  1008. X      bw_error( bw_ebuf );
  1009. X      return BW_ERROR;
  1010. X      }
  1011. #endif
  1012. X
  1013. #if DEF_RECTANGLE
  1014. X   def_rectangle( screen, x1, y1, x2, y2, color, style );
  1015. #else
  1016. X   ibm_screen( screen );
  1017. X
  1018. X   switch( style )
  1019. X      {
  1020. X      case 0:
  1021. X         _fill_interior = _fill_blank;
  1022. X         break;
  1023. X      case 2:
  1024. X         _fill_interior = _fill_grid;
  1025. X         break;
  1026. X      case 3:
  1027. X         _fill_interior = _fill_hatch;
  1028. X         break;
  1029. X      default:
  1030. X         _fill_interior = _fill_full;
  1031. X         break;
  1032. X      }
  1033. X   if ( style == HOLLOW )
  1034. X      {
  1035. X      _control = _GBORDER;
  1036. X      }
  1037. X   else
  1038. X      {
  1039. X      _control = _GFILLINTERIOR;
  1040. X      }
  1041. X   _setcolor( ibm_color( color ) );
  1042. X   _setfillmask( _fill_interior );
  1043. X   if ( screen != GR_HIDDEN )
  1044. X      {
  1045. X      msm_hide();
  1046. X      }
  1047. X   _rectangle( _control, x1,
  1048. X      ibm_window->ymax - y1,
  1049. X      x2,
  1050. X      ibm_window->ymax - y2 );
  1051. X   if ( screen != GR_HIDDEN )
  1052. X      {
  1053. X      msm_show();
  1054. X      }
  1055. #endif
  1056. X   }
  1057. X
  1058. /****************************************************************
  1059. X
  1060. X    gr_circle()
  1061. X
  1062. ****************************************************************/
  1063. X
  1064. gr_circle( screen, x, y, radius, color, style )
  1065. X   int screen;
  1066. X   int x, y, radius;
  1067. X   int color, style;
  1068. X   {
  1069. X   register int xradius;
  1070. X   static short _control;
  1071. X   char *_fill_interior;
  1072. X
  1073. #if CHECK_PARAMS
  1074. X   if ( ( x < 0 ) || ( x > ibm_window->xmax ))
  1075. X      {
  1076. X      sprintf( bw_ebuf, "[pr:] gr_circle(): x value is %d", x );
  1077. X      bw_error( bw_ebuf );
  1078. X      return BW_ERROR;
  1079. X      }
  1080. X   if ( ( y < 0 ) || ( y > ibm_window->ymax ))
  1081. X      {
  1082. X      sprintf( bw_ebuf, "[pr:] gr_circle(): y value is %d", y );
  1083. X      bw_error( bw_ebuf );
  1084. X      return BW_ERROR;
  1085. X      }
  1086. #endif
  1087. X
  1088. #if DEF_CIRCLE
  1089. X   def_circle( screen, x, y, radius, color, style );
  1090. #else
  1091. X   ibm_screen( screen );
  1092. X
  1093. X   xradius = ( radius * gr_pysize ) / gr_pxsize;
  1094. X
  1095. X   switch( style )
  1096. X      {
  1097. X      case 0:
  1098. X         _fill_interior = _fill_blank;
  1099. X         break;
  1100. X      case 2:
  1101. X         _fill_interior = _fill_grid;
  1102. X         break;
  1103. X      case 3:
  1104. X         _fill_interior = _fill_hatch;
  1105. X         break;
  1106. X      default:
  1107. X         _fill_interior = _fill_full;
  1108. X         break;
  1109. X      }
  1110. X   if ( style == HOLLOW )
  1111. X      {
  1112. X      _control = _GBORDER;
  1113. X      }
  1114. X   else
  1115. X      {
  1116. X      _control = _GFILLINTERIOR;
  1117. X      }
  1118. X   _setcolor( ibm_color( color ) );
  1119. X   _setfillmask( _fill_interior );
  1120. X   if ( screen != GR_HIDDEN )
  1121. X      {
  1122. X      msm_hide();
  1123. X      }
  1124. X   _ellipse( _control, x - xradius,
  1125. X      ibm_window->ymax - ( y + radius),
  1126. X      x + xradius,
  1127. X      ibm_window->ymax - ( y - radius ));
  1128. X   if ( screen != GR_HIDDEN )
  1129. X      {
  1130. X      msm_show();
  1131. X      }
  1132. #endif
  1133. X   }
  1134. X
  1135. /****************************************************************
  1136. X
  1137. X    gr_ellipse()
  1138. X
  1139. ****************************************************************/
  1140. X
  1141. gr_ellipse( screen, x, y, x_radius, y_radius, mode, color, style )
  1142. X   int screen;
  1143. X   int x, y, x_radius, y_radius;
  1144. X   int mode, color, style;
  1145. X   {
  1146. X   }
  1147. X         
  1148. /****************************************************************
  1149. X
  1150. X    gr_clip()
  1151. X
  1152. ****************************************************************/
  1153. X
  1154. gr_clip( screen, mode, x1, y1, x2, y2 )
  1155. X   int screen;
  1156. X   int mode;
  1157. X   int x1, y1, x2, y2;
  1158. X   {
  1159. X
  1160. #if CHECK_PARAMS
  1161. X   if ( ( x1 < 0 ) || ( x1 > ibm_window->xmax ))
  1162. X      {
  1163. X      sprintf( bw_ebuf, "[pr:] gr_clip(): x1 value is %d", x1 );
  1164. X      bw_error( bw_ebuf );
  1165. X      return BW_ERROR;
  1166. X      }
  1167. X   if ( ( x2 < 0 ) || ( x2 > ibm_window->xmax ))
  1168. X      {
  1169. X      sprintf( bw_ebuf, "[pr:] gr_clip(): x2 value is %d", x2 );
  1170. X      bw_error( bw_ebuf );
  1171. X      return BW_ERROR;
  1172. X      }
  1173. X   if ( ( y1 < 0 ) || ( y1 > ibm_window->ymax ))
  1174. X      {
  1175. X      sprintf( bw_ebuf, "[pr:] gr_clip(): y1 value is %d", y1 );
  1176. X      bw_error( bw_ebuf );
  1177. X      return BW_ERROR;
  1178. X      }
  1179. X   if ( ( y2 < 0 ) || ( y2 > ibm_window->ymax ))
  1180. X      {
  1181. X      sprintf( bw_ebuf, "[pr:] gr_clip(): y2 value is %d", y2 );
  1182. X      bw_error( bw_ebuf );
  1183. X      return BW_ERROR;
  1184. X      }
  1185. #endif
  1186. X
  1187. X   ibm_screen( screen );
  1188. X   if ( mode == FALSE )
  1189. X      {
  1190. X      _setcliprgn( 0, 0, ibm_window->xmax - 1,
  1191. X     ibm_window->ymax - 1 );
  1192. X      ibm_window->clipping = FALSE;
  1193. X      return TRUE;
  1194. X      }
  1195. X   else
  1196. X      {
  1197. X      _setcliprgn( x1, ibm_window->ymax - y2,
  1198. X     x2, ibm_window->ymax - y1 );
  1199. X      ibm_window->clipping = TRUE;
  1200. X      ibm_window->cl_x1 = x1;
  1201. X      ibm_window->cl_y1 = y1;
  1202. X      ibm_window->cl_x2 = x2;
  1203. X      ibm_window->cl_y2 = y2;
  1204. X      return TRUE;
  1205. X      }
  1206. X   }
  1207. X
  1208. /****************************************************************
  1209. X
  1210. X    gr_font()
  1211. X
  1212. ****************************************************************/
  1213. X
  1214. gr_font( screen, type, rq_height )
  1215. X   int screen;
  1216. X   int type, rq_height;
  1217. X   {
  1218. X   static char fs[ 48 ];
  1219. X   static int current_type = 0;
  1220. X   static int current_height = 0;
  1221. X   static struct _fontinfo fi;
  1222. X   int x;
  1223. X
  1224. X   ibm_screen( screen );
  1225. X
  1226. X   if ( ( current_type == type ) && ( current_height == rq_height ) )
  1227. X      {
  1228. X      return BW_ERROR;
  1229. X      }
  1230. X
  1231. X   /* first try a bit-mapped (raster-mapped) font */
  1232. X
  1233. X   sprintf( fs, "h%dw%dbr", rq_height, ( rq_height * 2 ) / 3 );
  1234. X   x = _setfont( fs );
  1235. X   _getfontinfo( &fi );
  1236. X   ibm_window->fysize = fi.pixheight;
  1237. X   ibm_window->fxsize = fi.avgwidth;
  1238. X
  1239. X   /* if this fails ( greater than 5 pixels different than request),
  1240. X      then try a vector font */
  1241. X
  1242. X   if ( abs( fi.pixheight - rq_height ) > 3 )
  1243. X      {
  1244. X      sprintf( fs, "h%dw%dbv", rq_height, ( rq_height * 2 ) / 3 );
  1245. X      x = _setfont( fs );
  1246. X      _getfontinfo( &fi );
  1247. X      ibm_window->fysize = rq_height;
  1248. X      ibm_window->fxsize = ( rq_height * 2 ) / 3;
  1249. X      }
  1250. X
  1251. #ifdef  OLD_DEBUG
  1252. X   printf( "Request for font: %s\n", fs );
  1253. X   printf( "_setfont() returned: %d\n", x );
  1254. X   printf( "fontinfo:  Height, %d  Width, %d  Ascent %d \n",
  1255. X      fi.pixheight,
  1256. X      fi.avgwidth, fi.ascent );
  1257. X   getch();
  1258. #endif
  1259. X   }
  1260. X
  1261. /****************************************************************
  1262. X
  1263. X    gr_blit()
  1264. X
  1265. ****************************************************************/
  1266. X
  1267. gr_blit( src, dst, x1, y1, x2, y2 )
  1268. X   int src, dst;
  1269. X   int x1, y1, x2, y2;
  1270. X   {
  1271. #if LINE_BLIT
  1272. X   register int l;
  1273. #endif
  1274. X
  1275. #if CHECK_PARAMS
  1276. X   if ( ( x1 < 0 ) || ( x1 > ibm_window->xmax ))
  1277. X      {
  1278. X      sprintf( bw_ebuf, "[pr:] gr_blit(): x1 value is %d", x1 );
  1279. X      bw_error( bw_ebuf );
  1280. X      return BW_ERROR;
  1281. X      }
  1282. X   if ( ( x2 < 0 ) || ( x2 > ibm_window->xmax ))
  1283. X      {
  1284. X      sprintf( bw_ebuf, "[pr:] gr_blit(): x2 value is %d", x2 );
  1285. X      bw_error( bw_ebuf );
  1286. X      return BW_ERROR;
  1287. X      }
  1288. X   if ( ( y1 < 0 ) || ( y1 > ibm_window->ymax ))
  1289. X      {
  1290. X      sprintf( bw_ebuf, "[pr:] gr_blit(): y1 value is %d", y1 );
  1291. X      bw_error( bw_ebuf );
  1292. X      return BW_ERROR;
  1293. X      }
  1294. X   if ( ( y2 < 0 ) || ( y2 > ibm_window->ymax ))
  1295. X      {
  1296. X      sprintf( bw_ebuf, "[pr:] gr_blit(): y2 value is %d", y2 );
  1297. X      bw_error( bw_ebuf );
  1298. X      return BW_ERROR;
  1299. X      }
  1300. X   if ( src == dst )
  1301. X      {
  1302. X      sprintf( bw_ebuf, "[pr:] gr_blit(): src == dst" );
  1303. X      bw_error( bw_ebuf );
  1304. X      return BW_ERROR;
  1305. X      }
  1306. #endif
  1307. X
  1308. X   if ( ibm_vc.numvideopages > 1 )
  1309. X      {
  1310. X      msm_hide();
  1311. X
  1312. X      /* if the area is the entire screen, use fast blit routine */
  1313. X
  1314. X      if ( ( ( x2 - x1 ) == ibm_window->xmax  )
  1315. X     && ( ( y2 - y1 ) == ibm_window->ymax ))
  1316. X     {
  1317. #ifdef  OLD_DEBUG
  1318. X     fprintf( stderr, "This is the fast blit routine. \n" );
  1319. X     getch();
  1320. #endif
  1321. X     if ( src == GR_PRIMARY )
  1322. X        {
  1323. X        if ( ibm_vmode == _HERCMONO )
  1324. X           {
  1325. X           movedata( (unsigned int) 0xb000,         /* source segment */
  1326. X            (unsigned int) 0x0000,              /* source offset */
  1327. X            (unsigned int) 0xb800,              /* dest segment */
  1328. X            (unsigned int) 0x0000,              /* dest offset */
  1329. X            (unsigned) 0x8000 );                /* number bytes */
  1330. X           }
  1331. X        else if ( ibm_vmode == _ERESCOLOR )
  1332. X           {
  1333. X           outp(0x3ce, 0x05);      /* Mode register select */
  1334. X           outp(0x3cf, 0x01);      /* Select write mode 1 */
  1335. X           outp(0x3ce, 0x03);      /* Merge mode */
  1336. X           outp(0x3cf, 0x00);      /* Replace mode */
  1337. X           outp(0x3ce, 0x03);      /* Bit Mask register */
  1338. X           outp(0x3cf, 0xff);      /* Select all bits */
  1339. X           movedata( 0xA000, 0x0000, 0xA800, 0x0000, 0x8000 );
  1340. X           }
  1341. X        }
  1342. X     else
  1343. X        {
  1344. X        if ( ibm_vmode == _HERCMONO )
  1345. X           {
  1346. X           movedata( (unsigned int) 0xb800,
  1347. X            (unsigned int) 0x0000,
  1348. X            (unsigned int) 0xb000,
  1349. X            (unsigned int) 0x0000,
  1350. X            (unsigned) 0x8000 );
  1351. X
  1352. X           }
  1353. X        if ( ibm_vmode == _ERESCOLOR )
  1354. X           {
  1355. X           outp(0x3ce, 0x05);      /* Mode register select */
  1356. X           outp(0x3cf, 0x01);      /* Select write mode 1 */
  1357. X           outp(0x3ce, 0x03);      /* Merge mode */
  1358. X           outp(0x3cf, 0x00);      /* Replace mode */
  1359. X           outp(0x3ce, 0x03);      /* Bit Mask register */
  1360. X           outp(0x3cf, 0xff);      /* Select all bits */
  1361. X           movedata( 0xA800, 0x0000, 0xA000, 0x0000, 0x8000 );
  1362. X           }
  1363. X        }
  1364. X     }
  1365. X
  1366. X      /* The area is not the complete screen; blit only part of it */
  1367. X
  1368. X      else
  1369. X     {
  1370. #ifdef  OLD_DEBUG
  1371. X     fprintf( stderr, "DEBUG: imsize will be %ld bytes \n",
  1372. X        _imagesize( x1, y2, x2, y1 ) );
  1373. X     getch();
  1374. #endif
  1375. X
  1376. #if     LINE_BLIT
  1377. X     for ( l = y2; l >= y1; --l )
  1378. X        {
  1379. X        ibm_screen( src );
  1380. X        _getimage( x1, ibm_window->ymax - l, x2, ibm_window->ymax - l,
  1381. X           xfr_mem );
  1382. X        ibm_screen( dst );
  1383. X        _putimage( x1, ibm_window->ymax - l, xfr_mem, _GPSET );
  1384. X        }
  1385. #else
  1386. X     ibm_screen( src );
  1387. X     _getimage( x1, ibm_window->ymax - y2, x2, ibm_window->ymax - y1,
  1388. X        xfr_mem );
  1389. X     ibm_screen( dst );
  1390. X     _putimage( x1, ibm_window->ymax - y2, xfr_mem, _GPSET );
  1391. #endif
  1392. X     }
  1393. X      }
  1394. X   msm_show();
  1395. X   return TRUE;
  1396. X   }
  1397. X
  1398. /****************************************************************
  1399. X
  1400. X    gr_imsave()
  1401. X
  1402. ****************************************************************/
  1403. X
  1404. gr_imsave( screen, mode, x1, y1, x2, y2, image )
  1405. X   int screen;
  1406. X   int mode, x1, y1, x2, y2;
  1407. X   int *image;
  1408. X   {
  1409. X   register int r;
  1410. X   int carry_on;
  1411. X
  1412. #if CHECK_PARAMS
  1413. X   if ( ( x1 < 0 ) || ( x1 > ibm_window->xmax ))
  1414. X      {
  1415. X      sprintf( bw_ebuf, "[pr:] gr_save(): x1 value is %d", x1 );
  1416. X      bw_error( bw_ebuf );
  1417. X      return BW_ERROR;
  1418. X      }
  1419. X   if ( ( x2 < 0 ) || ( x2 > ibm_window->xmax ))
  1420. X      {
  1421. X      sprintf( bw_ebuf, "[pr:] gr_save(): x2 value is %d", x2 );
  1422. X      bw_error( bw_ebuf );
  1423. X      return BW_ERROR;
  1424. X      }
  1425. X   if ( ( y1 < 0 ) || ( y1 > ibm_window->ymax ))
  1426. X      {
  1427. X      sprintf( bw_ebuf, "[pr:] gr_save(): y1 value is %d", y1 );
  1428. X      bw_error( bw_ebuf );
  1429. X      return BW_ERROR;
  1430. X      }
  1431. X   if ( ( y2 < 0 ) || ( y2 > ibm_window->ymax ))
  1432. X      {
  1433. X      sprintf( bw_ebuf, "[pr:] gr_save(): y2 value is %d", y2 );
  1434. X      bw_error( bw_ebuf );
  1435. X      return BW_ERROR;
  1436. X      }
  1437. #endif
  1438. X
  1439. X   ibm_screen( screen );
  1440. X
  1441. X   msm_hide();
  1442. X
  1443. X   switch ( mode )
  1444. X      {
  1445. X      case TRUE:                   /* TRUE = SAVE image */
  1446. #ifdef  OLD_DEBUG
  1447. X     printf( "DEBUG: saving screen %d, %d %d %d %d\n", screen, x1, y1,
  1448. X        x2, y2 );
  1449. X     getch();
  1450. #endif
  1451. X
  1452. X     /* find an available buffer */
  1453. X
  1454. X     carry_on = TRUE;
  1455. X     r = 0;
  1456. X     while( ( carry_on == TRUE ) && ( r < IMAGES ) )
  1457. X        {
  1458. X        if ( ibm_images[ r ] == NULL )
  1459. X           {
  1460. X           carry_on = FALSE;
  1461. X           }
  1462. X        else
  1463. X           {
  1464. X           ++r;
  1465. X           }
  1466. X        }
  1467. X
  1468. X     if ( r >= IMAGES )
  1469. X        {
  1470. X        bw_error( "No more slots for image storage" );
  1471. X        return FALSE;
  1472. X        }
  1473. X
  1474. X     *image = r;
  1475. X
  1476. X     /* get memory */
  1477. X
  1478. X     if ( ( ibm_images[ *image ] = malloc( (size_t) _imagesize(
  1479. X        x1, ibm_window->ymax - y2,
  1480. X        x2, ibm_window->ymax - y1 ) ) ) == NULL )
  1481. X        {
  1482. X        bw_error( "Out of memory to store image" );
  1483. X        return FALSE;
  1484. X        }
  1485. X
  1486. X     /* save the image */
  1487. X
  1488. X     _getimage( x1, ( ibm_window->ymax ) - y2, x2,
  1489. X        ( ibm_window->ymax ) - y1,
  1490. X        ibm_images[ *image ] );
  1491. X
  1492. X     break;
  1493. X
  1494. X      case FALSE:                  /* FALSE = RESTORE image */
  1495. X
  1496. #ifdef  OLD_DEBUG
  1497. X     printf( "DEBUG: restoring screen %d, %d %d %d %d\n", screen,
  1498. X        x1, y1, x2, y2 );
  1499. X     getch();
  1500. #endif
  1501. X
  1502. #ifdef DEBUG
  1503. X     if ( ibm_images[ *image ] == NULL )
  1504. X        {
  1505. X        bw_error( "gr_imsave(): NULL image requested" );
  1506. X        return FALSE;
  1507. X        }
  1508. #endif
  1509. X
  1510. X     _putimage( x1, ibm_window->ymax - y2, ibm_images[ *image ], _GPSET );
  1511. X     break;
  1512. X      default:
  1513. #ifdef  DEBUG
  1514. X     bw_error( "[pr:] gr_save(): incorrect mode" );
  1515. #endif
  1516. X     msm_show();
  1517. X     return BW_ERROR;
  1518. X     break;
  1519. X      }
  1520. X
  1521. X   msm_show();
  1522. X   }
  1523. X
  1524. /****************************************************************
  1525. X
  1526. X    gr_imfree()
  1527. X
  1528. ****************************************************************/
  1529. X
  1530. gr_imfree( image )
  1531. X   int image;
  1532. X   {
  1533. X
  1534. #ifdef DEBUG
  1535. X   if ( ibm_images[ image ] == NULL )
  1536. X      {
  1537. X      bw_error( "gr_imfree(): NULL image requested" );
  1538. X      return FALSE;
  1539. X      }
  1540. #endif
  1541. X
  1542. X   free( ibm_images[ image ] );
  1543. X   ibm_images[ image ] = NULL;
  1544. X
  1545. X   }
  1546. X
  1547. /****************************************************************
  1548. X
  1549. X    gr_mouse()
  1550. X
  1551. ****************************************************************/
  1552. X
  1553. gr_mouse( mode, x, y, buttons )
  1554. X   int mode;
  1555. X   int *x, *y;
  1556. X   int *buttons;
  1557. X   {
  1558. X   static int m_pending = FALSE, y_pos = 0, x_pos = 0;
  1559. X
  1560. X   switch( mode )
  1561. X      {
  1562. X      case HIDE:
  1563. X     msm_hide();
  1564. X     break;
  1565. X      case SHOW:
  1566. X     msm_show();
  1567. X     break;
  1568. X      case POSITION:
  1569. X     msm_hide();
  1570. X     msm_position( ibm_window->ymax - *y, *x );
  1571. X     msm_show();
  1572. X     break;
  1573. X      case STATUS:
  1574. X      case SAMPLE:
  1575. X         if ( m_pending == TRUE )
  1576. X            {
  1577. X            return TRUE;
  1578. X            }
  1579. X         if ( msm_read() == TRUE )
  1580. X            {
  1581. X            x_pos = *x = m_col;
  1582. X            y_pos = *y = m_row;
  1583. X            m_pending = TRUE;
  1584. X            return TRUE;
  1585. X            }
  1586. X         else
  1587. X            {
  1588. X            x_pos = *x = m_col;
  1589. X            y_pos = *y = m_row;
  1590. X        return BW_ERROR;
  1591. X            }
  1592. X         break;
  1593. X      case WAIT:
  1594. X         if ( m_pending == TRUE )
  1595. X            {
  1596. X            m_pending = FALSE;
  1597. X            *x = x_pos;
  1598. X            *y = y_pos;
  1599. X            return TRUE;
  1600. X            }
  1601. X         while( msm_read() == FALSE )
  1602. X            {
  1603. X            ;
  1604. X            }
  1605. X         *x = x_pos = m_col;
  1606. X         *y = y_pos = m_row;
  1607. X         return TRUE;
  1608. X         break;
  1609. X      default:
  1610. X         break;
  1611. X      }
  1612. X   }
  1613. X
  1614. /****************************************************************
  1615. X
  1616. X    ibm_    IBM PC (tm) specific routines
  1617. X
  1618. ****************************************************************/
  1619. X
  1620. ibm_screen( screen )
  1621. X   int screen;
  1622. X   {
  1623. X   static int x_screen = 599;
  1624. X
  1625. #if CHECK_PARAMS
  1626. X   if ( ( screen < 0 ) || ( screen > GR_HIDDEN ))
  1627. X      {
  1628. X      sprintf( bw_ebuf, "[pr:] ibm_screen(): incorrect screen number %d",
  1629. X     screen );
  1630. X      bw_error( bw_ebuf );
  1631. X      }
  1632. #endif
  1633. X
  1634. X   if ( screen != x_screen )
  1635. X      {
  1636. X      _setactivepage( screen );
  1637. X      x_screen = screen;
  1638. X      }
  1639. X   }
  1640. X
  1641. ibm_color( color )
  1642. X   int color;
  1643. X   {
  1644. X   switch( color )
  1645. X      {
  1646. X      case 0:
  1647. X         return 0;
  1648. X      case 1:
  1649. X         return 15;
  1650. X      case 2:
  1651. X         return 12;
  1652. X      case 3:
  1653. X         return 10;
  1654. X      case 4:
  1655. X         return 9;
  1656. X      case 5:
  1657. X         return 14;
  1658. X      case 6:
  1659. X         return 11;
  1660. X      case 7:
  1661. X         return 13;
  1662. X      case 8:
  1663. X         return 0;
  1664. X      case 9:
  1665. X         return 15;
  1666. X      case 10:
  1667. X         return 4;
  1668. X      case 11:
  1669. X         return 2;
  1670. X      case 12:
  1671. X         return 1;
  1672. X      case 13:
  1673. X         return 5;
  1674. X      case 14:
  1675. X         return 3;
  1676. X      case 15:
  1677. X         return 6;
  1678. X      default:
  1679. X         return 1;
  1680. X      }
  1681. X   }
  1682. X
  1683. /****************************************************************
  1684. X
  1685. X    msm_    Microsoft Mouse Routines
  1686. X
  1687. ****************************************************************/
  1688. X
  1689. msm_init()
  1690. X   {
  1691. X
  1692. X   /* if the video card is hercules, set the appropriate location */
  1693. X
  1694. X   if ( ibm_vmode == _HERCMONO )
  1695. X      {
  1696. #ifdef OLD_DEBUG
  1697. X      fprintf( stderr, "Hercules graphics mouse implementation.\n" );
  1698. X      getchar();
  1699. #endif
  1700. X      hgc_location = (char far *) 0x00400049;
  1701. X      *hgc_location = 6;                       /* use 5 for HGC CRT page 1 */
  1702. X      }
  1703. X
  1704. X   /* check if the mouse driver exists first */
  1705. X
  1706. X   ibm_registers.x.ax = 0x3533;       /* look at the interrupt 33 address */
  1707. X
  1708. X   int86x( 0x21, &ibm_registers, &ibm_registers, &segreg);
  1709. X   miaddr = (( (long) segreg.es) << 16) + (long) ibm_registers.x.bx;
  1710. X   if ( miaddr == 0 || *(char *) miaddr == 0xcf)
  1711. X      {
  1712. X      msm_exist = FALSE;
  1713. X      return BW_ERROR;
  1714. X      }
  1715. X
  1716. X   /* and then check for the mouse itself */
  1717. X
  1718. X   ibm_registers.x.ax = 0;                    /* mouse status flag */
  1719. X   int86( 0x33, &ibm_registers, &ibm_registers);         /* check for the mouse interupt */
  1720. X   msm_exist = (ibm_registers.x.ax != 0);
  1721. X   msm_buttons = ibm_registers.x.bx;
  1722. X   if ( msm_exist == FALSE)
  1723. X      {
  1724. #ifdef OLD_DEBUG
  1725. X      fprintf( stderr, "Found mouse driver, but no mouse\n" );
  1726. X      getchar();
  1727. #endif
  1728. X      return BW_ERROR;
  1729. X      }
  1730. X
  1731. X   /* Set minimum/maximum lines, columns */
  1732. X
  1733. X   switch ( ibm_vmode )
  1734. X      {
  1735. X      case _HERCMONO:
  1736. X     msm_bounds( 347, 719 );
  1737. X     break;
  1738. X      case _HRESBW:
  1739. X     msm_bounds( 199, 639 );
  1740. X     break;
  1741. X      case _ERESCOLOR:
  1742. X     msm_bounds( 349, 639 );
  1743. X     break;
  1744. X      default:
  1745. #ifdef  DEBUG
  1746. X     fprintf( stderr, "Unknown video mode in mouse initialization <%d>\n", ibm_vmode );
  1747. X     getchar();
  1748. #endif
  1749. X     break;
  1750. X      }
  1751. X
  1752. X   return TRUE;
  1753. X
  1754. X   }
  1755. X
  1756. msm_bounds( lines, columns )
  1757. X   int lines, columns;
  1758. X   {
  1759. X
  1760. X   ibm_registers.x.ax = 7;            /* set min/max horizontal cursor position */
  1761. X   ibm_registers.x.cx = 0;            /* start at 0 */
  1762. X   ibm_registers.x.dx = columns - 1;
  1763. X   int86( 0x33, &ibm_registers, &ibm_registers);
  1764. X
  1765. X   ibm_registers.x.ax = 8;            /* set min/max vertical cursor position */
  1766. X   ibm_registers.x.cx = 0;            /* start at 0 */
  1767. X   ibm_registers.x.dx = lines - 1;     /* end at the end */
  1768. X   int86( 0x33, &ibm_registers, &ibm_registers);
  1769. X
  1770. X   }
  1771. X
  1772. msm_show()
  1773. X   {
  1774. #ifdef  OLD_DEBUG
  1775. X   fprintf( stderr, "+" );
  1776. #endif
  1777. X
  1778. X   while( msm_showcounter < 0 )
  1779. X      {
  1780. X      ibm_registers.x.ax = 1;            /* show cursor */
  1781. X      int86( 0x33, &ibm_registers, &ibm_registers);
  1782. X      ++msm_showcounter;
  1783. X      }
  1784. X   }
  1785. X
  1786. msm_hide()
  1787. X   {
  1788. #ifdef  OLD_DEBUG
  1789. X   fprintf( stderr, "-" );
  1790. #endif
  1791. X   while( msm_showcounter >= 0 )
  1792. X      {
  1793. X      ibm_registers.x.ax = 2;            /* hide cursor */
  1794. X      int86( 0x33, &ibm_registers, &ibm_registers);
  1795. X      --msm_showcounter;
  1796. X      }
  1797. X   }
  1798. X
  1799. msm_position( line, column )
  1800. X   {
  1801. X   ibm_registers.x.ax = 4;            /* set mouse cursor position */
  1802. X   ibm_registers.x.cx = column;
  1803. X   ibm_registers.x.dx = line;
  1804. X   int86( 0x33, &ibm_registers, &ibm_registers);
  1805. X   }
  1806. X
  1807. msm_read()
  1808. X   {
  1809. X   register int k;         /* current bit/button of mouse */
  1810. X   register int event;     /* encoded mouse event */
  1811. X   int newbut;             /* new state of the mouse buttons */
  1812. X   int mousecol;           /* current mouse column */
  1813. X   int mouserow;           /* current mouse row */
  1814. X   int sstate;             /* current shift key status */
  1815. X
  1816. X   /* check to see if any mouse buttons are different */
  1817. X
  1818. X   ibm_registers.x.ax = 3;    /* Get button status and mouse position */
  1819. X   int86(0x33, &ibm_registers, &ibm_registers);
  1820. X   newbut   = ibm_registers.x.bx;
  1821. #ifdef OLDSTUFF
  1822. X   mousecol = ibm_registers.x.cx >> 3;
  1823. X   mouserow = ibm_registers.x.dx >> 3;
  1824. #else
  1825. X   mousecol = ibm_registers.x.cx;
  1826. X   mouserow = ibm_registers.x.dx;
  1827. #endif
  1828. X   m_col = mousecol;
  1829. X   m_row = ( ibm_vc.numypixels - 1 ) - ( mouserow );
  1830. X
  1831. X   /* get the shift key status as well */
  1832. X
  1833. X   sstate = 0;
  1834. X   ibm_registers.h.ah = 2;    /* return current shift status */
  1835. X   int86( 0x16, &ibm_registers, &ibm_registers);
  1836. X   sstate = ibm_registers.h.al;
  1837. X
  1838. X   for ( k = 1; k != (1 << msm_buttons); k = k<<1)
  1839. X      {
  1840. X
  1841. X      /* For each button on the mouse */
  1842. X
  1843. X      if ((msm_oldbut&k) != (newbut&k))
  1844. X         {
  1845. X
  1846. X         /* This button changed, generate an event */
  1847. X
  1848. X         msm_oldbut = newbut;
  1849. X         return ( TRUE );
  1850. X         }
  1851. X      }
  1852. X   return ( FALSE );
  1853. X   }
  1854. X
  1855. X
  1856. X
  1857. SHAR_EOF
  1858. chmod 0644 io/gr/gr_ibmpc.c ||
  1859. echo 'restore of io/gr/gr_ibmpc.c failed'
  1860. Wc_c="`wc -c < 'io/gr/gr_ibmpc.c'`"
  1861. test 34235 -eq "$Wc_c" ||
  1862.     echo 'io/gr/gr_ibmpc.c: original size 34235, current size' "$Wc_c"
  1863. rm -f _shar_wnt_.tmp
  1864. fi
  1865. # ============= io/gr/gr_mgr.c ==============
  1866. if test -f 'io/gr/gr_mgr.c' -a X"$1" != X"-c"; then
  1867.     echo 'x - skipping io/gr/gr_mgr.c (File already exists)'
  1868.     rm -f _shar_wnt_.tmp
  1869. else
  1870. > _shar_wnt_.tmp
  1871. echo 'x - extracting io/gr/gr_mgr.c (Text)'
  1872. sed 's/^X//' << 'SHAR_EOF' > 'io/gr/gr_mgr.c' &&
  1873. /****************************************************************
  1874. X
  1875. X       gr_mgr.c       Implementation of Graphics Interface 
  1876. X                      for Bellcore MGR (tm)
  1877. X
  1878. X            Copyright (c) 1991, Ted A. Campbell
  1879. X
  1880. X            Bywater Software
  1881. X            P. O. Box 4023 
  1882. X            Duke Station 
  1883. X            Durham, NC  27706
  1884. X
  1885. X            email: tcamp@hercules.acpub.duke.edu
  1886. X
  1887. X    Copyright and Permissions Information:
  1888. X
  1889. X    All U.S. and international copyrights are claimed by the
  1890. X    author. The author grants permission to use this code
  1891. X    and software based on it under the following conditions:
  1892. X    (a) in general, the code and software based upon it may be 
  1893. X    used by individuals and by non-profit organizations; (b) it
  1894. X    may also be utilized by governmental agencies in any country,
  1895. X    with the exception of military agencies; (c) the code and/or
  1896. X    software based upon it may not be sold for a profit without
  1897. X    an explicit and specific permission from the author, except
  1898. X    that a minimal fee may be charged for media on which it is
  1899. X    copied, and for copying and handling; (d) the code must be 
  1900. X    distributed in the form in which it has been released by the
  1901. X    author; and (e) the code and software based upon it may not 
  1902. X    be used for illegal activities. 
  1903. X
  1904. ****************************************************************/
  1905. X
  1906. #include "stdio.h"
  1907. #include "bw.h"
  1908. #include "gr.h"
  1909. #include "mgrterm.h"      /* for Bellcore MGR (tm) */
  1910. X
  1911. #ifdef __STDC__
  1912. #include "malloc.h"
  1913. #else
  1914. extern char * malloc();
  1915. #endif
  1916. X
  1917. #define X_OFFSET   12
  1918. #define Y_OFFSET   12
  1919. #define MAX_X      640
  1920. #define MAX_Y      450
  1921. X
  1922. #define    CHECK_PARAMS    TRUE
  1923. X
  1924. #define MGR_BLSIZE  32
  1925. X
  1926. #define MGR_FONT0    10
  1927. #define MGR_FONT1    11
  1928. #define MGR_FONT2    12
  1929. #define MGR_FONT3    13
  1930. #define MGR_FONT4    14
  1931. X
  1932. #define    MGR_DRAWMAIN    0        /* mgr primary screen */
  1933. #define MGR_DRAWHIDE    1        /* mgr secondary (hidden) screen */
  1934. #define MGR_DRAWGRID    2        /* mgr grid screen */
  1935. #define MGR_DRAWSTART   6        /* start assignable screens */
  1936. X
  1937. #define    TINYFONT            /* try to use tiny font */
  1938. X
  1939. int   gr_screens = 2;
  1940. int   gr_colors = 2;
  1941. int   gr_pxsize = 287;
  1942. int   gr_pysize = 428;
  1943. int   gr_ismouse = TRUE;
  1944. int   gr_clipping = FALSE;
  1945. int   gr_blitting = TRUE;
  1946. int   gr_saving = TRUE;
  1947. X
  1948. static int   mgr_wno;
  1949. X
  1950. static int   mgr_cltarget;
  1951. static int   mgr_border;
  1952. static int   mgr_hidden = FALSE;
  1953. static int   mgr_curwind = MGR_DRAWMAIN;
  1954. static int   mgr_xblocks, mgr_yblocks;
  1955. static int   mgr_clx1, mgr_cly1, mgr_clx2, mgr_cly2;
  1956. struct gr_window *mgr_grwind;
  1957. X
  1958. extern tam_imsize();
  1959. X
  1960. /****************************************************************
  1961. X
  1962. X   gr_init()
  1963. X
  1964. ****************************************************************/
  1965. X
  1966. gr_init( grwindow, font_path )
  1967. X   struct gr_window *grwindow;
  1968. X   char *font_path;
  1969. X   {
  1970. X   register int x, y, i;
  1971. X   int target_x, target_y;
  1972. X   static xmax, ymax;
  1973. X   static char _host[ 32 ];
  1974. X
  1975. X   mgr_grwind = grwindow;
  1976. X
  1977. X   /* set up MGR system */
  1978. X
  1979. X   m_setup( M_FLUSH );
  1980. X   m_ttyset();
  1981. X
  1982. X   /* get maximum sizes from MGR system */
  1983. X
  1984. X   get_param( _host, &xmax, &ymax, &mgr_border );
  1985. X
  1986. X   /* calculate target size for window, x axis */
  1987. X
  1988. X   if ( ( xmax - ( X_OFFSET * 2) ) < MAX_X )
  1989. X      {
  1990. X      target_x = xmax - ( X_OFFSET * 2 );
  1991. X      }
  1992. X   else
  1993. X      {
  1994. X      target_x = MAX_X;
  1995. X      }
  1996. X
  1997. X   /* calculate target size for window, y axis */
  1998. X
  1999. X   if ( ( ymax - ( Y_OFFSET * 2) ) < MAX_Y )
  2000. X      {
  2001. X      target_y = ymax - ( Y_OFFSET * 2 );
  2002. X      }
  2003. X   else
  2004. X      {
  2005. X      target_y = MAX_Y;
  2006. X      }
  2007. X
  2008. X   /* get new window for this application */
  2009. X
  2010. X   mgr_wno = m_makewindow( X_OFFSET, Y_OFFSET, target_x, target_y );
  2011. X   m_selectwin( mgr_wno );
  2012. X   mgr_grwind->xmax = target_x - ( ( mgr_border * 2 ) + 1 );
  2013. X   mgr_grwind->ymax = target_y - ( ( mgr_border * 2 ) + 1 );
  2014. X
  2015. X   /* load fonts */
  2016. X
  2017. X
  2018. X   x = m_loadfont( MGR_FONT4, "gal12x20r.fnt" );
  2019. #ifdef    OLD_DEBUG
  2020. X      fprintf( stderr, "load font %d returned %d \n", MGR_FONT4, x );
  2021. X      getchar();
  2022. #endif
  2023. X   x = m_loadfont( MGR_FONT3, "cour8x16r.fnt" );
  2024. #ifdef    OLD_DEBUG
  2025. X      fprintf( stderr, "load font %d returned %d \n", MGR_FONT3, x );
  2026. X      getchar();
  2027. #endif
  2028. X   x = m_loadfont( MGR_FONT2, "cour7x14r.fnt" );
  2029. #ifdef    OLD_DEBUG
  2030. X      fprintf( stderr, "load font %d returned %d \n", MGR_FONT2, x );
  2031. X      getchar();
  2032. #endif
  2033. X   x = m_loadfont( MGR_FONT1, "cour6x12r.fnt" );
  2034. #ifdef    OLD_DEBUG
  2035. X      fprintf( stderr, "load font %d returned %d \n", MGR_FONT1, x );
  2036. X      getchar();
  2037. #endif
  2038. X   x = m_loadfont( MGR_FONT0, "tiny4x7r.fnt" );
  2039. #ifdef    OLD_DEBUG
  2040. X      fprintf( stderr, "load font %d returned %d \n", MGR_FONT0, x );
  2041. X      getchar();
  2042. #endif
  2043. X
  2044. X
  2045. X   gr_font( GR_PRIMARY, F_DEFAULT, 10 );
  2046. X
  2047. X   /* set to absolute window coordinate mode */
  2048. X
  2049. X   m_setmode( M_ABS );
  2050. /*   m_setmode( M_NOWRAP ); */
  2051. X
  2052. X   /* calculate number of blocks necessary for fill patterns */
  2053. X
  2054. X   mgr_xblocks = ( ( target_x ) / MGR_BLSIZE ) + 1;
  2055. X   mgr_yblocks = ( ( target_y ) / MGR_BLSIZE ) + 1;
  2056. X
  2057. #ifdef OLD_DEBUG
  2058. X   fprintf( stderr, "x size = %d, x blocks = %d \n", mgr_grwind->xmax, mgr_xblocks );
  2059. X   fprintf( stderr, "y size = %d, y blocks = %d \n", mgr_grwind->ymax, mgr_yblocks );
  2060. X   kb_rx();
  2061. #endif
  2062. X
  2063. X   /* get scratchpad bitmaps */
  2064. X
  2065. X   m_bitcreate( MGR_DRAWGRID, mgr_xblocks * MGR_BLSIZE, 
  2066. X      mgr_yblocks * MGR_BLSIZE );
  2067. X
  2068. #ifdef USEFILL
  2069. X   m_bitcreate( MGR_DRAWFILL, mgr_xblocks * MGR_BLSIZE, 
  2070. X      mgr_yblocks * MGR_BLSIZE );
  2071. #endif
  2072. X
  2073. X   m_bitcreate( MGR_DRAWHIDE, target_x, target_y );
  2074. X
  2075. #ifdef    OLD_DEBUG
  2076. X   fprintf( stderr, "Bitmaps created. \n" );
  2077. #endif
  2078. X
  2079. X   /* signon message */
  2080. X
  2081. X   fprintf( stderr, "Implementation of Bywater Graphics (gr) Standard\n" );
  2082. X   fprintf( stderr, "for Bellcore MGR (tm). This implementation copyright\n" );
  2083. X   fprintf( stderr, "(c) 1990, Ted A. Campbell, Bywater Software \n" );
  2084. X   fprintf( stderr, "\nInitializing: " );
  2085. X
  2086. #ifdef USEFILL
  2087. X
  2088. X   /* fill first block of fill bitmap with solid pattern */
  2089. X
  2090. #ifdef OLD_DEBUG
  2091. X   fprintf( stderr, "Initializing SOLID fill: " );
  2092. #endif
  2093. X   m_func( B_SET );
  2094. X   for ( y = 0; y < MGR_BLSIZE; ++y )
  2095. X      {
  2096. X      fprintf( stderr, "." );
  2097. X      m_lineto( MGR_DRAWFILL, 0, y, MGR_BLSIZE, y );
  2098. X      }
  2099. X
  2100. X   /* now replicate the block pattern throughout the fill bitmap */
  2101. X
  2102. #ifdef OLD_DEBUG
  2103. X   fprintf( stderr, "\nCopying FILL images: " );
  2104. #endif
  2105. X   m_func( B_SRC );
  2106. X   for ( y = 0; y < mgr_yblocks; ++y )
  2107. X      {
  2108. #ifdef OLD_DEBUG
  2109. X      fprintf( stderr, "\nFILL line %d: ", y );
  2110. #endif
  2111. X      fprintf( stderr, "." );
  2112. X      for ( x = 0; x < mgr_xblocks; ++x )
  2113. X         {
  2114. X         if ( ( x == 0 ) && ( y == 0 ))
  2115. X            {
  2116. X            }
  2117. X         else
  2118. X            {
  2119. X            m_bitcopyto( x * MGR_BLSIZE, y * MGR_BLSIZE, 
  2120. X               MGR_BLSIZE, MGR_BLSIZE, 
  2121. X               0, 0, MGR_DRAWFILL, MGR_DRAWFILL );
  2122. X            }
  2123. X         }
  2124. X      }
  2125. X
  2126. #endif        /* USEFILL */
  2127. X
  2128. X   /* fill grid bitmap with solid pattern */
  2129. X
  2130. #ifdef OLD_DEBUG
  2131. X   fprintf( stderr, "\nInitializing GRID fill: " );
  2132. #endif
  2133. X   for ( y = 0; y < MGR_BLSIZE; y += 2 )
  2134. X      {
  2135. X
  2136. #ifdef OLD_DEBUG
  2137. X      fprintf( stderr, "\nLine %d: ", y );
  2138. #endif
  2139. X      for ( x = 0; x < MGR_BLSIZE; x += 2 )
  2140. X         {
  2141. X         fprintf( stderr, "." );
  2142. X         m_func( B_SET );
  2143. X         m_lineto( MGR_DRAWGRID, x, y, x, y );
  2144. X         m_func( B_CLEAR );
  2145. X         m_lineto( MGR_DRAWGRID, x + 1, y, x + 1, y );
  2146. X         m_func( B_CLEAR );
  2147. X         m_lineto( MGR_DRAWGRID, x, y + 1, x, y + 1 );
  2148. X         m_func( B_SET );
  2149. X         m_lineto( MGR_DRAWGRID, x + 1, y + 1, x + 1, y + 1 );
  2150. X         }
  2151. X      }
  2152. X
  2153. X   /* now replicate the block pattern throughout the fill bitmap */
  2154. X
  2155. #ifdef OLD_DEBUG
  2156. X   fprintf( stderr, "\nCopying GRID images: " );
  2157. #endif
  2158. X   m_func( B_SRC );
  2159. X   for ( y = 0; y < mgr_yblocks; ++y )
  2160. X      {
  2161. #ifdef OLD_DEBUG
  2162. X      fprintf( stderr, "\nGRID line %d: ", y );
  2163. #else
  2164. X      fprintf( stderr, "." );
  2165. #endif
  2166. X      for ( x = 0; x < mgr_xblocks; ++x )
  2167. X         {
  2168. X         if ( ( y == 0 ) && ( x == 0 ))
  2169. X            {
  2170. X            }
  2171. X         else
  2172. X            {
  2173. #ifdef OLD_DEBUG
  2174. X            fprintf( stderr, "." );
  2175. #endif
  2176. X            m_bitcopyto( x * MGR_BLSIZE, y * MGR_BLSIZE, 
  2177. X               MGR_BLSIZE, MGR_BLSIZE, 
  2178. X               0, 0, MGR_DRAWGRID, MGR_DRAWGRID );
  2179. X            }
  2180. X         }
  2181. X      }
  2182. X
  2183. #ifdef OLD_DEBUG
  2184. X   fprintf( stderr, "\nGRID bitmap filled. \n" );
  2185. #endif
  2186. X
  2187. X   /* turn cursor off */
  2188. X
  2189. X   m_setcursor( CS_INVIS );
  2190. X
  2191. X   /* move cursor to 0,0 to be safe */
  2192. X
  2193. X   m_move( 0, 0 );
  2194. X
  2195. X   /* note that system is initailized */
  2196. X
  2197. X   mgr_grwind->initialized = TRUE;
  2198. X   return TRUE;
  2199. X   }
  2200. X
  2201. /****************************************************************
  2202. X
  2203. X   gr_deinit()
  2204. X
  2205. ****************************************************************/
  2206. X
  2207. gr_deinit( )
  2208. X   {
  2209. X   m_bitdestroy( MGR_DRAWGRID );
  2210. X   m_bitdestroy( MGR_DRAWHIDE );
  2211. X   m_destroywin( mgr_wno );
  2212. X   m_ttyreset();
  2213. X   }
  2214. X
  2215. /****************************************************************
  2216. X
  2217. X   gr_cls()
  2218. X
  2219. ****************************************************************/
  2220. X
  2221. gr_cls( screen )
  2222. X   int screen;
  2223. X   {
  2224. X   gr_rectangle( screen, 0, 0, mgr_grwind->xmax, mgr_grwind->ymax, 
  2225. X      BLACK, SOLID );
  2226. X   }
  2227. X
  2228. X
  2229. /****************************************************************
  2230. X
  2231. X   gr_pixel()
  2232. X
  2233. ****************************************************************/
  2234. X
  2235. gr_pixel( screen, x, y, color )
  2236. X   int screen;
  2237. X   int x, y;
  2238. X   int color;
  2239. X   {
  2240. X
  2241. #if    CHECK_PARAMS
  2242. X   if ( ( x < 0 ) || ( x > mgr_grwind->xmax ))
  2243. X      {
  2244. X      sprintf( bw_ebuf, "[pr:] gr_pixel(): x value is %d", x );
  2245. X      bw_error( bw_ebuf );
  2246. X      return BW_ERROR;
  2247. X      }
  2248. X   if ( ( y < 0 ) || ( y > mgr_grwind->ymax ))
  2249. X      {
  2250. X      sprintf( bw_ebuf, "[pr:] gr_pixel(): y value is %d", y );
  2251. X      bw_error( bw_ebuf );
  2252. X      return BW_ERROR;
  2253. X      }
  2254. #endif
  2255. X
  2256. X   mgr_color( color );
  2257. X   if ( screen == MGR_DRAWMAIN )
  2258. X      {
  2259. X       m_line( x, mgr_y( y ), x, mgr_y( y ) );
  2260. X      }
  2261. X   else
  2262. X      {
  2263. X      m_lineto( screen, x, mgr_y( y ), x, mgr_y( y ) );
  2264. SHAR_EOF
  2265. true || echo 'restore of io/gr/gr_mgr.c failed'
  2266. fi
  2267. echo 'End of  part 2'
  2268. echo 'File io/gr/gr_mgr.c is continued in part 3'
  2269. echo 3 > _shar_seq_.tmp
  2270. exit 0
  2271. exit 0 # Just in case...
  2272. -- 
  2273. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  2274. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  2275. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  2276. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  2277.