1
0
Fork 0
forked from len0rd/rockbox

usb detection in bounce, and all files use default font (not loaded)

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2773 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Robert Hak 2002-10-29 10:45:29 +00:00
parent dae8deaf1f
commit 8f11dc00ac
5 changed files with 169 additions and 101 deletions

View file

@ -28,6 +28,8 @@
#include "menu.h"
#include "sprintf.h"
#include "rtc.h"
#include "font.h"
#include "screens.h"
#ifdef SIMULATOR
#include <stdio.h>
@ -37,6 +39,13 @@
#define SS_TITLE "Bouncer"
#define SS_TITLE_FONT 2
#define LETTERS_ON_SCREEN 12
#define YSPEED 2
#define XSPEED 3
#define YADD -4
static unsigned char table[]={
26,28,30,33,35,37,39,40,42,43,45,46,46,47,47,47,47,47,46,46,45,43,42,40,39,37,35,33,30,28,26,24,21,19,17,14,12,10,8,7,5,4,2,1,1,0,0,0,0,0,1,1,2,4,5,7,8,10,12,14,17,19,21,23,
};
@ -225,12 +234,6 @@ static void addclock(void)
}
}
#define LETTERS_ON_SCREEN 12
#define YSPEED 2
#define XSPEED 3
#define YADD -4
static int scrollit(void)
{
int b;
@ -301,6 +304,12 @@ static int loopit(void)
b = button_get_w_tmo(HZ/10);
if ( b == (BUTTON_OFF|BUTTON_REL) )
return 0;
if ( b == SYS_USB_CONNECTED) {
usb_screen();
return 0;
}
if ( b == (BUTTON_ON|BUTTON_REL) )
return 1;
else if(b != BUTTON_NONE)
@ -355,6 +364,8 @@ bool bounce(void)
char *off = "[Off] to stop";
int len = strlen(SS_TITLE);
lcd_setfont(FONT_SYSFIXED);
lcd_getstringsize(SS_TITLE,&w, &h);
/* Get horizontel centering for text */
@ -398,6 +409,8 @@ bool bounce(void)
h = scrollit();
} while(h);
lcd_setfont(FONT_UI);
return false;
}

View file

