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
This commit is contained in:
Felix Arends 2002-04-25 04:41:45 +00:00
parent 7b9581a131
commit 144bc70a12
13 changed files with 1347 additions and 0 deletions

BIN
uisimulator/win32/UI.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 253 KiB

View File

@ -0,0 +1,47 @@
#include <windows.h>
#include "config.h"
#include "sh7034.h"
#include "button.h"
#define KEY(k) HIBYTE(GetKeyState (k))
void button_init(void) {}int button_get(void)
{
int btn = 0;
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_NUMPAD8) ||
KEY (VK_UP))
btn |= BUTTON_UP; // up button
if (KEY (VK_NUMPAD2) ||
KEY (VK_DOWN))
btn |= BUTTON_DOWN; // down button
if (KEY (VK_NUMPAD5) ||
KEY (VK_SPACE))
btn |= BUTTON_PLAY; // play button
if (KEY (VK_RETURN))
btn |= BUTTON_OFF; // off button
if (KEY (VK_ADD))
btn |= BUTTON_ON; // on button
if (KEY (VK_DIVIDE))
btn |= BUTTON_F1; // F1 button
if (KEY (VK_MULTIPLY))
btn |= BUTTON_F2; // F2 button
if (KEY (VK_SUBTRACT))
btn |= BUTTON_F3; // F3 button
return btn;
}

View File

@ -0,0 +1,26 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2002 by Björn Stenberg, 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 "kernel.h"
void sleep(int ticks)
{
Sleep (1000 / HZ * ticks);
}

View File

@ -0,0 +1,27 @@
#ifndef __LCDWIN32_H__
#define __LCDWIN32_H__
#include "uisw32.h"
#include "lcd.h"
// BITMAPINFO2
typedef struct
{
BITMAPINFOHEADER bmiHeader;
RGBQUAD bmiColors[2];
} BITMAPINFO2;
#ifdef HAVE_LCD_BITMAP
extern unsigned char display[DISP_X][DISP_Y/8]; // the display
#else
#define DISP_X 112
#define DISP_Y 64
#endif
extern char bitmap[DISP_Y][DISP_X]; // the ui display
extern BITMAPINFO2 bmi; // bitmap information
#endif // #ifndef __LCDWIN32_H__

440
uisimulator/win32/lcd.c Normal file
View File

