|
@ -147,11 +147,21 @@ BOOL simCreateWindow(HWND *lphWnd, |
|
|
*/ |
|
|
*/ |
|
|
void simDrawMatrix(HDC hdc) |
|
|
void simDrawMatrix(HDC hdc) |
|
|
{ |
|
|
{ |
|
|
COLORREF colorLed; |
|
|
/* color, pen and brush for drawing the LEDS */ |
|
|
HBRUSH hBrushLed; |
|
|
COLORREF colorLed; /* RGB color for the pen and the brush */ |
|
|
HGDIOBJ hGdiOld; |
|
|
HPEN hPen; /* pen for the border of the LEDs */ |
|
|
|
|
|
HGDIOBJ hPenOld; /* SelectObject swap space for the pen */ |
|
|
|
|
|
HBRUSH hBrushLed; /* brush for filling the LED circles */ |
|
|
|
|
|
HGDIOBJ hOldBrush; /* SelectObject swap space for the brush */ |
|
|
|
|
|
|
|
|
|
|
|
/* loop variables */ |
|
|
unsigned int c, p, x, y, absX; |
|
|
unsigned int c, p, x, y, absX; |
|
|
|
|
|
|
|
|
|
|
|
/* geometric values */ |
|
|
|
|
|
RECT rect = {0, 0, WND_X_EXTENTS, WND_Y_EXTENTS}; |
|
|
int left, right, top, bottom; |
|
|
int left, right, top, bottom; |
|
|
|
|
|
|
|
|
|
|
|
/* lookup table for fast bit shifts of the value 0x01 */ |
|
|
static unsigned char const shl_map[8] = |
|
|
static unsigned char const shl_map[8] = |
|
|
{0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; |
|
|
{0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; |
|
|
|
|
|
|
|
@ -164,7 +174,9 @@ void simDrawMatrix(HDC hdc) |
|
|
/* create and select red brush into device context */ |
|
|
/* create and select red brush into device context */ |
|
|
colorLed = RGB((255.0 / NUMPLANE) * (p + 1), 0, 0); |
|
|
colorLed = RGB((255.0 / NUMPLANE) * (p + 1), 0, 0); |
|
|
hBrushLed = CreateSolidBrush(colorLed); |
|
|
hBrushLed = CreateSolidBrush(colorLed); |
|
|
hGdiOld = SelectObject(hdc, hBrushLed); |
|
|
hOldBrush = SelectObject(hdc, hBrushLed); |
|
|
|
|
|
hPen = CreatePen(PS_INSIDEFRAME | PS_SOLID, 1, colorLed); |
|
|
|
|
|
hPenOld = SelectObject(hdc, hPen); |
|
|
|
|
|
|
|
|
/* translate pixmap into LEDs */ |
|
|
/* translate pixmap into LEDs */ |
|
|
for (y = 0; y < NUM_ROWS; ++y) |
|
|
for (y = 0; y < NUM_ROWS; ++y) |
|
@ -175,7 +187,7 @@ void simDrawMatrix(HDC hdc) |
|
|
{ |
|
|
{ |
|
|
if (pixmap[p][y][c] & shl_map[x]) |
|
|
if (pixmap[p][y][c] & shl_map[x]) |
|
|
{ |
|
|
{ |
|
|
// eventually draw a LED, mirroring its coordinates
|
|
|
/* eventually draw a LED, mirroring its coordinates */ |
|
|
absX = (c * 8 + x) * LED_EXTENT + LED_MARGIN; |
|
|
absX = (c * 8 + x) * LED_EXTENT + LED_MARGIN; |
|
|
left = WND_X_EXTENTS - absX; |
|
|
left = WND_X_EXTENTS - absX; |
|
|
right = WND_X_EXTENTS - absX - LED_DIAMETER + 1; |
|
|
right = WND_X_EXTENTS - absX - LED_DIAMETER + 1; |
|
@ -187,8 +199,9 @@ void simDrawMatrix(HDC hdc) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/* dispose that brush */ |
|
|
/* dispose old brush and pen */ |
|
|
DeleteObject(SelectObject(hdc, hGdiOld)); |
|
|
DeleteObject(SelectObject(hdc, hOldBrush)); |
|
|
|
|
|
DeleteObject(SelectObject(hdc, hPenOld)); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -306,28 +319,28 @@ LRESULT CALLBACK simWndProc(HWND hWnd, |
|
|
case WM_KEYDOWN: |
|
|
case WM_KEYDOWN: |
|
|
switch (wParam) |
|
|
switch (wParam) |
|
|
{ |
|
|
{ |
|
|
case VK_ESCAPE: |
|
|
case VK_ESCAPE: /* quit simulator */ |
|
|
case 'Q': |
|
|
case 'Q': |
|
|
PostQuitMessage(0); |
|
|
PostQuitMessage(0); |
|
|
break; |
|
|
break; |
|
|
|
|
|
|
|
|
case VK_SPACE: |
|
|
case VK_SPACE: /* fire */ |
|
|
fakeport |= 0x01; |
|
|
fakeport |= 0x01; |
|
|
break; |
|
|
break; |
|
|
|
|
|
|
|
|
case 'A': |
|
|
case 'A': /* left */ |
|
|
fakeport |= 0x02; |
|
|
fakeport |= 0x02; |
|
|
break; |
|
|
break; |
|
|
|
|
|
|
|
|
case 'D': |
|
|
case 'D': /* right */ |
|
|
fakeport |= 0x04; |
|
|
fakeport |= 0x04; |
|
|
break; |
|
|
break; |
|
|
|
|
|
|
|
|
case 'S': |
|
|
case 'S': /* down */ |
|
|
fakeport |= 0x08; |
|
|
fakeport |= 0x08; |
|
|
break; |
|
|
break; |
|
|
|
|
|
|
|
|
case 'W': |
|
|
case 'W': /* up */ |
|
|
fakeport |= 0x10; |
|
|
fakeport |= 0x10; |
|
|
break; |
|
|
break; |
|
|
|
|
|
|
|
@ -341,23 +354,23 @@ LRESULT CALLBACK simWndProc(HWND hWnd, |
|
|
case WM_KEYUP: |
|
|
case WM_KEYUP: |
|
|
switch(wParam) |
|
|
switch(wParam) |
|
|
{ |
|
|
{ |
|
|
case VK_SPACE: |
|
|
case VK_SPACE: /* fire */ |
|
|
fakeport &= ~0x01; |
|
|
fakeport &= ~0x01; |
|
|
break; |
|
|
break; |
|
|
|
|
|
|
|
|
case 'A': |
|
|
case 'A': /* left */ |
|
|
fakeport &= ~0x02; |
|
|
fakeport &= ~0x02; |
|
|
break; |
|
|
break; |
|
|
|
|
|
|
|
|
case 'D': |
|
|
case 'D': /* right */ |
|
|
fakeport &= ~0x04; |
|
|
fakeport &= ~0x04; |
|
|
break; |
|
|
break; |
|
|
|
|
|
|
|
|
case 'S': |
|
|
case 'S': /* down */ |
|
|
fakeport &= ~0x08; |
|
|
fakeport &= ~0x08; |
|
|
break; |
|
|
break; |
|
|
|
|
|
|
|
|
case 'W': |
|
|
case 'W': /* up */ |
|
|
fakeport &= ~0x10; |
|
|
fakeport &= ~0x10; |
|
|
break; |
|
|
break; |
|
|
|
|
|
|
|
@ -484,7 +497,8 @@ 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, THREAD_PRIORITY_HIGHEST); |
|
|
SetThreadPriority(hLoopThread, |
|
|
|
|
|
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); |
|
|