user supplied l0dables: leiwand demo and tedliz game

This commit is contained in:
roy rocket 2011-08-11 01:06:01 +02:00
parent 5fce3b0d39
commit 7d79419f55
3 changed files with 579 additions and 0 deletions

290
firmware/l0dable/leiwand.c Normal file
View File

@ -0,0 +1,290 @@
#include <sysinit.h>
#include "basic/basic.h"
//#include "lcd/render.h"
//#include "lcd/display.h"
//#include "lcd/allfonts.h"
//#include "lcd/backlight.h"
//#include "lcd/print.h"
#include "usetable.h"
//void backlightInit(void);
void incBacklight(void);
void decBacklight(void);
void paintLogo(bool);
void leiwandDisplay(void);
/**************************************************************************/
#include "leiwand.h"
/**************************************************************************/
void ram(void) {
int key;
while (1) {
leiwandDisplay();
// Exit on enter+left
key=getInputRaw();
if(key== BTN_ENTER + BTN_LEFT)
return;
}
return;
}
void leiwandInit(void) {
paintLogo(false);
delayms(200);
DoString(0,0,"Boot...");
lcdDisplay();
delayms(1000);
}
void leiwandDisplay(void) {
int dx=0;
char key = 0;
//backlightInit();
int i;
int j;
char str[] = "LeiwandVille";
char msg[] = " Just cool! ";
#define msglen 12
int pos[msglen];
int dir[msglen];
int round = 0;
bool upPressed=false;
bool rightPressed=false;
bool downPressed=false;
int demoround = 0;
//lcdToggleFlag(LCD_INVERTED);
for(i = 0; i < msglen; i++) {
pos[i] = 1 + (i * 2);
dir[i] = 0;
}
while (1) {
lcdDisplay();
delayms(20);
key= getInputRaw();
// Easy flashing
if((key&(BTN_ENTER|BTN_LEFT))==(BTN_ENTER|BTN_LEFT)){
//DoString(0,8,"Enter ISP!");
//lcdDisplay();
//ISPandReset();
return;
}
/*
// INVERT
if(((key&(BTN_RIGHT))==(BTN_RIGHT))){
if(!rightPressed) {
lcdToggleFlag(LCD_INVERTED);
}
rightPressed = true;
} else {
rightPressed = false;
}
*/
// BRIGHTER
if(((key&(BTN_UP))==(BTN_UP))){
if(!upPressed) {
incBacklight();
}
upPressed = true;
} else {
upPressed = false;
}
// DARKER
if(((key&(BTN_DOWN))==(BTN_DOWN))){
if(!downPressed) {
decBacklight();
}
downPressed = true;
} else {
downPressed = false;
}
round++;
if(round > 200) {
round = 0;
if(demoround == 1) {
paintLogo(true);
} else {
paintLogo(false);
delayms(1000);
}
demoround++;
}
if(demoround == 4) {
demoround = 0;
}
for(i = 0; i < msglen; i++) {
if(dir[i] == 1) {
if(pos[i] >= 30) {
dir[i] = 0;
} else {
pos[i]++;
}
} else {
if(pos[i] == 0) {
dir[i] = 1;
} else {
pos[i]--;
}
}
}
lcdFill(0);
//font=&Font_7x8;
for(i = 0; i < msglen; i++) {
if(str[i] != 32) {
dx=DoChar(i*8, pos[i], str[i]);
}
}
if(round < 100) {
// Second line of message
for(i = 0; i < msglen; i++) {
if(msg[i] != 32) {
dx=DoChar(i*8, 15+pos[i], msg[i]);
}
}
} else {
// INVADERS
//font = &Font_Invaders;
for(i = 2; i < 10; i+= 2) {
dx=DoChar(i*8, 15+pos[i], 'x');
}
}
//font=&Font_7x8;
if(round < 50) {
dx=DoString(0, 60, " Visit us! ");
} else if(round < 100) {
dx=DoString(0, 60, " We are ");
} else if(round < 150) {
dx=DoString(0, 60, " next to the ");
} else {
dx=DoString(0, 60, " phone booth ");
if((round % 6) < 3) {
for(i = 0; i < 96; i++) {
for(j = 0; j < 8; j++) {
lcdSetPixel(i, j+60, !lcdGetPixel(i, j+60));
}
}
}
}
/*
if(key&BTN_ENTER){
lcdPrintInt(ctr++);
lcdPrintln(".");
while(getInputRaw())delayms(10);
};
if(key&BTN_RIGHT){
lcdShift(1,0,wrap);
}
if(key&BTN_LEFT){
lcdShift(-1,0,wrap);
}
if(key&BTN_UP){
lcdShift(0,1,wrap);
}
if(key&BTN_DOWN){
lcdShift(0,-1,wrap);
}
*/
//font = &Font_Ubuntu36pt;
}
return;
}
void tick_scroll(void){
return;
};
void incBacklight(void) {
/*
uint32_t brightness = backlightGetBrightness();
if (brightness < 100) {
backlightSetBrightness(brightness + 10);
}
*/
return;
}
void decBacklight(void) {
/*
uint32_t brightness = backlightGetBrightness();
if (brightness > 0) {
backlightSetBrightness(brightness - 10);
}
*/
return;
}
void paintLogo(bool animate) {
int i;
int j;
int t;
uint8_t pixel;
int bc = 8;
int next = 0;
int mask = 1;
lcdFill(0);
lcdDisplay();
for(i = 0; i < 68; i++) {
for(j = 0; j < 68; j++) {
if(bc == 8) {
mask = 1;
bc = 0;
pixel = lv_logo[next];
next++;
}
if((pixel & mask) > 0) {
lcdSetPixel(14+j, i, true);
} else {
lcdSetPixel(14+j, i, false);
}
bc++;
mask = mask << 1;
pixel >> 2;
}
//lcdDisplay();
}
lcdDisplay();
if(!animate) {
return;
}
/*
for(i = 0; i < 30; i++) {
delayms(20);
}
*/
for(t=0; t < 8; t++) {
for(i=0; i < 96; i++) {
for(j=0; j < 68; j++) {
lcdSetPixel(i, j, !lcdGetPixel(i,j));
}
lcdDisplay();
}
}
/*
for(i = 0; i < 50; i++) {
delayms(20);
}
*/
return;
}

