lcd/render.c: save 56 bytes

Introduce a utility function that reads a single byte from the current position
in the font file.
This commit is contained in:
Øyvind Kolås 2011-08-03 14:53:04 +01:00 committed by Stefan `Sec` Zehl
parent 81294835ec
commit ad0c993136
1 changed files with 18 additions and 12 deletions

View File

@ -8,6 +8,7 @@
#include "fonts/smallfonts.h"
#include "filesystem/ff.h"
#include "render.h"
/* Global Variables */
const struct FONT_DEF * font = NULL;
@ -40,6 +41,13 @@ int getFontHeight(void){
return 8; // XXX: Should be done right.
};
static uint8_t read_byte (void)
{
UINT readbytes;
uint8_t byte;
f_read(&file, &byte, sizeof(uint8_t), &readbytes);
return byte;
}
int _getFontData(int type, int offset){
UINT readbytes;
@ -51,10 +59,10 @@ int _getFontData(int type, int offset){
if(efont.type == FONT_EXTERNAL){
if (type == START_FONT){
res = f_read(&file, &efont.def.u8Width, sizeof(uint8_t), &readbytes);
res = f_read(&file, &efont.def.u8Height, sizeof(uint8_t), &readbytes);
res = f_read(&file, &efont.def.u8FirstChar, sizeof(uint8_t), &readbytes);
res = f_read(&file, &efont.def.u8LastChar, sizeof(uint8_t), &readbytes);
efont.def.u8Width = read_byte ();
efont.def.u8Height = read_byte ();
efont.def.u8FirstChar = read_byte ();
efont.def.u8LastChar = read_byte ();
res = f_read(&file, &extras, sizeof(uint16_t), &readbytes);
return 0;
};
@ -72,9 +80,7 @@ int _getFontData(int type, int offset){
return 0;
};
if(type == GET_WIDTH || type == GET_DATA){
uint8_t width;
res = f_read(&file, &width, sizeof(uint8_t), &readbytes);
return width;
return read_byte ();
};
if(type == SEEK_DATA){
character=offset;
@ -87,7 +93,7 @@ int _getFontData(int type, int offset){
};
if(type == PEEK_DATA){
uint8_t width;
res = f_read(&file, &width, sizeof(uint8_t), &readbytes);
width = read_byte ();
f_lseek(&file,6+
(extras*sizeof(uint16_t))+
((extras+font->u8LastChar-font->u8FirstChar)*sizeof(uint8_t))+
@ -240,10 +246,10 @@ int DoChar(int sx, int sy, int c){
UINT res;
UINT readbytes;
uint8_t testbyte;
res = f_read(&file, &testbyte, sizeof(uint8_t), &readbytes);
testbyte = read_byte ();
if(testbyte>>4 ==15){
res = f_read(&file, &preblank, sizeof(uint8_t), &readbytes);
res = f_read(&file, &postblank, sizeof(uint8_t), &readbytes);
preblank = read_byte ();
postblank = read_byte ();
width-=3;
width/=height;
res = f_read(&file, charBuf, width*height, &readbytes);