Small VGA unit for DOS games

This is a discussion on Small VGA unit for DOS games within the Game Programming forums, part of the General Programming Boards category; Had this sitting around and thought I'd share it since it's unlikely I'll ever touch this code again. Just a ...

  1. #1
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590

    Small VGA unit for DOS games

    Had this sitting around and thought I'd share it since it's unlikely I'll ever touch this code again.

    Just a little skeleton of a VGA unit for DOS. Not sure where to put it as it can be used in DOS game programming (if anyone does that anymore) so it's not exactly only for the DOS board.

    Just a little something to help for the new people getting started with VGA and mode 13h.

    Here is how to use it:

    void SetBufferMode(int mode=FALSE)
    • Sets double buffer mode to true or false
    • When true surface is buffer, else surface is screen
    • All pixel and line functions write to surface so this effects them


    void Pixel(WORD x,WORD y,BYTE color)
    • Writes a colored pixel to surface (screen or buffer) at x,y


    void PixelEx(WORD offset,BYTE color)
    • Write a colored pixel to offset in surface at x,y
    • Faster than Pixel since offset not computed


    void InitVGA(void)
    • Sets up screen, buffer, and surface pointers
    • Inits BufferMode to FALSE


    BYTE far *GetSurface()
    • Returns a pointer to the current surface


    BYTE far *GetScreen()
    • Returns a pointer to the current screen (always A000:0000)


    BYTE far *GetBuffer()
    • Returns a pointer to the current double buffer


    void Flip(void)
    • Flips the buffer to the screen
    • Does not use surface
    • Always flips from buffer to screen
    • Does not check for vertical sync
    • Uses movsw so it is fairly fast
    • Most of the function is in assembly


    void CLS(BYTE color=0)
    • Clears the screen (A000:0000) with a color
    • Again, assembly language


    void CLSB(BYTE color=0)
    • Clears the double buffer with a color
    • Written in inline assembler


    void Line(int x,int y,int x2,int y2,BYTE color)
    • Draws a line from x,y to x2,y2 on current surface and in chosen color (BYTE color)
    • Uses Brehsenams (or however you spell it) line drawing algorithm
    • Pure C - could be sped up in assembly


    Setup
    • Call InitVGA() to setup pointers
    • Call CLSB to clear buffer if double buffering
    • Call CLS to clear screen if not double buffering
    • The rest is up to you




    This is for 16-bit real mode DOS. DO NOT execute this code inside of Turbo C++ 1.0-3.0 as it will crash the IDE due to lack of memory. There is not enough memory for the double buffer and the memory that the IDE needs.

    This should get some of you going, at least those who are just starting out in DOS - yes there are still some of you out there.
    I would not recommend using Line and Pixel too much since they generate function calls. My advice is to write directly to video memory, the current surface, or the double buffer. You can retrieve these pointers with the aforementioned functions.

    Questions? Post them here
    Last edited by VirtualAce; 10-17-2003 at 12:09 AM.

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    ...and here is the zip.



    Was there before but forgot thread title so back button reset file text box.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. When done right, PC games are amazing
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 08-13-2008, 05:32 PM
  2. Violent video games?
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 58
    Last Post: 04-26-2006, 01:43 PM
  3. Video Games Industry. 5 years left.
    By Cheeze-It in forum A Brief History of Cprogramming.com
    Replies: 26
    Last Post: 12-10-2002, 09:52 PM
  4. Check out my small games
    By VirtualAce in forum Game Programming
    Replies: 5
    Last Post: 05-12-2002, 11:57 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21