diff --git a/docs/tec1g-emulation-review.md b/docs/tec1g-emulation-review.md index c360f76..f9f23bb 100644 --- a/docs/tec1g-emulation-review.md +++ b/docs/tec1g-emulation-review.md @@ -756,6 +756,7 @@ External add-on emulation. Fully independent of other stages. - [x] CMD58 (READ_OCR): respond with OCR register - [x] CMD17 (READ_SINGLE_BLOCK): respond with data token + 512 bytes from virtual image - [x] CMD24 (WRITE_SINGLE_BLOCK): accept data token + 512 bytes and write into virtual image +- [x] CMD13 (SEND_STATUS): respond with R2 status bytes - [x] Unit tests: full initialization sequence (CMD0 -> CMD8 -> ACMD41 -> CMD58) #### 6C — SD card integration with runtime diff --git a/src/platforms/tec1g/sd-spi.ts b/src/platforms/tec1g/sd-spi.ts index 7fb7591..cb396b0 100644 --- a/src/platforms/tec1g/sd-spi.ts +++ b/src/platforms/tec1g/sd-spi.ts @@ -254,6 +254,12 @@ export class SdSpi { this.delayBytes = 1; break; } + case 13: { + const r1 = this.ready ? 0x00 : 0x01; + this.pendingResponse = [r1, 0x00]; + this.delayBytes = 1; + break; + } case 17: { if (!this.ready) { this.pendingResponse = [0x01]; diff --git a/tests/platforms/tec1g/sd-spi.test.ts b/tests/platforms/tec1g/sd-spi.test.ts index 975081f..babbc4b 100644 --- a/tests/platforms/tec1g/sd-spi.test.ts +++ b/tests/platforms/tec1g/sd-spi.test.ts @@ -178,4 +178,28 @@ describe('SdSpi', () => { expect(image[1]).toBe(0x34); expect(image[2]).toBe(0x56); }); + + it('responds to CMD13 with status', () => { + const spi = new SdSpi({ csMask: CS_BIT }); + writeSpi(spi, 0x00); + sendCommand(spi, [0x77, 0x00, 0x00, 0x00, 0x00, 0x65]); + readResponseByte(spi); + sendCommand(spi, [0x69, 0x40, 0x00, 0x00, 0x00, 0x77]); + readResponseByte(spi); + sendCommand(spi, [0x77, 0x00, 0x00, 0x00, 0x00, 0x65]); + readResponseByte(spi); + sendCommand(spi, [0x69, 0x40, 0x00, 0x00, 0x00, 0x77]); + readResponseByte(spi); + sendCommand(spi, [0x4d, 0x00, 0x00, 0x00, 0x00, 0xff]); + expect(readResponseByte(spi)).toBe(0x00); + expect(readByte(spi)).toBe(0x00); + }); + + it('returns idle status for CMD13 before init', () => { + const spi = new SdSpi({ csMask: CS_BIT }); + writeSpi(spi, 0x00); + sendCommand(spi, [0x4d, 0x00, 0x00, 0x00, 0x00, 0xff]); + expect(readResponseByte(spi)).toBe(0x01); + expect(readByte(spi)).toBe(0x00); + }); });