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.