Browse Source

src/scrolltext: fix codestyle

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

2
src/scrolltext/scrolltext.h

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

110
src/scrolltext/scrolltext3.c

@ -36,12 +36,12 @@
font fonts[MAX_FONTS]; font fonts[MAX_FONTS];
#define MAX_SPECIALCOLORS 3 #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, 1, 1, 2, 3, 3,
3, 3, 2, 2, 3, 3, 2, 2 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]; char scrolltext_text[SCROLLTEXT_BUFFER_SIZE];
/* Konzept /* Konzept
@ -57,23 +57,24 @@ 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 ){ static void text_setpixel(pixel p, unsigned char value)
if(value){ {
if (value)
(*text_pixmap)[p.y % NUM_ROWS][p.x / 8] |= shl_table[p.x % 8]; (*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); memset(text_pixmap, 0, NUM_ROWS * LINEBYTES);
} }
static void update_pixmap(){ static void update_pixmap()
for(unsigned char p = NUMPLANE; p--;){ {
for (unsigned char p = NUMPLANE; p--;)
memcpy(&pixmap[p][0][0], text_pixmap, NUM_ROWS * LINEBYTES); memcpy(&pixmap[p][0][0], text_pixmap, NUM_ROWS * LINEBYTES);
} }
}
enum waitfor_e { enum waitfor_e {
wait_new, wait_new,
@ -124,7 +125,8 @@ typedef struct blob_t_struct{
/* /*
void showBlob(blob_t * blob){ void showBlob(blob_t *blob)
{
unsigned char *str = blob->str; unsigned char *str = blob->str;
unsigned char tmp[200], x = 0; unsigned char tmp[200], x = 0;
while (*str) { while (*str) {
@ -152,7 +154,8 @@ void showBlob(blob_t * blob){
#define PW(a) pgm_read_word(&(a)) #define PW(a) pgm_read_word(&(a))
#define PB(a) pgm_read_byte(&(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 char glyph;
unsigned int strLen = 0; unsigned int strLen = 0;
unsigned char *str = (unsigned char*) blob->str; unsigned char *str = (unsigned char*) blob->str;
@ -167,7 +170,8 @@ static unsigned int getLen(blob_t *blob) {
} }
static unsigned int getnum(blob_t * blob){ static unsigned int getnum(blob_t *blob)
{
unsigned int num = 0; unsigned int num = 0;
unsigned char gotnum = 0; unsigned char gotnum = 0;
@ -178,14 +182,14 @@ static unsigned int getnum(blob_t * blob){
blob->commands++; blob->commands++;
} }
if(gotnum){ if (gotnum)
return num; return num;
}else{ else
return 0xffff; return 0xffff;
} }
}
unsigned char blobNextCommand(blob_t * blob){ unsigned char blobNextCommand(blob_t *blob)
{
unsigned int tmp; unsigned int tmp;
unsigned char retval = 0; unsigned char retval = 0;
while (*blob->commands != 0) { while (*blob->commands != 0) {
@ -264,7 +268,7 @@ unsigned char blobNextCommand(blob_t * blob){
blob->waitfor = wait_posy; blob->waitfor = wait_posy;
return retval; return retval;
break; break;
case 'p': case 'p'://delay
blob->delayx_rld = 0; blob->delayx_rld = 0;
blob->delayy_rld = 0; blob->delayy_rld = 0;
if ((tmp = getnum(blob)) != 0xFFFF) { if ((tmp = getnum(blob)) != 0xFFFF) {
@ -296,7 +300,8 @@ unsigned char blobNextCommand(blob_t * blob){
} }
blob_t * setupBlob(char * str){ static blob_t *setupBlob(char *str)
{
static unsigned char chop_cnt; static unsigned char chop_cnt;
static char *last; static char delim[] = "#"; static char *last; static char delim[] = "#";
static char *lastcommands; static char *lastcommands;
@ -317,7 +322,8 @@ blob_t * setupBlob(char * str){
if (!chop_cnt) { if (!chop_cnt) {
blob->commands = strtok_r(str, delim, &last); 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; chop_cnt = tmp;
@ -332,7 +338,8 @@ blob_t * setupBlob(char * str){
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->fontIndex = fonts[0].fontIndex;
blob->fontData = fonts[0].fontData; blob->fontData = fonts[0].fontData;
@ -356,22 +363,29 @@ blob_t * setupBlob(char * str){
blob->sizey = fonts[0].fontHeight; blob->sizey = fonts[0].fontHeight;
blob->sizex = getLen(blob); blob->sizex = getLen(blob);
if(*blob->commands == '<'){ switch (*blob->commands) {
case '<':
blob->posx = 0; blob->posx = 0;
blob->posy = (UNUM_ROWS - blob->sizey) / 2; //MARK blob->posy = (UNUM_ROWS - blob->sizey) / 2; //MARK
}else if(*blob->commands == '>'){ break;
case '>':
blob->posx = NUM_COLS + blob->sizex; blob->posx = NUM_COLS + blob->sizex;
blob->posy = (UNUM_ROWS - blob->sizey) / 2; //MARK blob->posy = (UNUM_ROWS - blob->sizey) / 2; //MARK
}else if(*blob->commands == 'd'){ break;
case 'd':
blob->posy = -blob->sizey; blob->posy = -blob->sizey;
blob->posx = (UNUM_COLS - 2 + blob->sizex) / 2; //MARK blob->posx = (UNUM_COLS - 2 + blob->sizex) / 2; //MARK
}else if(*blob->commands == 'u'){ break;
case 'u':
blob->posy = blob->sizey; blob->posy = blob->sizey;
blob->posx = (UNUM_COLS - 2 + blob->sizex) / 2; //MARK blob->posx = (UNUM_COLS - 2 + blob->sizex) / 2; //MARK
}else if(*blob->commands == 'x'){ break;
case 'x':
blob->posy = (UNUM_ROWS - blob->sizey) / 2; //MARK blob->posy = (UNUM_ROWS - blob->sizey) / 2; //MARK
}else if(*blob->commands == 'y'){ break;
case 'y':
blob->posx = (UNUM_COLS - 2 + blob->sizex) / 2; //MARK blob->posx = (UNUM_COLS - 2 + blob->sizex) / 2; //MARK
break;
} }
blob->delayx_rld = 0; blob->delayx_rld = 0;
@ -388,8 +402,8 @@ fail:
} }
unsigned char updateBlob(blob_t * blob){ unsigned char updateBlob(blob_t *blob)
{
if (blob->delayx_rld && (!(blob->delayx--))) { if (blob->delayx_rld && (!(blob->delayx--))) {
blob->delayx = blob->delayx_rld; blob->delayx = blob->delayx_rld;
(blob->direction & DIRECTION_RIGHT) ? blob->posx-- : blob->posx++; (blob->direction & DIRECTION_RIGHT) ? blob->posx-- : blob->posx++;
@ -412,34 +426,35 @@ unsigned char updateBlob(blob_t * blob){
unsigned char done = 0; unsigned char done = 0;
switch (blob->waitfor) { switch (blob->waitfor) {
case wait_posy: case wait_posy:
if (blob->posy == blob->toy)done = 1; if (blob->posy == blob->toy)
done = 1;
break; break;
case wait_posx: case wait_posx:
if (blob->posx == blob->tox)done = 1; if (blob->posx == blob->tox)
done = 1;
break; break;
case wait_out: case wait_out:
if((blob->posx - blob->sizex) > NUM_COLS || blob->posx < 0) done = 1; if ((blob->posx - blob->sizex) > NUM_COLS || blob->posx < 0)
if((blob->posy) > NUM_ROWS || (blob->posy + blob->sizey) <0 ) done = 1; done = 1;
if ((blob->posy) > NUM_ROWS || (blob->posy + blob->sizey) < 0)
done = 1;
break; break;
case wait_timer: case wait_timer:
if(0 == blob->timer--){ if (0 == blob->timer--)
done = 1; done = 1;
}
break; break;
case wait_col_l: case wait_col_l:
if (blob->last) { if (blob->last) {
if((blob->last->posx - blob->last->sizex) == blob->posx){ if ((blob->last->posx - blob->last->sizex) == blob->posx)
done = 1; done = 1;
}
} else { } else {
done = 1; done = 1;
} }
break; break;
case wait_col_r: case wait_col_r:
if (blob->next) { if (blob->next) {
if(blob->next->posx == (blob->posx - blob->sizex)){ if (blob->next->posx == (blob->posx - blob->sizex))
done = 1; done = 1;
}
} else { } else {
done = 1; done = 1;
} }
@ -449,19 +464,21 @@ unsigned char updateBlob(blob_t * blob){
break; break;
} }
if (done) { if (done) {
return (blobNextCommand(blob)); return blobNextCommand(blob);
} }
return 0; return 0;
} }
void drawBlob(blob_t *blob) { static void drawBlob(blob_t *blob)
{
char x, y; char x, y;
unsigned char byte = 0, glyph, storebytes; unsigned char byte = 0, glyph, storebytes;
unsigned int charPos, charEnd; unsigned int charPos, charEnd;
unsigned int posx; unsigned char posy, toy; 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; posx = blob->posx;
@ -479,7 +496,8 @@ void drawBlob(blob_t *blob) {
posx--; posx--;
} else { } else {
posx -= blob->space + 1; posx -= blob->space + 1;
if (!(glyph = *++str)) return; if (!(glyph = *++str))
return;
glyph -= 1; glyph -= 1;
charPos = PW(blob->fontIndex[glyph]); charPos = PW(blob->fontIndex[glyph]);
charEnd = PW(blob->fontIndex[glyph + 1]); charEnd = PW(blob->fontIndex[glyph + 1]);
@ -505,7 +523,8 @@ void drawBlob(blob_t *blob) {
if (charPos < charEnd) { if (charPos < charEnd) {
} else { } else {
x -= blob->space; x -= blob->space;
if (!(glyph = *++str)) return; if (!(glyph = *++str))
return;
glyph -= 1; glyph -= 1;
charPos = PW(blob->fontIndex[glyph]); charPos = PW(blob->fontIndex[glyph]);
charEnd = PW(blob->fontIndex[glyph + 1]); charEnd = PW(blob->fontIndex[glyph + 1]);
@ -515,7 +534,8 @@ void drawBlob(blob_t *blob) {
extern jmp_buf newmode_jmpbuf; extern jmp_buf newmode_jmpbuf;
void scrolltext(char *str) { void scrolltext(char *str)
{
jmp_buf tmp_jmpbuf; jmp_buf tmp_jmpbuf;
char tmp_str[SCROLLTEXT_BUFFER_SIZE]; char tmp_str[SCROLLTEXT_BUFFER_SIZE];
int ljmp_retval; int ljmp_retval;

Loading…
Cancel
Save