@ -31,25 +31,33 @@
#include "button.h"
#include "sprintf.h"
#include "screens.h"
#include "font.h"
typedef struct
{long x,y,z;} point3D;
/* Loops that the values are displayed */
#define DISP_TIME 30
typedef struct
{long x,y;} point2D;
struct point_3D {
long x, y, z;
};
static point3D Sommet[8];
static point3D Point3D[8];
static point2D Point2D[8];
struct point_2D {
long x, y;
};
static int Nb_points = 8;
static struct point_3D sommet[8];
static struct point_3D point3D[8];
static struct point_2D point2D[8];
static int Xoff = 56;
static int Yoff = 95;
static int Zoff = 600;
static long matrice[3][3];
static int nb_points = 8;
static int x_off = 56;
static int y_off = 95;
static int z_off = 600;
/* Precalculated sine and cosine * 10000 (four digit fixed point math) */
static int SinTable[91] =
static int sin_table[91] =
{
0, 174, 348, 523, 697,
871,1045,1218,1391,1564,
@ -72,76 +80,83 @@ static int SinTable[91] =
10000
};
static long Sin(int val)
static long sin(int val)
{
/* Speed improvement through sukzessive lookup */
if (val<181)
{
if (val<91)/* phase 0-90 degree */
if (val<91)
{
return (long)SinTable[val];
/* phase 0-90 degree */
return (long)sin_table[val];
}
else/* phase 91-180 degree */
else
{
return (long)SinTable[180-val];
/* phase 91-180 degree */
return (long)sin_table[180-val];
}
}
else
{
if (val<271)/* phase 181-270 degree */
if (val<271)
{
return (-1L)*(long)SinTable[val-180];
/* phase 181-270 degree */
return (-1L)*(long)sin_table[val-180];
}
else/* phase 270-359 degree */
else
{
return (-1L)*(long)SinTable[360-val];
/* phase 270-359 degree */
return (-1L)*(long)sin_table[360-val];
}
}
return 0;
}
static long Cos(int val)
static long cos(int val)
{
/* Speed improvement through sukzessive lookup */
if (val<181)
{
if (val<91)/* phase 0-90 degree */
if (val<91)
{
return (long)SinTable[90-val];
/* phase 0-90 degree */
return (long)sin_table[90-val];
}
else/* phase 91-180 degree */
else
{
return (-1L)*(long)SinTable[val-90];
/* phase 91-180 degree */
return (-1L)*(long)sin_table[val-90];
}
}
else
{
if (val<271)/* phase 181-270 degree */
if (val<271)
{
return (-1L)*(long)SinTable[270-val];
/* phase 181-270 degree */
return (-1L)*(long)sin_table[270-val];
}
else/* phase 270-359 degree */
else
{
return (long)SinTable[val-270];
/* phase 270-359 degree */
return (long)sin_table[val-270];
}
}
return 0;
}
static long matrice[3][3];
static void cube_rotate(int Xa, int Ya, int Za)
static void cube_rotate(int xa, int ya, int za)
{
int i;
/* Just to prevent unnecessary lookups */
long sxa,cxa,sya,cya,sza,cza;
sxa=Sin(Xa);
cxa=Cos(Xa);
sya=Sin(Ya);
cya=Cos(Ya);
sza=Sin(Za);
cza=Cos(Za);
sxa=sin(xa);
cxa=cos(xa);
sya=sin(ya);
cya=cos(ya);
sza=sin(za);
cza=cos(za);
/* calculate overall translation matrix */
matrice[0][0] = cza*cya/10000L;
@ -157,19 +172,16 @@ static void cube_rotate(int Xa, int Ya, int Za)
matrice[2][2] = cxa*cya/10000L;
/* apply translation matrix to all points */
for(i=0;i<Nb_points;i++)
for(i=0;i<nb_points;i++)
{
Point3D[i].x = matrice[0][0]*Sommet[i].x
+ matrice[1][0]*Sommet[i].y
+ matrice[2][0]*Sommet[i].z;
point3D[i].x = matrice[0][0]*sommet[i].x + matrice[1][0]*sommet[i].y
+ matrice[2][0]*sommet[i].z;
Point3D[i].y = matrice[0][1]*Sommet[i].x
+ matrice[1][1]*Sommet[i].y
+ matrice[2][1]*Sommet[i].z;
point3D[i].y = matrice[0][1]*sommet[i].x + matrice[1][1]*sommet[i].y
+ matrice[2][1]*sommet[i].z;
Point3D[i].z = matrice[0][2]*Sommet[i].x
+ matrice[1][2]*Sommet[i].y
+ matrice[2][2]*Sommet[i].z;
point3D[i].z = matrice[0][2]*sommet[i].x + matrice[1][2]*sommet[i].y
+ matrice[2][2]*sommet[i].z;
}
}
@ -178,31 +190,31 @@ static void cube_viewport(void)
int i;
/* Do viewport transformation for all points */
for(i=0;i<Nb_points;i++)
for(i=0;i<nb_points;i++)
{
Point2D[i].x=(((Point3D[i].x)<<8)/10000L)/
(Point3D[i].z/10000L+Zoff)+Xoff;
Point2D[i].y=(((Point3D[i].y)<<8)/10000L)/
(Point3D[i].z/10000L+Zoff)+Yoff;
point2D[i].x=(((point3D[i].x)<<8)/10000L)/
(point3D[i].z/10000L+z_off)+x_off;
point2D[i].y=(((point3D[i].y)<<8)/10000L)/
(point3D[i].z/10000L+z_off)+y_off;
}
}
static void cube_init(void)
{
/* Original 3D-position of cube's corners */
Sommet[0].x = -40; Sommet[0].y = -40; Sommet[0].z = -40;
Sommet[1].x = 40; Sommet[1].y = -40; Sommet[1].z = -40;
Sommet[2].x = 40; Sommet[2].y = 40; Sommet[2].z = -40;
Sommet[3].x = -40; Sommet[3].y = 40; Sommet[3].z = -40;
Sommet[4].x = 40; Sommet[4].y = -40; Sommet[4].z = 40;
Sommet[5].x = -40; Sommet[5].y = -40; Sommet[5].z = 40;
Sommet[6].x = -40; Sommet[6].y = 40; Sommet[6].z = 40;
Sommet[7].x = 40; Sommet[7].y = 40; Sommet[7].z = 40;
sommet[0].x = -40; sommet[0].y = -40; sommet[0].z = -40;
sommet[1].x = 40; sommet[1].y = -40; sommet[1].z = -40;
sommet[2].x = 40; sommet[2].y = 40; sommet[2].z = -40;
sommet[3].x = -40; sommet[3].y = 40; sommet[3].z = -40;
sommet[4].x = 40; sommet[4].y = -40; sommet[4].z = 40;
sommet[5].x = -40; sommet[5].y = -40; sommet[5].z = 40;
sommet[6].x = -40; sommet[6].y = 40; sommet[6].z = 40;
sommet[7].x = 40; sommet[7].y = 40; sommet[7].z = 40;
}
static void line(int a, int b)
{
lcd_drawline(Point2D[a].x,Point2D[a].y,Point2D[b].x,Point2D[b].y);
lcd_drawline(point2D[a].x, point2D[a].y, point2D[b].x, point2D[b].y);
}
static void cube_draw(void)
@ -222,10 +234,6 @@ static void cube_draw(void)
line(3,6);
}
/* Loops that the values are displayed */
#define DISP_TIME 30
bool cube(void)
{
int t_disp=0;
@ -240,11 +248,14 @@ bool cube(void)
bool highspeed=0;
bool exit=0;
lcd_setfont(FONT_SYSFIXED);
cube_init();
while(!exit)
{
if (!highspeed) sleep(4);
if (!highspeed)
sleep(4);
lcd_clear_display();
cube_rotate(xa,ya,za);
@ -322,10 +333,13 @@ bool cube(void)
case SYS_USB_CONNECTED:
usb_screen();
lcd_setfont(FONT_UI);
return true;
}
}
lcd_setfont(FONT_UI);
}
}
return false;
}
@ -338,3 +352,5 @@ bool cube(void)
* vim: et sw=4 ts=8 sts=4 tw=78
*/

