delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/12/02/05:41:03

Sender: M DOT A DOT Bukin AT inp DOT nsk DOT su
To: djgpp AT delorie DOT com
Cc: NightWatchman AT Sacrilege DOT com
Subject: Re: Writing pixels fast
References: <65unrl$9gl AT mtinsc02 DOT worldnet DOT att DOT net>
From: Michael Bukin <M DOT A DOT Bukin AT inp DOT nsk DOT su>
Date: 02 Dec 1997 16:39:32 +0600
In-Reply-To: Walter Luke's message of Mon, 01 Dec 1997 11:08:44 -0500
Message-Id: <203ekcyqor.fsf@Sky.inp.nsk.su>
Lines: 71

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019