@ -0,0 +1,440 @@
#include <windows.h>
#include <process.h>
#include "uisw32.h"
#include "lcd.h"
#ifdef HAVE_LCD_CHARCELLS
# ifndef JBP_OLD
static char const lcd_ascii[] =
{
/*****************************************************************************************/
/* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF */
/* ************************************************************************************/
/* 0x */ 0x00,0x01,0x02,0x03,0x00,0x00,0x00,0x00,0x04,0x05,0x00,0x00,0x00,0x00,0x00,0x00,
/* 1x */ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/* 2x */ 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,
/* 3x */ 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,
/* 4x */ 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,
/* 5x */ 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F,
/* 6x */ 0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,
/* 7x */ 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x20,0x20,0x20,0x20,0x20,
/* 8x */ 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
/* 9x */ 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
/* Ax */ 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
/* Bx */ 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
/* Cx */ 0x41,0x41,0x41,0x41,0x41,0x41,0x20,0x43,0x45,0x45,0x45,0x45,0x49,0x49,0x49,0x49,
/* Dx */ 0x44,0x4E,0x4F,0x4F,0x4F,0x4F,0x4F,0x20,0x20,0x55,0x55,0x55,0x55,0x59,0x20,0x20,
/* Ex */ 0x61,0x61,0x61,0x61,0x61,0x61,0x20,0x63,0x65,0x65,0x65,0x65,0x69,0x69,0x69,0x69,
/* Fx */ 0x64,0x6E,0x6F,0x6F,0x6F,0x6F,0x6F,0x20,0x20,0x75,0x75,0x75,0x75,0x79,0x79,0x79
/******/
};
# else
static char const lcd_ascii[] =
{
/*****************************************************************************************/
/* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF */
/* ************************************************************************************/
/* 0x */ 0x00,0x01,0x02,0x03,0x00,0x00,0x00,0x00,0x85,0x89,0x00,0x00,0x00,0x00,0x00,0x00,
/* 1x */ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/* 2x */ 0x24,0x25,0x26,0x37,0x06,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,
/* 3x */ 0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,0x40,0x41,0x42,0x43,
/* 4x */ 0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,
/* 5x */ 0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0xA9,0x33,0xCE,0x00,0x15,
/* 6x */ 0x00,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,0x70,0x71,0x72,0x73,
/* 7x */ 0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x24,0x24,0x24,0x24,0x24,
/* 8x */ 0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,
/* 9x */ 0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,
/* Ax */ 0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,
/* Bx */ 0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,
/* Cx */ 0x45,0x45,0x45,0x45,0x45,0x45,0x24,0x47,0x49,0x49,0x49,0x49,0x4D,0x4D,0x4D,0x4D,
/* Dx */ 0x48,0x52,0x53,0x53,0x53,0x53,0x53,0x24,0x24,0x59,0x59,0x59,0x59,0x5D,0x24,0x24,
/* Ex */ 0x65,0x65,0x65,0x65,0x65,0x65,0x24,0x67,0x69,0x69,0x69,0x69,0x6D,0x6D,0x6D,0x6D,
/* Fx */ 0x73,0x72,0x73,0x73,0x73,0x73,0x73,0x24,0x24,0x79,0x79,0x79,0x79,0x7D,0x24,0x7D
/******/
};
# endif
void lcd_puts (char const *string)
{
while (*string)
lcd_data (LCD_ASCII(*string++));
}
void lcd_putns (char const *string,int n)
{
while (n--)
lcd_data (LCD_ASCII(*string++));
}
void lcd_putc (int character)
{
lcd_data (LCD_ASCII(character));
}
void lcd_pattern (int which,char const *pattern,int count)
{
lcd_instruction (LCD_PRAM|which);
lcd_copy ((void *)pattern,count);
}
void lcd_puthex (unsigned int value,int digits)
{
switch (digits) {
case 8:
lcd_puthex (value >> 16,4);
case 4:
lcd_puthex (value >> 8,2);
case 2:
lcd_puthex (value >> 4,1);
case 1:
value &= 15;
lcd_putc (value+((value < 10) ? '0' : ('A'-10)));
}
}
/* HAVE_LCD_CHARCELLS */
#elif defined(HAVE_LCD_BITMAP)
/*
* All bitmaps have this format:
* Bits within a byte are arranged veritcally, LSB at top.
* Bytes are stored in column-major format, with byte 0 at top left,
* byte 1 is 2nd from top, etc. Bytes following left-most column
* starts 2nd left column, etc.
*
* Note: The HW takes bitmap bytes in row-major order.
*
* Memory copy of display bitmap
*/
unsigned char display[DISP_X][DISP_Y/8];
/*
* ASCII character generation tables
*
* This contains only the printable characters (0x20-0x7f).
* Each element in this table is a character pattern bitmap.
*/
#define ASCII_MIN 0x20 /* First char in table */
#define ASCII_MAX 0x7f /* Last char in table */
extern const unsigned char char_gen_6x8[][5][1];
extern const unsigned char char_gen_8x12[][7][2];
extern const unsigned char char_gen_12x16[][11][2];
/* All zeros and ones bitmaps for area filling */
static const unsigned char zeros[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00 };
static const unsigned char ones[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff };
static int lcd_y; /* Current pixel row */
static int lcd_x; /* Current pixel column */
static int lcd_size; /* Current font width */
/*
* Clear the display
*/
void lcd_clear_display (void)
{
lcd_position (0, 0, 8);
memset (display, 0, sizeof display);
}
/*
* Set current x,y position and font size
*/
void lcd_position (int x, int y, int size)
{
if (x >= 0 && x < DISP_X && y >= 0 && y < DISP_Y)
{
lcd_x = x;
lcd_y = y;
}
lcd_size = size;
}
/*
* Display a string at current position and size
*/
void lcd_string (const char *str)
{
int x = lcd_x;
int nx = lcd_size;
int ny, ch;
const unsigned char *src;
if (nx == 12)
ny = 16;
else if (nx == 8)
ny = 12;
else
{
nx = 6;
ny = 8;
}
while ((ch = *str++) != '\0')
{
if (ch == '\n' || lcd_x + nx > DISP_X)
{
/* Wrap to next line */
lcd_x = x;
lcd_y += ny;
}
if (lcd_y + ny > DISP_Y)
return;
/* Limit to char generation table */
if (ch >= ASCII_MIN && ch <= ASCII_MAX)
{
if (nx == 12)
src = char_gen_12x16[ch-ASCII_MIN][0];
else if (nx == 8)
src = char_gen_8x12[ch-ASCII_MIN][0];
else
src = char_gen_6x8[ch-ASCII_MIN][0];
lcd_bitmap (src, lcd_x, lcd_y, nx-1, ny, TRUE);
lcd_bitmap (zeros, lcd_x+nx-1, lcd_y, 1, ny, TRUE);
lcd_x += nx;
}
}
}
/*
* Display a bitmap at (x, y), size (nx, ny)
* clear is TRUE to clear destination area first
*/
void lcd_bitmap (const unsigned char *src, int x, int y, int nx, int ny,
bool clear)
{
unsigned char *dst;
unsigned char *dst2 = &display[x][y/8];
unsigned int data, mask, mask2, mask3, mask4;
int shift = y & 7;
ny += shift;
/* Calculate bit masks */
mask4 = ~(0xfe << ((ny-1) & 7));
if (clear)
{
mask = ~(0xff << shift);
mask2 = 0;
mask3 = ~mask4;
if (ny <= 8)
mask3 |= mask;
}
else
mask = mask2 = mask3 = 0xff;
/* Loop for each column */
for (x = 0; x < nx; x++)
{
dst = dst2;
dst2 += DISP_Y/8;
data = 0;
y = 0;
if (ny > 8)
{
/* First partial row */
data = *src++ << shift;
*dst = (*dst & mask) ^ data;
data >>= 8;
dst++;
/* Intermediate rows */
for (y = 8; y < ny-8; y += 8)
{
data |= *src++ << shift;
*dst = (*dst & mask2) ^ data;
data >>= 8;
dst++;
}
}
/* Last partial row */
if (y + shift < ny)
data |= *src++ << shift;
*dst = (*dst & mask3) ^ (data & mask4);
}
}
/*
* Clear a rectangular area at (x, y), size (nx, ny)
*/
void lcd_clearrect (int x, int y, int nx, int ny)
{
int i;
for (i = 0; i < nx; i++)
lcd_bitmap (zeros, x+i, y, 1, ny, TRUE);
}
/*
* Fill a rectangular area at (x, y), size (nx, ny)
*/
void lcd_fillrect (int x, int y, int nx, int ny)
{
int i;
for (i = 0; i < nx; i++)
lcd_bitmap (ones, x+i, y, 1, ny, TRUE);
}
/* Invert a rectangular area at (x, y), size (nx, ny) */
void lcd_invertrect (int x, int y, int nx, int ny)
{
int i;
for (i = 0; i < nx; i++)
lcd_bitmap (ones, x+i, y, 1, ny, FALSE);
}
#define DRAW_PIXEL(x,y) display[x][y/8] |= (1<<(y&7))
#define CLEAR_PIXEL(x,y) display[x][y/8] &= ~(1<<(y&7))
void lcd_drawline( int x1, int y1, int x2, int y2 )
{
int numpixels;
int i;
int deltax, deltay;
int d, dinc1, dinc2;
int x, xinc1, xinc2;
int y, yinc1, yinc2;
deltax = abs(x2 - x1);
deltay = abs(y2 - y1);
if(deltax >= deltay)
{
numpixels = deltax;
d = 2 * deltay - deltax;
dinc1 = deltay * 2;
dinc2 = (deltay - deltax) * 2;
xinc1 = 1;
xinc2 = 1;
yinc1 = 0;
yinc2 = 1;
}
else
{
numpixels = deltay;
d = 2 * deltax - deltay;
dinc1 = deltax * 2;
dinc2 = (deltax - deltay) * 2;
xinc1 = 0;
xinc2 = 1;
yinc1 = 1;
yinc2 = 1;
}
numpixels++; /* include endpoints */
if(x1 > x2)
{
xinc1 = -xinc1;
xinc2 = -xinc2;
}
if(y1 > y2)
{
yinc1 = -yinc1;
yinc2 = -yinc2;
}
x = x1;
y = y1;
for(i=0; i<numpixels; i++)
{
DRAW_PIXEL(x,y);
if(d < 0)
{
d += dinc1;
x += xinc1;
y += yinc1;
}
else
{
d += dinc2;
x += xinc2;
y += yinc2;
}
}
}
/*
* Set a single pixel
*/
void lcd_drawpixel(int x, int y)
{
DRAW_PIXEL(x,y);
}
/*
* Clear a single pixel
*/
void lcd_clearpixel(int x, int y)
{
CLEAR_PIXEL(x,y);
}
#else
/* no LCD defined, no code to use */
#endif
//
//
//
// simulator specific code
//
//
//
// varaibles
unsigned char display[DISP_X][DISP_Y/8]; // the display
char bitmap[DISP_Y][DISP_X]; // the ui display
BITMAPINFO2 bmi =
{
sizeof (BITMAPINFOHEADER),
DISP_X, -DISP_Y, 1, 8,
BI_RGB, 0, 0, 0, 2, 2,
UI_LCD_COLOR, 0, // green background color
0, 0, 0, 0 // black color
}; // bitmap information
// lcd_init
// init lcd controler
void lcd_init()
{
lcd_clear_display ();
}
// lcd_update
// update lcd
void lcd_update()
{
int x, y;
if (hGUIWnd == NULL)
_endthread ();
for (x = 0; x < DISP_X; x++)
for (y = 0; y < DISP_Y; y++)
bitmap[y][x] = ((display[x][y/8] >> (y & 7)) & 1);
InvalidateRect (hGUIWnd, NULL, FALSE);
// natural sleep :)
Sleep (50);
}

