main.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. //#include "integer.h"
  2. #include "ff.h"
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <time.h>
  6. #include "data.h";
  7. #include "pad.h";
  8. #include "event.h";
  9. #include "myEvents.h";
  10. #include "ressource.h";
  11. #include "PPU.h"
  12. #include "debug.h"
  13. padStatus pad1;
  14. DWORD acc_size; /* Work register for fs command */
  15. WORD acc_files, acc_dirs;
  16. FILINFO finfo;
  17. FATFS fatfs[2]; /* File system object for each logical drive */
  18. BYTE Buff[1024]; /* Working buffer */
  19. DWORD p1, p2, p3;
  20. BYTE res;
  21. WORD w1;
  22. UINT s1, s2, cnt;
  23. FATFS *fs;
  24. DIR dir; /* Directory object */
  25. FIL file1, file2; /* File object */
  26. void initInternalRegisters(void) {
  27. characterLocation[0] = 0x0000;
  28. characterLocation[1] = 0x0000;
  29. characterLocation[2] = 0x0000;
  30. characterLocation[3] = 0x0000;
  31. debug_init();
  32. }
  33. void preInit(void) {
  34. // For testing purpose ...
  35. // Insert code here to be executed before register init
  36. }
  37. DWORD get_fattime ()
  38. {
  39. time_t rawtime;
  40. struct tm * ptm;
  41. //time ( &rawtime );
  42. ptm = gmtime ( &rawtime );
  43. return ((DWORD)(ptm->tm_year - 80) << 25)
  44. | ((DWORD)(ptm->tm_mon +1) << 21)
  45. | ((DWORD)ptm->tm_mday << 16)
  46. | ((DWORD)ptm->tm_hour << 11)
  47. | ((DWORD)ptm->tm_min << 5)
  48. | ((DWORD)ptm->tm_sec >> 1);
  49. }
  50. void halt(void) {
  51. while(1);
  52. }
  53. void put_rc (FRESULT rc){
  54. const char *p;
  55. static const char str[] =
  56. "OK\0" "NOT_READY\0" "NO_FILE\0" "NO_PATH\0" "INVALID_NAME\0" "INVALID_DRIVE\0"
  57. "DENIED\0" "EXIST\0" "RW_ERROR\0" "WRITE_PROTECTED\0" "NOT_ENABLED\0"
  58. "NO_FILESYSTEM\0" "INVALID_OBJECT\0" "MKFS_ABORTED\0";
  59. FRESULT i;
  60. for (p = str, i = 0; i != rc && *p; i++) {
  61. while(*p++);
  62. }
  63. printfc("rc=%u FR_%s\n", (WORD)rc, p);
  64. }
  65. FRESULT scan_files (char* path){
  66. DIR dirs;
  67. FRESULT res;
  68. int i;
  69. if ((res = f_opendir(&dirs, path)) == FR_OK) {
  70. i = strlen(path);
  71. while (((res = f_readdir(&dirs, &finfo)) == FR_OK) && finfo.fname[0]) {
  72. if (finfo.fattrib & AM_DIR) {
  73. acc_dirs++;
  74. *(path+i) = '/'; strcpy(path+i+1, &finfo.fname[0]);
  75. res = scan_files(path);
  76. *(path+i) = '\0';
  77. if (res != FR_OK) break;
  78. } else {
  79. acc_files++;
  80. acc_size += finfo.fsize;
  81. }
  82. }
  83. }
  84. return res;
  85. }
  86. void main(void) {
  87. word i,j;
  88. BYTE res;
  89. initInternalRegisters();
  90. *(byte*) 0x2105 = 0x01; // MODE 1 value
  91. *(byte*) 0x212c = 0x01; // Plane 0 (bit one) enable register
  92. *(byte*) 0x212d = 0x00; // All subPlane disable
  93. *(byte*) 0x2100 = 0x0f; // enable background
  94. debug_enable();
  95. printfs(0,"FATFS ");
  96. //halt();
  97. printfc("SNES::main: Try to init disk\n");
  98. put_rc(f_mount(0, &fatfs[0]));
  99. printfc("SNES::main: Try to get free\n");
  100. res = f_getfree("", &p2, &fs);
  101. if (res)
  102. put_rc(res);
  103. //halt();
  104. printfc("SNES::main: printf fs results\n");
  105. printfc("FAT TYPE = %u\nBYTES/CLUSTER = %lu\nNUMBER OF FATS = %u\n"
  106. "ROOT DIR ENTRIES = %u\nSECTORS/FAT = %lu\nNUMBER OF CLUSTERS = %lu\n"
  107. "FAT START = %lu\nDIR START LBA,CLUSTER = %lu\nDATA START LBA = %lu\n",
  108. (WORD)fs->fs_type, (DWORD)fs->csize * 512, (WORD)fs->n_fats,
  109. fs->n_rootdir, (DWORD)fs->sects_fat, (DWORD)fs->max_clust - 2,
  110. fs->fatbase, fs->dirbase, fs->database);
  111. acc_size = acc_files = acc_dirs = 0;
  112. printfc("SNES::main: scan files\n");
  113. res = scan_files("");
  114. if (res)
  115. put_rc(res);
  116. printfc("%u FILES, %lu BYTES\n%u FOLDERS\n"
  117. "%lu KB TOTAK DISK SPACE\n%lu KB AVAILABLE\n",
  118. acc_files, acc_size, acc_dirs,
  119. (fs->max_clust - 2) * (fs->csize / 2), p2 * (fs->csize / 2));
  120. while(1){
  121. while(!pad1.start) {
  122. waitForVBlank();
  123. pad1 = readPad((byte) 0);
  124. }
  125. }
  126. while(1);
  127. }
  128. void IRQHandler(void) {
  129. }
  130. void NMIHandler(void) {
  131. //processEvents();
  132. }