Merge branch 'master' of git@github.com:optixx/snesram
Conflicts: tools/ffsample/linux/diskio.c
This commit is contained in:
@@ -126,7 +126,7 @@ link += $(if $(findstring input.rawinput,$(ruby)),$(call mklib,xinput) $(call mk
|
||||
objects = libco ruby libfilter string \
|
||||
reader cart cheat \
|
||||
memory smemory cpu scpu smp ssmp sdsp ppu bppu snes \
|
||||
bsx srtc sdd1 spc7110 cx4 dsp1 dsp2 dsp3 dsp4 obc1 st010 cmmio
|
||||
bsx srtc sdd1 spc7110 cx4 dsp1 dsp2 dsp3 dsp4 obc1 st010 cmmio fatfs diskio
|
||||
|
||||
ifeq ($(enable_gzip),true)
|
||||
#objects += adler32 compress crc32 deflate gzio inffast inflate inftrees ioapi trees unzip zip zutil
|
||||
@@ -237,6 +237,10 @@ obj/dsp4.$(obj) : chip/dsp4/dsp4.cpp chip/dsp4/*
|
||||
obj/obc1.$(obj) : chip/obc1/obc1.cpp chip/obc1/*
|
||||
obj/st010.$(obj) : chip/st010/st010.cpp chip/st010/*
|
||||
obj/cmmio.$(obj) : chip/cmmio/cmmio.cpp chip/cmmio/*
|
||||
obj/fatfs.$(obj) : chip/fatfs/fatfs.cpp chip/fatfs/*
|
||||
obj/diskio.$(obj) : chip/fatfs/diskio.cpp chip/fatfs/*
|
||||
|
||||
|
||||
|
||||
|
||||
############
|
||||
|
||||
@@ -10,3 +10,4 @@
|
||||
#include "obc1/obc1.hpp"
|
||||
#include "st010/st010.hpp"
|
||||
#include "cmmio/cmmio.hpp"
|
||||
#include "fatfs/fatfs.hpp"
|
||||
|
||||
168
tools/bsnes/chip/fatfs/diskio.cpp
Normal file
168
tools/bsnes/chip/fatfs/diskio.cpp
Normal file
@@ -0,0 +1,168 @@
|
||||
|
||||
#include "integer.h"
|
||||
#include "diskio.h"
|
||||
|
||||
static volatile
|
||||
DSTATUS Stat = STA_NOINIT; /* Disk status */
|
||||
|
||||
|
||||
/* Interface
|
||||
** Scratch Buffer
|
||||
addr 3 byte
|
||||
size 1 byte
|
||||
|
||||
** Call Interface
|
||||
cmd 1 byte
|
||||
sector 4 bytes
|
||||
count 1 byte
|
||||
return 1 byte
|
||||
|
||||
** Commands
|
||||
* disk_init
|
||||
* disk_read
|
||||
* disk_write
|
||||
*/
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Initialize Disk Drive */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <string.h>
|
||||
|
||||
#define IMAGE_NAME "disk00.vfat"
|
||||
|
||||
BYTE *image_addr;
|
||||
|
||||
DSTATUS disk_initialize (BYTE drv) {
|
||||
if (drv) return STA_NOINIT; /* Supports only single drive */
|
||||
|
||||
Stat |= STA_NOINIT;
|
||||
|
||||
int fd = open(IMAGE_NAME, O_RDWR);
|
||||
if (fd == -1) {
|
||||
perror("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);
|
||||
if (image_addr == MAP_FAILED) {
|
||||
close(fd);
|
||||
perror("Error mmapping the file");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
Stat &= ~STA_NOINIT; /* When device goes ready, clear STA_NOINIT */
|
||||
return Stat;
|
||||
}
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Return Disk Status */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
DSTATUS disk_status (BYTE drv){
|
||||
if (drv) return STA_NOINIT; /* Supports only single drive */
|
||||
return Stat;
|
||||
}
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Read Sector(s) */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
DRESULT disk_read (
|
||||
BYTE drv, /* Physical drive nmuber (0) */
|
||||
BYTE *buff, /* Data buffer to store read data */
|
||||
DWORD sector, /* Sector number (LBA) */
|
||||
BYTE count /* Sector count (1..255) */
|
||||
)
|
||||
{
|
||||
BYTE c, iord_l, iord_h;
|
||||
if (drv || !count) return RES_PARERR;
|
||||
if (Stat & STA_NOINIT) return RES_NOTRDY;
|
||||
|
||||
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);
|
||||
memcpy(buff,image_addr + offset,size);
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Write Sector(s) */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
#if _READONLY == 0
|
||||
DRESULT disk_write (
|
||||
BYTE drv, /* Physical drive nmuber (0) */
|
||||
const BYTE *buff, /* Data to be written */
|
||||
DWORD sector, /* Sector number (LBA) */
|
||||
BYTE count /* Sector count (1..255) */
|
||||
)
|
||||
{
|
||||
|
||||
if (drv || !count) return RES_PARERR;
|
||||
if (Stat & STA_NOINIT) return RES_NOTRDY;
|
||||
|
||||
DWORD offset = sector * 512;
|
||||
int size = count * 512;
|
||||
printf("disk_write: sector=%li count=%i addr=%p off=%li size=%i\n",sector,count,image_addr + offset,offset,size);
|
||||
memcpy(image_addr + offset,buff,size);
|
||||
return RES_OK;
|
||||
}
|
||||
#endif /* _READONLY */
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Miscellaneous Functions */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
#if _USE_IOCTL != 0
|
||||
DRESULT disk_ioctl (
|
||||
BYTE drv, /* Physical drive nmuber (0) */
|
||||
BYTE ctrl, /* Control code */
|
||||
void *buff /* Buffer to send/receive data block */
|
||||
)
|
||||
{
|
||||
BYTE n, w, ofs, dl, dh, *ptr = (BYTE*)buff;
|
||||
|
||||
|
||||
if (drv) return RES_PARERR;
|
||||
if (Stat & STA_NOINIT) return RES_NOTRDY;
|
||||
|
||||
switch (ctrl) {
|
||||
case GET_SECTOR_COUNT : /* Get number of sectors on the disk (DWORD) */
|
||||
printf("disk_ioctl: GET_SECTOR_COUNT\n");
|
||||
ofs = 60; w = 2; n = 0;
|
||||
break;
|
||||
|
||||
case GET_SECTOR_SIZE : /* Get sectors on the disk (WORD) */
|
||||
printf("disk_ioctl: GET_SECTOR_SIZE\n");
|
||||
*(WORD*)buff = 512;
|
||||
return RES_OK;
|
||||
|
||||
case GET_BLOCK_SIZE : /* Get erase block size in sectors (DWORD) */
|
||||
printf("disk_ioctl: GET_BLOCK_SIZE\n");
|
||||
*(DWORD*)buff = 32;
|
||||
return RES_OK;
|
||||
|
||||
default:
|
||||
return RES_PARERR;
|
||||
}
|
||||
return RES_OK;
|
||||
}
|
||||
#endif /* _USE_IOCTL != 0 */
|
||||
|
||||
|
||||
|
||||
|
||||
71
tools/bsnes/chip/fatfs/diskio.h
Normal file
71
tools/bsnes/chip/fatfs/diskio.h
Normal file
@@ -0,0 +1,71 @@
|
||||
/*-----------------------------------------------------------------------
|
||||
/ Low level disk interface modlue include file R0.05 (C)ChaN, 2007
|
||||
/-----------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef _DISKIO
|
||||
|
||||
#define _READONLY 0 /* 1: Read-only mode */
|
||||
#define _USE_IOCTL 1
|
||||
|
||||
#include "integer.h"
|
||||
|
||||
|
||||
/* Status of Disk Functions */
|
||||
typedef BYTE DSTATUS;
|
||||
|
||||
/* Results of Disk Functions */
|
||||
typedef enum {
|
||||
RES_OK = 0, /* 0: Successful */
|
||||
RES_ERROR, /* 1: R/W Error */
|
||||
RES_WRPRT, /* 2: Write Protected */
|
||||
RES_NOTRDY, /* 3: Not Ready */
|
||||
RES_PARERR /* 4: Invalid Parameter */
|
||||
} DRESULT;
|
||||
|
||||
|
||||
/*---------------------------------------*/
|
||||
/* Prototypes for disk control functions */
|
||||
|
||||
DSTATUS disk_initialize (BYTE);
|
||||
DSTATUS disk_status (BYTE);
|
||||
DRESULT disk_read (BYTE, BYTE*, DWORD, BYTE);
|
||||
#if _READONLY == 0
|
||||
DRESULT disk_write (BYTE, const BYTE*, DWORD, BYTE);
|
||||
#endif
|
||||
DRESULT disk_ioctl (BYTE, BYTE, void*);
|
||||
void disk_timerproc (void);
|
||||
|
||||
|
||||
|
||||
|
||||
/* Disk Status Bits (DSTATUS) */
|
||||
|
||||
#define STA_NOINIT 0x01 /* Drive not initialized */
|
||||
#define STA_NODISK 0x02 /* No medium in the drive */
|
||||
#define STA_PROTECT 0x04 /* Write protected */
|
||||
|
||||
|
||||
|
||||
/* Command code for disk_ioctrl() */
|
||||
|
||||
/* Generic command */
|
||||
#define CTRL_SYNC 0 /* Mandatory for write functions */
|
||||
#define GET_SECTOR_COUNT 1 /* Mandatory for only f_mkfs() */
|
||||
#define GET_SECTOR_SIZE 2
|
||||
#define GET_BLOCK_SIZE 3 /* Mandatory for only f_mkfs() */
|
||||
#define CTRL_POWER 4
|
||||
#define CTRL_LOCK 5
|
||||
#define CTRL_EJECT 6
|
||||
|
||||
#define _DISKIO
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
116
tools/bsnes/chip/fatfs/fatfs.cpp
Normal file
116
tools/bsnes/chip/fatfs/fatfs.cpp
Normal file
@@ -0,0 +1,116 @@
|
||||
#include <../base.hpp>
|
||||
#include <../cart/cart.hpp>
|
||||
#include "fatfs.hpp"
|
||||
|
||||
|
||||
#include "diskio.h"
|
||||
|
||||
#define CMD_INIT 0x00
|
||||
#define CMD_READ 0x01
|
||||
#define CMD_WRITE 0x02
|
||||
#define CMD_NONE 0xff
|
||||
|
||||
#define SHARED_SIZE 512
|
||||
#define SHARED_ADDR 0x3f0000
|
||||
|
||||
void FATFS::init() {
|
||||
command = CMD_NONE;
|
||||
sector = 0;
|
||||
count = 0;
|
||||
retval = -1;
|
||||
scratch_buffer = (char*)malloc(SHARED_SIZE);
|
||||
}
|
||||
|
||||
void FATFS::enable() {
|
||||
// command
|
||||
memory::mmio.map(0x3010, *this);
|
||||
// sector
|
||||
memory::mmio.map(0x3011, *this);
|
||||
memory::mmio.map(0x3012, *this);
|
||||
memory::mmio.map(0x3013, *this);
|
||||
memory::mmio.map(0x3014, *this);
|
||||
// offset
|
||||
memory::mmio.map(0x3015, *this);
|
||||
// return value
|
||||
memory::mmio.map(0x3016, *this);
|
||||
}
|
||||
|
||||
void FATFS::power() {
|
||||
reset();
|
||||
}
|
||||
|
||||
void FATFS::reset() {
|
||||
}
|
||||
|
||||
|
||||
void FATFS::fetchMem() {
|
||||
for ( int i=0;i<SHARED_SIZE;i++){
|
||||
scratch_buffer[i] = bus.read(SHARED_ADDR + i);
|
||||
}
|
||||
}
|
||||
|
||||
void FATFS::pushMem() {
|
||||
for ( int i=0;i<SHARED_SIZE;i++){
|
||||
bus.write(SHARED_ADDR + i,scratch_buffer[i]);
|
||||
}
|
||||
}
|
||||
|
||||
uint8 FATFS::mmio_read(unsigned addr) {
|
||||
addr &= 0xffff;
|
||||
if (addr == 0x3016){
|
||||
printf("FATFS::mmio_read retal=%i\n",retval);
|
||||
return retval;
|
||||
}
|
||||
return cpu.regs.mdr;
|
||||
}
|
||||
|
||||
void FATFS::mmio_write(unsigned addr, uint8 data) {
|
||||
addr &= 0xffff;
|
||||
printf("FATFS::mmio_write 0x%04x 0x%02x (%i)\n",addr,data,data);
|
||||
if (addr == 0x3010){
|
||||
switch(data){
|
||||
case CMD_INIT:
|
||||
printf("FATFS::mmio_write CMD_INIT \n");
|
||||
command = CMD_INIT;
|
||||
disk_initialize(0);
|
||||
break;
|
||||
case CMD_READ:
|
||||
printf("FATFS::mmio_write CMD_READ \n");
|
||||
command = CMD_READ;
|
||||
break;
|
||||
case CMD_WRITE:
|
||||
command = CMD_WRITE;
|
||||
printf("FATFS::mmio_write CMD_WRITE \n");
|
||||
break;
|
||||
default:
|
||||
command = CMD_NONE;
|
||||
printf("FATFS::mmio_write CMD_NONE \n");
|
||||
break;
|
||||
}
|
||||
fflush(stderr);
|
||||
}
|
||||
if (addr >= 0x3011 && addr <= 0x3014){
|
||||
sector = data << ( (3 - ( addr - 0x3011)) << 3);
|
||||
printf("FATFS::mmio_write set sector: byte=%i val=%i sector=%i \n",(3 - ( addr - 0x3011)),data,sector);
|
||||
}
|
||||
if (addr == 0x3015){
|
||||
count = data;
|
||||
printf("FATFS::mmio_write set offset: countr=%i \n",count);
|
||||
if (command == CMD_READ) {
|
||||
retval = disk_read (0, (BYTE*)scratch_buffer, sector, count);
|
||||
if (!retval)
|
||||
pushMem();
|
||||
} else if (command == CMD_WRITE) {
|
||||
fetchMem();
|
||||
retval = disk_write (0, (BYTE*)scratch_buffer, sector, count);
|
||||
} else{
|
||||
printf("FATFS::mmio_write set offset: no command to trigger \n");
|
||||
}
|
||||
}
|
||||
if (addr == 0x3016){
|
||||
printf("FATFS::mmio_write reg 0x3016 retav is RW\n");
|
||||
}
|
||||
}
|
||||
|
||||
FATFS::FATFS() {
|
||||
}
|
||||
26
tools/bsnes/chip/fatfs/fatfs.hpp
Normal file
26
tools/bsnes/chip/fatfs/fatfs.hpp
Normal file
@@ -0,0 +1,26 @@
|
||||
class FATFS : public MMIO {
|
||||
public:
|
||||
|
||||
void init();
|
||||
void enable();
|
||||
void power();
|
||||
void reset();
|
||||
|
||||
|
||||
void fetchMem();
|
||||
void pushMem();
|
||||
|
||||
|
||||
uint8 mmio_read (unsigned addr);
|
||||
void mmio_write(unsigned addr, uint8 data);
|
||||
|
||||
FATFS();
|
||||
private:
|
||||
char command;
|
||||
int sector;
|
||||
char count;
|
||||
char retval;
|
||||
char *scratch_buffer;
|
||||
};
|
||||
|
||||
extern FATFS fatfs;
|
||||
37
tools/bsnes/chip/fatfs/integer.h
Normal file
37
tools/bsnes/chip/fatfs/integer.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/*-------------------------------------------*/
|
||||
/* Integer type definitions for FatFs module */
|
||||
/*-------------------------------------------*/
|
||||
|
||||
#ifndef _INTEGER
|
||||
|
||||
#if 0
|
||||
#include <windows.h>
|
||||
#else
|
||||
|
||||
/* These types must be 16-bit, 32-bit or larger integer */
|
||||
typedef int INT;
|
||||
typedef unsigned int UINT;
|
||||
|
||||
/* These types must be 8-bit integer */
|
||||
typedef signed char CHAR;
|
||||
typedef unsigned char UCHAR;
|
||||
typedef unsigned char BYTE;
|
||||
|
||||
/* These types must be 16-bit integer */
|
||||
typedef short SHORT;
|
||||
typedef unsigned short USHORT;
|
||||
typedef unsigned short WORD;
|
||||
typedef unsigned short WCHAR;
|
||||
|
||||
/* These types must be 32-bit integer */
|
||||
typedef long LONG;
|
||||
typedef unsigned long ULONG;
|
||||
typedef unsigned long DWORD;
|
||||
|
||||
/* Boolean type */
|
||||
typedef enum { FALSE = 0, TRUE } BOOL;
|
||||
|
||||
#endif
|
||||
|
||||
#define _INTEGER
|
||||
#endif
|
||||
@@ -24,6 +24,7 @@ DSP4 dsp4;
|
||||
OBC1 obc1;
|
||||
ST010 st010;
|
||||
CMMIO cmmio;
|
||||
FATFS fatfs;
|
||||
#include "scheduler/scheduler.cpp"
|
||||
#include "tracer/tracer.cpp"
|
||||
|
||||
@@ -101,6 +102,7 @@ void SNES::power() {
|
||||
if(cartridge.has_st010()) st010.power();
|
||||
|
||||
cmmio.power();
|
||||
fatfs.power();
|
||||
|
||||
for(unsigned i = 0x2100; i <= 0x213f; i++) memory::mmio.map(i, ppu);
|
||||
for(unsigned i = 0x2140; i <= 0x217f; i++) memory::mmio.map(i, cpu);
|
||||
@@ -125,6 +127,7 @@ void SNES::power() {
|
||||
if(cartridge.has_st010()) st010.enable();
|
||||
|
||||
cmmio.enable();
|
||||
fatfs.enable();
|
||||
|
||||
input.port_set_device(0, snes.config.controller_port1);
|
||||
input.port_set_device(1, snes.config.controller_port2);
|
||||
|
||||
@@ -18,12 +18,6 @@ $(bin): $(objs)
|
||||
clean:
|
||||
rm -rf $(bin) *.o
|
||||
|
||||
|
||||
image32:
|
||||
dd if=/dev/zero of=disk00.vfat bs=1M count=64
|
||||
sudo mkfs.vfat -F 32 -v disk00.vfat
|
||||
|
||||
|
||||
image_parted:
|
||||
dd if=/dev/zero of=disk00.vfat bs=1M count=256
|
||||
fdisk -H 32 -S 32 -C 500 disk00.vfat
|
||||
@@ -48,19 +42,11 @@ image_not_parted:
|
||||
sudo umount disk
|
||||
sudo losetup -d /dev/loop0
|
||||
|
||||
|
||||
image_no_fdisk:
|
||||
dd if=/dev/zero of=disk00.vfat bs=1M count=256
|
||||
sudo mkfs.vfat -I -f 2 -F 16 -v disk00.vfat
|
||||
sudo mount -o loop disk00.vfat disk
|
||||
sudo cp /var/log/*log disk/
|
||||
sudo umount disk
|
||||
|
||||
image_no_dd:
|
||||
image:
|
||||
rm -fv disk00.vfat
|
||||
mkfs.vfat -F 32 -v -C disk00.vfat 256000
|
||||
sudo mount -o loop,check=s disk00.vfat disk
|
||||
sudo cp -v /var/log/*log disk/
|
||||
mkfs.vfat -I -F 16 -v -C disk00.vfat 256000
|
||||
sudo mount -o loop disk00.vfat disk
|
||||
sudo cp -v /var/log/*.log disk/
|
||||
sudo umount disk
|
||||
|
||||
mount:
|
||||
@@ -71,3 +57,8 @@ umount:
|
||||
sudo umount disk
|
||||
sudo losetup -d /dev/loop0
|
||||
|
||||
test:
|
||||
echo "fi\nfs\nfl" | ./fftest
|
||||
|
||||
run:
|
||||
rlwrap ./fftest
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
static volatile
|
||||
DSTATUS Stat = STA_NOINIT; /* Disk status */
|
||||
|
||||
<<<<<<< HEAD:tools/ffsample/linux/diskio.c
|
||||
/*
|
||||
|
||||
sudo losetup /dev/loop0 disk00.vfat
|
||||
@@ -50,28 +51,24 @@ Signature: 0xAA55
|
||||
3: 00 0 0 0 - 0 0 0 [ 0 - 0] unused
|
||||
4: 00 0 0 0 - 0 0 0 [ 0 - 0] unused
|
||||
*/
|
||||
=======
|
||||
>>>>>>> 660767c464c3d78d36436123eb2e717c3c85f6bc:tools/ffsample/linux/diskio.c
|
||||
|
||||
/* Interface
|
||||
|
||||
** Scratch Buffer
|
||||
|
||||
addr 3 byte
|
||||
size 1 byte
|
||||
|
||||
** Call Interface
|
||||
|
||||
cmd 1 byte
|
||||
sector 4 bytes
|
||||
count 1 byte
|
||||
return 1 byte
|
||||
|
||||
** Commands
|
||||
|
||||
* disk_init
|
||||
* disk_read
|
||||
* disk_write
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
@@ -85,18 +82,16 @@ return 1 byte
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#define IMAGE_NAME "disk00.vfat"
|
||||
|
||||
int *image_addr;
|
||||
char *image_addr;
|
||||
|
||||
DSTATUS disk_initialize (BYTE drv) {
|
||||
if (drv) return STA_NOINIT; /* Supports only single drive */
|
||||
|
||||
Stat |= STA_NOINIT;
|
||||
/* map image */
|
||||
|
||||
|
||||
int fd = open(IMAGE_NAME, O_RDWR);
|
||||
if (fd == -1) {
|
||||
@@ -104,19 +99,17 @@ DSTATUS disk_initialize (BYTE drv) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
int size = lseek(fd,0,SEEK_END);
|
||||
lseek(fd,0,SEEK_SET);
|
||||
printf("Open Image (size %i)\n",size);
|
||||
|
||||
//image_addr = mmap(0,fd,)
|
||||
image_addr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
if (image_addr == MAP_FAILED) {
|
||||
close(fd);
|
||||
perror("Error mmapping the file");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
Stat &= ~STA_NOINIT; /* When device goes ready, clear STA_NOINIT */
|
||||
return Stat;
|
||||
}
|
||||
@@ -147,13 +140,10 @@ DRESULT disk_read (
|
||||
if (drv || !count) return RES_PARERR;
|
||||
if (Stat & STA_NOINIT) return RES_NOTRDY;
|
||||
|
||||
DWORD offset = sector * 512;
|
||||
DWORD offset = sector * 512;
|
||||
int size = count * 512;
|
||||
|
||||
printf("disk_read: sector=%li count=%i addr=%p size=%i\n",sector,count,image_addr + offset,size);
|
||||
printf("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("%x %x %x %x\n",buff[0],buff[1],buff[2],buff[3]);
|
||||
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
@@ -169,23 +159,14 @@ DRESULT disk_write (
|
||||
BYTE count /* Sector count (1..255) */
|
||||
)
|
||||
{
|
||||
BYTE s, c, iowr_l, iowr_h;
|
||||
|
||||
|
||||
|
||||
if (drv || !count) return RES_PARERR;
|
||||
if (Stat & STA_NOINIT) return RES_NOTRDY;
|
||||
|
||||
/* Issue Write Setor(s) command */
|
||||
/*
|
||||
write_ata(REG_COUNT, count);
|
||||
write_ata(REG_SECTOR, (BYTE)sector);
|
||||
write_ata(REG_CYLL, (BYTE)(sector >> 8));
|
||||
write_ata(REG_CYLH, (BYTE)(sector >> 16));
|
||||
write_ata(REG_DEV, ((BYTE)(sector >> 24) & 0x0F) | LBA);
|
||||
write_ata(REG_COMMAND, CMD_WRITE);
|
||||
*/
|
||||
|
||||
DWORD offset = sector * 512;
|
||||
int size = count * 512;
|
||||
printf("disk_write: sector=%li count=%i addr=%p off=%li size=%i\n",sector,count,image_addr + offset,offset,size);
|
||||
memcpy(image_addr + offset,buff,size);
|
||||
return RES_OK;
|
||||
}
|
||||
#endif /* _READONLY */
|
||||
@@ -223,38 +204,9 @@ DRESULT disk_ioctl (
|
||||
*(DWORD*)buff = 32;
|
||||
return RES_OK;
|
||||
|
||||
case CTRL_SYNC : /* Nothing to do */
|
||||
printf("disk_ioctl: CTRL_SIZE\n");
|
||||
return RES_OK;
|
||||
|
||||
case ATA_GET_REV : /* Get firmware revision (8 chars) */
|
||||
printf("disk_ioctl: ATAL_GET_REV\n");
|
||||
ofs = 23; w = 4; n = 4;
|
||||
break;
|
||||
|
||||
case ATA_GET_MODEL : /* Get model name (40 chars) */
|
||||
printf("disk_ioctl: ATAL_GET_MODEL\n");
|
||||
ofs = 27; w = 20; n = 20;
|
||||
break;
|
||||
|
||||
case ATA_GET_SN : /* Get serial number (20 chars) */
|
||||
printf("disk_ioctl: ATAL_GET_SN\n");
|
||||
ofs = 10; w = 10; n = 10;
|
||||
break;
|
||||
|
||||
default:
|
||||
return RES_PARERR;
|
||||
}
|
||||
|
||||
/*
|
||||
write_ata(REG_COMMAND, CMD_IDENTIFY);
|
||||
if (!wait_data()) return RES_ERROR;
|
||||
read_part(ptr, ofs, w);
|
||||
while (n--) {
|
||||
dl = *ptr; dh = *(ptr+1);
|
||||
*ptr++ = dh; *ptr++ = dl;
|
||||
}
|
||||
*/
|
||||
return RES_OK;
|
||||
}
|
||||
#endif /* _USE_IOCTL != 0 */
|
||||
|
||||
@@ -2,6 +2,11 @@
|
||||
/ Low level disk interface modlue include file R0.05 (C)ChaN, 2007
|
||||
/-----------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef _DISKIO
|
||||
|
||||
#define _READONLY 0 /* 1: Read-only mode */
|
||||
@@ -56,26 +61,11 @@ void disk_timerproc (void);
|
||||
#define CTRL_POWER 4
|
||||
#define CTRL_LOCK 5
|
||||
#define CTRL_EJECT 6
|
||||
/* MMC/SDC command */
|
||||
#define MMC_GET_TYPE 10
|
||||
#define MMC_GET_CSD 11
|
||||
#define MMC_GET_CID 12
|
||||
#define MMC_GET_OCR 13
|
||||
#define MMC_GET_SDSTAT 14
|
||||
/* ATA/CF command */
|
||||
#define ATA_GET_REV 20
|
||||
#define ATA_GET_MODEL 21
|
||||
#define ATA_GET_SN 22
|
||||
|
||||
|
||||
|
||||
/* Card type flags (CardType) */
|
||||
#define CT_MMC 0x01
|
||||
#define CT_SD1 0x02
|
||||
#define CT_SD2 0x04
|
||||
#define CT_SDC (CT_SD1|CT_SD2)
|
||||
#define CT_BLOCK 0x08
|
||||
|
||||
|
||||
#define _DISKIO
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -25,7 +25,7 @@
|
||||
#ifndef _FATFS
|
||||
#define _FATFS
|
||||
|
||||
#define _WORD_ACCESS 1
|
||||
#define _WORD_ACCESS 0
|
||||
/* The _WORD_ACCESS option defines which access method is used to the word
|
||||
/ data in the FAT structure.
|
||||
/
|
||||
@@ -60,7 +60,7 @@
|
||||
/ data transfer. This reduces memory consumption 512 bytes each file object. */
|
||||
|
||||
|
||||
#define _USE_STRFUNC 1
|
||||
#define _USE_STRFUNC 0
|
||||
/* To enable string functions, set _USE_STRFUNC to 1 or 2. */
|
||||
|
||||
|
||||
@@ -81,13 +81,13 @@
|
||||
/* 512 for memroy card and hard disk, 1024 for floppy disk, 2048 for MO disk */
|
||||
|
||||
|
||||
#define _MULTI_PARTITION 1
|
||||
#define _MULTI_PARTITION 0
|
||||
/* When _MULTI_PARTITION is set to 0, each volume is bound to the same physical
|
||||
/ drive number and can mount only first primaly partition. When it is set to 1,
|
||||
/ each volume is tied to the partitions listed in Drives[]. */
|
||||
|
||||
|
||||
#define _CODE_PAGE 850
|
||||
#define _CODE_PAGE 437
|
||||
/* The _CODE_PAGE specifies the OEM code page to be used on the target system.
|
||||
/ When it is non LFN configuration, there is no difference between SBCS code
|
||||
/ pages. When LFN is enabled, the code page must always be set correctly.
|
||||
|
||||
Binary file not shown.
@@ -118,7 +118,7 @@ FRESULT scan_files (char* path)
|
||||
|
||||
if ((res = f_opendir(&dirs, path)) == FR_OK) {
|
||||
i = strlen(path);
|
||||
printf("Ok\n");
|
||||
//printf("Ok\n");
|
||||
while (((res = f_readdir(&dirs, &finfo)) == FR_OK) && finfo.fname[0]) {
|
||||
if (finfo.fattrib & AM_DIR) {
|
||||
acc_dirs++;
|
||||
@@ -241,22 +241,6 @@ int main (void)
|
||||
{ printf("Sector size: %u\n", w1); }
|
||||
if (disk_ioctl((BYTE)p1, GET_BLOCK_SIZE, &p2) == RES_OK)
|
||||
{ printf("Erase block size: %lu sectors\n", p2); }
|
||||
if (disk_ioctl((BYTE)p1, MMC_GET_TYPE, &b1) == RES_OK)
|
||||
{ printf("Card type: %u\n", b1); }
|
||||
if (disk_ioctl((BYTE)p1, MMC_GET_CSD, Buff) == RES_OK)
|
||||
{ printf("CSD:\n"); put_dump(Buff, 0, 16); }
|
||||
if (disk_ioctl((BYTE)p1, MMC_GET_CID, Buff) == RES_OK)
|
||||
{ printf("CID:\n"); put_dump(Buff, 0, 16); }
|
||||
if (disk_ioctl((BYTE)p1, MMC_GET_OCR, Buff) == RES_OK)
|
||||
{ printf("OCR:\n"); put_dump(Buff, 0, 4); }
|
||||
if (disk_ioctl((BYTE)p1, MMC_GET_SDSTAT, Buff) == RES_OK) {
|
||||
printf("SD Status:\n");
|
||||
for (s1 = 0; s1 < 64; s1 += 16) put_dump(Buff+s1, s1, 16);
|
||||
}
|
||||
if (disk_ioctl((BYTE)p1, ATA_GET_MODEL, line) == RES_OK)
|
||||
{ line[40] = '\0'; printf("Model: %s\n", line); }
|
||||
if (disk_ioctl((BYTE)p1, ATA_GET_SN, line) == RES_OK)
|
||||
{ line[20] = '\0'; printf("S/N: %s\n", line); }
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user