From 84487caf9c95484727083fb372a15bb885416e72 Mon Sep 17 00:00:00 2001 From: sorgelig Date: Fri, 2 Oct 2020 03:17:07 +0800 Subject: [PATCH] ao486: support for CD image mounting from core. --- support/x86/x86_cdrom.cpp | 23 +++++++++++++++++++++++ support/x86/x86_ide.cpp | 11 +++++++++++ support/x86/x86_ide.h | 1 + 3 files changed, 35 insertions(+) diff --git a/support/x86/x86_cdrom.cpp b/support/x86/x86_cdrom.cpp index e1510d7..78d745e 100644 --- a/support/x86/x86_cdrom.cpp +++ b/support/x86/x86_cdrom.cpp @@ -1192,6 +1192,24 @@ void cdrom_handle_pkt(ide_config *ide) } } +static void prep_FA_cmd(ide_config *ide) +{ + ide->prepcnt = ide->regs.sector_count; + if (!ide->prepcnt || ide->prepcnt > ide_io_max_size) ide->prepcnt = ide_io_max_size; + + ide->regs.status = ATA_STATUS_RDY | ATA_STATUS_DRQ | ATA_STATUS_IRQ; + + if (ide->state == IDE_STATE_INIT_RW) + { + ide->regs.status &= ~ATA_STATUS_IRQ; + ide->null = 1; + } + + ide->state = IDE_STATE_WAIT_WR; + ide->regs.pkt_io_size = ide->prepcnt * 256; + ide_set_regs(ide); +} + int cdrom_handle_cmd(ide_config *ide) { uint8_t drv; @@ -1211,6 +1229,11 @@ int cdrom_handle_cmd(ide_config *ide) ide->state = IDE_STATE_WAIT_END; break; + case 0xFA: // mount image + ide->state = IDE_STATE_INIT_RW; + prep_FA_cmd(ide); + break; + case 0xEC: // identify (fail) dbg_printf("identify (CD)\n"); ide->regs.sector = 1; diff --git a/support/x86/x86_ide.cpp b/support/x86/x86_ide.cpp index f8e3aac..5c95eb7 100644 --- a/support/x86/x86_ide.cpp +++ b/support/x86/x86_ide.cpp @@ -101,12 +101,15 @@ void ide_set_regs(ide_config *ide) void x86_ide_set(uint32_t num, uint32_t baseaddr, fileTYPE *f, int ver, int cd) { + int drvnum = num; int drv = (ver == 3) ? (num & 1) : 0; if (ver == 3) num >>= 1; drive_t *drive = &ide_inst[num].drive[drv]; ide_inst[num].base = baseaddr; + ide_inst[num].drive[drv].drvnum = drvnum; + drive->f = f; drive->cylinders = 0; @@ -449,6 +452,14 @@ static void process_write(ide_config *ide) ide->regs.cylinder = lba; lba >>= 16; ide->regs.head = lba & 0xF; + + if (ide->regs.cmd == 0xFA) + { + ide->regs.sector_count = 0; + char* filename = user_io_make_filepath(HomeDir(), (char*)ide_buf); + printf("Request for new image for drive %d: %s\n", ide->drive[ide->regs.drv].drvnum, filename); + x86_set_image(ide->drive[ide->regs.drv].drvnum + 2, filename); + } } static int handle_hdd(ide_config *ide) diff --git a/support/x86/x86_ide.h b/support/x86/x86_ide.h index 5626cd1..70db020 100644 --- a/support/x86/x86_ide.h +++ b/support/x86/x86_ide.h @@ -72,6 +72,7 @@ typedef struct { fileTYPE *f; uint8_t present; + uint8_t drvnum; uint16_t cylinders; uint16_t heads;