From cd225736f95555c7083b642675d013bff8057d76 Mon Sep 17 00:00:00 2001 From: Björn Stenberg Date: Sun, 11 Aug 2002 09:17:47 +0000 Subject: First version of loadable fonts patch by Alex Gitelman git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1666 a1c6a512-1295-4272-9138-f99709370657 --- firmware/Makefile | 13 +++- firmware/common/dir.c | 1 + firmware/drivers/fat.c | 38 ++++++++-- firmware/drivers/lcd.c | 198 ++++++++++++++++++++++++++++++++++++++++++------- firmware/drivers/lcd.h | 11 +++ firmware/mpeg.c | 2 + firmware/panic.c | 5 +- 7 files changed, 230 insertions(+), 38 deletions(-) (limited to 'firmware') diff --git a/firmware/Makefile b/firmware/Makefile index 69a27a1b40..eb173848f3 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -15,6 +15,8 @@ OC = sh-elf-objcopy INCLUDES=-Iinclude -I. -Icommon -Idrivers +SYSTEM_FONT = fonts/alt6x10.bdf + # Pick a target to build for TARGET = -DARCHOS_PLAYER=1 #TARGET = -DARCHOS_PLAYER_OLD=1 @@ -23,7 +25,7 @@ TARGET = -DARCHOS_PLAYER=1 # store output files in this directory: OBJDIR = . -CFLAGS = -W -Wall -O -m1 -nostdlib -Wstrict-prototypes $(INCLUDES) $(TARGET) +CFLAGS = -W -Wall -O -m1 -nostdlib -Wstrict-prototypes $(INCLUDES) $(TARGET) $(EXTRA_DEFINES) ifdef DEBUG CFLAGS += -g -DDEBUG @@ -39,7 +41,11 @@ DEPDIRS:=$(DEPS) $(DEPS)/drivers $(DEPS)/common $(DEPS)/malloc OUTPUT = $(OBJDIR)/librockbox.a -$(OUTPUT): $(OBJS) +ifdef LOADABLE_FONTS + EXTRA_TARGETS = $(OBJDIR)/system.ajf +endif + +$(OUTPUT): $(OBJS) $(EXTRA_TARGETS) $(AR) ruv $@ $+ $(OBJDIR)/%.o: %.c @@ -50,6 +56,9 @@ $(OBJDIR)/%.o: %.S @mkdir -p `dirname $@` $(CC) $(CFLAGS) -c $< -o $@ +$(OBJDIR)/system.ajf: ../tools/bdf2ajf $(SYSTEM_FONT) + ../tools/bdf2ajf -f $(SYSTEM_FONT) -o $(OBJDIR)/system.ajf + clean: rm -f $(OBJS) $(OUTPUT) rm -rf $(OBJDIR)/$(DEPS) diff --git a/firmware/common/dir.c b/firmware/common/dir.c index 473997bd37..809e1a28e5 100644 --- a/firmware/common/dir.c +++ b/firmware/common/dir.c @@ -107,6 +107,7 @@ struct dirent* readdir(DIR* dir) if ( !entry.name[0] ) return NULL; + strncpy(theent->d_name, entry.name, sizeof( theent->d_name ) ); theent->attribute = entry.attr; diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c index 75915bd710..7fe011c863 100644 --- a/firmware/drivers/fat.c +++ b/firmware/drivers/fat.c @@ -27,6 +27,7 @@ #include #endif #include +#include #include "fat.h" #include "ata.h" #include "debug.h" @@ -1029,12 +1030,14 @@ int fat_getnext(struct fat_dir *dir, struct fat_direntry *entry) /* replace shortname with longname? */ if ( longs ) { int j,k,l=0; - /* iterate backwards through the dir entries */ for (j=longs-1; j>=0; j--) { unsigned char* ptr = dir->cached_buf; int index = longarray[j]; - +#ifdef LOADABLE_FONTS + int offset_idx = 0; + unsigned char uni_char[2]; +#endif /* current or cached sector? */ if ( sectoridx >= SECTOR_SIZE ) { if ( sectoridx >= SECTOR_SIZE*2 ) { @@ -1052,16 +1055,39 @@ int fat_getnext(struct fat_dir *dir, struct fat_direntry *entry) index &= SECTOR_SIZE-1; } - /* piece together the name subcomponents. - names are stored in unicode, but we - only grab the low byte (iso8859-1). - */ + /* piece together the name subcomponents. */ +#ifdef LOADABLE_FONTS + for (k=0; k<5; k++) + { + offset_idx = index + k*2 + 1; + uni_char[0] = ptr[offset_idx+1]; + uni_char[1] = ptr[offset_idx]; + entry->name[l++] = from_unicode(uni_char); + } + for (k=0; k<6; k++) + { + offset_idx = index + k*2 + 14; + uni_char[0] = ptr[offset_idx+1]; + uni_char[1] = ptr[offset_idx]; + entry->name[l++] = from_unicode(uni_char); + } + for (k=0; k<2; k++) + { + offset_idx = index + k*2 + 28; + uni_char[0] = ptr[offset_idx+1]; + uni_char[1] = ptr[offset_idx]; + entry->name[l++] = from_unicode(uni_char); + } +#else + /* names are stored in unicode, but we + only grab the low byte (iso8859-1). */ for (k=0; k<5; k++) entry->name[l++] = ptr[index + k*2 + 1]; for (k=0; k<6; k++) entry->name[l++] = ptr[index + k*2 + 14]; for (k=0; k<2; k++) entry->name[l++] = ptr[index + k*2 + 28]; +#endif } entry->name[l]=0; } diff --git a/firmware/drivers/lcd.c b/firmware/drivers/lcd.c index a9cd8c65ac..806b812b82 100644 --- a/firmware/drivers/lcd.c +++ b/firmware/drivers/lcd.c @@ -27,6 +27,13 @@ #include "debug.h" #include "system.h" +#ifdef LOADABLE_FONTS +#include "ajf.h" +#include "panic.h" +#endif + + + /*** definitions ***/ #define LCDR (PBDR_ADDR+1) @@ -296,21 +303,21 @@ static void lcd_write(bool command, int byte) PBDR &= ~LCD_CS; /* enable lcd chip select */ if ( command ) { - on=~(LCD_SD|LCD_SC|LCD_DS); - off=LCD_SC; + on=~(LCD_SD|LCD_SC|LCD_DS); + off=LCD_SC; } else { - on=~(LCD_SD|LCD_SC); - off=LCD_SC|LCD_DS; + on=~(LCD_SD|LCD_SC); + off=LCD_SC|LCD_DS; } /* clock out each bit, MSB first */ for (i=0x80;i;i>>=1) { - PBDR &= on; - if (i & byte) - PBDR |= LCD_SD; - PBDR |= off; + PBDR &= on; + if (i & byte) + PBDR |= LCD_SD; + PBDR |= off; } PBDR |= LCD_CS; /* disable lcd chip select */ @@ -322,9 +329,9 @@ static void lcd_write(bool command, int byte) void lcd_backlight(bool on) { if ( on ) - PAIOR |= LCD_BL; + PAIOR |= LCD_BL; else - PAIOR &= ~LCD_BL; + PAIOR &= ~LCD_BL; } #endif /* SIMULATOR */ @@ -431,7 +438,7 @@ void lcd_define_pattern (int which,char *pattern,int length) int i; lcd_write(true,LCD_PRAM|which); for (i=0;iheight) + height = dh; + width+=dw; + } + *w = width; + *h = height; + + return width; +} + +/* + * Put a string at specified bit position + */ + +void lcd_putsldfxy(int x, int y, unsigned char *str) +{ + unsigned char ch; + int nx; + int ny=8; + int lcd_x = x; + int lcd_y = y; + if (!_font) + { + lcd_putsxy(0,0,"No font", 0); + return; + } + ny = (int)_font[2]; + while (((ch = *str++) != '\0')) + { + unsigned char *char_buf = ajf_get_charbuf(ch, _font, &nx, &ny); + if (!char_buf) + { + char_buf = ajf_get_charbuf('?', _font, &nx, &ny); + if (!char_buf) + panicf("Bad font"); + } + if(lcd_x + nx > LCD_WIDTH) + break; + + lcd_clearrect (lcd_x, lcd_y, 1, ny); + lcd_bitmap (&char_buf[0], lcd_x, lcd_y, nx, ny, true); + lcd_x += nx+1; + } +} +#endif + + #ifdef LCD_PROPFONTS extern unsigned char char_dw_8x8_prop[][9]; @@ -746,10 +850,19 @@ void lcd_puts(int x, int y, unsigned char *str) ymargin = 8; #endif + if(!str || !str[0]) + return; + #ifdef LCD_PROPFONTS lcd_putspropxy( xmargin + x*fonts[font], ymargin + y*fontheight[font], str, font ); +#elif LOADABLE_FONTS + { + int w,h; + lcd_getstringsize(str,_font,&w,&h); + lcd_putsldfxy( xmargin + x*w/strlen(str), ymargin + y*h, str ); + } #else lcd_putsxy( xmargin + x*fonts[font], ymargin + y*fontheight[font], @@ -1105,25 +1218,31 @@ void lcd_puts_scroll(int x, int y, unsigned char* string ) s->space = 11 - x; #else -#ifdef LCD_PROPFONTS +#if defined(LCD_PROPFONTS) || defined(LOADABLE_FONTS) unsigned char ch[2]; int w, h; #endif int width, height; lcd_getfontsize(font, &width, &height); -#ifndef LCD_PROPFONTS - s->space = (LCD_WIDTH - xmargin - x*width) / width; -#else +#if defined(LCD_PROPFONTS) || defined(LOADABLE_FONTS) ch[1] = 0; /* zero terminate */ ch[0] = string[0]; width = 0; - for (s->space = 0; - ch[0] && - (width + lcd_getstringsize(ch, 0, &w, &h) < (LCD_WIDTH - x*8)); - ) { + s->space = 0; + while ( ch[0] && +#ifdef LCD_PROPFONTS + (width + lcd_getstringsize(ch, 0, &w, &h) < + (LCD_WIDTH - x*8))) { +#else + (width + lcd_getstringsize(ch, _font, &w, &h) < + (LCD_WIDTH - x*8))) { +#endif width += w; - ch[0]=string[(int)++s->space]; + s->space++; + ch[0]=string[s->space]; } +#else + s->space = (LCD_WIDTH - xmargin - x*width) / width; #endif #endif @@ -1148,11 +1267,25 @@ void lcd_stop_scroll(void) scroll_count = 0; #ifdef LCD_PROPFONTS + lcd_clearrect(xmargin + s->startx*fonts[font], - ymargin + s->starty*fontheight[font], - LCD_WIDTH - xmargin, - fontheight[font]); + ymargin + s->starty*fontheight[font], + LCD_WIDTH - xmargin, + fontheight[font]); + +#elif defined(LOADABLE_FONTS) + { + int w,h; + lcd_getstringsize( s->text, _font, &w, &h); + lcd_clearrect(xmargin + s->startx*w/s->textlen, + ymargin + s->starty*h, + LCD_WIDTH - xmargin, + h); + + } #endif + + /* restore scrolled row */ lcd_puts(s->startx,s->starty,s->text); lcd_update(); @@ -1208,6 +1341,15 @@ static void scroll_thread(void) ymargin + s->starty*fontheight[font], LCD_WIDTH - xmargin, fontheight[font]); +#elif defined(LOADABLE_FONTS) + { + int w,h; + lcd_getstringsize( s->text, _font, &w, &h); + lcd_clearrect(xmargin + s->startx*w/s->textlen, + ymargin + s->starty*h, + LCD_WIDTH - xmargin, + h); + } #endif lcd_puts(s->startx,s->starty,s->line); lcd_update(); diff --git a/firmware/drivers/lcd.h b/firmware/drivers/lcd.h index bc971dc117..ed2fe7ee45 100644 --- a/firmware/drivers/lcd.h +++ b/firmware/drivers/lcd.h @@ -105,4 +105,15 @@ extern void lcd_clearpixel(int x, int y); #endif /* CHARCELLS / BITMAP */ +#ifdef LOADABLE_FONTS +extern int lcd_init_fonts(void); +extern void lcd_putsldfxy(int x, int y, unsigned char *str); +extern int lcd_getstringsize(unsigned char *str, + unsigned char* font, + int *w, int *h); +extern void lcd_setldfont(unsigned char* f); + +extern unsigned char* lcd_getcurrentldfont(void); +#endif + #endif /* __LCD_H__ */ diff --git a/firmware/mpeg.c b/firmware/mpeg.c index efe7570bff..a85545efce 100644 --- a/firmware/mpeg.c +++ b/firmware/mpeg.c @@ -967,6 +967,7 @@ static void mpeg_thread(void) case SYS_USB_CONNECTED: stop_playing(); +#ifndef SIMULATOR /* Tell the USB thread that we are safe */ DEBUGF("mpeg_thread got SYS_USB_CONNECTED\n"); @@ -974,6 +975,7 @@ static void mpeg_thread(void) /* Wait until the USB cable is extracted again */ usb_wait_for_disconnect(&mpeg_queue); +#endif break; } } diff --git a/firmware/panic.c b/firmware/panic.c index f9023fe704..b130482495 100644 --- a/firmware/panic.c +++ b/firmware/panic.c @@ -8,7 +8,7 @@ * $Id$ * * Copyright (C) 2002 by wavey@wavey.org - * + *nn * All files in this archive are subject to the GNU General Public License. * See the file COPYING in the source tree root for full license agreement. * @@ -48,8 +48,9 @@ void panicf( char *fmt, ...) lcd_puts(0,0,panic_buf); #elif defined(HAVE_LCD_BITMAP) lcd_clear_display(); - lcd_puts(0,0,panic_buf); + lcd_putsxy(0,0,panic_buf,0); lcd_update(); + #else /* no LCD */ #endif -- cgit v1.2.3