Skip to content

Commit

Permalink
Updated translation of windows mouse coordinates to virtual joystick …
Browse files Browse the repository at this point in the history
…pot values (0-16383) to limit it to the non-border area of the display.
  • Loading branch information
ChetSimpson committed Oct 19, 2022
1 parent 8d3d5f5 commit 1d9eb42
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 14 deletions.
6 changes: 6 additions & 0 deletions DirectDrawInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,12 @@ void SetStatusBarText( char *TextBuffer,SystemState *STState)
return;
}

int GetMainWindowStatusBarHeight()
{
return StatusBarHeight;
}


void Cls(unsigned int ClsColor,SystemState *CLState)
{
CLState->ResetPending=3; //Tell Main loop to hold Emu
Expand Down
1 change: 1 addition & 0 deletions DirectDrawInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ BOOL InitDrawSurface(bool );
void UnlockScreen(SystemState *);
unsigned char LockScreen(SystemState *);
void SetStatusBarText( char *,SystemState *);
int GetMainWindowStatusBarHeight();
bool CreateDDWindow(SystemState *);
void Cls(unsigned int,SystemState *);
void DoCls(SystemState *);
Expand Down
42 changes: 29 additions & 13 deletions Vcc.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ This file is part of VCC (Virtual Color Computer).
#include "Breakpoints.h"
#include "MMUMonitor.h"

#undef min
#undef max


static HANDLE hout=NULL;

SystemState EmuState;
Expand Down Expand Up @@ -213,12 +217,10 @@ int APIENTRY WinMain(HINSTANCE hInstance,
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
unsigned int x,y; // joystick x,y values 0-3fff (0-16383)
unsigned char kb_char;
static unsigned char OEMscan=0;
int Extended;
static char ascii=0;
static RECT ClientSize;
static unsigned long Width,Height;

kb_char = (unsigned char)wParam;
Expand Down Expand Up @@ -575,19 +577,33 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
case WM_MOUSEMOVE:
if (EmuState.EmulationRunning)
{
x = LOWORD( lParam ) ;
y = HIWORD( lParam ) ;
GetClientRect(EmuState.WindowHandle,&ClientSize);
// Convert coordinates to x,y values with range 0-3fff (0-16383).
LONG scr_w = ClientSize.right-ClientSize.left;
LONG scr_h = ClientSize.bottom-ClientSize.top;
x = ((x<<14)/scr_w); if (x>65535) x=65535;
y = ((y<<14)/scr_h); if (y>65535) y=65535;
joystick(x,y);
static const float MAX_AXIS_VALUE = 16384.0f;

// Get the dimensions of the usable client area (i.e. sans status bar)
RECT clientRect;
GetClientRect(EmuState.WindowHandle, &clientRect);
clientRect.bottom -= GetMainWindowStatusBarHeight();

const auto displayDetails(GetDisplayDetails(clientRect.right, clientRect.bottom));
const int maxHorizontalPosition = clientRect.right - (displayDetails.leftBorderColumns + displayDetails.rightBorderColumns);
const int maxVerticalPosition = clientRect.bottom - (displayDetails.topBorderRows + displayDetails.bottomBorderRows);

int mouseXPosition = std::min(
std::max(0, LOWORD(lParam) - displayDetails.leftBorderColumns),
maxHorizontalPosition);
int mouseYPosition = std::min(
std::max(0, HIWORD(lParam) - displayDetails.topBorderRows),
maxVerticalPosition);

// Convert coordinates to mouseXPosition,mouseYPosition values with range 0-3fff (0-16383).
mouseXPosition = static_cast<int>(mouseXPosition * (MAX_AXIS_VALUE / maxHorizontalPosition));
mouseYPosition = static_cast<int>(mouseYPosition * (MAX_AXIS_VALUE / maxVerticalPosition));

joystick(mouseXPosition, mouseYPosition);
}

return(0);
break;
return 0;

// default:
// return DefWindowProc(hWnd, message, wParam, lParam);
}
Expand Down
28 changes: 28 additions & 0 deletions coco3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,34 @@ void SetLinesperScreen (unsigned char Lines)
}



DisplayDetails GetDisplayDetails(const int clientWidth, const int clientHeight)
{
static const float VIRTUAL_DISPLAY_HEIGHT = 250.0f;
// FIXME: This is wrong. It should reflect the actual resolution scaled based on the clientWidth (will not be correct on 640x???)
// and changes are the display width is going to match the value we load into pixelsPerLine so horizontal scaling may not be
// necessary, at least in the end.
static const float VIRTUAL_DISPLAY_WIDTH = 320.f;
const int short pixelsPerLine = GetDisplayedPixelsPerLine();
const int horizontalBorderSize = GetHorizontalBorderSize();

DisplayDetails details;

const auto horizontalScale(clientWidth / VIRTUAL_DISPLAY_WIDTH);
const auto verticalScale(clientHeight / VIRTUAL_DISPLAY_HEIGHT);

details.contentRows = static_cast<int>(LinesperScreen * verticalScale);
details.topBorderRows = static_cast<int>(TopBoarder * verticalScale);
details.bottomBorderRows = static_cast<int>(BottomBoarder * verticalScale);

details.contentColumns = static_cast<int>(pixelsPerLine * horizontalScale);
details.leftBorderColumns = static_cast<int>(horizontalBorderSize * horizontalScale);
details.rightBorderColumns = static_cast<int>(horizontalBorderSize * horizontalScale);

return details;
}


_inline int CPUCycle(void)
{
// CPU is in a halted state.
Expand Down
13 changes: 13 additions & 0 deletions coco3.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,22 @@ This file is part of VCC (Virtual Color Computer).
along with VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
*/

struct DisplayDetails
{
int contentRows = 0;
int topBorderRows = 0;
int bottomBorderRows = 0;

int contentColumns = 0;
int leftBorderColumns = 0;
int rightBorderColumns = 0;
};


//unsigned short RenderFrame (unsigned char);
void SetClockSpeed(unsigned short Cycles);
void SetLinesperScreen(unsigned char Lines);
DisplayDetails GetDisplayDetails(const int clientWidth, const int clientHeight);
void SetHorzInteruptState(unsigned char);
void SetVertInteruptState(unsigned char);
unsigned char SetSndOutMode(unsigned char);
Expand Down
10 changes: 10 additions & 0 deletions tcc1014graphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -9966,6 +9966,16 @@ int GetBytesPerRow() {
return BytesperRow;
}

int GetHorizontalBorderSize()
{
return HorzCenter / 2;
}

int GetDisplayedPixelsPerLine()
{
return PixelsperLine;
}

unsigned int GetStartOfVidram() {
return StartofVidram;
}
Expand Down
3 changes: 2 additions & 1 deletion tcc1014graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ void SetVideoBank(unsigned char);
unsigned char SetMonitorType(unsigned char );
void SetBoarderChange (unsigned char);
int GetBytesPerRow(void);

int GetHorizontalBorderSize();
int GetDisplayedPixelsPerLine();
unsigned int GetStartOfVidram();
int GetGraphicsMode();

Expand Down

0 comments on commit 1d9eb42

Please sign in to comment.