dos-vga-arena-shooter-game/system/mouse_io.c

63 lines
1.2 KiB
C
Raw Normal View History

2024-02-15 01:15:55 +00:00
#include <dos.h>
#include <conio.h>
2024-02-16 02:18:15 +00:00
#include <i86.h>
2024-02-15 01:15:55 +00:00
#include "mouse_io.h"
2024-02-16 02:18:15 +00:00
struct MouseStatus *_status;
2024-02-20 17:39:28 +00:00
int limitMouseArea(int sx, int sy, int ex, int ey) {
union REGS regs;
// set horiz and vert range
regs.w.ax = 0x07;
regs.w.cx = sx;
regs.w.dx = ex;
int386(MOUSE_DRIVER_INTERRUPT, &regs, &regs);
regs.w.ax = 0x08;
regs.w.cx = sy;
regs.w.dx = ey;
int386(MOUSE_DRIVER_INTERRUPT, &regs, &regs);
}
2024-02-20 11:48:12 +00:00
/**
* Ensure this is called after setting the desired video mode.
*/
2024-02-15 01:15:55 +00:00
int activateMouse(struct MouseStatus *status) {
union REGS regs;
int mouseActivated;
regs.w.ax = MOUSE_DRIVER_RESET;
int386(MOUSE_DRIVER_INTERRUPT, &regs, &regs);
mouseActivated = regs.w.ax;
if (mouseActivated) {
status->isActive = regs.w.ax;
status->buttonCount = regs.w.bx;
2024-02-20 17:39:28 +00:00
limitMouseArea(0, 0, VGA_DISPLAY_WIDTH - 1, VGA_DISPLAY_HEIGHT - 1);
2024-02-15 01:15:55 +00:00
}
2024-02-16 02:18:15 +00:00
_status = status;
2024-02-15 01:15:55 +00:00
return mouseActivated;
}
2024-02-16 02:18:15 +00:00
void readMouse() {
2024-02-15 01:15:55 +00:00
union REGS regs;
int buttonStatus;
regs.w.ax = MOUSE_DRIVER_READ_STATE;
int386(MOUSE_DRIVER_INTERRUPT, &regs, &regs);
buttonStatus = regs.w.bx;
2024-02-16 02:18:15 +00:00
_status->xPosition = regs.w.cx;
_status->yPosition = regs.w.dx;
2024-02-15 01:15:55 +00:00
2024-02-16 02:18:15 +00:00
_status->leftButtonDown = buttonStatus & 1;
_status->rightButtonDown = (buttonStatus >> 1) & 1;
2024-02-15 01:15:55 +00:00
}