Beginner Question
Question submitted by (15 June 2000)




Return to The Archives
 
  I have been programming in C++ for a couple years for school, and i have been wanting to break into some basic game design. I have text adventures down, no graphics!! I have looked on the web and have learned I need to set the video mode to13h for a basic 256 display. The problem is I can't seem to find how to do this in Borland C++, can anyone help me?  
 

 
  I'm not familiar with Borland's interface to assembly, but it should look something like this:

__asm { mov ax,0x13; int 0x10 };

To return to text mode, use the following:

__asm { mov ax,0x3; int 0x10 }; // Note the change from 0x13 to 0x3

Once in this mode, you'll want to address memory starting at 0xA0000. The first byte is the upper-left pixel, the next byte is the pixel to the right of the upper left pixel, etc. As you reach the end of a scanline of pixels (320 bytes in this case) the bytes keep going, but the pixels wrap around to the start of the next scanline. To set a specific pixel, do this:

char far *pixelAddress = (char far *) 0xA0000 + (pixel_y * 320 + pixel_x);

...pixel_x is the x-coordinate (from left to right) of the pixel, and pixel_y is the y-coordinate (from top to bottom) pixelAddress points to the address of the pixel you want to reference. The default palette (which maps the 8-byte values you store at these addresses to a specific color) uses the value 0xf for white. I only mention this, because the screen defaults to black, and if you fill it with zeros, you won't see anything.



Response provided by Paul Nettle
 
 

This article was originally an entry in flipCode's Ask Midnight, a Question and Answer column with Paul Nettle that's no longer active.


 

Copyright 1999-2008 (C) FLIPCODE.COM and/or the original content author(s). All rights reserved.
Please read our Terms, Conditions, and Privacy information.