delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/11/11/08:31:22

From: bdonor AT westnet DOT com (Brain Donor)
Newsgroups: comp.os.msdos.djgpp
Subject: Program runs in NT but not DOS.
Date: Mon, 10 Nov 1997 09:01:48 GMT
Organization: INTERNET AMERICA
Lines: 80
Message-ID: <C91001A3BBF76064.10FDC46AFC90742C.1E32F59DA2B26543@library-proxy.airnews.net>
NNTP-Proxy-Relay: library.airnews.net
NNTP-Posting-Time: Mon Nov 10 03:03:32 1997
NNTP-Posting-Host: h238-198.whitman.albany.edu
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

I'm just starting with DJGPP and I wrote a small program that has a
REALLY bad Mode13h putpixel in it.  I compiled the program and it ran
fine in NT, but in DOS it crashes with a segmentation fault (SIGSEGV).
The code is below.  Any ideas why?  Also, how can I make the putpixel
function inline.  When I try, it won't compile.  Thanks...

#include <dpmi.h>
#include <go32.h>
#include <stdlib.h>
#include <iostream.h>
#include <pc.h>

short graphics_global_selector = _dos_ds;

void main ()
{
  void putpixel (int, int, int);
  void setmode13h ();
  void setmode3h ();
  long int counter = 0;

  setmode13h ();

  while (!kbhit ())
  {
    putpixel (rand () % 320, rand () % 200, rand () % 256);
    counter++;
  }

  setmode3h ();
  counter = 90000;
  cout << counter << endl;
}

void putpixel (int x, int y, int color)
{ asm(
      "movw _graphics_global_selector, %%es;"  // This must be set so
we can access our lower memory.  It's some strange protected mode
thing
      "xorl %%edi, %%edi;"                     // Clear out edi.  This
is an absolute pointer to our video memory.  No need for segments!!!
:)
      "movw %0,    %%di;"                      // Load parameter zero
(defined as x below) in di
      "movw %1,    %%bx;"                      // Load parameter one
(defined as y below) in bx
      "movl %%ebx, %%edx;"                     // Copy ebx into edx
      "shll $8,    %%ebx;"                     // Do shifting for
commutative math (y * 256)
      "shll $6,    %%edx;"                     //
(y * 64)
      "addl %%edx, %%ebx;"                     // Perform ((y * 256) +
(y * 64)) to get y * 320
      "addl %%ebx, %%edi;"                     // Add this to our x
coordinate
      "addl $0xA0000, %%edi;"                  // Add the address of
video RAM to edi to point to the offset in video memory.
      "movw %2,    %%ax;"                      // Move color into ax
      "stosb;"                                 // Perform stosb to
store the color into video memory
      :
      :"g"(x), "g"(y), "g"(color)              // Define x as %0, y as
%1, color as %2
      );
}

void setmode13h ()
{
  __dpmi_regs reg;
  reg.x.ax = 0x13;
  __dpmi_int (0x10, &reg);
}

void setmode3h ()
{
  __dpmi_regs reg;
  reg.x.ax = 0x03;
  __dpmi_int (0x10, &reg);
}

- Raw text -


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