2017-03-25 22:05:10 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include "types.h"
|
|
|
|
#include "imports.h"
|
|
|
|
#include "devices.h"
|
|
|
|
#include "sdio.h"
|
|
|
|
#include "text.h"
|
|
|
|
#include "sd_fat.h"
|
|
|
|
|
|
|
|
unsigned char sd_io_buffer[0x40000] __attribute__((aligned(0x40))) __attribute__((section(".io_buffer")));
|
|
|
|
|
|
|
|
int sd_fat_read(unsigned long sector, unsigned char *buffer, unsigned long sector_count)
|
|
|
|
{
|
2017-03-27 22:04:19 +02:00
|
|
|
// It seems that sdcard_readwrite overwrite more bytes than requested with 0xff.... So I use io_buffer to read it.
|
|
|
|
if (sector_count * SDIO_BYTES_PER_SECTOR > sizeof(sd_io_buffer)) return 0;
|
2021-03-25 23:37:00 +01:00
|
|
|
int result = sdcard_readwrite(SDIO_READ, sd_io_buffer, sector_count, SDIO_BYTES_PER_SECTOR, sector, NULL, DEVICE_ID_SDCARD_PATCHED);
|
2017-03-27 22:04:19 +02:00
|
|
|
if (result) return 0;
|
|
|
|
memcpy(buffer, sd_io_buffer, sector_count * SDIO_BYTES_PER_SECTOR);
|
|
|
|
return 1;
|
2017-03-25 22:05:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int sd_fat_write(unsigned long sector, unsigned char *buffer, unsigned long sector_count)
|
|
|
|
{
|
2017-03-27 22:04:19 +02:00
|
|
|
if (sector_count * SDIO_BYTES_PER_SECTOR > sizeof(sd_io_buffer)) return 0;
|
2021-03-25 23:37:00 +01:00
|
|
|
int result = sdcard_readwrite(SDIO_WRITE, buffer, sector_count, SDIO_BYTES_PER_SECTOR, sector, NULL, DEVICE_ID_SDCARD_PATCHED);
|
2017-03-27 22:04:19 +02:00
|
|
|
return result ? 0 : 1;
|
2017-03-25 22:05:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int InitSDCardFAT32()
|
|
|
|
{
|
2017-03-27 22:04:19 +02:00
|
|
|
fl_init();
|
|
|
|
|
2021-03-25 23:37:00 +01:00
|
|
|
int result = fl_attach_media(sd_fat_read, sd_fat_write);
|
2017-03-27 22:04:19 +02:00
|
|
|
if (result != FAT_INIT_OK)
|
|
|
|
{
|
2021-03-25 23:37:00 +01:00
|
|
|
_printf(20, 40, "FAT32 attach failed %d", result);
|
2017-03-27 22:04:19 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2017-03-25 22:05:10 +01:00
|
|
|
}
|