What is wrong

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
B.E

What is wrong

Post 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
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:What is wrong

Post 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 ?)
B.E

Re:What is wrong

Post 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.
Post Reply