david 15 лет назад
Родитель
Сommit
4419128348

+ 6 - 0
snes/fatfstest/data.h

@@ -1,2 +1,8 @@
+
+#ifndef _DATA
+
 typedef	unsigned char	byte;
 typedef	unsigned short	word;
+
+#define _DATA
+#endif

+ 2 - 0
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,...);

+ 24 - 17
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 <string.h>
 
 
+// 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;    
+
+    printfc("SNES::disk_read poll retval\n");
+    while((retval = *(byte*) MMIO_RETVAL) == STA_VOID);
     
-    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 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;
 }
 

+ 6 - 1
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 */

+ 4 - 9
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

+ 19 - 10
snes/fatfstest/main.c

@@ -1,3 +1,7 @@
+
+//#include "integer.h"
+#include "ff.h"
+
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
@@ -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);
     

+ 5 - 4
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;
 }
 

+ 5 - 2
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<SHARED_SIZE;i++){
       bus.write(SHARED_ADDR + i,scratch_buffer[i]);
+      if ( i < 8)
+        printf("0x%02x ",scratch_buffer[i]);
   }
+  printf("\n");
 }
 
 uint8 FATFS::mmio_read(unsigned addr) {
@@ -90,7 +93,7 @@ void FATFS::mmio_write(unsigned addr, uint8 data) {
   }
   if (addr == MMIO_COUNT){
       count = data;
-      printf("FATFS::mmio_write set count: countr=%i \n",count);
+      printf("FATFS::mmio_write set count: count=%i \n",count);
       if (command == CMD_READ) {
           retval = disk_read (0, (BYTE*)scratch_buffer, sector, count);
           if (!retval)

+ 1 - 1
tools/bsnes/chip/fatfs/fatfs.hpp

@@ -20,7 +20,7 @@ private:
   int  sector;
   char count;
   char retval;
-  char *scratch_buffer;
+  unsigned char *scratch_buffer;
 };
 
 extern FATFS fatfs;

+ 2 - 0
tools/bsnes/snes/snes.cpp

@@ -78,6 +78,7 @@ void SNES::power() {
   }
 
   scheduler.init();
+  fatfs.init();
 
   ppu.PPUcounter::reset();
   cpu.power();
@@ -86,6 +87,7 @@ void SNES::power() {
   ppu.power();
   bus.power();
 
+
   if(expansion() == ExpansionBSX)            bsxbase.power();
   if(cartridge.mode() == Cartridge::ModeBsx) bsxcart.power();
   if(cartridge.bsx_flash_loaded())           bsxflash.power();

+ 1 - 1
tools/ffsample/linux/Makefile

@@ -44,7 +44,7 @@ image_not_parted:
 
 image:
 	rm -fv disk00.vfat
-	mkfs.vfat  -I -F 16 -v -C disk00.vfat 256000 
+	mkfs.vfat  -I -F 16 -v -C disk00.vfat 4000 
 	sudo mount -o loop disk00.vfat disk
 	sudo cp -v /var/log/*.log disk/
 	sudo umount disk