|
@@ -1,3 +1,7 @@
|
|
|
+#include <stdlib.h>
|
|
|
+#include <string.h>
|
|
|
+#include <time.h>
|
|
|
+
|
|
|
#include "data.h";
|
|
|
#include "pad.h";
|
|
|
#include "event.h";
|
|
@@ -5,27 +9,29 @@
|
|
|
#include "ressource.h";
|
|
|
#include "PPU.h"
|
|
|
#include "debug.h"
|
|
|
+#include "integer.h"
|
|
|
#include "ff.h"
|
|
|
|
|
|
|
|
|
-#include <stdlib.h>
|
|
|
-#include <string.h>
|
|
|
-#include <time.h>
|
|
|
-
|
|
|
padStatus pad1;
|
|
|
|
|
|
|
|
|
-WORD acc_size; /* Work register for fs command */
|
|
|
+DWORD acc_size; /* Work register for fs command */
|
|
|
WORD acc_files, acc_dirs;
|
|
|
+
|
|
|
FILINFO finfo;
|
|
|
+FATFS fatfs[2]; /* File system object for each logical drive */
|
|
|
+BYTE Buff[512]; /* Working buffer */
|
|
|
|
|
|
-FATFS fatfs[2]; /* File system object for each logical drive */
|
|
|
-BYTE buff[512]; /* Working buffer */
|
|
|
+DWORD p1, p2, p3;
|
|
|
+BYTE res;
|
|
|
+WORD w1;
|
|
|
+UINT s1, s2, cnt;
|
|
|
|
|
|
FATFS *fs;
|
|
|
-DIR dir; /* Directory object */
|
|
|
-FIL file1, file2; /* File object */
|
|
|
-DWORD p1, p2, p3;
|
|
|
+DIR dir; /* Directory object */
|
|
|
+FIL file1, file2; /* File object */
|
|
|
+
|
|
|
|
|
|
|
|
|
void initInternalRegisters(void) {
|
|
@@ -56,54 +62,49 @@ DWORD get_fattime ()
|
|
|
| ((DWORD)ptm->tm_sec >> 1);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-static
|
|
|
-FRESULT scan_files (char* path)
|
|
|
-{
|
|
|
- DIR dirs;
|
|
|
- FRESULT res;
|
|
|
- int i;
|
|
|
+void halt(void) {
|
|
|
+ while(1);
|
|
|
|
|
|
- if ((res = f_opendir(&dirs, path)) == FR_OK) {
|
|
|
- i = strlen(path);
|
|
|
- //printf("Ok\n");
|
|
|
- while (((res = f_readdir(&dirs, &finfo)) == FR_OK) && finfo.fname[0]) {
|
|
|
- if (finfo.fattrib & AM_DIR) {
|
|
|
- acc_dirs++;
|
|
|
- *(path+i) = '/'; strcpy(path+i+1, &finfo.fname[0]);
|
|
|
- res = scan_files(path);
|
|
|
- *(path+i) = '\0';
|
|
|
- if (res != FR_OK) break;
|
|
|
- } else {
|
|
|
- acc_files++;
|
|
|
- acc_size += finfo.fsize;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- print_console("scan_files ret\n");
|
|
|
- return res;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-void put_rc (FRESULT rc)
|
|
|
-{
|
|
|
- char *p;
|
|
|
- static char str[] =
|
|
|
- "OK\0" "NOT_READY\0" "NO_FILE\0" "FR_NO_PATH\0" "INVALID_NAME\0" "INVALID_DRIVE\0"
|
|
|
- "DENIED\0" "EXIST\0" "RW_ERROR\0" "WRITE_PROTECTED\0" "NOT_ENABLED\0"
|
|
|
- "NO_FILESYSTEM\0" "INVALID_OBJECT\0" "MKFS_ABORTED\0";
|
|
|
- FRESULT i;
|
|
|
-
|
|
|
- for (p = str, i = 0; i != rc && *p; i++) {
|
|
|
- while(*p++);
|
|
|
- }
|
|
|
- print_console(p);
|
|
|
+void put_rc (FRESULT rc){
|
|
|
+ const char *p;
|
|
|
+ static const char str[] =
|
|
|
+ "OK\0" "NOT_READY\0" "NO_FILE\0" "FR_NO_PATH\0" "INVALID_NAME\0" "INVALID_DRIVE\0"
|
|
|
+ "DENIED\0" "EXIST\0" "RW_ERROR\0" "WRITE_PROTECTED\0" "NOT_ENABLED\0"
|
|
|
+ "NO_FILESYSTEM\0" "INVALID_OBJECT\0" "MKFS_ABORTED\0";
|
|
|
+ FRESULT i;
|
|
|
+
|
|
|
+ for (p = str, i = 0; i != rc && *p; i++) {
|
|
|
+ while(*p++);
|
|
|
+ }
|
|
|
+ printfc("rc=%u FR_%s\n", (WORD)rc, p);
|
|
|
}
|
|
|
|
|
|
-void halt(void) {
|
|
|
- while(1);
|
|
|
-
|
|
|
+
|
|
|
+FRESULT scan_files (char* path){
|
|
|
+ DIR dirs;
|
|
|
+ FRESULT res;
|
|
|
+ int i;
|
|
|
+
|
|
|
+ if ((res = f_opendir(&dirs, path)) == FR_OK) {
|
|
|
+ i = strlen(path);
|
|
|
+ while (((res = f_readdir(&dirs, &finfo)) == FR_OK) && finfo.fname[0]) {
|
|
|
+ if (finfo.fattrib & AM_DIR) {
|
|
|
+ acc_dirs++;
|
|
|
+ *(path+i) = '/'; strcpy(path+i+1, &finfo.fname[0]);
|
|
|
+ res = scan_files(path);
|
|
|
+ *(path+i) = '\0';
|
|
|
+ if (res != FR_OK) break;
|
|
|
+ } else {
|
|
|
+ acc_files++;
|
|
|
+ acc_size += finfo.fsize;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return res;
|
|
|
}
|
|
|
+
|
|
|
void main(void) {
|
|
|
word i,j;
|
|
|
BYTE res;
|
|
@@ -114,46 +115,32 @@ void main(void) {
|
|
|
*(byte*) 0x2100 = 0x0f; // enable background
|
|
|
|
|
|
debug_enable();
|
|
|
- print_screen("FATFS TEST",0);
|
|
|
- print_console("mount ");
|
|
|
+ printfs(0,"FATFS ");
|
|
|
|
|
|
- put_rc(f_mount(0, &fatfs[0]));
|
|
|
+ printfc("Try to init disk\n");
|
|
|
+ put_rc(f_mount(0, &fatfs[p1]));
|
|
|
|
|
|
- print_console("disk_initialize \n");
|
|
|
- disk_initialize(0);
|
|
|
- print_console("disk_read \n");
|
|
|
- disk_read(0,buff,0xaabb,1);
|
|
|
- print_console("disk_done \n");
|
|
|
-
|
|
|
+ res = f_getfree("/", &p2, &fs);
|
|
|
+ if (res)
|
|
|
+ put_rc(res);
|
|
|
|
|
|
- halt();
|
|
|
-
|
|
|
- res = f_getfree("/", &p2, &fs);
|
|
|
- if (res) {
|
|
|
- put_rc(res);
|
|
|
- }
|
|
|
- /*
|
|
|
- printf("FAT type = %u\nBytes/Cluster = %lu\nNumber of FATs = %u\n"
|
|
|
- "Root DIR entries = %u\nSectors/FAT = %lu\nNumber of clusters = %lu\n"
|
|
|
- "FAT start (lba) = %lu\nDIR start (lba,clustor) = %lu\nData start (lba) = %lu\n",
|
|
|
- (WORD)fs->fs_type, (DWORD)fs->csize * 512, (WORD)fs->n_fats,
|
|
|
- fs->n_rootdir, (DWORD)fs->sects_fat, (DWORD)fs->max_clust - 2,
|
|
|
- fs->fatbase, fs->dirbase, fs->database
|
|
|
- );
|
|
|
- */
|
|
|
- acc_size = acc_files = acc_dirs = 0;
|
|
|
- res = scan_files("/");
|
|
|
- if (res) {
|
|
|
- put_rc(res);
|
|
|
- }
|
|
|
- /*
|
|
|
- printf("%u files, %lu bytes.\n%u folders.\n"
|
|
|
- "%lu KB total disk space.\n%lu KB available.\n",
|
|
|
- acc_files, acc_size, acc_dirs,
|
|
|
- (fs->max_clust - 2) * (fs->csize / 2), p2 * (fs->csize / 2)
|
|
|
- );
|
|
|
- */
|
|
|
-
|
|
|
+ printfs(0,"FAT type = %u\nBytes/Cluster = %lu\nNumber of FATs = %u\n"
|
|
|
+ "Root DIR entries = %u\nSectors/FAT = %lu\nNumber of clusters = %lu\n"
|
|
|
+ "FAT start (lba) = %lu\nDIR start (lba,clustor) = %lu\nData start (lba) = %lu\n",
|
|
|
+ (WORD)fs->fs_type, (DWORD)fs->csize * 512, (WORD)fs->n_fats,
|
|
|
+ fs->n_rootdir, (DWORD)fs->sects_fat, (DWORD)fs->max_clust - 2,
|
|
|
+ fs->fatbase, fs->dirbase, fs->database);
|
|
|
+
|
|
|
+ acc_size = acc_files = acc_dirs = 0;
|
|
|
+ res = scan_files("/");
|
|
|
+ if (res)
|
|
|
+ put_rc(res);
|
|
|
+
|
|
|
+ printfc("%u files, %lu bytes.\n%u folders.\n"
|
|
|
+ "%lu KB total disk space.\n%lu KB available.\n",
|
|
|
+ acc_files, acc_size, acc_dirs,
|
|
|
+ (fs->max_clust - 2) * (fs->csize / 2), p2 * (fs->csize / 2));
|
|
|
+
|
|
|
while(1){
|
|
|
while(!pad1.start) {
|
|
|
waitForVBlank();
|