mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-23 16:28:05 +11:00
emul/hw/rc2014: implement blk write in sdc
All of that should help me implement sdc support much faster in Forth.
This commit is contained in:
parent
7544b3834b
commit
9c41744e46
@ -20,6 +20,7 @@ void sdc_init(SDC *sdc)
|
||||
sdc->resp = 0xff;
|
||||
sdc->fp = NULL;
|
||||
sdc->cmd17bytes = -1;
|
||||
sdc->cmd24bytes = -2;
|
||||
}
|
||||
|
||||
void sdc_cslow(SDC *sdc)
|
||||
@ -64,6 +65,47 @@ void sdc_spi_wr(SDC *sdc, uint8_t val)
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (sdc->cmd24bytes == -1) {
|
||||
if (val == 0xff) {
|
||||
// it's ok to receive idle bytes before the data token.
|
||||
return;
|
||||
}
|
||||
if (val == 0xfe) {
|
||||
// data token, good
|
||||
sdc->cmd24bytes = 0;
|
||||
} else {
|
||||
// something is wrong, cancel cmd24
|
||||
sdc->cmd24bytes = -2;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (sdc->cmd24bytes >= 0) {
|
||||
if (sdc->cmd24bytes < 512) {
|
||||
if (sdc->fp) {
|
||||
putc(val, sdc->fp);
|
||||
}
|
||||
sdc->crc16 = crc16(sdc->crc16, val);
|
||||
} else if (sdc->cmd24bytes == 512) {
|
||||
// CRC MSB
|
||||
if (val == (sdc->crc16>>8)) {
|
||||
fprintf(stderr, "Good CRC16 MSB\n");
|
||||
} else {
|
||||
fprintf(stderr, "Bad CRC16 MSB\n");
|
||||
}
|
||||
} else {
|
||||
if (val == (sdc->crc16&0xff)) {
|
||||
fprintf(stderr, "Good CRC16 LSB\n");
|
||||
} else {
|
||||
fprintf(stderr, "Bad CRC16 LSB\n");
|
||||
}
|
||||
// valid response for CMD24
|
||||
sdc->sendbuf[4] = 0x05;
|
||||
sdc->sendidx = 4;
|
||||
sdc->cmd24bytes = -3;
|
||||
}
|
||||
sdc->cmd24bytes++;
|
||||
return;
|
||||
}
|
||||
if ((sdc->recvidx == 0) && ((val > 0x7f) || (val < 0x40))) {
|
||||
// not a command
|
||||
return;
|
||||
@ -139,6 +181,17 @@ void sdc_spi_wr(SDC *sdc, uint8_t val)
|
||||
sdc->crc16 = 0;
|
||||
return;
|
||||
}
|
||||
if (cmd == 24) {
|
||||
fprintf(stderr, "cmd24\n");
|
||||
if (sdc->fp) {
|
||||
fseek(sdc->fp, arg2*512, SEEK_SET);
|
||||
}
|
||||
sdc->sendbuf[4] = 0x00;
|
||||
sdc->sendidx = 4;
|
||||
sdc->cmd24bytes = -1;
|
||||
sdc->crc16 = 0;
|
||||
return;
|
||||
}
|
||||
// Simulate success for any unknown command.
|
||||
sdc->sendbuf[4] = 0x00;
|
||||
sdc->sendidx = 4;
|
||||
|
@ -23,6 +23,9 @@ typedef struct {
|
||||
FILE *fp;
|
||||
// number of bytes read into the current CMD17. -1 means no CMD17 active.
|
||||
int cmd17bytes;
|
||||
// number of bytes received for the current CMD24. -2 means no CMD24 active.
|
||||
// -1 means we're still waiting for the data token.
|
||||
int cmd24bytes;
|
||||
// running crc16 during read and write operations.
|
||||
uint16_t crc16;
|
||||
} SDC;
|
||||
|
Loading…
Reference in New Issue
Block a user