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 \
-Ahook=008000,0000 \
-N $(OBJS) hook.obj $(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 \ -Aressource=18000,8000 \
-Ahook=8000,0000 \ -Ahook=008000,0000 \
-N $(OBJS) $(LIBS) -O $@ -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

@ -6,4 +6,3 @@ 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

@ -15,10 +15,14 @@
#include "integer.h" #include "integer.h"
/* Status of Disk Functions */ /*
* Status of Disk Functions
*/
typedef BYTE DSTATUS; typedef BYTE DSTATUS;
/* Results of Disk Functions */ /*
* Results of Disk Functions
*/
typedef enum { typedef enum {
RES_OK = 0, /* 0: Successful */ RES_OK = 0, /* 0: Successful */
RES_ERROR, /* 1: R/W Error */ RES_ERROR, /* 1: R/W Error */
@ -29,7 +33,9 @@ typedef enum {
/*---------------------------------------*/ /*---------------------------------------*/
/* 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);
@ -43,7 +49,9 @@ 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 */
@ -51,9 +59,13 @@ void disk_timerproc (void);
#define STA_VOID 0xff #define STA_VOID 0xff
/* Command code for disk_ioctrl() */ /*
* Command code for disk_ioctrl()
*/
/* Generic command */ /*
* Generic command
*/
#define CTRL_SYNC 0 /* Mandatory for write functions */ #define CTRL_SYNC 0 /* Mandatory for write functions */
#define GET_SECTOR_COUNT 1 /* Mandatory for only f_mkfs() */ #define GET_SECTOR_COUNT 1 /* Mandatory for only f_mkfs() */
#define GET_SECTOR_SIZE 2 #define GET_SECTOR_SIZE 2

View File

@ -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),
int noDuplicateCallback);
extern void removeEvent(event * eventElement); 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,7 +151,9 @@
/* 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 */
@ -188,7 +188,9 @@ typedef struct _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 */
@ -207,7 +209,9 @@ typedef struct _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 */
@ -230,7 +234,9 @@ typedef struct _FIL {
/* File status structure */ /*
* File status structure
*/
typedef struct _FILINFO { typedef struct _FILINFO {
DWORD fsize; /* File size */ DWORD fsize; /* File size */
@ -246,7 +252,9 @@ typedef struct _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 */
@ -291,7 +299,9 @@ typedef struct _FILINFO {
/* 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'))
@ -320,7 +330,9 @@ typedef struct _FILINFO {
/* Definitions corresponds to multi partition */ /*
* Definitions corresponds to multi partition
*/
#if _MULTI_PARTITION /* Multiple partition configuration */ #if _MULTI_PARTITION /* Multiple partition configuration */
@ -343,7 +355,9 @@ const PARTITION Drives[]; /* Logical drive# to physical location conversion ta
/* File function return code (FRESULT) */ /*
* File function return code (FRESULT)
*/
typedef enum { typedef enum {
FR_OK = 0, /* 0 */ FR_OK = 0, /* 0 */
@ -367,7 +381,9 @@ typedef enum {
/*--------------------------------------------------------------*/ /*--------------------------------------------------------------*/
/* 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 */
@ -404,20 +420,30 @@ 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);
@ -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,14 +476,18 @@ 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 */
@ -465,9 +499,10 @@ void ff_rel_grant(_SYNC_t);
#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,7 +564,9 @@ 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))

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 */ /*
* These types must be 16-bit, 32-bit or larger integer
*/
typedef int INT; typedef int INT;
typedef unsigned int UINT; typedef unsigned int UINT;
/* These types must be 8-bit integer */ /*
* These types must be 8-bit integer
*/
typedef signed char CHAR; typedef signed char CHAR;
typedef unsigned char UCHAR; typedef unsigned char UCHAR;
typedef unsigned char BYTE; typedef unsigned char BYTE;
/* These types must be 16-bit integer */ /*
* These types must be 16-bit integer
*/
typedef short SHORT; typedef short SHORT;
typedef unsigned short USHORT; typedef unsigned short USHORT;
typedef unsigned short WORD; typedef unsigned short WORD;
typedef unsigned short WCHAR; typedef unsigned short WCHAR;
/* These types must be 32-bit integer */ /*
* These types must be 32-bit integer
*/
typedef long LONG; typedef long LONG;
typedef unsigned long ULONG; typedef unsigned long ULONG;
typedef unsigned long DWORD; 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

@ -14,12 +14,7 @@
#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
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 // #pragma section CODE=BANK2,offset $2:0000
@ -28,95 +23,93 @@ o exec loaded file
// #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)
{
void initInternalRegisters(void) {
characterLocation[0] = 0x0000; characterLocation[0] = 0x0000;
characterLocation[1] = 0x0000; characterLocation[1] = 0x0000;
characterLocation[2] = 0x0000; characterLocation[2] = 0x0000;
characterLocation[3] = 0x0000; characterLocation[3] = 0x0000;
debug_init(); debug_init();
} } void
preInit(void)
{
void preInit(void) {
// For testing purpose ... // For testing purpose ...
// Insert code here to be executed before register init // Insert code here to be executed before register init
} } DWORD get_fattime()
DWORD get_fattime ()
{ {
time_t rawtime; time_t rawtime;
struct tm *ptm; struct tm *ptm;
// time ( &rawtime ); // time ( &rawtime );
ptm = gmtime(&rawtime); ptm = gmtime(&rawtime);
return ((DWORD) (ptm->tm_year - 80) << 25) return ((DWORD) (ptm->tm_year - 80) << 25)
| ((DWORD) (ptm->tm_mon + 1) << 21) | ((DWORD) (ptm->tm_mon + 1) << 21)
| ((DWORD) ptm->tm_mday << 16) | ((DWORD) ptm->tm_mday << 16)
| ((DWORD) ptm->tm_hour << 11) | ((DWORD) ptm->tm_hour << 11)
| ((DWORD)ptm->tm_min << 5) | ((DWORD) ptm->tm_min << 5) | ((DWORD) ptm->tm_sec >> 1);
| ((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,9 +119,11 @@ 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) {
@ -136,31 +131,31 @@ void wait(void){
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 #asm
jsl $008000 jsl $008000
#endasm #endasm
} } void
main(void)
void main(void) { {
word i,j; 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,31 +163,26 @@ 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", "%lu KB TOTAK DISK SPACE\n%lu KB AVAILABLE\n", acc_files,
acc_files, acc_size, acc_dirs, acc_size, acc_dirs, (fs->max_clust - 2) * (fs->csize / 2),
(fs->max_clust - 2) * (fs->csize / 2), p2 * (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();
@ -200,29 +190,29 @@ void main(void) {
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", printfs(cnt, "%c%c%c%c%c %u/%02u/%02u %02u:%02u %9lu\n%s\n",
(finfo.fattrib & AM_DIR) ? 'D' : '-', (finfo.fattrib & AM_DIR) ? 'D' : '-',
(finfo.fattrib & AM_RDO) ? 'R' : '-', (finfo.fattrib & AM_RDO) ? 'R' : '-',
(finfo.fattrib & AM_HID) ? 'H' : '-', (finfo.fattrib & AM_HID) ? 'H' : '-',
(finfo.fattrib & AM_SYS) ? 'S' : '-', (finfo.fattrib & AM_SYS) ? 'S' : '-',
(finfo.fattrib & AM_ARC) ? 'A' : '-', (finfo.fattrib & AM_ARC) ? 'A' : '-',
(finfo.fdate >> 9) + 1980, (finfo.fdate >> 5) & 15, finfo.fdate & 31, (finfo.fdate >> 9) + 1980, (finfo.fdate >> 5) & 15,
(finfo.ftime >> 11), (finfo.ftime >> 5) & 63, finfo.fdate & 31, (finfo.ftime >> 11),
finfo.fsize, &(finfo.fname[0])); (finfo.ftime >> 5) & 63, finfo.fsize, &(finfo.fname[0]));
cnt += 2; 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) { if (cnt && cnt == 20) {
cnt = 0; cnt = 0;
@ -230,19 +220,16 @@ void main(void) {
clears(); 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
#endif /* */
printfc("SNES::main: open %s \n", ROM_NAME); printfc("SNES::main: open %s \n", ROM_NAME);
printfs(0, "OPEN %s", 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;
@ -254,8 +241,11 @@ void main(void) {
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);
@ -266,36 +256,31 @@ void main(void) {
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,"%lu BYTES READ", p2);
=======
printfs(1 + bank, "BANK %X ADDR %LX", bank, addr); printfs(1 + bank, "BANK %X ADDR %LX", bank, addr);
>>>>>>> c1203c3519d95a92e82a6f2ebf741ad663e46e33:snes/fatfstest/main.c
/*
for (i=0; i<BLOCK_SIZE; i++){
*(byte*)(addr + i) = Buff[i];
}
*/
<<<<<<< HEAD:snes/fatfstest/main.c
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){
/*
* for (i=0; i<BLOCK_SIZE; i++){ *(byte*)(addr + i) = Buff[i]; }
*/
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)); printc_packet(addr, 512, (byte *) (addr));
// } // }
addr += s2; addr += s2;
if (addr % 0x10000 == 0) { if (addr % 0x10000 == 0) {
// crc = crc_update_mem(crc_addr,0x8000); // crc = crc_update_mem(crc_addr,0x8000);
// printfc("addr=%lx crc=%x\n",crc_addr,crc); // printfc("addr=%lx crc=%x\n",crc_addr,crc);
//printfs(1 + bank,"BANK %X ADDR %LX 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();
@ -305,9 +290,11 @@ void main(void) {
while (1); while (1);
} }
void IRQHandler(void) { void IRQHandler(void)
} {
} void
NMIHandler(void)
{
void NMIHandler(void) {
// processEvents(); // processEvents();
} }