cleanup code

This commit is contained in:
david 2009-06-08 11:00:27 +02:00
parent cb0ea4f8c8
commit 309e1062b9
21 changed files with 4723 additions and 4705 deletions

View File

@ -29,22 +29,15 @@ LIBS=-L$(SDK)/lib/cl
#-L$(SDK)/lib/c134 #-L$(SDK)/lib/c134
<<<<<<< HEAD:snes/fatfstest/Makefile
OBJS=StartupSnes.obj main.obj pad.obj PPU.obj debug.obj ressource.obj diskio.obj ff.obj
=======
OBJS=hook.obj StartupSnes.obj main.obj pad.obj PPU.obj debug.obj ressource.obj diskio.obj ff.obj crc.obj OBJS=hook.obj StartupSnes.obj main.obj pad.obj PPU.obj debug.obj ressource.obj diskio.obj ff.obj crc.obj
>>>>>>> c1203c3519d95a92e82a6f2ebf741ad663e46e33:snes/fatfstest/Makefile
APP=fatfs.smc APP=fatfs.smc
GFX=debugfont GFX=debugfont
all: $(APP) repair all: $(APP)
run: run:
$(EMU) $(APP) $(EMU) $(APP)
debugger:
$(EMU_DEBUG) $(APP)
upload: upload:
ucon64 -chk $(APP) ucon64 -chk $(APP)
cp -rv $(APP) /Volumes/SNES cp -rv $(APP) /Volumes/SNES
@ -55,6 +48,10 @@ disasm: $(APP)
rm -rf fatfs.asm rm -rf fatfs.asm
$(DISASM) fatfs.smc > fatfs.asm $(DISASM) fatfs.smc > fatfs.asm
repair: $(APP)
$(UCON) -snes -chk $(APP) 2>&1 >/dev/null
rm -rf fatfs.bak
StartupSnes.obj: StartupSnes.asm StartupSnes.obj: StartupSnes.asm
$(AS) -V $? $(AS) -V $?
@ -65,45 +62,17 @@ hook.obj: hook.asm
$(AS) -V $? $(AS) -V $?
%.obj: %.c %.obj: %.c
<<<<<<< HEAD:snes/fatfstest/Makefile
$(CC) -wl -wp -sop -ML -I $(INC) $? $(CC) -wl -wp -sop -ML -I $(INC) $?
#$(APP): $(OBJS) $(APP): $(OBJS)
# $(LD) -HB -M21 -V -T -Pff \ echo "test"
# -C008000,0000 -U0000,0000 \
# -Avectors=FFE4,7FE4 \
# -Aregistration_data=FFB0,7FB0 \
# -Aressource=18000,8000 \
# -N $(OBJS) $(LIBS) -O $@
$(APP): $(OBJS) hook.obj
$(LD) -B -HB -M21 -V -T -Pff \ $(LD) -B -HB -M21 -V -T -Pff \
-C3e8000,1f0000 -U000000,000000 \ -C3e8000,1f0000 -U000000,000000 \
-Avectors=FFE4,7FE4 \ -Avectors=FFE4,7FE4 \
-Aregistration_data=FFB0,7FB0 \ -Aregistration_data=FFB0,7FB0 \
-Aressource=3f8000,1f8000 \ -Aressource=18000,8000 \
-Ahook=008000,0000 \ -Ahook=008000,0000 \
-N $(OBJS) hook.obj $(LIBS) -O $@ -N $(OBJS) $(LIBS) -O $@
repair: $(APP)
$(UCON) -snes -chk $(APP) 2>&1 >/dev/null
rm -rf fatfs.bak
=======
$(CC) -wl -wp -sop -ML -I $(INC) $?
$(APP): $(OBJS)
$(LD) -HB -M21 -V -T -Pff \
-C3e8000,1f0000 -U000000,000000 \
-Avectors=FFE4,7FE4 \
-Aregistration_data=FFB0,7FB0 \
-Aressource=18000,8000 \
-Ahook=8000,0000 \
-N $(OBJS) $(LIBS) -O $@
ucon64 -snes -chk $(APP) 2>&1 >/dev/null
>>>>>>> c1203c3519d95a92e82a6f2ebf741ad663e46e33:snes/fatfstest/Makefile
clean: clean:
rm -vf $(APP) *.obj *.TMP rm -vf $(APP) *.obj *.TMP

View File

@ -4,7 +4,9 @@
#define CMD_WRITE 0x02 #define CMD_WRITE 0x02
#define CMD_NONE 0xff #define CMD_NONE 0xff
/* Memory Map */ /*
* Memory Map
*/
#define MMIO_CMD 0x3010 #define MMIO_CMD 0x3010
#define MMIO_SECTOR01 0x3011 #define MMIO_SECTOR01 0x3011
#define MMIO_SECTOR02 0x3012 #define MMIO_SECTOR02 0x3012

View File

@ -1,4 +1,3 @@
word crc_update (byte *data, word size); word crc_update(byte * data, word size);
word crc_update_mem (unsigned long, word size); word crc_update_mem(unsigned long, word size);

View File

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

View File

@ -2,8 +2,7 @@
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, ...);
void printfc(char* fmt,...); void printfc(char *fmt, ...);
void clears(void); void clears(void);
void printc_packet(unsigned long addr,unsigned int len,byte *packet); void printc_packet(unsigned long addr, unsigned int len, byte * packet);

View File