View File

@ -0,0 +1,70 @@
uint8_t lv_logo[] = {
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,192,1,
0,0,0,0,0,0,128,63,0,
0,0,0,0,0,0,255,3,
0,0,0,0,0,0,255,95,0,
0,0,0,0,0,254,248,13,
0,0,0,0,0,254,3,159,0,
0,0,0,0,254,29,240,17,
0,0,0,0,252,131,1,31,1,
0,0,0,252,29,16,240,33,
0,0,0,252,131,1,1,31,2,
0,0,64,31,24,16,248,65,
0,0,0,224,129,129,193,31,4,
0,0,31,30,24,56,255,67,
0,0,252,231,129,129,255,61,4,
0,224,255,31,56,254,129,71,
0,0,255,255,129,255,3,120,4,
0,248,128,63,254,3,31,79,
0,192,247,224,255,3,248,243,4,
0,254,15,254,3,159,127,94,
0,224,255,240,3,248,251,199,5,
0,255,199,3,158,63,255,124,
0,240,63,4,248,251,247,143,7,
128,255,129,130,63,255,126,120,
0,248,0,0,248,247,207,129,3,
192,31,48,4,255,254,0,1,
0,252,255,231,240,207,3,0,0,
192,255,127,14,254,0,0,0,
0,254,255,113,193,3,0,0,0,
224,255,255,3,0,0,0,56,
0,0,255,63,2,0,0,240,7,
0,192,255,1,0,0,16,99,
0,0,224,7,2,0,8,49,4,
0,0,0,0,0,192,17,99,
0,0,0,0,0,24,60,49,6,
0,0,0,0,128,67,23,51,
0,0,0,0,96,60,228,241,1,
0,0,0,48,70,70,28,3,
0,0,0,8,39,100,132,1,0,
0,0,152,121,226,79,0,0,
0,0,136,153,54,198,0,0,6,
0,240,152,201,51,0,0,60,
0,0,131,241,28,1,0,192,0,
64,176,24,135,1,0,48,12,
0,4,143,113,0,0,4,195,7,
64,48,24,2,0,64,48,12,
0,4,131,1,0,100,4,195,0,
64,240,0,0,64,70,48,124,
0,60,3,0,48,102,4,203,0,
192,1,0,0,35,70,240,0,
0,0,0,0,96,99,60,0,0,
0,0,0,0,54,198,0,0,
0,0,0,0,192,97,0,0,0,
0,0,0,0,28,0,0,0,
0,0,0,0,128,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
0x0};

219
firmware/l0dable/tedliz.c Normal file
View File

