Page 2 of 2
Re: fat12 set cluster
Posted: Thu Aug 28, 2008 7:45 am
by jal
abuashraf wrote:I already wrote complete fat12 driver in C,but now I'm writing it in asm
but I'm really having problem with this specific function
So basically your problem is that you can't code assembly. It's pretty stupid then abandoning C.
JAL
Re: fat12 set cluster
Posted: Thu Aug 28, 2008 6:20 pm
by xyjamepa
I'm trying to learn assembly by coding a real mode os,and so far I've learnt alot
and I'm very pleased about that.
Re: fat12 set cluster
Posted: Fri Aug 29, 2008 1:38 am
by Combuster
DOS .COM works pretty well too if you want to learn to use basic assembly.
Re: fat12 set cluster
Posted: Fri Aug 29, 2008 5:15 am
by xyjamepa
I wrote a lot of Dos programs,but I'm having trouble with this specific fumction
Could we guys stop going off-topic please...
Re: fat12 set cluster
Posted: Fri Aug 29, 2008 7:37 am
by jal
abuashraf wrote:I wrote a lot of Dos programs,but I'm having trouble with this specific fumction
I really fail to understand that, if you have a working C-version, you are not able to make an assembly one. What is your problem?
JAL
Re: fat12 set cluster
Posted: Fri Aug 29, 2008 7:52 am
by DeletedAccount
http://www.it.lth.se/ssoa/Project1/FAT12Description.pdf 
. You might find this more readable than the official Microsoft specs
Regards
Thomas
Re: fat12 set cluster
Posted: Sat Aug 30, 2008 6:55 pm
by xyjamepa
here's what I have,till now I couldn't solve my problem,
There's somthing wrong in my code,would someone please check it...
Code: Select all
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
Thanx.
Re: fat12 set cluster
Posted: Sun Aug 31, 2008 8:47 am
by xyjamepa
right now I'm very sure of this function,90% it's fine and nothing wrong with him,
but till now I couldn't change the value in the fat entry.
Also I'm sure that I load FAT table correctly into memory,because I can read
text files even if they are very long.
guys what do you advice me?how can I figure out what's wrong?
how can I debug this problem?
Re: fat12 set cluster
Posted: Sun Aug 31, 2008 10:56 pm
by xyjamepa
It's working now...
Here's the working code,for anybody else...
Code: Select all
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