flat assembler
Message board for the users of flat assembler.

Index > DOS > FAT question

Author
Thread Post new topic Reply to topic
bubach



Joined: 17 Sep 2004
Posts: 341
Location: Trollhättan, Sweden
bubach 12 Nov 2004, 10:01
Hello, i am trying to alter my FAT and directory entrys for a FAT12 floppy.
I have added info in both FAT's and in the directory for a 50kb big file named kernel.sys that will be located at the very beginning of the data area.
I have not written the actual file on the floppy yet, but i think it would still show me a "fake" kernel.sys with 50kb size in xp.
Instead xp reports that i have used 6kb of the floppy space, but no file exists.

This is my code:

Code:
     ;--------------------;
     ;   sector buffer    ;
     ;--------------------;
          temp_sector:
          times 512       db  0 

     ;---------------;
     ;    other      ;
     ;---------------;
          filename        db  'KERNEL  SYS'    
....
Code:
     ;-------------;
     ; reset drive ;
     ;-------------;
     reset:
          xor     ax, ax
          mov     dl, 0
          int     0x13
          jc      reset

     ;---------------;
     ;  read fat 1   ;
     ;---------------;
          mov     ax, 0x0201
          mov     bx, temp_sector
          mov     cx, 2
          mov     dx, 0
          int     0x13
          jc      reset

     ;--------------;
     ;  change it   ;
     ;--------------;
          inc     bx
          inc     bx
          inc     bx
          mov     byte [bx], 0x03
          inc     bx
          mov     byte [bx], 0x40
          inc     bx
          mov     byte [bx], 0x00
          inc     bx
          mov     byte [bx], 0x05
          inc     bx
          mov     byte [bx], 0x60
          inc     bx
          mov     byte [bx], 0x00
          inc     bx
          mov     byte [bx], 0x07
          inc     bx
          mov     byte [bx], 0x80
          inc     bx
          mov     byte [bx], 0x00

     ;----------------;
     ;   write it     ;
     ;----------------;
          mov     ax, 0x0301
          mov     bx, temp_sector
          mov     cx, 2
          mov     dx, 0
          int     0x13
          jc      reset



     ;-------------;
     ; reset drive ;
     ;-------------;
     reset2:
          xor     ax, ax
          mov     dl, 0
          int     0x13
          jc      reset2

     ;---------------;
     ;  read fat 2   ;
     ;---------------;
          mov     ax, 0x0201
          mov     bx, temp_sector
          mov     cx, 10
          mov     dx, 0
          int     0x13
          jc      reset2

     ;--------------;
     ;  change it   ;
     ;--------------;
          inc     bx
          inc     bx
          inc     bx
          mov     byte [bx], 0x03
          inc     bx
          mov     byte [bx], 0x40
          inc     bx
          mov     byte [bx], 0x00
          inc     bx
          mov     byte [bx], 0x05
          inc     bx
          mov     byte [bx], 0x60
          inc     bx
          mov     byte [bx], 0x00
          inc     bx
          mov     byte [bx], 0x07
          inc     bx
          mov     byte [bx], 0x80
          inc     bx
          mov     byte [bx], 0x00

     ;----------------;
     ;   write it     ;
     ;----------------;
          mov     ax, 0x0301
          mov     bx, temp_sector
          mov     cx, 10
          mov     dx, 0
          int     0x13
          jc      reset2



     ;-------------;
     ; reset drive ;
     ;-------------;
     reset3:
          xor     ax, ax
          mov     dl, 0
          int     0x13
          jc      reset3

     ;---------------------------;
     ;   read directory entry    ;
     ;---------------------------;
          mov     ax, 0x0201
          mov     bx, temp_sector
          mov     cx, 15
          mov     dx, 0x0100
          int     0x13
          jc      reset3

     ;---------------------------;
     ;  change directory entry   ;
     ;---------------------------;
          mov     cx, 11
          mov     dx, filename
     .l1:
          mov     [bx], dx
          inc     bx
          inc     dx
          loop    .l1

     ;--------------------;
     ;  file attributes   ;
     ;--------------------;
          mov     byte [bx], 5
          inc     bx

     ;---------------------------------------;
     ;   jump over reserved and time/date    ;
     ;---------------------------------------;
          mov     cx, 15
     .l2:
          inc     bx
          loop    .l2

     ;----------------------------------;
     ;   reversed data area location    ;
     ;----------------------------------;
          mov     byte [bx], 0x02
          inc     bx
          mov     byte [bx], 0x00
          inc     bx

     ;------------------------;
     ;   reversed filesize    ;
     ;------------------------;
          mov     byte [bx], 0x00
          inc     bx
          mov     byte [bx], 0xC8


     ;---------------------------;
     ;  write directory entry    ;
     ;---------------------------;
          mov     ax, 0x0301
          mov     bx, temp_sector
          mov     cx, 15
          mov     dx, 0x0100
          int     0x13
          jc      reset3




     ;---------------------------------;
     ;  write the file to data area    ;
     ;---------------------------------;
          ;...... not done yet    

but it does not work.
The info i used for finding out what to write was from this page:
http://www.mega-tokyo.com/osfaq2/index.php/FAT12%20document
i have used the values for the "example" file PROCESSA.TXT described in the document, as it starts at the beginning of the data area.
The things i have changed is the filename and filesize..

Any idea of what i have done wrong? Or a suggestion of a simpler way of doing this?

