Re: Help needed

From: Martijn van Buul (martijnb_at_stack.nl)
Date: 2001-09-03 11:04:36

Ruud Baltissen wrote:
> Hallo allemaal,

Lo Ruud.
 
> 1) What I need is a conversion from "Track/Head/Sector" to a lineair number.

Exactly what 'type' of THS are you dealing with? Is it a 1541-ish type
of disk (for a diskimage, for example) with a variable number of sectors,
or do you want to convert 'IDE' THS (with a fixed geometry) back and from
a logical block address? (In that case, you may want to use LBA adressing
instead - most disks > 500MB probably support that. No conversion 
required).

> And vica versa of course.
> 
> Information you need:
> HDTRACKL = Low byte number of tracks on harddisk
> HDTRACKH = High byte number of tracks on harddisk
> HDHEADS  = number of heads
> HDSECT   = number of sectors on a track.

It *seems* like you want to have a fixed geometry, in which case it's
reasonably simple:

block(t,h,s)= t * HDHEADS * HDSECT + h * HDSECT + s

or

block(t,h,s)= (t * HDHEADS + h ) * HDSECT + s

(Saves one multiplication)

THe other way 'round is only slightly more complicated. It is helpful
if you have a 'cylinder'-step.

s = block MOD HDSECT
c = block \ HDSECT

h = c MOD HDHEADS
t = c \ HDHEADS

with 'MOD' being the modulo (or the 'remainder' of a division), \ being
an integer division. Ofcourse you can rewrite this to get rid of the MOD
by doing something like

c = block \ HDSECT
s = block - c*HDSECT

t = c \ HDHEADS
h = c - t*HDHEADS

The NRTRACKS is not required at all.

-- 
    Martijn van Buul -  Pino@dohd.org - http://www.stack.nl/~martijnb/
	 Geek code: G--  - Visit OuterSpace: mud.stack.nl 3333
   Kees J. Bot: The sum of CPU power and user brain power is a constant.

       Message was sent through the cbm-hackers mailing list

Archive generated by hypermail 2.1.1.