     1                                  ; ****************************************************************************
     2                                  ; HDIMAGE.ASM (HDIMAGE.COM) - TRDOS 386 Hard Disk Image Formatting Utility
     3                                  ; 						      (for MSDOS/WINDOWS)
     4                                  ; ****************************************************************************
     5                                  ; Last Update: 03/02/2018
     6                                  ; ----------------------------------------------------------------------------
     7                                  ; Beginning: 03/12/2017
     8                                  ; ----------------------------------------------------------------------------
     9                                  ; Assembler: NASM version 2.11
    10                                  ; ----------------------------------------------------------------------------
    11                                  ; Turkish Rational DOS
    12                                  ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
    13                                  ;
    14                                  ; Derived from 'fdimage.s'(FDIMAGE.COM) source code by Erdogan Tan
    15                                  ; (02/12/2017)
    16                                  ;
    17                                  ; Derived from 'fdformat.s'(FDFORMAT.COM) source code by Erdogan Tan
    18                                  ; (29/11/2017)
    19                                  ;
    20                                  ; Derived from 'FSFDISK.ASM'(FSFDISK.COM) source code by Erdogan Tan
    21                                  ; (27/04/2009)
    22                                  ;
    23                                  ; Derived from 'UNIXCOPY.ASM' (UNIXCOPY.COM) source code by Erdogan Tan
    24                                  ; (04/12/2015)
    25                                  ; ****************************************************************************
    26                                  ; nasm hdimage.s -l hdimage.lst -o HDIMAGE.COM
    27                                  
    28                                  bsDriveNumber   equ TRDOS_FAT_hd_bs + 36
    29                                  bsVolumeID      equ TRDOS_FAT_hd_bs + 39
    30                                  bsVolumeLabel   equ TRDOS_FAT_hd_bs + 43
    31                                  
    32                                  ; DTA (PSP+80h= Offset 128)
    33                                  DTA_Attrib equ 149 ; PDP+21
    34                                  DTA_Time equ 150 ; PSP+22
    35                                  DTA_Date equ 152 ; PSP 24
    36                                  DTA_FileSize equ 154 ; PSP + 26
    37                                  DTA_FileName equ 158 ; PSP + 30
    38                                  
    39                                  ; Masterboot / Partition Table at Beginning+1BEh
    40                                  ptBootable      equ 0
    41                                  ptBeginHead     equ 1
    42                                  ptBeginSector   equ 2
    43                                  ptBeginCylinder equ 3
    44                                  ptFileSystemID	equ 4
    45                                  ptEndHead       equ 5
    46                                  ptEndSector     equ 6
    47                                  ptEndCylinder   equ 7
    48                                  ptStartSector   equ 8
    49                                  ptSectors       equ 12
    50                                  
    51                                  ; BIOS Disk Parameters
    52                                  DPDiskNumber  equ 0h
    53                                  DPDType       equ 1h
    54                                  DPReturn      equ 2h
    55                                  DPHeads       equ 3h
    56                                  DPCylinders   equ 4h
    57                                  DPSecPerTrack equ 6h
    58                                  DPDisks       equ 7h
    59                                  DPTableOff    equ 8h
    60                                  DPTableSeg    equ 0Ah
    61                                  DPNumOfSecs   equ 0Ch
    62                                  
    63                                  ; BIOS INT 13h Extensions (LBA extensions)
    64                                  ; Just After DP Data (DPDiskNumber+)
    65                                  DAP_PacketSize equ 10h  ; If extensions present, this byte will be >=10h
    66                                  DAP_Reserved1 equ 11h   ; Reserved Byte 
    67                                  DAP_NumOfBlocks equ 12h ; Value of this byte must be 0 to 127
    68                                  DAP_Reserved2 equ 13h   ; Reserved Byte
    69                                  DAP_Destination equ 14h ; Address of Transfer Buffer as SEGMENT:OFFSET
    70                                  DAP_LBA_Address equ 18h ; LBA=(C1*H0+H1)*S0+S1-1
    71                                                          ; C1= Selected Cylinder Number
    72                                                          ; H0= Number Of Heads (Maximum Head Number + 1)
    73                                                          ; H1= Selected Head Number
    74                                                          ; S0= Maximum Sector Number
    75                                                          ; S1= Selected Sector Number
    76                                                          ; QUAD WORD
    77                                  ; DAP_Flat_Destination equ 20h ; 64 bit address, if value in 4h is FFFF:FFFFh
    78                                                               ; QUAD WORD (Also, value in 0h must be 18h) 
    79                                                               ; TR-DOS will not use 64 bit Flat Address
    80                                  
    81                                  ; INT 13h Function 48h "Get Enhanced Disk Drive Parameters"
    82                                  ; Just After DP Data (DPDiskNumber+)
    83                                  GetDParams_48h equ 20h ; Word. Data Lenght, must be 26 (1Ah) for short data.
    84                                  GDP_48h_InfoFlag equ 22h ; Word
    85                                  ; Bit 1 = 1 -> The geometry returned in bytes 4-15 is valid.
    86                                  GDP_48h_NumOfPCyls equ 24h ; Double Word. Number physical cylinders.
    87                                  GDP_48h_NumOfPHeads equ 28h ; Double Word. Number of physical heads.
    88                                  GDP_48h_NumOfPSpT equ 2Ch ; Double word. Num of physical sectors per track.
    89                                  GDP_48h_LBA_Sectors equ 30h ; 8 bytes. Number of physical/LBA sectors.
    90                                  GDP_48h_BytesPerSec equ 38h ; Word. Number of bytes in a sector.
    91                                  
    92                                  ; Cursor Location
    93                                  CCCpointer equ  0450h   ; BIOS data, current cursor column
    94                                  
    95                                  ; MINIMUM & MAXIMUM SECTORS (partition and disk size limits in sectors)
    96                                  MINPARTSIZE equ 4096 ; 2GB
    97                                  MAXPARTSIZE equ 4128768 - 1 ; 2GB - masterboot sector	
    98                                  MINDISKSIZE equ 16384 ; 8MB
    99                                  MAXDISKSIZE equ 4128768 ; 2GB
   100                                  
   101                                  pTableOffset equ 1BEh ; 446		
   102                                  
   103                                  [BITS 16]
   104                                  [ORG 100h]
   105                                  
   106                                  	;cli
   107                                  	;cld
   108                                  	;push	cs
   109                                  	;pop	ss
   110                                  	;mov	sp, 0FFFEh
   111                                  	;sti
   112                                  	
   113 00000000 BB[DE4C]                	mov	bx, SizeOfFile+100
   114 00000003 83C30F                          add	bx, 15
   115 00000006 D1EB                            shr	bx, 1
   116 00000008 D1EB                            shr	bx, 1
   117 0000000A D1EB                    	shr	bx, 1
   118 0000000C D1EB                    	shr	bx, 1
   119 0000000E B44A                            mov	ah, 4Ah ; modify memory allocation
   120                                          ;push	cs
   121                                          ;pop	es
   122 00000010 CD21                            int	21h 
   123                                  
   124                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   125                                  ; get fd image file name
   126                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   127                                  
   128 00000012 BE8000                  	mov	si, 80h			; PSP command tail
   129 00000015 AC                       	lodsb
   130 00000016 08C0                    	or	al, al 			; command tail length                            
   131 00000018 0F848705                	jz	R_17			; jump if zero
   132                                  R_01:
   133 0000001C AC                      	lodsb
   134 0000001D 3C20                    	cmp	al, ' '			; is it SPACE ?
   135 0000001F 74FB                    	je	short R_01 		
   136 00000021 0F827E05                	jb	R_17
   137                                  	
   138                                  	; check hd image file name
   139                                  R_02:
   140 00000025 BF[7243]                       	mov	di, img_file_name
   141 00000028 AA                      	stosb
   142                                  R_03:
   143 00000029 AC                      	lodsb
   144                                  	;cmp	al, 0Dh ; ENTER (CR) key
   145 0000002A 3C20                    	cmp	al, 20h ; ' '
   146 0000002C 760C                    	jna	short R_04
   147 0000002E AA                      	stosb
   148 0000002F 81FF[7E43]              	cmp	di, img_file_name + 12
   149 00000033 72F4                    	jb	short R_03
   150 00000035 803C20                  	cmp	byte [si], 20h 
   151 00000038 773F                    	ja	short R_11
   152                                  R_04:
   153                                  	;sub	al, al
   154                                  	;stosb
   155                                  
   156                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   157                                  ; File name capitalization
   158                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   159                                  
   160 0000003A BE[7243]                	mov	si, img_file_name
   161 0000003D 89F7                    	mov	di, si
   162 0000003F 89F3                    	mov	bx, si
   163                                  R_05:
   164 00000041 AC                      	lodsb
   165 00000042 3C61                    	cmp	al, 'a'
   166 00000044 730D                    	jnb	short R_07
   167 00000046 20C0                    	and	al, al
   168 00000048 7412                    	jz	short R_08
   169 0000004A 3C2E                    	cmp	al, '.'
   170 0000004C 7502                    	jne	short R_06
   171 0000004E 89FB                    	mov	bx, di ; dot position	
   172                                  R_06:
   173 00000050 AA                      	stosb
   174 00000051 EBEE                    	jmp	short R_05 		
   175                                  R_07:
   176 00000053 3C7A                    	cmp	al, 'z'
   177 00000055 77F9                    	ja	short R_06
   178 00000057 24DF                    	and	al, 0DFh ; NOT 32
   179 00000059 AA                      	stosb
   180 0000005A EBE5                    	jmp	short R_05	
   181                                  R_08:
   182 0000005C 8805                    	mov	[di], al
   183 0000005E 4F                      	dec	di
   184 0000005F 39FB                    	cmp	bx, di
   185 00000061 7316                    	jnb	short R_11
   186 00000063 29DF                    	sub	di, bx
   187 00000065 81EB[7243]              	sub	bx, img_file_name
   188 00000069 83FF03                  	cmp	di, 3
   189 0000006C 7606                    	jna	short R_09
   190 0000006E 21DB                    	and	bx, bx
   191 00000070 7507                    	jnz	short R_11
   192 00000072 EB0E                    	jmp	short R_10		
   193                                  R_09:
   194 00000074 83FB08                  	cmp	bx, 8
   195 00000077 7609                    	jna	short R_10
   196                                  R_11:
   197 00000079 BE[5B35]                	mov	si, msg_inv_file_name
   198                                  R_12:	
   199 0000007C E86319                  	call	print_msg
   200 0000007F E91605                  	jmp	R_16
   201                                  
   202                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   203                                  ; Find image file
   204                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   205                                  	
   206                                  R_10:
   207 00000082 BA[7243]                	mov	dx, img_file_name
   208 00000085 B93F00                  	mov	cx, 3Fh ; File Attributes
   209 00000088 B44E                    	mov	ah, 4Eh ; MS-DOS Function = Find First File
   210 0000008A CD21                    	int	21h
   211 0000008C 0F822A05                	jc	R_20
   212                                  
   213                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   214                                  ; Check image file features
   215                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   216                                  
   217                                  R_14:
   218 00000090 BE9500                  	mov	si, DTA_Attrib
   219 00000093 8A04                    	mov	al, [si]
   220 00000095 241F                    	and	al, 1Fh ; directory, volume label, system, hidden, read only
   221 00000097 0F851905                	jnz	R_19     
   222 0000009B BE9A00                  	mov	si, DTA_FileSize
   223 0000009E AD                      	lodsw
   224                                  	; max. size of hard disk image = 63sectors*64heads*1024cylinders
   225 0000009F 8B14                    	mov	dx, [si]
   226 000000A1 81FA007E                	cmp	dx, 7E00h ; 2GB upper limit (7E000000h)
   227 000000A5 0F870B05                	ja	R_19
   228 000000A9 720B                    	jb	short R_14a
   229 000000AB 21C0                    	and	ax, ax
   230 000000AD 0F850305                	jnz	R_19
   231 000000B1 B80004                  	mov	ax, 1024
   232 000000B4 EB6F                    	jmp	short R_14e
   233                                  R_14a:
   234 000000B6 A9FF01                  	test	ax, 511 ; check file size for sector boundary
   235 000000B9 0F85F704                	jnz	R_19
   236 000000BD 83FA7E                  	cmp	dx, 7Eh  ; 8MB lower limit  (7E0000h)
   237 000000C0 0F82F004                	jb	R_19
   238                                  R_14b:	
   239                                  	; cylinders*63sectors*16heads (<=528MB)
   240 000000C4 81FA801F                	cmp	dx, 1F80h ; 1024*16*63 (1F800000h)
   241 000000C8 7726                    	ja	short R_14c
   242 000000CA 7211                    	jb	short R_14x
   243 000000CC 21C0                    	and	ax, ax
   244 000000CE 0F857203                	jnz	R_14y
   245                                  	; = 528MB (1024*16*63*512)
   246 000000D2 C706[E430]1000          	mov	word [heads], 16
   247 000000D8 B80004                  	mov	ax, 1024
   248 000000DB EB4E                    	jmp	short R_14f	
   249                                  R_14x:
   250                                  	; < 528MB
   251 000000DD B9F003                  	mov	cx, 63*16
   252 000000E0 F7F1                    	div	cx
   253 000000E2 21D2                    	and	dx, dx
   254 000000E4 0F85CC04                	jnz	R_19
   255 000000E8 C706[E430]1000          	mov	word [heads], 16
   256 000000EE EB3B                    	jmp	short R_14f	
   257                                  R_14c:
   258                                  	; cylinders*63sectors*32heads (>528MB, <=1GB)
   259 000000F0 81FA003F                	cmp	dx, 3F00h ; 1024*32*63 (3F000000h)
   260 000000F4 7724                    	ja	short R_14d
   261 000000F6 720F                    	jb	short R_14w
   262 000000F8 21C0                    	and	ax, ax
   263 000000FA 751E                    	jnz	short R_14d
   264                                  	; = 1GB (1024*32*63*512)
   265 000000FC C706[E430]1000          	mov	word [heads], 16
   266 00000102 B80004                  	mov	ax, 1024
   267 00000105 EB24                    	jmp	short R_14f	
   268                                  R_14w:
   269 00000107 B9E007                  	mov	cx, 63*32
   270 0000010A F7F1                    	div	cx
   271 0000010C 21D2                    	and	dx, dx
   272 0000010E 0F85A204                	jnz	R_19
   273 00000112 C706[E430]2000          	mov	word [heads], 32
   274 00000118 EB11                    	jmp	short R_14f
   275                                  R_14d:
   276                                  	; cylinders*63sectors*64heads (>1GB, <=2GB)
   277 0000011A B9C00F                  	mov	cx, 63*64
   278 0000011D F7F1                    	div	cx
   279 0000011F 21D2                    	and	dx, dx
   280 00000121 0F858F04                	jnz	R_19
   281                                  R_14e:
   282 00000125 C706[E430]4000          	mov	word [heads], 64
   283                                  R_14f:
   284 0000012B C706[E230]3F00          	mov	word [sectors], 63
   285 00000131 A3[E630]                	mov	[cylinders], ax
   286                                  
   287                                  	; calculate total sectors (by using CHS values)
   288 00000134 A1[E230]                	mov	ax, [sectors]
   289 00000137 F726[E430]              	mul	word [heads]
   290 0000013B 8B16[E630]              	mov	dx, [cylinders]
   291 0000013F F7E2                    	mul	dx
   292 00000141 A3[8043]                	mov	[total_sectors], ax
   293 00000144 8916[8243]              	mov	[total_sectors+2], dx
   294                                  	
   295                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   296                                  ; Load masterboot sector of HD image file
   297                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   298                                  
   299 00000148 B002                    	mov	al, 2 ; open for reading and writing
   300 0000014A BA[7243]                	mov	dx, img_file_name
   301 0000014D B43D                    	mov	ah, 3Dh ; open file
   302 0000014F CD21                    	int	21h
   303 00000151 0F826A18                	jc	R_29
   304                                  
   305 00000155 A3[E030]                	mov	[img_file_handle], ax
   306                                  
   307 00000158 B43F                    	mov	ah, 3Fh ; read file
   308 0000015A B90002                  	mov	cx, 512
   309 0000015D BA[1E41]                	mov	dx, MasterBootBuff
   310 00000160 CD21                    	int	21h
   311 00000162 9C                      	pushf
   312 00000163 50                      	push	ax
   313 00000164 B43E                    	mov	ah, 3Eh ; close file
   314 00000166 8B1E[E030]              	mov	bx, [img_file_handle]
   315 0000016A CD21                    	int	21h
   316 0000016C 58                      	pop	ax
   317 0000016D 9D                      	popf
   318 0000016E 0F824D18                	jc	R_29
   319                                  
   320 00000172 813E[1C43]55AA          	cmp	word [MBIDCode], 0AA55h
   321 00000178 0F853804                	jne	R_19 ; invalid
   322                                  
   323 0000017C BE[DC42]                	mov	si, MasterBootBuff+446 ; Partition table offset
   324 0000017F B90400                  	mov	cx, 4
   325 00000182 BFFFFF                  	mov	di, 65535
   326                                  R_14g:
   327 00000185 47                      	inc	di
   328 00000186 8A6404                  	mov	ah, [si+ptFileSystemID]
   329 00000189 20E4                    	and	ah, ah
   330 0000018B 0F84C800                	jz	R_14i ; empty
   331                                  
   332 0000018F FE06[0444]              	inc	byte [pcount] ; partition count
   333                                  
   334 00000193 88A5[8443]              	mov	[pType+di], ah  ; Partition Type (FS type)
   335 00000197 A0[E430]                	mov	al, [heads]
   336 0000019A FEC8                    	dec	al
   337 0000019C 8A6401                  	mov	ah, [si+ptBeginHead]
   338 0000019F 38E0                    	cmp	al, ah
   339 000001A1 0F870F04                	ja	R_19 ; invalid
   340 000001A5 88A5[8843]              	mov	[bHead+di], ah
   341 000001A9 8A6405                  	mov	ah, [si+ptEndHead]
   342 000001AC 38E0                    	cmp	al, ah
   343 000001AE 0F870204                	ja	R_19 ; invalid
   344 000001B2 88A5[9843]              	mov	[eHead+di], ah
   345 000001B6 A0[E230]                	mov	al, [sectors]
   346 000001B9 8A7C02                  	mov	bh, [si+ptBeginSector]
   347 000001BC 88FC                    	mov	ah, bh
   348 000001BE 80E43F                  	and	ah, 63
   349 000001C1 38E0                    	cmp	al, ah
   350 000001C3 0F87ED03                	ja	R_19 ; invalid
   351 000001C7 88A5[8C43]              	mov	[bSector+di], ah
   352 000001CB 8A7406                  	mov	dh, [si+ptEndSector]
   353 000001CE 88F4                    	mov	ah, dh
   354 000001D0 80E43F                  	and	ah, 63
   355 000001D3 38E0                    	cmp	al, ah
   356 000001D5 0F87DB03                	ja	R_19 ; invalid
   357 000001D9 88A5[9C43]              	mov	[eSector+di], ah	
   358 000001DD C0EF06                  	shr	bh, 6
   359 000001E0 8A5C03                  	mov	bl, [si+ptBeginCylinder]
   360 000001E3 A1[E630]                	mov	ax, [cylinders]
   361 000001E6 48                      	dec	ax	
   362 000001E7 39D8                    	cmp	ax, bx
   363 000001E9 0F87C703                	ja	R_19 ; invalid
   364 000001ED D1E7                    	shl	di, 1 ; word offset
   365 000001EF 899D[9043]              	mov	[bCylinder+di], bx
   366 000001F3 C0EE06                  	shr	dh, 6
   367 000001F6 8A5407                  	mov	dl, [si+ptEndCylinder]
   368 000001F9 39D0                    	cmp	ax, dx
   369 000001FB 0F87B503                	ja	R_19 ; invalid
   370 000001FF 8995[A043]              	mov	[eCylinder+di], dx
   371                                  	
   372 00000203 D1E6                    	shl	si, 1
   373 00000205 D1E6                    	shl	si, 1	
   374                                  
   375 00000207 8B440C                  	mov	ax, [si+ptSectors]
   376 0000020A 8B540E                  	mov	dx, [si+ptSectors+2]
   377 0000020D 09C2                    	or	dx, ax
   378 0000020F 0F84A103                	jz	R_19 ; invalid
   379                                  
   380 00000213 D1E7                    	shl	di, 1 ; dword offset
   381                                  
   382 00000215 8B4408                  	mov	ax, [si+ptStartSector]
   383 00000218 8B540A                  	mov	dx, [si+ptStartSector+2]
   384                                  
   385 0000021B 8985[A843]              	mov	[bLBA+di], ax
   386 0000021F 8995[AA43]              	mov	[bLBA+2+di], dx	
   387                                  
   388 00000223 03440C                  	add	ax, [si+ptSectors]
   389 00000226 13540E                  	adc	dx, [si+ptSectors+2]
   390 00000229 0F828703                	jc	R_19 ; invalid
   391                                  
   392 0000022D D1EE                    	shr	si, 1
   393 0000022F D1EE                    	shr	si, 1	
   394                                  
   395 00000231 8985[B843]              	mov	[eLBA+di], ax
   396 00000235 8995[BA43]              	mov	[eLBA+2+di], dx
   397                                  
   398 00000239 3B16[8243]              	cmp	dx, [total_sectors+2]
   399 0000023D 0F877303                	ja	R_19 ; invalid
   400 00000241 7208                    	jb	short R_14h
   401 00000243 3B06[8043]              	cmp	ax, [total_sectors] ; (ax + 1) <= total sectors
   402 00000247 0F836903                	jnb	R_19 ; invalid
   403                                  R_14h:
   404 0000024B 49                      	dec	cx
   405 0000024C 741F                    	jz	short R_14k
   406 0000024E C1EF02                  	shr	di, 2 ; from dword offset to byte offset	
   407 00000251 83C610                  	add	si, 16
   408 00000254 E92EFF                  	jmp	R_14g
   409                                  R_14i:
   410                                  	; Empty partition table check (all of 16 bytes must be 0)
   411 00000257 51                      	push	cx
   412 00000258 31D2                    	xor	dx, dx
   413 0000025A B110                    	mov	cl, 16
   414                                  R_14j:
   415 0000025C AD                      	lodsw
   416 0000025D 01C2                    	add	dx, ax
   417 0000025F E2FB                    	loop	R_14j
   418 00000261 59                      	pop	cx
   419 00000262 09D2                    	or	dx, dx
   420 00000264 0F854C03                	jnz	R_19 ; invalid
   421 00000268 49                      	dec	cx
   422 00000269 0F8518FF                	jnz	R_14g
   423                                  R_14k:
   424 0000026D 803E[0444]00            	cmp	byte [pcount], 0
   425 00000272 0F8667FE                	jna	R_14x ; empty partition table
   426                                  
   427                                  	; masterboot partition table is not detected as invalid!?
   428 00000276 BE[DC42]                	mov	si, MasterBootBuff+1BEh ; +446 ; Same address !!!
   429 00000279 BF[DC42]                	mov	di, PartitionTable ;; Same address !!!
   430 0000027C B120                    	mov	cl, 32
   431 0000027E F3A5                    	rep	movsw
   432                                  
   433                                  	; Check disk parameters with current CHS settings
   434 00000280 BBFFFF                  	mov	bx, 65535
   435 00000283 31FF                    	xor	di, di
   436 00000285 B104                    	mov	cl, 4
   437                                  R_14l:
   438 00000287 43                      	inc	bx
   439 00000288 80BF[8443]00            	cmp	byte [bx+pType], 0
   440 0000028D 767F                    	jna	short R_14m
   441                                  
   442 0000028F 47                      	inc	di
   443                                  
   444 00000290 D1E3                    	shl	bx, 1
   445 00000292 8B87[9043]              	mov	ax, [bx+bCylinder]
   446 00000296 F726[E430]              	mul	word [heads]
   447 0000029A 52                      	push	dx
   448 0000029B 50                      	push	ax
   449 0000029C D1EB                    	shr	bx, 1
   450 0000029E 8A87[8843]              	mov	al, [bx+bHead]
   451 000002A2 F626[E230]              	mul	byte [sectors]
   452 000002A6 5A                      	pop	dx ; ax
   453 000002A7 01D0                    	add	ax, dx
   454 000002A9 5A                      	pop	dx
   455 000002AA 83D200                  	adc	dx, 0
   456 000002AD 0287[8C43]              	add	al, [bx+bSector]
   457 000002B1 80D400                  	adc	ah, 0
   458 000002B4 83D200                  	adc	dx, 0
   459 000002B7 D1E3                    	shl	bx, 1
   460 000002B9 D1E3                    	shl	bx, 1
   461 000002BB 3B97[AA43]              	cmp	dx, [bLBA+bx+2]
   462 000002BF 0F85F102                	jne	R_19
   463 000002C3 3B87[A843]              	cmp	ax, [bLBA+bx]
   464 000002C7 0F85E902                	jne	R_19
   465 000002CB D1EB                    	shr	bx, 1
   466 000002CD 8B87[A043]              	mov	ax, [bx+eCylinder]
   467 000002D1 F726[E430]              	mul	word [heads]
   468 000002D5 52                      	push	dx
   469 000002D6 50                      	push	ax
   470 000002D7 D1EB                    	shr	bx, 1
   471 000002D9 8A87[9843]              	mov	al, [bx+eHead]
   472 000002DD F626[E230]              	mul	byte [sectors]
   473 000002E1 5A                      	pop	dx ; ax
   474 000002E2 01D0                    	add	ax, dx
   475 000002E4 5A                      	pop	dx
   476 000002E5 83D200                  	adc	dx, 0
   477 000002E8 0287[9C43]              	add	al, [bx+eSector]
   478 000002EC 80D400                  	adc	ah, 0
   479 000002EF 83D200                  	adc	dx, 0
   480 000002F2 D1E3                    	shl	bx, 1
   481 000002F4 D1E3                    	shl	bx, 1
   482 000002F6 3B97[BA43]              	cmp	dx, [eLBA+bx+2]
   483 000002FA 0F85B602                	jne	R_19
   484 000002FE 3B87[B843]              	cmp	ax, [eLBA+bx]
   485 00000302 0F85AE02                	jne	R_19
   486                                  
   487 00000306 D1EB                    	shr	bx, 1
   488 00000308 D1EB                    	shr	bx, 1
   489                                  
   490 0000030A 889D[0444]              	mov	[pcount+di], bl ; partition number (0 to 3) 
   491                                  R_14m:
   492 0000030E 49                      	dec	cx
   493 0000030F 0F8574FF                	jnz	R_14l
   494                                  R_14r:
   495                                  	; LBA and CHS values of all partitions are OK (here)
   496 00000313 FE06[0944]              	inc	byte [psort]
   497 00000317 8A0E[0944]              	mov	cl, [psort]
   498 0000031B 89CF                    	mov	di, cx
   499 0000031D 8A0E[0444]              	mov	cl, [pcount]
   500 00000321 8A1E[0544]              	mov	bl, [pcount+1]
   501 00000325 889D[0944]              	mov	[psort+di], bl
   502 00000329 FEC9                    	dec	cl
   503 0000032B 0F84CA00                	jz	R_14q ; 1 partition only
   504                                  
   505                                  	; Checking partition overlaps
   506                                  	; (by sorting beginning addresses at first)
   507                                  
   508 0000032F BE0200                  	mov	si, 2 ; 2 or 3 or 4 partitions
   509 00000332 30FF                    	xor	bh, bh
   510 00000334 D0E3                    	shl	bl, 1
   511 00000336 D0E3                    	shl	bl, 1
   512 00000338 8B87[A843]              	mov	ax, [bx+bLBA]
   513 0000033C 8B97[AA43]              	mov	dx, [bx+bLBA+2]
   514 00000340 8A9C[0444]              	mov	bl, [pcount+si]
   515 00000344 D0E3                    	shl	bl, 1
   516 00000346 D0E3                    	shl	bl, 1
   517 00000348 3B97[AA43]              	cmp	dx, [bx+bLBA+2]
   518 0000034C 7212                    	jb	short R_14n1
   519 0000034E 745C                    	je	short R_14n0
   520 00000350 8B97[AA43]              	mov	dx, [bx+bLBA+2]
   521                                  R_14n10:
   522 00000354 8B87[A843]              	mov	ax, [bx+bLBA]
   523 00000358 D0EB                    	shr	bl, 1
   524 0000035A D0EB                    	shr	bl, 1
   525 0000035C 889D[0944]              	mov	[psort+di], bl
   526                                  R_14n1:
   527 00000360 FEC9                    	dec	cl
   528 00000362 746C                    	jz	short R_14p ; 2 partitions
   529                                  	; 3 or 4 partitions
   530 00000364 46                      	inc	si
   531 00000365 8A9C[0444]              	mov	bl, [pcount+si]
   532 00000369 D0E3                    	shl	bl, 1
   533 0000036B D0E3                    	shl	bl, 1
   534 0000036D 3B97[AA43]              	cmp	dx, [bx+bLBA+2]
   535 00000371 7212                    	jb	short R_14n11
   536 00000373 7443                    	je	short R_14n00
   537 00000375 8B97[AA43]              	mov	dx, [bx+bLBA+2]
   538                                  R_14n12:
   539 00000379 8B87[A843]              	mov	ax, [bx+bLBA]
   540 0000037D D0EB                    	shr	bl, 1
   541 0000037F D0EB                    	shr	bl, 1
   542 00000381 889D[0944]              	mov	[psort+di], bl
   543                                  R_14n11:
   544 00000385 FEC9                    	dec	cl
   545 00000387 74FC                    	jz	short R_14n11 ; 3 partitions
   546                                  	; 4 partitions
   547 00000389 46                      	inc	si
   548 0000038A 8A9C[0444]              	mov	bl, [pcount+si]
   549 0000038E D0E3                    	shl	bl, 1
   550 00000390 D0E3                    	shl	bl, 1
   551 00000392 3B97[AA43]              	cmp	dx, [bx+bLBA+2]
   552 00000396 7238                    	jb	short R_14p
   553 00000398 742A                    	je	short R_14n000
   554 0000039A 8B97[AA43]              	mov	dx, [bx+bLBA+2]
   555                                  R_14n22:
   556 0000039E 8B87[A843]              	mov	ax, [bx+bLBA]
   557 000003A2 D0EB                    	shr	bl, 1
   558 000003A4 D0EB                    	shr	bl, 1
   559 000003A6 889D[0944]              	mov	[psort+di], bl ; the first partition in order
   560 000003AA EB24                    	jmp	short R_14p ; check for [psort+1]
   561                                  
   562                                  R_14n0:
   563 000003AC 3B87[A843]              	cmp	ax, [bx+bLBA]
   564 000003B0 0F840002                	je	R_19 ; same LBA value ! Overlap !
   565 000003B4 779E                    	ja	short R_14n10
   566 000003B6 EBA8                    	jmp	short R_14n1
   567                                  
   568                                  R_14n00:
   569 000003B8 3B87[A843]              	cmp	ax, [bx+bLBA]
   570 000003BC 0F84F401                	je	R_19 ; same LBA value ! Overlap !
   571 000003C0 77B7                    	ja	short R_14n12
   572 000003C2 EBC1                    	jmp	short R_14n11
   573                                  
   574                                  R_14n000:
   575 000003C4 3B87[A843]              	cmp	ax, [bx+bLBA]
   576 000003C8 0F84E801                	je	R_19 ; same LBA value ! Overlap !
   577 000003CC 77AB                    	ja	short R_14n12
   578 000003CE EB00                    	jmp	short R_14p
   579                                  
   580                                  R_14p:
   581                                  	; remove the sorted partition from next calculation
   582 000003D0 8A0E[0444]              	mov	cl, [pcount]
   583 000003D4 31F6                    	xor	si, si	
   584                                  R_14p1:
   585 000003D6 46                      	inc	si
   586 000003D7 8A9C[0444]              	mov	bl, [pcount+si]
   587 000003DB 3A9D[0944]              	cmp	bl, [psort+di]
   588 000003DF 7514                    	jne	short R_14p2
   589                                  R_14p11:
   590                                  	; move 1 order back
   591 000003E1 46                      	inc	si
   592 000003E2 8A9C[0444]              	mov	bl, [si+pcount]
   593 000003E6 889C[0344]              	mov	[si+pcount-1], bl
   594 000003EA FEC9                    	dec	cl
   595 000003EC 75F3                    	jnz	short R_14p11
   596 000003EE FE0E[0444]              	dec	byte [pcount] ; remain count (non-sorted)
   597 000003F2 E91EFF                  	jmp	R_14r ; repeat	
   598                                  R_14p2:	
   599 000003F5 FEC9                    	dec	cl
   600 000003F7 EBDD                    	jmp	short R_14p1
   601                                  	
   602                                  R_14q:	
   603                                  	; Partition sort (pcount -> psort) is OK here !
   604                                  	;
   605                                  	; Check for ending LBA
   606 000003F9 8A0E[0944]              	mov	cl, [psort]
   607 000003FD 80F901                  	cmp	cl, 1
   608 00000400 7646                    	jna	short R_14z
   609 00000402 FEC9                    	dec	cl
   610                                  	;xor	bh, bh
   611 00000404 BE0100                  	mov	si, 1
   612 00000407 8A9C[0944]              	mov	bl, [psort+si] ; p1,p2,p3
   613 0000040B D0E3                    	shl	bl, 1
   614 0000040D D0E3                    	shl	bl, 1
   615                                  R_14t:
   616 0000040F 8B87[B843]              	mov	ax, [bx+eLBA]
   617 00000413 8B97[BA43]              	mov	dx, [bx+eLBA+2]
   618 00000417 46                      	inc	si
   619 00000418 8A9C[0944]              	mov	bl, [psort+si] ; p2,p3,p4
   620 0000041C D0E3                    	shl	bl, 1
   621 0000041E D0E3                    	shl	bl, 1
   622 00000420 3B97[AA43]              	cmp	dx, [bx+bLBA+2]
   623 00000424 0F878C01                	ja	R_19 ; overlap ! start2 < end1
   624 00000428 7208                    	jb	short R_14u
   625 0000042A 3B87[A843]              	cmp	ax, [bx+bLBA]
   626 0000042E 0F878201                	ja	R_19 ; overlap ! start2 < end1
   627                                  R_14u:
   628 00000432 3B97[BA43]              	cmp	dx, [bx+eLBA+2]
   629 00000436 0F877A01                	ja	R_19 ; overlap ! end2 <= end1
   630 0000043A 72F6                    	jb	short R_14u
   631 0000043C 3B87[B843]              	cmp	ax, [bx+eLBA]
   632 00000440 0F837001                	jnb	R_19 ; overlap ! end2 <= end1
   633                                  R_14y:
   634 00000444 FEC9                    	dec	cl
   635 00000446 75C7                    	jnz	short R_14t
   636                                  R_14z:
   637                                  	; All partitions (and CHS values) are valid (here)...
   638                                  	; 
   639                                  	; Calculating gaps (freespace) between partitions
   640                                  
   641                                  	;gap1: 1-part1b
   642                                  	;gap2: part1e-part2b
   643                                  	;gap3: part2e-part3b
   644                                  	;gap4: part3e-part4b
   645                                  	;gap5: part(4)e-end_of_disk 
   646                                  
   647 00000448 8A0E[0944]              	mov	cl, [psort]
   648                                  
   649 0000044C 66C706[C843]010000-     	mov	dword [gap1begin], 1
   649 00000454 00                 
   650                                  
   651 00000455 20C9                    	and	cl, cl
   652 00000457 751E                    	jnz	short R_14z1
   653                                  
   654                                  	; empty pt
   655 00000459 A1[8043]                	mov	ax, [total_sectors]
   656 0000045C 8B16[8243]              	mov	dx, [total_sectors+2]
   657 00000460 A3[DC43]                	mov	[gap1end], ax
   658 00000463 8916[DE43]              	mov	[gap1end+2], dx
   659 00000467 83E801                  	sub	ax, 1
   660 0000046A 83DA00                  	sbb	dx, 0
   661 0000046D A3[F043]                	mov	[gap1size], ax
   662 00000470 8916[F243]              	mov	[gap1size+2], dx 
   663 00000474 E9ED00                  	jmp	PT_1
   664                                  
   665                                  R_14z1:
   666 00000477 8A1E[0A44]              	mov	bl, [psort+1]
   667 0000047B 8B87[A843]              	mov	ax, [bx+bLBA]
   668 0000047F 8B97[AA43]              	mov	dx, [bx+bLBA+2]
   669 00000483 A3[DC43]                	mov	[gap1end], ax
   670 00000486 8916[DE43]              	mov	[gap1end+2], dx
   671 0000048A 83E801                  	sub	ax, 1
   672 0000048D 83DA00                  	sbb	dx, 0
   673 00000490 A3[F043]                	mov	[gap1size], ax
   674 00000493 8916[F243]              	mov	[gap1size+2], dx 
   675 00000497 FEC9                    	dec	cl
   676 00000499 0F849B00                	jz	PT_0
   677                                  
   678 0000049D 8B87[B843]              	mov	ax, [bx+eLBA]
   679 000004A1 8B97[BA43]              	mov	dx, [bx+eLBA+2]
   680 000004A5 A3[CC43]                	mov	[gap2begin], ax
   681 000004A8 8916[CE43]              	mov	[gap2begin+2], dx
   682 000004AC 8A1E[0B44]              	mov	bl, [psort+2]
   683 000004B0 8B87[A843]              	mov	ax, [bx+bLBA]
   684 000004B4 8B97[AA43]              	mov	dx, [bx+bLBA+2]
   685 000004B8 A3[E043]                	mov	[gap2end], ax
   686 000004BB 8916[E243]              	mov	[gap2end+2], dx
   687 000004BF 2B06[CC43]              	sub	ax, [gap2begin]
   688 000004C3 1B16[CE43]              	sbb	dx, [gap2begin+2]
   689 000004C7 A3[F443]                	mov	[gap2size], ax
   690 000004CA 8916[F643]              	mov	[gap2size+2], dx 	
   691 000004CE FEC9                    	dec	cl
   692 000004D0 7466                    	jz	short PT_0
   693                                  
   694 000004D2 8B87[B843]              	mov	ax, [bx+eLBA]
   695 000004D6 8B97[BA43]              	mov	dx, [bx+eLBA+2]
   696 000004DA A3[D043]                	mov	[gap3begin], ax
   697 000004DD 8916[D243]              	mov	[gap3begin+2], dx
   698 000004E1 8A1E[0C44]              	mov	bl, [psort+3]
   699 000004E5 8B87[A843]              	mov	ax, [bx+bLBA]
   700 000004E9 8B97[AA43]              	mov	dx, [bx+bLBA+2]
   701 000004ED A3[E443]                	mov	[gap3end], ax
   702 000004F0 8916[E643]              	mov	[gap3end+2], dx
   703 000004F4 2B06[D043]              	sub	ax, [gap3begin]
   704 000004F8 1B16[D243]              	sbb	dx, [gap3begin+2]
   705 000004FC A3[F843]                	mov	[gap3size], ax
   706 000004FF 8916[FA43]              	mov	[gap3size+2], dx 	
   707 00000503 FEC9                    	dec	cl
   708 00000505 7431                    	jz	short PT_0
   709                                  
   710 00000507 8B87[B843]              	mov	ax, [bx+eLBA]
   711 0000050B 8B97[BA43]              	mov	dx, [bx+eLBA+2]
   712 0000050F A3[D443]                	mov	[gap4begin], ax
   713 00000512 8916[D643]              	mov	[gap4begin+2], dx
   714 00000516 8A1E[0D44]              	mov	bl, [psort+4]
   715 0000051A 8B87[A843]              	mov	ax, [bx+bLBA]
   716 0000051E 8B97[AA43]              	mov	dx, [bx+bLBA+2]
   717 00000522 A3[E843]                	mov	[gap4end], ax
   718 00000525 8916[EA43]              	mov	[gap4end+2], dx
   719 00000529 2B06[D443]              	sub	ax, [gap4begin]
   720 0000052D 1B16[D643]              	sbb	dx, [gap4begin+2]
   721 00000531 A3[FC43]                	mov	[gap4size], ax
   722 00000534 8916[FE43]              	mov	[gap4size+2], dx 
   723                                  
   724                                  PT_0:
   725 00000538 8B87[B843]              	mov	ax, [bx+eLBA]
   726 0000053C 8B97[BA43]              	mov	dx, [bx+eLBA+2]
   727 00000540 A3[D843]                	mov	[gap5begin], ax
   728 00000543 8916[DA43]              	mov	[gap5begin+2], dx
   729 00000547 A1[8043]                	mov	ax, [total_sectors]
   730 0000054A 8B16[8243]              	mov	dx, [total_sectors+2]
   731 0000054E A3[EC43]                	mov	[gap5end], ax
   732 00000551 8916[EE43]              	mov	[gap5end+2], dx
   733 00000555 2B06[D843]              	sub	ax, [gap5begin]
   734 00000559 1B16[DA43]              	sbb	dx, [gap5begin+2]
   735 0000055D A3[0044]                	mov	[gap5size], ax
   736 00000560 8916[0244]              	mov	[gap5size+2], dx 	
   737                                  
   738                                  PT_1:
   739                                  
   740                                  
   741                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   742                                  ; Overwrite question
   743                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   744                                  
   745 00000564 BE[C23E]                	mov	si, msg_overwrite_question1
   746 00000567 E87814                  	call	print_msg
   747 0000056A BE9E00                  	mov	si, DTA_FileName
   748 0000056D E87214                  	call	print_msg
   749 00000570 BE[DF3E]                	mov	si, msg_overwrite_question2
   750 00000573 E86C14                  	call	print_msg
   751 00000576 BE[0B3F]                	mov	si, msg_yes_no
   752 00000579 E86614                  	call	print_msg
   753                                  
   754                                  	; get answer
   755                                  R_15:
   756 0000057C 31C0                    	xor	ax, ax
   757 0000057E CD16                    	int	16h			; wait for keyboard command
   758 00000580 3C03                    	cmp	al, 'C'-40h
   759 00000582 7414                    	je	short R_16 ; Exit                   
   760 00000584 3C1B                    	cmp	al, 27
   761 00000586 7410                    	je	short R_16 ; Exit
   762 00000588 24DF                    	and	al, 0DFh
   763 0000058A 3C59                    	cmp	al, 'Y'			; Yes?
   764 0000058C 741D                    	je	short R_18		; write
   765 0000058E 3C4E                    	cmp	al, 'N'			; No?
   766 00000590 75EA                    	jne	short R_15      
   767                                  					; no write (exit)  
   768 00000592 BE[6A40]                	mov	si, Msg_NO
   769 00000595 E84A14                  	call	print_msg 
   770                                  
   771                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   772                                  ; Nextline & Exit
   773                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   774                                  
   775                                  R_16:
   776 00000598 BE[6240]                	mov	si, CRLF
   777 0000059B E84414                  	call	print_msg
   778 0000059E B8004C                  	mov	ax, 4C00h		; terminate
   779 000005A1 CD21                    	int	21h
   780                                  
   781                                  R_17:
   782 000005A3 BE[E634]                	mov	si, TrDOS_Welcome
   783 000005A6 E83914                  	call	print_msg
   784 000005A9 EBED                    	jmp	short R_16 ; Exit
   785                                  
   786                                  R_18:
   787 000005AB BE[6540]                	mov	si, Msg_YES
   788 000005AE E83114                  	call	print_msg
   789 000005B1 E9FD12                  	jmp	_R_21
   790                                  
   791                                  R_19:
   792 000005B4 BE[9D35]                	mov	si, msg_inv_image_file
   793 000005B7 E9C2FA                  	jmp	R_12
   794                                  
   795                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   796                                  ; Set disk size before creating hd image file
   797                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   798                                  
   799                                  R_20:
   800 000005BA E86D15                  	call	write_chs_table
   801                                  R_20i:
   802 000005BD 30E4                    	xor	ah, ah
   803 000005BF CD16                    	int	16h
   804 000005C1 3C61                    	cmp	al, 'a'
   805 000005C3 7206                    	jb	short R_20j
   806 000005C5 3C7A                    	cmp	al, 'z'
   807 000005C7 7702                    	ja	short R_20j	
   808 000005C9 24DF                    	and	al, 0DFh
   809                                  R_20j:
   810 000005CB 3C43                    	cmp	al, 'C'
   811 000005CD 752C                    	jne	short R_20b
   812                                  R_20a:
   813 000005CF 833E[E630]00            	cmp	word [cylinders], 0
   814 000005D4 7706                    	ja	short R_20a1
   815 000005D6 C706[E630]0004          	mov	word [cylinders], 1024
   816                                  R_20a1:
   817 000005DC 833E[E430]00            	cmp	word [heads], 0
   818 000005E1 7706                    	ja	short R_20a2
   819 000005E3 C706[E430]1000          	mov	word [heads], 16
   820                                  R_20a2:
   821 000005E9 833E[E230]00            	cmp	word [sectors], 0
   822 000005EE 7706                    	ja	short R_20a3
   823 000005F0 C706[E230]3F00          	mov	word [sectors], 63
   824                                  R_20a3:
   825 000005F6 A2[1F44]                	mov	byte [chs_focus], al
   826 000005F9 EBBF                    	jmp	short R_20
   827                                  R_20b:
   828 000005FB 3C48                    	cmp	al, 'H'
   829 000005FD 74D0                    	je	short R_20a
   830 000005FF 3C53                    	cmp	al, 'S'
   831 00000601 74CC                    	je	short R_20a
   832 00000603 3C1B                    	cmp	al, 27 ; ESC key
   833 00000605 0F84AB00                	je	R_20c	
   834 00000609 3C0D                    	cmp	al, 13 ; ENTER key
   835 0000060B 0F850D01                	jne	R_20d
   836                                  
   837 0000060F 833E[E230]3F            	cmp	word [sectors], 63
   838 00000614 730D                    	jnb	short R_20b0
   839 00000616 833E[E430]10            	cmp	word [heads], 16
   840 0000061B 7606                    	jna	short R_20b0
   841 0000061D C706[E430]1000          	mov	word [heads], 16
   842                                  R_20b0:
   843 00000623 A1[E230]                	mov	ax, [sectors]
   844 00000626 8B16[E430]              	mov	dx, [heads]
   845 0000062A F7E2                    	mul	dx
   846 0000062C 8B16[E630]              	mov	dx, [cylinders]
   847 00000630 F7E2                    	mul	dx
   848 00000632 A3[8043]                	mov	[total_sectors], ax
   849 00000635 8916[8243]              	mov	[total_sectors+2], dx
   850                                  
   851 00000639 89E5                    	mov	bp, sp
   852 0000063B B90A00                  	mov	cx, 10
   853                                  R_20b1:
   854 0000063E E83502                  	call	div32
   855 00000641 53                      	push	bx
   856 00000642 89C3                    	mov	bx, ax
   857 00000644 09D3                    	or	bx, dx
   858 00000646 75F6                    	jnz	short R_20b1
   859                                  	;xor	ax, ax
   860 00000648 BF[9740]                	mov	di, str_disk_sectors
   861 0000064B 89FE                    	mov	si, di
   862 0000064D B90700                  	mov	cx, 7
   863 00000650 F3AA                     	rep	stosb ; clear disk sectors string
   864 00000652 89F7                    	mov	di, si
   865                                  	; remove leading zero (if num of digits > 1)
   866 00000654 89E9                    	mov	cx, bp
   867 00000656 29E1                    	sub	cx, sp
   868 00000658 C0E902                  	shr	cl, 2  ; 2 -> 0, 4 -> 1 ...
   869 0000065B 5B                      	pop	bx
   870 0000065C 20C9                    	and	cl, cl
   871 0000065E 7405                    	jz	short R_20b3
   872 00000660 08DB                    	or	bl, bl
   873 00000662 7501                    	jnz	short R_20b3
   874                                  R_20b2:	
   875 00000664 5B                      	pop	bx
   876                                  R_20b3:
   877 00000665 88D8                    	mov	al, bl
   878 00000667 0430                    	add	al, '0'
   879 00000669 AA                      	stosb
   880 0000066A 39E5                    	cmp	bp, sp
   881 0000066C 75F6                    	jne	short R_20b2
   882                                  
   883 0000066E A1[8043]                	mov	ax, [total_sectors]
   884 00000671 8B16[8243]              	mov	dx, [total_sectors+2]
   885 00000675 B90002                  	mov	cx, 512
   886 00000678 E80902                  	call	mul32
   887 0000067B A3[1044]                	mov	[file_size], ax
   888 0000067E 8916[1244]              	mov	[file_size+2], dx
   889                                  	
   890                                  	;mov	bp, sp
   891 00000682 B90A00                  	mov	cx, 10
   892                                  R_20b4:
   893 00000685 E8EE01                  	call	div32
   894 00000688 53                      	push	bx
   895 00000689 89C3                    	mov	bx, ax
   896 0000068B 09D3                    	or	bx, dx
   897 0000068D 75F6                    	jnz	short R_20b4
   898                                  	;xor	ax, ax
   899 0000068F BF[B540]                	mov	di, str_file_size
   900 00000692 89FE                    	mov	si, di
   901                                  	;mov	cx, 10
   902 00000694 F3AA                     	rep	stosb ; clear disk sectors string
   903 00000696 89F7                    	mov	di, si
   904                                  	; remove leading zero (if num of digits > 1)
   905 00000698 89E9                    	mov	cx, bp
   906 0000069A 29E1                    	sub	cx, sp
   907 0000069C C0E902                  	shr	cl, 2  ; 2 -> 0, 4 -> 1 ...
   908 0000069F 5B                      	pop	bx
   909 000006A0 20C9                    	and	cl, cl
   910 000006A2 7405                    	jz	short R_20b6
   911 000006A4 08DB                    	or	bl, bl
   912 000006A6 7501                    	jnz	short R_20b6
   913                                  R_20b5:	
   914 000006A8 5B                      	pop	bx
   915                                  R_20b6:
   916 000006A9 88D8                    	mov	al, bl
   917 000006AB 0430                    	add	al, '0'
   918 000006AD AA                      	stosb
   919 000006AE 39E5                    	cmp	bp, sp
   920 000006B0 75F6                    	jne	short R_20b5
   921                                  
   922 000006B2 B00D                    	mov	al, 13 ; ENTER (Carriage Return) key	
   923                                  
   924                                  R_20c:
   925 000006B4 50                      	push	ax
   926                                  
   927 000006B5 C606[1F44]00            	mov	byte [chs_focus], 0
   928 000006BA E86D14                  	call	write_chs_table
   929                                  
   930 000006BD 58                      	pop	ax
   931                                  
   932 000006BE 3C0D                    	cmp	al, 13 ; CR ?
   933 000006C0 7402                    	je	short R_20c1 ; print total sectors and file size..
   934                                  
   935                                  R_20c0:
   936 000006C2 CD20                    	int	20h
   937                                  R_20c1:
   938 000006C4 BE[8140]                	mov	si, msg_disk_sectors
   939 000006C7 E81813                  	call	print_msg
   940 000006CA BE[9740]                	mov	si, str_disk_sectors
   941 000006CD E81213                  	call	print_msg
   942 000006D0 BE[6240]                	mov	si, CRLF
   943 000006D3 E80C13                  	call	print_msg
   944 000006D6 BE[9F40]                	mov	si, msg_file_size
   945 000006D9 E80613                  	call	print_msg
   946 000006DC BE[B540]                	mov	si, str_file_size
   947 000006DF E80013                  	call	print_msg
   948 000006E2 BE[C040]                	mov	si, msg_bytes
   949 000006E5 E8FA12                  	call	print_msg
   950 000006E8 BE[C940]                	mov	si, msg_enter_cancel
   951 000006EB E8F412                  	call	print_msg
   952 000006EE 30E4                    	xor	ah, ah
   953 000006F0 CD16                    	int	16h
   954 000006F2 3C1B                    	cmp	al, 1Bh ; ESC key
   955 000006F4 74CC                    	je	short R_20c0
   956 000006F6 3C0D                    	cmp	al, 0Dh ; Enter key
   957 000006F8 0F85BEFE                	jne	R_20
   958                                  
   959 000006FC 833E[8243]00            	cmp	word [total_sectors+2], 0
   960 00000701 0F879301                	ja	R_20k
   961                                  
   962 00000705 813E[8043]003F          	cmp	word [total_sectors], 16128  ; 63*16*16
   963 0000070B 0F838901                	jnb	R_20k
   964                                  
   965 0000070F BE[F735]                	mov	si, msg_min_8mb_disk 
   966 00000712 E8CD12                  	call	print_msg
   967                                  
   968 00000715 30E4                    	xor	ah, ah
   969 00000717 CD16                    	int	16h
   970                                  
   971 00000719 E99EFE                  	jmp	R_20
   972                                  	
   973                                  R_20d:
   974 0000071C 3C20                    	cmp	al, 20h
   975 0000071E 7458                    	je	short R_20e
   976 00000720 3C2D                    	cmp	al, '-'
   977 00000722 0F84E000                	je	R_20h
   978 00000726 3C2B                    	cmp	al, '+'
   979 00000728 744E                    	je	short R_20e
   980 0000072A 80FC51                  	cmp	ah, 51h ; Pg Down
   981 0000072D 7416                    	je	short R_20d1
   982 0000072F 80FC49                  	cmp	ah, 49h ; Pg Up
   983 00000732 742D                    	je	short R_20d2  
   984                                  R_20d0:
   985 00000734 803E[1F44]00            	cmp	byte [chs_focus], 0
   986 00000739 0F8680FE                	jna	R_20i
   987 0000073D C606[1F44]00            	mov	byte [chs_focus], 0
   988 00000742 E975FE                  	jmp	R_20
   989                                  R_20d1:
   990 00000745 803E[1F44]43            	cmp	byte [chs_focus], 'C'
   991 0000074A 75E8                    	jne	short R_20d0
   992 0000074C 832E[E630]10            	sub	word [cylinders], 16
   993 00000751 0F82C500                	jc	R_20d4
   994 00000755 833E[E630]10            	cmp	word [cylinders], 16
   995 0000075A 0F82BC00                	jb	R_20d4
   996 0000075E E959FE                  	jmp	R_20
   997                                  R_20d2:
   998 00000761 803E[1F44]43            	cmp	byte [chs_focus], 'C'
   999 00000766 75CC                    	jne	short R_20d0
  1000 00000768 8306[E630]10            	add	word [cylinders], 16
  1001 0000076D 813E[E630]0004          	cmp	word [cylinders], 1024
  1002 00000773 7718                    	ja	short R_20d3
  1003 00000775 E942FE                  	jmp	R_20
  1004                                  R_20e:
  1005 00000778 803E[1F44]43            	cmp	byte [chs_focus], 'C'
  1006 0000077D 7517                    	jne	short R_20f
  1007 0000077F FF06[E630]              	inc	word [cylinders]
  1008 00000783 813E[E630]0004          	cmp	word [cylinders], 1024
  1009 00000789 0F862DFE                	jna	R_20
  1010                                  R_20d3:
  1011 0000078D C706[E630]1000          	mov	word [cylinders], 16 ; minimum cylinders
  1012 00000793 E924FE                  	jmp	R_20	
  1013                                  R_20f:
  1014 00000796 803E[1F44]48            	cmp	byte [chs_focus], 'H'
  1015 0000079B 7547                    	jne	short R_20g
  1016 0000079D 833E[E430]10            	cmp	word [heads], 16
  1017 000007A2 7307                    	jnb	short R_20f1
  1018 000007A4 FF06[E430]              	inc	word [heads]
  1019 000007A8 E90FFE                  	jmp	R_20
  1020                                  R_20f1:
  1021 000007AB 833E[E230]3F            	cmp	word [sectors], 63
  1022 000007B0 7212                    	jb	short R_20f11
  1023 000007B2 833E[E430]20            	cmp	word [heads], 32
  1024 000007B7 7722                    	ja	short R_20f3
  1025 000007B9 7217                    	jb	short R_20f2
  1026 000007BB C706[E430]4000          	mov	word [heads], 64
  1027 000007C1 E9F6FD                  	jmp	R_20
  1028                                  R_20f11:
  1029 000007C4 833E[E430]10            	cmp	word [heads], 16
  1030 000007C9 7310                    	jnb	short R_20f3
  1031 000007CB FF06[E430]              	inc	word [heads]
  1032 000007CF E9E8FD                  	jmp	R_20
  1033                                  R_20f2:
  1034 000007D2 C706[E430]2000          	mov	word [heads], 32
  1035 000007D8 E9DFFD                  	jmp	R_20
  1036                                  R_20f3:
  1037 000007DB C706[E430]0200          	mov	word [heads], 2
  1038 000007E1 E9D6FD                  	jmp	R_20
  1039                                  R_20g:
  1040 000007E4 803E[1F44]53            	cmp	byte [chs_focus], 'S'
  1041 000007E9 0F85CDFD                	jne	R_20
  1042 000007ED 833E[E230]3F            	cmp	word [sectors], 63
  1043 000007F2 7509                    	jne	short R_20g1
  1044 000007F4 C706[E230]1100          	mov	word [sectors], 17
  1045 000007FA E9BDFD                  	jmp	R_20
  1046                                  R_20g1:
  1047 000007FD C706[E230]3F00          	mov	word [sectors], 63
  1048 00000803 E9B4FD                  	jmp	R_20
  1049                                  R_20h:
  1050 00000806 803E[1F44]43            	cmp	byte [chs_focus], 'C'
  1051 0000080B 7516                    	jne	short R_20h0
  1052 0000080D FF0E[E630]              	dec	word [cylinders]
  1053 00000811 833E[E630]10            	cmp	word [cylinders], 16
  1054 00000816 0F83A0FD                	jnb	R_20
  1055                                  R_20d4:
  1056 0000081A C706[E630]0004          	mov	word [cylinders], 1024
  1057 00000820 E997FD                  	jmp	R_20	
  1058                                  R_20h0:
  1059 00000823 803E[1F44]48            	cmp	byte [chs_focus], 'H'
  1060 00000828 75BA                    	jne	short R_20g
  1061                                  
  1062 0000082A 833E[E230]3F            	cmp	word [sectors], 63
  1063 0000082F 721E                    	jb	short R_20h11
  1064                                  
  1065 00000831 833E[E430]02            	cmp	word [heads], 2
  1066 00000836 760E                    	jna	short R_20h1
  1067 00000838 833E[E430]10            	cmp	word [heads], 16
  1068 0000083D 771E                    	ja	short R_20h2
  1069 0000083F FF0E[E430]              	dec	word [heads]
  1070 00000843 E974FD                  	jmp	R_20
  1071                                  R_20h1:
  1072 00000846 C706[E430]4000          	mov	word [heads], 64
  1073 0000084C E96BFD                  	jmp	R_20
  1074                                  R_20h11:
  1075 0000084F 833E[E430]02            	cmp	word [heads], 2
  1076 00000854 760E                    	jna	short R_20h22
  1077 00000856 FF0E[E430]              	dec	word [heads]
  1078 0000085A E95DFD                  	jmp	R_20
  1079                                  R_20h2:
  1080 0000085D 833E[E430]20            	cmp	word [heads], 32
  1081 00000862 7709                    	ja	short R_20h3
  1082                                  R_20h22:
  1083 00000864 C706[E430]1000          	mov	word [heads], 16
  1084 0000086A E94DFD                  	jmp	R_20
  1085                                  R_20h3:
  1086 0000086D C706[E430]2000          	mov	word [heads], 32
  1087 00000873 E944FD                  	jmp	R_20
  1088                                  
  1089                                  div32:
  1090                                  	; DX_AX/CX
  1091                                  	; Result: DX_AX, BX (remainder) 
  1092 00000876 89C3                    	mov	bx, ax
  1093                                  	;or	dx, ax ; * DX_AX = 0 ?       
  1094                                  	;jz	short div32_retn ; yes, do not divide! 
  1095 00000878 89D0                    	mov	ax, dx
  1096 0000087A 31D2                            xor	dx, dx
  1097 0000087C F7F1                            div	cx	; at first, divide DX
  1098                                  			; remainder is in DX 
  1099 0000087E 93                      	xchg	ax, bx	; now quotient is in BX
  1100                                    			; and initial DX value is in AX
  1101 0000087F F7F1                    	div	cx	; now, DX_AX has been divided anbhbd
  1102                                  			; AX has quotient
  1103                                  			; DX has remainder
  1104 00000881 87D3                    	xchg	dx, bx	; finally, BX has remainder
  1105                                  ;div32_retn:
  1106 00000883 C3                              retn
  1107                                  
  1108                                  mul32:
  1109                                  	; DX_AX*CX
  1110                                  	; Result: BX_DX_AX 
  1111 00000884 51                      	push	cx
  1112 00000885 89D3                    	mov	bx, dx
  1113 00000887 F7E1                    	mul	cx
  1114 00000889 93                       	xchg	ax, bx
  1115 0000088A 52                      	push	dx
  1116 0000088B F7E1                    	mul	cx 
  1117 0000088D 59                      	pop	cx 
  1118 0000088E 01C8                    	add	ax, cx 
  1119 00000890 83D200                  	adc	dx, 0
  1120 00000893 93                      	xchg	bx, ax
  1121 00000894 87D3                    	xchg	dx, bx
  1122 00000896 59                      	pop	cx
  1123 00000897 C3                      	retn
  1124                                  
  1125                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1126                                  ; Create a new hard disk image file
  1127                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1128                                  		
  1129                                  R_20k:
  1130 00000898 BA[7243]                	mov	dx, img_file_name
  1131 0000089B B90000                  	mov	cx, 0 ; File Attributes
  1132 0000089E B43C                    	mov	ah, 3Ch ; MS-DOS Function = Create File
  1133 000008A0 CD21                    	int	21h
  1134 000008A2 0F82D3F7                	jc	R_11
  1135                                  
  1136 000008A6 BE[6240]                	mov	si, CRLF
  1137 000008A9 E83611                  	call	print_msg
  1138                                  
  1139                                  
  1140                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1141                                  ; Open image file for writing
  1142                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1143                                  
  1144 000008AC B002                    	mov	al, 2 ; open for reading and writing
  1145                                  	;mov	dx, img_file_name
  1146 000008AE B43D                    	mov	ah, 3Dh ; open file
  1147 000008B0 CD21                    	int	21h
  1148 000008B2 0F820911                	jc	R_29
  1149                                  
  1150 000008B6 A3[E030]                	mov	[img_file_handle], ax
  1151                                  
  1152 000008B9 BE[163F]                	mov	si, msg_writing_mbr
  1153 000008BC E82311                  	call	print_msg
  1154                                  
  1155                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1156                                  ; Writing/Saving CHS parameters into (Singlix FS1) MBR
  1157                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1158                                  ; Note: Partition Table will be left empty at this stage
  1159                                  
  1160                                  	;cmp	word [TRDOS386_MASTERBOOT_SECTOR+417], 417
  1161                                  	;jne	short R_20m
  1162                                  
  1163 000008BF 8B0E[E630]              	mov	cx, [cylinders]
  1164 000008C3 890E[7222]              	mov	[TRDOS386_MASTERBOOT_SECTOR+420], cx ; pt_cylinders
  1165 000008C7 8B0E[E430]              	mov	cx, [heads]
  1166 000008CB 890E[7422]              	mov	[TRDOS386_MASTERBOOT_SECTOR+422], cx ; pt_heads
  1167 000008CF 8B0E[E230]              	mov	cx, [sectors]
  1168 000008D3 890E[7622]              	mov	[TRDOS386_MASTERBOOT_SECTOR+424], cx ; pt_sectors	 	 
  1169                                  
  1170                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1171                                  ; writing masterboot sector
  1172                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1173                                  
  1174                                  R_20m:
  1175 000008D7 8B1E[E030]              	mov	bx, [img_file_handle]
  1176 000008DB BA[CE20]                	mov	dx, TRDOS386_MASTERBOOT_SECTOR ; Singlix FS1 MBR
  1177 000008DE B90002                  	mov	cx, 512
  1178 000008E1 B440                    	mov	ah, 40h ; write to file	
  1179 000008E3 CD21                    	int	21h
  1180 000008E5 0F82CC10                	jc	R_29x
  1181                                  
  1182 000008E9 BE[5E40]                	mov	si, Msg_OK
  1183 000008EC E8F310                  	call	print_msg
  1184                                  
  1185 000008EF BE[333F]                	mov	si, msg_writing_disk_sectors
  1186 000008F2 E8ED10                  	call	print_msg
  1187 000008F5 B403                    	mov	ah, 3
  1188 000008F7 BB0700                  	mov	bx, 7
  1189 000008FA CD10                    	int	10h ; Return Cursor Position
  1190                                  	; DL = Column, DH = Line
  1191 000008FC 8916[A63F]              	mov	[Cursor_Pos], dx
  1192                                  
  1193                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1194                                  ; writing disk sectors (with F6h -format- bytes)
  1195                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1196                                  
  1197 00000900 31D2                    	xor	dx, dx
  1198 00000902 B80100                  	mov	ax, 1
  1199                                  
  1200                                  	; 63 (17) sectors (after MBR) will be filled with ZERO 
  1201                                  R_20l1:
  1202 00000905 52                      	push	dx
  1203 00000906 50                      	push	ax
  1204 00000907 BE[A43F]                	mov	si, Sector_Str + 6
  1205 0000090A E85D11                  	call	bin_to_decimal
  1206 0000090D 8B16[A63F]              	mov	dx, [Cursor_Pos]
  1207 00000911 BB0700                  	mov	bx, 7
  1208 00000914 B402                    	mov	ah, 2
  1209 00000916 CD10                    	int	10h  ; Set Cursor Position
  1210 00000918 E8C710                  	call	print_msg
  1211 0000091B 58                      	pop	ax
  1212 0000091C 5A                      	pop	dx
  1213 0000091D BB[6248]                	mov	bx, HDFORMAT_FATBUFFER ; Empty Sector
  1214 00000920 E8CE10                  	call	write_hd_sector
  1215 00000923 0F828E10                	jc	R_29x
  1216                                  	;inc	ax
  1217 00000927 FEC0                    	inc	al
  1218 00000929 3B06[E230]              	cmp	ax, [sectors] ; 63 or 17
  1219 0000092D 76D6                    	jna	short R_20l1
  1220                                  
  1221                                  	; writing other sectors upto [total sectors] - 1 
  1222                                  R_20l2:
  1223 0000092F 52                      	push	dx
  1224 00000930 50                      	push	ax
  1225 00000931 BE[A43F]                	mov	si, Sector_Str + 6
  1226 00000934 E83311                  	call	bin_to_decimal
  1227 00000937 8B16[A63F]              	mov	dx, [Cursor_Pos]
  1228 0000093B BB0700                  	mov	bx, 7
  1229 0000093E B402                    	mov	ah, 2
  1230 00000940 CD10                    	int	10h  ; Set Cursor Position
  1231 00000942 E89D10                  	call	print_msg
  1232 00000945 58                      	pop	ax
  1233 00000946 5A                      	pop	dx
  1234 00000947 BB[6244]                	mov	bx, HDFORMAT_SECBUFFER ; F6h filled sectors
  1235 0000094A E8A410                  	call	write_hd_sector
  1236 0000094D 0F826410                	jc	R_29x
  1237 00000951 83C001                  	add	ax, 1
  1238 00000954 83D200                  	adc	dx, 0
  1239 00000957 3B16[8243]              	cmp	dx, [total_sectors+2]
  1240 0000095B 72D2                    	jb	short R_20l2
  1241 0000095D 7706                    	ja	short R_20n
  1242 0000095F 3B06[8043]              	cmp	ax, [total_sectors]
  1243 00000963 72CA                    	jb	short R_20l2
  1244                                  R_20n:
  1245 00000965 BE[5B40]                	mov	si, Msg_3dot_OK
  1246 00000968 E87710                  	call	print_msg
  1247                                  
  1248                                  
  1249 0000096B BE[5A36]                	mov	si, msg_any_key_esc_exit
  1250 0000096E E87110                  	call	print_msg
  1251                                  	
  1252 00000971 30E4                    	xor	ah, ah
  1253 00000973 CD16                    	int	16h	
  1254                                  
  1255 00000975 3C1B                    	cmp	al, 27 ; 1Bh, ESC key
  1256 00000977 7508                    	jne	short R_20t
  1257                                  
  1258                                  R_20esc:
  1259 00000979 BE[6240]                	mov	si, CRLF
  1260 0000097C E86310                  	call	print_msg
  1261                                  	
  1262 0000097F CD20                    	int	20h
  1263                                  R_20t:
  1264 00000981 FE06[E830]              	inc	byte [random] ; next r/w is not sequental 
  1265 00000985 FE06[E930]              	inc	byte [newdisk] ; will be used by partitioning
  1266                                  
  1267                                  R_20retry:
  1268                                  	; clear screen
  1269 00000989 B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
  1270 0000098C CD10                    	int	10h
  1271                                  	
  1272 0000098E BE[9236]                	mov	si, msg_create_trdos_partition_h ; header
  1273 00000991 E84E10                  	call	print_msg
  1274 00000994 BE[8737]                	mov	si, msg_create_trdos_partition_m ; menu
  1275 00000997 E84810                  	call	print_msg
  1276                                  R_20u:
  1277 0000099A 30E4                    	xor	ah, ah
  1278 0000099C CD16                    	int	16h
  1279 0000099E 3C1B                    	cmp	al, 27 ; ESC key	
  1280 000009A0 74D7                    	je	short R_20esc
  1281 000009A2 3C30                    	cmp	al, '0'
  1282 000009A4 74D3                    	je	short R_20esc
  1283 000009A6 72F2                    	jb	short R_20u
  1284 000009A8 3C35                    	cmp	al, '5'
  1285 000009AA 77EE                    	ja	short R_20u
  1286                                  
  1287 000009AC 2C30                    	sub	al, '0'
  1288 000009AE A2[1D44]                	mov	[pp_type], al
  1289                                  
  1290 000009B1 C606[1E44]00            	mov	byte [pp_type_user], 0
  1291                                  
  1292 000009B6 3C05                    	cmp	al, 5
  1293 000009B8 7516                    	jne	short R_20v
  1294                                  
  1295 000009BA E84E14                  	call	partition_type_input
  1296                                  	
  1297 000009BD 50                      	push	ax
  1298 000009BE BE[FF40]                	mov	si, msg_press_any_key 
  1299 000009C1 E81E10                  	call	print_msg
  1300 000009C4 28E4                    	sub	ah, ah
  1301 000009C6 CD16                    	int	16h
  1302 000009C8 58                      	pop	ax
  1303                                  		
  1304 000009C9 20C0                    	and	al, al
  1305 000009CB 74AC                    	jz	short R_20esc ; 0 = none or not a valid input
  1306                                  
  1307 000009CD A2[1E44]                	mov	[pp_type_user], al
  1308                                  R_20v:	
  1309                                  	; clear screen
  1310 000009D0 B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
  1311 000009D3 CD10                    	int	10h
  1312                                  
  1313 000009D5 BE[9236]                	mov	si, msg_create_trdos_partition_h ; header
  1314 000009D8 E80710                  	call	print_msg
  1315 000009DB BE[AA39]                	mov	si, msg_use_whole_disk ; partition size: whole disk
  1316 000009DE E80110                  	call	print_msg
  1317                                  R_20w:
  1318 000009E1 30E4                    	xor	ah, ah
  1319 000009E3 CD16                    	int	16h
  1320                                  
  1321 000009E5 3C1B                    	cmp	al, 27 ; ESCAPE key
  1322 000009E7 7490                    	je	short R_20esc
  1323 000009E9 24DF                    	and	al, 0DFh
  1324 000009EB 3C4E                    	cmp	al, 'N'
  1325 000009ED 7408                    	je	short R_20y
  1326 000009EF 3C59                    	cmp	al, 'Y'
  1327 000009F1 75EE                    	jne	short R_20w
  1328                                  	
  1329 000009F3 FE06[1C44]              	inc	byte [wholedisk]
  1330                                  R_20y:
  1331 000009F7 31D2                    	xor	dx, dx
  1332 000009F9 31C0                    	xor	ax, ax
  1333 000009FB BB[1E41]                	mov	bx, MasterBootBuff
  1334 000009FE E82F10                  	call	read_hd_sector
  1335 00000A01 0F82B00F                	jc	R_29x
  1336                                  
  1337 00000A05 A1[E230]                	mov	ax, [sectors]
  1338 00000A08 8B16[E430]              	mov	dx, [heads]
  1339 00000A0C F7E2                    	mul	dx
  1340 00000A0E 8B0E[E630]              	mov	cx, [cylinders]
  1341 00000A12 E86FFE                  	call	mul32
  1342 00000A15 2B06[E230]              	sub	ax, [sectors]
  1343 00000A19 83DA00                  	sbb	dx, 0
  1344 00000A1C A3[1844]                	mov	[pp_Sectors], ax   ; = [total_sectors] - [sectors]
  1345 00000A1F 8916[1A44]              	mov	[pp_Sectors+2], dx ; = [total_sectors+2] - carry bit
  1346                                  
  1347 00000A23 803E[1C44]00            	cmp	byte [wholedisk], 0
  1348 00000A28 0F87B100                	ja	R_20y3
  1349                                  
  1350                                  	; clear screen
  1351 00000A2C B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
  1352 00000A2F CD10                    	int	10h
  1353                                  
  1354 00000A31 BE[9236]                	mov	si, msg_create_trdos_partition_h ; header
  1355 00000A34 E8AB0F                  	call	print_msg
  1356 00000A37 BE[6838]                	mov	si, msg_create_trdos_partition_s ; size options
  1357 00000A3A E8A50F                  	call	print_msg	
  1358                                  R_20y0:	
  1359 00000A3D 30E4                    	xor	ah, ah
  1360 00000A3F CD16                    	int	16h
  1361                                  
  1362 00000A41 3C1B                    	cmp	al, 27 ; ESCAPE key
  1363 00000A43 7509                    	jne	short R_20y00
  1364                                  
  1365 00000A45 A1[1844]                	mov	ax, [pp_Sectors]
  1366 00000A48 8B16[1A44]              	mov	dx, [pp_Sectors+2]
  1367 00000A4C EB47                    	jmp	short R_20y11
  1368                                  R_20y00:
  1369 00000A4E C606[2A44]25            	mov	byte [pSize_unit], '%'
  1370 00000A53 3C25                    	cmp	al, '%'
  1371 00000A55 7422                    	je	short R_20y1
  1372 00000A57 C606[2A44]53            	mov	byte [pSize_unit], 'S'
  1373 00000A5C 3C0D                    	cmp	al, 13 ; 0Dh, Carriage Return key
  1374 00000A5E 7419                    	je	short R_20y1
  1375 00000A60 24DF                    	and	al, 0DFh
  1376 00000A62 3C53                    	cmp	al, 'S'
  1377 00000A64 7413                    	je	short R_20y1
  1378 00000A66 A2[2A44]                	mov	[pSize_unit], al
  1379 00000A69 3C4B                    	cmp	al, 'K'
  1380 00000A6B 740C                    	je	short R_20y1
  1381 00000A6D 3C4D                    	cmp	al, 'M'
  1382 00000A6F 7408                    	je	short R_20y1
  1383 00000A71 3C47                    	cmp	al, 'G'
  1384 00000A73 7404                    	je	short R_20y1
  1385 00000A75 3C43                    	cmp	al, 'C'
  1386 00000A77 75C4                    	jne	short R_20y0
  1387                                  R_20y1:
  1388 00000A79 C606[4044]73            	mov	byte [msg_sectors_crlf_s], 's' ; " sectors"
  1389                                  
  1390 00000A7E E89711                  	call	partition_size_input
  1391                                  
  1392 00000A81 21DB                    	and	bx, bx ; bx_dx_ax = partition size
  1393 00000A83 7558                    	jnz	R_20y3 ; invalid! (use max available sectors)
  1394                                  
  1395                                  	; write partition size
  1396 00000A85 52                      	push	dx
  1397 00000A86 50                      	push	ax
  1398 00000A87 89D1                    	mov	cx, dx
  1399 00000A89 09C1                    	or	cx, ax
  1400 00000A8B 83F901                  	cmp	cx, 1
  1401 00000A8E 7705                    	ja	short R_20y11 ; > 1 sector(s)
  1402                                  	; " sectors"
  1403 00000A90 C606[4044]20            	mov	byte [msg_sectors_crlf_s], 20h ; " sector "
  1404                                  R_20y11:
  1405 00000A95 BE[3744]                	mov	si, msg_partition_sectors + 7 ; max. 7 digits
  1406 00000A98 E8CF0F                  	call	bin_to_decimal
  1407                                  	; ds:si = beginning of decimal number text
  1408 00000A9B E8440F                  	call	print_msg
  1409 00000A9E BE[3944]                	mov	si, msg_sectors_crlf
  1410 00000AA1 E83E0F                  	call	print_msg
  1411 00000AA4 58                      	pop	ax
  1412 00000AA5 5A                      	pop	dx
  1413                                  
  1414                                  	; exit if partition size input is 0
  1415 00000AA6 89C1                    	mov	cx, ax
  1416 00000AA8 09D1                    	or	cx, dx
  1417 00000AAA 0F84CBFE                	jz	R_20esc
  1418                                  
  1419                                  	; select whole disk if partition size > disk size
  1420 00000AAE 3B16[1A44]              	cmp	dx, [pp_Sectors+2]
  1421 00000AB2 7708                    	ja	short R_20y12
  1422 00000AB4 7220                    	jb	short R_20y2
  1423 00000AB6 3B06[1844]              	cmp	ax, [pp_Sectors]
  1424 00000ABA 721E                    	jb	short R_20y21
  1425                                  R_20y12:
  1426                                  	; "use whole partition or go to back" question
  1427 00000ABC BE[623A]                	mov	si, msg_partition_size_overs
  1428 00000ABF E8200F                  	call	print_msg
  1429                                  R_20y13:
  1430 00000AC2 30E4                    	xor	ah, ah
  1431 00000AC4 CD16                    	int	16h
  1432 00000AC6 3C1B                    	cmp	al, 27 ; ESCAPE key
  1433 00000AC8 0F84BDFE                	je	R_20retry
  1434 00000ACC 3C0D                    	cmp	al, 13 ; ENTER (Carriage Return) key
  1435 00000ACE 75F2                    	jne	short R_20y13
  1436 00000AD0 FE06[1C44]              	inc	byte [wholedisk]
  1437 00000AD4 EB07                    	jmp	short R_20y3
  1438                                  R_20y2: 
  1439 00000AD6 8916[1A44]              	mov	[pp_Sectors+2], dx
  1440                                  R_20y21:
  1441 00000ADA A3[1844]                	mov	[pp_Sectors], ax
  1442                                  R_20y3:
  1443 00000ADD A1[E230]                	mov	ax, [sectors]
  1444 00000AE0 BE[DC42]                	mov	si, MasterBootBuff+pTableOffset
  1445                                  	;mov	byte [si+ptBootable], 80h ; Active partition
  1446 00000AE3 C60480                  	mov	byte [si], 80h ; Active partition
  1447 00000AE6 C6440101                	mov	byte [si+ptBeginHead], 1 ; Head 1
  1448 00000AEA C6440201                	mov	byte [si+ptBeginSector], 1
  1449 00000AEE C6440300                	mov	byte [si+ptBeginCylinder], 0
  1450                                  
  1451 00000AF2 A3[1444]                	mov	[pp_StartSector], ax
  1452 00000AF5 31D2                    	xor	dx, dx
  1453 00000AF7 8916[1644]              	mov	[pp_StartSector+2], dx
  1454                                  
  1455 00000AFB 894408                  	mov	[si+ptStartSector], ax
  1456 00000AFE 89540A                  	mov	[si+ptStartSector+2], dx
  1457                                  R_20y3i:
  1458 00000B01 0306[1844]              	add	ax, [pp_Sectors]
  1459 00000B05 1316[1A44]              	adc	dx, [pp_Sectors+2]
  1460 00000B09 7208                    	jc	short R_20y14
  1461                                  
  1462 00000B0B 3B16[8243]              	cmp	dx, [total_sectors+2]
  1463 00000B0F 7224                    	jb	short R_20y3c
  1464 00000B11 7411                    	je	short R_20y3a
  1465                                  R_20y14:
  1466 00000B13 8B16[8243]              	mov	dx, [total_sectors+2]
  1467 00000B17 8916[1A44]              	mov	[pp_Sectors+2], dx
  1468 00000B1B EB0D                    	jmp	short R_20y3b
  1469                                  R_20y3h:
  1470                                  	; [cylinder_boundary] > 0
  1471                                  	; start of partition size (over) check after
  1472                                  	; the cylinder boundary adjustment
  1473 00000B1D A1[E230]                	mov	ax, [sectors]
  1474 00000B20 29D2                    	sub	dx, dx ; 0
  1475 00000B22 EBDD                    	jmp	short R_20y3i	
  1476                                  R_20y3a:
  1477 00000B24 3B06[8043]              	cmp	ax, [total_sectors]
  1478 00000B28 760B                    	jna	short R_20y3c
  1479                                  R_20y3b:
  1480 00000B2A A1[8043]                	mov	ax, [total_sectors]
  1481 00000B2D A3[1844]                	mov	[pp_Sectors], ax
  1482 00000B30 800E[1C44]01            	or	byte [wholedisk], 1
  1483                                  R_20y3c:
  1484 00000B35 83E801                  	sub	ax, 1
  1485 00000B38 83DA00                  	sbb	dx, 0
  1486 00000B3B 8B0E[E230]              	mov	cx, [sectors]
  1487 00000B3F E834FD                  	call	div32
  1488                                  	; BX = Sector number - 1
  1489 00000B42 43                      	inc	bx ; sector number (1 based)
  1490 00000B43 885C06                  	mov	[si+ptEndSector], bl	
  1491                                  	; DX_AX = cylinders * heads + head
  1492 00000B46 8B0E[E430]              	mov	cx, [heads]
  1493 00000B4A E829FD                  	call	div32
  1494                                  	; BX = Head number
  1495 00000B4D 885C05                  	mov	[si+ptEndHead], bl
  1496                                  	; AX = Cylinder number
  1497 00000B50 25FF03                  	and	ax, 1023
  1498 00000B53 89C1                    	mov	cx, ax
  1499 00000B55 884C07                  	mov	[si+ptEndCylinder], cl
  1500 00000B58 28C9                    	sub	cl, cl
  1501 00000B5A C1E902                  	shr	cx, 2
  1502 00000B5D 084C06                  	or	[si+ptEndSector], cl
  1503                                  
  1504                                  	; Cylinder boundary check
  1505 00000B60 C606[5F44]00            	mov	byte [cylinder_boundary], 0
  1506 00000B65 803E[1C44]00            	cmp	byte [wholedisk], 0
  1507 00000B6A 0F879B00                	ja	R_20y3g
  1508 00000B6E FEC3                    	inc	bl
  1509 00000B70 3A1E[E430]              	cmp	bl, [heads]
  1510 00000B74 750E                    	jne	short R_20y3d
  1511 00000B76 8A4C06                  	mov	cl, [si+ptEndSector]
  1512 00000B79 80E13F                  	and	cl, 3Fh ; 1 to 63
  1513 00000B7C 3A0E[E230]              	cmp	cl, [sectors]
  1514 00000B80 0F848500                	je	R_20y3g 
  1515                                  	;xor	ch, ch
  1516                                  R_20y3d:
  1517 00000B84 89C7                    	mov	di, ax ; last cylinder number
  1518 00000B86 BE[CC3A]                	mov	si, msg_cylinder_boundary_set
  1519 00000B89 E8560E                  	call	print_msg
  1520                                  R_20y3d0:
  1521 00000B8C 30E4                    	xor	ah, ah
  1522 00000B8E CD16                    	int	16h
  1523                                  	; Cylinder boundary adjusting
  1524 00000B90 3C0D                    	cmp	al, 13 ; ENTER key
  1525 00000B92 74F0                    	je	short R_20y3d
  1526 00000B94 3C1B                    	cmp	al, 27 ; ESCAPE key
  1527 00000B96 7432                    	je	short R_20y3f
  1528 00000B98 24DF                    	and	al, 0DFh
  1529 00000B9A 3C4E                    	cmp	al, 'N'
  1530 00000B9C 7426                    	je	short R_20y3d3
  1531 00000B9E 3C59                    	cmp	al, 'Y'
  1532 00000BA0 75EA                    	jne	short R_20y3d0
  1533 00000BA2 BE[6540]                	mov	si, Msg_YES
  1534 00000BA5 E83A0E                  	call	print_msg
  1535                                  R_20y3d1:
  1536 00000BA8 BE[103B]                	mov	si, msg_cylinder_boundary_updown
  1537 00000BAB E8340E                  	call	print_msg
  1538                                  R_20y3d2:
  1539 00000BAE 30E4                    	xor	ah, ah
  1540 00000BB0 CD16                    	int	16h
  1541 00000BB2 3C0D                    	cmp	al, 13 ; ENTER key
  1542 00000BB4 74F2                    	je	short R_20y3d1
  1543 00000BB6 3C1B                    	cmp	al, 27 ; ESC key
  1544 00000BB8 7410                    	je	short R_20y3f
  1545 00000BBA 3C2B                    	cmp	al, '+'
  1546 00000BBC 7419                    	je	short R_20y3d5
  1547 00000BBE 3C2D                    	cmp	al, '-'
  1548 00000BC0 740F                    	je	short R_20y3d4
  1549 00000BC2 EBEA                    	jmp	short R_20y3d2
  1550                                  R_20y3d3:
  1551 00000BC4 BE[6A40]                	mov	si, Msg_NO
  1552 00000BC7 E8180E                  	call	print_msg
  1553                                  R_20y3f:
  1554 00000BCA BE[DC42]                	mov	si, MasterBootBuff+pTableOffset
  1555 00000BCD 89F8                    	mov	ax, di ; The last cylinder number
  1556 00000BCF EB38                    	jmp	short R_20y3g	
  1557                                  R_20y3d4:
  1558 00000BD1 FE0E[5F44]              	dec	byte [cylinder_boundary]
  1559 00000BD5 EB04                    	jmp	short R_20y3e
  1560                                  R_20y3d5:
  1561 00000BD7 FE06[5F44]              	inc	byte [cylinder_boundary]
  1562                                  R_20y3e:
  1563 00000BDB BE[DC42]                	mov	si, MasterBootBuff+pTableOffset
  1564 00000BDE 8A6C06                  	mov	ch, [si+ptEndSector]
  1565 00000BE1 C0ED06                  	shr	ch, 6
  1566 00000BE4 8A4C07                  	mov	cl, [si+ptEndCylinder]
  1567 00000BE7 A0[5F44]                	mov	al, [cylinder_boundary]
  1568                                  	; AL = 0FF = -1 : boundary down (prev cyl)
  1569                                  	; AL = 1 : boundary up (same cylinder)
  1570 00000BEA FEC0                    	inc	al
  1571 00000BEC 7501                    	jnz	short R_20y3e0 ; same cylinder
  1572                                  	; previous cylinder (with last head & sector)
  1573 00000BEE 49                      	dec	cx
  1574                                  R_20y3e0:
  1575 00000BEF A0[E430]                	mov	al, [heads]
  1576 00000BF2 FEC8                    	dec	al
  1577 00000BF4 884405                  	mov	[si+ptEndHead], al
  1578 00000BF7 A0[E230]                	mov	al, [sectors]
  1579 00000BFA 88EC                    	mov	ah, ch
  1580 00000BFC C0E406                  	shl	ah, 6
  1581 00000BFF 08E0                    	or	al, ah	
  1582 00000C01 884406                  	mov	[si+ptEndSector], al
  1583 00000C04 884C07                  	mov	[si+ptEndCylinder], cl
  1584 00000C07 89C8                    	mov	ax, cx 
  1585                                  	; End of cylinder boundary adjusting
  1586                                  R_20y3g:
  1587                                  	; convert CHS to LBA
  1588                                  	; AX = last cylinder number
  1589 00000C09 8B16[E430]              	mov	dx, [heads]
  1590 00000C0D F7E2                    	mul	dx
  1591 00000C0F 8B0E[E230]              	mov	cx, [sectors]
  1592 00000C13 E86EFC                  	call	mul32
  1593 00000C16 89C1                    	mov	cx, ax	
  1594 00000C18 8A6405                  	mov	ah, [si+ptEndHead]
  1595 00000C1B A0[E230]                	mov	al, [sectors]
  1596 00000C1E F6E4                    	mul	ah
  1597 00000C20 01C8                    	add	ax, cx
  1598 00000C22 83D200                  	adc	dx, 0
  1599 00000C25 8A4C06                  	mov	cl, [si+ptEndSector]
  1600 00000C28 80E13F                  	and	cl, 3Fh
  1601 00000C2B FEC9                    	dec	cl ; sector number - 1	
  1602 00000C2D 30ED                    	xor	ch, ch
  1603 00000C2F 01C8                    	add	ax, cx
  1604 00000C31 83D200                  	adc	dx, 0
  1605                                  
  1606 00000C34 2B4408                  	sub	ax, [si+ptStartSector]
  1607 00000C37 1B540A                  	sbb	dx, [si+ptStartSector+2]
  1608                                  
  1609 00000C3A 83C001                  	add	ax, 1
  1610 00000C3D 83D200                  	adc	dx, 0
  1611                                  
  1612 00000C40 89440C                  	mov	[si+ptSectors], ax
  1613 00000C43 89540E                  	mov	[si+ptSectors+2], dx
  1614                                  
  1615 00000C46 A3[1844]                	mov	[pp_Sectors], ax
  1616 00000C49 8916[1A44]              	mov	[pp_Sectors+2], dx
  1617                                  
  1618 00000C4D 803E[5F44]00            	cmp	byte [cylinder_boundary], 0
  1619 00000C52 0F87C7FE                	ja	R_20y3h
  1620                                  
  1621 00000C56 21D2                    	and	dx, dx
  1622 00000C58 7520                    	jnz	short R_20y31
  1623                                  
  1624 00000C5A 3D0010                  	cmp	ax, 4096
  1625 00000C5D 731B                    	jnb	short R_20y31
  1626                                  
  1627 00000C5F 8A0E[1E44]              	mov	cl, [pp_type_user]
  1628 00000C63 80F901                  	cmp	cl, 1 ; FAT 12
  1629 00000C66 747A                    	je	short R_20y8
  1630                                  
  1631                                  R_20y30:
  1632 00000C68 BE[093A]                	mov	si, msg_partition_type_error
  1633 00000C6B E8740D                  	call	print_msg
  1634 00000C6E 30E4                    	xor	ah, ah
  1635 00000C70 CD16                    	int	16h
  1636 00000C72 C606[1C44]00            	mov	byte [wholedisk], 0
  1637 00000C77 E90FFD                  	jmp	R_20retry
  1638                                  
  1639                                  R_20y31:
  1640 00000C7A 803E[1D44]01            	cmp	byte [pp_type], 1 ; FAT16
  1641 00000C7F 751F                    	jne	short R_20y4
  1642                                  
  1643                                  	; FAT 16 partition
  1644 00000C81 B104                    	mov	cl, 4  ; FAT 16 (<= 32MB)
  1645 00000C83 21D2                    	and	dx, dx ; > 32 MB	
  1646                                  	;jz	short R_20y8  ; no
  1647 00000C85 7507                    	jnz	short R_20y31x
  1648                                  	; Min. 8400+1 sectors is required
  1649                                  	; (according to MS FAT32 FS specification)
  1650 00000C87 3DD020                  	cmp	ax, 8400
  1651 00000C8A 76DC                    	jna	short R_20y30 ; invalid! (< 4.1MB)
  1652 00000C8C EB54                    	jmp	short R_20y8	
  1653                                  R_20y31x:
  1654 00000C8E B106                    	mov	cl, 6 ; Big FAT 16 (> 32MB)
  1655 00000C90 83FA0F                  	cmp	dx, 0Fh
  1656 00000C93 724D                    	jb	short R_20y8
  1657 00000C95 7705                    	ja	short R_20y32
  1658 00000C97 3D00C0                  	cmp	ax, 0C000h
  1659 00000C9A 7246                    	jb	short R_20y8 
  1660                                  R_20y32:
  1661 00000C9C B10E                    	mov	cl, 0Eh ; FAT 16 LBA 
  1662 00000C9E EB42                    	jmp	short R_20y8 
  1663                                  R_20y4:
  1664 00000CA0 803E[1D44]02            	cmp	byte [pp_type], 2
  1665 00000CA5 751E                    	jne	short R_20y6
  1666 00000CA7 83FA01                  	cmp	dx, 1
  1667 00000CAA 72BC                    	jb	short R_20y30
  1668 00000CAC 7705                    	ja	short R_20y40
  1669 00000CAE 3D0002                  	cmp	ax, 512
  1670 00000CB1 72B5                    	jb	short R_20y30
  1671                                  R_20y40:
  1672 00000CB3 B10B                    	mov	cl, 0Bh ; FAT 32 CHS
  1673 00000CB5 83FA0F                  	cmp	dx, 0Fh
  1674 00000CB8 7228                    	jb	short R_20y8
  1675 00000CBA 7705                    	ja	short R_20y5
  1676 00000CBC 3D00C0                  	cmp	ax, 0C000h
  1677 00000CBF 7221                    	jb	short R_20y8
  1678                                  R_20y5:
  1679 00000CC1 B10C                    	mov 	cl, 0Ch ; FAT 32 LBA
  1680 00000CC3 EB1D                    	jmp	short R_20y8
  1681                                  R_20y6:
  1682 00000CC5 803E[1D44]03            	cmp	byte [pp_type], 3 ; Singlix FS
  1683 00000CCA 7504                    	jne	short R_20y7
  1684 00000CCC B1A1                    	mov	cl, 0A1h
  1685 00000CCE EB12                    	jmp	short R_20y8
  1686                                  R_20y7:
  1687 00000CD0 803E[1D44]04            	cmp	byte [pp_type], 4 ; Retro Unix FS
  1688 00000CD5 7522                    	jne	short R_20y9
  1689 00000CD7 B171                    	mov	cl, 71h
  1690 00000CD9 EB07                    	jmp	short R_20y8
  1691                                  
  1692                                  R_20y8x:
  1693 00000CDB 833E[E230]3F            	cmp	word [sectors], 63
  1694 00000CE0 7586                    	jne	short R_20y30 ; not LBA compatible !
  1695                                  R_20y8:
  1696 00000CE2 884C04                  	mov	[si+ptFileSystemID], cl
  1697                                  
  1698 00000CE5 31C0                    	xor	ax, ax ; 0
  1699 00000CE7 31D2                    	xor	dx, dx ; 0
  1700                                  	; DX_AX = Masterboot Sector = 0
  1701 00000CE9 BB[1E41]                	mov	bx, MasterBootBuff
  1702                                  	; ES:BX = Sector Buffer
  1703 00000CEC E8020D                  	call	write_hd_sector
  1704 00000CEF 0F82C20C                	jc	R_29x
  1705                                  
  1706 00000CF3 E8F811                  	call	show_selected_partition
  1707                                  
  1708 00000CF6 E9DB00                  	jmp	R_21
  1709                                  
  1710                                  R_20y9:
  1711 00000CF9 8A0E[1E44]              	mov	cl, [pp_type_user]
  1712 00000CFD 80F901                  	cmp	cl, 1 ; FAT 12
  1713 00000D00 770F                    	ja	short  R_20y91
  1714 00000D02 21D2                    	and	dx, dx
  1715 00000D04 0F8560FF                	jnz	R_20y30 ; invalid! (> 32MB)
  1716 00000D08 F6C480                  	test	ah, 80h
  1717 00000D0B 0F8559FF                	jnz	R_20y30 ; invalid! (> 16MB)
  1718 00000D0F EBD1                    	jmp	short R_20y8
  1719                                  R_20y91:
  1720 00000D11 80F904                  	cmp	cl, 4 ; FAT 16 (<=32MB)
  1721 00000D14 770F                    	ja	short R_20y92
  1722 00000D16 09D2                    	or	dx, dx
  1723 00000D18 0F854CFF                	jnz	R_20y30 ; invalid! (> 32MB)
  1724                                  R_20y91x:
  1725                                  	; Min. 8400+1 sectors is required (for FAT16)
  1726                                  	; (according to MS FAT32 FS specification)
  1727 00000D1C 3DD020                  	cmp	ax, 8400
  1728 00000D1F 0F8645FF                	jna	R_20y30 ; invalid! (< 4.1MB)
  1729 00000D23 EBBD                    	jmp	short R_20y8
  1730                                  R_20y92:
  1731 00000D25 80F905                  	cmp	cl, 5 ; Extended partition (CHS)
  1732 00000D28 7717                    	ja	short R_20y94
  1733 00000D2A 83FA01                  	cmp	dx, 1
  1734 00000D2D 72B3                    	jb	short R_20y8  ; valid (< 32MB)
  1735                                  R_20y93:
  1736 00000D2F 83FA0F                  	cmp	dx, 0Fh
  1737 00000D32 0F8732FF                	ja	R_20y30 ; invalid! (> 528 MB)
  1738 00000D36 72AA                    	jb	short R_20y8  ; valid (< 528MB)
  1739 00000D38 3D00C0                  	cmp	ax, 0C000h
  1740 00000D3B 0F8329FF                	jnb	R_20y30 ; invalid! (>= 528 MB)
  1741 00000D3F EBA1                    	jmp	short R_20y8
  1742                                  R_20y94:
  1743 00000D41 80F906                  	cmp	cl, 6 ; FAT 16 partition (CHS)
  1744 00000D44 7716                    	ja	short R_20y95
  1745 00000D46 21D2                    	and	dx, dx
  1746 00000D48 74D2                    	jz	short R_20y91x ; check lower limit
  1747                                  	; check upper limit
  1748 00000D4A 83FA0F                  	cmp	dx, 0Fh
  1749 00000D4D 7293                    	jb	short R_20y8  ; valid (< 528MB)
  1750 00000D4F 0F8715FF                	ja	R_20y30 ; invalid! (> 528 MB)
  1751 00000D53 3D00C0                  	cmp	ax, 0C000h
  1752 00000D56 0F830EFF                	jnb	R_20y30 ; invalid! (>= 528 MB)
  1753 00000D5A EB86                    	jmp	short R_20y8
  1754                                  R_20y95:	
  1755 00000D5C 80F907                  	cmp	cl, 7 ; NTFS partition
  1756 00000D5F 7709                    	ja	short R_20y96
  1757 00000D61 21D2                    	and	dx, dx
  1758 00000D63 0F8401FF                	jz	R_20y30 ; invalid! (< 32 MB)
  1759 00000D67 E978FF                  	jmp	R_20y8
  1760                                  R_20y96:	
  1761 00000D6A 80F90B                  	cmp	cl, 0Bh ; FAT 32 CHS
  1762 00000D6D 7728                    	ja	short R_20y98
  1763                                  	; Min. 66600+1 sectors is required (for FAT32)
  1764                                  	; (according to MS FAT32 FS specification)
  1765 00000D6F 83FA01                  	cmp	dx, 1
  1766 00000D72 0F82F2FE                	jb	R_20y30  ; invalid! (< 33 MB)
  1767 00000D76 770A                    	ja	short R_20y97
  1768 00000D78 3D2804                  	cmp	ax, 1064
  1769 00000D7B 0F86E9FE                	jna	R_20y30  ; invalid! (< 33 MB)
  1770 00000D7F E960FF                  	jmp	R_20y8
  1771                                  R_20y97:
  1772 00000D82 83FA0F                  	cmp	dx, 0Fh
  1773 00000D85 0F8259FF                	jb	R_20y8  ; valid (< 528MB)
  1774 00000D89 0F87DBFE                	ja	R_20y30 ; invalid! (> 528 MB)
  1775 00000D8D 3D00C0                  	cmp	ax, 0C000h
  1776 00000D90 0F83D4FE                	jnb	R_20y30 ; invalid! (>= 528 MB)
  1777 00000D94 E94BFF                  	jmp	R_20y8
  1778                                  R_20y98:
  1779 00000D97 80F90C                  	cmp	cl, 0Ch ; FAT 32 LBA
  1780 00000D9A 7715                    	ja	short R_20y99
  1781                                  	; Min. 66600+1 sectors is required
  1782                                  	; (according to MS FAT32 FS specification)
  1783 00000D9C 83FA01                  	cmp	dx, 1
  1784 00000D9F 0F82C5FE                	jb	R_20y30 ; invalid! (< 33 MB)
  1785 00000DA3 0F8734FF                	ja	R_20y8x ; 'sectors per track' must be 63
  1786 00000DA7 3D2804                  	cmp	ax, 1064
  1787 00000DAA 0F86BAFE                	jna	R_20y30  ; invalid! (< 33 MB)
  1788 00000DAE E92AFF                  	jmp	R_20y8x ; 'sectors per track' must be 63
  1789                                  R_20y99:
  1790 00000DB1 80F90E                  	cmp	cl, 0Eh ; FAT 16 LBA
  1791                                  	;je	R_20y8x ; 'sectors per track' must be 63
  1792                                  	; check lower limit
  1793                                  	; (upper limit is 2GB, 1024*64*63 sectors)
  1794 00000DB4 09D2                    	or	dx, dx
  1795 00000DB6 0F8521FF                	jnz	R_20y8x ; 'sectors per track' must be 63
  1796                                  	; Min. 8400+1 sectors is required (for FAT16)
  1797                                  	; (according to MS FAT32 FS specification)
  1798 00000DBA 3DD020                  	cmp	ax, 8400
  1799 00000DBD 0F86A7FE                	jna	R_20y30 ; invalid! (< 4.1MB)
  1800 00000DC1 E917FF                  	jmp	R_20y8x
  1801                                  R_20y100:
  1802 00000DC4 80F90F                  	cmp	cl, 0Fh ; Extended partition (LBA)
  1803 00000DC7 0F8517FF                	jne	R_20y8
  1804 00000DCB 21D2                    	and	dx, dx
  1805 00000DCD 0F8497FE                	jz	R_20y30 ; invalid! (< 32 MB)
  1806 00000DD1 E907FF                  	jmp	R_20y8x	; 'sectors per track' must be 63
  1807                                  
  1808                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1809                                  ; Format question
  1810                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1811                                  
  1812                                  R_21:
  1813 00000DD4 BE[6240]                	mov	si, CRLF
  1814 00000DD7 E8080C                  	call	print_msg
  1815                                  
  1816 00000DDA C606[5A44]01            	mov	byte [format_q], 1
  1817                                  
  1818 00000DDF 803E[1D44]03            	cmp	byte [pp_type], 3 ; FAT16, FAT32, SINGLIX
  1819 00000DE4 7632                    	jna	short R_21a
  1820                                  
  1821 00000DE6 803E[1D44]04            	cmp	byte [pp_type], 4 ; RETRO UNIX 386
  1822 00000DEB 741F                    	je	short R_21x
  1823                                  
  1824                                  	; [pp_type] = 5 (Other FS types)
  1825                                  
  1826 00000DED A0[1E44]                	mov	al, [pp_type_user]
  1827 00000DF0 3C01                    	cmp	al, 1		; FAT12 (CHS)
  1828 00000DF2 7424                    	je	short R_21a
  1829 00000DF4 3C04                    	cmp	al, 4		; FAT16 CHS
  1830 00000DF6 7420                    	je	short R_21a
  1831 00000DF8 3C06                    	cmp	al, 6		; FAT16 BIG CHS
  1832 00000DFA 741C                    	je	short R_21a
  1833 00000DFC 3C0E                    	cmp	al, 0Eh		; FAT 16 LBA
  1834 00000DFE 7418                    	je	short R_21a
  1835 00000E00 3C0B                    	cmp	al, 0Bh		; FAT32 CHS
  1836 00000E02 7414                    	je	short R_21a
  1837 00000E04 3C0C                    	cmp	al, 0Ch		; FAT32 LBA
  1838 00000E06 7410                    	je	short R_21a
  1839 00000E08 3CA1                    	cmp	al, 0A1h	; SINGLIX FS1
  1840 00000E0A 740C                    	je	short R_21a
  1841                                  
  1842                                  R_21x:
  1843 00000E0C FE0E[5A44]              	dec	byte [format_q] ; 0		
  1844                                  
  1845                                  	; NON-DOS partition!
  1846                                  	; Ask for editing PT or exit (continue without formatting)
  1847 00000E10 BE[913E]                	mov	si, msg_edit_or_exit
  1848 00000E13 E8CC0B                  	call	print_msg
  1849 00000E16 EB06                    	jmp	short R_21b
  1850                                  R_21a:
  1851                                  	; Ask for formatting, editing PT or exit
  1852 00000E18 BE[223E]                	mov	si, msg_format_stage
  1853 00000E1B E8C40B                  	call	print_msg
  1854                                  R_21b:
  1855 00000E1E BE[623E]                	mov	si, msg_partition_edit
  1856 00000E21 E8BE0B                  	call	print_msg
  1857                                  R_21c:
  1858 00000E24 28E4                    	sub	ah, ah
  1859 00000E26 CD16                    	int	16h
  1860                                  
  1861 00000E28 3C0D                    	cmp	al, 13
  1862 00000E2A 7418                    	je	short R_21d
  1863                                  
  1864 00000E2C 3C20                    	cmp	al, 20h ; SPACE
  1865 00000E2E 7404                    	je	short edit_partition
  1866                                  
  1867 00000E30 3C1B                    	cmp	al, 27 ; ESCAPE
  1868 00000E32 75F0                    	jne	short R_21c
  1869                                  	
  1870                                  edit_partition: ; temporary !
  1871                                  Exit:
  1872                                  R_21esc:
  1873 00000E34 B43E                    	mov	ah, 3Eh ; close file
  1874 00000E36 8B1E[E030]              	mov	bx, [img_file_handle]
  1875 00000E3A CD21                    	int	21h
  1876 00000E3C BE[6240]                	mov	si, CRLF
  1877 00000E3F E8A00B                  	call	print_msg
  1878                                  	; Exit	
  1879 00000E42 CD20                    	int	20h
  1880                                  R_21d:
  1881 00000E44 803E[5A44]01            	cmp	byte [format_q], 1
  1882 00000E49 72E9                    	jb	short Exit
  1883                                  
  1884                                  	; clear screen
  1885 00000E4B B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
  1886 00000E4E CD10                    	int	10h	
  1887                                  
  1888 00000E50 A0[493E]                	mov	al, [partition_num_chr]
  1889 00000E53 A2[093F]                	mov	[partition_num_txt], al
  1890                                  
  1891 00000E56 BE[E73E]                	mov	si, msg_format_question
  1892 00000E59 E8860B                  	call	print_msg
  1893                                  R_21e:
  1894 00000E5C 30E4                    	xor	ah, ah
  1895 00000E5E CD16                    	int	16h
  1896                                  
  1897 00000E60 3C1B                    	cmp	al, 1Bh ; ESCAPE
  1898 00000E62 74D0                    	je	short R_21esc
  1899                                  
  1900 00000E64 24DF                    	and	al, 0DFh ; capitalization
  1901 00000E66 3C59                    	cmp	al, 'Y'
  1902 00000E68 740C                    	je	short R_21f
  1903 00000E6A 3C4E                    	cmp	al, 'N'
  1904 00000E6C 75EE                    	jne	short R_21e
  1905 00000E6E BE[6A40]                	mov	si, Msg_NO 
  1906 00000E71 E86E0B                  	call	print_msg
  1907 00000E74 EBBE                    	jmp	short R_21esc
  1908                                  R_21f:
  1909 00000E76 BE[6540]                	mov	si, Msg_YES
  1910 00000E79 E8660B                  	call	print_msg
  1911                                  
  1912                                  	; [pp_StartSector] = partition's start sector
  1913                                  	; [pp_Sectors] = partition size including start & end sector	
  1914                                  	; [partition_num_chr] = partition number + '0'
  1915                                  	; [pp_type] = partition type (for TRDOS 386 boot sector) 
  1916                                  
  1917 00000E7C 8926[744A]              	mov	[old_sp], sp
  1918                                  	
  1919 00000E80 8B16[1D44]              	mov	dx, [pp_type] ; dh = [pp_type_user]
  1920                                  	; DL = partition type 1 to 4 (FAT12, FAT16, FAT32, SINGLIX)
  1921                                  	; DH = file system ID (Microsoft FAT/FAT32 partition type)
  1922 00000E84 FECA                    	dec	dl
  1923 00000E86 0F84F403                	jz	FAT16_hdi_format
  1924 00000E8A 80FA02                  	cmp	dl, 2
  1925 00000E8D 721A                    	jb	short FAT32_hdi_format	
  1926 00000E8F 0F846807                	je	SINGLIX_hdi_format
  1927                                  	;
  1928 00000E93 80FEA1                  	cmp	dh, 0A1h
  1929 00000E96 0F836107                	jnb	SINGLIX_hdi_format
  1930 00000E9A 80FE0B                  	cmp	dh, 0Bh
  1931 00000E9D 730A                    	jnb	short FAT32_hdi_format
  1932 00000E9F 80FE01                  	cmp	dh, 01h
  1933 00000EA2 0F87D803                	ja	FAT16_hdi_format ; 04h, 06h, 0Eh	
  1934 00000EA6 E9D305                  	jmp	FAT12_hdi_format
  1935                                  
  1936                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1937                                  ; FAT32 FORMATTING
  1938                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 	
  1939                                  	
  1940                                  FAT32_hdi_format:
  1941 00000EA9 B80C00                  	mov	ax, 000Ch ; db 0Ch, 00h ; 'or al, 0'
  1942 00000EAC 38C6                    	cmp	dh, al ; 0Ch
  1943 00000EAE 7403                    	je	short FAT32_lba_format
  1944 00000EB0 B80BC0                  	mov	ax, 0C00Bh ; db 0Bh, 0C0h ; 'or ax, ax'
  1945                                  FAT32_lba_format:
  1946                                  	; Put TRDOS 386 FAT32 partition magic word 
  1947                                  	; at offset 5Ah, in TRDOS386 FAT32 boot sector 0.
  1948 00000EB3 BD[CE24]                	mov	bp, TRDOS_FAT32_hd_bs
  1949 00000EB6 8D7E03                  	lea	di, [bp+3]
  1950 00000EB9 BE[4544]                	mov	si, bs_oem_name
  1951 00000EBC B90400                  	mov	cx, 4
  1952 00000EBF F3A5                    	rep	movsw 
  1953 00000EC1 89465A                  	mov	[bp+5Ah], ax	; [loc_5A]
  1954 00000EC4 A1[E230]                	mov	ax, [sectors]
  1955 00000EC7 894618                  	mov	[bp+18h], ax	; [BPB_SecPerTrk]
  1956 00000ECA A1[E430]                	mov	ax, [heads]
  1957 00000ECD 89461A                  	mov	[bp+1Ah], ax	; [BPB_NumHeads]
  1958 00000ED0 A1[1444]                	mov	ax, [pp_StartSector]
  1959 00000ED3 89461C                  	mov	[bp+1Ch], ax	; [BPB_HiddSec]
  1960 00000ED6 A1[1644]                	mov	ax, [pp_StartSector+2]
  1961 00000ED9 89461E                  	mov	[bp+1Eh], ax	; [BPB_HiddSec+2]
  1962 00000EDC A1[1844]                	mov	ax, [pp_Sectors]
  1963 00000EDF 894620                  	mov	[bp+20h], ax	; [BPB_TotSec32]
  1964 00000EE2 8B16[1A44]              	mov	dx, [pp_Sectors+2]
  1965 00000EE6 895622                  	mov	[bp+22h], dx	; [BPB_TotSec32+2]
  1966                                  	
  1967                                  	; Sectors per cluster calculation
  1968                                  	; (According to MS FAT32 FS specification.)
  1969 00000EE9 B108                    	mov	cl, 8  ; 8 sectors per cluster
  1970 00000EEB 83FA08                  	cmp	dx, 8  ; >= 532480 sectors
  1971 00000EEE 7709                    	ja	short FAT32_f_2 ; 8 sectors per cluster
  1972 00000EF0 7205                    	jb	short FAT32_f_1 ; 1 sector per cluster	
  1973 00000EF2 3D0020                  	cmp	ax, 2000h ; dx_ax = (8*65536)+8192
  1974 00000EF5 7300                    	jnb	short FAT32_f_1
  1975                                  FAT32_f_1:
  1976 00000EF7 B101                    	mov	cl, 1	; 1 sector per cluster		
  1977                                  FAT32_f_2:
  1978 00000EF9 884E0D                  	mov	[bp+0Dh], cl	 ; [BPB_SecPerClus]
  1979                                  	;mov	byte [bp+10h], 2 ; [BPB_NumFATs] 
  1980                                  	;mov	word [bp+0Eh], 32 ; [BPB_RsvdSecCnt] 
  1981                                  
  1982                                  	; Calculating FAT size in sectors
  1983                                  	; (According to MS FAT32 FS Specification, 2000)
  1984                                  
  1985                                  	; DX_AX = partition (volume) size in sectors
  1986 00000EFC 2B460E                  	sub	ax, [bp+0Eh]	; [BPB_RsvdSecCnt] ; 32
  1987 00000EFF 83DA00                  	sbb	dx, 0
  1988                                  		; TmpVal1 = DiskSize - (BPB_ResvdSecCnt +
  1989                                  		;	     		RootDirsectors)
  1990                                  		; RootDirSectors = 0 (for FAT32 FS)
  1991 00000F02 89CB                    	mov	bx, cx ; ch = 0
  1992 00000F04 C1E308                  	shl	bx, 8 ; * 256
  1993 00000F07 8A4E10                  	mov	cl, [bp+10h] ; [BPB_NumFATs] 
  1994 00000F0A 01CB                    	add	bx, cx	
  1995                                  		; TmpVal2 = (256*BPB_SecPerClus)+BPB_NumFATs
  1996 00000F0C D1EB                    	shr	bx, 1
  1997                                  		; TmpVal2 = TmpVal2/2
  1998 00000F0E 89D9                    	mov	cx, bx
  1999 00000F10 4B                      	dec	bx  ; TmpVal2-1
  2000 00000F11 01D8                    	add	ax, bx
  2001 00000F13 83D200                  	adc	dx, 0
  2002 00000F16 E85DF9                  	call	div32
  2003                                  		; FATSz = (TmpVal1+(TmpVal2-1))/TmpVal2
  2004                                  	; DX_AX = FAT size in sectors
  2005 00000F19 894624                  	mov	[bp+24h], ax	; [BPB_FATSz32]
  2006 00000F1C 895626                  	mov	[bp+26h], dx	; [BPB_FATSz32+2]
  2007                                  	; * 2
  2008 00000F1F 89D3                    	mov	bx, dx
  2009 00000F21 01C0                    	add	ax, ax
  2010 00000F23 11D3                    	adc	bx, dx
  2011                                  	; BX_AX = [BPB_NumFATs] * [BPB_FATSz32]
  2012 00000F25 8B4E0E                  	mov	cx, [bp+0Eh]	; [BPB_RsvdSecCnt] ; 32
  2013 00000F28 01C1                    	add	cx, ax
  2014 00000F2A 83D300                  	adc	bx, 0
  2015                                  	; BX_CX = [BPB_RsvdSecCnt]+[BPB_NumFATs]*[BPB_FATSz32]
  2016 00000F2D 8B4620                  	mov	ax, [bp+20h]	; [BPB_TotSec32]
  2017 00000F30 8B5622                  	mov	dx, [bp+22h]	; [BPB_TotSec32+2]
  2018 00000F33 29C8                    	sub	ax, cx
  2019 00000F35 19DA                    	sbb	dx, bx
  2020 00000F37 890E[624A]              	mov	[data_start], cx
  2021 00000F3B 891E[644A]              	mov	[data_start+2], bx
  2022                                  	; DX_AX = Data sectors
  2023 00000F3F A3[664A]                	mov	[data_sectors], ax
  2024 00000F42 8916[684A]              	mov	[data_sectors+2], dx
  2025 00000F46 8A4E0D                  	mov	cl, [bp+0Dh]	 ; [BPB_SecPerClus]
  2026 00000F49 30ED                    	xor	ch, ch
  2027 00000F4B E828F9                  	call	div32 ; DX_AX/CX
  2028                                  	; DX_AX = Count of clusters (rounded down)
  2029 00000F4E A3[6A4A]                	mov	[cluster_count], ax
  2030 00000F51 8916[6C4A]              	mov	[cluster_count+2], dx
  2031                                  		
  2032 00000F55 8D7E47                  	lea	di, [bp+71] ; [BS_VolLab]
  2033 00000F58 E89A01                  	call	write_volume_name
  2034 00000F5B 8D7643                  	lea	si, [bp+67] ; [BS_VolID]
  2035 00000F5E E8F301                  	call	write_volume_serial
  2036 00000F61 E80303                  	call	write_cluster_count
  2037                                  
  2038 00000F64 E87402                  	call	write_formatting_msg
  2039 00000F67 B000                    	mov	al, 0
  2040 00000F69 E8CC02                  	call	write_format_percent_x
  2041                                  
  2042 00000F6C 8B461C                  	mov	ax, [bp+1Ch]	; [BPB_HiddSec]
  2043 00000F6F 8B561E                  	mov	dx, [bp+1Eh]	; [BPB_HiddSec+2]
  2044 00000F72 0106[624A]              	add	[data_start], ax
  2045 00000F76 1116[644A]              	adc	[data_start+2], dx
  2046                                  FAT32_f_3:
  2047                                  	; DX_AX = FAT32 Boot Sector address
  2048 00000F7A BB[CE24]                	mov	bx, TRDOS_FAT32_hd_bs
  2049                                  	; ES:BX = Boot Sector 1 Buffer
  2050 00000F7D E8710A                  	call	write_hd_sector
  2051 00000F80 0F82C802                	jc	formatting_error
  2052 00000F84 E87802                  	call	write_format_percent
  2053 00000F87 83C001                  	add	ax, 1
  2054 00000F8A 83D200                  	adc	dx, 0
  2055 00000F8D BB[6246]                	mov	bx, HDFORMAT_FSINFO_BUFF
  2056                                  	; ES:BX = FS INFO Sector Buffer (= BS+1)
  2057 00000F90 E85E0A                  	call	write_hd_sector
  2058 00000F93 0F82B502                	jc	formatting_error
  2059 00000F97 E86502                  	call	write_format_percent	
  2060 00000F9A 83C001                  	add	ax, 1
  2061 00000F9D 83D200                  	adc	dx, 0	
  2062 00000FA0 BB[CE26]                	mov	bx, TRDOS_FAT32_hd_bs + 512
  2063                                  	; ES:BX = Boot Sector 2 Buffer
  2064 00000FA3 E84B0A                  	call	write_hd_sector
  2065 00000FA6 0F82A202                	jc	formatting_error
  2066 00000FAA E85202                  	call	write_format_percent
  2067 00000FAD B90300                  	mov	cx, 3
  2068                                  FAT32_f_4:
  2069 00000FB0 51                      	push	cx
  2070 00000FB1 83C001                  	add	ax, 1
  2071 00000FB4 83D200                  	adc	dx, 0
  2072 00000FB7 BB[6248]                	mov	bx, HDFORMAT_EMPTY_BUFF
  2073 00000FBA E8340A                  	call	write_hd_sector
  2074 00000FBD 0F828B02                	jc	formatting_error
  2075 00000FC1 E83B02                  	call	write_format_percent
  2076 00000FC4 59                      	pop	cx
  2077 00000FC5 FEC9                    	dec	cl
  2078 00000FC7 75E7                    	jnz	short FAT32_f_4
  2079 00000FC9 83C001                  	add	ax, 1
  2080 00000FCC 83D200                  	adc	dx, 0
  2081 00000FCF 8B4E1C                  	mov	cx, [bp+1Ch]	; [BPB_HiddSec]
  2082 00000FD2 8B5E1E                  	mov	bx, [bp+1Eh]	; [BPB_HiddSec+2]
  2083 00000FD5 83C10C                  	add	cx, 12
  2084 00000FD8 83D300                  	adc	bx, 0
  2085                                  	; write BACKUP sectors
  2086                                  	; (6,7,8 boot+fsi and 9,10,11 empty sectors) 
  2087 00000FDB 39DA                    	cmp	dx, bx
  2088 00000FDD 729B                    	jb	short FAT32_f_3
  2089 00000FDF 39C8                    	cmp	ax, cx
  2090 00000FE1 7297                    	jb	short FAT32_f_3
  2091                                  	; write remain part of reserved sectors
  2092 00000FE3 8B4E0E                  	mov	cx, [bp+0Eh]	; [BPB_RsvdSecCnt]
  2093 00000FE6 83E90C                  	sub	cx, 12
  2094 00000FE9 7618                    	jna	short FAT32_f_6
  2095                                  FAT32_f_5:
  2096 00000FEB 51                      	push	cx
  2097 00000FEC BB[6248]                	mov	bx, HDFORMAT_EMPTY_BUFF
  2098 00000FEF E8FF09                  	call	write_hd_sector
  2099 00000FF2 0F825602                	jc	formatting_error
  2100 00000FF6 E80602                  	call	write_format_percent
  2101 00000FF9 83C001                  	add	ax, 1
  2102 00000FFC 83D200                  	adc	dx, 0
  2103 00000FFF 59                      	pop	cx
  2104 00001000 49                      	dec	cx
  2105 00001001 75E8                    	jnz	short FAT32_f_5
  2106                                  FAT32_f_6:
  2107                                  	; write FAT sectors
  2108 00001003 8B0E[624A]              	mov	cx, [data_start] ; lba/abs addr
  2109 00001007 8B1E[644A]              	mov	bx, [data_start+2] ; lba/abs addr
  2110 0000100B 53                      	push	bx
  2111 0000100C 51                      	push	cx
  2112 0000100D BB[6248]                	mov	bx, HDFORMAT_FATBUFFER
  2113                                  	; ES:BX = FAT Sector Buffer
  2114 00001010 8A4E15                  	mov	cl, [bp+15h] ; [BPB_Media]
  2115 00001013 B5FF                    	mov	ch, 0FFh
  2116 00001015 890F                    	mov	[bx], cx
  2117 00001017 88E9                    	mov	cl, ch ; cx = 0FFFFh
  2118 00001019 894F02                  	mov	[bx+2], cx
  2119 0000101C 894F04                  	mov	[bx+4], cx
  2120 0000101F 894F06                  	mov	[bx+6], cx
  2121                                  	; Root dir cluster number = 2
  2122                                  	; 0FFFFFFFh = end of cluster chain 
  2123 00001022 894F08                  	mov	[bx+8], cx  ; 0FFFFh
  2124 00001025 80E50F                  	and	ch, 0Fh
  2125 00001028 894F0A                  	mov	[bx+10], cx ; 0FFFh
  2126                                  	;inc	cx
  2127 0000102B E8C309                  	call	write_hd_sector
  2128 0000102E 0F821A02                	jc	formatting_error
  2129 00001032 E8CA01                  	call	write_format_percent
  2130                                  	;mov	bx, HDFORMAT_FATBUFFER
  2131 00001035 B90000                  	mov	cx, 0
  2132 00001038 890F                    	mov	[bx], cx
  2133 0000103A 894F02                  	mov	[bx+2], cx
  2134 0000103D 894F04                  	mov	[bx+4], cx
  2135 00001040 894F06                  	mov	[bx+6], cx
  2136 00001043 894F08                  	mov	[bx+8], cx
  2137 00001046 894F0A                  	mov	[bx+10], cx
  2138 00001049 EB0F                    	jmp	short FAT32_f_8
  2139                                  FAT32_f_7:	
  2140 0000104B 53                      	push	bx
  2141 0000104C 51                      	push	cx	
  2142 0000104D BB[6248]                	mov	bx, HDFORMAT_FATBUFFER
  2143 00001050 E89E09                  	call	write_hd_sector
  2144 00001053 0F82F501                	jc	formatting_error
  2145 00001057 E8A501                  	call	write_format_percent
  2146                                  FAT32_f_8:	
  2147 0000105A 59                      	pop	cx
  2148 0000105B 5B                      	pop	bx
  2149 0000105C 83C001                  	add	ax, 1
  2150 0000105F 83D200                  	adc	dx, 0
  2151 00001062 39DA                    	cmp	dx, bx
  2152 00001064 72E5                    	jb	short FAT32_f_7
  2153 00001066 39C8                    	cmp	ax, cx
  2154 00001068 72E1                    	jb	short FAT32_f_7
  2155                                  
  2156                                  	; write	root directory (1st cluster)
  2157                                  	; as empty sectors
  2158 0000106A 8A4E0D                  	mov	cl, [bp+0Dh]	 ; [BPB_SecPerClus]
  2159 0000106D 30ED                    	xor	ch, ch
  2160 0000106F 290E[664A]              	sub	[data_sectors], cx
  2161 00001073 831E[684A]00            	sbb	word [data_sectors+2], 0
  2162                                  FAT32_f_9:
  2163 00001078 51                      	push	cx
  2164 00001079 BB[6248]                	mov	bx, HDFORMAT_EMPTY_BUFF
  2165 0000107C E87209                  	call	write_hd_sector
  2166 0000107F 0F82C901                	jc	formatting_error
  2167 00001083 E87901                  	call	write_format_percent
  2168 00001086 83C001                  	add	ax, 1
  2169 00001089 83D200                  	adc	dx, 0
  2170 0000108C 59                      	pop	cx
  2171 0000108D FEC9                    	dec	cl
  2172 0000108F 75E7                    	jnz	short FAT32_f_9
  2173                                  
  2174                                  	; write DATA sectors 
  2175                                  	; (after root directory 1st cluster)
  2176 00001091 8B0E[664A]              	mov	cx, [data_sectors]
  2177 00001095 8B1E[684A]              	mov	bx, [data_sectors+2]
  2178                                  FAT32_f_10:	
  2179 00001099 53                      	push	bx
  2180 0000109A 51                      	push	cx	
  2181 0000109B BB[6244]                	mov	bx, HDFORMAT_SECBUFFER
  2182 0000109E E85009                  	call	write_hd_sector
  2183 000010A1 0F82A701                	jc	formatting_error
  2184 000010A5 E85701                  	call	write_format_percent
  2185 000010A8 59                      	pop	cx
  2186 000010A9 5B                      	pop	bx
  2187 000010AA 83C001                  	add	ax, 1
  2188 000010AD 83D200                  	adc	dx, 0
  2189 000010B0 49                      	dec	cx
  2190 000010B1 75E6                    	jnz	short FAT32_f_10
  2191 000010B3 4B                      	dec	bx
  2192 000010B4 75E3                    	jnz	short FAT32_f_10
  2193                                  
  2194                                  	; If there are, format remain sectors which are
  2195                                  	; at beyond of data clusters, with zero bytes.
  2196                                  	
  2197 000010B6 8B4E1C                  	mov	cx, [bp+1Ch]	; [BPB_HiddSec]
  2198 000010B9 8B5E1E                  	mov	bx, [bp+1Eh]	; [BPB_HiddSec+2]
  2199                                  FAT16_f_18:	
  2200 000010BC 034E20                  	add	cx, [bp+20h]	; [BPB_TotSec32]
  2201 000010BF 135E22                  	adc	bx, [bp+22h]	; [BPB_TotSec32+2]
  2202                                  FAT16_f_19:
  2203                                  FAT12_f_8:
  2204                                  	; are there remain sectors (in partition) ?
  2205 000010C2 29C1                    	sub	cx, ax
  2206 000010C4 19D3                    	sbb	bx, dx
  2207 000010C6 7618                    	jna	short FAT32_f_12 ; no.. (good!)
  2208                                  FAT32_f_11:
  2209 000010C8 51                      	push	cx
  2210 000010C9 BB[6248]                	mov	bx, HDFORMAT_EMPTY_BUFF
  2211 000010CC E82209                  	call	write_hd_sector
  2212 000010CF 0F827901                	jc	formatting_error
  2213 000010D3 E82901                  	call	write_format_percent
  2214 000010D6 59                      	pop	cx
  2215 000010D7 83C001                  	add	ax, 1
  2216 000010DA 83D200                  	adc	dx, 0
  2217 000010DD 49                      	dec	cx
  2218 000010DE 75E8                    	jnz	short FAT32_f_11
  2219                                  
  2220                                  FAT32_f_12:
  2221                                  SINGLIX_fs1_f_12:
  2222                                  	; End of FAT format routine...
  2223                                  end_of_formatting:
  2224 000010E0 B064                    	mov	al, 100
  2225 000010E2 E85301                  	call	write_format_percent_x
  2226                                  	;mov	si, CRLF
  2227                                  	;call	print_msg
  2228 000010E5 BE[5E40]                	mov	si, Msg_OK
  2229 000010E8 E8F708                  	call	print_msg
  2230 000010EB E946FD                  	jmp	Exit
  2231                                  
  2232                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2233                                  ; set & write volume name
  2234                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2235                                  
  2236                                  write_fs_volume_name:
  2237 000010EE C606[4444]40            	mov	byte [vname_length], 64
  2238 000010F3 EB05                    	jmp	short svn_fs
  2239                                  
  2240                                  write_volume_name:
  2241 000010F5 C606[4444]0B            	mov	byte [vname_length], 11
  2242                                  svn_fs:
  2243                                  	; DI = (BS) Volume Label address
  2244 000010FA BE[0040]                	mov	si, Msg_Volume_Name
  2245 000010FD E8E208                  	call	print_msg
  2246                                  
  2247                                  	; get cursor position
  2248                                  	; bh = 0  ; video page
  2249 00001100 B403                    	mov     ah, 3 ; get cursor pos
  2250 00001102 CD10                    	int     10h
  2251 00001104 8916[A63F]              	mov	[Cursor_Pos], dx
  2252                                  
  2253 00001108 E88D09                  	call	rw_char
  2254 0000110B 7207                    	jc	short svn_1
  2255                                  svn_0:
  2256 0000110D AC                      	lodsb
  2257 0000110E 3C20                    	cmp	al, 20h
  2258 00001110 7706                    	ja	short svn_2
  2259 00001112 74F9                    	je	short svn_0 
  2260                                  svn_1:
  2261 00001114 BE[4E44]                	mov	si, no_name
  2262 00001117 AC                      	lodsb
  2263                                  svn_2:
  2264                                  	;mov	di, [bp+47h) ; [BS_VolLab] ; FAT32
  2265                                  	;mov	di, [bp+2Bh) ; [BS_VolLab] ; FAT16 (&FAT12)
  2266 00001118 89FB                    	mov	bx, di ; *
  2267 0000111A 30ED                    	xor	ch, ch
  2268 0000111C 8A0E[4444]              	mov	cl, [vname_length] ; 11
  2269 00001120 EB05                    	jmp	short svn_4
  2270                                  svn_3:
  2271 00001122 AC                      	lodsb
  2272 00001123 3C20                    	cmp	al, 20h
  2273 00001125 7226                    	jb	short svn_6
  2274                                  svn_4:
  2275 00001127 AA                      	stosb
  2276 00001128 E2F8                    	loop	svn_3
  2277                                  svn_5:
  2278 0000112A 8A0E[4444]              	mov	cl, [vname_length] ; 11
  2279 0000112E 89DE                    	mov	si, bx ; *
  2280 00001130 BF[BF3F]                	mov	di, StrVolumeName
  2281 00001133 F3A4                    	rep	movsb
  2282                                  	;mov	byte [di], 0
  2283                                  
  2284 00001135 8B16[A63F]              	mov	dx, [Cursor_Pos]
  2285 00001139 BB0700                  	mov	bx, 7
  2286 0000113C B402                    	mov	ah, 2
  2287 0000113E CD10                    	int	10h  ; Set Cursor Position
  2288                                  
  2289 00001140 BE[BF3F]                	mov	si, StrVolumeName
  2290 00001143 E89C08                  	call	print_msg
  2291 00001146 BE[6240]                	mov	si, CRLF
  2292 00001149 E89608                  	call	print_msg
  2293 0000114C C3                      	retn
  2294                                  svn_6:
  2295 0000114D B020                    	mov	al, 20h
  2296                                  svn_7:
  2297 0000114F AA                      	stosb
  2298 00001150 E2FD                    	loop	svn_7
  2299 00001152 EBD6                    	jmp	short svn_5
  2300                                  
  2301                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2302                                  ; set & write volume serial number (volume ID)
  2303                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2304                                  
  2305                                  write_volume_serial:
  2306                                  	; SI = (BS) Volume Serial Number (binary) address
  2307                                  
  2308                                  	;xor	ax, ax
  2309                                  	;int	1Ah			; get time of day
  2310                                  
  2311                                  	;mov	[si], dx
  2312                                  	;mov	[si+2], cx		; set unique volume ID
  2313                                  
  2314                                  	;mov	ah, 02h			; Return Current Time
  2315                                  	;int	1Ah
  2316                                  	;xchg	ch, cl
  2317                                  	;xchg	dh, dl
  2318                                  
  2319                                  	;add	cx, dx  
  2320                                  	;add	[si+2], cx
  2321                                                 
  2322                                  	;mov	ah, 04h			; Return Current Date
  2323                                  	;int	1Ah
  2324                                  
  2325                                  	;xchg	ch,cl
  2326                                  	;xchg	dh,dl
  2327                                  
  2328                                  	;add	cx, dx  
  2329                                  	;add	[si+2], cx
  2330                                  
  2331                                  	; According to Microsoft DOS 6.0 serial number
  2332                                  	; production method...
  2333                                  	; < Create unique 32 bit serial number >
  2334                                  
  2335                                  	; Create_Serial_ID (MSDOS 6.0 Source code, MSFOR.ASM)
  2336                                  	; (20/04/1987)
  2337                                  	;
  2338                                  	;  Get date (INT 21h, AH=2Bh)
  2339                                  	;  Get time (INT 21h, AH=2Ch)
  2340                                  	;  Serial_ID+0 = DX reg date + DX reg time
  2341                                  	;  Serial_ID+2 = CX reg date + CX reg time
  2342                                  	;  Serial_Num_Low = Serial_ID+2
  2343                                  	;  Serial_Num_High = Serial_ID+0
  2344                                  
  2345 00001154 B404                    	mov	ah, 04h		; Return Current Date
  2346 00001156 CD1A                    	int	1Ah
  2347                                  
  2348                                  	; DL = Day (BCD)	(20h) 	
  2349                                  	; DH = Month (BCD)	(12h)
  2350                                  	; CH = Century (BCD)	(20h)
  2351                                  	; CL = Year (BCD) 	(17h)
  2352                                  
  2353 00001158 88D0                    	mov	al, dl
  2354 0000115A E87100                  	call	bcd_to_bin
  2355 0000115D 88C2                    	mov	dl, al 
  2356 0000115F 88F0                    	mov	al, dh
  2357 00001161 E86A00                  	call	bcd_to_bin
  2358 00001164 88C6                    	mov	dh, al 
  2359 00001166 88C8                    	mov	al, cl
  2360 00001168 E86300                  	call	bcd_to_bin
  2361 0000116B 88C1                    	mov	cl, al 
  2362 0000116D 88E8                    	mov	al, ch
  2363 0000116F E85C00                  	call	bcd_to_bin
  2364 00001172 88C5                    	mov	ch, al
  2365                                  
  2366                                  	; DH = Month (1-10)
  2367                                  	; DL = Day (1-31)
  2368                                  	; CX = Year (1900-2099)
  2369                                  
  2370 00001174 52                      	push	dx 
  2371 00001175 51                      	push	cx
  2372                                  
  2373 00001176 B402                    	mov	ah, 02h		; Return Current Time
  2374 00001178 CD1A                    	int	1Ah
  2375                                  	
  2376                                  	; DH = Seconds (BCD)	(59h) 	
  2377                                  	; CL = Minutes (BCD)	(59h)
  2378                                  	; CH = Hours (BCD)	(23h)
  2379                                  	; DL = Daylight savings time option (1=yes)
  2380                                  
  2381 0000117A 88F0                    	mov	al, dh
  2382 0000117C E84F00                  	call	bcd_to_bin
  2383 0000117F 88C6                    	mov	dh, al 
  2384 00001181 88C8                    	mov	al, cl
  2385 00001183 E84800                  	call	bcd_to_bin
  2386 00001186 88C1                    	mov	cl, al 
  2387 00001188 88E8                    	mov	al, ch
  2388 0000118A E84100                  	call	bcd_to_bin
  2389 0000118D 88C5                    	mov	ch, al 
  2390                                  
  2391                                  	; CH = Hour (0-23)
  2392                                  	; CL = Minutes (0-59)
  2393                                  	; DH = Seconds (0-59)
  2394                                  	; ((DL = Hundredths (0-99) - MSDOS!))
  2395                                  	; DL = 0 or 1 (here!)
  2396                                  
  2397 0000118F 89C8                    	mov	ax, cx
  2398 00001191 59                      	pop	cx
  2399 00001192 01C8                    	add	ax, cx
  2400                                  
  2401 00001194 894402                  	mov	[si+2], ax
  2402                                  
  2403 00001197 89D0                    	mov	ax, dx
  2404 00001199 5A                      	pop	dx
  2405 0000119A 01D0                    	add	ax, dx
  2406                                  
  2407 0000119C 8904                    	mov	[si], ax
  2408                                  
  2409 0000119E 30E4                    	xor	ah, ah		; Read time counter
  2410 000011A0 CD1A                    	int	1Ah
  2411                                  
  2412                                  	; CX = High word of clock count
  2413                                  	; DX = Low word of clock count
  2414                                  	; AL = 0 if 24 hours has not passed, else 1
  2415                                  
  2416                                  	; NOTES: 
  2417                                  	; (Ref: vitaly_filatov.tripod.com/ng/asm/asm_029.1.html)
  2418                                  	;
  2419                                     	; Following formulas convert the clock count to
  2420                                          ; the time of day:
  2421                                   	;	Hour      = Clock / 65543 (1007h)
  2422                                  	;	Remainder = Clock MOD 65543
  2423                                   	;
  2424                                  	;	Minutes   = Remainder / 1092 (444h)
  2425                                  	;	Remainder = Remainder MOD 1092
  2426                                  	;
  2427                                  	;	Second    = Remainder / 18.21
  2428                                  	;	Remainder = Remainder MOD 18.21
  2429                                  	;
  2430                                  	;	Hundredths = CINT(Remainder * 100)
  2431                                  
  2432 000011A2 0014                    	add	[si], dl
  2433                                  
  2434                                  	; SI = Volume serial number address (4 bytes) 
  2435 000011A4 8A04                    	mov	al, [si]
  2436 000011A6 E8D808                  	call	bin_to_hex
  2437 000011A9 A3[2B40]                	mov	[Vol_Serial2+2], ax	
  2438 000011AC 8A4401                  	mov	al, [si+1]
  2439 000011AF E8CF08                  	call	bin_to_hex
  2440 000011B2 A3[2940]                	mov	[Vol_Serial2], ax
  2441 000011B5 8A4402                  	mov	al, [si+2]
  2442 000011B8 E8C608                  	call	bin_to_hex
  2443 000011BB A3[2640]                	mov	[Vol_Serial1+2], ax	
  2444 000011BE 8A4403                  	mov	al, [si+3]
  2445 000011C1 E8BD08                  	call	bin_to_hex
  2446 000011C4 A3[2440]                	mov	[Vol_Serial1], ax
  2447                                  
  2448 000011C7 BE[1240]                	mov	si, Msg_Volume_Serial
  2449 000011CA E81508                  	call	print_msg
  2450                                  
  2451 000011CD C3                      	retn
  2452                                  
  2453                                  bcd_to_bin:
  2454 000011CE 53                      	push	bx
  2455 000011CF D410                    	db	0D4h,10h  ; Undocumented inst. AAM
  2456                                  			  ; AH = AL / 10h
  2457                                  			  ; AL = AL MOD 10h
  2458 000011D1 88C3                    	mov	bl, al
  2459 000011D3 B00A                    	mov	al, 10
  2460 000011D5 F6E4                    	mul	ah
  2461 000011D7 00D8                    	add	al, bl
  2462 000011D9 5B                      	pop	bx
  2463 000011DA C3                      	retn
  2464                                  
  2465                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2466                                  ; write formatting percentage
  2467                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2468                                  
  2469                                  write_formatting_msg:
  2470 000011DB A1[1844]                	mov	ax, [pp_Sectors]
  2471 000011DE 8B16[1A44]              	mov	dx, [pp_Sectors+2]
  2472                                  
  2473                                  	; DX_AX = Total sectors for percentage  
  2474 000011E2 B96400                  	mov	cx, 100	
  2475 000011E5 E88EF6                  	call	div32
  2476 000011E8 A3[704A]                	mov	[format_percent], ax
  2477                                  
  2478 000011EB BE[4A40]                	mov	si, msg_formatting
  2479 000011EE E8F107                  	call	print_msg
  2480                                  
  2481                                  	; get cursor position
  2482                                  	; bh = 0  ; video page
  2483 000011F1 B403                    	mov     ah, 3 ; get cursor pos
  2484 000011F3 CD10                    	int     10h
  2485 000011F5 8916[A63F]              	mov	[Cursor_Pos], dx
  2486                                  
  2487 000011F9 C606[724A]FF            	mov	byte [prev_percent], 255
  2488                                  
  2489 000011FE C3                      	retn
  2490                                  
  2491                                  write_format_percent:
  2492                                  	; DX_AX = Current sector (which has been written)
  2493                                  
  2494 000011FF 50                      	push	ax
  2495 00001200 52                      	push	dx
  2496 00001201 53                      	push	bx
  2497 00001202 51                      	push	cx
  2498 00001203 56                      	push	si
  2499                                  
  2500 00001204 2B461C                  	sub	ax, [bp+1Ch]	; [BPB_HiddSec]
  2501 00001207 1B561E                  	sbb	dx, [bp+1Eh]	; [BPB_HiddSec+2]
  2502                                  wpc_t:
  2503 0000120A 8B0E[704A]              	mov	cx, [format_percent]
  2504 0000120E E865F6                  	call	div32
  2505                                  	; AL = percentage value between 1 to 100
  2506                                  wpc_x:
  2507 00001211 3A06[724A]              	cmp	al, [prev_percent]
  2508 00001215 741B                    	je	short wpc_y
  2509 00001217 A2[724A]                	mov	[prev_percent], al
  2510 0000121A 8B16[A63F]              	mov	dx, [Cursor_Pos]
  2511 0000121E BB0700                  	mov	bx, 7
  2512 00001221 B402                    	mov	ah, 2
  2513 00001223 CD10                    	int	10h  ; Set Cursor Position
  2514 00001225 31D2                    	xor	dx, dx
  2515 00001227 30E4                    	xor	ah, ah
  2516                                  	;mov	al, [prev_percent]
  2517 00001229 BE[5840]                	mov	si, format_percent_str + 2
  2518 0000122C E83B08                  	call	bin_to_decimal
  2519 0000122F E8B007                  	call	print_msg
  2520                                  wpc_y:
  2521 00001232 5E                      	pop	si
  2522 00001233 59                      	pop	cx
  2523 00001234 5B                      	pop	bx
  2524 00001235 5A                      	pop	dx
  2525 00001236 58                      	pop	ax
  2526 00001237 C3                      	retn
  2527                                  
  2528                                  write_format_percent_x:
  2529                                  	; AL = % number
  2530                                  
  2531 00001238 50                      	push	ax
  2532 00001239 52                      	push	dx
  2533 0000123A 53                      	push	bx
  2534 0000123B 51                      	push	cx
  2535 0000123C 56                      	push	si
  2536                                  
  2537 0000123D EBD2                    	jmp	short wpc_x
  2538                                  
  2539                                  write_fs_format_percent:
  2540                                  	; DX_AX = Current sector (which has been written)
  2541                                  
  2542 0000123F 50                      	push	ax
  2543 00001240 52                      	push	dx
  2544 00001241 53                      	push	bx
  2545 00001242 51                      	push	cx
  2546 00001243 56                      	push	si
  2547                                  
  2548 00001244 2B460C                  	sub	ax, [bp+0Ch]	; [bsBeginSector]
  2549 00001247 1B560E                  	sbb	dx, [bp+0Eh]	; [bsBeginSector+2]
  2550 0000124A EBBE                    	jmp	short wpc_t	
  2551                                  	
  2552                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2553                                  ; format error 
  2554                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2555                                  
  2556                                  formatting_error:
  2557 0000124C 8B26[744A]              	mov	sp, [old_sp]
  2558                                  
  2559 00001250 88E0                    	mov	al, ah ;  error code
  2560 00001252 E82C08                  	call	bin_to_hex
  2561 00001255 A3[7940]                	mov 	[error_code], ax
  2562                                  
  2563 00001258 BE[6240]                	mov	si, CRLF
  2564 0000125B E88407                  	call	print_msg
  2565                                  
  2566 0000125E BE[6E40]                	mov	si, Msg_Error
  2567 00001261 E87E07                  	call	print_msg
  2568 00001264 E9CDFB                  	jmp	Exit
  2569                                  
  2570                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2571                                  ; write cluster count
  2572                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2573                                  
  2574                                  write_cluster_count:
  2575 00001267 BE[3040]                	mov	si, msg_cluster_count
  2576 0000126A E87507                  	call	print_msg
  2577 0000126D A1[6A4A]                	mov	ax, [cluster_count]
  2578 00001270 8B16[6C4A]              	mov	dx, [cluster_count+2]
  2579 00001274 BE[4640]                	mov	si, cluster_count_str+6
  2580 00001277 E8F007                  	call	bin_to_decimal
  2581 0000127A E86507                  	call	print_msg
  2582 0000127D C3                      	retn 
  2583                                  
  2584                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2585                                  ; FAT16 FORMATTING
  2586                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2587                                  
  2588                                  FAT16_hdi_format:
  2589                                  
  2590 0000127E B80607                  	mov	ax, 0706h ; db 06h, 07h ; 'push es, pop es'
  2591 00001281 38C6                    	cmp	dh, al ; 06h ; Big CHS partition (>= 32MB)
  2592 00001283 740A                    	je	short FAT16_big_chs_format
  2593 00001285 B80E07                  	mov	ax, 070Eh ; db 0Eh, 07h	; 'push cs, pop es'
  2594 00001288 38C6                    	cmp	dh, al ; 0Eh ; LBA partition
  2595 0000128A 7403                    	je	short FAT16_lba_format
  2596                                  FAT16_chs_format:  
  2597                                  	; Partition Type: 04h, CHS (<32 MB) partition
  2598 0000128C B80400                  	mov	ax, 0004h ; db 04h, 00h ; 'add al, 0'
  2599                                  FAT16_big_chs_format:
  2600                                  FAT16_lba_format:
  2601                                  	; Put TRDOS 386 FAT16 partition magic word 
  2602                                  	; at offset 3Eh, in TRDOS386 FAT16 boot sector.
  2603 0000128F BD[CE28]                	mov	bp, TRDOS_FAT16_hd_bs
  2604 00001292 8D7E03                  	lea	di, [bp+3]
  2605 00001295 BE[4544]                	mov	si, bs_oem_name
  2606 00001298 B90400                  	mov	cx, 4
  2607 0000129B F3A5                    	rep	movsw 
  2608 0000129D 89463E                  	mov	[bp+3Eh], ax	; [loc_3E]
  2609                                  
  2610 000012A0 A1[E230]                	mov	ax, [sectors]
  2611 000012A3 894618                  	mov	[bp+18h], ax	; [BPB_SecPerTrk]
  2612 000012A6 A1[E430]                	mov	ax, [heads]
  2613 000012A9 89461A                  	mov	[bp+1Ah], ax	; [BPB_NumHeads]
  2614 000012AC A1[1444]                	mov	ax, [pp_StartSector]
  2615 000012AF 89461C                  	mov	[bp+1Ch], ax	; [BPB_HiddSec]
  2616 000012B2 A1[1644]                	mov	ax, [pp_StartSector+2]
  2617 000012B5 89461E                  	mov	[bp+1Eh], ax	; [BPB_HiddSec+2]
  2618 000012B8 A1[1844]                	mov	ax, [pp_Sectors]
  2619 000012BB 8B16[1A44]              	mov	dx, [pp_Sectors+2]
  2620 000012BF 21D2                    	and	dx, dx
  2621 000012C1 7505                    	jnz	short FAT16_f_0
  2622 000012C3 894613                  	mov	[bp+13h], ax	; [BPB_TotSec16]
  2623                                  	; CX = 0
  2624                                  	;mov	[bp+20h], cx	; [BPB_TotSec32] =  0
  2625                                  	;mov	[bp+22h], cx	; [BPB_TotSec32+2] = 0
  2626 000012C6 EB06                    	jmp	short FAT16_f_1
  2627                                  FAT16_f_0:
  2628 000012C8 894620                  	mov	[bp+20h], ax	; [BPB_TotSec32]
  2629                                  	;mov	dx, [pp_Sectors+2]
  2630 000012CB 895622                  	mov	[bp+22h], dx	; [BPB_TotSec32+2]
  2631                                  	; CX = 0
  2632                                  	;mov	[bp+13h], cx ; [BPB_TotSec16] = 0
  2633                                  FAT16_f_1:
  2634                                  	; Sectors per cluster calculation
  2635                                  	; (According to MS FAT32 FS specification.)
  2636 000012CE B102                    	mov	cl, 2  ; 2 sectors per cluster
  2637 000012D0 09D2                    	or	dx, dx
  2638 000012D2 7507                    	jnz	short FAT16_f_2 ; >2 sectors (>16MB)
  2639 000012D4 3DA87F                  	cmp	ax, 32680
  2640 000012D7 763C                    	jna	short FAT16_f_10 ; 2 sectors, <=16MB
  2641                                  	; > 16MB
  2642 000012D9 EB38                    	jmp	short FAT16_f_9 ; 4 sectors per cluster
  2643                                  FAT16_f_2:
  2644 000012DB 83FA04                  	cmp	dx, 4  ; >= 262144 sectors ; >=128MB
  2645 000012DE 7708                    	ja	short FAT16_f_3 ; >4 sectors per cluster
  2646 000012E0 7231                    	jb	short FAT16_f_9 ; 4 sectors per cluster	
  2647 000012E2 09C0                    	or	ax, ax ; dx_ax = (4*65536)+0
  2648 000012E4 742D                    	jz	short FAT16_f_9 ; 4 sectors per cluster
  2649 000012E6 EB29                    	jmp	short FAT16_f_8 ; 8 sectors per cluster
  2650                                  FAT16_f_3:
  2651 000012E8 83FA08                  	cmp	dx, 8  ; >= 524288 sectors ; >=256MB
  2652 000012EB 7708                    	ja	short FAT16_f_4 ; >8 sectors per cluster
  2653 000012ED 7222                    	jb	short FAT16_f_8 ; 8 sectors per cluster	
  2654 000012EF 21C0                    	and	ax, ax ; dx_ax = (8*65536)+0
  2655 000012F1 741E                    	jz	short FAT16_f_8 ; 8 sectors per cluster
  2656 000012F3 EB1A                    	jmp	short FAT16_f_7 ; 16 sectors per cluster
  2657                                  FAT16_f_4:
  2658 000012F5 83FA10                  	cmp	dx, 16 ; >= 1048576 sectors ; >=512MB
  2659 000012F8 7708                    	ja	short FAT16_f_5 ; >16 sectors per cluster
  2660 000012FA 7213                    	jb	short FAT16_f_7 ; 16 sectors per cluster	
  2661 000012FC 21C0                    	and	ax, ax ; dx_ax = (16*65536)+0
  2662 000012FE 740F                    	jz	short FAT16_f_7 ; 16 sectors per cluster
  2663 00001300 EB0B                    	jmp	short FAT16_f_6 ; 32 sectors per cluster
  2664                                  FAT16_f_5:
  2665 00001302 83FA20                  	cmp	dx, 32 ; >= 2097152 sectors ; >=1GB
  2666 00001305 7206                    	jb	short FAT16_f_6 ; 32 sectors per cluster
  2667 00001307 09C0                    	or	ax, ax		; dx_ax = (32*65536)+0
  2668 00001309 7402                    	jz	short FAT16_f_6 ; 32 sectors per cluster
  2669                                  	; >1GB (<=2GB)
  2670                                  	; 64 sectors per cluster
  2671 0000130B D0E1                    	shl	cl, 1
  2672                                  FAT16_f_6:
  2673                                  	; 32 sectors per cluster (for <= 2GB volumes)
  2674 0000130D D0E1                    	shl	cl, 1	
  2675                                  FAT16_f_7:
  2676                                  	; 16 sectors per cluster (for <= 1GB volumes)
  2677 0000130F D0E1                    	shl	cl, 1
  2678                                  FAT16_f_8:
  2679                                  	; 8 sectors per cluster (for <= 512MB volumes)
  2680 00001311 D0E1                    	shl	cl, 1	
  2681                                  FAT16_f_9:
  2682                                  	; 4 sectors per cluster (for <= 256MB volumes)
  2683 00001313 D0E1                    	shl	cl, 1	
  2684                                  FAT16_f_10:	
  2685                                  	; 2 sectors per cluster (for <= 128MB volumes)
  2686 00001315 884E0D                  	mov	[bp+0Dh], cl	 ; [BPB_SecPerClus]
  2687                                  	;mov	byte [bp+10h], 2 ; [BPB_NumFATs] 
  2688                                  	;mov	word [bp+0Eh], 1 ; [BPB_RsvdSecCnt] 
  2689                                  	;mov	word [bp+11h], 512 ; [BPB_RootEntCnt]
  2690                                  	
  2691                                  	; Calculating FAT size in sectors
  2692                                  	; (According to MS FAT32 FS Specification, 2000)
  2693                                  
  2694                                  	; DX_AX = partition (volume) size in sectors
  2695 00001318 8B5E11                  	mov	bx, [bp+11h]	; [BPB_RootEntCnt] = 512
  2696 0000131B 83C30F                  	add	bx, 15 ; bx = 527
  2697 0000131E C1EB04                  	shr	bx, 4 ; /16 = 527/16 = 32
  2698                                  		; ((32*BX)+511)/512
  2699 00001321 891E[6E4A]              	mov	[root_dir_secs], bx
  2700 00001325 035E0E                  	add	bx, [bp+0Eh]	; [BPB_RsvdSecCnt] ; 1
  2701 00001328 29D8                    	sub	ax, bx
  2702 0000132A 83DA00                  	sbb	dx, 0
  2703                                  		; TmpVal1 = DiskSize - (BPB_ResvdSecCnt +
  2704                                  		;	     		RootDirsectors)
  2705 0000132D 89CB                    	mov	bx, cx ; ch = 0
  2706 0000132F C1E308                  	shl	bx, 8 ; * 256
  2707 00001332 B102                    	mov	cl, 2 ; [BPB_NumFATs] 
  2708 00001334 01CB                    	add	bx, cx	
  2709                                  		; TmpVal2 = (256*BPB_SecPerClus)+BPB_NumFATs
  2710 00001336 89D9                    	mov	cx, bx
  2711 00001338 4B                      	dec	bx  ; TmpVal2-1
  2712 00001339 01D8                    	add	ax, bx
  2713 0000133B 83D200                  	adc	dx, 0
  2714 0000133E E835F5                  	call	div32
  2715                                  		; FATSz = (TmpVal1+(TmpVal2-1))/TmpVal2
  2716                                  	; AX = FAT size in sectors
  2717                                  	; DX = 0
  2718 00001341 894616                  	mov	[bp+16h], ax	; [BPB_FATSz16]
  2719                                  	; * 2
  2720 00001344 D1E0                    	shl	ax, 1
  2721                                  	; AX = [BPB_NumFATs] * [BPB_FATSz32]
  2722 00001346 8B4E0E                  	mov	cx, [bp+0Eh]	; [BPB_RsvdSecCnt] ; 1
  2723 00001349 01C1                    	add	cx, ax
  2724                                  	; CX = [BPB_RsvdSecCnt]+([BPB_NumFATs]*[BPB_FATSz32])
  2725 0000134B 030E[6E4A]              	add	cx, [root_dir_secs] ; + RootDirsectors
  2726 0000134F 29DB                    	sub	bx, bx ; BX = 0
  2727                                  	; BX_CX = [BPB_RsvdSecCnt]+([BPB_NumFATs]*[BPB_FATSz32])
  2728                                  	;	  + RootDirSectors
  2729 00001351 8B4613                  	mov	ax, [bp+13h]	; [BPB_TotSec16]
  2730                                  	;sub	dx, dx 
  2731                                  	; DX = 0
  2732 00001354 21C0                    	and	ax, ax
  2733 00001356 7506                    	jnz	short FAT16_f_11
  2734 00001358 8B4620                  	mov	ax, [bp+20h]	; [BPB_TotSec32]
  2735 0000135B 8B5622                  	mov	dx, [bp+22h]	; [BPB_TotSec32+2]
  2736                                  FAT16_f_11:
  2737 0000135E 29C8                    	sub	ax, cx
  2738 00001360 19DA                    	sbb	dx, bx
  2739 00001362 890E[624A]              	mov	[data_start], cx
  2740 00001366 891E[644A]              	mov	[data_start+2], bx
  2741                                  	; DX_AX = Data sectors
  2742 0000136A A3[664A]                	mov	[data_sectors], ax
  2743 0000136D 8916[684A]              	mov	[data_sectors+2], dx
  2744 00001371 8A4E0D                  	mov	cl, [bp+0Dh]	 ; [BPB_SecPerClus]
  2745 00001374 30ED                    	xor	ch, ch
  2746 00001376 E8FDF4                  	call	div32 ; DX_AX/CX
  2747                                  	; AX = Count of clusters (rounded down)
  2748                                  	; DX = 0
  2749 00001379 A3[6A4A]                	mov	[cluster_count], ax
  2750 0000137C 8916[6C4A]              	mov	[cluster_count+2], dx
  2751                                  
  2752 00001380 8D7E2B                  	lea	di, [bp+43] ; [BS_VolLab]
  2753 00001383 E86FFD                  	call	write_volume_name
  2754 00001386 8D7627                  	lea	si, [bp+39] ; [BS_VolID]
  2755 00001389 E8C8FD                  	call	write_volume_serial
  2756 0000138C E8D8FE                  	call	write_cluster_count	
  2757                                  
  2758 0000138F E849FE                  	call	write_formatting_msg
  2759 00001392 B000                    	mov	al, 0
  2760 00001394 E8A1FE                  	call	write_format_percent_x
  2761                                  
  2762 00001397 8B461C                  	mov	ax, [bp+1Ch]	; [BPB_HiddSec]
  2763 0000139A 8B561E                  	mov	dx, [bp+1Eh]	; [BPB_HiddSec+2]
  2764                                  
  2765 0000139D 0106[624A]              	add	[data_start], ax
  2766 000013A1 1116[644A]              	adc	[data_start+2], dx
  2767                                  
  2768                                  	; DX_AX = FAT16 Boot Sector address
  2769 000013A5 BB[CE28]                	mov	bx, TRDOS_FAT16_hd_bs
  2770                                  	; ES:BX = Boot Sector Buffer
  2771 000013A8 E84606                  	call	write_hd_sector
  2772 000013AB 0F829DFE                	jc	formatting_error
  2773 000013AF E84DFE                  	call	write_format_percent
  2774 000013B2 83C001                  	add	ax, 1
  2775 000013B5 83D200                  	adc	dx, 0
  2776                                  	; write remain part of reserved sectors
  2777 000013B8 8B4E0E                  	mov	cx, [bp+0Eh] ; [BPB_RsvdSecCnt]
  2778 000013BB 83E901                  	sub	cx, 1
  2779 000013BE 7618                    	jna	short FAT16_f_13
  2780                                  FAT16_f_12:
  2781 000013C0 51                      	push	cx
  2782 000013C1 BB[6248]                	mov	bx, HDFORMAT_EMPTY_BUFF
  2783 000013C4 E82A06                  	call	write_hd_sector
  2784 000013C7 0F8281FE                	jc	formatting_error
  2785 000013CB E831FE                  	call	write_format_percent
  2786 000013CE 83C001                  	add	ax, 1
  2787 000013D1 83D200                  	adc	dx, 0
  2788 000013D4 59                      	pop	cx
  2789 000013D5 49                      	dec	cx ; dec cl
  2790 000013D6 75E8                    	jnz	short FAT16_f_12
  2791                                  FAT16_f_13:
  2792                                  	; write FAT sectors
  2793 000013D8 8B0E[624A]              	mov	cx, [data_start] ; lba/abs addr
  2794 000013DC 8B1E[644A]              	mov	bx, [data_start+2] ; lba/abs addr
  2795 000013E0 53                      	push	bx
  2796 000013E1 51                      	push	cx
  2797 000013E2 BB[6248]                	mov	bx, HDFORMAT_FATBUFFER
  2798                                  	; ES:BX = FAT Sector Buffer
  2799 000013E5 8A4E15                  	mov	cl, [bp+15h] ; [BPB_Media]
  2800 000013E8 B5FF                    	mov	ch, 0FFh
  2801 000013EA 890F                    	mov	[bx], cx ; 0FFF8h
  2802 000013EC 88E9                    	mov	cl, ch ; cx = 0FFFFh
  2803 000013EE 894F02                  	mov	[bx+2], cx
  2804                                  	;inc	cx
  2805 000013F1 E8FD05                  	call	write_hd_sector
  2806 000013F4 0F8254FE                	jc	formatting_error
  2807 000013F8 E804FE                  	call	write_format_percent
  2808                                  	;mov	bx, HDFORMAT_FATBUFFER
  2809 000013FB B90000                  	mov	cx, 0
  2810 000013FE 890F                    	mov	[bx], cx
  2811 00001400 894F02                  	mov	[bx+2], cx
  2812 00001403 EB0F                    	jmp	short FAT16_f_15
  2813                                  FAT16_f_14:	
  2814 00001405 53                      	push	bx
  2815 00001406 51                      	push	cx	
  2816 00001407 BB[6248]                	mov	bx, HDFORMAT_FATBUFFER
  2817 0000140A E8E405                  	call	write_hd_sector
  2818 0000140D 0F823BFE                	jc	formatting_error
  2819 00001411 E8EBFD                  	call	write_format_percent
  2820                                  FAT16_f_15:	
  2821 00001414 59                      	pop	cx
  2822 00001415 5B                      	pop	bx
  2823 00001416 83C001                  	add	ax, 1
  2824 00001419 83D200                  	adc	dx, 0
  2825 0000141C 39DA                    	cmp	dx, bx
  2826 0000141E 72E5                    	jb	short FAT16_f_14
  2827 00001420 39C8                    	cmp	ax, cx
  2828 00001422 72E1                    	jb	short FAT16_f_14
  2829                                  
  2830                                  	; write	root directory sectors
  2831                                  	; as empty sectors
  2832 00001424 8B0E[6E4A]              	mov	cx, [root_dir_secs]
  2833                                  FAT16_f_16:
  2834 00001428 51                      	push	cx
  2835 00001429 BB[6248]                	mov	bx, HDFORMAT_EMPTY_BUFF
  2836 0000142C E8C205                  	call	write_hd_sector
  2837 0000142F 0F8219FE                	jc	formatting_error
  2838 00001433 E8C9FD                  	call	write_format_percent
  2839 00001436 83C001                  	add	ax, 1
  2840 00001439 83D200                  	adc	dx, 0
  2841 0000143C 59                      	pop	cx
  2842 0000143D 49                      	dec	cx
  2843 0000143E 75E8                    	jnz	short FAT16_f_16	
  2844                                  
  2845                                  	; write DATA sectors 
  2846                                  	; (after root directory sectors)
  2847 00001440 8B0E[664A]              	mov	cx, [data_sectors]
  2848 00001444 8B1E[684A]              	mov	bx, [data_sectors+2]
  2849                                  FAT16_f_17:	
  2850 00001448 53                      	push	bx
  2851 00001449 51                      	push	cx	
  2852 0000144A BB[6244]                	mov	bx, HDFORMAT_SECBUFFER
  2853 0000144D E8A105                  	call	write_hd_sector
  2854 00001450 0F82F8FD                	jc	formatting_error
  2855 00001454 E8A8FD                  	call	write_format_percent
  2856 00001457 59                      	pop	cx
  2857 00001458 5B                      	pop	bx
  2858 00001459 83C001                  	add	ax, 1
  2859 0000145C 83D200                  	adc	dx, 0
  2860 0000145F 49                      	dec	cx
  2861 00001460 75E6                    	jnz	short FAT16_f_17
  2862 00001462 4B                      	dec	bx
  2863 00001463 75E3                    	jnz	short FAT16_f_17
  2864                                  
  2865                                  	; If there are, format remain sectors which are
  2866                                  	; at beyond of data clusters, with zero bytes.
  2867                                  	
  2868 00001465 8B4E1C                  	mov	cx, [bp+1Ch]	; [BPB_HiddSec]
  2869 00001468 8B5E1E                  	mov	bx, [bp+1Eh]	; [BPB_HiddSec+2]
  2870                                  
  2871 0000146B 837E1300                	cmp	word [bp+13h], 0 ; [BPB_TotSec16]
  2872 0000146F 0F8449FC                	jz	FAT16_f_18
  2873 00001473 034E13                  	add	cx, [bp+13h]	; [BPB_TotSec16]
  2874 00001476 83D300                  	adc	bx, 0
  2875 00001479 E946FC                  	jmp	FAT16_f_19
  2876                                  
  2877                                  FAT12_hdi_format:
  2878 0000147C BD[CE2A]                	mov	bp, TRDOS_FAT12_hd_bs
  2879 0000147F 8D7E03                  	lea	di, [bp+3]
  2880 00001482 BE[4544]                	mov	si, bs_oem_name
  2881 00001485 B90400                  	mov	cx, 4
  2882 00001488 F3A5                    	rep	movsw 
  2883 0000148A A1[E230]                	mov	ax, [sectors]
  2884 0000148D 894618                  	mov	[bp+18h], ax	; [BPB_SecPerTrk]
  2885 00001490 A1[E430]                	mov	ax, [heads]
  2886 00001493 89461A                  	mov	[bp+1Ah], ax	; [BPB_NumHeads]
  2887 00001496 A1[1444]                	mov	ax, [pp_StartSector]
  2888 00001499 89461C                  	mov	[bp+1Ch], ax	; [BPB_HiddSec]
  2889 0000149C A1[1644]                	mov	ax, [pp_StartSector+2]
  2890 0000149F 89461E                  	mov	[bp+1Eh], ax	; [BPB_HiddSec+2]
  2891 000014A2 A1[1844]                	mov	ax, [pp_Sectors]
  2892 000014A5 894613                  	mov	[bp+13h], ax	; [BPB_TotSec16]
  2893                                  
  2894                                  	; Sectors per cluster calculation
  2895                                  	; (According to MS FAT32 FS specification.)
  2896 000014A8 B101                    	mov	cl, 1  ; 1 sector per cluster
  2897                                  FAT12_f_0:
  2898 000014AA 3DF50F                  	cmp	ax, 4085 ; Max. cluster count for FAT12
  2899 000014AD 7206                    	jb	short FAT12_f_1
  2900 000014AF D0E1                    	shl	cl, 1 ; *2
  2901 000014B1 D1E8                    	shr	ax, 1 ; /2
  2902 000014B3 EBF5                    	jmp	short FAT12_f_0
  2903                                  FAT12_f_1:
  2904 000014B5 884E0D                  	mov	[bp+0Dh], cl	 ; [BPB_SecPerClus]
  2905                                  	;mov	byte [bp+10h], 2 ; [BPB_NumFATs] 
  2906                                  	;mov	word [bp+0Eh], 1 ; [BPB_RsvdSecCnt] 
  2907                                  	;mov	word [bp+11h], 512 ; [BPB_RootEntCnt]
  2908                                  	
  2909                                  	; Calculating FAT size in sectors
  2910                                  	; AX = partition (volume) size in sectors
  2911                                  	; CX = sectors per clusters
  2912 000014B8 31D2                    	xor	dx, dx
  2913 000014BA F7F1                    	div	cx
  2914                                  	; AX = cluster count (only for FAT size calc)
  2915                                  	; DX = 0
  2916 000014BC 83C002                  	add	ax, 2  ; cluster 2 to ...
  2917 000014BF 89C2                    	mov	dx, ax
  2918 000014C1 D1E2                    	shl	dx, 1
  2919 000014C3 01D0                    	add	ax, dx ; *3
  2920 000014C5 D1E8                    	shr	ax, 1  ; /2
  2921 000014C7 83D000                  	adc	ax, 0  ; +0.5 -> +1	
  2922                                  
  2923                                  	; AX = FAT bytes for 12 bit cluster numbers
  2924 000014CA B90002                  	mov	cx, 512		; [BPB_BytesPerSec]
  2925 000014CD 01C8                    	add	ax, cx		
  2926 000014CF 48                      	dec	ax		; [BPB_BytesPerSec] - 1
  2927 000014D0 29D2                    	sub	dx, dx
  2928 000014D2 F7F1                    	div	cx
  2929 000014D4 894616                  	mov	[bp+16h], ax	; [BPB_FATSz16]
  2930                                  	; * 2
  2931 000014D7 D1E0                    	shl	ax, 1
  2932                                  	; AX = [BPB_NumFATs] * [BPB_FATSz32]
  2933 000014D9 8B4E0E                  	mov	cx, [bp+0Eh]	; [BPB_RsvdSecCnt] ; 1
  2934 000014DC 01C1                    	add	cx, ax
  2935 000014DE 8B4611                  	mov	ax, [bp+11h]	; [BPB_RootEntCnt] = 512
  2936 000014E1 83C00F                  	add	ax, 15	; (16-1) (512-1)
  2937 000014E4 C1E804                  	shr	ax, 4	; /16  (*32/512)
  2938                                  	; AX = Root dir sectors
  2939                                  	; CX = [BPB_RsvdSecCnt]+([BPB_NumFATs]*[BPB_FATSz32])
  2940 000014E7 01C1                    	add	cx, ax ; + RootDirsectors
  2941 000014E9 A3[6E4A]                	mov	[root_dir_secs], ax
  2942                                  	; CX = [BPB_RsvdSecCnt]+([BPB_NumFATs]*[BPB_FATSz32])
  2943                                  	;	  + RootDirSectors
  2944 000014EC 8B4613                  	mov	ax, [bp+13h]	; [BPB_TotSec16]
  2945 000014EF 29C8                    	sub	ax, cx
  2946 000014F1 31D2                    	xor	dx, dx
  2947 000014F3 890E[624A]              	mov	[data_start], cx
  2948 000014F7 8916[644A]              	mov	[data_start+2], dx ; 0
  2949                                  	; DX_AX = Data sectors
  2950 000014FB A3[664A]                	mov	[data_sectors], ax
  2951 000014FE 8916[684A]              	mov	[data_sectors+2], dx ; 0
  2952 00001502 8A4E0D                  	mov	cl, [bp+0Dh]	 ; [BPB_SecPerClus]
  2953 00001505 28ED                    	sub	ch, ch
  2954 00001507 F7F1                    	div	cx
  2955                                  	; AX = Count of clusters (rounded down)
  2956 00001509 29D2                    	sub	dx, dx ; 0
  2957 0000150B A3[6A4A]                	mov	[cluster_count], ax
  2958 0000150E 8916[6C4A]              	mov	[cluster_count+2], dx ; 0
  2959                                  
  2960 00001512 8D7E2B                  	lea	di, [bp+43] ; [BS_VolLab]
  2961 00001515 E8DDFB                  	call	write_volume_name
  2962 00001518 8D7627                  	lea	si, [bp+39] ; [BS_VolID]
  2963 0000151B E836FC                  	call	write_volume_serial
  2964 0000151E E846FD                  	call	write_cluster_count	
  2965                                  
  2966 00001521 E8B7FC                  	call	write_formatting_msg
  2967 00001524 B000                    	mov	al, 0
  2968 00001526 E80FFD                  	call	write_format_percent_x
  2969                                  
  2970 00001529 8B461C                  	mov	ax, [bp+1Ch]	; [BPB_HiddSec]
  2971 0000152C 8B561E                  	mov	dx, [bp+1Eh]	; [BPB_HiddSec+2]
  2972                                  
  2973 0000152F 0106[624A]              	add	[data_start], ax
  2974 00001533 1116[644A]              	adc	[data_start+2], dx
  2975                                  
  2976                                  	; DX_AX = FAT12 Boot Sector address
  2977 00001537 BB[CE2A]                	mov	bx, TRDOS_FAT12_hd_bs
  2978                                  	; ES:BX = Boot Sector Buffer
  2979 0000153A E8B404                  	call	write_hd_sector
  2980 0000153D 0F820BFD                	jc	formatting_error
  2981 00001541 E8BBFC                  	call	write_format_percent
  2982 00001544 83C001                  	add	ax, 1
  2983 00001547 83D200                  	adc	dx, 0
  2984                                  	; write remain part of reserved sectors
  2985 0000154A 8B4E0E                  	mov	cx, [bp+0Eh] ; [BPB_RsvdSecCnt]
  2986 0000154D 83E901                  	sub	cx, 1
  2987 00001550 7618                    	jna	short FAT12_f_3
  2988                                  FAT12_f_2:
  2989 00001552 51                      	push	cx
  2990 00001553 BB[6248]                	mov	bx, HDFORMAT_EMPTY_BUFF
  2991 00001556 E89804                  	call	write_hd_sector
  2992 00001559 0F82EFFC                	jc	formatting_error
  2993 0000155D E89FFC                  	call	write_format_percent
  2994 00001560 83C001                  	add	ax, 1
  2995 00001563 83D200                  	adc	dx, 0
  2996 00001566 59                      	pop	cx
  2997 00001567 49                      	dec	cx ; dec cl
  2998 00001568 75E8                    	jnz	short FAT12_f_2
  2999                                  FAT12_f_3:
  3000                                  	; write FAT sectors
  3001 0000156A 8B0E[624A]              	mov	cx, [data_start] ; lba/abs addr
  3002 0000156E 8B1E[644A]              	mov	bx, [data_start+2] ; lba/abs addr
  3003 00001572 53                      	push	bx
  3004 00001573 51                      	push	cx
  3005 00001574 BB[6248]                	mov	bx, HDFORMAT_FATBUFFER
  3006                                  	; ES:BX = FAT Sector Buffer
  3007 00001577 8A4E15                  	mov	cl, [bp+15h] ; [BPB_Media]
  3008 0000157A B5FF                    	mov	ch, 0FFh
  3009 0000157C 890F                    	mov	[bx], cx ; 0FFF8h
  3010 0000157E 886F02                  	mov	[bx+2], ch ; 0FFFFF8h
  3011                                  	;xor	cx, cx
  3012 00001581 E86D04                  	call	write_hd_sector
  3013 00001584 0F82C4FC                	jc	formatting_error
  3014 00001588 E874FC                  	call	write_format_percent
  3015                                  	;mov	bx, HDFORMAT_FATBUFFER
  3016 0000158B B90000                  	mov	cx, 0
  3017 0000158E 890F                    	mov	[bx], cx
  3018 00001590 884F02                  	mov	[bx+2], cl
  3019 00001593 EB0F                    	jmp	short FAT12_f_5
  3020                                  FAT12_f_4:	
  3021 00001595 53                      	push	bx
  3022 00001596 51                      	push	cx	
  3023 00001597 BB[6248]                	mov	bx, HDFORMAT_FATBUFFER
  3024 0000159A E85404                  	call	write_hd_sector
  3025 0000159D 0F82ABFC                	jc	formatting_error
  3026 000015A1 E85BFC                  	call	write_format_percent
  3027                                  FAT12_f_5:	
  3028 000015A4 59                      	pop	cx
  3029 000015A5 5B                      	pop	bx
  3030 000015A6 83C001                  	add	ax, 1
  3031 000015A9 83D200                  	adc	dx, 0
  3032 000015AC 39DA                    	cmp	dx, bx
  3033 000015AE 72E5                    	jb	short FAT12_f_4
  3034 000015B0 39C8                    	cmp	ax, cx
  3035 000015B2 72E1                    	jb	short FAT12_f_4
  3036                                  
  3037                                  	; write	root directory sectors
  3038                                  	; as empty sectors
  3039 000015B4 8B0E[6E4A]              	mov	cx, [root_dir_secs]
  3040                                  FAT12_f_6:
  3041 000015B8 51                      	push	cx
  3042 000015B9 BB[6248]                	mov	bx, HDFORMAT_EMPTY_BUFF
  3043 000015BC E83204                  	call	write_hd_sector
  3044 000015BF 0F8289FC                	jc	formatting_error
  3045 000015C3 E839FC                  	call	write_format_percent
  3046 000015C6 83C001                  	add	ax, 1
  3047 000015C9 83D200                  	adc	dx, 0
  3048 000015CC 59                      	pop	cx
  3049 000015CD 49                      	dec	cx ; dec cl
  3050 000015CE 75E8                    	jnz	short FAT12_f_6
  3051                                  
  3052                                  	; write DATA sectors 
  3053                                  	; (after root directory sectors)
  3054 000015D0 8B0E[664A]              	mov	cx, [data_sectors]
  3055                                  	;mov	bx, [data_sectors+2]
  3056                                  FAT12_f_7:	
  3057                                  	;push	bx
  3058 000015D4 51                      	push	cx	
  3059 000015D5 BB[6244]                	mov	bx, HDFORMAT_SECBUFFER
  3060 000015D8 E81604                  	call	write_hd_sector
  3061 000015DB 0F826DFC                	jc	formatting_error
  3062 000015DF E81DFC                  	call	write_format_percent
  3063 000015E2 59                      	pop	cx
  3064                                  	;pop	bx
  3065 000015E3 83C001                  	add	ax, 1
  3066 000015E6 83D200                  	adc	dx, 0
  3067 000015E9 49                      	dec	cx
  3068 000015EA 75E8                    	jnz	short FAT12_f_7
  3069                                  	;dec	bx
  3070                                  	;jnz	short FAT12_f_7
  3071                                  
  3072                                  	; If there are, format remain sectors which are
  3073                                  	; at beyond of data clusters, with zero bytes.
  3074                                  	
  3075 000015EC 8B4E1C                  	mov	cx, [bp+1Ch]	; [BPB_HiddSec]
  3076 000015EF 8B5E1E                  	mov	bx, [bp+1Eh]	; [BPB_HiddSec+2]
  3077                                  
  3078 000015F2 034E13                  	add	cx, [bp+13h]	; [BPB_TotSec16]
  3079 000015F5 83D300                  	adc	bx, 0
  3080 000015F8 E9C7FA                  	jmp	FAT12_f_8
  3081                                  
  3082                                  
  3083                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3084                                  ; SINGLIX FS FORMATTING
  3085                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3086                                  
  3087                                  SINGLIX_hdi_format:
  3088                                  	; 06/01/2018
  3089                                  	; 05/01/2018
  3090                                  	; If Sectors/Track = 17, use CHS+LBA type boot sector
  3091 000015FB 8B1E[E230]              	mov	bx, [sectors]
  3092 000015FF 83FB11                  	cmp	bx, 17
  3093 00001602 7711                    	ja	short SINGLIX_fs1_f_1
  3094                                  SINGLIX_fs1_f_0:
  3095 00001604 BD[CE2C]                	mov	bp, TRDOS_TRFS1_chs_bs
  3096 00001607 887E2D                  	mov	[bp+45], bh ; 0 ; [bs_LBA_Ready] = 0
  3097 0000160A 885E2E                  	mov	[bp+46], bl	; [bs_Disk_SecPerTrack]
  3098 0000160D A0[E430]                	mov	al, [heads]
  3099 00001610 88462F                  	mov	[bp+47], al	; [bs_Disk_Heads]
  3100 00001613 EB15                    	jmp	short SINGLIX_fs1_f_3
  3101                                  SINGLIX_fs1_f_1:
  3102                                  	; Sectors per Track = 63
  3103                                  	; If disk capacity >= 63*16*1024 use LBA type boot sector
  3104 00001615 8B0E[E430]              	mov	cx, [heads]
  3105 00001619 A1[E630]                	mov	ax, [cylinders]
  3106 0000161C F7E1                    	mul	cx
  3107 0000161E 21D2                    	and	dx, dx
  3108 00001620 7505                    	jnz	short SINGLIX_fs1_f_2
  3109 00001622 3D0040                  	cmp	ax, 16384
  3110 00001625 72DD                    	jb	short SINGLIX_fs1_f_0
  3111                                  SINGLIX_fs1_f_2:	
  3112 00001627 BD[CE2E]                	mov	bp, TRDOS_TRFS1_lba_bs
  3113                                  	;mov	byte [bp+45], 1 ; [bs_LBA_Ready] = 1
  3114                                  SINGLIX_fs1_f_3:	
  3115 0000162A A1[1844]                	mov	ax, [pp_Sectors]
  3116 0000162D 8B16[1A44]              	mov	dx, [pp_Sectors+2]
  3117 00001631 894610                  	mov	[bp+16], ax	; [bsVolumeSize]
  3118 00001634 895612                  	mov	[bp+18], dx	; [bsVolumeSize+2]
  3119 00001637 8B0E[1444]              	mov	cx, [pp_StartSector]
  3120 0000163B 8B1E[1644]              	mov	bx, [pp_StartSector+2]
  3121 0000163F 894E0C                  	mov	[bp+12], cx	; [bsBeginSector]
  3122 00001642 895E0E                  	mov	[bp+14], bx	; [bsBeginSector+2]
  3123 00001645 C6462C80                	mov	byte [bp+44], 80h ; [bsDriveNumber]  ; hd0
  3124                                  
  3125                                  	; Prepare MAT
  3126 00001649 A3[C64A]                	mov	[MAT_VolumeSize], ax ; Total Sectors of the FS
  3127 0000164C 8916[C84A]              	mov	[MAT_VolumeSize+2], dx
  3128 00001650 890E[CA4A]              	mov	[MAT_BeginSector], cx ; Beginning Sector of the FS
  3129 00001654 891E[CC4A]              	mov	[MAT_BeginSector+2], bx
  3130                                  	;mov	cx, [bp+24]	; [bsMATLocation]
  3131                                  	;mov	bx, [bp+26]	; [bsMATLocation+2]
  3132                                  	;add	cx, 1
  3133                                  	;adc	bx, 0
  3134                                  	; Note: (as Default) MAT Address = 1, DAT Address = 2 
  3135 00001658 B90200                  	mov	cx, 2
  3136                                  	;xor	bx, bx ; 0
  3137                                  	;mov	[bp+24], cx	; [bsMATLocation]
  3138                                  	;mov	[bp+26], bx	; [bsMATLocation+2]
  3139 0000165B 890E[CE4A]              	mov	[DAT_Address], cx
  3140                                  	;mov	[DAT_Address+2], bx
  3141                                  	; DX_AX = FS1 Volume Size
  3142 0000165F 83C007                  	add	ax, 7 ; 7 bits more (for round up)
  3143 00001662 83D200                  	adc	dx, 0
  3144 00001665 B90800                  	mov	cx, 8 ;  1 DAT byte == 8 sectors 
  3145 00001668 E80BF2                  	call	div32
  3146                                  	; DX_AX = DAT bytes
  3147 0000166B B9FF01                  	mov	cx, 511
  3148 0000166E 01C8                    	add	ax, cx
  3149 00001670 83D200                  	adc	dx, 0
  3150 00001673 41                      	inc	cx ; 512
  3151 00001674 E8FFF1                  	call	div32
  3152                                  	; DX_AX = DAT sectors (DX must be 0 for volume sizes < 128GB)
  3153 00001677 A3[D24A]                	mov	[DAT_SectorCount], ax
  3154                                  	;mov	[DAT_SectorCount+2], dx ; 0
  3155                                  
  3156 0000167A 83C002                  	add	ax, 2  ; BS + MAT
  3157                                  	;adc	dx, 0
  3158 0000167D 89461C                  	mov	[bp+28], ax  ; [bsRootDirDT] ; RDT address (offset)
  3159                                  	;mov	[bp+30], dx
  3160                                  
  3161                                  	; Free Sectors = Total Sectors - (BS+MAT+DATsects+RDT+4)	 
  3162 00001680 83C005                  	add	ax, 5 ; DATsects + (BS+MAT+RDT+4)
  3163 00001683 89C2                    	mov	dx, ax
  3164 00001685 8B0E[C64A]              	mov	cx, [MAT_VolumeSize]
  3165 00001689 8B1E[C84A]              	mov	bx, [MAT_VolumeSize+2]
  3166 0000168D 29C1                    	sub	cx, ax
  3167 0000168F 83DB00                  	sbb	bx, 0
  3168 00001692 890E[D64A]              	mov	[MAT_FreeSectors], cx
  3169 00001696 891E[D84A]              	mov	[MAT_FreeSectors+2], bx
  3170 0000169A A3[DA4A]                	mov	[MAT_FirstFreeSector], ax
  3171                                  	;mov	word [MAT_FirstFreesector+2] , 0
  3172                                  
  3173 0000169D BF[764A]                	mov	di, fs_volume_name
  3174 000016A0 E84BFA                  	call	write_fs_volume_name
  3175 000016A3 BE[B64A]                	mov	si, fs_volume_serial
  3176 000016A6 E8ABFA                  	call	write_volume_serial
  3177                                  
  3178                                  	; Modify FS volume name
  3179                                  	; (Convert 20h tail bytes to 0)
  3180 000016A9 B94000                  	mov	cx, 64 
  3181 000016AC BE[764A]                	mov	si, fs_volume_name
  3182 000016AF 31DB                    	xor	bx, bx
  3183 000016B1 B0FF                    	mov	al, 0FFh
  3184                                  modify_fs_vname_1:	
  3185 000016B3 88C4                    	mov	ah, al
  3186 000016B5 AC                      	lodsb
  3187 000016B6 3C20                    	cmp	al, 20h
  3188 000016B8 7708                    	ja	short modify_fs_vname_2
  3189 000016BA 80FC20                  	cmp	ah, 20h
  3190 000016BD 7603                    	jna	short modify_fs_vname_2
  3191 000016BF 89F3                    	mov	bx, si
  3192 000016C1 4B                      	dec	bx
  3193                                  modify_fs_vname_2:
  3194 000016C2 E2EF                    	loop	modify_fs_vname_1		
  3195 000016C4 09DB                    	or	bx, bx
  3196 000016C6 740B                    	jz	short modify_fs_vname_3
  3197 000016C8 89DF                    	mov	di, bx
  3198 000016CA B9[B64A]                	mov	cx, fs_volume_name+64
  3199 000016CD 29D9                    	sub	cx, bx
  3200 000016CF 30C0                    	xor	al, al
  3201 000016D1 F3AA                    	rep	stosb 
  3202                                  
  3203                                  modify_fs_vname_3:
  3204 000016D3 E805FB                  	call	write_formatting_msg
  3205 000016D6 B000                    	mov	al, 0
  3206 000016D8 E85DFB                  	call	write_format_percent_x
  3207                                  
  3208 000016DB 8B460C                  	mov	ax, [bp+12]	; [bsBeginSector]
  3209 000016DE 8B560E                  	mov	dx, [bp+14]	; [bsBeginSector+2]
  3210                                  
  3211                                  	; DX_AX = TRFS1 Boot Sector address
  3212 000016E1 89EB                    	mov	bx, bp
  3213                                  	; ES:BX = Boot Sector Buffer
  3214 000016E3 E80B03                  	call	write_hd_sector
  3215 000016E6 0F8262FB                	jc	formatting_error
  3216                                  	
  3217 000016EA 83C001                  	add	ax, 1
  3218 000016ED 83D200                  	adc	dx, 0
  3219                                  
  3220                                  	; DX_AX = MAT (DAT header) sector address
  3221 000016F0 BB[C24A]                	mov	bx, FS_MAT_Buffer
  3222 000016F3 E8FB02                  	call	write_hd_sector
  3223 000016F6 0F8252FB                	jc	formatting_error
  3224 000016FA E842FB                  	call	write_fs_format_percent
  3225                                  
  3226                                  	; Calculate DAT bits 
  3227                                  	; NOTE: 4096 bits per DAT sector
  3228 000016FD A1[DA4A]                	mov	ax, [MAT_FirstFreeSector]
  3229                                  	;mov	dx, [MAT_FirstFreeSector+2]
  3230 00001700 31D2                    	xor	dx, dx
  3231 00001702 52                      	push	dx
  3232 00001703 50                      	push	ax
  3233 00001704 B90010                  	mov	cx, 4096
  3234 00001707 E86CF1                  	call	div32
  3235 0000170A 891E[BA4A]              	mov	[DAT_FFBit], bx
  3236 0000170E A3[BC4A]                	mov	[DAT_FFSector], ax
  3237 00001711 58                      	pop	ax
  3238 00001712 5A                      	pop	dx
  3239 00001713 83E801                  	sub	ax, 1
  3240 00001716 83DA00                  	sbb	dx, 0
  3241 00001719 0306[D64A]              	add	ax, [MAT_FreeSectors]
  3242 0000171D 1316[D84A]              	adc	dx, [MAT_FreeSectors+2]
  3243 00001721 E852F1                  	call	div32
  3244 00001724 891E[BE4A]              	mov	[DAT_LFBit], bx
  3245 00001728 A3[C04A]                	mov	[DAT_LFSector], ax
  3246                                  
  3247 0000172B 31F6                    	xor	si, si ; 0
  3248                                  SINGLIX_fs1_f_4:
  3249                                  	; calculate free bits for current DAT sector
  3250                                  	;			(to be written)
  3251 0000172D BF[DE4A]                	mov	di, FS_DAT_Buffer
  3252 00001730 3B36[BC4A]              	cmp	si, [DAT_FFSector]
  3253 00001734 7431                    	je	short SINGLIX_fs1_f_7
  3254 00001736 724D                    	jb	short SINGLIX_fs1_f_9
  3255 00001738 3B36[C04A]              	cmp	si, [DAT_LFSector]
  3256 0000173C 7224                    	jb	short SINGLIX_fs1_f_6
  3257 0000173E 7745                    	ja	short SINGLIX_fs1_f_9
  3258 00001740 8B1E[BE4A]              	mov	bx, [DAT_LFBit]
  3259 00001744 B0FF                    	mov	al, 0FFh
  3260 00001746 88DC                    	mov	ah, bl
  3261 00001748 C1EB03                  	shr	bx, 3 ; bit count to byte count
  3262 0000174B 7409                    	jz	short SINGLIX_fs1_f_5
  3263 0000174D 89D9                    	mov	cx, bx
  3264 0000174F F3AA                    	rep	stosb
  3265 00001751 BF[DE4A]                	mov	di, FS_DAT_Buffer
  3266 00001754 01DF                    	add	di, bx
  3267                                  SINGLIX_fs1_f_5:
  3268 00001756 80E407                  	and	ah, 7
  3269 00001759 88E1                    	mov	cl, ah 
  3270 0000175B D2E0                    	shl	al, cl
  3271 0000175D F6D0                    	not	al
  3272 0000175F AA                      	stosb
  3273                                  	;mov	cx, 511
  3274                                  	;sub	cx, bx
  3275                                  	;jna	short SINGLIX_fs1_f_9
  3276                                  	;mov	al, 0 ; out of volume bits (=0)
  3277                                  	;rep	stosb
  3278 00001760 EB23                    	jmp	short SINGLIX_fs1_f_9
  3279                                  SINGLIX_fs1_f_6:
  3280 00001762 B90002                  	mov	cx, 512
  3281 00001765 EB1A                    	jmp	short SINGLIX_fs1_f_8
  3282                                  SINGLIX_fs1_f_7:
  3283 00001767 8B1E[BA4A]              	mov	bx, [DAT_FFBit]
  3284 0000176B 88D9                    	mov	cl, bl
  3285 0000176D 80E107                  	and	cl, 7
  3286 00001770 C1EB03                  	shr	bx, 3 ; from bits to bytes
  3287 00001773 01DF                    	add	di, bx
  3288 00001775 B0FF                    	mov	al, 0FFh
  3289 00001777 D2E0                    	shl	al, cl
  3290 00001779 AA                      	stosb
  3291 0000177A B9FF01                  	mov	cx, 511
  3292 0000177D 29D9                    	sub	cx, bx
  3293 0000177F 7604                    	jna	short SINGLIX_fs1_f_9
  3294                                  SINGLIX_fs1_f_8:
  3295 00001781 B0FF                    	mov	al, 0FFh ; Free sector bits (=1)
  3296 00001783 F3AA                    	rep	stosb
  3297                                  SINGLIX_fs1_f_9:
  3298 00001785 A1[CA4A]                	mov	ax, [MAT_BeginSector]
  3299 00001788 8B16[CC4A]              	mov	dx, [MAT_BeginSector+2]
  3300                                  	;add	ax, [DAT_Address] ; = 2
  3301                                  	;adc	dx, [DAT_Address+2]
  3302 0000178C 83C002                  	add	ax, 2
  3303 0000178F 83D200                  	adc	dx, 0
  3304 00001792 01F0                    	add	ax, si
  3305 00001794 83D200                  	adc	dx, 0
  3306                                  	; Write DAT sector(s)
  3307                                  	; DX_AX = Disk Allocation Table sector address
  3308 00001797 BB[DE4A]                	mov	bx, FS_DAT_Buffer
  3309 0000179A E85402                  	call	write_hd_sector
  3310 0000179D 0F82ABFA                	jc	formatting_error
  3311 000017A1 E89BFA                  	call	write_fs_format_percent
  3312                                  	; Clear DAT buffer again (for next stage)
  3313 000017A4 B90001                  	mov	cx, 256
  3314 000017A7 BF[DE4A]                	mov	di, FS_DAT_Buffer
  3315 000017AA 29C0                    	sub	ax, ax
  3316 000017AC F3AB                    	rep	stosw
  3317                                  
  3318 000017AE 46                      	inc	si
  3319                                  
  3320 000017AF 3B36[D24A]              	cmp	si, [DAT_SectorCount]
  3321 000017B3 0F8676FF                	jna	SINGLIX_fs1_f_4
  3322                                  
  3323                                  	; ;;;
  3324                                  	
  3325                                  	; DAT sectors has been written..
  3326                                  	; Now, Root Directory Description Table is in order
  3327                                  
  3328 000017B7 BF[DE4A]                	mov	di, FS_RDT_Buffer
  3329 000017BA B84444                  	mov	ax, 'DD' 
  3330 000017BD AB                      	stosw
  3331 000017BE 30E4                    	xor	ah, ah
  3332 000017C0 B054                    	mov	al, 'T'
  3333 000017C2 AB                      	stosw
  3334 000017C3 B80002                  	mov	ax, 512 ; Sector size (Bytes per sector)	
  3335 000017C6 AB                      	stosw
  3336 000017C7 31C0                    	xor	ax, ax ; RDT sequence number (= 0, section 1)
  3337 000017C9 AB                      	stosw	
  3338                                  	; RDT address
  3339 000017CA A1[D24A]                	mov	ax, [DAT_SectorCount]
  3340 000017CD 8B16[D44A]              	mov	dx, [DAT_SectorCount+2]
  3341 000017D1 83C002                  	add	ax, 2 ; BS + MAT
  3342 000017D4 83D200                  	adc	dx, 0
  3343 000017D7 AB                      	stosw
  3344 000017D8 89D0                    	mov	ax, dx
  3345 000017DA AB                      	stosw
  3346 000017DB 29C0                    	sub	ax, ax ; Next RDT number
  3347 000017DD AB                      	stosw
  3348 000017DE AB                      	stosw
  3349 000017DF B80400                  	mov	ax, 4 ; Sector count of this section	
  3350                                  		      ; (4*512)/4 = 512 root dir entries
  3351 000017E2 AB                      	stosw
  3352 000017E3 30C0                    	xor	al, al
  3353 000017E5 AB                      	stosw
  3354                                  	; Volume beginning sector
  3355 000017E6 8B460C                  	mov	ax, [bp+12]	; [bsBeginSector]
  3356 000017E9 8B560E                  	mov	dx, [bp+14]	; [bsBeginSector+2]
  3357 000017EC AB                      	stosw
  3358 000017ED 89D0                    	mov	ax, dx
  3359 000017EF AB                      	stosw
  3360 000017F0 31C0                    	xor	ax, ax
  3361 000017F2 48                      	dec	ax ; 0FFFFh
  3362                                  	; Parent Dir Serial (= FFFFFFFFh for root dir)
  3363 000017F3 AB                      	stosw
  3364 000017F4 AB                      	stosw
  3365                                  
  3366                                  set_fs_volume_serial_number:
  3367 000017F5 BE[B64A]                	mov	si, fs_volume_serial
  3368 000017F8 A5                      	movsw
  3369 000017F9 A5                      	movsw
  3370                                  
  3371 000017FA 29C0                    	sub	ax, ax
  3372 000017FC AA                      	stosb	; sub directory level = 0
  3373 000017FD AA                      	stosb	; 0, reverved
  3374 000017FE B004                    	mov	al, 00000100b ;  (DOS) System attribute
  3375 00001800 AA                      	stosb	; (DOS) Basic attributes
  3376 00001801 28C0                    	sub	al, al ; Extended attributes (0 for TRDOS 386)
  3377 00001803 AA                      	stosb
  3378 00001804 29C0                    	sub	ax, ax ; reserved (8) bytes for TR-MULTIX
  3379 00001806 AB                      	stosw
  3380 00001807 AB                      	stosw
  3381 00001808 AB                      	stosw
  3382 00001809 AB                      	stosw
  3383 0000180A B85254                  	mov	ax, 'RT' ; TRFS Root directory signature
  3384 0000180D AB                      	stosw
  3385 0000180E 31C0                    	xor	ax, ax ; Country (language, date, text format)
  3386                                  		       ; (0 = Default, 1 = USA, 90 = Turkiye)
  3387 00001810 AA                      	stosb
  3388 00001811 AA                      	stosb	; Time Zone (0 = GMT = default ; -11 to +12)
  3389                                  
  3390 00001812 89FE                    	mov	si, di
  3391                                  	; get the date (from RTC)
  3392 00001814 B404                    	mov	ah, 4
  3393 00001816 CD1A                    	int	1Ah
  3394                                  	; Creating Date (of root directory)
  3395 00001818 86E9                    	xchg	ch, cl ; 07/01/2018
  3396 0000181A 89C8                    	mov	ax, cx ; cl = century (BCD), ch = year (BCD)
  3397 0000181C AB                      	stosw
  3398 0000181D 88F0                    	mov	al, dh  ; month (BCD)
  3399 0000181F AA                      	stosb
  3400 00001820 88D0                    	mov	al, dl  ; day (BCD)
  3401 00001822 AA                      	stosb
  3402                                  	; get the time (from RTC)
  3403 00001823 B402                    	mov	ah, 2
  3404 00001825 CD1A                    	int	1Ah
  3405                                  	; Creating Time (of root directory)
  3406 00001827 86CD                    	xchg	cl, ch ; ch = hour (BCD), cl = minute (BSD)
  3407 00001829 89C8                    	mov	ax, cx ; al = hour, ah = minute
  3408 0000182B AB                      	stosw
  3409 0000182C 88F0                    	mov	al, dh ; seconds (BCD)
  3410 0000182E AA                      	stosb
  3411 0000182F 88D0                    	mov	al, dl ; daylight savings time option 
  3412 00001831 AA                      	stosb
  3413                                  	; Set Last Modification Date&Time
  3414 00001832 B90400                  	mov	cx, 4
  3415 00001835 F3A5                    	rep	movsw ; copy creating date&time values to
  3416                                  		; last modification date time values	
  3417                                  		; (last modif date&time = creating date&time)
  3418                                  
  3419                                  set_fs_volume_name:
  3420 00001837 BE[764A]                	mov	si, fs_volume_name
  3421 0000183A B120                    	mov	cl, 32 
  3422 0000183C F3A5                    	rep	movsw
  3423                                  
  3424                                  	; Fill remain bytes (of this RDT) with zero
  3425 0000183E B9C000                  	mov	cx, (128+256)/2
  3426 00001841 31C0                    	xor	ax, ax
  3427 00001843 F3AB                    	rep	stosw
  3428                                  
  3429                                  	; RDT is ready here...
  3430                                  
  3431 00001845 8B461C                  	mov	ax, [bp+28]	; [bsRootDirDT]
  3432                                  	;mov	dx, [bp+30]	; [bsRootDirDT+2]
  3433 00001848 31D2                    	xor	dx, dx
  3434 0000184A 03460C                  	add	ax, [bp+12]	; [bsBeginSector]
  3435 0000184D 13560E                  	adc	dx, [bp+14]	; [bsBeginSector+2]
  3436                                  
  3437                                  	; Write RDT sector
  3438                                  	; DX_AX = Root Directory Description Table address
  3439 00001850 BB[DE4A]                	mov	bx, FS_RDT_Buffer
  3440 00001853 E89B01                  	call	write_hd_sector
  3441 00001856 0F82F2F9                	jc	formatting_error
  3442 0000185A E8E2F9                  	call	write_fs_format_percent
  3443                                  
  3444 0000185D 83C001                  	add	ax, 1
  3445 00001860 83D200                  	adc	dx, 0
  3446                                  
  3447                                  	; write root directory data sectors
  3448 00001863 B90400                  	mov	cx, 4
  3449                                  
  3450                                  SINGLIX_fs1_f_10:
  3451 00001866 51                      	push	cx
  3452                                  	; Write root directory sector(s)
  3453                                  	; DX_AX = Root Directory Sector address
  3454 00001867 BB[6248]                	mov	bx, HDFORMAT_EMPTY_BUFF
  3455 0000186A E88401                  	call	write_hd_sector
  3456 0000186D 0F82DBF9                	jc	formatting_error
  3457 00001871 E8CBF9                  	call	write_fs_format_percent
  3458 00001874 83C001                  	add	ax, 1
  3459 00001877 83D200                  	adc	dx, 0
  3460 0000187A 59                      	pop	cx
  3461 0000187B FEC9                    	dec	cl
  3462 0000187D 75E7                    	jnz	short SINGLIX_fs1_f_10
  3463                                  
  3464                                  	; Fill remain sectors with 'F6h' bytes
  3465 0000187F 8B4E10                  	mov	cx, [bp+16]	; [bsVolumeSize]
  3466 00001882 8B5E12                  	mov	bx, [bp+18]	; [bsVolumeSize+2]
  3467 00001885 034E0C                  	add	cx, [bp+12]	; [bsBeginSector]
  3468 00001888 135E0E                  	adc	bx, [bp+14]	; [bsBeginSector+2]
  3469                                  
  3470                                  	; write DATA sectors 
  3471                                  	; (after root directory sectors)
  3472                                  SINGLIX_fs1_f_11:
  3473 0000188B 53                      	push	bx
  3474 0000188C 51                      	push	cx
  3475 0000188D BB[6244]                	mov	bx, HDFORMAT_SECBUFFER
  3476 00001890 E85E01                  	call	write_hd_sector
  3477 00001893 0F82B5F9                	jc	formatting_error
  3478 00001897 E865F9                  	call	write_format_percent
  3479 0000189A 59                      	pop	cx
  3480 0000189B 5B                      	pop	bx
  3481 0000189C 83C001                  	add	ax, 1
  3482 0000189F 83D200                  	adc	dx, 0
  3483 000018A2 39DA                    	cmp	dx, bx
  3484 000018A4 72E5                    	jb	short SINGLIX_fs1_f_11
  3485 000018A6 0F8736F8                	ja	SINGLIX_fs1_f_12
  3486 000018AA 39C8                    	cmp	ax, cx
  3487 000018AC 72DD                    	jb	short SINGLIX_fs1_f_11
  3488 000018AE E92FF8                  	jmp	SINGLIX_fs1_f_12	
  3489                                  	
  3490                                  
  3491                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3492                                  ; writing root directory sectors
  3493                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3494                                  
  3495                                  _R_21:
  3496 000018B1 BE[6240]                	mov	si, CRLF
  3497 000018B4 E82B01                  	call	print_msg
  3498                                  
  3499                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3500                                  ; Open image file for writing
  3501                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3502                                  
  3503 000018B7 B002                    	mov	al, 2 ; open for reading and writing
  3504                                  	;mov	dx, img_file_name
  3505 000018B9 B43D                    	mov	ah, 3Dh ; open file
  3506 000018BB CD21                    	int	21h
  3507 000018BD 0F82FE00                	jc	R_29
  3508                                  
  3509 000018C1 B81300                  	mov	ax, 19  ; Root Directory Address
  3510 000018C4 BB[6248]                	mov	bx, FDFORMAT_FATBUFFER_S9
  3511                                  R_22:
  3512 000018C7 E82701                  	call	write_fd_sector
  3513 000018CA 0F82F100                	jc	R_29
  3514 000018CE 40                      	inc	ax
  3515 000018CF 83F820                   	cmp	ax, 32
  3516 000018D2 76F3                    	jna	short R_22
  3517                                  
  3518 000018D4 BE[5E40]                	mov	si, Msg_OK
  3519 000018D7 E80801                  	call	print_msg
  3520                                  
  3521                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3522                                  ; writing data sectors
  3523                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3524                                  
  3525 000018DA BE[883F]                	mov	si, Msg_Writing_Data_Sectors
  3526 000018DD E80201                  	call	print_msg
  3527 000018E0 B403                    	mov	ah, 3
  3528 000018E2 BB0700                  	mov	bx, 7
  3529 000018E5 CD10                    	int	10h ; Return Cursor Position
  3530                                  	; DL = Column, DH= Line
  3531 000018E7 8916[A63F]              	mov	[Cursor_Pos], dx
  3532 000018EB B82100                  	mov	ax, 33  ; First Data Sector
  3533                                  R_23:
  3534 000018EE 50                      	push	ax
  3535 000018EF 40                      	inc	ax ; 1 based printing of 0 based sectors
  3536 000018F0 BE[A13F]                	mov	si, Sector_Str + 3
  3537 000018F3 E87401                  	call	bin_to_decimal
  3538 000018F6 8B16[A63F]              	mov	dx, [Cursor_Pos]
  3539 000018FA B402                    	mov	ah, 2
  3540 000018FC CD10                    	int	10h  ; Set Cursor Position
  3541 000018FE E8E100                  	call	print_msg
  3542 00001901 58                      	pop	ax
  3543 00001902 BB[6244]                	mov	bx, FDFORMAT_SECBUFFER
  3544 00001905 E8E900                  	call	write_fd_sector
  3545 00001908 0F82B300                	jc	R_29
  3546                                  
  3547 0000190C BB0700                  	mov	bx, 7
  3548 0000190F 40                      	inc	ax
  3549 00001910 3D400B                  	cmp	ax, 2880
  3550 00001913 72D9                    	jb	short R_23
  3551                                  
  3552 00001915 BE[5B40]                	mov	si, Msg_3dot_OK
  3553 00001918 E8C700                  	call	print_msg
  3554                                  
  3555                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3556                                  ; writing FAT sectors
  3557                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3558                                  
  3559 0000191B BE[A83F]                	mov	si, Msg_Writing_FAT_Sectors
  3560 0000191E E8C100                  	call	print_msg
  3561 00001921 B80100                  	mov	ax, 1  ; FAT Beginning Address
  3562 00001924 BB[6248]                	mov	bx, FDFORMAT_FATBUFFER
  3563 00001927 E8C700                  	call	write_fd_sector
  3564 0000192A 0F829100                	jc	R_29
  3565 0000192E BB[6248]                	mov	bx, FDFORMAT_FATBUFFER_S9
  3566                                  R_24:
  3567 00001931 40                      	inc	ax
  3568 00001932 E8BC00                  	call	write_fd_sector
  3569 00001935 0F828600                 	jc	R_29
  3570 00001939 83F809                  	cmp	ax, 9
  3571 0000193C 72F3                    	jb	short R_24
  3572 0000193E BB[6248]                	mov	bx, FDFORMAT_FATBUFFER
  3573 00001941 40                      	inc	ax
  3574 00001942 E8AC00                  	call	write_fd_sector
  3575 00001945 7278                    	jc	short R_29
  3576 00001947 BB[6248]                	mov	bx, FDFORMAT_FATBUFFER_S9
  3577                                  R_25:
  3578 0000194A 40                      	inc	ax 
  3579 0000194B E8A300                          call	write_fd_sector
  3580 0000194E 726F                    	jc	short R_29
  3581 00001950 83F812                  	cmp	ax, 18
  3582 00001953 72F5                    	jb	short R_25
  3583                                  
  3584 00001955 BE[5E40]                	mov	si, Msg_OK
  3585 00001958 E88700                  	call	print_msg
  3586                                  
  3587 0000195B BE[0040]                	mov	si, Msg_Volume_Name
  3588 0000195E E88100                  	call	print_msg
  3589 00001961 E83401                  	call	rw_char
  3590 00001964 7219                    	jc	short R_28
  3591 00001966 8A04                    	mov	al, [si]
  3592 00001968 3C20                    	cmp	al, 20h
  3593 0000196A 7613                    	jna	short R_28
  3594 0000196C BF[F922]                	mov	di, bsVolumeLabel
  3595 0000196F B90B00                  	mov	cx, 11
  3596 00001972 46                      	inc	si  
  3597 00001973 EB06                    	jmp	short R_27  
  3598                                  
  3599                                  R_26:
  3600 00001975 AC                      	lodsb
  3601 00001976 47                      	inc	di
  3602 00001977 3C20                    	cmp	al, 20h
  3603 00001979 765F                    	jna	short R_32
  3604                                  R_27:
  3605 0000197B 8805                    	mov 	[di], al
  3606 0000197D E2F6                    	loop	R_26
  3607                                  
  3608                                  R_28:
  3609 0000197F BE[493F]                	mov	si, Msg_Writing_Boot_Sector
  3610 00001982 E85D00                  	call	print_msg
  3611                                  
  3612 00001985 BE[F522]                	mov	si, bsVolumeID
  3613                                  
  3614 00001988 31C0                    	xor	ax, ax
  3615 0000198A CD1A                    	int	1Ah			; get time of day
  3616 0000198C 8914                    	mov	[si], dx
  3617 0000198E 894C02                  	mov	[si+2], cx		; set unique volume ID
  3618                                  
  3619 00001991 B402                    	mov	ah, 02h			; Return Current Time
  3620 00001993 CD1A                    	int	1Ah
  3621 00001995 86E9                    	xchg	ch, cl
  3622 00001997 86F2                    	xchg	dh, dl
  3623                                  
  3624 00001999 01D1                    	add	cx, dx  
  3625 0000199B 014C02                  	add	[si+2], cx
  3626                                                 
  3627 0000199E B404                    	mov	ah, 04h			; Return Current Date
  3628 000019A0 CD1A                    	int	1Ah
  3629 000019A2 86E9                    	xchg	ch,cl
  3630 000019A4 86F2                    	xchg	dh,dl
  3631                                  
  3632 000019A6 01D1                    	add	cx, dx  
  3633 000019A8 014C02                  	add	[si+2], cx
  3634                                  
  3635 000019AB 31C0                    	xor	ax, ax ; Boot sector
  3636 000019AD BB[CE22]                	mov	bx, TRDOS_FAT_hd_bs	; location of boot code
  3637                                  
  3638 000019B0 E83E00                  	call	write_fd_sector
  3639 000019B3 731D                    	jnc	short R_30
  3640                                  
  3641                                  R_29x:
  3642 000019B5 50                      	push	ax
  3643 000019B6 8B1E[E030]              	mov	bx, [img_file_handle]
  3644 000019BA B43E                    	mov	ah, 3Eh ; close file
  3645 000019BC CD21                    	int	21h
  3646 000019BE 58                      	pop	ax
  3647                                  R_29:
  3648 000019BF 88E0                    	mov	al, ah ;  error code
  3649 000019C1 E8BD00                  	call	bin_to_hex
  3650 000019C4 A3[7940]                	mov 	[error_code], ax
  3651                                  
  3652 000019C7 BE[6240]                	mov	si, CRLF
  3653 000019CA E81500                  	call	print_msg
  3654                                  
  3655 000019CD BE[6E40]                	mov	si, Msg_Error
  3656 000019D0 EB03                    	jmp	short R_31
  3657                                  
  3658                                  R_30:
  3659 000019D2 BE[5E40]                	mov	si, Msg_OK
  3660                                  R_31:
  3661 000019D5 E80A00                  	call	print_msg
  3662                                  
  3663 000019D8 CD20                    	int	20h	; Exit
  3664                                  
  3665                                  R_32:
  3666 000019DA C60520                  	mov	byte [di], 20h
  3667 000019DD 47                      	inc	di
  3668 000019DE E2FA                    	loop	R_32
  3669 000019E0 EB9D                    	jmp	short R_28
  3670                                  
  3671                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3672                                  ; Print messages
  3673                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3674                                  
  3675                                  print_msg:
  3676                                  
  3677                                  print_msg_LOOP:
  3678 000019E2 AC                      	lodsb                           ; Load byte at DS:SI to AL
  3679 000019E3 20C0                    	and     al, al            
  3680 000019E5 7409                    	jz      short print_msg_OK       
  3681 000019E7 B40E                    	mov	ah, 0Eh			
  3682 000019E9 BB0700                  	mov     bx, 07h             
  3683 000019EC CD10                    	int	10h			; BIOS Service func ( ah ) = 0Eh
  3684                                  					; Write char as TTY
  3685                                  					; AL-char BH-page BL-color
  3686 000019EE EBF2                    	jmp     short print_msg_LOOP           
  3687                                  
  3688                                  print_msg_OK:
  3689 000019F0 C3                      	retn
  3690                                  
  3691                                  
  3692                                  write_fd_sector:  ; temporary
  3693                                  
  3694                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3695                                  ; Writing a block (sector) to hard disk disk image file
  3696                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3697                                  
  3698                                  write_hd_sector:
  3699                                  	; INPUT -> DX_AX = Logical Block Address
  3700                                  	; 	   ES:BX = Sector Buffer
  3701                                  	; OUTPUT ->
  3702                                  	;  cf = 0 -> DX_AX = Logical Block Adress
  3703                                  	;	     ES:BX = Sector Buffer
  3704                                  	;  cf = 1 -> AH = Error Number
  3705                                  	;
  3706 000019F1 52                      	push	dx ; sector (hw)
  3707 000019F2 50                      	push	ax ; sector (lw)
  3708 000019F3 53                      	push	bx ; buffer
  3709 000019F4 B90002                  	mov	cx, 512
  3710                                  	; DX_AX: Multiplicand
  3711                                  	; CX = Multiplier
  3712 000019F7 E88AEE                  	call	mul32
  3713                                  	; BX_DX_AX = result of multiplication (product)
  3714 000019FA 21DB                    	and	bx, bx
  3715 000019FC 7529                    	jnz	short image_file_size_err
  3716 000019FE F6C680                  	test	dh, 80h
  3717 00001A01 7524                    	jnz	short image_file_size_err	
  3718 00001A03 8B1E[E030]              	mov 	bx, [img_file_handle]
  3719 00001A07 803E[E830]00            	cmp	byte [random], 0
  3720 00001A0C 760A                    	jna	short whds
  3721 00001A0E 89D1                    	mov	cx, dx
  3722 00001A10 89C2                    	mov	dx, ax
  3723 00001A12 28C0                    	sub	al, al ; specified offset is from the beginning of the file
  3724 00001A14 B442                    	mov	ah, 42h ; seek (move file pointer)
  3725 00001A16 CD21                    	int	21h
  3726                                  whds:
  3727                                  	;mov	bx, [img_file_handle]
  3728 00001A18 B90002                  	mov	cx, 512
  3729 00001A1B 5A                      	pop	dx  ; buffer address
  3730 00001A1C B440                    	mov	ah, 40h ; write to file	
  3731 00001A1E CD21                    	int	21h
  3732 00001A20 89D3                    	mov	bx, dx
  3733 00001A22 7209                    	jc	short image_file_rw_err
  3734 00001A24 58                      	pop	ax ; sector (lw)
  3735 00001A25 5A                      	pop	dx ; sector (hw) 
  3736 00001A26 C3                      	retn
  3737                                  
  3738                                  image_file_size_err:
  3739 00001A27 5B                      	pop	bx
  3740 00001A28 30C0                    	xor	al, al
  3741                                  	;mov	ah, 1Bh ; sector not found error
  3742 00001A2A B419                    	mov	ah, 19h ; Seek error
  3743 00001A2C F9                      	stc
  3744                                  
  3745                                  image_file_rw_err:
  3746 00001A2D 5A                      	pop	dx ; sector (lw)
  3747 00001A2E 5A                      	pop	dx ; sector (hw)
  3748 00001A2F C3                      	retn
  3749                                  
  3750                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3751                                  ; Reading a block (sector) from hard disk disk image file
  3752                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3753                                  
  3754                                  read_hd_sector:
  3755                                  	; INPUT -> DX_AX = Logical Block Address
  3756                                  	; 	   ES:BX = Sector Buffer
  3757                                  	; OUTPUT ->
  3758                                  	;  cf = 0 -> DX_AX = Logical Block Adress
  3759                                  	;	     ES:BX = Sector Buffer
  3760                                  	;  cf = 1 -> AH = Error Number
  3761                                  	;
  3762 00001A30 52                      	push	dx ; sector (hw)
  3763 00001A31 50                      	push	ax ; sector (lw)
  3764 00001A32 53                      	push	bx ; buffer
  3765 00001A33 B90002                  	mov	cx, 512
  3766                                  	; DX_AX: Multiplicand
  3767                                  	; CX = Multiplier
  3768 00001A36 E84BEE                  	call	mul32
  3769                                  	; BX_DX_AX = result of multiplication (product)
  3770 00001A39 21DB                    	and	bx, bx
  3771 00001A3B 75EA                    	jnz	short image_file_size_err
  3772 00001A3D F6C680                  	test	dh, 80h
  3773 00001A40 75E5                    	jnz	short image_file_size_err	
  3774 00001A42 8B1E[E030]              	mov 	bx, [img_file_handle]
  3775 00001A46 803E[E830]00            	cmp	byte [random], 0
  3776 00001A4B 760A                    	jna	short rhds
  3777 00001A4D 89D1                    	mov	cx, dx
  3778 00001A4F 89C2                    	mov	dx, ax
  3779 00001A51 28C0                    	sub	al, al ; specified offset is from the beginning of the file
  3780 00001A53 B442                    	mov	ah, 42h ; seek (move file pointer)
  3781 00001A55 CD21                    	int	21h
  3782                                  rhds:
  3783                                  	;mov	bx, [img_file_handle]
  3784 00001A57 B90002                  	mov	cx, 512
  3785 00001A5A 5A                      	pop	dx  ; buffer address
  3786 00001A5B B43F                    	mov	ah, 3Fh ; read from file	
  3787 00001A5D CD21                    	int	21h
  3788 00001A5F 89D3                    	mov	bx, dx
  3789 00001A61 72CA                    	jc	short image_file_rw_err
  3790 00001A63 39C8                    	cmp	ax, cx
  3791 00001A65 75C0                    	jne	short image_file_size_err
  3792 00001A67 58                      	pop	ax ; sector (lw)
  3793 00001A68 5A                      	pop	dx ; sector (hw) 
  3794 00001A69 C3                      	retn
  3795                                  
  3796                                  	
  3797                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3798                                  ; Convert byte to decimal number
  3799                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3800                                  
  3801                                  bin_to_decimal:
  3802                                  	; INPUT: DS:SI = Target location
  3803                                  	;        DX_AX = Binary Number (Integer)
  3804                                  	; OUTPUT: Decimal char at DS:SI
  3805                                  	; 	 SI decremented after every division
  3806                                  	; 	 till AX<10.
  3807                                  	; CX, DX, BX will be changed.
  3808                                  	;
  3809 00001A6A B90A00                  	mov	cx, 10
  3810                                  btd_0:
  3811                                  	; DX_AX = Dividend
  3812                                  	; CX = Divisor
  3813 00001A6D E806EE                  	call	div32
  3814                                  	; DX_AX = Quotient
  3815                                  	; BX = remainder
  3816 00001A70 80C330                  	add	bl, '0'
  3817 00001A73 881C                    	mov	[si], bl
  3818 00001A75 21D2                    	and	dx, dx
  3819 00001A77 7403                    	jz	short btd_2
  3820                                  btd_1:
  3821 00001A79 4E                      	dec	si
  3822 00001A7A EBF1                    	jmp	short btd_0
  3823                                  btd_2:
  3824 00001A7C 09C0                    	or	ax, ax
  3825 00001A7E 75F9                    	jnz	short btd_1
  3826                                  
  3827 00001A80 C3                      	retn
  3828                                  
  3829                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3830                                  ; Convert byte to hexadecimal number
  3831                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3832                                  
  3833                                  bin_to_hex:
  3834                                  	; INPUT ->
  3835                                  	; 	AL = byte (binary number)
  3836                                  	; OUTPUT ->
  3837                                  	;	AX = hexadecimal string
  3838                                  	;
  3839 00001A81 53                      	push	bx
  3840 00001A82 31DB                    	xor	bx, bx
  3841 00001A84 88C3                    	mov	bl, al
  3842 00001A86 C0EB04                  	shr	bl, 4
  3843 00001A89 8A9F[CF30]              	mov	bl, [bx+hexchrs] 	 	
  3844 00001A8D 86D8                    	xchg	bl, al
  3845 00001A8F 80E30F                  	and	bl, 0Fh
  3846 00001A92 8AA7[CF30]              	mov	ah, [bx+hexchrs] 
  3847 00001A96 5B                      	pop	bx	
  3848 00001A97 C3                      	retn
  3849                                  
  3850                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3851                                  ; Read & Write characters
  3852                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3853                                  
  3854                                  rw_char:
  3855                                  	; OUTPUT -> DS:SI = Entered String (ASCIIZ)
  3856 00001A98 BE[BF3F]                	mov     si, StrVolumeName
  3857 00001A9B BB0700                  	mov     bx, 7
  3858 00001A9E B403                    	mov     ah, 3
  3859 00001AA0 CD10                    	int     10h
  3860 00001AA2 8916[A63F]              	mov     [Cursor_Pos], dx
  3861                                  read_next_char:
  3862 00001AA6 30E4                    	xor     ah, ah
  3863 00001AA8 CD16                    	int     16h
  3864 00001AAA 20C0                    	and     al, al
  3865 00001AAC 7439                    	jz      short loc_arrow    
  3866 00001AAE 3CE0                    	cmp     al, 0E0h          
  3867 00001AB0 7435                    	je      short loc_arrow
  3868 00001AB2 3C08                    	cmp     al, 8
  3869 00001AB4 753D                    	jne     short char_return
  3870                                  loc_back:
  3871 00001AB6 B403                    	mov     ah, 3
  3872 00001AB8 CD10                    	int     10h
  3873 00001ABA 3A16[A63F]              	cmp     dl, byte [Cursor_Pos]
  3874 00001ABE 761F                    	jna     short loc_beep
  3875                                  prev_column:
  3876 00001AC0 FECA                    	dec     dl
  3877                                  set_cursor_pos:
  3878 00001AC2 B402                    	mov     ah, 2
  3879 00001AC4 CD10                    	int     10h
  3880 00001AC6 88D3                    	mov     bl, dl
  3881 00001AC8 2A1E[A63F]              	sub     bl, byte [Cursor_Pos] 
  3882 00001ACC B90100                  	mov     cx, 1
  3883 00001ACF B409                    	mov     ah, 9
  3884 00001AD1 B020                    	mov     al, 20h
  3885 00001AD3 8800                    	mov     [si+bx], al
  3886                                  loc_write_it:
  3887 00001AD5 B307                    	mov     bl, 7
  3888 00001AD7 CD10                    	int     10h
  3889 00001AD9 8B16[A63F]              	mov     dx, [Cursor_Pos]
  3890 00001ADD EBC7                    	jmp     short read_next_char
  3891                                  loc_beep:
  3892 00001ADF B40E                    	mov     ah, 0Eh
  3893 00001AE1 B007                    	mov     al, 7
  3894 00001AE3 CD10                    	int     10h
  3895 00001AE5 EBBF                    	jmp     short read_next_char
  3896                                  loc_arrow:    
  3897 00001AE7 80FC4B                  	cmp     ah, 4Bh
  3898 00001AEA 74CA                    	je      short loc_back
  3899 00001AEC 80FC53                  	cmp     ah, 53h
  3900 00001AEF 74C5                    	je      short loc_back
  3901 00001AF1 EBB3                    	jmp     short read_next_char
  3902                                  char_return:
  3903 00001AF3 B403                    	mov     ah, 3
  3904 00001AF5 CD10                    	int     10h
  3905                                  check_char_type:
  3906 00001AF7 3C20                    	cmp     al, 20h
  3907 00001AF9 7229                    	jb      short loc_escape
  3908 00001AFB 88D4                    	mov     ah, dl
  3909 00001AFD 2A26[A63F]              	sub     ah, byte [Cursor_Pos]
  3910                                  	;cmp	ah, 10 
  3911                                  	;ja	short loc_beep
  3912 00001B01 3A26[4444]              	cmp     ah, [vname_length] ; 05/01/2018
  3913 00001B05 73D8                    	jnb	short loc_beep
  3914 00001B07 3C7A                    	cmp     al, 'z'
  3915 00001B09 779B                    	ja      short read_next_char
  3916 00001B0B 3C61                    	cmp     al, 'a'
  3917 00001B0D 7202                    	jb      short pass_capitalize
  3918 00001B0F 24DF                    	and     al, 0DFh
  3919                                  pass_capitalize:
  3920 00001B11 88E3                    	mov     bl, ah 
  3921 00001B13 30E4                    	xor     ah, ah
  3922 00001B15 8900                    	mov     [si+bx], ax
  3923 00001B17 B307                    	mov     bl, 7
  3924 00001B19 B40E                    	mov     ah, 0Eh
  3925 00001B1B CD10                    	int     10h
  3926 00001B1D EB87                    	jmp     short read_next_char
  3927                                  pass_escape:
  3928 00001B1F 3C0D                    	cmp     al, 0Dh	; 13 ; ENTER
  3929 00001B21 7583                    	jne     short read_next_char
  3930                                  	;mov	ah, 0Eh
  3931                                  	;int	10h
  3932                                  	;mov	al, 0Ah
  3933                                  	;int	10h
  3934 00001B23 C3                      	retn
  3935                                  loc_escape:
  3936 00001B24 3C1B                    	cmp     al, 1Bh	; 27 ; ESC
  3937 00001B26 75F7                    	jne     short pass_escape
  3938 00001B28 F9                      	stc
  3939 00001B29 C3                      	retn
  3940                                  
  3941                                  write_chs_table:
  3942 00001B2A 06                      	push	es
  3943 00001B2B BF00B8                  	mov	di, 0B800h
  3944 00001B2E 8EC7                    	mov	es, di
  3945 00001B30 31FF                    	xor	di, di
  3946 00001B32 B95000                  	mov	cx, 80
  3947 00001B35 B82007                  	mov	ax, 0720h
  3948 00001B38 F3AB                    	rep	stosw
  3949 00001B3A B150                    	mov	cl, 80 
  3950 00001B3C B02D                    	mov	al, "-"
  3951 00001B3E F3AB                    	rep	stosw
  3952 00001B40 B113                    	mov	cl, 19
  3953 00001B42 B020                    	mov	al, 20h
  3954 00001B44 F3AB                    	rep	stosw
  3955 00001B46 B043                    	mov	al, 'C'
  3956 00001B48 AB                      	stosw
  3957 00001B49 B079                    	mov	al, 'y'
  3958 00001B4B AB                      	stosw
  3959 00001B4C B06C                    	mov	al, 'l'
  3960 00001B4E AB                      	stosw
  3961 00001B4F B069                    	mov	al, 'i'
  3962 00001B51 AB                       	stosw
  3963 00001B52 B06E                    	mov	al, 'n'
  3964 00001B54 AB                      	stosw	
  3965 00001B55 B064                    	mov	al, 'd'
  3966 00001B57 AB                      	stosw
  3967 00001B58 B065                    	mov	al, 'e'
  3968 00001B5A AB                      	stosw
  3969 00001B5B B072                    	mov	al, 'r'
  3970 00001B5D AB                       	stosw
  3971 00001B5E B073                    	mov	al, 's'
  3972 00001B60 AB                       	stosw
  3973 00001B61 B03A                    	mov	al, ':'
  3974 00001B63 AB                      	stosw
  3975 00001B64 B020                    	mov	al, 20h
  3976 00001B66 AB                      	stosw
  3977                                  	;mov	[cylnumpos], di
  3978 00001B67 A1[E630]                	mov	ax, [cylinders]
  3979 00001B6A B104                    	mov	cl, 4
  3980 00001B6C B543                    	mov	ch, 'C'
  3981 00001B6E E87E00                  	call	write_number
  3982                                  	
  3983 00001B71 B82007                  	mov	ax, 0720h
  3984 00001B74 AB                      	stosw
  3985 00001B75 AB                      	stosw
  3986 00001B76 B048                    	mov	al, 'H'
  3987 00001B78 AB                      	stosw
  3988 00001B79 B065                    	mov	al, 'e'
  3989 00001B7B AB                      	stosw
  3990 00001B7C B061                    	mov	al, 'a'
  3991 00001B7E AB                      	stosw
  3992 00001B7F B064                    	mov	al, 'd'
  3993 00001B81 AB                       	stosw
  3994 00001B82 B073                    	mov	al, 's'
  3995 00001B84 AB                       	stosw
  3996 00001B85 B03A                    	mov	al, ':'
  3997 00001B87 AB                      	stosw
  3998 00001B88 B020                    	mov	al, 20h
  3999 00001B8A AB                      	stosw
  4000                                  	;mov	[hednumpos], di
  4001 00001B8B A1[E430]                	mov	ax, [heads]
  4002 00001B8E B102                    	mov	cl, 2
  4003 00001B90 B548                    	mov	ch, 'H'
  4004 00001B92 E85A00                  	call	write_number
  4005                                  
  4006 00001B95 B82007                  	mov	ax, 0720h
  4007 00001B98 AB                      	stosw
  4008 00001B99 AB                      	stosw
  4009 00001B9A B053                    	mov	al, 'S'
  4010 00001B9C AB                      	stosw
  4011 00001B9D B065                    	mov	al, 'e'
  4012 00001B9F AB                      	stosw
  4013 00001BA0 B063                    	mov	al, 'c'
  4014 00001BA2 AB                      	stosw
  4015 00001BA3 B074                    	mov	al, 't'
  4016 00001BA5 AB                       	stosw
  4017 00001BA6 B06F                    	mov	al, 'o'
  4018 00001BA8 AB                      	stosw
  4019 00001BA9 B072                    	mov	al, 'r'
  4020 00001BAB AB                       	stosw
  4021 00001BAC B073                    	mov	al, 's'
  4022 00001BAE AB                       	stosw
  4023 00001BAF B03A                    	mov	al, ':'
  4024 00001BB1 AB                      	stosw
  4025 00001BB2 B020                    	mov	al, 20h
  4026 00001BB4 AB                      	stosw
  4027                                  	;mov	[secnumpos], di
  4028 00001BB5 A1[E230]                	mov	ax, [sectors]
  4029 00001BB8 B102                    	mov	cl, 2
  4030 00001BBA B553                    	mov	ch, 'S'
  4031 00001BBC E83000                  	call	write_number
  4032                                  
  4033 00001BBF B116                    	mov	cl, 22
  4034 00001BC1 B82007                  	mov	ax, 0720h
  4035 00001BC4 F3AB                    	rep	stosw
  4036                                  	
  4037 00001BC6 B150                    	mov	cl, 80 
  4038 00001BC8 B02D                    	mov	al, "-"
  4039 00001BCA F3AB                    	rep	stosw
  4040                                  
  4041 00001BCC B150                    	mov	cl, 80
  4042 00001BCE B020                    	mov	al, 20h
  4043 00001BD0 F3AB                    	rep	stosw
  4044                                  
  4045 00001BD2 BA0006                  	mov	dx, 0600h ; DH = row, DL = 0 column
  4046 00001BD5 31DB                    	xor	bx, bx ; BH = video page (0)
  4047 00001BD7 B402                    	mov	ah, 02h ; set cursor position
  4048 00001BD9 CD10                    	int	10h
  4049                                  
  4050 00001BDB 81C7A005                	add	di, 9*160 ; 9 rows (CHS_msg)
  4051                                  
  4052 00001BDF BE[1532]                	mov	si, CHS_msg
  4053 00001BE2 E8FDFD                  	call	print_msg
  4054                                  
  4055 00001BE5 B92003                  	mov	cx, 10*80
  4056 00001BE8 B82007                  	mov	ax, 0720h
  4057 00001BEB F3AB                    	rep	stosw
  4058 00001BED 07                      	pop	es
  4059 00001BEE C3                      	retn
  4060                                  
  4061                                  write_number:
  4062 00001BEF 89CE                    	mov	si, cx
  4063 00001BF1 31D2                    	xor	dx, dx
  4064 00001BF3 BB0A00                  	mov	bx, 10
  4065                                  wnum_1:
  4066 00001BF6 F7F3                    	div	bx
  4067 00001BF8 52                      	push	dx
  4068 00001BF9 31D2                    	xor	dx, dx
  4069 00001BFB FEC9                    	dec	cl
  4070 00001BFD 75F7                    	jnz	short wnum_1
  4071 00001BFF 89F1                    	mov	cx, si
  4072 00001C01 B407                    	mov	ah, 07h
  4073 00001C03 88E8                    	mov	al, ch
  4074 00001C05 30ED                    	xor	ch, ch
  4075 00001C07 3806[1F44]              	cmp	byte [chs_focus], al
  4076 00001C0B 7502                    	jne	short wnum_2
  4077 00001C0D B40F                    	mov	ah, 0Fh
  4078                                  wnum_2:
  4079 00001C0F 5A                      	pop	dx
  4080 00001C10 88D0                    	mov	al, dl
  4081 00001C12 0430                    	add	al, '0'
  4082 00001C14 AB                      	stosw
  4083 00001C15 E2F8                    	loop	wnum_2
  4084 00001C17 C3                      	retn
  4085                                  
  4086                                  partition_size_input:
  4087 00001C18 C706[2644]0000          	mov	word [pSize_multiplier+2], 0
  4088 00001C1E C606[2B44]42            	mov	byte [msg_psize_unit+1], 'B'
  4089 00001C23 A0[2A44]                	mov	al, [pSize_unit]
  4090 00001C26 3C25                    	cmp	al, '%'
  4091 00001C28 751F                    	jne	short psu_0
  4092                                  	;mov	dx, [pp_Sectors+2]
  4093                                  	;mov	ax, [pp_Sectors]
  4094 00001C2A 8B16[8243]              	mov	dx, [total_sectors+2]
  4095 00001C2E A1[8043]                	mov	ax, [total_sectors]	
  4096 00001C31 B96400                  	mov	cx, 100
  4097 00001C34 E83FEC                  	call	div32
  4098 00001C37 A3[2444]                	mov	[pSize_multiplier], ax
  4099 00001C3A B400                    	mov	ah, 0
  4100 00001C3C 8826[2B44]              	mov	[msg_psize_unit+1], ah
  4101 00001C40 C606[2844]02            	mov	byte [pSize_maxdigits], 2
  4102 00001C45 B025                    	mov	al, '%'
  4103 00001C47 EB62                    	jmp	short psu_6
  4104                                  psu_0:
  4105 00001C49 3C43                    	cmp	al, 'C'
  4106 00001C4B 7519                    	jne	short psu_1
  4107 00001C4D A1[E230]                	mov	ax, [sectors]
  4108 00001C50 8B16[E430]              	mov	dx, [heads]
  4109 00001C54 F7E2                    	mul	dx
  4110 00001C56 A3[2444]                	mov	[pSize_multiplier], ax	
  4111 00001C59 C606[2844]04            	mov	byte [pSize_maxdigits], 4
  4112                                  	;sub	dh, dh
  4113 00001C5E 8836[2B44]              	mov	[msg_psize_unit+1], dh
  4114 00001C62 B043                    	mov	al, 'C'
  4115 00001C64 EB45                    	jmp	short psu_6	
  4116                                  psu_1:
  4117 00001C66 3C47                    	cmp	al, 'G'
  4118 00001C68 7513                    	jne	short psu_2
  4119 00001C6A C706[2444]0008          	mov	word [pSize_multiplier], 2*1024
  4120 00001C70 C706[2644]0004          	mov	word [pSize_multiplier+2], 1024
  4121 00001C76 C606[2844]01            	mov	byte [pSize_maxdigits], 1
  4122 00001C7B EB2E                    	jmp	short psu_6
  4123                                  psu_2:
  4124 00001C7D 3C4D                    	cmp	al, 'M'
  4125 00001C7F 750D                    	jne	short psu_3
  4126 00001C81 C706[2444]0008          	mov	word [pSize_multiplier], 2*1024
  4127 00001C87 C606[2844]04            	mov	byte [pSize_maxdigits], 4
  4128 00001C8C EB1D                    	jmp	short psu_6
  4129                                  psu_3:
  4130 00001C8E 3C4B                    	cmp	al, 'K'
  4131 00001C90 7508                    	jne	short psu_4
  4132 00001C92 C706[2444]0200          	mov	word [pSize_multiplier], 2
  4133 00001C98 EB0C                    	jmp	short psu_5	
  4134                                  psu_4:
  4135                                  	; al = 'S'
  4136 00001C9A 30E4                    	xor	ah, ah
  4137 00001C9C 8826[2B44]              	mov	[msg_psize_unit+1], ah
  4138 00001CA0 C706[2444]0100          	mov	word [pSize_multiplier], 1
  4139                                  psu_5:
  4140 00001CA6 C606[2844]07            	mov	byte [pSize_maxdigits], 7
  4141                                  psu_6:
  4142 00001CAB A2[E739]                	mov	[msg_partition_size_x], al
  4143 00001CAE BE[D339]                	mov	si, msg_partition_size	
  4144 00001CB1 E82EFD                  	call	print_msg
  4145                                  
  4146 00001CB4 89E5                    	mov	bp, sp
  4147 00001CB6 31DB                    	xor	bx, bx
  4148 00001CB8 891E[2044]              	mov	[pSize_temp], bx ; 0
  4149 00001CBC 891E[2244]              	mov	[pSize_temp+2], bx ; 0
  4150 00001CC0 881E[2944]              	mov	[pSize_digitpos], bl ; 0
  4151                                  	; bh = 0  ; video page
  4152 00001CC4 B403                    	mov     ah, 3 ; get cursor pos
  4153 00001CC6 CD10                    	int     10h
  4154 00001CC8 8916[A63F]              	mov	[Cursor_Pos], dx
  4155                                  psu_7:
  4156 00001CCC 30E4                    	xor	ah, ah
  4157 00001CCE CD16                    	int	16h
  4158                                  
  4159 00001CD0 3C30                    	cmp	al, '0'
  4160 00001CD2 7222                    	jb	short psu_8
  4161 00001CD4 3C39                    	cmp	al, '9'
  4162 00001CD6 77F4                    	ja	short psu_7
  4163 00001CD8 8A1E[2944]              	mov	bl, [pSize_digitpos]
  4164 00001CDC 3A1E[2844]              	cmp	bl, [pSize_maxdigits]
  4165 00001CE0 73EA                    	jnb	short psu_7
  4166 00001CE2 FE06[2944]              	inc	byte [pSize_digitpos]
  4167 00001CE6 2C30                    	sub	al, '0'
  4168 00001CE8 30E4                    	xor	ah, ah
  4169 00001CEA 50                      	push	ax
  4170 00001CEB 0430                    	add	al, '0'
  4171 00001CED B40E                    	mov	ah, 0Eh	; write char as tty		
  4172 00001CEF BB0700                  	mov     bx, 7   ; page 0, color 7 (light gray)         
  4173 00001CF2 CD10                    	int	10h
  4174 00001CF4 EBD6                    	jmp	short psu_7	
  4175                                  psu_8:
  4176 00001CF6 20C0                    	and	al, al
  4177 00001CF8 0F84A000                	jz	psu_15 ; check for left arrow key 
  4178 00001CFC 3C1B                    	cmp	al, 27
  4179 00001CFE 0F84A700                	je	psu_16esc ; ESCAPE key
  4180 00001D02 0F879000                	ja	psu_14 ; check for left arrow key
  4181 00001D06 3C0D                    	cmp	al, 13
  4182 00001D08 7404                    	je	short psu_9  ; ENTER key
  4183 00001D0A 7251                    	jb	short psu_11 ; check for backspace key
  4184 00001D0C EBBE                    	jmp	short psu_7
  4185                                  psu_9:	
  4186 00001D0E 803E[2944]00            	cmp	byte [pSize_digitpos], 0
  4187 00001D13 0F869C00                	jna	psu_16		
  4188                                  	;xor	bh, bh
  4189 00001D17 8A1E[2944]              	mov	bl, [pSize_digitpos]
  4190 00001D1B FECB                    	dec	bl
  4191 00001D1D D0E3                    	shl	bl, 1
  4192 00001D1F 01E3                    	add	bx, sp
  4193 00001D21 8B07                    	mov	ax, [bx]
  4194 00001D23 A3[2044]                	mov	[pSize_temp], ax
  4195 00001D26 C706[2244]0000          	mov	word [pSize_temp+2], 0
  4196 00001D2C B90A00                  	mov	cx, 10
  4197                                  psu_10:
  4198 00001D2F FE0E[2944]              	dec	byte [pSize_digitpos]
  4199 00001D33 747E                    	jz	short psu_16
  4200                                  	
  4201 00001D35 A1[2044]                	mov	ax, [pSize_temp]
  4202 00001D38 8B16[2244]              	mov	dx, [pSize_temp+2]
  4203                                  	;mov	cx, 10
  4204 00001D3C E845EB                  	call	mul32
  4205 00001D3F A3[2044]                	mov	[pSize_temp], ax
  4206 00001D42 8916[2244]              	mov	[pSize_temp+2], dx
  4207                                  	;xor	bh, bh
  4208 00001D46 8A1E[2944]              	mov	bl, [pSize_digitpos]
  4209 00001D4A FECB                    	dec	bl
  4210 00001D4C D0E3                    	shl	bl, 1
  4211 00001D4E 01E3                    	add	bx, sp
  4212 00001D50 8B1F                    	mov	bx, [bx]
  4213 00001D52 011E[2044]              	add	[pSize_temp], bx
  4214 00001D56 8316[2244]00            	adc	word [pSize_temp+2], 0
  4215 00001D5B EBD2                    	jmp	short psu_10
  4216                                  	
  4217                                  	; Left arrow, backspace, DEL key checking
  4218                                  psu_11:
  4219 00001D5D 3C08                    	cmp	al, 8 ; backspace key
  4220 00001D5F 0F8569FF                	jne	psu_7
  4221                                  psu_12:
  4222                                  	; bh = 0  ; video page
  4223 00001D63 B403                    	mov	ah, 3 ; get cursor pos
  4224 00001D65 CD10                    	int	10h
  4225 00001D67 3A16[A63F]              	cmp	dl, [Cursor_Pos]
  4226 00001D6B 7620                    	jna	short psu_13
  4227 00001D6D FECA                    	dec	dl
  4228 00001D6F FE0E[2944]              	dec	byte [pSize_digitpos]
  4229                                  	; bh = 0  ; video page
  4230 00001D73 B402                    	mov	ah, 2 ; set cursor pos
  4231 00001D75 CD10                    	int	10h
  4232 00001D77 88D3                    	mov	bl, dl
  4233 00001D79 2A1E[A63F]              	sub	bl, [Cursor_Pos] 
  4234 00001D7D B90100                  	mov	cx, 1
  4235 00001D80 B409                    	mov	ah, 9 ; write char at current curs pos
  4236 00001D82 B020                    	mov	al, 20h ; space (blank)
  4237 00001D84 8800                    	mov	[si+bx], al
  4238                                  	; bh = 0 ; video page
  4239 00001D86 B307                    	mov	bl, 7 ; attribute/color (light gray)
  4240 00001D88 CD10                    	int	10h
  4241 00001D8A E93FFF                  	jmp	psu_7
  4242                                  psu_13:
  4243 00001D8D B40E                    	mov	ah, 0Eh
  4244 00001D8F B007                    	mov	al, 7
  4245                                  	;mov	bx, 7
  4246 00001D91 CD10                    	int	10h
  4247 00001D93 E936FF                  	jmp	psu_7
  4248                                  psu_14:
  4249 00001D96 3CE0                    	cmp	al, 0E0h          
  4250 00001D98 0F8530FF                	jne	psu_7
  4251                                  psu_15:    
  4252 00001D9C 80FC4B                  	cmp	ah, 4Bh ; left arrow
  4253 00001D9F 74C2                    	je	short psu_12
  4254 00001DA1 80FC53                  	cmp	ah, 53h ; DEL key (backspace)
  4255 00001DA4 74BD                    	je	short psu_12
  4256 00001DA6 E923FF                  	jmp	psu_7
  4257                                  
  4258                                  psu_16esc:
  4259 00001DA9 31C9                    	xor	cx, cx ; 0
  4260 00001DAB 890E[2044]              	mov	[pSize_temp], cx
  4261 00001DAF 890E[2244]              	mov	[pSize_temp+2], cx
  4262                                  psu_16:
  4263 00001DB3 89EC                    	mov	sp, bp
  4264                                  
  4265 00001DB5 803E[2A44]53            	cmp	byte [pSize_unit], 'S'
  4266 00001DBA 750A                    	jne	short psu_17 
  4267                                  
  4268 00001DBC BE[3944]                	mov	si, msg_sectors_crlf
  4269 00001DBF E820FC                  	call	print_msg
  4270 00001DC2 31DB                    	xor	bx, bx
  4271 00001DC4 EB0C                    	jmp	short psu_18
  4272                                  psu_17:
  4273 00001DC6 BE[2A44]                	mov	si, msg_psize_unit
  4274 00001DC9 E816FC                  	call	print_msg
  4275                                  
  4276 00001DCC BE[6240]                	mov	si, CRLF
  4277 00001DCF E810FC                  	call	print_msg
  4278                                  psu_18:
  4279 00001DD2 A1[2044]                	mov	ax, [pSize_temp]
  4280 00001DD5 8B16[2244]              	mov	dx, [pSize_temp+2]
  4281 00001DD9 89C1                    	mov	cx, ax
  4282 00001DDB 09D1                    	or	cx, dx
  4283 00001DDD 742B                    	jz	short psu_20
  4284 00001DDF 8B0E[2444]              	mov	cx, [pSize_multiplier]
  4285 00001DE3 803E[2A44]43            	cmp	byte [pSize_unit], 'C'
  4286 00001DE8 750D                    	jne	short psu_19
  4287 00001DEA E897EA                  	call	mul32
  4288 00001DED 2B0E[E230]              	sub	cx, [sectors]
  4289 00001DF1 01C8                    	add	ax, cx	; (heads-1)*sectors
  4290 00001DF3 83D200                  	adc	dx, 0
  4291 00001DF6 C3                      	retn	
  4292                                  psu_19:
  4293                                  	;mov	cx, [pSize_multiplier]
  4294 00001DF7 83F901                  	cmp	cx, 1
  4295 00001DFA 760E                    	jna	short psu_20
  4296 00001DFC E885EA                  	call	mul32
  4297 00001DFF 8B0E[2644]              	mov	cx, [pSize_multiplier+2]
  4298 00001E03 09C9                    	or	cx, cx
  4299 00001E05 7403                    	jz	short psu_20
  4300 00001E07 E87AEA                  	call	mul32
  4301                                  psu_20:
  4302 00001E0A C3                      	retn
  4303                                  
  4304                                  partition_type_input:
  4305 00001E0B BE[ED39]                	mov	si, msg_partition_type	
  4306 00001E0E E8D1FB                  	call	print_msg
  4307                                  
  4308 00001E11 31DB                    	xor	bx, bx
  4309                                  
  4310 00001E13 881E[5C44]              	mov	[pType_pos], bl ; 0
  4311 00001E17 891E[5D44]              	mov	[pType_num], bx ; 0
  4312                                  
  4313                                  	; bh = 0  ; video page
  4314 00001E1B B403                    	mov     ah, 3 ; get cursor pos
  4315 00001E1D CD10                    	int     10h
  4316 00001E1F 8916[A63F]              	mov	[Cursor_Pos], dx
  4317                                  ptu_0:
  4318 00001E23 30E4                    	xor	ah, ah
  4319 00001E25 CD16                    	int	16h
  4320                                  
  4321 00001E27 803E[5C44]01            	cmp	byte [pType_pos], 1
  4322 00001E2C 773F                    	ja	short ptu_5	
  4323                                  
  4324 00001E2E 3C30                    	cmp	al, '0'
  4325 00001E30 723B                    	jb	short ptu_5
  4326 00001E32 3C39                    	cmp	al, '9'
  4327 00001E34 7707                    	ja	short ptu_1
  4328 00001E36 88C4                    	mov	ah, al
  4329 00001E38 80EC30                  	sub	ah, '0'
  4330 00001E3B EB13                    	jmp	short ptu_2 
  4331                                  ptu_1:
  4332 00001E3D 3CE0                    	cmp     al, 0E0h          
  4333 00001E3F 7473                    	je	short ptu_9
  4334                                  
  4335 00001E41 24DF                    	and	al, 0DFh
  4336 00001E43 3C41                    	cmp	al, 'A'
  4337 00001E45 72DC                    	jb	short ptu_0
  4338 00001E47 3C46                    	cmp	al, 'F'
  4339 00001E49 77D8                    	ja	short ptu_0
  4340 00001E4B 88C4                    	mov	ah, al
  4341 00001E4D 80EC37                  	sub	ah, 'A'-10
  4342                                  ptu_2:
  4343 00001E50 803E[5C44]00            	cmp	byte [pType_pos], 0
  4344 00001E55 7606                    	jna	short ptu_3
  4345 00001E57 8826[5E44]              	mov	[pType_num+1], ah
  4346 00001E5B EB04                    	jmp	short ptu_4 
  4347                                  ptu_3:
  4348 00001E5D 8826[5D44]              	mov	[pType_num], ah
  4349                                  ptu_4:
  4350 00001E61 B40E                    	mov	ah, 0Eh
  4351 00001E63 B307                    	mov	bl, 7
  4352 00001E65 CD10                    	int	10h
  4353                                  
  4354 00001E67 FE06[5C44]              	inc	byte [pType_pos]
  4355                                  
  4356 00001E6B EBB6                    	jmp	short ptu_0 
  4357                                  ptu_5:
  4358 00001E6D 20C0                    	and	al, al
  4359 00001E6F 7443                    	jz	short ptu_9 ; check for left arrow key 
  4360 00001E71 3C1B                    	cmp	al, 27
  4361 00001E73 744C                    	je	short ptu_10 ; ESCAPE key
  4362 00001E75 77AC                    	ja	short ptu_0
  4363 00001E77 3C0D                    	cmp	al, 13
  4364 00001E79 744A                    	je	short ptu_11  ; ENTER key
  4365 00001E7B 77A6                    	ja	short ptu_0
  4366                                  ptu_6:
  4367                                  	; Left arrow, backspace, DEL key checking
  4368                                  
  4369 00001E7D 3C08                    	cmp	al, 8 ; backspace key
  4370 00001E7F 75A2                    	jne	short ptu_0
  4371                                  ptu_7:
  4372                                  	; bh = 0  ; video page
  4373 00001E81 B403                    	mov	ah, 3 ; get cursor pos
  4374 00001E83 CD10                    	int	10h
  4375 00001E85 3A16[A63F]              	cmp	dl, [Cursor_Pos]
  4376 00001E89 7620                    	jna	short ptu_8
  4377 00001E8B FECA                    	dec	dl
  4378 00001E8D FE0E[5C44]              	dec	byte [pType_pos]
  4379                                  	; bh = 0  ; video page
  4380 00001E91 B402                    	mov	ah, 2 ; set cursor pos
  4381 00001E93 CD10                    	int	10h
  4382 00001E95 88D3                    	mov	bl, dl
  4383 00001E97 2A1E[A63F]              	sub	bl, [Cursor_Pos] 
  4384 00001E9B B90100                  	mov	cx, 1
  4385 00001E9E B409                    	mov	ah, 9 ; write char at current curs pos
  4386 00001EA0 B020                    	mov	al, 20h ; space (blank)
  4387 00001EA2 8800                    	mov	[si+bx], al
  4388                                  	; bh = 0 ; video page
  4389 00001EA4 B307                    	mov	bl, 7 ; attribute/color (light gray)
  4390 00001EA6 CD10                    	int	10h
  4391 00001EA8 E978FF                  	jmp	ptu_0
  4392                                  ptu_8:
  4393 00001EAB B40E                    	mov	ah, 0Eh
  4394 00001EAD B007                    	mov	al, 7
  4395 00001EAF CD10                    	int	10h
  4396 00001EB1 E96FFF                  	jmp	ptu_0
  4397                                  ptu_9:    
  4398 00001EB4 80FC4B                  	cmp	ah, 4Bh ; left arrow
  4399 00001EB7 74C8                    	je	short ptu_7
  4400 00001EB9 80FC53                  	cmp	ah, 53h ; DEL key (backspace)
  4401 00001EBC 74C3                    	je	short ptu_7
  4402 00001EBE E962FF                  	jmp	ptu_0
  4403                                  
  4404                                  ptu_10: ; ESCAPE
  4405 00001EC1 B000                    	mov	al, 0
  4406                                  	; partition type is 0 (none)
  4407 00001EC3 EB12                    	jmp	short ptu_12
  4408                                  ptu_11: ; ENTER
  4409 00001EC5 A0[5D44]                	mov	al, [pType_num]
  4410 00001EC8 803E[5C44]01            	cmp	byte [pType_pos], 1
  4411 00001ECD 7608                    	jna	short ptu_12
  4412 00001ECF B410                    	mov	ah, 16
  4413 00001ED1 F6E4                    	mul	ah
  4414 00001ED3 0206[5E44]              	add	al, [pType_num+1]
  4415                                  ptu_12:
  4416 00001ED7 50                      	push	ax
  4417 00001ED8 E8A6FB                  	call	bin_to_hex
  4418 00001EDB A3[033A]                	mov	[msg_ptype_num], ax
  4419                                  	; bh = 0  ; video page
  4420 00001EDE B402                    	mov	ah, 2 ; set cursor pos
  4421 00001EE0 8B16[A63F]              	mov	dx, [Cursor_Pos]
  4422 00001EE4 CD10                    	int	10h
  4423 00001EE6 BE[033A]                	mov	si, msg_ptype_num 
  4424 00001EE9 E8F6FA                  	call	print_msg
  4425 00001EEC 58                      	pop	ax
  4426 00001EED C3                      	retn
  4427                                  
  4428                                  show_selected_partition:
  4429                                  	; INPUT ->
  4430                                  	; 	DS:SI = Partition table row address
  4431                                  		
  4432                                  	pt_s_offset	equ 7
  4433                                  	pt_bh_offset	equ 11
  4434                                  	pt_bs_offset	equ 15
  4435                                  	pt_bc_offset	equ 19
  4436                                  	pt_fs_offset	equ 23
  4437                                  	pt_eh_offset	equ 27
  4438                                  	pt_es_offset	equ 31
  4439                                  	pt_ec_offset	equ 35
  4440                                  	pt_rs_offset	equ 41
  4441                                  	pt_ts_offset	equ 52
  4442                                  	pt_fsn_offset	equ 63
  4443                                  
  4444                                  	; clear screen
  4445 00001EEE B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
  4446 00001EF1 CD10                    	int	10h	
  4447                                  
  4448 00001EF3 89F0                    	mov	ax, si
  4449 00001EF5 2D[DC42]                	sub	ax, MasterBootBuff + pTableOffset ; + 446
  4450 00001EF8 C0E804                  	shr	al, 4 ; from offset to partition number
  4451 00001EFB 0431                    	add	al, '1'  ; 1 based partition number (chr)
  4452                                  	; Write partition number to the header location
  4453 00001EFD A2[7A3B]                	mov	[msg_selected_partition+43], al ; '1' to '4'
  4454                                  	
  4455                                  	; Partition number will be used at formatting stage
  4456 00001F00 A2[493E]                	mov	[partition_num_chr], al ; number + '0'
  4457                                  
  4458 00001F03 B268                    	mov	dl, 'h'
  4459 00001F05 8A04                    	mov	al, [si+ptBootable]
  4460 00001F07 E877FB                  	call	bin_to_hex
  4461 00001F0A A3[963C]                	mov	[pt_row+pt_s_offset], ax
  4462 00001F0D 8816[983C]              	mov	[pt_row+pt_s_offset+2], dl ; 'h'	
  4463 00001F11 8A4401                  	mov	al, [si+ptBeginHead]
  4464 00001F14 E86AFB                  	call	bin_to_hex
  4465 00001F17 A3[9A3C]                	mov	[pt_row+pt_bh_offset], ax
  4466 00001F1A 8816[9C3C]              	mov	[pt_row+pt_bh_offset+2], dl ; 'h'
  4467 00001F1E 8A4402                  	mov	al, [si+ptBeginSector]
  4468 00001F21 E85DFB                  	call	bin_to_hex
  4469 00001F24 A3[9E3C]                	mov	[pt_row+pt_bs_offset], ax
  4470 00001F27 8816[A03C]              	mov	[pt_row+pt_bs_offset+2], dl ; 'h'
  4471 00001F2B 8A4403                  	mov	al, [si+ptBeginCylinder]
  4472 00001F2E E850FB                  	call	bin_to_hex
  4473 00001F31 A3[A23C]                	mov	[pt_row+pt_bc_offset], ax
  4474 00001F34 8816[A43C]              	mov	[pt_row+pt_bc_offset+2], dl ; 'h'
  4475 00001F38 8A4404                  	mov	al, [si+ptFileSystemID]
  4476                                   	; Partition type will be used at formatting stage
  4477 00001F3B A2[1E44]                	mov	[pp_type_user], al
  4478 00001F3E E840FB                  	call	bin_to_hex
  4479 00001F41 A3[A63C]                	mov	[pt_row+pt_fs_offset], ax
  4480 00001F44 8816[A83C]              	mov	[pt_row+pt_fs_offset+2], dl ; 'h'
  4481 00001F48 8A4405                  	mov	al, [si+ptEndHead]
  4482 00001F4B E833FB                  	call	bin_to_hex
  4483 00001F4E A3[AA3C]                	mov	[pt_row+pt_eh_offset], ax
  4484 00001F51 8816[AC3C]              	mov	[pt_row+pt_eh_offset+2], dl ; 'h'
  4485 00001F55 8A4406                  	mov	al, [si+ptEndSector]
  4486 00001F58 E826FB                  	call	bin_to_hex
  4487 00001F5B A3[AE3C]                	mov	[pt_row+pt_es_offset], ax
  4488 00001F5E 8816[B03C]              	mov	[pt_row+pt_es_offset+2], dl ; 'h'
  4489 00001F62 8A4407                  	mov	al, [si+ptEndCylinder]
  4490 00001F65 E819FB                  	call	bin_to_hex
  4491 00001F68 A3[B23C]                	mov	[pt_row+pt_ec_offset], ax
  4492 00001F6B 8816[B43C]              	mov	[pt_row+pt_ec_offset+2], dl ; 'h'
  4493 00001F6F 8A4408                  	mov	al, [si+ptStartSector]
  4494 00001F72 E80CFB                  	call	bin_to_hex
  4495 00001F75 A3[BE3C]                	mov	[pt_row+pt_rs_offset+6], ax
  4496 00001F78 8816[C03C]              	mov	[pt_row+pt_rs_offset+8], dl ; 'h'
  4497 00001F7C 8A4409                  	mov	al, [si+ptStartSector+1]
  4498 00001F7F E8FFFA                  	call	bin_to_hex
  4499 00001F82 A3[BC3C]                	mov	[pt_row+pt_rs_offset+4], ax
  4500 00001F85 8A440A                  	mov	al, [si+ptStartSector+2]
  4501 00001F88 E8F6FA                  	call	bin_to_hex
  4502 00001F8B A3[BA3C]                	mov	[pt_row+pt_rs_offset+2], ax
  4503 00001F8E 8A440B                  	mov	al, [si+ptStartSector+3]
  4504 00001F91 E8EDFA                  	call	bin_to_hex
  4505 00001F94 A3[B83C]                	mov	[pt_row+pt_rs_offset], ax
  4506 00001F97 8A440C                  	mov	al, [si+ptSectors]
  4507 00001F9A E8E4FA                  	call	bin_to_hex
  4508 00001F9D A3[C93C]                	mov	[pt_row+pt_ts_offset+6], ax
  4509 00001FA0 8816[CB3C]              	mov	[pt_row+pt_ts_offset+8], dl ; 'h'
  4510 00001FA4 8A440D                  	mov	al, [si+ptSectors+1]
  4511 00001FA7 E8D7FA                  	call	bin_to_hex
  4512 00001FAA A3[C73C]                	mov	[pt_row+pt_ts_offset+4], ax
  4513 00001FAD 8A440E                  	mov	al, [si+ptSectors+2]
  4514 00001FB0 E8CEFA                  	call	bin_to_hex
  4515 00001FB3 A3[C53C]                	mov	[pt_row+pt_ts_offset+2], ax
  4516 00001FB6 8A440F                  	mov	al, [si+ptSectors+3]
  4517 00001FB9 E8C5FA                  	call	bin_to_hex
  4518 00001FBC A3[C33C]                	mov	[pt_row+pt_ts_offset], ax
  4519                                  
  4520 00001FBF 8A4404                  	mov	al, [si+ptFileSystemID]
  4521 00001FC2 BF[0232]                	mov	di, valid_partitions
  4522 00001FC5 B91300                  	mov	cx, 19
  4523 00001FC8 F2AE                    	repnz	scasb
  4524 00001FCA 7405                    	jz	short ssp_1
  4525 00001FCC B8[F431]                	mov	ax, FS_OTHERS	 
  4526 00001FCF EB0C                    	jmp	short ssp_2
  4527                                  ssp_1:
  4528 00001FD1 81EF[0332]              	sub	di, valid_partitions + 1
  4529 00001FD5 B80E00                  	mov	ax, 14
  4530 00001FD8 F7E7                    	mul	di
  4531 00001FDA 05[EA30]                	add	ax, FileSys_Names
  4532                                  ssp_2:
  4533 00001FDD 96                      	xchg	ax, si 
  4534 00001FDE B107                    	mov	cl, 7
  4535 00001FE0 BF[CE3C]                	mov	di, pt_row + pt_fsn_offset
  4536 00001FE3 F3A5                    	rep	movsw
  4537 00001FE5 89C7                    	mov	di, ax ; partition table row address
  4538                                  
  4539 00001FE7 BE[4F3B]                	mov	si, msg_selected_partition
  4540 00001FEA E8F5F9                  	call	print_msg
  4541                                  
  4542 00001FED BE[303D]                	mov	si, msg_boot_indicator
  4543 00001FF0 E8EFF9                  	call	print_msg
  4544 00001FF3 BE[6640]                	mov	si, msg_yes_
  4545 00001FF6 F60580                  	test	byte [di+ptBootable], 80h
  4546 00001FF9 7503                    	jnz	short ssp_3
  4547 00001FFB BE[6B40]                	mov	si, msg_no_
  4548                                  ssp_3:
  4549 00001FFE E8E1F9                  	call	print_msg
  4550                                  
  4551 00002001 BE[483D]                	mov	si, msg_starting_head
  4552 00002004 E8DBF9                  	call	print_msg
  4553 00002007 8A4501                  	mov	al, [di+ptBeginHead]
  4554 0000200A E8AC00                  	call	write_byte_decimal
  4555 0000200D E8D2F9                  	call	print_msg
  4556 00002010 BE[603D]                	mov	si, msg_starting_sector
  4557 00002013 E8CCF9                  	call	print_msg
  4558 00002016 8A4502                  	mov	al, [di+ptBeginSector]
  4559 00002019 88C2                    	mov	dl, al  ; bits 7&8 are bits 8&9 of cyl
  4560 0000201B 243F                    	and	al, 3Fh ; sector number, 1 to 63
  4561 0000201D E89900                  	call	write_byte_decimal			
  4562 00002020 E8BFF9                  	call	print_msg	
  4563 00002023 BE[783D]                	mov	si, msg_starting_cylinder
  4564 00002026 E8B9F9                  	call	print_msg
  4565 00002029 8A4503                  	mov	al, [di+ptBeginCylinder] ; bits 0to7 of cyl
  4566 0000202C C0EA06                  	shr	dl, 6 ; bits 8&9 of cyl
  4567 0000202F 88D4                    	mov	ah, dl
  4568 00002031 31D2                    	xor	dx, dx
  4569 00002033 BE[3744]                	mov	si, msg_partition_sectors + 7 ; max. 7 digits
  4570                                  	; dx_ax: binary number
  4571 00002036 E831FA                  	call	bin_to_decimal
  4572                                  	; ds:si = decimal number text address		
  4573 00002039 E8A6F9                  	call	print_msg
  4574 0000203C BE[903D]                	mov	si, msg_system_id
  4575 0000203F E8A0F9                  	call	print_msg
  4576                                  	; Write file system name (again, copy)
  4577 00002042 BE[CE3C]                	mov	si, pt_row + pt_fsn_offset
  4578                                  	;mov	cx, 14
  4579 00002045 B10E                    	mov	cl, 14
  4580 00002047 B40E                    	mov	ah, 0Eh ; write tty
  4581 00002049 BB0700                  	mov	bx, 7
  4582                                  ssp_4:	 
  4583 0000204C AC                      	lodsb
  4584 0000204D CD10                    	int	10h
  4585 0000204F E2FB                    	loop	ssp_4
  4586                                  
  4587 00002051 BE[A83D]                	mov	si, msg_ending_head
  4588 00002054 E88BF9                  	call	print_msg
  4589 00002057 8A4505                  	mov	al, [di+ptEndHead]
  4590 0000205A E85C00                  	call	write_byte_decimal
  4591 0000205D E882F9                  	call	print_msg
  4592 00002060 BE[C03D]                	mov	si, msg_ending_sector
  4593 00002063 E87CF9                  	call	print_msg
  4594 00002066 8A4506                  	mov	al, [di+ptEndSector]
  4595 00002069 88C2                    	mov	dl, al  ; bits 7&8 are bits 8&9 of cyl
  4596 0000206B 243F                    	and	al, 3Fh ; sector number, 1 to 63
  4597 0000206D E84900                  	call	write_byte_decimal			
  4598 00002070 E86FF9                  	call	print_msg	
  4599 00002073 BE[D83D]                	mov	si, msg_ending_cylinder
  4600 00002076 E869F9                  	call	print_msg
  4601 00002079 8A4507                  	mov	al, [di+ptEndCylinder] ; bits 0to7 of cyl
  4602 0000207C C0EA06                  	shr	dl, 6 ; bits 8&9 of cyl
  4603 0000207F 88D4                    	mov	ah, dl
  4604 00002081 31D2                    	xor	dx, dx
  4605 00002083 BE[3744]                	mov	si, msg_partition_sectors + 7 ; max. 7 digits
  4606                                  	; dx_ax: binary number
  4607 00002086 E8E1F9                  	call	bin_to_decimal
  4608                                  	; ds:si = decimal number text address		
  4609 00002089 E856F9                  	call	print_msg
  4610                                  
  4611 0000208C BE[F03D]                	mov	si, msg_relative_sectors
  4612 0000208F E850F9                  	call	print_msg
  4613 00002092 8B4508                  	mov	ax, [di+ptStartSector]
  4614 00002095 8B550A                  	mov	dx, [di+ptStartSector+2]
  4615                                  	;mov	si, msg_partition_sectors + 7 ; max. 11 digits
  4616 00002098 BE[3744]                	mov	si, reserved_bytes + 10 ; max. 11 digits
  4617 0000209B E8CCF9                  	call	bin_to_decimal
  4618 0000209E E841F9                  	call	print_msg
  4619                                  
  4620 000020A1 BE[0A3E]                	mov	si, msg_total_sectors
  4621 000020A4 E83BF9                  	call	print_msg
  4622 000020A7 8B450C                  	mov	ax, [di+ptSectors]
  4623 000020AA 8B550E                  	mov	dx, [di+ptSectors+2]
  4624                                  	;mov	si, msg_partition_sectors + 7 ; max. 11 digits
  4625 000020AD BE[3744]                	mov	si, reserved_bytes + 10 ; max. 11 digits
  4626 000020B0 E8B7F9                  	call	bin_to_decimal	
  4627 000020B3 E82CF9                  	call	print_msg
  4628                                  
  4629 000020B6 89FE                    	mov	si, di  ; partition table row address
  4630 000020B8 C3                      	retn
  4631                                  
  4632                                  write_byte_decimal:
  4633                                  	; INPUT ->
  4634                                  	;	AL = binary number
  4635                                  	; OUTPUT ->
  4636                                  	;	DS:SI = decimal number text address
  4637                                  	;	        (ASCIIZ string)
  4638                                  	;
  4639                                  	; (SI, AX, CX will me modified)	
  4640                                  
  4641 000020B9 BE[3844]                	mov	si, msg_partition_sectors + 8
  4642 000020BC B10A                    	mov	cl, 10
  4643                                  wbd_loop:
  4644 000020BE 4E                      	dec	si
  4645 000020BF 30E4                    	xor	ah, ah
  4646 000020C1 F6F1                    	div	cl
  4647 000020C3 80C430                  	add	ah, '0'
  4648 000020C6 8824                    	mov	[si], ah
  4649 000020C8 20C0                    	and	al, al
  4650 000020CA 75F2                    	jnz	short wbd_loop
  4651 000020CC C3                      	retn
  4652                                  
  4653                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4654                                  ;  Data
  4655                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4656                                  
  4657 000020CD 00                      	db	0
  4658                                  
  4659                                  TRDOS386_MASTERBOOT_SECTOR:
  4660 000020CE <incbin>                	incbin	'FS1_MBR.BIN' ; Singlix FS1 MBR	
  4661                                  
  4662                                  TRDOS_FAT_hd_bs:
  4663                                  	;incbin 'TRHDBS.BIN'
  4664 000022CE <incbin>                	incbin	'TRFDBS.BIN' ; temporary !
  4665                                  TRDOS_FAT32_hd_bs:
  4666 000024CE <incbin>                	incbin	'FAT32_BS.BIN'
  4667                                  TRDOS_FAT16_hd_bs: 
  4668 000028CE <incbin>                	incbin	'FAT16_BS.BIN'
  4669                                  TRDOS_FAT12_hd_bs: 
  4670 00002ACE <incbin>                	incbin	'FAT12_BS.BIN'
  4671                                  
  4672                                  TRDOS_TRFS1_chs_bs:
  4673 00002CCE <incbin>                	incbin	'TRFS1CHS.BIN' ; Singlix FS1 (CHS+LBA Disk) BS		
  4674                                  TRDOS_TRFS1_lba_bs:
  4675 00002ECE <incbin>                	incbin	'TRFS1LBA.BIN' ; Singlix FS1 (LBA Disk) BS	
  4676                                  
  4677 000030CE 00                      	db	0
  4678                                  
  4679                                  hexchrs:
  4680 000030CF 303132333435363738-     	db	'0123456789ABCDEF'
  4680 000030D8 39414243444546     
  4681                                  
  4682 000030DF 90                      align 2
  4683                                  
  4684                                  img_file_handle:
  4685 000030E0 0000                    	dw	0
  4686                                  
  4687                                  ; (TR-DOS 386 compatible) Hard Disk (image) parameters
  4688                                  
  4689                                  sectors: ; sectors per track (63)
  4690 000030E2 3F00                    	dw 63
  4691                                  heads:	 ; number of heads (16 or 32 or 64) 
  4692 000030E4 1000                    	dw 16
  4693                                  cylinders: ; number of cylinders (16 to 1024)
  4694 000030E6 0004                    	dw 1024
  4695                                  
  4696                                  random:
  4697 000030E8 00                      	db	0  ; random write to file (0 = sequental)
  4698                                  newdisk:
  4699 000030E9 00                      	db	0
  4700                                  
  4701                                  FileSys_Names: ; 2003-2017
  4702                                  ; (Valid FileSystems for TRDOS 386, SINGLIX, RETRO UNIX OS projects in 2017)
  4703 000030EA 464154313220202020-     FS_FAT12:     db "FAT12         "  ; 01h = FAT12
  4703 000030F3 2020202020         
  4704 000030F8 58454E495820202020-     FS_XENIX:     db "XENIX         "  ; 02h , XENIX System V root
  4704 00003101 2020202020         
  4705 00003106 58454E495820757372-     FS_XENIX_USR: db "XENIX usr     "  ; 03h , XENIX System V user
  4705 0000310F 2020202020         
  4706 00003114 464154313620283034-     FS_FAT16:     db "FAT16 (04h)   "  ; 04h = FAT16 < 32MB
  4706 0000311D 6829202020         
  4707 00003122 455854454E44454420-     FS_EXT_CHS:   db "EXTENDED (CHS)"  ; 05h = Extended DOS Partition
  4707 0000312B 2843485329         
  4708 00003130 464154313620283036-     FS_FAT16_BIG: db "FAT16 (06h)   "  ; 06h = FAT16 > 32MB, CHS mode
  4708 00003139 6829202020         
  4709 0000313E 4E5446532020202020-     FS_NTFS:      db "NTFS          "  ; 07h , WINDOWS NTFS Partition
  4709 00003147 2020202020         
  4710 0000314C 464154333220284348-     FS_FAT32_CHS: db "FAT32 (CHS)   "  ; 0Bh = FAT32, CHS mode
  4710 00003155 5329202020         
  4711 0000315A 464154333220284C42-     FS_FAT32_LBA: db "FAT32 (LBA)   "  ; 0Ch = FAT32, LBA mode
  4711 00003163 4129202020         
  4712 00003168 464154313620284C42-     FS_FAT16_LBA: db "FAT16 (LBA)   "  ; 0Eh = FAT16, LBA mode
  4712 00003171 4129202020         
  4713 00003176 455854454E44454420-     FS_EXT_LBA:   db "EXTENDED (LBA)"  ; 0Fh = Extented Partition, LBA mode
  4713 0000317F 284C424129         
  4714 00003184 554E49582053595354-     FS_UNIX_SYSV: db "UNIX SYSTEM V "  ; 63h , SCO UNIX, UNIXWARE, OPENSERVER
  4714 0000318D 454D205620         
  4715 00003192 524554524F20554E49-     FS_RETROUNIX: db "RETRO UNIX    "  ; 71h , Retro UNIX 386 v2 Partition
  4715 0000319B 5820202020         
  4716 000031A0 554E49582056372020-     FS_UNIX_V7:   db "UNIX V7       "  ; 72h , UNIX v7 x86 Partition  
  4716 000031A9 2020202020         
  4717 000031AE 4C494E555820535741-     FS_LINUXSWAP: db "LINUX SWAP    "  ; 82h , LINUX SWAP Partition
  4717 000031B7 5020202020         
  4718 000031BC 4C494E555820202020-     FS_LINUX:     db "LINUX         "  ; 83h , LINUX NATIVE (ext2) Partition
  4718 000031C5 2020202020         
  4719 000031CA 4C494E555820455854-     FS_LINUXEXT:  db "LINUX EXTENDED"  ; 85h , LINUX EXTENDED Partition
  4719 000031D3 454E444544         
  4720 000031D8 524444202020202020-     RS_TRDD:      db "RDD           "  ; A0h , (Random Data Disk) LBA
  4720 000031E1 2020202020         
  4721 000031E6 53494E474C49582046-     FS_TRFS:      db "SINGLIX FS1   "  ; A1h , (32 bit, 512 bytes per sector)
  4721 000031EF 5331202020         
  4722 000031F4 554E4B4E4F574E2046-     FS_OTHERS:    db "UNKNOWN FS    "  ; Another or Unknown File Systems
  4722 000031FD 5320202020         
  4723                                   
  4724                                  valid_partitions: ; (*)
  4725 00003202 01020304050607          	      db 01h, 02h, 03h, 04h, 05h, 06h, 07h
  4726 00003209 0B0C0E0F637172          	      db 0Bh, 0Ch, 0Eh, 0Fh, 63h, 71h, 72h
  4727 00003210 828385A0A1              	      db 82h, 83h, 85h, 0A0h, 0A1h 			
  4728                                  
  4729                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4730                                  ;  Messages
  4731                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4732                                  
  4733                                  CHS_msg: ; 80 bytes per row
  4734 00003215 507265737320274327-     db  "Press 'C' to set cylinders then press '+,-' keys to change number of cylinders. " 
  4734 0000321E 20746F207365742063-
  4734 00003227 796C696E6465727320-
  4734 00003230 7468656E2070726573-
  4734 00003239 7320272B2C2D27206B-
  4734 00003242 65797320746F206368-
  4734 0000324B 616E6765206E756D62-
  4734 00003254 6572206F662063796C-
  4734 0000325D 696E646572732E20   
  4735 00003265 507265737320274827-     db  "Press 'H' to set heads then press '+,-' keys to change number of heads.         " 
  4735 0000326E 20746F207365742068-
  4735 00003277 65616473207468656E-
  4735 00003280 20707265737320272B-
  4735 00003289 2C2D27206B65797320-
  4735 00003292 746F206368616E6765-
  4735 0000329B 206E756D626572206F-
  4735 000032A4 662068656164732E20-
  4735 000032AD 2020202020202020   
  4736 000032B5 507265737320275327-     db  "Press 'S' to set sectors then press '+,-' keys to change numb of sectors/track. " 
  4736 000032BE 20746F207365742073-
  4736 000032C7 6563746F7273207468-
  4736 000032D0 656E20707265737320-
  4736 000032D9 272B2C2D27206B6579-
  4736 000032E2 7320746F206368616E-
  4736 000032EB 6765206E756D62206F-
  4736 000032F4 6620736563746F7273-
  4736 000032FD 2F747261636B2E20   
  4737 00003305 202020202020202020-     db  "                                                                                " 
  4737 0000330E 202020202020202020-
  4737 00003317 202020202020202020-
  4737 00003320 202020202020202020-
  4737 00003329 202020202020202020-
  4737 00003332 202020202020202020-
  4737 0000333B 202020202020202020-
  4737 00003344 202020202020202020-
  4737 0000334D 2020202020202020   
  4738 00003355 202020202020202020-     db  "                                                                                " 
  4738 0000335E 202020202020202020-
  4738 00003367 202020202020202020-
  4738 00003370 202020202020202020-
  4738 00003379 202020202020202020-
  4738 00003382 202020202020202020-
  4738 0000338B 202020202020202020-
  4738 00003394 202020202020202020-
  4738 0000339D 2020202020202020   
  4739 000033A5 507265737320454E54-     db  "Press ENTER to use current CHS values.                                          "
  4739 000033AE 455220746F20757365-
  4739 000033B7 2063757272656E7420-
  4739 000033C0 4348532076616C7565-
  4739 000033C9 732E20202020202020-
  4739 000033D2 202020202020202020-
  4739 000033DB 202020202020202020-
  4739 000033E4 202020202020202020-
  4739 000033ED 2020202020202020   
  4740 000033F5 202020202020202020-     db  "                                                                                " 
  4740 000033FE 202020202020202020-
  4740 00003407 202020202020202020-
  4740 00003410 202020202020202020-
  4740 00003419 202020202020202020-
  4740 00003422 202020202020202020-
  4740 0000342B 202020202020202020-
  4740 00003434 202020202020202020-
  4740 0000343D 2020202020202020   
  4741 00003445 507265737320455343-     db  "Press ESC to cancel.                                                            "
  4741 0000344E 20746F2063616E6365-
  4741 00003457 6C2E20202020202020-
  4741 00003460 202020202020202020-
  4741 00003469 202020202020202020-
  4741 00003472 202020202020202020-
  4741 0000347B 202020202020202020-
  4741 00003484 202020202020202020-
  4741 0000348D 2020202020202020   
  4742 00003495 202020202020202020-     db  "                                                                                " 
  4742 0000349E 202020202020202020-
  4742 000034A7 202020202020202020-
  4742 000034B0 202020202020202020-
  4742 000034B9 202020202020202020-
  4742 000034C2 202020202020202020-
  4742 000034CB 202020202020202020-
  4742 000034D4 202020202020202020-
  4742 000034DD 2020202020202020   
  4743 000034E5 00                      db  0
  4744                                  
  4745                                  TrDOS_Welcome:
  4746 000034E6 0D0A                    	db	0Dh, 0Ah
  4747 000034E8 54522D444F53203338-     	db	'TR-DOS 386 Fixed Disk Image Format Utility'
  4747 000034F1 362046697865642044-
  4747 000034FA 69736B20496D616765-
  4747 00003503 20466F726D61742055-
  4747 0000350C 74696C697479       
  4748 00003512 0D0A                    	db	0Dh, 0Ah
  4749 00003514 76312E302E30333032-     	db	"v1.0.030218  (c) Erdogan TAN 2018"
  4749 0000351D 313820202863292045-
  4749 00003526 72646F67616E205441-
  4749 0000352F 4E2032303138       
  4750 00003535 0D0A                    	db	0Dh,0Ah
  4751 00003537 0D0A                    	db	0Dh,0Ah
  4752 00003539 55736167653A206864-     	db	'Usage: hdimage <image file name> '
  4752 00003542 696D616765203C696D-
  4752 0000354B 6167652066696C6520-
  4752 00003554 6E616D653E20       
  4753 0000355A 00                      	db	0
  4754                                  
  4755                                  msg_inv_file_name: 
  4756 0000355B 0D0A                    	db	0Dh, 0Ah
  4757 0000355D 496E76616C69642066-     	db	"Invalid file name !", 0Dh, 0Ah
  4757 00003566 696C65206E616D6520-
  4757 0000356F 210D0A             
  4758 00003572 2846696C65206E616D-     	db	"(File name must fit to 8.3 DOS format) !"
  4758 0000357B 65206D757374206669-
  4758 00003584 7420746F20382E3320-
  4758 0000358D 444F5320666F726D61-
  4758 00003596 74292021           
  4759 0000359A 0D0A00                  	db	0Dh, 0Ah, 0
  4760                                  
  4761                                  msg_inv_image_file:
  4762 0000359D 0D0A                    	db	0Dh, 0Ah
  4763 0000359F 496E76616C69642066-     	db	"Invalid fixed disk image file !", 0Dh, 0Ah
  4763 000035A8 69786564206469736B-
  4763 000035B1 20696D616765206669-
  4763 000035BA 6C6520210D0A       
  4764 000035C0 2846696C652073697A-     	db	"(File size or masterboot sector is not compatible) !"
  4764 000035C9 65206F72206D617374-
  4764 000035D2 6572626F6F74207365-
  4764 000035DB 63746F72206973206E-
  4764 000035E4 6F7420636F6D706174-
  4764 000035ED 69626C65292021     
  4765 000035F4 0D0A00                  	db	0Dh, 0Ah, 0  
  4766                                  
  4767                                  msg_min_8mb_disk:
  4768 000035F7 0D0A                    	db	0Dh, 0Ah
  4769 000035F9 4D696E696D756D2038-     	db	"Minimum 8 MB disk size is needed for a proper hard disk image !"
  4769 00003602 204D42206469736B20-
  4769 0000360B 73697A65206973206E-
  4769 00003614 656564656420666F72-
  4769 0000361D 20612070726F706572-
  4769 00003626 206861726420646973-
  4769 0000362F 6B20696D6167652021 
  4770 00003638 0D0A                    	db	0Dh, 0Ah
  4771 0000363A 28507265737320616E-     	db	"(Press any key to continue..)" 
  4771 00003643 79206B657920746F20-
  4771 0000364C 636F6E74696E75652E-
  4771 00003655 2E29               
  4772 00003657 0D0A00                  	db	0Dh, 0Ah, 0
  4773                                  
  4774                                  msg_any_key_esc_exit:
  4775 0000365A 0D0A                    	db	0Dh, 0Ah
  4776 0000365C 507265737320455343-     	db	"Press ESC to exit or press another key to continue..."
  4776 00003665 20746F206578697420-
  4776 0000366E 6F7220707265737320-
  4776 00003677 616E6F74686572206B-
  4776 00003680 657920746F20636F6E-
  4776 00003689 74696E75652E2E2E   
  4777 00003691 00                      	db	0
  4778                                  
  4779                                  msg_create_trdos_partition_h:
  4780 00003692 0D0A                    	db	0Dh, 0Ah
  4781 00003694 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"
  4781 0000369D 2D2D2D2D2D2D2D2D2D-
  4781 000036A6 2D2D2D2D2D2D2D2D2D-
  4781 000036AF 2D2D2D2D2D2D2D2D2D-
  4781 000036B8 2D2D2D2D2D2D2D2D2D-
  4781 000036C1 2D2D2D2D2D2D2D2D2D-
  4781 000036CA 2D2D2D2D2D2D2D2D2D-
  4781 000036D3 2D2D2D2D2D2D2D2D2D-
  4781 000036DC 2D2D2D2D2D2D2D2D   
  4782 000036E4 202020202020202020-     	db	"                       Create Primary (DOS) Partition                           "
  4782 000036ED 202020202020202020-
  4782 000036F6 202020202043726561-
  4782 000036FF 7465205072696D6172-
  4782 00003708 792028444F53292050-
  4782 00003711 6172746974696F6E20-
  4782 0000371A 202020202020202020-
  4782 00003723 202020202020202020-
  4782 0000372C 2020202020202020   
  4783 00003734 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"	
  4783 0000373D 2D2D2D2D2D2D2D2D2D-
  4783 00003746 2D2D2D2D2D2D2D2D2D-
  4783 0000374F 2D2D2D2D2D2D2D2D2D-
  4783 00003758 2D2D2D2D2D2D2D2D2D-
  4783 00003761 2D2D2D2D2D2D2D2D2D-
  4783 0000376A 2D2D2D2D2D2D2D2D2D-
  4783 00003773 2D2D2D2D2D2D2D2D2D-
  4783 0000377C 2D2D2D2D2D2D2D2D   
  4784 00003784 0D0A00                  	db	0Dh, 0Ah, 0	
  4785                                  msg_create_trdos_partition_m:
  4786 00003787 53656C65637420616E-     	db	"Select an option: "
  4786 00003790 206F7074696F6E3A20 
  4787 00003799 0D0A                    	db	0Dh, 0Ah
  4788 0000379B 0D0A                    	db	0Dh, 0Ah
  4789 0000379D 202031292043726561-     	db	"  1) Create FAT 16 partition ", 0Dh, 0Ah
  4789 000037A6 746520464154203136-
  4789 000037AF 20706172746974696F-
  4789 000037B8 6E200D0A           
  4790 000037BC 202032292043726561-     	db	"  2) Create FAT 32 partition ", 0Dh, 0Ah
  4790 000037C5 746520464154203332-
  4790 000037CE 20706172746974696F-
  4790 000037D7 6E200D0A           
  4791 000037DB 202033292043726561-     	db	"  3) Create SINGLIX FS partition ", 0Dh, 0Ah			
  4791 000037E4 74652053494E474C49-
  4791 000037ED 582046532070617274-
  4791 000037F6 6974696F6E200D0A   
  4792 000037FE 202034292043726561-     	db	"  4) Create RETRO UNIX partition ", 0Dh, 0Ah
  4792 00003807 746520524554524F20-
  4792 00003810 554E49582070617274-
  4792 00003819 6974696F6E200D0A   
  4793 00003821 202035292043726561-     	db	"  5) Create another type of partition ", 0Dh, 0Ah 		
  4793 0000382A 746520616E6F746865-
  4793 00003833 722074797065206F66-
  4793 0000383C 20706172746974696F-
  4793 00003845 6E200D0A           
  4794 00003849 0D0A                    	db	0Dh, 0Ah	
  4795 0000384B 507265737320455343-     	db	"Press ESC or 0 to exit .. "
  4795 00003854 206F72203020746F20-
  4795 0000385D 65786974202E2E20   
  4796 00003865 0D0A00                   	db 	0Dh, 0Ah, 0
  4797                                  
  4798                                  msg_create_trdos_partition_s:
  4799 00003868 53656C65637420616E-     	db	"Select an option to set partition size: "
  4799 00003871 206F7074696F6E2074-
  4799 0000387A 6F2073657420706172-
  4799 00003883 746974696F6E207369-
  4799 0000388C 7A653A20           
  4800 00003890 0D0A                    	db	0Dh, 0Ah
  4801 00003892 0D0A                    	db	0Dh, 0Ah
  4802 00003894 202043292043796C69-     	db	"  C) Cylinder count", 0Dh, 0Ah   
  4802 0000389D 6E64657220636F756E-
  4802 000038A6 740D0A             
  4803 000038A9 2020252920566F6C75-     	db	"  %) Volume percentage (##%)", 0Dh, 0Ah
  4803 000038B2 6D652070657263656E-
  4803 000038BB 746167652028232325-
  4803 000038C4 290D0A             
  4804 000038C7 202053292053656374-     	db	"  S) Sectors (number of 512 bytes)", 0Dh, 0Ah
  4804 000038D0 6F727320286E756D62-
  4804 000038D9 6572206F6620353132-
  4804 000038E2 206279746573290D0A 
  4805 000038EB 20204B29204B696C6F-     	db	"  K) Kilo bytes (KB, 2*K sectors)", 0Dh, 0Ah
  4805 000038F4 20627974657320284B-
  4805 000038FD 422C20322A4B207365-
  4805 00003906 63746F7273290D0A   
  4806 0000390E 20204D29204D656761-     	db	"  M) Mega bytes (MB, 2*1024*M sectors)", 0Dh, 0Ah
  4806 00003917 20627974657320284D-
  4806 00003920 422C20322A31303234-
  4806 00003929 2A4D20736563746F72-
  4806 00003932 73290D0A           
  4807 00003936 202047292047696761-     	db	"  G) Giga bytes (GB, 2*1024*1024*G sectors)", 0Dh, 0Ah			
  4807 0000393F 206279746573202847-
  4807 00003948 422C20322A31303234-
  4807 00003951 2A313032342A472073-
  4807 0000395A 6563746F7273290D0A 
  4808 00003963 0D0A                    	db	0Dh, 0Ah	
  4809 00003965 507265737320455343-     	db	"Press ESC to use whole disk or press ENTER to set sector count .. "
  4809 0000396E 20746F207573652077-
  4809 00003977 686F6C65206469736B-
  4809 00003980 206F72207072657373-
  4809 00003989 20454E54455220746F-
  4809 00003992 207365742073656374-
  4809 0000399B 6F7220636F756E7420-
  4809 000039A4 2E2E20             
  4810 000039A7 0D0A00                   	db 	0Dh, 0Ah, 0
  4811                                  
  4812                                  msg_use_whole_disk:
  4813 000039AA 446F20796F75207761-     	db	"Do you want to use WHOLE disk !? (Y/N)"
  4813 000039B3 6E7420746F20757365-
  4813 000039BC 2057484F4C45206469-
  4813 000039C5 736B20213F2028592F-
  4813 000039CE 4E29               
  4814 000039D0 0D0A00                  	db	0Dh, 0Ah, 0
  4815                                  
  4816                                  msg_partition_size:
  4817 000039D3 0D0A                    	db	0Dh, 0Ah
  4818 000039D5 0D0A                    	db	0Dh, 0Ah
  4819 000039D7 506172746974696F6E-     	db	"Partition size ("
  4819 000039E0 2073697A652028     
  4820                                  msg_partition_size_x:
  4821 000039E7 3F29203A20              	db	"?) : "
  4822 000039EC 00                      	db	0
  4823                                  
  4824                                  msg_partition_type:
  4825 000039ED 0D0A                    	db	0Dh, 0Ah
  4826 000039EF 0D0A                    	db	0Dh, 0Ah
  4827 000039F1 506172746974696F6E-     	db	"Partition type : "
  4827 000039FA 2074797065203A20   
  4828 00003A02 00                      	db	0
  4829                                  
  4830                                  msg_ptype_num:
  4831 00003A03 3030680D0A00            	db	"00h", 0Dh, 0Ah, 0
  4832                                  
  4833                                  msg_partition_type_error:
  4834 00003A09 506172746974696F6E-     	db	"Partition size is not proper for selected partition type !"
  4834 00003A12 2073697A6520697320-
  4834 00003A1B 6E6F742070726F7065-
  4834 00003A24 7220666F722073656C-
  4834 00003A2D 656374656420706172-
  4834 00003A36 746974696F6E207479-
  4834 00003A3F 70652021           
  4835 00003A43 0D0A                    	db	0Dh, 0Ah
  4836 00003A45 28507265737320616E-     	db	"(Press any key to retry..)" 
  4836 00003A4E 79206B657920746F20-
  4836 00003A57 72657472792E2E29   
  4837 00003A5F 0D0A00                  	db	0Dh, 0Ah, 0
  4838                                  
  4839                                  msg_partition_size_overs:
  4840 00003A62 0D0A                    	db	0Dh, 0Ah
  4841 00003A64 506172746974696F6E-     	db	"Partition size overs the disk capacity !"
  4841 00003A6D 2073697A65206F7665-
  4841 00003A76 727320746865206469-
  4841 00003A7F 736B20636170616369-
  4841 00003A88 74792021           
  4842 00003A8C 0D0A                    	db	0Dh, 0Ah
  4843 00003A8E 28507265737320454E-     	db	"(Press ENTER to use WHOLE disk or press ESC key to retry..)" 
  4843 00003A97 54455220746F207573-
  4843 00003AA0 652057484F4C452064-
  4843 00003AA9 69736B206F72207072-
  4843 00003AB2 65737320455343206B-
  4843 00003ABB 657920746F20726574-
  4843 00003AC4 72792E2E29         
  4844 00003AC9 0D0A00                  	db	0Dh, 0Ah, 0
  4845                                  
  4846                                  msg_cylinder_boundary_set:
  4847 00003ACC 0D0A                    	db	0Dh, 0Ah
  4848 00003ACE 446F20796F75207761-     	db	"Do you want to adjust partition size to cylinder boundary ? (Y/N)"
  4848 00003AD7 6E7420746F2061646A-
  4848 00003AE0 757374207061727469-
  4848 00003AE9 74696F6E2073697A65-
  4848 00003AF2 20746F2063796C696E-
  4848 00003AFB 64657220626F756E64-
  4848 00003B04 617279203F2028592F-
  4848 00003B0D 4E29               
  4849 00003B0F 00                      	db	0
  4850                                  msg_cylinder_boundary_updown:
  4851 00003B10 0D0A                    	db	0Dh, 0Ah
  4852 00003B12 507265737320272B27-     	db	"Press '+' to adjust to up or press '-' to adjust to down.."
  4852 00003B1B 20746F2061646A7573-
  4852 00003B24 7420746F207570206F-
  4852 00003B2D 722070726573732027-
  4852 00003B36 2D2720746F2061646A-
  4852 00003B3F 75737420746F20646F-
  4852 00003B48 776E2E2E           
  4853 00003B4C 0D0A00                  	db	0Dh, 0Ah, 0	
  4854                                  
  4855                                  msg_selected_partition:
  4856 00003B4F 202020202020202020-     	db	"                                 PARTITION 0                                    "
  4856 00003B58 202020202020202020-
  4856 00003B61 202020202020202020-
  4856 00003B6A 202020202020504152-
  4856 00003B73 544954494F4E203020-
  4856 00003B7C 202020202020202020-
  4856 00003B85 202020202020202020-
  4856 00003B8E 202020202020202020-
  4856 00003B97 2020202020202020   
  4857 00003B9F 3D3D3D3D3D3D3D3D3D-     	db	"================================================================================"
  4857 00003BA8 3D3D3D3D3D3D3D3D3D-
  4857 00003BB1 3D3D3D3D3D3D3D3D3D-
  4857 00003BBA 3D3D3D3D3D3D3D3D3D-
  4857 00003BC3 3D3D3D3D3D3D3D3D3D-
  4857 00003BCC 3D3D3D3D3D3D3D3D3D-
  4857 00003BD5 3D3D3D3D3D3D3D3D3D-
  4857 00003BDE 3D3D3D3D3D3D3D3D3D-
  4857 00003BE7 3D3D3D3D3D3D3D3D   
  4858 00003BEF 202020202020202053-     	db	"        S  BH  BS  BC  FS  EH  ES  EC    START SEC   SECTORS   FILE SYSTEM      "
  4858 00003BF8 202042482020425320-
  4858 00003C01 204243202046532020-
  4858 00003C0A 454820204553202045-
  4858 00003C13 432020202053544152-
  4858 00003C1C 542053454320202053-
  4858 00003C25 4543544F5253202020-
  4858 00003C2E 46494C452053595354-
  4858 00003C37 454D202020202020   
  4859 00003C3F 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"
  4859 00003C48 2D2D2D2D2D2D2D2D2D-
  4859 00003C51 2D2D2D2D2D2D2D2D2D-
  4859 00003C5A 2D2D2D2D2D2D2D2D2D-
  4859 00003C63 2D2D2D2D2D2D2D2D2D-
  4859 00003C6C 2D2D2D2D2D2D2D2D2D-
  4859 00003C75 2D2D2D2D2D2D2D2D2D-
  4859 00003C7E 2D2D2D2D2D2D2D2D2D-
  4859 00003C87 2D2D2D2D2D2D2D2D   
  4860 00003C8F 202020202020202020-     pt_row:	db	"                                                                                "
  4860 00003C98 202020202020202020-
  4860 00003CA1 202020202020202020-
  4860 00003CAA 202020202020202020-
  4860 00003CB3 202020202020202020-
  4860 00003CBC 202020202020202020-
  4860 00003CC5 202020202020202020-
  4860 00003CCE 202020202020202020-
  4860 00003CD7 2020202020202020   
  4861 00003CDF 3D3D3D3D3D3D3D3D3D-     	db	"================================================================================"
  4861 00003CE8 3D3D3D3D3D3D3D3D3D-
  4861 00003CF1 3D3D3D3D3D3D3D3D3D-
  4861 00003CFA 3D3D3D3D3D3D3D3D3D-
  4861 00003D03 3D3D3D3D3D3D3D3D3D-
  4861 00003D0C 3D3D3D3D3D3D3D3D3D-
  4861 00003D15 3D3D3D3D3D3D3D3D3D-
  4861 00003D1E 3D3D3D3D3D3D3D3D3D-
  4861 00003D27 3D3D3D3D3D3D3D3D   
  4862 00003D2F 00                      	db	0
  4863                                  msg_boot_indicator:
  4864 00003D30 0D0A                    	db	0Dh, 0Ah
  4865 00003D32 20202020426F6F7420-     	db	"    Boot Indicator : ", 0 ; "YES", "NO"
  4865 00003D3B 496E64696361746F72-
  4865 00003D44 203A2000           
  4866                                  msg_starting_head:
  4867 00003D48 0D0A                    	db	0Dh, 0Ah
  4868 00003D4A 202020202053746172-     	db 	"     Starting Head : ", 0
  4868 00003D53 74696E672048656164-
  4868 00003D5C 203A2000           
  4869                                  msg_starting_sector:
  4870 00003D60 0D0A                    	db	0Dh, 0Ah
  4871 00003D62 202020537461727469-     	db	"   Starting Sector : ", 0
  4871 00003D6B 6E6720536563746F72-
  4871 00003D74 203A2000           
  4872                                  msg_starting_cylinder:
  4873 00003D78 0D0A                    	db	0Dh, 0Ah
  4874 00003D7A 205374617274696E67-     	db	" Starting Cylinder : ", 0
  4874 00003D83 2043796C696E646572-
  4874 00003D8C 203A2000           
  4875                                  msg_system_id:
  4876 00003D90 0D0A                    	db	0Dh, 0Ah
  4877 00003D92 202020202020202020-     	db	"         System ID : ", 0
  4877 00003D9B 53797374656D204944-
  4877 00003DA4 203A2000           
  4878                                  msg_ending_head:
  4879 00003DA8 0D0A                    	db	0Dh, 0Ah
  4880 00003DAA 20202020202020456E-     	db 	"       Ending Head : ", 0
  4880 00003DB3 64696E672048656164-
  4880 00003DBC 203A2000           
  4881                                  msg_ending_sector:
  4882 00003DC0 0D0A                    	db	0Dh, 0Ah
  4883 00003DC2 2020202020456E6469-     	db	"     Ending Sector : ", 0
  4883 00003DCB 6E6720536563746F72-
  4883 00003DD4 203A2000           
  4884                                  msg_ending_cylinder:
  4885 00003DD8 0D0A                    	db	0Dh, 0Ah
  4886 00003DDA 202020456E64696E67-     	db	"   Ending Cylinder : ", 0
  4886 00003DE3 2043796C696E646572-
  4886 00003DEC 203A2000           
  4887                                  msg_relative_sectors:
  4888 00003DF0 0D0A                    	db	0Dh, 0Ah
  4889 00003DF2 0D0A                    	db	0Dh, 0Ah
  4890 00003DF4 202052656C61746976-     	db	"  Relative Sectors : ", 0
  4890 00003DFD 6520536563746F7273-
  4890 00003E06 203A2000           
  4891                                  msg_total_sectors:
  4892 00003E0A 0D0A                    	db	0Dh, 0Ah
  4893 00003E0C 2020202020546F7461-     	db	"     Total Sectors : ", 0
  4893 00003E15 6C20536563746F7273-
  4893 00003E1E 203A2000           
  4894                                  
  4895                                  msg_format_stage:
  4896 00003E22 0D0A                    	db	0Dh, 0Ah
  4897 00003E24 507265737320454E54-     	db	"Press ENTER to FORMAT disk partition "
  4897 00003E2D 455220746F20464F52-
  4897 00003E36 4D4154206469736B20-
  4897 00003E3F 706172746974696F6E-
  4897 00003E48 20                 
  4898                                  partition_num_chr:
  4899 00003E49 30                      	db	"0"
  4900 00003E4A 206F72207072657373-     	db	" or press ESC to EXIT.."
  4900 00003E53 2045534320746F2045-
  4900 00003E5C 5849542E2E         
  4901 00003E61 00                      	db	0
  4902                                  msg_partition_edit:
  4903 00003E62 0D0A                    	db	0Dh, 0Ah
  4904 00003E64 2E2E206F7220707265-     	db	".. or press SPACE to EDIT partition table."
  4904 00003E6D 737320535041434520-
  4904 00003E76 746F20454449542070-
  4904 00003E7F 6172746974696F6E20-
  4904 00003E88 7461626C652E       
  4905 00003E8E 0D0A00                  	db	0Dh, 0Ah, 0
  4906                                  
  4907                                  msg_edit_or_exit:
  4908 00003E91 0D0A                    	db 	0Dh, 0Ah
  4909 00003E93 507265737320454E54-     	db	"Press ENTER to continue or press ESC to exit.."
  4909 00003E9C 455220746F20636F6E-
  4909 00003EA5 74696E7565206F7220-
  4909 00003EAE 707265737320455343-
  4909 00003EB7 20746F20657869742E-
  4909 00003EC0 2E                 
  4910 00003EC1 00                      	db	0
  4911                                  
  4912                                  msg_overwrite_question1:
  4913 00003EC2 0D0A                    	db	0Dh, 0Ah
  4914 00003EC4 446F20796F75207761-     	db	'Do you want to overwrite '
  4914 00003ECD 6E7420746F206F7665-
  4914 00003ED6 72777269746520     
  4915 00003EDD 27                      	db	27h
  4916 00003EDE 00                      	db	0
  4917                                  
  4918                                  msg_overwrite_question2: 
  4919 00003EDF 27                      	db	27h
  4920 00003EE0 2066696C6520            	db	' file '
  4921 00003EE6 00                      	db	0
  4922                                  
  4923                                  msg_format_question:
  4924 00003EE7 0D0A                    	db	0Dh, 0Ah
  4925 00003EE9 446F20796F75207761-     	db	"Do you want to format partition "
  4925 00003EF2 6E7420746F20666F72-
  4925 00003EFB 6D6174207061727469-
  4925 00003F04 74696F6E20         
  4926                                  partition_num_txt:
  4927 00003F09 3020                    	db	 "0 "
  4928                                  msg_yes_no:
  4929 00003F0B 285965732F4E6F293F-     	db	'(Yes/No)? ', 0		
  4929 00003F14 2000               
  4930                                  
  4931                                  msg_writing_mbr:
  4932 00003F16 57726974696E67206D-     	db	"Writing masterboot sector...", 0
  4932 00003F1F 6173746572626F6F74-
  4932 00003F28 20736563746F722E2E-
  4932 00003F31 2E00               
  4933                                  
  4934                                  msg_writing_disk_sectors:
  4935 00003F33 57726974696E672064-     	db	"Writing disk sector: ", 0
  4935 00003F3C 69736B20736563746F-
  4935 00003F45 723A2000           
  4936                                  
  4937                                  Msg_Writing_Boot_Sector:
  4938 00003F49 57726974696E672074-     	db	"Writing trdos boot sector...", 0
  4938 00003F52 72646F7320626F6F74-
  4938 00003F5B 20736563746F722E2E-
  4938 00003F64 2E00               
  4939                                  
  4940                                  Msg_Writing_Root_Dir:
  4941 00003F66 57726974696E672072-     	db	"Writing root directory sectors...", 0
  4941 00003F6F 6F6F74206469726563-
  4941 00003F78 746F72792073656374-
  4941 00003F81 6F72732E2E2E00     
  4942                                  
  4943                                  Msg_Writing_Data_Sectors:
  4944 00003F88 57726974696E672064-     	db	"Writing data sector: ", 0
  4944 00003F91 61746120736563746F-
  4944 00003F9A 723A2000           
  4945                                  
  4946                                  Sector_Str:
  4947 00003F9E 3030303030303000        	db	"0000000", 0
  4948                                  Cursor_Pos:
  4949 00003FA6 0000                    	dw	0
  4950                                  
  4951                                  Msg_Writing_FAT_Sectors:
  4952 00003FA8 57726974696E672046-     	db	"Writing FAT sectors...", 0
  4952 00003FB1 415420736563746F72-
  4952 00003FBA 732E2E2E00         
  4953                                  
  4954                                  StrVolumeName:
  4955                                  	;times 	12 db  0
  4956 00003FBF 00<rept>                	times	65 db 0  ; 05/01/2018 (fs1 volume name)	
  4957                                  
  4958                                  Msg_Volume_Name:
  4959 00004000 0D0A                    	db	0Dh, 0Ah
  4960 00004002 0D0A                    	db	0Dh, 0Ah
  4961 00004004 566F6C756D65204E61-     	db	"Volume Name: ", 0
  4961 0000400D 6D653A2000         
  4962                                  
  4963                                  Msg_Volume_Serial:
  4964 00004012 566F6C756D65205365-     	db	"Volume Serial No: "
  4964 0000401B 7269616C204E6F3A20 
  4965                                  Vol_Serial1:
  4966 00004024 30303030                	db	"0000"
  4967 00004028 2D                      	db	"-"
  4968                                  Vol_Serial2:
  4969 00004029 30303030                	db	"0000"
  4970 0000402D 0D0A00                  	db	0Dh, 0Ah, 0
  4971                                  
  4972                                  msg_cluster_count:
  4973 00004030 436C75737465722043-     	db	"Cluster Count: ", 0
  4973 00004039 6F756E743A2000     
  4974                                  cluster_count_str:
  4975 00004040 30303030303030          	db	"0000000"
  4976 00004047 0D0A00                  	db	0Dh, 0Ah, 0
  4977                                  msg_formatting:
  4978 0000404A 466F726D617474696E-     	db	"Formatting ", 0
  4978 00004053 672000             
  4979                                  format_percent_str:
  4980 00004056 30303025                	db	"000%"
  4981 0000405A 00                      	db	0					
  4982                                  
  4983                                  Msg_3dot_OK:
  4984 0000405B 2E2E2E                  	db	"..."
  4985                                  Msg_OK:
  4986 0000405E 204F4B2E                	db	' OK.'
  4987                                  CRLF:
  4988 00004062 0D0A00                  	db	0Dh, 0Ah, 0
  4989                                  Msg_YES:
  4990 00004065 20                      	db	 20h
  4991                                  msg_yes_:
  4992 00004066 59455300                	db	'YES', 0
  4993                                  Msg_NO:
  4994 0000406A 20                      	db	20h
  4995                                  msg_no_:
  4996 0000406B 4E4F00                  	db	'NO', 0
  4997                                  
  4998                                  Msg_Error:
  4999 0000406E 0D0A                    	db	0Dh, 0Ah
  5000 00004070 4572726F72202120        	db	'Error ! '
  5001 00004078 28                      	db	'('
  5002                                  error_code:
  5003 00004079 3030                    	dw	3030h
  5004 0000407B 68                      	db	'h'
  5005 0000407C 2920                    	db	') '
  5006 0000407E 0D0A                    	db	0Dh, 0Ah
  5007 00004080 00                      	db	0
  5008                                  
  5009                                  msg_disk_sectors:
  5010 00004081 546F74616C20446973-     	db	"Total Disk Sectors : ", 0
  5010 0000408A 6B20536563746F7273-
  5010 00004093 203A2000           
  5011                                  
  5012                                  str_disk_sectors:
  5013 00004097 00<rept>                	times	8 db 0
  5014                                  
  5015                                  msg_file_size:
  5016 0000409F 484420496D61676520-     	db	"HD Image File Size : ", 0
  5016 000040A8 46696C652053697A65-
  5016 000040B1 203A2000           
  5017                                  
  5018                                  str_file_size:
  5019 000040B5 00<rept>                	times	11 db 0
  5020                                  
  5021                                  msg_bytes:
  5022 000040C0 206279746573            	db	" bytes"
  5023 000040C6 0D0A00                  	db	0Dh, 0Ah, 0
  5024                                  
  5025                                  msg_enter_cancel:
  5026 000040C9 0D0A                    	db	0Dh, 0Ah
  5027 000040CB 507265737320454E54-     	db	"Press ENTER to write file or press ESC to cancel." 
  5027 000040D4 455220746F20777269-
  5027 000040DD 74652066696C65206F-
  5027 000040E6 722070726573732045-
  5027 000040EF 534320746F2063616E-
  5027 000040F8 63656C2E           
  5028 000040FC 0D0A00                  	db	0Dh, 0Ah, 0
  5029                                  
  5030                                  msg_press_any_key:
  5031 000040FF 0D0A                    	db	0Dh, 0Ah
  5032 00004101 50726573732061206B-     	db	"Press a key to continue..." 
  5032 0000410A 657920746F20636F6E-
  5032 00004113 74696E75652E2E2E   
  5033 0000411B 0D0A00                  	db	0Dh, 0Ah, 0
  5034                                  
  5035                                  align 2
  5036                                  
  5037                                  ; Masterboot sector
  5038                                  
  5039                                  MasterBootBuff:
  5040                                  MasterBootCode: 
  5041 0000411E 00<rept>                	times	446 db 0
  5042                                  PartitionTable:
  5043 000042DC 00<rept>                	times	64 db 0
  5044                                  MBIDCode:
  5045 0000431C 0000                    	dw	0
  5046                                  
  5047                                  PTable_Buffer:
  5048 0000431E 00<rept>                	times	64 db 0
  5049                                   
  5050 0000435E 286329204572646F67-     	db	'(c) Erdogan TAN 2018'
  5050 00004367 616E2054414E203230-
  5050 00004370 3138               
  5051                                  
  5052                                  img_file_name:  
  5053 00004372 00<rept>                	times	13 db 0
  5054                                  
  5055 0000437F 90                      align 4
  5056                                  
  5057                                  ; (TR-DOS 386 compatible) Hard Disk (image) parameters
  5058                                  
  5059                                  total_sectors:
  5060 00004380 00000000                	dd 0
  5061                                  pType:
  5062 00004384 00<rept>                	times 4 db 0
  5063                                  bHead:	
  5064 00004388 00<rept>                	times 4 db 0
  5065                                  bSector:
  5066 0000438C 00<rept>                	times 4 db 0
  5067                                  bCylinder:
  5068 00004390 0000<rept>              	times 4 dw 0
  5069                                  eHead:	
  5070 00004398 00<rept>                	times 4 db 0
  5071                                  eSector:
  5072 0000439C 00<rept>                	times 4 db 0
  5073                                  eCylinder:
  5074 000043A0 0000<rept>              	times 4 dw 0
  5075                                  bLBA:
  5076 000043A8 00000000<rept>          	times 4 dd 0
  5077                                  eLBA:
  5078 000043B8 00000000<rept>          	times 4 dd 0
  5079                                  
  5080                                  ; Free space between partitions
  5081                                  gap1begin:
  5082 000043C8 00000000                	dd 0
  5083                                  gap2begin:
  5084 000043CC 00000000                	dd 0
  5085                                  gap3begin:
  5086 000043D0 00000000                	dd 0
  5087                                  gap4begin:
  5088 000043D4 00000000                	dd 0
  5089                                  gap5begin:
  5090 000043D8 00000000                	dd 0
  5091                                  gap1end:
  5092 000043DC 00000000                	dd 0
  5093                                  gap2end:
  5094 000043E0 00000000                	dd 0
  5095                                  gap3end:
  5096 000043E4 00000000                	dd 0
  5097                                  gap4end:
  5098 000043E8 00000000                	dd 0
  5099                                  gap5end:
  5100 000043EC 00000000                	dd 0
  5101                                  gap1size:
  5102 000043F0 00000000                	dd 0
  5103                                  gap2size:
  5104 000043F4 00000000                	dd 0
  5105                                  gap3size:
  5106 000043F8 00000000                	dd 0
  5107                                  gap4size:
  5108 000043FC 00000000                	dd 0
  5109                                  gap5size:
  5110 00004400 00000000                	dd 0
  5111                                  
  5112                                  pcount:
  5113 00004404 00<rept>                	times	5 db 0 ; partition count, pn1 .. pn4
  5114                                  psort:
  5115 00004409 00<rept>                	times	5 db 0 ; sorted partitions
  5116                                  
  5117 0000440E 90<rept>                align 4
  5118                                  
  5119                                  file_size:
  5120 00004410 00000000                	dd	0
  5121                                  
  5122                                  pp_StartSector:
  5123 00004414 00000000                	dd	0
  5124                                  
  5125                                  pp_Sectors:
  5126 00004418 00000000                	dd	0
  5127                                  
  5128                                  wholedisk:
  5129 0000441C 00                      	db	0
  5130                                  
  5131                                  pp_type: ; Primary partition type (for this program)	
  5132 0000441D 00                      	db	0
  5133                                  pp_type_user:
  5134 0000441E 00                      	db	0
  5135                                  
  5136                                  chs_focus:
  5137 0000441F 00                      	db 	0
  5138                                  
  5139                                  pSize_temp:
  5140 00004420 00000000                	dd	0
  5141                                  pSize_multiplier: 
  5142 00004424 00000000                	dd	0
  5143                                  pSize_maxdigits:
  5144 00004428 00                      	db 	0
  5145                                  pSize_digitpos:
  5146 00004429 00                      	db	0
  5147                                  
  5148                                  msg_psize_unit:
  5149                                  pSize_unit:
  5150 0000442A 0000                    	dw 	0	
  5151 0000442C 00                      	db	0
  5152                                  
  5153                                  reserved_bytes: ; for 11 bytes of numbers
  5154 0000442D 00<rept>                	times	3 db 0
  5155                                  
  5156                                  msg_partition_sectors:
  5157 00004430 00<rept>                	times	8 db 0
  5158 00004438 00                      	db	0
  5159                                  
  5160                                  msg_sectors_crlf:
  5161 00004439 20736563746F72          	db	" sector"
  5162                                  msg_sectors_crlf_s:
  5163 00004440 73                      	db	"s"
  5164 00004441 0D0A00                  	db	0Dh, 0Ah, 0
  5165                                  
  5166                                  vname_length:
  5167 00004444 00                      	db	0 ; 05/01/2018
  5168                                  
  5169                                  bs_oem_name:
  5170 00004445 5452444F53322E3000      	db	'TRDOS2.0', 0
  5171                                  
  5172                                  align 2
  5173                                  
  5174                                  no_name:
  5175 0000444E 4E4F204E414D452020-     	db 	'NO NAME    ', 0
  5175 00004457 202000             
  5176                                  
  5177                                  format_q:
  5178 0000445A 00                      	db 	0 ; 03/02/2018
  5179                                  
  5180 0000445B 90                      align 2
  5181                                  
  5182                                  pType_pos:
  5183 0000445C 00                      	db	0
  5184                                  pType_num:
  5185 0000445D 00                      	db	0
  5186 0000445E 00                      	db 	0
  5187                                  cylinder_boundary:
  5188 0000445F 00                      	db	0
  5189                                  
  5190                                  last_cylinder:
  5191 00004460 0000                    	dw	0
  5192                                  
  5193                                  ;align 2
  5194                                  
  5195                                  FDFORMAT_SECBUFFER:
  5196                                  HDFORMAT_SECBUFFER:
  5197 00004462 F6<rept>                	times	512 db 0F6h
  5198                                  HDFORMAT_FSINFO_BUFF:
  5199 00004662 52526141                	dd	41615252h  ; FSI_LeadSig
  5200 00004666 00<rept>                	times	480 db 0   ; FSI_Reserved1
  5201 00004846 72724161                	dd	61417272h  ; FSI_StrucSig
  5202 0000484A FFFFFFFF                	dd	0FFFFFFFFh ; FSI_Free_Count
  5203 0000484E 02000000                	dd	000000002h ; FSI_Nxt_Free
  5204 00004852 00<rept>                	times	12 db 0	   ; FSI_Reserved2
  5205 0000485E 000055AA                	dd	0AA550000h ; FSI_TrailSig	  		
  5206                                  HDFORMAT_FATBUFFER:
  5207                                  FDFORMAT_FATBUFFER:
  5208                                  FDFORMAT_FATBUFFER_S9: ; temporary !
  5209                                  HDFORMAT_EMPTY_BUFF:
  5210 00004862 00<rept>                	times	512 db 0
  5211                                  
  5212                                  data_start:
  5213 00004A62 00000000                	dd 0
  5214                                  data_sectors:
  5215 00004A66 00000000                	dd 0
  5216                                  cluster_count:
  5217 00004A6A 00000000                	dd 0
  5218                                  root_dir_secs:
  5219 00004A6E 0000                    	dw 0
  5220                                  format_percent:
  5221 00004A70 0000                    	dw 0
  5222                                  prev_percent:
  5223 00004A72 00                      	db 0
  5224                                  rsvdbyte:
  5225 00004A73 00                      	db 0
  5226                                  old_sp:
  5227 00004A74 0000                    	dw 0
  5228                                  
  5229                                  ;align 2
  5230                                  
  5231                                  ; 05/01/2018
  5232                                  fs_volume_name:
  5233 00004A76 00<rept>                	times	64 db 0
  5234                                  fs_volume_serial:
  5235 00004AB6 00000000                	dd	0
  5236                                  
  5237                                  DAT_FFBit:
  5238 00004ABA 0000                    	dw	0
  5239                                  DAT_FFSector:
  5240 00004ABC 0000                    	dw	0
  5241                                  	;dw	0
  5242                                  DAT_LFBit:
  5243 00004ABE 0000                    	dw	0
  5244                                  DAT_LFSector:
  5245 00004AC0 0000                    	dw	0
  5246                                  	;dw	0
  5247                                  
  5248                                  FS_MAT_Buffer: ; TRFS1 Master Allocation Table (05/01/2018)
  5249 00004AC2 4D4154                  MAT_Sign:		db	'MAT'	; Offset 0
  5250 00004AC5 00                      MAT_Version:		db	0	; 	 3
  5251 00004AC6 00000000                MAT_VolumeSize:		dd	0	;	 4  ; FS1 Volume Size	
  5252 00004ACA 00000000                MAT_BeginSector:	dd	0	;	 8  ; FS1 Start Sector
  5253 00004ACE 00000000                DAT_Address:		dd	0	;	12  ; Offset (=2)	
  5254 00004AD2 00000000                DAT_SectorCount:	dd	0	;	16  
  5255 00004AD6 00000000                MAT_FreeSectors:	dd	0	; 	20
  5256 00004ADA 00000000                MAT_FirstFreeSector:	dd	0	;	24
  5257                                  ;MAT_OS_Reserved:
  5258                                  ;	 	times	9   dd 0
  5259                                  ;MAT_Unused:
  5260                                  ;		times	112 dd 0
  5261                                  FS_DAT_Buffer: ; TRFS1 Disk Allocation Table (05/01/2018)
  5262                                  FS_RDT_Buffer: ; TRFS1 Root Directory Description Table (05/01/2018)		 
  5263 00004ADE 00<rept>                		times	512 db 0		
  5264                                  
  5265                                  SizeOfFile equ $-100
