www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/02/22/19:30:38

From: "Dylan Trotter" <trotterd AT idirect DOT ca>
Newsgroups: comp.os.msdos.djgpp
Subject: Problems with video class in C++
Date: Mon, 22 Feb 1999 19:25:09 -0500
Lines: 90
X-Newsreader: Microsoft Outlook Express 4.72.3110.1
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
NNTP-Posting-Host: ts7-9o-28.idirect.com
Message-ID: <36d1f59d.0@nemo.idirect.com>
X-Trace: 22 Feb 1999 19:26:05 -0500, ts7-9o-28.idirect.com
Organization: via Internet Direct
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Hi

I am having a problem with regards to a video class I am attempting to make.
It contains methods, variables, pointers, etc. which encapsulate video
output. I hope to eventually make it a solid class which will supply me with
a whole video interface for programming all kinds of things.

Unfortunately I ran into a rather large snag, right near the put_pixel phase
of things. I had an old C library from which I copied a lot of the functions
which were tried tested and true (though perhaps not as efficient as they
could be). So things were going good until I wrote a test program which
would simply fill the screen with different coloured pixels. It was to
switch to mode 13h, put pixels in a buffer, show the buffer and then switch
back to mode 03h.

It switches modes fine, it goes into 13h and shows nothing, then switches
back to mode 03h. So it's a problem with my show_buffer or put_pixel
functions (as those are the only other calls I make). The important lines
are shown below:

/*This is the assignment for the screen pointer which should point to the
VGA segment*/
screen = (unsigned char *) 0xA0000 + __djgpp_conventional_base;

/*This dynamically allocates memory for the 320x200x8 buffer*/
buffer = new unsigned char[64000];

/*This is the put_pixel routine I am using*/
inline void video::put_pixel(int x, int y, unsigned char col)
{
 if (col != trans_col[0])
 {
  if (x < 0) x = x_resolution + (x % x_resolution);
  if (x >= x_resolution) x %= x_resolution;
  if (y < 0) y = y_resolution + (y % y_resolution);
  if (y >= y_resolution) y %= y_resolution;

  buffer[y * bytes_per_scanline + x] = col;
 }
}

/*And this is the routine to copy the buffer to the screen*/
inline void video::show_buffer()
{
 wait_for_vertical_retrace();

 for(int y = 0; y < y_resolution; y++)
  memcpy((unsigned char *) (screen + (y * bytes_per_scanline *
bytes_per_pixel)),
                  (unsigned char *) (buffer + (y * x_resolution *
bytes_per_pixel)),
                  x_resolution * bytes_per_pixel);
}

The problem should be somewhere in here, I just don't know where yet. A word
of note, in case how it was all compiled matters, all of the inline
functions are in a file called "video.inl" which is included in "video.h".
This file is included in "video.cpp" which contains all of the non-inline
functions. I then compiled into an object file. This file was linked in the
compilation of the executable which I tested from. I don't think all of this
should matter, because it compiled fine and there are no undefined
references or anything.

Another quick question I have is whether there is a software interrupt I
could call to return the current video mode (preferably including extended
SVGA modes).

As if all of this weren't enough, I have yet another question. I included a
constructor for the video class and tried to incorporate a destructor, as
there are several pointers within the class. The destructor is written as
follows:

video::~video()
{
 if (buffer != NULL) delete [] buffer;
}

The object file compiled fine, but when I tried to link it into the test
program it gave some crazy assembler errors. If anyone knows what this is
all about, please tell me.

Anyway, I guess that's enough to bother everyone with for now :) Thanks very
much in advance for any help I receive, I hope I can return the favour some
time.

Thank you,
 Dylan Trotter
 trotterd AT idirect DOT ca


- Raw text -


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