소스 검색

o cleanup debug

david 15 년 전
부모
커밋
3ecc61adf4
8개의 변경된 파일116개의 추가작업 그리고 26개의 파일을 삭제
  1. 4 1
      snes/fatfstest/config.h
  2. 14 13
      snes/fatfstest/debug.c
  3. 22 1
      snes/fatfstest/diskio.c
  4. 0 5
      snes/fatfstest/ff.c
  5. 33 4
      snes/fatfstest/main.c
  6. 4 1
      tools/bsnes/chip/fatfs/config.h
  7. 15 1
      tools/bsnes/chip/fatfs/diskio.cpp
  8. 24 0
      tools/bsnes/chip/fatfs/fatfs.cpp

+ 4 - 1
snes/fatfstest/config.h

@@ -15,4 +15,7 @@
 
 
 #define SHARED_SIZE     512
-#define SHARED_ADDR     0x3f0000
+#define SHARED_ADDR     0x3f0000
+
+
+#undef MMIO_DEBUG

+ 14 - 13
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<l)
-		    VRAMByteWrite((byte) (buffer[i]-32), (word) (0x4000+i+(y*0x20)));
-	    else
-	        VRAMByteWrite((byte) (' '-32), (word) (0x4000+i+(y*0x20)));
-	}
+      }
+      _print_char(y,x,*buffer);
+      x++;
+      buffer++;
+    }
 }
 
 void _print_console(const char *buffer){
@@ -55,8 +58,6 @@ void _print_console(const char *buffer){
 	    *(byte*) 0x3000=*buffer++;
 }
 
-
-
 /* keep the linker happy */
 int open(const char * _name, int _mode){
     _print_console("open called\n");

+ 22 - 1
snes/fatfstest/diskio.c

@@ -39,16 +39,24 @@ DSTATUS Stat = 0 ; //STA_NOINIT;  /* Disk status */
 DSTATUS disk_initialize (BYTE drv) {
     
     byte retval;
+    #ifdef MMIO_DEBUG
     printfc("SNES::disk_initialize called drv=%i stat=%i\n",drv,Stat);
+    #endif
     if (drv) return STA_NOINIT;             /* Supports only single drive */
     Stat |= STA_NOINIT;
+    #ifdef MMIO_DEBUG
     printfc("SNES::disk_initialize stat=%i\n",Stat);
+    #endif
     *(byte*) MMIO_RETVAL = STA_VOID;
     *(byte*) MMIO_CMD = CMD_INIT;    
+    #ifdef MMIO_DEBUG
     printfc("SNES::disk_initialize poll retval\n");
+    #endif
     while((retval = *(byte*) MMIO_RETVAL) == STA_VOID);
     Stat &= ~STA_NOINIT;                    /* When device goes ready, clear STA_NOINIT */
+    #ifdef MMIO_DEBUG
     printfc("SNES::disk_initialize done Stat=%i\n",Stat);
+    #endif
     return Stat;
 }
 
@@ -79,11 +87,17 @@ DRESULT disk_read (
     byte retval;
     word i;
     
+    #ifdef MMIO_DEBUG
     printfc("SNES::disk_read called sector=%li count=%i\n",sector,count);
+    #endif
     if (drv || !count) return RES_PARERR;
+    #ifdef MMIO_DEBUG
     printfc("SNES::disk_read drv ok\n");
+    #endif
     if (Stat & STA_NOINIT) return RES_NOTRDY;
+    #ifdef MMIO_DEBUG
     printfc("SNES::disk_read sta ok\n");
+    #endif
 
     *(byte*) MMIO_RETVAL = STA_VOID;
     *(byte*) MMIO_CMD = CMD_READ;    
@@ -95,18 +109,25 @@ DRESULT disk_read (
     
     *(byte*) MMIO_COUNT = count;    
 
+    #ifdef MMIO_DEBUG
     printfc("SNES::disk_read poll retval\n");
+    #endif
     while((retval = *(byte*) MMIO_RETVAL) == STA_VOID);
     
     
+    #ifdef MMIO_DEBUG
     printfc("SNES::disk_read copy buffer to %06lx\n",SHARED_ADDR);
+    #endif
     for (i=0;i<(count*512);i++){
         buff[i]  = *(byte*)(SHARED_ADDR+i);
+        #ifdef MMIO_DEBUG
         if ( i < 8)
           printfc("0x%02x ",buff[i]);
-
+        #endif
     }
+    #ifdef MMIO_DEBUG
     printfc("\n");
+    #endif
     return retval;
 }
 

+ 0 - 5
snes/fatfstest/ff.c

@@ -1368,14 +1368,12 @@ 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);
@@ -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 */

+ 33 - 4
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);

+ 4 - 1
tools/bsnes/chip/fatfs/config.h

@@ -15,4 +15,7 @@
 
 
 #define SHARED_SIZE     512
-#define SHARED_ADDR     0x3f0000
+#define SHARED_ADDR     0x3f0000
+
+#undef MMIO_DEBUG
+#undef FATFS_DEBUG

+ 15 - 1
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;
 

+ 24 - 0
tools/bsnes/chip/fatfs/fatfs.cpp

@@ -47,16 +47,22 @@ void FATFS::fetchMem() {
 void FATFS::pushMem() {
   for ( int i=0;i<SHARED_SIZE;i++){
       bus.write(SHARED_ADDR + i,scratch_buffer[i]);
+      #ifdef FATFS_DEBUG
       if ( i < 8)
         printf("0x%02x ",scratch_buffer[i]);
+      #endif
   }
+  #ifdef FATFS_DEBUG
   printf("\n");
+  #endif
 }
 
 uint8 FATFS::mmio_read(unsigned addr) {
   addr &= 0xffff;
   if (addr == MMIO_RETVAL){
+      #ifdef FATFS_DEBUG
       printf("FATFS::mmio_read retal=%i\n",retval);
+      #endif
       return retval;
   }
   return cpu.regs.mdr;
@@ -64,36 +70,50 @@ uint8 FATFS::mmio_read(unsigned addr) {
 
 void FATFS::mmio_write(unsigned addr, uint8 data) {
   addr &= 0xffff;
+  #ifdef FATFS_DEBUG
   printf("FATFS::mmio_write 0x%04x 0x%02x (%i)\n",addr,data,data);
+  #endif
   if (addr == 0x3010){
       switch(data){
           case CMD_INIT:
+              #ifdef FATFS_DEBUG
               printf("FATFS::mmio_write CMD_INIT \n");
+              #endif
               command = CMD_INIT;
               retval = disk_initialize(0);
               break;
           case CMD_READ:
+              #ifdef FATFS_DEBUG
               printf("FATFS::mmio_write CMD_READ \n");
+              #endif
               command = CMD_READ;
               break;
           case CMD_WRITE:
               command = CMD_WRITE;
+              #ifdef FATFS_DEBUG
               printf("FATFS::mmio_write CMD_WRITE \n");
+              #endif
               break;
           default:
               command = CMD_NONE;
+              #ifdef FATFS_DEBUG
               printf("FATFS::mmio_write CMD_NONE \n");
+              #endif
               break;
       }
       fflush(stderr);
   }
   if (addr >= 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;
   }
 }