Page 1 of 1

Plotting Pixels in Real Mode

Posted: Thu Jul 25, 2002 7:49 pm
by kernel
im kinda stuck (again). :P
I have a small real-mode kernel made in ASM, and i linked some C code to it also. I am trying to plot pixels to the video memory, but it never works (doesn't plot the pixel)

My code looks something like this:

(In the ASM file)
...
;Set Video Mode Here

call _plotpixels ;This function was made in C
jmp $ ;Hang
...
(in the C file)

char *vidmem = (char *)0xA000;
short offset;

void plotpixels() {
offset = 320*10+10;
vidmem[offset] = 10; //Set pixel 10x10 green
}

It all compiles just fine and runs just fine except I cant see the pixels I plot! BTW It is using video mode 19 (13h?)

Re:Plotting Pixels in Real Mode

Posted: Thu Jul 25, 2002 11:48 pm
by The_Legend
What is videomode 13h? 320x256 with 256 Colors?
Are you sure you have set a valid palette?

Re:Plotting Pixels in Real Mode

Posted: Fri Jul 26, 2002 4:21 am
by drizzt
If I'm not wrong video mode 13h is 320x200 with 256 colors... and you don't set the correct address of VGA mem!
char *vidmem = (char *)0xA000;
Here I think you must set 0xA0000 because it's not the segment, but the linear address...

Re:Plotting Pixels in Real Mode

Posted: Fri Jul 26, 2002 9:08 am
by kernel
The_Legend wrote: What is videomode 13h? 320x256 with 256 Colors?
Are you sure you have set a valid palette?
How do you set a pallete?

BTW, Ive tried several different mem locations (0xA000, 0xA0000, etc... and i didn't see a pixel with any of them, so maybe I do have to set a pallete or something...

Re:Plotting Pixels in Real Mode

Posted: Fri Jul 26, 2002 5:01 pm
by drizzt
Are you sure that you really set 0xA0000???

Try with this code... before you call the plotpixel set the correct data segment register:

Code: Select all

...
; First of all you must initialize video mode 13h
mov   ax, 0013h
int   10h

; Here you must set data segment register to the VGA segment
push   ds
mov   ax, 0A000h
mov   ds, ax

; Now call the procedure
call   _plotpixel

; Restore old data segment register value
pop   ds
...
But now your C procedure must be like this:

Code: Select all

void plotpixel()
{
   char *vidmem;
   short offset;
   
   vidmem=0;  /* Initial location of VGA segment */
    offset = 320*10+10;
   vidmem[offset] = 10;
}
I think now it will work...

Re:Plotting Pixels in Real Mode

Posted: Fri Jul 26, 2002 11:11 pm
by kernel
Well, it plots pixels, but not in the right location

offset = 320*10+10 should be 10,10
but, the pixel is plotted somewhere near 170.1
I tried to fill each pixel with color, but only 3 or 4 pixels were plotted. Whats wrong now?

Re:Plotting Pixels in Real Mode

Posted: Sat Jul 27, 2002 4:19 am
by drizzt
Uhmmm... it seems to me very strange... I've tested it on my computer and it works perfectly...
Try to use an int var for the offset... So you can try with this code:

Code: Select all

void plotpixel()
{
   char *vidmem;
   int offset, x, y;
   char color;
   
   vidmem=0;  /* Initial location of VGA segment */

   x=<your x coord>;
   y=<your y coord>;
   color=<your color>;

   offset=320*y+x;
   vidmem[offset] = color;
}


Re:Plotting Pixels in Real Mode

Posted: Sat Jul 27, 2002 12:50 pm
by kernel
[attachment deleted by admin]

Re:Plotting Pixels in Real Mode

Posted: Sun Jul 28, 2002 3:56 am
by drizzt
[attachment deleted by admin]

Re:Plotting Pixels in Real Mode

Posted: Sun Jul 28, 2002 4:14 pm
by MattCarpenter
thanx. all works now :D