diff --git a/snes/fatfstest/data.h b/snes/fatfstest/data.h index 5152032..fbe7072 100644 --- a/snes/fatfstest/data.h +++ b/snes/fatfstest/data.h @@ -1,2 +1,8 @@ + +#ifndef _DATA + typedef unsigned char byte; typedef unsigned short word; + +#define _DATA +#endif diff --git a/snes/fatfstest/debug.h b/snes/fatfstest/debug.h index b3fa25b..07daa0e 100644 --- a/snes/fatfstest/debug.h +++ b/snes/fatfstest/debug.h @@ -1,3 +1,5 @@ +#include "data.h" + void debug_init(void); void debug_enable(void); void printfs(word y,char* fmt,...); diff --git a/snes/fatfstest/diskio.c b/snes/fatfstest/diskio.c index cf7b1c9..39ad894 100644 --- a/snes/fatfstest/diskio.c +++ b/snes/fatfstest/diskio.c @@ -5,8 +5,6 @@ #include "data.h" #include "debug.h" -volatile static -DSTATUS Stat = STA_NOINIT; /* Disk status */ /* Interface @@ -33,20 +31,24 @@ return 1 byte #include +// TODO: Figure out gobal vars ?!? + +DSTATUS Stat = 0 ; //STA_NOINIT; /* Disk status */ + + DSTATUS disk_initialize (BYTE drv) { byte retval; - printfc("disk_initialize\n"); + printfc("SNES::disk_initialize called drv=%i stat=%i\n",drv,Stat); if (drv) return STA_NOINIT; /* Supports only single drive */ - - Stat |= STA_NOINIT; + printfc("SNES::disk_initialize stat=%i\n",Stat); *(byte*) MMIO_RETVAL = STA_VOID; *(byte*) MMIO_CMD = CMD_INIT; - while(*(byte*) MMIO_RETVAL == STA_VOID); - retval = *(byte*) MMIO_RETVAL; + printfc("SNES::disk_initialize poll retval\n"); + while((retval = *(byte*) MMIO_RETVAL) == STA_VOID); Stat &= ~STA_NOINIT; /* When device goes ready, clear STA_NOINIT */ - printfc("disk_initialize done\n"); + printfc("SNES::disk_initialize done Stat=%i\n",Stat); return Stat; } @@ -77,11 +79,11 @@ DRESULT disk_read ( byte retval; word i; - printfc("disk_read enter\n"); - //if (drv || !count) return RES_PARERR; - printfc("drv ok\n"); + printfc("SNES::disk_read called sector=%li count=%i\n",sector,count); + if (drv || !count) return RES_PARERR; + printfc("SNES::disk_read drv ok\n"); if (Stat & STA_NOINIT) return RES_NOTRDY; - printfc("sta ok\n"); + printfc("SNES::disk_read sta ok\n"); *(byte*) MMIO_RETVAL = STA_VOID; *(byte*) MMIO_CMD = CMD_READ; @@ -92,14 +94,19 @@ DRESULT disk_read ( *(byte*) MMIO_SECTOR04 = (sector) & 0xff; *(byte*) MMIO_COUNT = count; - - while(*(byte*) MMIO_RETVAL == STA_VOID); - retval = *(byte*) MMIO_RETVAL; - - printfc("copy buffer\n"); - for (i=0;i<(count*512);i++) - *(byte*)(SHARED_ADDR+i) = buff[i]; + printfc("SNES::disk_read poll retval\n"); + while((retval = *(byte*) MMIO_RETVAL) == STA_VOID); + + + printfc("SNES::disk_read copy buffer to %06lx\n",SHARED_ADDR); + for (i=0;i<(count*512);i++){ + buff[i] = *(byte*)(SHARED_ADDR+i); + if ( i < 8) + printfc("0x%02x ",buff[i]); + + } + printfc("\n"); return retval; } diff --git a/snes/fatfstest/ff.c b/snes/fatfstest/ff.c index 5b38038..ef67980 100644 --- a/snes/fatfstest/ff.c +++ b/snes/fatfstest/ff.c @@ -66,6 +66,7 @@ #include "ff.h" /* FatFs configurations and declarations */ #include "diskio.h" /* Declarations of low level disk I/O functions */ +#include "debug.h" /* FatFs configurations and declarations */ /*-------------------------------------------------------------------------- @@ -1367,13 +1368,14 @@ FRESULT auto_mount ( /* FR_OK(0): successful, !=0: any error occured */ } else { vol = 0; /* No drive number is given, use drive number 0 as default */ } - + printfc("auto_mount drv %i\n",vol); /* Check if the logical drive number is valid or not */ if (vol >= _DRIVES) return FR_INVALID_DRIVE; /* Is the drive number valid? */ *rfs = fs = FatFs[vol]; /* Returen pointer to the corresponding file system object */ if (!fs) return FR_NOT_ENABLED; /* Is the file system object registered? */ ENTER_FF(fs); /* Lock file system */ + printfc("auto_mount ok enter_ff\n"); if (fs->fs_type) { /* If the logical drive has been mounted */ stat = disk_status(fs->drive); @@ -1386,11 +1388,13 @@ FRESULT auto_mount ( /* FR_OK(0): successful, !=0: any error occured */ } } + printfc("auto_mount mount now\n"); /* The logical drive must be re-mounted. Following code attempts to mount the volume */ fs->fs_type = 0; /* Clear the file system object */ fs->drive = LD2PD(vol); /* Bind the logical drive and a physical drive */ stat = disk_initialize(fs->drive); /* Initialize low level disk I/O layer */ + printfc("auto_mount disk_initialize return %i\n",stat); if (stat & STA_NOINIT) /* Check if the drive is ready */ return FR_NOT_READY; #if _MAX_SS != 512 /* Get disk sector size if needed */ @@ -1401,6 +1405,7 @@ FRESULT auto_mount ( /* FR_OK(0): successful, !=0: any error occured */ if (chk_wp && (stat & STA_PROTECT)) /* Check write protection if needed */ return FR_WRITE_PROTECTED; #endif + printfc("auto_mount search fat now\n"); /* Search FAT partition on the drive */ fmt = check_fs(fs, bsect = 0); /* Check sector 0 as an SFD format */ if (fmt == 1) { /* Not an FAT boot record, it may be patitioned */ diff --git a/snes/fatfstest/integer.h b/snes/fatfstest/integer.h index 782aab3..266856d 100644 --- a/snes/fatfstest/integer.h +++ b/snes/fatfstest/integer.h @@ -26,16 +26,11 @@ typedef unsigned long ULONG; typedef unsigned long DWORD; /* Boolean type */ -typedef enum { FALSE = 0, TRUE } BOOL; +// enum { false = 0 , true } bool; -/* -#define FALSE 0 -#define TRUE 1 - -typedef int BOOL; -*/ - -#endif +typedef int BOOL; +#define FALSE 0 +#define TRUE 1 #define _INTEGER #endif diff --git a/snes/fatfstest/main.c b/snes/fatfstest/main.c index 0f1f5bf..5afce9f 100644 --- a/snes/fatfstest/main.c +++ b/snes/fatfstest/main.c @@ -1,3 +1,7 @@ + +//#include "integer.h" +#include "ff.h" + #include #include #include @@ -9,8 +13,7 @@ #include "ressource.h"; #include "PPU.h" #include "debug.h" -#include "integer.h" -#include "ff.h" + padStatus pad1; @@ -20,8 +23,8 @@ DWORD acc_size; /* Work register for fs command */ WORD acc_files, acc_dirs; FILINFO finfo; -FATFS fatfs[1]; /* File system object for each logical drive */ -BYTE Buff[512]; /* Working buffer */ +FATFS fatfs[2]; /* File system object for each logical drive */ +BYTE Buff[1024]; /* Working buffer */ DWORD p1, p2, p3; BYTE res; @@ -70,7 +73,7 @@ void halt(void) { 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" + "OK\0" "NOT_READY\0" "NO_FILE\0" "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; @@ -117,14 +120,19 @@ void main(void) { debug_enable(); printfs(0,"FATFS "); - printfc("Try to init disk\n"); + //halt(); + printfc("SNES::main: Try to init disk\n"); put_rc(f_mount(0, &fatfs[0])); - - res = f_getfree("/", &p2, &fs); + + + printfc("SNES::main: Try to get free\n"); + res = f_getfree("", &p2, &fs); if (res) put_rc(res); + //halt(); - printfs(0,"FAT TYPE = %u\nBYTES/CLUSTER = %lu\nNUMBER OF FATS = %u\n" + printfc("SNES::main: printf fs results\n"); + 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 = %lu\nDIR START LBA,CLUSTER = %lu\nDATA START LBA = %lu\n", (WORD)fs->fs_type, (DWORD)fs->csize * 512, (WORD)fs->n_fats, @@ -132,7 +140,8 @@ void main(void) { fs->fatbase, fs->dirbase, fs->database); acc_size = acc_files = acc_dirs = 0; - res = scan_files("/"); + printfc("SNES::main: scan files\n"); + res = scan_files(""); if (res) put_rc(res); diff --git a/tools/bsnes/chip/fatfs/diskio.cpp b/tools/bsnes/chip/fatfs/diskio.cpp index 80e0429..3f4966a 100644 --- a/tools/bsnes/chip/fatfs/diskio.cpp +++ b/tools/bsnes/chip/fatfs/diskio.cpp @@ -47,18 +47,18 @@ DSTATUS disk_initialize (BYTE drv) { int fd = open(IMAGE_NAME, O_RDWR); if (fd == -1) { - perror("Error opening file for writing"); + perror("DISKIO::disk_initialize: Error opening file for writing"); exit(EXIT_FAILURE); } int size = lseek(fd,0,SEEK_END); lseek(fd,0,SEEK_SET); - printf("Open Image (size %i)\n",size); image_addr = (BYTE*)mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + printf("DISKIO::disk_initialize: Open Image (size %i) %p\n",size,image_addr); if (image_addr == MAP_FAILED) { close(fd); - perror("Error mmapping the file"); + perror("DISKIO::disk_initialize: Error mmapping the file"); exit(EXIT_FAILURE); } @@ -94,8 +94,9 @@ DRESULT disk_read ( DWORD offset = sector * 512; int size = count * 512; - printf("disk_read: sector=%li count=%i addr=%p off=%li size=%i\n",sector,count,image_addr + offset,offset,size); + printf("DISKIO::disk_read: sector=%li count=%i addr=%p off=%li size=%i\n",sector,count,image_addr + offset,offset,size); memcpy(buff,image_addr + offset,size); + printf("DISKIO::disk_read: done\n"); return RES_OK; } diff --git a/tools/bsnes/chip/fatfs/fatfs.cpp b/tools/bsnes/chip/fatfs/fatfs.cpp index 553ab33..2be7088 100644 --- a/tools/bsnes/chip/fatfs/fatfs.cpp +++ b/tools/bsnes/chip/fatfs/fatfs.cpp @@ -13,7 +13,7 @@ void FATFS::init() { sector = 0; count = 0; retval = -1; - scratch_buffer = (char*)malloc(SHARED_SIZE); + scratch_buffer = (unsigned char*)malloc(SHARED_SIZE); } void FATFS::enable() { @@ -47,7 +47,10 @@ void FATFS::fetchMem() { void FATFS::pushMem() { for ( int i=0;i