diff options
author | Felix Arends <edx@rockbox.org> | 2002-04-25 04:41:45 +0000 |
---|---|---|
committer | Felix Arends <edx@rockbox.org> | 2002-04-25 04:41:45 +0000 |
commit | 144bc70a12f84620137ce17bc843c26b27839717 (patch) | |
tree | 1424a4d8371aed3fbc7cb7a612f553a3d2ef45c9 /uisimulator/win32 | |
parent | 7b9581a13148957842ab53e2b28bf0a663a48980 (diff) | |
download | rockbox-144bc70a12f84620137ce17bc843c26b27839717.tar.gz rockbox-144bc70a12f84620137ce17bc843c26b27839717.zip |
First Version of UISimulator for Win32
lcd and keypad working for recorder
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@221 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'uisimulator/win32')
-rw-r--r-- | uisimulator/win32/UI.bmp | bin | 0 -> 259256 bytes | |||
-rw-r--r-- | uisimulator/win32/button.c | 47 | ||||
-rw-r--r-- | uisimulator/win32/kernel.c | 26 | ||||
-rw-r--r-- | uisimulator/win32/lcd-win32.h | 27 | ||||
-rw-r--r-- | uisimulator/win32/lcd.c | 440 | ||||
-rw-r--r-- | uisimulator/win32/main.cpp | 29 | ||||
-rw-r--r-- | uisimulator/win32/resource.h | 17 | ||||
-rw-r--r-- | uisimulator/win32/tetris.c | 288 | ||||
-rw-r--r-- | uisimulator/win32/uisw32.cpp | 259 | ||||
-rw-r--r-- | uisimulator/win32/uisw32.h | 39 | ||||
-rw-r--r-- | uisimulator/win32/uisw32.sln | 21 | ||||
-rw-r--r-- | uisimulator/win32/uisw32.suo | bin | 0 -> 9728 bytes | |||
-rw-r--r-- | uisimulator/win32/uisw32.vcproj | 154 |
13 files changed, 1347 insertions, 0 deletions
diff --git a/uisimulator/win32/UI.bmp b/uisimulator/win32/UI.bmp new file mode 100644 index 0000000000..ee21175ec4 --- /dev/null +++ b/uisimulator/win32/UI.bmp | |||
Binary files differ | |||
diff --git a/uisimulator/win32/button.c b/uisimulator/win32/button.c new file mode 100644 index 0000000000..ebcf973faa --- /dev/null +++ b/uisimulator/win32/button.c | |||
@@ -0,0 +1,47 @@ | |||
1 | #include <windows.h> | ||
2 | #include "config.h" | ||
3 | #include "sh7034.h" | ||
4 | #include "button.h" | ||
5 | |||
6 | #define KEY(k) HIBYTE(GetKeyState (k)) | ||
7 | |||
8 | void button_init(void) {}int button_get(void) | ||
9 | { | ||
10 | int btn = 0; | ||
11 | if (KEY (VK_NUMPAD4) || | ||
12 | KEY (VK_LEFT)) // left button | ||
13 | btn |= BUTTON_LEFT; | ||
14 | |||
15 | if (KEY (VK_NUMPAD6) || | ||
16 | KEY (VK_RIGHT)) | ||
17 | btn |= BUTTON_RIGHT; // right button | ||
18 | |||
19 | if (KEY (VK_NUMPAD8) || | ||
20 | KEY (VK_UP)) | ||
21 | btn |= BUTTON_UP; // up button | ||
22 | |||
23 | if (KEY (VK_NUMPAD2) || | ||
24 | KEY (VK_DOWN)) | ||
25 | btn |= BUTTON_DOWN; // down button | ||
26 | |||
27 | if (KEY (VK_NUMPAD5) || | ||
28 | KEY (VK_SPACE)) | ||
29 | btn |= BUTTON_PLAY; // play button | ||
30 | |||
31 | if (KEY (VK_RETURN)) | ||
32 | btn |= BUTTON_OFF; // off button | ||
33 | |||
34 | if (KEY (VK_ADD)) | ||
35 | btn |= BUTTON_ON; // on button | ||
36 | |||
37 | if (KEY (VK_DIVIDE)) | ||
38 | btn |= BUTTON_F1; // F1 button | ||
39 | |||
40 | if (KEY (VK_MULTIPLY)) | ||
41 | btn |= BUTTON_F2; // F2 button | ||
42 | |||
43 | if (KEY (VK_SUBTRACT)) | ||
44 | btn |= BUTTON_F3; // F3 button | ||
45 | |||
46 | return btn; | ||
47 | } \ No newline at end of file | ||
diff --git a/uisimulator/win32/kernel.c b/uisimulator/win32/kernel.c new file mode 100644 index 0000000000..4277190dab --- /dev/null +++ b/uisimulator/win32/kernel.c | |||
@@ -0,0 +1,26 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Björn Stenberg, Felix Arends | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #include <windows.h> | ||
21 | #include "kernel.h" | ||
22 | |||
23 | void sleep(int ticks) | ||
24 | { | ||
25 | Sleep (1000 / HZ * ticks); | ||
26 | } \ No newline at end of file | ||
diff --git a/uisimulator/win32/lcd-win32.h b/uisimulator/win32/lcd-win32.h new file mode 100644 index 0000000000..5049c2d70c --- /dev/null +++ b/uisimulator/win32/lcd-win32.h | |||
@@ -0,0 +1,27 @@ | |||
1 | #ifndef __LCDWIN32_H__ | ||
2 | #define __LCDWIN32_H__ | ||
3 | |||
4 | #include "uisw32.h" | ||
5 | #include "lcd.h" | ||
6 | |||
7 | // BITMAPINFO2 | ||
8 | typedef struct | ||
9 | { | ||
10 | BITMAPINFOHEADER bmiHeader; | ||
11 | RGBQUAD bmiColors[2]; | ||
12 | } BITMAPINFO2; | ||
13 | |||
14 | #ifdef HAVE_LCD_BITMAP | ||
15 | |||
16 | extern unsigned char display[DISP_X][DISP_Y/8]; // the display | ||
17 | #else | ||
18 | #define DISP_X 112 | ||
19 | #define DISP_Y 64 | ||
20 | #endif | ||
21 | |||
22 | |||
23 | extern char bitmap[DISP_Y][DISP_X]; // the ui display | ||
24 | extern BITMAPINFO2 bmi; // bitmap information | ||
25 | |||
26 | |||
27 | #endif // #ifndef __LCDWIN32_H__ \ No newline at end of file | ||
diff --git a/uisimulator/win32/lcd.c b/uisimulator/win32/lcd.c new file mode 100644 index 0000000000..2d1d80ccc7 --- /dev/null +++ b/uisimulator/win32/lcd.c | |||
@@ -0,0 +1,440 @@ | |||
1 | #include <windows.h> | ||
2 | #include <process.h> | ||
3 | #include "uisw32.h" | ||
4 | #include "lcd.h" | ||
5 | |||
6 | #ifdef HAVE_LCD_CHARCELLS | ||
7 | # ifndef JBP_OLD | ||
8 | |||
9 | static char const lcd_ascii[] = | ||
10 | { | ||
11 | /*****************************************************************************************/ | ||
12 | /* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF */ | ||
13 | /* ************************************************************************************/ | ||
14 | /* 0x */ 0x00,0x01,0x02,0x03,0x00,0x00,0x00,0x00,0x04,0x05,0x00,0x00,0x00,0x00,0x00,0x00, | ||
15 | /* 1x */ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, | ||
16 | /* 2x */ 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F, | ||
17 | /* 3x */ 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F, | ||
18 | /* 4x */ 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F, | ||
19 | /* 5x */ 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F, | ||
20 | /* 6x */ 0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F, | ||
21 | /* 7x */ 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x20,0x20,0x20,0x20,0x20, | ||
22 | /* 8x */ 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, | ||
23 | /* 9x */ 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, | ||
24 | /* Ax */ 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, | ||
25 | /* Bx */ 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, | ||
26 | /* Cx */ 0x41,0x41,0x41,0x41,0x41,0x41,0x20,0x43,0x45,0x45,0x45,0x45,0x49,0x49,0x49,0x49, | ||
27 | /* Dx */ 0x44,0x4E,0x4F,0x4F,0x4F,0x4F,0x4F,0x20,0x20,0x55,0x55,0x55,0x55,0x59,0x20,0x20, | ||
28 | /* Ex */ 0x61,0x61,0x61,0x61,0x61,0x61,0x20,0x63,0x65,0x65,0x65,0x65,0x69,0x69,0x69,0x69, | ||
29 | /* Fx */ 0x64,0x6E,0x6F,0x6F,0x6F,0x6F,0x6F,0x20,0x20,0x75,0x75,0x75,0x75,0x79,0x79,0x79 | ||
30 | /******/ | ||
31 | }; | ||
32 | |||
33 | # else | ||
34 | |||
35 | static char const lcd_ascii[] = | ||
36 | { | ||
37 | /*****************************************************************************************/ | ||
38 | /* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF */ | ||
39 | /* ************************************************************************************/ | ||
40 | /* 0x */ 0x00,0x01,0x02,0x03,0x00,0x00,0x00,0x00,0x85,0x89,0x00,0x00,0x00,0x00,0x00,0x00, | ||
41 | /* 1x */ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, | ||
42 | /* 2x */ 0x24,0x25,0x26,0x37,0x06,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,0x31,0x32,0x33, | ||
43 | /* 3x */ 0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,0x40,0x41,0x42,0x43, | ||
44 | /* 4x */ 0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,0x50,0x51,0x52,0x53, | ||
45 | /* 5x */ 0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0xA9,0x33,0xCE,0x00,0x15, | ||
46 | /* 6x */ 0x00,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,0x70,0x71,0x72,0x73, | ||
47 | /* 7x */ 0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x24,0x24,0x24,0x24,0x24, | ||
48 | /* 8x */ 0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24, | ||
49 | /* 9x */ 0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24, | ||
50 | /* Ax */ 0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24, | ||
51 | /* Bx */ 0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24, | ||
52 | /* Cx */ 0x45,0x45,0x45,0x45,0x45,0x45,0x24,0x47,0x49,0x49,0x49,0x49,0x4D,0x4D,0x4D,0x4D, | ||
53 | /* Dx */ 0x48,0x52,0x53,0x53,0x53,0x53,0x53,0x24,0x24,0x59,0x59,0x59,0x59,0x5D,0x24,0x24, | ||
54 | /* Ex */ 0x65,0x65,0x65,0x65,0x65,0x65,0x24,0x67,0x69,0x69,0x69,0x69,0x6D,0x6D,0x6D,0x6D, | ||
55 | /* Fx */ 0x73,0x72,0x73,0x73,0x73,0x73,0x73,0x24,0x24,0x79,0x79,0x79,0x79,0x7D,0x24,0x7D | ||
56 | /******/ | ||
57 | }; | ||
58 | |||
59 | # endif | ||
60 | |||
61 | void lcd_puts (char const *string) | ||
62 | { | ||
63 | while (*string) | ||
64 | lcd_data (LCD_ASCII(*string++)); | ||
65 | } | ||
66 | |||
67 | void lcd_putns (char const *string,int n) | ||
68 | { | ||
69 | while (n--) | ||
70 | lcd_data (LCD_ASCII(*string++)); | ||
71 | } | ||
72 | |||
73 | void lcd_putc (int character) | ||
74 | { | ||
75 | lcd_data (LCD_ASCII(character)); | ||
76 | } | ||
77 | |||
78 | void lcd_pattern (int which,char const *pattern,int count) | ||
79 | { | ||
80 | lcd_instruction (LCD_PRAM|which); | ||
81 | lcd_copy ((void *)pattern,count); | ||
82 | } | ||
83 | |||
84 | void lcd_puthex (unsigned int value,int digits) | ||
85 | { | ||
86 | switch (digits) { | ||
87 | case 8: | ||
88 | lcd_puthex (value >> 16,4); | ||
89 | case 4: | ||
90 | lcd_puthex (value >> 8,2); | ||
91 | case 2: | ||
92 | lcd_puthex (value >> 4,1); | ||
93 | case 1: | ||
94 | value &= 15; | ||
95 | lcd_putc (value+((value < 10) ? '0' : ('A'-10))); | ||
96 | } | ||
97 | } | ||
98 | |||
99 | |||
100 | /* HAVE_LCD_CHARCELLS */ | ||
101 | #elif defined(HAVE_LCD_BITMAP) | ||
102 | |||
103 | /* | ||
104 | * All bitmaps have this format: | ||
105 | * Bits within a byte are arranged veritcally, LSB at top. | ||
106 | * Bytes are stored in column-major format, with byte 0 at top left, | ||
107 | * byte 1 is 2nd from top, etc. Bytes following left-most column | ||
108 | * starts 2nd left column, etc. | ||
109 | * | ||
110 | * Note: The HW takes bitmap bytes in row-major order. | ||
111 | * | ||
112 | * Memory copy of display bitmap | ||
113 | */ | ||
114 | unsigned char display[DISP_X][DISP_Y/8]; | ||
115 | |||
116 | /* | ||
117 | * ASCII character generation tables | ||
118 | * | ||
119 | * This contains only the printable characters (0x20-0x7f). | ||
120 | * Each element in this table is a character pattern bitmap. | ||
121 | */ | ||
122 | #define ASCII_MIN 0x20 /* First char in table */ | ||
123 | #define ASCII_MAX 0x7f /* Last char in table */ | ||
124 | |||
125 | extern const unsigned char char_gen_6x8[][5][1]; | ||
126 | extern const unsigned char char_gen_8x12[][7][2]; | ||
127 | extern const unsigned char char_gen_12x16[][11][2]; | ||
128 | |||
129 | |||
130 | /* All zeros and ones bitmaps for area filling */ | ||
131 | static const unsigned char zeros[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
132 | 0x00, 0x00 }; | ||
133 | static const unsigned char ones[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
134 | 0xff, 0xff }; | ||
135 | |||
136 | static int lcd_y; /* Current pixel row */ | ||
137 | static int lcd_x; /* Current pixel column */ | ||
138 | static int lcd_size; /* Current font width */ | ||
139 | |||
140 | /* | ||
141 | * Clear the display | ||
142 | */ | ||
143 | void lcd_clear_display (void) | ||
144 | { | ||
145 | lcd_position (0, 0, 8); | ||
146 | memset (display, 0, sizeof display); | ||
147 | } | ||
148 | |||
149 | /* | ||
150 | * Set current x,y position and font size | ||
151 | */ | ||
152 | void lcd_position (int x, int y, int size) | ||
153 | { | ||
154 | if (x >= 0 && x < DISP_X && y >= 0 && y < DISP_Y) | ||
155 | { | ||
156 | lcd_x = x; | ||
157 | lcd_y = y; | ||
158 | } | ||
159 | |||
160 | lcd_size = size; | ||
161 | } | ||
162 | |||
163 | /* | ||
164 | * Display a string at current position and size | ||
165 | */ | ||
166 | void lcd_string (const char *str) | ||
167 | { | ||
168 | int x = lcd_x; | ||
169 | int nx = lcd_size; | ||
170 | int ny, ch; | ||
171 | const unsigned char *src; | ||
172 | |||
173 | if (nx == 12) | ||
174 | ny = 16; | ||
175 | else if (nx == 8) | ||
176 | ny = 12; | ||
177 | else | ||
178 | { | ||
179 | nx = 6; | ||
180 | ny = 8; | ||
181 | } | ||
182 | |||
183 | while ((ch = *str++) != '\0') | ||
184 | { | ||
185 | if (ch == '\n' || lcd_x + nx > DISP_X) | ||
186 | { | ||
187 | /* Wrap to next line */ | ||
188 | lcd_x = x; | ||
189 | lcd_y += ny; | ||
190 | } | ||
191 | |||
192 | if (lcd_y + ny > DISP_Y) | ||
193 | return; | ||
194 | |||
195 | /* Limit to char generation table */ | ||
196 | if (ch >= ASCII_MIN && ch <= ASCII_MAX) | ||
197 | { | ||
198 | if (nx == 12) | ||
199 | src = char_gen_12x16[ch-ASCII_MIN][0]; | ||
200 | else if (nx == 8) | ||
201 | src = char_gen_8x12[ch-ASCII_MIN][0]; | ||
202 | else | ||
203 | src = char_gen_6x8[ch-ASCII_MIN][0]; | ||
204 | |||
205 | lcd_bitmap (src, lcd_x, lcd_y, nx-1, ny, TRUE); | ||
206 | lcd_bitmap (zeros, lcd_x+nx-1, lcd_y, 1, ny, TRUE); | ||
207 | |||
208 | lcd_x += nx; | ||
209 | } | ||
210 | } | ||
211 | } | ||
212 | |||
213 | /* | ||
214 | * Display a bitmap at (x, y), size (nx, ny) | ||
215 | * clear is TRUE to clear destination area first | ||
216 | */ | ||
217 | void lcd_bitmap (const unsigned char *src, int x, int y, int nx, int ny, | ||
218 | bool clear) | ||
219 | { | ||
220 | unsigned char *dst; | ||
221 | unsigned char *dst2 = &display[x][y/8]; | ||
222 | unsigned int data, mask, mask2, mask3, mask4; | ||
223 | int shift = y & 7; | ||
224 | |||
225 | ny += shift; | ||
226 | |||
227 | /* Calculate bit masks */ | ||
228 | mask4 = ~(0xfe << ((ny-1) & 7)); | ||
229 | if (clear) | ||
230 | { | ||
231 | mask = ~(0xff << shift); | ||
232 | mask2 = 0; | ||
233 | mask3 = ~mask4; | ||
234 | if (ny <= 8) | ||
235 | mask3 |= mask; | ||
236 | } | ||
237 | else | ||
238 | mask = mask2 = mask3 = 0xff; | ||
239 | |||
240 | /* Loop for each column */ | ||
241 | for (x = 0; x < nx; x++) | ||
242 | { | ||
243 | dst = dst2; | ||
244 | dst2 += DISP_Y/8; | ||
245 | data = 0; | ||
246 | y = 0; | ||
247 | |||
248 | if (ny > 8) | ||
249 | { | ||
250 | /* First partial row */ | ||
251 | data = *src++ << shift; | ||
252 | *dst = (*dst & mask) ^ data; | ||
253 | data >>= 8; | ||
254 | dst++; | ||
255 | |||
256 | /* Intermediate rows */ | ||
257 | for (y = 8; y < ny-8; y += 8) | ||
258 | { | ||
259 | data |= *src++ << shift; | ||
260 | *dst = (*dst & mask2) ^ data; | ||
261 | data >>= 8; | ||
262 | dst++; | ||
263 | } | ||
264 | } | ||
265 | |||
266 | /* Last partial row */ | ||
267 | if (y + shift < ny) | ||
268 | data |= *src++ << shift; | ||
269 | *dst = (*dst & mask3) ^ (data & mask4); | ||
270 | } | ||
271 | } | ||
272 | |||
273 | /* | ||
274 | * Clear a rectangular area at (x, y), size (nx, ny) | ||
275 | */ | ||
276 | void lcd_clearrect (int x, int y, int nx, int ny) | ||
277 | { | ||
278 | int i; | ||
279 | for (i = 0; i < nx; i++) | ||
280 | lcd_bitmap (zeros, x+i, y, 1, ny, TRUE); | ||
281 | } | ||
282 | |||
283 | /* | ||
284 | * Fill a rectangular area at (x, y), size (nx, ny) | ||
285 | */ | ||
286 | void lcd_fillrect (int x, int y, int nx, int ny) | ||
287 | { | ||
288 | int i; | ||
289 | for (i = 0; i < nx; i++) | ||
290 | lcd_bitmap (ones, x+i, y, 1, ny, TRUE); | ||
291 | } | ||
292 | |||
293 | /* Invert a rectangular area at (x, y), size (nx, ny) */ | ||
294 | void lcd_invertrect (int x, int y, int nx, int ny) | ||
295 | { | ||
296 | int i; | ||
297 | for (i = 0; i < nx; i++) | ||
298 | lcd_bitmap (ones, x+i, y, 1, ny, FALSE); | ||
299 | } | ||
300 | |||
301 | #define DRAW_PIXEL(x,y) display[x][y/8] |= (1<<(y&7)) | ||
302 | #define CLEAR_PIXEL(x,y) display[x][y/8] &= ~(1<<(y&7)) | ||
303 | |||
304 | void lcd_drawline( int x1, int y1, int x2, int y2 ) | ||
305 | { | ||
306 | int numpixels; | ||
307 | int i; | ||
308 | int deltax, deltay; | ||
309 | int d, dinc1, dinc2; | ||
310 | int x, xinc1, xinc2; | ||
311 | int y, yinc1, yinc2; | ||
312 | |||
313 | deltax = abs(x2 - x1); | ||
314 | deltay = abs(y2 - y1); | ||
315 | |||
316 | if(deltax >= deltay) | ||
317 | { | ||
318 | numpixels = deltax; | ||
319 | d = 2 * deltay - deltax; | ||
320 | dinc1 = deltay * 2; | ||
321 | dinc2 = (deltay - deltax) * 2; | ||
322 | xinc1 = 1; | ||
323 | xinc2 = 1; | ||
324 | yinc1 = 0; | ||
325 | yinc2 = 1; | ||
326 | } | ||
327 | else | ||
328 | { | ||
329 | numpixels = deltay; | ||
330 | d = 2 * deltax - deltay; | ||
331 | dinc1 = deltax * 2; | ||
332 | dinc2 = (deltax - deltay) * 2; | ||
333 | xinc1 = 0; | ||
334 | xinc2 = 1; | ||
335 | yinc1 = 1; | ||
336 | yinc2 = 1; | ||
337 | } | ||
338 | numpixels++; /* include endpoints */ | ||
339 | |||
340 | if(x1 > x2) | ||
341 | { | ||
342 | xinc1 = -xinc1; | ||
343 | xinc2 = -xinc2; | ||
344 | } | ||
345 | |||
346 | if(y1 > y2) | ||
347 | { | ||
348 | yinc1 = -yinc1; | ||
349 | yinc2 = -yinc2; | ||
350 | } | ||
351 | |||
352 | x = x1; | ||
353 | y = y1; | ||
354 | |||
355 | for(i=0; i<numpixels; i++) | ||
356 | { | ||
357 | DRAW_PIXEL(x,y); | ||
358 | |||
359 | if(d < 0) | ||
360 | { | ||
361 | d += dinc1; | ||
362 | x += xinc1; | ||
363 | y += yinc1; | ||
364 | } | ||
365 | else | ||
366 | { | ||
367 | d += dinc2; | ||
368 | x += xinc2; | ||
369 | y += yinc2; | ||
370 | } | ||
371 | } | ||
372 | } | ||
373 | |||
374 | /* | ||
375 | * Set a single pixel | ||
376 | */ | ||
377 | void lcd_drawpixel(int x, int y) | ||
378 | { | ||
379 | DRAW_PIXEL(x,y); | ||
380 | } | ||
381 | |||
382 | /* | ||
383 | * Clear a single pixel | ||
384 | */ | ||
385 | void lcd_clearpixel(int x, int y) | ||
386 | { | ||
387 | CLEAR_PIXEL(x,y); | ||
388 | } | ||
389 | |||
390 | |||
391 | #else | ||
392 | /* no LCD defined, no code to use */ | ||
393 | #endif | ||
394 | |||
395 | // | ||
396 | // | ||
397 | // | ||
398 | // simulator specific code | ||
399 | // | ||
400 | // | ||
401 | // | ||
402 | |||
403 | // varaibles | ||
404 | unsigned char display[DISP_X][DISP_Y/8]; // the display | ||
405 | char bitmap[DISP_Y][DISP_X]; // the ui display | ||
406 | |||
407 | BITMAPINFO2 bmi = | ||
408 | { | ||
409 | sizeof (BITMAPINFOHEADER), | ||
410 | DISP_X, -DISP_Y, 1, 8, | ||
411 | BI_RGB, 0, 0, 0, 2, 2, | ||
412 | UI_LCD_COLOR, 0, // green background color | ||
413 | 0, 0, 0, 0 // black color | ||
414 | }; // bitmap information | ||
415 | |||
416 | |||
417 | // lcd_init | ||
418 | // init lcd controler | ||
419 | void lcd_init() | ||
420 | { | ||
421 | lcd_clear_display (); | ||
422 | } | ||
423 | |||
424 | // lcd_update | ||
425 | // update lcd | ||
426 | void lcd_update() | ||
427 | { | ||
428 | int x, y; | ||
429 | if (hGUIWnd == NULL) | ||
430 | _endthread (); | ||
431 | |||
432 | for (x = 0; x < DISP_X; x++) | ||
433 | for (y = 0; y < DISP_Y; y++) | ||
434 | bitmap[y][x] = ((display[x][y/8] >> (y & 7)) & 1); | ||
435 | |||
436 | InvalidateRect (hGUIWnd, NULL, FALSE); | ||
437 | |||
438 | // natural sleep :) | ||
439 | Sleep (50); | ||
440 | } \ No newline at end of file | ||
diff --git a/uisimulator/win32/main.cpp b/uisimulator/win32/main.cpp new file mode 100644 index 0000000000..7c3c66f967 --- /dev/null +++ b/uisimulator/win32/main.cpp | |||
@@ -0,0 +1,29 @@ | |||
1 | #include "uisw32.h" | ||
2 | #include "lcd-win32.h" | ||
3 | |||
4 | #define FS 6 | ||
5 | |||
6 | int main (void) | ||
7 | { | ||
8 | int x; | ||
9 | lcd_init (); | ||
10 | |||
11 | while (1) | ||
12 | { | ||
13 | for (x = 0; x < 10; x++) | ||
14 | { | ||
15 | lcd_clear_display (); | ||
16 | lcd_position (x, 12, FS); | ||
17 | lcd_string ("Hello World!"); | ||
18 | lcd_position (x, 32, FS); | ||
19 | lcd_string ("From the"); | ||
20 | lcd_position (x, 40, FS); | ||
21 | lcd_string (" Open Source "); | ||
22 | lcd_position (x, 48, FS); | ||
23 | lcd_string ("Jukebox Project"); | ||
24 | lcd_update (); | ||
25 | } | ||
26 | } | ||
27 | |||
28 | return 0; | ||
29 | } \ No newline at end of file | ||
diff --git a/uisimulator/win32/resource.h b/uisimulator/win32/resource.h new file mode 100644 index 0000000000..0e45d58d95 --- /dev/null +++ b/uisimulator/win32/resource.h | |||
@@ -0,0 +1,17 @@ | |||
1 | //{{NO_DEPENDENCIES}} | ||
2 | // Microsoft Visual C++ generated include file. | ||
3 | // Used by uisw32.rc | ||
4 | // | ||
5 | #define IDB_BITMAP1 102 | ||
6 | #define IDB_UI 102 | ||
7 | |||
8 | // Next default values for new objects | ||
9 | // | ||
10 | #ifdef APSTUDIO_INVOKED | ||
11 | #ifndef APSTUDIO_READONLY_SYMBOLS | ||
12 | #define _APS_NEXT_RESOURCE_VALUE 103 | ||
13 | #define _APS_NEXT_COMMAND_VALUE 40001 | ||
14 | #define _APS_NEXT_CONTROL_VALUE 1001 | ||
15 | #define _APS_NEXT_SYMED_VALUE 101 | ||
16 | #endif | ||
17 | #endif | ||
diff --git a/uisimulator/win32/tetris.c b/uisimulator/win32/tetris.c new file mode 100644 index 0000000000..040539bf6a --- /dev/null +++ b/uisimulator/win32/tetris.c | |||
@@ -0,0 +1,288 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 1999 Mattis Wadman (nappe@sudac.org) | ||
11 | * | ||
12 | * Heavily modified for embedded use by Björn Stenberg (bjorn@haxx.se) | ||
13 | * | ||
14 | * All files in this archive are subject to the GNU General Public License. | ||
15 | * See the file COPYING in the source tree root for full license agreement. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "types.h" | ||
23 | #include "lcd.h" | ||
24 | #include "button.h" | ||
25 | #include "kernel.h" | ||
26 | |||
27 | #ifdef SIMULATOR | ||
28 | #include <stdio.h> | ||
29 | // #include <unistd.h> | ||
30 | #endif | ||
31 | |||
32 | int start_x = 1; | ||
33 | int start_y = 1; | ||
34 | int max_x = 14; | ||
35 | int max_y = 24; | ||
36 | int current_x = 0; | ||
37 | int current_y = 0; | ||
38 | int current_f = 0; | ||
39 | int current_b = 0; | ||
40 | int level = 0; | ||
41 | short lines = 0; | ||
42 | int score = 0; | ||
43 | int next_b = 0; | ||
44 | int next_f = 0; | ||
45 | char virtual[LCD_WIDTH*LCD_HEIGHT]; | ||
46 | short level_speeds[10] = {1000,900,800,700,600,500,400,300,250,200}; | ||
47 | int blocks = 7; | ||
48 | int block_frames[7] = {1,2,2,2,4,4,4}; | ||
49 | int block_data[7][4][2][4] = | ||
50 | { | ||
51 | { | ||
52 | {{0,1,0,1},{0,0,1,1}} | ||
53 | }, | ||
54 | { | ||
55 | {{0,1,1,2},{1,1,0,0}}, | ||
56 | {{0,0,1,1},{0,1,1,2}} | ||
57 | }, | ||
58 | { | ||
59 | {{0,1,1,2},{0,0,1,1}}, | ||
60 | {{1,1,0,0},{0,1,1,2}} | ||
61 | }, | ||
62 | { | ||
63 | {{1,1,1,1},{0,1,2,3}}, | ||
64 | {{0,1,2,3},{2,2,2,2}} | ||
65 | }, | ||
66 | { | ||
67 | {{1,1,1,2},{2,1,0,0}}, | ||
68 | {{0,1,2,2},{1,1,1,2}}, | ||
69 | {{0,1,1,1},{2,2,1,0}}, | ||
70 | {{0,0,1,2},{0,1,1,1}} | ||
71 | }, | ||
72 | { | ||
73 | {{0,1,1,1},{0,0,1,2}}, | ||
74 | {{0,1,2,2},{1,1,1,0}}, | ||
75 | {{1,1,1,2},{0,1,2,2}}, | ||
76 | {{0,0,1,2},{2,1,1,1}} | ||
77 | }, | ||
78 | { | ||
79 | {{1,0,1,2},{0,1,1,1}}, | ||
80 | {{2,1,1,1},{1,0,1,2}}, | ||
81 | {{1,0,1,2},{2,1,1,1}}, | ||
82 | {{0,1,1,1},{1,0,1,2}} | ||
83 | } | ||
84 | }; | ||
85 | |||
86 | /* not even pseudo random :) */ | ||
87 | int rand(int range) | ||
88 | { | ||
89 | static int count; | ||
90 | count++; | ||
91 | return count % range; | ||
92 | } | ||
93 | |||
94 | void draw_frame(int fstart_x,int fstop_x,int fstart_y,int fstop_y) | ||
95 | { | ||
96 | int i; | ||
97 | for (i=0; fstart_x+i-1 < fstop_x; i++) | ||
98 | { | ||
99 | lcd_drawpixel(fstart_x+i,fstart_y); | ||
100 | lcd_drawpixel(fstart_x+i,fstop_y); | ||
101 | } | ||
102 | for (i=1; fstart_y+i < fstop_y; i++) | ||
103 | { | ||
104 | lcd_drawpixel(fstart_x,fstart_y+i); | ||
105 | lcd_drawpixel(fstop_x,fstart_y+i); | ||
106 | } | ||
107 | lcd_drawpixel(fstart_x,fstart_y); | ||
108 | lcd_drawpixel(fstop_x,fstart_y); | ||
109 | lcd_drawpixel(fstart_x,fstop_y); | ||
110 | lcd_drawpixel(fstop_x,fstop_y); | ||
111 | } | ||
112 | |||
113 | void draw_block(int x,int y,int block,int frame,int clear) | ||
114 | { | ||
115 | int i; | ||
116 | for(i=0;i < 4;i++) | ||
117 | if ( (clear ? 0 : block+1) ) | ||
118 | lcd_drawpixel(start_x+x+block_data[block][frame][0][i], | ||
119 | start_y+y+block_data[block][frame][1][i]); | ||
120 | else | ||
121 | lcd_clearpixel(start_x+x+block_data[block][frame][0][i], | ||
122 | start_y+y+block_data[block][frame][1][i]); | ||
123 | } | ||
124 | |||
125 | void to_virtual() | ||
126 | { | ||
127 | int i; | ||
128 | for(i=0;i < 4;i++) | ||
129 | *(virtual+ | ||
130 | ((current_y+block_data[current_b][current_f][1][i])*max_x)+ | ||
131 | (current_x+block_data[current_b][current_f][0][i])) = current_b+1; | ||
132 | } | ||
133 | |||
134 | int valid_position(int x,int y,int block,int frame) | ||
135 | { | ||
136 | int i; | ||
137 | for(i=0;i < 4;i++) | ||
138 | if( (*(virtual+((y+block_data[block][frame][1][i])*max_x)+x+ | ||
139 | block_data[block][frame][0][i]) != 0) || | ||
140 | (x+block_data[block][frame][0][i] < 0) || | ||
141 | (x+block_data[block][frame][0][i] > max_x-1) || | ||
142 | (y+block_data[block][frame][1][i] < 0) || | ||
143 | (y+block_data[block][frame][1][i] > max_y-1)) | ||
144 | return FALSE; | ||
145 | return TRUE; | ||
146 | } | ||
147 | |||
148 | void from_virtual() | ||
149 | { | ||
150 | int x,y; | ||
151 | for(y=0;y < max_y;y++) | ||
152 | for(x=0;x < max_x;x++) | ||
153 | if(*(virtual+(y*max_x)+x)) | ||
154 | lcd_drawpixel(start_x+x,start_y+y); | ||
155 | else | ||
156 | lcd_clearpixel(start_x+x,start_y+y); | ||
157 | } | ||
158 | |||
159 | void move_block(int x,int y,int f) | ||
160 | { | ||
161 | int last_frame = current_f; | ||
162 | if(f != 0) | ||
163 | { | ||
164 | current_f += f; | ||
165 | if(current_f > block_frames[current_b]-1) | ||
166 | current_f = 0; | ||
167 | if(current_f < 0) | ||
168 | current_f = block_frames[current_b]-1; | ||
169 | } | ||
170 | if(valid_position(current_x+x,current_y+y,current_b,current_f)) | ||
171 | { | ||
172 | draw_block(current_x,current_y,current_b,last_frame,TRUE); | ||
173 | current_x += x; | ||
174 | current_y += y; | ||
175 | draw_block(current_x,current_y,current_b,current_f,FALSE); | ||
176 | lcd_update(); | ||
177 | } | ||
178 | else | ||
179 | current_f = last_frame; | ||
180 | } | ||
181 | |||
182 | void new_block() | ||
183 | { | ||
184 | current_b = next_b; | ||
185 | current_f = next_f; | ||
186 | current_x = (int)((max_x)/2)-1; | ||
187 | current_y = 0; | ||
188 | next_b = rand(blocks); | ||
189 | next_f = rand(block_frames[next_b]); | ||
190 | draw_block(max_x+2,start_y-1,current_b,current_f,TRUE); | ||
191 | draw_block(max_x+2,start_y-1,next_b,next_f,FALSE); | ||
192 | if(!valid_position(current_x,current_y,current_b,current_f)) | ||
193 | { | ||
194 | draw_block(current_x,current_y,current_b,current_f,FALSE); | ||
195 | lcd_update(); | ||
196 | } | ||
197 | else | ||
198 | draw_block(current_x,current_y,current_b,current_f,FALSE); | ||
199 | } | ||
200 | |||
201 | int check_lines() | ||
202 | { | ||
203 | int x,y,line,i; | ||
204 | int lines = 0; | ||
205 | for(y=0;y < max_y;y++) | ||
206 | { | ||
207 | line = TRUE; | ||
208 | for(x=0;x < max_x;x++) | ||
209 | if(virtual[y*max_x+x] == 0) | ||
210 | line = FALSE; | ||
211 | if(line) | ||
212 | { | ||
213 | lines++; | ||
214 | for(i=y;i > 1;i--) | ||
215 | for (x=0;x<max_x;x++) | ||
216 | virtual[i*max_x] = virtual[((i-1)*max_x)]; | ||
217 | for (x=0;x<max_x;x++) | ||
218 | virtual[max_x] = 0; | ||
219 | } | ||
220 | } | ||
221 | return lines; | ||
222 | } | ||
223 | |||
224 | void move_down() | ||
225 | { | ||
226 | int l; | ||
227 | if(!valid_position(current_x,current_y+1,current_b,current_f)) | ||
228 | { | ||
229 | to_virtual(); | ||
230 | l = check_lines(); | ||
231 | if(l) | ||
232 | { | ||
233 | lines += l; | ||
234 | level = (int)lines/10; | ||
235 | if(level > 9) | ||
236 | level = 9; | ||
237 | from_virtual(); | ||
238 | score += l*l; | ||
239 | } | ||
240 | new_block(); | ||
241 | move_block(0,0,0); | ||
242 | } | ||
243 | else | ||
244 | move_block(0,1,0); | ||
245 | } | ||
246 | |||
247 | void game_loop(void) | ||
248 | { | ||
249 | while(1) | ||
250 | { | ||
251 | int b=0; | ||
252 | int count = 0; | ||
253 | /* while(count*20 < level_speeds[level]) */ | ||
254 | { | ||
255 | b = button_get(); | ||
256 | if ( b & BUTTON_LEFT ) { | ||
257 | printf("Left\n"); | ||
258 | move_block(-1,0,0); | ||
259 | } | ||
260 | if ( b & BUTTON_RIGHT ) { | ||
261 | printf("Right\n"); | ||
262 | move_block(1,0,0); | ||
263 | } | ||
264 | if ( b & BUTTON_UP ) { | ||
265 | printf("Up\n"); | ||
266 | move_block(0,0,1); | ||
267 | } | ||
268 | if ( b & BUTTON_DOWN ) { | ||
269 | printf("Down\n"); | ||
270 | move_down(); | ||
271 | } | ||
272 | count++; | ||
273 | sleep(HZ/4); | ||
274 | } | ||
275 | move_down(); | ||
276 | } | ||
277 | } | ||
278 | |||
279 | void main(void) | ||
280 | { | ||
281 | draw_frame(start_x-1,start_x+max_x,start_y-1,start_y+max_y); | ||
282 | lcd_update(); | ||
283 | |||
284 | next_b = rand(blocks); | ||
285 | next_f = rand(block_frames[next_b]); | ||
286 | new_block(); | ||
287 | game_loop(); | ||
288 | } | ||
diff --git a/uisimulator/win32/uisw32.cpp b/uisimulator/win32/uisw32.cpp new file mode 100644 index 0000000000..6bc1bedb00 --- /dev/null +++ b/uisimulator/win32/uisw32.cpp | |||
@@ -0,0 +1,259 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * Copyright (C) 2002 by Felix Arends | ||
10 | * | ||
11 | * All files in this archive are subject to the GNU General Public License. | ||
12 | * See the file COPYING in the source tree root for full license agreement. | ||
13 | * | ||
14 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
15 | * KIND, either express or implied. | ||
16 | * | ||
17 | ****************************************************************************/ | ||
18 | |||
19 | #include <windows.h> | ||
20 | #include <process.h> | ||
21 | #include "uisw32.h" | ||
22 | #include "resource.h" | ||
23 | |||
24 | // extern functions | ||
25 | extern void main (void *); // mod entry point | ||
26 | |||
27 | // variables | ||
28 | HWND hGUIWnd; // the GUI window handle | ||
29 | unsigned int uThreadID; // id of mod thread | ||
30 | PBYTE lpKeys; | ||
31 | |||
32 | // GUIWndProc | ||
33 | // window proc for GUI simulator | ||
34 | LRESULT GUIWndProc ( | ||
35 | HWND hWnd, | ||
36 | UINT uMsg, | ||
37 | WPARAM wParam, | ||
38 | LPARAM lParam | ||
39 | ) | ||
40 | { | ||
41 | static HBITMAP hBkgnd; | ||
42 | static lpBmp [UI_WIDTH * UI_HEIGHT * 3]; | ||
43 | static HDC hMemDc; | ||
44 | |||
45 | switch (uMsg) | ||
46 | { | ||
47 | case WM_CREATE: | ||
48 | // load background image | ||
49 | hBkgnd = (HBITMAP)LoadImage (GetModuleHandle (NULL), MAKEINTRESOURCE(IDB_UI), | ||
50 | IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR); | ||
51 | hMemDc = CreateCompatibleDC (GetDC (hWnd)); | ||
52 | SelectObject (hMemDc, hBkgnd); | ||
53 | return TRUE; | ||
54 | case WM_SIZING: | ||
55 | { | ||
56 | LPRECT r = (LPRECT)lParam; | ||
57 | RECT r2; | ||
58 | char s[256]; | ||
59 | int v; | ||
60 | |||
61 | switch (wParam) | ||
62 | { | ||
63 | case WMSZ_BOTTOM: | ||
64 | v = (r->bottom - r->top) / (UI_HEIGHT / 5); | ||
65 | r->bottom = r->top + v * UI_HEIGHT / 5; | ||
66 | r->right = r->left + v * UI_WIDTH / 5; | ||
67 | r->right += GetSystemMetrics (SM_CXSIZEFRAME) * 2; | ||
68 | r->bottom += GetSystemMetrics (SM_CYSIZEFRAME) * 2 + GetSystemMetrics (SM_CYSMCAPTION); | ||
69 | break; | ||
70 | case WMSZ_RIGHT: | ||
71 | v = (r->right - r->left) / (UI_WIDTH / 5); | ||
72 | r->bottom = r->top + v * UI_HEIGHT / 5; | ||
73 | r->right = r->left + v * UI_WIDTH / 5; | ||
74 | r->right += GetSystemMetrics (SM_CXSIZEFRAME) * 2; | ||
75 | r->bottom += GetSystemMetrics (SM_CYSIZEFRAME) * 2 + GetSystemMetrics (SM_CYSMCAPTION); | ||
76 | break; | ||
77 | case WMSZ_TOP: | ||
78 | v = (r->bottom - r->top) / (UI_HEIGHT / 5); | ||
79 | r->top = r->bottom - v * UI_HEIGHT / 5; | ||
80 | r->right = r->left + v * UI_WIDTH / 5; | ||
81 | r->right += GetSystemMetrics (SM_CXSIZEFRAME) * 2; | ||
82 | r->top -= GetSystemMetrics (SM_CYSIZEFRAME) * 2 + GetSystemMetrics (SM_CYSMCAPTION); | ||
83 | break; | ||
84 | case WMSZ_LEFT: | ||
85 | v = (r->right - r->left) / (UI_WIDTH / 5); | ||
86 | r->bottom = r->top + v * UI_HEIGHT / 5; | ||
87 | r->left = r->right - v * UI_WIDTH / 5; | ||
88 | r->left -= GetSystemMetrics (SM_CXSIZEFRAME) * 2; | ||
89 | r->bottom += GetSystemMetrics (SM_CYSIZEFRAME) * 2 + GetSystemMetrics (SM_CYSMCAPTION); | ||
90 | break; | ||
91 | case WMSZ_BOTTOMRIGHT: | ||
92 | GetWindowRect (hWnd, &r2); | ||
93 | if (abs(r2.right - r->right) > abs(r2.bottom - r->bottom)) | ||
94 | v = (r->right - r->left) / (UI_WIDTH / 5); | ||
95 | else | ||
96 | v = (r->bottom - r->top) / (UI_HEIGHT / 5); | ||
97 | r->bottom = r->top + v * UI_HEIGHT / 5; | ||
98 | r->right = r->left + v * UI_WIDTH / 5; | ||
99 | r->right += GetSystemMetrics (SM_CXSIZEFRAME) * 2; | ||
100 | r->bottom += GetSystemMetrics (SM_CYSIZEFRAME) * 2 + GetSystemMetrics (SM_CYSMCAPTION); | ||
101 | break; | ||
102 | case WMSZ_BOTTOMLEFT: | ||
103 | GetWindowRect (hWnd, &r2); | ||
104 | if (abs(r2.left - r->left) > abs(r2.bottom - r->bottom)) | ||
105 | v = (r->right - r->left) / (UI_WIDTH / 5); | ||
106 | else | ||
107 | v = (r->bottom - r->top) / (UI_HEIGHT / 5); | ||
108 | r->bottom = r->top + v * UI_HEIGHT / 5; | ||
109 | r->left = r->right - v * UI_WIDTH / 5; | ||
110 | r->left -= GetSystemMetrics (SM_CXSIZEFRAME) * 2; | ||
111 | r->bottom += GetSystemMetrics (SM_CYSIZEFRAME) * 2 + GetSystemMetrics (SM_CYSMCAPTION); | ||
112 | break; | ||
113 | case WMSZ_TOPRIGHT: | ||
114 | GetWindowRect (hWnd, &r2); | ||
115 | if (abs(r2.right - r->right) > abs(r2.top - r->top)) | ||
116 | v = (r->right - r->left) / (UI_WIDTH / 5); | ||
117 | else | ||
118 | v = (r->bottom - r->top) / (UI_HEIGHT / 5); | ||
119 | r->top = r->bottom - v * UI_HEIGHT / 5; | ||
120 | r->right = r->left + v * UI_WIDTH / 5; | ||
121 | r->right += GetSystemMetrics (SM_CXSIZEFRAME) * 2; | ||
122 | r->top -= GetSystemMetrics (SM_CYSIZEFRAME) * 2 + GetSystemMetrics (SM_CYSMCAPTION); | ||
123 | break; | ||
124 | case WMSZ_TOPLEFT: | ||
125 | GetWindowRect (hWnd, &r2); | ||
126 | if (abs(r2.left - r->left) > abs(r2.top - r->top)) | ||
127 | v = (r->right - r->left) / (UI_WIDTH / 5); | ||
128 | else | ||
129 | v = (r->bottom - r->top) / (UI_HEIGHT / 5); | ||
130 | r->top = r->bottom - v * UI_HEIGHT / 5; | ||
131 | r->left = r->right - v * UI_WIDTH / 5; | ||
132 | r->left -= GetSystemMetrics (SM_CXSIZEFRAME) * 2; | ||
133 | r->top -= GetSystemMetrics (SM_CYSIZEFRAME) * 2 + GetSystemMetrics (SM_CYSMCAPTION); | ||
134 | break; | ||
135 | } | ||
136 | |||
137 | wsprintf (s, "RockBox Simulator @%d%%", | ||
138 | (r->right - r->left - GetSystemMetrics (SM_CXSIZEFRAME) * 2) | ||
139 | * 100 / UI_WIDTH); | ||
140 | SetWindowText (hWnd, s); | ||
141 | |||
142 | return TRUE; | ||
143 | } | ||
144 | case WM_ERASEBKGND: | ||
145 | { | ||
146 | PAINTSTRUCT ps; | ||
147 | HDC hDc = BeginPaint (hWnd, &ps); | ||
148 | RECT r; | ||
149 | |||
150 | GetClientRect (hWnd, &r); | ||
151 | // blit to screen | ||
152 | StretchBlt (hDc, 0, 0, r.right, r.bottom, | ||
153 | hMemDc, 0, 0, UI_WIDTH, UI_HEIGHT, SRCCOPY); | ||
154 | EndPaint (hWnd, &ps); | ||
155 | return TRUE; | ||
156 | } | ||
157 | case WM_PAINT: | ||
158 | { | ||
159 | PAINTSTRUCT ps; | ||
160 | RECT r; | ||
161 | HDC hDc = BeginPaint (hWnd, &ps); | ||
162 | |||
163 | GetClientRect (hWnd, &r); | ||
164 | // draw lcd screen | ||
165 | StretchDIBits (hDc, | ||
166 | UI_LCD_POSX * r.right / UI_WIDTH, UI_LCD_POSY * r.bottom / UI_HEIGHT, | ||
167 | DISP_X * r.right / UI_WIDTH, DISP_Y * r.bottom / UI_HEIGHT, | ||
168 | 0, 0, DISP_X, DISP_Y, | ||
169 | bitmap, (BITMAPINFO *) &bmi, DIB_RGB_COLORS, SRCCOPY); | ||
170 | |||
171 | EndPaint (hWnd, &ps); | ||
172 | return TRUE; | ||
173 | } | ||
174 | case WM_CLOSE: | ||
175 | // close simulator | ||
176 | hGUIWnd = NULL; | ||
177 | PostQuitMessage (0); | ||
178 | break; | ||
179 | } | ||
180 | |||
181 | return DefWindowProc (hWnd, uMsg, wParam, lParam); | ||
182 | } | ||
183 | |||
184 | // GUIStartup | ||
185 | // register window class, show window, init GUI | ||
186 | BOOL GUIStartup () | ||
187 | { | ||
188 | WNDCLASS wc; | ||
189 | |||
190 | // create window class | ||
191 | ZeroMemory (&wc, sizeof(wc)); | ||
192 | wc.hbrBackground = GetSysColorBrush (COLOR_WINDOW); | ||
193 | wc.hCursor = LoadCursor (NULL, IDC_ARROW); | ||
194 | wc.hInstance = GetModuleHandle (NULL); | ||
195 | wc.lpfnWndProc = (WNDPROC)GUIWndProc; | ||
196 | wc.lpszClassName = "RockBoxUISimulator"; | ||
197 | wc.style = CS_HREDRAW | CS_VREDRAW; | ||
198 | |||
199 | if (RegisterClass (&wc) == 0) | ||
200 | return FALSE; | ||
201 | |||
202 | // create window | ||
203 | hGUIWnd = CreateWindowEx ( | ||
204 | WS_EX_TOOLWINDOW | WS_EX_PALETTEWINDOW, | ||
205 | "RockBoxUISimulator", "ARCHOS JukeBox", | ||
206 | WS_VISIBLE | WS_SYSMENU | WS_OVERLAPPEDWINDOW, | ||
207 | CW_USEDEFAULT, CW_USEDEFAULT, | ||
208 | UI_WIDTH + GetSystemMetrics (SM_CXSIZEFRAME) * 2, | ||
209 | UI_HEIGHT + GetSystemMetrics (SM_CYSIZEFRAME) * 2 + GetSystemMetrics (SM_CYSMCAPTION), | ||
210 | NULL, NULL, GetModuleHandle (NULL), NULL); | ||
211 | |||
212 | if (hGUIWnd == NULL) | ||
213 | return FALSE; | ||
214 | |||
215 | return TRUE; | ||
216 | } | ||
217 | |||
218 | // GUIDown | ||
219 | // destroy window, unregister window class | ||
220 | int GUIDown () | ||
221 | { | ||
222 | DestroyWindow (hGUIWnd); | ||
223 | _endthreadex (uThreadID); | ||
224 | return 0; | ||
225 | } | ||
226 | |||
227 | // GUIMessageLoop | ||
228 | // standard message loop for GUI window | ||
229 | void GUIMessageLoop () | ||
230 | { | ||
231 | MSG msg; | ||
232 | while (GetMessage (&msg, hGUIWnd, 0, 0) && hGUIWnd != NULL) | ||
233 | { | ||
234 | TranslateMessage (&msg); | ||
235 | DispatchMessage (&msg); | ||
236 | } | ||
237 | } | ||
238 | |||
239 | |||
240 | // WinMain | ||
241 | // program entry point | ||
242 | int WINAPI WinMain ( | ||
243 | HINSTANCE hInstance, // current instance | ||
244 | HINSTANCE hPrevInstance, // previous instance | ||
245 | LPSTR lpCmd, // command line | ||
246 | int nShowCmd // show command | ||
247 | ) | ||
248 | { | ||
249 | if (!GUIStartup ()) | ||
250 | return 0; | ||
251 | |||
252 | uThreadID = _beginthread (main, 0, NULL); | ||
253 | if (uThreadID == -0L) | ||
254 | return MessageBox (NULL, "Error creating mod thread!", "Error", MB_OK); | ||
255 | |||
256 | GUIMessageLoop (); | ||
257 | |||
258 | return GUIDown (); | ||
259 | } \ No newline at end of file | ||
diff --git a/uisimulator/win32/uisw32.h b/uisimulator/win32/uisw32.h new file mode 100644 index 0000000000..c1001d7222 --- /dev/null +++ b/uisimulator/win32/uisw32.h | |||
@@ -0,0 +1,39 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * Copyright (C) 2002 by Felix Arends | ||
10 | * | ||
11 | * All files in this archive are subject to the GNU General Public License. | ||
12 | * See the file COPYING in the source tree root for full license agreement. | ||
13 | * | ||
14 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
15 | * KIND, either express or implied. | ||
16 | * | ||
17 | ****************************************************************************/ | ||
18 | |||
19 | #ifndef __UISW32_H__ | ||
20 | #define __UISW32_H__ | ||
21 | |||
22 | #include <windows.h> | ||
23 | #include "lcd-win32.h" | ||
24 | |||
25 | #define UI_WIDTH 240 // width of GUI window | ||
26 | #define UI_HEIGHT 360 // height of GUI window | ||
27 | #define UI_LCD_COLOR 46, 57, 49 // bkgnd color of LCD | ||
28 | #define UI_LCD_BLACK RGB (0, 0, 0) // black | ||
29 | #define UI_LCD_POSX 59 // x position of lcd | ||
30 | #define UI_LCD_POSY 95 // y position of lcd | ||
31 | |||
32 | extern HWND hGUIWnd; // the GUI window handle | ||
33 | extern unsigned int uThreadID; // id of mod thread | ||
34 | |||
35 | // typedefs | ||
36 | typedef unsigned char uchar; | ||
37 | typedef unsigned int uint32; | ||
38 | |||
39 | #endif // #ifndef __UISW32_H__ \ No newline at end of file | ||
diff --git a/uisimulator/win32/uisw32.sln b/uisimulator/win32/uisw32.sln new file mode 100644 index 0000000000..ada5e11e7c --- /dev/null +++ b/uisimulator/win32/uisw32.sln | |||
@@ -0,0 +1,21 @@ | |||
1 | Microsoft Visual Studio Solution File, Format Version 7.00 | ||
2 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "uisw32", "uisw32.vcproj", "{A81A8EFA-647A-427A-BD04-F6B469752E7A}" | ||
3 | EndProject | ||
4 | Global | ||
5 | GlobalSection(SolutionConfiguration) = preSolution | ||
6 | ConfigName.0 = Debug | ||
7 | ConfigName.1 = Release | ||
8 | EndGlobalSection | ||
9 | GlobalSection(ProjectDependencies) = postSolution | ||
10 | EndGlobalSection | ||
11 | GlobalSection(ProjectConfiguration) = postSolution | ||
12 | {A81A8EFA-647A-427A-BD04-F6B469752E7A}.Debug.ActiveCfg = Debug|Win32 | ||
13 | {A81A8EFA-647A-427A-BD04-F6B469752E7A}.Debug.Build.0 = Debug|Win32 | ||
14 | {A81A8EFA-647A-427A-BD04-F6B469752E7A}.Release.ActiveCfg = Release|Win32 | ||
15 | {A81A8EFA-647A-427A-BD04-F6B469752E7A}.Release.Build.0 = Release|Win32 | ||
16 | EndGlobalSection | ||
17 | GlobalSection(ExtensibilityGlobals) = postSolution | ||
18 | EndGlobalSection | ||
19 | GlobalSection(ExtensibilityAddIns) = postSolution | ||
20 | EndGlobalSection | ||
21 | EndGlobal | ||
diff --git a/uisimulator/win32/uisw32.suo b/uisimulator/win32/uisw32.suo new file mode 100644 index 0000000000..f86d8f4bcf --- /dev/null +++ b/uisimulator/win32/uisw32.suo | |||
Binary files differ | |||
diff --git a/uisimulator/win32/uisw32.vcproj b/uisimulator/win32/uisw32.vcproj new file mode 100644 index 0000000000..c19c4eef05 --- /dev/null +++ b/uisimulator/win32/uisw32.vcproj | |||
@@ -0,0 +1,154 @@ | |||
1 | <?xml version="1.0" encoding = "Windows-1252"?> | ||
2 | <VisualStudioProject | ||
3 | ProjectType="Visual C++" | ||
4 | Version="7.00" | ||
5 | Name="uisw32" | ||
6 | ProjectGUID="{A81A8EFA-647A-427A-BD04-F6B469752E7A}" | ||
7 | Keyword="Win32Proj"> | ||
8 | <Platforms> | ||
9 | <Platform | ||
10 | Name="Win32"/> | ||
11 | </Platforms> | ||
12 | <Configurations> | ||
13 | <Configuration | ||
14 | Name="Debug|Win32" | ||
15 | OutputDirectory="Debug" | ||
16 | IntermediateDirectory="Debug" | ||
17 | ConfigurationType="1" | ||
18 | CharacterSet="2"> | ||
19 | <Tool | ||
20 | Name="VCCLCompilerTool" | ||
21 | Optimization="0" | ||
22 | AdditionalIncludeDirectories=""C:\Programming\CVS Checkout\firmware";"C:\Programming\CVS Checkout\firmware\drivers"" | ||
23 | PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;ARCHOS_RECORDER;SIMULATOR" | ||
24 | MinimalRebuild="TRUE" | ||
25 | BasicRuntimeChecks="3" | ||
26 | RuntimeLibrary="1" | ||
27 | UsePrecompiledHeader="0" | ||
28 | WarningLevel="3" | ||
29 | Detect64BitPortabilityProblems="FALSE" | ||
30 | DebugInformationFormat="4" | ||
31 | CompileAs="1"/> | ||
32 | <Tool | ||
33 | Name="VCCustomBuildTool"/> | ||
34 | <Tool | ||
35 | Name="VCLinkerTool" | ||
36 | OutputFile="$(OutDir)/uisw32.exe" | ||
37 | LinkIncremental="2" | ||
38 | GenerateDebugInformation="TRUE" | ||
39 | ProgramDatabaseFile="$(OutDir)/uisw32.pdb" | ||
40 | SubSystem="2" | ||
41 | TargetMachine="1"/> | ||
42 | <Tool | ||
43 | Name="VCMIDLTool"/> | ||
44 | <Tool | ||
45 | Name="VCPostBuildEventTool"/> | ||
46 | <Tool | ||
47 | Name="VCPreBuildEventTool"/> | ||
48 | <Tool | ||
49 | Name="VCPreLinkEventTool"/> | ||
50 | <Tool | ||
51 | Name="VCResourceCompilerTool"/> | ||
52 | <Tool | ||
53 | Name="VCWebServiceProxyGeneratorTool"/> | ||
54 | <Tool | ||
55 | Name="VCWebDeploymentTool"/> | ||
56 | </Configuration> | ||
57 | <Configuration | ||
58 | Name="Release|Win32" | ||
59 | OutputDirectory="Release" | ||
60 | IntermediateDirectory="Release" | ||
61 | ConfigurationType="1" | ||
62 | CharacterSet="2"> | ||
63 | <Tool | ||
64 | Name="VCCLCompilerTool" | ||
65 | Optimization="2" | ||
66 | InlineFunctionExpansion="1" | ||
67 | OmitFramePointers="TRUE" | ||
68 | AdditionalIncludeDirectories=""C:\Programming\CVS Checkout\firmware\drivers";"C:\Programming\CVS Checkout\firmware"" | ||
69 | PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;ARCHOS_RECORDER;SIMULATOR" | ||
70 | StringPooling="TRUE" | ||
71 | RuntimeLibrary="0" | ||
72 | EnableFunctionLevelLinking="TRUE" | ||
73 | UsePrecompiledHeader="0" | ||
74 | WarningLevel="3" | ||
75 | Detect64BitPortabilityProblems="FALSE" | ||
76 | DebugInformationFormat="3" | ||
77 | CompileAs="1"/> | ||
78 | <Tool | ||
79 | Name="VCCustomBuildTool"/> | ||
80 | <Tool | ||
81 | Name="VCLinkerTool" | ||
82 | OutputFile="$(OutDir)/uisw32.exe" | ||
83 | LinkIncremental="1" | ||
84 | GenerateDebugInformation="TRUE" | ||
85 | SubSystem="2" | ||
86 | OptimizeReferences="2" | ||
87 | EnableCOMDATFolding="2" | ||
88 | TargetMachine="1"/> | ||
89 | <Tool | ||
90 | Name="VCMIDLTool"/> | ||
91 | <Tool | ||
92 | Name="VCPostBuildEventTool"/> | ||
93 | <Tool | ||
94 | Name="VCPreBuildEventTool"/> | ||
95 | <Tool | ||
96 | Name="VCPreLinkEventTool"/> | ||
97 | <Tool | ||
98 | Name="VCResourceCompilerTool"/> | ||
99 | <Tool | ||
100 | Name="VCWebServiceProxyGeneratorTool"/> | ||
101 | <Tool | ||
102 | Name="VCWebDeploymentTool"/> | ||
103 | </Configuration> | ||
104 | </Configurations> | ||
105 | <Files> | ||
106 | <Filter | ||
107 | Name="Source Files" | ||
108 | Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm"> | ||
109 | <File | ||
110 | RelativePath="button.c"> | ||
111 | </File> | ||
112 | <File | ||
113 | RelativePath="..\..\firmware\chartables.c"> | ||
114 | </File> | ||
115 | <File | ||
116 | RelativePath="kernel.c"> | ||
117 | </File> | ||
118 | <File | ||
119 | RelativePath="lcd.c"> | ||
120 | </File> | ||
121 | <File | ||
122 | RelativePath="tetris.c"> | ||
123 | </File> | ||
124 | <File | ||
125 | RelativePath="uisw32.cpp"> | ||
126 | </File> | ||
127 | </Filter> | ||
128 | <Filter | ||
129 | Name="Header Files" | ||
130 | Filter="h;hpp;hxx;hm;inl;inc"> | ||
131 | <File | ||
132 | RelativePath="lcd-win32.h"> | ||
133 | </File> | ||
134 | <File | ||
135 | RelativePath="resource.h"> | ||
136 | </File> | ||
137 | <File | ||
138 | RelativePath="uisw32.h"> | ||
139 | </File> | ||
140 | </Filter> | ||
141 | <Filter | ||
142 | Name="Resource Files" | ||
143 | Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"> | ||
144 | <File | ||
145 | RelativePath="UI.bmp"> | ||
146 | </File> | ||
147 | <File | ||
148 | RelativePath="uisw32.rc"> | ||
149 | </File> | ||
150 | </Filter> | ||
151 | </Files> | ||
152 | <Globals> | ||
153 | </Globals> | ||
154 | </VisualStudioProject> | ||