mirror of
https://github.com/Spritetm/minimacplus.git
synced 2024-06-10 22:29:41 +00:00
Quick & dirty HD write implementation. Hey, it works!
This commit is contained in:
parent
20c4e48be2
commit
cb147908ee
|
@ -25,16 +25,27 @@ const uint8_t inq_resp[95]={
|
||||||
'1','.','0',' ',' ',' ',' ',' ', //prod rev lvl
|
'1','.','0',' ',' ',' ',' ',' ', //prod rev lvl
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void writeSector(HdPriv *hd, unsigned int lba, uint8_t *data) {
|
||||||
|
uint8_t *secdat=malloc(4096);
|
||||||
|
assert(secdat);
|
||||||
|
unsigned int lbaStart=lba&(~7);
|
||||||
|
unsigned int lbaOff=lba&7;
|
||||||
|
assert(esp_partition_read(hd->part, lbaStart*512, secdat, 4096)==ESP_OK);
|
||||||
|
assert(esp_partition_erase_range(hd->part, lbaStart*512, 4096)==ESP_OK);
|
||||||
|
for (int i=0; i<512; i++) secdat[lbaOff*512+i]=data[i];
|
||||||
|
assert(esp_partition_write(hd->part, lbaStart*512, secdat, 4096)==ESP_OK);
|
||||||
|
free(secdat);
|
||||||
|
}
|
||||||
|
|
||||||
static int hdScsiCmd(SCSITransferData *data, unsigned int cmd, unsigned int len, unsigned int lba, void *arg) {
|
static int hdScsiCmd(SCSITransferData *data, unsigned int cmd, unsigned int len, unsigned int lba, void *arg) {
|
||||||
int ret=0;
|
int ret=0;
|
||||||
static uint8_t *bb=NULL;
|
static uint8_t *bb=NULL;
|
||||||
HdPriv *hd=(HdPriv*)arg;
|
HdPriv *hd=(HdPriv*)arg;
|
||||||
if (cmd==0x8 || cmd==0x28) { //read
|
if (cmd==0x8 || cmd==0x28) { //read
|
||||||
printf("HD: Read %d bytes from LBA %d.\n", len*512, lba);
|
printf("HD: Read %d bytes from LBA %d.\n", len*512, lba);
|
||||||
#if 0 //spi ram read/write does not play well with flash reads
|
|
||||||
|
|
||||||
assert(esp_partition_read(hd->part, lba*512, data->data, len*512)==ESP_OK);
|
assert(esp_partition_read(hd->part, lba*512, data->data, len*512)==ESP_OK);
|
||||||
#else
|
#if 0
|
||||||
|
//alternate mmap solution
|
||||||
uint8_t *buf;
|
uint8_t *buf;
|
||||||
spi_flash_mmap_handle_t handle;
|
spi_flash_mmap_handle_t handle;
|
||||||
esp_partition_mmap(hd->part, lba*512, len*512, SPI_FLASH_MMAP_DATA, &buf, &handle);
|
esp_partition_mmap(hd->part, lba*512, len*512, SPI_FLASH_MMAP_DATA, &buf, &handle);
|
||||||
|
@ -43,6 +54,15 @@ static int hdScsiCmd(SCSITransferData *data, unsigned int cmd, unsigned int len,
|
||||||
#endif
|
#endif
|
||||||
// hexdump(data->data, len*512);
|
// hexdump(data->data, len*512);
|
||||||
ret=len*512;
|
ret=len*512;
|
||||||
|
} else if (cmd==0x0A || cmd==0x2A) { //write
|
||||||
|
uint8_t *dp=data->data;
|
||||||
|
while(len) {
|
||||||
|
writeSector(hd, lba, dp);
|
||||||
|
lba++;
|
||||||
|
dp+=512;
|
||||||
|
len--;
|
||||||
|
}
|
||||||
|
ret=0;
|
||||||
} else if (cmd==0x12) { //inquiry
|
} else if (cmd==0x12) { //inquiry
|
||||||
printf("HD: Inquery\n");
|
printf("HD: Inquery\n");
|
||||||
memcpy(data->data, inq_resp, sizeof(inq_resp));
|
memcpy(data->data, inq_resp, sizeof(inq_resp));
|
||||||
|
|
|
@ -107,7 +107,7 @@ static void parseScsiCmd(int isRead) {
|
||||||
printf("SCSI: UNSUPPORTED CMD %x\n", cmd);
|
printf("SCSI: UNSUPPORTED CMD %x\n", cmd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// printf("SCSI: CMD %x LBA %x LEN %x CTRL %x\n", cmd, lba, len, ctrl);
|
printf("SCSI: CMD %x LBA %x LEN %x CTRL %x %s\n", cmd, lba, len, ctrl, isRead?"*READ*":"*WRITE*");
|
||||||
if (ncr.dev[ncr.selected]) {
|
if (ncr.dev[ncr.selected]) {
|
||||||
ncr.datalen=ncr.dev[ncr.selected]->scsiCmd(&ncr.data, cmd, len, lba, ncr.dev[ncr.selected]->arg);
|
ncr.datalen=ncr.dev[ncr.selected]->scsiCmd(&ncr.data, cmd, len, lba, ncr.dev[ncr.selected]->arg);
|
||||||
}
|
}
|
||||||
|
@ -178,9 +178,13 @@ unsigned int ncrRead(unsigned int addr, unsigned int dack) {
|
||||||
|
|
||||||
void ncrWrite(unsigned int addr, unsigned int dack, unsigned int val) {
|
void ncrWrite(unsigned int addr, unsigned int dack, unsigned int val) {
|
||||||
unsigned int pc=m68k_get_reg(NULL, M68K_REG_PC);
|
unsigned int pc=m68k_get_reg(NULL, M68K_REG_PC);
|
||||||
|
|
||||||
if (addr==0) {
|
if (addr==0) {
|
||||||
if (ncr.mode&MODE_DMA && dack) {
|
if (ncr.mode&MODE_DMA && dack) {
|
||||||
printf("UNSUPPORTED: dma write\n");
|
ncr.buf[ncr.bufpos]=val;
|
||||||
|
if ((ncr.tcr&TCR_IO)==0) {
|
||||||
|
if (ncr.bufpos!=ncr.bufmax) ncr.bufpos++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ncr.dout=val;
|
ncr.dout=val;
|
||||||
ncr.din=val;
|
ncr.din=val;
|
||||||
|
@ -234,10 +238,10 @@ void ncrWrite(unsigned int addr, unsigned int dack, unsigned int val) {
|
||||||
int newtcr=(val&7);
|
int newtcr=(val&7);
|
||||||
if (oldtcr==0 && ncr.bufpos) {
|
if (oldtcr==0 && ncr.bufpos) {
|
||||||
//End of data out phase
|
//End of data out phase
|
||||||
parseScsiCmd(1);
|
parseScsiCmd(0);
|
||||||
} else if ((oldtcr==TCR_CD) && (newtcr==TCR_IO)) {
|
} else if ((oldtcr==TCR_CD) && (newtcr==TCR_IO)) {
|
||||||
//Start of data in phase
|
//Start of data in phase
|
||||||
parseScsiCmd(0);
|
parseScsiCmd(1);
|
||||||
}
|
}
|
||||||
if ((ncr.tcr&0x7)==TCR_IO) {
|
if ((ncr.tcr&0x7)==TCR_IO) {
|
||||||
printf("Data Out finished: Host read %d/%d bytes.\n", ncr.bufpos, ncr.datalen);
|
printf("Data Out finished: Host read %d/%d bytes.\n", ncr.bufpos, ncr.datalen);
|
||||||
|
|
|
@ -33,6 +33,11 @@ static int hdScsiCmd(SCSITransferData *data, unsigned int cmd, unsigned int len,
|
||||||
fread(data->data, 512, len, hd->f);
|
fread(data->data, 512, len, hd->f);
|
||||||
printf("HD: Read %d bytes.\n", len*512);
|
printf("HD: Read %d bytes.\n", len*512);
|
||||||
ret=len*512;
|
ret=len*512;
|
||||||
|
} else if (cmd==0xA || cmd==0x2A) { //write
|
||||||
|
fseek(hd->f, lba*512, SEEK_SET);
|
||||||
|
fwrite(data->data, 512, len, hd->f);
|
||||||
|
printf("HD: Write %d bytes\n", len*512);
|
||||||
|
ret=0;
|
||||||
} else if (cmd==0x12) { //inquiry
|
} else if (cmd==0x12) { //inquiry
|
||||||
printf("HD: Inquery\n");
|
printf("HD: Inquery\n");
|
||||||
memcpy(data->data, inq_resp, sizeof(inq_resp));
|
memcpy(data->data, inq_resp, sizeof(inq_resp));
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
#define TME_ROMSIZE (128*1024)
|
#define TME_ROMSIZE (128*1024)
|
||||||
|
|
||||||
|
|
||||||
#ifdef CONFIG_SPIRAM_SUPPORT_MALLOC
|
#ifdef CONFIG_SPIRAM_SUPPORT_MALLOC
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
|
|
Loading…
Reference in New Issue
Block a user