TR-DOS DISK INPUT/OUTPUT PROGRAMMING

[ TR-DOS project TRDOS Kernel drafts ]
 

 ataid.html  diskio.zip  ataid.zip
 
; *****************************************************************************
;
; DISKINFO.ASM  [ TR-DOS DRV INIT Sample & DISK INFO Utility ]
; Copyright (c) 2004  Erdogan TAN [ Version 2.0 - 29/01/2005 ]
;
; *****************************************************************************

; Masterboot / Partition Table at Beginning+1BEh
ptBootable       equ 0
ptBeginHead      equ 1
ptBeginSector    equ 2
ptBeginCylinder  equ 3
ptFileSystemName equ 4
ptEndHead        equ 5
ptEndSector      equ 6
ptEndCylinder    equ 7
ptStartSector    equ 8
ptSectors        equ 12

; Boot Sector Parameters at 7C00h
DataArea1     equ -4
DataArea2     equ -2
BootStart     equ 0h
OemName       equ 03h
BytesPerSec   equ 0Bh
SecPerClust   equ 0Dh
ResSectors    equ 0Eh
FATs          equ 10h
RootDirEnts   equ 11h
Sectors       equ 13h
Media         equ 15h
FATsecs       equ 16h
SecPerTrack   equ 18h
Heads         equ 1Ah 
Hidden1       equ 1Ch
Hidden2       equ 1Eh
HugeSec1      equ 20h
HugeSec2      equ 22h
DriveNumber   equ 24h
Reserved1     equ 25h
bootsignature equ 26h                 
VolumeID      equ 27h
VolumeLabel   equ 2Bh
FileSysType   equ 36h          
Reserved2     equ 3Eh                           ; Starting cluster of P2000

; FAT32 BPB Structure
FAT32_FAT_Size equ 36
FAT32_RootFClust equ 44
FAT32_FSInfoSec equ 48
FAT32_DrvNum equ 64
FAT32_Reserved1 equ 65
FAT32_BootSig equ 66
FAT32_VolID equ 67
FAT32_VolLab equ 71
FAT32_FilSysType equ 82

; BIOS Disk Parameters
DPDiskNumber  equ 0h
DPDType       equ 1h
DPReturn      equ 2h
DPHeads       equ 3h
DPCylinders   equ 4h
DPSecPerTrack equ 6h
DPDisks       equ 7h
DPTableOff    equ 8h
DPTableSeg    equ 0Ah
DPNumOfSecs   equ 0Ch

; BIOS INT 13h Extensions (LBA extensions)
; Just After DP Data (DPDiskNumber+)
DAP_PacketSize equ 10h  ; If extensions present, this byte will be >=10h
DAP_Reserved1 equ 11h   ; Reserved Byte 
DAP_NumOfBlocks equ 12h ; Value of this byte must be 0 to 127
DAP_Reserved2 equ 13h   ; Reserved Byte
DAP_Destination equ 14h ; Address of Transfer Buffer as SEGMENT:OFFSET
DAP_LBA_Address equ 18h ; LBA=(C1*H0+H1)*S0+S1-1
                        ; C1= Selected Cylinder Number
                        ; H0= Number Of Heads (Maximum Head Number + 1)
                        ; H1= Selected Head Number
                        ; S0= Maximum Sector Number
                        ; S1= Selected Sector Number
                        ; QUAD WORD
; DAP_Flat_Destination equ 20h ; 64 bit address, if value in 4h is FFFF:FFFFh
                             ; QUAD WORD (Also, value in 0h must be 18h) 
                             ; TR-DOS will not use 64 bit Flat Address

; INT 13h Function 48h "Get Enhanced Disk Drive Parameters"
; Just After DP Data (DPDiskNumber+)
GetDParams_48h equ 20h ; Word. Data Lenght, must be 26 (1Ah) for short data.
GDP_48h_InfoFlag equ 22h ; Word
; Bit 1 = 1 -> The geometry returned in bytes 4-15 is valid.
GDP_48h_NumOfPCyls equ 24h ; Double Word. Number physical cylinders.
GDP_48h_NumOfPHeads equ 28h ; Double Word. Number of physical heads.
GDP_48h_NumOfPSpT equ 2Ch ; Double word. Num of physical sectors per track.
GDP_48h_LBA_Sectors equ 30h ; 8 bytes. Number of physical/LBA sectors.
GDP_48h_BytesPerSec equ 38h ; Word. Number of bytes in a sector.

; TR-DOS Standalone Program Extensions to the DiskParams Block
; Just After DP Data (DPDiskNumber+)
TRDP_CurrentSector equ 3Ah  ; DX:AX (LBA)
TRDP_SectorCount equ 3Eh    ; CX (or Counter)

; DOS Logical Disks
LD_Name equ 0
LD_DiskType equ 1
LD_PhyDrvNo equ 2
LD_FATType equ 3
LD_FSType equ 4
LD_LBAYes equ 5
LD_BPB equ 6
LD_FATBegin equ 96
LD_ROOTBegin equ 100
LD_DATABegin equ 104
LD_StartSector equ 108
LD_TotalSectors equ 112
LD_FreeSectors equ 116
LD_Clusters equ 120
LD_PartitionEntry equ 124
LD_DParamEntry equ 125
LD_MediaChanged equ 126
LD_CDirLevel equ 127
LD_CurrentDirectory equ 128

; Valid FAT Types
FS_FAT12 equ 1
FS_FAT16_CHS equ 2
FS_FAT32_CHS equ 3
FS_FAT16_LBA equ 4
FS_FAT32_LBA equ 5

; Cursor Location
CCCpointer equ  0450h   ; BIOS data, current cursor column
; FAT Clusters EOC sign
FAT12EOC equ 0FFFh
FAT16EOC equ 0FFFFh
;FAT32EOC equ 0FFFFFFFh ; It is not direct usable for 8086 code
; BAD Cluster
FAT12BADC equ 0FF7h
FAT16BADC equ 0FFF7h
;FAT32BADC equ 0FFFFFF7h ; It is not direct usable for 8086 code
; MS-DOS FAT16 FS (Maximum Possible) Last Cluster Number= 0FFF6h 


Present segment Para 'code'

		assume CS:Present, DS:Present, ES:Present, SS:Present


;北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北
;
;              PROCEDURE proc_start
;
;北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北北

proc_start      proc    far

                org 100h
start:
                call proc_drv_init  ; DRV_INIT.ASM

                xor dl, dl
                call floppy_drv_init
                mov al, byte ptr [Current_TRDOS_Drv]
                adc al, 0
                push ax
                mov dl, 1
                call floppy_drv_init
                pop ax
                adc al, 0
                mov byte ptr [Current_TRDOS_Drv], al

loc_print_partition_table:
                mov si, offset P_Table_Header
                call proc_printmsg
                
                mov si, offset PTable_hd0
                mov word ptr [PTable_Drv],"dh"
                mov byte ptr [PTable_Drv]+2,"0"
                mov byte ptr [P_Number],"1"
                mov cx, 4
check_entry_next_0:
                push cx
                mov cx, 4
check_p_entry_next_1:
                cmp byte ptr [SI][ptFileSystemName],0
                jna short pass_call_print_p_entry
                call proc_print_p_entry
pass_call_print_p_entry:
                add si, 10h
                inc byte ptr [P_Number]
                loop check_p_entry_next_1
                pop cx
                inc byte ptr [PTable_Drv]+2
                mov byte ptr [P_Number], "1"
                loop check_entry_next_0
                mov word ptr [PTable_Drv],"pe"
                mov byte ptr [PTable_Drv]+2,"0"
                mov byte ptr [P_Number],"1"
                mov cx, 4
check_p_entry_next_ep_0:
                push cx
                mov cx, 4
check_p_entry_next_ep_1:
                cmp byte ptr [SI][ptFileSystemName],0
                jna short pass_call_print_p_entry_ep
                call proc_print_p_entry
pass_call_print_p_entry_ep:
                add si, 10h
                inc byte ptr [P_Number]
                loop check_p_entry_next_ep_1                  
                pop cx
                inc byte ptr [PTable_Drv]+2
                mov byte ptr [P_Number], "1"
                loop check_p_entry_next_ep_0
end_of_print_partition_table:
                mov si, offset DiskParams
                mov byte ptr [DPT_No], "0"