@ -3,61 +3,73 @@
/-----------------------------------------------------------------------*/ /-----------------------------------------------------------------------*/
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#ifndef _DISKIO #ifndef _DISKIO
#define _READONLY 0 /* 1: Read-only mode */ #define _READONLY 0 /* 1: Read-only mode */
#define _USE_IOCTL 1 #define _USE_IOCTL 1
#include "integer.h" #include "integer.h"
/* Status of Disk Functions */ /*
typedef BYTE DSTATUS; * Status of Disk Functions
*/
typedef BYTE DSTATUS;
/* Results of Disk Functions */ /*
typedef enum { * Results of Disk Functions
RES_OK = 0, /* 0: Successful */ */
RES_ERROR, /* 1: R/W Error */ typedef enum {
RES_WRPRT, /* 2: Write Protected */ RES_OK = 0, /* 0: Successful */
RES_NOTRDY, /* 3: Not Ready */ RES_ERROR, /* 1: R/W Error */
RES_PARERR /* 4: Invalid Parameter */ RES_WRPRT, /* 2: Write Protected */
} DRESULT; RES_NOTRDY, /* 3: Not Ready */
RES_PARERR /* 4: Invalid Parameter */
} DRESULT;
/*---------------------------------------*/ /*---------------------------------------*/
/* Prototypes for disk control functions */ /*
* Prototypes for disk control functions
*/
DSTATUS disk_initialize (BYTE); DSTATUS disk_initialize(BYTE);
DSTATUS disk_status (BYTE); DSTATUS disk_status(BYTE);
DRESULT disk_read (BYTE, BYTE*, DWORD, BYTE); DRESULT disk_read(BYTE, BYTE *, DWORD, BYTE);
#if _READONLY == 0 #if _READONLY == 0
DRESULT disk_write (BYTE, const BYTE*, DWORD, BYTE); DRESULT disk_write(BYTE, const BYTE *, DWORD, BYTE);
#endif #endif
DRESULT disk_ioctl (BYTE, BYTE, void*); DRESULT disk_ioctl(BYTE, BYTE, void *);
void disk_timerproc (void); void disk_timerproc(void);
/* Disk Status Bits (DSTATUS) */ /*
* Disk Status Bits (DSTATUS)
*/
#define STA_NOINIT 0x01 /* Drive not initialized */ #define STA_NOINIT 0x01 /* Drive not initialized */
#define STA_NODISK 0x02 /* No medium in the drive */ #define STA_NODISK 0x02 /* No medium in the drive */
#define STA_PROTECT 0x04 /* Write protected */ #define STA_PROTECT 0x04 /* Write protected */
#define STA_VOID 0xff #define STA_VOID 0xff
/* Command code for disk_ioctrl() */ /*
* Command code for disk_ioctrl()
*/
/* Generic command */ /*
#define CTRL_SYNC 0 /* Mandatory for write functions */ * Generic command
#define GET_SECTOR_COUNT 1 /* Mandatory for only f_mkfs() */ */
#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_SECTOR_SIZE 2
#define GET_BLOCK_SIZE 3 /* Mandatory for only f_mkfs() */ #define GET_BLOCK_SIZE 3 /* Mandatory for only f_mkfs() */
#define CTRL_POWER 4 #define CTRL_POWER 4
#define CTRL_LOCK 5 #define CTRL_LOCK 5
#define CTRL_EJECT 6 #define CTRL_EJECT 6
@ -66,6 +78,6 @@ void disk_timerproc (void);
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -1,8 +1,8 @@
typedef struct event{ typedef struct event {
word VBlankCount; word VBlankCount;
char (*callback)(word counter); char (*callback) (word counter);
struct event *previousEvent; struct event *previousEvent;
struct event *nextEvent; struct event *nextEvent;
} event; } event;
#define EVENT_STOP 0 #define EVENT_STOP 0
@ -11,6 +11,7 @@ typedef struct event{
extern event *events; extern event *events;
void initEvents(void); void initEvents(void);
extern event* addEvent(char (*callback)(word counter), int noDuplicateCallback); extern event *addEvent(char (*callback) (word counter),
extern void removeEvent(event *eventElement); int noDuplicateCallback);
extern void removeEvent(event * eventElement);
extern void processEvents(void); extern void processEvents(void);

View File

@ -26,120 +26,118 @@
#define _FATFS #define _FATFS
#define _WORD_ACCESS 0 #define _WORD_ACCESS 0
/* The _WORD_ACCESS option defines which access method is used to the word /*
/ data in the FAT structure. * The _WORD_ACCESS option defines which access method is used to the word / data in the FAT structure. / / 0: Byte-by-byte access. Always
/ * compatible with all platforms. / 1: Word access. Do not choose this unless following condition is met. / / When the byte order on the
/ 0: Byte-by-byte access. Always compatible with all platforms. * memory is big-endian or address miss-aligned / word access results incorrect behavior, the _WORD_ACCESS must be set to 0. / If it is not
/ 1: Word access. Do not choose this unless following condition is met. * the case, the value can also be set to 1 to improve the / performance and code efficiency.
/ */
/ When the byte order on the memory is big-endian or address miss-aligned
/ word access results incorrect behavior, the _WORD_ACCESS must be set to 0.
/ If it is not the case, the value can also be set to 1 to improve the
/ performance and code efficiency. */
#define _FS_READONLY 0 #define _FS_READONLY 0
/* Setting _FS_READONLY to 1 defines read only configuration. This removes /*
/ writing functions, f_write, f_sync, f_unlink, f_mkdir, f_chmod, f_rename, * Setting _FS_READONLY to 1 defines read only configuration. This removes / writing functions, f_write, f_sync, f_unlink, f_mkdir,
/ f_truncate and useless f_getfree. */ * f_chmod, f_rename, / f_truncate and useless f_getfree.
*/
#define _FS_MINIMIZE 0 #define _FS_MINIMIZE 0
/* The _FS_MINIMIZE option defines minimization level to remove some functions. /*
/ * The _FS_MINIMIZE option defines minimization level to remove some functions. / / 0: Full function. / 1: f_stat, f_getfree, f_unlink,
/ 0: Full function. * f_mkdir, f_chmod, f_truncate and f_rename / are removed. / 2: f_opendir and f_readdir are removed in addition to level 1. / 3: f_lseek
/ 1: f_stat, f_getfree, f_unlink, f_mkdir, f_chmod, f_truncate and f_rename * is removed in addition to level 2.
/ are removed. */
/ 2: f_opendir and f_readdir are removed in addition to level 1.
/ 3: f_lseek is removed in addition to level 2. */
#define _FS_TINY 0 #define _FS_TINY 0
/* When _FS_TINY is set to 1, FatFs uses the sector buffer in the file system /*
/ object instead of the sector buffer in the individual file object for file * When _FS_TINY is set to 1, FatFs uses the sector buffer in the file system / object instead of the sector buffer in the individual file
/ data transfer. This reduces memory consumption 512 bytes each file object. */ * object for file / data transfer. This reduces memory consumption 512 bytes each file object.
*/
#define _USE_STRFUNC 0 #define _USE_STRFUNC 0
/* To enable string functions, set _USE_STRFUNC to 1 or 2. */ /*
* To enable string functions, set _USE_STRFUNC to 1 or 2.
*/
#define _USE_MKFS 0 #define _USE_MKFS 0
/* To enable f_mkfs function, set _USE_MKFS to 1 and set _FS_READONLY to 0 */ /*
* To enable f_mkfs function, set _USE_MKFS to 1 and set _FS_READONLY to 0
*/
#define _USE_FORWARD 0 #define _USE_FORWARD 0
/* To enable f_forward function, set _USE_FORWARD to 1 and set _FS_TINY to 1. */ /*
* To enable f_forward function, set _USE_FORWARD to 1 and set _FS_TINY to 1.
*/
#define _DRIVES 1 #define _DRIVES 1
/* Number of volumes (logical drives) to be used. */ /*
* Number of volumes (logical drives) to be used.
*/
#define _MAX_SS 512 #define _MAX_SS 512
/* Maximum sector size to be handled. (512/1024/2048/4096) */ /*
/* 512 for memroy card and hard disk, 1024 for floppy disk, 2048 for MO disk */ * Maximum sector size to be handled. (512/1024/2048/4096)
*/
/*
* 512 for memroy card and hard disk, 1024 for floppy disk, 2048 for MO disk
*/
#define _MULTI_PARTITION 0 #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, * When _MULTI_PARTITION is set to 0, each volume is bound to the same physical / drive number and can mount only first primaly partition.
/ each volume is tied to the partitions listed in Drives[]. */ * When it is set to 1, / each volume is tied to the partitions listed in Drives[].
*/
#define _CODE_PAGE 437 #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 * 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
/ pages. When LFN is enabled, the code page must always be set correctly. * between SBCS code / pages. When LFN is enabled, the code page must always be set correctly. / 437 - U.S. / 720 - Arabic / 737 - Greek /
/ 437 - U.S. * 775 - Baltic / 850 - Multilingual Latin 1 / 852 - Latin 2 / 855 - Cyrillic / 857 - Turkish / 858 - Multilingual Latin 1 + Euro / 862 -
/ 720 - Arabic * Hebrew / 866 - Russian / 874 - Thai / 932 - Japanese Shift-JIS (DBCS) / 936 - Simplified Chinese GBK (DBCS) / 949 - Korean (DBCS) / 950
/ 737 - Greek * - Traditional Chinese Big5 (DBCS) / 1258 - Vietnam
/ 775 - Baltic */
/ 850 - Multilingual Latin 1
/ 852 - Latin 2
/ 855 - Cyrillic
/ 857 - Turkish
/ 858 - Multilingual Latin 1 + Euro
/ 862 - Hebrew
/ 866 - Russian
/ 874 - Thai
/ 932 - Japanese Shift-JIS (DBCS)
/ 936 - Simplified Chinese GBK (DBCS)
/ 949 - Korean (DBCS)
/ 950 - Traditional Chinese Big5 (DBCS)
/ 1258 - Vietnam
*/
#define _USE_LFN 0 #define _USE_LFN 0
#define _MAX_LFN 255 /* Maximum LFN length to handle (max:255) */ #define _MAX_LFN 255 /* Maximum LFN length to handle (max:255) */
/* The _USE_LFN option switches the LFN support. /*
/ * The _USE_LFN option switches the LFN support. / / 0: Disable LFN. / 1: Enable LFN with static working buffer on the bss. NOT REENTRANT.
/ 0: Disable LFN. * / 2: Enable LFN with dynamic working buffer on the caller's STACK. / / The working buffer occupies (_MAX_LFN + 1) * 2 bytes. When enable
/ 1: Enable LFN with static working buffer on the bss. NOT REENTRANT. * LFN, / a Unicode - OEM code conversion function ff_convert() must be added to / the project.
/ 2: Enable LFN with dynamic working buffer on the caller's STACK. */
/
/ The working buffer occupies (_MAX_LFN + 1) * 2 bytes. When enable LFN,
/ a Unicode - OEM code conversion function ff_convert() must be added to
/ the project. */
#define _FS_REENTRANT 0 #define _FS_REENTRANT 0
#define _TIMEOUT 1000 /* Timeout period in unit of time ticks */ #define _TIMEOUT 1000 /* Timeout period in unit of time ticks */
#define _SYNC_t HANDLE /* Type of sync object used on the OS. */ #define _SYNC_t HANDLE /* Type of sync object used on the OS. */
/* e.g. HANDLE, OS_EVENT*, ID and etc.. */ /*
/* To make the FatFs module re-entrant, set _FS_REENTRANT to 1 and add user * e.g. HANDLE, OS_EVENT*, ID and etc..
/ provided synchronization handlers, ff_req_grant, ff_rel_grant, */
/ ff_del_syncobj and ff_cre_syncobj function to the project. */ /*
* To make the FatFs module re-entrant, set _FS_REENTRANT to 1 and add user / provided synchronization handlers, ff_req_grant,
* ff_rel_grant, / ff_del_syncobj and ff_cre_syncobj function to the project.
*/
/* End of configuration options. Do not change followings without care. */ /*
* End of configuration options. Do not change followings without care.
*/
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
/* Definitions corresponds to multiple sector size */ /*
* Definitions corresponds to multiple sector size
*/
#if _MAX_SS == 512 #if _MAX_SS == 512
#define SS(fs) 512 #define SS(fs) 512
@ -153,112 +151,122 @@
/* File system object structure */ /*
* File system object structure
*/
typedef struct _FATFS { typedef struct _FATFS {
BYTE fs_type; /* FAT sub type */ BYTE fs_type; /* FAT sub type */
BYTE drive; /* Physical drive number */ BYTE drive; /* Physical drive number */
BYTE csize; /* Number of sectors per cluster */ BYTE csize; /* Number of sectors per cluster */
BYTE n_fats; /* Number of FAT copies */ BYTE n_fats; /* Number of FAT copies */
BYTE wflag; /* win[] dirty flag (1:must be written back) */ BYTE wflag; /* win[] dirty flag (1:must be written back) */
BYTE pad1; BYTE pad1;
WORD id; /* File system mount ID */ WORD id; /* File system mount ID */
WORD n_rootdir; /* Number of root directory entries (0 on FAT32) */ WORD n_rootdir; /* Number of root directory entries (0 on FAT32) */
#if _FS_REENTRANT #if _FS_REENTRANT
_SYNC_t sobj; /* Identifier of sync object */ _SYNC_t sobj; /* Identifier of sync object */
#endif #endif
#if _MAX_SS != 512U #if _MAX_SS != 512U
WORD s_size; /* Sector size */ WORD s_size; /* Sector size */
#endif #endif
#if !_FS_READONLY #if !_FS_READONLY
BYTE fsi_flag; /* fsinfo dirty flag (1:must be written back) */ BYTE fsi_flag; /* fsinfo dirty flag (1:must be written back) */
BYTE pad2; BYTE pad2;
DWORD last_clust; /* Last allocated cluster */ DWORD last_clust; /* Last allocated cluster */
DWORD free_clust; /* Number of free clusters */ DWORD free_clust; /* Number of free clusters */
DWORD fsi_sector; /* fsinfo sector */ DWORD fsi_sector; /* fsinfo sector */
#endif #endif
DWORD sects_fat; /* Sectors per fat */ DWORD sects_fat; /* Sectors per fat */
DWORD max_clust; /* Maximum cluster# + 1. Number of clusters is max_clust - 2 */ DWORD max_clust; /* Maximum cluster# + 1. Number of clusters is max_clust - 2 */
DWORD fatbase; /* FAT start sector */ DWORD fatbase; /* FAT start sector */
DWORD dirbase; /* Root directory start sector (Cluster# on FAT32) */ DWORD dirbase; /* Root directory start sector (Cluster# on FAT32) */
DWORD database; /* Data start sector */ DWORD database; /* Data start sector */
DWORD winsect; /* Current sector appearing in the win[] */ DWORD winsect; /* Current sector appearing in the win[] */
BYTE win[_MAX_SS];/* Disk access window for Directory/FAT */ BYTE win[_MAX_SS]; /* Disk access window for Directory/FAT */
} FATFS; } FATFS;
/* Directory object structure */ /*
* Directory object structure
*/
typedef struct _DIR { typedef struct _DIR {
WORD id; /* Owner file system mount ID */ WORD id; /* Owner file system mount ID */
WORD index; /* Current index number */ WORD index; /* Current index number */
FATFS* fs; /* Pointer to the owner file system object */ FATFS *fs; /* Pointer to the owner file system object */
DWORD sclust; /* Table start cluster (0:Static table) */ DWORD sclust; /* Table start cluster (0:Static table) */
DWORD clust; /* Current cluster */ DWORD clust; /* Current cluster */
DWORD sect; /* Current sector */ DWORD sect; /* Current sector */
BYTE* dir; /* Pointer to the current SFN entry in the win[] */ BYTE *dir; /* Pointer to the current SFN entry in the win[] */
BYTE* fn; /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */ BYTE *fn; /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */
#if _USE_LFN #if _USE_LFN
WCHAR* lfn; /* Pointer to the LFN working buffer */ WCHAR *lfn; /* Pointer to the LFN working buffer */
WORD lfn_idx; /* Last matched LFN index (0xFFFF:No LFN) */ WORD lfn_idx; /* Last matched LFN index (0xFFFF:No LFN) */
#endif #endif
} DIR; } DIR;
/* File object structure */ /*
* File object structure
*/
typedef struct _FIL { typedef struct _FIL {
FATFS* fs; /* Pointer to the owner file system object */ FATFS *fs; /* Pointer to the owner file system object */
WORD id; /* Owner file system mount ID */ WORD id; /* Owner file system mount ID */
BYTE flag; /* File status flags */ BYTE flag; /* File status flags */
BYTE csect; /* Sector address in the cluster */ BYTE csect; /* Sector address in the cluster */
DWORD fptr; /* File R/W pointer */ DWORD fptr; /* File R/W pointer */
DWORD fsize; /* File size */ DWORD fsize; /* File size */
DWORD org_clust; /* File start cluster */ DWORD org_clust; /* File start cluster */
DWORD curr_clust; /* Current cluster */ DWORD curr_clust; /* Current cluster */
DWORD dsect; /* Current data sector */ DWORD dsect; /* Current data sector */
#if !_FS_READONLY #if !_FS_READONLY
DWORD dir_sect; /* Sector containing the directory entry */ DWORD dir_sect; /* Sector containing the directory entry */
BYTE* dir_ptr; /* Ponter to the directory entry in the window */ BYTE *dir_ptr; /* Ponter to the directory entry in the window */
#endif #endif
#if !_FS_TINY #if !_FS_TINY
BYTE buf[_MAX_SS];/* File R/W buffer */ BYTE buf[_MAX_SS]; /* File R/W buffer */
#endif #endif
} FIL; } FIL;
/* File status structure */ /*
* File status structure
*/
typedef struct _FILINFO { typedef struct _FILINFO {
DWORD fsize; /* File size */ DWORD fsize; /* File size */
WORD fdate; /* Last modified date */ WORD fdate; /* Last modified date */
WORD ftime; /* Last modified time */ WORD ftime; /* Last modified time */
BYTE fattrib; /* Attribute */ BYTE fattrib; /* Attribute */
char fname[13]; /* Short file name (8.3 format) */ char fname[13]; /* Short file name (8.3 format) */
#if _USE_LFN #if _USE_LFN
char *lfname; /* Pointer to the LFN buffer */ char *lfname; /* Pointer to the LFN buffer */
int lfsize; /* Size of LFN buffer [bytes] */ int lfsize; /* Size of LFN buffer [bytes] */
#endif #endif
} FILINFO; } FILINFO;
/* DBCS code ranges */ /*
* DBCS code ranges
*/
#if _CODE_PAGE == 932 /* CP932 (Japanese Shift-JIS) */ #if _CODE_PAGE == 932 /* CP932 (Japanese Shift-JIS) */
#define _DF1S 0x81 /* DBC 1st byte range 1 start */ #define _DF1S 0x81 /* DBC 1st byte range 1 start */
#define _DF1E 0x9F /* DBC 1st byte range 1 end */ #define _DF1E 0x9F /* DBC 1st byte range 1 end */
#define _DF2S 0xE0 /* DBC 1st byte range 2 start */ #define _DF2S 0xE0 /* DBC 1st byte range 2 start */
#define _DF2E 0xFC /* DBC 1st byte range 2 end */ #define _DF2E 0xFC /* DBC 1st byte range 2 end */
#define _DS1S 0x40 /* DBC 2nd byte range 1 start */ #define _DS1S 0x40 /* DBC 2nd byte range 1 start */
#define _DS1E 0x7E /* DBC 2nd byte range 1 end */ #define _DS1E 0x7E /* DBC 2nd byte range 1 end */
#define _DS2S 0x80 /* DBC 2nd byte range 2 start */ #define _DS2S 0x80 /* DBC 2nd byte range 2 start */
#define _DS2E 0xFC /* DBC 2nd byte range 2 end */ #define _DS2E 0xFC /* DBC 2nd byte range 2 end */
#elif _CODE_PAGE == 936 /* CP936 (Simplified Chinese GBK) */ #elif _CODE_PAGE == 936 /* CP936 (Simplified Chinese GBK) */
#define _DF1S 0x81 #define _DF1S 0x81
#define _DF1E 0xFE #define _DF1E 0xFE
#define _DS1S 0x40 #define _DS1S 0x40
@ -266,7 +274,7 @@ typedef struct _FILINFO {
#define _DS2S 0x80 #define _DS2S 0x80
#define _DS2E 0xFE #define _DS2E 0xFE
#elif _CODE_PAGE == 949 /* CP949 (Korean) */ #elif _CODE_PAGE == 949 /* CP949 (Korean) */
#define _DF1S 0x81 #define _DF1S 0x81
#define _DF1E 0xFE #define _DF1E 0xFE
#define _DS1S 0x41 #define _DS1S 0x41
@ -276,7 +284,7 @@ typedef struct _FILINFO {
#define _DS3S 0x81 #define _DS3S 0x81
#define _DS3E 0xFE #define _DS3E 0xFE
#elif _CODE_PAGE == 950 /* CP950 (Traditional Chinese Big5) */ #elif _CODE_PAGE == 950 /* CP950 (Traditional Chinese Big5) */
#define _DF1S 0x81 #define _DF1S 0x81
#define _DF1E 0xFE #define _DF1E 0xFE
#define _DS1S 0x40 #define _DS1S 0x40
@ -284,116 +292,124 @@ typedef struct _FILINFO {
#define _DS2S 0xA1 #define _DS2S 0xA1
#define _DS2E 0xFE #define _DS2E 0xFE
#else /* SBCS code pages */ #else /* SBCS code pages */
#define _DF1S 0 #define _DF1S 0
#endif #endif
/* Character code support macros */ /*
* Character code support macros
*/
#define IsUpper(c) (((c)>='A')&&((c)<='Z')) #define IsUpper(c) (((c)>='A')&&((c)<='Z'))
#define IsLower(c) (((c)>='a')&&((c)<='z')) #define IsLower(c) (((c)>='a')&&((c)<='z'))
#define IsDigit(c) (((c)>='0')&&((c)<='9')) #define IsDigit(c) (((c)>='0')&&((c)<='9'))
#if _DF1S /* DBCS configuration */ #if _DF1S /* DBCS configuration */
#if _DF2S /* Two 1st byte areas */ #if _DF2S /* Two 1st byte areas */
#define IsDBCS1(c) (((BYTE)(c) >= _DF1S && (BYTE)(c) <= _DF1E) || ((BYTE)(c) >= _DF2S && (BYTE)(c) <= _DF2E)) #define IsDBCS1(c) (((BYTE)(c) >= _DF1S && (BYTE)(c) <= _DF1E) || ((BYTE)(c) >= _DF2S && (BYTE)(c) <= _DF2E))
#else /* One 1st byte area */ #else /* One 1st byte area */
#define IsDBCS1(c) ((BYTE)(c) >= _DF1S && (BYTE)(c) <= _DF1E) #define IsDBCS1(c) ((BYTE)(c) >= _DF1S && (BYTE)(c) <= _DF1E)
#endif #endif
#if _DS3S /* Three 2nd byte areas */ #if _DS3S /* Three 2nd byte areas */
#define IsDBCS2(c) (((BYTE)(c) >= _DS1S && (BYTE)(c) <= _DS1E) || ((BYTE)(c) >= _DS2S && (BYTE)(c) <= _DS2E) || ((BYTE)(c) >= _DS3S && (BYTE)(c) <= _DS3E)) #define IsDBCS2(c) (((BYTE)(c) >= _DS1S && (BYTE)(c) <= _DS1E) || ((BYTE)(c) >= _DS2S && (BYTE)(c) <= _DS2E) || ((BYTE)(c) >= _DS3S && (BYTE)(c) <= _DS3E))
#else /* Two 2nd byte areas */ #else /* Two 2nd byte areas */
#define IsDBCS2(c) (((BYTE)(c) >= _DS1S && (BYTE)(c) <= _DS1E) || ((BYTE)(c) >= _DS2S && (BYTE)(c) <= _DS2E)) #define IsDBCS2(c) (((BYTE)(c) >= _DS1S && (BYTE)(c) <= _DS1E) || ((BYTE)(c) >= _DS2S && (BYTE)(c) <= _DS2E))
#endif #endif
#else /* SBCS configuration */ #else /* SBCS configuration */
#define IsDBCS1(c) 0 #define IsDBCS1(c) 0
#define IsDBCS2(c) 0 #define IsDBCS2(c) 0
#endif /* _DF1S */ #endif /* _DF1S */
/* Definitions corresponds to multi partition */ /*
* Definitions corresponds to multi partition
*/
#if _MULTI_PARTITION /* Multiple partition configuration */ #if _MULTI_PARTITION /* Multiple partition configuration */
typedef struct _PARTITION { typedef struct _PARTITION {
BYTE pd; /* Physical drive# */ BYTE pd; /* Physical drive# */
BYTE pt; /* Partition # (0-3) */ BYTE pt; /* Partition # (0-3) */
} PARTITION; } PARTITION;
extern extern
const PARTITION Drives[]; /* Logical drive# to physical location conversion table */ const PARTITION Drives[]; /* Logical drive# to physical location conversion table */
#define LD2PD(drv) (Drives[drv].pd) /* Get physical drive# */ #define LD2PD(drv) (Drives[drv].pd) /* Get physical drive# */
#define LD2PT(drv) (Drives[drv].pt) /* Get partition# */ #define LD2PT(drv) (Drives[drv].pt) /* Get partition# */
#else /* Single partition configuration */ #else /* Single partition configuration */
#define LD2PD(drv) (drv) /* Physical drive# is equal to the logical drive# */ #define LD2PD(drv) (drv) /* Physical drive# is equal to the logical drive# */
#define LD2PT(drv) 0 /* Always mounts the 1st partition */ #define LD2PT(drv) 0 /* Always mounts the 1st partition */
#endif #endif
/* File function return code (FRESULT) */ /*
* File function return code (FRESULT)
*/
typedef enum { typedef enum {
FR_OK = 0, /* 0 */ FR_OK = 0, /* 0 */
FR_DISK_ERR, /* 1 */ FR_DISK_ERR, /* 1 */
FR_INT_ERR, /* 2 */ FR_INT_ERR, /* 2 */
FR_NOT_READY, /* 3 */ FR_NOT_READY, /* 3 */
FR_NO_FILE, /* 4 */ FR_NO_FILE, /* 4 */
FR_NO_PATH, /* 5 */ FR_NO_PATH, /* 5 */
FR_INVALID_NAME, /* 6 */ FR_INVALID_NAME, /* 6 */
FR_DENIED, /* 7 */ FR_DENIED, /* 7 */
FR_EXIST, /* 8 */ FR_EXIST, /* 8 */
FR_INVALID_OBJECT, /* 9 */ FR_INVALID_OBJECT, /* 9 */
FR_WRITE_PROTECTED, /* 10 */ FR_WRITE_PROTECTED, /* 10 */
FR_INVALID_DRIVE, /* 11 */ FR_INVALID_DRIVE, /* 11 */
FR_NOT_ENABLED, /* 12 */ FR_NOT_ENABLED, /* 12 */
FR_NO_FILESYSTEM, /* 13 */ FR_NO_FILESYSTEM, /* 13 */
FR_MKFS_ABORTED, /* 14 */ FR_MKFS_ABORTED, /* 14 */
FR_TIMEOUT /* 15 */ FR_TIMEOUT /* 15 */
} FRESULT; } FRESULT;
/*--------------------------------------------------------------*/ /*--------------------------------------------------------------*/
/* FatFs module application interface */ /*
* FatFs module application interface
*/
FRESULT f_mount (BYTE, FATFS*); /* Mount/Unmount a logical drive */ FRESULT f_mount(BYTE, FATFS *); /* Mount/Unmount a logical drive */
FRESULT f_open (FIL*, const char*, BYTE); /* Open or create a file */ FRESULT f_open(FIL *, const char *, BYTE); /* Open or create a file */
FRESULT f_read (FIL*, void*, UINT, UINT*); /* Read data from a file */ FRESULT f_read(FIL *, void *, UINT, UINT *); /* Read data from a file */
FRESULT f_write (FIL*, const void*, UINT, UINT*); /* Write data to a file */ FRESULT f_write(FIL *, const void *, UINT, UINT *); /* Write data to a file */
FRESULT f_lseek (FIL*, DWORD); /* Move file pointer of a file object */ FRESULT f_lseek(FIL *, DWORD); /* Move file pointer of a file object */
FRESULT f_close (FIL*); /* Close an open file object */ FRESULT f_close(FIL *); /* Close an open file object */
FRESULT f_opendir (DIR*, const char*); /* Open an existing directory */ FRESULT f_opendir(DIR *, const char *); /* Open an existing directory */
FRESULT f_readdir (DIR*, FILINFO*); /* Read a directory item */ FRESULT f_readdir(DIR *, FILINFO *); /* Read a directory item */
FRESULT f_stat (const char*, FILINFO*); /* Get file status */ FRESULT f_stat(const char *, FILINFO *); /* Get file status */
FRESULT f_getfree (const char*, DWORD*, FATFS**); /* Get number of free clusters on the drive */ FRESULT f_getfree(const char *, DWORD *, FATFS **); /* Get number of free clusters on the drive */
FRESULT f_truncate (FIL*); /* Truncate file */ FRESULT f_truncate(FIL *); /* Truncate file */
FRESULT f_sync (FIL*); /* Flush cached data of a writing file */ FRESULT f_sync(FIL *); /* Flush cached data of a writing file */
FRESULT f_unlink (const char*); /* Delete an existing file or directory */ FRESULT f_unlink(const char *); /* Delete an existing file or directory */
FRESULT f_mkdir (const char*); /* Create a new directory */ FRESULT f_mkdir(const char *); /* Create a new directory */
FRESULT f_chmod (const char*, BYTE, BYTE); /* Change attriburte of the file/dir */ FRESULT f_chmod(const char *, BYTE, BYTE); /* Change attriburte of the file/dir */
FRESULT f_utime (const char*, const FILINFO*); /* Change timestamp of the file/dir */ FRESULT f_utime(const char *, const FILINFO *); /* Change timestamp of the file/dir */
FRESULT f_rename (const char*, const char*); /* Rename/Move a file or directory */ FRESULT f_rename(const char *, const char *); /* Rename/Move a file or directory */
FRESULT f_forward (FIL*, UINT(*)(const BYTE*,UINT), UINT, UINT*); /* Forward data to the stream */ FRESULT f_forward(FIL *, UINT(*)(const BYTE *, UINT), UINT, UINT *); /* Forward data to the stream */
FRESULT f_mkfs (BYTE, BYTE, WORD); /* Create a file system on the drive */ FRESULT f_mkfs(BYTE, BYTE, WORD); /* Create a file system on the drive */
#if _USE_STRFUNC #if _USE_STRFUNC
int f_putc (int, FIL*); /* Put a character to the file */ int f_putc(int, FIL *); /* Put a character to the file */
int f_puts (const char*, FIL*); /* Put a string to the file */ int f_puts(const char *, FIL *); /* Put a string to the file */
int f_printf (FIL*, const char*, ...); /* Put a formatted string to the file */ int f_printf(FIL *, const char *, ...); /* Put a formatted string to the file */
char* f_gets (char*, int, FIL*); /* Get a string from the file */ char *f_gets(char *, int, FIL *); /* Get a string from the file */
#define f_eof(fp) (((fp)->fptr == (fp)->fsize) ? 1 : 0) #define f_eof(fp) (((fp)->fptr == (fp)->fsize) ? 1 : 0)
#define f_error(fp) (((fp)->flag & FA__ERROR) ? 1 : 0) #define f_error(fp) (((fp)->flag & FA__ERROR) ? 1 : 0)
#ifndef EOF #ifndef EOF
@ -404,22 +420,32 @@ char* f_gets (char*, int, FIL*); /* Get a string from the file */
/*--------------------------------------------------------------*/ /*--------------------------------------------------------------*/
/* User defined functions */ /*
* User defined functions
*/
/* Real time clock */ /*
* Real time clock
*/
#if !_FS_READONLY #if !_FS_READONLY
DWORD get_fattime (void); /* 31-25: Year(0-127 org.1980), 24-21: Month(1-12), 20-16: Day(1-31) */ DWORD get_fattime(void); /* 31-25: Year(0-127 org.1980), 24-21: Month(1-12), 20-16: Day(1-31) */
/* 15-11: Hour(0-23), 10-5: Minute(0-59), 4-0: Second(0-29 *2) */ /*
* 15-11: Hour(0-23), 10-5: Minute(0-59), 4-0: Second(0-29 *2)
*/
#endif #endif
/* Unicode - OEM code conversion */ /*
* Unicode - OEM code conversion
*/
#if _USE_LFN #if _USE_LFN
WCHAR ff_convert (WCHAR, UINT); WCHAR ff_convert(WCHAR, UINT);
#endif #endif
/* Sync functions */ /*
* Sync functions
*/
#if _FS_REENTRANT #if _FS_REENTRANT
BOOL ff_cre_syncobj(BYTE, _SYNC_t*); BOOL ff_cre_syncobj(BYTE, _SYNC_t *);
BOOL ff_del_syncobj(_SYNC_t); BOOL ff_del_syncobj(_SYNC_t);
BOOL ff_req_grant(_SYNC_t); BOOL ff_req_grant(_SYNC_t);
void ff_rel_grant(_SYNC_t); void ff_rel_grant(_SYNC_t);
@ -428,10 +454,14 @@ void ff_rel_grant(_SYNC_t);
/*--------------------------------------------------------------*/ /*--------------------------------------------------------------*/
/* Flags and offset address */ /*
* Flags and offset address
*/
/* File access control and file status flags (FIL.flag) */ /*
* File access control and file status flags (FIL.flag)
*/
#define FA_READ 0x01 #define FA_READ 0x01
#define FA_OPEN_EXISTING 0x00 #define FA_OPEN_EXISTING 0x00
@ -446,28 +476,33 @@ void ff_rel_grant(_SYNC_t);
#define FA__ERROR 0x80 #define FA__ERROR 0x80
/* FAT sub type (FATFS.fs_type) */ /*
* FAT sub type (FATFS.fs_type)
*/
#define FS_FAT12 1 #define FS_FAT12 1
#define FS_FAT16 2 #define FS_FAT16 2
#define FS_FAT32 3 #define FS_FAT32 3
/* File attribute bits for directory entry */ /*
* File attribute bits for directory entry
*/
#define AM_RDO 0x01 /* Read only */ #define AM_RDO 0x01 /* Read only */
#define AM_HID 0x02 /* Hidden */ #define AM_HID 0x02 /* Hidden */
#define AM_SYS 0x04 /* System */ #define AM_SYS 0x04 /* System */
#define AM_VOL 0x08 /* Volume label */ #define AM_VOL 0x08 /* Volume label */
#define AM_LFN 0x0F /* LFN entry */ #define AM_LFN 0x0F /* LFN entry */
#define AM_DIR 0x10 /* Directory */ #define AM_DIR 0x10 /* Directory */
#define AM_ARC 0x20 /* Archive */ #define AM_ARC 0x20 /* Archive */
#define AM_MASK 0x3F /* Mask of defined bits */ #define AM_MASK 0x3F /* Mask of defined bits */
/* FatFs refers the members in the FAT structures with byte offset instead /*
/ of structure member because there are incompatibility of the packing option * FatFs refers the members in the FAT structures with byte offset instead / of structure member because there are incompatibility of the
/ between various compilers. */ * packing option / between various compilers.
*/
#define BS_jmpBoot 0 #define BS_jmpBoot 0
#define BS_OEMName 3 #define BS_OEMName 3
@ -529,14 +564,16 @@ void ff_rel_grant(_SYNC_t);
/*--------------------------------*/ /*--------------------------------*/
/* Multi-byte word access macros */ /*
* Multi-byte word access macros
*/
#if _WORD_ACCESS == 1 /* Enable word access to the FAT structure */ #if _WORD_ACCESS == 1 /* Enable word access to the FAT structure */
#define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr)) #define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr))
#define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr)) #define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr))
#define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val) #define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val)
#define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val) #define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val)
#else /* Use byte-by-byte access to the FAT structure */ #else /* Use byte-by-byte access to the FAT structure */
#define LD_WORD(ptr) (WORD)(((WORD)*(BYTE*)((ptr)+1)<<8)|(WORD)*(BYTE*)(ptr)) #define LD_WORD(ptr) (WORD)(((WORD)*(BYTE*)((ptr)+1)<<8)|(WORD)*(BYTE*)(ptr))
#define LD_DWORD(ptr) (DWORD)(((DWORD)*(BYTE*)((ptr)+3)<<24)|((DWORD)*(BYTE*)((ptr)+2)<<16)|((WORD)*(BYTE*)((ptr)+1)<<8)|*(BYTE*)(ptr)) #define LD_DWORD(ptr) (DWORD)(((DWORD)*(BYTE*)((ptr)+3)<<24)|((DWORD)*(BYTE*)((ptr)+2)<<16)|((WORD)*(BYTE*)((ptr)+1)<<8)|*(BYTE*)(ptr))
#define ST_WORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *(BYTE*)((ptr)+1)=(BYTE)((WORD)(val)>>8) #define ST_WORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *(BYTE*)((ptr)+1)=(BYTE)((WORD)(val)>>8)
@ -544,4 +581,4 @@ void ff_rel_grant(_SYNC_t);
#endif #endif
#endif /* _FATFS */ #endif /* _FATFS */

View File

@ -1,31 +1,43 @@
/*-------------------------------------------*/ /*-------------------------------------------*/
/* Integer type definitions for FatFs module */ /*
* Integer type definitions for FatFs module
*/
/*-------------------------------------------*/ /*-------------------------------------------*/
#ifndef _INTEGER #ifndef _INTEGER
/* These types must be 16-bit, 32-bit or larger integer */ /*
typedef int INT; * These types must be 16-bit, 32-bit or larger integer
typedef unsigned int UINT; */
typedef int INT;
typedef unsigned int UINT;
/* These types must be 8-bit integer */ /*
typedef signed char CHAR; * These types must be 8-bit integer
typedef unsigned char UCHAR; */
typedef unsigned char BYTE; typedef signed char CHAR;
typedef unsigned char UCHAR;
typedef unsigned char BYTE;
/* These types must be 16-bit integer */ /*
typedef short SHORT; * These types must be 16-bit integer
typedef unsigned short USHORT; */
typedef unsigned short WORD; typedef short SHORT;
typedef unsigned short WCHAR; typedef unsigned short USHORT;
typedef unsigned short WORD;
typedef unsigned short WCHAR;
/* These types must be 32-bit integer */ /*
typedef long LONG; * These types must be 32-bit integer
typedef unsigned long ULONG; */
typedef unsigned long DWORD; typedef long LONG;
typedef unsigned long ULONG;
typedef unsigned long DWORD;
/* Boolean type */ /*
* Boolean type
*/
// enum { false = 0 , true } bool; // enum { false = 0 , true } bool;
typedef int BOOL; typedef int BOOL;

View File

@ -13,110 +13,103 @@
#include "debug.h" #include "debug.h"
#include "crc.h" #include "crc.h"
/* /*
* o debug STA global o optimize internal transfer buffer o direct write to mempage o relocate main code o exec loaded file
*/
o debug STA global // #pragma section CODE=BANK2,offset $2:0000
o optimize internal transfer buffer
o direct write to mempage
o relocate main code
o exec loaded file
*/
//#pragma section CODE=BANK2,offset $2:0000
#define ROM_NAME "MRDO.SMC" #define ROM_NAME "MRDO.SMC"
//#define ROM_NAME "TEST.TXT" // #define ROM_NAME "TEST.TXT"
#define BLOCK_SIZE 512 #define BLOCK_SIZE 512
#define BASE_ADDR 0x008000 #define BASE_ADDR 0x008000
padStatus pad1; padStatus pad1;
DWORD acc_size; /* Work register for fs command */ DWORD acc_size; /* Work register for fs command */
WORD acc_files, acc_dirs; WORD acc_files,
acc_dirs;
FILINFO finfo; FILINFO finfo;
FATFS fatfs[2]; /* File system object for each logical drive */ FATFS fatfs[2]; /* File system object for each logical * drive */
BYTE Buff[512]; /* Working buffer */ BYTE Buff[512]; /* Working buffer */
DWORD p1,
DWORD p1, p2, p3; p2,
p3;
DWORD addr; DWORD addr;
DWORD crc_addr; DWORD crc_addr;
UINT crc; UINT crc;
BYTE res,
BYTE res,bank; bank;
WORD w1; WORD w1;
UINT s1, s2, cnt; UINT s1,
s2,
cnt;
FATFS *fs; FATFS *fs;
DIR dir; /* Directory object */ DIR dir; /* Directory object */
FIL file1,file2; FIL file1,
file2;
void initInternalRegisters(void)
{
characterLocation[0] = 0x0000;
characterLocation[1] = 0x0000;
characterLocation[2] = 0x0000;
characterLocation[3] = 0x0000;
debug_init();
} void
preInit(void)
{
// For testing purpose ...
// Insert code here to be executed before register init
} DWORD get_fattime()
void initInternalRegisters(void) {
characterLocation[0] = 0x0000;
characterLocation[1] = 0x0000;
characterLocation[2] = 0x0000;
characterLocation[3] = 0x0000;
debug_init();
}
void preInit(void) {
// For testing purpose ...
// Insert code here to be executed before register init
}
DWORD get_fattime ()
{ {
time_t rawtime; time_t rawtime;
struct tm * ptm; struct tm *ptm;
//time ( &rawtime );
ptm = gmtime ( &rawtime );
return ((DWORD)(ptm->tm_year - 80) << 25) // time ( &rawtime );
| ((DWORD)(ptm->tm_mon +1) << 21) ptm = gmtime(&rawtime);
| ((DWORD)ptm->tm_mday << 16) return ((DWORD) (ptm->tm_year - 80) << 25)
| ((DWORD)ptm->tm_hour << 11) | ((DWORD) (ptm->tm_mon + 1) << 21)
| ((DWORD)ptm->tm_min << 5) | ((DWORD) ptm->tm_mday << 16)
| ((DWORD)ptm->tm_sec >> 1); | ((DWORD) ptm->tm_hour << 11)
| ((DWORD) ptm->tm_min << 5) | ((DWORD) ptm->tm_sec >> 1);
} }
void halt(void) { void halt(void)
while(1); {
while (1);
} }
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" "NO_PATH\0" "INVALID_NAME\0" "INVALID_DRIVE\0" "OK\0" "NOT_READY\0" "NO_FILE\0" "NO_PATH\0" "INVALID_NAME\0"
"DENIED\0" "EXIST\0" "RW_ERROR\0" "WRITE_PROTECTED\0" "NOT_ENABLED\0" "INVALID_DRIVE\0" "DENIED\0" "EXIST\0" "RW_ERROR\0"
"NO_FILESYSTEM\0" "INVALID_OBJECT\0" "MKFS_ABORTED\0"; "WRITE_PROTECTED\0" "NOT_ENABLED\0" "NO_FILESYSTEM\0"
"INVALID_OBJECT\0" "MKFS_ABORTED\0";
FRESULT i; FRESULT i;
for (p = str, i = 0; i != rc && *p; i++) { for (p = str, i = 0; i != rc && *p; i++) {
while(*p++); while (*p++);
} }
printfc("rc=%u FR_%s\n", (WORD)rc, p); printfc("rc=%u FR_%s\n", (WORD) rc, p);
} }
FRESULT scan_files(char *path)
FRESULT scan_files (char* path){ {
DIR dirs; DIR dirs;
FRESULT res; FRESULT res;
int i; int i;
if ((res = f_opendir(&dirs, path)) == FR_OK) { if ((res = f_opendir(&dirs, path)) == FR_OK) {
i = strlen(path); i = strlen(path);
while (((res = f_readdir(&dirs, &finfo)) == FR_OK) && finfo.fname[0]) { while (((res = f_readdir(&dirs, &finfo)) == FR_OK)
&& finfo.fname[0]) {
if (finfo.fattrib & AM_DIR) { if (finfo.fattrib & AM_DIR) {
acc_dirs++; acc_dirs++;
*(path+i) = '/'; strcpy(path+i+1, &finfo.fname[0]); *(path + i) = '/';
strcpy(path + i + 1, &finfo.fname[0]);
res = scan_files(path); res = scan_files(path);
*(path+i) = '\0'; *(path + i) = '\0';
if (res != FR_OK) break; if (res != FR_OK)
break;
} else { } else {
acc_files++; acc_files++;
acc_size += finfo.fsize; acc_size += finfo.fsize;
@ -126,41 +119,43 @@ FRESULT scan_files (char* path){
return res; return res;
} }
void wait(void){ void wait(void)
{
printfc("SNES::wait: press A to continue\n"); printfc("SNES::wait: press A to continue\n");
enablePad(); enablePad();
//waitForVBlank();
// waitForVBlank();
pad1 = readPad((byte) 0); pad1 = readPad((byte) 0);
while(!pad1.A) { while (!pad1.A) {
waitForVBlank(); waitForVBlank();
pad1 = readPad((byte) 0); pad1 = readPad((byte) 0);
} }
printfc("SNES::wait: done\n"); printfc("SNES::wait: done\n");
//disablePad();
// disablePad();
} }
void boot(void){ void boot(void)
#asm {
jsl $008000
#endasm
}
void main(void) { #asm
word i,j; jsl $008000
#endasm
} void
main(void)
{
word i,
j;
BYTE res; BYTE res;
initInternalRegisters(); initInternalRegisters();
*(byte *) 0x2105 = 0x01; // MODE 1 value
*(byte*) 0x2105 = 0x01; // MODE 1 value *(byte *) 0x212c = 0x01; // Plane 0 (bit one) enable register
*(byte*) 0x212c = 0x01; // Plane 0 (bit one) enable register *(byte *) 0x212d = 0x00; // All subPlane disable
*(byte*) 0x212d = 0x00; // All subPlane disable *(byte *) 0x2100 = 0x0f; // enable background
*(byte*) 0x2100 = 0x0f; // enable background
debug_enable(); debug_enable();
printfs(0, "FATFS OPTIXX.ORG ");
printfs(0,"FATFS OPTIXX.ORG ");
wait();
printfc("SNES::main: Try to init disk\n"); printfc("SNES::main: Try to init disk\n");
put_rc(f_mount(0, &fatfs[0])); put_rc(f_mount(0, &fatfs[0]));
#if 0 #if 0
@ -168,146 +163,138 @@ void main(void) {
res = f_getfree("", &p2, &fs); res = f_getfree("", &p2, &fs);
if (res) if (res)
put_rc(res); put_rc(res);
printfc("SNES::main: printf fs results\n"); printfc("SNES::main: printf fs results\n");
printfs(1,"FAT TYPE = %u\nBYTES/CLUSTER = %lu\nNUMBER OF FATS = %u\n" printfs(1,
"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,
fs->n_rootdir, (DWORD)fs->sects_fat, (DWORD)fs->max_clust - 2, (WORD) fs->n_fats, fs->n_rootdir, (DWORD) fs->sects_fat,
fs->fatbase, fs->dirbase, fs->database); (DWORD) fs->max_clust - 2, fs->fatbase, fs->dirbase, fs->database);
acc_size = acc_files = acc_dirs = 0; acc_size = acc_files = acc_dirs = 0;
printfc("SNES::main: scan files\n"); printfc("SNES::main: scan files\n");
res = scan_files(""); res = scan_files("");
if (res) if (res)
put_rc(res); put_rc(res);
printfs(12, "%u FILES, %lu BYTES\n%u FOLDERS\n"
printfs(12,"%u FILES, %lu BYTES\n%u FOLDERS\n" "%lu KB TOTAK DISK SPACE\n%lu KB AVAILABLE\n", acc_files,
"%lu KB TOTAK DISK SPACE\n%lu KB AVAILABLE\n", acc_size, acc_dirs, (fs->max_clust - 2) * (fs->csize / 2),
acc_files, acc_size, acc_dirs, p2 * (fs->csize / 2));
(fs->max_clust - 2) * (fs->csize / 2), p2 * (fs->csize / 2));
res = f_opendir(&dir, ""); res = f_opendir(&dir, "");
if (res) if (res)
put_rc(res); put_rc(res);
p1 = s1 = s2 = 0; p1 = s1 = s2 = 0;
cnt = 0; cnt = 0;
wait(); wait();
clears(); clears();
printfc("SNES::main: read dir\n"); printfc("SNES::main: read dir\n");
for(;;) { for (;;) {
res = f_readdir(&dir, &finfo); res = f_readdir(&dir, &finfo);
if ((res != FR_OK) || !finfo.fname[0]) break; if ((res != FR_OK) || !finfo.fname[0])
break;
if (finfo.fattrib & AM_DIR) { if (finfo.fattrib & AM_DIR) {
s2++; s2++;
} else { } else {
s1++; p1 += finfo.fsize; s1++;
p1 += finfo.fsize;
} }
; ;
printfs(cnt, "%c%c%c%c%c %u/%02u/%02u %02u:%02u %9lu\n%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]));
cnt += 2;
printfs(cnt,"%c%c%c%c%c %u/%02u/%02u %02u:%02u %9lu\n%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]));
cnt+=2;
/* /*
printfs(cnt,"%u/%02u/%02u %02u:%02u %9lu\n%s\n", * printfs(cnt,"%u/%02u/%02u %02u:%02u %9lu\n%s\n", (finfo.fdate >> 9) + 1980, (finfo.fdate >> 5) & 15, finfo.fdate & 31,
(finfo.fdate >> 9) + 1980, (finfo.fdate >> 5) & 15, finfo.fdate & 31, * (finfo.ftime >> 11), (finfo.ftime >> 5) & 63, finfo.fsize, &(finfo.fname[0]));
(finfo.ftime >> 11), (finfo.ftime >> 5) & 63, */
finfo.fsize, &(finfo.fname[0])); if (cnt && cnt == 20) {
*/ cnt = 0;
if (cnt && cnt==20){ wait();
cnt = 0; clears();
wait();
clears();
} }
} }
printfs(20, "%4u FILES\n%10lu BYTES TOTAL\n%4u DIRS", s1, p1, s2);
printfs(20,"%4u FILES\n%10lu BYTES TOTAL\n%4u DIRS", s1, p1, s2);
if (f_getfree("", &p1, &fs) == FR_OK) if (f_getfree("", &p1, &fs) == FR_OK)
printfs(23,"%10luK BYTES FREE\n", p1 * fs->csize / 2); printfs(23, "%10luK BYTES FREE\n", p1 * fs->csize / 2);
wait(); wait();
clears(); clears();
#endif
printfc("SNES::main: open %s \n",ROM_NAME); #endif /* */
printfs(0,"OPEN %s",ROM_NAME); printfc("SNES::main: open %s \n", ROM_NAME);
printfs(0, "OPEN %s", ROM_NAME);
put_rc(f_open(&file1, ROM_NAME, FA_READ)); put_rc(f_open(&file1, ROM_NAME, FA_READ));
p1 = 32768L * 8; p1 = 32768L * 8;
p2 = 0 ; p2 = 0;
p3 = 0; p3 = 0;
cnt = 0; cnt = 0;
bank =0; bank = 0;
addr = BASE_ADDR; addr = BASE_ADDR;
crc_addr = BASE_ADDR; crc_addr = BASE_ADDR;
while (p1) { while (p1) {
cnt = BLOCK_SIZE; cnt = BLOCK_SIZE;
p1 -= BLOCK_SIZE; p1 -= BLOCK_SIZE;
res = f_read(&file1, (byte*)(addr) , cnt, &s2); res = f_read(&file1, (byte *) (addr), cnt, &s2);
printfc("SNES::main: read cnt=%i p1=%li p2=%li s2=%i\n",cnt,p1,p2,s2); printfc("SNES::main: read cnt=%i p1=%li p2=%li s2=%i\n", cnt,
//printfc("SNES::main: file %x %x %x %x\n",Buff[0],Buff[1],Buff[2],Buff[3]); p1, p2, s2);
// printfc("SNES::main: file %x %x %x
// %x\n",Buff[0],Buff[1],Buff[2],Buff[3]);
if (res != FR_OK) { if (res != FR_OK) {
printfc("SNES::main: read failed\n"); printfc("SNES::main: read failed\n");
put_rc(res); put_rc(res);
break; break;
} }
p2 += s2; p2 += s2;
if (cnt != s2){ if (cnt != s2) {
printfc("SNES::main: read cnt=%i s2=%i\n",cnt,s2); printfc("SNES::main: read cnt=%i s2=%i\n", cnt, s2);
break; break;
} }
<<<<<<< HEAD:snes/fatfstest/main.c printfs(1 + bank, "BANK %X ADDR %LX", bank, addr);
printfs(1,"%lu BYTES READ", p2);
=======
printfs(1 + bank,"BANK %X ADDR %LX",bank,addr);
>>>>>>> c1203c3519d95a92e82a6f2ebf741ad663e46e33:snes/fatfstest/main.c
/* /*
for (i=0; i<BLOCK_SIZE; i++){ * for (i=0; i<BLOCK_SIZE; i++){ *(byte*)(addr + i) = Buff[i]; }
*(byte*)(addr + i) = Buff[i]; */
} printfc("SNES::main: mem %x %x %x %x %lx\n",
*/ *(byte *) (addr + 0), *(byte *) (addr + 1),
<<<<<<< HEAD:snes/fatfstest/main.c *(byte *) (addr + 2), *(byte *) (addr + 3), addr);
printfs(2,"%i BYTES TANS %x",BLOCK_SIZE, 0x020000 + p2);
=======
printfc("SNES::main: mem %x %x %x %x %lx\n",*(byte*)(addr + 0) ,*(byte*)(addr + 1) ,*(byte*)(addr + 2) ,*(byte*)(addr + 3) ,addr);
//if (addr=0x10fe00){
printc_packet(addr,512,(byte*)(addr)); // if (addr=0x10fe00){
printc_packet(addr, 512, (byte *) (addr));
//} // }
addr += s2;
if (addr % 0x10000 == 0) {
addr+=s2; // crc = crc_update_mem(crc_addr,0x8000);
if (addr%0x10000==0){ // printfc("addr=%lx crc=%x\n",crc_addr,crc);
//crc = crc_update_mem(crc_addr,0x8000); // printfs(1 + bank,"BANK %X ADDR %LX CRC
//printfc("addr=%lx crc=%x\n",crc_addr,crc); // %X",bank,addr,crc);
//printfs(1 + bank,"BANK %X ADDR %LX CRC %X",bank,addr,crc); addr += 0x8000;
addr+=0x8000;
//crc_addr+=0x8000; // crc_addr+=0x8000;
bank++; bank++;
} }
>>>>>>> c1203c3519d95a92e82a6f2ebf741ad663e46e33:snes/fatfstest/main.c
} }
put_rc(f_close(&file1)); put_rc(f_close(&file1));
boot(); boot();
while(1){ while (1) {
wait(); wait();
} }
while(1); while (1);
} }
void IRQHandler(void) { void IRQHandler(void)
} {
} void
NMIHandler(void)
{
void NMIHandler(void) { // processEvents();
//processEvents();
} }

View File

@ -1,18 +1,18 @@
typedef struct padStatus{ typedef struct padStatus {
byte right:1; byte right:1;
byte left:1; byte left:1;
byte down:1; byte down:1;
byte up:1; byte up:1;
byte start:1; // Enter byte start:1; // Enter
byte select:1; // Space byte select:1; // Space
byte Y:1; // X byte Y:1; // X
byte B:1; // C byte B:1; // C
//-------------------------------- // --------------------------------
byte Dummy:4; byte Dummy:4;
byte R:1; // Z byte R:1; // Z
byte L:1; // A byte L:1; // A
byte X:1; // S byte X:1; // S
byte A:1; // D byte A:1; // D
} padStatus; } padStatus;
extern void enablePad(void); extern void enablePad(void);