Mail Archives: djgpp/1998/07/27/16:15:26
From: | martin AT loplop DOT com (Martin Peach)
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | fwrite from linear vga buffer
|
Date: | Mon, 27 Jul 1998 20:01:39 GMT
|
Organization: | Communications Accessibles Montreal, Quebec Canada
|
Lines: | 60
|
Message-ID: | <35bcd9c0.147173@nntp.hip.cam.org>
|
NNTP-Posting-Host: | dialup-831.hip.cam.org
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Hi all,
I want to dump the screen image to a file for debugging purposes. I
have set up a linear buffer in the way Shawn Hargreaves describes on
the delorie website. I have no problem accessing the data via a line
buffer I allocate, using movedata(linBufSelector, i, _my_ds,
(int)lineBuf, lineBytes). But I want it to go faster...it seems as
though I could just do a fwrite((void *)linBufMapping.address + i,
lineBytes, 1L, fp) to write the data directly to a file rather than
going through an intermediate line buffer. But the thing crashes when
I use linBufMapping.address (which is 0xE0000000, a reasonable looking
address, no?). Is there some other call I need to make to point the
thing to the right place or does fwrite not work on this kind of
address?
Martin.
The function:
size_t DumpScreen(char *Nom)
{// write screen image to file Nom, return number of bytes written
FILE *fp;
unsigned long bytes, i, x, y, numwritten;
unsigned long lineBytes;
char *lineBuf;
fprintf(stdout, "Doing screen dump to %s\n", Nom);
// allocate a buffer for one line of pixels
lineBytes = vgaModeInfo.XResolution * bytesPerPixel;
if ((lineBuf = malloc(lineBytes)) == NULL)
{
fprintf(stdout, "DumpScreen: Unable to allocate %u
bytes for lineBuf\n", lineBytes);
return 0L;
}
if ((fp = fopen(Nom, "wb")) == NULL)
{
fprintf(stdout, "DumpScreen: Unable to open %s for
writing\n", Nom);
return 0L;
}
for (y = bytes = 0; y < vgaModeInfo.YResolution; y++)
{
i = y * vgaModeInfo.BytesPerScanLine;
movedata(linBufSelector, i, _my_ds(), (int)lineBuf,
lineBytes);
// this crashes:
// if ((numwritten = fwrite((void *)linBufMapping.address + i,
lineBytes, 1L, fp))!=1L)
// fprintf(stdout, "DumpScreen: Write Error at
offset %u\n", i);
//this works:
if ((numwritten = fwrite((void *)lineBuf, lineBytes,
1L, fp))!=1L)
fprintf(stdout, "DumpScreen: Write Error at offset
%u\n", i); bytes += numwritten;
}
fclose(fp);
free(lineBuf);
return bytes;
}
- Raw text -