Browse Source

src/scrolltext: fix codestyle

feature/2015
Nicolas Reinecke 10 years ago
parent
commit
b2dd959767
  1. 2
      src/scrolltext/scrolltext.h
  2. 360
      src/scrolltext/scrolltext3.c

2
src/scrolltext/scrolltext.h

@ -6,6 +6,6 @@
#define FONT_UNI53 3
#define FONT_C64 4
void scrolltext(char *str);
extern void scrolltext(char *str);
#endif /* SCROLLTEXT_H_ */

360
src/scrolltext/scrolltext3.c

@ -36,12 +36,12 @@
font fonts[MAX_FONTS];
#define MAX_SPECIALCOLORS 3
unsigned const char PROGMEM colorTable[MAX_SPECIALCOLORS*NUM_ROWS] = {1, 1, 2, 3, 3, 2, 1, 1,
static const unsigned char PROGMEM colorTable[MAX_SPECIALCOLORS * NUM_ROWS] = {1, 1, 2, 3, 3, 2, 1, 1,
3, 3, 2, 1, 1, 2, 3, 3,
3, 3, 2, 2, 3, 3, 2, 2
};
const char default_text[] PROGMEM = SCROLLTEXT_TEXT;
static const char default_text[] PROGMEM = SCROLLTEXT_TEXT;
char scrolltext_text[SCROLLTEXT_BUFFER_SIZE];
/* Konzept
@ -57,25 +57,26 @@ Wenn der Command abgearbeitet ist wird automatisch das nächste Token eingelesen
*/
unsigned char (*text_pixmap)[NUM_ROWS][LINEBYTES];
static unsigned char (*text_pixmap)[NUM_ROWS][LINEBYTES];
static void text_setpixel(pixel p, unsigned char value ){
if(value){
(*text_pixmap)[p.y%NUM_ROWS][p.x/8] |= shl_table[p.x%8];
}
static void text_setpixel(pixel p, unsigned char value)
{
if (value)
(*text_pixmap)[p.y % NUM_ROWS][p.x / 8] |= shl_table[p.x % 8];
}
static void clear_text_pixmap(){
static void clear_text_pixmap()
{
memset(text_pixmap, 0, NUM_ROWS * LINEBYTES);
}
static void update_pixmap(){
for(unsigned char p = NUMPLANE; p--;){
static void update_pixmap()
{
for (unsigned char p = NUMPLANE; p--;)
memcpy(&pixmap[p][0][0], text_pixmap, NUM_ROWS * LINEBYTES);
}
}
enum waitfor_e{
enum waitfor_e {
wait_new,
wait_posy,
wait_posx,
@ -92,11 +93,11 @@ enum waitfor_e{
#define DIRECTION_RIGHT 0x01
#define DIRECTION_DOWN 0x02
#define DIRECTION_DOWN 0x02
struct blob_t_struct;
typedef struct blob_t_struct{
struct blob_t_struct * next, * last;
typedef struct blob_t_struct {
struct blob_t_struct *next, *last;
char *str;
char *commands;
waitfor_e_t waitfor;
@ -113,37 +114,38 @@ typedef struct blob_t_struct{
unsigned char direction;
unsigned int timer;
const unsigned int* fontIndex;
const unsigned char* fontData;
const unsigned int *fontIndex;
const unsigned char *fontData;
unsigned char font_storebytes;/*bytes per char*/
unsigned char space;
#ifndef AVR
char scrolltextBuffer[SCROLLTEXT_BUFFER_SIZE];
#endif
}blob_t;
} blob_t;
/*
void showBlob(blob_t * blob){
unsigned char * str = blob->str;
unsigned char tmp[200], x=0;
while(*str){
void showBlob(blob_t *blob)
{
unsigned char *str = blob->str;
unsigned char tmp[200], x = 0;
while (*str) {
tmp[x++] = (*str++) + ' ' -1;
}
tmp[x] = 0;
printf("this:\t%x\n",blob);
printf("last:\t%x\n",blob->last);
printf("next:\t%x\n",blob->next);
printf("str:\t%s\n",tmp);
printf("cmd:\t%s\n",blob->commands);
printf("sizex\t%d\n",blob->sizex);
printf("posx\t%d\n",blob->posx);
printf("posy\t%d\n",blob->posy);
printf("tox\t%d\n",blob->tox);
printf("toy\t%d\n",blob->toy);
printf("delayy_rld\t%d\n",blob->delayx_rld);
printf("delayx_rld\t%d\n",blob->delayy_rld);
printf("timer\t%d\n",blob->timer);
printf("this:\t%x\n", blob);
printf("last:\t%x\n", blob->last);
printf("next:\t%x\n", blob->next);
printf("str:\t%s\n", tmp);
printf("cmd:\t%s\n", blob->commands);
printf("sizex\t%d\n", blob->sizex);
printf("posx\t%d\n", blob->posx);
printf("posy\t%d\n", blob->posy);
printf("tox\t%d\n", blob->tox);
printf("toy\t%d\n", blob->toy);
printf("delayy_rld\t%d\n", blob->delayx_rld);
printf("delayx_rld\t%d\n", blob->delayy_rld);
printf("timer\t%d\n", blob->timer);
printf("\n");
}
*/
@ -152,125 +154,127 @@ void showBlob(blob_t * blob){
#define PW(a) pgm_read_word(&(a))
#define PB(a) pgm_read_byte(&(a))
static unsigned int getLen(blob_t *blob) {
static unsigned int getLen(blob_t *blob)
{
unsigned char glyph;
unsigned int strLen = 0;
unsigned char * str = (unsigned char*)blob->str;
uint8_t space = blob->space * blob->font_storebytes;
unsigned char *str = (unsigned char*) blob->str;
uint8_t space = blob->space *blob->font_storebytes;
while ((glyph = *str++)) {
glyph -= 1;
strLen += PW(blob->fontIndex[glyph+1]) - PW(blob->fontIndex[glyph]);
strLen += PW(blob->fontIndex[glyph + 1]) - PW(blob->fontIndex[glyph]);
strLen += space;
}
return strLen/blob->font_storebytes;
return strLen / blob->font_storebytes;
}
static unsigned int getnum(blob_t * blob){
unsigned int num=0;
static unsigned int getnum(blob_t *blob)
{
unsigned int num = 0;
unsigned char gotnum = 0;
while( (*blob->commands >= '0') && (*blob->commands <='9') ){
while ((*blob->commands >= '0') && (*blob->commands <= '9')) {
gotnum = 1;
num *= 10;
num += *blob->commands - '0';
blob->commands++;
}
if(gotnum){
if (gotnum)
return num;
}else{
else
return 0xffff;
}
}
unsigned char blobNextCommand(blob_t * blob){
unsigned char blobNextCommand(blob_t *blob)
{
unsigned int tmp;
unsigned char retval = 0;
while(*blob->commands != 0){
switch (*blob->commands++){
while (*blob->commands != 0) {
switch (*blob->commands++) {
case '<':
blob->direction &= ~DIRECTION_RIGHT;
if((tmp = getnum(blob)) != 0xFFFF){
if ((tmp = getnum(blob)) != 0xFFFF) {
blob->delayx_rld = tmp;
}else{
} else {
blob->delayx_rld = SCROLL_X_SPEED;
}
blob->delayx = blob->delayx_rld;
break;
case '>':
blob->direction |= DIRECTION_RIGHT;
if((tmp = getnum(blob)) != 0xFFFF){
if ((tmp = getnum(blob)) != 0xFFFF) {
blob->delayx_rld = tmp;
}else{
} else {
blob->delayx_rld = SCROLL_X_SPEED;
}
blob->delayx = blob->delayx_rld;
break;
case 'd':
blob->direction |= DIRECTION_DOWN;
if((tmp = getnum(blob)) != 0xFFFF){
if ((tmp = getnum(blob)) != 0xFFFF) {
blob->delayy_rld = tmp;
}else{
} else {
blob->delayy_rld = SCROLL_Y_SPEED;
}
blob->delayy = blob->delayy_rld;
break;
case 'u':
blob->direction &= ~DIRECTION_DOWN;
if((tmp = getnum(blob)) != 0xFFFF){
if ((tmp = getnum(blob)) != 0xFFFF) {
blob->delayy_rld = tmp;
}else{
} else {
blob->delayy_rld = SCROLL_Y_SPEED;
}
blob->delayy = blob->delayy_rld;
break;
case 'x'://Place string at this x Position
if((tmp = getnum(blob)) != 0xFFFF){
if ((tmp = getnum(blob)) != 0xFFFF) {
blob->posx = tmp;
}else{
blob->posx = NUM_COLS/2 + blob->sizex/2;
} else {
blob->posx = NUM_COLS / 2 + blob->sizex / 2;
}
break;
case 'y'://Place string at this y Position
if((tmp = getnum(blob)) != 0xFFFF){
if ((tmp = getnum(blob)) != 0xFFFF) {
blob->posy = tmp - blob->sizey;
}
break;
case 'b'://blink blob
if((tmp = getnum(blob)) != 0xFFFF){
if ((tmp = getnum(blob)) != 0xFFFF) {
blob->delayb_rld = tmp;
}else{
} else {
blob->delayb_rld = 50;
}
blob->delayb = blob->delayb_rld;
break;
case '|':
if((tmp = getnum(blob)) != 0xFFFF){
if ((tmp = getnum(blob)) != 0xFFFF) {
blob->tox = tmp;
}else{
blob->tox = (NUM_COLS - 2 + blob->sizex)/2;
} else {
blob->tox = (NUM_COLS - 2 + blob->sizex) / 2;
}
blob->waitfor = wait_posx;
return retval;
break;
case '-':
if((tmp = getnum(blob)) != 0xFFFF){
if ((tmp = getnum(blob)) != 0xFFFF) {
blob->toy = tmp;
}else{
} else {
blob->toy = (UNUM_ROWS-blob->sizey) / 2; //MARK
}
blob->waitfor = wait_posy;
return retval;
break;
case 'p':
case 'p'://delay
blob->delayx_rld = 0;
blob->delayy_rld = 0;
if((tmp = getnum(blob)) != 0xFFFF){
blob->timer = tmp*64;
}else{
blob->timer = 30*64;
if ((tmp = getnum(blob)) != 0xFFFF) {
blob->timer = tmp * 64;
} else {
blob->timer = 30 * 64;
}
blob->waitfor = wait_timer;
return retval;
@ -296,57 +300,60 @@ unsigned char blobNextCommand(blob_t * blob){
}
blob_t * setupBlob(char * str){
static blob_t *setupBlob(char *str)
{
static unsigned char chop_cnt;
static char *last; static char delim[] = "#";
static char *lastcommands;
unsigned int tmp;
blob_t *blob = malloc(sizeof (blob_t));
blob_t *blob = malloc(sizeof(blob_t));
if(str){
if (str) {
#ifndef AVR
// on non-AVR archs strtok_r fails for some reason if it operates on a
// string which is located on another stack frame, so we need our own copy
memcpy (blob->scrolltextBuffer, str, SCROLLTEXT_BUFFER_SIZE);
memcpy(blob->scrolltextBuffer, str, SCROLLTEXT_BUFFER_SIZE);
str = blob->scrolltextBuffer;
#endif
chop_cnt = 0;
}
if(!chop_cnt){
blob->commands = strtok_r (str, delim, &last);
if (!chop_cnt) {
blob->commands = strtok_r(str, delim, &last);
if( blob->commands == 0) goto fail;
if (blob->commands == 0)
goto fail;
if((tmp = getnum(blob)) != 0xFFFF){
if ((tmp = getnum(blob)) != 0xFFFF) {
chop_cnt = tmp;
lastcommands = blob->commands;
}
}
if(chop_cnt){
if (chop_cnt) {
chop_cnt--;
blob->commands = lastcommands;
}
blob->str = strtok_r (NULL, delim, &last);
blob->str = strtok_r(NULL, delim, &last);
if ( blob->str == 0) goto fail;
if (blob->str == 0)
goto fail;
blob->fontIndex = fonts[0].fontIndex;
blob->fontData = fonts[0].fontData;
blob->font_storebytes = fonts[0].storebytes;
unsigned char tmp1, *strg = (unsigned char*)blob->str;
unsigned char tmp1, *strg = (unsigned char*) blob->str;
unsigned char glyph_beg = fonts[0].glyph_beg;
unsigned char glyph_end = fonts[0].glyph_end;
//translate the string: subtract 1 to get offset in Table
while((tmp1 = *strg)){
if((tmp1>=glyph_beg) && (tmp1<glyph_end)){
while ((tmp1 = *strg)) {
if ((tmp1 >= glyph_beg) && (tmp1 < glyph_end)) {
*strg = 1 + tmp1 - glyph_beg;
}else{
} else {
*strg = 1;
}
strg++;
@ -356,22 +363,29 @@ blob_t * setupBlob(char * str){
blob->sizey = fonts[0].fontHeight;
blob->sizex = getLen(blob);
if(*blob->commands == '<'){
blob->posx = 0;
blob->posy = (UNUM_ROWS-blob->sizey)/2; //MARK
}else if(*blob->commands == '>'){
blob->posx = NUM_COLS+blob->sizex;
blob->posy = (UNUM_ROWS-blob->sizey)/2; //MARK
}else if(*blob->commands == 'd'){
blob->posy = -blob->sizey;
blob->posx = (UNUM_COLS - 2 + blob->sizex)/2; //MARK
}else if(*blob->commands == 'u'){
blob->posy = blob->sizey;
blob->posx = (UNUM_COLS - 2 + blob->sizex)/2; //MARK
}else if(*blob->commands == 'x'){
blob->posy = (UNUM_ROWS-blob->sizey)/2; //MARK
}else if(*blob->commands == 'y'){
blob->posx = (UNUM_COLS - 2 + blob->sizex)/2; //MARK
switch (*blob->commands) {
case '<':
blob->posx = 0;
blob->posy = (UNUM_ROWS - blob->sizey) / 2; //MARK
break;
case '>':
blob->posx = NUM_COLS + blob->sizex;
blob->posy = (UNUM_ROWS - blob->sizey) / 2; //MARK
break;
case 'd':
blob->posy = -blob->sizey;
blob->posx = (UNUM_COLS - 2 + blob->sizex) / 2; //MARK
break;
case 'u':
blob->posy = blob->sizey;
blob->posx = (UNUM_COLS - 2 + blob->sizex) / 2; //MARK
break;
case 'x':
blob->posy = (UNUM_ROWS - blob->sizey) / 2; //MARK
break;
case 'y':
blob->posx = (UNUM_COLS - 2 + blob->sizex) / 2; //MARK
break;
}
blob->delayx_rld = 0;
@ -388,59 +402,60 @@ fail:
}
unsigned char updateBlob(blob_t * blob){
if(blob->delayx_rld && (!(blob->delayx--))){
unsigned char updateBlob(blob_t *blob)
{
if (blob->delayx_rld && (!(blob->delayx--))) {
blob->delayx = blob->delayx_rld;
(blob->direction & DIRECTION_RIGHT)?blob->posx--:blob->posx++;
(blob->direction & DIRECTION_RIGHT) ? blob->posx-- : blob->posx++;
}
if(blob->delayy_rld && (!(blob->delayy--))){
if (blob->delayy_rld && (!(blob->delayy--))) {
blob->delayy = blob->delayy_rld;
(blob->direction & DIRECTION_DOWN)?blob->posy++:blob->posy--;
(blob->direction & DIRECTION_DOWN) ? blob->posy++ : blob->posy--;
}
if(blob->delayb_rld){
if(!(blob->delayb--)){
if (blob->delayb_rld) {
if (!(blob->delayb--)) {
blob->delayb = blob->delayb_rld;
blob->visible ^= 1;
}
}else{
} else {
blob->visible = 1;
}
unsigned char done=0;
switch (blob->waitfor){
unsigned char done = 0;
switch (blob->waitfor) {
case wait_posy:
if (blob->posy == blob->toy)done = 1;
if (blob->posy == blob->toy)
done = 1;
break;
case wait_posx:
if (blob->posx == blob->tox)done = 1;
if (blob->posx == blob->tox)
done = 1;
break;
case wait_out:
if((blob->posx - blob->sizex) > NUM_COLS || blob->posx < 0) done = 1;
if((blob->posy) > NUM_ROWS || (blob->posy + blob->sizey) <0 ) done = 1;
if ((blob->posx - blob->sizex) > NUM_COLS || blob->posx < 0)
done = 1;
if ((blob->posy) > NUM_ROWS || (blob->posy + blob->sizey) < 0)
done = 1;
break;
case wait_timer:
if(0 == blob->timer--){
if (0 == blob->timer--)
done = 1;
}
break;
case wait_col_l:
if(blob->last){
if((blob->last->posx - blob->last->sizex) == blob->posx){
done=1;
}
}else{
if (blob->last) {
if ((blob->last->posx - blob->last->sizex) == blob->posx)
done = 1;
} else {
done = 1;
}
break;
case wait_col_r:
if(blob->next){
if(blob->next->posx == (blob->posx - blob->sizex)){
done=1;
}
}else{
if (blob->next) {
if (blob->next->posx == (blob->posx - blob->sizex))
done = 1;
} else {
done = 1;
}
break;
@ -448,41 +463,44 @@ unsigned char updateBlob(blob_t * blob){
done = 1;
break;
}
if(done){
return (blobNextCommand(blob));
if (done) {
return blobNextCommand(blob);
}
return 0;
}
void drawBlob(blob_t *blob) {
static void drawBlob(blob_t *blob)
{
char x, y;
unsigned char byte=0, glyph, storebytes;
unsigned char byte = 0, glyph, storebytes;
unsigned int charPos, charEnd;
unsigned int posx; unsigned char posy, toy;
if(!blob->visible) return;
if (!blob->visible)
return;
unsigned char * str = (unsigned char*)blob->str;
unsigned char *str = (unsigned char*) blob->str;
posx = blob->posx;
posy = blob->posy;
toy = posy + blob->sizey;
storebytes = blob->font_storebytes;
glyph = (*blob->str)-1;
glyph = (*blob->str) - 1;
charPos = PW(blob->fontIndex[glyph]);
charEnd = PW(blob->fontIndex[glyph+1]);
charEnd = PW(blob->fontIndex[glyph + 1]);
while (posx >= NUM_COLS) {
charPos += storebytes;
if (charPos < charEnd) {
posx--;
}else{
} else {
posx -= blob->space + 1;
if (!(glyph = *++str)) return;
if (!(glyph = *++str))
return;
glyph -= 1;
charPos = PW(blob->fontIndex[glyph]);
charEnd = PW(blob->fontIndex[glyph+1]);
charEnd = PW(blob->fontIndex[glyph + 1]);
}
}
for (x = posx; x >= 0; x-- ) {
@ -492,30 +510,32 @@ void drawBlob(blob_t *blob) {
for (y = posy; (y < NUM_ROWS) && (y < toy); y++) {
if((mask<<=1) == 0){
if ((mask <<= 1) == 0) {
mask = 0x01;
byte = PB(blob->fontData[datpos++]);
}
if ((byte & mask) && y >= 0 ) {
text_setpixel((pixel){x, y},1);
text_setpixel((pixel) {x, y}, 1);
}
}
charPos += storebytes;
if (charPos < charEnd) {
}else{
} else {
x -= blob->space;
if (!(glyph = *++str)) return;
if (!(glyph = *++str))
return;
glyph -= 1;
charPos = PW(blob->fontIndex[glyph]);
charEnd = PW(blob->fontIndex[glyph+1]);
charEnd = PW(blob->fontIndex[glyph + 1]);
}
}
}
extern jmp_buf newmode_jmpbuf;
void scrolltext(char *str) {
void scrolltext(char *str)
{
jmp_buf tmp_jmpbuf;
char tmp_str[SCROLLTEXT_BUFFER_SIZE];
int ljmp_retval;
@ -525,55 +545,55 @@ void scrolltext(char *str) {
unsigned char auto_pixmap[NUM_ROWS][LINEBYTES];
text_pixmap = &auto_pixmap;
if(scrolltext_text[0] == 0){
if (scrolltext_text[0] == 0) {
strcpy_P(scrolltext_text, default_text);
}
memcpy(tmp_str, str, SCROLLTEXT_BUFFER_SIZE);
blob_t *startblob=0, *aktblob, *nextblob=0;
blob_t *startblob = 0, *aktblob, *nextblob = 0;
memcpy (tmp_jmpbuf, newmode_jmpbuf, sizeof(jmp_buf));
if((ljmp_retval = setjmp(newmode_jmpbuf))){
while(startblob){
memcpy(tmp_jmpbuf, newmode_jmpbuf, sizeof(jmp_buf));
if ((ljmp_retval = setjmp(newmode_jmpbuf))) {
while (startblob) {
aktblob = startblob;
startblob = aktblob->next;
free(aktblob);
}
memcpy (newmode_jmpbuf, tmp_jmpbuf, sizeof(jmp_buf));
memcpy(newmode_jmpbuf, tmp_jmpbuf, sizeof(jmp_buf));
longjmp(newmode_jmpbuf, ljmp_retval);
}
if (!(startblob = setupBlob(tmp_str))){
if (!(startblob = setupBlob(tmp_str))) {
goto exit;
}
unsigned char retval;
do{
do {
startblob->next = 0;
startblob->last = 0;
while(startblob){
while (startblob) {
aktblob = startblob;
while(aktblob){
while (aktblob) {
retval = updateBlob(aktblob);
if(!retval){
if (!retval) {
nextblob = aktblob->next;
}else if(retval == 1){
if(aktblob == startblob){
} else if (retval == 1) {
if (aktblob == startblob) {
startblob = aktblob->next;
}else{
} else {
aktblob->last->next = aktblob->next;
}
if(aktblob->next){
if (aktblob->next) {
aktblob->next->last = aktblob->last;
}
nextblob = aktblob->next;
free(aktblob);
}else if(retval == 2){
blob_t * newblob = setupBlob(0);
if (newblob){
} else if (retval == 2) {
blob_t *newblob = setupBlob(0);
if (newblob) {
newblob->last = aktblob;
newblob->next = aktblob->next;
if(aktblob->next){
if (aktblob->next) {
aktblob->next->last = newblob;
}
aktblob->next = newblob;
@ -585,7 +605,7 @@ void scrolltext(char *str) {
aktblob = startblob;
clear_text_pixmap();
while(aktblob){
while (aktblob) {
drawBlob(aktblob);
aktblob = aktblob->next;
}
@ -594,8 +614,8 @@ void scrolltext(char *str) {
};
startblob = setupBlob(0);
//showBlob(startblob);
}while(startblob);
} while (startblob);
exit:
memcpy (newmode_jmpbuf, tmp_jmpbuf, sizeof(jmp_buf));
memcpy(newmode_jmpbuf, tmp_jmpbuf, sizeof(jmp_buf));
}

Loading…
Cancel
Save