From: Toni Wilen Date: Sun, 12 May 2019 17:11:25 +0000 (+0300) Subject: Missing disk write end condition added, check write protection. X-Git-Tag: 4300~206 X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=c8560891c3c3e1d8f0ff0e8707d419c194a4b67e;p=francis%2Fwinuae.git Missing disk write end condition added, check write protection. --- diff --git a/x86.cpp b/x86.cpp index dbe2ec58..4138c256 100644 --- a/x86.cpp +++ b/x86.cpp @@ -1013,6 +1013,7 @@ static void floppy_do_cmd(struct x86_bridge *xb) floppy_cmd[2], floppy_cmd[3], floppy_cmd[4], floppy_cmd[5], floppy_cmd[6], floppy_cmd[7], floppy_cmd[8]); write_log(_T("DMA addr %08x len %04x\n"), dma[2].page | dma[2].ac, dma[2].ab); + write_log(_T("IMG: Secs=%d Heads=%d\n"), fr.secs, fr.heads); #endif floppy_delay_hsync = 50; int eot = floppy_cmd[6]; @@ -1023,20 +1024,26 @@ static void floppy_do_cmd(struct x86_bridge *xb) floppy_status[0] |= 0x40; // abnormal termination floppy_status[2] |= 0x20; // wrong cylinder } else if (fr.img) { - bool end = false; + int end = 0; pcf->sector = floppy_cmd[4] - 1; pcf->head = (floppy_cmd[1] & 4) ? 1 : 0; - while (!end) { + while (!end && !fr.wrprot) { int len = 128 << floppy_cmd[5]; uae_u8 buf[512] = { 0 }; for (int i = 0; i < 512 && i < len; i++) { int v = dma_channel_read(2); - if (v < 0) + if (v < 0) { + end = -1; break; + } buf[i] = v; - if (v >= 0x10000) + if (v >= 0x10000) { + end = 1; break; + } } + if (end < 0) + break; zfile_fseek(fr.img, (pcf->cyl * fr.secs * fr.heads + pcf->head * fr.secs + pcf->sector) * 512, SEEK_SET); zfile_fwrite(buf, 1, 512, fr.img); pcf->sector++; @@ -1086,6 +1093,7 @@ static void floppy_do_cmd(struct x86_bridge *xb) floppy_cmd[2], floppy_cmd[3], floppy_cmd[4], floppy_cmd[5], floppy_cmd[6], floppy_cmd[7], floppy_cmd[8]); write_log(_T("DMA addr %08x len %04x\n"), dma[2].page | dma[2].ac, dma[2].cb); + write_log(_T("IMG: Secs=%d Heads=%d\n"), fr.secs, fr.heads); #endif floppy_delay_hsync = 50; int eot = floppy_cmd[6]; @@ -1197,6 +1205,7 @@ static void floppy_do_cmd(struct x86_bridge *xb) floppy_num, (floppy_cmd[0] & 0x40) ? 1 : 0, floppy_cmd[2], floppy_cmd[3], floppy_cmd[4], floppy_cmd[5]); write_log(_T("DMA addr %08x len %04x\n"), dma[2].page | dma[2].ac, dma[2].cb); + write_log(_T("IMG: Secs=%d Heads=%d\n"), fr.secs, fr.heads); #endif int secs = floppy_cmd[3]; if (valid_floppy && fr.img) { @@ -1204,7 +1213,7 @@ static void floppy_do_cmd(struct x86_bridge *xb) pcf->head = (floppy_cmd[1] & 4) ? 1 : 0; uae_u8 buf[512]; memset(buf, floppy_cmd[5], sizeof buf); - for (int i = 0; i < secs && i < fr.secs; i++) { + for (int i = 0; i < secs && i < fr.secs && !fr.wrprot; i++) { uae_u8 cx = dma_channel_read(2); uae_u8 hx = dma_channel_read(2); uae_u8 rx = dma_channel_read(2); @@ -1215,6 +1224,7 @@ static void floppy_do_cmd(struct x86_bridge *xb) #endif zfile_fseek(fr.img, (pcf->cyl * fr.secs * fr.heads + pcf->head * fr.secs + pcf->sector) * 512, SEEK_SET); zfile_fwrite(buf, 1, 512, fr.img); + pcf->sector++; } } else { floppy_status[0] |= 0x40; // abnormal termination