PDA

View Full Version : graphics flickering problem



Benzakhar
02-22-2004, 09:51 AM
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!

VirtualAce
02-22-2004, 03:46 PM
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.





#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.

Benzakhar
02-23-2004, 05:15 PM
Thanx very much.