Thread: graphics flickering problem

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    161

    graphics flickering problem

    My graphics flicker. I tryed to create a second buffer by allocating memory and drawing on the second buffer then copying to the screen. That would work but when I try to allocate memory 64000bytes of memory for 320*200 graphics I get a NULL pointer. How do other programmers that wrote dos games prevent the flickering?

    Thanx in advance!

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    In order to transfer 64KB blocks of memory at a time you must be in large memory model. As well do not attempt to run the program inside of your Turbo IDE as it takes up too much memory. You must test the code outside of the IDE - then your pointer will no longer be NULL.


    Code:
    #define XYTOMEM(x,y)  ((y<<6)+(y<<8)+x)
    #define TRUE 1
    #define FALSE 0
    
    typedef unsigned char BYTE;
    BYTE *Surface;
    BYTE *Screen;
    BYTE *Buffer;
    
    void Init(void);
    void Flip(void);
    void Pixel(int x,int y,BYTE c);
    void SetBufferMode(int mode=TRUE);
    
    void Init(void)
    {
      asm 
      {
        mov ax,13
        int 10h
      }
      
      Screen=(BYTE far *)MK_FP(0,0xA000);
      Buffer=new BYTE[64000L];  //will fail inside of the IDE
      Surface=Screen;
    }
    
    void Flip(void)
    {
      asm
      {
         push  ds
         les      edi,[Screen]
         lds      esi,[Buffer]
         mov    cx,32000d
         rep     stosw
       }
       //or use memcpy() from mem.h
    }
    
    void Pixel(int x,int y,BYTE c)
    {
      Surface[XYTOMEM(x,y)]=c;
    }
    
    void SetBufferMode(int mode)
    {
      if (mode) 
      {
         Surface=Buffer;
      } else Surface=Screen;
    }

    That should be enough to get you started. Flip() flips the buffer to the screen regardless of the surface pointer. SetBufferMode alters the surface pointer so that you can plot pixels either to the buffer or the screen with one function.

  3. #3
    Registered User
    Join Date
    Nov 2003
    Posts
    161
    Thanx very much.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginning Game Programming Type Books
    By bumfluff in forum Game Programming
    Replies: 36
    Last Post: 09-13-2006, 04:15 PM
  2. Bin packing problem....
    By 81N4RY_DR460N in forum C++ Programming
    Replies: 0
    Last Post: 08-01-2005, 05:20 AM
  3. Graphics Programming :: Approach and Books
    By kuphryn in forum Windows Programming
    Replies: 4
    Last Post: 05-11-2004, 08:33 PM
  4. egavga.bgi problem
    By sunil21 in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 09-22-2003, 05:06 PM
  5. Graphics Problem
    By drdroid in forum C++ Programming
    Replies: 5
    Last Post: 02-27-2002, 02:37 PM