Skip to content

Commit

Permalink
Merge pull request #432 from kiwisincebirth/map/hbios-diomed
Browse files Browse the repository at this point in the history
Improvements to HBIOS
  • Loading branch information
wwarthen authored Oct 8, 2024
2 parents ecc7a15 + 06d9561 commit 76a5f21
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 24 deletions.
Binary file modified Doc/RomWBW System Guide.pdf
Binary file not shown.
74 changes: 56 additions & 18 deletions Source/Doc/SystemGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,38 @@ application. The user is responsible for ensuring that the start of the
FAT partition does not overlap with the area they intend to use for
CP/M slices. FDISK80 has a Reserve option to assist with this.

## Mapping to Media ID

HBIOS has a definition of "Media ID", which defines the type and physical
properties of disk media provided by an underlying storage device. For a
complete list of Media ID's please see the following section

[Disk Input/Output (DIO)]

There are two important Media ID's relating to Hard Disk Layouts:

| **Media** | **ID** | **Format / Meaning** |
|------------|-------:|-------------------------------------------------------------|
| MID_HD | 4 | Classic Disk Layout (hd512) *--and--* HBIOS Hard Disk Drive |
| MID_HDNEW | 10 | Modern Disk Layout (hd1k) |

HBIOS typically does not understand the format of data on a device,
instead just treating all hard disks as raw sectors. `MID_HD` is the typical
Media ID used by HBIOS to describe high capaity hard disk media

When the Modern Disk Layout was added, the `MID_HDNEW`, was added to
differentiate (at the oerating system level) between the Classic and Modern layouts.

However HBIOS itself typically does NOT make this distinction, since the use
of these two formats is determined by the operating system based on the
partition table on the media.

There are two important HBIOS functions that deal with Media ID.

[Function 0x18 -- Disk Media (DIOMEDIA)]

[SYSGET Subfunction 0x12 -- Get Extended Disk Media (DIOMED)]

# System Boot Process

A multi-phase boot strategy is employed. This is necessary because at
Expand Down Expand Up @@ -840,20 +872,17 @@ more of the defined media types.
| MID_MDROM | 1 | ROM Drive |
| MID_MDRAM | 2 | RAM Drive |
| MID_RF | 3 | RAM Floppy (LBA) |
| MID_HD512 | 4 | Hard Disk (LBA) w/ 512 directory entries |
| MID_HD | 4 | Hard Disk (LBA) w/ 512 directory entries |
| MID_FD720 | 5 | 3.5" 720K Floppy |
| MID_FD144 | 6 | 3.5" 1.44M Floppy |
| MID_FD360 | 7 | 5.25" 360K Floppy |
| MID_FD120 | 8 | 5.25" 1.2M Floppy |
| MID_FD111 | 9 | 8" 1.11M Floppy |
| MID_HD1K | 10 | Hard Disk (LBA) w/ 1024 directory entries |
| MID_HDNEW | 10 | Hard Disk (LBA) w/ 1024 directory entries |

**NOTE**: HBIOS does not actually differentiate between MID_HD512 and
MID_HD1K. The use of these two formats is determined by the use of a
partition table on the media and is implemented by the operating
system itself. HBIOS treats all hard disks as raw sectors. See
[Function 0x18 -- Disk Media (DIOMEDIA)] for more information on the
Media ID byte returned.
**NOTE**: HBIOS typically does not actually differentiate between MID_HD and
MID_HDNEW, it will generally only use MID_HD.
See the section [Mapping to Media ID] for information on this.

HBIOS supports both Cylinder/Head/Sector (CHS) and Logical Block
Addresses (CHS) when locating a sector for I/O (see DIOSEEK function).
Expand Down Expand Up @@ -1073,10 +1102,9 @@ Report the Media ID (E) for the for media in the specified Disk Unit
will be performed. The Status (A) is a standard HBIOS result code. If
there is no media in device, function will return an error status.

**NOTE**: This function will always return MID_HD512 for hard disk
devices. MID_HD1K is provided for use internally by operating systems
that provide different filsystem formats depending on the partition
table. To determine if an HD1K formatted partition exists on the hard disk
**NOTE**: This function will always return MID_HD for hard disk
devices. See the section [Mapping to Media ID] for information on this.
To determine if an HD1K formatted partition exists on the hard disk
please see the following function.

[SYSGET Subfunction 0x12 -- Get Extended Disk Media (DIOMED)]
Expand Down Expand Up @@ -2466,18 +2494,23 @@ lookup.
| **Entry Parameters** | **Returned Values** |
|----------------------------------------|---------------------------------------|
| B: 0xF8 | A: Status |
| C: 0x12 | C: Media ID |
| D: Disk Unit | DEHL: Sector Address |
| E: Slice | |
| C: 0x12 | B: Device Attributes |
| D: Disk Unit | C: Media ID |
| E: Slice | DEHL: Sector Address |

Report the Media ID (C) for the for media in the specified Disk Unit (D),
and for hard disks the absolute Sector offset to the start of the Slice (E).
The Status (A) is a standard HBIOS result code.
Report the Media ID (C), and Device Attributes (B) for the for media in the
specified Disk Unit (D), and for hard disks the absolute Sector offset to the
start of the Slice (E). The Status (A) is a standard HBIOS result code.

This function extends upon [Function 0x18 -- Disk Media (DIOMEDIA)] for hard
disk media by scanning for a partition to determine if the disk uses HD512
or HD1K, correctly reporting MID_HD or MID_HDNEW respectively.

**NOTE: This is contrary to the design of HBIOS. See the section
[Mapping to Media ID] for information on this.
This function was placed in HBIOS to be shared between the diffeent CP/M
varients supported by RomWBW, and may be moved in future.

It will also return the sector number of the first sector in the
slice if the slice number is valid. If the slice number is invalid
(it wont fix on the media) an error will be returned.
Expand All @@ -2487,10 +2520,15 @@ The slice calculation is performed by considering the partition start
that the slice fits within the media or partition size, taking into
consideration other partitions that may exist.

The Device Attributes (B) are the same as defined in
[Function 0x17 -- Disk Device (DIODEVICE)]

If the Unit specified is not a hard disk the Media ID will be returned and
the slice parameter ignored. If there is no media in device, or the slice
number is invaid (Parameter Out Of Range) the function will return an error status.

Also see [Function 0x18 -- Disk Media (DIOMEDIA)]

#### SYSGET Subfunction 0x20 -- Get RTC Device Unit Count (RTCCNT)

| **Entry Parameters** | **Returned Values** |
Expand Down
33 changes: 27 additions & 6 deletions Source/HBIOS/hbios.asm
Original file line number Diff line number Diff line change
Expand Up @@ -5243,11 +5243,13 @@ SYS_GETDIOFN:
; E: SLICE, ignored if media is not a hard disk
; RETURNS:
; A: STATUS, -6 (parameter out of range) - if Slice is invalid
; B: DEVICE ATTRIBUTES, as reported by DIODEVICE
; C: MEDIAID, including MID_HDNEW if hd1k partition is found
; DEHL: LBAOFFSET, of Slice if valid, 0 otherwise.
;
DIOMED_SLICE .DB 0 ; SLICE ARGUMENT (E)
DIOMED_UNIT .DB 0 ; UNIT ARGUMENT (D)
DIOMED_DEVATT .DB 0 ; DEVICE ATTRIBUTES
;
DIOMED_WRKSTA .EQU $
DIOMED_LBAOFF .FILL 4,0 ; START OF PARTITION / SLICE (SECTORS)
Expand All @@ -5260,6 +5262,17 @@ DIOMED_WRKSIZ .EQU $ - DIOMED_WRKSTA ; SIZE OF WORKING DATA
SYS_GETDIOMED:
; SAVE CALL ARGUMENTS
LD (DIOMED_SLICE),DE ; STORES DE -> SLICE/UNIT PARAMETERS

; READ DEVICE INFORMATION USING DIODEVICE FUNTON
LD A,(DIOMED_UNIT)
LD C,A ; UNIT ID PARAMETER INTO C
LD B,BF_DIODEVICE ; DRIVER FUNCTION = DISK MEDIA
CALL DIO_DISPATCH ; CALL DIO TO GET MEDIAID (RESULT IN E)
RET NZ ; ABORT ON ERROR
;
; DEVICE ATTRIBUTES IN C
LD A,C
LD (DIOMED_DEVATT),A ; STORE DEVICE ATTRIBUTES
;
; DETERMINE MEDIA IN DRIVE USING DIOMEDIA FUNCTION
LD A,(DIOMED_UNIT)
Expand All @@ -5274,16 +5287,18 @@ SYS_GETDIOMED:
OR A ; SET FLAGS
JR Z, SYS_GETDIOMED1A ; BAIL IF NO MEDIA
CP MID_HD ; IS IT A HARD DISK
JR NZ, SYS_GETDIOMED1A ; BAIL IF NOT HARD DISK
JR SYS_GETDIOMED1B ; CONTINUE TO PROCESS HD
JR Z, SYS_GETDIOMED1B ; IS HD, CONTINUE TO PROCESS HD
;
; NOT A HARD DISK, CHECK SLICE = 0
LD A,(DIOMED_SLICE) ; GET THE SLICE
OR A ; SET FLAGS
JP NZ, SYS_GETDIOMED5C ; SLICE NOT ZERO - SIGNAL ERROR AND RETURN
;
SYS_GETDIOMED1A:
; RETURN MEDIA ID (NOT HD) WITH SUCCESS
LD DE,0
LD DE,0 ; LBA VALUE WILL BE ZERO
LD HL,0
LD C,A ; RETURN MEDIA ID IN C
XOR A ; SIGNAL SUCCESS
RET ; NOT HD JUST RETURN
JP SYS_GETDIOMED6A ; RETURN SUCESS
;
SYS_GETDIOMED1B:
; FOUND HD, NEED TO PROCESS MBR / PART TABLE
Expand Down Expand Up @@ -5454,9 +5469,12 @@ SYS_GETDIOMED5B:
; REQUIRE - CAPACITY -> GENERATES BORROW IF CAPITY > REQUIREMENT
JR NC,SYS_GETDIOMED6 ; IF WE HAVE ENOUGH CAPACITY
;
SYS_GETDIOMED5C:
; SLICE WONT FIT - STOP AND RETURN ERROR
LD DE,0
LD HL,0 ; EMTY OFFSET IN DEHL
LD A,(DIOMED_DEVATT)
LD B,A ; DEVICE ATTRIBUTES IN B
LD A,(DIOMED_MID)
LD C,A ; RETURN MEDIA ID IN C
LD A,ERR_RANGE ; OTHERWISE SIGNAL NOT ENOUGH CAPACITY
Expand All @@ -5473,7 +5491,10 @@ SYS_GETDIOMED6:
ADC HL,BC ; ADD MSB
EX DE, HL ; FLIP BACK DE:HL AS SLICE OFFSET
;
SYS_GETDIOMED6A:
; SLICE FITS - RETURN CORRECTLY
LD A,(DIOMED_DEVATT)
LD B,A ; DEVICE ATTRIBUTES IN B
LD A,(DIOMED_MID)
LD C,A ; RETURN MEDIA ID IN C
XOR A ; CLEAR FLAGS
Expand Down

0 comments on commit 76a5f21

Please sign in to comment.