View File

@ -0,0 +1,29 @@
#include "uisw32.h"
#include "lcd-win32.h"
#define FS 6
int main (void)
{
int x;
lcd_init ();
while (1)
{
for (x = 0; x < 10; x++)
{
lcd_clear_display ();
lcd_position (x, 12, FS);
lcd_string ("Hello World!");
lcd_position (x, 32, FS);
lcd_string ("From the");
lcd_position (x, 40, FS);
lcd_string (" Open Source ");
lcd_position (x, 48, FS);
lcd_string ("Jukebox Project");
lcd_update ();
}
}
return 0;
}

View File

@ -0,0 +1,17 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by uisw32.rc
//
#define IDB_BITMAP1 102
#define IDB_UI 102
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 103
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

288
uisimulator/win32/tetris.c Normal file
View File

@ -0,0 +1,288 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 1999 Mattis Wadman (nappe@sudac.org)
*
* Heavily modified for embedded use by Björn Stenberg (bjorn@haxx.se)
*
* 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 "types.h"
#include "lcd.h"
#include "button.h"
#include "kernel.h"
#ifdef SIMULATOR
#include <stdio.h>
// #include <unistd.h>
#endif
int start_x = 1;
int start_y = 1;
int max_x = 14;
int max_y = 24;
int current_x = 0;
int current_y = 0;
int current_f = 0;
int current_b = 0;
int level = 0;
short lines = 0;
int score = 0;
int next_b = 0;
int next_f = 0;
char virtual[LCD_WIDTH*LCD_HEIGHT];
short level_speeds[10] = {1000,900,800,700,600,500,400,300,250,200};
int blocks = 7;
int block_frames[7] = {1,2,2,2,4,4,4};
int block_data[7][4][2][4] =
{
{
{{0,1,0,1},{0,0,1,1}}
},
{
{{0,1,1,2},{1,1,0,0}},
{{0,0,1,1},{0,1,1,2}}
},
{
{{0,1,1,2},{0,0,1,1}},
{{1,1,0,0},{0,1,1,2}}
},
{
{{1,1,1,1},{0,1,2,3}},
{{0,1,2,3},{2,2,2,2}}
},
{
{{1,1,1,2},{2,1,0,0}},
{{0,1,2,2},{1,1,1,2}},
{{0,1,1,1},{2,2,1,0}},
{{0,0,1,2},{0,1,1,1}}
},
{
{{0,1,1,1},{0,0,1,2}},
{{0,1,2,2},{1,1,1,0}},
{{1,1,1,2},{0,1,2,2}},
{{0,0,1,2},{2,1,1,1}}
},
{
{{1,0,1,2},{0,1,1,1}},
{{2,1,1,1},{1,0,1,2}},
{{1,0,1,2},{2,1,1,1}},
{{0,1,1,1},{1,0,1,2}}
}
};
/* not even pseudo random :) */
int rand(int range)
{
static int count;
count++;
return count % range;
}
void draw_frame(int fstart_x,int fstop_x,int fstart_y,int fstop_y)
{
int i;
for (i=0; fstart_x+i-1 < fstop_x; i++)
{
lcd_drawpixel(fstart_x+i,fstart_y);
lcd_drawpixel(fstart_x+i,fstop_y);
}
for (i=1; fstart_y+i < fstop_y; i++)
{
lcd_drawpixel(fstart_x,fstart_y+i);
lcd_drawpixel(fstop_x,fstart_y+i);
}
lcd_drawpixel(fstart_x,fstart_y);
lcd_drawpixel(fstop_x,fstart_y);
lcd_drawpixel(fstart_x,fstop_y);
lcd_drawpixel(fstop_x,fstop_y);
}
void draw_block(int x,int y,int block,int frame,int clear)
{
int i;
for(i=0;i < 4;i++)
if ( (clear ? 0 : block+1) )
lcd_drawpixel(start_x+x+block_data[block][frame][0][i],
start_y+y+block_data[block][frame][1][i]);
else
lcd_clearpixel(start_x+x+block_data[block][frame][0][i],
start_y+y+block_data[block][frame][1][i]);
}
void to_virtual()
{
int i;
for(i=0;i < 4;i++)
*(virtual+
((current_y+block_data[current_b][current_f][1][i])*max_x)+
(current_x+block_data[current_b][current_f][0][i])) = current_b+1;
}
int valid_position(int x,int y,int block,int frame)
{
int i;
for(i=0;i < 4;i++)
if( (*(virtual+((y+block_data[block][frame][1][i])*max_x)+x+
block_data[block][frame][0][i]) != 0) ||
(x+block_data[block][frame][0][i] < 0) ||
(x+block_data[block][frame][0][i] > max_x-1) ||
(y+block_data[block][frame][1][i] < 0) ||
(y+block_data[block][frame][1][i] > max_y-1))
return FALSE;
return TRUE;
}
void from_virtual()
{
int x,y;
for(y=0;y < max_y;y++)
for(x=0;x < max_x;x++)
if(*(virtual+(y*max_x)+x))
lcd_drawpixel(start_x+x,start_y+y);
else
lcd_clearpixel(start_x+x,start_y+y);
}
void move_block(int x,int y,int f)
{
int last_frame = current_f;
if(f != 0)
{
current_f += f;
if(current_f > block_frames[current_b]-1)
current_f = 0;
if(current_f < 0)
current_f = block_frames[current_b]-1;
}
if(valid_position(current_x+x,current_y+y,current_b,current_f))
{
draw_block(current_x,current_y,current_b,last_frame,TRUE);
current_x += x;
current_y += y;
draw_block(current_x,current_y,current_b,current_f,FALSE);
lcd_update();
}
else
current_f = last_frame;
}
void new_block()
{
current_b = next_b;
current_f = next_f;
current_x = (int)((max_x)/2)-1;
current_y = 0;
next_b = rand(blocks);
next_f = rand(block_frames[next_b]);
draw_block(max_x+2,start_y-1,current_b,current_f,TRUE);
draw_block(max_x+2,start_y-1,next_b,next_f,FALSE);
if(!valid_position(current_x,current_y,current_b,current_f))
{
draw_block(current_x,current_y,current_b,current_f,FALSE);
lcd_update();
}
else
draw_block(current_x,current_y,current_b,current_f,FALSE);
}
int check_lines()
{
int x,y,line,i;
int lines = 0;
for(y=0;y < max_y;y++)
{
line = TRUE;
for(x=0;x < max_x;x++)
if(virtual[y*max_x+x] == 0)
line = FALSE;
if(line)
{
lines++;
for(i=y;i > 1;i--)
for (x=0;x<max_x;x++)
virtual[i*max_x] = virtual[((i-1)*max_x)];
for (x=0;x<max_x;x++)
virtual[max_x] = 0;
}
}
return lines;
}
void move_down()
{
int l;
if(!valid_position(current_x,current_y+1,current_b,current_f))
{
to_virtual();
l = check_lines();
if(l)
{
lines += l;
level = (int)lines/10;
if(level > 9)
level = 9;
from_virtual();
score += l*l;
}
new_block();
move_block(0,0,0);
}
else
move_block(0,1,0);
}
void game_loop(void)
{
while(1)
{
int b=0;
int count = 0;
/* while(count*20 < level_speeds[level]) */
{
b = button_get();
if ( b & BUTTON_LEFT ) {
printf("Left\n");
move_block(-1,0,0);
}
if ( b & BUTTON_RIGHT ) {
printf("Right\n");
move_block(1,0,0);
}
if ( b & BUTTON_UP ) {
printf("Up\n");
move_block(0,0,1);
}
if ( b & BUTTON_DOWN ) {
printf("Down\n");
move_down();
}
count++;
sleep(HZ/4);
}
move_down();
}
}
void main(void)
{
draw_frame(start_x-1,start_x+max_x,start_y-1,start_y+max_y);
lcd_update();
next_b = rand(blocks);
next_f = rand(block_frames[next_b]);
new_block();
game_loop();
}

View File

@ -0,0 +1,259 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
*
* 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>
#include "uisw32.h"
#include "resource.h"
// extern functions
extern void main (void *); // mod entry point
// variables
HWND hGUIWnd; // the GUI window handle
unsigned int uThreadID; // id of mod thread
PBYTE lpKeys;
// GUIWndProc
// window proc for GUI simulator
LRESULT GUIWndProc (
HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
static HBITMAP hBkgnd;
static lpBmp [UI_WIDTH * UI_HEIGHT * 3];
static HDC hMemDc;
switch (uMsg)
{
case WM_CREATE:
// load background image
hBkgnd = (HBITMAP)LoadImage (GetModuleHandle (NULL), MAKEINTRESOURCE(IDB_UI),
IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
hMemDc = CreateCompatibleDC (GetDC (hWnd));
SelectObject (hMemDc, hBkgnd);
return TRUE;
case WM_SIZING:
{
LPRECT r = (LPRECT)lParam;
RECT r2;
char s[256];
int v;
switch (wParam)
{
case WMSZ_BOTTOM:
v = (r->bottom - r->top) / (UI_HEIGHT / 5);
r->bottom = r->top + v * UI_HEIGHT / 5;
r->right = r->left + v * UI_WIDTH / 5;
r->right += GetSystemMetrics (SM_CXSIZEFRAME) * 2;
r->bottom += GetSystemMetrics (SM_CYSIZEFRAME) * 2 + GetSystemMetrics (SM_CYSMCAPTION);
break;
case WMSZ_RIGHT:
v = (r->right - r->left) / (UI_WIDTH / 5);
r->bottom = r->top + v * UI_HEIGHT / 5;
r->right = r->left + v * UI_WIDTH / 5;
r->right += GetSystemMetrics (SM_CXSIZEFRAME) * 2;
r->bottom += GetSystemMetrics (SM_CYSIZEFRAME) * 2 + GetSystemMetrics (SM_CYSMCAPTION);
break;
case WMSZ_TOP:
v = (r->bottom - r->top) / (UI_HEIGHT / 5);
r->top = r->bottom - v * UI_HEIGHT / 5;
r->right = r->left + v * UI_WIDTH / 5;
r->right += GetSystemMetrics (SM_CXSIZEFRAME) * 2;
r->top -= GetSystemMetrics (SM_CYSIZEFRAME) * 2 + GetSystemMetrics (SM_CYSMCAPTION);
break;
case WMSZ_LEFT:
v = (r->right - r->left) / (UI_WIDTH / 5);
r->bottom = r->top + v * UI_HEIGHT / 5;
r->left = r->right - v * UI_WIDTH / 5;
r->left -= GetSystemMetrics (SM_CXSIZEFRAME) * 2;
r->bottom += GetSystemMetrics (SM_CYSIZEFRAME) * 2 + GetSystemMetrics (SM_CYSMCAPTION);
break;
case WMSZ_BOTTOMRIGHT:
GetWindowRect (hWnd, &r2);
if (abs(r2.right - r->right) > abs(r2.bottom - r->bottom))
v = (r->right - r->left) / (UI_WIDTH / 5);
else
v = (r->bottom - r->top) / (UI_HEIGHT / 5);
r->bottom = r->top + v * UI_HEIGHT / 5;
r->right = r->left + v * UI_WIDTH / 5;
r->right += GetSystemMetrics (SM_CXSIZEFRAME) * 2;
r->bottom += GetSystemMetrics (SM_CYSIZEFRAME) * 2 + GetSystemMetrics (SM_CYSMCAPTION);
break;
case WMSZ_BOTTOMLEFT:
GetWindowRect (hWnd, &r2);
if (abs(r2.left - r->left) > abs(r2.bottom - r->bottom))
v = (r->right - r->left) / (UI_WIDTH / 5);
else
v = (r->bottom - r->top) / (UI_HEIGHT / 5);
r->bottom = r->top + v * UI_HEIGHT / 5;
r->left = r->right - v * UI_WIDTH / 5;
r->left -= GetSystemMetrics (SM_CXSIZEFRAME) * 2;
r->bottom += GetSystemMetrics (SM_CYSIZEFRAME) * 2 + GetSystemMetrics (SM_CYSMCAPTION);
break;
case WMSZ_TOPRIGHT:
GetWindowRect (hWnd, &r2);
if (abs(r2.right - r->right) > abs(r2.top - r->top))
v = (r->right - r->left) / (UI_WIDTH / 5);
else
v = (r->bottom - r->top) / (UI_HEIGHT / 5);
r->top = r->bottom - v * UI_HEIGHT / 5;
r->right = r->left + v * UI_WIDTH / 5;
r->right += GetSystemMetrics (SM_CXSIZEFRAME) * 2;
r->top -= GetSystemMetrics (SM_CYSIZEFRAME) * 2 + GetSystemMetrics (SM_CYSMCAPTION);
break;
case WMSZ_TOPLEFT:
GetWindowRect (hWnd, &r2);
if (abs(r2.left - r->left) > abs(r2.top - r->top))
v = (r->right - r->left) / (UI_WIDTH / 5);
else
v = (r->bottom - r->top) / (UI_HEIGHT / 5);
r->top = r->bottom - v * UI_HEIGHT / 5;
r->left = r->right - v * UI_WIDTH / 5;
r->left -= GetSystemMetrics (SM_CXSIZEFRAME) * 2;
r->top -= GetSystemMetrics (SM_CYSIZEFRAME) * 2 + GetSystemMetrics (SM_CYSMCAPTION);
break;
}
wsprintf (s, "RockBox Simulator @%d%%",
(r->right - r->left - GetSystemMetrics (SM_CXSIZEFRAME) * 2)
* 100 / UI_WIDTH);
SetWindowText (hWnd, s);
return TRUE;
}
case WM_ERASEBKGND:
{
PAINTSTRUCT ps;
HDC hDc = BeginPaint (hWnd, &ps);
RECT r;
GetClientRect (hWnd, &r);
// blit to screen
StretchBlt (hDc, 0, 0, r.right, r.bottom,
hMemDc, 0, 0, UI_WIDTH, UI_HEIGHT, SRCCOPY);
EndPaint (hWnd, &ps);
return TRUE;
}
case WM_PAINT:
{
PAINTSTRUCT ps;
RECT r;
HDC hDc = BeginPaint (hWnd, &ps);
GetClientRect (hWnd, &r);
// draw lcd screen
StretchDIBits (hDc,
UI_LCD_POSX * r.right / UI_WIDTH, UI_LCD_POSY * r.bottom / UI_HEIGHT,
DISP_X * r.right / UI_WIDTH, DISP_Y * r.bottom / UI_HEIGHT,
0, 0, DISP_X, DISP_Y,
bitmap, (BITMAPINFO *) &bmi, DIB_RGB_COLORS, SRCCOPY);
EndPaint (hWnd, &ps);
return TRUE;
}
case WM_CLOSE:
// close simulator
hGUIWnd = NULL;
PostQuitMessage (0);
break;
}
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);
wc.lpfnWndProc = (WNDPROC)GUIWndProc;
wc.lpszClassName = "RockBoxUISimulator";
wc.style = CS_HREDRAW | CS_VREDRAW;
if (RegisterClass (&wc) == 0)
return FALSE;
// create window
hGUIWnd = CreateWindowEx (
WS_EX_TOOLWINDOW | WS_EX_PALETTEWINDOW,
"RockBoxUISimulator", "ARCHOS JukeBox",
WS_VISIBLE | WS_SYSMENU | WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
UI_WIDTH + GetSystemMetrics (SM_CXSIZEFRAME) * 2,
UI_HEIGHT + GetSystemMetrics (SM_CYSIZEFRAME) * 2 + GetSystemMetrics (SM_CYSMCAPTION),
NULL, NULL, GetModuleHandle (NULL), NULL);
if (hGUIWnd == NULL)
return FALSE;
return TRUE;
}
// GUIDown
// destroy window, unregister window class
int GUIDown ()
{
DestroyWindow (hGUIWnd);
_endthreadex (uThreadID);
return 0;
}
// GUIMessageLoop
// standard message loop for GUI window
void GUIMessageLoop ()
{
MSG msg;
while (GetMessage (&msg, hGUIWnd, 0, 0) && hGUIWnd != NULL)
{
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
)
{
if (!GUIStartup ())
return 0;
uThreadID = _beginthread (main, 0, NULL);
if (uThreadID == -0L)
return MessageBox (NULL, "Error creating mod thread!", "Error", MB_OK);
GUIMessageLoop ();
return GUIDown ();
}

View File

@ -0,0 +1,39 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
*
* 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.
*
****************************************************************************/
#ifndef __UISW32_H__
#define __UISW32_H__
#include <windows.h>
#include "lcd-win32.h"
#define UI_WIDTH 240 // width of GUI window
#define UI_HEIGHT 360 // height of GUI window
#define UI_LCD_COLOR 46, 57, 49 // bkgnd color of LCD
#define UI_LCD_BLACK RGB (0, 0, 0) // black
#define UI_LCD_POSX 59 // x position of lcd
#define UI_LCD_POSY 95 // y position of lcd
extern HWND hGUIWnd; // the GUI window handle
extern unsigned int uThreadID; // id of mod thread
// typedefs
typedef unsigned char uchar;
typedef unsigned int uint32;
#endif // #ifndef __UISW32_H__

View File

@ -0,0 +1,21 @@
Microsoft Visual Studio Solution File, Format Version 7.00
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "uisw32", "uisw32.vcproj", "{A81A8EFA-647A-427A-BD04-F6B469752E7A}"
EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
ConfigName.0 = Debug
ConfigName.1 = Release
EndGlobalSection
GlobalSection(ProjectDependencies) = postSolution
EndGlobalSection
GlobalSection(ProjectConfiguration) = postSolution
{A81A8EFA-647A-427A-BD04-F6B469752E7A}.Debug.ActiveCfg = Debug|Win32
{A81A8EFA-647A-427A-BD04-F6B469752E7A}.Debug.Build.0 = Debug|Win32
{A81A8EFA-647A-427A-BD04-F6B469752E7A}.Release.ActiveCfg = Release|Win32
{A81A8EFA-647A-427A-BD04-F6B469752E7A}.Release.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection
GlobalSection(ExtensibilityAddIns) = postSolution
EndGlobalSection
EndGlobal

Binary file not shown.

View File

@ -0,0 +1,154 @@
<?xml version="1.0" encoding = "Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.00"
Name="uisw32"
ProjectGUID="{A81A8EFA-647A-427A-BD04-F6B469752E7A}"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="&quot;C:\Programming\CVS Checkout\firmware&quot;;&quot;C:\Programming\CVS Checkout\firmware\drivers&quot;"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;ARCHOS_RECORDER;SIMULATOR"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="FALSE"
DebugInformationFormat="4"
CompileAs="1"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/uisw32.exe"
LinkIncremental="2"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/uisw32.pdb"
SubSystem="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
OmitFramePointers="TRUE"
AdditionalIncludeDirectories="&quot;C:\Programming\CVS Checkout\firmware\drivers&quot;;&quot;C:\Programming\CVS Checkout\firmware&quot;"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;ARCHOS_RECORDER;SIMULATOR"
StringPooling="TRUE"
RuntimeLibrary="0"
EnableFunctionLevelLinking="TRUE"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="FALSE"
DebugInformationFormat="3"
CompileAs="1"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/uisw32.exe"
LinkIncremental="1"
GenerateDebugInformation="TRUE"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
</Configuration>
</Configurations>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
<File
RelativePath="button.c">
</File>
<File
RelativePath="..\..\firmware\chartables.c">
</File>
<File
RelativePath="kernel.c">
</File>
<File
RelativePath="lcd.c">
</File>
<File
RelativePath="tetris.c">
</File>
<File
RelativePath="uisw32.cpp">
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc">
<File
RelativePath="lcd-win32.h">
</File>
<File
RelativePath="resource.h">
</File>
<File
RelativePath="uisw32.h">
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
<File
RelativePath="UI.bmp">
</File>
<File
RelativePath="uisw32.rc">
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>