repeat_for_next_dparam:
                cmp si, offset end_of_dparams_buff
                ja short loc_print_trdos_drive_infos

                cmp  byte ptr [si][DPDType],0
                je short pass_current_dparam

                push si

                mov si, offset Press_Any_Key
                call proc_printmsg

                pop si

                xor ah, ah              ; "Press any key to continue"
                int 16h

                cmp al, 1Bh
                je short end_of_prog_drvinfo

                call proc_clear_screen

                cmp byte ptr [si][DPReturn], 0
                ja short pass_current_dparam

                call proc_fill_diskinfo_fields

                push si
                mov si, offset [Disk_Info]
                call proc_printmsg
                pop si

pass_current_dparam:
                add si, 40h
                jmp short repeat_for_next_dparam

loc_print_trdos_drive_infos:
                mov si, offset Logical_DOSDisks
loc_check_trdos_drv_exists:
                cmp byte ptr [SI][LD_Name], 0
                jna short pass_current_trdos_drv

                push si

                call proc_print_drv_info

                mov si, offset Press_Any_Key
                call proc_printmsg

                pop si

                xor ah, ah              ; "Press any key to continue"
                int 16h                

                cmp al, 1Bh
                je short end_of_prog_drvinfo

                call proc_clear_screen

                inc byte ptr [Current_TRDOS_Drv]

pass_current_trdos_drv:
                mov al, byte ptr [Last_Dos_DiskNo]
                cmp al, byte ptr [Current_TRDOS_Drv]
                jb short end_of_prog_drvinfo
                add si, 100h
                jmp short loc_check_trdos_drv_exists

end_of_prog_drvinfo:
                mov si, offset Program_Name
                call proc_printmsg

                mov ax, word ptr [File_Size]
                mov si, offset FileSize_StrPlus5
                mov cx, 10                  
loc_wfsize_rdivide:
                dec si
                xor dx, dx
                div cx
                add dl, '0'
                mov byte Ptr [si], dl
                cmp ax,0
                ja short loc_wfsize_rdivide

                call proc_printmsg

                int 20h
                    
proc_start      endp

proc_printmsg   proc near

                mov BX, 07
loc_print:
		lodsb                           ; Load byte at DS:SI to AL
		and     AL,AL            
		je      short loc_return        ; If AL = 00h then return
		mov     AH,0Eh                  
		int     10h                     ; BIOS Service func ( ah ) = 0Eh
						; Write char as TTY
						;AL-char BH-page BL-color
		jmp     short loc_print           
loc_return:
		retn

proc_printmsg   endp


proc_clear_screen proc near

                mov ah, 0Fh 
                int 10h
                mov ah, 0
                int 10h

                retn

proc_clear_screen endp

;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
; Rx_DOS  32 bit Divide                                      ;
; (Special version by Erdogan Tan)                           ;
;- - - - - - - - - - - - - - - - - - - - - - - - - -- - - - -;
;                                                            ;
; input -> DX_AX = 32 bit dividend                           ;
; input -> CX = 16 bit divisor                               ;
; output -> DX_AX = 32 bit quotient                          ;
; output -> BX = 16 bit remainder                            ;
;                                                            ;
;  This procedure divides the requested 32 bit number        ;
;  and gives the result in DX, AX and BX (remainder)         ;
;                                                            ;
; Original Procedure by Michael Podanoffsky / Real Time DOS  ;
; (c) Erdogan TAN  1999                     [ RXDOSBIO.ASM ] ;
;............................................................;

Rx_Dos_Div32    proc near

		mov  bx, dx
		xchg ax, bx
		xor  dx, dx
		div  cx         ; at first, divide DX
		xchg ax, bx     ; remainder is in DX
				; now, BX has quotient
				; save remainder
		div  cx         ; so, DX_AX divided and
				; AX has quotient
				; DX has remainder
		xchg dx, bx     ; finally, BX has remainder

		retn

Rx_Dos_Div32    endp

;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
; From binary (byte) to hexadecimal (character) converter    ;
;                                                            ;
; input -> AL = byte (binary number) to be converted         ;
; output -> AH = First character of hexadecimal number       ;
; output -> AL = Second character of hexadecimal number      ;
;                                                            ;
; (c) Erdogan TAN  1998 - 1999                               ;
;............................................................;

; 1998

proc_hex        proc    near

		db 0D4h,10h                     ; Undocumented inst. AAM
						; AH = AL / 10h
						; AL = AL MOD 10h
		or AX,'00'                      ; Make it ZERO (ASCII) based

                xchg AH,AL 

; 1999
		cmp AL,'9'
		jna pass_cc_al
		add AL,7
pass_cc_al:
		cmp AH,'9'
		jna pass_cc_ah
		add AH,7
pass_cc_ah:

; 1998
		retn

proc_hex        endp

;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
; 32 bit Multiply                                            ;
;- - - - - - - - - - - - - - - - - - - - - - - - - -- - - - -;
;                                                            ;
; input -> DX_AX = 32 bit multiplier                         ;
; input -> BX = 16 bit number to be multiplied by DX_AX      ;
; output -> BX_DX_AX = 48 bit (16+32 bit) result number      ;
;                                                            ;
; (c) Erdogan TAN  1999                                      ;
;............................................................;

proc_mul32    proc near

	      push cx

	      mov cx, bx
	      mov bx, dx

	      mul cx

              xchg ax, bx

	      push dx

              mul cx 

              pop cx 

              add ax, cx 
	      adc dx, 0

	      xchg bx, ax
	      xchg dx, bx

	      pop cx

	      retn

proc_mul32    endp

; include DRV_INIT.ASM  

; Beginning of DRV_INIT.ASM  (TR-DOS Drive Initialization Procedures)

proc_drv_init   proc    near

                xor dl,dl
                mov si, offset DiskParams
dparam_read:
                call proc_dparam
                mov dl, byte ptr [SI][DPDisks]
                add si, 40h
                cmp dl, 2
                jne short pass_floppy1
                dec dl
                call proc_dparam
pass_floppy1:
                mov dl, 80h
                add si, 40h
                call proc_dparam
                jnc short pass_hd_15h_error
                mov word ptr [si][DPNumOfSecs], 0
                mov word ptr [si][DPNumOfSecs]+2,0
pass_hd_15h_error:
                mov ah, byte ptr [SI][DPDisks]
                mov byte ptr [HDCounter], ah
next_hard_disk:
                dec byte ptr [HDCounter]
                cmp byte ptr [HDCounter], 0
                jna short load_hd_partition_tables
                inc dl
                add si, 40h
                call proc_dparam
                jnc short next_hard_disk
                mov word ptr [si][DPNumOfSecs], 0
                mov word ptr [si][DPNumOfSecs]+2,0
                jmp short next_hard_disk
load_hd_partition_tables:
                mov si, offset Disk_hd0
                mov di, offset PTable_hd0
                push ds
                pop es
                mov dl, 80h
                mov cx, 4
load_next_hd_partition_table:
                push cx
                push dx
                push si
                push di
                cmp byte ptr [SI]+1, 03h
                jne short pass_pt_this_hard_disk
                call proc_load_masterboot
                jc short pass_pt_this_hard_disk
                pop di
                push di
                mov si, offset PartitionTable
                mov cx, 32
                rep movsw
pass_pt_this_hard_disk:
                pop di
                pop si
                pop dx
                pop cx
                inc dl
                add si, 40h
                add di, 40h
                loop load_next_hd_partition_table
load_extended_dos_partitions:
                mov si, Offset PTable_hd0
                mov di, Offset PTable_ep0
                mov byte ptr [HDCounter], 80h
next_hd_extd_partition:
                push si
                mov cx, 4
hd_check_fs_id_05h:
                mov al, byte ptr [SI][ptFileSystemName]
                cmp al, 05h ; Is it an extended dos partition ?
                je short pass_hd_check_05h
                cmp al, 0Fh ; Is it an extended win4 (LBA mode) partition ?
                je short pass_hd_check_0Fh 
continue_to_check_ep:
                add si, 10h
                loop hd_check_fs_id_05h
continue_check_ep_next_disk:
                pop si
                add si, 40h
                add di, 40h
                inc byte ptr [HDCounter]
                cmp byte ptr [HDCounter], 83h
                jna short next_hd_extd_partition
                jmp logical_drv_init
pass_hd_check_05h:
                push cx
                mov ax, word ptr [SI][ptStartSector]
                mov dx, word ptr [SI][ptStartSector]+2
                xor bh,bh
                mov bl, byte ptr [HDCounter]
                push bx
                sub bl, 80h
                shl bl, 1
                shl bl, 1
                mov word ptr [Val_StartSector][BX],ax
                mov word ptr [Val_StartSector][BX]+2,dx
                pop dx
                mov dh, byte ptr [SI][ptBeginHead]
                mov cx, word ptr [SI][ptBeginSector]
                mov ax, 0201h    ; Read 1 sector
                mov bx, offset MasterBootBuff
                push ds
                pop es
                int 13h
                pop cx
                jc short continue_to_check_ep
                push si
                push di
                push cx
                mov si, offset PartitionTable
                mov cx, 32
                rep movsw
                pop cx
                pop di
                pop si
                jmp short continue_check_ep_next_disk
