Mail Archives: djgpp/1995/06/17/08:15:38
Yeah, it's me again. I must have an older, bug-ridden version or something...
I have source code for a very rapid, direct-memory-copying screen
scrolling routine. (As direct as it can be in protected mode..>!)
It works fine when the scroll involves copying the memory to a higher
address, but not when copying to a lower one. When copying to a lower one
it almost works, but the top one fifth or so of the screen behaves very
strangely.
The scroll uses a buffer; 64000 bytes are copied from screen into the
buffer at (buffer+1000+scroll) where scroll is dx+320*dy (320x200). Then
64000 bytes are copied from buffer+1000 to screen. If scroll is negative
the problem occurs. I have checked and rechecked all the pointer
operations and math, and I have concluded that the problem lies with the
compiler and how it handles the assignment operation that does the memory
copying.
The source code follows for a short program that scrolls a field of random
pixels and slowly changes the scroll, as though a camera were flying in a
circle over a landscape of random dots.
#include <graphics.h>
#include <dos.h>
#define SETMODE 0
#define VIDEO_INT 0x10
#define G320x200x256 19
#define TEXT_COLOR 3
#define PUTPIXEL(x,y,c) *(video+(x)+(y)*320)=(c)
struct the_screen {
unsigned char pixel[320][240];
unsigned char overflows[2000];
};
void hsetmode (char mode);
void scroll (int scrollstep);
struct the_screen *screen = (struct the_screen *)0xD0000000;
char *video = (char *)0xD0000000;
struct the_screen vbuffer;
struct the_screen *vbuf = &vbuffer;
char *vb2 = (char *)&vbuffer+1000;
void main (void) {
int x,y;
int x1,y1;
int x2,y2;
int i,j;
int scrs;
int dx[16]={-6,-5,-4,-3, 0, 3, 4, 5, 6, 5, 4, 3, 0,-3,-4,-5};
int dy[16]={ 0,-3,-4,-5,-6,-5,-4,-3, 0, 3, 4, 5, 6, 5, 4, 3};
unsigned char color;
hsetmode (G320x200x256);
for (x=0; x<320; x++) {
for (y=0; y<200; y++) {
color=rand()/128;
PUTPIXEL(x,y,color);
}
}
for (i=0; i<16; i++) {
scrs=dy[i]*320+dx[i];
y1=(dy[i]<0) ? 200+dy[i] : 0;
y2=(dy[i]<0) ? 200 : dy[i];
x1=(dx[i]<0) ? 320+dx[i] : 0;
x2=(dx[i]<0) ? 320 : dx[i];
for (j=0; j<40; j++) {
scroll (scrs);
for (x=x1; x<x2; x++) {
for (y=0; y<200; y++) {
color=rand()/128;
PUTPIXEL(x,y,color);
}
}
for (y=y1; y<y2; y++) {
for (x=0; x<320; x++) {
color=rand()/128;
PUTPIXEL(x,y,color);
}
}
}
}
for (j=0; j<10000; j++);
hsetmode (TEXT_COLOR);
}
void hsetmode (char mode) {
union REGS regs;
regs.h.ah=SETMODE;
regs.h.al=mode;
int86 (VIDEO_INT, ®s, ®s);
}
void scroll (int scrollstep) {
*(struct the_screen *)(vb2+scrollstep)=*screen;
*screen=*(struct the_screen *)vb2;
}
If anyone can help with this inexplicable problem, could they e-mail the
solution?
Thanks in advance,
PGD
--
.*. "Clouds are not spheres, mountains are not cones, coastlines are not
-() < circles, and bark is not smooth, nor does lightning travel in a
`*' straight line." ,------------------------------------------------
-- B. Mandelbrot | Paul Derbyshire (PGD) ao950 AT freenet DOT carleton DOT ca
- Raw text -