Introduce MBR struct; simplify cdrom emulation code.

Define and use a struct for the master boot record.
Simplify cdrom emulation chs setting code.
Fix an apparent bug in harddrive chs setting - it wasn't properly
    masking the spt/cyl fields.
diff --git a/src/boot.c b/src/boot.c
index 1f0647a..6db213a 100644
--- a/src/boot.c
+++ b/src/boot.c
@@ -130,7 +130,8 @@
         /* Always check the signature on a HDD boot sector; on FDD,
          * only do the check if configured for it */
         if (type != IPL_TYPE_FLOPPY || IPL.checkfloppysig) {
-            if (GET_FARVAR(bootseg, *(u16*)0x1fe) != 0xaa55) {
+            struct mbr_s *mbr = (void*)0;
+            if (GET_FARVAR(bootseg, mbr->signature) != MBR_SIGNATURE) {
                 print_boot_failure(type, 0);
                 return;
             }
diff --git a/src/cdrom.c b/src/cdrom.c
index fdef873..389a42e 100644
--- a/src/cdrom.c
+++ b/src/cdrom.c
@@ -519,38 +519,38 @@
         // Floppy emulation
         SET_EBDA2(ebda_seg, cdemu.emulated_drive, 0x00);
         SETBITS_BDA(equipment_list_flags, 0x41);
+
+        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);
+            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);
+            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);
+            break;
+        }
     } else {
         // Harddrive emulation
         SET_EBDA2(ebda_seg, cdemu.emulated_drive, 0x80);
         SET_BDA(hdcount, GET_BDA(hdcount) + 1);
-    }
 
-    // Remember the media type
-    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);
-        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);
-        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);
-        break;
-    case 0x04: { // Harddrive
-        u16 spt = GET_FARVAR(boot_segment,*(u8*)(446+6));
-        u16 cyl = (spt << 2) + GET_FARVAR(boot_segment,*(u8*)(446+7)) + 1;
-        u16 heads = GET_FARVAR(boot_segment,*(u8*)(446+5)) + 1;
-        SET_EBDA2(ebda_seg, cdemu.spt, spt & 0x3f);
-        SET_EBDA2(ebda_seg, cdemu.cylinders, cyl);
-        SET_EBDA2(ebda_seg, cdemu.heads, heads);
-        break;
-    }
+        // Peak at partition table to get chs.
+        struct mbr_s *mbr = (void*)0;
+        u8 sptcyl = GET_FARVAR(boot_segment, mbr->partitions[0].last.sptcyl);
+        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);
     }
 
     // everything is ok, so from now on, the emulation is active
diff --git a/src/disk.h b/src/disk.h
index fae66e3..9a4bf37 100644
--- a/src/disk.h
+++ b/src/disk.h
@@ -104,6 +104,40 @@
 
 
 /****************************************************************
+ * Master boot record
+ ****************************************************************/
+
+struct packed_chs_s {
+    u8 heads;
+    u8 sptcyl;
+    u8 cyllow;
+};
+
+struct partition_s {
+    u8 status;
+    struct packed_chs_s first;
+    u8 type;
+    struct packed_chs_s last;
+    u32 lba;
+    u32 count;
+} PACKED;
+
+struct mbr_s {
+    u8 code[440];
+    // 0x01b8
+    u32 diskseg;
+    // 0x01bc
+    u16 null;
+    // 0x01be
+    struct partition_s partitions[4];
+    // 0x01fe
+    u16 signature;
+} PACKED;
+
+#define MBR_SIGNATURE 0xaa55
+
+
+/****************************************************************
  * Disk command request
  ****************************************************************/