Mail Archives: djgpp/1997/10/20/00:19:58
waage wrote:
> I am having problems copying info from a virtual screen allocated with
> malloc and copying it to the VGA 0xa000. The code looks like this,
> when compiled it says no errors but when I try to write to the virtual
> screen with my put_pixel it crashes.
[ snipped code, etc ]
Whoa there fella :) You're making it too difficult for yourself.
Here, try this:
char *get_screen(int x, int y) {
return (char *)malloc(x*y);
}
void putpixel(char *screen, int x, int y, char c) {
screen[y*max_x+x] = c;
}
void show_screen(char *screen) {
dosmemput(screen, max_x*max_y, 0xA0000);
// or perhaps...
dosmemput(screen, sizeof(*screen), 0xA0000);
}
int main(void) {
char *screen;
// set video mode here
screen = get_screen(max_x, max_y);
putpixel(screen, 0, 0, 15);
show_screen(screen);
// goto text mode here
}
There... that should get you up and running, I hope. That's all off the
top of my head though, so they're may be a few tiny errors... but I don't
think so. I've checked through it. Also, unless you specifically _have_
to, just copy the virtual screen, don't swap it with video memory...
reading from video memory is very slow. Plus, dosmemput isn't exactly
the fastest method to copy the virtual screen either.
For more information about graphics programming, check out my
DJGPP graphics programming tutorial on my hompage (location is in my
sig.). It's due for an update, but still has a lot of good stuff in it.
Jeff
--------------------------------------------
- Code X Software -
Programming to a Higher Power
email: mailto:pweeks AT execulink DOT com
web: http://www.execulink.com/~pweeks/
--------------------------------------------
- Raw text -