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 char byte;
typedef unsigned short word; typedef unsigned short word;
#define _DATA
#endif

View File

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

View File

@ -5,8 +5,6 @@
#include "data.h" #include "data.h"
#include "debug.h" #include "debug.h"
volatile static
DSTATUS Stat = STA_NOINIT; /* Disk status */
/* Interface /* Interface
@ -33,20 +31,24 @@ return 1 byte
#include <string.h> #include <string.h>
// TODO: Figure out gobal vars ?!?
DSTATUS Stat = 0 ; //STA_NOINIT; /* Disk status */
DSTATUS disk_initialize (BYTE drv) { DSTATUS disk_initialize (BYTE drv) {
byte retval; 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 */ if (drv) return STA_NOINIT; /* Supports only single drive */
Stat |= STA_NOINIT; Stat |= STA_NOINIT;
printfc("SNES::disk_initialize stat=%i\n",Stat);
*(byte*) MMIO_RETVAL = STA_VOID; *(byte*) MMIO_RETVAL = STA_VOID;
*(byte*) MMIO_CMD = CMD_INIT; *(byte*) MMIO_CMD = CMD_INIT;
while(*(byte*) MMIO_RETVAL == STA_VOID); printfc("SNES::disk_initialize poll retval\n");
retval = *(byte*) MMIO_RETVAL; while((retval = *(byte*) MMIO_RETVAL) == STA_VOID);
Stat &= ~STA_NOINIT; /* When device goes ready, clear STA_NOINIT */ 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; return Stat;
} }
@ -77,11 +79,11 @@ DRESULT disk_read (
byte retval; byte retval;
word i; word i;
printfc("disk_read enter\n"); printfc("SNES::disk_read called sector=%li count=%i\n",sector,count);
//if (drv || !count) return RES_PARERR; if (drv || !count) return RES_PARERR;
printfc("drv ok\n"); printfc("SNES::disk_read drv ok\n");
if (Stat & STA_NOINIT) return RES_NOTRDY; 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_RETVAL = STA_VOID;
*(byte*) MMIO_CMD = CMD_READ; *(byte*) MMIO_CMD = CMD_READ;
@ -93,13 +95,18 @@ DRESULT disk_read (
*(byte*) MMIO_COUNT = count; *(byte*) MMIO_COUNT = count;
while(*(byte*) MMIO_RETVAL == STA_VOID); printfc("SNES::disk_read poll retval\n");
retval = *(byte*) MMIO_RETVAL; while((retval = *(byte*) MMIO_RETVAL) == STA_VOID);
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; return retval;
} }

View File

