// 16bit code to access cdrom drives.
//
-// Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net>
+// Copyright (C) 2008,2009 Kevin O'Connor <kevin@koconnor.net>
// Copyright (C) 2002 MandrakeSoft S.A.
//
// This file may be distributed under the terms of the GNU LGPLv3 license.
#include "util.h" // memset
#include "bregs.h" // struct bregs
#include "biosvar.h" // GET_EBDA
-#include "atabits.h" // ATA_TYPE_ATAPI
+#include "ata.h" // ATA_CMD_REQUEST_SENSE
/****************************************************************
* CD emulation
****************************************************************/
+static void
+cdemu_1302(struct bregs *regs, u8 device)
+{
+ cdemu_access(regs, device, CMD_READ);
+}
+
+static void
+cdemu_1304(struct bregs *regs, u8 device)
+{
+ cdemu_access(regs, device, CMD_VERIFY);
+}
+
// read disk drive parameters
static void
cdemu_1308(struct bregs *regs, u8 device)
{
u16 ebda_seg = get_ebda_seg();
- u16 nlc = GET_EBDA2(ebda_seg, cdemu.cylinders) - 1;
- u16 nlh = GET_EBDA2(ebda_seg, cdemu.heads) - 1;
- u16 nlspt = GET_EBDA2(ebda_seg, cdemu.spt);
+ u16 nlc = GET_EBDA2(ebda_seg, cdemu.lchs.cylinders) - 1;
+ u16 nlh = GET_EBDA2(ebda_seg, cdemu.lchs.heads) - 1;
+ u16 nlspt = GET_EBDA2(ebda_seg, cdemu.lchs.spt);
regs->al = 0x00;
regs->bl = 0x00;
device += GET_EBDA2(ebda_seg, cdemu.device_spec);
switch (regs->ah) {
- // These functions are the same as for hard disks
- case 0x02:
- case 0x04:
- disk_13(regs, device);
- break;
+ case 0x02: cdemu_1302(regs, device); break;
+ case 0x04: cdemu_1304(regs, device); break;
+ case 0x08: cdemu_1308(regs, device); break;
// These functions are the same as standard CDROM.
case 0x00:
cdrom_13(regs, device);
break;
- case 0x08: cdemu_1308(regs, device); break;
-
default: disk_13XX(regs, device); break;
}
}
SET_INT13ET(regs, buffer_segment, GET_EBDA2(ebda_seg, cdemu.buffer_segment));
SET_INT13ET(regs, load_segment, GET_EBDA2(ebda_seg, cdemu.load_segment));
SET_INT13ET(regs, sector_count, GET_EBDA2(ebda_seg, cdemu.sector_count));
- SET_INT13ET(regs, cylinders, GET_EBDA2(ebda_seg, cdemu.cylinders));
- SET_INT13ET(regs, sectors, GET_EBDA2(ebda_seg, cdemu.spt));
- SET_INT13ET(regs, heads, GET_EBDA2(ebda_seg, cdemu.heads));
+ SET_INT13ET(regs, cylinders, GET_EBDA2(ebda_seg, cdemu.lchs.cylinders));
+ SET_INT13ET(regs, sectors, GET_EBDA2(ebda_seg, cdemu.lchs.spt));
+ SET_INT13ET(regs, heads, GET_EBDA2(ebda_seg, cdemu.lchs.heads));
// If we have to terminate emulation
if (regs->al == 0x00) {
}
}
- if (blksize != GET_GLOBAL(ATA.devices[device].blksize)) {
+ if (blksize != GET_GLOBAL(Drives.drives[device].blksize)) {
printf("Unsupported sector size %u\n", blksize);
return -1;
}
cdrom_boot(int cdid)
{
// Verify device is a cdrom.
- if (cdid >= ATA.cdcount)
+ if (cdid >= Drives.cdcount)
return 1;
- int driveid = GET_GLOBAL(ATA.idmap[1][cdid]);
- if (GET_GLOBAL(ATA.devices[driveid].device) != ATA_DEVICE_CDROM)
- return 2;
+ int driveid = GET_GLOBAL(Drives.idmap[1][cdid]);
int ret = atapi_is_ready(driveid);
if (ret)
// Read the Boot Record Volume Descriptor
u8 buffer[2048];
struct disk_op_s dop;
+ memset(&dop, 0, sizeof(dop));
dop.driveid = driveid;
dop.lba = 0x11;
dop.count = 1;
switch (media) {
case 0x01: // 1.2M floppy
- SET_EBDA2(ebda_seg, cdemu.spt, 15);
- SET_EBDA2(ebda_seg, cdemu.cylinders, 80);
- SET_EBDA2(ebda_seg, cdemu.heads, 2);
+ SET_EBDA2(ebda_seg, cdemu.lchs.spt, 15);
+ SET_EBDA2(ebda_seg, cdemu.lchs.cylinders, 80);
+ SET_EBDA2(ebda_seg, cdemu.lchs.heads, 2);
break;
case 0x02: // 1.44M floppy
- SET_EBDA2(ebda_seg, cdemu.spt, 18);
- SET_EBDA2(ebda_seg, cdemu.cylinders, 80);
- SET_EBDA2(ebda_seg, cdemu.heads, 2);
+ SET_EBDA2(ebda_seg, cdemu.lchs.spt, 18);
+ SET_EBDA2(ebda_seg, cdemu.lchs.cylinders, 80);
+ SET_EBDA2(ebda_seg, cdemu.lchs.heads, 2);
break;
case 0x03: // 2.88M floppy
- SET_EBDA2(ebda_seg, cdemu.spt, 36);
- SET_EBDA2(ebda_seg, cdemu.cylinders, 80);
- SET_EBDA2(ebda_seg, cdemu.heads, 2);
+ SET_EBDA2(ebda_seg, cdemu.lchs.spt, 36);
+ SET_EBDA2(ebda_seg, cdemu.lchs.cylinders, 80);
+ SET_EBDA2(ebda_seg, cdemu.lchs.heads, 2);
break;
}
} else {
u8 cyllow = GET_FARVAR(boot_segment, mbr->partitions[0].last.cyllow);
u8 heads = GET_FARVAR(boot_segment, mbr->partitions[0].last.heads);
- SET_EBDA2(ebda_seg, cdemu.spt, sptcyl & 0x3f);
- SET_EBDA2(ebda_seg, cdemu.cylinders, ((sptcyl<<2)&0x300) + cyllow + 1);
- SET_EBDA2(ebda_seg, cdemu.heads, heads + 1);
+ SET_EBDA2(ebda_seg, cdemu.lchs.spt, sptcyl & 0x3f);
+ SET_EBDA2(ebda_seg, cdemu.lchs.cylinders
+ , ((sptcyl<<2)&0x300) + cyllow + 1);
+ SET_EBDA2(ebda_seg, cdemu.lchs.heads, heads + 1);
}
// everything is ok, so from now on, the emulation is active