     1                                  ; ****************************************************************************
     2                                  ; HDIMAGE.ASM (HDIMAGE.COM) - TRDOS 386 Hard Disk Image Formatting Utility
     3                                  ; 						      (for MSDOS/WINDOWS)
     4                                  ; ****************************************************************************
     5                                  ; Last Update: 04/11/2020
     6                                  ; ----------------------------------------------------------------------------
     7                                  ; Beginning: 03/12/2017
     8                                  ; ----------------------------------------------------------------------------
     9                                  ; Assembler: NASM version 2.14
    10                                  ; ----------------------------------------------------------------------------
    11                                  ; Turkish Rational DOS
    12                                  ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
    13                                  ;
    14                                  ; Derived from 'fdisk2.s' (FDISK2.COM) source code by Erdogan Tan
    15                                  ; (03/02/2019)
    16                                  ;
    17                                  ; Derived from 'fdimage.s' (FDIMAGE.COM) source code by Erdogan Tan
    18                                  ; (02/12/2017)
    19                                  ;
    20                                  ; Derived from 'fdformat.s' (FDFORMAT.COM) source code by Erdogan Tan
    21                                  ; (29/11/2017)
    22                                  ;
    23                                  ; Derived from 'FSFDISK.ASM' (FSFDISK.COM) source code by Erdogan Tan
    24                                  ; (27/04/2009)
    25                                  ;
    26                                  ; Derived from 'UNIXCOPY.ASM' (UNIXCOPY.COM) source code by Erdogan Tan
    27                                  ; (04/12/2015)
    28                                  ; ****************************************************************************
    29                                  ; nasm hdimage.s -l hdimage.lst -o HDIMAGE.COM
    30                                  
    31                                  ; DTA (PSP+80h= Offset 128)
    32                                  DTA_Attrib equ 149 ; PDP+21
    33                                  DTA_Time equ 150 ; PSP+22
    34                                  DTA_Date equ 152 ; PSP 24
    35                                  DTA_FileSize equ 154 ; PSP + 26
    36                                  DTA_FileName equ 158 ; PSP + 30
    37                                  
    38                                  ; Masterboot / Partition Table at Beginning+1BEh
    39                                  ptBootable      equ 0
    40                                  ptBeginHead     equ 1
    41                                  ptBeginSector   equ 2
    42                                  ptBeginCylinder equ 3
    43                                  ptFileSystemID	equ 4
    44                                  ptEndHead       equ 5
    45                                  ptEndSector     equ 6
    46                                  ptEndCylinder   equ 7
    47                                  ptStartSector   equ 8
    48                                  ptSectors       equ 12
    49                                  
    50                                  ; BIOS Disk Parameters
    51                                  DPDiskNumber  equ 0h
    52                                  DPDType       equ 1h
    53                                  DPReturn      equ 2h
    54                                  DPHeads       equ 3h
    55                                  DPCylinders   equ 4h
    56                                  DPSecPerTrack equ 6h
    57                                  DPDisks       equ 7h
    58                                  DPTableOff    equ 8h
    59                                  DPTableSeg    equ 0Ah
    60                                  DPNumOfSecs   equ 0Ch
    61                                  
    62                                  ; BIOS INT 13h Extensions (LBA extensions)
    63                                  ; Just After DP Data (DPDiskNumber+)
    64                                  DAP_PacketSize equ 10h  ; If extensions present, this byte will be >=10h
    65                                  DAP_Reserved1 equ 11h   ; Reserved Byte 
    66                                  DAP_NumOfBlocks equ 12h ; Value of this byte must be 0 to 127
    67                                  DAP_Reserved2 equ 13h   ; Reserved Byte
    68                                  DAP_Destination equ 14h ; Address of Transfer Buffer as SEGMENT:OFFSET
    69                                  DAP_LBA_Address equ 18h ; LBA=(C1*H0+H1)*S0+S1-1
    70                                                          ; C1= Selected Cylinder Number
    71                                                          ; H0= Number Of Heads (Maximum Head Number + 1)
    72                                                          ; H1= Selected Head Number
    73                                                          ; S0= Maximum Sector Number
    74                                                          ; S1= Selected Sector Number
    75                                                          ; QUAD WORD
    76                                  ; DAP_Flat_Destination equ 20h ; 64 bit address, if value in 4h is FFFF:FFFFh
    77                                                               ; QUAD WORD (Also, value in 0h must be 18h) 
    78                                                               ; TR-DOS will not use 64 bit Flat Address
    79                                  
    80                                  ; INT 13h Function 48h "Get Enhanced Disk Drive Parameters"
    81                                  ; Just After DP Data (DPDiskNumber+)
    82                                  GetDParams_48h equ 20h ; Word. Data Lenght, must be 26 (1Ah) for short data.
    83                                  GDP_48h_InfoFlag equ 22h ; Word
    84                                  ; Bit 1 = 1 -> The geometry returned in bytes 4-15 is valid.
    85                                  GDP_48h_NumOfPCyls equ 24h ; Double Word. Number physical cylinders.
    86                                  GDP_48h_NumOfPHeads equ 28h ; Double Word. Number of physical heads.
    87                                  GDP_48h_NumOfPSpT equ 2Ch ; Double word. Num of physical sectors per track.
    88                                  GDP_48h_LBA_Sectors equ 30h ; 8 bytes. Number of physical/LBA sectors.
    89                                  GDP_48h_BytesPerSec equ 38h ; Word. Number of bytes in a sector.
    90                                  
    91                                  ; Cursor Location
    92                                  CCCpointer equ  0450h   ; BIOS data, current cursor column
    93                                  
    94                                  ; MINIMUM & MAXIMUM SECTORS (partition and disk size limits in sectors)
    95                                  MINPARTSIZE equ 4096 ; 2MB
    96                                  MAXPARTSIZE equ 4128768 - 1 ; 2GB - masterboot sector	
    97                                  MINDISKSIZE equ 16384 ; 8MB
    98                                  MAXDISKSIZE equ 4128768 ; 2GB
    99                                  
   100                                  pTableOffset equ 1BEh ; 446
   101                                  
   102                                  	; Convert LBA to CHS
   103                                  	; 08/02/2019
   104                                  
   105                                  	; LBA = ((C1*H0+H1)*S0)+S1-1
   106                                  	;
   107                                  	; C1 = Selected Cylinder Number
   108                                  	; H0 = Number of Heads (Maximum Head Number + 1)
   109                                  	; H1 = Selected Head Number
   110                                  	; S0 = Maximum Sector Number
   111                                  	; S1 = Selected Sector Number
   112                                  	;
   113                                  	; Phoenix, Enchanced Disk Drive Specicifications, v1.1, Page 8)
   114                                  		
   115                                  
   116                                  [BITS 16]
   117                                  [ORG 100h]
   118                                  
   119                                  	;cli
   120                                  	;cld
   121                                  	;push	cs
   122                                  	;pop	ss
   123                                  	;mov	sp, 0FFFEh
   124                                  	;sti
   125                                  	
   126                                  	;mov	bx, SizeOfFile+100
   127                                  	
   128 00000000 BB[6C73]                	mov	bx, bss_end
   129                                  
   130 00000003 83C30F                          add	bx, 15
   131 00000006 D1EB                            shr	bx, 1
   132 00000008 D1EB                            shr	bx, 1
   133 0000000A D1EB                    	shr	bx, 1
   134 0000000C D1EB                    	shr	bx, 1
   135 0000000E B44A                            mov	ah, 4Ah ; modify memory allocation
   136                                          ;push	cs
   137                                          ;pop	es
   138 00000010 CD21                            int	21h
   139                                  
   140                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   141                                  ; clear BSS
   142                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   143                                  ; 03/02/2019
   144                                  
   145                                  	;mov	cx, bss_end
   146 00000012 B9[5872]                	mov	cx, bss_clear_end ; 15/02/2019
   147                                  
   148 00000015 BF[1E6B]                	mov	di, bss_start
   149 00000018 29F9                    	sub	cx, di
   150 0000001A 41                      	inc	cx
   151 0000001B D1E9                    	shr	cx, 1
   152 0000001D 31C0                    	xor	ax, ax
   153 0000001F F3AB                    	rep	stosw 
   154                                  
   155                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   156                                  ; get hd image file name
   157                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   158                                  
   159 00000021 BE8000                  	mov	si, 80h			; PSP command tail
   160 00000024 AC                       	lodsb
   161 00000025 08C0                    	or	al, al 			; command tail length                            
   162 00000027 0F848007                	jz	B_01			; jump if zero
   163                                  A_01:
   164 0000002B AC                      	lodsb
   165 0000002C 3C20                    	cmp	al, ' '			; is it SPACE ?
   166 0000002E 74FB                    	je	short A_01 		
   167 00000030 0F827707                	jb	B_01
   168                                  	
   169                                  	; check hd image file name
   170                                  A_02:
   171 00000034 BF[915A]                       	mov	di, img_file_name
   172 00000037 AA                      	stosb
   173                                  A_03:
   174 00000038 AC                      	lodsb
   175                                  	;cmp	al, 0Dh ; ENTER (CR) key
   176 00000039 3C20                    	cmp	al, 20h ; ' '
   177 0000003B 760C                    	jna	short A_04
   178 0000003D AA                      	stosb
   179 0000003E 81FF[9D5A]              	cmp	di, img_file_name + 12
   180 00000042 72F4                    	jb	short A_03
   181 00000044 803C20                  	cmp	byte [si], 20h 
   182 00000047 773F                    	ja	short A_10
   183                                  A_04:
   184                                  	;sub	al, al
   185                                  	;stosb
   186                                  
   187                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   188                                  ; File name capitalization
   189                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   190                                  
   191 00000049 BE[915A]                	mov	si, img_file_name
   192 0000004C 89F7                    	mov	di, si
   193 0000004E 89F3                    	mov	bx, si
   194                                  A_05:
   195 00000050 AC                      	lodsb
   196 00000051 3C61                    	cmp	al, 'a'
   197 00000053 730D                    	jnb	short A_07
   198 00000055 20C0                    	and	al, al
   199 00000057 7412                    	jz	short A_08
   200 00000059 3C2E                    	cmp	al, '.'
   201 0000005B 7502                    	jne	short A_06
   202 0000005D 89FB                    	mov	bx, di ; dot position	
   203                                  A_06:
   204 0000005F AA                      	stosb
   205 00000060 EBEE                    	jmp	short A_05 		
   206                                  A_07:
   207 00000062 3C7A                    	cmp	al, 'z'
   208 00000064 77F9                    	ja	short A_06
   209 00000066 24DF                    	and	al, 0DFh ; NOT 32
   210 00000068 AA                      	stosb
   211 00000069 EBE5                    	jmp	short A_05	
   212                                  A_08:
   213 0000006B 8805                    	mov	[di], al
   214 0000006D 4F                      	dec	di
   215 0000006E 39FB                    	cmp	bx, di
   216 00000070 7316                    	jnb	short A_10
   217 00000072 29DF                    	sub	di, bx
   218 00000074 81EB[915A]              	sub	bx, img_file_name
   219 00000078 83FF03                  	cmp	di, 3
   220 0000007B 7606                    	jna	short A_09
   221 0000007D 21DB                    	and	bx, bx
   222 0000007F 7507                    	jnz	short A_10
   223 00000081 EB0E                    	jmp	short A_11		
   224                                  A_09:
   225 00000083 83FB08                  	cmp	bx, 8
   226 00000086 7609                    	jna	short A_11
   227                                  A_10:
   228 00000088 BE[2346]                	mov	si, msg_inv_file_name
   229 0000008B E8F11D                  	call	print_msg
   230 0000008E E92007                  	jmp	B_02
   231                                  
   232                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   233                                  ; Find image file
   234                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   235                                  	
   236                                  A_11:
   237 00000091 BA[915A]                	mov	dx, img_file_name
   238 00000094 B93F00                  	mov	cx, 3Fh ; File Attributes
   239 00000097 B44E                    	mov	ah, 4Eh ; MS-DOS Function = Find First File
   240 00000099 CD21                    	int	21h
   241                                  	;jc	B_05
   242 0000009B 0F822E0B                	jc	new_image ; 07/03/2019
   243                                  
   244                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   245                                  ; Check image file features
   246                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   247                                  
   248                                  A_12:
   249 0000009F BE9500                  	mov	si, DTA_Attrib
   250 000000A2 8A04                    	mov	al, [si]
   251 000000A4 241F                    	and	al, 1Fh ; directory, volume label, system, hidden, read only
   252 000000A6 0F851207                	jnz	B_04     
   253 000000AA BE9A00                  	mov	si, DTA_FileSize
   254 000000AD AD                      	lodsw
   255                                  	; max. size of hard disk image = 63sectors*64heads*1024cylinders
   256 000000AE 8B14                    	mov	dx, [si]
   257 000000B0 81FA007E                	cmp	dx, 7E00h ; 2GB upper limit (7E000000h)
   258 000000B4 0F870407                	ja	B_04
   259 000000B8 7208                    	jb	short A_13
   260 000000BA 21C0                    	and	ax, ax
   261 000000BC 0F85FC06                	jnz	B_04
   262                                  	; 20/09/2020
   263                                  	;mov	ax, 1024
   264                                  	;jmp	A_24
   265 000000C0 EB0E                    	jmp	short A_14
   266                                  A_13:
   267 000000C2 A9FF01                  	test	ax, 511 ; check file size for sector boundary
   268 000000C5 0F85F306                	jnz	B_04
   269 000000C9 83FA7E                  	cmp	dx, 7Eh  ; 8MB lower limit  (7E0000h)
   270 000000CC 0F82EC06                	jb	B_04
   271                                  A_14:
   272 000000D0 A3[A46F]                	mov	[file_size], ax
   273 000000D3 8916[A66F]              	mov	[file_size+2], dx
   274                                  
   275                                  	; convert (disk image) file size to sector count (disk size)
   276                                  	; (dx:ax)/512
   277                                  	
   278 000000D7 B90002                  	mov	cx, 512
   279 000000DA E8950D                  	call	div32
   280                                  
   281                                  	; 12/02/2019
   282 000000DD A3[9C6F]                	mov	[total_sectors], ax
   283 000000E0 8916[9E6F]              	mov	[total_sectors+2], dx
   284                                  
   285                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   286                                  ; Load masterboot sector of HD image file
   287                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   288                                  
   289 000000E4 BA[915A]                	mov	dx, img_file_name
   290 000000E7 B8023D                  	mov	ax, 3D02h ; open for reading and writing
   291 000000EA CD21                    	int	21h
   292 000000EC 0F82791D                	jc	D_02
   293                                  
   294                                  	;mov	[img_file_handle], ax
   295 000000F0 89C3                    	mov	bx, ax
   296                                  
   297 000000F2 B43F                    	mov	ah, 3Fh ; read file
   298 000000F4 B90002                  	mov	cx, 512
   299 000000F7 BA[3858]                	mov	dx, MasterBootBuff
   300 000000FA CD21                    	int	21h
   301 000000FC 9C                      	pushf
   302 000000FD 50                      	push	ax
   303 000000FE B43E                    	mov	ah, 3Eh ; close file
   304                                  	;mov	bx, [img_file_handle]
   305 00000100 CD21                    	int	21h
   306 00000102 58                      	pop	ax
   307 00000103 9D                      	popf
   308 00000104 0F82611D                	jc	D_02
   309                                  
   310                                  	; 11/02/2019
   311                                  	;mov	word [img_file_handle], 0 ; disk image file is not open	
   312                                  
   313                                  	; 12/02/2019
   314                                  
   315 00000108 813E[365A]55AA          	cmp 	word [MBIDCode], 0AA55h
   316 0000010E 0F85AA06                	jne	B_04 ; invalid disk image file !
   317                                  
   318                                  	; clear screen
   319 00000112 B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
   320 00000115 CD10                    	int	10h
   321                                  
   322 00000117 C606[D56F]01            	mov	byte [existingfile], 1 ; we are using existing disk image file
   323                                  				       ; (not a new file) flag
   324                                  
   325                                  	; Check for Singlix Master Boot code
   326 0000011C 813E[F459]BE07          	cmp	word [MasterBootBuff+444], 7BEh
   327 00000122 7540                    	jne	short A_15 ; no ..
   328                                  	
   329                                  	; It is seen as singlix MBR
   330                                  	; Let's check for disk size words (CHS record)
   331 00000124 8B0E[DC59]              	mov	cx, [MasterBootBuff+420] ; cylinders
   332 00000128 83F910                  	cmp	cx, 16
   333 0000012B 7237                    	jb	short A_15 ; invalid
   334 0000012D A1[DE59]                	mov	ax, [MasterBootBuff+422] ; heads
   335 00000130 83F802                  	cmp	ax, 2
   336 00000133 722F                    	jb	short A_15 ; invalid
   337 00000135 8B16[E059]              	mov	dx, [MasterBootBuff+424] ; sectors
   338 00000139 83FA11                  	cmp	dx, 17
   339 0000013C 7226                    	jb	short A_15 ; invalid
   340 0000013E 890E[AA41]              	mov	[cylinders], cx
   341 00000142 A3[A841]                	mov	[heads], ax
   342 00000145 8916[A641]              	mov	[sectors], dx
   343 00000149 F7E2                    	mul	dx
   344 0000014B E8320D                  	call	mul32
   345 0000014E 09DB                    	or	bx, bx
   346 00000150 7512                    	jnz	short A_15 ; invalid
   347 00000152 3B16[9E6F]              	cmp	dx, [total_sectors+2]
   348 00000156 750C                    	jne	short A_15
   349 00000158 3B06[9C6F]              	cmp	ax, [total_sectors]
   350 0000015C 7506                    	jne	short A_15 ; invalid 
   351                                  
   352                                  	; valid singlix MBR & disk image file
   353                                  
   354                                  	; Display disk geometry
   355                                  
   356 0000015E BE[2160]                	mov	si, trdos386_disk_chs_header
   357                                  	;call	print_msg
   358                                  	;
   359                                  	;jmp	A_27
   360                                  	; 20/09/2020
   361 00000161 E9D300                  	jmp	A_24
   362                                  
   363                                  A_15:
   364                                  	; 17/10/2020
   365                                  	;mov	ax, [file_size]
   366                                  	;mov	dx, [file_size+2]
   367                                  
   368                                  	;shr	dx, 1
   369                                  	;rcr	ax, 1 ; / 2
   370                                  		      ; / 256	
   371                                  	;mov	al, ah
   372                                  	;mov	ah, dl
   373                                  	;mov	dl, dh
   374                                  	;xor	dh, dh
   375                                  	
   376                                  ;	mov	cl, 9 ; / 512
   377                                  ;A_15shr32:
   378                                  ;	shr	dx,1
   379                                  ;	rcr	ax,1
   380                                  ;	dec	cl
   381                                  ;	jnz	short A_15shr32
   382                                  
   383                                  	; 17/10/2020
   384 00000164 A1[9C6F]                	mov	ax, [total_sectors]
   385 00000167 8B16[9E6F]              	mov	dx, [total_sectors+2]
   386                                  
   387                                  	; cylinders*63sectors*16heads (<=528MB)
   388                                  	;cmp	dx, 1F80h ; 1024*16*63 (1F800000h)
   389 0000016B 83FA0F                  	cmp	dx, 0Fh ; 17/10/2020
   390 0000016E 7774                    	ja	short A_21
   391 00000170 7213                    	jb	short A_16
   392                                  	;and	ax, ax
   393                                  	;jnz	A_22
   394 00000172 3D00C0                  	cmp	ax, 0C000h ; 17/10/2020
   395 00000175 0F878200                	ja	A_22
   396                                  	; = 528MB (1024*16*63*512)
   397 00000179 C706[A841]1000          	mov	word [heads], 16
   398 0000017F B80004                  	mov	ax, 1024
   399 00000182 E99C00                  	jmp	A_25	
   400                                  A_16:
   401                                  	; < 528MB
   402 00000185 B9F003                  	mov	cx, 63*16 ; 1008
   403                                  	;div	cx
   404                                  	;and	dx, dx
   405 00000188 E8E70C                  	call	div32 ; 16/10/2020
   406 0000018B 21DB                    	and	bx, bx ; remainder
   407                                  	;jnz	B_04
   408                                  	; 10/02/2019
   409 0000018D 7509                    	jnz	short A_17 ; 17 spt disk image check
   410 0000018F C706[A841]1000          	mov	word [heads], 16
   411 00000195 E98900                  	jmp	A_25
   412                                  A_17:
   413                                  	; 12/02/2019
   414                                  	;mov	ax, [file_size]
   415                                  	;mov	dx, [file_size+2]
   416                                  
   417                                  	; 17/10/2020
   418 00000198 A1[9C6F]                	mov	ax, [total_sectors]
   419 0000019B 8B16[9E6F]              	mov	dx, [total_sectors+2]
   420                                  
   421                                  	;; 10/02/2019
   422                                  	;; Check 17 spt disk image
   423                                  	;mov	si, DTA_FileSize
   424                                  	;lodsw
   425                                  	;; max. size of hard disk image = 17sectors*16heads*1024cylinders
   426                                  	;mov	dx, [si]
   427                                  	
   428                                  	;cmp	dx, 880h ; 136MB upper limit (8800000h)
   429 0000019F 83FA04                  	cmp	dx, 04h  ;17/10/2020
   430 000001A2 0F871606                	ja	B_04
   431 000001A6 7207                    	jb	short A_49
   432                                  
   433 000001A8 3D0040                  	cmp	ax, 4000h ; 17/10/2020
   434 000001AB 0F870D06                	ja	B_04
   435                                  A_49:
   436                                  	; 17/10/2020
   437                                  	;mov	cx, 512
   438                                  	;call	div32
   439                                  
   440                                  	;mov	[pp_Sectors], ax
   441                                  	;mov	[pp_Sectors+2], dx
   442                                  	
   443                                  	; Calculate with increased heads (count) order
   444                                  	; (For example cyls = 1024 & heads = 8 is better than
   445                                  	;      cyls = 512 & heads = 16, for 17 SPT.v)
   446                                  
   447 000001AF B92200                  	mov	cx, 17*2 ; 34 ; heads = 2
   448                                  A_18:
   449 000001B2 E8BD0C                  	call	div32
   450                                  		; If remainder = 0
   451                                  		;    it is 17 spt hard disk image file
   452 000001B5 21DB                    	and	bx, bx
   453 000001B7 7414                    	jz	short A_20
   454                                  A_19:	
   455 000001B9 83C111                  	add	cx, 17
   456 000001BC 81F91001                	cmp	cx, 17*16 ; 272 ; heads = 16
   457 000001C0 0F87F805                	ja	B_04 ; invalid image file !
   458                                  
   459                                  	;mov	ax, [pp_Sectors]
   460                                  	;mov	dx, [pp_Sectors+2]
   461                                  
   462                                  	; 17/10/2020
   463 000001C4 A1[9C6F]                	mov	ax, [total_sectors]
   464 000001C7 8B16[9E6F]              	mov	dx, [total_sectors+2]
   465                                  	 	
   466 000001CB EBE5                    	jmp	short A_18
   467                                  
   468                                  A_20:
   469 000001CD 3D0004                  	cmp	ax, 1024
   470 000001D0 77E7                    	ja	short A_19
   471                                  
   472 000001D2 B311                    	mov	bl, 17
   473 000001D4 881E[A641]              	mov	[sectors], bl ; 17
   474 000001D8 A3[AA41]                	mov	[cylinders], ax
   475                                  
   476 000001DB 89C8                    	mov	ax, cx
   477 000001DD F6F3                    	div	bl
   478                                  	;xor	ah, ah
   479 000001DF A3[A841]                	mov	[heads], ax
   480                                  
   481 000001E2 EB46                    	jmp	short A_26
   482                                  
   483                                  A_21:
   484                                  	; cylinders*63sectors*32heads (>528MB, <=1GB)
   485                                  	;cmp	dx, 3F00h ; 1024*32*63 (3F000000h)
   486 000001E4 83FA1F                  	cmp	dx, 1Fh ; 17/10/2020
   487 000001E7 7726                    	ja	short A_23
   488 000001E9 7210                    	jb	short A_22
   489                                  	;and	ax, ax
   490                                  	;jnz	short A_23
   491 000001EB 3D0080                  	cmp	ax, 8000h ; 17/10/2020
   492 000001EE 771F                    	ja	short A_23
   493                                  	; = 1GB (1024*32*63*512)
   494 000001F0 C706[A841]1000          	mov	word [heads], 16
   495 000001F6 B80004                  	mov	ax, 1024
   496 000001F9 EB26                    	jmp	short A_25	
   497                                  A_22:
   498 000001FB B9E007                  	mov	cx, 63*32
   499                                  	;div	cx
   500                                  	;and	dx, dx
   501 000001FE E8710C                  	call	div32 ; 16/10/2020
   502 00000201 21DB                    	and	bx, bx ; remainder
   503 00000203 0F85B505                	jnz	B_04
   504 00000207 C706[A841]2000          	mov	word [heads], 32
   505 0000020D EB12                    	jmp	short A_25
   506                                  A_23:
   507                                  	; cylinders*63sectors*64heads (>1GB, <=2GB)
   508 0000020F B9C00F                  	mov	cx, 63*64
   509                                  	;div	cx
   510                                  	;and	dx, dx
   511 00000212 E85D0C                  	call	div32 ; 16/10/2020
   512 00000215 21DB                    	and	bx, bx ; remainder
   513 00000217 0F85A105                	jnz	B_04
   514                                  ;A_24:
   515 0000021B C706[A841]4000          	mov	word [heads], 64
   516                                  A_25:
   517 00000221 C706[A641]3F00          	mov	word [sectors], 63
   518 00000227 A3[AA41]                	mov	[cylinders], ax
   519                                  A_26:
   520                                  	; 08/02/2019
   521                                  
   522                                  	; calculate total sectors (by using CHS values)
   523 0000022A A1[A641]                	mov	ax, [sectors]
   524 0000022D F726[A841]              	mul	word [heads]
   525 00000231 A3[D66F]                	mov	[min_sectors], ax ; Minimum sectors
   526                                  	
   527                                  	; 17/10/2020
   528                                  	;mov	dx, [cylinders]
   529                                  	;mul	dx
   530                                  	;mov	[total_sectors], ax
   531                                  	;mov	[total_sectors+2], dx
   532                                  
   533                                  	; 12/02/2019
   534 00000234 BE[7460]                	mov	si, disk_chs_header
   535                                  A_24:			; 20/09/2020	
   536 00000237 E8451C                  	call	print_msg
   537                                  A_27:
   538 0000023A E87C23                  	call	init_partition_tables
   539 0000023D 7307                    	jnc	short A_28
   540                                  
   541                                  	; 24/02/2019
   542 0000023F E88F29                  	call	partition_table_fix
   543 00000242 73F6                    	jnc	short A_27
   544                                  
   545 00000244 CD20                    	int 	20h
   546                                  A_28:
   547                                  	; 26/02/2019
   548 00000246 803E[A372]00            	cmp	byte [epnumber], 0
   549 0000024B 7623                    	jna	short A_29
   550                                  
   551                                  	; Enable random access to disk image file
   552 0000024D C606[AC41]01            	mov	byte [random], 1
   553                                  
   554                                  	;mov	byte [ldrives], 255 ; invalid value
   555                                  	;			    ; to prevent deleting
   556                                  	;			    ; extended partition
   557                                  
   558                                  	; Open disk image file again.
   559 00000252 BA[915A]                	mov	dx, img_file_name
   560 00000255 B8023D                  	mov	ax, 3D02h ; open for reading and writing
   561 00000258 CD21                    	int	21h
   562 0000025A 7214                    	jc	short A_29
   563                                  
   564 0000025C A3[A441]                	mov	[img_file_handle], ax
   565                                  
   566 0000025F E8742F                  	call	init_ext_partition_tables
   567                                  
   568                                  	; Close file
   569 00000262 8B1E[A441]              	mov	bx, [img_file_handle]
   570 00000266 B43E                    	mov	ah, 3Eh ; close file
   571 00000268 CD21                    	int	21h
   572                                  	
   573                                  	; 28/02/2019
   574 0000026A C706[A441]0000          	mov	word [img_file_handle], 0
   575                                  A_29:
   576                                  	; 08/03/2019
   577 00000270 803E[D56F]00            	cmp	byte [existingfile], 0
   578 00000275 7743                    	ja	short A_32
   579                                  
   580 00000277 B80300                  	mov	ax, 3  ; clear screen
   581 0000027A CD10                    	int	10h
   582                                  
   583 0000027C E8481D                  	call	display_chs_table
   584                                  
   585 0000027F BE[6057]                	mov	si, CRLF
   586 00000282 E8FA1B                  	call	print_msg
   587                                  
   588                                  	; 08/03/2019
   589 00000285 C606[D56F]01            	mov	byte [existingfile], 1
   590                                  
   591 0000028A E8A827                  	call	dpt_1
   592                                  
   593 0000028D BE[6057]                	mov	si, CRLF
   594 00000290 E8EC1B                  	call	print_msg
   595                                  
   596 00000293 BE[8F55]                	mov	si, msg_edit_or_exit
   597 00000296 E8E61B                  	call	print_msg
   598                                  A_30:
   599 00000299 30E4                    	xor	ah, ah
   600 0000029B CD16                    	int	16h
   601                                  
   602 0000029D 3C0D                    	cmp	al, 13 ; CR (ENTER) key
   603 0000029F 7426                    	je	short A_33 
   604                                  
   605 000002A1 3C1B                    	cmp	al, 27 ; ESCape key
   606 000002A3 740D                    	je	short A_31
   607                                  
   608 000002A5 3C20                    	cmp	al, 32 ; SPACE key
   609 000002A7 741E                    	je	short A_33 
   610                                  
   611 000002A9 3C03                    	cmp	al, 3 ; CTRL+C
   612 000002AB 7405                    	je	short A_31
   613                                  
   614 000002AD 83F800                  	cmp	ax, 0 ; CTRL+BREAK
   615 000002B0 77E7                    	ja	short A_30
   616                                  A_31:
   617 000002B2 BE[6057]                	mov	si, CRLF
   618 000002B5 E8C71B                  	call	print_msg
   619                                  
   620 000002B8 CD20                    	int	20h
   621                                  
   622                                  A_32:
   623                                  	; initialize primary partition tables
   624                                  
   625 000002BA E8FC22                  	call	init_partition_tables
   626 000002BD 7308                    	jnc	short A_33  ; 24/02/2019
   627                                  
   628                                  	; 24/02/2019
   629 000002BF E80F29                  	call	partition_table_fix
   630 000002C2 73F6                    	jnc	short A_32
   631                                  	; ESC key has been pressed for EXIT
   632 000002C4 E9EA04                  	jmp	B_02  ; Terminate program
   633                                  A_33:
   634                                  	; 04/02/2019
   635 000002C7 30C0                    	xor	al, al  ; MBR/PRIMARY PARTITIONS
   636 000002C9 E85327                  	call	display_partition_table
   637                                  A_34:
   638 000002CC 30C0                    	xor	al, al ; 11/02/2019
   639 000002CE 3806[A072]              	cmp	byte [pcount], al ; 0
   640                                  	;jna	A_44 ; empty partition table
   641 000002D2 7703                    	ja	short A_35
   642                                  	;inc	al ; 11/02/2019
   643                                  	; 10/02/2019
   644                                  	;mov	[newdisk], al ; 1 ; Continue as new disk image (with empty pt)
   645                                  	;mov	[random], al ; 1 ; next r/w is not sequental
   646 000002D4 E90D01                  	jmp	A_44
   647                                  A_35:
   648                                  	; Check disk parameters with current CHS settings
   649 000002D7 31DB                    	xor	bx, bx
   650 000002D9 31C9                    	xor	cx, cx
   651                                  A_36:
   652 000002DB 80BF[5D72]00            	cmp	byte [part_table_sys_id+bx], 0
   653 000002E0 767C                    	jna	A_37
   654                                  
   655 000002E2 A1[A641]                	mov	ax, [sectors]
   656 000002E5 F726[A841]              	mul	word [heads]
   657                                  	; dx = 0, ax = heads*sectors
   658 000002E9 8B97[5B72]              	mov	dx, [part_table_start_cyl+bx]
   659 000002ED F7E2                    	mul	dx
   660 000002EF 89C6                    	mov	si, ax
   661 000002F1 89D7                    	mov	di, dx
   662 000002F3 8A87[5972]              	mov	al, [part_table_start_head+bx]
   663 000002F7 F626[A641]              	mul	byte [sectors]
   664 000002FB 01C6                    	add	si, ax
   665 000002FD 83D700                  	adc	di, 0
   666 00000300 8A87[5A72]              	mov	al, [part_table_start_sector+bx]
   667 00000304 30E4                    	xor	ah, ah
   668 00000306 FEC8                    	dec	al ; 1 -> 0
   669 00000308 01C6                    	add	si, ax
   670 0000030A 83D700                  	adc	di, 0
   671                                  
   672 0000030D 3BBF[6472]              	cmp	di, [part_table_rel_sec_hw+bx]
   673                                  	;jne	B_04 ; invalid
   674 00000311 7558                    	jne	short A_38
   675 00000313 3BB7[6272]              	cmp	si, [part_table_rel_sec_lw+bx]
   676                                  	;jne	B_04 ; invalid
   677 00000317 7552                    	jne	short A_38
   678                                  
   679 00000319 A1[A641]                	mov	ax, [sectors]
   680 0000031C F726[A841]              	mul	word [heads]
   681                                  	; dx = 0, ax = heads*sectors
   682 00000320 8B97[6072]              	mov	dx, [part_table_end_cyl+bx]
   683 00000324 F7E2                    	mul	dx
   684 00000326 89C6                    	mov	si, ax
   685 00000328 89D7                    	mov	di, dx
   686 0000032A 8A87[5E72]              	mov	al, [part_table_end_head+bx]
   687 0000032E F626[A641]              	mul	byte [sectors]
   688 00000332 01C6                    	add	si, ax
   689 00000334 83D700                  	adc	di, 0
   690 00000337 8A87[5F72]              	mov	al, [part_table_end_sector+bx]
   691 0000033B 30E4                    	xor	ah, ah
   692                                  	;dec	al ; 63 -> 62
   693 0000033D 01C6                    	add	si, ax
   694 0000033F 83D700                  	adc	di, 0
   695                                  
   696 00000342 8B87[6672]              	mov	ax, [part_table_num_sec_lw+bx]
   697 00000346 8B97[6872]              	mov	dx, [part_table_num_sec_hw+bx]
   698                                  	
   699 0000034A 0387[6272]              	add	ax, [part_table_rel_sec_lw+bx]
   700 0000034E 1397[6472]              	adc	dx, [part_table_rel_sec_hw+bx]
   701                                  
   702 00000352 39F0                    	cmp	ax, si
   703                                  	;jne	B_04 ; invalid
   704 00000354 7515                    	jne	short A_38
   705                                  
   706 00000356 39FA                    	cmp	dx, di
   707                                  	;jne	B_04 ; invalid
   708 00000358 7511                    	jne	short A_38
   709                                  
   710 0000035A FE06[5672]              	inc	byte [goodpte]	
   711                                  A_37:
   712 0000035E FEC1                    	inc	cl
   713                                  
   714 00000360 80F904                  	cmp	cl, 4
   715 00000363 7316                    	jnb	short A_39
   716                                  
   717 00000365 83C312                  	add	bx, 18  ; partition table structure size
   718                                  	
   719 00000368 E970FF                  	jmp	A_36
   720                                  A_38:
   721                                  	; 24/02/2019 
   722                                  	; If defective pte count > 1 do not tolerate MBR.
   723 0000036B B001                    	mov 	al, 1
   724 0000036D 3806[5772]              	cmp	[badpte], al ; 1
   725 00000371 0F874704                	ja	B_04
   726 00000375 FE06[5772]              	inc	byte [badpte]
   727 00000379 EBE3                    	jmp	short A_37 
   728                                  A_39:
   729                                  	; If defective pte count > good pte, we must not continue
   730 0000037B A0[5772]                	mov	al, [badpte]	
   731 0000037E 20C0                    	and	al, al
   732 00000380 7410                    	jz	short A_41
   733                                  
   734 00000382 3A06[5672]              	cmp	al, [goodpte]
   735 00000386 0F873204                	ja	B_04
   736                                  
   737                                  	; 24/02/2019
   738                                  A_40:
   739 0000038A BE[0162]                	mov	si, msg_defective_pt
   740 0000038D E8EF1A                  	call	print_msg
   741 00000390 EB52                    	jmp	short A_44
   742                                  
   743                                  A_41:
   744                                  	; LBA and CHS values of all partitions are OK (here)
   745                                  
   746                                  	; sort MBR (primary) partitions
   747                                  
   748 00000392 E86D23                  	call	sort_partition_table
   749                                  
   750                                  	; Checking partition overlaps (via start and end cylinders)
   751                                  
   752 00000395 31DB                    	xor	bx, bx
   753 00000397 BA1200                  	mov	dx, 18
   754                                  A_42:
   755 0000039A FEC3                    	inc	bl
   756                                  
   757 0000039C 8A87[E66F]              	mov	al, [bx+sort]
   758 000003A0 F6E2                    	mul	dl
   759 000003A2 89C6                    	mov	si, ax	; current
   760                                  
   761 000003A4 80BC[5D72]00            	cmp	byte [part_table_sys_id+si], 0
   762 000003A9 7634                    	jna	short A_43
   763                                  
   764 000003AB 8A87[E56F]              	mov	al, [bx+sort-1]
   765 000003AF F6E2                    	mul	dl
   766 000003B1 89C7                    	mov	di, ax  ; previous
   767                                  
   768 000003B3 8B85[6072]              	mov	ax, [part_table_end_cyl+di]
   769 000003B7 3B84[5B72]              	cmp	ax, [part_table_start_cyl+si]
   770 000003BB 7222                    	jb	short A_43
   771                                  
   772 000003BD 21C0                    	and	ax, ax
   773                                  	;jnz	B_04  ; overlap error (except empty entries)
   774                                  	; 24/02/2019
   775                                  	;jnz	short A_40
   776                                  	; 31/10/2020
   777 000003BF 741E                    	jz	short A_43 ; empty pt entries
   778                                  			; (previous pte is empty)
   779                                  	; 31/10/2020
   780 000003C1 8B85[6272]              	mov	ax, [part_table_rel_sec_lw+di] ; previous
   781 000003C5 8B95[6472]              	mov	dx, [part_table_rel_sec_hw+di]
   782 000003C9 0385[6672]              	add	ax, [part_table_num_sec_lw+di]
   783 000003CD 1395[6872]              	adc	dx, [part_table_num_sec_hw+di]
   784                                  	;jc	short A_40
   785                                  		 ; dx:ax = end sector + 1
   786 000003D1 3B94[6472]              	cmp	dx, [part_table_rel_sec_hw+si] ; current
   787 000003D5 7208                    	jb	short A_43
   788 000003D7 77B1                    	ja	short A_40 ; overlap error !	
   789 000003D9 3B84[6272]              	cmp	ax, [part_table_rel_sec_lw+si]
   790 000003DD 73AB                    	jnb	short A_40 ; overlap error ! 	
   791                                  A_43:
   792 000003DF 80FB03                  	cmp	bl, 3
   793 000003E2 72B6                    	jb	short A_42
   794                                  A_44:
   795 000003E4 BE[325C]                	mov	si, mbr_editing_options
   796 000003E7 E8951A                  	call	print_msg
   797                                  
   798 000003EA BE[E05C]                	mov	si, enter_option_number_msg
   799 000003ED E88F1A                  	call	print_msg
   800                                  
   801 000003F0 803E[E46F]00            	cmp	byte [ldrives], 0
   802 000003F5 760C                    	jna	short A_45
   803                                  
   804 000003F7 BE[6057]                	mov	si, CRLF
   805 000003FA E8821A                  	call	print_msg
   806                                  
   807 000003FD BE[4963]                	mov	si, str_display_ebr_pt
   808 00000400 E87C1A                  	call	print_msg
   809                                  A_45:	
   810                                  	;mov	si, CRLF
   811                                  	;call	print_msg
   812                                  
   813                                  A_46:
   814 00000403 30E4                    	xor	ah, ah
   815 00000405 CD16                    	int	16h
   816                                  
   817 00000407 3C30                    	cmp	al, '0'
   818 00000409 7428                    	je	short A_47
   819                                  
   820 0000040B 3C31                    	cmp	al, '1'
   821 0000040D 742D                    	je	short create_partition	
   822 0000040F 3C32                    	cmp	al, '2'
   823 00000411 0F84FA00                	je	activate_partition
   824 00000415 3C33                    	cmp	al, '3'
   825 00000417 0F849701                	je	delete_partition
   826 0000041B 3C34                    	cmp	al, '4'
   827 0000041D 0F849D02                	je	write_pt_mbr
   828                                  	
   829 00000421 3C1B                    	cmp	al, 27 ; ESCape
   830 00000423 740E                    	je	short A_47
   831                                  
   832                                  	; 28/02/2019
   833 00000425 803E[E46F]00            	cmp	byte [ldrives], 0
   834 0000042A 76D7                    	jna	short A_46
   835                                  
   836 0000042C 3C20                    	cmp	al, 20h ; SPACE
   837 0000042E 75D3                    	jne	short A_46
   838                                  
   839 00000430 E9D127                  	jmp	display_extended_pt
   840                                  A_47:
   841                                  	; terminate
   842 00000433 CD20                    	int	20h
   843                                  
   844                                  A_48:
   845                                  	; 24/02/2019
   846 00000435 30C0                    	xor	al, al  ; MBR/PRIMARY PARTITIONS
   847 00000437 E8E525                  	call	display_partition_table
   848 0000043A EBA8                    	jmp	short A_44
   849                                  
   850                                  ;-----------------------------------------------------------------------------
   851                                  
   852                                  create_partition:
   853                                  	; 10/02/2019
   854 0000043C 31C0                    	xor	ax, ax
   855 0000043E A2[B06F]                	mov	byte [wholedisk], al ; 0 ; Reset wholedisk flag
   856                                  
   857                                  	; 13/02/2019
   858 00000441 3806[AD41]              	cmp	byte [newdisk], al ; 0
   859 00000445 772E                    	ja	short cp_2 ; New disk image, continue
   860                                  
   861 00000447 3806[A072]              	cmp	byte [pcount], al ; 0 ; number of (valid) partitions
   862 0000044B 7707                    	ja	short cp_1
   863                                  
   864 0000044D C606[AD41]01            	mov	byte [newdisk], 1
   865 00000452 EB21                    	jmp	short cp_2
   866                                  cp_1:
   867 00000454 803E[A072]04            	cmp	byte [pcount], 4
   868 00000459 7339                    	jnb	short cp_3 ; full pt !		
   869                                  
   870                                  	; al = 0
   871 0000045B E80623                  	call	find_part_free_space
   872                                  		 ; Following values are for the max. free space on disk
   873                                  
   874 0000045E 21C9                    	and	cx, cx
   875 00000460 7445                    	jz	short cp_4 ; there is not free space on disk
   876                                  
   877                                  	;mov	[c_cylinders], cx  ; count of free cylinders in the gap
   878 00000462 891E[3E73]              	mov	[c_fspc_offset], bx  ; offset from beginning of 'fspc:'
   879                                  	;mov	[c_gap], al ; gap (space index) number of this free space
   880                                  	;		    ; 0 -> before partition 1 (as PTE)
   881                                  	;		    ; 1-2-3 -> between partitions 1 to 4
   882                                  	;		    ; 4 -> after partition 4 (as PTE)
   883                                  
   884                                  	; Start to job with non-aligned (full) free sectors of this max. space
   885                                  	
   886 00000466 8B87[F472]              	mov	ax, [free_space.sectors_unused+bx]
   887 0000046A 8B97[F672]              	mov	dx, [free_space.sectors_unused+2+bx]	
   888                                  
   889 0000046E A3[AC6F]                	mov	[pp_Sectors], ax
   890 00000471 8916[AE6F]              	mov	[pp_Sectors+2], dx
   891                                  cp_2:
   892 00000475 C606[AC41]01            	mov	byte [random], 1  ; random access (use seek before reading)
   893                                  
   894 0000047A 3906[A441]              	cmp	[img_file_handle], ax ; 0
   895 0000047E 0F871E0B                	ja	B_49
   896                                  
   897                                  	; Open disk image file again.
   898                                  
   899                                  	; 25/02/2019 (Random access to disk image sectors must be enabled)
   900                                  	;dec	byte [random] ; 0 ; masterboot sector will be written		 
   901                                  	;		  	  ; no need to seek file pointer
   902                                  
   903 00000482 BA[915A]                	mov	dx, img_file_name
   904 00000485 B8023D                  	mov	ax, 3D02h ; open file for reading and writing
   905 00000488 CD21                    	int	21h
   906 0000048A 0F82DB19                	jc	D_02
   907                                  
   908 0000048E A3[A441]                	mov	[img_file_handle], ax
   909                                  
   910 00000491 E90C0B                  	jmp	B_49 ; New/Empty disk, create partition menu
   911                                  
   912                                  cp_3:
   913                                  	; 13/02/2019
   914                                  	; There is not a free pt entry to create a new partition
   915                                  
   916 00000494 30C0                    	xor	al, al  ; MBR/PRIMARY PARTITIONS
   917 00000496 E88625                  	call	display_partition_table
   918                                  
   919 00000499 BE[C25D]                	mov	si, msg_full_pt
   920 0000049C E8E019                  	call	print_msg
   921 0000049F BE[EF5D]                	mov	si, msg_to_create_new_p
   922 000004A2 E8DA19                  	call	print_msg
   923                                  
   924 000004A5 EB7A                    	jmp	ap_0
   925                                  cp_4:
   926                                  	; 02/03/2019
   927 000004A7 803E[A372]00            	cmp	byte [epnumber], 0
   928 000004AC 7602                    	jna	short cp_5
   929                                  
   930 000004AE EB08                    	jmp	short create_logical_drives
   931                                  cp_5:
   932                                  	; 15/02/2019
   933                                  	; There is not (enough) free space to create a new partition
   934                                  
   935 000004B0 BE[0D5E]                	mov	si, msg_no_free_space
   936 000004B3 E8C919                  	call	print_msg
   937 000004B6 EB69                    	jmp	ap_0
   938                                  
   939                                  ;-----------------------------------------------------------------------------
   940                                  
   941                                  create_logical_drives:
   942                                  	; 05/03/2019
   943 000004B8 E8CC2A                  	call	check_ext_free_space
   944 000004BB 723D                    	jc	short cld_5 ; 19/10/2020
   945                                  cld_1:
   946                                  	; 05/03/2019
   947 000004BD 803E[E46F]04            	cmp	byte [ldrives], 4
   948 000004C2 7203                    	jb	short cld_2
   949 000004C4 E9AF27                  	jmp	eetc_2
   950                                  cld_2:
   951                                  	; 01/11/2020
   952 000004C7 A3[6273]                	mov	[ep_free_sectors], ax
   953 000004CA 8916[6473]              	mov	[ep_free_sectors+2], dx
   954                                  
   955 000004CE BE[7C66]                	mov	si, msg_c_ldd_q
   956 000004D1 E8AB19                  	call	print_msg
   957                                  cld_3:	
   958 000004D4 28E4                    	sub	ah, ah
   959 000004D6 CD16                    	int	16h
   960                                  
   961 000004D8 3C1B                    	cmp	al, 27 ; ESCAPE key
   962 000004DA 0F846501                	je	cp_esc
   963 000004DE 24DF                    	and	al, 0DFh
   964 000004E0 3C4E                    	cmp	al, 'N'
   965 000004E2 740D                    	je	short cld_4
   966 000004E4 3C59                    	cmp	al, 'Y'
   967 000004E6 75EC                    	jne	short cld_3
   968 000004E8 BE[025F]                	mov	si, _msg_YES
   969 000004EB E89119                  	call	print_msg
   970                                  
   971 000004EE E9B927                  	jmp	edit_ext_table_create_x
   972                                  cld_4:	
   973 000004F1 BE[085F]                	mov	si, _msg_NO
   974 000004F4 E88819                  	call	print_msg
   975                                  
   976 000004F7 E94901                  	jmp	cp_esc
   977                                  cld_5:	
   978 000004FA BE[1C66]                	mov	si, msg_c_part_error
   979 000004FD E87F19                  	call	print_msg
   980                                  
   981 00000500 803E[E46F]03            	cmp	byte [ldrives], 3
   982 00000505 76C0                    	jna	short cld_2
   983                                  
   984 00000507 BE[4A66]                	mov	si, msg_c_ldd_error
   985 0000050A E87219                  	call	print_msg
   986                                  
   987 0000050D EB12                    	jmp	short ap_0
   988                                  
   989                                  ;-----------------------------------------------------------------------------
   990                                   	
   991                                  activate_partition:
   992                                  	; 12/02/2019
   993 0000050F 30C0                    	xor	al, al  ; MBR/PRIMARY PARTITIONS
   994 00000511 E80B25                  	call	display_partition_table
   995                                  
   996 00000514 803E[A072]00            	cmp	byte [pcount], 0
   997 00000519 7713                    	ja	short ap_1
   998                                  
   999 0000051B BE[765D]                	mov	si, msg_empty_pt
  1000 0000051E E85E19                  	call	print_msg
  1001                                  
  1002                                  ap_0:
  1003 00000521 BE[1958]                	mov	si, msg_press_any_key
  1004 00000524 E85819                  	call	print_msg
  1005                                  
  1006 00000527 30E4                    	xor	ah, ah
  1007 00000529 CD16                    	int	16h
  1008                                  
  1009 0000052B E91501                  	jmp	ap_esc
  1010                                  
  1011                                  ap_1:
  1012                                  	; Set valid_ppnums (MBR partition IDs) list
  1013 0000052E BE[F659]                	mov	si, MasterBootBuff+pTableOffset ; MasterBootBuff+446
  1014 00000531 BB[F871]                	mov	bx, valid_ppnums
  1015 00000534 B104                    	mov	cl, 4
  1016                                  ap_2:
  1017 00000536 8A4404                  	mov	al, [si+ptFileSystemID]
  1018 00000539 8807                    	mov	[bx], al
  1019 0000053B FEC9                    	dec	cl
  1020 0000053D 7406                    	jz	short ap_3
  1021 0000053F 43                      	inc	bx
  1022 00000540 83C610                  	add	si, 16
  1023 00000543 EBF1                    	jmp	short ap_2
  1024                                  ap_3:
  1025 00000545 BE[F55F]                	mov	si, msg_enter_pn_to_act
  1026 00000548 E83419                  	call	print_msg
  1027                                  ap_getchar:
  1028 0000054B 30E4                    	xor	ah, ah
  1029 0000054D CD16                    	int	16h
  1030                                  	
  1031                                  	; 19/10/2020
  1032 0000054F 3C1B                    	cmp	al, 27
  1033 00000551 0F84EE00                	je	ap_esc
  1034                                  
  1035                                  	;cmp	al, '0'
  1036                                  	;je	ap_esc
  1037                                  	
  1038 00000555 3C31                    	cmp	al, '1'
  1039 00000557 72F2                    	jb	short ap_getchar
  1040 00000559 3C34                    	cmp	al, '4'
  1041 0000055B 77EE                    	ja	short ap_getchar
  1042                                  
  1043 0000055D 30E4                    	xor	ah, ah
  1044 0000055F 89C2                    	mov	dx, ax
  1045                                  	
  1046 00000561 80EA31                  	sub	dl, '1'
  1047 00000564 89D6                    	mov	si, dx
  1048 00000566 38A4[F871]              	cmp	byte [si+valid_ppnums], ah  ; 0
  1049 0000056A 76DF                    	jna	short ap_getchar ; Empty partition table entry, it is not shown
  1050                                  
  1051 0000056C BB0700                  	mov	bx, 07h
  1052 0000056F B409                    	mov	ah, 09h
  1053 00000571 B90100                  	mov	cx, 1
  1054 00000574 CD10                    	int	10h
  1055                                  
  1056 00000576 BE[F659]                	mov	si, MasterBootBuff+pTableOffset
  1057 00000579 BF[5872]                	mov	di, part_table_boot_ind ; (**)
  1058                                  
  1059                                  	; Clear all of possible active partition flags
  1060 0000057C 8834                    	mov	[si], dh ; 0	
  1061 0000057E 887410                  	mov	[si+16], dh ; 0
  1062 00000581 887420                  	mov	[si+32], dh ; 0
  1063 00000584 887430                  	mov	[si+48], dh ; 0
  1064                                  
  1065                                  	; This may not be needed !? 
  1066                                  	; (**) (Primary partitions structure/list)
  1067 00000587 8835                    	mov	[di], dh ; 0	
  1068 00000589 887512                  	mov	[di+18], dh ; 0
  1069 0000058C 887524                  	mov	[di+36], dh ; 0
  1070 0000058F 887536                  	mov	[di+54], dh ; 0
  1071                                  
  1072 00000592 20D2                    	and 	dl, dl
  1073 00000594 740D                    	jz	short ap_4
  1074                                  
  1075 00000596 89D0                    	mov	ax, dx
  1076                                  
  1077 00000598 C0E004                  	shl	al, 4 ; * 16
  1078 0000059B 01C6                    	add	si, ax
  1079                                  
  1080 0000059D B012                    	mov	al, 18
  1081 0000059F F6E2                    	mul	dl ; 1 to 3
  1082 000005A1 01C7                    	add	di, ax
  1083                                  ap_4:
  1084                                  	; Then	set active partition as requested by user
  1085 000005A3 C60480                  	mov	byte [si], 80h
  1086 000005A6 C60580                  	mov	byte [di], 80h ; (**)
  1087                                  
  1088 000005A9 BE[6057]                	mov	si, CRLF ; Next line	
  1089 000005AC E8D018                  	call	print_msg
  1090                                  
  1091                                  	; NOTE: Only the MBR buffer has been changed
  1092                                  	; (Masterboot sector will not be updated unless/till
  1093                                  	;  MBR partition table -and MBR code- will be written
  1094                                  	;  to disk image as result of 'write part. table' command.)
  1095                                  
  1096                                  	;; wait for 1 second
  1097                                  	;mov	ah, 02h
  1098                                  	;int	1Ah
  1099                                  	;mov	[GetChar], dh
  1100                                  ;ap_wait:
  1101                                  	;mov	ah, 02h
  1102                                  	;int	1Ah
  1103                                  	;cmp	dh, [GetChar]
  1104                                  	;je	short ap_wait
  1105                                  
  1106                                  	;jmp	A_33 ; display partition table again
  1107 000005AF E983FE                  	jmp	A_48 ; 25/02/2019
  1108                                  
  1109                                  ;----------------------------------------------------------------------------- 	 
  1110                                  
  1111                                  delete_partition:
  1112                                  	; 19/10/2020
  1113                                  	; 10/02/2019
  1114 000005B2 30C0                    	xor	al, al  ; MBR/PRIMARY PARTITIONS
  1115 000005B4 E86824                  	call	display_partition_table
  1116                                  
  1117 000005B7 803E[A072]00            	cmp	byte [pcount], 0
  1118 000005BC 7712                    	ja	short dp_1
  1119                                  
  1120 000005BE BE[765D]                	mov	si, msg_empty_pt
  1121 000005C1 E8BB18                  	call	print_msg
  1122                                  
  1123 000005C4 BE[1958]                	mov	si, msg_press_any_key
  1124 000005C7 E8B518                  	call	print_msg
  1125                                  
  1126 000005CA 30E4                    	xor	ah, ah
  1127 000005CC CD16                    	int	16h
  1128                                  
  1129 000005CE EB73                    	jmp	short dp_esc
  1130                                  
  1131                                  dp_1:
  1132                                  	; Set valid_ppnums (MBR partition IDs) list
  1133 000005D0 BE[F659]                	mov	si, MasterBootBuff+pTableOffset ; MasterBootBuff+446
  1134 000005D3 BB[F871]                	mov	bx, valid_ppnums
  1135 000005D6 B104                    	mov	cl, 4
  1136                                  dp_2:
  1137 000005D8 8A4404                  	mov	al, [si+ptFileSystemID]
  1138 000005DB 8807                    	mov	[bx], al
  1139 000005DD FEC9                    	dec	cl
  1140 000005DF 7406                    	jz	short dp_3
  1141 000005E1 43                      	inc	bx
  1142 000005E2 83C610                  	add	si, 16
  1143 000005E5 EBF1                    	jmp	short dp_2
  1144                                  dp_3:
  1145 000005E7 BE[315E]                	mov	si, msg_enter_pn_to_del
  1146 000005EA E89218                  	call	print_msg
  1147                                  dp_getchar1:
  1148 000005ED 30E4                    	xor	ah, ah
  1149 000005EF CD16                    	int	16h
  1150                                  	
  1151                                  	; 19/10/2020
  1152 000005F1 3C1B                    	cmp	al, 27
  1153 000005F3 744E                    	je	short dp_esc
  1154 000005F5 3C30                    	cmp	al, '0'
  1155 000005F7 744A                    	je	short dp_esc
  1156                                  	;cmp	al, '1'
  1157 000005F9 72F2                    	jb	short dp_getchar1
  1158 000005FB 3C34                    	cmp	al, '4'
  1159 000005FD 77EE                    	ja	short dp_getchar1
  1160                                  
  1161                                  	;sub	al, '0'
  1162 000005FF 30FF                    	xor	bh, bh
  1163 00000601 88C3                    	mov	bl, al
  1164                                  	;dec	bl
  1165 00000603 80EB31                  	sub	bl, '1'
  1166 00000606 38BF[F871]              	cmp	byte [bx+valid_ppnums], bh ; 0 ; 12/02/2019
  1167 0000060A 76E1                    	jna	short dp_getchar1  ; Empty partition table entry, it is not shown
  1168                                  	
  1169 0000060C 881E[0372]              	mov	[del_part_num], bl ; Selected partition number to be deleted.
  1170                                  	;add	al, '0'
  1171 00000610 A2[555E]                	mov	[chr_del_pnum1], al ; Partition number for "Enter ..." text
  1172 00000613 A2[F75E]                	mov	[chr_del_pnum2], al ; Partition number for "Do you want ..." text
  1173                                  
  1174 00000616 BE[555E]                	mov	si, chr_del_pnum1 ; write partition number (user input)
  1175 00000619 E86318                  	call	print_msg
  1176                                  
  1177                                  	;xor	al, al
  1178 0000061C A2[555E]                	mov	[chr_del_pnum1], al ; 0 ; reset
  1179                                  
  1180 0000061F BE[595E]                	mov	si, msg_delete_partition_q ; question for deleting (with warning)
  1181 00000622 E85A18                  	call	print_msg
  1182                                  
  1183                                  dp_getchar2:
  1184 00000625 30E4                    	xor	ah, ah
  1185 00000627 CD16                    	int	16h
  1186                                  
  1187 00000629 3C1B                    	cmp	al, 27
  1188 0000062B 7416                    	je	short dp_esc
  1189                                  
  1190 0000062D 24DF                    	and	al, 0DFh
  1191 0000062F 3C59                    	cmp	al, 'Y'
  1192 00000631 7418                    	je	short dp_yes
  1193 00000633 3C4E                    	cmp	al, 'N'
  1194 00000635 75EE                    	jne	short dp_getchar2
  1195                                  dp_no:
  1196 00000637 BE[095F]                	mov	si, msg_NO ;  Write 'NO' (it may be shown for a moment)
  1197 0000063A E84218                  	call	print_msg
  1198                                  	
  1199 0000063D BE[6057]                	mov	si, CRLF  ; Next line
  1200 00000640 E83C18                  	call	print_msg
  1201                                  	
  1202                                  	;jmp	short dp_esc
  1203                                  
  1204                                  cp_esc:
  1205                                  ap_esc:
  1206                                  wptmbr_esc:
  1207                                  dp_esc:
  1208 00000643 30C0                    	xor	al, al  ; MBR/PRIMARY PARTITIONS
  1209 00000645 E8D723                  	call	display_partition_table
  1210 00000648 E999FD                  	jmp	A_44
  1211                                  
  1212                                  dp_yes:
  1213 0000064B BE[035F]                	mov	si, msg_YES ;  Write 'YES' (it may be shown for a moment)
  1214 0000064E E82E18                  	call	print_msg
  1215                                  
  1216 00000651 BF[F659]                	mov	di, MasterBootBuff+pTableOffset
  1217 00000654 A0[0372]                	mov	al, [del_part_num]
  1218 00000657 20C0                    	and 	al, al
  1219 00000659 7406                    	jz	short dp_4
  1220 0000065B 98                      	cbw
  1221                                  	;xor	ah, ah
  1222 0000065C C0E004                  	shl	al, 4 ; * 16
  1223 0000065F 01C7                    	add	di, ax
  1224                                  dp_4:
  1225 00000661 BE[6057]                	mov	si, CRLF ; Next line	
  1226 00000664 E81818                  	call	print_msg
  1227                                  
  1228                                  	; 27/02/2019
  1229 00000667 807D0405                	cmp	byte [di+ptFileSystemID], 5
  1230 0000066B 7547                    	jne	short dp_5
  1231                                  
  1232 0000066D 3806[E46F]              	cmp	byte [ldrives], al ; 0
  1233 00000671 7641                    	jna	short dp_5
  1234                                  
  1235 00000673 BE[1F62]                	mov	si, msg_ext_part_del_error	
  1236 00000676 E80618                  	call	print_msg
  1237 00000679 BE[5F62]                	mov	si, msg_cancel_continue
  1238 0000067C E80018                  	call	print_msg
  1239                                       	
  1240 0000067F 30E4                    	xor	ah, ah
  1241 00000681 CD16                    	int	16h
  1242                                  	
  1243 00000683 3C1B                    	cmp	al, 27 ; ESCape
  1244 00000685 74BC                    	je	short dp_esc
  1245                                  
  1246 00000687 E8532C                  	call	delete_logical_drives
  1247                                  	
  1248                                  	; 28/02/2019
  1249 0000068A 803E[E46F]01            	cmp	byte [ldrives], 1
  1250 0000068F 73B2                    	jnb	short dp_esc
  1251                                  
  1252 00000691 30C0                    	xor	al, al  ; MBR/PRIMARY PARTITIONS
  1253 00000693 E88923                  	call	display_partition_table
  1254                                  
  1255 00000696 BE[F262]                	mov	si, msg_delete_ext_part
  1256 00000699 E8E317                  	call	print_msg
  1257                                  
  1258                                  dp_ask_again:
  1259 0000069C 28E4                    	sub	ah, ah
  1260 0000069E CD16                    	int	16h
  1261                                  
  1262 000006A0 3C1B                    	cmp	al, 27 ; ESCape
  1263 000006A2 749F                    	je	short dp_esc	
  1264                                  
  1265 000006A4 3C0D                    	cmp	al, 13 ; ENTER/CR
  1266 000006A6 75F4                    	jne	short dp_ask_again
  1267                                  
  1268 000006A8 BF[F659]                	mov	di, MasterBootBuff+pTableOffset
  1269 000006AB A0[0372]                	mov	al, [del_part_num]
  1270 000006AE 98                      	cbw
  1271 000006AF C0E004                  	shl	al, 4 ; * 16
  1272 000006B2 01C7                    	add	di, ax
  1273                                  dp_5:
  1274 000006B4 31C0                    	xor	ax, ax
  1275                                  
  1276                                  	; clear partition table entry in MBR buffer
  1277 000006B6 B90800                  	mov	cx, 8
  1278 000006B9 F3AB                    	rep	stosw
  1279                                  	
  1280                                  	; NOTE: Only the MBR buffer will be cleared
  1281                                  	; (Masterboot sector will not be updated unless/till
  1282                                  	;  MBR partition table -and MBR code- will be written
  1283                                  	;  to disk image as result of 'write part. table' command.)
  1284                                  
  1285 000006BB E97CFB                  	jmp	A_27 ; 08/03/2019
  1286                                   	 
  1287                                  ;-----------------------------------------------------------------------------
  1288                                  
  1289                                  write_pt_mbr:
  1290                                  	; 11/02/2019
  1291 000006BE 30C0                    	xor	al, al  ; MBR/PRIMARY PARTITIONS
  1292 000006C0 E85C23                  	call	display_partition_table
  1293                                  
  1294 000006C3 BE[0D5F]                	mov	si, msg_write_masterboot_sector
  1295 000006C6 E8B617                  	call	print_msg
  1296                                  
  1297 000006C9 A2[D46F]                	mov	[GetChar], al ; 0
  1298                                  
  1299 000006CC BE[F05F]                	mov	si, option_input
  1300 000006CF E8AD17                  	call	print_msg
  1301                                  
  1302 000006D2 B403                    	mov	ah, 3
  1303                                  	;mov	bx, 7
  1304 000006D4 CD10                    	int	10h ; Return Cursor Position
  1305                                  	; DL = Column
  1306                                  	
  1307 000006D6 FECA                    	dec	dl ; previous char ; ']'
  1308 000006D8 FECA                    	dec	dl ; previous char ; '[ ]'
  1309                                  
  1310 000006DA B402                    	mov	ah, 2
  1311                                  	;mov	bx, 7
  1312 000006DC CD10                    	int	10h ; Set Cursor Position
  1313                                  
  1314                                  	; write char at current cursor position
  1315                                  
  1316 000006DE B030                    	mov	al, '0' ; Write default char
  1317                                  
  1318                                  	;;mov	bx, 07h
  1319 000006E0 B409                    	mov	ah, 09h
  1320 000006E2 B90100                  	mov	cx, 1
  1321 000006E5 CD10                    	int	10h
  1322                                  
  1323                                  wptmbr_getchar:
  1324 000006E7 30E4                    	xor	ah, ah              
  1325 000006E9 CD16                    	int	16h
  1326                                  
  1327 000006EB 3C1B                    	cmp	al, 1Bh ; 27
  1328 000006ED 0F8452FF                	je	wptmbr_esc ; 19/10/2020
  1329                                  
  1330 000006F1 3C0D                    	cmp	al, 0Dh ; 13
  1331 000006F3 7414                    	je	short wptmbr_1
  1332                                                  
  1333 000006F5 3C31                    	cmp	al, '1'
  1334 000006F7 72EE                    	jb	short wptmbr_getchar
  1335                                  
  1336 000006F9 3C32                    	cmp	al, '2'
  1337 000006FB 77EA                    	ja 	short wptmbr_getchar
  1338                                  
  1339 000006FD A2[D46F]                	mov	[GetChar], al
  1340                                  
  1341                                  	;;mov	bx, 07h
  1342 00000700 B409                    	mov	ah, 09h
  1343 00000702 B90100                  	mov	cx, 1
  1344 00000705 CD10                    	int	10h
  1345 00000707 EBDE                    	jmp	short wptmbr_getchar
  1346                                  
  1347                                  wptmbr_1:
  1348 00000709 803E[D46F]00            	cmp	byte [GetChar], 0
  1349 0000070E 76D7                    	jna	short wptmbr_getchar
  1350                                  
  1351 00000710 BE[BE5F]                	mov	si, msg_writing_ptable
  1352 00000713 E86917                  	call	print_msg
  1353                                  
  1354 00000716 803E[D46F]32            	cmp	byte [GetChar], '2'
  1355 0000071B 7471                    	je	short wptmbr_5
  1356                                  
  1357                                  wptmbr_2:
  1358                                  	; this may not be needed here (?)
  1359                                  	; ('seek' file pointer is needed flag)
  1360 0000071D C606[AC41]01            	mov 	byte [random], 1
  1361                                  
  1362 00000722 833E[A441]00            	cmp	word [img_file_handle], 0
  1363 00000727 7713                    	ja	short wptmbr_3
  1364                                  
  1365                                  	; Open disk image file again.
  1366                                  
  1367 00000729 FE0E[AC41]              	dec	byte [random] ; 0 ; masteeboot sector will be written		 
  1368                                  			  	  ; no need to seek file pointer
  1369                                  
  1370 0000072D BA[915A]                	mov	dx, img_file_name
  1371 00000730 B8023D                  	mov	ax, 3D02h ; open file for reading and writing
  1372 00000733 CD21                    	int	21h
  1373 00000735 0F823017                	jc	D_02
  1374                                  
  1375 00000739 A3[A441]                	mov	[img_file_handle], ax
  1376                                  wptmbr_3:
  1377 0000073C 31C0                    	xor	ax, ax ; 0
  1378 0000073E 31D2                    	xor	dx, dx ; 0
  1379                                  	; DX_AX = Masterboot Sector = 0
  1380 00000740 BB[3858]                	mov	bx, MasterBootBuff
  1381                                  	; ES:BX = Sector Buffer
  1382 00000743 E84817                  	call	write_hd_sector
  1383 00000746 0F821517                	jc	D_01 ; ! display error msg and then exit !
  1384                                  
  1385 0000074A BE[E75F]                	mov	si, _msg_OK
  1386 0000074D E82F17                  	call	print_msg
  1387                                  
  1388 00000750 803E[AC41]00            	cmp	byte [random], 0
  1389 00000755 7712                    	ja	short wptmbr_4
  1390                                  
  1391                                  	;mov	byte [random], 1
  1392                                  
  1393 00000757 8B1E[A441]              	mov	bx, [img_file_handle]
  1394 0000075B B43E                    	mov	ah, 3Eh ; close file
  1395 0000075D CD21                    	int	21h
  1396 0000075F 0F820617                	jc	D_02
  1397                                  
  1398 00000763 C706[A441]0000          	mov	word [img_file_handle], 0
  1399                                  
  1400                                  wptmbr_4:
  1401                                  	; wait for 1 second
  1402 00000769 B402                    	mov	ah, 02h
  1403 0000076B CD1A                    	int	1Ah
  1404 0000076D 8836[D46F]              	mov	[GetChar], dh
  1405                                  wptmbr_wait:
  1406 00000771 B402                    	mov	ah, 02h
  1407 00000773 CD1A                    	int	1Ah
  1408 00000775 3A36[D46F]              	cmp	dh, [GetChar]
  1409 00000779 74F6                    	je	short wptmbr_wait
  1410                                  	
  1411 0000077B BE[1958]                	mov	si, msg_press_any_key
  1412 0000077E E8FE16                  	call	print_msg
  1413                                                  
  1414 00000781 30E4                    	xor	ah, ah	; "Press any key to continue"
  1415 00000783 CD16                    	int	16h
  1416                                  
  1417 00000785 BE[6057]                	mov	si, CRLF
  1418 00000788 E8F416                  	call	print_msg
  1419                                  
  1420 0000078B E9B5FE                  	jmp	wptmbr_esc
  1421                                  
  1422                                  wptmbr_5:
  1423 0000078E BE[9333]                	mov	si, TRDOS386_MASTERBOOT_SECTOR
  1424 00000791 B9DF00                  	mov	cx, 446/2 ; Copy Singlix FS 1 MBR code
  1425                                  			  ; except Partition Table
  1426 00000794 BF[3858]                	mov	di, MasterBootBuff
  1427 00000797 F3A5                    	rep	movsw
  1428                                  	
  1429                                  	; This (Below) is not needed; because, if MBR magicword
  1430                                  	; would not be 0AA55h, we would not be able to come here!
  1431                                  	;;add	di, 64  ; skip partition table	
  1432                                  	;;mov	ax, 0AA55h
  1433                                  	;;stosw
  1434                                  	;mov 	word [MBIDCode], 0AA55h
  1435                                  
  1436                                  	; 12/02/2019
  1437                                  	; Copy CHS parameters to Singlix MBR (on disk)
  1438                                  	
  1439 00000799 BF[DC59]                	mov	di, MasterBootBuff+420
  1440                                  
  1441 0000079C A1[AA41]                	mov	ax, [cylinders]
  1442 0000079F AB                      	stosw 			; cylinders
  1443 000007A0 A1[A841]                	mov	ax, [heads]
  1444 000007A3 AB                      	stosw 			; heads
  1445 000007A4 A1[A641]                	mov	ax, [sectors]
  1446 000007A7 AB                      	stosw 			; sectors
  1447                                  
  1448 000007A8 E972FF                  	jmp	wptmbr_2
  1449                                  
  1450                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1451                                  ; Nextline & Exit
  1452                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1453                                  ; 25/02/2019
  1454                                  
  1455                                  B_01:
  1456 000007AB BE[AA45]                	mov	si, TrDOS_Welcome
  1457 000007AE E8CE16                  	call	print_msg
  1458                                  B_02:
  1459 000007B1 BE[6057]                	mov	si, CRLF
  1460                                  B_03:
  1461 000007B4 E8C816                  	call	print_msg
  1462 000007B7 B8004C                  	mov	ax, 4C00h		; terminate
  1463 000007BA CD21                    	int	21h
  1464                                  B_04:
  1465 000007BC BE[6546]                	mov	si, msg_inv_image_file
  1466 000007BF EBF3                    	jmp	short B_03 ; 03/10/2020 (short jump)
  1467                                  
  1468                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1469                                  ; Display create partition menu & get partition type input
  1470                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1471                                  
  1472                                  create_partition_input:
  1473                                  	; 15/02/2019
  1474                                  	; clear screen
  1475 000007C1 B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
  1476 000007C4 CD10                    	int	10h
  1477                                  	
  1478 000007C6 BE[5A47]                	mov	si, msg_create_partition_h ; header
  1479 000007C9 E8B316                  	call	print_msg
  1480 000007CC BE[4F48]                	mov	si, msg_create_partition_m ; menu
  1481 000007CF E8AD16                  	call	print_msg
  1482                                  cpi_1:
  1483 000007D2 30E4                    	xor	ah, ah
  1484 000007D4 CD16                    	int	16h
  1485 000007D6 3C1B                    	cmp	al, 27 ; ESC key	
  1486                                  	;;je	B_47
  1487                                  	;je	A_48 ; A_33
  1488 000007D8 7445                    	je	short cpi_4  ; 25/02/2019
  1489 000007DA 3C30                    	cmp	al, '0'
  1490                                  	;;je	B_47
  1491                                  	;je	A_48 ; A_33
  1492 000007DC 7441                    	je	short cpi_4  ; 25/02/2019
  1493 000007DE 72F2                    	jb	short cpi_1
  1494 000007E0 3C34                    	cmp	al, '4'
  1495 000007E2 77EE                    	ja	short cpi_1
  1496                                  
  1497 000007E4 30E4                    	xor	ah, ah
  1498 000007E6 2C30                    	sub	al, '0'
  1499                                  
  1500                                  	;mov	[pp_type], al
  1501                                  
  1502                                  	;mov	byte [pp_type_user], 0
  1503                                  
  1504 000007E8 3C01                    	cmp	al, 1 ; DOS partition
  1505 000007EA 7536                    	jne	short cpi_5 ; ah = 0 
  1506                                  			    ; (al = 2 -> singlix, al = 3 -> retro unix)
  1507                                  cpi_2:
  1508                                  	; clear screen
  1509 000007EC B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
  1510 000007EF CD10                    	int	10h
  1511                                  	
  1512 000007F1 BE[054A]                	mov	si, msg_create_dos_partition_h ; header
  1513 000007F4 E88816                  	call	print_msg
  1514 000007F7 BE[D94D]                	mov	si, msg_create_dos_partition_m ; menu
  1515 000007FA E88216                  	call	print_msg
  1516                                  cpi_3:
  1517 000007FD 30E4                    	xor	ah, ah
  1518 000007FF CD16                    	int	16h
  1519 00000801 3C1B                    	cmp	al, 27 ; ESC key	
  1520                                  	;je	short B_47
  1521 00000803 741A                    	je	short cpi_4
  1522 00000805 3C30                    	cmp	al, '0'
  1523                                  	;je	short B_47
  1524 00000807 7416                    	je	short cpi_4
  1525 00000809 72F2                    	jb	short cpi_3
  1526 0000080B 3C33                    	cmp	al, '3'
  1527 0000080D 77EE                    	ja	short cpi_3
  1528                                  	
  1529 0000080F 30E4                    	xor	ah, ah
  1530 00000811 2C30                    	sub	al, '0'
  1531 00000813 3C01                    	cmp	al, 1
  1532 00000815 7424                    	je	short cpi_6  ;	ah = 0 (al = primary dos partition)
  1533                                  
  1534                                  	;mov	byte [pp_type], 5
  1535                                  
  1536 00000817 3C02                    	cmp	al, 2
  1537 00000819 7621                    	jna	short cpi_7
  1538                                  
  1539 0000081B B80600                  	mov	ax, 6	; ah = 0 (al = logical dos drive/partition)
  1540 0000081E C3                      	retn
  1541                                  
  1542                                  cpi_4:
  1543 0000081F 31C0                    	xor	ax, ax	; ah = 0 (al = 0 -> ESCape/Cancel)
  1544 00000821 C3                      	retn
  1545                                  cpi_5:
  1546 00000822 3C04                    	cmp	al, 4	 ; option num. for partition type (user) input
  1547 00000824 7515                    	jne	short cpi_6
  1548                                  
  1549 00000826 E8C81A                  	call	partition_type_input
  1550                                  
  1551                                  	; 29/10/2020
  1552 00000829 08C0                    	or	al, al
  1553                                  	;jz	short cpi_6 ; invalid (zero) input or ESC key
  1554 0000082B 74F2                    	jz	short cpi_4
  1555                                  
  1556 0000082D B404                    	mov	ah, 4 ; user/another type partition flag
  1557                                  	; al = Partition ID	
  1558 0000082F 50                      	push	ax
  1559 00000830 BE[1958]                	mov	si, msg_press_any_key 
  1560 00000833 E84916                  	call	print_msg
  1561 00000836 28E4                    	sub	ah, ah
  1562 00000838 CD16                    	int	16h
  1563 0000083A 58                      	pop	ax
  1564                                  cpi_6:
  1565 0000083B C3                      	retn
  1566                                  cpi_7:
  1567 0000083C B80500                  	mov	ax, 5	; ah = 0 (al = extended dos partition)
  1568 0000083F C3                      	retn
  1569                                  
  1570                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1571                                  ; Create primary (dos or non-dos) partition
  1572                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1573                                  ; 16/02/2019 
  1574                                  ;	(This procedure must be called after 'find_part_free_space')
  1575                                  
  1576                                  create_primary_partition:  
  1577                                  	; 16/02/2019
  1578                                  
  1579                                  	; INPUT:
  1580                                  	;	none 
  1581                                  	;  (CHS parameters and free space calculation result will be used.) 
  1582                                  	;
  1583                                  	; OUTPUT:
  1584                                  	;	Partition table in MBR buffer will be updated.
  1585                                  	;
  1586                                  	; (Modified registers: ax, bx, cx, dx, si, di)
  1587                                  
  1588                                  	; Create primary dos or non-dos partition,
  1589                                  	; make partition table entry
  1590                                  
  1591 00000840 803E[AD41]00            	cmp	byte [newdisk], 0
  1592 00000845 760A                    	jna	short cpp_0
  1593                                  
  1594                                  	; cylinder = 0, head = 1, sector = 1
  1595                                  	; LBA = (((cylinder*heads)+head)*sectors)+sector-1
  1596                                  
  1597 00000847 BE[F659]                	mov	si, MasterBootBuff+pTableOffset
  1598                                  
  1599 0000084A A1[A641]                	mov	ax, [sectors] ; LBA = 17 or 63
  1600 0000084D 31D2                    	xor	dx, dx
  1601 0000084F EB56                    	jmp	short cpp_4
  1602                                  cpp_0:
  1603                                  	; 16/02/2019
  1604 00000851 E88421                  	call	get_first_free_pte
  1605                                  		 ; CX = First free PTE number, 0 to 3 
  1606                                  		 ;    (CX = 3 if there is not a free PTE, and CF = 1)
  1607                                  		 ;    ((But CF = 1 is not possible here because pcount < 4))
  1608                                   	 	 ; SI = PTE address/offset in MBR buffer
  1609                                  
  1610                                  	;mov	si, MasterBootBuff+pTableOffset
  1611                                  	;shl	cl, 4 ; * 16
  1612                                  	;add	si, cx
  1613                                  
  1614                                  	; 18/02/2019
  1615 00000854 8B3E[3E73]              	mov	di, [c_fspc_offset]
  1616 00000858 8B9D[EE72]              	mov	bx, [di+free_space.start]
  1617 0000085C A0[A841]                	mov	al, [heads]
  1618 0000085F F626[A641]              	mul	byte [sectors]
  1619 00000863 F7E3                    	mul	bx
  1620                                  		; DX:AX = LBA of start cylinder, head 0, sector 1
  1621                                  	
  1622 00000865 8A0E[4073]              	mov	cl, [cylinder_boundary]
  1623                                  
  1624                                  	;cmp	cl, 0 ; Default (partition size unit is one of C, G, M)
  1625                                  		      ; boundary alignment is forced as default
  1626                                  	;je	short cpp_4
  1627                                  
  1628                                  	; 20/02/2019
  1629                                  	;and	cl, cl
  1630                                  	;jz 	short cpp_1
  1631                                  
  1632 00000869 80F959                  	cmp	cl, 'Y'
  1633 0000086C 7439                    	je	short cpp_4 ; cylinder boundary option (answer) = YES
  1634                                  
  1635 0000086E 80F94E                  	cmp	cl, 'N'
  1636 00000871 750A                    	jne	short cpp_1 ; cylinder boundary option (answer) = YES/NO
  1637                                  
  1638                                  	; cylinder boundary option (answer) = NO 
  1639 00000873 8B85[F872]              	mov	ax, [di+free_space.startsector]
  1640 00000877 8B95[FA72]              	mov	dx, [di+free_space.startsector+2]
  1641 0000087B EB2A                    	jmp	short cpp_4
  1642                                  cpp_1:
  1643                                  	;cmp	cl, 27 ; ESCape
  1644                                  	;jne	short cpp_4 ; 'Y'
  1645                                  
  1646                                  	; check	cylinder boundary alignment of the start sector
  1647                                  
  1648                                  	; if start sector is not aligned, end sector must not be aligned
  1649                                  	; (this rule is valid for ESCape key from the user) 
  1650                                  
  1651 0000087D C606[4073]59            	mov	byte [cylinder_boundary], 'Y' ; YES for end sector check
  1652                                  
  1653 00000882 8B8D[F872]              	mov	cx, [di+free_space.startsector]
  1654                                  
  1655 00000886 09DB                    	or	bx, bx
  1656                                  
  1657 00000888 8B9D[FA72]              	mov	bx, [di+free_space.startsector+2]
  1658                                  
  1659 0000088C 7508                    	jnz	short cpp_2 ; start cylinder > 0
  1660                                  
  1661                                  	;and	bx, bx
  1662                                  	;jnz	short cpp_3
  1663                                  
  1664 0000088E 3B0E[A641]              	cmp	cx, [sectors]
  1665 00000892 7413                    	je	short cpp_4 ; start sector is as aligned 
  1666 00000894 EB08                    	jmp	short cpp_3
  1667                                  cpp_2:
  1668 00000896 39C8                    	cmp	ax, cx
  1669 00000898 7504                    	jne	short cpp_3
  1670 0000089A 39DA                    	cmp	dx, bx
  1671 0000089C 7409                    	je	short cpp_4 
  1672                                  cpp_3:
  1673 0000089E 89C8                    	mov	ax, cx
  1674 000008A0 89DA                    	mov	dx, bx
  1675 000008A2 C606[4073]4E            	mov	byte [cylinder_boundary], 'N'
  1676                                  cpp_4:
  1677 000008A7 894408                  	mov	[si+ptStartSector], ax
  1678 000008AA 89540A                  	mov	[si+ptStartSector+2], dx
  1679                                  
  1680                                  	; save start sector (for partition formatting procedure)
  1681 000008AD A3[A86F]                	mov	[pp_StartSector], ax
  1682 000008B0 8916[AA6F]              	mov	[pp_StartSector+2], dx
  1683                                  
  1684 000008B4 803E[AD41]00            	cmp	byte [newdisk], 0
  1685 000008B9 763F                    	jna	short cpp_5
  1686                                  
  1687 000008BB 31C9                    	xor	cx, cx
  1688 000008BD 894C03                  	mov	[si+ptBeginCylinder], cx ; 0
  1689 000008C0 FEC1                    	inc	cl  ; 1
  1690 000008C2 884C02                  	mov	[si+ptBeginSector], cl ; 1
  1691 000008C5 884C01                  	mov	[si+ptBeginHead], cl ; 1
  1692                                  
  1693                                  	; set active partition flag
  1694                                  	;mov	byte [si+ptBootable], 80h ; bootable/active partition
  1695 000008C8 C60480                  	mov	byte [si], 80h ; bootable/active partition
  1696                                  
  1697                                  	; 18/02/2019
  1698                                  
  1699 000008CB 8B0E[DC6F]              	mov	cx, [ppn_Sectors]
  1700 000008CF 8B1E[DE6F]              	mov	bx, [ppn_Sectors+2]
  1701                                  
  1702 000008D3 803E[B06F]00            	cmp	byte [wholedisk], 0
  1703 000008D8 0F861101                	jna	cpp_12
  1704                                  
  1705 000008DC A0[A841]                	mov	al, [heads]
  1706 000008DF FEC8                    	dec	al
  1707 000008E1 884405                  	mov	[si+ptEndHead], al
  1708 000008E4 A0[A641]                	mov	al, [sectors]
  1709 000008E7 884406                  	mov	[si+ptEndSector], al
  1710 000008EA A1[AA41]                	mov	ax, [cylinders]
  1711 000008ED 48                      	dec	ax
  1712 000008EE 884407                  	mov	[si+ptEndCylinder], al
  1713 000008F1 C0E406                  	shl	ah, 6
  1714 000008F4 086406                  	or	[si+ptEndSector], ah		
  1715                                  
  1716                                  	;jmp	cpp_16
  1717 000008F7 E96801                  	jmp	cpp_15 ; 06/03/2019	
  1718                                  cpp_5:
  1719                                  	; 18/02/2019
  1720                                  		
  1721 000008FA 803E[4073]59            	cmp	byte [cylinder_boundary], 'Y'
  1722 000008FF 753D                    	jne	short cpp_7
  1723                                  
  1724 00000901 30DB                    	xor	bl, bl ; head  = 0
  1725                                  
  1726 00000903 8B8D[EE72]              	mov	cx, [di+free_space.start]
  1727                                  
  1728                                  	; 06/03/2019
  1729                                  	;or	ax, ax
  1730                                  	;jnz	short cpp_6
  1731                                  
  1732                                  	;and	cx, cx  ; start cylinder = 0 ?
  1733                                  	;jnz	short cpp_6
  1734                                  
  1735 00000907 09C8                    	or	ax, cx
  1736 00000909 740B                    	jz	short cpp_16 ; 31/10/2020
  1737                                  
  1738                                  	; 31/10/2020
  1739 0000090B A0[A641]                	mov	al, [sectors]
  1740 0000090E F626[A841]              	mul	byte [heads]
  1741 00000912 F7E1                    	mul	cx
  1742                                  	; dx:ax = LBA sector address
  1743                                  	; bl = head = 0
  1744                                  	; cx = cylinder number
  1745                                  	; ax = sector number
  1746 00000914 EB07                    	jmp	short cpp_6
  1747                                  cpp_16:
  1748 00000916 A1[A641]                	mov	ax, [sectors]
  1749                                  	; cylinder 0, head 1, sector 1 (LBA = 17 or 63)
  1750 00000919 FEC3                    	inc	bl  ; head = 1
  1751 0000091B 31D2                    	xor	dx, dx ; 0
  1752                                  cpp_6:
  1753                                  	; 31/10/2020
  1754 0000091D 894408                  	mov	[si+ptStartSector], ax
  1755 00000920 89540A                  	mov	[si+ptStartSector+2], dx
  1756                                  
  1757 00000923 A3[A86F]                	mov	[pp_StartSector], ax
  1758 00000926 8916[AA6F]              	mov	[pp_StartSector+2], dx
  1759                                  
  1760 0000092A 09C9                    	or	cx, cx  ; start cylinder ?
  1761 0000092C 7508                    	jnz	short cpp_17 ; > 0
  1762                                  	
  1763                                  	;and	bl, bl  ; head = 0 ?
  1764                                  	;jz	short cpp_17
  1765                                  
  1766                                  	; cylinder = 0, head = 1, dx:ax = [sectors]
  1767                                  
  1768                                  	;sub	[pp_Sectors], ax
  1769                                  	;sbb	[pp_Sectors+2], cx ; 0
  1770                                  
  1771 0000092E 2906[DC6F]              	sub	[ppn_Sectors], ax
  1772 00000932 190E[DE6F]              	sbb	[ppn_Sectors+2], cx ; 0
  1773                                  cpp_17:
  1774 00000936 89C8                    	mov	ax, cx
  1775 00000938 C6440201                	mov	byte [si+ptBeginSector], 1 ; sector = 1		
  1776 0000093C EB16                    	jmp	short cpp_8		
  1777                                  cpp_7:
  1778                                  	; 18/02/2019
  1779                                  
  1780                                  	; [wholedisk] = 0
  1781                                  
  1782                                  	; Fix partition size for MSDOS 3.3 (Retro DOS 3.0) compatibility.
  1783                                  	; (DOS partition size will be changed -down- to 65535 sectors,
  1784                                  	; if it is 65536 sectors.)
  1785                                  	
  1786 0000093E E83101                  	call	fix_32mb_dos_psize
  1787                                  
  1788                                  	;cylinder = LBA / (heads_per_cylinder * sectors_per_track)
  1789                                  	;temp = LBA % (heads_per_cylinder * sectors_per_track)
  1790                                  	;head = temp / sectors_per_track
  1791                                  	;sector = temp % sectors_per_track + 1
  1792                                  	
  1793                                  	; Convert LBA sector address to CHS parameters
  1794 00000941 8B0E[A641]              	mov	cx, [sectors]
  1795 00000945 E82A05                  	call	div32
  1796                                  	; BX = Sector number - 1
  1797 00000948 FEC3                    	inc	bl ; sector number (1 based)
  1798 0000094A 885C02                  	mov	[si+ptBeginSector], bl	
  1799                                  	; DX_AX = cylinders * heads + head
  1800 0000094D 8B0E[A841]              	mov	cx, [heads]
  1801 00000951 E81E05                  	call	div32
  1802                                  cpp_8:
  1803                                  	; BX = Head number
  1804 00000954 885C01                  	mov	[si+ptBeginHead], bl
  1805                                  	; AX = Cylinder number
  1806                                  	;and	ax, 1023
  1807 00000957 884403                  	mov	[si+ptBeginCylinder], al
  1808 0000095A C0E406                  	shl	ah, 6
  1809 0000095D 086402                  	or	[si+ptBeginSector], ah
  1810                                  
  1811                                  	; clear active partition flag (for now)
  1812                                  	;mov	byte [si+ptBootable], 0 ; not bootable/active partition
  1813 00000960 C60400                  	mov	byte [si], 0 ; not bootable/active partition
  1814                                  
  1815                                  	;mov	di, [c_fspc_offset]
  1816                                  
  1817 00000963 803E[4073]59            	cmp	byte [cylinder_boundary], 'Y'
  1818 00000968 7574                    	jne	short cpp_11
  1819                                  
  1820 0000096A 8A0E[A841]              	mov	cl, [heads]
  1821 0000096E A0[A641]                	mov	al, [sectors]
  1822 00000971 88C5                    	mov	ch, al
  1823 00000973 F6E1                    	mul	cl	
  1824                                  	; ax = heads*sectors
  1825                                  
  1826 00000975 8B9D[F072]              	mov	bx, [di+free_space.end]	; end cylinder of the partition
  1827                                  
  1828 00000979 803E[B06F]00            	cmp	byte [wholedisk], 0 ; entire free space ?
  1829 0000097E 7721                    	ja	short cpp_10
  1830                                  
  1831 00000980 89C3                    	mov	bx, ax
  1832 00000982 A1[DC6F]                	mov	ax, [ppn_Sectors]
  1833 00000985 8B16[DE6F]              	mov	dx, [ppn_Sectors+2]
  1834 00000989 0306[A86F]              	add	ax, [pp_StartSector]
  1835 0000098D 1316[AA6F]              	adc	dx, [pp_StartSector+2]
  1836 00000991 83E801                  	sub	ax, 1
  1837 00000994 83DA00                  	sbb	dx, 0
  1838                                  		; dx:ax = end sector
  1839 00000997 F7F3                    	div	bx
  1840                                  		; ax = cylinder number
  1841                                  	; 31/10/2020
  1842                                  	;and	dx, dx
  1843                                  	;jz	short cpp_9
  1844                                  	;inc	ax ; + 1 (because of remainder > 0)
  1845                                  cpp_9:	
  1846 00000999 93                      	xchg	ax, bx
  1847                                  		; bx = end cylinder
  1848                                  		; ax = heads*sectors
  1849                                  	; free space limit check
  1850 0000099A 3B9D[F072]              	cmp	bx, [di+free_space.end]
  1851 0000099E 7601                    	jna	short cpp_10 ; ok
  1852                                  	; end cylinder is out of free space	
  1853 000009A0 4B                      	dec	bx  ; decrease end cylinder number
  1854                                  cpp_10: 
  1855 000009A1 F7E3                    	mul	bx
  1856                                  		 ; dx:ax = (end cylinder)*heads*sectors
  1857 000009A3 52                      	push	dx ; **
  1858 000009A4 50                      	push	ax ; *
  1859 000009A5 FEC9                    	dec	cl ; heads - 1 = end head
  1860                                  
  1861 000009A7 884C05                  	mov	[si+ptEndHead], cl
  1862                                  		
  1863                                  	;mov	al, [sectors]
  1864 000009AA 88E8                    	mov	al, ch
  1865 000009AC 885C07                  	mov	[si+ptEndCylinder], bl
  1866 000009AF 88C3                    	mov	bl, al
  1867 000009B1 C0E706                  	shl	bh, 6 ; shift high bytes (2 bits) of end cyl num
  1868                                  		      ; to 6 bits left	
  1869 000009B4 08DF                    	or	bh, bl ; combine high bits of end cyl num and end sector		
  1870 000009B6 887C06                  	mov	[si+ptEndSector], bh
  1871 000009B9 30FF                    	xor	bh, bh ; clear bh
  1872 000009BB FECB                    	dec	bl ; sectors - 1 ; 22/02/2019
  1873 000009BD F6E1                    	mul	cl
  1874 000009BF 5A                      	pop	dx ; *
  1875                                  	; 22/02/2019
  1876 000009C0 31C9                    	xor	cx, cx
  1877 000009C2 01D0                    	add	ax, dx
  1878 000009C4 5A                      	pop	dx ; **
  1879 000009C5 11CA                    	adc	dx, cx ; 0
  1880 000009C7 01D8                    	add	ax, bx
  1881 000009C9 11CA                    	adc	dx, cx ; 0
  1882                                  	; dx:ax = ((([end cylinder]*heads)+[end head])*sectors)+sectors-1
  1883                                  
  1884                                  	; calculate aligned partition size in sectors
  1885 000009CB 89C1                    	mov	cx, ax
  1886 000009CD 89D3                    	mov	bx, dx
  1887 000009CF 83C101                  	add	cx, 1
  1888 000009D2 83D300                  	adc	bx, 0	
  1889 000009D5 2B4C08                  	sub	cx, [si+ptStartSector]
  1890 000009D8 1B5C0A                  	sbb	bx, [si+ptStartSector+2]
  1891                                  		; bx:cx = partition size
  1892                                  	;mov	[ppn_Sectors], cx
  1893                                  	;mov	[ppn_Sectors+2], bx
  1894                                  	;jmp	cpp_16
  1895 000009DB E98400                  	jmp	cpp_15 ; 06/03/2019
  1896                                  cpp_11:
  1897                                  	; 20/02/2019
  1898 000009DE 8B0E[DC6F]              	mov	cx, [ppn_Sectors]
  1899 000009E2 8B1E[DE6F]              	mov	bx, [ppn_Sectors+2]
  1900                                  
  1901                                  	;;mov	ax, [di+free_space.startsector]
  1902                                  	;;mov	ax, [di+free_space.startsector+2]
  1903                                  	;mov	ax, [si+ptStartSector]
  1904                                  	;mov	dx, [si+ptStartSector+2]
  1905 000009E6 A1[A86F]                	mov	ax, [pp_StartSector]
  1906 000009E9 8B16[AA6F]              	mov	dx, [pp_StartSector+2]
  1907                                  cpp_12:	
  1908                                  	; 18/02/2019
  1909                                  
  1910                                  	; [wholedisk] = 0
  1911                                  
  1912                                  	; Fix partition size for MSDOS 3.3 (Retro DOS 3.0) compatibility.
  1913                                  	; (DOS partition size will be changed -down- to 65535 sectors,
  1914                                  	; if it is 65536 sectors.)
  1915                                  
  1916 000009ED E88200                  	call	fix_32mb_dos_psize
  1917                                  
  1918 000009F0 01C8                    	add	ax, cx
  1919 000009F2 11DA                    	adc	dx, bx
  1920                                  
  1921                                  	; Convert LBA sector address to CHS parameters
  1922 000009F4 83E801                  	sub	ax, 1 ; locate on to end sector of the partition
  1923 000009F7 83DA00                  	sbb	dx, 0
  1924                                  	
  1925                                  	; 06/03/2019
  1926 000009FA 803E[4073]59            	cmp	byte [cylinder_boundary],'Y'
  1927                                  	;jne	short cpp_15
  1928 000009FF 753A                    	jne	short cpp_14
  1929                                  
  1930 00000A01 89C1                    	mov	cx, ax
  1931 00000A03 A0[A841]                	mov	al, [heads]
  1932 00000A06 F626[A641]              	mul	byte [sectors]
  1933 00000A0A 89C7                    	mov	di, ax ; [heads]*[sectors]
  1934 00000A0C 91                      	xchg	ax, cx
  1935                                  		; cx = heads*spt
  1936 00000A0D E86204                  	call	div32
  1937                                  		; dx = 0
  1938                                  		; ax = end cylinder
  1939                                  		; bx = remainder	
  1940                                  	;and	bx, bx
  1941                                  	;jz	short cpp_13
  1942                                  	;inc	ax
  1943                                  ;cpp_13:
  1944                                  	;cmp	ax, [cylinders]
  1945                                  	;jb	short cpp_14
  1946                                  	;dec	ax
  1947                                  ;cpp_14:
  1948 00000A10 8B1E[A841]              	mov	bx, [heads]
  1949 00000A14 FECB                    	dec	bl
  1950 00000A16 885C05                  	mov	[si+ptEndHead], bl
  1951 00000A19 8B0E[A641]              	mov	cx, [sectors]
  1952 00000A1D 88E2                    	mov	dl, ah
  1953 00000A1F C0E206                  	shl	dl, 6
  1954 00000A22 08CA                    	or	dl, cl
  1955 00000A24 885406                  	mov	[si+ptEndSector], dl
  1956 00000A27 884407                  	mov	[si+ptEndCylinder], al	
  1957                                  	;mul	di ; [cylinders]*[heads]*[sectors]
  1958                                  	;;sub	di, cx ; ([heads] - 1) * [sectors]
  1959                                  	;add	ax, di
  1960                                  	;adc	dx, 0
  1961                                  	;;add	ax, cx
  1962                                  	;;adc	dx, 0
  1963 00000A2A 40                      	inc	ax
  1964 00000A2B F7E7                    	mul	di  ; result = start LBA of next cylinder
  1965                                  	; dx:ax = end sector LBA + 1 (as cyl. boundary aligned)
  1966 00000A2D 2B06[A86F]              	sub	ax, [pp_StartSector]
  1967 00000A31 1B16[AA6F]              	sbb	dx, [pp_StartSector+2] ; 26/10/2020
  1968                                  
  1969 00000A35 89C1                    	mov	cx, ax
  1970 00000A37 89D3                    	mov	bx, dx
  1971                                  	;jmp	short cpp_16
  1972 00000A39 EB27                    	jmp	short cpp_15
  1973                                  ;cpp_15:
  1974                                  cpp_14:
  1975 00000A3B 8B0E[A641]              	mov	cx, [sectors]
  1976 00000A3F E83004                  	call	div32
  1977                                  	; BX = Sector number - 1
  1978 00000A42 FEC3                    	inc	bl ; sector number (1 based)
  1979 00000A44 885C06                  	mov	[si+ptEndSector], bl	
  1980                                  	; DX_AX = cylinders * heads + head
  1981 00000A47 8B0E[A841]              	mov	cx, [heads]
  1982 00000A4B E82404                  	call	div32
  1983                                  	; BX = Head number
  1984 00000A4E 885C05                  	mov	[si+ptEndHead], bl
  1985                                  	; AX = Cylinder number
  1986                                  	;and	ax, 1023
  1987 00000A51 884407                  	mov	[si+ptEndCylinder], al
  1988                                  	; 18/02/2019
  1989 00000A54 C0E406                  	shl	ah, 6
  1990 00000A57 086406                  	or	[si+ptEndSector], ah
  1991                                  
  1992 00000A5A 8B0E[DC6F]              	mov	cx, [ppn_Sectors]
  1993 00000A5E 8B1E[DE6F]              	mov	bx, [ppn_Sectors+2]
  1994                                  ;cpp_16:
  1995                                  cpp_15:
  1996 00000A62 894C0C                  	mov	[si+ptSectors], cx
  1997 00000A65 895C0E                  	mov	[si+ptSectors+2], bx
  1998                                  
  1999                                  	; set partition ID after checking DOS FAT limits
  2000 00000A68 E8CD00                  	call	set_partition_id
  2001                                  	; al = partition ID
  2002                                  
  2003 00000A6B A2[B16F]                	mov	[pp_type], al
  2004                                  
  2005 00000A6E 884404                  	mov	[si+ptFileSystemID], al
  2006                                  
  2007 00000A71 C3                      	retn
  2008                                  
  2009                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2010                                  ; Decrease DOS partition size when it is (exact) 65536 sectors
  2011                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2012                                  ; 18/02/2019
  2013                                  
  2014                                  fix_32mb_dos_psize:	; call this if [wholedisk] = 0
  2015                                  
  2016                                  ; Purpose: 
  2017                                  ;	If a DOS partition's size is 65536 sectors
  2018                                  ;	MSDOS 3.3 can not use it. (FAT 16 partition ID = 06h)
  2019                                  ;	Decreasing partition size to 65535 sectors will ensure
  2020                                  ;	MSDOS 3.3 compatibility (FAT 16 partition ID will be 04h).			
  2021                                  
  2022                                  	; INPUT:
  2023                                  	;    BX:CX = partition size in sectors
  2024                                  	;    [pp_type] = partition type dos, non-dos, user input
  2025                                  	;
  2026                                  	; OUTPUT:
  2027                                  	;    Partition size will be changed to 65535 sectors, if
  2028                                  	;    	- partition size is 65536 sectors and
  2029                                  	; 	- [pp_type] is 1 (DOS)
  2030                                  	;
  2031                                  	;    [ppn_Sectors] = 65535 (if it will be changed)
  2032                                  	;
  2033                                  	; (Modified registers: cx, bx) 
  2034                                  
  2035                                  	;mov	cx, [ppn_Sectors]
  2036                                  	;mov	bx, [ppn_Sectors+2]
  2037                                  
  2038 00000A72 803E[B16F]01            	cmp	byte [pp_type], 1 ;  DOS partition
  2039 00000A77 7513                    	jne	short psfx_0  ; non-dos partition or user input
  2040                                  			      ; nothing to do ! 	
  2041 00000A79 09C9                    	or	cx, cx
  2042 00000A7B 750F                    	jnz	short psfx_0 ; <> 65536 sectors
  2043 00000A7D 83FB01                  	cmp	bx, 1
  2044 00000A80 750A                    	jne	short psfx_0
  2045 00000A82 4B                      	dec	bx
  2046                                  	;mov	[wholedisk], bx ; 0
  2047 00000A83 49                      	dec	cx  ; bx:cx = 65535
  2048 00000A84 890E[DC6F]              	mov	[ppn_Sectors], cx
  2049 00000A88 891E[DE6F]              	mov	[ppn_Sectors+2], bx
  2050                                  psfx_0:
  2051 00000A8C C3                      	retn
  2052                                  
  2053                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2054                                  ; Create extended dos partition
  2055                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2056                                  ; 16/02/2019 
  2057                                  ;	(This procedure must be called after 'find_part_free_space')
  2058                                  
  2059                                  create_extended_partition:  
  2060                                  	; 15/02/2019
  2061                                  
  2062                                  	; INPUT:
  2063                                  	;	none 
  2064                                  	;  (CHS parameters and free space calculation result will be used.) 
  2065                                  	;
  2066                                  	; OUTPUT:
  2067                                  	;	Partition table in MBR buffer will be updated.
  2068                                  	;
  2069                                  	; (Modified registers: ax, bx, cx, dx, si, di)
  2070                                  
  2071                                  	; Create extended dos partition, make partition table entry
  2072                                  	; (Extended partition will be created on cylinder bounds.)
  2073                                  
  2074                                  	; 16/02/2019
  2075 00000A8D E8481F                  	call	get_first_free_pte
  2076                                  		 ; CX = First free PTE number, 0 to 3 
  2077                                  		 ;    (CX = 3 if there is not a free PTE, and CF = 1)
  2078                                  		 ;    ((But CF = 1 is not possible here because pcount < 4))
  2079                                   	 	 ; SI = PTE addres/offset in MBR buffer
  2080                                  
  2081                                  	;mov	si, MasterBootBuff+pTableOffset
  2082                                  	;shl	cl, 4 ; * 16
  2083                                  	;add	si, cx
  2084                                  	
  2085 00000A90 8B1E[3E73]              	mov	bx, [c_fspc_offset]
  2086                                  	
  2087 00000A94 8B87[EE72]              	mov	ax, [bx+free_space.start]
  2088 00000A98 89C7                    	mov	di, ax
  2089                                  
  2090                                  	;mov	cx, 1
  2091 00000A9A B101                    	mov	cl, 1
  2092                                  
  2093                                  	;mov	byte [si+ptBootable], 0 ; not bootable/active partition
  2094 00000A9C 882C                    	mov	[si], ch ; 0 ; not bootable/active partition
  2095 00000A9E 886C01                  	mov	[si+ptBeginHead], ch ; Head 0 
  2096 00000AA1 C0E406                  	shl	ah, 6
  2097 00000AA4 08E1                    	or	cl, ah
  2098 00000AA6 884C02                  	mov	[si+ptBeginSector], cl ; Sector 1 
  2099 00000AA9 884403                  	mov	[si+ptBeginCylinder], al
  2100                                  
  2101 00000AAC A0[A841]                	mov	al, [heads]
  2102 00000AAF F626[A641]              	mul	byte [sectors]
  2103                                  		; ax = heads*sectors
  2104 00000AB3 F7E7                    	mul	di  ; AX * cylinder count before start cylinder
  2105                                  		; DX:AX = LBA of cylinder DI, head 0, sector 1 
  2106                                  
  2107 00000AB5 894408                  	mov	[si+ptStartSector], ax
  2108 00000AB8 89540A                  	mov	[si+ptStartSector+2], dx
  2109                                  
  2110                                  	; This is not needed for extended partition.
  2111                                  	; 16/02/2019
  2112                                  	;mov	[pp_StartSector], ax
  2113                                  	;mov	[pp_StartSector+2], dx
  2114                                  
  2115                                  	; 16/02/2019
  2116 00000ABB 803E[B06F]00            	cmp	byte [wholedisk], 0
  2117 00000AC0 772A                    	ja	short cep_2 ; all of free space will be used
  2118                                  			    ; ([bx+free_space.end] will be end cyl)	
  2119                                  
  2120                                  	; calculate cylinder count (from partition size input)
  2121 00000AC2 A0[A841]                	mov	al, [heads]
  2122 00000AC5 F626[A641]              	mul	byte [sectors]
  2123 00000AC9 89C1                    	mov	cx, ax
  2124 00000ACB A1[DC6F]                	mov	ax, [ppn_Sectors]
  2125 00000ACE 8B16[DE6F]              	mov	dx, [ppn_Sectors+2]
  2126 00000AD2 E89D03                  	call	div32
  2127                                  		; ax = cylinders
  2128                                  		; bx = remainder
  2129 00000AD5 21DB                    	and	bx, bx
  2130 00000AD7 7401                    	jz	short cep_1
  2131                                  
  2132 00000AD9 40                      	inc	ax  ; round up
  2133                                  cep_1:
  2134                                  	; 16/02/2019
  2135                                  	; DI  = extended partition's start cylinder
  2136 00000ADA 89C2                    	mov	dx, ax ; cylinder count
  2137 00000ADC 01FA                    	add	dx, di ; result is end cyl + 1
  2138 00000ADE 4A                      	dec	dx ; decrease number for current end cylinder
  2139 00000ADF 8B1E[3E73]              	mov	bx, [c_fspc_offset]
  2140 00000AE3 3B97[F072]              	cmp	dx, [bx+free_space.end]
  2141 00000AE7 7607                    	jna	short cep_3
  2142                                  	; 24/10/2020
  2143                                  	;dec	ax ; decrease cylinder count down to the limit
  2144 00000AE9 4A                      	dec	dx ; decrease end cylinder down to the limit		  
  2145 00000AEA EB04                    	jmp	short cep_3 	
  2146                                  cep_2:
  2147 00000AEC 8B97[F072]              	mov	dx, [bx+free_space.end]
  2148                                  	; 24/10/2020
  2149                                  	;mov	ax, [bx+free_space.space]
  2150                                  cep_3:
  2151 00000AF0 8A2E[A841]              	mov	ch, [heads]
  2152 00000AF4 FECD                    	dec	ch 
  2153 00000AF6 8A0E[A641]              	mov	cl, [sectors]
  2154 00000AFA 886C05                  	mov	[si+ptEndHead], ch
  2155                                  	; 23/02/2019
  2156 00000AFD 88F3                    	mov	bl, dh
  2157 00000AFF C0E306                  	shl	bl, 6
  2158 00000B02 08CB                    	or	bl, cl
  2159                                  	;or	[si+ptEndSector], bl
  2160                                  	; 24/10/2020
  2161 00000B04 885C06                  	mov	[si+ptEndSector], bl
  2162 00000B07 885407                  	mov	[si+ptEndCylinder], dl
  2163                                  
  2164 00000B0A A0[A841]                	mov	al, [heads]
  2165                                  	;mul	byte [sectors]
  2166 00000B0D F6E1                    	mul	cl
  2167                                  		; ax = heads*sectors	
  2168 00000B0F F7E2                    	mul	dx ; AX * cylinder count before end cylinder
  2169                                  		; DX:AX = LBA of cylinder DX, head 0, sector 1 		
  2170 00000B11 52                      	push	dx
  2171 00000B12 50                      	push	ax
  2172 00000B13 88E8                    	mov	al, ch ; [heads] - 1
  2173 00000B15 8B0E[A641]              	mov	cx, [sectors]  ; 63 or 17	 	
  2174 00000B19 F6E1                    	mul	cl
  2175                                  		; ax = (heads-1)*sectors
  2176 00000B1B 5A                      	pop	dx
  2177 00000B1C 01D0                    	add	ax, dx
  2178 00000B1E 5A                      	pop	dx
  2179 00000B1F 83D200                  	adc	dx, 0
  2180                                  		; dx:ax = ((end cylinder)*heads)+(heads-1)*sectors
  2181 00000B22 01C8                    	add	ax, cx
  2182 00000B24 83D200                  	adc	dx, 0
  2183                                  	; dx:ax = (((end cylinder)*heads)+(heads-1)*sectors) + sectors
  2184                                  	; dx:ax = LBA of the partition's end sector + 1
  2185 00000B27 2B4408                  	sub	ax, [si+ptStartSector]
  2186 00000B2A 1B540A                  	sbb	dx, [si+ptStartSector+2] 
  2187                                  
  2188 00000B2D 89440C                  	mov	[si+ptSectors], ax
  2189 00000B30 89540E                  	mov	[si+ptSectors+2], dx
  2190                                  
  2191                                  	;mov	[pp_type], al
  2192                                  
  2193 00000B33 C6440405                	mov	byte [si+ptFileSystemID], 5
  2194                                  
  2195 00000B37 C3                      	retn
  2196                                  
  2197                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2198                                  ; Set DOS (and non-dos) partition ID according to partition size
  2199                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2200                                  ; 18/02/2019
  2201                                  
  2202                                  set_partition_id: 
  2203                                  	; 18/02/2019
  2204                                  	;mov	cx, [ppn_Sectors]
  2205                                  	;mov	bx, [ppn_Sectors+2]
  2206                                  
  2207 00000B38 A0[B16F]                	mov	al, [pp_type]
  2208                                  
  2209                                  	;cmp	byte [pp_type], 1
  2210 00000B3B 3C01                    	cmp	al, 1 ; primary DOS (FAT12, FAT16, FAT32)
  2211 00000B3D 7519                    	jne	short spid_2
  2212                                  
  2213                                  	;mov	al, 1	; FAT12
  2214                                  
  2215 00000B3F 09DB                    	or	bx, bx
  2216 00000B41 750A                    	jnz	short spid_1
  2217                                  
  2218 00000B43 81F9A87F                	cmp	cx, 32680
  2219 00000B47 763A                    	jna	short spid_8	; FAT12 file system
  2220                                  
  2221 00000B49 B004                    	mov	al, 4	; FAT16 (< 32MB)
  2222                                  
  2223 00000B4B EB36                    	jmp	short spid_8	; FAT16 (CHS) file system
  2224                                  
  2225                                  spid_1:
  2226 00000B4D B00B                    	mov	al, 0Bh ; FAT32 (CHS)
  2227                                  
  2228 00000B4F 83FB10                  	cmp	bx, 10h
  2229 00000B52 732F                    	jnb	short spid_8	; FAT32 (CHS) file system	
  2230                                  
  2231 00000B54 B006                    	mov	al, 6	; FAT16 (>= 32MB)
  2232                                  
  2233 00000B56 EB2B                    	jmp	short spid_8	; FAT16 big (CHS) file system
  2234                                  
  2235                                  spid_2:
  2236                                  	;cmp	byte [pp_type], 2 ; Singlix FS
  2237 00000B58 3C02                    	cmp	al, 2
  2238 00000B5A 7504                    	jne	short spid_3
  2239 00000B5C B0A1                    	mov	al, 0A1h
  2240 00000B5E EB23                    	jmp	short spid_8
  2241                                  spid_3:
  2242                                  	;cmp	byte [pp_type], 3 ; Retro Unix FS
  2243 00000B60 3C03                    	cmp	al, 3
  2244 00000B62 7504                    	jne	short spid_4
  2245 00000B64 B071                    	mov	al, 71h
  2246 00000B66 EB1B                    	jmp	short spid_8
  2247                                  
  2248                                  spid_4:
  2249                                  	; another partition type (user input)
  2250                                  	
  2251                                  	; [pp_type] = 4
  2252                                  
  2253 00000B68 A0[B26F]                	mov	al, [pp_type_user]
  2254                                  
  2255                                  	; Check FAT12 fs size validation
  2256                                  
  2257 00000B6B 3C01                    	cmp	al, 1 ; FAT12
  2258 00000B6D 7715                    	ja	short spid_9
  2259                                  
  2260 00000B6F 21DB                    	and	bx, bx
  2261 00000B71 750A                    	jnz	short spid_6
  2262                                  
  2263 00000B73 81F9A87F                	cmp	cx, 32680
  2264 00000B77 760A                    	jna	short spid_8
  2265                                  spid_5:
  2266 00000B79 B004                    	mov	al, 4 ; FAT16 (<= 32MB) 
  2267 00000B7B EB06                    	jmp	short spid_8
  2268                                  spid_6:
  2269                                  	;;cmp	bx, 10h	; 512MB (16*32MB)
  2270                                  	;cmp	bx, 40h ; 2GB (64*32MB)
  2271                                  	;jnb	short spid_7
  2272                                  	
  2273 00000B7D B006                    	mov	al, 6
  2274 00000B7F EB02                    	jmp	short spid_8
  2275                                  spid_7:
  2276 00000B81 B00B                    	mov	al, 0Bh ; FAT32 (CHS) partition
  2277                                  spid_8:
  2278 00000B83 C3                      	retn
  2279                                  spid_9:
  2280 00000B84 3C04                    	cmp	al, 4 ; FAT16 (< 32 MB)
  2281 00000B86 7505                    	jne	short spid_10
  2282                                  
  2283 00000B88 09DB                    	or	bx, bx
  2284 00000B8A 75F1                    	jnz	short spid_6
  2285                                  	
  2286 00000B8C C3                      	retn	; FAT16 (< 32 MB) partition
  2287                                  spid_10:
  2288 00000B8D 3C06                    	cmp	al, 6 ; FAT 16 big partition
  2289 00000B8F 750E                    	jne	short spid_13 ; Extended partition or another type
  2290                                  	
  2291 00000B91 21DB                    	and	bx, bx
  2292 00000B93 7401                    	jz	short spid_11
  2293                                  
  2294                                  	;;cmp	bx, 10h	; 512MB (16*32MB)
  2295                                  	;cmp	bx, 40h ; 2GB (64*32MB)
  2296                                  	;jnb	short spid_7
  2297                                  	
  2298 00000B95 C3                      	retn
  2299                                  spid_11:
  2300                                  	;cmp	ax, 4150 ; 4085 + 32 + 32 + 1
  2301 00000B96 81F93610                	cmp	cx, 4150 ; 14/09/2020 (BugFix)
  2302 00000B9A 73DD                    	jnb	short spid_5
  2303                                  spid_12:
  2304 00000B9C B001                    	mov	al, 1 ;  FAT12 partition
  2305 00000B9E C3                      	retn
  2306                                  spid_13:
  2307                                  	; 14/09/2020
  2308 00000B9F 3C0B                    	cmp	al, 0Bh ; FAT 32 (CHS) partition
  2309 00000BA1 7419                    	je	short spid_15 ; FAT 32 CHS
  2310 00000BA3 3C0C                    	cmp	al, 0Ch	 
  2311 00000BA5 750C                    	jne	short spid_14 
  2312                                  	; FAT 32 LBA
  2313 00000BA7 21DB                    	and	bx, bx	; < 33 MB
  2314 00000BA9 74EB                    	jz	short spid_11 ; force to FAT 16 CHS or FAT 12
  2315 00000BAB 83FB10                  	cmp	bx, 10h ; 512 MB
  2316 00000BAE 73D3                    	jnb	short spid_8  ; OK, FAT 32 LBA has been confirmed
  2317 00000BB0 B00E                    	mov	al, 0Eh ; force to FAT 16 LBA
  2318 00000BB2 C3                      	retn
  2319                                  spid_14:
  2320                                  	; 14/09/2020
  2321 00000BB3 3C0E                    	cmp	al, 0Eh
  2322 00000BB5 75CC                    	jne	short spid_8 ; non-dos or extended partition
  2323                                  	; FAT 16 LBA
  2324 00000BB7 09DB                    	or	bx, bx
  2325 00000BB9 74DB                    	jz	short spid_11
  2326                                  	;cmp	bx, 20h ; 1 GB
  2327                                  	;jb	short spid_8
  2328                                  	;mov	al, 0Ch	; FAT 32 LBA
  2329 00000BBB C3                      	retn
  2330                                  spid_15:
  2331                                  	; Minimum size of FAT 32 FS = 65525 + 512 + 512 + 32
  2332                                   	; >= 66581 sectors (or >= 65525 data clusters)
  2333 00000BBC 83FB01                  	cmp	bx, 1
  2334 00000BBF 72D5                    	jb	short spid_11  ; invalid! (< 33 MB)
  2335 00000BC1 77C0                    	ja	short spid_8
  2336 00000BC3 81F91504                	cmp	cx, 1045
  2337 00000BC7 7201                    	jb	short spid_16  ; invalid! (< 33 MB)
  2338 00000BC9 C3                      	retn
  2339                                  spid_16:
  2340 00000BCA B006                    	mov	al, 6
  2341 00000BCC C3                      	retn
  2342                                  
  2343                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2344                                  ; Set disk size before creating hd image file
  2345                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2346                                  
  2347                                  new_image:
  2348                                  	; 07/03/2019
  2349 00000BCD B80300                  	mov	ax, 3 ; set video mode to 3 (clear video page)
  2350 00000BD0 CD10                    	int	10h
  2351                                  B_05:
  2352                                  	;mov	byte [existingfile], 0 ; 12/02/2019
  2353 00000BD2 E8F213                  	call	display_chs_table
  2354                                  B_06:
  2355 00000BD5 30E4                    	xor	ah, ah
  2356 00000BD7 CD16                    	int	16h
  2357 00000BD9 3C61                    	cmp	al, 'a'
  2358 00000BDB 7206                    	jb	short B_07
  2359 00000BDD 3C7A                    	cmp	al, 'z'
  2360 00000BDF 7702                    	ja	short B_07	
  2361 00000BE1 24DF                    	and	al, 0DFh
  2362                                  B_07:
  2363 00000BE3 3C43                    	cmp	al, 'C'
  2364 00000BE5 752C                    	jne	short B_12
  2365                                  B_08:
  2366 00000BE7 833E[AA41]00            	cmp	word [cylinders], 0
  2367 00000BEC 7706                    	ja	short B_09
  2368 00000BEE C706[AA41]0004          	mov	word [cylinders], 1024
  2369                                  B_09:
  2370 00000BF4 833E[A841]00            	cmp	word [heads], 0
  2371 00000BF9 7706                    	ja	short B_10
  2372 00000BFB C706[A841]1000          	mov	word [heads], 16
  2373                                  B_10:
  2374 00000C01 833E[A641]00            	cmp	word [sectors], 0
  2375 00000C06 7706                    	ja	short B_11
  2376 00000C08 C706[A641]3F00          	mov	word [sectors], 63
  2377                                  B_11:
  2378 00000C0E A2[B36F]                	mov	byte [chs_focus], al
  2379 00000C11 EBBF                    	jmp	short B_05
  2380                                  B_12:
  2381 00000C13 3C48                    	cmp	al, 'H'
  2382 00000C15 74D0                    	je	short B_08
  2383 00000C17 3C53                    	cmp	al, 'S'
  2384 00000C19 74CC                    	je	short B_08
  2385 00000C1B 3C1B                    	cmp	al, 27 ; ESC key
  2386 00000C1D 0F848D00                	je	B_18	
  2387 00000C21 3C0D                    	cmp	al, 13 ; ENTER key
  2388 00000C23 0F85EF00                	jne	B_21
  2389                                  
  2390 00000C27 833E[A641]3F            	cmp	word [sectors], 63
  2391 00000C2C 730D                    	jnb	short B_13
  2392 00000C2E 833E[A841]10            	cmp	word [heads], 16
  2393 00000C33 7606                    	jna	short B_13
  2394 00000C35 C706[A841]1000          	mov	word [heads], 16
  2395                                  B_13:
  2396 00000C3B A1[A641]                	mov	ax, [sectors]
  2397 00000C3E F726[A841]              	mul	word [heads]
  2398 00000C42 A3[D66F]                	mov	[min_sectors], ax  ; 08/02/2019
  2399 00000C45 8B16[AA41]              	mov	dx, [cylinders]
  2400 00000C49 F7E2                    	mul	dx
  2401 00000C4B A3[9C6F]                	mov	[total_sectors], ax
  2402 00000C4E 8916[9E6F]              	mov	[total_sectors+2], dx
  2403                                  
  2404                                  	; 05/02/2019
  2405 00000C52 BF[8C57]                	mov	di, str_disk_sectors
  2406                                  
  2407 00000C55 89E5                    	mov	bp, sp
  2408 00000C57 B90A00                  	mov	cx, 10
  2409                                  B_14:
  2410 00000C5A E81502                  	call	div32
  2411                                  	
  2412 00000C5D 80C330                  	add	bl, '0'
  2413 00000C60 53                      	push	bx
  2414 00000C61 21C0                    	and	ax, ax
  2415 00000C63 75F5                    	jnz	short B_14
  2416 00000C65 21D2                    	and	dx, dx
  2417 00000C67 75F1                    	jnz	short B_14
  2418                                  
  2419 00000C69 29E5                    	sub	bp, sp
  2420 00000C6B D1ED                    	shr	bp, 1
  2421                                  B_15:
  2422 00000C6D 58                      	pop	ax
  2423 00000C6E AA                      	stosb
  2424 00000C6F 4D                      	dec	bp
  2425 00000C70 75FB                    	jnz	short B_15
  2426                                  
  2427 00000C72 30C0                    	xor	al, al
  2428 00000C74 AA                      	stosb
  2429                                  
  2430 00000C75 A1[9C6F]                	mov	ax, [total_sectors]
  2431 00000C78 8B16[9E6F]              	mov	dx, [total_sectors+2]
  2432 00000C7C B90002                  	mov	cx, 512
  2433 00000C7F E8FE01                  	call	mul32
  2434 00000C82 A3[A46F]                	mov	[file_size], ax
  2435 00000C85 8916[A66F]              	mov	[file_size+2], dx
  2436                                  	
  2437 00000C89 BF[CF57]                	mov	di, str_file_size
  2438                                  
  2439 00000C8C 89E5                    	mov	bp, sp
  2440 00000C8E B90A00                  	mov	cx, 10
  2441                                  B_16:
  2442 00000C91 E8DE01                  	call	div32
  2443                                  
  2444 00000C94 80C330                  	add	bl, '0'
  2445 00000C97 53                      	push	bx
  2446 00000C98 21C0                    	and	ax, ax
  2447 00000C9A 75F5                    	jnz	short B_16
  2448 00000C9C 21D2                    	and	dx, dx
  2449 00000C9E 75F1                    	jnz	short B_16
  2450                                  
  2451 00000CA0 29E5                    	sub	bp, sp
  2452 00000CA2 D1ED                    	shr	bp, 1
  2453                                  B_17:
  2454 00000CA4 58                      	pop	ax
  2455 00000CA5 AA                      	stosb
  2456 00000CA6 4D                      	dec	bp
  2457 00000CA7 75FB                    	jnz	short B_17
  2458                                  
  2459 00000CA9 30C0                    	xor	al, al
  2460 00000CAB AA                      	stosb
  2461                                  
  2462 00000CAC B00D                    	mov	al, 13 ; ENTER (Carriage Return) key	
  2463                                  B_18:
  2464 00000CAE 50                      	push	ax
  2465                                  
  2466 00000CAF C606[B36F]00            	mov	byte [chs_focus], 0
  2467 00000CB4 E81013                  	call	display_chs_table
  2468                                  
  2469 00000CB7 58                      	pop	ax
  2470                                  
  2471 00000CB8 3C0D                    	cmp	al, 13 ; CR ?
  2472 00000CBA 7402                    	je	short B_20 ; print total sectors and file size..
  2473                                  B_19:
  2474 00000CBC CD20                    	int	20h
  2475                                  B_20:
  2476 00000CBE BE[7657]                	mov	si, msg_disk_sectors
  2477 00000CC1 E8BB11                  	call	print_msg
  2478 00000CC4 BE[8C57]                	mov	si, str_disk_sectors
  2479 00000CC7 E8B511                  	call	print_msg
  2480 00000CCA BE[6057]                	mov	si, CRLF
  2481 00000CCD E8AF11                  	call	print_msg
  2482 00000CD0 BE[B957]                	mov	si, msg_file_size
  2483 00000CD3 E8A911                  	call	print_msg
  2484 00000CD6 BE[CF57]                	mov	si, str_file_size
  2485 00000CD9 E8A311                  	call	print_msg
  2486 00000CDC BE[DA57]                	mov	si, msg_bytes
  2487 00000CDF E89D11                  	call	print_msg
  2488 00000CE2 BE[E357]                	mov	si, msg_enter_cancel
  2489 00000CE5 E89711                  	call	print_msg
  2490 00000CE8 30E4                    	xor	ah, ah
  2491 00000CEA CD16                    	int	16h
  2492 00000CEC 3C1B                    	cmp	al, 1Bh ; ESC key
  2493 00000CEE 74CC                    	je	short B_19
  2494 00000CF0 3C0D                    	cmp	al, 0Dh ; Enter key
  2495 00000CF2 0F85DCFE                	jne	B_05
  2496                                  
  2497 00000CF6 833E[9E6F]00            	cmp	word [total_sectors+2], 0
  2498 00000CFB 0F879501                	ja	B_42
  2499                                  
  2500 00000CFF 813E[9C6F]003F          	cmp	word [total_sectors], 16128  ; 63*16*16
  2501 00000D05 0F838B01                	jnb	B_42
  2502                                  
  2503 00000D09 BE[BF46]                	mov	si, msg_min_8mb_disk 
  2504 00000D0C E87011                  	call	print_msg
  2505                                  
  2506 00000D0F 30E4                    	xor	ah, ah
  2507 00000D11 CD16                    	int	16h
  2508                                  
  2509 00000D13 E9BCFE                  	jmp	B_05
  2510                                  	
  2511                                  B_21:
  2512 00000D16 3C20                    	cmp	al, 20h
  2513 00000D18 745A                    	je	short B_25
  2514 00000D1A 3C2D                    	cmp	al, '-'
  2515 00000D1C 0F84E200                	je	B_34
  2516 00000D20 3C2B                    	cmp	al, '+'
  2517 00000D22 7450                    	je	short B_25
  2518 00000D24 80FC51                  	cmp	ah, 51h ; Pg Down
  2519 00000D27 7416                    	je	short B_23
  2520 00000D29 80FC49                  	cmp	ah, 49h ; Pg Up
  2521 00000D2C 742F                    	je	short B_24  
  2522                                  B_22:
  2523 00000D2E 803E[B36F]00            	cmp	byte [chs_focus], 0
  2524 00000D33 0F869EFE                	jna	B_06
  2525 00000D37 C606[B36F]00            	mov	byte [chs_focus], 0
  2526 00000D3C E993FE                  	jmp	B_05
  2527                                  B_23:
  2528 00000D3F 803E[B36F]43            	cmp	byte [chs_focus], 'C'
  2529                                  	;jne	short B_22
  2530 00000D44 0F85BA00                	jne	B_34 ; 10/02/2019
  2531 00000D48 832E[AA41]10            	sub	word [cylinders], 16
  2532 00000D4D 0F82C500                	jc	B_35
  2533 00000D51 833E[AA41]10            	cmp	word [cylinders], 16
  2534 00000D56 0F82BC00                	jb	B_35
  2535 00000D5A E975FE                  	jmp	B_05
  2536                                  B_24:
  2537 00000D5D 803E[B36F]43            	cmp	byte [chs_focus], 'C'
  2538                                  	;jne	short B_22
  2539 00000D62 752E                    	jne	short B_27 ; 10/02/2019
  2540 00000D64 8306[AA41]10            	add	word [cylinders], 16
  2541 00000D69 813E[AA41]0004          	cmp	word [cylinders], 1024
  2542 00000D6F 7718                    	ja	short B_26
  2543 00000D71 E95EFE                  	jmp	B_05
  2544                                  B_25:
  2545 00000D74 803E[B36F]43            	cmp	byte [chs_focus], 'C'
  2546 00000D79 7517                    	jne	short B_27
  2547 00000D7B FF06[AA41]              	inc	word [cylinders]
  2548 00000D7F 813E[AA41]0004          	cmp	word [cylinders], 1024
  2549 00000D85 0F8649FE                	jna	B_05
  2550                                  B_26:
  2551 00000D89 C706[AA41]1000          	mov	word [cylinders], 16 ; minimum cylinders
  2552 00000D8F E940FE                  	jmp	B_05	
  2553                                  B_27:
  2554 00000D92 803E[B36F]48            	cmp	byte [chs_focus], 'H'
  2555 00000D97 7547                    	jne	short B_32
  2556 00000D99 833E[A841]10            	cmp	word [heads], 16
  2557 00000D9E 7307                    	jnb	short B_28
  2558 00000DA0 FF06[A841]              	inc	word [heads]
  2559 00000DA4 E92BFE                  	jmp	B_05
  2560                                  B_28:
  2561 00000DA7 833E[A641]3F            	cmp	word [sectors], 63
  2562 00000DAC 7212                    	jb	short B_29
  2563 00000DAE 833E[A841]20            	cmp	word [heads], 32
  2564 00000DB3 7722                    	ja	short B_31
  2565 00000DB5 7217                    	jb	short B_30
  2566 00000DB7 C706[A841]4000          	mov	word [heads], 64
  2567 00000DBD E912FE                  	jmp	B_05
  2568                                  B_29:
  2569 00000DC0 833E[A841]10            	cmp	word [heads], 16
  2570 00000DC5 7310                    	jnb	short B_31
  2571 00000DC7 FF06[A841]              	inc	word [heads]
  2572 00000DCB E904FE                  	jmp	B_05
  2573                                  B_30:
  2574 00000DCE C706[A841]2000          	mov	word [heads], 32
  2575 00000DD4 E9FBFD                  	jmp	B_05
  2576                                  B_31:
  2577 00000DD7 C706[A841]0200          	mov	word [heads], 2
  2578 00000DDD E9F2FD                  	jmp	B_05
  2579                                  B_32:
  2580 00000DE0 803E[B36F]53            	cmp	byte [chs_focus], 'S'
  2581 00000DE5 0F85E9FD                	jne	B_05
  2582 00000DE9 833E[A641]3F            	cmp	word [sectors], 63
  2583 00000DEE 7509                    	jne	short B_33
  2584 00000DF0 C706[A641]1100          	mov	word [sectors], 17
  2585 00000DF6 E9D9FD                  	jmp	B_05
  2586                                  B_33:
  2587 00000DF9 C706[A641]3F00          	mov	word [sectors], 63
  2588 00000DFF E9D0FD                  	jmp	B_05
  2589                                  B_34:
  2590 00000E02 803E[B36F]43            	cmp	byte [chs_focus], 'C'
  2591 00000E07 7516                    	jne	short B_36
  2592 00000E09 FF0E[AA41]              	dec	word [cylinders]
  2593 00000E0D 833E[AA41]10            	cmp	word [cylinders], 16
  2594 00000E12 0F83BCFD                	jnb	B_05
  2595                                  B_35:
  2596 00000E16 C706[AA41]0004          	mov	word [cylinders], 1024
  2597 00000E1C E9B3FD                  	jmp	B_05	
  2598                                  B_36:
  2599 00000E1F 803E[B36F]48            	cmp	byte [chs_focus], 'H'
  2600 00000E24 75BA                    	jne	short B_32
  2601                                  
  2602 00000E26 833E[A641]3F            	cmp	word [sectors], 63
  2603 00000E2B 721E                    	jb	short B_38
  2604                                  
  2605 00000E2D 833E[A841]02            	cmp	word [heads], 2
  2606 00000E32 760E                    	jna	short B_37
  2607 00000E34 833E[A841]10            	cmp	word [heads], 16
  2608 00000E39 771E                    	ja	short B_39
  2609 00000E3B FF0E[A841]              	dec	word [heads]
  2610 00000E3F E990FD                  	jmp	B_05
  2611                                  B_37:
  2612 00000E42 C706[A841]4000          	mov	word [heads], 64
  2613 00000E48 E987FD                  	jmp	B_05
  2614                                  B_38:
  2615 00000E4B 833E[A841]02            	cmp	word [heads], 2
  2616 00000E50 760E                    	jna	short B_40
  2617 00000E52 FF0E[A841]              	dec	word [heads]
  2618 00000E56 E979FD                  	jmp	B_05
  2619                                  B_39:
  2620 00000E59 833E[A841]20            	cmp	word [heads], 32
  2621 00000E5E 7709                    	ja	short B_41
  2622                                  B_40:
  2623 00000E60 C706[A841]1000          	mov	word [heads], 16
  2624 00000E66 E969FD                  	jmp	B_05
  2625                                  B_41:
  2626 00000E69 C706[A841]2000          	mov	word [heads], 32
  2627 00000E6F E960FD                  	jmp	B_05
  2628                                  
  2629                                  ;-----------------------------------------------------------------------------
  2630                                  
  2631                                  div32:
  2632                                  	; DX_AX/CX
  2633                                  	; Result: DX_AX, BX (remainder) 
  2634 00000E72 89C3                    	mov	bx, ax
  2635                                  	;or	dx, ax ; * DX_AX = 0 ?       
  2636                                  	;jz	short div32_retn ; yes, do not divide! 
  2637 00000E74 89D0                    	mov	ax, dx
  2638 00000E76 31D2                            xor	dx, dx
  2639 00000E78 F7F1                            div	cx	; at first, divide DX
  2640                                  			; remainder is in DX 
  2641 00000E7A 93                      	xchg	ax, bx	; now quotient is in BX
  2642                                    			; and initial AX value is in AX
  2643 00000E7B F7F1                    	div	cx	; now, DX_AX has been divided and
  2644                                  			; AX has quotient
  2645                                  			; DX has remainder
  2646 00000E7D 87D3                    	xchg	dx, bx	; finally, BX has remainder
  2647                                  ;div32_retn:
  2648 00000E7F C3                              retn
  2649                                  
  2650                                  ;-----------------------------------------------------------------------------
  2651                                  
  2652                                  mul32:
  2653                                  	; DX_AX*CX
  2654                                  	; Result: BX_DX_AX 
  2655 00000E80 51                      	push	cx
  2656 00000E81 89D3                    	mov	bx, dx
  2657 00000E83 F7E1                    	mul	cx
  2658 00000E85 93                       	xchg	ax, bx
  2659 00000E86 52                      	push	dx
  2660 00000E87 F7E1                    	mul	cx 
  2661 00000E89 59                      	pop	cx 
  2662 00000E8A 01C8                    	add	ax, cx 
  2663 00000E8C 83D200                  	adc	dx, 0
  2664 00000E8F 93                      	xchg	bx, ax
  2665 00000E90 87D3                    	xchg	dx, bx
  2666 00000E92 59                      	pop	cx
  2667 00000E93 C3                      	retn
  2668                                  
  2669                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2670                                  ; Create a new hard disk image file
  2671                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2672                                  		
  2673                                  B_42:
  2674 00000E94 BA[915A]                	mov	dx, img_file_name
  2675 00000E97 B90000                  	mov	cx, 0 ; File Attributes
  2676 00000E9A B43C                    	mov	ah, 3Ch ; MS-DOS Function = Create File
  2677 00000E9C CD21                    	int	21h
  2678 00000E9E 0F82E6F1                	jc	A_10
  2679                                  
  2680 00000EA2 BE[6057]                	mov	si, CRLF
  2681 00000EA5 E8D70F                  	call	print_msg
  2682                                  
  2683                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2684                                  ; Open image file for writing
  2685                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2686                                  
  2687 00000EA8 B002                    	mov	al, 2 ; open for reading and writing
  2688                                  	;mov	dx, img_file_name
  2689 00000EAA B43D                    	mov	ah, 3Dh ; open file
  2690 00000EAC CD21                    	int	21h
  2691 00000EAE 0F82B70F                	jc	D_02
  2692                                  
  2693 00000EB2 A3[A441]                	mov	[img_file_handle], ax
  2694                                  
  2695 00000EB5 BE[1456]                	mov	si, msg_writing_mbr
  2696 00000EB8 E8C40F                  	call	print_msg
  2697                                  
  2698                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2699                                  ; Writing/Saving CHS parameters into (Singlix FS1) MBR
  2700                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2701                                  ; Note: Partition Table will be left empty at this stage
  2702                                  
  2703                                  	;cmp	word [TRDOS386_MASTERBOOT_SECTOR+417], 417
  2704                                  	;jne	short B_43
  2705                                  
  2706 00000EBB 8B0E[AA41]              	mov	cx, [cylinders]
  2707 00000EBF 890E[3735]              	mov	[TRDOS386_MASTERBOOT_SECTOR+420], cx ; pt_cylinders
  2708 00000EC3 8B0E[A841]              	mov	cx, [heads]
  2709 00000EC7 890E[3935]              	mov	[TRDOS386_MASTERBOOT_SECTOR+422], cx ; pt_heads
  2710 00000ECB 8B0E[A641]              	mov	cx, [sectors]
  2711 00000ECF 890E[3B35]              	mov	[TRDOS386_MASTERBOOT_SECTOR+424], cx ; pt_sectors	 	 
  2712                                  
  2713                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2714                                  ; writing masterboot sector
  2715                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2716                                  
  2717                                  B_43:
  2718 00000ED3 8B1E[A441]              	mov	bx, [img_file_handle]
  2719 00000ED7 BA[9333]                	mov	dx, TRDOS386_MASTERBOOT_SECTOR ; Singlix FS1 MBR
  2720 00000EDA B90002                  	mov	cx, 512
  2721 00000EDD B440                    	mov	ah, 40h ; write to file	
  2722 00000EDF CD21                    	int	21h
  2723 00000EE1 0F827A0F                	jc	D_01
  2724                                  
  2725 00000EE5 BE[5C57]                	mov	si, Msg_OK
  2726 00000EE8 E8940F                  	call	print_msg
  2727                                  
  2728 00000EEB BE[3156]                	mov	si, msg_writing_disk_sectors
  2729 00000EEE E88E0F                  	call	print_msg
  2730 00000EF1 B403                    	mov	ah, 3
  2731 00000EF3 BB0700                  	mov	bx, 7
  2732 00000EF6 CD10                    	int	10h ; Return Cursor Position
  2733                                  	; DL = Column, DH = Line
  2734 00000EF8 8916[A456]              	mov	[Cursor_Pos], dx
  2735                                  
  2736                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2737                                  ; writing disk sectors (with F6h -format- bytes)
  2738                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2739                                  
  2740 00000EFC 31D2                    	xor	dx, dx
  2741 00000EFE B80100                  	mov	ax, 1
  2742                                  
  2743                                  	; 63 (17) sectors (after MBR) will be filled with ZERO 
  2744                                  B_44:
  2745 00000F01 52                      	push	dx
  2746 00000F02 50                      	push	ax
  2747 00000F03 BE[A256]                	mov	si, Sector_Str + 6
  2748 00000F06 E8FE0F                  	call	bin_to_decimal
  2749 00000F09 8B16[A456]              	mov	dx, [Cursor_Pos]
  2750 00000F0D BB0700                  	mov	bx, 7
  2751 00000F10 B402                    	mov	ah, 2
  2752 00000F12 CD10                    	int	10h  ; Set Cursor Position
  2753 00000F14 E8680F                  	call	print_msg
  2754 00000F17 58                      	pop	ax
  2755 00000F18 5A                      	pop	dx
  2756 00000F19 BB[206B]                	mov	bx, HDFORMAT_FATBUFFER ; Empty Sector
  2757 00000F1C E86F0F                  	call	write_hd_sector
  2758 00000F1F 0F823C0F                	jc	D_01
  2759                                  	;inc	ax
  2760 00000F23 FEC0                    	inc	al
  2761 00000F25 3B06[A641]              	cmp	ax, [sectors] ; 63 or 17
  2762 00000F29 76D6                    	jna	short B_44
  2763                                  
  2764                                  	; writing other sectors upto [total sectors] - 1 
  2765                                  B_45:
  2766 00000F2B 52                      	push	dx
  2767 00000F2C 50                      	push	ax
  2768 00000F2D BE[A256]                	mov	si, Sector_Str + 6
  2769 00000F30 E8D40F                  	call	bin_to_decimal
  2770 00000F33 8B16[A456]              	mov	dx, [Cursor_Pos]
  2771 00000F37 BB0700                  	mov	bx, 7
  2772 00000F3A B402                    	mov	ah, 2
  2773 00000F3C CD10                    	int	10h  ; Set Cursor Position
  2774 00000F3E E83E0F                  	call	print_msg
  2775 00000F41 58                      	pop	ax
  2776 00000F42 5A                      	pop	dx
  2777 00000F43 BB[1A67]                	mov	bx, HDFORMAT_SECBUFFER ; F6h filled sectors
  2778 00000F46 E8450F                  	call	write_hd_sector
  2779 00000F49 0F82120F                	jc	D_01
  2780 00000F4D 83C001                  	add	ax, 1
  2781 00000F50 83D200                  	adc	dx, 0
  2782 00000F53 3B16[9E6F]              	cmp	dx, [total_sectors+2]
  2783 00000F57 72D2                    	jb	short B_45
  2784 00000F59 7706                    	ja	short B_46
  2785 00000F5B 3B06[9C6F]              	cmp	ax, [total_sectors]
  2786 00000F5F 72CA                    	jb	short B_45
  2787                                  B_46:
  2788 00000F61 BE[5957]                	mov	si, Msg_3dot_OK
  2789 00000F64 E8180F                  	call	print_msg
  2790                                  
  2791 00000F67 BE[2247]                	mov	si, msg_any_key_esc_exit
  2792 00000F6A E8120F                  	call	print_msg
  2793                                  	
  2794 00000F6D 30E4                    	xor	ah, ah
  2795 00000F6F CD16                    	int	16h	
  2796                                  
  2797 00000F71 3C1B                    	cmp	al, 27 ; 1Bh, ESC key
  2798 00000F73 7508                    	jne	short B_48
  2799                                  B_47:
  2800 00000F75 BE[6057]                	mov	si, CRLF
  2801 00000F78 E8040F                  	call	print_msg
  2802                                  	
  2803 00000F7B CD20                    	int	20h
  2804                                  B_48:
  2805 00000F7D FE06[AC41]              	inc	byte [random] ; next r/w is not sequental 
  2806 00000F81 FE06[AD41]              	inc	byte [newdisk] ; will be used by partitioning
  2807                                  
  2808                                  	; 11/02/2019
  2809                                  	; Copy Singlix FS (TRDOS 386) MBR to MasterBoot buffer
  2810 00000F85 B90001                  	mov	cx, 256
  2811 00000F88 BE[9333]                	mov	si, TRDOS386_MASTERBOOT_SECTOR ; Singlix FS1 MBR
  2812 00000F8B BF[3858]                	mov	di, MasterBootBuff
  2813 00000F8E F3A5                    	rep	movsw
  2814                                  
  2815                                  	; 26/02/2019
  2816                                  	; Clear partition table structure
  2817                                  	; (for preventing wrong partition data display for new disk image)
  2818 00000F90 BF[5872]                	mov	di, part_table_boot_ind
  2819 00000F93 31C0                    	xor	ax, ax
  2820 00000F95 B92400                  	mov	cx, 4*18/2
  2821 00000F98 F3AB                    	rep	stosw
  2822                                  
  2823                                  	; 08/03/2019
  2824                                  	; Clear pcount, epnumber values
  2825 00000F9A A3[A072]                	mov	[pcount], ax ; reset (pcount & ppcount)
  2826 00000F9D A3[A272]                	mov	[apcount], ax ; reset (apcount & epnumber)
  2827                                  B_49:
  2828                                  	; 06/03/2019
  2829 00000FA0 C606[BE6F]4D            	mov	byte [pSize_unit], 'M' ; default (for 'whole' disk/space)
  2830                                  	; 15/02/2019
  2831 00000FA5 E819F8                  	call	create_partition_input
  2832                                  B_50:		
  2833 00000FA8 21C0                    	and	ax, ax
  2834                                  	;jz	short B_47 ; 0 = none or not a valid input
  2835 00000FAA 0F8487F4                	jz	A_48 ; 25/02/2019
  2836                                  
  2837                                  	;or	ah, ah
  2838                                  	;jz	short B_51
  2839                                  
  2840                                  	; 23/02/2019
  2841 00000FAE 80FC04                  	cmp	ah, 4  ; user's partition type input ?
  2842 00000FB1 7505                    	jne	short B_51 ; no
  2843                                  
  2844                                  	; 29/10/2020
  2845                                  	; (ah = 0)
  2846                                  	;or	al, al
  2847                                  	;jz	A_42  ; invalid partition type input
  2848                                  	;	      ; or ESC key has been pressed
  2849                                  
  2850                                  	; user type input
  2851 00000FB3 A2[B26F]                	mov	[pp_type_user], al
  2852 00000FB6 88E0                    	mov	al, ah ; mov al, 4
  2853                                  B_51:
  2854 00000FB8 A2[B16F]                	mov	[pp_type], al
  2855                                  
  2856                                  	; clear screen
  2857 00000FBB B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
  2858 00000FBE CD10                    	int	10h
  2859                                  
  2860 00000FC0 A0[B16F]                	mov	al, [pp_type]
  2861 00000FC3 3C01                    	cmp	al, 1
  2862 00000FC5 7705                    	ja	short B_52
  2863                                  
  2864 00000FC7 BE[054A]                	mov	si,  msg_create_dos_partition_h ; header
  2865 00000FCA EB69                    	jmp	short B_57
  2866                                  B_52:
  2867 00000FCC 3C05                    	cmp	al, 5
  2868 00000FCE 7262                    	jb	short B_56
  2869                                  	;ja	short B_55
  2870 00000FD0 7741                    	ja	short B_106 ; 26/10/2020
  2871                                  
  2872                                  	; 23/02/2019
  2873 00000FD2 BE[FA4A]                	mov	si, msg_create_ext_partition_h
  2874 00000FD5 E8A70E                  	call	print_msg
  2875                                  
  2876                                  	; 24/02/2019
  2877 00000FD8 803E[A372]00            	cmp	byte [epnumber], 0
  2878 00000FDD 7613                    	jna	short B_53	
  2879                                  
  2880 00000FDF BE[DB61]                	mov	si, msg_ext_partition_exists
  2881 00000FE2 E89A0E                  	call 	print_msg
  2882                                  
  2883 00000FE5 BE[1958]                	mov	si, msg_press_any_key
  2884 00000FE8 E8940E                  	call	print_msg
  2885                                  
  2886 00000FEB 30E4                    	xor	ah, ah
  2887 00000FED CD16                    	int	16h
  2888                                  
  2889                                  	;jmp	A_33
  2890 00000FEF E943F4                  	jmp	A_48
  2891                                  B_53:
  2892 00000FF2 803E[A172]00            	cmp	byte [ppcount], 0  ; primary partition count
  2893 00000FF7 773F                    	ja	short B_58
  2894                                  
  2895                                  	; 09/02/2019
  2896 00000FF9 BE[8151]                	mov	si, msg_ext_partition_error
  2897 00000FFC E8800E                  	call	print_msg
  2898                                  B_54:	
  2899 00000FFF BE[1958]                	mov	si, msg_press_any_key
  2900 00001002 E87A0E                  	call	print_msg
  2901                                  
  2902 00001005 30E4                    	xor	ah, ah
  2903 00001007 CD16                    	int	16h
  2904                                  
  2905 00001009 C606[B16F]01            	mov	byte [pp_type], 1
  2906                                  
  2907 0000100E E8DBF7                  	call	cpi_2 ; 15/02/2019
  2908 00001011 EB95                    	jmp	short B_50
  2909                                  B_106:
  2910                                  	; 26/10/2020
  2911 00001013 803E[A172]00            	cmp	byte [ppcount], 0  ; primary partition count
  2912 00001018 760A                    	jna	short B_55
  2913 0000101A 803E[A372]00            	cmp	byte [epnumber], 0  
  2914                                  			; is there an extended partition ? 	
  2915 0000101F 7603                    	jna	short B_55
  2916 00001021 E994F4                  	jmp	create_logical_drives
  2917                                  B_55:
  2918 00001024 BE[EF4B]                	mov	si, msg_create_logical_drive_h
  2919 00001027 E8550E                  	call	print_msg
  2920                                  
  2921 0000102A BE[C051]                	mov	si, msg_logical_drive_error
  2922 0000102D E84F0E                  	call	print_msg
  2923 00001030 EBCD                    	jmp	short B_54
  2924                                  
  2925                                  ;	mov	si, msg_use_entire_ep_space
  2926                                  ;	jmp	short B_60
  2927                                  	
  2928                                  B_56:
  2929 00001032 BE[E44C]                	mov	si, msg_create_nondos_partition_h
  2930                                  B_57:
  2931 00001035 E8470E                  	call	print_msg
  2932                                  B_58:
  2933                                  	; 15/02/2019
  2934 00001038 803E[AD41]00            	cmp	byte [newdisk], 0
  2935 0000103D 7705                    	ja	short B_59
  2936                                  
  2937 0000103F BE[1950]                	mov	si, msg_use_all_space
  2938 00001042 EB03                    	jmp	short B_60
  2939                                  B_59:
  2940 00001044 BE[F24F]                	mov	si, msg_use_whole_disk ; partition size: whole disk
  2941                                  B_60:
  2942 00001047 E8350E                  	call	print_msg
  2943                                  B_61:
  2944 0000104A 30E4                    	xor	ah, ah
  2945 0000104C CD16                    	int	16h
  2946                                  
  2947 0000104E 3C1B                    	cmp	al, 27 ; ESCAPE key
  2948                                  	;;je	B_47
  2949                                  	;je	A_33
  2950 00001050 0F84E1F3                	je	A_48 ; 25/02/2019
  2951 00001054 24DF                    	and	al, 0DFh
  2952 00001056 3C4E                    	cmp	al, 'N'
  2953 00001058 740D                    	je	short B_62  ;02/03/2019
  2954 0000105A 3C59                    	cmp	al, 'Y'
  2955 0000105C 75EC                    	jne	short B_61
  2956                                  	
  2957 0000105E FE06[B06F]              	inc	byte [wholedisk]
  2958                                  	
  2959                                  	; 02/03/2019
  2960 00001062 BE[025F]                	mov	si, _msg_YES
  2961                                  	;call	print_msg
  2962 00001065 EB03                    	jmp	short B_63	
  2963                                  B_62:
  2964 00001067 BE[085F]                	mov	si, _msg_NO
  2965                                  B_63:	; 06/03/2019
  2966 0000106A E8120E                  	call	print_msg
  2967                                  
  2968                                  	; 15/02/2019
  2969 0000106D 29DB                    	sub	bx, bx
  2970 0000106F 381E[AD41]              	cmp	byte [newdisk], bl ; 0
  2971 00001073 7708                    	ja	short B_64 ; 23/02/2019
  2972 00001075 381E[B06F]              	cmp	byte [wholedisk], bl ; 0
  2973 00001079 0F871C01                	ja	B_75 ; 23/02/2019
  2974                                  B_64:
  2975                                  	; 08/02/2019
  2976                                  	;sub	bx, bx
  2977 0000107D A1[9C6F]                	mov	ax, [total_sectors]
  2978 00001080 8B16[9E6F]              	mov	dx, [total_sectors+2]
  2979 00001084 2B06[A641]              	sub	ax, [sectors]
  2980 00001088 19DA                    	sbb	dx, bx ; sbb dx, 0
  2981                                  
  2982 0000108A A3[AC6F]                	mov	[pp_Sectors], ax   ; = [total_sectors] - [sectors]
  2983 0000108D 8916[AE6F]              	mov	[pp_Sectors+2], dx ; = [total_sectors+2] - carry bit
  2984                                  B_65:
  2985 00001091 381E[B06F]              	cmp	byte [wholedisk], bl ; 0
  2986 00001095 0F870701                	ja	B_76 ; 09/02/2019
  2987                                  B_66:
  2988                                  	; clear screen
  2989 00001099 B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
  2990 0000109C CD10                    	int	10h
  2991                                  
  2992                                  	; 04/11/2020
  2993 0000109E 803E[B16F]01            	cmp	byte [pp_type], 1 ; primary dos partition ?
  2994 000010A3 7405                    	je	short B_108
  2995                                  	; "Create Partition"
  2996 000010A5 BE[5A47]                	mov	si, msg_create_partition_h
  2997 000010A8 EB03                    	jmp	short B_109
  2998                                  B_108:
  2999                                  	; "Create DOS Partition"
  3000 000010AA BE[054A]                	mov	si, msg_create_dos_partition_h ; header
  3001                                  B_109:
  3002 000010AD E8CF0D                  	call	print_msg
  3003 000010B0 BE[964E]                	mov	si, msg_create_trdos_partition_s ; size options
  3004 000010B3 E8C90D                  	call	print_msg	
  3005                                  B_67:	
  3006 000010B6 30E4                    	xor	ah, ah
  3007 000010B8 CD16                    	int	16h
  3008                                  
  3009                                  	; 24/02/2019
  3010 000010BA 3C1B                    	cmp	al, 27	; ESCAPE key 
  3011 000010BC 0F8475F3                	je	A_48	; Cancel
  3012                                  
  3013 000010C0 3C20                    	cmp	al, 32	; SPACE key
  3014 000010C2 7521                    	jne	short B_69
  3015                                  
  3016                                  		; Entire space
  3017 000010C4 A1[AC6F]                	mov	ax, [pp_Sectors]
  3018 000010C7 8B16[AE6F]              	mov	dx, [pp_Sectors+2]
  3019                                  
  3020 000010CB C606[B06F]01            	mov 	byte [wholedisk], 1 ; 09/02/2019
  3021 000010D0 EB5A                    	jmp	short B_71
  3022                                  
  3023                                  B_107:	; 31/10/2020
  3024 000010D2 75C5                    	jnz	short B_66  ; ESCape (return to options menu)
  3025                                  	; partition size input is ZERO !
  3026                                  B_68:
  3027                                  	; ZERO partition size message
  3028 000010D4 BE[155D]                	mov	si, msg_zero_partition_size
  3029 000010D7 E8A50D                  	call	print_msg
  3030                                  	
  3031 000010DA 30E4                    	xor	ah, ah
  3032 000010DC CD16                    	int	16h
  3033 000010DE 3C1B                    	cmp	al, 27 ; ESCAPE key
  3034 000010E0 75B7                    	jne	short B_66 ; Retry
  3035                                  
  3036 000010E2 E990FE                  	jmp	B_47 ; exit
  3037                                  
  3038                                  B_69:
  3039 000010E5 C606[BE6F]25            	mov	byte [pSize_unit], '%'
  3040 000010EA 3C25                    	cmp	al, '%'
  3041 000010EC 7422                    	je	short B_70
  3042 000010EE C606[BE6F]53            	mov	byte [pSize_unit], 'S'
  3043 000010F3 3C0D                    	cmp	al, 13 ; 0Dh, Carriage Return key
  3044 000010F5 7419                    	je	short B_70
  3045 000010F7 24DF                    	and	al, 0DFh
  3046 000010F9 3C53                    	cmp	al, 'S'
  3047 000010FB 7413                    	je	short B_70
  3048 000010FD A2[BE6F]                	mov	[pSize_unit], al
  3049 00001100 3C4B                    	cmp	al, 'K'
  3050 00001102 740C                    	je	short B_70
  3051 00001104 3C4D                    	cmp	al, 'M'
  3052 00001106 7408                    	je	short B_70
  3053 00001108 3C47                    	cmp	al, 'G'
  3054 0000110A 7404                    	je	short B_70
  3055 0000110C 3C43                    	cmp	al, 'C'
  3056 0000110E 75A6                    	jne	short B_67
  3057                                  B_70:
  3058 00001110 C606[FF66]73            	mov	byte [msg_sectors_crlf_s], 's' ; " sectors"
  3059                                  
  3060 00001115 E8AE0F                  	call	partition_size_input
  3061                                  	;jc	B_47 ; exit if partition size input is 0
  3062                                  	;jc	short B_68
  3063                                  	; 29/10/2020
  3064                                  	;jnc	short B_107
  3065                                  	;jz	short B_68 ; partition size input is ZERO !
  3066                                  	;jmp	short B_66 ; ESCape (return to options menu)	
  3067                                  	; 31/10/2020
  3068 00001118 72B8                    	jc	short B_107 ; ESC or zero partition size
  3069                                  ;B_107:
  3070 0000111A 21DB                    	and	bx, bx ; bx_dx_ax = partition size
  3071                                  	;jnz	short B_77
  3072                                  	; 23/02/2019 
  3073 0000111C 7540                    	jnz	short B_72 ; invalid! (use maximum available sectors)
  3074                                  
  3075                                  	; 08/02/2019
  3076 0000111E 09D2                    	or	dx, dx
  3077 00001120 750A                    	jnz	short B_71 ; proper size (for now)
  3078                                  
  3079 00001122 8B1E[D66F]              	mov	bx, [min_sectors] ; minimum sectors
  3080 00001126 39C3                    	cmp	bx, ax
  3081 00001128 7602                    	jna	short B_71 ; proper size (for now)	 
  3082                                  
  3083                                  	; invalid! (use minimum sectors or sectors per cylinder)
  3084 0000112A 89D8                    	mov	ax, bx
  3085                                  B_71:
  3086                                  	; 09/02/2019
  3087                                  	; save dx,ax
  3088 0000112C 8916[DE6F]              	mov	[ppn_Sectors+2], dx
  3089 00001130 A3[DC6F]                	mov	[ppn_Sectors], ax
  3090                                  
  3091                                  	; write partition size
  3092                                  	;push	dx
  3093                                  	;push	ax
  3094 00001133 BE[CB6F]                	mov	si, msg_partition_sectors + 7 ; max. 7 digits
  3095 00001136 E8CE0D                  	call	bin_to_decimal
  3096                                  	; ds:si = beginning of decimal number text
  3097 00001139 E8430D                  	call	print_msg
  3098 0000113C BE[F866]                	mov	si, msg_sectors_crlf
  3099 0000113F E83D0D                  	call	print_msg
  3100                                  	;pop	ax
  3101                                  	;pop	dx
  3102                                  
  3103 00001142 803E[B06F]00            	cmp	byte [wholedisk], 0
  3104 00001147 775E                    	ja	short B_77 ; 09/02/2019
  3105                                  
  3106                                  	; restore ax,dx
  3107 00001149 A1[DC6F]                	mov	ax, [ppn_Sectors]
  3108 0000114C 8B16[DE6F]              	mov	dx, [ppn_Sectors+2]
  3109                                  
  3110                                  	; select whole disk 
  3111                                  	;   if partition size > disk size
  3112 00001150 3B16[AE6F]              	cmp	dx, [pp_Sectors+2]
  3113 00001154 7708                    	ja	short B_72
  3114 00001156 724F                    	jb	short B_77
  3115 00001158 3B06[AC6F]              	cmp	ax, [pp_Sectors]
  3116 0000115C 7649                    	jna	short B_77
  3117                                  B_72:
  3118 0000115E 803E[AD41]00            	cmp	byte [newdisk], 0
  3119 00001163 7667                    	jna	short B_78
  3120                                  
  3121                                  	; "use whole disk or go to back" question
  3122 00001165 BE[1751]                	mov	si, msg_partition_size_overs
  3123                                  B_73:
  3124 00001168 E8140D                  	call	print_msg
  3125                                  B_74:
  3126 0000116B 30E4                    	xor	ah, ah
  3127 0000116D CD16                    	int	16h
  3128                                  	
  3129 0000116F 3C1B                    	cmp	al, 27 ; ESCAPE key
  3130                                  	;je	B_49
  3131 00001171 0F8424FF                	je	B_66 ; 09/02/2019
  3132 00001175 3C0D                    	cmp	al, 13 ; ENTER (Carriage Return) key
  3133 00001177 75F2                    	jne	short B_74
  3134                                  
  3135 00001179 FE06[B06F]              	inc	byte [wholedisk]
  3136                                  
  3137                                  	; 24/02/2019
  3138 0000117D 803E[AD41]00            	cmp	byte [newdisk], 0
  3139 00001182 7715                    	ja	short B_75
  3140                                  
  3141 00001184 8B1E[3E73]              	mov	bx, [c_fspc_offset]
  3142 00001188 8B87[F472]              	mov	ax, [free_space.sectors_unused+bx]
  3143 0000118C 8B97[F672]              	mov	dx, [free_space.sectors_unused+bx+2]
  3144 00001190 A3[AC6F]                	mov	[pp_Sectors], ax
  3145 00001193 8916[AE6F]              	mov	[pp_Sectors+2], dx
  3146 00001197 EB07                    	jmp	short B_76 
  3147                                  B_75:
  3148                                  	; 09/02/2019
  3149 00001199 8B16[AE6F]              	mov	dx, [pp_Sectors+2]
  3150 0000119D A1[AC6F]                	mov	ax, [pp_Sectors]
  3151                                  B_76:
  3152 000011A0 8916[DE6F]              	mov	[ppn_Sectors+2], dx
  3153 000011A4 A3[DC6F]                	mov	[ppn_Sectors], ax
  3154                                  B_77:
  3155 000011A7 803E[B16F]05            	cmp	byte [pp_type], 5
  3156 000011AC 0F853601                	jne	B_99
  3157                                  
  3158 000011B0 803E[A172]00            	cmp	byte [ppcount], 0  ; primary partition count
  3159 000011B5 0F87C500                	ja	B_93
  3160                                  
  3161 000011B9 BE[8151]                	mov	si, msg_ext_partition_error
  3162 000011BC E8C00C                  	call	print_msg
  3163 000011BF BE[FA50]                	mov	si, msg_any_key_to_retry
  3164 000011C2 E8BA0C                  	call	print_msg
  3165                                  
  3166                                  	; 09/02/2019
  3167 000011C5 30E4                    	xor	ah, ah
  3168 000011C7 CD16                    	int	16h
  3169                                  
  3170                                  	;jmp	B_49
  3171 000011C9 E920F6                  	jmp	cpi_2 
  3172                                  
  3173                                  B_78:
  3174                                  	; clear screen
  3175 000011CC B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
  3176 000011CF CD10                    	int	10h
  3177                                  
  3178 000011D1 BE[054A]                	mov	si, msg_create_dos_partition_h ; header
  3179 000011D4 E8A80C                  	call	print_msg
  3180                                  
  3181 000011D7 BE[C760]                	mov	si, msg_partition_size_limit
  3182 000011DA E8A20C                  	call	print_msg
  3183                                  
  3184 000011DD 8B1E[3E73]              	mov	bx, [c_fspc_offset]
  3185                                  
  3186 000011E1 803E[BE6F]53            	cmp	byte [pSize_unit], 'S'
  3187 000011E6 7415                    	je	short B_79
  3188 000011E8 803E[BE6F]4B            	cmp	byte [pSize_unit], 'K'
  3189 000011ED 740E                    	je	short B_79
  3190                                  
  3191 000011EF 803E[BE6F]25            	cmp	byte [pSize_unit], '%'
  3192 000011F4 7469                    	je	short B_89
  3193                                  
  3194 000011F6 803E[BE6F]43            	cmp	byte [pSize_unit], 'C'
  3195 000011FB 7479                    	je	B_92
  3196                                  B_79:
  3197                                  	; 'S', 'K'
  3198 000011FD 81C3[F472]              	add	bx, free_space.sectors_unused	
  3199 00001201 8B07                    	mov	ax, [bx]
  3200 00001203 8B5702                  	mov	dx, [bx+2]
  3201                                  		
  3202 00001206 B90A00                  	mov	cx, 10
  3203 00001209 89E5                    	mov	bp, sp
  3204                                  B_80:
  3205 0000120B E864FC                  	call	div32
  3206 0000120E 53                      	push	bx
  3207 0000120F 09D2                    	or	dx, dx
  3208 00001211 75F8                    	jnz	short B_80
  3209 00001213 83F809                  	cmp	ax, 9
  3210 00001216 77F3                    	ja	short B_80
  3211                                  B_81:
  3212 00001218 BB0700                  	mov	bx, 07h
  3213 0000121B 09C0                    	or	ax, ax
  3214 0000121D 7501                    	jnz	short B_83
  3215                                  B_82:
  3216 0000121F 58                      	pop	ax
  3217                                  B_83:
  3218 00001220 0430                    	add	al, '0'
  3219                                  B_84:
  3220 00001222 B40E                    	mov	ah, 0Eh
  3221                                  	;mov	bx, 07h
  3222 00001224 CD10                    	int	10h	; write character (as tty)
  3223                                  
  3224 00001226 39EC                    	cmp	sp, bp			
  3225 00001228 72F5                    	jb	short B_82
  3226                                  
  3227 0000122A 803E[BE6F]53            	cmp	byte [pSize_unit], 'S'
  3228 0000122F 7422                    	je	short B_86
  3229 00001231 803E[BE6F]4B            	cmp	byte [pSize_unit], 'K'
  3230 00001236 741B                    	je	short B_86
  3231                                  
  3232 00001238 803E[BE6F]25            	cmp	byte [pSize_unit], '%'
  3233 0000123D 7508                    	jne	short B_85
  3234                                  
  3235                                  	; 24/02/2019
  3236 0000123F 3C25                    	cmp	al, '%'
  3237 00001241 7416                    	je	short B_88
  3238 00001243 B025                    	mov	al, '%'
  3239 00001245 EBDB                    	jmp	short B_84 
  3240                                  B_85:
  3241 00001247 803E[BE6F]43            	cmp	byte [pSize_unit], 'C'
  3242 0000124C 7505                    	jne	short B_86
  3243                                  
  3244 0000124E BE[6361]                	mov	si, msg_cylinders
  3245 00001251 EB03                    	jmp	short B_87
  3246                                  B_86:
  3247 00001253 BE[6E61]                	mov	si, msg_sectors
  3248                                  B_87:
  3249 00001256 E8260C                  	call	print_msg
  3250                                  B_88:
  3251 00001259 BE[1461]                	mov	si, msg_partition_size_limit_r
  3252                                  	;call	print_msg
  3253                                  
  3254 0000125C E909FF                  	jmp	B_73
  3255                                  
  3256                                  B_89:
  3257                                  	; '%'
  3258 0000125F 81C3[F272]              	add	bx, free_space.percent_unused
  3259 00001263 8B07                    	mov	ax, [bx]
  3260                                  B_90:	
  3261 00001265 89E5                    	mov	bp, sp
  3262                                  B_91:	
  3263 00001267 31D2                    	xor	dx, dx
  3264 00001269 B90A00                  	mov	cx, 10
  3265 0000126C F7F1                    	div	cx
  3266 0000126E 52                      	push	dx
  3267 0000126F 83F809                  	cmp	ax, 9
  3268 00001272 77F3                    	ja	short B_91	
  3269 00001274 EBA2                    	jmp	short B_81
  3270                                  B_92:
  3271                                  	; 'C'
  3272 00001276 81C3[EC72]              	add	bx, free_space.space
  3273 0000127A 8B07                    	mov	ax, [bx]
  3274 0000127C EBE7                    	jmp	short B_90
  3275                                  
  3276                                  B_93:
  3277                                  	; 23/02/2019
  3278 0000127E 8B1E[3E73]              	mov	bx, [c_fspc_offset]
  3279 00001282 8B87[EE72]              	mov	ax, [bx+free_space.start]
  3280                                  
  3281                                  	; set free space start cylinder to 1 if it is 0
  3282 00001286 09C0                    	or	ax, ax
  3283 00001288 750F                    	jnz	short B_94
  3284                                  
  3285 0000128A B005                    	mov	al, 5	; Get free space for extended partition
  3286 0000128C E8D514                  	call	find_part_free_space
  3287                                  
  3288 0000128F 891E[3E73]              	mov	[c_fspc_offset], bx
  3289                                  
  3290 00001293 21C9                    	and	cx, cx
  3291 00001295 0F840EF2                	jz	cp_4	; there is not free space on disk
  3292                                  B_94:
  3293                                  	; 24/02/2019
  3294 00001299 E81100                  	call	partition_size_fixup_x
  3295 0000129C 0F822CFF                	jc	B_78
  3296                                  
  3297                                  	; 16/02/2019
  3298 000012A0 E8EAF7                  	call	create_extended_partition 
  3299                                  			; must be called after 'find_part_free_space'.
  3300                                  	; 24/02/2019
  3301 000012A3 E82E11                  	call	show_selected_partition
  3302 000012A6 E9BE00                  	jmp	C_02
  3303                                  
  3304                                  partition_size_fixup:
  3305                                  	; 24/02/2019
  3306 000012A9 8B1E[3E73]              	mov	bx, [c_fspc_offset]
  3307                                  partition_size_fixup_x:
  3308                                  	; 25/02/2019 
  3309 000012AD 803E[AD41]00            	cmp	byte [newdisk], 0
  3310 000012B2 7731                    	ja	short B_98
  3311                                  
  3312 000012B4 81C3[F472]              	add	bx, free_space.sectors_unused	
  3313 000012B8 8B07                    	mov	ax, [bx]
  3314 000012BA 8B5702                  	mov	dx, [bx+2]
  3315                                  
  3316 000012BD 3B16[DE6F]              	cmp	dx, [ppn_Sectors+2]
  3317 000012C1 7222                    	jb	short B_98 ; 24/02/2019
  3318 000012C3 7708                    	ja	short B_95
  3319 000012C5 3B06[DC6F]              	cmp	ax, [ppn_Sectors]
  3320 000012C9 721A                    	jb	short B_98 ; 24/02/2019
  3321 000012CB 7411                    	je	short B_97
  3322                                  
  3323                                  B_95:
  3324                                  	; 19/02/2019
  3325 000012CD A1[DC6F]                	mov	ax, [ppn_Sectors]
  3326                                  B_96:
  3327 000012D0 8B16[DE6F]              	mov	dx, [ppn_Sectors+2]
  3328                                  
  3329                                  	; 18/02/2019
  3330                                  
  3331                                  	; check for best fit
  3332                                  	; (leave max. available space to next time if 
  3333                                  	;  another space/gap fits to partition size request.)
  3334                                  
  3335 000012D4 E8A716                  	call	find_enough_free_sectors
  3336                                  		; CX = Free space index (0 to 4)
  3337                                  		; DX:AX = First available space which fits to request
  3338                                  	;mov	bx, cx
  3339                                  	;shl	bl, 4 ; * 16  ; * Free space structure size
  3340                                  	;mov	[c_fspc_offset], bx
  3341                                  	
  3342                                  	; 22/02/2019
  3343 000012D7 C0E104                  	shl	cl, 4
  3344 000012DA 890E[3E73]              	mov	[c_fspc_offset], cx 
  3345                                  
  3346                                  	;add	bx, free_space.sectors_unused	
  3347                                  	;mov	ax, [bx]
  3348                                  	;mov	dx, [bx+2]
  3349                                  B_97:		
  3350                                  	; Save max. available space
  3351 000012DE A3[AC6F]                	mov	[pp_Sectors], ax
  3352 000012E1 8916[AE6F]              	mov	[pp_Sectors+2], dx
  3353                                  B_98:
  3354 000012E5 C3                      	retn
  3355                                  
  3356                                  B_99:
  3357                                  	; 24/02/2019
  3358 000012E6 E8C0FF                  	call	partition_size_fixup
  3359 000012E9 0F82DFFE                	jc	B_78
  3360                                  
  3361                                  	; 16/02/2019
  3362                                  	; Force cylinder boundary alignment except
  3363                                  	;   sectors ('S') and kilobytes ('K') as sizing unit.
  3364                                  
  3365 000012ED C606[4073]59            	mov	byte [cylinder_boundary], 'Y' ; Default
  3366                                  				; sizing unit is one of
  3367                                  				; 'cylinders','megabytes','gigabytes'
  3368                                  				; and boundary alignment is yes for them.
  3369 000012F2 A0[BE6F]                	mov	al, [pSize_unit]
  3370                                  
  3371                                  	;cmp	byte [pSize_unit], 'S' ; Sectors
  3372 000012F5 3C53                    	cmp	al, 'S'
  3373 000012F7 7404                    	je	short B_100
  3374                                  
  3375                                  	;cmp	byte [pSize_unit], 'K' ; Kilobytes
  3376 000012F9 3C4B                    	cmp	al, 'K'
  3377 000012FB 752F                    	jne	short B_104
  3378                                  B_100:
  3379                                  	; Sizing unit is one of 'sectors' and/or 'kilobytes'
  3380                                  	; and bound aligment will be applied if the answer will be yes. 
  3381                                  
  3382 000012FD BE[0952]                	mov	si, msg_cylinder_boundary_set
  3383 00001300 E87C0B                  	call	print_msg
  3384                                  B_101:
  3385 00001303 30E4                    	xor	ah, ah
  3386 00001305 CD16                    	int	16h
  3387                                  	; Cylinder boundary adjusting
  3388 00001307 3C0D                    	cmp	al, 13 ; ENTER key
  3389 00001309 74F2                    	je	short B_100
  3390 0000130B 3C1B                    	cmp	al, 27 ; ESCAPE key
  3391 0000130D 741A                    	je	short B_103	; Align end of the partition only
  3392                                  				; if start of the partition is aligned
  3393                                  				; or it starts at cyl 0, head 1, sect 17 or 63.
  3394                                  				; (End of the partition will be extended to
  3395                                  				; end sector of it's last cylinder if the size
  3396                                  				; will not over [pp_Sectors] value.)  	 
  3397 0000130F 24DF                    	and	al, 0DFh
  3398                                  
  3399                                  	; 22/02/2019
  3400 00001311 3C59                    	cmp	al, 'Y'
  3401 00001313 7508                    	jne	short B_102
  3402                                  
  3403 00001315 BE[025F]                	mov	si, _msg_YES
  3404 00001318 E8640B                  	call	print_msg
  3405                                  
  3406                                  	;mov	al, 'Y'
  3407                                  	;jmp	short B_103
  3408 0000131B EB0F                    	jmp	short B_104
  3409                                  B_102:
  3410 0000131D 3C4E                    	cmp	al, 'N'
  3411 0000131F 75E2                    	jne	short B_101
  3412                                  
  3413 00001321 BE[085F]                	mov	si, _msg_NO
  3414 00001324 E8580B                  	call	print_msg
  3415                                  
  3416 00001327 B04E                    	mov	al, 'N'
  3417                                  		; do not align partition to cylinder boundary 
  3418                                  B_103:
  3419 00001329 A2[4073]                	mov	[cylinder_boundary], al
  3420                                  B_104:
  3421 0000132C E811F5                  	call	create_primary_partition
  3422                                  	
  3423                                  	; 18/02/2019
  3424 0000132F 803E[AD41]00            	cmp	byte [newdisk], 0
  3425 00001334 760E                    	jna	short B_105
  3426                                  
  3427 00001336 31C0                    	xor	ax, ax ; 0
  3428 00001338 31D2                    	xor	dx, dx ; 0
  3429                                  	; DX_AX = Masterboot Sector = 0
  3430 0000133A BB[3858]                	mov	bx, MasterBootBuff
  3431                                  	; ES:BX = Sector Buffer
  3432 0000133D E84E0B                  	call	write_hd_sector
  3433 00001340 0F821B0B                	jc	D_01
  3434                                  
  3435                                  B_105:
  3436                                  	; DS:SI = Partition Table Entry address
  3437                                  	; 25/02/2019
  3438 00001344 8936[6673]              	mov	[pte_address], si  ; save PTE address
  3439 00001348 E88910                  	call	show_selected_partition
  3440                                  
  3441                                  	;jmp	C_01
  3442                                  
  3443                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3444                                  ; Format question
  3445                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3446                                  
  3447                                  C_01:
  3448                                  	;mov	si, CRLF
  3449                                  	;call	print_msg
  3450                                  
  3451 0000134B C606[CD6F]01            	mov	byte [format_q], 1
  3452                                  
  3453 00001350 A0[B16F]                	mov	al, [pp_type]
  3454 00001353 3C01                    	cmp	al, 1		; FAT12 (CHS)
  3455 00001355 741D                    	je	short C_03
  3456 00001357 3C04                    	cmp	al, 4		; FAT16 CHS
  3457 00001359 7419                    	je	short C_03
  3458 0000135B 3C06                    	cmp	al, 6		; FAT16 BIG CHS
  3459 0000135D 7415                    	je	short C_03
  3460 0000135F 3C0B                    	cmp	al, 0Bh		; FAT32 CHS
  3461 00001361 7411                    	je	short C_03
  3462 00001363 3CA1                    	cmp	al, 0A1h	; SINGLIX FS1
  3463 00001365 740D                    	je	short C_03
  3464                                  
  3465                                  	;cmp	al, 71h
  3466                                  	;je	short C_03	; RETRO UNIX 386
  3467                                  
  3468                                  	;dec	byte [format_q] ; 0		
  3469                                  C_02:
  3470 00001367 C606[CD6F]00            	mov	byte [format_q], 0 ; 24/02/2019
  3471                                  
  3472                                  	; NON-DOS partition!
  3473                                  	; Ask for editing PT or exit (continue without formatting)
  3474 0000136C BE[8F55]                	mov	si, msg_edit_or_exit
  3475 0000136F E80D0B                  	call	print_msg
  3476 00001372 EB06                    	jmp	short C_04
  3477                                  C_03:
  3478                                  	; Ask for formatting, editing PT or exit
  3479 00001374 BE[2055]                	mov	si, msg_format_stage
  3480 00001377 E8050B                  	call	print_msg
  3481                                  C_04:
  3482 0000137A BE[6055]                	mov	si, msg_partition_edit
  3483 0000137D E8FF0A                  	call	print_msg
  3484                                  C_05:
  3485 00001380 28E4                    	sub	ah, ah
  3486 00001382 CD16                    	int	16h
  3487                                  
  3488 00001384 3C0D                    	cmp	al, 13
  3489 00001386 7452                    	je	short C_08
  3490                                  
  3491                                  	;; 07/03/2019
  3492 00001388 3C20                    	cmp	al, 20h ; SPACE
  3493                                  	;je	A_27 ; edit partition table option is selected
  3494 0000138A 7406                    	je	short C_06 ; 08/03/2019	
  3495                                  
  3496 0000138C 3C1B                    	cmp	al, 27 ; ESCAPE
  3497 0000138E 75F0                    	jne	short C_05
  3498                                  	
  3499 00001390 30C0                    	xor	al, al ; 08/03/2019 
  3500                                  Exit:
  3501                                  C_06:
  3502 00001392 50                      	push	ax ; 08/03/2019
  3503 00001393 B43E                    	mov	ah, 3Eh ; close file
  3504 00001395 8B1E[A441]              	mov	bx, [img_file_handle]
  3505 00001399 CD21                    	int	21h
  3506                                  	; 08/03/2019
  3507 0000139B 58                      	pop	ax
  3508                                  	;cmp	al, 27
  3509                                  	;je	short C_06_exit
  3510 0000139C 08C0                    	or	al, al
  3511 0000139E 7409                    	jz	short C_06_exit
  3512 000013A0 C706[A441]0000          	mov 	word [img_file_handle], 0
  3513 000013A6 E991EE                  	jmp	A_27
  3514                                  
  3515                                  C_06_exit:
  3516 000013A9 BE[6057]                	mov	si, CRLF
  3517 000013AC E8D00A                  	call	print_msg
  3518                                  
  3519                                  	; 11/02/2019
  3520                                   
  3521                                  	; Exit	
  3522 000013AF CD20                    	int	20h
  3523                                  
  3524                                  ;-----------------------------------------------------------------------------
  3525                                  
  3526                                  save_mbr_exit:
  3527                                  	; 24/02/2019
  3528 000013B1 E80512                  	call	init_partition_tables
  3529                                  
  3530 000013B4 E86816                  	call	display_partition_table
  3531                                  
  3532 000013B7 BE[6057]                	mov	si, CRLF
  3533 000013BA E8C20A                  	call	print_msg
  3534                                  
  3535 000013BD BE[1456]                	mov	si, msg_writing_mbr
  3536 000013C0 E8BC0A                  	call	print_msg
  3537                                  
  3538 000013C3 31C0                    	xor	ax, ax ; 0
  3539 000013C5 31D2                    	xor	dx, dx ; 0
  3540                                  	; DX_AX = Masterboot Sector = 0
  3541 000013C7 BB[3858]                	mov	bx, MasterBootBuff
  3542                                  	; ES:BX = Sector Buffer
  3543 000013CA E8C10A                  	call	write_hd_sector
  3544 000013CD 7303                    	jnc	short C_07
  3545 000013CF E98D0A                  	jmp	D_01
  3546                                  C_07:
  3547 000013D2 BE[5C57]                	mov	si, Msg_OK
  3548 000013D5 E8A70A                  	call	print_msg
  3549 000013D8 EBB8                    	jmp	short Exit
  3550                                  
  3551                                  C_08:
  3552 000013DA 803E[CD6F]01            	cmp	byte [format_q], 1
  3553 000013DF 72D0                    	jb	short save_mbr_exit
  3554                                  
  3555                                  	; 25/02/2019
  3556                                  	; Write MBR without writing message
  3557                                  	
  3558                                  	; NOTE: This may be second time of MBR writing...
  3559                                  	;	but, if partition table is modified,
  3560                                  	;	we need to write MBR to disk, here.
  3561                                  	;
  3562                                  	; (Otherwise.. the last created partition would not be recorded.) 	
  3563                                  
  3564 000013E1 31C0                    	xor	ax, ax ; 0
  3565 000013E3 31D2                    	xor	dx, dx ; 0
  3566                                  	; DX_AX = Masterboot Sector = 0
  3567 000013E5 BB[3858]                	mov	bx, MasterBootBuff
  3568                                  	; ES:BX = Sector Buffer
  3569 000013E8 E8A30A                  	call	write_hd_sector
  3570 000013EB 0F82700A                	jc	D_01
  3571                                  
  3572                                  	;; clear screen
  3573                                  	;mov	ax, 3 ; set video mode to 03h (80x25 text)
  3574                                  	;int	10h
  3575                                  
  3576                                  	; 25/02/2019
  3577 000013EF 8B36[6673]              	mov	si, [pte_address]
  3578                                  
  3579                                  	; 18/02/2019
  3580 000013F3 E8DE0F                  	call	show_selected_partition	
  3581                                  
  3582 000013F6 A0[4755]                	mov	al, [partition_num_chr]
  3583 000013F9 A2[0756]                	mov	[partition_num_txt], al
  3584                                  
  3585 000013FC BE[E555]                	mov	si, msg_format_question
  3586 000013FF E87D0A                  	call	print_msg
  3587                                  C_09:
  3588 00001402 30E4                    	xor	ah, ah
  3589 00001404 CD16                    	int	16h
  3590                                  
  3591 00001406 3C1B                    	cmp	al, 1Bh ; ESCAPE
  3592 00001408 7488                    	je	short C_06
  3593                                  
  3594 0000140A 24DF                    	and	al, 0DFh ; capitalization
  3595 0000140C 3C59                    	cmp	al, 'Y'
  3596 0000140E 740C                    	je	short C_10
  3597 00001410 3C4E                    	cmp	al, 'N'
  3598 00001412 75EE                    	jne	short C_09
  3599 00001414 BE[085F]                	mov	si, _msg_NO 
  3600 00001417 E8650A                  	call	print_msg
  3601                                  	;jmp	short C_06
  3602                                  	; 24/02/2019
  3603 0000141A EB95                    	jmp	short save_mbr_exit 
  3604                                  C_10:
  3605 0000141C BE[025F]                	mov	si, _msg_YES
  3606 0000141F E85D0A                  	call	print_msg
  3607                                  
  3608                                  	; [pp_StartSector] = partition's start sector
  3609                                  	; [pp_Sectors] = partition size including start & end sector	
  3610                                  	; [partition_num_chr] = partition number + '0'
  3611                                  	; [pp_type] = partition type (for TRDOS 386 boot sector) 
  3612                                  
  3613 00001422 8926[1E6B]              	mov	[old_sp], sp
  3614                                  	
  3615 00001426 8A16[B16F]              	mov	dl, [pp_type]
  3616                                  	; DL = partition type (file system ID)
  3617                                  	;dec	dl
  3618                                  	;jz	FAT12_hdi_format
  3619 0000142A 80FA01                  	cmp	dl, 1 ; 14/09/2020 (BugFix)
  3620 0000142D 0F86D805                	jna	FAT12_hdi_format
  3621                                  	;cmp	dl, 4
  3622                                  	;je	FAT16_hdi_format
  3623                                  	;cmp	dl, 6
  3624                                  	;je	FAT16_hdi_format
  3625 00001431 80FA0B                  	cmp	dl, 0Bh 
  3626 00001434 0F82D503                	jb	FAT16_hdi_format
  3627                                  	;je	short FAT32_hdi_format	
  3628                                  	;cmp	dl, 0Ch ; 14/09/2020
  3629 00001438 0F876507                	ja	SINGLIX_hdi_format
  3630                                  
  3631                                  	;cmp	dl, 0A1h
  3632                                  	;je	SINGLIX_hdi_format
  3633                                  	;jb	RUNIX386_hdi_format ; dl = 071h
  3634                                  
  3635                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3636                                  ; FAT32 FORMATTING
  3637                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 	
  3638                                  	
  3639                                  	; 08/02/2019 (Modified for -only- FAT32 CHS partitions) 
  3640                                  FAT32_hdi_format:
  3641                                  	;mov	ax, 000Ch ; db 0Ch, 00h ; 'or al, 0'
  3642                                  	;cmp	dl, al ; 0Ch
  3643                                  	;je	short FAT32_lba_format
  3644                                  	;mov	ax, 0C00Bh ; db 0Bh, 0C0h ; 'or ax, ax'
  3645                                  ;FAT32_lba_format:
  3646                                  	; Put TRDOS 386 FAT32 partition magic word 
  3647                                  	; at offset 5Ah, in TRDOS386 FAT32 boot sector 0.
  3648 0000143C BD[9335]                	mov	bp, TRDOS_FAT32_hd_bs
  3649 0000143F 8D7E03                  	lea	di, [bp+3]
  3650 00001442 BE[0467]                	mov	si, bs_oem_name
  3651 00001445 B90400                  	mov	cx, 4
  3652 00001448 F3A5                    	rep	movsw 
  3653                                  	;mov	[bp+5Ah], ax	; [loc_5A]
  3654 0000144A C7465A0BC0              	mov	word [bp+5Ah], 0C00Bh ; 08/02/2019
  3655 0000144F A1[A641]                	mov	ax, [sectors]
  3656 00001452 894618                  	mov	[bp+18h], ax	; [BPB_SecPerTrk]
  3657 00001455 A1[A841]                	mov	ax, [heads]
  3658 00001458 89461A                  	mov	[bp+1Ah], ax	; [BPB_NumHeads]
  3659 0000145B A1[A86F]                	mov	ax, [pp_StartSector]
  3660 0000145E 89461C                  	mov	[bp+1Ch], ax	; [BPB_HiddSec]
  3661 00001461 A1[AA6F]                	mov	ax, [pp_StartSector+2]
  3662 00001464 89461E                  	mov	[bp+1Eh], ax	; [BPB_HiddSec+2]
  3663                                  	;mov	ax, [pp_Sectors]
  3664 00001467 A1[DC6F]                	mov	ax, [ppn_Sectors] ; 16/02/2019
  3665 0000146A 894620                  	mov	[bp+20h], ax	; [BPB_TotSec32]
  3666                                  	;mov	dx, [pp_Sectors+2]
  3667 0000146D 8B16[DE6F]              	mov	dx, [ppn_Sectors+2] ; 16/02/2019
  3668 00001471 895622                  	mov	[bp+22h], dx	; [BPB_TotSec32+2]
  3669                                  	
  3670                                  	; Sectors per cluster calculation
  3671                                  	; (According to MS FAT32 FS specification.)
  3672 00001474 B108                    	mov	cl, 8  ; 8 sectors per cluster
  3673 00001476 83FA08                  	cmp	dx, 8  ; >= 532480 sectors
  3674 00001479 7709                    	ja	short FAT32_f_2 ; 8 sectors per cluster
  3675 0000147B 7205                    	jb	short FAT32_f_1 ; 1 sector per cluster	
  3676 0000147D 3D0020                  	cmp	ax, 2000h ; dx_ax = (8*65536)+8192
  3677 00001480 7302                    	jnb	short FAT32_f_2 ; 12/09/2020 (BugFix)
  3678                                  FAT32_f_1:
  3679 00001482 B101                    	mov	cl, 1	; 1 sector per cluster		
  3680                                  FAT32_f_2:
  3681 00001484 884E0D                  	mov	[bp+0Dh], cl	 ; [BPB_SecPerClus]
  3682                                  	;mov	byte [bp+10h], 2 ; [BPB_NumFATs] 
  3683                                  	;mov	word [bp+0Eh], 32 ; [BPB_RsvdSecCnt] 
  3684                                  
  3685                                  	; Calculating FAT size in sectors
  3686                                  	; (According to MS FAT32 FS Specification, 2000)
  3687                                  
  3688                                  	; DX_AX = partition (volume) size in sectors
  3689 00001487 2B460E                  	sub	ax, [bp+0Eh]	; [BPB_RsvdSecCnt] ; 32
  3690 0000148A 83DA00                  	sbb	dx, 0
  3691                                  		; TmpVal1 = DiskSize - (BPB_ResvdSecCnt +
  3692                                  		;	     		RootDirsectors)
  3693                                  		; RootDirSectors = 0 (for FAT32 FS)
  3694 0000148D 89CB                    	mov	bx, cx ; ch = 0
  3695 0000148F C1E308                  	shl	bx, 8 ; * 256
  3696 00001492 8A4E10                  	mov	cl, [bp+10h] ; [BPB_NumFATs] 
  3697 00001495 01CB                    	add	bx, cx	
  3698                                  		; TmpVal2 = (256*BPB_SecPerClus)+BPB_NumFATs
  3699 00001497 D1EB                    	shr	bx, 1
  3700                                  		; TmpVal2 = TmpVal2/2
  3701 00001499 89D9                    	mov	cx, bx
  3702 0000149B 4B                      	dec	bx  ; TmpVal2-1
  3703 0000149C 01D8                    	add	ax, bx
  3704 0000149E 83D200                  	adc	dx, 0
  3705 000014A1 E8CEF9                  	call	div32
  3706                                  		; FATSz = (TmpVal1+(TmpVal2-1))/TmpVal2
  3707                                  	; DX_AX = FAT size in sectors
  3708 000014A4 894624                  	mov	[bp+24h], ax	; [BPB_FATSz32]
  3709 000014A7 895626                  	mov	[bp+26h], dx	; [BPB_FATSz32+2]
  3710                                  	; * 2
  3711 000014AA 89D3                    	mov	bx, dx
  3712 000014AC 01C0                    	add	ax, ax
  3713 000014AE 11D3                    	adc	bx, dx
  3714                                  	; BX_AX = [BPB_NumFATs] * [BPB_FATSz32]
  3715 000014B0 8B4E0E                  	mov	cx, [bp+0Eh]	; [BPB_RsvdSecCnt] ; 32
  3716 000014B3 01C1                    	add	cx, ax
  3717 000014B5 83D300                  	adc	bx, 0
  3718                                  	; BX_CX = [BPB_RsvdSecCnt]+[BPB_NumFATs]*[BPB_FATSz32]
  3719 000014B8 8B4620                  	mov	ax, [bp+20h]	; [BPB_TotSec32]
  3720 000014BB 8B5622                  	mov	dx, [bp+22h]	; [BPB_TotSec32+2]
  3721 000014BE 29C8                    	sub	ax, cx
  3722 000014C0 19DA                    	sbb	dx, bx
  3723 000014C2 890E[206D]              	mov	[data_start], cx
  3724 000014C6 891E[226D]              	mov	[data_start+2], bx
  3725                                  	; DX_AX = Data sectors
  3726 000014CA A3[246D]                	mov	[data_sectors], ax
  3727 000014CD 8916[266D]              	mov	[data_sectors+2], dx
  3728 000014D1 8A4E0D                  	mov	cl, [bp+0Dh]	 ; [BPB_SecPerClus]
  3729 000014D4 30ED                    	xor	ch, ch
  3730 000014D6 E899F9                  	call	div32 ; DX_AX/CX
  3731                                  	; DX_AX = Count of clusters (rounded down)
  3732 000014D9 A3[286D]                	mov	[cluster_count], ax
  3733 000014DC 8916[2A6D]              	mov	[cluster_count+2], dx
  3734                                  		
  3735 000014E0 8D7E47                  	lea	di, [bp+71] ; [BS_VolLab]
  3736 000014E3 E89E01                  	call	write_volume_name
  3737 000014E6 8D7643                  	lea	si, [bp+67] ; [BS_VolID]
  3738 000014E9 E8F701                  	call	write_volume_serial
  3739 000014EC E80703                  	call	write_cluster_count
  3740                                  
  3741 000014EF E87802                  	call	write_formatting_msg
  3742 000014F2 B000                    	mov	al, 0
  3743 000014F4 E8D002                  	call	write_format_percent_x
  3744                                  
  3745 000014F7 8B461C                  	mov	ax, [bp+1Ch]	; [BPB_HiddSec]
  3746 000014FA 8B561E                  	mov	dx, [bp+1Eh]	; [BPB_HiddSec+2]
  3747 000014FD 0106[206D]              	add	[data_start], ax
  3748 00001501 1116[226D]              	adc	[data_start+2], dx
  3749                                  FAT32_f_3:
  3750                                  	; DX_AX = FAT32 Boot Sector address
  3751 00001505 BB[9335]                	mov	bx, TRDOS_FAT32_hd_bs
  3752                                  	; ES:BX = Boot Sector 1 Buffer
  3753 00001508 E88309                  	call	write_hd_sector
  3754 0000150B 0F82CC02                	jc	formatting_error
  3755 0000150F E87C02                  	call	write_format_percent
  3756 00001512 83C001                  	add	ax, 1
  3757 00001515 83D200                  	adc	dx, 0
  3758 00001518 BB[1A69]                	mov	bx, HDFORMAT_FSINFO_BUFF
  3759                                  	; ES:BX = FS INFO Sector Buffer (= BS+1)
  3760 0000151B E87009                  	call	write_hd_sector
  3761 0000151E 0F82B902                	jc	formatting_error
  3762 00001522 E86902                  	call	write_format_percent	
  3763 00001525 83C001                  	add	ax, 1
  3764 00001528 83D200                  	adc	dx, 0	
  3765 0000152B BB[9337]                	mov	bx, TRDOS_FAT32_hd_bs + 512
  3766                                  	; ES:BX = Boot Sector 2 Buffer
  3767 0000152E E85D09                  	call	write_hd_sector
  3768 00001531 0F82A602                	jc	formatting_error
  3769 00001535 E85602                  	call	write_format_percent
  3770 00001538 B90300                  	mov	cx, 3
  3771                                  FAT32_f_4:
  3772 0000153B 51                      	push	cx
  3773 0000153C 83C001                  	add	ax, 1
  3774 0000153F 83D200                  	adc	dx, 0
  3775 00001542 BB[206B]                	mov	bx, HDFORMAT_EMPTY_BUFF
  3776 00001545 E84609                  	call	write_hd_sector
  3777 00001548 0F828F02                	jc	formatting_error
  3778 0000154C E83F02                  	call	write_format_percent
  3779 0000154F 59                      	pop	cx
  3780 00001550 FEC9                    	dec	cl
  3781 00001552 75E7                    	jnz	short FAT32_f_4
  3782 00001554 83C001                  	add	ax, 1
  3783 00001557 83D200                  	adc	dx, 0
  3784 0000155A 8B4E1C                  	mov	cx, [bp+1Ch]	; [BPB_HiddSec]
  3785 0000155D 8B5E1E                  	mov	bx, [bp+1Eh]	; [BPB_HiddSec+2]
  3786 00001560 83C10C                  	add	cx, 12
  3787 00001563 83D300                  	adc	bx, 0
  3788                                  	; write BACKUP sectors
  3789                                  	; (6,7,8 boot+fsi and 9,10,11 empty sectors) 
  3790 00001566 39DA                    	cmp	dx, bx
  3791 00001568 729B                    	jb	short FAT32_f_3
  3792 0000156A 39C8                    	cmp	ax, cx
  3793 0000156C 7297                    	jb	short FAT32_f_3
  3794                                  	; write remain part of reserved sectors
  3795 0000156E 8B4E0E                  	mov	cx, [bp+0Eh]	; [BPB_RsvdSecCnt]
  3796 00001571 83E90C                  	sub	cx, 12
  3797 00001574 7618                    	jna	short FAT32_f_6
  3798                                  FAT32_f_5:
  3799 00001576 51                      	push	cx
  3800 00001577 BB[206B]                	mov	bx, HDFORMAT_EMPTY_BUFF
  3801 0000157A E81109                  	call	write_hd_sector
  3802 0000157D 0F825A02                	jc	formatting_error
  3803 00001581 E80A02                  	call	write_format_percent
  3804 00001584 83C001                  	add	ax, 1
  3805 00001587 83D200                  	adc	dx, 0
  3806 0000158A 59                      	pop	cx
  3807 0000158B 49                      	dec	cx
  3808 0000158C 75E8                    	jnz	short FAT32_f_5
  3809                                  FAT32_f_6:
  3810                                  	; write FAT sectors
  3811 0000158E 8B0E[206D]              	mov	cx, [data_start] ; lba/abs addr
  3812 00001592 8B1E[226D]              	mov	bx, [data_start+2] ; lba/abs addr
  3813 00001596 53                      	push	bx
  3814 00001597 51                      	push	cx
  3815 00001598 BB[206B]                	mov	bx, HDFORMAT_FATBUFFER
  3816                                  	; ES:BX = FAT Sector Buffer
  3817 0000159B 8A4E15                  	mov	cl, [bp+15h] ; [BPB_Media]
  3818 0000159E B5FF                    	mov	ch, 0FFh
  3819 000015A0 890F                    	mov	[bx], cx
  3820 000015A2 88E9                    	mov	cl, ch ; cx = 0FFFFh
  3821 000015A4 894F02                  	mov	[bx+2], cx
  3822 000015A7 894F04                  	mov	[bx+4], cx
  3823 000015AA 894F06                  	mov	[bx+6], cx
  3824                                  	; Root dir cluster number = 2
  3825                                  	; 0FFFFFFFh = end of cluster chain 
  3826 000015AD 894F08                  	mov	[bx+8], cx  ; 0FFFFh
  3827 000015B0 80E50F                  	and	ch, 0Fh
  3828 000015B3 894F0A                  	mov	[bx+10], cx ; 0FFFh
  3829                                  	;inc	cx
  3830 000015B6 E8D508                  	call	write_hd_sector
  3831 000015B9 0F821E02                	jc	formatting_error
  3832 000015BD E8CE01                  	call	write_format_percent
  3833                                  	;mov	bx, HDFORMAT_FATBUFFER
  3834 000015C0 B90000                  	mov	cx, 0
  3835 000015C3 890F                    	mov	[bx], cx
  3836 000015C5 894F02                  	mov	[bx+2], cx
  3837 000015C8 894F04                  	mov	[bx+4], cx
  3838 000015CB 894F06                  	mov	[bx+6], cx
  3839 000015CE 894F08                  	mov	[bx+8], cx
  3840 000015D1 894F0A                  	mov	[bx+10], cx
  3841 000015D4 EB0F                    	jmp	short FAT32_f_8
  3842                                  FAT32_f_7:	
  3843 000015D6 53                      	push	bx
  3844 000015D7 51                      	push	cx	
  3845 000015D8 BB[206B]                	mov	bx, HDFORMAT_FATBUFFER
  3846 000015DB E8B008                  	call	write_hd_sector
  3847 000015DE 0F82F901                	jc	formatting_error
  3848 000015E2 E8A901                  	call	write_format_percent
  3849                                  FAT32_f_8:	
  3850 000015E5 59                      	pop	cx
  3851 000015E6 5B                      	pop	bx
  3852 000015E7 83C001                  	add	ax, 1
  3853 000015EA 83D200                  	adc	dx, 0
  3854 000015ED 39DA                    	cmp	dx, bx
  3855 000015EF 72E5                    	jb	short FAT32_f_7
  3856 000015F1 39C8                    	cmp	ax, cx
  3857 000015F3 72E1                    	jb	short FAT32_f_7
  3858                                  
  3859                                  	; write	root directory (1st cluster)
  3860                                  	; as empty sectors
  3861 000015F5 8A4E0D                  	mov	cl, [bp+0Dh]	 ; [BPB_SecPerClus]
  3862 000015F8 30ED                    	xor	ch, ch
  3863 000015FA 290E[246D]              	sub	[data_sectors], cx
  3864 000015FE 831E[266D]00            	sbb	word [data_sectors+2], 0
  3865                                  FAT32_f_9:
  3866 00001603 51                      	push	cx
  3867 00001604 BB[206B]                	mov	bx, HDFORMAT_EMPTY_BUFF
  3868 00001607 E88408                  	call	write_hd_sector
  3869 0000160A 0F82CD01                	jc	formatting_error
  3870 0000160E E87D01                  	call	write_format_percent
  3871 00001611 83C001                  	add	ax, 1
  3872 00001614 83D200                  	adc	dx, 0
  3873 00001617 59                      	pop	cx
  3874 00001618 FEC9                    	dec	cl
  3875 0000161A 75E7                    	jnz	short FAT32_f_9
  3876                                  
  3877                                  	; write DATA sectors 
  3878                                  	; (after root directory 1st cluster)
  3879 0000161C 8B0E[246D]              	mov	cx, [data_sectors]
  3880 00001620 8B1E[266D]              	mov	bx, [data_sectors+2] 
  3881                                  			; NOTE: Partition size must be >= 512 MB
  3882                                  			;	for FAT32 FS  ((BX >= 15))		
  3883                                  FAT32_f_10:	
  3884 00001624 53                      	push	bx
  3885 00001625 51                      	push	cx	
  3886 00001626 BB[1A67]                	mov	bx, HDFORMAT_SECBUFFER
  3887 00001629 E86208                  	call	write_hd_sector
  3888 0000162C 0F82AB01                	jc	formatting_error
  3889 00001630 E85B01                  	call	write_format_percent
  3890 00001633 59                      	pop	cx
  3891 00001634 5B                      	pop	bx
  3892 00001635 83C001                  	add	ax, 1
  3893 00001638 83D200                  	adc	dx, 0
  3894 0000163B 49                      	dec	cx
  3895 0000163C 75E6                    	jnz	short FAT32_f_10
  3896 0000163E 4B                      	dec	bx
  3897 0000163F 75E3                    	jnz	short FAT32_f_10
  3898                                  
  3899                                  	; If there are, format remain sectors which are
  3900                                  	; at beyond of data clusters, with zero bytes.
  3901                                  	
  3902 00001641 8B4E1C                  	mov	cx, [bp+1Ch]	; [BPB_HiddSec]
  3903 00001644 8B5E1E                  	mov	bx, [bp+1Eh]	; [BPB_HiddSec+2]
  3904                                  FAT16_f_18:	
  3905 00001647 034E20                  	add	cx, [bp+20h]	; [BPB_TotSec32]
  3906 0000164A 135E22                  	adc	bx, [bp+22h]	; [BPB_TotSec32+2]
  3907                                  FAT16_f_19:
  3908                                  FAT12_f_8:
  3909                                  	; are there remain sectors (in partition) ?
  3910 0000164D 29C1                    	sub	cx, ax
  3911 0000164F 19D3                    	sbb	bx, dx
  3912                                  	; 11/02/2019
  3913                                  	; BX must be 0 (Because, 1 cluster <= 32KB. So, 
  3914                                  	;	        remain sectors must not be more than 32K)
  3915 00001651 751C                    	jnz	short FAT32_f_12 ; There is a wrong thing !!!
  3916                                  				 ; If BX is not zero,	
  3917                                  				 ; it is better to skip this stage...)
  3918 00001653 09C9                    	or	cx, cx		
  3919 00001655 7418                    	jz	short FAT32_f_12 ; no.. 
  3920                                  				 ; (good! FAT contains all data sectors)
  3921                                  FAT32_f_11:
  3922 00001657 51                      	push	cx
  3923 00001658 BB[206B]                	mov	bx, HDFORMAT_EMPTY_BUFF
  3924 0000165B E83008                  	call	write_hd_sector
  3925 0000165E 0F827901                	jc	formatting_error
  3926 00001662 E82901                  	call	write_format_percent
  3927 00001665 59                      	pop	cx
  3928 00001666 83C001                  	add	ax, 1
  3929 00001669 83D200                  	adc	dx, 0
  3930 0000166C 49                      	dec	cx
  3931 0000166D 75E8                    	jnz	short FAT32_f_11
  3932                                  
  3933                                  FAT32_f_12:
  3934                                  SINGLIX_fs1_f_12:
  3935                                  	; End of FAT format routine...
  3936                                  end_of_formatting:
  3937 0000166F B064                    	mov	al, 100
  3938 00001671 E85301                  	call	write_format_percent_x
  3939                                  	;mov	si, CRLF
  3940                                  	;call	print_msg
  3941 00001674 BE[5C57]                	mov	si, Msg_OK
  3942 00001677 E80508                  	call	print_msg
  3943 0000167A E915FD                  	jmp	Exit
  3944                                  
  3945                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3946                                  ; set & write volume name
  3947                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3948                                  
  3949                                  write_fs_volume_name:
  3950 0000167D C606[0367]40            	mov	byte [vname_length], 64
  3951 00001682 EB05                    	jmp	short svn_fs
  3952                                  
  3953                                  write_volume_name:
  3954 00001684 C606[0367]0B            	mov	byte [vname_length], 11
  3955                                  svn_fs:
  3956                                  	; DI = (BS) Volume Label address
  3957 00001689 BE[FE56]                	mov	si, Msg_Volume_Name
  3958 0000168C E8F007                  	call	print_msg
  3959                                  
  3960                                  	; get cursor position
  3961                                  	; bh = 0  ; video page
  3962 0000168F B403                    	mov     ah, 3 ; get cursor pos
  3963 00001691 CD10                    	int     10h
  3964 00001693 8916[A456]              	mov	[Cursor_Pos], dx
  3965                                  
  3966 00001697 E89B08                  	call	rw_char
  3967 0000169A 7207                    	jc	short svn_1
  3968                                  svn_0:
  3969 0000169C AC                      	lodsb
  3970 0000169D 3C20                    	cmp	al, 20h
  3971 0000169F 7706                    	ja	short svn_2
  3972 000016A1 74F9                    	je	short svn_0 
  3973                                  svn_1:
  3974 000016A3 BE[0E67]                	mov	si, no_name
  3975 000016A6 AC                      	lodsb
  3976                                  svn_2:
  3977                                  	;mov	di, [bp+47h) ; [BS_VolLab] ; FAT32
  3978                                  	;mov	di, [bp+2Bh) ; [BS_VolLab] ; FAT16 (&FAT12)
  3979 000016A7 89FB                    	mov	bx, di ; *
  3980 000016A9 30ED                    	xor	ch, ch
  3981 000016AB 8A0E[0367]              	mov	cl, [vname_length] ; 11
  3982 000016AF EB05                    	jmp	short svn_4
  3983                                  svn_3:
  3984 000016B1 AC                      	lodsb
  3985 000016B2 3C20                    	cmp	al, 20h
  3986 000016B4 7226                    	jb	short svn_6
  3987                                  svn_4:
  3988 000016B6 AA                      	stosb
  3989 000016B7 E2F8                    	loop	svn_3
  3990                                  svn_5:
  3991 000016B9 8A0E[0367]              	mov	cl, [vname_length] ; 11
  3992 000016BD 89DE                    	mov	si, bx ; *
  3993 000016BF BF[BD56]                	mov	di, StrVolumeName
  3994 000016C2 F3A4                    	rep	movsb
  3995                                  	;mov	byte [di], 0
  3996                                  
  3997 000016C4 8B16[A456]              	mov	dx, [Cursor_Pos]
  3998 000016C8 BB0700                  	mov	bx, 7
  3999 000016CB B402                    	mov	ah, 2
  4000 000016CD CD10                    	int	10h  ; Set Cursor Position
  4001                                  
  4002 000016CF BE[BD56]                	mov	si, StrVolumeName
  4003 000016D2 E8AA07                  	call	print_msg
  4004 000016D5 BE[6057]                	mov	si, CRLF
  4005 000016D8 E8A407                  	call	print_msg
  4006 000016DB C3                      	retn
  4007                                  svn_6:
  4008 000016DC B020                    	mov	al, 20h
  4009                                  svn_7:
  4010 000016DE AA                      	stosb
  4011 000016DF E2FD                    	loop	svn_7
  4012 000016E1 EBD6                    	jmp	short svn_5
  4013                                  
  4014                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4015                                  ; set & write volume serial number (volume ID)
  4016                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4017                                  
  4018                                  write_volume_serial:
  4019                                  	; SI = (BS) Volume Serial Number (binary) address
  4020                                  
  4021                                  	;xor	ax, ax
  4022                                  	;int	1Ah			; get time of day
  4023                                  
  4024                                  	;mov	[si], dx
  4025                                  	;mov	[si+2], cx		; set unique volume ID
  4026                                  
  4027                                  	;mov	ah, 02h			; Return Current Time
  4028                                  	;int	1Ah
  4029                                  	;xchg	ch, cl
  4030                                  	;xchg	dh, dl
  4031                                  
  4032                                  	;add	cx, dx  
  4033                                  	;add	[si+2], cx
  4034                                                 
  4035                                  	;mov	ah, 04h			; Return Current Date
  4036                                  	;int	1Ah
  4037                                  
  4038                                  	;xchg	ch,cl
  4039                                  	;xchg	dh,dl
  4040                                  
  4041                                  	;add	cx, dx  
  4042                                  	;add	[si+2], cx
  4043                                  
  4044                                  	; According to Microsoft DOS 6.0 serial number
  4045                                  	; production method...
  4046                                  	; < Create unique 32 bit serial number >
  4047                                  
  4048                                  	; Create_Serial_ID (MSDOS 6.0 Source code, MSFOR.ASM)
  4049                                  	; (20/04/1987)
  4050                                  	;
  4051                                  	;  Get date (INT 21h, AH=2Bh)
  4052                                  	;  Get time (INT 21h, AH=2Ch)
  4053                                  	;  Serial_ID+0 = DX reg date + DX reg time
  4054                                  	;  Serial_ID+2 = CX reg date + CX reg time
  4055                                  	;  Serial_Num_Low = Serial_ID+2
  4056                                  	;  Serial_Num_High = Serial_ID+0
  4057                                  
  4058 000016E3 B404                    	mov	ah, 04h		; Return Current Date
  4059 000016E5 CD1A                    	int	1Ah
  4060                                  
  4061                                  	; DL = Day (BCD)	(20h) 	
  4062                                  	; DH = Month (BCD)	(12h)
  4063                                  	; CH = Century (BCD)	(20h)
  4064                                  	; CL = Year (BCD) 	(17h)
  4065                                  
  4066 000016E7 88D0                    	mov	al, dl
  4067 000016E9 E87100                  	call	bcd_to_bin
  4068 000016EC 88C2                    	mov	dl, al 
  4069 000016EE 88F0                    	mov	al, dh
  4070 000016F0 E86A00                  	call	bcd_to_bin
  4071 000016F3 88C6                    	mov	dh, al 
  4072 000016F5 88C8                    	mov	al, cl
  4073 000016F7 E86300                  	call	bcd_to_bin
  4074 000016FA 88C1                    	mov	cl, al 
  4075 000016FC 88E8                    	mov	al, ch
  4076 000016FE E85C00                  	call	bcd_to_bin
  4077 00001701 88C5                    	mov	ch, al
  4078                                  
  4079                                  	; DH = Month (1-10)
  4080                                  	; DL = Day (1-31)
  4081                                  	; CX = Year (1900-2099)
  4082                                  
  4083 00001703 52                      	push	dx 
  4084 00001704 51                      	push	cx
  4085                                  
  4086 00001705 B402                    	mov	ah, 02h		; Return Current Time
  4087 00001707 CD1A                    	int	1Ah
  4088                                  	
  4089                                  	; DH = Seconds (BCD)	(59h) 	
  4090                                  	; CL = Minutes (BCD)	(59h)
  4091                                  	; CH = Hours (BCD)	(23h)
  4092                                  	; DL = Daylight savings time option (1=yes)
  4093                                  
  4094 00001709 88F0                    	mov	al, dh
  4095 0000170B E84F00                  	call	bcd_to_bin
  4096 0000170E 88C6                    	mov	dh, al 
  4097 00001710 88C8                    	mov	al, cl
  4098 00001712 E84800                  	call	bcd_to_bin
  4099 00001715 88C1                    	mov	cl, al 
  4100 00001717 88E8                    	mov	al, ch
  4101 00001719 E84100                  	call	bcd_to_bin
  4102 0000171C 88C5                    	mov	ch, al 
  4103                                  
  4104                                  	; CH = Hour (0-23)
  4105                                  	; CL = Minutes (0-59)
  4106                                  	; DH = Seconds (0-59)
  4107                                  	; ((DL = Hundredths (0-99) - MSDOS!))
  4108                                  	; DL = 0 or 1 (here!)
  4109                                  
  4110 0000171E 89C8                    	mov	ax, cx
  4111 00001720 59                      	pop	cx
  4112 00001721 01C8                    	add	ax, cx
  4113                                  
  4114 00001723 894402                  	mov	[si+2], ax
  4115                                  
  4116 00001726 89D0                    	mov	ax, dx
  4117 00001728 5A                      	pop	dx
  4118 00001729 01D0                    	add	ax, dx
  4119                                  
  4120 0000172B 8904                    	mov	[si], ax
  4121                                  
  4122 0000172D 30E4                    	xor	ah, ah		; Read time counter
  4123 0000172F CD1A                    	int	1Ah
  4124                                  
  4125                                  	; CX = High word of clock count
  4126                                  	; DX = Low word of clock count
  4127                                  	; AL = 0 if 24 hours has not passed, else 1
  4128                                  
  4129                                  	; NOTES: 
  4130                                  	; (Ref: vitaly_filatov.tripod.com/ng/asm/asm_029.1.html)
  4131                                  	;
  4132                                     	; Following formulas convert the clock count to
  4133                                          ; the time of day:
  4134                                   	;	Hour      = Clock / 65543 (1007h)
  4135                                  	;	Remainder = Clock MOD 65543
  4136                                   	;
  4137                                  	;	Minutes   = Remainder / 1092 (444h)
  4138                                  	;	Remainder = Remainder MOD 1092
  4139                                  	;
  4140                                  	;	Second    = Remainder / 18.21
  4141                                  	;	Remainder = Remainder MOD 18.21
  4142                                  	;
  4143                                  	;	Hundredths = CINT(Remainder * 100)
  4144                                  
  4145 00001731 0014                    	add	[si], dl
  4146                                  
  4147                                  	; SI = Volume serial number address (4 bytes) 
  4148 00001733 8A04                    	mov	al, [si]
  4149 00001735 E8E607                  	call	bin_to_hex
  4150 00001738 A3[2957]                	mov	[Vol_Serial2+2], ax	
  4151 0000173B 8A4401                  	mov	al, [si+1]
  4152 0000173E E8DD07                  	call	bin_to_hex
  4153 00001741 A3[2757]                	mov	[Vol_Serial2], ax
  4154 00001744 8A4402                  	mov	al, [si+2]
  4155 00001747 E8D407                  	call	bin_to_hex
  4156 0000174A A3[2457]                	mov	[Vol_Serial1+2], ax	
  4157 0000174D 8A4403                  	mov	al, [si+3]
  4158 00001750 E8CB07                  	call	bin_to_hex
  4159 00001753 A3[2257]                	mov	[Vol_Serial1], ax
  4160                                  
  4161 00001756 BE[1057]                	mov	si, Msg_Volume_Serial
  4162 00001759 E82307                  	call	print_msg
  4163                                  
  4164 0000175C C3                      	retn
  4165                                  
  4166                                  bcd_to_bin:
  4167 0000175D 53                      	push	bx
  4168 0000175E D410                    	db	0D4h,10h  ; Undocumented inst. AAM
  4169                                  			  ; AH = AL / 10h
  4170                                  			  ; AL = AL MOD 10h
  4171 00001760 88C3                    	mov	bl, al
  4172 00001762 B00A                    	mov	al, 10
  4173 00001764 F6E4                    	mul	ah
  4174 00001766 00D8                    	add	al, bl
  4175 00001768 5B                      	pop	bx
  4176 00001769 C3                      	retn
  4177                                  
  4178                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4179                                  ; write formatting percentage
  4180                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4181                                  
  4182                                  write_formatting_msg:
  4183                                  	;mov	ax, [pp_Sectors]
  4184                                  	;mov	dx, [pp_Sectors+2]
  4185                                  	; 16/02/2019
  4186 0000176A A1[DC6F]                	mov	ax, [ppn_Sectors]
  4187 0000176D 8B16[DE6F]              	mov	dx, [ppn_Sectors+2]
  4188                                  
  4189                                  	; DX_AX = Total sectors for percentage  
  4190 00001771 B96400                  	mov	cx, 100	
  4191 00001774 E8FBF6                  	call	div32
  4192 00001777 A3[2E6D]                	mov	[format_percent], ax
  4193                                  
  4194 0000177A BE[4857]                	mov	si, msg_formatting
  4195 0000177D E8FF06                  	call	print_msg
  4196                                  
  4197                                  	; get cursor position
  4198                                  	; bh = 0  ; video page
  4199 00001780 B403                    	mov     ah, 3 ; get cursor pos
  4200 00001782 CD10                    	int     10h
  4201 00001784 8916[A456]              	mov	[Cursor_Pos], dx
  4202                                  
  4203 00001788 C606[306D]FF            	mov	byte [prev_percent], 255
  4204                                  
  4205 0000178D C3                      	retn
  4206                                  
  4207                                  write_format_percent:
  4208                                  	; DX_AX = Current sector (which has been written)
  4209                                  
  4210 0000178E 50                      	push	ax
  4211 0000178F 52                      	push	dx
  4212 00001790 53                      	push	bx
  4213 00001791 51                      	push	cx
  4214 00001792 56                      	push	si
  4215                                  
  4216 00001793 2B461C                  	sub	ax, [bp+1Ch]	; [BPB_HiddSec]
  4217 00001796 1B561E                  	sbb	dx, [bp+1Eh]	; [BPB_HiddSec+2]
  4218                                  wpc_t:
  4219 00001799 8B0E[2E6D]              	mov	cx, [format_percent]
  4220 0000179D E8D2F6                  	call	div32
  4221                                  	; AL = percentage value between 1 to 100
  4222                                  wpc_x:
  4223 000017A0 3A06[306D]              	cmp	al, [prev_percent]
  4224 000017A4 741B                    	je	short wpc_y
  4225 000017A6 A2[306D]                	mov	[prev_percent], al
  4226 000017A9 8B16[A456]              	mov	dx, [Cursor_Pos]
  4227 000017AD BB0700                  	mov	bx, 7
  4228 000017B0 B402                    	mov	ah, 2
  4229 000017B2 CD10                    	int	10h  ; Set Cursor Position
  4230 000017B4 31D2                    	xor	dx, dx
  4231 000017B6 30E4                    	xor	ah, ah
  4232                                  	;mov	al, [prev_percent]
  4233 000017B8 BE[5657]                	mov	si, format_percent_str + 2
  4234 000017BB E84907                  	call	bin_to_decimal
  4235 000017BE E8BE06                  	call	print_msg
  4236                                  wpc_y:
  4237 000017C1 5E                      	pop	si
  4238 000017C2 59                      	pop	cx
  4239 000017C3 5B                      	pop	bx
  4240 000017C4 5A                      	pop	dx
  4241 000017C5 58                      	pop	ax
  4242 000017C6 C3                      	retn
  4243                                  
  4244                                  write_format_percent_x:
  4245                                  	; AL = % number
  4246                                  
  4247 000017C7 50                      	push	ax
  4248 000017C8 52                      	push	dx
  4249 000017C9 53                      	push	bx
  4250 000017CA 51                      	push	cx
  4251 000017CB 56                      	push	si
  4252                                  
  4253 000017CC EBD2                    	jmp	short wpc_x
  4254                                  
  4255                                  write_fs_format_percent:
  4256                                  	; DX_AX = Current sector (which has been written)
  4257                                  
  4258 000017CE 50                      	push	ax
  4259 000017CF 52                      	push	dx
  4260 000017D0 53                      	push	bx
  4261 000017D1 51                      	push	cx
  4262 000017D2 56                      	push	si
  4263                                  
  4264 000017D3 2B460C                  	sub	ax, [bp+0Ch]	; [bsBeginSector]
  4265 000017D6 1B560E                  	sbb	dx, [bp+0Eh]	; [bsBeginSector+2]
  4266 000017D9 EBBE                    	jmp	short wpc_t	
  4267                                  	
  4268                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4269                                  ; format error 
  4270                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4271                                  
  4272                                  formatting_error:
  4273 000017DB 8B26[1E6B]              	mov	sp, [old_sp]
  4274                                  
  4275 000017DF 88E0                    	mov	al, ah ;  error code
  4276 000017E1 E83A07                  	call	bin_to_hex
  4277 000017E4 A3[6E57]                	mov 	[error_code], ax
  4278                                  
  4279 000017E7 BE[6057]                	mov	si, CRLF
  4280 000017EA E89206                  	call	print_msg
  4281                                  
  4282 000017ED BE[6357]                	mov	si, Msg_Error
  4283 000017F0 E88C06                  	call	print_msg
  4284 000017F3 E99CFB                  	jmp	Exit
  4285                                  
  4286                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4287                                  ; write cluster count
  4288                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4289                                  
  4290                                  write_cluster_count:
  4291 000017F6 BE[2E57]                	mov	si, msg_cluster_count
  4292 000017F9 E88306                  	call	print_msg
  4293 000017FC A1[286D]                	mov	ax, [cluster_count]
  4294 000017FF 8B16[2A6D]              	mov	dx, [cluster_count+2]
  4295 00001803 BE[4457]                	mov	si, cluster_count_str+6
  4296 00001806 E8FE06                  	call	bin_to_decimal
  4297 00001809 E87306                  	call	print_msg
  4298 0000180C C3                      	retn 
  4299                                  
  4300                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4301                                  ; FAT16 FORMATTING
  4302                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4303                                  	; 08/02/2019 (Modified for -only- FAT16 CHS partitions) 
  4304                                  FAT16_hdi_format:
  4305 0000180D B80607                  	mov	ax, 0706h ; db 06h, 07h ; 'push es, pop es'
  4306 00001810 38C2                    	cmp	dl, al ; 06h ; Big CHS partition (>= 32MB)
  4307 00001812 7403                    	je	short FAT16_big_chs_format
  4308                                  	;mov	ax, 070Eh ; db 0Eh, 07h	; 'push cs, pop es'
  4309                                  	;cmp	dl, al ; 0Eh ; LBA partition
  4310                                  	;je	short FAT16_lba_format
  4311                                  FAT16_chs_format:  
  4312                                  	; Partition Type: 04h, CHS (<32 MB) partition
  4313 00001814 B80400                  	mov	ax, 0004h ; db 04h, 00h ; 'add al, 0'
  4314                                  FAT16_big_chs_format:
  4315                                  ;FAT16_lba_format:
  4316                                  	; Put TRDOS 386 FAT16 partition magic word 
  4317                                  	; at offset 3Eh, in TRDOS386 FAT16 boot sector.
  4318 00001817 BD[9339]                	mov	bp, TRDOS_FAT16_hd_bs
  4319 0000181A 8D7E03                  	lea	di, [bp+3]
  4320 0000181D BE[0467]                	mov	si, bs_oem_name
  4321 00001820 B90400                  	mov	cx, 4
  4322 00001823 F3A5                    	rep	movsw 
  4323 00001825 89463E                  	mov	[bp+3Eh], ax	; [loc_3E]
  4324                                  
  4325 00001828 A1[A641]                	mov	ax, [sectors]
  4326 0000182B 894618                  	mov	[bp+18h], ax	; [BPB_SecPerTrk]
  4327 0000182E A1[A841]                	mov	ax, [heads]
  4328 00001831 89461A                  	mov	[bp+1Ah], ax	; [BPB_NumHeads]
  4329 00001834 A1[A86F]                	mov	ax, [pp_StartSector]
  4330 00001837 89461C                  	mov	[bp+1Ch], ax	; [BPB_HiddSec]
  4331 0000183A A1[AA6F]                	mov	ax, [pp_StartSector+2]
  4332 0000183D 89461E                  	mov	[bp+1Eh], ax	; [BPB_HiddSec+2]
  4333                                  	;mov	ax, [pp_Sectors]
  4334 00001840 A1[DC6F]                	mov	ax, [ppn_Sectors] ; 16/02/2019
  4335                                  	;mov	dx, [pp_Sectors+2]
  4336 00001843 8B16[DE6F]              	mov	dx, [ppn_Sectors+2] ; 16/02/2019
  4337 00001847 21D2                    	and	dx, dx
  4338 00001849 7505                    	jnz	short FAT16_f_0
  4339 0000184B 894613                  	mov	[bp+13h], ax	; [BPB_TotSec16]
  4340                                  	; CX = 0
  4341                                  	;mov	[bp+20h], cx	; [BPB_TotSec32] =  0
  4342                                  	;mov	[bp+22h], cx	; [BPB_TotSec32+2] = 0
  4343 0000184E EB06                    	jmp	short FAT16_f_1
  4344                                  FAT16_f_0:
  4345 00001850 894620                  	mov	[bp+20h], ax	; [BPB_TotSec32]
  4346                                  	;;mov	dx, [pp_Sectors+2]
  4347                                  	;mov	dx, [ppn_Sectors+2] ; 16/02/2019 
  4348 00001853 895622                  	mov	[bp+22h], dx	; [BPB_TotSec32+2]
  4349                                  	; CX = 0
  4350                                  	;mov	[bp+13h], cx ; [BPB_TotSec16] = 0
  4351                                  FAT16_f_1:
  4352                                  	; Sectors per cluster calculation
  4353                                  	; (According to MS FAT32 FS specification.)
  4354 00001856 B102                    	mov	cl, 2  ; 2 sectors per cluster
  4355 00001858 09D2                    	or	dx, dx
  4356 0000185A 7507                    	jnz	short FAT16_f_2 ; >2 sectors (>16MB)
  4357 0000185C 3DA87F                  	cmp	ax, 32680
  4358 0000185F 763C                    	jna	short FAT16_f_10 ; 2 sectors, <=16MB
  4359                                  	; > 16MB
  4360 00001861 EB38                    	jmp	short FAT16_f_9 ; 4 sectors per cluster
  4361                                  FAT16_f_2:
  4362 00001863 83FA04                  	cmp	dx, 4  ; >= 262144 sectors ; >=128MB
  4363 00001866 7708                    	ja	short FAT16_f_3 ; >4 sectors per cluster
  4364 00001868 7231                    	jb	short FAT16_f_9 ; 4 sectors per cluster	
  4365 0000186A 09C0                    	or	ax, ax ; dx_ax = (4*65536)+0
  4366 0000186C 742D                    	jz	short FAT16_f_9 ; 4 sectors per cluster
  4367 0000186E EB29                    	jmp	short FAT16_f_8 ; 8 sectors per cluster
  4368                                  FAT16_f_3:
  4369 00001870 83FA08                  	cmp	dx, 8  ; >= 524288 sectors ; >=256MB
  4370 00001873 7708                    	ja	short FAT16_f_4 ; >8 sectors per cluster
  4371 00001875 7222                    	jb	short FAT16_f_8 ; 8 sectors per cluster	
  4372 00001877 21C0                    	and	ax, ax ; dx_ax = (8*65536)+0
  4373 00001879 741E                    	jz	short FAT16_f_8 ; 8 sectors per cluster
  4374 0000187B EB1A                    	jmp	short FAT16_f_7 ; 16 sectors per cluster
  4375                                  FAT16_f_4:
  4376 0000187D 83FA10                  	cmp	dx, 16 ; >= 1048576 sectors ; >=512MB
  4377 00001880 7708                    	ja	short FAT16_f_5 ; >16 sectors per cluster
  4378 00001882 7213                    	jb	short FAT16_f_7 ; 16 sectors per cluster	
  4379 00001884 21C0                    	and	ax, ax ; dx_ax = (16*65536)+0
  4380 00001886 740F                    	jz	short FAT16_f_7 ; 16 sectors per cluster
  4381 00001888 EB0B                    	jmp	short FAT16_f_6 ; 32 sectors per cluster
  4382                                  FAT16_f_5:
  4383 0000188A 83FA20                  	cmp	dx, 32 ; >= 2097152 sectors ; >=1GB
  4384 0000188D 7206                    	jb	short FAT16_f_6 ; 32 sectors per cluster
  4385 0000188F 09C0                    	or	ax, ax		; dx_ax = (32*65536)+0
  4386 00001891 7402                    	jz	short FAT16_f_6 ; 32 sectors per cluster
  4387                                  	; >1GB (<=2GB)
  4388                                  	; 64 sectors per cluster
  4389 00001893 D0E1                    	shl	cl, 1
  4390                                  FAT16_f_6:
  4391                                  	; 32 sectors per cluster (for <= 2GB volumes)
  4392 00001895 D0E1                    	shl	cl, 1	
  4393                                  FAT16_f_7:
  4394                                  	; 16 sectors per cluster (for <= 1GB volumes)
  4395 00001897 D0E1                    	shl	cl, 1
  4396                                  FAT16_f_8:
  4397                                  	; 8 sectors per cluster (for <= 512MB volumes)
  4398 00001899 D0E1                    	shl	cl, 1	
  4399                                  FAT16_f_9:
  4400                                  	; 4 sectors per cluster (for <= 256MB volumes)
  4401 0000189B D0E1                    	shl	cl, 1	
  4402                                  FAT16_f_10:	
  4403                                  	; 2 sectors per cluster (for <= 128MB volumes)
  4404 0000189D 884E0D                  	mov	[bp+0Dh], cl	 ; [BPB_SecPerClus]
  4405                                  	;mov	byte [bp+10h], 2 ; [BPB_NumFATs] 
  4406                                  	;mov	word [bp+0Eh], 1 ; [BPB_RsvdSecCnt] 
  4407                                  	;mov	word [bp+11h], 512 ; [BPB_RootEntCnt]
  4408                                  	
  4409                                  	; Calculating FAT size in sectors
  4410                                  	; (According to MS FAT32 FS Specification, 2000)
  4411                                  
  4412                                  	; DX_AX = partition (volume) size in sectors
  4413 000018A0 8B5E11                  	mov	bx, [bp+11h]	; [BPB_RootEntCnt] = 512
  4414 000018A3 83C30F                  	add	bx, 15 ; bx = 527
  4415 000018A6 C1EB04                  	shr	bx, 4 ; /16 = 527/16 = 32
  4416                                  		; ((32*BX)+511)/512
  4417 000018A9 891E[2C6D]              	mov	[root_dir_secs], bx
  4418 000018AD 035E0E                  	add	bx, [bp+0Eh]	; [BPB_RsvdSecCnt] ; 1
  4419 000018B0 29D8                    	sub	ax, bx
  4420 000018B2 83DA00                  	sbb	dx, 0
  4421                                  		; TmpVal1 = DiskSize - (BPB_ResvdSecCnt +
  4422                                  		;	     		RootDirsectors)
  4423                                  	;mov	bx, cx ; ch = 0
  4424                                  	;shl	bx, 8 ; * 256
  4425                                  	; 11/02/2019
  4426 000018B5 88CF                    	mov	bh, cl
  4427 000018B7 30DB                    	xor	bl, bl
  4428 000018B9 B102                    	mov	cl, 2 ; [BPB_NumFATs] 
  4429 000018BB 01CB                    	add	bx, cx	
  4430                                  		; TmpVal2 = (256*BPB_SecPerClus)+BPB_NumFATs
  4431 000018BD 89D9                    	mov	cx, bx
  4432 000018BF 4B                      	dec	bx  ; TmpVal2-1
  4433 000018C0 01D8                    	add	ax, bx
  4434 000018C2 83D200                  	adc	dx, 0
  4435 000018C5 E8AAF5                  	call	div32
  4436                                  		; FATSz = (TmpVal1+(TmpVal2-1))/TmpVal2
  4437                                  	; AX = FAT size in sectors
  4438                                  	; DX = 0
  4439 000018C8 894616                  	mov	[bp+16h], ax	; [BPB_FATSz16]
  4440                                  	; * 2
  4441 000018CB D1E0                    	shl	ax, 1
  4442                                  	; AX = [BPB_NumFATs] * [BPB_FATSz16]
  4443 000018CD 8B4E0E                  	mov	cx, [bp+0Eh]	; [BPB_RsvdSecCnt] ; 1
  4444 000018D0 01C1                    	add	cx, ax
  4445                                  	; CX = [BPB_RsvdSecCnt]+([BPB_NumFATs]*[BPB_FATSz16])
  4446 000018D2 030E[2C6D]              	add	cx, [root_dir_secs] ; + RootDirsectors
  4447 000018D6 29DB                    	sub	bx, bx ; BX = 0
  4448                                  	; BX_CX = [BPB_RsvdSecCnt]+([BPB_NumFATs]*[BPB_FATSz16])
  4449                                  	;	  + RootDirSectors
  4450 000018D8 8B4613                  	mov	ax, [bp+13h]	; [BPB_TotSec16]
  4451                                  	;sub	dx, dx 
  4452                                  	; DX = 0
  4453 000018DB 21C0                    	and	ax, ax
  4454 000018DD 7506                    	jnz	short FAT16_f_11
  4455 000018DF 8B4620                  	mov	ax, [bp+20h]	; [BPB_TotSec32]
  4456 000018E2 8B5622                  	mov	dx, [bp+22h]	; [BPB_TotSec32+2]
  4457                                  FAT16_f_11:
  4458 000018E5 29C8                    	sub	ax, cx
  4459 000018E7 19DA                    	sbb	dx, bx
  4460 000018E9 890E[206D]              	mov	[data_start], cx
  4461 000018ED 891E[226D]              	mov	[data_start+2], bx
  4462                                  	; DX_AX = Data sectors
  4463 000018F1 A3[246D]                	mov	[data_sectors], ax
  4464 000018F4 8916[266D]              	mov	[data_sectors+2], dx
  4465 000018F8 8A4E0D                  	mov	cl, [bp+0Dh]	 ; [BPB_SecPerClus]
  4466 000018FB 30ED                    	xor	ch, ch
  4467 000018FD E872F5                  	call	div32 ; DX_AX/CX
  4468                                  	; AX = Count of clusters (rounded down)
  4469                                  	; DX = 0
  4470 00001900 A3[286D]                	mov	[cluster_count], ax
  4471 00001903 8916[2A6D]              	mov	[cluster_count+2], dx
  4472                                  
  4473 00001907 8D7E2B                  	lea	di, [bp+43] ; [BS_VolLab]
  4474 0000190A E877FD                  	call	write_volume_name
  4475 0000190D 8D7627                  	lea	si, [bp+39] ; [BS_VolID]
  4476 00001910 E8D0FD                  	call	write_volume_serial
  4477 00001913 E8E0FE                  	call	write_cluster_count	
  4478                                  
  4479 00001916 E851FE                  	call	write_formatting_msg
  4480 00001919 B000                    	mov	al, 0
  4481 0000191B E8A9FE                  	call	write_format_percent_x
  4482                                  
  4483 0000191E 8B461C                  	mov	ax, [bp+1Ch]	; [BPB_HiddSec]
  4484 00001921 8B561E                  	mov	dx, [bp+1Eh]	; [BPB_HiddSec+2]
  4485                                  
  4486 00001924 0106[206D]              	add	[data_start], ax
  4487 00001928 1116[226D]              	adc	[data_start+2], dx
  4488                                  
  4489                                  	; DX_AX = FAT16 Boot Sector address
  4490 0000192C BB[9339]                	mov	bx, TRDOS_FAT16_hd_bs
  4491                                  	; ES:BX = Boot Sector Buffer
  4492 0000192F E85C05                  	call	write_hd_sector
  4493 00001932 0F82A5FE                	jc	formatting_error
  4494 00001936 E855FE                  	call	write_format_percent
  4495 00001939 83C001                  	add	ax, 1
  4496 0000193C 83D200                  	adc	dx, 0
  4497                                  	; write remain part of reserved sectors
  4498 0000193F 8B4E0E                  	mov	cx, [bp+0Eh] ; [BPB_RsvdSecCnt]
  4499                                  	;sub	cx, 1
  4500                                  	;jna	short FAT16_f_13
  4501                                  	; 11/02/2019
  4502 00001942 49                      	dec	cx
  4503 00001943 7418                    	jz	short FAT16_f_13
  4504                                  FAT16_f_12:
  4505 00001945 51                      	push	cx
  4506 00001946 BB[206B]                	mov	bx, HDFORMAT_EMPTY_BUFF
  4507 00001949 E84205                  	call	write_hd_sector
  4508 0000194C 0F828BFE                	jc	formatting_error
  4509 00001950 E83BFE                  	call	write_format_percent
  4510 00001953 83C001                  	add	ax, 1
  4511 00001956 83D200                  	adc	dx, 0
  4512 00001959 59                      	pop	cx
  4513 0000195A 49                      	dec	cx ; dec cl
  4514 0000195B 75E8                    	jnz	short FAT16_f_12
  4515                                  FAT16_f_13:
  4516                                  	; write FAT sectors
  4517 0000195D 8B0E[206D]              	mov	cx, [data_start] ; lba/abs addr
  4518 00001961 8B1E[226D]              	mov	bx, [data_start+2] ; lba/abs addr
  4519                                  
  4520                                  	; 11/02/2019
  4521 00001965 2B0E[2C6D]              	sub	cx, [root_dir_secs]
  4522 00001969 83DB00                  	sbb	bx, 0
  4523                                  
  4524 0000196C 53                      	push	bx
  4525 0000196D 51                      	push	cx
  4526 0000196E BB[206B]                	mov	bx, HDFORMAT_FATBUFFER
  4527                                  	; ES:BX = FAT Sector Buffer
  4528 00001971 8A4E15                  	mov	cl, [bp+15h] ; [BPB_Media]
  4529 00001974 B5FF                    	mov	ch, 0FFh
  4530 00001976 890F                    	mov	[bx], cx ; 0FFF8h
  4531 00001978 88E9                    	mov	cl, ch ; cx = 0FFFFh
  4532 0000197A 894F02                  	mov	[bx+2], cx
  4533                                  	;inc	cx
  4534 0000197D E80E05                  	call	write_hd_sector
  4535 00001980 0F8257FE                	jc	formatting_error
  4536 00001984 E807FE                  	call	write_format_percent
  4537                                  	;mov	bx, HDFORMAT_FATBUFFER
  4538 00001987 B90000                  	mov	cx, 0
  4539 0000198A 890F                    	mov	[bx], cx
  4540 0000198C 894F02                  	mov	[bx+2], cx
  4541 0000198F EB0F                    	jmp	short FAT16_f_15
  4542                                  FAT16_f_14:	
  4543 00001991 53                      	push	bx
  4544 00001992 51                      	push	cx	
  4545 00001993 BB[206B]                	mov	bx, HDFORMAT_FATBUFFER
  4546 00001996 E8F504                  	call	write_hd_sector
  4547 00001999 0F823EFE                	jc	formatting_error
  4548 0000199D E8EEFD                  	call	write_format_percent
  4549                                  FAT16_f_15:	
  4550 000019A0 59                      	pop	cx
  4551 000019A1 5B                      	pop	bx
  4552 000019A2 83C001                  	add	ax, 1
  4553 000019A5 83D200                  	adc	dx, 0
  4554 000019A8 39DA                    	cmp	dx, bx
  4555 000019AA 72E5                    	jb	short FAT16_f_14
  4556 000019AC 39C8                    	cmp	ax, cx
  4557 000019AE 72E1                    	jb	short FAT16_f_14
  4558                                  
  4559                                  	; write	root directory sectors
  4560                                  	; as empty sectors
  4561 000019B0 8B0E[2C6D]              	mov	cx, [root_dir_secs]
  4562                                  FAT16_f_16:
  4563 000019B4 51                      	push	cx
  4564 000019B5 BB[206B]                	mov	bx, HDFORMAT_EMPTY_BUFF
  4565 000019B8 E8D304                  	call	write_hd_sector
  4566 000019BB 0F821CFE                	jc	formatting_error
  4567 000019BF E8CCFD                  	call	write_format_percent
  4568 000019C2 83C001                  	add	ax, 1
  4569 000019C5 83D200                  	adc	dx, 0
  4570 000019C8 59                      	pop	cx
  4571 000019C9 49                      	dec	cx
  4572 000019CA 75E8                    	jnz	short FAT16_f_16	
  4573                                  
  4574                                  	; write DATA sectors 
  4575                                  	; (after root directory sectors)
  4576 000019CC 8B0E[246D]              	mov	cx, [data_sectors]
  4577 000019D0 8B1E[266D]              	mov	bx, [data_sectors+2]
  4578                                  	; 11/02/2019
  4579 000019D4 43                      	inc	bx ; 0 -> 1, 1-> 2
  4580                                  FAT16_f_17:	
  4581 000019D5 53                      	push	bx
  4582 000019D6 51                      	push	cx	
  4583 000019D7 BB[1A67]                	mov	bx, HDFORMAT_SECBUFFER
  4584 000019DA E8B104                  	call	write_hd_sector
  4585 000019DD 0F82FAFD                	jc	formatting_error
  4586 000019E1 E8AAFD                  	call	write_format_percent
  4587 000019E4 59                      	pop	cx
  4588 000019E5 5B                      	pop	bx
  4589 000019E6 83C001                  	add	ax, 1
  4590 000019E9 83D200                  	adc	dx, 0
  4591 000019EC 49                      	dec	cx
  4592 000019ED 75E6                    	jnz	short FAT16_f_17
  4593 000019EF 4B                      	dec	bx
  4594 000019F0 75E3                    	jnz	short FAT16_f_17
  4595                                  
  4596                                  	; If there are, format remain sectors which are
  4597                                  	; at beyond of data clusters, with zero bytes.
  4598                                  	
  4599 000019F2 8B4E1C                  	mov	cx, [bp+1Ch]	; [BPB_HiddSec]
  4600 000019F5 8B5E1E                  	mov	bx, [bp+1Eh]	; [BPB_HiddSec+2]
  4601                                  
  4602 000019F8 837E1300                	cmp	word [bp+13h], 0 ; [BPB_TotSec16]
  4603 000019FC 0F8447FC                	jz	FAT16_f_18
  4604 00001A00 034E13                  	add	cx, [bp+13h]	; [BPB_TotSec16]
  4605 00001A03 83D300                  	adc	bx, 0
  4606 00001A06 E944FC                  	jmp	FAT16_f_19
  4607                                  
  4608                                  FAT12_hdi_format:
  4609 00001A09 BD[933B]                	mov	bp, TRDOS_FAT12_hd_bs
  4610 00001A0C 8D7E03                  	lea	di, [bp+3]
  4611 00001A0F BE[0467]                	mov	si, bs_oem_name
  4612 00001A12 B90400                  	mov	cx, 4
  4613 00001A15 F3A5                    	rep	movsw 
  4614 00001A17 A1[A641]                	mov	ax, [sectors]
  4615 00001A1A 894618                  	mov	[bp+18h], ax	; [BPB_SecPerTrk]
  4616 00001A1D A1[A841]                	mov	ax, [heads]
  4617 00001A20 89461A                  	mov	[bp+1Ah], ax	; [BPB_NumHeads]
  4618 00001A23 A1[A86F]                	mov	ax, [pp_StartSector]
  4619 00001A26 89461C                  	mov	[bp+1Ch], ax	; [BPB_HiddSec]
  4620 00001A29 A1[AA6F]                	mov	ax, [pp_StartSector+2]
  4621 00001A2C 89461E                  	mov	[bp+1Eh], ax	; [BPB_HiddSec+2]
  4622                                  	;mov	ax, [pp_Sectors]
  4623 00001A2F A1[DC6F]                	mov	ax, [ppn_Sectors] ; 16/02/2019
  4624 00001A32 894613                  	mov	[bp+13h], ax	; [BPB_TotSec16]
  4625                                  
  4626                                  	; 11/02/2019
  4627 00001A35 31F6                    	xor	si, si ; reset (FAT size fix) flag
  4628 00001A37 8B4E0E                  	mov	cx, [bp+0Eh]	; [BPB_RsvdSecCnt] ; 1
  4629 00001A3A 8B5611                  	mov	dx, [bp+11h]	; [BPB_RootEntCnt] = 512
  4630 00001A3D 83C20F                  	add	dx, 15	; (16-1) (512-1)
  4631 00001A40 C1EA04                  	shr	dx, 4	; /16  (*32/512)
  4632                                  	; AX = Root dir sectors
  4633                                  	; CX = [BPB_RsvdSecCnt]+([BPB_NumFATs]*[BPB_FATSz16])
  4634 00001A43 01D1                    	add	cx, dx ; + RootDirsectors ; + 32
  4635 00001A45 890E[2C6D]              	mov	[root_dir_secs], cx ; = 33
  4636                                  
  4637                                  	; 11/02/2019
  4638                                  	;sub	ax, 33  ; 1 reserved sector, 32 root dir sectors
  4639                                  			; .. now AX has number of data sectors
  4640                                  			;	 		+ 2* (FAT sectors)
  4641 00001A49 29C8                    	sub	ax, cx	
  4642                                  FAT12_f_10:	; 11/02/2019
  4643                                  	; Sectors per cluster calculation
  4644                                  	; (According to MS FAT32 FS specification.)
  4645                                  	;mov	cx, 1  ; 1 sector per cluster
  4646 00001A4B B101                    	mov	cl, 1  ; CH = 0
  4647                                  FAT12_f_0:
  4648 00001A4D 3DF50F                  	cmp	ax, 4085 ; Max. cluster count for FAT12
  4649 00001A50 7206                    	jb	short FAT12_f_1
  4650 00001A52 D0E1                    	shl	cl, 1 ; *2
  4651 00001A54 D1E8                    	shr	ax, 1 ; /2
  4652 00001A56 EBF5                    	jmp	short FAT12_f_0
  4653                                  FAT12_f_1:
  4654 00001A58 884E0D                  	mov	[bp+0Dh], cl	 ; [BPB_SecPerClus]
  4655                                  	;mov	byte [bp+10h], 2 ; [BPB_NumFATs] 
  4656                                  	;mov	word [bp+0Eh], 1 ; [BPB_RsvdSecCnt] 
  4657                                  	;mov	word [bp+11h], 512 ; [BPB_RootEntCnt]
  4658                                  	
  4659                                  	; Calculating FAT size in sectors
  4660                                  	; AX = partition (volume) size in sectors
  4661                                  	; CX = sectors per clusters
  4662 00001A5B 31D2                    	xor	dx, dx
  4663 00001A5D F7F1                    	div	cx
  4664                                  	; AX = cluster count (only for FAT size calc)
  4665                                  	; DX = 0
  4666 00001A5F 83C002                  	add	ax, 2  ; cluster 2 to ...
  4667 00001A62 89C2                    	mov	dx, ax
  4668 00001A64 D1E2                    	shl	dx, 1
  4669 00001A66 01D0                    	add	ax, dx ; *3
  4670 00001A68 D1E8                    	shr	ax, 1  ; /2
  4671 00001A6A 83D000                  	adc	ax, 0  ; +0.5 -> +1
  4672                                  
  4673                                  	; AX = FAT bytes for 12 bit cluster numbers
  4674                                  	
  4675 00001A6D B90002                  	mov	cx, 512		; [BPB_BytesPerSec]
  4676 00001A70 01C8                    	add	ax, cx		
  4677 00001A72 48                      	dec	ax		; [BPB_BytesPerSec] - 1
  4678 00001A73 29D2                    	sub	dx, dx
  4679 00001A75 F7F1                    	div	cx
  4680 00001A77 894616                  	mov	[bp+16h], ax	; [BPB_FATSz16]
  4681                                  	; * 2
  4682 00001A7A D1E0                    	shl	ax, 1
  4683                                  	; AX = [BPB_NumFATs] * [BPB_FATSz16]
  4684                                  
  4685                                  	;mov	cx, [bp+0Eh]	; [BPB_RsvdSecCnt] ; 1
  4686                                  	;add	cx, ax
  4687                                  	;mov	ax, [bp+11h]	; [BPB_RootEntCnt] = 512
  4688                                  	;add	ax, 15	; (16-1) (512-1)
  4689                                  	;shr	ax, 4	; /16  (*32/512)
  4690                                  	;; AX = Root dir sectors
  4691                                  	;; CX = [BPB_RsvdSecCnt]+([BPB_NumFATs]*[BPB_FATSz16])
  4692                                  	;add	cx, ax ; + RootDirsectors
  4693                                  	;mov	[root_dir_secs], ax
  4694                                  
  4695                                  	; 11/02/2019
  4696                                  	;mov	cx, 33
  4697 00001A7C 8B0E[2C6D]              	mov	cx, [root_dir_secs]
  4698 00001A80 034E0E                  	add	cx, [bp+0Eh]	; [BPB_RsvdSecCnt] ; 1
  4699                                  		; cx = root directory sectors + reserved sectors
  4700 00001A83 01C1                    	add	cx, ax
  4701                                  	; CX = [BPB_RsvdSecCnt]+([BPB_NumFATs]*[BPB_FATSz16])
  4702                                  	;	  + RootDirSectors
  4703 00001A85 8B4613                  	mov	ax, [bp+13h]	; [BPB_TotSec16]
  4704 00001A88 29C8                    	sub	ax, cx
  4705                                  		 ; AX = data sectors
  4706                                  		 ; cH = 0
  4707                                  
  4708                                  	; 11/02/2019 - fix FAT size (better method)
  4709 00001A8A 09F6                    	or	si, si
  4710 00001A8C 7504                    	jnz	short FAT12_f_9
  4711                                  
  4712 00001A8E 89C6                    	mov	si, ax  ; ax = data sectors
  4713 00001A90 EBB9                    	jmp	short FAT12_f_10
  4714                                  
  4715                                  FAT12_f_9:
  4716 00001A92 31D2                    	xor	dx, dx
  4717 00001A94 890E[206D]              	mov	[data_start], cx
  4718 00001A98 8916[226D]              	mov	[data_start+2], dx ; 0
  4719                                  	; DX_AX = Data sectors
  4720 00001A9C A3[246D]                	mov	[data_sectors], ax
  4721 00001A9F 8916[266D]              	mov	[data_sectors+2], dx ; 0
  4722 00001AA3 8A4E0D                  	mov	cl, [bp+0Dh]	 ; [BPB_SecPerClus]
  4723 00001AA6 28ED                    	sub	ch, ch
  4724 00001AA8 F7F1                    	div	cx
  4725                                  	; AX = Count of clusters (rounded down)
  4726 00001AAA 29D2                    	sub	dx, dx ; 0
  4727 00001AAC A3[286D]                	mov	[cluster_count], ax
  4728 00001AAF 8916[2A6D]              	mov	[cluster_count+2], dx ; 0
  4729                                  
  4730 00001AB3 8D7E2B                  	lea	di, [bp+43] ; [BS_VolLab]
  4731 00001AB6 E8CBFB                  	call	write_volume_name
  4732 00001AB9 8D7627                  	lea	si, [bp+39] ; [BS_VolID]
  4733 00001ABC E824FC                  	call	write_volume_serial
  4734 00001ABF E834FD                  	call	write_cluster_count	
  4735                                  
  4736 00001AC2 E8A5FC                  	call	write_formatting_msg
  4737 00001AC5 B000                    	mov	al, 0
  4738 00001AC7 E8FDFC                  	call	write_format_percent_x
  4739                                  
  4740 00001ACA 8B461C                  	mov	ax, [bp+1Ch]	; [BPB_HiddSec]
  4741 00001ACD 8B561E                  	mov	dx, [bp+1Eh]	; [BPB_HiddSec+2]
  4742                                  
  4743 00001AD0 0106[206D]              	add	[data_start], ax
  4744 00001AD4 1116[226D]              	adc	[data_start+2], dx
  4745                                  
  4746                                  	; DX_AX = FAT12 Boot Sector address
  4747 00001AD8 BB[933B]                	mov	bx, TRDOS_FAT12_hd_bs
  4748                                  	; ES:BX = Boot Sector Buffer
  4749 00001ADB E8B003                  	call	write_hd_sector
  4750 00001ADE 0F82F9FC                	jc	formatting_error
  4751 00001AE2 E8A9FC                  	call	write_format_percent
  4752 00001AE5 83C001                  	add	ax, 1
  4753 00001AE8 83D200                  	adc	dx, 0
  4754                                  	; write remain part of reserved sectors
  4755 00001AEB 8B4E0E                  	mov	cx, [bp+0Eh] ; [BPB_RsvdSecCnt]
  4756                                  	;sub	cx, 1
  4757                                  	;jna	short FAT12_f_3
  4758                                  	; 11/02/2019
  4759 00001AEE 49                      	dec	cx
  4760 00001AEF 7418                    	jz	short FAT12_f_3
  4761                                  FAT12_f_2:
  4762 00001AF1 51                      	push	cx
  4763 00001AF2 BB[206B]                	mov	bx, HDFORMAT_EMPTY_BUFF
  4764 00001AF5 E89603                  	call	write_hd_sector
  4765 00001AF8 0F82DFFC                	jc	formatting_error
  4766 00001AFC E88FFC                  	call	write_format_percent
  4767 00001AFF 83C001                  	add	ax, 1
  4768 00001B02 83D200                  	adc	dx, 0
  4769 00001B05 59                      	pop	cx
  4770 00001B06 49                      	dec	cx ; dec cl
  4771 00001B07 75E8                    	jnz	short FAT12_f_2
  4772                                  FAT12_f_3:
  4773                                  	; write FAT sectors
  4774 00001B09 8B0E[206D]              	mov	cx, [data_start] ; lba/abs addr
  4775 00001B0D 8B1E[226D]              	mov	bx, [data_start+2] ; lba/abs addr
  4776                                  
  4777                                  	; 11/02/2019
  4778 00001B11 2B0E[2C6D]              	sub	cx, [root_dir_secs]
  4779 00001B15 83DB00                  	sbb	bx, 0
  4780                                  
  4781 00001B18 53                      	push	bx
  4782 00001B19 51                      	push	cx
  4783 00001B1A BB[206B]                	mov	bx, HDFORMAT_FATBUFFER
  4784                                  	; ES:BX = FAT Sector Buffer
  4785 00001B1D 8A4E15                  	mov	cl, [bp+15h] ; [BPB_Media]
  4786 00001B20 B5FF                    	mov	ch, 0FFh
  4787 00001B22 890F                    	mov	[bx], cx ; 0FFF8h
  4788 00001B24 886F02                  	mov	[bx+2], ch ; 0FFFFF8h
  4789                                  	;xor	cx, cx
  4790 00001B27 E86403                  	call	write_hd_sector
  4791 00001B2A 0F82ADFC                	jc	formatting_error
  4792 00001B2E E85DFC                  	call	write_format_percent
  4793                                  	;mov	bx, HDFORMAT_FATBUFFER
  4794 00001B31 B90000                  	mov	cx, 0
  4795 00001B34 890F                    	mov	[bx], cx
  4796 00001B36 884F02                  	mov	[bx+2], cl
  4797 00001B39 EB0F                    	jmp	short FAT12_f_5
  4798                                  FAT12_f_4:	
  4799 00001B3B 53                      	push	bx
  4800 00001B3C 51                      	push	cx	
  4801 00001B3D BB[206B]                	mov	bx, HDFORMAT_FATBUFFER
  4802 00001B40 E84B03                  	call	write_hd_sector
  4803 00001B43 0F8294FC                	jc	formatting_error
  4804 00001B47 E844FC                  	call	write_format_percent
  4805                                  FAT12_f_5:	
  4806 00001B4A 59                      	pop	cx
  4807 00001B4B 5B                      	pop	bx
  4808 00001B4C 83C001                  	add	ax, 1
  4809 00001B4F 83D200                  	adc	dx, 0
  4810 00001B52 39DA                    	cmp	dx, bx
  4811 00001B54 72E5                    	jb	short FAT12_f_4
  4812 00001B56 39C8                    	cmp	ax, cx
  4813 00001B58 72E1                    	jb	short FAT12_f_4
  4814                                  
  4815                                  	; write	root directory sectors
  4816                                  	; as empty sectors
  4817 00001B5A 8B0E[2C6D]              	mov	cx, [root_dir_secs]
  4818                                  FAT12_f_6:
  4819 00001B5E 51                      	push	cx
  4820 00001B5F BB[206B]                	mov	bx, HDFORMAT_EMPTY_BUFF
  4821 00001B62 E82903                  	call	write_hd_sector
  4822 00001B65 0F8272FC                	jc	formatting_error
  4823 00001B69 E822FC                  	call	write_format_percent
  4824 00001B6C 83C001                  	add	ax, 1
  4825 00001B6F 83D200                  	adc	dx, 0
  4826 00001B72 59                      	pop	cx
  4827 00001B73 49                      	dec	cx ; dec cl
  4828 00001B74 75E8                    	jnz	short FAT12_f_6
  4829                                  
  4830                                  	; write DATA sectors 
  4831                                  	; (after root directory sectors)
  4832 00001B76 8B0E[246D]              	mov	cx, [data_sectors]
  4833                                  	;mov	bx, [data_sectors+2]
  4834                                  	;inc	bx ; 11/02/2019
  4835                                  FAT12_f_7:	
  4836                                  	;push	bx
  4837 00001B7A 51                      	push	cx	
  4838 00001B7B BB[1A67]                	mov	bx, HDFORMAT_SECBUFFER
  4839 00001B7E E80D03                  	call	write_hd_sector
  4840 00001B81 0F8256FC                	jc	formatting_error
  4841 00001B85 E806FC                  	call	write_format_percent
  4842 00001B88 59                      	pop	cx
  4843                                  	;pop	bx
  4844 00001B89 83C001                  	add	ax, 1
  4845 00001B8C 83D200                  	adc	dx, 0
  4846 00001B8F 49                      	dec	cx
  4847 00001B90 75E8                    	jnz	short FAT12_f_7
  4848                                  	;dec	bx
  4849                                  	;jnz	short FAT12_f_7
  4850                                  
  4851                                  	; If there are, format remain sectors which are
  4852                                  	; at beyond of data clusters, with zero bytes.
  4853                                  	
  4854 00001B92 8B4E1C                  	mov	cx, [bp+1Ch]	; [BPB_HiddSec]
  4855 00001B95 8B5E1E                  	mov	bx, [bp+1Eh]	; [BPB_HiddSec+2]
  4856                                  
  4857 00001B98 034E13                  	add	cx, [bp+13h]	; [BPB_TotSec16]
  4858 00001B9B 83D300                  	adc	bx, 0
  4859 00001B9E E9ACFA                  	jmp	FAT12_f_8
  4860                                  
  4861                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4862                                  ; SINGLIX FS FORMATTING
  4863                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4864                                  
  4865                                  SINGLIX_hdi_format:
  4866                                  	; 06/01/2018
  4867                                  	; 05/01/2018
  4868                                  	; If Sectors/Track = 17, use CHS+LBA type boot sector
  4869 00001BA1 8B1E[A641]              	mov	bx, [sectors]
  4870 00001BA5 83FB11                  	cmp	bx, 17
  4871 00001BA8 7711                    	ja	short SINGLIX_fs1_f_1
  4872                                  SINGLIX_fs1_f_0:
  4873 00001BAA BD[933D]                	mov	bp, TRDOS_TRFS1_chs_bs
  4874 00001BAD 887E2D                  	mov	[bp+45], bh ; 0 ; [bs_LBA_Ready] = 0
  4875 00001BB0 885E2E                  	mov	[bp+46], bl	; [bs_Disk_SecPerTrack]
  4876 00001BB3 A0[A841]                	mov	al, [heads]
  4877 00001BB6 88462F                  	mov	[bp+47], al	; [bs_Disk_Heads]
  4878 00001BB9 EB15                    	jmp	short SINGLIX_fs1_f_3
  4879                                  SINGLIX_fs1_f_1:
  4880                                  	; Sectors per Track = 63
  4881                                  	; If disk capacity >= 63*16*1024 use LBA type boot sector
  4882 00001BBB 8B0E[A841]              	mov	cx, [heads]
  4883 00001BBF A1[AA41]                	mov	ax, [cylinders]
  4884 00001BC2 F7E1                    	mul	cx
  4885 00001BC4 21D2                    	and	dx, dx
  4886 00001BC6 7505                    	jnz	short SINGLIX_fs1_f_2
  4887 00001BC8 3D0040                  	cmp	ax, 16384
  4888 00001BCB 72DD                    	jb	short SINGLIX_fs1_f_0
  4889                                  SINGLIX_fs1_f_2:	
  4890 00001BCD BD[933F]                	mov	bp, TRDOS_TRFS1_lba_bs
  4891                                  	;mov	byte [bp+45], 1 ; [bs_LBA_Ready] = 1
  4892                                  SINGLIX_fs1_f_3:	
  4893                                  	;mov	ax, [pp_Sectors]
  4894                                  	;mov	dx, [pp_Sectors+2]
  4895                                  	; 16/02/2019
  4896 00001BD0 A1[DC6F]                	mov	ax, [ppn_Sectors]
  4897 00001BD3 8B16[DE6F]              	mov	dx, [ppn_Sectors+2]
  4898 00001BD7 894610                  	mov	[bp+16], ax	; [bsVolumeSize]
  4899 00001BDA 895612                  	mov	[bp+18], dx	; [bsVolumeSize+2]
  4900 00001BDD 8B0E[A86F]              	mov	cx, [pp_StartSector]
  4901 00001BE1 8B1E[AA6F]              	mov	bx, [pp_StartSector+2]
  4902 00001BE5 894E0C                  	mov	[bp+12], cx	; [bsBeginSector]
  4903 00001BE8 895E0E                  	mov	[bp+14], bx	; [bsBeginSector+2]
  4904 00001BEB C6462C80                	mov	byte [bp+44], 80h ; [bsDriveNumber]  ; hd0
  4905                                  
  4906                                  	; Prepare MAT
  4907 00001BEF A3[846D]                	mov	[MAT_VolumeSize], ax ; Total Sectors of the FS
  4908 00001BF2 8916[866D]              	mov	[MAT_VolumeSize+2], dx
  4909 00001BF6 890E[886D]              	mov	[MAT_BeginSector], cx ; Beginning Sector of the FS
  4910 00001BFA 891E[8A6D]              	mov	[MAT_BeginSector+2], bx
  4911                                  	;mov	cx, [bp+24]	; [bsMATLocation]
  4912                                  	;mov	bx, [bp+26]	; [bsMATLocation+2]
  4913                                  	;add	cx, 1
  4914                                  	;adc	bx, 0
  4915                                  	; Note: (as Default) MAT Address = 1, DAT Address = 2 
  4916 00001BFE B90200                  	mov	cx, 2
  4917                                  	;xor	bx, bx ; 0
  4918                                  	;mov	[bp+24], cx	; [bsMATLocation]
  4919                                  	;mov	[bp+26], bx	; [bsMATLocation+2]
  4920 00001C01 890E[8C6D]              	mov	[DAT_Address], cx
  4921                                  	;mov	[DAT_Address+2], bx
  4922                                  	; DX_AX = FS1 Volume Size
  4923 00001C05 83C007                  	add	ax, 7 ; 7 bits more (for round up)
  4924 00001C08 83D200                  	adc	dx, 0
  4925 00001C0B B90800                  	mov	cx, 8 ;  1 DAT byte == 8 sectors 
  4926 00001C0E E861F2                  	call	div32
  4927                                  	; DX_AX = DAT bytes
  4928 00001C11 B9FF01                  	mov	cx, 511
  4929 00001C14 01C8                    	add	ax, cx
  4930 00001C16 83D200                  	adc	dx, 0
  4931 00001C19 41                      	inc	cx ; 512
  4932 00001C1A E855F2                  	call	div32
  4933                                  	; DX_AX = DAT sectors (DX must be 0 for volume sizes < 128GB)
  4934 00001C1D A3[906D]                	mov	[DAT_SectorCount], ax
  4935                                  	;mov	[DAT_SectorCount+2], dx ; 0
  4936                                  
  4937 00001C20 83C002                  	add	ax, 2  ; BS + MAT
  4938                                  	;adc	dx, 0
  4939 00001C23 89461C                  	mov	[bp+28], ax  ; [bsRootDirDT] ; RDT address (offset)
  4940                                  	;mov	[bp+30], dx
  4941                                  
  4942                                  	; Free Sectors = Total Sectors - (BS+MAT+DATsects+RDT+4)	 
  4943 00001C26 83C005                  	add	ax, 5 ; DATsects + (BS+MAT+RDT+4)
  4944 00001C29 89C2                    	mov	dx, ax
  4945 00001C2B 8B0E[846D]              	mov	cx, [MAT_VolumeSize]
  4946 00001C2F 8B1E[866D]              	mov	bx, [MAT_VolumeSize+2]
  4947 00001C33 29C1                    	sub	cx, ax
  4948 00001C35 83DB00                  	sbb	bx, 0
  4949 00001C38 890E[946D]              	mov	[MAT_FreeSectors], cx
  4950 00001C3C 891E[966D]              	mov	[MAT_FreeSectors+2], bx
  4951 00001C40 A3[986D]                	mov	[MAT_FirstFreeSector], ax
  4952                                  	;mov	word [MAT_FirstFreesector+2] , 0
  4953                                  
  4954 00001C43 BF[346D]                	mov	di, fs_volume_name
  4955 00001C46 E834FA                  	call	write_fs_volume_name
  4956 00001C49 BE[746D]                	mov	si, fs_volume_serial
  4957 00001C4C E894FA                  	call	write_volume_serial
  4958                                  
  4959                                  	; Modify FS volume name
  4960                                  	; (Convert 20h tail bytes to 0)
  4961 00001C4F B94000                  	mov	cx, 64 
  4962 00001C52 BE[346D]                	mov	si, fs_volume_name
  4963 00001C55 31DB                    	xor	bx, bx
  4964 00001C57 B0FF                    	mov	al, 0FFh
  4965                                  modify_fs_vname_1:	
  4966 00001C59 88C4                    	mov	ah, al
  4967 00001C5B AC                      	lodsb
  4968 00001C5C 3C20                    	cmp	al, 20h
  4969 00001C5E 7708                    	ja	short modify_fs_vname_2
  4970 00001C60 80FC20                  	cmp	ah, 20h
  4971 00001C63 7603                    	jna	short modify_fs_vname_2
  4972 00001C65 89F3                    	mov	bx, si
  4973 00001C67 4B                      	dec	bx
  4974                                  modify_fs_vname_2:
  4975 00001C68 E2EF                    	loop	modify_fs_vname_1		
  4976 00001C6A 09DB                    	or	bx, bx
  4977 00001C6C 740B                    	jz	short modify_fs_vname_3
  4978 00001C6E 89DF                    	mov	di, bx
  4979 00001C70 B9[746D]                	mov	cx, fs_volume_name+64
  4980 00001C73 29D9                    	sub	cx, bx
  4981 00001C75 30C0                    	xor	al, al
  4982 00001C77 F3AA                    	rep	stosb 
  4983                                  
  4984                                  modify_fs_vname_3:
  4985 00001C79 E8EEFA                  	call	write_formatting_msg
  4986 00001C7C B000                    	mov	al, 0
  4987 00001C7E E846FB                  	call	write_format_percent_x
  4988                                  
  4989 00001C81 8B460C                  	mov	ax, [bp+12]	; [bsBeginSector]
  4990 00001C84 8B560E                  	mov	dx, [bp+14]	; [bsBeginSector+2]
  4991                                  
  4992                                  	; DX_AX = TRFS1 Boot Sector address
  4993 00001C87 89EB                    	mov	bx, bp
  4994                                  	; ES:BX = Boot Sector Buffer
  4995 00001C89 E80202                  	call	write_hd_sector
  4996 00001C8C 0F824BFB                	jc	formatting_error
  4997                                  	
  4998 00001C90 83C001                  	add	ax, 1
  4999 00001C93 83D200                  	adc	dx, 0
  5000                                  
  5001                                  	; DX_AX = MAT (DAT header) sector address
  5002 00001C96 BB[806D]                	mov	bx, FS_MAT_Buffer
  5003                                  	; 16/02/2019
  5004 00001C99 C7074D41                	mov	word [bx],'MA'
  5005 00001C9D C6470254                	mov	byte [bx+2],'T'
  5006 00001CA1 E8EA01                  	call	write_hd_sector
  5007 00001CA4 0F8233FB                	jc	formatting_error
  5008 00001CA8 E823FB                  	call	write_fs_format_percent
  5009                                  
  5010                                  	; Calculate DAT bits 
  5011                                  	; NOTE: 4096 bits per DAT sector
  5012 00001CAB A1[986D]                	mov	ax, [MAT_FirstFreeSector]
  5013                                  	;mov	dx, [MAT_FirstFreeSector+2]
  5014 00001CAE 31D2                    	xor	dx, dx
  5015 00001CB0 52                      	push	dx
  5016 00001CB1 50                      	push	ax
  5017 00001CB2 B90010                  	mov	cx, 4096
  5018 00001CB5 E8BAF1                  	call	div32
  5019 00001CB8 891E[786D]              	mov	[DAT_FFBit], bx
  5020 00001CBC A3[7A6D]                	mov	[DAT_FFSector], ax
  5021 00001CBF 58                      	pop	ax
  5022 00001CC0 5A                      	pop	dx
  5023 00001CC1 83E801                  	sub	ax, 1
  5024 00001CC4 83DA00                  	sbb	dx, 0
  5025 00001CC7 0306[946D]              	add	ax, [MAT_FreeSectors]
  5026 00001CCB 1316[966D]              	adc	dx, [MAT_FreeSectors+2]
  5027 00001CCF E8A0F1                  	call	div32
  5028 00001CD2 891E[7C6D]              	mov	[DAT_LFBit], bx
  5029 00001CD6 A3[7E6D]                	mov	[DAT_LFSector], ax
  5030                                  
  5031 00001CD9 31F6                    	xor	si, si ; 0
  5032                                  SINGLIX_fs1_f_4:
  5033                                  	; calculate free bits for current DAT sector
  5034                                  	;			(to be written)
  5035 00001CDB BF[9C6D]                	mov	di, FS_DAT_Buffer
  5036 00001CDE 3B36[7A6D]              	cmp	si, [DAT_FFSector]
  5037 00001CE2 7431                    	je	short SINGLIX_fs1_f_7
  5038 00001CE4 724D                    	jb	short SINGLIX_fs1_f_9
  5039 00001CE6 3B36[7E6D]              	cmp	si, [DAT_LFSector]
  5040 00001CEA 7224                    	jb	short SINGLIX_fs1_f_6
  5041 00001CEC 7745                    	ja	short SINGLIX_fs1_f_9
  5042 00001CEE 8B1E[7C6D]              	mov	bx, [DAT_LFBit]
  5043 00001CF2 B0FF                    	mov	al, 0FFh
  5044 00001CF4 88DC                    	mov	ah, bl
  5045 00001CF6 C1EB03                  	shr	bx, 3 ; bit count to byte count
  5046 00001CF9 7409                    	jz	short SINGLIX_fs1_f_5
  5047 00001CFB 89D9                    	mov	cx, bx
  5048 00001CFD F3AA                    	rep	stosb
  5049 00001CFF BF[9C6D]                	mov	di, FS_DAT_Buffer
  5050 00001D02 01DF                    	add	di, bx
  5051                                  SINGLIX_fs1_f_5:
  5052 00001D04 80E407                  	and	ah, 7
  5053 00001D07 88E1                    	mov	cl, ah 
  5054 00001D09 D2E0                    	shl	al, cl
  5055 00001D0B F6D0                    	not	al
  5056 00001D0D AA                      	stosb
  5057                                  	;mov	cx, 511
  5058                                  	;sub	cx, bx
  5059                                  	;jna	short SINGLIX_fs1_f_9
  5060                                  	;mov	al, 0 ; out of volume bits (=0)
  5061                                  	;rep	stosb
  5062 00001D0E EB23                    	jmp	short SINGLIX_fs1_f_9
  5063                                  SINGLIX_fs1_f_6:
  5064 00001D10 B90002                  	mov	cx, 512
  5065 00001D13 EB1A                    	jmp	short SINGLIX_fs1_f_8
  5066                                  SINGLIX_fs1_f_7:
  5067 00001D15 8B1E[786D]              	mov	bx, [DAT_FFBit]
  5068 00001D19 88D9                    	mov	cl, bl
  5069 00001D1B 80E107                  	and	cl, 7
  5070 00001D1E C1EB03                  	shr	bx, 3 ; from bits to bytes
  5071 00001D21 01DF                    	add	di, bx
  5072 00001D23 B0FF                    	mov	al, 0FFh
  5073 00001D25 D2E0                    	shl	al, cl
  5074 00001D27 AA                      	stosb
  5075 00001D28 B9FF01                  	mov	cx, 511
  5076 00001D2B 29D9                    	sub	cx, bx
  5077 00001D2D 7604                    	jna	short SINGLIX_fs1_f_9
  5078                                  SINGLIX_fs1_f_8:
  5079 00001D2F B0FF                    	mov	al, 0FFh ; Free sector bits (=1)
  5080 00001D31 F3AA                    	rep	stosb
  5081                                  SINGLIX_fs1_f_9:
  5082 00001D33 A1[886D]                	mov	ax, [MAT_BeginSector]
  5083 00001D36 8B16[8A6D]              	mov	dx, [MAT_BeginSector+2]
  5084                                  	;add	ax, [DAT_Address] ; = 2
  5085                                  	;adc	dx, [DAT_Address+2]
  5086 00001D3A 83C002                  	add	ax, 2
  5087 00001D3D 83D200                  	adc	dx, 0
  5088 00001D40 01F0                    	add	ax, si
  5089 00001D42 83D200                  	adc	dx, 0
  5090                                  	; Write DAT sector(s)
  5091                                  	; DX_AX = Disk Allocation Table sector address
  5092 00001D45 BB[9C6D]                	mov	bx, FS_DAT_Buffer
  5093 00001D48 E84301                  	call	write_hd_sector
  5094 00001D4B 0F828CFA                	jc	formatting_error
  5095 00001D4F E87CFA                  	call	write_fs_format_percent
  5096                                  	; Clear DAT buffer again (for next stage)
  5097 00001D52 B90001                  	mov	cx, 256
  5098 00001D55 BF[9C6D]                	mov	di, FS_DAT_Buffer
  5099 00001D58 29C0                    	sub	ax, ax
  5100 00001D5A F3AB                    	rep	stosw
  5101                                  
  5102 00001D5C 46                      	inc	si
  5103                                  
  5104 00001D5D 3B36[906D]              	cmp	si, [DAT_SectorCount]
  5105 00001D61 0F8676FF                	jna	SINGLIX_fs1_f_4
  5106                                  
  5107                                  	; ;;;
  5108                                  	
  5109                                  	; DAT sectors has been written..
  5110                                  	; Now, Root Directory Description Table is in order
  5111                                  
  5112 00001D65 BF[9C6D]                	mov	di, FS_RDT_Buffer
  5113 00001D68 B84444                  	mov	ax, 'DD' 
  5114 00001D6B AB                      	stosw
  5115 00001D6C 30E4                    	xor	ah, ah
  5116 00001D6E B054                    	mov	al, 'T'
  5117 00001D70 AB                      	stosw
  5118 00001D71 B80002                  	mov	ax, 512 ; Sector size (Bytes per sector)	
  5119 00001D74 AB                      	stosw
  5120 00001D75 31C0                    	xor	ax, ax ; RDT sequence number (= 0, section 1)
  5121 00001D77 AB                      	stosw	
  5122                                  	; RDT address
  5123 00001D78 A1[906D]                	mov	ax, [DAT_SectorCount]
  5124 00001D7B 8B16[926D]              	mov	dx, [DAT_SectorCount+2]
  5125 00001D7F 83C002                  	add	ax, 2 ; BS + MAT
  5126 00001D82 83D200                  	adc	dx, 0
  5127 00001D85 AB                      	stosw
  5128 00001D86 89D0                    	mov	ax, dx
  5129 00001D88 AB                      	stosw
  5130 00001D89 29C0                    	sub	ax, ax ; Next RDT number
  5131 00001D8B AB                      	stosw
  5132 00001D8C AB                      	stosw
  5133 00001D8D B80400                  	mov	ax, 4 ; Sector count of this section	
  5134                                  		      ; (4*512)/4 = 512 root dir entries
  5135 00001D90 AB                      	stosw
  5136 00001D91 30C0                    	xor	al, al
  5137 00001D93 AB                      	stosw
  5138                                  	; Volume beginning sector
  5139 00001D94 8B460C                  	mov	ax, [bp+12]	; [bsBeginSector]
  5140 00001D97 8B560E                  	mov	dx, [bp+14]	; [bsBeginSector+2]
  5141 00001D9A AB                      	stosw
  5142 00001D9B 89D0                    	mov	ax, dx
  5143 00001D9D AB                      	stosw
  5144 00001D9E 31C0                    	xor	ax, ax
  5145 00001DA0 48                      	dec	ax ; 0FFFFh
  5146                                  	; Parent Dir Serial (= FFFFFFFFh for root dir)
  5147 00001DA1 AB                      	stosw
  5148 00001DA2 AB                      	stosw
  5149                                  
  5150                                  set_fs_volume_serial_number:
  5151 00001DA3 BE[746D]                	mov	si, fs_volume_serial
  5152 00001DA6 A5                      	movsw
  5153 00001DA7 A5                      	movsw
  5154                                  
  5155 00001DA8 29C0                    	sub	ax, ax
  5156 00001DAA AA                      	stosb	; sub directory level = 0
  5157 00001DAB AA                      	stosb	; 0, reverved
  5158 00001DAC B004                    	mov	al, 00000100b ;  (DOS) System attribute
  5159 00001DAE AA                      	stosb	; (DOS) Basic attributes
  5160 00001DAF 28C0                    	sub	al, al ; Extended attributes (0 for TRDOS 386)
  5161 00001DB1 AA                      	stosb
  5162 00001DB2 29C0                    	sub	ax, ax ; reserved (8) bytes for TR-MULTIX
  5163 00001DB4 AB                      	stosw
  5164 00001DB5 AB                      	stosw
  5165 00001DB6 AB                      	stosw
  5166 00001DB7 AB                      	stosw
  5167 00001DB8 B85254                  	mov	ax, 'RT' ; TRFS Root directory signature
  5168 00001DBB AB                      	stosw
  5169 00001DBC 31C0                    	xor	ax, ax ; Country (language, date, text format)
  5170                                  		       ; (0 = Default, 1 = USA, 90 = Turkiye)
  5171 00001DBE AA                      	stosb
  5172 00001DBF AA                      	stosb	; Time Zone (0 = GMT = default ; -11 to +12)
  5173                                  
  5174 00001DC0 89FE                    	mov	si, di
  5175                                  	; get the date (from RTC)
  5176 00001DC2 B404                    	mov	ah, 4
  5177 00001DC4 CD1A                    	int	1Ah
  5178                                  	; Creating Date (of root directory)
  5179 00001DC6 86E9                    	xchg	ch, cl ; 07/01/2018
  5180 00001DC8 89C8                    	mov	ax, cx ; cl = century (BCD), ch = year (BCD)
  5181 00001DCA AB                      	stosw
  5182 00001DCB 88F0                    	mov	al, dh  ; month (BCD)
  5183 00001DCD AA                      	stosb
  5184 00001DCE 88D0                    	mov	al, dl  ; day (BCD)
  5185 00001DD0 AA                      	stosb
  5186                                  	; get the time (from RTC)
  5187 00001DD1 B402                    	mov	ah, 2
  5188 00001DD3 CD1A                    	int	1Ah
  5189                                  	; Creating Time (of root directory)
  5190 00001DD5 86CD                    	xchg	cl, ch ; ch = hour (BCD), cl = minute (BSD)
  5191 00001DD7 89C8                    	mov	ax, cx ; al = hour, ah = minute
  5192 00001DD9 AB                      	stosw
  5193 00001DDA 88F0                    	mov	al, dh ; seconds (BCD)
  5194 00001DDC AA                      	stosb
  5195 00001DDD 88D0                    	mov	al, dl ; daylight savings time option 
  5196 00001DDF AA                      	stosb
  5197                                  	; Set Last Modification Date&Time
  5198 00001DE0 B90400                  	mov	cx, 4
  5199 00001DE3 F3A5                    	rep	movsw ; copy creating date&time values to
  5200                                  		; last modification date time values	
  5201                                  		; (last modif date&time = creating date&time)
  5202                                  
  5203                                  set_fs_volume_name:
  5204 00001DE5 BE[346D]                	mov	si, fs_volume_name
  5205 00001DE8 B120                    	mov	cl, 32 
  5206 00001DEA F3A5                    	rep	movsw
  5207                                  
  5208                                  	; Fill remain bytes (of this RDT) with zero
  5209 00001DEC B9C000                  	mov	cx, (128+256)/2
  5210 00001DEF 31C0                    	xor	ax, ax
  5211 00001DF1 F3AB                    	rep	stosw
  5212                                  
  5213                                  	; RDT is ready here...
  5214                                  
  5215 00001DF3 8B461C                  	mov	ax, [bp+28]	; [bsRootDirDT]
  5216                                  	;mov	dx, [bp+30]	; [bsRootDirDT+2]
  5217 00001DF6 31D2                    	xor	dx, dx
  5218 00001DF8 03460C                  	add	ax, [bp+12]	; [bsBeginSector]
  5219 00001DFB 13560E                  	adc	dx, [bp+14]	; [bsBeginSector+2]
  5220                                  
  5221                                  	; Write RDT sector
  5222                                  	; DX_AX = Root Directory Description Table address
  5223 00001DFE BB[9C6D]                	mov	bx, FS_RDT_Buffer
  5224 00001E01 E88A00                  	call	write_hd_sector
  5225 00001E04 0F82D3F9                	jc	formatting_error
  5226 00001E08 E8C3F9                  	call	write_fs_format_percent
  5227                                  
  5228 00001E0B 83C001                  	add	ax, 1
  5229 00001E0E 83D200                  	adc	dx, 0
  5230                                  
  5231                                  	; write root directory data sectors
  5232 00001E11 B90400                  	mov	cx, 4
  5233                                  
  5234                                  SINGLIX_fs1_f_10:
  5235 00001E14 51                      	push	cx
  5236                                  	; Write root directory sector(s)
  5237                                  	; DX_AX = Root Directory Sector address
  5238 00001E15 BB[206B]                	mov	bx, HDFORMAT_EMPTY_BUFF
  5239 00001E18 E87300                  	call	write_hd_sector
  5240 00001E1B 0F82BCF9                	jc	formatting_error
  5241 00001E1F E8ACF9                  	call	write_fs_format_percent
  5242 00001E22 83C001                  	add	ax, 1
  5243 00001E25 83D200                  	adc	dx, 0
  5244 00001E28 59                      	pop	cx
  5245 00001E29 FEC9                    	dec	cl
  5246 00001E2B 75E7                    	jnz	short SINGLIX_fs1_f_10
  5247                                  
  5248                                  	; Fill remain sectors with 'F6h' bytes
  5249 00001E2D 8B4E10                  	mov	cx, [bp+16]	; [bsVolumeSize]
  5250 00001E30 8B5E12                  	mov	bx, [bp+18]	; [bsVolumeSize+2]
  5251 00001E33 034E0C                  	add	cx, [bp+12]	; [bsBeginSector]
  5252 00001E36 135E0E                  	adc	bx, [bp+14]	; [bsBeginSector+2]
  5253                                  
  5254                                  	; write DATA sectors 
  5255                                  	; (after root directory sectors)
  5256                                  SINGLIX_fs1_f_11:
  5257 00001E39 53                      	push	bx
  5258 00001E3A 51                      	push	cx
  5259 00001E3B BB[1A67]                	mov	bx, HDFORMAT_SECBUFFER
  5260 00001E3E E84D00                  	call	write_hd_sector
  5261 00001E41 0F8296F9                	jc	formatting_error
  5262 00001E45 E846F9                  	call	write_format_percent
  5263 00001E48 59                      	pop	cx
  5264 00001E49 5B                      	pop	bx
  5265 00001E4A 83C001                  	add	ax, 1
  5266 00001E4D 83D200                  	adc	dx, 0
  5267 00001E50 39DA                    	cmp	dx, bx
  5268 00001E52 72E5                    	jb	short SINGLIX_fs1_f_11
  5269 00001E54 0F8717F8                	ja	SINGLIX_fs1_f_12
  5270 00001E58 39C8                    	cmp	ax, cx
  5271 00001E5A 72DD                    	jb	short SINGLIX_fs1_f_11
  5272 00001E5C E910F8                  	jmp	SINGLIX_fs1_f_12	
  5273                                  
  5274                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5275                                  ; Print error message and exit
  5276                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5277                                  ; 25/02/2019
  5278                                  	
  5279                                  D_01:
  5280 00001E5F 50                      	push	ax
  5281 00001E60 8B1E[A441]              	mov	bx, [img_file_handle]
  5282 00001E64 B43E                    	mov	ah, 3Eh ; close file
  5283 00001E66 CD21                    	int	21h
  5284 00001E68 58                      	pop	ax
  5285                                  
  5286                                  	; 11/02/2019
  5287                                  	;mov 	word [img_file_handle], 0
  5288                                  D_02:
  5289 00001E69 88E0                    	mov	al, ah ;  error code
  5290 00001E6B E8B000                  	call	bin_to_hex
  5291 00001E6E A3[6E57]                	mov 	[error_code], ax
  5292                                  
  5293 00001E71 BE[6057]                	mov	si, CRLF
  5294 00001E74 E80800                  	call	print_msg
  5295                                  
  5296 00001E77 BE[6357]                	mov	si, Msg_Error
  5297                                  
  5298 00001E7A E80200                  	call	print_msg
  5299                                  
  5300 00001E7D CD20                    	int	20h	; Exit
  5301                                  
  5302                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5303                                  ; Print messages
  5304                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5305                                  
  5306                                  print_msg:
  5307                                  
  5308                                  print_msg_LOOP:
  5309 00001E7F AC                      	lodsb                           ; Load byte at DS:SI to AL
  5310 00001E80 20C0                    	and     al, al            
  5311 00001E82 7409                    	jz      short print_msg_OK       
  5312 00001E84 B40E                    	mov	ah, 0Eh			
  5313 00001E86 BB0700                  	mov     bx, 07h             
  5314 00001E89 CD10                    	int	10h			; BIOS Service func ( ah ) = 0Eh
  5315                                  					; Write char as TTY
  5316                                  					; AL-char BH-page BL-color
  5317 00001E8B EBF2                    	jmp     short print_msg_LOOP           
  5318                                  
  5319                                  print_msg_OK:
  5320 00001E8D C3                      	retn
  5321                                  
  5322                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5323                                  ; Writing a block (sector) to hard disk disk image file
  5324                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5325                                  
  5326                                  write_hd_sector:
  5327                                  	; INPUT -> DX_AX = Logical Block Address
  5328                                  	; 	   ES:BX = Sector Buffer
  5329                                  	; OUTPUT ->
  5330                                  	;  cf = 0 -> DX_AX = Logical Block Adress
  5331                                  	;	     ES:BX = Sector Buffer
  5332                                  	;  cf = 1 -> AH = Error Number
  5333                                  	;
  5334 00001E8E 52                      	push	dx ; sector (hw)
  5335 00001E8F 50                      	push	ax ; sector (lw)
  5336 00001E90 53                      	push	bx ; buffer
  5337 00001E91 B90002                  	mov	cx, 512
  5338                                  	; DX_AX: Multiplicand
  5339                                  	; CX = Multiplier
  5340 00001E94 E8E9EF                  	call	mul32
  5341                                  	; BX_DX_AX = result of multiplication (product)
  5342 00001E97 21DB                    	and	bx, bx
  5343 00001E99 7529                    	jnz	short image_file_size_err
  5344 00001E9B F6C680                  	test	dh, 80h
  5345 00001E9E 7524                    	jnz	short image_file_size_err	
  5346 00001EA0 8B1E[A441]              	mov 	bx, [img_file_handle]
  5347 00001EA4 803E[AC41]00            	cmp	byte [random], 0
  5348 00001EA9 760A                    	jna	short whds
  5349 00001EAB 89D1                    	mov	cx, dx
  5350 00001EAD 89C2                    	mov	dx, ax
  5351 00001EAF 28C0                    	sub	al, al ; specified offset is from the beginning of the file
  5352 00001EB1 B442                    	mov	ah, 42h ; seek (move file pointer)
  5353 00001EB3 CD21                    	int	21h
  5354                                  whds:
  5355                                  	;mov	bx, [img_file_handle]
  5356 00001EB5 B90002                  	mov	cx, 512
  5357 00001EB8 5A                      	pop	dx  ; buffer address
  5358 00001EB9 B440                    	mov	ah, 40h ; write to file	
  5359 00001EBB CD21                    	int	21h
  5360 00001EBD 89D3                    	mov	bx, dx
  5361 00001EBF 7209                    	jc	short image_file_rw_err
  5362 00001EC1 58                      	pop	ax ; sector (lw)
  5363 00001EC2 5A                      	pop	dx ; sector (hw) 
  5364 00001EC3 C3                      	retn
  5365                                  
  5366                                  image_file_size_err:
  5367 00001EC4 5B                      	pop	bx
  5368 00001EC5 30C0                    	xor	al, al
  5369                                  	;mov	ah, 1Bh ; sector not found error
  5370 00001EC7 B419                    	mov	ah, 19h ; Seek error
  5371 00001EC9 F9                      	stc
  5372                                  
  5373                                  image_file_rw_err:
  5374 00001ECA 5A                      	pop	dx ; sector (lw)
  5375 00001ECB 5A                      	pop	dx ; sector (hw)
  5376 00001ECC C3                      	retn
  5377                                  
  5378                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5379                                  ; Reading a block (sector) from hard disk disk image file
  5380                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5381                                  
  5382                                  read_hd_sector:
  5383                                  	; INPUT -> DX_AX = Logical Block Address
  5384                                  	; 	   ES:BX = Sector Buffer
  5385                                  	; OUTPUT ->
  5386                                  	;  cf = 0 -> DX_AX = Logical Block Adress
  5387                                  	;	     ES:BX = Sector Buffer
  5388                                  	;  cf = 1 -> AH = Error Number
  5389                                  	;
  5390 00001ECD 52                      	push	dx ; sector (hw)
  5391 00001ECE 50                      	push	ax ; sector (lw)
  5392 00001ECF 53                      	push	bx ; buffer
  5393 00001ED0 B90002                  	mov	cx, 512
  5394                                  	; DX_AX: Multiplicand
  5395                                  	; CX = Multiplier
  5396 00001ED3 E8AAEF                  	call	mul32
  5397                                  	; BX_DX_AX = result of multiplication (product)
  5398 00001ED6 21DB                    	and	bx, bx
  5399 00001ED8 75EA                    	jnz	short image_file_size_err
  5400 00001EDA F6C680                  	test	dh, 80h
  5401 00001EDD 75E5                    	jnz	short image_file_size_err	
  5402 00001EDF 8B1E[A441]              	mov 	bx, [img_file_handle]
  5403 00001EE3 803E[AC41]00            	cmp	byte [random], 0
  5404 00001EE8 760A                    	jna	short rhds
  5405 00001EEA 89D1                    	mov	cx, dx
  5406 00001EEC 89C2                    	mov	dx, ax
  5407 00001EEE 28C0                    	sub	al, al ; specified offset is from the beginning of the file
  5408 00001EF0 B442                    	mov	ah, 42h ; seek (move file pointer)
  5409 00001EF2 CD21                    	int	21h
  5410                                  rhds:
  5411                                  	;mov	bx, [img_file_handle]
  5412 00001EF4 B90002                  	mov	cx, 512
  5413 00001EF7 5A                      	pop	dx  ; buffer address
  5414 00001EF8 B43F                    	mov	ah, 3Fh ; read from file	
  5415 00001EFA CD21                    	int	21h
  5416 00001EFC 89D3                    	mov	bx, dx
  5417 00001EFE 72CA                    	jc	short image_file_rw_err
  5418 00001F00 39C8                    	cmp	ax, cx
  5419 00001F02 75C0                    	jne	short image_file_size_err
  5420 00001F04 58                      	pop	ax ; sector (lw)
  5421 00001F05 5A                      	pop	dx ; sector (hw) 
  5422 00001F06 C3                      	retn
  5423                                  	
  5424                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5425                                  ; Convert byte to decimal number
  5426                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5427                                  
  5428                                  bin_to_decimal:
  5429                                  	; INPUT: DS:SI = Target location
  5430                                  	;        DX_AX = Binary Number (Integer)
  5431                                  	; OUTPUT: Decimal char at DS:SI
  5432                                  	; 	 SI decremented after every division
  5433                                  	; 	 till AX<10.
  5434                                  	; CX, DX, BX will be changed.
  5435                                  	;
  5436 00001F07 B90A00                  	mov	cx, 10
  5437                                  btd_0:
  5438                                  	; DX_AX = Dividend
  5439                                  	; CX = Divisor
  5440 00001F0A E865EF                  	call	div32
  5441                                  	; DX_AX = Quotient
  5442                                  	; BX = remainder
  5443 00001F0D 80C330                  	add	bl, '0'
  5444 00001F10 881C                    	mov	[si], bl
  5445 00001F12 21D2                    	and	dx, dx
  5446 00001F14 7403                    	jz	short btd_2
  5447                                  btd_1:
  5448 00001F16 4E                      	dec	si
  5449 00001F17 EBF1                    	jmp	short btd_0
  5450                                  btd_2:
  5451 00001F19 09C0                    	or	ax, ax
  5452 00001F1B 75F9                    	jnz	short btd_1
  5453                                  
  5454 00001F1D C3                      	retn
  5455                                  
  5456                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5457                                  ; Convert byte to hexadecimal number
  5458                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5459                                  
  5460                                  byte_to_hex: ; 04/02/2019
  5461                                  bin_to_hex:
  5462                                  	; INPUT ->
  5463                                  	; 	AL = byte (binary number)
  5464                                  	; OUTPUT ->
  5465                                  	;	AX = hexadecimal string
  5466                                  	;
  5467 00001F1E 53                      	push	bx
  5468 00001F1F 31DB                    	xor	bx, bx
  5469 00001F21 88C3                    	mov	bl, al
  5470 00001F23 C0EB04                  	shr	bl, 4
  5471 00001F26 8A9F[9441]              	mov	bl, [bx+hexchrs] 	 	
  5472 00001F2A 86D8                    	xchg	bl, al
  5473 00001F2C 80E30F                  	and	bl, 0Fh
  5474 00001F2F 8AA7[9441]              	mov	ah, [bx+hexchrs] 
  5475 00001F33 5B                      	pop	bx	
  5476 00001F34 C3                      	retn
  5477                                  
  5478                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5479                                  ; Read & Write characters
  5480                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5481                                  
  5482                                  rw_char:
  5483                                  	; OUTPUT -> DS:SI = Entered String (ASCIIZ)
  5484 00001F35 BE[BD56]                	mov     si, StrVolumeName
  5485 00001F38 BB0700                  	mov     bx, 7
  5486 00001F3B B403                    	mov     ah, 3
  5487 00001F3D CD10                    	int     10h
  5488 00001F3F 8916[A456]              	mov     [Cursor_Pos], dx
  5489                                  read_next_char:
  5490 00001F43 30E4                    	xor     ah, ah
  5491 00001F45 CD16                    	int     16h
  5492 00001F47 20C0                    	and     al, al
  5493 00001F49 7439                    	jz      short loc_arrow    
  5494 00001F4B 3CE0                    	cmp     al, 0E0h          
  5495 00001F4D 7435                    	je      short loc_arrow
  5496 00001F4F 3C08                    	cmp     al, 8
  5497 00001F51 753D                    	jne     short char_return
  5498                                  loc_back:
  5499 00001F53 B403                    	mov     ah, 3
  5500 00001F55 CD10                    	int     10h
  5501 00001F57 3A16[A456]              	cmp     dl, byte [Cursor_Pos]
  5502 00001F5B 761F                    	jna     short loc_beep
  5503                                  prev_column:
  5504 00001F5D FECA                    	dec     dl
  5505                                  set_cursor_pos:
  5506 00001F5F B402                    	mov     ah, 2
  5507 00001F61 CD10                    	int     10h
  5508 00001F63 88D3                    	mov     bl, dl
  5509 00001F65 2A1E[A456]              	sub     bl, byte [Cursor_Pos] 
  5510 00001F69 B90100                  	mov     cx, 1
  5511 00001F6C B409                    	mov     ah, 9
  5512 00001F6E B020                    	mov     al, 20h
  5513 00001F70 8800                    	mov     [si+bx], al
  5514                                  loc_write_it:
  5515 00001F72 B307                    	mov     bl, 7
  5516 00001F74 CD10                    	int     10h
  5517 00001F76 8B16[A456]              	mov     dx, [Cursor_Pos]
  5518 00001F7A EBC7                    	jmp     short read_next_char
  5519                                  loc_beep:
  5520 00001F7C B40E                    	mov     ah, 0Eh
  5521 00001F7E B007                    	mov     al, 7
  5522 00001F80 CD10                    	int     10h
  5523 00001F82 EBBF                    	jmp     short read_next_char
  5524                                  loc_arrow:    
  5525 00001F84 80FC4B                  	cmp     ah, 4Bh
  5526 00001F87 74CA                    	je      short loc_back
  5527 00001F89 80FC53                  	cmp     ah, 53h
  5528 00001F8C 74C5                    	je      short loc_back
  5529 00001F8E EBB3                    	jmp     short read_next_char
  5530                                  char_return:
  5531 00001F90 B403                    	mov     ah, 3
  5532 00001F92 CD10                    	int     10h
  5533                                  check_char_type:
  5534 00001F94 3C20                    	cmp     al, 20h
  5535 00001F96 7229                    	jb      short loc_escape
  5536 00001F98 88D4                    	mov     ah, dl
  5537 00001F9A 2A26[A456]              	sub     ah, byte [Cursor_Pos]
  5538                                  	;cmp	ah, 10 
  5539                                  	;ja	short loc_beep
  5540 00001F9E 3A26[0367]              	cmp     ah, [vname_length] ; 05/01/2018
  5541 00001FA2 73D8                    	jnb	short loc_beep
  5542 00001FA4 3C7A                    	cmp     al, 'z'
  5543 00001FA6 779B                    	ja      short read_next_char
  5544 00001FA8 3C61                    	cmp     al, 'a'
  5545 00001FAA 7202                    	jb      short pass_capitalize
  5546 00001FAC 24DF                    	and     al, 0DFh
  5547                                  pass_capitalize:
  5548 00001FAE 88E3                    	mov     bl, ah 
  5549 00001FB0 30E4                    	xor     ah, ah
  5550 00001FB2 8900                    	mov     [si+bx], ax
  5551 00001FB4 B307                    	mov     bl, 7
  5552 00001FB6 B40E                    	mov     ah, 0Eh
  5553 00001FB8 CD10                    	int     10h
  5554 00001FBA EB87                    	jmp     short read_next_char
  5555                                  pass_escape:
  5556 00001FBC 3C0D                    	cmp     al, 0Dh	; 13 ; ENTER
  5557 00001FBE 7583                    	jne     short read_next_char
  5558                                  	;mov	ah, 0Eh
  5559                                  	;int	10h
  5560                                  	;mov	al, 0Ah
  5561                                  	;int	10h
  5562 00001FC0 C3                      	retn
  5563                                  loc_escape:
  5564 00001FC1 3C1B                    	cmp     al, 1Bh	; 27 ; ESC
  5565 00001FC3 75F7                    	jne     short pass_escape
  5566 00001FC5 F9                      	stc
  5567 00001FC6 C3                      	retn
  5568                                  
  5569                                  ;-----------------------------------------------------------------------------
  5570                                  
  5571                                  display_chs_table:
  5572 00001FC7 06                      	push	es
  5573 00001FC8 BF00B8                  	mov	di, 0B800h
  5574 00001FCB 8EC7                    	mov	es, di
  5575 00001FCD 31FF                    	xor	di, di
  5576                                  	; 12/02/2019
  5577                                  	; new file ?
  5578 00001FCF 803E[D56F]00            	cmp	byte [existingfile], 0
  5579 00001FD4 7604                    	jna	short dchstbl_1
  5580 00001FD6 81C74001                	add	di, 320 ; skip 2 rows (for the header)
  5581                                  dchstbl_1:
  5582 00001FDA B95000                  	mov	cx, 80
  5583 00001FDD B82007                  	mov	ax, 0720h
  5584 00001FE0 F3AB                    	rep	stosw
  5585 00001FE2 B150                    	mov	cl, 80 
  5586 00001FE4 B02D                    	mov	al, "-"
  5587 00001FE6 F3AB                    	rep	stosw
  5588 00001FE8 B113                    	mov	cl, 19
  5589 00001FEA B020                    	mov	al, 20h
  5590 00001FEC F3AB                    	rep	stosw
  5591 00001FEE B043                    	mov	al, 'C'
  5592 00001FF0 AB                      	stosw
  5593 00001FF1 B079                    	mov	al, 'y'
  5594 00001FF3 AB                      	stosw
  5595 00001FF4 B06C                    	mov	al, 'l'
  5596 00001FF6 AB                      	stosw
  5597 00001FF7 B069                    	mov	al, 'i'
  5598 00001FF9 AB                       	stosw
  5599 00001FFA B06E                    	mov	al, 'n'
  5600 00001FFC AB                      	stosw	
  5601 00001FFD B064                    	mov	al, 'd'
  5602 00001FFF AB                      	stosw
  5603 00002000 B065                    	mov	al, 'e'
  5604 00002002 AB                      	stosw
  5605 00002003 B072                    	mov	al, 'r'
  5606 00002005 AB                       	stosw
  5607 00002006 B073                    	mov	al, 's'
  5608 00002008 AB                       	stosw
  5609 00002009 B03A                    	mov	al, ':'
  5610 0000200B AB                      	stosw
  5611 0000200C B020                    	mov	al, 20h
  5612 0000200E AB                      	stosw
  5613                                  	;mov	[cylnumpos], di
  5614 0000200F A1[AA41]                	mov	ax, [cylinders]
  5615 00002012 B104                    	mov	cl, 4
  5616 00002014 B543                    	mov	ch, 'C'
  5617 00002016 E88400                  	call	write_number
  5618                                  	
  5619 00002019 B82007                  	mov	ax, 0720h
  5620 0000201C AB                      	stosw
  5621 0000201D AB                      	stosw
  5622 0000201E B048                    	mov	al, 'H'
  5623 00002020 AB                      	stosw
  5624 00002021 B065                    	mov	al, 'e'
  5625 00002023 AB                      	stosw
  5626 00002024 B061                    	mov	al, 'a'
  5627 00002026 AB                      	stosw
  5628 00002027 B064                    	mov	al, 'd'
  5629 00002029 AB                       	stosw
  5630 0000202A B073                    	mov	al, 's'
  5631 0000202C AB                       	stosw
  5632 0000202D B03A                    	mov	al, ':'
  5633 0000202F AB                      	stosw
  5634 00002030 B020                    	mov	al, 20h
  5635 00002032 AB                      	stosw
  5636                                  	;mov	[hednumpos], di
  5637 00002033 A1[A841]                	mov	ax, [heads]
  5638 00002036 B102                    	mov	cl, 2
  5639 00002038 B548                    	mov	ch, 'H'
  5640 0000203A E86000                  	call	write_number
  5641                                  
  5642 0000203D B82007                  	mov	ax, 0720h
  5643 00002040 AB                      	stosw
  5644 00002041 AB                      	stosw
  5645 00002042 B053                    	mov	al, 'S'
  5646 00002044 AB                      	stosw
  5647 00002045 B065                    	mov	al, 'e'
  5648 00002047 AB                      	stosw
  5649 00002048 B063                    	mov	al, 'c'
  5650 0000204A AB                      	stosw
  5651 0000204B B074                    	mov	al, 't'
  5652 0000204D AB                       	stosw
  5653 0000204E B06F                    	mov	al, 'o'
  5654 00002050 AB                      	stosw
  5655 00002051 B072                    	mov	al, 'r'
  5656 00002053 AB                       	stosw
  5657 00002054 B073                    	mov	al, 's'
  5658 00002056 AB                       	stosw
  5659 00002057 B03A                    	mov	al, ':'
  5660 00002059 AB                      	stosw
  5661 0000205A B020                    	mov	al, 20h
  5662 0000205C AB                      	stosw
  5663                                  	;mov	[secnumpos], di
  5664 0000205D A1[A641]                	mov	ax, [sectors]
  5665 00002060 B102                    	mov	cl, 2
  5666 00002062 B553                    	mov	ch, 'S'
  5667 00002064 E83600                  	call	write_number
  5668                                  
  5669 00002067 B116                    	mov	cl, 22
  5670 00002069 B82007                  	mov	ax, 0720h
  5671 0000206C F3AB                    	rep	stosw
  5672                                  	
  5673 0000206E B150                    	mov	cl, 80 
  5674 00002070 B02D                    	mov	al, "-"
  5675 00002072 F3AB                    	rep	stosw
  5676                                  
  5677                                  	;mov	cl, 80
  5678 00002074 B1A0                    	mov	cl, 160 ; 11/02/2019
  5679 00002076 B020                    	mov	al, 20h
  5680 00002078 F3AB                    	rep	stosw
  5681                                  
  5682 0000207A BA0006                  	mov	dx, 0600h ; DH = row, DL = 0 column
  5683 0000207D 31DB                    	xor	bx, bx ; BH = video page (0)
  5684 0000207F B402                    	mov	ah, 02h ; set cursor position
  5685 00002081 CD10                    	int	10h
  5686                                  
  5687                                  	; 12/02/2019
  5688                                  	; new file ?
  5689 00002083 380E[D56F]              	cmp	byte [existingfile], cl ; 0
  5690 00002087 7712                    	ja	short dchstbl_2
  5691                                  
  5692 00002089 81C7A005                	add	di, 9*160 ; 9 rows (CHS_msg)
  5693                                  
  5694 0000208D BE[D942]                	mov	si, CHS_msg
  5695 00002090 E8ECFD                  	call	print_msg
  5696                                  
  5697 00002093 B92003                  	mov	cx, 10*80
  5698 00002096 B82007                  	mov	ax, 0720h
  5699 00002099 F3AB                    	rep	stosw
  5700                                  dchstbl_2:
  5701 0000209B 07                      	pop	es
  5702 0000209C C3                      	retn
  5703                                  
  5704                                  ;-----------------------------------------------------------------------------
  5705                                  
  5706                                  write_number:
  5707 0000209D 89CE                    	mov	si, cx
  5708 0000209F 31D2                    	xor	dx, dx
  5709 000020A1 BB0A00                  	mov	bx, 10
  5710                                  wnum_1:
  5711 000020A4 F7F3                    	div	bx
  5712 000020A6 52                      	push	dx
  5713 000020A7 31D2                    	xor	dx, dx
  5714 000020A9 FEC9                    	dec	cl
  5715 000020AB 75F7                    	jnz	short wnum_1
  5716 000020AD 89F1                    	mov	cx, si
  5717 000020AF B407                    	mov	ah, 07h
  5718 000020B1 88E8                    	mov	al, ch
  5719 000020B3 30ED                    	xor	ch, ch
  5720 000020B5 3806[B36F]              	cmp	byte [chs_focus], al
  5721 000020B9 7502                    	jne	short wnum_2
  5722 000020BB B40F                    	mov	ah, 0Fh
  5723                                  wnum_2:
  5724 000020BD 5A                      	pop	dx
  5725 000020BE 88D0                    	mov	al, dl
  5726 000020C0 0430                    	add	al, '0'
  5727 000020C2 AB                      	stosw
  5728 000020C3 E2F8                    	loop	wnum_2
  5729 000020C5 C3                      	retn
  5730                                  
  5731                                  ;-----------------------------------------------------------------------------
  5732                                  
  5733                                  partition_size_input:
  5734 000020C6 C706[BA6F]0000          	mov	word [pSize_multiplier+2], 0
  5735 000020CC C606[BF6F]42            	mov	byte [msg_psize_unit+1], 'B'
  5736 000020D1 A0[BE6F]                	mov	al, [pSize_unit]
  5737 000020D4 3C25                    	cmp	al, '%'
  5738 000020D6 7523                    	jne	short psu_0
  5739                                  	; 08/02/2019
  5740                                  	; calculate sector count for max. available sectors percentage
  5741 000020D8 8B16[AE6F]              	mov	dx, [pp_Sectors+2] ; max. available sectors
  5742 000020DC A1[AC6F]                	mov	ax, [pp_Sectors]   ; for a new partition
  5743                                  	;mov	dx, [total_sectors+2]
  5744                                  	;mov	ax, [total_sectors]	
  5745 000020DF B96400                  	mov	cx, 100
  5746 000020E2 E88DED                  	call	div32
  5747 000020E5 A3[B86F]                	mov	[pSize_multiplier], ax
  5748                                  	; 29/10/2020
  5749 000020E8 8916[BA6F]              	mov	[pSize_multiplier+2], dx
  5750 000020EC B400                    	mov	ah, 0
  5751 000020EE 8826[BF6F]              	mov	[msg_psize_unit+1], ah
  5752                                  	;mov	byte [pSize_maxdigits], 2
  5753 000020F2 C606[BC6F]03            	mov	byte [pSize_maxdigits], 3 ; 29/10/2020
  5754 000020F7 B025                    	mov	al, '%'
  5755 000020F9 EB60                    	jmp	short psu_6
  5756                                  psu_0:
  5757 000020FB 3C43                    	cmp	al, 'C'
  5758 000020FD 7517                    	jne	short psu_1
  5759 000020FF A1[A641]                	mov	ax, [sectors]
  5760 00002102 F726[A841]              	mul	word [heads]
  5761 00002106 A3[B86F]                	mov	[pSize_multiplier], ax	
  5762 00002109 C606[BC6F]04            	mov	byte [pSize_maxdigits], 4
  5763                                  	;sub	dh, dh
  5764 0000210E 8836[BF6F]              	mov	[msg_psize_unit+1], dh
  5765 00002112 B043                    	mov	al, 'C'
  5766 00002114 EB45                    	jmp	short psu_6	
  5767                                  psu_1:
  5768 00002116 3C47                    	cmp	al, 'G'
  5769 00002118 7513                    	jne	short psu_2
  5770 0000211A C706[B86F]0008          	mov	word [pSize_multiplier], 2*1024
  5771 00002120 C706[BA6F]0004          	mov	word [pSize_multiplier+2], 1024
  5772 00002126 C606[BC6F]01            	mov	byte [pSize_maxdigits], 1
  5773 0000212B EB2E                    	jmp	short psu_6
  5774                                  psu_2:
  5775 0000212D 3C4D                    	cmp	al, 'M'
  5776 0000212F 750D                    	jne	short psu_3
  5777 00002131 C706[B86F]0008          	mov	word [pSize_multiplier], 2*1024
  5778 00002137 C606[BC6F]04            	mov	byte [pSize_maxdigits], 4
  5779 0000213C EB1D                    	jmp	short psu_6
  5780                                  psu_3:
  5781 0000213E 3C4B                    	cmp	al, 'K'
  5782 00002140 7508                    	jne	short psu_4
  5783 00002142 C706[B86F]0200          	mov	word [pSize_multiplier], 2
  5784 00002148 EB0C                    	jmp	short psu_5	
  5785                                  psu_4:
  5786                                  	; al = 'S'
  5787 0000214A 30E4                    	xor	ah, ah
  5788 0000214C 8826[BF6F]              	mov	[msg_psize_unit+1], ah
  5789 00002150 C706[B86F]0100          	mov	word [pSize_multiplier], 1
  5790                                  psu_5:
  5791 00002156 C606[BC6F]07            	mov	byte [pSize_maxdigits], 7
  5792                                  psu_6:
  5793 0000215B A2[9C50]                	mov	[msg_partition_size_x], al
  5794 0000215E BE[8850]                	mov	si, msg_partition_size	
  5795 00002161 E81BFD                  	call	print_msg
  5796                                  
  5797 00002164 89E5                    	mov	bp, sp
  5798 00002166 31DB                    	xor	bx, bx
  5799 00002168 891E[B46F]              	mov	[pSize_temp], bx ; 0
  5800                                  	;mov	[pSize_temp+2], bx ; 0
  5801 0000216C 881E[BD6F]              	mov	[pSize_digitpos], bl ; 0
  5802                                  	; bh = 0  ; video page
  5803 00002170 B403                    	mov     ah, 3 ; get cursor pos
  5804 00002172 CD10                    	int     10h
  5805 00002174 8916[A456]              	mov	[Cursor_Pos], dx
  5806                                  	; 09/02/2019
  5807 00002178 B307                    	mov     bl, 7   ; page 0, color 7 (light gray)   
  5808                                  psu_7:
  5809 0000217A 30E4                    	xor	ah, ah
  5810 0000217C CD16                    	int	16h
  5811                                  
  5812 0000217E 3C30                    	cmp	al, '0'
  5813 00002180 7225                    	jb	short psu_8
  5814 00002182 3C39                    	cmp	al, '9'
  5815 00002184 77F4                    	ja	short psu_7
  5816 00002186 8A1E[BD6F]              	mov	bl, [pSize_digitpos]
  5817 0000218A 3A1E[BC6F]              	cmp	bl, [pSize_maxdigits]
  5818 0000218E 73EA                    	jnb	short psu_7
  5819 00002190 FE06[BD6F]              	inc	byte [pSize_digitpos]
  5820 00002194 2C30                    	sub	al, '0'
  5821 00002196 30E4                    	xor	ah, ah
  5822 00002198 50                      	push	ax
  5823 00002199 0430                    	add	al, '0'
  5824 0000219B B40E                    	mov	ah, 0Eh	; write char as tty		
  5825                                  	;mov	bx, 7   ; page 0, color 7 (light gray)         
  5826 0000219D CD10                    	int	10h
  5827 0000219F EBD9                    	jmp	short psu_7
  5828                                  psu_8esc:
  5829                                  	; 29/10/2020 (ESCape)
  5830 000021A1 89EC                    	mov	sp, bp ; clean stack
  5831                                  
  5832 000021A3 08C0                    	or	al, al ; zf = 0
  5833 000021A5 F9                      	stc
  5834 000021A6 C3                      	retn	
  5835                                  psu_8:
  5836 000021A7 20C0                    	and	al, al
  5837 000021A9 0F849300                	jz	psu_15 ; check for left arrow key 
  5838 000021AD 3C1B                    	cmp	al, 27
  5839 000021AF 74F0                    	je	short psu_8esc ; ESCAPE key ; 29/10/2020
  5840 000021B1 0F878500                	ja	psu_14 ; check for left arrow key
  5841 000021B5 3C0D                    	cmp	al, 13
  5842                                  	;je	short psu_9  ; ENTER key
  5843 000021B7 7249                    	jb	short psu_11 ; check for backspace key
  5844                                  	;jmp	short psu_7
  5845 000021B9 77BF                    	ja	short psu_7
  5846                                  psu_9:
  5847 000021BB 31C0                    	xor	ax, ax
  5848 000021BD A3[B66F]                	mov	[pSize_temp+2], ax ; 0 ; 08/02/2019
  5849 000021C0 3806[BD6F]              	cmp	byte [pSize_digitpos], al ; 0
  5850 000021C4 0F868500                	jna	psu_16		
  5851                                  	;xor	bh, bh
  5852 000021C8 8A1E[BD6F]              	mov	bl, [pSize_digitpos]
  5853 000021CC FECB                    	dec	bl
  5854 000021CE D0E3                    	shl	bl, 1
  5855 000021D0 01E3                    	add	bx, sp
  5856 000021D2 8B07                    	mov	ax, [bx]
  5857 000021D4 A3[B46F]                	mov	[pSize_temp], ax
  5858                                  	;mov	word [pSize_temp+2], 0
  5859 000021D7 B90A00                  	mov	cx, 10
  5860                                  psu_10:
  5861 000021DA FE0E[BD6F]              	dec	byte [pSize_digitpos]
  5862 000021DE 746D                    	jz	short psu_16
  5863                                  	
  5864 000021E0 A1[B46F]                	mov	ax, [pSize_temp]
  5865 000021E3 8B16[B66F]              	mov	dx, [pSize_temp+2]
  5866                                  	;mov	cx, 10
  5867 000021E7 E896EC                  	call	mul32
  5868                                  	;mov	[pSize_temp], ax
  5869                                  	;mov	[pSize_temp+2], dx
  5870                                  	;xor	bh, bh
  5871 000021EA 8A1E[BD6F]              	mov	bl, [pSize_digitpos]
  5872 000021EE FECB                    	dec	bl
  5873 000021F0 D0E3                    	shl	bl, 1
  5874 000021F2 01E3                    	add	bx, sp ; (*)
  5875                                  	;mov	ax, [bx]
  5876                                  	;add	[pSize_temp], ax
  5877                                  	;adc	word [pSize_temp+2], 0
  5878 000021F4 0307                    	add	ax, [bx]
  5879 000021F6 83D200                  	adc	dx, 0
  5880 000021F9 A3[B46F]                	mov	[pSize_temp], ax
  5881 000021FC 8916[B66F]              	mov	[pSize_temp+2], dx
  5882 00002200 EBD8                    	jmp	short psu_10
  5883                                  	
  5884                                  	; Left arrow, backspace, DEL key checking
  5885                                  psu_11:
  5886 00002202 3C08                    	cmp	al, 8 ; backspace key
  5887 00002204 0F8572FF                	jne	psu_7
  5888                                  psu_12:
  5889                                  	;; bh = 0  ; video page
  5890                                  	;mov	ah, 3 ; get cursor pos
  5891                                  	;int	10h
  5892                                  	;cmp	dl, [Cursor_Pos]
  5893                                  	;jna	short psu_13
  5894                                  	;dec	dl
  5895                                  	;dec	byte [pSize_digitpos]
  5896                                  
  5897                                  	; 08/02/2019
  5898 00002208 8B16[A456]              	mov	dx, [Cursor_Pos]
  5899 0000220C 8A1E[BD6F]              	mov	bl, [pSize_digitpos]
  5900 00002210 20DB                    	and	bl, bl
  5901 00002212 741D                    	jz	short psu_13	
  5902                                  
  5903 00002214 FECB                    	dec	bl 
  5904 00002216 881E[BD6F]              	mov	[pSize_digitpos], bl
  5905                                  	
  5906 0000221A 00DA                    	add	dl, bl
  5907                                  
  5908                                  	; bh = 0  ; video page
  5909 0000221C B402                    	mov	ah, 2 ; set cursor pos
  5910 0000221E CD10                    	int	10h
  5911                                  	;mov	bl, dl
  5912                                  	;sub	bl, [Cursor_Pos] 
  5913 00002220 B90100                  	mov	cx, 1
  5914 00002223 B409                    	mov	ah, 9 ; write char at current curs pos
  5915 00002225 B020                    	mov	al, 20h ; space (blank)
  5916 00002227 8800                    	mov	[si+bx], al
  5917                                  	; bh = 0 ; video page
  5918 00002229 B307                    	mov	bl, 7 ; attribute/color (light gray)
  5919 0000222B CD10                    	int	10h
  5920                                  
  5921                                  	; 09/02/2019
  5922 0000222D 58                      	pop	ax ; remove last digit on top of stack 
  5923                                  		   ; set sp to correct position for BX (*)	
  5924 0000222E E949FF                  	jmp	psu_7
  5925                                  psu_13:
  5926 00002231 B40E                    	mov	ah, 0Eh
  5927 00002233 B007                    	mov	al, 7
  5928                                  	;mov	bx, 7
  5929 00002235 CD10                    	int	10h
  5930 00002237 E940FF                  	jmp	psu_7
  5931                                  psu_14:
  5932 0000223A 3CE0                    	cmp	al, 0E0h          
  5933 0000223C 0F853AFF                	jne	psu_7
  5934                                  psu_15:    
  5935 00002240 80FC4B                  	cmp	ah, 4Bh ; left arrow
  5936 00002243 74C3                    	je	short psu_12
  5937 00002245 80FC53                  	cmp	ah, 53h ; DEL key (backspace)
  5938 00002248 74BE                    	je	short psu_12
  5939 0000224A E92DFF                  	jmp	psu_7
  5940                                  psu_16:
  5941 0000224D 89EC                    	mov	sp, bp
  5942                                  
  5943                                  	; 29/10/2020
  5944 0000224F 803E[BE6F]25            	cmp	byte [pSize_unit], '%'
  5945 00002254 7519                    	jne	short psu_23
  5946                                  
  5947 00002256 833E[B46F]64            	cmp	word [pSize_temp], 100 ; 100% limit
  5948 0000225B 7621                    	jna	short psu_17
  5949                                  
  5950                                  	; (re)set asciiz number string to '100' 
  5951                                  
  5952 0000225D 28FF                    	sub	bh, bh ; 0 ; video page 0
  5953 0000225F 8B16[A456]              	mov	dx, [Cursor_Pos]
  5954 00002263 B402                    	mov	ah, 2 ; set cursor pos
  5955 00002265 CD10                    	int	10h
  5956                                  
  5957 00002267 BE[1A6B]                	mov	si, msg_100
  5958 0000226A E812FC                  	call	print_msg
  5959                                  
  5960 0000226D EB0F                    	jmp	short psu_17
  5961                                  psu_23:
  5962 0000226F 803E[BE6F]53            	cmp	byte [pSize_unit], 'S'
  5963 00002274 7508                    	jne	short psu_17 
  5964                                  
  5965 00002276 BE[F866]                	mov	si, msg_sectors_crlf
  5966 00002279 E803FC                  	call	print_msg
  5967                                  	;xor	bx, bx
  5968 0000227C EB30                    	jmp	short psu_18
  5969                                  psu_17:
  5970 0000227E BE[BE6F]                	mov	si, msg_psize_unit
  5971 00002281 E8FBFB                  	call	print_msg
  5972                                  
  5973 00002284 BE[6057]                	mov	si, CRLF
  5974 00002287 E8F5FB                  	call	print_msg
  5975                                  
  5976                                  	; 29/10/2020
  5977 0000228A 803E[BE6F]25            	cmp	byte [pSize_unit], '%'
  5978 0000228F 751D                    	jne	short psu_18
  5979                                  	
  5980 00002291 8B0E[B46F]              	mov	cx, [pSize_temp]
  5981                                  
  5982 00002295 21C9                    	and	cx, cx
  5983 00002297 7443                    	jz	short psu_21 ; 0%, ZERO !
  5984                                  
  5985 00002299 83F964                  	cmp	cx, 100
  5986 0000229C 7606                    	jna	short psu_24
  5987                                  
  5988                                  	; show 100% for 1 second (for >100%)
  5989 0000229E E83D00                  	call	wait1second ; 29/10/2020
  5990                                  
  5991 000022A1 B96400                  	mov	cx, 100
  5992                                  psu_24:
  5993 000022A4 A1[B86F]                	mov	ax, [pSize_multiplier]
  5994 000022A7 8B16[BA6F]              	mov	dx, [pSize_multiplier+2]
  5995                                  
  5996                                  	;mov	cx, [pSize_temp]
  5997                                  	;and	cx, cx
  5998                                  	;jz	short psu_21 ; 0%, ZERO !
  5999                                  
  6000 000022AB E9D2EB                  	jmp	mul32
  6001                                  psu_18:
  6002 000022AE A1[B46F]                	mov	ax, [pSize_temp]
  6003 000022B1 8B16[B66F]              	mov	dx, [pSize_temp+2]
  6004 000022B5 89C1                    	mov	cx, ax
  6005 000022B7 09D1                    	or	cx, dx
  6006                                  	;jz	short psu_20
  6007 000022B9 7421                    	jz	short psu_21 ; 08/02/2019
  6008 000022BB 8B0E[B86F]              	mov	cx, [pSize_multiplier]
  6009 000022BF 803E[BE6F]43            	cmp	byte [pSize_unit], 'C'
  6010 000022C4 7413                    	je	short psu_20 ; 09/02/2019
  6011                                  	;jne	short psu_19
  6012                                  	;call	mul32
  6013                                  	; 08/02/2019
  6014                                  	; dx:ax = requested partition size in sectors
  6015                                  	;retn	
  6016                                  ;psu_19:
  6017                                  	;mov	cx, [pSize_multiplier]
  6018 000022C6 83F901                  	cmp	cx, 1
  6019                                  	;jna	short psu_20
  6020 000022C9 7703                    	ja	short psu_19
  6021                                  	; 09/02/2019
  6022 000022CB 31DB                    	xor	bx, bx
  6023 000022CD C3                      	retn
  6024                                  psu_19:
  6025 000022CE E8AFEB                  	call	mul32
  6026                                  	;and	bx, bx
  6027                                  	;jnz	short psu_22 ; 09/02/2019	
  6028 000022D1 8B0E[BA6F]              	mov	cx, [pSize_multiplier+2]
  6029 000022D5 09C9                    	or	cx, cx
  6030                                  	;jz	short psu_20
  6031 000022D7 7404                    	jz	short psu_22 ; 09/02/2019
  6032                                  psu_20:
  6033                                  	;call	mul32
  6034                                  	;retn
  6035                                  	; 29/10/2020
  6036 000022D9 E9A4EB                  	jmp	mul32
  6037                                  psu_21:
  6038                                  	; zf = 1 ; 29/10/2020
  6039 000022DC F9                      	stc
  6040                                  psu_22:
  6041 000022DD C3                      	retn
  6042                                  
  6043                                  ;-----------------------------------------------------------------------------
  6044                                  
  6045                                  	; 29/10/2020
  6046                                  wait1second:
  6047 000022DE B402                    	mov	ah, 2
  6048 000022E0 CD1A                    	int	1Ah ; get time of day
  6049 000022E2 720C                    	jc	short w1s_2
  6050                                  w1s_1:
  6051 000022E4 52                      	push	dx
  6052 000022E5 B402                    	mov	ah, 2
  6053 000022E7 CD1A                    	int	1Ah ; get time of day
  6054 000022E9 58                      	pop	ax
  6055 000022EA 7204                    	jc	short w1s_2
  6056 000022EC 38E6                    	cmp	dh, ah
  6057 000022EE 74F4                    	je	short w1s_1 ; same second
  6058                                  w1s_2:
  6059 000022F0 C3                      	retn
  6060                                  
  6061                                  ;-----------------------------------------------------------------------------
  6062                                  
  6063                                  partition_type_input:
  6064 000022F1 BE[A250]                	mov	si, msg_partition_type	
  6065 000022F4 E888FB                  	call	print_msg
  6066                                  
  6067 000022F7 31DB                    	xor	bx, bx
  6068                                  
  6069 000022F9 881E[CE6F]              	mov	[pType_pos], bl ; 0
  6070 000022FD 891E[CF6F]              	mov	[pType_num], bx ; 0
  6071                                  
  6072                                  	; bh = 0  ; video page
  6073 00002301 B403                    	mov     ah, 3 ; get cursor pos
  6074 00002303 CD10                    	int     10h
  6075 00002305 8916[A456]              	mov	[Cursor_Pos], dx
  6076                                  ptu_0:
  6077 00002309 30E4                    	xor	ah, ah
  6078 0000230B CD16                    	int	16h
  6079                                  
  6080 0000230D 803E[CE6F]01            	cmp	byte [pType_pos], 1
  6081 00002312 773F                    	ja	short ptu_5	
  6082                                  
  6083 00002314 3C30                    	cmp	al, '0'
  6084 00002316 723B                    	jb	short ptu_5
  6085 00002318 3C39                    	cmp	al, '9'
  6086 0000231A 7707                    	ja	short ptu_1
  6087 0000231C 88C4                    	mov	ah, al
  6088 0000231E 80EC30                  	sub	ah, '0'
  6089 00002321 EB13                    	jmp	short ptu_2 
  6090                                  ptu_1:
  6091 00002323 3CE0                    	cmp     al, 0E0h          
  6092 00002325 7473                    	je	short ptu_9
  6093                                  
  6094 00002327 24DF                    	and	al, 0DFh
  6095 00002329 3C41                    	cmp	al, 'A'
  6096 0000232B 72DC                    	jb	short ptu_0
  6097 0000232D 3C46                    	cmp	al, 'F'
  6098 0000232F 77D8                    	ja	short ptu_0
  6099 00002331 88C4                    	mov	ah, al
  6100 00002333 80EC37                  	sub	ah, 'A'-10
  6101                                  ptu_2:
  6102 00002336 803E[CE6F]00            	cmp	byte [pType_pos], 0
  6103 0000233B 7606                    	jna	short ptu_3
  6104 0000233D 8826[D06F]              	mov	[pType_num+1], ah
  6105 00002341 EB04                    	jmp	short ptu_4 
  6106                                  ptu_3:
  6107 00002343 8826[CF6F]              	mov	[pType_num], ah
  6108                                  ptu_4:
  6109 00002347 B40E                    	mov	ah, 0Eh
  6110 00002349 B307                    	mov	bl, 7
  6111 0000234B CD10                    	int	10h
  6112                                  
  6113 0000234D FE06[CE6F]              	inc	byte [pType_pos]
  6114                                  
  6115 00002351 EBB6                    	jmp	short ptu_0 
  6116                                  ptu_5:
  6117 00002353 20C0                    	and	al, al
  6118 00002355 7443                    	jz	short ptu_9 ; check for left arrow key 
  6119 00002357 3C1B                    	cmp	al, 27
  6120 00002359 744C                    	je	short ptu_10 ; ESCAPE key
  6121 0000235B 77AC                    	ja	short ptu_0
  6122 0000235D 3C0D                    	cmp	al, 13
  6123 0000235F 744A                    	je	short ptu_11  ; ENTER key
  6124 00002361 77A6                    	ja	short ptu_0
  6125                                  ptu_6:
  6126                                  	; Left arrow, backspace, DEL key checking
  6127                                  
  6128 00002363 3C08                    	cmp	al, 8 ; backspace key
  6129 00002365 75A2                    	jne	short ptu_0
  6130                                  ptu_7:
  6131                                  	; bh = 0  ; video page
  6132 00002367 B403                    	mov	ah, 3 ; get cursor pos
  6133 00002369 CD10                    	int	10h
  6134 0000236B 3A16[A456]              	cmp	dl, [Cursor_Pos]
  6135 0000236F 7620                    	jna	short ptu_8
  6136 00002371 FECA                    	dec	dl
  6137 00002373 FE0E[CE6F]              	dec	byte [pType_pos]
  6138                                  	; bh = 0  ; video page
  6139 00002377 B402                    	mov	ah, 2 ; set cursor pos
  6140 00002379 CD10                    	int	10h
  6141 0000237B 88D3                    	mov	bl, dl
  6142 0000237D 2A1E[A456]              	sub	bl, [Cursor_Pos] 
  6143 00002381 B90100                  	mov	cx, 1
  6144 00002384 B409                    	mov	ah, 9 ; write char at current curs pos
  6145 00002386 B020                    	mov	al, 20h ; space (blank)
  6146 00002388 8800                    	mov	[si+bx], al
  6147                                  	; bh = 0 ; video page
  6148 0000238A B307                    	mov	bl, 7 ; attribute/color (light gray)
  6149 0000238C CD10                    	int	10h
  6150 0000238E E978FF                  	jmp	ptu_0
  6151                                  ptu_8:
  6152 00002391 B40E                    	mov	ah, 0Eh
  6153 00002393 B007                    	mov	al, 7
  6154 00002395 CD10                    	int	10h
  6155 00002397 E96FFF                  	jmp	ptu_0
  6156                                  ptu_9:    
  6157 0000239A 80FC4B                  	cmp	ah, 4Bh ; left arrow
  6158 0000239D 74C8                    	je	short ptu_7
  6159 0000239F 80FC53                  	cmp	ah, 53h ; DEL key (backspace)
  6160 000023A2 74C3                    	je	short ptu_7
  6161 000023A4 E962FF                  	jmp	ptu_0
  6162                                  
  6163                                  ptu_10: ; ESCAPE
  6164                                  	;mov	al, 0
  6165                                  	; 29/10/2020
  6166 000023A7 28C0                    	sub	al, al ; 0
  6167                                  	; partition type is 0 (none)
  6168 000023A9 EB12                    	jmp	short ptu_12
  6169                                  ptu_11: ; ENTER
  6170 000023AB A0[CF6F]                	mov	al, [pType_num]
  6171 000023AE 803E[CE6F]01            	cmp	byte [pType_pos], 1
  6172 000023B3 7608                    	jna	short ptu_12
  6173 000023B5 B410                    	mov	ah, 16
  6174 000023B7 F6E4                    	mul	ah
  6175 000023B9 0206[D06F]              	add	al, [pType_num+1]
  6176                                  ptu_12:
  6177 000023BD 50                      	push	ax
  6178 000023BE E85DFB                  	call	bin_to_hex
  6179 000023C1 A3[B850]                	mov	[msg_ptype_num], ax
  6180                                  	; bh = 0  ; video page
  6181 000023C4 B402                    	mov	ah, 2 ; set cursor pos
  6182 000023C6 8B16[A456]              	mov	dx, [Cursor_Pos]
  6183 000023CA CD10                    	int	10h
  6184 000023CC BE[B850]                	mov	si, msg_ptype_num 
  6185 000023CF E8ADFA                  	call	print_msg
  6186 000023D2 58                      	pop	ax
  6187 000023D3 C3                      	retn
  6188                                  
  6189                                  ;-----------------------------------------------------------------------------
  6190                                  
  6191                                  show_selected_partition:
  6192                                  	; INPUT ->
  6193                                  	; 	DS:SI = Partition table row address
  6194                                  		
  6195                                  	pt_s_offset	equ 7
  6196                                  	pt_bh_offset	equ 11
  6197                                  	pt_bs_offset	equ 15
  6198                                  	pt_bc_offset	equ 19
  6199                                  	pt_fs_offset	equ 23
  6200                                  	pt_eh_offset	equ 27
  6201                                  	pt_es_offset	equ 31
  6202                                  	pt_ec_offset	equ 35
  6203                                  	pt_rs_offset	equ 41
  6204                                  	pt_ts_offset	equ 52
  6205                                  	pt_fsn_offset	equ 63
  6206                                  
  6207                                  	; clear screen
  6208 000023D4 B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
  6209 000023D7 CD10                    	int	10h	
  6210                                  
  6211 000023D9 89F0                    	mov	ax, si
  6212 000023DB 2D[F659]                	sub	ax, MasterBootBuff + pTableOffset ; + 446
  6213 000023DE C0E804                  	shr	al, 4 ; from offset to partition number
  6214 000023E1 0431                    	add	al, '1'  ; 1 based partition number (chr)
  6215                                  	; Write partition number to the header location
  6216 000023E3 A2[7852]                	mov	[msg_selected_partition+43], al ; '1' to '4'
  6217                                  	
  6218                                  	; Partition number will be used at formatting stage
  6219 000023E6 A2[4755]                	mov	[partition_num_chr], al ; number + '0'
  6220                                  
  6221 000023E9 B268                    	mov	dl, 'h'
  6222 000023EB 8A04                    	mov	al, [si+ptBootable]
  6223 000023ED E82EFB                  	call	bin_to_hex
  6224 000023F0 A3[9453]                	mov	[pt_row+pt_s_offset], ax
  6225 000023F3 8816[9653]              	mov	[pt_row+pt_s_offset+2], dl ; 'h'	
  6226 000023F7 8A4401                  	mov	al, [si+ptBeginHead]
  6227 000023FA E821FB                  	call	bin_to_hex
  6228 000023FD A3[9853]                	mov	[pt_row+pt_bh_offset], ax
  6229 00002400 8816[9A53]              	mov	[pt_row+pt_bh_offset+2], dl ; 'h'
  6230 00002404 8A4402                  	mov	al, [si+ptBeginSector]
  6231 00002407 E814FB                  	call	bin_to_hex
  6232 0000240A A3[9C53]                	mov	[pt_row+pt_bs_offset], ax
  6233 0000240D 8816[9E53]              	mov	[pt_row+pt_bs_offset+2], dl ; 'h'
  6234 00002411 8A4403                  	mov	al, [si+ptBeginCylinder]
  6235 00002414 E807FB                  	call	bin_to_hex
  6236 00002417 A3[A053]                	mov	[pt_row+pt_bc_offset], ax
  6237 0000241A 8816[A253]              	mov	[pt_row+pt_bc_offset+2], dl ; 'h'
  6238 0000241E 8A4404                  	mov	al, [si+ptFileSystemID]
  6239                                   	; Partition type will be used at formatting stage
  6240 00002421 A2[B26F]                	mov	[pp_type_user], al
  6241 00002424 E8F7FA                  	call	bin_to_hex
  6242 00002427 A3[A453]                	mov	[pt_row+pt_fs_offset], ax
  6243 0000242A 8816[A653]              	mov	[pt_row+pt_fs_offset+2], dl ; 'h'
  6244 0000242E 8A4405                  	mov	al, [si+ptEndHead]
  6245 00002431 E8EAFA                  	call	bin_to_hex
  6246 00002434 A3[A853]                	mov	[pt_row+pt_eh_offset], ax
  6247 00002437 8816[AA53]              	mov	[pt_row+pt_eh_offset+2], dl ; 'h'
  6248 0000243B 8A4406                  	mov	al, [si+ptEndSector]
  6249 0000243E E8DDFA                  	call	bin_to_hex
  6250 00002441 A3[AC53]                	mov	[pt_row+pt_es_offset], ax
  6251 00002444 8816[AE53]              	mov	[pt_row+pt_es_offset+2], dl ; 'h'
  6252 00002448 8A4407                  	mov	al, [si+ptEndCylinder]
  6253 0000244B E8D0FA                  	call	bin_to_hex
  6254 0000244E A3[B053]                	mov	[pt_row+pt_ec_offset], ax
  6255 00002451 8816[B253]              	mov	[pt_row+pt_ec_offset+2], dl ; 'h'
  6256 00002455 8A4408                  	mov	al, [si+ptStartSector]
  6257 00002458 E8C3FA                  	call	bin_to_hex
  6258 0000245B A3[BC53]                	mov	[pt_row+pt_rs_offset+6], ax
  6259 0000245E 8816[BE53]              	mov	[pt_row+pt_rs_offset+8], dl ; 'h'
  6260 00002462 8A4409                  	mov	al, [si+ptStartSector+1]
  6261 00002465 E8B6FA                  	call	bin_to_hex
  6262 00002468 A3[BA53]                	mov	[pt_row+pt_rs_offset+4], ax
  6263 0000246B 8A440A                  	mov	al, [si+ptStartSector+2]
  6264 0000246E E8ADFA                  	call	bin_to_hex
  6265 00002471 A3[B853]                	mov	[pt_row+pt_rs_offset+2], ax
  6266 00002474 8A440B                  	mov	al, [si+ptStartSector+3]
  6267 00002477 E8A4FA                  	call	bin_to_hex
  6268 0000247A A3[B653]                	mov	[pt_row+pt_rs_offset], ax
  6269 0000247D 8A440C                  	mov	al, [si+ptSectors]
  6270 00002480 E89BFA                  	call	bin_to_hex
  6271 00002483 A3[C753]                	mov	[pt_row+pt_ts_offset+6], ax
  6272 00002486 8816[C953]              	mov	[pt_row+pt_ts_offset+8], dl ; 'h'
  6273 0000248A 8A440D                  	mov	al, [si+ptSectors+1]
  6274 0000248D E88EFA                  	call	bin_to_hex
  6275 00002490 A3[C553]                	mov	[pt_row+pt_ts_offset+4], ax
  6276 00002493 8A440E                  	mov	al, [si+ptSectors+2]
  6277 00002496 E885FA                  	call	bin_to_hex
  6278 00002499 A3[C353]                	mov	[pt_row+pt_ts_offset+2], ax
  6279 0000249C 8A440F                  	mov	al, [si+ptSectors+3]
  6280 0000249F E87CFA                  	call	bin_to_hex
  6281 000024A2 A3[C153]                	mov	[pt_row+pt_ts_offset], ax
  6282                                  
  6283 000024A5 8A4404                  	mov	al, [si+ptFileSystemID]
  6284 000024A8 BF[C642]                	mov	di, valid_partitions
  6285 000024AB B91300                  	mov	cx, 19
  6286 000024AE F2AE                    	repnz	scasb
  6287 000024B0 7405                    	jz	short ssp_1
  6288 000024B2 B8[B842]                	mov	ax, FS_OTHERS	 
  6289 000024B5 EB0C                    	jmp	short ssp_2
  6290                                  ssp_1:
  6291 000024B7 81EF[C742]              	sub	di, valid_partitions + 1
  6292 000024BB B80E00                  	mov	ax, 14
  6293 000024BE F7E7                    	mul	di
  6294 000024C0 05[AE41]                	add	ax, FileSys_Names
  6295                                  ssp_2:
  6296 000024C3 96                      	xchg	ax, si 
  6297 000024C4 B107                    	mov	cl, 7
  6298 000024C6 BF[CC53]                	mov	di, pt_row + pt_fsn_offset
  6299 000024C9 F3A5                    	rep	movsw
  6300 000024CB 89C7                    	mov	di, ax ; partition table row address
  6301                                  
  6302 000024CD BE[4D52]                	mov	si, msg_selected_partition
  6303 000024D0 E8ACF9                  	call	print_msg
  6304                                  
  6305 000024D3 BE[2E54]                	mov	si, msg_boot_indicator
  6306 000024D6 E8A6F9                  	call	print_msg
  6307 000024D9 BE[035F]                	mov	si, msg_YES
  6308 000024DC F60580                  	test	byte [di+ptBootable], 80h
  6309 000024DF 7503                    	jnz	short ssp_3
  6310 000024E1 BE[095F]                	mov	si, msg_NO
  6311                                  ssp_3:
  6312 000024E4 E898F9                  	call	print_msg
  6313                                  
  6314 000024E7 BE[4654]                	mov	si, msg_starting_head
  6315 000024EA E892F9                  	call	print_msg
  6316 000024ED 8A4501                  	mov	al, [di+ptBeginHead]
  6317 000024F0 E8B200                  	call	write_byte_decimal
  6318 000024F3 E889F9                  	call	print_msg
  6319 000024F6 BE[5E54]                	mov	si, msg_starting_sector
  6320 000024F9 E883F9                  	call	print_msg
  6321 000024FC 8A4502                  	mov	al, [di+ptBeginSector]
  6322 000024FF 88C2                    	mov	dl, al  ; bits 7&8 are bits 8&9 of cyl
  6323 00002501 243F                    	and	al, 3Fh ; sector number, 1 to 63
  6324 00002503 E89F00                  	call	write_byte_decimal			
  6325 00002506 E876F9                  	call	print_msg	
  6326 00002509 BE[7654]                	mov	si, msg_starting_cylinder
  6327 0000250C E870F9                  	call	print_msg
  6328 0000250F 8A4503                  	mov	al, [di+ptBeginCylinder] ; bits 0to7 of cyl
  6329 00002512 C0EA06                  	shr	dl, 6 ; bits 8&9 of cyl
  6330 00002515 88D4                    	mov	ah, dl
  6331 00002517 31D2                    	xor	dx, dx
  6332 00002519 BE[CB6F]                	mov	si, msg_partition_sectors + 7 ; max. 7 digits
  6333                                  	; dx_ax: binary number
  6334 0000251C E8E8F9                  	call	bin_to_decimal
  6335                                  	; ds:si = decimal number text address		
  6336 0000251F E85DF9                  	call	print_msg
  6337 00002522 BE[8E54]                	mov	si, msg_system_id
  6338 00002525 E857F9                  	call	print_msg
  6339                                  	; Write file system name (again, copy)
  6340 00002528 BE[CC53]                	mov	si, pt_row + pt_fsn_offset
  6341                                  	;mov	cx, 14
  6342 0000252B B10E                    	mov	cl, 14
  6343 0000252D B40E                    	mov	ah, 0Eh ; write tty
  6344 0000252F BB0700                  	mov	bx, 7
  6345                                  ssp_4:	 
  6346 00002532 AC                      	lodsb
  6347 00002533 CD10                    	int	10h
  6348 00002535 E2FB                    	loop	ssp_4
  6349                                  
  6350 00002537 BE[A654]                	mov	si, msg_ending_head
  6351 0000253A E842F9                  	call	print_msg
  6352 0000253D 8A4505                  	mov	al, [di+ptEndHead]
  6353 00002540 E86200                  	call	write_byte_decimal
  6354 00002543 E839F9                  	call	print_msg
  6355 00002546 BE[BE54]                	mov	si, msg_ending_sector
  6356 00002549 E833F9                  	call	print_msg
  6357 0000254C 8A4506                  	mov	al, [di+ptEndSector]
  6358 0000254F 88C2                    	mov	dl, al  ; bits 7&8 are bits 8&9 of cyl
  6359 00002551 243F                    	and	al, 3Fh ; sector number, 1 to 63
  6360 00002553 E84F00                  	call	write_byte_decimal			
  6361 00002556 E826F9                  	call	print_msg	
  6362 00002559 BE[D654]                	mov	si, msg_ending_cylinder
  6363 0000255C E820F9                  	call	print_msg
  6364 0000255F 8A4507                  	mov	al, [di+ptEndCylinder] ; bits 0to7 of cyl
  6365 00002562 C0EA06                  	shr	dl, 6 ; bits 8&9 of cyl
  6366 00002565 88D4                    	mov	ah, dl
  6367 00002567 31D2                    	xor	dx, dx
  6368 00002569 BE[CB6F]                	mov	si, msg_partition_sectors + 7 ; max. 7 digits
  6369                                  	; dx_ax: binary number
  6370 0000256C E898F9                  	call	bin_to_decimal
  6371                                  	; ds:si = decimal number text address		
  6372 0000256F E80DF9                  	call	print_msg
  6373                                  
  6374 00002572 BE[EE54]                	mov	si, msg_relative_sectors
  6375 00002575 E807F9                  	call	print_msg
  6376 00002578 8B4508                  	mov	ax, [di+ptStartSector]
  6377 0000257B 8B550A                  	mov	dx, [di+ptStartSector+2]
  6378                                  	;mov	si, msg_partition_sectors + 7 ; max. 11 digits
  6379 0000257E BE[CB6F]                	mov	si, reserved_bytes + 10 ; max. 11 digits
  6380 00002581 E883F9                  	call	bin_to_decimal
  6381 00002584 E8F8F8                  	call	print_msg
  6382                                  
  6383 00002587 BE[0855]                	mov	si, msg_total_sectors
  6384 0000258A E8F2F8                  	call	print_msg
  6385 0000258D 8B450C                  	mov	ax, [di+ptSectors]
  6386 00002590 8B550E                  	mov	dx, [di+ptSectors+2]
  6387                                  	;mov	si, msg_partition_sectors + 7 ; max. 11 digits
  6388 00002593 BE[CB6F]                	mov	si, reserved_bytes + 10 ; max. 11 digits
  6389 00002596 E86EF9                  	call	bin_to_decimal	
  6390 00002599 E8E3F8                  	call	print_msg
  6391                                  
  6392                                  	; 24/02/2019
  6393 0000259C BE[6057]                	mov	si, CRLF
  6394 0000259F E8DDF8                  	call	print_msg
  6395                                  
  6396 000025A2 89FE                    	mov	si, di  ; partition table row address
  6397                                  
  6398 000025A4 C3                      	retn
  6399                                  
  6400                                  ;-----------------------------------------------------------------------------
  6401                                  
  6402                                  write_byte_decimal:
  6403                                  	; INPUT ->
  6404                                  	;	AL = binary number
  6405                                  	; OUTPUT ->
  6406                                  	;	DS:SI = decimal number text address
  6407                                  	;	        (ASCIIZ string)
  6408                                  	;
  6409                                  	; (SI, AX, CX will be modified)	
  6410                                  
  6411 000025A5 BE[CC6F]                	mov	si, msg_partition_sectors + 8
  6412 000025A8 B10A                    	mov	cl, 10
  6413                                  wbd_loop:
  6414 000025AA 4E                      	dec	si
  6415 000025AB 30E4                    	xor	ah, ah
  6416 000025AD F6F1                    	div	cl
  6417 000025AF 80C430                  	add	ah, '0'
  6418 000025B2 8824                    	mov	[si], ah
  6419 000025B4 20C0                    	and	al, al
  6420 000025B6 75F2                    	jnz	short wbd_loop
  6421 000025B8 C3                      	retn
  6422                                  
  6423                                  ;-----------------------------------------------------------------------------
  6424                                  ; 03/02/2019
  6425                                  ; 16/10/2020
  6426                                  
  6427                                  init_partition_tables:
  6428                                  
  6429                                  	; INPUT -> none
  6430                                  	; OUTPUT -> none
  6431                                  	 
  6432                                  	; 12/02/2019	
  6433                                  	;cmp	word [MBIDCode], 0AA55h
  6434                                  	;jne	ipt_stc ; invalid
  6435                                  
  6436                                  	; 15/02/2019
  6437                                  	; clear primary partition tables structure/list
  6438                                  
  6439 000025B9 BF[5872]                	mov	di, part_table_boot_ind
  6440 000025BC B92400                  	mov	cx, 36 ; 18*4 = 72 bytes
  6441 000025BF 31C0                    	xor	ax, ax ; 0
  6442 000025C1 F3AB                    	rep	stosw
  6443                                  
  6444 000025C3 A3[A072]                	mov	[pcount], ax ; reset (pcount & ppcount)
  6445 000025C6 A3[A272]                	mov	[apcount], ax ; reset (apcount & epnumber)
  6446                                  
  6447 000025C9 BE[F659]                	mov	si, MasterBootBuff+446 ; Partition table offset
  6448                                  	;mov	cx, 4
  6449 000025CC B104                    	mov	cl, 4
  6450 000025CE 31FF                    	xor	di, di
  6451                                  ipt_0:
  6452 000025D0 8A6404                  	mov	ah, [si+ptFileSystemID]
  6453                                  
  6454 000025D3 20E4                    	and	ah, ah
  6455 000025D5 0F841801                	jz	ipt_8 ; empty
  6456                                  
  6457 000025D9 FE06[A072]              	inc	byte [pcount] ; partition count
  6458                                  
  6459 000025DD 80FC01                  	cmp	ah, 1	; FAT12
  6460 000025E0 7427                    	je	short ipt_2
  6461 000025E2 80FC04                  	cmp	ah, 4	; FAT16
  6462 000025E5 7422                    	je	short ipt_2
  6463 000025E7 7224                    	jb	short ipt_3	
  6464 000025E9 80FC06                  	cmp	ah, 6	; FAT16 big
  6465 000025EC 741B                    	je	short ipt_2
  6466 000025EE 7712                    	ja	short ipt_1 ; EXTENDED
  6467                                  
  6468                                  	;cmp	ah, 5 ; EXTENDED
  6469                                  	;jne	short ipt_3
  6470                                  
  6471 000025F0 803E[A372]00            	cmp	byte [epnumber], 0
  6472 000025F5 0F87B100                	ja	ipt_stc ; invalid  (more than 1 extended dos partition)
  6473                                  	
  6474 000025F9 B005                    	mov	al, 5
  6475 000025FB 28C8                    	sub	al, cl ; partition number 1 to 4
  6476 000025FD A2[A372]                	mov	byte [epnumber], al ; extended partition entry number (1 to 4)
  6477 00002600 EB0B                    	jmp	short ipt_3
  6478                                  ipt_1:
  6479 00002602 80FC0B                  	cmp	ah, 0Bh ; FAT32 (CHS)
  6480 00002605 7506                    	jne	short ipt_3 ; 16/10/2020
  6481                                  	; 26/10/2020
  6482 00002607 7400                    	je	short ipt_2
  6483                                  	;cmp	ah, 07h ; NTFS (Windows FS)
  6484                                  	;jne	short ipt_3 ; accept NTFS as primary dos partition
  6485                                  	;		    ; (then, extended partition can be created)		
  6486                                  ipt_2:
  6487 00002609 FE06[A172]              	inc	byte [ppcount] ; primary dos partition count
  6488                                  ipt_3:
  6489 0000260D 88A5[5D72]              	mov	[part_table_sys_id+di], ah  ; Partition Type (FS type)
  6490                                  	
  6491 00002611 8A04                    	mov	al, [si+ptBootable]
  6492                                  
  6493 00002613 20C0                    	and	al, al
  6494 00002615 7413                    	jz	short ipt_4
  6495                                  
  6496 00002617 803E[A272]01            	cmp	byte [apcount], 1 ; check (previous) active partition count
  6497 0000261C 0F838A00                	jnb	ipt_stc  ; invalid (if it is not zero here)
  6498                                  
  6499 00002620 3C80                    	cmp	al, 80h  ; active partition sign/flag?
  6500 00002622 0F858400                	jne	ipt_stc  ; invalid flag
  6501                                  
  6502 00002626 FE06[A272]              	inc	byte [apcount]  ; active partition count  = 1
  6503                                  ipt_4:
  6504 0000262A 8885[5872]              	mov	[part_table_boot_ind+di], al
  6505                                  
  6506 0000262E A0[A841]                	mov	al, [heads]
  6507                                  ipt_4_fix:
  6508 00002631 FEC8                    	dec	al
  6509 00002633 8A6401                  	mov	ah, [si+ptBeginHead]
  6510 00002636 38E0                    	cmp	al, ah
  6511                                  	;jb	short ipt_retn ; invalid
  6512 00002638 7272                    	jb	ipt_heads_fix ; 10/02/2019
  6513 0000263A 88A5[5972]              	mov	[part_table_start_head+di], ah
  6514 0000263E 8A6405                  	mov	ah, [si+ptEndHead]
  6515 00002641 38E0                    	cmp	al, ah
  6516                                  	;jb	short ipt_retn ; invalid
  6517 00002643 7267                    	jb	short ipt_heads_fix ; 10/02/2019
  6518 00002645 88A5[5E72]              	mov	[part_table_end_head+di], ah
  6519 00002649 A0[A641]                	mov	al, [sectors]
  6520 0000264C 8A7C02                  	mov	bh, [si+ptBeginSector]
  6521 0000264F 88FC                    	mov	ah, bh
  6522 00002651 80E43F                  	and	ah, 3Fh ; 63
  6523 00002654 38E0                    	cmp	al, ah
  6524 00002656 7253                    	jb	short ipt_retn ; invalid
  6525 00002658 88A5[5A72]              	mov	[part_table_start_sector+di], ah
  6526 0000265C 8A7406                  	mov	dh, [si+ptEndSector]
  6527 0000265F 88F4                    	mov	ah, dh
  6528 00002661 80E43F                  	and	ah, 3Fh ; 63
  6529 00002664 38E0                    	cmp	al, ah
  6530 00002666 7243                    	jb	short ipt_retn ; invalid
  6531 00002668 88A5[5F72]              	mov	[part_table_end_sector+di], ah
  6532 0000266C C0EF06                  	shr	bh, 6
  6533 0000266F 8A5C03                  	mov	bl, [si+ptBeginCylinder]
  6534 00002672 A1[AA41]                	mov	ax, [cylinders]
  6535 00002675 48                      	dec	ax	
  6536 00002676 39D8                    	cmp	ax, bx
  6537 00002678 7231                    	jb	short ipt_retn ; invalid
  6538 0000267A 899D[5B72]              	mov	[part_table_start_cyl+di], bx
  6539 0000267E C0EE06                  	shr	dh, 6
  6540 00002681 8A5407                  	mov	dl, [si+ptEndCylinder]
  6541 00002684 39D0                    	cmp	ax, dx
  6542 00002686 7223                    	jb	short ipt_retn ; invalid
  6543 00002688 8995[6072]              	mov	[part_table_end_cyl+di], dx
  6544                                  
  6545 0000268C 8B4408                  	mov	ax, [si+ptStartSector]
  6546 0000268F 8B540A                  	mov	dx, [si+ptStartSector+2]
  6547                                  
  6548 00002692 8985[6272]              	mov	[part_table_rel_sec_lw+di], ax
  6549 00002696 8995[6472]              	mov	[part_table_rel_sec_hw+di], dx
  6550                                  
  6551 0000269A 09D0                    	or	ax, dx
  6552 0000269C 740C                    	jz	short ipt_stc ; invalid (start sector must not be zero)
  6553                                  
  6554 0000269E 8B440C                  	mov	ax, [si+ptSectors]
  6555 000026A1 8B540E                  	mov	dx, [si+ptSectors+2]
  6556                                  
  6557 000026A4 89D3                    	mov	bx, dx
  6558 000026A6 09C3                    	or	bx, ax
  6559                                  	;jz	short ipt_stc	; invalid (zero size of partition)
  6560 000026A8 7521                    	jnz	short ipt_6 ; 10/02/2019
  6561                                  
  6562                                  	;cmp	dx, [total_sectors+2]
  6563                                  	;ja	short ipt_stc	; invalid (partition size > disk capacity)
  6564                                  	;jb	short ipt_6
  6565                                  	;;cmp	ax, [total_sectors] ; (ax + 1) <= total sectors
  6566                                  	;jb	short ipt_6
  6567                                  	
  6568                                  ipt_stc:
  6569                                  	; invalid MBR data
  6570 000026AA F9                      	stc
  6571                                  ipt_retn:
  6572 000026AB C3                      	retn
  6573                                  
  6574                                  ipt_heads_fix:
  6575                                  	; 10/02/2019
  6576                                  	; AL = [heads] - 1
  6577                                  
  6578 000026AC F606[AA41]01            	test	byte [cylinders], 1
  6579 000026B1 75F7                    	jnz	short ipt_stc ; odd cylinder count (can not be shifted)
  6580                                  	
  6581 000026B3 FEC0                    	inc	al ; = [heads]
  6582 000026B5 3C08                    	cmp	al, 8
  6583 000026B7 77F1                    	ja	short ipt_stc ; this fix is needed for <= 16 heads (& 17 spt)
  6584 000026B9 D0E0                    	shl	al, 1
  6585 000026BB A2[A841]                	mov	[heads], al ; heads = heads*2
  6586 000026BE D12E[AA41]              	shr	word [cylinders], 1 ; cylinders = cylinders/2
  6587 000026C2 E96CFF                  	jmp	ipt_4_fix
  6588                                  
  6589                                  ipt_5:
  6590 000026C5 83C712                  	add	di, 18
  6591 000026C8 E905FF                  	jmp	ipt_0
  6592                                  
  6593                                  ipt_6:
  6594 000026CB 8985[6672]              	mov	[part_table_num_sec_lw+di], ax
  6595 000026CF 8995[6872]              	mov	[part_table_num_sec_hw+di], dx
  6596                                  
  6597 000026D3 0385[6272]              	add	ax, [part_table_rel_sec_lw+di]
  6598 000026D7 1395[6472]              	adc	dx, [part_table_rel_sec_hw+di]
  6599 000026DB 72CE                    	jc	short ipt_retn  ; invalid
  6600                                  
  6601 000026DD 3B16[9E6F]              	cmp	dx, [total_sectors+2]
  6602 000026E1 77C7                    	ja	short ipt_stc	; invalid (partition end > disk capacity)
  6603 000026E3 7206                    	jb	short ipt_7
  6604 000026E5 3B06[9C6F]              	cmp	ax, [total_sectors] ; ax <= total sectors
  6605 000026E9 77BF                    	ja	short ipt_stc	; invalid (partition end > disk capacity)
  6606                                  ipt_7:
  6607 000026EB 83C610                  	add	si, 16
  6608 000026EE E2D5                    	loop	ipt_5
  6609                                  	
  6610                                  	; OK!
  6611                                  
  6612                                  	;clc
  6613 000026F0 C3                      	retn
  6614                                  
  6615                                  ipt_8:
  6616                                  	; Empty partition table check (all of 16 bytes must be 0)
  6617 000026F1 51                      	push	cx
  6618 000026F2 B108                    	mov	cl, 8
  6619                                  ipt_9:
  6620 000026F4 AD                      	lodsw
  6621 000026F5 09C0                    	or	ax, ax
  6622 000026F7 7506                    	jnz	short ipt_10
  6623 000026F9 E2F9                    	loop	ipt_9
  6624 000026FB 59                      	pop	cx
  6625 000026FC E2C7                    	loop	ipt_5
  6626                                  	
  6627                                  	;clc
  6628 000026FE C3                      	retn
  6629                                  ipt_10:
  6630 000026FF 59                      	pop	cx
  6631                                  	; invalid
  6632 00002700 F9                      	stc	
  6633 00002701 C3                      	retn
  6634                                  
  6635                                  ;-----------------------------------------------------------------------------
  6636                                  ; 25/10/2020
  6637                                  
  6638                                  	; 02/02/2019
  6639                                  	
  6640                                  sort_partition_table:
  6641                                  
  6642                                  	; INPUT -> none
  6643                                  	; OUTPUT -> none
  6644                                  
  6645 00002702 31DB                    	xor	bx, bx
  6646                                  	;jmp	short sortpt_2 ; 25/10/2020
  6647                                  sortpt_1:
  6648 00002704 889F[E66F]              	mov	[bx+sort], bl ; 0	
  6649 00002708 FEC3                    	inc	bl
  6650                                  sortpt_2:
  6651 0000270A 80FB04                  	cmp	bl, 4 ; number of partition table entries to sort
  6652 0000270D 72F5                    	jb	short sortpt_1
  6653                                  
  6654                                  	; Do a bubble sort
  6655                                  
  6656 0000270F EB04                    	jmp	short sortpt_4
  6657                                  sortpt_3:
  6658                                  	; Sort until we don't do a swap
  6659                                  
  6660 00002711 08C9                    	or	cl, cl ; sort changed ?
  6661 00002713 744E                    	jz	short sortpt_8 ; no
  6662                                  sortpt_4:
  6663 00002715 30C9                    	xor	cl, cl
  6664                                  
  6665 00002717 B301                    	mov	bl, 1
  6666                                  
  6667 00002719 B212                    	mov	dl, 18  ; partition table structure size
  6668 0000271B EB07                    	jmp	short sortpt_6
  6669                                  sortpt_5:
  6670 0000271D FEC3                    	inc	bl
  6671                                  
  6672 0000271F 80FB04                  	cmp	bl, 4
  6673 00002722 73ED                    	jnb	short sortpt_3
  6674                                  
  6675                                  sortpt_6:
  6676 00002724 8A87[E66F]              	mov	al, [bx+sort]
  6677                                  
  6678 00002728 F6E2                    	mul	dl
  6679                                  
  6680 0000272A 89C6                    	mov	si, ax
  6681                                  
  6682 0000272C 8BBC[6072]              	mov	di, [part_table_end_cyl+si]
  6683                                  
  6684 00002730 8A87[E56F]              	mov	al, [bx+sort-1]
  6685                                  
  6686 00002734 F6E2                    	mul	dl ; * 18
  6687                                  
  6688 00002736 97                      	xchg	di, ax
  6689                                  
  6690 00002737 3985[6072]              	cmp	[part_table_end_cyl+di], ax ; previous > current
  6691                                  	;ja	short sortpt_7 ; swap order indicators
  6692                                  		; 31/10/2020
  6693                                  		; current end cyl >= previous end cyl
  6694                                  	; 31/10/2020
  6695 0000273B 72E0                    	jb	short sortpt_5  
  6696                                  		; current end cyl > previous end cyl
  6697                                  	
  6698 0000273D 21C0                    	and	ax, ax ; cylinder 0 ?
  6699 0000273F 75DC                    	jnz	short sortpt_5 ; no
  6700                                  		; current end cyl = previous end cyl, cyl > 0
  6701                                  	
  6702                                  	; current end cyl = previous end cyl = 0	
  6703                                  
  6704                                  	; If current entry is empty partition entry
  6705                                  	; and previous entry is not empty partition entry
  6706                                  	; swap them.
  6707                                  	;
  6708 00002741 8B85[6872]              	mov	ax, [part_table_num_sec_hw+di] ; previous entry
  6709 00002745 0B85[6672]              	or	ax, [part_table_num_sec_lw+di]
  6710 00002749 74D2                    	jz	short sortpt_5
  6711                                  
  6712 0000274B 8B84[6872]              	mov	ax, [part_table_num_sec_hw+si] ; current entry
  6713 0000274F 0B84[6672]              	or	ax, [part_table_num_sec_lw+si]
  6714 00002753 75C8                    	jnz	short sortpt_5
  6715                                  sortpt_7:
  6716                                  	; Swap the order indicators
  6717                                  
  6718 00002755 8B87[E56F]              	mov	ax, [bx+sort-1]
  6719 00002759 86E0                    	xchg	ah, al
  6720 0000275B 8987[E56F]              	mov	[bx+sort-1], ax
  6721                                  
  6722 0000275F B101                    	mov	cl, 1 ; sort changed
  6723 00002761 EBBA                    	jmp	short sortpt_5
  6724                                  
  6725                                  sortpt_8:
  6726                                  	; 30/10/2020
  6727                                  	;mov 	byte [p_sorted], 1 ; 04/02/2019
  6728                                  
  6729 00002763 C3                      	retn
  6730                                  
  6731                                  ;-----------------------------------------------------------------------------
  6732                                  ; 03/02/2019
  6733                                  
  6734                                  find_part_free_space:  ; find/calculate free space for partitions
  6735                                  	; 15/02/2019
  6736                                  
  6737                                  	; INPUT -> 
  6738                                  	;	AL = 0 -> calculate for primary/MBR partitions 
  6739                                  	;	AL = 5 -> calculate for extended partition
  6740                                  	; OUTPUT ->
  6741                                  	;	CX = the largest free space/cylinders (between partitions)
  6742                                  	;	AX = Free space index (gap number) - from 0 to 4 -
  6743                                  	;	BX = Free space structure offset (for the largest free space)
  6744                                  	;
  6745                                  	;	22/02/2019
  6746                                  	;	[freespace_count] = number of free spaces/gaps
  6747                                  
  6748 00002764 A2[0172]                	mov	[p_type], al
  6749                                  
  6750                                  	; Sort the partition table
  6751                                  
  6752 00002767 E898FF                  	call	sort_partition_table ; 16/02/2019
  6753                                  
  6754                                  	; Initialize free space to zero
  6755                                  
  6756                                  	; 15/02/2019
  6757 0000276A BF[EC72]                	mov	di, fspc ; free_space.space
  6758 0000276D B92800                  	mov	cx, 5*8 ; (5*16/2)
  6759 00002770 31C0                    	xor	ax, ax ; 0
  6760 00002772 F3AB                    	rep	stosw
  6761                                  
  6762 00002774 A2[FE71]                	mov	[freespace_count], al ; 0
  6763                                  	; 22/02/2019
  6764                                  	;mov	[last_found_partition], al ; 0
  6765                                  
  6766 00002777 A3[FC71]                	mov	[_i_], ax ; 0
  6767                                  	;jmp	short fpfs_2
  6768                                  	; 31/10/020
  6769 0000277A EB0E                    	jmp	short fpfs_3
  6770                                  fpfs_1:	
  6771 0000277C FE06[FC71]              	inc	byte [_i_]
  6772                                  ;;fpfs_2:
  6773 00002780 803E[FC71]04            	cmp	byte [_i_], 4
  6774 00002785 7203                    	jb	short fpfs_3
  6775 00002787 E97801                  	jmp	fpfs_13
  6776                                  fpfs_3:
  6777                                  	; Find space between start of disk and first partition
  6778                                  
  6779                                  	;mov	ax, [_i_]
  6780 0000278A 8B1E[FC71]              	mov	bx, [_i_] ; 31/10/2020
  6781                                  fpfs_2:
  6782                                  	;mov	bx, ax ; 31/10/2020
  6783                                  	;mov	al, [sort+bx]
  6784 0000278E 8A8F[E66F]              	mov	cl, [sort+bx] ; 15/02/2019
  6785                                  
  6786                                  	;mov	cl, 18 ; partition table structure size = 18 bytes
  6787 00002792 B012                    	mov	al, 18 ; 15/02/2019
  6788 00002794 F6E1                    	mul	cl
  6789 00002796 89C3                    	mov	bx, ax
  6790                                  
  6791 00002798 80BF[5D72]00            	cmp	byte [part_table_sys_id+bx], 0
  6792 0000279D 74DD                    	je	short fpfs_1
  6793                                  
  6794 0000279F 880E[0072]              	mov	[last_found_partition], cl ; 15/02/2019
  6795                                  
  6796 000027A3 30C9                    	xor	cl, cl ; 0 	
  6797                                  	;mov	al, 1 ; LBA = 1 (after MBR) ; ah = 0
  6798                                  	; 03/11/2020
  6799 000027A5 A0[A641]                	mov	al, [sectors] ; 63 or 17 ; 03/11/2020	
  6800                                  	
  6801 000027A8 803E[0172]05            	cmp	byte [p_type], 5  ; EXTENDED
  6802 000027AD 7506                    	jne	short fpfs_4
  6803                                  
  6804                                  	; This is a special case - the extended partition can not start
  6805                                  	; on cylinder 0 due to its architecture. Protect against that here
  6806                                  
  6807                                  	; 13/02/2019
  6808                                  	; LBA value of free space start
  6809                                  	;mov	al, [sectors] ; 03/11/2020
  6810 000027AF F626[A841]              	mul	byte [heads]
  6811                                  		; ax = start sector (for Extended Partition)
  6812 000027B3 FEC1                    	inc	cl ; 1  ; cx = start cylinder = 1
  6813                                  fpfs_4:
  6814                                  	; Found a partition, get the space
  6815                                  
  6816                                  	; 15/02/2019
  6817 000027B5 8B97[5B72]              	mov	dx, [part_table_start_cyl+bx]
  6818 000027B9 39CA                    	cmp	dx, cx
  6819 000027BB 0F86C300                	jna	fpfs_9 ; It is accepted as free (partition) space
  6820                                  		       ; if this space between masterboot sector and partition 1
  6821                                  		       ; has 1 cylinder (heads*spt) size at least.
  6822                                  	; 22/02/2019
  6823 000027BF 31FF                    	xor	di, di  ; 0 ; Reset Free Space Table offset
  6824                                  
  6825 000027C1 FE06[FE71]              	inc	byte [freespace_count]	; mov byte [freespace_count], 1
  6826                                  
  6827 000027C5 890E[EE72]              	mov	[free_space.start], cx ; 0 (for PP) or 1 (for EP)
  6828                                  	
  6829                                  	; non-aligned address of start sector (for the 1st partition as sorted)
  6830                                  	; NOTE: later, start sector will be moved to (chs) head 1 and sector 1
  6831                                  	;	if new partition will be selected as a primary dos partition.
  6832                                  	;	(But, start sector -LBA- will not be changed 
  6833                                  	;	 if it is a non-dos or user input type partition.. unless
  6834                                  	;	 cylinder boundary alignment option is used.)
  6835                                  	 	
  6836 000027C9 A3[F872]                	mov	[free_space.startsector], ax ; = [sectors]*[heads] (for EP)
  6837                                  					     ; or 1 (for PP)
  6838                                  	;mov	[free_space.startsector+2], 0
  6839                                  
  6840                                  	; free space ends before start of next valid partition
  6841 000027CC 89D0                    	mov	ax, dx	; start cylinder of partition 1 (as sorted)
  6842 000027CE 29CA                    	sub	dx, cx	; cylinder count of free space 1 (gap 1)
  6843 000027D0 48                      	dec	ax	; end cylinder of free space 1 (gap 1)
  6844 000027D1 A3[F072]                	mov	[free_space.end], ax 
  6845 000027D4 8916[EC72]              	mov	[free_space.space], dx
  6846                                  
  6847                                  	; save free space (1) as (non-aligned) sector count
  6848 000027D8 8B87[6272]              	mov	ax, [part_table_rel_sec_lw+bx]
  6849 000027DC 8B97[6472]              	mov	dx, [part_table_rel_sec_hw+bx]
  6850 000027E0 2B06[F872]              	sub	ax, [free_space.startsector]
  6851 000027E4 83DA00                  	sbb	dx, 0
  6852 000027E7 A3[F472]                	mov	[free_space.sectors_unused], ax
  6853 000027EA 8916[F672]              	mov	[free_space.sectors_unused+2], dx
  6854                                  
  6855                                  	;mov	ax, [free_space.space]
  6856                                  
  6857                                  	;call	cylinders_to_sectors
  6858                                  
  6859                                  	;mov	[free_space.sectors_unused], ax
  6860                                  	;mov	[free_space.sectors_unused+2], dx
  6861                                  
  6862 000027EE 8B0E[AA41]              	mov	cx, [cylinders]		; Total (disk) cylinders -divisor-
  6863 000027F2 8B1E[EC72]              	mov	bx, [free_space.space]	; Partition cylinders -dividend-
  6864                                  
  6865 000027F6 E80802                  	call	cylinders_to_percent
  6866                                  
  6867 000027F9 A3[F272]                	mov	[free_space.percent_unused], ax
  6868                                  
  6869                                  	; 15/02/2019
  6870                                  	;mov	bl, [_i_]
  6871                                  	;xor	bh, bh
  6872                                  	;mov	al, [sort+bx]
  6873                                  
  6874                                  	;mov	[last_found_partition], al
  6875                                  
  6876                                  	; 31/10/2020
  6877 000027FC E98300                  	jmp	fpfs_9
  6878                                  
  6879                                  	; Look for space between the rest of the partitions
  6880                                  
  6881                                  fpfs_7:
  6882                                  	; ah = 0
  6883                                  	;mov	al, [_i_]
  6884                                  	;;cbw
  6885                                  	;mov	bx, ax
  6886                                  	; 22/02/2019
  6887 000027FF 8B1E[FC71]              	mov	bx, [_i_]
  6888                                  
  6889                                  	; 15/02/2019
  6890                                  	;mov	al, [sort+bx]
  6891 00002803 8A8F[E66F]              	mov	cl, [sort+bx]
  6892                                  	;mov	bl, 18
  6893                                  	;mul	bl
  6894 00002807 B012                    	mov	al, 18
  6895 00002809 F6E1                    	mul	cl
  6896 0000280B 89C6                    	mov	si, ax
  6897                                  	
  6898 0000280D 80BC[5D72]00            	cmp	byte [part_table_sys_id+si], 0
  6899 00002812 746E                    	je	short fpfs_9
  6900                                  
  6901                                  	; 15/02/2019
  6902 00002814 860E[0072]              	xchg	[last_found_partition], cl
  6903                                  
  6904                                  	; Check to see if more than one partition on a cylinder
  6905                                  	; If so, leave the space at zero */
  6906                                  
  6907                                  	; NOTE:
  6908                                  	; It is accepted as valid free (partition) space
  6909                                  	; if free space (gap) between partitions
  6910                                  	; has 1 cylinder (heads*spt) size at least.
  6911                                  
  6912 00002818 B012                    	mov	al, 18 ; Partition tables/data structure size = 18 bytes
  6913 0000281A F6E1                    	mul	cl
  6914 0000281C 89C3                    	mov	bx, ax  ; ah = 0
  6915                                  
  6916 0000281E 8B97[6072]              	mov	dx, [part_table_end_cyl+bx]   ; end cyl. of previous partition 
  6917 00002822 8B84[5B72]              	mov	ax, [part_table_start_cyl+si] ; start cyl. of current partition
  6918                                  
  6919 00002826 42                      	inc	dx  ; start cylinder of free space is after the end cylinder of
  6920                                  		    ; the previous partition (as sorted)
  6921                                  
  6922 00002827 39D0                    	cmp	ax, dx ; and it must be before than the next partition (as sorted)
  6923 00002829 7657                    	jna	short fpfs_9 ; je short fpfs_9
  6924                                  		
  6925                                  	; No, things are normal
  6926                                  	; Get space between the end of the last one and the start of the next one
  6927                                  
  6928                                  	; 22/02/2019
  6929                                  	;add	di, 16
  6930 0000282B 8B3E[FE71]              	mov	di, [freespace_count] 
  6931 0000282F C1E704                  	shl	di, 4	; * 16 ; next entry offset (in free space table)
  6932                                  
  6933 00002832 FE06[FE71]              	inc	byte [freespace_count]
  6934                                  
  6935 00002836 89C1                    	mov	cx, ax
  6936 00002838 29D1                    	sub	cx, dx
  6937 0000283A 48                      	dec	ax
  6938 0000283B 8995[EE72]              	mov	[free_space.start+di], dx
  6939 0000283F 8985[F072]              	mov	[free_space.end+di], ax
  6940 00002843 898D[EC72]              	mov	[free_space.space+di], cx
  6941                                  
  6942                                  	;mov	ax, [free_space.space+di]
  6943                                  	;call	cylinders_to_sectors
  6944                                  	;mov	[free_space.sectors_unused+di], ax
  6945                                  	;mov	[free_space.sectors_unused+2+di], dx
  6946                                  
  6947                                  	; calculate and save (non-aligned) free sector count between partitions
  6948                                  
  6949 00002847 8B87[6272]              	mov	ax, [part_table_rel_sec_lw+bx]
  6950 0000284B 8B97[6472]              	mov	dx, [part_table_rel_sec_hw+bx]
  6951 0000284F 0387[6672]              	add	ax, [part_table_num_sec_lw+bx]
  6952 00002853 1397[6872]              	adc	dx, [part_table_num_sec_hw+bx]
  6953                                  
  6954 00002857 8B8C[6272]              	mov	cx, [part_table_rel_sec_lw+si]
  6955 0000285B 8B9C[6472]              	mov	bx, [part_table_rel_sec_hw+si]
  6956                                  
  6957 0000285F 8985[F872]              	mov	[free_space.startsector+di], ax
  6958 00002863 8995[FA72]              	mov	[free_space.startsector+2+di], dx
  6959                                  
  6960 00002867 29C1                    	sub	cx, ax
  6961 00002869 19D3                    	sbb	bx, dx
  6962                                  
  6963 0000286B 898D[F472]              	mov	[free_space.sectors_unused+di], cx
  6964 0000286F 899D[F672]              	mov	[free_space.sectors_unused+2+di], bx
  6965                                  
  6966                                  fpfs_8:
  6967                                  	; NOTE: Percentage is based on cylinder-boundary aligned partition size.
  6968                                  	; (total disk cylinders and partition's cylinder count are used for that)
  6969                                  
  6970 00002873 8B0E[AA41]              	mov	cx, [cylinders] ; -divisor-
  6971 00002877 8B9D[EC72]              	mov	bx, [free_space.space+di] ; -dividend-
  6972 0000287B E88301                  	call	cylinders_to_percent
  6973                                  	
  6974 0000287E 8985[F272]              	mov	[free_space.percent_unused+di], ax 
  6975                                  	
  6976                                  	; ah = 0
  6977                                  
  6978                                  	; 15/02/2019
  6979                                  	;mov	bl, [_i_]
  6980                                  	;xor	bh, bh
  6981                                  	;mov	al, [sort+bx]
  6982                                  	;	
  6983                                  	;mov	[last_found_partition], al
  6984                                  
  6985                                  fpfs_9:
  6986 00002882 FE06[FC71]              	inc	byte [_i_]
  6987                                  fpfs_10:
  6988 00002886 803E[FC71]04            	cmp	byte [_i_], 4
  6989 0000288B 7303                    	jnb	short fpfs_11
  6990                                  
  6991 0000288D E96FFF                  	jmp	fpfs_7
  6992                                  
  6993                                  fpfs_11:
  6994                                  	; Find the space between the last partition and the end of the disk
  6995                                  	; Make sure that freespace cannot become negative
  6996                                  
  6997 00002890 A0[0072]                	mov	al, [last_found_partition]
  6998 00002893 B112                    	mov	cl, 18  ; Partition table structure size = 18 bytes
  6999 00002895 F6E1                    	mul	cl
  7000 00002897 89C3                    	mov	bx, ax
  7001 00002899 8B0E[AA41]              	mov	cx, [cylinders]
  7002 0000289D 49                      	dec	cx ; 15/02/2019 
  7003                                  		   ; (min. cylinder count = 1 for a valid/usable free space)
  7004 0000289E 8B87[6072]              	mov	ax, [part_table_end_cyl+bx]
  7005                                  	;cmp	[part_table_end_cyl+bx], cx
  7006 000028A2 39C8                    	cmp	ax, cx	; cx = end cylinder of the disk
  7007 000028A4 7203                    	jb	short fpfs_12
  7008 000028A6 E9A600                  	jmp	fpfs_15
  7009                                  fpfs_12:
  7010                                  	; 22/02/2019
  7011 000028A9 8B3E[FE71]              	mov	di, [freespace_count]
  7012 000028AD C1E704                  	shl	di, 4 ; * 16  ; next entry offset (in free space table)
  7013                                  
  7014 000028B0 FE06[FE71]              	inc	byte [freespace_count]
  7015                                  
  7016 000028B4 898D[F072]              	mov	[free_space.end+di], cx	; end cyl. of free space 5 (gap 5) 
  7017                                  	;mov	ax, [part_table_end_cyl+bx]
  7018 000028B8 89CA                    	mov	dx, cx	; cx = end cylinder of the disk
  7019 000028BA 29C2                    	sub	dx, ax	; ax = end cylinder of the last partition
  7020 000028BC 8995[EC72]              	mov	[free_space.space+di], dx ; di = 4*16
  7021 000028C0 40                      	inc	ax
  7022 000028C1 8985[EE72]              	mov	[free_space.start+di], ax
  7023                                  	
  7024                                  	;inc	cx ; [cylinders]
  7025                                  	;mov	ax, [free_space.space+si]
  7026                                  	;call	cylinders_to_sectors
  7027                                  	;mov	[free_space.sectors_unused+di], ax
  7028                                  	;mov	[free_space.sectors_unused+2+di], dx
  7029                                  
  7030                                  	; calculate and save (non-aligned) free sector count
  7031                                  
  7032                                  	; 22/02/2019
  7033 000028C5 8B87[6272]              	mov	ax, [part_table_rel_sec_lw+bx]
  7034 000028C9 8B97[6472]              	mov	dx, [part_table_rel_sec_hw+bx]
  7035 000028CD 0387[6672]              	add	ax, [part_table_num_sec_lw+bx]
  7036 000028D1 1397[6872]              	adc	dx, [part_table_num_sec_hw+bx]
  7037                                  
  7038 000028D5 8985[F872]              	mov	[free_space.startsector+di], ax
  7039 000028D9 8995[FA72]              	mov	[free_space.startsector+2+di], dx
  7040                                  
  7041 000028DD 8B0E[9C6F]              	mov	cx, [total_sectors]
  7042 000028E1 8B1E[9E6F]              	mov	bx, [total_sectors+2]
  7043 000028E5 29C1                    	sub	cx, ax
  7044 000028E7 19D3                    	sbb	bx, dx
  7045 000028E9 898D[F472]              	mov	[free_space.sectors_unused+di], cx
  7046 000028ED 899D[F672]              	mov	[free_space.sectors_unused+2+di], bx
  7047                                  
  7048 000028F1 8B0E[AA41]              	mov	cx, [cylinders]
  7049 000028F5 8B9D[EC72]              	mov	bx, [free_space.space+di]
  7050 000028F9 E80501                  	call	cylinders_to_percent
  7051 000028FC 8985[F272]              	mov	[free_space.percent_unused+di], ax
  7052 00002900 EB4D                    	jmp	short fpfs_15
  7053                                  
  7054                                  fpfs_13:
  7055                                  	; No partitions found, show entire space as free
  7056                                  
  7057                                  	; 22/02/2019
  7058 00002902 FE06[FE71]              	inc	byte [freespace_count]	; mov byte [freespace_count], 1
  7059                                  	
  7060                                  	; 15/02/2019
  7061                                  	;sub	ax, ax
  7062                                  	; ah = 0 ; 31/10/2020
  7063 00002906 29D2                    	sub	dx, dx
  7064                                  
  7065                                  	;inc	al ; LBA = 1 (after MBR) ; ah = 0
  7066 00002908 B001                    	mov	al, 1 ; 25/02/2019
  7067                                  
  7068                                  	;This is a special case - the extended partition can not start
  7069                                  	;on cylinder 0 due to its architecture. Protect against that here
  7070                                  
  7071 0000290A 803E[0172]05            	cmp	byte [p_type], 5 ; EXTENDED
  7072 0000290F 7509                    	jne	short fpfs_14
  7073                                  		
  7074 00002911 FEC2                    	inc	dl
  7075                                  
  7076                                  	; 15/02/2019
  7077                                  	; LBA value of free space start
  7078 00002913 A0[A641]                	mov	al, [sectors]
  7079 00002916 F626[A841]              	mul	byte [heads]
  7080                                  		; ax = start sector (for Extended Partition)
  7081                                  fpfs_14:
  7082 0000291A 8916[EE72]              	mov	[free_space.start], dx ; 0 or 1
  7083                                  
  7084                                  	; non-aligned address of start sector (for the 1st partition as sorted)
  7085                                  	; NOTE: later, start sector will be moved to (chs) head 1 and sector 1
  7086                                  	;	if new partition will be selected as a primary dos partition.
  7087                                  	 	
  7088 0000291E A3[F872]                	mov	[free_space.startsector], ax ; = [sectors]*[heads] (for EP)
  7089                                  					     ; or 1 (for PP)
  7090                                  	;mov	[free_space.startsector+2], 0
  7091                                  
  7092 00002921 A1[AA41]                	mov	ax, [cylinders] ; disk capacity 
  7093 00002924 89C1                    	mov	cx, ax
  7094 00002926 48                      	dec	ax
  7095 00002927 A3[F072]                	mov	[free_space.end], ax
  7096 0000292A 29D0                    	sub	ax, dx
  7097 0000292C 40                      	inc	ax
  7098 0000292D A3[EC72]                	mov	[free_space.space], ax
  7099                                  
  7100 00002930 A1[9C6F]                	mov	ax, [total_sectors]
  7101 00002933 8B16[9E6F]              	mov	dx, [total_sectors+2]
  7102 00002937 2B06[F872]              	sub	ax, [free_space.startsector]
  7103 0000293B 83DA00                  	sbb	dx, 0
  7104 0000293E A3[F472]                	mov	[free_space.sectors_unused], ax
  7105 00002941 8916[F672]              	mov	[free_space.sectors_unused+2], dx
  7106                                  
  7107                                  	;mov	cx, [cylinders] 
  7108 00002945 8B1E[EC72]              	mov	bx, [free_space.space]
  7109 00002949 E8B500                  	call	cylinders_to_percent
  7110 0000294C A3[F272]                	mov	[free_space.percent_unused], ax
  7111                                  
  7112                                  fpfs_15:
  7113                                  	; Find largest free space
  7114 0000294F 29C9                    	sub	cx, cx
  7115                                  	; 22/02/2019
  7116 00002951 29C0                    	sub	ax, ax
  7117 00002953 31DB                    	xor	bx, bx
  7118 00002955 8A16[FE71]              	mov	dl, [freespace_count]
  7119 00002959 08D2                    	or	dl, dl
  7120 0000295B 7420                    	jz	short fpfs_19
  7121 0000295D 8816[FC71]              	mov	[_i_], dl
  7122                                  fpfs_16:
  7123 00002961 8B97[EC72]              	mov	dx, [free_space.space+bx] 
  7124 00002965 39CA                    	cmp	dx, cx
  7125 00002967 7604                    	jbe	short fpfs_17
  7126                                  	; 22/02/2019
  7127 00002969 89D1                    	mov	cx, dx ; Largest free space
  7128 0000296B 89D8                    	mov	ax, bx
  7129                                  fpfs_17:
  7130 0000296D FE0E[FC71]              	dec	byte [_i_]
  7131 00002971 7405                    	jz	short fpfs_18
  7132                                  
  7133 00002973 83C310                  	add	bx, 16 ; Free space structure size
  7134 00002976 EBE9                    	jmp	short fpfs_16
  7135                                  fpfs_18:
  7136                                  	; 22/02/2019
  7137 00002978 89C3                    	mov	bx, ax ; offset (from 0 to 64)
  7138 0000297A C0E804                  	shr	al, 4  ; index (from 0 to 4)
  7139                                  fpfs_19:
  7140 0000297D C3                      	retn
  7141                                  
  7142                                  ;-----------------------------------------------------------------------------
  7143                                  
  7144                                  ;	; 15/02/2019
  7145                                  ;find_enough_free_space:
  7146                                  ;	; Find enough free space
  7147                                  ;	;
  7148                                  ;	; INPUT:
  7149                                  ;	;	AX = Requested space (in cylinders)
  7150                                  ;	;	22/02/2019
  7151                                  ;	;	[freespace_count] = number of free spaces/gaps
  7152                                  ;	; OUTPUT:
  7153                                  ;	;	AX = Available space
  7154                                  	;	DX = Requested space
  7155                                  ;	;	If CF = 0 -> AX >= DX
  7156                                  ;	;	If CF = 1 -> AX < DX
  7157                                  ;	;	CX = Index of available space in free space structure
  7158                                  ;	;	     (GAP number, 0 to 4) - if AX > 0 -	
  7159                                  ;
  7160                                  ;	mov	dx, ax ; 22/02/2019
  7161                                  ;	sub	ax, ax
  7162                                  ;	xor	bx, bx
  7163                                  ;	; 22/02/2019
  7164                                  ;	mov	ch, [freespace_count]
  7165                                  ;	mov	[_i_], ax ; 0
  7166                                  ;	jmp	short fefs_1
  7167                                  ;fefs_0:
  7168                                  ;	;mov	al, 16
  7169                                  ;	;mul	byte [_i_]
  7170                                  ;	;mov	bx, ax
  7171                                  ;	mov	bl, [_i_]
  7172                                  ;	shl	bl, 4 ; * 16
  7173                                  ;fefs_1:
  7174                                  ;	mov	ax, [free_space.space+bx]
  7175                                  ;	and	ax, ax
  7176                                  ;	jz	short fefs_2 ; not a free space
  7177                                  ;	mov	cl, [_i_] 
  7178                                  ;	cmp	ax, dx
  7179                                  ;	jnb	short fefs_3 ; enough space
  7180                                  ;fefs_2:
  7181                                  ;	; 22/02/2019
  7182                                  ;	inc	byte [_i_]
  7183                                  ;	cmp	byte [_i_], ch	
  7184                                  ;	jb	short fefs_0
  7185                                  ;	sub	ch, ch
  7186                                  ;	stc
  7187                                  ;	retn
  7188                                  ;fefs_3:
  7189                                  ;	xor	ch, ch
  7190                                  ;	retn
  7191                                  
  7192                                  ;-----------------------------------------------------------------------------
  7193                                  
  7194                                  	; 15/02/2019
  7195                                  find_enough_free_sectors:
  7196                                  	; Find (first) enough free space in sectors
  7197                                  	;
  7198                                  	; INPUT:
  7199                                  	;	DX:AX = Requested space (as non-aligned free sectors)
  7200                                  	;	22/02/2019
  7201                                  	;	[freespace_count] = number of free spaces/gaps
  7202                                  	; OUTPUT:
  7203                                  	;	DX:AX = Available space
  7204                                  	;	If CF = 0 -> DX:AX >= Request
  7205                                  	;	If CF = 1 -> DX:AX < Request
  7206                                  	;	CX = Index of available space in free space structure
  7207                                  	;	     (GAP number, 0 to 4) - if DX:AX > 0 -
  7208                                  
  7209 0000297E 31FF                    	xor	di, di
  7210 00002980 31F6                    	xor	si, si
  7211 00002982 31DB                    	xor	bx, bx
  7212                                  	; 22/02/2019
  7213 00002984 8A2E[FE71]              	mov	ch, [freespace_count]
  7214 00002988 891E[FC71]              	mov	[_i_], bx ; 0
  7215 0000298C EB07                    	jmp	short fefss_1
  7216                                  fefss_0:
  7217                                  	;mov	al, 16
  7218                                  	;mul	byte [_i_]
  7219                                  	;mov	bx, ax
  7220 0000298E 8B1E[FC71]              	mov	bx, [_i_]
  7221 00002992 C0E304                  	shl	bl, 4 ; * 16
  7222                                  fefss_1:
  7223 00002995 81C3[F472]              	add	bx, free_space.sectors_unused
  7224 00002999 3B5702                  	cmp	dx, [bx+2]
  7225 0000299C 7230                    	jb	short fefss_7
  7226 0000299E 7706                    	ja	short fefss_2
  7227 000029A0 3B07                    	cmp	ax, [bx]
  7228 000029A2 742F                    	je	short fefss_8
  7229 000029A4 7228                    	jb	short fefss_7 ; 18/02/2019
  7230                                  fefss_2:
  7231                                  	; 30/10/2020
  7232                                  	;cmp	word [bx], 0
  7233                                  	;jne	short fefss_3
  7234                                  	;cmp	word [bx+2], 0
  7235                                  	;je	short fefss_6	
  7236                                  fefss_3:
  7237 000029A6 3B7F02                  	cmp	di, [bx+2]
  7238 000029A9 7711                    	ja	short fefss_6
  7239 000029AB 7405                    	je	short fefss_4
  7240 000029AD 8B7F02                  	mov	di, [bx+2]
  7241 000029B0 EB04                    	jmp	short fefss_5
  7242                                  fefss_4:
  7243 000029B2 3B37                    	cmp	si, [bx]
  7244 000029B4 7306                    	jnb	short fefss_6
  7245                                  fefss_5:
  7246 000029B6 8B37                    	mov	si, [bx]
  7247                                  	; 22/02/2019
  7248 000029B8 8A0E[FC71]              	mov	cl, [_i_]
  7249                                  fefss_6:
  7250 000029BC FE06[FC71]              	inc	byte [_i_]
  7251 000029C0 382E[FC71]              	cmp	byte [_i_], ch ; [freespace_count]
  7252 000029C4 72C8                    	jb	short fefss_0
  7253                                  	
  7254 000029C6 89F0                    	mov	ax, si
  7255 000029C8 89FA                    	mov	dx, di
  7256 000029CA 30ED                    	xor	ch, ch
  7257 000029CC F9                      	stc
  7258 000029CD C3                      	retn
  7259                                  fefss_7:
  7260 000029CE 8B07                    	mov	ax, [bx]
  7261 000029D0 8B5702                  	mov	dx, [bx+2]
  7262                                  fefss_8:
  7263 000029D3 8B0E[FC71]              	mov	cx, [_i_]
  7264 000029D7 C3                      	retn
  7265                                  
  7266                                  ;-----------------------------------------------------------------------------
  7267                                  
  7268                                  	; 16/02/2019
  7269                                  get_first_free_pte:
  7270                                  	; Find free partition table entry
  7271                                  	;
  7272                                  	; INPUT:
  7273                                  	;	none
  7274                                  	; OUTPUT:
  7275                                  	;	If CF = 0 -> CX = partition table entry number
  7276                                  	;	If CF = 1 -> there is not a free entry in partition table
  7277                                  
  7278 000029D8 BE[F659]                	mov	si, MasterBootBuff+pTableOffset
  7279 000029DB 31C9                    	xor	cx, cx
  7280                                  gffp_1:
  7281 000029DD 8A4404                  	mov	al, [si+ptFileSystemID] ; 23/02/2019
  7282                                  
  7283 000029E0 20C0                    	and	al, al
  7284 000029E2 740E                    	jz	short gffp_3 ; empty
  7285                                  
  7286 000029E4 80F903                  	cmp	cl, 3
  7287 000029E7 7307                    	jnb	short gffp_2
  7288                                  
  7289 000029E9 FEC1                    	inc	cl
  7290 000029EB 83C610                  	add	si, 16 ; Partition table entry size
  7291 000029EE EBED                    	jmp	short gffp_1
  7292                                  gffp_2:
  7293                                  	; CL = 3
  7294 000029F0 F9                      	stc
  7295 000029F1 C3                      	retn
  7296                                  gffp_3:
  7297                                  	; CL = PTE number (0 to 3)
  7298 000029F2 C3                      	retn 	
  7299                                  	
  7300                                  ;-----------------------------------------------------------------------------
  7301                                  ; 03/02/2019
  7302                                  
  7303                                  cylinders_to_sectors:
  7304                                  	; INPUT:
  7305                                  	;	ax = Cylinders (Total or partition's cylinder count)
  7306                                  	; OUTPUT:
  7307                                  	;	dx:ax = Sectors
  7308                                  
  7309 000029F3 8B16[A841]              	mov	dx,[heads]
  7310 000029F7 F7E2                    	mul	dx
  7311                                  		; dx:ax = Number of tracks (cylinders*heads)
  7312 000029F9 8B0E[A641]              	mov	cx,[sectors]
  7313 000029FD E880E4                  	call	mul32
  7314                                  		; dx:ax = Number of sectors 
  7315 00002A00 C3                      	retn
  7316                                  		
  7317                                  ;-----------------------------------------------------------------------------
  7318                                  ; 03/02/2019
  7319                                  
  7320                                  cylinders_to_percent:
  7321                                  
  7322                                  	; INPUT:
  7323                                  	;	bx = Number of cylinders (of partition) -dividend-
  7324                                  	;	cx = Total cylinders -divisor-
  7325                                  	; OUTPUT:
  7326                                  	;	ax = Percentage
  7327                                  
  7328                                  	;  if (cylinders_in == 0)
  7329                                  	;	 percentage_out = 0;
  7330                                  	;  else if (total_cylinders == 0)
  7331                                  	;           percentage_out = 0;
  7332                                  	;       else
  7333                                  
  7334 00002A01 09DB                    	or	bx, bx
  7335 00002A03 7419                    	jz	short ctpc_6 ; ax = 0 = percentage_out 
  7336                                  ctpc_1:
  7337 00002A05 09C9                    	or	cx, cx
  7338 00002A07 7415                    	jz	short ctpc_6
  7339                                  
  7340 00002A09 B86400                  	mov	ax, 100
  7341 00002A0C F7E3                    	mul	bx ; [cylinders_in] 
  7342                                  
  7343                                  		; dx:ax = Dividend
  7344                                  
  7345 00002A0E E861E4                  	call	div32 ; 100*cylinders_in / total_cylinders
  7346                                  		; DX:AX = Quotient
  7347                                  		; BX = Remainder
  7348                                  
  7349                                  	; ax = percentage_out	
  7350                                  
  7351 00002A11 39CB                    	cmp	bx, cx	; is remainder >= total_cylinders/2 ?
  7352 00002A13 7201                    	jb	short ctpc_5 ; No. 
  7353                                  ctpc_4:
  7354 00002A15 40                      	inc	ax
  7355                                  ctpc_5:
  7356 00002A16 83F864                  	cmp	ax, 100
  7357 00002A19 7603                    	jbe	short ctpc_6
  7358 00002A1B B86400                  	mov	ax, 100
  7359                                  ctpc_6:
  7360 00002A1E C3                      	retn
  7361                                  
  7362                                  ;-----------------------------------------------------------------------------
  7363                                  ; 04/02/2019
  7364                                  
  7365                                  display_partition_table:
  7366                                  
  7367                                  	; INPUT:
  7368                                  	;	al = 0 for MBR
  7369                                  	;	   = 5 for EBR (logical drives in extended partition)
  7370                                  	; OUTPUT:
  7371                                  	;	none
  7372                                  
  7373                                  ;pt_positions:
  7374                                  n_pos	equ 30 ; 1 byte	
  7375                                  
  7376 00002A1F A2[0272]                	mov	[_e_], al	
  7377                                  
  7378                                  	; clear screen
  7379 00002A22 B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
  7380 00002A25 CD10                    	int	10h
  7381                                  
  7382 00002A27 803E[0272]05            	cmp	byte [_e_], 5
  7383 00002A2C 7507                    	jne	short dpt_1
  7384                                  dpt_0:
  7385 00002A2E BD[A472]                	mov	bp, ext_table_boot_ind
  7386 00002A31 B045                    	mov	al, 'E'
  7387 00002A33 EB05                    	jmp	short dpt_4
  7388                                  dpt_1:
  7389 00002A35 BD[5872]                	mov	bp, part_table_boot_ind
  7390 00002A38 B04D                    	mov	al, 'M'
  7391                                  dpt_4:
  7392 00002A3A BE[9E5A]                	mov	si, p_table_header
  7393 00002A3D 88441E                  	mov	[si+n_pos], al
  7394 00002A40 E83CF4                         	call 	print_msg
  7395                                     
  7396 00002A43 31DB                    	xor	bx, bx
  7397 00002A45 891E[FC71]              	mov	[_i_], bx
  7398                                  dpt_5:
  7399 00002A49 FE06[FC71]              	inc	byte [_i_]
  7400                                  
  7401                                  	; BX = partition entry (0 to 3)
  7402                                  	; BP = partition table structure address
  7403                                  
  7404 00002A4D E86600                  	call	display_pt_entry  ; display partition table row
  7405                                  
  7406 00002A50 8B1E[FC71]              	mov	bx, [_i_] 
  7407                                  	
  7408 00002A54 80FB04                  	cmp	bl, 4
  7409 00002A57 72F0                    	jb	short dpt_5
  7410                                  
  7411 00002A59 BE[DF5B]                	mov	si, p_table_footer
  7412 00002A5C E820F4                         	call 	print_msg
  7413                                  
  7414                                  	; 27/02/2019
  7415 00002A5F BF[8C57]                	mov	di, str_disk_sectors
  7416                                  
  7417 00002A62 803E[0272]05            	cmp	byte [_e_], 5
  7418 00002A67 741D                    	je	short dpt_9 
  7419                                  
  7420                                  	; display total disk sectors
  7421                                  
  7422                                  	;mov	di, str_disk_sectors
  7423                                  
  7424                                  	;cmp	byte [di], '0'
  7425                                  	;jnb	short dpt_8	
  7426                                  
  7427 00002A69 A1[9C6F]                        mov	ax, [total_sectors]
  7428 00002A6C 8B16[9E6F]                      mov	dx, [total_sectors+2]
  7429                                  
  7430 00002A70 E82200                  	call	dpt_10
  7431                                  dpt_8:
  7432 00002A73 BE[7657]                	mov	si, msg_disk_sectors
  7433                                  dpt_11:
  7434 00002A76 E806F4                  	call	print_msg
  7435                                  
  7436 00002A79 BE[8C57]                	mov	si, str_disk_sectors
  7437 00002A7C E800F4                  	call	print_msg
  7438                                  
  7439 00002A7F BE[6057]                	mov	si, CRLF
  7440 00002A82 E8FAF3                  	call	print_msg
  7441                                  
  7442 00002A85 C3                      	retn
  7443                                  
  7444                                  dpt_9:
  7445                                  	; display extended partition size
  7446                                  
  7447 00002A86 A1[F471]                	mov	ax, [ep_Size]
  7448 00002A89 8B16[F671]                      mov	dx, [ep_Size+2]
  7449                                  
  7450 00002A8D E80500                  	call	dpt_10
  7451                                  
  7452 00002A90 BE[9457]                	mov	si, msg_ep_size
  7453 00002A93 EBE1                    	jmp	short dpt_11
  7454                                  
  7455                                  dpt_10:
  7456 00002A95 89E6                    	mov	si, sp
  7457 00002A97 B90A00                  	mov	cx, 10
  7458                                  dpt_6:
  7459 00002A9A E8D5E3                  	call	div32
  7460                                  	
  7461 00002A9D 80C330                  	add	bl, '0'
  7462 00002AA0 53                      	push	bx
  7463 00002AA1 21C0                    	and	ax, ax
  7464 00002AA3 75F5                    	jnz	short dpt_6
  7465 00002AA5 21D2                    	and	dx, dx
  7466 00002AA7 75F1                    	jnz	short dpt_6
  7467                                  
  7468 00002AA9 29E6                    	sub	si, sp
  7469 00002AAB D1EE                    	shr	si, 1
  7470                                  dpt_7:
  7471 00002AAD 58                      	pop	ax
  7472 00002AAE AA                      	stosb
  7473 00002AAF 4E                      	dec	si
  7474 00002AB0 75FB                    	jnz	short dpt_7
  7475                                  
  7476 00002AB2 30C0                    	xor	al, al
  7477 00002AB4 AA                      	stosb
  7478                                  
  7479                                  	; 27/02/2019
  7480 00002AB5 C3                      	retn
  7481                                  
  7482                                  ;-----------------------------------------------------------------------------
  7483                                  ; 04/02/2019
  7484                                  
  7485                                  struc ptbl
  7486                                  
  7487 00000000 <res 00000001>          .boot_ind:	resb 1
  7488 00000001 <res 00000001>          .start_head:	resb 1
  7489 00000002 <res 00000001>          .start_sector:	resb 1
  7490 00000003 <res 00000002>          .start_cyl:	resw 1
  7491 00000005 <res 00000001>          .sys_id:	resb 1
  7492 00000006 <res 00000001>          .end_head:	resb 1
  7493 00000007 <res 00000001>          .end_sector:	resb 1
  7494 00000008 <res 00000002>          .end_cyl:	resw 1
  7495 0000000A <res 00000002>          .rel_sec_lw:	resw 1
  7496 0000000C <res 00000002>          .rel_sec_hw:	resw 1
  7497 0000000E <res 00000002>          .num_sec_lw:	resw 1
  7498 00000010 <res 00000002>          .num_sec_hw:	resw 1	
  7499                                  .size:
  7500                                  
  7501                                  endstruc
  7502                                  
  7503                                  display_pt_entry:
  7504                                  
  7505                                  	; INPUT:
  7506                                  	;	bl = partition entry
  7507                                  	;	bh = 0
  7508                                  	;	bp = partition table structure address
  7509                                  	; OUTPUT:
  7510                                  	;	none
  7511                                  
  7512                                  ;pt_positions:
  7513                                  p_pos	equ 7  ; 1 byte	hdi
  7514                                  s_pos	equ 9  ; 2+1 byte
  7515                                  bh_pos	equ 13 ; 2+1 bytes
  7516                                  bs_pos	equ 17 ; 2+1 bytes
  7517                                  bc_pos	equ 21 ; 2+1 bytes
  7518                                  fs_pos  equ 25 ; 2+1 bytes
  7519                                  eh_pos  equ 29 ; 2+1 bytes
  7520                                  es_pos	equ 33 ; 2+1 bytes
  7521                                  ec_pos	equ 37 ; 2+1 bytes
  7522                                  rs_pos	equ 42 ; 7 bytes
  7523                                  ns_pos	equ 52 ; 7 bytes
  7524                                  fsx_pos equ 61 ; 14 bytes
  7525                                  
  7526 00002AB6 55                      	push	 bp ; 23/02/2019
  7527                                  
  7528 00002AB7 08DB                    	or	bl, bl
  7529 00002AB9 7406                    	jz	short dpte_0
  7530                                  
  7531                                  	;xor	bh, bh
  7532 00002ABB B012                    	mov	al, ptbl.size ; 18
  7533 00002ABD F6E3                    	mul	bl
  7534 00002ABF 01C5                    	add	bp, ax
  7535                                  dpte_0:
  7536 00002AC1 807E0500                	cmp	byte [bp+ptbl.sys_id], 0
  7537 00002AC5 0F860601                	jna	dpte_9
  7538                                  
  7539 00002AC9 B768                    	mov	bh, 'h'
  7540                                  
  7541 00002ACB BE[0472]                	mov	si, pte_row
  7542                                  
  7543                                  	; clear partition table display buffer/row
  7544 00002ACE 89F7                    	mov	di, si
  7545 00002AD0 B92800                  	mov	cx, 40
  7546 00002AD3 B82020                  	mov	ax, 2020h
  7547 00002AD6 F3AB                    	rep	stosw
  7548                                  
  7549 00002AD8 88D8                    	mov	al, bl
  7550 00002ADA 0431                    	add	al, '1'
  7551 00002ADC 884407                  	mov	[si+p_pos], al  ; partition number '1' to '4'
  7552                                  
  7553                                  	; partition status, type and CHS parameters
  7554                                  	; (as hexadecimal number)
  7555                                  
  7556                                  	;mov	al, [bp+ptbl.boot_ind]
  7557 00002ADF 8A4600                  	mov	al, [bp]
  7558 00002AE2 E839F4                  	call	byte_to_hex
  7559                                  
  7560 00002AE5 894409                  	mov	[si+s_pos], ax
  7561 00002AE8 887C0B                  	mov	[si+s_pos+2], bh ; 'h'
  7562                                  
  7563 00002AEB 8A4601                  	mov	al, [bp+ptbl.start_head]
  7564 00002AEE E82DF4                  	call	byte_to_hex
  7565                                  
  7566 00002AF1 89440D                  	mov	[si+bh_pos], ax
  7567 00002AF4 887C0F                  	mov	[si+bh_pos+2], bh ; 'h'
  7568                                  
  7569 00002AF7 8B4E03                  	mov	cx, [bp+ptbl.start_cyl]
  7570 00002AFA C0E506                  	shl	ch, 6
  7571 00002AFD 8A4602                  	mov	al, [bp+ptbl.start_sector]
  7572 00002B00 08E8                    	or	al, ch
  7573 00002B02 E819F4                  	call	byte_to_hex
  7574                                  
  7575 00002B05 894411                  	mov	[si+bs_pos], ax
  7576 00002B08 887C13                  	mov	[si+bs_pos+2], bh ; 'h'
  7577                                  
  7578                                  	;mov	al, [bp+ptbl.start_cyl]
  7579 00002B0B 88C8                    	mov	al, cl
  7580 00002B0D E80EF4                  	call	byte_to_hex
  7581                                  
  7582 00002B10 894415                  	mov	[si+bc_pos], ax
  7583 00002B13 887C17                  	mov	[si+bc_pos+2], bh ; 'h'
  7584                                  
  7585 00002B16 8A4605                  	mov	al, [bp+ptbl.sys_id]
  7586 00002B19 E802F4                  	call	byte_to_hex
  7587                                  
  7588 00002B1C 894419                  	mov	[si+fs_pos], ax
  7589 00002B1F 887C1B                  	mov	[si+fs_pos+2], bh ; 'h'
  7590                                  
  7591 00002B22 8A4606                  	mov	al, [bp+ptbl.end_head]
  7592 00002B25 E8F6F3                  	call	byte_to_hex
  7593                                  
  7594 00002B28 89441D                  	mov	[si+eh_pos], ax
  7595 00002B2B 887C1F                  	mov	[si+eh_pos+2], bh ; 'h'
  7596                                  
  7597 00002B2E 8B4E08                  	mov	cx, [bp+ptbl.end_cyl]
  7598 00002B31 C0E506                  	shl	ch, 6
  7599 00002B34 8A4607                  	mov	al, [bp+ptbl.end_sector]
  7600 00002B37 08E8                    	or	al, ch
  7601 00002B39 E8E2F3                  	call	byte_to_hex
  7602                                  
  7603 00002B3C 894421                  	mov	[si+es_pos], ax
  7604 00002B3F 887C23                  	mov	[si+es_pos+2], bh ; 'h'
  7605                                  
  7606                                  	;mov	al, [bp+ptbl.end_cyl]
  7607 00002B42 88C8                    	mov	al, cl
  7608 00002B44 E8D7F3                  	call	byte_to_hex
  7609                                  
  7610 00002B47 894425                  	mov	[si+ec_pos], ax
  7611 00002B4A 887C27                  	mov	[si+ec_pos+2], bh ; 'h'
  7612                                  
  7613                                  	; relative (start) sector address (lba)
  7614                                  	; (as decimal number)
  7615                                  
  7616 00002B4D 8B460A                          mov	ax, [bp+ptbl.rel_sec_lw]
  7617 00002B50 8B560C                          mov	dx, [bp+ptbl.rel_sec_hw]
  7618                                  
  7619 00002B53 89E7                    	mov	di, sp
  7620 00002B55 B90A00                  	mov	cx, 10
  7621                                  dpte_1:
  7622 00002B58 E817E3                  	call	div32
  7623                                  	
  7624 00002B5B 80C330                  	add	bl, '0'
  7625 00002B5E 53                      	push	bx
  7626 00002B5F 21C0                    	and	ax, ax
  7627 00002B61 75F5                    	jnz	short dpte_1
  7628 00002B63 21D2                    	and	dx, dx
  7629 00002B65 75F1                    	jnz	short dpte_1
  7630                                  
  7631 00002B67 8D5C31                  	lea	bx, [si+rs_pos+7]
  7632                                  
  7633 00002B6A 29E7                    	sub	di, sp
  7634 00002B6C D1EF                    	shr	di, 1
  7635 00002B6E 29FB                    	sub	bx, di	
  7636                                  dpte_2:
  7637 00002B70 58                      	pop	ax
  7638 00002B71 8807                    	mov	[bx], al
  7639 00002B73 4F                      	dec	di
  7640 00002B74 7403                    	jz	short dpte_3
  7641                                  	
  7642 00002B76 43                      	inc	bx
  7643 00002B77 EBF7                    	jmp	short dpte_2
  7644                                  
  7645                                  dpte_3:
  7646                                  	; number of sectors)
  7647                                  	; (as decimal number)
  7648                                  
  7649 00002B79 8B460E                          mov	ax, [bp+ptbl.num_sec_lw]
  7650 00002B7C 8B5610                          mov	dx, [bp+ptbl.num_sec_hw]
  7651                                  
  7652 00002B7F 89E7                    	mov	di, sp
  7653                                  	;mov	cx, 10
  7654                                  dpte_4:
  7655 00002B81 E8EEE2                  	call	div32
  7656                                  	
  7657 00002B84 80C330                  	add	bl, '0'
  7658 00002B87 53                      	push	bx
  7659 00002B88 21C0                    	and	ax, ax
  7660 00002B8A 75F5                    	jnz	short dpte_4
  7661 00002B8C 21D2                    	and	dx, dx
  7662 00002B8E 75F1                    	jnz	short dpte_4
  7663                                  
  7664 00002B90 8D5C3B                  	lea	bx, [si+ns_pos+7]
  7665                                  
  7666 00002B93 29E7                    	sub	di, sp
  7667 00002B95 D1EF                    	shr	di, 1
  7668 00002B97 29FB                    	sub	bx, di	
  7669                                  dpte_5:
  7670 00002B99 58                      	pop	ax
  7671 00002B9A 8807                    	mov	[bx], al
  7672 00002B9C 4F                      	dec	di
  7673 00002B9D 7403                    	jz	short dpte_6
  7674                                  	
  7675 00002B9F 43                      	inc	bx
  7676 00002BA0 EBF7                    	jmp	short dpte_5
  7677                                  dpte_6:
  7678                                  	; set file system name
  7679                                  
  7680 00002BA2 8A4605                  	mov	al, [bp+ptbl.sys_id]
  7681 00002BA5 BF[C642]                	mov	di, valid_partitions
  7682 00002BA8 B91300                  	mov	cx, 19
  7683 00002BAB F2AE                    	repnz	scasb
  7684 00002BAD 7405                    	jz	short dpte_7
  7685 00002BAF B8[B842]                	mov	ax, FS_OTHERS	 
  7686 00002BB2 EB0C                    	jmp	short dpte_8
  7687                                  dpte_7:
  7688 00002BB4 81EF[C742]              	sub	di, valid_partitions + 1
  7689 00002BB8 B80E00                  	mov	ax, 14
  7690 00002BBB F7E7                    	mul	di
  7691 00002BBD 05[AE41]                	add	ax, FileSys_Names
  7692                                  dpte_8:
  7693 00002BC0 8D7C3D                  	lea	di, [si+fsx_pos]
  7694 00002BC3 89C6                    	mov	si, ax
  7695 00002BC5 B107                    	mov	cl, 7
  7696 00002BC7 F3A5                    	rep	movsw
  7697                                  
  7698 00002BC9 BE[0472]                	mov	si, pte_row
  7699 00002BCC E8B0F2                  	call	print_msg
  7700                                  dpte_9:
  7701 00002BCF 5D                      	pop	bp ; 23/02/2019
  7702                                  	
  7703 00002BD0 C3                      	retn
  7704                                  
  7705                                  ;-----------------------------------------------------------------------------
  7706                                  ; 24/02/2019
  7707                                  
  7708                                  partition_table_fix:
  7709                                  	; DELETE or EXIT option for Invalid Partition Table Entry
  7710                                  	; INPUT: 
  7711                                  	;	DS:SI = PTE address in MBR buffer
  7712                                  	
  7713 00002BD1 56                      	push	si  ; save PTE address
  7714                                  
  7715 00002BD2 89F0                    	mov	ax, si
  7716 00002BD4 2D[F659]                	sub	ax, MasterBootBuff+446
  7717 00002BD7 C0E804                  	shr	al, 4 ; / 16 
  7718 00002BDA 0431                    	add	al, '1'
  7719 00002BDC A2[A661]                	mov	[inv_pte_num], al
  7720                                  
  7721                                  	; DS:SI = PTE address in MBR buffer
  7722 00002BDF E8F2F7                  	call	show_selected_partition
  7723                                  
  7724                                  	;mov	si, CRLF
  7725                                  	;call	print_msg
  7726                                  
  7727                                  	; Warning message...
  7728                                  
  7729 00002BE2 BE[8261]                	mov	si, msg_inv_pte
  7730 00002BE5 E897F2                  	call	print_msg
  7731                                  
  7732 00002BE8 5F                      	pop	di  ; restore PTE address
  7733                                  ptf_0:	
  7734 00002BE9 30E4                    	xor	ah, ah
  7735 00002BEB CD16                    	int	16h
  7736                                  
  7737 00002BED 3C0D                    	cmp	al, 13
  7738 00002BEF 7406                    	je	short ptf_1
  7739                                  
  7740 00002BF1 3C1B                    	cmp	al, 27
  7741 00002BF3 75F4                    	jne	short ptf_0
  7742                                  
  7743 00002BF5 F9                      	stc
  7744 00002BF6 C3                      	retn
  7745                                  ptf_1:
  7746                                  	; Clear that (invalid) PTE
  7747 00002BF7 31C0                    	xor	ax, ax	
  7748 00002BF9 B90800                  	mov	cx, 8
  7749 00002BFC F3AB                    	rep	stosw
  7750                                  
  7751                                  	; Clear screen
  7752 00002BFE B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
  7753 00002C01 CD10                    	int	10h
  7754                                  
  7755 00002C03 C3                      	retn
  7756                                  
  7757                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7758                                  ; Display (& Edit) EXTENDED (DOS) Partition Table
  7759                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7760                                  ; 28/02/2019
  7761                                  
  7762                                  display_extended_pt:
  7763 00002C04 B005                    	mov	al, 5 ; extended partition (logical drives)
  7764 00002C06 E816FE                  	call	display_partition_table
  7765                                  
  7766 00002C09 BE[7A63]                	mov	si, ebr_editing_options
  7767 00002C0C E870F2                  	call	print_msg
  7768                                  
  7769 00002C0F BE[895F]                	mov	si, enter_opt_num_cancel_msg
  7770 00002C12 E86AF2                  	call	print_msg
  7771                                  
  7772 00002C15 BE[6057]                	mov	si, CRLF
  7773 00002C18 E864F2                  	call	print_msg
  7774                                  dept_1:
  7775 00002C1B 30E4                    	xor	ah, ah
  7776 00002C1D CD16                    	int	16h
  7777                                  
  7778 00002C1F 3C30                    	cmp	al, '0'
  7779 00002C21 740C                    	je	short dept_2
  7780                                  
  7781 00002C23 3C31                    	cmp	al, '1'
  7782 00002C25 7467                    	je	short edit_ext_table_create
  7783 00002C27 3C32                    	cmp	al, '2'
  7784 00002C29 7407                    	je	short edit_ext_table_delete
  7785                                  		
  7786 00002C2B 3C1B                    	cmp	al, 27 ; ESCape
  7787 00002C2D 75EC                    	jne	short dept_1
  7788                                  dept_2:
  7789 00002C2F E903D8                  	jmp	A_48
  7790                                  
  7791                                  edit_ext_table_delete:
  7792                                  	; 28/02/2019
  7793 00002C32 B005                    	mov	al, 5 ; extended partition (logical drives)
  7794 00002C34 E8E8FD                  	call	display_partition_table
  7795                                  
  7796 00002C37 BE[F963]                	mov	si, msg_delete_ldd_q
  7797 00002C3A E842F2                  	call	print_msg
  7798                                  
  7799                                  	;mov	si, CRLF
  7800                                  	;call	print_msg
  7801                                  eetd_1:
  7802 00002C3D 30E4                    	xor	ah, ah
  7803 00002C3F CD16                    	int	16h
  7804                                  
  7805 00002C41 3C1B                    	cmp	al, 27
  7806 00002C43 7410                    	je	short eetd_2
  7807                                  
  7808 00002C45 24DF                    	and	al, 0DFh
  7809 00002C47 3C59                    	cmp	al, 'Y'
  7810 00002C49 7412                    	je	short eetd_yes
  7811 00002C4B 3C4E                    	cmp	al, 'N'
  7812 00002C4D 75EE                    	jne	short eetd_1
  7813                                  eetd_no:
  7814 00002C4F BE[095F]                	mov	si, msg_NO ;  Write 'NO' (it may be shown for a moment)
  7815 00002C52 E82AF2                  	call	print_msg
  7816                                  eetd_2:	
  7817 00002C55 BE[6057]                	mov	si, CRLF  ; Next line
  7818 00002C58 E824F2                  	call	print_msg
  7819 00002C5B EBA7                    	jmp	short display_extended_pt
  7820                                  eetd_yes:
  7821 00002C5D BE[035F]                	mov	si, msg_YES ;  Write 'YES' (it may be shown for a moment)
  7822 00002C60 E81CF2                  	call	print_msg
  7823 00002C63 BE[6057]                	mov	si, CRLF  ; Next line
  7824 00002C66 E816F2                  	call	print_msg
  7825 00002C69 E87106                  	call	delete_logical_drives
  7826 00002C6C 803E[E46F]00            	cmp	byte [ldrives], 0
  7827 00002C71 7791                    	ja	short display_extended_pt
  7828 00002C73 E9BFD7                  	jmp	A_48
  7829                                  
  7830                                  ;-----------------------------------------------------------------------------
  7831                                  
  7832                                  eetc_2:
  7833 00002C76 BE[5F64]                	mov	si, msg_create_ldd_max_error
  7834                                  eetc_10:
  7835 00002C79 E803F2                  	call	print_msg
  7836 00002C7C BE[1958]                	mov	si, msg_press_any_key
  7837 00002C7F E8FDF1                  	call	print_msg
  7838 00002C82 30E4                    	xor	ah, ah
  7839 00002C84 CD16                    	int	16h
  7840 00002C86 E97BFF                  	jmp	display_extended_pt
  7841                                  	
  7842                                  	; 05/03/2019
  7843                                  eetc_9:
  7844 00002C89 BE[C866]                	mov	si, msg_c_ldd_nofspc_error
  7845 00002C8C EBEB                    	jmp	short eetc_10
  7846                                  
  7847                                  ;-----------------------------------------------------------------------------
  7848                                  ; 01/03/2019
  7849                                  
  7850                                  edit_ext_table_create:
  7851                                  
  7852                                  ; Create Method: ; 04/03/2019
  7853                                  ;LDD 1 <- LDD_START0, ebr 1st entry <- MBR (extended partition) - EBR 0
  7854                                  ;LDD 2 <- LDD_START1, ebr 2nd entry <- EBR 1
  7855                                  ;LDD 3 <- LDD_START2, ebr 2nd entry <- EBR 2
  7856                                  ;LDD 4 <- LDD_START3, ebr 2nd entry <- EBR 3
  7857                                  
  7858                                  	; 01/03/2019
  7859 00002C8E 803E[A372]00            	cmp	byte [epnumber], 0 ; check extended partition
  7860 00002C93 0F868DE3                	jna	B_55		; cancel with error message
  7861                                  
  7862                                  	; 05/03/2019
  7863 00002C97 E8ED02                  	call	check_ext_free_space
  7864 00002C9A 72ED                    	jc	eetc_9	; error, no free space in extented partition
  7865                                  
  7866                                  	; 30/10/2020
  7867 00002C9C A3[6273]                	mov	[ep_free_sectors], ax
  7868 00002C9F 8916[6473]              	mov	[ep_free_sectors+2], dx
  7869                                  
  7870 00002CA3 803E[E46F]04            	cmp	byte [ldrives], 4
  7871 00002CA8 73CC                    	jnb	eetc_2	; error, write program limit message
  7872                                  
  7873                                  edit_ext_table_create_x: ; 02/03/2019
  7874                                  
  7875                                  	; Get logical drive size/cylinders (request) from user
  7876 00002CAA E84C03                  	call	get_ldd_size
  7877 00002CAD 833E[6873]01            	cmp	word [lcylinders], 1  ; at least 1 cylinder
  7878 00002CB2 0F824EFF                	jb	display_extended_pt ; cancel
  7879                                  
  7880                                  	; Open hard disk image file
  7881 00002CB6 BA[915A]                	mov	dx, img_file_name
  7882 00002CB9 B8023D                  	mov	ax, 3D02h ; open for reading and writing
  7883 00002CBC CD21                    	int	21h
  7884 00002CBE 0F82A7F1                	jc	D_02
  7885                                  
  7886 00002CC2 A3[A441]                	mov	[img_file_handle], ax
  7887                                  
  7888                                  	; 03/03/2019
  7889 00002CC5 A0[E46F]                	mov	al, [ldrives]
  7890                                  
  7891                                  	;cmp	byte [ldrives], 1
  7892                                  	;jnb	short eetc_3	; skip verify MBR extended partition
  7893                                  
  7894 00002CC8 20C0                    	and	al, al
  7895 00002CCA 757C                    	jnz	short eetc_3
  7896                                  
  7897 00002CCC 31ED                    	xor	bp, bp
  7898                                  
  7899                                  	; Read MBR at EBR buffer
  7900                                  	;xor	ax, ax
  7901 00002CCE 31D2                    	xor	dx, dx
  7902 00002CD0 BB[EA6F]                	mov	bx, ebr_buffer
  7903 00002CD3 E8F7F1                  	call	read_hd_sector
  7904 00002CD6 7218                    	jc	short eetc_0
  7905                                  
  7906 00002CD8 A0[A372]                	mov	al, [epnumber]
  7907 00002CDB 98                      	cbw
  7908 00002CDC C0E004                  	shl	al, 4 ; * 16	
  7909 00002CDF BE[A871]                	mov	si, ebr_buffer+446
  7910 00002CE2 01C6                    	add	si, ax
  7911 00002CE4 BF[F659]                	mov	di, MasterBootBuff+446
  7912 00002CE7 01C7                    	add	di, ax
  7913 00002CE9 B90800                  	mov	cx, 8
  7914 00002CEC F3A7                    	repe	cmpsw	; repeat comparising while cx > 0 and zf = 1
  7915 00002CEE E30C                    	jcxz	eetc_1	; Extended partition entry is not changed 
  7916                                  	; Different PTE (means there is a new extended partition) 
  7917                                  eetc_0:
  7918                                  	; Write current MBR (with modified PT)
  7919 00002CF0 BB[3858]                	mov	bx, MasterBootBuff
  7920 00002CF3 31C0                    	xor	ax, ax
  7921                                  	; 25/10/2020
  7922                                  	;xor	dx, dx
  7923 00002CF5 E896F1                  	call	write_hd_sector
  7924 00002CF8 0F8263F1                	jc	D_01 ; ! display error msg and then exit !
  7925                                  eetc_1:
  7926                                  	; clear	EBR buffer
  7927 00002CFC BF[EA6F]                	mov	di, ebr_buffer
  7928 00002CFF 31C0                    	xor	ax, ax
  7929 00002D01 B9FF00                  	mov	cx, 255
  7930 00002D04 F3AB                    	rep	stosw
  7931 00002D06 C70555AA                	mov	word [di], 0AA55h
  7932                                  
  7933                                  	; Set logical dos drive parameters in it's EBR
  7934 00002D0A BF[A871]                	mov	di, ebr_buffer+446
  7935                                  
  7936 00002D0D 8B0E[A641]              	mov	cx, [sectors]
  7937 00002D11 29DB                    	sub	bx, bx ; 0
  7938 00002D13 A1[EC71]                	mov	ax, [ep_StartSector]
  7939 00002D16 8B16[EE71]              	mov	dx, [ep_StartSector+2]
  7940                                  
  7941                                  	; 03/03/2019
  7942                                  	; set partition start address & size
  7943                                  
  7944 00002D1A A3[4273]                	mov	[ldd_start], ax
  7945 00002D1D 8916[4473]              	mov	[ldd_start+2], dx
  7946                                  
  7947                                  	; 01/11/2020
  7948 00002D21 833E[6873]FF            	cmp	word [lcylinders], 65535  
  7949                                  			; sign for using all of available sectors	
  7950 00002D26 7209                    	jb	short eetc_11
  7951                                  
  7952 00002D28 A1[6273]                	mov	ax, [ep_free_sectors]
  7953 00002D2B 8B16[6473]              	mov	dx, [ep_free_sectors+2]
  7954 00002D2F EB0B                    	jmp	short eetc_12
  7955                                  eetc_11:
  7956 00002D31 A0[A841]                	mov	al, [heads]
  7957 00002D34 F626[A641]              	mul	byte [sectors]
  7958 00002D38 F726[6873]              	mul	word [lcylinders]
  7959                                  eetc_12:
  7960                                  	; 01/11/2020
  7961 00002D3C 31ED                    	xor	bp, bp
  7962 00002D3E A3[5273]                	mov	[ldd_size], ax
  7963 00002D41 8916[5473]              	mov	[ldd_size+2], dx
  7964                                  
  7965                                  	; 1st ldd start sector is always 63 or 17 (= spt)
  7966                                  	;sub	ax, cx ; cx = 63 or 17, [sectors]
  7967                                  	;sbb	dx, bx ; sbb dx, 0
  7968                                  
  7969                                  	; 01/11/2020	
  7970 00002D45 E9DD00                  	jmp	eetc_4
  7971                                  
  7972                                  	;mov	[di+ptStartSector], cx
  7973                                  	;mov	[di+ptStartSector+2], bx
  7974                                  	;
  7975                                  	;; 01/11/2020
  7976                                  	;mov	[di+ptSectors], ax
  7977                                  	;mov	[di+ptSectors+2], dx
  7978                                  	;
  7979                                  	;mov	cx, ax
  7980                                  	;mov	bx, dx
  7981                                  	;; cx:bx = volume size of logical -dos- drive
  7982                                  	;
  7983                                  	;pop	ax ; ldd's LBA
  7984                                  	;pop	dx
  7985                                  	;; dx:ax = start sector address of ldd
  7986                                  	;
  7987                                  	;; 01/11/2020
  7988                                  	;add	cx, ax
  7989                                  	;adc	bx, dx
  7990                                  	;sub	cx, 1
  7991                                  	;sbb	bx, 0
  7992                                  	;; bx:cx = end sector address of ldd
  7993                                  	;push	cx
  7994                                  	;push	bx
  7995                                  	;
  7996                                  	;jmp	eetc_4
  7997                                  
  7998                                  eetc_3:
  7999                                  	; [ldrives] >= 1
  8000                                  	; Read EBR
  8001                                  	;mov	al, [ldrives]
  8002                                  	;;xor	ah, ah
  8003 00002D48 C0E002                  	shl	al, 2
  8004 00002D4B 89C5                    	mov	bp, ax
  8005                                  
  8006                                  	; 03/03/2019
  8007 00002D4D 8B86[3E73]              	mov	ax, [bp+ldd_start-4]
  8008 00002D51 8B96[4073]              	mov	dx, [bp+ldd_start-2]
  8009 00002D55 BB[EA6F]                	mov	bx, ebr_buffer
  8010 00002D58 E872F1                  	call	read_hd_sector
  8011 00002D5B 0F8200F1                	jc	D_01 ; ! display error msg and then exit !
  8012                                  
  8013                                  	; 04/03/2019
  8014 00002D5F BE[B871]                	mov	si, ebr_buffer+446+16 ; 2nd entry (next EBR)
  8015                                  	
  8016                                  	; 03/03/2019
  8017 00002D62 8B86[3E73]              	mov	ax, [bp+ldd_start-4]
  8018 00002D66 8B96[4073]              	mov	dx, [bp+ldd_start-2]
  8019 00002D6A 0386[4E73]              	add	ax, [bp+ldd_size-4]
  8020 00002D6E 1396[5073]              	adc	dx, [bp+ldd_size-2]
  8021                                  
  8022 00002D72 8B0E[EC71]              	mov	cx, [ep_StartSector]
  8023 00002D76 8B1E[EE71]              	mov	bx, [ep_StartSector+2]
  8024                                  
  8025 00002D7A 8986[4273]              	mov	[bp+ldd_start], ax
  8026 00002D7E 8996[4473]              	mov	[bp+ldd_start+2], dx
  8027                                  
  8028 00002D82 52                      	push	dx ; ldd's start sector LBA
  8029 00002D83 50                      	push	ax
  8030                                  	
  8031 00002D84 29C8                    	sub	ax, cx
  8032 00002D86 19DA                    	sbb	dx, bx
  8033                                  	; dx:ax = offset from start of the ep start sector
  8034                                  
  8035 00002D88 894408                  	mov	[si+ptStartSector], ax
  8036 00002D8B 89540A                  	mov	[si+ptStartSector+2], dx
  8037                                  
  8038                                  	; 01/11/2020
  8039 00002D8E 833E[6873]FF            	cmp	word [lcylinders], 65535  
  8040                                  			; sign for using all of available sectors	
  8041 00002D93 7209                    	jb	short eetc_13
  8042                                  
  8043 00002D95 A1[6273]                	mov	ax, [ep_free_sectors]
  8044 00002D98 8B16[6473]              	mov	dx, [ep_free_sectors+2]
  8045 00002D9C EB0B                    	jmp	short eetc_14
  8046                                  eetc_13:
  8047 00002D9E A0[A841]                	mov	al, [heads]
  8048 00002DA1 F626[A641]              	mul	byte [sectors]
  8049 00002DA5 F726[6873]              	mul	word [lcylinders]
  8050                                  eetc_14:
  8051                                  	; 01/11/2020
  8052 00002DA9 8986[5273]              	mov	[bp+ldd_size], ax
  8053 00002DAD 8996[5473]              	mov	[bp+ldd_size+2], dx
  8054                                  
  8055 00002DB1 89440C                   	mov	[si+ptSectors], ax
  8056 00002DB4 89540E                  	mov	[si+ptSectors+2], dx
  8057                                  
  8058                                  	; 01/11/2020
  8059 00002DB7 89C1                    	mov	cx, ax
  8060 00002DB9 89D3                    	mov	bx, dx
  8061                                  	; cx:bx = volume size of logical -dos- drive
  8062                                  
  8063 00002DBB 58                      	pop	ax ; ldd's start sector LBA	
  8064 00002DBC 5A                      	pop	dx
  8065                                  
  8066                                  	; 01/11/2020
  8067 00002DBD 01C1                    	add	cx, ax
  8068 00002DBF 11D3                    	adc	bx, dx
  8069 00002DC1 83E901                  	sub	cx, 1
  8070 00002DC4 83DB00                  	sbb	bx, 0
  8071                                  	; bx:cx = end sector address of ldd
  8072 00002DC7 51                      	push	cx
  8073 00002DC8 53                      	push	bx
  8074                                  
  8075                                  	; calculate CHS from LBA
  8076 00002DC9 E8FE01                  	call	lba_to_chs
  8077                                  		; ax = cylinder
  8078                                  		; dl = sector
  8079                                  		; dh = head
  8080                                  
  8081 00002DCC C60400                  	mov	byte [si+ptBootable], 0
  8082 00002DCF 887401                  	mov	[si+ptBeginHead], dh
  8083 00002DD2 884403                  	mov	[si+ptBeginCylinder], al
  8084 00002DD5 C0E406                  	shl	ah, 6
  8085 00002DD8 08E2                    	or	dl, ah		
  8086 00002DDA 885402                  	mov	[si+ptBeginSector], dl
  8087                                  
  8088                                   	;;mov	ax, [si+ptSectors]
  8089                                  	;;mov	dx, [si+ptSectors+2]
  8090                                   	;mov	ax, [bp+ldd_size]
  8091                                  	;mov	dx, [bp+ldd_size+2]
  8092                                  	;sub	ax, 1
  8093                                  	;sbb	dx, 0
  8094                                  	;add	ax, [bp+ldd_start]
  8095                                  	;adc	dx, [bp+ldd_start+2]
  8096                                  	;	; dx:ax = end sector
  8097                                  	
  8098                                  	; 01/11/2020
  8099 00002DDD 58                      	pop	ax
  8100 00002DDE 5A                      	pop	dx
  8101                                  	; dx:ax = end sector address of ldd
  8102                                  
  8103 00002DDF E8E801                  	call	lba_to_chs
  8104                                  		; ax = cylinder
  8105                                  		; dl = sector
  8106                                  		; dh = head
  8107                                  		
  8108 00002DE2 C6440405                	mov	byte [si+ptFileSystemID], 5 ; EXTENDED
  8109 00002DE6 887405                  	mov	[si+ptEndHead], dh
  8110 00002DE9 884407                  	mov	[si+ptEndCylinder], al
  8111 00002DEC C0E406                  	shl	ah, 6
  8112 00002DEF 08D4                    	or	ah, dl	
  8113 00002DF1 886406                  	mov	[si+ptEndSector], ah
  8114                                  
  8115                                  	; Write EBR
  8116 00002DF4 8B86[3E73]              	mov	ax, [bp+ldd_start-4]
  8117 00002DF8 8B96[4073]              	mov	dx, [bp+ldd_start-2]
  8118 00002DFC BB[EA6F]                	mov	bx, ebr_buffer
  8119 00002DFF E88CF0                  	call	write_hd_sector
  8120 00002E02 0F8259F0                	jc	D_01 ; ! display error msg and then exit !
  8121                                  
  8122                                  	; clear	EBR buffer
  8123 00002E06 BF[EA6F]                	mov	di, ebr_buffer
  8124 00002E09 31C0                    	xor	ax, ax
  8125 00002E0B B9FF00                  	mov	cx, 255
  8126 00002E0E F3AB                    	rep	stosw
  8127 00002E10 C70555AA                	mov	word [di], 0AA55h
  8128                                  
  8129 00002E14 BF[A871]                	mov	di, ebr_buffer+446 ; 1st entry points to LDD
  8130                                  
  8131 00002E17 8B0E[A641]              	mov	cx, [sectors]
  8132 00002E1B 29DB                    	sub	bx, bx ; 0
  8133                                  	; 01/11/2020
  8134 00002E1D 8B86[5273]              	mov	ax, [bp+ldd_size]
  8135 00002E21 8B96[5473]              	mov	dx, [bp+ldd_size+2]
  8136                                  	;sub	ax, cx
  8137                                  	;sbb	dx, bx ; sbb dx, 0 
  8138                                  eetc_4:	
  8139 00002E25 894D08                  	mov	[di+ptStartSector], cx
  8140 00002E28 895D0A                  	mov	[di+ptStartSector+2], bx
  8141                                  
  8142                                  	; 01/11/2020
  8143                                  	; 1st ldd start sector is always 63 or 17 (= spt)
  8144 00002E2B 29C8                    	sub	ax, cx ; cx = 63 or 17, [sectors]
  8145 00002E2D 19DA                    	sbb	dx, bx ; sbb dx, 0
  8146                                  
  8147                                  	; 01/11/2020
  8148 00002E2F 89450C                  	mov	[di+ptSectors], ax
  8149 00002E32 89550E                  	mov	[di+ptSectors+2], dx
  8150                                  
  8151 00002E35 8B8E[5273]              	mov	cx, [bp+ldd_size]
  8152 00002E39 8B9E[5473]              	mov	bx, [bp+ldd_size+2]
  8153                                  	; cx:bx = volume size of logical -dos- drive
  8154                                  
  8155 00002E3D 8B86[4273]              	mov	ax, [bp+ldd_start]
  8156 00002E41 8B96[4473]              	mov	dx, [bp+ldd_start+2]
  8157                                  	; dx:ax = start sector address of ldd (EBR addr)
  8158                                  
  8159                                  	; 01/11/2020
  8160 00002E45 01C1                    	add	cx, ax
  8161 00002E47 11D3                    	adc	bx, dx
  8162 00002E49 83E901                  	sub	cx, 1
  8163 00002E4C 83DB00                  	sbb	bx, 0
  8164                                  	; bx:cx = end sector address of ldd
  8165 00002E4F 53                      	push	bx
  8166 00002E50 51                      	push	cx
  8167                                  ;eetc_4:
  8168                                  	; 01/11/2020
  8169                                  	; stack = end sector address of ldd
  8170                                  	; dx:ax = start sector address of ldd
  8171                                  
  8172                                  	; calculate CHS from LBA
  8173                                  
  8174 00002E51 E87601                  	call	lba_to_chs
  8175                                  		; ax = cylinder
  8176                                  		; dl = sector
  8177                                  		; dh = head
  8178                                  
  8179                                  	;mov	byte [di+ptBootable], 0
  8180 00002E54 887501                  	mov	[di+ptBeginHead], dh
  8181 00002E57 884503                  	mov	[di+ptBeginCylinder], al
  8182                                  	;mov	bl, ah
  8183                                  	;shl	bl, 6
  8184                                  	;or	dl, bl
  8185                                  	; 01/11/2020		
  8186 00002E5A C0E406                  	shl	ah, 6
  8187 00002E5D 08E2                    	or	dl, ah
  8188 00002E5F 885502                  	mov	[di+ptBeginSector], dl
  8189                                  
  8190                                  	;add	ax, [lcylinders]
  8191                                  	;dec	ax ; end cylinder
  8192                                  	;mov	bx, ax
  8193                                  
  8194                                  	; 01/11/2020
  8195 00002E62 58                      	pop	ax
  8196 00002E63 5A                      	pop	dx
  8197                                  	; dx:ax = end sector address of ldd
  8198                                  
  8199 00002E64 E86301                  	call	lba_to_chs
  8200                                  		; ax = cylinder
  8201                                  		; dl = sector
  8202                                  		; dh = head
  8203                                  
  8204                                  	;mov	[di+ptFileSystemID], 0
  8205                                  	;mov	cx, [heads]
  8206                                  	;dec	cl
  8207                                  	;mov	[di+ptEndHead], cl
  8208                                  	; 01/11/2020
  8209 00002E67 887505                  	mov	[di+ptEndHead], dh
  8210                                  
  8211 00002E6A 89C1                    	mov	cx, ax ; 01/11/2020
  8212                                  	
  8213                                  	; 02/11/2020
  8214                                  	; cx = ax = end cylinder of the ldd
  8215                                  	; [endcyl] = end cylinder of the ep
  8216                                  
  8217 00002E6C 884507                  	mov	[di+ptEndCylinder], al
  8218                                  	;mov	dx, [sectors]
  8219 00002E6F C0E406                  	shl	ah, 6
  8220 00002E72 08D4                    	or	ah, dl	
  8221 00002E74 886506                  	mov	[di+ptEndSector], ah
  8222                                  	
  8223                                  	; 02/03/2019
  8224                                  	; Check unused space if it is 3rd LDD
  8225                                  	; (write message to add unused space.)
  8226                                  
  8227                                  	; 02/11/2020
  8228                                  	;cmp	byte [ldrives], 3
  8229                                  	;jb	eetc_7
  8230                                  
  8231                                  	; 01/11/2020
  8232 00002E77 833E[6873]FF            	cmp	word [lcylinders], 65535  
  8233                                  			; sign for using all of available sectors	
  8234 00002E7C 0F83A900                	jnb	eetc_7	; no need to add unused sector 
  8235                                  			; (there are not any unused sectors)
  8236                                  
  8237                                  	; cx = cylinder number (0 to 1023)
  8238                                  
  8239                                  	; 02/11/2020
  8240 00002E80 803E[E46F]03            	cmp	byte [ldrives], 3 ; is this logical drive 4 ?
  8241 00002E85 730A                    	jnb	short eetc_15  
  8242                                  			; force to show unused space message
  8243                                  
  8244                                  	; 02/11/2020
  8245                                  	; (add unused space if cyl nums are same or diff is 1)
  8246 00002E87 41                      	inc	cx  ; tolerate cylinder numbers n and n-1 
  8247 00002E88 3B0E[6A73]              	cmp	cx, [endcyl] ; < end cylinder of the ep ?  
  8248 00002E8C 0F829900                	jb	eetc_7  ; the end cyl number of the last ldd
  8249                                  			; is 2 or more cyls less than
  8250                                  			; the end cyl number of the ep
  8251                                  			; (a next ldd can be added to
  8252                                  			; extd partition with 2 or more cyls)
  8253 00002E90 49                      	dec	cx 
  8254                                  		; cx = end cylinder of the ldd
  8255                                  eetc_15:
  8256                                  	; 02/11/2020
  8257 00002E91 A0[E46F]                	mov	al, [ldrives]
  8258 00002E94 0431                    	add	al, '1' ; 03/11/2020
  8259 00002E96 A2[D764]                	mov	[char_lddn], al
  8260                                  
  8261 00002E99 A0[A641]                	mov	al, [sectors]
  8262 00002E9C 88C7                    	mov	bh, al
  8263 00002E9E 8A1E[A841]              	mov	bl, [heads]
  8264 00002EA2 FECB                    	dec	bl
  8265 00002EA4 F6E3                    	mul	bl ; [sectors] * [heads] - 1
  8266                                  
  8267 00002EA6 50                      	push	ax
  8268                                  
  8269 00002EA7 88F8                    	mov	al, bh  ; [sectors]
  8270                                  	;mul	byte [heads]
  8271 00002EA9 FEC3                    	inc	bl
  8272 00002EAB F6E3                    	mul	bl
  8273                                  		; ax = heads * sectors
  8274 00002EAD F7E1                    	mul	cx ; * end cylinder
  8275                                  		; dx:ax = end cylinder * heads * sectors
  8276 00002EAF 59                      	pop	cx
  8277 00002EB0 01C8                    	add	ax, cx ; + (sectors * (heads - 1))
  8278 00002EB2 83D200                  	adc	dx, 0	
  8279                                  
  8280                                  	; 03/03/2019
  8281 00002EB5 8B0E[A641]              	mov	cx, [sectors]
  8282 00002EB9 FEC9                    	dec	cl  ; [sectors] - 1
  8283 00002EBB 01C8                    	add	ax, cx ; + (sectors - 1)
  8284 00002EBD 83D200                  	adc	dx, 0
  8285                                  		; DX:AX = end LBA
  8286                                  	
  8287 00002EC0 8B0E[F071]              	mov	cx, [ep_EndSector]
  8288 00002EC4 8B1E[F271]              	mov	bx, [ep_EndSector+2]
  8289                                  
  8290 00002EC8 39DA                      	cmp	dx, bx
  8291 00002ECA 7504                    	jne	short eetc_5
  8292 00002ECC 39C8                    	cmp	ax, cx
  8293 00002ECE 7459                    	je	short eetc_7 ; 05/03/2019
  8294                                  eetc_5:
  8295 00002ED0 53                      	push	bx
  8296 00002ED1 BE[9464]                	mov	si, msg_c_ldd_unused_warning
  8297 00002ED4 E8A8EF                  	call	print_msg
  8298 00002ED7 5B                      	pop	bx
  8299                                  eetc_6:
  8300 00002ED8 28E4                    	sub	ah, ah
  8301 00002EDA CD16                    	int	16h
  8302 00002EDC 3C0D                    	cmp	al, 13 ; ENTER
  8303 00002EDE 7449                    	je	short eetc_7 ; continue  ; 01/11/2020
  8304 00002EE0 3C1B                    	cmp	al, 27 ; ESC
  8305 00002EE2 75F4                    	jne	short eetc_6
  8306                                  
  8307                                  	; 03/03/2019
  8308                                  	; change end cylinder value
  8309 00002EE4 A0[A372]                	mov	al, [epnumber]
  8310 00002EE7 FEC8                    	dec	al
  8311 00002EE9 B412                    	mov	ah, 18	; primary partition table structure size
  8312 00002EEB F6E4                    	mul	ah
  8313 00002EED 89C6                    	mov	si, ax
  8314 00002EEF 8B84[6072]              	mov	ax, [si+part_table_end_cyl]
  8315 00002EF3 884507                  	mov	[di+ptEndCylinder], al
  8316 00002EF6 8A84[5F72]              	mov	al, [si+part_table_end_sector]
  8317 00002EFA C0E406                  	shl	ah, 6
  8318 00002EFD 08C4                    	or	ah, al	
  8319 00002EFF 886506                  	mov	[di+ptEndSector], ah
  8320 00002F02 8A84[5E72]              	mov	al, [si+part_table_end_head]
  8321 00002F06 884505                  	mov	[di+ptEndHead], al
  8322                                  
  8323 00002F09 89C8                    	mov	ax, cx
  8324 00002F0B 89DA                    	mov	dx, bx
  8325 00002F0D 83C001                  	add	ax, 1
  8326 00002F10 83D200                  	adc	dx, 0
  8327                                  		; dx:ax = end of extd partition + 1 
  8328                                  
  8329                                  	; 02/11/2020
  8330 00002F13 2B86[4273]              	sub	ax, [bp+ldd_start]
  8331 00002F17 1B96[4473]              	sbb	dx, [bp+ldd_start+2]
  8332 00002F1B 2B4508                  	sub	ax, [di+ptStartSector]
  8333 00002F1E 1B550A                  	sbb	dx, [di+ptStartSector+2]
  8334                                  		; dx:ax = new sector count of the ldd
  8335                                  
  8336 00002F21 89450C                  	mov	[di+ptSectors], ax
  8337 00002F24 89550E                  	mov	[di+ptSectors+2], dx
  8338 00002F27 EB06                    	jmp	short eetc_8
  8339                                  eetc_7:
  8340 00002F29 8B450C                  	mov	ax, [di+ptSectors]
  8341 00002F2C 8B550E                  	mov	dx, [di+ptSectors+2]
  8342                                  eetc_8:
  8343                                  	; Get proper FAT type in [ldd_type]
  8344                                  	; by using DX:AX - size -
  8345 00002F2F E8AD00                  	call	size_to_fat_type
  8346                                  
  8347 00002F32 884504                  	mov	[di+ptFileSystemID], al
  8348                                  
  8349                                  	; Write current EBR (with modified PT)
  8350 00002F35 8B86[4273]              	mov	ax, [bp+ldd_start]
  8351 00002F39 8B96[4473]              	mov	dx, [bp+ldd_start+2]
  8352 00002F3D BB[EA6F]                	mov	bx, ebr_buffer
  8353 00002F40 E84BEF                  	call	write_hd_sector
  8354 00002F43 0F8218EF                	jc	D_01 ; ! display error msg and then exit !
  8355                                  
  8356 00002F47 A0[E46F]                	mov	al, [ldrives]
  8357 00002F4A B412                    	mov	ah, 18 ; extended partition table structure size 	
  8358 00002F4C F6E4                    	mul	ah
  8359                                  
  8360 00002F4E 89C6                    	mov	si, ax
  8361 00002F50 81C6[A472]              	add	si, ext_table_boot_ind
  8362 00002F54 87F7                    	xchg	si, di
  8363                                  
  8364                                  	; set partition (logical -dos- drive) data
  8365 00002F56 A5                      	movsw	; boot indicator, beginning head
  8366 00002F57 AC                      	lodsb
  8367 00002F58 88C4                    	mov	ah, al
  8368 00002F5A 243F                    	and	al, 3Fh
  8369 00002F5C AA                      	stosb	; beginning sector
  8370 00002F5D C0EC06                  	shr	ah, 6
  8371 00002F60 AC                      	lodsb	; beginning cylinder
  8372 00002F61 AB                      	stosw	
  8373 00002F62 A5                      	movsw	; partition id, end head
  8374 00002F63 AC                      	lodsb
  8375 00002F64 88C4                    	mov	ah, al
  8376 00002F66 243F                    	and	al, 3Fh
  8377 00002F68 AA                      	stosb	; end sector
  8378 00002F69 C0EC06                  	shr	ah, 6
  8379 00002F6C AC                      	lodsb	; end cylinder
  8380 00002F6D AB                      	stosw
  8381                                  
  8382 00002F6E A5                      	movsw	; copy start sector (LBA) and sector count
  8383 00002F6F A5                      	movsw
  8384 00002F70 A5                      	movsw
  8385 00002F71 A5                      	movsw
  8386                                  
  8387 00002F72 FE06[E46F]              	inc	byte [ldrives]
  8388                                  
  8389                                  	; Close hard disk image file
  8390                                  
  8391 00002F76 B43E                    	mov	ah, 3Eh ; close file
  8392 00002F78 8B1E[A441]              	mov	bx, [img_file_handle]
  8393 00002F7C CD21                    	int	21h
  8394                                  
  8395 00002F7E C706[A441]0000          	mov	word [img_file_handle], 0
  8396                                  	
  8397 00002F84 E97DFC                  	jmp	display_extended_pt
  8398                                  
  8399                                  ;-----------------------------------------------------------------------------
  8400                                  ; 05/03/2019
  8401                                  
  8402                                  check_ext_free_space:
  8403 00002F87 A1[F471]                	mov	ax, [ep_Size]
  8404 00002F8A 8B16[F671]              	mov	dx, [ep_Size+2]
  8405                                  
  8406 00002F8E 8A1E[E46F]              	mov	bl, [ldrives]
  8407 00002F92 20DB                    	and	bl, bl
  8408 00002F94 7433                    	jz	short cefs_1
  8409 00002F96 80FB04                  	cmp	bl, 4
  8410 00002F99 7602                    	jna	short cefs_0
  8411 00002F9B B304                    	mov	bl, 4
  8412                                  cefs_0:
  8413 00002F9D FECB                    	dec	bl	
  8414 00002F9F C0E302                  	shl	bl, 2 ; *4
  8415 00002FA2 30FF                    	xor	bh, bh
  8416 00002FA4 89DE                    	mov	si, bx
  8417                                  
  8418 00002FA6 8B8C[4273]              	mov	cx, [si+ldd_start]
  8419 00002FAA 8B9C[4473]              	mov	bx, [si+ldd_start+2]
  8420 00002FAE 038C[5273]              	add	cx, [si+ldd_size]
  8421 00002FB2 139C[5473]              	adc	bx, [si+ldd_size+2]
  8422                                  
  8423 00002FB6 0306[EC71]              	add	ax, [ep_StartSector]
  8424 00002FBA 1316[EE71]              	adc	dx, [ep_StartSector+2]
  8425                                  
  8426 00002FBE 29C8                    	sub	ax, cx
  8427 00002FC0 19DA                    	sbb	dx, bx
  8428 00002FC2 7505                    	jnz	short cefs_1
  8429                                  	
  8430 00002FC4 09C0                    	or	ax, ax
  8431 00002FC6 7501                    	jnz	short cefs_1
  8432                                  
  8433                                  	; cf = 0 if the result not negative
  8434                                  
  8435 00002FC8 F9                      	stc	
  8436                                  
  8437                                  	; cf = 1 if the result is negative or zero
  8438                                  	 
  8439                                  	; If cf = 0 -> There is free space as in DX:AX
  8440                                  	; NOTE: This calculation is unsafe if
  8441                                  	; logical dos drive count > 4 !	
  8442                                  	; (But still meaningful for creating a new ldd.
  8443                                  	;  Because a new ldd will be created only
  8444                                  	;  if ldd count < 4.)
  8445                                  cefs_1:
  8446 00002FC9 C3                      	retn
  8447                                  
  8448                                  ;-----------------------------------------------------------------------------
  8449                                  ; 01/03/2019
  8450                                  
  8451                                  lba_to_chs:
  8452                                  	; INPUT:
  8453                                  	;	DX:AX = LBA address
  8454                                  	; OUTPUT:
  8455                                  	;	AX = cylinder
  8456                                  	;	DL = sector
  8457                                  	;	DH = head
  8458                                  	;
  8459                                  	; (modified registers: ax, bx, cx, dx)
  8460                                  
  8461 00002FCA 8B0E[A641]              	mov	cx, [sectors]
  8462 00002FCE E8A1DE                  	call	div32
  8463 00002FD1 FEC3                    	inc	bl
  8464 00002FD3 53                      	push	bx ; BL = sector
  8465 00002FD4 8B0E[A841]              	mov	cx, [heads]
  8466 00002FD8 E897DE                  	call	div32
  8467 00002FDB 5A                      	pop	dx  ; DL = sector	
  8468 00002FDC 88DE                    	mov	dh, bl ; BL = head
  8469 00002FDE C3                      	retn
  8470                                  
  8471                                  ;-----------------------------------------------------------------------------
  8472                                  ; 02/03/2019
  8473                                  
  8474                                  size_to_fat_type:
  8475                                  	; INPUT:
  8476                                  	;	DX:AX = DOS Partitition Size in sectors
  8477                                  	; OUTPUT:
  8478                                  	;	AL = Partition type/ID (FAT type)
  8479                                  
  8480 00002FDF 09D2                    	or	dx, dx
  8481 00002FE1 750B                    	jnz	short stft_2
  8482                                  
  8483 00002FE3 3DA87F                  	cmp	ax, 32680
  8484 00002FE6 7703                    	ja	short stft_1	
  8485                                  	
  8486 00002FE8 B001                    	mov	al, 1	; FAT12 file system
  8487 00002FEA C3                      	retn
  8488                                  stft_1:
  8489 00002FEB B004                    	mov	al, 4	; FAT16 (< 32MB)
  8490 00002FED C3                      	retn	
  8491                                  stft_2:
  8492 00002FEE 83FA10                  	cmp	dx, 10h
  8493 00002FF1 7303                    	jnb	short stft_3 ; FAT32 (CHS) file system	
  8494                                  
  8495 00002FF3 B006                    	mov	al, 6	; FAT16 (>= 32MB)
  8496 00002FF5 C3                      	retn
  8497                                  stft_3:
  8498 00002FF6 B00B                    	mov	al, 0Bh ; FAT32 (CHS)
  8499 00002FF8 C3                      	retn
  8500                                  
  8501                                  ;-----------------------------------------------------------------------------
  8502                                  ; 02/03/2019
  8503                                  
  8504                                  get_ldd_size:	; Get requested logical dos drive size (from user)
  8505                                  	; INPUT -> none
  8506                                  	;
  8507                                  	; OUTPUT -> 
  8508                                  	;	[lcylinders] = cylinder count
  8509                                  	;
  8510                                  	; (Modified registers: ax, bx, cx, dx, si, di) 
  8511                                  
  8512 00002FF9 B80300                  	mov	ax, 3 ; clear screen
  8513 00002FFC CD10                    	int	10h
  8514                                  
  8515 00002FFE BE[054A]                	mov	si, msg_create_dos_partition_h
  8516 00003001 E87BEE                  	call	print_msg
  8517                                  
  8518                                  	; 03/03/2019
  8519 00003004 A0[E46F]                	mov	al, [ldrives]
  8520 00003007 08C0                    	or	al, al		; cmp byte [ldrives], 0
  8521 00003009 7405                    	jz	short gldds_1	; jna short gldds_0
  8522                                  
  8523                                  	;push	ax ; *	
  8524                                  
  8525                                  	;dec	al
  8526                                  	;mov	ah, 18
  8527                                  	;mul	ah
  8528                                  	
  8529                                  	;mov	di, ext_table_rel_sec_lw
  8530                                  	;add	di, ax
  8531                                  
  8532 0000300B BE[1950]                	mov	si, msg_use_all_space
  8533                                  	; 01/11/2020
  8534                                  	;call	print_msg
  8535 0000300E EB03                    	jmp	short gldds_2
  8536                                  
  8537                                  	; Calculate available space
  8538                                  
  8539                                  	;mov	ax, [ep_Size] ; ext part size in sectors
  8540                                  	;mov	dx, [ep_Size+2]
  8541                                  	
  8542                                  	; 04/03/2019
  8543                                  ;gldds_0:
  8544                                  	;mov	cx, [di]    ; start sector			
  8545                                  	;mov	bx, [di+2]
  8546                                  	;add	cx, [di+4]  ; sectors
  8547                                  	;adc	bx, [di+6]
  8548                                  	;	; bx:cx = start of next ldd
  8549                                  	;sub	ax, cx
  8550                                  	;sbb	dx, bx
  8551                                  	;	; dx:ax = free space in sectors
  8552                                  	;
  8553                                  	;pop	cx ; *
  8554                                  	;dec	cl
  8555                                  	;jz	short gldds_2
  8556                                  	;sub	di, 18
  8557                                  	;push	cx ; *
  8558                                  	;jmp	short gldds_0
  8559                                  
  8560                                  	; 05/03/2019
  8561                                  	;call	check_ext_free_space
  8562                                  	;jc	short gldds_cancel
  8563                                  	
  8564                                  	; 01/11/2020
  8565                                  	; 30/10/2020
  8566                                  	;mov	ax, [ep_free_sectors]
  8567                                  	;mov	dx, [ep_free_sectors+2]
  8568                                  	
  8569                                  		; DX:AX = free sectors in extended partition
  8570                                  	;jmp	short gldds_2
  8571                                  gldds_1:
  8572 00003010 BE[4C50]                	mov	si, msg_use_entire_ep_space
  8573                                  	;call	print_msg
  8574                                  	
  8575                                  	; 01/11/2020
  8576                                  	; Calculate free space in extended partition
  8577                                  	;mov	ax, [ep_Size]
  8578                                  	;mov	dx, [ep_Size+2]
  8579                                  gldds_2:
  8580                                  	; 01/11/2020
  8581 00003013 E869EE                  	call	print_msg
  8582                                  
  8583 00003016 A0[A841]                	mov	al, [heads]
  8584 00003019 F626[A641]              	mul	byte [sectors]
  8585 0000301D 89C1                    	mov	cx, ax
  8586                                  		
  8587 0000301F A1[6273]                	mov	ax, [ep_free_sectors]
  8588 00003022 8B16[6473]              	mov	dx, [ep_free_sectors+2]
  8589                                  
  8590                                  	; 01/11/2020
  8591                                  	; this is needed for partition size input
  8592                                  	; (maximum available sectors)
  8593                                  	;mov	[pp_Sectors], ax
  8594                                  	;mov	[pp_Sectors+2], dx
  8595                                  
  8596                                  	; 01/11/2020
  8597                                  	; subtrack start offset (which always equals to spt value)
  8598                                  	;sub	ax, [sectors]
  8599                                  	;sbb	dx, 0
  8600                                  
  8601                                  	;mov	cx, ax
  8602                                  	;mov	al, [heads]
  8603                                  	;mul	byte [sectors]
  8604                                  	;xchg	ax, cx
  8605                                  		; dx:ax = sectors
  8606                                  		; cx = heads*spt 
  8607                                  	;call	div32
  8608                                  		; ax = cylinders
  8609                                  		; bx = remainder
  8610                                   		; dx = 0
  8611                                  	;and	bx, bx
  8612                                  	;jz	short gldds_3
  8613                                  	;inc	ax
  8614                                  	; 01/11/2020
  8615 00003026 F7F1                    	div	cx
  8616                                  	;and	dx, dx
  8617                                  	;jz	short gldds_3
  8618                                  	;inc	ax
  8619                                  gldds_3:
  8620 00003028 A3[6873]                	mov	[lcylinders], ax ; <= 65535 (< 65535)
  8621                                  gldds_getchar:
  8622 0000302B 30E4                    	xor	ah, ah
  8623 0000302D CD16                    	int	16h
  8624                                  
  8625 0000302F 3C1B                    	cmp	al, 27 ; ESCAPE key
  8626 00003031 7416                    	je	short gldds_cancel
  8627 00003033 24DF                    	and	al, 0DFh
  8628 00003035 3C4E                    	cmp	al, 'N'
  8629 00003037 7417                    	je	short gldds_4
  8630 00003039 3C59                    	cmp	al, 'Y'
  8631 0000303B 75EE                    	jne	short gldds_getchar
  8632                                  
  8633                                  	; 01/11/2020
  8634 0000303D C706[6873]FFFF          	mov	word [lcylinders], 65535 ; sign for all free sectors
  8635                                  	
  8636 00003043 BE[025F]                	mov	si, _msg_YES
  8637                                  	;call	print_msg
  8638                                  	;retn
  8639 00003046 E936EE                  	jmp	print_msg
  8640                                  
  8641                                  gldds_cancel:
  8642 00003049 C706[6873]0000          	mov	word [lcylinders], 0
  8643                                  gldds_28:
  8644 0000304F C3                      	retn
  8645                                  gldds_4:	
  8646 00003050 BE[085F]                	mov	si, _msg_NO
  8647 00003053 E829EE                  	call	print_msg
  8648                                  gldds_26:
  8649 00003056 B80300                  	mov	ax, 3 ; clear screen
  8650 00003059 CD10                    	int	10h
  8651                                  
  8652 0000305B BE[054A]                	mov	si, msg_create_dos_partition_h
  8653 0000305E E81EEE                  	call	print_msg
  8654                                  
  8655 00003061 BE[1A65]                	mov	si, msg_create_ldd_s
  8656 00003064 E818EE                  	call	print_msg
  8657 00003067 BE[D74F]                	mov	si, msg_press_esc_to_cancel
  8658 0000306A E812EE                  	call	print_msg
  8659                                  gldds_25:
  8660 0000306D 30E4                    	xor	ah, ah
  8661 0000306F CD16                    	int	16h
  8662                                  
  8663 00003071 3C1B                    	cmp	al, 27 ; ESCAPE key
  8664 00003073 7502                    	jne	short gldds_5
  8665                                  
  8666 00003075 EBD2                    	jmp	short gldds_cancel
  8667                                  gldds_5:
  8668                                  	; 04/03/2019
  8669 00003077 3C20                    	cmp	al, 32 ; SPACE key
  8670 00003079 74D4                    	je	short gldds_28
  8671                                  	
  8672                                  	; 01/11/2020
  8673                                  	;mov	byte [pSize_unit], '%'
  8674 0000307B 3C25                    	cmp	al, '%'
  8675 0000307D 7416                    	je	short gldds_6
  8676                                  	;mov	byte [pSize_unit], 'M'
  8677 0000307F 3C0D                    	cmp	al, 13 ; 0Dh, Carriage Return key
  8678                                  	;je	short gldds_6
  8679 00003081 7504                    	jne	short gldds_29
  8680                                  	; 01/11/2020
  8681 00003083 B04D                    	mov	al, 'M'
  8682 00003085 EB0E                    	jmp	short gldds_6
  8683                                  gldds_29:
  8684 00003087 24DF                    	and	al, 0DFh
  8685 00003089 3C4D                    	cmp	al, 'M'
  8686 0000308B 7408                    	je	short gldds_6
  8687                                  	;mov	[pSize_unit], al
  8688 0000308D 3C47                    	cmp	al, 'G'
  8689 0000308F 7404                    	je	short gldds_6
  8690 00003091 3C43                    	cmp	al, 'C'
  8691 00003093 75D8                    	jne	short gldds_25
  8692                                  gldds_6:
  8693                                  	; 01/11/2020
  8694 00003095 A2[BE6F]                	mov	[pSize_unit], al
  8695                                  
  8696                                  	; Set maximum sector count (all of extended partition)
  8697                                  	;mov	al, [sectors]
  8698                                  	;mul	byte [heads]
  8699                                  	;mul	word [lcylinders]
  8700                                  	; 01/11/2020	
  8701 00003098 A1[6273]                	mov	ax, [ep_free_sectors]
  8702 0000309B 8B16[6473]              	mov	dx, [ep_free_sectors+2]
  8703 0000309F A3[AC6F]                	mov	[pp_Sectors], ax
  8704 000030A2 8916[AE6F]              	mov	[pp_Sectors+2], dx
  8705                                  	
  8706 000030A6 E81DF0                   	call	partition_size_input
  8707 000030A9 729E                    	jc	short gldds_cancel
  8708                                  		; DX:AX = Partition size in sectors
  8709                                  	;or	bx, bx
  8710                                  	;jnz	short gldds_cancel
  8711                                  
  8712                                  	; 01/11/2020
  8713 000030AB A3[DC6F]                	mov	[ppn_Sectors], ax
  8714 000030AE 8916[DE6F]              	mov	[ppn_Sectors+2], dx
  8715                                  		
  8716 000030B2 89C1                    	mov	cx, ax
  8717 000030B4 A0[A841]                	mov	al, [heads]
  8718 000030B7 F626[A641]              	mul	byte [sectors]
  8719 000030BB 91                      	xchg	ax, cx
  8720                                  		; dx:ax = sectors
  8721                                  		; cx = heads*spt 
  8722                                  	;call	div32
  8723                                  		; ax = cylinders
  8724                                  		; bx = remainder
  8725                                   		; dx = 0
  8726                                  	;and	bx, bx
  8727                                  	;jz	short gldds_7
  8728                                  	;inc	ax
  8729                                  	; 01/11/2020
  8730 000030BC F7F1                    	div	cx
  8731                                  	;and	dx, dx
  8732                                  	;jz	short gldds_7
  8733                                  	;inc	ax
  8734                                  gldds_7:
  8735 000030BE 3B06[6873]              	cmp	ax, [lcylinders]
  8736 000030C2 7704                    	ja	short gldds_9
  8737                                  gldds_8:
  8738                                  	; OK
  8739 000030C4 A3[6873]                	mov	[lcylinders], ax
  8740 000030C7 C3                      	retn
  8741                                  
  8742                                  gldds_9:
  8743                                  	; Partition size limit message
  8744                                  	
  8745 000030C8 803E[BE6F]43            	cmp	byte [pSize_unit], 'C'
  8746 000030CD 741C                    	je	short gldds_10
  8747                                  
  8748                                  	; Tolerate 1 cylinder if unit is not cylinder
  8749                                  	;dec	ax
  8750                                  	;cmp	ax, [lcylinders]
  8751                                  	;jna	short gldds_8
  8752                                  
  8753                                  	; 01/11/2020
  8754                                  	; Tolerate sectors if sectorcount doesn't over ep limit
  8755 000030CF A1[DC6F]                	mov	ax, [ppn_Sectors]
  8756 000030D2 8B16[DE6F]              	mov	dx, [ppn_Sectors+2]
  8757 000030D6 3B16[6473]              	cmp	dx, [ep_free_sectors+2]
  8758 000030DA 770F                    	ja	short gldds_10
  8759 000030DC 7206                    	jb	short gldds_30
  8760 000030DE 3B06[6273]              	cmp	ax, [ep_free_sectors]
  8761 000030E2 7707                    	ja	short gldds_10
  8762                                  gldds_30:
  8763 000030E4 C706[6873]FFFF          	mov	word [lcylinders], 65535 ; sign for all free sectors
  8764 000030EA C3                      	retn
  8765                                  
  8766                                  gldds_10:
  8767                                  	; clear screen
  8768 000030EB B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
  8769 000030EE CD10                    	int	10h
  8770                                  
  8771 000030F0 BE[054A]                	mov	si, msg_create_dos_partition_h ; header
  8772 000030F3 E889ED                  	call	print_msg
  8773                                  
  8774 000030F6 BE[C760]                	mov	si, msg_partition_size_limit
  8775 000030F9 E883ED                  	call	print_msg
  8776                                  
  8777 000030FC 803E[BE6F]4D            	cmp	byte [pSize_unit], 'M'
  8778 00003101 7413                    	je	short gldds_11
  8779                                  
  8780 00003103 803E[BE6F]25            	cmp	byte [pSize_unit], '%'
  8781 00003108 745A                    	je	short gldds_22
  8782                                  
  8783 0000310A 803E[BE6F]43            	cmp	byte [pSize_unit], 'C'
  8784 0000310F 7505                    	jne	short gldds_11
  8785                                  
  8786 00003111 A1[6873]                	mov	ax, [lcylinders]
  8787 00003114 EB0F                    	jmp	short gldds_12
  8788                                  gldds_11:
  8789                                  	; 'M'
  8790 00003116 A1[AC6F]                	mov	ax, [pp_Sectors]
  8791 00003119 8B16[AE6F]              	mov	dx, [pp_Sectors+2]
  8792 0000311D B90008                  	mov	cx, 2*1024 ; sectors -> MB
  8793 00003120 E84FDD                  	call	div32
  8794                                  		; DX = 0 
  8795                                  		; AX = Available space in Megabytes
  8796 00003123 89C7                    	mov	di, ax		
  8797                                  gldds_12:	
  8798 00003125 B90A00                  	mov	cx, 10
  8799 00003128 89E5                    	mov	bp, sp
  8800                                  gldds_13:
  8801 0000312A 31D2                    	xor	dx, dx
  8802 0000312C B90A00                  	mov	cx, 10
  8803 0000312F F7F1                    	div	cx
  8804 00003131 52                      	push	dx
  8805 00003132 83F809                  	cmp	ax, 9
  8806 00003135 77F3                    	ja	short gldds_13
  8807                                  gldds_14:
  8808 00003137 BB0700                  	mov	bx, 07h
  8809 0000313A 09C0                    	or	ax, ax
  8810 0000313C 7501                    	jnz	short gldds_16
  8811                                  gldds_15:
  8812 0000313E 58                      	pop	ax
  8813                                  gldds_16:
  8814 0000313F 0430                    	add	al, '0'
  8815                                  gldds_17:
  8816 00003141 B40E                    	mov	ah, 0Eh
  8817                                  	;mov	bx, 07h
  8818 00003143 CD10                    	int	10h	; write character (as tty)
  8819                                  
  8820 00003145 39EC                    	cmp	sp, bp			
  8821 00003147 72F5                    	jb	short gldds_15
  8822                                  
  8823 00003149 803E[BE6F]25            	cmp	byte [pSize_unit], '%'
  8824 0000314E 7508                    	jne	short gldds_18
  8825                                  
  8826 00003150 3C25                    	cmp	al, '%'
  8827 00003152 746D                    	je	short gldds_21
  8828 00003154 B025                    	mov	al, '%'
  8829 00003156 EBE9                    	jmp	short gldds_17
  8830                                  gldds_18:
  8831 00003158 803E[BE6F]43            	cmp	byte [pSize_unit], 'C'
  8832 0000315D 754D                    	jne	short gldds_19
  8833                                  
  8834 0000315F BE[6361]                	mov	si, msg_cylinders
  8835 00003162 EB5A                    	jmp	short gldds_20
  8836                                  
  8837                                  gldds_22:
  8838                                  	; '%'
  8839                                  	; 01/11/2020
  8840 00003164 8B16[F671]              	mov	dx, [ep_Size+2]
  8841 00003168 A1[F471]                	mov	ax, [ep_Size] ; *
  8842 0000316B 21D2                    	and	dx, dx
  8843 0000316D 7419                    	jz	short gldds_33 ; dx = 0
  8844 0000316F B90100                  	mov	cx, 1
  8845                                  gldds_31:
  8846 00003172 D1E1                    	shl	cx, 1
  8847 00003174 E8FBDC                  	call	div32
  8848 00003177 09D2                    	or	dx, dx
  8849 00003179 7409                    	jz	short gldds_32 ; *
  8850 0000317B A1[F471]                	mov	ax, [ep_Size]	
  8851 0000317E 8B16[F671]              	mov	dx, [ep_Size+2]
  8852 00003182 EBEE                    	jmp	short gldds_31
  8853                                  gldds_32:
  8854 00003184 8B16[6473]              	mov	dx, [ep_free_sectors+2]
  8855                                  	; ep free secors <= ep size
  8856                                  gldds_33:
  8857 00003188 50                      	push	ax ; * ; dx = 0 (ep size weight)
  8858 00003189 A1[6273]                	mov	ax, [ep_free_sectors]
  8859 0000318C B96400                  	mov	cx, 100
  8860                                  	;and	dx, dx
  8861                                  	;jnz	short gldds_34
  8862                                  	;mul	cx
  8863                                  	;jmp	short gldds_35
  8864                                  ;gldds_34:
  8865 0000318F E8EEDC                  	call	mul32
  8866                                  		; dx:ax = 100 * ep free sectors weight
  8867                                  ;gldds_35:
  8868 00003192 59                      	pop	cx ; *
  8869 00003193 E8DCDC                  	call	div32 ; 100 * ep free sectors / ep size
  8870                                  		; ax = % value (<= 100)
  8871 00003196 09C0                    	or	ax, ax
  8872 00003198 7501                    	jnz	short gldds_23
  8873 0000319A 40                      	inc	ax ; 0 -> 1
  8874                                  
  8875                                  gldds_23:	
  8876 0000319B 89E5                    	mov	bp, sp
  8877                                  gldds_24:	
  8878 0000319D 31D2                    	xor	dx, dx
  8879 0000319F B90A00                  	mov	cx, 10
  8880 000031A2 F7F1                    	div	cx
  8881 000031A4 52                      	push	dx
  8882 000031A5 83F809                  	cmp	ax, 9
  8883 000031A8 77F3                    	ja	short gldds_24
  8884 000031AA EB8B                    	jmp	short gldds_14
  8885                                  
  8886                                  gldds_19:
  8887 000031AC BE[7761]                	mov	si, msg_megabytes
  8888 000031AF C606[8061]73            	mov	byte [msg_megabytes_s], 's'
  8889 000031B4 83FF01                  	cmp	di, 1
  8890 000031B7 7705                    	ja	short gldds_20
  8891 000031B9 C606[8061]00            	mov	byte [msg_megabytes_s], 0	
  8892                                  gldds_20:
  8893 000031BE E8BEEC                  	call	print_msg
  8894                                  gldds_21:
  8895 000031C1 BE[1461]                	mov	si, msg_partition_size_limit_r
  8896 000031C4 E8B8EC                  	call	print_msg
  8897                                  gldds_27:
  8898 000031C7 30E4                    	xor	ah, ah
  8899 000031C9 CD16                    	int	16h
  8900                                  	
  8901 000031CB 3C1B                    	cmp	al, 27 ; ESCAPE key
  8902 000031CD 0F8485FE                	je	gldds_26
  8903 000031D1 3C0D                    	cmp	al, 13 ; ENTER (Carriage Return) key
  8904 000031D3 75F2                    	jne	short gldds_27
  8905                                  
  8906                                  	;mov	ax, [lcylinders]
  8907 000031D5 C3                      	retn
  8908                                  	
  8909                                  ;-----------------------------------------------------------------------------
  8910                                  ; 26/02/2019
  8911                                  
  8912                                  init_ext_partition_tables:
  8913                                  
  8914                                  	; INPUT -> 
  8915                                  	;	[epnumber] = extended partition number
  8916                                  	;
  8917                                  	; OUTPUT -> none
  8918                                  
  8919                                  ; Display Method: ; 04/03/2019
  8920                                  ;LDD 1 <- LDD_START0, ebr 1st entry <- MBR (extended partition) - EBR 0
  8921                                  ;LDD 2 <- LDD_START1, ebr 1st entry <- EBR 1
  8922                                  ;LDD 3 <- LDD_START2, ebr 1st entry <- EBR 2
  8923                                  ;LDD 4 <- LDD_START3, ebr 1st entry <- EBR 3
  8924                                  ;LDD 5 <- LDD_START3, ebr 2nd entry (LDD 5 is not diplayed)
  8925                                  
  8926                                  	; 08/03/2019
  8927                                  
  8928                                  	; clear extended partition tables structure/list
  8929                                  
  8930 000031D6 BF[A472]                	mov	di, ext_table_boot_ind
  8931 000031D9 89FE                    	mov	si, di ; 28/02/2019
  8932 000031DB B92400                  	mov	cx, 36 ; 18*4 = 72 bytes
  8933 000031DE 31C0                    	xor	ax, ax ; 0
  8934 000031E0 F3AB                    	rep	stosw
  8935 000031E2 89F7                    	mov	di, si ; 28/02/2019	
  8936                                  
  8937                                  	;mov	byte [ldrives], 0
  8938 000031E4 A2[E46F]                	mov	[ldrives], al ; 0
  8939                                  
  8940                                  	;cmp	byte [epnumber], 1
  8941                                  	;jb	short iept_0
  8942                                  
  8943 000031E7 A0[A372]                	mov	al, [epnumber]
  8944 000031EA FEC8                    	dec	al
  8945 000031EC B412                    	mov	ah, 18  ; partition table structure size 
  8946 000031EE F6E4                    	mul	ah
  8947 000031F0 BE[6272]                	mov	si, part_table_rel_sec_lw
  8948 000031F3 01C6                    	add	si, ax
  8949                                  	; 02/11/2020
  8950                                  	;(save end cylinder for comparising later)
  8951 000031F5 8B44FE                  	mov	ax, [si-2] ; part_table_end_cyl 
  8952                                  			; 16 bit cylinder number
  8953 000031F8 A3[6A73]                	mov	[endcyl], ax
  8954                                  	;
  8955 000031FB 8B04                    	mov	ax, [si]
  8956 000031FD 8B5402                  	mov	dx, [si+2]
  8957 00003200 A3[EC71]                	mov	[ep_StartSector], ax
  8958 00003203 8916[EE71]              	mov	[ep_StartSector+2], dx
  8959 00003207 8B4C04                  	mov	cx, [si+4]
  8960 0000320A 8B5C06                  	mov	bx, [si+6]
  8961 0000320D 890E[F471]              	mov	[ep_Size], cx
  8962 00003211 891E[F671]              	mov	[ep_Size+2], bx
  8963 00003215 83E901                  	sub	cx, 1
  8964 00003218 83DB00                  	sbb	bx, 0
  8965 0000321B 01C1                    	add	cx, ax
  8966 0000321D 11D3                    	adc	bx, dx 
  8967 0000321F 890E[F071]              	mov	[ep_EndSector], cx
  8968 00003223 891E[F271]              	mov	[ep_EndSector+2], bx
  8969                                  
  8970                                  	; 27/02/2019
  8971 00003227 A3[4273]                	mov	[ldd_start], ax
  8972 0000322A 8916[4473]              	mov	[ldd_start+2], dx
  8973                                  
  8974                                  	; 03/03/2019
  8975                                  	;mov	word [ldd_size], 0
  8976                                  	;mov	word [ldd_size+2], 0
  8977                                  	
  8978 0000322E BB[EA6F]                	mov	bx, ebr_buffer
  8979                                  	; dx:ax = Extended partition address
  8980                                  	; es:bx = Extended partition buffer 
  8981 00003231 E899EC                  	call	read_hd_sector
  8982 00003234 7209                    	jc	short iept_0
  8983                                  
  8984                                  	; Check EBR if it is a valid boot record or not
  8985 00003236 813E[E871]55AA          	cmp	word [ebr_buffer+510], 0AA55h
  8986 0000323C 7402                    	je	short iept_1
  8987                                  iept_stc_retn:
  8988 0000323E F9                      	stc
  8989                                  iept_0:
  8990 0000323F C3                      	retn
  8991                                  iept_1:
  8992                                  	; Check PTE 1, if it is valid or not
  8993 00003240 A0[AC71]                	mov	al, [ebr_buffer+446+ptFileSystemID]
  8994 00003243 20C0                    	and	al, al
  8995 00003245 74F7                    	jz	short iept_stc_retn ; empty pte, error
  8996 00003247 3C05                    	cmp	al, 5
  8997 00003249 74F3                    	je	short iept_stc_retn ; extended partition, error
  8998                                  
  8999                                  	;inc	byte [ldrives] ; logical (dos) drive count
  9000                                  
  9001 0000324B BE[A871]                	mov	si, ebr_buffer+446 ; Partition table offset
  9002 0000324E B90400                  	mov	cx, 4
  9003                                  
  9004                                  	; set partition (logical -dos- drive) data
  9005 00003251 A5                      	movsw	; boot indicator, beginning head
  9006 00003252 AC                      	lodsb
  9007 00003253 88C4                    	mov	ah, al
  9008 00003255 243F                    	and	al, 3Fh
  9009 00003257 AA                      	stosb	; beginning sector
  9010 00003258 C0EC06                  	shr	ah, 6
  9011 0000325B AC                      	lodsb	; beginning cylinder
  9012 0000325C AB                      	stosw	
  9013 0000325D A5                      	movsw	; partition id, end head
  9014 0000325E AC                      	lodsb
  9015 0000325F 88C4                    	mov	ah, al
  9016 00003261 243F                    	and	al, 3Fh
  9017 00003263 AA                      	stosb	; end sector
  9018 00003264 C0EC06                  	shr	ah, 6
  9019 00003267 AC                      	lodsb	; end cylinder
  9020 00003268 AB                      	stosw
  9021                                  
  9022                                  	; 04/03/2019
  9023 00003269 8A1E[E46F]              	mov	bl, [ldrives]
  9024                                  	;dec 	bl
  9025                                  	;jnz	short iept_2
  9026                                  
  9027                                  	; 05/03/2019
  9028 0000326D 08DB                    	or	bl, bl 
  9029 0000326F 7518                    	jnz	short iept_2
  9030                                  
  9031 00003271 8B04                    	mov	ax, [si]   ; start sector of 1st LDD (offset)	
  9032 00003273 8B5402                  	mov	dx, [si+2]
  9033 00003276 034404                  	add	ax, [si+4] ; size of 1st LDD (volume)
  9034 00003279 135406                  	adc	dx, [si+6]
  9035                                  
  9036 0000327C A3[5273]                	mov	[ldd_size], ax ; size of 1st LDD (partition)
  9037 0000327F 8916[5473]              	mov	[ldd_size+2], dx
  9038                                  	; 05/03/2019
  9039 00003283 FE06[E46F]              	inc	byte [ldrives] ; logical (dos) drive count
  9040 00003287 FEC3                    	inc	bl
  9041                                  iept_2:
  9042 00003289 F3A5                    	rep	movsw ; copy start sector (LBA) and sector count
  9043                                  
  9044                                  	; get next extended partition (logical -dos- drive) data 
  9045 0000328B 8A4404                  	mov	al, [si+ptFileSystemID]
  9046 0000328E 20C0                    	and	al, al ; EMPTY
  9047 00003290 74AD                    	jz	short iept_0 ; end of logical -dos- drive chain	
  9048                                  
  9049 00003292 3C05                    	cmp	al, 5 ; EXTENDED
  9050 00003294 75A8                    	jne	short iept_stc_retn  ; 2nd PTE must have
  9051                                  				     ; extended partition ID
  9052                                  
  9053                                  	; 05/03/2019
  9054 00003296 FE06[E46F]              	inc	byte [ldrives] ; logical (dos) drive count
  9055                                  
  9056                                  	;cmp	byte [ldrives], al ; 5
  9057 0000329A 80FB04                  	cmp	bl, 4 ; number of logical dos drives (till here)
  9058 0000329D 733D                    	jnb	short iept_3
  9059                                  
  9060 0000329F 83C608                  	add	si, 8
  9061                                  
  9062 000032A2 AD                      	lodsw	
  9063 000032A3 89C2                    	mov	dx, ax	; start sector
  9064 000032A5 AD                      	lodsw
  9065 000032A6 92                      	xchg	dx, ax	; start sector + 2
  9066                                  
  9067                                  	; 04/03/2019
  9068 000032A7 0306[EC71]              	add	ax, [ep_StartSector]
  9069 000032AB 1316[EE71]              	adc	dx, [ep_StartSector+2]
  9070                                  	
  9071 000032AF 30FF                    	xor	bh, bh
  9072 000032B1 C0E302                  	shl	bl, 2 ; *4
  9073                                  
  9074                                  	; 28/02/2019
  9075 000032B4 8987[4273]              	mov	[bx+ldd_start], ax ; start of (next) LDD (partition)
  9076 000032B8 8997[4473]              	mov	[bx+ldd_start+2], dx
  9077                                  
  9078                                  	; 03/03/2019
  9079                                  	; set partition size for logical dos drive
  9080 000032BC 8B0C                    	mov	cx, [si]
  9081 000032BE 898F[5273]              	mov	[bx+ldd_size], cx
  9082 000032C2 8B4C02                  	mov	cx, [si+2]
  9083 000032C5 898F[5473]              	mov	[bx+ldd_size+2], cx
  9084                                  
  9085 000032C9 BB[EA6F]                	mov	bx, ebr_buffer
  9086                                  	; dx:ax = Extended partition address
  9087                                  	; es:bx = Extended partition buffer 
  9088 000032CC E8FEEB                  	call	read_hd_sector
  9089 000032CF 720B                    	jc	short iept_3 ; 03/03/2019
  9090                                  
  9091                                  	; Check EBR if it is valid or not
  9092 000032D1 813E[E871]55AA          	cmp	word [ebr_buffer+510], 0AA55h
  9093 000032D7 0F8465FF                	je	iept_1
  9094                                  
  9095 000032DB F9                      	stc
  9096                                  iept_3:	
  9097 000032DC C3                      	retn
  9098                                  
  9099                                  ;-----------------------------------------------------------------------------
  9100                                  ; 27/02/2019
  9101                                  
  9102                                  delete_logical_drives:
  9103                                  
  9104                                  ; Delete Method: ; 04/03/2019
  9105                                  ;LDD 5 <- LDD_START3, ebr 2nd entry
  9106                                  ;LDD 4 <- LDD_START2, ebr 2nd entry
  9107                                  ;LDD 3 <- LDD_START1, ebr 2nd entry
  9108                                  ;LDD 2 <- LDD_START0, ebr 2nd entry
  9109                                  ;LDD 1 <- LDD_START0, ebr 1st entry
  9110                                  
  9111                                  	;cmp	byte [ldrives], 0
  9112                                  	;jna	short dld_stc
  9113                                  
  9114 000032DD B005                    	mov	al, 5 ; extended partition (logical drives)
  9115 000032DF E83DF7                  	call	display_partition_table
  9116                                  
  9117 000032E2 A0[E46F]                	mov	al, [ldrives]
  9118 000032E5 0430                    	add	al, '0'
  9119 000032E7 A2[ED62]                	mov	[lddp_num], al
  9120                                  
  9121 000032EA BE[9A62]                	mov	si, msg_delete_ldd
  9122 000032ED E88FEB                  	call	print_msg
  9123                                  
  9124 000032F0 BE[D74F]                	mov	si, msg_press_esc_to_cancel
  9125 000032F3 E889EB                  	call	print_msg
  9126                                  dld_0:
  9127 000032F6 30E4                    	xor	ah, ah
  9128 000032F8 CD16                    	int	16h
  9129                                  
  9130 000032FA 80FC53                  	cmp	ah, 53h  ; DELETE or DEL key
  9131 000032FD 7527                    	jne	short dld_1
  9132                                  
  9133                                  	; Open disk image file again.
  9134 000032FF BA[915A]                	mov	dx, img_file_name
  9135 00003302 B8023D                  	mov	ax, 3D02h ; open for reading and writing
  9136 00003305 CD21                    	int	21h
  9137 00003307 7221                    	jc	short dld_5
  9138                                  
  9139 00003309 A3[A441]                	mov	[img_file_handle], ax
  9140                                  
  9141                                  	; Delete PTE 1 & PTE 2 on EBR 1
  9142                                  	;xor	ah, ah
  9143 0000330C A0[E46F]                	mov	al, [ldrives]
  9144 0000330F FEC8                    	dec	al
  9145 00003311 7518                    	jnz	short dld_2
  9146                                  
  9147 00003313 BF[A871]                	mov	di, ebr_buffer+446
  9148 00003316 B91000                  	mov	cx, 16
  9149 00003319 F3AB                    	rep	stosw
  9150                                  
  9151                                  	; 04/03/2019
  9152                                  	; Clear ldd data in extended partition table/structure
  9153 0000331B BF[A472]                	mov	di, ext_table_boot_ind
  9154 0000331E B109                    	mov	cl, 9
  9155 00003320 F3AB                    	rep	stosw
  9156 00003322 31F6                    	xor	si, si
  9157 00003324 EB40                    	jmp	short dld_3
  9158                                  dld_1:	
  9159 00003326 3C1B                    	cmp	al, 27 ; ESC key
  9160 00003328 75CC                    	jne	short dld_0
  9161                                  dld_5:
  9162 0000332A C3                      	retn
  9163                                  
  9164                                  ;dld_stc:
  9165                                  ;	stc
  9166                                  ;	retn	
  9167                                  
  9168                                  dld_2:
  9169                                  	; 04/03/2019
  9170                                  	; Delete 2nd PTE on EBR 2 to 4
  9171 0000332B FEC8                    	dec	al 
  9172 0000332D C0E002                  	shl	al, 2 ; *4
  9173 00003330 89C6                    	mov	si, ax
  9174                                  
  9175 00003332 8B84[4273]              	mov	ax, [si+ldd_start]
  9176 00003336 8B94[4473]              	mov	dx, [si+ldd_start+2]
  9177 0000333A BB[EA6F]                	mov	bx, ebr_buffer
  9178 0000333D E88DEB                  	call	read_hd_sector
  9179 00003340 7238                    	jc	short dld_4
  9180                                  
  9181 00003342 BF[B871]                	mov	di, ebr_buffer+446+16
  9182 00003345 B90800                  	mov	cx, 8
  9183 00003348 29C0                    	sub	ax, ax
  9184 0000334A F3AB                    	rep	stosw
  9185                                  
  9186                                  	; 04/03/2019
  9187                                  	;cmp	byte [ldrives], 5
  9188                                  	;jnb	short dld_3
  9189 0000334C 8A26[E46F]              	mov	ah, [ldrives]
  9190 00003350 80FC05                  	cmp	ah, 5
  9191 00003353 7311                    	jnb	short dld_3
  9192                                  
  9193                                  	; Clear ldd data in extended partition table/structure
  9194                                  	;mov	ah, [ldrives]
  9195 00003355 FECC                    	dec	ah
  9196 00003357 B012                    	mov	al, 18
  9197 00003359 F6E4                    	mul	ah
  9198 0000335B BF[A472]                	mov	di, ext_table_boot_ind
  9199 0000335E 01C7                    	add	di, ax
  9200                                  	;mov	cx, 9
  9201 00003360 B109                    	mov	cl, 9
  9202                                  	;xor	ax, ax
  9203 00003362 30C0                    	xor	al, al
  9204 00003364 F3AB                    	rep	stosw
  9205                                  dld_3:
  9206                                  	; Write changed EBR
  9207 00003366 8B84[4273]              	mov	ax, [si+ldd_start]
  9208 0000336A 8B94[4473]              	mov	dx, [si+ldd_start+2]
  9209 0000336E BB[EA6F]                	mov	bx, ebr_buffer
  9210 00003371 E81AEB                  	call	write_hd_sector
  9211 00003374 7204                    	jc	short dld_4
  9212                                  
  9213                                  	; 28/02/2019
  9214 00003376 FE0E[E46F]              	dec	byte [ldrives]
  9215                                  dld_4:
  9216                                  	; Close file
  9217 0000337A 8B1E[A441]              	mov	bx, [img_file_handle]
  9218 0000337E B43E                    	mov	ah, 3Eh ; close file
  9219 00003380 CD21                    	int	21h
  9220                                  
  9221 00003382 C706[A441]0000          	mov	word [img_file_handle], 0
  9222                                  
  9223 00003388 803E[E46F]00            	cmp	byte [ldrives], 0
  9224 0000338D 0F874CFF                	ja	delete_logical_drives
  9225                                  
  9226 00003391 C3                      	retn
  9227                                  
  9228                                  ;=============================================================================
  9229                                  ;        	initialized data
  9230                                  ;=============================================================================
  9231                                  
  9232 00003392 00                      	db	0
  9233                                  
  9234                                  TRDOS386_MASTERBOOT_SECTOR:
  9235 00003393 <incbin>                	incbin	'FS1_MBR.BIN' ; Singlix FS1 MBR	
  9236                                  
  9237                                  TRDOS_FAT_hd_bs:
  9238                                  	;incbin 'TRHDBS.BIN'
  9239                                  TRDOS_FAT32_hd_bs:
  9240 00003593 <incbin>                	incbin	'FAT32_BS.BIN'
  9241                                  TRDOS_FAT16_hd_bs: 
  9242 00003993 <incbin>                	incbin	'FAT16_BS.BIN'
  9243                                  TRDOS_FAT12_hd_bs: 
  9244 00003B93 <incbin>                	incbin	'FAT12_BS.BIN'
  9245                                  
  9246                                  TRDOS_TRFS1_chs_bs:
  9247 00003D93 <incbin>                	incbin	'TRFS1CHS.BIN' ; Singlix FS1 (CHS+LBA Disk) BS		
  9248                                  TRDOS_TRFS1_lba_bs:
  9249 00003F93 <incbin>                	incbin	'TRFS1LBA.BIN' ; Singlix FS1 (LBA Disk) BS	
  9250                                  
  9251 00004193 00                      	db	0
  9252                                  
  9253                                  hexchrs:
  9254 00004194 303132333435363738-     	db	'0123456789ABCDEF'
  9254 0000419D 39414243444546     
  9255                                  
  9256                                  align 2
  9257                                  
  9258                                  img_file_handle:
  9259 000041A4 0000                    	dw	0
  9260                                  
  9261                                  ; (TR-DOS 386 compatible) Hard Disk (image) parameters
  9262                                  
  9263                                  sectors: ; sectors per track (63)
  9264 000041A6 3F00                    	dw 63
  9265                                  heads:	 ; number of heads (16 or 32 or 64) 
  9266 000041A8 1000                    	dw 16
  9267                                  cylinders: ; number of cylinders (16 to 1024)
  9268 000041AA 0004                    	dw 1024
  9269                                  
  9270                                  random:
  9271 000041AC 00                      	db	0  ; random write to file (0 = sequental)
  9272                                  newdisk:
  9273 000041AD 00                      	db	0
  9274                                  
  9275                                  FileSys_Names: ; 2003-2017
  9276                                  ; (Valid FileSystems for TRDOS 386, SINGLIX, RETRO UNIX OS projects in 2017)
  9277 000041AE 464154313220202020-     FS_FAT12:     db "FAT12         "  ; 01h = FAT12
  9277 000041B7 2020202020         
  9278 000041BC 58454E495820202020-     FS_XENIX:     db "XENIX         "  ; 02h , XENIX System V root
  9278 000041C5 2020202020         
  9279 000041CA 58454E495820757372-     FS_XENIX_USR: db "XENIX usr     "  ; 03h , XENIX System V user
  9279 000041D3 2020202020         
  9280 000041D8 464154313620283034-     FS_FAT16:     db "FAT16 (04h)   "  ; 04h = FAT16 < 32MB
  9280 000041E1 6829202020         
  9281 000041E6 455854454E44454420-     FS_EXT_CHS:   db "EXTENDED (CHS)"  ; 05h = Extended DOS Partition
  9281 000041EF 2843485329         
  9282 000041F4 464154313620283036-     FS_FAT16_BIG: db "FAT16 (06h)   "  ; 06h = FAT16 > 32MB, CHS mode
  9282 000041FD 6829202020         
  9283 00004202 4E5446532020202020-     FS_NTFS:      db "NTFS          "  ; 07h , WINDOWS NTFS Partition
  9283 0000420B 2020202020         
  9284 00004210 464154333220284348-     FS_FAT32_CHS: db "FAT32 (CHS)   "  ; 0Bh = FAT32, CHS mode
  9284 00004219 5329202020         
  9285 0000421E 464154333220284C42-     FS_FAT32_LBA: db "FAT32 (LBA)   "  ; 0Ch = FAT32, LBA mode
  9285 00004227 4129202020         
  9286 0000422C 464154313620284C42-     FS_FAT16_LBA: db "FAT16 (LBA)   "  ; 0Eh = FAT16, LBA mode
  9286 00004235 4129202020         
  9287 0000423A 455854454E44454420-     FS_EXT_LBA:   db "EXTENDED (LBA)"  ; 0Fh = Extented Partition, LBA mode
  9287 00004243 284C424129         
  9288 00004248 554E49582053595354-     FS_UNIX_SYSV: db "UNIX SYSTEM V "  ; 63h , SCO UNIX, UNIXWARE, OPENSERVER
  9288 00004251 454D205620         
  9289 00004256 524554524F20554E49-     FS_RETROUNIX: db "RETRO UNIX    "  ; 71h , Retro UNIX 386 v2 Partition
  9289 0000425F 5820202020         
  9290 00004264 554E49582056372020-     FS_UNIX_V7:   db "UNIX V7       "  ; 72h , UNIX v7 x86 Partition  
  9290 0000426D 2020202020         
  9291 00004272 4C494E555820535741-     FS_LINUXSWAP: db "LINUX SWAP    "  ; 82h , LINUX SWAP Partition
  9291 0000427B 5020202020         
  9292 00004280 4C494E555820202020-     FS_LINUX:     db "LINUX         "  ; 83h , LINUX NATIVE (ext2) Partition
  9292 00004289 2020202020         
  9293 0000428E 4C494E555820455854-     FS_LINUXEXT:  db "LINUX EXTENDED"  ; 85h , LINUX EXTENDED Partition
  9293 00004297 454E444544         
  9294 0000429C 524444202020202020-     FS_TRDD:      db "RDD           "  ; A0h , (Random Data Disk) LBA
  9294 000042A5 2020202020         
  9295 000042AA 53494E474C49582046-     FS_TRFS:      db "SINGLIX FS1   "  ; A1h , (32 bit, 512 bytes per sector)
  9295 000042B3 5331202020         
  9296 000042B8 554E4B4E4F574E2046-     FS_OTHERS:    db "UNKNOWN FS    "  ; Another or Unknown File Systems
  9296 000042C1 5320202020         
  9297                                   
  9298                                  valid_partitions: ; (*)
  9299 000042C6 01020304050607          	      db 01h, 02h, 03h, 04h, 05h, 06h, 07h
  9300 000042CD 0B0C0E0F637172          	      db 0Bh, 0Ch, 0Eh, 0Fh, 63h, 71h, 72h
  9301 000042D4 828385A0A1              	      db 82h, 83h, 85h, 0A0h, 0A1h 			
  9302                                  
  9303                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  9304                                  ;  Messages
  9305                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  9306                                  
  9307                                  CHS_msg: ; 80 bytes per row
  9308 000042D9 507265737320274327-     db  "Press 'C' to set cylinders then press '+,-' keys to change number of cylinders. " 
  9308 000042E2 20746F207365742063-
  9308 000042EB 796C696E6465727320-
  9308 000042F4 7468656E2070726573-
  9308 000042FD 7320272B2C2D27206B-
  9308 00004306 65797320746F206368-
  9308 0000430F 616E6765206E756D62-
  9308 00004318 6572206F662063796C-
  9308 00004321 696E646572732E20   
  9309 00004329 507265737320274827-     db  "Press 'H' to set heads then press '+,-' keys to change number of heads.         " 
  9309 00004332 20746F207365742068-
  9309 0000433B 65616473207468656E-
  9309 00004344 20707265737320272B-
  9309 0000434D 2C2D27206B65797320-
  9309 00004356 746F206368616E6765-
  9309 0000435F 206E756D626572206F-
  9309 00004368 662068656164732E20-
  9309 00004371 2020202020202020   
  9310 00004379 507265737320275327-     db  "Press 'S' to set sectors then press '+,-' keys to change numb of sectors/track. " 
  9310 00004382 20746F207365742073-
  9310 0000438B 6563746F7273207468-
  9310 00004394 656E20707265737320-
  9310 0000439D 272B2C2D27206B6579-
  9310 000043A6 7320746F206368616E-
  9310 000043AF 6765206E756D62206F-
  9310 000043B8 6620736563746F7273-
  9310 000043C1 2F747261636B2E20   
  9311 000043C9 202020202020202020-     db  "                                                                                " 
  9311 000043D2 202020202020202020-
  9311 000043DB 202020202020202020-
  9311 000043E4 202020202020202020-
  9311 000043ED 202020202020202020-
  9311 000043F6 202020202020202020-
  9311 000043FF 202020202020202020-
  9311 00004408 202020202020202020-
  9311 00004411 2020202020202020   
  9312 00004419 202020202020202020-     db  "                                                                                " 
  9312 00004422 202020202020202020-
  9312 0000442B 202020202020202020-
  9312 00004434 202020202020202020-
  9312 0000443D 202020202020202020-
  9312 00004446 202020202020202020-
  9312 0000444F 202020202020202020-
  9312 00004458 202020202020202020-
  9312 00004461 2020202020202020   
  9313 00004469 507265737320454E54-     db  "Press ENTER to use current CHS values.                                          "
  9313 00004472 455220746F20757365-
  9313 0000447B 2063757272656E7420-
  9313 00004484 4348532076616C7565-
  9313 0000448D 732E20202020202020-
  9313 00004496 202020202020202020-
  9313 0000449F 202020202020202020-
  9313 000044A8 202020202020202020-
  9313 000044B1 2020202020202020   
  9314 000044B9 202020202020202020-     db  "                                                                                " 
  9314 000044C2 202020202020202020-
  9314 000044CB 202020202020202020-
  9314 000044D4 202020202020202020-
  9314 000044DD 202020202020202020-
  9314 000044E6 202020202020202020-
  9314 000044EF 202020202020202020-
  9314 000044F8 202020202020202020-
  9314 00004501 2020202020202020   
  9315 00004509 507265737320455343-     db  "Press ESC to cancel.                                                            "
  9315 00004512 20746F2063616E6365-
  9315 0000451B 6C2E20202020202020-
  9315 00004524 202020202020202020-
  9315 0000452D 202020202020202020-
  9315 00004536 202020202020202020-
  9315 0000453F 202020202020202020-
  9315 00004548 202020202020202020-
  9315 00004551 2020202020202020   
  9316 00004559 202020202020202020-     db  "                                                                                " 
  9316 00004562 202020202020202020-
  9316 0000456B 202020202020202020-
  9316 00004574 202020202020202020-
  9316 0000457D 202020202020202020-
  9316 00004586 202020202020202020-
  9316 0000458F 202020202020202020-
  9316 00004598 202020202020202020-
  9316 000045A1 2020202020202020   
  9317 000045A9 00                      db  0
  9318                                  
  9319                                  TrDOS_Welcome:
  9320 000045AA 0D0A                    	db	0Dh, 0Ah
  9321 000045AC 54522D444F53203338-     	db	'TR-DOS 386 Fixed Disk Image Format Utility'
  9321 000045B5 362046697865642044-
  9321 000045BE 69736B20496D616765-
  9321 000045C7 20466F726D61742055-
  9321 000045D0 74696C697479       
  9322 000045D6 0D0A                    	db	0Dh, 0Ah
  9323 000045D8 76312E302E30343131-     	db	"v1.0.041120 (c) Erdogan TAN 2019-2020"
  9323 000045E1 323020286329204572-
  9323 000045EA 646F67616E2054414E-
  9323 000045F3 20323031392D323032-
  9323 000045FC 30                 
  9324 000045FD 0D0A                    	db	0Dh,0Ah
  9325 000045FF 0D0A                    	db	0Dh,0Ah
  9326 00004601 55736167653A206864-     	db	'Usage: hdimage <image file name> '
  9326 0000460A 696D616765203C696D-
  9326 00004613 6167652066696C6520-
  9326 0000461C 6E616D653E20       
  9327 00004622 00                      	db	0
  9328                                  
  9329                                  msg_inv_file_name: 
  9330 00004623 0D0A                    	db	0Dh, 0Ah
  9331 00004625 496E76616C69642066-     	db	"Invalid file name !", 0Dh, 0Ah
  9331 0000462E 696C65206E616D6520-
  9331 00004637 210D0A             
  9332 0000463A 2846696C65206E616D-     	db	"(File name must fit to 8.3 DOS format) !"
  9332 00004643 65206D757374206669-
  9332 0000464C 7420746F20382E3320-
  9332 00004655 444F5320666F726D61-
  9332 0000465E 74292021           
  9333 00004662 0D0A00                  	db	0Dh, 0Ah, 0
  9334                                  
  9335                                  msg_inv_image_file:
  9336 00004665 0D0A                    	db	0Dh, 0Ah
  9337 00004667 496E76616C69642066-     	db	"Invalid fixed disk image file !", 0Dh, 0Ah
  9337 00004670 69786564206469736B-
  9337 00004679 20696D616765206669-
  9337 00004682 6C6520210D0A       
  9338 00004688 2846696C652073697A-     	db	"(File size or masterboot sector is not compatible) !"
  9338 00004691 65206F72206D617374-
  9338 0000469A 6572626F6F74207365-
  9338 000046A3 63746F72206973206E-
  9338 000046AC 6F7420636F6D706174-
  9338 000046B5 69626C65292021     
  9339 000046BC 0D0A00                  	db	0Dh, 0Ah, 0  
  9340                                  
  9341                                  msg_min_8mb_disk:
  9342 000046BF 0D0A                    	db	0Dh, 0Ah
  9343 000046C1 4D696E696D756D2038-     	db	"Minimum 8 MB disk size is needed for a proper hard disk image !"
  9343 000046CA 204D42206469736B20-
  9343 000046D3 73697A65206973206E-
  9343 000046DC 656564656420666F72-
  9343 000046E5 20612070726F706572-
  9343 000046EE 206861726420646973-
  9343 000046F7 6B20696D6167652021 
  9344 00004700 0D0A                    	db	0Dh, 0Ah
  9345 00004702 28507265737320616E-     	db	"(Press any key to continue..)" 
  9345 0000470B 79206B657920746F20-
  9345 00004714 636F6E74696E75652E-
  9345 0000471D 2E29               
  9346 0000471F 0D0A00                  	db	0Dh, 0Ah, 0
  9347                                  
  9348                                  msg_any_key_esc_exit:
  9349 00004722 0D0A                    	db	0Dh, 0Ah
  9350 00004724 507265737320455343-     	db	"Press ESC to exit or press another key to continue..."
  9350 0000472D 20746F206578697420-
  9350 00004736 6F7220707265737320-
  9350 0000473F 616E6F74686572206B-
  9350 00004748 657920746F20636F6E-
  9350 00004751 74696E75652E2E2E   
  9351 00004759 00                      	db	0
  9352                                  
  9353                                  msg_create_partition_h:
  9354 0000475A 0D0A                    	db	0Dh, 0Ah
  9355 0000475C 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"
  9355 00004765 2D2D2D2D2D2D2D2D2D-
  9355 0000476E 2D2D2D2D2D2D2D2D2D-
  9355 00004777 2D2D2D2D2D2D2D2D2D-
  9355 00004780 2D2D2D2D2D2D2D2D2D-
  9355 00004789 2D2D2D2D2D2D2D2D2D-
  9355 00004792 2D2D2D2D2D2D2D2D2D-
  9355 0000479B 2D2D2D2D2D2D2D2D2D-
  9355 000047A4 2D2D2D2D2D2D2D2D   
  9356 000047AC 202020202020202020-     	db	"                               Create Partition                                 "
  9356 000047B5 202020202020202020-
  9356 000047BE 202020202020202020-
  9356 000047C7 202020204372656174-
  9356 000047D0 652050617274697469-
  9356 000047D9 6F6E20202020202020-
  9356 000047E2 202020202020202020-
  9356 000047EB 202020202020202020-
  9356 000047F4 2020202020202020   
  9357 000047FC 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"	
  9357 00004805 2D2D2D2D2D2D2D2D2D-
  9357 0000480E 2D2D2D2D2D2D2D2D2D-
  9357 00004817 2D2D2D2D2D2D2D2D2D-
  9357 00004820 2D2D2D2D2D2D2D2D2D-
  9357 00004829 2D2D2D2D2D2D2D2D2D-
  9357 00004832 2D2D2D2D2D2D2D2D2D-
  9357 0000483B 2D2D2D2D2D2D2D2D2D-
  9357 00004844 2D2D2D2D2D2D2D2D   
  9358 0000484C 0D0A00                  	db	0Dh, 0Ah, 0
  9359                                  msg_create_partition_m:
  9360 0000484F 53656C65637420616E-     	db	"Select an option: "
  9360 00004858 206F7074696F6E3A20 
  9361 00004861 0D0A                    	db	0Dh, 0Ah
  9362 00004863 0D0A                    	db	0Dh, 0Ah
  9363 00004865 202031292043726561-     	db	"  1) Create DOS partition ", 0Dh, 0Ah
  9363 0000486E 746520444F53207061-
  9363 00004877 72746974696F6E200D-
  9363 00004880 0A                 
  9364 00004881 202032292043726561-     	db	"  2) Create SINGLIX FS partition ", 0Dh, 0Ah			
  9364 0000488A 74652053494E474C49-
  9364 00004893 582046532070617274-
  9364 0000489C 6974696F6E200D0A   
  9365 000048A4 202033292043726561-     	db	"  3) Create RETRO UNIX partition ", 0Dh, 0Ah
  9365 000048AD 746520524554524F20-
  9365 000048B6 554E49582070617274-
  9365 000048BF 6974696F6E200D0A   
  9366 000048C7 202034292043726561-     	db	"  4) Create another type of partition ", 0Dh, 0Ah 		
  9366 000048D0 746520616E6F746865-
  9366 000048D9 722074797065206F66-
  9366 000048E2 20706172746974696F-
  9366 000048EB 6E200D0A           
  9367 000048EF 0D0A                    	db	0Dh, 0Ah	
  9368 000048F1 507265737320455343-     	db	"Press ESC or 0 to cancel .. "
  9368 000048FA 206F72203020746F20-
  9368 00004903 63616E63656C202E2E-
  9368 0000490C 20                 
  9369 0000490D 0D0A00                   	db 	0Dh, 0Ah, 0	
  9370                                  
  9371                                  msg_create_primary_partition_h:
  9372 00004910 0D0A                    	db	0Dh, 0Ah
  9373 00004912 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"
  9373 0000491B 2D2D2D2D2D2D2D2D2D-
  9373 00004924 2D2D2D2D2D2D2D2D2D-
  9373 0000492D 2D2D2D2D2D2D2D2D2D-
  9373 00004936 2D2D2D2D2D2D2D2D2D-
  9373 0000493F 2D2D2D2D2D2D2D2D2D-
  9373 00004948 2D2D2D2D2D2D2D2D2D-
  9373 00004951 2D2D2D2D2D2D2D2D2D-
  9373 0000495A 2D2D2D2D2D2D2D2D   
  9374 00004962 202020202020202020-     	db	"                          Create Primary DOS Partition                          "
  9374 0000496B 202020202020202020-
  9374 00004974 202020202020202043-
  9374 0000497D 726561746520507269-
  9374 00004986 6D61727920444F5320-
  9374 0000498F 506172746974696F6E-
  9374 00004998 202020202020202020-
  9374 000049A1 202020202020202020-
  9374 000049AA 2020202020202020   
  9375 000049B2 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"	
  9375 000049BB 2D2D2D2D2D2D2D2D2D-
  9375 000049C4 2D2D2D2D2D2D2D2D2D-
  9375 000049CD 2D2D2D2D2D2D2D2D2D-
  9375 000049D6 2D2D2D2D2D2D2D2D2D-
  9375 000049DF 2D2D2D2D2D2D2D2D2D-
  9375 000049E8 2D2D2D2D2D2D2D2D2D-
  9375 000049F1 2D2D2D2D2D2D2D2D2D-
  9375 000049FA 2D2D2D2D2D2D2D2D   
  9376 00004A02 0D0A00                  	db	0Dh, 0Ah, 0	
  9377                                  
  9378                                  msg_create_dos_partition_h:
  9379 00004A05 0D0A                    	db	0Dh, 0Ah
  9380 00004A07 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"
  9380 00004A10 2D2D2D2D2D2D2D2D2D-
  9380 00004A19 2D2D2D2D2D2D2D2D2D-
  9380 00004A22 2D2D2D2D2D2D2D2D2D-
  9380 00004A2B 2D2D2D2D2D2D2D2D2D-
  9380 00004A34 2D2D2D2D2D2D2D2D2D-
  9380 00004A3D 2D2D2D2D2D2D2D2D2D-
  9380 00004A46 2D2D2D2D2D2D2D2D2D-
  9380 00004A4F 2D2D2D2D2D2D2D2D   
  9381 00004A57 202020202020202020-     	db	"                   Create DOS Partition or Logical DOS Drive                    "
  9381 00004A60 202020202020202020-
  9381 00004A69 204372656174652044-
  9381 00004A72 4F5320506172746974-
  9381 00004A7B 696F6E206F72204C6F-
  9381 00004A84 676963616C20444F53-
  9381 00004A8D 204472697665202020-
  9381 00004A96 202020202020202020-
  9381 00004A9F 2020202020202020   
  9382 00004AA7 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"	
  9382 00004AB0 2D2D2D2D2D2D2D2D2D-
  9382 00004AB9 2D2D2D2D2D2D2D2D2D-
  9382 00004AC2 2D2D2D2D2D2D2D2D2D-
  9382 00004ACB 2D2D2D2D2D2D2D2D2D-
  9382 00004AD4 2D2D2D2D2D2D2D2D2D-
  9382 00004ADD 2D2D2D2D2D2D2D2D2D-
  9382 00004AE6 2D2D2D2D2D2D2D2D2D-
  9382 00004AEF 2D2D2D2D2D2D2D2D   
  9383 00004AF7 0D0A00                  	db	0Dh, 0Ah, 0	
  9384                                  
  9385                                  msg_create_ext_partition_h:
  9386 00004AFA 0D0A                    	db	0Dh, 0Ah
  9387 00004AFC 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"
  9387 00004B05 2D2D2D2D2D2D2D2D2D-
  9387 00004B0E 2D2D2D2D2D2D2D2D2D-
  9387 00004B17 2D2D2D2D2D2D2D2D2D-
  9387 00004B20 2D2D2D2D2D2D2D2D2D-
  9387 00004B29 2D2D2D2D2D2D2D2D2D-
  9387 00004B32 2D2D2D2D2D2D2D2D2D-
  9387 00004B3B 2D2D2D2D2D2D2D2D2D-
  9387 00004B44 2D2D2D2D2D2D2D2D   
  9388 00004B4C 202020202020202020-     	db	"                         Create Extended DOS Partition                          "
  9388 00004B55 202020202020202020-
  9388 00004B5E 202020202020204372-
  9388 00004B67 656174652045787465-
  9388 00004B70 6E64656420444F5320-
  9388 00004B79 506172746974696F6E-
  9388 00004B82 202020202020202020-
  9388 00004B8B 202020202020202020-
  9388 00004B94 2020202020202020   
  9389 00004B9C 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"	
  9389 00004BA5 2D2D2D2D2D2D2D2D2D-
  9389 00004BAE 2D2D2D2D2D2D2D2D2D-
  9389 00004BB7 2D2D2D2D2D2D2D2D2D-
  9389 00004BC0 2D2D2D2D2D2D2D2D2D-
  9389 00004BC9 2D2D2D2D2D2D2D2D2D-
  9389 00004BD2 2D2D2D2D2D2D2D2D2D-
  9389 00004BDB 2D2D2D2D2D2D2D2D2D-
  9389 00004BE4 2D2D2D2D2D2D2D2D   
  9390 00004BEC 0D0A00                  	db	0Dh, 0Ah, 0
  9391                                  
  9392                                  msg_create_logical_drive_h:
  9393 00004BEF 0D0A                    	db	0Dh, 0Ah
  9394 00004BF1 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"
  9394 00004BFA 2D2D2D2D2D2D2D2D2D-
  9394 00004C03 2D2D2D2D2D2D2D2D2D-
  9394 00004C0C 2D2D2D2D2D2D2D2D2D-
  9394 00004C15 2D2D2D2D2D2D2D2D2D-
  9394 00004C1E 2D2D2D2D2D2D2D2D2D-
  9394 00004C27 2D2D2D2D2D2D2D2D2D-
  9394 00004C30 2D2D2D2D2D2D2D2D2D-
  9394 00004C39 2D2D2D2D2D2D2D2D   
  9395 00004C41 202020202020202020-     	db	"                            Create Logical DOS Drive                            "
  9395 00004C4A 202020202020202020-
  9395 00004C53 202020202020202020-
  9395 00004C5C 20437265617465204C-
  9395 00004C65 6F676963616C20444F-
  9395 00004C6E 532044726976652020-
  9395 00004C77 202020202020202020-
  9395 00004C80 202020202020202020-
  9395 00004C89 2020202020202020   
  9396 00004C91 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"	
  9396 00004C9A 2D2D2D2D2D2D2D2D2D-
  9396 00004CA3 2D2D2D2D2D2D2D2D2D-
  9396 00004CAC 2D2D2D2D2D2D2D2D2D-
  9396 00004CB5 2D2D2D2D2D2D2D2D2D-
  9396 00004CBE 2D2D2D2D2D2D2D2D2D-
  9396 00004CC7 2D2D2D2D2D2D2D2D2D-
  9396 00004CD0 2D2D2D2D2D2D2D2D2D-
  9396 00004CD9 2D2D2D2D2D2D2D2D   
  9397 00004CE1 0D0A00                  	db	0Dh, 0Ah, 0	
  9398                                  
  9399                                  msg_create_nondos_partition_h:
  9400 00004CE4 0D0A                    	db	0Dh, 0Ah
  9401 00004CE6 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"
  9401 00004CEF 2D2D2D2D2D2D2D2D2D-
  9401 00004CF8 2D2D2D2D2D2D2D2D2D-
  9401 00004D01 2D2D2D2D2D2D2D2D2D-
  9401 00004D0A 2D2D2D2D2D2D2D2D2D-
  9401 00004D13 2D2D2D2D2D2D2D2D2D-
  9401 00004D1C 2D2D2D2D2D2D2D2D2D-
  9401 00004D25 2D2D2D2D2D2D2D2D2D-
  9401 00004D2E 2D2D2D2D2D2D2D2D   
  9402 00004D36 202020202020202020-     	db	"                            Create NON-DOS Partition                            "
  9402 00004D3F 202020202020202020-
  9402 00004D48 202020202020202020-
  9402 00004D51 20437265617465204E-
  9402 00004D5A 4F4E2D444F53205061-
  9402 00004D63 72746974696F6E2020-
  9402 00004D6C 202020202020202020-
  9402 00004D75 202020202020202020-
  9402 00004D7E 2020202020202020   
  9403 00004D86 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"	
  9403 00004D8F 2D2D2D2D2D2D2D2D2D-
  9403 00004D98 2D2D2D2D2D2D2D2D2D-
  9403 00004DA1 2D2D2D2D2D2D2D2D2D-
  9403 00004DAA 2D2D2D2D2D2D2D2D2D-
  9403 00004DB3 2D2D2D2D2D2D2D2D2D-
  9403 00004DBC 2D2D2D2D2D2D2D2D2D-
  9403 00004DC5 2D2D2D2D2D2D2D2D2D-
  9403 00004DCE 2D2D2D2D2D2D2D2D   
  9404 00004DD6 0D0A00                  	db	0Dh, 0Ah, 0		
  9405                                  
  9406                                  msg_create_dos_partition_m:
  9407 00004DD9 53656C65637420616E-     	db	"Select an option: "
  9407 00004DE2 206F7074696F6E3A20 
  9408 00004DEB 0D0A                    	db	0Dh, 0Ah
  9409 00004DED 0D0A                    	db	0Dh, 0Ah
  9410 00004DEF 202031292043726561-     	db	"  1) Create Primary DOS partition ", 0Dh, 0Ah
  9410 00004DF8 7465205072696D6172-
  9410 00004E01 7920444F5320706172-
  9410 00004E0A 746974696F6E200D0A 
  9411 00004E13 202032292043726561-     	db	"  2) Create Extended DOS partition ", 0Dh, 0Ah			
  9411 00004E1C 746520457874656E64-
  9411 00004E25 656420444F53207061-
  9411 00004E2E 72746974696F6E200D-
  9411 00004E37 0A                 
  9412 00004E38 202033292043726561-     	db	"  3) Create Logical DOS drive(s) in Extended DOS partition ", 0Dh, 0Ah
  9412 00004E41 7465204C6F67696361-
  9412 00004E4A 6C20444F5320647269-
  9412 00004E53 766528732920696E20-
  9412 00004E5C 457874656E64656420-
  9412 00004E65 444F53207061727469-
  9412 00004E6E 74696F6E200D0A     
  9413 00004E75 0D0A                    	db	0Dh, 0Ah	
  9414 00004E77 507265737320455343-     	db	"Press ESC or 0 to cancel .. "
  9414 00004E80 206F72203020746F20-
  9414 00004E89 63616E63656C202E2E-
  9414 00004E92 20                 
  9415 00004E93 0D0A00                   	db 	0Dh, 0Ah, 0
  9416                                  
  9417                                  msg_create_trdos_partition_s:
  9418 00004E96 53656C65637420616E-     	db	"Select an option to set partition size: "
  9418 00004E9F 206F7074696F6E2074-
  9418 00004EA8 6F2073657420706172-
  9418 00004EB1 746974696F6E207369-
  9418 00004EBA 7A653A20           
  9419 00004EBE 0D0A                    	db	0Dh, 0Ah
  9420 00004EC0 0D0A                    	db	0Dh, 0Ah
  9421 00004EC2 202043292043796C69-     	db	"  C) Cylinder count", 0Dh, 0Ah   
  9421 00004ECB 6E64657220636F756E-
  9421 00004ED4 740D0A             
  9422 00004ED7 2020252920566F6C75-     	db	"  %) Volume percentage (##%)", 0Dh, 0Ah
  9422 00004EE0 6D652070657263656E-
  9422 00004EE9 746167652028232325-
  9422 00004EF2 290D0A             
  9423 00004EF5 202053292053656374-     	db	"  S) Sectors (number of 512 bytes)", 0Dh, 0Ah
  9423 00004EFE 6F727320286E756D62-
  9423 00004F07 6572206F6620353132-
  9423 00004F10 206279746573290D0A 
  9424 00004F19 20204B29204B696C6F-     	db	"  K) Kilo bytes (KB, 2*K sectors)", 0Dh, 0Ah
  9424 00004F22 20627974657320284B-
  9424 00004F2B 422C20322A4B207365-
  9424 00004F34 63746F7273290D0A   
  9425 00004F3C 20204D29204D656761-     	db	"  M) Mega bytes (MB, 2*1024*M sectors)", 0Dh, 0Ah
  9425 00004F45 20627974657320284D-
  9425 00004F4E 422C20322A31303234-
  9425 00004F57 2A4D20736563746F72-
  9425 00004F60 73290D0A           
  9426 00004F64 202047292047696761-     	db	"  G) Giga bytes (GB, 2*1024*1024*G sectors)", 0Dh, 0Ah			
  9426 00004F6D 206279746573202847-
  9426 00004F76 422C20322A31303234-
  9426 00004F7F 2A313032342A472073-
  9426 00004F88 6563746F7273290D0A 
  9427 00004F91 0D0A                    	db	0Dh, 0Ah	
  9428 00004F93 507265737320535041-     	db	"Press SPACE to use whole disk or press ENTER to set sector count .. "
  9428 00004F9C 434520746F20757365-
  9428 00004FA5 2077686F6C65206469-
  9428 00004FAE 736B206F7220707265-
  9428 00004FB7 737320454E54455220-
  9428 00004FC0 746F20736574207365-
  9428 00004FC9 63746F7220636F756E-
  9428 00004FD2 74202E2E20         
  9429                                  msg_press_esc_to_cancel:
  9430 00004FD7 0D0A                     	db	0Dh, 0Ah
  9431 00004FD9 285072657373204553-     	db	"(Press ESC to CANCEL) "
  9431 00004FE2 4320746F2043414E43-
  9431 00004FEB 454C2920           
  9432 00004FEF 0D0A00                  	db 	0Dh, 0Ah, 0
  9433                                  
  9434                                  msg_use_whole_disk:
  9435 00004FF2 446F20796F75207761-     	db	"Do you want to use WHOLE disk !? (Y/N)", 0
  9435 00004FFB 6E7420746F20757365-
  9435 00005004 2057484F4C45206469-
  9435 0000500D 736B20213F2028592F-
  9435 00005016 4E2900             
  9436                                  
  9437                                  msg_use_all_space:
  9438 00005019 446F20796F75207761-     	db	"Do you want to use all of available space !? (Y/N)", 0
  9438 00005022 6E7420746F20757365-
  9438 0000502B 20616C6C206F662061-
  9438 00005034 7661696C61626C6520-
  9438 0000503D 737061636520213F20-
  9438 00005046 28592F4E2900       
  9439                                  
  9440                                  msg_use_entire_ep_space:
  9441 0000504C 446F20796F75207761-     	db	"Do you want to use entire extended partition space !? (Y/N)", 0
  9441 00005055 6E7420746F20757365-
  9441 0000505E 20656E746972652065-
  9441 00005067 7874656E6465642070-
  9441 00005070 6172746974696F6E20-
  9441 00005079 737061636520213F20-
  9441 00005082 28592F4E2900       
  9442                                  
  9443                                  msg_partition_size:
  9444 00005088 0D0A                    	db	0Dh, 0Ah
  9445 0000508A 0D0A                    	db	0Dh, 0Ah
  9446 0000508C 506172746974696F6E-     	db	"Partition size ("
  9446 00005095 2073697A652028     
  9447                                  msg_partition_size_x:
  9448 0000509C 3F29203A20              	db	"?) : "
  9449 000050A1 00                      	db	0
  9450                                  
  9451                                  msg_partition_type:
  9452 000050A2 0D0A                    	db	0Dh, 0Ah
  9453 000050A4 0D0A                    	db	0Dh, 0Ah
  9454 000050A6 506172746974696F6E-     	db	"Partition type : "
  9454 000050AF 2074797065203A20   
  9455 000050B7 00                      	db	0
  9456                                  
  9457                                  msg_ptype_num:
  9458 000050B8 3030680D0A00            	db	"00h", 0Dh, 0Ah, 0
  9459                                  
  9460                                  msg_partition_type_error:
  9461 000050BE 506172746974696F6E-     	db	"Partition size is not proper for selected partition type !"
  9461 000050C7 2073697A6520697320-
  9461 000050D0 6E6F742070726F7065-
  9461 000050D9 7220666F722073656C-
  9461 000050E2 656374656420706172-
  9461 000050EB 746974696F6E207479-
  9461 000050F4 70652021           
  9462 000050F8 0D0A                    	db	0Dh, 0Ah
  9463                                  msg_any_key_to_retry:
  9464 000050FA 28507265737320616E-     	db	"(Press any key to retry..)" 
  9464 00005103 79206B657920746F20-
  9464 0000510C 72657472792E2E29   
  9465 00005114 0D0A00                  	db	0Dh, 0Ah, 0
  9466                                  
  9467                                  msg_partition_size_overs:
  9468 00005117 0D0A                    	db	0Dh, 0Ah
  9469 00005119 506172746974696F6E-     	db	"Partition size overs the disk capacity !"
  9469 00005122 2073697A65206F7665-
  9469 0000512B 727320746865206469-
  9469 00005134 736B20636170616369-
  9469 0000513D 74792021           
  9470 00005141 0D0A                    	db	0Dh, 0Ah
  9471 00005143 28507265737320454E-     	db	"(Press ENTER to use WHOLE disk or press ESC key to retry..)" 
  9471 0000514C 54455220746F207573-
  9471 00005155 652057484F4C452064-
  9471 0000515E 69736B206F72207072-
  9471 00005167 65737320455343206B-
  9471 00005170 657920746F20726574-
  9471 00005179 72792E2E29         
  9472 0000517E 0D0A00                  	db	0Dh, 0Ah, 0
  9473                                  
  9474                                  msg_ext_partition_error:
  9475 00005181 457874656E64656420-     	db	"Extended partition must be created after primary partition !"
  9475 0000518A 706172746974696F6E-
  9475 00005193 206D75737420626520-
  9475 0000519C 637265617465642061-
  9475 000051A5 66746572207072696D-
  9475 000051AE 617279207061727469-
  9475 000051B7 74696F6E2021       
  9476 000051BD 0D0A00                  	db	0Dh, 0Ah,0
  9477                                  
  9478                                  msg_logical_drive_error:
  9479 000051C0 5072696D6172792061-     	db	"Primary and extended partitions must be created before logical drive !"
  9479 000051C9 6E6420657874656E64-
  9479 000051D2 656420706172746974-
  9479 000051DB 696F6E73206D757374-
  9479 000051E4 206265206372656174-
  9479 000051ED 6564206265666F7265-
  9479 000051F6 206C6F676963616C20-
  9479 000051FF 64726976652021     
  9480 00005206 0D0A00                  	db	0Dh, 0Ah,0
  9481                                  
  9482                                  msg_cylinder_boundary_set:
  9483 00005209 0D0A                    	db	0Dh, 0Ah
  9484 0000520B 446F20796F75207761-     	db	"Do you want to adjust partition size to cylinder boundary ? (Y/N)"
  9484 00005214 6E7420746F2061646A-
  9484 0000521D 757374207061727469-
  9484 00005226 74696F6E2073697A65-
  9484 0000522F 20746F2063796C696E-
  9484 00005238 64657220626F756E64-
  9484 00005241 617279203F2028592F-
  9484 0000524A 4E29               
  9485 0000524C 00                      	db	0
  9486                                  
  9487                                  msg_selected_partition:
  9488 0000524D 202020202020202020-     	db	"                                 PARTITION 0                                    "
  9488 00005256 202020202020202020-
  9488 0000525F 202020202020202020-
  9488 00005268 202020202020504152-
  9488 00005271 544954494F4E203020-
  9488 0000527A 202020202020202020-
  9488 00005283 202020202020202020-
  9488 0000528C 202020202020202020-
  9488 00005295 2020202020202020   
  9489 0000529D 3D3D3D3D3D3D3D3D3D-     	db	"================================================================================"
  9489 000052A6 3D3D3D3D3D3D3D3D3D-
  9489 000052AF 3D3D3D3D3D3D3D3D3D-
  9489 000052B8 3D3D3D3D3D3D3D3D3D-
  9489 000052C1 3D3D3D3D3D3D3D3D3D-
  9489 000052CA 3D3D3D3D3D3D3D3D3D-
  9489 000052D3 3D3D3D3D3D3D3D3D3D-
  9489 000052DC 3D3D3D3D3D3D3D3D3D-
  9489 000052E5 3D3D3D3D3D3D3D3D   
  9490 000052ED 202020202020202053-     	db	"        S  BH  BS  BC  FS  EH  ES  EC    START SEC   SECTORS   FILE SYSTEM      "
  9490 000052F6 202042482020425320-
  9490 000052FF 204243202046532020-
  9490 00005308 454820204553202045-
  9490 00005311 432020202053544152-
  9490 0000531A 542053454320202053-
  9490 00005323 4543544F5253202020-
  9490 0000532C 46494C452053595354-
  9490 00005335 454D202020202020   
  9491 0000533D 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"
  9491 00005346 2D2D2D2D2D2D2D2D2D-
  9491 0000534F 2D2D2D2D2D2D2D2D2D-
  9491 00005358 2D2D2D2D2D2D2D2D2D-
  9491 00005361 2D2D2D2D2D2D2D2D2D-
  9491 0000536A 2D2D2D2D2D2D2D2D2D-
  9491 00005373 2D2D2D2D2D2D2D2D2D-
  9491 0000537C 2D2D2D2D2D2D2D2D2D-
  9491 00005385 2D2D2D2D2D2D2D2D   
  9492 0000538D 202020202020202020-     pt_row:	db	"                                                                                "
  9492 00005396 202020202020202020-
  9492 0000539F 202020202020202020-
  9492 000053A8 202020202020202020-
  9492 000053B1 202020202020202020-
  9492 000053BA 202020202020202020-
  9492 000053C3 202020202020202020-
  9492 000053CC 202020202020202020-
  9492 000053D5 2020202020202020   
  9493 000053DD 3D3D3D3D3D3D3D3D3D-     	db	"================================================================================"
  9493 000053E6 3D3D3D3D3D3D3D3D3D-
  9493 000053EF 3D3D3D3D3D3D3D3D3D-
  9493 000053F8 3D3D3D3D3D3D3D3D3D-
  9493 00005401 3D3D3D3D3D3D3D3D3D-
  9493 0000540A 3D3D3D3D3D3D3D3D3D-
  9493 00005413 3D3D3D3D3D3D3D3D3D-
  9493 0000541C 3D3D3D3D3D3D3D3D3D-
  9493 00005425 3D3D3D3D3D3D3D3D   
  9494 0000542D 00                      	db	0
  9495                                  msg_boot_indicator:
  9496 0000542E 0D0A                    	db	0Dh, 0Ah
  9497 00005430 20202020426F6F7420-     	db	"    Boot Indicator : ", 0 ; "YES", "NO"
  9497 00005439 496E64696361746F72-
  9497 00005442 203A2000           
  9498                                  msg_starting_head:
  9499 00005446 0D0A                    	db	0Dh, 0Ah
  9500 00005448 202020202053746172-     	db 	"     Starting Head : ", 0
  9500 00005451 74696E672048656164-
  9500 0000545A 203A2000           
  9501                                  msg_starting_sector:
  9502 0000545E 0D0A                    	db	0Dh, 0Ah
  9503 00005460 202020537461727469-     	db	"   Starting Sector : ", 0
  9503 00005469 6E6720536563746F72-
  9503 00005472 203A2000           
  9504                                  msg_starting_cylinder:
  9505 00005476 0D0A                    	db	0Dh, 0Ah
  9506 00005478 205374617274696E67-     	db	" Starting Cylinder : ", 0
  9506 00005481 2043796C696E646572-
  9506 0000548A 203A2000           
  9507                                  msg_system_id:
  9508 0000548E 0D0A                    	db	0Dh, 0Ah
  9509 00005490 202020202020202020-     	db	"         System ID : ", 0
  9509 00005499 53797374656D204944-
  9509 000054A2 203A2000           
  9510                                  msg_ending_head:
  9511 000054A6 0D0A                    	db	0Dh, 0Ah
  9512 000054A8 20202020202020456E-     	db 	"       Ending Head : ", 0
  9512 000054B1 64696E672048656164-
  9512 000054BA 203A2000           
  9513                                  msg_ending_sector:
  9514 000054BE 0D0A                    	db	0Dh, 0Ah
  9515 000054C0 2020202020456E6469-     	db	"     Ending Sector : ", 0
  9515 000054C9 6E6720536563746F72-
  9515 000054D2 203A2000           
  9516                                  msg_ending_cylinder:
  9517 000054D6 0D0A                    	db	0Dh, 0Ah
  9518 000054D8 202020456E64696E67-     	db	"   Ending Cylinder : ", 0
  9518 000054E1 2043796C696E646572-
  9518 000054EA 203A2000           
  9519                                  msg_relative_sectors:
  9520 000054EE 0D0A                    	db	0Dh, 0Ah
  9521 000054F0 0D0A                    	db	0Dh, 0Ah
  9522 000054F2 202052656C61746976-     	db	"  Relative Sectors : ", 0
  9522 000054FB 6520536563746F7273-
  9522 00005504 203A2000           
  9523                                  msg_total_sectors:
  9524 00005508 0D0A                    	db	0Dh, 0Ah
  9525 0000550A 2020202020546F7461-     	db	"     Total Sectors : ", 0
  9525 00005513 6C20536563746F7273-
  9525 0000551C 203A2000           
  9526                                  
  9527                                  msg_format_stage:
  9528 00005520 0D0A                    	db	0Dh, 0Ah
  9529 00005522 507265737320454E54-     	db	"Press ENTER to FORMAT disk partition "
  9529 0000552B 455220746F20464F52-
  9529 00005534 4D4154206469736B20-
  9529 0000553D 706172746974696F6E-
  9529 00005546 20                 
  9530                                  partition_num_chr:
  9531 00005547 30                      	db	"0"
  9532 00005548 206F72207072657373-     	db	" or press ESC to EXIT.."
  9532 00005551 2045534320746F2045-
  9532 0000555A 5849542E2E         
  9533 0000555F 00                      	db	0
  9534                                  msg_partition_edit:
  9535 00005560 0D0A                    	db	0Dh, 0Ah
  9536 00005562 2E2E206F7220707265-     	db	".. or press SPACE to EDIT partition table."
  9536 0000556B 737320535041434520-
  9536 00005574 746F20454449542070-
  9536 0000557D 6172746974696F6E20-
  9536 00005586 7461626C652E       
  9537 0000558C 0D0A00                  	db	0Dh, 0Ah, 0
  9538                                  
  9539                                  msg_edit_or_exit:
  9540 0000558F 0D0A                    	db 	0Dh, 0Ah
  9541 00005591 507265737320454E54-     	db	"Press ENTER to continue or press ESC to exit.."
  9541 0000559A 455220746F20636F6E-
  9541 000055A3 74696E7565206F7220-
  9541 000055AC 707265737320455343-
  9541 000055B5 20746F20657869742E-
  9541 000055BE 2E                 
  9542 000055BF 00                      	db	0
  9543                                  
  9544                                  msg_overwrite_question1:
  9545 000055C0 0D0A                    	db	0Dh, 0Ah
  9546 000055C2 446F20796F75207761-     	db	'Do you want to overwrite '
  9546 000055CB 6E7420746F206F7665-
  9546 000055D4 72777269746520     
  9547 000055DB 27                      	db	27h
  9548 000055DC 00                      	db	0
  9549                                  
  9550                                  msg_overwrite_question2: 
  9551 000055DD 27                      	db	27h
  9552 000055DE 2066696C6520            	db	' file '
  9553 000055E4 00                      	db	0
  9554                                  
  9555                                  msg_format_question:
  9556 000055E5 0D0A                    	db	0Dh, 0Ah
  9557 000055E7 446F20796F75207761-     	db	"Do you want to format partition "
  9557 000055F0 6E7420746F20666F72-
  9557 000055F9 6D6174207061727469-
  9557 00005602 74696F6E20         
  9558                                  partition_num_txt:
  9559 00005607 3020                    	db	 "0 "
  9560                                  msg_yes_no:
  9561 00005609 285965732F4E6F293F-     	db	'(Yes/No)? ', 0		
  9561 00005612 2000               
  9562                                  
  9563                                  msg_writing_mbr:
  9564 00005614 57726974696E67206D-     	db	"Writing masterboot sector...", 0
  9564 0000561D 6173746572626F6F74-
  9564 00005626 20736563746F722E2E-
  9564 0000562F 2E00               
  9565                                  
  9566                                  msg_writing_disk_sectors:
  9567 00005631 57726974696E672064-     	db	"Writing disk sector: ", 0
  9567 0000563A 69736B20736563746F-
  9567 00005643 723A2000           
  9568                                  
  9569                                  Msg_Writing_Boot_Sector:
  9570 00005647 57726974696E672074-     	db	"Writing trdos boot sector...", 0
  9570 00005650 72646F7320626F6F74-
  9570 00005659 20736563746F722E2E-
  9570 00005662 2E00               
  9571                                  
  9572                                  Msg_Writing_Root_Dir:
  9573 00005664 57726974696E672072-     	db	"Writing root directory sectors...", 0
  9573 0000566D 6F6F74206469726563-
  9573 00005676 746F72792073656374-
  9573 0000567F 6F72732E2E2E00     
  9574                                  
  9575                                  Msg_Writing_Data_Sectors:
  9576 00005686 57726974696E672064-     	db	"Writing data sector: ", 0
  9576 0000568F 61746120736563746F-
  9576 00005698 723A2000           
  9577                                  
  9578                                  Sector_Str:
  9579 0000569C 3030303030303000        	db	"0000000", 0
  9580                                  Cursor_Pos:
  9581 000056A4 0000                    	dw	0
  9582                                  
  9583                                  Msg_Writing_FAT_Sectors:
  9584 000056A6 57726974696E672046-     	db	"Writing FAT sectors...", 0
  9584 000056AF 415420736563746F72-
  9584 000056B8 732E2E2E00         
  9585                                  
  9586                                  StrVolumeName:
  9587                                  	;times 	12 db  0
  9588 000056BD 00<rept>                	times	65 db 0  ; 05/01/2018 (fs1 volume name)	
  9589                                  
  9590                                  Msg_Volume_Name:
  9591 000056FE 0D0A                    	db	0Dh, 0Ah
  9592 00005700 0D0A                    	db	0Dh, 0Ah
  9593 00005702 566F6C756D65204E61-     	db	"Volume Name: ", 0
  9593 0000570B 6D653A2000         
  9594                                  
  9595                                  Msg_Volume_Serial:
  9596 00005710 566F6C756D65205365-     	db	"Volume Serial No: "
  9596 00005719 7269616C204E6F3A20 
  9597                                  Vol_Serial1:
  9598 00005722 30303030                	db	"0000"
  9599 00005726 2D                      	db	"-"
  9600                                  Vol_Serial2:
  9601 00005727 30303030                	db	"0000"
  9602 0000572B 0D0A00                  	db	0Dh, 0Ah, 0
  9603                                  
  9604                                  msg_cluster_count:
  9605 0000572E 436C75737465722043-     	db	"Cluster Count: ", 0
  9605 00005737 6F756E743A2000     
  9606                                  cluster_count_str:
  9607 0000573E 30303030303030          	db	"0000000"
  9608 00005745 0D0A00                  	db	0Dh, 0Ah, 0
  9609                                  msg_formatting:
  9610 00005748 466F726D617474696E-     	db	"Formatting ", 0
  9610 00005751 672000             
  9611                                  format_percent_str:
  9612 00005754 30303025                	db	"000%"
  9613 00005758 00                      	db	0					
  9614                                  
  9615                                  Msg_3dot_OK:
  9616 00005759 2E2E2E                  	db	"..."
  9617                                  Msg_OK:
  9618 0000575C 204F4B2E                	db	' OK.'
  9619                                  CRLF:
  9620 00005760 0D0A00                  	db	0Dh, 0Ah, 0
  9621                                  
  9622                                  Msg_Error:
  9623 00005763 0D0A                    	db	0Dh, 0Ah
  9624 00005765 4572726F72202120        	db	'Error ! '
  9625 0000576D 28                      	db	'('
  9626                                  error_code:
  9627 0000576E 3030                    	dw	3030h
  9628 00005770 68                      	db	'h'
  9629 00005771 2920                    	db	') '
  9630 00005773 0D0A                    	db	0Dh, 0Ah
  9631 00005775 00                      	db	0
  9632                                  
  9633                                  msg_disk_sectors:
  9634 00005776 546F74616C20446973-     	db	"Total Disk Sectors : ", 0
  9634 0000577F 6B20536563746F7273-
  9634 00005788 203A2000           
  9635                                  
  9636                                  str_disk_sectors:
  9637 0000578C 00<rept>                	times	8 db 0
  9638                                  
  9639                                  msg_ep_size:
  9640 00005794 457874656E64656420-     	db	"Extended Partition Size in Sectors: ", 0
  9640 0000579D 506172746974696F6E-
  9640 000057A6 2053697A6520696E20-
  9640 000057AF 536563746F72733A20-
  9640 000057B8 00                 
  9641                                  
  9642                                  msg_file_size:
  9643 000057B9 484420496D61676520-     	db	"HD Image File Size : ", 0
  9643 000057C2 46696C652053697A65-
  9643 000057CB 203A2000           
  9644                                  
  9645                                  str_file_size:
  9646 000057CF 00<rept>                	times	11 db 0
  9647                                  
  9648                                  msg_bytes:
  9649 000057DA 206279746573            	db	" bytes"
  9650 000057E0 0D0A00                  	db	0Dh, 0Ah, 0
  9651                                  
  9652                                  msg_enter_cancel:
  9653 000057E3 0D0A                    	db	0Dh, 0Ah
  9654 000057E5 507265737320454E54-     	db	"Press ENTER to write file or press ESC to cancel." 
  9654 000057EE 455220746F20777269-
  9654 000057F7 74652066696C65206F-
  9654 00005800 722070726573732045-
  9654 00005809 534320746F2063616E-
  9654 00005812 63656C2E           
  9655 00005816 0D0A00                  	db	0Dh, 0Ah, 0
  9656                                  
  9657                                  msg_press_any_key:
  9658 00005819 0D0A                    	db	0Dh, 0Ah
  9659 0000581B 50726573732061206B-     	db	"Press a key to continue..." 
  9659 00005824 657920746F20636F6E-
  9659 0000582D 74696E75652E2E2E   
  9660 00005835 0D0A00                  	db	0Dh, 0Ah, 0
  9661                                  
  9662                                  align 2
  9663                                  
  9664                                  ; Masterboot sector
  9665                                  
  9666                                  MasterBootBuff:
  9667                                  MasterBootCode: 
  9668 00005838 00<rept>                	times	446 db 0
  9669                                  PartitionTable:
  9670 000059F6 00<rept>                	times	64 db 0
  9671                                  MBIDCode:
  9672 00005A36 0000                    	dw	0
  9673                                  
  9674                                  PTable_Buffer:
  9675 00005A38 00<rept>                	times	64 db 0
  9676                                   
  9677 00005A78 286329204572646F67-     	db	'(c) Erdogan TAN 2019-2020'
  9677 00005A81 616E2054414E203230-
  9677 00005A8A 31392D32303230     
  9678                                  
  9679                                  img_file_name:  
  9680 00005A91 00<rept>                	times	13 db 0
  9681                                  
  9682                                  p_table_header:
  9683 00005A9E 202020202020202020-     	db	"                              ?BR PARTITION TABLE                               "
  9683 00005AA7 202020202020202020-
  9683 00005AB0 202020202020202020-
  9683 00005AB9 2020203F4252205041-
  9683 00005AC2 52544954494F4E2054-
  9683 00005ACB 41424C452020202020-
  9683 00005AD4 202020202020202020-
  9683 00005ADD 202020202020202020-
  9683 00005AE6 2020202020202020   
  9684 00005AEE 3D3D3D3D3D3D3D3D3D-     	db	"================================================================================"
  9684 00005AF7 3D3D3D3D3D3D3D3D3D-
  9684 00005B00 3D3D3D3D3D3D3D3D3D-
  9684 00005B09 3D3D3D3D3D3D3D3D3D-
  9684 00005B12 3D3D3D3D3D3D3D3D3D-
  9684 00005B1B 3D3D3D3D3D3D3D3D3D-
  9684 00005B24 3D3D3D3D3D3D3D3D3D-
  9684 00005B2D 3D3D3D3D3D3D3D3D3D-
  9684 00005B36 3D3D3D3D3D3D3D3D   
  9685 00005B3E 202020202020205020-     	db	"       P  S  BH  BS  BC  FS  EH  ES  EC  START SEC  SECTORS  FILE SYSTEM        "
  9685 00005B47 205320204248202042-
  9685 00005B50 532020424320204653-
  9685 00005B59 202045482020455320-
  9685 00005B62 204543202053544152-
  9685 00005B6B 542053454320205345-
  9685 00005B74 43544F525320204649-
  9685 00005B7D 4C452053595354454D-
  9685 00005B86 2020202020202020   
  9686 00005B8E 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"
  9686 00005B97 2D2D2D2D2D2D2D2D2D-
  9686 00005BA0 2D2D2D2D2D2D2D2D2D-
  9686 00005BA9 2D2D2D2D2D2D2D2D2D-
  9686 00005BB2 2D2D2D2D2D2D2D2D2D-
  9686 00005BBB 2D2D2D2D2D2D2D2D2D-
  9686 00005BC4 2D2D2D2D2D2D2D2D2D-
  9686 00005BCD 2D2D2D2D2D2D2D2D2D-
  9686 00005BD6 2D2D2D2D2D2D2D2D   
  9687 00005BDE 00                      	db	0
  9688                                  p_table_footer:
  9689 00005BDF 3D3D3D3D3D3D3D3D3D-     	db	"================================================================================"
  9689 00005BE8 3D3D3D3D3D3D3D3D3D-
  9689 00005BF1 3D3D3D3D3D3D3D3D3D-
  9689 00005BFA 3D3D3D3D3D3D3D3D3D-
  9689 00005C03 3D3D3D3D3D3D3D3D3D-
  9689 00005C0C 3D3D3D3D3D3D3D3D3D-
  9689 00005C15 3D3D3D3D3D3D3D3D3D-
  9689 00005C1E 3D3D3D3D3D3D3D3D3D-
  9689 00005C27 3D3D3D3D3D3D3D3D   
  9690 00005C2F 0D0A00                  	db	0Dh,0Ah,0
  9691                                  
  9692                                  mbr_editing_options:
  9693 00005C32 0D0A0D0A                	db 0Dh, 0Ah, 0Dh, 0Ah 
  9694 00005C36 4D4252205061727469-     	db "MBR Partition Table Editing Options:" 
  9694 00005C3F 74696F6E205461626C-
  9694 00005C48 652045646974696E67-
  9694 00005C51 204F7074696F6E733A 
  9695 00005C5A 0D0A0D0A                	db 0Dh, 0Ah, 0Dh, 0Ah
  9696 00005C5E 20202020202020312E-     	db "       1. Create Partition", 0Dh, 0Ah
  9696 00005C67 204372656174652050-
  9696 00005C70 6172746974696F6E0D-
  9696 00005C79 0A                 
  9697 00005C7A 20202020202020322E-     	db "       2. Set Active Partition", 0Dh, 0Ah
  9697 00005C83 205365742041637469-
  9697 00005C8C 766520506172746974-
  9697 00005C95 696F6E0D0A         
  9698 00005C9A 20202020202020332E-     	db "       3. Delete Partition", 0Dh, 0Ah  
  9698 00005CA3 2044656C6574652050-
  9698 00005CAC 6172746974696F6E0D-
  9698 00005CB5 0A                 
  9699 00005CB6 20202020202020342E-     	db "       4. Write Current Partition Table", 0Dh, 0Ah, 0
  9699 00005CBF 205772697465204375-
  9699 00005CC8 7272656E7420506172-
  9699 00005CD1 746974696F6E205461-
  9699 00005CDA 626C650D0A00       
  9700                                  
  9701                                  enter_option_number_msg:
  9702 00005CE0 0D0A                    	db 0Dh, 0Ah
  9703 00005CE2 456E74657220746865-     	db "Enter the option number or press ESC to exit ...", 0Dh, 0Ah
  9703 00005CEB 206F7074696F6E206E-
  9703 00005CF4 756D626572206F7220-
  9703 00005CFD 707265737320455343-
  9703 00005D06 20746F206578697420-
  9703 00005D0F 2E2E2E0D0A         
  9704                                  	;db 0Dh, 0Ah, 0
  9705 00005D14 00                      	db 0 
  9706                                  
  9707                                  msg_zero_partition_size:  ; 19/02/2019
  9708 00005D15 0D0A                    	db	0Dh, 0Ah
  9709 00005D17 506172746974696F6E-     	db	"Partition size input must not be ZERO !", 0Dh, 0Ah
  9709 00005D20 2073697A6520696E70-
  9709 00005D29 7574206D757374206E-
  9709 00005D32 6F74206265205A4552-
  9709 00005D3B 4F20210D0A         
  9710 00005D40 285072657373204553-     	db	"(Press ESC to exit or press another key to retry..)", 0Dh, 0Ah
  9710 00005D49 4320746F2065786974-
  9710 00005D52 206F72207072657373-
  9710 00005D5B 20616E6F7468657220-
  9710 00005D64 6B657920746F207265-
  9710 00005D6D 7472792E2E290D0A   
  9711 00005D75 00                      	db	0 
  9712                                  
  9713                                  msg_empty_pt:
  9714 00005D76 0D0A                    	db	0Dh, 0Ah
  9715 00005D78 456D70747920706172-     	db	"Empty partition table !", 0Dh, 0Ah
  9715 00005D81 746974696F6E207461-
  9715 00005D8A 626C6520210D0A     
  9716 00005D91 28412076616C696420-     	db	"(A valid partition must be created at first..)", 0Dh, 0Ah
  9716 00005D9A 706172746974696F6E-
  9716 00005DA3 206D75737420626520-
  9716 00005DAC 637265617465642061-
  9716 00005DB5 742066697273742E2E-
  9716 00005DBE 290D0A             
  9717 00005DC1 00                      	db	0
  9718                                  
  9719                                  msg_full_pt:
  9720 00005DC2 0D0A                    	db	0Dh, 0Ah
  9721 00005DC4 546865726520697320-     	db	"There is not a free partition table entry ", 0
  9721 00005DCD 6E6F74206120667265-
  9721 00005DD6 652070617274697469-
  9721 00005DDF 6F6E207461626C6520-
  9721 00005DE8 656E7472792000     
  9722                                  msg_to_create_new_p: 
  9723 00005DEF 746F20637265617465-     	db	"to create a new partition !", 0Dh, 0Ah
  9723 00005DF8 2061206E6577207061-
  9723 00005E01 72746974696F6E2021-
  9723 00005E0A 0D0A               
  9724 00005E0C 00                      	db	0
  9725                                  msg_no_free_space:
  9726 00005E0D 0D0A                    	db	0Dh, 0Ah
  9727 00005E0F 546865726520697320-     	db	"There is not (enough) free space ", 0
  9727 00005E18 6E6F742028656E6F75-
  9727 00005E21 676829206672656520-
  9727 00005E2A 73706163652000     
  9728                                  
  9729                                  msg_enter_pn_to_del:
  9730 00005E31 0D0A                    	db	0Dh, 0Ah
  9731 00005E33 456E74657220706172-     	db	"Enter partition number to delete: " 
  9731 00005E3C 746974696F6E206E75-
  9731 00005E45 6D62657220746F2064-
  9731 00005E4E 656C6574653A20     
  9732                                  chr_del_pnum1:
  9733 00005E55 00                      	db	0       
  9734 00005E56 0D0A00                  	db	0Dh, 0Ah, 0
  9735                                  
  9736                                  msg_delete_partition_q:
  9737 00005E59 0D0A                    	db 	0Dh, 0Ah
  9738 00005E5B 5741524E494E472120-     	db 	"WARNING! All of data in the selected partition will be lost", 0Dh, 0Ah
  9738 00005E64 416C6C206F66206461-
  9738 00005E6D 746120696E20746865-
  9738 00005E76 2073656C6563746564-
  9738 00005E7F 20706172746974696F-
  9738 00005E88 6E2077696C6C206265-
  9738 00005E91 206C6F73740D0A     
  9739 00005E98 202020202020202020-     	db	"         after you write changed partition table to disk !!", 0Dh, 0Ah
  9739 00005EA1 616674657220796F75-
  9739 00005EAA 207772697465206368-
  9739 00005EB3 616E67656420706172-
  9739 00005EBC 746974696F6E207461-
  9739 00005EC5 626C6520746F206469-
  9739 00005ECE 736B2021210D0A     
  9740 00005ED5 0D0A                    	db	0Dh, 0Ah
  9741 00005ED7 446F20796F75207761-     	db	"Do you want to delete PARTITION " 
  9741 00005EE0 6E7420746F2064656C-
  9741 00005EE9 657465205041525449-
  9741 00005EF2 54494F4E20         
  9742                                  chr_del_pnum2:
  9743 00005EF7 30                      	db	'0'
  9744 00005EF8 203F2028592F4E2920-     	db	' ? (Y/N) ', 0
  9744 00005F01 00                 
  9745                                  
  9746                                  _msg_YES:
  9747 00005F02 20                      	db	 20h
  9748                                  msg_YES:
  9749 00005F03 5945532000              	db	'YES ', 0
  9750                                  _msg_NO:
  9751 00005F08 20                      	db	20h
  9752                                  msg_NO:
  9753 00005F09 4E4F2000                	db	'NO ', 0
  9754                                  
  9755                                  ; 11/02/2019
  9756                                  msg_write_masterboot_sector:
  9757 00005F0D 0D0A                    	db	0Dh, 0Ah 
  9758 00005F0F 577269746520437572-     	db	"Write Current Partition Table:" 
  9758 00005F18 72656E742050617274-
  9758 00005F21 6974696F6E20546162-
  9758 00005F2A 6C653A             
  9759 00005F2D 0D0A0D0A                	db	0Dh, 0Ah, 0Dh, 0Ah
  9760 00005F31 20312E205772697465-     	db	" 1. Write Partition Table only", 0Dh, 0Ah
  9760 00005F3A 20506172746974696F-
  9760 00005F43 6E205461626C65206F-
  9760 00005F4C 6E6C790D0A         
  9761 00005F51 20322E205772697465-     	db	" 2. Write Partition Table and Singlix Master Boot Code", 0Dh, 0Ah
  9761 00005F5A 20506172746974696F-
  9761 00005F63 6E205461626C652061-
  9761 00005F6C 6E642053696E676C69-
  9761 00005F75 78204D617374657220-
  9761 00005F7E 426F6F7420436F6465-
  9761 00005F87 0D0A               
  9762                                  enter_opt_num_cancel_msg:
  9763 00005F89 0D0A                    	db	0Dh, 0Ah
  9764 00005F8B 456E74657220746865-     	db	"Enter the option number or press ESC to cancel ...", 0           
  9764 00005F94 206F7074696F6E206E-
  9764 00005F9D 756D626572206F7220-
  9764 00005FA6 707265737320455343-
  9764 00005FAF 20746F2063616E6365-
  9764 00005FB8 6C202E2E2E00       
  9765                                  
  9766                                  msg_writing_ptable:
  9767 00005FBE 0D0A0D0A                	db	0Dh, 0Ah, 0Dh, 0Ah  
  9768 00005FC2 57726974696E672070-     	db	"Writing partition table on disk ... ", 0
  9768 00005FCB 6172746974696F6E20-
  9768 00005FD4 7461626C65206F6E20-
  9768 00005FDD 6469736B202E2E2E20-
  9768 00005FE6 00                 
  9769                                  _msg_OK:
  9770                                  	;db	7
  9771 00005FE7 0D0A                    	db	0Dh, 0Ah
  9772 00005FE9 4F4B2021                	db	"OK !"
  9773 00005FED 0D0A00                  	db	0Dh, 0Ah, 0
  9774                                  
  9775                                  option_input:
  9776 00005FF0 205B205D00              	db	' [ ]', 0
  9777                                  
  9778                                  msg_enter_pn_to_act:
  9779 00005FF5 0D0A                    	db	0Dh, 0Ah
  9780 00005FF7 456E74657220706172-     	db	"Enter partition number to set as active: ", 0 
  9780 00006000 746974696F6E206E75-
  9780 00006009 6D62657220746F2073-
  9780 00006012 657420617320616374-
  9780 0000601B 6976653A2000       
  9781                                  
  9782                                  trdos386_disk_chs_header:
  9783 00006021 0D0A                    	db	0Dh, 0Ah
  9784 00006023 202020202020202020-     	db	"                     TRDOS 386 (SINGLIX) HARD DISK IMAGE                        "
  9784 0000602C 202020202020202020-
  9784 00006035 2020205452444F5320-
  9784 0000603E 333836202853494E47-
  9784 00006047 4C4958292048415244-
  9784 00006050 204449534B20494D41-
  9784 00006059 474520202020202020-
  9784 00006062 202020202020202020-
  9784 0000606B 2020202020202020   
  9785 00006073 00                      	db 	0
  9786                                  
  9787                                  disk_chs_header:
  9788 00006074 0D0A                    	db	0Dh, 0Ah
  9789 00006076 202020202020202020-     	db	"                                HARD DISK IMAGE                                 "
  9789 0000607F 202020202020202020-
  9789 00006088 202020202020202020-
  9789 00006091 202020202048415244-
  9789 0000609A 204449534B20494D41-
  9789 000060A3 474520202020202020-
  9789 000060AC 202020202020202020-
  9789 000060B5 202020202020202020-
  9789 000060BE 2020202020202020   
  9790 000060C6 00                      	db 	0
  9791                                  
  9792                                  msg_partition_size_limit:
  9793 000060C7 0D0A                    	db	0Dh, 0Ah
  9794 000060C9 506172746974696F6E-     	db	"Partition size overs available free space !"
  9794 000060D2 2073697A65206F7665-
  9794 000060DB 727320617661696C61-
  9794 000060E4 626C65206672656520-
  9794 000060ED 73706163652021     
  9795 000060F4 0D0A                    	db	0Dh, 0Ah
  9796 000060F6 4D61782E2061766169-     	db 	"Max. available free space is ", 0
  9796 000060FF 6C61626C6520667265-
  9796 00006108 652073706163652069-
  9796 00006111 732000             
  9797                                  
  9798                                  msg_partition_size_limit_r:
  9799 00006114 0D0A0D0A                	db	0Dh, 0Ah, 0Dh, 0Ah
  9800 00006118 28507265737320454E-     	db	"(Press ENTER to use all of available space or press ESC key to retry..) " 
  9800 00006121 54455220746F207573-
  9800 0000612A 6520616C6C206F6620-
  9800 00006133 617661696C61626C65-
  9800 0000613C 207370616365206F72-
  9800 00006145 207072657373204553-
  9800 0000614E 43206B657920746F20-
  9800 00006157 72657472792E2E2920 
  9801 00006160 000A00                  	db	0D, 0Ah, 0
  9802                                  
  9803                                  msg_cylinders:
  9804 00006163 2063796C696E646572-     	db	" cylinders", 0
  9804 0000616C 7300               
  9805                                  msg_sectors:
  9806 0000616E 20736563746F727300      	db	" sectors", 0
  9807                                  
  9808                                  ; 02/03/2019
  9809                                  msg_megabytes:
  9810 00006177 206D65676162797465      	db	" megabyte"
  9811                                  msg_megabytes_s:
  9812 00006180 0000                    	db	0, 0
  9813                                  
  9814                                  msg_inv_pte:
  9815 00006182 0D0A                    	db	0Dh, 0Ah
  9816 00006184 496E76616C69642070-     	db	"Invalid partition table entry ! (P"
  9816 0000618D 6172746974696F6E20-
  9816 00006196 7461626C6520656E74-
  9816 0000619F 72792021202850     
  9817 000061A6 3F290D0A                inv_pte_num: db	"?)", 0Dh, 0Ah
  9818 000061AA 28507265737320454E-     	db	"(Press ENTER to DELETE or press ESC to EXIT..)"
  9818 000061B3 54455220746F204445-
  9818 000061BC 4C455445206F722070-
  9818 000061C5 726573732045534320-
  9818 000061CE 746F20455849542E2E-
  9818 000061D7 29                 
  9819 000061D8 0D0A00                  	db	0Dh, 0Ah, 0
  9820                                  
  9821                                  msg_ext_partition_exists:
  9822 000061DB 457874656E64656420-     	db	"Extended partition already exists !"
  9822 000061E4 706172746974696F6E-
  9822 000061ED 20616C726561647920-
  9822 000061F6 6578697374732021   
  9823 000061FE 0D0A00                  	db	0Dh, 0Ah, 0
  9824                                  
  9825                                  msg_defective_pt:
  9826 00006201 0D0A                    	db	0Dh, 0Ah
  9827 00006203 446566656374697665-     	db	"Defective partition table !", 0
  9827 0000620C 20706172746974696F-
  9827 00006215 6E207461626C652021-
  9827 0000621E 00                 
  9828                                  
  9829                                  ; 27/02/2019
  9830                                  msg_ext_part_del_error:
  9831 0000621F 0D0A                    	db	0Dh, 0Ah
  9832 00006221 457874656E64656420-     	db	"Extended partition must be deleted after logical drive(s) !"
  9832 0000622A 706172746974696F6E-
  9832 00006233 206D75737420626520-
  9832 0000623C 64656C657465642061-
  9832 00006245 66746572206C6F6769-
  9832 0000624E 63616C206472697665-
  9832 00006257 2873292021         
  9833 0000625C 0D0A00                  	db	0Dh, 0Ah, 0
  9834                                  
  9835                                  msg_cancel_continue:
  9836 0000625F 285072657373204553-     	db	"(Press ESC to cancel or press another key to continue..)"
  9836 00006268 4320746F2063616E63-
  9836 00006271 656C206F7220707265-
  9836 0000627A 737320616E6F746865-
  9836 00006283 72206B657920746F20-
  9836 0000628C 636F6E74696E75652E-
  9836 00006295 2E29               
  9837 00006297 0D0A00                  	db	0Dh, 0Ah, 0
  9838                                  
  9839                                  msg_delete_ldd:
  9840 0000629A 0D0A                    	db	0Dh, 0Ah
  9841 0000629C 0D0A                    	db	0Dh, 0Ah
  9842 0000629E 44656C657465204C6F-     	db	"Delete Logical (DOS) Drive:"
  9842 000062A7 676963616C2028444F-
  9842 000062B0 53292044726976653A 
  9843 000062B9 0D0A                    	db	0Dh, 0Ah
  9844 000062BB 50726573732044454C-     	db	"Press DELETE key to delete logical disk partition "
  9844 000062C4 455445206B65792074-
  9844 000062CD 6F2064656C65746520-
  9844 000062D6 6C6F676963616C2064-
  9844 000062DF 69736B207061727469-
  9844 000062E8 74696F6E20         
  9845 000062ED 3F2E                    lddp_num: db	"?."
  9846 000062EF 0D0A00                  	db	0Dh, 0Ah, 0
  9847                                  
  9848                                  msg_delete_ext_part:
  9849 000062F2 0D0A                    	db	0Dh, 0Ah
  9850 000062F4 0D0A                    	db	0Dh, 0Ah
  9851 000062F6 44656C657465204578-     	db	"Delete Extended (DOS) Partition:"
  9851 000062FF 74656E646564202844-
  9851 00006308 4F5329205061727469-
  9851 00006311 74696F6E3A         
  9852 00006316 0D0A                    	db	0Dh, 0Ah
  9853 00006318 507265737320454E54-     	db	"Press ENTER to delete or press ESC to cancel.."
  9853 00006321 455220746F2064656C-
  9853 0000632A 657465206F72207072-
  9853 00006333 657373204553432074-
  9853 0000633C 6F2063616E63656C2E-
  9853 00006345 2E                 
  9854 00006346 0D0A00                  	db	0Dh, 0Ah, 0
  9855                                  
  9856                                  str_display_ebr_pt:
  9857 00006349 285072657373205350-     	db	"(Press SPACE to edit EXTENDED Partition Table)", 0Dh, 0Ah, 0
  9857 00006352 41434520746F206564-
  9857 0000635B 697420455854454E44-
  9857 00006364 454420506172746974-
  9857 0000636D 696F6E205461626C65-
  9857 00006376 290D0A00           
  9858                                  
  9859                                  ebr_editing_options:
  9860 0000637A 0D0A0D0A                	db 0Dh, 0Ah, 0Dh, 0Ah 
  9861 0000637E 457874656E64656420-     	db "Extended Partition Table Editing Options:" 
  9861 00006387 506172746974696F6E-
  9861 00006390 205461626C65204564-
  9861 00006399 6974696E67204F7074-
  9861 000063A2 696F6E733A         
  9862 000063A7 0D0A0D0A                	db 0Dh, 0Ah, 0Dh, 0Ah
  9863 000063AB 20202020202020312E-     	db "       1. Create Logical DOS Drive", 0Dh, 0Ah
  9863 000063B4 20437265617465204C-
  9863 000063BD 6F676963616C20444F-
  9863 000063C6 532044726976650D0A 
  9864 000063CF 20202020202020322E-     	db "       2. Delete Logical (DOS) Drive(s)",0Dh, 0Ah, 0
  9864 000063D8 2044656C657465204C-
  9864 000063E1 6F676963616C202844-
  9864 000063EA 4F5329204472697665-
  9864 000063F3 2873290D0A00       
  9865                                  
  9866                                  msg_delete_ldd_q:
  9867 000063F9 0D0A                    	db 	0Dh, 0Ah
  9868 000063FB 5741524E494E47210D-     	db 	"WARNING!", 0Dh, 0Ah 
  9868 00006404 0A                 
  9869 00006405 416C6C206F66206461-     	db	"All of data in logical (DOS) drive(s) will be lost !!", 0Dh, 0Ah
  9869 0000640E 746120696E206C6F67-
  9869 00006417 6963616C2028444F53-
  9869 00006420 292064726976652873-
  9869 00006429 292077696C6C206265-
  9869 00006432 206C6F73742021210D-
  9869 0000643B 0A                 
  9870 0000643C 0D0A                    	db	0Dh, 0Ah
  9871 0000643E 446F20796F75207761-     	db	"Do you want to continue ? (Y/N) ", 0
  9871 00006447 6E7420746F20636F6E-
  9871 00006450 74696E7565203F2028-
  9871 00006459 592F4E292000       
  9872                                  
  9873                                  msg_create_ldd_max_error:
  9874 0000645F 0D0A                    	db	0Dh, 0Ah
  9875 00006461 50726F6772616D206C-     	db	"Program limit for logical dos drive count is 4 !"
  9875 0000646A 696D697420666F7220-
  9875 00006473 6C6F676963616C2064-
  9875 0000647C 6F7320647269766520-
  9875 00006485 636F756E7420697320-
  9875 0000648E 342021             
  9876 00006491 0D0A00                  	db 	0Dh, 0Ah, 0
  9877                                  
  9878                                  msg_c_ldd_unused_warning:
  9879 00006494 0D0A                    	db	0Dh, 0Ah
  9880 00006496 546865726520697320-     	db	"There is unused extended partition space after logical dos drive "
  9880 0000649F 756E75736564206578-
  9880 000064A8 74656E646564207061-
  9880 000064B1 72746974696F6E2073-
  9880 000064BA 706163652061667465-
  9880 000064C3 72206C6F676963616C-
  9880 000064CC 20646F732064726976-
  9880 000064D5 6520               
  9881                                  char_lddn:
  9882 000064D7 342021                  	db	"4 !"
  9883 000064DA 0D0A                    	db 	0Dh, 0Ah
  9884 000064DC 285072657373204553-     	db	"(Press ESC to add unused space or press ENTER to continue.)"	 
  9884 000064E5 4320746F2061646420-
  9884 000064EE 756E75736564207370-
  9884 000064F7 616365206F72207072-
  9884 00006500 65737320454E544552-
  9884 00006509 20746F20636F6E7469-
  9884 00006512 6E75652E29         
  9885 00006517 0D0A00                  	db 	0Dh, 0Ah, 0
  9886                                  
  9887                                  msg_create_ldd_s:
  9888 0000651A 53656C65637420616E-     	db	"Select an option to set logical dos drive size: "
  9888 00006523 206F7074696F6E2074-
  9888 0000652C 6F20736574206C6F67-
  9888 00006535 6963616C20646F7320-
  9888 0000653E 64726976652073697A-
  9888 00006547 653A20             
  9889 0000654A 0D0A                    	db	0Dh, 0Ah
  9890 0000654C 0D0A                    	db	0Dh, 0Ah
  9891 0000654E 202043292043796C69-     	db	"  C) Cylinder count", 0Dh, 0Ah   
  9891 00006557 6E64657220636F756E-
  9891 00006560 740D0A             
  9892 00006563 2020252920566F6C75-     	db	"  %) Volume percentage (##%)", 0Dh, 0Ah
  9892 0000656C 6D652070657263656E-
  9892 00006575 746167652028232325-
  9892 0000657E 290D0A             
  9893 00006581 20204D29204D656761-     	db	"  M) Mega bytes (MB, 2*1024*M sectors)", 0Dh, 0Ah
  9893 0000658A 20627974657320284D-
  9893 00006593 422C20322A31303234-
  9893 0000659C 2A4D20736563746F72-
  9893 000065A5 73290D0A           
  9894 000065A9 202047292047696761-     	db	"  G) Giga bytes (GB, 2*1024*1024*G sectors)", 0Dh, 0Ah			
  9894 000065B2 206279746573202847-
  9894 000065BB 422C20322A31303234-
  9894 000065C4 2A313032342A472073-
  9894 000065CD 6563746F7273290D0A 
  9895 000065D6 0D0A                    	db	0Dh, 0Ah	
  9896 000065D8 507265737320535041-     	db	"Press SPACE to use entire space or press ENTER to set Megabytes .. ", 0
  9896 000065E1 434520746F20757365-
  9896 000065EA 20656E746972652073-
  9896 000065F3 70616365206F722070-
  9896 000065FC 7265737320454E5445-
  9896 00006605 5220746F2073657420-
  9896 0000660E 4D6567616279746573-
  9896 00006617 202E2E2000         
  9897                                  
  9898                                  msg_c_part_error:
  9899 0000661C 0D0A                    	db 	0Dh, 0Ah
  9900 0000661E 4E6F20667265652073-     	db	"No free space for a new primary partition", 0Dh, 0Ah, 0
  9900 00006627 7061636520666F7220-
  9900 00006630 61206E657720707269-
  9900 00006639 6D6172792070617274-
  9900 00006642 6974696F6E0D0A00   
  9901                                  msg_c_ldd_error: 
  9902 0000664A 616E64206C6F676963-     	db	"and logical dos drives over program limit (4) !", 0Dh, 0Ah, 0
  9902 00006653 616C20646F73206472-
  9902 0000665C 69766573206F766572-
  9902 00006665 2070726F6772616D20-
  9902 0000666E 6C696D697420283429-
  9902 00006677 20210D0A00         
  9903                                  msg_c_ldd_q:
  9904 0000667C 0D0A                    	db	0Dh, 0Ah
  9905 0000667E 446F20796F75207761-     	db	"Do you want to create logical dos drive in extended dos partition " 
  9905 00006687 6E7420746F20637265-
  9905 00006690 617465206C6F676963-
  9905 00006699 616C20646F73206472-
  9905 000066A2 69766520696E206578-
  9905 000066AB 74656E64656420646F-
  9905 000066B4 732070617274697469-
  9905 000066BD 6F6E20             
  9906 000066C0 3F2028592F4E2900        	db	'? (Y/N)', 0
  9907                                  
  9908                                  msg_c_ldd_nofspc_error:
  9909 000066C8 0D0A                    	db 	0Dh, 0Ah
  9910 000066CA 4E6F20667265652073-     	db	"No free space for a new logical dos drive !", 0Dh, 0Ah, 0
  9910 000066D3 7061636520666F7220-
  9910 000066DC 61206E6577206C6F67-
  9910 000066E5 6963616C20646F7320-
  9910 000066EE 647269766520210D0A-
  9910 000066F7 00                 
  9911                                  
  9912                                  ;pt_positions:
  9913                                  ;n_pos:	 dw	30 ; 1 byte	
  9914                                  ;p_pos:	 dw	7  ; 1 byte	
  9915                                  ;s_pos:	 dw	9  ; 2+1 bytes
  9916                                  ;bh_pos: dw 	13 ; 2+1 bytes
  9917                                  ;bs_pos: dw	17 ; 2+1 bytes
  9918                                  ;bc_pos: dw  	21 ; 2+1 bytes
  9919                                  ;fs_pos: dw 	25 ; 2+1 bytes
  9920                                  ;eh_pos: dw 	29 ; 2+1 bytes
  9921                                  ;es_pos: dw	33 ; 2+1 bytes
  9922                                  ;ec_pos: dw	37 ; 2+1 bytes
  9923                                  ;rs_pos: dw	42 ; 7 bytes
  9924                                  ;ns_pos: dw	52 ; 7 bytes
  9925                                  ;fsx_pos: dw	61 ; 14 bytes
  9926                                  
  9927                                  align 4
  9928                                  
  9929                                  msg_sectors_crlf:
  9930 000066F8 20736563746F72          	db	" sector"
  9931                                  msg_sectors_crlf_s:
  9932 000066FF 73                      	db	"s"
  9933 00006700 0D0A00                  	db	0Dh, 0Ah, 0
  9934                                  
  9935                                  vname_length:
  9936 00006703 00                      	db	0 ; 05/01/2018
  9937                                  
  9938                                  bs_oem_name:
  9939 00006704 5452444F53322E3000      	db	'TRDOS2.0', 0
  9940                                  
  9941 0000670D 90                      align 2
  9942                                  
  9943                                  no_name:
  9944 0000670E 4E4F204E414D452020-     	db 	'NO NAME    ', 0
  9944 00006717 202000             
  9945                                  
  9946                                  align 2
  9947                                  
  9948                                  FDFORMAT_SECBUFFER:
  9949                                  HDFORMAT_SECBUFFER:
  9950 0000671A F6<rept>                	times	512 db 0F6h
  9951                                  HDFORMAT_FSINFO_BUFF:
  9952 0000691A 52526141                	dd	41615252h  ; FSI_LeadSig
  9953 0000691E 00<rept>                	times	480 db 0   ; FSI_Reserved1
  9954 00006AFE 72724161                	dd	61417272h  ; FSI_StrucSig
  9955 00006B02 FFFFFFFF                	dd	0FFFFFFFFh ; FSI_Free_Count
  9956 00006B06 02000000                	dd	000000002h ; FSI_Nxt_Free
  9957 00006B0A 00<rept>                	times	12 db 0	   ; FSI_Reserved2
  9958 00006B16 000055AA                	dd	0AA550000h ; FSI_TrailSig	  		
  9959                                  
  9960                                  ; 29/10/2020
  9961                                  msg_100:
  9962 00006B1A 31303000                	db	'100', 0
  9963                                  
  9964                                  SizeOfFile equ $-100
  9965                                  
  9966                                  ; 03/02/2019
  9967                                  
  9968                                  ;=============================================================================
  9969                                  ;        	uninitialized data
  9970                                  ;=============================================================================
  9971                                  
  9972                                  bss_start:
  9973                                  
  9974                                  ABSOLUTE bss_start
  9975                                  
  9976                                  alignb 2
  9977 00006B1E <res 00000002>          old_sp:		resw 1
  9978                                  
  9979                                  HDFORMAT_FATBUFFER:
  9980                                  FDFORMAT_FATBUFFER:
  9981                                  FDFORMAT_FATBUFFER_S9: ; temporary !
  9982                                  HDFORMAT_EMPTY_BUFF:
  9983 00006B20 <res 00000200>          	resb 512
  9984                                  
  9985 00006D20 <res 00000004>          data_start: resd 1
  9986 00006D24 <res 00000004>          data_sectors: resd 1
  9987 00006D28 <res 00000004>          cluster_count: resd 1
  9988 00006D2C <res 00000002>          root_dir_secs: resw 1
  9989 00006D2E <res 00000002>          format_percent: resw 1
  9990 00006D30 <res 00000001>          prev_percent:	resb 1
  9991 00006D31 <res 00000001>          rsvdbyte:	resb 1
  9992                                  
  9993 00006D32 <res 00000002>          alignb 4
  9994                                  
  9995                                  ; 05/01/2018
  9996 00006D34 <res 00000040>          fs_volume_name: resb 64
  9997 00006D74 <res 00000004>          fs_volume_serial: resd 1
  9998 00006D78 <res 00000002>          DAT_FFBit:	resw 1
  9999 00006D7A <res 00000002>          DAT_FFSector:	resw 1
 10000                                  		;resw 1
 10001 00006D7C <res 00000002>          DAT_LFBit:	resw 1
 10002 00006D7E <res 00000002>          DAT_LFSector:	resw 1
 10003                                  		;resw 1
 10004                                  
 10005                                  ;alignb 4
 10006                                  
 10007                                  FS_MAT_Buffer: ; TRFS1 Master Allocation Table (05/01/2018)
 10008 00006D80 <res 00000003>          MAT_Sign:		resb    3	; Offset 0  ; 'MAT' 
 10009 00006D83 <res 00000001>          MAT_Version:		resb 	1	; 	 3  ; 0	
 10010 00006D84 <res 00000004>          MAT_VolumeSize:		resd	1	;	 4  ; FS1 Volume Size	
 10011 00006D88 <res 00000004>          MAT_BeginSector:	resd	1	;	 8  ; FS1 Start Sector
 10012 00006D8C <res 00000004>          DAT_Address:		resd	1	;	12  ; Offset (=2)	
 10013 00006D90 <res 00000004>          DAT_SectorCount:	resd	1	;	16  
 10014 00006D94 <res 00000004>          MAT_FreeSectors:	resd 	1	; 	20
 10015 00006D98 <res 00000004>          MAT_FirstFreeSector:	resd	1	;	24
 10016                                  ;MAT_OS_Reserved:
 10017                                  ;	 		resb	9
 10018                                  ;MAT_Unused:
 10019                                  ;			resb	112
 10020                                  FS_DAT_Buffer: ; TRFS1 Disk Allocation Table (05/01/2018)
 10021                                  FS_RDT_Buffer: ; TRFS1 Root Directory Description Table (05/01/2018)		 
 10022 00006D9C <res 00000200>          			resb	512		
 10023                                  ;alignb 4
 10024                                  
 10025                                  ; (TR-DOS 386 compatible) Hard Disk (image) parameters
 10026                                  
 10027 00006F9C <res 00000004>          total_sectors: resd 1
 10028 00006FA0 <res 00000004>          pType:	       resb 4 		
 10029 00006FA4 <res 00000004>          file_size:     resd 1
 10030 00006FA8 <res 00000004>          pp_StartSector: resd 1
 10031 00006FAC <res 00000004>          pp_Sectors:	resd 1
 10032 00006FB0 <res 00000001>          wholedisk:	resb 1
 10033 00006FB1 <res 00000001>          pp_type: resb 1 ; Primary partition type (for this program)	
 10034 00006FB2 <res 00000001>          pp_type_user: resb 1
 10035 00006FB3 <res 00000001>          chs_focus: resb 1
 10036 00006FB4 <res 00000004>          pSize_temp: resd 1
 10037 00006FB8 <res 00000004>          pSize_multiplier: resd 1
 10038 00006FBC <res 00000001>          pSize_maxdigits: resb 1
 10039 00006FBD <res 00000001>          pSize_digitpos: resb 1
 10040                                  msg_psize_unit:
 10041 00006FBE <res 00000002>          pSize_unit:	resw 1
 10042 00006FC0 <res 00000001>          		resb 1
 10043 00006FC1 <res 00000003>          reserved_bytes: resb 3 ; for 11 bytes of numbers
 10044                                  msg_partition_sectors:
 10045 00006FC4 <res 00000008>          		resb 8
 10046 00006FCC <res 00000001>          		resb 1
 10047 00006FCD <res 00000001>          format_q:	resb 1 ; 03/02/2018
 10048                                  
 10049                                  ;alignb 2
 10050 00006FCE <res 00000001>          pType_pos:	resb 1
 10051 00006FCF <res 00000001>          pType_num:	resb 1
 10052 00006FD0 <res 00000001>          		resb 1
 10053                                  ;cylinder_boundary:
 10054 00006FD1 <res 00000001>          		resb 1
 10055 00006FD2 <res 00000002>          last_cylinder:	resw 1
 10056                                  
 10057                                  alignb 2
 10058                                  
 10059 00006FD4 <res 00000001>          GetChar:	resb 1 ; 11/02/2019
 10060 00006FD5 <res 00000001>          existingfile:	resb 1 ; 12/02/2019
 10061                                  
 10062 00006FD6 <res 00000002>          min_sectors:	resw 1 ; 08/02/2019
 10063 00006FD8 <res 00000002>          pp_StartCylinder: resw 1
 10064 00006FDA <res 00000002>          pp_EndCylinder:	resw 1
 10065                                  
 10066 00006FDC <res 00000004>          ppn_Sectors:	resd 1 ; 09/02/2019
 10067                                  
 10068 00006FE0 <res 00000002>          input_col:	resw 1
 10069 00006FE2 <res 00000001>          No:		resb 1
 10070 00006FE3 <res 00000001>          Yes:		resb 1
 10071                                  
 10072                                  ; 26/02/2019
 10073 00006FE4 <res 00000001>          ldrives:	resb 1	
 10074                                  
 10075 00006FE5 <res 00000001>          sort_1:		resb 1
 10076 00006FE6 <res 00000004>          sort:		resb 4
 10077                                  
 10078                                  ;max_sector:	resb 8
 10079                                  ebr_buffer:		; 26/02/2019
 10080 00006FEA <res 00000200>          boot_record:	resb 512
 10081                                  
 10082 000071EA <res 00000001>          valid_input:	resb 1
 10083 000071EB <res 00000001>          		resb 1
 10084                                  
 10085                                  ; 26/02/2019
 10086 000071EC <res 00000004>          ep_StartSector:	resd 1
 10087 000071F0 <res 00000004>          ep_EndSector:	resd 1
 10088 000071F4 <res 00000004>          ep_Size:	resd 1
 10089                                  
 10090                                  ; 10/02/2019
 10091 000071F8 <res 00000004>          valid_ppnums:	resb 4	
 10092                                  
 10093 000071FC <res 00000002>          _i_:	resw 1
 10094                                  
 10095 000071FE <res 00000002>          freespace_count: resw 1
 10096 00007200 <res 00000001>          last_found_partition: resb 1
 10097 00007201 <res 00000001>          p_type: resb 1	
 10098                                  
 10099                                  ; 30/10/2020
 10100                                  ;p_sorted:
 10101                                  ;	resb 1
 10102                                  ;ep_sorted:
 10103                                  ;	resb 1
 10104                                  
 10105 00007202 <res 00000001>          _e_:	resb 1
 10106                                  
 10107                                  act_part_num:
 10108                                  cre_part_num:
 10109 00007203 <res 00000001>          del_part_num: resb 1 ; 10/02/2019
 10110                                  
 10111                                  alignb 2
 10112                                  
 10113 00007204 <res 00000050>          pte_row: resb 80
 10114                                  
 10115 00007254 <res 00000001>          _zero_:	resb 1
 10116                                  
 10117                                  ;alignb 2
 10118                                  
 10119 00007255 <res 00000001>          	resb 1
 10120                                  
 10121                                  ; 24/02/2019
 10122                                  goodpte:
 10123 00007256 <res 00000001>          	resb 1
 10124 00007257 <res 00000001>          badpte:	resb 1
 10125                                  
 10126                                  bss_clear_end: ; 15/02/2019
 10127                                  
 10128                                  ; PARTITION DATA STRUCTURE
 10129                                  ; 4 partitions
 10130                                  ; 18 byte partition data structure per partition
 10131                                  ; 72 bytes (4*18)
 10132                                  
 10133 00007258 <res 00000001>          part_table_boot_ind:	 resb 1
 10134 00007259 <res 00000001>          part_table_start_head:	 resb 1
 10135 0000725A <res 00000001>          part_table_start_sector: resb 1
 10136 0000725B <res 00000002>          part_table_start_cyl:	 resw 1
 10137 0000725D <res 00000001>          part_table_sys_id:	 resb 1
 10138 0000725E <res 00000001>          part_table_end_head:	 resb 1
 10139 0000725F <res 00000001>          part_table_end_sector:	 resb 1
 10140 00007260 <res 00000002>          part_table_end_cyl:	 resw 1
 10141 00007262 <res 00000002>          part_table_rel_sec_lw:	 resw 1
 10142 00007264 <res 00000002>          part_table_rel_sec_hw:	 resw 1
 10143 00007266 <res 00000002>          part_table_num_sec_lw:	 resw 1
 10144 00007268 <res 00000002>          part_table_num_sec_hw:	 resw 1
 10145                                  
 10146 0000726A <res 00000036>          			resb 54 ; 3*18 
 10147                                  
 10148 000072A0 <res 00000001>          pcount:		resb 1
 10149 000072A1 <res 00000001>          ppcount:	resb 1
 10150 000072A2 <res 00000001>          apcount:	resb 1 
 10151 000072A3 <res 00000001>          epnumber:	resb 1
 10152                                  
 10153                                  ; LOGICAL PARTITION DATA STRUCTURE
 10154                                  ; (for logical partitions in extended partition)
 10155                                  
 10156                                  ; 1 extended partition
 10157                                  ; 4 logical drives (18 bytes)
 10158                                  ; 72 bytes (4*18)
 10159                                  
 10160 000072A4 <res 00000001>          ext_table_boot_ind:	resb 1
 10161 000072A5 <res 00000001>          ext_table_start_head:	resb 1
 10162 000072A6 <res 00000001>          ext_table_start_sector: resb 1
 10163 000072A7 <res 00000002>          ext_table_start_cyl:	resw 1
 10164 000072A9 <res 00000001>          ext_table_sys_id:	resb 1
 10165 000072AA <res 00000001>          ext_table_end_head:	resb 1
 10166 000072AB <res 00000001>          ext_table_end_sector:	resb 1
 10167 000072AC <res 00000002>          ext_table_end_cyl:	resw 1
 10168 000072AE <res 00000002>          ext_table_rel_sec_lw:	resw 1
 10169 000072B0 <res 00000002>          ext_table_rel_sec_hw:	resw 1
 10170 000072B2 <res 00000002>          ext_table_num_sec_lw:	resw 1
 10171 000072B4 <res 00000002>          ext_table_num_sec_hw:	resw 1
 10172                                  
 10173 000072B6 <res 00000036>          			resb 54 ; 3*18
 10174                                  
 10175                                  fspc:		; 5*8 words (for free space calculations)
 10176                                  
 10177                                  ; Space 1 - unused cylinders before partition 0
 10178                                  ; Space 2 - unused cylinders between partition 0 & 1 
 10179                                  ; Space 3 - unused cylinders between partition 1 & 2 
 10180                                  ; Space 4 - unused cylinders between partition 2 & 3 
 10181                                  ; Space 5 - unused cylinders after partition 3
 10182                                  
 10183 000072EC <res 00000002>          free_space.space:   	   resw 1
 10184 000072EE <res 00000002>          free_space.start:   	   resw 1
 10185 000072F0 <res 00000002>          free_space.end:	   	   resw 1
 10186 000072F2 <res 00000002>          free_space.percent_unused: resw 1
 10187 000072F4 <res 00000004>          free_space.sectors_unused: resd 1
 10188 000072F8 <res 00000004>          free_space.startsector:   resd 1 ; 13/02/2019
 10189                                  		;resw  4*6 
 10190 000072FC <res 00000040>          		resw   4*8 ; 13/02/2019
 10191                                  
 10192                                  ; 18/02/2019
 10193 0000733C <res 00000002>          c_cylinder:	resw 1
 10194 0000733E <res 00000002>          c_fspc_offset:	resw 1
 10195 00007340 <res 00000001>          cylinder_boundary: resb 1
 10196                                  ;c_gap:		resb 1
 10197 00007341 <res 00000001>          		resb 1
 10198                                  
 10199                                  ; 27/02/2019
 10200 00007342 <res 00000010>          ldd_start:	resd 4
 10201                                  ; 03/03/2019
 10202 00007352 <res 00000010>          ldd_size:	resd 4
 10203                                  ; 30/10/2020
 10204 00007362 <res 00000004>          ep_free_sectors: resd 1
 10205                                  
 10206                                  ; 25/02/2019
 10207 00007366 <res 00000002>          pte_address:	resw 1
 10208                                  ; 02/03/2019
 10209 00007368 <res 00000002>          lcylinders:	resw 1
 10210                                  ; 02/11/2020
 10211 0000736A <res 00000002>          endcyl:		resw 1
 10212                                  
 10213                                  ;bss_clear_end: ; 18/02/2019  ; temporary
 10214                                  
 10215                                  bss_end:	 	
