From 0053ec0c725206a5fca17bfca8f4ab607b90096a Mon Sep 17 00:00:00 2001 From: Felix Arends Date: Wed, 12 Jun 2002 15:39:39 +0000 Subject: Threading is working on uisw32 as well now, code is up-to-date, makefile is up-to-date git-svn-id: svn://svn.rockbox.org/rockbox/trunk@981 a1c6a512-1295-4272-9138-f99709370657 --- uisimulator/win32/button.c | 74 +++++++++++++++++++++------------------ uisimulator/win32/kernel.c | 8 +++++ uisimulator/win32/lcd-win32.c | 7 ---- uisimulator/win32/makefile | 15 ++++---- uisimulator/win32/mpeg.c | 11 ++++++ uisimulator/win32/thread-win32.c | 53 ++++++++++++++++++++++++++++ uisimulator/win32/thread-win32.h | 22 ++++++++++++ uisimulator/win32/uisw32.c | 36 ++++++++++++++++--- uisimulator/win32/uisw32.h | 2 ++ uisimulator/win32/uisw32.suo | Bin 12800 -> 12800 bytes uisimulator/win32/uisw32.vcproj | 14 +++++++- 11 files changed, 189 insertions(+), 53 deletions(-) create mode 100644 uisimulator/win32/thread-win32.c create mode 100644 uisimulator/win32/thread-win32.h (limited to 'uisimulator') diff --git a/uisimulator/win32/button.c b/uisimulator/win32/button.c index a2edbde9a3..9f3c324077 100644 --- a/uisimulator/win32/button.c +++ b/uisimulator/win32/button.c @@ -34,52 +34,58 @@ void button_init(void) int button_get(bool block) { + int btn = 0; - if (bActive) + do { - if (KEY (VK_NUMPAD4) || - KEY (VK_LEFT)) // left button - btn |= BUTTON_LEFT; + if (bActive) + { + if (KEY (VK_NUMPAD4) || + KEY (VK_LEFT)) // left button + btn |= BUTTON_LEFT; - if (KEY (VK_NUMPAD6) || - KEY (VK_RIGHT)) - btn |= BUTTON_RIGHT; // right button + if (KEY (VK_NUMPAD6) || + KEY (VK_RIGHT)) + btn |= BUTTON_RIGHT; // right button - if (KEY (VK_NUMPAD8) || - KEY (VK_UP)) - btn |= BUTTON_UP; // up button + if (KEY (VK_NUMPAD8) || + KEY (VK_UP)) + btn |= BUTTON_UP; // up button - if (KEY (VK_NUMPAD2) || - KEY (VK_DOWN)) - btn |= BUTTON_DOWN; // down button + if (KEY (VK_NUMPAD2) || + KEY (VK_DOWN)) + btn |= BUTTON_DOWN; // down button - if (KEY (VK_ADD)) - btn |= BUTTON_ON; // on button + if (KEY (VK_ADD)) + btn |= BUTTON_ON; // on button - #ifdef HAVE_RECORDER_KEYPAD - if (KEY (VK_RETURN)) - btn |= BUTTON_OFF; // off button + #ifdef HAVE_RECORDER_KEYPAD + if (KEY (VK_RETURN)) + btn |= BUTTON_OFF; // off button - if (KEY (VK_DIVIDE)) - btn |= BUTTON_F1; // F1 button + if (KEY (VK_DIVIDE)) + btn |= BUTTON_F1; // F1 button - if (KEY (VK_MULTIPLY)) - btn |= BUTTON_F2; // F2 button + if (KEY (VK_MULTIPLY)) + btn |= BUTTON_F2; // F2 button - if (KEY (VK_SUBTRACT)) - btn |= BUTTON_F3; // F3 button + if (KEY (VK_SUBTRACT)) + btn |= BUTTON_F3; // F3 button - if (KEY (VK_NUMPAD5) || - KEY (VK_SPACE)) - btn |= BUTTON_PLAY; // play button - #else - if (KEY (VK_RETURN)) - btn |= BUTTON_MENU; // menu button - #endif + if (KEY (VK_NUMPAD5) || + KEY (VK_SPACE)) + btn |= BUTTON_PLAY; // play button + #else + if (KEY (VK_RETURN)) + btn |= BUTTON_MENU; // menu button + #endif - if (btn != 0) { - last_key = 0 ; - } + if (btn != 0) { + last_key = 0 ; + } + } } + while (btn == 0 && block); + return btn; } \ No newline at end of file diff --git a/uisimulator/win32/kernel.c b/uisimulator/win32/kernel.c index b6d36e3fa8..102bb6c82a 100644 --- a/uisimulator/win32/kernel.c +++ b/uisimulator/win32/kernel.c @@ -18,9 +18,17 @@ ****************************************************************************/ #include +#include "uisw32.h" #include "kernel.h" +#include "thread-win32.h" void sleep(int ticks) { Sleep (1000 / HZ * ticks); +} + + +void yield (void) +{ + PostThreadMessage (GetWindowThreadProcessId (hGUIWnd,NULL), TM_YIELD, 0, 0); } \ No newline at end of file diff --git a/uisimulator/win32/lcd-win32.c b/uisimulator/win32/lcd-win32.c index 2330d444c5..2eef2d5646 100644 --- a/uisimulator/win32/lcd-win32.c +++ b/uisimulator/win32/lcd-win32.c @@ -40,13 +40,6 @@ BITMAPINFO2 bmi = }; // bitmap information -// lcd_init -// init lcd controler -void lcd_init() -{ - lcd_clear_display (); -} - // lcd_update // update lcd void lcd_update() diff --git a/uisimulator/win32/makefile b/uisimulator/win32/makefile index cc5098b89b..0e93dcd855 100644 --- a/uisimulator/win32/makefile +++ b/uisimulator/win32/makefile @@ -27,11 +27,11 @@ APPDIR = ../../apps/ RECDIR = $(APPDIR)recorder/ RM = del -#DISPLAY = -DHAVE_LCD_CHARCELLS -DISPLAY = -DHAVE_LCD_BITMAP +DISPLAY = -DHAVE_LCD_CHARCELLS +#DISPLAY = -DHAVE_LCD_BITMAP -#KEYPAD = -DHAVE_PLAYER_KEYPAD -KEYPAD = -DHAVE_RECORDER_KEYPAD +KEYPAD = -DHAVE_PLAYER_KEYPAD +#KEYPAD = -DHAVE_RECORDER_KEYPAD CC = cl DEFINES = -DWIN32 -DHAVE_CONFIG_H -DGETTIMEOFDAY_TWO_ARGS -DSIMULATOR \ @@ -46,7 +46,7 @@ CFLAGS = $(DEBUG) $(DEFINES) $(INCLUDES) /MD /Fd"Release/vc70.pdb" SRCS = lcd-win32.c uisw32.c lcd.c button.c tree.c main.c \ chartables.c kernel.c uisw32.res dir-win32.c main_menu.c \ play.c debug-win32.c menu.c credits.c sound_menu.c mpeg.c \ - id3.c settings.c sprintf.c + id3.c settings.c sprintf.c thread-win32.c playlist.c !IF ("$(DISPLAY)" == "-DHAVE_LCD_BITMAP") SRCS = $(SRCS) tetris.c screensaver.c icons.c bmp.c @@ -105,5 +105,8 @@ settings.obj: $(FIRMWAREDIR)/settings.c sprintf.obj: $(FIRMWAREDIR)/common/sprintf.c $(CC) $(CFLAGS) -c $(FIRMWAREDIR)/common/sprintf.c -osprintf.obj +playlist.obj: ../../apps/playlist.c + $(CC) $(CFLAGS) -c ../../apps/playlist.c -oplaylist.obj + clean: - $(RM) *.obj \ No newline at end of file + $(RM) *.obj diff --git a/uisimulator/win32/mpeg.c b/uisimulator/win32/mpeg.c index 7f7b76aacb..1ff9bce3ff 100644 --- a/uisimulator/win32/mpeg.c +++ b/uisimulator/win32/mpeg.c @@ -20,6 +20,8 @@ /* This file is for emulating some of the mpeg controlling functions of the target */ +#include "debug.h" + void mpeg_volume(void) { } @@ -35,3 +37,12 @@ void mpeg_treble(void) void mpeg_stop(void) { } + +#ifndef MPEGPLAY +void mpeg_play(char *tune) +{ + DEBUGF("We instruct the MPEG thread to play %s for us\n", + tune); +} + +#endif diff --git a/uisimulator/win32/thread-win32.c b/uisimulator/win32/thread-win32.c new file mode 100644 index 0000000000..466567c535 --- /dev/null +++ b/uisimulator/win32/thread-win32.c @@ -0,0 +1,53 @@ +/*************************************************************************** + * __________ __ ___. + * 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 +#include "thread-win32.h" + +HANDLE lpThreads[256]; +int nThreads = 0, + nPos = 0; + + +DWORD WINAPI runthread (LPVOID lpParameter) +{ + ((void(*)())lpParameter) (); + return 0; +} + +int create_thread(void* fp, void* sp, int stk_size) +{ + DWORD dwThreadID; + + if (nThreads == 256) + return -1; + + lpThreads[nThreads++] = CreateThread (NULL, + 0, + runthread, + fp, + 0, + &dwThreadID); + + return 0; +} + +void init_threads(void) +{ +} diff --git a/uisimulator/win32/thread-win32.h b/uisimulator/win32/thread-win32.h new file mode 100644 index 0000000000..edaab83448 --- /dev/null +++ b/uisimulator/win32/thread-win32.h @@ -0,0 +1,22 @@ +/*************************************************************************** + * __________ __ ___. + * 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. + * + ****************************************************************************/ + +extern HANDLE lpThreads[256]; +extern int nPos, + nThreads; \ No newline at end of file diff --git a/uisimulator/win32/uisw32.c b/uisimulator/win32/uisw32.c index 0b2f88066c..77ad917461 100644 --- a/uisimulator/win32/uisw32.c +++ b/uisimulator/win32/uisw32.c @@ -22,6 +22,8 @@ #include "uisw32.h" #include "resource.h" #include "button.h" +#include "thread.h" +#include "thread-win32.h" // extern functions extern void app_main (void *); // mod entry point @@ -32,6 +34,7 @@ HWND hGUIWnd; // the GUI window handle unsigned int uThreadID; // id of mod thread PBYTE lpKeys; bool bActive; // window active? +HANDLE hGUIThread; // thread for GUI // GUIWndProc // window proc for GUI simulator @@ -186,6 +189,11 @@ LRESULT GUIWndProc ( hGUIWnd = NULL; PostQuitMessage (0); break; + case WM_DESTROY: + // close simulator + hGUIWnd = NULL; + PostQuitMessage (0); + break; } return DefWindowProc (hWnd, uMsg, wParam, lParam); @@ -229,8 +237,16 @@ BOOL GUIStartup () // destroy window, unregister window class int GUIDown () { + int i; + DestroyWindow (hGUIWnd); - _endthreadex (uThreadID); + CloseHandle (hGUIThread); + for (i = 0; i < nThreads; i++) + { + ResumeThread (lpThreads[i]); + WaitForSingleObject (lpThreads[i], 1); + CloseHandle (lpThreads[i]); + } return 0; } @@ -239,10 +255,17 @@ int GUIDown () void GUIMessageLoop () { MSG msg; - while (GetMessage (&msg, hGUIWnd, 0, 0) && hGUIWnd != NULL) + while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg); DispatchMessage (&msg); + if (msg.message == TM_YIELD) + { + SuspendThread (lpThreads[nPos]); + if (++nPos >= nThreads) + nPos = 0; + ResumeThread (lpThreads[nPos]); + } } } @@ -256,12 +279,15 @@ int WINAPI WinMain ( int nShowCmd // show command ) { + DWORD dwThreadID; if (!GUIStartup ()) return 0; - uThreadID = _beginthread (app_main, 0, NULL); - if (uThreadID == -0L) - return MessageBox (NULL, "Error creating mod thread!", "Error", MB_OK); + 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); GUIMessageLoop (); diff --git a/uisimulator/win32/uisw32.h b/uisimulator/win32/uisw32.h index d709e207f2..fd778e9182 100644 --- a/uisimulator/win32/uisw32.h +++ b/uisimulator/win32/uisw32.h @@ -32,6 +32,8 @@ #define UI_LCD_POSX 59 // x position of lcd #define UI_LCD_POSY 95 // y position of lcd +#define TM_YIELD WM_USER + 101 // thread message for yield + extern HWND hGUIWnd; // the GUI window handle extern unsigned int uThreadID; // id of mod thread extern bool bActive; diff --git a/uisimulator/win32/uisw32.suo b/uisimulator/win32/uisw32.suo index f17bb723c3..b18805cf4a 100644 Binary files a/uisimulator/win32/uisw32.suo and b/uisimulator/win32/uisw32.suo differ diff --git a/uisimulator/win32/uisw32.vcproj b/uisimulator/win32/uisw32.vcproj index f5a17cc431..99222a64a8 100644 --- a/uisimulator/win32/uisw32.vcproj +++ b/uisimulator/win32/uisw32.vcproj @@ -182,7 +182,10 @@ + RelativePath="..\..\apps\playlist.c"> + + @@ -193,6 +196,12 @@ + + + + @@ -221,6 +230,9 @@ + + -- cgit v1.2.3