aboutsummaryrefslogtreecommitdiff
path: root/moustest.c
diff options
context:
space:
mode:
authorJavier <dev.git@javispedro.com>2024-07-07 18:55:08 +0200
committerJavier <dev.git@javispedro.com>2024-07-07 19:04:42 +0200
commit0af940aae4938289e7a4a11354ef9a6db4ee5140 (patch)
treed39ab5b5fd5c2729e8812594cd39e4a49216a4e9 /moustest.c
parent347e5022e7f93abd1bddd361b843f7c63325904d (diff)
downloadvbados-0af940aae4938289e7a4a11354ef9a6db4ee5140.tar.gz
vbados-0af940aae4938289e7a4a11354ef9a6db4ee5140.zip
moustest: do not run graphics/cio code from interrupt
Diffstat (limited to 'moustest.c')
-rw-r--r--moustest.c223
1 files changed, 147 insertions, 76 deletions
diff --git a/moustest.c b/moustest.c
index 81a9fd9..5d43e54 100644
--- a/moustest.c
+++ b/moustest.c
@@ -9,6 +9,7 @@
#include <graph.h>
#include "int33.h"
+#include "int16kbd.h"
#include "utils.h"
#include "dlog.h"
@@ -28,10 +29,25 @@ enum T_COLOR {
bool main_exiting = false;
+/// Do not automatically reset the mouse driver
+bool args_no_reset = false;
+/// Do not query for wheel features
+bool args_no_wheel = false;
+
uint16_t driver_caps;
uint16_t num_buttons;
uint16_t num_wheels;
+struct mouseevent {
+ uint16_t events;
+ uint8_t buttons;
+ int16_t x;
+ int16_t y;
+ int8_t z;
+ int16_t delta_x;
+ int16_t delta_y;
+} lastmouseevent;
+
struct videoconfig vidconf;
bool vidconf_is_graphics, vidconf_is_color;
@@ -154,6 +170,8 @@ void gui_init()
_getvideoconfig(&vidconf);
_gettextsettings(&txtconf);
+ _clearscreen(_GCLEARSCREEN);
+
switch (vidconf.mode) {
case _TEXTBW40:
case _TEXTC40:
@@ -487,23 +505,99 @@ void modelist_show_modal()
void __far mouse_callback(uint16_t events, uint16_t buttons, int16_t x, int16_t y, int16_t delta_x, int16_t delta_y)
#pragma aux (INT33_CB) mouse_callback
{
- int8_t z = buttons >> 8;
-
- (void) delta_x;
- (void) delta_y;
+ _disable();
-#if 0
+#if 1
dprintf(DPREFIX "mouse_callback events=0x%x buttons=0x%x x=%d y=%d dx=%d dy=%d\n",
events, buttons, x, y, delta_x, delta_y);
#endif
- // Update the status bar
- _disable();
+ lastmouseevent.events = events;
+ lastmouseevent.buttons = buttons & 0xFFU;
+ lastmouseevent.x = x;
+ lastmouseevent.y = y;
+ lastmouseevent.z = buttons >> 8;
+ lastmouseevent.delta_x = delta_x;
+ lastmouseevent.delta_y = delta_y;
+
+ // Doing this to wake up getch()
+ int16_store_keystroke(1, 0);
+
+ _enable();
+}
+
+bool mouse_reset()
+{
+ if (!int33_reset_get_buttons(&num_buttons)) {
+ puts("Mouse not installed");
+ return false;
+ }
+
+ if (!args_no_wheel) {
+ driver_caps = int33_get_capabilities();
+ num_wheels = 0;
+ if (driver_caps & INT33_CAPABILITY_WHEEL_API) {
+ num_wheels = 1;
+ }
+ if (driver_caps & INT33_CAPABILITY_WHEEL2_API) {
+ num_wheels = 2;
+ }
+ }
+
+ int33_set_event_handler(INT33_EVENT_MASK_ALL, mouse_callback);
+
+ return true;
+}
+
+void mouse_report()
+{
+ const char __far *fstr;
+
+ if (driver_caps != 0) {
+ console_printf("Driver capabilities bits: 0x%x %s %s\n", driver_caps,
+ driver_caps & INT33_CAPABILITY_WHEEL_API ? "<wheel API>" : "",
+ driver_caps & INT33_CAPABILITY_WHEEL2_API ? "<wheel API v2>" : "");
+ }
+
+ fstr = int33_get_version_string();
+ if (fstr) {
+ console_printf("Driver version string: %Fs\n", fstr);
+ }
+
+ console_printf("Number of buttons: %u\n", num_buttons);
+ console_printf("Number of wheels: %u\n", num_wheels);
+}
+
+void mouse_quit()
+{
+ int33_reset();
+}
+
+void mouse_debug()
+{
+ // Add test code here
+}
+
+void status_report_last_event()
+{
+ uint16_t events = lastmouseevent.events;
+ uint8_t buttons = lastmouseevent.buttons;
+ int x = lastmouseevent.x;
+ int y = lastmouseevent.y;
+ int z = lastmouseevent.z;
+ lastmouseevent.events = 0;
+
+ if (!events) {
+ return;
+ }
+
+ // Update the status bar message
gui_draw_status();
gui_printf(GUI_COLOR_BAR, " %3s %4u , %4u |",
events & INT33_EVENT_MASK_ABSOLUTE ? "ABS" : "REL", x, y);
+
if (num_buttons <= 2) {
gui_printf(GUI_COLOR_BAR, " [%5s] [%5s] ",
buttons & INT33_BUTTON_MASK_LEFT ? "LEFT" : "",
@@ -530,7 +624,7 @@ void __far mouse_callback(uint16_t events, uint16_t buttons, int16_t x, int16_t
gui_printf(GUI_COLOR_BAR, "| %c", c);
}
- // Log the events
+ // Log the events to the console
if (events & INT33_EVENT_MASK_LEFT_BUTTON_PRESSED) {
console_printf("Left button pressed\n");
}
@@ -568,77 +662,31 @@ void __far mouse_callback(uint16_t events, uint16_t buttons, int16_t x, int16_t
if (events & INT33_EVENT_MASK_HORIZ_WHEEL_MOVEMENT) {
console_printf("Wheel %s %d\n", z > 0 ? "right" : "left", z);
}
-
- _enable();
-}
-
-bool mouse_reset()
-{
- if (!int33_reset_get_buttons(&num_buttons)) {
- puts("Mouse not installed");
- return false;
- }
-
- driver_caps = int33_get_capabilities();
- num_wheels = 0;
- if (driver_caps & INT33_CAPABILITY_WHEEL_API) {
- num_wheels = 1;
- }
- if (driver_caps & INT33_CAPABILITY_WHEEL2_API) {
- num_wheels = 2;
- }
-
- int33_set_event_handler(INT33_EVENT_MASK_ALL, mouse_callback);
-
- return true;
-}
-
-void mouse_report()
-{
- const char __far *fstr;
-
- if (driver_caps != 0) {
- console_printf("Driver capabilities bits: 0x%x %s %s\n", driver_caps,
- driver_caps & INT33_CAPABILITY_WHEEL_API ? "<wheel API>" : "",
- driver_caps & INT33_CAPABILITY_WHEEL2_API ? "<wheel API v2>" : "");
- }
-
- fstr = int33_get_version_string();
- if (fstr) {
- console_printf("Driver version string: %Fs\n", fstr);
- }
-
- console_printf("Number of buttons: %u\n", num_buttons);
- console_printf("Number of wheels: %u\n", num_wheels);
-
-}
-
-void mouse_quit()
-{
- int33_reset();
-}
-
-void mouse_debug()
-{
- // Add test code here
}
int main(int argc, const char *argv[])
{
- int c;
-
- (void)argc;
- (void)argv;
-
- if (!mouse_reset()) {
- return EXIT_FAILURE;
+ int i;
+ for (i = 1; i < argc; i++) {
+ if (stricmp(argv[i], "/nr") == 0) {
+ args_no_reset = true;
+ } else if (stricmp(argv[i], "/nw") == 0) {
+ args_no_wheel = true;
+ }
}
gui_init();
- mouse_report();
-
- int33_show_cursor();
+ if (!args_no_reset) {
+ if (mouse_reset()) {
+ mouse_report();
+ int33_show_cursor();
+ } else {
+ console_printf("Mouse driver not found or failed to reset\n");
+ }
+ } else {
+ console_printf("Use r, s to reset and show mouse pointer\n");
+ }
while (!main_exiting) {
int c = getch();
@@ -648,17 +696,32 @@ int main(int argc, const char *argv[])
if (c == 0) {
// Extended key
c = getch();
- console_printf("Keyboard extended key %d\n", c);
+
+ dprintf(DPREFIX "getch returns extended %d\n", c);
+
+ switch (c) {
+ case 1: // Internal: mouse event
+ status_report_last_event();
+ break;
+ default:
+ console_printf("Keyboard extended key %d\n", c);
+ break;
+ }
} else {
console_printf("Keyboard key %d '%c'\n", c, c);
+
switch (c) {
case 27: // Escape
main_exiting = true;
break;
case 'r':
- console_printf("Reset mouse driver\n");
- mouse_reset();
- mouse_report();
+ console_printf("Reset mouse\n");
+ if (mouse_reset()) {
+ mouse_report();
+ console_printf("Mouse reset complete\n");
+ } else {
+ console_printf("Mouse reset failed\n");
+ }
break;
case 's':
int33_show_cursor();
@@ -669,7 +732,15 @@ int main(int argc, const char *argv[])
case 'm':
modelist_show_modal();
gui_init();
- mouse_reset();
+ if (!args_no_reset) {
+ if (mouse_reset()) {
+ mouse_report();
+ int33_show_cursor();
+ console_printf("Mouse reset complete\n");
+ } else {
+ console_printf("Mouse reset failed\n");
+ }
+ }
break;
case 'd':
mouse_debug();