/** * Library for GameDev on DOS * * Alexander Popov * Version: 0.0.0 * * LICENSE: * This is free and unencumbered software released into the public domain. * Anyone is free to copy, modify, publish, use, compile, sell, or * distribute this software, either in source code form or as a compiled * binary, for any purpose, commercial or non-commercial, and by any * means. * * In jurisdictions that recognize copyright laws, the author or authors * of this software dedicate any and all copyright interest in the * software to the public domain. We make this dedication for the benefit * of the public at large and to the detriment of our heirs and * successors. We intend this dedication to be an overt act of * relinquishment in perpetuity of all present and future rights to this * software under copyright law. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * For more information, please refer to * * THANKS: * David Brackeen - http://www.brackeen.com/vga/basics.html * Stanislav Sokolov - https://stanislavs.org/helppc/int_33-3.html * Team EQA - https://www.equestionanswers.com/c/c-int33-mouse-service.php */ #ifndef GDOS_H_ #define GDOS_H_ #include #include /* ... */ #define GD_TRUE 1 /* bool true */ #define GD_FALSE 0 /* bool false */ #define VIDEO_INT 0x10 /* BIOS video interrupt */ #define MOUSE_INTERRUPT 0x33 /* BIOS mouse interrupt */ #define WRITE_DOT 0x0C /* BIOS func to plot a pixel */ #define SET_MODE 0x00 /* BIOS func to set the video mode */ #define TEXT_MODE 0x03 /* 80x25 text mode */ #define VGA_4_COLOR_MODE 0x04 /* 320x200 4-color graphics mode */ #define VGA_MONO_SM_MODE 0x05 /* 320x200 monochrome graphics mode */ #define VGA_MONO_LG_MODE 0x06 /* 640x200 monochrome graphics mode */ #define VGA_256_COLOR_MODE 0x13 /* 320x200 graphics mode */ #define SCREEN_WIDTH 320 /* width in pixels of mode 0x13 */ #define SCREEN_HEIGHT 200 /* height in pixels of mode 0x13 */ #define GD_DRAW_FAST 1 #define GD_DRAW_SLOW 0 typedef unsigned char byte; byte *VGA=(byte *)0xA0000000L; /* this points to video memory */ /* KEY CODES */ #define key_ESC 27 /* ESCAPE key */ #define key_A 65 /* A key */ #define key_B 66 /* B key */ #define key_C 67 /* C key */ #define key_D 68 /* D key */ #define key_E 69 /* E key */ #define key_F 70 /* F key */ #define key_G 71 /* G key */ #define key_H 72 /* H key */ #define key_I 73 /* I key */ #define key_J 74 /* J key */ #define key_K 75 /* K key */ #define key_L 76 /* L key */ #define key_M 77 /* M key */ #define key_N 78 /* N key */ #define key_O 79 /* O key */ #define key_P 80 /* P key */ #define key_Q 81 /* Q key */ #define key_R 82 /* R key */ #define key_S 83 /* S key */ #define key_T 84 /* T key */ #define key_U 85 /* U key */ #define key_V 86 /* V key */ #define key_W 87 /* W key */ #define key_X 88 /* X key */ #define key_Y 89 /* Y key */ #define key_Z 90 /* Z key */ #define key_a 97 /* a key */ #define key_b 98 /* b key */ #define key_c 99 /* c key */ #define key_d 100 /* d key */ #define key_e 101 /* e key */ #define key_f 102 /* f key */ #define key_g 103 /* g key */ #define key_h 104 /* h key */ #define key_i 105 /* i key */ #define key_j 106 /* j key */ #define key_k 107 /* k key */ #define key_l 108 /* l key */ #define key_m 109 /* m key */ #define key_n 110 /* n key */ #define key_o 111 /* o key */ #define key_p 112 /* p key */ #define key_q 113 /* q key */ #define key_r 114 /* r key */ #define key_s 115 /* s key */ #define key_t 116 /* t key */ #define key_u 117 /* u key */ #define key_v 118 /* v key */ #define key_w 119 /* w key */ #define key_x 120 /* x key */ #define key_y 121 /* y key */ #define key_z 122 /* z key */ /** * gd_set_mode(byte mode) * Sets the video mode */ void gd_set_mode(byte mode) { union REGS regs; regs.h.ah = SET_MODE; regs.h.al = mode; int86(VIDEO_INT, ®s, ®s); } /** * gd_draw_pixel(int x, int y, byte color, int draw_mode) * Draw pixel on VGA */ void gd_draw_pixel(int x, int y, byte color, int draw_mode) { union REGS regs; /* draw pixel as fast mode */ if (draw_mode == 1) { VGA[y*SCREEN_WIDTH+x]=color; } /* draw pixel as slow mode */ else { regs.h.ah = WRITE_DOT; regs.h.al = color; regs.x.cx = x; regs.x.dx = y; int86(VIDEO_INT, ®s, ®s); } } /** * gd_get_kb(int *key) * Gets the ASCII code of the pressed key from the keyboard */ void gd_get_kb(int *key) { if (kbhit()) { *key = getch(); } } /** * gd_detect_mouse(void) * Return mouse support/available */ int gd_detect_mouse(void) { union REGS in, out; in.x.ax = 0; int86(MOUSE_INTERRUPT, &in, &out); /* Mouse support not available */ if (out.x.ax != 0) { return GD_TRUE; } else { return GD_FALSE; } } /** * gd_show_mouse(void) * Show mouse cursor */ int gd_show_mouse(void) { union REGS in, out; in.x.ax = 1; int86(MOUSE_INTERRUPT, &in, &out); return GD_TRUE; } /** * gd_hide_mouse(void) * Hide mouse cursor */ int gd_hide_mouse(void) { union REGS in, out; in.x.ax = 2; int86(MOUSE_INTERRUPT, &in, &out); return GD_TRUE; } /** * gd_get_mouse_status(int *x, int *y, int *click) * Gets mouse position by X,Y and mouse button click status */ void gd_get_mouse_status(int *x, int *y, int *click) { union REGS in, out; in.x.ax = 3; int86(MOUSE_INTERRUPT, &in, &out); /** * Click is the integer variable which returns the values * 1 - Left mouse button * 2 - Right mouse button * 3 - Middle mouse button * 4 - ... */ *click = out.x.bx; *x = out.x.cx; *y = out.x.dx; } #endif