Category : Printer + Display Graphics
Archive   : TSENGVGA.ZIP
Filename : SAMPLE.C

 
Output of file : SAMPLE.C contained in archive : TSENGVGA.ZIP
/* ********************************************************************** */
/* Sample VGA test programs. (sample.c) */
/* This file contains sample program "fragments" to show how to do bank */
/* selecting when in hi-res graphics modes. */
/* */
/* This program has been compiled by both turboc and Microsoft C using */
/* small memory model. To compile this program, type TCC sample.c at the */
/* DOS prompt for Turboc, or type cl sample.c at the DOS prompt if using */
/* Microsoft C. NOTE: This has been compiled (without errors) on both */
/* microsoft C (ver 5.1) and turboc (ver 2.0). */
/* */
/* The purpose of this program is to aid the programmer (you) in building*/
/* application programs. This code has not been optimized, and, as you */
/* clone this code into your own programs, you will probably find better */
/* ways of coding some of the functions below. We hope this program is a */
/* help to you in your programming efforts. */
/* */
/* Non-copyright (NC), Definicon Corp, 1990. No rights reserved. */
/* This program is free to all programmers everywhere so that thier */
/* burden in life might be a little lighter. Feel free to copy, change, */
/* clone, fold, staple or mutulate this program in any way desired to */
/* suit your programming needs. -The Definicon Programming Staff. */
/* ********************************************************************** */

#include
#include
#define VIDEO 0x10 /* video INT 10 bios call */
#define VGARAM 0xa0000000 /* memory addr. of vga/ega video ram */
/*
dip switch info. When the Tseng board is plugged into the system,
the 4 dip switches are numbered from BOTTOM to TOP, as 1,2,3,4
(4 at the top, 1 at the bottom). The decoding is done through these
tables.
*/
#define OFF 0 /* switch is off */
#define ON 1 /* switch is on */
/* NOTE: Switches are mapped as SW1, SW4, SW3, SW2 */
int sw_map[] = {0, 3, 2, 1}; /* register index to switch mapping */

/* ******************************* */
/* Sample bank select program */
/* ******************************* */
main()
{
int rbank, wbank, banks; /* selected memory bank */
int i, j;
unsigned int bcnt; /* byte count */
char far *vidptr; /* video memory pointer */

/*
read and display the dip switch settings for the VGA card
*/
clr_home(); /* be sure the screen is cleared */
i = get_dip_sw(); /* get current dip switch settings */
decode_sw (i); /* print switch info */
/*
get size of memory and write into each of the 64k banks (256 color mode)
*/
set_mode (0x2d); /* select a 256 color mode for get_ram_size() */
banks = get_ram_size(); /* find out how much memory present */

printf("\n\nThere are %d 64k memory banks on the video board (%dk)",
banks, banks * 64);
printf("\n\nPress any key when ready for write test"); getch();

set_mode (0x30); /* 1024 x 768 x 256 colors */
for (i = 0; i < banks; i++)
{
select_bank (i, i); /* set write/read mem. bank */
vidptr = (char far *) VGARAM; /* point to video ram */
bcnt = 65535; /* initalize bytes to write */

while (bcnt-- > 0) /* fill a 64k bank with data */
*vidptr++ = i; /* pointers are faster than array references */

printf("\nBank %d written", i);
}
/*
sample of how to copy data from one bank into another bank
this is done when "scrolling" windows across a memory bank boundry)
*/
printf("\n\nPress any key when ready for bank to bank copy");
getch();

rbank = 1;
wbank = 0; /* setup to copy from one bank to another */
for (i = 0; i < banks; i++)
{
select_bank (rbank, wbank); /* set up for bank to bank copy */
vidptr = (char far *) VGARAM; /* set up mem. pointer */
bcnt = 65535; /* set up byte count */
while (bcnt-- > 0) /* copy an entire 64k bank */
{
*vidptr = *vidptr; /* get a byte from read bank, store in write bank */
vidptr++; /* bump the buffer pointer */
}
pos_cursor (50, i+2);
printf("Bank %d-%d copied", rbank, wbank);
rbank++;
wbank++; /* bump the bank counters */
}
printf("\nDone. Press any key to return to normal color mode");
getch();
set_mode (3); /* mode 3 is default */
}
/* ******************************************************* */
/* This will read the dip switch settings on the VGA */
/* board. The switches are numbered as SW1 to SW4 with */
/* sw1 on the bottom (when the board is plugged in), and */
/* sw4 on the top (near the 15pin connector). */
/* */
/* calling sequence: */
/* i = get_dip_sw(); */
/* */
/* on return, the switch settings will be in the lower */
/* 4 bits of i, with sw1 as bit 0, and sw4 as bit3. */
/* A bit that is on defines a switch that is on. a bit */
/* that is off is a switch that is off (This function */
/* reverses the values actually read, which are inverted) */
/* ******************************************************* */
get_dip_sw()
{
int clk_reg; /* current contents of clock reg. */
int i, j;
int retval, mask; /* used to build up output byte */
/*
select each of the four switch positions, and read it's state
*/
clk_reg = inp (0x3cc); /* get current value (must put this back) */
mask = 1; /* set up mask byte */
retval = 0x0f; /* init return value for "all switches on" */

for (i = 0; i < 4; i++) /* get the 4 switch positions */
{
j = (clk_reg & 0xf3); /* mask out old bits select bits */
j |= (sw_map[i] << 2); /* "or" in new bits */
outp (0x3c2, j); /* select next switch */
j = inp (0x3c2);

if (j & 0x10)
retval ^= mask; /* "turn off" the bit for this switch */

mask <<= 1; /* "shift" mask bit left for next switch */
}
outp (0x3c2, clk_reg); /* put back the clock value */
return (retval); /* return switch info to caller */
}
/* **************************************************** */
/* This is used to get switch no info (SW1, SW2, etc) */
/* from the value read from the dip switch registers. */
/* **************************************************** */
decode_sw (sw_val)
int sw_val; /* switch value read from "get_dip_sw()" */
{
int mask;
int i; /* scratch pad use */

mask = 1;
printf("\n The VGA dip switch settings are:\n\n");

for (i = 0; i < 4; i++)
{
printf("\nSwitch %d is ", i+1);

if (mask & sw_val) /* if the bit is set */
printf("on"); /* then the switch is on */
else
printf("off");

mask <<= 1;
}
printf("\n\nPress any key to continue "); getch();
return (0);
}
/* ************************************************************ */
/* Determine Vram size. */
/* This will determine the amount of video RAM present on the */
/* graphics board, and return that amount back to the caller */
/* as the number of 64k banks of memory. Typically, the return */
/* value will be either 4 (256k) 8 (512k) or 16 (1MB of ram). */
/* return values other than these three indicates a possible */
/* error in the video board or in the vram chips. */
/* */
/* NOTE: This function only works in a 256 color graphics mode.*/
/* be sure to call set_mode() with a 256 color mode */
/* (mode x'30' for example) before calling this function */
/* ************************************************************ */
get_ram_size()
{
int bank;
int i; /* # of 64k banks on the card */
int memerr;
char far *vidptr; /* points to video ram */

memerr = 0; /* assume no errors at first */
for (bank = 0; bank < 16; bank++) /* max of 16 banks for 1MB video ram */
{
select_bank (bank, bank); /* select a 64k bank to test */
vidptr = (char far *) VGARAM; /* point to video memory */

for (i = 0; i < 40; i++) /* only test a few locations to see if mem. present */
{
*vidptr = 0x55; /* write test data */
if (*vidptr != 0x55)
{
memerr = 1; /* set memory error flag */
break; /* quit if memory error (or no memory) */
}
vidptr += 4;
}
if (memerr)
break; /* quit if memory error found */
}
if (bank == 0)
bank = 1; /* probably have a mem. error - there must be > 1 bank! */

return (bank); /* return # of 64k banks to caller */
}
/* ********************************************************** */
/* Set video mode. */
/* This is used to select the various video modes. */
/* ********************************************************** */
set_mode (mode)
int mode;
{
union REGS inregs, outregs;

inregs.h.ah = 0; /* set up the new video mode */
inregs.h.al = mode; /* video mode */
int86( 0x10, &inregs, &outregs); /* let the bios do it !!! */

return (0);
}
/* *********************************************************** */
/* Select memory bank. */
/* In graphics mode, memory is arranged as N 64k banks of */
/* video ram. In graphics mode, all these banks are referenced*/
/* from memory location a000:0. */
/* This function will select one of those banks for writing */
/* and reading. Note that the write bank and read bank can */
/* be different, so that memory could be copied from one bank */
/* into a different bank (as in scrolling operations). */
/* *********************************************************** */
select_bank (readbank, writebank)
int readbank; /* 64k video ram bank for read operations */
int writebank; /* 64k video ram bank for write operations */
{
readbank <<= 4; /* shift read bank bits into position */
readbank |= writebank; /* "or" in the write bank bits */
outp (0x3cd, readbank); /* send to video controller chip */

return (0); /* there is nothing to return, so return a null */
}
/* *********************************************************** */
/* Position cursor. */
/* This is used to position the cursor on the screen at any */
/* x/y position. */
/* *********************************************************** */
pos_cursor (xpos, ypos)
int xpos; /* desired x position */
int ypos; /* desired y position */
{
union REGS inregs, outregs;

inregs.h.ah = 2; /* set cursor posistion */
inregs.h.al = 0;
inregs.h.bh = 0; /* default to page 0 */
inregs.x.cx = 0; /* not used, but set to 0 anyway */
inregs.h.dl = xpos; /* set desired column (x) pos. */
inregs.h.dh = ypos; /* set desired row (Y) pos. */
int86 (VIDEO, &inregs, &outregs);
return (0);
}
/* **************************************************** */
/* clear-home */
/* This used the bios (in character mode) to clear the */
/* screen. This will also work in graphics mode, but */
/* is very slow. */
/* **************************************************** */
clr_home()
{
union REGS inregs, outregs;

inregs.h.ah = 2;
inregs.h.bh = 0;
inregs.x.dx = 0;
int86 (VIDEO, &inregs, &inregs); /* home the cursor */

inregs.h.ah = 9;
inregs.h.al = ' ';
inregs.h.bl = 7; /* attribute char */
inregs.x.cx = 2000; /* write 2000 blanks */
int86 (VIDEO, &inregs, &inregs);

return(0);
}



  3 Responses to “Category : Printer + Display Graphics
Archive   : TSENGVGA.ZIP
Filename : SAMPLE.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/