Mail Archives: djgpp/1999/05/10/15:25:23
From: | Darkstar <darkstar AT user1 DOT channel1 DOT com>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | I NEED HELP!
|
Date: | Mon, 10 May 1999 08:11:08 -0400
|
Organization: | Channel 1 Communications
|
Lines: | 127
|
Message-ID: | <3736CCDB.5528948F@user1.channel1.com>
|
NNTP-Posting-Host: | xdial134.channel1.com
|
Mime-Version: | 1.0
|
X-Mailer: | Mozilla 4.05 [en] (Win95; I)
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
Hello to all the DJGPP gurus out there. I need help with a set of
functions that seem to have a wandering pointer somewhere but I don't
seem to be able to find it.
Here are the offending functions. a c++ struct. The function of this
struct is to hold
16x16 images for sprite animation. Screen is a 320x200 buffer of
unsigned char(uns8)
MAXFRAMES is 100
struct frame16 {
int number;
uns8 *frames[MAXFRAMES];
frame16(int i);
~frame16();
void loadframe(pcx_picture pic,int i,int x,int y);
void drawframe(int i,int wx,int wy,int sx,int sy,
int sox,int soy,int sw,int sh,uns8 *screen);
void ncdrawframe(int i,int x,int y,uns8 *screen);
};
// this is the constructor for a frame
frame16::frame16(int i) {
int n;
number=i;
for(n=0;n<MAXFRAMES;++n) {
frames[n]=NULL;
}
for(n=0;n<i;++n) {
frames[n]=new uns8[256];
}
}
// this is the destructor of frame
frame16::~frame16() {
int i;
for(i=0;i<number;++i)
delete frames[i];
}
// this function loads a frame image into a frame buffer from a picture
void frame16::loadframe(pcx_picture pic,int i,int x,int y) {
int a;
int b;
int c;
int offset;
uns8 *aframe;
aframe=frames[i];
if(aframe==NULL)
printf("error\n");
c=0;
offset=y*(pic.header.width+1)+x;
for(a=0;a<16;++a) {
for(b=0;b<16;++b) {
// printf("c=%d\n",c);
aframe[c]=pic.buffer[offset+b];
// printf("%d\n",c);
c++;
}
offset+=pic.header.width+1;
}
}
void frame16::ncdrawframe(int i,int x,int y,uns8 *screen) {
uns8 *aframe;
int offset=(y<<8)+(y<<6)+x;
int foffset=0;
int a=0;
int b=0;
uns8 c=0;
aframe=frames[i];
for(a=0;a<16;++a) {
for(b=0;b<16;++b) {
c=aframe[(foffset+b)];
if(c!=0)
screen[(offset+b)]=c;
}
foffset+=16;
offset+=320;
}
}
The regular drawframe function hasn't been used yet or tested.
ncdrawframe works.
The image is loaded from a 320x200 pcx image(there is no problem with
that function.
When the contents of screen are to be displayed I use
void screenblast13h(uns8 *screen) {
waitforvs();
dosmemput(screen,64000,0xa0000);
}
waitforvs() waits for the vertical retrace. This function when tested
works too.
If everything seems to work what is the problem? Ok. If I display
a background image (display screen's contents without drawing a frame)
and the loadframe function is
called a dot sometimes appears in the upper left corner of the screen.
This dot will not
appear if the loadframe function is not called. Also I occasionally get
a segment fault
after exciting the program normally(It doesn't crash until the end of
the program)
All the program does is load the graphic data, load the frames, set the
graphics mode to 13h and display stuff. As I said all the functions seem
to work fine(I have tested all the
functions). All the arrays are of the correct sizeand pointers
cannot(as far as I can tell)
wander out of their arrays. the header data for the modules are the
same size as the data they represent. There seems to be a sign of a
wandering pointer but I cannot find the problem.
Please Help me! Tell me what could be wrong. I have been
executing this
program in a dos shell of win95. Please send me an email with helpful
suggestions.
Thank you!!!!
-darkstar
- Raw text -