home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / EMXLIB8F.ZIP / EMX / LIB / GRAPH / GRAPH1.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-02  |  5.3 KB  |  278 lines

  1. /* graph1.c (emx+gcc) -- Copyright (c) 1987-1993 by Eberhard Mattes */
  2.  
  3. #include <stdlib.h>
  4. #include <graph.h>
  5. #include <dos.h>
  6. #include <memory.h>
  7. #include <sys/hw.h>
  8. #define INCL_DOSMEMMGR
  9. #define INCL_DOSPROCESS
  10. #define INCL_VIO
  11. #include <os2emx.h>
  12. #include <os2thunk.h>
  13. #include "graph2.h"
  14.  
  15. #define FALSE 0
  16. #define TRUE  1
  17.  
  18. static int graph_mode = 0;
  19. static int setmode = 0;
  20. static int old_mode_number = 3;
  21. static int _g_save_saved = 0;
  22. static int _g_save_segsize = 0;
  23.  
  24. #if 0
  25. static void *_g_save_buf = NULL;
  26. #endif
  27.  
  28. static VIOMODEINFO old_vio_mode;
  29. static VIOMODEINFO new_vio_mode;
  30. static VIOPHYSBUF phys;
  31.  
  32. int g_xsize = 1;
  33. int g_ysize = 1;
  34. int g_colors = 1;
  35.  
  36. int _g_xsize = 1;
  37. int _g_ysize = 1;
  38. int _g_colors = 1;
  39.  
  40. int _g_clipx0 = 0;
  41. int _g_clipy0 = 0;
  42. int _g_clipx1 = 0;
  43. int _g_clipy1 = 0;
  44.  
  45. int _g_locklevel = 0;
  46.  
  47. unsigned char *_g_mem = NULL;
  48.  
  49. static int g_mode_on (int width, int height, int mode_number);
  50. static void g_mode_off (void);
  51. static void g_mode_vgal (void);
  52. static void g_init2 (void);
  53. static void g_mode_s (void);
  54.  
  55.  
  56. int _ggetmode (void)
  57. {
  58.   union REGS r;
  59.  
  60.   r.h.ah = 0x0f;
  61.   _int86 (0x10, &r, &r);
  62.   return (r.h.al);
  63. }
  64.  
  65.  
  66. void _gsetmode (int mode)
  67. {
  68.   union REGS r;
  69.  
  70.   r.h.ah = 0x00;
  71.   r.h.al = (unsigned char)mode;
  72.   _int86 (0x10, &r, &r);
  73. }
  74.  
  75.  
  76. void g_wmode (int wmode)
  77. {
  78. }
  79.  
  80.  
  81. void g_lock (void)
  82. {
  83.   BYTE not_locked;
  84.  
  85.   if (_osmode == OS2_MODE && _g_locklevel == 0)
  86.     {
  87.       ++_g_locklevel;
  88.       VioScrLock (LOCKIO_WAIT, ¬_locked, 0);
  89.     }
  90. }
  91.  
  92.  
  93. void g_unlockall (void)
  94. {
  95.   if (_g_locklevel != 0)
  96.     {
  97.       _g_locklevel = 1;
  98.       g_unlock ();
  99.     }
  100. }
  101.  
  102.  
  103. void g_unlock (void)
  104. {
  105.   if (_osmode == OS2_MODE && _g_locklevel > 0)
  106.     {
  107.       --_g_locklevel;
  108.       if (_g_locklevel == 0)
  109.         VioScrUnLock (0);
  110.     }
  111. }
  112.  
  113.  
  114. int g_modeset (int mode, int flag)
  115. {
  116.   g_xsize = g_ysize = g_colors = 1; setmode = 0;
  117.   switch (mode)
  118.     {
  119.     case G_MODE_VGA_L:
  120.       g_xsize = 320; g_ysize = 200; g_colors = 256; setmode = 19;
  121.       break;
  122.     default:
  123.       mode = G_MODE_OFF;
  124.       break;
  125.     }
  126.   return (mode);
  127. }
  128.  
  129.  
  130. int g_mode (int mode)
  131. {
  132.   g_unlockall ();
  133.   if (mode == G_MODE_OFF)
  134.     {
  135.       if (graph_mode != 0)
  136.         {
  137.           g_mode_off ();
  138.           graph_mode = 0;
  139.         }
  140.       return (FALSE);
  141.     }
  142.   else
  143.     {
  144.       g_mode (G_MODE_OFF);
  145.       g_lock ();
  146.       if (_osmode == OS2_MODE)
  147.         {
  148.           _g_save_saved = 0;
  149.           old_vio_mode.cb = sizeof (old_vio_mode);
  150.           VioGetMode (&old_vio_mode, 0);
  151.         }
  152.       else
  153.         old_mode_number = _ggetmode ();
  154.       mode = g_modeset (mode, G_SET_KEEP);
  155.       if (setmode == 0)
  156.         {
  157.           g_unlock ();
  158.           return (FALSE);
  159.         }
  160.       _g_xsize = g_xsize; _g_ysize = g_ysize; _g_colors = g_colors;
  161.       _g_clipx0 = 0; _g_clipx1 = _g_xsize - 1;
  162.       _g_clipy0 = 0; _g_clipy1 = _g_ysize - 1;
  163.       switch (setmode)
  164.         {
  165.         case 19:    /* G_MODE_VGA_L */
  166.           _g_save_segsize = _g_xsize * _g_ysize;
  167.           if (!g_mode_on (40, 25, 19))
  168.             {
  169.               g_unlock ();
  170.               return (FALSE);
  171.             }
  172.           g_mode_vgal ();
  173.           break;
  174.         }
  175.       g_wmode (G_NORM);
  176.       graph_mode = setmode;
  177.       g_init2 ();
  178.       g_mode_s ();
  179.       if (_osmode == OS2_MODE)
  180.         g_clear (G_BLACK);
  181.       g_unlock ();
  182.       return (TRUE);
  183.     }
  184. }
  185.  
  186.  
  187. static int g_mode_on (int width, int height, int mode_number)
  188. {
  189.   if (_osmode == OS2_MODE)
  190.     {
  191. #if 0
  192.       TID tid;
  193.  
  194.       if (DosAllocMem (&_g_save_buf, _g_save_segsize,
  195.                        PAG_COMMIT|PAG_READ|PAG_WRITE|OBJ_TILE))
  196.         return (FALSE);
  197.       if (DosCreateThread (&tid, redraw_wait, 0, 2, 0x2000) != 0)
  198.         return (FALSE);
  199.       if (DosCreateThread (&tid, mode_wait, 0, 2, 0x2000) != 0)
  200.         return (FALSE);
  201. #endif
  202.       new_vio_mode = old_vio_mode;
  203.       switch (_g_colors)
  204.         {
  205.         case 4:
  206.           new_vio_mode.color = 2; break;
  207.         case 16:
  208.           new_vio_mode.color = 4; break;
  209.         case 256:
  210.           new_vio_mode.color = 8; break;
  211.         default:
  212.           if (setmode == 15 || setmode == 17)
  213.             new_vio_mode.color = 0;
  214.           else
  215.             new_vio_mode.color = 1;
  216.           break;
  217.         }
  218.       new_vio_mode.fbType |= VGMT_GRAPHICS;
  219.       new_vio_mode.hres = _g_xsize;
  220.       new_vio_mode.vres = _g_ysize;
  221.       new_vio_mode.row = height;
  222.       new_vio_mode.col = width;
  223.       VioSetMode (&new_vio_mode, 0);
  224.       phys.pBuf = (PBYTE)0xa0000;
  225.       phys.cb = 0x10000;
  226.       if (VioGetPhysBuf (&phys, 0) != 0)
  227.         return (FALSE);
  228.       _g_mem = MAKEP (phys.asel[0], 0);
  229.     }
  230.   else
  231.     {
  232.       _gsetmode (mode_number);
  233.       _g_mem = _memaccess (0xa0000, 0xaffff, 1);
  234.       if (_g_mem == NULL)
  235.         return (FALSE);
  236.     }
  237.   return (TRUE);
  238. }
  239.  
  240.  
  241. static void g_mode_off (void)
  242. {
  243.   if (_osmode == OS2_MODE)
  244.     {
  245.       VioSetMode (&old_vio_mode, 0);
  246. #if 0
  247.       VioSavRedrawUndo (1, 1, 0);
  248.       VioModeUndo (1, 1, 0);
  249.       DosFreeMem (_g_save_buf);
  250. #endif
  251.     }
  252.   else
  253.     _gsetmode (old_mode_number);
  254. }
  255.  
  256.  
  257. static void g_init2 (void)
  258. {
  259. }
  260.  
  261.  
  262. static void g_mode_vgal (void)
  263. {
  264. }
  265.  
  266.  
  267. static void g_mode_s (void)
  268. {
  269. }
  270.  
  271.  
  272. void g_clear (int color)
  273. {
  274.   GLOCK;
  275.   memset (_g_mem, color, 320*200);
  276.   GUNLOCK;
  277. }
  278.