Subject: 16-bit sector addresses in CP/M 2.2
From: Alexis <thrashbarg at kaput.homeunix.org>
Date: Fri, 08 Feb 2008 01:43:37 +1030
To: "General Discussion: On-Topic and Off-Topic Posts" <cctalk at
classiccmp.org>
Hi,
I'm attaching a hard drive to my 8080 computer and there seems to be
something about the way the sector translation works that's caught my
attention. Before I go wasting my time trying to figure it out myself
I'll ask here because there's going to be someone who knows (it's 1:30am
and I'm feeling a little lazy).
Observe the following code:
sectran:
;translate the sector given by BC using the
;translate table given by DE
xchg ;HL=.trans
dad b ;HL=.trans(sector)
mov l,m ;L = trans(sector)
mvi h,0 ;HL= trans(sector)
ret ;with value in HL
>From a standard CP/M BIOS.
Firt off that is for for up to 65536 sectors (per track). As that
directly maps to only sectors on a track and only for 128byte logical
sectors. (typically it's less than 64 for most disk drives)
My question is does the BDOS use this as a 16-bit
value, or does it cut
it to an 8-bit value, like sectran does. H is loaded with 0 and L is
loaded with the translated sector.
I'm thinking that if this is the case, then a total of 256 tracks *
65536 sectors * 128 bytes = 2048MB. This could be done without a massive
translation table by transferring the desired sector, BC, into HL.
It would be that if for only one thing. The math is not way. The
calulation is 65536 sectors total or 65536*128 or 8516608 (8mb).
It's really a result that all math truncates to 16bits.
there are BDOSs that fix this (P2DOS, Suprbdos, Novados, ZRdos...)
and can do the full 2Gb.
I've only just started writing the CBIOS for the hard drive interface
and I don't really want to waste my time on pointless endeavours.
Define pointless.. The problem is if your using a LBA HD or CF that has
more than 8MB then you have to partition the drive. Also for LBA
addressing there are some track and sector tricks that can be applied
as well for deblocking.
It wouldn't make sense to use 16-bits for a sector
register and 8-bits
for a track register if you're only going to use 8-bits of the sector
register, but perhaps the upper 8-bits are used for internal flags or
error conditions?
You might.
Another thing is that the total sectors per track in
the Disk Parameter
Block is a 16-bits, not 8-bits.
It allows up to 16bit values for both track and sector. While floppies
never use more than byte values the parameters passed to the BIOS is a
word and it's at your choice to truncate to byte.
Caveat: For floppies and smaller hard disks they are CHS, usually
cylinders needs a byte for floppy but hard disks it may have more than
256 cylinders. Both however rarely have more than 64 logical sectors
per track so a byte works. The gotcga is devices like Ramdisks, CF
and larger IDE drives are or can be LBA where it's easier to look at
it as 1 track of 65536 sectors or 65536 tracks of one sector or anything
that multiples out to 65536! Where the byte/word thing is important
is this case:
Hard disk organized as 16spt (assume they are 128 byte sectors which
rarely happens) and 8192 tracks for 16mb. Thats a total of 131072
sectors. So to use it all you partition it in the bios as two drives
and one has an offset(reseverd tracks) of half the total tracks or 4097.
That means the parameter for tracks passed will be a word as you need
at least 13bits. CP/M does handle that correctly.
It's gets discussed but not often and it's straight forward and not
obvious. The CP/M alteration guide is plain poor on why or how.
the only book that explains this reasonably and you have to read
the whole book to get all the bits is Andy Johnson-Laird, The Programers
CP/M Handbook.
I have done enough things with CP/M and it's bios to have the need to
understand it and that books was both best and good reference. Prior
to that I had to infer, guess and test to see what was really happening.
As a result when I do a bios SETTRACK, and SECSEC stores a word value
and else where I can then selectivly chose to use a byte or word.
Also SECTRAN (AKA skew) is a allways NUL routine in my BIOS as it's
useless when drives that have sectors larger than 128 bytes. For hard
disks and CF/IDE types it's never used as they are too fast. If I need Sectran
functionality I do it at the device level rather than have BDOS
do the work. You may use it if you wish and it applies well for any disk that is SD
especially for 8"SSSD.
Hope that helps.
Allison