On (06 Jun 97) Christopher Butler wrote to All...
CB> Could someone tell me whats wrong with this code?
[ ... ]
CB> GraphicsScreen::~GraphicsScreen()
CB> {
CB> asm { // Back to text mode, via ASM again
CB> mov ah,0x13
CB> int 0x10
Unless you've got a very unusual graphics card, this isn't going to get
you back to text mode...
CB> GraphicsScreen::Box(int x1,int y1,int x2,int y2,unsigned char col)
CB> {
CB> // Do basically the same as above, but with a range.
CB> // I've repeated the poke instruction here as its probably
CB> // faster.
CB> int x,y;
CB> for (x=x1;x<=x2;x++)
CB> {
CB> for (y=y1;y<=y2;y++)
CB> {
CB> pokeb(0xA000,(x+(y*320)),(char)col);
CB> }
CB> }
CB> return 0;
CB> }
This still isn't going to be any kind of speed champ with most
compilers. The problem is that you're re-creating the pointer to memory
again at each iteration of the loop. With most compilers, the following
is likely to be faster:
void GraphicsScreen::Box(int x1, int y1, int x2, int y2, unsigned char col) {
int x, y;
char _far *spot = (char far *)MK_FP(0xa000, y2*320 + x2);
int offset = 320 - (y2 - y1);
for ( y = y2 - y1; y; y--) {
for ( x = x2 - x1; x; x--)
*spot-- = col;
spot -= offset;
}
}
This also draws from bottom to top, which is often faster than top to
bottom. Even if it doesn't make any difference in accessing video
memory, it avoids comparisons each time through the loops.
CB> int main(void)
CB> {
CB> GraphicsScreen gs; // Initalize object, and set screen mode.
CB> gs.Box(100,100,200,200,0x13); // Draw a box
CB> gs.PutPixel(150,150,0x2F); // Put a pixel in the middle
CB> delete &gs; // Back to text mode
You didn't call `new' to create gs - you should NOT call `delete' to
destroy it. This was likely what was causing your GPF.
CB> return 0;
CB> }
Most likely you also want a pause between putting stuff on the screen
and going back to text mode:
int main(void) {
GraphicsScreen gs;
gs.Box(100, 100, 200, 200, 0x13);
gs.PutPixel(150, 150, 0x2f);
getch();
}
For the sake of clarity, I'll post the complete, working program in the
next message.
Later,
Jerry.
... The Universe is a figment of its own imagination.
--- PPoint 1.90
---------------
* Origin: Point Pointedly Pointless (1:128/166.5)
|