1.1 diff -r b3f309d46e97 -r feb84193a43a src/wd279x.c 1.2 --- a/src/wd279x.c Mon Dec 13 03:00:43 2010 +0000 1.3 +++ b/src/wd279x.c Tue Dec 14 02:41:40 2010 +0000 1.4 @@ -170,9 +170,9 @@ 1.5 // Get current status flags (set by last command) 1.6 // DRQ bit 1.7 if (ctx->cmd_has_drq) { 1.8 - printf("\tWDFDC rd sr, has drq, pos=%lu len=%lu\n", ctx->data_pos, ctx->data_len); 1.9 temp = ctx->status & ~0x03; 1.10 temp |= (ctx->data_pos < ctx->data_len) ? 0x02 : 0x00; 1.11 + printf("\tWDFDC rd sr, has drq, pos=%lu len=%lu, sr=0x%02X\n", ctx->data_pos, ctx->data_len, temp); 1.12 } else { 1.13 temp = ctx->status & ~0x01; 1.14 } 1.15 @@ -384,6 +384,20 @@ 1.16 ctx->head = (val & 0x02) ? 1 : 0; 1.17 printf("WD279X: READ SECTOR cmd=%02X chs=%d:%d:%d\n", cmd, ctx->track, ctx->head, ctx->sector); 1.18 // Read Sector or Read Sector Multiple 1.19 + 1.20 + // Check to see if the cyl, hd and sec are valid 1.21 + if ((ctx->track > (ctx->geom_tracks-1)) || (ctx->head > (ctx->geom_heads-1)) || (ctx->sector > ctx->geom_spt) || (ctx->sector == 0)) { 1.22 + fprintf(stderr, "*** WD2797 ALERT: CHS parameter limit exceeded! CHS=%d:%d:%d, maxCHS=%d:%d:%d\n", 1.23 + ctx->track, ctx->head, ctx->sector, 1.24 + ctx->geom_tracks-1, ctx->geom_heads-1, ctx->geom_spt); 1.25 + // CHS parameters exceed limits 1.26 + ctx->status = 0x10; // Record Not Found 1.27 + break; 1.28 + // Set IRQ only if IRQL has been cleared (no pending IRQs) 1.29 + ctx->irqe = ctx->irql ? ctx->irqe : true; 1.30 + ctx->irql = true; 1.31 + } 1.32 + 1.33 // reset data pointers 1.34 ctx->data_pos = ctx->data_len = 0; 1.35 1.36 @@ -395,7 +409,11 @@ 1.37 1.38 for (int i=0; i<temp; i++) { 1.39 // Calculate the LBA address of the required sector 1.40 - lba = ((((ctx->track * ctx->geom_heads) + ctx->head) * ctx->geom_spt) + ((ctx->sector + i - 1) % ctx->geom_spt)) * ctx->geom_secsz; 1.41 +// lba = ((((ctx->track * ctx->geom_heads) + ctx->head) * ctx->geom_spt) + ((ctx->sector + i - 1) % ctx->geom_spt)) * ctx->geom_secsz; 1.42 + // LBA = (C * nHeads * nSectors) + (H * nSectors) + S - 1 1.43 + lba = (((ctx->track * ctx->geom_heads * ctx->geom_spt) + (ctx->head * ctx->geom_spt) + ctx->sector) + i) - 1; 1.44 + // convert LBA to byte address 1.45 + lba *= ctx->geom_secsz; 1.46 printf("\tREAD lba = %lu\n", lba); 1.47 1.48 // Read the sector from the file 1.49 @@ -408,7 +426,7 @@ 1.50 ctx->status = 0; 1.51 // B6 = 0 1.52 // B5 = Record Type -- 1 = deleted, 0 = normal. We can't emulate anything but normal data blocks. 1.53 - // B4 = Record Not Found. We're not going to see this... FIXME-not emulated 1.54 + // B4 = Record Not Found. Basically, the CHS parameters are bullcrap. 1.55 // B3 = CRC Error. Not possible. 1.56 // B2 = Lost Data. Caused if DRQ isn't serviced in time. FIXME-not emulated 1.57 // B1 = DRQ. Data request.