|
@ -31,6 +31,7 @@ |
|
|
|
|
|
|
|
|
#include <windows.h> |
|
|
#include <windows.h> |
|
|
#include <setjmp.h> |
|
|
#include <setjmp.h> |
|
|
|
|
|
#include <stdio.h> |
|
|
#include "../config.h" |
|
|
#include "../config.h" |
|
|
#include "../display_loop.h" |
|
|
#include "../display_loop.h" |
|
|
|
|
|
|
|
@ -41,7 +42,7 @@ |
|
|
#define LED_MARGIN 1 |
|
|
#define LED_MARGIN 1 |
|
|
/** The diameter (in pixels) of a LED. */ |
|
|
/** The diameter (in pixels) of a LED. */ |
|
|
#define LED_DIAMETER 14 |
|
|
#define LED_DIAMETER 14 |
|
|
/** The extend of the whole LED including its margin. */ |
|
|
/** The extent of the whole LED including its margin. */ |
|
|
#define LED_EXTENT (2 * LED_MARGIN + LED_DIAMETER) |
|
|
#define LED_EXTENT (2 * LED_MARGIN + LED_DIAMETER) |
|
|
|
|
|
|
|
|
/** Width of the canvas. */ |
|
|
/** Width of the canvas. */ |
|
@ -75,69 +76,80 @@ volatile unsigned char pixmap[NUMPLANE][NUM_ROWS][LINEBYTES]; |
|
|
/** Jump buffer which leads directly the menu. */ |
|
|
/** Jump buffer which leads directly the menu. */ |
|
|
extern jmp_buf newmode_jmpbuf; |
|
|
extern jmp_buf newmode_jmpbuf; |
|
|
|
|
|
|
|
|
/* forward declarations */ |
|
|
/* forward declaration of window message handler */ |
|
|
LRESULT CALLBACK simWndProc(HWND hWnd, |
|
|
LRESULT CALLBACK simWndProc(HWND hWnd, |
|
|
UINT msg, |
|
|
UINT msg, |
|
|
WPARAM wParam, |
|
|
WPARAM wParam, |
|
|
LPARAM lParam); |
|
|
LPARAM lParam); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Registers a window class (necessary for creating a window). |
|
|
|
|
|
* @param lpwc Pointer to WNDCLASS struct. |
|
|
|
|
|
* @param hInstance Handle of the instance where this window class belongs to. |
|
|
|
|
|
* @return TRUE if successful, otherwise FALSE. |
|
|
|
|
|
*/ |
|
|
|
|
|
BOOL simRegisterWindowClass(WNDCLASSA *const lpwc, |
|
|
|
|
|
HINSTANCE hInstance) |
|
|
|
|
|
{ |
|
|
|
|
|
lpwc->style = 0; |
|
|
|
|
|
lpwc->lpfnWndProc = simWndProc; |
|
|
|
|
|
lpwc->cbClsExtra = 0; |
|
|
|
|
|
lpwc->cbWndExtra = 0; |
|
|
|
|
|
lpwc->hInstance = hInstance; |
|
|
|
|
|
lpwc->hIcon = LoadIcon(NULL, IDI_WINLOGO); |
|
|
|
|
|
lpwc->hCursor = LoadCursor(NULL, IDC_ARROW); |
|
|
|
|
|
lpwc->hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); |
|
|
|
|
|
lpwc->lpszMenuName = NULL; |
|
|
|
|
|
lpwc->lpszClassName = g_strWindowClass; |
|
|
|
|
|
|
|
|
|
|
|
return (RegisterClassA(lpwc) != 0); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* Creates a new window and makes it visible. |
|
|
* Creates a new window and makes it visible. |
|
|
* @param lphWnd Pointer to window handle. |
|
|
* @param hInstance Handle of the instance where this window should belong to. |
|
|
* @param hInstance Handle of the instance where this window belongs to. |
|
|
|
|
|
* @param nCmdShow Flag for showing the window minimized, maximized etc. |
|
|
* @param nCmdShow Flag for showing the window minimized, maximized etc. |
|
|
* @return TRUE if successful, otherwise FALSE. |
|
|
* @return TRUE if successful, otherwise FALSE. |
|
|
*/ |
|
|
*/ |
|
|
BOOL simCreateWindow(HWND *lphWnd, |
|
|
HWND simCreateWindow(HINSTANCE hInstance, |
|
|
HINSTANCE hInstance, |
|
|
|
|
|
int nCmdShow) |
|
|
int nCmdShow) |
|
|
{ |
|
|
{ |
|
|
BOOL bSuccess = FALSE; |
|
|
HWND hWnd = NULL; |
|
|
|
|
|
|
|
|
|
|
|
/* register window class for an window with a neat black background */ |
|
|
|
|
|
WNDCLASSA lpwc; |
|
|
|
|
|
lpwc.style = 0; |
|
|
|
|
|
lpwc.lpfnWndProc = simWndProc; |
|
|
|
|
|
lpwc.cbClsExtra = 0; |
|
|
|
|
|
lpwc.cbWndExtra = 0; |
|
|
|
|
|
lpwc.hInstance = hInstance; |
|
|
|
|
|
lpwc.hIcon = LoadIcon(NULL, IDI_WINLOGO); |
|
|
|
|
|
lpwc.hCursor = LoadCursor(NULL, IDC_ARROW); |
|
|
|
|
|
lpwc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); |
|
|
|
|
|
lpwc.lpszMenuName = NULL; |
|
|
|
|
|
lpwc.lpszClassName = g_strWindowClass; |
|
|
|
|
|
|
|
|
|
|
|
if (RegisterClassA(&lpwc) != 0) |
|
|
|
|
|
{ |
|
|
/* ensure that the client area has the right proportions */ |
|
|
/* ensure that the client area has the right proportions */ |
|
|
RECT rectMin = {0, 0, WND_X_EXTENTS * 1.5 - 1, WND_Y_EXTENTS * 1.5 - 1}; |
|
|
RECT rect = {0, 0, WND_X_EXTENTS * 1.5 - 1, WND_Y_EXTENTS * 1.5 - 1}; |
|
|
AdjustWindowRect(&rectMin, WS_OVERLAPPEDWINDOW & ~(WS_OVERLAPPED), FALSE); |
|
|
AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW & ~(WS_OVERLAPPED), FALSE); |
|
|
|
|
|
|
|
|
/* create window and retrieve its handle */ |
|
|
/* create window and retrieve its handle */ |
|
|
*lphWnd = CreateWindow(g_strWindowClass, g_strWindowTitle, |
|
|
hWnd = CreateWindow(g_strWindowClass, g_strWindowTitle, |
|
|
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, |
|
|
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, |
|
|
rectMin.right - rectMin.left, rectMin.bottom - rectMin.top, |
|
|
rect.right - rect.left, rect.bottom - rect.top, |
|
|
HWND_DESKTOP, NULL, hInstance, NULL); |
|
|
HWND_DESKTOP, NULL, hInstance, NULL); |
|
|
|
|
|
|
|
|
/* make it visible */ |
|
|
/* if window was created successfully, make it visible */ |
|
|
if (*lphWnd != NULL) |
|
|
if (hWnd != NULL) |
|
|
|
|
|
{ |
|
|
|
|
|
ShowWindow(hWnd, nCmdShow); |
|
|
|
|
|
UpdateWindow(hWnd); |
|
|
|
|
|
} |
|
|
|
|
|
/* otherwise clean up*/ |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
UnregisterClass(g_strWindowClass, hInstance); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
{ |
|
|
{ |
|
|
ShowWindow(*lphWnd, nCmdShow); |
|
|
fprintf(stderr, g_strErrorRegisterWindow); |
|
|
UpdateWindow(*lphWnd); |
|
|
} |
|
|
bSuccess = TRUE; |
|
|
|
|
|
|
|
|
return hWnd; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return bSuccess; |
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Closes windows and unregisters its associated window class. |
|
|
|
|
|
* @param lphWnd Pointer to window handle. |
|
|
|
|
|
* @param hInstance Handle of the instance where this window belongs to. |
|
|
|
|
|
*/ |
|
|
|
|
|
void simDestroyWindow(HWND hWnd, |
|
|
|
|
|
HINSTANCE hInstance) |
|
|
|
|
|
{ |
|
|
|
|
|
DestroyWindow(hWnd); |
|
|
|
|
|
UnregisterClassA(g_strWindowClass, hInstance); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -476,17 +488,13 @@ int APIENTRY WinMain(HINSTANCE hInstance, |
|
|
LPSTR lpCmdLine, |
|
|
LPSTR lpCmdLine, |
|
|
int nCmdShow) |
|
|
int nCmdShow) |
|
|
{ |
|
|
{ |
|
|
WNDCLASS wc; |
|
|
|
|
|
HWND hWnd; |
|
|
HWND hWnd; |
|
|
MSG msg; |
|
|
MSG msg; |
|
|
HANDLE hLoopThread; |
|
|
HANDLE hLoopThread; |
|
|
UINT_PTR uTimerId; |
|
|
UINT_PTR uTimerId; |
|
|
int nExitCode = 0; |
|
|
int nExitCode = 0; |
|
|
|
|
|
|
|
|
/* register window class (with nice black background!) and create window */ |
|
|
if ((hWnd = simCreateWindow(hInstance, nCmdShow)) != NULL) |
|
|
if (simRegisterWindowClass(&wc, hInstance)) |
|
|
|
|
|
{ |
|
|
|
|
|
if (simCreateWindow(&hWnd, hInstance, nCmdShow)) |
|
|
|
|
|
{ |
|
|
{ |
|
|
/* event handle for multimedia timer (for the wait() function) */ |
|
|
/* event handle for multimedia timer (for the wait() function) */ |
|
|
g_hWaitEvent = CreateEventA(NULL, TRUE, FALSE, "Local\\WaitEvent"); |
|
|
g_hWaitEvent = CreateEventA(NULL, TRUE, FALSE, "Local\\WaitEvent"); |
|
@ -496,8 +504,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, |
|
|
hLoopThread = CreateThread(NULL, 0, simLoop, NULL, 0, NULL); |
|
|
hLoopThread = CreateThread(NULL, 0, simLoop, NULL, 0, NULL); |
|
|
if (hLoopThread != NULL) |
|
|
if (hLoopThread != NULL) |
|
|
{ |
|
|
{ |
|
|
SetThreadPriority(hLoopThread, |
|
|
SetThreadPriority(hLoopThread, THREAD_PRIORITY_TIME_CRITICAL); |
|
|
THREAD_PRIORITY_TIME_CRITICAL); |
|
|
|
|
|
|
|
|
|
|
|
/* issue a UI timer message every 40 ms (roughly 25 fps) */ |
|
|
/* issue a UI timer message every 40 ms (roughly 25 fps) */ |
|
|
uTimerId = SetTimer(hWnd, 23, 40, NULL); |
|
|
uTimerId = SetTimer(hWnd, 23, 40, NULL); |
|
@ -515,16 +522,14 @@ int APIENTRY WinMain(HINSTANCE hInstance, |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
MessageBoxA(HWND_DESKTOP, g_strErrorCreateUITimer, |
|
|
fprintf(stderr, g_strErrorCreateUITimer); |
|
|
g_strError, MB_OK | MB_ICONERROR); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
TerminateThread(hLoopThread, 0); |
|
|
TerminateThread(hLoopThread, 0); |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
MessageBoxA(HWND_DESKTOP, g_strErrorCreateThread, |
|
|
fprintf(stderr, g_strErrorCreateThread); |
|
|
g_strError, MB_OK | MB_ICONERROR); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/* relieve wait event object from its duties */ |
|
|
/* relieve wait event object from its duties */ |
|
@ -532,24 +537,14 @@ int APIENTRY WinMain(HINSTANCE hInstance, |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
MessageBoxA(HWND_DESKTOP, g_strErrorCreateEvent, |
|
|
fprintf(stderr, g_strErrorCreateEvent); |
|
|
g_strError, MB_OK | MB_ICONERROR); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
DestroyWindow(hWnd); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
MessageBoxA(HWND_DESKTOP, g_strErrorCreateWindow, |
|
|
|
|
|
g_strError, MB_OK | MB_ICONERROR); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
UnregisterClassA(g_strWindowClass, hInstance); |
|
|
simDestroyWindow(hWnd, hInstance); |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
MessageBoxA(HWND_DESKTOP, g_strErrorRegisterWindow, |
|
|
fprintf(stderr, g_strErrorCreateWindow); |
|
|
g_strError, MB_OK | MB_ICONERROR); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return nExitCode; |
|
|
return nExitCode; |
|
|