From 0a50554f4a7e212960885ee3d7597bd4b8740f2b Mon Sep 17 00:00:00 2001 From: david Date: Wed, 3 Jun 2009 18:24:18 +0200 Subject: [PATCH] o cleanup code o get ls working --- snes/fatfstest/debug.c | 87 +++++++++++++++++-------- snes/fatfstest/debug.h | 1 + snes/fatfstest/main.c | 46 +++++++++---- snes/fatfstest/pad.c | 6 ++ snes/fatfstest/pad.h | 1 + snes/fatfstest/ressource/debugFont.clr | Bin 2 -> 512 bytes tools/ffsample/linux/Makefile | 4 +- 7 files changed, 105 insertions(+), 40 deletions(-) diff --git a/snes/fatfstest/debug.c b/snes/fatfstest/debug.c index 762f776..2c18a1e 100644 --- a/snes/fatfstest/debug.c +++ b/snes/fatfstest/debug.c @@ -2,6 +2,7 @@ #include #include +#include "debug.h" #include "data.h" #include "pad.h" #include "PPU.h" @@ -10,7 +11,27 @@ word debugMap[0x400]; static char debug_buffer[255]; +static char screen_buffer[255]; +word col[] = { + 0x03ff, + 0x03ff, + 0x03ff, + 0x03ff, + 0x03ff, + 0x03ff, + 0x03ff, + 0x03ff, + 0x03ff, + 0x03ff, + 0x03ff, + 0x03ff, + 0x03ff, + 0x03ff, + 0x03ff, + 0x03ff, + +}; void debug_init(void) { word i; @@ -31,7 +52,16 @@ void debug_enable(void){ } -void _print_char(word y,word x, unsigned char c){ +void clears(void) { + word x,y; + for(y=0; y<16; y++) + for(x=0; x<32; x++) + VRAMByteWrite((byte) (' '-32), (word) (0x4000+x+(y*0x20))); +} + + +void _print_char(word y,word x, char c){ + waitForVBlank(); VRAMByteWrite((byte) (c-32), (word) (0x4000+x+(y*0x20))); } @@ -41,23 +71,42 @@ void _print_screen(word y, char *buffer){ l = strlen(buffer); waitForVBlank(); while(*buffer){ + if (*buffer == '\n' ) { - while(x++<32) - _print_char(y,x,' '); - x = 0; - y++; - } - _print_char(y,x,*buffer); - x++; - buffer++; + while(x++<32) + _print_char(y,x,' '); + x = 0; + y++; + buffer++; + continue; + } + _print_char(y,x,*buffer); + x++; + buffer++; } } - void _print_console(const char *buffer){ - while(*buffer) - *(byte*) 0x3000=*buffer++; + while(*buffer) + *(byte*) 0x3000=*buffer++; } +void printfc(char *fmt,...){ + va_list ap; + va_start(ap,fmt); + vsprintf(debug_buffer,fmt,ap); + va_end(ap); + _print_console(debug_buffer); +} + +void printfs(word y,char *fmt,...){ + va_list ap; + va_start(ap,fmt); + vsprintf(screen_buffer,fmt,ap); + va_end(ap); + _print_screen(y,screen_buffer); +} + + /* keep the linker happy */ int open(const char * _name, int _mode){ _print_console("open called\n"); @@ -94,18 +143,4 @@ int isatty(){ _print_console("isatty called\n"); return 1; } -void printfc(char *fmt,...){ - va_list ap; - va_start(ap,fmt); - vsprintf(debug_buffer,fmt,ap); - va_end(ap); - _print_console(debug_buffer); -} -void printfs(word y,char *fmt,...){ - va_list ap; - va_start(ap,fmt); - vsprintf(debug_buffer,fmt,ap); - va_end(ap); - _print_screen(y,debug_buffer); -} diff --git a/snes/fatfstest/debug.h b/snes/fatfstest/debug.h index 07daa0e..c9ed2a1 100644 --- a/snes/fatfstest/debug.h +++ b/snes/fatfstest/debug.h @@ -4,4 +4,5 @@ void debug_init(void); void debug_enable(void); void printfs(word y,char* fmt,...); void printfc(char* fmt,...); +void clears(void); diff --git a/snes/fatfstest/main.c b/snes/fatfstest/main.c index fa9d422..da0c4b4 100644 --- a/snes/fatfstest/main.c +++ b/snes/fatfstest/main.c @@ -108,22 +108,34 @@ FRESULT scan_files (char* path){ return res; } +void wait(){ + printfc("SNES::wait: press A to continue\n"); + enablePad(); + pad1 = readPad((byte) 0); + while(!pad1.A) { + pad1 = readPad((byte) 0); + } + printfc("SNES::wait: done\n"); + disablePad(); +} + + void main(void) { word i,j; BYTE res; initInternalRegisters(); + *(byte*) 0x2105 = 0x01; // MODE 1 value *(byte*) 0x212c = 0x01; // Plane 0 (bit one) enable register *(byte*) 0x212d = 0x00; // All subPlane disable *(byte*) 0x2100 = 0x0f; // enable background debug_enable(); + printfs(0,"FATFS "); - printfs(2,"FATFS "); - printfs(3,"FATFS "); - printfs(4,"FATFS "); - halt(); + //wait(); printfc("SNES::main: Try to init disk\n"); + put_rc(f_mount(0, &fatfs[0])); @@ -133,7 +145,7 @@ void main(void) { put_rc(res); printfc("SNES::main: printf fs results\n"); - printfc("FAT TYPE = %u\nBYTES/CLUSTER = %lu\nNUMBER OF FATS = %u\n" + printfs(1,"FAT TYPE = %u\nBYTES/CLUSTER = %lu\nNUMBER OF FATS = %u\n" "ROOT DIR ENTRIES = %u\nSECTORS/FAT = %lu\nNUMBER OF CLUSTERS = %lu\n" "FAT START = %lu\nDIR START LBA,CLUSTER = %lu\nDATA START LBA = %lu\n", (WORD)fs->fs_type, (DWORD)fs->csize * 512, (WORD)fs->n_fats, @@ -146,7 +158,7 @@ void main(void) { if (res) put_rc(res); - printfc("%u FILES, %lu BYTES\n%u FOLDERS\n" + printfs(12,"%u FILES, %lu BYTES\n%u FOLDERS\n" "%lu KB TOTAK DISK SPACE\n%lu KB AVAILABLE\n", acc_files, acc_size, acc_dirs, (fs->max_clust - 2) * (fs->csize / 2), p2 * (fs->csize / 2)); @@ -156,6 +168,9 @@ void main(void) { put_rc(res); p1 = s1 = s2 = 0; + cnt = 0; + wait(); + clears(); printfc("SNES::main: read dir\n"); for(;;) { res = f_readdir(&dir, &finfo); @@ -165,7 +180,9 @@ void main(void) { } else { s1++; p1 += finfo.fsize; } - printfc("%c%c%c%c%c %u/%02u/%02u %02u:%02u %9lu %s\n", + ; + + printfs(cnt,"%c%c%c%c%c %u/%02u/%02u %02u:%02u %9lu\n%s\n", (finfo.fattrib & AM_DIR) ? 'D' : '-', (finfo.fattrib & AM_RDO) ? 'R' : '-', (finfo.fattrib & AM_HID) ? 'H' : '-', @@ -174,16 +191,21 @@ void main(void) { (finfo.fdate >> 9) + 1980, (finfo.fdate >> 5) & 15, finfo.fdate & 31, (finfo.ftime >> 11), (finfo.ftime >> 5) & 63, finfo.fsize, &(finfo.fname[0])); + cnt+=2; + /* + printfs(cnt,"%u/%02u/%02u %02u:%02u %9lu\n%s\n", + (finfo.fdate >> 9) + 1980, (finfo.fdate >> 5) & 15, finfo.fdate & 31, + (finfo.ftime >> 11), (finfo.ftime >> 5) & 63, + finfo.fsize, &(finfo.fname[0])); + */ } + /* printfc("%4u FILES, %10lu BYTES TOTAL\n%4u DIRS", s1, p1, s2); if (f_getfree("", &p1, &fs) == FR_OK) printfc(", %10luK BYTES FREE\n", p1 * fs->csize / 2); - + */ while(1){ - while(!pad1.start) { - waitForVBlank(); - pad1 = readPad((byte) 0); - } + wait(); } while(1); } diff --git a/snes/fatfstest/pad.c b/snes/fatfstest/pad.c index 2b86eac..d764f62 100644 --- a/snes/fatfstest/pad.c +++ b/snes/fatfstest/pad.c @@ -1,11 +1,17 @@ #include "data.h"; #include "pad.h"; +#include "debug.h"; void enablePad(void) { // Enable pad reading and NMI *(byte*)0x4200 = 0x81; } +void disablePad(void) { + // Enable pad reading and NMI + *(byte*)0x4200 = 0x00; +} + padStatus readPad(byte padNumber) { word test; padStatus *status; diff --git a/snes/fatfstest/pad.h b/snes/fatfstest/pad.h index e5a907f..595761f 100644 --- a/snes/fatfstest/pad.h +++ b/snes/fatfstest/pad.h @@ -16,4 +16,5 @@ typedef struct padStatus{ } padStatus; extern void enablePad(void); +extern void disablePad(void); extern padStatus readPad(byte padNumber); diff --git a/snes/fatfstest/ressource/debugFont.clr b/snes/fatfstest/ressource/debugFont.clr index 09f370e38f498a462e1ca0faa724559b6630c04f..aad44283e99541114e6541c0de05a3287372b22e 100644 GIT binary patch literal 512 ncmZQzkY|u!nqIUuYJZe`banBJ`uh0)%zx_t*E5WQ5fB0Z+_wtD literal 2 JcmZQz0000200961 diff --git a/tools/ffsample/linux/Makefile b/tools/ffsample/linux/Makefile index 2da98e4..ffcb009 100644 --- a/tools/ffsample/linux/Makefile +++ b/tools/ffsample/linux/Makefile @@ -44,9 +44,9 @@ image_not_parted: image: rm -fv disk00.vfat - mkfs.vfat -I -F 16 -v -C disk00.vfat 4000 + mkfs.vfat -I -F 16 -v -C disk00.vfat 32000 sudo mount -o loop disk00.vfat disk - sudo cp -v /var/log/*.log disk/ + sudo cp -v ../../../roms/*smc disk/ sudo umount disk mount: