[48069] | 1 | /* $Id: floppyt.c 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
| 3 | * Floppy drive tables.
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2011-2023 Oracle and/or its affiliates.
|
---|
[48069] | 8 | *
|
---|
[96407] | 9 | * This file is part of VirtualBox base platform packages, as
|
---|
| 10 | * available from https://www.virtualbox.org.
|
---|
| 11 | *
|
---|
| 12 | * This program is free software; you can redistribute it and/or
|
---|
| 13 | * modify it under the terms of the GNU General Public License
|
---|
| 14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 15 | * License.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful, but
|
---|
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | * General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 24 | *
|
---|
| 25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
[48069] | 26 | */
|
---|
| 27 |
|
---|
| 28 | #include <stdint.h>
|
---|
| 29 | #include <string.h>
|
---|
| 30 | #include "biosint.h"
|
---|
| 31 | #include "inlines.h"
|
---|
| 32 |
|
---|
| 33 | /**
|
---|
| 34 | * Extended DPT (Disk Parameter Table) structure.
|
---|
| 35 | */
|
---|
| 36 | typedef struct
|
---|
| 37 | {
|
---|
| 38 | uint8_t spec1; /* First SPECIFY byte. */
|
---|
| 39 | uint8_t spec2; /* Second SPECIFY byte. */
|
---|
| 40 | uint8_t mot_wait; /* Motor wait time after operation. */
|
---|
| 41 | uint8_t ss_code; /* Sector size code. */
|
---|
| 42 | uint8_t eot; /* End of Track (ID of last sector). */
|
---|
| 43 | uint8_t gap; /* Gap length. */
|
---|
| 44 | uint8_t dtl; /* Data length. */
|
---|
| 45 | uint8_t fmt_gap; /* Gap length for format. */
|
---|
| 46 | uint8_t fmt_fill; /* Format fill byte. */
|
---|
| 47 | uint8_t hd_settle; /* Head settle time (msec). */
|
---|
| 48 | uint8_t mot_start; /* Motor start time (1/8 sec units). */
|
---|
| 49 | uint8_t max_trk; /* Maximum track number. */
|
---|
| 50 | uint8_t rate; /* Data transfer rate code. */
|
---|
| 51 | } dpt_ext;
|
---|
| 52 |
|
---|
| 53 | ct_assert(sizeof(dpt_ext) == 13);
|
---|
| 54 |
|
---|
| 55 | /* Motor spin-up wait time in BIOS ticks (~2 seconds). */
|
---|
| 56 | #define MOTOR_WAIT 0x25
|
---|
| 57 |
|
---|
| 58 | /* Data rates as stored in the DPT */
|
---|
| 59 | #define RATE_250K 0x80
|
---|
| 60 | #define RATE_300K 0x40
|
---|
| 61 | #define RATE_500K 0x00
|
---|
| 62 | #define RATE_1M 0xC0
|
---|
| 63 |
|
---|
| 64 | /* In the 13-entry DPT, 7 entries are constant. Use a macro to set those. */
|
---|
| 65 | #define MAKE_DPT_ENTRY(sp1, eot, gap, fgp, mxt, dtr) \
|
---|
| 66 | { sp1, 2, MOTOR_WAIT, 2, eot, gap, 0xFF, fgp, 0xF6, 15, 8, mxt, dtr }
|
---|
| 67 |
|
---|
| 68 | dpt_ext fd_parm[] = {
|
---|
| 69 | MAKE_DPT_ENTRY(0xDF, 9, 0x2A, 0x50, 39, RATE_250K), /* 360K disk/360K drive */
|
---|
| 70 | MAKE_DPT_ENTRY(0xDF, 9, 0x2A, 0x50, 39, RATE_300K), /* 360K disk/1.2M drive */
|
---|
| 71 | MAKE_DPT_ENTRY(0xDF, 15, 0x1B, 0x54, 79, RATE_500K), /* 1.2M disk */
|
---|
| 72 | MAKE_DPT_ENTRY(0xDF, 9, 0x2A, 0x50, 79, RATE_250K), /* 720K disk */
|
---|
| 73 | MAKE_DPT_ENTRY(0xAF, 18, 0x1B, 0x6C, 79, RATE_500K), /* 1.44M disk */
|
---|
| 74 | MAKE_DPT_ENTRY(0xAF, 36, 0x1B, 0x54, 79, RATE_1M), /* 2.88M disk */
|
---|
| 75 | MAKE_DPT_ENTRY(0xAF, 255, 0x1B, 0x54, 255, RATE_500K) /* Fake mega-disk */
|
---|
| 76 | };
|
---|
| 77 |
|
---|
| 78 | typedef struct {
|
---|
| 79 | uint8_t type; /* Drive type. */
|
---|
| 80 | uint8_t dpt_entry; /* Index of entry in fd_parm. */
|
---|
| 81 | } fd_map_entry;
|
---|
| 82 |
|
---|
| 83 | /* Drive types as stored in the CMOS. Must match DevPCBios! */
|
---|
| 84 | #define FDRV_360K 1
|
---|
| 85 | #define FDRV_1_2M 2
|
---|
| 86 | #define FDRV_720K 3
|
---|
| 87 | #define FDRV_1_44M 4
|
---|
| 88 | #define FDRV_2_88M 5
|
---|
| 89 | #define FDRV_15M 14
|
---|
| 90 | #define FDRV_63M 15
|
---|
| 91 |
|
---|
| 92 | /* A table mapping (CMOS) drive types to DPT entries. */
|
---|
| 93 | fd_map_entry fd_map[] = {
|
---|
| 94 | { FDRV_360K, 0 },
|
---|
| 95 | { FDRV_1_2M, 2 },
|
---|
| 96 | { FDRV_720K, 3 },
|
---|
| 97 | { FDRV_1_44M, 4 },
|
---|
| 98 | { FDRV_2_88M, 5 },
|
---|
| 99 | { FDRV_15M, 6 },
|
---|
| 100 | { FDRV_63M, 6 }
|
---|
| 101 | };
|
---|
| 102 |
|
---|
| 103 | /* Find a DPT corresponding to the given drive type. */
|
---|
| 104 | dpt_ext *get_floppy_dpt(uint8_t drv_typ)
|
---|
| 105 | {
|
---|
| 106 | int i;
|
---|
| 107 |
|
---|
| 108 | for (i = 0; i < sizeof(fd_map) / sizeof(fd_map[0]); ++i)
|
---|
| 109 | if (fd_map[i].type == drv_typ)
|
---|
[48072] | 110 | return &fd_parm[fd_map[i].dpt_entry];
|
---|
[48069] | 111 |
|
---|
| 112 | /* As a fallback, return the 1.44M DPT. */
|
---|
| 113 | return &fd_parm[5];
|
---|
| 114 | }
|
---|