Author Topic: [FASM] Generating Fat12 formatted bootsector.  (Read 2032 times)

0 Members and 1 Guest are viewing this topic.

Offline zorm

  • Hero Member
  • *****
  • Posts: 591
    • View Profile
    • Zorm's Page
[FASM] Generating Fat12 formatted bootsector.
« on: June 19, 2005, 06:40:24 PM »
Code: [Select]
use16
org 0x7C00

BYTES_PER_SECTOR = 512

RESERVED_SECTORS = 1
MEDIA_DESCRIPTOR = 0xF0

NUMBER_OF_HEADS = 0x2
NUMBER_OF_TRACKS = 0x50
SECTORS_PER_TRACK = 0x12

NUMBER_OF_SECTORS = NUMBER_OF_HEADS * NUMBER_OF_TRACKS * SECTORS_PER_TRACK
SECTORS_PER_CLUSTER = 1
NUMBER_OF_FATS = 2

SECTORS_PER_FAT = 1
SECTORS_PER_ROOT = 1
;This was taken from a post on the fasm message board
NUMBER_OF_CLUSTERS = (NUMBER_OF_SECTORS-RESERVED_SECTORS-(NUMBER_OF_FATS*SECTORS_PER_FAT)-SECTORS_PER_ROOT)/SECTORS_PER_CLUSTER
REPEAT (((NUMBER_OF_CLUSTERS+1)/2*3+3)+BYTES_PER_SECTOR-1)/BYTES_PER_SECTOR
NUMBER_OF_CLUSTERS = (NUMBER_OF_SECTORS-RESERVED_SECTORS-(NUMBER_OF_FATS*SECTORS_PER_FAT)-SECTORS_PER_ROOT)/SECTORS_PER_CLUSTER
if (((NUMBER_OF_CLUSTERS+1)/2*3+3)+BYTES_PER_SECTOR-1)/BYTES_PER_SECTOR > SECTORS_PER_FAT
SECTORS_PER_FAT = SECTORS_PER_FAT+1
end if
END REPEAT

SECTORS_PER_ROOT = SECTORS_PER_ROOT+(NUMBER_OF_SECTORS-RESERVED_SECTORS-(NUMBER_OF_FATS*SECTORS_PER_FAT)-SECTORS_PER_ROOT)-(NUMBER_OF_CLUSTERS*SECTORS_PER_CLUSTER)
ENTRIES_PER_ROOT = SECTORS_PER_ROOT*BYTES_PER_SECTOR / 0x20


jmp beginning
nop ;To fill the first 3 bytes of fat12


OEMName db 'MSWIN4.1'
BytesPerSec dw BYTES_PER_SECTOR
SecPerClus db SECTORS_PER_CLUSTER
RsvdSecCnt dw RESERVED_SECTORS
numFats db NUMBER_OF_FATS
RootEntCnt dw ENTRIES_PER_ROOT
TotSec16 dw NUMBER_OF_SECTORS
Media db MEDIA_DESCRIPTOR
FATSz16 dw SECTORS_PER_FAT
SecPerTrk dw SECTORS_PER_TRACK
NumHeads dw NUMBER_OF_HEADS
HiddSec dd 0
TotSec32 dd 0
DrvNum db 0
Reservered1 db 0
BootSig db 0x29
VolID dd 0x33333333
VolLab db 'NO NAME    '
FilSysType db 'FAT12   '

beginning:
 ;Your code here

Attached is a PDF explaining the Fat Format which also explains how this works. It covers FAT12, FAT16 and FAT32.
"Frustra fit per plura quod potest fieri per pauciora"
- William of Ockham