From 2f2d306783085fe6695dad86fba9d535469f5390 Mon Sep 17 00:00:00 2001 From: Yourtion Date: Fri, 29 Apr 2016 12:19:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9FAT=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 19_day/bootpack.c | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/19_day/bootpack.c b/19_day/bootpack.c index ee8b293..ac6f823 100644 --- a/19_day/bootpack.c +++ b/19_day/bootpack.c @@ -17,6 +17,8 @@ void make_textbox8(struct SHEET *sht, int x0, int y0, int sx, int sy, int c); void make_wtitle8(unsigned char *buf, int xsize, char *title, char act); void console_task(struct SHEET *sheet, unsigned int memtotal); int cons_newline(int cursor_y, struct SHEET *sheet); +void file_readfat(int *fat, unsigned char *img); +void file_loadfile(int clustno, int size, char *buf, int *fat, char *img); #define KEYCMD_LED 0xed @@ -388,11 +390,13 @@ void console_task(struct SHEET *sheet, unsigned int memtotal) struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; int x, y; struct FILEINFO *finfo = (struct FILEINFO *) (ADR_DISKIMG + 0x002600); + int *fat = (int *) memman_alloc_4k(memman, 4 * 2880); fifo32_init(&task->fifo, 128, fifobuf, task); timer = timer_alloc(); timer_init(timer, &task->fifo, 1); timer_settime(timer, 50); + file_readfat(fat, (unsigned char *) (ADR_DISKIMG + 0x000200)); /*显示提示符*/ putfonts8_asc_sht(sheet, 8, 28, COL8_FFFFFF, COL8_000000, ">", 1); @@ -518,11 +522,12 @@ void console_task(struct SHEET *sheet, unsigned int memtotal) if (x < 224 && finfo[x].name[0] != 0x00) { /*找到文件的情况*/ y = finfo[x].size; - p = (char *) (finfo[x].clustno * 512 + 0x003e00 + ADR_DISKIMG); + p = (char *) memman_alloc_4k(memman, finfo[x].size); + file_loadfile(finfo[x].clustno, finfo[x].size, p, fat, (char *) (ADR_DISKIMG + 0x003e00)); cursor_x = 8; - for (x = 0; x < y; x++) { + for (y = 0; y < finfo[x].size; y++) { /*逐字输出*/ - s[0] = p[x]; + s[0] = p[y]; s[1] = 0; if (s[0] == 0x09) { /*制表符*/ for (;;) { @@ -550,6 +555,7 @@ void console_task(struct SHEET *sheet, unsigned int memtotal) } } } + memman_free_4k(memman, (int) p, finfo[x].size); } else { /*没有找到文件的情况*/ putfonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, "File not found.", 15); @@ -607,3 +613,35 @@ int cons_newline(int cursor_y, struct SHEET *sheet) } return cursor_y; } + +void file_readfat(int *fat, unsigned char *img) +/*将磁盘映像中的FAT解压缩 */ +{ + int i, j = 0; + for (i = 0; i < 2880; i += 2) { + fat[i + 0] = (img[j + 0] | img[j + 1] << 8) & 0xfff; + fat[i + 1] = (img[j + 1] >> 4 | img[j + 2] << 4) & 0xfff; + j += 3; + } + return; +} + +void file_loadfile(int clustno, int size, char *buf, int *fat, char *img) +{ + int i; + for (;;) { + if (size <= 512) { + for (i = 0; i < size; i++) { + buf[i] = img[clustno * 512 + i]; + } + break; + } + for (i = 0; i < 512; i++) { + buf[i] = img[clustno * 512 + i]; + } + size -= 512; + buf += 512; + clustno = fat[clustno]; + } + return; +}