flat assembler
Message board for the users of flat assembler.

Index > OS Construction > root directory again...

Author
Thread Post new topic Reply to topic
abuashraf



Joined: 11 Nov 2006
Posts: 88
abuashraf
Hi guys,
I'm trying to write a new entry in the root directory,let's assume
I want to write a new file name in the first sector of the root directory,
and the 5th entry was free,so here's the code:
Code:
        xor     ax,ax                   ;zero ax
        mov     bx,ax                   ;zero bx
        mov     dx,ax                   ;zero dx
        mov     si,ax                   ;zero si
        mov     di,ax   
        mov     bx,[es:0x400]             ;our buffer
        mov     ax,19                    ;first sector of the root directory
        mov     cx,1                     ;read one sector
        call    read_sectors                ;load the sector to the buffer
        call    getname                       ;get the name from the user
        mov     si,cname         ;cname holds the input from the user
        mov     di,[es:0x400]                               
        mov     cx,11                       ;file name length
   @loop:
        mov     al,byte [si]              ;start copying the name to the buffer
        mov     byte [di],al
        inc     si
        inc     di
        loop    @loop
        mov     bx,[es:0x400]
        mov     ax,19
        mov     cx,1
        call    write_sectors               ;write the updated buffer back to the first
        ret                              ;sector of the root directory
    

the code above change the whole first sector of the root directory
the problem is,how to write to the 5th entry(for example),
and keep the other entries without change

Thanx.
Post 10 Aug 2008, 02:38
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
You load the whole root dir into a buffer, change the 5th entry in the buffer and write the whole root dir back.
This is fine for fat12 and fat16, but for fat32 you would write just the changed part.
Post 10 Aug 2008, 12:51
View user's profile Send private message Reply with quote
abuashraf



Joined: 11 Nov 2006
Posts: 88
abuashraf
I tried this:
Code:
        xor     ax,ax                   ;zero ax
        mov     bx,ax                   ;zero bx
        mov     dx,ax                   ;zero dx
        mov     si,ax                   ;zero si
        mov     di,ax   
        mov     bx,[es:0x400]
        mov     ax,19
        mov     cx,1
        call    read_sectors
        call    getname
        mov     si,cname
        mov     di,[es:0x400]
        mov     cx,11
        push    bx
        xor     bx,bx
        mov     bx,160                  ;the 5th entry
    @loop:
        mov     al,byte [si]
        mov     byte [di+bx],al
        inc     si
        inc     di
        inc     bx
        loop    @loop
        pop     bx
        mov     bx,[es:0x400]
        mov     ax,19
        mov     cx,1
        call    write_sectors
        ret     

I never saw any changes in the root directory Sad ,
but when I execute the code
in the provious post,as you said it changes the whole first sector in the
root directory...
Post 10 Aug 2008, 18:43
View user's profile Send private message Reply with quote
abuashraf



Joined: 11 Nov 2006
Posts: 88
abuashraf
Hi,
now my code works only if I'm writing to entries less than the 4th entry
Code:
        xor     ax,ax                   ;zero ax
        mov     bx,ax                   ;zero bx
        mov     dx,ax                   ;zero dx
        mov     si,ax                   ;zero si
        mov     di,ax   
        mov     bx,[es:0x400]     ;the buffer
        mov     ax,19
        mov     cx,1                  ;read one sector
        call    read_sectors        ;read sectors from floppy
        call    getname              ;get file name from users
        mov     si,cname
        mov     bx,[es:0x400]   ;save buffer address in bx

        add     bx,96               ;the entry number goes here(3rd entry)
   ;if i change the value of bx to for example 128 or 160
   ;it will not work
        mov     cx,11
    yeh:
        mov     al,byte [si]       ;save name in buffer
        mov     byte [bx],al
        inc     si
        inc     bx
        loop    yeh
        mov     bx,[es:0x400]    ;write the buffer back to the floppy disk
        mov     ax,19
        mov     cx,1                  ;write one sector
        call    write_sectors
        ret     

so if I tried to write to the 5th entry 6th...
it's not gonna work Confused
Post 13 Aug 2008, 01:38
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
What is the buffer address set to, is there any chance that BX adds up to more than 0xffff ?, when you add 128 etc.
Post 14 Aug 2008, 17:30
View user's profile Send private message Reply with quote
abuashraf



