/* NMGRFX v.1.01 (c) 2002. Nick Meyer Very simple and easy to use MODE13H graphics library in Turbo C++. DESCRIPTION OF CAPABILITIES: -mode13h support -double buffering -direct input -drawing functions HOW TO USE MODE13H: -call setmode(MODE13H) at beggining of program -call setmode(TEXTMODE) at end of program DOUBLE BUFFERING: -call setupbuf() at beggining -call clrbuf() to clear buffer -call showbuf() to show buffer -all drawing functions draw to buffer DIRECT INPUT: -all key variables are either true or false. true=key pressed down. false=key up. -test for key like this: if (KEY_VARIABLE) do_something(); key variables: CursorUp Up Arrow CursorDown Down Arrow CursorLeft ... CursorRight ... KeyA 'A' key KeyS 'S' key KeyW ... KeyD ... DRAWING FUNCTIONS: -just look at the prototypes for drawing. Same as in normal BGI graphics, but with 'color' parameter in function call. */ //=========INCLUDES===================== #include #include #include #include #include #include #include #include #include //=========MODE DECS================ #define MODE13H 0x13 #define TEXTMODE 0x03 //========COLORS================= #define WHITE 15 #define GRAY 7 #define DARKGRAY 8 #define BLACK 0 #define BROWN 6 #define GREEN 2 #define LIGHTGREEN 10 #define ORANGE 66 #define YELLOW 14 #define RED 4 #define BLUE 1 #define LIGHTBLUE 3 #define PURPLE 5 //==========KEYS==================== #define LEFT_ARROW 75 #define UP_ARROW 72 #define RIGHT_ARROW 77 #define DOWN_ARROW 80 //========MUSIX======================= #define nA 100 #define nAs 200 #define nB 300 #define nBs 400 #define nC 500 #define nCs 600 #define nD 700 #define nDs 800 #define nE 900 #define nEs 1000 #define nF 1100 #define nFs 1200 #define nG 1300 #define nGs 1400 //==========PROTOTYPES============================== char far *video_buffer = (char far *)0xA0000000L; char far *double_buffer; char far *temp; #include #ifdef __DJGPP #include #include #endif #ifdef __cplusplus #include #include #endif //Key status indicators int CursorUp, CursorDown, CursorLeft, CursorRight, KeyW, KeyS, KeyA, KeyD, KeyF, KeyP, KeyEnter, KeyAlt, KeyRShift, KeyRCtrl, KeyEscape, Spacebar; //Pointer to original keyboard handler #ifdef __DJGPP //and for DJGPP also to the new handler... _go32_dpmi_seginfo BIOSHandler, MyHandler; #else #ifdef __cplusplus void interrupt (*BIOSHandler)(...); #else void interrupt (*BIOSHandler)(); #endif #endif int getkeyval(); int randint(int low, int high); void setmode(int mode); void setupbuf(); void disablebuf(); void clrbuf(); void showbuf(); void cleardevice(); void fillbuf(unsigned char color); void setupkbd(); void restorekbd(); void putpixel(int x,int y, unsigned char color); unsigned char getpixel(int x,int y); void putbigpixel(int x,int y, unsigned char color); void horiz(float x1,float y1,float x2,unsigned char color); void horiz(float x1,float y1,float x2,float width,unsigned char color); void vert(float x1,float y1,float y2,unsigned char color); void vert(float x1,float y1,float y2,float width,unsigned char color); void line(float x1,float y1,float x2,float y2, unsigned char color); void line(float x1,float y1,float x2,float y2,float width,unsigned char color); void triangle(float x1,float y1,float x2,float y2, float x3, float y3, unsigned char color); void circle(float x,float y, float radius, unsigned char color); //==========DRAWING FUNCTIONS=================================== void line(float x1,float y1,float x2,float y2, unsigned char color) { if (abs(y1 - y2) > abs(x1 - x2)) { // ! (0 < the magnitude of the slope < 1) // make the first point the bottom-most point if (y1 > y2) { int temp; temp = x1; x1 = x2; x2 = temp; temp = y1; y1 = y2; y2 = temp; } // make the algorithm work for negative slopes int slopeSign = 1; if (x2 < x1) slopeSign = -1; int dx = x2 - x1, dy = y2 - y1; int d = 2 * dx - dy; int incrE = 2 * dx * slopeSign, incrNE = 2 * ((dx * slopeSign) - dy); int x = x1, y = y1; putpixel(x,y,color); while (y < y2) { if (d < 0) { d += incrE; y++; } else { d += incrNE; y++; x += slopeSign; } putpixel(x,y,color); } } // 0 < the magnitude of the slope < 1 else { // make the first point the left-most point if (x1 > x2) { int temp; temp = x1; x1 = x2; x2 = temp; temp = y1; y1 = y2; y2 = temp; } // make the algorithm work for negative slopes int slopeSign = 1; if (y2 < y1) slopeSign = -1; int dx = x2 - x1, dy = y2 - y1; int d = 2 * dy - dx; int incrE = 2 * dy * slopeSign, incrNE = 2 * ((dy * slopeSign) - dx); int x = x1, y = y1; putpixel(x,y,color); while (x < x2) { if (d < 0) { d += incrE; x++; } else { d += incrNE; x++; y += slopeSign; } putpixel(x,y,color); } } } void line(float x1,float y1,float x2,float y2,float width,unsigned char color) { float hw = width / 2; for (int n=-hw;n<=hw;n++) line(x1+n,y1,x2+n,y2,color); } void horiz(float x1,float y1,float x2,unsigned char color) { for (int x=x1;x= columns[tmpcol].speed) { for (int s=25;s>0;s--) { screen[s*80+tmpcol] = screen[(s-1)*80+tmpcol]; screen[(s-1)*80] = 0x0000; } columns[tmpcol].scount = 0; // draw new character at top tchar = random(255)+1; if (screen[tmpcol+80] != 0x0000) { if (random(100) < 80) { // if (random(5)<4) screen[tmpcol] = 0x0200 | tchar; // else screen[tmpcol] = 0x0A00 | tchar; screen[tmpcol] = 0x0200 | tchar; } else screen[tmpcol] = 0x0000; } else { if (random(100) > 93) { // if (random(5)<4) screen[tmpcol] = 0x0200 | tchar; // else screen[tmpcol] = 0x0A00 | tchar; screen[tmpcol] = 0xA00 | tchar; } } } } for (int m=0;m<80;m++) columns[m].scount++; } for (int n=0;n<21;n++) { screen[11*80+31+n] = 0x0200 | str1[n]; screen[12*80+31+n] = 0x0200 | str2[n]; screen[13*80+31+n] = 0x0200 | str3[n]; } KeyEscape = 0; while(!KeyEscape) { tchar = random(255)+1; screen[random(2001)] = 0x0100 | tchar; tchar = random(255)+1; screen[random(2001)] = 0x0900 | tchar; delay(10); } restorekbd(); return (0); } void clrscreen() { _fmemset(screen,0x0000,2000); } void speedup() { for (int n=0;n<80;n++) columns[n].speed-=50; CursorDown = 0; } void slowdown() { for (int n=0;n<80;n++) columns[n].speed+=50; CursorUp = 0; }