From: Consalus Newsgroups: comp.os.msdos.djgpp Subject: [Q]: Why is my djgpp program in C rebooting my machine? Date: Thu, 20 Nov 1997 18:09:41 -0600 Organization: Planet Digital Network Technologies Lines: 163 Message-ID: <3474D145.5BE9A39C@pdnt.com> Reply-To: consalus AT pdnt DOT com NNTP-Posting-Host: ppp46-ts1.pdnt.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Okay, here is my problem. I am making a very simple program in djgpp. I am making a happy little pixel that avoids obstacles on the screen and eventually makes it to its destination point with as little moves as possible. I started off by making the dot moves to the destination. It compiled nicely, but when it runs, It reboots my machine. I guess I will have to post the whole source code.. it can also be found at http://users.pdnt.com/~consalus/C/ai.c #include #include #include #include #include #include #define sgn(x) ((x<0)?-1:((x>0)?1:0)) #define VGA_MODE 0 #define TEXT_MODE 1 typedef struct coord { int x; int y; }; struct coord ailoc; void set_vgamode(int whatmode) { if (whatmode == 0) { union REGS regs; regs.h.ah = 0x00; regs.h.al = 0x13; int86(0x10, ®s, ®s); } if (whatmode == 1) { union REGS regs; regs.h.ah = 0x00; regs.h.al = 0x03; int86(0x10, ®s, ®s); } } void putpixel(int x, int y, unsigned char color) { _farpokeb(_dos_ds, 0xa0000 + (y << 8) + (y << 6) + x, color); } int get_pixel(int x, int y) { int thing; thing = _farpeekb(_dos_ds, 0xa0000 + (y << 8) + (y << 6) + x); return thing; } void moveguy(int howmanyx, int howmanyy) { int bleah, bleah2; putpixel(ailoc.x + howmanyx, ailoc.y + howmanyy, 15); bleah = ailoc.x + howmanyx; bleah2 = ailoc.y + howmanyy; putpixel(ailoc.x, ailoc.y, 0); ailoc.x = bleah; ailoc.y = bleah2; } void line(int x1, int y1, int x2, int y2, char color) { short int dx, dy, sdx, sdy, x, y, px, py; dx = x2 - x1; dy = y2 - y1; sdx = (dx < 0) ? -1 : 1; sdy = (dy < 0) ? -1 : 1; dx = sdx * dx + 1; dy = sdy * dy + 1; x = y = 0; px = x1; py = y1; if (dx >= dy) { for (x = 0; x < dx; x++) { _farpokeb(_dos_ds, 0xa0000 + (py << 8) + (py << 6) + px, color); y += dy; if (y >= dx) { y -= dx; py += sdy; } px += sdx; } } else { for (y = 0; y < dy; y++) { _farpokeb(_dos_ds, 0xa0000 + (py << 8) + (py << 6) + px, color); x += dx; if (x >= dy) { x -= dy; px += sdx; } py += sdy; } } } void main(void) { struct coord destloc; struct coord distance; int counter; set_vgamode(VGA_MODE); line(1, 1, 319, 1, 15); line(1, 1, 1, 199, 15); line(319, 199, 319, 1, 15); line(319, 199, 1, 199, 15); destloc.x = 300; destloc.y = 100; ailoc.x = 10; ailoc.y = 10; counter = 0; putpixel(destloc.x, destloc.y, 1); while (1) { distance.x = destloc.x - ailoc.x; distance.y = destloc.y - ailoc.y; if (distance.x < distance.y) { moveguy(1, 0); continue; } else if (distance.x == distance.y) { set_vgamode(TEXT_MODE); printf("\n\n Yeah! It took %d turns to get to the destination.", counter); exit(0); } else { moveguy(0, 1); continue; } delay(3); } getch(); set_vgamode(TEXT_MODE); }