View file

@ -19,6 +19,7 @@
#include "config.h"
#include "options.h"
#ifdef USE_GAMES
#include <sprintf.h>
@ -28,6 +29,7 @@
#include "kernel.h"
#include "menu.h"
#include "screens.h"
#include "font.h"
#include "sokoban_levels.h"
@ -503,6 +505,8 @@ bool sokoban(void)
int w, h;
int len;
lcd_setfont(FONT_SYSFIXED);
lcd_getstringsize(SOKOBAN_TITLE, &w, &h);
/* Get horizontel centering for text */
@ -535,10 +539,9 @@ bool sokoban(void)
lcd_clear_display();
result = sokoban_loop();
lcd_setfont(FONT_UI);
return result;
}
#endif

View file

@ -25,12 +25,13 @@
#ifdef USE_GAMES
#include <stdbool.h>
#include <string.h>
#include "lcd.h"
#include "button.h"
#include "kernel.h"
#include <string.h>
#include "menu.h"
#include "screens.h"
#include "font.h"
#ifdef SIMULATOR
#include <stdio.h>
@ -46,7 +47,9 @@ static const int start_x = 5;
static const int start_y = 5;
static const int max_x = 4 * 17;
static const int max_y = 3 * 10;
static const short level_speeds[10] = {1000,900,800,700,600,500,400,300,250,200};
static const short level_speeds[10] = {
1000, 900, 800, 700, 600, 500, 400, 300, 250, 200
};
static const int blocks = 7;
static const int block_frames[7] = {1,2,2,2,4,4,4};
@ -153,8 +156,9 @@ static void to_virtual(void)
for (a = 0; a < 3; a++)
for (b = 0; b < 4; b++)
*(virtual +
(current_y + block_data[current_b][current_f][0][i] * 3 + a) * max_x +
current_x + block_data[current_b][current_f][1][i] * 4 - b) = current_b + 1;
(current_y + block_data[current_b][current_f][0][i] * 3 + a) *
max_x + current_x + block_data[current_b][current_f][1][i] *
4 - b) = current_b + 1;
}
static bool block_touch (int x, int y)
@ -179,7 +183,8 @@ static bool gameover(void)
for(i = 0; i < 4; i++){
/* Do we have blocks touching? */
if(block_touch(x + block_data[block][frame][1][i] * 4, y + block_data[block][frame][0][i] * 3))
if(block_touch(x + block_data[block][frame][1][i] * 4,
y + block_data[block][frame][0][i] * 3))
{
/* Are we at the top of the frame? */
if(x + block_data[block][frame][1][i] * 4 >= max_x - 16)
@ -200,8 +205,11 @@ static bool valid_position(int x, int y, int block, int frame)
(x + block_data[block][frame][1][i] * 4 > max_x - 4) ||
(y + block_data[block][frame][0][i] * 3 < 0) ||
(x + block_data[block][frame][1][i] * 4 < 4) ||
block_touch (x + block_data[block][frame][1][i] * 4, y + block_data[block][frame][0][i] * 3))
block_touch (x + block_data[block][frame][1][i] * 4,
y + block_data[block][frame][0][i] * 3))
{
return false;
}
return true;
}
@ -402,6 +410,10 @@ static void init_tetris(void)
bool tetris(void)
{
char buf[20];
bool val;
/* Lets use the default font */
lcd_setfont(FONT_SYSFIXED);
init_tetris();
@ -413,7 +425,14 @@ bool tetris(void)
next_b = t_rand(blocks);
next_f = t_rand(block_frames[next_b]);
new_block();
return game_loop();
val = game_loop();
lcd_setfont(FONT_UI);
return val;
}
#endif

View file

@ -35,6 +35,7 @@
#include "rtc.h"
#include "lang.h"
#include "screens.h"
#include "font.h"
/* size of the field the worm lives in */
#define FIELD_RECT_X 1
@ -1891,8 +1892,11 @@ extern bool use_old_rect;
*/
bool wormlet(void)
{
bool wormDead = false;
bool worm_dead = false;
int button;
lcd_setfont(FONT_SYSFIXED);
#ifdef DEBUG_WORMLET
testline_in_rect();
test_worm_argh_collision_in_moves();
@ -1978,6 +1982,7 @@ bool wormlet(void)
case SYS_USB_CONNECTED:
usb_screen();
lcd_setfont(FONT_UI);
return true;
}
} while (button != BUTTON_PLAY &&
@ -1997,11 +2002,11 @@ bool wormlet(void)
button = BUTTON_OFF;
/* start the game */
wormDead = run();
worm_dead = run();
/* if worm isn't dead the game was quit
via BUTTON_OFF -> no need to wait for buttons. */
if (wormDead) {
if (worm_dead) {
do {
button = button_get(true);
}
@ -2012,8 +2017,20 @@ bool wormlet(void)
}
while (button != BUTTON_OFF);
lcd_setfont(FONT_UI);
return false;
}
#endif /* USE_GAMES */