/* NMGRFX v.2.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 ... ÚÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ ³ Scan Codes ³\ ÀÄÄÄÄÄÄÄÄÄÄÄÄÙ\ The following is a list of all the regular key scan codes in numerical order: Scan Scan Code Key Code Key ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ 1 ESC 44 Z 2 1 45 X 3 2 46 C 4 3 47 V 5 4 48 B 6 5 49 N 7 6 50 M 8 7 51 , < 9 8 52 . > 10 9 53 / ? 11 0 54 RIGHT SHIFT 12 - _ 55 * (KEYPAD) 13 = + 56 LEFT ALT 14 BACKSPACE 57 SPACEBAR 15 TAB 58 CAPSLOCK 16 Q 59 F1 17 W 60 F2 18 E 61 F3 19 R 62 F4 20 T 63 F5 21 Y 64 F6 22 U 65 F7 23 I 66 F8 24 O 67 F9 25 P 68 F10 26 [ { 69 NUMLOCK (KEYPAD) 27 ] } 70 SCROLL LOCK 28 ENTER (RETURN) 71 7 HOME (KEYPAD) 29 LEFT CONTROL 72 8 UP (KEYPAD) 30 A 73 9 PGUP (KEYPAD) 31 S 74 - (KEYPAD) 32 D 75 4 LEFT (KEYPAD) 33 F 76 5 (KEYPAD) 34 G 77 6 RIGHT (KEYPAD) 35 H 78 + (KEYPAD) 36 J 79 1 END (KEYPAD) 37 K 80 2 DOWN (KEYPAD) 38 L 81 3 PGDN (KEYPAD) 39 ; : 82 0 INSERT (KEYPAD) 40 ' " 83 . DEL (KEYPAD) 41 ` ~ 87 F11 42 LEFT SHIFT 88 F12 The following is a list of all the extended key scan codes in numerical order: Scan Scan Code Key Code Key ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ 28 ENTER (KEYPAD) 75 LEFT (NOT KEYPAD) 29 RIGHT CONTROL 77 RIGHT (NOT KEYPAD) 42 PRINT SCREEN (SEE TEXT) 79 END (NOT KEYPAD) 53 / (KEYPAD) 80 DOWN (NOT KEYPAD) 55 PRINT SCREEN (SEE TEXT) 81 PAGE DOWN (NOT KEYPAD) 56 RIGHT ALT 82 INSERT (NOT KEYPAD) 71 HOME (NOT KEYPAD) 83 DELETE (NOT KEYPAD) 72 UP (NOT KEYPAD) 111 MACRO 73 PAGE UP (NOT KEYPAD) 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 #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, KeyI, KeyK, KeyJ, KeyL, Key3, Key0, Key1, KeyDel, 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