www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/12/21/14:42:54

From: Mike Pope <dt AT inreach DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Slow code and SVGALib
Date: Sat, 21 Dec 1996 10:18:02 -0800
Organization: N/A
Lines: 219
Message-ID: <32BC29D9.7036@inreach.com>
NNTP-Posting-Host: ppp2204.inreach.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Hi all...
Could somebody PLEASE tell me why this code is so danged SLOW?
I've tried everything I could think of!  Basically, what I'm trying
to do is write a scrolling routine with SVGALib, but it's so dang slow.
I'm essentially using SVGALib as nothing more than a pointer
to video memory and I wrote my own blast functions and everything.
For those of you wondering why I'm mucking around with SVGALib
instead of something nice like Allegro, I need portability to  Linux.
(For those of you who suggest GRX and JLib, I can't get JLib to compile
and GRX seems essentially useless :) ).  I'm using a 486DX/50
with 8 megs of RAM and a TSeng ET4000 video board.  

/*Fodder.c - my program.*/

#define BYTE unsigned char
#define far
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>
#include <conio.h>
#include <vga.h>
#include <vgagl.h>
#include <vgakeybo.h>
#define NUMBALLS 50
#define SCRWIDTH 352
#define SCRHEIGHT 232
#define bitblt(a, b, c, d, e, f, g, h) _bitblt(a, b, 0, 0, c, d, e, f, g, 
h, FALSE)
#define cutbitblt(a, b, c, d, e, f, g, h, i, j) _bitblt(a, b, c, d, e, f, 
g, h, i, j, FALSE)
#define scrdump(a, b, c, d, e) _bitblt(a, b, c, d, e, videomem, TRUE)
#define TRUE 1
#define FALSE 0
#define BALLWIDTH 8
#define BALLHEIGHT 8
unsigned char ballpic[64] = {
0, 0, 0, 9, 9, 0, 0, 0,
0, 0, 9, 9, 9, 9, 0, 0,
0, 9, 9, 9, 9, 9, 9, 0,
9, 9, 9, 9, 9, 9, 9, 9,
9, 9, 9, 9, 9, 9, 9, 9,
0, 9, 9, 9, 9, 9, 9, 0,
0, 0, 9, 9, 9, 9, 0, 0,
0, 0, 0, 9, 9, 0, 0, 0
};
unsigned char *buffer;
unsigned char *videomem;
unsigned char data[256] = {
0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0,
0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0,
0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0,
0, 0, 0, 0, 0, 2, 5, 5, 5, 5, 5, 2, 0, 0, 0, 0,
0, 0, 0, 0, 0, 2, 0, 5, 5, 5, 0, 2, 0, 0, 0, 0,
0, 0, 0, 0, 0, 2, 0, 0, 5, 0, 0, 2, 0, 0, 0, 0,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5,
5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5,
0, 0, 0, 5, 4, 4, 4, 4, 4, 4, 4, 4, 5, 0, 0, 0,
0, 0, 0, 0, 5, 4, 4, 4, 4, 4, 4, 5, 0, 0, 0, 0,
0, 0, 0, 0, 0, 5, 4, 4, 4, 4, 5, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 5, 4, 4, 5, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0, 0};


void rawblt(int x, int y, unsigned char *dest, unsigned char *source, int 
srcwidth, int srcheight) 
{
	int i, j;
	source+=(y*SCRWIDTH+x);
	for (j=0;j<200;j++) {
		for (i=0;i<320;i++) {
			*dest=*source;
			dest++;
			source++;
		}
		source+=32;
	}	
}

