Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SVGA - how to read pixel color?? ATI adapter

Status
Not open for further replies.

GuyZana

Programmer
Jan 14, 2002
11
IL
i'm doing a software (17,000 lines untill now) that works in SVGA 800x600 256 colors mode (using banks) and i need to save the background and than drawing it back again, i made the algorithem for saving the background (if you want it notify me) anyway, my problem is this:

i need to read a pixel color from the screen at specified coord (x,y) to do so i build this function (2 ways):

(1)
int get_pixel(int x, int y)
/* Function reads a pixel from the screen *
* from coordinates x,y (the offset) *
* and returning the pixel color */
{
int color;
int bits_per_pixel = 8; // 2^8 = 256 colors
long offset = ((long)y*SCREEN_WIDTH+(long)x)*(bits_per_pixel>>3);
setbank(offset>>16);
color=(*(video_buffer+offset))*(bits_per_pixel>>3);
return(color);
}


(2)
int get_pixel(int x, int y)
{
asm {
mov ah, 0dh
mov bh, 0
mov cx, x
mov dx, y
int 10h
}

return(_AL);
}


in both ways the function works but only at non-ati adapters, if i'm calling the function at a computer that has an ati adapter i'm getting colors only from the first segment at screen.

i have checked these function at home (i've got voodoo) and it works.

if you know other ways to read a pixel color please tell me or if you have any suggestion for how to solve this problem please replay.

thanks from advanced,
Guy Zana
 
Do you use a graphics driver?
If not then you can only get to this mode (800x600) using VBE instructions (AX=4F__h; INT 10h) and standard 10h video instructions may not be supported in these modes.
If you use a driver, then use the driver's getpixel command.

I use the VBE and Pascal + Assembly and I have no problems with ATI adapters. Regards,
Bert Vingerhoets
vingerhoetsbert@hotmail.com
Don't worry what people think about you. They're too busy wondering what you think about them.
 
anyone knows a good svga programming site with c for Dos?
 
I really suggest avoiding BIOS interrupts. I would rather implement multiple versions of the getpixel routine which interface direct to hardware. Then, at card detection time, bind getpixel() to the proper routine (just leave a dummy jmp far at the getpixel procedure). "Information has a tendency to be free. Which means someone will always tell you something you don't want to know."
 
Thanks bertv100 and thanks amkG,
i don't know what you meant could you give an example

bye
 
getpixel proc
JMP far ptr getpixel
getpixel endp

getpixelATI proc
;hardware-specific get pixel
.
.
.
.
getpixelATI endp

getpixelS3 proc
.
.
.
.
getpixelS3 endp

;other getpixels for other adapters
.
.
.
.

initgraphicsystem proc
Call DetectGraphicsAdapter
cmp Adapter,ATI
jne notATI
mov si,addr getpixelATI
jmp loadgetpixel
notATI:
cmp Adapter,S3
jne notS3
mov si,addr getpixelS3
jmp loadgetpixel
notS3:
.
.
.
.
loadgetpixel:
mov getpixel+1,si
push cs
pop getpixel+3
;other inits
.
.
.

ret
initgraphicsystem endp


Of course, you would probably be making several hardware specific routines, one routine each for one of the things you want to do (switch banks for example, or get and write pixels, or even draw lines so that you have more efficiency). To do that you can use procedure tables instead of just routines, have procedure pointers loaded into tables, separated by adapter, and at init time just load the procedure pointers into the main procedure table which is referenced by the rest of the program.

Note that this is largely an ASM technique although you can implement this in C (with some difficulty, because you need to say it in a way that C understands).
"Information has a tendency to be free. Which means someone will always tell you something you don't want to know."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top