add keyboard and mouse tests

This commit is contained in:
Gered 2018-04-30 20:53:07 -04:00
parent 8a61d6e674
commit 4a7beacbdc
8 changed files with 170 additions and 7 deletions

28
TEST/HELPERS.C Normal file
View file

@ -0,0 +1,28 @@
#include "helpers.h"
#include "dgl.h"
#include <conio.h>
#include <dos.h>
#include <stdio.h>
void clrscr(unsigned char attr) {
union REGS r;
r.h.ah = 6;
r.h.al = 0; // 0 = clear
r.h.ch = 0; // y1
r.h.cl = 0; // x1
r.h.dh = 24; // y2
r.h.dl = 79; // x2
r.h.bh = attr; // attr (char + color) to fill with
int386(0x10, &r, &r);
gotoxy(0, 0);
}
void gotoxy(int x, int y) {
union REGS r;
r.h.ah = 2;
r.h.bh = 0;
r.h.dh = y;
r.h.dl = x;
int386(0x10, &r, &r);
}

View file

@ -21,3 +21,6 @@ extern void _breakpoint();
#endif
void clrscr(unsigned char attr);
void gotoxy(int x, int y);

63
TEST/KBRD.C Normal file
View file

@ -0,0 +1,63 @@
#include "kbrd.h"
#include "dgl.h"
#include <dos.h>
#include <stdio.h>
#include "helpers.h"
void display_key_states(void) {
int x, y;
gotoxy(0, 2);
for (y = 0; y < 8; ++y) {
for (x = 0; x < 16; ++x) {
unsigned char pressed;
pressed = keys[y * 16 + x] > 0;
printf("%d", pressed);
}
printf("\n");
}
}
void test_keyboard(void) {
boolean result;
KEY k;
clrscr(0);
ASSERT(keyboard_is_initialized() == FALSE);
result = keyboard_init();
ASSERT(result == TRUE);
ASSERT(keyboard_is_initialized() == TRUE);
printf("Keyboard state\n");
display_key_states();
while (!keys[1]) {
display_key_states();
}
// delay to give enough time for key to be released before next ...
delay(500);
gotoxy(0, 18);
printf("Press any key ...\n");
k = keyboard_read_key();
printf("Pressed key %d\n", k);
// same thing, giving enough time for key to be released ...
delay(500);
printf("Press that same key again ...\n");
keyboard_wait_for_key(k);
result = keyboard_shutdown();
ASSERT(result == TRUE);
ASSERT(keyboard_is_initialized() == FALSE);
gotoxy(0, 23);
printf("Press a key to continue...\n");
getch();
}

7
TEST/KBRD.H Normal file
View file

@ -0,0 +1,7 @@
#ifndef DGL_TEST_KBRD_H_INCLUDED
#define DGL_TEST_KBRD_H_INCLUDED
void test_keyboard(void);
#endif

View file

@ -4,7 +4,10 @@ target_name = test
object_files = blit.obj &
fixed.obj &
helpers.obj &
kbrd.obj &
line.obj &
mouse.obj &
pal.obj &
pcx.obj &
pset.obj &

48
TEST/MOUSE.C Normal file
View file

@ -0,0 +1,48 @@
#include "mouse.h"
#include "dgl.h"
#include <dos.h>
#include <stdio.h>
#include "helpers.h"
void test_mouse(void) {
boolean result;
clrscr(0);
ASSERT(mouse_is_initialized() == FALSE);
result = mouse_init();
ASSERT(result == TRUE);
ASSERT(mouse_is_initialized() == TRUE);
// this may seem a little weird to check for a mouse AFTER init, but
// it's the init call that determines if a mouse is present :)
if (mouse_is_present()) {
printf("Mouse detected. Showing mouse state.\n");
mouse_show();
while (!kbhit()) {
gotoxy(0, 2);
printf("X: %03d\n", mouse_x);
printf("Y: %03d\n", mouse_y);
printf("Buttons: %03d\n", mouse_buttons);
}
mouse_hide();
} else {
printf("Mouse not detected. Skipping.\n");
}
// need to close down the mouse subsystem even if one is not present
result = mouse_shutdown();
ASSERT(result == TRUE);
ASSERT(mouse_is_initialized() == FALSE);
gotoxy(0, 23);
printf("Press a key to continue...\n");
getch();
}

7
TEST/MOUSE.H Normal file
View file

@ -0,0 +1,7 @@
#ifndef DGL_TEST_MOUSE_H_INCLUDED
#define DGL_TEST_MOUSE_H_INCLUDED
void test_mouse(void);
#endif

View file

@ -3,16 +3,18 @@
#include "dgl.h"
#include "helpers.h"
#include "fixed.h"
#include "vector2.h"
#include "surface.h"
#include "pset.h"
#include "line.h"
#include "rect.h"
#include "blit.h"
#include "text.h"
#include "fixed.h"
#include "kbrd.h"
#include "line.h"
#include "mouse.h"
#include "pal.h"
#include "pcx.h"
#include "pset.h"
#include "rect.h"
#include "surface.h"
#include "text.h"
#include "vector2.h"
SURFACE *backbuffer = NULL;
@ -39,6 +41,8 @@ int main(void) {
ASSERT(backbuffer != NULL);
ASSERT(backbuffer->width == 320 && backbuffer->height == 200);
test_keyboard();
test_mouse();
test_fixed();
test_vector2i();
test_vector2f();