pop_di_check_next_ep:
                pop di
                jmp continue_to_check_ep
pass_hd_check_0Fh:
                mov ax, word ptr [SI][ptStartSector]
                mov dx, word ptr [SI][ptStartSector]+2
                xor bh,bh
                mov bl, byte ptr [HDCounter]
                sub bl, 80h
                push bx
                shl bl, 1
                shl bl, 1
                mov word ptr [Val_StartSector][BX],ax
                mov word ptr [Val_StartSector][BX]+2,dx
                pop ax
                push di
                mov ah, 40h
                mul ah
                mov di, offset Disk_hd0
                add di, ax
ep_mov_dap_parameters:
                push ds
                pop es
                cmp byte ptr [DI][DAP_PacketSize], 10h
                jne short pop_di_check_next_ep
                mov word ptr [DI][DAP_Destination], offset MasterBootBuff
                push ds
                pop word ptr [DI][DAP_Destination]+2
                mov byte ptr [DI][DAP_NumOfBlocks],1
                push si
                push di
                add si, ptStartSector
                add di, DAP_LBA_Address
                movsw
                movsw
                pop si  
                add si, DAP_PacketSize ; DS:SI= DAP Location
                mov ah, 42h  ; Extended Disk Read - LBA Read
                mov dl, byte ptr [HDCounter]
                int 13h
                pop si
                pop di
                jc continue_to_check_ep
                push di
                push si
                push cx
                mov si, offset PartitionTable
                mov cx, 32
                rep movsw
                pop cx
                pop si
                pop di
                jmp continue_check_ep_next_disk
logical_drv_init:
                mov byte ptr [Hard_Disk], 80h
                mov cx, 4
                xor al, al
                mov si, offset PTable_Buffer
                mov di, offset Logical_DOSDisks + 200h
                mov byte ptr [Last_DOS_DiskNo], 1
ldrv_init_next_hdp:
                push si
                push cx
                push ax
                push di
                cmp byte ptr [SI][ptFileSystemName], 06h
                jne short pass_this_is_FAT16_CHS_disk
                mov byte ptr [DI][LD_DiskType], 2
                mov dl, byte ptr [Hard_Disk]
                mov byte ptr [DI][LD_PhyDrvNo], dl
                mov byte ptr [DI][LD_FATType], 2
                mov byte ptr [DI][LD_FSType], 06
                mov bl, dl
                sub bl, 80h
                xor bh, bh
                mov ah, byte ptr [HD_LBAYes][BX]
                mov byte ptr [DI][LD_LBAYes], ah
                mov byte ptr [DI][LD_PartitionEntry],al
                mov ah, dl
                sub ah, 7Eh
                mov byte ptr [DI][LD_DParamEntry], ah
                mov dh, byte ptr [SI][ptBeginHead]
                mov cx, word ptr [SI][ptBeginSector]
                mov ax, 0201h    ; Read 1 sector
                mov bx, offset DOSBootSectorBuff
                int 13h
                jc pass_this_is_FAT32_LBA_disk
                jmp hdp_boot_validation
pass_this_is_FAT16_CHS_disk:
                cmp byte ptr [SI][ptFileSystemName], 0Eh
                jne pass_this_is_FAT16_LBA_disk
                mov byte ptr [DI][LD_DiskType], 2
                mov dl, byte ptr [Hard_Disk]
                mov byte ptr [DI][LD_PhyDrvNo], dl
                mov byte ptr [DI][LD_FATType], 2
                mov byte ptr [DI][LD_FSType], 0Eh
                mov byte ptr [DI][LD_LBAYes], 1
                mov byte ptr [DI][LD_PartitionEntry],al
                mov ah, dl
                sub ah, 7Eh
                mov byte ptr [DI][LD_DParamEntry], ah
                mov al, 40h
                mul ah
                add ax, offset Disk_fd0
                mov di, ax
                cmp byte ptr [DI][DAP_PacketSize], 10h
                jne pass_this_is_FAT32_LBA_disk
                mov word ptr [DI][DAP_Destination], offset DOSBootSectorBuff
                push ds
                pop word ptr [DI][DAP_Destination]+2
                mov byte ptr [DI][DAP_NumOfBlocks],1
                push di
                add si, ptStartSector
                add di, DAP_LBA_Address
                movsw
                movsw
                pop si  
                add si, DAP_PacketSize ; DS:SI= DAP Location
                mov ah, 42h  ; Extended Disk Read - LBA Read
                mov dl, byte ptr [Hard_Disk]
                int 13h
                jc pass_this_is_FAT32_LBA_disk
hdp_boot_validation:
                cmp word ptr [BS_Validation], 0AA55h
                jne pass_this_is_FAT32_LBA_disk
                cmp byte ptr [BPB_Media], 0F8h
                jne pass_this_is_FAT32_LBA_disk
                cmp word ptr [BPB_FATSz16], 0
                ja short pass_FAT32_BPB
                cmp byte ptr [BS_FAT32_BootSig], 29h
                jne pass_this_is_FAT32_LBA_disk
                mov cx, 45
                jmp short loc_move_hd_BPB
pass_FAT32_BPB:
                cmp byte ptr [BS_BootSig], 29h
                jne pass_this_is_FAT32_LBA_disk
                mov cx, 32
loc_move_hd_BPB:
                mov si, offset DOSBootSectorBuff
                pop di
                push di
                push di
                add di, LD_BPB
                rep movsw 
                pop si
                pop di
                add di, 100h
                push di
                inc byte ptr [Last_DOS_DiskNo]
                mov al, 'A'
                add al, byte ptr [Last_DOS_DiskNo]
                mov byte ptr [SI][LD_Name], al

                cmp byte ptr [Now_EP_Drives], 0
                jna short ld_StartSector_set1
                cmp byte ptr [SI][LD_FsType], 0Bh
                jne short ld_StartSector_set1
                mov ax, word ptr [SI][LD_StartSector]
                mov dx, word ptr [SI][LD_StartSector]+2
                jmp short ld_StartSector_set2
ld_StartSector_set1:
                mov AX,Word Ptr [SI][LD_BPB][Hidden1]
                mov DX,Word Ptr [SI][LD_BPB][Hidden2]
                mov word ptr [SI][LD_StartSector],AX
                mov word ptr [SI][LD_StartSector]+2,DX
ld_StartSector_set2:
                add AX,Word Ptr [SI][LD_BPB][ResSectors]
                adc DX,0

                mov Word Ptr [SI][LD_FATBegin], AX
                mov Word Ptr [SI][LD_FATBegin]+2, DX
                cmp byte ptr [SI][LD_FATType], 3
                jne short pass_FAT32_RootDirLoc
                mov ax, Word Ptr [SI][LD_BPB][FAT32_FAT_Size]
                mov dx, Word Ptr [SI][LD_BPB][FAT32_FAT_Size]+2
                xor bh,bh
                mov bl,Byte Ptr [SI][LD_BPB][FATs]
                call proc_mul32
                add ax, Word Ptr [SI][LD_FATBegin]
                adc dx, Word Ptr [SI][LD_FATBegin]+2
                mov Word Ptr [SI][LD_DATABegin], AX
                mov Word Ptr [SI][LD_DATABegin]+2, DX
                mov Word Ptr [SI][LD_ROOTBegin], AX
                mov Word Ptr [SI][LD_ROOTBegin]+2, DX
                jmp short pass_FAT_FS_Locations
pass_FAT32_RootDirLoc:
                mov AL,Byte Ptr [SI][LD_BPB][FATs]
                cbw                             
                mul Word Ptr [SI][LD_BPB][FATSecs]
                add AX,Word Ptr [SI][LD_FATBegin]
                adc DX,Word Ptr [SI][LD_FATBegin]+2
                mov Word Ptr [SI][LD_ROOTBegin], AX
                mov Word Ptr [SI][LD_ROOTBegin]+2, DX
                mov Word Ptr [SI][LD_DATABegin], AX 
                mov Word Ptr [SI][LD_DATABegin]+2, DX
                mov AX,20h       ; Size of a directory entry
                mul Word Ptr [SI][LD_BPB][RootDirEnts]
                add AX,511
              ; adc dx, 0
                mov cx, 512
                div cx
                add Word Ptr [SI][LD_DATABegin],AX 
                adc Word Ptr [SI][LD_DATABegin]+2,0
