Plotting Pixels in Real Mode
Plotting Pixels in Real Mode
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?)
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
What is videomode 13h? 320x256 with 256 Colors?
Are you sure you have set a valid palette?
Are you sure you have set a valid palette?
Re:Plotting Pixels in Real Mode
If I'm not wrong video mode 13h is 320x200 with 256 colors... and you don't set the correct address of VGA mem!
Here I think you must set 0xA0000 because it's not the segment, but the linear address...char *vidmem = (char *)0xA000;
Re:Plotting Pixels in Real Mode
How do you set a pallete?The_Legend wrote: What is videomode 13h? 320x256 with 256 Colors?
Are you sure you have set a valid palette?
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
Are you sure that you really set 0xA0000???
Try with this code... before you call the plotpixel set the correct data segment register:
But now your C procedure must be like this:
I think now it will work...
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
...
Code: Select all
void plotpixel()
{
char *vidmem;
short offset;
vidmem=0; /* Initial location of VGA segment */
offset = 320*10+10;
vidmem[offset] = 10;
}
Re:Plotting Pixels in Real Mode
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?
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
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:
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;
}