Menu

Far pointers and writing to video memory?

2002-10-14
2012-09-26
  • Nobody/Anonymous

    Hi,

    I am bit of a newbie, but I am hoping to write a graphics demo in Dev-C++. I have written a method to implement Bresehams line drawing algorithm, but I have a problem when I call a method I have written called SetPixel....

    // Sets the given pixel in the image buffer
    void RasterAlgorithm::SetPixel( int X, int Y, int winWidth, unsigned char Colour )
    {
    imageBuffer[ Y*winWidth + X ] = Colour;
    }

    However, I do not know how to define imageBuffer ... I have seen examples that define it as (unsigned char far*) imageBuffer = (unsigned char far*) 0XA00000000L;

    This does not work as Dev-C++ does not allow me to use the keyword "far" for far pointer, so how do I define the imageBuffer? HELP!

     
    • Nobody/Anonymous

      DevC++ is an IDE, it uses the MinGW compiler.
      Below is one site that offers tutorials in programming in C/C++ and others. ( tutorials for DevC++ and VC++).

      Here check it out.
      http://gametutorials.com/Tutorials/c/C_Pg3.htm

      j@ck_

       
    • Nobody/Anonymous

      Thanks j@ck_!

      Chloe-anne.

       
    • Nobody/Anonymous

      Just to amplify on something Jack said, Dev uses MingW, which is a nice little tool that enables a number of Gnu components to be usedin a PC/Windows environment.  Among those tools is the gcc compiler suite, of which g++ is the C++ compiler.

      gcc pops up in other places by the way, it is the compiler suite included in Cygwin, djgpp, and used on a ton of UNIX machines.  I use it most in Cygwin, giving you WAY more information than you wanted.

      So, for future reference, the compiler you are using is called gcc, this might be helpful when you go googling.

      By the way, when you get your issue worked out, be sure to post back here, as there are intellectually challenged types such as myself who would love to see the answer.

      :-)

      Wayne

       
    • Nobody/Anonymous

      Thanx Wayne, for the info that makes things clear about gcc , and all of it is a big help to people that need to be clear on these things.

      j@ck_

       
    • Nobody/Anonymous

      Just a tad of info on DJGPP.
      It was the compiler for unix ported to dos, that the game company  Id  used to create DOOM on...all so many years ago.

      j@ck_

       
    • Nobody/Anonymous

      Yep. I am familiar with g++ on Linux and by "newbie", I mean a newbie to dev-c++ and programming in a windows environment!.

      I have found djgpp much easier to access the image buffer in Protected Mode. For anyone who is interested I have found a couple of ways of implementing SetPixel (and I am sure there are more, even better ways!):

      1.)
      #include <sys/farptr.h>
      #include <go32.h>   

      _farpokeb(_dos_ds, 0xA0000 + (320 * y + x), Colour);

      2.)
      #include <sys/neaptr.h>

      unsigned char* imageBuffer = (unsigned char *)(__djgpp_conventional_base + 0xA0000);

      imageBuffer[320 * y + x] = Colour;

        __djgpp_nearptr_disable();

      This can be speed up:
      imageBuffer[(y << 8) + (y << 6) + x] = Colour;

      The first way is considered *safer* as you are in effect turning memory protection off in the second method as opposed to overriding.

      Thanks for your help guys :-)

      Chloe-anne.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.