home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / windows / graphite / graphite.c next >
Encoding:
C/C++ Source or Header  |  1993-01-30  |  9.6 KB  |  305 lines

  1. /*[]------------------------------------------------------------[]*/
  2. /*|                                                              |*/
  3. /*|     Source code for TDVIDEO.DLL (for TDW.EXE)                |*/
  4. /*|                                                              |*/
  5. /*|     Module for Dual screen Graphite system                   |*/
  6. /*|                                                              |*/
  7. /*|                                                              |*/
  8. /*|     Copyright (c) 1992 by Borland International              |*/
  9. /*|     All Rights Reserved.                                     |*/
  10. /*|                                                              |*/
  11. /*[]------------------------------------------------------------[]*/
  12.  
  13. /* Derived from Jeffrey J. Peters code of DUAL8514.C */
  14. /*   changed by P. Sawatzki */
  15.  
  16. #include <windows.h>   // cause we're in Windows
  17. #include <dos.h>
  18. #include <stdio.h>     // for fprintf()
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include "tdvideo.h"   // prototypes for our TDW/TDVIDEO API
  22.  
  23. #define mono(a) {if (debug_string) fprintf (debug_file, "\n%s",a);} // cause I'm lazy
  24. #define force(a)   // null macro
  25.  
  26. // #define dll_check() {if (!dll_in_use) FatalAppExit (0, fatal_error);}
  27. #define dll_check() {if (!dll_in_use) exit (-99);}
  28. char far *fatal_error = "Fatal TDVIDEO.DLL Error";
  29.  
  30. static int debug_string = 0;// 1 = write helpful info to a debugging file
  31.                             //     specified with DebugFile= in the .INI
  32.                             // 0 = don't log anything
  33. static int use_color_colors = 0; // 1=use color colors on mono screen
  34. static int dll_in_use = 1;  // sanity check; 1 = we should be called, 0 = fatal error
  35.  
  36. char card_ident[] = "3.2.0 TDW video driver for Dual screen Graphite";
  37.  
  38. FILE *debug_file;           // FILE* for the debugging file (if any)
  39. BYTE screen_hold[80*25*2];  // buffer for restoring the text screen
  40. int restore_code = 0;       // 0 = none, 1 = restore, 2 = clear
  41. char option_file[] = "TDW.INI";
  42.  
  43. //--------------------------------------------------------------------------//
  44. #pragma argsused
  45. int FAR PASCAL LibMain( HANDLE hInstance, WORD wDataSegment,
  46.                         WORD wHeapSize, LPSTR lpszCmdLine )
  47. /*
  48.    This is a standard Windows DLL LibMain function.
  49. */
  50. {
  51.  // The startup code for the DLL initializes the local heap (if there is one)
  52.  // with a call to LocalInit which locks the data segment.
  53.     if ( wHeapSize != 0 )
  54.         UnlockData( 0 );
  55.  
  56.     return 1;   // Always succeed LibMain
  57. }
  58. //--------------------------------------------------------------------------//
  59. #pragma argsused
  60. int FAR PASCAL WEP ( int bSystemExit )
  61. /*
  62.    This is a standard Windows DLL WEP function.
  63. */
  64. { return 1;  // Unload succeeded
  65. }
  66.  
  67. //--------------------------------------------------------------------------//
  68. void setmem (int eightbit)
  69. /*
  70.    This function sets the Hercules Graphite to 8 bit or 16 bit operation
  71.    to let the Graphite live together with the monochrome card
  72.    28.1.93 Peter Sawatzki
  73. */
  74. { static char oIn=0, oVG=0;
  75.   if (!oIn) {outportb (0x216A, 0x6D); oIn=inportb(0x216B);}
  76.   if (!oVG) {outportb (0x3C4,  0x0E); oVG=inportb(0x3C5);}
  77.  
  78.   if (eightbit) {
  79.     outportb (0x3C4,  0x0E); outportb(0x3C5, oVG&~0x08);
  80.     outportb (0x216A, 0x6D); outportb(0x216B,oIn&~0x01);
  81.   } else {
  82.     outportb (0x216A, 0x6D); outportb(0x216B,oIn);
  83.     outportb (0x3C4,  0x0E); outportb(0x3C5, oVG);
  84.   }
  85.   if (debug_string)
  86.     if (eightbit) fprintf (debug_file, " [8]");
  87.              else fprintf (debug_file, " [16]");
  88. }
  89.  
  90.  
  91. //--------------------------------------------------------------------------//
  92. WORD _win VideoInit (void)
  93. /*
  94.    This function detects the video card and mode and allocates the
  95.    memory for the memory saving routines.
  96. */
  97. {
  98.   char buf[81];
  99.   char drv_dll[61];
  100.   int j;
  101.   struct time tm;
  102.   struct date da;
  103.  
  104.   use_color_colors=GetPrivateProfileInt("VideoOptions", "Color",
  105.                                         0, option_file);
  106.  
  107.   GetPrivateProfileString ("VideoOptions", "DebugFile",
  108.                            "NUL", buf, 80, option_file);
  109.  
  110.   if (!lstrcmp (buf, "NUL"))
  111.     debug_string = 0;
  112.   else
  113.     debug_string = 1;
  114.  
  115.   if (debug_string)
  116.   {
  117.     if ((debug_file = fopen (buf,"wt")) == NULL)
  118.       debug_string = 0;
  119.  
  120.     getdate (&da);
  121.     gettime (&tm);
  122.     fprintf(debug_file,"\nLogging on %02d/%02d/%04d at %2d:%02d\n",
  123.             da.da_mon, da.da_day, da.da_year,
  124.             tm.ti_hour, tm.ti_min);
  125.  
  126.     fprintf (debug_file, "\n%s (Built on %s, %s)\n"
  127.     "------------------------------------------------"
  128.     "------------------------------",
  129.     card_ident,__DATE__,
  130.     __TIME__); mono ("TDVIDEO.DLL:VideoInit");
  131.   }
  132.  
  133.   GetPrivateProfileString ("VideoOptions", "RestoreTextScreen", "R", buf,
  134.                            10, option_file);
  135.  
  136.   strupr (buf);
  137.   if (buf[0] == 'C')
  138.     restore_code = 2;     // clear screen
  139.   else
  140.     if (buf[0] == 'Y' || buf[0] == 'R') restore_code = 1; // restore it
  141.     else
  142.       restore_code = 0;       // none
  143.  
  144.   GetPrivateProfileString ("boot", "display.drv", "NULL",
  145.                            drv_dll, 60, "SYSTEM.INI");
  146.  
  147.   if (debug_string)
  148.     if (strcmp (drv_dll, "NULL"))
  149.       fprintf (debug_file, "\n  display.drv=%s", drv_dll);
  150.     else
  151.       fprintf (debug_file, "\n  WARNING: Unable to locate 'display.drv' "
  152.                            "in SYSTEM.INI\n");
  153.  
  154.   dll_in_use = 1;
  155.   return 0;  // 0 = success
  156. }
  157.  
  158. //--------------------------------------------------------------------------//
  159. WORD _win VideoDone (void)
  160. /*
  161.    This function frees all the memory allocated for saving data.
  162. */
  163. { dll_check ();      // make sure that we are supposed to be called
  164.  
  165.   if (debug_string)
  166.     mono ("TDVIDEO.DLL:VideoDone");
  167.  
  168.   if (restore_code) {
  169.     setmem(TRUE);
  170.     if (restore_code==1) // restore
  171.       _fmemcpy (MK_FP (((WORD) &_B000H),0), screen_hold, 80*25*2);    // restore text screen
  172.     else { // clear
  173.       int j;
  174.       WORD far *p, hold;
  175.  
  176.       p = MK_FP (((WORD) &_B000H),0);
  177.       for (j=0;j<80*25;j++)
  178.         p[j] = 0x0720;    // grey on black spaces
  179.     }
  180.     setmem(FALSE);
  181.   }
  182.  
  183.   if (debug_string)
  184.     fclose (debug_file);
  185.  
  186.   return 1;
  187. }
  188.  
  189. //--------------------------------------------------------------------------//
  190. WORD _win VideoIsColor (void)
  191. /*
  192.    This function is called to determine if we are in color or mono mode.
  193. */
  194. {
  195.   dll_check ();      // make sure that we are supposed to be called
  196.   if (debug_string)
  197.     fprintf (debug_file,"\nTDVIDEO.DLL:VideoIsColor = %d", use_color_colors);
  198.  
  199.   return use_color_colors;
  200. }
  201.  
  202. //--------------------------------------------------------------------------//
  203. WORD _win VideoGetTextSelector (int display)
  204. /*
  205.    This function returns the protected mode selector that corresponds to
  206.    the real mode segment of the text screen requested.
  207.    Display is ignored for this driver and we always return a selector for
  208.    the monochrome area (0xB000).
  209. */
  210. { static int first_in = 1; // flag for noting the first time in selector call
  211.   display+=0;              // no warning
  212.  
  213.   dll_check ();            // make sure that we are supposed to be called
  214.  
  215.   if (first_in) {
  216.     first_in = 0;
  217.     if (restore_code==1) {
  218.       setmem(TRUE);
  219.       _fmemcpy (screen_hold, MK_FP (((WORD) &_B000H), 0), 80*25*2);    // save text screen
  220.       setmem(FALSE);
  221.     }
  222.   }
  223.  
  224.   if (debug_string)
  225.   { mono ("TDVIDEO.DLL:VideoGetTextSelector");
  226.     fprintf (debug_file, " (Mono) - B000=%04X",(WORD)&_B000H);
  227.     force (debug_file);
  228.   }
  229.   return (((WORD) &_B000H));
  230. }
  231.  
  232. //--------------------------------------------------------------------------//
  233. void _win VideoSetCursor (WORD x, WORD y)
  234. /*
  235.    This function positions the cursor on the text mode screen.
  236. */
  237. { WORD a, port = 0x3B4;  // mono port
  238.  
  239.   dll_check ();      // make sure that we are supposed to be called
  240.  
  241.   if (debug_string)
  242.   { mono ("TDVIDEO.DLL:VideoSetCursor");
  243.     fprintf (debug_file, "  (%03d,%03d)",x,y);
  244.   }
  245.  
  246.   a = y * 80 + x;
  247.   outportb (port, 0x0E); // cursor location high byte reg.
  248.   _CX = a;
  249.   outport (port+1, _CH);
  250.   outportb (port, 0x0F); // cursor location low byte reg.
  251.   _CX = a;
  252.   outport (port+1, _CL);
  253.   force (debug_file);
  254. }
  255. //--------------------------------------------------------------------------//
  256. void _win VideoDebuggerScreen (void)
  257. /*
  258.    This function saves the palette and video memory, and switches into
  259.    text mode.
  260. */
  261.  
  262. {
  263.   dll_check ();      // make sure that we are supposed to be called
  264.   if (debug_string)
  265.     mono ("TDVIDEO.DLL:VideoDebuggerScreen");
  266.   force (debug_file);
  267.   setmem(TRUE);
  268. }
  269.  
  270. //--------------------------------------------------------------------------//
  271. void _win VideoWindowsScreen (void)
  272. /*
  273.    This function switches back into graphics mode, restoring the
  274.    palette, and video memory.
  275. */
  276.  
  277. {
  278.   dll_check ();      // make sure that we are supposed to be called
  279.   if (debug_string)
  280.     mono ("TDVIDEO.DLL:VideoWindowsScreen");
  281.   force (debug_file);
  282.   setmem(FALSE);
  283. }
  284. //--------------------------------------------------------------------------//
  285. WORD _win VideoBigSize (void)
  286. /*
  287.    This function returns the maximum number of lines that the high res
  288.    text mode can handle (25 for the monochrome screen).
  289. */
  290. { return(25);
  291. }
  292.  
  293. //--------------------------------------------------------------------------//
  294. void _win VideoSetSize (WORD bigflag)
  295. /*
  296.    This function changes the text mode to (bigflag==1) 50 line mode, or
  297.    (bigflag==0), 25 line mode.
  298. */
  299.  
  300. { bigflag+=0; //satisfay compiler warning
  301.   return;
  302. }
  303. //--------------------------------------------------------------------------//
  304.  
  305.