From 3ecc61adf4ed2377ae876222363005023f3268d3 Mon Sep 17 00:00:00 2001 From: david Date: Wed, 3 Jun 2009 17:06:02 +0200 Subject: [PATCH] o cleanup debug --- snes/fatfstest/config.h | 5 ++++- snes/fatfstest/debug.c | 27 +++++++++++----------- snes/fatfstest/diskio.c | 23 ++++++++++++++++++- snes/fatfstest/ff.c | 5 ----- snes/fatfstest/main.c | 37 +++++++++++++++++++++++++++---- tools/bsnes/chip/fatfs/config.h | 5 ++++- tools/bsnes/chip/fatfs/diskio.cpp | 16 ++++++++++++- tools/bsnes/chip/fatfs/fatfs.cpp | 24 ++++++++++++++++++++ 8 files changed, 116 insertions(+), 26 deletions(-) diff --git a/snes/fatfstest/config.h b/snes/fatfstest/config.h index 435e9c3..6094016 100644 --- a/snes/fatfstest/config.h +++ b/snes/fatfstest/config.h @@ -15,4 +15,7 @@ #define SHARED_SIZE 512 -#define SHARED_ADDR 0x3f0000 \ No newline at end of file +#define SHARED_ADDR 0x3f0000 + + +#undef MMIO_DEBUG diff --git a/snes/fatfstest/debug.c b/snes/fatfstest/debug.c index b5be78d..762f776 100644 --- a/snes/fatfstest/debug.c +++ b/snes/fatfstest/debug.c @@ -31,23 +31,26 @@ void debug_enable(void){ } +void _print_char(word y,word x, unsigned char c){ + VRAMByteWrite((byte) (c-32), (word) (0x4000+x+(y*0x20))); +} void _print_screen(word y, char *buffer){ - char i; char l; + char x = 0; l = strlen(buffer); waitForVBlank(); - - for(i=0; i<32; i++) { - if (buffer[i] == '\n' ) { + while(*buffer){ + if (*buffer == '\n' ) { + while(x++<32) + _print_char(y,x,' '); + x = 0; y++; - continue; - } - if (i= _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); @@ -1388,13 +1386,11 @@ 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 */ @@ -1405,7 +1401,6 @@ 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/main.c b/snes/fatfstest/main.c index 5afce9f..fa9d422 100644 --- a/snes/fatfstest/main.c +++ b/snes/fatfstest/main.c @@ -119,8 +119,10 @@ void main(void) { debug_enable(); printfs(0,"FATFS "); - - //halt(); + printfs(2,"FATFS "); + printfs(3,"FATFS "); + printfs(4,"FATFS "); + halt(); printfc("SNES::main: Try to init disk\n"); put_rc(f_mount(0, &fatfs[0])); @@ -129,7 +131,6 @@ void main(void) { res = f_getfree("", &p2, &fs); if (res) put_rc(res); - //halt(); printfc("SNES::main: printf fs results\n"); printfc("FAT TYPE = %u\nBYTES/CLUSTER = %lu\nNUMBER OF FATS = %u\n" @@ -150,7 +151,35 @@ void main(void) { acc_files, acc_size, acc_dirs, (fs->max_clust - 2) * (fs->csize / 2), p2 * (fs->csize / 2)); - while(1){ + res = f_opendir(&dir, ""); + if (res) + put_rc(res); + + p1 = s1 = s2 = 0; + printfc("SNES::main: read dir\n"); + for(;;) { + res = f_readdir(&dir, &finfo); + if ((res != FR_OK) || !finfo.fname[0]) break; + if (finfo.fattrib & AM_DIR) { + s2++; + } else { + s1++; p1 += finfo.fsize; + } + printfc("%c%c%c%c%c %u/%02u/%02u %02u:%02u %9lu %s\n", + (finfo.fattrib & AM_DIR) ? 'D' : '-', + (finfo.fattrib & AM_RDO) ? 'R' : '-', + (finfo.fattrib & AM_HID) ? 'H' : '-', + (finfo.fattrib & AM_SYS) ? 'S' : '-', + (finfo.fattrib & AM_ARC) ? 'A' : '-', + (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); diff --git a/tools/bsnes/chip/fatfs/config.h b/tools/bsnes/chip/fatfs/config.h index 435e9c3..77ac0d0 100644 --- a/tools/bsnes/chip/fatfs/config.h +++ b/tools/bsnes/chip/fatfs/config.h @@ -15,4 +15,7 @@ #define SHARED_SIZE 512 -#define SHARED_ADDR 0x3f0000 \ No newline at end of file +#define SHARED_ADDR 0x3f0000 + +#undef MMIO_DEBUG +#undef FATFS_DEBUG diff --git a/tools/bsnes/chip/fatfs/diskio.cpp b/tools/bsnes/chip/fatfs/diskio.cpp index 3f4966a..3387932 100644 --- a/tools/bsnes/chip/fatfs/diskio.cpp +++ b/tools/bsnes/chip/fatfs/diskio.cpp @@ -55,11 +55,13 @@ DSTATUS disk_initialize (BYTE drv) { lseek(fd,0,SEEK_SET); image_addr = (BYTE*)mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + #ifdef MMIO_DEBUG printf("DISKIO::disk_initialize: Open Image (size %i) %p\n",size,image_addr); + #endif if (image_addr == MAP_FAILED) { close(fd); perror("DISKIO::disk_initialize: Error mmapping the file"); - exit(EXIT_FAILURE); + exit(EXIT_FAILURE); } Stat &= ~STA_NOINIT; /* When device goes ready, clear STA_NOINIT */ @@ -94,9 +96,13 @@ DRESULT disk_read ( DWORD offset = sector * 512; int size = count * 512; + #ifdef MMIO_DEBUG printf("DISKIO::disk_read: sector=%li count=%i addr=%p off=%li size=%i\n",sector,count,image_addr + offset,offset,size); + #endif memcpy(buff,image_addr + offset,size); + #ifdef MMIO_DEBUG printf("DISKIO::disk_read: done\n"); + #endif return RES_OK; } @@ -118,7 +124,9 @@ DRESULT disk_write ( DWORD offset = sector * 512; int size = count * 512; + #ifdef MMIO_DEBUG printf("disk_write: sector=%li count=%i addr=%p off=%li size=%i\n",sector,count,image_addr + offset,offset,size); + #endif memcpy(image_addr + offset,buff,size); return RES_OK; } @@ -143,17 +151,23 @@ DRESULT disk_ioctl ( switch (ctrl) { case GET_SECTOR_COUNT : /* Get number of sectors on the disk (DWORD) */ + #ifdef MMIO_DEBUG printf("disk_ioctl: GET_SECTOR_COUNT\n"); + #endif ofs = 60; w = 2; n = 0; break; case GET_SECTOR_SIZE : /* Get sectors on the disk (WORD) */ + #ifdef MMIO_DEBUG printf("disk_ioctl: GET_SECTOR_SIZE\n"); + #endif *(WORD*)buff = 512; return RES_OK; case GET_BLOCK_SIZE : /* Get erase block size in sectors (DWORD) */ + #ifdef MMIO_DEBUG printf("disk_ioctl: GET_BLOCK_SIZE\n"); + #endif *(DWORD*)buff = 32; return RES_OK; diff --git a/tools/bsnes/chip/fatfs/fatfs.cpp b/tools/bsnes/chip/fatfs/fatfs.cpp index 2be7088..3edde01 100644 --- a/tools/bsnes/chip/fatfs/fatfs.cpp +++ b/tools/bsnes/chip/fatfs/fatfs.cpp @@ -47,16 +47,22 @@ void FATFS::fetchMem() { void FATFS::pushMem() { for ( int i=0;i= MMIO_SECTOR01 && addr <= MMIO_SECTOR04){ sector = data << ( (3 - ( addr - MMIO_SECTOR01)) << 3); + #ifdef FATFS_DEBUG printf("FATFS::mmio_write set sector: byte=%i val=%i sector=%i \n",(3 - ( addr - MMIO_SECTOR01)),data,sector); + #endif } if (addr == MMIO_COUNT){ count = data; + #ifdef FATFS_DEBUG printf("FATFS::mmio_write set count: count=%i \n",count); + #endif if (command == CMD_READ) { retval = disk_read (0, (BYTE*)scratch_buffer, sector, count); if (!retval) @@ -102,11 +122,15 @@ void FATFS::mmio_write(unsigned addr, uint8 data) { fetchMem(); retval = disk_write (0, (BYTE*)scratch_buffer, sector, count); } else{ + #ifdef FATFS_DEBUG printf("FATFS::mmio_write set offset: no command to trigger \n"); + #endif } } if (addr == MMIO_RETVAL){ + #ifdef FATFS_DEBUG printf("FATFS::mmio_write reg 0x3016 reset\n"); + #endif retval = STA_VOID; } }