Joined: 11 Nov 2006
Posts: 88
abuashraf
Quote:
What is the buffer address set to,

I load the sectors in memory at [es:0x400] in my 'read_sectors' function.
Post 15 Aug 2008, 00:42
View user's profile Send private message Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 696
Location: Adelaide
sinsi
Is your buffer at address es:0x400 or is your buffer address stored at [es:0x400]?
Post 15 Aug 2008, 01:05
View user's profile Send private message Reply with quote
abuashraf



Joined: 11 Nov 2006
Posts: 88
abuashraf
my buffer address at es:0x400,so [es:0x400] holds the value of my buffer
the content of sector
Post 15 Aug 2008, 02:29
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
If your buffer is at es:0x400 than this code will not work, as your putting whats in that address into BX, than when you add to BX your just add to the content, not the address.
Post 15 Aug 2008, 16:24
View user's profile Send private message Reply with quote
abuashraf



Joined: 11 Nov 2006
Posts: 88
abuashraf
humm...how can I fix that?
Post 15 Aug 2008, 17:46
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
You could try something like this:
Code:
        xor     ax,ax                   ;zero ax
        mov     bx,ax                   ;zero bx
        mov     dx,ax                   ;zero dx
        mov     si,ax                   ;zero si
        mov     di,ax   
        mov     bx,0x400       ;the buffer
        mov     ax,19
        mov     cx,1                  ;read one sector
        call    read_sectors        ;read sectors from floppy
        call    getname              ;get file name from users
        mov     si,cname
        mov     bx,0x400           ;save buffer address in bx

        add     bx,96               ;the entry number goes here(3rd entry)
   ;if i change the value of bx to for example 128 or 160
   ;it will not work
        mov     cx,11
    yeh:
        mov     al,byte [si]       ;save name in buffer
        mov     byte [es:bx],al
        inc     si
        inc     bx
        loop    yeh
        mov     bx,0x400   ;write the buffer back to the floppy disk
        mov     ax,19
        mov     cx,1                  ;write one sector
        call    write_sectors
        ret     

But we would also need to see your 'write_sectors', 'read_sectors' to be sure, also they need to be in the same segment.
Post 16 Aug 2008, 16:00
View user's profile Send private message Reply with quote
abuashraf



Joined: 11 Nov 2006
Posts: 88
abuashraf
There was a push instrucion in other function of my os,this push was making the trouble,I erased this push and my code working now.
Thank you guys very much for your help,but there is a question,
I never executed the function with the bad push ,how would this push affect my current working func?
the function with the bad push was away from being executed,while executing my function to make the new entry...
Post 17 Aug 2008, 00:54
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
Replace the push and pop with 4 nop eg:
Code:
nop
nop
nop
nop
    

If it stops work again, then your problem maybe that as your code grows, it move into the next segment etc.
Post 17 Aug 2008, 12:17
View user's profile Send private message Reply with quote
abuashraf



Joined: 11 Nov 2006
Posts: 88
abuashraf
No,it did'nt work,my os just frezze...
Also every time I try to add a new instructions,my os either frezze
or reboot....even if the new code was a single instruction. Question
how can I fix this problem?
Post 17 Aug 2008, 17:39
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4240
Location: 2018
edfed
u can try this:
BOOT.ASM
Code:
;version 13/05/2008 15:31;;;;;
comloader:
use16
        org 7c00h
        push cs
        pop ds
        mov si,reboot
        mov [si+disk.drv],dl
        call disk
        mov word[si+disk.off],there
        jmp far dword[si+disk.off]
there:
        push cs
        pop ds
        mov si,kernel
        mov ax,[si+disk.seg]
        mov es,ax
        xor bx,bx
        mov cl,psp.end-psp
        mov di,psp
@@:
        mov ax,[di+bx]
        mov [es:bx],ax
        add bx,2
        dec cl
        jne @b
        mov [si+disk.drv],dl
        call disk
        mov word [si+disk.off],0
        call far dword[si+disk.off]
        push cs
        pop ds
        mov bx,0b101h
        call cls
        mov si,reboot
        mov dword[si+disk.off],7c00h
        mov byte[si+disk.drv],80h
        call disk
        jmp far dword[si+disk.off]
cls:
        mov di,80*25*2-2
        mov ax,0b800h
        mov es,ax
@@:
        mov [es:di],bx
        sub di,2
        jnl @b
        ret