void _bitblt(int x, int y, int origx, int origy, int width, int height, 
int destwidth, int destheight, unsigned char *source, unsigned char 
*dest, int scrcopy)
{
        int i, j;

	dest+=y*destwidth+x;
	source+=origy*width+origx;
        for (j=y;j<y+height;j++) {
                for (i=x;i<x+width;i++) {
                       	if (i>0 && i<destwidth && j>0 && j<destheight)
        	                *(dest) = *(source);
	               	dest++;
               		source++;
                }
	dest+=destwidth-width;
        }
        
        return;
}                
void draw_background()
{
	int i, j;
	for (i=0;i<(352/16);i++) {
       		for (j=0;j<(232/16);j++) {
	        	bitblt(i*16, j*16, 16, 16, SCRWIDTH, SCRHEIGHT, 
data, buffer);
		}
	}
}	
void do_balls(int initialize)
{
	static int x[NUMBALLS], y[NUMBALLS], dx[NUMBALLS], dy[NUMBALLS];
	int i, j;
	if (initialize==TRUE) {
		for (i=0;i<NUMBALLS;i++) {
			x[i] = rand()%SCRWIDTH-8;
			y[i] = rand()%SCRHEIGHT-8;
			dx[i] = (rand()%8)-4;
			dy[i] = (rand()%8)-4;
			if (dx[i] == 0) dx[i]++;
			if (dy[i] == 0) dy[i]++;
		}
		return;
	}
	for (i=0;i<NUMBALLS;i++) {
		x[i]+=dx[i];
		y[i]+=dy[i];
		if (x[i]>SCRWIDTH-8 || x[i]<0) {
			dx[i] = -(dx[i]);
			x[i] += dx[i];
		}
		if (y[i]>SCRHEIGHT-8 || y[i]<0) {
			dy[i] = -(dy[i]);
			y[i] += dy[i];
		}
		bitblt(x[i], y[i], BALLWIDTH, BALLHEIGHT, SCRWIDTH, 
SCRHEIGHT, ballpic, buffer);
	}
	return;
}
void main() {
	int i;
        int j;
	int dx, dy;
	int curx, cury;
	int stop = FALSE;
	unsigned char keybuf = NULL;
	curx = cury = dx = dy = 0;
        buffer = (unsigned char*)malloc((SCRWIDTH*SCRHEIGHT));
	vga_init();

	vga_setmode(G320x200x256);
	videomem = vga_getgraphmem();
        draw_background();
	do_balls(TRUE);
	while(!stop) {
		if (kbhit()) keybuf = getch();
		if (keybuf=='4') 
			dx--;
		if (keybuf=='6')
			dx++;
		if (keybuf=='8')
			dy--;
		if (keybuf=='2')
			dy++;
		if (keybuf == 'q' || keybuf == 'Q' || keybuf == 'x' || 
keybuf == 'X')
			stop = TRUE;
		curx+=dx;
		cury+=dy;
		if (curx>32 || curx<0) curx-=dx;
		if (cury>24 || cury<0) cury-=dy;
		dx = dy = 0;
		keybuf = NULL;
		draw_background();
		do_balls(FALSE);
//->This is where gl_putbox goes gl_putboxpart(0, 0, 320, 200, 320, 200, 
buffer, 0, 0);
                rawblt(curx, cury, videomem, buffer, 320, 200);
	}
		
	vga_setmode(TEXT);
	return; 
}
/*End*/
I'm awfully sorry that it's so sloppy but I didn't anticipate this
kind of problem as it was intended as nothing more than a simple
demo to see what I could do with it.

gl_putbox() is the built-in blitting function, but I can't seem
to get it to work.  This is the error message it produces when I 
compile it with gl_putbox() in it:
D:\DJGPP\CODE\SVGALIB>gcc -Wall fodder.c -o fodder -lvga -lvgagl
fodder.c: In function `do_balls':
fodder.c:96: warning: unused variable `j'
fodder.c: In function `main':
fodder.c:125: warning: unused variable `j'
fodder.c:124: warning: unused variable `i'
grlib.c(.text+0x11ee): undefined reference to `vga_copytoplanar256'
grlib.c(.text+0x1281): undefined reference to `vga_copytoplanar16'
grlib.c(.text+0x12da): undefined reference to `vga_copytoplanar16'
grlib.c(.text+0x1341): undefined reference to `vga_copytoplanar16'
driver.c(.text+0x328): undefined reference to `vga_accel'
driver.c(.text+0x333): undefined reference to `vga_accel'
driver.c(.text+0xbef): undefined reference to `vga_accel'
driver.c(.text+0x3406): undefined reference to `vga_copytoplanar256'
...And the library is compiled with everything, so I can't
fathom the problem.  Any ideas at all?  I'm completely stumped.
This slowdown is there a lot without the balls too, so I
think it's rawblt(), which is used to transfer the virtual screen
to the video pointer.  Also, is there any way to assure it runs
in mode 13h and would run on any other VGA system?
Any help you can give me on any of this would be greatly appreciated.
Back to your regularly scheduled news broadcast...

-Mike

- Raw text -


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