2002-04-27 17:10:15 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 by Felix Arends
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <process.h>
|
2003-05-30 00:29:50 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <fcntl.h>
|
2005-07-19 21:24:32 +00:00
|
|
|
#include "autoconf.h"
|
2002-04-27 17:10:15 +00:00
|
|
|
#include "uisw32.h"
|
|
|
|
#include "resource.h"
|
2002-04-30 21:15:02 +00:00
|
|
|
#include "button.h"
|
2002-06-12 15:39:39 +00:00
|
|
|
#include "thread.h"
|
|
|
|
#include "thread-win32.h"
|
2002-06-15 10:58:14 +00:00
|
|
|
#include "kernel.h"
|
2005-07-19 21:24:32 +00:00
|
|
|
#include "sound.h"
|
2002-04-27 17:10:15 +00:00
|
|
|
|
2002-08-02 12:17:54 +00:00
|
|
|
#ifndef LR_VGACOLOR /* Should be under MINGW32 builds? */
|
|
|
|
#define LR_VGACOLOR LR_COLOR
|
|
|
|
#endif
|
|
|
|
|
2002-04-27 17:10:15 +00:00
|
|
|
// extern functions
|
2002-04-30 21:15:02 +00:00
|
|
|
extern void app_main (void *); // mod entry point
|
2005-11-21 23:55:39 +00:00
|
|
|
extern void new_key(int key);
|
|
|
|
extern void sim_tick_tasks(void);
|
2002-04-27 17:10:15 +00:00
|
|
|
|
2003-04-19 13:15:33 +00:00
|
|
|
void button_event(int key, bool pressed);
|
|
|
|
|
2002-04-27 17:10:15 +00:00
|
|
|
// variables
|
|
|
|
HWND hGUIWnd; // the GUI window handle
|
|
|
|
unsigned int uThreadID; // id of mod thread
|
|
|
|
PBYTE lpKeys;
|
2002-06-01 20:56:38 +00:00
|
|
|
bool bActive; // window active?
|
2002-06-12 15:39:39 +00:00
|
|
|
HANDLE hGUIThread; // thread for GUI
|
2005-07-19 21:24:32 +00:00
|
|
|
#ifdef ROCKBOX_HAS_SIMSOUND
|
|
|
|
HANDLE hSoundThread; // thread for sound
|
|
|
|
#endif
|
2005-01-25 23:47:28 +00:00
|
|
|
bool bIsWinNT; // Windows NT derivate?
|
2002-04-27 17:10:15 +00:00
|
|
|
|
2003-02-19 14:20:16 +00:00
|
|
|
bool lcd_display_redraw=true; // Used for player simulator
|
2002-10-28 20:45:37 +00:00
|
|
|
char having_new_lcd=true; // Used for player simulator
|
|
|
|
|
2002-04-27 17:10:15 +00:00
|
|
|
// GUIWndProc
|
|
|
|
// window proc for GUI simulator
|
2003-07-03 04:04:28 +00:00
|
|
|
LRESULT CALLBACK GUIWndProc (
|
|
|
|
HWND hWnd,
|
|
|
|
UINT uMsg,
|
|
|
|
WPARAM wParam,
|
|
|
|
LPARAM lParam
|
|
|
|
)
|
2002-04-27 17:10:15 +00:00
|
|
|
{
|
|
|
|
static HBITMAP hBkgnd;
|
|
|
|
static HDC hMemDc;
|
|
|
|
|
2004-07-22 07:47:56 +00:00
|
|
|
static LARGE_INTEGER persec, tick1, ticknow;
|
2005-11-21 23:55:39 +00:00
|
|
|
long new_tick;
|
2004-07-22 07:47:56 +00:00
|
|
|
|
2002-04-27 17:10:15 +00:00
|
|
|
switch (uMsg)
|
|
|
|
{
|
2002-06-15 10:58:14 +00:00
|
|
|
case WM_TIMER:
|
2004-07-22 07:47:56 +00:00
|
|
|
QueryPerformanceCounter(&ticknow);
|
2005-11-21 23:55:39 +00:00
|
|
|
new_tick = ((ticknow.QuadPart-tick1.QuadPart)*HZ)/persec.QuadPart;
|
|
|
|
if (new_tick != current_tick)
|
|
|
|
{
|
2005-11-26 11:22:33 +00:00
|
|
|
long i;
|
|
|
|
for (i = new_tick - current_tick; i > 0; i--)
|
|
|
|
sim_tick_tasks();
|
2005-11-21 23:55:39 +00:00
|
|
|
current_tick = new_tick;
|
|
|
|
}
|
2002-06-15 10:58:14 +00:00
|
|
|
return TRUE;
|
2002-06-01 20:56:38 +00:00
|
|
|
case WM_ACTIVATE:
|
|
|
|
if (LOWORD(wParam) == WA_ACTIVE || LOWORD(wParam) == WA_CLICKACTIVE)
|
|
|
|
bActive = true;
|
|
|
|
else
|
|
|
|
bActive = false;
|
|
|
|
return TRUE;
|
2002-04-27 17:10:15 +00:00
|
|
|
case WM_CREATE:
|
2004-07-22 07:47:56 +00:00
|
|
|
QueryPerformanceFrequency(&persec);
|
|
|
|
QueryPerformanceCounter(&tick1);
|
|
|
|
SetTimer (hWnd, TIMER_EVENT, 1, NULL);
|
|
|
|
|
2002-04-27 17:10:15 +00:00
|
|
|
// load background image
|
2005-01-25 23:47:28 +00:00
|
|
|
hBkgnd = (HBITMAP)LoadImage (GetModuleHandle (NULL),
|
|
|
|
MAKEINTRESOURCE(IDB_UI), IMAGE_BITMAP, 0, 0, LR_VGACOLOR);
|
2002-04-27 17:10:15 +00:00
|
|
|
hMemDc = CreateCompatibleDC (GetDC (hWnd));
|
|
|
|
SelectObject (hMemDc, hBkgnd);
|
|
|
|
return TRUE;
|
|
|
|
case WM_SIZING:
|
|
|
|
{
|
|
|
|
LPRECT r = (LPRECT)lParam;
|
|
|
|
char s[256];
|
|
|
|
int v;
|
2005-01-25 23:47:28 +00:00
|
|
|
int h_add = GetSystemMetrics (SM_CXSIZEFRAME) * 2 + 4;
|
|
|
|
int v_add = GetSystemMetrics (SM_CYSIZEFRAME) * 2
|
|
|
|
+ GetSystemMetrics (SM_CYCAPTION) + 4;
|
2002-04-27 17:10:15 +00:00
|
|
|
|
|
|
|
switch (wParam)
|
|
|
|
{
|
|
|
|
case WMSZ_BOTTOM:
|
|
|
|
v = (r->bottom - r->top) / (UI_HEIGHT / 5);
|
2005-01-25 23:47:28 +00:00
|
|
|
r->bottom = r->top + v * UI_HEIGHT / 5 + v_add;
|
|
|
|
r->right = r->left + v * UI_WIDTH / 5 + h_add;
|
2002-04-27 17:10:15 +00:00
|
|
|
break;
|
|
|
|
case WMSZ_RIGHT:
|
|
|
|
v = (r->right - r->left) / (UI_WIDTH / 5);
|
2005-01-25 23:47:28 +00:00
|
|
|
r->bottom = r->top + v * UI_HEIGHT / 5 + v_add;
|
|
|
|
r->right = r->left + v * UI_WIDTH / 5 + h_add;
|
2002-04-27 17:10:15 +00:00
|
|
|
break;
|
|
|
|
case WMSZ_TOP:
|
|
|
|
v = (r->bottom - r->top) / (UI_HEIGHT / 5);
|
2005-01-25 23:47:28 +00:00
|
|
|
r->top = r->bottom - v * UI_HEIGHT / 5 - v_add;
|
|
|
|
r->right = r->left + v * UI_WIDTH / 5 + h_add;
|
2002-04-27 17:10:15 +00:00
|
|
|
break;
|
|
|
|
case WMSZ_LEFT:
|
|
|
|
v = (r->right - r->left) / (UI_WIDTH / 5);
|
2005-01-25 23:47:28 +00:00
|
|
|
r->bottom = r->top + v * UI_HEIGHT / 5 + v_add;
|
|
|
|
r->left = r->right - v * UI_WIDTH / 5 - h_add;
|
2002-04-27 17:10:15 +00:00
|
|
|
break;
|
|
|
|
case WMSZ_BOTTOMRIGHT:
|
2005-01-25 23:47:28 +00:00
|
|
|
v = ((r->right - r->left) * UI_HEIGHT
|
|
|
|
+(r->bottom - r->top) * UI_WIDTH)
|
|
|
|
/ (2 * UI_WIDTH * UI_HEIGHT / 5);
|
|
|
|
r->bottom = r->top + v * UI_HEIGHT / 5 + v_add;
|
|
|
|
r->right = r->left + v * UI_WIDTH / 5 + h_add;
|
2002-04-27 17:10:15 +00:00
|
|
|
break;
|
|
|
|
case WMSZ_BOTTOMLEFT:
|
2005-01-25 23:47:28 +00:00
|
|
|
v = ((r->right - r->left) * UI_HEIGHT
|
|
|
|
+(r->bottom - r->top) * UI_WIDTH)
|
|
|
|
/ (2 * UI_WIDTH * UI_HEIGHT / 5);
|
|
|
|
r->bottom = r->top + v * UI_HEIGHT / 5 + v_add;
|
|
|
|
r->left = r->right - v * UI_WIDTH / 5 - h_add;
|
2002-04-27 17:10:15 +00:00
|
|
|
break;
|
|
|
|
case WMSZ_TOPRIGHT:
|
2005-01-25 23:47:28 +00:00
|
|
|
v = ((r->right - r->left) * UI_HEIGHT
|
|
|
|
+(r->bottom - r->top) * UI_WIDTH)
|
|
|
|
/ (2 * UI_WIDTH * UI_HEIGHT / 5);
|
|
|
|
r->top = r->bottom - v * UI_HEIGHT / 5 - v_add;
|
|
|
|
r->right = r->left + v * UI_WIDTH / 5 + h_add;
|
2002-04-27 17:10:15 +00:00
|
|
|
break;
|
|
|
|
case WMSZ_TOPLEFT:
|
2005-01-25 23:47:28 +00:00
|
|
|
v = ((r->right - r->left) * UI_HEIGHT
|
|
|
|
+(r->bottom - r->top) * UI_WIDTH)
|
|
|
|
/ (2 * UI_WIDTH * UI_HEIGHT / 5);
|
|
|
|
r->top = r->bottom - v * UI_HEIGHT / 5 - v_add;
|
|
|
|
r->left = r->right - v * UI_WIDTH / 5 - h_add;
|
2002-04-27 17:10:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-01-23 12:43:33 +00:00
|
|
|
wsprintf (s, UI_TITLE " @%d%%",
|
2005-01-25 23:47:28 +00:00
|
|
|
(r->right - r->left - h_add + 1) * 100 / UI_WIDTH);
|
2002-04-27 17:10:15 +00:00
|
|
|
SetWindowText (hWnd, s);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
case WM_ERASEBKGND:
|
|
|
|
{
|
2005-01-23 12:43:33 +00:00
|
|
|
HDC hDc = (HDC) wParam;
|
2002-04-27 17:10:15 +00:00
|
|
|
RECT r;
|
|
|
|
|
|
|
|
GetClientRect (hWnd, &r);
|
2003-04-19 13:15:33 +00:00
|
|
|
// blit background image to screen
|
2005-01-25 23:47:28 +00:00
|
|
|
SetStretchBltMode(hDc, bIsWinNT ? HALFTONE : COLORONCOLOR);
|
2002-04-27 17:10:15 +00:00
|
|
|
StretchBlt (hDc, 0, 0, r.right, r.bottom,
|
|
|
|
hMemDc, 0, 0, UI_WIDTH, UI_HEIGHT, SRCCOPY);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
case WM_PAINT:
|
|
|
|
{
|
|
|
|
PAINTSTRUCT ps;
|
|
|
|
RECT r;
|
|
|
|
HDC hDc = BeginPaint (hWnd, &ps);
|
|
|
|
|
|
|
|
GetClientRect (hWnd, &r);
|
|
|
|
// draw lcd screen
|
2005-01-25 23:47:28 +00:00
|
|
|
SetStretchBltMode(hDc, bIsWinNT ? HALFTONE : COLORONCOLOR);
|
2004-07-22 07:47:56 +00:00
|
|
|
StretchDIBits (hDc,
|
|
|
|
UI_LCD_POSX * r.right / UI_WIDTH,
|
|
|
|
UI_LCD_POSY * r.bottom / UI_HEIGHT,
|
2005-01-25 23:47:28 +00:00
|
|
|
UI_LCD_WIDTH * r.right / UI_WIDTH,
|
2004-07-22 07:47:56 +00:00
|
|
|
UI_LCD_HEIGHT * r.bottom / UI_HEIGHT,
|
|
|
|
0, 0, LCD_WIDTH, LCD_HEIGHT,
|
|
|
|
bitmap, (BITMAPINFO *) &bmi, DIB_RGB_COLORS,
|
|
|
|
SRCCOPY);
|
2005-07-08 01:41:12 +00:00
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
StretchDIBits (hDc,
|
|
|
|
UI_REMOTE_POSX * r.right / UI_WIDTH,
|
|
|
|
UI_REMOTE_POSY * r.bottom / UI_HEIGHT,
|
|
|
|
UI_REMOTE_WIDTH * r.right / UI_WIDTH,
|
|
|
|
UI_REMOTE_HEIGHT * r.bottom / UI_HEIGHT,
|
|
|
|
0, 0, LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT,
|
|
|
|
remote_bitmap, (BITMAPINFO *) &remote_bmi,
|
|
|
|
DIB_RGB_COLORS, SRCCOPY);
|
|
|
|
#endif
|
2002-04-27 17:10:15 +00:00
|
|
|
EndPaint (hWnd, &ps);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
case WM_CLOSE:
|
|
|
|
// close simulator
|
2002-06-15 10:58:14 +00:00
|
|
|
KillTimer (hWnd, TIMER_EVENT);
|
2002-04-27 17:10:15 +00:00
|
|
|
hGUIWnd = NULL;
|
|
|
|
PostQuitMessage (0);
|
|
|
|
break;
|
2002-06-12 15:39:39 +00:00
|
|
|
case WM_DESTROY:
|
|
|
|
// close simulator
|
|
|
|
hGUIWnd = NULL;
|
|
|
|
PostQuitMessage (0);
|
|
|
|
break;
|
2003-04-19 13:15:33 +00:00
|
|
|
case WM_KEYDOWN:
|
|
|
|
button_event(wParam, true);
|
|
|
|
break;
|
|
|
|
case WM_KEYUP:
|
|
|
|
button_event(wParam, false);
|
|
|
|
break;
|
2002-04-27 17:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return DefWindowProc (hWnd, uMsg, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
// GUIStartup
|
|
|
|
// register window class, show window, init GUI
|
|
|
|
BOOL GUIStartup ()
|
|
|
|
{
|
|
|
|
WNDCLASS wc;
|
|
|
|
|
|
|
|
// create window class
|
|
|
|
ZeroMemory (&wc, sizeof(wc));
|
|
|
|
wc.hbrBackground = GetSysColorBrush (COLOR_WINDOW);
|
|
|
|
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
|
|
|
|
wc.hInstance = GetModuleHandle (NULL);
|
2003-07-03 04:04:28 +00:00
|
|
|
wc.lpfnWndProc = GUIWndProc;
|
2002-04-27 17:10:15 +00:00
|
|
|
wc.lpszClassName = "RockBoxUISimulator";
|
|
|
|
wc.style = CS_HREDRAW | CS_VREDRAW;
|
|
|
|
|
|
|
|
if (RegisterClass (&wc) == 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
// create window
|
|
|
|
hGUIWnd = CreateWindowEx (
|
2004-07-22 07:47:56 +00:00
|
|
|
WS_EX_OVERLAPPEDWINDOW,
|
2005-01-17 00:25:23 +00:00
|
|
|
"RockBoxUISimulator", UI_TITLE,
|
2002-04-27 17:10:15 +00:00
|
|
|
WS_VISIBLE | WS_SYSMENU | WS_OVERLAPPEDWINDOW,
|
|
|
|
CW_USEDEFAULT, CW_USEDEFAULT,
|
2003-12-22 20:24:56 +00:00
|
|
|
UI_WIDTH + GetSystemMetrics (SM_CXSIZEFRAME) * 2 +4,
|
2004-07-22 07:47:56 +00:00
|
|
|
UI_HEIGHT + GetSystemMetrics (SM_CYSIZEFRAME) * 2 +
|
2005-01-17 00:25:23 +00:00
|
|
|
GetSystemMetrics (SM_CYCAPTION) +4,
|
2002-04-27 17:10:15 +00:00
|
|
|
NULL, NULL, GetModuleHandle (NULL), NULL);
|
|
|
|
|
|
|
|
if (hGUIWnd == NULL)
|
|
|
|
return FALSE;
|
2005-07-06 22:58:02 +00:00
|
|
|
|
2005-07-08 01:41:12 +00:00
|
|
|
simlcdinit();
|
2002-04-27 17:10:15 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// GUIDown
|
|
|
|
// destroy window, unregister window class
|
|
|
|
int GUIDown ()
|
|
|
|
{
|
2002-06-12 15:39:39 +00:00
|
|
|
int i;
|
|
|
|
|
2002-04-27 17:10:15 +00:00
|
|
|
DestroyWindow (hGUIWnd);
|
2002-06-12 15:39:39 +00:00
|
|
|
CloseHandle (hGUIThread);
|
2005-07-19 21:24:32 +00:00
|
|
|
#ifdef ROCKBOX_HAS_SIMSOUND
|
|
|
|
CloseHandle (hSoundThread);
|
|
|
|
#endif
|
2005-07-19 20:43:21 +00:00
|
|
|
|
2002-06-12 15:39:39 +00:00
|
|
|
for (i = 0; i < nThreads; i++)
|
|
|
|
{
|
|
|
|
CloseHandle (lpThreads[i]);
|
|
|
|
}
|
2002-04-27 17:10:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// GUIMessageLoop
|
|
|
|
// standard message loop for GUI window
|
|
|
|
void GUIMessageLoop ()
|
|
|
|
{
|
|
|
|
MSG msg;
|
2002-06-12 15:39:39 +00:00
|
|
|
while (GetMessage (&msg, NULL, 0, 0))
|
2002-04-27 17:10:15 +00:00
|
|
|
{
|
|
|
|
TranslateMessage (&msg);
|
|
|
|
DispatchMessage (&msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// WinMain
|
|
|
|
// program entry point
|
|
|
|
int WINAPI WinMain (
|
|
|
|
HINSTANCE hInstance, // current instance
|
|
|
|
HINSTANCE hPrevInstance, // previous instance
|
|
|
|
LPSTR lpCmd, // command line
|
|
|
|
int nShowCmd // show command
|
|
|
|
)
|
|
|
|
{
|
2002-06-12 15:39:39 +00:00
|
|
|
DWORD dwThreadID;
|
2002-08-02 14:00:52 +00:00
|
|
|
|
|
|
|
(void)hInstance;
|
|
|
|
(void)hPrevInstance;
|
|
|
|
(void)lpCmd;
|
|
|
|
(void)nShowCmd;
|
|
|
|
|
2003-05-30 00:29:50 +00:00
|
|
|
/* default file mode should be O_BINARY to be consistent with rockbox */
|
|
|
|
_fmode = _O_BINARY;
|
2005-01-25 23:47:28 +00:00
|
|
|
|
|
|
|
bIsWinNT = ((GetVersion() & 0x80000000) == 0);
|
2003-05-30 00:29:50 +00:00
|
|
|
|
2002-04-27 17:10:15 +00:00
|
|
|
if (!GUIStartup ())
|
|
|
|
return 0;
|
|
|
|
|
2002-06-12 15:39:39 +00:00
|
|
|
hGUIThread = CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE)app_main,
|
|
|
|
NULL, 0, &dwThreadID);
|
|
|
|
|
|
|
|
if (hGUIThread == NULL)
|
|
|
|
return MessageBox (NULL, "Error creating gui thread!", "Error", MB_OK);
|
2002-04-27 17:10:15 +00:00
|
|
|
|
2005-07-19 21:24:32 +00:00
|
|
|
#ifdef ROCKBOX_HAS_SIMSOUND
|
|
|
|
hSoundThread = CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE)
|
|
|
|
sound_playback_thread, NULL, 0, &dwThreadID);
|
|
|
|
|
2005-07-21 10:19:50 +00:00
|
|
|
if (hSoundThread == NULL)
|
2005-07-19 21:24:32 +00:00
|
|
|
MessageBox (NULL, "Error creating sound thread!", "Warning", MB_OK);
|
|
|
|
#endif
|
|
|
|
|
2002-04-27 17:10:15 +00:00
|
|
|
GUIMessageLoop ();
|
|
|
|
|
|
|
|
return GUIDown ();
|
2002-08-02 12:17:54 +00:00
|
|
|
}
|