psp:
        push cs
        pop ds
        mov ax,100h
        call ax
        retf
.end:
align 4
reboot: ; dd disk
        dd 00010002h,1,1000h:7c00h,0;,0
kernel:; dd disk
        dd 007f0002h,2,2000h:0100h,0;,0
include 'disk.inc'           ;
free =  510-(padding-$$)
padding rb free
        dw 0aa55h
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; macro from an Adam Marquis's bootsector , an user of FASM board Very Happy      ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d1 = '0'+ free shr 8 and 0Fh
d2 = '0'+ free shr 4 and 0Fh
d3 = '0'+ free and 0Fh
if d1>'9' 
d1 = d1 + 7 
end if 
if d2>'9' 
d2 = d2 + 7 
end if 
if d3>'9' 
d3 = d3 + 7 
end if 
display d1,d2,d3,'h '
display 'free bytes ',13,10
    

DISK.INC
Code:
disk:
;.call=0     ; not usefull for bootloader
.cmd=0;4     ; then, relocate the fields
.drv=1;5     ; and will save 4 bytes by objects.
.cnt=2;6
.s=4;8
.h=5;9
.c=6;10
.off=8;12
.seg=10;14
.s0=12;16
.h0=13;17
.c0=14;18
;.kb0=20     ; not usefull for now, save 4 bytes + source code.
        call .id
        mov al,[si+.s]
        mov ah,[si+.h]
        mov bx,[si+.c]
        mov cx,[si+.cnt]
        mov dx,[si+.off]
        push cx dx es
.next:
        dec word[si+.cnt]
        jl .end
        push ax bx
        mov cx,bx
        mov bl,cl
        mov cl,ch
        mov ch,bl
        shl cl,6
        and cl,0c0h
        or cl,al
        mov dh,ah
        pushaw
        call .atom
        jnc @f
        popaw
        pushaw
        call .atom
        jnc @f
        popaw
        pushaw
        call .atom
        jnc @f
.error:
        popaw
        pop bx ax
        clc
        jmp .tchao
@@:
        add word[si+.off],512
        popaw
        pop bx ax
        inc al
        cmp al,[si+.s0]
        jne @f
        mov al,1
        inc ah
        cmp ah,[si+.h0]
        jl @f
        mov ah,0
        inc bx
        cmp bx,[si+.c0]
        jl .next
        mov bx,0
@@:
        jmp .next
.atom:
        call .reset
        mov bx,[si+.seg]
        mov es,bx
        mov bx,[si+.off]
        mov ah,[si+.cmd]
        mov al,1
        mov dl,[si+.drv]
        int 13h
        ret
.reset:
        mov dl,[si+.drv]
        mov ah,0
        int 13h
        ret
@@:
        clc
        ret
.id:
        cmp byte[si+.drv],0
        jnl .floppy
        call .reset
        jc @b
        mov ah,8
        mov dl,[si+.drv]
        int 13h
        inc dh
        mov [si+.h0],dh
        mov bx,cx
        and cl,not 0c0h
        mov [si+.s0],cl
        mov cl,ch
        mov ch,bl
        shr ch,6
        inc cx
        mov [si+.c0],cx
@@:
;        movzx ax,byte[si+.s0]
;        movzx bx,byte[si+.h0]
;        mov cx,word[si+.c0]
;        imul ax,bx
;        imul ax,cx
;        shr ax,1
;        mov [si+.kb0],ax
        stc
        ret
.floppy:
        mov word[si+.c0],80
        mov byte[si+.h0],2
        mov byte[si+.s0],18
        jmp @b
.end:
        stc
.tchao:
        pop es dx cx
        mov [si+.off],dx
        mov [si+.cnt],cx
        ret
    

it was hard to debug, but now, it's stable.

many problems when using int13h with more than 1 sector on floppy drives.
then, read/write sectors one by one is prefered.
otherwise, i don't see where can be your pb as you didn't post it integrally.


Last edited by edfed on 18 Aug 2008, 17:55; edited 1 time in total
Post 18 Aug 2008, 16:56
View user's profile Send private message Visit poster's website Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
We need to know where your kernel is load to and what you put in you segment regs eg: DS, ES etc.
This is the main problem with real-mode that's why its best to move to pmode.
Also i like bootprog as a boot loader , as it can load a com or mz exe
http://alexfru.chat.ru/epm.html#bootprog
Post 18 Aug 2008, 17:37
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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.