delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/20/00:19:58

From: Jeff Weeks <pweeks AT execulink DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: wirting to a virtual screen - HELP!
Date: Sat, 18 Oct 1997 14:57:45 -0400
Organization: Code X Software
Lines: 58
Message-ID: <344906A8.AAA3ED1B@execulink.com>
References: <3446a9d5 DOT 2362988 AT news DOT polaristel DOT net>
NNTP-Posting-Host: ppp34.a6.execulink.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019