Mail Archives: djgpp/1997/12/02/05:41:03
Walter Luke <NightWatchman AT Sacrilege DOT com> writes:
> I'm currently using a procedure for writing pixels in VGA (modes 18
> and 19) using ROM-BIOS. Can anyone suggest a faster way?
Accessing video memory in mode 19 is rather easy, read the FAQ
(search for _dos_ds and 0xa000), for mode 18 I have some
code which is faster than using BIOS (but slow anyway, blitting some
pixels in a row can be faster).
#include <dos.h>
#include <stdlib.h>
#include <string.h>
#include <pc.h>
#include <dpmi.h>
#include <sys/farptr.h>
static int width = 640;
static int height = 480;
static short video = 0;
void
vga_putpixel (int x, int y, int color)
{
if ((x >= 0) && (x < width) && (y >= 0) && (y < heigth))
{
static int bit_mask[8] = { 0x8000, 0x4000, 0x2000, 0x1000,
0x0800, 0x0400, 0x0200, 0x0100 };
const int d = (y * width + x) / 8;
const int b = bit_mask[x & 7];
outportw (0x3CE, 0x0205);
outportw (0x3CE, 0x0003);
outportw (0x3CE, 0x0008 | b);
#if 1
_farpeekb (video, d);
_farpokeb (video, d, color);
#else
_farpeekb (_dos_ds, 0xA0000 + d);
_farpokeb (_dos_ds, 0xA0000 + d, color);
#endif
}
}
/* mode can be 0x12 (640x480 graphics) and 0x03 (text). */
int
vga_set_mode (int mode)
{
__dpmi_regs r;
if ((mode != 0x12) && (mode != 0x03))
return -1;
memset (&r, 0. sizeof (r));
r.x.ax = mode;
__dpmi_int (0x10, &r);
memset (&r, 0, sizeof (r));
r.x.ax = 0x0F00;
__dpmi_int (0x10, &r);
if (mode != (r.x.ax & 0xFF))
return -1;
video = __dpmi_segment_to_descriptor (0xA000);
return 0;
}
I hope, I did not remove any significant code.
You can read about [S]VGA registers in vgadoc:
ftp://x2ftp.oulu.fi/pub/msdos/programming/docs/vgadoc4b.zip
(not sure about the URL, but file name should be correct).
HTH.
- Raw text -