1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-27 14:18:06 +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:
Virgil Dupras 2020-04-17 20:19:55 -04:00
parent 7544b3834b
commit 9c41744e46
2 changed files with 56 additions and 0 deletions

View File

@ -20,6 +20,7 @@ void sdc_init(SDC *sdc)
sdc->resp = 0xff; sdc->resp = 0xff;
sdc->fp = NULL; sdc->fp = NULL;
sdc->cmd17bytes = -1; sdc->cmd17bytes = -1;
sdc->cmd24bytes = -2;
} }
void sdc_cslow(SDC *sdc) void sdc_cslow(SDC *sdc)
@ -64,6 +65,47 @@ void sdc_spi_wr(SDC *sdc, uint8_t val)
} }
return; 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))) { if ((sdc->recvidx == 0) && ((val > 0x7f) || (val < 0x40))) {
// not a command // not a command
return; return;
@ -139,6 +181,17 @@ void sdc_spi_wr(SDC *sdc, uint8_t val)
sdc->crc16 = 0; sdc->crc16 = 0;
return; 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. // Simulate success for any unknown command.
sdc->sendbuf[4] = 0x00; sdc->sendbuf[4] = 0x00;
sdc->sendidx = 4; sdc->sendidx = 4;

View File

@ -23,6 +23,9 @@ typedef struct {
FILE *fp; FILE *fp;
// number of bytes read into the current CMD17. -1 means no CMD17 active. // number of bytes read into the current CMD17. -1 means no CMD17 active.
int cmd17bytes; 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. // running crc16 during read and write operations.
uint16_t crc16; uint16_t crc16;
} SDC; } SDC;