Page 1 of 1

What is wrong

Posted: Wed Mar 09, 2005 9:34 pm
by B.E
the following code is ment to convert LBA to CHS. it is works in dos and windows(protected mode) but does not work in Real Mode

Code: Select all

;+-------------------------------------------------+
;| LBAtoCHS - convert the LBA (Local block         |
;|            address) number into                 |
;|            CHS (Cylinder head sector)           |
;|                                                 |
;| Input                                           |
;|    dh = Sectors per track                       |
;|    dl = number of heads                         |
;|    ax = LBA number                              |
;| Output                                          |
;|    CH = Cylinder number                         |
;|    CL = Sector Number                           |
;|    DH = Head Number                             |
;|                                                 |
;+-------------------------------------------------+

LBAtoCHS:

   div dh         ; al = int(LBA / SectorsPerTrk)
                              ; ah = LBA mod SectorsPerTrk;
   mov cl,ah     ; cl = LBA mod SectorsPerTrk;
   inc cl           ; cl = (LBA mod SectorsPerTrk)+1;
   xor ah,ah      ; clear remainder
   div dl           ; al = int(LBA / SectorsPerTrk / NumHeads) 
                              ;ah = int((LBA / SectorsPerTrk) mod NumHeads)
             mov ch,al      
             mov dh,ah
              
             ret
Any help will be good. thankyou

Re:What is wrong

Posted: Thu Mar 10, 2005 3:30 am
by Pype.Clicker
err ?? since when does DOS run in pmode ??

i'd rather say DOS and BIOS add an additionnal translation level that you're not aware of ... how do you use the output of this code in
- DOS
- your bootsector (presumably, this is for a boot sector, right ?)

Re:What is wrong

Posted: Thu Mar 10, 2005 6:34 am
by B.E
Pype.Clicker wrote: err ?? since when does DOS run in pmode ??
Sorry I was wrong I thought EMM386.EXE converts to Protected Mode, it does, but only to get into V86 Mode.

I don't like using PC Emulators to test my OS. So I use Debug.
all i do is change the ORG 100h to ORG 7c00h when I finished Developing the bootsector.

After hour of looking at the code and Ralf's Interrupt List I relised it was'nt the disk code I was using it was the buufer I was sending the data to. I was sending it to 8000h wich happends to be a 640k boundry. Before EMM386 get into V86 mode it must set the segment selector to a different value.