diff --git a/bm2ppm.py b/bm2ppm.py index 8562d4c..7bc1827 100644 --- a/bm2ppm.py +++ b/bm2ppm.py @@ -13,9 +13,9 @@ def readfile(name): def toRGB(pixel): color = unpack(">10)&31)<<3 + red = ((color>>0)&31)<<3 green = ((color>>5)&31)<<3 - blue = ((color>>0)&31)<<3 + blue = ((color>>10)&31)<<3 return chr(red) + chr(green) + chr(blue) if __name__ == "__main__": diff --git a/libfc_visoly_xg1/libflashcart.a b/libfc_visoly_xg1/libflashcart.a index c346688..b889617 100644 Binary files a/libfc_visoly_xg1/libflashcart.a and b/libfc_visoly_xg1/libflashcart.a differ diff --git a/libfc_xrom/libflashcart.a b/libfc_xrom/libflashcart.a index ab1d404..d901d49 100644 Binary files a/libfc_xrom/libflashcart.a and b/libfc_xrom/libflashcart.a differ diff --git a/libpogo/lib/libpogo.a b/libpogo/lib/libpogo.a index 17cefdd..b59139d 100644 Binary files a/libpogo/lib/libpogo.a and b/libpogo/lib/libpogo.a differ diff --git a/libpogo/lib/libpogod.a b/libpogo/lib/libpogod.a index e3dfebc..cb6ce92 100644 Binary files a/libpogo/lib/libpogod.a and b/libpogo/lib/libpogod.a differ diff --git a/shell2/Makefile b/shell2/Makefile index 545ef27..ea25109 100644 --- a/shell2/Makefile +++ b/shell2/Makefile @@ -42,7 +42,7 @@ WIDGETS = widgets/textbar.o widgets/tricontainer.o widgets/listview.o widgets/te CART_OBJFILES = main.o filetype.o filesys.o -FULL_OBJFILES = bmpview.o jpgview.o jpeg.o iwram.o sram_convert.o widgets/textreader.o +FULL_OBJFILES = bmview.o bmpview.o jpgview.o jpeg.o iwram.o sram_convert.o widgets/textreader.o COMMON_OBJFILES = crt0.o text.o unapack.o bitmap.o window.o backdrop.o \ guiparser.o savesystem.o rle.o msgbox.o users.o \ diff --git a/shell2/bitmap.o b/shell2/bitmap.o index bb83cd8..221c470 100644 Binary files a/shell2/bitmap.o and b/shell2/bitmap.o differ diff --git a/shell2/bmpview.o b/shell2/bmpview.o index 5e66d06..2f79ac2 100644 Binary files a/shell2/bmpview.o and b/shell2/bmpview.o differ diff --git a/shell2/bmview.c b/shell2/bmview.c new file mode 100644 index 0000000..e4a5a00 --- /dev/null +++ b/shell2/bmview.c @@ -0,0 +1,135 @@ + +#include +#include "misc.h" + +#define BM 0x4D42 +#define BMHEADERSIZE 8 + +void bm_view(char *fname); + +static uint16 *bm_ptr; +static int bm_h; +static int bm_w; +static int bm_size; + +int prepare_bm(uint16 *ptr) +{ + int sfd; + + if (!ptr || ptr[0] != BM || ptr[1] != 0x10) + return 1; + + bm_w = ptr[2]; + bm_h = ptr[3]; + + if (bm_size != bm_w * bm_h * 2 + BMHEADERSIZE) + return 2; + + sfd = open("/dev/screen", 0); + ioctl(sfd, SC_SETMODE, 2); + close(sfd); + + bm_ptr = &ptr[4]; + return 0; +} + +#define MIN(a,b) (ab ? a : b) + +void render_bm(int x, int y) +{ + int wi; + uint16 *src, *dst; + + int w = MIN(bm_w, 240); + int h = MIN(bm_h, 160); + + if((x+240) > bm_w) + x = (bm_w-240); + if((y+160) > bm_h) + y = (bm_h-160); + + if(x < 0) x = 0; + if(y < 0) y = 0; + + src = &bm_ptr[y*bm_w+x]; + dst = (uint16 *)0x06000000; //vram + + while(h--) + { + wi = w; + while(wi--) + *dst++ = *src++; + dst += (240 - w); + } +} + +void bm_view(char *fname) +{ + int c, l, r, fd, quit = 0; + int x=0, y=0; + int dx=0, dy=0; + int speed = 8; + uint16 *bm; + uint32 *p = (uint32 *)0x06000000; + + fd = open(fname, 0); + bm = (uint16 *)lseek(fd, 0, SEEK_MEM); + bm_size = lseek(fd, 0, SEEK_END); + close(fd); + + r = prepare_bm(bm); + + if (r) { + l = 120*160; + while(l--) + *p++ = 0x7fff7fff; + } else { + l = 120*160; + while(l--) + *p++ = 0; + while(!quit) + { + render_bm(x, y); + + c = getchar(); + + switch(c&0x7F) + { + case RAWKEY_L: + speed = c&0x80 ? 8 : 128; + break; + case RAWKEY_RIGHT: + dx = c&0x80 ? 0 : speed; + break; + case RAWKEY_LEFT: + dx = c&0x80 ? 0 : -speed; + break; + case RAWKEY_UP: + dy = c&0x80 ? 0 : -speed; + break; + case RAWKEY_DOWN: + dy = c&0x80 ? 0 : speed; + break; + case RAWKEY_A: + case RAWKEY_B: + if(c != (RAWKEY_A|0x80)) + quit = 1; + break; + } + x += dx; + y += dy; + if((x+240) > bm_w) + x = (bm_w-240); + if((y+160) > bm_h) + y = (bm_h-160); + + if(x < 0) x = 0; + if(y < 0) y = 0; + } + } + + fd = open("/dev/screen", 0); + ioctl(fd, SC_SETMODE, 2); + close(fd); +} diff --git a/shell2/bmview.o b/shell2/bmview.o new file mode 100644 index 0000000..59b2ca6 Binary files /dev/null and b/shell2/bmview.o differ diff --git a/shell2/filesys.c b/shell2/filesys.c index 6308808..e38e750 100644 --- a/shell2/filesys.c +++ b/shell2/filesys.c @@ -81,10 +81,9 @@ void qsort(void *array, int count, int size, int cf(void *a, void *b)) static int get_dir(char *name, DirList *list) { int i; - char *p; DIR *dir; struct dirent *result; - struct stat sbuf; + //struct stat sbuf; i = 0; dir = opendir(name); @@ -97,14 +96,10 @@ static int get_dir(char *name, DirList *list) if(settings_get(SF_HIDEDOT) && list[i].entry.d_name[0] == '.') i--; else { - p = &name[strlen(name)]; - *p = '/'; - strcpy(p+1, list[i].entry.d_name); - stat(name, &sbuf); //fprintf(stderr, "get_dir(%s, %p); // (%s, %d)\n", name, list, list[i].entry.d_name, list[i].entry.d_size); //fprintf(stderr, "stat(%s, ...); // (..., %hd, ...)\n", name, sbuf.st_mode); - *p = '\0'; - list[i].type = (sbuf.st_mode & S_IFDIR) ? 1 : 0; + //*p = '\0'; + list[i].type = (list[i].entry.d_size & 0x80000000) ? 1 : 0; } } closedir(dir); diff --git a/shell2/filetype.c b/shell2/filetype.c index 8c6651c..2449cc9 100644 --- a/shell2/filetype.c +++ b/shell2/filetype.c @@ -16,6 +16,7 @@ extern int clipsize; extern uint16 marked; int execute_mb_joined(char *fname, int decompression, int keys); +void bm_view(char *fname); void bmp_view(char *fname); void bmz_view(char *fname); void bmap_view(char *fname); @@ -24,9 +25,11 @@ void jpe_view(char *fname); extern void reset(void); static BitMap **icon_set; +static BitMap *settings_icn = NULL; +static int settings_iconidx = -1; static int ftcount = 1; -static FileType *filetypes[50]; +static FileType *filetypes[100]; extern ListView *MainList; //extern TextBar *StatusBar; @@ -244,6 +247,13 @@ int show_text(char *cmd, char *fname, int keys) return 1; } +int showbm(char *cmd, char *fname, int keys) +{ + bm_view(fname); + MainScreen->firstWindow->widget->flags |= WFLG_REDRAW; + return 2; +} + int showbmp(char *cmd, char *fname, int keys) { bmp_view(fname); @@ -326,6 +336,7 @@ void filetype_readtypes(FILE *fp) f->command = NULL; f->compare_func = check_extention; f->handle_func = NULL; + f->textcolor = NULL; f->saver = 0; ptr[-1] = 0; @@ -340,10 +351,8 @@ void filetype_readtypes(FILE *fp) i = atoi(ptr); //fprintf(stderr, "ICON:%d\n", i); - if (icon_set) - f->icon = icon_set[i]; - else - f->icon = NULL; + f->iconidx = i; + f->icon = NULL; while(isdigit(*ptr++)); } else @@ -355,6 +364,7 @@ void filetype_readtypes(FILE *fp) //fp2 = fopen(p, "rb"); //f->icon = bitmap_readbm(fp2); //fclose(fp2); + f->iconidx = -1; f->icon = bitmap_loadbm(p); } @@ -372,15 +382,31 @@ void filetype_readtypes(FILE *fp) //fprintf(stderr, "SAVER:%d\n", f->saver); while(isdigit(*q++)); *ptr = 0; - ptr = q-1; + ptr = q - 1; + } + + if(*ptr == ' ' && *(ptr+1) == '$') + { + *ptr = 0; + ptr += 2; + i = gethex(ptr); + while (isalnum(*ptr++)); + q = ptr--; + f->textcolor = malloc(sizeof(Color)); + f->textcolor->r = (i>>16) & 0xff; + f->textcolor->g = (i>>8) & 0xff; + f->textcolor->b = i & 0xff; + f->textcolor->a = 0; } - /* The rest of the line is the description, if it exists */ - while((*q != 10) && (*q != 13)) q++; - *q = 0; - f->desc = malloc(strlen(ptr+1)+1); - strcpy(f->desc, ptr+1); - //fprintf(stderr, "DESC:%s\n", ptr+1); + if (*q && *q != 10 && *q != 13) { + /* The rest of the line is the description, if it exists */ + while ((*q != 10) && (*q != 13)) q++; + *q = 0; + f->desc = malloc(strlen(ptr+1)+1); + strcpy(f->desc, ptr+1); + //fprintf(stderr, "DESC:%s\n", ptr+1); + } } *ptr = 0; /* Set correct internal handler for filetype */ @@ -401,8 +427,9 @@ void filetype_readtypes(FILE *fp) } else if(strcmp(p, "SET") == 0) - { - settings_icon(f->icon); + { + settings_icn = f->icon; + settings_iconidx = f->iconidx; ftcount--; } else @@ -430,6 +457,9 @@ void filetype_readtypes(FILE *fp) if(strcmp(p, "FNT") == 0) f->handle_func = set_font; else + if(strcmp(p, "BM") == 0) + f->handle_func = showbm; + else if(strcmp(p, "BMP") == 0) f->handle_func = showbmp; else @@ -464,6 +494,37 @@ void filetype_set_iconset(BitMap **icons) icon_set = icons; } +void filetype_set_icons(void) +{ + FileType *f; + int i; + for (i=1; iiconidx >= 0 && icon_set) + f->icon = icon_set[f->iconidx]; + } + if (settings_iconidx >= 0 && icon_set) { + settings_icn = icon_set[settings_iconidx]; + } + settings_icon(settings_icn); +} + +int filetype_font(DirList *entry) +{ + return (filetypes[filetype_lookup(entry)]->handle_func == set_font); +} + +int filetype_bm(DirList *entry) +{ + return (filetypes[filetype_lookup(entry)]->handle_func == showbm); +} + +int filetype_theme(DirList *entry) +{ + return (filetypes[filetype_lookup(entry)]->handle_func == set_theme); +} + int filetype_lookup(DirList *entry) { int i; @@ -496,3 +557,8 @@ BitMap *filetype_icon(int type) { return filetypes[type]->icon; } + +Color *filetype_textcolor(int type) +{ + return filetypes[type]->textcolor; +} diff --git a/shell2/filetype.h b/shell2/filetype.h index 662cfef..bef0fc0 100644 --- a/shell2/filetype.h +++ b/shell2/filetype.h @@ -6,7 +6,9 @@ typedef struct { + int iconidx; BitMap *icon; + Color *textcolor; int (*handle_func)(char *data, char *fname, int keys); char data[8]; int (*compare_func)(char *data, DirList *entry); @@ -17,11 +19,16 @@ typedef struct } FileType; void filetype_register(char *ext, BitMap *bm, int handler); +int filetype_bm(DirList *entry); +int filetype_font(DirList *entry); +int filetype_theme(DirList *entry); int filetype_lookup(DirList *entry); int filetype_handle(char *fname, int type, int keys); BitMap *filetype_icon(int type); +Color *filetype_textcolor(int type); void filetype_readtypes(FILE *fp); void filetype_set_iconset(BitMap **icons); +void filetype_set_icons(void); #endif diff --git a/shell2/guiparser.c b/shell2/guiparser.c index 7a74350..38ef1a6 100644 --- a/shell2/guiparser.c +++ b/shell2/guiparser.c @@ -4,6 +4,8 @@ #include "window.h" #include "widgets/widgets.h" #include "misc.h" +#include "filesys.h" +#include "filetype.h" typedef void *(*WidgetAttrFunc)(Widget *, int, void *); @@ -111,26 +113,6 @@ void guiparser_readsymbols(FILE *fp) } } -int gethex(char *p) -{ - int l = 0; - - while((*p >= '0' && *p <= '9') || - (*p >= 'A' && *p <= 'F') || - (*p >= 'a' && *p <= 'f')) - { - if(*p <= '9') - l = (l << 4) | ((*p++) - '0'); - else if (*p <= 'F') - l = (l << 4) | ((*p++) - 'A' + 10); - else - l = (l << 4) | ((*p++) - 'a' + 10); - } - - return l; -} - - void icons_set_attr(Widget *w, int attr, void *val) { switch(attr & 0xFF0) @@ -162,7 +144,9 @@ Widget *guiparser_create(char *spec, char *rootitem) char tmp[32]; char *d, *startp, *endp; char *p = spec; + DirList dl; + dl.entry.d_name[31] = '\0'; while(p && *p) { @@ -254,22 +238,15 @@ Widget *guiparser_create(char *spec, char *rootitem) while(*p != '>') *d++ = *p++; *d = 0; - - d--; - while(d > tmp && *d && *d != '.') d--; - - if(*d == '.') - d++; - else - d = tmp; - p++; + strncpy(dl.entry.d_name, tmp, 31); + //fprintf(stderr, "Opening file %s %s\n", tmp, d); //if(()) { - if(*d == 'b') + if(filetype_bm(&dl)) { //fp = fopen(tmp, "rb"); //bm = bitmap_readbm(fp); @@ -277,8 +254,7 @@ Widget *guiparser_create(char *spec, char *rootitem) bm = bitmap_loadbm(tmp); attr_func(lastw, attr, bm); } - else - if(*d == 'f') + else if(filetype_font(&dl)) { font = font_load_path(tmp); font->flags |= FFLG_TRANSP; diff --git a/shell2/guiparser.o b/shell2/guiparser.o index c5e6dad..3a99a8e 100644 Binary files a/shell2/guiparser.o and b/shell2/guiparser.o differ diff --git a/shell2/jpeg.c b/shell2/jpeg.c index 8568246..da5f463 100644 --- a/shell2/jpeg.c +++ b/shell2/jpeg.c @@ -711,6 +711,7 @@ int JPEG_DecompressImage (const unsigned char *data, JPEG_OUTPUT_TYPE **out, int dcTableList = pmalloc(sizeof(JPEG_HuffmanTable)*2); space_left = pmemory_free(); + fprintf(stderr, "space left: %d\n", space_left); // Clear memory. /*for (i = 0; i < 64*1024; i++) diff --git a/shell2/jpeg.o b/shell2/jpeg.o index b29196a..84225f7 100644 Binary files a/shell2/jpeg.o and b/shell2/jpeg.o differ diff --git a/shell2/jpgview.o b/shell2/jpgview.o index cae04aa..5a8b400 100644 Binary files a/shell2/jpgview.o and b/shell2/jpgview.o differ diff --git a/shell2/main.c b/shell2/main.c index 702084c..3e52355 100644 --- a/shell2/main.c +++ b/shell2/main.c @@ -68,7 +68,7 @@ char *path[5] = { NULL, NULL, NULL, NULL, NULL }; int sram_game_size = 64; int new_marked = -1; -uint16 marked; +int16 marked; const char *PogoVersion = "2.0b3mod5"; @@ -86,7 +86,7 @@ char *dirname; /* State, saved to /sram/.state */ struct { unsigned /*short*/ char settings[NO_SETTINGS]; - uint16 marked; + int16 marked; uint32 seed; } __attribute__ ((packed)) state; @@ -94,7 +94,6 @@ struct { void save_state(void) { int fd; - uchar usr; char *name = filesys_get_current(); memcpy(state.settings, settings, NO_SETTINGS); @@ -128,11 +127,15 @@ int load_state(void) srand(state.seed); memcpy(settings, state.settings, NO_SETTINGS); + sleep_time = sleep_array[settings_get(SF_SLEEP)]; if (settings_get(SF_THEME) >= theme_count) settings_set(SF_THEME, 0); get_theme_name(settings_get(SF_THEME), theme_name); return 1; } + + settings_default(); + sleep_time = sleep_array[settings_get(SF_SLEEP)]; get_theme_name(settings_get(SF_THEME), theme_name); return 0; @@ -271,30 +274,29 @@ int sram_paste(char *name) } struct tm clockdata; -char *oldtext = NULL; +char statusbar_buffer[50]; +char statusbar_postrtc[60]; + void statusbar_set(char *text) { - char tmp[80]; if(StatusBar) { - oldtext = text; + if (text) + strcpy(statusbar_buffer, text); + strcpy(statusbar_postrtc, statusbar_buffer); if(rtc_check()) { - //memcpy(&dst, localtime(time(NULL)), sizeof(struct tm)); - strcpy(tmp, text); - sprintf(&tmp[strlen(tmp)], "| %02d:%02d", clockdata.tm_hour, clockdata.tm_min); - text = tmp; + sprintf(&statusbar_postrtc[strlen(statusbar_postrtc)], "| %02d:%02d", clockdata.tm_hour, clockdata.tm_min); } - textbar_set_attribute(StatusBar, WATR_TEXT, text); + textbar_set_attribute(StatusBar, WATR_TEXT, statusbar_postrtc); } } void statusbar_refresh(void) { - if(oldtext) - statusbar_set(oldtext); + statusbar_set(NULL); } void pprintf(char *tmp, char *fmt) @@ -369,7 +371,7 @@ void update_list(void) listview_clear(MainList); if (!DialogBox) - listview_addline(MainList, NULL, TEXT(PLEASE_WAIT), ""); + listview_addline(MainList, NULL, NULL, TEXT(PLEASE_WAIT), ""); screen_redraw(MainScreen); filecount = filesys_getfiles(dirlist); if (!DialogBox) @@ -403,7 +405,7 @@ void update_list(void) *p = 0; } - listview_addline(MainList, filetype_icon(t), &dirname[i*32], &dirsize[i*10]); + listview_addline(MainList, filetype_textcolor(t), filetype_icon(t), &dirname[i*32], &dirsize[i*10]); } if (new_marked != -1) { @@ -411,12 +413,12 @@ void update_list(void) marked = new_marked; new_marked = -1; } - if (marked == 0xFFFF && filecount) + if (marked == -1 && filecount) marked = 0; - if (marked != 0xFFFF && filecount) { + if (marked != -1 && filecount) { listview_set_marked(MainList, marked); - if (listview_get_marked(MainList) == 0xFFFF) + if (listview_get_marked(MainList) == -1) listview_set_marked(MainList, 0); } @@ -446,7 +448,8 @@ void setup_screen(void) FILE *fp; Widget *dbox; Widget *mbox; - Window *win; + Window *win; + Scrollbar *sb; //BitMap *screen = bitmap_getscreen(); //bitmap_clear(screen, 0xFF00); @@ -516,6 +519,14 @@ void setup_screen(void) MessageBox->list = MessageList; } + if (MainList->scrollbar) { + sb = MainList->scrollbar; + if (sb->troughtopbutton && sb->troughtopbutton->bitmap) + sb->troughtopbutton->bitmap->format |= TRANSPARENT; + if (sb->troughbottombutton && sb->troughbottombutton->bitmap) + sb->troughbottombutton->bitmap->format |= TRANSPARENT; + } + if (IconSet) { count = IconSet->height / IconHeight; @@ -530,7 +541,7 @@ void setup_screen(void) icon_list = NULL; filetype_set_iconset(icon_list); - filetype_readtypes(config_fp); + filetype_set_icons(); font = font_load_path("cnokia.font"); //font->flags |= FFLG_TRANSP; @@ -689,6 +700,14 @@ int main(int argc, char **argv) //uint32 *mem = (uint32 *)0x02000000; SoftReset(0xfc); //Reset sound, sio, and other registers + SETW(REG_BG0HOFS, 0x0); + SETW(REG_BG0VOFS, 0x0); + SETW(REG_BG1HOFS, 0x0); + SETW(REG_BG1VOFS, 0x0); + SETW(REG_BG2HOFS, 0x0); + SETW(REG_BG2VOFS, 0x0); + SETW(REG_BG3HOFS, 0x0); + SETW(REG_BG3VOFS, 0x0); dirlist = pmalloc(sizeof(DirList) * MAX_FILE_COUNT); dirsize = pmalloc(10 * MAX_FILE_COUNT); @@ -771,18 +790,11 @@ int main(int argc, char **argv) DIR *dir; struct dirent *de; struct stat sbuf; - char filename[128], *p; dir = opendir(GET_PATH(SCREENSAVERS)); if (dir) { - strcpy(filename, GET_PATH(SCREENSAVERS)); - p = &filename[strlen(filename)]; - *p = '/'; - p++; while ((de = readdir(dir))) { - strcpy(p, de->d_name); - stat(filename, &sbuf); - if (!(sbuf.st_mode & S_IFDIR)) + if (!(de->d_size & 0x80000000)) screensaver_count++; } closedir(dir); @@ -794,6 +806,8 @@ int main(int argc, char **argv) read_texts(config_fp); read_users(config_fp); + filetype_readtypes(config_fp); + settings_init(); //strcpy(theme_name, "default.theme"); @@ -865,7 +879,7 @@ int main(int argc, char **argv) if (sleep_time && sleepcount >= sleep_time) { if (settings_get(SF_SCREENSAVER) && screensaver_count) { DIR *dir; - struct dirent *de; + struct dirent *result; int i; DirList dl; char filename[128]; @@ -873,26 +887,23 @@ int main(int argc, char **argv) i = abs(rand()) % screensaver_count; dir = opendir(GET_PATH(SCREENSAVERS)); do { - de = readdir(dir); - if (!(de->d_size & 0x80000000)) + if (readdir_r(dir, &dl.entry, &result) || !result) { + i = -2; + break; + } + if (!(dl.entry.d_size & 0x80000000)) i--; - } while (i > 0); + } while (i >= 0); closedir(dir); - //strcpy(filename, "/rom/"); - strcpy(filename, GET_PATH(SCREENSAVERS)); - strcat(filename, de->d_name); - strcpy(dl.entry.d_name, de->d_name); - dl.entry.d_size = de->d_size; - dl.type = 0; - i = filetype_lookup(&dl); - if (filetype_handle(filename, i, 0) == 2) - update_list(); - /*filesys_cd_marked(GET_PATH(SCREENSAVERS)); - update_list(); - marked = 2; - i = filetype_lookup(&dirlist[marked]); - if (filetype_handle(filesys_fullname(marked), i, qualifiers) == 2) - update_list();*/ + if (i != -2) { + //strcpy(filename, "/rom/"); + strcpy(filename, GET_PATH(SCREENSAVERS)); + strcat(filename, dl.entry.d_name); + dl.type = 0; + i = filetype_lookup(&dl); + if (filetype_handle(filename, i, 0) == 2) + update_list(); + } } else { suspend(); getchar(); //dump char used for wakeup @@ -942,8 +953,12 @@ int main(int argc, char **argv) if(qualifiers == 1) listview_set_marked(MainList, 0); else - if(qualifiers == 2) + if(qualifiers == 2) { + h = listview_get_marked(MainList); listview_set_marked(MainList, marked - MainList->showing); + if (h == listview_get_marked(MainList)) + listview_set_marked(MainList, 0); + } else listview_set_marked(MainList, marked-1); break; @@ -953,40 +968,45 @@ int main(int argc, char **argv) if(qualifiers == 1) listview_set_marked(MainList, MainList->lines-1); else - if(qualifiers == 2) + if(qualifiers == 2) { + h = listview_get_marked(MainList); listview_set_marked(MainList, marked + MainList->showing); - else + if (h == listview_get_marked(MainList)) + listview_set_marked(MainList, MainList->lines-1); + } else listview_set_marked(MainList, marked+1); break; case RAWKEY_A: - if(filesys_getstate() == FSTATE_SRAM) { char *name = filesys_fullname(marked); - switch(qualifiers) + if(filesys_getstate() == FSTATE_SRAM) + { + switch(qualifiers) + { + case 0: + i = filetype_lookup(&dirlist[marked]); + if(filetype_handle(name, i, 0) == 2) + update_list(); + break; + case 2: + cmd_sramcopy(name); + break; + case 1: + cmd_srampaste(name); + break; + case 3: + cmd_sramdel(name); + break; + } + } + else { - case 0: i = filetype_lookup(&dirlist[marked]); - if(filetype_handle(filesys_fullname(marked), i, 0) == 2) + if (filetype_handle(name, i, qualifiers) == 2) update_list(); - break; - case 2: - cmd_sramcopy(name); - break; - case 1: - cmd_srampaste(name); - break; - case 3: - cmd_sramdel(name); - break; } } - else - { - i = filetype_lookup(&dirlist[marked]); - if (filetype_handle(filesys_fullname(marked), i, qualifiers) == 2) - update_list(); - } break; case RAWKEY_B: diff --git a/shell2/misc.c b/shell2/misc.c index e2756f2..4c64259 100644 --- a/shell2/misc.c +++ b/shell2/misc.c @@ -51,6 +51,25 @@ void reset_gba(void) ::: "r0", "r1", "r2", "r3"); } +int gethex(char *p) +{ + int l = 0; + + while((*p >= '0' && *p <= '9') || + (*p >= 'A' && *p <= 'F') || + (*p >= 'a' && *p <= 'f')) + { + if(*p <= '9') + l = (l << 4) | ((*p++) - '0'); + else if (*p <= 'F') + l = (l << 4) | ((*p++) - 'A' + 10); + else + l = (l << 4) | ((*p++) - 'a' + 10); + } + + return l; +} + char *strdup(char *str) { char *p = malloc(strlen(str)+1); diff --git a/shell2/misc.h b/shell2/misc.h index 6db00d8..ee08e2f 100644 --- a/shell2/misc.h +++ b/shell2/misc.h @@ -4,6 +4,7 @@ enum { LZ77 = 1, APACK = 2, RAW = 0 }; void reset_gba (void); +int gethex(char *p); char *basename(char *str); void *pmalloc(int size); int pmemory_free(void); diff --git a/shell2/misc.o b/shell2/misc.o index 61f3596..7dfacbf 100644 Binary files a/shell2/misc.o and b/shell2/misc.o differ diff --git a/shell2/msgbox.c b/shell2/msgbox.c index c16d602..57c3f7d 100644 --- a/shell2/msgbox.c +++ b/shell2/msgbox.c @@ -83,7 +83,7 @@ int msgbox_list(tbox *box, char *title, char **lines, int num) listview_clear(box->list); for(i=0; ilist, NULL, lines[i]); + listview_addline(box->list, NULL, NULL, lines[i]); listview_set_marked(box->list, marked); diff --git a/shell2/msgbox.o b/shell2/msgbox.o index b79242f..fb36904 100644 Binary files a/shell2/msgbox.o and b/shell2/msgbox.o differ diff --git a/shell2/pogo_visoly_xg1.elf b/shell2/pogo_visoly_xg1.elf index 7ae2ac1..418362d 100644 Binary files a/shell2/pogo_visoly_xg1.elf and b/shell2/pogo_visoly_xg1.elf differ diff --git a/shell2/pogo_visoly_xg1.gba b/shell2/pogo_visoly_xg1.gba index 92ab582..7c855d6 100644 Binary files a/shell2/pogo_visoly_xg1.gba and b/shell2/pogo_visoly_xg1.gba differ diff --git a/shell2/pogo_xrom.elf b/shell2/pogo_xrom.elf index b5134ee..62dfe17 100644 Binary files a/shell2/pogo_xrom.elf and b/shell2/pogo_xrom.elf differ diff --git a/shell2/pogo_xrom.gba b/shell2/pogo_xrom.gba index b97cce6..de5da48 100644 Binary files a/shell2/pogo_xrom.gba and b/shell2/pogo_xrom.gba differ diff --git a/shell2/savesystem.o b/shell2/savesystem.o index 9a939e8..a858c4a 100644 Binary files a/shell2/savesystem.o and b/shell2/savesystem.o differ diff --git a/shell2/settings.c b/shell2/settings.c index e4a59c7..ccaaf16 100644 --- a/shell2/settings.c +++ b/shell2/settings.c @@ -5,9 +5,13 @@ #include "widgets/listview.h" #include "text.h" #include "misc.h" +#include "filesys.h" +#include "filetype.h" #include "settings.h" +#define DEFAULTTHEME "default.theme" + extern ListView *MainList; extern Screen *MainScreen; @@ -50,7 +54,7 @@ int settings_write(void) return 0; } */ -static BitMap *icon; +static BitMap *icon = NULL; void update_line(int i) { @@ -72,7 +76,7 @@ void update_line(int i) p = temp_theme_name; } - listview_setline(MainList, i, icon, TEXT(SETTINGS_START + i), p); + listview_setline(MainList, i, NULL, icon, TEXT(SETTINGS_START + i), p); } void settings_icon(BitMap *bm) @@ -84,21 +88,18 @@ void settings_init(void) { int i; DIR *dir; - struct dirent *de; - struct stat sbuf; - char *tmp; + DirList dl; + struct dirent *result; - memcpy(settings, defsettings, NO_SETTINGS); + settings_default(); dir = opendir(GET_PATH(THEMES)); if (dir) { - for (i = 0; ((de = readdir(dir)) && (i < MAX_FILE_COUNT)); i++) + for (i = 0; ((i < MAX_FILE_COUNT) && !readdir_r(dir, &dl.entry, &result) && (result != NULL)); i++) { - tmp = strrchr(de->d_name, '.'); - stat(de->d_name, &sbuf); - if (!(sbuf.st_mode & S_IFDIR) && strcmp(tmp, ".theme") == 0) { - if (strcmp(de->d_name, "default.theme") != 0) + if (filetype_theme(&dl)) { + if (strcmp(dl.entry.d_name, DEFAULTTHEME) != 0) theme_count++; } } @@ -106,29 +107,31 @@ void settings_init(void) } } +void settings_default(void) +{ + memcpy(settings, defsettings, NO_SETTINGS); +} + int set_theme_setting(char *src) { int i; char count, current; DIR *dir; - struct dirent *de; - struct stat sbuf; - char *tmp; + DirList dl; + struct dirent *result; dir = opendir(GET_PATH(THEMES)); count = 1; if (dir) { - for (i = 0; (de = readdir(dir)) && (i < MAX_FILE_COUNT); i++) + for (i = 0; ((i < MAX_FILE_COUNT) && !readdir_r(dir, &dl.entry, &result) && (result != NULL)); i++) { - tmp = strrchr(de->d_name, '.'); - stat(de->d_name, &sbuf); - if (!(sbuf.st_mode & S_IFDIR) && strcmp(tmp, ".theme") == 0) { - if (strcmp(de->d_name, "default.theme") == 0) + if (filetype_theme(&dl)) { + if (strcmp(dl.entry.d_name, DEFAULTTHEME) == 0) current = 0; else current = count++; - if (!strcmp(de->d_name, src)) { + if (!strcmp(dl.entry.d_name, src)) { settings_set(SF_THEME, current); closedir(dir); return 0; @@ -137,6 +140,7 @@ int set_theme_setting(char *src) } closedir(dir); } + return 1; } @@ -145,25 +149,23 @@ void get_theme_name(char line, char *dest) int i; char count, current; DIR *dir; - struct dirent *de; - struct stat sbuf; - char *tmp; + DirList dl; + struct dirent *result; dir = opendir(GET_PATH(THEMES)); count = 1; if (dir) { - for (i = 0; (de = readdir(dir)) && (i < MAX_FILE_COUNT); i++) + for (i = 0; ((i < MAX_FILE_COUNT) && !readdir_r(dir, &dl.entry, &result) && (result != NULL)); i++) { - tmp = strrchr(de->d_name, '.'); - stat(de->d_name, &sbuf); - if (!(sbuf.st_mode & S_IFDIR) && strcmp(tmp, ".theme") == 0) { - if (strcmp(de->d_name, "default.theme") == 0) + if (filetype_theme(&dl)) { + if (strcmp(dl.entry.d_name, DEFAULTTHEME) == 0) current = 0; else current = count++; if (line == current) { - memcpy(dest, de->d_name, 32); + memcpy(dest, dl.entry.d_name, 32); + settings_set(SF_THEME, current); closedir(dir); return; } @@ -184,7 +186,7 @@ int settings_edit(void) for(i=0; ih; i++) + { + cp = lv->associatecolors[l]; + c = (cp) ? *cp : lv->textcolor[0]; + gdcol = TO_RGB16(c); + for (j = 0; j < lv->gradientwidth; j++) + *dst++ = gdcol; + dh += lv->lines; + while (dh >= r->h) { + l++; + dh -= r->h; + } + dst += (bm->width - lv->gradientwidth); + } +} + int listview_render(ListView *lv, Rect *org_r, BitMap *bm) { //const char col[3] = { 0xFF, 0x00, 0x00}; @@ -40,6 +66,7 @@ int listview_render(ListView *lv, Rect *org_r, BitMap *bm) int i, j, l, y, maxi; uint16 bdcol; int drawwidth; + Color c, *cp; int lineh = lv->lineh; int fonty = (lv->lineh - lv->font->height) / 2; @@ -96,21 +123,60 @@ int listview_render(ListView *lv, Rect *org_r, BitMap *bm) r->y += lv->marginy; + if (lv->columns == 2) { + if (lv->gradientwidth && + (lv->gradientalign == ALIGN_LEFT || lv->gradientalign == ALIGN_RIGHT)) + { + lv->colwidth[0] -= lv->gradientwidth/2; + lv->colwidth[1] -= (lv->gradientwidth - lv->gradientwidth/2); + dst = (uint16 *) bm->pixels + r->y * bm->width + r->x; + if (lv->gradientalign == ALIGN_LEFT) + r->x += lv->gradientwidth; + else + dst += r->w - lv->gradientwidth; + r->w -= lv->gradientwidth; + draw_gradient(lv, r, dst, bm); + } + } + if (lv->scrollbar) scrollbar_render(lv->scrollbar, r, bm); + if (lv->columns == 2) { + if (lv->scrollbar) { + lv->colwidth[0] += lv->scrollbar->addleft; + lv->colwidth[1] += lv->scrollbar->addright; + } + if (lv->gradientwidth && lv->gradientalign == ALIGN_CENTER) { + lv->colwidth[0] -= lv->gradientwidth/2; + lv->colwidth[1] -= (lv->gradientwidth - lv->gradientwidth/2); + dst = (uint16 *) bm->pixels + r->y * bm->width + r->x; + if (lv->scrollbar && !(lv->scrollbar->alignside)) + r->x += lv->gradientwidth; + else + dst += r->w - lv->gradientwidth; + r->w -= lv->gradientwidth; + draw_gradient(lv, r, dst, bm); + } + } + if(!lv->lines) { + if (lv->columns == 2) { + if (lv->gradientwidth) { + lv->colwidth[0] += lv->gradientwidth/2; + lv->colwidth[1] += (lv->gradientwidth - lv->gradientwidth/2); + } + if (lv->scrollbar) { + lv->colwidth[0] -= lv->scrollbar->addleft; + lv->colwidth[1] -= lv->scrollbar->addright; + } + } lv->dirty = 0; for (i = 0; i < MAPSLOTCOUNT; i++) lv->redrawmap[i] = 0; return 1; } - if (lv->scrollbar && lv->columns == 2) { - lv->colwidth[0] += lv->scrollbar->addleft; - lv->colwidth[1] += lv->scrollbar->addright; - } - dst = (uint16 *)bm->pixels + (r->x + lv->iconw + lv->marginx) + (r->y + fonty) * bm->width ; @@ -125,7 +191,7 @@ int listview_render(ListView *lv, Rect *org_r, BitMap *bm) r2.w = r->w; r2.h = lineh; - font_setcolor(TO_RGB16(lv->textcolor[0]), 0x0000); + //font_setcolor(TO_RGB16(lv->textcolor[0]), 0x0000); for(i=lv->start; idirty == 0xFF || lv->redrawmap[i>>5]&(1<<(i&31))) @@ -142,9 +208,9 @@ int listview_render(ListView *lv, Rect *org_r, BitMap *bm) d = dst; + cp = lv->associatecolors[i]; if(i == lv->marked) { - Color c; c = lv->textcolor[3]; if(c.a == 0xFF) bitmap_addbox(bm, &r2, TO_RGB16(c)); @@ -159,7 +225,11 @@ int listview_render(ListView *lv, Rect *org_r, BitMap *bm) bitmap_backbox(bm, &r2, TO_RGB16(c), c.a - 0x80); } else bitmap_fillbox(bm, &r2, TO_RGB16(c)); - font_setcolor(TO_RGB16(lv->textcolor[2]), TO_RGB16(lv->textcolor[3])); + c = (cp) ? *cp : lv->textcolor[2]; + font_setcolor(TO_RGB16(c), TO_RGB16(lv->textcolor[3])); + } else { + c = (cp) ? *cp : lv->textcolor[0]; + font_setcolor(TO_RGB16(c), 0x0000); } for(j=0; jcolumns; j++) { @@ -175,9 +245,7 @@ int listview_render(ListView *lv, Rect *org_r, BitMap *bm) } d += lv->colwidth[j]; } - if (i == lv->marked) { - font_setcolor(TO_RGB16(lv->textcolor[0]), 0x0000); - } + //font_setcolor(TO_RGB16(lv->textcolor[0]), 0x0000); if(lv->icons[i]) bitmap_blit(bm, r->x + lv->marginx, r->y + y, lv->icons[i], 0, 0, lv->icons[i]->width, lv->icons[i]->height); } @@ -185,9 +253,15 @@ int listview_render(ListView *lv, Rect *org_r, BitMap *bm) y += lineh; } - if (lv->scrollbar && lv->columns == 2) { - lv->colwidth[0] -= lv->scrollbar->addleft; - lv->colwidth[1] -= lv->scrollbar->addright; + if (lv->columns == 2) { + if (lv->gradientwidth) { + lv->colwidth[0] += lv->gradientwidth/2; + lv->colwidth[1] += (lv->gradientwidth - lv->gradientwidth/2); + } + if (lv->scrollbar) { + lv->colwidth[0] -= lv->scrollbar->addleft; + lv->colwidth[1] -= lv->scrollbar->addright; + } } lv->dirty = 0; @@ -217,7 +291,10 @@ void listview_set_attribute(ListView *lv, int attr, void *val) lv->w.flags |= WFLG_REDRAW; break; case WATR_COLWIDTH: - lv->colwidth[n] = (int)val; + if (n < 8) + lv->colwidth[n] = (int)val; + else + lv->gradientwidth = (int)val; lv->w.flags |= WFLG_REDRAW; break; case WATR_RGB: @@ -290,7 +367,10 @@ void listview_set_attribute(ListView *lv, int attr, void *val) lv->w.flags |= WFLG_REDRAW; break; case WATR_ALIGN: - lv->colalign[(attr&0xf)] = (int)val; + if (n < 8) + lv->colalign[n] = (int)val; + else + lv->gradientalign = (int)val; lv->w.flags |= WFLG_REDRAW; break; //case WATR_NAME: @@ -333,6 +413,7 @@ ListView *listview_new(int columns, int maxlines, Font *font) lv->iconw = 0; lv->icons = pmalloc(sizeof(BitMap *) * maxlines); + lv->associatecolors = pmalloc(sizeof(Color *) * maxlines); //memset(lv->icons, 0, sizeof(BitMap *) * maxlines); for(i=0; iscrollbar = backdrop_new(STYLE_BEVEL); //backdrop_set_border(lv->scrollbar, 1); + lv->gradientwidth = 2; + lv->gradientalign = ALIGN_RIGHT; + return lv; } @@ -421,12 +505,13 @@ void listview_set_marked(ListView *lv, int i) lv->marked = i; } -void listview_setline(ListView *lv, int index, BitMap *bm, ...) +void listview_setline(ListView *lv, int index, Color *cl, BitMap *bm, ...) { int i, w = 0; va_list vl; va_start(vl, bm); + lv->associatecolors[index] = cl; lv->icons[index] = bm; if(bm) @@ -465,13 +550,14 @@ void listview_setline(ListView *lv, int index, BitMap *bm, ...) va_end(vl); } -void listview_addline(ListView *lv, BitMap *bm, ...) +void listview_addline(ListView *lv, Color *cl, BitMap *bm, ...) { int i, w = 0; va_list vl; va_start(vl, bm); + lv->associatecolors[lv->lines] = cl; lv->icons[lv->lines] = bm; if(bm) diff --git a/shell2/widgets/listview.h b/shell2/widgets/listview.h index d03d2ef..52c9b10 100644 --- a/shell2/widgets/listview.h +++ b/shell2/widgets/listview.h @@ -33,7 +33,11 @@ typedef struct uint16 colwidth[8]; uint16 colalign[8]; + uint16 gradientwidth; + uint16 gradientalign; + BitMap **icons; + Color **associatecolors; char **texts[8]; @@ -46,8 +50,8 @@ typedef struct #define listview_get_marked(l) (l->marked) ListView *listview_new(int columns, int maxlines, Font *font); -void listview_addline(ListView *lv, BitMap *icon, ...); -void listview_setline(ListView *lv, int index, BitMap *bm, ...); +void listview_addline(ListView *lv, Color *c, BitMap *icon, ...); +void listview_setline(ListView *lv, int index, Color *c, BitMap *bm, ...); void listview_set_attribute(ListView *tb, int attr, void *val); void listview_set_marked(ListView *lv, int i); void listview_set_dirty(ListView *lv); diff --git a/shell2/widgets/listview.o b/shell2/widgets/listview.o index 2c72d69..4b113e8 100644 Binary files a/shell2/widgets/listview.o and b/shell2/widgets/listview.o differ diff --git a/shell2/widgets/scrollbar.c b/shell2/widgets/scrollbar.c index 28cadcf..c69be83 100644 --- a/shell2/widgets/scrollbar.c +++ b/shell2/widgets/scrollbar.c @@ -7,7 +7,8 @@ int scrollbar_render(Scrollbar *scr, Rect *r, BitMap *bm) { int dirty, draw_trough, draw_bar, space_for_trough, space_for_bar; - Rect sbar; + Rect sbar, buttonbox; + BackDrop *bd; dirty = draw_trough = draw_bar = space_for_trough = space_for_bar = 0; @@ -61,7 +62,7 @@ int scrollbar_render(Scrollbar *scr, Rect *r, BitMap *bm) if (scr->alignside) sbar.x = r->x + r->w - sbar.w; else - sbar.x = 0; + sbar.x = r->x; if (space_for_trough) { r->w -= sbar.w; @@ -127,6 +128,39 @@ int scrollbar_render(Scrollbar *scr, Rect *r, BitMap *bm) { Color c; + if (scr->troughtopbutton) { + bd = scr->troughtopbutton; + buttonbox.x = sbar.x; + buttonbox.y = sbar.y; + if (bd->bitmap) { + buttonbox.w = bd->bitmap->width; + buttonbox.w = (sbar.w < buttonbox.w) ? sbar.w : buttonbox.w; + buttonbox.h = bd->bitmap->height; + buttonbox.h = (sbar.h < buttonbox.h) ? sbar.h : buttonbox.h; + } else { + buttonbox.w = sbar.w; + buttonbox.h = sbar.w; + } + sbar.h -= buttonbox.h; + sbar.y += buttonbox.h; + backdrop_render(bd, &buttonbox, bm); + } + if (scr->troughbottombutton) { + bd = scr->troughbottombutton; + buttonbox.x = sbar.x; + if (bd->bitmap) { + buttonbox.w = bd->bitmap->width; + buttonbox.w = (sbar.w < buttonbox.w) ? sbar.w : buttonbox.w; + buttonbox.h = bd->bitmap->height; + buttonbox.h = (sbar.h < buttonbox.h) ? sbar.h : buttonbox.h; + } else { + buttonbox.w = sbar.w; + buttonbox.h = sbar.w; + } + sbar.h -= buttonbox.h; + buttonbox.y = sbar.y + sbar.h; + backdrop_render(bd, &buttonbox, bm); + } c = scr->troughcolor; if (scr->trough) backdrop_render(scr->trough, &sbar, bm); @@ -193,6 +227,8 @@ Scrollbar *scrollbar_new() p[0] = 0xff181818; sc->bar = NULL; sc->trough = NULL; + sc->troughtopbutton = NULL; + sc->troughbottombutton = NULL; return sc; @@ -239,14 +275,29 @@ void scrollbar_set_attribute(Scrollbar *sc, int attr, void *val) switch(attr & 0xFF0) { case WATR_BACKDROP: - if (n) { - if (sc->trough) - free(sc->trough); - sc->trough = (BackDrop *)val; - } else { - if (sc->bar) - free(sc->bar); - sc->bar = (BackDrop *)val; + switch (n) + { + case TROUGHTOPBUTTONBACKDROP: + if (sc->troughtopbutton) + free(sc->troughtopbutton); + sc->troughtopbutton = (BackDrop *)val; + break; + case TROUGHBOTTOMBUTTONBACKDROP: + if (sc->troughbottombutton) + free(sc->troughbottombutton); + sc->troughbottombutton = (BackDrop *)val; + break; + case TROUGHBACKDROP: + if (sc->trough) + free(sc->trough); + sc->trough = (BackDrop *)val; + break; + case BARBACKDROP: + default: + if (sc->bar) + free(sc->bar); + sc->bar = (BackDrop *)val; + break; } sc->w.flags |= WFLG_REDRAW; break; diff --git a/shell2/widgets/scrollbar.h b/shell2/widgets/scrollbar.h index a7ba74e..a642114 100644 --- a/shell2/widgets/scrollbar.h +++ b/shell2/widgets/scrollbar.h @@ -31,6 +31,8 @@ typedef struct uint16 style; BackDrop *bar; BackDrop *trough; + BackDrop *troughtopbutton; + BackDrop *troughbottombutton; uint16 marginl[2]; uint16 marginr[2]; uint16 marginu[2]; @@ -43,6 +45,9 @@ typedef struct } Scrollbar; +enum { BARBACKDROP = 0, TROUGHBACKDROP = 1, TROUGHTOPBUTTONBACKDROP = 2, TROUGHBOTTOMBUTTONBACKDROP = 3}; + +int scrollbar_render(Scrollbar *scr, Rect *r, BitMap *bm); Scrollbar *scrollbar_new(); void scrollbar_set_attribute(Scrollbar *sc, int attr, void *val); void scrollbar_set_start(Scrollbar *sc, int start); diff --git a/shell2/widgets/scrollbar.o b/shell2/widgets/scrollbar.o index 23e5bcc..f694df9 100644 Binary files a/shell2/widgets/scrollbar.o and b/shell2/widgets/scrollbar.o differ diff --git a/shell2/widgets/textreader.o b/shell2/widgets/textreader.o index 098a5d3..b87db7c 100644 Binary files a/shell2/widgets/textreader.o and b/shell2/widgets/textreader.o differ diff --git a/shell2/xrom_obj/filesys.o b/shell2/xrom_obj/filesys.o index dafea1a..1050ac7 100644 Binary files a/shell2/xrom_obj/filesys.o and b/shell2/xrom_obj/filesys.o differ diff --git a/shell2/xrom_obj/filetype.o b/shell2/xrom_obj/filetype.o index 9d8ce44..1fffd02 100644 Binary files a/shell2/xrom_obj/filetype.o and b/shell2/xrom_obj/filetype.o differ diff --git a/shell2/xrom_obj/main.o b/shell2/xrom_obj/main.o index de85e61..6235260 100644 Binary files a/shell2/xrom_obj/main.o and b/shell2/xrom_obj/main.o differ