@ -0,0 +1,219 @@
// tedliz
// ======
// a kick ass tetris clone
// code by twobit (c3d2 at pentagon ville)
////////////////////////////////////////////////////////////////////////////////
#include <sysinit.h>
#include <string.h>
#include "basic/basic.h"
#include "basic/config.h"
#include "basic/random.h"
#include "lcd/render.h"
#include "lcd/display.h"
#include "lcd/fonts.h"
#include "lcd/fonts/invaders.h"
#include "funk/mesh.h"
#include "usetable.h"
////////////////////////////////////////////////////////////////////////////////
enum {
GRID_WIDTH = 10,
GRID_HEIGHT = 20,
TICK_LENGTH = 30,
KEY_REPEAT_DELEAY = 5,
STARTING_SPEED = 12
};
// key repeat delay stuff
int key_rep[] = { 0, 0, 0, 0, 0 };
int ticks_per_drop = STARTING_SPEED;
int lines = 0;
int ticks = 0;
int rot;
int stone;
int next_rot;
int next_stone;
int x_pos;
int y_pos;
uint8_t grid[GRID_HEIGHT][GRID_WIDTH];
const uint8_t stones[7][16] = {
{ 0, 0, 0, 0, 0,15,15, 0, 0,15,15, 0, 0, 0, 0, 0 },
{ 0, 0,10, 0, 5, 5,15, 5, 0, 0,10, 0, 0, 0,10, 0 },
{ 0, 0, 5, 0, 0, 0,15,15, 0,10,10, 5, 0, 0, 0, 0 },
{ 0, 0, 0, 5, 0,10,15, 5, 0, 0,15,10, 0, 0, 0, 0 },
{ 0, 4, 5, 8, 0,10,15,10, 0, 2, 5, 1, 0, 0, 0, 0 },
{ 0, 8, 5, 1, 0,10,15,10, 0, 4, 5, 2, 0, 0, 0, 0 },
{ 0, 0,11, 0, 0,13,15, 7, 0, 0,14, 0, 0, 0, 0, 0 }
};
void draw_grid();
void new_stone();
int collision(int top_also);
void ram() {
int raw_key, key;
int i, j;
new_stone();
new_stone();
// epmty grid
for(i = 0; i < GRID_HEIGHT; i++)
for(j = 0; j < GRID_WIDTH; j++)
grid[i][j] = 0;
// prepare screen
lcdClear();
for(i = 0; i < 96; i++) {
lcdSetPixel(i, 2, 1);
lcdSetPixel(i, 65, 1);
}
for(i = 3; i < 65; i++) {
lcdSetPixel(2, i, 1);
lcdSetPixel(35, i, 1);
lcdSetPixel(93, i, 1);
}
for(;;) {
// handle input
raw_key = getInputRaw();
key = 0;
for(i = 0; i < 5; i++) {
if(raw_key & (1 << i)) {
if(!key_rep[i] || key_rep[i] == KEY_REPEAT_DELEAY) key |= 1 << i;
key_rep[i] += key_rep[i] < KEY_REPEAT_DELEAY;
}
else key_rep[i] = 0;
}
// rotate
if(key & BTN_UP) {
i = rot;
rot = (rot << 1) % 15;
if(collision(0)) rot = i;
}
// horizontal movement
i = x_pos;
x_pos += !!(key & BTN_RIGHT) - !!(key & BTN_LEFT);
if(i != x_pos && collision(0)) x_pos = i;
// vertical movement
ticks++;
if(key & BTN_DOWN || ticks >= ticks_per_drop) {
ticks = 0;
y_pos++;
if(collision(0)) {
y_pos--;
// check for game over
if(collision(1)) return;
// copy stone to grid
int x, y;
for(y = 0; y < 4; y++) {
for(x = 0; x < 4; x++) {
if(stones[stone][(x << 2) + y] & rot)
grid[y + y_pos][x + x_pos] = 1;
}
}
// check for complete lines
for(y = 0; y < GRID_HEIGHT; y++) {
for(x = 0; x < GRID_WIDTH; x++)
if(!grid[y][x]) break;
if(x == GRID_WIDTH) {
lines++;
ticks_per_drop = STARTING_SPEED - lines / 10;
if(ticks_per_drop < 1) ticks_per_drop = 1;
for(i = y; i > 0; i--)
for(x = 0; x < GRID_WIDTH; x++)
grid[i][x] = grid[i - 1][x];
}
}
// get a new stone
new_stone();
}
}
draw_grid();
lcdDisplay();
delayms(TICK_LENGTH);
}
return;
}
int collision(int top_also) {
int x, y;
for(y = 0; y < 4; y++) {
for(x = 0; x < 4; x++) {
if(stones[stone][(x << 2) + y] & rot && (
x + x_pos < 0 || x + x_pos >= GRID_WIDTH ||
(top_also && y + y_pos < 0) || y + y_pos >= GRID_HEIGHT ||
grid[y + y_pos][x + x_pos]))
return 1;
}
}
return 0;
}
void new_stone() {
x_pos = 3;
y_pos = -3;
rot = next_rot;
stone = next_stone;
next_rot = 1 << getRandom() % 4;
next_stone = getRandom() % 7;
}
void draw_block(int x, int y, int b) {
lcdSetPixel(0 + x, 0 + y, b);
lcdSetPixel(1 + x, 0 + y, b);
lcdSetPixel(2 + x, 0 + y, b);
lcdSetPixel(0 + x, 1 + y, b);
lcdSetPixel(1 + x, 1 + y, b);
lcdSetPixel(2 + x, 1 + y, b);
lcdSetPixel(0 + x, 2 + y, b);
lcdSetPixel(1 + x, 2 + y, b);
lcdSetPixel(2 + x, 2 + y, b);
}
void draw_grid() {
int b, y, x;
for(y = 0; y < GRID_HEIGHT; y++) {
for(x = 0; x < GRID_WIDTH; x++) {
b = grid[y][x] ||
(x >= x_pos && x < x_pos + 4 && y >= y_pos && y < y_pos + 4 &&
stones[stone][((x - x_pos) << 2) + (y - y_pos)] & rot);
draw_block(4 + x * 3, 4 + y * 3, b);
}
}
// look adhead
for(y = 0; y < 4; y++)
for(x = 0; x < 4; x++)
draw_block(40 + x * 3, 7 + y * 3, !!(stones[next_stone][(x << 2) + y] & next_rot));
}