repo2/firmware/mist/diskio_sectorrequest.c @ 173
46 | markw | #include "diskio.h"
|
|
#include "regs.h"
|
|||
69 | markw | #include "printf.h"
|
|
extern int debug_pos;
|
|||
46 | markw | void mmcReadCached(u32 sector);
|
|
u32 n_actual_mmc_sector;
|
|||
unsigned char * mmc_sector_buffer;
|
|||
void mmcReadCached(u32 sector)
|
|||
{
|
|||
//debug("mmcReadCached");
|
|||
//plotnext(toatarichar(' '));
|
|||
//plotnextnumber(sector);
|
|||
//debug("\n");
|
|||
if(sector==n_actual_mmc_sector) return;
|
|||
//debug("mmcReadREAL");
|
|||
//plotnext(toatarichar(' '));
|
|||
//plotnextnumber(sector);
|
|||
//debug("\n");
|
|||
//u08 ret,retry;
|
|||
//predtim nez nacte jiny, musi ulozit soucasny
|
|||
// TODO mmcWriteCachedFlush();
|
|||
//az ted nacte novy
|
|||
//retry=0; //zkusi to maximalne 256x
|
|||
/*do
|
|||
{
|
|||
ret = mmcRead(sector); //vraci 0 kdyz ok
|
|||
retry--;
|
|||
} while (ret && retry);
|
|||
while(ret); //a pokud se vubec nepovedlo, tady zustane zablokovany cely SDrive!
|
|||
*/
|
|||
69 | markw | //printf("Reading sector:%d", sector);
|
|
163 | markw | *zpu_out4 = sector|0x04000000;
|
|
69 | markw | while (!*zpu_in4)
|
|
46 | markw | {
|
|
// Wait until ready
|
|||
}
|
|||
69 | markw | *zpu_out4 = 0;
|
|
//printf(" RD1 ");
|
|||
while (*zpu_in4)
|
|||
{
|
|||
// Wait until ready cleared
|
|||
}
|
|||
46 | markw | ||
69 | markw | //printf(" RD2 ");
|
|
46 | markw | n_actual_mmc_sector=sector;
|
|
}
|
|||
/*-----------------------------------------------------------------------*/
|
|||
/* Initialize Disk Drive */
|
|||
/*-----------------------------------------------------------------------*/
|
|||
DSTATUS disk_initialize (void)
|
|||
{
|
|||
DSTATUS stat;
|
|||
n_actual_mmc_sector = 0xffffffff;
|
|||
//do
|
|||
//{
|
|||
// mmcInit();
|
|||
//}
|
|||
//while(mmcReset()); //dokud nenulove, tak smycka (return 0 => ok!)
|
|||
//set_spi_clock_freq();
|
|||
// no longer in ram (yet!), misuse will break us...
|
|||
69 | markw | mmc_sector_buffer = (unsigned char *)0x4000; // 512 bytes in the middle of memory space!
|
|
46 | markw | ||
stat = RES_OK;
|
|||
return stat;
|
|||
}
|
|||
/*-----------------------------------------------------------------------*/
|
|||
/* Read Partial Sector */
|
|||
/*-----------------------------------------------------------------------*/
|
|||
DRESULT disk_readp (
|
|||
BYTE* dest, /* Pointer to the destination object */
|
|||
DWORD sector, /* Sector number (LBA) */
|
|||
WORD sofs, /* Offset in the sector */
|
|||
WORD count /* Byte count (bit15:destination) */
|
|||
)
|
|||
{
|
|||
DRESULT res;
|
|||
/*debug("readp:");
|
|||
plotnextnumber(sector);
|
|||
debug(" ");
|
|||
plotnextnumber((int)dest);
|
|||
debug(" ");
|
|||
plotnextnumber(sofs);
|
|||
debug(" ");
|
|||
plotnextnumber(count);
|
|||
debug(" ");
|
|||
plotnextnumber(atari_sector_buffer);
|
|||
debug(" ");
|
|||
plotnextnumber(mmc_sector_buffer);
|
|||
debug("\n");
|
|||
*/
|
|||
// Put your code here
|
|||
mmcReadCached(sector);
|
|||
for(;count>0;++sofs,--count)
|
|||
{
|
|||
unsigned char x = mmc_sector_buffer[sofs];
|
|||
//printf("char:%02x loc:%d", x,sofs);
|
|||
*dest++ = x;
|
|||
}
|
|||
res = RES_OK;
|
|||
return res;
|
|||
}
|
|||
/*-----------------------------------------------------------------------*/
|
|||
/* Write Partial Sector */
|
|||
/*-----------------------------------------------------------------------*/
|
|||
69 | markw | DRESULT disk_writep (const BYTE* buff, DWORD sofs, DWORD count)
|
|
46 | markw | {
|
|
DRESULT res;
|
|||
69 | markw | int i=sofs;
|
|
int end=sofs+count;
|
|||
int pos = 0;
|
|||
46 | markw | ||
69 | markw | /* debug_pos = 0;
|
|
printf("WP:%x %d %d"),buff,sofs,count;
|
|||
debug_pos = -1;*/
|
|||
46 | markw | ||
69 | markw | for (;i!=end;++i,++pos)
|
|
{
|
|||
unsigned char temp = buff[pos];
|
|||
46 | markw | ||
69 | markw | unsigned int volatile* addr = (unsigned int volatile *)&mmc_sector_buffer[i&~3];
|
|
unsigned int prev = *(unsigned int volatile*)addr;
|
|||
((char unsigned *)&prev)[i&3] = temp;
|
|||
*addr = prev;
|
|||
//mmc_sector_buffer[i] = buff[pos];
|
|||
//printf("char:%c loc:%d,", buff[pos],i);
|
|||
}
|
|||
46 | markw | ||
69 | markw | /* debug_pos = 40;
|
|
printf("WP DONE:%x %d %d"),buff,sofs,count;
|
|||
debug_pos = -1;*/
|
|||
46 | markw | ||
69 | markw | res = RES_OK;
|
|
46 | markw | ||
69 | markw | return res;
|
|
}
|
|||
46 | markw | ||
69 | markw | void disk_writeflush()
|
|
{
|
|||
/* // Finalize write process
|
|||
int retry=16; //zkusi to maximalne 16x
|
|||
int ret;
|
|||
//printf(":WSECT:%d",n_actual_mmc_sector);
|
|||
do
|
|||
{
|
|||
ret = mmcWrite(n_actual_mmc_sector); //vraci 0 kdyz ok
|
|||
retry--;
|
|||
} while (ret && retry);
|
|||
//printf(":WD:");
|
|||
*/
|
|||
/*debug_pos = 0;
|
|||
printf("WF");
|
|||
debug_pos = -1;*/
|
|||
//printf(" WTF:%d:%x ", n_actual_mmc_sector, ((unsigned int *)mmc_sector_buffer)[0]);
|
|||
163 | markw | *zpu_out4 = n_actual_mmc_sector|0x08000000;
|
|
69 | markw | while (!*zpu_in4)
|
|
{
|
|||
// Wait until ready
|
|||
46 | markw | }
|
|
69 | markw | *zpu_out4 = 0;
|
|
//printf(" PT1 ");
|
|||
while (*zpu_in4)
|
|||
{
|
|||
// Wait until ready cleared
|
|||
}
|
|||
46 | markw | ||
69 | markw | //printf(" PT2 ");
|
|
/*debug_pos = 40;
|
|||
printf("DONE");
|
|||
debug_pos = -1;*/
|
|||
46 | markw | }
|