Plotting Pixels in Real Mode

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
kernel

Plotting Pixels in Real Mode

Post 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?)
The_Legend

Re:Plotting Pixels in Real Mode

Post by The_Legend »

What is videomode 13h? 320x256 with 256 Colors?
Are you sure you have set a valid palette?
drizzt

Re:Plotting Pixels in Real Mode

Post 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...
kernel

Re:Plotting Pixels in Real Mode

Post 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...
drizzt

Re:Plotting Pixels in Real Mode

Post 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...
kernel

Re:Plotting Pixels in Real Mode

Post 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?
drizzt

Re:Plotting Pixels in Real Mode

Post 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;
}

kernel

Re:Plotting Pixels in Real Mode

Post by kernel »

[attachment deleted by admin]
drizzt

Re:Plotting Pixels in Real Mode

Post by drizzt »

[attachment deleted by admin]
MattCarpenter

Re:Plotting Pixels in Real Mode

Post by MattCarpenter »

thanx. all works now :D
Post Reply