Article View: att.lang.c++
Article #200Re: Putpixel
From: Karl Martens
Date: Sun, 21 Jun 1998 00:00
Date: Sun, 21 Jun 1998 00:00
88 lines
3163 bytes
3163 bytes
Morten Kruse wrote in message <6mbp2r$d27$1@news.cybercity.dk>...
>I have some problems With my function putpixel in c++.
>
>I have implemented the putpixel function using the function memset.
>
>void putpixel(int x, int y, unsigned char col)
>{
> memset(vga+x(y*320),col);
>};
>
>Now I don't know how to implement the const vga to point at the mem adr.
>0XA000.
The prototype for the memset function is as follows,
void *memset( void *dest, int c, size_t count );
Parameters
dest Pointer to destination
c Character to set
count Number of characters
Remarks
The memset function sets the first count bytes of dest to the
character c.
The problem with your code is that your forgeting that a pointer is a 32bit
value. The base memory location your trying to access is 0xA000:0x0000 or
0xA0000000. Try...
// This function is limited to work in DOS and on an INTEL machine, it
// is my experience that windows and other OSes handle video in a
// very different manner. Furhter more this function is limited to modes
// with a 320 pixel width and a color scheme limited to one byte per
// pixel.
int putlpixel (int x, int y, char color)
{
// declare and inialize variables
void * vga = 0xA0000000; // make the variable vga equal to the
// video memory base
address.
unsigned int offset = 0;
offset = y * 320 + x; // procedure only valid in VGA mode
vga = vga + offset;
memset (vga, color, 1); // the one tells the function that you only
// want to replace one byte at
that memory
// location
return (0);
}
If you want to give assembly a try this should work as well on a 386 and
up....
// same limitations as above procedure...
int putpixel (int x, int y, char color)
{
asm
{
mov es,0xA000 // initialize segment word...
// begin calculations for offset word...
mov ax,y
mov bx,ax
shl ax,8 // these next three lines same as * 320
shl bx,6
add ax,bx
add ax,x // add in the x value
mov di,ax
// perform actual copy...
mov al, color
mov es:[di], al
}
return (0);
}
I've never actually used the first example but base on the prototype of the
procedure you wanted to use it should work. The only problem might come in
assigning a value to a pointer... I'm not sure on C++ or C's rules on that.
The second will work, as I have used it a lot ever since the 386 was
arround. Remember you must first set the video mode to 0x13 or it will not
work....
Technical Details
Message-ID:
<6mi8l0$7q1@priv-sys04-le0.telusplanet.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<6mbp2r$d27$1@news.cybercity.dk>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10d4ba,3f64e003c7efdf28 X-Google-Attributes: gid10d4ba,public From: "Karl Martens" <martensk@telusplanet.net> Subject: Re: Putpixel Date: 1998/06/21 Message-ID: <6mi8l0$7q1@priv-sys04-le0.telusplanet.net> X-Deja-AN: 364649900 References: <6mbp2r$d27$1@news.cybercity.dk> X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4 Organization: TELUS Communications Inc. Newsgroups: att.lang.c++