Initial. Don't... just don't ask.
This commit is contained in:
commit
00bae13bba
586 changed files with 129057 additions and 0 deletions
1
utils/0-README
Normal file
1
utils/0-README
Normal file
|
|
@ -0,0 +1 @@
|
|||
Please read the resp. manual pages on each of the utilities in here.
|
||||
69
utils/Makefile
Normal file
69
utils/Makefile
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
#----------------------------------------------------------------------
|
||||
# Makefile for SVGAlib utilities.
|
||||
#
|
||||
# This file is a part of SVGAlib.
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
include ../Makefile.cfg
|
||||
|
||||
srcdir = ..
|
||||
VPATH = $(srcdir)/utils
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
# Compiler Section (overrides Makefile.cfg)
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
CFLAGS = $(WARN) $(OPTIMIZE) -I../include -L../sharedlib
|
||||
#Use the next one for the Alpha/AXP if you need it
|
||||
#LDFLAGS = -L../staticlib
|
||||
LIBS = -lvga -lm
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
# Rules Section
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
UTILPROGS = restorefont convfont restoretextmode restorepalette dumpreg gtfcalc
|
||||
OBJECTS = restorefont.o convfont.o restoretextmode.o restorepalette.o dumpreg.o
|
||||
|
||||
ifeq ($(ARCH),i386)
|
||||
UTILPROGS += fix132x43 setmclk
|
||||
OBJECTS += fix132x43.o setmclk.o
|
||||
endif
|
||||
|
||||
.c.o:
|
||||
$(CC) $(CFLAGS) -c -o $*.o $<
|
||||
|
||||
.o:
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $* $*.o $(LIBS)
|
||||
chmod 4755 $*
|
||||
|
||||
all: $(UTILPROGS)
|
||||
.PHONY: all clean cleanbin dep
|
||||
|
||||
$(OBJECTS): .depend
|
||||
|
||||
convfont: convfont.o
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o convfont convfont.o $(LIBS)
|
||||
|
||||
gtfcalc: gtf/gtfcalc.c
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o gtfcalc -DTESTING_GTF gtf/gtfcalc.c $(LIBS)
|
||||
|
||||
clean:
|
||||
rm -f $(UTILPROGS) *.o *~ UVCONFIG.CRT
|
||||
|
||||
dep:
|
||||
rm -f .depend
|
||||
make .depend
|
||||
|
||||
install:
|
||||
$(INSTALLPROG) $(UTILPROGS) $(UTILINSTALLDIR)
|
||||
|
||||
.depend:
|
||||
gcc $(INCLUDES) -MM $(patsubst %.o,$(srcdir)/utils/%.c,$(OBJECTS)) >.depend
|
||||
|
||||
#
|
||||
# include a dependency file if one exists
|
||||
#
|
||||
ifeq (.depend.src,$(wildcard .depend.src))
|
||||
include .depend.src
|
||||
endif
|
||||
81
utils/convfont.c
Normal file
81
utils/convfont.c
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
/* Convert standard binary font to codepage format */
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
int fontheight;
|
||||
int sfontsize;
|
||||
int font_nuchars;
|
||||
unsigned char sfontbuf[32 * 256];
|
||||
unsigned char tfontbuf[32 * 256];
|
||||
FILE *sf;
|
||||
FILE *tf;
|
||||
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
if (argc != 4)
|
||||
{
|
||||
printf ("Syntax: convfont fontfile fontheight vgafontfile\n");
|
||||
printf (
|
||||
"\nconvfont - convert standard format binary font to codepage format\n"
|
||||
"The converted font is written to vgafontfile.\n");
|
||||
printf (
|
||||
"A binary font file of any number of characters up to 256 can be used, although\n"
|
||||
"at least defining the first 128 characters is a good idea. The fontheight\n"
|
||||
"should be in the range 1-32.\n"
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
if ((sf = fopen (argv[1], "rb")) == NULL)
|
||||
{
|
||||
printf ("convfont: Unable to open file.\n");
|
||||
return 1;
|
||||
}
|
||||
if ((tf = fopen (argv[3], "wb")) == NULL)
|
||||
{
|
||||
printf ("convfont: Unable to create file.\n");
|
||||
return 1;
|
||||
}
|
||||
fontheight = atoi (argv[2]);
|
||||
if (fontheight < 1 || fontheight > 32)
|
||||
{
|
||||
printf ("convfont: Invalid fontheight.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
fseek (sf, 0, SEEK_END);
|
||||
sfontsize = ftell (sf);
|
||||
fseek (sf, 0, SEEK_SET);
|
||||
font_nuchars = sfontsize / fontheight;
|
||||
printf ("Converting %d characters\n", font_nuchars);
|
||||
if (font_nuchars < 1 || font_nuchars > 256)
|
||||
{
|
||||
printf ("convfont: Invalid number of characters in font.\n");
|
||||
return 1;
|
||||
}
|
||||
fread (sfontbuf, 1, sfontsize, sf);
|
||||
fclose (sf);
|
||||
for (i = 0; i < font_nuchars; i++)
|
||||
{
|
||||
int j;
|
||||
|
||||
for (j = 0; j < fontheight; j++)
|
||||
tfontbuf[i * 32 + j] =
|
||||
sfontbuf[i * fontheight + j];
|
||||
|
||||
for (j = 0; j < 32 - fontheight; j++)
|
||||
tfontbuf[i * 32 + fontheight] = 0;
|
||||
}
|
||||
/* clear remaining characters */
|
||||
for (i = font_nuchars * 32; i < 32 * 256; i++)
|
||||
tfontbuf[i] = 0;
|
||||
printf ("Writing font file.\n");
|
||||
fwrite (tfontbuf, 1, 32 * 256, tf);
|
||||
fclose (tf);
|
||||
return 0;
|
||||
}
|
||||
14
utils/dumpreg.c
Normal file
14
utils/dumpreg.c
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#include <vga.h>
|
||||
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
/* We can't call vga_init, because register dumping should work */
|
||||
/* from within X, and vga_init will exit in that case. */
|
||||
vga_init();
|
||||
vga_dumpregs ();
|
||||
vga_screenon ();
|
||||
/* vga_setmode(TEXT); Hack to unblank screen. */
|
||||
return 0;
|
||||
}
|
||||
219
utils/fix132x43.c
Normal file
219
utils/fix132x43.c
Normal file
|
|
@ -0,0 +1,219 @@
|
|||
/*
|
||||
This file assumes 132 column textmode :-).
|
||||
|
||||
This program tries to fix problems with extended textmodes on some cards. The problem is that for 132x43 textmode, some
|
||||
BIOSes set the vertical display end register to 349 (350), instead of 343 (344 = 3 * 8 scanlines). Because in Linux textmode
|
||||
video memory is usually filled with old text that has already scrolled away (this includes the area below the 43rd textmode
|
||||
line, which changes when the console scrolls), the top half of a constantly changing irrelevant text line is visible
|
||||
at the bottom of the screen, which is very annoying.
|
||||
|
||||
This program sets the VGA Vertical Display End register to the proper value.
|
||||
|
||||
The problem is at least present in the BIOS of most Cirrus Logic 542x based cards, and some WD90C03x based cards.
|
||||
|
||||
|
||||
You can also change the number scanlines and number of lines per character of 132x43 textmode to improve readability.
|
||||
|
||||
|
||||
VGA CRTC 0x12 bits 0-7 Vertical Display End Register bits 0-7
|
||||
VGA CRTC 0x07 bit 1 Vertical Display End Register bit 8
|
||||
|
||||
Cirrus 542x BIOS v1.10 132x43: 0x15d (349) (this is the wrong value that the BIOS sets)
|
||||
Correct value for 132x43: 0x157 (343)
|
||||
Correct value for 132x44: 0x15f (351)
|
||||
|
||||
|
||||
VGA CRTC 0x09 bits 0-4 Number of scanlines in a textmode font character.
|
||||
VGA MiscOut bits 6-7 Indicates number of scanlines: 1 = 400, 2 = 350, 3 = 480.
|
||||
VGA CRTC 0x06 bits 0-7 Vertical Total register bits 0-7 (should be #scanlines - 2)
|
||||
Bit 8 is in VGA CRTC 0x07, bit 0
|
||||
Bit 9 is in VGA CRTC 0x07, bit 5
|
||||
VGA CRTC 0x10 bits 0-7 Vertical Retrace Start
|
||||
Bit 8 is in VGA CRTC 0x07, bit 2
|
||||
Bit 9 is in VGA CRTC 0x07, bit 7
|
||||
VGA CRTC 0x11 bits 0-3 Vertical Retrace End (last 4 bits)
|
||||
VGA CRTC 0x15 bits 0-7 Vertical Blank Start
|
||||
Bit 8 is in VGA CRTC 0x07 bit 3
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/* Comment this out if setting graphics modes is undesirable. You can load proper fonts with restorefont. */
|
||||
#define FIX_FONT
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <vga.h>
|
||||
#include "sys/io.h" /* For port I/O macros. */
|
||||
#define OUTB(a,d) outb(d,a)
|
||||
|
||||
static void fixfont (int);
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
int vgaIOBase;
|
||||
unsigned char val;
|
||||
int lines;
|
||||
|
||||
vga_disabledriverreport ();
|
||||
vga_setchipset (VGA);
|
||||
vga_init ();
|
||||
|
||||
if (argc == 1)
|
||||
{
|
||||
printf ("Fiddle with 132x43 textmode VGA registers.\n");
|
||||
printf ("Syntax: fix132x43 option (one at a time).\n");
|
||||
printf (" -f Fix problem of annoying changing line of text at bottom of screen.\n");
|
||||
printf (" -v Switch to 9 line characters (400 line frame, 70 Hz).\n");
|
||||
#ifdef INCLUDE_480LINEMODE
|
||||
printf (" -w Switch to 11 line characters (480 line frame, 60 Hz).\n");
|
||||
#endif
|
||||
printf (" -r Switch to 8 line characters again (350 line frame, 70 Hz).\n");
|
||||
printf ("LINES environment variable is used to detect 43 or 44 line console.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (argv[1][0] != '-')
|
||||
{
|
||||
printf ("Must specify -f, -v or -r.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (argv[1][1] != 'f' && argv[1][1] != 'v' && argv[1][1] != 'w' && argv[1][1] != 'r')
|
||||
{
|
||||
printf ("Must specify -f, -v, or -r.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
lines = atoi (getenv ("LINES"));
|
||||
printf ("Lines: %d\n", lines);
|
||||
|
||||
/* Deprotect CRT registers 0-7. */
|
||||
vgaIOBase = (inb (0x3cc) & 0x01) ? 0x3D0 : 0x3B0;
|
||||
OUTB (vgaIOBase + 4, 0x11);
|
||||
val = inb (vgaIOBase + 5);
|
||||
OUTB (vgaIOBase + 5, val & 0x7f);
|
||||
|
||||
if (argv[1][1] == 'f')
|
||||
{
|
||||
/* Fix stupid bottom line. */
|
||||
OUTB (vgaIOBase + 4, 0x12);
|
||||
OUTB (vgaIOBase + 5, 0x57); /* Value for 43 lines (343). */
|
||||
}
|
||||
|
||||
if (argv[1][1] == 'r')
|
||||
{
|
||||
/* Set 8 line characters, 350 line frame (344 used). */
|
||||
|
||||
OUTB (vgaIOBase + 4, 0x09);
|
||||
val = inb (vgaIOBase + 5);
|
||||
OUTB (vgaIOBase + 5, (val & 0xe0) | 7); /* Set 8-line characters. */
|
||||
|
||||
val = inb (0x3cc);
|
||||
OUTB (0x3c2, (val & 0x3f) | (2 << 6)); /* 350 scanlines. */
|
||||
|
||||
OUTB (vgaIOBase + 4, 0x12); /* Vertical Display End */
|
||||
if (lines == 44)
|
||||
OUTB (vgaIOBase + 5, 0x60); /* Value for 44 lines (352). */
|
||||
else
|
||||
OUTB (vgaIOBase + 5, 0x57); /* Value for 43 lines (343). */
|
||||
|
||||
OUTB (vgaIOBase + 4, 0x10); /* Retrace Start */
|
||||
OUTB (vgaIOBase + 5, 0x83); /* Value for 350 line frame. */
|
||||
|
||||
OUTB (vgaIOBase + 4, 0x11); /* Retrace End */
|
||||
val = inb (vgaIOBase + 5);
|
||||
OUTB (vgaIOBase + 5, (val & 0xf0) | 0x05);
|
||||
|
||||
OUTB (vgaIOBase + 4, 0x15); /* Vertical Blank Start */
|
||||
OUTB (vgaIOBase + 5, 0x63); /* Value for 350 line frame. */
|
||||
}
|
||||
|
||||
if (argv[1][1] == 'v')
|
||||
{
|
||||
/* Set 9 line characters, 400 line frame (387 used). */
|
||||
|
||||
OUTB (vgaIOBase + 4, 0x09);
|
||||
val = inb (vgaIOBase + 5);
|
||||
OUTB (vgaIOBase + 5, (val & 0xe0) | 8); /* Set 9-line characters. */
|
||||
|
||||
val = inb (0x3cc);
|
||||
OUTB (0x3c2, (val & 0x3f) | (1 << 6)); /* 400 scanlines. */
|
||||
|
||||
OUTB (vgaIOBase + 4, 0x12);
|
||||
if (lines == 44)
|
||||
OUTB (vgaIOBase + 5, 0x8b); /* End scanline is 44 * 9 - 1 = 395 */
|
||||
else
|
||||
OUTB (vgaIOBase + 5, 0x82); /* End scanline is 43 * 9 - 1 = 386 */
|
||||
|
||||
OUTB (vgaIOBase + 4, 0x10); /* Retrace Start */
|
||||
OUTB (vgaIOBase + 5, 0x9c); /* Value for 400 line frame. */
|
||||
|
||||
OUTB (vgaIOBase + 4, 0x11); /* Retrace End */
|
||||
val = inb (vgaIOBase + 5);
|
||||
OUTB (vgaIOBase + 5, (val & 0xf0) | 0x0e);
|
||||
|
||||
OUTB (vgaIOBase + 4, 0x15); /* Vertical Blank Start */
|
||||
OUTB (vgaIOBase + 5, 0x95); /* Value for 400 line frame. */
|
||||
|
||||
#ifdef FIX_FONT
|
||||
fixfont (9);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef INCLUDE_480LINEMODE
|
||||
if (argv[1][1] == 'w')
|
||||
{
|
||||
/* Set 11 line characters, 480 line frame (473 used). */
|
||||
|
||||
OUTB (vgaIOBase + 4, 0x09);
|
||||
val = inb (vgaIOBase + 5);
|
||||
OUTB (vgaIOBase + 5, (val & 0xe0) | 10); /* Set 11-line characters. */
|
||||
|
||||
OUTB (0x3c2, 0xeb);
|
||||
|
||||
OUTB (vgaIOBase + 4, 0x12);
|
||||
OUTB (vgaIOBase + 5, 0xd8); /* End scanline is 43 * 11 - 1 = 472 */
|
||||
|
||||
OUTB (vgaIOBase + 4, 0x10); /* Retrace Start */
|
||||
OUTB (vgaIOBase + 5, 0xf4 /*0xea */ ); /* Value for 480 line frame. ?? */
|
||||
|
||||
OUTB (vgaIOBase + 4, 0x11); /* Retrace End */
|
||||
val = inb (vgaIOBase + 5);
|
||||
OUTB (vgaIOBase + 5, (val & 0xf0) | 0x0c);
|
||||
|
||||
OUTB (vgaIOBase + 4, 0x15); /* Vertical Blank Start */
|
||||
OUTB (vgaIOBase + 5, 0xf4 /*0xe7 */ ); /* Value for 480 line frame. */
|
||||
|
||||
#ifdef FIX_FONT
|
||||
fixfont (11);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Clear offsets 8-31 of each character bitmap (the BIOS usually leaves some trash here from the 16 line font that was loaded */
|
||||
/* prior to setting 132x43 (8 line font) textmode). */
|
||||
|
||||
static void
|
||||
fixfont (int lines)
|
||||
{
|
||||
unsigned char font[8192];
|
||||
int i;
|
||||
vga_setmode (G640x480x16);
|
||||
vga_gettextfont (font);
|
||||
|
||||
for (i = 0; i < 256; i++)
|
||||
memset (font + i * 32 + 8, 0, 32 - 8); /* Clear remaining part of character bitmap buffer. */
|
||||
|
||||
vga_puttextfont (font);
|
||||
vga_setmode (TEXT);
|
||||
}
|
||||
BIN
utils/font14
Normal file
BIN
utils/font14
Normal file
Binary file not shown.
BIN
utils/font16
Normal file
BIN
utils/font16
Normal file
Binary file not shown.
BIN
utils/font8
Normal file
BIN
utils/font8
Normal file
Binary file not shown.
152
utils/gtf/gtf.h
Normal file
152
utils/gtf/gtf.h
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
/****************************************************************************
|
||||
*
|
||||
* VESA Generalized Timing Formula (GTF)
|
||||
* Version 1.0
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* The contents of this file are subject to the SciTech MGL Public
|
||||
* License Version 1.0 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.scitechsoft.com/mgl-license.txt
|
||||
*
|
||||
* Software distributed under the License is distributed on an
|
||||
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc.
|
||||
*
|
||||
* The Initial Developer of the Original Code is SciTech Software, Inc.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Developed by: SciTech Software, Inc.
|
||||
*
|
||||
* Language: ANSI C
|
||||
* Environment: Any
|
||||
*
|
||||
* Description: Header file for generating GTF compatible timings given a
|
||||
* set of input requirements. Translated from the original GTF
|
||||
* 1.14 spreadsheet definition.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __GTF_H
|
||||
#define __GTF_H
|
||||
|
||||
#ifndef __SCITECH_H
|
||||
#include "scitech.h"
|
||||
#endif
|
||||
|
||||
/*---------------------- Macros and type definitions ----------------------*/
|
||||
|
||||
/* Define the structures for holding the horizontal and vertical
|
||||
* CRTC parameters for a mode.
|
||||
*
|
||||
* Note: The sync timings are defined in both VGA compatible timings
|
||||
* (sync start and sync end positions) and also in GTF compatible
|
||||
* modes with the front porch, sync width and back porch defined.
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
int hTotal; /* Horizontal total */
|
||||
int hDisp; /* Horizontal displayed */
|
||||
int hSyncStart; /* Horizontal sync start */
|
||||
int hSyncEnd; /* Horizontal sync end */
|
||||
int hFrontPorch; /* Horizontal front porch */
|
||||
int hSyncWidth; /* Horizontal sync width */
|
||||
int hBackPorch; /* Horizontal back porch */
|
||||
} GTF_hCRTC;
|
||||
|
||||
typedef struct {
|
||||
int vTotal; /* Vertical total */
|
||||
int vDisp; /* Vertical displayed */
|
||||
int vSyncStart; /* Vertical sync start */
|
||||
int vSyncEnd; /* Vertical sync end */
|
||||
int vFrontPorch; /* Vertical front porch */
|
||||
int vSyncWidth; /* Vertical sync width */
|
||||
int vBackPorch; /* Vertical back porch */
|
||||
} GTF_vCRTC;
|
||||
|
||||
/* Define the main structure for holding generated GTF timings */
|
||||
|
||||
typedef struct {
|
||||
GTF_hCRTC h; /* Horizontal CRTC paremeters */
|
||||
GTF_vCRTC v; /* Vertical CRTC parameters */
|
||||
char hSyncPol; /* Horizontal sync polarity */
|
||||
char vSyncPol; /* Vertical sync polarity */
|
||||
char interlace; /* 'I' for Interlace, 'N' for Non */
|
||||
double vFreq; /* Vertical frequency (Hz) */
|
||||
double hFreq; /* Horizontal frequency (KHz) */
|
||||
double dotClock; /* Pixel clock (Mhz) */
|
||||
} GTF_timings;
|
||||
|
||||
/* Define the structure for holding standard GTF formula constants */
|
||||
|
||||
typedef struct {
|
||||
double margin; /* Margin size as percentage of display */
|
||||
double cellGran; /* Character cell granularity */
|
||||
double minPorch; /* Minimum front porch in lines/chars */
|
||||
double vSyncRqd; /* Width of V sync in lines */
|
||||
double hSync; /* Width of H sync as percent of total */
|
||||
double minVSyncBP; /* Minimum vertical sync + back porch (us) */
|
||||
double m; /* Blanking formula gradient */
|
||||
double c; /* Blanking formula offset */
|
||||
double k; /* Blanking formula scaling factor */
|
||||
double j; /* Blanking formula scaling factor weight */
|
||||
} GTF_constants;
|
||||
|
||||
#define GTF_lockVF 1 /* Lock to vertical frequency */
|
||||
#define GTF_lockHF 2 /* Lock to horizontal frequency */
|
||||
#define GTF_lockPF 3 /* Lock to pixel clock frequency */
|
||||
|
||||
/*-------------------------- Function Prototypes --------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" { /* Use "C" linkage when in C++ mode */
|
||||
#endif
|
||||
|
||||
/* Generate a set of timings for a mode from the GTF formulas. This will
|
||||
* allow you to generate a set of timings by specifying the type as:
|
||||
*
|
||||
* 1. Vertical frequency
|
||||
* 2. Horizontal frequency
|
||||
* 3. Pixel clock
|
||||
*
|
||||
* Generally if you want to find the timings for a specific vertical
|
||||
* frequency, you may want to generate a first set of timings given the
|
||||
* desired vertical frequency, which will give you a specific horizontal
|
||||
* frequency and dot clock. You can then adjust the dot clock to a value
|
||||
* that is known to be available on the underlying hardware, and then
|
||||
* regenerate the timings for that particular dot clock to determine what
|
||||
* the exact final timings will be.
|
||||
*
|
||||
* Alternatively if you only have a fixed set of dot clocks available such
|
||||
* as on older controllers, you can simply run through the set of available
|
||||
* dot clocks, and generate a complete set of all available timings that
|
||||
* can be generated with the set of available dot clocks (and filter out
|
||||
* unuseable values say < 60Hz and > 120Hz).
|
||||
*/
|
||||
|
||||
void GTF_calcTimings(double hPixels,double vLines,double freq,int type,
|
||||
ibool wantMargins,ibool wantInterlace,GTF_timings *timings);
|
||||
|
||||
/* Functions to read and write the current set of GTF formula constants.
|
||||
* These constants should be left in the default state that is defined
|
||||
* by the current version of the GTF specification. However newer DDC
|
||||
* monitos that support the GTF specification may be able to pass back a
|
||||
* table of GTF constants to fine tune the GTF timings for their particular
|
||||
* requirements.
|
||||
*/
|
||||
|
||||
void GTF_getConstants(GTF_constants *constants);
|
||||
void GTF_setConstants(GTF_constants *constants);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* End of "C" linkage for C++ */
|
||||
#endif
|
||||
|
||||
#endif /* __GTF_H */
|
||||
441
utils/gtf/gtfcalc.c
Normal file
441
utils/gtf/gtfcalc.c
Normal file
|
|
@ -0,0 +1,441 @@
|
|||
/****************************************************************************
|
||||
*
|
||||
* VESA Generalized Timing Formula (GTF)
|
||||
* Version 1.1
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* The contents of this file are subject to the SciTech MGL Public
|
||||
* License Version 1.0 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.scitechsoft.com/mgl-license.txt
|
||||
*
|
||||
* Software distributed under the License is distributed on an
|
||||
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc.
|
||||
*
|
||||
* The Initial Developer of the Original Code is SciTech Software, Inc.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Developed by: SciTech Software, Inc.
|
||||
*
|
||||
* Language: ANSI C
|
||||
* Environment: Any.
|
||||
*
|
||||
* Description: C module for generating GTF compatible timings given a set
|
||||
* of input requirements. Translated from the original GTF
|
||||
* 1.14 spreadsheet definition.
|
||||
*
|
||||
* Compile with #define TESTING to build a command line test
|
||||
* program.
|
||||
*
|
||||
* NOTE: The code in here has been written for clarity and
|
||||
* to follow the original GTF spec as closely as
|
||||
* possible.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
#include "gtf.h"
|
||||
|
||||
/*------------------------- Global Variables ------------------------------*/
|
||||
|
||||
static GTF_constants GC = {
|
||||
1.8, /* Margin size as percentage of display */
|
||||
8, /* Character cell granularity */
|
||||
1, /* Minimum front porch in lines/chars */
|
||||
3, /* Width of V sync in lines */
|
||||
8, /* Width of H sync as percent of total */
|
||||
550, /* Minimum vertical sync + back porch (us) */
|
||||
600, /* Blanking formula gradient */
|
||||
40, /* Blanking formula offset */
|
||||
128, /* Blanking formula scaling factor */
|
||||
20, /* Blanking formula scaling factor weight */
|
||||
};
|
||||
|
||||
/*-------------------------- Implementation -------------------------------*/
|
||||
|
||||
static double round(double v)
|
||||
{
|
||||
return floor(v + 0.5);
|
||||
}
|
||||
|
||||
static void GetInternalConstants(GTF_constants *c)
|
||||
/****************************************************************************
|
||||
*
|
||||
* Function: GetInternalConstants
|
||||
* Parameters: c - Place to store the internal constants
|
||||
*
|
||||
* Description: Calculates the rounded, internal set of GTF constants.
|
||||
* These constants are different to the real GTF constants
|
||||
* that can be set up for the monitor. The calculations to
|
||||
* get these real constants are defined in the 'Work Area'
|
||||
* after the constants are defined in the Excel spreadsheet.
|
||||
*
|
||||
****************************************************************************/
|
||||
{
|
||||
c->margin = GC.margin;
|
||||
c->cellGran = round(GC.cellGran);
|
||||
c->minPorch = round(GC.minPorch);
|
||||
c->vSyncRqd = round(GC.vSyncRqd);
|
||||
c->hSync = GC.hSync;
|
||||
c->minVSyncBP = GC.minVSyncBP;
|
||||
if (GC.k == 0)
|
||||
c->k = 0.001;
|
||||
else
|
||||
c->k = GC.k;
|
||||
c->m = (c->k / 256) * GC.m;
|
||||
c->c = (GC.c - GC.j) * (c->k / 256) + GC.j;
|
||||
c->j = GC.j;
|
||||
}
|
||||
|
||||
void GTF_calcTimings(double hPixels,double vLines,double freq,
|
||||
int type,ibool wantMargins,ibool wantInterlace,GTF_timings *t)
|
||||
/****************************************************************************
|
||||
*
|
||||
* Function: GTF_calcTimings
|
||||
* Parameters: hPixels - X resolution
|
||||
* vLines - Y resolution
|
||||
* freq - Frequency (Hz, KHz or MHz depending on type)
|
||||
* type - 1 - vertical, 2 - horizontal, 3 - dot clock
|
||||
* margins - True if margins should be generated
|
||||
* interlace - True if interlaced timings to be generated
|
||||
* t - Place to store the resulting timings
|
||||
*
|
||||
* Description: Calculates a set of GTF timing parameters given a specified
|
||||
* resolution and vertical frequency. The horizontal frequency
|
||||
* and dot clock will be automatically generated by this
|
||||
* routines.
|
||||
*
|
||||
* For interlaced modes the CRTC parameters are calculated for
|
||||
* a single field, so will be half what would be used in
|
||||
* a non-interlaced mode.
|
||||
*
|
||||
****************************************************************************/
|
||||
{
|
||||
double interlace,vFieldRate,hPeriod;
|
||||
double topMarginLines,botMarginLines;
|
||||
double leftMarginPixels,rightMarginPixels;
|
||||
double hPeriodEst,vSyncBP,vBackPorch;
|
||||
double vTotalLines,vFieldRateEst;
|
||||
double hTotalPixels,hTotalActivePixels,hBlankPixels;
|
||||
double idealDutyCycle,hSyncWidth,hSyncBP,hBackPorch;
|
||||
double idealHPeriod;
|
||||
double vFreq,hFreq,dotClock;
|
||||
GTF_constants c;
|
||||
|
||||
/* Get rounded GTF constants used for internal calculations */
|
||||
GetInternalConstants(&c);
|
||||
|
||||
/* Move input parameters into appropriate variables */
|
||||
vFreq = hFreq = dotClock = freq;
|
||||
|
||||
/* Round pixels to character cell granularity */
|
||||
hPixels = round(hPixels / c.cellGran) * c.cellGran;
|
||||
|
||||
/* For interlaced mode halve the vertical parameters, and double
|
||||
* the required field refresh rate.
|
||||
*/
|
||||
if (wantInterlace) {
|
||||
vLines = round(vLines / 2);
|
||||
vFieldRate = vFreq * 2;
|
||||
dotClock = dotClock * 2;
|
||||
interlace = 0.5;
|
||||
}
|
||||
else {
|
||||
vFieldRate = vFreq;
|
||||
interlace = 0;
|
||||
}
|
||||
|
||||
/* Determine the lines for margins */
|
||||
if (wantMargins) {
|
||||
topMarginLines = round(c.margin / 100 * vLines);
|
||||
botMarginLines = round(c.margin / 100 * vLines);
|
||||
}
|
||||
else {
|
||||
topMarginLines = 0;
|
||||
botMarginLines = 0;
|
||||
}
|
||||
|
||||
if (type != GTF_lockPF) {
|
||||
if (type == GTF_lockVF) {
|
||||
/* Estimate the horizontal period */
|
||||
hPeriodEst = ((1/vFieldRate) - (c.minVSyncBP/1000000)) /
|
||||
(vLines + (2*topMarginLines) + c.minPorch + interlace) * 1000000;
|
||||
|
||||
/* Find the number of lines in vSync + back porch */
|
||||
vSyncBP = round(c.minVSyncBP / hPeriodEst);
|
||||
}
|
||||
else if (type == GTF_lockHF) {
|
||||
/* Find the number of lines in vSync + back porch */
|
||||
vSyncBP = round((c.minVSyncBP * hFreq) / 1000);
|
||||
}
|
||||
|
||||
/* Find the number of lines in the V back porch alone */
|
||||
vBackPorch = vSyncBP - c.vSyncRqd;
|
||||
|
||||
/* Find the total number of lines in the vertical period */
|
||||
vTotalLines = vLines + topMarginLines + botMarginLines + vSyncBP
|
||||
+ interlace + c.minPorch;
|
||||
|
||||
if (type == GTF_lockVF) {
|
||||
/* Estimate the vertical frequency */
|
||||
vFieldRateEst = 1000000 / (hPeriodEst * vTotalLines);
|
||||
|
||||
/* Find the actual horizontal period */
|
||||
hPeriod = (hPeriodEst * vFieldRateEst) / vFieldRate;
|
||||
|
||||
/* Find the actual vertical field frequency */
|
||||
vFieldRate = 1000000 / (hPeriod * vTotalLines);
|
||||
}
|
||||
else if (type == GTF_lockHF) {
|
||||
/* Find the actual vertical field frequency */
|
||||
vFieldRate = (hFreq / vTotalLines) * 1000;
|
||||
}
|
||||
}
|
||||
|
||||
/* Find the number of pixels in the left and right margins */
|
||||
if (wantMargins) {
|
||||
leftMarginPixels = round(hPixels * c.margin) / (100 * c.cellGran);
|
||||
rightMarginPixels = round(hPixels * c.margin) / (100 * c.cellGran);
|
||||
}
|
||||
else {
|
||||
leftMarginPixels = 0;
|
||||
rightMarginPixels = 0;
|
||||
}
|
||||
|
||||
/* Find the total number of active pixels in image + margins */
|
||||
hTotalActivePixels = hPixels + leftMarginPixels + rightMarginPixels;
|
||||
|
||||
if (type == GTF_lockVF) {
|
||||
/* Find the ideal blanking duty cycle */
|
||||
idealDutyCycle = c.c - ((c.m * hPeriod) / 1000);
|
||||
}
|
||||
else if (type == GTF_lockHF) {
|
||||
/* Find the ideal blanking duty cycle */
|
||||
idealDutyCycle = c.c - (c.m / hFreq);
|
||||
}
|
||||
else if (type == GTF_lockPF) {
|
||||
/* Find ideal horizontal period from blanking duty cycle formula */
|
||||
idealHPeriod = (((c.c - 100) + (sqrt((pow(100-c.c,2)) +
|
||||
(0.4 * c.m * (hTotalActivePixels + rightMarginPixels +
|
||||
leftMarginPixels) / dotClock)))) / (2 * c.m)) * 1000;
|
||||
|
||||
/* Find the ideal blanking duty cycle */
|
||||
idealDutyCycle = c.c - ((c.m * idealHPeriod) / 1000);
|
||||
}
|
||||
|
||||
/* Find the number of pixels in blanking time */
|
||||
hBlankPixels = round((hTotalActivePixels * idealDutyCycle) /
|
||||
((100 - idealDutyCycle) * 2 * c.cellGran)) * (2 * c.cellGran);
|
||||
|
||||
/* Find the total number of pixels */
|
||||
hTotalPixels = hTotalActivePixels + hBlankPixels;
|
||||
|
||||
/* Find the horizontal back porch */
|
||||
hBackPorch = round((hBlankPixels / 2) / c.cellGran) * c.cellGran;
|
||||
|
||||
/* Find the horizontal sync width */
|
||||
hSyncWidth = round(((c.hSync/100) * hTotalPixels) / c.cellGran) * c.cellGran;
|
||||
|
||||
/* Find the horizontal sync + back porch */
|
||||
hSyncBP = hBackPorch + hSyncWidth;
|
||||
|
||||
if (type == GTF_lockPF) {
|
||||
/* Find the horizontal frequency */
|
||||
hFreq = (dotClock / hTotalPixels) * 1000;
|
||||
|
||||
/* Find the horizontal period */
|
||||
hPeriod = 1000 / hFreq;
|
||||
|
||||
/* Find the number of lines in vSync + back porch */
|
||||
vSyncBP = round((c.minVSyncBP * hFreq) / 1000);
|
||||
|
||||
/* Find the number of lines in the V back porch alone */
|
||||
vBackPorch = vSyncBP - c.vSyncRqd;
|
||||
|
||||
/* Find the total number of lines in the vertical period */
|
||||
vTotalLines = vLines + topMarginLines + botMarginLines + vSyncBP
|
||||
+ interlace + c.minPorch;
|
||||
|
||||
/* Find the actual vertical field frequency */
|
||||
vFieldRate = (hFreq / vTotalLines) * 1000;
|
||||
}
|
||||
else {
|
||||
if (type == GTF_lockVF) {
|
||||
/* Find the horizontal frequency */
|
||||
hFreq = 1000 / hPeriod;
|
||||
}
|
||||
else if (type == GTF_lockHF) {
|
||||
/* Find the horizontal frequency */
|
||||
hPeriod = 1000 / hFreq;
|
||||
}
|
||||
|
||||
/* Find the pixel clock frequency */
|
||||
dotClock = hTotalPixels / hPeriod;
|
||||
}
|
||||
|
||||
/* Find the vertical frame frequency */
|
||||
if (wantInterlace) {
|
||||
vFreq = vFieldRate / 2;
|
||||
dotClock = dotClock / 2;
|
||||
}
|
||||
else
|
||||
vFreq = vFieldRate;
|
||||
|
||||
/* Return the computed frequencies */
|
||||
t->vFreq = vFreq;
|
||||
t->hFreq = hFreq;
|
||||
t->dotClock = dotClock;
|
||||
|
||||
/* Determine the vertical timing parameters */
|
||||
t->h.hTotal = hTotalPixels;
|
||||
t->h.hDisp = hTotalActivePixels;
|
||||
t->h.hSyncStart = t->h.hTotal - hSyncBP;
|
||||
t->h.hSyncEnd = t->h.hTotal - hBackPorch;
|
||||
t->h.hFrontPorch = t->h.hSyncStart - t->h.hDisp;
|
||||
t->h.hSyncWidth = hSyncWidth;
|
||||
t->h.hBackPorch = hBackPorch;
|
||||
|
||||
/* Determine the vertical timing parameters */
|
||||
t->v.vTotal = vTotalLines;
|
||||
t->v.vDisp = vLines;
|
||||
t->v.vSyncStart = t->v.vTotal - vSyncBP;
|
||||
t->v.vSyncEnd = t->v.vTotal - vBackPorch;
|
||||
t->v.vFrontPorch = t->v.vSyncStart - t->v.vDisp;
|
||||
t->v.vSyncWidth = c.vSyncRqd;
|
||||
t->v.vBackPorch = vBackPorch;
|
||||
|
||||
/* Mark as GTF timing using the sync polarities */
|
||||
t->interlace = (wantInterlace) ? 'I' : 'N';
|
||||
t->hSyncPol = '-';
|
||||
t->vSyncPol = '+';
|
||||
}
|
||||
|
||||
void GTF_getConstants(GTF_constants *constants)
|
||||
{ *constants = GC; }
|
||||
|
||||
void GTF_setConstants(GTF_constants *constants)
|
||||
{ GC = *constants; }
|
||||
|
||||
#ifdef TESTING_GTF
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
{
|
||||
FILE *f;
|
||||
double xPixels,yPixels,freq;
|
||||
ibool interlace;
|
||||
GTF_timings t;
|
||||
|
||||
if (argc != 5 && argc != 6) {
|
||||
printf("Usage: GTFCALC <xPixels> <yPixels> <freq> [[Hz] [KHz] [MHz]] [I]\n");
|
||||
printf("\n");
|
||||
printf("where <xPixels> is the horizontal resolution of the mode, <yPixels> is the\n");
|
||||
printf("vertical resolution of the mode. The <freq> value will be the frequency to\n");
|
||||
printf("drive the calculations, and will be either the vertical frequency (in Hz)\n");
|
||||
printf("the horizontal frequency (in KHz) or the dot clock (in MHz). To generate\n");
|
||||
printf("timings for an interlaced mode, add 'I' to the end of the command line.\n");
|
||||
printf("\n");
|
||||
printf("For example to generate timings for 640x480 at 60Hz vertical:\n");
|
||||
printf("\n");
|
||||
printf(" GTFCALC 640 480 60 Hz\n");
|
||||
printf("\n");
|
||||
printf("For example to generate timings for 640x480 at 31.5KHz horizontal:\n");
|
||||
printf("\n");
|
||||
printf(" GTFCALC 640 480 31.5 KHz\n");
|
||||
printf("\n");
|
||||
printf("For example to generate timings for 640x480 with a 25.175Mhz dot clock:\n");
|
||||
printf("\n");
|
||||
printf(" GTFCALC 640 480 25.175 MHz\n");
|
||||
printf("\n");
|
||||
printf("GTFCALC will print a summary of the results found, and dump the CRTC\n");
|
||||
printf("values to the UVCONFIG.CRT file in the format used by SciTech Display Doctor.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Get values from command line */
|
||||
xPixels = atof(argv[1]);
|
||||
yPixels = atof(argv[2]);
|
||||
freq = atof(argv[3]);
|
||||
interlace = ((argc == 6) && (argv[5][0] == 'I'));
|
||||
|
||||
/* Compute the CRTC timings */
|
||||
if (toupper(argv[4][0]) == 'H')
|
||||
GTF_calcTimings(xPixels,yPixels,freq,GTF_lockVF,false,interlace,&t);
|
||||
else if (toupper(argv[4][0]) == 'K')
|
||||
GTF_calcTimings(xPixels,yPixels,freq,GTF_lockHF,false,interlace,&t);
|
||||
else if (toupper(argv[4][0]) == 'M')
|
||||
GTF_calcTimings(xPixels,yPixels,freq,GTF_lockPF,false,interlace,&t);
|
||||
else {
|
||||
printf("Unknown command line!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Dump summary info to standard output */
|
||||
printf("CRTC values for %.0fx%.0f @ %.2f %s\n", xPixels, yPixels, freq, argv[4]);
|
||||
printf("\n");
|
||||
printf(" hTotal = %-4d vTotal = %-4d\n",
|
||||
t.h.hTotal, t.v.vTotal);
|
||||
printf(" hDisp = %-4d vDisp = %-4d\n",
|
||||
t.h.hDisp, t.v.vDisp);
|
||||
printf(" hSyncStart = %-4d vSyncStart = %-4d\n",
|
||||
t.h.hSyncStart, t.v.vSyncStart);
|
||||
printf(" hSyncEnd = %-4d vSyncEnd = %-4d\n",
|
||||
t.h.hSyncEnd, t.v.vSyncEnd);
|
||||
printf(" hFrontPorch = %-4d vFrontPorch = %-4d\n",
|
||||
t.h.hFrontPorch, t.v.vFrontPorch);
|
||||
printf(" hSyncWidth = %-4d vSyncWidth = %-4d\n",
|
||||
t.h.hSyncWidth, t.v.vSyncWidth);
|
||||
printf(" hBackPorch = %-4d vBackPorch = %-4d\n",
|
||||
t.h.hBackPorch, t.v.vBackPorch);
|
||||
printf("\n");
|
||||
printf(" Interlaced = %s\n", (t.interlace == 'I') ? "Yes" : "No");
|
||||
printf(" H sync pol = %c\n", t.hSyncPol);
|
||||
printf(" V sync pol = %c\n", t.vSyncPol);
|
||||
printf("\n");
|
||||
printf(" Vert freq = %.2f Hz\n", t.vFreq);
|
||||
printf(" Horiz freq = %.2f KHz\n", t.hFreq);
|
||||
printf(" Dot Clock = %.2f Mhz\n", t.dotClock);
|
||||
fprintf(stderr,"Modeline %c%ix%i@%.0f%c %.3f %i %i %i %i %i %i %i %i %s %chsync %cvsync\n",
|
||||
'"',t.h.hDisp,t.v.vDisp,t.vFreq,'"',
|
||||
t.dotClock,
|
||||
t.h.hDisp,
|
||||
t.h.hSyncStart,
|
||||
t.h.hSyncEnd,
|
||||
t.h.hTotal,
|
||||
t.v.vDisp,
|
||||
t.v.vSyncStart,
|
||||
t.v.vSyncEnd,
|
||||
t.v.vTotal,
|
||||
(t.interlace == 'I') ? "Interlace" : "",
|
||||
t.hSyncPol,
|
||||
t.vSyncPol
|
||||
);
|
||||
|
||||
/* Dump to file in format used by SciTech Display Doctor */
|
||||
if ((f = fopen("UVCONFIG.CRT","wt")) != NULL) {
|
||||
fprintf(f, "[%.0f %.0f]\n", xPixels, yPixels);
|
||||
fprintf(f, "%d %d %d %d '%c' %s\n",
|
||||
t.h.hTotal, t.h.hDisp,
|
||||
t.h.hSyncStart, t.h.hSyncEnd,
|
||||
t.hSyncPol, (t.interlace == 'I') ? "I" : "NI");
|
||||
fprintf(f, "%d %d %d %d '%c'\n",
|
||||
t.v.vTotal, t.v.vDisp,
|
||||
t.v.vSyncStart, t.v.vSyncEnd,
|
||||
t.vSyncPol);
|
||||
fprintf(f, "%.2f\n", t.dotClock);
|
||||
fclose(f);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* TESTING */
|
||||
506
utils/gtf/scitech.h
Normal file
506
utils/gtf/scitech.h
Normal file
|
|
@ -0,0 +1,506 @@
|
|||
/****************************************************************************
|
||||
*
|
||||
* SciTech Multi-platform Graphics Library
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* The contents of this file are subject to the SciTech MGL Public
|
||||
* License Version 1.0 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.scitechsoft.com/mgl-license.txt
|
||||
*
|
||||
* Software distributed under the License is distributed on an
|
||||
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc.
|
||||
*
|
||||
* The Initial Developer of the Original Code is SciTech Software, Inc.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* ========================================================================
|
||||
*
|
||||
* Language: ANSI C
|
||||
* Environment: any
|
||||
*
|
||||
* Description: General header file for operating system portable code.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __SCITECH_H
|
||||
#define __SCITECH_H
|
||||
|
||||
/* We have the following defines to identify the compilation environment:
|
||||
*
|
||||
* __16BIT__ Compiling for 16 bit code (any environment)
|
||||
* __32BIT__ Compiling for 32 bit code (any environment)
|
||||
* __MSDOS__ Compiling for MS-DOS (includes __WINDOWS16__, __WIN386__)
|
||||
* __REALDOS__ Compiling for MS-DOS (excludes __WINDOWS16__)
|
||||
* __MSDOS16__ Compiling for 16 bit MS-DOS
|
||||
* __MSDOS32__ Compiling for 32 bit MS-DOS
|
||||
* __WINDOWS__ Compiling for Windows
|
||||
* __WINDOWS16__ Compiling for 16 bit Windows (__MSDOS__ also defined)
|
||||
* __WINDOWS32__ Compiling for 32 bit Windows
|
||||
* __WIN32_VXD__ Compiling for a 32-bit C based VxD
|
||||
* __OS2__ Compiling for OS/2
|
||||
* __OS2_16__ Compiling for 16 bit OS/2
|
||||
* __OS2_32__ Compiling for 32 bit OS/2
|
||||
* __UNIX__ Compiling for Unix
|
||||
* __QNX__ Compiling for the QNX realtime OS (Unix compatible)
|
||||
* __LINUX__ Compiling for the Linux OS (Unix compatible)
|
||||
* __FREEBSD__ Compiling for the FreeBSD OS (Unix compatible)
|
||||
* __BEOS__ Compiling for the BeOS (Unix compatible)
|
||||
* __SMX32__ Compiling for the SMX 32-bit Real Time OS
|
||||
* __DRIVER__ Compiling for a 32-bit binary compatible driver
|
||||
*
|
||||
* __INTEL__ Compiling for Intel CPU's
|
||||
* __ALPHA__ Compiling for DEC Alpha CPU's
|
||||
* __MIPS__ Compiling for MIPS CPU's
|
||||
* __PPC__ Compiling for PowerPC CPU's
|
||||
* __MC68K__ Compiling for Motorola 680x0
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef __SC__
|
||||
#if __INTSIZE == 4
|
||||
#define __SC386__
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
#if !defined(__BEOS__)
|
||||
#define __cdecl /* GCC doesn't know about __cdecl modifiers */
|
||||
#endif
|
||||
#define __FLAT__ /* GCC is always 32 bit flat model */
|
||||
#define __HAS_BOOL__ /* Latest GNU C++ has ibool type */
|
||||
#include <stdio.h> /* Bring in for definition of NULL */
|
||||
#endif
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#if (__BORLANDC__ >= 0x500) || defined(CLASSLIB_DEFS_H)
|
||||
#define __HAS_BOOL__ /* Borland C++ 5.0 and later define ibool type */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
* Determine the compile time environment. This must be done for each
|
||||
* supported platform so that we can determine at compile time the target
|
||||
* environment, hopefully without requiring #define's from the user.
|
||||
*-------------------------------------------------------------------------*/
|
||||
|
||||
/* 32-bit binary compatible driver. Compiled as Win32, but as OS neutral */
|
||||
#ifdef __DRIVER__
|
||||
#ifndef __32BIT__
|
||||
#define __32BIT__
|
||||
#endif
|
||||
#undef __WINDOWS__
|
||||
#undef _WIN32
|
||||
#undef __WIN32__
|
||||
#undef __NT__
|
||||
|
||||
/* 32-bit Windows VxD compile environment */
|
||||
#elif defined(__vtoolsd_h_) || defined(VTOOLSD)
|
||||
#include <vtoolsc.h>
|
||||
#define __WIN32_VXD__
|
||||
#ifndef __32BIT__
|
||||
#define __32BIT__
|
||||
#endif
|
||||
#define _MAX_PATH 256
|
||||
#ifndef __WINDOWS32__
|
||||
#define __WINDOWS32__
|
||||
#endif
|
||||
|
||||
/* 32-bit SMX compile environment */
|
||||
#elif defined(__SMX32__)
|
||||
#ifndef __MSDOS__
|
||||
#define __MSDOS__
|
||||
#endif
|
||||
#ifndef __32BIT__
|
||||
#define __32BIT__
|
||||
#endif
|
||||
#ifndef __REALDOS__
|
||||
#define __REALDOS__
|
||||
#endif
|
||||
|
||||
/* 32-bit extended DOS compile environment */
|
||||
#elif defined(__MSDOS__) || defined(__MSDOS32__) || defined(__DOS__) || defined(__DPMI32__) || (defined(M_I86) && !defined(__SC386__)) || defined(TNT)
|
||||
#ifndef __MSDOS__
|
||||
#define __MSDOS__
|
||||
#endif
|
||||
#if defined(__MSDOS32__) || defined(__386__) || defined(__FLAT__) || defined(__NT__) || defined(__SC386__)
|
||||
#ifndef __MSDOS32__
|
||||
#define __MSDOS32__
|
||||
#endif
|
||||
#ifndef __32BIT__
|
||||
#define __32BIT__
|
||||
#endif
|
||||
#ifndef __REALDOS__
|
||||
#define __REALDOS__
|
||||
#endif
|
||||
|
||||
/* 16-bit Windows compile environment */
|
||||
#elif (defined(_Windows) || defined(_WINDOWS)) && !defined(__DPMI16__)
|
||||
#ifndef __16BIT__
|
||||
#define __16BIT__
|
||||
#endif
|
||||
#ifndef __WINDOWS16__
|
||||
#define __WINDOWS16__
|
||||
#endif
|
||||
#ifndef __WINDOWS__
|
||||
#define __WINDOWS__
|
||||
#endif
|
||||
#ifndef __MSDOS__
|
||||
#define __MSDOS__
|
||||
#endif
|
||||
|
||||
/* 16-bit DOS compile environment */
|
||||
#else
|
||||
#ifndef __16BIT__
|
||||
#define __16BIT__
|
||||
#endif
|
||||
#ifndef __MSDOS16__
|
||||
#define __MSDOS16__
|
||||
#endif
|
||||
#ifndef __REALDOS__
|
||||
#define __REALDOS__
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* 32-bit Windows compile environment */
|
||||
#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
#ifndef __32BIT__
|
||||
#define __32BIT__
|
||||
#endif
|
||||
#ifndef __WINDOWS32__
|
||||
#define __WINDOWS32__
|
||||
#endif
|
||||
#ifndef _WIN32
|
||||
#define _WIN32 /* Microsoft Win32 SDK headers use _WIN32 */
|
||||
#endif
|
||||
#ifndef WIN32
|
||||
#define WIN32 /* OpenGL headers use WIN32 */
|
||||
#endif
|
||||
#ifndef __WINDOWS__
|
||||
#define __WINDOWS__
|
||||
#endif
|
||||
|
||||
/* 16-bit OS/2 compile environment */
|
||||
#elif defined(__OS2_16__)
|
||||
#ifndef __OS2__
|
||||
#define __OS2__
|
||||
#endif
|
||||
#ifndef __16BIT__
|
||||
#define __16BIT__
|
||||
#endif
|
||||
|
||||
/* 32-bit OS/2 compile environment */
|
||||
#elif defined(__OS2__) || defined(__OS2_32__)
|
||||
#ifndef __OS2__
|
||||
#define __OS2__
|
||||
#endif
|
||||
#ifndef __OS2_32__
|
||||
#define __OS2_32__
|
||||
#endif
|
||||
#ifndef __32BIT__
|
||||
#define __32BIT__
|
||||
#endif
|
||||
|
||||
/* 32-bit QNX compile environment */
|
||||
#elif defined(__QNX__)
|
||||
#ifndef __32BIT__
|
||||
#define __32BIT__
|
||||
#endif
|
||||
#ifndef __UNIX__
|
||||
#define __UNIX__
|
||||
#endif
|
||||
|
||||
/* 32-bit Linux compile environment */
|
||||
#elif defined(__LINUX__) || defined(linux)
|
||||
#ifndef __LINUX__
|
||||
#define __LINUX__
|
||||
#endif
|
||||
#ifndef __32BIT__
|
||||
#define __32BIT__
|
||||
#endif
|
||||
#ifndef __UNIX__
|
||||
#define __UNIX__
|
||||
#endif
|
||||
|
||||
/* 32-bit FreeBSD compile environment */
|
||||
#elif defined(__FREEBSD__)
|
||||
#ifndef __32BIT__
|
||||
#define __32BIT__
|
||||
#endif
|
||||
#ifndef __UNIX__
|
||||
#define __UNIX__
|
||||
#endif
|
||||
|
||||
/* 32-bit BeOS compile environment */
|
||||
#elif defined(__BEOS__)
|
||||
#ifndef __32BIT__
|
||||
#define __32BIT__
|
||||
#endif
|
||||
#ifndef __UNIX__
|
||||
#define __UNIX__
|
||||
#endif
|
||||
#else
|
||||
#error This platform is not currently supported!
|
||||
#endif
|
||||
|
||||
/* Determine the CPU type that we are compiling for */
|
||||
|
||||
#if defined(__M_ALPHA) || defined(__ALPHA_) || defined(__ALPHA) || defined(__alpha)
|
||||
#ifndef __ALPHA__
|
||||
#define __ALPHA__
|
||||
#endif
|
||||
#elif defined(__M_PPC) || defined(__POWERC)
|
||||
#ifndef __PPC__
|
||||
#define __PPC__
|
||||
#endif
|
||||
#elif defined(__M_MRX000)
|
||||
#ifndef __MIPS__
|
||||
#define __MIPS__
|
||||
#endif
|
||||
#else
|
||||
#ifndef __INTEL__
|
||||
#define __INTEL__ /* Assume Intel if nothing found */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* We have the following defines to define the calling conventions for
|
||||
* publicly accesible functions:
|
||||
*
|
||||
* _PUBAPI - Compiler default calling conventions for all public 'C' functions
|
||||
* _ASMAPI - Calling conventions for all public assembler functions
|
||||
* _DLLAPI - Calling conventions for all DLL exported functions
|
||||
* _DLLVAR - Modifier to export/import globals in 32 bit DLL's
|
||||
* _EXPORT - Expands to _export when compiling a DLL
|
||||
* _VARAPI - Modifiers for variables; Watcom C++ mangles C++ globals
|
||||
*/
|
||||
|
||||
#if defined(_MSC_VER) && defined(_WIN32) && !defined(__SC__)
|
||||
#define __PASCAL __stdcall
|
||||
#define __export
|
||||
#define __import
|
||||
#else
|
||||
#define __PASCAL __pascal
|
||||
#endif
|
||||
|
||||
#ifdef __WATCOMC__
|
||||
#if (__WATCOMC__ >= 1050)
|
||||
#define _VARAPI __cdecl
|
||||
#else
|
||||
#define _VARAPI
|
||||
#endif
|
||||
#else
|
||||
#define _VARAPI
|
||||
#endif
|
||||
|
||||
#if defined(__IBMC__) || defined(__IBMCPP__)
|
||||
#define PTR_DECL_IN_FRONT
|
||||
#endif
|
||||
|
||||
#if defined(__WINDOWS__)
|
||||
#ifdef BUILD_DLL
|
||||
#define _DLLASM __export __cdecl
|
||||
#define _EXPORT __export
|
||||
#ifdef __WINDOWS32__
|
||||
#define _DLLAPI __export __PASCAL
|
||||
#define _DLLVAR __export
|
||||
#else
|
||||
#define _DLLAPI __export __far __pascal
|
||||
#define _DLLVAR
|
||||
#endif
|
||||
#else
|
||||
#define _DLLASM __cdecl
|
||||
#define _EXPORT
|
||||
#ifdef __WINDOWS32__
|
||||
#define _DLLAPI __PASCAL
|
||||
#define _DLLVAR __import
|
||||
#else
|
||||
#define _DLLAPI __far __pascal
|
||||
#define _DLLVAR
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#if !defined(__BEOS__)
|
||||
#define _EXPORT
|
||||
#endif
|
||||
#define _DLLAPI
|
||||
#define _DLLVAR
|
||||
#endif
|
||||
|
||||
/* Define the calling conventions for all public functions. For simplicity
|
||||
* we define all public functions as __cdecl calling conventions, so that
|
||||
* they are the same across all compilers and runtime DLL's.
|
||||
*/
|
||||
|
||||
#define _PUBAPI __cdecl
|
||||
#define _ASMAPI __cdecl
|
||||
|
||||
/* Determine the syntax for declaring a function pointer with a
|
||||
* calling conventions override. Most compilers require the calling
|
||||
* convention to be declared in front of the '*', but others require
|
||||
* it to be declared after the '*'. We handle both in here depending
|
||||
* on what the compiler requires.
|
||||
*/
|
||||
|
||||
#ifdef PTR_DECL_IN_FRONT
|
||||
#define _DLLAPIP * _DLLAPI
|
||||
#define _DLLASMP * _DLLASM
|
||||
#define _PUBAPIP * _PUBAPI
|
||||
#define _ASMAPIP * _ASMAPI
|
||||
#else
|
||||
#define _DLLAPIP _DLLAPI *
|
||||
#define _DLLASMP _DLLASM *
|
||||
#define _PUBAPIP _PUBAPI *
|
||||
#define _ASMAPIP _ASMAPI *
|
||||
#endif
|
||||
|
||||
/* Useful macros */
|
||||
|
||||
#define PRIVATE static
|
||||
#define PUBLIC
|
||||
|
||||
/* This HAS to be 0L for 16-bit real mode code to work!!! */
|
||||
|
||||
#ifndef NULL
|
||||
# define NULL 0L
|
||||
#endif
|
||||
|
||||
#ifndef MAX
|
||||
# define MAX(a,b) ( ((a) > (b)) ? (a) : (b))
|
||||
#endif
|
||||
#ifndef MIN
|
||||
# define MIN(a,b) ( ((a) < (b)) ? (a) : (b))
|
||||
#endif
|
||||
#ifndef ABS
|
||||
# define ABS(a) ((a) >= 0 ? (a) : -(a))
|
||||
#endif
|
||||
#ifndef SIGN
|
||||
# define SIGN(a) ((a) > 0 ? 1 : -1)
|
||||
#endif
|
||||
|
||||
/* General typedefs */
|
||||
|
||||
#ifndef __GENDEFS
|
||||
#define __GENDEFS
|
||||
#if defined(__BEOS__)
|
||||
#include <SupportDefs.h>
|
||||
#else
|
||||
#ifdef __LINUX__
|
||||
#include <sys/types.h>
|
||||
#ifdef __STRICT_ANSI__
|
||||
typedef unsigned short ushort;
|
||||
typedef unsigned long ulong;
|
||||
typedef unsigned int uint;
|
||||
#endif
|
||||
#else
|
||||
#if !(defined(__QNXNTO__) && defined(GENERAL_STRUCT))
|
||||
typedef unsigned short ushort;
|
||||
typedef unsigned long ulong;
|
||||
#endif
|
||||
typedef unsigned int uint;
|
||||
#endif
|
||||
typedef unsigned char uchar;
|
||||
#endif
|
||||
typedef int ibool; /* Integer boolean type */
|
||||
#ifdef USE_BOOL /* Only for older code */
|
||||
#ifndef __cplusplus
|
||||
#define bool ibool /* Standard C */
|
||||
#else
|
||||
#ifndef __HAS_BOOL__
|
||||
#define bool ibool /* Older C++ compilers */
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
#endif /* USE_BOOL */
|
||||
#endif /* __GENDEFS */
|
||||
|
||||
/* Boolean truth values */
|
||||
|
||||
#undef false
|
||||
#undef true
|
||||
#undef NO
|
||||
#undef YES
|
||||
#undef FALSE
|
||||
#undef TRUE
|
||||
#define false 0
|
||||
#define true 1
|
||||
#define NO 0
|
||||
#define YES 1
|
||||
#define FALSE 0
|
||||
#define TRUE 1
|
||||
|
||||
/* Inline debugger interrupts for Watcom C++ and Borland C++ */
|
||||
|
||||
#ifdef __WATCOMC__
|
||||
void DebugInt(void);
|
||||
#pragma aux DebugInt = \
|
||||
"int 3";
|
||||
void DebugVxD(void);
|
||||
#pragma aux DebugVxD = \
|
||||
"int 1";
|
||||
#elif defined(__BORLANDC__)
|
||||
#define DebugInt() __emit__(0xCC)
|
||||
#define DebugVxD() {__emit__(0xCD); __emit__(0x01);}
|
||||
#elif defined(_MSC_VER)
|
||||
#define DebugInt() _asm int 0x3
|
||||
#define DebugVxD() _asm int 0x1
|
||||
#else
|
||||
#define DebugInt()
|
||||
#define DebugVxD()
|
||||
#endif
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
* Set of debugging macros used by the libraries. If the debug flag is
|
||||
* set, they are turned on depending on the setting of the flag. User code
|
||||
* can override the default functions called when a check fails, and the
|
||||
* MGL does this so it can restore the system from graphics mode to display
|
||||
* an error message. These functions also log information to the
|
||||
* scitech.log file in the root directory of the hard drive when problems
|
||||
* show up.
|
||||
*
|
||||
* If you set the value of CHECKED to be 2, it will also enable code to
|
||||
* insert hard coded debugger interrupt into the source code at the line of
|
||||
* code where the check fail. This is useful if you run the code under a
|
||||
* debugger as it will break inside the debugger before exiting with a
|
||||
* failure condition.
|
||||
*
|
||||
* Also for code compiled to run under Windows, we also call the
|
||||
* OutputDebugString function to send the message to the system debugger
|
||||
* such as Soft-ICE or WDEB386. Hence if you get any non-fatal warnings you
|
||||
* will see those on the debugger terminal as well as in the log file.
|
||||
*-------------------------------------------------------------------------*/
|
||||
|
||||
extern void (*_CHK_fail)(int fatal,const char *msg,const char *cond,const char *file,int line);
|
||||
void _CHK_defaultFail(int fatal,const char *msg,const char *cond,const char *file,int line);
|
||||
|
||||
#ifdef CHECKED
|
||||
# define CHK(x) x
|
||||
#if CHECKED > 1
|
||||
# define CHECK(p) \
|
||||
((p) ? (void)0 : DebugInt(), \
|
||||
_CHK_fail(1,"Check failed: '%s', file %s, line %d\n", \
|
||||
#p, __FILE__, __LINE__))
|
||||
# define WARN(p) \
|
||||
((p) ? (void)0 : DebugInt(), \
|
||||
_CHK_fail(0,"Warning: '%s', file %s, line %d\n", \
|
||||
#p, __FILE__, __LINE__))
|
||||
#else
|
||||
# define CHECK(p) \
|
||||
((p) ? (void)0 : \
|
||||
_CHK_fail(1,"Check failed: '%s', file %s, line %d\n", \
|
||||
#p, __FILE__, __LINE__))
|
||||
# define WARN(p) \
|
||||
((p) ? (void)0 : \
|
||||
_CHK_fail(0,"Warning: '%s', file %s, line %d\n", \
|
||||
#p, __FILE__, __LINE__))
|
||||
#endif
|
||||
#else
|
||||
# define CHK(x)
|
||||
# define CHECK(p) ((void)0)
|
||||
# define WARN(p) ((void)0)
|
||||
#endif
|
||||
|
||||
#endif /* __SCITECH_H */
|
||||
121
utils/restorefont.c
Normal file
121
utils/restorefont.c
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <vga.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include "../src/libvga.h"
|
||||
|
||||
/*
|
||||
* Note: Observe that when writing the font to a file, the file to write is
|
||||
* opened after vga_init has been called (so that root permissions have been
|
||||
* given up). This means that there is no major security hole lurking here.
|
||||
*/
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
FILE *f;
|
||||
unsigned char *font;
|
||||
size_t font_size = FONT_SIZE; /* buffer size in 1.2.11 and before */
|
||||
int can_set = 0;
|
||||
struct stat statbuf;
|
||||
|
||||
if (argc == 1) {
|
||||
printf("Restore corrupted textmode font.\n");
|
||||
printf("Syntax: restorefont option filename\n");
|
||||
printf(" -r filename Restore VGA font from file.\n");
|
||||
printf(" -w filename Write current VGA font to file.\n");
|
||||
return 0;
|
||||
}
|
||||
if (argv[1][0] != '-') {
|
||||
printf("Must specify -r or -w.\n");
|
||||
return 1;
|
||||
}
|
||||
switch (argv[1][1]) {
|
||||
case 'r':
|
||||
case 'w':
|
||||
if (argc != 3) {
|
||||
printf("Must specify filename.\n");
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
printf("Invalid option. Must specify -r or -w.\n");
|
||||
return 1;
|
||||
}
|
||||
vga_disabledriverreport();
|
||||
vga_setchipset(VGA); /* avoid SVGA detection */
|
||||
vga_init();
|
||||
/* we are in TEXT mode. Check for availability of vga_ext_set: */
|
||||
if (vga_getmodeinfo(TEXT)->flags & HAVE_EXT_SET) {
|
||||
if (vga_ext_set(VGA_EXT_AVAILABLE, VGA_AVAIL_SET) &
|
||||
(1 << VGA_EXT_FONT_SIZE)) {
|
||||
can_set = 1;
|
||||
/* Query the preferred data size: */
|
||||
font_size = vga_ext_set(VGA_EXT_FONT_SIZE, 0);
|
||||
if (font_size < FONT_SIZE) {
|
||||
font_size = FONT_SIZE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* We never need more than that memory: */
|
||||
font = malloc((size_t)font_size);
|
||||
if (!font) {
|
||||
puts("restorefont: out of memory.");
|
||||
goto ex_no_errno;
|
||||
}
|
||||
|
||||
vga_setmode(G640x350x16);
|
||||
switch (argv[1][1]) {
|
||||
case 'r':
|
||||
f = fopen(argv[2], "rb");
|
||||
if (f == NULL) {
|
||||
error:
|
||||
perror("restorefont");
|
||||
ex_no_errno:
|
||||
vga_setmode(TEXT);
|
||||
return 1;
|
||||
}
|
||||
if (fstat(fileno(f), &statbuf))
|
||||
goto error;
|
||||
font_size = statbuf.st_size;
|
||||
/* Check for sensible sizes: */
|
||||
switch (font_size) {
|
||||
case 0x2000:
|
||||
case 0x2000 * 4:
|
||||
case 0x2000 * 8:
|
||||
if (can_set)
|
||||
vga_ext_set(VGA_EXT_FONT_SIZE, font_size);
|
||||
break;
|
||||
default:
|
||||
corrupt:
|
||||
puts("restorefont: input file corrupted.");
|
||||
goto ex_no_errno;
|
||||
}
|
||||
|
||||
if (1 != fread(font, font_size, 1, f)) {
|
||||
if (errno)
|
||||
goto error;
|
||||
goto corrupt;
|
||||
}
|
||||
fclose(f);
|
||||
vga_puttextfont(font);
|
||||
break;
|
||||
case 'w':
|
||||
/* save as much as we have.. */
|
||||
if (can_set)
|
||||
vga_ext_set(VGA_EXT_FONT_SIZE, font_size);
|
||||
vga_gettextfont(font);
|
||||
f = fopen(argv[2], "wb");
|
||||
if (f == NULL)
|
||||
goto error;
|
||||
if (1 != fwrite(font, font_size, 1, f))
|
||||
goto error;
|
||||
if (fclose(f))
|
||||
goto error;
|
||||
break;
|
||||
}
|
||||
vga_setmode(TEXT);
|
||||
return 0;
|
||||
}
|
||||
143
utils/restorepalette.c
Normal file
143
utils/restorepalette.c
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <vga.h>
|
||||
#include <errno.h>
|
||||
#include <string.h> /* strerror */
|
||||
#include "../src/libvga.h"
|
||||
|
||||
|
||||
/* default palette values */
|
||||
|
||||
static char default_red[256]
|
||||
=
|
||||
{0, 0, 0, 0, 42, 42, 42, 42, 21, 21, 21, 21, 63, 63, 63, 63,
|
||||
0, 5, 8, 11, 14, 17, 20, 24, 28, 32, 36, 40, 45, 50, 56, 63,
|
||||
0, 16, 31, 47, 63, 63, 63, 63, 63, 63, 63, 63, 63, 47, 31, 16,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 31, 39, 47, 55, 63, 63, 63, 63,
|
||||
63, 63, 63, 63, 63, 55, 47, 39, 31, 31, 31, 31, 31, 31, 31, 31,
|
||||
45, 49, 54, 58, 63, 63, 63, 63, 63, 63, 63, 63, 63, 58, 54, 49,
|
||||
45, 45, 45, 45, 45, 45, 45, 45, 0, 7, 14, 21, 28, 28, 28, 28,
|
||||
28, 28, 28, 28, 28, 21, 14, 7, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
14, 17, 21, 24, 28, 28, 28, 28, 28, 28, 28, 28, 28, 24, 21, 17,
|
||||
14, 14, 14, 14, 14, 14, 14, 14, 20, 22, 24, 26, 28, 28, 28, 28,
|
||||
28, 28, 28, 28, 28, 26, 24, 22, 20, 20, 20, 20, 20, 20, 20, 20,
|
||||
0, 4, 8, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 12, 8, 4,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 8, 10, 12, 14, 16, 16, 16, 16,
|
||||
16, 16, 16, 16, 16, 14, 12, 10, 8, 8, 8, 8, 8, 8, 8, 8,
|
||||
11, 12, 13, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 13, 12,
|
||||
11, 11, 11, 11, 11, 11, 11, 11, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
static char default_green[256]
|
||||
=
|
||||
{0, 0, 42, 42, 0, 0, 21, 42, 21, 21, 63, 63, 21, 21, 63, 63,
|
||||
0, 5, 8, 11, 14, 17, 20, 24, 28, 32, 36, 40, 45, 50, 56, 63,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 31, 47, 63, 63, 63, 63,
|
||||
63, 63, 63, 63, 63, 47, 31, 16, 31, 31, 31, 31, 31, 31, 31, 31,
|
||||
31, 39, 47, 55, 63, 63, 63, 63, 63, 63, 63, 63, 63, 55, 47, 39,
|
||||
45, 45, 45, 45, 45, 45, 45, 45, 45, 49, 54, 58, 63, 63, 63, 63,
|
||||
63, 63, 63, 63, 63, 58, 54, 49, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 7, 14, 21, 29, 28, 28, 28, 28, 28, 28, 28, 28, 21, 14, 7,
|
||||
14, 14, 14, 14, 14, 14, 14, 14, 14, 17, 21, 24, 28, 28, 28, 28,
|
||||
28, 28, 28, 28, 28, 24, 21, 17, 20, 20, 20, 20, 20, 20, 20, 20,
|
||||
20, 22, 24, 26, 28, 28, 28, 28, 28, 28, 28, 28, 28, 26, 24, 22,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 8, 12, 16, 16, 16, 16,
|
||||
16, 16, 16, 16, 16, 12, 8, 4, 8, 8, 8, 8, 8, 8, 8, 8,
|
||||
8, 10, 12, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 12, 10,
|
||||
11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 13, 15, 16, 16, 16, 16,
|
||||
16, 16, 16, 16, 16, 15, 13, 12, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
static char default_blue[256]
|
||||
=
|
||||
{0, 42, 0, 42, 0, 42, 0, 42, 21, 63, 21, 63, 21, 63, 21, 63,
|
||||
0, 5, 8, 11, 14, 17, 20, 24, 28, 32, 36, 40, 45, 50, 56, 63,
|
||||
63, 63, 63, 63, 63, 47, 31, 16, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 16, 31, 47, 63, 63, 63, 63, 63, 63, 63, 63, 63, 55, 47, 39,
|
||||
31, 31, 31, 31, 31, 31, 31, 31, 31, 39, 47, 55, 63, 63, 63, 63,
|
||||
63, 63, 63, 63, 63, 58, 54, 49, 45, 45, 45, 45, 45, 45, 45, 45,
|
||||
45, 49, 54, 58, 63, 63, 63, 63, 28, 28, 28, 28, 28, 21, 14, 7,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 14, 21, 28, 28, 28, 28,
|
||||
28, 28, 28, 28, 28, 24, 21, 17, 14, 14, 14, 14, 14, 14, 14, 14,
|
||||
14, 17, 21, 24, 28, 28, 28, 28, 28, 28, 28, 28, 28, 26, 24, 22,
|
||||
20, 20, 20, 20, 20, 20, 20, 20, 20, 22, 24, 26, 28, 28, 28, 28,
|
||||
16, 16, 16, 16, 16, 12, 8, 4, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 4, 8, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 12, 10,
|
||||
8, 8, 8, 8, 8, 8, 8, 8, 8, 10, 12, 14, 16, 16, 16, 16,
|
||||
16, 16, 16, 16, 16, 15, 13, 12, 11, 11, 11, 11, 11, 11, 11, 11,
|
||||
11, 12, 13, 15, 16, 16, 16, 16, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
|
||||
void
|
||||
delay (void)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < 10; i++);
|
||||
}
|
||||
|
||||
/* Modifications to restorepalette to allow custom palette setting from a file.
|
||||
* The format of the file is simply a table of color number -> color mappings:
|
||||
* <color(0-255)> <red(0-63)> <green(0-63)> <blue(0-63)> <rest of line ignored>
|
||||
* By Charles Blake, chuckb@alice.wonderland.caltech.edu
|
||||
*/
|
||||
|
||||
void
|
||||
process_palette_file (char **argv)
|
||||
{
|
||||
int i, n, r, g, b;
|
||||
FILE *palette_file;
|
||||
|
||||
if ((palette_file = fopen (argv[1], "r")) == NULL)
|
||||
{
|
||||
fprintf (stderr, "%s opening %s: %s\n", argv[0], argv[1], strerror (errno));
|
||||
exit (1);
|
||||
}
|
||||
/*
|
||||
* NOTE:The tricky %*[^\n] conversion specifier allows arbitrary text following
|
||||
* any line with a valid entry on it. This is a simple comment syntax device.
|
||||
*/
|
||||
for (n = 1; fscanf (palette_file, "%d %d %d %d %*[^\n]", &i, &r, &g, &b) == 4; n++)
|
||||
{
|
||||
default_red[i] = r; /* deferred assignment prevents partial */
|
||||
default_green[i] = g; /* assignment in case of in-line errors */
|
||||
default_blue[i] = b;
|
||||
}
|
||||
if (!feof (palette_file))
|
||||
{
|
||||
fprintf (stderr, "%s parse error: %s: line %d\n", argv[0], argv[1], n);
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
|
||||
vga_init ();
|
||||
if (argc > 1)
|
||||
process_palette_file (argv);
|
||||
|
||||
if (vga_getcurrentchipset () != EGA)
|
||||
{
|
||||
/* Restore textmode/16-color mode palette */
|
||||
if (vga_getcurrentchipset() != FBDEV)
|
||||
for (i = 0; i < 16; i++)
|
||||
{
|
||||
port_in (IS1_RC);
|
||||
delay ();
|
||||
port_out (i, ATT_IW); /* set palette color number */
|
||||
delay ();
|
||||
port_out (i, ATT_IW); /* set palette color value */
|
||||
delay ();
|
||||
}
|
||||
|
||||
/* Restore 256-color VGA RGB look-up table */
|
||||
for (i = 0; i < 256; i++)
|
||||
vga_setpalette (i, default_red[i], default_green[i],
|
||||
default_blue[i]);
|
||||
|
||||
if (vga_getcurrentchipset() != FBDEV) {
|
||||
port_in (IS1_RC);
|
||||
delay ();
|
||||
port_out (0x20, ATT_IW); /* enable display */
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
90
utils/restoretextmode.c
Normal file
90
utils/restoretextmode.c
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <vga.h>
|
||||
#include "../src/driver.h"
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
/*
|
||||
* Note: Observe that when writing the font to a file, the file to write is
|
||||
* opened after vga_init has been called (so that root permissions have been
|
||||
* given up). This means that there is no major security hole lurking here.
|
||||
*/
|
||||
|
||||
unsigned char regs[MAX_REGS];
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
vga_init ();
|
||||
if (argc == 1)
|
||||
{
|
||||
printf ("Save/restore textmode registers.\n");
|
||||
printf ("Syntax: restoretextmode option filename\n");
|
||||
printf (" -r filename Restore registers from file.\n");
|
||||
printf (" -w filename Write registers to file.\n");
|
||||
return 0;
|
||||
}
|
||||
if (argv[1][0] != '-')
|
||||
{
|
||||
printf ("Must specify -r or -w.\n");
|
||||
return 1;
|
||||
}
|
||||
switch (argv[1][1])
|
||||
{
|
||||
case 'r':
|
||||
case 'w':
|
||||
if (argc != 3)
|
||||
{
|
||||
printf ("Must specify filename.\n");
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
printf ("Invalid option. Must specify -r or -w.\n");
|
||||
return 1;
|
||||
}
|
||||
if (argv[1][1] == 'r')
|
||||
{
|
||||
FILE *f;
|
||||
f = fopen (argv[2], "rb");
|
||||
if (f == NULL)
|
||||
{
|
||||
error:
|
||||
perror ("restoretextmode");
|
||||
return 1;
|
||||
}
|
||||
if (1 != fread (regs, MAX_REGS, 1, f))
|
||||
{
|
||||
if (errno)
|
||||
goto error;
|
||||
puts ("restoretextmode: input file corrupted.");
|
||||
return 1;
|
||||
}
|
||||
fclose (f);
|
||||
}
|
||||
vga_setmode (G640x350x16);
|
||||
switch (argv[1][1])
|
||||
{
|
||||
case 'r':
|
||||
vga_settextmoderegs (regs);
|
||||
break;
|
||||
case 'w':
|
||||
vga_gettextmoderegs (regs);
|
||||
break;
|
||||
}
|
||||
vga_setmode (TEXT);
|
||||
if (argv[1][1] == 'w')
|
||||
{
|
||||
FILE *f;
|
||||
f = fopen (argv[2], "wb");
|
||||
if (f == NULL)
|
||||
goto error;
|
||||
if (1 != fwrite (regs, MAX_REGS, 1, f))
|
||||
goto error;
|
||||
if (fclose (f))
|
||||
goto error;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
12
utils/runx
Executable file
12
utils/runx
Executable file
|
|
@ -0,0 +1,12 @@
|
|||
#!/bin/sh
|
||||
# Script to save VGA textmode font, run X, and restore VGA textmode font.
|
||||
|
||||
# A more rigorous alternative is to run the 'savetextmode' script before
|
||||
# running X, and 'textmode' after. This will restore the textmode registers
|
||||
# and the VGA palette in addition to the VGA font.
|
||||
|
||||
echo Saving font in /tmp/fontdata
|
||||
restorefont -w /tmp/fontdata
|
||||
startx
|
||||
echo Restoring font from /tmp/fontdata
|
||||
restorefont -r /tmp/fontdata
|
||||
4
utils/savetextmode
Executable file
4
utils/savetextmode
Executable file
|
|
@ -0,0 +1,4 @@
|
|||
#!/bin/sh
|
||||
rm -f /etc/vga/textregs /etc/vga/fontdata
|
||||
restoretextmode -w /etc/vga/textregs
|
||||
restorefont -w /etc/vga/fontdata
|
||||
89
utils/setmclk.c
Normal file
89
utils/setmclk.c
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
Note: Previously this program did not unlock the extended registers,
|
||||
so it only worked if the registers happened to be unlocked.
|
||||
|
||||
This program sets the 'memory clock' of Cirrus 5424/26/28 cards.
|
||||
The first three values could be set by utility programs that
|
||||
came with my card (AVGA3), but somewhat higher values seem to work (on my
|
||||
card at least). It may be that better and more recent Cirrus cards use a
|
||||
higher value as boot-up default. It should depend on DRAM speed, but it
|
||||
seems to be more dependant on the card logic.
|
||||
|
||||
I have the impression that many Cirrus 542x cards suffer from horrible
|
||||
BIOS version/DRAM timing misconfigurations. Perhaps even some versions of
|
||||
MS-Windows drivers change the MCLK register. In any case, the boot-up BIOS
|
||||
default (0x1c) may be inappropriately low for the type of DRAM timing most
|
||||
cards use.
|
||||
|
||||
Using a higher memory clock gives a very significant performance improvement;
|
||||
with high dot clock modes (like 640x480x16M or 1150x900x256) performance can
|
||||
be more than twice that of the standard 50 MHz clock. This goes for both
|
||||
(VLB) framebuffer access and accelerated features (bitblt). This also helps
|
||||
XFree86 server performance, but only if the XFree86 Cirrus driver doesn't
|
||||
set the memory clock register (it should work for XFree86 1.3 and 2.0).
|
||||
Use at your own risk!
|
||||
|
||||
Note that the 'dot clock' is something entirely different. There does not
|
||||
seem to be much correlation between the two (i.e. if a high dot clock gives
|
||||
screen problems, using a high memory clock is not likely to fix it, other
|
||||
than improving speed).
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#define NEW_MCLK 0x1C /* Default value */
|
||||
/* #define NEW_MCLK 0x26 *//* High value to test XFree86 */
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <vga.h>
|
||||
#include <sys/io.h> /* For port I/O macros. */
|
||||
#define OUTB(a,d) outb(d,a)
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
vga_init ();
|
||||
if (vga_getcurrentchipset () != CIRRUS)
|
||||
{
|
||||
printf ("Not a Cirrus.\n");
|
||||
printf ("Continue anyway (y/n)?\n");
|
||||
if (getchar () != 'y')
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Unlock extended registers. */
|
||||
OUTB (0x3c4, 0x06);
|
||||
OUTB (0x3c5, 0x12);
|
||||
|
||||
|
||||
/*
|
||||
Tested on VLB AVGA3 CL-GD5426 on 40MHz VLB
|
||||
0x1c 50 MHz (boot-up default)
|
||||
0x21 59
|
||||
0x22 62
|
||||
0x23 OK
|
||||
0x24 OK
|
||||
0x25 OK
|
||||
0x26 OK [This corresponds to the highest value
|
||||
mentioned in the databook (which does
|
||||
not mean that it is supposed to work
|
||||
on all cards); the book also says the
|
||||
parts are not specified for more than
|
||||
50 MHz].
|
||||
0x27 occasional loose pixels
|
||||
0x28 occasional problems
|
||||
0x29 some problems
|
||||
0x2A 16M/textmode problems
|
||||
0x2c 256/32k color problems
|
||||
*/
|
||||
OUTB (0x3c4, 0x1f);
|
||||
printf ("Old MCLK value: %02x\n", inb (0x3c5));
|
||||
OUTB (0x3c4, 0x1f);
|
||||
OUTB (0x3c5, NEW_MCLK);
|
||||
printf ("New MCLK value: %02x\n", NEW_MCLK);
|
||||
|
||||
return 0;
|
||||
}
|
||||
98
utils/svgakeymap
Executable file
98
utils/svgakeymap
Executable file
|
|
@ -0,0 +1,98 @@
|
|||
#!/usr/bin/perl
|
||||
#
|
||||
# svgakeymap - by Brion Vibber (brion@pobox.com), 6/30 - 7/3/1998
|
||||
# Generates a keymap conversion file for svgalib from two keytable definitions.
|
||||
#
|
||||
# Usage:
|
||||
# svgakeymap [physical_map [program_map]] > output.keymap
|
||||
#
|
||||
# The conversion map is output to stdout; you may wish to redirect it.
|
||||
# Keymaps are searched for in /usr/lib/kbd/keytables and are automatically
|
||||
# filtered through gzip if necessary.
|
||||
#
|
||||
# Read the file README.keymap from the svgalib distribution for more info.
|
||||
|
||||
$ktd = "/usr/lib/kbd/keytables/";
|
||||
if(scalar(@ARGV) > 0) {
|
||||
$inmap = $ARGV[0];
|
||||
} else {
|
||||
$inmap = "us";
|
||||
}
|
||||
if(scalar(@ARGV) > 1) {
|
||||
$outmap = $ARGV[1];
|
||||
} else {
|
||||
$outmap = $inmap;
|
||||
}
|
||||
|
||||
|
||||
foreach $bob ($inmap, $outmap) {
|
||||
#print "$bob\n";
|
||||
unless(-e $bob) {
|
||||
# Tack the keytable dir on it
|
||||
$bob = $ktd . $bob;
|
||||
#print "$bob\n";
|
||||
|
||||
unless(-e $bob) {
|
||||
# Tack a .gz on it
|
||||
$bob .= ".map";
|
||||
#print "$bob\n";
|
||||
|
||||
unless(-e $bob) {
|
||||
# Tack a .gz on it
|
||||
$bob .= ".gz";
|
||||
#print "$bob\n";
|
||||
|
||||
unless(-e $bob) {
|
||||
die "Couldn't find $bob\n.";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($inmap =~ m/\.gz$/) {
|
||||
# Filter thru gzip
|
||||
open INMAP, "gzip -dc $inmap |" or die "Could not open $inmap!\n";
|
||||
} else {
|
||||
open INMAP, "<$inmap" or die "Could not open $inmap!\n";
|
||||
}
|
||||
|
||||
if($outmap =~ m/\.gz$/) {
|
||||
# Filter thru gzip
|
||||
open OUTMAP, "gzip -dc $outmap |" or die "Could not open $outmap!\n";
|
||||
} else {
|
||||
open OUTMAP, "<$outmap" or die "Could not open $outmap!\n";
|
||||
}
|
||||
|
||||
print "# This is a svgalib scancode conversion map generated by svgakeymap.\n",
|
||||
"# Read the file README.keymap from the svgalib distribution for more info.\n#\n",
|
||||
"# Physical keyboard layout: $inmap\n",
|
||||
"# Program's expected keyboard layout: $outmap\n#\n",
|
||||
"# physical_scancode program_scancode key_name\n";
|
||||
|
||||
|
||||
while($kc = <OUTMAP>) {
|
||||
if($kc =~ m/^keycode\s+([0-9]+)\s*\=\s*(\S+)/) {
|
||||
# Store scancodes and names for future reference
|
||||
#print stderr "- $1 - $2 -\n";
|
||||
$keys{$1} = $2;
|
||||
$keys{$2} = $1;
|
||||
} else {
|
||||
# We ignore anything else - including modifiers
|
||||
}
|
||||
}
|
||||
|
||||
while($kc = <INMAP>) {
|
||||
if($kc =~ m/^keycode\s+([0-9]+)\s*\=\s*(\S+)/) {
|
||||
if($keys{$2}) {
|
||||
# Matching scancodes!
|
||||
#unless($keys{$1} eq $2) {
|
||||
# Find the other code with the same key...
|
||||
#print "$1 $keys{$2}\t# $keys{$1} <-> $2\n";
|
||||
#print "$1 $keys{$2}\t# $2\n";
|
||||
print "$1 $keys{$2} $2\n";
|
||||
#}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
4
utils/textmode
Executable file
4
utils/textmode
Executable file
|
|
@ -0,0 +1,4 @@
|
|||
#!/bin/sh
|
||||
restoretextmode -r /etc/vga/textregs
|
||||
restorefont -r /etc/vga/fontdata
|
||||
restorepalette
|
||||
Loading…
Add table
Add a link
Reference in a new issue