implement various functions
This commit is contained in:
parent
3fcac12ec8
commit
8264d647ba
@ -26,7 +26,7 @@ void memSpiSetSpeed(u8 speed);
|
||||
void spiReadBlock(void *dat);
|
||||
void spiWriteBlock(void *dat);
|
||||
u8 memSpiRead(void *dst, u16 slen);
|
||||
u8 memSpiWrite(void *src);
|
||||
u8 memSpiWrite(const void *src);
|
||||
//u8 mem_spi(u8 dat);
|
||||
void memfill(void *dst, u8 val, u16 len);
|
||||
void memcopy(void *src, void *dst, u16 len);
|
||||
|
@ -4,16 +4,17 @@
|
||||
// See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
#ifndef _DISK_H
|
||||
#define _DISK_H
|
||||
#ifndef _SD_H
|
||||
#define _SD_H
|
||||
|
||||
#include "types.h"
|
||||
|
||||
u8 diskGetInterface();
|
||||
u8 diskInit();
|
||||
u8 diskRead(u32 saddr, void *buff, u16 slen);
|
||||
u8 diskWrite(u32 saddr, u8 *buff, u16 slen);
|
||||
void diskSetInterface(u32 interface);
|
||||
u8 sdGetInterface();
|
||||
u8 sdInit();
|
||||
u8 sdRead(u32 sector, u8 *buff, u16 count);
|
||||
u8 sdWrite(u32 sector, const u8 *buff, u16 count);
|
||||
|
||||
void sdSetInterface(u32 interface);
|
||||
|
||||
|
||||
|
194
src/diskio.c
194
src/diskio.c
@ -8,6 +8,7 @@
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
#include "diskio.h" /* FatFs lower layer API */
|
||||
#include "sd.h"
|
||||
|
||||
/* Definitions of physical drive number for each drive */
|
||||
#define DEV_RAM 0 /* Example: Map Ramdisk to physical drive 0 */
|
||||
@ -24,31 +25,37 @@ DSTATUS disk_status (
|
||||
)
|
||||
{
|
||||
DSTATUS stat;
|
||||
int result;
|
||||
// int result;
|
||||
|
||||
switch (pdrv) {
|
||||
case DEV_RAM :
|
||||
result = RAM_disk_status();
|
||||
// switch (pdrv) {
|
||||
// case DEV_RAM :
|
||||
// result = RAM_disk_status();
|
||||
|
||||
// translate the reslut code here
|
||||
// // translate the reslut code here
|
||||
|
||||
return stat;
|
||||
// return stat;
|
||||
|
||||
case DEV_MMC :
|
||||
result = MMC_disk_status();
|
||||
// case DEV_MMC :
|
||||
// result = MMC_disk_status();
|
||||
|
||||
// translate the reslut code here
|
||||
// // translate the reslut code here
|
||||
|
||||
return stat;
|
||||
// return stat;
|
||||
|
||||
case DEV_USB :
|
||||
result = USB_disk_status();
|
||||
// case DEV_USB :
|
||||
// result = USB_disk_status();
|
||||
|
||||
// translate the reslut code here
|
||||
// // translate the reslut code here
|
||||
|
||||
return stat;
|
||||
}
|
||||
return STA_NOINIT;
|
||||
// return stat;
|
||||
// }
|
||||
// return STA_NOINIT;
|
||||
|
||||
if(pdrv)
|
||||
{
|
||||
return STA_NOINIT;
|
||||
}
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
|
||||
@ -64,28 +71,44 @@ DSTATUS disk_initialize (
|
||||
DSTATUS stat;
|
||||
int result;
|
||||
|
||||
switch (pdrv) {
|
||||
case DEV_RAM :
|
||||
result = RAM_disk_initialize();
|
||||
// switch (pdrv) {
|
||||
// case DEV_RAM :
|
||||
// result = RAM_disk_initialize();
|
||||
|
||||
// translate the reslut code here
|
||||
// // translate the reslut code here
|
||||
|
||||
return stat;
|
||||
// return stat;
|
||||
|
||||
case DEV_MMC :
|
||||
result = MMC_disk_initialize();
|
||||
// case DEV_MMC :
|
||||
// result = MMC_disk_initialize();
|
||||
|
||||
// translate the reslut code here
|
||||
// // translate the reslut code here
|
||||
|
||||
return stat;
|
||||
// return stat;
|
||||
|
||||
case DEV_USB :
|
||||
result = USB_disk_initialize();
|
||||
// case DEV_USB :
|
||||
// result = USB_disk_initialize();
|
||||
|
||||
// translate the reslut code here
|
||||
// // translate the reslut code here
|
||||
|
||||
return stat;
|
||||
// return stat;
|
||||
// }
|
||||
|
||||
stat=sdInit(); //SD card initialization
|
||||
|
||||
if(stat == STA_NODISK)
|
||||
{
|
||||
return STA_NODISK;
|
||||
}
|
||||
else if(stat != 0)
|
||||
{
|
||||
return STA_NOINIT;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return STA_NOINIT;
|
||||
}
|
||||
|
||||
@ -103,38 +126,54 @@ DRESULT disk_read (
|
||||
)
|
||||
{
|
||||
DRESULT res;
|
||||
int result;
|
||||
// int result;
|
||||
|
||||
switch (pdrv) {
|
||||
case DEV_RAM :
|
||||
// translate the arguments here
|
||||
// switch (pdrv) {
|
||||
// case DEV_RAM :
|
||||
// // translate the arguments here
|
||||
|
||||
result = RAM_disk_read(buff, sector, count);
|
||||
// result = RAM_disk_read(buff, sector, count);
|
||||
|
||||
// translate the reslut code here
|
||||
// // translate the reslut code here
|
||||
|
||||
return res;
|
||||
// return res;
|
||||
|
||||
case DEV_MMC :
|
||||
// translate the arguments here
|
||||
// case DEV_MMC :
|
||||
// // translate the arguments here
|
||||
|
||||
result = MMC_disk_read(buff, sector, count);
|
||||
// result = MMC_disk_read(buff, sector, count);
|
||||
|
||||
// translate the reslut code here
|
||||
// // translate the reslut code here
|
||||
|
||||
return res;
|
||||
// return res;
|
||||
|
||||
case DEV_USB :
|
||||
// translate the arguments here
|
||||
// case DEV_USB :
|
||||
// // translate the arguments here
|
||||
|
||||
result = USB_disk_read(buff, sector, count);
|
||||
// result = USB_disk_read(buff, sector, count);
|
||||
|
||||
// translate the reslut code here
|
||||
// // translate the reslut code here
|
||||
|
||||
return res;
|
||||
}
|
||||
// return res;
|
||||
// }
|
||||
|
||||
return RES_PARERR;
|
||||
// return RES_PARERR;
|
||||
|
||||
if (pdrv || !count)
|
||||
{
|
||||
return RES_PARERR;
|
||||
}
|
||||
|
||||
res = sdRead(sector, buff, count);
|
||||
|
||||
if(res == 0x00)
|
||||
{
|
||||
return RES_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return RES_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -151,38 +190,54 @@ DRESULT disk_write (
|
||||
)
|
||||
{
|
||||
DRESULT res;
|
||||
int result;
|
||||
// int result;
|
||||
|
||||
switch (pdrv) {
|
||||
case DEV_RAM :
|
||||
// translate the arguments here
|
||||
// switch (pdrv) {
|
||||
// case DEV_RAM :
|
||||
// // translate the arguments here
|
||||
|
||||
result = RAM_disk_write(buff, sector, count);
|
||||
// result = RAM_disk_write(buff, sector, count);
|
||||
|
||||
// translate the reslut code here
|
||||
// // translate the reslut code here
|
||||
|
||||
return res;
|
||||
// return res;
|
||||
|
||||
case DEV_MMC :
|
||||
// translate the arguments here
|
||||
// case DEV_MMC :
|
||||
// // translate the arguments here
|
||||
|
||||
result = MMC_disk_write(buff, sector, count);
|
||||
// result = MMC_disk_write(buff, sector, count);
|
||||
|
||||
// translate the reslut code here
|
||||
// // translate the reslut code here
|
||||
|
||||
return res;
|
||||
// return res;
|
||||
|
||||
case DEV_USB :
|
||||
// translate the arguments here
|
||||
// case DEV_USB :
|
||||
// // translate the arguments here
|
||||
|
||||
result = USB_disk_write(buff, sector, count);
|
||||
// result = USB_disk_write(buff, sector, count);
|
||||
|
||||
// translate the reslut code here
|
||||
// // translate the reslut code here
|
||||
|
||||
return res;
|
||||
}
|
||||
// return res;
|
||||
// }
|
||||
|
||||
return RES_PARERR;
|
||||
//return RES_PARERR;
|
||||
|
||||
if (pdrv || !count)
|
||||
{
|
||||
return RES_PARERR;
|
||||
}
|
||||
|
||||
res = sdWrite(sector, buff, count);
|
||||
|
||||
if(res == 0)
|
||||
{
|
||||
return RES_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return RES_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -223,3 +278,8 @@ DRESULT disk_ioctl (
|
||||
return RES_PARERR;
|
||||
}
|
||||
|
||||
DWORD get_fattime (void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include <libdragon.h>
|
||||
|
||||
#include "fat_old.h"
|
||||
#include "disk_old.h"
|
||||
#include "sd.h"
|
||||
#include "mem.h"
|
||||
#include "everdrive.h"
|
||||
#include "strlib.h"
|
||||
@ -163,7 +163,7 @@ u8 fatInit() {
|
||||
u8 resp;
|
||||
|
||||
u32 reserved_sectors;
|
||||
resp = diskInit();
|
||||
resp = sdInit();
|
||||
if (resp)return resp;
|
||||
fat_cache->data_sec_idx = 0xffffffff;
|
||||
fat_cache->table_sec_idx = 0xffffffff;
|
||||
@ -578,12 +578,12 @@ u8 fatCacheLoadData(u32 sector, u8 save_befor_load) {
|
||||
if (fat_cache->data_sec_idx == sector)return 0;
|
||||
|
||||
if (save_befor_load) {
|
||||
resp = diskWrite(fat_cache->data_sec_idx, fat_cache->data_sector, 1);
|
||||
resp = sdWrite(fat_cache->data_sec_idx, fat_cache->data_sector, 1);
|
||||
}
|
||||
fat_cache->data_sec_idx = sector;
|
||||
|
||||
//addr=addr*512, buff, lenght 1
|
||||
resp = diskRead(fat_cache->data_sec_idx, fat_cache->data_sector, 1);
|
||||
resp = sdRead(fat_cache->data_sec_idx, fat_cache->data_sector, 1);
|
||||
|
||||
//console_printf("c: %u\n", cache->buff_sector);
|
||||
//joyWait();
|
||||
@ -594,7 +594,7 @@ u8 fatCacheLoadData(u32 sector, u8 save_befor_load) {
|
||||
|
||||
u8 fatCacheSaveData() {
|
||||
|
||||
return diskWrite(fat_cache->data_sec_idx, fat_cache->data_sector, 1);
|
||||
return sdWrite(fat_cache->data_sec_idx, fat_cache->data_sector, 1);
|
||||
}
|
||||
|
||||
u8 fatCacheLoadTable(u32 sector, u8 save_before_load) {
|
||||
@ -610,7 +610,7 @@ u8 fatCacheLoadTable(u32 sector, u8 save_before_load) {
|
||||
|
||||
fat_cache->table_sec_idx = sector;
|
||||
|
||||
resp = diskRead(fat_cache->table_sec_idx, fat_cache->table_sector, 1);
|
||||
resp = sdRead(fat_cache->table_sec_idx, fat_cache->table_sector, 1);
|
||||
|
||||
return resp;
|
||||
|
||||
@ -620,9 +620,9 @@ u8 fatCacheApplyTable() {
|
||||
|
||||
u8 resp;
|
||||
|
||||
resp = diskWrite(fat_cache->table_sec_idx, fat_cache->table_sector, 1);
|
||||
resp = sdWrite(fat_cache->table_sec_idx, fat_cache->table_sector, 1);
|
||||
if (resp)return resp;
|
||||
resp = diskWrite(fat_cache->table_sec_idx + current_fat.sectors_per_fat, fat_cache->table_sector, 1);
|
||||
resp = sdWrite(fat_cache->table_sec_idx + current_fat.sectors_per_fat, fat_cache->table_sector, 1);
|
||||
|
||||
table_changed = 0;
|
||||
return resp;
|
||||
@ -930,7 +930,7 @@ u8 fatCreateRecord(u8 *name, u8 is_dir, u8 check_exist) {
|
||||
|
||||
//ocuppy function may destroy cache buff data
|
||||
if (lfn_blocks != 0) {
|
||||
resp = diskWrite(fat_cache->data_sec_idx, fat_cache->data_sector, 1);
|
||||
resp = sdWrite(fat_cache->data_sec_idx, fat_cache->data_sector, 1);
|
||||
if (resp)return resp;
|
||||
}
|
||||
cluster = 0;
|
||||
@ -1150,7 +1150,7 @@ u8 fatCreateRecord2(u8 *name, u8 is_dir, u8 check_exist) {
|
||||
|
||||
//ocuppy function may destroy cache buff data
|
||||
if (lfn_blocks != 0) {
|
||||
resp = diskWrite(fat_cache->data_sec_idx, fat_cache->data_sector, 1);
|
||||
resp = sdWrite(fat_cache->data_sec_idx, fat_cache->data_sector, 1);
|
||||
if (resp)return resp;
|
||||
}
|
||||
cluster = 0;
|
||||
@ -1174,7 +1174,7 @@ u8 fatCreateRecord2(u8 *name, u8 is_dir, u8 check_exist) {
|
||||
|
||||
memcopy(&hdr, &fat_cache->data_sector[rec.hdr_idx * 32], 32);
|
||||
|
||||
resp = diskWrite(fat_cache->data_sec_idx, fat_cache->data_sector, 1);
|
||||
resp = sdWrite(fat_cache->data_sec_idx, fat_cache->data_sector, 1);
|
||||
if (resp)return resp;
|
||||
|
||||
if (is_dir) {
|
||||
@ -1341,7 +1341,7 @@ u8 fatClearClusters(u32 cluster, u8 len) {
|
||||
while (len--) {
|
||||
fat_cache->data_sec_idx = fatClusterToSector(cluster++);
|
||||
for (i = 0; i < current_fat.cluster_size; i++) {
|
||||
resp = diskWrite(fat_cache->data_sec_idx++, fat_cache->data_sector, 1);
|
||||
resp = sdWrite(fat_cache->data_sec_idx++, fat_cache->data_sector, 1);
|
||||
|
||||
if (resp)return resp;
|
||||
}
|
||||
@ -1371,8 +1371,8 @@ u8 fatOccupyClusters(u32 *base_cluster, u16 len) {
|
||||
|
||||
|
||||
//memcopy(current_cache->table_frame, occupy_buff, 512);
|
||||
resp = diskRead(current_fat.fat_entry + fat_table_sector, (void *) ROM_ADDR, 32);
|
||||
//resp = diskRead(current_fat.fat_entry + fat_table_sector, occupy_buff, 1);
|
||||
resp = sdRead(current_fat.fat_entry + fat_table_sector, (void *) ROM_ADDR, 32);
|
||||
//resp = sdRead(current_fat.fat_entry + fat_table_sector, occupy_buff, 1);
|
||||
if (resp)return resp;
|
||||
dma_read(occupy_buff, ROM_ADDR, 32 * 512);
|
||||
|
||||
@ -1559,7 +1559,7 @@ u8 fatWriteFile(void *src, u32 sectors) {
|
||||
|
||||
//console_printf("len: %d\n", len);
|
||||
//joyWait();
|
||||
resp = diskWrite(file.sector, ptr8, len);
|
||||
resp = sdWrite(file.sector, ptr8, len);
|
||||
if (resp)return resp;
|
||||
ptr8 += 512 * len;
|
||||
resp = fatSkipSectors(len);
|
||||
@ -1592,7 +1592,7 @@ u8 fatReadFile(void *dst, u32 sectors) {
|
||||
len = current_fat.cluster_size - file.in_cluster_ptr;
|
||||
if (len > sectors)len = sectors;
|
||||
|
||||
resp = diskRead(file.sector, dst, len);
|
||||
resp = sdRead(file.sector, dst, len);
|
||||
|
||||
if (resp)return resp;
|
||||
dst += 512 * len;
|
||||
@ -1688,9 +1688,9 @@ u8 fatMultiClustRW(void *buff, u32 max_sectors, u32 *readrd_sectors, u16 write)
|
||||
*readrd_sectors = len;
|
||||
|
||||
if (write) {
|
||||
resp = diskWrite(begin_sect, buff, len);
|
||||
resp = sdWrite(begin_sect, buff, len);
|
||||
} else {
|
||||
resp = diskRead(begin_sect, buff, len);
|
||||
resp = sdRead(begin_sect, buff, len);
|
||||
}
|
||||
|
||||
return resp;
|
||||
@ -1718,7 +1718,7 @@ u8 fatReadCluster(void *dst) {
|
||||
u8 resp;
|
||||
if (file.mode != FILE_MODE_RD)return FAT_ERR_FILE_MODE;
|
||||
|
||||
resp = diskRead(file.sector, dst, current_fat.cluster_size);
|
||||
resp = sdRead(file.sector, dst, current_fat.cluster_size);
|
||||
if (resp)return resp;
|
||||
dst += current_fat.cluster_byte_size;
|
||||
resp = fatGetNextCluster(&file.cluster);
|
||||
|
16
src/main.c
16
src/main.c
@ -20,7 +20,7 @@
|
||||
#include "everdrive.h"
|
||||
|
||||
//filesystem
|
||||
#include "disk_old.h"
|
||||
#include "sd.h"
|
||||
#include "fat_old.h"
|
||||
|
||||
//utils
|
||||
@ -881,11 +881,11 @@ void configure()
|
||||
|
||||
if (streql("ED64 SD boot", buff, 12) && firm >= 0x0116) //TODO: can this be moved before the firmware is loaded?
|
||||
{
|
||||
diskSetInterface(DISK_IFACE_SD);
|
||||
sdSetInterface(DISK_IFACE_SD);
|
||||
}
|
||||
else
|
||||
{
|
||||
diskSetInterface(DISK_IFACE_SPI);
|
||||
sdSetInterface(DISK_IFACE_SPI);
|
||||
}
|
||||
memSpiSetDma(0);
|
||||
}
|
||||
@ -1206,11 +1206,11 @@ void loadnesrom(display_context_t disp, u8 *rom_path)
|
||||
u8 resp = 0;
|
||||
//load nes emulator
|
||||
resp = fatOpenFileByName("/ED64/neon64bu.rom", 0); //err if not found ^^
|
||||
resp = diskRead(file.sector, (void *)0xb0000000, file.sec_available);
|
||||
resp = sdRead(file.sector, (void *)0xb0000000, file.sec_available);
|
||||
|
||||
//load nes rom
|
||||
resp = fatOpenFileByName(rom_path, 0); //err if not found ^^
|
||||
resp = diskRead(file.sector, (void *)0xb0200000, file.sec_available);
|
||||
resp = sdRead(file.sector, (void *)0xb0200000, file.sec_available);
|
||||
|
||||
boot_cic = CIC_6102;
|
||||
boot_save = 0; //save off/cpak
|
||||
@ -1370,12 +1370,12 @@ void loadrom(display_context_t disp, u8 *buff, int fast)
|
||||
|
||||
if (mb <= 32)
|
||||
{
|
||||
resp = diskRead(begin_sector, (void *)0xb0000000, file_sectors); //2048 cluster 1Mb
|
||||
resp = sdRead(begin_sector, (void *)0xb0000000, file_sectors); //2048 cluster 1Mb
|
||||
}
|
||||
else
|
||||
{
|
||||
resp = diskRead(begin_sector, (void *)0xb0000000, lower_half);
|
||||
resp = diskRead(begin_sector + lower_half, (void *)0xb2000000, file_sectors - lower_half);
|
||||
resp = sdRead(begin_sector, (void *)0xb0000000, lower_half);
|
||||
resp = sdRead(begin_sector + lower_half, (void *)0xb2000000, file_sectors - lower_half);
|
||||
}
|
||||
|
||||
if (resp)
|
||||
|
@ -110,7 +110,7 @@ u8 memSpiReadDma(void *dst, u16 slen) {
|
||||
return resp;
|
||||
}
|
||||
|
||||
u8 memSpiWrite(void *src) {
|
||||
u8 memSpiWrite(const void *src) {
|
||||
|
||||
u16 i;
|
||||
|
||||
|
@ -4,7 +4,9 @@
|
||||
// See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
#include "disk_old.h"
|
||||
#include "types.h"
|
||||
#include "integer.h"
|
||||
#include "sd.h"
|
||||
#include "mem.h"
|
||||
#include "everdrive.h"
|
||||
#include "errors.h"
|
||||
@ -46,19 +48,19 @@ u32 disk_interface;
|
||||
|
||||
|
||||
unsigned int diskCrc7(unsigned char *buff, unsigned int len);
|
||||
void diskCrc16SD(u8 *data, u16 *crc_out, u16 len);
|
||||
void diskCrc16SD(const u8 *data, u16 *crc_out, u16 len);
|
||||
u8 diskGetRespTypeSD(u8 cmd);
|
||||
u8 diskCmdSD(u8 cmd, u32 arg);
|
||||
|
||||
u8 diskInitSD();
|
||||
u8 diskReadSD(u32 saddr, void *buff, u16 slen);
|
||||
u8 diskWriteSD(u32 saddr, u8 *buff, u16 slen);
|
||||
u8 diskReadSD(u32 sector, void *buff, u16 count);
|
||||
u8 diskWriteSD(u32 sector, const u8 *buff, u16 count);
|
||||
u8 diskStopRwSD();
|
||||
|
||||
u8 diskCmdSPI(u8 cmd, u32 arg);
|
||||
u8 diskInitSPI();
|
||||
u8 diskReadSPI(u32 saddr, void *buff, u16 slen);
|
||||
u8 diskWriteSPI(u32 saddr, u8 *buff, u16 slen);
|
||||
u8 diskReadSPI(u32 sector, void *buff, u16 count);
|
||||
u8 diskWriteSPI(u32 sector, const u8 *buff, u16 count);
|
||||
|
||||
|
||||
|
||||
@ -97,17 +99,17 @@ const u16 sd_crc16_table[] = {
|
||||
0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0
|
||||
};
|
||||
|
||||
void diskSetInterface(u32 interface) {
|
||||
void sdSetInterface(u32 interface) {
|
||||
|
||||
disk_interface = interface;
|
||||
}
|
||||
|
||||
u8 diskGetInterface() {
|
||||
u8 sdGetInterface() {
|
||||
|
||||
return disk_interface;
|
||||
}
|
||||
|
||||
u8 diskInit() {
|
||||
u8 sdInit() {
|
||||
|
||||
if (disk_interface == DISK_IFACE_SD) {
|
||||
return diskInitSD();
|
||||
@ -116,25 +118,25 @@ u8 diskInit() {
|
||||
}
|
||||
}
|
||||
|
||||
u8 diskRead(u32 saddr, void *buff, u16 slen) {
|
||||
u8 sdRead(u32 sector, u8 *buff, u16 count) {
|
||||
|
||||
if (disk_interface == DISK_IFACE_SD) {
|
||||
return diskReadSD(saddr, buff, slen);
|
||||
return diskReadSD(sector, buff, count);
|
||||
} else {
|
||||
return diskReadSPI(saddr, buff, slen);
|
||||
return diskReadSPI(sector, buff, count);
|
||||
}
|
||||
}
|
||||
|
||||
u8 diskWrite(u32 saddr, u8 *buff, u16 slen) {
|
||||
u8 sdWrite(u32 sector, const u8 *buff, u16 count) {
|
||||
|
||||
if (disk_interface == DISK_IFACE_SD) {
|
||||
return diskWriteSD(saddr, buff, slen);
|
||||
return diskWriteSD(sector, buff, count);
|
||||
} else {
|
||||
return diskWriteSPI(saddr, buff, slen);
|
||||
return diskWriteSPI(sector, buff, count);
|
||||
}
|
||||
}
|
||||
|
||||
void diskCrc16SD(u8 *data, u16 *crc_out, u16 len) {
|
||||
void diskCrc16SD(const u8 *data, u16 *crc_out, u16 len) {
|
||||
|
||||
///u16 len = 512;
|
||||
u16 i, tmp1, u;
|
||||
@ -369,20 +371,20 @@ u8 diskInitSD() {
|
||||
|
||||
}
|
||||
|
||||
u8 diskReadSD(u32 saddr, void *buff, u16 slen) {
|
||||
u8 diskReadSD(u32 sector, void *buff, u16 count) {
|
||||
|
||||
u8 resp;
|
||||
|
||||
|
||||
if (!(card_type & 1))saddr *= 512;
|
||||
resp = diskCmdSD(CMD18, saddr);
|
||||
if (!(card_type & 1))sector *= 512;
|
||||
resp = diskCmdSD(CMD18, sector);
|
||||
if (resp)return DISK_ERR_RD1;
|
||||
|
||||
|
||||
resp = memSpiRead(buff, slen);
|
||||
resp = memSpiRead(buff, count);
|
||||
if (resp)return resp;
|
||||
|
||||
//console_printf("drd: %0X\n", saddr);
|
||||
//console_printf("drd: %0X\n", sector);
|
||||
resp = diskStopRwSD();
|
||||
|
||||
return resp;
|
||||
@ -409,24 +411,24 @@ u8 diskStopRwSD() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
u8 diskWriteSD(u32 saddr, u8 *buff, u16 slen) {
|
||||
u8 diskWriteSD(u32 sector, const u8 *buff, u16 count) {
|
||||
|
||||
u8 resp;
|
||||
u16 crc16[5];
|
||||
u16 i;
|
||||
u16 u;
|
||||
u8 ram_buff[512];
|
||||
u8 *buff_ptr;
|
||||
const u8 *buff_ptr;
|
||||
|
||||
|
||||
if (!(card_type & 1))saddr *= 512;
|
||||
resp = diskCmdSD(CMD25, saddr);
|
||||
if (!(card_type & 1))sector *= 512;
|
||||
resp = diskCmdSD(CMD25, sector);
|
||||
if (resp)return DISK_ERR_WR1;
|
||||
|
||||
evd_SDdatWriteMode(0);
|
||||
|
||||
|
||||
while (slen--) {
|
||||
while (count--) {
|
||||
|
||||
if ((u32) buff >= ROM_ADDR && (u32) buff < ROM_END_ADDR) {
|
||||
dma_read_s(ram_buff, (u32) buff, 512);
|
||||
@ -626,17 +628,17 @@ u8 diskInitSPI() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
u8 diskReadSPI(u32 saddr, void *buff, u16 slen) {
|
||||
u8 diskReadSPI(u32 sector, void *buff, u16 count) {
|
||||
|
||||
|
||||
u8 resp;
|
||||
|
||||
if (!(card_type & 1))saddr *= 512;
|
||||
resp = diskCmdSPI(CMD18, saddr);
|
||||
if (!(card_type & 1))sector *= 512;
|
||||
resp = diskCmdSPI(CMD18, sector);
|
||||
if (resp != 0)return DISK_ERR_RD1;
|
||||
memSpiSSOn();
|
||||
|
||||
resp = memSpiRead(buff, slen);
|
||||
resp = memSpiRead(buff, count);
|
||||
|
||||
memSpiSSOff();
|
||||
diskCmdSPI(CMD12, 0);
|
||||
@ -644,18 +646,18 @@ u8 diskReadSPI(u32 saddr, void *buff, u16 slen) {
|
||||
return resp;
|
||||
}
|
||||
|
||||
u8 diskWriteSPI(u32 saddr, u8 *buff, u16 slen) {
|
||||
u8 diskWriteSPI(u32 sector, const u8 *buff, u16 count) {
|
||||
|
||||
u8 resp;
|
||||
u16 i;
|
||||
|
||||
if (!(card_type & 1))saddr *= 512;
|
||||
resp = diskCmdSPI(CMD25, saddr);
|
||||
if (!(card_type & 1))sector *= 512;
|
||||
resp = diskCmdSPI(CMD25, sector);
|
||||
if (resp != 0)return DISK_ERR_WR1;
|
||||
memSpiSSOn();
|
||||
|
||||
|
||||
while (slen--) {
|
||||
while (count--) {
|
||||
|
||||
mem_spi(0xff);
|
||||
mem_spi(0xff);
|
Loading…
Reference in New Issue
Block a user