flat assembler
Message board for the users of flat assembler.

Index > OS Construction > fat12 entry

Author
Thread Post new topic Reply to topic
abuashraf



Joined: 11 Nov 2006
Posts: 88
abuashraf 31 Aug 2008, 01:10
Hi,
I'm writing a FAT12 driver for my real mode os,right now I'm having problem with setting an entry in the fat table to a specific value
here's my code...

Code:
setcluster:
              push    cx dx bx
        mov     cx, ax                  ;copy current cluster
        mov     dx, ax                  ;copy current cluster
        shr     dx, 0x0001              ;divide by two
        add     cx, dx                  ;cx=offset into FAT                  
        mov     bx,[es:0x500]           ;address of fat table
        add     bx, cx                  ;index into FAT
        mov     dx, WORD [bx]           ;read two bytes from FAT(old value in dx)
        test    ax, 0x0001
 jnz     .odd
.eve:       
    mov     bx,dx
       and     bx,0xF000               ;bx holds the old value 
    and     word[value],0x0FFF      ;next cluster
       
    or      word[value],bx
      mov     dx,word[value]
      mov     word [bx],dx
        jmp     donexx
.odd:
 mov     bx,dx
       and     bx,0x000F               ;bx holds the old value
     shl     word[value],4           ;next_cluster
       or      word[value],bx
      mov     dx,word[value]
      mov     word [bx],dx            ;save the new value
donexx:
        pop     bx dx cx
        ret         
    

would you please help me...
Please note that "value"holds the new value I want to set.

Thanx
Post 31 Aug 2008, 01:10
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u 31 Aug 2008, 14:59
First it may help if you post what it does when you run it
Code from DexOS floppy driver
Code:
;====================================================;
; UpdateClusterValue.                                ;
;====================================================;
UpdateClusterValue:
      pushad  mov   word[Cluster],ax
      mov   word[UpdateValue],bx
  xor   ecx,ecx
       mov   cx,ax                                     
    mov   dx,ax                                     
    shr   dx,0x0001                                 
    add   cx,dx                                     
    mov   esi,BpbFat12                              
    add   esi,512   
    add   esi,ecx 
      mov   dx,word [ds:esi]
  ;mov   [ClustOrigValue ],dx
 test  ax,0x0001
     jnz   OddUpdateClusterValue          
EvenUpdateClusterValue:
        mov   bx,dx
 and   bx,0000111111111111b
  mov   [ClustOrigValue ],bx  
        and   dx,1111000000000000b
  mov   bx,word[UpdateValue]
  and   bx,0000111111111111b
  add   dx,bx
 mov   word [ds:esi],dx                       
   jmp   DoneUpdateClusterValue
OddUpdateClusterValue:
  mov   bx,dx
 shr   bx,4
  mov   [ClustOrigValue ],bx 
 and   dx,0000000000001111b
  mov   bx,word[UpdateValue]
  shl   bx,4
  add   dx,bx
 mov   word [ds:esi],dx 
DoneUpdateClusterValue:
  popad                        
       ret
    

Can you see a differanc ?
Also this does not seem right
Code:
mov bx,[es:0x500]
    

Is your address of your FAT store there ? , because if not and its the address of of your FAT, its the wrong way to use it.
See DexOS function.
Post 31 Aug 2008, 14:59
View user's profile Send private message Reply with quote
abuashraf



Joined: 11 Nov 2006
Posts: 88
abuashraf 31 Aug 2008, 23:15
Quote:
Is your address of your FAT store there ?

Yes I loaded FAT table into memory at [es:0x500],
Also I used this combination when getting an entry from fat table
and it worked fine,because I was able to read 10KB TXT files.

Quote:
First it may help if you post what it does when you run it

It dosent change any thing in the FAT table,so every time I try to make a new file,the first free cluster still the same,but when I make a new file
from windows and and save it on the IMG,the first free cluster increases by one.
Post 31 Aug 2008, 23:15
View user's profile Send private message Reply with quote
abuashraf



Joined: 11 Nov 2006
Posts: 88
abuashraf 01 Sep 2008, 04:54
Thank you Dex for your help,it's working now,the problem was that
I was lossing the value of BX which holds the FAT offset.
here's the working code...
Code:
setcluster:
        push     cx 
        mov     cx, ax                  ;copy current cluster 
        mov     dx, ax                  ;copy current cluster 
        shr     dx, 0x0001              ;divide by two 
        add     cx, dx                  ;cx=offset into FAT                      
        mov     bx,[es:0x500]           ;address of fat table 
        add     bx, cx                  ;index into FAT
        push    bx 
        mov     dx, WORD [bx]           ;read two bytes from FAT(old value in dx) 
        test    ax, 0x0001 
        jnz     .odd 
.eve:    
        mov     bx,dx 
        and     bx,0xF000               ;bx holds the old value  
        and     word[value],0x0FFF      ;next cluster 
         
        or      word[value],bx 
        mov     dx,word[value]
        pop     bx 
        mov     word [bx],dx 
        jmp     donexx 
.odd: 
        mov     bx,dx 
        and     bx,0x000F               ;bx holds the old value 
        shl     word[value],4           ;next_cluster 
        or      word[value],bx 
        mov     dx,word[value] 
        pop     bx
        mov     word [bx],dx            ;save the new value 
donexx:          
        pop      cx  
        ret
    
Post 01 Sep 2008, 04:54
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 21 Sep 2008, 13:10
Here is the snippet:
Code:
;;; di = cluster number; ax = new cluster number
  mov     bx, di
      shr     bx, 1           ; CF: odd?
      mov     cx, FAT12[bx+di]
    jnc     .even
.odd:      shl     ax, 4
       and     cx, 0x000f
  jmp     .done
.even:     and     cx, 0xf000
.done:        or      cx, ax
      mov     FAT12[bx+di], cx    
By the way, that could be improved. Don't you see
Code:
;;; si = cluster number
    mov     bx, si
      shr     bx, 1
       mov     ax, FAT12[bx+si]
    jnc     @f
  shr     ax, 4
@@:        and     ax, 0xfff
;;; ax = next cluster number

;;; si = cluster number
    xor     cx, cx
      mov     bx, si
      shr     bx, 1
       rcl     cx, 3           ; 2 [log2(4)==2] +1 (respect the CF Wink)
        mov     ax, FAT12[bx+si]
    shr     ax, cl          ; here CF goes: to shift or not to shift...
     and     ax, 0xfff
;;; ax = next cluster number    
the similarities?

P.S. Beware of off-segment...
Post 21 Sep 2008, 13:10
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.