PS: if anything is terrible wrong in this code, i blame it at i did this coding _really_ late at night.. Wink

Thanks in advance...
/ Christoffer

_________________
BOS homepage: http://bos.asmhackers.net/


Last edited by bubach on 13 Feb 2012, 14:53; edited 1 time in total
Post 12 Nov 2004, 10:01
View user's profile Send private message Reply with quote
mike.dld



Joined: 03 Oct 2003
Posts: 235
Location: Belarus, Minsk
mike.dld 12 Nov 2004, 17:48
Post 12 Nov 2004, 17:48
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
bubach



Joined: 17 Sep 2004
Posts: 341
Location: Trollhättan, Sweden
bubach 12 Nov 2004, 18:13
Thanks, i had a quick look, didn't get much except it uses DOS not BIOS like me. But i better study it more carfully.

One more thing, how do i get params, from the dos prompt in a .com file? Nothing to complex, i need it for either -b or -k and then a filename. Any guides on this?

/ Christoffer


Last edited by bubach on 13 Feb 2012, 14:58; edited 1 time in total
Post 12 Nov 2004, 18:13
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1166
Location: Overflow
Matrix 12 Nov 2004, 19:04
what do you say searching for it like:

What is fat-12
Post 12 Nov 2004, 19:04
View user's profile Send private message Visit poster's website Reply with quote
mike.dld



Joined: 03 Oct 2003
Posts: 235
Location: Belarus, Minsk
mike.dld 12 Nov 2004, 19:33
.com-file has addresses from $100, so those $100 bytes from the beginning are used as PSP block. Sorry if I'd mistaken.
Post 12 Nov 2004, 19:33
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1166
Location: Overflow
Matrix 12 Nov 2004, 19:40
mike.dld wrote:
.com-file has addresses from $100, so those $100 bytes from the beginning are used as PSP block. Sorry if I'd mistaken.


no , you're right, dos loads it there. while bootprog usually loads @ 7c00h
Post 12 Nov 2004, 19:40
View user's profile Send private message Visit poster's website Reply with quote
mike.dld



Joined: 03 Oct 2003
Posts: 235
Location: Belarus, Minsk
mike.dld 12 Nov 2004, 23:44
ok Wink
so parameters are at offset $80 IIRC
Post 12 Nov 2004, 23:44
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
bubach



Joined: 17 Sep 2004
Posts: 341
Location: Trollhättan, Sweden
bubach 13 Nov 2004, 13:24
Thanks, but i already solved it.. Wink

for future forum-searches, here's how i did it:
Code:
       boot            db  0
       kernel          db  0
       hyphen          db  0
       filename        db  '           ',0

;-----------------------------------------------;
;  read in arguments from the command line...   ;
;-----------------------------------------------;
    mov     cl, [ds:0x80]
   or      cl, cl
      je      print_usage
         mov     si, 0x81
    mov     di, filename
        mov     bx, 0

     param_loop:
   lodsb
     ;     or      al, al
     ;     je      continue
   cmp     al, 13
      je      continue
    cmp     al, '-'
   jne     .c1
         mov     [hyphen], 1
         jmp     .c5
     .c1:
        cmp     [hyphen], 1
         jne     .c5
         cmp     [boot], 1
   je      .c3
         cmp     [kernel], 1
         je      .c3
         cmp     al, 'b'
   jne     .c2
         mov     [boot], 1
   jmp     .c5
     .c2:
        cmp     al, 'k'
   jne     print_usage
         mov     [kernel], 1
         jmp     .c5
     .c3:
        cmp     al, ' '
   je      .c5
         cmp     bx, 11
      ja      print_usage
;          cmp     al, '.'                        ; Old code, becasue i was
;          jne     .c4                            ; thinking wrong. This converts:
;          cmp     bx, 8                          ; FILE.TXT to:
;          je      .c5                            ; FILE    TXT

;          push    cx
;          mov     cx, 8
;          sub     cx, bx
;          mov     al, ' '
;          rep     stosb
;          inc     bx
;          pop     cx
;          jmp     .c5
     .c4:
    stosb
       inc     bx
     .c5:
         loop    param_loop


     ;---------------;
     ;  continue..   ;
     ;---------------;
     continue:
      cmp     al, 13
      jne     .next
       mov     al, 0     ; Make the filename ASCIIZ Wink
        stosb
     .next:
    cmp     [boot], 1
   je      write_boot
          cmp     [kernel], 1
         je      write_kernel
    


Last edited by bubach on 13 Feb 2012, 15:00; edited 1 time in total
Post 13 Nov 2004, 13:24
View user's profile Send private message Reply with quote
bubach



Joined: 17 Sep 2004
Posts: 341
Location: Trollhättan, Sweden
bubach 13 Nov 2004, 16:55
Is there a way of finding out a file-size, when using handle not FCB?

/ Christoffer
Post 13 Nov 2004, 16:55
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1166
Location: Overflow
Matrix 13 Nov 2004, 18:17
you're jokeing are you? this is not funny anymore.
Post 13 Nov 2004, 18:17
View user's profile Send private message Visit poster's website Reply with quote
bubach



Joined: 17 Sep 2004
Posts: 341
Location: Trollhättan, Sweden
bubach 14 Nov 2004, 12:42
Huh?? What is funny about my questions?
Post 14 Nov 2004, 12:42
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.