o mount and getfree working

This commit is contained in:
david
2009-06-03 12:12:12 +02:00
parent 551ecb1915
commit 4419128348
11 changed files with 77 additions and 47 deletions

View File

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

View File

@@ -1,3 +1,5 @@
#include "data.h"
void debug_init(void);
void debug_enable(void);
void printfs(word y,char* fmt,...);

View File

@@ -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;
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;
}

View File

@@ -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 */

View File

@@ -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

View File

@@ -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);