     1                                  ; ****************************************************************************
     2                                  ; FDISK3.ASM (FDISK3.COM) - TRDOS 386 Hard Disk Partitioning Utility
     3                                  ; 						      (for MSDOS/WINDOWS)
     4                                  ; ****************************************************************************
     5                                  ; Last Update: 21/03/2021
     6                                  ; ----------------------------------------------------------------------------
     7                                  ; Beginning: 11/10/2020
     8                                  ; ----------------------------------------------------------------------------
     9                                  ; Assembler: NASM version 2.15
    10                                  ; ----------------------------------------------------------------------------
    11                                  ; Turkish Rational DOS
    12                                  ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
    13                                  ; ----------------------------------------------------------------------------
    14                                  ; Derived from 'hdimage.s' (HDIMAGE.COM) source code by Erdogan Tan
    15                                  ; (03/10/2020)
    16                                  
    17                                  ; Derived from 'fdisk2.s' (FDISK2.COM) source code by Erdogan Tan
    18                                  ; (03/02/2019)
    19                                  ;
    20                                  ; Derived from 'fdimage.s' (FDIMAGE.COM) source code by Erdogan Tan
    21                                  ; (02/12/2017)
    22                                  ;
    23                                  ; Derived from 'fdformat.s' (FDFORMAT.COM) source code by Erdogan Tan
    24                                  ; (29/11/2017)
    25                                  ;
    26                                  ; Derived from 'FSFDISK.ASM' (FSFDISK.COM) source code by Erdogan Tan
    27                                  ; (27/04/2009)
    28                                  ;
    29                                  ; Derived from 'UNIXCOPY.ASM' (UNIXCOPY.COM) source code by Erdogan Tan
    30                                  ; (04/12/2015)
    31                                  ; ****************************************************************************
    32                                  ; nasm fdisk3.s -l fdisk3.lst -o FDISK3.COM -Z error.txt
    33                                  
    34                                  ; Masterboot / Partition Table at Beginning+1BEh
    35                                  ptBootable      equ 0
    36                                  ptBeginHead     equ 1
    37                                  ptBeginSector   equ 2
    38                                  ptBeginCylinder equ 3
    39                                  ptFileSystemID	equ 4
    40                                  ptEndHead       equ 5
    41                                  ptEndSector     equ 6
    42                                  ptEndCylinder   equ 7
    43                                  ptStartSector   equ 8
    44                                  ptSectors       equ 12
    45                                  
    46                                  ; BIOS Disk Parameters
    47                                  DPDiskNumber  equ 0h
    48                                  DPDType       equ 1h
    49                                  DPReturn      equ 2h
    50                                  DPHeads       equ 3h
    51                                  DPCylinders   equ 4h
    52                                  DPSecPerTrack equ 6h
    53                                  DPDisks       equ 7h
    54                                  DPTableOff    equ 8h
    55                                  DPTableSeg    equ 0Ah
    56                                  DPNumOfSecs   equ 0Ch
    57                                  
    58                                  ; BIOS INT 13h Extensions (LBA extensions)
    59                                  ; Just After DP Data (DPDiskNumber+)
    60                                  DAP_PacketSize equ 10h  ; If extensions present, this byte will be >=10h
    61                                  DAP_Reserved1 equ 11h   ; Reserved Byte 
    62                                  DAP_NumOfBlocks equ 12h ; Value of this byte must be 0 to 127
    63                                  DAP_Reserved2 equ 13h   ; Reserved Byte
    64                                  DAP_Destination equ 14h ; Address of Transfer Buffer as SEGMENT:OFFSET
    65                                  DAP_LBA_Address equ 18h ; LBA=(C1*H0+H1)*S0+S1-1
    66                                                          ; C1= Selected Cylinder Number
    67                                                          ; H0= Number Of Heads (Maximum Head Number + 1)
    68                                                          ; H1= Selected Head Number
    69                                                          ; S0= Maximum Sector Number
    70                                                          ; S1= Selected Sector Number
    71                                                          ; QUAD WORD
    72                                  ; DAP_Flat_Destination equ 20h ; 64 bit address, if value in 4h is FFFF:FFFFh
    73                                                               ; QUAD WORD (Also, value in 0h must be 18h) 
    74                                                               ; TR-DOS will not use 64 bit Flat Address
    75                                  
    76                                  ; INT 13h Function 48h "Get Enhanced Disk Drive Parameters"
    77                                  ; Just After DP Data (DPDiskNumber+)
    78                                  GetDParams_48h equ 20h ; Word. Data Lenght, must be 26 (1Ah) for short data.
    79                                  GDP_48h_InfoFlag equ 22h ; Word
    80                                  ; Bit 1 = 1 -> The geometry returned in bytes 4-15 is valid.
    81                                  GDP_48h_NumOfPCyls equ 24h ; Double Word. Number physical cylinders.
    82                                  GDP_48h_NumOfPHeads equ 28h ; Double Word. Number of physical heads.
    83                                  GDP_48h_NumOfPSpT equ 2Ch ; Double word. Num of physical sectors per track.
    84                                  GDP_48h_LBA_Sectors equ 30h ; 8 bytes. Number of physical/LBA sectors.
    85                                  GDP_48h_BytesPerSec equ 38h ; Word. Number of bytes in a sector.
    86                                  
    87                                  pTableOffset equ 1BEh ; 446
    88                                  
    89                                  	; Convert LBA to CHS
    90                                  	; 08/02/2019
    91                                  
    92                                  	; LBA = ((C1*H0+H1)*S0)+S1-1
    93                                  	;
    94                                  	; C1 = Selected Cylinder Number
    95                                  	; H0 = Number of Heads (Maximum Head Number + 1)
    96                                  	; H1 = Selected Head Number
    97                                  	; S0 = Maximum Sector Number
    98                                  	; S1 = Selected Sector Number
    99                                  	;
   100                                  	; Phoenix, Enchanced Disk Drive Specicifications, v1.1, Page 8)
   101                                  		
   102                                  
   103                                  [BITS 16]
   104                                  [ORG 100h]
   105                                  
   106                                  	;cli
   107                                  	;cld
   108                                  	;push	cs
   109                                  	;pop	ss
   110                                  	;mov	sp, 0FFFEh
   111                                  	;sti
   112                                  	
   113                                  	;mov	bx, SizeOfFile+100
   114                                  	
   115 00000000 BB[4871]                	mov	bx, bss_end
   116                                  
   117 00000003 83C30F                          add	bx, 15
   118 00000006 D1EB                            shr	bx, 1
   119 00000008 D1EB                            shr	bx, 1
   120 0000000A D1EB                    	shr	bx, 1
   121 0000000C D1EB                    	shr	bx, 1
   122 0000000E B44A                            mov	ah, 4Ah ; modify memory allocation
   123                                          ;push	cs
   124                                          ;pop	es
   125 00000010 CD21                            int	21h
   126                                  
   127                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   128                                  ; clear BSS
   129                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   130                                  ; 03/02/2019
   131                                  
   132                                  	;mov	cx, bss_end
   133 00000012 B9[1870]                	mov	cx, bss_clear_end ; 15/02/2019
   134                                  
   135 00000015 BF[D668]                	mov	di, bss_start
   136 00000018 29F9                    	sub	cx, di
   137 0000001A 41                      	inc	cx
   138 0000001B D1E9                    	shr	cx, 1
   139 0000001D 31C0                    	xor	ax, ax
   140 0000001F F3AB                    	rep	stosw 
   141                                  
   142                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   143                                  ; display program name & version
   144                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   145                                  
   146 00000021 BE[7243]                	mov	si, TrDOS_Welcome
   147 00000024 E85B1B                  	call	print_msg
   148                                  
   149                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   150                                  ; get hard disk name
   151                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   152                                  ; 11/10/2020
   153                                  
   154 00000027 BE8000                  	mov	si, 80h			; PSP command tail
   155 0000002A AC                       	lodsb
   156 0000002B 08C0                    	or	al, al 			; command tail length                            
   157 0000002D 7431                    	jz	short A_05			; jump if zero
   158                                  A_01:
   159 0000002F AC                      	lodsb
   160 00000030 3C20                    	cmp	al, ' '			; is it SPACE ?
   161 00000032 74FB                    	je	short A_01 		
   162 00000034 722A                    	jb	short A_05
   163                                  	
   164                                  	; check disk name
   165                                  
   166 00000036 3C68                    	cmp	al, 'h'
   167 00000038 751B                    	jne	short A_03	
   168 0000003A 803C64                  	cmp	byte [si], 'd'
   169 0000003D 7516                    	jne	short A_03
   170 0000003F 46                      	inc	si
   171 00000040 AC                      	lodsb
   172 00000041 3C30                    	cmp	al, '0'
   173 00000043 7406                    	je	short A_02
   174 00000045 720E                    	jb	short A_03
   175 00000047 3C33                    	cmp	al, '3'
   176 00000049 770A                    	ja	short A_03
   177                                  A_02:
   178 0000004B 803C20                  	cmp	byte [si], ' '
   179 0000004E 720B                    	jb	short A_04
   180 00000050 7703                    	ja	short A_03
   181 00000052 46                      	inc	si
   182 00000053 EBF6                    	jmp	short A_02
   183                                  A_03:
   184 00000055 BE[C543]                	mov	si, TrDOS_Usage
   185 00000058 E94F07                  	jmp	_p_exit
   186                                  A_04:
   187 0000005B 0450                    	add	al, 80h - '0'
   188 0000005D A2[D668]                	mov	[DrvNum], al	; 80h .. 83h
   189                                  
   190                                  A_05:
   191                                  
   192                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   193                                  ; get hard disk parameters 
   194                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   195                                  ; 11/10/2020
   196                                  
   197                                  	; check bios int 13h extensions
   198 00000060 B441                    	mov	ah, 41h
   199 00000062 BBAA55                  	mov	bx, 55AAh
   200 00000065 B280                    	mov	dl, 80h
   201 00000067 CD13                    	int	13h
   202 00000069 720B                    	jc	short A_06
   203 0000006B 81FB55AA                	cmp	bx, 0AA55h
   204 0000006F 7505                    	jne	short A_06
   205                                  
   206 00000071 C606[5A31]01            	mov	byte [int13h_x], 1
   207                                  A_06:
   208                                  	;mov	dl, 80h	 ; hd0
   209 00000076 B408                    	mov	ah, 08h  ; return disk parameters
   210 00000078 CD13                    	int	13h	
   211 0000007A 7313                    	jnc	short A_10
   212                                  A_07:
   213 0000007C 803E[D668]80            	cmp 	byte [DrvNum], 80h  ; hard disk name option ?
   214 00000081 7206                    	jb	short A_09 ; no, default	
   215                                  A_08:
   216 00000083 BE[5E64]                	mov	si, msg_drv_not_ready ; drive not ready
   217 00000086 E92107                  	jmp	_p_exit
   218                                  A_09:
   219 00000089 BE[8864]                	mov	si, msg_not_any_disks ; there is not a hard disk
   220 0000008C E91B07                  	jmp	_p_exit
   221                                  A_10:
   222 0000008F 08E4                    	or	ah, ah	 ; ah = 0 ?	
   223 00000091 75E9                    	jnz	short A_07  ; no, there is an error !
   224                                  	
   225 00000093 8816[D768]              	mov	[hdc], dl ; number of hard disks
   226                                  
   227 00000097 A0[D668]                	mov	al, [DrvNum]
   228                                  
   229 0000009A 3C80                    	cmp	al, 80h
   230 0000009C 7308                    	jnb	short A_11 ; option
   231                                  	; default
   232 0000009E C606[D668]80            	mov	byte [DrvNum], 80h
   233 000000A3 E98F00                  	jmp	A_14
   234                                  A_11:
   235                                  	; hard disk name option
   236 000000A6 80C27F                  	add	dl, 7Fh
   237                                  
   238 000000A9 38D0                    	cmp	al, dl
   239 000000AB 77D6                    	ja	short A_08
   240                                  
   241 000000AD 80FA80                  	cmp	dl, 80h
   242 000000B0 760C                    	jna	short A_13 ; hd0 parameters are ready 
   243                                  A_12:
   244 000000B2 88C2                    	mov	dl, al ; [DrvNum]
   245                                  
   246 000000B4 B408                    	mov	ah, 08h  ; return (get) disk parameters
   247 000000B6 CD13                    	int	13h	
   248 000000B8 72C2                    	jc	short A_07
   249 000000BA 08E4                    	or	ah, ah
   250 000000BC 75BE                    	jnz	short A_07
   251                                  A_13:
   252 000000BE 88C8                    	mov	al, cl
   253 000000C0 243F                    	and	al, 3Fh ; 63
   254 000000C2 C0E906                  	shr	cl, 6
   255 000000C5 86E9                    	xchg	ch, cl
   256 000000C7 41                      	inc	cx
   257 000000C8 41                      	inc	cx ; 15/10/2020 ; BIOS BugFix 
   258                                  				; (for reserved last cylinder)
   259 000000C9 890E[723F]              	mov	[cylinders], cx
   260                                  	;mov	word [cylinders+2], 0 ; 16/10/2020
   261 000000CD FEC6                    	inc	dh
   262 000000CF 8836[703F]              	mov	[heads], dh	
   263 000000D3 A2[6E3F]                	mov	[sectors], al
   264 000000D6 F6E6                    	mul	dh
   265 000000D8 A3[986D]                	mov	[hs], ax ; heads*sectors ; 15/10/2020
   266 000000DB F7E1                    	mul	cx
   267 000000DD A3[DA68]                	mov	[disksize], ax
   268 000000E0 8916[DC68]              	mov	[disksize+2], dx
   269 000000E4 83E801                  	sub	ax, 1	; 17/10/2020
   270 000000E7 83DA00                  	sbb	dx, 0
   271 000000EA A3[DE68]                	mov	[chs_limit], ax	
   272 000000ED 8916[E068]              	mov	[chs_limit+2], dx
   273                                  
   274 000000F1 803E[5A31]01            	cmp	byte [int13h_x], 1
   275 000000F6 0F82D700                	jb	A_20
   276                                  
   277 000000FA BE[2C71]                	mov	si, gdp_buffer
   278                                  	;mov	word [si], 30 ; buffer length (minimum)
   279 000000FD C7041A00                	mov	word [si], 26 ; buffer length (minimum)
   280 00000101 B448                    	mov	ah, 48h
   281 00000103 8A16[D668]              	mov	dl, [DrvNum]
   282 00000107 CD13                    	int	13h
   283 00000109 0F82C400                	jc	A_20
   284 0000010D 20E4                    	and	ah, ah
   285 0000010F 0F85BE00                	jnz	A_20
   286                                  
   287                                  	; number of physical sectors
   288 00000113 8B4410                  	mov	ax, [si+16]
   289 00000116 8B5412                  	mov	dx, [si+18]
   290 00000119 A3[DA68]                	mov	[disksize], ax
   291 0000011C 8916[DC68]              	mov	[disksize+2], dx
   292                                  
   293                                  	; 15/10/2020
   294 00000120 8B0E[986D]              	mov	cx, [hs]
   295 00000124 E8560B                  	call	div32
   296                                  	; 16/10/2020
   297                                  	;mov	[lba_cyls], ax
   298                                  	;mov	[lba_cyls+2], dx
   299 00000127 A3[723F]                	mov	[cylinders], ax
   300 0000012A 8916[743F]              	mov	[cylinders+2], dx
   301 0000012E 891E[E268]              	mov	[lba_chs_remain], bx	
   302                                  
   303 00000132 E99C00                  	jmp	A_20	
   304                                  A_14:
   305 00000135 80FA01                  	cmp	dl, 1
   306 00000138 7684                    	jna	short A_13 ; [DrvNum] = 80h
   307                                  
   308 0000013A 80C230                  	add	dl, '0' ; '2' to '4'
   309 0000013D 8816[8844]              	mov	byte [TrDOS_dnmax], dl
   310                                  
   311 00000141 BE[6A44]                	mov	si, TrDOS_Options
   312 00000144 E83B1A                  	call	print_msg
   313                                  
   314                                  	; check bios int 13h extensions
   315 00000147 803E[5A31]01            	cmp	byte [int13h_x], 1
   316 0000014C 732D                    	jnb	short A_16
   317                                  A_15:
   318 0000014E 8A16[D668]              	mov	dl, [DrvNum]
   319 00000152 B408                    	mov	ah, 08h  ; return disk parameters
   320 00000154 CD13                    	int	13h	
   321 00000156 724D                    	jc	short A_17
   322 00000158 08E4                    	or	ah, ah
   323 0000015A 7549                    	jnz	short A_17
   324                                  
   325 0000015C 88C8                    	mov	al, cl
   326 0000015E 243F                    	and	al, 3Fh ; 63
   327 00000160 C0E906                  	shr	cl, 6
   328 00000163 86E9                    	xchg	ch, cl
   329 00000165 41                      	inc	cx
   330 00000166 FEC6                    	inc	dh
   331 00000168 F6E6                    	mul	dh
   332 0000016A F7E1                    	mul	cx
   333                                  
   334                                  	; dx:ax = disk size
   335                                  
   336 0000016C E89D02                  	call	display_hd_row	
   337                                  
   338 0000016F FE0E[D768]              	dec	byte [hdc]
   339 00000173 7430                    	jz	short A_17
   340 00000175 FE06[D668]              	inc	byte [DrvNum]
   341 00000179 EBD3                    	jmp	short A_15
   342                                  A_16:
   343 0000017B BE[2C71]                	mov	si, gdp_buffer
   344                                  	;mov	word [si], 30 ; buffer length (minimum)
   345 0000017E C7041A00                	mov	word [si], 26 ; buffer length (minimum)
   346 00000182 B448                    	mov	ah, 48h
   347 00000184 8A16[D668]              	mov	dl, [DrvNum]
   348 00000188 CD13                    	int	13h
   349 0000018A 72C2                    	jc	short A_15
   350 0000018C 20E4                    	and	ah, ah
   351 0000018E 75BE                    	jnz	short A_15
   352                                  
   353                                  	; number of phsical sectors
   354 00000190 8B4410                  	mov	ax, [si+16]
   355 00000193 8B5412                  	mov	dx, [si+18]
   356                                  
   357                                  	; dx:ax = disk size
   358                                  
   359 00000196 E87302                  	call	display_hd_row	
   360                                  
   361 00000199 FE0E[D768]              	dec	byte [hdc]
   362 0000019D 7406                    	jz	short A_17
   363 0000019F FE06[D668]              	inc	byte [DrvNum]
   364 000001A3 EBD6                    	jmp	short A_16
   365                                  A_17:
   366 000001A5 BE[5F55]                	mov	si, CRLF
   367 000001A8 E8D719                  	call	print_msg
   368                                  
   369                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   370                                  ; hard disk number input (getchar)
   371                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   372                                  ; 11/10/2020
   373                                  	
   374                                  A_18:
   375 000001AB 31C0                    	xor	ax, ax
   376 000001AD CD16                    	int	16h			; wait for keyboard command
   377                                  
   378 000001AF 83F800                  	cmp	ax, 0			; CTRL+BREAK
   379 000001B2 761A                    	jna	short A_19
   380                                  
   381 000001B4 3C03                    	cmp	al, 'C'-40h		; 3
   382 000001B6 7416                    	je	short A_19             	; CTRL+C
   383 000001B8 3C1B                    	cmp	al, 27			; ESCape
   384 000001BA 7412                    	je	short A_19
   385                                  
   386 000001BC 3C31                    	cmp	al, '1'			; "(1) hd0" 
   387 000001BE 72EB                    	jb	short A_18		; retry
   388 000001C0 3A06[8844]              	cmp	al, [TrDOS_dnmax]	; ('2' to '4')	
   389 000001C4 77E5                    	ja	short A_18		; retry
   390 000001C6 044F                    	add	al, 80h-'1'		; bios disk num (80h-83h)
   391 000001C8 A2[D668]                	mov	[DrvNum], al
   392 000001CB E9E4FE                  	jmp	A_12			; get disk parameters
   393                                  A_19:
   394 000001CE E9DC05                  	jmp	_exit			; Exit
   395                                  
   396                                  A_20:
   397                                  
   398                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   399                                  ; read masterboot sector
   400                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   401                                  ; 12/10/2020
   402                                  
   403 000001D1 BB[DA55]                	mov	bx, MasterBootBuff
   404 000001D4 B90100                  	mov	cx, 1	; cylinder = 0
   405                                  			; sector = 1
   406 000001D7 B600                    	mov	dh, 0	; head = 0
   407 000001D9 8A16[D668]              	mov	dl, [DrvNum]
   408 000001DD B80102                  	mov	ax, 0201h ; read one sector
   409 000001E0 CD13                    	int	13h
   410 000001E2 7306                    	jnc	short A_21
   411                                  
   412 000001E4 BE[5E64]                	mov	si, msg_drv_not_ready ; drive not ready
   413 000001E7 E98700                  	jmp	A_26
   414                                  A_21:
   415                                  
   416                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   417                                  ; display CHS values and disk size (LBA) and partition table
   418                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   419                                  ; 12/10/2020
   420                                  
   421 000001EA B80300                  	mov	ax, 3  ; clear screen
   422 000001ED CD10                    	int	10h
   423                                  
   424 000001EF E80321                  	call	init_partition_table ; 13/10/2020
   425                                  
   426 000001F2 E80C1B                  	call	display_chs_table
   427                                  
   428 000001F5 A1[DA68]                	mov	ax, [disksize]
   429 000001F8 8B16[DC68]              	mov	dx, [disksize+2]
   430                                  
   431 000001FC 81FA0001                	cmp	dx, 256 ; >= 8GB  
   432 00000200 7315                    	jnb	short A_22
   433                                  
   434                                  	;mov	cx, 2048 ; /2048 (2048 sectors = 1 MB)	
   435                                  	;div	cx
   436                                  
   437                                  	; shift dx:ax to 8 bits right (/256)  
   438 00000202 88E0                    	mov	al, ah
   439 00000204 88D4                    	mov	ah, dl
   440 00000206 C1E803                  	shr	ax, 3 ; /8 
   441                                  		; result = (dx:ax)/2048
   442                                  
   443                                  	; ax =  0 to 8191
   444                                  
   445 00000209 C606[BE44]4D            	mov	byte [TrDOS_hdrow_unit], 'M'
   446 0000020E EB11                    	jmp	short A_23
   447                                  
   448                                  
   449                                  A_29:	; 16/10/2020
   450 00000210 E88E27                  	call	partition_table_fix
   451 00000213 73D5                    	jnc	short A_21
   452                                  
   453 00000215 CD20                    	int	20h
   454                                  ;here:	
   455                                  	;jmp	short here
   456                                  
   457                                  A_22:
   458                                  	; 1024 MB = 1GB (2097152 sectors)
   459                                  	; DX/32 --> GB 
   460 00000217 89D0                    	mov	ax, dx
   461 00000219 C1E805                  	shr	ax, 5 ; /32
   462                                  
   463                                  	; ax = 8 to 2047
   464 0000021C C606[BE44]47            	mov	byte [TrDOS_hdrow_unit], 'G'
   465                                  A_23:
   466                                  	;xor	dx, dx
   467 00000221 BE[C444]                	mov	si, TrDOS_hdrow_capacity	
   468 00000224 E82402                  	call	convert_to_decimal
   469                                  
   470 00000227 BE[CB44]                	mov	si, TrDOS_disksize
   471 0000022A E85519                  	call	print_msg
   472                                  
   473 0000022D BE[C444]                	mov	si, TrDOS_hdrow_capacity
   474 00000230 E84F19                  	call	print_msg
   475                                  
   476 00000233 BE[BE44]                	mov	si, TrDOS_hdrow_unit
   477 00000236 E84919                  	call	print_msg
   478                                  
   479                                  	; 16/10/2020
   480                                  	;cmp	word [lba_cyls+2], 0
   481 00000239 833E[743F]00            	cmp	word [cylinders+2], 0
   482 0000023E 7736                    	ja	short A_27  ; Huge disk ! number of (lba) cylinders > 65335
   483                                  			    ; Current FDISK version (v3) can not be used !	
   484                                  
   485 00000240 BE[5F55]                	mov	si, CRLF
   486 00000243 E83C19                  	call	print_msg
   487                                  
   488 00000246 E8AA25                  	call	dpt_1
   489                                  
   490 00000249 BE[5F55]                	mov	si, CRLF
   491 0000024C E83319                  	call	print_msg
   492                                  
   493                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   494                                  ; display edit or exit option, getchar
   495                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   496                                  
   497 0000024F BE[8E53]                	mov	si, msg_edit_or_exit
   498 00000252 E82D19                  	call	print_msg
   499                                  A_24:
   500 00000255 30E4                    	xor	ah, ah
   501 00000257 CD16                    	int	16h
   502                                  
   503 00000259 3C0D                    	cmp	al, 13 ; CR (ENTER) key
   504 0000025B 744A                    	je	short A_28 
   505                                  
   506 0000025D 3C1B                    	cmp	al, 27 ; ESCape key
   507 0000025F 740D                    	je	short A_25
   508                                  
   509 00000261 3C20                    	cmp	al, 32 ; SPACE key
   510 00000263 7442                    	je	short A_28
   511                                  
   512 00000265 3C03                    	cmp	al, 3 ; CTRL+C
   513 00000267 7405                    	je	short A_25
   514                                  
   515 00000269 83F800                  	cmp	ax, 0 ; CTRL+BREAK
   516 0000026C 77E7                    	ja	short A_24
   517                                  A_25:
   518 0000026E BE[5F55]                	mov	si, CRLF
   519                                  A_26:
   520 00000271 E80E19                  	call	print_msg
   521                                  
   522 00000274 CD20                    	int	20h
   523                                  ;here:
   524                                  ;	jmp	short here
   525                                  
   526                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   527                                  ; display fdisk program disk capacity limit message and then exit
   528                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   529                                  
   530                                  A_27:
   531                                  	; 16/10/2020
   532                                  	; 15/10/2020
   533                                  	; Display FDISK (v3) capacity limit (error) message
   534                                  
   535 00000276 B8FFFF                  	mov	ax, 65535
   536 00000279 F726[986D]              	mul	word [hs]
   537                                  		; 1024 MB = 1GB (2097152 sectors)
   538                                  	; DX/32 --> GB 
   539 0000027D 89D0                    	mov	ax, dx
   540 0000027F C1E805                  	shr	ax, 5 ; /32
   541                                  
   542                                  	; ax = 8 to 2047
   543 00000282 C606[BE44]47            	mov	byte [TrDOS_hdrow_unit], 'G'
   544                                  	;mov	byte [TrDOS_hdrow_unit+1], 'B'
   545 00000287 C606[C044]2E            	mov	byte [TrDOS_hdrow_unit+2], '.'
   546                                  
   547                                  	;xor	dx, dx
   548 0000028C BE[C444]                	mov	si, TrDOS_hdrow_capacity	
   549 0000028F E8B901                  	call	convert_to_decimal
   550                                  
   551 00000292 BE[DA44]                	mov	si, msg_fdisk_capacity_err
   552 00000295 E8EA18                  	call 	print_msg
   553                                  
   554 00000298 BE[C444]                	mov	si, TrDOS_hdrow_capacity
   555 0000029B E8E418                  	call	print_msg
   556                                  
   557 0000029E BE[BE44]                	mov	si, TrDOS_hdrow_unit
   558 000002A1 E8DE18                  	call	print_msg
   559                                  	
   560 000002A4 E90605                  	jmp	_exit
   561                                  
   562                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   563                                  ; check defective pte and then init extended partition table(s)
   564                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   565                                  
   566                                  A_28:
   567 000002A7 E8BE01                  	call	check_defective_partition
   568 000002AA 0F8262FF                	jc	A_29 ; ds:si -> defective pte
   569                                  
   570                                  	; 17/10/2020
   571                                  	; 26/02/2019
   572 000002AE 803E[6370]00            	cmp	byte [epnumber], 0
   573 000002B3 7603                    	jna	short A_30
   574                                  
   575 000002B5 E8F92C                  	call	init_ext_partition_table
   576                                  A_30:
   577                                  	; 17/10/2020
   578                                  	; 04/02/2019
   579                                  	;xor	al, al  ; MBR/PRIMARY PARTITIONS
   580 000002B8 E82025                  	call	display_partition_table ; 12/03/2021
   581                                  
   582                                  	; 17/10/2020
   583 000002BB 803E[6070]00            	cmp	byte [pcount], 0
   584 000002C0 0F86F000                	jna	A_38 ; empty partition table
   585                                  
   586                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   587                                  ; check CHS parms against start sector address and partition size 
   588                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   589                                  
   590                                  A_31:
   591                                  	; Check disk parameters with current CHS settings
   592 000002C4 31DB                    	xor	bx, bx
   593 000002C6 31C9                    	xor	cx, cx
   594                                  A_32:
   595                                  	; 17/10/2020
   596 000002C8 80BF[1D70]00            	cmp	byte [part_table_sys_id+bx], 0
   597 000002CD 767C                    	jna	short A_33
   598                                  
   599                                  	; 27/10/2020
   600                                  	;mov	ax, [sectors]
   601                                  	;mul	word [heads]
   602                                  	; dx = 0, ax = heads*sectors
   603                                  
   604 000002CF 8B97[1B70]              	mov	dx, [part_table_start_cyl+bx]
   605                                  	; 27/10/2020
   606 000002D3 81FAFF03                	cmp	dx, 1023 ; fixed cylinder number (> 1023)
   607                                  			 ; (partition's start sector is used for fixing)
   608 000002D7 7772                    	ja	short A_33 ; no need to check CHS parms here
   609                                  			; (also, CHS to LBA calculation is not applicable)
   610 000002D9 A1[986D]                	mov	ax, [hs] ; heads*sectors
   611                                  
   612 000002DC F7E2                    	mul	dx
   613                                  		; dx:ax = cylinder*heads*spt
   614 000002DE 89C6                    	mov	si, ax
   615 000002E0 89D7                    	mov	di, dx
   616 000002E2 8A87[1970]              	mov	al, [part_table_start_head+bx]
   617 000002E6 F626[6E3F]              	mul	byte [sectors]
   618 000002EA 01C6                    	add	si, ax
   619 000002EC 83D700                  	adc	di, 0
   620                                  		; di:si = (cylinder*heads*spt) + head*spt
   621 000002EF 8A87[1A70]              	mov	al, [part_table_start_sector+bx]
   622 000002F3 30E4                    	xor	ah, ah
   623 000002F5 FEC8                    	dec	al ; 1 -> 0
   624 000002F7 01C6                    	add	si, ax
   625 000002F9 83D700                  	adc	di, 0
   626                                  		; di:si = (cylinder*heads*spt) + head*spt + sector - 1
   627                                  		; (start sector as converted to LBA)
   628                                  
   629 000002FC 3BBF[2470]              	cmp	di, [part_table_rel_sec_hw+bx]
   630 00000300 7556                    	jne	short A_34 ; Invalid !
   631                                  
   632 00000302 3BB7[2270]              	cmp	si, [part_table_rel_sec_lw+bx]
   633 00000306 7550                    	jne	short A_34 ; Invalid !
   634                                  		; di:si = partition's start sector (LBA)
   635                                  
   636                                  	; 27/10/2020
   637                                  	;mov	ax, [sectors]
   638                                  	;mul	word [heads]
   639                                  	; dx = 0, ax = heads*sectors
   640                                  
   641 00000308 8B97[2070]              	mov	dx, [part_table_end_cyl+bx]
   642                                  
   643                                  	; 27/10/2020
   644 0000030C 81FAFF03                	cmp	dx, 1023 ; fixed cylinder number (> 1023)
   645                                  			 ; (partition's end sector is used for fixing)
   646 00000310 7739                    	ja	short A_33 ; no need to check CHS parms here
   647                                  			; (also, CHS to LBA calculation is not applicable)
   648 00000312 A1[986D]                	mov	ax, [hs] ; heads*sectors
   649                                  
   650 00000315 F7E2                    	mul	dx
   651                                  		; dx:ax = cylinder*heads*spt
   652 00000317 89C6                    	mov	si, ax
   653 00000319 89D7                    	mov	di, dx
   654 0000031B 8A87[1E70]              	mov	al, [part_table_end_head+bx]
   655 0000031F F626[6E3F]              	mul	byte [sectors]
   656 00000323 01C6                    	add	si, ax
   657 00000325 83D700                  	adc	di, 0
   658                                  		; di:si = (cylinder*heads*spt) + head*spt
   659 00000328 8A87[1F70]              	mov	al, [part_table_end_sector+bx]
   660 0000032C 30E4                    	xor	ah, ah
   661                                  	;dec	al ; 63 -> 62
   662 0000032E 01C6                    	add	si, ax
   663 00000330 83D700                  	adc	di, 0
   664                                  		; di:si = (cylinder*heads*spt) + head*spt + sector
   665                                  		; (end sector + 1 as converted to LBA)
   666 00000333 8B87[2670]              	mov	ax, [part_table_num_sec_lw+bx]
   667 00000337 8B97[2870]              	mov	dx, [part_table_num_sec_hw+bx]
   668                                  	
   669 0000033B 0387[2270]              	add	ax, [part_table_rel_sec_lw+bx]
   670 0000033F 1397[2470]              	adc	dx, [part_table_rel_sec_hw+bx]
   671                                  		; dx:ax = partition's end sector (LBA) + 1
   672                                  
   673 00000343 39F0                    	cmp	ax, si
   674 00000345 7511                    	jne	short A_34 ; Invalid !
   675                                  
   676 00000347 39FA                    	cmp	dx, di
   677 00000349 750D                    	jne	short A_34 ; Invalid !
   678                                  A_33:
   679 0000034B FEC1                    	inc	cl
   680                                  
   681 0000034D 80F904                  	cmp	cl, 4
   682 00000350 730E                    	jnb	short A_35
   683                                  
   684 00000352 83C312                  	add	bx, 18  ; partition table structure size
   685                                  	
   686 00000355 E970FF                  	jmp	A_32
   687                                  A_34:
   688 00000358 BE[975F]                	mov	si, msg_defective_pt
   689 0000035B E82418                  	call	print_msg
   690 0000035E EB54                    	jmp	short A_38
   691                                  
   692                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   693                                  ; sort MBR partitions
   694                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   695                                  
   696                                  A_35:
   697                                  	; LBA and CHS values of all partitions are OK (here)
   698                                  
   699                                  	; sort MBR (primary) partitions
   700                                  
   701 00000360 E86321                  	call	sort_partition_table
   702                                  
   703                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   704                                  ; Check partition (start, size) overlaps after sorting 
   705                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   706                                  
   707                                  	; Checking partition overlaps (via start and end cylinders)
   708                                  
   709 00000363 31DB                    	xor	bx, bx
   710 00000365 BA1200                  	mov	dx, 18
   711                                  A_36:
   712 00000368 FEC3                    	inc	bl
   713                                  
   714 0000036A 8A87[A86D]              	mov	al, [bx+sort]
   715 0000036E F6E2                    	mul	dl
   716 00000370 89C6                    	mov	si, ax	; current
   717                                  
   718 00000372 80BC[1D70]00            	cmp	byte [part_table_sys_id+si], 0
   719 00000377 7636                    	jna	short A_37
   720                                  
   721 00000379 8A87[A76D]              	mov	al, [bx+sort-1]
   722 0000037D F6E2                    	mul	dl
   723 0000037F 89C7                    	mov	di, ax  ; previous
   724                                  
   725 00000381 8B85[2070]              	mov	ax, [part_table_end_cyl+di]
   726 00000385 3B84[1B70]              	cmp	ax, [part_table_start_cyl+si]
   727 00000389 7224                    	jb	short A_37
   728                                  	; 29/10/2020
   729 0000038B 77CB                    	ja	short A_34 ; overlap !
   730                                  
   731                                  	; 17/10/2020
   732                                  	;and	ax, ax
   733                                  	;jnz	short A_34 ; overlap error (except empty entries)
   734                                  
   735                                  	; 29/10/2020
   736                                  	; same cylinder
   737                                  	; check end-start sectors for overlap
   738                                  
   739 0000038D 21C0                    	and	ax, ax
   740 0000038F 741E                    	jz	short A_37 ; empty pt entries
   741                                  			; (previous pte is empty)
   742                                  
   743 00000391 8B85[2270]              	mov	ax, [part_table_rel_sec_lw+di] ; previous
   744 00000395 8B95[2470]              	mov	dx, [part_table_rel_sec_hw+di]
   745 00000399 0385[2670]              	add	ax, [part_table_num_sec_lw+di]
   746 0000039D 1395[2870]              	adc	dx, [part_table_num_sec_hw+di]
   747                                  	;jc	short A_34
   748                                  		 ; dx:ax = end sector + 1
   749 000003A1 3B94[2470]              	cmp	dx, [part_table_rel_sec_hw+si] ; current
   750 000003A5 7208                    	jb	short A_37
   751 000003A7 77AF                    	ja	short A_34 ; overlap error !	
   752 000003A9 3B84[2270]              	cmp	ax, [part_table_rel_sec_lw+si]
   753 000003AD 73A9                    	jnb	short A_34 ; overlap error ! 	
   754                                  A_37:
   755 000003AF 80FB03                  	cmp	bl, 3
   756 000003B2 72B4                    	jb	short A_36
   757                                  
   758                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   759                                  ; display partition table editing options
   760                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   761                                  
   762                                  A_38:
   763 000003B4 BE[C859]                	mov	si, mbr_editing_options
   764 000003B7 E8C817                  	call	print_msg
   765                                  
   766 000003BA BE[765A]                	mov	si, enter_option_number_msg
   767 000003BD E8C217                  	call	print_msg
   768                                  
   769 000003C0 803E[A66D]00            	cmp	byte [ldrives], 0
   770 000003C5 760C                    	jna	short A_39
   771                                  
   772 000003C7 BE[5F55]                	mov	si, CRLF
   773 000003CA E8B517                  	call	print_msg
   774                                  
   775 000003CD BE[DF60]                	mov	si, str_display_ebr_pt
   776 000003D0 E8AF17                  	call	print_msg
   777                                  A_39:	
   778                                  	;mov	si, CRLF
   779                                  	;call	print_msg
   780                                  
   781                                  A_40:
   782 000003D3 30E4                    	xor	ah, ah
   783 000003D5 CD16                    	int	16h
   784                                  
   785 000003D7 3C30                    	cmp	al, '0'
   786 000003D9 742A                    	je	short A_41
   787                                  
   788 000003DB 3C31                    	cmp	al, '1'
   789 000003DD 0F84A600                	je	create_partition	
   790 000003E1 3C32                    	cmp	al, '2'
   791 000003E3 0F843701                	je	activate_partition
   792 000003E7 3C33                    	cmp	al, '3'
   793 000003E9 0F84D001                	je	delete_partition
   794 000003ED 3C34                    	cmp	al, '4'
   795 000003EF 0F84D302                	je	write_pt_mbr
   796                                  	
   797 000003F3 3C1B                    	cmp	al, 27 ; ESCape
   798 000003F5 740E                    	je	short A_41
   799                                  
   800                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   801                                  ; display (EPT) logical drives/partitions if 'SPACE' is pressed
   802                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   803                                  
   804                                  	; 28/02/2019
   805 000003F7 803E[A66D]00            	cmp	byte [ldrives], 0
   806 000003FC 76D5                    	jna	short A_40
   807                                  
   808 000003FE 3C20                    	cmp	al, 20h ; SPACE
   809 00000400 75D1                    	jne	short A_40
   810                                  
   811 00000402 E9CF25                  	jmp	display_extended_pt
   812                                  
   813                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   814                                  ; exit if ESC key or '0' is pressed
   815                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   816                                  
   817                                  A_41:
   818                                  	; terminate
   819 00000405 CD20                    	int	20h
   820                                  
   821                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   822                                  ; display partition table again
   823                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   824                                  
   825                                  A_42:
   826                                  	; 24/02/2019
   827                                  	;xor	al, al  ; MBR/PRIMARY PARTITIONS
   828 00000407 E8D123                  	call	display_partition_table ; 12/03/2021
   829 0000040A EBA8                    	jmp	short A_38
   830                                  
   831                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   832                                  ; display a row for hard disk name, number and capacity 
   833                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   834                                  ; 11/10/2020
   835                                  
   836                                  display_hd_row:
   837                                  	; dx:ax = disk size
   838                                  
   839 0000040C 81FA0001                	cmp	dx, 256 ; >= 8GB  
   840 00000410 730E                    	jnb	short dhdr_1
   841                                  
   842                                  	;mov	cx, 2048 ; /2048 (2048 sectors = 1 MB)	
   843                                  	;div	cx
   844                                  
   845                                  	; shift dx:ax to 8 bits right (/256)  
   846 00000412 88E0                    	mov	al, ah
   847 00000414 88D4                    	mov	ah, dl
   848 00000416 C1E803                  	shr	ax, 3 ; /8 
   849                                  		; result = (dx:ax)/2048
   850                                  
   851                                  	; ax =  0 to 8191
   852                                  
   853 00000419 C606[BE44]4D            	mov	byte [TrDOS_hdrow_unit], 'M'
   854 0000041E EB0A                    	jmp	short dhdr_2
   855                                  	
   856                                  dhdr_1:
   857                                  	; 1024 MB = 1GB (2097152 sectors)
   858                                  	; DX/32 --> GB 
   859 00000420 89D0                    	mov	ax, dx
   860 00000422 C1E805                  	shr	ax, 5 ; /32
   861                                  
   862                                  	; ax = 8 to 2047
   863 00000425 C606[BE44]47            	mov	byte [TrDOS_hdrow_unit], 'G'
   864                                  dhdr_2:
   865                                  	;xor	dx, dx
   866 0000042A BE[C444]                	mov	si, TrDOS_hdrow_capacity	
   867 0000042D E81B00                  	call	convert_to_decimal
   868                                  
   869 00000430 FE06[A944]              	inc	byte [TrDOS_hdrow_n] ; next number for "(#)"
   870                                  	
   871 00000434 BE[A644]                	mov	si, TrDOS_hdrow
   872 00000437 E84817                  	call	print_msg
   873 0000043A BE[C444]                	mov	si, TrDOS_hdrow_capacity ; db "#### ", 0
   874 0000043D E84217                  	call	print_msg
   875 00000440 BE[BE44]                	mov	si, TrDOS_hdrow_unit ; "GB" or "MB"
   876 00000443 E83C17                  	call	print_msg
   877                                  
   878 00000446 FE06[AE44]              	inc	byte [TrDOS_hdrow_i] ; next number for "hd#"
   879                                  
   880 0000044A C3                      	retn	
   881                                  
   882                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   883                                  ; convert binary number to decimal character string
   884                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   885                                  ; 11/10/2020
   886                                  
   887                                  convert_to_decimal:
   888                                  	; ax = binary number
   889                                  	; si = decimal string start addr (max. 5 digits + space)
   890 0000044B B90A00                  	mov	cx, 10
   891 0000044E 89E5                    	mov	bp, sp
   892                                  ctd_1:
   893 00000450 31D2                    	xor	dx, dx
   894 00000452 F7F1                    	div	cx
   895 00000454 52                      	push	dx ; 0 to 9
   896 00000455 09C0                    	or	ax, ax
   897 00000457 75F7                    	jnz	short ctd_1
   898                                  ctd_2:
   899 00000459 58                      	pop	ax
   900 0000045A 0430                    	add	al, '0'
   901 0000045C 8804                    	mov	[si], al
   902 0000045E 46                      	inc	si
   903 0000045F 39E5                    	cmp	bp, sp
   904 00000461 77F6                    	ja	short ctd_2
   905                                  	;mov	byte [si], 20h ; space before size unit char
   906                                  	;inc	si 
   907                                  	;mov	byte [si], 0 ; ASCIIZ string terminator (Z)
   908 00000463 C7042000                	mov	word [si], 20h
   909 00000467 C3                      	retn
   910                                  
   911                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   912                                  ; check defective partition signature 
   913                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   914                                  ; 16/10/2020
   915                                  
   916                                  check_defective_partition:
   917 00000468 BB[1870]                	mov	bx, part_table_boot_ind
   918 0000046B 31F6                    	xor	si, si 
   919                                  chk_dp_1:
   920 0000046D 803FFF                  	cmp	byte [bx], 0FFh ; invalid/defective/partition sign	
   921 00000470 7509                    	jne	short chk_dp_2
   922 00000472 C1E604                  	shl	si, 4 ; * 16
   923 00000475 81C6[9857]              	add	si, MasterBootBuff+446
   924 00000479 F9                      	stc
   925 0000047A C3                      	retn
   926                                  chk_dp_2:
   927                                  	;cmp	bx, part_table_boot_ind+(18*4)
   928 0000047B 83FE03                  	cmp	si, 3
   929 0000047E 7306                    	jnb	short chk_dp_3
   930 00000480 83C312                  	add	bx, 18
   931 00000483 46                      	inc	si
   932 00000484 EBE7                    	jmp	short chk_dp_1 
   933                                  chk_dp_3:
   934                                  	;sub	si, si
   935 00000486 C3                      	retn
   936                                  
   937                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   938                                  ; create a disk partition (on MBR partition table)
   939                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   940                                  ; 18/10/2020
   941                                  
   942                                  create_partition:
   943                                  	; 19/10/2020
   944                                  	; 10/02/2019 (hdimage.s)
   945 00000487 31C0                    	xor	ax, ax
   946 00000489 A2[746D]                	mov	byte [wholedisk], al ; 0 ; Reset wholedisk flag
   947                                  
   948                                  	; 19/10/2020
   949 0000048C 3806[6070]              	cmp	byte [pcount], al ; 0 ; number of (valid) partitions
   950 00000490 7621                    	jna	short cp_1
   951                                  ;cp_0:
   952 00000492 803E[6070]04            	cmp	byte [pcount], 4
   953 00000497 731D                    	jnb	short cp_2 ; full pt !		
   954                                  
   955                                  	; al = 0
   956 00000499 E88E20                  	call	find_part_free_space
   957                                  		 ; Following values are for the max. free space on disk
   958                                  
   959 0000049C 21C9                    	and	cx, cx
   960 0000049E 7427                    	jz	short cp_3 ; there is not free space on disk
   961                                  
   962                                  	;mov	[c_cylinders], cx  ; count of free cylinders in the gap
   963 000004A0 891E[FE70]              	mov	[c_fspc_offset], bx  ; offset from beginning of 'fspc:'
   964                                  	;mov	[c_gap], al ; gap (space index) number of this free space
   965                                  	;		    ; 0 -> before partition 1 (as PTE)
   966                                  	;		    ; 1-2-3 -> between partitions 1 to 4
   967                                  	;		    ; 4 -> after partition 4 (as PTE)
   968                                  
   969                                  	; Start to job with non-aligned (full) free sectors of this max. space
   970                                  	
   971 000004A4 8B87[B470]              	mov	ax, [free_space.sectors_unused+bx]
   972 000004A8 8B97[B670]              	mov	dx, [free_space.sectors_unused+2+bx]
   973                                  
   974 000004AC A3[706D]                	mov	[pp_Sectors], ax
   975 000004AF 8916[726D]              	mov	[pp_Sectors+2], dx
   976                                  cp_1:
   977 000004B3 E9E907                  	jmp	B_01 ; New/Empty disk, create partition menu
   978                                  
   979                                  cp_2:
   980                                  	; 13/02/2019
   981                                  	; There is not a free pt entry to create a new partition
   982                                  
   983                                  	;xor	al, al  ; MBR/PRIMARY PARTITIONS
   984 000004B6 E82223                  	call	display_partition_table ; 12/03/2021
   985                                  
   986 000004B9 BE[585B]                	mov	si, msg_full_pt
   987 000004BC E8C316                  	call	print_msg
   988 000004BF BE[855B]                	mov	si, msg_to_create_new_p
   989 000004C2 E8BD16                  	call	print_msg
   990                                  
   991 000004C5 EB67                    	jmp	ap_0
   992                                  cp_3:
   993                                  	; 19/10/2020
   994 000004C7 803E[6370]00            	cmp	byte [epnumber], 0
   995 000004CC 7708                    	ja	short create_logical_drives
   996                                  ;cp_4:
   997                                  	; 15/02/2019
   998                                  	; There is not (enough) free space to create a new partition
   999                                  
  1000 000004CE BE[A35B]                	mov	si, msg_no_free_space
  1001 000004D1 E8AE16                  	call	print_msg
  1002 000004D4 EB58                    	jmp	ap_0
  1003                                  
  1004                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1005                                  ; create logical -dos- drives
  1006                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1007                                  ; 19/10/2020
  1008                                  
  1009                                  create_logical_drives:
  1010                                  	; 05/03/2019
  1011 000004D6 E87A28                  	call	check_ext_free_space
  1012 000004D9 723B                    	jc	short cld_5
  1013                                  cld_1:
  1014                                  	; 05/03/2019
  1015 000004DB 803E[A66D]04            	cmp	byte [ldrives], 4
  1016 000004E0 7203                    	jb	short cld_2
  1017 000004E2 E95D25                  	jmp	eetc_2
  1018                                  cld_2:
  1019                                  	; 01/11/2020
  1020 000004E5 A3[2271]                	mov	[ep_free_sectors], ax
  1021 000004E8 8916[2471]              	mov	[ep_free_sectors+2], dx
  1022                                  
  1023 000004EC BE[E263]                	mov	si, msg_c_ldd_q
  1024 000004EF E89016                  	call	print_msg
  1025                                  cld_3:	
  1026 000004F2 28E4                    	sub	ah, ah
  1027 000004F4 CD16                    	int	16h
  1028                                  
  1029 000004F6 3C1B                    	cmp	al, 27 ; ESCAPE key
  1030                                  	;je	cp_esc
  1031 000004F8 7419                    	je	short cld_6 ; 19/10/2020
  1032 000004FA 24DF                    	and	al, 0DFh
  1033 000004FC 3C4E                    	cmp	al, 'N'
  1034 000004FE 740D                    	je	short cld_4
  1035 00000500 3C59                    	cmp	al, 'Y'
  1036 00000502 75EE                    	jne	short cld_3
  1037 00000504 BE[985C]                	mov	si, _msg_YES
  1038 00000507 E87816                  	call	print_msg
  1039                                  
  1040 0000050A E96825                  	jmp	edit_ext_table_create_x
  1041                                  cld_4:	
  1042 0000050D BE[9E5C]                	mov	si, _msg_NO
  1043 00000510 E86F16                  	call	print_msg
  1044                                  cld_6:
  1045                                  	;jmp	cp_esc
  1046                                  	; 19/10/2020
  1047 00000513 E9F1FE                  	jmp	A_42
  1048                                  cld_5:	
  1049 00000516 BE[B263]                	mov	si, msg_c_part_error
  1050 00000519 E86616                  	call	print_msg
  1051                                  
  1052                                  	; 21/03/2021
  1053                                  	;cmp	byte [ldrives], 3
  1054                                  	;;jna	short cld_2
  1055                                  	; 21/03/2021
  1056                                  	;jna	short ap_0
  1057                                  
  1058                                  	;mov	si, msg_c_ldd_error
  1059                                  	;call	print_msg
  1060                                  
  1061 0000051C EB10                    	jmp	short ap_0
  1062                                  
  1063                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1064                                  ; set active partition
  1065                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1066                                  ; 19/10/2020 
  1067                                  	
  1068                                  activate_partition:
  1069                                  	; 12/02/2019
  1070                                  	;xor	al, al  ; MBR/PRIMARY PARTITIONS
  1071 0000051E E8BA22                  	call	display_partition_table ; 12/03/2021
  1072                                  
  1073 00000521 803E[6070]00            	cmp	byte [pcount], 0
  1074 00000526 7713                    	ja	short ap_1
  1075                                  
  1076 00000528 BE[0C5B]                	mov	si, msg_empty_pt
  1077 0000052B E85416                  	call	print_msg
  1078                                  ap_0:
  1079 0000052E BE[BB55]                	mov	si, msg_press_any_key
  1080 00000531 E84E16                  	call	print_msg
  1081                                  
  1082 00000534 30E4                    	xor	ah, ah
  1083 00000536 CD16                    	int	16h
  1084                                  ap_5:
  1085                                  	;jmp	ap_esc
  1086                                  	; 19/10/2020
  1087 00000538 E9CCFE                  	jmp	A_42
  1088                                  
  1089                                  ap_1:
  1090                                  	; Set valid_ppnums (MBR partition IDs) list
  1091 0000053B BE[9857]                	mov	si, MasterBootBuff+pTableOffset ; MasterBootBuff+446
  1092 0000053E BB[BA6F]                	mov	bx, valid_ppnums
  1093 00000541 B104                    	mov	cl, 4
  1094                                  ap_2:
  1095 00000543 8A4404                  	mov	al, [si+ptFileSystemID]
  1096 00000546 8807                    	mov	[bx], al
  1097 00000548 FEC9                    	dec	cl
  1098 0000054A 7406                    	jz	short ap_3
  1099 0000054C 43                      	inc	bx
  1100 0000054D 83C610                  	add	si, 16
  1101 00000550 EBF1                    	jmp	short ap_2
  1102                                  ap_3:
  1103 00000552 BE[8B5D]                	mov	si, msg_enter_pn_to_act
  1104 00000555 E82A16                  	call	print_msg
  1105                                  ap_getchar:
  1106 00000558 30E4                    	xor	ah, ah
  1107 0000055A CD16                    	int	16h
  1108                                  	
  1109                                  	; 19/10/2020
  1110 0000055C 3C1B                    	cmp	al, 27
  1111                                  	;je	ap_esc
  1112 0000055E 74D8                    	je	short ap_5
  1113                                  
  1114                                  	;cmp	al, '0'
  1115                                  	;;je	ap_esc
  1116                                  	;je	short ap_5	
  1117                                  
  1118 00000560 3C31                    	cmp	al, '1'
  1119 00000562 72F4                    	jb	short ap_getchar
  1120 00000564 3C34                    	cmp	al, '4'
  1121 00000566 77F0                    	ja	short ap_getchar
  1122                                  
  1123 00000568 30E4                    	xor	ah, ah
  1124 0000056A 89C2                    	mov	dx, ax
  1125                                  	
  1126 0000056C 80EA31                  	sub	dl, '1'
  1127 0000056F 89D6                    	mov	si, dx
  1128 00000571 38A4[BA6F]              	cmp	byte [si+valid_ppnums], ah  ; 0
  1129 00000575 76E1                    	jna	short ap_getchar ; Empty partition table entry, it is not shown
  1130                                  
  1131 00000577 BB0700                  	mov	bx, 07h
  1132 0000057A B409                    	mov	ah, 09h
  1133 0000057C B90100                  	mov	cx, 1
  1134 0000057F CD10                    	int	10h
  1135                                  
  1136 00000581 BE[9857]                	mov	si, MasterBootBuff+pTableOffset
  1137 00000584 BF[1870]                	mov	di, part_table_boot_ind ; (**)
  1138                                  
  1139                                  	; Clear all of possible active partition flags
  1140 00000587 8834                    	mov	[si], dh ; 0	
  1141 00000589 887410                  	mov	[si+16], dh ; 0
  1142 0000058C 887420                  	mov	[si+32], dh ; 0
  1143 0000058F 887430                  	mov	[si+48], dh ; 0
  1144                                  
  1145                                  	; This may not be needed !? 
  1146                                  	; (**) (Primary partitions structure/list)
  1147 00000592 8835                    	mov	[di], dh ; 0	
  1148 00000594 887512                  	mov	[di+18], dh ; 0
  1149 00000597 887524                  	mov	[di+36], dh ; 0
  1150 0000059A 887536                  	mov	[di+54], dh ; 0
  1151                                  
  1152 0000059D 20D2                    	and 	dl, dl
  1153 0000059F 740D                    	jz	short ap_4
  1154                                  
  1155 000005A1 89D0                    	mov	ax, dx
  1156                                  
  1157 000005A3 C0E004                  	shl	al, 4 ; * 16
  1158 000005A6 01C6                    	add	si, ax
  1159                                  
  1160 000005A8 B012                    	mov	al, 18
  1161 000005AA F6E2                    	mul	dl ; 1 to 3
  1162 000005AC 01C7                    	add	di, ax
  1163                                  ap_4:
  1164                                  	; Then	set active partition as requested by user
  1165 000005AE C60480                  	mov	byte [si], 80h
  1166 000005B1 C60580                  	mov	byte [di], 80h ; (**)
  1167                                  
  1168 000005B4 BE[5F55]                	mov	si, CRLF ; Next line	
  1169 000005B7 E8C815                  	call	print_msg
  1170                                  
  1171                                  	; NOTE: Only the MBR buffer has been changed
  1172                                  	; (Masterboot sector will not be updated unless/till
  1173                                  	;  MBR partition table -and MBR code- will be written
  1174                                  	;  to disk image as result of 'write part. table' command.)
  1175                                  
  1176                                  	;; wait for 1 second
  1177                                  	;mov	ah, 02h
  1178                                  	;int	1Ah
  1179                                  	;mov	[GetChar], dh
  1180                                  ;ap_wait:
  1181                                  	;mov	ah, 02h
  1182                                  	;int	1Ah
  1183                                  	;cmp	dh, [GetChar]
  1184                                  	;je	short ap_wait
  1185                                  
  1186                                  	; 17/10/2020 
  1187 000005BA E94AFE                  	jmp	A_42 ; display partition table again
  1188                                  
  1189                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1190                                  ; delete selected partition
  1191                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1192                                  ; 19/10/2020
  1193                                  
  1194                                  delete_partition:
  1195                                  	; 10/02/2019
  1196                                  	;xor	al, al  ; MBR/PRIMARY PARTITIONS
  1197 000005BD E81B22                  	call	display_partition_table ; 12/03/2021
  1198                                  
  1199 000005C0 803E[6070]00            	cmp	byte [pcount], 0
  1200 000005C5 7712                    	ja	short dp_1
  1201                                  
  1202 000005C7 BE[0C5B]                	mov	si, msg_empty_pt
  1203 000005CA E8B515                  	call	print_msg
  1204                                  
  1205 000005CD BE[BB55]                	mov	si, msg_press_any_key
  1206 000005D0 E8AF15                  	call	print_msg
  1207                                  
  1208 000005D3 30E4                    	xor	ah, ah
  1209 000005D5 CD16                    	int	16h
  1210                                  
  1211 000005D7 EB73                    	jmp	short dp_esc
  1212                                  
  1213                                  dp_1:
  1214                                  	; Set valid_ppnums (MBR partition IDs) list
  1215 000005D9 BE[9857]                	mov	si, MasterBootBuff+pTableOffset ; MasterBootBuff+446
  1216 000005DC BB[BA6F]                	mov	bx, valid_ppnums
  1217 000005DF B104                    	mov	cl, 4
  1218                                  dp_2:
  1219 000005E1 8A4404                  	mov	al, [si+ptFileSystemID]
  1220 000005E4 8807                    	mov	[bx], al
  1221 000005E6 FEC9                    	dec	cl
  1222 000005E8 7406                    	jz	short dp_3
  1223 000005EA 43                      	inc	bx
  1224 000005EB 83C610                  	add	si, 16
  1225 000005EE EBF1                    	jmp	short dp_2
  1226                                  dp_3:
  1227 000005F0 BE[C75B]                	mov	si, msg_enter_pn_to_del
  1228 000005F3 E88C15                  	call	print_msg
  1229                                  dp_getchar1:
  1230 000005F6 30E4                    	xor	ah, ah
  1231 000005F8 CD16                    	int	16h
  1232                                  	
  1233                                  	; 19/10/2020
  1234 000005FA 3C1B                    	cmp	al, 27
  1235 000005FC 744E                    	je	short dp_esc
  1236 000005FE 3C30                    	cmp	al, '0'
  1237 00000600 744A                    	je	short dp_esc
  1238                                  	;cmp	al, '1'
  1239 00000602 72F2                    	jb	short dp_getchar1
  1240 00000604 3C34                    	cmp	al, '4'
  1241 00000606 77EE                    	ja	short dp_getchar1
  1242                                  
  1243 00000608 30FF                    	xor	bh, bh
  1244 0000060A 88C3                    	mov	bl, al
  1245                                  	;dec	bl
  1246 0000060C 80EB31                  	sub	bl, '1'
  1247 0000060F 38BF[BA6F]              	cmp	byte [bx+valid_ppnums], bh ; 0 ; 12/02/2019
  1248 00000613 76E1                    	jna	short dp_getchar1  ; Empty partition table entry, it is not shown
  1249                                  	
  1250 00000615 881E[C56F]              	mov	[del_part_num], bl ; Selected partition number to be deleted.
  1251 00000619 A2[EB5B]                	mov	[chr_del_pnum1], al ; Partition number for "Enter ..." text
  1252 0000061C A2[8D5C]                	mov	[chr_del_pnum2], al ; Partition number for "Do you want ..." text
  1253                                  
  1254 0000061F BE[EB5B]                	mov	si, chr_del_pnum1 ; write partition number (user input)
  1255 00000622 E85D15                  	call	print_msg
  1256                                  
  1257                                  	;xor	al, al
  1258 00000625 A2[EB5B]                	mov	[chr_del_pnum1], al ; 0 ; reset
  1259                                  
  1260 00000628 BE[EF5B]                	mov	si, msg_delete_partition_q ; question for deleting (with warning)
  1261 0000062B E85415                  	call	print_msg
  1262                                  
  1263                                  dp_getchar2:
  1264 0000062E 30E4                    	xor	ah, ah
  1265 00000630 CD16                    	int	16h
  1266                                  
  1267 00000632 3C1B                    	cmp	al, 27
  1268 00000634 7416                    	je	short dp_esc
  1269                                  
  1270 00000636 24DF                    	and	al, 0DFh
  1271 00000638 3C59                    	cmp	al, 'Y'
  1272 0000063A 7413                    	je	short dp_yes
  1273 0000063C 3C4E                    	cmp	al, 'N'
  1274 0000063E 75EE                    	jne	short dp_getchar2
  1275                                  dp_no:
  1276 00000640 BE[9F5C]                	mov	si, msg_NO ;  Write 'NO' (it may be shown for a moment)
  1277 00000643 E83C15                  	call	print_msg
  1278                                  	
  1279 00000646 BE[5F55]                	mov	si, CRLF  ; Next line
  1280 00000649 E83615                  	call	print_msg
  1281                                  	
  1282                                  	;jmp	short dp_esc
  1283                                  
  1284                                  ;cp_esc:
  1285                                  ;ap_esc:
  1286                                  ;wptmbr_esc:
  1287                                  dp_esc:
  1288                                  	;xor	al, al  ; MBR/PRIMARY PARTITIONS
  1289                                  	;call	display_partition_table
  1290                                  	;jmp	A_38 ; 17/10/2020
  1291                                  
  1292                                  	; 19/10/2020
  1293 0000064C E9B8FD                  	jmp	A_42
  1294                                  
  1295                                  dp_yes:
  1296 0000064F BE[995C]                	mov	si, msg_YES ;  Write 'YES' (it may be shown for a moment)
  1297 00000652 E82D15                  	call	print_msg
  1298                                  
  1299 00000655 BF[9857]                	mov	di, MasterBootBuff+pTableOffset
  1300 00000658 A0[C56F]                	mov	al, [del_part_num]
  1301 0000065B 20C0                    	and 	al, al
  1302 0000065D 7406                    	jz	short dp_4
  1303 0000065F 98                      	cbw
  1304                                  	;xor	ah, ah
  1305 00000660 C0E004                  	shl	al, 4 ; * 16
  1306 00000663 01C7                    	add	di, ax
  1307                                  dp_4:
  1308 00000665 BE[5F55]                	mov	si, CRLF ; Next line	
  1309 00000668 E81715                  	call	print_msg
  1310                                  
  1311                                  	; 27/02/2019
  1312 0000066B 807D0405                	cmp	byte [di+ptFileSystemID], 05h ; EXTENDED (CHS)  
  1313                                  	;jne	short dp_5
  1314 0000066F 7406                    	je	short dp_6
  1315                                  	; 24/10/2020
  1316 00000671 807D040F                	cmp	byte [di+ptFileSystemID], 0Fh ; EXTENDED (LBA)
  1317 00000675 7545                    	jne	short dp_5
  1318                                  dp_6:
  1319 00000677 3806[A66D]              	cmp	byte [ldrives], al ; 0
  1320 0000067B 763F                    	jna	short dp_5
  1321                                  
  1322 0000067D BE[B55F]                	mov	si, msg_ext_part_del_error	
  1323 00000680 E8FF14                  	call	print_msg
  1324 00000683 BE[F55F]                	mov	si, msg_cancel_continue
  1325 00000686 E8F914                  	call	print_msg
  1326                                       	
  1327 00000689 30E4                    	xor	ah, ah
  1328 0000068B CD16                    	int	16h
  1329                                  	
  1330 0000068D 3C1B                    	cmp	al, 27 ; ESCape
  1331 0000068F 74BB                    	je	short dp_esc
  1332                                  
  1333 00000691 E82C2A                  	call	delete_logical_drives
  1334                                  	
  1335                                  	; 28/02/2019
  1336 00000694 803E[A66D]01            	cmp	byte [ldrives], 1
  1337 00000699 73B1                    	jnb	short dp_esc
  1338                                  
  1339                                  	;xor	al, al  ; MBR/PRIMARY PARTITIONS
  1340 0000069B E83D21                  	call	display_partition_table ; 12/03/2021
  1341                                  
  1342 0000069E BE[8860]                	mov	si, msg_delete_ext_part
  1343 000006A1 E8DE14                  	call	print_msg
  1344                                  
  1345                                  dp_ask_again:
  1346 000006A4 28E4                    	sub	ah, ah
  1347 000006A6 CD16                    	int	16h
  1348                                  
  1349 000006A8 3C1B                    	cmp	al, 27 ; ESCape
  1350 000006AA 74A0                    	je	short dp_esc	
  1351                                  
  1352 000006AC 3C0D                    	cmp	al, 13 ; ENTER/CR
  1353 000006AE 75F4                    	jne	short dp_ask_again
  1354                                  
  1355 000006B0 BF[9857]                	mov	di, MasterBootBuff+pTableOffset
  1356 000006B3 A0[C56F]                	mov	al, [del_part_num]
  1357 000006B6 98                      	cbw
  1358 000006B7 C0E004                  	shl	al, 4 ; * 16
  1359 000006BA 01C7                    	add	di, ax
  1360                                  dp_5:
  1361 000006BC 31C0                    	xor	ax, ax
  1362                                  
  1363                                  	; clear partition table entry in MBR buffer
  1364 000006BE B90800                  	mov	cx, 8
  1365 000006C1 F3AB                    	rep	stosw
  1366                                  	
  1367                                  	; NOTE: Only the MBR buffer will be cleared
  1368                                  	; (Masterboot sector will not be updated unless/till
  1369                                  	;  MBR partition table -and MBR code- will be written
  1370                                  	;  to disk image as result of 'write part. table' command.)
  1371                                  
  1372 000006C3 E924FB                  	jmp	A_21 ; 17/10/2020
  1373                                   	 
  1374                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1375                                  ; write partition table (and MBR code) onto disk
  1376                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1377                                  ; 18/10/2020
  1378                                  
  1379                                  write_pt_mbr:
  1380                                  	; 18/10/2020 (fdisk3.s)
  1381                                  	; 11/02/2019 (hdimage.s)
  1382                                  	;xor	al, al  ; MBR/PRIMARY PARTITIONS
  1383 000006C6 E81221                  	call	display_partition_table ; 12/03/2021
  1384                                  
  1385 000006C9 BE[A35C]                	mov	si, msg_write_masterboot_sector
  1386 000006CC E8B314                  	call	print_msg
  1387                                  
  1388 000006CF A2[966D]                	mov	[GetChar], al ; 0
  1389                                  
  1390 000006D2 BE[865D]                	mov	si, option_input
  1391 000006D5 E8AA14                  	call	print_msg
  1392                                  
  1393 000006D8 B403                    	mov	ah, 3
  1394                                  	;mov	bx, 7
  1395 000006DA CD10                    	int	10h ; Return Cursor Position
  1396                                  	; DL = Column
  1397                                  	
  1398 000006DC FECA                    	dec	dl ; previous char ; ']'
  1399 000006DE FECA                    	dec	dl ; previous char ; '[ ]'
  1400                                  
  1401 000006E0 B402                    	mov	ah, 2
  1402                                  	;mov	bx, 7
  1403 000006E2 CD10                    	int	10h ; Set Cursor Position
  1404                                  
  1405                                  	; write char at current cursor position
  1406                                  
  1407 000006E4 B030                    	mov	al, '0' ; Write default char
  1408                                  
  1409                                  	;;mov	bx, 07h
  1410 000006E6 B409                    	mov	ah, 09h
  1411 000006E8 B90100                  	mov	cx, 1
  1412 000006EB CD10                    	int	10h
  1413                                  
  1414                                  wptmbr_getchar:
  1415 000006ED 30E4                    	xor	ah, ah              
  1416 000006EF CD16                    	int	16h
  1417                                  
  1418 000006F1 3C1B                    	cmp	al, 1Bh ; 27
  1419                                  	;je	wptmbr_esc ; 19/10/2020
  1420 000006F3 0F8410FD                	je	A_42
  1421                                  
  1422 000006F7 3C0D                    	cmp	al, 0Dh ; 13
  1423 000006F9 7414                    	je	short wptmbr_1
  1424                                                  
  1425 000006FB 3C31                    	cmp	al, '1'
  1426 000006FD 72EE                    	jb	short wptmbr_getchar
  1427                                  
  1428 000006FF 3C32                    	cmp	al, '2'
  1429 00000701 77EA                    	ja 	short wptmbr_getchar
  1430                                  
  1431 00000703 A2[966D]                	mov	[GetChar], al
  1432                                  
  1433                                  	;;mov	bx, 07h
  1434 00000706 B409                    	mov	ah, 09h
  1435 00000708 B90100                  	mov	cx, 1
  1436 0000070B CD10                    	int	10h
  1437 0000070D EBDE                    	jmp	short wptmbr_getchar
  1438                                  
  1439                                  wptmbr_1:
  1440 0000070F 803E[966D]00            	cmp	byte [GetChar], 0
  1441 00000714 76D7                    	jna	short wptmbr_getchar
  1442                                  
  1443 00000716 BE[545D]                	mov	si, msg_writing_ptable
  1444 00000719 E86614                  	call	print_msg
  1445                                  
  1446 0000071C 803E[966D]32            	cmp	byte [GetChar], '2'
  1447 00000721 751F                    	jne	short wptmbr_2 ; Do not write Singlix MBR code
  1448                                  
  1449                                  	; Write CHS parameters in Singlix (FS specific) MBR
  1450                                  	
  1451 00000723 BE[5B31]                	mov	si, TRDOS386_MASTERBOOT_SECTOR
  1452 00000726 B9DF00                  	mov	cx, 446/2 ; Copy Singlix FS 1 MBR code
  1453                                  			  ; except Partition Table
  1454 00000729 BF[DA55]                	mov	di, MasterBootBuff
  1455 0000072C F3A5                    	rep	movsw
  1456                                  	
  1457                                  	; This (Below) is not needed; because, if MBR magicword
  1458                                  	; would not be 0AA55h, we would not be able to come here!
  1459                                  	;;add	di, 64  ; skip partition table	
  1460                                  	;;mov	ax, 0AA55h
  1461                                  	;;stosw
  1462                                  	;mov 	word [MBIDCode], 0AA55h
  1463                                  
  1464                                  	; 12/02/2019
  1465                                  	; Copy CHS parameters to Singlix MBR (on disk)
  1466                                  	
  1467 0000072E BF[7E57]                	mov	di, MasterBootBuff+420
  1468                                  
  1469 00000731 A1[723F]                	mov	ax, [cylinders]
  1470 00000734 AB                      	stosw 			; cylinders
  1471 00000735 A1[703F]                	mov	ax, [heads]
  1472 00000738 AB                      	stosw 			; heads
  1473 00000739 A1[6E3F]                	mov	ax, [sectors]
  1474 0000073C AB                      	stosw 			; sectors
  1475                                  
  1476                                  	; 13/03/2021
  1477                                  	; copy 32 bit disk size (total LBA sectors) to MBR offset 426
  1478 0000073D BE[DA68]                	mov	si, disksize
  1479 00000740 A5                      	movsw
  1480 00000741 A5                      	movsw
  1481                                  
  1482                                  wptmbr_2:
  1483                                  	;xor	ax, ax ; 0
  1484                                  	;xor	dx, dx ; 0
  1485                                  	;; DX_AX = Masterboot Sector = 0
  1486                                  	;mov	bx, MasterBootBuff
  1487                                  	;; ES:BX = Sector Buffer
  1488                                  	;call	write_hd_sector
  1489                                  	;jc	short print_error_code 
  1490                                  			; ! display error msg and then exit !
  1491                                  
  1492 00000742 C606[D968]05            	mov	byte [rcnt], 5  ; retry count
  1493                                  
  1494 00000747 BB[DA55]                	mov	bx, MasterBootBuff
  1495                                  
  1496 0000074A B90100                  	mov	cx, 1	; cylinder = 0
  1497                                  			; sector = 1
  1498 0000074D B600                    	mov	dh, 0	; head = 0
  1499 0000074F 8A16[D668]              	mov	dl, [DrvNum]
  1500                                  wptmbr_3:
  1501 00000753 B80103                  	mov	ax, 0301h ; write one sector
  1502 00000756 CD13                    	int	13h	
  1503 00000758 730C                    	jnc     short wptmbr_4
  1504                                               
  1505 0000075A FE0E[D968]              	dec	byte [rcnt]
  1506 0000075E 7431                    	jz	short print_error_code
  1507                                          
  1508 00000760 30E4                    	xor	ah, ah                   
  1509                                  	;mov	dl, [DrvNum]
  1510 00000762 CD13                    	int	13h	; BIOS Service func (ah) = 0
  1511                                  			; Reset disk system
  1512 00000764 EBED                    	jmp	short wptmbr_3
  1513                                  
  1514                                  wptmbr_4:
  1515 00000766 BE[7D5D]                	mov	si, _msg_OK
  1516 00000769 E81614                  	call	print_msg
  1517                                  
  1518                                  	; wait for 1 second
  1519 0000076C B402                    	mov	ah, 02h
  1520 0000076E CD1A                    	int	1Ah
  1521 00000770 8836[966D]              	mov	[GetChar], dh
  1522                                  wptmbr_wait:
  1523 00000774 B402                    	mov	ah, 02h
  1524 00000776 CD1A                    	int	1Ah
  1525 00000778 3A36[966D]              	cmp	dh, [GetChar]
  1526 0000077C 74F6                    	je	short wptmbr_wait
  1527                                  	
  1528 0000077E BE[BB55]                	mov	si, msg_press_any_key
  1529 00000781 E8FE13                  	call	print_msg
  1530                                                  
  1531 00000784 30E4                    	xor	ah, ah	; "Press any key to continue"
  1532 00000786 CD16                    	int	16h
  1533                                  
  1534 00000788 BE[5F55]                	mov	si, CRLF
  1535 0000078B E8F413                  	call	print_msg
  1536                                  
  1537                                  	;jmp	wptmbr_esc
  1538                                  	; 19/10/2020
  1539 0000078E E976FC                  	jmp	A_42
  1540                                  
  1541                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1542                                  ; print error message and exit
  1543                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1544                                  ; 18/10/2020 (fdisk3.s)
  1545                                  	
  1546                                  print_error_code:
  1547                                  	; 25/02/2019 (hdimage.s)
  1548                                  
  1549 00000791 88E0                    	mov	al, ah	; error code
  1550 00000793 E8C214                  	call	bin_to_hex
  1551 00000796 A3[6D55]                	mov 	[error_code], ax
  1552                                  
  1553 00000799 BE[5F55]                	mov	si, CRLF
  1554 0000079C E8E313                  	call	print_msg
  1555                                  
  1556 0000079F BE[6255]                	mov	si, Msg_Error
  1557 000007A2 E8DD13                  	call	print_msg
  1558                                  	
  1559 000007A5 CD20                    	int	20h	; Exit
  1560                                  
  1561                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1562                                  ; exit, print_msg & exit
  1563                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1564                                  ; 19/10/2020
  1565                                  
  1566                                  _crlf_exit:
  1567 000007A7 BE[5F55]                	mov	si, CRLF
  1568                                  _p_exit:
  1569                                  	; 11/10/2020
  1570 000007AA E8D513                  	call	print_msg
  1571                                  _exit:
  1572 000007AD B8004C                  	mov	ax, 4C00h		; terminate
  1573 000007B0 CD21                    	int	21h
  1574                                  
  1575                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1576                                  ; display create partition menu & get partition type input
  1577                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1578                                  ; 19/10/2020
  1579                                  
  1580                                  create_partition_input:
  1581                                  	; 15/02/2019
  1582                                  	; clear screen
  1583 000007B2 B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
  1584 000007B5 CD10                    	int	10h
  1585                                  	
  1586 000007B7 BE[5945]                	mov	si, msg_create_partition_h ; header
  1587 000007BA E8C513                  	call	print_msg
  1588 000007BD BE[4E46]                	mov	si, msg_create_partition_m ; menu
  1589 000007C0 E8BF13                  	call	print_msg
  1590                                  cpi_1:
  1591 000007C3 30E4                    	xor	ah, ah
  1592 000007C5 CD16                    	int	16h
  1593 000007C7 3C1B                    	cmp	al, 27 ; ESC key	
  1594 000007C9 7445                    	je	short cpi_4  ; 25/02/2019
  1595 000007CB 3C30                    	cmp	al, '0'
  1596 000007CD 7441                    	je	short cpi_4  ; 25/02/2019
  1597 000007CF 72F2                    	jb	short cpi_1
  1598 000007D1 3C34                    	cmp	al, '4'
  1599 000007D3 77EE                    	ja	short cpi_1
  1600                                  
  1601 000007D5 30E4                    	xor	ah, ah
  1602 000007D7 2C30                    	sub	al, '0'
  1603                                  
  1604                                  	;mov	[pp_type], al
  1605                                  
  1606                                  	;mov	byte [pp_type_user], 0
  1607                                  
  1608 000007D9 3C01                    	cmp	al, 1 ; DOS partition
  1609 000007DB 7536                    	jne	short cpi_5 ; ah = 0 
  1610                                  			    ; (al = 2 -> singlix, al = 3 -> retro unix)
  1611                                  cpi_2:
  1612                                  	; clear screen
  1613 000007DD B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
  1614 000007E0 CD10                    	int	10h
  1615                                  	
  1616 000007E2 BE[0448]                	mov	si, msg_create_dos_partition_h ; header
  1617 000007E5 E89A13                  	call	print_msg
  1618 000007E8 BE[D84B]                	mov	si, msg_create_dos_partition_m ; menu
  1619 000007EB E89413                  	call	print_msg
  1620                                  cpi_3:
  1621 000007EE 30E4                    	xor	ah, ah
  1622 000007F0 CD16                    	int	16h
  1623 000007F2 3C1B                    	cmp	al, 27 ; ESC key	
  1624 000007F4 741A                    	je	short cpi_4
  1625 000007F6 3C30                    	cmp	al, '0'
  1626 000007F8 7416                    	je	short cpi_4
  1627 000007FA 72F2                    	jb	short cpi_3
  1628 000007FC 3C33                    	cmp	al, '3'
  1629 000007FE 77EE                    	ja	short cpi_3
  1630                                  	
  1631 00000800 30E4                    	xor	ah, ah
  1632 00000802 2C30                    	sub	al, '0'
  1633 00000804 3C01                    	cmp	al, 1
  1634 00000806 7424                    	je	short cpi_6  ;	ah = 0 (al = primary dos partition)
  1635                                  
  1636                                  	;mov	byte [pp_type], 5
  1637                                  
  1638 00000808 3C02                    	cmp	al, 2
  1639 0000080A 7621                    	jna	short cpi_7
  1640                                  
  1641 0000080C B80600                  	mov	ax, 6	; ah = 0 (al = logical dos drive/partition)
  1642 0000080F C3                      	retn
  1643                                  
  1644                                  cpi_4:
  1645 00000810 31C0                    	xor	ax, ax	; ah = 0 (al = 0 -> ESCape/Cancel)
  1646 00000812 C3                      	retn
  1647                                  cpi_5:
  1648 00000813 3C04                    	cmp	al, 4	 ; option num. for partition type (user) input
  1649 00000815 7515                    	jne	short cpi_6
  1650                                  
  1651 00000817 E81318                  	call	partition_type_input
  1652                                  	
  1653                                  	; 29/10/2020
  1654 0000081A 08C0                    	or	al, al
  1655                                  	;jz	short cpi_6 ; invalid (zero) input or ESC key
  1656 0000081C 74F2                    	jz	short cpi_4
  1657                                  
  1658 0000081E B404                    	mov	ah, 4 ; user/another type partition flag
  1659                                  	; al = Partition ID	
  1660 00000820 50                      	push	ax
  1661 00000821 BE[BB55]                	mov	si, msg_press_any_key 
  1662 00000824 E85B13                  	call	print_msg
  1663 00000827 28E4                    	sub	ah, ah
  1664 00000829 CD16                    	int	16h
  1665 0000082B 58                      	pop	ax
  1666                                  cpi_6:
  1667 0000082C C3                      	retn
  1668                                  cpi_7:
  1669 0000082D B80500                  	mov	ax, 5	; ah = 0 (al = extended dos partition)
  1670 00000830 C3                      	retn
  1671                                  
  1672                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1673                                  ; create primary (dos or non-dos) partition
  1674                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1675                                  ; 19/10/2020 
  1676                                  ;	(This procedure must be called after 'find_part_free_space')
  1677                                  
  1678                                  create_primary_partition:  
  1679                                  	; 16/02/2019
  1680                                  
  1681                                  	; INPUT:
  1682                                  	;	none 
  1683                                  	;  (CHS parameters and free space calculation result will be used.) 
  1684                                  	;
  1685                                  	; OUTPUT:
  1686                                  	;	Partition table in MBR buffer will be updated.
  1687                                  	;
  1688                                  	; (Modified registers: ax, bx, cx, dx, si, di)
  1689                                  
  1690                                  	; Create primary dos or non-dos partition,
  1691                                  	; make partition table entry
  1692                                  
  1693                                  	; 19/10/2020
  1694 00000831 803E[6070]00            	cmp	byte [pcount], 0  ; count of (valid) partitions
  1695 00000836 770A                    	ja	short cpp_0
  1696                                  
  1697                                  	; cylinder = 0, head = 1, sector = 1
  1698                                  	; LBA = (((cylinder*heads)+head)*sectors)+sector-1
  1699                                  
  1700 00000838 BE[9857]                	mov	si, MasterBootBuff+pTableOffset
  1701                                  
  1702 0000083B A1[6E3F]                	mov	ax, [sectors] ; LBA = 17 or 63
  1703 0000083E 31D2                    	xor	dx, dx
  1704 00000840 EB56                    	jmp	short cpp_4
  1705                                  cpp_0:
  1706                                  	; 16/02/2019
  1707 00000842 E8571F                  	call	get_first_free_pte
  1708                                  		 ; CX = First free PTE number, 0 to 3 
  1709                                  		 ;    (CX = 3 if there is not a free PTE, and CF = 1)
  1710                                  		 ;    ((But CF = 1 is not possible here because pcount < 4))
  1711                                   	 	 ; SI = PTE address/offset in MBR buffer
  1712                                  
  1713                                  	;mov	si, MasterBootBuff+pTableOffset
  1714                                  	;shl	cl, 4 ; * 16
  1715                                  	;add	si, cx
  1716                                  
  1717                                  	; 18/02/2019
  1718 00000845 8B3E[FE70]              	mov	di, [c_fspc_offset]
  1719 00000849 8B9D[AE70]              	mov	bx, [di+free_space.start]
  1720 0000084D A0[703F]                	mov	al, [heads]
  1721 00000850 F626[6E3F]              	mul	byte [sectors]
  1722 00000854 F7E3                    	mul	bx
  1723                                  		; DX:AX = LBA of start cylinder, head 0, sector 1
  1724                                  	
  1725 00000856 8A0E[0071]              	mov	cl, [cylinder_boundary]
  1726                                  
  1727                                  	;cmp	cl, 0 ; Default (partition size unit is one of C, G, M)
  1728                                  		      ; boundary alignment is forced as default
  1729                                  	;je	short cpp_4
  1730                                  
  1731                                  	; 20/02/2019
  1732                                  	;and	cl, cl
  1733                                  	;jz 	short cpp_1
  1734                                  
  1735 0000085A 80F959                  	cmp	cl, 'Y'
  1736 0000085D 7439                    	je	short cpp_4 ; cylinder boundary option (answer) = YES
  1737                                  
  1738 0000085F 80F94E                  	cmp	cl, 'N'
  1739 00000862 750A                    	jne	short cpp_1 ; cylinder boundary option (answer) = YES/NO
  1740                                  
  1741                                  	; cylinder boundary option (answer) = NO 
  1742 00000864 8B85[B870]              	mov	ax, [di+free_space.startsector]
  1743 00000868 8B95[BA70]              	mov	dx, [di+free_space.startsector+2]
  1744 0000086C EB2A                    	jmp	short cpp_4
  1745                                  cpp_1:
  1746                                  	;cmp	cl, 27 ; ESCape
  1747                                  	;jne	short cpp_4 ; 'Y'
  1748                                  
  1749                                  	; check	cylinder boundary alignment of the start sector
  1750                                  
  1751                                  	; if start sector is not aligned, end sector must not be aligned
  1752                                  	; (this rule is valid for ESCape key from the user) 
  1753                                  
  1754 0000086E C606[0071]59            	mov	byte [cylinder_boundary], 'Y' ; YES for end sector check
  1755                                  
  1756 00000873 8B8D[B870]              	mov	cx, [di+free_space.startsector]
  1757                                  
  1758 00000877 09DB                    	or	bx, bx
  1759                                  
  1760 00000879 8B9D[BA70]              	mov	bx, [di+free_space.startsector+2]
  1761                                  
  1762 0000087D 7508                    	jnz	short cpp_2 ; start cylinder > 0
  1763                                  
  1764                                  	;and	bx, bx
  1765                                  	;jnz	short cpp_3
  1766                                  
  1767 0000087F 3B0E[6E3F]              	cmp	cx, [sectors]
  1768 00000883 7413                    	je	short cpp_4 ; start sector is as aligned 
  1769 00000885 EB08                    	jmp	short cpp_3
  1770                                  cpp_2:
  1771 00000887 39C8                    	cmp	ax, cx
  1772 00000889 7504                    	jne	short cpp_3
  1773 0000088B 39DA                    	cmp	dx, bx
  1774 0000088D 7409                    	je	short cpp_4 
  1775                                  cpp_3:
  1776 0000088F 89C8                    	mov	ax, cx
  1777 00000891 89DA                    	mov	dx, bx
  1778 00000893 C606[0071]4E            	mov	byte [cylinder_boundary], 'N'
  1779                                  cpp_4:
  1780 00000898 894408                  	mov	[si+ptStartSector], ax
  1781 0000089B 89540A                  	mov	[si+ptStartSector+2], dx
  1782                                  
  1783                                  	; save start sector (for partition formatting procedure)
  1784 0000089E A3[6C6D]                	mov	[pp_StartSector], ax
  1785 000008A1 8916[6E6D]              	mov	[pp_StartSector+2], dx
  1786                                  
  1787                                  	; 14/03/2021
  1788 000008A5 8B0E[9E6D]              	mov	cx, [ppn_Sectors]
  1789 000008A9 8B1E[A06D]              	mov	bx, [ppn_Sectors+2]
  1790                                  
  1791                                  	; 19/10/2020
  1792 000008AD 803E[6070]00            	cmp	byte [pcount], 0
  1793 000008B2 775E                    	ja	short cpp_5
  1794                                  
  1795                                  	;xor	cx, cx
  1796                                  	;mov	[si+ptBeginCylinder], cx ; 0
  1797                                  	;inc	cl  ; 1
  1798                                  	;mov	[si+ptBeginSector], cl ; 1
  1799                                  	;mov	[si+ptBeginHead], cl ; 1
  1800                                  	; 14/03/2021
  1801 000008B4 C744030000              	mov	word [si+ptBeginCylinder], 0
  1802 000008B9 C6440201                	mov	byte [si+ptBeginSector], 1
  1803 000008BD C6440101                	mov	byte [si+ptBeginHead], 1
  1804                                  
  1805                                  	; set active partition flag
  1806                                  	;mov	byte [si+ptBootable], 80h ; bootable/active partition
  1807 000008C1 C60480                  	mov	byte [si], 80h ; bootable/active partition
  1808                                  
  1809                                  	; 14/03/2021
  1810                                  	; 18/02/2019
  1811                                  	;mov	cx, [ppn_Sectors]
  1812                                  	;mov	bx, [ppn_Sectors+2]
  1813                                  
  1814 000008C4 803E[746D]00            	cmp	byte [wholedisk], 0
  1815 000008C9 0F865401                	jna	cpp_12
  1816                                  
  1817                                  	; 26/10/2020
  1818 000008CD 01C8                    	add	ax, cx
  1819 000008CF 11DA                    	adc	dx, bx
  1820 000008D1 83E801                  	sub	ax, 1
  1821 000008D4 83DA00                  	sbb	dx, 0 
  1822                                  
  1823                                  	; 24/10/2020
  1824 000008D7 3B16[E068]              	cmp	dx, [chs_limit+2]
  1825 000008DB 7217                    	jb	short cpp_17
  1826 000008DD 7706                    	ja	short cpp_16
  1827 000008DF 3B06[DE68]              	cmp	ax, [chs_limit]
  1828 000008E3 760F                    	jna	short cpp_17
  1829                                  cpp_16:
  1830 000008E5 C64405FE                	mov	byte [si+ptEndHead], 0FEh
  1831 000008E9 C64406FF                	mov	byte [si+ptEndSector], 0FFh
  1832 000008ED C64407FF                	mov	byte [si+ptEndCylinder], 0FFh
  1833 000008F1 E9C801                  	jmp	cpp_15
  1834                                  cpp_17:
  1835 000008F4 A0[703F]                	mov	al, [heads]
  1836 000008F7 FEC8                    	dec	al
  1837 000008F9 884405                  	mov	[si+ptEndHead], al
  1838 000008FC A0[6E3F]                	mov	al, [sectors]
  1839 000008FF 884406                  	mov	[si+ptEndSector], al
  1840 00000902 A1[723F]                	mov	ax, [cylinders]
  1841 00000905 48                      	dec	ax
  1842 00000906 884407                  	mov	[si+ptEndCylinder], al
  1843 00000909 C0E406                  	shl	ah, 6
  1844 0000090C 086406                  	or	[si+ptEndSector], ah		
  1845                                  
  1846                                  	;jmp	cpp_16
  1847 0000090F E9AA01                  	jmp	cpp_15 ; 06/03/2019	
  1848                                  cpp_5:
  1849                                  	; 18/02/2019
  1850 00000912 803E[0071]59            	cmp	byte [cylinder_boundary], 'Y'
  1851 00000917 753D                    	jne	short cpp_7
  1852                                  
  1853 00000919 30DB                    	xor	bl, bl ; head  = 0
  1854                                  
  1855 0000091B 8B8D[AE70]              	mov	cx, [di+free_space.start]
  1856                                  
  1857                                  	; 06/03/2019
  1858                                  	;or	ax, ax
  1859                                  	;jnz	short cpp_6
  1860                                  
  1861                                  	;and	cx, cx  ; start cylinder = 0 ?
  1862                                  	;jnz	short cpp_6
  1863                                  
  1864 0000091F 09C8                    	or	ax, cx
  1865                                  	;jnz	short cpp_6
  1866 00000921 740B                    	jz	short cpp_24 ; 31/10/2020
  1867                                  
  1868                                  	; 31/10/2020
  1869 00000923 A0[6E3F]                	mov	al, [sectors]
  1870 00000926 F626[703F]              	mul	byte [heads]
  1871 0000092A F7E1                    	mul	cx
  1872                                  	; dx:ax = LBA sector address
  1873                                  	; bl = head = 0
  1874                                  	; cx = cylinder number
  1875                                  	; ax = sector number
  1876 0000092C EB07                    	jmp	short cpp_6
  1877                                  cpp_24:
  1878 0000092E A1[6E3F]                	mov	ax, [sectors]
  1879                                  	; cylinder 0, head 1, sector 1 (LBA = 17 or 63)
  1880 00000931 FEC3                    	inc	bl  ; head = 1
  1881 00000933 31D2                    	xor	dx, dx ; 0
  1882                                  cpp_6:
  1883                                  	; 31/10/2020
  1884 00000935 894408                  	mov	[si+ptStartSector], ax
  1885 00000938 89540A                  	mov	[si+ptStartSector+2], dx
  1886                                  
  1887 0000093B A3[6C6D]                	mov	[pp_StartSector], ax
  1888 0000093E 8916[6E6D]              	mov	[pp_StartSector+2], dx
  1889                                  
  1890 00000942 09C9                    	or	cx, cx  ; start cylinder ?
  1891 00000944 7508                    	jnz	short cpp_25 ; > 0
  1892                                  	
  1893                                  	;and	bl, bl  ; head = 0 ?
  1894                                  	;jz	short cpp_25
  1895                                  
  1896                                  	; cylinder = 0, head = 1, dx:ax = [sectors]
  1897                                  
  1898                                  	;sub	[pp_Sectors], ax
  1899                                  	;sbb	[pp_Sectors+2], cx ; 0
  1900                                  
  1901 00000946 2906[9E6D]              	sub	[ppn_Sectors], ax
  1902 0000094A 190E[A06D]              	sbb	[ppn_Sectors+2], cx ; 0
  1903                                  cpp_25:
  1904 0000094E 89C8                    	mov	ax, cx
  1905                                  	; 29/10/2020
  1906 00000950 C6440201                	mov	byte [si+ptBeginSector], 1 ; sector = 1	
  1907 00000954 EB16                    	jmp	short cpp_8		
  1908                                  cpp_7:
  1909                                  	; 18/02/2019
  1910                                  
  1911                                  	; [wholedisk] = 0
  1912                                  
  1913                                  	; Fix partition size for MSDOS 3.3 (Retro DOS 3.0) compatibility.
  1914                                  	; (DOS partition size will be changed -down- to 65535 sectors,
  1915                                  	; if it is 65536 sectors.)
  1916                                  	
  1917 00000956 E87301                  	call	fix_32mb_dos_psize
  1918                                  		; bx:cx = [ppn_sectors] = partition size
  1919                                  		; dx:ax = start sector's LBA 
  1920                                  
  1921                                  	;cylinder = LBA / (heads_per_cylinder * sectors_per_track)
  1922                                  	;temp = LBA % (heads_per_cylinder * sectors_per_track)
  1923                                  	;head = temp / sectors_per_track
  1924                                  	;sector = temp % sectors_per_track + 1
  1925                                  	
  1926                                  	; Convert LBA sector address to CHS parameters
  1927 00000959 8B0E[6E3F]              	mov	cx, [sectors]
  1928 0000095D E81D03                  	call	div32
  1929                                  	; BX = Sector number - 1
  1930 00000960 FEC3                    	inc	bl ; sector number (1 based)
  1931 00000962 885C02                  	mov	[si+ptBeginSector], bl	
  1932                                  	; DX_AX = cylinders * heads + head
  1933 00000965 8B0E[703F]              	mov	cx, [heads]
  1934 00000969 E81103                  	call	div32
  1935                                  	; ax = cylinder
  1936                                  	; bl = head
  1937                                  cpp_8:
  1938                                  	; 24/10/2020
  1939                                  	;mov	bh, 1  ; [si+ptBeginSector]
  1940 0000096C 3DFF03                  	cmp	ax, 1023  ; CHS limit
  1941 0000096F 7609                    	jna	short cpp_18	
  1942                                  	; > CHS limit
  1943 00000971 B8FF03                  	mov	ax, 1023 ; cylinder
  1944 00000974 B3FE                    	mov	bl, 0FEh ; 254 (head)
  1945                                  	;mov	bh, 3Fh ; 63 (sector)
  1946                                  	; 26/10/2020
  1947 00000976 C644023F                	mov	byte [si+ptBeginSector], 3Fh			
  1948                                  cpp_18:
  1949                                  	; BL = Head number
  1950 0000097A 885C01                  	mov	[si+ptBeginHead], bl
  1951                                  	; AX = Cylinder number
  1952                                  	;and	ax, 1023
  1953 0000097D 884403                  	mov	[si+ptBeginCylinder], al
  1954 00000980 C0E406                  	shl	ah, 6
  1955                                  	; 24/10/2020
  1956                                  	;or	ah, bh	; bh = sector number
  1957                                  	; 26/10/2020
  1958 00000983 086402                  	or	[si+ptBeginSector], ah
  1959                                  	;mov	[si+ptBeginSector], ah
  1960                                  
  1961                                  	; clear active partition flag (for now)
  1962                                  	;mov	byte [si+ptBootable], 0 ; not bootable/active partition
  1963 00000986 C60400                  	mov	byte [si], 0 ; not bootable/active partition
  1964                                  
  1965                                  	;mov	di, [c_fspc_offset]
  1966                                  
  1967 00000989 803E[0071]59            	cmp	byte [cylinder_boundary], 'Y'
  1968 0000098E 0F858000                	jne	cpp_11
  1969                                  
  1970 00000992 8A0E[703F]              	mov	cl, [heads]
  1971 00000996 A0[6E3F]                	mov	al, [sectors]
  1972 00000999 88C5                    	mov	ch, al
  1973 0000099B F6E1                    	mul	cl	
  1974                                  	; ax = heads*sectors
  1975                                  
  1976 0000099D 8B9D[B070]              	mov	bx, [di+free_space.end]	; end cylinder of the partition
  1977                                  
  1978 000009A1 803E[746D]00            	cmp	byte [wholedisk], 0 ; entire free space ?
  1979 000009A6 7721                    	ja	short cpp_10
  1980                                  
  1981 000009A8 89C3                    	mov	bx, ax
  1982 000009AA A1[9E6D]                	mov	ax, [ppn_Sectors]
  1983 000009AD 8B16[A06D]              	mov	dx, [ppn_Sectors+2]
  1984 000009B1 0306[6C6D]              	add	ax, [pp_StartSector]
  1985 000009B5 1316[6E6D]              	adc	dx, [pp_StartSector+2]
  1986 000009B9 83E801                  	sub	ax, 1
  1987 000009BC 83DA00                  	sbb	dx, 0
  1988                                  		; dx:ax = end sector
  1989 000009BF F7F3                    	div	bx
  1990                                  		; ax = cylinder number
  1991                                  	; 31/10/2020
  1992                                  	;and	dx, dx
  1993                                  	;jz	short cpp_9
  1994                                  	;inc	ax ; + 1 (because of remainder > 0)
  1995                                  cpp_9:	
  1996 000009C1 93                      	xchg	ax, bx
  1997                                  		; bx = end cylinder
  1998                                  		; ax = heads*sectors
  1999                                  	; free space limit check
  2000 000009C2 3B9D[B070]              	cmp	bx, [di+free_space.end]
  2001 000009C6 7601                    	jna	short cpp_10 ; ok
  2002                                  	; end cylinder is out of free space	
  2003 000009C8 4B                      	dec	bx  ; decrease end cylinder number
  2004                                  cpp_10: 
  2005 000009C9 F7E3                    	mul	bx
  2006                                  		 ; dx:ax = (end cylinder)*heads*sectors
  2007 000009CB 52                      	push	dx ; **
  2008 000009CC 50                      	push	ax ; *
  2009                                  
  2010                                  	; 24/10/2020
  2011 000009CD 81FBFF03                	cmp	bx, 1023  ; CHS limit
  2012 000009D1 7606                    	jna	short cpp_19	
  2013                                  	; > CHS limit
  2014 000009D3 BBFF03                  	mov	bx, 1023 ; cylinder
  2015                                  	;mov	cl, 0FFh ; 255 (head+1)
  2016                                  	;mov	ch, 3Fh ; 63 (sector)
  2017 000009D6 B9FF3F                  	mov	cx, 3FFFh		
  2018                                  cpp_19:
  2019 000009D9 FEC9                    	dec	cl ; heads - 1 = end head
  2020                                  
  2021 000009DB 884C05                  	mov	[si+ptEndHead], cl
  2022                                  	; 26/10/2020		
  2023                                  	;mov	al, [sectors]
  2024                                  	; 31/10/2020
  2025 000009DE 88E8                    	mov	al, ch
  2026 000009E0 885C07                  	mov	[si+ptEndCylinder], bl
  2027                                  	;mov	bl, al
  2028                                  	;shl	bh, 6 ; shift high bytes (2 bits) of end cyl num
  2029                                  	;	      ; to 6 bits left	
  2030                                  	;or	bh, bl ; combine high bits of end cyl num and end sector		
  2031 000009E3 C0E706                  	shl	bh, 6
  2032 000009E6 08EF                    	or	bh, ch ; ch = end sector (= sectors)
  2033 000009E8 887C06                  	mov	[si+ptEndSector], bh
  2034                                  
  2035                                  	; 24/10/2020
  2036                                  	;mov	bl, [sectors]
  2037                                  	;xor	bh, bh ; clear bh
  2038 000009EB 8B1E[6E3F]              	mov	bx, [sectors] ; 17 or 63
  2039                                  
  2040 000009EF FECB                    	dec	bl ; sectors - 1 ; 22/02/2019
  2041 000009F1 F6E1                    	mul	cl ; sectors * [end head]
  2042 000009F3 5A                      	pop	dx ; *
  2043                                  	; 22/02/2019
  2044 000009F4 31C9                    	xor	cx, cx
  2045 000009F6 01D0                    	add	ax, dx
  2046 000009F8 5A                      	pop	dx ; **
  2047 000009F9 11CA                    	adc	dx, cx ; 0
  2048 000009FB 01D8                    	add	ax, bx
  2049 000009FD 11CA                    	adc	dx, cx ; 0
  2050                                  	; dx:ax = ((([end cylinder]*heads)+[end head])*sectors)+sectors-1
  2051                                  
  2052                                  	; calculate aligned partition size in sectors
  2053 000009FF 89C1                    	mov	cx, ax
  2054 00000A01 89D3                    	mov	bx, dx
  2055 00000A03 83C101                  	add	cx, 1
  2056 00000A06 83D300                  	adc	bx, 0	
  2057 00000A09 2B4C08                  	sub	cx, [si+ptStartSector]
  2058 00000A0C 1B5C0A                  	sbb	bx, [si+ptStartSector+2]
  2059                                  		; bx:cx = partition size
  2060                                  	;mov	[ppn_Sectors], cx
  2061                                  	;mov	[ppn_Sectors+2], bx
  2062                                  	;jmp	cpp_16
  2063 00000A0F E9AA00                  	jmp	cpp_15 ; 06/03/2019
  2064                                  cpp_11:
  2065                                  	; 20/02/2019
  2066 00000A12 8B0E[9E6D]              	mov	cx, [ppn_Sectors]
  2067 00000A16 8B1E[A06D]              	mov	bx, [ppn_Sectors+2]
  2068                                  
  2069                                  	;;mov	ax, [di+free_space.startsector]
  2070                                  	;;mov	ax, [di+free_space.startsector+2]
  2071                                  	;mov	ax, [si+ptStartSector]
  2072                                  	;mov	dx, [si+ptStartSector+2]
  2073 00000A1A A1[6C6D]                	mov	ax, [pp_StartSector]
  2074 00000A1D 8B16[6E6D]              	mov	dx, [pp_StartSector+2]
  2075                                  cpp_12:	
  2076                                  	; 18/02/2019
  2077                                  
  2078                                  	; [wholedisk] = 0
  2079                                  
  2080                                  	; Fix partition size for MSDOS 3.3 (Retro DOS 3.0) compatibility.
  2081                                  	; (DOS partition size will be changed -down- to 65535 sectors,
  2082                                  	; if it is 65536 sectors.)
  2083                                  
  2084 00000A21 E8A800                  	call	fix_32mb_dos_psize
  2085                                  		; bx:cx = [ppn_sectors] = partition size
  2086                                  		; dx:ax = start sector's LBA
  2087                                  
  2088 00000A24 01C8                    	add	ax, cx
  2089 00000A26 11DA                    	adc	dx, bx
  2090                                  
  2091                                  	; Convert LBA sector address to CHS parameters
  2092 00000A28 83E801                  	sub	ax, 1 ; locate on to end sector of the partition
  2093 00000A2B 83DA00                  	sbb	dx, 0
  2094                                  
  2095                                  	; 06/03/2019
  2096 00000A2E 803E[0071]59            	cmp	byte [cylinder_boundary],'Y'
  2097                                  	;jne	short cpp_15
  2098 00000A33 754D                    	jne	short cpp_14
  2099                                  
  2100 00000A35 89C1                    	mov	cx, ax
  2101 00000A37 A0[703F]                	mov	al, [heads]
  2102 00000A3A F626[6E3F]              	mul	byte [sectors]
  2103 00000A3E 89C7                    	mov	di, ax ; [heads]*[sectors]
  2104 00000A40 91                      	xchg	ax, cx
  2105                                  		; cx = heads*spt
  2106                                  
  2107 00000A41 E83902                  	call	div32
  2108                                  		; dx = 0
  2109                                  		; ax = end cylinder
  2110                                  		; bx = remainder	
  2111                                  	;and	bx, bx
  2112                                  	;jz	short cpp_13
  2113                                  	;inc	ax
  2114                                  ;cpp_13:
  2115                                  	;cmp	ax, [cylinders]
  2116                                  	;jb	short cpp_14
  2117                                  	;dec	ax
  2118                                  ;cpp_14:
  2119                                  
  2120                                  	; 26/10/2020
  2121 00000A44 3DFF03                  	cmp	ax, 1023
  2122 00000A47 760E                    	jna	short cpp_20
  2123                                  
  2124 00000A49 C64405FE                	mov	byte [si+ptEndHead], 0FEh
  2125 00000A4D C64406FF                	mov	byte [si+ptEndSector], 0FFh
  2126 00000A51 C64407FF                	mov	byte [si+ptEndCylinder], 0FFh
  2127 00000A55 EB1A                    	jmp	short cpp_21
  2128                                  cpp_20:
  2129 00000A57 8B1E[703F]              	mov	bx, [heads]
  2130 00000A5B FECB                    	dec	bl
  2131 00000A5D 885C05                  	mov	[si+ptEndHead], bl
  2132 00000A60 8B0E[6E3F]              	mov	cx, [sectors]
  2133 00000A64 88E2                    	mov	dl, ah
  2134 00000A66 C0E206                  	shl	dl, 6
  2135 00000A69 08CA                    	or	dl, cl
  2136 00000A6B 885406                  	mov	[si+ptEndSector], dl
  2137 00000A6E 884407                  	mov	[si+ptEndCylinder], al	
  2138                                  	;mul	di ; [cylinders]*[heads]*[sectors]
  2139                                  	;;sub	di, cx ; ([heads] - 1) * [sectors]
  2140                                  	;add	ax, di
  2141                                  	;adc	dx, 0
  2142                                  	;;add	ax, cx
  2143                                  	;;adc	dx, 0
  2144                                  cpp_21:
  2145 00000A71 40                      	inc	ax
  2146 00000A72 F7E7                    	mul	di  ; result = start LBA of next cylinder
  2147                                  	; dx:ax = end sector LBA + 1 (as cyl. boundary aligned)
  2148 00000A74 2B06[6C6D]              	sub	ax, [pp_StartSector]
  2149 00000A78 1B16[6E6D]              	sbb	dx, [pp_StartSector+2]
  2150                                  
  2151 00000A7C 89C1                    	mov	cx, ax
  2152 00000A7E 89D3                    	mov	bx, dx
  2153                                  	;jmp	short cpp_16
  2154 00000A80 EB3A                    	jmp	short cpp_15
  2155                                  ;cpp_15:
  2156                                  cpp_14:
  2157 00000A82 8B0E[6E3F]              	mov	cx, [sectors]
  2158 00000A86 E8F401                  	call	div32
  2159                                  	; BX = Sector number - 1
  2160 00000A89 FEC3                    	inc	bl ; sector number (1 based)
  2161 00000A8B 885C06                  	mov	[si+ptEndSector], bl	
  2162                                  	; DX_AX = cylinders * heads + head
  2163 00000A8E 8B0E[703F]              	mov	cx, [heads]
  2164 00000A92 E8E801                  	call	div32
  2165                                  	; BX = Head number
  2166 00000A95 885C05                  	mov	[si+ptEndHead], bl
  2167                                  	; AX = Cylinder number
  2168                                  	;and	ax, 1023
  2169                                  
  2170                                  	; 26/10/2020
  2171 00000A98 3DFF03                  	cmp	ax, 1023
  2172 00000A9B 760E                    	jna	short cpp_22
  2173                                  		
  2174 00000A9D C64405FE                	mov	byte [si+ptEndHead], 0FEh
  2175 00000AA1 C64406FF                	mov	byte [si+ptEndSector], 0FFh
  2176 00000AA5 C64407FF                	mov	byte [si+ptEndCylinder], 0FFh
  2177 00000AA9 EB09                    	jmp	short cpp_23
  2178                                  cpp_22:
  2179 00000AAB 884407                  	mov	[si+ptEndCylinder], al
  2180                                  	; 18/02/2019
  2181 00000AAE C0E406                  	shl	ah, 6
  2182 00000AB1 086406                  	or	[si+ptEndSector], ah
  2183                                  cpp_23:
  2184 00000AB4 8B0E[9E6D]              	mov	cx, [ppn_Sectors]
  2185 00000AB8 8B1E[A06D]              	mov	bx, [ppn_Sectors+2]
  2186                                  ;cpp_16:
  2187                                  cpp_15:
  2188 00000ABC 894C0C                  	mov	[si+ptSectors], cx
  2189 00000ABF 895C0E                  	mov	[si+ptSectors+2], bx
  2190                                  
  2191                                  	; set partition ID after checking DOS FAT limits
  2192 00000AC2 E8EF00                  	call	set_partition_id
  2193                                  	; al = partition ID
  2194                                  
  2195 00000AC5 A2[756D]                	mov	[pp_type], al
  2196                                  
  2197 00000AC8 884404                  	mov	[si+ptFileSystemID], al
  2198                                  
  2199 00000ACB C3                      	retn
  2200                                  
  2201                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2202                                  ; decrease DOS partition size when it is (exact) 65536 sectors
  2203                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2204                                  ; 18/02/2019
  2205                                  
  2206                                  fix_32mb_dos_psize:	; call this if [wholedisk] = 0
  2207                                  
  2208                                  ; Purpose: 
  2209                                  ;	If a DOS partition's size is 65536 sectors
  2210                                  ;	MSDOS 3.3 can not use it. (FAT 16 partition ID = 06h)
  2211                                  ;	Decreasing partition size to 65535 sectors will ensure
  2212                                  ;	MSDOS 3.3 compatibility (FAT 16 partition ID will be 04h).			
  2213                                  
  2214                                  	; INPUT:
  2215                                  	;    BX:CX = partition size in sectors
  2216                                  	;    [pp_type] = partition type dos, non-dos, user input
  2217                                  	;
  2218                                  	; OUTPUT:
  2219                                  	;    Partition size will be changed to 65535 sectors, if
  2220                                  	;    	- partition size is 65536 sectors and
  2221                                  	; 	- [pp_type] is 1 (DOS)
  2222                                  	;
  2223                                  	;    [ppn_Sectors] = 65535 (if it will be changed)
  2224                                  	;
  2225                                  	; (Modified registers: cx, bx) 
  2226                                  
  2227                                  	;mov	cx, [ppn_Sectors]
  2228                                  	;mov	bx, [ppn_Sectors+2]
  2229                                  
  2230 00000ACC 803E[756D]01            	cmp	byte [pp_type], 1 ;  DOS partition
  2231 00000AD1 7513                    	jne	short psfx_0  ; non-dos partition or user input
  2232                                  			      ; nothing to do ! 	
  2233 00000AD3 09C9                    	or	cx, cx
  2234 00000AD5 750F                    	jnz	short psfx_0 ; <> 65536 sectors
  2235 00000AD7 83FB01                  	cmp	bx, 1
  2236 00000ADA 750A                    	jne	short psfx_0
  2237 00000ADC 4B                      	dec	bx
  2238                                  	;mov	[wholedisk], bx ; 0
  2239 00000ADD 49                      	dec	cx  ; bx:cx = 65535
  2240 00000ADE 890E[9E6D]              	mov	[ppn_Sectors], cx
  2241 00000AE2 891E[A06D]              	mov	[ppn_Sectors+2], bx
  2242                                  psfx_0:
  2243 00000AE6 C3                      	retn
  2244                                  
  2245                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2246                                  ; create extended dos partition
  2247                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2248                                  ; 24/10/2020 (fdisk3.s)
  2249                                  
  2250                                  ; 16/02/2019 (hdimage.s) 
  2251                                  ;	(This procedure must be called after 'find_part_free_space')
  2252                                  
  2253                                  create_extended_partition:  
  2254                                  	; 15/02/2019
  2255                                  
  2256                                  	; INPUT:
  2257                                  	;	none 
  2258                                  	;  (CHS parameters and free space calculation result will be used.) 
  2259                                  	;
  2260                                  	; OUTPUT:
  2261                                  	;	Partition table in MBR buffer will be updated.
  2262                                  	;
  2263                                  	; (Modified registers: ax, bx, cx, dx, si, di)
  2264                                  
  2265                                  	; Create extended dos partition, make partition table entry
  2266                                  	; (Extended partition will be created on cylinder bounds.)
  2267                                  
  2268                                  	; 16/02/2019
  2269 00000AE7 E8B21C                  	call	get_first_free_pte
  2270                                  		 ; CX = First free PTE number, 0 to 3 
  2271                                  		 ;    (CX = 3 if there is not a free PTE, and CF = 1)
  2272                                  		 ;    ((But CF = 1 is not possible here because pcount < 4))
  2273                                   	 	 ; SI = PTE addres/offset in MBR buffer
  2274                                  
  2275                                  	;mov	si, MasterBootBuff+pTableOffset
  2276                                  	;shl	cl, 4 ; * 16
  2277                                  	;add	si, cx
  2278                                  	
  2279 00000AEA 8B1E[FE70]              	mov	bx, [c_fspc_offset]
  2280                                  	
  2281 00000AEE 8B87[AE70]              	mov	ax, [bx+free_space.start]
  2282                                  
  2283                                  	; 24/10/2020
  2284 00000AF2 89C7                    	mov	di, ax
  2285                                  	;mov	cx, 1
  2286 00000AF4 B101                    	mov	cl, 1 ; head (ch) = 0, sector (cl) = 1
  2287                                  
  2288 00000AF6 3DFF03                  	cmp	ax, 1023
  2289 00000AF9 7606                    	jna	short cep_4
  2290                                  
  2291                                  	; partition start  > CHS limit
  2292 00000AFB B8FF03                  	mov	ax, 1023
  2293                                  	;mov	ch, 254
  2294                                  	;mov	cl, 63
  2295 00000AFE B93FFE                  	mov	cx, 0FE3Fh
  2296                                  cep_4:	
  2297                                  	;mov	byte [si+ptBootable], 0 ; not bootable/active partition
  2298                                  	;mov	[si], ch ; 0 ; not bootable/active partition
  2299                                  	; 26/10/2020
  2300 00000B01 C60400                  	mov	byte [si], 0
  2301 00000B04 886C01                  	mov	[si+ptBeginHead], ch
  2302 00000B07 C0E406                  	shl	ah, 6
  2303 00000B0A 08E1                    	or	cl, ah
  2304 00000B0C 884C02                  	mov	[si+ptBeginSector], cl ; Sector 1 
  2305 00000B0F 884403                  	mov	[si+ptBeginCylinder], al
  2306                                  
  2307 00000B12 A0[703F]                	mov	al, [heads]
  2308 00000B15 F626[6E3F]              	mul	byte [sectors]
  2309                                  		; ax = heads*sectors
  2310 00000B19 F7E7                    	mul	di  ; AX * cylinder count before start cylinder
  2311                                  		; DX:AX = LBA of cylinder DI, head 0, sector 1 
  2312                                  
  2313 00000B1B 894408                  	mov	[si+ptStartSector], ax
  2314 00000B1E 89540A                  	mov	[si+ptStartSector+2], dx
  2315                                  
  2316                                  	; This is not needed for extended partition.
  2317                                  	; 16/02/2019
  2318                                  	;mov	[pp_StartSector], ax
  2319                                  	;mov	[pp_StartSector+2], dx
  2320                                  
  2321                                  	; 16/02/2019
  2322 00000B21 803E[746D]00            	cmp	byte [wholedisk], 0
  2323 00000B26 772A                    	ja	short cep_2 ; all of free space will be used
  2324                                  			    ; ([bx+free_space.end] will be end cyl)	
  2325                                  
  2326                                  	; calculate cylinder count (from partition size input)
  2327 00000B28 A0[703F]                	mov	al, [heads]
  2328 00000B2B F626[6E3F]              	mul	byte [sectors]
  2329 00000B2F 89C1                    	mov	cx, ax
  2330 00000B31 A1[9E6D]                	mov	ax, [ppn_Sectors]
  2331 00000B34 8B16[A06D]              	mov	dx, [ppn_Sectors+2]
  2332 00000B38 E84201                  	call	div32
  2333                                  		; ax = cylinders
  2334                                  		; bx = remainder
  2335 00000B3B 21DB                    	and	bx, bx
  2336 00000B3D 7401                    	jz	short cep_1
  2337                                  
  2338 00000B3F 40                      	inc	ax  ; round up
  2339                                  cep_1:
  2340                                  	; 16/02/2019
  2341                                  	; DI  = extended partition's start cylinder
  2342 00000B40 89C2                    	mov	dx, ax ; cylinder count
  2343 00000B42 01FA                    	add	dx, di ; result is end cyl + 1
  2344 00000B44 4A                      	dec	dx ; decrease number for current end cylinder
  2345 00000B45 8B1E[FE70]              	mov	bx, [c_fspc_offset]
  2346 00000B49 3B97[B070]              	cmp	dx, [bx+free_space.end]
  2347 00000B4D 7607                    	jna	short cep_3
  2348                                  	; 24/10/2020
  2349                                  	;dec	ax ; decrease cylinder count down to the limit
  2350 00000B4F 4A                      	dec	dx ; decrease end cylinder down to the limit		  
  2351 00000B50 EB04                    	jmp	short cep_3 	
  2352                                  cep_2:
  2353 00000B52 8B97[B070]              	mov	dx, [bx+free_space.end]
  2354                                  	;mov	ax, [bx+free_space.space]
  2355                                  cep_3:
  2356                                  	; 24/10/2020
  2357 00000B56 89D0                    	mov	ax, dx ; end cylinder
  2358 00000B58 B305                    	mov	bl, 05h	; Extended Partition ID (CHS)
  2359 00000B5A 3DFF03                  	cmp	ax, 1023
  2360 00000B5D 760A                    	jna	short cep_5
  2361                                  
  2362                                  	; partition end > CHS limit
  2363 00000B5F B8FF03                  	mov	ax, 1023
  2364                                  	;mov	ch, 254
  2365                                  	;mov	cl, 63
  2366 00000B62 B93FFE                  	mov	cx, 0FE3Fh
  2367 00000B65 B30F                    	mov	bl, 0Fh	; Extended Partition ID (LBA)
  2368 00000B67 EB0A                    	jmp	short cep_6
  2369                                  cep_5:
  2370 00000B69 8A2E[703F]              	mov	ch, [heads]
  2371 00000B6D FECD                    	dec	ch 
  2372 00000B6F 8A0E[6E3F]              	mov	cl, [sectors]
  2373                                  cep_6:
  2374 00000B73 886C05                  	mov	[si+ptEndHead], ch
  2375                                  	; 24/10/2020
  2376                                  	; ax = (chs limit compatible) end cylinder (<= 1023)
  2377                                  	; 23/02/2019
  2378                                  	;mov	bl, dh
  2379                                  	;shl	bl, 6
  2380                                  	;or	bl, cl
  2381 00000B76 C0E406                  	shl	ah, 6
  2382 00000B79 08E1                    	or	cl, ah
  2383                                  	;mov	[si+ptEndSector], bl
  2384 00000B7B 884C06                  	mov	[si+ptEndSector], cl	
  2385                                  	;mov	[si+ptEndCylinder], dl
  2386 00000B7E 884407                  	mov	[si+ptEndCylinder], al
  2387                                  	; dx = (lba compatible) end cylinder (up to 65535)
  2388                                  
  2389                                  	;mov	al, [heads]
  2390                                  	; 26/10/2020
  2391                                  	;;mul	cl
  2392                                  	;mul	byte [sectors]
  2393 00000B81 8A2E[703F]              	mov	ch, [heads]
  2394 00000B85 A0[6E3F]                	mov	al, [sectors]
  2395 00000B88 F6E5                    	mul	ch	
  2396                                  	; ax = heads*sectors	
  2397 00000B8A F7E2                    	mul	dx ; AX * cylinder count before end cylinder
  2398                                  		; DX:AX = LBA of cylinder DX, head 0, sector 1 		
  2399 00000B8C 52                      	push	dx
  2400 00000B8D 50                      	push	ax
  2401 00000B8E 88E8                    	mov	al, ch
  2402 00000B90 FEC8                    	dec	al ; 26/10/2020 ; [heads] - 1
  2403 00000B92 8B0E[6E3F]              	mov	cx, [sectors]  ; 63 or 17	 	
  2404 00000B96 F6E1                    	mul	cl
  2405                                  		; ax = (heads-1)*sectors
  2406 00000B98 5A                      	pop	dx
  2407 00000B99 01D0                    	add	ax, dx
  2408 00000B9B 5A                      	pop	dx
  2409 00000B9C 83D200                  	adc	dx, 0
  2410                                  		; dx:ax = ((end cylinder)*heads)+(heads-1)*sectors
  2411 00000B9F 01C8                    	add	ax, cx
  2412 00000BA1 83D200                  	adc	dx, 0
  2413                                  	; dx:ax = (((end cylinder)*heads)+(heads-1)*sectors) + sectors
  2414                                  	; dx:ax = LBA of the partition's end sector + 1
  2415 00000BA4 2B4408                  	sub	ax, [si+ptStartSector]
  2416 00000BA7 1B540A                  	sbb	dx, [si+ptStartSector+2] 
  2417                                  
  2418 00000BAA 89440C                  	mov	[si+ptSectors], ax
  2419 00000BAD 89540E                  	mov	[si+ptSectors+2], dx
  2420                                  
  2421                                  	;mov	[pp_type], al
  2422                                  
  2423                                  	;mov	byte [si+ptFileSystemID], 5
  2424                                  	; 24/10/2020
  2425 00000BB0 885C04                  	mov	 [si+ptFileSystemID], bl ; 05h or 0Fh
  2426                                  	
  2427 00000BB3 C3                      	retn
  2428                                  
  2429                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2430                                  ; set DOS (and non-dos) partition ID according to partition size
  2431                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2432                                  ; 23/10/2020
  2433                                  
  2434                                  set_partition_id: 
  2435                                  	; 23/10/2020 (fdisk3.s)
  2436                                  	; input:
  2437                                  	;   si = partition table offset
  2438                                  	;   bx:cx = partition size
  2439                                  
  2440                                  	; 18/02/2019 (hdimage.s)
  2441                                  	;mov	cx, [ppn_Sectors]
  2442                                  	;mov	bx, [ppn_Sectors+2]
  2443                                  
  2444 00000BB4 A0[756D]                	mov	al, [pp_type]
  2445                                  
  2446                                  	;cmp	byte [pp_type], 1
  2447 00000BB7 3C01                    	cmp	al, 1 ; primary DOS (FAT12, FAT16, FAT32)
  2448 00000BB9 7519                    	jne	short spid_2 ; singlix, runix or user type 
  2449                                  
  2450                                  	;mov	al, 1	; FAT12
  2451                                  
  2452 00000BBB 09DB                    	or	bx, bx
  2453 00000BBD 750A                    	jnz	short spid_1
  2454                                  
  2455 00000BBF 81F9A87F                	cmp	cx, 32680
  2456                                  	;jna	short spid_8	; FAT12 file system
  2457 00000BC3 761C                    	jna	short spid_19 ; 23/10/2020
  2458                                  
  2459 00000BC5 B004                    	mov	al, 4	; FAT16 (< 32MB)
  2460                                  
  2461 00000BC7 EB39                    	jmp	short spid_8	; FAT16 (CHS) file system
  2462                                  
  2463                                  spid_1:
  2464 00000BC9 B00B                    	mov	al, 0Bh ; FAT32 (CHS)
  2465                                  
  2466 00000BCB 83FB10                  	cmp	bx, 10h
  2467 00000BCE 7332                    	jnb	short spid_8	; FAT32 (CHS) file system	
  2468                                  
  2469 00000BD0 B006                    	mov	al, 6	; FAT16 (>= 32MB)
  2470                                  
  2471 00000BD2 EB2E                    	jmp	short spid_8	; FAT16 big (CHS) file system
  2472                                  
  2473                                  spid_2:
  2474                                  	;cmp	byte [pp_type], 2 ; Singlix FS
  2475 00000BD4 3C02                    	cmp	al, 2
  2476 00000BD6 7503                    	jne	short spid_3
  2477 00000BD8 B0A1                    	mov	al, 0A1h
  2478                                  	;jmp	short spid_8
  2479 00000BDA C3                      	retn	; 23/10/2020
  2480                                  spid_3:
  2481                                  	;cmp	byte [pp_type], 3 ; Retro Unix FS
  2482 00000BDB 3C03                    	cmp	al, 3
  2483 00000BDD 7503                    	jne	short spid_4
  2484 00000BDF B071                    	mov	al, 71h	
  2485                                  	;jmp	short spid_8
  2486                                  spid_19:
  2487 00000BE1 C3                      	retn
  2488                                  
  2489                                  spid_4:
  2490                                  	; another partition type (user input)
  2491                                  	
  2492                                  	; [pp_type] = 4
  2493                                  
  2494 00000BE2 A0[766D]                	mov	al, [pp_type_user]
  2495                                  
  2496                                  	; Check FAT12 fs size validation
  2497                                  
  2498 00000BE5 3C01                    	cmp	al, 1 ; FAT12
  2499 00000BE7 7737                    	ja	short spid_9
  2500                                  
  2501 00000BE9 21DB                    	and	bx, bx
  2502 00000BEB 750A                    	jnz	short spid_6
  2503                                  
  2504 00000BED 81F9A87F                	cmp	cx, 32680
  2505                                  	;jna	short spid_8
  2506 00000BF1 76EE                    	jna	short spid_19 ; 23/10/2020 
  2507                                  spid_5:
  2508 00000BF3 B004                    	mov	al, 4 ; FAT16 (<= 32MB) 
  2509 00000BF5 EB0B                    	jmp	short spid_8
  2510                                  spid_6:
  2511                                  	;;cmp	bx, 10h	; 512MB (16*32MB)
  2512                                  	; 15/03/2021
  2513 00000BF7 83FB40                  	cmp	bx, 40h ; 2GB (64*32MB)
  2514 00000BFA 7304                    	jnb	short spid_7
  2515                                  	
  2516 00000BFC B006                    	mov	al, 6
  2517 00000BFE EB02                    	jmp	short spid_8
  2518                                  spid_7:
  2519 00000C00 B00B                    	mov	al, 0Bh ; FAT32 (CHS) partition
  2520                                  spid_8:
  2521                                  	; 23/10/2020
  2522                                  	; check the partition's end sector against CHS limit and
  2523                                  	; convert partition ID if the partition overs CHS limit
  2524                                  	;cmp	al, 1  ; FAT12 fs
  2525                                  	;je	short spid_19 ; nothing to do (for FAT12 fs)
  2526 00000C02 034C08                  	add	cx, [si+ptStartSector]
  2527 00000C05 135C0A                  	adc	bx, [si+ptStartSector+2]
  2528 00000C08 3B1E[E068]              	cmp	bx, [chs_limit+2] ; 07/11/2020
  2529 00000C0C 72D3                    	jb	short spid_19 ; partition's end sector is in CHS limit 
  2530 00000C0E 7706                    	ja	short spid_17 ; out of CHS limit	
  2531 00000C10 3B0E[DE68]              	cmp	cx, [chs_limit]
  2532 00000C14 76CB                    	jna	short spid_19 ; partition's end sector is in CHS limit
  2533                                  spid_17:
  2534                                  	; out of CHS limit, partition ID conversion is needed
  2535 00000C16 3C0B                    	cmp	al, 0Bh	; FAT32 CHS
  2536 00000C18 7203                    	jb	short spid_18
  2537 00000C1A B00C                    	mov	al, 0Ch	; FAT 32 LBA
  2538 00000C1C C3                      	retn
  2539                                  spid_18:
  2540 00000C1D B00E                    	mov	al, 0Eh ; FAT16 LBA
  2541 00000C1F C3                      	retn
  2542                                  spid_9:
  2543 00000C20 3C04                    	cmp	al, 4 ; FAT16 (< 32 MB)
  2544 00000C22 750C                    	jne	short spid_10
  2545                                  
  2546 00000C24 09DB                    	or	bx, bx
  2547 00000C26 75CF                    	jnz	short spid_6
  2548                                  
  2549                                  	; 15/03/2021
  2550 00000C28 81F93610                	cmp	cx, 4150 ; 4085 + 32 + 32 + 1
  2551 00000C2C 7217                    	jb	short spid_12
  2552                                  	
  2553                                  	;retn	; FAT16 (< 32 MB) partition
  2554 00000C2E EBD2                    	jmp	short spid_8  ; 23/10/2020
  2555                                  
  2556                                  spid_10:
  2557 00000C30 3C06                    	cmp	al, 6 ; FAT 16 big partition
  2558 00000C32 7514                    	jne	short spid_13 ; Extended partition or another type
  2559                                  	
  2560 00000C34 21DB                    	and	bx, bx
  2561 00000C36 7407                    	jz	short spid_11
  2562                                  
  2563                                  	;cmp	bx, 10h	; 512MB (16*32MB)
  2564                                  	; 15/03/2021
  2565 00000C38 83FB40                  	cmp	bx, 40h ; 2GB (64*32MB)
  2566 00000C3B 73C3                    	jnb	short spid_7
  2567                                  
  2568                                  	;retn
  2569 00000C3D EBC3                    	jmp	short spid_8 ; 23/10/2020
  2570                                  
  2571                                  spid_11:
  2572                                  	;cmp	ax, 4150 ; 4085 + 32 + 32 + 1
  2573 00000C3F 81F93610                	cmp	cx, 4150 ; 14/09/2020 (BugFix)
  2574 00000C43 73AE                    	jnb	short spid_5
  2575                                  spid_12:
  2576 00000C45 B001                    	mov	al, 1 ;  FAT12 partition
  2577                                  spid_16:
  2578 00000C47 C3                      	retn
  2579                                  spid_13:
  2580                                  	; 14/09/2020
  2581 00000C48 3C0B                    	cmp	al, 0Bh ; FAT 32 (CHS) partition
  2582 00000C4A 7420                    	je	short spid_15 ; FAT 32 CHS
  2583 00000C4C 3C0C                    	cmp	al, 0Ch	 
  2584 00000C4E 750C                    	jne	short spid_14 
  2585                                  	; FAT 32 LBA
  2586 00000C50 21DB                    	and	bx, bx	; < 33 MB
  2587 00000C52 74EB                    	jz	short spid_11 ; force to FAT 16 CHS or FAT 12
  2588 00000C54 83FB10                  	cmp	bx, 10h ; 512 MB
  2589                                  	;jnb	short spid_8  ; OK, FAT 32 LBA has been confirmed
  2590 00000C57 73EE                    	jnb	short spid_16 ; 23/10/2020
  2591 00000C59 B00E                    	mov	al, 0Eh ; force to FAT 16 LBA
  2592 00000C5B C3                      	retn
  2593                                  spid_14:
  2594                                  	; 14/09/2020
  2595 00000C5C 3C0E                    	cmp	al, 0Eh
  2596                                  	;jne	short spid_8 ; non-dos or extended partition
  2597 00000C5E 75E7                    	jne	short spid_16 ; 23/10/2020
  2598                                  	; FAT 16 LBA
  2599 00000C60 09DB                    	or	bx, bx
  2600 00000C62 74DB                    	jz	short spid_11
  2601                                  	; 23/10/2020
  2602 00000C64 83FB20                  	cmp	bx, 20h ; 1 GB
  2603 00000C67 72DE                    	jb	short spid_16
  2604 00000C69 B00C                    	mov	al, 0Ch	; FAT 32 LBA
  2605 00000C6B C3                      	retn
  2606                                  spid_15:
  2607                                  	; Minimum size of FAT 32 FS = 65525 + 512 + 512 + 32
  2608                                   	; >= 66581 sectors (or >= 65525 data clusters)
  2609 00000C6C 83FB01                  	cmp	bx, 1
  2610 00000C6F 72CE                    	jb	short spid_11  ; invalid! (< 33 MB)
  2611 00000C71 778F                    	ja	short spid_8
  2612 00000C73 81F91504                	cmp	cx, 1045
  2613                                  	;jb	short spid_16  ; invalid! (< 33 MB)
  2614                                  	;retn
  2615                                  	;jmp	short spid_8 ; 23/10/2020
  2616 00000C77 7389                    	jnb	short spid_8
  2617                                  ;spid_16:
  2618 00000C79 B006                    	mov	al, 6
  2619                                  	;retn
  2620 00000C7B EB85                    	jmp	short spid_8 ; 23/10/2020
  2621                                  
  2622                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2623                                  ; 32 bit division by using 16 bit registers
  2624                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2625                                  
  2626                                  div32:
  2627                                  	; DX_AX/CX
  2628                                  	; Result: DX_AX, BX (remainder) 
  2629 00000C7D 89C3                    	mov	bx, ax
  2630                                  	;or	dx, ax ; * DX_AX = 0 ?       
  2631                                  	;jz	short div32_retn ; yes, do not divide! 
  2632 00000C7F 89D0                    	mov	ax, dx
  2633 00000C81 31D2                            xor	dx, dx
  2634 00000C83 F7F1                            div	cx	; at first, divide DX
  2635                                  			; remainder is in DX 
  2636 00000C85 93                      	xchg	ax, bx	; now quotient is in BX
  2637                                    			; and initial AX value is in AX
  2638 00000C86 F7F1                    	div	cx	; now, DX_AX has been divided and
  2639                                  			; AX has quotient
  2640                                  			; DX has remainder
  2641 00000C88 87D3                    	xchg	dx, bx	; finally, BX has remainder
  2642                                  ;div32_retn:
  2643 00000C8A C3                              retn
  2644                                  
  2645                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2646                                  ; 32 bit multiplication by using 16 bit registers
  2647                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2648                                  
  2649                                  mul32:
  2650                                  	; DX_AX*CX
  2651                                  	; Result: BX_DX_AX 
  2652 00000C8B 51                      	push	cx
  2653 00000C8C 89D3                    	mov	bx, dx
  2654 00000C8E F7E1                    	mul	cx
  2655 00000C90 93                       	xchg	ax, bx
  2656 00000C91 52                      	push	dx
  2657 00000C92 F7E1                    	mul	cx 
  2658 00000C94 59                      	pop	cx 
  2659 00000C95 01C8                    	add	ax, cx 
  2660 00000C97 83D200                  	adc	dx, 0
  2661 00000C9A 93                      	xchg	bx, ax
  2662 00000C9B 87D3                    	xchg	dx, bx
  2663 00000C9D 59                      	pop	cx
  2664 00000C9E C3                      	retn
  2665                                  
  2666                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2667                                  ; creeate new partition input menu
  2668                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2669                                  
  2670                                  B_01:
  2671                                  	; 06/03/2019
  2672 00000C9F C606[826D]4D            	mov	byte [pSize_unit], 'M' ; default (for 'whole' disk/space)
  2673                                  	; 15/02/2019
  2674 00000CA4 E80BFB                  	call	create_partition_input
  2675                                  B_02:		
  2676 00000CA7 21C0                    	and	ax, ax
  2677                                  	;jz	_crlf_exit ; 0 = none or not a valid input
  2678 00000CA9 0F845AF7                	jz	A_42 ; 25/02/2019
  2679                                  
  2680                                  	;or	ah, ah
  2681                                  	;jz	short B_03
  2682                                  
  2683                                  	; 23/02/2019
  2684 00000CAD 80FC04                  	cmp	ah, 4  ; user's partition type input ?
  2685 00000CB0 7505                    	jne	short B_03 ; no
  2686                                  
  2687                                  	; 29/10/2020
  2688                                  	; (ah = 0)
  2689                                  	;or	al, al
  2690                                  	;jz	A_42  ; invalid partition type input
  2691                                  	;	      ; or ESC key has been pressed
  2692                                  
  2693                                  	; user type input
  2694 00000CB2 A2[766D]                	mov	[pp_type_user], al
  2695 00000CB5 88E0                    	mov	al, ah ; mov al, 4
  2696                                  B_03:
  2697 00000CB7 A2[756D]                	mov	[pp_type], al
  2698                                  
  2699                                  	; clear screen
  2700 00000CBA B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
  2701 00000CBD CD10                    	int	10h
  2702                                  
  2703 00000CBF A0[756D]                	mov	al, [pp_type]
  2704 00000CC2 3C01                    	cmp	al, 1
  2705 00000CC4 7705                    	ja	short B_04
  2706                                  
  2707 00000CC6 BE[0448]                	mov	si,  msg_create_dos_partition_h ; header
  2708 00000CC9 EB70                    	jmp	short B_09
  2709                                  B_04:
  2710 00000CCB 3C05                    	cmp	al, 5
  2711 00000CCD 7269                    	jb	short B_08
  2712                                  	;ja	short B_07
  2713 00000CCF 7741                    	ja	short B_58 ; 26/10/2020
  2714                                  
  2715                                  	; 23/02/2019
  2716 00000CD1 BE[F948]                	mov	si, msg_create_ext_partition_h
  2717 00000CD4 E8AB0E                  	call	print_msg
  2718                                  
  2719                                  	; 24/02/2019
  2720 00000CD7 803E[6370]00            	cmp	byte [epnumber], 0
  2721 00000CDC 7613                    	jna	short B_05	
  2722                                  
  2723 00000CDE BE[715F]                	mov	si, msg_ext_partition_exists
  2724 00000CE1 E89E0E                  	call 	print_msg
  2725                                  
  2726 00000CE4 BE[BB55]                	mov	si, msg_press_any_key
  2727 00000CE7 E8980E                  	call	print_msg
  2728                                  
  2729 00000CEA 30E4                    	xor	ah, ah
  2730 00000CEC CD16                    	int	16h
  2731                                  
  2732 00000CEE E916F7                  	jmp	A_42
  2733                                  B_05:
  2734 00000CF1 803E[6170]00            	cmp	byte [ppcount], 0  ; primary partition count
  2735 00000CF6 7746                    	ja	short B_10
  2736                                  
  2737                                  	; 09/02/2019
  2738 00000CF8 BE[804F]                	mov	si, msg_ext_partition_error
  2739 00000CFB E8840E                  	call	print_msg
  2740                                  B_06:	
  2741 00000CFE BE[BB55]                	mov	si, msg_press_any_key
  2742 00000D01 E87E0E                  	call	print_msg
  2743                                  
  2744 00000D04 30E4                    	xor	ah, ah
  2745 00000D06 CD16                    	int	16h
  2746                                  
  2747 00000D08 C606[756D]01            	mov	byte [pp_type], 1
  2748                                  
  2749 00000D0D E8CDFA                  	call	cpi_2 ; 15/02/2019
  2750 00000D10 EB95                    	jmp	short B_02
  2751                                  
  2752                                  B_58:
  2753                                  	; 26/10/2020
  2754 00000D12 803E[D668]80            	cmp	byte [DrvNum], 80h ; hd0 ?
  2755 00000D17 7707                    	ja	short B_59 ; Do not check primary dos partition count	
  2756                                  	; The second hard disk may contain extended partition without
  2757                                  	; a primary dos partition
  2758 00000D19 803E[6170]00            	cmp	byte [ppcount], 0  ; primary dos partition count
  2759 00000D1E 760A                    	jna	short B_07
  2760                                  B_59:
  2761 00000D20 803E[6370]00            	cmp	byte [epnumber], 0  
  2762                                  			; is there an extended partition ? 	
  2763 00000D25 7603                    	jna	short B_07 ; no
  2764 00000D27 E9ACF7                  	jmp	create_logical_drives
  2765                                  B_07:
  2766 00000D2A BE[EE49]                	mov	si, msg_create_logical_drive_h
  2767 00000D2D E8520E                  	call	print_msg
  2768                                  
  2769 00000D30 BE[BF4F]                	mov	si, msg_logical_drive_error
  2770 00000D33 E84C0E                  	call	print_msg
  2771 00000D36 EBC6                    	jmp	short B_06
  2772                                  
  2773                                  ;	mov	si, msg_use_entire_ep_space
  2774                                  ;	jmp	short B_12
  2775                                  	
  2776                                  B_08:
  2777 00000D38 BE[E34A]                	mov	si, msg_create_nondos_partition_h
  2778                                  B_09:
  2779 00000D3B E8440E                  	call	print_msg
  2780                                  B_10:
  2781                                  	; 15/02/2019
  2782                                  	;cmp	byte [newdisk], 0
  2783                                  	;ja	short B_11
  2784                                  
  2785 00000D3E 803E[6070]00            	cmp	byte [pcount], 0 ; (valid) partition count
  2786 00000D43 7605                    	jna	short B_11
  2787                                  
  2788 00000D45 BE[184E]                	mov	si, msg_use_all_space
  2789 00000D48 EB03                    	jmp	short B_12
  2790                                  B_11:
  2791 00000D4A BE[F14D]                	mov	si, msg_use_whole_disk ; partition size: whole disk
  2792                                  B_12:
  2793 00000D4D E8320E                  	call	print_msg
  2794                                  B_13:
  2795 00000D50 30E4                    	xor	ah, ah
  2796 00000D52 CD16                    	int	16h
  2797                                  
  2798 00000D54 3C1B                    	cmp	al, 27 ; ESCAPE key
  2799                                  	;;je	_crlf_exit
  2800 00000D56 0F84ADF6                	je	A_42 ; 25/02/2019
  2801 00000D5A 24DF                    	and	al, 0DFh
  2802 00000D5C 3C4E                    	cmp	al, 'N'
  2803 00000D5E 740D                    	je	short B_14  ;02/03/2019
  2804 00000D60 3C59                    	cmp	al, 'Y'
  2805 00000D62 75EC                    	jne	short B_13
  2806                                  	
  2807 00000D64 FE06[746D]              	inc	byte [wholedisk]
  2808                                  	
  2809                                  	; 02/03/2019
  2810 00000D68 BE[985C]                	mov	si, _msg_YES
  2811                                  	;call	print_msg
  2812 00000D6B EB03                    	jmp	short B_15	
  2813                                  B_14:
  2814 00000D6D BE[9E5C]                	mov	si, _msg_NO
  2815                                  B_15:	; 06/03/2019
  2816 00000D70 E80F0E                  	call	print_msg
  2817                                  
  2818                                  	; 15/02/2019
  2819 00000D73 29DB                    	sub	bx, bx
  2820                                  	;cmp	byte [newdisk], bl ; 0
  2821                                  	;ja	short B_16 ; 23/02/2019
  2822                                  	; 19/10/2020
  2823                                  	;cmp	byte [pcount], 0
  2824                                  	; 03/11/2020
  2825 00000D75 381E[6070]              	cmp	byte [pcount], bl ; 0
  2826 00000D79 7608                    	jna	short B_16 ; [pcount] = 0 (newdisk, empty pt) 
  2827 00000D7B 381E[746D]              	cmp	byte [wholedisk], bl ; 0
  2828 00000D7F 0F871C01                	ja	B_27 ; 23/02/2019
  2829                                  B_16:
  2830                                  	; 08/02/2019
  2831                                  	;sub	bx, bx
  2832 00000D83 A1[DA68]                	mov	ax, [total_sectors]
  2833 00000D86 8B16[DC68]              	mov	dx, [total_sectors+2]
  2834 00000D8A 2B06[6E3F]              	sub	ax, [sectors]
  2835 00000D8E 19DA                    	sbb	dx, bx ; sbb dx, 0
  2836                                  
  2837 00000D90 A3[706D]                	mov	[pp_Sectors], ax   ; = [total_sectors] - [sectors]
  2838 00000D93 8916[726D]              	mov	[pp_Sectors+2], dx ; = [total_sectors+2] - carry bit
  2839                                  B_17:
  2840 00000D97 381E[746D]              	cmp	byte [wholedisk], bl ; 0
  2841 00000D9B 0F870701                	ja	B_28 ; 09/02/2019
  2842                                  B_18:
  2843                                  	; clear screen
  2844 00000D9F B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
  2845 00000DA2 CD10                    	int	10h
  2846                                  
  2847                                  	; 04/11/2020
  2848 00000DA4 803E[756D]01            	cmp	byte [pp_type], 1 ; primary dos partition ?
  2849 00000DA9 7405                    	je	short B_61
  2850                                  	; "Create Partition"
  2851 00000DAB BE[5945]                	mov	si, msg_create_partition_h
  2852 00000DAE EB03                    	jmp	short B_62
  2853                                  B_61:
  2854                                  	; "Create DOS partition"
  2855 00000DB0 BE[0448]                	mov	si, msg_create_dos_partition_h ; header
  2856                                  B_62:
  2857 00000DB3 E8CC0D                  	call	print_msg
  2858 00000DB6 BE[954C]                	mov	si, msg_create_trdos_partition_s ; size options
  2859 00000DB9 E8C60D                  	call	print_msg	
  2860                                  B_19:	
  2861 00000DBC 30E4                    	xor	ah, ah
  2862 00000DBE CD16                    	int	16h
  2863                                  
  2864                                  	; 24/02/2019
  2865 00000DC0 3C1B                    	cmp	al, 27	; ESCAPE key 
  2866 00000DC2 0F8441F6                	je	A_42	; Cancel
  2867                                  
  2868 00000DC6 3C20                    	cmp	al, 32	; SPACE key
  2869 00000DC8 7521                    	jne	short B_21
  2870                                  
  2871                                  		; Entire space
  2872 00000DCA A1[706D]                	mov	ax, [pp_Sectors]
  2873 00000DCD 8B16[726D]              	mov	dx, [pp_Sectors+2]
  2874                                  
  2875 00000DD1 C606[746D]01            	mov 	byte [wholedisk], 1 ; 09/02/2019
  2876 00000DD6 EB5A                    	jmp	short B_23
  2877                                  
  2878                                  B_60:	; 31/10/2020
  2879 00000DD8 75C5                    	jnz	short B_18  ; ESCape (return to options menu)
  2880                                  	; partition size input is ZERO !
  2881                                  B_20:
  2882                                  	; ZERO partition size message
  2883 00000DDA BE[AB5A]                	mov	si, msg_zero_partition_size
  2884 00000DDD E8A20D                  	call	print_msg
  2885                                  	
  2886 00000DE0 30E4                    	xor	ah, ah
  2887 00000DE2 CD16                    	int	16h
  2888 00000DE4 3C1B                    	cmp	al, 27 ; ESCAPE key
  2889 00000DE6 75B7                    	jne	short B_18 ; Retry
  2890                                  
  2891                                  	; 19/10/2020
  2892 00000DE8 E9BCF9                  	jmp	_crlf_exit ; exit
  2893                                  
  2894                                  B_21:
  2895 00000DEB C606[826D]25            	mov	byte [pSize_unit], '%'
  2896 00000DF0 3C25                    	cmp	al, '%'
  2897 00000DF2 7422                    	je	short B_22
  2898 00000DF4 C606[826D]53            	mov	byte [pSize_unit], 'S'
  2899 00000DF9 3C0D                    	cmp	al, 13 ; 0Dh, Carriage Return key
  2900 00000DFB 7419                    	je	short B_22
  2901 00000DFD 24DF                    	and	al, 0DFh
  2902 00000DFF 3C53                    	cmp	al, 'S'
  2903 00000E01 7413                    	je	short B_22
  2904 00000E03 A2[826D]                	mov	[pSize_unit], al
  2905 00000E06 3C4B                    	cmp	al, 'K'
  2906 00000E08 740C                    	je	short B_22
  2907 00000E0A 3C4D                    	cmp	al, 'M'
  2908 00000E0C 7408                    	je	short B_22
  2909 00000E0E 3C47                    	cmp	al, 'G'
  2910 00000E10 7404                    	je	short B_22
  2911 00000E12 3C43                    	cmp	al, 'C'
  2912 00000E14 75A6                    	jne	short B_19
  2913                                  B_22:
  2914 00000E16 C606[B764]73            	mov	byte [msg_sectors_crlf_s], 's' ; " sectors"
  2915                                  
  2916 00000E1B E8D40F                  	call	partition_size_input
  2917                                  	;jc	_crlf_exit ; exit if partition size input is 0
  2918                                  	;jc	short B_20
  2919                                  	; 29/10/2020
  2920                                  	;jnc	short B_60
  2921                                  	;jz	short B_20 ; partition size input is ZERO !
  2922                                  	;jmp	short B_18 ; ESCape (return to options menu)	
  2923                                  	; 31/10/2020
  2924 00000E1E 72B8                    	jc	short B_60 ; ESC or zero partition size
  2925                                  ;B_60:
  2926 00000E20 21DB                    	and	bx, bx ; bx_dx_ax = partition size
  2927                                  	;jnz	short B_29
  2928                                  	; 23/02/2019 
  2929 00000E22 7540                    	jnz	short B_24 ; invalid! (use maximum available sectors)
  2930                                  
  2931                                  	; 08/02/2019
  2932 00000E24 09D2                    	or	dx, dx
  2933 00000E26 750A                    	jnz	short B_23 ; proper size (for now)
  2934                                  
  2935 00000E28 8B1E[986D]              	mov	bx, [min_sectors] ; minimum sectors
  2936 00000E2C 39C3                    	cmp	bx, ax
  2937 00000E2E 7602                    	jna	short B_23 ; proper size (for now)	 
  2938                                  
  2939                                  	; invalid! (use minimum sectors or sectors per cylinder)
  2940 00000E30 89D8                    	mov	ax, bx
  2941                                  B_23:
  2942                                  	; 09/02/2019
  2943                                  	; save dx,ax
  2944 00000E32 8916[A06D]              	mov	[ppn_Sectors+2], dx 
  2945 00000E36 A3[9E6D]                	mov	[ppn_Sectors], ax
  2946                                  
  2947                                  	; write partition size
  2948                                  	;push	dx
  2949                                  	;push	ax
  2950                                  	;mov	si, msg_partition_sectors + 7 ; max. 8 digits
  2951                                  	; 06/11/2020
  2952 00000E39 BE[8F6D]                	mov	si, msg_partition_sectors + 10 ; max. 11 digits
  2953 00000E3C E8020E                  	call	bin_to_decimal
  2954                                  	; ds:si = beginning of decimal number text
  2955 00000E3F E8400D                  	call	print_msg
  2956 00000E42 BE[B064]                	mov	si, msg_sectors_crlf
  2957 00000E45 E83A0D                  	call	print_msg
  2958                                  	;pop	ax
  2959                                  	;pop	dx
  2960                                  
  2961 00000E48 803E[746D]00            	cmp	byte [wholedisk], 0
  2962 00000E4D 775E                    	ja	short B_29 ; 09/02/2019
  2963                                  
  2964                                  	; restore ax,dx
  2965 00000E4F A1[9E6D]                	mov	ax, [ppn_Sectors]
  2966 00000E52 8B16[A06D]              	mov	dx, [ppn_Sectors+2]
  2967                                  
  2968                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2969                                  ; select whole disk
  2970                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2971                                  
  2972                                  	; select whole disk 
  2973                                  	;   if partition size > disk size
  2974 00000E56 3B16[726D]              	cmp	dx, [pp_Sectors+2]
  2975 00000E5A 7708                    	ja	short B_24
  2976 00000E5C 724F                    	jb	short B_29
  2977 00000E5E 3B06[706D]              	cmp	ax, [pp_Sectors]
  2978 00000E62 7649                    	jna	short B_29
  2979                                  B_24:
  2980                                  	;cmp	byte [newdisk], 0
  2981                                  	;jna	short B_30
  2982                                  	; 19/10/2020
  2983 00000E64 803E[6070]00            	cmp	byte [pcount], 0
  2984 00000E69 7767                    	ja	short B_30
  2985                                  
  2986                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2987                                  ; "use whole disk or go to back" question
  2988                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2989                                  
  2990 00000E6B BE[164F]                	mov	si, msg_partition_size_overs
  2991                                  B_25:
  2992 00000E6E E8110D                  	call	print_msg
  2993                                  B_26:
  2994 00000E71 30E4                    	xor	ah, ah
  2995 00000E73 CD16                    	int	16h
  2996                                  	
  2997 00000E75 3C1B                    	cmp	al, 27 ; ESCAPE key
  2998                                  	;je	B_01
  2999 00000E77 0F8424FF                	je	B_18 ; 09/02/2019
  3000 00000E7B 3C0D                    	cmp	al, 13 ; ENTER (Carriage Return) key
  3001 00000E7D 75F2                    	jne	short B_26
  3002                                  
  3003 00000E7F FE06[746D]              	inc	byte [wholedisk]
  3004                                  
  3005                                  	; 24/02/2019
  3006                                  	;cmp	byte [newdisk], 0
  3007                                  	;ja	short B_27
  3008 00000E83 803E[6070]00            	cmp	byte [pcount], 0  ; (valid) partition count
  3009 00000E88 7615                    	jna	short B_27 ; no
  3010                                  
  3011 00000E8A 8B1E[FE70]              	mov	bx, [c_fspc_offset]
  3012 00000E8E 8B87[B470]              	mov	ax, [free_space.sectors_unused+bx]
  3013 00000E92 8B97[B670]              	mov	dx, [free_space.sectors_unused+bx+2]
  3014 00000E96 A3[706D]                	mov	[pp_Sectors], ax
  3015 00000E99 8916[726D]              	mov	[pp_Sectors+2], dx
  3016 00000E9D EB07                    	jmp	short B_28 
  3017                                  B_27:
  3018                                  	; 09/02/2019
  3019 00000E9F 8B16[726D]              	mov	dx, [pp_Sectors+2]
  3020 00000EA3 A1[706D]                	mov	ax, [pp_Sectors]
  3021                                  B_28:
  3022 00000EA6 8916[A06D]              	mov	[ppn_Sectors+2], dx
  3023 00000EAA A3[9E6D]                	mov	[ppn_Sectors], ax
  3024                                  B_29:
  3025 00000EAD 803E[756D]05            	cmp	byte [pp_type], 5
  3026 00000EB2 0F853601                	jne	B_51
  3027                                  
  3028 00000EB6 803E[6170]00            	cmp	byte [ppcount], 0  ; primary partition count
  3029 00000EBB 0F87C500                	ja	B_45
  3030                                  
  3031 00000EBF BE[804F]                	mov	si, msg_ext_partition_error
  3032 00000EC2 E8BD0C                  	call	print_msg
  3033 00000EC5 BE[F94E]                	mov	si, msg_any_key_to_retry
  3034 00000EC8 E8B70C                  	call	print_msg
  3035                                  
  3036                                  	; 09/02/2019
  3037 00000ECB 30E4                    	xor	ah, ah
  3038 00000ECD CD16                    	int	16h
  3039                                  
  3040                                  	;jmp	B_01
  3041 00000ECF E90BF9                  	jmp	cpi_2 
  3042                                  
  3043                                  B_30:
  3044                                  	; clear screen
  3045 00000ED2 B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
  3046 00000ED5 CD10                    	int	10h
  3047                                  
  3048 00000ED7 BE[0448]                	mov	si, msg_create_dos_partition_h ; header
  3049 00000EDA E8A50C                  	call	print_msg
  3050                                  
  3051 00000EDD BE[5D5E]                	mov	si, msg_partition_size_limit
  3052 00000EE0 E89F0C                  	call	print_msg
  3053                                  
  3054 00000EE3 8B1E[FE70]              	mov	bx, [c_fspc_offset]
  3055                                  
  3056 00000EE7 803E[826D]53            	cmp	byte [pSize_unit], 'S'
  3057 00000EEC 7415                    	je	short B_31
  3058 00000EEE 803E[826D]4B            	cmp	byte [pSize_unit], 'K'
  3059 00000EF3 740E                    	je	short B_31
  3060                                  
  3061 00000EF5 803E[826D]25            	cmp	byte [pSize_unit], '%'
  3062 00000EFA 7469                    	je	short B_41
  3063                                  
  3064 00000EFC 803E[826D]43            	cmp	byte [pSize_unit], 'C'
  3065 00000F01 7479                    	je	B_44
  3066                                  B_31:
  3067                                  	; 'S', 'K'
  3068 00000F03 81C3[B470]              	add	bx, free_space.sectors_unused	
  3069 00000F07 8B07                    	mov	ax, [bx]
  3070 00000F09 8B5702                  	mov	dx, [bx+2]
  3071                                  		
  3072 00000F0C B90A00                  	mov	cx, 10
  3073 00000F0F 89E5                    	mov	bp, sp
  3074                                  B_32:
  3075 00000F11 E869FD                  	call	div32
  3076 00000F14 53                      	push	bx
  3077 00000F15 09D2                    	or	dx, dx
  3078 00000F17 75F8                    	jnz	short B_32
  3079 00000F19 83F809                  	cmp	ax, 9
  3080 00000F1C 77F3                    	ja	short B_32
  3081                                  B_33:
  3082 00000F1E BB0700                  	mov	bx, 07h
  3083 00000F21 09C0                    	or	ax, ax
  3084 00000F23 7501                    	jnz	short B_35
  3085                                  B_34:
  3086 00000F25 58                      	pop	ax
  3087                                  B_35:
  3088 00000F26 0430                    	add	al, '0'
  3089                                  B_36:
  3090 00000F28 B40E                    	mov	ah, 0Eh
  3091                                  	;mov	bx, 07h
  3092 00000F2A CD10                    	int	10h	; write character (as tty)
  3093                                  
  3094 00000F2C 39EC                    	cmp	sp, bp			
  3095 00000F2E 72F5                    	jb	short B_34
  3096                                  
  3097 00000F30 803E[826D]53            	cmp	byte [pSize_unit], 'S'
  3098 00000F35 7422                    	je	short B_38
  3099 00000F37 803E[826D]4B            	cmp	byte [pSize_unit], 'K'
  3100 00000F3C 741B                    	je	short B_38
  3101                                  
  3102 00000F3E 803E[826D]25            	cmp	byte [pSize_unit], '%'
  3103 00000F43 7508                    	jne	short B_37
  3104                                  
  3105                                  	; 24/02/2019
  3106 00000F45 3C25                    	cmp	al, '%'
  3107 00000F47 7416                    	je	short B_40
  3108 00000F49 B025                    	mov	al, '%'
  3109 00000F4B EBDB                    	jmp	short B_36 
  3110                                  B_37:
  3111 00000F4D 803E[826D]43            	cmp	byte [pSize_unit], 'C'
  3112 00000F52 7505                    	jne	short B_38
  3113                                  
  3114 00000F54 BE[F95E]                	mov	si, msg_cylinders
  3115 00000F57 EB03                    	jmp	short B_39
  3116                                  B_38:
  3117 00000F59 BE[045F]                	mov	si, msg_sectors
  3118                                  B_39:
  3119 00000F5C E8230C                  	call	print_msg
  3120                                  B_40:
  3121 00000F5F BE[AA5E]                	mov	si, msg_partition_size_limit_r
  3122                                  	;call	print_msg
  3123                                  
  3124 00000F62 E909FF                  	jmp	B_25
  3125                                  
  3126                                  B_41:
  3127                                  	; '%'
  3128 00000F65 81C3[B270]              	add	bx, free_space.percent_unused
  3129 00000F69 8B07                    	mov	ax, [bx]
  3130                                  B_42:	
  3131 00000F6B 89E5                    	mov	bp, sp
  3132 00000F6D B90A00                  	mov	cx, 10
  3133                                  B_43:	
  3134 00000F70 31D2                    	xor	dx, dx
  3135                                  	;mov	cx, 10
  3136 00000F72 F7F1                    	div	cx
  3137 00000F74 52                      	push	dx
  3138 00000F75 83F809                  	cmp	ax, 9
  3139 00000F78 77F6                    	ja	short B_43	
  3140 00000F7A EBA2                    	jmp	short B_33
  3141                                  B_44:
  3142                                  	; 'C'
  3143 00000F7C 81C3[AC70]              	add	bx, free_space.space
  3144 00000F80 8B07                    	mov	ax, [bx]
  3145 00000F82 EBE7                    	jmp	short B_42
  3146                                  
  3147                                  B_45:
  3148                                  	; 23/02/2019
  3149 00000F84 8B1E[FE70]              	mov	bx, [c_fspc_offset]
  3150 00000F88 8B87[AE70]              	mov	ax, [bx+free_space.start]
  3151                                  
  3152                                  	; set free space start cylinder to 1 if it is 0
  3153 00000F8C 09C0                    	or	ax, ax
  3154 00000F8E 750F                    	jnz	short B_46
  3155                                  
  3156 00000F90 B005                    	mov	al, 5	; Get free space for extended partition
  3157 00000F92 E89515                  	call	find_part_free_space
  3158                                  
  3159 00000F95 891E[FE70]              	mov	[c_fspc_offset], bx
  3160                                  
  3161                                  	; 19/10/2020
  3162 00000F99 21C9                    	and	cx, cx
  3163 00000F9B 0F8428F5                	jz	cp_3	; there is not free space on disk
  3164                                  B_46:
  3165                                  	; 24/02/2019
  3166 00000F9F E81100                  	call	partition_size_fixup_x
  3167 00000FA2 0F822CFF                	jc	B_30
  3168                                  
  3169                                  	; 16/02/2019
  3170 00000FA6 E83EFB                  	call	create_extended_partition 
  3171                                  			; must be called after 'find_part_free_space'.
  3172                                  	; 24/02/2019
  3173 00000FA9 E86411                  	call	show_selected_partition
  3174 00000FAC E9BE00                  	jmp	C_02
  3175                                  
  3176                                  partition_size_fixup:
  3177                                  	; 24/02/2019
  3178 00000FAF 8B1E[FE70]              	mov	bx, [c_fspc_offset]
  3179                                  partition_size_fixup_x:
  3180                                  	; 19/10/2020
  3181                                  
  3182                                  	;cmp	byte [newdisk], 0
  3183                                  	;ja	short B_50
  3184                                  
  3185 00000FB3 803E[6070]00            	cmp	byte [pcount], 0 ; (valid) partition count
  3186 00000FB8 7631                    	jna	short B_50
  3187                                  
  3188 00000FBA 81C3[B470]              	add	bx, free_space.sectors_unused	
  3189 00000FBE 8B07                    	mov	ax, [bx]
  3190 00000FC0 8B5702                  	mov	dx, [bx+2]
  3191                                  
  3192 00000FC3 3B16[A06D]              	cmp	dx, [ppn_Sectors+2]
  3193 00000FC7 7222                    	jb	short B_50 ; 24/02/2019
  3194 00000FC9 7708                    	ja	short B_47
  3195 00000FCB 3B06[9E6D]              	cmp	ax, [ppn_Sectors]
  3196 00000FCF 721A                    	jb	short B_50 ; 24/02/2019
  3197 00000FD1 7411                    	je	short B_49
  3198                                  
  3199                                  B_47:
  3200                                  	; 19/02/2019
  3201 00000FD3 A1[9E6D]                	mov	ax, [ppn_Sectors]
  3202                                  B_48:
  3203 00000FD6 8B16[A06D]              	mov	dx, [ppn_Sectors+2]
  3204                                  
  3205                                  	; 18/02/2019
  3206                                  
  3207                                  	; check for best fit
  3208                                  	; (leave max. available space to next time if 
  3209                                  	;  another space/gap fits to partition size request.)
  3210                                  
  3211 00000FDA E86517                  	call	find_enough_free_sectors
  3212                                  		; CX = Free space index (0 to 4)
  3213                                  		; DX:AX = First available space which fits to request
  3214                                  	;mov	bx, cx
  3215                                  	;shl	bl, 4 ; * 16  ; * Free space structure size
  3216                                  	;mov	[c_fspc_offset], bx
  3217                                  	
  3218                                  	; 22/02/2019
  3219 00000FDD C0E104                  	shl	cl, 4
  3220 00000FE0 890E[FE70]              	mov	[c_fspc_offset], cx 
  3221                                  
  3222                                  	;add	bx, free_space.sectors_unused	
  3223                                  	;mov	ax, [bx]
  3224                                  	;mov	dx, [bx+2]
  3225                                  B_49:		
  3226                                  	; Save max. available space
  3227 00000FE4 A3[706D]                	mov	[pp_Sectors], ax
  3228 00000FE7 8916[726D]              	mov	[pp_Sectors+2], dx
  3229                                  B_50:
  3230 00000FEB C3                      	retn
  3231                                  
  3232                                  B_51:
  3233                                  	; 24/02/2019
  3234 00000FEC E8C0FF                  	call	partition_size_fixup
  3235 00000FEF 0F82DFFE                	jc	B_30
  3236                                  
  3237                                  	; 16/02/2019
  3238                                  	; Force cylinder boundary alignment except
  3239                                  	;   sectors ('S') and kilobytes ('K') as sizing unit.
  3240                                  
  3241 00000FF3 C606[0071]59            	mov	byte [cylinder_boundary], 'Y' ; Default
  3242                                  				; sizing unit is one of
  3243                                  				; 'cylinders','megabytes','gigabytes'
  3244                                  				; and boundary alignment is yes for them.
  3245 00000FF8 A0[826D]                	mov	al, [pSize_unit]
  3246                                  
  3247                                  	;cmp	byte [pSize_unit], 'S' ; Sectors
  3248 00000FFB 3C53                    	cmp	al, 'S'
  3249 00000FFD 7404                    	je	short B_52
  3250                                  
  3251                                  	;cmp	byte [pSize_unit], 'K' ; Kilobytes
  3252 00000FFF 3C4B                    	cmp	al, 'K'
  3253 00001001 752F                    	jne	short B_56
  3254                                  B_52:
  3255                                  	; Sizing unit is one of 'sectors' and/or 'kilobytes'
  3256                                  	; and bound aligment will be applied if the answer will be yes. 
  3257                                  
  3258 00001003 BE[0850]                	mov	si, msg_cylinder_boundary_set
  3259 00001006 E8790B                  	call	print_msg
  3260                                  B_53:
  3261 00001009 30E4                    	xor	ah, ah
  3262 0000100B CD16                    	int	16h
  3263                                  	; Cylinder boundary adjusting
  3264 0000100D 3C0D                    	cmp	al, 13 ; ENTER key
  3265 0000100F 74F2                    	je	short B_52
  3266 00001011 3C1B                    	cmp	al, 27 ; ESCAPE key
  3267 00001013 741A                    	je	short B_55	; Align end of the partition only
  3268                                  				; if start of the partition is aligned
  3269                                  				; or it starts at cyl 0, head 1, sect 17 or 63.
  3270                                  				; (End of the partition will be extended to
  3271                                  				; end sector of it's last cylinder if the size
  3272                                  				; will not over [pp_Sectors] value.)  	 
  3273 00001015 24DF                    	and	al, 0DFh
  3274                                  
  3275                                  	; 22/02/2019
  3276 00001017 3C59                    	cmp	al, 'Y'
  3277 00001019 7508                    	jne	short B_54
  3278                                  
  3279 0000101B BE[985C]                	mov	si, _msg_YES
  3280 0000101E E8610B                  	call	print_msg
  3281                                  
  3282                                  	;mov	al, 'Y'
  3283                                  	;jmp	short B_55
  3284 00001021 EB0F                    	jmp	short B_56
  3285                                  B_54:
  3286 00001023 3C4E                    	cmp	al, 'N'
  3287 00001025 75E2                    	jne	short B_53
  3288                                  
  3289 00001027 BE[9E5C]                	mov	si, _msg_NO
  3290 0000102A E8550B                  	call	print_msg
  3291                                  
  3292 0000102D B04E                    	mov	al, 'N'
  3293                                  		; do not align partition to cylinder boundary 
  3294                                  B_55:
  3295 0000102F A2[0071]                	mov	[cylinder_boundary], al
  3296                                  B_56:
  3297 00001032 E8FCF7                  	call	create_primary_partition
  3298                                  	
  3299                                  	; 18/02/2019
  3300                                  	;cmp	byte [newdisk], 0
  3301                                  	;jna	short B_57
  3302                                  
  3303                                  	; 19/10/2020
  3304 00001035 803E[6070]00            	cmp	byte [pcount], 0
  3305 0000103A 770E                    	ja	short B_57
  3306                                  
  3307 0000103C 31C0                    	xor	ax, ax ; 0
  3308 0000103E 31D2                    	xor	dx, dx ; 0
  3309                                  	; DX_AX = Masterboot Sector = 0
  3310 00001040 BB[DA55]                	mov	bx, MasterBootBuff
  3311                                  	; ES:BX = Sector Buffer
  3312 00001043 E8A10B                  	call	write_hd_sector
  3313 00001046 0F8247F7                	jc	print_error_code ; 18/10/2020
  3314                                  B_57:
  3315                                  	; DS:SI = Partition Table Entry address
  3316                                  	; 25/02/2019
  3317 0000104A 8936[2671]              	mov	[pte_address], si  ; save PTE address
  3318 0000104E E8BF10                  	call	show_selected_partition
  3319                                  
  3320                                  	;jmp	C_01
  3321                                  
  3322                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3323                                  ; format question
  3324                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3325                                  
  3326                                  C_01:
  3327                                  	;mov	si, CRLF
  3328                                  	;call	print_msg
  3329                                  
  3330 00001051 C606[916D]01            	mov	byte [format_q], 1
  3331                                  
  3332 00001056 A0[756D]                	mov	al, [pp_type]
  3333 00001059 3C01                    	cmp	al, 1		; FAT12 (CHS)
  3334 0000105B 741D                    	je	short C_03
  3335 0000105D 3C04                    	cmp	al, 4		; FAT16 CHS
  3336 0000105F 7419                    	je	short C_03
  3337 00001061 3C06                    	cmp	al, 6		; FAT16 BIG CHS
  3338 00001063 7415                    	je	short C_03
  3339 00001065 3C0B                    	cmp	al, 0Bh		; FAT32 CHS
  3340 00001067 7411                    	je	short C_03
  3341 00001069 3CA1                    	cmp	al, 0A1h	; SINGLIX FS1
  3342 0000106B 740D                    	je	short C_03
  3343                                  
  3344                                  	;cmp	al, 71h
  3345                                  	;je	short C_03	; RETRO UNIX 386
  3346                                  
  3347                                  	;dec	byte [format_q] ; 0		
  3348                                  C_02:
  3349 0000106D C606[916D]00            	mov	byte [format_q], 0 ; 24/02/2019
  3350                                  
  3351                                  	; NON-DOS partition!
  3352                                  	; Ask for editing PT or exit (continue without formatting)
  3353 00001072 BE[8E53]                	mov	si, msg_edit_or_exit
  3354 00001075 E80A0B                  	call	print_msg
  3355 00001078 EB06                    	jmp	short C_04
  3356                                  C_03:
  3357                                  	; Ask for formatting, editing PT or exit
  3358 0000107A BE[1F53]                	mov	si, msg_format_stage
  3359 0000107D E8020B                  	call	print_msg
  3360                                  C_04:
  3361 00001080 BE[5F53]                	mov	si, msg_partition_edit
  3362 00001083 E8FC0A                  	call	print_msg
  3363                                  C_05:
  3364 00001086 28E4                    	sub	ah, ah
  3365 00001088 CD16                    	int	16h
  3366                                  
  3367 0000108A 3C0D                    	cmp	al, 13
  3368 0000108C 7435                    	je	short C_08
  3369                                  
  3370                                  	;; 07/03/2019
  3371 0000108E 3C20                    	cmp	al, 20h ; SPACE
  3372                                  	;je	A_21 ; edit partition table option is selected
  3373 00001090 7503                    	jne	short C_06
  3374                                  	; 19/10/2020	
  3375 00001092 E955F1                  	jmp	A_21
  3376                                  C_06:
  3377 00001095 3C1B                    	cmp	al, 27 ; ESCAPE
  3378 00001097 75ED                    	jne	short C_05
  3379                                  	
  3380                                  	; 19/010/2020
  3381 00001099 E911F7                  	jmp	_exit
  3382                                  
  3383                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3384                                  ; save MBR then exit
  3385                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3386                                  
  3387                                  save_mbr_exit:
  3388                                  	; 24/02/2019
  3389 0000109C E85612                  	call	init_partition_table
  3390                                  
  3391 0000109F E83917                  	call	display_partition_table
  3392                                  
  3393 000010A2 BE[5F55]                	mov	si, CRLF
  3394 000010A5 E8DA0A                  	call	print_msg
  3395                                  
  3396 000010A8 BE[1354]                	mov	si, msg_writing_mbr
  3397 000010AB E8D40A                  	call	print_msg
  3398                                  
  3399 000010AE 31C0                    	xor	ax, ax ; 0
  3400 000010B0 31D2                    	xor	dx, dx ; 0
  3401                                  	; DX_AX = Masterboot Sector = 0
  3402 000010B2 BB[DA55]                	mov	bx, MasterBootBuff
  3403                                  	; ES:BX = Sector Buffer
  3404 000010B5 E82F0B                  	call	write_hd_sector
  3405 000010B8 7303                    	jnc	short C_07
  3406 000010BA E9D4F6                  	jmp	print_error_code ; 18/10/2020
  3407                                  
  3408                                  C_07:
  3409 000010BD BE[5B55]                	mov	si, Msg_OK
  3410                                  	;call	print_msg
  3411                                  	; 19/10/2020
  3412                                  	;jmp	_exit
  3413 000010C0 E9E7F6                  	jmp	_p_exit
  3414                                  
  3415                                  C_08:
  3416 000010C3 803E[916D]01            	cmp	byte [format_q], 1
  3417 000010C8 72D2                    	jb	short save_mbr_exit
  3418                                  
  3419                                  	; 25/02/2019
  3420                                  	; Write MBR without writing message
  3421                                  	
  3422                                  	; NOTE: This may be second time of MBR writing...
  3423                                  	;	but, if partition table is modified,
  3424                                  	;	we need to write MBR to disk, here.
  3425                                  	;
  3426                                  	; (Otherwise.. the last created partition would not be recorded.) 	
  3427                                  
  3428 000010CA 31C0                    	xor	ax, ax ; 0
  3429 000010CC 31D2                    	xor	dx, dx ; 0
  3430                                  	; DX_AX = Masterboot Sector = 0
  3431 000010CE BB[DA55]                	mov	bx, MasterBootBuff
  3432                                  	; ES:BX = Sector Buffer
  3433 000010D1 E8130B                  	call	write_hd_sector
  3434 000010D4 0F82B9F6                	jc	print_error_code ; 18/10/2020
  3435                                  
  3436                                  	;; clear screen
  3437                                  	;mov	ax, 3 ; set video mode to 03h (80x25 text)
  3438                                  	;int	10h
  3439                                  
  3440                                  	; 25/02/2019
  3441 000010D8 8B36[2671]              	mov	si, [pte_address]
  3442                                  
  3443                                  	; 18/02/2019
  3444 000010DC E83110                  	call	show_selected_partition	
  3445                                  
  3446 000010DF A0[4653]                	mov	al, [partition_num_chr]
  3447 000010E2 A2[0654]                	mov	[partition_num_txt], al
  3448                                  
  3449 000010E5 BE[E453]                	mov	si, msg_format_question
  3450 000010E8 E8970A                  	call	print_msg
  3451                                  C_09:
  3452 000010EB 30E4                    	xor	ah, ah
  3453 000010ED CD16                    	int	16h
  3454                                  
  3455 000010EF 3C1B                    	cmp	al, 1Bh ; ESCAPE
  3456 000010F1 74A2                    	je	short C_06
  3457                                  
  3458 000010F3 24DF                    	and	al, 0DFh ; capitalization
  3459 000010F5 3C59                    	cmp	al, 'Y'
  3460 000010F7 740C                    	je	short C_10
  3461 000010F9 3C4E                    	cmp	al, 'N'
  3462 000010FB 75EE                    	jne	short C_09
  3463 000010FD BE[9E5C]                	mov	si, _msg_NO 
  3464 00001100 E87F0A                  	call	print_msg
  3465                                  	;jmp	short C_06
  3466                                  	; 24/02/2019
  3467 00001103 EB97                    	jmp	short save_mbr_exit 
  3468                                  C_10:
  3469 00001105 BE[985C]                	mov	si, _msg_YES
  3470 00001108 E8770A                  	call	print_msg
  3471                                  
  3472                                  	; [pp_StartSector] = partition's start sector
  3473                                  	; [pp_Sectors] = partition size including start & end sector	
  3474                                  	; [partition_num_chr] = partition number + '0'
  3475                                  	; [pp_type] = partition type (for TRDOS 386 boot sector) 
  3476                                  
  3477 0000110B 8926[E468]              	mov	[old_sp], sp
  3478                                  	
  3479 0000110F 8A16[756D]              	mov	dl, [pp_type]
  3480                                  	; DL = partition type (file system ID)
  3481                                  	;dec	dl
  3482                                  	;jz	FAT12_hd_format
  3483 00001113 80FA01                  	cmp	dl, 1 ; 14/09/2020 (BugFix)
  3484 00001116 0F86D505                	jna	FAT12_hd_format
  3485                                  	;cmp	dl, 4
  3486                                  	;je	FAT16_hd_format
  3487                                  	;cmp	dl, 6
  3488                                  	;je	FAT16_hd_format
  3489 0000111A 80FA0B                  	cmp	dl, 0Bh 
  3490 0000111D 0F82D203                	jb	FAT16_hd_format
  3491                                  	;je	short FAT32_hd_format	
  3492                                  	;cmp	dl, 0Ch ; 14/09/2020
  3493 00001121 0F876207                	ja	SINGLIX_hd_format
  3494                                  
  3495                                  	;cmp	dl, 0A1h
  3496                                  	;je	SINGLIX_hd_format
  3497                                  	;jb	RUNIX386_hd_format ; dl = 071h
  3498                                  
  3499                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3500                                  ; FAT32 FORMATTING
  3501                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 	
  3502                                  	
  3503                                  	; 08/02/2019 (Modified for -only- FAT32 CHS partitions) 
  3504                                  FAT32_hd_format:
  3505                                  	;mov	ax, 000Ch ; db 0Ch, 00h ; 'or al, 0'
  3506                                  	;cmp	dl, al ; 0Ch
  3507                                  	;je	short FAT32_lbAx_format
  3508                                  	;mov	ax, 0C00Bh ; db 0Bh, 0C0h ; 'or ax, ax'
  3509                                  ;FAT32_lba_format:
  3510                                  	; Put TRDOS 386 FAT32 partition magic word 
  3511                                  	; at offset 5Ah, in TRDOS386 FAT32 boot sector 0.
  3512 00001125 BD[5B33]                	mov	bp, TRDOS_FAT32_hd_bs
  3513 00001128 8D7E03                  	lea	di, [bp+3]
  3514 0000112B BE[BC64]                	mov	si, bs_oem_name
  3515 0000112E B90400                  	mov	cx, 4
  3516 00001131 F3A5                    	rep	movsw 
  3517                                  	;mov	[bp+5Ah], ax	; [loc_5A]
  3518 00001133 C7465A0BC0              	mov	word [bp+5Ah], 0C00Bh ; 08/02/2019
  3519 00001138 A1[6E3F]                	mov	ax, [sectors]
  3520 0000113B 894618                  	mov	[bp+18h], ax	; [BPB_SecPerTrk]
  3521 0000113E A1[703F]                	mov	ax, [heads]
  3522 00001141 89461A                  	mov	[bp+1Ah], ax	; [BPB_NumHeads]
  3523 00001144 A1[6C6D]                	mov	ax, [pp_StartSector]
  3524 00001147 89461C                  	mov	[bp+1Ch], ax	; [BPB_HiddSec]
  3525 0000114A A1[6E6D]                	mov	ax, [pp_StartSector+2]
  3526 0000114D 89461E                  	mov	[bp+1Eh], ax	; [BPB_HiddSec+2]
  3527                                  	;mov	ax, [pp_Sectors]
  3528 00001150 A1[9E6D]                	mov	ax, [ppn_Sectors] ; 16/02/2019
  3529 00001153 894620                  	mov	[bp+20h], ax	; [BPB_TotSec32]
  3530                                  	;mov	dx, [pp_Sectors+2]
  3531 00001156 8B16[A06D]              	mov	dx, [ppn_Sectors+2] ; 16/02/2019
  3532 0000115A 895622                  	mov	[bp+22h], dx	; [BPB_TotSec32+2]
  3533                                  	
  3534                                  	; Sectors per cluster calculation
  3535                                  	; (According to MS FAT32 FS specification.)
  3536 0000115D B108                    	mov	cl, 8  ; 8 sectors per cluster
  3537 0000115F 83FA08                  	cmp	dx, 8  ; >= 532480 sectors
  3538 00001162 7709                    	ja	short FAT32_f_2 ; 8 sectors per cluster
  3539 00001164 7205                    	jb	short FAT32_f_1 ; 1 sector per cluster	
  3540 00001166 3D0020                  	cmp	ax, 2000h ; dx_ax = (8*65536)+8192
  3541 00001169 7302                    	jnb	short FAT32_f_2 ; 12/09/2020 (BugFix)
  3542                                  FAT32_f_1:
  3543 0000116B B101                    	mov	cl, 1	; 1 sector per cluster		
  3544                                  FAT32_f_2:
  3545 0000116D 884E0D                  	mov	[bp+0Dh], cl	 ; [BPB_SecPerClus]
  3546                                  	;mov	byte [bp+10h], 2 ; [BPB_NumFATs] 
  3547                                  	;mov	word [bp+0Eh], 32 ; [BPB_RsvdSecCnt] 
  3548                                  
  3549                                  	; Calculating FAT size in sectors
  3550                                  	; (According to MS FAT32 FS Specification, 2000)
  3551                                  
  3552                                  	; DX_AX = partition (volume) size in sectors
  3553 00001170 2B460E                  	sub	ax, [bp+0Eh]	; [BPB_RsvdSecCnt] ; 32
  3554 00001173 83DA00                  	sbb	dx, 0
  3555                                  		; TmpVal1 = DiskSize - (BPB_ResvdSecCnt +
  3556                                  		;	     		RootDirsectors)
  3557                                  		; RootDirSectors = 0 (for FAT32 FS)
  3558 00001176 89CB                    	mov	bx, cx ; ch = 0
  3559 00001178 C1E308                  	shl	bx, 8 ; * 256
  3560 0000117B 8A4E10                  	mov	cl, [bp+10h] ; [BPB_NumFATs] 
  3561 0000117E 01CB                    	add	bx, cx	
  3562                                  		; TmpVal2 = (256*BPB_SecPerClus)+BPB_NumFATs
  3563 00001180 D1EB                    	shr	bx, 1
  3564                                  		; TmpVal2 = TmpVal2/2
  3565 00001182 89D9                    	mov	cx, bx
  3566 00001184 4B                      	dec	bx  ; TmpVal2-1
  3567 00001185 01D8                    	add	ax, bx
  3568 00001187 83D200                  	adc	dx, 0
  3569 0000118A E8F0FA                  	call	div32
  3570                                  		; FATSz = (TmpVal1+(TmpVal2-1))/TmpVal2
  3571                                  	; DX_AX = FAT size in sectors
  3572 0000118D 894624                  	mov	[bp+24h], ax	; [BPB_FATSz32]
  3573 00001190 895626                  	mov	[bp+26h], dx	; [BPB_FATSz32+2]
  3574                                  	; * 2
  3575 00001193 89D3                    	mov	bx, dx
  3576 00001195 01C0                    	add	ax, ax
  3577 00001197 11D3                    	adc	bx, dx
  3578                                  	; BX_AX = [BPB_NumFATs] * [BPB_FATSz32]
  3579 00001199 8B4E0E                  	mov	cx, [bp+0Eh]	; [BPB_RsvdSecCnt] ; 32
  3580 0000119C 01C1                    	add	cx, ax
  3581 0000119E 83D300                  	adc	bx, 0
  3582                                  	; BX_CX = [BPB_RsvdSecCnt]+[BPB_NumFATs]*[BPB_FATSz32]
  3583 000011A1 8B4620                  	mov	ax, [bp+20h]	; [BPB_TotSec32]
  3584 000011A4 8B5622                  	mov	dx, [bp+22h]	; [BPB_TotSec32+2]
  3585 000011A7 29C8                    	sub	ax, cx
  3586 000011A9 19DA                    	sbb	dx, bx
  3587 000011AB 890E[E66A]              	mov	[data_start], cx
  3588 000011AF 891E[E86A]              	mov	[data_start+2], bx
  3589                                  	; DX_AX = Data sectors
  3590 000011B3 A3[EA6A]                	mov	[data_sectors], ax
  3591 000011B6 8916[EC6A]              	mov	[data_sectors+2], dx
  3592 000011BA 8A4E0D                  	mov	cl, [bp+0Dh]	 ; [BPB_SecPerClus]
  3593 000011BD 30ED                    	xor	ch, ch
  3594 000011BF E8BBFA                  	call	div32 ; DX_AX/CX
  3595                                  	; DX_AX = Count of clusters (rounded down)
  3596 000011C2 A3[EE6A]                	mov	[cluster_count], ax
  3597 000011C5 8916[F06A]              	mov	[cluster_count+2], dx
  3598                                  		
  3599 000011C9 8D7E47                  	lea	di, [bp+71] ; [BS_VolLab]
  3600 000011CC E89B01                  	call	write_volume_name
  3601 000011CF 8D7643                  	lea	si, [bp+67] ; [BS_VolID]
  3602 000011D2 E8F401                  	call	write_volume_serial
  3603 000011D5 E80503                  	call	write_cluster_count
  3604                                  
  3605 000011D8 E87502                  	call	write_formatting_msg
  3606 000011DB B000                    	mov	al, 0
  3607 000011DD E8D102                  	call	write_format_percent_x
  3608                                  
  3609 000011E0 8B461C                  	mov	ax, [bp+1Ch]	; [BPB_HiddSec]
  3610 000011E3 8B561E                  	mov	dx, [bp+1Eh]	; [BPB_HiddSec+2]
  3611 000011E6 0106[E66A]              	add	[data_start], ax
  3612 000011EA 1116[E86A]              	adc	[data_start+2], dx
  3613                                  FAT32_f_3:
  3614                                  	; DX_AX = FAT32 Boot Sector address
  3615 000011EE BB[5B33]                	mov	bx, TRDOS_FAT32_hd_bs
  3616                                  	; ES:BX = Boot Sector 1 Buffer
  3617 000011F1 E8F309                  	call	write_hd_sector
  3618 000011F4 0F82CD02                	jc	formatting_error
  3619 000011F8 E87902                  	call	write_format_percent
  3620 000011FB 83C001                  	add	ax, 1
  3621 000011FE 83D200                  	adc	dx, 0
  3622 00001201 BB[D266]                	mov	bx, HDFORMAT_FSINFO_BUFF
  3623                                  	; ES:BX = FS INFO Sector Buffer (= BS+1)
  3624 00001204 E8E009                  	call	write_hd_sector
  3625 00001207 0F82BA02                	jc	formatting_error
  3626 0000120B E86602                  	call	write_format_percent	
  3627 0000120E 83C001                  	add	ax, 1
  3628 00001211 83D200                  	adc	dx, 0	
  3629 00001214 BB[5B35]                	mov	bx, TRDOS_FAT32_hd_bs + 512
  3630                                  	; ES:BX = Boot Sector 2 Buffer
  3631 00001217 E8CD09                  	call	write_hd_sector
  3632 0000121A 0F82A702                	jc	formatting_error
  3633 0000121E E85302                  	call	write_format_percent
  3634 00001221 B90300                  	mov	cx, 3
  3635                                  FAT32_f_4:
  3636 00001224 51                      	push	cx
  3637 00001225 83C001                  	add	ax, 1
  3638 00001228 83D200                  	adc	dx, 0
  3639 0000122B BB[E668]                	mov	bx, HDFORMAT_EMPTY_BUFF
  3640 0000122E E8B609                  	call	write_hd_sector
  3641 00001231 0F829002                	jc	formatting_error
  3642 00001235 E83C02                  	call	write_format_percent
  3643 00001238 59                      	pop	cx
  3644 00001239 FEC9                    	dec	cl
  3645 0000123B 75E7                    	jnz	short FAT32_f_4
  3646 0000123D 83C001                  	add	ax, 1
  3647 00001240 83D200                  	adc	dx, 0
  3648 00001243 8B4E1C                  	mov	cx, [bp+1Ch]	; [BPB_HiddSec]
  3649 00001246 8B5E1E                  	mov	bx, [bp+1Eh]	; [BPB_HiddSec+2]
  3650 00001249 83C10C                  	add	cx, 12
  3651 0000124C 83D300                  	adc	bx, 0
  3652                                  	; write BACKUP sectors
  3653                                  	; (6,7,8 boot+fsi and 9,10,11 empty sectors) 
  3654 0000124F 39DA                    	cmp	dx, bx
  3655 00001251 729B                    	jb	short FAT32_f_3
  3656 00001253 39C8                    	cmp	ax, cx
  3657 00001255 7297                    	jb	short FAT32_f_3
  3658                                  	; write remain part of reserved sectors
  3659 00001257 8B4E0E                  	mov	cx, [bp+0Eh]	; [BPB_RsvdSecCnt]
  3660 0000125A 83E90C                  	sub	cx, 12
  3661 0000125D 7618                    	jna	short FAT32_f_6
  3662                                  FAT32_f_5:
  3663 0000125F 51                      	push	cx
  3664 00001260 BB[E668]                	mov	bx, HDFORMAT_EMPTY_BUFF
  3665 00001263 E88109                  	call	write_hd_sector
  3666 00001266 0F825B02                	jc	formatting_error
  3667 0000126A E80702                  	call	write_format_percent
  3668 0000126D 83C001                  	add	ax, 1
  3669 00001270 83D200                  	adc	dx, 0
  3670 00001273 59                      	pop	cx
  3671 00001274 49                      	dec	cx
  3672 00001275 75E8                    	jnz	short FAT32_f_5
  3673                                  FAT32_f_6:
  3674                                  	; write FAT sectors
  3675 00001277 8B0E[E66A]              	mov	cx, [data_start] ; lba/abs addr
  3676 0000127B 8B1E[E86A]              	mov	bx, [data_start+2] ; lba/abs addr
  3677 0000127F 53                      	push	bx
  3678 00001280 51                      	push	cx
  3679 00001281 BB[E668]                	mov	bx, HDFORMAT_FATBUFFER
  3680                                  	; ES:BX = FAT Sector Buffer
  3681 00001284 8A4E15                  	mov	cl, [bp+15h] ; [BPB_Media]
  3682 00001287 B5FF                    	mov	ch, 0FFh
  3683 00001289 890F                    	mov	[bx], cx
  3684 0000128B 88E9                    	mov	cl, ch ; cx = 0FFFFh
  3685 0000128D 894F02                  	mov	[bx+2], cx
  3686 00001290 894F04                  	mov	[bx+4], cx
  3687 00001293 894F06                  	mov	[bx+6], cx
  3688                                  	; Root dir cluster number = 2
  3689                                  	; 0FFFFFFFh = end of cluster chain 
  3690 00001296 894F08                  	mov	[bx+8], cx  ; 0FFFFh
  3691 00001299 80E50F                  	and	ch, 0Fh
  3692 0000129C 894F0A                  	mov	[bx+10], cx ; 0FFFh
  3693                                  	;inc	cx
  3694 0000129F E84509                  	call	write_hd_sector
  3695 000012A2 0F821F02                	jc	formatting_error
  3696 000012A6 E8CB01                  	call	write_format_percent
  3697                                  	;mov	bx, HDFORMAT_FATBUFFER
  3698 000012A9 B90000                  	mov	cx, 0
  3699 000012AC 890F                    	mov	[bx], cx
  3700 000012AE 894F02                  	mov	[bx+2], cx
  3701 000012B1 894F04                  	mov	[bx+4], cx
  3702 000012B4 894F06                  	mov	[bx+6], cx
  3703 000012B7 894F08                  	mov	[bx+8], cx
  3704 000012BA 894F0A                  	mov	[bx+10], cx
  3705 000012BD EB0F                    	jmp	short FAT32_f_8
  3706                                  FAT32_f_7:	
  3707 000012BF 53                      	push	bx
  3708 000012C0 51                      	push	cx	
  3709 000012C1 BB[E668]                	mov	bx, HDFORMAT_FATBUFFER
  3710 000012C4 E82009                  	call	write_hd_sector
  3711 000012C7 0F82FA01                	jc	formatting_error
  3712 000012CB E8A601                  	call	write_format_percent
  3713                                  FAT32_f_8:	
  3714 000012CE 59                      	pop	cx
  3715 000012CF 5B                      	pop	bx
  3716 000012D0 83C001                  	add	ax, 1
  3717 000012D3 83D200                  	adc	dx, 0
  3718 000012D6 39DA                    	cmp	dx, bx
  3719 000012D8 72E5                    	jb	short FAT32_f_7
  3720 000012DA 39C8                    	cmp	ax, cx
  3721 000012DC 72E1                    	jb	short FAT32_f_7
  3722                                  
  3723                                  	; write	root directory (1st cluster)
  3724                                  	; as empty sectors
  3725 000012DE 8A4E0D                  	mov	cl, [bp+0Dh]	 ; [BPB_SecPerClus]
  3726 000012E1 30ED                    	xor	ch, ch
  3727 000012E3 290E[EA6A]              	sub	[data_sectors], cx
  3728 000012E7 831E[EC6A]00            	sbb	word [data_sectors+2], 0
  3729                                  FAT32_f_9:
  3730 000012EC 51                      	push	cx
  3731 000012ED BB[E668]                	mov	bx, HDFORMAT_EMPTY_BUFF
  3732 000012F0 E8F408                  	call	write_hd_sector
  3733 000012F3 0F82CE01                	jc	formatting_error
  3734 000012F7 E87A01                  	call	write_format_percent
  3735 000012FA 83C001                  	add	ax, 1
  3736 000012FD 83D200                  	adc	dx, 0
  3737 00001300 59                      	pop	cx
  3738 00001301 FEC9                    	dec	cl
  3739 00001303 75E7                    	jnz	short FAT32_f_9
  3740                                  
  3741                                  	; write DATA sectors 
  3742                                  	; (after root directory 1st cluster)
  3743 00001305 8B0E[EA6A]              	mov	cx, [data_sectors]
  3744 00001309 8B1E[EC6A]              	mov	bx, [data_sectors+2] 
  3745                                  			; NOTE: Partition size must be >= 512 MB
  3746                                  			;	for FAT32 FS  ((BX >= 15))		
  3747                                  FAT32_f_10:	
  3748 0000130D 53                      	push	bx
  3749 0000130E 51                      	push	cx	
  3750 0000130F BB[D264]                	mov	bx, HDFORMAT_SECBUFFER
  3751 00001312 E8D208                  	call	write_hd_sector
  3752 00001315 0F82AC01                	jc	formatting_error
  3753 00001319 E85801                  	call	write_format_percent
  3754 0000131C 59                      	pop	cx
  3755 0000131D 5B                      	pop	bx
  3756 0000131E 83C001                  	add	ax, 1
  3757 00001321 83D200                  	adc	dx, 0
  3758 00001324 49                      	dec	cx
  3759 00001325 75E6                    	jnz	short FAT32_f_10
  3760 00001327 4B                      	dec	bx
  3761 00001328 75E3                    	jnz	short FAT32_f_10
  3762                                  
  3763                                  	; If there are, format remain sectors which are
  3764                                  	; at beyond of data clusters, with zero bytes.
  3765                                  	
  3766 0000132A 8B4E1C                  	mov	cx, [bp+1Ch]	; [BPB_HiddSec]
  3767 0000132D 8B5E1E                  	mov	bx, [bp+1Eh]	; [BPB_HiddSec+2]
  3768                                  FAT16_f_18:	
  3769 00001330 034E20                  	add	cx, [bp+20h]	; [BPB_TotSec32]
  3770 00001333 135E22                  	adc	bx, [bp+22h]	; [BPB_TotSec32+2]
  3771                                  FAT16_f_19:
  3772                                  FAT12_f_8:
  3773                                  	; are there remain sectors (in partition) ?
  3774 00001336 29C1                    	sub	cx, ax
  3775 00001338 19D3                    	sbb	bx, dx
  3776                                  	; 11/02/2019
  3777                                  	; BX must be 0 (Because, 1 cluster <= 32KB. So, 
  3778                                  	;	        remain sectors must not be more than 32K)
  3779 0000133A 751C                    	jnz	short FAT32_f_12 ; There is a wrong thing !!!
  3780                                  				 ; If BX is not zero,	
  3781                                  				 ; it is better to skip this stage...)
  3782 0000133C 09C9                    	or	cx, cx		
  3783 0000133E 7418                    	jz	short FAT32_f_12 ; no.. 
  3784                                  				 ; (good! FAT contains all data sectors)
  3785                                  FAT32_f_11:
  3786 00001340 51                      	push	cx
  3787 00001341 BB[E668]                	mov	bx, HDFORMAT_EMPTY_BUFF
  3788 00001344 E8A008                  	call	write_hd_sector
  3789 00001347 0F827A01                	jc	formatting_error
  3790 0000134B E82601                  	call	write_format_percent
  3791 0000134E 59                      	pop	cx
  3792 0000134F 83C001                  	add	ax, 1
  3793 00001352 83D200                  	adc	dx, 0
  3794 00001355 49                      	dec	cx
  3795 00001356 75E8                    	jnz	short FAT32_f_11
  3796                                  
  3797                                  FAT32_f_12:
  3798                                  SINGLIX_fs1_f_12:
  3799                                  	; End of FAT format routine...
  3800                                  end_of_formatting:
  3801 00001358 B064                    	mov	al, 100
  3802 0000135A E85401                  	call	write_format_percent_x
  3803                                  	;mov	si, CRLF
  3804                                  	;call	print_msg
  3805 0000135D BE[5B55]                	mov	si, Msg_OK
  3806                                  	;call	print_msg
  3807                                  	;jmp	_exit
  3808                                  	; 19/10/2020
  3809 00001360 E947F4                  	jmp	_p_exit
  3810                                  
  3811                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3812                                  ; set & write volume name
  3813                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3814                                  
  3815                                  write_fs_volume_name:
  3816 00001363 C606[BB64]40            	mov	byte [vname_length], 64
  3817 00001368 EB05                    	jmp	short svn_fs
  3818                                  
  3819                                  write_volume_name:
  3820 0000136A C606[BB64]0B            	mov	byte [vname_length], 11
  3821                                  svn_fs:
  3822                                  	; DI = (BS) Volume Label address
  3823 0000136F BE[FD54]                	mov	si, Msg_Volume_Name
  3824 00001372 E80D08                  	call	print_msg
  3825                                  
  3826                                  	; get cursor position
  3827                                  	; bh = 0  ; video page
  3828 00001375 B403                    	mov     ah, 3 ; get cursor pos
  3829 00001377 CD10                    	int     10h
  3830 00001379 8916[A354]              	mov	[Cursor_Pos], dx
  3831                                  
  3832 0000137D E8EF08                  	call	rw_char
  3833 00001380 7207                    	jc	short svn_1
  3834                                  svn_0:
  3835 00001382 AC                      	lodsb
  3836 00001383 3C20                    	cmp	al, 20h
  3837 00001385 7706                    	ja	short svn_2
  3838 00001387 74F9                    	je	short svn_0 
  3839                                  svn_1:
  3840 00001389 BE[C664]                	mov	si, no_name
  3841 0000138C AC                      	lodsb
  3842                                  svn_2:
  3843                                  	;mov	di, [bp+47h) ; [BS_VolLab] ; FAT32
  3844                                  	;mov	di, [bp+2Bh) ; [BS_VolLab] ; FAT16 (&FAT12)
  3845 0000138D 89FB                    	mov	bx, di ; *
  3846 0000138F 30ED                    	xor	ch, ch
  3847 00001391 8A0E[BB64]              	mov	cl, [vname_length] ; 11
  3848 00001395 EB05                    	jmp	short svn_4
  3849                                  svn_3:
  3850 00001397 AC                      	lodsb
  3851 00001398 3C20                    	cmp	al, 20h
  3852 0000139A 7226                    	jb	short svn_6
  3853                                  svn_4:
  3854 0000139C AA                      	stosb
  3855 0000139D E2F8                    	loop	svn_3
  3856                                  svn_5:
  3857 0000139F 8A0E[BB64]              	mov	cl, [vname_length] ; 11
  3858 000013A3 89DE                    	mov	si, bx ; *
  3859 000013A5 BF[BC54]                	mov	di, StrVolumeName
  3860 000013A8 F3A4                    	rep	movsb
  3861                                  	;mov	byte [di], 0
  3862                                  
  3863 000013AA 8B16[A354]              	mov	dx, [Cursor_Pos]
  3864 000013AE BB0700                  	mov	bx, 7
  3865 000013B1 B402                    	mov	ah, 2
  3866 000013B3 CD10                    	int	10h  ; Set Cursor Position
  3867                                  
  3868 000013B5 BE[BC54]                	mov	si, StrVolumeName
  3869 000013B8 E8C707                  	call	print_msg
  3870 000013BB BE[5F55]                	mov	si, CRLF
  3871 000013BE E8C107                  	call	print_msg
  3872 000013C1 C3                      	retn
  3873                                  svn_6:
  3874 000013C2 B020                    	mov	al, 20h
  3875                                  svn_7:
  3876 000013C4 AA                      	stosb
  3877 000013C5 E2FD                    	loop	svn_7
  3878 000013C7 EBD6                    	jmp	short svn_5
  3879                                  
  3880                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3881                                  ; set & write volume serial number (volume ID)
  3882                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3883                                  
  3884                                  write_volume_serial:
  3885                                  	; SI = (BS) Volume Serial Number (binary) address
  3886                                  
  3887                                  	;xor	ax, ax
  3888                                  	;int	1Ah			; get time of day
  3889                                  
  3890                                  	;mov	[si], dx
  3891                                  	;mov	[si+2], cx		; set unique volume ID
  3892                                  
  3893                                  	;mov	ah, 02h			; Return Current Time
  3894                                  	;int	1Ah
  3895                                  	;xchg	ch, cl
  3896                                  	;xchg	dh, dl
  3897                                  
  3898                                  	;add	cx, dx  
  3899                                  	;add	[si+2], cx
  3900                                                 
  3901                                  	;mov	ah, 04h			; Return Current Date
  3902                                  	;int	1Ah
  3903                                  
  3904                                  	;xchg	ch,cl
  3905                                  	;xchg	dh,dl
  3906                                  
  3907                                  	;add	cx, dx  
  3908                                  	;add	[si+2], cx
  3909                                  
  3910                                  	; According to Microsoft DOS 6.0 serial number
  3911                                  	; production method...
  3912                                  	; < Create unique 32 bit serial number >
  3913                                  
  3914                                  	; Create_Serial_ID (MSDOS 6.0 Source code, MSFOR.ASM)
  3915                                  	; (20/04/1987)
  3916                                  	;
  3917                                  	;  Get date (INT 21h, AH=2Bh)
  3918                                  	;  Get time (INT 21h, AH=2Ch)
  3919                                  	;  Serial_ID+0 = DX reg date + DX reg time
  3920                                  	;  Serial_ID+2 = CX reg date + CX reg time
  3921                                  	;  Serial_Num_Low = Serial_ID+2
  3922                                  	;  Serial_Num_High = Serial_ID+0
  3923                                  
  3924 000013C9 B404                    	mov	ah, 04h		; Return Current Date
  3925 000013CB CD1A                    	int	1Ah
  3926                                  
  3927                                  	; DL = Day (BCD)	(20h) 	
  3928                                  	; DH = Month (BCD)	(12h)
  3929                                  	; CH = Century (BCD)	(20h)
  3930                                  	; CL = Year (BCD) 	(17h)
  3931                                  
  3932 000013CD 88D0                    	mov	al, dl
  3933 000013CF E87100                  	call	bcd_to_bin
  3934 000013D2 88C2                    	mov	dl, al 
  3935 000013D4 88F0                    	mov	al, dh
  3936 000013D6 E86A00                  	call	bcd_to_bin
  3937 000013D9 88C6                    	mov	dh, al 
  3938 000013DB 88C8                    	mov	al, cl
  3939 000013DD E86300                  	call	bcd_to_bin
  3940 000013E0 88C1                    	mov	cl, al 
  3941 000013E2 88E8                    	mov	al, ch
  3942 000013E4 E85C00                  	call	bcd_to_bin
  3943 000013E7 88C5                    	mov	ch, al
  3944                                  
  3945                                  	; DH = Month (1-10)
  3946                                  	; DL = Day (1-31)
  3947                                  	; CX = Year (1900-2099)
  3948                                  
  3949 000013E9 52                      	push	dx 
  3950 000013EA 51                      	push	cx
  3951                                  
  3952 000013EB B402                    	mov	ah, 02h		; Return Current Time
  3953 000013ED CD1A                    	int	1Ah
  3954                                  	
  3955                                  	; DH = Seconds (BCD)	(59h) 	
  3956                                  	; CL = Minutes (BCD)	(59h)
  3957                                  	; CH = Hours (BCD)	(23h)
  3958                                  	; DL = Daylight savings time option (1=yes)
  3959                                  
  3960 000013EF 88F0                    	mov	al, dh
  3961 000013F1 E84F00                  	call	bcd_to_bin
  3962 000013F4 88C6                    	mov	dh, al 
  3963 000013F6 88C8                    	mov	al, cl
  3964 000013F8 E84800                  	call	bcd_to_bin
  3965 000013FB 88C1                    	mov	cl, al 
  3966 000013FD 88E8                    	mov	al, ch
  3967 000013FF E84100                  	call	bcd_to_bin
  3968 00001402 88C5                    	mov	ch, al 
  3969                                  
  3970                                  	; CH = Hour (0-23)
  3971                                  	; CL = Minutes (0-59)
  3972                                  	; DH = Seconds (0-59)
  3973                                  	; ((DL = Hundredths (0-99) - MSDOS!))
  3974                                  	; DL = 0 or 1 (here!)
  3975                                  
  3976 00001404 89C8                    	mov	ax, cx
  3977 00001406 59                      	pop	cx
  3978 00001407 01C8                    	add	ax, cx
  3979                                  
  3980 00001409 894402                  	mov	[si+2], ax
  3981                                  
  3982 0000140C 89D0                    	mov	ax, dx
  3983 0000140E 5A                      	pop	dx
  3984 0000140F 01D0                    	add	ax, dx
  3985                                  
  3986 00001411 8904                    	mov	[si], ax
  3987                                  
  3988 00001413 30E4                    	xor	ah, ah		; Read time counter
  3989 00001415 CD1A                    	int	1Ah
  3990                                  
  3991                                  	; CX = High word of clock count
  3992                                  	; DX = Low word of clock count
  3993                                  	; AL = 0 if 24 hours has not passed, else 1
  3994                                  
  3995                                  	; NOTES: 
  3996                                  	; (Ref: vitaly_filatov.tripod.com/ng/asm/asm_029.1.html)
  3997                                  	;
  3998                                     	; Following formulas convert the clock count to
  3999                                          ; the time of day:
  4000                                   	;	Hour      = Clock / 65543 (1007h)
  4001                                  	;	Remainder = Clock MOD 65543
  4002                                   	;
  4003                                  	;	Minutes   = Remainder / 1092 (444h)
  4004                                  	;	Remainder = Remainder MOD 1092
  4005                                  	;
  4006                                  	;	Second    = Remainder / 18.21
  4007                                  	;	Remainder = Remainder MOD 18.21
  4008                                  	;
  4009                                  	;	Hundredths = CINT(Remainder * 100)
  4010                                  
  4011 00001417 0014                    	add	[si], dl
  4012                                  
  4013                                  	; SI = Volume serial number address (4 bytes) 
  4014 00001419 8A04                    	mov	al, [si]
  4015 0000141B E83A08                  	call	bin_to_hex
  4016 0000141E A3[2855]                	mov	[Vol_Serial2+2], ax	
  4017 00001421 8A4401                  	mov	al, [si+1]
  4018 00001424 E83108                  	call	bin_to_hex
  4019 00001427 A3[2655]                	mov	[Vol_Serial2], ax
  4020 0000142A 8A4402                  	mov	al, [si+2]
  4021 0000142D E82808                  	call	bin_to_hex
  4022 00001430 A3[2355]                	mov	[Vol_Serial1+2], ax	
  4023 00001433 8A4403                  	mov	al, [si+3]
  4024 00001436 E81F08                  	call	bin_to_hex
  4025 00001439 A3[2155]                	mov	[Vol_Serial1], ax
  4026                                  
  4027 0000143C BE[0F55]                	mov	si, Msg_Volume_Serial
  4028 0000143F E84007                  	call	print_msg
  4029                                  
  4030 00001442 C3                      	retn
  4031                                  
  4032                                  bcd_to_bin:
  4033 00001443 53                      	push	bx
  4034 00001444 D410                    	db	0D4h,10h  ; Undocumented inst. AAM
  4035                                  			  ; AH = AL / 10h
  4036                                  			  ; AL = AL MOD 10h
  4037 00001446 88C3                    	mov	bl, al
  4038 00001448 B00A                    	mov	al, 10
  4039 0000144A F6E4                    	mul	ah
  4040 0000144C 00D8                    	add	al, bl
  4041 0000144E 5B                      	pop	bx
  4042 0000144F C3                      	retn
  4043                                  
  4044                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4045                                  ; write formatting percentage
  4046                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4047                                  
  4048                                  write_formatting_msg:
  4049                                  	;mov	ax, [pp_Sectors]
  4050                                  	;mov	dx, [pp_Sectors+2]
  4051                                  	; 16/02/2019
  4052 00001450 A1[9E6D]                	mov	ax, [ppn_Sectors]
  4053 00001453 8B16[A06D]              	mov	dx, [ppn_Sectors+2]
  4054                                  
  4055                                  	; DX_AX = Total sectors for percentage  
  4056                                  	;mov	cx, 100	
  4057 00001457 B90064                  	mov	cx, 256*100 ; 16/03/2021 
  4058 0000145A E820F8                  	call	div32
  4059 0000145D A3[F46A]                	mov	[format_percent], ax
  4060                                  
  4061 00001460 BE[4755]                	mov	si, msg_formatting
  4062 00001463 E81C07                  	call	print_msg
  4063                                  
  4064                                  	; get cursor position
  4065                                  	; bh = 0  ; video page
  4066 00001466 B403                    	mov     ah, 3 ; get cursor pos
  4067 00001468 CD10                    	int     10h
  4068 0000146A 8916[A354]              	mov	[Cursor_Pos], dx
  4069                                  
  4070 0000146E C606[F66A]FF            	mov	byte [prev_percent], 255
  4071                                  
  4072 00001473 C3                      	retn
  4073                                  
  4074                                  write_format_percent:
  4075                                  	; DX_AX = Current sector (which has been written)
  4076                                  
  4077 00001474 50                      	push	ax
  4078 00001475 52                      	push	dx
  4079 00001476 53                      	push	bx
  4080 00001477 51                      	push	cx
  4081 00001478 56                      	push	si
  4082                                  
  4083 00001479 2B461C                  	sub	ax, [bp+1Ch]	; [BPB_HiddSec]
  4084 0000147C 1B561E                  	sbb	dx, [bp+1Eh]	; [BPB_HiddSec+2]
  4085                                  wpc_t:
  4086 0000147F 8B0E[F46A]              	mov	cx, [format_percent]
  4087 00001483 E8F7F7                  	call	div32
  4088                                  	; AL = percentage value between 1 to 100
  4089                                  	; 16/03/2021
  4090                                  	; AH = percentage value between 1 to 100
  4091                                  wpc_x:
  4092                                  	;cmp	al, [prev_percent]
  4093                                  	;je	short wpc_y
  4094                                  	;mov	[prev_percent], al
  4095                                  	; 16/03/2021
  4096 00001486 3A26[F66A]              	cmp	ah, [prev_percent]
  4097 0000148A 741F                    	je	short wpc_y
  4098 0000148C 8826[F66A]              	mov	[prev_percent], ah
  4099 00001490 8B16[A354]              	mov	dx, [Cursor_Pos]
  4100 00001494 BB0700                  	mov	bx, 7
  4101 00001497 B402                    	mov	ah, 2
  4102 00001499 CD10                    	int	10h  ; Set Cursor Position
  4103 0000149B 31D2                    	xor	dx, dx
  4104 0000149D 30E4                    	xor	ah, ah
  4105 0000149F A0[F66A]                	mov	al, [prev_percent] ; 16/03/2021
  4106 000014A2 BE[5555]                	mov	si, format_percent_str + 2
  4107 000014A5 E89907                  	call	bin_to_decimal
  4108 000014A8 E8D706                  	call	print_msg
  4109                                  wpc_y:
  4110 000014AB 5E                      	pop	si
  4111 000014AC 59                      	pop	cx
  4112 000014AD 5B                      	pop	bx
  4113 000014AE 5A                      	pop	dx
  4114 000014AF 58                      	pop	ax
  4115 000014B0 C3                      	retn
  4116                                  
  4117                                  write_format_percent_x:
  4118                                  	; AL = % number
  4119                                  
  4120 000014B1 50                      	push	ax
  4121 000014B2 52                      	push	dx
  4122 000014B3 53                      	push	bx
  4123 000014B4 51                      	push	cx
  4124 000014B5 56                      	push	si
  4125                                  
  4126 000014B6 EBCE                    	jmp	short wpc_x
  4127                                  
  4128                                  write_fs_format_percent:
  4129                                  	; DX_AX = Current sector (which has been written)
  4130                                  
  4131 000014B8 50                      	push	ax
  4132 000014B9 52                      	push	dx
  4133 000014BA 53                      	push	bx
  4134 000014BB 51                      	push	cx
  4135 000014BC 56                      	push	si
  4136                                  
  4137 000014BD 2B460C                  	sub	ax, [bp+0Ch]	; [bsBeginSector]
  4138 000014C0 1B560E                  	sbb	dx, [bp+0Eh]	; [bsBeginSector+2]
  4139 000014C3 EBBA                    	jmp	short wpc_t	
  4140                                  	
  4141                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4142                                  ; format error 
  4143                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4144                                  
  4145                                  formatting_error:
  4146 000014C5 8B26[E468]              	mov	sp, [old_sp]
  4147                                  
  4148 000014C9 88E0                    	mov	al, ah ;  error code
  4149 000014CB E88A07                  	call	bin_to_hex
  4150 000014CE A3[6D55]                	mov 	[error_code], ax
  4151                                  
  4152 000014D1 BE[5F55]                	mov	si, CRLF
  4153 000014D4 E8AB06                  	call	print_msg
  4154                                  
  4155 000014D7 BE[6255]                	mov	si, Msg_Error
  4156                                  	;call	print_msg
  4157                                  	;jmp	_exit
  4158                                  	; 19/10/2020
  4159 000014DA E9CDF2                  	jmp	_p_exit
  4160                                  
  4161                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4162                                  ; write cluster count
  4163                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4164                                  
  4165                                  write_cluster_count:
  4166 000014DD BE[2D55]                	mov	si, msg_cluster_count
  4167 000014E0 E89F06                  	call	print_msg
  4168 000014E3 A1[EE6A]                	mov	ax, [cluster_count]
  4169 000014E6 8B16[F06A]              	mov	dx, [cluster_count+2]
  4170 000014EA BE[4355]                	mov	si, cluster_count_str+6
  4171 000014ED E85107                  	call	bin_to_decimal
  4172                                  	;call	print_msg
  4173                                  	;retn
  4174                                  	; 19/10/2020
  4175 000014F0 E98F06                  	jmp	print_msg 
  4176                                  
  4177                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4178                                  ; FAT16 FORMATTING
  4179                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4180                                  	; 08/02/2019 (Modified for -only- FAT16 CHS partitions) 
  4181                                  FAT16_hd_format:
  4182 000014F3 B80607                  	mov	ax, 0706h ; db 06h, 07h ; 'push es, pop es'
  4183 000014F6 38C2                    	cmp	dl, al ; 06h ; Big CHS partition (>= 32MB)
  4184 000014F8 7403                    	je	short FAT16_big_chs_format
  4185                                  	;mov	ax, 070Eh ; db 0Eh, 07h	; 'push cs, pop es'
  4186                                  	;cmp	dl, al ; 0Eh ; LBA partition
  4187                                  	;je	short FAT16_lba_format
  4188                                  FAT16_chs_format:  
  4189                                  	; Partition Type: 04h, CHS (<32 MB) partition
  4190 000014FA B80400                  	mov	ax, 0004h ; db 04h, 00h ; 'add al, 0'
  4191                                  FAT16_big_chs_format:
  4192                                  ;FAT16_lba_format:
  4193                                  	; Put TRDOS 386 FAT16 partition magic word 
  4194                                  	; at offset 3Eh, in TRDOS386 FAT16 boot sector.
  4195 000014FD BD[5B37]                	mov	bp, TRDOS_FAT16_hd_bs
  4196 00001500 8D7E03                  	lea	di, [bp+3]
  4197 00001503 BE[BC64]                	mov	si, bs_oem_name
  4198 00001506 B90400                  	mov	cx, 4
  4199 00001509 F3A5                    	rep	movsw 
  4200 0000150B 89463E                  	mov	[bp+3Eh], ax	; [loc_3E]
  4201                                  
  4202 0000150E A1[6E3F]                	mov	ax, [sectors]
  4203 00001511 894618                  	mov	[bp+18h], ax	; [BPB_SecPerTrk]
  4204 00001514 A1[703F]                	mov	ax, [heads]
  4205 00001517 89461A                  	mov	[bp+1Ah], ax	; [BPB_NumHeads]
  4206 0000151A A1[6C6D]                	mov	ax, [pp_StartSector]
  4207 0000151D 89461C                  	mov	[bp+1Ch], ax	; [BPB_HiddSec]
  4208 00001520 A1[6E6D]                	mov	ax, [pp_StartSector+2]
  4209 00001523 89461E                  	mov	[bp+1Eh], ax	; [BPB_HiddSec+2]
  4210                                  	;mov	ax, [pp_Sectors]
  4211 00001526 A1[9E6D]                	mov	ax, [ppn_Sectors] ; 16/02/2019
  4212                                  	;mov	dx, [pp_Sectors+2]
  4213 00001529 8B16[A06D]              	mov	dx, [ppn_Sectors+2] ; 16/02/2019
  4214 0000152D 21D2                    	and	dx, dx
  4215 0000152F 7505                    	jnz	short FAT16_f_0
  4216 00001531 894613                  	mov	[bp+13h], ax	; [BPB_TotSec16]
  4217                                  	; CX = 0
  4218                                  	;mov	[bp+20h], cx	; [BPB_TotSec32] =  0
  4219                                  	;mov	[bp+22h], cx	; [BPB_TotSec32+2] = 0
  4220 00001534 EB06                    	jmp	short FAT16_f_1
  4221                                  FAT16_f_0:
  4222 00001536 894620                  	mov	[bp+20h], ax	; [BPB_TotSec32]
  4223                                  	;;mov	dx, [pp_Sectors+2]
  4224                                  	;mov	dx, [ppn_Sectors+2] ; 16/02/2019 
  4225 00001539 895622                  	mov	[bp+22h], dx	; [BPB_TotSec32+2]
  4226                                  	; CX = 0
  4227                                  	;mov	[bp+13h], cx ; [BPB_TotSec16] = 0
  4228                                  FAT16_f_1:
  4229                                  	; Sectors per cluster calculation
  4230                                  	; (According to MS FAT32 FS specification.)
  4231 0000153C B102                    	mov	cl, 2  ; 2 sectors per cluster
  4232 0000153E 09D2                    	or	dx, dx
  4233 00001540 7507                    	jnz	short FAT16_f_2 ; >2 sectors (>16MB)
  4234 00001542 3DA87F                  	cmp	ax, 32680
  4235 00001545 763C                    	jna	short FAT16_f_10 ; 2 sectors, <=16MB
  4236                                  	; > 16MB
  4237 00001547 EB38                    	jmp	short FAT16_f_9 ; 4 sectors per cluster
  4238                                  FAT16_f_2:
  4239 00001549 83FA04                  	cmp	dx, 4  ; >= 262144 sectors ; >=128MB
  4240 0000154C 7708                    	ja	short FAT16_f_3 ; >4 sectors per cluster
  4241 0000154E 7231                    	jb	short FAT16_f_9 ; 4 sectors per cluster	
  4242 00001550 09C0                    	or	ax, ax ; dx_ax = (4*65536)+0
  4243 00001552 742D                    	jz	short FAT16_f_9 ; 4 sectors per cluster
  4244 00001554 EB29                    	jmp	short FAT16_f_8 ; 8 sectors per cluster
  4245                                  FAT16_f_3:
  4246 00001556 83FA08                  	cmp	dx, 8  ; >= 524288 sectors ; >=256MB
  4247 00001559 7708                    	ja	short FAT16_f_4 ; >8 sectors per cluster
  4248 0000155B 7222                    	jb	short FAT16_f_8 ; 8 sectors per cluster	
  4249 0000155D 21C0                    	and	ax, ax ; dx_ax = (8*65536)+0
  4250 0000155F 741E                    	jz	short FAT16_f_8 ; 8 sectors per cluster
  4251 00001561 EB1A                    	jmp	short FAT16_f_7 ; 16 sectors per cluster
  4252                                  FAT16_f_4:
  4253 00001563 83FA10                  	cmp	dx, 16 ; >= 1048576 sectors ; >=512MB
  4254 00001566 7708                    	ja	short FAT16_f_5 ; >16 sectors per cluster
  4255 00001568 7213                    	jb	short FAT16_f_7 ; 16 sectors per cluster	
  4256 0000156A 21C0                    	and	ax, ax ; dx_ax = (16*65536)+0
  4257 0000156C 740F                    	jz	short FAT16_f_7 ; 16 sectors per cluster
  4258 0000156E EB0B                    	jmp	short FAT16_f_6 ; 32 sectors per cluster
  4259                                  FAT16_f_5:
  4260 00001570 83FA20                  	cmp	dx, 32 ; >= 2097152 sectors ; >=1GB
  4261 00001573 7206                    	jb	short FAT16_f_6 ; 32 sectors per cluster
  4262 00001575 09C0                    	or	ax, ax		; dx_ax = (32*65536)+0
  4263 00001577 7402                    	jz	short FAT16_f_6 ; 32 sectors per cluster
  4264                                  	; >1GB (<=2GB)
  4265                                  	; 64 sectors per cluster
  4266 00001579 D0E1                    	shl	cl, 1
  4267                                  FAT16_f_6:
  4268                                  	; 32 sectors per cluster (for <= 2GB volumes)
  4269 0000157B D0E1                    	shl	cl, 1	
  4270                                  FAT16_f_7:
  4271                                  	; 16 sectors per cluster (for <= 1GB volumes)
  4272 0000157D D0E1                    	shl	cl, 1
  4273                                  FAT16_f_8:
  4274                                  	; 8 sectors per cluster (for <= 512MB volumes)
  4275 0000157F D0E1                    	shl	cl, 1	
  4276                                  FAT16_f_9:
  4277                                  	; 4 sectors per cluster (for <= 256MB volumes)
  4278 00001581 D0E1                    	shl	cl, 1	
  4279                                  FAT16_f_10:	
  4280                                  	; 2 sectors per cluster (for <= 128MB volumes)
  4281 00001583 884E0D                  	mov	[bp+0Dh], cl	 ; [BPB_SecPerClus]
  4282                                  	;mov	byte [bp+10h], 2 ; [BPB_NumFATs] 
  4283                                  	;mov	word [bp+0Eh], 1 ; [BPB_RsvdSecCnt] 
  4284                                  	;mov	word [bp+11h], 512 ; [BPB_RootEntCnt]
  4285                                  	
  4286                                  	; Calculating FAT size in sectors
  4287                                  	; (According to MS FAT32 FS Specification, 2000)
  4288                                  
  4289                                  	; DX_AX = partition (volume) size in sectors
  4290 00001586 8B5E11                  	mov	bx, [bp+11h]	; [BPB_RootEntCnt] = 512
  4291 00001589 83C30F                  	add	bx, 15 ; bx = 527
  4292 0000158C C1EB04                  	shr	bx, 4 ; /16 = 527/16 = 32
  4293                                  		; ((32*BX)+511)/512
  4294 0000158F 891E[F26A]              	mov	[root_dir_secs], bx
  4295 00001593 035E0E                  	add	bx, [bp+0Eh]	; [BPB_RsvdSecCnt] ; 1
  4296 00001596 29D8                    	sub	ax, bx
  4297 00001598 83DA00                  	sbb	dx, 0
  4298                                  		; TmpVal1 = DiskSize - (BPB_ResvdSecCnt +
  4299                                  		;	     		RootDirsectors)
  4300                                  	;mov	bx, cx ; ch = 0
  4301                                  	;shl	bx, 8 ; * 256
  4302                                  	; 11/02/2019
  4303 0000159B 88CF                    	mov	bh, cl
  4304 0000159D 30DB                    	xor	bl, bl
  4305 0000159F B102                    	mov	cl, 2 ; [BPB_NumFATs] 
  4306 000015A1 01CB                    	add	bx, cx	
  4307                                  		; TmpVal2 = (256*BPB_SecPerClus)+BPB_NumFATs
  4308 000015A3 89D9                    	mov	cx, bx
  4309 000015A5 4B                      	dec	bx  ; TmpVal2-1
  4310 000015A6 01D8                    	add	ax, bx
  4311 000015A8 83D200                  	adc	dx, 0
  4312 000015AB E8CFF6                  	call	div32
  4313                                  		; FATSz = (TmpVal1+(TmpVal2-1))/TmpVal2
  4314                                  	; AX = FAT size in sectors
  4315                                  	; DX = 0
  4316 000015AE 894616                  	mov	[bp+16h], ax	; [BPB_FATSz16]
  4317                                  	; * 2
  4318 000015B1 D1E0                    	shl	ax, 1
  4319                                  	; AX = [BPB_NumFATs] * [BPB_FATSz16]
  4320 000015B3 8B4E0E                  	mov	cx, [bp+0Eh]	; [BPB_RsvdSecCnt] ; 1
  4321 000015B6 01C1                    	add	cx, ax
  4322                                  	; CX = [BPB_RsvdSecCnt]+([BPB_NumFATs]*[BPB_FATSz16])
  4323 000015B8 030E[F26A]              	add	cx, [root_dir_secs] ; + RootDirsectors
  4324 000015BC 29DB                    	sub	bx, bx ; BX = 0
  4325                                  	; BX_CX = [BPB_RsvdSecCnt]+([BPB_NumFATs]*[BPB_FATSz16])
  4326                                  	;	  + RootDirSectors
  4327 000015BE 8B4613                  	mov	ax, [bp+13h]	; [BPB_TotSec16]
  4328                                  	;sub	dx, dx 
  4329                                  	; DX = 0
  4330 000015C1 21C0                    	and	ax, ax
  4331 000015C3 7506                    	jnz	short FAT16_f_11
  4332 000015C5 8B4620                  	mov	ax, [bp+20h]	; [BPB_TotSec32]
  4333 000015C8 8B5622                  	mov	dx, [bp+22h]	; [BPB_TotSec32+2]
  4334                                  FAT16_f_11:
  4335 000015CB 29C8                    	sub	ax, cx
  4336 000015CD 19DA                    	sbb	dx, bx
  4337 000015CF 890E[E66A]              	mov	[data_start], cx
  4338 000015D3 891E[E86A]              	mov	[data_start+2], bx
  4339                                  	; DX_AX = Data sectors
  4340 000015D7 A3[EA6A]                	mov	[data_sectors], ax
  4341 000015DA 8916[EC6A]              	mov	[data_sectors+2], dx
  4342 000015DE 8A4E0D                  	mov	cl, [bp+0Dh]	 ; [BPB_SecPerClus]
  4343 000015E1 30ED                    	xor	ch, ch
  4344 000015E3 E897F6                  	call	div32 ; DX_AX/CX
  4345                                  	; AX = Count of clusters (rounded down)
  4346                                  	; DX = 0
  4347 000015E6 A3[EE6A]                	mov	[cluster_count], ax
  4348 000015E9 8916[F06A]              	mov	[cluster_count+2], dx
  4349                                  
  4350 000015ED 8D7E2B                  	lea	di, [bp+43] ; [BS_VolLab]
  4351 000015F0 E877FD                  	call	write_volume_name
  4352 000015F3 8D7627                  	lea	si, [bp+39] ; [BS_VolID]
  4353 000015F6 E8D0FD                  	call	write_volume_serial
  4354 000015F9 E8E1FE                  	call	write_cluster_count	
  4355                                  
  4356 000015FC E851FE                  	call	write_formatting_msg
  4357 000015FF B000                    	mov	al, 0
  4358 00001601 E8ADFE                  	call	write_format_percent_x
  4359                                  
  4360 00001604 8B461C                  	mov	ax, [bp+1Ch]	; [BPB_HiddSec]
  4361 00001607 8B561E                  	mov	dx, [bp+1Eh]	; [BPB_HiddSec+2]
  4362                                  
  4363 0000160A 0106[E66A]              	add	[data_start], ax
  4364 0000160E 1116[E86A]              	adc	[data_start+2], dx
  4365                                  
  4366                                  	; DX_AX = FAT16 Boot Sector address
  4367 00001612 BB[5B37]                	mov	bx, TRDOS_FAT16_hd_bs
  4368                                  	; ES:BX = Boot Sector Buffer
  4369 00001615 E8CF05                  	call	write_hd_sector
  4370 00001618 0F82A9FE                	jc	formatting_error
  4371 0000161C E855FE                  	call	write_format_percent
  4372 0000161F 83C001                  	add	ax, 1
  4373 00001622 83D200                  	adc	dx, 0
  4374                                  	; write remain part of reserved sectors
  4375 00001625 8B4E0E                  	mov	cx, [bp+0Eh] ; [BPB_RsvdSecCnt]
  4376                                  	;sub	cx, 1
  4377                                  	;jna	short FAT16_f_13
  4378                                  	; 11/02/2019
  4379 00001628 49                      	dec	cx
  4380 00001629 7418                    	jz	short FAT16_f_13
  4381                                  FAT16_f_12:
  4382 0000162B 51                      	push	cx
  4383 0000162C BB[E668]                	mov	bx, HDFORMAT_EMPTY_BUFF
  4384 0000162F E8B505                  	call	write_hd_sector
  4385 00001632 0F828FFE                	jc	formatting_error
  4386 00001636 E83BFE                  	call	write_format_percent
  4387 00001639 83C001                  	add	ax, 1
  4388 0000163C 83D200                  	adc	dx, 0
  4389 0000163F 59                      	pop	cx
  4390 00001640 49                      	dec	cx ; dec cl
  4391 00001641 75E8                    	jnz	short FAT16_f_12
  4392                                  FAT16_f_13:
  4393                                  	; write FAT sectors
  4394 00001643 8B0E[E66A]              	mov	cx, [data_start] ; lba/abs addr
  4395 00001647 8B1E[E86A]              	mov	bx, [data_start+2] ; lba/abs addr
  4396                                  
  4397                                  	; 11/02/2019
  4398 0000164B 2B0E[F26A]              	sub	cx, [root_dir_secs]
  4399 0000164F 83DB00                  	sbb	bx, 0
  4400                                  
  4401 00001652 53                      	push	bx
  4402 00001653 51                      	push	cx
  4403 00001654 BB[E668]                	mov	bx, HDFORMAT_FATBUFFER
  4404                                  	; ES:BX = FAT Sector Buffer
  4405 00001657 8A4E15                  	mov	cl, [bp+15h] ; [BPB_Media]
  4406 0000165A B5FF                    	mov	ch, 0FFh
  4407 0000165C 890F                    	mov	[bx], cx ; 0FFF8h
  4408 0000165E 88E9                    	mov	cl, ch ; cx = 0FFFFh
  4409 00001660 894F02                  	mov	[bx+2], cx
  4410                                  	;inc	cx
  4411 00001663 E88105                  	call	write_hd_sector
  4412 00001666 0F825BFE                	jc	formatting_error
  4413 0000166A E807FE                  	call	write_format_percent
  4414                                  	;mov	bx, HDFORMAT_FATBUFFER
  4415 0000166D B90000                  	mov	cx, 0
  4416 00001670 890F                    	mov	[bx], cx
  4417 00001672 894F02                  	mov	[bx+2], cx
  4418 00001675 EB0F                    	jmp	short FAT16_f_15
  4419                                  FAT16_f_14:	
  4420 00001677 53                      	push	bx
  4421 00001678 51                      	push	cx	
  4422 00001679 BB[E668]                	mov	bx, HDFORMAT_FATBUFFER
  4423 0000167C E86805                  	call	write_hd_sector
  4424 0000167F 0F8242FE                	jc	formatting_error
  4425 00001683 E8EEFD                  	call	write_format_percent
  4426                                  FAT16_f_15:	
  4427 00001686 59                      	pop	cx
  4428 00001687 5B                      	pop	bx
  4429 00001688 83C001                  	add	ax, 1
  4430 0000168B 83D200                  	adc	dx, 0
  4431 0000168E 39DA                    	cmp	dx, bx
  4432 00001690 72E5                    	jb	short FAT16_f_14
  4433 00001692 39C8                    	cmp	ax, cx
  4434 00001694 72E1                    	jb	short FAT16_f_14
  4435                                  
  4436                                  	; write	root directory sectors
  4437                                  	; as empty sectors
  4438 00001696 8B0E[F26A]              	mov	cx, [root_dir_secs]
  4439                                  FAT16_f_16:
  4440 0000169A 51                      	push	cx
  4441 0000169B BB[E668]                	mov	bx, HDFORMAT_EMPTY_BUFF
  4442 0000169E E84605                  	call	write_hd_sector
  4443 000016A1 0F8220FE                	jc	formatting_error
  4444 000016A5 E8CCFD                  	call	write_format_percent
  4445 000016A8 83C001                  	add	ax, 1
  4446 000016AB 83D200                  	adc	dx, 0
  4447 000016AE 59                      	pop	cx
  4448 000016AF 49                      	dec	cx
  4449 000016B0 75E8                    	jnz	short FAT16_f_16	
  4450                                  
  4451                                  	; write DATA sectors 
  4452                                  	; (after root directory sectors)
  4453 000016B2 8B0E[EA6A]              	mov	cx, [data_sectors]
  4454 000016B6 8B1E[EC6A]              	mov	bx, [data_sectors+2]
  4455                                  	; 11/02/2019
  4456 000016BA 43                      	inc	bx ; 0 -> 1, 1-> 2
  4457                                  FAT16_f_17:	
  4458 000016BB 53                      	push	bx
  4459 000016BC 51                      	push	cx	
  4460 000016BD BB[D264]                	mov	bx, HDFORMAT_SECBUFFER
  4461 000016C0 E82405                  	call	write_hd_sector
  4462 000016C3 0F82FEFD                	jc	formatting_error
  4463 000016C7 E8AAFD                  	call	write_format_percent
  4464 000016CA 59                      	pop	cx
  4465 000016CB 5B                      	pop	bx
  4466 000016CC 83C001                  	add	ax, 1
  4467 000016CF 83D200                  	adc	dx, 0
  4468 000016D2 49                      	dec	cx
  4469 000016D3 75E6                    	jnz	short FAT16_f_17
  4470 000016D5 4B                      	dec	bx
  4471 000016D6 75E3                    	jnz	short FAT16_f_17
  4472                                  
  4473                                  	; If there are, format remain sectors which are
  4474                                  	; at beyond of data clusters, with zero bytes.
  4475                                  	
  4476 000016D8 8B4E1C                  	mov	cx, [bp+1Ch]	; [BPB_HiddSec]
  4477 000016DB 8B5E1E                  	mov	bx, [bp+1Eh]	; [BPB_HiddSec+2]
  4478                                  
  4479 000016DE 837E1300                	cmp	word [bp+13h], 0 ; [BPB_TotSec16]
  4480 000016E2 0F844AFC                	jz	FAT16_f_18
  4481 000016E6 034E13                  	add	cx, [bp+13h]	; [BPB_TotSec16]
  4482 000016E9 83D300                  	adc	bx, 0
  4483 000016EC E947FC                  	jmp	FAT16_f_19
  4484                                  
  4485                                  FAT12_hd_format:
  4486 000016EF BD[5B39]                	mov	bp, TRDOS_FAT12_hd_bs
  4487 000016F2 8D7E03                  	lea	di, [bp+3]
  4488 000016F5 BE[BC64]                	mov	si, bs_oem_name
  4489 000016F8 B90400                  	mov	cx, 4
  4490 000016FB F3A5                    	rep	movsw 
  4491 000016FD A1[6E3F]                	mov	ax, [sectors]
  4492 00001700 894618                  	mov	[bp+18h], ax	; [BPB_SecPerTrk]
  4493 00001703 A1[703F]                	mov	ax, [heads]
  4494 00001706 89461A                  	mov	[bp+1Ah], ax	; [BPB_NumHeads]
  4495 00001709 A1[6C6D]                	mov	ax, [pp_StartSector]
  4496 0000170C 89461C                  	mov	[bp+1Ch], ax	; [BPB_HiddSec]
  4497 0000170F A1[6E6D]                	mov	ax, [pp_StartSector+2]
  4498 00001712 89461E                  	mov	[bp+1Eh], ax	; [BPB_HiddSec+2]
  4499                                  	;mov	ax, [pp_Sectors]
  4500 00001715 A1[9E6D]                	mov	ax, [ppn_Sectors] ; 16/02/2019
  4501 00001718 894613                  	mov	[bp+13h], ax	; [BPB_TotSec16]
  4502                                  
  4503                                  	; 11/02/2019
  4504 0000171B 31F6                    	xor	si, si ; reset (FAT size fix) flag
  4505 0000171D 8B4E0E                  	mov	cx, [bp+0Eh]	; [BPB_RsvdSecCnt] ; 1
  4506 00001720 8B5611                  	mov	dx, [bp+11h]	; [BPB_RootEntCnt] = 512
  4507 00001723 83C20F                  	add	dx, 15	; (16-1) (512-1)
  4508 00001726 C1EA04                  	shr	dx, 4	; /16  (*32/512)
  4509                                  	; AX = Root dir sectors
  4510                                  	; CX = [BPB_RsvdSecCnt]+([BPB_NumFATs]*[BPB_FATSz16])
  4511 00001729 01D1                    	add	cx, dx ; + RootDirsectors ; + 32
  4512 0000172B 890E[F26A]              	mov	[root_dir_secs], cx ; = 33
  4513                                  
  4514                                  	; 11/02/2019
  4515                                  	;sub	ax, 33  ; 1 reserved sector, 32 root dir sectors
  4516                                  			; .. now AX has number of data sectors
  4517                                  			;	 		+ 2* (FAT sectors)
  4518 0000172F 29C8                    	sub	ax, cx	
  4519                                  FAT12_f_10:	; 11/02/2019
  4520                                  	; Sectors per cluster calculation
  4521                                  	; (According to MS FAT32 FS specification.)
  4522                                  	;mov	cx, 1  ; 1 sector per cluster
  4523 00001731 B101                    	mov	cl, 1  ; CH = 0
  4524                                  FAT12_f_0:
  4525 00001733 3DF50F                  	cmp	ax, 4085 ; Max. cluster count for FAT12
  4526 00001736 7206                    	jb	short FAT12_f_1
  4527 00001738 D0E1                    	shl	cl, 1 ; *2
  4528 0000173A D1E8                    	shr	ax, 1 ; /2
  4529 0000173C EBF5                    	jmp	short FAT12_f_0
  4530                                  FAT12_f_1:
  4531 0000173E 884E0D                  	mov	[bp+0Dh], cl	 ; [BPB_SecPerClus]
  4532                                  	;mov	byte [bp+10h], 2 ; [BPB_NumFATs] 
  4533                                  	;mov	word [bp+0Eh], 1 ; [BPB_RsvdSecCnt] 
  4534                                  	;mov	word [bp+11h], 512 ; [BPB_RootEntCnt]
  4535                                  	
  4536                                  	; Calculating FAT size in sectors
  4537                                  	; AX = partition (volume) size in sectors
  4538                                  	; CX = sectors per clusters
  4539 00001741 31D2                    	xor	dx, dx
  4540 00001743 F7F1                    	div	cx
  4541                                  	; AX = cluster count (only for FAT size calc)
  4542                                  	; DX = 0
  4543 00001745 83C002                  	add	ax, 2  ; cluster 2 to ...
  4544 00001748 89C2                    	mov	dx, ax
  4545 0000174A D1E2                    	shl	dx, 1
  4546 0000174C 01D0                    	add	ax, dx ; *3
  4547 0000174E D1E8                    	shr	ax, 1  ; /2
  4548 00001750 83D000                  	adc	ax, 0  ; +0.5 -> +1
  4549                                  
  4550                                  	; AX = FAT bytes for 12 bit cluster numbers
  4551                                  	
  4552 00001753 B90002                  	mov	cx, 512		; [BPB_BytesPerSec]
  4553 00001756 01C8                    	add	ax, cx		
  4554 00001758 48                      	dec	ax		; [BPB_BytesPerSec] - 1
  4555 00001759 29D2                    	sub	dx, dx
  4556 0000175B F7F1                    	div	cx
  4557 0000175D 894616                  	mov	[bp+16h], ax	; [BPB_FATSz16]
  4558                                  	; * 2
  4559 00001760 D1E0                    	shl	ax, 1
  4560                                  	; AX = [BPB_NumFATs] * [BPB_FATSz16]
  4561                                  
  4562                                  	;mov	cx, [bp+0Eh]	; [BPB_RsvdSecCnt] ; 1
  4563                                  	;add	cx, ax
  4564                                  	;mov	ax, [bp+11h]	; [BPB_RootEntCnt] = 512
  4565                                  	;add	ax, 15	; (16-1) (512-1)
  4566                                  	;shr	ax, 4	; /16  (*32/512)
  4567                                  	;; AX = Root dir sectors
  4568                                  	;; CX = [BPB_RsvdSecCnt]+([BPB_NumFATs]*[BPB_FATSz16])
  4569                                  	;add	cx, ax ; + RootDirsectors
  4570                                  	;mov	[root_dir_secs], ax
  4571                                  
  4572                                  	; 11/02/2019
  4573                                  	;mov	cx, 33
  4574 00001762 8B0E[F26A]              	mov	cx, [root_dir_secs]
  4575 00001766 034E0E                  	add	cx, [bp+0Eh]	; [BPB_RsvdSecCnt] ; 1
  4576                                  		; cx = root directory sectors + reserved sectors
  4577 00001769 01C1                    	add	cx, ax
  4578                                  	; CX = [BPB_RsvdSecCnt]+([BPB_NumFATs]*[BPB_FATSz16])
  4579                                  	;	  + RootDirSectors
  4580 0000176B 8B4613                  	mov	ax, [bp+13h]	; [BPB_TotSec16]
  4581 0000176E 29C8                    	sub	ax, cx
  4582                                  		 ; AX = data sectors
  4583                                  		 ; cH = 0
  4584                                  
  4585                                  	; 11/02/2019 - fix FAT size (better method)
  4586 00001770 09F6                    	or	si, si
  4587 00001772 7504                    	jnz	short FAT12_f_9
  4588                                  
  4589 00001774 89C6                    	mov	si, ax  ; ax = data sectors
  4590 00001776 EBB9                    	jmp	short FAT12_f_10
  4591                                  
  4592                                  FAT12_f_9:
  4593 00001778 31D2                    	xor	dx, dx
  4594 0000177A 890E[E66A]              	mov	[data_start], cx
  4595 0000177E 8916[E86A]              	mov	[data_start+2], dx ; 0
  4596                                  	; DX_AX = Data sectors
  4597 00001782 A3[EA6A]                	mov	[data_sectors], ax
  4598 00001785 8916[EC6A]              	mov	[data_sectors+2], dx ; 0
  4599 00001789 8A4E0D                  	mov	cl, [bp+0Dh]	 ; [BPB_SecPerClus]
  4600 0000178C 28ED                    	sub	ch, ch
  4601 0000178E F7F1                    	div	cx
  4602                                  	; AX = Count of clusters (rounded down)
  4603 00001790 29D2                    	sub	dx, dx ; 0
  4604 00001792 A3[EE6A]                	mov	[cluster_count], ax
  4605 00001795 8916[F06A]              	mov	[cluster_count+2], dx ; 0
  4606                                  
  4607 00001799 8D7E2B                  	lea	di, [bp+43] ; [BS_VolLab]
  4608 0000179C E8CBFB                  	call	write_volume_name
  4609 0000179F 8D7627                  	lea	si, [bp+39] ; [BS_VolID]
  4610 000017A2 E824FC                  	call	write_volume_serial
  4611 000017A5 E835FD                  	call	write_cluster_count	
  4612                                  
  4613 000017A8 E8A5FC                  	call	write_formatting_msg
  4614 000017AB B000                    	mov	al, 0
  4615 000017AD E801FD                  	call	write_format_percent_x
  4616                                  
  4617 000017B0 8B461C                  	mov	ax, [bp+1Ch]	; [BPB_HiddSec]
  4618 000017B3 8B561E                  	mov	dx, [bp+1Eh]	; [BPB_HiddSec+2]
  4619                                  
  4620 000017B6 0106[E66A]              	add	[data_start], ax
  4621 000017BA 1116[E86A]              	adc	[data_start+2], dx
  4622                                  
  4623                                  	; DX_AX = FAT12 Boot Sector address
  4624 000017BE BB[5B39]                	mov	bx, TRDOS_FAT12_hd_bs
  4625                                  	; ES:BX = Boot Sector Buffer
  4626 000017C1 E82304                  	call	write_hd_sector
  4627 000017C4 0F82FDFC                	jc	formatting_error
  4628 000017C8 E8A9FC                  	call	write_format_percent
  4629 000017CB 83C001                  	add	ax, 1
  4630 000017CE 83D200                  	adc	dx, 0
  4631                                  	; write remain part of reserved sectors
  4632 000017D1 8B4E0E                  	mov	cx, [bp+0Eh] ; [BPB_RsvdSecCnt]
  4633                                  	;sub	cx, 1
  4634                                  	;jna	short FAT12_f_3
  4635                                  	; 11/02/2019
  4636 000017D4 49                      	dec	cx
  4637 000017D5 7418                    	jz	short FAT12_f_3
  4638                                  FAT12_f_2:
  4639 000017D7 51                      	push	cx
  4640 000017D8 BB[E668]                	mov	bx, HDFORMAT_EMPTY_BUFF
  4641 000017DB E80904                  	call	write_hd_sector
  4642 000017DE 0F82E3FC                	jc	formatting_error
  4643 000017E2 E88FFC                  	call	write_format_percent
  4644 000017E5 83C001                  	add	ax, 1
  4645 000017E8 83D200                  	adc	dx, 0
  4646 000017EB 59                      	pop	cx
  4647 000017EC 49                      	dec	cx ; dec cl
  4648 000017ED 75E8                    	jnz	short FAT12_f_2
  4649                                  FAT12_f_3:
  4650                                  	; write FAT sectors
  4651 000017EF 8B0E[E66A]              	mov	cx, [data_start] ; lba/abs addr
  4652 000017F3 8B1E[E86A]              	mov	bx, [data_start+2] ; lba/abs addr
  4653                                  
  4654                                  	; 11/02/2019
  4655 000017F7 2B0E[F26A]              	sub	cx, [root_dir_secs]
  4656 000017FB 83DB00                  	sbb	bx, 0
  4657                                  
  4658 000017FE 53                      	push	bx
  4659 000017FF 51                      	push	cx
  4660 00001800 BB[E668]                	mov	bx, HDFORMAT_FATBUFFER
  4661                                  	; ES:BX = FAT Sector Buffer
  4662 00001803 8A4E15                  	mov	cl, [bp+15h] ; [BPB_Media]
  4663 00001806 B5FF                    	mov	ch, 0FFh
  4664 00001808 890F                    	mov	[bx], cx ; 0FFF8h
  4665 0000180A 886F02                  	mov	[bx+2], ch ; 0FFFFF8h
  4666                                  	;xor	cx, cx
  4667 0000180D E8D703                  	call	write_hd_sector
  4668 00001810 0F82B1FC                	jc	formatting_error
  4669 00001814 E85DFC                  	call	write_format_percent
  4670                                  	;mov	bx, HDFORMAT_FATBUFFER
  4671 00001817 B90000                  	mov	cx, 0
  4672 0000181A 890F                    	mov	[bx], cx
  4673 0000181C 884F02                  	mov	[bx+2], cl
  4674 0000181F EB0F                    	jmp	short FAT12_f_5
  4675                                  FAT12_f_4:	
  4676 00001821 53                      	push	bx
  4677 00001822 51                      	push	cx	
  4678 00001823 BB[E668]                	mov	bx, HDFORMAT_FATBUFFER
  4679 00001826 E8BE03                  	call	write_hd_sector
  4680 00001829 0F8298FC                	jc	formatting_error
  4681 0000182D E844FC                  	call	write_format_percent
  4682                                  FAT12_f_5:	
  4683 00001830 59                      	pop	cx
  4684 00001831 5B                      	pop	bx
  4685 00001832 83C001                  	add	ax, 1
  4686 00001835 83D200                  	adc	dx, 0
  4687 00001838 39DA                    	cmp	dx, bx
  4688 0000183A 72E5                    	jb	short FAT12_f_4
  4689 0000183C 39C8                    	cmp	ax, cx
  4690 0000183E 72E1                    	jb	short FAT12_f_4
  4691                                  
  4692                                  	; write	root directory sectors
  4693                                  	; as empty sectors
  4694 00001840 8B0E[F26A]              	mov	cx, [root_dir_secs]
  4695                                  FAT12_f_6:
  4696 00001844 51                      	push	cx
  4697 00001845 BB[E668]                	mov	bx, HDFORMAT_EMPTY_BUFF
  4698 00001848 E89C03                  	call	write_hd_sector
  4699 0000184B 0F8276FC                	jc	formatting_error
  4700 0000184F E822FC                  	call	write_format_percent
  4701 00001852 83C001                  	add	ax, 1
  4702 00001855 83D200                  	adc	dx, 0
  4703 00001858 59                      	pop	cx
  4704 00001859 49                      	dec	cx ; dec cl
  4705 0000185A 75E8                    	jnz	short FAT12_f_6
  4706                                  
  4707                                  	; write DATA sectors 
  4708                                  	; (after root directory sectors)
  4709 0000185C 8B0E[EA6A]              	mov	cx, [data_sectors]
  4710                                  	;mov	bx, [data_sectors+2]
  4711                                  	;inc	bx ; 11/02/2019
  4712                                  FAT12_f_7:	
  4713                                  	;push	bx
  4714 00001860 51                      	push	cx	
  4715 00001861 BB[D264]                	mov	bx, HDFORMAT_SECBUFFER
  4716 00001864 E88003                  	call	write_hd_sector
  4717 00001867 0F825AFC                	jc	formatting_error
  4718 0000186B E806FC                  	call	write_format_percent
  4719 0000186E 59                      	pop	cx
  4720                                  	;pop	bx
  4721 0000186F 83C001                  	add	ax, 1
  4722 00001872 83D200                  	adc	dx, 0
  4723 00001875 49                      	dec	cx
  4724 00001876 75E8                    	jnz	short FAT12_f_7
  4725                                  	;dec	bx
  4726                                  	;jnz	short FAT12_f_7
  4727                                  
  4728                                  	; If there are, format remain sectors which are
  4729                                  	; at beyond of data clusters, with zero bytes.
  4730                                  	
  4731 00001878 8B4E1C                  	mov	cx, [bp+1Ch]	; [BPB_HiddSec]
  4732 0000187B 8B5E1E                  	mov	bx, [bp+1Eh]	; [BPB_HiddSec+2]
  4733                                  
  4734 0000187E 034E13                  	add	cx, [bp+13h]	; [BPB_TotSec16]
  4735 00001881 83D300                  	adc	bx, 0
  4736 00001884 E9AFFA                  	jmp	FAT12_f_8
  4737                                  
  4738                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4739                                  ; SINGLIX FS FORMATTING
  4740                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4741                                  
  4742                                  	; 20/03/2021
  4743                                  	; 19/03/2021
  4744                                  SINGLIX_hd_format:
  4745                                  	; 06/01/2018
  4746                                  	; 05/01/2018
  4747                                  	; If Sectors/Track = 17, use CHS+LBA type boot sector
  4748 00001887 8B1E[6E3F]              	mov	bx, [sectors]
  4749 0000188B 83FB11                  	cmp	bx, 17
  4750 0000188E 7711                    	ja	short SINGLIX_fs1_f_1
  4751                                  SINGLIX_fs1_f_0:
  4752 00001890 BD[5B3B]                	mov	bp, TRDOS_TRFS1_chs_bs
  4753 00001893 887E2D                  	mov	[bp+45], bh ; 0 ; [bs_LBA_Ready] = 0
  4754 00001896 885E2E                  	mov	[bp+46], bl	; [bs_Disk_SecPerTrack]
  4755 00001899 A0[703F]                	mov	al, [heads]
  4756 0000189C 88462F                  	mov	[bp+47], al	; [bs_Disk_Heads]
  4757 0000189F EB15                    	jmp	short SINGLIX_fs1_f_3
  4758                                  SINGLIX_fs1_f_1:
  4759                                  	; Sectors per Track = 63
  4760                                  	; If disk capacity >= 63*16*1024 use LBA type boot sector
  4761 000018A1 8B0E[703F]              	mov	cx, [heads]
  4762 000018A5 A1[723F]                	mov	ax, [cylinders]
  4763 000018A8 F7E1                    	mul	cx
  4764 000018AA 21D2                    	and	dx, dx
  4765 000018AC 7505                    	jnz	short SINGLIX_fs1_f_2
  4766 000018AE 3D0040                  	cmp	ax, 16384
  4767 000018B1 72DD                    	jb	short SINGLIX_fs1_f_0
  4768                                  SINGLIX_fs1_f_2:	
  4769 000018B3 BD[5B3D]                	mov	bp, TRDOS_TRFS1_lba_bs
  4770                                  	;mov	byte [bp+45], 1 ; [bs_LBA_Ready] = 1
  4771                                  SINGLIX_fs1_f_3:	
  4772                                  	;mov	ax, [pp_Sectors]
  4773                                  	;mov	dx, [pp_Sectors+2]
  4774                                  	; 16/02/2019
  4775 000018B6 A1[9E6D]                	mov	ax, [ppn_Sectors]
  4776 000018B9 8B16[A06D]              	mov	dx, [ppn_Sectors+2]
  4777 000018BD 894610                  	mov	[bp+16], ax	; [bsVolumeSize]
  4778 000018C0 895612                  	mov	[bp+18], dx	; [bsVolumeSize+2]
  4779 000018C3 8B0E[6C6D]              	mov	cx, [pp_StartSector]
  4780 000018C7 8B1E[6E6D]              	mov	bx, [pp_StartSector+2]
  4781 000018CB 894E0C                  	mov	[bp+12], cx	; [bsBeginSector]
  4782 000018CE 895E0E                  	mov	[bp+14], bx	; [bsBeginSector+2]
  4783 000018D1 C6462C80                	mov	byte [bp+44], 80h ; [bsDriveNumber]  ; hd0
  4784                                  
  4785                                  	; Prepare MAT
  4786 000018D5 A3[4C6B]                	mov	[MAT_VolumeSize], ax ; Total Sectors of the FS
  4787 000018D8 8916[4E6B]              	mov	[MAT_VolumeSize+2], dx
  4788 000018DC 890E[506B]              	mov	[MAT_BeginSector], cx ; Beginning Sector of the FS
  4789 000018E0 891E[526B]              	mov	[MAT_BeginSector+2], bx
  4790                                  	;mov	cx, [bp+24]	; [bsMATLocation]
  4791                                  	;mov	bx, [bp+26]	; [bsMATLocation+2]
  4792                                  	;add	cx, 1
  4793                                  	;adc	bx, 0
  4794                                  	; Note: (as Default) MAT Address = 1, DAT Address = 2 
  4795 000018E4 B90200                  	mov	cx, 2
  4796                                  	;xor	bx, bx ; 0
  4797                                  	;mov	[bp+24], cx	; [bsMATLocation]
  4798                                  	;mov	[bp+26], bx	; [bsMATLocation+2]
  4799 000018E7 890E[546B]              	mov	[DAT_Address], cx
  4800                                  	;mov	[DAT_Address+2], bx
  4801                                  	; DX_AX = FS1 Volume Size
  4802 000018EB 83C007                  	add	ax, 7 ; 7 bits more (for round up)
  4803 000018EE 83D200                  	adc	dx, 0
  4804 000018F1 B90800                  	mov	cx, 8 ;  1 DAT byte == 8 sectors 
  4805 000018F4 E886F3                  	call	div32
  4806                                  	; DX_AX = DAT bytes
  4807 000018F7 B9FF01                  	mov	cx, 511
  4808 000018FA 01C8                    	add	ax, cx
  4809 000018FC 83D200                  	adc	dx, 0
  4810 000018FF 41                      	inc	cx ; 512
  4811 00001900 E87AF3                  	call	div32
  4812                                  	; DX_AX = DAT sectors (DX must be 0 for volume sizes < 128GB)
  4813 00001903 A3[586B]                	mov	[DAT_SectorCount], ax
  4814                                  	; 19/03/2021
  4815 00001906 8916[5A6B]              	mov	[DAT_SectorCount+2], dx
  4816                                  
  4817 0000190A 83C002                  	add	ax, 2  ; BS + MAT
  4818 0000190D 83D200                  	adc	dx, 0  ; 19/03/2021
  4819 00001910 89461C                  	mov	[bp+28], ax  ; [bsRootDirDT] ; RDT address (offset)
  4820 00001913 89561E                  	mov	[bp+30], dx ; 19/03/2021
  4821                                  
  4822                                  	; Free Sectors = Total Sectors - (BS+MAT+DATsects+RDT+4)	 
  4823 00001916 83C005                  	add	ax, 5 ; DATsects + (BS+MAT+RDT+4)
  4824                                  	; 19/03/2021
  4825 00001919 83D200                  	adc	dx, 0
  4826                                  	;mov	dx, ax ; ? ; 19/03/2021
  4827 0000191C 8B0E[4C6B]              	mov	cx, [MAT_VolumeSize]
  4828 00001920 8B1E[4E6B]              	mov	bx, [MAT_VolumeSize+2]
  4829 00001924 29C1                    	sub	cx, ax
  4830                                  	; 19/03/2021
  4831                                  	;sbb	bx, 0
  4832 00001926 19D3                    	sbb	bx, dx	
  4833                                  
  4834 00001928 890E[5C6B]              	mov	[MAT_FreeSectors], cx
  4835 0000192C 891E[5E6B]              	mov	[MAT_FreeSectors+2], bx
  4836 00001930 A3[606B]                	mov	[MAT_FirstFreeSector], ax
  4837                                  	;mov	word [MAT_FirstFreeSector+2], 0
  4838                                  	; 19/03/2021
  4839 00001933 8916[626B]              	mov	[MAT_FirstFreeSector+2], dx
  4840                                  	
  4841 00001937 BF[F86A]                	mov	di, fs_volume_name
  4842 0000193A E826FA                  	call	write_fs_volume_name
  4843 0000193D BE[386B]                	mov	si, fs_volume_serial
  4844 00001940 E886FA                  	call	write_volume_serial
  4845                                  
  4846                                  	; Modify FS volume name
  4847                                  	; (Convert 20h tail bytes to 0)
  4848 00001943 B94000                  	mov	cx, 64 
  4849 00001946 BE[F86A]                	mov	si, fs_volume_name
  4850 00001949 31DB                    	xor	bx, bx
  4851 0000194B B0FF                    	mov	al, 0FFh
  4852                                  modify_fs_vname_1:	
  4853 0000194D 88C4                    	mov	ah, al
  4854 0000194F AC                      	lodsb
  4855 00001950 3C20                    	cmp	al, 20h
  4856 00001952 7708                    	ja	short modify_fs_vname_2
  4857 00001954 80FC20                  	cmp	ah, 20h
  4858 00001957 7603                    	jna	short modify_fs_vname_2
  4859 00001959 89F3                    	mov	bx, si
  4860 0000195B 4B                      	dec	bx
  4861                                  modify_fs_vname_2:
  4862 0000195C E2EF                    	loop	modify_fs_vname_1		
  4863 0000195E 09DB                    	or	bx, bx
  4864 00001960 740B                    	jz	short modify_fs_vname_3
  4865 00001962 89DF                    	mov	di, bx
  4866 00001964 B9[386B]                	mov	cx, fs_volume_name+64
  4867 00001967 29D9                    	sub	cx, bx
  4868 00001969 30C0                    	xor	al, al
  4869 0000196B F3AA                    	rep	stosb 
  4870                                  
  4871                                  modify_fs_vname_3:
  4872 0000196D E8E0FA                  	call	write_formatting_msg
  4873 00001970 B000                    	mov	al, 0
  4874 00001972 E83CFB                  	call	write_format_percent_x
  4875                                  
  4876 00001975 8B460C                  	mov	ax, [bp+12]	; [bsBeginSector]
  4877 00001978 8B560E                  	mov	dx, [bp+14]	; [bsBeginSector+2]
  4878                                  
  4879                                  	; DX_AX = TRFS1 Boot Sector address
  4880 0000197B 89EB                    	mov	bx, bp
  4881                                  	; ES:BX = Boot Sector Buffer
  4882 0000197D E86702                  	call	write_hd_sector
  4883 00001980 0F8241FB                	jc	formatting_error
  4884                                  	
  4885 00001984 83C001                  	add	ax, 1
  4886 00001987 83D200                  	adc	dx, 0
  4887                                  
  4888                                  	; DX_AX = MAT (DAT header) sector address
  4889 0000198A BB[486B]                	mov	bx, FS_MAT_Buffer
  4890                                  	; 16/02/2019
  4891 0000198D C7074D41                	mov	word [bx],'MA'
  4892 00001991 C6470254                	mov	byte [bx+2],'T'
  4893 00001995 E84F02                  	call	write_hd_sector
  4894 00001998 0F8229FB                	jc	formatting_error
  4895 0000199C E819FB                  	call	write_fs_format_percent
  4896                                  
  4897                                  	; Calculate DAT bits 
  4898                                  	; NOTE: 4096 bits per DAT sector
  4899 0000199F A1[606B]                	mov	ax, [MAT_FirstFreeSector]
  4900                                  	; 19/03/2021
  4901                                  	;xor	dx, dx
  4902 000019A2 8B16[626B]              	mov	dx, [MAT_FirstFreeSector+2]
  4903 000019A6 52                      	push	dx
  4904 000019A7 50                      	push	ax
  4905 000019A8 B90010                  	mov	cx, 4096
  4906 000019AB E8CFF2                  	call	div32
  4907 000019AE 891E[3C6B]              	mov	[DAT_FFBit], bx
  4908 000019B2 A3[3E6B]                	mov	[DAT_FFSector], ax
  4909                                  	; 19/03/2021
  4910 000019B5 8916[406B]              	mov	[DAT_FFSector+2], dx
  4911 000019B9 58                      	pop	ax
  4912 000019BA 5A                      	pop	dx
  4913 000019BB 83E801                  	sub	ax, 1
  4914 000019BE 83DA00                  	sbb	dx, 0
  4915 000019C1 0306[5C6B]              	add	ax, [MAT_FreeSectors]
  4916 000019C5 1316[5E6B]              	adc	dx, [MAT_FreeSectors+2]
  4917 000019C9 E8B1F2                  	call	div32
  4918 000019CC 891E[426B]              	mov	[DAT_LFBit], bx
  4919 000019D0 A3[446B]                	mov	[DAT_LFSector], ax
  4920                                  	; 19/03/2021
  4921 000019D3 8916[466B]              	mov	[DAT_LFSector+2], dx
  4922                                  	;
  4923 000019D7 31F6                    	xor	si, si ; 0
  4924                                  	; 19/03/2021
  4925 000019D9 8936[4671]              	mov	[tempword], si ; 0
  4926                                  SINGLIX_fs1_f_4:
  4927                                  	; calculate free bits for current DAT sector
  4928                                  	;			(to be written)
  4929 000019DD BF[646B]                	mov	di, FS_DAT_Buffer
  4930                                  
  4931                                  	; 19/03/2021
  4932 000019E0 A1[4671]                	mov	ax, [tempword]
  4933 000019E3 3B06[406B]              	cmp	ax, [DAT_FFSector+2]
  4934 000019E7 7260                    	jb	short SINGLIX_fs1_f_9
  4935 000019E9 7708                    	ja	short SINGLIX_fs1_f_13
  4936                                  
  4937 000019EB 3B36[3E6B]              	cmp	si, [DAT_FFSector]
  4938 000019EF 743A                    	je	short SINGLIX_fs1_f_7
  4939 000019F1 7256                    	jb	short SINGLIX_fs1_f_9
  4940                                  SINGLIX_fs1_f_13:
  4941                                  	; 19/03/2021
  4942 000019F3 3B06[466B]              	cmp	ax, [DAT_LFSector+2]
  4943 000019F7 722D                    	jb	short SINGLIX_fs1_f_6
  4944 000019F9 774E                    	ja	short SINGLIX_fs1_f_9
  4945                                  
  4946 000019FB 3B36[446B]              	cmp	si, [DAT_LFSector]
  4947 000019FF 7225                    	jb	short SINGLIX_fs1_f_6
  4948 00001A01 7746                    	ja	short SINGLIX_fs1_f_9
  4949                                  
  4950                                  	;mov	bx, [DAT_LFBit]
  4951                                  	;;mov	al, 0FFh
  4952                                  	;mov	ah, bl
  4953                                  	;shr	bx, 3 ; bit count to byte count
  4954                                  	;jz	short SINGLIX_fs1_f_5
  4955                                  	; 20/03/2021
  4956 00001A03 8B0E[426B]              	mov	cx, [DAT_LFBit]
  4957 00001A07 88CC                    	mov	ah, cl
  4958 00001A09 C1E903                   	shr	cx, 3 ; bit count to byte count
  4959 00001A0C 7404                    	jz	short SINGLIX_fs1_f_5
  4960                                  	;Example:
  4961                                  	;last free sector = 47 -> byte 5, bit 7
  4962                                  	;last free sector = 48 -> byte 6, bit 0
  4963                                  	; (also previous sectors are free sectors)
  4964 00001A0E B0FF                    	mov	al, 0FFh ; 20/03/2021
  4965                                  	;mov	cx, bx
  4966 00001A10 F3AA                    	rep	stosb
  4967                                  	; 20/03/2021
  4968                                  	;mov	di, FS_DAT_Buffer
  4969                                  	;add	di, bx
  4970                                  SINGLIX_fs1_f_5:
  4971 00001A12 80E407                  	and	ah, 7
  4972                                  	;mov	cl, ah
  4973                                  	;shl	al, cl
  4974                                  	;not	al
  4975                                  	; 20/03/2021
  4976 00001A15 30C0                    	xor	al, al
  4977                                  SINGLIX_fs1_f_15:
  4978                                  	; 20/03/2021 
  4979                                  	; 0 -> 00000001b (last free bit is bit 0)
  4980                                  	; 1 -> 00000011b (last free bit is bit 1)
  4981                                  	; 7 -> 11111111b (last free bit is bit 7)
  4982 00001A17 0C01                    	or	al, 1
  4983 00001A19 08E4                    	or	ah, ah
  4984 00001A1B 7406                    	jz	short SINGLIX_fs1_f_16
  4985 00001A1D D0E0                    	shl	al, 1
  4986 00001A1F FECC                    	dec	ah
  4987 00001A21 EBF4                    	jmp	short SINGLIX_fs1_f_15
  4988                                  SINGLIX_fs1_f_16:
  4989 00001A23 AA                      	stosb
  4990                                  	;mov	cx, 511
  4991                                  	;sub	cx, bx
  4992                                  	;jna	short SINGLIX_fs1_f_9
  4993                                  	;mov	al, 0 ; out of volume bits (=0)
  4994                                  	;rep	stosb
  4995 00001A24 EB23                    	jmp	short SINGLIX_fs1_f_9
  4996                                  SINGLIX_fs1_f_6:
  4997 00001A26 B90002                  	mov	cx, 512
  4998 00001A29 EB1A                    	jmp	short SINGLIX_fs1_f_8
  4999                                  SINGLIX_fs1_f_7:
  5000                                  	; 20/03/2021
  5001                                  	;Example:
  5002                                  	;first free sector = 23 -> byte 2, bit 7
  5003                                  	;first free sector = 24 -> byte 3, bit 0
  5004                                  	; (previous sectors are allocated sectors)
  5005 00001A2B 8B1E[3C6B]              	mov	bx, [DAT_FFBit]
  5006 00001A2F 88D9                    	mov	cl, bl
  5007 00001A31 80E107                  	and	cl, 7
  5008 00001A34 C1EB03                  	shr	bx, 3 ; from bits to bytes
  5009 00001A37 01DF                    	add	di, bx
  5010 00001A39 B0FF                    	mov	al, 0FFh
  5011 00001A3B D2E0                    	shl	al, cl
  5012 00001A3D AA                      	stosb
  5013 00001A3E B9FF01                  	mov	cx, 511
  5014 00001A41 29D9                    	sub	cx, bx
  5015 00001A43 7604                    	jna	short SINGLIX_fs1_f_9
  5016                                  SINGLIX_fs1_f_8:
  5017 00001A45 B0FF                    	mov	al, 0FFh ; Free sector bits (=1)
  5018 00001A47 F3AA                    	rep	stosb
  5019                                  SINGLIX_fs1_f_9:
  5020 00001A49 A1[506B]                	mov	ax, [MAT_BeginSector]
  5021 00001A4C 8B16[526B]              	mov	dx, [MAT_BeginSector+2]
  5022                                  	;add	ax, [DAT_Address] ; = 2
  5023                                  	;adc	dx, [DAT_Address+2]
  5024 00001A50 83C002                  	add	ax, 2
  5025 00001A53 83D200                  	adc	dx, 0
  5026 00001A56 01F0                    	add	ax, si
  5027 00001A58 83D200                  	adc	dx, 0
  5028                                  	; Write DAT sector(s)
  5029                                  	; DX_AX = Disk Allocation Table sector address
  5030 00001A5B BB[646B]                	mov	bx, FS_DAT_Buffer
  5031 00001A5E E88601                  	call	write_hd_sector
  5032 00001A61 0F8260FA                	jc	formatting_error
  5033 00001A65 E850FA                  	call	write_fs_format_percent
  5034                                  	; Clear DAT buffer again (for next stage)
  5035 00001A68 B90001                  	mov	cx, 256
  5036 00001A6B BF[646B]                	mov	di, FS_DAT_Buffer
  5037 00001A6E 29C0                    	sub	ax, ax
  5038 00001A70 F3AB                    	rep	stosw
  5039                                  
  5040 00001A72 46                      	inc	si
  5041                                  	; 19/03/2021
  5042 00001A73 7504                    	jnz	short SINGLIX_fs1_f_14
  5043                                  
  5044                                  	; 19/03/2021
  5045 00001A75 FF06[4671]              	inc	word [tempword]
  5046                                  SINGLIX_fs1_f_14:
  5047 00001A79 A1[4671]                	mov	ax, [tempword]
  5048 00001A7C 3B06[5A6B]              	cmp	ax, [DAT_SectorCount+2]
  5049 00001A80 0F8259FF                	jb	SINGLIX_fs1_f_4
  5050                                  
  5051 00001A84 3B36[586B]              	cmp	si, [DAT_SectorCount]
  5052                                  	;jna	SINGLIX_fs1_f_4
  5053                                  	; 19/03/2021 (bugfix)
  5054 00001A88 0F8251FF                	jb	SINGLIX_fs1_f_4
  5055                                  
  5056                                  	; ;;;
  5057                                  	
  5058                                  	; DAT sectors has been written..
  5059                                  	; Now, Root Directory Description Table is in order
  5060                                  
  5061 00001A8C BF[646B]                	mov	di, FS_RDT_Buffer
  5062 00001A8F B84444                  	mov	ax, 'DD' 
  5063 00001A92 AB                      	stosw
  5064 00001A93 30E4                    	xor	ah, ah
  5065 00001A95 B054                    	mov	al, 'T'
  5066 00001A97 AB                      	stosw
  5067 00001A98 B80002                  	mov	ax, 512 ; Sector size (Bytes per sector)	
  5068 00001A9B AB                      	stosw
  5069 00001A9C 31C0                    	xor	ax, ax ; RDT sequence number (= 0, section 1)
  5070 00001A9E AB                      	stosw	
  5071                                  	; RDT address
  5072 00001A9F A1[586B]                	mov	ax, [DAT_SectorCount]
  5073 00001AA2 8B16[5A6B]              	mov	dx, [DAT_SectorCount+2]
  5074 00001AA6 83C002                  	add	ax, 2 ; BS + MAT
  5075 00001AA9 83D200                  	adc	dx, 0
  5076 00001AAC AB                      	stosw
  5077 00001AAD 89D0                    	mov	ax, dx
  5078 00001AAF AB                      	stosw
  5079 00001AB0 29C0                    	sub	ax, ax ; Next RDT number
  5080 00001AB2 AB                      	stosw
  5081 00001AB3 AB                      	stosw
  5082                                  	;mov	ax, 4 ; Sector count of this section	
  5083                                  	;	      ; (4*512)/4 = 512 root dir entries
  5084                                  	; 20/03/2021
  5085 00001AB4 B004                    	mov	al, 4
  5086 00001AB6 AB                      	stosw
  5087 00001AB7 30C0                    	xor	al, al
  5088 00001AB9 AB                      	stosw
  5089                                  	; Volume beginning sector
  5090 00001ABA 8B460C                  	mov	ax, [bp+12]	; [bsBeginSector]
  5091 00001ABD 8B560E                  	mov	dx, [bp+14]	; [bsBeginSector+2]
  5092 00001AC0 AB                      	stosw
  5093 00001AC1 89D0                    	mov	ax, dx
  5094 00001AC3 AB                      	stosw
  5095 00001AC4 31C0                    	xor	ax, ax
  5096 00001AC6 48                      	dec	ax ; 0FFFFh
  5097                                  	; Parent Dir Serial (= FFFFFFFFh for root dir)
  5098 00001AC7 AB                      	stosw
  5099 00001AC8 AB                      	stosw
  5100                                  
  5101                                  set_fs_volume_serial_number:
  5102 00001AC9 BE[386B]                	mov	si, fs_volume_serial
  5103 00001ACC A5                      	movsw
  5104 00001ACD A5                      	movsw
  5105                                  
  5106 00001ACE 29C0                    	sub	ax, ax
  5107                                  	;stosb	; sub directory level = 0
  5108                                  	;stosb	; 0, reserved
  5109 00001AD0 AB                      	stosw
  5110 00001AD1 B004                    	mov	al, 00000100b ;  (DOS) System attribute
  5111 00001AD3 AA                      	stosb	; (DOS) Basic attributes
  5112 00001AD4 28C0                    	sub	al, al ; Extended attributes (0 for TRDOS 386)
  5113 00001AD6 AA                      	stosb
  5114                                  	; 20/03/2021
  5115                                  	;sub	ax, ax ; reserved (8) bytes for TR-MULTIX
  5116 00001AD7 AB                      	stosw
  5117 00001AD8 AB                      	stosw
  5118 00001AD9 AB                      	stosw
  5119 00001ADA AB                      	stosw
  5120 00001ADB B85254                  	mov	ax, 'RT' ; TRFS Root directory signature
  5121 00001ADE AB                      	stosw
  5122 00001ADF 31C0                    	xor	ax, ax ; Country (language, date, text format)
  5123                                  		       ; (0 = Default, 1 = USA, 90 = Turkiye)
  5124                                  	;stosb
  5125                                  	;stosb	; Time Zone (0 = GMT = default ; -11 to +12)
  5126 00001AE1 AB                      	stosw
  5127                                  
  5128 00001AE2 89FE                    	mov	si, di
  5129                                  	; get the date (from RTC)
  5130 00001AE4 B404                    	mov	ah, 4
  5131 00001AE6 CD1A                    	int	1Ah
  5132                                  	; Creating Date (of root directory)
  5133 00001AE8 86E9                    	xchg	ch, cl ; 07/01/2018
  5134 00001AEA 89C8                    	mov	ax, cx ; cl = century (BCD), ch = year (BCD)
  5135 00001AEC AB                      	stosw
  5136 00001AED 88F0                    	mov	al, dh  ; month (BCD)
  5137 00001AEF AA                      	stosb
  5138 00001AF0 88D0                    	mov	al, dl  ; day (BCD)
  5139 00001AF2 AA                      	stosb
  5140                                  	; get the time (from RTC)
  5141 00001AF3 B402                    	mov	ah, 2
  5142 00001AF5 CD1A                    	int	1Ah
  5143                                  	; Creating Time (of root directory)
  5144 00001AF7 86CD                    	xchg	cl, ch ; ch = hour (BCD), cl = minute (BSD)
  5145 00001AF9 89C8                    	mov	ax, cx ; al = hour, ah = minute
  5146 00001AFB AB                      	stosw
  5147 00001AFC 88F0                    	mov	al, dh ; seconds (BCD)
  5148 00001AFE AA                      	stosb
  5149 00001AFF 88D0                    	mov	al, dl ; daylight savings time option 
  5150 00001B01 AA                      	stosb
  5151                                  	; Set Last Modification Date&Time
  5152 00001B02 B90400                  	mov	cx, 4
  5153 00001B05 F3A5                    	rep	movsw ; copy creating date&time values to
  5154                                  		; last modification date time values	
  5155                                  		; (last modif date&time = creating date&time)
  5156                                  
  5157                                  set_fs_volume_name:
  5158 00001B07 BE[F86A]                	mov	si, fs_volume_name
  5159 00001B0A B120                    	mov	cl, 32 
  5160 00001B0C F3A5                    	rep	movsw
  5161                                  
  5162                                  	; Fill remain bytes (of this RDT) with zero
  5163 00001B0E B9C000                  	mov	cx, (128+256)/2
  5164 00001B11 31C0                    	xor	ax, ax
  5165 00001B13 F3AB                    	rep	stosw
  5166                                  
  5167                                  	; RDT is ready here...
  5168                                  
  5169 00001B15 8B461C                  	mov	ax, [bp+28]	; [bsRootDirDT]
  5170 00001B18 8B561E                  	mov	dx, [bp+30]	; [bsRootDirDT+2]
  5171                                  	; 20/03/2021
  5172                                  	;xor	dx, dx
  5173 00001B1B 03460C                  	add	ax, [bp+12]	; [bsBeginSector]
  5174 00001B1E 13560E                  	adc	dx, [bp+14]	; [bsBeginSector+2]
  5175                                  
  5176                                  	; Write RDT sector
  5177                                  	; DX_AX = Root Directory Description Table address
  5178 00001B21 BB[646B]                	mov	bx, FS_RDT_Buffer
  5179 00001B24 E8C000                  	call	write_hd_sector
  5180 00001B27 0F829AF9                	jc	formatting_error
  5181 00001B2B E88AF9                  	call	write_fs_format_percent
  5182                                  
  5183 00001B2E 83C001                  	add	ax, 1
  5184 00001B31 83D200                  	adc	dx, 0
  5185                                  
  5186                                  	; write root directory data sectors
  5187 00001B34 B90400                  	mov	cx, 4
  5188                                  
  5189                                  SINGLIX_fs1_f_10:
  5190 00001B37 51                      	push	cx
  5191                                  	; Write root directory sector(s)
  5192                                  	; DX_AX = Root Directory Sector address
  5193 00001B38 BB[E668]                	mov	bx, HDFORMAT_EMPTY_BUFF
  5194 00001B3B E8A900                  	call	write_hd_sector
  5195 00001B3E 0F8283F9                	jc	formatting_error
  5196 00001B42 E873F9                  	call	write_fs_format_percent
  5197 00001B45 83C001                  	add	ax, 1
  5198 00001B48 83D200                  	adc	dx, 0
  5199 00001B4B 59                      	pop	cx
  5200 00001B4C FEC9                    	dec	cl
  5201 00001B4E 75E7                    	jnz	short SINGLIX_fs1_f_10
  5202                                  
  5203                                  	; Fill remain sectors with 'F6h' bytes
  5204 00001B50 8B4E10                  	mov	cx, [bp+16]	; [bsVolumeSize]
  5205 00001B53 8B5E12                  	mov	bx, [bp+18]	; [bsVolumeSize+2]
  5206 00001B56 034E0C                  	add	cx, [bp+12]	; [bsBeginSector]
  5207 00001B59 135E0E                  	adc	bx, [bp+14]	; [bsBeginSector+2]
  5208                                  
  5209                                  	; write DATA sectors 
  5210                                  	; (after root directory sectors)
  5211                                  SINGLIX_fs1_f_11:
  5212 00001B5C 53                      	push	bx
  5213 00001B5D 51                      	push	cx
  5214 00001B5E BB[D264]                	mov	bx, HDFORMAT_SECBUFFER
  5215 00001B61 E88300                  	call	write_hd_sector
  5216 00001B64 0F825DF9                	jc	formatting_error
  5217 00001B68 E809F9                  	call	write_format_percent
  5218 00001B6B 59                      	pop	cx
  5219 00001B6C 5B                      	pop	bx
  5220 00001B6D 83C001                  	add	ax, 1
  5221 00001B70 83D200                  	adc	dx, 0
  5222 00001B73 39DA                    	cmp	dx, bx
  5223 00001B75 72E5                    	jb	short SINGLIX_fs1_f_11
  5224 00001B77 0F87DDF7                	ja	SINGLIX_fs1_f_12
  5225 00001B7B 39C8                    	cmp	ax, cx
  5226 00001B7D 72DD                    	jb	short SINGLIX_fs1_f_11
  5227 00001B7F E9D6F7                  	jmp	SINGLIX_fs1_f_12	
  5228                                  
  5229                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5230                                  ; print messages
  5231                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5232                                  
  5233                                  print_msg:
  5234                                  
  5235                                  print_msg_LOOP:
  5236 00001B82 AC                      	lodsb                           ; Load byte at DS:SI to AL
  5237 00001B83 20C0                    	and     al, al            
  5238 00001B85 7409                    	jz      short print_msg_OK       
  5239 00001B87 B40E                    	mov	ah, 0Eh			
  5240 00001B89 BB0700                  	mov     bx, 07h             
  5241 00001B8C CD10                    	int	10h			; BIOS Service func ( ah ) = 0Eh
  5242                                  					; Write char as TTY
  5243                                  					; AL-char BH-page BL-color
  5244 00001B8E EBF2                    	jmp     short print_msg_LOOP           
  5245                                  
  5246                                  print_msg_OK:
  5247 00001B90 C3                      	retn
  5248                                  
  5249                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5250                                  ; reading a block (sector) on hard disk
  5251                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5252                                  ; 17/10/2020
  5253                                  
  5254                                  read_hd_sector:
  5255                                  
  5256                                  	; INPUT -> DX_AX = Logical Block Address
  5257                                  	; 	   ES:BX = Sector Buffer
  5258                                  	; OUTPUT ->
  5259                                  	;  cf = 0 -> DX_AX = Logical Block Adress
  5260                                  	;	     ES:BX = Sector Buffer
  5261                                  	;  cf = 1 -> AH = Error Number
  5262                                  
  5263 00001B91 3B16[E068]              	cmp	dx, [chs_limit+2]
  5264 00001B95 770F                    	ja	short read_lba_sector
  5265 00001B97 7206                    	jb	short read_chs_sector
  5266 00001B99 3B06[DE68]              	cmp	ax, [chs_limit]
  5267 00001B9D 7707                    	ja	short read_lba_sector
  5268                                  	;jmp	short read_chs_sector
  5269                                  
  5270                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5271                                  ; reading a block (sector) by using CHS read (ROMBIOS) function
  5272                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5273                                  ; 17/10/2020
  5274                                  
  5275                                  read_chs_sector:
  5276                                  	; hdformat.s (25/09/2020)
  5277 00001B9F C606[D868]02            	mov	byte [rw], 2 ; read
  5278 00001BA4 EB54                    	jmp	short chs_rw
  5279                                  
  5280                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5281                                  ; reading a block (sector) by using LBA read (ROMBIOS) function
  5282                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5283                                  ; 17/10/2020
  5284                                  
  5285                                  read_lba_sector:
  5286                                  	; hdformat.s (25/09/2020)
  5287 00001BA6 C606[D868]42            	mov	byte [rw], 42h
  5288 00001BAB EB05                    	jmp	short lba_rw
  5289                                  
  5290                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5291                                  ; writing a block (sector) by using LBA write (ROMBIOS) function
  5292                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5293                                  ; 17/10/2020
  5294                                  
  5295                                  	; 18/10/2020 
  5296                                  write_lba_sector:
  5297                                  	; hdformat.s (25/09/2020)
  5298 00001BAD C606[D868]43            	mov	byte [rw], 43h
  5299                                  	;jmp	short lba_rw
  5300                                  lba_rw:
  5301                                  	;mov	di, 5
  5302                                  	; 18/10/2020
  5303 00001BB2 C606[D968]05            	mov	byte [rcnt], 5  ; Retry count
  5304                                  lba_rw_1:
  5305                                  	;pusha			; db 60h
  5306 00001BB7 60                      	db	60h
  5307                                  	;push 	0		; db 6Ah, 00h
  5308 00001BB8 6A00                    	db	6Ah, 0
  5309                                  	;push	0		; db 6Ah, 00h
  5310 00001BBA 6A00                    	db	6Ah, 0
  5311 00001BBC 52                      	push    dx
  5312 00001BBD 50                      	push    ax
  5313 00001BBE 06                      	push    es
  5314 00001BBF 53                      	push    bx
  5315                                  	;push	1		; db 6Ah, 01h
  5316 00001BC0 6A01                    	db	6Ah, 01h                     
  5317                                  	;push	10h		; db 6Ah, 10h
  5318 00001BC2 6A10                    	db	6Ah, 10h
  5319                                  
  5320 00001BC4 89E6                    	mov     si, sp
  5321 00001BC6 8A16[D668]              	mov     dl, [DrvNum]
  5322 00001BCA 30C0                    	xor	al, al	; verify off 
  5323                                  lba_rw_2:
  5324 00001BCC 8A26[D868]              	mov     ah, [rw] ; 42h = LBA read, 43h = LBA write
  5325                                  	;xor	al, al	; verify off 
  5326 00001BD0 CD13                    	int     13h
  5327                                  
  5328                                  	;mov	[error], ah
  5329 00001BD2 7310                    	jnc     short lba_rw_3
  5330                                  
  5331                                  	;dec	di 
  5332                                  	; 18/10/2020
  5333 00001BD4 FE0E[D968]              	dec	byte [rcnt]                 
  5334 00001BD8 740A                    	jz	short lba_rw_3 
  5335                                          
  5336 00001BDA 30E4                    	xor	ah, ah                   
  5337                                  	;mov	dl, [DrvNum]
  5338 00001BDC CD13                    	int	13h	; BIOS Service func (ah) = 0
  5339                                  			; Reset disk system
  5340                                  
  5341                                  	;mov	word [si+2], 1 ; set r/w count to 1 again
  5342 00001BDE C6440201                	mov	byte [si+2], 1
  5343                                  
  5344 00001BE2 EBE8                    	jmp	short lba_rw_2
  5345                                  
  5346                                  lba_rw_3:
  5347                                  	;popa
  5348 00001BE4 61                      	db	61h
  5349                                  	;popa
  5350 00001BE5 61                      	db	61h
  5351 00001BE6 C3                      	retn
  5352                                  
  5353                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5354                                  ; writing a block (sector) on hard disk
  5355                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5356                                  ; 17/10/2020
  5357                                  
  5358                                  write_hd_sector:
  5359                                  
  5360                                  	; INPUT -> DX_AX = Logical Block Address
  5361                                  	; 	   ES:BX = Sector Buffer
  5362                                  	; OUTPUT ->
  5363                                  	;  cf = 0 -> DX_AX = Logical Block Adress
  5364                                  	;	     ES:BX = Sector Buffer
  5365                                  	;  cf = 1 -> AH = Error Number
  5366                                  
  5367 00001BE7 3B16[E068]              	cmp	dx, [chs_limit+2]
  5368 00001BEB 77C0                    	ja	short write_lba_sector
  5369 00001BED 7206                    	jb	short write_chs_sector
  5370 00001BEF 3B06[DE68]              	cmp	ax, [chs_limit]
  5371 00001BF3 77B8                    	ja	short write_lba_sector
  5372                                  	;jmp	short write_chs_sector
  5373                                  
  5374                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5375                                  ; writing a block (sector) by using CHS write (ROMBIOS) function
  5376                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5377                                  ; 17/10/2020
  5378                                  
  5379                                  	; 18/10/2020
  5380                                  write_chs_sector:
  5381                                  	; hdformat.s (25/09/2020)
  5382 00001BF5 C606[D868]03            	mov	byte [rw], 3 ; write
  5383                                  	;jmp	short chs_rw
  5384                                  chs_rw:
  5385 00001BFA 56                      	push	si
  5386 00001BFB 51                              push	cx        
  5387                                  chs_rw_0:
  5388                                  	;mov	di, 5
  5389                                  	; 18/10/2020
  5390 00001BFC C606[D968]05            	mov	byte [rcnt], 5  ; Retry count                    
  5391                                  chs_rw_1:               
  5392 00001C01 52                      	push	dx	; Linear sector #
  5393 00001C02 50                      	push	ax	; DX_AX = Linear address (sectors)
  5394 00001C03 8B0E[6E3F]              	mov	cx, [sectors]
  5395 00001C07 53                      	push	bx
  5396                                  
  5397 00001C08 E872F0                  	call    div32	; 32 bit divide
  5398                                  
  5399 00001C0B 89D9                    	mov	cx, bx	; Sector (zero based)
  5400 00001C0D 41                      	inc	cx	; To make it 1 based
  5401 00001C0E 51                      	push	cx
  5402 00001C0F 8B0E[703F]              	mov     cx, [heads]
  5403 00001C13 E867F0                  	call	div32	; Convert track to head & cyl
  5404 00001C16 88DE                    	mov	dh, bl	; BX = Head (max. FFh)
  5405 00001C18 59                      	pop	cx	; AX=Cyl, DH=Head, CX=Sector
  5406 00001C19 5B                      	pop     bx	; ES:BX = Buffer
  5407                                  
  5408 00001C1A 8A16[D668]              	mov	dl, [DrvNum]
  5409 00001C1E 88C5                    	mov	ch, al                   
  5410 00001C20 D0CC                    	ror	ah, 1	; Rotate right
  5411 00001C22 D0CC                    	ror	ah, 1                   
  5412 00001C24 08E1                    	or	cl, ah                   
  5413                                  chs_rw_2:
  5414 00001C26 8A26[D868]              	mov	ah, [rw] ; 02h = read, 03h = write
  5415 00001C2A B001                    	mov	al, 01h
  5416 00001C2C CD13                    	int	13h	; BIOS Service func (ah) = 2/3
  5417                                  			; Read/Write disk sectors
  5418                                  			; AL-sec num CH-track CL-sec
  5419                                  			; DH-head DL-drive ES:BX-buffer
  5420                                  			; CF-flag AH-status AL-sectors written/read
  5421                                  			; If CF = 1 then AH = Error code (>0) 
  5422                                          
  5423 00001C2E 730C                    	jnc     short chs_rw_3
  5424                                  	;dec	di                 
  5425 00001C30 FE0E[D968]              	dec	byte [rcnt] ; 18/10/2020
  5426 00001C34 7406                    	jz	short chs_rw_3 
  5427                                          
  5428 00001C36 30E4                    	xor	ah, ah                   
  5429                                  	;mov	dl, [DrvNum]
  5430 00001C38 CD13                    	int	13h	; BIOS Service func (ah) = 0
  5431                                  			; Reset disk system
  5432 00001C3A EBEA                    	jmp	short chs_rw_2
  5433                                  
  5434                                  chs_rw_3:
  5435 00001C3C 58                      	pop	ax
  5436 00001C3D 5A                      	pop	dx
  5437 00001C3E 59                      	pop	cx
  5438 00001C3F 5E                      	pop	si	
  5439 00001C40 C3                      	retn
  5440                                  	
  5441                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5442                                  ; convert byte to decimal number
  5443                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5444                                  
  5445                                  bin_to_decimal:
  5446                                  	; INPUT: DS:SI = Target location
  5447                                  	;        DX_AX = Binary Number (Integer)
  5448                                  	; OUTPUT: Decimal char at DS:SI
  5449                                  	; 	 SI decremented after every division
  5450                                  	; 	 till AX<10.
  5451                                  	; CX, DX, BX will be changed.
  5452                                  	;
  5453 00001C41 B90A00                  	mov	cx, 10
  5454                                  btd_0:
  5455                                  	; DX_AX = Dividend
  5456                                  	; CX = Divisor
  5457 00001C44 E836F0                  	call	div32
  5458                                  	; DX_AX = Quotient
  5459                                  	; BX = remainder
  5460 00001C47 80C330                  	add	bl, '0'
  5461 00001C4A 881C                    	mov	[si], bl
  5462 00001C4C 21D2                    	and	dx, dx
  5463 00001C4E 7403                    	jz	short btd_2
  5464                                  btd_1:
  5465 00001C50 4E                      	dec	si
  5466 00001C51 EBF1                    	jmp	short btd_0
  5467                                  btd_2:
  5468 00001C53 09C0                    	or	ax, ax
  5469 00001C55 75F9                    	jnz	short btd_1
  5470                                  
  5471 00001C57 C3                      	retn
  5472                                  
  5473                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5474                                  ; convert byte to hexadecimal number
  5475                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5476                                  
  5477                                  byte_to_hex: ; 04/02/2019
  5478                                  bin_to_hex:
  5479                                  	; INPUT ->
  5480                                  	; 	AL = byte (binary number)
  5481                                  	; OUTPUT ->
  5482                                  	;	AX = hexadecimal string
  5483                                  	;
  5484 00001C58 53                      	push	bx
  5485 00001C59 31DB                    	xor	bx, bx
  5486 00001C5B 88C3                    	mov	bl, al
  5487 00001C5D C0EB04                  	shr	bl, 4
  5488 00001C60 8A9F[5C3F]              	mov	bl, [bx+hexchrs] 	 	
  5489 00001C64 86D8                    	xchg	bl, al
  5490 00001C66 80E30F                  	and	bl, 0Fh
  5491 00001C69 8AA7[5C3F]              	mov	ah, [bx+hexchrs] 
  5492 00001C6D 5B                      	pop	bx	
  5493 00001C6E C3                      	retn
  5494                                  
  5495                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5496                                  ; read & write characters
  5497                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5498                                  
  5499                                  rw_char:
  5500                                  	; OUTPUT -> DS:SI = Entered String (ASCIIZ)
  5501 00001C6F BE[BC54]                	mov     si, StrVolumeName
  5502 00001C72 BB0700                  	mov     bx, 7
  5503 00001C75 B403                    	mov     ah, 3
  5504 00001C77 CD10                    	int     10h
  5505 00001C79 8916[A354]              	mov     [Cursor_Pos], dx
  5506                                  read_next_char:
  5507 00001C7D 30E4                    	xor     ah, ah
  5508 00001C7F CD16                    	int     16h
  5509 00001C81 20C0                    	and     al, al
  5510 00001C83 7439                    	jz      short loc_arrow    
  5511 00001C85 3CE0                    	cmp     al, 0E0h          
  5512 00001C87 7435                    	je      short loc_arrow
  5513 00001C89 3C08                    	cmp     al, 8
  5514 00001C8B 753D                    	jne     short char_return
  5515                                  loc_back:
  5516 00001C8D B403                    	mov     ah, 3
  5517 00001C8F CD10                    	int     10h
  5518 00001C91 3A16[A354]              	cmp     dl, byte [Cursor_Pos]
  5519 00001C95 761F                    	jna     short loc_beep
  5520                                  prev_column:
  5521 00001C97 FECA                    	dec     dl
  5522                                  set_cursor_pos:
  5523 00001C99 B402                    	mov     ah, 2
  5524 00001C9B CD10                    	int     10h
  5525 00001C9D 88D3                    	mov     bl, dl
  5526 00001C9F 2A1E[A354]              	sub     bl, byte [Cursor_Pos] 
  5527 00001CA3 B90100                  	mov     cx, 1
  5528 00001CA6 B409                    	mov     ah, 9
  5529 00001CA8 B020                    	mov     al, 20h
  5530 00001CAA 8800                    	mov     [si+bx], al
  5531                                  loc_write_it:
  5532 00001CAC B307                    	mov     bl, 7
  5533 00001CAE CD10                    	int     10h
  5534 00001CB0 8B16[A354]              	mov     dx, [Cursor_Pos]
  5535 00001CB4 EBC7                    	jmp     short read_next_char
  5536                                  loc_beep:
  5537 00001CB6 B40E                    	mov     ah, 0Eh
  5538 00001CB8 B007                    	mov     al, 7
  5539 00001CBA CD10                    	int     10h
  5540 00001CBC EBBF                    	jmp     short read_next_char
  5541                                  loc_arrow:    
  5542 00001CBE 80FC4B                  	cmp     ah, 4Bh
  5543 00001CC1 74CA                    	je      short loc_back
  5544 00001CC3 80FC53                  	cmp     ah, 53h
  5545 00001CC6 74C5                    	je      short loc_back
  5546 00001CC8 EBB3                    	jmp     short read_next_char
  5547                                  char_return:
  5548 00001CCA B403                    	mov     ah, 3
  5549 00001CCC CD10                    	int     10h
  5550                                  check_char_type:
  5551 00001CCE 3C20                    	cmp     al, 20h
  5552 00001CD0 7229                    	jb      short loc_escape
  5553 00001CD2 88D4                    	mov     ah, dl
  5554 00001CD4 2A26[A354]              	sub     ah, byte [Cursor_Pos]
  5555                                  	;cmp	ah, 10 
  5556                                  	;ja	short loc_beep
  5557 00001CD8 3A26[BB64]              	cmp     ah, [vname_length] ; 05/01/2018
  5558 00001CDC 73D8                    	jnb	short loc_beep
  5559 00001CDE 3C7A                    	cmp     al, 'z'
  5560 00001CE0 779B                    	ja      short read_next_char
  5561 00001CE2 3C61                    	cmp     al, 'a'
  5562 00001CE4 7202                    	jb      short pass_capitalize
  5563 00001CE6 24DF                    	and     al, 0DFh
  5564                                  pass_capitalize:
  5565 00001CE8 88E3                    	mov     bl, ah 
  5566 00001CEA 30E4                    	xor     ah, ah
  5567 00001CEC 8900                    	mov     [si+bx], ax
  5568 00001CEE B307                    	mov     bl, 7
  5569 00001CF0 B40E                    	mov     ah, 0Eh
  5570 00001CF2 CD10                    	int     10h
  5571 00001CF4 EB87                    	jmp     short read_next_char
  5572                                  pass_escape:
  5573 00001CF6 3C0D                    	cmp     al, 0Dh	; 13 ; ENTER
  5574 00001CF8 7583                    	jne     short read_next_char
  5575                                  	;mov	ah, 0Eh
  5576                                  	;int	10h
  5577                                  	;mov	al, 0Ah
  5578                                  	;int	10h
  5579 00001CFA C3                      	retn
  5580                                  loc_escape:
  5581 00001CFB 3C1B                    	cmp     al, 1Bh	; 27 ; ESC
  5582 00001CFD 75F7                    	jne     short pass_escape
  5583 00001CFF F9                      	stc
  5584 00001D00 C3                      	retn
  5585                                  
  5586                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5587                                  ; display CHS takle
  5588                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5589                                  
  5590                                  display_chs_table:
  5591                                  
  5592                                  	; 16/10/2020
  5593                                  	; 12/10/2020 (fdisk3)
  5594                                  	; 11/02/2019 (hdimage)
  5595                                  
  5596 00001D01 06                      	push	es
  5597 00001D02 BF00B8                  	mov	di, 0B800h
  5598 00001D05 8EC7                    	mov	es, di
  5599 00001D07 BFA000                  	mov	di, 160 ; row 1
  5600 00001D0A B407                    	mov	ah, 07h
  5601 00001D0C B044                    	mov	al, 'D'
  5602 00001D0E AB                      	stosw
  5603 00001D0F B069                    	mov	al, 'i'
  5604 00001D11 AB                      	stosw
  5605 00001D12 B073                    	mov	al, 's'
  5606 00001D14 AB                      	stosw
  5607 00001D15 B06B                    	mov	al, 'k'
  5608 00001D17 AB                      	stosw
  5609 00001D18 B03A                    	mov	al, ':'
  5610 00001D1A AB                      	stosw
  5611 00001D1B B020                    	mov	al, ' '
  5612 00001D1D AB                      	stosw
  5613 00001D1E B068                    	mov	al, 'h'
  5614 00001D20 AB                      	stosw
  5615 00001D21 B064                    	mov	al, 'd'
  5616 00001D23 AB                      	stosw
  5617 00001D24 A0[D668]                	mov	al, [DrvNum]
  5618 00001D27 2C50                    	sub	al, 80h-'0'
  5619 00001D29 AB                      	stosw
  5620 00001D2A BF4001                  	mov	di, 320 ; row 2
  5621 00001D2D B95000                  	mov	cx, 80		
  5622 00001D30 B82007                  	mov	ax, 0720h
  5623 00001D33 F3AB                    	rep	stosw
  5624 00001D35 B150                    	mov	cl, 80	; row 3 
  5625 00001D37 B02D                    	mov	al, "-"
  5626 00001D39 F3AB                    	rep	stosw
  5627                                  	;mov	cl, 19
  5628 00001D3B B112                    	mov	cl, 18 ; 16/10/2020 ; row 4
  5629 00001D3D B020                    	mov	al, 20h
  5630 00001D3F F3AB                    	rep	stosw
  5631 00001D41 B043                    	mov	al, 'C'
  5632 00001D43 AB                      	stosw
  5633 00001D44 B079                    	mov	al, 'y'
  5634 00001D46 AB                      	stosw
  5635 00001D47 B06C                    	mov	al, 'l'
  5636 00001D49 AB                      	stosw
  5637 00001D4A B069                    	mov	al, 'i'
  5638 00001D4C AB                       	stosw
  5639 00001D4D B06E                    	mov	al, 'n'
  5640 00001D4F AB                      	stosw	
  5641 00001D50 B064                    	mov	al, 'd'
  5642 00001D52 AB                      	stosw
  5643 00001D53 B065                    	mov	al, 'e'
  5644 00001D55 AB                      	stosw
  5645 00001D56 B072                    	mov	al, 'r'
  5646 00001D58 AB                       	stosw
  5647 00001D59 B073                    	mov	al, 's'
  5648 00001D5B AB                       	stosw
  5649 00001D5C B03A                    	mov	al, ':'
  5650 00001D5E AB                      	stosw
  5651 00001D5F B020                    	mov	al, 20h
  5652 00001D61 AB                      	stosw
  5653                                  	;mov	[cylnumpos], di
  5654 00001D62 A1[723F]                	mov	ax, [cylinders]
  5655 00001D65 8B16[743F]              	mov	dx, [cylinders+2] ; 16/10/2020
  5656                                  	;mov	cl, 4
  5657                                  	;mov	ch, 07h ; color
  5658 00001D69 E86A00                  	call	write_number
  5659                                  	
  5660                                  	;mov	ax, 0720h
  5661 00001D6C B020                    	mov	al, 20h ; 16/10/2020
  5662 00001D6E AB                      	stosw
  5663 00001D6F AB                      	stosw
  5664 00001D70 B048                    	mov	al, 'H'
  5665 00001D72 AB                      	stosw
  5666 00001D73 B065                    	mov	al, 'e'
  5667 00001D75 AB                      	stosw
  5668 00001D76 B061                    	mov	al, 'a'
  5669 00001D78 AB                      	stosw
  5670 00001D79 B064                    	mov	al, 'd'
  5671 00001D7B AB                       	stosw
  5672 00001D7C B073                    	mov	al, 's'
  5673 00001D7E AB                       	stosw
  5674 00001D7F B03A                    	mov	al, ':'
  5675 00001D81 AB                      	stosw
  5676 00001D82 B020                    	mov	al, 20h
  5677 00001D84 AB                      	stosw
  5678                                  	;mov	[hednumpos], di
  5679 00001D85 A1[703F]                	mov	ax, [heads]
  5680 00001D88 31D2                    	xor	dx, dx ; 16/10/2020
  5681                                  	;mov	cl, 2
  5682                                  	;mov	ch, 07h ; color
  5683 00001D8A E84900                  	call	write_number
  5684                                  
  5685                                  	;mov	ax, 0720h
  5686 00001D8D B020                    	mov	al, 20h ; 16/10/2020
  5687 00001D8F AB                      	stosw
  5688 00001D90 AB                      	stosw
  5689 00001D91 B053                    	mov	al, 'S'
  5690 00001D93 AB                      	stosw
  5691 00001D94 B065                    	mov	al, 'e'
  5692 00001D96 AB                      	stosw
  5693 00001D97 B063                    	mov	al, 'c'
  5694 00001D99 AB                      	stosw
  5695 00001D9A B074                    	mov	al, 't'
  5696 00001D9C AB                       	stosw
  5697 00001D9D B06F                    	mov	al, 'o'
  5698 00001D9F AB                      	stosw
  5699 00001DA0 B072                    	mov	al, 'r'
  5700 00001DA2 AB                       	stosw
  5701 00001DA3 B073                    	mov	al, 's'
  5702 00001DA5 AB                       	stosw
  5703 00001DA6 B03A                    	mov	al, ':'
  5704 00001DA8 AB                      	stosw
  5705 00001DA9 B020                    	mov	al, 20h
  5706 00001DAB AB                      	stosw
  5707                                  	;mov	[secnumpos], di
  5708 00001DAC A1[6E3F]                	mov	ax, [sectors]
  5709 00001DAF 29D2                    	sub	dx, dx ; 16/10/2020
  5710                                  	;mov	cl, 2
  5711                                  	;mov	ch, 07h ; color
  5712 00001DB1 E82200                  	call	write_number
  5713                                  
  5714 00001DB4 B92003                  	mov	cx, 800 ; 16/10/2020 ; row 5
  5715 00001DB7 29F9                    	sub	cx, di
  5716 00001DB9 D0E9                    	shr	cl, 1
  5717                                  	;mov	cl, 22
  5718                                  	;mov	ax, 0720h
  5719 00001DBB B020                    	mov	al, 20h ; 16/10/2020
  5720 00001DBD F3AB                    	rep	stosw
  5721                                  	
  5722 00001DBF B150                    	mov	cl, 80 	; row 6
  5723 00001DC1 B02D                    	mov	al, "-"
  5724 00001DC3 F3AB                    	rep	stosw
  5725                                  
  5726 00001DC5 B150                    	mov	cl, 80	 ; row 7
  5727                                  	;mov	cl, 160	 ; row 7, 8
  5728 00001DC7 B020                    	mov	al, 20h
  5729 00001DC9 F3AB                    	rep	stosw
  5730                                  
  5731 00001DCB BA0006                  	mov	dx, 0600h ; DH = row, DL = 0 column
  5732 00001DCE 31DB                    	xor	bx, bx ; BH = video page (0)
  5733 00001DD0 B402                    	mov	ah, 02h ; set cursor position
  5734 00001DD2 CD10                    	int	10h
  5735                                  
  5736 00001DD4 07                      	pop	es
  5737 00001DD5 C3                      	retn
  5738                                  
  5739                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5740                                  ; write decimal number
  5741                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5742                                  
  5743                                  ;write_number:
  5744                                  ;	; 12/10/2020
  5745                                  ;	mov	bx, 10
  5746                                  ;	mov	si, cx
  5747                                  ;wnum_1:
  5748                                  ;	xor	dx, dx
  5749                                  ;	div	bx
  5750                                  ;	push	dx
  5751                                  ;	dec	cl
  5752                                  ;	jnz	short wnum_1
  5753                                  ;	mov	cx, si
  5754                                  ;	mov	ah, ch	; color (07h or 0Fh)
  5755                                  ;	xor	ch, ch
  5756                                  ;wnum_2:
  5757                                  ;	pop	dx
  5758                                  ;	mov	al, dl
  5759                                  ;	add	al, '0'
  5760                                  ;	stosw
  5761                                  ;	loop	wnum_2
  5762                                  ;	retn
  5763                                  
  5764                                  write_number:
  5765                                  	; 16/10/2020
  5766                                  	; dx:ax = binary number
  5767                                  	; di = decimal number/string location
  5768                                  	; modified registers: ax, bx, cx, dx, bp, di
  5769 00001DD6 B90A00                  	mov	cx, 10
  5770 00001DD9 89E5                    	mov	bp, sp
  5771                                  wnum_1:
  5772 00001DDB E89FEE                  	call	div32
  5773 00001DDE 53                      	push	bx
  5774 00001DDF 21D2                    	and	dx, dx
  5775 00001DE1 75F8                    	jnz	short wnum_1
  5776 00001DE3 09C0                    	or	ax, ax
  5777 00001DE5 75F4                    	jnz	short wnum_1
  5778                                  wnum_2:	
  5779 00001DE7 58                      	pop	ax
  5780 00001DE8 0430                    	add	al, '0'
  5781 00001DEA B407                    	mov	ah, 07h ; color
  5782 00001DEC AB                      	stosw
  5783 00001DED 39E5                    	cmp	bp, sp
  5784 00001DEF 77F6                    	ja	short wnum_2
  5785 00001DF1 C3                      	retn
  5786                                  
  5787                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5788                                  ; partition size input
  5789                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5790                                  
  5791                                  	; 12/03/2021
  5792                                  partition_size_input:
  5793                                  	; 23/10/2020 (fdisk3.s modification on hdimage.s source code)
  5794                                  
  5795 00001DF2 C706[7E6D]0000          	mov	word [pSize_multiplier+2], 0
  5796 00001DF8 C606[836D]42            	mov	byte [msg_psize_unit+1], 'B'
  5797 00001DFD A0[826D]                	mov	al, [pSize_unit]
  5798 00001E00 3C25                    	cmp	al, '%'
  5799 00001E02 7529                    	jne	short psu_0
  5800                                  	; 08/02/2019
  5801                                  	; calculate sector count for max. available sectors percentage
  5802 00001E04 8B16[726D]              	mov	dx, [pp_Sectors+2] ; max. available sectors
  5803 00001E08 A1[706D]                	mov	ax, [pp_Sectors]   ; for a new partition
  5804                                  	;mov	dx, [total_sectors+2]
  5805                                  	;mov	ax, [total_sectors]	
  5806                                  	;mov	cx, 100
  5807                                  	; 13/03/2021
  5808 00001E0B B96300                  	mov	cx, 99
  5809 00001E0E 01C8                    	add	ax, cx
  5810 00001E10 83D200                  	adc	dx, 0
  5811 00001E13 41                      	inc	cx ; cx = 100
  5812 00001E14 E866EE                  	call	div32
  5813 00001E17 A3[7C6D]                	mov	[pSize_multiplier], ax
  5814                                  	; 29/10/2020
  5815 00001E1A 8916[7E6D]              	mov	[pSize_multiplier+2], dx
  5816 00001E1E B400                    	mov	ah, 0
  5817 00001E20 8826[836D]              	mov	[msg_psize_unit+1], ah
  5818                                  	;mov	byte [pSize_maxdigits], 2
  5819 00001E24 C606[806D]03            	mov	byte [pSize_maxdigits], 3 ; 29/10/2020
  5820 00001E29 B025                    	mov	al, '%'
  5821 00001E2B EB65                    	jmp	short psu_6
  5822                                  psu_0:
  5823 00001E2D 3C43                    	cmp	al, 'C'
  5824 00001E2F 7517                    	jne	short psu_1
  5825 00001E31 A1[6E3F]                	mov	ax, [sectors]
  5826 00001E34 F726[703F]              	mul	word [heads]
  5827 00001E38 A3[7C6D]                	mov	[pSize_multiplier], ax	
  5828                                  	;mov	byte [pSize_maxdigits], 4 
  5829                                  	; <= 65535 cylinders
  5830 00001E3B C606[806D]05            	mov	byte [pSize_maxdigits], 5 ; 23/10/2020
  5831                                  	;sub	dh, dh
  5832 00001E40 8836[836D]              	mov	[msg_psize_unit+1], dh
  5833 00001E44 B043                    	mov	al, 'C'
  5834 00001E46 EB4A                    	jmp	short psu_6	
  5835                                  psu_1:
  5836 00001E48 3C47                    	cmp	al, 'G'
  5837 00001E4A 7513                    	jne	short psu_2
  5838 00001E4C C706[7C6D]0008          	mov	word [pSize_multiplier], 2*1024
  5839 00001E52 C706[7E6D]0004          	mov	word [pSize_multiplier+2], 1024
  5840                                  	;mov	byte [pSize_maxdigits], 1
  5841 00001E58 C606[806D]03            	mov	byte [pSize_maxdigits], 3 ; <= 512 GB ; 23/10/2020
  5842 00001E5D EB33                    	jmp	short psu_6
  5843                                  psu_2:
  5844 00001E5F 3C4D                    	cmp	al, 'M'
  5845 00001E61 750D                    	jne	short psu_3
  5846 00001E63 C706[7C6D]0008          	mov	word [pSize_multiplier], 2*1024
  5847                                  	;;mov	byte [pSize_maxdigits], 4
  5848                                  	;mov	byte [pSize_maxdigits], 7 ; 23/10/2020
  5849                                  	; 12/03/2021
  5850 00001E69 C606[806D]06            	mov	byte [pSize_maxdigits], 6 ; <= 524288
  5851 00001E6E EB22                    	jmp	short psu_6
  5852                                  psu_3:
  5853 00001E70 3C4B                    	cmp	al, 'K'
  5854 00001E72 750D                    	jne	short psu_4
  5855 00001E74 C706[7C6D]0200          	mov	word [pSize_multiplier], 2
  5856                                  	;jmp	short psu_5
  5857                                  	; 12/03/2021
  5858 00001E7A C606[806D]09            	mov	byte [pSize_maxdigits], 9 ; <= 536870912
  5859 00001E7F EB11                    	jmp	short psu_6 	
  5860                                  psu_4:
  5861                                  	; al = 'S'
  5862 00001E81 30E4                    	xor	ah, ah
  5863 00001E83 8826[836D]              	mov	[msg_psize_unit+1], ah
  5864 00001E87 C706[7C6D]0100          	mov	word [pSize_multiplier], 1
  5865                                  psu_5:
  5866                                  	;mov	byte [pSize_maxdigits], 7
  5867 00001E8D C606[806D]0A            	mov	byte [pSize_maxdigits], 10 ; 23/10/2020
  5868                                  psu_6:
  5869 00001E92 A2[9B4E]                	mov	[msg_partition_size_x], al
  5870 00001E95 BE[874E]                	mov	si, msg_partition_size	
  5871 00001E98 E8E7FC                  	call	print_msg
  5872                                  
  5873 00001E9B 89E5                    	mov	bp, sp
  5874 00001E9D 31DB                    	xor	bx, bx
  5875 00001E9F 891E[786D]              	mov	[pSize_temp], bx ; 0
  5876                                  	;mov	[pSize_temp+2], bx ; 0
  5877 00001EA3 881E[816D]              	mov	[pSize_digitpos], bl ; 0
  5878                                  	; bh = 0  ; video page
  5879 00001EA7 B403                    	mov     ah, 3	; get cursor pos
  5880 00001EA9 CD10                    	int     10h
  5881 00001EAB 8916[A354]              	mov	[Cursor_Pos], dx
  5882                                  	; 09/02/2019
  5883 00001EAF B307                    	mov     bl, 7   ; page 0, color 7 (light gray)   
  5884                                  psu_7:
  5885 00001EB1 30E4                    	xor	ah, ah
  5886 00001EB3 CD16                    	int	16h
  5887                                  
  5888 00001EB5 3C30                    	cmp	al, '0'
  5889 00001EB7 7225                    	jb	short psu_8
  5890 00001EB9 3C39                    	cmp	al, '9'
  5891 00001EBB 77F4                    	ja	short psu_7
  5892 00001EBD 8A1E[816D]              	mov	bl, [pSize_digitpos]
  5893 00001EC1 3A1E[806D]              	cmp	bl, [pSize_maxdigits]
  5894 00001EC5 73EA                    	jnb	short psu_7
  5895 00001EC7 FE06[816D]              	inc	byte [pSize_digitpos]
  5896 00001ECB 2C30                    	sub	al, '0'
  5897 00001ECD 30E4                    	xor	ah, ah
  5898 00001ECF 50                      	push	ax
  5899 00001ED0 0430                    	add	al, '0'
  5900 00001ED2 B40E                    	mov	ah, 0Eh	; write char as tty		
  5901                                  	;mov	bx, 7   ; page 0, color 7 (light gray)         
  5902 00001ED4 CD10                    	int	10h
  5903 00001ED6 EBD9                    	jmp	short psu_7
  5904                                  
  5905                                  psu_8esc:
  5906                                  	; 29/10/2020 (ESCape)
  5907 00001ED8 89EC                    	mov	sp, bp ; clean stack
  5908                                  
  5909 00001EDA 08C0                    	or	al, al ; zf = 0
  5910 00001EDC F9                      	stc
  5911 00001EDD C3                      	retn	
  5912                                  psu_8:
  5913 00001EDE 20C0                    	and	al, al
  5914 00001EE0 0F849300                	jz	psu_15 ; check for left arrow key 
  5915 00001EE4 3C1B                    	cmp	al, 27
  5916 00001EE6 74F0                    	je	short psu_8esc ; ESCAPE key ; 29/10/2020
  5917 00001EE8 0F878500                	ja	psu_14 ; check for left arrow key
  5918 00001EEC 3C0D                    	cmp	al, 13
  5919                                  	;je	short psu_9  ; ENTER key
  5920 00001EEE 7249                    	jb	short psu_11 ; check for backspace key
  5921                                  	;jmp	short psu_7
  5922 00001EF0 77BF                    	ja	short psu_7
  5923                                  psu_9:
  5924 00001EF2 31C0                    	xor	ax, ax
  5925 00001EF4 A3[7A6D]                	mov	[pSize_temp+2], ax ; 0 ; 08/02/2019
  5926 00001EF7 3806[816D]              	cmp	byte [pSize_digitpos], al ; 0
  5927 00001EFB 0F868500                	jna	psu_16		
  5928                                  	;xor	bh, bh
  5929 00001EFF 8A1E[816D]              	mov	bl, [pSize_digitpos]
  5930 00001F03 FECB                    	dec	bl
  5931 00001F05 D0E3                    	shl	bl, 1
  5932 00001F07 01E3                    	add	bx, sp
  5933 00001F09 8B07                    	mov	ax, [bx]
  5934 00001F0B A3[786D]                	mov	[pSize_temp], ax
  5935                                  	;mov	word [pSize_temp+2], 0
  5936 00001F0E B90A00                  	mov	cx, 10
  5937                                  psu_10:
  5938 00001F11 FE0E[816D]              	dec	byte [pSize_digitpos]
  5939 00001F15 746D                    	jz	short psu_16
  5940                                  	
  5941 00001F17 A1[786D]                	mov	ax, [pSize_temp]
  5942 00001F1A 8B16[7A6D]              	mov	dx, [pSize_temp+2]
  5943                                  	;mov	cx, 10
  5944 00001F1E E86AED                  	call	mul32
  5945                                  	;mov	[pSize_temp], ax
  5946                                  	;mov	[pSize_temp+2], dx
  5947                                  	;xor	bh, bh
  5948 00001F21 8A1E[816D]              	mov	bl, [pSize_digitpos]
  5949 00001F25 FECB                    	dec	bl
  5950 00001F27 D0E3                    	shl	bl, 1
  5951 00001F29 01E3                    	add	bx, sp ; (*)
  5952                                  	;mov	ax, [bx]
  5953                                  	;add	[pSize_temp], ax
  5954                                  	;adc	word [pSize_temp+2], 0
  5955 00001F2B 0307                    	add	ax, [bx]
  5956 00001F2D 83D200                  	adc	dx, 0
  5957 00001F30 A3[786D]                	mov	[pSize_temp], ax
  5958 00001F33 8916[7A6D]              	mov	[pSize_temp+2], dx
  5959 00001F37 EBD8                    	jmp	short psu_10
  5960                                  	
  5961                                  	; Left arrow, backspace, DEL key checking
  5962                                  psu_11:
  5963 00001F39 3C08                    	cmp	al, 8 ; backspace key
  5964 00001F3B 0F8572FF                	jne	psu_7
  5965                                  psu_12:
  5966                                  	;; bh = 0  ; video page
  5967                                  	;mov	ah, 3 ; get cursor pos
  5968                                  	;int	10h
  5969                                  	;cmp	dl, [Cursor_Pos]
  5970                                  	;jna	short psu_13
  5971                                  	;dec	dl
  5972                                  	;dec	byte [pSize_digitpos]
  5973                                  
  5974                                  	; 08/02/2019
  5975 00001F3F 8B16[A354]              	mov	dx, [Cursor_Pos]
  5976 00001F43 8A1E[816D]              	mov	bl, [pSize_digitpos]
  5977 00001F47 20DB                    	and	bl, bl
  5978 00001F49 741D                    	jz	short psu_13	
  5979                                  
  5980 00001F4B FECB                    	dec	bl 
  5981 00001F4D 881E[816D]              	mov	[pSize_digitpos], bl
  5982                                  	
  5983 00001F51 00DA                    	add	dl, bl
  5984                                  
  5985                                  	; bh = 0  ; video page
  5986 00001F53 B402                    	mov	ah, 2 ; set cursor pos
  5987 00001F55 CD10                    	int	10h
  5988                                  	;mov	bl, dl
  5989                                  	;sub	bl, [Cursor_Pos] 
  5990 00001F57 B90100                  	mov	cx, 1
  5991 00001F5A B409                    	mov	ah, 9 ; write char at current curs pos
  5992 00001F5C B020                    	mov	al, 20h ; space (blank)
  5993 00001F5E 8800                    	mov	[si+bx], al
  5994                                  	; bh = 0 ; video page
  5995 00001F60 B307                    	mov	bl, 7 ; attribute/color (light gray)
  5996 00001F62 CD10                    	int	10h
  5997                                  
  5998                                  	; 09/02/2019
  5999 00001F64 58                      	pop	ax ; remove last digit on top of stack 
  6000                                  		   ; set sp to correct position for BX (*)	
  6001 00001F65 E949FF                  	jmp	psu_7
  6002                                  psu_13:
  6003 00001F68 B40E                    	mov	ah, 0Eh
  6004 00001F6A B007                    	mov	al, 7
  6005                                  	;mov	bx, 7
  6006 00001F6C CD10                    	int	10h
  6007 00001F6E E940FF                  	jmp	psu_7
  6008                                  psu_14:
  6009 00001F71 3CE0                    	cmp	al, 0E0h          
  6010 00001F73 0F853AFF                	jne	psu_7
  6011                                  psu_15:    
  6012 00001F77 80FC4B                  	cmp	ah, 4Bh ; left arrow
  6013 00001F7A 74C3                    	je	short psu_12
  6014 00001F7C 80FC53                  	cmp	ah, 53h ; DEL key (backspace)
  6015 00001F7F 74BE                    	je	short psu_12
  6016 00001F81 E92DFF                  	jmp	psu_7
  6017                                  psu_16:
  6018 00001F84 89EC                    	mov	sp, bp
  6019                                  
  6020                                  	; 29/10/2020
  6021 00001F86 803E[826D]25            	cmp	byte [pSize_unit], '%'
  6022 00001F8B 751E                    	jne	short psu_23
  6023                                  
  6024 00001F8D B86400                  	mov	ax, 100
  6025 00001F90 3906[786D]              	cmp	word [pSize_temp], ax ; 100 ; % limit
  6026 00001F94 7624                    	jna	short psu_17
  6027 00001F96 A3[786D]                	mov	word [pSize_temp], ax
  6028                                  
  6029                                  	; (re)set asciiz number string to '100' 
  6030                                  
  6031 00001F99 28FF                    	sub	bh, bh ; 0 ; video page 0
  6032 00001F9B 8B16[A354]              	mov	dx, [Cursor_Pos]
  6033 00001F9F B402                    	mov	ah, 2 ; set cursor pos
  6034 00001FA1 CD10                    	int	10h
  6035                                  
  6036 00001FA3 BE[D268]                	mov	si, msg_100
  6037 00001FA6 E8D9FB                  	call	print_msg
  6038                                  
  6039 00001FA9 EB0F                    	jmp	short psu_17
  6040                                  psu_23:
  6041 00001FAB 803E[826D]53            	cmp	byte [pSize_unit], 'S'
  6042 00001FB0 7508                    	jne	short psu_17 
  6043                                  
  6044 00001FB2 BE[B064]                	mov	si, msg_sectors_crlf
  6045 00001FB5 E8CAFB                  	call	print_msg
  6046                                  	;xor	bx, bx
  6047 00001FB8 EB30                    	jmp	short psu_18
  6048                                  psu_17:
  6049 00001FBA BE[826D]                	mov	si, msg_psize_unit
  6050 00001FBD E8C2FB                  	call	print_msg
  6051                                  
  6052 00001FC0 BE[5F55]                	mov	si, CRLF
  6053 00001FC3 E8BCFB                  	call	print_msg
  6054                                  
  6055                                  	; 29/10/2020
  6056 00001FC6 803E[826D]25            	cmp	byte [pSize_unit], '%'
  6057 00001FCB 751D                    	jne	short psu_18
  6058                                  	
  6059 00001FCD 8B0E[786D]              	mov	cx, [pSize_temp]
  6060                                  
  6061 00001FD1 21C9                    	and	cx, cx
  6062 00001FD3 7443                    	jz	short psu_21 ; 0%, ZERO !
  6063                                  
  6064 00001FD5 83F964                  	cmp	cx, 100
  6065 00001FD8 7606                    	jna	short psu_24
  6066                                  
  6067                                  	; show 100% for 1 second (for >100%)
  6068 00001FDA E83D00                  	call	wait1second ; 29/10/2020
  6069                                  
  6070 00001FDD B96400                  	mov	cx, 100
  6071                                  psu_24:
  6072 00001FE0 A1[7C6D]                	mov	ax, [pSize_multiplier]
  6073 00001FE3 8B16[7E6D]              	mov	dx, [pSize_multiplier+2]
  6074                                  
  6075                                  	;mov	cx, [pSize_temp]
  6076                                  	;and	cx, cx
  6077                                  	;jz	short psu_21 ; 0%, ZERO !
  6078                                  
  6079 00001FE7 E9A1EC                  	jmp	mul32
  6080                                  psu_18:
  6081 00001FEA A1[786D]                	mov	ax, [pSize_temp]
  6082 00001FED 8B16[7A6D]              	mov	dx, [pSize_temp+2]
  6083 00001FF1 89C1                    	mov	cx, ax
  6084 00001FF3 09D1                    	or	cx, dx
  6085                                  	;jz	short psu_20
  6086 00001FF5 7421                    	jz	short psu_21 ; 08/02/2019
  6087 00001FF7 8B0E[7C6D]              	mov	cx, [pSize_multiplier]
  6088 00001FFB 803E[826D]43            	cmp	byte [pSize_unit], 'C'
  6089 00002000 7413                    	je	short psu_20 ; 09/02/2019
  6090                                  	;jne	short psu_19
  6091                                  	;call	mul32
  6092                                  	; 08/02/2019
  6093                                  	; dx:ax = requested partition size in sectors
  6094                                  	;retn	
  6095                                  ;psu_19:
  6096                                  	;mov	cx, [pSize_multiplier]
  6097 00002002 83F901                  	cmp	cx, 1
  6098                                  	;jna	short psu_20
  6099 00002005 7703                    	ja	short psu_19
  6100                                  	; 09/02/2019
  6101 00002007 31DB                    	xor	bx, bx
  6102 00002009 C3                      	retn
  6103                                  psu_19:
  6104 0000200A E87EEC                  	call	mul32
  6105                                  	;and	bx, bx
  6106                                  	;jnz	short psu_22 ; 09/02/2019	
  6107 0000200D 8B0E[7E6D]              	mov	cx, [pSize_multiplier+2]
  6108 00002011 09C9                    	or	cx, cx
  6109                                  	;jz	short psu_20
  6110 00002013 7404                    	jz	short psu_22 ; 09/02/2019
  6111                                  psu_20:
  6112                                  	;call	mul32
  6113                                  	;retn
  6114 00002015 E973EC                  	jmp	mul32 ; 23/10/2020
  6115                                  psu_21:
  6116                                  	; zf = 1 ; 29/10/2020
  6117 00002018 F9                      	stc
  6118                                  psu_22:
  6119 00002019 C3                      	retn
  6120                                  
  6121                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6122                                  ; wait for 1 second
  6123                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6124                                  
  6125                                  	; 29/10/2020
  6126                                  wait1second:
  6127 0000201A B402                    	mov	ah, 2
  6128 0000201C CD1A                    	int	1Ah ; get time of day
  6129 0000201E 720C                    	jc	short w1s_2
  6130                                  w1s_1:
  6131 00002020 52                      	push	dx
  6132 00002021 B402                    	mov	ah, 2
  6133 00002023 CD1A                    	int	1Ah ; get time of day
  6134 00002025 58                      	pop	ax
  6135 00002026 7204                    	jc	short w1s_2
  6136 00002028 38E6                    	cmp	dh, ah
  6137 0000202A 74F4                    	je	short w1s_1 ; same second
  6138                                  w1s_2:
  6139 0000202C C3                      	retn
  6140                                  
  6141                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6142                                  ; partition type input
  6143                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6144                                  
  6145                                  partition_type_input:
  6146 0000202D BE[A14E]                	mov	si, msg_partition_type	
  6147 00002030 E84FFB                  	call	print_msg
  6148                                  
  6149 00002033 31DB                    	xor	bx, bx
  6150                                  
  6151 00002035 881E[926D]              	mov	[pType_pos], bl ; 0
  6152 00002039 891E[936D]              	mov	[pType_num], bx ; 0
  6153                                  
  6154                                  	; bh = 0  ; video page
  6155 0000203D B403                    	mov     ah, 3 ; get cursor pos
  6156 0000203F CD10                    	int     10h
  6157 00002041 8916[A354]              	mov	[Cursor_Pos], dx
  6158                                  ptu_0:
  6159 00002045 30E4                    	xor	ah, ah
  6160 00002047 CD16                    	int	16h
  6161                                  
  6162 00002049 803E[926D]01            	cmp	byte [pType_pos], 1
  6163 0000204E 773F                    	ja	short ptu_5	
  6164                                  
  6165 00002050 3C30                    	cmp	al, '0'
  6166 00002052 723B                    	jb	short ptu_5
  6167 00002054 3C39                    	cmp	al, '9'
  6168 00002056 7707                    	ja	short ptu_1
  6169 00002058 88C4                    	mov	ah, al
  6170 0000205A 80EC30                  	sub	ah, '0'
  6171 0000205D EB13                    	jmp	short ptu_2 
  6172                                  ptu_1:
  6173 0000205F 3CE0                    	cmp     al, 0E0h          
  6174 00002061 7473                    	je	short ptu_9
  6175                                  
  6176 00002063 24DF                    	and	al, 0DFh
  6177 00002065 3C41                    	cmp	al, 'A'
  6178 00002067 72DC                    	jb	short ptu_0
  6179 00002069 3C46                    	cmp	al, 'F'
  6180 0000206B 77D8                    	ja	short ptu_0
  6181 0000206D 88C4                    	mov	ah, al
  6182 0000206F 80EC37                  	sub	ah, 'A'-10
  6183                                  ptu_2:
  6184 00002072 803E[926D]00            	cmp	byte [pType_pos], 0
  6185 00002077 7606                    	jna	short ptu_3
  6186 00002079 8826[946D]              	mov	[pType_num+1], ah
  6187 0000207D EB04                    	jmp	short ptu_4 
  6188                                  ptu_3:
  6189 0000207F 8826[936D]              	mov	[pType_num], ah
  6190                                  ptu_4:
  6191 00002083 B40E                    	mov	ah, 0Eh
  6192 00002085 B307                    	mov	bl, 7
  6193 00002087 CD10                    	int	10h
  6194                                  
  6195 00002089 FE06[926D]              	inc	byte [pType_pos]
  6196                                  
  6197 0000208D EBB6                    	jmp	short ptu_0 
  6198                                  ptu_5:
  6199 0000208F 20C0                    	and	al, al
  6200 00002091 7443                    	jz	short ptu_9 ; check for left arrow key 
  6201 00002093 3C1B                    	cmp	al, 27
  6202 00002095 744C                    	je	short ptu_10 ; ESCAPE key
  6203 00002097 77AC                    	ja	short ptu_0
  6204 00002099 3C0D                    	cmp	al, 13
  6205 0000209B 744A                    	je	short ptu_11  ; ENTER key
  6206 0000209D 77A6                    	ja	short ptu_0
  6207                                  ptu_6:
  6208                                  	; Left arrow, backspace, DEL key checking
  6209                                  
  6210 0000209F 3C08                    	cmp	al, 8 ; backspace key
  6211 000020A1 75A2                    	jne	short ptu_0
  6212                                  ptu_7:
  6213                                  	; bh = 0  ; video page
  6214 000020A3 B403                    	mov	ah, 3 ; get cursor pos
  6215 000020A5 CD10                    	int	10h
  6216 000020A7 3A16[A354]              	cmp	dl, [Cursor_Pos]
  6217 000020AB 7620                    	jna	short ptu_8
  6218 000020AD FECA                    	dec	dl
  6219 000020AF FE0E[926D]              	dec	byte [pType_pos]
  6220                                  	; bh = 0  ; video page
  6221 000020B3 B402                    	mov	ah, 2 ; set cursor pos
  6222 000020B5 CD10                    	int	10h
  6223 000020B7 88D3                    	mov	bl, dl
  6224 000020B9 2A1E[A354]              	sub	bl, [Cursor_Pos] 
  6225 000020BD B90100                  	mov	cx, 1
  6226 000020C0 B409                    	mov	ah, 9 ; write char at current curs pos
  6227 000020C2 B020                    	mov	al, 20h ; space (blank)
  6228 000020C4 8800                    	mov	[si+bx], al
  6229                                  	; bh = 0 ; video page
  6230 000020C6 B307                    	mov	bl, 7 ; attribute/color (light gray)
  6231 000020C8 CD10                    	int	10h
  6232 000020CA E978FF                  	jmp	ptu_0
  6233                                  ptu_8:
  6234 000020CD B40E                    	mov	ah, 0Eh
  6235 000020CF B007                    	mov	al, 7
  6236 000020D1 CD10                    	int	10h
  6237 000020D3 E96FFF                  	jmp	ptu_0
  6238                                  ptu_9:    
  6239 000020D6 80FC4B                  	cmp	ah, 4Bh ; left arrow
  6240 000020D9 74C8                    	je	short ptu_7
  6241 000020DB 80FC53                  	cmp	ah, 53h ; DEL key (backspace)
  6242 000020DE 74C3                    	je	short ptu_7
  6243 000020E0 E962FF                  	jmp	ptu_0
  6244                                  
  6245                                  ptu_10: ; ESCAPE
  6246                                  	;mov	al, 0
  6247                                  	; 29/10/2020
  6248 000020E3 28C0                    	sub	al, al ; 0
  6249                                  	; partition type is 0 (none)
  6250 000020E5 EB12                    	jmp	short ptu_12
  6251                                  ptu_11: ; ENTER
  6252 000020E7 A0[936D]                	mov	al, [pType_num]
  6253 000020EA 803E[926D]01            	cmp	byte [pType_pos], 1
  6254 000020EF 7608                    	jna	short ptu_12
  6255 000020F1 B410                    	mov	ah, 16
  6256 000020F3 F6E4                    	mul	ah
  6257 000020F5 0206[946D]              	add	al, [pType_num+1]
  6258                                  ptu_12:
  6259 000020F9 50                      	push	ax
  6260 000020FA E85BFB                  	call	bin_to_hex
  6261 000020FD A3[B74E]                	mov	[msg_ptype_num], ax
  6262                                  	; bh = 0  ; video page
  6263 00002100 B402                    	mov	ah, 2 ; set cursor pos
  6264 00002102 8B16[A354]              	mov	dx, [Cursor_Pos]
  6265 00002106 CD10                    	int	10h
  6266 00002108 BE[B74E]                	mov	si, msg_ptype_num 
  6267 0000210B E874FA                  	call	print_msg
  6268 0000210E 58                      	pop	ax
  6269 0000210F C3                      	retn
  6270                                  
  6271                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6272                                  ; show selected partition
  6273                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6274                                  
  6275                                  show_selected_partition:
  6276                                  	; INPUT ->
  6277                                  	; 	DS:SI = Partition table row address
  6278                                  	
  6279                                  	; 2019 - 2020 (hdimage.s)	
  6280                                  	;pt_s_offset	equ 7
  6281                                  	;pt_bh_offset	equ 11
  6282                                  	;pt_bs_offset	equ 15
  6283                                  	;pt_bc_offset	equ 19
  6284                                  	;pt_fs_offset	equ 23
  6285                                  	;pt_eh_offset	equ 27
  6286                                  	;pt_es_offset	equ 31
  6287                                  	;pt_ec_offset	equ 35
  6288                                  	;pt_rs_offset	equ 41
  6289                                  	;pt_ts_offset	equ 52
  6290                                  	;pt_fsn_offset	equ 63
  6291                                  
  6292                                  	; 24/10/2020 (fdisk3.s)	
  6293                                  	pt_s_offset	equ 6
  6294                                  	pt_bh_offset	equ 10
  6295                                  	pt_bs_offset	equ 14
  6296                                  	pt_bc_offset	equ 18
  6297                                  	pt_fs_offset	equ 22
  6298                                  	pt_eh_offset	equ 26
  6299                                  	pt_es_offset	equ 30
  6300                                  	pt_ec_offset	equ 34
  6301                                  	pt_rs_offset	equ 40
  6302                                  	pt_ts_offset	equ 51
  6303                                  	pt_fsn_offset	equ 63
  6304                                  
  6305                                  	; clear screen
  6306 00002110 B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
  6307 00002113 CD10                    	int	10h	
  6308                                  
  6309 00002115 89F0                    	mov	ax, si
  6310 00002117 2D[9857]                	sub	ax, MasterBootBuff + pTableOffset ; + 446
  6311 0000211A C0E804                  	shr	al, 4 ; from offset to partition number
  6312 0000211D 0431                    	add	al, '1'  ; 1 based partition number (chr)
  6313                                  	; Write partition number to the header location
  6314 0000211F A2[7750]                	mov	[msg_selected_partition+43], al ; '1' to '4'
  6315                                  	
  6316                                  	; Partition number will be used at formatting stage
  6317 00002122 A2[4653]                	mov	[partition_num_chr], al ; number + '0'
  6318                                  
  6319 00002125 B268                    	mov	dl, 'h'
  6320 00002127 8A04                    	mov	al, [si+ptBootable]
  6321 00002129 E82CFB                  	call	bin_to_hex
  6322 0000212C A3[9251]                	mov	[pt_row+pt_s_offset], ax
  6323 0000212F 8816[9451]              	mov	[pt_row+pt_s_offset+2], dl ; 'h'	
  6324 00002133 8A4401                  	mov	al, [si+ptBeginHead]
  6325 00002136 E81FFB                  	call	bin_to_hex
  6326 00002139 A3[9651]                	mov	[pt_row+pt_bh_offset], ax
  6327 0000213C 8816[9851]              	mov	[pt_row+pt_bh_offset+2], dl ; 'h'
  6328 00002140 8A4402                  	mov	al, [si+ptBeginSector]
  6329 00002143 E812FB                  	call	bin_to_hex
  6330 00002146 A3[9A51]                	mov	[pt_row+pt_bs_offset], ax
  6331 00002149 8816[9C51]              	mov	[pt_row+pt_bs_offset+2], dl ; 'h'
  6332 0000214D 8A4403                  	mov	al, [si+ptBeginCylinder]
  6333 00002150 E805FB                  	call	bin_to_hex
  6334 00002153 A3[9E51]                	mov	[pt_row+pt_bc_offset], ax
  6335 00002156 8816[A051]              	mov	[pt_row+pt_bc_offset+2], dl ; 'h'
  6336 0000215A 8A4404                  	mov	al, [si+ptFileSystemID]
  6337                                   	; Partition type will be used at formatting stage
  6338 0000215D A2[766D]                	mov	[pp_type_user], al
  6339 00002160 E8F5FA                  	call	bin_to_hex
  6340 00002163 A3[A251]                	mov	[pt_row+pt_fs_offset], ax
  6341 00002166 8816[A451]              	mov	[pt_row+pt_fs_offset+2], dl ; 'h'
  6342 0000216A 8A4405                  	mov	al, [si+ptEndHead]
  6343 0000216D E8E8FA                  	call	bin_to_hex
  6344 00002170 A3[A651]                	mov	[pt_row+pt_eh_offset], ax
  6345 00002173 8816[A851]              	mov	[pt_row+pt_eh_offset+2], dl ; 'h'
  6346 00002177 8A4406                  	mov	al, [si+ptEndSector]
  6347 0000217A E8DBFA                  	call	bin_to_hex
  6348 0000217D A3[AA51]                	mov	[pt_row+pt_es_offset], ax
  6349 00002180 8816[AC51]              	mov	[pt_row+pt_es_offset+2], dl ; 'h'
  6350 00002184 8A4407                  	mov	al, [si+ptEndCylinder]
  6351 00002187 E8CEFA                  	call	bin_to_hex
  6352 0000218A A3[AE51]                	mov	[pt_row+pt_ec_offset], ax
  6353 0000218D 8816[B051]              	mov	[pt_row+pt_ec_offset+2], dl ; 'h'
  6354 00002191 8A4408                  	mov	al, [si+ptStartSector]
  6355 00002194 E8C1FA                  	call	bin_to_hex
  6356 00002197 A3[BA51]                	mov	[pt_row+pt_rs_offset+6], ax
  6357 0000219A 8816[BC51]              	mov	[pt_row+pt_rs_offset+8], dl ; 'h'
  6358 0000219E 8A4409                  	mov	al, [si+ptStartSector+1]
  6359 000021A1 E8B4FA                  	call	bin_to_hex
  6360 000021A4 A3[B851]                	mov	[pt_row+pt_rs_offset+4], ax
  6361 000021A7 8A440A                  	mov	al, [si+ptStartSector+2]
  6362 000021AA E8ABFA                  	call	bin_to_hex
  6363 000021AD A3[B651]                	mov	[pt_row+pt_rs_offset+2], ax
  6364 000021B0 8A440B                  	mov	al, [si+ptStartSector+3]
  6365 000021B3 E8A2FA                  	call	bin_to_hex
  6366 000021B6 A3[B451]                	mov	[pt_row+pt_rs_offset], ax
  6367 000021B9 8A440C                  	mov	al, [si+ptSectors]
  6368 000021BC E899FA                  	call	bin_to_hex
  6369 000021BF A3[C551]                	mov	[pt_row+pt_ts_offset+6], ax
  6370 000021C2 8816[C751]              	mov	[pt_row+pt_ts_offset+8], dl ; 'h'
  6371 000021C6 8A440D                  	mov	al, [si+ptSectors+1]
  6372 000021C9 E88CFA                  	call	bin_to_hex
  6373 000021CC A3[C351]                	mov	[pt_row+pt_ts_offset+4], ax
  6374 000021CF 8A440E                  	mov	al, [si+ptSectors+2]
  6375 000021D2 E883FA                  	call	bin_to_hex
  6376 000021D5 A3[C151]                	mov	[pt_row+pt_ts_offset+2], ax
  6377 000021D8 8A440F                  	mov	al, [si+ptSectors+3]
  6378 000021DB E87AFA                  	call	bin_to_hex
  6379 000021DE A3[BF51]                	mov	[pt_row+pt_ts_offset], ax
  6380                                  
  6381 000021E1 8A4404                  	mov	al, [si+ptFileSystemID]
  6382 000021E4 BF[8E40]                	mov	di, valid_partitions
  6383 000021E7 B91300                  	mov	cx, 19
  6384 000021EA F2AE                    	repnz	scasb
  6385 000021EC 7405                    	jz	short ssp_1
  6386 000021EE B8[8040]                	mov	ax, FS_OTHERS	 
  6387 000021F1 EB0C                    	jmp	short ssp_2
  6388                                  ssp_1:
  6389 000021F3 81EF[8F40]              	sub	di, valid_partitions + 1
  6390 000021F7 B80E00                  	mov	ax, 14
  6391 000021FA F7E7                    	mul	di
  6392 000021FC 05[763F]                	add	ax, FileSys_Names
  6393                                  ssp_2:
  6394 000021FF 96                      	xchg	ax, si 
  6395 00002200 B107                    	mov	cl, 7
  6396 00002202 BF[CB51]                	mov	di, pt_row + pt_fsn_offset
  6397 00002205 F3A5                    	rep	movsw
  6398 00002207 89C7                    	mov	di, ax ; partition table row address
  6399                                  
  6400 00002209 BE[4C50]                	mov	si, msg_selected_partition
  6401 0000220C E873F9                  	call	print_msg
  6402                                  
  6403 0000220F BE[2D52]                	mov	si, msg_boot_indicator
  6404 00002212 E86DF9                  	call	print_msg
  6405 00002215 BE[995C]                	mov	si, msg_YES
  6406 00002218 F60580                  	test	byte [di+ptBootable], 80h
  6407 0000221B 7503                    	jnz	short ssp_3
  6408 0000221D BE[9F5C]                	mov	si, msg_NO
  6409                                  ssp_3:
  6410 00002220 E85FF9                  	call	print_msg
  6411                                  
  6412 00002223 BE[4552]                	mov	si, msg_starting_head
  6413 00002226 E859F9                  	call	print_msg
  6414 00002229 8A4501                  	mov	al, [di+ptBeginHead]
  6415 0000222C E8B200                  	call	write_byte_decimal
  6416 0000222F E850F9                  	call	print_msg
  6417 00002232 BE[5D52]                	mov	si, msg_starting_sector
  6418 00002235 E84AF9                  	call	print_msg
  6419 00002238 8A4502                  	mov	al, [di+ptBeginSector]
  6420 0000223B 88C2                    	mov	dl, al  ; bits 7&8 are bits 8&9 of cyl
  6421 0000223D 243F                    	and	al, 3Fh ; sector number, 1 to 63
  6422 0000223F E89F00                  	call	write_byte_decimal			
  6423 00002242 E83DF9                  	call	print_msg	
  6424 00002245 BE[7552]                	mov	si, msg_starting_cylinder
  6425 00002248 E837F9                  	call	print_msg
  6426 0000224B 8A4503                  	mov	al, [di+ptBeginCylinder] ; bits 0to7 of cyl
  6427 0000224E C0EA06                  	shr	dl, 6 ; bits 8&9 of cyl
  6428 00002251 88D4                    	mov	ah, dl
  6429 00002253 31D2                    	xor	dx, dx
  6430                                  	;mov	si, msg_partition_sectors + 7 ; max. 8 digits
  6431                                  	; 06/11/2020
  6432 00002255 BE[8F6D]                	mov	si, msg_partition_sectors + 10 ; max. 11 digits
  6433                                  	; dx_ax: binary number
  6434 00002258 E8E6F9                  	call	bin_to_decimal
  6435                                  	; ds:si = decimal number text address		
  6436 0000225B E824F9                  	call	print_msg
  6437 0000225E BE[8D52]                	mov	si, msg_system_id
  6438 00002261 E81EF9                  	call	print_msg
  6439                                  	; Write file system name (again, copy)
  6440 00002264 BE[CB51]                	mov	si, pt_row + pt_fsn_offset
  6441                                  	;mov	cx, 14
  6442 00002267 B10E                    	mov	cl, 14
  6443 00002269 B40E                    	mov	ah, 0Eh ; write tty
  6444 0000226B BB0700                  	mov	bx, 7
  6445                                  ssp_4:	 
  6446 0000226E AC                      	lodsb
  6447 0000226F CD10                    	int	10h
  6448 00002271 E2FB                    	loop	ssp_4
  6449                                  
  6450 00002273 BE[A552]                	mov	si, msg_ending_head
  6451 00002276 E809F9                  	call	print_msg
  6452 00002279 8A4505                  	mov	al, [di+ptEndHead]
  6453 0000227C E86200                  	call	write_byte_decimal
  6454 0000227F E800F9                  	call	print_msg
  6455 00002282 BE[BD52]                	mov	si, msg_ending_sector
  6456 00002285 E8FAF8                  	call	print_msg
  6457 00002288 8A4506                  	mov	al, [di+ptEndSector]
  6458 0000228B 88C2                    	mov	dl, al  ; bits 7&8 are bits 8&9 of cyl
  6459 0000228D 243F                    	and	al, 3Fh ; sector number, 1 to 63
  6460 0000228F E84F00                  	call	write_byte_decimal			
  6461 00002292 E8EDF8                  	call	print_msg	
  6462 00002295 BE[D552]                	mov	si, msg_ending_cylinder
  6463 00002298 E8E7F8                  	call	print_msg
  6464 0000229B 8A4507                  	mov	al, [di+ptEndCylinder] ; bits 0to7 of cyl
  6465 0000229E C0EA06                  	shr	dl, 6 ; bits 8&9 of cyl
  6466 000022A1 88D4                    	mov	ah, dl
  6467 000022A3 31D2                    	xor	dx, dx
  6468                                  	;mov	si, msg_partition_sectors + 7 ; max. 8 digits
  6469                                  	; 06/11/2020
  6470 000022A5 BE[8F6D]                	mov	si, msg_partition_sectors + 10 ; max. 11 digits 
  6471                                  	; dx_ax: binary number
  6472 000022A8 E896F9                  	call	bin_to_decimal
  6473                                  	; ds:si = decimal number text address		
  6474 000022AB E8D4F8                  	call	print_msg
  6475                                  
  6476 000022AE BE[ED52]                	mov	si, msg_relative_sectors
  6477 000022B1 E8CEF8                  	call	print_msg
  6478 000022B4 8B4508                  	mov	ax, [di+ptStartSector]
  6479 000022B7 8B550A                  	mov	dx, [di+ptStartSector+2]
  6480                                  	;;mov	si, msg_partition_sectors + 7 ; max. 8 digits
  6481                                  	;mov	si, reserved_bytes + 10 ; max. 11 digits
  6482                                  	; 06/11/2020
  6483 000022BA BE[8F6D]                	mov	si, msg_partition_sectors + 10 ; max. 11 digits
  6484 000022BD E881F9                  	call	bin_to_decimal
  6485 000022C0 E8BFF8                  	call	print_msg
  6486                                  
  6487 000022C3 BE[0753]                	mov	si, msg_total_sectors
  6488 000022C6 E8B9F8                  	call	print_msg
  6489 000022C9 8B450C                  	mov	ax, [di+ptSectors]
  6490 000022CC 8B550E                  	mov	dx, [di+ptSectors+2]
  6491                                  	;;mov	si, msg_partition_sectors + 7 ; max. 8 digits
  6492                                  	;mov	si, reserved_bytes + 10 ; max. 11 digits
  6493                                  	; 06/11/2020
  6494 000022CF BE[8F6D]                	mov	si, msg_partition_sectors + 10 ; max. 11 digits
  6495 000022D2 E86CF9                  	call	bin_to_decimal	
  6496 000022D5 E8AAF8                  	call	print_msg
  6497                                  
  6498                                  	; 24/02/2019
  6499 000022D8 BE[5F55]                	mov	si, CRLF
  6500 000022DB E8A4F8                  	call	print_msg
  6501                                  
  6502 000022DE 89FE                    	mov	si, di  ; partition table row address
  6503                                  
  6504 000022E0 C3                      	retn
  6505                                  
  6506                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6507                                  ; write byte as descimal number
  6508                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6509                                  
  6510                                  write_byte_decimal:
  6511                                  	; INPUT ->
  6512                                  	;	AL = binary number
  6513                                  	; OUTPUT ->
  6514                                  	;	DS:SI = decimal number text address
  6515                                  	;	        (ASCIIZ string)
  6516                                  	;
  6517                                  	; (SI, AX, CX will be modified)	
  6518                                  
  6519                                  	;mov	si, msg_partition_sectors + 8 ; max. 8 digits
  6520                                  	; 06/11/2020
  6521 000022E1 BE[906D]                	mov	si, msg_partition_sectors + 11 ; max. 11 digits
  6522 000022E4 B10A                    	mov	cl, 10
  6523                                  wbd_loop:
  6524 000022E6 4E                      	dec	si
  6525 000022E7 30E4                    	xor	ah, ah
  6526 000022E9 F6F1                    	div	cl
  6527 000022EB 80C430                  	add	ah, '0'
  6528 000022EE 8824                    	mov	[si], ah
  6529 000022F0 20C0                    	and	al, al
  6530 000022F2 75F2                    	jnz	short wbd_loop
  6531 000022F4 C3                      	retn
  6532                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6533                                  ; init (MBR) partition table
  6534                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6535                                  ; 16/10/2020
  6536                                  
  6537                                  	; 03/02/2019
  6538                                  init_partition_table:
  6539                                  
  6540                                  	; INPUT -> none
  6541                                  	; OUTPUT -> none
  6542                                  
  6543                                  	; 15/10/2020
  6544                                  	; (If a partition row contains invalid/wrong/defective parameters)
  6545                                  	; (it's active partition flag/byte will be 0FFh, an invalid value!)	 
  6546                                  
  6547                                  	; 12/02/2019	
  6548                                  	;cmp	word [MBIDCode], 0AA55h
  6549                                  	;jne	ipt_stc ; invalid
  6550                                  
  6551                                  	; 15/02/2019
  6552                                  	; clear primary partition table structure/list
  6553                                  
  6554 000022F5 BF[1870]                	mov	di, part_table_boot_ind
  6555 000022F8 B92400                  	mov	cx, 36 ; 18*4 = 72 bytes
  6556 000022FB 31C0                    	xor	ax, ax ; 0
  6557 000022FD F3AB                    	rep	stosw
  6558                                  
  6559 000022FF A3[6070]                	mov	[pcount], ax ; reset (pcount & ppcount)
  6560 00002302 A3[6270]                	mov	[apcount], ax ; reset (apcount & epnumber)
  6561                                  
  6562 00002305 BE[9857]                	mov	si, MasterBootBuff+446 ; Partition table offset
  6563                                  	;mov	cx, 4
  6564 00002308 B104                    	mov	cl, 4
  6565 0000230A 31FF                    	xor	di, di
  6566                                  ipt_0:
  6567 0000230C 8A6404                  	mov	ah, [si+ptFileSystemID]
  6568                                  
  6569 0000230F 20E4                    	and	ah, ah
  6570 00002311 0F841601                	jz	ipt_8 ; empty
  6571                                  
  6572 00002315 FE06[6070]              	inc	byte [pcount] ; partition count
  6573                                  
  6574 00002319 80FC01                  	cmp	ah, 1	; FAT12
  6575 0000231C 7442                    	je	short ipt_2
  6576 0000231E 80FC04                  	cmp	ah, 4	; FAT16
  6577 00002321 743D                    	je	short ipt_2
  6578 00002323 723F                    	jb	short ipt_3	
  6579 00002325 80FC06                  	cmp	ah, 6	; FAT16 big
  6580 00002328 7436                    	je	short ipt_2
  6581 0000232A 7715                    	ja	short ipt_1 ; EXTENDED
  6582                                  
  6583                                  	;cmp	ah, 5 ; EXTENDED
  6584                                  	;jne	short ipt_3
  6585                                  ipt_17:
  6586 0000232C 803E[6370]00            	cmp	byte [epnumber], 0
  6587                                  	;ja	short ipt_stc ; invalid  (more than 1 extended dos partition)
  6588 00002331 7605                    	jna	short ipt_15
  6589                                  	
  6590 00002333 C685[1870]FF            	mov	byte [part_table_boot_ind+di], 0FFh 
  6591                                  				; Invalid/Defective partition flag
  6592                                  ipt_15:	
  6593 00002338 B005                    	mov	al, 5
  6594 0000233A 28C8                    	sub	al, cl ; partition number 1 to 4
  6595 0000233C A2[6370]                	mov	byte [epnumber], al ; extended partition entry number (1 to 4)
  6596 0000233F EB23                    	jmp	short ipt_3
  6597                                  ipt_1:
  6598                                  	; 26/10/2020
  6599 00002341 80FC07                  	cmp	ah, 07h ; NTFS (Windows FS)
  6600 00002344 741A                    	je	short ipt_2 ; accept NTFS as primary dos partition
  6601                                  			    ; (then, extended partition can be created)	
  6602                                  	; 24/10/2020
  6603 00002346 80FC0C                  	cmp	ah, 0Ch ; FAT32 (LBA)
  6604 00002349 7415                    	je	short ipt_2
  6605 0000234B 7707                    	ja	short ipt_18
  6606                                  	; 16/10/2020
  6607 0000234D 80FC0B                  	cmp	ah, 0Bh ; FAT32 (CHS)
  6608                                  	;jne	short ipt_3
  6609                                  	; 24/10/2020
  6610 00002350 740E                    	je	short ipt_2
  6611 00002352 7210                    	jb	short ipt_3 ; non-dos partition (NTFS or unknown fs type)
  6612                                  ipt_18:
  6613 00002354 80FC0F                  	cmp	ah, 0Fh  ; EXTENDED (LBA)	
  6614 00002357 74D3                    	je	short ipt_17
  6615 00002359 7709                    	ja	short ipt_3 ; non-dos partition 
  6616                                  			    ; (xenix/unix/linux/singlix/runix or unknown)
  6617 0000235B 80FC0E                  	cmp	ah, 0Eh ; FAT16 (LBA)
  6618 0000235E 7504                    	jne	short ipt_3 ; 0Dh
  6619                                  	; FAT16 LBA (0Eh)
  6620                                  ipt_2:
  6621 00002360 FE06[6170]              	inc	byte [ppcount] ; primary dos partition count
  6622                                  ipt_3:
  6623 00002364 88A5[1D70]              	mov	[part_table_sys_id+di], ah  ; Partition Type (FS type)
  6624                                  	
  6625 00002368 8A04                    	mov	al, [si+ptBootable]
  6626                                  
  6627 0000236A 20C0                    	and	al, al
  6628 0000236C 7413                    	jz	short ipt_4
  6629                                  
  6630 0000236E 803E[6270]01            	cmp	byte [apcount], 1 ; check (previous) active partition count
  6631                                  	;jnb	short ipt_stc  ; invalid (if it is not zero here)
  6632 00002373 7304                    	jnb	short ipt_16
  6633                                  
  6634 00002375 3C80                    	cmp	al, 80h  ; active partition sign/flag?
  6635                                  	;jne	short ipt_stc  ; invalid flag
  6636 00002377 7404                    	je	short ipt_11
  6637                                  ipt_16:
  6638                                  	; 15/10/2020
  6639 00002379 B0FF                    	mov	al, 0FFh ; Invalid/Defective partition flag 
  6640 0000237B EB04                    	jmp	short ipt_4
  6641                                  ipt_11:
  6642 0000237D FE06[6270]              	inc	byte [apcount]  ; active partition count = 1
  6643                                  ipt_4:
  6644 00002381 8885[1870]              	mov	[part_table_boot_ind+di], al
  6645                                  
  6646                                  	;mov	al, [heads]
  6647                                  ;ipt_4_fix:
  6648                                  	;dec	al
  6649 00002385 8A6401                  	mov	ah, [si+ptBeginHead]
  6650                                  	;cmp	al, ah
  6651                                  	;;jb	short ipt_retn ; invalid
  6652                                  	;jb	ipt_heads_fix ; 10/02/2019
  6653 00002388 88A5[1970]              	mov	[part_table_start_head+di], ah
  6654 0000238C 8A6405                  	mov	ah, [si+ptEndHead]
  6655                                  	;cmp	al, ah
  6656                                  	;;jb	short ipt_retn ; invalid
  6657                                  	;jb	short ipt_heads_fix ; 10/02/2019
  6658 0000238F 88A5[1E70]              	mov	[part_table_end_head+di], ah
  6659                                  	;mov	al, [sectors]
  6660 00002393 8A7C02                  	mov	bh, [si+ptBeginSector]
  6661 00002396 88FC                    	mov	ah, bh
  6662 00002398 80E43F                  	and	ah, 3Fh ; 63
  6663                                  	;cmp	al, ah
  6664                                  	;jb	short ipt_retn ; invalid
  6665 0000239B 88A5[1A70]              	mov	[part_table_start_sector+di], ah
  6666 0000239F 8A7406                  	mov	dh, [si+ptEndSector]
  6667 000023A2 88F4                    	mov	ah, dh
  6668 000023A4 80E43F                  	and	ah, 3Fh ; 63
  6669                                  	;cmp	al, ah
  6670                                  	;jb	short ipt_retn ; invalid
  6671 000023A7 88A5[1F70]              	mov	[part_table_end_sector+di], ah
  6672 000023AB C0EF06                  	shr	bh, 6
  6673 000023AE 8A5C03                  	mov	bl, [si+ptBeginCylinder]
  6674                                  	;mov	ax, [cylinders]
  6675                                  	;dec	ax	
  6676                                  	;cmp	ax, bx
  6677                                  	;jb	short ipt_retn ; invalid
  6678 000023B1 899D[1B70]              	mov	[part_table_start_cyl+di], bx
  6679 000023B5 C0EE06                  	shr	dh, 6
  6680 000023B8 8A5407                  	mov	dl, [si+ptEndCylinder]
  6681                                  	;cmp	ax, dx
  6682                                  	;jb	short ipt_retn ; invalid
  6683 000023BB 8995[2070]              	mov	[part_table_end_cyl+di], dx
  6684                                  
  6685 000023BF 8B4408                  	mov	ax, [si+ptStartSector]
  6686 000023C2 8B540A                  	mov	dx, [si+ptStartSector+2]
  6687                                  
  6688 000023C5 8985[2270]              	mov	[part_table_rel_sec_lw+di], ax
  6689 000023C9 8995[2470]              	mov	[part_table_rel_sec_hw+di], dx
  6690                                  
  6691 000023CD 09D0                    	or	ax, dx
  6692                                  	;jz	short ipt_stc ; invalid (start sector must not be zero)
  6693 000023CF 7505                    	jnz	short ipt_12
  6694                                  	; 15/10/2020
  6695 000023D1 C685[1870]FF            	mov	byte [part_table_boot_ind+di], 0FFh 
  6696                                  				; Invalid/Defective partition flag
  6697                                  ipt_12:
  6698 000023D6 8B440C                  	mov	ax, [si+ptSectors]
  6699 000023D9 8B540E                  	mov	dx, [si+ptSectors+2]
  6700                                  
  6701 000023DC 89D3                    	mov	bx, dx
  6702 000023DE 09C3                    	or	bx, ax
  6703                                  	;jz	short ipt_stc	; invalid (zero size of partition)
  6704 000023E0 7505                    	jnz	short ipt_6 ; 10/02/2019
  6705                                  
  6706                                  	; 15/10/2020
  6707 000023E2 C685[1870]FF            	mov	byte [part_table_boot_ind+di], 0FFh 
  6708                                  				; Invalid/Defective partition flag
  6709                                  
  6710                                  	;cmp	dx, [total_sectors+2]
  6711                                  	;ja	short ipt_stc	; invalid (partition size > disk capacity)
  6712                                  	;jb	short ipt_6
  6713                                  	;;cmp	ax, [total_sectors] ; (ax + 1) <= total sectors
  6714                                  	;jb	short ipt_6
  6715                                  	
  6716                                  ;ipt_stc:
  6717                                  ;	; invalid MBR data
  6718                                  ;	;stc
  6719                                  ;ipt_retn:
  6720                                  ;	retn
  6721                                  
  6722                                  ;ipt_heads_fix:
  6723                                  	; 10/02/2019
  6724                                  	; AL = [heads] - 1
  6725                                  
  6726                                  	;test	byte [cylinders], 1
  6727                                  	;jnz	short ipt_stc ; odd cylinder count (can not be shifted)
  6728                                  	
  6729                                  	;inc	al ; = [heads]
  6730                                  	;cmp	al, 8
  6731                                  	;ja	short ipt_stc ; this fix is needed for <= 16 heads (& 17 spt)
  6732                                  	;shl	al, 1
  6733                                  	;mov	[heads], al ; heads = heads*2
  6734                                  	;shr	word [cylinders], 1 ; cylinders = cylinders/2
  6735                                  	;jmp	ipt_4_fix
  6736                                  
  6737                                  ipt_6:
  6738 000023E7 8985[2670]              	mov	[part_table_num_sec_lw+di], ax
  6739 000023EB 8995[2870]              	mov	[part_table_num_sec_hw+di], dx
  6740                                  
  6741 000023EF 0385[2270]              	add	ax, [part_table_rel_sec_lw+di]
  6742 000023F3 1395[2470]              	adc	dx, [part_table_rel_sec_hw+di]
  6743                                  	;jc	short ipt_retn  ; invalid
  6744                                  	; 27/10/2020
  6745 000023F7 720E                    	jc	short ipt_13
  6746                                  
  6747 000023F9 3B16[DC68]              	cmp	dx, [total_sectors+2]
  6748                                  	;ja	short ipt_stc	; invalid (partition end > disk capacity)
  6749 000023FD 720D                    	jb	short ipt_7
  6750                                  	; 27/10/2020
  6751 000023FF 7706                    	ja	short ipt_13
  6752 00002401 3B06[DA68]              	cmp	ax, [total_sectors] ; ax <= total sectors
  6753                                  	;ja	short ipt_stc	; invalid (partition end > disk capacity)
  6754 00002405 7605                    	jna	short ipt_7
  6755                                  ipt_13:
  6756                                  	; 15/10/2020
  6757 00002407 C685[1870]FF            	mov	byte [part_table_boot_ind+di], 0FFh 
  6758                                  				; Invalid/Defective partition flag 
  6759                                  ipt_7:
  6760                                  	; 27/10/2020
  6761 0000240C B8FE03                  	mov	ax, 1022 ; CHS cylinder number limit
  6762 0000240F 3985[1B70]              	cmp	[part_table_start_cyl+di], ax
  6763 00002413 7707                    	ja	short ipt_19 ; = 1023
  6764 00002415 40                      	inc	ax ; 1023
  6765 00002416 3985[2070]              	cmp	[part_table_end_cyl+di], ax
  6766 0000241A 7203                    	jb	short ipt_14  ; < 1023
  6767                                  ipt_19:
  6768                                  	; 27/10/2020
  6769                                  	; set cylinder number if the partition's start or end sector is
  6770                                  	; at the beyond of chs limit 
  6771                                  	; ax = 1022 -> set start cylinder
  6772                                  	; ax = 1023 -> set end cylinder
  6773 0000241C E82100                  	call	cylindernumberfix
  6774                                  ipt_14:
  6775 0000241F 83C610                  	add	si, 16
  6776 00002422 E201                    	loop	ipt_5
  6777                                  	
  6778                                  	; OK!
  6779                                  
  6780                                  	;clc
  6781 00002424 C3                      	retn
  6782                                  
  6783                                  ipt_5:
  6784 00002425 83C712                  	add	di, 18
  6785 00002428 E9E1FE                  	jmp	ipt_0
  6786                                  
  6787                                  ipt_8:
  6788                                  	; Empty partition table check (all of 16 bytes must be 0)
  6789 0000242B 51                      	push	cx
  6790 0000242C 56                      	push	si ; 16/10/2020
  6791 0000242D B108                    	mov	cl, 8
  6792                                  ipt_9:
  6793 0000242F AD                      	lodsw
  6794 00002430 09C0                    	or	ax, ax
  6795 00002432 7507                    	jnz	short ipt_10
  6796 00002434 E2F9                    	loop	ipt_9
  6797 00002436 59                      	pop	cx ; 16/10/2020  ; (discard si)
  6798 00002437 59                      	pop	cx
  6799 00002438 E2EB                    	loop	ipt_5
  6800                                  	
  6801                                  	;clc
  6802 0000243A C3                      	retn
  6803                                  ipt_10:
  6804                                  	;pop	cx
  6805                                  	; invalid
  6806                                  	;stc
  6807                                  	; 27/10/2020
  6808                                  	; 15/10/2020
  6809                                  	;mov	byte [part_table_boot_ind+di], 0FFh 
  6810                                  				; Invalid/Defective partition flag 
  6811                                  	;retn
  6812                                  	; 16/10/2020
  6813                                  	; 31/10/2020
  6814                                  	;mov	byte [part_table_sys_id+di], 0	; Empty partition
  6815 0000243B 5E                      	pop	si
  6816 0000243C 59                      	pop	cx
  6817 0000243D E939FF                  	jmp	ipt_16
  6818                                  
  6819                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6820                                  ; set cylinder number to partition's start or end sector 
  6821                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6822                                  ; 27/10/2020
  6823                                  
  6824                                  cylindernumberfix:
  6825                                  	; ax = 1022 -> set start cylinder
  6826                                  	; ax = 1023 -> set end cylinder
  6827                                  	; di = partition table structure offset
  6828                                  
  6829                                  	; modified registers: ax, dx, bx
  6830                                  	
  6831 00002440 3DFF03                  	cmp	ax, 1023
  6832 00002443 7343                    	jnb	short cnf_4 ; set end cylinder
  6833                                  	
  6834 00002445 80BD[1970]FE            	cmp	byte [part_table_start_head+di], 0FEh ; 254
  6835 0000244A 753C                    	jne	short cnf_4 ; no need to fix (start cyl) 
  6836                                  			; 30/10/2020
  6837                                  	; 28/10/2020
  6838 0000244C 80BD[1A70]3F            	cmp	byte [part_table_start_sector+di], 3Fh ; 63
  6839 00002451 7535                    	jne	short cnf_4 ; no need to fix (start cyl)
  6840                                  			; 30/10/2020
  6841                                  
  6842 00002453 8B85[2270]              	mov	ax, [part_table_rel_sec_lw+di] ; start sector, lw
  6843 00002457 8B95[2470]              	mov	dx, [part_table_rel_sec_hw+di] ; start sector, hw
  6844 0000245B 51                      	push	cx
  6845 0000245C 8B0E[986D]              	mov	cx, [hs] ; [heads*spt]
  6846 00002460 E81AE8                  	call	div32
  6847                                  		; dx:ax = cylinder number, dx = 0, quotient	
  6848                                  		; bx = remainder
  6849 00002463 59                      	pop	cx
  6850 00002464 09D2                    	or 	dx, dx
  6851 00002466 751A                    	jnz	short cnf_2 ; invalid
  6852 00002468 3B85[1B70]              	cmp	ax, [part_table_start_cyl+di]
  6853                                  	;je	short cnf_5
  6854 0000246C 7406                    	je	short cnf_1
  6855 0000246E 7212                    	jb	short cnf_2 ; invalid
  6856 00002470 8985[1B70]              	mov	[part_table_start_cyl+di], ax ; change it
  6857                                  	;jmp	short cnf_5 
  6858                                  cnf_1:
  6859 00002474 80BD[1E70]FE            	cmp	byte [part_table_end_head+di], 0FEh ; 254
  6860 00002479 7507                    	jne	short cnf_2 ; no need to fix (also invalid)
  6861                                  	
  6862                                  	; 28/10/2020
  6863 0000247B 80BD[1F70]3F            	cmp	byte [part_table_end_sector+di], 3Fh ; 63
  6864 00002480 7414                    	je	short cnf_5 ; fix
  6865                                  	; no need to fix (also invalid)
  6866                                  cnf_2:
  6867 00002482 C685[1870]FF            	mov	byte [part_table_boot_ind+di], 0FFh ; invalid PTE
  6868                                  cnf_3:
  6869 00002487 C3                      	retn
  6870                                  cnf_4:
  6871 00002488 80BD[1E70]FE            	cmp	byte [part_table_end_head+di], 0FEh ; 254
  6872 0000248D 75F8                    	jne	short cnf_3 ; no need to fix (end cyl)
  6873                                  	
  6874                                  	; 28/10/2020
  6875 0000248F 80BD[1F70]3F            	cmp	byte [part_table_end_sector+di], 3Fh ; 63
  6876 00002494 75F1                    	jne	short cnf_3 ; no need to fix (end cyl)
  6877                                  cnf_5:
  6878 00002496 8B85[2270]              	mov	ax, [part_table_rel_sec_lw+di] ; start sector, lw
  6879 0000249A 8B95[2470]              	mov	dx, [part_table_rel_sec_hw+di] ; start sector, hw
  6880                                  
  6881 0000249E 0385[2670]              	add	ax, [part_table_num_sec_lw+di] ; number of sectors, lw 
  6882 000024A2 1395[2870]              	adc	dx, [part_table_num_sec_hw+di] ; number of sectors, hw 
  6883                                  	;jc	short cnf_2
  6884                                  
  6885 000024A6 83E801                  	sub	ax, 1
  6886 000024A9 83DA00                  	sbb	dx, 0	
  6887                                  		; dx:ax = end sector
  6888 000024AC 51                      	push	cx
  6889 000024AD 8B0E[986D]              	mov	cx, [hs] ; [heads*spt]
  6890 000024B1 E8C9E7                  	call	div32
  6891                                  		; dx:ax = cylinder number, dx = 0, quotient	
  6892                                  		; bx = remainder
  6893 000024B4 59                      	pop	cx
  6894 000024B5 09D2                    	or 	dx, dx
  6895 000024B7 75C9                    	jnz	short cnf_2 ; invalid
  6896 000024B9 3B85[2070]              	cmp	ax, [part_table_end_cyl+di]
  6897 000024BD 74C8                    	je	short cnf_3 ; same cylinder number
  6898 000024BF 72C1                    	jb	short cnf_2 ; invalid
  6899 000024C1 8985[2070]              	mov	[part_table_end_cyl+di], ax ; change it
  6900 000024C5 C3                      	retn
  6901                                  
  6902                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6903                                  ; sort partition table in (ending) cylinder number order
  6904                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6905                                  ; 25/10/2020 (fdisk3.s)
  6906                                  
  6907                                  	; 02/02/2019 (hdimage.s)
  6908                                  	
  6909                                  sort_partition_table:
  6910                                  
  6911                                  	; INPUT -> none
  6912                                  	; OUTPUT -> none
  6913                                  
  6914 000024C6 31DB                    	xor	bx, bx
  6915                                  	;jmp	short sortpt_2 ; 25/10/2020
  6916                                  sortpt_1:
  6917 000024C8 889F[A86D]              	mov	[bx+sort], bl ; 0	
  6918 000024CC FEC3                    	inc	bl
  6919                                  sortpt_2:
  6920 000024CE 80FB04                  	cmp	bl, 4 ; number of partition table entries to sort
  6921 000024D1 72F5                    	jb	short sortpt_1
  6922                                  
  6923                                  	; Do a bubble sort
  6924                                  
  6925 000024D3 EB04                    	jmp	short sortpt_4
  6926                                  sortpt_3:
  6927                                  	; Sort until we don't do a swap
  6928                                  
  6929 000024D5 08C9                    	or	cl, cl ; sort changed ?
  6930 000024D7 7450                    	jz	short sortpt_8 ; no
  6931                                  sortpt_4:
  6932 000024D9 30C9                    	xor	cl, cl
  6933                                  
  6934 000024DB B301                    	mov	bl, 1
  6935                                  
  6936 000024DD B212                    	mov	dl, 18  ; partition table structure size
  6937 000024DF EB07                    	jmp	short sortpt_6
  6938                                  sortpt_5:
  6939 000024E1 FEC3                    	inc	bl
  6940                                  
  6941 000024E3 80FB04                  	cmp	bl, 4
  6942 000024E6 73ED                    	jnb	short sortpt_3
  6943                                  
  6944                                  sortpt_6:
  6945 000024E8 8A87[A86D]              	mov	al, [bx+sort]
  6946                                  
  6947 000024EC F6E2                    	mul	dl
  6948                                  
  6949 000024EE 89C6                    	mov	si, ax
  6950                                  
  6951 000024F0 8BBC[2070]              	mov	di, [part_table_end_cyl+si]
  6952                                  
  6953 000024F4 8A87[A76D]              	mov	al, [bx+sort-1]
  6954                                  
  6955 000024F8 F6E2                    	mul	dl ; * 18
  6956                                  
  6957 000024FA 97                      	xchg	di, ax
  6958                                  
  6959 000024FB 3985[2070]              	cmp	[part_table_end_cyl+di], ax ; previous > current
  6960 000024FF 771A                    	ja	short sortpt_7 ; swap order indicators
  6961                                  		; 31/10/2020
  6962                                  		; current end cyl >= previous end cyl
  6963                                  	; 31/10/2020
  6964 00002501 72DE                    	jb	short sortpt_5  
  6965                                  		; current end cyl > previous end cyl
  6966                                  	
  6967 00002503 21C0                    	and	ax, ax ; cylinder 0 ?
  6968 00002505 75DA                    	jnz	short sortpt_5 ; no
  6969                                  		; current end cyl = previous end cyl, cyl > 0
  6970                                  	
  6971                                  	; current end cyl = previous end cyl = 0	
  6972                                  
  6973                                  	; If current entry is empty partition entry
  6974                                  	; and previous entry is not empty partition entry
  6975                                  	; swap them.
  6976                                  	;
  6977 00002507 8B85[2870]              	mov	ax, [part_table_num_sec_hw+di] ; previous entry
  6978 0000250B 0B85[2670]              	or	ax, [part_table_num_sec_lw+di]
  6979 0000250F 74D0                    	jz	short sortpt_5
  6980                                  
  6981 00002511 8B84[2870]              	mov	ax, [part_table_num_sec_hw+si] ; current entry
  6982 00002515 0B84[2670]              	or	ax, [part_table_num_sec_lw+si]
  6983 00002519 75C6                    	jnz	short sortpt_5
  6984                                  sortpt_7:
  6985                                  	; Swap the order indicators
  6986                                  
  6987 0000251B 8B87[A76D]              	mov	ax, [bx+sort-1]
  6988 0000251F 86E0                    	xchg	ah, al
  6989 00002521 8987[A76D]              	mov	[bx+sort-1], ax
  6990                                  
  6991 00002525 B101                    	mov	cl, 1 ; sort changed
  6992 00002527 EBB8                    	jmp	short sortpt_5
  6993                                  
  6994                                  sortpt_8:
  6995                                  	; 30/10/2020
  6996                                  	;mov 	byte [p_sorted], 1 ; 04/02/2019
  6997                                  
  6998 00002529 C3                      	retn
  6999                                  
  7000                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7001                                  ; find free space before/after/between partitions
  7002                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7003                                  ; 03/02/2019
  7004                                  
  7005                                  find_part_free_space:  ; find/calculate free space for partitions
  7006                                  	; 15/02/2019
  7007                                  
  7008                                  	; INPUT -> 
  7009                                  	;	AL = 0 -> calculate for primary/MBR partitions 
  7010                                  	;	AL = 5 -> calculate for extended partition
  7011                                  	; OUTPUT ->
  7012                                  	;	CX = the largest free space/cylinders (between partitions)
  7013                                  	;	AX = Free space index (gap number) - from 0 to 4 -
  7014                                  	;	BX = Free space structure offset (for the largest free space)
  7015                                  	;
  7016                                  	;	22/02/2019
  7017                                  	;	[freespace_count] = number of free spaces/gaps
  7018                                  
  7019 0000252A A2[C36F]                	mov	[p_type], al
  7020                                  
  7021                                  	; Sort the partition table
  7022                                  
  7023 0000252D E896FF                  	call	sort_partition_table ; 16/02/2019
  7024                                  
  7025                                  	; Initialize free space to zero
  7026                                  
  7027                                  	; 15/02/2019
  7028 00002530 BF[AC70]                	mov	di, fspc ; free_space.space
  7029 00002533 B92800                  	mov	cx, 5*8 ; (5*16/2)
  7030 00002536 31C0                    	xor	ax, ax ; 0
  7031 00002538 F3AB                    	rep	stosw
  7032                                  
  7033 0000253A A2[C06F]                	mov	[freespace_count], al ; 0
  7034                                  	; 22/02/2019
  7035                                  	;mov	[last_found_partition], al ; 0
  7036                                  
  7037 0000253D A3[BE6F]                	mov	[_i_], ax ; 0
  7038                                  	;jmp	short fpfs_2
  7039                                  	; 31/10/020
  7040 00002540 EB0E                    	jmp	short fpfs_3
  7041                                  fpfs_1:	
  7042 00002542 FE06[BE6F]              	inc	byte [_i_]
  7043                                  ;;fpfs_2:
  7044 00002546 803E[BE6F]04            	cmp	byte [_i_], 4
  7045 0000254B 7203                    	jb	short fpfs_3
  7046 0000254D E97601                  	jmp	fpfs_13
  7047                                  fpfs_3:
  7048                                  	; Find space between start of disk and first partition
  7049                                  
  7050                                  	;mov	ax, [_i_]
  7051 00002550 8B1E[BE6F]              	mov	bx, [_i_] ; 31/10/2020
  7052                                  fpfs_2:
  7053                                  	;mov	bx, ax ; 31/10/2020
  7054                                  	;mov	al, [sort+bx]
  7055 00002554 8A8F[A86D]              	mov	cl, [sort+bx] ; 15/02/2019
  7056                                  
  7057                                  	;mov	cl, 18 ; partition table structure size = 18 bytes
  7058 00002558 B012                    	mov	al, 18 ; 15/02/2019
  7059 0000255A F6E1                    	mul	cl
  7060 0000255C 89C3                    	mov	bx, ax
  7061                                  
  7062 0000255E 80BF[1D70]00            	cmp	byte [part_table_sys_id+bx], 0
  7063 00002563 74DD                    	je	short fpfs_1
  7064                                  
  7065 00002565 880E[C26F]              	mov	[last_found_partition], cl ; 15/02/2019
  7066                                  
  7067                                  	;xor	cx, cx
  7068 00002569 30C9                    	xor	cl, cl ; 0 	
  7069                                  	;mov	al, 1 ; LBA = 1 (after MBR) ; ah = 0
  7070                                  	; 03/11/2020
  7071 0000256B A0[6E3F]                	mov	al, [sectors] ; 63 or 17 ; 03/11/2020	
  7072                                  
  7073 0000256E 803E[C36F]05            	cmp	byte [p_type], 5  ; EXTENDED
  7074 00002573 7506                    	jne	short fpfs_4
  7075                                  
  7076                                  	; This is a special case - the extended partition can not start
  7077                                  	; on cylinder 0 due to its architecture. Protect against that here
  7078                                  
  7079                                  	; 13/02/2019
  7080                                  	; LBA value of free space start
  7081                                  	;mov	al, [sectors] ; 03/11/2020
  7082 00002575 F626[703F]              	mul	byte [heads]
  7083                                  		; ax = start sector (for Extended Partition)
  7084 00002579 FEC1                    	inc	cl ; 1  ; cx = start cylinder = 1
  7085                                  fpfs_4:
  7086                                  	; Found a partition, get the space
  7087                                  
  7088                                  	; 15/02/2019
  7089 0000257B 8B97[1B70]              	mov	dx, [part_table_start_cyl+bx] 
  7090                                  		       ; Start cylinder of the 1st partition (as sorted)
  7091 0000257F 39CA                    	cmp	dx, cx ; (cx=0 for primary partition, cx=1 for extd partition)
  7092 00002581 0F86C300                	jna	fpfs_9 ; It is accepted as free (partition) space
  7093                                  		       ; if this space between masterboot sector and partition 1
  7094                                  		       ; has 1 cylinder (heads*spt) size at least.
  7095                                  	; 22/02/2019
  7096 00002585 31FF                    	xor	di, di  ; 0 ; Reset Free Space Table offset
  7097                                  
  7098 00002587 FE06[C06F]              	inc	byte [freespace_count]	; mov byte [freespace_count], 1
  7099                                  
  7100 0000258B 890E[AE70]              	mov	[free_space.start], cx ; 0 (for PP) or 1 (for EP)
  7101                                  	
  7102                                  	; non-aligned address of start sector (for the 1st partition as sorted)
  7103                                  	; NOTE: later, start sector will be moved to (chs) head 1 and sector 1
  7104                                  	;	if new partition will be selected as a primary dos partition.
  7105                                  	;	(But, start sector -LBA- will not be changed 
  7106                                  	;	 if it is a non-dos or user input type partition.. unless
  7107                                  	;	 cylinder boundary alignment option is used.)
  7108                                  	 	
  7109 0000258F A3[B870]                	mov	[free_space.startsector], ax ; = [sectors]*[heads] (for EP)
  7110                                  					     ; or 1 (for PP)
  7111                                  	;mov	[free_space.startsector+2], 0
  7112                                  
  7113                                  	; free space ends before start of next valid partition
  7114 00002592 89D0                    	mov	ax, dx	; start cylinder of partition 1 (as sorted)
  7115 00002594 29CA                    	sub	dx, cx	; cylinder count of free space 1 (gap 1)
  7116 00002596 48                      	dec	ax	; end cylinder of free space 1 (gap 1)
  7117 00002597 A3[B070]                	mov	[free_space.end], ax 
  7118 0000259A 8916[AC70]              	mov	[free_space.space], dx
  7119                                  
  7120                                  	; save free space (1) as (non-aligned) sector count
  7121 0000259E 8B87[2270]              	mov	ax, [part_table_rel_sec_lw+bx]
  7122 000025A2 8B97[2470]              	mov	dx, [part_table_rel_sec_hw+bx]
  7123 000025A6 2B06[B870]              	sub	ax, [free_space.startsector]
  7124 000025AA 83DA00                  	sbb	dx, 0
  7125 000025AD A3[B470]                	mov	[free_space.sectors_unused], ax
  7126 000025B0 8916[B670]              	mov	[free_space.sectors_unused+2], dx
  7127                                  
  7128                                  	;mov	ax, [free_space.space]
  7129                                  
  7130                                  	;call	cylinders_to_sectors
  7131                                  
  7132                                  	;mov	[free_space.sectors_unused], ax
  7133                                  	;mov	[free_space.sectors_unused+2], dx
  7134                                  
  7135 000025B4 8B0E[723F]              	mov	cx, [cylinders]		; Total (disk) cylinders -divisor-
  7136 000025B8 8B1E[AC70]              	mov	bx, [free_space.space]	; Partition cylinders -dividend-
  7137                                  
  7138 000025BC E8F801                  	call	cylinders_to_percent
  7139                                  
  7140 000025BF A3[B270]                	mov	[free_space.percent_unused], ax
  7141                                  
  7142                                  	; 15/02/2019
  7143                                  	;mov	bl, [_i_]
  7144                                  	;xor	bh, bh
  7145                                  	;mov	al, [sort+bx]
  7146                                  
  7147                                  	;mov	[last_found_partition], al
  7148                                  
  7149                                  	; 31/10/2020
  7150 000025C2 E98300                  	jmp	fpfs_9
  7151                                  
  7152                                  	; Look for space between the rest of the partitions
  7153                                  
  7154                                  fpfs_7:
  7155                                  	; ah = 0
  7156                                  	;mov	al, [_i_]
  7157                                  	;;cbw
  7158                                  	;mov	bx, ax
  7159                                  	; 22/02/2019
  7160 000025C5 8B1E[BE6F]              	mov	bx, [_i_]
  7161                                  
  7162                                  	; 15/02/2019
  7163                                  	;mov	al, [sort+bx]
  7164 000025C9 8A8F[A86D]              	mov	cl, [sort+bx]
  7165                                  	;mov	bl, 18
  7166                                  	;mul	bl
  7167 000025CD B012                    	mov	al, 18
  7168 000025CF F6E1                    	mul	cl
  7169 000025D1 89C6                    	mov	si, ax
  7170                                  	
  7171 000025D3 80BC[1D70]00            	cmp	byte [part_table_sys_id+si], 0
  7172 000025D8 746E                    	je	short fpfs_9
  7173                                  
  7174                                  	; 15/02/2019
  7175 000025DA 860E[C26F]              	xchg	[last_found_partition], cl
  7176                                  
  7177                                  	; Check to see if more than one partition on a cylinder
  7178                                  	; If so, leave the space at zero */
  7179                                  
  7180                                  	; NOTE:
  7181                                  	; It is accepted as valid free (partition) space
  7182                                  	; if free space (gap) between partitions
  7183                                  	; has 1 cylinder (heads*spt) size at least.
  7184                                  
  7185 000025DE B012                    	mov	al, 18 ; Partition tables/data structure size = 18 bytes
  7186 000025E0 F6E1                    	mul	cl
  7187 000025E2 89C3                    	mov	bx, ax  ; ah = 0
  7188                                  
  7189 000025E4 8B97[2070]              	mov	dx, [part_table_end_cyl+bx]   ; end cyl. of previous partition 
  7190 000025E8 8B84[1B70]              	mov	ax, [part_table_start_cyl+si] ; start cyl. of current partition
  7191                                  
  7192 000025EC 42                      	inc	dx  ; start cylinder of free space is after the end cylinder of
  7193                                  		    ; the previous partition (as sorted)
  7194                                  
  7195 000025ED 39D0                    	cmp	ax, dx ; and it must be before than the next partition (as sorted)
  7196 000025EF 7657                    	jna	short fpfs_9 ; je short fpfs_9
  7197                                  		
  7198                                  	; No, things are normal
  7199                                  	; Get space between the end of the last one and the start of the next one
  7200                                  
  7201                                  	; 22/02/2019
  7202                                  	;add	di, 16
  7203 000025F1 8B3E[C06F]              	mov	di, [freespace_count] 
  7204 000025F5 C1E704                  	shl	di, 4	; * 16 ; next entry offset (in free space table)
  7205                                  
  7206 000025F8 FE06[C06F]              	inc	byte [freespace_count]
  7207                                  
  7208 000025FC 89C1                    	mov	cx, ax
  7209 000025FE 29D1                    	sub	cx, dx
  7210 00002600 48                      	dec	ax
  7211 00002601 8995[AE70]              	mov	[free_space.start+di], dx
  7212 00002605 8985[B070]              	mov	[free_space.end+di], ax
  7213 00002609 898D[AC70]              	mov	[free_space.space+di], cx
  7214                                  
  7215                                  	;mov	ax, [free_space.space+di]
  7216                                  	;call	cylinders_to_sectors
  7217                                  	;mov	[free_space.sectors_unused+di], ax
  7218                                  	;mov	[free_space.sectors_unused+2+di], dx
  7219                                  
  7220                                  	; calculate and save (non-aligned) free sector count between partitions
  7221                                  
  7222 0000260D 8B87[2270]              	mov	ax, [part_table_rel_sec_lw+bx]
  7223 00002611 8B97[2470]              	mov	dx, [part_table_rel_sec_hw+bx]
  7224 00002615 0387[2670]              	add	ax, [part_table_num_sec_lw+bx]
  7225 00002619 1397[2870]              	adc	dx, [part_table_num_sec_hw+bx]
  7226                                  
  7227 0000261D 8B8C[2270]              	mov	cx, [part_table_rel_sec_lw+si]
  7228 00002621 8B9C[2470]              	mov	bx, [part_table_rel_sec_hw+si]
  7229                                  
  7230 00002625 8985[B870]              	mov	[free_space.startsector+di], ax
  7231 00002629 8995[BA70]              	mov	[free_space.startsector+2+di], dx
  7232                                  
  7233 0000262D 29C1                    	sub	cx, ax
  7234 0000262F 19D3                    	sbb	bx, dx
  7235                                  
  7236 00002631 898D[B470]              	mov	[free_space.sectors_unused+di], cx
  7237 00002635 899D[B670]              	mov	[free_space.sectors_unused+2+di], bx
  7238                                  
  7239                                  fpfs_8:
  7240                                  	; NOTE: Percentage is based on cylinder-boundary aligned partition size.
  7241                                  	; (total disk cylinders and partition's cylinder count are used for that)
  7242                                  
  7243 00002639 8B0E[723F]              	mov	cx, [cylinders] ; -divisor-
  7244 0000263D 8B9D[AC70]              	mov	bx, [free_space.space+di] ; -dividend-
  7245 00002641 E87301                  	call	cylinders_to_percent
  7246                                  	
  7247 00002644 8985[B270]              	mov	[free_space.percent_unused+di], ax 
  7248                                  	
  7249                                  	; ah = 0
  7250                                  
  7251                                  	; 15/02/2019
  7252                                  	;mov	bl, [_i_]
  7253                                  	;xor	bh, bh
  7254                                  	;mov	al, [sort+bx]
  7255                                  	;	
  7256                                  	;mov	[last_found_partition], al
  7257                                  
  7258                                  fpfs_9:
  7259 00002648 FE06[BE6F]              	inc	byte [_i_]
  7260                                  fpfs_10:
  7261 0000264C 803E[BE6F]04            	cmp	byte [_i_], 4
  7262 00002651 7303                    	jnb	short fpfs_11
  7263                                  
  7264 00002653 E96FFF                  	jmp	fpfs_7
  7265                                  
  7266                                  fpfs_11:
  7267                                  	; Find the space between the last partition and the end of the disk
  7268                                  	; Make sure that freespace cannot become negative
  7269                                  
  7270 00002656 A0[C26F]                	mov	al, [last_found_partition]
  7271 00002659 B112                    	mov	cl, 18  ; Partition table structure size = 18 bytes
  7272 0000265B F6E1                    	mul	cl
  7273 0000265D 89C3                    	mov	bx, ax
  7274 0000265F 8B0E[723F]              	mov	cx, [cylinders]
  7275 00002663 49                      	dec	cx ; 15/02/2019 
  7276                                  		   ; (min. cylinder count = 1 for a valid/usable free space)
  7277 00002664 8B87[2070]              	mov	ax, [part_table_end_cyl+bx]
  7278                                  	;cmp	[part_table_end_cyl+bx], cx
  7279 00002668 39C8                    	cmp	ax, cx	; cx = end cylinder of the disk
  7280 0000266A 7203                    	jb	short fpfs_12
  7281 0000266C E9A400                  	jmp	fpfs_15
  7282                                  fpfs_12:
  7283                                  	; 22/02/2019
  7284 0000266F 8B3E[C06F]              	mov	di, [freespace_count]
  7285 00002673 C1E704                  	shl	di, 4 ; * 16  ; next entry offset (in free space table)
  7286                                  
  7287 00002676 FE06[C06F]              	inc	byte [freespace_count]
  7288                                  
  7289 0000267A 898D[B070]              	mov	[free_space.end+di], cx	; end cyl. of free space 5 (gap 5) 
  7290                                  	;mov	ax, [part_table_end_cyl+bx]
  7291                                  	
  7292                                  	;mov	dx, cx
  7293                                  	;sub	dx, ax
  7294                                  	;mov	[free_space.space+di], dx ; di = 4*16
  7295                                  	; 12/03/2021
  7296                                  	; ax = end cylinder of the last partition
  7297                                  	; cx = end cylinder of the disk
  7298 0000267E 29C1                    	sub	cx, ax
  7299 00002680 898D[AC70]              	mov	[free_space.space+di], cx ; di = 4*16
  7300                                  
  7301 00002684 40                      	inc	ax
  7302 00002685 8985[AE70]              	mov	[free_space.start+di], ax
  7303                                  	
  7304                                  	;inc	cx ; [cylinders]
  7305                                  	;mov	ax, [free_space.space+si]
  7306                                  	;call	cylinders_to_sectors
  7307                                  	;mov	[free_space.sectors_unused+di], ax
  7308                                  	;mov	[free_space.sectors_unused+2+di], dx
  7309                                  
  7310                                  	; calculate and save (non-aligned) free sector count
  7311                                  
  7312                                  	; 22/02/2019
  7313 00002689 8B87[2270]              	mov	ax, [part_table_rel_sec_lw+bx]
  7314 0000268D 8B97[2470]              	mov	dx, [part_table_rel_sec_hw+bx]
  7315 00002691 0387[2670]              	add	ax, [part_table_num_sec_lw+bx]
  7316 00002695 1397[2870]              	adc	dx, [part_table_num_sec_hw+bx]
  7317                                  
  7318 00002699 8985[B870]              	mov	[free_space.startsector+di], ax
  7319 0000269D 8995[BA70]              	mov	[free_space.startsector+2+di], dx
  7320                                  
  7321 000026A1 8B0E[DA68]              	mov	cx, [total_sectors]
  7322 000026A5 8B1E[DC68]              	mov	bx, [total_sectors+2]
  7323 000026A9 29C1                    	sub	cx, ax
  7324 000026AB 19D3                    	sbb	bx, dx
  7325 000026AD 898D[B470]              	mov	[free_space.sectors_unused+di], cx
  7326 000026B1 899D[B670]              	mov	[free_space.sectors_unused+2+di], bx
  7327                                  
  7328 000026B5 8B0E[723F]              	mov	cx, [cylinders]
  7329 000026B9 8B9D[AC70]              	mov	bx, [free_space.space+di]
  7330 000026BD E8F700                  	call	cylinders_to_percent
  7331 000026C0 8985[B270]              	mov	[free_space.percent_unused+di], ax
  7332 000026C4 EB4D                    	jmp	short fpfs_15
  7333                                  
  7334                                  fpfs_13:
  7335                                  	; No partitions found, show entire space as free
  7336                                  
  7337                                  	; 22/02/2019
  7338 000026C6 FE06[C06F]              	inc	byte [freespace_count]	; mov byte [freespace_count], 1
  7339                                  	
  7340                                  	; 15/02/2019
  7341                                  	;sub	ax, ax
  7342                                  	; ah = 0 ; 31/10/2020
  7343 000026CA 29D2                    	sub	dx, dx
  7344                                  
  7345                                  	;inc	al ; LBA = 1 (after MBR) ; ah = 0
  7346 000026CC B001                    	mov	al, 1 ; 25/02/2019
  7347                                  
  7348                                  	;This is a special case - the extended partition can not start
  7349                                  	;on cylinder 0 due to its architecture. Protect against that here
  7350                                  
  7351 000026CE 803E[C36F]05            	cmp	byte [p_type], 5 ; EXTENDED
  7352 000026D3 7509                    	jne	short fpfs_14
  7353                                  		
  7354 000026D5 FEC2                    	inc	dl
  7355                                  
  7356                                  	; 15/02/2019
  7357                                  	; LBA value of free space start
  7358 000026D7 A0[6E3F]                	mov	al, [sectors]
  7359 000026DA F626[703F]              	mul	byte [heads]
  7360                                  		; ax = start sector (for Extended Partition)
  7361                                  fpfs_14:
  7362 000026DE 8916[AE70]              	mov	[free_space.start], dx ; 0 or 1
  7363                                  
  7364                                  	; non-aligned address of start sector (for the 1st partition as sorted)
  7365                                  	; NOTE: later, start sector will be moved to (chs) head 1 and sector 1
  7366                                  	;	if new partition will be selected as a primary dos partition.
  7367                                  	 	
  7368 000026E2 A3[B870]                	mov	[free_space.startsector], ax ; = [sectors]*[heads] (for EP)
  7369                                  					     ; or 1 (for PP)
  7370                                  	;mov	[free_space.startsector+2], 0
  7371                                  
  7372 000026E5 A1[723F]                	mov	ax, [cylinders] ; disk capacity 
  7373 000026E8 89C1                    	mov	cx, ax
  7374 000026EA 48                      	dec	ax
  7375 000026EB A3[B070]                	mov	[free_space.end], ax
  7376 000026EE 29D0                    	sub	ax, dx
  7377 000026F0 40                      	inc	ax
  7378 000026F1 A3[AC70]                	mov	[free_space.space], ax
  7379                                  
  7380 000026F4 A1[DA68]                	mov	ax, [total_sectors]
  7381 000026F7 8B16[DC68]              	mov	dx, [total_sectors+2]
  7382 000026FB 2B06[B870]              	sub	ax, [free_space.startsector]
  7383 000026FF 83DA00                  	sbb	dx, 0
  7384 00002702 A3[B470]                	mov	[free_space.sectors_unused], ax
  7385 00002705 8916[B670]              	mov	[free_space.sectors_unused+2], dx
  7386                                  
  7387                                  	;mov	cx, [cylinders] 
  7388 00002709 8B1E[AC70]              	mov	bx, [free_space.space]
  7389 0000270D E8A700                  	call	cylinders_to_percent
  7390 00002710 A3[B270]                	mov	[free_space.percent_unused], ax
  7391                                  
  7392                                  fpfs_15:
  7393                                  	; Find largest free space
  7394 00002713 29C9                    	sub	cx, cx
  7395                                  	; 22/02/2019
  7396 00002715 29C0                    	sub	ax, ax
  7397 00002717 31DB                    	xor	bx, bx
  7398 00002719 8A16[C06F]              	mov	dl, [freespace_count]
  7399 0000271D 08D2                    	or	dl, dl
  7400 0000271F 7420                    	jz	short fpfs_19
  7401 00002721 8816[BE6F]              	mov	[_i_], dl
  7402                                  fpfs_16:
  7403 00002725 8B97[AC70]              	mov	dx, [free_space.space+bx] 
  7404 00002729 39CA                    	cmp	dx, cx
  7405 0000272B 7604                    	jbe	short fpfs_17
  7406                                  	; 22/02/2019
  7407 0000272D 89D1                    	mov	cx, dx ; Largest free space
  7408 0000272F 89D8                    	mov	ax, bx
  7409                                  fpfs_17:
  7410 00002731 FE0E[BE6F]              	dec	byte [_i_]
  7411 00002735 7405                    	jz	short fpfs_18
  7412                                  
  7413 00002737 83C310                  	add	bx, 16 ; Free space structure size
  7414 0000273A EBE9                    	jmp	short fpfs_16
  7415                                  fpfs_18:
  7416                                  	; 22/02/2019
  7417 0000273C 89C3                    	mov	bx, ax ; offset (from 0 to 64)
  7418 0000273E C0E804                  	shr	al, 4  ; index (from 0 to 4)
  7419                                  fpfs_19:
  7420 00002741 C3                      	retn
  7421                                  
  7422                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7423                                  ; find enough free space
  7424                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7425                                  
  7426                                  ;	; 15/02/2019
  7427                                  ;find_enough_free_space:
  7428                                  ;	; Find enough free space
  7429                                  ;	;
  7430                                  ;	; INPUT:
  7431                                  ;	;	AX = Requested space (in cylinders)
  7432                                  ;	;	22/02/2019
  7433                                  ;	;	[freespace_count] = number of free spaces/gaps
  7434                                  ;	; OUTPUT:
  7435                                  ;	;	AX = Available space
  7436                                  	;	DX = Requested space
  7437                                  ;	;	If CF = 0 -> AX >= DX
  7438                                  ;	;	If CF = 1 -> AX < DX
  7439                                  ;	;	CX = Index of available space in free space structure
  7440                                  ;	;	     (GAP number, 0 to 4) - if AX > 0 -	
  7441                                  ;
  7442                                  ;	mov	dx, ax ; 22/02/2019
  7443                                  ;	sub	ax, ax
  7444                                  ;	xor	bx, bx
  7445                                  ;	; 22/02/2019
  7446                                  ;	mov	ch, [freespace_count]
  7447                                  ;	mov	[_i_], ax ; 0
  7448                                  ;	jmp	short fefs_1
  7449                                  ;fefs_0:
  7450                                  ;	;mov	al, 16
  7451                                  ;	;mul	byte [_i_]
  7452                                  ;	;mov	bx, ax
  7453                                  ;	mov	bl, [_i_]
  7454                                  ;	shl	bl, 4 ; * 16
  7455                                  ;fefs_1:
  7456                                  ;	mov	ax, [free_space.space+bx]
  7457                                  ;	and	ax, ax
  7458                                  ;	jz	short fefs_2 ; not a free space
  7459                                  ;	mov	cl, [_i_] 
  7460                                  ;	cmp	ax, dx
  7461                                  ;	jnb	short fefs_3 ; enough space
  7462                                  ;fefs_2:
  7463                                  ;	; 22/02/2019
  7464                                  ;	inc	byte [_i_]
  7465                                  ;	cmp	byte [_i_], ch	
  7466                                  ;	jb	short fefs_0
  7467                                  ;	sub	ch, ch
  7468                                  ;	stc
  7469                                  ;	retn
  7470                                  ;fefs_3:
  7471                                  ;	xor	ch, ch
  7472                                  ;	retn
  7473                                  
  7474                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7475                                  ; find enough free sectors
  7476                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7477                                  
  7478                                  	; 15/02/2019
  7479                                  find_enough_free_sectors:
  7480                                  	; Find (first) enough free space in sectors
  7481                                  	;
  7482                                  	; INPUT:
  7483                                  	;	DX:AX = Requested space (as non-aligned free sectors)
  7484                                  	;	22/02/2019
  7485                                  	;	[freespace_count] = number of free spaces/gaps
  7486                                  	; OUTPUT:
  7487                                  	;	DX:AX = Available space
  7488                                  	;	If CF = 0 -> DX:AX >= Request
  7489                                  	;	If CF = 1 -> DX:AX < Request
  7490                                  	;	CX = Index of available space in free space structure
  7491                                  	;	     (GAP number, 0 to 4) - if DX:AX > 0 -
  7492                                  
  7493 00002742 31FF                    	xor	di, di
  7494 00002744 31F6                    	xor	si, si
  7495 00002746 31DB                    	xor	bx, bx
  7496                                  	; 22/02/2019
  7497 00002748 8A2E[C06F]              	mov	ch, [freespace_count]
  7498 0000274C 891E[BE6F]              	mov	[_i_], bx ; 0
  7499 00002750 EB07                    	jmp	short fefss_1
  7500                                  fefss_0:
  7501                                  	;mov	al, 16
  7502                                  	;mul	byte [_i_]
  7503                                  	;mov	bx, ax
  7504 00002752 8B1E[BE6F]              	mov	bx, [_i_]
  7505 00002756 C0E304                  	shl	bl, 4 ; * 16
  7506                                  fefss_1:
  7507 00002759 81C3[B470]              	add	bx, free_space.sectors_unused
  7508 0000275D 3B5702                  	cmp	dx, [bx+2]
  7509 00002760 7230                    	jb	short fefss_7
  7510 00002762 7706                    	ja	short fefss_2
  7511 00002764 3B07                    	cmp	ax, [bx]
  7512 00002766 742F                    	je	short fefss_8
  7513 00002768 7228                    	jb	short fefss_7 ; 18/02/2019
  7514                                  fefss_2:
  7515                                  	; 30/10/2020
  7516                                  	;cmp	word [bx], 0
  7517                                  	;jne	short fefss_3
  7518                                  	;cmp	word [bx+2], 0
  7519                                  	;je	short fefss_6	
  7520                                  fefss_3:
  7521 0000276A 3B7F02                  	cmp	di, [bx+2]
  7522 0000276D 7711                    	ja	short fefss_6
  7523 0000276F 7405                    	je	short fefss_4
  7524 00002771 8B7F02                  	mov	di, [bx+2]
  7525 00002774 EB04                    	jmp	short fefss_5
  7526                                  fefss_4:
  7527 00002776 3B37                    	cmp	si, [bx]
  7528 00002778 7306                    	jnb	short fefss_6
  7529                                  fefss_5:
  7530 0000277A 8B37                    	mov	si, [bx]
  7531                                  	; 22/02/2019
  7532 0000277C 8A0E[BE6F]              	mov	cl, [_i_]
  7533                                  fefss_6:
  7534 00002780 FE06[BE6F]              	inc	byte [_i_]
  7535 00002784 382E[BE6F]              	cmp	byte [_i_], ch ; [freespace_count]
  7536 00002788 72C8                    	jb	short fefss_0
  7537                                  	
  7538 0000278A 89F0                    	mov	ax, si
  7539 0000278C 89FA                    	mov	dx, di
  7540 0000278E 30ED                    	xor	ch, ch
  7541 00002790 F9                      	stc
  7542 00002791 C3                      	retn
  7543                                  fefss_7:
  7544 00002792 8B07                    	mov	ax, [bx]
  7545 00002794 8B5702                  	mov	dx, [bx+2]
  7546                                  fefss_8:
  7547 00002797 8B0E[BE6F]              	mov	cx, [_i_]
  7548 0000279B C3                      	retn
  7549                                  
  7550                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7551                                  ; get first free partition table entry
  7552                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7553                                  
  7554                                  	; 16/02/2019
  7555                                  get_first_free_pte:
  7556                                  	; Find free partition table entry
  7557                                  	;
  7558                                  	; INPUT:
  7559                                  	;	none
  7560                                  	; OUTPUT:
  7561                                  	;	If CF = 0 -> CX = partition table entry number
  7562                                  	;	If CF = 1 -> there is not a free entry in partition table
  7563                                  
  7564 0000279C BE[9857]                	mov	si, MasterBootBuff+pTableOffset
  7565 0000279F 31C9                    	xor	cx, cx
  7566                                  gffp_1:
  7567 000027A1 8A4404                  	mov	al, [si+ptFileSystemID] ; 23/02/2019
  7568                                  
  7569 000027A4 20C0                    	and	al, al
  7570 000027A6 740E                    	jz	short gffp_3 ; empty
  7571                                  
  7572 000027A8 80F903                  	cmp	cl, 3
  7573 000027AB 7307                    	jnb	short gffp_2
  7574                                  
  7575 000027AD FEC1                    	inc	cl
  7576 000027AF 83C610                  	add	si, 16 ; Partition table entry size
  7577 000027B2 EBED                    	jmp	short gffp_1
  7578                                  gffp_2:
  7579                                  	; CL = 3
  7580 000027B4 F9                      	stc
  7581 000027B5 C3                      	retn
  7582                                  gffp_3:
  7583                                  	; CL = PTE number (0 to 3)
  7584 000027B6 C3                      	retn 	
  7585                                  
  7586                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7587                                  ; convert cylinder count to sectors
  7588                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7589                                  ; 03/02/2019
  7590                                  
  7591                                  	; 15/03/2021
  7592                                  ;cylinders_to_sectors:
  7593                                  	; INPUT:
  7594                                  	;	ax = Cylinders (Total or partition's cylinder count)
  7595                                  	; OUTPUT:
  7596                                  	;	dx:ax = Sectors
  7597                                  
  7598                                  	;;mov	dx, [heads]
  7599                                  	;;mul	dx
  7600                                  	;; 30/10/2020
  7601                                  	;mul	word [heads]	
  7602                                  	;; dx:ax = Number of tracks (cylinders*heads)
  7603                                  	;mov	cx, [sectors]
  7604                                  	;call	mul32
  7605                                  	;	; dx:ax = Number of sectors 
  7606                                  	;retn
  7607                                  		
  7608                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7609                                  ; convert cylinder count to percent of disk size (total cylinders)
  7610                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7611                                  ; 03/02/2019
  7612                                  
  7613                                  cylinders_to_percent:
  7614                                  
  7615                                  	; INPUT:
  7616                                  	;	bx = Number of cylinders (of partition) -dividend-
  7617                                  	;	cx = Total cylinders -divisor-
  7618                                  	; OUTPUT:
  7619                                  	;	ax = Percentage
  7620                                  
  7621                                  	;  if (cylinders_in == 0)
  7622                                  	;	 percentage_out = 0;
  7623                                  	;  else if (total_cylinders == 0)
  7624                                  	;           percentage_out = 0;
  7625                                  	;       else
  7626                                  
  7627 000027B7 09DB                    	or	bx, bx
  7628 000027B9 741B                    	jz	short ctpc_6 ; ax = 0 = percentage_out 
  7629                                  ctpc_1:
  7630 000027BB 09C9                    	or	cx, cx
  7631 000027BD 7417                    	jz	short ctpc_6
  7632                                  
  7633 000027BF B86400                  	mov	ax, 100
  7634 000027C2 F7E3                    	mul	bx ; [cylinders_in] 
  7635                                  
  7636                                  		; dx:ax = Dividend
  7637                                  
  7638 000027C4 E8B6E4                  	call	div32 ; 100*cylinders_in / total_cylinders
  7639                                  		; DX:AX = Quotient
  7640                                  		; BX = Remainder
  7641                                  
  7642                                  	; ax = percentage_out
  7643                                  
  7644                                  	; 12/03/2021
  7645 000027C7 D1E9                    	shr	cx, 1	
  7646                                  
  7647 000027C9 39CB                    	cmp	bx, cx	; is remainder >= total_cylinders/2 ?
  7648 000027CB 7201                    	jb	short ctpc_5 ; No. 
  7649                                  ctpc_4:
  7650 000027CD 40                      	inc	ax
  7651                                  ctpc_5:
  7652 000027CE 83F864                  	cmp	ax, 100
  7653 000027D1 7603                    	jbe	short ctpc_6
  7654 000027D3 B86400                  	mov	ax, 100
  7655                                  ctpc_6:
  7656 000027D6 C3                      	retn
  7657                                  
  7658                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7659                                  ; display partition table
  7660                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7661                                  ; 04/02/2019
  7662                                  
  7663                                  	; 12/03/2021
  7664                                  display_partition_table_x:
  7665 000027D7 B005                    	mov	al, 5 ; display extended partition table
  7666 000027D9 EB02                    	jmp	short dpt_x
  7667                                  
  7668                                  display_partition_table:
  7669                                  
  7670                                  	; INPUT:
  7671                                  	;	al = 0 for MBR
  7672                                  	;	   = 5 for EBR (logical drives in extended partition)
  7673                                  	; OUTPUT:
  7674                                  	;	none
  7675                                  
  7676                                  	; 12/03/2021
  7677 000027DB 30C0                    	xor	al, al ; display primary partition table
  7678                                  dpt_x:
  7679                                  ;pt_positions:
  7680                                  n_pos	equ 30 ; 1 byte	
  7681                                  
  7682 000027DD A2[C46F]                	mov	[_e_], al	
  7683                                  
  7684                                  	; clear screen
  7685 000027E0 B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
  7686 000027E3 CD10                    	int	10h
  7687                                  
  7688 000027E5 803E[C46F]05            	cmp	byte [_e_], 5
  7689 000027EA 7507                    	jne	short dpt_1
  7690                                  dpt_0:
  7691 000027EC BD[6470]                	mov	bp, ext_table_boot_ind
  7692 000027EF B045                    	mov	al, 'E'
  7693 000027F1 EB05                    	jmp	short dpt_4
  7694                                  dpt_1:
  7695 000027F3 BD[1870]                	mov	bp, part_table_boot_ind
  7696 000027F6 B04D                    	mov	al, 'M'
  7697                                  dpt_4:
  7698 000027F8 BE[3458]                	mov	si, p_table_header
  7699 000027FB 88441E                  	mov	[si+n_pos], al
  7700 000027FE E881F3                         	call 	print_msg
  7701                                     
  7702 00002801 31DB                    	xor	bx, bx
  7703 00002803 891E[BE6F]              	mov	[_i_], bx
  7704                                  dpt_5:
  7705 00002807 FE06[BE6F]              	inc	byte [_i_]
  7706                                  
  7707                                  	; BX = partition entry (0 to 3)
  7708                                  	; BP = partition table structure address
  7709                                  
  7710 0000280B E86600                  	call	display_pt_entry  ; display partition table row
  7711                                  
  7712 0000280E 8B1E[BE6F]              	mov	bx, [_i_] 
  7713                                  	
  7714 00002812 80FB04                  	cmp	bl, 4
  7715 00002815 72F0                    	jb	short dpt_5
  7716                                  
  7717 00002817 BE[7559]                	mov	si, p_table_footer
  7718 0000281A E865F3                         	call 	print_msg
  7719                                  
  7720                                  	; 27/02/2019
  7721 0000281D BF[8B55]                	mov	di, str_disk_sectors
  7722                                  
  7723 00002820 803E[C46F]05            	cmp	byte [_e_], 5
  7724 00002825 741D                    	je	short dpt_9 
  7725                                  
  7726                                  	; display total disk sectors
  7727                                  
  7728                                  	;mov	di, str_disk_sectors
  7729                                  
  7730                                  	;cmp	byte [di], '0'
  7731                                  	;jnb	short dpt_8	
  7732                                  
  7733 00002827 A1[DA68]                        mov	ax, [total_sectors]
  7734 0000282A 8B16[DC68]                      mov	dx, [total_sectors+2]
  7735                                  
  7736 0000282E E82200                  	call	dpt_10
  7737                                  dpt_8:
  7738 00002831 BE[7555]                	mov	si, msg_disk_sectors
  7739                                  dpt_11:
  7740 00002834 E84BF3                  	call	print_msg
  7741                                  
  7742 00002837 BE[8B55]                	mov	si, str_disk_sectors
  7743 0000283A E845F3                  	call	print_msg
  7744                                  
  7745 0000283D BE[5F55]                	mov	si, CRLF
  7746 00002840 E83FF3                  	call	print_msg
  7747                                  
  7748 00002843 C3                      	retn
  7749                                  
  7750                                  dpt_9:
  7751                                  	; display extended partition size
  7752                                  
  7753 00002844 A1[B66F]                	mov	ax, [ep_Size]
  7754 00002847 8B16[B86F]                      mov	dx, [ep_Size+2]
  7755                                  
  7756 0000284B E80500                  	call	dpt_10
  7757                                  
  7758 0000284E BE[9655]                	mov	si, msg_ep_size
  7759 00002851 EBE1                    	jmp	short dpt_11
  7760                                  
  7761                                  dpt_10:
  7762 00002853 89E6                    	mov	si, sp
  7763 00002855 B90A00                  	mov	cx, 10
  7764                                  dpt_6:
  7765 00002858 E822E4                  	call	div32
  7766                                  	
  7767 0000285B 80C330                  	add	bl, '0'
  7768 0000285E 53                      	push	bx
  7769 0000285F 21C0                    	and	ax, ax
  7770 00002861 75F5                    	jnz	short dpt_6
  7771 00002863 21D2                    	and	dx, dx
  7772 00002865 75F1                    	jnz	short dpt_6
  7773                                  
  7774 00002867 29E6                    	sub	si, sp
  7775 00002869 D1EE                    	shr	si, 1
  7776                                  dpt_7:
  7777 0000286B 58                      	pop	ax
  7778 0000286C AA                      	stosb
  7779 0000286D 4E                      	dec	si
  7780 0000286E 75FB                    	jnz	short dpt_7
  7781                                  
  7782 00002870 30C0                    	xor	al, al
  7783 00002872 AA                      	stosb
  7784                                  
  7785                                  	; 27/02/2019
  7786 00002873 C3                      	retn
  7787                                  
  7788                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7789                                  ; display partition table entry/row
  7790                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7791                                  ; 04/02/2019
  7792                                  
  7793                                  struc ptbl
  7794                                  
  7795 00000000 ??                      .boot_ind:	resb 1
  7796 00000001 ??                      .start_head:	resb 1
  7797 00000002 ??                      .start_sector:	resb 1
  7798 00000003 ????                    .start_cyl:	resw 1
  7799 00000005 ??                      .sys_id:	resb 1
  7800 00000006 ??                      .end_head:	resb 1
  7801 00000007 ??                      .end_sector:	resb 1
  7802 00000008 ????                    .end_cyl:	resw 1
  7803 0000000A ????                    .rel_sec_lw:	resw 1
  7804 0000000C ????                    .rel_sec_hw:	resw 1
  7805 0000000E ????                    .num_sec_lw:	resw 1
  7806 00000010 ????                    .num_sec_hw:	resw 1	
  7807                                  .size:
  7808                                  
  7809                                  endstruc
  7810                                  
  7811                                  display_pt_entry:
  7812                                  	; 24/10/2020 (fdisk3.s)
  7813                                  
  7814                                  	; INPUT:
  7815                                  	;	bl = partition entry
  7816                                  	;	bh = 0
  7817                                  	;	bp = partition table structure address
  7818                                  	; OUTPUT:
  7819                                  	;	none
  7820                                  
  7821                                  ; 24/10/2020 (fdisk3.s)
  7822                                  ;pt_positions:
  7823                                  p_pos	equ 3  ; 1 byte
  7824                                  s_pos	equ 6  ; 2+1 byte
  7825                                  bh_pos	equ 10 ; 2+1 bytes
  7826                                  bs_pos	equ 14 ; 2+1 bytes
  7827                                  bc_pos	equ 18 ; 2+1 bytes
  7828                                  fs_pos  equ 22 ; 2+1 bytes
  7829                                  eh_pos  equ 26 ; 2+1 bytes
  7830                                  es_pos	equ 30 ; 2+1 bytes
  7831                                  ec_pos	equ 34 ; 2+1 bytes
  7832                                  rs_pos	equ 42 ; 10 bytes
  7833                                  ns_pos	equ 53 ; 10 bytes
  7834                                  fsx_pos equ 64 ; 14 bytes
  7835                                  
  7836                                  ; 2019-2020 (hdimage.s)
  7837                                  ;;pt_positions:
  7838                                  ;p_pos	equ 7  ; 1 byte
  7839                                  ;s_pos	equ 9  ; 2+1 byte
  7840                                  ;bh_pos	equ 13 ; 2+1 bytes
  7841                                  ;bs_pos	equ 17 ; 2+1 bytes
  7842                                  ;bc_pos	equ 21 ; 2+1 bytes
  7843                                  ;fs_pos equ 25 ; 2+1 bytes
  7844                                  ;eh_pos equ 29 ; 2+1 bytes
  7845                                  ;es_pos	equ 33 ; 2+1 bytes
  7846                                  ;ec_pos	equ 37 ; 2+1 bytes
  7847                                  ;rs_pos	equ 42 ; 7 bytes
  7848                                  ;ns_pos	equ 52 ; 7 bytes
  7849                                  ;fsx_pos equ 61 ; 14 bytes
  7850                                  
  7851 00002874 55                      	push	 bp ; 23/02/2019
  7852                                  
  7853 00002875 08DB                    	or	bl, bl
  7854 00002877 7406                    	jz	short dpte_0
  7855                                  
  7856                                  	;xor	bh, bh
  7857 00002879 B012                    	mov	al, ptbl.size ; 18
  7858 0000287B F6E3                    	mul	bl
  7859 0000287D 01C5                    	add	bp, ax
  7860                                  dpte_0:
  7861 0000287F 807E0500                	cmp	byte [bp+ptbl.sys_id], 0
  7862 00002883 0F861801                	jna	dpte_9
  7863                                  
  7864 00002887 B768                    	mov	bh, 'h'
  7865                                  
  7866 00002889 BE[C66F]                	mov	si, pte_row
  7867                                  
  7868                                  	; clear partition table display buffer/row
  7869 0000288C 89F7                    	mov	di, si
  7870 0000288E B92800                  	mov	cx, 40
  7871 00002891 B82020                  	mov	ax, 2020h
  7872 00002894 F3AB                    	rep	stosw
  7873                                  
  7874 00002896 88D8                    	mov	al, bl
  7875 00002898 0431                    	add	al, '1'
  7876 0000289A 884403                  	mov	[si+p_pos], al  ; partition number '1' to '4'
  7877                                  
  7878                                  	; partition status, type and CHS parameters
  7879                                  	; (as hexadecimal number)
  7880                                  
  7881                                  	;mov	al, [bp+ptbl.boot_ind]
  7882 0000289D 8A4600                  	mov	al, [bp]
  7883 000028A0 E8B5F3                  	call	byte_to_hex
  7884                                  
  7885 000028A3 894406                  	mov	[si+s_pos], ax
  7886 000028A6 887C08                  	mov	[si+s_pos+2], bh ; 'h'
  7887                                  
  7888 000028A9 8A4601                  	mov	al, [bp+ptbl.start_head]
  7889 000028AC E8A9F3                  	call	byte_to_hex
  7890                                  
  7891 000028AF 89440A                  	mov	[si+bh_pos], ax
  7892 000028B2 887C0C                  	mov	[si+bh_pos+2], bh ; 'h'
  7893                                  
  7894 000028B5 8B4E03                  	mov	cx, [bp+ptbl.start_cyl]
  7895                                  	; 28/10/2020
  7896 000028B8 81F9FF03                	cmp	cx, 1023
  7897 000028BC 7603                    	jna	short dpte_10 ; cyl number is in CHS limit
  7898 000028BE B9FF03                  	mov	cx, 1023 ; fix cylinder number (to it's PTE value)
  7899                                  			 ; to correct display PTE (CHS bytes)
  7900                                  dpte_10:
  7901 000028C1 C0E506                  	shl	ch, 6
  7902 000028C4 8A4602                  	mov	al, [bp+ptbl.start_sector]
  7903 000028C7 08E8                    	or	al, ch
  7904 000028C9 E88CF3                  	call	byte_to_hex
  7905                                  
  7906 000028CC 89440E                  	mov	[si+bs_pos], ax
  7907 000028CF 887C10                  	mov	[si+bs_pos+2], bh ; 'h'
  7908                                  
  7909                                  	;mov	al, [bp+ptbl.start_cyl]
  7910 000028D2 88C8                    	mov	al, cl
  7911 000028D4 E881F3                  	call	byte_to_hex
  7912                                  
  7913 000028D7 894412                  	mov	[si+bc_pos], ax
  7914 000028DA 887C14                  	mov	[si+bc_pos+2], bh ; 'h'
  7915                                  
  7916 000028DD 8A4605                  	mov	al, [bp+ptbl.sys_id]
  7917 000028E0 E875F3                  	call	byte_to_hex
  7918                                  
  7919 000028E3 894416                  	mov	[si+fs_pos], ax
  7920 000028E6 887C18                  	mov	[si+fs_pos+2], bh ; 'h'
  7921                                  
  7922 000028E9 8A4606                  	mov	al, [bp+ptbl.end_head]
  7923 000028EC E869F3                  	call	byte_to_hex
  7924                                  
  7925 000028EF 89441A                  	mov	[si+eh_pos], ax
  7926 000028F2 887C1C                  	mov	[si+eh_pos+2], bh ; 'h'
  7927                                  
  7928 000028F5 8B4E08                  	mov	cx, [bp+ptbl.end_cyl]
  7929                                  	; 28/10/2020
  7930 000028F8 81F9FF03                	cmp	cx, 1023
  7931 000028FC 7603                    	jna	short dpte_11 ; cyl number is in CHS limit
  7932 000028FE B9FF03                  	mov	cx, 1023 ; fix cylinder number (to it's PTE value)
  7933                                  			 ; to correct display PTE (CHS bytes)
  7934                                  dpte_11:
  7935 00002901 C0E506                  	shl	ch, 6
  7936 00002904 8A4607                  	mov	al, [bp+ptbl.end_sector]
  7937 00002907 08E8                    	or	al, ch
  7938 00002909 E84CF3                  	call	byte_to_hex
  7939                                  
  7940 0000290C 89441E                  	mov	[si+es_pos], ax
  7941 0000290F 887C20                  	mov	[si+es_pos+2], bh ; 'h'
  7942                                  
  7943                                  	;mov	al, [bp+ptbl.end_cyl]
  7944 00002912 88C8                    	mov	al, cl
  7945 00002914 E841F3                  	call	byte_to_hex
  7946                                  
  7947 00002917 894422                  	mov	[si+ec_pos], ax
  7948 0000291A 887C24                  	mov	[si+ec_pos+2], bh ; 'h'
  7949                                  
  7950                                  	; relative (start) sector address (lba)
  7951                                  	; (as decimal number)
  7952                                  
  7953 0000291D 8B460A                          mov	ax, [bp+ptbl.rel_sec_lw]
  7954 00002920 8B560C                          mov	dx, [bp+ptbl.rel_sec_hw]
  7955                                  
  7956 00002923 89E7                    	mov	di, sp
  7957 00002925 B90A00                  	mov	cx, 10
  7958                                  dpte_1:
  7959 00002928 E852E3                  	call	div32
  7960                                  	
  7961 0000292B 80C330                  	add	bl, '0'
  7962 0000292E 53                      	push	bx
  7963 0000292F 21C0                    	and	ax, ax
  7964 00002931 75F5                    	jnz	short dpte_1
  7965 00002933 21D2                    	and	dx, dx
  7966 00002935 75F1                    	jnz	short dpte_1
  7967                                  
  7968 00002937 8D5C31                  	lea	bx, [si+rs_pos+7]
  7969                                  
  7970 0000293A 29E7                    	sub	di, sp
  7971 0000293C D1EF                    	shr	di, 1
  7972 0000293E 29FB                    	sub	bx, di	
  7973                                  dpte_2:
  7974 00002940 58                      	pop	ax
  7975 00002941 8807                    	mov	[bx], al
  7976 00002943 4F                      	dec	di
  7977 00002944 7403                    	jz	short dpte_3
  7978                                  	
  7979 00002946 43                      	inc	bx
  7980 00002947 EBF7                    	jmp	short dpte_2
  7981                                  
  7982                                  dpte_3:
  7983                                  	; number of sectors)
  7984                                  	; (as decimal number)
  7985                                  
  7986 00002949 8B460E                          mov	ax, [bp+ptbl.num_sec_lw]
  7987 0000294C 8B5610                          mov	dx, [bp+ptbl.num_sec_hw]
  7988                                  
  7989 0000294F 89E7                    	mov	di, sp
  7990                                  	;mov	cx, 10
  7991                                  dpte_4:
  7992 00002951 E829E3                  	call	div32
  7993                                  	
  7994 00002954 80C330                  	add	bl, '0'
  7995 00002957 53                      	push	bx
  7996 00002958 21C0                    	and	ax, ax
  7997 0000295A 75F5                    	jnz	short dpte_4
  7998 0000295C 21D2                    	and	dx, dx
  7999 0000295E 75F1                    	jnz	short dpte_4
  8000                                  
  8001 00002960 8D5C3C                  	lea	bx, [si+ns_pos+7]
  8002                                  
  8003 00002963 29E7                    	sub	di, sp
  8004 00002965 D1EF                    	shr	di, 1
  8005 00002967 29FB                    	sub	bx, di	
  8006                                  dpte_5:
  8007 00002969 58                      	pop	ax
  8008 0000296A 8807                    	mov	[bx], al
  8009 0000296C 4F                      	dec	di
  8010 0000296D 7403                    	jz	short dpte_6
  8011                                  	
  8012 0000296F 43                      	inc	bx
  8013 00002970 EBF7                    	jmp	short dpte_5
  8014                                  dpte_6:
  8015                                  	; set file system name
  8016                                  
  8017 00002972 8A4605                  	mov	al, [bp+ptbl.sys_id]
  8018 00002975 BF[8E40]                	mov	di, valid_partitions
  8019 00002978 B91300                  	mov	cx, 19
  8020 0000297B F2AE                    	repnz	scasb
  8021 0000297D 7405                    	jz	short dpte_7
  8022 0000297F B8[8040]                	mov	ax, FS_OTHERS	 
  8023 00002982 EB0C                    	jmp	short dpte_8
  8024                                  dpte_7:
  8025 00002984 81EF[8F40]              	sub	di, valid_partitions + 1
  8026 00002988 B80E00                  	mov	ax, 14
  8027 0000298B F7E7                    	mul	di
  8028 0000298D 05[763F]                	add	ax, FileSys_Names
  8029                                  dpte_8:
  8030 00002990 8D7C40                  	lea	di, [si+fsx_pos]
  8031 00002993 89C6                    	mov	si, ax
  8032 00002995 B107                    	mov	cl, 7
  8033 00002997 F3A5                    	rep	movsw
  8034                                  
  8035 00002999 BE[C66F]                	mov	si, pte_row
  8036 0000299C E8E3F1                  	call	print_msg
  8037                                  dpte_9:
  8038 0000299F 5D                      	pop	bp ; 23/02/2019
  8039                                  	
  8040 000029A0 C3                      	retn
  8041                                  
  8042                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  8043                                  ; fix partition table
  8044                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  8045                                  ; 24/02/2019
  8046                                  
  8047                                  partition_table_fix:
  8048                                  	; DELETE or EXIT option for Invalid Partition Table Entry
  8049                                  	; INPUT: 
  8050                                  	;	DS:SI = PTE address in MBR buffer
  8051                                  	
  8052 000029A1 56                      	push	si  ; save PTE address
  8053                                  
  8054 000029A2 89F0                    	mov	ax, si
  8055 000029A4 2D[9857]                	sub	ax, MasterBootBuff+446
  8056 000029A7 C0E804                  	shr	al, 4 ; / 16 
  8057 000029AA 0431                    	add	al, '1'
  8058 000029AC A2[3C5F]                	mov	[inv_pte_num], al
  8059                                  
  8060                                  	; DS:SI = PTE address in MBR buffer
  8061 000029AF E85EF7                  	call	show_selected_partition
  8062                                  
  8063                                  	;mov	si, CRLF
  8064                                  	;call	print_msg
  8065                                  
  8066                                  	; Warning message...
  8067                                  
  8068 000029B2 BE[185F]                	mov	si, msg_inv_pte
  8069 000029B5 E8CAF1                  	call	print_msg
  8070                                  
  8071 000029B8 5F                      	pop	di  ; restore PTE address
  8072                                  ptf_0:	
  8073 000029B9 30E4                    	xor	ah, ah
  8074 000029BB CD16                    	int	16h
  8075                                  
  8076 000029BD 3C0D                    	cmp	al, 13
  8077 000029BF 7406                    	je	short ptf_1
  8078                                  
  8079 000029C1 3C1B                    	cmp	al, 27
  8080 000029C3 75F4                    	jne	short ptf_0
  8081                                  
  8082 000029C5 F9                      	stc
  8083 000029C6 C3                      	retn
  8084                                  ptf_1:
  8085                                  	; Clear that (invalid) PTE
  8086 000029C7 31C0                    	xor	ax, ax	
  8087 000029C9 B90800                  	mov	cx, 8
  8088 000029CC F3AB                    	rep	stosw
  8089                                  
  8090                                  	; Clear screen
  8091 000029CE B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
  8092 000029D1 CD10                    	int	10h
  8093                                  
  8094 000029D3 C3                      	retn
  8095                                  
  8096                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  8097                                  ; display (& edit) EXTENDED (DOS) partition table
  8098                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  8099                                  ; 28/02/2019
  8100                                  
  8101                                  display_extended_pt:
  8102                                  	;mov	al, 5 ; extended partition (logical drives)
  8103                                  	;call	display_partition_table
  8104                                  	; 12/03/2021
  8105 000029D4 E800FE                  	call	display_partition_table_x
  8106                                  
  8107 000029D7 BE[1061]                	mov	si, ebr_editing_options
  8108 000029DA E8A5F1                  	call	print_msg
  8109                                  
  8110 000029DD BE[1F5D]                	mov	si, enter_opt_num_cancel_msg
  8111 000029E0 E89FF1                  	call	print_msg
  8112                                  
  8113 000029E3 BE[5F55]                	mov	si, CRLF
  8114 000029E6 E899F1                  	call	print_msg
  8115                                  dept_1:
  8116 000029E9 30E4                    	xor	ah, ah
  8117 000029EB CD16                    	int	16h
  8118                                  
  8119 000029ED 3C30                    	cmp	al, '0'
  8120 000029EF 740C                    	je	short dept_2
  8121                                  
  8122 000029F1 3C31                    	cmp	al, '1'
  8123 000029F3 7464                    	je	short edit_ext_table_create
  8124 000029F5 3C32                    	cmp	al, '2'
  8125 000029F7 7407                    	je	short edit_ext_table_delete
  8126                                  		
  8127 000029F9 3C1B                    	cmp	al, 27 ; ESCape
  8128 000029FB 75EC                    	jne	short dept_1
  8129                                  dept_2:
  8130 000029FD E907DA                  	jmp	A_42
  8131                                  
  8132                                  edit_ext_table_delete:
  8133                                  	; 28/02/2019
  8134                                  	;mov	al, 5 ; extended partition (logical drives)
  8135                                  	;call	display_partition_table
  8136                                  	; 12/03/2021
  8137 00002A00 E8D4FD                  	call	display_partition_table_x
  8138                                  
  8139 00002A03 BE[8F61]                	mov	si, msg_delete_ldd_q
  8140 00002A06 E879F1                  	call	print_msg
  8141                                  
  8142                                  	;mov	si, CRLF
  8143                                  	;call	print_msg
  8144                                  eetd_1:
  8145 00002A09 30E4                    	xor	ah, ah
  8146 00002A0B CD16                    	int	16h
  8147                                  
  8148 00002A0D 3C1B                    	cmp	al, 27
  8149 00002A0F 7410                    	je	short eetd_2
  8150                                  
  8151 00002A11 24DF                    	and	al, 0DFh
  8152 00002A13 3C59                    	cmp	al, 'Y'
  8153 00002A15 7412                    	je	short eetd_yes
  8154 00002A17 3C4E                    	cmp	al, 'N'
  8155 00002A19 75EE                    	jne	short eetd_1
  8156                                  eetd_no:
  8157 00002A1B BE[9F5C]                	mov	si, msg_NO ;  Write 'NO' (it may be shown for a moment)
  8158 00002A1E E861F1                  	call	print_msg
  8159                                  eetd_2:	
  8160 00002A21 BE[5F55]                	mov	si, CRLF  ; Next line
  8161 00002A24 E85BF1                  	call	print_msg
  8162 00002A27 EBAB                    	jmp	short display_extended_pt
  8163                                  eetd_yes:
  8164 00002A29 BE[995C]                	mov	si, msg_YES ;  Write 'YES' (it may be shown for a moment)
  8165 00002A2C E853F1                  	call	print_msg
  8166 00002A2F BE[5F55]                	mov	si, CRLF  ; Next line
  8167 00002A32 E84DF1                  	call	print_msg
  8168 00002A35 E88806                  	call	delete_logical_drives
  8169 00002A38 803E[A66D]00            	cmp	byte [ldrives], 0
  8170 00002A3D 7795                    	ja	short display_extended_pt
  8171 00002A3F E9C5D9                  	jmp	A_42
  8172                                  
  8173                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  8174                                  ; logical drive count limit error 
  8175                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  8176                                  
  8177                                  eetc_2:
  8178 00002A42 BE[F561]                	mov	si, msg_create_ldd_max_error
  8179                                  eetc_10:
  8180 00002A45 E83AF1                  	call	print_msg
  8181 00002A48 BE[BB55]                	mov	si, msg_press_any_key
  8182 00002A4B E834F1                  	call	print_msg
  8183 00002A4E 30E4                    	xor	ah, ah
  8184 00002A50 CD16                    	int	16h
  8185 00002A52 EB80                    	jmp	display_extended_pt
  8186                                  
  8187                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  8188                                  ; no free space in extended partition
  8189                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  8190                                  	
  8191                                  	; 05/03/2019
  8192                                  eetc_9:
  8193 00002A54 BE[2E64]                	mov	si, msg_c_ldd_nofspc_error
  8194 00002A57 EBEC                    	jmp	short eetc_10
  8195                                  
  8196                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  8197                                  ; create logical dos drive in EXTENDED (DOS) partition
  8198                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  8199                                  ; 19/10/2020 (fdisk3.s) 
  8200                                  
  8201                                  edit_ext_table_create:	; 01/03/2019 (hdimage.s)
  8202                                  
  8203                                  ; Create Method: ; 04/03/2019
  8204                                  ;LDD 1 <- LDD_START0, ebr 1st entry <- MBR (extended partition) - EBR 0
  8205                                  ;LDD 2 <- LDD_START1, ebr 2nd entry <- EBR 1
  8206                                  ;LDD 3 <- LDD_START2, ebr 2nd entry <- EBR 2
  8207                                  ;LDD 4 <- LDD_START3, ebr 2nd entry <- EBR 3
  8208                                  
  8209                                  	; 01/03/2019
  8210 00002A59 803E[6370]00            	cmp	byte [epnumber], 0 ; check extended partition
  8211 00002A5E 0F86C8E2                	jna	B_07		; cancel with error message
  8212                                  
  8213                                  	; 05/03/2019
  8214 00002A62 E8EE02                  	call	check_ext_free_space
  8215 00002A65 72ED                    	jc	eetc_9	; error, no free space in extented partition
  8216                                  
  8217                                  	; 30/10/2020
  8218 00002A67 A3[2271]                	mov	[ep_free_sectors], ax
  8219 00002A6A 8916[2471]              	mov	[ep_free_sectors+2], dx
  8220                                  
  8221 00002A6E 803E[A66D]04            	cmp	byte [ldrives], 4
  8222 00002A73 73CD                    	jnb	eetc_2	; error, write program limit message
  8223                                  
  8224                                  edit_ext_table_create_x: ; 02/03/2019
  8225                                  
  8226                                  	; Get logical drive size/cylinders (request) from user
  8227 00002A75 E87303                  	call	get_ldd_size
  8228 00002A78 833E[2871]01            	cmp	word [lcylinders], 1  ; at least 1 cylinder
  8229 00002A7D 0F8253FF                	jb	display_extended_pt ; cancel
  8230                                  
  8231                                  	; 03/03/2019
  8232 00002A81 A0[A66D]                	mov	al, [ldrives]
  8233                                  
  8234                                  	;cmp	byte [ldrives], 1
  8235                                  	;jnb	short eetc_3	; skip verify MBR extended partition
  8236                                  
  8237 00002A84 20C0                    	and	al, al
  8238 00002A86 757E                    	jnz	short eetc_3
  8239                                  
  8240 00002A88 31ED                    	xor	bp, bp
  8241                                  
  8242                                  	; Read MBR at EBR buffer
  8243 00002A8A 30E4                    	xor	ah, ah ; 19/10/2020
  8244 00002A8C 31D2                    	xor	dx, dx
  8245 00002A8E BB[AC6D]                	mov	bx, ebr_buffer
  8246 00002A91 E8FDF0                  	call	read_hd_sector
  8247 00002A94 7218                    	jc	short eetc_0
  8248                                  
  8249 00002A96 A0[6370]                	mov	al, [epnumber]
  8250 00002A99 98                      	cbw
  8251 00002A9A C0E004                  	shl	al, 4 ; * 16	
  8252 00002A9D BE[6A6F]                	mov	si, ebr_buffer+446
  8253 00002AA0 01C6                    	add	si, ax
  8254 00002AA2 BF[9857]                	mov	di, MasterBootBuff+446
  8255 00002AA5 01C7                    	add	di, ax
  8256 00002AA7 B90800                  	mov	cx, 8
  8257 00002AAA F3A7                    	repe	cmpsw	; repeat comparising while cx > 0 and zf = 1
  8258 00002AAC E30C                    	jcxz	eetc_1	; Extended partition entry is not changed 
  8259                                  	; Different PTE (means there is a new extended partition) 
  8260                                  eetc_0:
  8261                                  	; Write current MBR (with modified PT)
  8262 00002AAE BB[DA55]                	mov	bx, MasterBootBuff
  8263 00002AB1 31C0                    	xor	ax, ax
  8264                                  	;xor	dx, dx
  8265 00002AB3 E831F1                  	call	write_hd_sector
  8266 00002AB6 0F82D7DC                	jc	print_error_code ; ! display error msg and then exit !
  8267                                  eetc_1:
  8268                                  	; clear	EBR buffer
  8269 00002ABA BF[AC6D]                	mov	di, ebr_buffer
  8270 00002ABD 31C0                    	xor	ax, ax
  8271 00002ABF B9FF00                  	mov	cx, 255
  8272 00002AC2 F3AB                    	rep	stosw
  8273 00002AC4 C70555AA                	mov	word [di], 0AA55h
  8274                                  
  8275                                  	; Set logical dos drive parameters in it's EBR
  8276 00002AC8 BF[6A6F]                	mov	di, ebr_buffer+446
  8277                                  
  8278 00002ACB 8B0E[6E3F]              	mov	cx, [sectors]
  8279 00002ACF 29DB                    	sub	bx, bx ; 0
  8280 00002AD1 A1[AE6F]                	mov	ax, [ep_StartSector]
  8281 00002AD4 8B16[B06F]              	mov	dx, [ep_StartSector+2]
  8282                                  
  8283                                  	; 03/03/2019
  8284                                  	; set partition start address & size
  8285                                  
  8286 00002AD8 A3[0271]                	mov	[ldd_start], ax
  8287 00002ADB 8916[0471]              	mov	[ldd_start+2], dx
  8288                                  
  8289                                  	; 01/11/2020
  8290 00002ADF 833E[2871]FF            	cmp	word [lcylinders], 65535  
  8291                                  			; sign for using all of available sectors	
  8292 00002AE4 7209                    	jb	short eetc_11
  8293                                  
  8294 00002AE6 A1[2271]                	mov	ax, [ep_free_sectors]
  8295 00002AE9 8B16[2471]              	mov	dx, [ep_free_sectors+2]
  8296 00002AED EB0B                    	jmp	short eetc_12
  8297                                  eetc_11:
  8298 00002AEF A0[703F]                	mov	al, [heads]
  8299 00002AF2 F626[6E3F]              	mul	byte [sectors]
  8300 00002AF6 F726[2871]              	mul	word [lcylinders]
  8301                                  eetc_12:
  8302                                  	; 01/11/2020
  8303 00002AFA 31ED                    	xor	bp, bp
  8304 00002AFC A3[1271]                	mov	[ldd_size], ax
  8305 00002AFF 8916[1471]              	mov	[ldd_size+2], dx
  8306                                  
  8307                                  	; 1st ldd start sector is always 63 or 17 (= spt)
  8308                                  	;sub	ax, cx ; cx = 63 or 17, [sectors]
  8309                                  	;sbb	dx, bx ; sbb dx, 0
  8310                                  
  8311                                  	; 01/11/2020	
  8312 00002B03 E9DE00                  	jmp	eetc_4
  8313                                  
  8314                                  	;mov	[di+ptStartSector], cx
  8315                                  	;mov	[di+ptStartSector+2], bx
  8316                                  	;
  8317                                  	;; 01/11/2020
  8318                                  	;mov	[di+ptSectors], ax
  8319                                  	;mov	[di+ptSectors+2], dx
  8320                                  	;
  8321                                  	;mov	cx, ax
  8322                                  	;mov	bx, dx
  8323                                  	;; cx:bx = volume size of logical -dos- drive
  8324                                  	;
  8325                                  	;pop	ax ; ldd's LBA
  8326                                  	;pop	dx
  8327                                  	;; dx:ax = start sector address of ldd
  8328                                  	;
  8329                                  	;; 01/11/2020
  8330                                  	;add	cx, ax
  8331                                  	;adc	bx, dx
  8332                                  	;sub	cx, 1
  8333                                  	;sbb	bx, 0
  8334                                  	;; bx:cx = end sector address of ldd
  8335                                  	;push	cx
  8336                                  	;push	bx
  8337                                  	;
  8338                                  	;jmp	eetc_4
  8339                                  
  8340                                  eetc_3:
  8341                                  	; [ldrives] >= 1
  8342                                  	; Read EBR
  8343                                  	;mov	al, [ldrives]
  8344 00002B06 30E4                    	xor	ah, ah ; 02/11/2020
  8345 00002B08 C0E002                  	shl	al, 2
  8346 00002B0B 89C5                    	mov	bp, ax
  8347                                  
  8348                                  	; 03/03/2019
  8349 00002B0D 8B86[FE70]              	mov	ax, [bp+ldd_start-4]
  8350 00002B11 8B96[0071]              	mov	dx, [bp+ldd_start-2]
  8351 00002B15 BB[AC6D]                	mov	bx, ebr_buffer
  8352 00002B18 E876F0                  	call	read_hd_sector
  8353 00002B1B 0F8272DC                	jc	print_error_code ; ! display error msg and then exit !
  8354                                  
  8355                                  	; 04/03/2019
  8356 00002B1F BE[7A6F]                	mov	si, ebr_buffer+446+16 ; 2nd entry (next EBR)
  8357                                  	
  8358                                  	; 03/03/2019
  8359 00002B22 8B86[FE70]              	mov	ax, [bp+ldd_start-4]
  8360 00002B26 8B96[0071]              	mov	dx, [bp+ldd_start-2]
  8361 00002B2A 0386[0E71]              	add	ax, [bp+ldd_size-4]
  8362 00002B2E 1396[1071]              	adc	dx, [bp+ldd_size-2]
  8363                                  
  8364 00002B32 8B0E[AE6F]              	mov	cx, [ep_StartSector]
  8365 00002B36 8B1E[B06F]              	mov	bx, [ep_StartSector+2]
  8366                                  
  8367 00002B3A 8986[0271]              	mov	[bp+ldd_start], ax
  8368 00002B3E 8996[0471]              	mov	[bp+ldd_start+2], dx
  8369                                  
  8370 00002B42 52                      	push	dx ; ldd's start sector LBA
  8371 00002B43 50                      	push	ax
  8372                                  	
  8373 00002B44 29C8                    	sub	ax, cx
  8374 00002B46 19DA                    	sbb	dx, bx
  8375                                  	; dx:ax = offset from start of the ep start sector
  8376                                  
  8377 00002B48 894408                  	mov	[si+ptStartSector], ax
  8378 00002B4B 89540A                  	mov	[si+ptStartSector+2], dx
  8379                                  
  8380                                  	; 01/11/2020
  8381 00002B4E 833E[2871]FF            	cmp	word [lcylinders], 65535  
  8382                                  			; sign for using all of available sectors	
  8383 00002B53 7209                    	jb	short eetc_13
  8384                                  
  8385 00002B55 A1[2271]                	mov	ax, [ep_free_sectors]
  8386 00002B58 8B16[2471]              	mov	dx, [ep_free_sectors+2]
  8387 00002B5C EB0B                    	jmp	short eetc_14
  8388                                  eetc_13:
  8389 00002B5E A0[703F]                	mov	al, [heads]
  8390 00002B61 F626[6E3F]              	mul	byte [sectors]
  8391 00002B65 F726[2871]              	mul	word [lcylinders]
  8392                                  eetc_14:
  8393                                  	; 01/11/2020
  8394 00002B69 8986[1271]              	mov	[bp+ldd_size], ax
  8395 00002B6D 8996[1471]              	mov	[bp+ldd_size+2], dx
  8396                                  
  8397 00002B71 89440C                   	mov	[si+ptSectors], ax
  8398 00002B74 89540E                  	mov	[si+ptSectors+2], dx
  8399                                  
  8400                                  	; 01/11/2020
  8401 00002B77 89C1                    	mov	cx, ax
  8402 00002B79 89D3                    	mov	bx, dx
  8403                                  	; cx:bx = volume size of logical -dos- drive
  8404                                  
  8405 00002B7B 58                      	pop	ax ; ldd's start sector LBA	
  8406 00002B7C 5A                      	pop	dx
  8407                                  
  8408                                  	; 01/11/2020
  8409 00002B7D 01C1                    	add	cx, ax
  8410 00002B7F 11D3                    	adc	bx, dx
  8411 00002B81 83E901                  	sub	cx, 1
  8412 00002B84 83DB00                  	sbb	bx, 0
  8413                                  	; bx:cx = end sector address of ldd
  8414 00002B87 51                      	push	cx
  8415 00002B88 53                      	push	bx
  8416                                  
  8417                                  	; calculate CHS from LBA
  8418 00002B89 E80A02                  	call	lba_to_chs
  8419                                  		; ax = cylinder
  8420                                  		; dl = sector
  8421                                  		; dh = head
  8422                                  
  8423 00002B8C C60400                  	mov	byte [si+ptBootable], 0
  8424 00002B8F 887401                  	mov	[si+ptBeginHead], dh
  8425 00002B92 884403                  	mov	[si+ptBeginCylinder], al
  8426 00002B95 C0E406                  	shl	ah, 6
  8427 00002B98 08E2                    	or	dl, ah		
  8428 00002B9A 885402                  	mov	[si+ptBeginSector], dl
  8429                                  
  8430                                   	;;mov	ax, [si+ptSectors]
  8431                                  	;;mov	dx, [si+ptSectors+2]
  8432                                   	;mov	ax, [bp+ldd_size]
  8433                                  	;mov	dx, [bp+ldd_size+2]
  8434                                  	;sub	ax, 1
  8435                                  	;sbb	dx, 0
  8436                                  	;add	ax, [bp+ldd_start]
  8437                                  	;adc	dx, [bp+ldd_start+2]
  8438                                  	;	; dx:ax = end sector
  8439                                  	
  8440                                  	; 01/11/2020
  8441 00002B9D 58                      	pop	ax
  8442 00002B9E 5A                      	pop	dx
  8443                                  	; dx:ax = end sector address of ldd
  8444                                  
  8445 00002B9F E8F401                  	call	lba_to_chs
  8446                                  		; ax = cylinder
  8447                                  		; dl = sector
  8448                                  		; dh = head
  8449                                  		; 24/10/2020
  8450                                  		; bl = Extended partition ID
  8451                                  		
  8452                                  	;mov	byte [si+ptFileSystemID], 5 ; EXTENDED
  8453                                  	; 24/10/2020
  8454 00002BA2 885C04                  	mov	[si+ptFileSystemID], bl ; EXTENDED ; 05h or 0Fh
  8455                                  	;
  8456 00002BA5 887405                  	mov	[si+ptEndHead], dh
  8457 00002BA8 884407                  	mov	[si+ptEndCylinder], al
  8458 00002BAB C0E406                  	shl	ah, 6
  8459 00002BAE 08D4                    	or	ah, dl	
  8460 00002BB0 886406                  	mov	[si+ptEndSector], ah
  8461                                  
  8462                                  	; Write EBR
  8463 00002BB3 8B86[FE70]              	mov	ax, [bp+ldd_start-4]
  8464 00002BB7 8B96[0071]              	mov	dx, [bp+ldd_start-2]
  8465 00002BBB BB[AC6D]                	mov	bx, ebr_buffer
  8466 00002BBE E826F0                  	call	write_hd_sector
  8467 00002BC1 0F82CCDB                	jc	print_error_code ; ! display error msg and then exit !
  8468                                  
  8469                                  	; clear	EBR buffer
  8470 00002BC5 BF[AC6D]                	mov	di, ebr_buffer
  8471 00002BC8 31C0                    	xor	ax, ax
  8472 00002BCA B9FF00                  	mov	cx, 255
  8473 00002BCD F3AB                    	rep	stosw
  8474 00002BCF C70555AA                	mov	word [di], 0AA55h
  8475                                  
  8476 00002BD3 BF[6A6F]                	mov	di, ebr_buffer+446 ; 1st entry points to LDD
  8477                                  
  8478 00002BD6 8B0E[6E3F]              	mov	cx, [sectors]
  8479 00002BDA 29DB                    	sub	bx, bx ; 0
  8480                                  	; 01/11/2020
  8481 00002BDC 8B86[1271]              	mov	ax, [bp+ldd_size]
  8482 00002BE0 8B96[1471]              	mov	dx, [bp+ldd_size+2]
  8483                                  	;sub	ax, cx
  8484                                  	;sbb	dx, bx ; sbb dx, 0 
  8485                                  eetc_4:	
  8486 00002BE4 894D08                  	mov	[di+ptStartSector], cx
  8487 00002BE7 895D0A                  	mov	[di+ptStartSector+2], bx
  8488                                  
  8489                                  	; 01/11/2020
  8490                                  	; 1st ldd start sector is always 63 or 17 (= spt)
  8491 00002BEA 29C8                    	sub	ax, cx ; cx = 63 or 17, [sectors]
  8492 00002BEC 19DA                    	sbb	dx, bx ; sbb dx, 0
  8493                                  
  8494                                  	; 01/11/2020
  8495 00002BEE 89450C                  	mov	[di+ptSectors], ax
  8496 00002BF1 89550E                  	mov	[di+ptSectors+2], dx
  8497                                  
  8498 00002BF4 8B8E[1271]              	mov	cx, [bp+ldd_size]
  8499 00002BF8 8B9E[1471]              	mov	bx, [bp+ldd_size+2]
  8500                                  	; cx:bx = volume size of logical -dos- drive
  8501                                  
  8502 00002BFC 8B86[0271]              	mov	ax, [bp+ldd_start]
  8503 00002C00 8B96[0471]              	mov	dx, [bp+ldd_start+2]
  8504                                  	; dx:ax = start sector address of ldd (EBR addr)
  8505                                  
  8506                                  	; 01/11/2020
  8507 00002C04 01C1                    	add	cx, ax
  8508 00002C06 11D3                    	adc	bx, dx
  8509 00002C08 83E901                  	sub	cx, 1
  8510 00002C0B 83DB00                  	sbb	bx, 0
  8511                                  	; bx:cx = end sector address of ldd
  8512 00002C0E 53                      	push	bx
  8513 00002C0F 51                      	push	cx
  8514                                  ;eetc_4:
  8515                                  	; 01/11/2020
  8516                                  	; stack = end sector address of ldd
  8517                                  	; dx:ax = start sector address of ldd
  8518                                  
  8519                                  	; calculate CHS from LBA
  8520                                  
  8521 00002C10 E88301                  	call	lba_to_chs
  8522                                  		; ax = cylinder
  8523                                  		; dl = sector
  8524                                  		; dh = head
  8525                                  
  8526                                  	;mov	byte [di+ptBootable], 0
  8527 00002C13 887501                  	mov	[di+ptBeginHead], dh
  8528 00002C16 884503                  	mov	[di+ptBeginCylinder], al
  8529                                  	;mov	bl, ah
  8530                                  	;shl	bl, 6
  8531                                  	;or	dl, bl
  8532                                  	; 01/11/2020		
  8533 00002C19 C0E406                  	shl	ah, 6
  8534 00002C1C 08E2                    	or	dl, ah
  8535 00002C1E 885502                  	mov	[di+ptBeginSector], dl
  8536                                  
  8537                                  	;add	ax, [lcylinders]
  8538                                  	;dec	ax ; end cylinder
  8539                                  	;mov	bx, ax
  8540                                  
  8541                                  	; 01/11/2020
  8542 00002C21 58                      	pop	ax
  8543 00002C22 5A                      	pop	dx
  8544                                  	; dx:ax = end sector address of ldd
  8545                                  
  8546 00002C23 E87001                  	call	lba_to_chs
  8547                                  		; ax = cylinder number (0-1023)
  8548                                  		; dl = sector
  8549                                  		; dh = head
  8550                                  		; 01/11/2020
  8551                                  		; cx = cylinder number (0-65535)
  8552                                  
  8553                                  	; 02/11/2020
  8554                                  	;mov	[endcyl], cx ; 01/11/2020
  8555 00002C26 870E[2A71]              	xchg	[endcyl], cx 
  8556                                  		; cx = end cylinder of the ep
  8557                                  		; [endcyl] = end cylinder of the ldd
  8558                                  
  8559                                  	;mov	[di+ptFileSystemID], 0
  8560                                  	;mov	cx, [heads]
  8561                                  	;dec	cl
  8562                                  	;mov	[di+ptEndHead], cl
  8563                                  	; 01/11/2020
  8564 00002C2A 887505                  	mov	[di+ptEndHead], dh
  8565                                  
  8566 00002C2D 884507                  	mov	[di+ptEndCylinder], al
  8567                                  	;mov	dx, [sectors]
  8568 00002C30 C0E406                  	shl	ah, 6
  8569 00002C33 08D4                    	or	ah, dl	
  8570 00002C35 886506                  	mov	[di+ptEndSector], ah
  8571                                  
  8572                                  	; 02/03/2019
  8573                                  	; Check unused space if it is 3rd LDD
  8574                                  	; (write message to add unused space.)
  8575                                  
  8576                                  	; 02/11/2020
  8577                                  	;cmp	byte [ldrives], 3
  8578                                  	;jb	eetc_7
  8579                                  
  8580                                  	; 01/11/2020
  8581 00002C38 833E[2871]FF            	cmp	word [lcylinders], 65535  
  8582                                  			; sign for using all of available sectors	
  8583 00002C3D 0F83B500                	jnb	eetc_7	; no need to add unused sector 
  8584                                  			; (there are not any unused sectors)
  8585                                  
  8586                                  	; cx = cylinder number (0 to 65535)
  8587                                  
  8588                                  	; 02/11/2020
  8589 00002C41 803E[A66D]03            	cmp	byte [ldrives], 3 ; is this logical drive 4 ?
  8590 00002C46 7309                    	jnb	short eetc_17  
  8591                                  			; force to show unused space message
  8592                                  
  8593                                  	; 02/11/2020
  8594                                  	; (add unused space if cyl nums are same or diff is 1)
  8595 00002C48 49                      	dec	cx  ; tolerate cylinder numbers n and n-1 
  8596 00002C49 3B0E[2A71]              	cmp	cx, [endcyl]
  8597 00002C4D 0F87A500                	ja	eetc_7  ; the end cyl number of the last ldd
  8598                                  			; is 2 or more cyls less than
  8599                                  			; the end cyl number of the ep
  8600                                  			; (a next ldd can be added to
  8601                                  			; extd partition with 2 or more cyls)
  8602                                  eetc_17:
  8603                                  	; 02/11/2020
  8604 00002C51 A0[A66D]                	mov	al, [ldrives]
  8605                                  	;add	al, '0'
  8606 00002C54 0431                    	add	al, '1'	; 03/11/2020
  8607 00002C56 A2[6D62]                	mov	[char_lddn], al
  8608                                  
  8609 00002C59 A0[6E3F]                	mov	al, [sectors]
  8610 00002C5C 88C7                    	mov	bh, al
  8611 00002C5E 8A1E[703F]              	mov	bl, [heads]
  8612 00002C62 FECB                    	dec	bl
  8613 00002C64 F6E3                    	mul	bl ; [sectors] * [heads] - 1
  8614                                  
  8615 00002C66 50                      	push	ax
  8616                                  
  8617 00002C67 88F8                    	mov	al, bh  ; [sectors]
  8618                                  	;mul	byte [heads]
  8619 00002C69 FEC3                    	inc	bl
  8620 00002C6B F6E3                    	mul	bl
  8621                                  		; ax = heads * sectors
  8622                                  	;mul	cx ; * end cylinder
  8623 00002C6D F726[2A71]              	mul	word [endcyl] ; 02/11/2020
  8624                                  		; dx:ax = end cylinder * heads * sectors
  8625 00002C71 59                      	pop	cx
  8626 00002C72 01C8                    	add	ax, cx ; + (sectors * (heads - 1))
  8627 00002C74 83D200                  	adc	dx, 0	
  8628                                  
  8629                                  	; 03/03/2019
  8630 00002C77 8B0E[6E3F]              	mov	cx, [sectors]
  8631 00002C7B FEC9                    	dec	cl  ; [sectors] - 1
  8632 00002C7D 01C8                    	add	ax, cx ; + (sectors - 1)
  8633 00002C7F 83D200                  	adc	dx, 0
  8634                                  		; DX:AX = end LBA
  8635                                  	
  8636 00002C82 8B0E[B26F]              	mov	cx, [ep_EndSector]
  8637 00002C86 8B1E[B46F]              	mov	bx, [ep_EndSector+2]
  8638                                  
  8639 00002C8A 39DA                      	cmp	dx, bx
  8640 00002C8C 7504                    	jne	short eetc_5
  8641 00002C8E 39C8                    	cmp	ax, cx
  8642 00002C90 7464                    	je	short eetc_7 ; 05/03/2019
  8643                                  eetc_5:
  8644 00002C92 53                      	push	bx
  8645 00002C93 BE[2A62]                	mov	si, msg_c_ldd_unused_warning
  8646 00002C96 E8E9EE                  	call	print_msg
  8647 00002C99 5B                      	pop	bx
  8648                                  eetc_6:
  8649 00002C9A 28E4                    	sub	ah, ah
  8650 00002C9C CD16                    	int	16h
  8651 00002C9E 3C0D                    	cmp	al, 13 ; ENTER
  8652 00002CA0 7454                    	je	short eetc_7 ; continue
  8653 00002CA2 3C1B                    	cmp	al, 27 ; ESC
  8654 00002CA4 75F4                    	jne	short eetc_6
  8655                                  
  8656                                  	; 03/03/2019
  8657                                  	; change end cylinder value
  8658 00002CA6 A0[6370]                	mov	al, [epnumber]
  8659 00002CA9 FEC8                    	dec	al
  8660 00002CAB B412                    	mov	ah, 18  ; primary partition table structure size
  8661 00002CAD F6E4                    	mul	ah
  8662 00002CAF 89C6                    	mov	si, ax
  8663 00002CB1 8B84[2070]              	mov	ax, [si+part_table_end_cyl]
  8664                                  	; 02/11/2020
  8665 00002CB5 A3[2A71]                	mov	[endcyl], ax ; end cylinder of the ep
  8666                                  eetc_19:
  8667                                  	; 03/11/2020
  8668 00002CB8 3DFF03                  	cmp	ax, 1023 ; overs CHS limit ?
  8669 00002CBB 7603                    	jna	short eetc_20 ; no
  8670 00002CBD B8FF03                  	mov	ax, 1023 ; 03FFh ; fix end CHS values of the PTE
  8671                                  eetc_20:
  8672 00002CC0 884507                  	mov	[di+ptEndCylinder], al
  8673 00002CC3 8A84[1F70]              	mov	al, [si+part_table_end_sector]
  8674 00002CC7 C0E406                  	shl	ah, 6
  8675 00002CCA 08C4                    	or	ah, al	
  8676 00002CCC 886506                  	mov	[di+ptEndSector], ah
  8677 00002CCF 8A84[1E70]              	mov	al, [si+part_table_end_head]
  8678 00002CD3 884505                  	mov	[di+ptEndHead], al
  8679                                  
  8680 00002CD6 89C8                    	mov	ax, cx
  8681 00002CD8 89DA                    	mov	dx, bx
  8682 00002CDA 83C001                  	add	ax, 1
  8683 00002CDD 83D200                  	adc	dx, 0
  8684                                  		; dx:ax = end of extd partition + 1 
  8685                                  
  8686                                  	; 02/11/2020
  8687 00002CE0 2B86[0271]              	sub	ax, [bp+ldd_start]
  8688 00002CE4 1B96[0471]              	sbb	dx, [bp+ldd_start+2]
  8689 00002CE8 2B4508                  	sub	ax, [di+ptStartSector]
  8690 00002CEB 1B550A                  	sbb	dx, [di+ptStartSector+2]
  8691                                  		; dx:ax = new sector count of the ldd
  8692                                  
  8693 00002CEE 89450C                  	mov	[di+ptSectors], ax
  8694 00002CF1 89550E                  	mov	[di+ptSectors+2], dx
  8695 00002CF4 EB06                    	jmp	short eetc_8
  8696                                  eetc_7:
  8697 00002CF6 8B450C                  	mov	ax, [di+ptSectors]
  8698 00002CF9 8B550E                  	mov	dx, [di+ptSectors+2]
  8699                                  eetc_8:
  8700                                  	; 01/11/2020
  8701 00002CFC 813E[2A71]FF03          	cmp	word [endcyl], 1023
  8702 00002D02 7605                    	jna	short eetc_15
  8703                                  
  8704                                  	; 25/10/2020
  8705                                  	;mov	cx, [bp+ldd_start]
  8706                                  	;mov	bx, [bp+ldd_start+2]
  8707                                  	;; 01/11/2020
  8708                                  	;add	cx, [bp+ldd_size]
  8709                                  	;adc	bx, [bp+ldd_size+2]
  8710                                  	;sub	cx, 1 ; *
  8711                                  	;sbb	bx, 0 ; *
  8712                                  	;cmp	bx, [chs_limit+2]
  8713                                  	;jb	short eetc_15
  8714                                  	;ja	short eetc_19
  8715                                  	;cmp	cx, [chs_limit]
  8716                                  	;jna	short eetc_15
  8717                                  ;eetc_19:
  8718 00002D04 E8D000                  	call	size_to_fat_type_lba ; 25/10/2020
  8719 00002D07 EB03                    	jmp	short eetc_16
  8720                                  eetc_15:
  8721                                  	; Get proper FAT type in [ldd_type]
  8722                                  	; by using DX:AX - size -
  8723 00002D09 E8B100                  	call	size_to_fat_type
  8724                                  eetc_16:
  8725 00002D0C 884504                  	mov	[di+ptFileSystemID], al
  8726                                  
  8727                                  	; Write current EBR (with modified PT)
  8728 00002D0F 8B86[0271]              	mov	ax, [bp+ldd_start]
  8729 00002D13 8B96[0471]              	mov	dx, [bp+ldd_start+2]
  8730                                  
  8731                                  	; 01/11/2020
  8732                                  	; ! safety ! (to protect MBR and primary partition)
  8733                                  ;eetc_16:
  8734                                  	;cmp	dx, [ep_StartSector+2]	
  8735                                  	;jb	short eetc_18
  8736                                  	;ja	short eetc_17
  8737                                  	;cmp	ax, [ep_StartSector]	
  8738                                  	;jna	short eetc_18
  8739                                  ;eetc_17:
  8740                                  	;mov	ah, 0FFh
  8741                                  	;jmp	print_error_code
  8742                                  ;eetc_18:
  8743                                  
  8744 00002D17 BB[AC6D]                	mov	bx, ebr_buffer
  8745 00002D1A E8CAEE                  	call	write_hd_sector
  8746 00002D1D 0F8270DA                	jc	print_error_code ; ! display error msg and then exit !
  8747                                  
  8748 00002D21 A0[A66D]                	mov	al, [ldrives]
  8749 00002D24 B412                    	mov	ah, 18 ; extended partition table structure size 	
  8750 00002D26 F6E4                    	mul	ah
  8751                                  
  8752 00002D28 89C6                    	mov	si, ax
  8753 00002D2A 81C6[6470]              	add	si, ext_table_boot_ind
  8754 00002D2E 87F7                    	xchg	si, di
  8755                                  
  8756                                  	; set partition (logical -dos- drive) data
  8757 00002D30 A5                      	movsw	; boot indicator, beginning head
  8758 00002D31 AC                      	lodsb
  8759 00002D32 88C4                    	mov	ah, al
  8760 00002D34 243F                    	and	al, 3Fh
  8761 00002D36 AA                      	stosb	; beginning sector
  8762 00002D37 C0EC06                  	shr	ah, 6
  8763 00002D3A AC                      	lodsb	; beginning cylinder
  8764 00002D3B AB                      	stosw	
  8765 00002D3C A5                      	movsw	; partition id, end head
  8766 00002D3D AC                      	lodsb
  8767 00002D3E 88C4                    	mov	ah, al
  8768 00002D40 243F                    	and	al, 3Fh
  8769 00002D42 AA                      	stosb	; end sector
  8770 00002D43 C0EC06                  	shr	ah, 6
  8771 00002D46 AC                      	lodsb	; end cylinder
  8772 00002D47 AB                      	stosw
  8773                                  
  8774 00002D48 A5                      	movsw	; copy start sector (LBA) and sector count
  8775 00002D49 A5                      	movsw
  8776 00002D4A A5                      	movsw
  8777 00002D4B A5                      	movsw
  8778                                  
  8779 00002D4C FE06[A66D]              	inc	byte [ldrives]
  8780                                  
  8781 00002D50 E981FC                  	jmp	display_extended_pt
  8782                                  
  8783                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  8784                                  ; check free space in EXTENDED (DOS) partition
  8785                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  8786                                  ; 05/03/2019
  8787                                  
  8788                                  check_ext_free_space:
  8789 00002D53 A1[B66F]                	mov	ax, [ep_Size]
  8790 00002D56 8B16[B86F]              	mov	dx, [ep_Size+2]
  8791                                  
  8792 00002D5A 8A1E[A66D]              	mov	bl, [ldrives]
  8793 00002D5E 20DB                    	and	bl, bl
  8794 00002D60 7433                    	jz	short cefs_1
  8795 00002D62 80FB04                  	cmp	bl, 4
  8796 00002D65 7602                    	jna	short cefs_0
  8797 00002D67 B304                    	mov	bl, 4
  8798                                  cefs_0:
  8799 00002D69 FECB                    	dec	bl	
  8800 00002D6B C0E302                  	shl	bl, 2 ; * 4
  8801 00002D6E 30FF                    	xor	bh, bh
  8802 00002D70 89DE                    	mov	si, bx
  8803                                  
  8804 00002D72 8B8C[0271]              	mov	cx, [si+ldd_start]
  8805 00002D76 8B9C[0471]              	mov	bx, [si+ldd_start+2]
  8806 00002D7A 038C[1271]              	add	cx, [si+ldd_size]
  8807 00002D7E 139C[1471]              	adc	bx, [si+ldd_size+2]
  8808                                  
  8809 00002D82 0306[AE6F]              	add	ax, [ep_StartSector]
  8810 00002D86 1316[B06F]              	adc	dx, [ep_StartSector+2]
  8811                                  
  8812 00002D8A 29C8                    	sub	ax, cx
  8813 00002D8C 19DA                    	sbb	dx, bx
  8814 00002D8E 7505                    	jnz	short cefs_1
  8815                                  	
  8816 00002D90 09C0                    	or	ax, ax
  8817 00002D92 7501                    	jnz	short cefs_1
  8818                                  
  8819                                  	; cf = 0 if the result not negative
  8820                                  
  8821 00002D94 F9                      	stc	
  8822                                  
  8823                                  	; cf = 1 if the result is negative or zero
  8824                                  	 
  8825                                  	; If cf = 0 -> There is free space as in DX:AX
  8826                                  	; NOTE: This calculation is unsafe if
  8827                                  	; logical dos drive count > 4 !	
  8828                                  	; (But still meaningful for creating a new ldd.
  8829                                  	;  Because a new ldd will be created only
  8830                                  	;  if ldd count < 4.)
  8831                                  cefs_1:
  8832 00002D95 C3                      	retn
  8833                                  
  8834                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  8835                                  ; convert LBA to CHS parameters (in registers)
  8836                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  8837                                  ; 24/10/2020
  8838                                  
  8839                                  	; 13/01/2021 (BugFix)
  8840                                  	; 01/03/2019 (hdimage.s)
  8841                                  lba_to_chs:
  8842                                  	; INPUT:
  8843                                  	;	DX:AX = LBA address
  8844                                  	; OUTPUT:
  8845                                  	;	AX = cylinder
  8846                                  	;	DL = sector
  8847                                  	;	DH = head
  8848                                  	; 24/10/2020
  8849                                  	;	BL = extended partition ID (05h, 0Fh)
  8850                                  	;
  8851                                  	; (modified registers: ax, bx, cx, dx)
  8852                                  
  8853 00002D96 8B0E[6E3F]              	mov	cx, [sectors]
  8854 00002D9A E8E0DE                  	call	div32
  8855 00002D9D FEC3                    	inc	bl
  8856 00002D9F 53                      	push	bx ; BL = sector
  8857 00002DA0 8B0E[703F]              	mov	cx, [heads]
  8858 00002DA4 E8D6DE                  	call	div32
  8859 00002DA7 5A                      	pop	dx  ; DL = sector	
  8860 00002DA8 88DE                    	mov	dh, bl ; BL = head
  8861                                  	
  8862                                  	; 24/10/2020
  8863                                  	; check cylinder number (CHS) limit
  8864                                  	;mov	bh, 05h ; ENTENTED (LBA)
  8865                                  	; 13/03/2021
  8866 00002DAA B305                    	mov	bl, 05h ; EXTENDED (LBA)
  8867                                  
  8868 00002DAC 89C1                    	mov	cx, ax ; 01/11/2020
  8869                                  
  8870 00002DAE 3DFF03                  	cmp	ax, 1023
  8871 00002DB1 7609                    	jna	short lbatochs_ok
  8872                                  
  8873 00002DB3 B8FF03                  	mov	ax, 1023 ; BC/EC = 0FFh
  8874 00002DB6 B23F                    	mov	dl, 63  ; BS/ES = 0FFh
  8875 00002DB8 B6FE                    	mov	dh, 254 ; BH/EH = 0FEh
  8876 00002DBA B30F                    	mov	bl, 0Fh ; EXTENDED (CHS)
  8877                                  lbatochs_ok:
  8878 00002DBC C3                      	retn
  8879                                  
  8880                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  8881                                  ; specify FAT type by using partition/volume size (CHS)
  8882                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  8883                                  ; 02/03/2019
  8884                                  
  8885                                  size_to_fat_type:
  8886                                  	; INPUT:
  8887                                  	;	DX:AX = DOS Partition Size in sectors
  8888                                  	; OUTPUT:
  8889                                  	;	AL = Partition type/ID (FAT type)
  8890                                  
  8891 00002DBD 09D2                    	or	dx, dx
  8892 00002DBF 750B                    	jnz	short stft_2
  8893                                  
  8894 00002DC1 3DA87F                  	cmp	ax, 32680
  8895 00002DC4 7703                    	ja	short stft_1	
  8896                                  stft_0:	
  8897 00002DC6 B001                    	mov	al, 1	; FAT12 file system
  8898 00002DC8 C3                      	retn
  8899                                  stft_1:
  8900 00002DC9 B004                    	mov	al, 4	; FAT16 (< 32MB)
  8901 00002DCB C3                      	retn	
  8902                                  stft_2:
  8903 00002DCC 83FA10                  	cmp	dx, 10h
  8904 00002DCF 7303                    	jnb	short stft_3 ; FAT32 (CHS) file system	
  8905                                  
  8906 00002DD1 B006                    	mov	al, 6	; FAT16 (>= 32MB)
  8907 00002DD3 C3                      	retn
  8908                                  stft_3:
  8909 00002DD4 B00B                    	mov	al, 0Bh ; FAT32 (CHS)
  8910 00002DD6 C3                      	retn
  8911                                  
  8912                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  8913                                  ; specify FAT type by using partition/volume size (LBA)
  8914                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  8915                                  ; 25/10/2020
  8916                                  
  8917                                  size_to_fat_type_lba:
  8918                                  	; INPUT:
  8919                                  	;	DX:AX = DOS Partition Size in sectors
  8920                                  	; OUTPUT:
  8921                                  	;	AL = Partition type/ID (FAT type)
  8922                                  
  8923 00002DD7 09D2                    	or	dx, dx
  8924 00002DD9 7408                    	jz	short stft_4
  8925                                  
  8926 00002DDB 83FA10                  	cmp	dx, 10h
  8927 00002DDE 7208                    	jb	short stft_5 ; FAT16 (LBA) file system	
  8928                                  
  8929 00002DE0 B00C                    	mov	al, 0Ch ; FAT32 file system (LBA)
  8930 00002DE2 C3                      	retn
  8931                                  stft_4:
  8932 00002DE3 3DA87F                  	cmp	ax, 32680
  8933 00002DE6 76DE                    	jna	short stft_0  ; FAT12 file system 	
  8934                                  stft_5:	
  8935 00002DE8 B00E                    	mov	al, 0Eh	; FAT16 file system (LBA)
  8936 00002DEA C3                      	retn
  8937                                  
  8938                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  8939                                  ; get requested logical dos drive size (from user)
  8940                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  8941                                  ; 02/03/2019
  8942                                  
  8943                                  get_ldd_size:
  8944                                  	; INPUT -> none
  8945                                  	;
  8946                                  	; OUTPUT -> 
  8947                                  	;	[lcylinders] = cylinder count
  8948                                  	;
  8949                                  	; (Modified registers: ax, bx, cx, dx, si, di) 
  8950                                  
  8951 00002DEB B80300                  	mov	ax, 3 ; clear screen
  8952 00002DEE CD10                    	int	10h
  8953                                  
  8954 00002DF0 BE[0448]                	mov	si, msg_create_dos_partition_h
  8955 00002DF3 E88CED                  	call	print_msg
  8956                                  
  8957                                  	; 03/03/2019
  8958 00002DF6 A0[A66D]                	mov	al, [ldrives]
  8959 00002DF9 08C0                    	or	al, al		; cmp byte [ldrives], 0
  8960 00002DFB 7405                    	jz	short gldds_1	; jna short gldds_0
  8961                                  
  8962                                  	;push	ax ; *	
  8963                                  
  8964                                  	;dec	al
  8965                                  	;mov	ah, 18
  8966                                  	;mul	ah
  8967                                  	
  8968                                  	;mov	di, ext_table_rel_sec_lw
  8969                                  	;add	di, ax
  8970                                  
  8971 00002DFD BE[184E]                	mov	si, msg_use_all_space
  8972                                  	; 01/11/2020
  8973                                  	;call	print_msg
  8974 00002E00 EB03                    	jmp	short gldds_2
  8975                                  
  8976                                  	; Calculate available space
  8977                                  
  8978                                  	;mov	ax, [ep_Size] ; ext part size in sectors
  8979                                  	;mov	dx, [ep_Size+2]
  8980                                  	
  8981                                  	; 04/03/2019
  8982                                  ;gldds_0:
  8983                                  	;mov	cx, [di]    ; start sector			
  8984                                  	;mov	bx, [di+2]
  8985                                  	;add	cx, [di+4]  ; sectors
  8986                                  	;adc	bx, [di+6]
  8987                                  	;	; bx:cx = start of next ldd
  8988                                  	;sub	ax, cx
  8989                                  	;sbb	dx, bx
  8990                                  	;	; dx:ax = free space in sectors
  8991                                  	;
  8992                                  	;pop	cx ; *
  8993                                  	;dec	cl
  8994                                  	;jz	short gldds_2
  8995                                  	;sub	di, 18
  8996                                  	;push	cx ; *
  8997                                  	;jmp	short gldds_0
  8998                                  
  8999                                  	; 05/03/2019
  9000                                  	;call	check_ext_free_space
  9001                                  	;jc	short gldds_cancel
  9002                                  	
  9003                                  	; 01/11/2020
  9004                                  	; 30/10/2020
  9005                                  	;mov	ax, [ep_free_sectors]
  9006                                  	;mov	dx, [ep_free_sectors+2]
  9007                                  	
  9008                                  		; DX:AX = free sectors in extended partition
  9009                                  	;jmp	short gldds_2
  9010                                  gldds_1:
  9011 00002E02 BE[4B4E]                	mov	si, msg_use_entire_ep_space
  9012                                  	;call	print_msg
  9013                                  	
  9014                                  	; 01/11/2020
  9015                                  	; Calculate free space in extended partition
  9016                                  	;mov	ax, [ep_Size]
  9017                                  	;mov	dx, [ep_Size+2]
  9018                                  gldds_2:
  9019                                  	; 01/11/2020
  9020 00002E05 E87AED                  	call	print_msg
  9021                                  
  9022 00002E08 A0[703F]                	mov	al, [heads]
  9023 00002E0B F626[6E3F]              	mul	byte [sectors]
  9024 00002E0F 89C1                    	mov	cx, ax
  9025                                  		
  9026 00002E11 A1[2271]                	mov	ax, [ep_free_sectors]
  9027 00002E14 8B16[2471]              	mov	dx, [ep_free_sectors+2]
  9028                                  
  9029                                  	; 01/11/2020
  9030                                  	; this is needed for partition size input
  9031                                  	; (maximum available sectors)
  9032                                  	;mov	[pp_Sectors], ax
  9033                                  	;mov	[pp_Sectors+2], dx
  9034                                  
  9035                                  	; 01/11/2020
  9036                                  	; subtrack start offset (which always equals to spt value)
  9037                                  	;sub	ax, [sectors]
  9038                                  	;sbb	dx, 0
  9039                                  
  9040                                  	;mov	cx, ax
  9041                                  	;mov	al, [heads]
  9042                                  	;mul	byte [sectors]
  9043                                  	;xchg	ax, cx
  9044                                  		; dx:ax = sectors
  9045                                  		; cx = heads*spt 
  9046                                  	;call	div32
  9047                                  		; ax = cylinders
  9048                                  		; bx = remainder
  9049                                   		; dx = 0
  9050                                  	;and	bx, bx
  9051                                  	;jz	short gldds_3
  9052                                  	;inc	ax
  9053                                  	; 01/11/2020
  9054 00002E18 F7F1                    	div	cx
  9055                                  	;and	dx, dx
  9056                                  	;jz	short gldds_3
  9057                                  	;inc	ax
  9058                                  gldds_3:
  9059 00002E1A A3[2871]                	mov	[lcylinders], ax ; <= 65535 (< 65535)
  9060                                  gldds_getchar:
  9061 00002E1D 30E4                    	xor	ah, ah
  9062 00002E1F CD16                    	int	16h
  9063                                  
  9064 00002E21 3C1B                    	cmp	al, 27 ; ESCAPE key
  9065 00002E23 7416                    	je	short gldds_cancel
  9066 00002E25 24DF                    	and	al, 0DFh
  9067 00002E27 3C4E                    	cmp	al, 'N'
  9068 00002E29 7417                    	je	short gldds_4
  9069 00002E2B 3C59                    	cmp	al, 'Y'
  9070 00002E2D 75EE                    	jne	short gldds_getchar
  9071                                  
  9072                                  	; 01/11/2020
  9073 00002E2F C706[2871]FFFF          	mov	word [lcylinders], 65535 ; sign for all free sectors
  9074                                  	
  9075 00002E35 BE[985C]                	mov	si, _msg_YES
  9076                                  	;call	print_msg
  9077                                  	;retn
  9078 00002E38 E947ED                  	jmp	print_msg
  9079                                  
  9080                                  gldds_cancel:
  9081 00002E3B C706[2871]0000          	mov	word [lcylinders], 0
  9082                                  gldds_28:
  9083 00002E41 C3                      	retn
  9084                                  gldds_4:	
  9085 00002E42 BE[9E5C]                	mov	si, _msg_NO
  9086 00002E45 E83AED                  	call	print_msg
  9087                                  gldds_26:
  9088 00002E48 B80300                  	mov	ax, 3 ; clear screen
  9089 00002E4B CD10                    	int	10h
  9090                                  
  9091 00002E4D BE[0448]                	mov	si, msg_create_dos_partition_h
  9092 00002E50 E82FED                  	call	print_msg
  9093                                  
  9094 00002E53 BE[B062]                	mov	si, msg_create_ldd_s
  9095 00002E56 E829ED                  	call	print_msg
  9096 00002E59 BE[D64D]                	mov	si, msg_press_esc_to_cancel
  9097 00002E5C E823ED                  	call	print_msg
  9098                                  gldds_25:
  9099 00002E5F 30E4                    	xor	ah, ah
  9100 00002E61 CD16                    	int	16h
  9101                                  
  9102 00002E63 3C1B                    	cmp	al, 27 ; ESCAPE key
  9103 00002E65 7502                    	jne	short gldds_5
  9104                                  
  9105 00002E67 EBD2                    	jmp	short gldds_cancel
  9106                                  gldds_5:
  9107                                  	; 04/03/2019
  9108 00002E69 3C20                    	cmp	al, 32 ; SPACE key
  9109 00002E6B 74D4                    	je	short gldds_28
  9110                                  	
  9111                                  	; 01/11/2020
  9112                                  	;mov	byte [pSize_unit], '%'
  9113 00002E6D 3C25                    	cmp	al, '%'
  9114 00002E6F 7416                    	je	short gldds_6
  9115                                  	;mov	byte [pSize_unit], 'M'
  9116 00002E71 3C0D                    	cmp	al, 13 ; 0Dh, Carriage Return key
  9117                                  	;je	short gldds_6
  9118 00002E73 7504                    	jne	short gldds_29
  9119                                  	; 01/11/2020
  9120 00002E75 B04D                    	mov	al, 'M'
  9121 00002E77 EB0E                    	jmp	short gldds_6
  9122                                  gldds_29:
  9123 00002E79 24DF                    	and	al, 0DFh
  9124 00002E7B 3C4D                    	cmp	al, 'M'
  9125 00002E7D 7408                    	je	short gldds_6
  9126                                  	;mov	[pSize_unit], al
  9127 00002E7F 3C47                    	cmp	al, 'G'
  9128 00002E81 7404                    	je	short gldds_6
  9129 00002E83 3C43                    	cmp	al, 'C'
  9130 00002E85 75D8                    	jne	short gldds_25
  9131                                  gldds_6:
  9132                                  	; 01/11/2020
  9133 00002E87 A2[826D]                	mov	[pSize_unit], al
  9134                                  
  9135                                  	; Set maximum sector count (all of extended partition)
  9136                                  	;mov	al, [sectors]
  9137                                  	;mul	byte [heads]
  9138                                  	;mul	word [lcylinders]
  9139                                  	; 01/11/2020	
  9140 00002E8A A1[2271]                	mov	ax, [ep_free_sectors]
  9141 00002E8D 8B16[2471]              	mov	dx, [ep_free_sectors+2]
  9142 00002E91 A3[706D]                	mov	[pp_Sectors], ax
  9143 00002E94 8916[726D]              	mov	[pp_Sectors+2], dx
  9144                                  	
  9145 00002E98 E857EF                   	call	partition_size_input
  9146 00002E9B 729E                    	jc	short gldds_cancel
  9147                                  		; DX:AX = Partition size in sectors
  9148                                  	;or	bx, bx
  9149                                  	;jnz	short gldds_cancel
  9150                                  
  9151                                  	; 01/11/2020
  9152 00002E9D A3[9E6D]                	mov	[ppn_Sectors], ax
  9153 00002EA0 8916[A06D]              	mov	[ppn_Sectors+2], dx
  9154                                  		
  9155                                  	;mov	cx, ax
  9156                                  	;mov	al, [heads]
  9157                                  	;mul	byte [sectors]
  9158                                  	;xchg	ax, cx
  9159                                  	; 13/03/2021
  9160 00002EA4 8B0E[986D]              	mov	cx, [hs] ; heads*sectors
  9161                                  		; dx:ax = sectors
  9162                                  		; cx = heads*spt 
  9163 00002EA8 E8D2DD                  	call	div32
  9164                                  		; ax = cylinders
  9165                                  		; bx = remainder
  9166                                   		; dx = 0
  9167                                  	; 02/11/2020
  9168                                  	;and	bx, bx
  9169                                  	;jz	short gldds_7
  9170                                  	;inc	ax
  9171                                  gldds_7:
  9172 00002EAB 3B06[2871]              	cmp	ax, [lcylinders]
  9173 00002EAF 7704                    	ja	short gldds_9
  9174                                  gldds_8:
  9175                                  	; OK
  9176 00002EB1 A3[2871]                	mov	[lcylinders], ax
  9177 00002EB4 C3                      	retn
  9178                                  
  9179                                  gldds_9:
  9180                                  	; Partition size limit message
  9181                                  	
  9182 00002EB5 803E[826D]43            	cmp	byte [pSize_unit], 'C'
  9183 00002EBA 741C                    	je	short gldds_10
  9184                                  
  9185                                  	; Tolerate 1 cylinder if unit is not cylinder
  9186                                  	;dec	ax
  9187                                  	;cmp	ax, [lcylinders]
  9188                                  	;jna	short gldds_8
  9189                                  
  9190                                  	; 01/11/2020
  9191                                  	; Tolerate sectors if sectorcount doesn't over ep limit
  9192 00002EBC A1[9E6D]                	mov	ax, [ppn_Sectors]
  9193 00002EBF 8B16[A06D]              	mov	dx, [ppn_Sectors+2]
  9194 00002EC3 3B16[2471]              	cmp	dx, [ep_free_sectors+2]
  9195 00002EC7 770F                    	ja	short gldds_10
  9196 00002EC9 7206                    	jb	short gldds_30
  9197 00002ECB 3B06[2271]              	cmp	ax, [ep_free_sectors]
  9198 00002ECF 7707                    	ja	short gldds_10
  9199                                  gldds_30:
  9200 00002ED1 C706[2871]FFFF          	mov	word [lcylinders], 65535 ; sign for all free sectors
  9201 00002ED7 C3                      	retn
  9202                                  
  9203                                  gldds_10:
  9204                                  	; clear screen
  9205 00002ED8 B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
  9206 00002EDB CD10                    	int	10h
  9207                                  
  9208 00002EDD BE[0448]                	mov	si, msg_create_dos_partition_h ; header
  9209 00002EE0 E89FEC                  	call	print_msg
  9210                                  
  9211 00002EE3 BE[5D5E]                	mov	si, msg_partition_size_limit
  9212 00002EE6 E899EC                  	call	print_msg
  9213                                  
  9214 00002EE9 803E[826D]4D            	cmp	byte [pSize_unit], 'M'
  9215 00002EEE 7413                    	je	short gldds_11
  9216                                  
  9217 00002EF0 803E[826D]25            	cmp	byte [pSize_unit], '%'
  9218 00002EF5 7457                    	je	short gldds_22
  9219                                  
  9220 00002EF7 803E[826D]43            	cmp	byte [pSize_unit], 'C'
  9221 00002EFC 7505                    	jne	short gldds_11
  9222                                  
  9223 00002EFE A1[2871]                	mov	ax, [lcylinders]
  9224 00002F01 EB0F                    	jmp	short gldds_12
  9225                                  gldds_11:
  9226                                  	; 'M'
  9227 00002F03 A1[706D]                	mov	ax, [pp_Sectors]
  9228 00002F06 8B16[726D]              	mov	dx, [pp_Sectors+2]
  9229 00002F0A B90008                  	mov	cx, 2*1024 ; sectors -> MB
  9230 00002F0D E86DDD                  	call	div32
  9231                                  		; DX = 0 
  9232                                  		; AX = Available space in Megabytes
  9233 00002F10 89C7                    	mov	di, ax		
  9234                                  gldds_12:	
  9235 00002F12 B90A00                  	mov	cx, 10
  9236 00002F15 89E5                    	mov	bp, sp
  9237                                  gldds_13:
  9238 00002F17 31D2                    	xor	dx, dx
  9239                                  	;mov	cx, 10
  9240 00002F19 F7F1                    	div	cx
  9241 00002F1B 52                      	push	dx
  9242 00002F1C 83F809                  	cmp	ax, 9
  9243 00002F1F 77F6                    	ja	short gldds_13
  9244                                  gldds_14:
  9245 00002F21 BB0700                  	mov	bx, 07h
  9246 00002F24 09C0                    	or	ax, ax
  9247 00002F26 7501                    	jnz	short gldds_16
  9248                                  gldds_15:
  9249 00002F28 58                      	pop	ax
  9250                                  gldds_16:
  9251 00002F29 0430                    	add	al, '0'
  9252                                  gldds_17:
  9253 00002F2B B40E                    	mov	ah, 0Eh
  9254                                  	;mov	bx, 07h
  9255 00002F2D CD10                    	int	10h	; write character (as tty)
  9256                                  
  9257 00002F2F 39EC                    	cmp	sp, bp
  9258 00002F31 72F5                    	jb	short gldds_15
  9259                                  
  9260 00002F33 803E[826D]25            	cmp	byte [pSize_unit], '%'
  9261 00002F38 7508                    	jne	short gldds_18
  9262                                  
  9263 00002F3A 3C25                    	cmp	al, '%'
  9264 00002F3C 745E                    	je	short gldds_21
  9265 00002F3E B025                    	mov	al, '%'
  9266 00002F40 EBE9                    	jmp	short gldds_17
  9267                                  gldds_18:
  9268 00002F42 803E[826D]43            	cmp	byte [pSize_unit], 'C'
  9269 00002F47 753E                    	jne	short gldds_19
  9270                                  
  9271 00002F49 BE[F95E]                	mov	si, msg_cylinders
  9272 00002F4C EB4B                    	jmp	short gldds_20
  9273                                  
  9274                                  gldds_22:
  9275                                  	; '%'
  9276                                  	; 01/11/2020
  9277 00002F4E 8B16[B86F]              	mov	dx, [ep_Size+2]
  9278 00002F52 A1[B66F]                	mov	ax, [ep_Size] ; *
  9279 00002F55 21D2                    	and	dx, dx
  9280 00002F57 7419                    	jz	short gldds_33 ; dx = 0
  9281 00002F59 B90100                  	mov	cx, 1
  9282                                  gldds_31:
  9283 00002F5C D1E1                    	shl	cx, 1
  9284 00002F5E E81CDD                  	call	div32
  9285 00002F61 09D2                    	or	dx, dx
  9286 00002F63 7409                    	jz	short gldds_32 ; *
  9287 00002F65 A1[B66F]                	mov	ax, [ep_Size]	
  9288 00002F68 8B16[B86F]              	mov	dx, [ep_Size+2]
  9289 00002F6C EBEE                    	jmp	short gldds_31
  9290                                  gldds_32:
  9291 00002F6E 8B16[2471]              	mov	dx, [ep_free_sectors+2]
  9292                                  	; ep free sectors <= ep size
  9293                                  gldds_33:
  9294 00002F72 50                      	push	ax ; * ; dx = 0 (ep size weight)
  9295 00002F73 A1[2271]                	mov	ax, [ep_free_sectors]
  9296 00002F76 B96400                  	mov	cx, 100
  9297                                  	;and	dx, dx
  9298                                  	;jnz	short gldds_34
  9299                                  	;mul	cx
  9300                                  	;jmp	short gldds_35
  9301                                  ;gldds_34:
  9302 00002F79 E80FDD                  	call	mul32
  9303                                  		; dx:ax = 100 * ep free sectors weight
  9304                                  ;gldds_35:
  9305 00002F7C 59                      	pop	cx ; *
  9306 00002F7D E8FDDC                  	call	div32 ; 100 * ep free sectors / ep size
  9307                                  		; ax = % value (<= 100)
  9308 00002F80 09C0                    	or	ax, ax
  9309                                  	;jnz	short gldds_23
  9310 00002F82 758E                    	jnz	short gldds_12 ; 13/01/2021
  9311 00002F84 40                      	inc	ax ; 0 -> 1
  9312                                  	; 13/03/2021
  9313 00002F85 EB8B                    	jmp	short gldds_12
  9314                                  
  9315                                  ;gldds_23:	
  9316                                  	;mov	bp, sp
  9317                                  	;mov	cx, 10
  9318                                  ;gldds_24:	
  9319                                  	;xor	dx, dx
  9320                                  	;div	cx
  9321                                  	;push	dx ; *
  9322                                  	;cmp	ax, 9
  9323                                  	;ja	short gldds_24
  9324                                  	;jmp	short gldds_14
  9325                                  
  9326                                  gldds_19:
  9327 00002F87 BE[0D5F]                	mov	si, msg_megabytes
  9328 00002F8A C606[165F]73            	mov	byte [msg_megabytes_s], 's'
  9329 00002F8F 83FF01                  	cmp	di, 1
  9330 00002F92 7705                    	ja	short gldds_20
  9331 00002F94 C606[165F]00            	mov	byte [msg_megabytes_s], 0	
  9332                                  gldds_20:
  9333 00002F99 E8E6EB                  	call	print_msg
  9334                                  gldds_21:
  9335 00002F9C BE[AA5E]                	mov	si, msg_partition_size_limit_r
  9336 00002F9F E8E0EB                  	call	print_msg
  9337                                  gldds_27:
  9338 00002FA2 30E4                    	xor	ah, ah
  9339 00002FA4 CD16                    	int	16h
  9340                                  	
  9341 00002FA6 3C1B                    	cmp	al, 27 ; ESCAPE key
  9342 00002FA8 0F849CFE                	je	gldds_26
  9343 00002FAC 3C0D                    	cmp	al, 13 ; ENTER (Carriage Return) key
  9344 00002FAE 75F2                    	jne	short gldds_27
  9345                                  
  9346                                  	;mov	ax, [lcylinders]
  9347 00002FB0 C3                      	retn
  9348                                  	
  9349                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  9350                                  ; initialize extended (dos) partition table 
  9351                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  9352                                  ; 18/10/2020 (fdisk3.s)
  9353                                  ; 26/02/2019 (hdimage.s)
  9354                                  
  9355                                  init_ext_partition_table:
  9356                                  
  9357                                  	; INPUT -> 
  9358                                  	;	[epnumber] = extended partition number
  9359                                  	;
  9360                                  	; OUTPUT -> none
  9361                                  
  9362                                  ; Display Method: ; 04/03/2019
  9363                                  ;LDD 1 <- LDD_START0, ebr 1st entry <- MBR (extended partition) - EBR 0
  9364                                  ;LDD 2 <- LDD_START1, ebr 1st entry <- EBR 1
  9365                                  ;LDD 3 <- LDD_START2, ebr 1st entry <- EBR 2
  9366                                  ;LDD 4 <- LDD_START3, ebr 1st entry <- EBR 3
  9367                                  ;LDD 5 <- LDD_START3, ebr 2nd entry (LDD 5 is not displayed)
  9368                                  
  9369                                  	; 08/03/2019
  9370                                  
  9371                                  	; clear extended partition table structure/list
  9372                                  
  9373 00002FB1 BF[6470]                	mov	di, ext_table_boot_ind
  9374 00002FB4 89FE                    	mov	si, di ; 28/02/2019
  9375 00002FB6 B92400                  	mov	cx, 36 ; 18*4 = 72 bytes
  9376 00002FB9 31C0                    	xor	ax, ax ; 0
  9377 00002FBB F3AB                    	rep	stosw
  9378 00002FBD 89F7                    	mov	di, si ; 28/02/2019	
  9379                                  
  9380                                  	;mov	byte [ldrives], 0
  9381 00002FBF A2[A66D]                	mov	[ldrives], al ; 0
  9382                                  
  9383                                  	;cmp	byte [epnumber], 1
  9384                                  	;jb	short iept_0
  9385                                  
  9386 00002FC2 A0[6370]                	mov	al, [epnumber]
  9387 00002FC5 FEC8                    	dec	al
  9388 00002FC7 B412                    	mov	ah, 18  ; partition table structure size 
  9389 00002FC9 F6E4                    	mul	ah
  9390 00002FCB BE[2270]                	mov	si, part_table_rel_sec_lw
  9391 00002FCE 01C6                    	add	si, ax
  9392                                  	; 02/11/2020
  9393                                  	;(save end cylinder for comparising later)
  9394 00002FD0 8B44FE                  	mov	ax, [si-2] ; part_table_end_cyl 
  9395                                  			; 16 bit cylinder number
  9396 00002FD3 A3[2A71]                	mov	[endcyl], ax
  9397                                  	;
  9398 00002FD6 8B04                    	mov	ax, [si]
  9399 00002FD8 8B5402                  	mov	dx, [si+2]
  9400 00002FDB A3[AE6F]                	mov	[ep_StartSector], ax
  9401 00002FDE 8916[B06F]              	mov	[ep_StartSector+2], dx
  9402 00002FE2 8B4C04                  	mov	cx, [si+4]
  9403 00002FE5 8B5C06                  	mov	bx, [si+6]
  9404 00002FE8 890E[B66F]              	mov	[ep_Size], cx
  9405 00002FEC 891E[B86F]              	mov	[ep_Size+2], bx
  9406 00002FF0 83E901                  	sub	cx, 1
  9407 00002FF3 83DB00                  	sbb	bx, 0
  9408 00002FF6 01C1                    	add	cx, ax
  9409 00002FF8 11D3                    	adc	bx, dx 
  9410 00002FFA 890E[B26F]              	mov	[ep_EndSector], cx
  9411 00002FFE 891E[B46F]              	mov	[ep_EndSector+2], bx
  9412                                  
  9413                                  	; 27/02/2019
  9414 00003002 A3[0271]                	mov	[ldd_start], ax
  9415 00003005 8916[0471]              	mov	[ldd_start+2], dx
  9416                                  
  9417                                  	; 03/03/2019
  9418                                  	;mov	word [ldd_size], 0
  9419                                  	;mov	word [ldd_size+2], 0
  9420                                  	
  9421 00003009 BB[AC6D]                	mov	bx, ebr_buffer
  9422                                  	; dx:ax = Extended partition address
  9423                                  	; es:bx = Extended partition buffer 
  9424 0000300C E882EB                  	call	read_hd_sector
  9425 0000300F 7209                    	jc	short iept_0
  9426                                  
  9427                                  	; Check EBR if it is a valid boot record or not
  9428 00003011 813E[AA6F]55AA          	cmp	word [ebr_buffer+510], 0AA55h
  9429 00003017 7402                    	je	short iept_1
  9430                                  iept_stc_retn:
  9431 00003019 F9                      	stc
  9432                                  iept_0:
  9433 0000301A C3                      	retn
  9434                                  iept_1:
  9435                                  	; Check PTE 1, if it is valid or not
  9436 0000301B A0[6E6F]                	mov	al, [ebr_buffer+446+ptFileSystemID]
  9437 0000301E 20C0                    	and	al, al
  9438 00003020 74F7                    	jz	short iept_stc_retn ; empty pte, error
  9439 00003022 3C05                    	cmp	al, 5
  9440 00003024 74F3                    	je	short iept_stc_retn ; extended partition, error
  9441                                  	; 24/10/2020
  9442 00003026 3C0F                    	cmp	al, 0Fh
  9443 00003028 74EF                    	je	short iept_stc_retn ; extended partition, error
  9444                                  
  9445                                  	;inc	byte [ldrives] ; logical (dos) drive count
  9446                                  
  9447 0000302A BE[6A6F]                	mov	si, ebr_buffer+446 ; Partition table offset
  9448 0000302D B90400                  	mov	cx, 4
  9449                                  
  9450                                  	; set partition (logical -dos- drive) data
  9451 00003030 A5                      	movsw	; boot indicator, beginning head
  9452 00003031 AC                      	lodsb
  9453 00003032 88C4                    	mov	ah, al
  9454 00003034 243F                    	and	al, 3Fh
  9455 00003036 AA                      	stosb	; beginning sector
  9456 00003037 C0EC06                  	shr	ah, 6
  9457 0000303A AC                      	lodsb	; beginning cylinder
  9458 0000303B AB                      	stosw	
  9459 0000303C A5                      	movsw	; partition id, end head
  9460 0000303D AC                      	lodsb
  9461 0000303E 88C4                    	mov	ah, al
  9462 00003040 243F                    	and	al, 3Fh
  9463 00003042 AA                      	stosb	; end sector
  9464 00003043 C0EC06                  	shr	ah, 6
  9465 00003046 AC                      	lodsb	; end cylinder
  9466 00003047 AB                      	stosw
  9467                                  
  9468                                  	; 04/03/2019
  9469 00003048 8A1E[A66D]              	mov	bl, [ldrives]
  9470                                  	;dec 	bl
  9471                                  	;jnz	short iept_2
  9472                                  
  9473                                  	; 05/03/2019
  9474 0000304C 08DB                    	or	bl, bl 
  9475 0000304E 7518                    	jnz	short iept_2
  9476                                  
  9477 00003050 8B04                    	mov	ax, [si]   ; start sector of 1st LDD (offset)	
  9478 00003052 8B5402                  	mov	dx, [si+2]
  9479 00003055 034404                  	add	ax, [si+4] ; size of 1st LDD (volume)
  9480 00003058 135406                  	adc	dx, [si+6]
  9481                                  
  9482 0000305B A3[1271]                	mov	[ldd_size], ax ; size of 1st LDD (partition)
  9483 0000305E 8916[1471]              	mov	[ldd_size+2], dx
  9484                                  	; 05/03/2019
  9485 00003062 FE06[A66D]              	inc	byte [ldrives] ; logical (dos) drive count
  9486 00003066 FEC3                    	inc	bl
  9487                                  iept_2:
  9488 00003068 F3A5                    	rep	movsw ; copy start sector (LBA) and sector count
  9489                                  
  9490                                  	; get next extended partition (logical -dos- drive) data 
  9491 0000306A 8A4404                  	mov	al, [si+ptFileSystemID]
  9492 0000306D 20C0                    	and	al, al ; EMPTY
  9493 0000306F 74A9                    	jz	short iept_0 ; end of logical -dos- drive chain	
  9494                                  
  9495 00003071 3C05                    	cmp	al, 5 ; EXTENDED
  9496                                  	;jne	short iept_stc_retn  ; 2nd PTE must have
  9497                                  	;			     ; extended partition ID
  9498 00003073 7404                    	je	short iept_4
  9499                                  	; 24/10/2020
  9500 00003075 3C0F                    	cmp	al, 0Fh ; EXTENDED (LBA)
  9501 00003077 75A0                    	jne	short iept_stc_retn  ; 2nd PTE must have
  9502                                  				     ; extended partition ID
  9503                                  iept_4:
  9504                                  	; 05/03/2019
  9505 00003079 FE06[A66D]              	inc	byte [ldrives] ; logical (dos) drive count
  9506                                  
  9507                                  	;cmp	byte [ldrives], al ; 5
  9508 0000307D 80FB04                  	cmp	bl, 4 ; number of logical dos drives (till here)
  9509 00003080 733D                    	jnb	short iept_3
  9510                                  
  9511 00003082 83C608                  	add	si, 8
  9512                                  
  9513 00003085 AD                      	lodsw	
  9514 00003086 89C2                    	mov	dx, ax	; start sector
  9515 00003088 AD                      	lodsw
  9516 00003089 92                      	xchg	dx, ax	; start sector + 2
  9517                                  
  9518                                  	; 04/03/2019
  9519 0000308A 0306[AE6F]              	add	ax, [ep_StartSector]
  9520 0000308E 1316[B06F]              	adc	dx, [ep_StartSector+2]
  9521                                  	
  9522 00003092 30FF                    	xor	bh, bh
  9523 00003094 C0E302                  	shl	bl, 2 ; *4
  9524                                  
  9525                                  	; 28/02/2019
  9526 00003097 8987[0271]              	mov	[bx+ldd_start], ax ; start of (next) LDD (partition)
  9527 0000309B 8997[0471]              	mov	[bx+ldd_start+2], dx
  9528                                  
  9529                                  	; 03/03/2019
  9530                                  	; set partition size for logical dos drive
  9531 0000309F 8B0C                    	mov	cx, [si]
  9532 000030A1 898F[1271]              	mov	[bx+ldd_size], cx
  9533 000030A5 8B4C02                  	mov	cx, [si+2]
  9534 000030A8 898F[1471]              	mov	[bx+ldd_size+2], cx
  9535                                  
  9536 000030AC BB[AC6D]                	mov	bx, ebr_buffer
  9537                                  	; dx:ax = Extended partition address
  9538                                  	; es:bx = Extended partition buffer 
  9539 000030AF E8DFEA                  	call	read_hd_sector
  9540 000030B2 720B                    	jc	short iept_3 ; 03/03/2019
  9541                                  
  9542                                  	; Check EBR if it is valid or not
  9543 000030B4 813E[AA6F]55AA          	cmp	word [ebr_buffer+510], 0AA55h
  9544 000030BA 0F845DFF                	je	iept_1
  9545                                  
  9546 000030BE F9                      	stc
  9547                                  iept_3:	
  9548 000030BF C3                      	retn
  9549                                  
  9550                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  9551                                  ; delete logical -dos- drives in extended partition
  9552                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  9553                                  ; 18/10/2020 (fdisk3.s)
  9554                                  
  9555                                  delete_logical_drives:
  9556                                  		; 27/02/2019 (hdimage.s)
  9557                                  
  9558                                  ; Delete Method: ; 04/03/2019
  9559                                  ;LDD 5 <- LDD_START3, ebr 2nd entry
  9560                                  ;LDD 4 <- LDD_START2, ebr 2nd entry
  9561                                  ;LDD 3 <- LDD_START1, ebr 2nd entry
  9562                                  ;LDD 2 <- LDD_START0, ebr 2nd entry
  9563                                  ;LDD 1 <- LDD_START0, ebr 1st entry
  9564                                  
  9565                                  	;cmp	byte [ldrives], 0
  9566                                  	;jna	short dld_stc
  9567                                  
  9568                                  	;mov	al, 5 ; extended partition (logical drives)
  9569                                  	;call	display_partition_table
  9570                                  	; 12/03/2021
  9571 000030C0 E814F7                  	call	display_partition_table_x
  9572                                  
  9573 000030C3 A0[A66D]                	mov	al, [ldrives]
  9574 000030C6 0430                    	add	al, '0'
  9575 000030C8 A2[8360]                	mov	[lddp_num], al
  9576                                  
  9577 000030CB BE[3060]                	mov	si, msg_delete_ldd
  9578 000030CE E8B1EA                  	call	print_msg
  9579                                  
  9580 000030D1 BE[D64D]                	mov	si, msg_press_esc_to_cancel
  9581 000030D4 E8ABEA                  	call	print_msg
  9582                                  dld_0:
  9583 000030D7 30E4                    	xor	ah, ah
  9584 000030D9 CD16                    	int	16h
  9585                                  
  9586 000030DB 80FC53                  	cmp	ah, 53h  ; DELETE or DEL key
  9587 000030DE 751C                    	jne	short dld_1
  9588                                  
  9589                                  	; Delete PTE 1 & PTE 2 on EBR 1
  9590 000030E0 30E4                    	xor	ah, ah
  9591 000030E2 A0[A66D]                	mov	al, [ldrives]
  9592 000030E5 FEC8                    	dec	al
  9593 000030E7 7518                    	jnz	short dld_2
  9594                                  
  9595 000030E9 BF[6A6F]                	mov	di, ebr_buffer+446
  9596 000030EC B91000                  	mov	cx, 16
  9597 000030EF F3AB                    	rep	stosw
  9598                                  
  9599                                  	; 04/03/2019
  9600                                  	; Clear ldd data in extended partition table/structure
  9601 000030F1 BF[6470]                	mov	di, ext_table_boot_ind
  9602 000030F4 B109                    	mov	cl, 9
  9603 000030F6 F3AB                    	rep	stosw
  9604 000030F8 31F6                    	xor	si, si
  9605 000030FA EB40                    	jmp	short dld_3
  9606                                  dld_1:	
  9607 000030FC 3C1B                    	cmp	al, 27 ; ESC key
  9608 000030FE 75D7                    	jne	short dld_0
  9609                                  dld_5:
  9610 00003100 C3                      	retn
  9611                                  
  9612                                  ;dld_stc:
  9613                                  ;	stc
  9614                                  ;	retn	
  9615                                  
  9616                                  dld_2:
  9617                                  	; 04/03/2019
  9618                                  	; Delete 2nd PTE on EBR 2 to 4
  9619 00003101 FEC8                    	dec	al 
  9620 00003103 C0E002                  	shl	al, 2 ; * 4
  9621 00003106 89C6                    	mov	si, ax
  9622                                  
  9623 00003108 8B84[0271]              	mov	ax, [si+ldd_start]
  9624 0000310C 8B94[0471]              	mov	dx, [si+ldd_start+2]
  9625 00003110 BB[AC6D]                	mov	bx, ebr_buffer
  9626 00003113 E87BEA                  	call	read_hd_sector
  9627 00003116 7238                    	jc	short dld_4
  9628                                  
  9629 00003118 BF[7A6F]                	mov	di, ebr_buffer+446+16
  9630 0000311B B90800                  	mov	cx, 8
  9631 0000311E 29C0                    	sub	ax, ax
  9632 00003120 F3AB                    	rep	stosw
  9633                                  
  9634                                  	; 04/03/2019
  9635                                  	;cmp	byte [ldrives], 5
  9636                                  	;jnb	short dld_3
  9637 00003122 8A26[A66D]              	mov	ah, [ldrives]
  9638 00003126 80FC05                  	cmp	ah, 5
  9639 00003129 7311                    	jnb	short dld_3
  9640                                  
  9641                                  	; Clear ldd data in extended partition table/structure
  9642                                  	;mov	ah, [ldrives]
  9643 0000312B FECC                    	dec	ah
  9644 0000312D B012                    	mov	al, 18
  9645 0000312F F6E4                    	mul	ah
  9646 00003131 BF[6470]                	mov	di, ext_table_boot_ind
  9647 00003134 01C7                    	add	di, ax
  9648                                  	;mov	cx, 9
  9649 00003136 B109                    	mov	cl, 9
  9650                                  	;xor	ax, ax
  9651 00003138 30C0                    	xor	al, al
  9652 0000313A F3AB                    	rep	stosw
  9653                                  dld_3:
  9654                                  	; Write changed EBR
  9655 0000313C 8B84[0271]              	mov	ax, [si+ldd_start]
  9656 00003140 8B94[0471]              	mov	dx, [si+ldd_start+2]
  9657 00003144 BB[AC6D]                	mov	bx, ebr_buffer
  9658 00003147 E89DEA                  	call	write_hd_sector
  9659 0000314A 7204                    	jc	short dld_4
  9660                                  
  9661                                  	; 28/02/2019
  9662 0000314C FE0E[A66D]              	dec	byte [ldrives]
  9663                                  dld_4:
  9664 00003150 803E[A66D]00            	cmp	byte [ldrives], 0
  9665 00003155 0F8767FF                	ja	delete_logical_drives
  9666                                  
  9667 00003159 C3                      	retn
  9668                                  
  9669                                  ;=============================================================================
  9670                                  ;        	initialized data
  9671                                  ;=============================================================================
  9672                                  
  9673                                  ; 12/10/2020
  9674 0000315A 00                      int13h_x:	db	0
  9675                                  
  9676                                  TRDOS386_MASTERBOOT_SECTOR:
  9677 0000315B <bin 200h>              	incbin	'FS1_MBR.BIN' ; Singlix FS1 MBR	
  9678                                  
  9679                                  TRDOS_FAT_hd_bs:
  9680                                  	;incbin 'TRHDBS.BIN'
  9681                                  TRDOS_FAT32_hd_bs:
  9682 0000335B <bin 400h>              	incbin	'FAT32_BS.BIN'
  9683                                  TRDOS_FAT16_hd_bs: 
  9684 0000375B <bin 200h>              	incbin	'FAT16_BS.BIN'
  9685                                  TRDOS_FAT12_hd_bs: 
  9686 0000395B <bin 200h>              	incbin	'FAT12_BS.BIN'
  9687                                  
  9688                                  TRDOS_TRFS1_chs_bs:
  9689 00003B5B <bin 200h>              	incbin	'TRFS1CHS.BIN' ; Singlix FS1 (CHS+LBA Disk) BS		
  9690                                  TRDOS_TRFS1_lba_bs:
  9691 00003D5B <bin 200h>              	incbin	'TRFS1LBA.BIN' ; Singlix FS1 (LBA Disk) BS	
  9692                                  
  9693 00003F5B 00                      	db	0
  9694                                  
  9695                                  hexchrs:
  9696 00003F5C 303132333435363738-     	db	'0123456789ABCDEF'
  9696 00003F65 39414243444546     
  9697                                  
  9698                                  ; 05/11/2020
  9699 00003F6C 00                      	db	0	
  9700                                  
  9701 00003F6D 90                      align 2
  9702                                  
  9703                                  ; (TR-DOS 386 compatible) Hard Disk (image) parameters
  9704                                  
  9705                                  sectors: ; sectors per track (63)
  9706 00003F6E 3F00                    	dw 63
  9707                                  heads:	 ; number of heads (16 or 32 or 64) 
  9708 00003F70 1000                    	dw 16
  9709                                  cylinders: ; number of cylinders (16 to 1024)
  9710 00003F72 0004                    	dw 1024
  9711 00003F74 0000                    	dw 0 ; 16/10/2020 (double word)
  9712                                  
  9713                                  ; 05/11/2020
  9714                                  
  9715                                  ;random:
  9716                                  ;	db 0  ; random write to file (0 = sequental)
  9717                                  ;newdisk:
  9718                                  ;	db 0
  9719                                  
  9720                                  FileSys_Names: ; 2003-2017
  9721                                  ; (Valid FileSystems for TRDOS 386, SINGLIX, RETRO UNIX OS projects in 2017)
  9722 00003F76 464154313220202020-     FS_FAT12:     db "FAT12         "  ; 01h = FAT12
  9722 00003F7F 2020202020         
  9723 00003F84 58454E495820202020-     FS_XENIX:     db "XENIX         "  ; 02h , XENIX System V root
  9723 00003F8D 2020202020         
  9724 00003F92 58454E495820757372-     FS_XENIX_USR: db "XENIX usr     "  ; 03h , XENIX System V user
  9724 00003F9B 2020202020         
  9725 00003FA0 464154313620283034-     FS_FAT16:     db "FAT16 (04h)   "  ; 04h = FAT16 < 32MB
  9725 00003FA9 6829202020         
  9726 00003FAE 455854454E44454420-     FS_EXT_CHS:   db "EXTENDED (CHS)"  ; 05h = Extended DOS Partition
  9726 00003FB7 2843485329         
  9727 00003FBC 464154313620283036-     FS_FAT16_BIG: db "FAT16 (06h)   "  ; 06h = FAT16 > 32MB, CHS mode
  9727 00003FC5 6829202020         
  9728 00003FCA 4E5446532020202020-     FS_NTFS:      db "NTFS          "  ; 07h , WINDOWS NTFS Partition
  9728 00003FD3 2020202020         
  9729 00003FD8 464154333220284348-     FS_FAT32_CHS: db "FAT32 (CHS)   "  ; 0Bh = FAT32, CHS mode
  9729 00003FE1 5329202020         
  9730 00003FE6 464154333220284C42-     FS_FAT32_LBA: db "FAT32 (LBA)   "  ; 0Ch = FAT32, LBA mode
  9730 00003FEF 4129202020         
  9731 00003FF4 464154313620284C42-     FS_FAT16_LBA: db "FAT16 (LBA)   "  ; 0Eh = FAT16, LBA mode
  9731 00003FFD 4129202020         
  9732 00004002 455854454E44454420-     FS_EXT_LBA:   db "EXTENDED (LBA)"  ; 0Fh = Extented Partition, LBA mode
  9732 0000400B 284C424129         
  9733 00004010 554E49582053595354-     FS_UNIX_SYSV: db "UNIX SYSTEM V "  ; 63h , SCO UNIX, UNIXWARE, OPENSERVER
  9733 00004019 454D205620         
  9734 0000401E 524554524F20554E49-     FS_RETROUNIX: db "RETRO UNIX    "  ; 71h , Retro UNIX 386 v2 Partition
  9734 00004027 5820202020         
  9735 0000402C 554E49582056372020-     FS_UNIX_V7:   db "UNIX V7       "  ; 72h , UNIX v7 x86 Partition  
  9735 00004035 2020202020         
  9736 0000403A 4C494E555820535741-     FS_LINUXSWAP: db "LINUX SWAP    "  ; 82h , LINUX SWAP Partition
  9736 00004043 5020202020         
  9737 00004048 4C494E555820202020-     FS_LINUX:     db "LINUX         "  ; 83h , LINUX NATIVE (ext2) Partition
  9737 00004051 2020202020         
  9738 00004056 4C494E555820455854-     FS_LINUXEXT:  db "LINUX EXTENDED"  ; 85h , LINUX EXTENDED Partition
  9738 0000405F 454E444544         
  9739 00004064 524444202020202020-     FS_TRDD:      db "RDD           "  ; A0h , (Random Data Disk) LBA
  9739 0000406D 2020202020         
  9740 00004072 53494E474C49582046-     FS_TRFS:      db "SINGLIX FS1   "  ; A1h , (32 bit, 512 bytes per sector)
  9740 0000407B 5331202020         
  9741 00004080 554E4B4E4F574E2046-     FS_OTHERS:    db "UNKNOWN FS    "  ; Another or Unknown File Systems
  9741 00004089 5320202020         
  9742                                   
  9743                                  valid_partitions: ; (*)
  9744 0000408E 01020304050607          	      db 01h, 02h, 03h, 04h, 05h, 06h, 07h
  9745 00004095 0B0C0E0F637172          	      db 0Bh, 0Ch, 0Eh, 0Fh, 63h, 71h, 72h
  9746 0000409C 828385A0A1              	      db 82h, 83h, 85h, 0A0h, 0A1h 			
  9747                                  
  9748                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  9749                                  ;  messages
  9750                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  9751                                  
  9752                                  CHS_msg: ; 80 bytes per row
  9753 000040A1 507265737320274327-     db  "Press 'C' to set cylinders then press '+,-' keys to change number of cylinders. " 
  9753 000040AA 20746F207365742063-
  9753 000040B3 796C696E6465727320-
  9753 000040BC 7468656E2070726573-
  9753 000040C5 7320272B2C2D27206B-
  9753 000040CE 65797320746F206368-
  9753 000040D7 616E6765206E756D62-
  9753 000040E0 6572206F662063796C-
  9753 000040E9 696E646572732E20   
  9754 000040F1 507265737320274827-     db  "Press 'H' to set heads then press '+,-' keys to change number of heads.         " 
  9754 000040FA 20746F207365742068-
  9754 00004103 65616473207468656E-
  9754 0000410C 20707265737320272B-
  9754 00004115 2C2D27206B65797320-
  9754 0000411E 746F206368616E6765-
  9754 00004127 206E756D626572206F-
  9754 00004130 662068656164732E20-
  9754 00004139 2020202020202020   
  9755 00004141 507265737320275327-     db  "Press 'S' to set sectors then press '+,-' keys to change numb of sectors/track. " 
  9755 0000414A 20746F207365742073-
  9755 00004153 6563746F7273207468-
  9755 0000415C 656E20707265737320-
  9755 00004165 272B2C2D27206B6579-
  9755 0000416E 7320746F206368616E-
  9755 00004177 6765206E756D62206F-
  9755 00004180 6620736563746F7273-
  9755 00004189 2F747261636B2E20   
  9756 00004191 202020202020202020-     db  "                                                                                " 
  9756 0000419A 202020202020202020-
  9756 000041A3 202020202020202020-
  9756 000041AC 202020202020202020-
  9756 000041B5 202020202020202020-
  9756 000041BE 202020202020202020-
  9756 000041C7 202020202020202020-
  9756 000041D0 202020202020202020-
  9756 000041D9 2020202020202020   
  9757 000041E1 202020202020202020-     db  "                                                                                " 
  9757 000041EA 202020202020202020-
  9757 000041F3 202020202020202020-
  9757 000041FC 202020202020202020-
  9757 00004205 202020202020202020-
  9757 0000420E 202020202020202020-
  9757 00004217 202020202020202020-
  9757 00004220 202020202020202020-
  9757 00004229 2020202020202020   
  9758 00004231 507265737320454E54-     db  "Press ENTER to use current CHS values.                                          "
  9758 0000423A 455220746F20757365-
  9758 00004243 2063757272656E7420-
  9758 0000424C 4348532076616C7565-
  9758 00004255 732E20202020202020-
  9758 0000425E 202020202020202020-
  9758 00004267 202020202020202020-
  9758 00004270 202020202020202020-
  9758 00004279 2020202020202020   
  9759 00004281 202020202020202020-     db  "                                                                                " 
  9759 0000428A 202020202020202020-
  9759 00004293 202020202020202020-
  9759 0000429C 202020202020202020-
  9759 000042A5 202020202020202020-
  9759 000042AE 202020202020202020-
  9759 000042B7 202020202020202020-
  9759 000042C0 202020202020202020-
  9759 000042C9 2020202020202020   
  9760 000042D1 507265737320455343-     db  "Press ESC to cancel.                                                            "
  9760 000042DA 20746F2063616E6365-
  9760 000042E3 6C2E20202020202020-
  9760 000042EC 202020202020202020-
  9760 000042F5 202020202020202020-
  9760 000042FE 202020202020202020-
  9760 00004307 202020202020202020-
  9760 00004310 202020202020202020-
  9760 00004319 2020202020202020   
  9761 00004321 202020202020202020-     db  "                                                                                " 
  9761 0000432A 202020202020202020-
  9761 00004333 202020202020202020-
  9761 0000433C 202020202020202020-
  9761 00004345 202020202020202020-
  9761 0000434E 202020202020202020-
  9761 00004357 202020202020202020-
  9761 00004360 202020202020202020-
  9761 00004369 2020202020202020   
  9762 00004371 00                      db  0
  9763                                  
  9764                                  TrDOS_Welcome:
  9765 00004372 0D0A                    	db	0Dh, 0Ah
  9766 00004374 54522D444F53203338-     	db	'TR-DOS 386 Fixed Disk Partitioning Utility'
  9766 0000437D 362046697865642044-
  9766 00004386 69736B205061727469-
  9766 0000438F 74696F6E696E672055-
  9766 00004398 74696C697479       
  9767 0000439E 0D0A                    	db	0Dh, 0Ah
  9768 000043A0 76312E302E32313033-     	db	"v1.0.210321 (c) Erdogan TAN 2021"
  9768 000043A9 323120286329204572-
  9768 000043B2 646F67616E2054414E-
  9768 000043BB 2032303231         
  9769 000043C0 0D0A                    	db	0Dh,0Ah
  9770 000043C2 0D0A                    	db	0Dh,0Ah
  9771 000043C4 00                      	db	0
  9772                                  TrDOS_Usage:
  9773 000043C5 55736167653A206664-     	db	'Usage: fdisk3 <hard disk name> '
  9773 000043CE 69736B33203C686172-
  9773 000043D7 64206469736B206E61-
  9773 000043E0 6D653E20           
  9774 000043E4 0D0A                    	db	0Dh, 0Ah
  9775 000043E6 0D0A                    	db	0Dh, 0Ah
  9776 000043E8 48617264206469736B-     	db	"Hard disk names: "
  9776 000043F1 206E616D65733A20   
  9777 000043F9 0D0A                    	db	0Dh, 0Ah
  9778 000043FB 0D0A                    	db	0Dh, 0Ah
  9779 000043FD 20686430202E2E666F-     	db	" hd0 ..for 1st hard disk "
  9779 00004406 722031737420686172-
  9779 0000440F 64206469736B20     
  9780 00004416 0D0A                    	db	0Dh, 0Ah
  9781 00004418 20686431202E2E666F-     	db	" hd1 ..for 2nd hard disk "
  9781 00004421 7220326E6420686172-
  9781 0000442A 64206469736B20     
  9782 00004431 0D0A                    	db	0Dh, 0Ah
  9783 00004433 20686432202E2E666F-     	db	" hd2 ..for 3rd hard disk "
  9783 0000443C 722033726420686172-
  9783 00004445 64206469736B20     
  9784 0000444C 0D0A                    	db	0Dh, 0Ah
  9785 0000444E 20686433202E2E666F-     	db	" hd3 ..for 4th hard disk "
  9785 00004457 722034746820686172-
  9785 00004460 64206469736B20     
  9786 00004467 0D0A00                  	db	0Dh, 0Ah, 0
  9787                                  
  9788                                  TrDOS_Options:
  9789 0000446A 53656C656374206861-     	db	"Select hard disk number (1 to "
  9789 00004473 7264206469736B206E-
  9789 0000447C 756D62657220283120-
  9789 00004485 746F20             
  9790                                  TrDOS_dnmax:
  9791 00004488 3429206F7220707265-     	db	"4) or press ESC to exit ..." 
  9791 00004491 73732045534320746F-
  9791 0000449A 2065786974202E2E2E 
  9792 000044A3 0D0A00                  	db	0Dh, 0Ah, 0
  9793                                  TrDOS_hdrow:
  9794 000044A6 0D0A                    	db	0Dh, 0Ah 
  9795 000044A8 28                      	db	"("
  9796                                  TrDOS_hdrow_n:
  9797 000044A9 3029206864              	db	"0) hd"
  9798                                  TrDOS_hdrow_i:
  9799 000044AE 30202D204361706163-     	db	"0 - Capacity : "
  9799 000044B7 697479203A20       
  9800 000044BD 00                      	db	0
  9801                                  TrDOS_hdrow_unit:
  9802 000044BE 474220                  	db	"GB "
  9803 000044C1 0D0A00                  	db 	0Dh, 0Ah, 0
  9804                                  
  9805                                  TrDOS_hdrow_capacity:
  9806 000044C4 303030302000            	db	"0000 ", 0
  9807 000044CA 00                      	db	0
  9808                                  
  9809                                  TrDOS_disksize:
  9810 000044CB 0D0A                    	db	0Dh, 0Ah
  9811 000044CD 4469736B2073697A65-     	db	"Disk size : "
  9811 000044D6 203A20             
  9812 000044D9 00                      	db	0
  9813                                  
  9814                                  msg_fdisk_capacity_err:
  9815 000044DA 0D0A                    	db	0Dh, 0Ah
  9816 000044DC 48756765206469736B-     	db	"Huge disk !"
  9816 000044E5 2021               
  9817 000044E7 0D0A                    	db	0Dh, 0Ah
  9818 000044E9 546869732046444953-     	db	"This FDISK version (v3) can work with disk sizes up to "
  9818 000044F2 4B2076657273696F6E-
  9818 000044FB 20287633292063616E-
  9818 00004504 20776F726B20776974-
  9818 0000450D 68206469736B207369-
  9818 00004516 7A657320757020746F-
  9818 0000451F 20                 
  9819 00004520 00                      	db	0
  9820                                  
  9821                                  msg_any_key_esc_exit:
  9822 00004521 0D0A                    	db	0Dh, 0Ah
  9823 00004523 507265737320455343-     	db	"Press ESC to exit or press another key to continue..."
  9823 0000452C 20746F206578697420-
  9823 00004535 6F7220707265737320-
  9823 0000453E 616E6F74686572206B-
  9823 00004547 657920746F20636F6E-
  9823 00004550 74696E75652E2E2E   
  9824 00004558 00                      	db	0
  9825                                  
  9826                                  msg_create_partition_h:
  9827 00004559 0D0A                    	db	0Dh, 0Ah
  9828 0000455B 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"
  9828 00004564 2D2D2D2D2D2D2D2D2D-
  9828 0000456D 2D2D2D2D2D2D2D2D2D-
  9828 00004576 2D2D2D2D2D2D2D2D2D-
  9828 0000457F 2D2D2D2D2D2D2D2D2D-
  9828 00004588 2D2D2D2D2D2D2D2D2D-
  9828 00004591 2D2D2D2D2D2D2D2D2D-
  9828 0000459A 2D2D2D2D2D2D2D2D2D-
  9828 000045A3 2D2D2D2D2D2D2D2D   
  9829 000045AB 202020202020202020-     	db	"                               Create Partition                                 "
  9829 000045B4 202020202020202020-
  9829 000045BD 202020202020202020-
  9829 000045C6 202020204372656174-
  9829 000045CF 652050617274697469-
  9829 000045D8 6F6E20202020202020-
  9829 000045E1 202020202020202020-
  9829 000045EA 202020202020202020-
  9829 000045F3 2020202020202020   
  9830 000045FB 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"	
  9830 00004604 2D2D2D2D2D2D2D2D2D-
  9830 0000460D 2D2D2D2D2D2D2D2D2D-
  9830 00004616 2D2D2D2D2D2D2D2D2D-
  9830 0000461F 2D2D2D2D2D2D2D2D2D-
  9830 00004628 2D2D2D2D2D2D2D2D2D-
  9830 00004631 2D2D2D2D2D2D2D2D2D-
  9830 0000463A 2D2D2D2D2D2D2D2D2D-
  9830 00004643 2D2D2D2D2D2D2D2D   
  9831 0000464B 0D0A00                  	db	0Dh, 0Ah, 0
  9832                                  msg_create_partition_m:
  9833 0000464E 53656C65637420616E-     	db	"Select an option: "
  9833 00004657 206F7074696F6E3A20 
  9834 00004660 0D0A                    	db	0Dh, 0Ah
  9835 00004662 0D0A                    	db	0Dh, 0Ah
  9836 00004664 202031292043726561-     	db	"  1) Create DOS partition ", 0Dh, 0Ah
  9836 0000466D 746520444F53207061-
  9836 00004676 72746974696F6E200D-
  9836 0000467F 0A                 
  9837 00004680 202032292043726561-     	db	"  2) Create SINGLIX FS partition ", 0Dh, 0Ah			
  9837 00004689 74652053494E474C49-
  9837 00004692 582046532070617274-
  9837 0000469B 6974696F6E200D0A   
  9838 000046A3 202033292043726561-     	db	"  3) Create RETRO UNIX partition ", 0Dh, 0Ah
  9838 000046AC 746520524554524F20-
  9838 000046B5 554E49582070617274-
  9838 000046BE 6974696F6E200D0A   
  9839 000046C6 202034292043726561-     	db	"  4) Create another type of partition ", 0Dh, 0Ah 		
  9839 000046CF 746520616E6F746865-
  9839 000046D8 722074797065206F66-
  9839 000046E1 20706172746974696F-
  9839 000046EA 6E200D0A           
  9840 000046EE 0D0A                    	db	0Dh, 0Ah	
  9841 000046F0 507265737320455343-     	db	"Press ESC or 0 to cancel .. "
  9841 000046F9 206F72203020746F20-
  9841 00004702 63616E63656C202E2E-
  9841 0000470B 20                 
  9842 0000470C 0D0A00                   	db 	0Dh, 0Ah, 0	
  9843                                  
  9844                                  msg_create_primary_partition_h:
  9845 0000470F 0D0A                    	db	0Dh, 0Ah
  9846 00004711 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"
  9846 0000471A 2D2D2D2D2D2D2D2D2D-
  9846 00004723 2D2D2D2D2D2D2D2D2D-
  9846 0000472C 2D2D2D2D2D2D2D2D2D-
  9846 00004735 2D2D2D2D2D2D2D2D2D-
  9846 0000473E 2D2D2D2D2D2D2D2D2D-
  9846 00004747 2D2D2D2D2D2D2D2D2D-
  9846 00004750 2D2D2D2D2D2D2D2D2D-
  9846 00004759 2D2D2D2D2D2D2D2D   
  9847 00004761 202020202020202020-     	db	"                          Create Primary DOS Partition                          "
  9847 0000476A 202020202020202020-
  9847 00004773 202020202020202043-
  9847 0000477C 726561746520507269-
  9847 00004785 6D61727920444F5320-
  9847 0000478E 506172746974696F6E-
  9847 00004797 202020202020202020-
  9847 000047A0 202020202020202020-
  9847 000047A9 2020202020202020   
  9848 000047B1 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"	
  9848 000047BA 2D2D2D2D2D2D2D2D2D-
  9848 000047C3 2D2D2D2D2D2D2D2D2D-
  9848 000047CC 2D2D2D2D2D2D2D2D2D-
  9848 000047D5 2D2D2D2D2D2D2D2D2D-
  9848 000047DE 2D2D2D2D2D2D2D2D2D-
  9848 000047E7 2D2D2D2D2D2D2D2D2D-
  9848 000047F0 2D2D2D2D2D2D2D2D2D-
  9848 000047F9 2D2D2D2D2D2D2D2D   
  9849 00004801 0D0A00                  	db	0Dh, 0Ah, 0	
  9850                                  
  9851                                  msg_create_dos_partition_h:
  9852 00004804 0D0A                    	db	0Dh, 0Ah
  9853 00004806 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"
  9853 0000480F 2D2D2D2D2D2D2D2D2D-
  9853 00004818 2D2D2D2D2D2D2D2D2D-
  9853 00004821 2D2D2D2D2D2D2D2D2D-
  9853 0000482A 2D2D2D2D2D2D2D2D2D-
  9853 00004833 2D2D2D2D2D2D2D2D2D-
  9853 0000483C 2D2D2D2D2D2D2D2D2D-
  9853 00004845 2D2D2D2D2D2D2D2D2D-
  9853 0000484E 2D2D2D2D2D2D2D2D   
  9854 00004856 202020202020202020-     	db	"                   Create DOS Partition or Logical DOS Drive                    "
  9854 0000485F 202020202020202020-
  9854 00004868 204372656174652044-
  9854 00004871 4F5320506172746974-
  9854 0000487A 696F6E206F72204C6F-
  9854 00004883 676963616C20444F53-
  9854 0000488C 204472697665202020-
  9854 00004895 202020202020202020-
  9854 0000489E 2020202020202020   
  9855 000048A6 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"	
  9855 000048AF 2D2D2D2D2D2D2D2D2D-
  9855 000048B8 2D2D2D2D2D2D2D2D2D-
  9855 000048C1 2D2D2D2D2D2D2D2D2D-
  9855 000048CA 2D2D2D2D2D2D2D2D2D-
  9855 000048D3 2D2D2D2D2D2D2D2D2D-
  9855 000048DC 2D2D2D2D2D2D2D2D2D-
  9855 000048E5 2D2D2D2D2D2D2D2D2D-
  9855 000048EE 2D2D2D2D2D2D2D2D   
  9856 000048F6 0D0A00                  	db	0Dh, 0Ah, 0	
  9857                                  
  9858                                  msg_create_ext_partition_h:
  9859 000048F9 0D0A                    	db	0Dh, 0Ah
  9860 000048FB 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"
  9860 00004904 2D2D2D2D2D2D2D2D2D-
  9860 0000490D 2D2D2D2D2D2D2D2D2D-
  9860 00004916 2D2D2D2D2D2D2D2D2D-
  9860 0000491F 2D2D2D2D2D2D2D2D2D-
  9860 00004928 2D2D2D2D2D2D2D2D2D-
  9860 00004931 2D2D2D2D2D2D2D2D2D-
  9860 0000493A 2D2D2D2D2D2D2D2D2D-
  9860 00004943 2D2D2D2D2D2D2D2D   
  9861 0000494B 202020202020202020-     	db	"                         Create Extended DOS Partition                          "
  9861 00004954 202020202020202020-
  9861 0000495D 202020202020204372-
  9861 00004966 656174652045787465-
  9861 0000496F 6E64656420444F5320-
  9861 00004978 506172746974696F6E-
  9861 00004981 202020202020202020-
  9861 0000498A 202020202020202020-
  9861 00004993 2020202020202020   
  9862 0000499B 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"	
  9862 000049A4 2D2D2D2D2D2D2D2D2D-
  9862 000049AD 2D2D2D2D2D2D2D2D2D-
  9862 000049B6 2D2D2D2D2D2D2D2D2D-
  9862 000049BF 2D2D2D2D2D2D2D2D2D-
  9862 000049C8 2D2D2D2D2D2D2D2D2D-
  9862 000049D1 2D2D2D2D2D2D2D2D2D-
  9862 000049DA 2D2D2D2D2D2D2D2D2D-
  9862 000049E3 2D2D2D2D2D2D2D2D   
  9863 000049EB 0D0A00                  	db	0Dh, 0Ah, 0
  9864                                  
  9865                                  msg_create_logical_drive_h:
  9866 000049EE 0D0A                    	db	0Dh, 0Ah
  9867 000049F0 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"
  9867 000049F9 2D2D2D2D2D2D2D2D2D-
  9867 00004A02 2D2D2D2D2D2D2D2D2D-
  9867 00004A0B 2D2D2D2D2D2D2D2D2D-
  9867 00004A14 2D2D2D2D2D2D2D2D2D-
  9867 00004A1D 2D2D2D2D2D2D2D2D2D-
  9867 00004A26 2D2D2D2D2D2D2D2D2D-
  9867 00004A2F 2D2D2D2D2D2D2D2D2D-
  9867 00004A38 2D2D2D2D2D2D2D2D   
  9868 00004A40 202020202020202020-     	db	"                            Create Logical DOS Drive                            "
  9868 00004A49 202020202020202020-
  9868 00004A52 202020202020202020-
  9868 00004A5B 20437265617465204C-
  9868 00004A64 6F676963616C20444F-
  9868 00004A6D 532044726976652020-
  9868 00004A76 202020202020202020-
  9868 00004A7F 202020202020202020-
  9868 00004A88 2020202020202020   
  9869 00004A90 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"	
  9869 00004A99 2D2D2D2D2D2D2D2D2D-
  9869 00004AA2 2D2D2D2D2D2D2D2D2D-
  9869 00004AAB 2D2D2D2D2D2D2D2D2D-
  9869 00004AB4 2D2D2D2D2D2D2D2D2D-
  9869 00004ABD 2D2D2D2D2D2D2D2D2D-
  9869 00004AC6 2D2D2D2D2D2D2D2D2D-
  9869 00004ACF 2D2D2D2D2D2D2D2D2D-
  9869 00004AD8 2D2D2D2D2D2D2D2D   
  9870 00004AE0 0D0A00                  	db	0Dh, 0Ah, 0	
  9871                                  
  9872                                  msg_create_nondos_partition_h:
  9873 00004AE3 0D0A                    	db	0Dh, 0Ah
  9874 00004AE5 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"
  9874 00004AEE 2D2D2D2D2D2D2D2D2D-
  9874 00004AF7 2D2D2D2D2D2D2D2D2D-
  9874 00004B00 2D2D2D2D2D2D2D2D2D-
  9874 00004B09 2D2D2D2D2D2D2D2D2D-
  9874 00004B12 2D2D2D2D2D2D2D2D2D-
  9874 00004B1B 2D2D2D2D2D2D2D2D2D-
  9874 00004B24 2D2D2D2D2D2D2D2D2D-
  9874 00004B2D 2D2D2D2D2D2D2D2D   
  9875 00004B35 202020202020202020-     	db	"                            Create NON-DOS Partition                            "
  9875 00004B3E 202020202020202020-
  9875 00004B47 202020202020202020-
  9875 00004B50 20437265617465204E-
  9875 00004B59 4F4E2D444F53205061-
  9875 00004B62 72746974696F6E2020-
  9875 00004B6B 202020202020202020-
  9875 00004B74 202020202020202020-
  9875 00004B7D 2020202020202020   
  9876 00004B85 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"	
  9876 00004B8E 2D2D2D2D2D2D2D2D2D-
  9876 00004B97 2D2D2D2D2D2D2D2D2D-
  9876 00004BA0 2D2D2D2D2D2D2D2D2D-
  9876 00004BA9 2D2D2D2D2D2D2D2D2D-
  9876 00004BB2 2D2D2D2D2D2D2D2D2D-
  9876 00004BBB 2D2D2D2D2D2D2D2D2D-
  9876 00004BC4 2D2D2D2D2D2D2D2D2D-
  9876 00004BCD 2D2D2D2D2D2D2D2D   
  9877 00004BD5 0D0A00                  	db	0Dh, 0Ah, 0		
  9878                                  
  9879                                  msg_create_dos_partition_m:
  9880 00004BD8 53656C65637420616E-     	db	"Select an option: "
  9880 00004BE1 206F7074696F6E3A20 
  9881 00004BEA 0D0A                    	db	0Dh, 0Ah
  9882 00004BEC 0D0A                    	db	0Dh, 0Ah
  9883 00004BEE 202031292043726561-     	db	"  1) Create Primary DOS partition ", 0Dh, 0Ah
  9883 00004BF7 7465205072696D6172-
  9883 00004C00 7920444F5320706172-
  9883 00004C09 746974696F6E200D0A 
  9884 00004C12 202032292043726561-     	db	"  2) Create Extended DOS partition ", 0Dh, 0Ah			
  9884 00004C1B 746520457874656E64-
  9884 00004C24 656420444F53207061-
  9884 00004C2D 72746974696F6E200D-
  9884 00004C36 0A                 
  9885 00004C37 202033292043726561-     	db	"  3) Create Logical DOS drive(s) in Extended DOS partition ", 0Dh, 0Ah
  9885 00004C40 7465204C6F67696361-
  9885 00004C49 6C20444F5320647269-
  9885 00004C52 766528732920696E20-
  9885 00004C5B 457874656E64656420-
  9885 00004C64 444F53207061727469-
  9885 00004C6D 74696F6E200D0A     
  9886 00004C74 0D0A                    	db	0Dh, 0Ah	
  9887 00004C76 507265737320455343-     	db	"Press ESC or 0 to cancel .. "
  9887 00004C7F 206F72203020746F20-
  9887 00004C88 63616E63656C202E2E-
  9887 00004C91 20                 
  9888 00004C92 0D0A00                   	db 	0Dh, 0Ah, 0
  9889                                  
  9890                                  msg_create_trdos_partition_s:
  9891 00004C95 53656C65637420616E-     	db	"Select an option to set partition size: "
  9891 00004C9E 206F7074696F6E2074-
  9891 00004CA7 6F2073657420706172-
  9891 00004CB0 746974696F6E207369-
  9891 00004CB9 7A653A20           
  9892 00004CBD 0D0A                    	db	0Dh, 0Ah
  9893 00004CBF 0D0A                    	db	0Dh, 0Ah
  9894 00004CC1 202043292043796C69-     	db	"  C) Cylinder count", 0Dh, 0Ah   
  9894 00004CCA 6E64657220636F756E-
  9894 00004CD3 740D0A             
  9895 00004CD6 2020252920566F6C75-     	db	"  %) Volume percentage (##%)", 0Dh, 0Ah
  9895 00004CDF 6D652070657263656E-
  9895 00004CE8 746167652028232325-
  9895 00004CF1 290D0A             
  9896 00004CF4 202053292053656374-     	db	"  S) Sectors (number of 512 bytes)", 0Dh, 0Ah
  9896 00004CFD 6F727320286E756D62-
  9896 00004D06 6572206F6620353132-
  9896 00004D0F 206279746573290D0A 
  9897 00004D18 20204B29204B696C6F-     	db	"  K) Kilo bytes (KB, 2*K sectors)", 0Dh, 0Ah
  9897 00004D21 20627974657320284B-
  9897 00004D2A 422C20322A4B207365-
  9897 00004D33 63746F7273290D0A   
  9898 00004D3B 20204D29204D656761-     	db	"  M) Mega bytes (MB, 2*1024*M sectors)", 0Dh, 0Ah
  9898 00004D44 20627974657320284D-
  9898 00004D4D 422C20322A31303234-
  9898 00004D56 2A4D20736563746F72-
  9898 00004D5F 73290D0A           
  9899 00004D63 202047292047696761-     	db	"  G) Giga bytes (GB, 2*1024*1024*G sectors)", 0Dh, 0Ah			
  9899 00004D6C 206279746573202847-
  9899 00004D75 422C20322A31303234-
  9899 00004D7E 2A313032342A472073-
  9899 00004D87 6563746F7273290D0A 
  9900 00004D90 0D0A                    	db	0Dh, 0Ah	
  9901 00004D92 507265737320535041-     	db	"Press SPACE to use whole disk or press ENTER to set sector count .. "
  9901 00004D9B 434520746F20757365-
  9901 00004DA4 2077686F6C65206469-
  9901 00004DAD 736B206F7220707265-
  9901 00004DB6 737320454E54455220-
  9901 00004DBF 746F20736574207365-
  9901 00004DC8 63746F7220636F756E-
  9901 00004DD1 74202E2E20         
  9902                                  msg_press_esc_to_cancel:
  9903 00004DD6 0D0A                     	db	0Dh, 0Ah
  9904 00004DD8 285072657373204553-     	db	"(Press ESC to CANCEL) "
  9904 00004DE1 4320746F2043414E43-
  9904 00004DEA 454C2920           
  9905 00004DEE 0D0A00                  	db 	0Dh, 0Ah, 0
  9906                                  
  9907                                  msg_use_whole_disk:
  9908 00004DF1 446F20796F75207761-     	db	"Do you want to use WHOLE disk !? (Y/N)", 0
  9908 00004DFA 6E7420746F20757365-
  9908 00004E03 2057484F4C45206469-
  9908 00004E0C 736B20213F2028592F-
  9908 00004E15 4E2900             
  9909                                  
  9910                                  msg_use_all_space:
  9911 00004E18 446F20796F75207761-     	db	"Do you want to use all of available space !? (Y/N)", 0
  9911 00004E21 6E7420746F20757365-
  9911 00004E2A 20616C6C206F662061-
  9911 00004E33 7661696C61626C6520-
  9911 00004E3C 737061636520213F20-
  9911 00004E45 28592F4E2900       
  9912                                  
  9913                                  msg_use_entire_ep_space:
  9914 00004E4B 446F20796F75207761-     	db	"Do you want to use entire extended partition space !? (Y/N)", 0
  9914 00004E54 6E7420746F20757365-
  9914 00004E5D 20656E746972652065-
  9914 00004E66 7874656E6465642070-
  9914 00004E6F 6172746974696F6E20-
  9914 00004E78 737061636520213F20-
  9914 00004E81 28592F4E2900       
  9915                                  
  9916                                  msg_partition_size:
  9917 00004E87 0D0A                    	db	0Dh, 0Ah
  9918 00004E89 0D0A                    	db	0Dh, 0Ah
  9919 00004E8B 506172746974696F6E-     	db	"Partition size ("
  9919 00004E94 2073697A652028     
  9920                                  msg_partition_size_x:
  9921 00004E9B 3F29203A20              	db	"?) : "
  9922 00004EA0 00                      	db	0
  9923                                  
  9924                                  msg_partition_type:
  9925 00004EA1 0D0A                    	db	0Dh, 0Ah
  9926 00004EA3 0D0A                    	db	0Dh, 0Ah
  9927 00004EA5 506172746974696F6E-     	db	"Partition type : "
  9927 00004EAE 2074797065203A20   
  9928 00004EB6 00                      	db	0
  9929                                  
  9930                                  msg_ptype_num:
  9931 00004EB7 3030680D0A00            	db	"00h", 0Dh, 0Ah, 0
  9932                                  
  9933                                  msg_partition_type_error:
  9934 00004EBD 506172746974696F6E-     	db	"Partition size is not proper for selected partition type !"
  9934 00004EC6 2073697A6520697320-
  9934 00004ECF 6E6F742070726F7065-
  9934 00004ED8 7220666F722073656C-
  9934 00004EE1 656374656420706172-
  9934 00004EEA 746974696F6E207479-
  9934 00004EF3 70652021           
  9935 00004EF7 0D0A                    	db	0Dh, 0Ah
  9936                                  msg_any_key_to_retry:
  9937 00004EF9 28507265737320616E-     	db	"(Press any key to retry..)" 
  9937 00004F02 79206B657920746F20-
  9937 00004F0B 72657472792E2E29   
  9938 00004F13 0D0A00                  	db	0Dh, 0Ah, 0
  9939                                  
  9940                                  msg_partition_size_overs:
  9941 00004F16 0D0A                    	db	0Dh, 0Ah
  9942 00004F18 506172746974696F6E-     	db	"Partition size overs the disk capacity !"
  9942 00004F21 2073697A65206F7665-
  9942 00004F2A 727320746865206469-
  9942 00004F33 736B20636170616369-
  9942 00004F3C 74792021           
  9943 00004F40 0D0A                    	db	0Dh, 0Ah
  9944 00004F42 28507265737320454E-     	db	"(Press ENTER to use WHOLE disk or press ESC key to retry..)" 
  9944 00004F4B 54455220746F207573-
  9944 00004F54 652057484F4C452064-
  9944 00004F5D 69736B206F72207072-
  9944 00004F66 65737320455343206B-
  9944 00004F6F 657920746F20726574-
  9944 00004F78 72792E2E29         
  9945 00004F7D 0D0A00                  	db	0Dh, 0Ah, 0
  9946                                  
  9947                                  msg_ext_partition_error:
  9948 00004F80 457874656E64656420-     	db	"Extended partition must be created after primary partition !"
  9948 00004F89 706172746974696F6E-
  9948 00004F92 206D75737420626520-
  9948 00004F9B 637265617465642061-
  9948 00004FA4 66746572207072696D-
  9948 00004FAD 617279207061727469-
  9948 00004FB6 74696F6E2021       
  9949 00004FBC 0D0A00                  	db	0Dh, 0Ah,0
  9950                                  
  9951                                  msg_logical_drive_error:
  9952 00004FBF 5072696D6172792061-     	db	"Primary and extended partitions must be created before logical drive !"
  9952 00004FC8 6E6420657874656E64-
  9952 00004FD1 656420706172746974-
  9952 00004FDA 696F6E73206D757374-
  9952 00004FE3 206265206372656174-
  9952 00004FEC 6564206265666F7265-
  9952 00004FF5 206C6F676963616C20-
  9952 00004FFE 64726976652021     
  9953 00005005 0D0A00                  	db	0Dh, 0Ah,0
  9954                                  
  9955                                  msg_cylinder_boundary_set:
  9956 00005008 0D0A                    	db	0Dh, 0Ah
  9957 0000500A 446F20796F75207761-     	db	"Do you want to adjust partition size to cylinder boundary ? (Y/N)"
  9957 00005013 6E7420746F2061646A-
  9957 0000501C 757374207061727469-
  9957 00005025 74696F6E2073697A65-
  9957 0000502E 20746F2063796C696E-
  9957 00005037 64657220626F756E64-
  9957 00005040 617279203F2028592F-
  9957 00005049 4E29               
  9958 0000504B 00                      	db	0
  9959                                  
  9960                                  	; 2019 - 2020 (hdimage.s)
  9961                                  ;msg_selected_partition:
  9962                                  ;	db	"                                 PARTITION 0                                    "
  9963                                  ;	db	"================================================================================"
  9964                                  ;	db	"        S  BH  BS  BC  FS  EH  ES  EC    START SEC   SECTORS   FILE SYSTEM      "
  9965                                  ;	db	"--------------------------------------------------------------------------------"
  9966                                  ;pt_row: db	"                                                                                "
  9967                                  ;	db	"================================================================================"
  9968                                  ;	db	0
  9969                                  
  9970                                  	; 24/10/2020 (fdisk3.s)
  9971                                  msg_selected_partition:
  9972 0000504C 202020202020202020-     	db	"                                 PARTITION 0                                    "
  9972 00005055 202020202020202020-
  9972 0000505E 202020202020202020-
  9972 00005067 202020202020504152-
  9972 00005070 544954494F4E203020-
  9972 00005079 202020202020202020-
  9972 00005082 202020202020202020-
  9972 0000508B 202020202020202020-
  9972 00005094 2020202020202020   
  9973 0000509C 3D3D3D3D3D3D3D3D3D-     	db	"================================================================================"
  9973 000050A5 3D3D3D3D3D3D3D3D3D-
  9973 000050AE 3D3D3D3D3D3D3D3D3D-
  9973 000050B7 3D3D3D3D3D3D3D3D3D-
  9973 000050C0 3D3D3D3D3D3D3D3D3D-
  9973 000050C9 3D3D3D3D3D3D3D3D3D-
  9973 000050D2 3D3D3D3D3D3D3D3D3D-
  9973 000050DB 3D3D3D3D3D3D3D3D3D-
  9973 000050E4 3D3D3D3D3D3D3D3D   
  9974 000050EC 202020202020205320-     	db	"       S  BH  BS  BC  FS  EH  ES  EC   START SECT    SECTORS   FILE SYSTEM      "
  9974 000050F5 204248202042532020-
  9974 000050FE 424320204653202045-
  9974 00005107 482020455320204543-
  9974 00005110 202020535441525420-
  9974 00005119 534543542020202053-
  9974 00005122 4543544F5253202020-
  9974 0000512B 46494C452053595354-
  9974 00005134 454D202020202020   
  9975 0000513C 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"
  9975 00005145 2D2D2D2D2D2D2D2D2D-
  9975 0000514E 2D2D2D2D2D2D2D2D2D-
  9975 00005157 2D2D2D2D2D2D2D2D2D-
  9975 00005160 2D2D2D2D2D2D2D2D2D-
  9975 00005169 2D2D2D2D2D2D2D2D2D-
  9975 00005172 2D2D2D2D2D2D2D2D2D-
  9975 0000517B 2D2D2D2D2D2D2D2D2D-
  9975 00005184 2D2D2D2D2D2D2D2D   
  9976 0000518C 202020202020202020-     pt_row:	db	"                                                                                "
  9976 00005195 202020202020202020-
  9976 0000519E 202020202020202020-
  9976 000051A7 202020202020202020-
  9976 000051B0 202020202020202020-
  9976 000051B9 202020202020202020-
  9976 000051C2 202020202020202020-
  9976 000051CB 202020202020202020-
  9976 000051D4 2020202020202020   
  9977 000051DC 3D3D3D3D3D3D3D3D3D-     	db	"================================================================================"
  9977 000051E5 3D3D3D3D3D3D3D3D3D-
  9977 000051EE 3D3D3D3D3D3D3D3D3D-
  9977 000051F7 3D3D3D3D3D3D3D3D3D-
  9977 00005200 3D3D3D3D3D3D3D3D3D-
  9977 00005209 3D3D3D3D3D3D3D3D3D-
  9977 00005212 3D3D3D3D3D3D3D3D3D-
  9977 0000521B 3D3D3D3D3D3D3D3D3D-
  9977 00005224 3D3D3D3D3D3D3D3D   
  9978 0000522C 00                      	db	0
  9979                                  msg_boot_indicator:
  9980 0000522D 0D0A                    	db	0Dh, 0Ah
  9981 0000522F 20202020426F6F7420-     	db	"    Boot Indicator : ", 0 ; "YES", "NO"
  9981 00005238 496E64696361746F72-
  9981 00005241 203A2000           
  9982                                  msg_starting_head:
  9983 00005245 0D0A                    	db	0Dh, 0Ah
  9984 00005247 202020202053746172-     	db 	"     Starting Head : ", 0
  9984 00005250 74696E672048656164-
  9984 00005259 203A2000           
  9985                                  msg_starting_sector:
  9986 0000525D 0D0A                    	db	0Dh, 0Ah
  9987 0000525F 202020537461727469-     	db	"   Starting Sector : ", 0
  9987 00005268 6E6720536563746F72-
  9987 00005271 203A2000           
  9988                                  msg_starting_cylinder:
  9989 00005275 0D0A                    	db	0Dh, 0Ah
  9990 00005277 205374617274696E67-     	db	" Starting Cylinder : ", 0
  9990 00005280 2043796C696E646572-
  9990 00005289 203A2000           
  9991                                  msg_system_id:
  9992 0000528D 0D0A                    	db	0Dh, 0Ah
  9993 0000528F 202020202020202020-     	db	"         System ID : ", 0
  9993 00005298 53797374656D204944-
  9993 000052A1 203A2000           
  9994                                  msg_ending_head:
  9995 000052A5 0D0A                    	db	0Dh, 0Ah
  9996 000052A7 20202020202020456E-     	db 	"       Ending Head : ", 0
  9996 000052B0 64696E672048656164-
  9996 000052B9 203A2000           
  9997                                  msg_ending_sector:
  9998 000052BD 0D0A                    	db	0Dh, 0Ah
  9999 000052BF 2020202020456E6469-     	db	"     Ending Sector : ", 0
  9999 000052C8 6E6720536563746F72-
  9999 000052D1 203A2000           
 10000                                  msg_ending_cylinder:
 10001 000052D5 0D0A                    	db	0Dh, 0Ah
 10002 000052D7 202020456E64696E67-     	db	"   Ending Cylinder : ", 0
 10002 000052E0 2043796C696E646572-
 10002 000052E9 203A2000           
 10003                                  msg_relative_sectors:
 10004 000052ED 0D0A                    	db	0Dh, 0Ah
 10005 000052EF 0D0A                    	db	0Dh, 0Ah
 10006 000052F1 202052656C61746976-     	db	"  Relative Sectors : ", 0
 10006 000052FA 6520536563746F7273-
 10006 00005303 203A2000           
 10007                                  msg_total_sectors:
 10008 00005307 0D0A                    	db	0Dh, 0Ah
 10009 00005309 2020202020546F7461-     	db	"     Total Sectors : ", 0
 10009 00005312 6C20536563746F7273-
 10009 0000531B 203A2000           
 10010                                  
 10011                                  msg_format_stage:
 10012 0000531F 0D0A                    	db	0Dh, 0Ah
 10013 00005321 507265737320454E54-     	db	"Press ENTER to FORMAT disk partition "
 10013 0000532A 455220746F20464F52-
 10013 00005333 4D4154206469736B20-
 10013 0000533C 706172746974696F6E-
 10013 00005345 20                 
 10014                                  partition_num_chr:
 10015 00005346 30                      	db	"0"
 10016 00005347 206F72207072657373-     	db	" or press ESC to EXIT.."
 10016 00005350 2045534320746F2045-
 10016 00005359 5849542E2E         
 10017 0000535E 00                      	db	0
 10018                                  msg_partition_edit:
 10019 0000535F 0D0A                    	db	0Dh, 0Ah
 10020 00005361 2E2E206F7220707265-     	db	".. or press SPACE to EDIT partition table."
 10020 0000536A 737320535041434520-
 10020 00005373 746F20454449542070-
 10020 0000537C 6172746974696F6E20-
 10020 00005385 7461626C652E       
 10021 0000538B 0D0A00                  	db	0Dh, 0Ah, 0
 10022                                  
 10023                                  msg_edit_or_exit:
 10024 0000538E 0D0A                    	db 	0Dh, 0Ah
 10025 00005390 507265737320454E54-     	db	"Press ENTER to continue or press ESC to exit.."
 10025 00005399 455220746F20636F6E-
 10025 000053A2 74696E7565206F7220-
 10025 000053AB 707265737320455343-
 10025 000053B4 20746F20657869742E-
 10025 000053BD 2E                 
 10026 000053BE 00                      	db	0
 10027                                  
 10028                                  msg_overwrite_question1:
 10029 000053BF 0D0A                    	db	0Dh, 0Ah
 10030 000053C1 446F20796F75207761-     	db	'Do you want to overwrite '
 10030 000053CA 6E7420746F206F7665-
 10030 000053D3 72777269746520     
 10031 000053DA 27                      	db	27h
 10032 000053DB 00                      	db	0
 10033                                  
 10034                                  msg_overwrite_question2: 
 10035 000053DC 27                      	db	27h
 10036 000053DD 2066696C6520            	db	' file '
 10037 000053E3 00                      	db	0
 10038                                  
 10039                                  msg_format_question:
 10040 000053E4 0D0A                    	db	0Dh, 0Ah
 10041 000053E6 446F20796F75207761-     	db	"Do you want to format partition "
 10041 000053EF 6E7420746F20666F72-
 10041 000053F8 6D6174207061727469-
 10041 00005401 74696F6E20         
 10042                                  partition_num_txt:
 10043 00005406 3020                    	db	 "0 "
 10044                                  msg_yes_no:
 10045 00005408 285965732F4E6F293F-     	db	'(Yes/No)? ', 0		
 10045 00005411 2000               
 10046                                  
 10047                                  msg_writing_mbr:
 10048 00005413 57726974696E67206D-     	db	"Writing masterboot sector...", 0
 10048 0000541C 6173746572626F6F74-
 10048 00005425 20736563746F722E2E-
 10048 0000542E 2E00               
 10049                                  
 10050                                  msg_writing_disk_sectors:
 10051 00005430 57726974696E672064-     	db	"Writing disk sector: ", 0
 10051 00005439 69736B20736563746F-
 10051 00005442 723A2000           
 10052                                  
 10053                                  Msg_Writing_Boot_Sector:
 10054 00005446 57726974696E672074-     	db	"Writing trdos boot sector...", 0
 10054 0000544F 72646F7320626F6F74-
 10054 00005458 20736563746F722E2E-
 10054 00005461 2E00               
 10055                                  
 10056                                  Msg_Writing_Root_Dir:
 10057 00005463 57726974696E672072-     	db	"Writing root directory sectors...", 0
 10057 0000546C 6F6F74206469726563-
 10057 00005475 746F72792073656374-
 10057 0000547E 6F72732E2E2E00     
 10058                                  
 10059                                  Msg_Writing_Data_Sectors:
 10060 00005485 57726974696E672064-     	db	"Writing data sector: ", 0
 10060 0000548E 61746120736563746F-
 10060 00005497 723A2000           
 10061                                  
 10062                                  Sector_Str:
 10063 0000549B 3030303030303000        	db	"0000000", 0
 10064                                  Cursor_Pos:
 10065 000054A3 0000                    	dw	0
 10066                                  
 10067                                  Msg_Writing_FAT_Sectors:
 10068 000054A5 57726974696E672046-     	db	"Writing FAT sectors...", 0
 10068 000054AE 415420736563746F72-
 10068 000054B7 732E2E2E00         
 10069                                  
 10070                                  StrVolumeName:
 10071                                  	;times 	12 db  0
 10072 000054BC 00<rep 41h>             	times	65 db 0  ; 05/01/2018 (fs1 volume name)	
 10073                                  
 10074                                  Msg_Volume_Name:
 10075 000054FD 0D0A                    	db	0Dh, 0Ah
 10076 000054FF 0D0A                    	db	0Dh, 0Ah
 10077 00005501 566F6C756D65204E61-     	db	"Volume Name: ", 0
 10077 0000550A 6D653A2000         
 10078                                  
 10079                                  Msg_Volume_Serial:
 10080 0000550F 566F6C756D65205365-     	db	"Volume Serial No: "
 10080 00005518 7269616C204E6F3A20 
 10081                                  Vol_Serial1:
 10082 00005521 30303030                	db	"0000"
 10083 00005525 2D                      	db	"-"
 10084                                  Vol_Serial2:
 10085 00005526 30303030                	db	"0000"
 10086 0000552A 0D0A00                  	db	0Dh, 0Ah, 0
 10087                                  
 10088                                  msg_cluster_count:
 10089 0000552D 436C75737465722043-     	db	"Cluster Count: ", 0
 10089 00005536 6F756E743A2000     
 10090                                  cluster_count_str:
 10091 0000553D 30303030303030          	db	"0000000"
 10092 00005544 0D0A00                  	db	0Dh, 0Ah, 0
 10093                                  msg_formatting:
 10094 00005547 466F726D617474696E-     	db	"Formatting ", 0
 10094 00005550 672000             
 10095                                  format_percent_str:
 10096 00005553 30303025                	db	"000%"
 10097 00005557 00                      	db	0					
 10098                                  
 10099                                  Msg_3dot_OK:
 10100 00005558 2E2E2E                  	db	"..."
 10101                                  Msg_OK:
 10102 0000555B 204F4B2E                	db	' OK.'
 10103                                  CRLF:
 10104 0000555F 0D0A00                  	db	0Dh, 0Ah, 0
 10105                                  
 10106                                  Msg_Error:
 10107 00005562 0D0A                    	db	0Dh, 0Ah
 10108 00005564 4572726F72202120        	db	'Error ! '
 10109 0000556C 28                      	db	'('
 10110                                  error_code:
 10111 0000556D 3030                    	dw	3030h
 10112 0000556F 68                      	db	'h'
 10113 00005570 2920                    	db	') '
 10114 00005572 0D0A                    	db	0Dh, 0Ah
 10115 00005574 00                      	db	0
 10116                                  
 10117                                  msg_disk_sectors:
 10118 00005575 546F74616C20446973-     	db	"Total Disk Sectors : ", 0
 10118 0000557E 6B20536563746F7273-
 10118 00005587 203A2000           
 10119                                  
 10120                                  str_disk_sectors:
 10121                                  	;times	8 db 0
 10122 0000558B 00<rep Bh>              	times	11 db 0 ; 27/10/2020
 10123                                  
 10124                                  msg_ep_size:
 10125 00005596 457874656E64656420-     	db	"Extended Partition Size in Sectors: ", 0
 10125 0000559F 506172746974696F6E-
 10125 000055A8 2053697A6520696E20-
 10125 000055B1 536563746F72733A20-
 10125 000055BA 00                 
 10126                                  
 10127                                  msg_press_any_key:
 10128 000055BB 0D0A                    	db	0Dh, 0Ah
 10129 000055BD 50726573732061206B-     	db	"Press a key to continue..." 
 10129 000055C6 657920746F20636F6E-
 10129 000055CF 74696E75652E2E2E   
 10130 000055D7 0D0A00                  	db	0Dh, 0Ah, 0
 10131                                  
 10132                                  align 2
 10133                                  
 10134                                  ; Masterboot sector
 10135                                  
 10136                                  MasterBootBuff:
 10137                                  MasterBootCode: 
 10138 000055DA 00<rep 1BEh>            	times	446 db 0
 10139                                  PartitionTable:
 10140 00005798 00<rep 40h>             	times	64 db 0
 10141                                  MBIDCode:
 10142 000057D8 0000                    	dw	0
 10143                                  
 10144                                  PTable_Buffer:
 10145 000057DA 00<rep 40h>             	times	64 db 0
 10146                                   
 10147 0000581A 286329204572646F67-     	db	'(c) Erdogan TAN 2019-2021'
 10147 00005823 616E2054414E203230-
 10147 0000582C 31392D32303231     
 10148                                  
 10149                                  ; 05/11/2020
 10150 00005833 00                      	db	0
 10151                                  
 10152                                  	; 2019 - 2020 (hdimage.s)
 10153                                  ;p_table_header:
 10154                                  ;	db	"                              ?BR PARTITION TABLE                               "
 10155                                  ;	db	"================================================================================"
 10156                                  ;	db	"       P  S  BH  BS  BC  FS  EH  ES  EC  START SEC  SECTORS  FILE SYSTEM        "
 10157                                  ;	db	"--------------------------------------------------------------------------------"
 10158                                  ;	db	0
 10159                                  ;p_table_footer:
 10160                                  ;	db	"================================================================================"
 10161                                  ;	db	0Dh, 0Ah, 0
 10162                                  
 10163                                  	; 24/10/2020 (fdisk3.s)
 10164                                  p_table_header:
 10165 00005834 202020202020202020-     	db	"                              ?BR PARTITION TABLE                               "
 10165 0000583D 202020202020202020-
 10165 00005846 202020202020202020-
 10165 0000584F 2020203F4252205041-
 10165 00005858 52544954494F4E2054-
 10165 00005861 41424C452020202020-
 10165 0000586A 202020202020202020-
 10165 00005873 202020202020202020-
 10165 0000587C 2020202020202020   
 10166 00005884 3D3D3D3D3D3D3D3D3D-     	db	"================================================================================"
 10166 0000588D 3D3D3D3D3D3D3D3D3D-
 10166 00005896 3D3D3D3D3D3D3D3D3D-
 10166 0000589F 3D3D3D3D3D3D3D3D3D-
 10166 000058A8 3D3D3D3D3D3D3D3D3D-
 10166 000058B1 3D3D3D3D3D3D3D3D3D-
 10166 000058BA 3D3D3D3D3D3D3D3D3D-
 10166 000058C3 3D3D3D3D3D3D3D3D3D-
 10166 000058CC 3D3D3D3D3D3D3D3D   
 10167 000058D4 202020502020205320-     	db	"   P   S  BH  BS  BC  FS  EH  ES  EC   START SECT    SECTORS    FILE SYSTEM     "
 10167 000058DD 204248202042532020-
 10167 000058E6 424320204653202045-
 10167 000058EF 482020455320204543-
 10167 000058F8 202020535441525420-
 10167 00005901 534543542020202053-
 10167 0000590A 4543544F5253202020-
 10167 00005913 2046494C4520535953-
 10167 0000591C 54454D2020202020   
 10168 00005924 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"
 10168 0000592D 2D2D2D2D2D2D2D2D2D-
 10168 00005936 2D2D2D2D2D2D2D2D2D-
 10168 0000593F 2D2D2D2D2D2D2D2D2D-
 10168 00005948 2D2D2D2D2D2D2D2D2D-
 10168 00005951 2D2D2D2D2D2D2D2D2D-
 10168 0000595A 2D2D2D2D2D2D2D2D2D-
 10168 00005963 2D2D2D2D2D2D2D2D2D-
 10168 0000596C 2D2D2D2D2D2D2D2D   
 10169 00005974 00                      	db	0
 10170                                  p_table_footer:
 10171 00005975 3D3D3D3D3D3D3D3D3D-     	db	"================================================================================"
 10171 0000597E 3D3D3D3D3D3D3D3D3D-
 10171 00005987 3D3D3D3D3D3D3D3D3D-
 10171 00005990 3D3D3D3D3D3D3D3D3D-
 10171 00005999 3D3D3D3D3D3D3D3D3D-
 10171 000059A2 3D3D3D3D3D3D3D3D3D-
 10171 000059AB 3D3D3D3D3D3D3D3D3D-
 10171 000059B4 3D3D3D3D3D3D3D3D3D-
 10171 000059BD 3D3D3D3D3D3D3D3D   
 10172 000059C5 0D0A00                  	db	0Dh, 0Ah, 0
 10173                                  
 10174                                  mbr_editing_options:
 10175 000059C8 0D0A0D0A                	db	0Dh, 0Ah, 0Dh, 0Ah 
 10176 000059CC 4D4252205061727469-     	db	"MBR Partition Table Editing Options:" 
 10176 000059D5 74696F6E205461626C-
 10176 000059DE 652045646974696E67-
 10176 000059E7 204F7074696F6E733A 
 10177 000059F0 0D0A0D0A                	db	0Dh, 0Ah, 0Dh, 0Ah
 10178 000059F4 20202020202020312E-     	db	"       1. Create Partition", 0Dh, 0Ah
 10178 000059FD 204372656174652050-
 10178 00005A06 6172746974696F6E0D-
 10178 00005A0F 0A                 
 10179 00005A10 20202020202020322E-     	db	"       2. Set Active Partition", 0Dh, 0Ah
 10179 00005A19 205365742041637469-
 10179 00005A22 766520506172746974-
 10179 00005A2B 696F6E0D0A         
 10180 00005A30 20202020202020332E-     	db	"       3. Delete Partition", 0Dh, 0Ah  
 10180 00005A39 2044656C6574652050-
 10180 00005A42 6172746974696F6E0D-
 10180 00005A4B 0A                 
 10181 00005A4C 20202020202020342E-     	db	"       4. Write Current Partition Table", 0Dh, 0Ah, 0
 10181 00005A55 205772697465204375-
 10181 00005A5E 7272656E7420506172-
 10181 00005A67 746974696F6E205461-
 10181 00005A70 626C650D0A00       
 10182                                  
 10183                                  enter_option_number_msg:
 10184 00005A76 0D0A                    	db	0Dh, 0Ah
 10185 00005A78 456E74657220746865-     	db	"Enter the option number or press ESC to exit ...", 0Dh, 0Ah
 10185 00005A81 206F7074696F6E206E-
 10185 00005A8A 756D626572206F7220-
 10185 00005A93 707265737320455343-
 10185 00005A9C 20746F206578697420-
 10185 00005AA5 2E2E2E0D0A         
 10186                                  	;db	0Dh, 0Ah, 0
 10187 00005AAA 00                      	db	0 
 10188                                  
 10189                                  msg_zero_partition_size:  ; 19/02/2019
 10190 00005AAB 0D0A                    	db	0Dh, 0Ah
 10191 00005AAD 506172746974696F6E-     	db	"Partition size input must not be ZERO !", 0Dh, 0Ah
 10191 00005AB6 2073697A6520696E70-
 10191 00005ABF 7574206D757374206E-
 10191 00005AC8 6F74206265205A4552-
 10191 00005AD1 4F20210D0A         
 10192 00005AD6 285072657373204553-     	db	"(Press ESC to exit or press another key to retry..)", 0Dh, 0Ah
 10192 00005ADF 4320746F2065786974-
 10192 00005AE8 206F72207072657373-
 10192 00005AF1 20616E6F7468657220-
 10192 00005AFA 6B657920746F207265-
 10192 00005B03 7472792E2E290D0A   
 10193 00005B0B 00                      	db	0 
 10194                                  
 10195                                  msg_empty_pt:
 10196 00005B0C 0D0A                    	db	0Dh, 0Ah
 10197 00005B0E 456D70747920706172-     	db	"Empty partition table !", 0Dh, 0Ah
 10197 00005B17 746974696F6E207461-
 10197 00005B20 626C6520210D0A     
 10198 00005B27 28412076616C696420-     	db	"(A valid partition must be created at first..)", 0Dh, 0Ah
 10198 00005B30 706172746974696F6E-
 10198 00005B39 206D75737420626520-
 10198 00005B42 637265617465642061-
 10198 00005B4B 742066697273742E2E-
 10198 00005B54 290D0A             
 10199 00005B57 00                      	db	0
 10200                                  
 10201                                  msg_full_pt:
 10202 00005B58 0D0A                    	db	0Dh, 0Ah
 10203 00005B5A 546865726520697320-     	db	"There is not a free partition table entry ", 0
 10203 00005B63 6E6F74206120667265-
 10203 00005B6C 652070617274697469-
 10203 00005B75 6F6E207461626C6520-
 10203 00005B7E 656E7472792000     
 10204                                  msg_to_create_new_p: 
 10205 00005B85 746F20637265617465-     	db	"to create a new partition !", 0Dh, 0Ah
 10205 00005B8E 2061206E6577207061-
 10205 00005B97 72746974696F6E2021-
 10205 00005BA0 0D0A               
 10206 00005BA2 00                      	db	0
 10207                                  msg_no_free_space:
 10208 00005BA3 0D0A                    	db	0Dh, 0Ah
 10209 00005BA5 546865726520697320-     	db	"There is not (enough) free space ", 0
 10209 00005BAE 6E6F742028656E6F75-
 10209 00005BB7 676829206672656520-
 10209 00005BC0 73706163652000     
 10210                                  
 10211                                  msg_enter_pn_to_del:
 10212 00005BC7 0D0A                    	db	0Dh, 0Ah
 10213 00005BC9 456E74657220706172-     	db	"Enter partition number to delete: " 
 10213 00005BD2 746974696F6E206E75-
 10213 00005BDB 6D62657220746F2064-
 10213 00005BE4 656C6574653A20     
 10214                                  chr_del_pnum1:
 10215 00005BEB 00                      	db	0       
 10216 00005BEC 0D0A00                  	db	0Dh, 0Ah, 0
 10217                                  
 10218                                  msg_delete_partition_q:
 10219 00005BEF 0D0A                    	db 	0Dh, 0Ah
 10220 00005BF1 5741524E494E472120-     	db 	"WARNING! All of data in the selected partition will be lost", 0Dh, 0Ah
 10220 00005BFA 416C6C206F66206461-
 10220 00005C03 746120696E20746865-
 10220 00005C0C 2073656C6563746564-
 10220 00005C15 20706172746974696F-
 10220 00005C1E 6E2077696C6C206265-
 10220 00005C27 206C6F73740D0A     
 10221 00005C2E 202020202020202020-     	db	"         after you write changed partition table to disk !!", 0Dh, 0Ah
 10221 00005C37 616674657220796F75-
 10221 00005C40 207772697465206368-
 10221 00005C49 616E67656420706172-
 10221 00005C52 746974696F6E207461-
 10221 00005C5B 626C6520746F206469-
 10221 00005C64 736B2021210D0A     
 10222 00005C6B 0D0A                    	db	0Dh, 0Ah
 10223 00005C6D 446F20796F75207761-     	db	"Do you want to delete PARTITION " 
 10223 00005C76 6E7420746F2064656C-
 10223 00005C7F 657465205041525449-
 10223 00005C88 54494F4E20         
 10224                                  chr_del_pnum2:
 10225 00005C8D 30                      	db	'0'
 10226 00005C8E 203F2028592F4E2920-     	db	' ? (Y/N) ', 0
 10226 00005C97 00                 
 10227                                  
 10228                                  _msg_YES:
 10229 00005C98 20                      	db	 20h
 10230                                  msg_YES:
 10231 00005C99 5945532000              	db	'YES ', 0
 10232                                  _msg_NO:
 10233 00005C9E 20                      	db	20h
 10234                                  msg_NO:
 10235 00005C9F 4E4F2000                	db	'NO ', 0
 10236                                  
 10237                                  ; 11/02/2019
 10238                                  msg_write_masterboot_sector:
 10239 00005CA3 0D0A                    	db	0Dh, 0Ah 
 10240 00005CA5 577269746520437572-     	db	"Write Current Partition Table:" 
 10240 00005CAE 72656E742050617274-
 10240 00005CB7 6974696F6E20546162-
 10240 00005CC0 6C653A             
 10241 00005CC3 0D0A0D0A                	db	0Dh, 0Ah, 0Dh, 0Ah
 10242 00005CC7 20312E205772697465-     	db	" 1. Write Partition Table only", 0Dh, 0Ah
 10242 00005CD0 20506172746974696F-
 10242 00005CD9 6E205461626C65206F-
 10242 00005CE2 6E6C790D0A         
 10243 00005CE7 20322E205772697465-     	db	" 2. Write Partition Table and Singlix Master Boot Code", 0Dh, 0Ah
 10243 00005CF0 20506172746974696F-
 10243 00005CF9 6E205461626C652061-
 10243 00005D02 6E642053696E676C69-
 10243 00005D0B 78204D617374657220-
 10243 00005D14 426F6F7420436F6465-
 10243 00005D1D 0D0A               
 10244                                  enter_opt_num_cancel_msg:
 10245 00005D1F 0D0A                    	db	0Dh, 0Ah
 10246 00005D21 456E74657220746865-     	db	"Enter the option number or press ESC to cancel ...", 0           
 10246 00005D2A 206F7074696F6E206E-
 10246 00005D33 756D626572206F7220-
 10246 00005D3C 707265737320455343-
 10246 00005D45 20746F2063616E6365-
 10246 00005D4E 6C202E2E2E00       
 10247                                  
 10248                                  msg_writing_ptable:
 10249 00005D54 0D0A0D0A                	db	0Dh, 0Ah, 0Dh, 0Ah  
 10250 00005D58 57726974696E672070-     	db	"Writing partition table on disk ... ", 0
 10250 00005D61 6172746974696F6E20-
 10250 00005D6A 7461626C65206F6E20-
 10250 00005D73 6469736B202E2E2E20-
 10250 00005D7C 00                 
 10251                                  _msg_OK:
 10252                                  	;db	7
 10253 00005D7D 0D0A                    	db	0Dh, 0Ah
 10254 00005D7F 4F4B2021                	db	"OK !"
 10255 00005D83 0D0A00                  	db	0Dh, 0Ah, 0
 10256                                  
 10257                                  option_input:
 10258 00005D86 205B205D00              	db	' [ ]', 0
 10259                                  
 10260                                  msg_enter_pn_to_act:
 10261 00005D8B 0D0A                    	db	0Dh, 0Ah
 10262 00005D8D 456E74657220706172-     	db	"Enter partition number to set as active: ", 0 
 10262 00005D96 746974696F6E206E75-
 10262 00005D9F 6D62657220746F2073-
 10262 00005DA8 657420617320616374-
 10262 00005DB1 6976653A2000       
 10263                                  
 10264                                  trdos386_disk_chs_header:
 10265 00005DB7 0D0A                    	db	0Dh, 0Ah
 10266 00005DB9 202020202020202020-     	db	"                     TRDOS 386 (SINGLIX) HARD DISK IMAGE                        "
 10266 00005DC2 202020202020202020-
 10266 00005DCB 2020205452444F5320-
 10266 00005DD4 333836202853494E47-
 10266 00005DDD 4C4958292048415244-
 10266 00005DE6 204449534B20494D41-
 10266 00005DEF 474520202020202020-
 10266 00005DF8 202020202020202020-
 10266 00005E01 2020202020202020   
 10267 00005E09 00                      	db 	0
 10268                                  
 10269                                  disk_chs_header:
 10270 00005E0A 0D0A                    	db	0Dh, 0Ah
 10271 00005E0C 202020202020202020-     	db	"                                HARD DISK IMAGE                                 "
 10271 00005E15 202020202020202020-
 10271 00005E1E 202020202020202020-
 10271 00005E27 202020202048415244-
 10271 00005E30 204449534B20494D41-
 10271 00005E39 474520202020202020-
 10271 00005E42 202020202020202020-
 10271 00005E4B 202020202020202020-
 10271 00005E54 2020202020202020   
 10272 00005E5C 00                      	db 	0
 10273                                  
 10274                                  msg_partition_size_limit:
 10275 00005E5D 0D0A                    	db	0Dh, 0Ah
 10276 00005E5F 506172746974696F6E-     	db	"Partition size overs available free space !"
 10276 00005E68 2073697A65206F7665-
 10276 00005E71 727320617661696C61-
 10276 00005E7A 626C65206672656520-
 10276 00005E83 73706163652021     
 10277 00005E8A 0D0A                    	db	0Dh, 0Ah
 10278 00005E8C 4D61782E2061766169-     	db 	"Max. available free space is ", 0
 10278 00005E95 6C61626C6520667265-
 10278 00005E9E 652073706163652069-
 10278 00005EA7 732000             
 10279                                  
 10280                                  msg_partition_size_limit_r:
 10281 00005EAA 0D0A0D0A                	db	0Dh, 0Ah, 0Dh, 0Ah
 10282 00005EAE 28507265737320454E-     	db	"(Press ENTER to use all of available space or press ESC key to retry..) " 
 10282 00005EB7 54455220746F207573-
 10282 00005EC0 6520616C6C206F6620-
 10282 00005EC9 617661696C61626C65-
 10282 00005ED2 207370616365206F72-
 10282 00005EDB 207072657373204553-
 10282 00005EE4 43206B657920746F20-
 10282 00005EED 72657472792E2E2920 
 10283 00005EF6 000A00                  	db	0D, 0Ah, 0
 10284                                  
 10285                                  msg_cylinders:
 10286 00005EF9 2063796C696E646572-     	db	" cylinders", 0
 10286 00005F02 7300               
 10287                                  msg_sectors:
 10288 00005F04 20736563746F727300      	db	" sectors", 0
 10289                                  
 10290                                  ; 02/03/2019
 10291                                  msg_megabytes:
 10292 00005F0D 206D65676162797465      	db	" megabyte"
 10293                                  msg_megabytes_s:
 10294 00005F16 0000                    	db	0, 0
 10295                                  
 10296                                  msg_inv_pte:
 10297 00005F18 0D0A                    	db	0Dh, 0Ah
 10298 00005F1A 496E76616C69642070-     	db	"Invalid partition table entry ! (P"
 10298 00005F23 6172746974696F6E20-
 10298 00005F2C 7461626C6520656E74-
 10298 00005F35 72792021202850     
 10299 00005F3C 3F290D0A                inv_pte_num: db	"?)", 0Dh, 0Ah
 10300 00005F40 28507265737320454E-     	db	"(Press ENTER to DELETE or press ESC to EXIT..)"
 10300 00005F49 54455220746F204445-
 10300 00005F52 4C455445206F722070-
 10300 00005F5B 726573732045534320-
 10300 00005F64 746F20455849542E2E-
 10300 00005F6D 29                 
 10301 00005F6E 0D0A00                  	db	0Dh, 0Ah, 0
 10302                                  
 10303                                  msg_ext_partition_exists:
 10304 00005F71 457874656E64656420-     	db	"Extended partition already exists !"
 10304 00005F7A 706172746974696F6E-
 10304 00005F83 20616C726561647920-
 10304 00005F8C 6578697374732021   
 10305 00005F94 0D0A00                  	db	0Dh, 0Ah, 0
 10306                                  
 10307                                  msg_defective_pt:
 10308 00005F97 0D0A                    	db	0Dh, 0Ah
 10309 00005F99 446566656374697665-     	db	"Defective partition table !", 0
 10309 00005FA2 20706172746974696F-
 10309 00005FAB 6E207461626C652021-
 10309 00005FB4 00                 
 10310                                  
 10311                                  ; 27/02/2019
 10312                                  msg_ext_part_del_error:
 10313 00005FB5 0D0A                    	db	0Dh, 0Ah
 10314 00005FB7 457874656E64656420-     	db	"Extended partition must be deleted after logical drive(s) !"
 10314 00005FC0 706172746974696F6E-
 10314 00005FC9 206D75737420626520-
 10314 00005FD2 64656C657465642061-
 10314 00005FDB 66746572206C6F6769-
 10314 00005FE4 63616C206472697665-
 10314 00005FED 2873292021         
 10315 00005FF2 0D0A00                  	db	0Dh, 0Ah, 0
 10316                                  
 10317                                  msg_cancel_continue:
 10318 00005FF5 285072657373204553-     	db	"(Press ESC to cancel or press another key to continue..)"
 10318 00005FFE 4320746F2063616E63-
 10318 00006007 656C206F7220707265-
 10318 00006010 737320616E6F746865-
 10318 00006019 72206B657920746F20-
 10318 00006022 636F6E74696E75652E-
 10318 0000602B 2E29               
 10319 0000602D 0D0A00                  	db	0Dh, 0Ah, 0
 10320                                  
 10321                                  msg_delete_ldd:
 10322 00006030 0D0A                    	db	0Dh, 0Ah
 10323 00006032 0D0A                    	db	0Dh, 0Ah
 10324 00006034 44656C657465204C6F-     	db	"Delete Logical (DOS) Drive:"
 10324 0000603D 676963616C2028444F-
 10324 00006046 53292044726976653A 
 10325 0000604F 0D0A                    	db	0Dh, 0Ah
 10326 00006051 50726573732044454C-     	db	"Press DELETE key to delete logical disk partition "
 10326 0000605A 455445206B65792074-
 10326 00006063 6F2064656C65746520-
 10326 0000606C 6C6F676963616C2064-
 10326 00006075 69736B207061727469-
 10326 0000607E 74696F6E20         
 10327 00006083 3F2E                    lddp_num: db	"?."
 10328 00006085 0D0A00                  	db	0Dh, 0Ah, 0
 10329                                  
 10330                                  msg_delete_ext_part:
 10331 00006088 0D0A                    	db	0Dh, 0Ah
 10332 0000608A 0D0A                    	db	0Dh, 0Ah
 10333 0000608C 44656C657465204578-     	db	"Delete Extended (DOS) Partition:"
 10333 00006095 74656E646564202844-
 10333 0000609E 4F5329205061727469-
 10333 000060A7 74696F6E3A         
 10334 000060AC 0D0A                    	db	0Dh, 0Ah
 10335 000060AE 507265737320454E54-     	db	"Press ENTER to delete or press ESC to cancel.."
 10335 000060B7 455220746F2064656C-
 10335 000060C0 657465206F72207072-
 10335 000060C9 657373204553432074-
 10335 000060D2 6F2063616E63656C2E-
 10335 000060DB 2E                 
 10336 000060DC 0D0A00                  	db	0Dh, 0Ah, 0
 10337                                  
 10338                                  str_display_ebr_pt:
 10339 000060DF 285072657373205350-     	db	"(Press SPACE to edit EXTENDED Partition Table)", 0Dh, 0Ah, 0
 10339 000060E8 41434520746F206564-
 10339 000060F1 697420455854454E44-
 10339 000060FA 454420506172746974-
 10339 00006103 696F6E205461626C65-
 10339 0000610C 290D0A00           
 10340                                  
 10341                                  ebr_editing_options:
 10342 00006110 0D0A0D0A                	db	0Dh, 0Ah, 0Dh, 0Ah 
 10343 00006114 457874656E64656420-     	db	"Extended Partition Table Editing Options:" 
 10343 0000611D 506172746974696F6E-
 10343 00006126 205461626C65204564-
 10343 0000612F 6974696E67204F7074-
 10343 00006138 696F6E733A         
 10344 0000613D 0D0A0D0A                	db	0Dh, 0Ah, 0Dh, 0Ah
 10345 00006141 20202020202020312E-     	db	"       1. Create Logical DOS Drive", 0Dh, 0Ah
 10345 0000614A 20437265617465204C-
 10345 00006153 6F676963616C20444F-
 10345 0000615C 532044726976650D0A 
 10346 00006165 20202020202020322E-     	db	"       2. Delete Logical (DOS) Drive(s)",0Dh, 0Ah, 0
 10346 0000616E 2044656C657465204C-
 10346 00006177 6F676963616C202844-
 10346 00006180 4F5329204472697665-
 10346 00006189 2873290D0A00       
 10347                                  
 10348                                  msg_delete_ldd_q:
 10349 0000618F 0D0A                    	db 	0Dh, 0Ah
 10350 00006191 5741524E494E47210D-     	db 	"WARNING!", 0Dh, 0Ah 
 10350 0000619A 0A                 
 10351 0000619B 416C6C206F66206461-     	db	"All of data in logical (DOS) drive(s) will be lost !!", 0Dh, 0Ah
 10351 000061A4 746120696E206C6F67-
 10351 000061AD 6963616C2028444F53-
 10351 000061B6 292064726976652873-
 10351 000061BF 292077696C6C206265-
 10351 000061C8 206C6F73742021210D-
 10351 000061D1 0A                 
 10352 000061D2 0D0A                    	db	0Dh, 0Ah
 10353 000061D4 446F20796F75207761-     	db	"Do you want to continue ? (Y/N) ", 0
 10353 000061DD 6E7420746F20636F6E-
 10353 000061E6 74696E7565203F2028-
 10353 000061EF 592F4E292000       
 10354                                  
 10355                                  msg_create_ldd_max_error:
 10356 000061F5 0D0A                    	db	0Dh, 0Ah
 10357 000061F7 50726F6772616D206C-     	db	"Program limit for logical dos drive count is 4 !"
 10357 00006200 696D697420666F7220-
 10357 00006209 6C6F676963616C2064-
 10357 00006212 6F7320647269766520-
 10357 0000621B 636F756E7420697320-
 10357 00006224 342021             
 10358 00006227 0D0A00                  	db 	0Dh, 0Ah, 0
 10359                                  
 10360                                  msg_c_ldd_unused_warning:
 10361 0000622A 0D0A                    	db	0Dh, 0Ah
 10362 0000622C 546865726520697320-     	db	"There is unused extended partition space after logical dos drive "
 10362 00006235 756E75736564206578-
 10362 0000623E 74656E646564207061-
 10362 00006247 72746974696F6E2073-
 10362 00006250 706163652061667465-
 10362 00006259 72206C6F676963616C-
 10362 00006262 20646F732064726976-
 10362 0000626B 6520               
 10363                                  char_lddn:
 10364 0000626D 342021                  	db	"4 !"
 10365 00006270 0D0A                    	db 	0Dh, 0Ah
 10366 00006272 285072657373204553-     	db	"(Press ESC to add unused space or press ENTER to continue.)"	 
 10366 0000627B 4320746F2061646420-
 10366 00006284 756E75736564207370-
 10366 0000628D 616365206F72207072-
 10366 00006296 65737320454E544552-
 10366 0000629F 20746F20636F6E7469-
 10366 000062A8 6E75652E29         
 10367 000062AD 0D0A00                  	db 	0Dh, 0Ah, 0
 10368                                  
 10369                                  msg_create_ldd_s:
 10370 000062B0 53656C65637420616E-     	db	"Select an option to set logical dos drive size: "
 10370 000062B9 206F7074696F6E2074-
 10370 000062C2 6F20736574206C6F67-
 10370 000062CB 6963616C20646F7320-
 10370 000062D4 64726976652073697A-
 10370 000062DD 653A20             
 10371 000062E0 0D0A                    	db	0Dh, 0Ah
 10372 000062E2 0D0A                    	db	0Dh, 0Ah
 10373 000062E4 202043292043796C69-     	db	"  C) Cylinder count", 0Dh, 0Ah   
 10373 000062ED 6E64657220636F756E-
 10373 000062F6 740D0A             
 10374 000062F9 2020252920566F6C75-     	db	"  %) Volume percentage (##%)", 0Dh, 0Ah
 10374 00006302 6D652070657263656E-
 10374 0000630B 746167652028232325-
 10374 00006314 290D0A             
 10375 00006317 20204D29204D656761-     	db	"  M) Mega bytes (MB, 2*1024*M sectors)", 0Dh, 0Ah
 10375 00006320 20627974657320284D-
 10375 00006329 422C20322A31303234-
 10375 00006332 2A4D20736563746F72-
 10375 0000633B 73290D0A           
 10376 0000633F 202047292047696761-     	db	"  G) Giga bytes (GB, 2*1024*1024*G sectors)", 0Dh, 0Ah			
 10376 00006348 206279746573202847-
 10376 00006351 422C20322A31303234-
 10376 0000635A 2A313032342A472073-
 10376 00006363 6563746F7273290D0A 
 10377 0000636C 0D0A                    	db	0Dh, 0Ah	
 10378 0000636E 507265737320535041-     	db	"Press SPACE to use entire space or press ENTER to set Megabytes .. ", 0
 10378 00006377 434520746F20757365-
 10378 00006380 20656E746972652073-
 10378 00006389 70616365206F722070-
 10378 00006392 7265737320454E5445-
 10378 0000639B 5220746F2073657420-
 10378 000063A4 4D6567616279746573-
 10378 000063AD 202E2E2000         
 10379                                  
 10380                                  msg_c_part_error:
 10381 000063B2 0D0A                    	db 	0Dh, 0Ah
 10382                                  	;db	"No free space for a new primary partition", 0Dh, 0Ah, 0
 10383                                  	; 21/03/2021
 10384 000063B4 4E6F20667265652073-     	db	"No free space for a new primary partition !", 0Dh, 0Ah, 0
 10384 000063BD 7061636520666F7220-
 10384 000063C6 61206E657720707269-
 10384 000063CF 6D6172792070617274-
 10384 000063D8 6974696F6E20210D0A-
 10384 000063E1 00                 
 10385                                  ; 21/03/2021
 10386                                  ;msg_c_ldd_error: 
 10387                                  ;	db	"and logical dos drives over program limit (4) !", 0Dh, 0Ah, 0
 10388                                  msg_c_ldd_q:
 10389 000063E2 0D0A                    	db	0Dh, 0Ah
 10390 000063E4 446F20796F75207761-     	db	"Do you want to create logical dos drive in extended dos partition " 
 10390 000063ED 6E7420746F20637265-
 10390 000063F6 617465206C6F676963-
 10390 000063FF 616C20646F73206472-
 10390 00006408 69766520696E206578-
 10390 00006411 74656E64656420646F-
 10390 0000641A 732070617274697469-
 10390 00006423 6F6E20             
 10391 00006426 3F2028592F4E2900        	db	'? (Y/N)', 0
 10392                                  
 10393                                  msg_c_ldd_nofspc_error:
 10394 0000642E 0D0A                    	db 	0Dh, 0Ah
 10395 00006430 4E6F20667265652073-     	db	"No free space for a new logical dos drive !", 0Dh, 0Ah, 0
 10395 00006439 7061636520666F7220-
 10395 00006442 61206E6577206C6F67-
 10395 0000644B 6963616C20646F7320-
 10395 00006454 647269766520210D0A-
 10395 0000645D 00                 
 10396                                  
 10397                                  	; 12/10/2020
 10398                                  msg_drv_not_ready:
 10399 0000645E 0D0A                    	db	0Dh, 0Ah
 10400 00006460 4469736B2064726976-     	db	"Disk drive not ready or read error ! "
 10400 00006469 65206E6F7420726561-
 10400 00006472 6479206F7220726561-
 10400 0000647B 64206572726F722021-
 10400 00006484 20                 
 10401 00006485 0D0A00                  	db	0Dh, 0Ah, 0
 10402                                  
 10403                                  msg_not_any_disks:
 10404 00006488 0D0A                    	db	0Dh, 0Ah
 10405 0000648A 546865726520697320-     	db	"There is not a hard disk (ready) ! "
 10405 00006493 6E6F74206120686172-
 10405 0000649C 64206469736B202872-
 10405 000064A5 6561647929202120   
 10406 000064AD 0D0A00                  	db	0Dh, 0Ah, 0
 10407                                  
 10408                                  align 4
 10409                                  
 10410                                  msg_sectors_crlf:
 10411 000064B0 20736563746F72          	db	" sector"
 10412                                  msg_sectors_crlf_s:
 10413 000064B7 73                      	db	"s"
 10414 000064B8 0D0A00                  	db	0Dh, 0Ah, 0
 10415                                  
 10416                                  vname_length:
 10417 000064BB 00                      	db	0 ; 05/01/2018
 10418                                  
 10419                                  bs_oem_name:
 10420 000064BC 5452444F53322E3000      	db	'TRDOS2.0', 0
 10421                                  
 10422 000064C5 90                      align 2
 10423                                  
 10424                                  no_name:
 10425 000064C6 4E4F204E414D452020-     	db 	'NO NAME    ', 0
 10425 000064CF 202000             
 10426                                  
 10427                                  align 2
 10428                                  
 10429                                  FDFORMAT_SECBUFFER:
 10430                                  HDFORMAT_SECBUFFER:
 10431 000064D2 F6<rep 200h>            	times	512 db 0F6h
 10432                                  HDFORMAT_FSINFO_BUFF:
 10433 000066D2 52526141                	dd	41615252h  ; FSI_LeadSig
 10434 000066D6 00<rep 1E0h>            	times	480 db 0   ; FSI_Reserved1
 10435 000068B6 72724161                	dd	61417272h  ; FSI_StrucSig
 10436 000068BA FFFFFFFF                	dd	0FFFFFFFFh ; FSI_Free_Count
 10437 000068BE 02000000                	dd	000000002h ; FSI_Nxt_Free
 10438 000068C2 00<rep Ch>              	times	12 db 0	   ; FSI_Reserved2
 10439 000068CE 000055AA                	dd	0AA550000h ; FSI_TrailSig
 10440                                  
 10441                                  ; 29/10/2020
 10442                                  msg_100:
 10443 000068D2 31303000                	db	'100', 0
 10444                                  
 10445                                  SizeOfFile equ $-100
 10446                                  
 10447                                  ; 03/02/2019
 10448                                  
 10449                                  ;=============================================================================
 10450                                  ;        	uninitialized data
 10451                                  ;=============================================================================
 10452                                  
 10453                                  bss_start:
 10454                                  
 10455                                  ABSOLUTE bss_start
 10456                                  
 10457                                  ; 12/10/2020
 10458 000068D6 ??                      DrvNum:	resb 1
 10459 000068D7 ??                      hdc:	resb 1
 10460                                  ;hs:	resw 1 ; (bios/dos virtual) head*sectors ; 16/10/2020
 10461 000068D8 ??                      rw:	resb 1 
 10462 000068D9 ??                      rcnt:	resb 1 ; 18/10/2020	
 10463                                  total_sectors:
 10464 000068DA ????????                disksize: resd 1
 10465 000068DE ????????                chs_limit: resd 1
 10466                                  
 10467                                  ; 16/10/2020
 10468                                  ;lba_cyls: resd 1  ; cylinder count calculated from LBA sectors
 10469 000068E2 ????                    lba_chs_remain: resw 1	 ; remain sectors after the last cylinder
 10470                                  
 10471                                  alignb 2
 10472 000068E4 ????                    old_sp:	resw 1
 10473                                  
 10474                                  HDFORMAT_FATBUFFER:
 10475                                  HDFORMAT_EMPTY_BUFF:
 10476 000068E6 <res 200h>              	resb 512
 10477                                  
 10478 00006AE6 ????????                data_start: resd 1
 10479 00006AEA ????????                data_sectors: resd 1
 10480 00006AEE ????????                cluster_count: resd 1
 10481 00006AF2 ????                    root_dir_secs: resw 1
 10482 00006AF4 ????                    format_percent: resw 1
 10483 00006AF6 ??                      prev_percent:	resb 1
 10484 00006AF7 ??                      rsvdbyte:	resb 1
 10485                                  
 10486                                  alignb 4
 10487                                  
 10488                                  ; 05/01/2018
 10489 00006AF8 <res 40h>               fs_volume_name: resb 64
 10490 00006B38 ????????                fs_volume_serial: resd 1
 10491 00006B3C ????                    DAT_FFBit:	resw 1
 10492 00006B3E ????                    DAT_FFSector:	resw 1
 10493 00006B40 ????                    		resw 1 ; 19/03/2021
 10494 00006B42 ????                    DAT_LFBit:	resw 1
 10495 00006B44 ????                    DAT_LFSector:	resw 1
 10496 00006B46 ????                    		resw 1 ; 19/03/2021
 10497                                  
 10498                                  ;alignb 4
 10499                                  
 10500                                  FS_MAT_Buffer: ; TRFS1 Master Allocation Table (05/01/2018)
 10501 00006B48 ??????                  MAT_Sign:		resb    3	; Offset 0  ; 'MAT' 
 10502 00006B4B ??                      MAT_Version:		resb 	1	; 	 3  ; 0	
 10503 00006B4C ????????                MAT_VolumeSize:		resd	1	;	 4  ; FS1 Volume Size	
 10504 00006B50 ????????                MAT_BeginSector:	resd	1	;	 8  ; FS1 Start Sector
 10505 00006B54 ????????                DAT_Address:		resd	1	;	12  ; Offset (=2)	
 10506 00006B58 ????????                DAT_SectorCount:	resd	1	;	16  
 10507 00006B5C ????????                MAT_FreeSectors:	resd 	1	; 	20
 10508 00006B60 ????????                MAT_FirstFreeSector:	resd	1	;	24
 10509                                  ;MAT_OS_Reserved:
 10510                                  ;	 		resb	9
 10511                                  ;MAT_Unused:
 10512                                  ;			resb	112
 10513                                  FS_DAT_Buffer: ; TRFS1 Disk Allocation Table (05/01/2018)
 10514                                  FS_RDT_Buffer: ; TRFS1 Root Directory Description Table (05/01/2018)		 
 10515 00006B64 <res 200h>              			resb	512		
 10516                                  ;alignb 4
 10517                                  
 10518                                  ; (TR-DOS 386 compatible) Hard Disk (image) parameters
 10519                                  
 10520                                  ;total_sectors: resd 1
 10521 00006D64 ????????                pType:	       resb 4 		
 10522 00006D68 ????????                file_size:     resd 1
 10523 00006D6C ????????                pp_StartSector: resd 1
 10524 00006D70 ????????                pp_Sectors:	resd 1
 10525 00006D74 ??                      wholedisk:	resb 1
 10526 00006D75 ??                      pp_type: resb 1 ; Primary partition type (for this program)	
 10527 00006D76 ??                      pp_type_user: resb 1
 10528 00006D77 ??                      chs_focus: resb 1
 10529 00006D78 ????????                pSize_temp: resd 1
 10530 00006D7C ????????                pSize_multiplier: resd 1
 10531 00006D80 ??                      pSize_maxdigits: resb 1
 10532 00006D81 ??                      pSize_digitpos: resb 1
 10533                                  msg_psize_unit:
 10534 00006D82 ????                    pSize_unit:	resw 1
 10535 00006D84 ??                      		resb 1
 10536                                  ; 06/11/2020		
 10537                                  ;reserved_bytes: resb 3 ; for 11 bytes of numbers
 10538                                  msg_partition_sectors:
 10539                                  		;resb 8
 10540 00006D85 <res Bh>                		resb 11 ; 06/11/2020
 10541 00006D90 ??                      		resb 1
 10542 00006D91 ??                      format_q:	resb 1 ; 03/02/2018
 10543                                  
 10544                                  ;alignb 2
 10545 00006D92 ??                      pType_pos:	resb 1
 10546 00006D93 ??                      pType_num:	resb 1
 10547 00006D94 ??                      		resb 1
 10548                                  ;cylinder_boundary:
 10549 00006D95 ??                      		resb 1
 10550                                  ; 05/11/2020
 10551                                  
 10552                                  alignb 2
 10553                                  
 10554 00006D96 ??                      GetChar:	resb 1 ; 11/02/2019
 10555 00006D97 ??                      existingfile:	resb 1 ; 12/02/2019
 10556                                  
 10557                                  hs: ; 17/10/2020 ; (bios/dos virtual) head*sectors	
 10558 00006D98 ????                    min_sectors:	resw 1 ; 08/02/2019
 10559 00006D9A ????                    pp_StartCylinder: resw 1
 10560 00006D9C ????                    pp_EndCylinder:	resw 1
 10561                                  
 10562 00006D9E ????????                ppn_Sectors:	resd 1 ; 09/02/2019
 10563                                  
 10564 00006DA2 ????                    input_col:	resw 1
 10565 00006DA4 ??                      No:		resb 1
 10566 00006DA5 ??                      Yes:		resb 1
 10567                                  
 10568                                  ; 26/02/2019
 10569 00006DA6 ??                      ldrives:	resb 1	
 10570                                  
 10571                                  ;sort_1:	resb 1
 10572 00006DA7 ??                      		resb 1 ; 23/10/2020
 10573 00006DA8 ????????                sort:		resb 4
 10574                                  
 10575                                  ;max_sector:	resb 8
 10576                                  ebr_buffer:		; 26/02/2019
 10577 00006DAC <res 200h>              boot_record:	resb 512
 10578                                  
 10579 00006FAC ??                      valid_input:	resb 1
 10580 00006FAD ??                      		resb 1
 10581                                  
 10582                                  ; 26/02/2019
 10583 00006FAE ????????                ep_StartSector:	resd 1
 10584 00006FB2 ????????                ep_EndSector:	resd 1
 10585 00006FB6 ????????                ep_Size:	resd 1
 10586                                  
 10587                                  ; 10/02/2019
 10588 00006FBA ????????                valid_ppnums:	resb 4	
 10589                                  
 10590 00006FBE ????                    _i_:	resw 1
 10591                                  
 10592 00006FC0 ????                    freespace_count: resw 1
 10593 00006FC2 ??                      last_found_partition: resb 1
 10594 00006FC3 ??                      p_type: resb 1	
 10595                                  
 10596                                  ; 30/10/2020
 10597                                  ;p_sorted:
 10598                                  ;	resb 1
 10599                                  ;ep_sorted:
 10600                                  ;	resb 1
 10601                                  
 10602 00006FC4 ??                      _e_:	resb 1
 10603                                  
 10604                                  act_part_num:
 10605                                  cre_part_num:
 10606 00006FC5 ??                      del_part_num: resb 1 ; 10/02/2019
 10607                                  
 10608                                  alignb 2
 10609                                  
 10610 00006FC6 <res 50h>               pte_row: resb 80
 10611                                  
 10612 00007016 ??                      _zero_:	resb 1
 10613                                  
 10614                                  ;alignb 2
 10615                                  
 10616 00007017 ??                      	resb 1
 10617                                  
 10618                                  bss_clear_end: ; 15/02/2019
 10619                                  
 10620                                  ; PARTITION DATA STRUCTURE
 10621                                  ; 4 partitions
 10622                                  ; 18 byte partition data structure per partition
 10623                                  ; 72 bytes (4*18)
 10624                                  
 10625 00007018 ??                      part_table_boot_ind:	 resb 1
 10626 00007019 ??                      part_table_start_head:	 resb 1
 10627 0000701A ??                      part_table_start_sector: resb 1
 10628 0000701B ????                    part_table_start_cyl:	 resw 1
 10629 0000701D ??                      part_table_sys_id:	 resb 1
 10630 0000701E ??                      part_table_end_head:	 resb 1
 10631 0000701F ??                      part_table_end_sector:	 resb 1
 10632 00007020 ????                    part_table_end_cyl:	 resw 1
 10633 00007022 ????                    part_table_rel_sec_lw:	 resw 1
 10634 00007024 ????                    part_table_rel_sec_hw:	 resw 1
 10635 00007026 ????                    part_table_num_sec_lw:	 resw 1
 10636 00007028 ????                    part_table_num_sec_hw:	 resw 1
 10637                                  
 10638 0000702A <res 36h>               			resb 54 ; 3*18 bytes
 10639                                  
 10640 00007060 ??                      pcount:		resb 1
 10641 00007061 ??                      ppcount:	resb 1
 10642 00007062 ??                      apcount:	resb 1 
 10643 00007063 ??                      epnumber:	resb 1
 10644                                  
 10645                                  ; LOGICAL PARTITION DATA STRUCTURE
 10646                                  ; (for logical partitions in extended partition)
 10647                                  
 10648                                  ; 1 extended partition
 10649                                  ; 4 logical drives (18 bytes)
 10650                                  ; 72 bytes (4*18)
 10651                                  
 10652 00007064 ??                      ext_table_boot_ind:	resb 1
 10653 00007065 ??                      ext_table_start_head:	resb 1
 10654 00007066 ??                      ext_table_start_sector: resb 1
 10655 00007067 ????                    ext_table_start_cyl:	resw 1
 10656 00007069 ??                      ext_table_sys_id:	resb 1
 10657 0000706A ??                      ext_table_end_head:	resb 1
 10658 0000706B ??                      ext_table_end_sector:	resb 1
 10659 0000706C ????                    ext_table_end_cyl:	resw 1
 10660 0000706E ????                    ext_table_rel_sec_lw:	resw 1
 10661 00007070 ????                    ext_table_rel_sec_hw:	resw 1
 10662 00007072 ????                    ext_table_num_sec_lw:	resw 1
 10663 00007074 ????                    ext_table_num_sec_hw:	resw 1
 10664                                  
 10665 00007076 <res 36h>               			resb 54 ; 3*18 bytes
 10666                                  
 10667                                  fspc:		; 5*8 words (for free space calculations)
 10668                                  
 10669                                  ; Space 1 - unused cylinders before partition 0
 10670                                  ; Space 2 - unused cylinders between partition 0 & 1 
 10671                                  ; Space 3 - unused cylinders between partition 1 & 2 
 10672                                  ; Space 4 - unused cylinders between partition 2 & 3 
 10673                                  ; Space 5 - unused cylinders after partition 3
 10674                                  
 10675 000070AC ????                    free_space.space:   	   resw 1
 10676 000070AE ????                    free_space.start:   	   resw 1
 10677 000070B0 ????                    free_space.end:	   	   resw 1
 10678 000070B2 ????                    free_space.percent_unused: resw 1
 10679 000070B4 ????????                free_space.sectors_unused: resd 1
 10680 000070B8 ????????                free_space.startsector:   resd 1 ; 13/02/2019
 10681                                  		;resw  4*6 
 10682 000070BC <res 40h>               		resw   4*8 ; 4*16 bytes ; 13/02/2019
 10683                                  
 10684                                  ; 18/02/2019
 10685 000070FC ????                    c_cylinder:	resw 1
 10686 000070FE ????                    c_fspc_offset:	resw 1
 10687 00007100 ??                      cylinder_boundary: resb 1
 10688                                  ;c_gap:		resb 1
 10689 00007101 ??                      		resb 1
 10690                                  
 10691                                  ; 27/02/2019
 10692 00007102 <res 10h>               ldd_start:	resd 4
 10693                                  ; 03/03/2019
 10694 00007112 <res 10h>               ldd_size:	resd 4
 10695                                  ; 30/10/2020
 10696 00007122 ????????                ep_free_sectors: resd 1
 10697                                  
 10698                                  ; 25/02/2019
 10699 00007126 ????                    pte_address:	resw 1
 10700                                  ; 02/03/2019
 10701 00007128 ????                    lcylinders:	resw 1
 10702                                  ; 01/11/2020
 10703 0000712A ????                    endcyl:		resw 1
 10704                                  
 10705                                  ;bss_clear_end: ; 18/02/2019
 10706                                  
 10707                                  ; 11/10/2020
 10708                                  ;gdp_buffer:	resb 30 ; buffer for int 13h, ah = 48h
 10709 0000712C <res 1Ah>               gdp_buffer:	resb 26 ; buffer for int 13h, ah = 48h
 10710                                  ; 19/03/2021
 10711 00007146 ????                    tempword:	resw 1
 10712                                  
 10713                                  bss_end:	 	
