home *** CD-ROM | disk | FTP | other *** search
- /*[]------------------------------------------------------------[]*/
- /*| |*/
- /*| Source code for TDVIDEO.DLL (for TDW.EXE) |*/
- /*| |*/
- /*| Module for Dual screen Graphite system |*/
- /*| |*/
- /*| |*/
- /*| Copyright (c) 1992 by Borland International |*/
- /*| All Rights Reserved. |*/
- /*| |*/
- /*[]------------------------------------------------------------[]*/
-
- /* Derived from Jeffrey J. Peters code of DUAL8514.C */
- /* changed by P. Sawatzki */
-
- #include <windows.h> // cause we're in Windows
- #include <dos.h>
- #include <stdio.h> // for fprintf()
- #include <stdlib.h>
- #include <string.h>
- #include "tdvideo.h" // prototypes for our TDW/TDVIDEO API
-
- #define mono(a) {if (debug_string) fprintf (debug_file, "\n%s",a);} // cause I'm lazy
- #define force(a) // null macro
-
- // #define dll_check() {if (!dll_in_use) FatalAppExit (0, fatal_error);}
- #define dll_check() {if (!dll_in_use) exit (-99);}
- char far *fatal_error = "Fatal TDVIDEO.DLL Error";
-
- static int debug_string = 0;// 1 = write helpful info to a debugging file
- // specified with DebugFile= in the .INI
- // 0 = don't log anything
- static int use_color_colors = 0; // 1=use color colors on mono screen
- static int dll_in_use = 1; // sanity check; 1 = we should be called, 0 = fatal error
-
- char card_ident[] = "3.2.0 TDW video driver for Dual screen Graphite";
-
- FILE *debug_file; // FILE* for the debugging file (if any)
- BYTE screen_hold[80*25*2]; // buffer for restoring the text screen
- int restore_code = 0; // 0 = none, 1 = restore, 2 = clear
- char option_file[] = "TDW.INI";
-
- //--------------------------------------------------------------------------//
- #pragma argsused
- int FAR PASCAL LibMain( HANDLE hInstance, WORD wDataSegment,
- WORD wHeapSize, LPSTR lpszCmdLine )
- /*
- This is a standard Windows DLL LibMain function.
- */
- {
- // The startup code for the DLL initializes the local heap (if there is one)
- // with a call to LocalInit which locks the data segment.
- if ( wHeapSize != 0 )
- UnlockData( 0 );
-
- return 1; // Always succeed LibMain
- }
- //--------------------------------------------------------------------------//
- #pragma argsused
- int FAR PASCAL WEP ( int bSystemExit )
- /*
- This is a standard Windows DLL WEP function.
- */
- { return 1; // Unload succeeded
- }
-
- //--------------------------------------------------------------------------//
- void setmem (int eightbit)
- /*
- This function sets the Hercules Graphite to 8 bit or 16 bit operation
- to let the Graphite live together with the monochrome card
- 28.1.93 Peter Sawatzki
- */
- { static char oIn=0, oVG=0;
- if (!oIn) {outportb (0x216A, 0x6D); oIn=inportb(0x216B);}
- if (!oVG) {outportb (0x3C4, 0x0E); oVG=inportb(0x3C5);}
-
- if (eightbit) {
- outportb (0x3C4, 0x0E); outportb(0x3C5, oVG&~0x08);
- outportb (0x216A, 0x6D); outportb(0x216B,oIn&~0x01);
- } else {
- outportb (0x216A, 0x6D); outportb(0x216B,oIn);
- outportb (0x3C4, 0x0E); outportb(0x3C5, oVG);
- }
- if (debug_string)
- if (eightbit) fprintf (debug_file, " [8]");
- else fprintf (debug_file, " [16]");
- }
-
-
- //--------------------------------------------------------------------------//
- WORD _win VideoInit (void)
- /*
- This function detects the video card and mode and allocates the
- memory for the memory saving routines.
- */
- {
- char buf[81];
- char drv_dll[61];
- int j;
- struct time tm;
- struct date da;
-
- use_color_colors=GetPrivateProfileInt("VideoOptions", "Color",
- 0, option_file);
-
- GetPrivateProfileString ("VideoOptions", "DebugFile",
- "NUL", buf, 80, option_file);
-
- if (!lstrcmp (buf, "NUL"))
- debug_string = 0;
- else
- debug_string = 1;
-
- if (debug_string)
- {
- if ((debug_file = fopen (buf,"wt")) == NULL)
- debug_string = 0;
-
- getdate (&da);
- gettime (&tm);
- fprintf(debug_file,"\nLogging on %02d/%02d/%04d at %2d:%02d\n",
- da.da_mon, da.da_day, da.da_year,
- tm.ti_hour, tm.ti_min);
-
- fprintf (debug_file, "\n%s (Built on %s, %s)\n"
- "------------------------------------------------"
- "------------------------------",
- card_ident,__DATE__,
- __TIME__); mono ("TDVIDEO.DLL:VideoInit");
- }
-
- GetPrivateProfileString ("VideoOptions", "RestoreTextScreen", "R", buf,
- 10, option_file);
-
- strupr (buf);
- if (buf[0] == 'C')
- restore_code = 2; // clear screen
- else
- if (buf[0] == 'Y' || buf[0] == 'R') restore_code = 1; // restore it
- else
- restore_code = 0; // none
-
- GetPrivateProfileString ("boot", "display.drv", "NULL",
- drv_dll, 60, "SYSTEM.INI");
-
- if (debug_string)
- if (strcmp (drv_dll, "NULL"))
- fprintf (debug_file, "\n display.drv=%s", drv_dll);
- else
- fprintf (debug_file, "\n WARNING: Unable to locate 'display.drv' "
- "in SYSTEM.INI\n");
-
- dll_in_use = 1;
- return 0; // 0 = success
- }
-
- //--------------------------------------------------------------------------//
- WORD _win VideoDone (void)
- /*
- This function frees all the memory allocated for saving data.
- */
- { dll_check (); // make sure that we are supposed to be called
-
- if (debug_string)
- mono ("TDVIDEO.DLL:VideoDone");
-
- if (restore_code) {
- setmem(TRUE);
- if (restore_code==1) // restore
- _fmemcpy (MK_FP (((WORD) &_B000H),0), screen_hold, 80*25*2); // restore text screen
- else { // clear
- int j;
- WORD far *p, hold;
-
- p = MK_FP (((WORD) &_B000H),0);
- for (j=0;j<80*25;j++)
- p[j] = 0x0720; // grey on black spaces
- }
- setmem(FALSE);
- }
-
- if (debug_string)
- fclose (debug_file);
-
- return 1;
- }
-
- //--------------------------------------------------------------------------//
- WORD _win VideoIsColor (void)
- /*
- This function is called to determine if we are in color or mono mode.
- */
- {
- dll_check (); // make sure that we are supposed to be called
- if (debug_string)
- fprintf (debug_file,"\nTDVIDEO.DLL:VideoIsColor = %d", use_color_colors);
-
- return use_color_colors;
- }
-
- //--------------------------------------------------------------------------//
- WORD _win VideoGetTextSelector (int display)
- /*
- This function returns the protected mode selector that corresponds to
- the real mode segment of the text screen requested.
- Display is ignored for this driver and we always return a selector for
- the monochrome area (0xB000).
- */
- { static int first_in = 1; // flag for noting the first time in selector call
- display+=0; // no warning
-
- dll_check (); // make sure that we are supposed to be called
-
- if (first_in) {
- first_in = 0;
- if (restore_code==1) {
- setmem(TRUE);
- _fmemcpy (screen_hold, MK_FP (((WORD) &_B000H), 0), 80*25*2); // save text screen
- setmem(FALSE);
- }
- }
-
- if (debug_string)
- { mono ("TDVIDEO.DLL:VideoGetTextSelector");
- fprintf (debug_file, " (Mono) - B000=%04X",(WORD)&_B000H);
- force (debug_file);
- }
- return (((WORD) &_B000H));
- }
-
- //--------------------------------------------------------------------------//
- void _win VideoSetCursor (WORD x, WORD y)
- /*
- This function positions the cursor on the text mode screen.
- */
- { WORD a, port = 0x3B4; // mono port
-
- dll_check (); // make sure that we are supposed to be called
-
- if (debug_string)
- { mono ("TDVIDEO.DLL:VideoSetCursor");
- fprintf (debug_file, " (%03d,%03d)",x,y);
- }
-
- a = y * 80 + x;
- outportb (port, 0x0E); // cursor location high byte reg.
- _CX = a;
- outport (port+1, _CH);
- outportb (port, 0x0F); // cursor location low byte reg.
- _CX = a;
- outport (port+1, _CL);
- force (debug_file);
- }
- //--------------------------------------------------------------------------//
- void _win VideoDebuggerScreen (void)
- /*
- This function saves the palette and video memory, and switches into
- text mode.
- */
-
- {
- dll_check (); // make sure that we are supposed to be called
- if (debug_string)
- mono ("TDVIDEO.DLL:VideoDebuggerScreen");
- force (debug_file);
- setmem(TRUE);
- }
-
- //--------------------------------------------------------------------------//
- void _win VideoWindowsScreen (void)
- /*
- This function switches back into graphics mode, restoring the
- palette, and video memory.
- */
-
- {
- dll_check (); // make sure that we are supposed to be called
- if (debug_string)
- mono ("TDVIDEO.DLL:VideoWindowsScreen");
- force (debug_file);
- setmem(FALSE);
- }
- //--------------------------------------------------------------------------//
- WORD _win VideoBigSize (void)
- /*
- This function returns the maximum number of lines that the high res
- text mode can handle (25 for the monochrome screen).
- */
- { return(25);
- }
-
- //--------------------------------------------------------------------------//
- void _win VideoSetSize (WORD bigflag)
- /*
- This function changes the text mode to (bigflag==1) 50 line mode, or
- (bigflag==0), 25 line mode.
- */
-
- { bigflag+=0; //satisfay compiler warning
- return;
- }
- //--------------------------------------------------------------------------//
-
-