Skip to content

Commit

Permalink
Merge pull request #409 from paulscottrobson/mouse_support
Browse files Browse the repository at this point in the history
USB mouse support
  • Loading branch information
paulscottrobson authored Apr 7, 2024
2 parents 122fc46 + d2da9f7 commit 3a23235
Show file tree
Hide file tree
Showing 9 changed files with 213 additions and 136 deletions.
2 changes: 1 addition & 1 deletion emulator/src/core/sys_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void DBGXRender(int *address,int showDisplay) {
}
const uint8_t *cursorImage;
uint16_t cursorX,cursorY;
if (CURGetCursorDrawInformation(&cursorImage,&cursorX,&cursorY)) {
if (MSEGetCursorDrawInformation(&cursorImage,&cursorX,&cursorY)) {
uint8_t w = 16,h = 16;
if (cursorX + 16 >= 320) w = 320-cursorX;
if (cursorY + 16 >= 240) h = 240-cursorY;
Expand Down
13 changes: 10 additions & 3 deletions firmware/common/config/miscellany/group11_mouse.inc
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,18 @@

GROUP 11 Mouse
FUNCTION 1 Move display cursor
CURSetPosition(DSPGetInt16(DCOMMAND,4),DSPGetInt16(DCOMMAND,6));
MSESetPosition(DSPGetInt16(DCOMMAND,4),DSPGetInt16(DCOMMAND,6));
DOCUMENTATION
Positions the display cursor at \Param{0,1},\Param{2,3}
Positions the display cursor at \Param{0,1},\Param{2,3}

FUNCTION 2 Set mouse display cursor on/off
CURSetVisible(DCOMMAND[4] != 0);
MSESetVisible(DCOMMAND[4] != 0);
DOCUMENTATION
Shows or hides the mouse cursor depending on the \Param{0}

FUNCTION 3 Get mouse state
MSEGetState((uint16_t*)DPARAMS, (uint16_t*)(DPARAMS + 2), DPARAMS + 4, DPARAMS + 5);
DOCUMENTATION
Returns the mouse position (screen pixel, unsigned) in x \Param{0,1} and y \Param{2,3},
buttonstate in \Param{4} (button 1 is 0x1, button 2 0x2 etc., set when pressed),
scrollwheelstate in \Param{5} as uint8 which changes according to scrolls.
2 changes: 1 addition & 1 deletion firmware/common/include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#include "interface/keyboard.h"
#include "interface/graphics.h"
#include "interface/console.h"
#include "interface/cursor.h"
#include "interface/mouse.h"
#include "interface/timer.h"
#include "interface/sound.h"
#include "interface/memory.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@
#ifndef _CURSOR_H
#define _CURSOR_H

void CURInitialise(void);
void CURSetPosition(uint16_t x,uint16_t y);
bool CURGetCursorDrawInformation(const uint8_t **pData,uint16_t *pX,uint16_t *pY);
void CURSetVisible(bool isVisible);
void MSEInitialise(void);
void MSESetPosition(uint16_t x, uint16_t y);
void MSEOffsetPosition(int8_t dx, int8_t dy);
void MSEUpdateScrollWheel(int8_t ds);
void MSEUpdateButtonState(uint8_t buttonState);
void MSEGetState(uint16_t *pX, uint16_t *pY, uint8_t *pButtonState, uint8_t *pScrollWheelState);
bool MSEGetCursorDrawInformation(const uint8_t **pData, uint16_t *pX, uint16_t *pY);
void MSESetVisible(bool isVisible);

#endif

Expand Down
67 changes: 0 additions & 67 deletions firmware/common/sources/interface/cursor.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion firmware/common/sources/interface/dispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void TIMECRITICAL(DSPSync)(void)
void DSPReset(void) {
const char bootString[] = PROMPT;
MEMInitialiseMemory(); // Set up memory, load kernel ROM
CURInitialise(); // Cursor first, before starting graphics.
MSEInitialise(); // Mouse first, before starting graphics.
GFXSetMode(0); // Initialise graphics
SPRReset(); // Reset sprites.
LOGDrawLogo(); // Draw logo
Expand Down
122 changes: 122 additions & 0 deletions firmware/common/sources/interface/mouse.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// ***************************************************************************************
// ***************************************************************************************
//
// Name : mouse.cpp
// Authors : Paul Robson ([email protected])
// Sascha Schneider ([email protected])
// Date : 3rd April 2024
// Reviewed : No
// Purpose : Mouse code.
//
// ***************************************************************************************
// ***************************************************************************************

#include "common.h"
#include "data/cursors.h"

static uint16_t xCursor, yCursor; // Current position
static bool isCursorVisible; // True if visible
static uint8_t buttonState;
static uint8_t scrollWheelState;

// ***************************************************************************************
//
// Initialise mouse
//
// ***************************************************************************************

void MSEInitialise(void) {
xCursor = yCursor = 0;
buttonState = 0;
scrollWheelState = 0;
isCursorVisible = false;
}

// ***************************************************************************************
//
// Set cursor position
//
// ***************************************************************************************

void MSESetPosition(uint16_t x, uint16_t y) {
xCursor = x;
yCursor = y;
}

void MSEOffsetPosition(int8_t dx, int8_t dy) {
if(dx < 0 && xCursor < abs(dx)) {
xCursor = 0;
} else {
xCursor += dx;
}
if(dy < 0 && yCursor < abs(dy)) {
yCursor = 0;
} else {
yCursor += dy;
}

if(xCursor > gMode.xGSize) xCursor = gMode.xGSize;
if(yCursor > gMode.yGSize) yCursor = gMode.yGSize;
}

// ***************************************************************************************
//
// Update cursor visibility
//
// ***************************************************************************************

void MSESetVisible(bool isVisible) {
isCursorVisible = isVisible;
}

// ***************************************************************************************
//
// Get cursor draw information
//
// ***************************************************************************************

bool MSEGetCursorDrawInformation(const uint8_t **pData, uint16_t *pX, uint16_t *pY) {
*pData = default_cursor_data; // Just one cursor
*pX = xCursor; *pY = yCursor; // This is top left - so crosshairs will need adjusting for example.
return isCursorVisible && xCursor < gMode.xGSize && yCursor < gMode.yGSize; // On and on screen.
}

// ***************************************************************************************
//
// Update mouse scroll wheel state
//
// ***************************************************************************************

void MSEUpdateScrollWheel(int8_t ds) {
scrollWheelState += ds;
}

// ***************************************************************************************
//
// Update mouse button state
//
// ***************************************************************************************

void MSEUpdateButtonState(uint8_t bs) {
buttonState = bs;
}

// ***************************************************************************************
//
// Get mouse position, button state and scroll wheel state
//
// ***************************************************************************************

void MSEGetState(uint16_t *pX, uint16_t *pY, uint8_t *pButtonState, uint8_t *pScrollWheelState) {
*pX = xCursor;
*pY = yCursor;
*pButtonState = buttonState;
*pScrollWheelState = scrollWheelState;
}

// ***************************************************************************************
//
// Date Revision
// ==== ========
//
// ***************************************************************************************
2 changes: 1 addition & 1 deletion firmware/sources/hardware/dvi_320x240x256.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static void __not_in_flash_func(_scanline_callback)(void) {
if (lineCounter == FRAME_HEIGHT) {
frameCounter++;
lineCounter = 0;
cursorEnabled = CURGetCursorDrawInformation(&cursorImage, // Get cursor info this frame.
cursorEnabled = MSEGetCursorDrawInformation(&cursorImage, // Get cursor info this frame.
&xCursor,&yCursor);
if (cursorEnabled) { // If enabled work out physical drawing height.
wCursor = hCursor = 16; // Could be partially drawn.
Expand Down
Loading

0 comments on commit 3a23235

Please sign in to comment.