make Games 4 DOS easy

This commit is contained in:
Alexander Popov 2023-08-16 15:02:01 +03:00
commit b4fdd5a659
Signed by: iiiypuk
GPG Key ID: E47FE0AB36CD5ED6
11 changed files with 352 additions and 0 deletions

23
.editorconfig Normal file
View File

@ -0,0 +1,23 @@
root = true
[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[{*.c,*.h}]
end_of_line = crlf
indent_style = space
indent_size = 2
[*.bat]
end_of_line = crlf
[*.md]
trim_trailing_whitespace = false
[{LICENSE,READ.ME}]
end_of_line = crlf

6
.gitattributes vendored Normal file
View File

@ -0,0 +1,6 @@
* text=auto eol=lf
LICENSE eol=crlf
READ.ME eol=crlf
*.c eol=crlf
*.h eol=crlf
*.bat eol=crlf

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.EXE

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
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.

4
READ.ME Normal file
View File

@ -0,0 +1,4 @@
Library for GameDev on DOS
==========================
TBA

7
README.md Normal file
View File

@ -0,0 +1,7 @@
# Library for GameDev 🕹️ on DOS 💽
## Screenshots
![](screenshots/cursor_text.png)
![](screenshots/cursor_graphics.png)

14
build.bat Normal file
View File

@ -0,0 +1,14 @@
:: Script for build code in DOS by TCC
:: Alexander Popov <iiiypuk@fastmail.fm>
:: Clear old program
del MOUSE.EXE
:: Compile program by Turbo C
M:
cd M:/TC
TCC.EXE -eS:/MOUSE.EXE S:/mouse.c
S:
:: Run PROGRAM
MOUSE.EXE

48
examples/mouse.c Normal file
View File

@ -0,0 +1,48 @@
/**
* Example mouse work
*
* Alexander Popov <iiiypuk@fastmail.fm>
* License: Unlicense
*/
#include <stdio.h>
#include <gdos/gdos.h>
void main() {
int mouse_status;
int mouse_x, mouse_y, mouse_click;
int mouse_x_old = -1, mouse_y_old = -1, mouse_click_old = -1;
mouse_status = gd_detect_mouse();
if (mouse_status != GD_TRUE) {
printf("Mouse support not available.\n");
abort();
}
/* example: TEXT_MODE || VGA_256_COLOR_MODE */
gd_set_mode(VGA_256_COLOR_MODE);
clrscr();
gd_show_mouse();
do {
gd_get_mouse_status(&mouse_x, &mouse_y, &mouse_click);
/* when mouse status change update */
if (mouse_x != mouse_x_old ||
mouse_y != mouse_y_old ||
mouse_click != mouse_click_old)
{
mouse_x_old = mouse_x;
mouse_y_old = mouse_y;
mouse_click_old = mouse_click;
clrscr();
gotoxy(0, 0);
printf("Mouse position: X=%d, Y=%d, CLICK=%d", mouse_x, mouse_y, mouse_click);
gd_show_mouse();
}
} while (!kbhit());
gd_hide_mouse();
getch();
gd_set_mode(TEXT_MODE);
}

228
include/gdos.h Normal file
View File

@ -0,0 +1,228 @@
/**
* Library for GameDev on DOS
*
* Alexander Popov <iiiypuk@fastmail.fm>
* 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 <http://unlicense.org/>
*
* 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 <dos.h>
#include <conio.h>
/* ... */
#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, &regs, &regs);
}
/**
* 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, &regs, &regs);
}
}
/**
* 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

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

BIN
screenshots/cursor_text.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB