]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
Missing disk write end condition added, check write protection.
authorToni Wilen <twilen@winuae.net>
Sun, 12 May 2019 17:11:25 +0000 (20:11 +0300)
committerToni Wilen <twilen@winuae.net>
Sun, 12 May 2019 17:11:25 +0000 (20:11 +0300)
x86.cpp

diff --git a/x86.cpp b/x86.cpp
index dbe2ec58d9e852587d4e6198de5460847f74be86..4138c2563a45ac4a6e039687e48f5a419dfb83e5 100644 (file)
--- 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