@ -66,6 +66,7 @@
#include "ff.h" /* FatFs configurations and declarations */ #include "ff.h" /* FatFs configurations and declarations */
#include "diskio.h" /* Declarations of low level disk I/O functions */ #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 { } else {
vol = 0; /* No drive number is given, use drive number 0 as default */ 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 */ /* Check if the logical drive number is valid or not */
if (vol >= _DRIVES) return FR_INVALID_DRIVE; /* Is the drive number valid? */ if (vol >= _DRIVES) return FR_INVALID_DRIVE; /* Is the drive number valid? */
*rfs = fs = FatFs[vol]; /* Returen pointer to the corresponding file system object */ *rfs = fs = FatFs[vol]; /* Returen pointer to the corresponding file system object */
if (!fs) return FR_NOT_ENABLED; /* Is the file system object registered? */ if (!fs) return FR_NOT_ENABLED; /* Is the file system object registered? */
ENTER_FF(fs); /* Lock file system */ ENTER_FF(fs); /* Lock file system */
printfc("auto_mount ok enter_ff\n");
if (fs->fs_type) { /* If the logical drive has been mounted */ if (fs->fs_type) { /* If the logical drive has been mounted */
stat = disk_status(fs->drive); 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 */ /* The logical drive must be re-mounted. Following code attempts to mount the volume */
fs->fs_type = 0; /* Clear the file system object */ fs->fs_type = 0; /* Clear the file system object */
fs->drive = LD2PD(vol); /* Bind the logical drive and a physical drive */ fs->drive = LD2PD(vol); /* Bind the logical drive and a physical drive */
stat = disk_initialize(fs->drive); /* Initialize low level disk I/O layer */ 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 */ if (stat & STA_NOINIT) /* Check if the drive is ready */
return FR_NOT_READY; return FR_NOT_READY;
#if _MAX_SS != 512 /* Get disk sector size if needed */ #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 */ if (chk_wp && (stat & STA_PROTECT)) /* Check write protection if needed */
return FR_WRITE_PROTECTED; return FR_WRITE_PROTECTED;
#endif #endif
printfc("auto_mount search fat now\n");
/* Search FAT partition on the drive */ /* Search FAT partition on the drive */
fmt = check_fs(fs, bsect = 0); /* Check sector 0 as an SFD format */ 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 */ 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; typedef unsigned long DWORD;
/* Boolean type */ /* Boolean type */
typedef enum { FALSE = 0, TRUE } BOOL; // enum { false = 0 , true } bool;
/* typedef int BOOL;
#define FALSE 0 #define FALSE 0
#define TRUE 1 #define TRUE 1
typedef int BOOL;
*/
#endif
#define _INTEGER #define _INTEGER
#endif #endif

View File

@ -1,3 +1,7 @@
//#include "integer.h"
#include "ff.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
@ -9,8 +13,7 @@
#include "ressource.h"; #include "ressource.h";
#include "PPU.h" #include "PPU.h"
#include "debug.h" #include "debug.h"
#include "integer.h"
#include "ff.h"
padStatus pad1; padStatus pad1;
@ -20,8 +23,8 @@ DWORD acc_size; /* Work register for fs command */
WORD acc_files, acc_dirs; WORD acc_files, acc_dirs;
FILINFO finfo; FILINFO finfo;
FATFS fatfs[1]; /* File system object for each logical drive */ FATFS fatfs[2]; /* File system object for each logical drive */
BYTE Buff[512]; /* Working buffer */ BYTE Buff[1024]; /* Working buffer */
DWORD p1, p2, p3; DWORD p1, p2, p3;
BYTE res; BYTE res;
@ -70,7 +73,7 @@ void halt(void) {
void put_rc (FRESULT rc){ void put_rc (FRESULT rc){
const char *p; const char *p;
static const char str[] = 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" "DENIED\0" "EXIST\0" "RW_ERROR\0" "WRITE_PROTECTED\0" "NOT_ENABLED\0"
"NO_FILESYSTEM\0" "INVALID_OBJECT\0" "MKFS_ABORTED\0"; "NO_FILESYSTEM\0" "INVALID_OBJECT\0" "MKFS_ABORTED\0";
FRESULT i; FRESULT i;
@ -117,14 +120,19 @@ void main(void) {
debug_enable(); debug_enable();
printfs(0,"FATFS "); 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])); 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) if (res)
put_rc(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" "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", "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, (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); fs->fatbase, fs->dirbase, fs->database);
acc_size = acc_files = acc_dirs = 0; acc_size = acc_files = acc_dirs = 0;
res = scan_files("/"); printfc("SNES::main: scan files\n");
res = scan_files("");
if (res) if (res)
put_rc(res); put_rc(res);

View File

@ -47,18 +47,18 @@ DSTATUS disk_initialize (BYTE drv) {
int fd = open(IMAGE_NAME, O_RDWR); int fd = open(IMAGE_NAME, O_RDWR);
if (fd == -1) { if (fd == -1) {
perror("Error opening file for writing"); perror("DISKIO::disk_initialize: Error opening file for writing");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
int size = lseek(fd,0,SEEK_END); int size = lseek(fd,0,SEEK_END);
lseek(fd,0,SEEK_SET); 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); 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) { if (image_addr == MAP_FAILED) {
close(fd); close(fd);
perror("Error mmapping the file"); perror("DISKIO::disk_initialize: Error mmapping the file");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -94,8 +94,9 @@ DRESULT disk_read (
DWORD offset = sector * 512; DWORD offset = sector * 512;
int size = count * 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); memcpy(buff,image_addr + offset,size);
printf("DISKIO::disk_read: done\n");
return RES_OK; return RES_OK;
} }

View File

@ -13,7 +13,7 @@ void FATFS::init() {
sector = 0; sector = 0;
count = 0; count = 0;
retval = -1; retval = -1;
scratch_buffer = (char*)malloc(SHARED_SIZE); scratch_buffer = (unsigned char*)malloc(SHARED_SIZE);
} }
void FATFS::enable() { void FATFS::enable() {
@ -47,7 +47,10 @@ void FATFS::fetchMem() {
void FATFS::pushMem() { void FATFS::pushMem() {
for ( int i=0;i<SHARED_SIZE;i++){ for ( int i=0;i<SHARED_SIZE;i++){
bus.write(SHARED_ADDR + i,scratch_buffer[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) { uint8 FATFS::mmio_read(unsigned addr) {
@ -90,7 +93,7 @@ void FATFS::mmio_write(unsigned addr, uint8 data) {
} }
if (addr == MMIO_COUNT){ if (addr == MMIO_COUNT){
count = data; 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) { if (command == CMD_READ) {
retval = disk_read (0, (BYTE*)scratch_buffer, sector, count); retval = disk_read (0, (BYTE*)scratch_buffer, sector, count);
if (!retval) if (!retval)

View File

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

View File

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

View File

@ -44,7 +44,7 @@ image_not_parted:
image: image:
rm -fv disk00.vfat 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 mount -o loop disk00.vfat disk
sudo cp -v /var/log/*.log disk/ sudo cp -v /var/log/*.log disk/
sudo umount disk sudo umount disk