pass_FAT_FS_Locations:
                mov ax,Word Ptr [SI][LD_BPB][HugeSec1]
                mov Word Ptr [SI][LD_TotalSectors], AX
                mov dx,Word Ptr [SI][LD_BPB][HugeSec2]
                mov Word Ptr [SI][LD_TotalSectors]+2, dx
                add ax,Word Ptr [SI][LD_StartSector]
                adc dx,Word Ptr [SI][LD_StartSector]+2
                sub ax,Word Ptr [SI][LD_DATABegin]
                sbb dx,Word Ptr [SI][LD_DATABegin]+2
                xor ch,ch
                mov cl,Byte Ptr [SI][LD_BPB][SecPerClust]
                call Rx_Dos_Div32 
                mov word ptr [SI][LD_Clusters], AX
                mov word ptr [SI][LD_Clusters]+2, DX
                    ; Maximum Valid Cluster Number= DX:AX +1
                    ; with 2 reserved clusters= DX:AX +2
               ;mov word ptr [SI][LD_FreeSectors],0
               ;mov word ptr [SI][LD_FreeSectors]+2,0
               ;BPB has been loaded, yet
               ;LD_MediaChanged= 1 is "New Boot, FAT is not read"
                mov byte ptr [SI][LD_MediaChanged],1

                jmp pass_this_is_FAT32_LBA_disk

pass_this_is_FAT16_LBA_disk:
                cmp byte ptr [SI][ptFileSystemName], 0Bh
                jne short pass_this_is_FAT32_CHS_disk
                mov byte ptr [DI][LD_DiskType], 2
                mov bl, byte ptr [Hard_Disk]
                mov byte ptr [DI][LD_PhyDrvNo], bl
                mov byte ptr [DI][LD_FATType], 3
                mov byte ptr [DI][LD_FSType], 0Bh
                sub bl, 80h
                xor bh, bh
                mov ah, byte ptr [HD_LBAYes][BX]
                mov byte ptr [DI][LD_LBAYes],ah
                mov byte ptr [DI][LD_PartitionEntry],al
                mov ah, bl
                add ah, 2
                mov byte ptr [DI][LD_DParamEntry], ah
                mov ax, word ptr [SI][ptStartSector]
                mov dx, word ptr [SI][ptStartSector]+2
                cmp byte ptr [Now_EP_Drives],0
                jna short pass_0Bh_ext_part_start_fixup
                shl bl, 1
                shl bl, 1
                add ax, word ptr [Val_StartSector][BX]
                adc dx, word ptr [Val_StartSector][BX]+2
                mov word ptr [DI][LD_StartSector], ax
                mov word ptr [DI][LD_StartSector]+2, dx
pass_0Bh_ext_part_start_fixup:
                push ax
                mov ah, byte ptr [Hard_Disk]
                sub ah, 7Eh
                mov al, 40h
                mul ah
                add ax, offset Disk_fd0
                mov di, ax
                pop ax
                cmp byte ptr [DI][DAP_PacketSize], 10h
                jne pass_this_is_FAT32_LBA_disk
                mov word ptr [DI][DAP_LBA_Address], ax
                mov word ptr [DI][DAP_LBA_Address]+2, dx
                jmp short loc_fixup_8GB_CHS_to_LBA
pass_val_startsec_check:
                mov dh, byte ptr [SI][ptBeginHead]
                mov cx, word ptr [SI][ptBeginSector]
                mov ax, 0201h    ; Read 1 sector
                mov bx, offset DOSBootSectorBuff
                int 13h
                jc pass_this_is_FAT32_LBA_disk
                jmp hdp_boot_validation
pass_this_is_FAT32_CHS_disk:
                cmp byte ptr [SI][ptFileSystemName], 0Ch
                jne pass_this_is_FAT32_LBA_disk
                mov byte ptr [DI][LD_DiskType], 2
                mov ah, byte ptr [Hard_Disk]
                mov byte ptr [DI][LD_PhyDrvNo], ah
                mov byte ptr [DI][LD_FATType], 3
                mov byte ptr [DI][LD_FSType], 0Ch
                mov byte ptr [DI][LD_LBAYes], 1
                mov byte ptr [DI][LD_PartitionEntry],al
                sub ah, 7Eh
                mov byte ptr [DI][LD_DParamEntry], ah
                mov al, 40h
                mul ah
                add ax, offset Disk_fd0
                mov di, ax
                cmp byte ptr [DI][DAP_PacketSize], 10h
                jne pass_this_is_FAT32_LBA_disk
                push word ptr [SI][ptStartSector]
                pop word ptr [DI][DAP_LBA_Address]
                push word ptr [SI][ptStartSector]+2
                pop word ptr [DI][DAP_LBA_Address]+2
loc_fixup_8GB_CHS_to_LBA:
                mov word ptr [DI][DAP_Destination], offset DOSBootSectorBuff
                push ds
                pop word ptr [DI][DAP_Destination]+2
                mov byte ptr [DI][DAP_NumOfBlocks],1
                push di
                pop si  
                add si, DAP_PacketSize ; DS:SI= DAP Location
                mov ah, 42h  ; Extended Disk Read - LBA Read
                mov dl, byte ptr [Hard_Disk]
                int 13h
                jnc hdp_boot_validation
pass_this_is_FAT32_LBA_disk:
                pop di
                pop ax
                pop cx
                pop si
                add si, 10h
                inc al
                dec cx
                cmp cx, 0
                ja  ldrv_init_next_hdp
                cmp byte ptr [Hard_Disk], 83h
                jnb short pass_init_primary_dos_partitions
                mov cx, 4
                inc byte ptr [Hard_Disk]
                jmp ldrv_init_next_hdp
pass_init_primary_dos_partitions:
                cmp byte ptr [Now_EP_Drives], 0
                ja short loc_drv_init_retn
                mov byte ptr [Now_EP_Drives], 1
                mov si, offset PTable_ep0
                mov byte ptr [Hard_Disk], 80h
                mov ah, byte ptr [Last_DOS_DiskNo]
                inc ah
                xor al,al
                mov di, offset Logical_DOSDisks
                add di, ax
                mov al, 16
                mov cx, 4
                jmp ldrv_init_next_hdp

Now_EP_Drives:  db 0

Val_StartSector: dd 0
                 dd 0
                 dd 0
                 dd 0

loc_drv_init_retn:
                retn

proc_drv_init   endp

proc_dparam   proc near
              ; input
              ; dl = Disk Drive Number
              ; ds:si = Parameters Table Buffer
              ; output
              ; ah = error number (0 = No Error if C flag is ZERO)
              mov byte ptr [si][DPDiskNumber], dl
              mov byte ptr [si][DPDType], 0
              push dx
              mov ah, 08h
              int 13h
              mov byte ptr [si][DPReturn], ah
              jnc short dparam_no_error
              pop dx
              retn
dparam_no_error:
              mov byte ptr [si][DPDType], bl
              mov byte ptr [si][DPDisks], dl
              inc dh
              mov byte ptr [si][DPHeads], dh
              push cx
              and cl, 3Fh
              mov byte ptr [si][DPSecPerTrack], cl
              pop cx
              shr cl,1
              shr cl,1
              shr cl,1
              shr cl,1
              shr cl,1
              shr cl,1
              xchg ch,cl
              inc cx
              mov word ptr [si][DPCylinders], cx
              mov word ptr [si][DPTableOff], di
              push es
              pop word ptr [si][DPTableSeg]

              cmp byte ptr [si][DPDiskNumber], 80h
              jb short dparam_15h_return

              mov dl, byte ptr [si][DPDiskNumber]
              mov byte ptr [Hard_Disk], dl
              mov byte ptr [si][DPDType], 0
              mov ah, 15h
              int 13h
              jc short dparam_15h_return
              mov byte ptr [si][DPDType], ah
              mov word ptr [si][DPNumOfSecs], cx
              mov word ptr [si][DPNumOfSecs]+2, dx
dparam_15h_return:
              pop dx ; dl = Drive Number
              mov byte ptr [SI][DAP_PacketSize], 0 ; Reset (No DAP)
              mov ah, 41h ; Check Extensions Present
              mov bx, 55AAh
              int 13h
              jc short dparam_48h_return
              cmp bx, 0AA55h
              jne short dparam_48h_return
              test cx, 01h ; Fixed Disk Access Subset - is LBA ready ? 
              jz short dparam_48h_return
              xor bh,bh
              mov bl, byte ptr [Hard_Disk]
              sub bl, 80h
              mov byte ptr [HD_LBAYes][BX],1
              mov byte ptr [SI][DAP_PacketSize], 10h
dparam_41h_return:
              push si
              add si, GetDParams_48h
              mov word ptr [SI], 0026 ; GDP Data Lenght - Set
            ; DS:SI= Address of Result Buffer
            ; DL (Drive Number) must be not changed before here...
              mov ah, 48h  ; Get Enhanced Disk Drive Parameters
              int 13h
              pop si
              jc short dparam_48h_return
              mov word ptr [SI][GetDParams_48h], 0 ; GDP Data Lenght - Reset
dparam_48h_return:
              xor ah,ah
              retn
proc_dparam   endp

proc_load_masterboot proc near
                ; input -> dl = drive number
                xor ah,ah
                int 13h
                jnc short pass_reset_error
harddisk_error:
                retn
pass_reset_error:
                mov bx, offset MasterBootBuff
                mov ax,0201h
                mov cx,1
                xor dh,dh
                push ds
                pop es
                int 13h
                jc short harddisk_error

                cmp word ptr [MBIDCode],0AA55h
                jnz short loc_not_masterboot
                retn
loc_not_masterboot:
                stc
                retn

proc_load_masterboot endp

floppy_drv_init proc near
                ; INPUT -> dl = Drive Number (0,1)
                ; OUTPUT -> al = drive name,
                ;           ah = drive number
                mov si, offset Disk_fd0
                mov di, offset Logical_DOSDisks
                xor dh, dh
                cmp dl, 0
                jna short pass_drv_init_fd1
                add si, 40h
                add di, 100h
pass_drv_init_fd1:
                mov byte ptr [DI][LD_MediaChanged],0
             ;  cmp byte ptr [SI][DPDType], 0
             ;  jna short pass_fd_read_boot_sector0
read_fd_boot_sector:
                push ds
                pop es
                push dx
                mov cx, 4 ; Retry Count
read_fd_boot_sector_again:
                push cx
                mov cx, 1
                mov ax, 0201h    ; Read 1 sector
                mov bx, offset DOSBootSectorBuff
                int 13h
                pop cx
                jnc short use_fd_boot_sector_params
                loop read_fd_boot_sector_again
pass_fd_read_boot_sector0:
                stc
pass_fd_read_boot_sector1:
                pop dx
                retn
use_fd_boot_sector_params:
                cmp word ptr [BS_Validation], 0AA55h
                jne short pass_fd_read_boot_sector0
              ; cmp byte ptr [BS_BootSig], 29h
              ; jne short pass_fd_read_boot_sector0
                cmp byte ptr [BPB_Media], 0F0h
                jb short pass_fd_read_boot_sector1
                mov si, offset DOSBootSectorBuff
                push di
                add di, LD_BPB
                mov cx, 32
                rep movsw 
                pop si
                xor ax, ax
                mov Word Ptr [SI][LD_StartSector], AX
                mov Word Ptr [SI][LD_StartSector]+2,0
                add AX,Word Ptr [SI][LD_BPB][ResSectors]
                mov Word Ptr [SI][LD_FATBegin], AX
                mov Word Ptr [SI][LD_FATBegin]+2, 0
                mov AL,Byte Ptr [SI][LD_BPB][FATs] 
                cbw                             
                mul Word Ptr [SI][LD_BPB][FATSecs]
                add AX,Word Ptr [SI][LD_FATBegin]
                mov Word Ptr [SI][LD_ROOTBegin], AX
                mov Word Ptr [SI][LD_ROOTBegin]+2, 0
                mov Word Ptr [SI][LD_DATABegin], AX 
                mov Word Ptr [SI][LD_DATABegin]+2, 0
                mov AX,20h   ; Size of a directory entry
                mul Word Ptr [SI][LD_BPB][RootDirEnts]
                add AX,511
                mov cx,512
                div cx
                add Word Ptr [SI][LD_DATABegin], AX 
                adc Word Ptr [SI][LD_DATABegin]+2, 0 
                mov AX,Word Ptr [SI][LD_BPB][Sectors]
                mov Word Ptr [SI][LD_TotalSectors], AX
                mov Word Ptr [SI][LD_TotalSectors]+2,0
                sub ax,Word Ptr [SI][LD_DATABegin]
                xor dx,dx
                xor ch,ch
                mov cl,Byte Ptr [SI][LD_BPB][SecPerClust]
                div cx 
                mov word ptr [SI][LD_Clusters], AX
                mov byte ptr [SI][LD_FATType], 1
                mov byte ptr [SI][LD_FSType], 0
                mov word ptr [SI][LD_Clusters]+2, 0
                    ; Maximum Valid Cluster Number= AX +1
                    ; with 2 reserved clusters= AX +2
                pop ax
                mov byte ptr [SI][LD_DParamEntry], al
                mov byte ptr [SI][LD_PhyDrvNo], al
                mov ah, al
                add al, 'A'
                mov byte ptr [SI][LD_Name], al
                mov byte ptr [SI][LD_DiskType], 1
                mov byte ptr [SI][LD_LBAYes], 0
                mov byte ptr [SI][LD_PartitionEntry], 0
                mov byte ptr [SI][LD_MediaChanged], 1
                retn

floppy_drv_init endp

HDCounter:     db 1

MasterBootBuff:
MasterBootCode: db 1BEh dup (?)
PartitionTable: db 64 dup (?)
MBIDCode: dw ?

PTable_Buffer:
PTable_hd0: db 64 dup (0)
PTable_hd1: db 64 dup (0)
PTable_hd2: db 64 dup (0)
PTable_hd3: db 64 dup (0)
PTable_ep0: db 64 dup (0)
PTable_ep1: db 64 dup (0)
PTable_ep2: db 64 dup (0)
PTable_ep3: db 64 dup (0)

DiskParams:
Disk_fd0: db 16 dup (0)
DAP_fd0: db 16 dup(0)
GDP_fd0: db 26 dup(0)
TRDP_fd0: db 6 dup(0)
Disk_fd1: db 16 dup (0)
DAP_fd1: db 16 dup(0)
GDP_fd1: db 26 dup(0)
TRDP_fd1: db 6 dup(0)
Disk_hd0: db 16 dup (0)
DAP_hd0: db 16 dup(0)
GDP_hd0: db 26 dup(0)
TRDP_hd0: db 6 dup(0)
Disk_hd1: db 16 dup (0)
DAP_hd1: db 16 dup(0)
GDP_hd1: db 26 dup(0)
TRDP_hd1: db 6 dup(0)
Disk_hd2: db 16 dup (0)
DAP_hd2: db 16 dup(0)
GDP_hd2: db 26 dup(0)
TRDP_hd2: db 6 dup(0)
Disk_hd3: db 16 dup (0)
DAP_hd3: db 16 dup(0)
GDP_hd3: db 26 dup(0)
TRDP_hd3: db 6 dup(0)
end_of_dparams_buff:

DOSBootSectorBuff:
BS_JmpBoot: db 3 dup (0)
BS_OEMName: db 8 dup (0)
BPB_BytsPerSec: dw 0
BPB_SecPerClust: db 0
BPB_RsvdSecCnt: dw 0
BPB_NumFATs: db 0
BPB_RootEntCnt: dw 0
BPB_TotalSec16: dw 0
BPB_Media: db 0
BPB_FATSz16: dw 0
BPB_SecPerTrk: dw 0
BPB_NumHeads: dw 0
BPB_HiddSec: dd 0
BPB_TotalSec32: dd 0
BPB_FATSz32: ; FAT32, 4 bytes
BS_DrvNum: db 0
BS_Reserved1: db 0
BS_BootSig: db 0
BS_VolID: db 0
BPB_ExtFlags: ; FAT32, 2 bytes
          dw 0
BPB_FSVer: ; FAT32, 2 bytes
          db 0
BS_VolLab: db 0
BPB_RootClus: ; FAT32, 4 bytes
           dd 0
BPB_FSInfo: ; FAT 32, 2 bytes 
           dw 0
BPB_BkBootSec: ; FAT32, 2 bytes
           dw 0
BPB_Reserved: ; FAT32, 12 bytes
           dw 0
BS_FilSysType:
           db 8 dup (0)
BS_BootCode:
           dw 0
BS_FAT32_DrvNum: ; FAT32, 1 byte
           db 0
BS_FAT32_Reserved1: ; FAT32, 1 byte
           db 0
BS_FAT32_BootSig: ; FAT32, 1 byte
           db 0
BS_FAT32_VolID: ; FAT32, 4 bytes
           dd 0
BS_FAT32_VolLab: ; FAT32, 11 bytes
           db 11 dup (0)
BS_FAT32_FilSysType: ; FAT32, 8 bytes
           db 8 dup (0)
BS_FAT32_BootCode:
           db 420 dup (0)
BS_Validation: dw 0
Hard_Disk:         db 80h
Last_DOS_DiskNo:   db 0
HD_LBAYes:         dd 0

; end of DRV_INIT.ASM

proc_print_p_entry proc near
                   ; Input -> DS:SI = Partition Entry Buffer
                   push si
                   push cx
                   mov al, byte ptr [SI][ptBootable]
                   call proc_hex
		   mov word ptr [P_Status], ax
		   mov al, byte ptr [SI][ptBeginHead]
		   call proc_hex
		   mov word ptr [Begin_Head], ax
		   mov al, byte ptr [SI][ptBeginSector]
		   call proc_hex
		   mov word ptr [Begin_Sec], ax
		   mov al, byte ptr [SI][ptBeginCylinder]
		   call proc_hex
		   mov word ptr [Begin_Cyl], ax
		   mov al, byte ptr [SI][ptFileSystemName]
		   call proc_hex
		   mov word ptr [FS_ID], ax
		   mov al, byte ptr [SI][ptEndHead]
		   call proc_hex
		   mov word ptr [End_Head], ax
		   mov al, byte ptr [SI][ptEndSector]
		   call proc_hex
		   mov word ptr [End_Sec], ax
		   mov al, byte ptr [SI][ptEndCylinder]
		   call proc_hex
		   mov word ptr [End_Cyl], ax
                   mov ax, word ptr [SI][ptStartSector]
		   mov dx, word ptr [SI][ptStartSector]+2
		   mov bp, 8
		   mov cx, 10
loc_rediv_startsec:
		   call Rx_Dos_Div32
		   add bl,'0'
		   mov byte ptr [P_Start_Sec][bp],bl
		   dec bp
                   and ax, ax
                   jnz short loc_rediv_startsec
                   and dx, dx
                   jnz short loc_rediv_startsec
loc_fspc_startsec:
		   mov byte ptr [P_Start_Sec][bp],20h
		   cmp bp,0
		   jna short loc_conv_psectors
		   dec bp
		   jmp short loc_fspc_startsec
loc_conv_psectors:
		   mov ax, word ptr [SI][ptSectors]
		   mov dx, word ptr [SI][ptSectors]+2
		   mov bp, 8
		 ; mov cx, 10
loc_rediv_psectors:
		   call Rx_Dos_Div32
		   add bl,'0'
		   mov byte ptr [P_Sectors][bp],bl
		   dec bp
                   and ax, ax
                   jnz short loc_rediv_psectors
                   and dx, dx
                   jnz short loc_rediv_psectors
loc_fspc_psectors:
		   mov byte ptr [P_Sectors][bp],20h
		   cmp bp,0
		   jna short loc_filesys_str
		   dec bp
		   jmp short loc_fspc_psectors
loc_filesys_str:
		   mov  bl, byte ptr [SI][ptFileSystemName]
                   cmp  bl, 7
		   ja   short loc_non_dos_fs
		   mov  al, 0Bh
		   mul  bl
		   mov  si, offset FileSys_Names
		   add  si, ax
loc_move_fsname:
		   mov  di, offset P_FileSystem
		   push cx
		   mov  cx,11
		   rep  movsb
		   pop  cx
print_p_entry_row:
                   mov si, offset PTable_Drv
		   call proc_printmsg
                   pop cx
                   pop si
                   retn
loc_non_dos_fs:
		   mov si, offset FS_WIN_32
		   cmp bl, 0Bh
		   jz short loc_move_fsname
		   cmp bl, 0Ch
		   jz short loc_move_fsname
		   mov si, offset FS_WIN_P
		   cmp bl, 0Eh
		   jz short loc_move_fsname
		   mov si, offset FS_WIN_EXT
		   cmp bl, 0Fh
		   jz short loc_move_fsname
		   mov si, offset FS_SCO
		   cmp bl, 63h
		   jz short loc_move_fsname
		   mov si, offset FS_Linux
		   cmp bl, 83h
		   jz short loc_move_fsname
		   mov si, offset FS_LinuxSwap
		   cmp bl, 82h
		   jz short loc_move_fsname
		   mov si, offset FS_LinuxExt
		   cmp bl, 85h
		   jz short loc_move_fsname
                   mov si, offset FS_TR_MULTIX
		   cmp bl, 0A1h
		   jz short loc_move_fsname
                   mov si, offset FS_ATAPITR
                   cmp bl, 0A2h
                   jz short loc_move_fsname
                   mov si, offset RS_TRDD
                   cmp bl, 0A0h
                   jz short loc_move_fsname
		   mov si, offset FS_Others
		   jmp short loc_move_fsname

proc_print_p_entry endp

proc_fill_diskinfo_fields proc near

                inc byte ptr [DPT_No]
                mov al, byte ptr [si]        ; Disk Drive Number
                call proc_hex
                mov word ptr [DI_DDN], ax

                mov al, byte ptr [si][DPDType]
                call proc_hex
                mov word ptr [DI_T], ax

                mov al, byte ptr [si][DPDisks]
                call proc_hex
                mov word ptr [DI_TD], ax

                mov al, byte ptr [si][DPSecPerTrack]
                call proc_hex
                mov word ptr [DI_SPT], ax

                mov al, byte ptr [si][DPHeads]
                call proc_hex
                mov word ptr [DI_H], ax

                mov al, byte ptr [si][DPCylinders]+1
                call proc_hex
                mov word ptr [DI_C], ax
                mov al, byte ptr [si][DPCylinders]
                call proc_hex
                mov word ptr [DI_C]+2, ax

                mov al, byte ptr [si][DPTableOff]+1
                call proc_hex
                mov word ptr [DI_DPTO], ax
                mov al, byte ptr [si][DPTableOff]
                call proc_hex
                mov word ptr [DI_DPTO]+2, ax

                mov al, byte ptr [si][DPTableSeg]+1
                call proc_hex
                mov word ptr [DI_DPTS], ax
                mov al, byte ptr [si][DPTableSeg]
                call proc_hex
                mov word ptr [DI_DPTS]+2, ax

                mov al, byte ptr [si][DPNumOfSecs]+3
                call proc_hex
                mov word ptr [DI_TS_2], ax
                mov al, byte ptr [si][DPNumOfSecs]+2
                call proc_hex
                mov word ptr [DI_TS_2]+2, ax

                mov al, byte ptr [si][DPNumOfSecs]+1
                call proc_hex
                mov word ptr [DI_TS_1], ax
                mov al, byte ptr [si][DPNumOfSecs]
                call proc_hex
                mov word ptr [DI_TS_1]+2, ax

                cmp byte ptr [SI][DAP_PacketSize], 10h
                je short loc_LBA_Ready_YES
                mov word ptr [DI_LBA_Ready], "ON"
                mov word ptr [DI_LBA_Ready]+2, 2020h

loc_return_without_LBA_totals:
                mov byte ptr [Msg_LBA_Totals], 0 ; Don't print
                retn

loc_LBA_Ready_YES:
                mov word ptr [DI_LBA_Ready], "EY"
                mov word ptr [DI_LBA_Ready]+2, " S"

                cmp word ptr [si][GetDParams_48h], 0
                ja short loc_return_without_LBA_totals

                mov byte ptr [Msg_LBA_Totals], 0Dh  ; Print

                mov al, byte ptr [si][GDP_48h_LBA_Sectors]+3
                call proc_hex
                mov word ptr [DI_LBA_TS_1], ax
                mov al, byte ptr [si][GDP_48h_LBA_Sectors]+2
                call proc_hex
                mov word ptr [DI_LBA_TS_1]+2, ax

                mov al, byte ptr [si][GDP_48h_LBA_Sectors]+1
                call proc_hex
                mov word ptr [DI_LBA_TS_2], ax
                mov al, byte ptr [si][GDP_48h_LBA_Sectors]
                call proc_hex
                mov word ptr [DI_LBA_TS_2]+2, ax

                mov al, byte ptr [si][GDP_48h_BytesPerSec]+1
                call proc_hex
                mov word ptr [DI_BytesPersec], ax
                mov al, byte ptr [si][GDP_48h_BytesPerSec]
                call proc_hex
                mov word ptr [DI_BytesPerSec]+2, ax

                retn

proc_fill_diskinfo_fields endp

proc_print_drv_info proc near
                ; input -> DS:SI = Logical Disk Parameters table
                cmp word ptr [SI][LD_BPB][FATSecs], 0
                ja short pass_FAT32_drv_info
                mov word ptr [val_fatsecs], '00'
                mov word ptr [val_fatsecs]+2, '00'
                mov al, byte ptr [SI][LD_BPB][FAT32_DrvNum]
		call proc_hex
		mov word ptr [val_drivenumber], ax
                mov al, byte ptr [SI][LD_BPB][FAT32_Reserved1]
		call proc_hex
		mov word ptr [val_reserved1], ax
                mov al, byte ptr [SI][LD_BPB][FAT32_BootSig]
		call proc_hex
		mov word ptr [val_bootsignature], ax
                mov al, byte ptr [SI][LD_BPB][FAT32_VolID]
		call proc_hex
		mov word ptr [val_volumeid]+6, ax
                mov al, byte ptr [SI][LD_BPB][FAT32_VolID]+1
		call proc_hex
		mov word ptr [val_volumeid]+4, ax
                mov al, byte ptr [SI][LD_BPB][FAT32_VolID]+2
		call proc_hex
		mov word ptr [val_volumeid]+2, ax
                mov al, byte ptr [SI][LD_BPB][FAT32_VolID]+3
		call proc_hex
		mov word ptr [val_volumeid], ax
                push si
                add si, LD_BPB + FAT32_VolLab
                mov di, offset str_volumelabel
		mov cx, 11
		rep movsb
		mov cx, 4
		mov di, offset str_filesystype
		rep movsw
		mov cx, 19
		mov di, offset str_volumelabel
loop_scan_str_FAT32vlabel:
		cmp byte ptr [DI], 0
                jne short pass_i_str_FAT32vlabel
		mov byte ptr [DI], 20h
pass_i_str_FAT32vlabel:
		inc di
                loop loop_scan_str_FAT32vlabel
                pop si
                jmp short pass_FAT16_drv_info
pass_FAT32_drv_info:
                mov al, byte ptr [SI][LD_BPB][FATsecs]
		call proc_hex
		mov word ptr [val_fatsecs]+2, ax
                mov al, byte ptr [SI][LD_BPB][FATsecs]+1
		call proc_hex
		mov word ptr [val_fatsecs], ax
                mov al, byte ptr [SI][LD_BPB][DriveNumber]
		call proc_hex
		mov word ptr [val_drivenumber], ax
                mov al, byte ptr [SI][LD_BPB][Reserved1]
		call proc_hex
		mov word ptr [val_reserved1], ax
                mov al, byte ptr [SI][LD_BPB][bootsignature]
		call proc_hex
		mov word ptr [val_bootsignature], ax
                mov al, byte ptr [SI][LD_BPB][VolumeID]
		call proc_hex
		mov word ptr [val_volumeid]+6, ax
                mov al, byte ptr [SI][LD_BPB][VolumeID]+1
		call proc_hex
		mov word ptr [val_volumeid]+4, ax
                mov al, byte ptr [SI][LD_BPB][VolumeID]+2
		call proc_hex
		mov word ptr [val_volumeid]+2, ax
                mov al, byte ptr [SI][LD_BPB][VolumeID]+3
		call proc_hex
		mov word ptr [val_volumeid], ax
                push si
                add si, LD_BPB + VolumeLabel
		mov di, offset str_volumelabel
		mov cx, 11
		rep movsb
		mov cx, 4
		mov di, offset str_filesystype
		rep movsw
		mov cx, 19
		mov di, offset str_volumelabel
loop_scan_str_volumelabel:
		cmp byte ptr [DI], 0
		jne short pass_i_str_volumelabel
		mov byte ptr [DI], 20h
pass_i_str_volumelabel:
		inc di
		loop loop_scan_str_volumelabel
                pop si
pass_FAT16_drv_info:
                mov al, byte ptr [SI][LD_Name]
		mov byte ptr [str_info_drv_name], al
                push si
                add si, LD_BPB + OemName
		mov di, offset str_oemname
		mov cx, 4
		rep movsw
		mov cx, 8
		mov di, offset str_oemname
loop_scan_str_oemname:
		cmp byte ptr [DI], 0
		jne short pass_i_str_oemname
		mov byte ptr [DI], 20h
pass_i_str_oemname:
		inc di
		loop loop_scan_str_oemname
		pop si
                mov al, byte ptr [SI][LD_BPB][BytesPerSec]
		call proc_hex
		mov word ptr [val_bytespersec]+2, ax
                mov al, byte ptr [SI][LD_BPB][BytesPerSec]+1
		call proc_hex
		mov word ptr [val_bytespersec], ax
                mov al, byte ptr [SI][LD_BPB][SecPerClust]
		call proc_hex
		mov word ptr [val_secperclust], ax
                mov al, byte ptr [SI][LD_BPB][ResSectors]
		call proc_hex
		mov word ptr [val_ressectors]+2, ax
                mov al, byte ptr [SI][LD_BPB][ResSectors]+1
		call proc_hex
		mov word ptr [val_ressectors], ax
                mov al, byte ptr [SI][LD_BPB][FATs]
		call proc_hex
		mov word ptr [val_fats], ax
                mov al, byte ptr [SI][LD_BPB][RootDirEnts]
		call proc_hex
		mov word ptr [val_rootdirents]+2, ax
                mov al, byte ptr [SI][LD_BPB][RootDirEnts]+1
		call proc_hex
		mov word ptr [val_rootdirents], ax
                mov al, byte ptr [SI][LD_BPB][Sectors]
		call proc_hex
		mov word ptr [val_sectors]+2, ax
                mov al, byte ptr [SI][LD_BPB][Sectors]+1
		call proc_hex
		mov word ptr [val_sectors], ax
                mov al, byte ptr [SI][LD_BPB][Media]
		call proc_hex
		mov word ptr [val_media], ax
                mov al, byte ptr [SI][LD_BPB][SecPerTrack]
		call proc_hex
		mov word ptr [val_secpertrack]+2, ax
                mov al, byte ptr [SI][LD_BPB][SecPerTrack]+1
		call proc_hex
		mov word ptr [val_secpertrack], ax
                mov al, byte ptr [SI][LD_BPB][Heads]
		call proc_hex
		mov word ptr [val_heads]+2, ax
                mov al, byte ptr [SI][LD_BPB][Heads]+1
		call proc_hex
		mov word ptr [val_heads], ax
                mov al, byte ptr [SI][LD_BPB][Hidden1]
		call proc_hex
		mov word ptr [val_hidden1]+2, ax
                mov al, byte ptr [SI][LD_BPB][Hidden1]+1
		call proc_hex
		mov word ptr [val_hidden1], ax
                mov al, byte ptr [SI][LD_BPB][Hidden2]
		call proc_hex
		mov word ptr [val_hidden2]+2, ax
                mov al, byte ptr [SI][LD_BPB][Hidden2]+1
		call proc_hex
		mov word ptr [val_hidden2], ax
                mov al, byte ptr [SI][LD_BPB][HugeSec1]
		call proc_hex
		mov word ptr [val_hugesec1]+2, ax
                mov al, byte ptr [SI][LD_BPB][HugeSec1]+1
		call proc_hex
		mov word ptr [val_hugesec1], ax
                mov al, byte ptr [SI][LD_BPB][HugeSec2]
		call proc_hex
		mov word ptr [val_hugesec2]+2, ax
                mov al, byte ptr [SI][LD_BPB][HugeSec2]+1
		call proc_hex
		mov word ptr [val_hugesec2], ax

		mov si, offset msg_drive_info
		call proc_printmsg
		retn

proc_print_drv_info endp

P_Table_Header:
               db 7
               db 0Dh, 0Ah
               db "[TRDOS] PRESENT FIXED DISK PARTITIONS   Erdogan TAN 2005"
               db  0Dh, 0Ah, 0Dh, 0Ah
               db "DRV PN  S  BH  BS  BC  FS  EH  ES  EC  START SEC  SECTORS  FILE SYSTEM"
               db 0Dh, 0Ah
               db "--- -- --- --- --- --- --- --- --- --- --------- --------- -----------"
               db 0Dh, 0Ah, 0h
PTable_Drv:
               db  "hd"
               db  0,20h
               db  "p"
P_Number:      db  0,20h
P_Status:      dw  0
               db  "h "
Begin_Head:    dw  0
               db  "h "
Begin_Sec:     dw  0
               db "h "
Begin_Cyl:     dw  0
               db "h "
FS_ID:         dw  0
               db "h "
End_Head:      dw  0
               db "h "
End_Sec:       dw  0
               db "h "
End_Cyl:       dw  0
               db "h "
P_Start_Sec:   dd  0
               dd  0
               db "  "
P_Sectors:     dd  0
               dd  0
               db "  "
P_FileSystem:  db 11 dup(20h)
               db 0Dh, 0Ah, 0h

FileSys_Names: ; 2003 (Valid FileSystems for TR-DOS Project in 2005)
               db "           "
               db "TrDos FS1  "  ; 01h (16 bit, 512 bytes per sec)
                                 ; Reserved for future TRDOS versions
               db "TrDos FS2  "  ; 02h (32 bit, 512 bytes per sec)
                                 ; Reserved for future TRDOS versions
               db "TrDos FS3  "  ; 03h (32 bit, 2048 bytes per sec)
                                 ; Reserved for future TRDOS versions
               db "DOS FAT16  "  ; 04h = FAT16 < 32MB
                                 ; TRDOS doesn't use this FS for hard disks
               db "DOS EXT    "  ; 05h = Extended DOS Partition
                                 ; TRDOS uses DOS extended partitions
               db "DOS FAT16  "  ; 06h = FAT16 > 32MB, CHS Mode
                                 ; TRDOS uses FAT16 Big CHS mode FS
FS_NTFS:       db "WINDOWS NT "  ; 07h , WINDOWS 2000/XP NTFS Partition
                                 ; TRDOS doesn't use NTFS
FS_WIN_32:     db "WIN4 FAT32 "  ; OBh = FAT32 CHS, 0Ch = FAT32 LBA
                                 ; TRDOS uses FAT32 CHS and LBA modes
FS_WIN_P:      db "WIN4 FAT16 "  ; 0Eh = FAT16, LBA Mode
                                 ; TRDOS uses FAT16 LBA mode FS
FS_WIN_EXT:    db "WIN4 EXT   "  ; 0Fh = Extented Partition, LBA Mode
                                 ; TRDOS uses WINDOWS extended partitions
FS_SCO:        db "SCO Unix   "  ; 63h , SCO UNIX, UNIXWARE, OPENSERVER
                                 ; TRDOS doesn't use any UNIX file systems 
FS_Linux:      db "Linux      "  ; 83h , LINUX NATIVE (ext2) Partition
FS_LinuxSwap:  db "Linux Swap "  ; 82h , LINUX SWAP Partition
FS_LinuxExt:   db "Linux Ext  "  ; 85h , LINUX EXTENDED Partition
                                 ; TRDOS doesn't use any LINUX file systems 
FS_TR_MULTIX:  db "Singlix FS1"  ; A1h , (32 bit, 512 bytes per sector)
                                 ; TR-MULTIX LBA disk FS (ATA device LBA FS)
FS_ATAPITR:    db "Singlix FS2"  ; A2h , (32 bit, 2048 bytes per sector)
                                 ; TR-MULTIX ATAPI device LBA FS
RS_TRDD:       db "RDD        "  ; A0h , (Random Data Disk) LBA
                                 ; Reserved (New Record System)
FS_Others:     db "Non-DOS    "  ; Non DOS, Another or Unknown File Systems

Disk_Info:
                db 7
                db "TR-DOS DISK PARAMETERS TABLE [ Disk "
DPT_No:         db "0"
                db " ]"
                db 0Dh, 0Ah, 0Dh, 0Ah
                db "Disk Drive Number: "
DI_DDN:         dw 3030h
                db 'h'
                db 0Dh, 0Ah
                db "Drive Type: "
DI_T:           dw 3030h
                db 'h'
                db 0Dh, 0Ah
                db "Total Drives: "
DI_TD:          dw 3030h
                db 'h'
                db 0Dh, 0Ah
                db "Sectors per Track: "
DI_SPT:         dw 3030h
                db 'h'
                db 0Dh, 0Ah
                db "Heads: "
DI_H:           dw 3030h
                db 'h'
                db 0Dh, 0Ah
                db "Cylinders: "
DI_C:           dd 30303030h
                db 'h'
                db 0Dh, 0Ah
                db "BIOS DPT Segment: "
DI_DPTS:        dd 30303030h
                db 'h'
                db 0Dh, 0Ah
                db "BIOS DPT Offset: "
DI_DPTO:        dd 30303030h
                db 'h'
                db 0Dh, 0Ah
                db "Total Sectors: "
DI_TS_1:        dd 30303030h
                db 'h:'
DI_TS_2:        dd 30303030h
                db 'h'
                db 0Dh, 0Ah
                db 0Dh, 0Ah
                db "LBA Ready: "
DI_LBA_Ready:   db "NO  "
                db 0Dh, 0Ah
Msg_LBA_Totals:
                db 0Dh, 0Ah
                db "LBA Total Sectors: "
DI_LBA_TS_1:    dd 30303030h
                db 'h:'
DI_LBA_TS_2:    dd 30303030h
                db 'h'
                db 0Dh, 0Ah
                db "Bytes in a Sector: "
DI_BytesPersec: dd 30303030h
                db "h"
                db 0Dh, 0Ah, 0

Msg_drive_info:
                   db 7
                   db "[ TR-DOS DRIVE ] "
str_info_drv_name: db "0:"
                   db  0Dh, 0Ah
                   db  0Dh, 0Ah
                   db "OEM Name :  "
str_oemname:       db 8 dup(20h)
                   db 0Dh, 0Ah
                   db "Bytes Per Sector :  "
val_bytespersec:   dd 0
                   db "h"
                   db 0Dh, 0Ah
                   db "Sectors Per Cluster :  "
val_secperclust:   dw 0
                   db "h"
                   db 0Dh, 0Ah
                   db "Reserved Sectors :  "
val_ressectors:    dd 0
                   db "h"
                   db 0Dh, 0Ah
                   db "Number Of FATs :  "
val_fats:          dw 0
                   db "h"
                   db 0Dh, 0Ah
                   db "Root Directory Entries :  "
val_rootdirents:   dd 0
                   db "h"
                   db 0Dh, 0Ah
                   db "Total Sectors :  "
val_sectors:       dd 0
                   db "h"
                   db 0Dh, 0Ah
                   db "Media :  "
val_media:         dw 0
                   db "h"
                   db 0Dh, 0Ah
                   db "FAT Sectors :  "
val_fatsecs:       dd 0
                   db "h"
                   db 0Dh, 0Ah
                   db "Sectors Per Track :  "
val_secpertrack:   dd 0
                   db "h"
                   db 0Dh, 0Ah
                   db "Heads :  "
val_heads:         dd 0
                   db "h"
                   db 0Dh, 0Ah
                   db "Hidden Sectors :  "
val_hidden2:       dd 0
val_hidden1:       dd 0
                   db "h"
                   db 0Dh, 0Ah
                   db "Total Sectors (Huge) :  "
val_hugesec2:      dd 0
val_hugesec1:      dd 0
                   db "h"
                   db 0Dh, 0Ah
                   db "Drive Number :  "
val_drivenumber:   dw 0
                   db "h"
                   db 0Dh, 0Ah
                   db "Reserved Byte :  "
val_reserved1:     dw 0
                   db "h"
                   db 0Dh, 0Ah
                   db "Boot Signature :  "
val_bootsignature: dw 0
                   db "h"
                   db 0Dh, 0Ah
                   db "Volume ID :  "
val_volumeid:      dd 0
                   dd 0
                   db 0Dh, 0Ah
                   db "Volume Label :  "
str_volumelabel:   db 11 dup(20h)
                   db 0Dh, 0Ah
                   db "File System :  "
str_filesystype:   db 8 dup (20h)
                   db 0Dh, 0Ah
                   db 0Dh, 0Ah
                   db 0
Magic_Bytes:
                   db 4
                   db 1
Press_Any_Key:
                db 0Dh, 0Ah 
                db "Press any key to continue ..."
                db 0Dh, 0Ah, 0
Program_Name:
                   db 7
                   db "[TRDOS] DISK INFO "
Version_Str:       db "v2.0   Erdogan Tan 2004-2005"
                   db 0Dh, 0Ah
                   db "File Size = "
                   db 6 dup(0)
FileSize_StrPlus5: db " bytes"
                   db 0Dh, 0Ah
                   db 0

Current_TRDOS_Drv: db 0
Logical_DOSDisks:  dw 3328 dup(0)
File_Size:         dw $-254

Present            ends

                   end  start

    

    

    

 index.html  specs.html  trdos.html

Tarkan - KUZU KUZU