2
0

abcdrive.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include <stdbool.h>
  2. #include <stddef.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include "common.h"
  6. #include "ff.h"
  7. #include "io.h"
  8. #include "console.h"
  9. #define MAX_FAST_FRAGMENTS 16
  10. /* Extend these with a lot more stuff */
  11. #define CLTBL_SIZE ((MAX_FAST_FRAGMENTS+1)*2)
  12. struct drive {
  13. FIL fp;
  14. DWORD cltbl[CLTBL_SIZE];
  15. bool mounted;
  16. };
  17. #define MAX_DRIVES 8 /* Drives per controller */
  18. struct disk_type {
  19. char name[4];
  20. struct drive drive[MAX_DRIVES];
  21. };
  22. #define DISK_TYPES 4
  23. static struct disk_type __attribute__((section(".dram.bss"))) disks[DISK_TYPES];
  24. static const char disk_names[][4] = { "hd", "sf", "mf", "mo" };
  25. /*
  26. * Look for ABC/UFD-DOS disks and open them
  27. */
  28. void mount_abcdrives(void)
  29. {
  30. char filename_buf[64];
  31. unsigned int type;
  32. unsigned int drive;
  33. int whichabc = (ABC_STATUS & ABC_STATUS_800) ? 800 : 80;
  34. FRESULT rv;
  35. for (type = 0; type < DISK_TYPES; type++) {
  36. memcpy(disks[type].name, disk_names[type], 4);
  37. for (drive = 0; drive < MAX_DRIVES; drive++) {
  38. struct drive *drv = &disks[type].drive[drive];
  39. drv->mounted = false;
  40. snprintf(filename_buf, sizeof filename_buf,
  41. "/abcdisk.%d/%s%u",
  42. whichabc, disks[type].name, drive);
  43. rv = f_open(&drv->fp, filename_buf,
  44. FA_READ|FA_WRITE|FA_OPEN_EXISTING);
  45. if (rv != FR_OK) {
  46. snprintf(filename_buf, sizeof filename_buf,
  47. "/abcdisk/%s%u",
  48. disks[type].name, drive);
  49. rv = f_open(&drv->fp, filename_buf,
  50. FA_READ|FA_WRITE|FA_OPEN_EXISTING);
  51. }
  52. if (rv != FR_OK)
  53. continue;
  54. drv->mounted = true;
  55. con_printf("%s%u: mounted %s\n", disks[type].name, drive,
  56. filename_buf);
  57. /* Try to create memoized extent lists */
  58. drv->cltbl[0] = CLTBL_SIZE;
  59. drv->fp.cltbl = drv->cltbl;
  60. rv = f_lseek(&drv->fp, CREATE_LINKMAP);
  61. if (rv != FR_OK) {
  62. con_printf("%s%u: warning: file too fragmented, will be slow\n",
  63. disks[type].name, drive);
  64. }
  65. }
  66. }
  67. }