From 7b98ebb48040f01d734d417d054ba5e4bc30e8cd Mon Sep 17 00:00:00 2001 From: david Date: Tue, 2 Jun 2009 10:42:16 +0200 Subject: [PATCH 1/4] o test compilew2q --- snes/fatfstest/Makefile | 4 ++-- snes/fatfstest/main.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/snes/fatfstest/Makefile b/snes/fatfstest/Makefile index 58b12c3..8d6e6aa 100644 --- a/snes/fatfstest/Makefile +++ b/snes/fatfstest/Makefile @@ -25,7 +25,7 @@ LD=$(WINE) $(SDK)/bin/WDCLN.exe INC=$(SDK)/include LIBS=$(SDK)/lib/cc -OBJS=StartupSnes.obj main.obj pad.obj PPU.obj debug.obj ressource.obj +OBJS=StartupSnes.obj pad.obj main.obj PPU.obj debug.obj ressource.obj APP=fatfs.smc GFX=debugfont @@ -66,4 +66,4 @@ $(APP): $(OBJS) ucon64 -snes -chk $(APP) clean: - rm -vf $(APP) *.obj + rm -vf $(APP) *.obj *.TMP diff --git a/snes/fatfstest/main.c b/snes/fatfstest/main.c index c9d22e9..007e0d4 100644 --- a/snes/fatfstest/main.c +++ b/snes/fatfstest/main.c @@ -39,10 +39,10 @@ void main(void) { *(byte*) 0x2100 = 0x0f; // enable background enableDebugScreen(); - printDebugScreen(line_header,0); - printf("Debugging console test\n"); - printf("test me\n"); + //printDebugScreen("FATFS TEST",0); printDebugScreen(line_header,1); + + while(1){ while(!pad1.start) { From a64e9ebd7df464dad6d43972ea727492f569a3a1 Mon Sep 17 00:00:00 2001 From: david Date: Tue, 2 Jun 2009 15:41:43 +0200 Subject: [PATCH 2/4] o get varg printf working --- snes/fatfstest/Makefile | 6 +--- snes/fatfstest/debug.c | 64 +++++++++++++++++++++++++++++------------ snes/fatfstest/debug.h | 6 ++-- snes/fatfstest/diskio.c | 2 +- snes/fatfstest/main.c | 9 +++--- 5 files changed, 55 insertions(+), 32 deletions(-) diff --git a/snes/fatfstest/Makefile b/snes/fatfstest/Makefile index 336d7c9..691f63d 100644 --- a/snes/fatfstest/Makefile +++ b/snes/fatfstest/Makefile @@ -7,7 +7,7 @@ ifeq ($(PLATFORM),Linux) # Linux Wine SDK=/home/david/.wine/drive_c/65xx_FreeSDK WINE=wine - EMU=zsnes + EMU=../../tools/bsnes/bsnes EMU_DEBUG=/home/david/Devel/arch/snes/tools/zsnes_linux_debug151/src/zsnesd -d else # Mac Wine @@ -25,11 +25,7 @@ LD=$(WINE) $(SDK)/bin/WDCLN.exe INC=$(SDK)/include LIBS=$(SDK)/lib/cc -<<<<<<< HEAD:snes/fatfstest/Makefile -OBJS=StartupSnes.obj pad.obj main.obj PPU.obj debug.obj ressource.obj -======= OBJS=StartupSnes.obj main.obj pad.obj PPU.obj debug.obj ressource.obj diskio.obj ff.obj ->>>>>>> d69d2bf39842c032ea4660a10556e78b14b6d71c:snes/fatfstest/Makefile APP=fatfs.smc GFX=debugfont diff --git a/snes/fatfstest/debug.c b/snes/fatfstest/debug.c index 96de0e0..87e2a7b 100644 --- a/snes/fatfstest/debug.c +++ b/snes/fatfstest/debug.c @@ -1,10 +1,15 @@ #include +#include +#include + #include "data.h" #include "pad.h" #include "PPU.h" #include "ressource.h" + word debugMap[0x400]; +char debug_buffer[255]; void debug_init(void) { @@ -14,23 +19,7 @@ void debug_init(void) { } } -char hex_chars[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; - -void int2hex(unsigned long number, char *buf,word size) -{ - unsigned long n; - unsigned char i; - //unsigned char x; - for (i = 0; i < size; i++) { - n = number >> 4; - //x = (number - (n << 4)); - buf[size-i-1] = hex_chars[(number - (n << 4))]; - number = n; - } - -} - -void print_screen(char *buffer,word y){ +void _print_screen(word y, char *buffer){ char i; char l; l = strlen(buffer); @@ -43,11 +32,28 @@ void print_screen(char *buffer,word y){ } } -void print_console(char *buffer){ +void _print_console(char *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(debug_buffer,fmt,ap); + va_end(ap); + _print_screen(y,debug_buffer); +} + + void debug_enable(void){ VRAMLoad((word) debugFont_pic, 0x5000, 2048); CGRAMLoad((word) debugFont_pal, (byte) 0x00, (word) 16); @@ -55,4 +61,24 @@ void debug_enable(void){ setTileMapLocation(0x4000, (byte) 0x00, (byte) 0); setCharacterLocation(0x5000, (byte) 0); *(byte*) 0x2100 = 0x0f; // enable background -} \ No newline at end of file +} + +int unlink(const char *name){ + printfc("unlink called"); +} + +int close(int fd){ + printfc("close called"); +} + +int isatty(int fd){ + printfc("isatty called"); +} + +int write(int fd,void * buffer, size_t len){ + printfc("write called"); +} + +long lseek(int fd,long offset, int whence){ + printfc("lseek called"); +} diff --git a/snes/fatfstest/debug.h b/snes/fatfstest/debug.h index 9c786db..b3fa25b 100644 --- a/snes/fatfstest/debug.h +++ b/snes/fatfstest/debug.h @@ -1,5 +1,5 @@ void debug_init(void); void debug_enable(void); -void int2hex(unsigned long i, char *buf,word size); -void print_screen(char* line,word y); -void print_console(char* line); +void printfs(word y,char* fmt,...); +void printfc(char* fmt,...); + diff --git a/snes/fatfstest/diskio.c b/snes/fatfstest/diskio.c index e0e189f..7552033 100644 --- a/snes/fatfstest/diskio.c +++ b/snes/fatfstest/diskio.c @@ -88,7 +88,7 @@ DRESULT disk_read ( *(byte*) MMIO_SECTOR01 = (sector >> 24) & 0xff; *(byte*) MMIO_SECTOR02 = (sector >> 16) & 0xff; *(byte*) MMIO_SECTOR03 = (sector >> 8) & 0xff; - *(byte*) MMIO_SECTOR04 = (sector >> 8) & 0xff; + *(byte*) MMIO_SECTOR04 = (sector) & 0xff; *(byte*) MMIO_COUNT = count; diff --git a/snes/fatfstest/main.c b/snes/fatfstest/main.c index 0d66614..ed35390 100644 --- a/snes/fatfstest/main.c +++ b/snes/fatfstest/main.c @@ -38,10 +38,11 @@ void main(void) { *(byte*) 0x2100 = 0x0f; // enable background debug_enable(); - print_screen("FATFS TEST",0); - print_console("Debugging console test\n"); - print_console("test me\n"); - + printfs(0,"FATFS TEST %i",10); + printfc("Test me\n"); + printfc("Test me %i\n",10); + + while(1){ while(!pad1.start) { waitForVBlank(); From 6b8902910592b9759bd0855e7b791d1e9c493d99 Mon Sep 17 00:00:00 2001 From: david Date: Tue, 2 Jun 2009 16:01:35 +0200 Subject: [PATCH 3/4] o add ff setup stuff --- snes/fatfstest/ff.h | 2 +- snes/fatfstest/main.c | 106 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 104 insertions(+), 4 deletions(-) diff --git a/snes/fatfstest/ff.h b/snes/fatfstest/ff.h index 3381a2f..57786c9 100644 --- a/snes/fatfstest/ff.h +++ b/snes/fatfstest/ff.h @@ -38,7 +38,7 @@ / performance and code efficiency. */ -#define _FS_READONLY 1 +#define _FS_READONLY 0 /* Setting _FS_READONLY to 1 defines read only configuration. This removes / writing functions, f_write, f_sync, f_unlink, f_mkdir, f_chmod, f_rename, / f_truncate and useless f_getfree. */ diff --git a/snes/fatfstest/main.c b/snes/fatfstest/main.c index ed35390..1984f4d 100644 --- a/snes/fatfstest/main.c +++ b/snes/fatfstest/main.c @@ -1,3 +1,4 @@ + #include "data.h"; #include "pad.h"; #include "event.h"; @@ -5,12 +6,34 @@ #include "ressource.h"; #include "PPU.h" #include "debug.h" +#include "integer.h" +#include "ff.h" +#include #include +#include padStatus pad1; +DWORD acc_size; /* Work register for fs command */ +WORD acc_files, acc_dirs; + +FILINFO finfo; +FATFS fatfs[2]; /* File system object for each logical drive */ +BYTE Buff[512]; /* Working buffer */ + +DWORD p1, p2, p3; +BYTE res; +WORD w1; +UINT s1, s2, cnt; + +FATFS *fs; +DIR dir; /* Directory object */ +FIL file1, file2; /* File object */ + + + void initInternalRegisters(void) { characterLocation[0] = 0x0000; characterLocation[1] = 0x0000; @@ -24,6 +47,61 @@ void preInit(void) { // Insert code here to be executed before register init } +DWORD get_fattime () +{ + time_t rawtime; + struct tm * ptm; + //time ( &rawtime ); + ptm = gmtime ( &rawtime ); + + return ((DWORD)(ptm->tm_year - 80) << 25) + | ((DWORD)(ptm->tm_mon +1) << 21) + | ((DWORD)ptm->tm_mday << 16) + | ((DWORD)ptm->tm_hour << 11) + | ((DWORD)ptm->tm_min << 5) + | ((DWORD)ptm->tm_sec >> 1); +} + + + +void put_rc (FRESULT rc){ + const char *p; + static const char str[] = + "OK\0" "NOT_READY\0" "NO_FILE\0" "FR_NO_PATH\0" "INVALID_NAME\0" "INVALID_DRIVE\0" + "DENIED\0" "EXIST\0" "RW_ERROR\0" "WRITE_PROTECTED\0" "NOT_ENABLED\0" + "NO_FILESYSTEM\0" "INVALID_OBJECT\0" "MKFS_ABORTED\0"; + FRESULT i; + + for (p = str, i = 0; i != rc && *p; i++) { + while(*p++); + } + printfc("rc=%u FR_%s\n", (WORD)rc, p); +} + + +FRESULT scan_files (char* path){ + DIR dirs; + FRESULT res; + int i; + + if ((res = f_opendir(&dirs, path)) == FR_OK) { + i = strlen(path); + while (((res = f_readdir(&dirs, &finfo)) == FR_OK) && finfo.fname[0]) { + if (finfo.fattrib & AM_DIR) { + acc_dirs++; + *(path+i) = '/'; strcpy(path+i+1, &finfo.fname[0]); + res = scan_files(path); + *(path+i) = '\0'; + if (res != FR_OK) break; + } else { + acc_files++; + acc_size += finfo.fsize; + } + } + } + return res; +} + void main(void) { word i,j; word crc01; @@ -38,9 +116,31 @@ void main(void) { *(byte*) 0x2100 = 0x0f; // enable background debug_enable(); - printfs(0,"FATFS TEST %i",10); - printfc("Test me\n"); - printfc("Test me %i\n",10); + printfs(0,"FATFS "); + + printfc("Try to init disk\n"); + put_rc(f_mount(0, &fatfs[p1])); + + res = f_getfree("/", &p2, &fs); + if (res) + put_rc(res); + + printfc("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 (lba) = %lu\nDIR start (lba,clustor) = %lu\nData start (lba) = %lu\n", + (WORD)fs->fs_type, (DWORD)fs->csize * 512, (WORD)fs->n_fats, + fs->n_rootdir, (DWORD)fs->sects_fat, (DWORD)fs->max_clust - 2, + fs->fatbase, fs->dirbase, fs->database + ); + acc_size = acc_files = acc_dirs = 0; + res = scan_files("/"); + if (res) + put_rc(res); + printfc("%u files, %lu bytes.\n%u folders.\n" + "%lu KB total disk space.\n%lu KB available.\n", + acc_files, acc_size, acc_dirs, + (fs->max_clust - 2) * (fs->csize / 2), p2 * (fs->csize / 2) + ); while(1){ From 4ec2da3a5c413238f3e549b608fbf37ff8940642 Mon Sep 17 00:00:00 2001 From: david Date: Tue, 2 Jun 2009 16:08:45 +0200 Subject: [PATCH 4/4] o add support for multline screen printfs --- snes/fatfstest/debug.c | 4 ++++ snes/fatfstest/main.c | 9 +++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/snes/fatfstest/debug.c b/snes/fatfstest/debug.c index 87e2a7b..7a442da 100644 --- a/snes/fatfstest/debug.c +++ b/snes/fatfstest/debug.c @@ -25,6 +25,10 @@ void _print_screen(word y, char *buffer){ l = strlen(buffer); waitForVBlank(); for(i=0; i<32; i++) { + if (buffer[i] == '\n' ) { + y++; + continue; + } if (ifs_type, (DWORD)fs->csize * 512, (WORD)fs->n_fats, fs->n_rootdir, (DWORD)fs->sects_fat, (DWORD)fs->max_clust - 2, - fs->fatbase, fs->dirbase, fs->database - ); + fs->fatbase, fs->dirbase, fs->database); acc_size = acc_files = acc_dirs = 0; res = scan_files("/"); if (res) @@ -139,9 +138,7 @@ void main(void) { printfc("%u files, %lu bytes.\n%u folders.\n" "%lu KB total disk space.\n%lu KB available.\n", acc_files, acc_size, acc_dirs, - (fs->max_clust - 2) * (fs->csize / 2), p2 * (fs->csize / 2) - ); - + (fs->max_clust - 2) * (fs->csize / 2), p2 * (fs->csize / 2)); while(1){ while(!pad1.start) {