TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: Owen Kaluza
from: Ian Binnie
date: 1996-01-21 04:01:10
subject: Writing a pixel in VGA 640x480x16 m

-=> Quoting Owen Kaluza to All <=-

 OK> Can anyone tell me how to write a pixel directly to the video memory
 OK> in VGA 640x480x16 mode, i know how to do it in 320x200x256 but

Assuming you have set the card into the correct mode (0x12) you can
write a pixel using INT 0x10, function 0x0c - see VGA/EGA BIOS for
details.

Few programs do this (as it is too slow); the following is an example of
a direct screen write. (This may require some work to compile, as it
uses the HITECH compler's ability to output direct to a port but you
will get the idea; you could use outp).

A good explanation of the 16 colour mode (which is complex) is "PC
System Programming" published by Abacus. Briefly each bit needs to be
put into a seperate memory plane of 64k; planes are switched by
outputting to a control register.

/*
    OUTPT16.C -- low level interface to IBM PC 16 colour graphics screen.
    Single pixel routine for EGA 16 colour.

    Written in HITECH 'C' by Paul de Leeuw 20/05/92.
*/

volatile static port unsigned int  GRAPHW     {at} 0x3ce;	/* graphics cont reg */
volatile static port unsigned char GRAPHBLO   {at} 0x3ce;	/* ditto low byte */
volatile static port unsigned char GRAPHBHI   {at} 0x3cf;	/* ditto hi byte */

#define	graph_out(index)	{GRAPHW = index;}
#define	EGA_ADDRESS	0xa0000000		/* EGA */
#define	FARWORDPTR	(far unsigned int *)
#define	FARBYTEPTR	(far unsigned char *)

typedef unsigned char	BYTE;
typedef unsigned	WORD;
typedef unsigned long	DWORD;

extern far void	*mem_address;

/**************************************************************************
	Plot a single point on graphics card
**************************************************************************/

void	fastdot16(const WORD x, const WORD y, const DWORD colour)

{
calc_ega_address(x, y);
graph_out(0x0003)			/* function 3 normal mode */
graph_out(0x08 + (0x8000 >> (x % 8)));	/* setup bit mask reg */
graph_out(((WORD) (colour & 0xff)) << 8);	/* colour to set/reset reg */
graph_out(0x0f01);				/* enable set/reset reg */
*(FARBYTEPTR mem_address) |= 1;		/* memory write */
}

/*
    EGA_ADDR.C -- low level interface to IBM PC 16 colour graphics screen.
    Calculate the memory address of current point on screen.
*/

extern DWORD	vga_address;
extern far BYTE	*mem_address;
extern WORD 	xdots, ydots;		/* absolute screen size */

/**************************************************************************
	Calculate VGA / EGA address
**************************************************************************/

void	calc_ega_address(unsigned x, unsigned y)

{
vga_address = ((DWORD) y * (DWORD) xdots + x) >> 3;
mem_address = (far BYTE *) (EGA_ADDRESS | (WORD) vga_address);
}

--- Blue Wave/Max v2.20
* Origin: Sydney PC Users Group Mail Exchange (3:712/505)
SEEN-BY: 50/99 620/243 623/630 711/401 409 410 413 430 510 808 809 932 934
SEEN-BY: 712/311 407 411 416 505 506 515 517 535 616 617 704 816 820 713/306
SEEN-BY: 713/888 714/906 800/1 7877/2809
@PATH: 712/505 517 515 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.