     1                                  ; ****************************************************************************
     2                                  ; FDISK4.ASM (FDISK4.COM) - TRDOS 386 Hard Disk Partitioning Utility
     3                                  ; 						      (for MSDOS/WINDOWS)
     4                                  ; ****************************************************************************
     5                                  ; 32 bit cylinder numbers modification on fdisk3.s (2TB hardisk partitioning)
     6                                  ; ----------------------------------------------------------------------------
     7                                  ; Last Update: 04/05/2024 (Previous: 21/03/2021)
     8                                  ; ----------------------------------------------------------------------------
     9                                  ; Beginning: 05/11/2020
    10                                  ; ----------------------------------------------------------------------------
    11                                  ; Assembler: NASM version 2.15
    12                                  ; ----------------------------------------------------------------------------
    13                                  ; Turkish Rational DOS
    14                                  ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
    15                                  ; ----------------------------------------------------------------------------
    16                                  ; Derived from 'fdisk3.s' (FDISK3.COM) source code by Erdogan Tan
    17                                  ; (05/11/2020)
    18                                  ;
    19                                  ; Derived from 'hdimage.s' (HDIMAGE.COM) source code by Erdogan Tan
    20                                  ; (04/11/2020)
    21                                  ; ****************************************************************************
    22                                  ; nasm fdisk4.s -l fdisk4.lst -o FDISK4.COM -Z error.txt
    23                                  
    24                                  ; Masterboot / Partition Table at Beginning+1BEh
    25                                  ptBootable      equ 0
    26                                  ptBeginHead     equ 1
    27                                  ptBeginSector   equ 2
    28                                  ptBeginCylinder equ 3
    29                                  ptFileSystemID	equ 4
    30                                  ptEndHead       equ 5
    31                                  ptEndSector     equ 6
    32                                  ptEndCylinder   equ 7
    33                                  ptStartSector   equ 8
    34                                  ptSectors       equ 12
    35                                  
    36                                  ; BIOS Disk Parameters
    37                                  DPDiskNumber  equ 0h
    38                                  DPDType       equ 1h
    39                                  DPReturn      equ 2h
    40                                  DPHeads       equ 3h
    41                                  DPCylinders   equ 4h
    42                                  DPSecPerTrack equ 6h
    43                                  DPDisks       equ 7h
    44                                  DPTableOff    equ 8h
    45                                  DPTableSeg    equ 0Ah
    46                                  DPNumOfSecs   equ 0Ch
    47                                  
    48                                  ; BIOS INT 13h Extensions (LBA extensions)
    49                                  ; Just After DP Data (DPDiskNumber+)
    50                                  DAP_PacketSize equ 10h  ; If extensions present, this byte will be >=10h
    51                                  DAP_Reserved1 equ 11h   ; Reserved Byte 
    52                                  DAP_NumOfBlocks equ 12h ; Value of this byte must be 0 to 127
    53                                  DAP_Reserved2 equ 13h   ; Reserved Byte
    54                                  DAP_Destination equ 14h ; Address of Transfer Buffer as SEGMENT:OFFSET
    55                                  DAP_LBA_Address equ 18h ; LBA=(C1*H0+H1)*S0+S1-1
    56                                                          ; C1= Selected Cylinder Number
    57                                                          ; H0= Number Of Heads (Maximum Head Number + 1)
    58                                                          ; H1= Selected Head Number
    59                                                          ; S0= Maximum Sector Number
    60                                                          ; S1= Selected Sector Number
    61                                                          ; QUAD WORD
    62                                  ; DAP_Flat_Destination equ 20h ; 64 bit address, if value in 4h is FFFF:FFFFh
    63                                                               ; QUAD WORD (Also, value in 0h must be 18h) 
    64                                                               ; TR-DOS will not use 64 bit Flat Address
    65                                  
    66                                  ; INT 13h Function 48h "Get Enhanced Disk Drive Parameters"
    67                                  ; Just After DP Data (DPDiskNumber+)
    68                                  GetDParams_48h equ 20h ; Word. Data Lenght, must be 26 (1Ah) for short data.
    69                                  GDP_48h_InfoFlag equ 22h ; Word
    70                                  ; Bit 1 = 1 -> The geometry returned in bytes 4-15 is valid.
    71                                  GDP_48h_NumOfPCyls equ 24h ; Double Word. Number physical cylinders.
    72                                  GDP_48h_NumOfPHeads equ 28h ; Double Word. Number of physical heads.
    73                                  GDP_48h_NumOfPSpT equ 2Ch ; Double word. Num of physical sectors per track.
    74                                  GDP_48h_LBA_Sectors equ 30h ; 8 bytes. Number of physical/LBA sectors.
    75                                  GDP_48h_BytesPerSec equ 38h ; Word. Number of bytes in a sector.
    76                                  
    77                                  pTableOffset equ 1BEh ; 446
    78                                  
    79                                  	; Convert LBA to CHS
    80                                  	; 08/02/2019
    81                                  
    82                                  	; LBA = ((C1*H0+H1)*S0)+S1-1
    83                                  	;
    84                                  	; C1 = Selected Cylinder Number
    85                                  	; H0 = Number of Heads (Maximum Head Number + 1)
    86                                  	; H1 = Selected Head Number
    87                                  	; S0 = Maximum Sector Number
    88                                  	; S1 = Selected Sector Number
    89                                  	;
    90                                  	; Phoenix, Enchanced Disk Drive Specicifications, v1.1, Page 8)
    91                                  
    92                                  [BITS 16]
    93                                  [ORG 100h]
    94                                  
    95                                  ; Note: 80386 cpu is required (this program will not run on 80286 systems)
    96                                  
    97                                  	; Detect 80386 cpu (386+)
    98                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    99                                  ; detect 386+ cpu
   100                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   101                                  ; 06/11/2020
   102                                  	; (https://forum.osdev.org/viewtopic.php?p=36822)
   103                                  	; (ogotay)
   104                                  
   105 00000000 9C                      	pushf
   106 00000001 B4D0                    	mov	ah, 0D0h
   107 00000003 50                      	push	ax
   108 00000004 9D                      	popf
   109 00000005 9C                      	pushf
   110 00000006 58                      	pop	ax
   111 00000007 9D                      	popf
   112 00000008 80FC50                  	cmp	ah, 50h
   113 0000000B 7408                    	je	short _386_ok
   114                                  	
   115                                  	; Write program message and terminate
   116                                  
   117 0000000D BE[A640]                	mov	si, TrDOS_Welcome
   118 00000010 E89D19                  	call	print_msg
   119                                  	
   120 00000013 CD20                    	int	20h
   121                                  
   122                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   123                                  _386_ok:
   124                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   125                                  
   126                                  	;cli
   127                                  	;cld
   128                                  	;push	cs
   129                                  	;pop	ss
   130                                  	;mov	sp, 0FFFEh
   131                                  	;sti
   132                                  	
   133                                  	;mov	bx, SizeOfFile+100
   134                                  	
   135 00000015 BB[D86D]                	mov	bx, bss_end
   136                                  
   137 00000018 83C30F                          add	bx, 15
   138 0000001B D1EB                            shr	bx, 1
   139 0000001D D1EB                            shr	bx, 1
   140 0000001F D1EB                    	shr	bx, 1
   141 00000021 D1EB                    	shr	bx, 1
   142 00000023 B44A                            mov	ah, 4Ah ; modify memory allocation
   143                                          ;push	cs
   144                                          ;pop	es
   145 00000025 CD21                            int	21h
   146                                  
   147                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   148                                  ; clear BSS
   149                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   150                                  ; 03/02/2019
   151                                  
   152                                  	;mov	cx, bss_end
   153 00000027 B9[6A6C]                	mov	cx, bss_clear_end ; 15/02/2019
   154                                  
   155 0000002A BF[2265]                	mov	di, bss_start
   156 0000002D 29F9                    	sub	cx, di
   157 0000002F 41                      	inc	cx
   158 00000030 D1E9                    	shr	cx, 1
   159 00000032 31C0                    	xor	ax, ax
   160 00000034 F3AB                    	rep	stosw 
   161                                  
   162                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   163                                  ; display program name & version
   164                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   165                                  
   166 00000036 BE[A640]                	mov	si, TrDOS_Welcome
   167 00000039 E87419                  	call	print_msg
   168                                  
   169                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   170                                  ; get hard disk name
   171                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   172                                  ; 11/10/2020
   173                                  
   174 0000003C BE8000                  	mov	si, 80h			; PSP command tail
   175 0000003F AC                       	lodsb
   176 00000040 08C0                    	or	al, al 			; command tail length
   177 00000042 7431                    	jz	short A_05		; jump if zero
   178                                  A_01:
   179 00000044 AC                      	lodsb
   180 00000045 3C20                    	cmp	al, ' '			; is it SPACE ?
   181 00000047 74FB                    	je	short A_01
   182 00000049 722A                    	jb	short A_05
   183                                  	
   184                                  	; check disk name
   185                                  
   186 0000004B 3C68                    	cmp	al, 'h'
   187 0000004D 751B                    	jne	short A_03
   188 0000004F 803C64                  	cmp	byte [si], 'd'
   189 00000052 7516                    	jne	short A_03
   190 00000054 46                      	inc	si
   191 00000055 AC                      	lodsb
   192 00000056 3C30                    	cmp	al, '0'
   193 00000058 7406                    	je	short A_02
   194 0000005A 720E                    	jb	short A_03
   195 0000005C 3C33                    	cmp	al, '3'
   196 0000005E 770A                    	ja	short A_03
   197                                  A_02:
   198 00000060 803C20                  	cmp	byte [si], ' '
   199 00000063 720B                    	jb	short A_04
   200 00000065 7703                    	ja	short A_03
   201 00000067 46                      	inc	si
   202 00000068 EBF6                    	jmp	short A_02
   203                                  A_03:
   204 0000006A BE[FE40]                	mov	si, TrDOS_Usage
   205 0000006D E90207                  	jmp	_p_exit
   206                                  A_04:
   207 00000070 0450                    	add	al, 80h - '0'
   208 00000072 A2[2265]                	mov	[DrvNum], al	; 80h .. 83h
   209                                  
   210                                  A_05:
   211                                  
   212                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   213                                  ; get hard disk parameters 
   214                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   215                                  ; 11/10/2020
   216                                  
   217                                  	; check bios int 13h extensions
   218 00000075 B441                    	mov	ah, 41h
   219 00000077 BBAA55                  	mov	bx, 55AAh
   220 0000007A B280                    	mov	dl, 80h
   221 0000007C CD13                    	int	13h
   222 0000007E 720B                    	jc	short A_06
   223 00000080 81FB55AA                	cmp	bx, 0AA55h
   224 00000084 7505                    	jne	short A_06
   225                                  
   226 00000086 C606[8F2E]01            	mov	byte [int13h_x], 1
   227                                  A_06:
   228                                  	;mov	dl, 80h	 ; hd0
   229 0000008B B408                    	mov	ah, 08h  ; return disk parameters
   230 0000008D CD13                    	int	13h	
   231 0000008F 7313                    	jnc	short A_10
   232                                  A_07:
   233 00000091 803E[2265]80            	cmp 	byte [DrvNum], 80h  ; hard disk name option ?
   234 00000096 7206                    	jb	short A_09 ; no, default
   235                                  A_08:
   236 00000098 BE[AA60]                	mov	si, msg_drv_not_ready ; drive not ready
   237 0000009B E9D406                  	jmp	_p_exit
   238                                  A_09:
   239 0000009E BE[D460]                	mov	si, msg_not_any_disks ; there is not a hard disk
   240 000000A1 E9CE06                  	jmp	_p_exit
   241                                  A_10:
   242 000000A4 08E4                    	or	ah, ah	 ; ah = 0 ?
   243 000000A6 75E9                    	jnz	short A_07  ; no, there is an error !
   244                                  	
   245 000000A8 8816[2365]              	mov	[hdc], dl ; number of hard disks
   246                                  
   247 000000AC A0[2265]                	mov	al, [DrvNum]
   248                                  
   249 000000AF 3C80                    	cmp	al, 80h
   250 000000B1 7308                    	jnb	short A_11 ; option
   251                                  	; default
   252 000000B3 C606[2265]80            	mov	byte [DrvNum], 80h
   253 000000B8 E98D00                  	jmp	A_14
   254                                  A_11:
   255                                  	; hard disk name option
   256 000000BB 80C27F                  	add	dl, 7Fh
   257                                  
   258 000000BE 38D0                    	cmp	al, dl
   259 000000C0 77D6                    	ja	short A_08
   260                                  
   261 000000C2 80FA80                  	cmp	dl, 80h
   262 000000C5 760C                    	jna	short A_13 ; hd0 parameters are ready 
   263                                  A_12:
   264 000000C7 88C2                    	mov	dl, al ; [DrvNum]
   265                                  
   266 000000C9 B408                    	mov	ah, 08h  ; return (get) disk parameters
   267 000000CB CD13                    	int	13h	
   268 000000CD 72C2                    	jc	short A_07
   269 000000CF 08E4                    	or	ah, ah
   270 000000D1 75BE                    	jnz	short A_07
   271                                  A_13:
   272 000000D3 88C8                    	mov	al, cl
   273 000000D5 243F                    	and	al, 3Fh ; 63
   274 000000D7 C0E906                  	shr	cl, 6
   275 000000DA 86E9                    	xchg	ch, cl
   276 000000DC 41                      	inc	cx
   277 000000DD 41                      	inc	cx ; 15/10/2020 ; BIOS BugFix
   278                                  				; (for reserved last cylinder)
   279 000000DE 890E[A63C]              	mov	[cylinders], cx
   280                                  	;mov	word [cylinders+2], 0 ; 16/10/2020
   281 000000E2 FEC6                    	inc	dh
   282 000000E4 8836[A43C]              	mov	[heads], dh
   283 000000E8 A2[A23C]                	mov	[sectors], al
   284 000000EB F6E6                    	mul	dh
   285 000000ED A3[E469]                	mov	[hs], ax ; heads*sectors ; 15/10/2020
   286 000000F0 F7E1                    	mul	cx
   287 000000F2 A3[2665]                	mov	[disksize], ax
   288 000000F5 8916[2865]              	mov	[disksize+2], dx
   289 000000F9 83E801                  	sub	ax, 1	; 17/10/2020
   290 000000FC 83DA00                  	sbb	dx, 0
   291 000000FF A3[2A65]                	mov	[chs_limit], ax
   292 00000102 8916[2C65]              	mov	[chs_limit+2], dx
   293                                  
   294 00000106 803E[8F2E]01            	cmp	byte [int13h_x], 1
   295 0000010B 0F82D500                	jb	A_20
   296                                  
   297 0000010F BE[BE6D]                	mov	si, gdp_buffer
   298                                  	;mov	word [si], 30 ; buffer length (minimum)
   299 00000112 C7041A00                	mov	word [si], 26 ; buffer length (minimum)
   300 00000116 B448                    	mov	ah, 48h
   301 00000118 8A16[2265]              	mov	dl, [DrvNum]
   302 0000011C CD13                    	int	13h
   303 0000011E 0F82C200                	jc	A_20
   304 00000122 20E4                    	and	ah, ah
   305 00000124 0F85BC00                	jnz	A_20
   306                                  
   307                                  	; 06/11/2020
   308                                  	; number of physical sectors
   309                                  	;mov	ax, [si+16]
   310                                  	;mov	dx, [si+18]
   311                                  	;mov	[disksize], ax
   312                                  	;mov	[disksize+2], dx
   313                                  	
   314 00000128 668B4410                	mov	eax, [si+16]
   315 0000012C 66A3[2665]              	mov	[disksize], eax
   316 00000130 6631D2                  	xor	edx, edx
   317                                  
   318                                  	; 15/10/2020
   319                                  	;mov	cx, [hs]
   320                                  	;call	div32
   321                                  	;; 16/10/2020
   322                                  	;;mov	[lba_cyls], ax
   323                                  	;;mov	[lba_cyls+2], dx
   324                                  	;mov	[cylinders], ax
   325                                  	;mov	[cylinders+2], dx
   326                                  	;mov	[lba_chs_remain], bx
   327                                  
   328                                  	; 06/11/2020
   329 00000133 66F736[E469]            	div 	dword [hs]
   330 00000138 66A3[A63C]              	mov	[cylinders], eax
   331 0000013C 8916[2E65]              	mov	[lba_chs_remain], dx
   332                                  	; reset
   333 00000140 6631C0                  	xor	eax, eax
   334                                  	;xor	edx, edx
   335 00000143 31D2                    	xor	dx, dx
   336                                  
   337 00000145 E99C00                  	jmp	A_20
   338                                  A_14:
   339 00000148 80FA01                  	cmp	dl, 1
   340 0000014B 7686                    	jna	short A_13 ; [DrvNum] = 80h
   341                                  
   342 0000014D 80C230                  	add	dl, '0' ; '2' to '4'
   343 00000150 8816[C141]              	mov	byte [TrDOS_dnmax], dl
   344                                  
   345 00000154 BE[A341]                	mov	si, TrDOS_Options
   346 00000157 E85618                  	call	print_msg
   347                                  
   348                                  	; check bios int 13h extensions
   349 0000015A 803E[8F2E]01            	cmp	byte [int13h_x], 1
   350 0000015F 732D                    	jnb	short A_16
   351                                  A_15:
   352 00000161 8A16[2265]              	mov	dl, [DrvNum]
   353 00000165 B408                    	mov	ah, 08h  ; return disk parameters
   354 00000167 CD13                    	int	13h	
   355 00000169 724D                    	jc	short A_17
   356 0000016B 08E4                    	or	ah, ah
   357 0000016D 7549                    	jnz	short A_17
   358                                  
   359 0000016F 88C8                    	mov	al, cl
   360 00000171 243F                    	and	al, 3Fh ; 63
   361 00000173 C0E906                  	shr	cl, 6
   362 00000176 86E9                    	xchg	ch, cl
   363 00000178 41                      	inc	cx
   364 00000179 FEC6                    	inc	dh
   365 0000017B F6E6                    	mul	dh
   366 0000017D F7E1                    	mul	cx
   367                                  
   368                                  	; dx:ax = disk size
   369                                  
   370 0000017F E85602                  	call	display_hd_row
   371                                  
   372 00000182 FE0E[2365]              	dec	byte [hdc]
   373 00000186 7430                    	jz	short A_17
   374 00000188 FE06[2265]              	inc	byte [DrvNum]
   375 0000018C EBD3                    	jmp	short A_15
   376                                  A_16:
   377 0000018E BE[BE6D]                	mov	si, gdp_buffer
   378                                  	;mov	word [si], 30 ; buffer length (minimum)
   379 00000191 C7041A00                	mov	word [si], 26 ; buffer length (minimum)
   380 00000195 B448                    	mov	ah, 48h
   381 00000197 8A16[2265]              	mov	dl, [DrvNum]
   382 0000019B CD13                    	int	13h
   383 0000019D 72C2                    	jc	short A_15
   384 0000019F 20E4                    	and	ah, ah
   385 000001A1 75BE                    	jnz	short A_15
   386                                  
   387                                  	; number of phsical sectors
   388 000001A3 8B4410                  	mov	ax, [si+16]
   389 000001A6 8B5412                  	mov	dx, [si+18]
   390                                  
   391                                  	; dx:ax = disk size
   392                                  
   393 000001A9 E82C02                  	call	display_hd_row
   394                                  
   395 000001AC FE0E[2365]              	dec	byte [hdc]
   396 000001B0 7406                    	jz	short A_17
   397 000001B2 FE06[2265]              	inc	byte [DrvNum]
   398 000001B6 EBD6                    	jmp	short A_16
   399                                  A_17:
   400 000001B8 BE[5152]                	mov	si, CRLF
   401 000001BB E8F217                  	call	print_msg
   402                                  
   403                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   404                                  ; hard disk number input (getchar)
   405                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   406                                  ; 11/10/2020
   407                                  	
   408                                  A_18:
   409 000001BE 31C0                    	xor	ax, ax
   410 000001C0 CD16                    	int	16h			; wait for keyboard command
   411                                  
   412 000001C2 83F800                  	cmp	ax, 0			; CTRL+BREAK
   413 000001C5 761A                    	jna	short A_19
   414                                  
   415 000001C7 3C03                    	cmp	al, 'C'-40h		; 3
   416 000001C9 7416                    	je	short A_19             	; CTRL+C
   417 000001CB 3C1B                    	cmp	al, 27			; ESCape
   418 000001CD 7412                    	je	short A_19
   419                                  
   420 000001CF 3C31                    	cmp	al, '1'			; "(1) hd0" 
   421 000001D1 72EB                    	jb	short A_18		; retry
   422 000001D3 3A06[C141]              	cmp	al, [TrDOS_dnmax]	; ('2' to '4')
   423 000001D7 77E5                    	ja	short A_18		; retry
   424 000001D9 044F                    	add	al, 80h-'1'		; bios disk num (80h-83h)
   425 000001DB A2[2265]                	mov	[DrvNum], al
   426 000001DE E9E6FE                  	jmp	A_12			; get disk parameters
   427                                  A_19:
   428 000001E1 E99105                  	jmp	_exit			; Exit
   429                                  
   430                                  A_20:
   431                                  
   432                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   433                                  ; read masterboot sector
   434                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   435                                  ; 12/10/2020
   436                                  
   437 000001E4 BB[CC52]                	mov	bx, MasterBootBuff
   438 000001E7 B90100                  	mov	cx, 1	; cylinder = 0
   439                                  			; sector = 1
   440 000001EA B600                    	mov	dh, 0	; head = 0
   441 000001EC 8A16[2265]              	mov	dl, [DrvNum]
   442 000001F0 B80102                  	mov	ax, 0201h ; read one sector
   443 000001F3 CD13                    	int	13h
   444 000001F5 7306                    	jnc	short A_21
   445                                  
   446 000001F7 BE[AA60]                	mov	si, msg_drv_not_ready ; drive not ready
   447 000001FA E98000                  	jmp	A_26
   448                                  A_21:
   449                                  
   450                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   451                                  ; display CHS values and disk size (LBA) and partition table
   452                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   453                                  ; 12/10/2020
   454                                  
   455 000001FD B80300                  	mov	ax, 3  ; clear screen
   456 00000200 CD10                    	int	10h
   457                                  
   458 00000202 E8D11E                  	call	init_partition_table ; 13/10/2020
   459                                  
   460 00000205 E82519                  	call	display_chs_table
   461                                  
   462 00000208 A1[2665]                	mov	ax, [disksize]
   463 0000020B 8B16[2865]              	mov	dx, [disksize+2]
   464                                  
   465 0000020F 81FA0001                	cmp	dx, 256 ; >= 8GB
   466 00000213 7315                    	jnb	short A_22
   467                                  
   468                                  	;mov	cx, 2048 ; /2048 (2048 sectors = 1 MB)
   469                                  	;div	cx
   470                                  
   471                                  	; shift dx:ax to 8 bits right (/256)
   472 00000215 88E0                    	mov	al, ah
   473 00000217 88D4                    	mov	ah, dl
   474 00000219 C1E803                  	shr	ax, 3 ; /8 
   475                                  		; result = (dx:ax)/2048
   476                                  
   477                                  	; ax =  0 to 8191
   478                                  
   479 0000021C C606[F741]4D            	mov	byte [TrDOS_hdrow_unit], 'M'
   480 00000221 EB11                    	jmp	short A_23
   481                                  
   482                                  
   483                                  A_29:	; 16/10/2020
   484 00000223 E84525                  	call	partition_table_fix
   485 00000226 73D5                    	jnc	short A_21
   486                                  
   487 00000228 CD20                    	int	20h
   488                                  ;here:	
   489                                  	;jmp	short here
   490                                  
   491                                  A_22:
   492                                  	; 1024 MB = 1GB (2097152 sectors)
   493                                  	; DX/32 --> GB
   494 0000022A 89D0                    	mov	ax, dx
   495 0000022C C1E805                  	shr	ax, 5 ; /32
   496                                  
   497                                  	; ax = 8 to 2047
   498 0000022F C606[F741]47            	mov	byte [TrDOS_hdrow_unit], 'G'
   499                                  A_23:
   500                                  	;xor	dx, dx
   501 00000234 BE[FD41]                	mov	si, TrDOS_hdrow_capacity
   502 00000237 E8DD01                  	call	convert_to_decimal
   503                                  
   504 0000023A BE[0442]                	mov	si, TrDOS_disksize
   505 0000023D E87017                  	call	print_msg
   506                                  
   507 00000240 BE[FD41]                	mov	si, TrDOS_hdrow_capacity
   508 00000243 E86A17                  	call	print_msg
   509                                  
   510 00000246 BE[F741]                	mov	si, TrDOS_hdrow_unit
   511 00000249 E86417                  	call	print_msg
   512                                  
   513                                  	; 05/11/2020
   514                                  	; fdisk4 can be used for 2TB hard disks 
   515                                  	;	(because of 32 bit virtual cylinder number)
   516                                   	; (fdisk3 limit is 502GB disks size and 65535 cylinders)
   517                                  
   518                                  	;; 16/10/2020
   519                                  	;;cmp	word [lba_cyls+2], 0
   520                                  	;cmp	word [cylinders+2], 0
   521                                  	;ja	short A_27  ; Huge disk ! number of (lba) cylinders > 65335
   522                                  	;		    ; Current FDISK version (v3) can not be used !
   523                                  
   524 0000024C BE[5152]                	mov	si, CRLF
   525 0000024F E85E17                  	call	print_msg
   526                                  
   527 00000252 E86D23                  	call	dpt_1
   528                                  
   529 00000255 BE[5152]                	mov	si, CRLF
   530 00000258 E85517                  	call	print_msg
   531                                  
   532                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   533                                  ; display edit or exit option, getchar
   534                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   535                                  
   536 0000025B BE[8050]                	mov	si, msg_edit_or_exit
   537 0000025E E84F17                  	call	print_msg
   538                                  A_24:
   539 00000261 30E4                    	xor	ah, ah
   540 00000263 CD16                    	int	16h
   541                                  
   542 00000265 3C0D                    	cmp	al, 13 ; CR (ENTER) key
   543 00000267 7419                    	je	short A_28 
   544                                  
   545 00000269 3C1B                    	cmp	al, 27 ; ESCape key
   546 0000026B 740D                    	je	short A_25
   547                                  
   548 0000026D 3C20                    	cmp	al, 32 ; SPACE key
   549 0000026F 7411                    	je	short A_28
   550                                  
   551 00000271 3C03                    	cmp	al, 3 ; CTRL+C
   552 00000273 7405                    	je	short A_25
   553                                  
   554 00000275 83F800                  	cmp	ax, 0 ; CTRL+BREAK
   555 00000278 77E7                    	ja	short A_24
   556                                  A_25:
   557 0000027A BE[5152]                	mov	si, CRLF
   558                                  A_26:
   559 0000027D E83017                  	call	print_msg
   560                                  
   561 00000280 CD20                    	int	20h
   562                                  ;here:
   563                                  ;	jmp	short here
   564                                  
   565                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   566                                  ; display fdisk program disk capacity limit message and then exit
   567                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   568                                  	; 05/11/2020 
   569                                  	; (fdisk4 is proper for -upto- 2TB hard disks)
   570                                  ;A_27:
   571                                  	;; 16/10/2020
   572                                  	;; 15/10/2020
   573                                  	;; Display FDISK (v3) capacity limit (error) message
   574                                  	;
   575                                  	;mov	ax, 65535
   576                                  	;mul	word [hs]
   577                                  	;	; 1024 MB = 1GB (2097152 sectors)
   578                                  	;; DX/32 --> GB 
   579                                  	;mov	ax, dx
   580                                  	;shr	ax, 5 ; /32
   581                                  	;
   582                                  	;; ax = 8 to 2047
   583                                  	;mov	byte [TrDOS_hdrow_unit], 'G'
   584                                  	;mov	byte [TrDOS_hdrow_unit+1], 'B'
   585                                  	;mov	byte [TrDOS_hdrow_unit+2], '.'
   586                                  	;
   587                                  	;;xor	dx, dx
   588                                  	;mov	si, TrDOS_hdrow_capacity
   589                                  	;call	convert_to_decimal
   590                                  	;
   591                                  	;mov	si, msg_fdisk_capacity_err
   592                                  	;call 	print_msg
   593                                  	;
   594                                  	;mov	si, TrDOS_hdrow_capacity
   595                                  	;call	print_msg
   596                                  	;
   597                                  	;mov	si, TrDOS_hdrow_unit
   598                                  	;call	print_msg
   599                                  	;	
   600                                  	;jmp	_exit
   601                                  
   602                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   603                                  ; check defective pte and then init extended partition table(s)
   604                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   605                                  
   606                                  A_28:
   607 00000282 E8AF01                  	call	check_defective_partition
   608 00000285 729C                    	jc	A_29 ; ds:si -> defective pte
   609                                  
   610                                  	; 17/10/2020
   611                                  	; 26/02/2019
   612 00000287 803E[C56C]00            	cmp	byte [epnumber], 0
   613 0000028C 7603                    	jna	short A_30
   614                                  
   615 0000028E E8792A                  	call	init_ext_partition_table
   616                                  A_30:
   617                                  	; 17/10/2020
   618                                  	; 04/02/2019
   619                                  	;xor	al, al  ; MBR/PRIMARY PARTITIONS
   620                                  	; 12/03/2021
   621                                  	;xor	eax, eax
   622 00000291 E81523                  	call	display_partition_table
   623                                  
   624                                  	; 17/10/2020
   625 00000294 803E[C26C]00            	cmp	byte [pcount], 0
   626 00000299 0F86E300                	jna	A_38 ; empty partition table
   627                                  
   628                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   629                                  ; check CHS parms against start sector address and partition size 
   630                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   631                                  
   632                                  A_31:
   633                                  	; Check disk parameters with current CHS settings
   634 0000029D 31DB                    	xor	bx, bx
   635 0000029F 31C9                    	xor	cx, cx
   636                                  A_32:
   637                                  	; 17/10/2020
   638 000002A1 80BF[716C]00            	cmp	byte [part_table_sys_id+bx], 0
   639 000002A6 7670                    	jna	short A_33
   640                                  
   641                                  	; 27/10/2020
   642                                  	;mov	ax, [sectors]
   643                                  	;mul	word [heads]
   644                                  	; dx = 0, ax = heads*sectors
   645                                  
   646                                  	; 06/11/2020
   647                                  	;mov	dx, [part_table_start_cyl+bx]
   648 000002A8 668B87[6D6C]            	mov	eax, [part_table_start_cyl+bx] ; 10/03/2021
   649                                  	; 27/10/2020
   650                                  	;cmp	ax, 1023 ; fixed cylinder number (> 1023)
   651                                  			 ; (partition's start sector is used for fixing)
   652 000002AD 663DFF030000            	cmp	eax, 1023 ; 06/11/2020 
   653 000002B3 7763                    	ja	short A_33 ; no need to check CHS parms here
   654                                  			; (also, CHS to LBA calculation is not applicable)
   655                                  	;mov	dx, [hs] ; heads*sectors
   656                                  	;
   657                                  	;mul	dx
   658                                  	;	; dx:ax = cylinder*heads*spt
   659                                  	
   660                                  	; 10/03/2021
   661 000002B5 66F726[E469]            	mul	dword [hs]
   662 000002BA 6689C6                  	mov	esi, eax
   663                                  
   664                                  	;mov	si, ax
   665                                  	;mov	di, dx
   666                                  
   667 000002BD 6631C0                  	xor	eax, eax
   668 000002C0 8A87[6B6C]              	mov	al, [part_table_start_head+bx]
   669 000002C4 F626[A23C]              	mul	byte [sectors]
   670                                  	;add	si, ax
   671                                  	;adc	di, 0
   672                                  		; di:si = (cylinder*heads*spt) + head*spt
   673                                  	; 10/03/2021
   674 000002C8 6601C6                  	add	esi, eax
   675                                  
   676 000002CB 8A87[6C6C]              	mov	al, [part_table_start_sector+bx]
   677 000002CF 30E4                    	xor	ah, ah
   678 000002D1 FEC8                    	dec	al ; 1 -> 0
   679                                  	;add	si, ax
   680                                  	;adc	di, 0
   681                                  		; di:si = (cylinder*heads*spt) + head*spt + sector - 1
   682                                  		; (start sector as converted to LBA)
   683                                  
   684                                  	; 10/03/2021
   685 000002D3 6601F0                  	add	eax, esi
   686                                  	;xor	esi, esi
   687                                  
   688                                  	; 07/11/2020
   689                                  	;;cmp	di, [part_table_rel_sec_hw+bx]
   690                                  	;cmp	di, [bx+part_table_rel_sec+2]
   691                                  	;jne	short A_34 ; Invalid !
   692                                  
   693                                  	;;cmp	si, [part_table_rel_sec_lw+bx]
   694                                  	;cmp	si, [bx+part_table_rel_sec]
   695                                  	;jne	short A_34 ; Invalid !
   696                                  		; di:si = partition's start sector (LBA)
   697                                  
   698 000002D6 663B87[786C]            	cmp	eax, [part_table_rel_sec+bx]
   699 000002DB 7548                    	jne	short A_34 ; Invalid ! 
   700                                  
   701                                  	; 27/10/2020
   702                                  	;mov	ax, [sectors]
   703                                  	;mul	word [heads]
   704                                  	; dx = 0, ax = heads*sectors
   705                                  
   706                                  	; 10/03/2021
   707 000002DD 668B87[746C]            	mov	eax, [part_table_end_cyl+bx]
   708 000002E2 663DFF030000            	cmp	eax, 1023
   709                                  	; 27/10/2020
   710                                  	;cmp	ax, 1023 ; fixed cylinder number (> 1023)
   711                                  			 ; (partition's end sector is used for fixing)
   712 000002E8 772E                    	ja	short A_33 ; no need to check CHS parms here
   713                                  			; (also, CHS to LBA calculation is not applicable)
   714                                  	;mov	ax, [hs] ; heads*sectors
   715                                  	;
   716                                  	;mul	dx
   717                                  	;	; dx:ax = cylinder*heads*spt
   718                                  	;mov	si, ax
   719                                  	;mov	di, dx
   720                                  	
   721 000002EA 66F726[E469]            	mul	dword [hs]
   722 000002EF 6689C6                  	mov	esi, eax 
   723                                  	
   724 000002F2 6631C0                  	xor	eax, eax
   725 000002F5 8A87[726C]              	mov	al, [part_table_end_head+bx]
   726 000002F9 F626[A23C]              	mul	byte [sectors]
   727                                  	;add	si, ax
   728                                  	;adc	di, 0
   729                                  		; di:si = (cylinder*heads*spt) + head*spt
   730                                  	; 10/03/2021
   731 000002FD 6601C6                  	add	esi, eax
   732                                  
   733 00000300 8A87[736C]              	mov	al, [part_table_end_sector+bx]
   734 00000304 30E4                    	xor	ah, ah
   735                                  	;dec	al ; 63 -> 62
   736                                  	;add	si, ax
   737                                  	;adc	di, 0
   738                                  		; di:si = (cylinder*heads*spt) + head*spt + sector
   739                                  		; (end sector + 1 as converted to LBA)
   740                                  	; 10/03/2021
   741 00000306 6601C6                  	add	esi, eax
   742                                  
   743                                  	;mov	ax, [part_table_num_sec_lw+bx]
   744                                  	;mov	dx, [part_table_num_sec_hw+bx]
   745                                  	;
   746                                  	;add	ax, [part_table_rel_sec_lw+bx]
   747                                  	;adc	dx, [part_table_rel_sec_hw+bx]
   748                                  	;	; dx:ax = partition's end sector (LBA) + 1
   749                                  
   750                                  	; 10/03/2021
   751 00000309 668B87[7C6C]            	mov	eax, [part_table_num_sec+bx]
   752 0000030E 660387[786C]            	add	eax, [part_table_rel_sec+bx]
   753                                  
   754 00000313 6639C6                  	cmp	esi, eax
   755 00000316 750D                    	jne	short A_34 ; Invalid !
   756                                  
   757                                  	;cmp	ax, si
   758                                  	;jne	short A_34 ; Invalid !
   759                                  
   760                                  	;cmp	dx, di
   761                                  	;jne	short A_34 ; Invalid !
   762                                  A_33:
   763 00000318 FEC1                    	inc	cl
   764                                  
   765 0000031A 80F904                  	cmp	cl, 4
   766 0000031D 7311                    	jnb	short A_35
   767                                  
   768                                  	;add	bx, 18 ; partition table structure size
   769                                  	; 05/11/2020
   770 0000031F 83C316                  	add	bx, 22 ; partition table structure size	
   771                                  
   772 00000322 E97CFF                  	jmp	A_32
   773                                  A_34:
   774                                  	;mov	si, msg_defective_pt
   775                                  	; 10/03/2021
   776 00000325 66BE[E35B0000]          	mov	esi, msg_defective_pt
   777 0000032B E88216                  	call	print_msg
   778 0000032E EB50                    	jmp	short A_38
   779                                  
   780                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   781                                  ; sort MBR partitions
   782                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   783                                  
   784                                  A_35:
   785                                  	; 10/03/2021
   786 00000330 6631F6                  	xor	esi, esi
   787                                  	; 06/11/2020
   788 00000333 6631D2                  	xor	edx, edx
   789                                  
   790                                  	; LBA and CHS values of all partitions are OK (here)
   791                                  
   792                                  	; sort MBR (primary) partitions
   793                                  
   794 00000336 E8581F                  	call	sort_partition_table
   795                                  
   796                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   797                                  ; Check partition (start, size) overlaps after sorting 
   798                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   799                                  
   800                                  	; Checking partition overlaps (via start and end cylinders)
   801                                  
   802 00000339 31DB                    	xor	bx, bx
   803                                  	;mov	dx, 18
   804                                  	; 05/11/2020
   805 0000033B BA1600                  	mov	dx, 22
   806                                  A_36:
   807 0000033E FEC3                    	inc	bl
   808                                  
   809 00000340 8A87[FA69]              	mov	al, [bx+sort]
   810 00000344 F6E2                    	mul	dl
   811 00000346 89C6                    	mov	si, ax	; current
   812                                  
   813 00000348 80BC[716C]00            	cmp	byte [part_table_sys_id+si], 0
   814 0000034D 762C                    	jna	short A_37
   815                                  
   816 0000034F 8A87[F969]              	mov	al, [bx+sort-1]
   817 00000353 F6E2                    	mul	dl
   818 00000355 89C7                    	mov	di, ax  ; previous
   819                                  
   820                                  	;mov	ax, [part_table_end_cyl+di]
   821                                  	;cmp	ax, [part_table_start_cyl+si]
   822                                  	;jb	short A_37
   823                                  	; 29/10/2020
   824                                  	;ja	short A_34 ; overlap !
   825                                  	; 10/03/2021
   826 00000357 668B85[746C]            	mov	eax, [part_table_end_cyl+di]
   827 0000035C 663B84[6D6C]            	cmp	eax, [part_table_start_cyl+si]
   828 00000361 7218                    	jb	short A_37
   829 00000363 77C0                    	ja	short A_34 ; overlap !
   830                                  
   831                                  	; 17/10/2020
   832                                  	;and	ax, ax
   833                                  	;jnz	short A_34 ; overlap error (except empty entries)
   834                                  
   835                                  	; 29/10/2020
   836                                  	; same cylinder
   837                                  	; check end-start sectors for overlap
   838                                  
   839                                  	;and	ax, ax
   840                                  	;jz	short A_37 ; empty pt entries
   841                                  			; (previous pte is empty)
   842                                  	; 10/03/2021
   843 00000365 6621C0                  	and	eax, eax
   844 00000368 7411                    	jz	short A_37 ; empty pt entries
   845                                  			; (previous pte is empty)
   846                                  
   847                                  	;mov	ax, [part_table_rel_sec_lw+di] ; previous
   848                                  	;mov	dx, [part_table_rel_sec_hw+di]
   849                                  	;add	ax, [part_table_num_sec_lw+di]
   850                                  	;adc	dx, [part_table_num_sec_hw+di]
   851                                  	;;jc	short A_34
   852                                  	;	 ; dx:ax = end sector + 1
   853                                  	; 10/03/2021	
   854 0000036A 668B85[786C]            	mov	eax, [part_table_rel_sec+di] ; previous
   855 0000036F 660385[7C6C]            	add	eax, [part_table_num_sec+di]
   856                                  
   857                                  	;cmp	dx, [part_table_rel_sec_hw+si] ; current
   858                                  	;jb	short A_37
   859                                  	;ja	short A_34 ; overlap error !
   860                                  	;cmp	ax, [part_table_rel_sec_lw+si]
   861                                  	;jnb	short A_34 ; overlap error !
   862                                  	; 10/03/2021
   863 00000374 663B84[786C]            	cmp	eax, [part_table_rel_sec+si] ; current
   864 00000379 73AA                    	jnb	short A_34 ; overlap error !
   865                                   A_37:
   866 0000037B 80FB03                  	cmp	bl, 3
   867 0000037E 72BE                    	jb	short A_36
   868                                  
   869                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   870                                  ; display partition table editing options
   871                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   872                                  
   873                                  A_38:
   874 00000380 BE[BA56]                	mov	si, mbr_editing_options
   875 00000383 E82A16                  	call	print_msg
   876                                  
   877 00000386 BE[6857]                	mov	si, enter_option_number_msg
   878 00000389 E82416                  	call	print_msg
   879                                  
   880 0000038C 803E[F869]00            	cmp	byte [ldrives], 0
   881 00000391 760C                    	jna	short A_39
   882                                  
   883 00000393 BE[5152]                	mov	si, CRLF
   884 00000396 E81716                  	call	print_msg
   885                                  
   886 00000399 BE[2B5D]                	mov	si, str_display_ebr_pt
   887 0000039C E81116                  	call	print_msg
   888                                  A_39:	
   889                                  	;mov	si, CRLF
   890                                  	;call	print_msg
   891                                  
   892                                  A_40:
   893 0000039F 30E4                    	xor	ah, ah
   894 000003A1 CD16                    	int	16h
   895                                  
   896 000003A3 3C30                    	cmp	al, '0'
   897 000003A5 742A                    	je	short A_41
   898                                  
   899 000003A7 3C31                    	cmp	al, '1'
   900 000003A9 0F84A600                	je	create_partition
   901 000003AD 3C32                    	cmp	al, '2'
   902 000003AF 0F842F01                	je	activate_partition
   903 000003B3 3C33                    	cmp	al, '3'
   904 000003B5 0F84C801                	je	delete_partition
   905 000003B9 3C34                    	cmp	al, '4'
   906 000003BB 0F84CB02                	je	write_pt_mbr
   907                                  	
   908 000003BF 3C1B                    	cmp	al, 27 ; ESCape
   909 000003C1 740E                    	je	short A_41
   910                                  
   911                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   912                                  ; display (EPT) logical drives/partitions if 'SPACE' is pressed
   913                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   914                                  
   915                                  	; 28/02/2019
   916 000003C3 803E[F869]00            	cmp	byte [ldrives], 0
   917 000003C8 76D5                    	jna	short A_40
   918                                  
   919 000003CA 3C20                    	cmp	al, 20h ; SPACE
   920 000003CC 75D1                    	jne	short A_40
   921                                  
   922 000003CE E9CD23                  	jmp	display_extended_pt
   923                                  
   924                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   925                                  ; exit if ESC key or '0' is pressed
   926                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   927                                  
   928                                  A_41:
   929                                  	; terminate
   930 000003D1 CD20                    	int	20h
   931                                  
   932                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   933                                  ; display partition table again
   934                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   935                                  
   936                                  A_42:
   937                                  	; 24/02/2019
   938                                  	;xor	al, al  ; MBR/PRIMARY PARTITIONS
   939                                  	; 12/03/2021
   940                                  	;xor	eax, eax
   941 000003D3 E8D321                  	call	display_partition_table
   942 000003D6 EBA8                    	jmp	short A_38
   943                                  
   944                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   945                                  ; display a row for hard disk name, number and capacity 
   946                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   947                                  ; 11/10/2020
   948                                  
   949                                  display_hd_row:
   950                                  	; dx:ax = disk size
   951                                  
   952 000003D8 81FA0001                	cmp	dx, 256 ; >= 8GB
   953 000003DC 730E                    	jnb	short dhdr_1
   954                                  
   955                                  	;mov	cx, 2048 ; /2048 (2048 sectors = 1 MB)
   956                                  	;div	cx
   957                                  
   958                                  	; shift dx:ax to 8 bits right (/256)
   959 000003DE 88E0                    	mov	al, ah
   960 000003E0 88D4                    	mov	ah, dl
   961 000003E2 C1E803                  	shr	ax, 3 ; /8 
   962                                  		; result = (dx:ax)/2048
   963                                  
   964                                  	; ax =  0 to 8191
   965                                  
   966 000003E5 C606[F741]4D            	mov	byte [TrDOS_hdrow_unit], 'M'
   967 000003EA EB0A                    	jmp	short dhdr_2
   968                                  	
   969                                  dhdr_1:
   970                                  	; 1024 MB = 1GB (2097152 sectors)
   971                                  	; DX/32 --> GB 
   972 000003EC 89D0                    	mov	ax, dx
   973 000003EE C1E805                  	shr	ax, 5 ; /32
   974                                  
   975                                  	; ax = 8 to 2047
   976 000003F1 C606[F741]47            	mov	byte [TrDOS_hdrow_unit], 'G'
   977                                  dhdr_2:
   978                                  	;xor	dx, dx
   979 000003F6 BE[FD41]                	mov	si, TrDOS_hdrow_capacity
   980 000003F9 E81B00                  	call	convert_to_decimal
   981                                  
   982 000003FC FE06[E241]              	inc	byte [TrDOS_hdrow_n] ; next number for "(#)"
   983                                  	
   984 00000400 BE[DF41]                	mov	si, TrDOS_hdrow
   985 00000403 E8AA15                  	call	print_msg
   986 00000406 BE[FD41]                	mov	si, TrDOS_hdrow_capacity ; db "#### ", 0
   987 00000409 E8A415                  	call	print_msg
   988 0000040C BE[F741]                	mov	si, TrDOS_hdrow_unit ; "GB" or "MB"
   989 0000040F E89E15                  	call	print_msg
   990                                  
   991 00000412 FE06[E741]              	inc	byte [TrDOS_hdrow_i] ; next number for "hd#"
   992                                  
   993 00000416 C3                      	retn	
   994                                  
   995                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   996                                  ; convert binary number to decimal character string
   997                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   998                                  ; 11/10/2020
   999                                  
  1000                                  convert_to_decimal:
  1001                                  	; ax = binary number
  1002                                  	; si = decimal string start addr (max. 5 digits + space)
  1003 00000417 B90A00                  	mov	cx, 10
  1004 0000041A 89E5                    	mov	bp, sp
  1005                                  ctd_1:
  1006 0000041C 31D2                    	xor	dx, dx
  1007 0000041E F7F1                    	div	cx
  1008 00000420 52                      	push	dx ; 0 to 9
  1009 00000421 09C0                    	or	ax, ax
  1010 00000423 75F7                    	jnz	short ctd_1
  1011                                  ctd_2:
  1012 00000425 58                      	pop	ax
  1013 00000426 0430                    	add	al, '0'
  1014 00000428 8804                    	mov	[si], al
  1015 0000042A 46                      	inc	si
  1016 0000042B 39E5                    	cmp	bp, sp
  1017 0000042D 77F6                    	ja	short ctd_2
  1018                                  	;mov	byte [si], 20h ; space before size unit char
  1019                                  	;inc	si 
  1020                                  	;mov	byte [si], 0 ; ASCIIZ string terminator (Z)
  1021 0000042F C7042000                	mov	word [si], 20h
  1022 00000433 C3                      	retn
  1023                                  
  1024                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1025                                  ; check defective partition signature 
  1026                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1027                                  ; 16/10/2020
  1028                                  
  1029                                  check_defective_partition:
  1030 00000434 BB[6A6C]                	mov	bx, part_table_boot_ind
  1031 00000437 31F6                    	xor	si, si 
  1032                                  chk_dp_1:
  1033 00000439 803FFF                  	cmp	byte [bx], 0FFh ; invalid/defective/partition sign
  1034 0000043C 7509                    	jne	short chk_dp_2
  1035 0000043E C1E604                  	shl	si, 4 ; * 16
  1036 00000441 81C6[8A54]              	add	si, MasterBootBuff+446
  1037 00000445 F9                      	stc
  1038 00000446 C3                      	retn
  1039                                  chk_dp_2:
  1040                                  	;cmp	bx, part_table_boot_ind+(22*4) ; 05/11/2020
  1041 00000447 83FE03                  	cmp	si, 3
  1042 0000044A 7306                    	jnb	short chk_dp_3
  1043                                  	;add	bx, 18
  1044                                  	; 05/11/2020
  1045 0000044C 83C316                  	add	bx, 22
  1046 0000044F 46                      	inc	si
  1047 00000450 EBE7                    	jmp	short chk_dp_1 
  1048                                  chk_dp_3:
  1049                                  	;sub	si, si
  1050 00000452 C3                      	retn
  1051                                  
  1052                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1053                                  ; create a disk partition (on MBR partition table)
  1054                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1055                                  ; 18/10/2020
  1056                                  
  1057                                  	; 12/03/2021
  1058                                  	; 11/03/2021 (fdisk4.s)
  1059                                  create_partition:
  1060                                  	; 19/10/2020
  1061                                  	; 10/02/2019 (hdimage.s)
  1062 00000453 31C0                    	xor	ax, ax
  1063                                  	;xor	eax, eax ; 12/03/2021
  1064 00000455 A2[C069]                	mov	byte [wholedisk], al ; 0 ; Reset wholedisk flag
  1065                                  
  1066                                  	; 19/10/2020
  1067 00000458 3806[C26C]              	cmp	byte [pcount], al ; 0 ; number of (valid) partitions
  1068 0000045C 761C                    	jna	short cp_1
  1069                                  ;cp_0:
  1070 0000045E 803E[C26C]04            	cmp	byte [pcount], 4
  1071 00000463 7318                    	jnb	short cp_2 ; full pt !
  1072                                  
  1073                                  	; al = 0
  1074 00000465 E8911E                  	call	find_part_free_space
  1075                                  		 ; Following values are for the max. free space on disk
  1076                                  
  1077                                  	;and	cx, cx
  1078                                  	; 12/03/2021
  1079 00000468 6621C9                  	and	ecx, ecx
  1080 0000046B 7421                    	jz	short cp_3 ; there is not free space on disk
  1081                                  
  1082                                  	;mov	[c_cylinders], cx  ; count of free cylinders in the gap
  1083 0000046D 891E[8C6D]              	mov	[c_fspc_offset], bx  ; offset from beginning of 'fspc:'
  1084                                  	;mov	[c_gap], al ; gap (space index) number of this free space
  1085                                  	;		    ; 0 -> before partition 1 (as PTE)
  1086                                  	;		    ; 1-2-3 -> between partitions 1 to 4
  1087                                  	;		    ; 4 -> after partition 4 (as PTE)
  1088                                  
  1089                                  	; Start to job with non-aligned (full) free sectors of this max. space
  1090                                  	
  1091                                  	;mov	ax, [free_space.sectors_unused+bx]
  1092                                  	;mov	dx, [free_space.sectors_unused+2+bx]
  1093                                  	; 12/03/2021
  1094 00000471 668B87[2A6D]            	mov	eax, [free_space.sectors_unused+bx]
  1095                                  
  1096                                  	;mov	[pp_Sectors], ax
  1097                                  	;mov	[pp_Sectors+2], dx
  1098                                  	; 12/03/2021
  1099 00000476 66A3[BC69]              	mov	[pp_Sectors], eax
  1100                                  cp_1:
  1101 0000047A E9C807                  	jmp	B_01 ; New/Empty disk, create partition menu
  1102                                  ;cp_2:
  1103                                  	; 13/02/2019
  1104                                  	; There is not a free pt entry to create a new partition
  1105                                  
  1106                                  	;xor	al, al  ; MBR/PRIMARY PARTITIONS
  1107                                  	; 12/03/2021
  1108                                  	;xor	eax, eax
  1109                                  cp_2:
  1110 0000047D E82921                  	call	display_partition_table
  1111                                  
  1112 00000480 BE[4A58]                	mov	si, msg_full_pt
  1113 00000483 E82A15                  	call	print_msg
  1114 00000486 BE[7758]                	mov	si, msg_to_create_new_p
  1115 00000489 E82415                  	call	print_msg
  1116                                  
  1117 0000048C EB64                    	jmp	ap_0
  1118                                  cp_3:
  1119                                  	; 19/10/2020
  1120 0000048E 803E[C56C]00            	cmp	byte [epnumber], 0
  1121 00000493 7708                    	ja	short create_logical_drives
  1122                                  ;cp_4:
  1123                                  	; 15/02/2019
  1124                                  	; There is not (enough) free space to create a new partition
  1125                                  
  1126 00000495 BE[9558]                	mov	si, msg_no_free_space
  1127 00000498 E81515                  	call	print_msg
  1128 0000049B EB55                    	jmp	ap_0
  1129                                  
  1130                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1131                                  ; create logical -dos- drives
  1132                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1133                                  ; 19/10/2020
  1134                                  
  1135                                  	; 12/03/2021 (fdisk4.s)
  1136                                  create_logical_drives:
  1137                                  	; 05/03/2019
  1138 0000049D E82526                  	call	check_ext_free_space
  1139 000004A0 7238                    	jc	short cld_5
  1140                                  cld_1:
  1141                                  	; 05/03/2019
  1142 000004A2 803E[F869]04            	cmp	byte [ldrives], 4
  1143 000004A7 7203                    	jb	short cld_2
  1144 000004A9 E96023                  	jmp	eetc_2
  1145                                  cld_2:
  1146                                  	; 01/11/2020
  1147                                  	;mov	[ep_free_sectors], ax
  1148                                  	;mov	[ep_free_sectors+2], dx
  1149                                  	; 12/03/2021
  1150 000004AC 66A3[B06D]              	mov	[ep_free_sectors], eax
  1151                                  
  1152 000004B0 BE[2E60]                	mov	si, msg_c_ldd_q
  1153 000004B3 E8FA14                  	call	print_msg
  1154                                  cld_3:	
  1155 000004B6 28E4                    	sub	ah, ah
  1156 000004B8 CD16                    	int	16h
  1157                                  
  1158 000004BA 3C1B                    	cmp	al, 27 ; ESCAPE key
  1159                                  	;je	cp_esc
  1160 000004BC 7419                    	je	short cld_6 ; 19/10/2020
  1161 000004BE 24DF                    	and	al, 0DFh
  1162 000004C0 3C4E                    	cmp	al, 'N'
  1163 000004C2 740D                    	je	short cld_4
  1164 000004C4 3C59                    	cmp	al, 'Y'
  1165 000004C6 75EE                    	jne	short cld_3
  1166 000004C8 BE[8A59]                	mov	si, _msg_YES
  1167 000004CB E8E214                  	call	print_msg
  1168                                  
  1169 000004CE E96B23                  	jmp	edit_ext_table_create_x
  1170                                  cld_4:	
  1171 000004D1 BE[9059]                	mov	si, _msg_NO
  1172 000004D4 E8D914                  	call	print_msg
  1173                                  cld_6:
  1174                                  	;jmp	cp_esc
  1175                                  	; 19/10/2020
  1176 000004D7 E9F9FE                  	jmp	A_42
  1177                                  cld_5:	
  1178 000004DA BE[FE5F]                	mov	si, msg_c_part_error
  1179 000004DD E8D014                  	call	print_msg
  1180                                  
  1181                                  	; 21/03/2021
  1182                                  	;cmp	byte [ldrives], 3
  1183                                  	;;jna	short cld_2
  1184                                  	; 21/03/2021
  1185                                  	;jna	short ap_0
  1186                                  
  1187                                  	;mov	si, msg_c_ldd_error
  1188                                  	;call	print_msg
  1189                                  
  1190 000004E0 EB10                    	jmp	short ap_0
  1191                                  
  1192                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1193                                  ; set active partition
  1194                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1195                                  ; 19/10/2020 
  1196                                  	
  1197                                  activate_partition:
  1198                                  	; 12/02/2019
  1199                                  	;xor	al, al  ; MBR/PRIMARY PARTITIONS
  1200                                  	; 12/03/2021
  1201                                  	;xor	eax, eax
  1202 000004E2 E8C420                  	call	display_partition_table
  1203                                  
  1204 000004E5 803E[C26C]00            	cmp	byte [pcount], 0
  1205 000004EA 7713                    	ja	short ap_1
  1206                                  
  1207 000004EC BE[FE57]                	mov	si, msg_empty_pt
  1208 000004EF E8BE14                  	call	print_msg
  1209                                  ap_0:
  1210 000004F2 BE[AD52]                	mov	si, msg_press_any_key
  1211 000004F5 E8B814                  	call	print_msg
  1212                                  
  1213 000004F8 30E4                    	xor	ah, ah
  1214 000004FA CD16                    	int	16h
  1215                                  ap_5:
  1216                                  	;jmp	ap_esc
  1217                                  	; 19/10/2020
  1218 000004FC E9D4FE                  	jmp	A_42
  1219                                  
  1220                                  ap_1:
  1221                                  	; Set valid_ppnums (MBR partition IDs) list
  1222 000004FF BE[8A54]                	mov	si, MasterBootBuff+pTableOffset ; MasterBootBuff+446
  1223 00000502 BB[0C6C]                	mov	bx, valid_ppnums
  1224 00000505 B104                    	mov	cl, 4
  1225                                  ap_2:
  1226 00000507 8A4404                  	mov	al, [si+ptFileSystemID]
  1227 0000050A 8807                    	mov	[bx], al
  1228 0000050C FEC9                    	dec	cl
  1229 0000050E 7406                    	jz	short ap_3
  1230 00000510 43                      	inc	bx
  1231 00000511 83C610                  	add	si, 16
  1232 00000514 EBF1                    	jmp	short ap_2
  1233                                  ap_3:
  1234 00000516 BE[7D5A]                	mov	si, msg_enter_pn_to_act
  1235 00000519 E89414                  	call	print_msg
  1236                                  ap_getchar:
  1237 0000051C 30E4                    	xor	ah, ah
  1238 0000051E CD16                    	int	16h
  1239                                  	
  1240                                  	; 19/10/2020
  1241 00000520 3C1B                    	cmp	al, 27
  1242                                  	;je	ap_esc
  1243 00000522 74D8                    	je	short ap_5
  1244                                  
  1245                                  	;cmp	al, '0'
  1246                                  	;;je	ap_esc
  1247                                  	;je	short ap_5
  1248                                  
  1249 00000524 3C31                    	cmp	al, '1'
  1250 00000526 72F4                    	jb	short ap_getchar
  1251 00000528 3C34                    	cmp	al, '4'
  1252 0000052A 77F0                    	ja	short ap_getchar
  1253                                  
  1254 0000052C 30E4                    	xor	ah, ah
  1255 0000052E 89C2                    	mov	dx, ax
  1256                                  	
  1257 00000530 80EA31                  	sub	dl, '1'
  1258 00000533 89D6                    	mov	si, dx
  1259 00000535 38A4[0C6C]              	cmp	byte [si+valid_ppnums], ah  ; 0
  1260 00000539 76E1                    	jna	short ap_getchar ; Empty partition table entry, it is not shown
  1261                                  
  1262 0000053B BB0700                  	mov	bx, 07h
  1263 0000053E B409                    	mov	ah, 09h
  1264 00000540 B90100                  	mov	cx, 1
  1265 00000543 CD10                    	int	10h
  1266                                  
  1267 00000545 BE[8A54]                	mov	si, MasterBootBuff+pTableOffset
  1268 00000548 BF[6A6C]                	mov	di, part_table_boot_ind ; (**)
  1269                                  
  1270                                  	; Clear all of possible active partition flags
  1271 0000054B 8834                    	mov	[si], dh ; 0
  1272 0000054D 887410                  	mov	[si+16], dh ; 0
  1273 00000550 887420                  	mov	[si+32], dh ; 0
  1274 00000553 887430                  	mov	[si+48], dh ; 0
  1275                                  
  1276                                  	; 09/03/2021
  1277                                  	; This may not be needed !?
  1278                                  	; (**) (Primary partitions structure/list)
  1279 00000556 8835                    	mov	[di], dh ; 0
  1280 00000558 887516                  	mov	[di+22], dh ; 0
  1281 0000055B 88752C                  	mov	[di+44], dh ; 0
  1282 0000055E 887542                  	mov	[di+66], dh ; 0
  1283                                  
  1284 00000561 20D2                    	and 	dl, dl
  1285 00000563 740D                    	jz	short ap_4
  1286                                  
  1287 00000565 89D0                    	mov	ax, dx
  1288                                  
  1289 00000567 C0E004                  	shl	al, 4 ; * 16
  1290 0000056A 01C6                    	add	si, ax
  1291                                  
  1292                                  	;mov	al, 18
  1293                                  	; 05/11/2020
  1294 0000056C B016                    	mov	al, 22
  1295 0000056E F6E2                    	mul	dl ; 1 to 3
  1296 00000570 01C7                    	add	di, ax
  1297                                  ap_4:
  1298                                  	; Then	set active partition as requested by user
  1299 00000572 C60480                  	mov	byte [si], 80h
  1300 00000575 C60580                  	mov	byte [di], 80h ; (**)
  1301                                  
  1302 00000578 BE[5152]                	mov	si, CRLF ; Next line
  1303 0000057B E83214                  	call	print_msg
  1304                                  
  1305                                  	; NOTE: Only the MBR buffer has been changed
  1306                                  	; (Masterboot sector will not be updated unless/till
  1307                                  	;  MBR partition table -and MBR code- will be written
  1308                                  	;  to disk image as result of 'write part. table' command.)
  1309                                  
  1310                                  	;; wait for 1 second
  1311                                  	;mov	ah, 02h
  1312                                  	;int	1Ah
  1313                                  	;mov	[GetChar], dh
  1314                                  ;ap_wait:
  1315                                  	;mov	ah, 02h
  1316                                  	;int	1Ah
  1317                                  	;cmp	dh, [GetChar]
  1318                                  	;je	short ap_wait
  1319                                  
  1320                                  	; 17/10/2020 
  1321 0000057E E952FE                  	jmp	A_42 ; display partition table again
  1322                                  
  1323                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1324                                  ; delete selected partition
  1325                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1326                                  ; 19/10/2020
  1327                                  
  1328                                  delete_partition:
  1329                                  	; 10/02/2019
  1330                                  	;xor	al, al  ; MBR/PRIMARY PARTITIONS
  1331                                  	; 12/03/2021
  1332                                  	;xor	eax, eax
  1333 00000581 E82520                  	call	display_partition_table
  1334                                  
  1335 00000584 803E[C26C]00            	cmp	byte [pcount], 0
  1336 00000589 7712                    	ja	short dp_1
  1337                                  
  1338 0000058B BE[FE57]                	mov	si, msg_empty_pt
  1339 0000058E E81F14                  	call	print_msg
  1340                                  
  1341 00000591 BE[AD52]                	mov	si, msg_press_any_key
  1342 00000594 E81914                  	call	print_msg
  1343                                  
  1344 00000597 30E4                    	xor	ah, ah
  1345 00000599 CD16                    	int	16h
  1346                                  
  1347 0000059B EB73                    	jmp	short dp_esc
  1348                                  
  1349                                  dp_1:
  1350                                  	; Set valid_ppnums (MBR partition IDs) list
  1351 0000059D BE[8A54]                	mov	si, MasterBootBuff+pTableOffset ; MasterBootBuff+446
  1352 000005A0 BB[0C6C]                	mov	bx, valid_ppnums
  1353 000005A3 B104                    	mov	cl, 4
  1354                                  dp_2:
  1355 000005A5 8A4404                  	mov	al, [si+ptFileSystemID]
  1356 000005A8 8807                    	mov	[bx], al
  1357 000005AA FEC9                    	dec	cl
  1358 000005AC 7406                    	jz	short dp_3
  1359 000005AE 43                      	inc	bx
  1360 000005AF 83C610                  	add	si, 16
  1361 000005B2 EBF1                    	jmp	short dp_2
  1362                                  dp_3:
  1363 000005B4 BE[B958]                	mov	si, msg_enter_pn_to_del
  1364 000005B7 E8F613                  	call	print_msg
  1365                                  dp_getchar1:
  1366 000005BA 30E4                    	xor	ah, ah
  1367 000005BC CD16                    	int	16h
  1368                                  	
  1369                                  	; 19/10/2020
  1370 000005BE 3C1B                    	cmp	al, 27
  1371 000005C0 744E                    	je	short dp_esc
  1372 000005C2 3C30                    	cmp	al, '0'
  1373 000005C4 744A                    	je	short dp_esc
  1374                                  	;cmp	al, '1'
  1375 000005C6 72F2                    	jb	short dp_getchar1
  1376 000005C8 3C34                    	cmp	al, '4'
  1377 000005CA 77EE                    	ja	short dp_getchar1
  1378                                  
  1379 000005CC 30FF                    	xor	bh, bh
  1380 000005CE 88C3                    	mov	bl, al
  1381                                  	;dec	bl
  1382 000005D0 80EB31                  	sub	bl, '1'
  1383 000005D3 38BF[0C6C]              	cmp	byte [bx+valid_ppnums], bh ; 0 ; 12/02/2019
  1384 000005D7 76E1                    	jna	short dp_getchar1  ; Empty partition table entry, it is not shown
  1385                                  	
  1386 000005D9 881E[166C]              	mov	[del_part_num], bl ; Selected partition number to be deleted.
  1387 000005DD A2[DD58]                	mov	[chr_del_pnum1], al ; Partition number for "Enter ..." text
  1388 000005E0 A2[7F59]                	mov	[chr_del_pnum2], al ; Partition number for "Do you want ..." text
  1389                                  
  1390 000005E3 BE[DD58]                	mov	si, chr_del_pnum1 ; write partition number (user input)
  1391 000005E6 E8C713                  	call	print_msg
  1392                                  
  1393                                  	;xor	al, al
  1394 000005E9 A2[DD58]                	mov	[chr_del_pnum1], al ; 0 ; reset
  1395                                  
  1396 000005EC BE[E158]                	mov	si, msg_delete_partition_q ; question for deleting (with warning)
  1397 000005EF E8BE13                  	call	print_msg
  1398                                  
  1399                                  dp_getchar2:
  1400 000005F2 30E4                    	xor	ah, ah
  1401 000005F4 CD16                    	int	16h
  1402                                  
  1403 000005F6 3C1B                    	cmp	al, 27
  1404 000005F8 7416                    	je	short dp_esc
  1405                                  
  1406 000005FA 24DF                    	and	al, 0DFh
  1407 000005FC 3C59                    	cmp	al, 'Y'
  1408 000005FE 7413                    	je	short dp_yes
  1409 00000600 3C4E                    	cmp	al, 'N'
  1410 00000602 75EE                    	jne	short dp_getchar2
  1411                                  dp_no:
  1412 00000604 BE[9159]                	mov	si, msg_NO ;  Write 'NO' (it may be shown for a moment)
  1413 00000607 E8A613                  	call	print_msg
  1414                                  	
  1415 0000060A BE[5152]                	mov	si, CRLF  ; Next line
  1416 0000060D E8A013                  	call	print_msg
  1417                                  	
  1418                                  	;jmp	short dp_esc
  1419                                  
  1420                                  ;cp_esc:
  1421                                  ;ap_esc:
  1422                                  ;wptmbr_esc:
  1423                                  dp_esc:
  1424                                  	;xor	al, al  ; MBR/PRIMARY PARTITIONS
  1425                                  	;call	display_partition_table
  1426                                  	;jmp	A_38 ; 17/10/2020
  1427                                  
  1428                                  	; 19/10/2020
  1429 00000610 E9C0FD                  	jmp	A_42
  1430                                  
  1431                                  dp_yes:
  1432 00000613 BE[8B59]                	mov	si, msg_YES ;  Write 'YES' (it may be shown for a moment)
  1433 00000616 E89713                  	call	print_msg
  1434                                  
  1435 00000619 BF[8A54]                	mov	di, MasterBootBuff+pTableOffset
  1436 0000061C A0[166C]                	mov	al, [del_part_num]
  1437 0000061F 20C0                    	and 	al, al
  1438 00000621 7406                    	jz	short dp_4
  1439 00000623 98                      	cbw
  1440                                  	;xor	ah, ah
  1441 00000624 C0E004                  	shl	al, 4 ; * 16
  1442 00000627 01C7                    	add	di, ax
  1443                                  dp_4:
  1444 00000629 BE[5152]                	mov	si, CRLF ; Next line
  1445 0000062C E88113                  	call	print_msg
  1446                                  
  1447                                  	; 27/02/2019
  1448 0000062F 807D0405                	cmp	byte [di+ptFileSystemID], 05h ; EXTENDED (CHS)
  1449                                  	;jne	short dp_5
  1450 00000633 7406                    	je	short dp_6
  1451                                  	; 24/10/2020
  1452 00000635 807D040F                	cmp	byte [di+ptFileSystemID], 0Fh ; EXTENDED (LBA)
  1453 00000639 7545                    	jne	short dp_5
  1454                                  dp_6:
  1455 0000063B 3806[F869]              	cmp	byte [ldrives], al ; 0
  1456 0000063F 763F                    	jna	short dp_5
  1457                                  
  1458 00000641 BE[015C]                	mov	si, msg_ext_part_del_error
  1459 00000644 E86913                  	call	print_msg
  1460 00000647 BE[415C]                	mov	si, msg_cancel_continue
  1461 0000064A E86313                  	call	print_msg
  1462                                       	
  1463 0000064D 30E4                    	xor	ah, ah
  1464 0000064F CD16                    	int	16h
  1465                                  	
  1466 00000651 3C1B                    	cmp	al, 27 ; ESCape
  1467 00000653 74BB                    	je	short dp_esc
  1468                                  
  1469 00000655 E8A327                  	call	delete_logical_drives
  1470                                  	
  1471                                  	; 28/02/2019
  1472 00000658 803E[F869]01            	cmp	byte [ldrives], 1
  1473 0000065D 73B1                    	jnb	short dp_esc
  1474                                  
  1475                                  	;xor	al, al  ; MBR/PRIMARY PARTITIONS
  1476                                  	; 12/03/2021
  1477                                  	;xor	eax, eax
  1478 0000065F E8471F                  	call	display_partition_table
  1479                                  
  1480 00000662 BE[D45C]                	mov	si, msg_delete_ext_part
  1481 00000665 E84813                  	call	print_msg
  1482                                  
  1483                                  dp_ask_again:
  1484 00000668 28E4                    	sub	ah, ah
  1485 0000066A CD16                    	int	16h
  1486                                  
  1487 0000066C 3C1B                    	cmp	al, 27 ; ESCape
  1488 0000066E 74A0                    	je	short dp_esc
  1489                                  
  1490 00000670 3C0D                    	cmp	al, 13 ; ENTER/CR
  1491 00000672 75F4                    	jne	short dp_ask_again
  1492                                  
  1493 00000674 BF[8A54]                	mov	di, MasterBootBuff+pTableOffset
  1494 00000677 A0[166C]                	mov	al, [del_part_num]
  1495 0000067A 98                      	cbw
  1496 0000067B C0E004                  	shl	al, 4 ; * 16
  1497 0000067E 01C7                    	add	di, ax
  1498                                  dp_5:
  1499 00000680 31C0                    	xor	ax, ax
  1500                                  
  1501                                  	; clear partition table entry in MBR buffer
  1502 00000682 B90800                  	mov	cx, 8
  1503 00000685 F3AB                    	rep	stosw
  1504                                  	
  1505                                  	; NOTE: Only the MBR buffer will be cleared
  1506                                  	; (Masterboot sector will not be updated unless/till
  1507                                  	;  MBR partition table -and MBR code- will be written
  1508                                  	;  to disk image as result of 'write part. table' command.)
  1509                                  
  1510 00000687 E973FB                  	jmp	A_21 ; 17/10/2020
  1511                                   	 
  1512                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1513                                  ; write partition table (and MBR code) onto disk
  1514                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1515                                  ; 18/10/2020
  1516                                  
  1517                                  	; 13/03/2021 (fdisk4.s)	
  1518                                  write_pt_mbr:
  1519                                  	; 18/10/2020 (fdisk3.s)
  1520                                  	; 11/02/2019 (hdimage.s)
  1521                                  	;xor	al, al  ; MBR/PRIMARY PARTITIONS
  1522                                  	; 12/03/2021
  1523                                  	;xor	eax, eax
  1524 0000068A E81C1F                  	call	display_partition_table
  1525                                  
  1526 0000068D BE[9559]                	mov	si, msg_write_masterboot_sector
  1527 00000690 E81D13                  	call	print_msg
  1528                                  
  1529 00000693 A2[E269]                	mov	[GetChar], al ; 0
  1530                                  
  1531 00000696 BE[785A]                	mov	si, option_input
  1532 00000699 E81413                  	call	print_msg
  1533                                  
  1534 0000069C B403                    	mov	ah, 3
  1535                                  	;mov	bx, 7
  1536 0000069E CD10                    	int	10h ; Return Cursor Position
  1537                                  	; DL = Column
  1538                                  	
  1539 000006A0 FECA                    	dec	dl ; previous char ; ']'
  1540 000006A2 FECA                    	dec	dl ; previous char ; '[ ]'
  1541                                  
  1542 000006A4 B402                    	mov	ah, 2
  1543                                  	;mov	bx, 7
  1544 000006A6 CD10                    	int	10h ; Set Cursor Position
  1545                                  
  1546                                  	; write char at current cursor position
  1547                                  
  1548 000006A8 B030                    	mov	al, '0' ; Write default char
  1549                                  
  1550                                  	;;mov	bx, 07h
  1551 000006AA B409                    	mov	ah, 09h
  1552 000006AC B90100                  	mov	cx, 1
  1553 000006AF CD10                    	int	10h
  1554                                  
  1555                                  wptmbr_getchar:
  1556 000006B1 30E4                    	xor	ah, ah
  1557 000006B3 CD16                    	int	16h
  1558                                  
  1559 000006B5 3C1B                    	cmp	al, 1Bh ; 27
  1560                                  	;je	wptmbr_esc ; 19/10/2020
  1561 000006B7 0F8418FD                	je	A_42
  1562                                  
  1563 000006BB 3C0D                    	cmp	al, 0Dh ; 13
  1564 000006BD 7414                    	je	short wptmbr_1
  1565                                                  
  1566 000006BF 3C31                    	cmp	al, '1'
  1567 000006C1 72EE                    	jb	short wptmbr_getchar
  1568                                  
  1569 000006C3 3C32                    	cmp	al, '2'
  1570 000006C5 77EA                    	ja 	short wptmbr_getchar
  1571                                  
  1572 000006C7 A2[E269]                	mov	[GetChar], al
  1573                                  
  1574                                  	;;mov	bx, 07h
  1575 000006CA B409                    	mov	ah, 09h
  1576 000006CC B90100                  	mov	cx, 1
  1577 000006CF CD10                    	int	10h
  1578 000006D1 EBDE                    	jmp	short wptmbr_getchar
  1579                                  
  1580                                  wptmbr_1:
  1581 000006D3 803E[E269]00            	cmp	byte [GetChar], 0
  1582 000006D8 76D7                    	jna	short wptmbr_getchar
  1583                                  
  1584 000006DA BE[465A]                	mov	si, msg_writing_ptable
  1585 000006DD E8D012                  	call	print_msg
  1586                                  
  1587 000006E0 803E[E269]32            	cmp	byte [GetChar], '2'
  1588 000006E5 7523                    	jne	short wptmbr_2 ; Do not write Singlix MBR code
  1589                                  
  1590                                  	; Write CHS parameters in Singlix (FS specific) MBR
  1591                                  	
  1592 000006E7 BE[902E]                	mov	si, TRDOS386_MASTERBOOT_SECTOR
  1593 000006EA B9DF00                  	mov	cx, 446/2 ; Copy Singlix FS 1 MBR code
  1594                                  			  ; except Partition Table
  1595 000006ED BF[CC52]                	mov	di, MasterBootBuff
  1596 000006F0 F3A5                    	rep	movsw
  1597                                  	
  1598                                  	; This (Below) is not needed; because, if MBR magicword
  1599                                  	; would not be 0AA55h, we would not be able to come here!
  1600                                  	;;add	di, 64  ; skip partition table	
  1601                                  	;;mov	ax, 0AA55h
  1602                                  	;;stosw
  1603                                  	;mov 	word [MBIDCode], 0AA55h
  1604                                  
  1605                                  	; 12/02/2019
  1606                                  	; Copy CHS parameters to Singlix MBR (on disk)
  1607                                  	
  1608                                  	; 13/03/2021
  1609                                  	;mov	di, MasterBootBuff+420
  1610 000006F2 BF[6F54]                	mov	di, MasterBootBuff+419
  1611                                  	
  1612                                  	; (if disk size > 512 GB, number of cylinders will be > 65535)
  1613 000006F5 A0[A83C]                	mov	al, [cylinders+2]
  1614 000006F8 AA                      	stosb
  1615                                  	;
  1616 000006F9 A1[A63C]                	mov	ax, [cylinders]
  1617 000006FC AB                      	stosw 			; cylinders
  1618 000006FD A1[A43C]                	mov	ax, [heads]
  1619 00000700 AB                      	stosw 			; heads
  1620 00000701 A1[A23C]                	mov	ax, [sectors]
  1621 00000704 AB                      	stosw 			; sectors
  1622                                  
  1623                                  	; 13/03/2021
  1624                                  	; copy 32 bit disk size (total LBA sectors) to MBR offset 426
  1625 00000705 BE[2665]                	mov	si, disksize
  1626 00000708 A5                      	movsw
  1627 00000709 A5                      	movsw
  1628                                  
  1629                                  wptmbr_2:
  1630                                  	;xor	ax, ax ; 0
  1631                                  	;xor	dx, dx ; 0
  1632                                  	;; DX_AX = Masterboot Sector = 0
  1633                                  	;mov	bx, MasterBootBuff
  1634                                  	;; ES:BX = Sector Buffer
  1635                                  	;call	write_hd_sector
  1636                                  	;jc	short print_error_code
  1637                                  			; ! display error msg and then exit !
  1638                                  
  1639 0000070A C606[2565]05            	mov	byte [rcnt], 5  ; retry count
  1640                                  
  1641 0000070F BB[CC52]                	mov	bx, MasterBootBuff
  1642                                  
  1643 00000712 B90100                  	mov	cx, 1	; cylinder = 0
  1644                                  			; sector = 1
  1645 00000715 B600                    	mov	dh, 0	; head = 0
  1646 00000717 8A16[2265]              	mov	dl, [DrvNum]
  1647                                  wptmbr_3:
  1648 0000071B B80103                  	mov	ax, 0301h ; write one sector
  1649 0000071E CD13                    	int	13h	
  1650 00000720 730C                    	jnc     short wptmbr_4
  1651                                               
  1652 00000722 FE0E[2565]              	dec	byte [rcnt]
  1653 00000726 7431                    	jz	short print_error_code
  1654                                          
  1655 00000728 30E4                    	xor	ah, ah
  1656                                  	;mov	dl, [DrvNum]
  1657 0000072A CD13                    	int	13h	; BIOS Service func (ah) = 0
  1658                                  			; Reset disk system
  1659 0000072C EBED                    	jmp	short wptmbr_3
  1660                                  
  1661                                  wptmbr_4:
  1662 0000072E BE[6F5A]                	mov	si, _msg_OK
  1663 00000731 E87C12                  	call	print_msg
  1664                                  
  1665                                  	; wait for 1 second
  1666 00000734 B402                    	mov	ah, 02h
  1667 00000736 CD1A                    	int	1Ah
  1668 00000738 8836[E269]              	mov	[GetChar], dh
  1669                                  wptmbr_wait:
  1670 0000073C B402                    	mov	ah, 02h
  1671 0000073E CD1A                    	int	1Ah
  1672 00000740 3A36[E269]              	cmp	dh, [GetChar]
  1673 00000744 74F6                    	je	short wptmbr_wait
  1674                                  	
  1675 00000746 BE[AD52]                	mov	si, msg_press_any_key
  1676 00000749 E86412                  	call	print_msg
  1677                                                  
  1678 0000074C 30E4                    	xor	ah, ah	; "Press any key to continue"
  1679 0000074E CD16                    	int	16h
  1680                                  
  1681 00000750 BE[5152]                	mov	si, CRLF
  1682 00000753 E85A12                  	call	print_msg
  1683                                  
  1684                                  	;jmp	wptmbr_esc
  1685                                  	; 19/10/2020
  1686 00000756 E97AFC                  	jmp	A_42
  1687                                  
  1688                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1689                                  ; print error message and exit
  1690                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1691                                  ; 18/10/2020 (fdisk3.s)
  1692                                  	
  1693                                  print_error_code:
  1694                                  	; 25/02/2019 (hdimage.s)
  1695                                  
  1696 00000759 88E0                    	mov	al, ah	; error code
  1697 0000075B E82613                  	call	bin_to_hex
  1698 0000075E A3[5F52]                	mov 	[error_code], ax
  1699                                  
  1700 00000761 BE[5152]                	mov	si, CRLF
  1701 00000764 E84912                  	call	print_msg
  1702                                  
  1703 00000767 BE[5452]                	mov	si, Msg_Error
  1704 0000076A E84312                  	call	print_msg
  1705                                  	
  1706 0000076D CD20                    	int	20h	; Exit
  1707                                  
  1708                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1709                                  ; exit, print_msg & exit
  1710                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1711                                  ; 19/10/2020
  1712                                  
  1713                                  _crlf_exit:
  1714 0000076F BE[5152]                	mov	si, CRLF
  1715                                  _p_exit:
  1716                                  	; 11/10/2020
  1717 00000772 E83B12                  	call	print_msg
  1718                                  _exit:
  1719 00000775 B8004C                  	mov	ax, 4C00h		; terminate
  1720 00000778 CD21                    	int	21h
  1721                                  
  1722                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1723                                  ; display create partition menu & get partition type input
  1724                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1725                                  ; 19/10/2020
  1726                                  
  1727                                  create_partition_input:
  1728                                  	; 15/02/2019
  1729                                  	; clear screen
  1730 0000077A B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
  1731 0000077D CD10                    	int	10h
  1732                                  	
  1733 0000077F BE[4B42]                	mov	si, msg_create_partition_h ; header
  1734 00000782 E82B12                  	call	print_msg
  1735 00000785 BE[4043]                	mov	si, msg_create_partition_m ; menu
  1736 00000788 E82512                  	call	print_msg
  1737                                  cpi_1:
  1738 0000078B 30E4                    	xor	ah, ah
  1739 0000078D CD16                    	int	16h
  1740 0000078F 3C1B                    	cmp	al, 27 ; ESC key
  1741 00000791 7445                    	je	short cpi_4  ; 25/02/2019
  1742 00000793 3C30                    	cmp	al, '0'
  1743 00000795 7441                    	je	short cpi_4  ; 25/02/2019
  1744 00000797 72F2                    	jb	short cpi_1
  1745 00000799 3C34                    	cmp	al, '4'
  1746 0000079B 77EE                    	ja	short cpi_1
  1747                                  
  1748 0000079D 30E4                    	xor	ah, ah
  1749 0000079F 2C30                    	sub	al, '0'
  1750                                  
  1751                                  	;mov	[pp_type], al
  1752                                  
  1753                                  	;mov	byte [pp_type_user], 0
  1754                                  
  1755 000007A1 3C01                    	cmp	al, 1 ; DOS partition
  1756 000007A3 7536                    	jne	short cpi_5 ; ah = 0 
  1757                                  			    ; (al = 2 -> singlix, al = 3 -> retro unix)
  1758                                  cpi_2:
  1759                                  	; clear screen
  1760 000007A5 B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
  1761 000007A8 CD10                    	int	10h
  1762                                  	
  1763 000007AA BE[F644]                	mov	si, msg_create_dos_partition_h ; header
  1764 000007AD E80012                  	call	print_msg
  1765 000007B0 BE[CA48]                	mov	si, msg_create_dos_partition_m ; menu
  1766 000007B3 E8FA11                  	call	print_msg
  1767                                  cpi_3:
  1768 000007B6 30E4                    	xor	ah, ah
  1769 000007B8 CD16                    	int	16h
  1770 000007BA 3C1B                    	cmp	al, 27 ; ESC key
  1771 000007BC 741A                    	je	short cpi_4
  1772 000007BE 3C30                    	cmp	al, '0'
  1773 000007C0 7416                    	je	short cpi_4
  1774 000007C2 72F2                    	jb	short cpi_3
  1775 000007C4 3C33                    	cmp	al, '3'
  1776 000007C6 77EE                    	ja	short cpi_3
  1777                                  	
  1778 000007C8 30E4                    	xor	ah, ah
  1779 000007CA 2C30                    	sub	al, '0'
  1780 000007CC 3C01                    	cmp	al, 1
  1781 000007CE 7424                    	je	short cpi_6  ;	ah = 0 (al = primary dos partition)
  1782                                  
  1783                                  	;mov	byte [pp_type], 5
  1784                                  
  1785 000007D0 3C02                    	cmp	al, 2
  1786 000007D2 7621                    	jna	short cpi_7
  1787                                  
  1788 000007D4 B80600                  	mov	ax, 6	; ah = 0 (al = logical dos drive/partition)
  1789 000007D7 C3                      	retn
  1790                                  
  1791                                  cpi_4:
  1792 000007D8 31C0                    	xor	ax, ax	; ah = 0 (al = 0 -> ESCape/Cancel)
  1793 000007DA C3                      	retn
  1794                                  cpi_5:
  1795 000007DB 3C04                    	cmp	al, 4	 ; option num. for partition type (user) input
  1796 000007DD 7515                    	jne	short cpi_6
  1797                                  
  1798 000007DF E82F16                  	call	partition_type_input
  1799                                  	
  1800                                  	; 29/10/2020
  1801 000007E2 08C0                    	or	al, al
  1802                                  	;jz	short cpi_6 ; invalid (zero) input or ESC key
  1803 000007E4 74F2                    	jz	short cpi_4
  1804                                  
  1805 000007E6 B404                    	mov	ah, 4 ; user/another type partition flag
  1806                                  	; al = Partition ID
  1807 000007E8 50                      	push	ax
  1808 000007E9 BE[AD52]                	mov	si, msg_press_any_key 
  1809 000007EC E8C111                  	call	print_msg
  1810 000007EF 28E4                    	sub	ah, ah
  1811 000007F1 CD16                    	int	16h
  1812 000007F3 58                      	pop	ax
  1813                                  cpi_6:
  1814 000007F4 C3                      	retn
  1815                                  cpi_7:
  1816 000007F5 B80500                  	mov	ax, 5	; ah = 0 (al = extended dos partition)
  1817 000007F8 C3                      	retn
  1818                                  
  1819                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1820                                  ; create primary (dos or non-dos) partition
  1821                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1822                                  ; 19/10/2020 
  1823                                  ;	(This procedure must be called after 'find_part_free_space')
  1824                                  
  1825                                  	; 14/03/2021 (fdisk4.s)
  1826                                  create_primary_partition:  
  1827                                  	; 16/02/2019
  1828                                  
  1829                                  	; INPUT:
  1830                                  	;	none 
  1831                                  	;  (CHS parameters and free space calculation result will be used.) 
  1832                                  	;
  1833                                  	; OUTPUT:
  1834                                  	;	Partition table in MBR buffer will be updated.
  1835                                  	;
  1836                                  	; (Modified registers: ax, bx, cx, dx, si, di)
  1837                                  
  1838                                  	; Create primary dos or non-dos partition,
  1839                                  	; make partition table entry
  1840                                  
  1841                                  	; 19/10/2020
  1842 000007F9 803E[C26C]00            	cmp	byte [pcount], 0  ; count of (valid) partitions
  1843 000007FE 770B                    	ja	short cpp_0
  1844                                  
  1845                                  	; cylinder = 0, head = 1, sector = 1
  1846                                  	; LBA = (((cylinder*heads)+head)*sectors)+sector-1
  1847                                  
  1848 00000800 BE[8A54]                	mov	si, MasterBootBuff+pTableOffset
  1849                                  
  1850                                  	;mov	ax, [sectors] ; LBA = 17 or 63
  1851                                  	; 07/11/2020
  1852 00000803 660FB606[A23C]          	movzx	eax, byte [sectors]
  1853                                  	;xor	dx, dx
  1854 00000809 EB4F                    	jmp	short cpp_4
  1855                                  cpp_0:
  1856                                  	; 16/02/2019
  1857 0000080B E8471D                  	call	get_first_free_pte
  1858                                  		 ; CX = First free PTE number, 0 to 3 
  1859                                  		 ;    (CX = 3 if there is not a free PTE, and CF = 1)
  1860                                  		 ;    ((But CF = 1 is not possible here because pcount < 4))
  1861                                   	 	 ; SI = PTE address/offset in MBR buffer
  1862                                  
  1863                                  	;mov	si, MasterBootBuff+pTableOffset
  1864                                  	;shl	cl, 4 ; * 16
  1865                                  	;add	si, cx
  1866                                  
  1867                                  	; 18/02/2019
  1868 0000080E 8B3E[8C6D]              	mov	di, [c_fspc_offset]
  1869                                  	;mov	bx, [di+free_space.start]
  1870                                  	;mov	al, [heads]
  1871                                  	;; 07/11/2020
  1872                                  	;movzx	eax, byte [heads]
  1873                                  	;mul	byte [sectors]
  1874                                  	;;mul	bx
  1875                                  	;	; DX:AX = LBA of start cylinder, head 0, sector 1
  1876                                  	; 14/03/2021
  1877 00000812 66A1[E469]              	mov	eax, [hs] ; [heads] * [sectors]
  1878                                  	; 07/11/2020
  1879 00000816 668B9D[226D]            	mov	ebx, [di+free_space.start]
  1880 0000081B 66F7E3                  	mul	ebx
  1881                                  	;	; EAX =  LBA of start cylinder, head 0, sector 1
  1882                                  	
  1883 0000081E 8A0E[8E6D]              	mov	cl, [cylinder_boundary]
  1884                                  
  1885                                  	;cmp	cl, 0 ; Default (partition size unit is one of C, G, M)
  1886                                  		      ; boundary alignment is forced as default
  1887                                  	;je	short cpp_4
  1888                                  
  1889                                  	; 20/02/2019
  1890                                  	;and	cl, cl
  1891                                  	;jz 	short cpp_1
  1892                                  
  1893 00000822 80F959                  	cmp	cl, 'Y'
  1894 00000825 7433                    	je	short cpp_4 ; cylinder boundary option (answer) = YES
  1895                                  
  1896 00000827 80F94E                  	cmp	cl, 'N'
  1897 0000082A 7507                    	jne	short cpp_1 ; cylinder boundary option (answer) = YES/NO
  1898                                  
  1899                                  	; cylinder boundary option (answer) = NO 
  1900                                  	;mov	ax, [di+free_space.startsector]
  1901                                  	;mov	dx, [di+free_space.startsector+2]
  1902                                  	; 07/11/2020
  1903 0000082C 668B85[2E6D]            	mov	eax, [di+free_space.startsector]
  1904 00000831 EB27                    	jmp	short cpp_4
  1905                                  cpp_1:
  1906                                  	;cmp	cl, 27 ; ESCape
  1907                                  	;jne	short cpp_4 ; 'Y'
  1908                                  
  1909                                  	; check	cylinder boundary alignment of the start sector
  1910                                  
  1911                                  	; if start sector is not aligned, end sector must not be aligned
  1912                                  	; (this rule is valid for ESCape key from the user) 
  1913                                  
  1914 00000833 C606[8E6D]59            	mov	byte [cylinder_boundary], 'Y' ; YES for end sector check
  1915                                  
  1916                                  	;mov	cx, [di+free_space.startsector]
  1917                                  
  1918                                  	;or	bx, bx
  1919                                  
  1920                                  	;mov	bx, [di+free_space.startsector+2]
  1921                                  
  1922                                  	;jnz	short cpp_2 ; start cylinder > 0
  1923                                  
  1924                                  	;and	bx, bx
  1925                                  	;jnz	short cpp_3
  1926                                  
  1927 00000838 668B8D[2E6D]            	mov	ecx, [di+free_space.startsector]
  1928 0000083D 6609DB                  	or	ebx, ebx
  1929 00000840 750B                    	jnz	short cpp_2 ; start cylinder > 0
  1930                                  
  1931                                  	; 07/11/2020
  1932 00000842 8A1E[A23C]              	mov	bl, [sectors]
  1933                                  	;cmp	cx, [sectors]
  1934                                  	;je	short cpp_4 ; start sector is as aligned 
  1935 00000846 6639D9                  	cmp	ecx, ebx 
  1936 00000849 740F                    	je	short cpp_4 ; start sector is as aligned 
  1937 0000084B EB05                    	jmp	short cpp_3
  1938                                  cpp_2:
  1939                                  	;cmp	ax, cx
  1940                                  	;jne	short cpp_3
  1941                                  	;cmp	dx, bx
  1942                                  	;je	short cpp_4
  1943                                  	; 07/11/2020
  1944 0000084D 6639C8                  	cmp	eax, ecx
  1945 00000850 7408                    	je	short cpp_4
  1946                                  cpp_3:
  1947                                  	;mov	ax, cx
  1948                                  	;mov	dx, bx
  1949                                  	; 07/11/2020
  1950 00000852 6689C8                  	mov	eax, ecx 
  1951 00000855 C606[8E6D]4E            	mov	byte [cylinder_boundary], 'N'
  1952                                  cpp_4:
  1953                                  	;mov	[si+ptStartSector], ax
  1954                                  	;mov	[si+ptStartSector+2], dx
  1955                                  	; 07/11/2020
  1956 0000085A 66894408                	mov	[si+ptStartSector], eax
  1957                                  
  1958                                  	; save start sector (for partition formatting procedure)
  1959                                  	;mov	[pp_StartSector], ax
  1960                                  	;mov	[pp_StartSector+2], dx
  1961 0000085E 66A3[B869]              	mov	[pp_StartSector], eax
  1962                                  
  1963                                  	; 14/03/2021
  1964 00000862 668B0E[F069]            	mov	ecx, [ppn_Sectors]
  1965                                  
  1966                                  	; 19/10/2020
  1967 00000867 803E[C26C]00            	cmp	byte [pcount], 0
  1968 0000086C 7752                    	ja	short cpp_5
  1969                                  
  1970                                  	; 07/11/2020
  1971                                  	;;xor	cx, cx
  1972                                  	;xor	ecx, ecx
  1973                                  	;mov	[si+ptBeginCylinder], cx ; 0
  1974                                  	;inc	cl  ; 1
  1975                                  	;mov	[si+ptBeginSector], cl ; 1
  1976                                  	;mov	[si+ptBeginHead], cl ; 1
  1977                                  	; 14/03/2021
  1978 0000086E C744030000              	mov	word [si+ptBeginCylinder], 0
  1979 00000873 C6440201                	mov	byte [si+ptBeginSector], 1
  1980 00000877 C6440101                	mov	byte [si+ptBeginHead], 1
  1981                                  
  1982                                  	; set active partition flag
  1983                                  	;mov	byte [si+ptBootable], 80h ; bootable/active partition
  1984 0000087B C60480                  	mov	byte [si], 80h ; bootable/active partition
  1985                                  
  1986                                  	; 18/02/2019
  1987                                  
  1988                                  	;;mov	cx, [ppn_Sectors]
  1989                                  	;;mov	bx, [ppn_Sectors+2]
  1990                                  	; 07/11/2020
  1991                                  	;mov	ecx, [ppn_sectors]
  1992                                  
  1993 0000087E 803E[C069]00            	cmp	byte [wholedisk], 0
  1994 00000883 0F864101                	jna	cpp_12
  1995                                  
  1996                                  	; 26/10/2020
  1997                                  	;add	ax, cx
  1998                                  	;adc	dx, bx
  1999                                  	;sub	ax, 1
  2000                                  	;sbb	dx, 0 
  2001                                  	; 07/11/2020
  2002 00000887 6601C8                  	add	eax, ecx
  2003 0000088A 6648                    	dec	eax  ; sub eax, 1
  2004                                  
  2005                                  	; 24/10/2020
  2006                                  	;cmp	dx, [chs_limit+2]
  2007                                  	;jb	short cpp_17
  2008                                  	;ja	short cpp_16
  2009                                  	;cmp	ax, [chs_limit]
  2010                                  	;jna	short cpp_17
  2011                                  	; 07/11/2020
  2012 0000088C 663B06[2A65]            	cmp	eax, [chs_limit]
  2013 00000891 760F                    	jna	short cpp_17
  2014                                  cpp_16:
  2015 00000893 C64405FE                	mov	byte [si+ptEndHead], 0FEh
  2016 00000897 C64406FF                	mov	byte [si+ptEndSector], 0FFh
  2017 0000089B C64407FF                	mov	byte [si+ptEndCylinder], 0FFh
  2018 0000089F E9BA01                  	jmp	cpp_15
  2019                                  cpp_17:
  2020 000008A2 A0[A43C]                	mov	al, [heads]
  2021 000008A5 FEC8                    	dec	al
  2022 000008A7 884405                  	mov	[si+ptEndHead], al
  2023 000008AA A0[A23C]                	mov	al, [sectors]
  2024 000008AD 884406                  	mov	[si+ptEndSector], al
  2025 000008B0 A1[A63C]                	mov	ax, [cylinders]
  2026 000008B3 48                      	dec	ax
  2027 000008B4 884407                  	mov	[si+ptEndCylinder], al
  2028 000008B7 C0E406                  	shl	ah, 6
  2029 000008BA 086406                  	or	[si+ptEndSector], ah
  2030                                  
  2031                                  	;jmp	cpp_16
  2032 000008BD E99C01                  	jmp	cpp_15 ; 06/03/2019
  2033                                  cpp_5:
  2034                                  	; 14/03/2021
  2035                                  	; eax = start sector
  2036                                  
  2037                                  	; 18/02/2019
  2038 000008C0 803E[8E6D]59            	cmp	byte [cylinder_boundary], 'Y'
  2039 000008C5 7535                    	jne	short cpp_7
  2040                                  
  2041 000008C7 30DB                    	xor	bl, bl ; head  = 0
  2042                                  
  2043                                  	; 14/03/2021
  2044                                  	;mov	cx, [di+free_space.start]
  2045 000008C9 668B8D[226D]            	mov	ecx, [di+free_space.start]
  2046                                  	; ecx = start cylinder
  2047                                  
  2048                                  	; 06/03/2019
  2049                                  	;or	ax, ax
  2050                                  	;jnz	short cpp_6
  2051                                  
  2052                                  	;and	cx, cx  ; start cylinder = 0 ?
  2053                                  	;jnz	short cpp_6
  2054                                  
  2055                                  	;or	ax, cx
  2056                                  	;;jnz	short cpp_6
  2057                                  	;jz	short cpp_24 ; 31/10/2020
  2058                                  	; 14/03/2021
  2059 000008CE 6609C8                  	or	eax, ecx
  2060 000008D1 7409                    	jz	short cpp_24 ; cyl = 0, sector = 0
  2061                                  
  2062                                  	; 31/10/2020
  2063                                  	;mov	al, [sectors]
  2064                                  	;mul	byte [heads]
  2065                                  	;mul	cx
  2066                                  	;; dx:ax = LBA sector address
  2067                                  	;; bl = head = 0
  2068                                  	;; cx = cylinder number
  2069                                  	; 14/03/2021
  2070 000008D3 66A1[E469]              	mov	eax, [hs] ; [heads] * [sectors]
  2071 000008D7 66F7E1                  	mul	ecx 	
  2072                                  		; eax = LBA sector address
  2073                                  		; ecx = cylinder number
  2074                                  		; bl = head = 0
  2075                                   
  2076 000008DA EB05                    	jmp	short cpp_6
  2077                                  cpp_24:
  2078                                  	; 14/03/2021
  2079                                  	;mov	ax, [sectors]
  2080 000008DC A0[A23C]                	mov	al, [sectors]
  2081                                  
  2082                                  	; cylinder 0, head 1, sector 1 (LBA = 17 or 63)
  2083 000008DF FEC3                    	inc	bl  ; head = 1
  2084                                  	; 14/03/2021
  2085                                  	;xor	dx, dx ; 0
  2086                                  cpp_6:
  2087                                  	; 31/10/2020
  2088                                  	;mov	[si+ptStartSector], ax
  2089                                  	;mov	[si+ptStartSector+2], dx
  2090                                  	; 14/03/2021
  2091 000008E1 66894408                	mov	[si+ptStartSector], eax
  2092                                  
  2093                                  	;mov	[pp_StartSector], ax
  2094                                  	;mov	[pp_StartSector+2], dx
  2095                                  	; 14/03/2021
  2096 000008E5 66A3[B869]              	mov	[pp_StartSector], eax
  2097                                  
  2098                                  	;or	cx, cx  ; start cylinder ?
  2099                                  	;jnz	short cpp_25 ; > 0
  2100                                  	; 14/03/2021
  2101 000008E9 6609C9                  	or	ecx, ecx  ; start cylinder ?
  2102 000008EC 7505                    	jnz	short cpp_25 ; > 0
  2103                                  
  2104                                  	;and	bl, bl  ; head = 0 ?
  2105                                  	;jz	short cpp_25
  2106                                  
  2107                                  	; cylinder = 0, head = 1, dx:ax = [sectors]
  2108                                  
  2109                                  	;;sub	[pp_Sectors], ax
  2110                                  	;;sbb	[pp_Sectors+2], cx ; 0
  2111                                  
  2112                                  	;sub	[ppn_Sectors], ax
  2113                                  	;sbb	[ppn_Sectors+2], cx ; 0
  2114                                  	; 14/03/2021
  2115 000008EE 662906[F069]            	sub	[ppn_Sectors], eax
  2116                                  cpp_25:
  2117                                  	; 14/03/2021
  2118                                  	;mov	ax, cx
  2119 000008F3 6689C8                  	mov	eax, ecx
  2120                                  
  2121                                  	; 29/10/2020
  2122 000008F6 C6440201                	mov	byte [si+ptBeginSector], 1 ; sector = 1	
  2123 000008FA EB1E                    	jmp	short cpp_8
  2124                                  cpp_7:
  2125                                  	; 18/02/2019
  2126                                  
  2127                                  	; [wholedisk] = 0
  2128                                  
  2129                                  	; Fix partition size for MSDOS 3.3 (Retro DOS 3.0) compatibility.
  2130                                  	; (DOS partition size will be changed -down- to 65535 sectors,
  2131                                  	; if it is 65536 sectors.)
  2132                                  	
  2133 000008FC E86E01                  	call	fix_32mb_dos_psize
  2134                                  		; bx:cx = [ppn_sectors] = partition size
  2135                                  		; dx:ax = start sector's LBA
  2136                                  
  2137                                  	;cylinder = LBA / (heads_per_cylinder * sectors_per_track)
  2138                                  	;temp = LBA % (heads_per_cylinder * sectors_per_track)
  2139                                  	;head = temp / sectors_per_track
  2140                                  	;sector = temp % sectors_per_track + 1
  2141                                  	
  2142                                  	; Convert LBA sector address to CHS parameters
  2143                                  	;mov	cx, [sectors]
  2144                                  	;call	div32
  2145                                  	;; BX = Sector number - 1
  2146                                  	;inc	bl ; sector number (1 based)
  2147                                  	;mov	[si+ptBeginSector], bl
  2148                                  	
  2149                                  	; 14/03/2021
  2150                                  	; eax = start sector address (LBA)
  2151                                  
  2152                                  	; 07/11/2020
  2153 000008FF 6629D2                  	sub	edx, edx ; 14/03/2021
  2154                                  	;movzx	ecx, byte [sectors]
  2155 00000902 6631C9                  	xor	ecx, ecx
  2156 00000905 8A0E[A23C]              	mov	cl, [sectors]
  2157 00000909 66F7F1                  	div	ecx
  2158 0000090C FEC2                    	inc	dl ; sector number (1 based)
  2159 0000090E 885402                  	mov	[si+ptBeginSector], dl
  2160                                  	; eax = cylinders * heads + head
  2161                                  
  2162                                  	;; DX_AX = cylinders * heads + head
  2163                                  	;mov	cx, [heads]
  2164                                  	;call	div32
  2165                                  	;; ax = cylinder
  2166                                  	;; bl = head
  2167                                  
  2168                                  	; 07/11/2020
  2169                                  	;sub	edx, edx
  2170                                  	;sub	dx, dx
  2171 00000911 28D2                    	sub	dl, dl
  2172                                  	;movzx	ecx, byte [heads]
  2173 00000913 8A0E[A43C]              	mov	cl, [heads]
  2174 00000917 66F7F1                  	div	ecx
  2175                                  	; eax = cylinder
  2176                                  	; dl = head
  2177                                  cpp_8:
  2178                                  	;; 24/10/2020
  2179                                  	;;mov	bh, 1  ; [si+ptBeginSector]
  2180                                  	;cmp	ax, 1023  ; CHS limit
  2181                                  	;jna	short cpp_18	
  2182                                  	; 07/11/2020
  2183 0000091A 663DFF030000            	cmp	eax, 1023
  2184 00000920 760C                    	jna	short cpp_18
  2185                                  
  2186                                  	; > CHS limit
  2187                                  	;mov	ax, 1023 ; cylinder
  2188                                  	;mov	bl, 0FEh ; 254 (head)
  2189                                  	;mov	bh, 3Fh ; 63 (sector)
  2190                                  	; 07/11/2020
  2191 00000922 66B8FF030000            	mov	eax, 1023
  2192 00000928 B2FE                    	mov	dl, 0FEh ; 254
  2193                                  	; 26/10/2020
  2194 0000092A C644023F                	mov	byte [si+ptBeginSector], 3Fh
  2195                                  cpp_18:
  2196                                  	; 07/11/2020
  2197                                  	; DL = Head number
  2198 0000092E 885401                  	mov	[si+ptBeginHead], dl
  2199                                  
  2200                                  	;; BL = Head number
  2201                                  	;mov	[si+ptBeginHead], bl
  2202                                  	; AX = Cylinder number
  2203                                  	;and	ax, 1023
  2204 00000931 884403                  	mov	[si+ptBeginCylinder], al
  2205 00000934 C0E406                  	shl	ah, 6
  2206                                  	; 24/10/2020
  2207                                  	;or	ah, bh	; bh = sector number
  2208                                  	; 26/10/2020
  2209 00000937 086402                  	or	[si+ptBeginSector], ah
  2210                                  	;mov	[si+ptBeginSector], ah
  2211                                  
  2212                                  	; clear active partition flag (for now)
  2213                                  	;mov	byte [si+ptBootable], 0 ; not bootable/active partition
  2214 0000093A C60400                  	mov	byte [si], 0 ; not bootable/active partition
  2215                                  
  2216                                  	;mov	di, [c_fspc_offset]
  2217                                  
  2218 0000093D 803E[8E6D]59            	cmp	byte [cylinder_boundary], 'Y'
  2219 00000942 757B                    	jne	cpp_11
  2220                                  
  2221                                  	;mov	cl, [heads]
  2222                                  	;mov	al, [sectors]
  2223                                  	;mov	ch, al
  2224                                  	;mul	cl	
  2225                                  	;; ax = heads*sectors
  2226                                  	; 14/03/2021
  2227                                  	;mov	eax, [hs] ; heads * spt
  2228                                  
  2229                                  	;mov	bx, [di+free_space.end]	; end cylinder of the partition
  2230                                  	; 14/03/2021
  2231                                  	;mov	ebx, [di+free_space.end]
  2232 00000944 668B85[266D]            	mov	eax, [di+free_space.end]
  2233                                  
  2234 00000949 803E[C069]00            	cmp	byte [wholedisk], 0 ; entire free space ?
  2235 0000094E 771C                    	ja	short cpp_10
  2236                                  
  2237                                  	;mov	bx, ax
  2238                                  	;mov	ax, [ppn_Sectors]
  2239                                  	;mov	dx, [ppn_Sectors+2]
  2240                                  	;add	ax, [pp_StartSector]
  2241                                  	;adc	dx, [pp_StartSector+2]
  2242                                  	;sub	ax, 1
  2243                                  	;sbb	dx, 0
  2244                                  	;	; dx:ax = end sector
  2245                                  	;div	bx
  2246                                  	;	; ax = cylinder number
  2247                                  	; 14/03/2021
  2248                                  	;mov	ebx, eax
  2249 00000950 66A1[F069]              	mov	eax, [ppn_Sectors]
  2250 00000954 660306[B869]            	add	eax, [pp_StartSector]
  2251 00000959 6648                    	dec	eax
  2252 0000095B 6631D2                  	xor	edx, edx
  2253                                  	;div	ebx
  2254 0000095E 66F736[E469]            	div	dword [hs] ; heads * spt
  2255                                  		; eax = (end) cylinder number
  2256                                  
  2257                                  	; 31/10/2020
  2258                                  	;and	dx, dx
  2259                                  	;jz	short cpp_9
  2260                                  	;inc	ax ; + 1 (because of remainder > 0)
  2261                                  cpp_9:	
  2262                                  	;xchg	ax, bx
  2263                                  	;	; bx = end cylinder
  2264                                  	;	; ax = heads*sectors
  2265                                  	; 14/03/2021
  2266                                  	;xchg	eax, ebx
  2267                                  
  2268                                  	; free space limit check
  2269                                  	;cmp	bx, [di+free_space.end]
  2270                                  	;jna	short cpp_10 ; ok
  2271                                  	;; end cylinder is out of free space
  2272                                  	;dec	bx  ; decrease end cylinder number
  2273                                  	; 14/03/2021
  2274 00000963 663B85[266D]            	cmp	eax, [di+free_space.end]
  2275 00000968 7602                    	jna	short cpp_10 ; ok
  2276 0000096A 6648                    	dec	eax
  2277                                  cpp_10: 
  2278 0000096C 6650                    	push	eax ; * ; end cylinder
  2279                                  	;mul	bx
  2280                                  	;	 ; dx:ax = (end cylinder)*heads*sectors
  2281                                  	; 14/03/2021
  2282 0000096E 66F726[E469]            	mul	dword [hs] ; heads * spt
  2283                                  		; eax = (end cylinder)*heads*sectors
  2284                                  		; edx = 0
  2285 00000973 665A                    	pop	edx ; * ; end cylinder
  2286                                  
  2287                                  	;push	dx ; **
  2288                                  	;push	ax ; *
  2289                                  	; 14/03/2021
  2290 00000975 6650                    	push	eax ; **
  2291                                  
  2292 00000977 6631C0                  	xor	eax, eax ; clear high word of eax
  2293 0000097A A0[A23C]                	mov	al, [sectors]
  2294 0000097D 8A26[A43C]              	mov	ah, [heads]
  2295                                  
  2296                                  	; 24/10/2020
  2297                                  	;cmp	bx, 1023  ; CHS limit
  2298                                  	;jna	short cpp_19	
  2299                                  	;; > CHS limit
  2300                                  	;mov	bx, 1023 ; cylinder
  2301                                  	;;mov	cl, 0FFh ; 255 (head+1)
  2302                                  	;;mov	ch, 3Fh ; 63 (sector)
  2303                                  	;mov	cx, 3FFFh
  2304                                  	; 14/03/2021
  2305 00000981 6681FAFF030000          	cmp	edx, 1023  ; CHS limit
  2306 00000988 7609                    	jna	short cpp_19	
  2307                                  	; > CHS limit
  2308 0000098A 66BAFF030000            	mov	edx, 1023 ; cylinder
  2309 00000990 B83FFF                  	mov	ax, 0FF3Fh ; heads = 255, sector = 63
  2310                                  cpp_19:
  2311                                  	;dec	cl ; heads - 1 = end head
  2312                                  	; 14/03/2021
  2313 00000993 FECC                    	dec	ah ; heads - 1 = end head
  2314                                  
  2315                                  	; 14/03/2021
  2316                                  	; al = sectors (spt), ah = end head
  2317                                  
  2318                                  	;mov	[si+ptEndHead], cl
  2319                                  	; 14/03/2021
  2320 00000995 886405                  	mov	[si+ptEndHead], ah
  2321                                  
  2322                                  	;; 26/10/2020
  2323                                  	;;mov	al, [sectors]
  2324                                  	;; 31/10/2020
  2325                                  	;mov	al, ch
  2326                                  	;mov	[si+ptEndCylinder], bl
  2327                                  	;;mov	bl, al
  2328                                  	;;shl	bh, 6 ; shift high bytes (2 bits) of end cyl num
  2329                                  	;;	      ; to 6 bits left	
  2330                                  	;;or	bh, bl ; combine high bits of end cyl num and end sector
  2331                                  	;shl	bh, 6
  2332                                  	;or	bh, ch ; ch = end sector (= sectors)
  2333                                  	;mov	[si+ptEndSector], bh
  2334                                  	; 14/03/2021
  2335 00000998 885407                  	mov	[si+ptEndCylinder], dl
  2336 0000099B C0E606                  	shl	dh, 6
  2337 0000099E 08C6                    	or	dh, al ; or dh, byte [sectors]
  2338 000009A0 887406                  	mov	[si+ptEndSector], dh
  2339                                  
  2340                                  	; 24/10/2020
  2341                                  	;;mov	bl, [sectors]
  2342                                  	;;xor	bh, bh ; clear bh
  2343                                  	;mov	bx, [sectors] ; 17 or 63
  2344                                  	;dec	bl ; sectors - 1 ; 22/02/2019
  2345                                  	; 14/03/2021
  2346 000009A3 88C2                    	mov	dl, al ; sectors (spt)
  2347 000009A5 30F6                    	xor	dh, dh
  2348 000009A7 FECA                    	dec	dl
  2349                                  	; edx = sectors - 1
  2350                                  
  2351                                  	;mul	cl ; sectors * [end head]
  2352                                  	; 14/03/2021
  2353 000009A9 F6E4                    	mul	ah 
  2354                                  		; eax = sectors * [end head]
  2355                                  	
  2356                                  	;pop	dx ; *
  2357                                  	;; 22/02/2019
  2358                                  	;xor	cx, cx
  2359                                  	;add	ax, dx
  2360                                  	;pop	dx ; **
  2361                                  	;adc	dx, cx ; 0
  2362                                  	;add	ax, bx
  2363                                  	;adc	dx, cx ; 0
  2364                                  	;; dx:ax = ((([end cylinder]*heads)+[end head])*sectors)+sectors-1
  2365                                  	; 14/03/2021
  2366 000009AB 6601D0                  	add	eax, edx ; ([end head]*sectors)+sectors-1
  2367 000009AE 665A                    	pop	edx ; (end cylinder)*heads*sectors
  2368 000009B0 6601D0                  	add	eax, edx
  2369                                  	; eax = (([end cylinder]*heads)+[end head])*sectors)+sectors-1
  2370                                  
  2371                                  	; calculate aligned partition size in sectors
  2372                                  	;mov	cx, ax
  2373                                  	;mov	bx, dx
  2374                                  	;add	cx, 1
  2375                                  	;adc	bx, 0	
  2376                                  	;sub	cx, [si+ptStartSector]
  2377                                  	;sbb	bx, [si+ptStartSector+2]
  2378                                  	;	; bx:cx = partition size
  2379                                  	;;mov	[ppn_Sectors], cx
  2380                                  	;;mov	[ppn_Sectors+2], bx
  2381                                  	;;jmp	cpp_16
  2382                                  	; 14/03/2021
  2383 000009B3 6689C1                  	mov	ecx, eax
  2384 000009B6 6641                    	inc	ecx
  2385 000009B8 662B4C08                	sub	ecx, [si+ptStartSector]
  2386                                  		; ecx = partition size in sectors
  2387                                  
  2388 000009BC E99D00                  	jmp	cpp_15 ; 06/03/2019
  2389                                  cpp_11:
  2390                                  	; 20/02/2019
  2391                                  	;mov	cx, [ppn_Sectors]
  2392                                  	;mov	bx, [ppn_Sectors+2]
  2393                                  	; 14/03/2021
  2394 000009BF 668B0E[F069]            	mov	ecx, [ppn_Sectors] 
  2395                                  
  2396                                  	;;;mov	ax, [di+free_space.startsector]
  2397                                  	;;;mov	ax, [di+free_space.startsector+2]
  2398                                  	;;mov	ax, [si+ptStartSector]
  2399                                  	;;mov	dx, [si+ptStartSector+2]
  2400                                  	;mov	ax, [pp_StartSector]
  2401                                  	;mov	dx, [pp_StartSector+2]
  2402                                  	; 14/03/2021
  2403 000009C4 66A1[B869]              	mov	eax, [pp_StartSector]
  2404                                  cpp_12:	
  2405                                  	; 18/02/2019
  2406                                  
  2407                                  	; [wholedisk] = 0
  2408                                  
  2409                                  	; Fix partition size for MSDOS 3.3 (Retro DOS 3.0) compatibility.
  2410                                  	; (DOS partition size will be changed -down- to 65535 sectors,
  2411                                  	; if it is 65536 sectors.)
  2412                                  
  2413 000009C8 E8A200                  	call	fix_32mb_dos_psize
  2414                                  		; bx:cx = [ppn_sectors] = partition size
  2415                                  		; dx:ax = start sector's LBA
  2416                                  
  2417                                  	;add	ax, cx
  2418                                  	;adc	dx, bx
  2419                                  	; 14/03/2021
  2420 000009CB 6601C8                  	add	eax, ecx
  2421                                  	
  2422                                  	; Convert LBA sector address to CHS parameters
  2423                                  	;sub	ax, 1 ; locate on to end sector of the partition
  2424                                  	;sbb	dx, 0
  2425                                  	; 14/03/2021
  2426 000009CE 6648                    	dec	eax ; end sector of the partition
  2427                                  
  2428                                  	; 06/03/2019
  2429 000009D0 803E[8E6D]59            	cmp	byte [cylinder_boundary],'Y'
  2430                                  	;jne	short cpp_15
  2431 000009D5 7545                    	jne	short cpp_14
  2432                                  
  2433                                  	;mov	cx, ax
  2434                                  	;mov	al, [heads]
  2435                                  	;mul	byte [sectors]
  2436                                  	;mov	di, ax ; [heads]*[sectors]
  2437                                  	;xchg	ax, cx
  2438                                  	;	; cx = heads*spt
  2439                                  	;
  2440                                  	;call	div32
  2441                                  	;	; dx = 0
  2442                                  	;	; ax = end cylinder
  2443                                  	;	; bx = remainder
  2444                                  	; 14/03/2021
  2445 000009D7 6631D2                  	xor	edx, edx
  2446 000009DA 66F736[E469]            	div	dword [hs] ; heads*spt
  2447                                  		; eax = end cylinder
  2448                                  		; dx = remainder
  2449                                  
  2450                                  	;and	bx, bx
  2451                                  	;jz	short cpp_13
  2452                                  	;inc	ax
  2453                                  ;cpp_13:
  2454                                  	;cmp	ax, [cylinders]
  2455                                  	;jb	short cpp_14
  2456                                  	;dec	ax
  2457                                  ;cpp_14:
  2458                                  
  2459                                  	; 26/10/2020
  2460                                  	;cmp	ax, 1023
  2461                                  	;jna	short cpp_20
  2462                                  	; 14/03/2021
  2463 000009DF 663DFF030000            	cmp	eax, 1023
  2464 000009E5 760E                    	jna	short cpp_20
  2465                                  	
  2466 000009E7 C64405FE                	mov	byte [si+ptEndHead], 0FEh
  2467 000009EB C64406FF                	mov	byte [si+ptEndSector], 0FFh
  2468 000009EF C64407FF                	mov	byte [si+ptEndCylinder], 0FFh
  2469 000009F3 EB16                    	jmp	short cpp_21
  2470                                  cpp_20:
  2471                                  	;mov	bx, [heads]
  2472 000009F5 8A1E[A43C]              	mov	bl, [heads]
  2473 000009F9 FECB                    	dec	bl
  2474 000009FB 885C05                  	mov	[si+ptEndHead], bl
  2475                                  	;;mov	cx, [sectors]
  2476                                  	;mov	cl, [sectors]
  2477                                  	;mov	dl, ah
  2478                                  	;shl	dl, 6
  2479                                  	;or	dl, cl
  2480                                  	;mov	[si+ptEndSector], dl
  2481                                  	; 14/03/2021
  2482 000009FE C0E406                  	shl	ah, 6
  2483 00000A01 0A26[A23C]              	or	ah, [sectors]
  2484 00000A05 886406                  	mov	[si+ptEndSector], ah
  2485 00000A08 884407                  	mov	[si+ptEndCylinder], al	
  2486                                  	;mul	di ; [cylinders]*[heads]*[sectors]
  2487                                  	;;sub	di, cx ; ([heads] - 1) * [sectors]
  2488                                  	;add	ax, di
  2489                                  	;adc	dx, 0
  2490                                  	;;add	ax, cx
  2491                                  	;;adc	dx, 0
  2492                                  cpp_21:
  2493                                  	;inc	ax
  2494                                  	;mul	di  ; result = start LBA of next cylinder
  2495                                  	;; dx:ax = end sector LBA + 1 (as cyl. boundary aligned)
  2496                                  	; 14/03/2021
  2497 00000A0B 6640                    	inc	eax ; end sector address + 1
  2498 00000A0D 66F726[E469]            	mul	dword [hs] ; heads*spt
  2499                                  	
  2500                                  	;sub	ax, [pp_StartSector]
  2501                                  	;sbb	dx, [pp_StartSector+2]
  2502                                  	; 14/03/2021
  2503 00000A12 662B06[B869]            	sub	eax, [pp_StartSector]
  2504                                  
  2505                                  	;mov	cx, ax
  2506                                  	;mov	bx, dx
  2507                                  	;;jmp	short cpp_16
  2508                                  	; 14/03/2021
  2509 00000A17 6689C1                  	mov	ecx, eax ; partition size
  2510                                  
  2511 00000A1A EB40                    	jmp	short cpp_15
  2512                                  ;cpp_15:
  2513                                  cpp_14:
  2514                                  	; 14/03/2021
  2515                                  	; eax =  end sector
  2516                                  
  2517                                  	;mov	cx, [sectors]
  2518                                  	;call	div32
  2519                                  	;; BX = Sector number - 1
  2520                                  	;inc	bl ; sector number (1 based)
  2521                                  	;mov	[si+ptEndSector], bl
  2522                                  	;; DX_AX = cylinders * heads + head
  2523                                  	; 14/03/2021
  2524                                  	;xor	edx, edx
  2525 00000A1C 31D2                    	xor	dx, dx
  2526 00000A1E 660FB61E[A23C]          	movzx	ebx, byte [sectors]
  2527 00000A24 66F7F3                  	div	ebx
  2528                                  		 ; dl = sector number - 1
  2529 00000A27 FEC2                    	inc	dl ; sector number
  2530 00000A29 885406                  	mov	[si+ptEndSector], dl
  2531                                  
  2532                                  	;mov	cx, [heads]
  2533                                  	;call	div32
  2534                                  	;; BX = Head number
  2535                                  	;mov	[si+ptEndHead], bl
  2536                                  	;; AX = Cylinder number
  2537                                  	;;and	ax, 1023
  2538                                  	; 14/03/2021
  2539                                  	;xor	dx, dx
  2540 00000A2C 30D2                    	xor	dl, dl
  2541 00000A2E 8A1E[A43C]              	mov	bl, [heads]
  2542 00000A32 66F7F3                  	div	ebx
  2543                                  		; eax = cylinder number
  2544                                  		; dl = head number
  2545 00000A35 885405                  	mov	[si+ptEndHead], dl
  2546                                  
  2547                                  	; 26/10/2020
  2548                                  	;cmp	ax, 1023
  2549                                  	;jna	short cpp_22
  2550                                  	; 14/03/2021
  2551 00000A38 663DFF030000            	cmp	eax, 1023
  2552 00000A3E 760E                    	jna	short cpp_22
  2553                                  	
  2554 00000A40 C64405FE                	mov	byte [si+ptEndHead], 0FEh
  2555 00000A44 C64406FF                	mov	byte [si+ptEndSector], 0FFh
  2556 00000A48 C64407FF                	mov	byte [si+ptEndCylinder], 0FFh
  2557 00000A4C EB09                    	jmp	short cpp_23
  2558                                  cpp_22:
  2559 00000A4E 884407                  	mov	[si+ptEndCylinder], al
  2560                                  	; 18/02/2019
  2561 00000A51 C0E406                  	shl	ah, 6
  2562 00000A54 086406                  	or	[si+ptEndSector], ah
  2563                                  cpp_23:
  2564                                  	;mov	cx, [ppn_Sectors]
  2565                                  	;mov	bx, [ppn_Sectors+2]
  2566                                  	; 14/03/2021
  2567 00000A57 668B0E[F069]            	mov	ecx, [ppn_Sectors]
  2568                                  ;cpp_16:
  2569                                  cpp_15:
  2570                                  	;mov	[si+ptSectors], cx
  2571                                  	;mov	[si+ptSectors+2], bx
  2572                                  	; 14/03/2021
  2573 00000A5C 66894C0C                	mov	[si+ptSectors], ecx
  2574                                  
  2575                                  	; set partition ID after checking DOS FAT limits
  2576 00000A60 E8E500                  	call	set_partition_id
  2577                                  	; al = partition ID
  2578                                  
  2579                                  	; 14/03/2021
  2580                                  	; clear -specially- high word of ecx
  2581 00000A63 6631C9                  	xor	ecx, ecx ; (this may not be needed!?)
  2582                                  
  2583 00000A66 A2[C169]                	mov	[pp_type], al
  2584                                  
  2585 00000A69 884404                  	mov	[si+ptFileSystemID], al
  2586                                  
  2587 00000A6C C3                      	retn
  2588                                  
  2589                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2590                                  ; decrease DOS partition size when it is (exact) 65536 sectors
  2591                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2592                                  ; 07/11/2020 (fdisk4)
  2593                                  ; 18/02/2019
  2594                                  
  2595                                  fix_32mb_dos_psize:	; call this if [wholedisk] = 0
  2596                                  
  2597                                  ; Purpose: 
  2598                                  ;	If a DOS partition's size is 65536 sectors
  2599                                  ;	MSDOS 3.3 can not use it. (FAT 16 partition ID = 06h)
  2600                                  ;	Decreasing partition size to 65535 sectors will ensure
  2601                                  ;	MSDOS 3.3 compatibility (FAT 16 partition ID will be 04h).
  2602                                  
  2603                                  	; INPUT:
  2604                                  	;    BX:CX = partition size in sectors
  2605                                  	;    [pp_type] = partition type dos, non-dos, user input
  2606                                  	;
  2607                                  	; OUTPUT:
  2608                                  	;    Partition size will be changed to 65535 sectors, if
  2609                                  	;    	- partition size is 65536 sectors and
  2610                                  	; 	- [pp_type] is 1 (DOS)
  2611                                  	;
  2612                                  	;    [ppn_Sectors] = 65535 (if it will be changed)
  2613                                  	;
  2614                                  	; (Modified registers: cx, bx) 
  2615                                  
  2616                                  	;mov	cx, [ppn_Sectors]
  2617                                  	;mov	bx, [ppn_Sectors+2]
  2618                                  
  2619 00000A6D 803E[C169]01            	cmp	byte [pp_type], 1 ;  DOS partition
  2620 00000A72 7514                    	jne	short psfx_0  ; non-dos partition or user input
  2621                                  			      ; nothing to do !
  2622                                  	; 07/11/2020
  2623                                  	;or	cx, cx
  2624 00000A74 7512                    	jnz	short psfx_0 ; <> 65536 sectors
  2625                                  	;cmp	bx, 1
  2626 00000A76 7510                    	jne	short psfx_0
  2627                                  	;dec	bx
  2628                                  	;;mov	[wholedisk], bx ; 0
  2629                                  	;dec	cx  ; bx:cx = 65535
  2630                                  	;mov	[ppn_Sectors], cx
  2631                                  	;mov	[ppn_Sectors+2], bx
  2632                                  
  2633                                  	; 07/11/2020 (fdisk4)
  2634 00000A78 6681F900000100          	cmp	ecx, 65536
  2635 00000A7F 7507                    	jne	short psfx_0
  2636 00000A81 6649                    	dec	ecx  ; 65535
  2637 00000A83 66890E[F069]            	mov	[ppn_Sectors], ecx
  2638                                  psfx_0:
  2639 00000A88 C3                      	retn
  2640                                  
  2641                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2642                                  ; create extended dos partition
  2643                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2644                                  ; 24/10/2020 (fdisk3.s)
  2645                                  
  2646                                  ; 16/02/2019 (hdimage.s) 
  2647                                  ;	(This procedure must be called after 'find_part_free_space')
  2648                                  
  2649                                  	; 15/03/2021 (fdisk4.s)
  2650                                  create_extended_partition:  
  2651                                  	; 15/02/2019
  2652                                  
  2653                                  	; INPUT:
  2654                                  	;	none 
  2655                                  	;  (CHS parameters and free space calculation result will be used.)
  2656                                  	;
  2657                                  	; OUTPUT:
  2658                                  	;	Partition table in MBR buffer will be updated.
  2659                                  	;
  2660                                  	; (Modified registers: ax, bx, cx, dx, si, di)
  2661                                  
  2662                                  	; Create extended dos partition, make partition table entry
  2663                                  	; (Extended partition will be created on cylinder bounds.)
  2664                                  
  2665                                  	; 16/02/2019
  2666 00000A89 E8C91A                  	call	get_first_free_pte
  2667                                  		 ; CX = First free PTE number, 0 to 3 
  2668                                  		 ;    (CX = 3 if there is not a free PTE, and CF = 1)
  2669                                  		 ;    ((But CF = 1 is not possible here because pcount < 4))
  2670                                   	 	 ; SI = PTE addres/offset in MBR buffer
  2671                                  
  2672                                  	;mov	si, MasterBootBuff+pTableOffset
  2673                                  	;shl	cl, 4 ; * 16
  2674                                  	;add	si, cx
  2675                                  	
  2676                                  	;mov	bx, [c_fspc_offset]
  2677                                  	; 15/03/2021
  2678 00000A8C 8B3E[8C6D]              	mov	di, [c_fspc_offset]
  2679                                  
  2680                                  	;mov	ax, [bx+free_space.start]
  2681                                  	; 15/03/2021
  2682 00000A90 668B85[226D]            	mov	eax, [di+free_space.start]
  2683                                  
  2684                                  	; 24/10/2020
  2685                                  	;mov	di, ax ; 15/03/2021
  2686                                  
  2687                                  	;mov	cx, 1
  2688 00000A95 B101                    	mov	cl, 1 ; head (ch) = 0, sector (cl) = 1
  2689                                  
  2690                                  	; 15/03/2021
  2691 00000A97 6689C3                  	mov	ebx, eax
  2692                                  
  2693                                  	;cmp	ax, 1023
  2694                                  	;jna	short cep_4
  2695                                  	; 15/03/2021
  2696 00000A9A 663DFF030000            	cmp	eax, 1023
  2697 00000AA0 7609                    	jna	short cep_4
  2698                                  
  2699                                  	; partition start  > CHS limit
  2700                                  	;mov	ax, 1023
  2701                                  	; 15/03/2021
  2702 00000AA2 66B8FF030000            	mov	eax, 1023
  2703                                  
  2704                                  	;mov	ch, 254
  2705                                  	;mov	cl, 63
  2706 00000AA8 B93FFE                  	mov	cx, 0FE3Fh
  2707                                  cep_4:	
  2708                                  	;mov	byte [si+ptBootable], 0 ; not bootable/active partition
  2709                                  	;mov	[si], ch ; 0 ; not bootable/active partition
  2710                                  	; 26/10/2020
  2711 00000AAB C60400                  	mov	byte [si], 0
  2712 00000AAE 886C01                  	mov	[si+ptBeginHead], ch
  2713 00000AB1 C0E406                  	shl	ah, 6
  2714 00000AB4 08E1                    	or	cl, ah
  2715 00000AB6 884C02                  	mov	[si+ptBeginSector], cl ; Sector 1
  2716 00000AB9 884403                  	mov	[si+ptBeginCylinder], al
  2717                                  
  2718                                  	;mov	al, [heads]
  2719                                  	;mul	byte [sectors]
  2720                                  	;	; ax = heads*sectors
  2721                                  	;mul	di  ; AX * cylinder count before start cylinder
  2722                                  	;	; DX:AX = LBA of cylinder DI, head 0, sector 1 
  2723                                  	; 15/03/2021
  2724                                  	; eax = start cylinder
  2725 00000ABC 6689D8                  	mov	eax, ebx
  2726 00000ABF 66F726[E469]            	mul	dword [hs] ; heads * sectors
  2727                                  		; eax = start sector, edx = 0
  2728                                  	
  2729                                  	;mov	[si+ptStartSector], ax
  2730                                  	;mov	[si+ptStartSector+2], dx
  2731                                  	; 15/03/2021
  2732 00000AC4 66894408                	mov	[si+ptStartSector], eax
  2733                                  
  2734                                  	; This is not needed for extended partition.
  2735                                  	; 16/02/2019
  2736                                  	;mov	[pp_StartSector], ax
  2737                                  	;mov	[pp_StartSector+2], dx
  2738                                  	; 15/03/2021
  2739                                  	;mov	[pp_StartSector], eax
  2740                                  
  2741                                  	; 16/02/2019
  2742 00000AC8 803E[C069]00            	cmp	byte [wholedisk], 0
  2743 00000ACD 7719                    	ja	short cep_2 ; all of free space will be used
  2744                                  			    ; ([bx+free_space.end] will be end cyl)
  2745                                  
  2746                                  	; calculate cylinder count (from partition size input)
  2747                                  	;mov	al, [heads]
  2748                                  	;mul	byte [sectors]
  2749                                  	;mov	cx, ax
  2750                                  	;mov	ax, [ppn_Sectors]
  2751                                  	;mov	dx, [ppn_Sectors+2]
  2752                                  	;call	div32
  2753                                  	;	; ax = cylinders
  2754                                  	;	; bx = remainder
  2755                                  	;and	bx, bx
  2756                                  	;jz	short cep_1
  2757                                  	;inc	ax  ; round up
  2758                                  	; 15/03/2021
  2759                                  	; edx = 0
  2760 00000ACF 66A1[F069]              	mov	eax, [ppn_Sectors]
  2761 00000AD3 66F736[E469]            	div	dword [hs] ; heads * spt
  2762                                  		; eax = cylinders, dx = remainder
  2763 00000AD8 21D2                    	and	dx, dx
  2764 00000ADA 7402                    	jz	short cep_1
  2765 00000ADC 6640                    	inc	eax ; round up
  2766                                  cep_1:
  2767                                  	; 15/03/2021
  2768                                  	; EBX = extended partition's start cylinder
  2769                                   	; 16/02/2019
  2770                                  	; DI  = extended partition's start cylinder
  2771                                  	;mov	dx, ax ; cylinder count
  2772                                  	;add	dx, di ; result is end cyl + 1
  2773                                  	;dec	dx ; decrease number for current end cylinder
  2774                                  	;mov	bx, [c_fspc_offset]
  2775                                  	;cmp	dx, [bx+free_space.end]
  2776                                  	;jna	short cep_3
  2777                                  	; 24/10/2020
  2778                                  	;;dec	ax ; decrease cylinder count down to the limit
  2779                                  	;dec	dx ; decrease end cylinder down to the limit
  2780                                  	; 15/03/2021	
  2781 00000ADE 6689C2                  	mov	edx, eax ; cylinder count
  2782 00000AE1 6601DA                  	add	edx, ebx ; result is end cyl + 1
  2783 00000AE4 664A                    	dec	edx ; end cylinder
  2784                                  	;mov	di, [c_fspc_offset]
  2785                                  
  2786 00000AE6 EB05                    	jmp	short cep_3
  2787                                  cep_2:
  2788                                  	; 15/03/2021
  2789                                  	; DI = [c_fspc_offset]
  2790                                  
  2791                                  	;mov	dx, [bx+free_space.end]
  2792                                  	;;mov	ax, [bx+free_space.space]
  2793                                  	; 15/03/2021
  2794 00000AE8 668B97[266D]            	mov	edx, [bx+free_space.end]
  2795                                  cep_3:
  2796                                  	; 15/03/2021
  2797 00000AED 6631DB                  	xor	ebx, ebx
  2798                                  
  2799                                  	; 24/10/2020
  2800                                  	;mov	ax, dx ; end cylinder
  2801                                  	;mov	bl, 05h	; Extended Partition ID (CHS)
  2802                                  	;cmp	ax, 1023
  2803                                  	;jna	short cep_5
  2804                                  	; 15/03/2021
  2805 00000AF0 6689D0                  	mov	eax, edx ; end cylinder
  2806 00000AF3 B305                    	mov	bl, 05h ; Extended Partition ID (CHS)
  2807 00000AF5 663DFF030000            	cmp	eax, 1023
  2808 00000AFB 760D                    	jna	short cep_5
  2809                                  
  2810                                  	; partition end > CHS limit
  2811                                  	;mov	ax, 1023
  2812                                  	; 15/03/2021
  2813 00000AFD 66B8FF030000            	mov	eax, 1023
  2814                                  
  2815                                  	;mov	ch, 254
  2816                                  	;mov	cl, 63
  2817 00000B03 B93FFE                  	mov	cx, 0FE3Fh
  2818 00000B06 B30F                    	mov	bl, 0Fh	; Extended Partition ID (LBA)
  2819 00000B08 EB0A                    	jmp	short cep_6
  2820                                  cep_5:
  2821 00000B0A 8A2E[A43C]              	mov	ch, [heads]
  2822 00000B0E FECD                    	dec	ch 
  2823 00000B10 8A0E[A23C]              	mov	cl, [sectors]
  2824                                  cep_6:
  2825 00000B14 886C05                  	mov	[si+ptEndHead], ch
  2826                                  	; 24/10/2020
  2827                                  	; ax = (chs limit compatible) end cylinder (<= 1023)
  2828                                  	; 23/02/2019
  2829                                  	;mov	bl, dh
  2830                                  	;shl	bl, 6
  2831                                  	;or	bl, cl
  2832 00000B17 C0E406                  	shl	ah, 6
  2833                                  	;or	cl, ah
  2834                                  	;;mov	[si+ptEndSector], bl
  2835                                  	;mov	[si+ptEndSector], cl
  2836                                  	; 15/03/2021
  2837 00000B1A 08CC                    	or	ah, cl
  2838 00000B1C 886406                  	mov	[si+ptEndSector], ah
  2839                                  	;mov	[si+ptEndCylinder], dl
  2840 00000B1F 884407                  	mov	[si+ptEndCylinder], al
  2841                                  	; dx = (lba compatible) end cylinder (up to 65535)
  2842                                  
  2843                                  	;mov	al, [heads]
  2844                                  	; 26/10/2020
  2845                                  	;;;mul	cl
  2846                                  	;;mul	byte [sectors]
  2847                                  	;mov	ch, [heads]
  2848                                  	;mov	al, [sectors]
  2849                                  	;mul	ch	
  2850                                  	;; ax = heads*sectors
  2851                                  	;mul	dx ; AX * cylinder count before end cylinder
  2852                                  	;	; DX:AX = LBA of cylinder DX, head 0, sector 1
  2853                                  	; 15/03/2021
  2854                                  	; edx = end cylinder
  2855 00000B22 66A1[E469]              	mov	eax, [hs] ; [heads] * [sectors]
  2856 00000B26 66F7E2                  	mul	edx
  2857                                  		; eax = LBA of end cylinder, head 0, sector 1
  2858                                  		; edx = 0
  2859                                  	;push	dx
  2860                                  	;push	ax
  2861                                  	; 15/03/2021
  2862 00000B29 6650                    	push	eax ; (end cylinder)*heads*sectors
  2863                                  	
  2864 00000B2B 88E8                    	mov	al, ch
  2865 00000B2D FEC8                    	dec	al ; 26/10/2020 ; [heads] - 1
  2866                                  	;mov	cx, [sectors]  ; 63 or 17
  2867                                  	; cl = sectors ; 15/03/2021
  2868 00000B2F F6E1                    	mul	cl
  2869                                  		; ax = (heads-1)*sectors
  2870                                  	; 15/03/2021
  2871 00000B31 89C2                    	mov	dx, ax ; (heads-1)*sectors
  2872                                  	
  2873                                  	;pop	dx
  2874                                  	;add	ax, dx
  2875                                  	;pop	dx
  2876                                  	;adc	dx, 0
  2877                                  	;	; dx:ax = ((end cylinder)*heads)+(heads-1)*sectors
  2878                                  	;add	ax, cx
  2879                                  	;adc	dx, 0
  2880                                  	; dx:ax = (((end cylinder)*heads)+(heads-1))*sectors) + sectors
  2881                                  	; dx:ax = LBA of the partition's end sector + 1
  2882                                  
  2883                                  	; 15/03/2021
  2884 00000B33 30ED                    	xor	ch, ch
  2885 00000B35 01CA                    	add	dx, cx ; ((heads-1)*sectors)+sectors
  2886 00000B37 6658                    	pop	eax ; ((end cylinder)*heads)*sectors
  2887 00000B39 6601D0                  	add	eax, edx
  2888                                  	; eax = (((end cylinder)*heads)+(heads-1))*sectors)+sectors
  2889                                  
  2890                                  	;sub	ax, [si+ptStartSector]
  2891                                  	;sbb	dx, [si+ptStartSector+2]
  2892                                  	; 15/03/2021
  2893 00000B3C 662B4408                	sub	eax, [si+ptStartSector]
  2894                                  	
  2895                                  	;mov	[si+ptSectors], ax
  2896                                  	;mov	[si+ptSectors+2], dx
  2897                                  	; 15/03/2021
  2898 00000B40 6689440C                	mov	[si+ptSectors], eax
  2899                                  
  2900                                  	;mov	[pp_type], al
  2901                                  
  2902                                  	;mov	byte [si+ptFileSystemID], 5
  2903                                  	; 24/10/2020
  2904 00000B44 885C04                  	mov	 [si+ptFileSystemID], bl ; 05h or 0Fh
  2905                                  	
  2906 00000B47 C3                      	retn
  2907                                  
  2908                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2909                                  ; set DOS (and non-dos) partition ID according to partition size
  2910                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2911                                  ; 23/10/2020
  2912                                  
  2913                                  	; 15/03/2021
  2914                                  set_partition_id: 
  2915                                  	; 07/11/2020 (fdisk4.s, 32 bit registers)
  2916                                  	; 23/10/2020 (fdisk3.s)
  2917                                  	; input:
  2918                                  	;   si = partition table offset
  2919                                  	;   bx:cx = partition size
  2920                                  
  2921                                  	; 18/02/2019 (hdimage.s)
  2922                                  	;mov	cx, [ppn_Sectors]
  2923                                  	;mov	bx, [ppn_Sectors+2]
  2924                                  
  2925 00000B48 A0[C169]                	mov	al, [pp_type]
  2926                                  
  2927                                  	;cmp	byte [pp_type], 1
  2928 00000B4B 3C01                    	cmp	al, 1 ; primary DOS (FAT12, FAT16, FAT32)
  2929 00000B4D 7525                    	jne	short spid_2 ; singlix, runix or user type
  2930                                  
  2931                                  	;mov	al, 1	; FAT12
  2932                                  
  2933                                  	;or	bx, bx
  2934                                  	;jnz	short spid_1
  2935                                  	; 15/03/2021
  2936 00000B4F 6681F900000100          	cmp	ecx, 65536 ; >= 32 MB
  2937 00000B56 730D                    	jnb	short spid_1	
  2938                                  
  2939                                  	;cmp	cx, 32680
  2940                                  	;;jna	short spid_8	; FAT12 file system
  2941                                  	;jna	short spid_19 ; 23/10/2020
  2942                                  	; 07/11/2020
  2943 00000B58 6681F9A87F0000          	cmp	ecx, 32680
  2944 00000B5F 7620                    	jna	short spid_19
  2945                                  
  2946 00000B61 B004                    	mov	al, 4	; FAT16 (< 32MB)
  2947                                  
  2948 00000B63 EB46                    	jmp	short spid_8	; FAT16 (CHS) file system
  2949                                  
  2950                                  spid_1:
  2951 00000B65 B00B                    	mov	al, 0Bh ; FAT32 (CHS)
  2952                                  
  2953                                  	;cmp	bx, 10h
  2954                                  	; 07/11/2020
  2955 00000B67 6681F900001000          	cmp	ecx, 100000h ; 512 MB 
  2956 00000B6E 733B                    	jnb	short spid_8	; FAT32 (CHS) file system
  2957                                  
  2958 00000B70 B006                    	mov	al, 6	; FAT16 (>= 32MB)
  2959                                  
  2960 00000B72 EB37                    	jmp	short spid_8	; FAT16 big (CHS) file system
  2961                                  
  2962                                  spid_2:
  2963                                  	;cmp	byte [pp_type], 2 ; Singlix FS
  2964 00000B74 3C02                    	cmp	al, 2
  2965 00000B76 7503                    	jne	short spid_3
  2966 00000B78 B0A1                    	mov	al, 0A1h
  2967                                  	;jmp	short spid_8
  2968 00000B7A C3                      	retn	; 23/10/2020
  2969                                  spid_3:
  2970                                  	;cmp	byte [pp_type], 3 ; Retro Unix FS
  2971 00000B7B 3C03                    	cmp	al, 3
  2972 00000B7D 7503                    	jne	short spid_4
  2973 00000B7F B071                    	mov	al, 71h	
  2974                                  	;jmp	short spid_8
  2975                                  spid_19:
  2976 00000B81 C3                      	retn
  2977                                  
  2978                                  spid_4:
  2979                                  	; another partition type (user input)
  2980                                  	
  2981                                  	; [pp_type] = 4
  2982                                  
  2983 00000B82 A0[C269]                	mov	al, [pp_type_user]
  2984                                  
  2985                                  	; Check FAT12 fs size validation
  2986                                  
  2987 00000B85 3C01                    	cmp	al, 1 ; FAT12
  2988 00000B87 7737                    	ja	short spid_9
  2989                                  
  2990                                  	;and	bx, bx
  2991                                  	;jnz	short spid_6
  2992                                  
  2993                                  	;cmp	cx, 32680
  2994                                  	;;jna	short spid_8
  2995                                  	;jna	short spid_19 ; 23/10/2020
  2996                                  
  2997                                  	; 07/11/2020
  2998 00000B89 6681F900000100          	cmp	ecx, 65536
  2999 00000B90 730A                    	jnb	short spid_6
  3000 00000B92 81F9A87F                	cmp	cx, 32680
  3001 00000B96 76E9                    	jna	short spid_19
  3002                                  spid_5:
  3003 00000B98 B004                    	mov	al, 4 ; FAT16 (<= 32MB)
  3004 00000B9A EB0F                    	jmp	short spid_8
  3005                                  spid_6:
  3006                                  	;;cmp	bx, 10h	; 512MB (16*32MB)
  3007                                  	;cmp	bx, 40h ; 2GB (64*32MB)
  3008                                  	;jnb	short spid_7
  3009                                  	; 15/03/2021
  3010 00000B9C 6681F900004000          	cmp	ecx, 400000h ; 2GB (64K*64 sectors)
  3011 00000BA3 7304                    	jnb	short spid_7
  3012                                  
  3013 00000BA5 B006                    	mov	al, 6
  3014 00000BA7 EB02                    	jmp	short spid_8
  3015                                  spid_7:
  3016 00000BA9 B00B                    	mov	al, 0Bh ; FAT32 (CHS) partition
  3017                                  spid_8:
  3018                                  	; 23/10/2020
  3019                                  	; check the partition's end sector against CHS limit and
  3020                                  	; convert partition ID if the partition overs CHS limit
  3021                                  	;cmp	al, 1 ; FAT12 fs
  3022                                  	;je	short spid_19 ; nothing to do (for FAT12 fs)
  3023                                  	;add	cx, [si+ptStartSector]
  3024                                  	;adc	bx, [si+ptStartSector+2]
  3025                                  	; 15/03/2021
  3026 00000BAB 66034C08                	add	ecx, [si+ptStartSector]
  3027                                  	
  3028                                  	;cmp	bx, [chs_limit+2]
  3029                                  	;jb	short spid_19 ; partition's end sector is in CHS limit
  3030                                  	;ja	short spid_17 ; out of CHS limit
  3031                                  	;cmp	cx, [chs_limit]
  3032                                  	;jna	short spid_19 ; partition's end sector is in CHS limit
  3033                                  	; 07/11/2020
  3034 00000BAF 663B0E[2A65]            	cmp	ecx, [chs_limit]
  3035 00000BB4 76CB                    	jna	short spid_19 ; partition's end sector is in CHS limit
  3036                                  spid_17:
  3037                                  	; out of CHS limit, partition ID conversion is needed
  3038 00000BB6 3C0B                    	cmp	al, 0Bh	; FAT32 CHS
  3039 00000BB8 7203                    	jb	short spid_18
  3040 00000BBA B00C                    	mov	al, 0Ch	; FAT 32 LBA
  3041 00000BBC C3                      	retn
  3042                                  spid_18:
  3043 00000BBD B00E                    	mov	al, 0Eh ; FAT16 LBA
  3044 00000BBF C3                      	retn
  3045                                  spid_9:
  3046 00000BC0 3C04                    	cmp	al, 4 ; FAT16 (< 32 MB)
  3047 00000BC2 7511                    	jne	short spid_10
  3048                                  
  3049                                  	;or	bx, bx
  3050                                  	;jnz	short spid_6
  3051                                  	; 15/03/2021
  3052 00000BC4 6681F900000100          	cmp	ecx, 65536
  3053 00000BCB 73CF                    	jnb	short spid_6
  3054 00000BCD 81F93610                	cmp	cx, 4150 ; 4085 + 32 + 32 + 1
  3055 00000BD1 7220                    	jb	short spid_12
  3056                                  	
  3057                                  	;retn	; FAT16 (< 32 MB) partition
  3058 00000BD3 EBD6                    	jmp	short spid_8  ; 23/10/2020
  3059                                  
  3060                                  spid_10:
  3061 00000BD5 3C06                    	cmp	al, 6 ; FAT 16 big partition
  3062 00000BD7 751D                    	jne	short spid_13 ; Extended partition or another type
  3063                                  	
  3064                                  	;and	bx, bx
  3065                                  	;jz	short spid_11
  3066                                  	; 07/11/2020
  3067 00000BD9 6681F900000100          	cmp	ecx, 65536
  3068 00000BE0 720B                    	jb	short spid_11
  3069                                  
  3070                                  	;;cmp	bx, 10h	; 512MB (16*32MB)
  3071                                  	;cmp	bx, 40h ; 2GB (64*32MB)
  3072                                  	;jnb	short spid_7
  3073                                  	; 15/03/2021
  3074 00000BE2 6681F900004000          	cmp	ecx, 400000h ; 2GB (64K*64 sectors)
  3075 00000BE9 73BE                    	jnb	short spid_7
  3076                                  
  3077                                  	;retn
  3078 00000BEB EBBE                    	jmp	short spid_8 ; 23/10/2020
  3079                                  
  3080                                  spid_11:
  3081                                  	;cmp	ax, 4150 ; 4085 + 32 + 32 + 1
  3082 00000BED 81F93610                	cmp	cx, 4150 ; 14/09/2020 (BugFix)
  3083 00000BF1 73A5                    	jnb	short spid_5
  3084                                  spid_12:
  3085 00000BF3 B001                    	mov	al, 1 ;  FAT12 partition
  3086                                  spid_16:
  3087 00000BF5 C3                      	retn
  3088                                  spid_13:
  3089                                  	; 14/09/2020
  3090 00000BF6 3C0B                    	cmp	al, 0Bh ; FAT 32 (CHS) partition
  3091 00000BF8 7432                    	je	short spid_15 ; FAT 32 CHS
  3092 00000BFA 3C0C                    	cmp	al, 0Ch	 
  3093 00000BFC 7515                    	jne	short spid_14
  3094                                  	; FAT 32 LBA
  3095                                  	;and	bx, bx	; < 33 MB
  3096                                  	;jz	short spid_11 ; force to FAT 16 CHS or FAT 12
  3097                                  	;cmp	bx, 10h ; 512 MB
  3098                                  	;;jnb	short spid_8  ; OK, FAT 32 LBA has been confirmed
  3099                                  	;jnb	short spid_16 ; 23/10/2020
  3100                                  	; 15/03/2021
  3101 00000BFE 6681F900000100          	cmp	ecx, 65536
  3102 00000C05 72E6                    	jb	short  spid_11 ; force to FAT 16 CHS or FAT 12
  3103 00000C07 6681F900001000          	cmp	ecx, 100000h ; 512MB
  3104 00000C0E 73E5                    	jnb	short spid_16  ; OK
  3105                                  	; < 512MB
  3106 00000C10 B00E                    	mov	al, 0Eh ; force to FAT 16 LBA
  3107 00000C12 C3                      	retn
  3108                                  spid_14:
  3109                                  	; 14/09/2020
  3110 00000C13 3C0E                    	cmp	al, 0Eh
  3111                                  	;jne	short spid_8 ; non-dos or extended partition
  3112 00000C15 75DE                    	jne	short spid_16 ; 23/10/2020
  3113                                  	; FAT 16 LBA
  3114                                  	;or	bx, bx
  3115                                  	;jz	short spid_11
  3116                                  	; 15/03/2021
  3117 00000C17 6681F900000100          	cmp	ecx, 65536
  3118 00000C1E 72CD                    	jb	short spid_11
  3119                                  	; 23/10/2020
  3120                                  	;cmp	bx, 20h ; 1 GB
  3121                                  	;jb	short spid_16
  3122                                  	; 15/03/2021
  3123                                  	;((this 1GB limit may be 2GB))
  3124 00000C20 6681F900002000          	cmp	ecx, 200000h ; 1GB
  3125 00000C27 72CC                    	jb	short spid_16
  3126 00000C29 B00C                    	mov	al, 0Ch	; FAT 32 LBA
  3127 00000C2B C3                      	retn
  3128                                  spid_15:
  3129                                  	; Minimum size of FAT 32 FS = 65525 + 512 + 512 + 32
  3130                                   	; >= 66581 sectors (or >= 65525 data clusters)
  3131                                  	;cmp	bx, 1
  3132                                  	;jb	short spid_11  ; invalid! (< 32 MB)
  3133                                  	;ja	short spid_8
  3134                                  	;cmp	cx, 1045
  3135                                  	;;jb	short spid_16  ; invalid! (< 33 MB)
  3136                                  	;;retn
  3137                                  	;;jmp	short spid_8 ; 23/10/2020
  3138                                  	;jnb	short spid_8
  3139                                  	; 15/03/2021
  3140 00000C2C 6681F915040100          	cmp	ecx, 66581
  3141 00000C33 0F8374FF                	jnb	spid_8   ; OK (>= 33MB)
  3142 00000C37 6681F900000100          	cmp	ecx, 65536
  3143 00000C3E 72AD                    	jb	short spid_11  ; invalid! (< 32MB)
  3144                                  ;spid_16:
  3145 00000C40 B006                    	mov	al, 6
  3146                                  	;retn
  3147 00000C42 E966FF                  	jmp	spid_8 ; 23/10/2020
  3148                                  
  3149                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3150                                  ; 32 bit division by using 16 bit registers
  3151                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3152                                  
  3153                                  	; 06/11/2020 (fdisk4)
  3154                                  	; 32 bit division (80386 div instruction for 32 bit regs)
  3155                                  	; will be used instead of div32 procedure for 16 bit regs
  3156                                  ;div32:
  3157                                  	;; DX_AX/CX
  3158                                  	;; Result: DX_AX, BX (remainder)
  3159                                  	;mov	bx, ax
  3160                                  	;;or	dx, ax ; * DX_AX = 0 ?
  3161                                  	;;jz	short div32_retn ; yes, do not divide!
  3162                                  	;mov	ax, dx
  3163                                          ;xor	dx, dx
  3164                                          ;div	cx	; at first, divide DX
  3165                                  	;		; remainder is in DX 
  3166                                  	;xchg	ax, bx	; now quotient is in BX
  3167                                    	;		; and initial AX value is in AX
  3168                                  	;div	cx	; now, DX_AX has been divided and
  3169                                  	;		; AX has quotient
  3170                                  	;		; DX has remainder
  3171                                  	;xchg	dx, bx	; finally, BX has remainder
  3172                                  ;;div32_retn:
  3173                                          ;retn
  3174                                  
  3175                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3176                                  ; 32 bit multiplication by using 16 bit registers
  3177                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3178                                  
  3179                                  	; 06/11/2020 (fdisk4)
  3180                                  	; 32 bit multiplication (80386 mul instruction)
  3181                                  	; will be used instead of mul32 procedure for 16 bit regs
  3182                                  ;mul32:
  3183                                  	;; DX_AX*CX
  3184                                  	;; Result: BX_DX_AX 
  3185                                  	;push	cx
  3186                                  	;mov	bx, dx
  3187                                  	;mul	cx
  3188                                   	;xchg	ax, bx
  3189                                  	;push	dx
  3190                                  	;mul	cx 
  3191                                  	;pop	cx 
  3192                                  	;add	ax, cx 
  3193                                  	;adc	dx, 0
  3194                                  	;xchg	bx, ax
  3195                                  	;xchg	dx, bx
  3196                                  	;pop	cx
  3197                                  	;retn
  3198                                  
  3199                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3200                                  ; creeate new partition input menu
  3201                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3202                                  
  3203                                  B_01:
  3204                                  	; 06/03/2019
  3205 00000C45 C606[CE69]4D            	mov	byte [pSize_unit], 'M' ; default (for 'whole' disk/space)
  3206                                  	; 15/02/2019
  3207 00000C4A E82DFB                  	call	create_partition_input
  3208                                  B_02:		
  3209 00000C4D 21C0                    	and	ax, ax
  3210                                  	;jz	_crlf_exit ; 0 = none or not a valid input
  3211 00000C4F 0F8480F7                	jz	A_42 ; 25/02/2019
  3212                                  
  3213                                  	;or	ah, ah
  3214                                  	;jz	short B_03
  3215                                  
  3216                                  	; 23/02/2019
  3217 00000C53 80FC04                  	cmp	ah, 4  ; user's partition type input ?
  3218 00000C56 7505                    	jne	short B_03 ; no
  3219                                  
  3220                                  	; 29/10/2020
  3221                                  	; (ah = 0)
  3222                                  	;or	al, al
  3223                                  	;jz	A_42  ; invalid partition type input
  3224                                  	;	      ; or ESC key has been pressed
  3225                                  
  3226                                  	; user type input
  3227 00000C58 A2[C269]                	mov	[pp_type_user], al
  3228 00000C5B 88E0                    	mov	al, ah ; mov al, 4
  3229                                  B_03:
  3230 00000C5D A2[C169]                	mov	[pp_type], al
  3231                                  
  3232                                  	; clear screen
  3233 00000C60 B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
  3234 00000C63 CD10                    	int	10h
  3235                                  
  3236 00000C65 A0[C169]                	mov	al, [pp_type]
  3237 00000C68 3C01                    	cmp	al, 1
  3238 00000C6A 7705                    	ja	short B_04
  3239                                  
  3240 00000C6C BE[F644]                	mov	si,  msg_create_dos_partition_h ; header
  3241 00000C6F EB70                    	jmp	short B_09
  3242                                  B_04:
  3243 00000C71 3C05                    	cmp	al, 5
  3244 00000C73 7269                    	jb	short B_08
  3245                                  	;ja	short B_07
  3246 00000C75 7741                    	ja	short B_58 ; 26/10/2020
  3247                                  
  3248                                  	; 23/02/2019
  3249 00000C77 BE[EB45]                	mov	si, msg_create_ext_partition_h
  3250 00000C7A E8330D                  	call	print_msg
  3251                                  
  3252                                  	; 24/02/2019
  3253 00000C7D 803E[C56C]00            	cmp	byte [epnumber], 0
  3254 00000C82 7613                    	jna	short B_05
  3255                                  
  3256 00000C84 BE[BD5B]                	mov	si, msg_ext_partition_exists
  3257 00000C87 E8260D                  	call 	print_msg
  3258                                  
  3259 00000C8A BE[AD52]                	mov	si, msg_press_any_key
  3260 00000C8D E8200D                  	call	print_msg
  3261                                  
  3262 00000C90 30E4                    	xor	ah, ah
  3263 00000C92 CD16                    	int	16h
  3264                                  
  3265 00000C94 E93CF7                  	jmp	A_42
  3266                                  B_05:
  3267 00000C97 803E[C36C]00            	cmp	byte [ppcount], 0  ; primary partition count
  3268 00000C9C 7746                    	ja	short B_10
  3269                                  
  3270                                  	; 09/02/2019
  3271 00000C9E BE[724C]                	mov	si, msg_ext_partition_error
  3272 00000CA1 E80C0D                  	call	print_msg
  3273                                  B_06:	
  3274 00000CA4 BE[AD52]                	mov	si, msg_press_any_key
  3275 00000CA7 E8060D                  	call	print_msg
  3276                                  
  3277 00000CAA 30E4                    	xor	ah, ah
  3278 00000CAC CD16                    	int	16h
  3279                                  
  3280 00000CAE C606[C169]01            	mov	byte [pp_type], 1
  3281                                  
  3282 00000CB3 E8EFFA                  	call	cpi_2 ; 15/02/2019
  3283 00000CB6 EB95                    	jmp	short B_02
  3284                                  
  3285                                  B_58:
  3286                                  	; 26/10/2020
  3287 00000CB8 803E[2265]80            	cmp	byte [DrvNum], 80h ; hd0 ?
  3288 00000CBD 7707                    	ja	short B_59 ; Do not check primary dos partition count
  3289                                  	; The second hard disk may contain extended partition without
  3290                                  	; a primary dos partition
  3291 00000CBF 803E[C36C]00            	cmp	byte [ppcount], 0  ; primary dos partition count
  3292 00000CC4 760A                    	jna	short B_07
  3293                                  B_59:
  3294 00000CC6 803E[C56C]00            	cmp	byte [epnumber], 0
  3295                                  			; is there an extended partition ?
  3296 00000CCB 7603                    	jna	short B_07 ; no
  3297 00000CCD E9CDF7                  	jmp	create_logical_drives
  3298                                  B_07:
  3299 00000CD0 BE[E046]                	mov	si, msg_create_logical_drive_h
  3300 00000CD3 E8DA0C                  	call	print_msg
  3301                                  
  3302 00000CD6 BE[B14C]                	mov	si, msg_logical_drive_error
  3303 00000CD9 E8D40C                  	call	print_msg
  3304 00000CDC EBC6                    	jmp	short B_06
  3305                                  
  3306                                  ;	mov	si, msg_use_entire_ep_space
  3307                                  ;	jmp	short B_12
  3308                                  	
  3309                                  B_08:
  3310 00000CDE BE[D547]                	mov	si, msg_create_nondos_partition_h
  3311                                  B_09:
  3312 00000CE1 E8CC0C                  	call	print_msg
  3313                                  B_10:
  3314                                  	; 15/02/2019
  3315                                  	;cmp	byte [newdisk], 0
  3316                                  	;ja	short B_11
  3317                                  
  3318 00000CE4 803E[C26C]00            	cmp	byte [pcount], 0 ; (valid) partition count
  3319 00000CE9 7605                    	jna	short B_11
  3320                                  
  3321 00000CEB BE[0A4B]                	mov	si, msg_use_all_space
  3322 00000CEE EB03                    	jmp	short B_12
  3323                                  B_11:
  3324 00000CF0 BE[E34A]                	mov	si, msg_use_whole_disk ; partition size: whole disk
  3325                                  B_12:
  3326 00000CF3 E8BA0C                  	call	print_msg
  3327                                  B_13:
  3328 00000CF6 30E4                    	xor	ah, ah
  3329 00000CF8 CD16                    	int	16h
  3330                                  
  3331 00000CFA 3C1B                    	cmp	al, 27 ; ESCAPE key
  3332                                  	;;je	_crlf_exit
  3333 00000CFC 0F84D3F6                	je	A_42 ; 25/02/2019
  3334 00000D00 24DF                    	and	al, 0DFh
  3335 00000D02 3C4E                    	cmp	al, 'N'
  3336 00000D04 740D                    	je	short B_14  ;02/03/2019
  3337 00000D06 3C59                    	cmp	al, 'Y'
  3338 00000D08 75EC                    	jne	short B_13
  3339                                  	
  3340 00000D0A FE06[C069]              	inc	byte [wholedisk]
  3341                                  	
  3342                                  	; 02/03/2019
  3343 00000D0E BE[8A59]                	mov	si, _msg_YES
  3344                                  	;call	print_msg
  3345 00000D11 EB03                    	jmp	short B_15
  3346                                  B_14:
  3347 00000D13 BE[9059]                	mov	si, _msg_NO
  3348                                  B_15:	; 06/03/2019
  3349 00000D16 E8970C                  	call	print_msg
  3350                                  
  3351                                  	; 15/02/2019
  3352 00000D19 29DB                    	sub	bx, bx
  3353                                  	;cmp	byte [newdisk], bl ; 0
  3354                                  	;ja	short B_16 ; 23/02/2019
  3355                                  	; 19/10/2020
  3356                                  	;cmp	byte [pcount], 0
  3357                                  	; 03/11/2020
  3358 00000D1B 381E[C26C]              	cmp	byte [pcount], bl ; 0
  3359 00000D1F 7608                    	jna	short B_16 ; [pcount] = 0 (newdisk, empty pt)
  3360 00000D21 381E[C069]              	cmp	byte [wholedisk], bl ; 0
  3361 00000D25 0F87FE00                	ja	B_27 ; 23/02/2019
  3362                                  B_16:
  3363                                  	; 08/02/2019
  3364                                  	;;sub	bx, bx
  3365                                  	;mov	ax, [total_sectors]
  3366                                  	;mov	dx, [total_sectors+2]
  3367                                  	;sub	ax, [sectors]
  3368                                  	;sbb	dx, bx ; sbb dx, 0
  3369                                  	;
  3370                                  	;mov	[pp_Sectors], ax   ; = [total_sectors] - [sectors]
  3371                                  	;mov	[pp_Sectors+2], dx ; = [total_sectors+2] - carry bit
  3372                                  	; 21/03/2021
  3373 00000D29 66A1[2665]              	mov	eax, [total_sectors]
  3374 00000D2D 660FB716[A23C]          	movzx	edx, word [sectors]
  3375 00000D33 6629D0                  	sub	eax, edx
  3376 00000D36 66A3[BC69]              	mov	[pp_Sectors], eax  ; = [total_sectors] - [sectors]
  3377                                  B_17:
  3378 00000D3A 381E[C069]              	cmp	byte [wholedisk], bl ; 0
  3379 00000D3E 0F87E900                	ja	B_28 ; 09/02/2019
  3380                                  B_18:
  3381                                  	; clear screen
  3382 00000D42 B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
  3383 00000D45 CD10                    	int	10h
  3384                                  
  3385                                  	; 04/11/2020
  3386 00000D47 803E[C169]01            	cmp	byte [pp_type], 1 ; primary dos partition ?
  3387 00000D4C 7405                    	je	short B_61
  3388                                  	; "Create Partition"
  3389 00000D4E BE[4B42]                	mov	si, msg_create_partition_h
  3390 00000D51 EB03                    	jmp	short B_62
  3391                                  B_61:
  3392                                  	; "Create DOS partition"
  3393 00000D53 BE[F644]                	mov	si, msg_create_dos_partition_h ; header
  3394                                  B_62:
  3395 00000D56 E8570C                  	call	print_msg
  3396 00000D59 BE[8749]                	mov	si, msg_create_trdos_partition_s ; size options
  3397 00000D5C E8510C                  	call	print_msg	
  3398                                  B_19:	
  3399 00000D5F 30E4                    	xor	ah, ah
  3400 00000D61 CD16                    	int	16h
  3401                                  
  3402                                  	; 24/02/2019
  3403 00000D63 3C1B                    	cmp	al, 27	; ESCAPE key
  3404 00000D65 0F846AF6                	je	A_42	; Cancel
  3405                                  
  3406 00000D69 3C20                    	cmp	al, 32	; SPACE key
  3407 00000D6B 751E                    	jne	short B_21
  3408                                  
  3409                                  		; Entire space
  3410                                  	;mov	ax, [pp_Sectors]
  3411                                  	;mov	dx, [pp_Sectors+2]
  3412                                  	; 15/03/2021
  3413 00000D6D 66A1[BC69]              	mov	eax, [pp_Sectors]
  3414                                  
  3415 00000D71 C606[C069]01            	mov 	byte [wholedisk], 1 ; 09/02/2019
  3416 00000D76 EB55                    	jmp	short B_23
  3417                                  
  3418                                  B_60:	; 31/10/2020
  3419 00000D78 75C8                    	jnz	short B_18  ; ESCape (return to options menu)
  3420                                  	; partition size input is ZERO !
  3421                                  B_20:
  3422                                  	; ZERO partition size message
  3423 00000D7A BE[9D57]                	mov	si, msg_zero_partition_size
  3424 00000D7D E8300C                  	call	print_msg
  3425                                  	
  3426 00000D80 30E4                    	xor	ah, ah
  3427 00000D82 CD16                    	int	16h
  3428 00000D84 3C1B                    	cmp	al, 27 ; ESCAPE key
  3429 00000D86 75BA                    	jne	short B_18 ; Retry
  3430                                  
  3431                                  	; 19/10/2020
  3432 00000D88 E9E4F9                  	jmp	_crlf_exit ; exit
  3433                                  
  3434                                  B_21:
  3435 00000D8B C606[CE69]25            	mov	byte [pSize_unit], '%'
  3436 00000D90 3C25                    	cmp	al, '%'
  3437 00000D92 7422                    	je	short B_22
  3438 00000D94 C606[CE69]53            	mov	byte [pSize_unit], 'S'
  3439 00000D99 3C0D                    	cmp	al, 13 ; 0Dh, Carriage Return key
  3440 00000D9B 7419                    	je	short B_22
  3441 00000D9D 24DF                    	and	al, 0DFh
  3442 00000D9F 3C53                    	cmp	al, 'S'
  3443 00000DA1 7413                    	je	short B_22
  3444 00000DA3 A2[CE69]                	mov	[pSize_unit], al
  3445 00000DA6 3C4B                    	cmp	al, 'K'
  3446 00000DA8 740C                    	je	short B_22
  3447 00000DAA 3C4D                    	cmp	al, 'M'
  3448 00000DAC 7408                    	je	short B_22
  3449 00000DAE 3C47                    	cmp	al, 'G'
  3450 00000DB0 7404                    	je	short B_22
  3451 00000DB2 3C43                    	cmp	al, 'C'
  3452 00000DB4 75A9                    	jne	short B_19
  3453                                  B_22:
  3454 00000DB6 C606[0361]73            	mov	byte [msg_sectors_crlf_s], 's' ; " sectors"
  3455                                  
  3456 00000DBB E8600E                  	call	partition_size_input
  3457                                  	;jc	_crlf_exit ; exit if partition size input is 0
  3458                                  	;jc	short B_20
  3459                                  	; 29/10/2020
  3460                                  	;jnc	short B_60
  3461                                  	;jz	short B_20 ; partition size input is ZERO !
  3462                                  	;jmp	short B_18 ; ESCape (return to options menu)
  3463                                  	; 31/10/2020
  3464 00000DBE 72B8                    	jc	short B_60 ; ESC or zero partition size
  3465                                  ;B_60:
  3466                                  	; 13/03/2021
  3467                                  	;and	bx, bx ; bx_dx_ax = partition size
  3468                                  	;;jnz	short B_29
  3469                                  	;; 23/02/2019 
  3470                                  	;jnz	short B_24 ; invalid! (use maximum available sectors)
  3471                                  	;; 08/02/2019
  3472                                  	;or	dx, dx
  3473                                  	;jnz	short B_23 ; proper size (for now)
  3474                                  	
  3475                                  	; 13/03/2021
  3476                                  	;or	edx, edx
  3477                                  	;jnz	short B_24 ; invalid! (use maximum available sectors)
  3478                                  
  3479                                  	;mov	bx, [min_sectors] ; minimum sectors
  3480                                  	;cmp	bx, ax
  3481                                  	;jna	short B_23 ; proper size (for now)
  3482                                  	; 13/03/2021
  3483 00000DC0 668B16[E469]            	mov	edx, [min_sectors]
  3484 00000DC5 6639D0                  	cmp	eax, edx
  3485 00000DC8 7303                    	jnb	short B_23 ; proper size (for now)
  3486                                  	
  3487                                  	; invalid! (use minimum sectors or sectors per cylinder)
  3488                                  	;mov	ax, bx
  3489                                  	; 13/03/2021
  3490 00000DCA 6689D0                  	mov	eax, edx
  3491                                  B_23:
  3492                                  	; 09/02/2019
  3493                                  	; save dx,ax
  3494                                  	;mov	[ppn_Sectors+2], dx 
  3495                                  	;mov	[ppn_Sectors], ax
  3496                                  	; 13/03/2021
  3497 00000DCD 66A3[F069]              	mov	[ppn_Sectors], eax
  3498                                  
  3499                                  	; write partition size
  3500                                  	;push	dx
  3501                                  	;push	ax
  3502                                  	; 06/11/2020
  3503 00000DD1 BE[DB69]                	mov	si, msg_partition_sectors + 10 ; max. 11 digits
  3504 00000DD4 E8920C                  	call	bin_to_decimal
  3505                                  	; ds:si = beginning of decimal number text
  3506 00000DD7 E8D60B                  	call	print_msg
  3507 00000DDA BE[FC60]                	mov	si, msg_sectors_crlf
  3508 00000DDD E8D00B                  	call	print_msg
  3509                                  	;pop	ax
  3510                                  	;pop	dx
  3511                                  
  3512 00000DE0 803E[C069]00            	cmp	byte [wholedisk], 0
  3513 00000DE5 7748                    	ja	short B_29 ; 09/02/2019
  3514                                  
  3515                                  	; 15/03/2021
  3516                                  	;sub	eax, eax ; no need to clear hw of eax here
  3517                                  
  3518                                  	; restore ax,dx
  3519                                  	;mov	ax, [ppn_Sectors]
  3520                                  	;mov	dx, [ppn_Sectors+2]
  3521                                  
  3522                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3523                                  ; select whole disk
  3524                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3525                                  
  3526                                  	; 15/03/2021
  3527 00000DE7 66A1[F069]              	mov	eax, [ppn_Sectors]
  3528                                  
  3529                                  	; select whole disk 
  3530                                  	;   if partition size > disk size
  3531                                  	;cmp	dx, [pp_Sectors+2]
  3532                                  	;ja	short B_24
  3533                                  	;jb	short B_29
  3534                                  	;cmp	ax, [pp_Sectors]
  3535                                  	;jna	short B_29
  3536                                  	; 15/03/2021
  3537 00000DEB 663B06[BC69]            	cmp	eax, [pp_Sectors]
  3538 00000DF0 763D                    	jna	short B_29
  3539                                  B_24:
  3540                                  	;cmp	byte [newdisk], 0
  3541                                  	;jna	short B_30
  3542                                  	; 19/10/2020
  3543 00000DF2 803E[C26C]00            	cmp	byte [pcount], 0
  3544 00000DF7 775B                    	ja	short B_30
  3545                                  
  3546                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3547                                  ; "use whole disk or go to back" question
  3548                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3549                                  
  3550 00000DF9 BE[084C]                	mov	si, msg_partition_size_overs
  3551                                  B_25:
  3552 00000DFC E8B10B                  	call	print_msg
  3553                                  B_26:
  3554 00000DFF 30E4                    	xor	ah, ah
  3555 00000E01 CD16                    	int	16h
  3556                                  	
  3557 00000E03 3C1B                    	cmp	al, 27 ; ESCAPE key
  3558                                  	;je	B_01
  3559 00000E05 0F8439FF                	je	B_18 ; 09/02/2019
  3560 00000E09 3C0D                    	cmp	al, 13 ; ENTER (Carriage Return) key
  3561 00000E0B 75F2                    	jne	short B_26
  3562                                  
  3563 00000E0D FE06[C069]              	inc	byte [wholedisk]
  3564                                  
  3565                                  	; 24/02/2019
  3566                                  	;cmp	byte [newdisk], 0
  3567                                  	;ja	short B_27
  3568 00000E11 803E[C26C]00            	cmp	byte [pcount], 0  ; (valid) partition count
  3569 00000E16 760F                    	jna	short B_27 ; no
  3570                                  
  3571 00000E18 8B1E[8C6D]              	mov	bx, [c_fspc_offset]
  3572                                  	;mov	ax, [free_space.sectors_unused+bx]
  3573                                  	;mov	dx, [free_space.sectors_unused+bx+2]
  3574                                  	;mov	[pp_Sectors], ax
  3575                                  	;mov	[pp_Sectors+2], dx
  3576                                  	; 15/03/2021
  3577 00000E1C 668B87[2A6D]            	mov	eax, [free_space.sectors_unused+bx]
  3578 00000E21 66A3[BC69]              	mov	[pp_Sectors], eax
  3579                                  
  3580 00000E25 EB04                    	jmp	short B_28 
  3581                                  B_27:
  3582                                  	; 09/02/2019
  3583                                  	;mov	dx, [pp_Sectors+2]
  3584                                  	;mov	ax, [pp_Sectors]
  3585                                  	; 15/03/2021
  3586 00000E27 66A1[BC69]              	mov	eax, [pp_Sectors]
  3587                                  B_28:
  3588                                  	;mov	[ppn_Sectors+2], dx
  3589                                  	;mov	[ppn_Sectors], ax
  3590                                  	; 15/03/2021
  3591 00000E2B 66A3[F069]              	mov	[ppn_Sectors], eax
  3592                                  B_29:
  3593 00000E2F 803E[C169]05            	cmp	byte [pp_type], 5
  3594 00000E34 0F852C01                	jne	B_51
  3595                                  
  3596 00000E38 803E[C36C]00            	cmp	byte [ppcount], 0  ; primary partition count
  3597 00000E3D 0F87C700                	ja	B_45
  3598                                  
  3599 00000E41 BE[724C]                	mov	si, msg_ext_partition_error
  3600 00000E44 E8690B                  	call	print_msg
  3601 00000E47 BE[EB4B]                	mov	si, msg_any_key_to_retry
  3602 00000E4A E8630B                  	call	print_msg
  3603                                  
  3604                                  	; 09/02/2019
  3605 00000E4D 30E4                    	xor	ah, ah
  3606 00000E4F CD16                    	int	16h
  3607                                  
  3608                                  	;jmp	B_01
  3609 00000E51 E951F9                  	jmp	cpi_2
  3610                                  
  3611                                  B_30:
  3612                                  	; clear screen
  3613 00000E54 B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
  3614 00000E57 CD10                    	int	10h
  3615                                  
  3616 00000E59 BE[F644]                	mov	si, msg_create_dos_partition_h ; header
  3617 00000E5C E8510B                  	call	print_msg
  3618                                  
  3619 00000E5F BE[A95A]                	mov	si, msg_partition_size_limit
  3620 00000E62 E84B0B                  	call	print_msg
  3621                                  
  3622 00000E65 8B1E[8C6D]              	mov	bx, [c_fspc_offset]
  3623                                  
  3624 00000E69 803E[CE69]53            	cmp	byte [pSize_unit], 'S'
  3625 00000E6E 7415                    	je	short B_31
  3626 00000E70 803E[CE69]4B            	cmp	byte [pSize_unit], 'K'
  3627 00000E75 740E                    	je	short B_31
  3628                                  
  3629 00000E77 803E[CE69]25            	cmp	byte [pSize_unit], '%'
  3630 00000E7C 746D                    	je	short B_41
  3631                                  
  3632 00000E7E 803E[CE69]43            	cmp	byte [pSize_unit], 'C'
  3633 00000E83 747D                    	je	B_44
  3634                                  B_31:
  3635                                  	; 'S', 'K'
  3636 00000E85 81C3[2A6D]              	add	bx, free_space.sectors_unused
  3637                                  	;mov	ax, [bx]
  3638                                  	;mov	dx, [bx+2]
  3639                                  B_42:
  3640                                  	; 15/03/2021	
  3641 00000E89 668B07                  	mov	eax, [bx]
  3642 00000E8C 6631D2                  	xor	edx, edx
  3643 00000E8F 6631C9                  	xor	ecx, ecx
  3644 00000E92 B10A                    	mov	cl, 10 
  3645                                  	
  3646                                  	;mov	cx, 10
  3647 00000E94 89E5                    	mov	bp, sp
  3648                                  ;B_32:
  3649                                  	;call	div32
  3650                                  	;push	bx
  3651                                  	;or	dx, dx
  3652                                  	;jnz	short B_32
  3653                                  	;cmp	ax, 9
  3654                                  	;ja	short B_32
  3655                                  B_32:
  3656                                  	; 15/03/2021
  3657 00000E96 66F7F1                  	div	ecx
  3658 00000E99 52                      	push	dx
  3659 00000E9A 6683F809                	cmp	eax, 9
  3660 00000E9E 7604                    	jna	short B_33
  3661 00000EA0 28D2                    	sub	dl, dl
  3662                                  	; edx = 0
  3663 00000EA2 EBF2                    	jmp	short B_32
  3664                                  B_33:
  3665 00000EA4 BB0700                  	mov	bx, 07h
  3666                                  	;or	ax, ax
  3667                                  	;jnz	short B_35
  3668                                  	; 15/03/2021
  3669 00000EA7 08C0                    	or	al, al
  3670 00000EA9 7501                    	jnz	short B_35
  3671                                  B_34:
  3672 00000EAB 58                      	pop	ax
  3673                                  B_35:
  3674 00000EAC 0430                    	add	al, '0'
  3675                                  B_36:
  3676 00000EAE B40E                    	mov	ah, 0Eh
  3677                                  	;mov	bx, 07h
  3678 00000EB0 CD10                    	int	10h	; write character (as tty)
  3679                                  
  3680 00000EB2 39EC                    	cmp	sp, bp
  3681 00000EB4 72F5                    	jb	short B_34
  3682                                  
  3683 00000EB6 803E[CE69]53            	cmp	byte [pSize_unit], 'S'
  3684 00000EBB 7422                    	je	short B_38
  3685 00000EBD 803E[CE69]4B            	cmp	byte [pSize_unit], 'K'
  3686 00000EC2 741B                    	je	short B_38
  3687                                  
  3688 00000EC4 803E[CE69]25            	cmp	byte [pSize_unit], '%'
  3689 00000EC9 7508                    	jne	short B_37
  3690                                  
  3691                                  	; 24/02/2019
  3692 00000ECB 3C25                    	cmp	al, '%'
  3693 00000ECD 7416                    	je	short B_40
  3694 00000ECF B025                    	mov	al, '%'
  3695 00000ED1 EBDB                    	jmp	short B_36 
  3696                                  B_37:
  3697 00000ED3 803E[CE69]43            	cmp	byte [pSize_unit], 'C'
  3698 00000ED8 7505                    	jne	short B_38
  3699                                  
  3700 00000EDA BE[455B]                	mov	si, msg_cylinders
  3701 00000EDD EB03                    	jmp	short B_39
  3702                                  B_38:
  3703 00000EDF BE[505B]                	mov	si, msg_sectors
  3704                                  B_39:
  3705 00000EE2 E8CB0A                  	call	print_msg
  3706                                  B_40:
  3707 00000EE5 BE[F65A]                	mov	si, msg_partition_size_limit_r
  3708                                  	;call	print_msg
  3709                                  
  3710 00000EE8 E911FF                  	jmp	B_25
  3711                                  
  3712                                  B_41:
  3713                                  	; '%'
  3714 00000EEB 81C3[326D]              	add	bx, free_space.percent_unused
  3715 00000EEF 8B07                    	mov	ax, [bx]
  3716                                  ;B_42:	
  3717 00000EF1 89E5                    	mov	bp, sp
  3718 00000EF3 B90A00                  	mov	cx, 10
  3719                                  B_43:	
  3720 00000EF6 31D2                    	xor	dx, dx
  3721 00000EF8 F7F1                    	div	cx
  3722 00000EFA 52                      	push	dx
  3723 00000EFB 83F809                  	cmp	ax, 9
  3724 00000EFE 77F6                    	ja	short B_43
  3725 00000F00 EBA2                    	jmp	short B_33
  3726                                  B_44:
  3727                                  	; 'C'
  3728 00000F02 81C3[1E6D]              	add	bx, free_space.space
  3729                                  	;mov	ax, [bx]
  3730                                  	;jmp	short B_42
  3731                                  	; 15/03/2021
  3732 00000F06 EB81                    	jmp	short B_42
  3733                                  
  3734                                  B_45:
  3735                                  	; 23/02/2019
  3736 00000F08 8B1E[8C6D]              	mov	bx, [c_fspc_offset]
  3737                                  	;mov	ax, [bx+free_space.start]
  3738                                  	; 15/03/2021
  3739 00000F0C 668B87[226D]            	mov	eax, [bx+free_space.start]
  3740                                  
  3741                                  	; set free space start cylinder to 1 if it is 0
  3742                                  	;or	ax, ax
  3743                                  	;jnz	short B_46
  3744                                  	; 15/03/2021
  3745 00000F11 6609C0                  	or	eax, eax
  3746 00000F14 7510                    	jnz	short B_46
  3747                                  
  3748 00000F16 B005                    	mov	al, 5	; Get free space for extended partition
  3749 00000F18 E8DE13                  	call	find_part_free_space
  3750                                  
  3751 00000F1B 891E[8C6D]              	mov	[c_fspc_offset], bx
  3752                                  
  3753                                  	; 19/10/2020
  3754                                  	;and	cx, cx
  3755                                  	; 15/03/2021
  3756 00000F1F 6621C9                  	and	ecx, ecx
  3757 00000F22 0F8468F5                	jz	cp_3	; there is not free space on disk
  3758                                  B_46:
  3759                                  	; 15/03/2021
  3760                                  	;sub	eax, eax ; no need to clear hw of eax here
  3761                                  
  3762                                  	; 24/02/2019
  3763 00000F26 E81100                  	call	partition_size_fixup_x
  3764 00000F29 0F8227FF                	jc	B_30
  3765                                  
  3766                                  	; 16/02/2019
  3767 00000F2D E859FB                  	call	create_extended_partition 
  3768                                  			; must be called after 'find_part_free_space'.
  3769                                  	; 24/02/2019
  3770 00000F30 E8C10F                  	call	show_selected_partition
  3771 00000F33 E9AE00                  	jmp	C_02
  3772                                  
  3773                                  partition_size_fixup:
  3774                                  	; 24/02/2019
  3775 00000F36 8B1E[8C6D]              	mov	bx, [c_fspc_offset]
  3776                                  partition_size_fixup_x:
  3777                                  	; 19/10/2020
  3778                                  
  3779                                  	;cmp	byte [newdisk], 0
  3780                                  	;ja	short B_50
  3781                                  
  3782 00000F3A 803E[C26C]00            	cmp	byte [pcount], 0 ; (valid) partition count
  3783 00000F3F 7622                    	jna	short B_50
  3784                                  
  3785 00000F41 81C3[2A6D]              	add	bx, free_space.sectors_unused
  3786                                  	;mov	ax, [bx]
  3787                                  	;mov	dx, [bx+2]
  3788                                  	; 15/03/2021
  3789 00000F45 668B07                  	mov	eax, [bx]
  3790                                  
  3791                                  	;cmp	dx, [ppn_Sectors+2]
  3792                                  	;jb	short B_50 ; 24/02/2019
  3793                                  	;ja	short B_47
  3794                                  	;cmp	ax, [ppn_Sectors]
  3795                                  	;jb	short B_50 ; 24/02/2019
  3796                                  	;je	short B_49
  3797                                  	; 15/03/2021
  3798 00000F48 663B06[F069]            	cmp	eax, [ppn_Sectors]
  3799 00000F4D 7214                    	jb	short B_50
  3800 00000F4F 740E                    	je	short B_49
  3801                                  B_47:
  3802                                  	; 19/02/2019
  3803                                  	;mov	ax, [ppn_Sectors]
  3804                                  B_48:
  3805                                  	;mov	dx, [ppn_Sectors+2]
  3806                                  	; 15/03/2021
  3807 00000F51 66A1[F069]              	mov	eax, [ppn_Sectors] 
  3808                                  
  3809                                  	; 18/02/2019
  3810                                  
  3811                                  	; check for best fit
  3812                                  	; (leave max. available space to next time if 
  3813                                  	;  another space/gap fits to partition size request)
  3814                                  
  3815 00000F55 E8B015                  	call	find_enough_free_sectors
  3816                                  		; CX = Free space index (0 to 4)
  3817                                  		; DX:AX = First available space which fits to request
  3818                                  	; 15/03/2021
  3819                                  	; eax = First available space which fits to request
  3820                                  	
  3821                                  	;mov	bx, cx
  3822                                  	;shl	bl, 4 ; * 16  ; * Free space structure size
  3823                                  	;mov	[c_fspc_offset], bx
  3824                                  	
  3825                                  	; 22/02/2019
  3826 00000F58 C0E104                  	shl	cl, 4
  3827 00000F5B 890E[8C6D]              	mov	[c_fspc_offset], cx
  3828                                  
  3829                                  	;add	bx, free_space.sectors_unused
  3830                                  	;mov	ax, [bx]
  3831                                  	;mov	dx, [bx+2]
  3832                                  B_49:		
  3833                                  	; Save max. available space
  3834                                  	;mov	[pp_Sectors], ax
  3835                                  	;mov	[pp_Sectors+2], dx
  3836                                  	; 15/03/2021
  3837 00000F5F 66A3[BC69]              	mov	[pp_Sectors], eax
  3838                                  B_50:
  3839 00000F63 C3                      	retn
  3840                                  B_51:
  3841                                  	; 24/02/2019
  3842 00000F64 E8CFFF                  	call	partition_size_fixup
  3843 00000F67 0F82E9FE                	jc	B_30
  3844                                  
  3845                                  	; 16/02/2019
  3846                                  	; Force cylinder boundary alignment except
  3847                                  	;   sectors ('S') and kilobytes ('K') as sizing unit.
  3848                                  
  3849 00000F6B C606[8E6D]59            	mov	byte [cylinder_boundary], 'Y' ; Default
  3850                                  				; sizing unit is one of
  3851                                  				; 'cylinders','megabytes','gigabytes'
  3852                                  				; and boundary alignment is yes for them.
  3853 00000F70 A0[CE69]                	mov	al, [pSize_unit]
  3854                                  
  3855                                  	;cmp	byte [pSize_unit], 'S' ; Sectors
  3856 00000F73 3C53                    	cmp	al, 'S'
  3857 00000F75 7404                    	je	short B_52
  3858                                  
  3859                                  	;cmp	byte [pSize_unit], 'K' ; Kilobytes
  3860 00000F77 3C4B                    	cmp	al, 'K'
  3861 00000F79 752F                    	jne	short B_56
  3862                                  B_52:
  3863                                  	; Sizing unit is one of 'sectors' and/or 'kilobytes'
  3864                                  	; and bound aligment will be applied if the answer will be yes.
  3865                                  
  3866 00000F7B BE[FA4C]                	mov	si, msg_cylinder_boundary_set
  3867 00000F7E E82F0A                  	call	print_msg
  3868                                  B_53:
  3869 00000F81 30E4                    	xor	ah, ah
  3870 00000F83 CD16                    	int	16h
  3871                                  	; Cylinder boundary adjusting
  3872 00000F85 3C0D                    	cmp	al, 13 ; ENTER key
  3873 00000F87 74F2                    	je	short B_52
  3874 00000F89 3C1B                    	cmp	al, 27 ; ESCAPE key
  3875 00000F8B 741A                    	je	short B_55	; Align end of the partition only
  3876                                  				; if start of the partition is aligned
  3877                                  				; or it starts at cyl 0, head 1, sect 17 or 63.
  3878                                  				; (End of the partition will be extended to
  3879                                  				; end sector of it's last cylinder if the size
  3880                                  				; will not over [pp_Sectors] value.)
  3881 00000F8D 24DF                    	and	al, 0DFh
  3882                                  
  3883                                  	; 22/02/2019
  3884 00000F8F 3C59                    	cmp	al, 'Y'
  3885 00000F91 7508                    	jne	short B_54
  3886                                  
  3887 00000F93 BE[8A59]                	mov	si, _msg_YES
  3888 00000F96 E8170A                  	call	print_msg
  3889                                  
  3890                                  	;mov	al, 'Y'
  3891                                  	;jmp	short B_55
  3892 00000F99 EB0F                    	jmp	short B_56
  3893                                  B_54:
  3894 00000F9B 3C4E                    	cmp	al, 'N'
  3895 00000F9D 75E2                    	jne	short B_53
  3896                                  
  3897 00000F9F BE[9059]                	mov	si, _msg_NO
  3898 00000FA2 E80B0A                  	call	print_msg
  3899                                  
  3900 00000FA5 B04E                    	mov	al, 'N'
  3901                                  		; do not align partition to cylinder boundary
  3902                                  B_55:
  3903 00000FA7 A2[8E6D]                	mov	[cylinder_boundary], al
  3904                                  B_56:
  3905 00000FAA E84CF8                  	call	create_primary_partition
  3906                                  	
  3907                                  	; 18/02/2019
  3908                                  	;cmp	byte [newdisk], 0
  3909                                  	;jna	short B_57
  3910                                  
  3911                                  	; 19/10/2020
  3912 00000FAD 803E[C26C]00            	cmp	byte [pcount], 0
  3913 00000FB2 770D                    	ja	short B_57
  3914                                  
  3915                                  	;xor	ax, ax ; 0
  3916                                  	;xor	dx, dx ; 0
  3917                                  	; 09/03/2021
  3918 00000FB4 6631C0                  	xor	eax, eax
  3919                                  
  3920                                  	; DX_AX = Masterboot Sector = 0
  3921                                  
  3922 00000FB7 BB[CC52]                	mov	bx, MasterBootBuff
  3923                                  
  3924                                  	; ES:BX = Sector Buffer
  3925                                  	; 09/03/2021
  3926                                  	; EAX = Masterboot Sector = 0
  3927                                  
  3928 00000FBA E8510A                  	call	write_hd_sector
  3929 00000FBD 0F8298F7                	jc	print_error_code ; 18/10/2020
  3930                                  B_57:
  3931                                  	; DS:SI = Partition Table Entry address
  3932                                  	; 25/02/2019
  3933 00000FC1 8936[B86D]              	mov	[pte_address], si  ; save PTE address
  3934 00000FC5 E82C0F                  	call	show_selected_partition
  3935                                  
  3936                                  	;jmp	C_01
  3937                                  
  3938                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3939                                  ; format question
  3940                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3941                                  
  3942                                  C_01:
  3943                                  	;mov	si, CRLF
  3944                                  	;call	print_msg
  3945                                  
  3946 00000FC8 C606[DD69]01            	mov	byte [format_q], 1
  3947                                  
  3948 00000FCD A0[C169]                	mov	al, [pp_type]
  3949 00000FD0 3C01                    	cmp	al, 1		; FAT12 (CHS)
  3950 00000FD2 741D                    	je	short C_03
  3951 00000FD4 3C04                    	cmp	al, 4		; FAT16 CHS
  3952 00000FD6 7419                    	je	short C_03
  3953 00000FD8 3C06                    	cmp	al, 6		; FAT16 BIG CHS
  3954 00000FDA 7415                    	je	short C_03
  3955 00000FDC 3C0B                    	cmp	al, 0Bh		; FAT32 CHS
  3956 00000FDE 7411                    	je	short C_03
  3957 00000FE0 3CA1                    	cmp	al, 0A1h	; SINGLIX FS1
  3958 00000FE2 740D                    	je	short C_03
  3959                                  
  3960                                  	;cmp	al, 71h
  3961                                  	;je	short C_03	; RETRO UNIX 386
  3962                                  
  3963                                  	;dec	byte [format_q] ; 0
  3964                                  C_02:
  3965 00000FE4 C606[DD69]00            	mov	byte [format_q], 0 ; 24/02/2019
  3966                                  
  3967                                  	; NON-DOS partition!
  3968                                  	; Ask for editing PT or exit (continue without formatting)
  3969 00000FE9 BE[8050]                	mov	si, msg_edit_or_exit
  3970 00000FEC E8C109                  	call	print_msg
  3971 00000FEF EB06                    	jmp	short C_04
  3972                                  C_03:
  3973                                  	; Ask for formatting, editing PT or exit
  3974 00000FF1 BE[1150]                	mov	si, msg_format_stage
  3975 00000FF4 E8B909                  	call	print_msg
  3976                                  C_04:
  3977 00000FF7 BE[5150]                	mov	si, msg_partition_edit
  3978 00000FFA E8B309                  	call	print_msg
  3979                                  C_05:
  3980 00000FFD 28E4                    	sub	ah, ah
  3981 00000FFF CD16                    	int	16h
  3982                                  
  3983 00001001 3C0D                    	cmp	al, 13
  3984 00001003 7434                    	je	short C_08
  3985                                  
  3986                                  	;; 07/03/2019
  3987 00001005 3C20                    	cmp	al, 20h ; SPACE
  3988                                  	;je	A_21 ; edit partition table option is selected
  3989 00001007 7503                    	jne	short C_06
  3990                                  	; 19/10/2020	
  3991 00001009 E9F1F1                  	jmp	A_21
  3992                                  C_06:
  3993 0000100C 3C1B                    	cmp	al, 27 ; ESCAPE
  3994 0000100E 75ED                    	jne	short C_05
  3995                                  	
  3996                                  	; 19/010/2020
  3997 00001010 E962F7                  	jmp	_exit
  3998                                  
  3999                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4000                                  ; save MBR then exit
  4001                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4002                                  
  4003                                  save_mbr_exit:
  4004                                  	; 24/02/2019
  4005 00001013 E8C010                  	call	init_partition_table
  4006                                  	; 12/03/2021
  4007                                  	;xor	eax, eax
  4008 00001016 E89015                  	call	display_partition_table
  4009                                  
  4010 00001019 BE[5152]                	mov	si, CRLF
  4011 0000101C E89109                  	call	print_msg
  4012                                  
  4013 0000101F BE[0551]                	mov	si, msg_writing_mbr
  4014 00001022 E88B09                  	call	print_msg
  4015                                  
  4016                                  	;xor	ax, ax ; 0
  4017                                  	;xor	dx, dx ; 0
  4018                                  	; 09/03/2021
  4019 00001025 6631C0                  	xor	eax, eax
  4020                                  
  4021                                  	; DX_AX = Masterboot Sector = 0
  4022                                  
  4023 00001028 BB[CC52]                	mov	bx, MasterBootBuff
  4024                                  
  4025                                  	; ES:BX = Sector Buffer
  4026                                  	; 09/03/2021
  4027                                  	; EAX = Masterboot Sector = 0
  4028                                  
  4029 0000102B E8E009                  	call	write_hd_sector
  4030 0000102E 7303                    	jnc	short C_07
  4031 00001030 E926F7                  	jmp	print_error_code ; 18/10/2020
  4032                                  
  4033                                  C_07:
  4034 00001033 BE[4D52]                	mov	si, Msg_OK
  4035                                  	;call	print_msg
  4036                                  	; 19/10/2020
  4037                                  	;jmp	_exit
  4038 00001036 E939F7                  	jmp	_p_exit
  4039                                  
  4040                                  C_08:
  4041 00001039 803E[DD69]01            	cmp	byte [format_q], 1
  4042 0000103E 72D3                    	jb	short save_mbr_exit
  4043                                  
  4044                                  	; 25/02/2019
  4045                                  	; Write MBR without writing message
  4046                                  	
  4047                                  	; NOTE: This may be second time of MBR writing...
  4048                                  	;	but, if partition table is modified,
  4049                                  	;	we need to write MBR to disk, here.
  4050                                  	;
  4051                                  	; (Otherwise.. the last created partition would not be recorded.)
  4052                                  
  4053                                  	;xor	ax, ax ; 0
  4054                                  	;xor	dx, dx ; 0
  4055                                  	; 09/03/2021
  4056 00001040 6631C0                  	xor	eax, eax
  4057                                  
  4058                                  	; DX_AX = Masterboot Sector = 0
  4059                                  
  4060 00001043 BB[CC52]                	mov	bx, MasterBootBuff
  4061                                  
  4062                                  	; ES:BX = Sector Buffer
  4063                                  	; 09/03/2021
  4064                                  	; EAX = Masterboot Sector = 0
  4065                                  
  4066 00001046 E8C509                  	call	write_hd_sector
  4067 00001049 0F820CF7                	jc	print_error_code ; 18/10/2020
  4068                                  
  4069                                  	;; clear screen
  4070                                  	;mov	ax, 3 ; set video mode to 03h (80x25 text)
  4071                                  	;int	10h
  4072                                  
  4073                                  	; 25/02/2019
  4074 0000104D 8B36[B86D]              	mov	si, [pte_address]
  4075                                  
  4076                                  	; 18/02/2019
  4077 00001051 E8A00E                  	call	show_selected_partition	
  4078                                  
  4079 00001054 A0[3850]                	mov	al, [partition_num_chr]
  4080 00001057 A2[F850]                	mov	[partition_num_txt], al
  4081                                  
  4082 0000105A BE[D650]                	mov	si, msg_format_question
  4083 0000105D E85009                  	call	print_msg
  4084                                  C_09:
  4085 00001060 30E4                    	xor	ah, ah
  4086 00001062 CD16                    	int	16h
  4087                                  
  4088 00001064 3C1B                    	cmp	al, 1Bh ; ESCAPE
  4089 00001066 74A4                    	je	short C_06
  4090                                  
  4091 00001068 24DF                    	and	al, 0DFh ; capitalization
  4092 0000106A 3C59                    	cmp	al, 'Y'
  4093 0000106C 740C                    	je	short C_10
  4094 0000106E 3C4E                    	cmp	al, 'N'
  4095 00001070 75EE                    	jne	short C_09
  4096 00001072 BE[9059]                	mov	si, _msg_NO 
  4097 00001075 E83809                  	call	print_msg
  4098                                  	;jmp	short C_06
  4099                                  	; 24/02/2019
  4100 00001078 EB99                    	jmp	short save_mbr_exit 
  4101                                  C_10:
  4102 0000107A BE[8A59]                	mov	si, _msg_YES
  4103 0000107D E83009                  	call	print_msg
  4104                                  
  4105                                  	; [pp_StartSector] = partition's start sector
  4106                                  	; [pp_Sectors] = partition size including start & end sector
  4107                                  	; [partition_num_chr] = partition number + '0'
  4108                                  	; [pp_type] = partition type (for TRDOS 386 boot sector)
  4109                                  
  4110 00001080 8926[3065]              	mov	[old_sp], sp
  4111                                  
  4112                                  	; 16/03/2021
  4113 00001084 6631D2                  	xor	edx, edx ; (this may not be necessary)
  4114 00001087 6631DB                  	xor	ebx, ebx ; (this may not be necessary)
  4115 0000108A 6631C9                  	xor	ecx, ecx ; (this may not be necessary)
  4116                                  
  4117 0000108D 8A16[C169]              	mov	dl, [pp_type]
  4118                                  	; DL = partition type (file system ID)
  4119                                  	;dec	dl
  4120                                  	;jz	FAT12_hd_format
  4121 00001091 80FA01                  	cmp	dl, 1 ; 14/09/2020 (BugFix)
  4122 00001094 0F862605                	jna	FAT12_hd_format
  4123                                  	;cmp	dl, 4
  4124                                  	;je	FAT16_hd_format
  4125                                  	;cmp	dl, 6
  4126                                  	;je	FAT16_hd_format
  4127 00001098 80FA0B                  	cmp	dl, 0Bh 
  4128 0000109B 0F826303                	jb	FAT16_hd_format
  4129                                  	;je	short FAT32_hd_format
  4130                                  	;cmp	dl, 0Ch ; 14/09/2020
  4131 0000109F 0F878806                	ja	SINGLIX_hd_format
  4132                                  
  4133                                  	;cmp	dl, 0A1h
  4134                                  	;je	SINGLIX_hd_format
  4135                                  	;jb	RUNIX386_hd_format ; dl = 071h
  4136                                  
  4137                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4138                                  ; FAT32 FORMATTING
  4139                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4140                                  	
  4141                                  	; 16/03/2021 (fdisk4.s)
  4142                                  	; 08/02/2019 (Modified for -only- FAT32 CHS partitions)
  4143                                  FAT32_hd_format:
  4144                                  	;mov	ax, 000Ch ; db 0Ch, 00h ; 'or al, 0'
  4145                                  	;cmp	dl, al ; 0Ch
  4146                                  	;je	short FAT32_lbAx_format
  4147                                  	;mov	ax, 0C00Bh ; db 0Bh, 0C0h ; 'or ax, ax'
  4148                                  ;FAT32_lba_format:
  4149                                  	; Put TRDOS 386 FAT32 partition magic word 
  4150                                  	; at offset 5Ah, in TRDOS386 FAT32 boot sector 0.
  4151 000010A3 BD[9030]                	mov	bp, TRDOS_FAT32_hd_bs
  4152 000010A6 8D7E03                  	lea	di, [bp+3]
  4153 000010A9 BE[0861]                	mov	si, bs_oem_name
  4154 000010AC B90400                  	mov	cx, 4
  4155 000010AF F3A5                    	rep	movsw 
  4156                                  	;mov	[bp+5Ah], ax	; [loc_5A]
  4157 000010B1 C7465A0BC0              	mov	word [bp+5Ah], 0C00Bh ; 08/02/2019
  4158 000010B6 A1[A23C]                	mov	ax, [sectors]
  4159 000010B9 894618                  	mov	[bp+18h], ax	; [BPB_SecPerTrk]
  4160 000010BC A1[A43C]                	mov	ax, [heads]
  4161 000010BF 89461A                  	mov	[bp+1Ah], ax	; [BPB_NumHeads]
  4162                                  	; 16/03/2021
  4163                                  	;mov	ax, [pp_StartSector]
  4164                                  	;mov	[bp+1Ch], ax	; [BPB_HiddSec]
  4165                                  	;mov	ax, [pp_StartSector+2]
  4166                                  	;mov	[bp+1Eh], ax	; [BPB_HiddSec+2]
  4167 000010C2 66A1[B869]              	mov	eax, [pp_StartSector]
  4168 000010C6 6689461C                	mov	[bp+1Ch], eax	; [BPB_HiddSec]
  4169                                  	;;mov	ax, [pp_Sectors]
  4170                                  	;mov	ax, [ppn_Sectors] ; 16/02/2019
  4171                                  	;mov	[bp+20h], ax	; [BPB_TotSec32]
  4172                                  	;;mov	dx, [pp_Sectors+2]
  4173                                  	;mov	dx, [ppn_Sectors+2] ; 16/02/2019
  4174                                  	;mov	[bp+22h], dx	; [BPB_TotSec32+2]
  4175 000010CA 66A1[F069]              	mov	eax, [ppn_Sectors]
  4176 000010CE 66894620                	mov	[bp+20h], eax	; [BPB_TotSec32]
  4177                                  	
  4178                                  	; Sectors per cluster calculation
  4179                                  	; (According to MS FAT32 FS specification.)
  4180 000010D2 B108                    	mov	cl, 8  ; 8 sectors per cluster
  4181                                  	;cmp	dx, 8  ; >= 532480 sectors
  4182                                  	;ja	short FAT32_f_2 ; 8 sectors per cluster
  4183                                  	;jb	short FAT32_f_1 ; 1 sector per cluster
  4184                                  	;cmp	ax, 2000h ; dx_ax = (8*65536)+8192
  4185                                  	;jnb	short FAT32_f_2 ; 12/09/2020 (BugFix)
  4186                                  	; 16/03/2021
  4187 000010D4 663D00200800            	cmp	eax, 532480
  4188 000010DA 7302                    	jnb	short FAT32_f_2
  4189                                  FAT32_f_1:
  4190 000010DC B101                    	mov	cl, 1	; 1 sector per cluster
  4191                                  FAT32_f_2:
  4192 000010DE 884E0D                  	mov	[bp+0Dh], cl	 ; [BPB_SecPerClus]
  4193                                  	;mov	byte [bp+10h], 2 ; [BPB_NumFATs] 
  4194                                  	;mov	word [bp+0Eh], 32 ; [BPB_RsvdSecCnt]
  4195                                  
  4196                                  	; Calculating FAT size in sectors
  4197                                  	; (According to MS FAT32 FS Specification, 2000)
  4198                                  
  4199                                  	; DX_AX = partition (volume) size in sectors
  4200                                  	;sub	ax, [bp+0Eh]	; [BPB_RsvdSecCnt] ; 32
  4201                                  	;sbb	dx, 0
  4202                                  	;	; TmpVal1 = DiskSize - (BPB_ResvdSecCnt +
  4203                                  	;	;	     		RootDirsectors)
  4204                                  	;	; RootDirSectors = 0 (for FAT32 FS)
  4205                                  	; 16/03/2021
  4206                                  	;xor	edx, edx
  4207 000010E1 8B560E                  	mov	dx, [bp+0Eh] ; [BPB_RsvdSecCnt] ; 2 bytes
  4208 000010E4 6629D0                  	sub	eax, edx ; sub eax, 32
  4209                                  		; TmpVal1 = DiskSize - (BPB_ResvdSecCnt +
  4210                                  		;	     		RootDirsectors)
  4211                                  		; RootDirSectors = 0 (for FAT32 FS)
  4212                                  
  4213                                  	;mov	bx, cx ; ch = 0
  4214                                  	;shl	bx, 8 ; * 256
  4215                                  	;mov	cl, [bp+10h] ; [BPB_NumFATs] 
  4216                                  	;add	bx, cx	
  4217                                  	;	; TmpVal2 = (256*BPB_SecPerClus)+BPB_NumFATs
  4218                                  	;shr	bx, 1
  4219                                  	;	; TmpVal2 = TmpVal2/2
  4220                                  	;mov	cx, bx
  4221                                  	;dec	bx  ; TmpVal2-1
  4222                                  	;add	ax, bx
  4223                                  	;adc	dx, 0
  4224                                  	;call	div32
  4225                                  	;	; FATSz = (TmpVal1+(TmpVal2-1))/TmpVal2
  4226                                  	; DX_AX = FAT size in sectors
  4227                                  	; 16/03/2021
  4228 000010E7 88CE                    	mov	dh, cl ; * 256
  4229 000010E9 8A5610                  	mov	dl, [bp+10h] ; [BPB_NumFATs]
  4230                                  		; TmpVal2 = (256*BPB_SecPerClus)+BPB_NumFATs
  4231 000010EC D1EA                    	shr	dx, 1
  4232                                  		; TmpVal2 = TmpVal2/2
  4233 000010EE 6689D1                  	mov	ecx, edx
  4234 000010F1 4A                      	dec	dx ; TmpVal2-1
  4235 000010F2 6601D0                  	add	eax, edx
  4236                                  	;xor	edx, edx
  4237 000010F5 31D2                    	xor	dx, dx
  4238 000010F7 66F7F1                  	div	ecx
  4239                                  		; FATSz = (TmpVal1+(TmpVal2-1))/TmpVal2
  4240                                  	; EAX = FAT size in sectors
  4241                                  
  4242                                  	;mov	[bp+24h], ax	; [BPB_FATSz32]
  4243                                  	;mov	[bp+26h], dx	; [BPB_FATSz32+2]
  4244                                  	;; * 2
  4245                                  	;mov	bx, dx
  4246                                  	;add	ax, ax
  4247                                  	;adc	bx, dx
  4248                                  	;; BX_AX = [BPB_NumFATs] * [BPB_FATSz32]
  4249                                  	;mov	cx, [bp+0Eh]	; [BPB_RsvdSecCnt] ; 32
  4250                                  	;add	cx, ax
  4251                                  	;adc	bx, 0
  4252                                  	;; BX_CX = [BPB_RsvdSecCnt]+[BPB_NumFATs]*[BPB_FATSz32]
  4253                                  	;mov	ax, [bp+20h]	; [BPB_TotSec32]
  4254                                  	;mov	dx, [bp+22h]	; [BPB_TotSec32+2]
  4255                                  	;sub	ax, cx
  4256                                  	;sbb	dx, bx
  4257                                  	;mov	[data_start], cx
  4258                                  	;mov	[data_start+2], bx
  4259                                  	;; DX_AX = Data sectors
  4260                                  	;mov	[data_sectors], ax
  4261                                  	;mov	[data_sectors+2], dx
  4262                                  	;mov	cl, [bp+0Dh]	 ; [BPB_SecPerClus]
  4263                                  	;xor	ch, ch
  4264                                  	;call	div32 ; DX_AX/CX
  4265                                  	;; DX_AX = Count of clusters (rounded down)
  4266                                  	;mov	[cluster_count], ax
  4267                                  	;mov	[cluster_count+2], dx
  4268                                  	; 16/03/2021
  4269 000010FA 66894624                	mov	[bp+24h], eax	; [BPB_FATSz32]
  4270                                  	; * 2
  4271 000010FE 66D1E0                  	shl	eax, 1
  4272                                  	;add	eax, eax
  4273                                  	;EAX = [BPB_NumFATs] * [BPB_FATSz32] ; 2 * FATsz
  4274 00001101 8B4E0E                  	mov	cx, [bp+0Eh]	; [BPB_RsvdSecCnt] ; 32
  4275 00001104 6601C1                  	add	ecx, eax
  4276                                  	;ECX = [BPB_RsvdSecCnt]+[BPB_NumFATs]*[BPB_FATSz32]
  4277 00001107 668B4620                	mov	eax, [bp+20h]	; [BPB_TotSec32]
  4278 0000110B 6629C8                  	sub	eax, ecx
  4279 0000110E 66890E[3267]            	mov	[data_start], ecx
  4280                                  	;EAX = Data sectors
  4281 00001113 66A3[3667]              	mov	[data_sectors], eax
  4282 00001117 660FB64E0D              	movzx	ecx, byte [bp+0Dh] ; [BPB_SecPerClus]
  4283 0000111C 6629D2                  	sub	edx, edx
  4284 0000111F 66F7F1                  	div	ecx
  4285                                  	;EAX = Count of clusters (rounded down)
  4286 00001122 66A3[3A67]              	mov	[cluster_count], eax
  4287 00001126 30D2                    	xor	dl, dl
  4288                                  	
  4289 00001128 8D7E47                  	lea	di, [bp+71] ; [BS_VolLab]
  4290 0000112B E84B01                  	call	write_volume_name
  4291 0000112E 8D7643                  	lea	si, [bp+67] ; [BS_VolID]
  4292 00001131 E8A401                  	call	write_volume_serial
  4293 00001134 E8B802                  	call	write_cluster_count
  4294                                  
  4295 00001137 E82502                  	call	write_formatting_msg
  4296 0000113A B000                    	mov	al, 0
  4297 0000113C E88202                  	call	write_format_percent_x
  4298                                  
  4299                                  	;mov	ax, [bp+1Ch]	; [BPB_HiddSec]
  4300                                  	;mov	dx, [bp+1Eh]	; [BPB_HiddSec+2]
  4301                                  	;add	[data_start], ax
  4302                                  	;adc	[data_start+2], dx
  4303                                  	; 16/03/2021
  4304 0000113F 668B461C                	mov	eax, [bp+1Ch]	; [BPB_HiddSec]
  4305 00001143 660106[3267]            	add	[data_start], eax 
  4306                                  FAT32_f_3:
  4307                                  	;; DX_AX = FAT32 Boot Sector address
  4308                                  	; 16/03/2021
  4309                                  	; EAX = FAT32 Boot Sector address
  4310 00001148 BB[9030]                	mov	bx, TRDOS_FAT32_hd_bs
  4311                                  	; ES:BX = Boot Sector 1 Buffer
  4312 0000114B E8C008                  	call	write_hd_sector
  4313 0000114E 0F828502                	jc	formatting_error
  4314 00001152 E83202                  	call	write_format_percent
  4315                                  	;add	ax, 1
  4316                                  	;adc	dx, 0
  4317                                  	; 16/03/2021
  4318 00001155 6640                    	inc	eax
  4319 00001157 BB[1E63]                	mov	bx, HDFORMAT_FSINFO_BUFF
  4320                                  	; ES:BX = FS INFO Sector Buffer (= BS+1)
  4321 0000115A E8B108                  	call	write_hd_sector
  4322 0000115D 0F827602                	jc	formatting_error
  4323 00001161 E82302                  	call	write_format_percent
  4324                                  	;add	ax, 1
  4325                                  	;adc	dx, 0
  4326                                  	; 16/03/2021
  4327 00001164 6640                    	inc	eax
  4328 00001166 BB[9032]                	mov	bx, TRDOS_FAT32_hd_bs + 512
  4329                                  	; ES:BX = Boot Sector 2 Buffer
  4330 00001169 E8A208                  	call	write_hd_sector
  4331 0000116C 0F826702                	jc	formatting_error
  4332 00001170 E81402                  	call	write_format_percent
  4333 00001173 B90300                  	mov	cx, 3
  4334                                  FAT32_f_4:
  4335 00001176 51                      	push	cx
  4336                                  	;add	ax, 1
  4337                                  	;adc	dx, 0
  4338                                  	; 16/03/2021
  4339 00001177 6640                    	inc	eax
  4340 00001179 BB[3265]                	mov	bx, HDFORMAT_EMPTY_BUFF
  4341 0000117C E88F08                  	call	write_hd_sector
  4342 0000117F 0F825402                	jc	formatting_error
  4343 00001183 E80102                  	call	write_format_percent
  4344 00001186 59                      	pop	cx
  4345 00001187 FEC9                    	dec	cl
  4346 00001189 75EB                    	jnz	short FAT32_f_4
  4347                                  	;add	ax, 1
  4348                                  	;adc	dx, 0
  4349                                  	; 16/03/2021
  4350 0000118B 6640                    	inc	eax
  4351                                  	;mov	cx, [bp+1Ch]	; [BPB_HiddSec]
  4352                                  	;mov	bx, [bp+1Eh]	; [BPB_HiddSec+2]
  4353                                  	;add	cx, 12
  4354                                  	;adc	bx, 0
  4355                                  	; 16/03/2021
  4356 0000118D 668B561C                	mov	edx, [bp+1Ch]	; [BPB_HiddSec]
  4357 00001191 6683C20C                	add	edx, 12
  4358                                  	; write BACKUP sectors
  4359                                  	; (6,7,8 boot+fsi and 9,10,11 empty sectors)
  4360                                  	;cmp	dx, bx
  4361                                  	;jb	short FAT32_f_3
  4362                                  	;cmp	ax, cx
  4363                                  	;jb	short FAT32_f_3
  4364                                  	; 16/03/2021
  4365 00001195 6639D0                  	cmp	eax, edx
  4366 00001198 72AE                    	jb	short FAT32_f_3	
  4367                                  
  4368                                  	; write remain part of reserved sectors
  4369 0000119A 8B4E0E                  	mov	cx, [bp+0Eh]	; [BPB_RsvdSecCnt]
  4370 0000119D 83E90C                  	sub	cx, 12
  4371 000011A0 7614                    	jna	short FAT32_f_6
  4372                                  FAT32_f_5:
  4373 000011A2 51                      	push	cx
  4374 000011A3 BB[3265]                	mov	bx, HDFORMAT_EMPTY_BUFF
  4375 000011A6 E86508                  	call	write_hd_sector
  4376 000011A9 0F822A02                	jc	formatting_error
  4377 000011AD E8D701                  	call	write_format_percent
  4378                                  	;add	ax, 1
  4379                                  	;adc	dx, 0
  4380                                  	; 16/03/2021
  4381 000011B0 6640                    	inc	eax
  4382 000011B2 59                      	pop	cx
  4383 000011B3 49                      	dec	cx
  4384 000011B4 75EC                    	jnz	short FAT32_f_5
  4385                                  FAT32_f_6:
  4386                                  	; write FAT sectors
  4387                                  	;mov	cx, [data_start] ; lba/abs addr
  4388                                  	;mov	bx, [data_start+2] ; lba/abs addr
  4389                                  	;push	bx
  4390                                  	;push	cx
  4391                                  	; 16/03/2021
  4392 000011B6 668B16[3267]            	mov	edx, [data_start]
  4393                                  	;push	edx ; *
  4394                                  	; eax = sector address
  4395 000011BB BB[3265]                	mov	bx, HDFORMAT_FATBUFFER
  4396                                  	; ES:BX = FAT Sector Buffer
  4397 000011BE 8A4E15                  	mov	cl, [bp+15h] ; [BPB_Media]
  4398 000011C1 B5FF                    	mov	ch, 0FFh
  4399 000011C3 890F                    	mov	[bx], cx
  4400 000011C5 88E9                    	mov	cl, ch ; cx = 0FFFFh
  4401 000011C7 894F02                  	mov	[bx+2], cx
  4402 000011CA 894F04                  	mov	[bx+4], cx
  4403 000011CD 894F06                  	mov	[bx+6], cx
  4404                                  	; Root dir cluster number = 2
  4405                                  	; 0FFFFFFFh = end of cluster chain
  4406 000011D0 894F08                  	mov	[bx+8], cx  ; 0FFFFh
  4407 000011D3 80E50F                  	and	ch, 0Fh
  4408 000011D6 894F0A                  	mov	[bx+10], cx ; 0FFFh
  4409                                  	;inc	cx
  4410 000011D9 E83208                  	call	write_hd_sector
  4411 000011DC 0F82F701                	jc	formatting_error
  4412 000011E0 E8A401                  	call	write_format_percent
  4413                                  	;mov	bx, HDFORMAT_FATBUFFER
  4414 000011E3 B90000                  	mov	cx, 0
  4415 000011E6 890F                    	mov	[bx], cx
  4416 000011E8 894F02                  	mov	[bx+2], cx
  4417 000011EB 894F04                  	mov	[bx+4], cx
  4418 000011EE 894F06                  	mov	[bx+6], cx
  4419 000011F1 894F08                  	mov	[bx+8], cx
  4420 000011F4 894F0A                  	mov	[bx+10], cx
  4421 000011F7 EB0D                    	jmp	short FAT32_f_8
  4422                                  FAT32_f_7:	
  4423                                  	;push	bx
  4424                                  	;push	cx
  4425                                  	; 16/03/2021
  4426                                  	;push	edx ; *
  4427 000011F9 BB[3265]                	mov	bx, HDFORMAT_FATBUFFER
  4428 000011FC E80F08                  	call	write_hd_sector
  4429 000011FF 0F82D401                	jc	formatting_error
  4430 00001203 E88101                  	call	write_format_percent
  4431                                  FAT32_f_8:	
  4432                                  	;pop	cx
  4433                                  	;pop	bx
  4434                                  	;add	ax, 1
  4435                                  	;adc	dx, 0
  4436                                  	;cmp	dx, bx
  4437                                  	;jb	short FAT32_f_7
  4438                                  	;cmp	ax, cx
  4439                                  	;jb	short FAT32_f_7
  4440                                  	; 16/03/2021
  4441                                  	;pop	edx ; *
  4442 00001206 6640                    	inc	eax ; next sector
  4443 00001208 6639D0                  	cmp	eax, edx
  4444 0000120B 72EC                    	jb	short FAT32_f_7
  4445                                  	
  4446                                  	; write	root directory (1st cluster)
  4447                                  	; as empty sectors
  4448 0000120D 8A4E0D                  	mov	cl, [bp+0Dh]	 ; [BPB_SecPerClus]
  4449 00001210 30ED                    	xor	ch, ch
  4450 00001212 290E[3667]              	sub	[data_sectors], cx
  4451 00001216 831E[3867]00            	sbb	word [data_sectors+2], 0
  4452                                  FAT32_f_9:
  4453 0000121B 51                      	push	cx
  4454 0000121C BB[3265]                	mov	bx, HDFORMAT_EMPTY_BUFF
  4455 0000121F E8EC07                  	call	write_hd_sector
  4456 00001222 0F82B101                	jc	formatting_error
  4457 00001226 E85E01                  	call	write_format_percent
  4458                                  	;add	ax, 1
  4459                                  	;adc	dx, 0
  4460                                  	; 16/03/2021
  4461 00001229 6640                    	inc	eax
  4462 0000122B 59                      	pop	cx
  4463 0000122C FEC9                    	dec	cl
  4464 0000122E 75EB                    	jnz	short FAT32_f_9
  4465                                  
  4466                                  	; write DATA sectors 
  4467                                  	; (after root directory 1st cluster)
  4468                                  	;mov	cx, [data_sectors]
  4469                                  	;mov	bx, [data_sectors+2] 
  4470                                  	;		; NOTE: Partition size must be >= 512 MB
  4471                                  	;		;	for FAT32 FS  ((BX >= 15))
  4472                                  	; 16/03/2021
  4473 00001230 668B16[3667]            	mov	edx, [data_sectors]
  4474                                  FAT32_f_10:	
  4475                                  	;push	bx
  4476                                  	;push	cx
  4477                                  	; 16/03/2021
  4478                                  	;push	edx
  4479 00001235 BB[1E61]                	mov	bx, HDFORMAT_SECBUFFER
  4480 00001238 E8D307                  	call	write_hd_sector
  4481 0000123B 0F829801                	jc	formatting_error
  4482 0000123F E84501                  	call	write_format_percent
  4483                                  	;pop	edx
  4484                                  	;pop	cx
  4485                                  	;pop	bx
  4486                                  	;add	ax, 1
  4487                                  	;adc	dx, 0
  4488 00001242 6640                    	inc	eax
  4489                                  	;dec	cx
  4490                                  	;jnz	short FAT32_f_10
  4491                                  	;dec	bx
  4492                                  	;jnz	short FAT32_f_10
  4493                                  	; 16/03/2021
  4494 00001244 664A                    	dec	edx
  4495 00001246 75ED                    	jnz	short FAT32_f_10
  4496                                  
  4497                                  	; If there are, format remain sectors which are
  4498                                  	; at beyond of data clusters, with zero bytes.
  4499                                  	
  4500                                  	;mov	cx, [bp+1Ch]	; [BPB_HiddSec]
  4501                                  	;mov	bx, [bp+1Eh]	; [BPB_HiddSec+2]
  4502                                  	; 16/03/2021
  4503 00001248 668B561C                	mov	edx, [bp+1Ch]	; [BPB_HiddSec]
  4504                                  FAT16_f_18:	
  4505                                  	;add	cx, [bp+20h]	; [BPB_TotSec32]
  4506                                  	;adc	bx, [bp+22h]	; [BPB_TotSec32+2]
  4507                                  	; 16/03/2021
  4508 0000124C 66035620                	add	edx, [bp+20h]	; [BPB_TotSec32]
  4509                                  FAT16_f_19:
  4510                                  FAT12_f_8:
  4511                                  	; are there remain sectors (in partition) ?
  4512                                  	;sub	cx, ax
  4513                                  	;sbb	bx, dx
  4514                                  	; 11/02/2019
  4515                                  	; BX must be 0 (Because, 1 cluster <= 32KB. So, 
  4516                                  	;	        remain sectors must not be more than 32K)
  4517                                  	;jnz	short FAT32_f_12 ; There is a wrong thing !!!
  4518                                  	;			 ; If BX is not zero,	
  4519                                  	;			 ; it is better to skip this stage...)
  4520                                  	;or	cx, cx
  4521                                  	;jz	short FAT32_f_12 ; no.. 
  4522                                  	;			 ; (good! FAT contains all data sectors)
  4523                                  	; 16/03/2021
  4524 00001250 6629C2                  	sub	edx, eax
  4525 00001253 7612                    	jna	short FAT32_f_12
  4526                                  FAT32_f_11:
  4527                                  	;push	cx
  4528                                  	; 16/03/2021
  4529                                  	;push	dx ; edx <= 32K
  4530 00001255 BB[3265]                	mov	bx, HDFORMAT_EMPTY_BUFF
  4531 00001258 E8B307                  	call	write_hd_sector
  4532 0000125B 0F827801                	jc	formatting_error
  4533 0000125F E82501                  	call	write_format_percent
  4534                                  	; 16/03/2021
  4535                                  	;pop	dx ; edx <= 32K
  4536                                  	;pop	cx
  4537                                  	;add	ax, 1
  4538                                  	;adc	dx, 0
  4539                                  	; 16/03/2021
  4540 00001262 6640                    	inc	eax
  4541                                  	;dec	cx
  4542 00001264 4A                      	dec	dx 
  4543 00001265 75EE                    	jnz	short FAT32_f_11
  4544                                  
  4545                                  FAT32_f_12:
  4546                                  SINGLIX_fs1_f_12:
  4547                                  	; End of FAT format routine...
  4548                                  end_of_formatting:
  4549 00001267 B064                    	mov	al, 100
  4550 00001269 E85501                  	call	write_format_percent_x
  4551                                  	;mov	si, CRLF
  4552                                  	;call	print_msg
  4553 0000126C BE[4D52]                	mov	si, Msg_OK
  4554                                  	;call	print_msg
  4555                                  	;jmp	_exit
  4556                                  	; 19/10/2020
  4557 0000126F E900F5                  	jmp	_p_exit
  4558                                  
  4559                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4560                                  ; set & write volume name
  4561                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4562                                  
  4563                                  write_fs_volume_name:
  4564 00001272 C606[0761]40            	mov	byte [vname_length], 64
  4565 00001277 EB05                    	jmp	short svn_fs
  4566                                  
  4567                                  write_volume_name:
  4568 00001279 C606[0761]0B            	mov	byte [vname_length], 11
  4569                                  svn_fs:
  4570                                  	; DI = (BS) Volume Label address
  4571 0000127E BE[EF51]                	mov	si, Msg_Volume_Name
  4572 00001281 E82C07                  	call	print_msg
  4573                                  
  4574                                  	; get cursor position
  4575                                  	; bh = 0  ; video page
  4576 00001284 B403                    	mov     ah, 3 ; get cursor pos
  4577 00001286 CD10                    	int     10h
  4578 00001288 8916[9551]              	mov	[Cursor_Pos], dx
  4579                                  
  4580 0000128C E80C08                  	call	rw_char
  4581 0000128F 7207                    	jc	short svn_1
  4582                                  svn_0:
  4583 00001291 AC                      	lodsb
  4584 00001292 3C20                    	cmp	al, 20h
  4585 00001294 7706                    	ja	short svn_2
  4586 00001296 74F9                    	je	short svn_0
  4587                                  svn_1:
  4588 00001298 BE[1261]                	mov	si, no_name
  4589 0000129B AC                      	lodsb
  4590                                  svn_2:
  4591                                  	;mov	di, [bp+47h) ; [BS_VolLab] ; FAT32
  4592                                  	;mov	di, [bp+2Bh) ; [BS_VolLab] ; FAT16 (&FAT12)
  4593 0000129C 89FB                    	mov	bx, di ; *
  4594 0000129E 30ED                    	xor	ch, ch
  4595 000012A0 8A0E[0761]              	mov	cl, [vname_length] ; 11
  4596 000012A4 EB05                    	jmp	short svn_4
  4597                                  svn_3:
  4598 000012A6 AC                      	lodsb
  4599 000012A7 3C20                    	cmp	al, 20h
  4600 000012A9 7226                    	jb	short svn_6
  4601                                  svn_4:
  4602 000012AB AA                      	stosb
  4603 000012AC E2F8                    	loop	svn_3
  4604                                  svn_5:
  4605 000012AE 8A0E[0761]              	mov	cl, [vname_length] ; 11
  4606 000012B2 89DE                    	mov	si, bx ; *
  4607 000012B4 BF[AE51]                	mov	di, StrVolumeName
  4608 000012B7 F3A4                    	rep	movsb
  4609                                  	;mov	byte [di], 0
  4610                                  
  4611 000012B9 8B16[9551]              	mov	dx, [Cursor_Pos]
  4612 000012BD BB0700                  	mov	bx, 7
  4613 000012C0 B402                    	mov	ah, 2
  4614 000012C2 CD10                    	int	10h  ; Set Cursor Position
  4615                                  
  4616 000012C4 BE[AE51]                	mov	si, StrVolumeName
  4617 000012C7 E8E606                  	call	print_msg
  4618 000012CA BE[5152]                	mov	si, CRLF
  4619 000012CD E8E006                  	call	print_msg
  4620 000012D0 C3                      	retn
  4621                                  svn_6:
  4622 000012D1 B020                    	mov	al, 20h
  4623                                  svn_7:
  4624 000012D3 AA                      	stosb
  4625 000012D4 E2FD                    	loop	svn_7
  4626 000012D6 EBD6                    	jmp	short svn_5
  4627                                  
  4628                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4629                                  ; set & write volume serial number (volume ID)
  4630                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4631                                  
  4632                                  write_volume_serial:
  4633                                  	; SI = (BS) Volume Serial Number (binary) address
  4634                                  
  4635                                  	;xor	ax, ax
  4636                                  	;int	1Ah			; get time of day
  4637                                  
  4638                                  	;mov	[si], dx
  4639                                  	;mov	[si+2], cx		; set unique volume ID
  4640                                  
  4641                                  	;mov	ah, 02h			; Return Current Time
  4642                                  	;int	1Ah
  4643                                  	;xchg	ch, cl
  4644                                  	;xchg	dh, dl
  4645                                  
  4646                                  	;add	cx, dx
  4647                                  	;add	[si+2], cx
  4648                                                 
  4649                                  	;mov	ah, 04h			; Return Current Date
  4650                                  	;int	1Ah
  4651                                  
  4652                                  	;xchg	ch,cl
  4653                                  	;xchg	dh,dl
  4654                                  
  4655                                  	;add	cx, dx
  4656                                  	;add	[si+2], cx
  4657                                  
  4658                                  	; According to Microsoft DOS 6.0 serial number
  4659                                  	; production method...
  4660                                  	; < Create unique 32 bit serial number >
  4661                                  
  4662                                  	; Create_Serial_ID (MSDOS 6.0 Source code, MSFOR.ASM)
  4663                                  	; (20/04/1987)
  4664                                  	;
  4665                                  	;  Get date (INT 21h, AH=2Bh)
  4666                                  	;  Get time (INT 21h, AH=2Ch)
  4667                                  	;  Serial_ID+0 = DX reg date + DX reg time
  4668                                  	;  Serial_ID+2 = CX reg date + CX reg time
  4669                                  	;  Serial_Num_Low = Serial_ID+2
  4670                                  	;  Serial_Num_High = Serial_ID+0
  4671                                  
  4672 000012D8 B404                    	mov	ah, 04h		; Return Current Date
  4673 000012DA CD1A                    	int	1Ah
  4674                                  
  4675                                  	; DL = Day (BCD)	(20h)
  4676                                  	; DH = Month (BCD)	(12h)
  4677                                  	; CH = Century (BCD)	(20h)
  4678                                  	; CL = Year (BCD) 	(17h)
  4679                                  
  4680 000012DC 88D0                    	mov	al, dl
  4681 000012DE E87100                  	call	bcd_to_bin
  4682 000012E1 88C2                    	mov	dl, al 
  4683 000012E3 88F0                    	mov	al, dh
  4684 000012E5 E86A00                  	call	bcd_to_bin
  4685 000012E8 88C6                    	mov	dh, al 
  4686 000012EA 88C8                    	mov	al, cl
  4687 000012EC E86300                  	call	bcd_to_bin
  4688 000012EF 88C1                    	mov	cl, al 
  4689 000012F1 88E8                    	mov	al, ch
  4690 000012F3 E85C00                  	call	bcd_to_bin
  4691 000012F6 88C5                    	mov	ch, al
  4692                                  
  4693                                  	; DH = Month (1-10)
  4694                                  	; DL = Day (1-31)
  4695                                  	; CX = Year (1900-2099)
  4696                                  
  4697 000012F8 52                      	push	dx 
  4698 000012F9 51                      	push	cx
  4699                                  
  4700 000012FA B402                    	mov	ah, 02h		; Return Current Time
  4701 000012FC CD1A                    	int	1Ah
  4702                                  	
  4703                                  	; DH = Seconds (BCD)	(59h)
  4704                                  	; CL = Minutes (BCD)	(59h)
  4705                                  	; CH = Hours (BCD)	(23h)
  4706                                  	; DL = Daylight savings time option (1=yes)
  4707                                  
  4708 000012FE 88F0                    	mov	al, dh
  4709 00001300 E84F00                  	call	bcd_to_bin
  4710 00001303 88C6                    	mov	dh, al 
  4711 00001305 88C8                    	mov	al, cl
  4712 00001307 E84800                  	call	bcd_to_bin
  4713 0000130A 88C1                    	mov	cl, al 
  4714 0000130C 88E8                    	mov	al, ch
  4715 0000130E E84100                  	call	bcd_to_bin
  4716 00001311 88C5                    	mov	ch, al 
  4717                                  
  4718                                  	; CH = Hour (0-23)
  4719                                  	; CL = Minutes (0-59)
  4720                                  	; DH = Seconds (0-59)
  4721                                  	; ((DL = Hundredths (0-99) - MSDOS!))
  4722                                  	; DL = 0 or 1 (here!)
  4723                                  
  4724 00001313 89C8                    	mov	ax, cx
  4725 00001315 59                      	pop	cx
  4726 00001316 01C8                    	add	ax, cx
  4727                                  
  4728 00001318 894402                  	mov	[si+2], ax
  4729                                  
  4730 0000131B 89D0                    	mov	ax, dx
  4731 0000131D 5A                      	pop	dx
  4732 0000131E 01D0                    	add	ax, dx
  4733                                  
  4734 00001320 8904                    	mov	[si], ax
  4735                                  
  4736 00001322 30E4                    	xor	ah, ah		; Read time counter
  4737 00001324 CD1A                    	int	1Ah
  4738                                  
  4739                                  	; CX = High word of clock count
  4740                                  	; DX = Low word of clock count
  4741                                  	; AL = 0 if 24 hours has not passed, else 1
  4742                                  
  4743                                  	; NOTES: 
  4744                                  	; (Ref: vitaly_filatov.tripod.com/ng/asm/asm_029.1.html)
  4745                                  	;
  4746                                     	; Following formulas convert the clock count to
  4747                                          ; the time of day:
  4748                                   	;	Hour      = Clock / 65543 (1007h)
  4749                                  	;	Remainder = Clock MOD 65543
  4750                                   	;
  4751                                  	;	Minutes   = Remainder / 1092 (444h)
  4752                                  	;	Remainder = Remainder MOD 1092
  4753                                  	;
  4754                                  	;	Second    = Remainder / 18.21
  4755                                  	;	Remainder = Remainder MOD 18.21
  4756                                  	;
  4757                                  	;	Hundredths = CINT(Remainder * 100)
  4758                                  
  4759 00001326 0014                    	add	[si], dl
  4760                                  
  4761                                  	; SI = Volume serial number address (4 bytes)
  4762 00001328 8A04                    	mov	al, [si]
  4763 0000132A E85707                  	call	bin_to_hex
  4764 0000132D A3[1A52]                	mov	[Vol_Serial2+2], ax
  4765 00001330 8A4401                  	mov	al, [si+1]
  4766 00001333 E84E07                  	call	bin_to_hex
  4767 00001336 A3[1852]                	mov	[Vol_Serial2], ax
  4768 00001339 8A4402                  	mov	al, [si+2]
  4769 0000133C E84507                  	call	bin_to_hex
  4770 0000133F A3[1552]                	mov	[Vol_Serial1+2], ax
  4771 00001342 8A4403                  	mov	al, [si+3]
  4772 00001345 E83C07                  	call	bin_to_hex
  4773 00001348 A3[1352]                	mov	[Vol_Serial1], ax
  4774                                  
  4775 0000134B BE[0152]                	mov	si, Msg_Volume_Serial
  4776 0000134E E85F06                  	call	print_msg
  4777                                  
  4778 00001351 C3                      	retn
  4779                                  
  4780                                  bcd_to_bin:
  4781 00001352 53                      	push	bx
  4782 00001353 D410                    	db	0D4h, 10h ; Undocumented inst. AAM
  4783                                  			  ; AH = AL / 10h
  4784                                  			  ; AL = AL MOD 10h
  4785 00001355 88C3                    	mov	bl, al
  4786 00001357 B00A                    	mov	al, 10
  4787 00001359 F6E4                    	mul	ah
  4788 0000135B 00D8                    	add	al, bl
  4789 0000135D 5B                      	pop	bx
  4790 0000135E C3                      	retn
  4791                                  
  4792                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4793                                  ; write formatting percentage
  4794                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4795                                  
  4796                                  	; 16/03/2021 (fdisk4.s)
  4797                                  write_formatting_msg:
  4798                                  	;;mov	ax, [pp_Sectors]
  4799                                  	;;mov	dx, [pp_Sectors+2]
  4800                                  	;; 16/02/2019
  4801                                  	;mov	ax, [ppn_Sectors]
  4802                                  	;mov	dx, [ppn_Sectors+2]
  4803                                  	; 16/03/2021
  4804 0000135F 66A1[F069]              	mov	eax, [ppn_Sectors] 
  4805                                  
  4806                                  	;; DX_AX = Total sectors for percentage
  4807                                  	;mov	cx, 100	
  4808                                  	;call	div32
  4809                                  	;mov	[format_percent], ax
  4810                                  	; 16/03/2021
  4811 00001363 6631D2                  	xor	edx, edx
  4812 00001366 66B964000000            	mov	ecx, 100
  4813 0000136C 66F7F1                  	div	ecx
  4814 0000136F 66A3[4067]              	mov	[format_percent], eax
  4815                                  	
  4816 00001373 BE[3952]                	mov	si, msg_formatting
  4817 00001376 E83706                  	call	print_msg
  4818                                  
  4819                                  	; get cursor position
  4820                                  	; bh = 0  ; video page
  4821 00001379 B403                    	mov     ah, 3 ; get cursor pos
  4822 0000137B CD10                    	int     10h
  4823 0000137D 8916[9551]              	mov	[Cursor_Pos], dx
  4824                                  
  4825 00001381 C606[4467]FF            	mov	byte [prev_percent], 255
  4826                                  
  4827 00001386 C3                      	retn
  4828                                  
  4829                                  	; 16/03/2021 (fdisk4.s)
  4830                                  write_format_percent:
  4831                                  	; DX_AX = Current sector (which has been written)
  4832                                  
  4833                                  	; 16/03/2021
  4834                                  	; EAX = current sector (which has been written)
  4835                                  
  4836                                  	;push	ax
  4837                                  	;push	dx
  4838                                  	; 16/03/2021
  4839 00001387 6650                    	push	eax
  4840 00001389 6652                    	push	edx
  4841 0000138B 53                      	push	bx
  4842 0000138C 51                      	push	cx
  4843 0000138D 56                      	push	si
  4844                                  
  4845                                  	;sub	ax, [bp+1Ch]	; [BPB_HiddSec]
  4846                                  	;sbb	dx, [bp+1Eh]	; [BPB_HiddSec+2]
  4847                                  	; 16/03/2021
  4848 0000138E 662B461C                	sub	eax, [bp+1Ch]	; [BPB_HiddSec]
  4849                                  wpc_t:
  4850                                  	;mov	cx, [format_percent]
  4851                                  	;call	div32
  4852                                  	; 16/03/2021
  4853 00001392 6629D2                  	sub	edx, edx
  4854 00001395 66F736[4067]            	div	dword [format_percent]
  4855                                  	; AL = percentage value between 1 to 100
  4856                                  wpc_x:
  4857 0000139A 3A06[4467]              	cmp	al, [prev_percent]
  4858 0000139E 7419                    	je	short wpc_y
  4859 000013A0 A2[4467]                	mov	[prev_percent], al
  4860 000013A3 8B16[9551]              	mov	dx, [Cursor_Pos]
  4861 000013A7 BB0700                  	mov	bx, 7
  4862 000013AA B402                    	mov	ah, 2
  4863 000013AC CD10                    	int	10h  ; Set Cursor Position
  4864                                  	;;xor	dx, dx
  4865                                  	;xor	edx, edx ; 16/03/2021
  4866 000013AE 30E4                    	xor	ah, ah
  4867                                  	;mov	al, [prev_percent]
  4868 000013B0 BE[4752]                	mov	si, format_percent_str + 2
  4869 000013B3 E8B306                  	call	bin_to_decimal
  4870 000013B6 E8F705                  	call	print_msg
  4871                                  wpc_y:
  4872 000013B9 5E                      	pop	si
  4873 000013BA 59                      	pop	cx
  4874 000013BB 5B                      	pop	bx
  4875                                  	; 16/03/2021
  4876 000013BC 665A                    	pop	edx
  4877 000013BE 6658                    	pop	eax
  4878                                  	;pop	dx
  4879                                  	;pop	ax
  4880 000013C0 C3                      	retn
  4881                                  
  4882                                  write_format_percent_x:
  4883                                  	; AL = % number
  4884                                  
  4885                                  	;push	ax
  4886                                  	;push	dx
  4887                                  	; 16/03/2021
  4888 000013C1 6650                    	push	eax
  4889 000013C3 6652                    	push	edx
  4890 000013C5 53                      	push	bx
  4891 000013C6 51                      	push	cx
  4892 000013C7 56                      	push	si
  4893                                  
  4894 000013C8 EBD0                    	jmp	short wpc_x
  4895                                  
  4896                                  write_fs_format_percent:
  4897                                  	; DX_AX = Current sector (which has been written)
  4898                                  	; 16/03/2021
  4899                                  	; EAX = Current sector
  4900                                  
  4901                                  	;push	ax
  4902                                  	;push	dx
  4903                                  	; 16/03/2021
  4904 000013CA 6650                    	push	eax
  4905 000013CC 6652                    	push	edx
  4906 000013CE 53                      	push	bx
  4907 000013CF 51                      	push	cx
  4908 000013D0 56                      	push	si
  4909                                  
  4910                                  	;sub	ax, [bp+0Ch]	; [bsBeginSector]
  4911                                  	;sbb	dx, [bp+0Eh]	; [bsBeginSector+2]
  4912                                  	; 16/03/2021
  4913 000013D1 662B460C                	sub	eax, [bp+0Ch]	; [bsBeginSector]
  4914                                  
  4915 000013D5 EBBB                    	jmp	short wpc_t
  4916                                  	
  4917                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4918                                  ; format error 
  4919                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4920                                  
  4921                                  formatting_error:
  4922 000013D7 8B26[3065]              	mov	sp, [old_sp]
  4923                                  
  4924 000013DB 88E0                    	mov	al, ah ;  error code
  4925 000013DD E8A406                  	call	bin_to_hex
  4926 000013E0 A3[5F52]                	mov 	[error_code], ax
  4927                                  
  4928 000013E3 BE[5152]                	mov	si, CRLF
  4929 000013E6 E8C705                  	call	print_msg
  4930                                  
  4931 000013E9 BE[5452]                	mov	si, Msg_Error
  4932                                  	;call	print_msg
  4933                                  	;jmp	_exit
  4934                                  	; 19/10/2020
  4935 000013EC E983F3                  	jmp	_p_exit
  4936                                  
  4937                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4938                                  ; write cluster count
  4939                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4940                                  
  4941                                  write_cluster_count:
  4942 000013EF BE[1F52]                	mov	si, msg_cluster_count
  4943 000013F2 E8BB05                  	call	print_msg
  4944                                  	;mov	ax, [cluster_count]
  4945                                  	;mov	dx, [cluster_count+2]
  4946                                  	; 16/03/2021
  4947 000013F5 66A1[3A67]              	mov	eax, [cluster_count]
  4948 000013F9 BE[3552]                	mov	si, cluster_count_str+6
  4949 000013FC E86A06                  	call	bin_to_decimal
  4950                                  	;call	print_msg
  4951                                  	;retn
  4952                                  	; 19/10/2020
  4953 000013FF E9AE05                  	jmp	print_msg 
  4954                                  
  4955                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4956                                  ; FAT16 FORMATTING
  4957                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4958                                  	
  4959                                  	; 17/03/2021 (fdisk4.s)
  4960                                  	; 08/02/2019 (Modified for -only- FAT16 CHS partitions) 
  4961                                  FAT16_hd_format:
  4962 00001402 B80607                  	mov	ax, 0706h ; db 06h, 07h ; 'push es, pop es'
  4963 00001405 38C2                    	cmp	dl, al ; 06h ; Big CHS partition (>= 32MB)
  4964 00001407 7403                    	je	short FAT16_big_chs_format
  4965                                  	;mov	ax, 070Eh ; db 0Eh, 07h	; 'push cs, pop es'
  4966                                  	;cmp	dl, al ; 0Eh ; LBA partition
  4967                                  	;je	short FAT16_lba_format
  4968                                  FAT16_chs_format:  
  4969                                  	; Partition Type: 04h, CHS (<32 MB) partition
  4970 00001409 B80400                  	mov	ax, 0004h ; db 04h, 00h ; 'add al, 0'
  4971                                  FAT16_big_chs_format:
  4972                                  ;FAT16_lba_format:
  4973                                  	; Put TRDOS 386 FAT16 partition magic word 
  4974                                  	; at offset 3Eh, in TRDOS386 FAT16 boot sector.
  4975 0000140C BD[9034]                	mov	bp, TRDOS_FAT16_hd_bs
  4976 0000140F 8D7E03                  	lea	di, [bp+3]
  4977 00001412 BE[0861]                	mov	si, bs_oem_name
  4978 00001415 B90400                  	mov	cx, 4
  4979 00001418 F3A5                    	rep	movsw 
  4980 0000141A 89463E                  	mov	[bp+3Eh], ax	; [loc_3E]
  4981                                  
  4982 0000141D A1[A23C]                	mov	ax, [sectors]
  4983 00001420 894618                  	mov	[bp+18h], ax	; [BPB_SecPerTrk]
  4984 00001423 A1[A43C]                	mov	ax, [heads]
  4985 00001426 89461A                  	mov	[bp+1Ah], ax	; [BPB_NumHeads]
  4986 00001429 A1[B869]                	mov	ax, [pp_StartSector]
  4987 0000142C 89461C                  	mov	[bp+1Ch], ax	; [BPB_HiddSec]
  4988 0000142F A1[BA69]                	mov	ax, [pp_StartSector+2]
  4989 00001432 89461E                  	mov	[bp+1Eh], ax	; [BPB_HiddSec+2]
  4990                                  	
  4991                                  	;;mov	ax, [pp_Sectors]
  4992                                  	;mov	ax, [ppn_Sectors] ; 16/02/2019
  4993                                  	;;mov	dx, [pp_Sectors+2]
  4994                                  	;mov	dx, [ppn_Sectors+2] ; 16/02/2019
  4995                                  	;and	dx, dx
  4996                                  	;jnz	short FAT16_f_0
  4997                                  	; 17/03/2021
  4998 00001435 66A1[F069]              	mov	eax,[ppn_Sectors]
  4999 00001439 663D00000100            	cmp	eax, 65536
  5000 0000143F 7305                    	jnb	short FAT16_f_0
  5001                                  
  5002 00001441 894613                  	mov	[bp+13h], ax	; [BPB_TotSec16]
  5003                                  	; CX = 0
  5004                                  	;mov	[bp+20h], cx	; [BPB_TotSec32] =  0
  5005                                  	;mov	[bp+22h], cx	; [BPB_TotSec32+2] = 0
  5006 00001444 EB04                    	jmp	short FAT16_f_1
  5007                                  FAT16_f_0:
  5008                                  	;mov	[bp+20h], ax	; [BPB_TotSec32]
  5009                                  	;;;mov	dx, [pp_Sectors+2]
  5010                                  	;;mov	dx, [ppn_Sectors+2] ; 16/02/2019 
  5011                                  	;mov	[bp+22h], dx	; [BPB_TotSec32+2]
  5012                                  	;; CX = 0
  5013                                  	;;mov	[bp+13h], cx ; [BPB_TotSec16] = 0
  5014                                  	; 17/03/2021
  5015 00001446 66894620                	mov	[bp+20h], eax	; [BPB_TotSec32]
  5016                                  FAT16_f_1:
  5017                                  	; Sectors per cluster calculation
  5018                                  	; (According to MS FAT32 FS specification.)
  5019 0000144A B102                    	mov	cl, 2  ; 2 sectors per cluster
  5020                                  	; 17/03/2021
  5021 0000144C 6689C2                  	mov	edx, eax
  5022 0000144F 66C1EA10                	shr	edx, 16
  5023 00001453 7507                    	jnz	short FAT16_f_2 ; >2 sectors (>16MB)
  5024                                  	;or	dx, dx
  5025                                  	;jnz	short FAT16_f_2 ; >2 sectors (>16MB)
  5026 00001455 3DA87F                  	cmp	ax, 32680
  5027 00001458 763C                    	jna	short FAT16_f_10 ; 2 sectors, <=16MB
  5028                                  	; > 16MB
  5029 0000145A EB38                    	jmp	short FAT16_f_9 ; 4 sectors per cluster
  5030                                  FAT16_f_2:
  5031 0000145C 83FA04                  	cmp	dx, 4  ; >= 262144 sectors ; >=128MB
  5032 0000145F 7708                    	ja	short FAT16_f_3 ; >4 sectors per cluster
  5033 00001461 7231                    	jb	short FAT16_f_9 ; 4 sectors per cluster	
  5034 00001463 09C0                    	or	ax, ax ; dx_ax = (4*65536)+0
  5035 00001465 742D                    	jz	short FAT16_f_9 ; 4 sectors per cluster
  5036 00001467 EB29                    	jmp	short FAT16_f_8 ; 8 sectors per cluster
  5037                                  FAT16_f_3:
  5038 00001469 83FA08                  	cmp	dx, 8  ; >= 524288 sectors ; >=256MB
  5039 0000146C 7708                    	ja	short FAT16_f_4 ; >8 sectors per cluster
  5040 0000146E 7222                    	jb	short FAT16_f_8 ; 8 sectors per cluster	
  5041 00001470 21C0                    	and	ax, ax ; dx_ax = (8*65536)+0
  5042 00001472 741E                    	jz	short FAT16_f_8 ; 8 sectors per cluster
  5043 00001474 EB1A                    	jmp	short FAT16_f_7 ; 16 sectors per cluster
  5044                                  FAT16_f_4:
  5045 00001476 83FA10                  	cmp	dx, 16 ; >= 1048576 sectors ; >=512MB
  5046 00001479 7708                    	ja	short FAT16_f_5 ; >16 sectors per cluster
  5047 0000147B 7213                    	jb	short FAT16_f_7 ; 16 sectors per cluster
  5048 0000147D 21C0                    	and	ax, ax ; dx_ax = (16*65536)+0
  5049 0000147F 740F                    	jz	short FAT16_f_7 ; 16 sectors per cluster
  5050 00001481 EB0B                    	jmp	short FAT16_f_6 ; 32 sectors per cluster
  5051                                  FAT16_f_5:
  5052 00001483 83FA20                  	cmp	dx, 32 ; >= 2097152 sectors ; >=1GB
  5053 00001486 7206                    	jb	short FAT16_f_6 ; 32 sectors per cluster
  5054 00001488 09C0                    	or	ax, ax		; dx_ax = (32*65536)+0
  5055 0000148A 7402                    	jz	short FAT16_f_6 ; 32 sectors per cluster
  5056                                  	; >1GB (<=2GB)
  5057                                  	; 64 sectors per cluster
  5058 0000148C D0E1                    	shl	cl, 1
  5059                                  FAT16_f_6:
  5060                                  	; 32 sectors per cluster (for <= 2GB volumes)
  5061 0000148E D0E1                    	shl	cl, 1	
  5062                                  FAT16_f_7:
  5063                                  	; 16 sectors per cluster (for <= 1GB volumes)
  5064 00001490 D0E1                    	shl	cl, 1
  5065                                  FAT16_f_8:
  5066                                  	; 8 sectors per cluster (for <= 512MB volumes)
  5067 00001492 D0E1                    	shl	cl, 1	
  5068                                  FAT16_f_9:
  5069                                  	; 4 sectors per cluster (for <= 256MB volumes)
  5070 00001494 D0E1                    	shl	cl, 1	
  5071                                  FAT16_f_10:	
  5072                                  	; 2 sectors per cluster (for <= 128MB volumes)
  5073 00001496 884E0D                  	mov	[bp+0Dh], cl	 ; [BPB_SecPerClus]
  5074                                  	;mov	byte [bp+10h], 2 ; [BPB_NumFATs] 
  5075                                  	;mov	word [bp+0Eh], 1 ; [BPB_RsvdSecCnt] 
  5076                                  	;mov	word [bp+11h], 512 ; [BPB_RootEntCnt]
  5077                                  	
  5078                                  	; Calculating FAT size in sectors
  5079                                  	; (According to MS FAT32 FS Specification, 2000)
  5080                                  
  5081                                  	; DX_AX = partition (volume) size in sectors
  5082                                  	;mov	bx, [bp+11h]	; [BPB_RootEntCnt] = 512
  5083                                  	;add	bx, 15 ; bx = 527
  5084                                  	;shr	bx, 4 ; /16 = 527/16 = 32
  5085                                  	;	; ((32*BX)+511)/512
  5086                                  	;mov	[root_dir_secs], bx
  5087                                  	;add	bx, [bp+0Eh]	; [BPB_RsvdSecCnt] ; 1
  5088                                  	;sub	ax, bx
  5089                                  	;sbb	dx, 0
  5090                                  	;	; TmpVal1 = DiskSize - (BPB_ResvdSecCnt +
  5091                                  	;	;	     		RootDirsectors)
  5092                                  	; 17/03/2021
  5093 00001499 8B5611                  	mov	dx, [bp+11h]	; [BPB_RootEntCnt] = 512
  5094 0000149C 83C20F                  	add	dx, 15 ; DX = 527
  5095 0000149F C1EA04                  	shr	dx, 4 ; /16 = 527/16 = 32
  5096                                  		; ((32*DX)+511)/512
  5097 000014A2 8916[3E67]              	mov	[root_dir_secs], dx
  5098 000014A6 03560E                  	add	dx, [bp+0Eh]	; [BPB_RsvdSecCnt] ; 1
  5099 000014A9 6629D0                  	sub	eax, edx
  5100                                  		; TmpVal1 = DiskSize - (BPB_ResvdSecCnt +
  5101                                  		;	     		RootDirsectors)
  5102                                  	
  5103                                  	;;mov	bx, cx ; ch = 0
  5104                                  	;;shl	bx, 8 ; * 256
  5105                                  	;; 11/02/2019
  5106                                  	;mov	bh, cl
  5107                                  	;xor	bl, bl
  5108                                  	;mov	cl, 2 ; [BPB_NumFATs]
  5109                                  	;add	bx, cx	
  5110                                  	;	; TmpVal2 = (256*BPB_SecPerClus)+BPB_NumFATs
  5111                                  	;mov	cx, bx
  5112                                  	;dec	bx  ; TmpVal2-1
  5113                                  	;add	ax, bx
  5114                                  	;adc	dx, 0
  5115                                  	;call	div32
  5116                                  	;	; FATSz = (TmpVal1+(TmpVal2-1))/TmpVal2
  5117                                  	;; AX = FAT size in sectors
  5118                                  	;; DX = 0
  5119                                  	;mov	[bp+16h], ax	; [BPB_FATSz16]
  5120                                  	; 17/03/2021
  5121 000014AC 88CE                    	mov	dh, cl ; * 256
  5122                                  	;mov	dl, [bp+10h] ; [BPB_NumFATs] 
  5123 000014AE B202                    	mov	dl, 2 ; [BPB_NumFATs]
  5124                                  		; TmpVal2 = (256*BPB_SecPerClus)+BPB_NumFATs 
  5125 000014B0 6689D3                  	mov	ebx, edx
  5126 000014B3 4A                      	dec	dx ; TmpVal2-1
  5127 000014B4 6601D0                  	add	eax, edx
  5128 000014B7 31D2                    	xor	dx, dx
  5129 000014B9 66F7F3                  	div	ebx
  5130                                  		; FATSz = (TmpVal1+(TmpVal2-1))/TmpVal2
  5131                                  	; EAX = FAT size in sectors (<= 256)
  5132                                  	; * 2
  5133 000014BC D1E0                    	shl	ax, 1
  5134                                  	; AX = [BPB_NumFATs] * [BPB_FATSz16]
  5135                                  	;mov	cx, [bp+0Eh]	; [BPB_RsvdSecCnt] ; 1
  5136                                  	;add	cx, ax
  5137                                  	; 17/03/2021
  5138 000014BE 8B560E                  	mov	dx, [bp+0Eh]	; [BPB_RsvdSecCnt] ; 1
  5139 000014C1 01C2                    	add	dx, ax
  5140                                  	; CX = [BPB_RsvdSecCnt]+([BPB_NumFATs]*[BPB_FATSz16])
  5141                                  	;add	cx, [root_dir_secs] ; + RootDirsectors
  5142                                  	;sub	bx, bx ; BX = 0
  5143 000014C3 0316[3E67]              	add	dx, [root_dir_secs] ; + RootDirsectors
  5144                                  	; BX_CX = [BPB_RsvdSecCnt]+([BPB_NumFATs]*[BPB_FATSz16])
  5145                                  	;	  + RootDirSectors
  5146 000014C7 8B4613                  	mov	ax, [bp+13h]	; [BPB_TotSec16]
  5147                                  	;sub	dx, dx 
  5148                                  	; DX = 0
  5149 000014CA 21C0                    	and	ax, ax
  5150 000014CC 7504                    	jnz	short FAT16_f_11
  5151                                  	;mov	ax, [bp+20h]	; [BPB_TotSec32]
  5152                                  	;mov	dx, [bp+22h]	; [BPB_TotSec32+2]
  5153 000014CE 668B4620                	mov	eax, [bp+20h]	; [BPB_TotSec32]
  5154                                  FAT16_f_11:
  5155                                  	;sub	ax, cx
  5156                                  	;sbb	dx, bx
  5157                                  	; 17/03/2021
  5158                                  	; EAX = Total Sectors
  5159                                  	; EDX = [BPB_RsvdSecCnt]+([BPB_NumFATs]*[BPB_FATSz16])
  5160                                  	;	+ RootDirSectors
  5161 000014D2 6629D0                  	sub	eax, edx
  5162                                  	;mov	[data_start], cx
  5163                                  	;mov	[data_start+2], bx
  5164 000014D5 668916[3267]            	mov	[data_start], edx
  5165                                  	; DX_AX = Data sectors
  5166                                  	;mov	[data_sectors], ax
  5167                                  	;mov	[data_sectors+2], dx
  5168 000014DA 66A3[3667]              	mov	[data_sectors], eax
  5169 000014DE 31D2                    	xor	dx, dx
  5170                                  	;mov	cl, [bp+0Dh]	 ; [BPB_SecPerClus]
  5171                                  	;xor	ch, ch
  5172                                  	;call	div32 ; DX_AX/CX
  5173                                  	;; AX = Count of clusters (rounded down)
  5174                                  	;; DX = 0
  5175 000014E0 8A5E0D                  	mov	bl, [bp+0Dh]	 ; [BPB_SecPerClus]
  5176 000014E3 30FF                    	xor	bh, bh
  5177 000014E5 66F7F3                  	div	ebx
  5178                                  	; AX = Count of clusters (rounded down)
  5179                                  	; (eax <= 65528)
  5180                                  
  5181                                  	;mov	[cluster_count], ax
  5182                                  	;mov	[cluster_count+2], dx
  5183 000014E8 66A3[3A67]              	mov	[cluster_count], eax
  5184                                  
  5185 000014EC 8D7E2B                  	lea	di, [bp+43] ; [BS_VolLab]
  5186 000014EF E887FD                  	call	write_volume_name
  5187 000014F2 8D7627                  	lea	si, [bp+39] ; [BS_VolID]
  5188 000014F5 E8E0FD                  	call	write_volume_serial
  5189 000014F8 E8F4FE                  	call	write_cluster_count
  5190                                  
  5191 000014FB E861FE                  	call	write_formatting_msg
  5192 000014FE B000                    	mov	al, 0
  5193 00001500 E8BEFE                  	call	write_format_percent_x
  5194                                  
  5195                                  	;mov	ax, [bp+1Ch]	; [BPB_HiddSec]
  5196                                  	;mov	dx, [bp+1Eh]	; [BPB_HiddSec+2]
  5197 00001503 668B461C                	mov	eax, [bp+1Ch]	; [BPB_HiddSec]
  5198                                  
  5199                                  	;add	[data_start], ax
  5200                                  	;adc	[data_start+2], dx
  5201 00001507 660106[3267]            	add	[data_start], eax
  5202                                  	;sub	dx, dx ; edx = 0
  5203                                  
  5204                                  	; DX_AX = FAT16 Boot Sector address
  5205 0000150C BB[9034]                	mov	bx, TRDOS_FAT16_hd_bs
  5206                                  	; ES:BX = Boot Sector Buffer
  5207 0000150F E8FC04                  	call	write_hd_sector
  5208 00001512 0F82C1FE                	jc	formatting_error
  5209 00001516 E86EFE                  	call	write_format_percent
  5210                                  	;add	ax, 1
  5211                                  	;adc	dx, 0
  5212                                  	; 17/03/2021
  5213 00001519 6640                    	inc	eax
  5214                                  	; write remain part of reserved sectors
  5215 0000151B 8B4E0E                  	mov	cx, [bp+0Eh] ; [BPB_RsvdSecCnt]
  5216                                  	;sub	cx, 1
  5217                                  	;jna	short FAT16_f_13
  5218                                  	; 11/02/2019
  5219 0000151E 49                      	dec	cx
  5220 0000151F 7414                    	jz	short FAT16_f_13
  5221                                  FAT16_f_12:
  5222 00001521 51                      	push	cx
  5223 00001522 BB[3265]                	mov	bx, HDFORMAT_EMPTY_BUFF
  5224 00001525 E8E604                  	call	write_hd_sector
  5225 00001528 0F82ABFE                	jc	formatting_error
  5226 0000152C E858FE                  	call	write_format_percent
  5227                                  	;add	ax, 1
  5228                                  	;adc	dx, 0
  5229                                  	; 17/03/2021
  5230 0000152F 6640                    	inc	eax
  5231 00001531 59                      	pop	cx
  5232 00001532 49                      	dec	cx ; dec cl
  5233 00001533 75EC                    	jnz	short FAT16_f_12
  5234                                  FAT16_f_13:
  5235                                  	; write FAT sectors
  5236                                  	;mov	cx, [data_start] ; lba/abs addr
  5237                                  	;mov	bx, [data_start+2] ; lba/abs addr
  5238                                  	; 17/03/2021	
  5239 00001535 668B16[3267]            	mov	edx, [data_start]
  5240                                  
  5241                                  	; 11/02/2019
  5242                                  	;sub	cx, [root_dir_secs]
  5243                                  	;sbb	bx, 0
  5244                                  	; 17/03/2021	
  5245 0000153A 8B1E[3E67]              	mov	bx, [root_dir_secs]
  5246 0000153E 6629DA                  	sub	edx, ebx 
  5247                                  	;push	edx  ; *
  5248                                  
  5249                                  	;push	bx
  5250                                  	;push	cx
  5251 00001541 BB[3265]                	mov	bx, HDFORMAT_FATBUFFER
  5252                                  	; ES:BX = FAT Sector Buffer
  5253 00001544 8A4E15                  	mov	cl, [bp+15h] ; [BPB_Media]
  5254 00001547 B5FF                    	mov	ch, 0FFh
  5255 00001549 890F                    	mov	[bx], cx ; 0FFF8h
  5256 0000154B 88E9                    	mov	cl, ch ; cx = 0FFFFh
  5257 0000154D 894F02                  	mov	[bx+2], cx
  5258                                  	;inc	cx
  5259 00001550 E8BB04                  	call	write_hd_sector
  5260 00001553 0F8280FE                	jc	formatting_error
  5261 00001557 E82DFE                  	call	write_format_percent
  5262                                  	;mov	bx, HDFORMAT_FATBUFFER
  5263 0000155A B90000                  	mov	cx, 0
  5264 0000155D 890F                    	mov	[bx], cx
  5265 0000155F 894F02                  	mov	[bx+2], cx
  5266 00001562 EB0D                    	jmp	short FAT16_f_15
  5267                                  FAT16_f_14:	
  5268                                  	;push	bx
  5269                                  	;push	cx
  5270                                  	; 17/03/2021
  5271                                  	; push	edx ; *
  5272 00001564 BB[3265]                	mov	bx, HDFORMAT_FATBUFFER
  5273 00001567 E8A404                  	call	write_hd_sector
  5274 0000156A 0F8269FE                	jc	formatting_error
  5275 0000156E E816FE                  	call	write_format_percent
  5276                                  FAT16_f_15:	
  5277                                  	;pop	cx
  5278                                  	;pop	bx
  5279                                  	; 17/03/2021
  5280                                  	;pop	edx ; *
  5281                                  	;add	ax, 1
  5282                                  	;adc	dx, 0
  5283 00001571 6640                    	inc	eax
  5284                                  	;cmp	dx, bx
  5285                                  	;jb	short FAT16_f_14
  5286                                  	;cmp	ax, cx
  5287                                  	;jb	short FAT16_f_14
  5288 00001573 6639D0                  	cmp	eax, edx
  5289 00001576 72EC                    	jb	short FAT16_f_14
  5290                                  
  5291                                  	; write	root directory sectors
  5292                                  	; as empty sectors
  5293 00001578 8B0E[3E67]              	mov	cx, [root_dir_secs]
  5294                                  FAT16_f_16:
  5295 0000157C 51                      	push	cx
  5296 0000157D BB[3265]                	mov	bx, HDFORMAT_EMPTY_BUFF
  5297 00001580 E88B04                  	call	write_hd_sector
  5298 00001583 0F8250FE                	jc	formatting_error
  5299 00001587 E8FDFD                  	call	write_format_percent
  5300                                  	;add	ax, 1
  5301                                  	;adc	dx, 0
  5302                                  	; 17/03/2021
  5303 0000158A 6640                    	inc	eax
  5304 0000158C 59                      	pop	cx
  5305 0000158D 49                      	dec	cx
  5306 0000158E 75EC                    	jnz	short FAT16_f_16
  5307                                  
  5308                                  	; write DATA sectors 
  5309                                  	; (after root directory sectors)
  5310                                  	;mov	cx, [data_sectors]
  5311                                  	;mov	bx, [data_sectors+2]
  5312                                  	; 17/03/2021
  5313 00001590 668B16[3667]            	mov	edx, [data_sectors]
  5314                                  	; 11/02/2019
  5315 00001595 43                      	inc	bx ; 0 -> 1, 1-> 2
  5316                                  FAT16_f_17:	
  5317                                  	;push	bx
  5318                                  	;push	cx
  5319                                  	; 17/03/2021
  5320                                  	;push	edx ; **
  5321 00001596 BB[1E61]                	mov	bx, HDFORMAT_SECBUFFER
  5322 00001599 E87204                  	call	write_hd_sector
  5323 0000159C 0F8237FE                	jc	formatting_error
  5324 000015A0 E8E4FD                  	call	write_format_percent
  5325                                  	; 17/03/2021
  5326 000015A3 665A                    	pop	edx ;**
  5327                                  	;pop	cx
  5328                                  	;pop	bx
  5329                                  	;add	ax, 1
  5330                                  	;adc	dx, 0
  5331 000015A5 6640                    	inc	eax
  5332                                  	;dec	cx
  5333                                  	;jnz	short FAT16_f_17
  5334                                  	;dec	bx
  5335                                  	;jnz	short FAT16_f_17
  5336                                  	; 17/03/2021
  5337 000015A7 664A                    	dec	edx
  5338 000015A9 75EB                    	jnz	short FAT16_f_17
  5339                                  
  5340                                  	; If there are, format remain sectors which are
  5341                                  	; at beyond of data clusters, with zero bytes.
  5342                                  	
  5343                                  	;mov	cx, [bp+1Ch]	; [BPB_HiddSec]
  5344                                  	;mov	bx, [bp+1Eh]	; [BPB_HiddSec+2]
  5345                                  	; 17/03/2021
  5346 000015AB 668B561C                	mov	edx, [bp+1Ch]	; [BPB_HiddSec]
  5347                                  	;movzx	ebx, word [bp+13h] ; [BPB_TotSec16]
  5348 000015AF 8B5E13                  	mov	bx, [bp+13h] ; [BPB_TotSec16]
  5349                                  
  5350                                  	;cmp	word [bp+13h], 0 ; [BPB_TotSec16]
  5351 000015B2 09DB                    	or	bx, bx	; 17/03/2021
  5352 000015B4 0F8494FC                	jz	FAT16_f_18
  5353                                  	;add	cx, [bp+13h]	; [BPB_TotSec16]
  5354                                  	;adc	bx, 0
  5355                                  	; 17/03/2021
  5356 000015B8 6601DA                  	add	edx, ebx
  5357 000015BB E992FC                  	jmp	FAT16_f_19
  5358                                  
  5359                                  	; 17/03/2021 (fdisk4.s)
  5360                                  FAT12_hd_format:
  5361 000015BE BD[9036]                	mov	bp, TRDOS_FAT12_hd_bs
  5362 000015C1 8D7E03                  	lea	di, [bp+3]
  5363 000015C4 BE[0861]                	mov	si, bs_oem_name
  5364 000015C7 B90400                  	mov	cx, 4
  5365 000015CA F3A5                    	rep	movsw 
  5366 000015CC A1[A23C]                	mov	ax, [sectors]
  5367 000015CF 894618                  	mov	[bp+18h], ax	; [BPB_SecPerTrk]
  5368 000015D2 A1[A43C]                	mov	ax, [heads]
  5369 000015D5 89461A                  	mov	[bp+1Ah], ax	; [BPB_NumHeads]
  5370                                  
  5371                                  	;mov	ax, [pp_StartSector]
  5372                                  	;mov	[bp+1Ch], ax	; [BPB_HiddSec]
  5373                                  	;mov	ax, [pp_StartSector+2]
  5374                                  	;mov	[bp+1Eh], ax	; [BPB_HiddSec+2]
  5375                                  	; 17/03/2021
  5376 000015D8 66A1[B869]              	mov	eax, [pp_StartSector]
  5377 000015DC 6689461C                	mov	[bp+1Ch], eax	; [BPB_HiddSec]
  5378                                  
  5379                                  	;mov	ax, [pp_Sectors]
  5380 000015E0 A1[F069]                	mov	ax, [ppn_Sectors] ; 16/02/2019
  5381 000015E3 894613                  	mov	[bp+13h], ax	; [BPB_TotSec16]
  5382                                  
  5383                                  	; 11/02/2019
  5384 000015E6 31F6                    	xor	si, si ; reset (FAT size fix) flag
  5385 000015E8 8B4E0E                  	mov	cx, [bp+0Eh]	; [BPB_RsvdSecCnt] ; 1
  5386 000015EB 8B5611                  	mov	dx, [bp+11h]	; [BPB_RootEntCnt] = 512
  5387 000015EE 83C20F                  	add	dx, 15	; (16-1) (512-1)
  5388 000015F1 C1EA04                  	shr	dx, 4	; /16  (*32/512)
  5389                                  	; AX = Root dir sectors
  5390                                  	; CX = [BPB_RsvdSecCnt]+([BPB_NumFATs]*[BPB_FATSz16])
  5391 000015F4 01D1                    	add	cx, dx ; + RootDirsectors ; + 32
  5392 000015F6 890E[3E67]              	mov	[root_dir_secs], cx ; = 33
  5393                                  
  5394                                  	; 11/02/2019
  5395                                  	;sub	ax, 33  ; 1 reserved sector, 32 root dir sectors
  5396                                  			; .. now AX has number of data sectors
  5397                                  			;	 		+ 2* (FAT sectors)
  5398 000015FA 29C8                    	sub	ax, cx
  5399                                  FAT12_f_10:	; 11/02/2019
  5400                                  	; Sectors per cluster calculation
  5401                                  	; (According to MS FAT32 FS specification.)
  5402                                  	;mov	cx, 1  ; 1 sector per cluster
  5403 000015FC B101                    	mov	cl, 1  ; CH = 0
  5404                                  FAT12_f_0:
  5405 000015FE 3DF50F                  	cmp	ax, 4085 ; Max. cluster count for FAT12
  5406 00001601 7206                    	jb	short FAT12_f_1
  5407 00001603 D0E1                    	shl	cl, 1 ; *2
  5408 00001605 D1E8                    	shr	ax, 1 ; /2
  5409 00001607 EBF5                    	jmp	short FAT12_f_0
  5410                                  FAT12_f_1:
  5411 00001609 884E0D                  	mov	[bp+0Dh], cl	 ; [BPB_SecPerClus]
  5412                                  	;mov	byte [bp+10h], 2 ; [BPB_NumFATs] 
  5413                                  	;mov	word [bp+0Eh], 1 ; [BPB_RsvdSecCnt] 
  5414                                  	;mov	word [bp+11h], 512 ; [BPB_RootEntCnt]
  5415                                  	
  5416                                  	; Calculating FAT size in sectors
  5417                                  	; AX = partition (volume) size in sectors
  5418                                  	; CX = sectors per clusters
  5419 0000160C 31D2                    	xor	dx, dx
  5420 0000160E F7F1                    	div	cx
  5421                                  	; AX = cluster count (only for FAT size calc)
  5422                                  	; DX = 0
  5423 00001610 83C002                  	add	ax, 2  ; cluster 2 to ...
  5424 00001613 89C2                    	mov	dx, ax
  5425 00001615 D1E2                    	shl	dx, 1
  5426 00001617 01D0                    	add	ax, dx ; *3
  5427 00001619 D1E8                    	shr	ax, 1  ; /2
  5428 0000161B 83D000                  	adc	ax, 0  ; +0.5 -> +1
  5429                                  
  5430                                  	; AX = FAT bytes for 12 bit cluster numbers
  5431                                  	
  5432 0000161E B90002                  	mov	cx, 512		; [BPB_BytesPerSec]
  5433 00001621 01C8                    	add	ax, cx		
  5434 00001623 48                      	dec	ax		; [BPB_BytesPerSec] - 1
  5435 00001624 29D2                    	sub	dx, dx
  5436 00001626 F7F1                    	div	cx
  5437 00001628 894616                  	mov	[bp+16h], ax	; [BPB_FATSz16]
  5438                                  	; * 2
  5439 0000162B D1E0                    	shl	ax, 1
  5440                                  	; AX = [BPB_NumFATs] * [BPB_FATSz16]
  5441                                  
  5442                                  	;mov	cx, [bp+0Eh]	; [BPB_RsvdSecCnt] ; 1
  5443                                  	;add	cx, ax
  5444                                  	;mov	ax, [bp+11h]	; [BPB_RootEntCnt] = 512
  5445                                  	;add	ax, 15	; (16-1) (512-1)
  5446                                  	;shr	ax, 4	; /16  (*32/512)
  5447                                  	;; AX = Root dir sectors
  5448                                  	;; CX = [BPB_RsvdSecCnt]+([BPB_NumFATs]*[BPB_FATSz16])
  5449                                  	;add	cx, ax ; + RootDirsectors
  5450                                  	;mov	[root_dir_secs], ax
  5451                                  
  5452                                  	; 11/02/2019
  5453                                  	;mov	cx, 33
  5454 0000162D 8B0E[3E67]              	mov	cx, [root_dir_secs]
  5455 00001631 034E0E                  	add	cx, [bp+0Eh]	; [BPB_RsvdSecCnt] ; 1
  5456                                  		; cx = root directory sectors + reserved sectors
  5457 00001634 01C1                    	add	cx, ax
  5458                                  	; CX = [BPB_RsvdSecCnt]+([BPB_NumFATs]*[BPB_FATSz16])
  5459                                  	;	  + RootDirSectors
  5460                                  
  5461                                  	; 17/03/2021
  5462 00001636 6631C0                  	xor	eax, eax
  5463                                  
  5464 00001639 8B4613                  	mov	ax, [bp+13h]	; [BPB_TotSec16]
  5465 0000163C 29C8                    	sub	ax, cx
  5466                                  		 ; AX = data sectors
  5467                                  		 ; cH = 0
  5468                                  
  5469                                  	; 11/02/2019 - fix FAT size (better method)
  5470 0000163E 09F6                    	or	si, si
  5471 00001640 7504                    	jnz	short FAT12_f_9
  5472                                  
  5473 00001642 89C6                    	mov	si, ax  ; ax = data sectors
  5474 00001644 EBB6                    	jmp	short FAT12_f_10
  5475                                  
  5476                                  FAT12_f_9:
  5477 00001646 31D2                    	xor	dx, dx
  5478 00001648 890E[3267]              	mov	[data_start], cx
  5479 0000164C 8916[3467]              	mov	[data_start+2], dx ; 0
  5480                                  	; DX_AX = Data sectors
  5481                                  	;mov	[data_sectors], ax
  5482                                  	;mov	[data_sectors+2], dx ; 0
  5483                                  	; 17/03/2021
  5484 00001650 66A3[3667]              	mov	[data_sectors], eax
  5485 00001654 8A4E0D                  	mov	cl, [bp+0Dh]	 ; [BPB_SecPerClus]
  5486 00001657 28ED                    	sub	ch, ch
  5487 00001659 F7F1                    	div	cx
  5488                                  	; AX = Count of clusters (rounded down)
  5489 0000165B 29D2                    	sub	dx, dx ; 0
  5490 0000165D A3[3A67]                	mov	[cluster_count], ax
  5491 00001660 8916[3C67]              	mov	[cluster_count+2], dx ; 0
  5492                                  
  5493 00001664 8D7E2B                  	lea	di, [bp+43] ; [BS_VolLab]
  5494 00001667 E80FFC                  	call	write_volume_name
  5495 0000166A 8D7627                  	lea	si, [bp+39] ; [BS_VolID]
  5496 0000166D E868FC                  	call	write_volume_serial
  5497 00001670 E87CFD                  	call	write_cluster_count
  5498                                  
  5499 00001673 E8E9FC                  	call	write_formatting_msg
  5500 00001676 B000                    	mov	al, 0
  5501 00001678 E846FD                  	call	write_format_percent_x
  5502                                  
  5503                                  	;mov	ax, [bp+1Ch]	; [BPB_HiddSec]
  5504                                  	;mov	dx, [bp+1Eh]	; [BPB_HiddSec+2]
  5505                                  	; 17/03/2021
  5506 0000167B 668B461C                	mov	eax, [bp+1Ch]	; [BPB_HiddSec]
  5507                                  
  5508                                  	;add	[data_start], ax
  5509                                  	;adc	[data_start+2], dx
  5510                                  	; 17/03/2021
  5511 0000167F 660106[3267]            	add	[data_start], eax
  5512                                  
  5513                                  	; DX_AX = FAT12 Boot Sector address
  5514 00001684 BB[9036]                	mov	bx, TRDOS_FAT12_hd_bs
  5515                                  	; ES:BX = Boot Sector Buffer
  5516 00001687 E88403                  	call	write_hd_sector
  5517 0000168A 0F8249FD                	jc	formatting_error
  5518 0000168E E8F6FC                  	call	write_format_percent
  5519                                  	;add	ax, 1
  5520                                  	;adc	dx, 0
  5521                                  	; 17/03/2021
  5522 00001691 6640                    	inc	eax
  5523                                  	; write remain part of reserved sectors
  5524 00001693 8B4E0E                  	mov	cx, [bp+0Eh] ; [BPB_RsvdSecCnt]
  5525                                  	;sub	cx, 1
  5526                                  	;jna	short FAT12_f_3
  5527                                  	; 11/02/2019
  5528 00001696 49                      	dec	cx
  5529 00001697 7414                    	jz	short FAT12_f_3
  5530                                  FAT12_f_2:
  5531 00001699 51                      	push	cx
  5532 0000169A BB[3265]                	mov	bx, HDFORMAT_EMPTY_BUFF
  5533 0000169D E86E03                  	call	write_hd_sector
  5534 000016A0 0F8233FD                	jc	formatting_error
  5535 000016A4 E8E0FC                  	call	write_format_percent
  5536                                  	;add	ax, 1
  5537                                  	;adc	dx, 0
  5538                                  	; 17/03/2021
  5539 000016A7 6640                    	inc	eax ; next sector
  5540 000016A9 59                      	pop	cx
  5541 000016AA 49                      	dec	cx ; dec cl
  5542 000016AB 75EC                    	jnz	short FAT12_f_2
  5543                                  FAT12_f_3:
  5544                                  	; write FAT sectors
  5545                                  	;mov	cx, [data_start] ; lba/abs addr
  5546                                  	;mov	bx, [data_start+2] ; lba/abs addr
  5547                                  	; 17/03/2021
  5548 000016AD 668B16[3267]            	mov	edx, [data_start] ; lba/abs addr
  5549                                  
  5550                                  	; 11/02/2019
  5551                                  	;sub	cx, [root_dir_secs]
  5552                                  	;sbb	bx, 0
  5553                                  	; 17/03/2021
  5554                                  	;movzx	ebx, word [root_dir_secs]
  5555 000016B2 8B1E[3E67]              	mov	bx, [root_dir_secs]
  5556 000016B6 6629DA                  	sub	edx, ebx
  5557                                  	;push	edx ; ***
  5558                                  
  5559                                  	;push	bx
  5560                                  	;push	cx
  5561 000016B9 BB[3265]                	mov	bx, HDFORMAT_FATBUFFER
  5562                                  	; ES:BX = FAT Sector Buffer
  5563 000016BC 8A4E15                  	mov	cl, [bp+15h] ; [BPB_Media]
  5564 000016BF B5FF                    	mov	ch, 0FFh
  5565 000016C1 890F                    	mov	[bx], cx ; 0FFF8h
  5566 000016C3 886F02                  	mov	[bx+2], ch ; 0FFFFF8h
  5567                                  	;xor	cx, cx
  5568 000016C6 E84503                  	call	write_hd_sector
  5569 000016C9 0F820AFD                	jc	formatting_error
  5570 000016CD E8B7FC                  	call	write_format_percent
  5571                                  	;mov	bx, HDFORMAT_FATBUFFER
  5572 000016D0 B90000                  	mov	cx, 0
  5573 000016D3 890F                    	mov	[bx], cx
  5574 000016D5 884F02                  	mov	[bx+2], cl
  5575 000016D8 EB0D                    	jmp	short FAT12_f_5
  5576                                  FAT12_f_4:	
  5577                                  	;push	bx
  5578                                  	;push	cx	
  5579                                  	; 17/03/2021
  5580                                  	;push	edx ; ***
  5581 000016DA BB[3265]                	mov	bx, HDFORMAT_FATBUFFER
  5582 000016DD E82E03                  	call	write_hd_sector
  5583 000016E0 0F82F3FC                	jc	formatting_error
  5584 000016E4 E8A0FC                  	call	write_format_percent
  5585                                  FAT12_f_5:	
  5586                                  	;pop	cx
  5587                                  	;pop	bx
  5588                                  	; 17/03/2021
  5589                                  	;pop	edx ; ***
  5590                                  	;
  5591                                  	;add	ax, 1
  5592                                  	;adc	dx, 0
  5593                                  	; 17/03/2021
  5594 000016E7 6640                    	inc	eax
  5595                                  	;cmp	dx, bx
  5596                                  	;jb	short FAT12_f_4
  5597                                  	;cmp	ax, cx
  5598                                  	;jb	short FAT12_f_4
  5599 000016E9 6639D0                  	cmp	eax, edx
  5600 000016EC 72EC                    	jb	short FAT12_f_4
  5601                                  
  5602                                  	; write	root directory sectors
  5603                                  	; as empty sectors
  5604 000016EE 8B0E[3E67]              	mov	cx, [root_dir_secs]
  5605                                  FAT12_f_6:
  5606 000016F2 51                      	push	cx
  5607 000016F3 BB[3265]                	mov	bx, HDFORMAT_EMPTY_BUFF
  5608 000016F6 E81503                  	call	write_hd_sector
  5609 000016F9 0F82DAFC                	jc	formatting_error
  5610 000016FD E887FC                  	call	write_format_percent
  5611                                  	;add	ax, 1
  5612                                  	;adc	dx, 0
  5613                                  	; 17/03/2021
  5614 00001700 6640                    	inc	eax
  5615 00001702 59                      	pop	cx
  5616 00001703 49                      	dec	cx ; dec cl
  5617 00001704 75EC                    	jnz	short FAT12_f_6
  5618                                  
  5619                                  	; write DATA sectors 
  5620                                  	; (after root directory sectors)
  5621 00001706 8B0E[3667]              	mov	cx, [data_sectors]
  5622                                  	;mov	bx, [data_sectors+2]
  5623                                  	;inc	bx ; 11/02/2019
  5624                                  FAT12_f_7:	
  5625                                  	;push	bx
  5626 0000170A 51                      	push	cx	
  5627 0000170B BB[1E61]                	mov	bx, HDFORMAT_SECBUFFER
  5628 0000170E E8FD02                  	call	write_hd_sector
  5629 00001711 0F82C2FC                	jc	formatting_error
  5630 00001715 E86FFC                  	call	write_format_percent
  5631 00001718 59                      	pop	cx
  5632                                  	;pop	bx
  5633                                  	;add	ax, 1
  5634                                  	;adc	dx, 0
  5635                                  	; 17/03/2021
  5636 00001719 6640                    	inc	eax
  5637 0000171B 49                      	dec	cx
  5638 0000171C 75EC                    	jnz	short FAT12_f_7
  5639                                  	;dec	bx
  5640                                  	;jnz	short FAT12_f_7
  5641                                  
  5642                                  	; If there are, format remain sectors which are
  5643                                  	; at beyond of data clusters, with zero bytes.
  5644                                  	
  5645                                  	;mov	cx, [bp+1Ch]	; [BPB_HiddSec]
  5646                                  	;mov	bx, [bp+1Eh]	; [BPB_HiddSec+2]
  5647                                  	; 17/03/2021
  5648 0000171E 668B561C                	mov	edx, [bp+1Ch]	; [BPB_HiddSec]
  5649                                  
  5650                                  	;add	cx, [bp+13h]	; [BPB_TotSec16]
  5651                                  	;adc	bx, 0
  5652                                  	; 17/03/2021
  5653                                  	;movzx	ebx, word [bp+13h] ; [BPB_TotSec16]
  5654 00001722 8B5E13                  	mov	bx, [bp+13h]	; [BPB_TotSec16]
  5655 00001725 6601DA                  	add	edx, ebx
  5656                                  
  5657 00001728 E925FB                  	jmp	FAT12_f_8
  5658                                  
  5659                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5660                                  ; SINGLIX FS FORMATTING
  5661                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5662                                  
  5663                                  	; 20/03/2021
  5664                                  	; 19/03/2021 (fdisk4.s)
  5665                                  SINGLIX_hd_format:
  5666                                  	; 06/01/2018
  5667                                  	; 05/01/2018
  5668                                  	; If Sectors/Track = 17, use CHS+LBA type boot sector
  5669 0000172B 8B1E[A23C]              	mov	bx, [sectors]
  5670 0000172F 83FB11                  	cmp	bx, 17
  5671 00001732 7711                    	ja	short SINGLIX_fs1_f_1
  5672                                  SINGLIX_fs1_f_0:
  5673 00001734 BD[9038]                	mov	bp, TRDOS_TRFS1_chs_bs
  5674 00001737 887E2D                  	mov	[bp+45], bh ; 0 ; [bs_LBA_Ready] = 0
  5675 0000173A 885E2E                  	mov	[bp+46], bl	; [bs_Disk_SecPerTrack]
  5676 0000173D A0[A43C]                	mov	al, [heads]
  5677 00001740 88462F                  	mov	[bp+47], al	; [bs_Disk_Heads]
  5678 00001743 EB1C                    	jmp	short SINGLIX_fs1_f_3
  5679                                  SINGLIX_fs1_f_1:
  5680                                  	; Sectors per Track = 63
  5681                                  	; If disk capacity >= 63*16*1024 use LBA type boot sector
  5682                                  	; 19/03/2021 (32bit cylinder count <=267349)
  5683 00001745 803E[A83C]00            	cmp	byte [cylinders+2], 0
  5684 0000174A 7712                    	ja	short SINGLIX_fs1_f_2
  5685 0000174C 8B0E[A43C]              	mov	cx, [heads]
  5686 00001750 A1[A63C]                	mov	ax, [cylinders]
  5687 00001753 F7E1                    	mul	cx
  5688 00001755 21D2                    	and	dx, dx
  5689 00001757 7505                    	jnz	short SINGLIX_fs1_f_2
  5690 00001759 3D0040                  	cmp	ax, 16384
  5691 0000175C 72D6                    	jb	short SINGLIX_fs1_f_0
  5692                                  SINGLIX_fs1_f_2:	
  5693 0000175E BD[903A]                	mov	bp, TRDOS_TRFS1_lba_bs
  5694                                  	;mov	byte [bp+45], 1 ; [bs_LBA_Ready] = 1
  5695                                  SINGLIX_fs1_f_3:	
  5696                                  	;mov	ax, [pp_Sectors]
  5697                                  	;mov	dx, [pp_Sectors+2]
  5698                                  	; 16/02/2019
  5699                                  	;mov	ax, [ppn_Sectors]
  5700                                  	;mov	dx, [ppn_Sectors+2]
  5701                                  
  5702                                  	; 19/03/2021
  5703 00001761 66A1[F069]              	mov	eax, [ppn_Sectors]
  5704                                  	;mov	[bp+16], ax	; [bsVolumeSize]
  5705                                  	;mov	[bp+18], dx	; [bsVolumeSize+2]
  5706 00001765 66894610                	mov	[bp+16], eax	; [bsVolumeSize]
  5707                                  	;mov	cx, [pp_StartSector]
  5708                                  	;mov	bx, [pp_StartSector+2]
  5709 00001769 668B16[B869]            	mov	edx, [pp_StartSector] 
  5710                                  	;mov	[bp+12], cx	; [bsBeginSector]
  5711                                  	;mov	[bp+14], bx	; [bsBeginSector+2]
  5712 0000176E 6689560C                	mov	[bp+12], edx	; [bsBeginSector]
  5713                                  
  5714 00001772 C6462C80                	mov	byte [bp+44], 80h ; [bsDriveNumber]  ; hd0
  5715                                  
  5716                                  	; Prepare MAT
  5717                                  	;mov	[MAT_VolumeSize], ax ; Total Sectors of the FS
  5718                                  	;mov	[MAT_VolumeSize+2], dx
  5719                                  	; 19/03/2021
  5720 00001776 66A3[9867]              	mov	[MAT_VolumeSize], eax ; Total Sectors of the FS
  5721                                  	;mov	[MAT_BeginSector], cx ; Beginning Sector of the FS
  5722                                  	;mov	[MAT_BeginSector+2], bx
  5723 0000177A 668916[9C67]            	mov	[MAT_BeginSector], edx ; Beginning Sector of the FS
  5724                                  
  5725                                  	;mov	cx, [bp+24]	; [bsMATLocation]
  5726                                  	;mov	bx, [bp+26]	; [bsMATLocation+2]
  5727                                  	;add	cx, 1
  5728                                  	;adc	bx, 0
  5729                                  	; Note: (as Default) MAT Address = 1, DAT Address = 2
  5730                                  	;mov	cx, 2
  5731                                  	; 19/03/2021
  5732 0000177F 6631D2                  	xor	edx, edx
  5733 00001782 B202                    	mov	dl, 2
  5734                                  	
  5735                                  	;xor	bx, bx ; 0
  5736                                  	;mov	[bp+24], cx	; [bsMATLocation]
  5737                                  	;mov	[bp+26], bx	; [bsMATLocation+2]
  5738                                  	;mov	[DAT_Address], cx
  5739                                  	;;mov	[DAT_Address+2], bx
  5740                                  	; 19/03/2021
  5741                                  	;mov	[DAT_Address], dx
  5742 00001784 8816[A067]              	mov	[DAT_Address], dl
  5743                                  
  5744                                  	; DX_AX = FS1 Volume Size
  5745                                  	;add	ax, 7 ; 7 bits more (for round up)
  5746                                  	;adc	dx, 0
  5747                                  	; 19/03/2021
  5748                                  	; EAX = FS1 Volume Size	
  5749 00001788 6683C007                	add	eax, 7 ; 7 bits more (for round up)
  5750 0000178C 30D2                    	xor	dl, dl ; edx = 0
  5751                                  	;mov	cx, 8 ;  1 DAT byte == 8 sectors
  5752                                  	;call	div32
  5753                                  	; DX_AX = DAT bytes
  5754                                  	; 19/03/2021
  5755 0000178E 6631C9                  	xor	ecx, ecx
  5756 00001791 B108                    	mov	cl, 8
  5757 00001793 66F7F1                  	div	ecx
  5758                                  	; eax = DAT bytes
  5759                                  
  5760 00001796 B9FF01                  	mov	cx, 511
  5761                                  	;add	ax, cx
  5762                                  	;adc	dx, 0
  5763                                  	; 19/03/2021
  5764 00001799 6601C8                  	add	eax, ecx
  5765                                  	
  5766                                  	;inc	cx ; 512
  5767                                  	;call	div32
  5768                                  	; DX_AX = DAT sectors (DX must be 0 for volume sizes < 128GB)
  5769                                  	; 19/03/2021	
  5770 0000179C 41                      	inc	cx  ; ecx = 512 
  5771 0000179D 66F7F1                  	div	ecx	
  5772                                  
  5773                                  	;mov	[DAT_SectorCount], ax
  5774                                  	;mov	[DAT_SectorCount+2], dx ; 0
  5775                                  	; 20/03/2021
  5776 000017A0 66A3[A467]              	mov	[DAT_SectorCount], eax
  5777                                  
  5778                                  	;add	ax, 2  ; BS + MAT
  5779                                  	;adc	dx, 0
  5780                                  	;mov	[bp+28], ax  ; [bsRootDirDT] ; RDT address (offset)
  5781                                  	;mov	[bp+30], dx
  5782                                  	; 20/03/2021
  5783 000017A4 6683C002                	add	eax, 2
  5784 000017A8 6689461C                	mov	[bp+28], eax  ; [bsRootDirDT] ; RDT address (offset)
  5785                                  
  5786                                  	; Free Sectors = Total Sectors - (BS+MAT+DATsects+RDT+4)
  5787                                  	;add	ax, 5 ; DATsects + (BS+MAT+RDT+4)
  5788                                  	;;mov	dx, ax ; ? ;
  5789                                  	;adc 	dx, 0
  5790                                  	; 20/03/2021
  5791 000017AC 6683C005                	add	eax, 5
  5792                                  	;mov	cx, [MAT_VolumeSize]
  5793                                  	;mov	bx, [MAT_VolumeSize+2]
  5794                                  	;sub	cx, ax
  5795                                  	;sbb	bx, 0
  5796                                  	;mov	[MAT_FreeSectors], cx
  5797                                  	;mov	[MAT_FreeSectors+2], bx
  5798                                  	;mov	[MAT_FirstFreeSector], ax
  5799                                  	;mov	[MAT_FirstFreesector+2], dx
  5800                                  	; 20/03/2021
  5801 000017B0 668B16[9867]            	mov	edx, [MAT_VolumeSize]
  5802 000017B5 6629C2                  	sub	edx, eax
  5803 000017B8 668916[A867]            	mov	[MAT_FreeSectors], edx
  5804 000017BD 66A3[AC67]              	mov	[MAT_FirstFreeSector], eax
  5805                                   
  5806 000017C1 BF[4867]                	mov	di, fs_volume_name
  5807 000017C4 E8ABFA                  	call	write_fs_volume_name
  5808 000017C7 BE[8867]                	mov	si, fs_volume_serial
  5809 000017CA E80BFB                  	call	write_volume_serial
  5810                                  
  5811                                  	; Modify FS volume name
  5812                                  	; (Convert 20h tail bytes to 0)
  5813 000017CD B94000                  	mov	cx, 64 
  5814 000017D0 BE[4867]                	mov	si, fs_volume_name
  5815 000017D3 31DB                    	xor	bx, bx
  5816 000017D5 B0FF                    	mov	al, 0FFh
  5817                                  modify_fs_vname_1:	
  5818 000017D7 88C4                    	mov	ah, al
  5819 000017D9 AC                      	lodsb
  5820 000017DA 3C20                    	cmp	al, 20h
  5821 000017DC 7708                    	ja	short modify_fs_vname_2
  5822 000017DE 80FC20                  	cmp	ah, 20h
  5823 000017E1 7603                    	jna	short modify_fs_vname_2
  5824 000017E3 89F3                    	mov	bx, si
  5825 000017E5 4B                      	dec	bx
  5826                                  modify_fs_vname_2:
  5827 000017E6 E2EF                    	loop	modify_fs_vname_1
  5828 000017E8 09DB                    	or	bx, bx
  5829 000017EA 740B                    	jz	short modify_fs_vname_3
  5830 000017EC 89DF                    	mov	di, bx
  5831 000017EE B9[8867]                	mov	cx, fs_volume_name+64
  5832 000017F1 29D9                    	sub	cx, bx
  5833 000017F3 30C0                    	xor	al, al
  5834 000017F5 F3AA                    	rep	stosb 
  5835                                  
  5836                                  modify_fs_vname_3:
  5837 000017F7 E865FB                  	call	write_formatting_msg
  5838 000017FA B000                    	mov	al, 0
  5839 000017FC E8C2FB                  	call	write_format_percent_x
  5840                                  
  5841                                  	;mov	ax, [bp+12]	; [bsBeginSector]
  5842                                  	;mov	dx, [bp+14]	; [bsBeginSector+2]
  5843                                  	; 20/03/2021
  5844 000017FF 668B460C                	mov	eax, [bp+12]	; [bsBeginSector]
  5845                                  
  5846                                  	; DX_AX = TRFS1 Boot Sector address
  5847 00001803 89EB                    	mov	bx, bp
  5848                                  	; ES:BX = Boot Sector Buffer
  5849 00001805 E80602                  	call	write_hd_sector
  5850 00001808 0F82CBFB                	jc	formatting_error
  5851                                  	
  5852                                  	;add	ax, 1
  5853                                  	;adc	dx, 0
  5854                                  	; 20/03/2021
  5855 0000180C 6640                    	inc	eax
  5856                                  
  5857                                  	; DX_AX = MAT (DAT header) sector address
  5858 0000180E BB[9467]                	mov	bx, FS_MAT_Buffer
  5859                                  	; 16/02/2019
  5860 00001811 C7074D41                	mov	word [bx],'MA'
  5861 00001815 C6470254                	mov	byte [bx+2],'T'
  5862 00001819 E8F201                  	call	write_hd_sector
  5863 0000181C 0F82B7FB                	jc	formatting_error
  5864 00001820 E8A7FB                  	call	write_fs_format_percent
  5865                                  
  5866                                  	; Calculate DAT bits 
  5867                                  	; NOTE: 4096 bits per DAT sector
  5868                                  	;mov	ax, [MAT_FirstFreeSector]
  5869                                  	;mov	dx, [MAT_FirstFreeSector+2]
  5870                                  	;;xor	dx, dx
  5871                                  	; 20/03/2021
  5872 00001823 66A1[AC67]              	mov	eax, [MAT_FirstFreeSector]
  5873 00001827 6631D2                  	xor	edx, edx
  5874                                  
  5875                                  	;push	dx
  5876                                  	;push	ax
  5877                                  	; 20/03/2021
  5878 0000182A 6650                    	push	eax
  5879 0000182C B90010                  	mov	cx, 4096
  5880                                  	;call	div32
  5881                                  	;20/03/2021
  5882 0000182F 66F7F1                  	div	ecx
  5883                                  	;mov	[DAT_FFBit], bx
  5884                                  	;mov	[DAT_FFSector], ax
  5885                                  	;mov	[DAT_FFSector+2], dx
  5886                                  	; 20/03/2021
  5887 00001832 8916[8C67]              	mov	[DAT_FFBit], dx
  5888 00001836 66A3[8E67]              	mov	[DAT_FFSector], eax	
  5889                                  	;pop	ax
  5890                                  	;pop	dx
  5891                                  	;sub	ax, 1
  5892                                  	;sbb	dx, 0
  5893                                  	; 20/03/2021
  5894 0000183A 6658                    	pop	eax
  5895 0000183C 6648                    	dec	eax	
  5896                                  
  5897                                  	;add	ax, [MAT_FreeSectors]
  5898                                  	;adc	dx, [MAT_FreeSectors+2]
  5899                                  	;call	div32
  5900                                  	;mov	[DAT_LFBit], bx
  5901                                  	;mov	[DAT_LFSector], ax
  5902                                  	; 20/03/2021
  5903 0000183E 31D2                    	xor	dx, dx
  5904 00001840 660306[A867]            	add	eax, [MAT_FreeSectors]
  5905 00001845 66F7F1                  	div	ecx
  5906 00001848 8916[9067]              	mov	[DAT_LFBit], dx
  5907 0000184C 66A3[9267]              	mov	[DAT_LFSector], eax
  5908                                  
  5909                                  	;xor	si, si ; 0
  5910                                  	; 20/03/2021
  5911 00001850 6631F6                  	xor	esi, esi ; 0
  5912                                  SINGLIX_fs1_f_4:
  5913                                  	; calculate free bits for current DAT sector
  5914                                  	;			(to be written)
  5915 00001853 BF[B067]                	mov	di, FS_DAT_Buffer
  5916                                  
  5917                                  	; 20/03/2021
  5918                                  	;cmp	si, [DAT_FFSector]
  5919 00001856 663B36[8E67]            	cmp	esi, [DAT_FFSector]
  5920 0000185B 7433                    	je	short SINGLIX_fs1_f_7
  5921 0000185D 724F                    	jb	short SINGLIX_fs1_f_9
  5922                                  	
  5923                                  	;cmp	si, [DAT_LFSector]
  5924 0000185F 663B36[9267]            	cmp	esi, [DAT_LFSector]
  5925 00001864 7225                    	jb	short SINGLIX_fs1_f_6
  5926 00001866 7746                    	ja	short SINGLIX_fs1_f_9
  5927                                  
  5928                                  	; 20/03/2021
  5929 00001868 8B0E[9067]              	mov	cx, [DAT_LFBit]
  5930 0000186C 88CC                    	mov	ah, cl
  5931 0000186E C1E903                   	shr	cx, 3 ; bit count to byte count
  5932 00001871 7404                    	jz	short SINGLIX_fs1_f_5
  5933                                  	;Example:
  5934                                  	;last free sector = 47 -> byte 5, bit 7
  5935                                  	;last free sector = 48 -> byte 6, bit 0
  5936                                  	; (also previous sectors are free sectors)
  5937 00001873 B0FF                    	mov	al, 0FFh ; 20/03/2021
  5938                                  	;mov	cx, bx
  5939 00001875 F3AA                    	rep	stosb
  5940                                  	; 20/03/2021
  5941                                  	;mov	di, FS_DAT_Buffer
  5942                                  	;add	di, bx
  5943                                  SINGLIX_fs1_f_5:
  5944 00001877 80E407                  	and	ah, 7
  5945                                  	;mov	cl, ah
  5946                                  	;shl	al, cl
  5947                                  	;not	al
  5948                                  	; 20/03/2021
  5949 0000187A 30C0                    	xor	al, al
  5950                                  SINGLIX_fs1_f_13:
  5951                                  	; 20/03/2021 
  5952                                  	; 0 -> 00000001b (last free bit is bit 0)
  5953                                  	; 1 -> 00000011b (last free bit is bit 1)
  5954                                  	; 7 -> 11111111b (last free bit is bit 7)
  5955 0000187C 0C01                    	or	al, 1
  5956 0000187E 08E4                    	or	ah, ah
  5957 00001880 7406                    	jz	short SINGLIX_fs1_f_14
  5958 00001882 D0E0                    	shl	al, 1
  5959 00001884 FECC                    	dec	ah
  5960 00001886 EBF4                    	jmp	short SINGLIX_fs1_f_13
  5961                                  SINGLIX_fs1_f_14:
  5962 00001888 AA                      	stosb
  5963                                  	;mov	cx, 511
  5964                                  	;sub	cx, bx
  5965                                  	;jna	short SINGLIX_fs1_f_9
  5966                                  	;mov	al, 0 ; out of volume bits (=0)
  5967                                  	;rep	stosb
  5968 00001889 EB23                    	jmp	short SINGLIX_fs1_f_9
  5969                                  SINGLIX_fs1_f_6:
  5970 0000188B B90002                  	mov	cx, 512
  5971 0000188E EB1A                    	jmp	short SINGLIX_fs1_f_8
  5972                                  SINGLIX_fs1_f_7:
  5973                                  	; 20/03/2021
  5974                                  	;Example:
  5975                                  	;first free sector = 23 -> byte 2, bit 7
  5976                                  	;first free sector = 24 -> byte 3, bit 0
  5977                                  	; (previous sectors are allocated sectors)
  5978 00001890 8B1E[8C67]              	mov	bx, [DAT_FFBit]
  5979 00001894 88D9                    	mov	cl, bl
  5980 00001896 80E107                  	and	cl, 7
  5981 00001899 C1EB03                  	shr	bx, 3 ; from bits to bytes
  5982 0000189C 01DF                    	add	di, bx
  5983 0000189E B0FF                    	mov	al, 0FFh
  5984 000018A0 D2E0                    	shl	al, cl
  5985 000018A2 AA                      	stosb
  5986 000018A3 B9FF01                  	mov	cx, 511
  5987 000018A6 29D9                    	sub	cx, bx
  5988 000018A8 7604                    	jna	short SINGLIX_fs1_f_9
  5989                                  SINGLIX_fs1_f_8:
  5990 000018AA B0FF                    	mov	al, 0FFh ; Free sector bits (=1)
  5991 000018AC F3AA                    	rep	stosb
  5992                                  SINGLIX_fs1_f_9:
  5993                                  	;mov	ax, [MAT_BeginSector]
  5994                                  	;mov	dx, [MAT_BeginSector+2]
  5995                                  	;;add	ax, [DAT_Address] ; = 2
  5996                                  	;;adc	dx, [DAT_Address+2]
  5997                                  	;add	ax, 2
  5998                                  	;adc	dx, 0
  5999                                  	;add	ax, si
  6000                                  	;adc	dx, 0
  6001                                  	; 20/03/2021
  6002 000018AE 66A1[9C67]              	mov	eax, [MAT_BeginSector]
  6003 000018B2 6683C002                	add	eax, 2 ; [DAT_Address] = 2
  6004 000018B6 6601F0                  	add	eax, esi
  6005                                  
  6006                                  	; Write DAT sector(s)
  6007                                  	;; DX_AX = Disk Allocation Table sector address
  6008                                  	; EAX = Disk Allocation Table sector address
  6009 000018B9 BB[B067]                	mov	bx, FS_DAT_Buffer
  6010 000018BC E84F01                  	call	write_hd_sector
  6011 000018BF 0F8214FB                	jc	formatting_error
  6012 000018C3 E804FB                  	call	write_fs_format_percent
  6013                                  	; Clear DAT buffer again (for next stage)
  6014 000018C6 B90001                  	mov	cx, 256
  6015 000018C9 BF[B067]                	mov	di, FS_DAT_Buffer
  6016 000018CC 29C0                    	sub	ax, ax
  6017 000018CE F3AB                    	rep	stosw
  6018                                  
  6019                                  	;inc	si
  6020                                  	;
  6021                                  	;cmp	si, [DAT_SectorCount]
  6022                                  	;jna	SINGLIX_fs1_f_4
  6023                                  
  6024                                  	; 20/03/2021
  6025 000018D0 6646                    	inc	esi
  6026 000018D2 663B36[A467]            	cmp	esi, [DAT_SectorCount]
  6027 000018D7 0F8678FF                	jna	SINGLIX_fs1_f_4
  6028                                  	
  6029                                  	; 20/03/2021
  6030 000018DB 6631F6                  	xor esi, esi
  6031                                  
  6032                                  	; ;;;
  6033                                  	
  6034                                  	; DAT sectors has been written..
  6035                                  	; Now, Root Directory Description Table is in order
  6036                                  
  6037 000018DE BF[B067]                	mov	di, FS_RDT_Buffer
  6038 000018E1 B84444                  	mov	ax, 'DD' 
  6039 000018E4 AB                      	stosw
  6040 000018E5 30E4                    	xor	ah, ah
  6041 000018E7 B054                    	mov	al, 'T'
  6042 000018E9 AB                      	stosw
  6043 000018EA B80002                  	mov	ax, 512 ; Sector size (Bytes per sector)
  6044 000018ED AB                      	stosw
  6045 000018EE 31C0                    	xor	ax, ax ; RDT sequence number (= 0, section 1)
  6046 000018F0 AB                      	stosw	
  6047                                  	; RDT address
  6048                                  	;mov	ax, [DAT_SectorCount]
  6049                                  	;mov	dx, [DAT_SectorCount+2]
  6050                                  	;add	ax, 2 ; BS + MAT
  6051                                  	;adc	dx, 0
  6052                                  	;stosw
  6053                                  	;mov	ax, dx
  6054                                  	;stosw
  6055                                  	; 20/03/2021
  6056 000018F1 66A1[A467]              	mov	eax, [DAT_SectorCount]
  6057 000018F5 6683C002                	add	eax, 2 ; BS + MAT
  6058 000018F9 66AB                    	stosd
  6059                                  
  6060                                  	;sub	ax, ax ; Next RDT number
  6061                                  	;stosw
  6062                                  	;stosw
  6063                                  	; 20/03/2021
  6064 000018FB 6629C0                  	sub	eax, eax
  6065 000018FE 66AB                    	stosd
  6066                                  
  6067                                  	;mov	ax, 4 ; Sector count of this section
  6068                                  	;	      ; (4*512)/4 = 512 root dir entries
  6069                                  	;stosw
  6070                                  	; 20/03/2021
  6071 00001900 B004                    	mov	al, 4
  6072                                  	;stosw
  6073                                  	;xor	al, al
  6074                                  	;stosw
  6075 00001902 66AB                    	stosd
  6076                                  
  6077                                  	; Volume beginning sector
  6078                                  	;mov	ax, [bp+12]	; [bsBeginSector]
  6079                                  	;mov	dx, [bp+14]	; [bsBeginSector+2]
  6080                                  	;stosw
  6081                                  	;mov	ax, dx
  6082                                  	;stosw
  6083                                  	; 20/03/2021
  6084 00001904 668B460C                	mov	eax, [bp+12]	; [bsBeginSector]
  6085 00001908 66AB                    	stosd
  6086                                  
  6087                                  	;xor	ax, ax
  6088                                  	;dec	ax ; 0FFFFh
  6089                                  	;; Parent Dir Serial (= FFFFFFFFh for root dir)
  6090                                  	;stosw
  6091                                  	;stosw
  6092                                  	; 20/03/2021
  6093 0000190A 6631C0                  	xor	eax, eax ; 0
  6094 0000190D 6648                    	dec	eax ; 0FFFFFFFFh
  6095                                  	; Parent Dir Serial (= FFFFFFFFh for root dir) 
  6096 0000190F 66AB                    	stosd
  6097 00001911 6640                    	inc	eax
  6098                                  	; eax = 0
  6099                                  set_fs_volume_serial_number:
  6100 00001913 BE[8867]                	mov	si, fs_volume_serial
  6101 00001916 A5                      	movsw
  6102 00001917 A5                      	movsw
  6103                                  
  6104                                  	; 20/03/2021
  6105                                  	;sub	ax, ax
  6106                                  	;stosb	; sub directory level = 0
  6107                                  	;stosb	; 0, reserved
  6108 00001918 AB                      	stosw
  6109 00001919 B004                    	mov	al, 00000100b ;  (DOS) System attribute
  6110 0000191B AA                      	stosb	; (DOS) Basic attributes
  6111 0000191C 28C0                    	sub	al, al ; Extended attributes (0 for TRDOS 386)
  6112 0000191E AA                      	stosb
  6113                                  	; 20/03/2021
  6114                                  	;sub	ax, ax ; reserved (8) bytes for TR-MULTIX
  6115 0000191F AB                      	stosw
  6116 00001920 AB                      	stosw
  6117 00001921 AB                      	stosw
  6118 00001922 AB                      	stosw
  6119 00001923 B85254                  	mov	ax, 'RT' ; TRFS Root directory signature
  6120 00001926 AB                      	stosw
  6121 00001927 31C0                    	xor	ax, ax ; Country (language, date, text format)
  6122                                  		       ; (0 = Default, 1 = USA, 90 = Turkiye)
  6123                                  	;stosb
  6124                                  	;stosb	; Time Zone (0 = GMT = default ; -11 to +12)
  6125 00001929 AB                      	stosw
  6126                                  
  6127 0000192A 89FE                    	mov	si, di
  6128                                  	; get the date (from RTC)
  6129 0000192C B404                    	mov	ah, 4
  6130 0000192E CD1A                    	int	1Ah
  6131                                  	; Creating Date (of root directory)
  6132 00001930 86E9                    	xchg	ch, cl ; 07/01/2018
  6133 00001932 89C8                    	mov	ax, cx ; cl = century (BCD), ch = year (BCD)
  6134 00001934 AB                      	stosw
  6135 00001935 88F0                    	mov	al, dh  ; month (BCD)
  6136 00001937 AA                      	stosb
  6137 00001938 88D0                    	mov	al, dl  ; day (BCD)
  6138 0000193A AA                      	stosb
  6139                                  	; get the time (from RTC)
  6140 0000193B B402                    	mov	ah, 2
  6141 0000193D CD1A                    	int	1Ah
  6142                                  	; Creating Time (of root directory)
  6143 0000193F 86CD                    	xchg	cl, ch ; ch = hour (BCD), cl = minute (BSD)
  6144 00001941 89C8                    	mov	ax, cx ; al = hour, ah = minute
  6145 00001943 AB                      	stosw
  6146 00001944 88F0                    	mov	al, dh ; seconds (BCD)
  6147 00001946 AA                      	stosb
  6148 00001947 88D0                    	mov	al, dl ; daylight savings time option
  6149 00001949 AA                      	stosb
  6150                                  	; Set Last Modification Date&Time
  6151 0000194A B90400                  	mov	cx, 4
  6152 0000194D F3A5                    	rep	movsw ; copy creating date&time values to
  6153                                  		; last modification date time values
  6154                                  		; (last modif date&time = creating date&time)
  6155                                  
  6156                                  set_fs_volume_name:
  6157 0000194F BE[4867]                	mov	si, fs_volume_name
  6158 00001952 B120                    	mov	cl, 32 
  6159 00001954 F3A5                    	rep	movsw
  6160                                  
  6161                                  	; Fill remain bytes (of this RDT) with zero
  6162 00001956 B9C000                  	mov	cx, (128+256)/2
  6163 00001959 31C0                    	xor	ax, ax
  6164 0000195B F3AB                    	rep	stosw
  6165                                  
  6166                                  	; RDT is ready here...
  6167                                  
  6168                                  	;mov	ax, [bp+28]	; [bsRootDirDT]
  6169                                  	;mov	dx, [bp+30]	; [bsRootDirDT+2]
  6170                                  	;;xor	dx, dx
  6171                                  	;add	ax, [bp+12]	; [bsBeginSector]
  6172                                  	;adc	dx, [bp+14]	; [bsBeginSector+2]
  6173                                  	; 20/03/2021
  6174 0000195D 668B461C                	mov	eax, [bp+28]	; [bsRootDirDT]
  6175 00001961 6603460C                	add	eax, [bp+12]	; [bsBeginSector]
  6176                                  
  6177                                  	; Write RDT sector
  6178                                  	;; DX_AX = Root Directory Description Table address
  6179                                  	; EAX = Root Directory Description Table address
  6180 00001965 BB[B067]                	mov	bx, FS_RDT_Buffer
  6181 00001968 E8A300                  	call	write_hd_sector
  6182 0000196B 0F8268FA                	jc	formatting_error
  6183 0000196F E858FA                  	call	write_fs_format_percent
  6184                                  
  6185                                  	;add	ax, 1
  6186                                  	;adc	dx, 0
  6187                                  	; 20/03/2021
  6188 00001972 6640                    	inc	eax
  6189                                  
  6190                                  	; write root directory data sectors
  6191                                  	;mov	cx, 4
  6192                                  	; 20/03/2021
  6193 00001974 B104                    	mov	cl, 4
  6194                                  SINGLIX_fs1_f_10:
  6195 00001976 51                      	push	cx
  6196                                  	; Write root directory sector(s)
  6197                                  	; DX_AX = Root Directory Sector address
  6198 00001977 BB[3265]                	mov	bx, HDFORMAT_EMPTY_BUFF
  6199 0000197A E89100                  	call	write_hd_sector
  6200 0000197D 0F8256FA                	jc	formatting_error
  6201 00001981 E846FA                  	call	write_fs_format_percent
  6202                                  	;add	ax, 1
  6203                                  	;adc	dx, 0
  6204                                  	; 20/03/2021
  6205 00001984 6640                    	inc	eax
  6206 00001986 59                      	pop	cx
  6207 00001987 FEC9                    	dec	cl
  6208 00001989 75EB                    	jnz	short SINGLIX_fs1_f_10
  6209                                  
  6210                                  	; Fill remain sectors with 'F6h' bytes
  6211                                  	;mov	cx, [bp+16]	; [bsVolumeSize]
  6212                                  	;mov	bx, [bp+18]	; [bsVolumeSize+2]
  6213                                  	;add	cx, [bp+12]	; [bsBeginSector]
  6214                                  	;adc	bx, [bp+14]	; [bsBeginSector+2]
  6215                                  	; 20/03/2021
  6216 0000198B 668B5610                	mov	edx, [bp+16]	; [bsVolumeSize]
  6217 0000198F 6603560C                	add	edx, [bp+12]	; [bsBeginSector]
  6218                                  
  6219                                  	; write DATA sectors 
  6220                                  	; (after root directory sectors)
  6221                                  SINGLIX_fs1_f_11:
  6222                                  	;push	bx
  6223                                  	;push	cx
  6224                                  	; 20/03/2021
  6225                                  	;push	edx ; *
  6226 00001993 BB[1E61]                	mov	bx, HDFORMAT_SECBUFFER
  6227 00001996 E87500                  	call	write_hd_sector
  6228 00001999 0F823AFA                	jc	formatting_error
  6229 0000199D E8E7F9                  	call	write_format_percent
  6230                                  	;pop	cx
  6231                                  	;pop	bx
  6232                                  	; 20/03/2021
  6233                                  	;pop	edx ; *
  6234                                  	
  6235                                  	;add	ax, 1
  6236                                  	;adc	dx, 0
  6237                                  	; 20/03/2021
  6238 000019A0 6640                    	inc	eax	
  6239                                  
  6240                                  	;cmp	dx, bx
  6241                                  	;jb	short SINGLIX_fs1_f_11
  6242                                  	;ja	SINGLIX_fs1_f_12
  6243                                  	;cmp	ax, cx
  6244                                  	;jb	short SINGLIX_fs1_f_11
  6245                                  	; 20/03/2021
  6246 000019A2 6639D0                  	cmp	eax, edx
  6247 000019A5 72EC                    	jb	short SINGLIX_fs1_f_11
  6248                                  
  6249                                  	; 20/03/2021
  6250                                  	; (this may not be needed)
  6251                                  	; (but cleaering hw of 32 bit regs may be useful)) 
  6252 000019A7 6631D2                  	xor	edx, edx 
  6253 000019AA 6631C0                  	xor	eax, eax
  6254                                  
  6255 000019AD E9B7F8                  	jmp	SINGLIX_fs1_f_12
  6256                                  
  6257                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6258                                  ; print messages
  6259                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6260                                  
  6261                                  print_msg:
  6262                                  
  6263                                  print_msg_LOOP:
  6264 000019B0 AC                      	lodsb                           ; Load byte at DS:SI to AL
  6265 000019B1 20C0                    	and     al, al
  6266 000019B3 7409                    	jz      short print_msg_OK
  6267 000019B5 B40E                    	mov	ah, 0Eh
  6268 000019B7 BB0700                  	mov     bx, 07h
  6269 000019BA CD10                    	int	10h			; BIOS Service func ( ah ) = 0Eh
  6270                                  					; Write char as TTY
  6271                                  					; AL-char BH-page BL-color
  6272 000019BC EBF2                    	jmp     short print_msg_LOOP
  6273                                  
  6274                                  print_msg_OK:
  6275 000019BE C3                      	retn
  6276                                  
  6277                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6278                                  ; reading a block (sector) on hard disk
  6279                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6280                                  ; 17/10/2020
  6281                                  
  6282                                  	; 09/03/2021 (fdisk4.s)
  6283                                  read_hd_sector:
  6284                                  
  6285                                  	; INPUT -> DX_AX = Logical Block Address
  6286                                  	; 	   ES:BX = Sector Buffer
  6287                                  	; OUTPUT ->
  6288                                  	;  cf = 0 -> DX_AX = Logical Block Adress
  6289                                  	;	     ES:BX = Sector Buffer
  6290                                  	;  cf = 1 -> AH = Error Number
  6291                                  
  6292                                  	; 09/03/2021
  6293                                  	; INPUT -> EAX = Logical Block Address
  6294                                  	; 	   ES:BX = Sector buffer
  6295                                  
  6296                                  	;cmp	dx, [chs_limit+2]
  6297                                  	;ja	short read_lba_sector
  6298                                  	;jb	short read_chs_sector
  6299                                  	;cmp	ax, [chs_limit]
  6300                                  	;ja	short read_lba_sector
  6301                                  	;;jmp	short read_chs_sector
  6302                                  
  6303                                  	; 09/03/2021
  6304 000019BF 663B06[2A65]            	cmp	eax, [chs_limit]
  6305 000019C4 7707                    	ja	short read_lba_sector
  6306                                  
  6307                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6308                                  ; reading a block (sector) by using CHS read (ROMBIOS) function
  6309                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6310                                  ; 17/10/2020
  6311                                  
  6312                                  read_chs_sector:
  6313                                  	; hdformat.s (25/09/2020)
  6314 000019C6 C606[2465]02            	mov	byte [rw], 2 ; read
  6315 000019CB EB4D                    	jmp	short chs_rw
  6316                                  
  6317                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6318                                  ; reading a block (sector) by using LBA read (ROMBIOS) function
  6319                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6320                                  ; 17/10/2020
  6321                                  
  6322                                  read_lba_sector:
  6323                                  	; hdformat.s (25/09/2020)
  6324 000019CD C606[2465]42            	mov	byte [rw], 42h
  6325 000019D2 EB05                    	jmp	short lba_rw
  6326                                  
  6327                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6328                                  ; writing a block (sector) by using LBA write (ROMBIOS) function
  6329                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6330                                  ; 17/10/2020
  6331                                  
  6332                                  	; 18/10/2020 
  6333                                  write_lba_sector:
  6334                                  	; hdformat.s (25/09/2020)
  6335 000019D4 C606[2465]43            	mov	byte [rw], 43h
  6336                                  	;jmp	short lba_rw
  6337                                  lba_rw:
  6338                                  	;mov	di, 5
  6339                                  	; 18/10/2020
  6340 000019D9 C606[2565]05            	mov	byte [rcnt], 5  ; Retry count
  6341                                  lba_rw_1:
  6342                                  	;pusha			; db 60h
  6343 000019DE 60                      	db	60h
  6344                                  	;push 	0		; db 6Ah, 00h
  6345 000019DF 6A00                    	db	6Ah, 0
  6346                                  	;push	0		; db 6Ah, 00h
  6347 000019E1 6A00                    	db	6Ah, 0
  6348                                  	;push	dx
  6349                                  	;push	ax
  6350                                  	; 09/03/2021
  6351 000019E3 6650                    	push	eax
  6352 000019E5 06                      	push    es
  6353 000019E6 53                      	push    bx
  6354                                  	;push	1		; db 6Ah, 01h
  6355 000019E7 6A01                    	db	6Ah, 01h                     
  6356                                  	;push	10h		; db 6Ah, 10h
  6357 000019E9 6A10                    	db	6Ah, 10h
  6358                                  
  6359 000019EB 89E6                    	mov     si, sp
  6360 000019ED 8A16[2265]              	mov     dl, [DrvNum]
  6361 000019F1 30C0                    	xor	al, al	; verify off 
  6362                                  lba_rw_2:
  6363 000019F3 8A26[2465]              	mov     ah, [rw] ; 42h = LBA read, 43h = LBA write
  6364                                  	;xor	al, al	; verify off 
  6365 000019F7 CD13                    	int     13h
  6366                                  
  6367                                  	;mov	[error], ah
  6368 000019F9 7310                    	jnc     short lba_rw_3
  6369                                  
  6370                                  	;dec	di 
  6371                                  	; 18/10/2020
  6372 000019FB FE0E[2565]              	dec	byte [rcnt]
  6373 000019FF 740A                    	jz	short lba_rw_3 
  6374                                          
  6375 00001A01 30E4                    	xor	ah, ah
  6376                                  	;mov	dl, [DrvNum]
  6377 00001A03 CD13                    	int	13h	; BIOS Service func (ah) = 0
  6378                                  			; Reset disk system
  6379                                  
  6380                                  	;mov	word [si+2], 1 ; set r/w count to 1 again
  6381 00001A05 C6440201                	mov	byte [si+2], 1
  6382                                  
  6383 00001A09 EBE8                    	jmp	short lba_rw_2
  6384                                  
  6385                                  lba_rw_3:
  6386                                  	;popa
  6387 00001A0B 61                      	db	61h
  6388                                  	;popa
  6389 00001A0C 61                      	db	61h
  6390 00001A0D C3                      	retn
  6391                                  
  6392                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6393                                  ; writing a block (sector) on hard disk
  6394                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6395                                  ; 17/10/2020
  6396                                  
  6397                                  	; 09/03/2021 (fdisk4.s)
  6398                                  write_hd_sector:
  6399                                  
  6400                                  	; INPUT -> DX_AX = Logical Block Address
  6401                                  	; 	   ES:BX = Sector Buffer
  6402                                  	; OUTPUT ->
  6403                                  	;  cf = 0 -> DX_AX = Logical Block Adress
  6404                                  	;	     ES:BX = Sector Buffer
  6405                                  	;  cf = 1 -> AH = Error Number
  6406                                  
  6407                                  	; 09/03/2021
  6408                                  	; INPUT -> EAX = Logical Block Address
  6409                                  	; 	   ES:BX = Sector buffer
  6410                                  
  6411                                  	;cmp	dx, [chs_limit+2]
  6412                                  	;ja	short write_lba_sector
  6413                                  	;jb	short write_chs_sector
  6414                                  	;cmp	ax, [chs_limit]
  6415                                  	;ja	short write_lba_sector
  6416                                  	;;jmp	short write_chs_sector
  6417                                  
  6418                                  	; 09/03/2021
  6419 00001A0E 663B06[2A65]            	cmp	eax, [chs_limit]
  6420 00001A13 77B8                    	ja	short read_lba_sector
  6421                                  
  6422                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6423                                  ; writing a block (sector) by using CHS write (ROMBIOS) function
  6424                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6425                                  ; 17/10/2020
  6426                                  	
  6427                                  	; 18/10/2020
  6428                                  write_chs_sector:
  6429                                  	; hdformat.s (25/09/2020)
  6430 00001A15 C606[2465]03            	mov	byte [rw], 3 ; write
  6431                                  	;jmp	short chs_rw
  6432                                  
  6433                                  	; 09/03/2021
  6434                                  chs_rw:
  6435 00001A1A 56                      	push	si
  6436                                          ;push	cx
  6437                                  	; 09/03/2021
  6438 00001A1B 6651                    	push	ecx
  6439                                  chs_rw_0:
  6440                                  	;mov	di, 5
  6441                                  	; 18/10/2020
  6442 00001A1D C606[2565]05            	mov	byte [rcnt], 5  ; Retry count
  6443                                  chs_rw_1:               
  6444                                  	;push	dx	; Linear sector #
  6445                                  	;push	ax	; DX_AX = Linear address (sectors)
  6446                                  	;mov	cx, [sectors]
  6447                                  	;push	bx
  6448                                  	;
  6449                                  	;call	div32	; 32 bit divide
  6450                                  
  6451                                  	; 09/03/2021
  6452 00001A22 6652                    	push	edx
  6453 00001A24 6650                    	push	eax
  6454 00001A26 6631D2                  	xor	edx, edx
  6455 00001A29 6631C9                  	xor	ecx, ecx
  6456 00001A2C 8B0E[A23C]              	mov	cx, [sectors]
  6457 00001A30 66F7F1                  	div	ecx
  6458 00001A33 42                      	inc	dx
  6459 00001A34 52                      	push	dx  ; sector (1 based)
  6460 00001A35 8B0E[A43C]              	mov	cx, [heads]
  6461 00001A39 66F7F1                  	div	ecx
  6462 00001A3C 88D6                    	mov	dh, dl ; head
  6463 00001A3E 59                      	pop	cx
  6464                                  
  6465                                  	;mov	cx, bx	; Sector (zero based)
  6466                                  	;inc	cx	; To make it 1 based
  6467                                  	;push	cx
  6468                                  	;mov	cx, [heads]
  6469                                  	;call	div32	; Convert track to head & cyl
  6470                                  	;mov	dh, bl	; BX = Head (max. FFh)
  6471                                  	;pop	cx	; AX=Cyl, DH=Head, CX=Sector
  6472                                  	;pop	bx	; ES:BX = Buffer
  6473                                  
  6474 00001A3F 8A16[2265]              	mov	dl, [DrvNum]
  6475 00001A43 88C5                    	mov	ch, al
  6476 00001A45 D0CC                    	ror	ah, 1	; Rotate right
  6477 00001A47 D0CC                    	ror	ah, 1
  6478 00001A49 08E1                    	or	cl, ah
  6479                                  chs_rw_2:
  6480 00001A4B 8A26[2465]              	mov	ah, [rw] ; 02h = read, 03h = write
  6481 00001A4F B001                    	mov	al, 01h
  6482 00001A51 CD13                    	int	13h	; BIOS Service func (ah) = 2/3
  6483                                  			; Read/Write disk sectors
  6484                                  			; AL-sec num CH-track CL-sec
  6485                                  			; DH-head DL-drive ES:BX-buffer
  6486                                  			; CF-flag AH-status AL-sectors written/read
  6487                                  			; If CF = 1 then AH = Error code (>0)
  6488                                          
  6489 00001A53 730C                    	jnc     short chs_rw_3
  6490                                  	;dec	di
  6491 00001A55 FE0E[2565]              	dec	byte [rcnt] ; 18/10/2020
  6492 00001A59 7406                    	jz	short chs_rw_3 
  6493                                          
  6494 00001A5B 30E4                    	xor	ah, ah
  6495                                  	;mov	dl, [DrvNum]
  6496 00001A5D CD13                    	int	13h	; BIOS Service func (ah) = 0
  6497                                  			; Reset disk system
  6498 00001A5F EBEA                    	jmp	short chs_rw_2
  6499                                  
  6500                                  chs_rw_3:
  6501                                  	;pop	ax
  6502                                  	;pop	dx
  6503                                  	;pop	cx
  6504                                  	; 09/03/2021
  6505 00001A61 6658                    	pop	eax
  6506 00001A63 665A                    	pop	edx
  6507 00001A65 6659                    	pop	ecx
  6508 00001A67 5E                      	pop	si
  6509 00001A68 C3                      	retn
  6510                                  	
  6511                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6512                                  ; convert byte to decimal number
  6513                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6514                                  
  6515                                  	; 16/03/2021 (fdisk4.s)
  6516                                  bin_to_decimal:
  6517                                  	; INPUT: DS:SI = Target location
  6518                                  	;        DX_AX = Binary Number (Integer)
  6519                                  	; OUTPUT: Decimal char at DS:SI
  6520                                  	; 	 SI decremented after every division
  6521                                  	; 	 till AX<10.
  6522                                  	; CX, DX, BX will be changed.
  6523                                  
  6524                                  	; 16/03/2021
  6525                                  	; INPUT:
  6526                                  	;	DS:SI = Target location
  6527                                  	;	EAX = Binary number
  6528                                  	; OUTPUT: Decimal char at DS:SI
  6529                                  	; 	SI decremented after every division
  6530                                  	; 	till EAX<10.
  6531                                  	;
  6532                                  	; Modified regaisters: ecx (=10), edx (<10)
  6533                                  
  6534                                  	;mov	cx, 10
  6535                                  	; 16/03/2021
  6536 00001A69 6631C9                  	xor	ecx, ecx
  6537 00001A6C B10A                    	mov	cl, 10
  6538 00001A6E 6631D2                  	xor	edx, edx
  6539                                  btd_0:
  6540                                  	;; DX_AX = Dividend
  6541                                  	;; CX = Divisor
  6542                                  	;call	div32
  6543                                  	;; DX_AX = Quotient
  6544                                  	;; BX = remainder
  6545                                  	;add	bl, '0'
  6546                                  	;mov	[si], bl
  6547                                  	;and	dx, dx
  6548                                  	;jz	short btd_2
  6549                                  	; 16/03/2021
  6550 00001A71 66F7F1                  	div	ecx
  6551                                  		; eax = quotient
  6552                                  		; dl = remainder
  6553 00001A74 80C230                  	add	dl, '0'
  6554 00001A77 8814                    	mov	[si], dl
  6555 00001A79 6621C0                  	and	eax, eax
  6556 00001A7C 7405                    	jz	short btd_1
  6557                                  ;btd_1:
  6558 00001A7E 4E                      	dec	si
  6559 00001A7F 30D2                    	xor	dl, dl ; 16/03/2021
  6560 00001A81 EBEE                    	jmp	short btd_0
  6561                                  ;btd_2:
  6562                                  	;or	ax, ax
  6563                                  	;jnz	short btd_1
  6564                                  btd_1:
  6565 00001A83 C3                      	retn
  6566                                  
  6567                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6568                                  ; convert byte to hexadecimal number
  6569                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6570                                  
  6571                                  byte_to_hex: ; 04/02/2019
  6572                                  bin_to_hex:
  6573                                  	; INPUT ->
  6574                                  	; 	AL = byte (binary number)
  6575                                  	; OUTPUT ->
  6576                                  	;	AX = hexadecimal string
  6577                                  	;
  6578 00001A84 53                      	push	bx
  6579 00001A85 31DB                    	xor	bx, bx
  6580 00001A87 88C3                    	mov	bl, al
  6581 00001A89 C0EB04                  	shr	bl, 4
  6582 00001A8C 8A9F[913C]              	mov	bl, [bx+hexchrs]
  6583 00001A90 86D8                    	xchg	bl, al
  6584 00001A92 80E30F                  	and	bl, 0Fh
  6585 00001A95 8AA7[913C]              	mov	ah, [bx+hexchrs]
  6586 00001A99 5B                      	pop	bx	
  6587 00001A9A C3                      	retn
  6588                                  
  6589                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6590                                  ; read & write characters
  6591                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6592                                  
  6593                                  rw_char:
  6594                                  	; OUTPUT -> DS:SI = Entered String (ASCIIZ)
  6595 00001A9B BE[AE51]                	mov     si, StrVolumeName
  6596 00001A9E BB0700                  	mov     bx, 7
  6597 00001AA1 B403                    	mov     ah, 3
  6598 00001AA3 CD10                    	int     10h
  6599 00001AA5 8916[9551]              	mov     [Cursor_Pos], dx
  6600                                  read_next_char:
  6601 00001AA9 30E4                    	xor     ah, ah
  6602 00001AAB CD16                    	int     16h
  6603 00001AAD 20C0                    	and     al, al
  6604 00001AAF 7439                    	jz      short loc_arrow
  6605 00001AB1 3CE0                    	cmp     al, 0E0h
  6606 00001AB3 7435                    	je      short loc_arrow
  6607 00001AB5 3C08                    	cmp     al, 8
  6608 00001AB7 753D                    	jne     short char_return
  6609                                  loc_back:
  6610 00001AB9 B403                    	mov     ah, 3
  6611 00001ABB CD10                    	int     10h
  6612 00001ABD 3A16[9551]              	cmp     dl, byte [Cursor_Pos]
  6613 00001AC1 761F                    	jna     short loc_beep
  6614                                  prev_column:
  6615 00001AC3 FECA                    	dec     dl
  6616                                  set_cursor_pos:
  6617 00001AC5 B402                    	mov     ah, 2
  6618 00001AC7 CD10                    	int     10h
  6619 00001AC9 88D3                    	mov     bl, dl
  6620 00001ACB 2A1E[9551]              	sub     bl, byte [Cursor_Pos]
  6621 00001ACF B90100                  	mov     cx, 1
  6622 00001AD2 B409                    	mov     ah, 9
  6623 00001AD4 B020                    	mov     al, 20h
  6624 00001AD6 8800                    	mov     [si+bx], al
  6625                                  loc_write_it:
  6626 00001AD8 B307                    	mov     bl, 7
  6627 00001ADA CD10                    	int     10h
  6628 00001ADC 8B16[9551]              	mov     dx, [Cursor_Pos]
  6629 00001AE0 EBC7                    	jmp     short read_next_char
  6630                                  loc_beep:
  6631 00001AE2 B40E                    	mov     ah, 0Eh
  6632 00001AE4 B007                    	mov     al, 7
  6633 00001AE6 CD10                    	int     10h
  6634 00001AE8 EBBF                    	jmp     short read_next_char
  6635                                  loc_arrow:    
  6636 00001AEA 80FC4B                  	cmp     ah, 4Bh
  6637 00001AED 74CA                    	je      short loc_back
  6638 00001AEF 80FC53                  	cmp     ah, 53h
  6639 00001AF2 74C5                    	je      short loc_back
  6640 00001AF4 EBB3                    	jmp     short read_next_char
  6641                                  char_return:
  6642 00001AF6 B403                    	mov     ah, 3
  6643 00001AF8 CD10                    	int     10h
  6644                                  check_char_type:
  6645 00001AFA 3C20                    	cmp     al, 20h
  6646 00001AFC 7229                    	jb      short loc_escape
  6647 00001AFE 88D4                    	mov     ah, dl
  6648 00001B00 2A26[9551]              	sub     ah, byte [Cursor_Pos]
  6649                                  	;cmp	ah, 10 
  6650                                  	;ja	short loc_beep
  6651 00001B04 3A26[0761]              	cmp     ah, [vname_length] ; 05/01/2018
  6652 00001B08 73D8                    	jnb	short loc_beep
  6653 00001B0A 3C7A                    	cmp     al, 'z'
  6654 00001B0C 779B                    	ja      short read_next_char
  6655 00001B0E 3C61                    	cmp     al, 'a'
  6656 00001B10 7202                    	jb      short pass_capitalize
  6657 00001B12 24DF                    	and     al, 0DFh
  6658                                  pass_capitalize:
  6659 00001B14 88E3                    	mov     bl, ah 
  6660 00001B16 30E4                    	xor     ah, ah
  6661 00001B18 8900                    	mov     [si+bx], ax
  6662 00001B1A B307                    	mov     bl, 7
  6663 00001B1C B40E                    	mov     ah, 0Eh
  6664 00001B1E CD10                    	int     10h
  6665 00001B20 EB87                    	jmp     short read_next_char
  6666                                  pass_escape:
  6667 00001B22 3C0D                    	cmp     al, 0Dh	; 13 ; ENTER
  6668 00001B24 7583                    	jne     short read_next_char
  6669                                  	;mov	ah, 0Eh
  6670                                  	;int	10h
  6671                                  	;mov	al, 0Ah
  6672                                  	;int	10h
  6673 00001B26 C3                      	retn
  6674                                  loc_escape:
  6675 00001B27 3C1B                    	cmp     al, 1Bh	; 27 ; ESC
  6676 00001B29 75F7                    	jne     short pass_escape
  6677 00001B2B F9                      	stc
  6678 00001B2C C3                      	retn
  6679                                  
  6680                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6681                                  ; display CHS table
  6682                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6683                                  
  6684                                  	; 09/03/2021 (fdisk4.s)
  6685                                  display_chs_table:
  6686                                  
  6687                                  	; 16/10/2020
  6688                                  	; 12/10/2020 (fdisk3)
  6689                                  	; 11/02/2019 (hdimage)
  6690                                  
  6691 00001B2D 06                      	push	es
  6692 00001B2E BF00B8                  	mov	di, 0B800h
  6693 00001B31 8EC7                    	mov	es, di
  6694 00001B33 BFA000                  	mov	di, 160 ; row 1
  6695 00001B36 B407                    	mov	ah, 07h
  6696 00001B38 B044                    	mov	al, 'D'
  6697 00001B3A AB                      	stosw
  6698 00001B3B B069                    	mov	al, 'i'
  6699 00001B3D AB                      	stosw
  6700 00001B3E B073                    	mov	al, 's'
  6701 00001B40 AB                      	stosw
  6702 00001B41 B06B                    	mov	al, 'k'
  6703 00001B43 AB                      	stosw
  6704 00001B44 B03A                    	mov	al, ':'
  6705 00001B46 AB                      	stosw
  6706 00001B47 B020                    	mov	al, ' '
  6707 00001B49 AB                      	stosw
  6708 00001B4A B068                    	mov	al, 'h'
  6709 00001B4C AB                      	stosw
  6710 00001B4D B064                    	mov	al, 'd'
  6711 00001B4F AB                      	stosw
  6712 00001B50 A0[2265]                	mov	al, [DrvNum]
  6713 00001B53 2C50                    	sub	al, 80h-'0'
  6714 00001B55 AB                      	stosw
  6715 00001B56 BF4001                  	mov	di, 320 ; row 2
  6716 00001B59 B95000                  	mov	cx, 80
  6717 00001B5C B82007                  	mov	ax, 0720h
  6718 00001B5F F3AB                    	rep	stosw
  6719 00001B61 B150                    	mov	cl, 80	; row 3
  6720 00001B63 B02D                    	mov	al, "-"
  6721 00001B65 F3AB                    	rep	stosw
  6722                                  	;mov	cl, 19
  6723 00001B67 B112                    	mov	cl, 18 ; 16/10/2020 ; row 4
  6724 00001B69 B020                    	mov	al, 20h
  6725 00001B6B F3AB                    	rep	stosw
  6726 00001B6D B043                    	mov	al, 'C'
  6727 00001B6F AB                      	stosw
  6728 00001B70 B079                    	mov	al, 'y'
  6729 00001B72 AB                      	stosw
  6730 00001B73 B06C                    	mov	al, 'l'
  6731 00001B75 AB                      	stosw
  6732 00001B76 B069                    	mov	al, 'i'
  6733 00001B78 AB                       	stosw
  6734 00001B79 B06E                    	mov	al, 'n'
  6735 00001B7B AB                      	stosw	
  6736 00001B7C B064                    	mov	al, 'd'
  6737 00001B7E AB                      	stosw
  6738 00001B7F B065                    	mov	al, 'e'
  6739 00001B81 AB                      	stosw
  6740 00001B82 B072                    	mov	al, 'r'
  6741 00001B84 AB                       	stosw
  6742 00001B85 B073                    	mov	al, 's'
  6743 00001B87 AB                       	stosw
  6744 00001B88 B03A                    	mov	al, ':'
  6745 00001B8A AB                      	stosw
  6746 00001B8B B020                    	mov	al, 20h
  6747 00001B8D AB                      	stosw
  6748                                  	;mov	[cylnumpos], di
  6749                                  	
  6750                                  	; 09/03/2021
  6751                                  	;mov	ax, [cylinders]
  6752                                  	;mov	dx, [cylinders+2] ; 16/10/2020
  6753 00001B8E 66A1[A63C]              	mov	eax, [cylinders]
  6754                                  
  6755                                  	;mov	cl, 4
  6756                                  	;mov	ch, 07h ; color
  6757 00001B92 E86600                  	call	write_number
  6758                                  	
  6759                                  	;mov	ax, 0720h
  6760 00001B95 B020                    	mov	al, 20h ; 16/10/2020
  6761 00001B97 AB                      	stosw
  6762 00001B98 AB                      	stosw
  6763 00001B99 B048                    	mov	al, 'H'
  6764 00001B9B AB                      	stosw
  6765 00001B9C B065                    	mov	al, 'e'
  6766 00001B9E AB                      	stosw
  6767 00001B9F B061                    	mov	al, 'a'
  6768 00001BA1 AB                      	stosw
  6769 00001BA2 B064                    	mov	al, 'd'
  6770 00001BA4 AB                       	stosw
  6771 00001BA5 B073                    	mov	al, 's'
  6772 00001BA7 AB                       	stosw
  6773 00001BA8 B03A                    	mov	al, ':'
  6774 00001BAA AB                      	stosw
  6775 00001BAB B020                    	mov	al, 20h
  6776 00001BAD AB                      	stosw
  6777                                  	;mov	[hednumpos], di
  6778                                  	
  6779                                  	; 09/03/2021
  6780                                  	;mov	ax, [heads]
  6781                                  	;xor	dx, dx ; 16/10/2020
  6782                                  	;
  6783                                  	;movzx	eax, word [heads]
  6784                                  	; eax < 65536
  6785 00001BAE A1[A43C]                	mov	ax, [heads]
  6786                                  
  6787                                  	;mov	cl, 2
  6788                                  	;mov	ch, 07h ; color
  6789 00001BB1 E84700                  	call	write_number
  6790                                  
  6791                                  	;mov	ax, 0720h
  6792 00001BB4 B020                    	mov	al, 20h ; 16/10/2020
  6793 00001BB6 AB                      	stosw
  6794 00001BB7 AB                      	stosw
  6795 00001BB8 B053                    	mov	al, 'S'
  6796 00001BBA AB                      	stosw
  6797 00001BBB B065                    	mov	al, 'e'
  6798 00001BBD AB                      	stosw
  6799 00001BBE B063                    	mov	al, 'c'
  6800 00001BC0 AB                      	stosw
  6801 00001BC1 B074                    	mov	al, 't'
  6802 00001BC3 AB                       	stosw
  6803 00001BC4 B06F                    	mov	al, 'o'
  6804 00001BC6 AB                      	stosw
  6805 00001BC7 B072                    	mov	al, 'r'
  6806 00001BC9 AB                       	stosw
  6807 00001BCA B073                    	mov	al, 's'
  6808 00001BCC AB                       	stosw
  6809 00001BCD B03A                    	mov	al, ':'
  6810 00001BCF AB                      	stosw
  6811 00001BD0 B020                    	mov	al, 20h
  6812 00001BD2 AB                      	stosw
  6813                                  	;mov	[secnumpos], di
  6814                                  
  6815                                  	; 09/03/2021
  6816                                  	;mov	ax, [sectors]
  6817                                  	;sub	dx, dx ; 16/10/2020
  6818                                  	;
  6819                                  	;movzx	eax, [sectors]
  6820                                  	; eax < 65536
  6821 00001BD3 A1[A23C]                	mov	ax, [sectors]
  6822                                  
  6823                                  	;mov	cl, 2
  6824                                  	;mov	ch, 07h ; color
  6825 00001BD6 E82200                  	call	write_number
  6826                                  
  6827 00001BD9 B92003                  	mov	cx, 800 ; 16/10/2020 ; row 5
  6828 00001BDC 29F9                    	sub	cx, di
  6829 00001BDE D0E9                    	shr	cl, 1
  6830                                  	;mov	cl, 22
  6831                                  	;mov	ax, 0720h
  6832 00001BE0 B020                    	mov	al, 20h ; 16/10/2020
  6833 00001BE2 F3AB                    	rep	stosw
  6834                                  	
  6835 00001BE4 B150                    	mov	cl, 80 	; row 6
  6836 00001BE6 B02D                    	mov	al, "-"
  6837 00001BE8 F3AB                    	rep	stosw
  6838                                  
  6839 00001BEA B150                    	mov	cl, 80	 ; row 7
  6840                                  	;mov	cl, 160	 ; row 7, 8
  6841 00001BEC B020                    	mov	al, 20h
  6842 00001BEE F3AB                    	rep	stosw
  6843                                  
  6844 00001BF0 BA0006                  	mov	dx, 0600h ; DH = row, DL = 0 column
  6845 00001BF3 31DB                    	xor	bx, bx ; BH = video page (0)
  6846 00001BF5 B402                    	mov	ah, 02h ; set cursor position
  6847 00001BF7 CD10                    	int	10h
  6848                                  
  6849 00001BF9 07                      	pop	es
  6850 00001BFA C3                      	retn
  6851                                  
  6852                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6853                                  ; write decimal number
  6854                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6855                                  
  6856                                  ;write_number:
  6857                                  ;	; 12/10/2020
  6858                                  ;	mov	bx, 10
  6859                                  ;	mov	si, cx
  6860                                  ;wnum_1:
  6861                                  ;	xor	dx, dx
  6862                                  ;	div	bx
  6863                                  ;	push	dx
  6864                                  ;	dec	cl
  6865                                  ;	jnz	short wnum_1
  6866                                  ;	mov	cx, si
  6867                                  ;	mov	ah, ch	; color (07h or 0Fh)
  6868                                  ;	xor	ch, ch
  6869                                  ;wnum_2:
  6870                                  ;	pop	dx
  6871                                  ;	mov	al, dl
  6872                                  ;	add	al, '0'
  6873                                  ;	stosw
  6874                                  ;	loop	wnum_2
  6875                                  ;	retn
  6876                                  
  6877                                  ;write_number:
  6878                                  ;	; 16/10/2020
  6879                                  ;	; dx:ax = binary number
  6880                                  ;	; di = decimal number/string location
  6881                                  ;	; modified registers: ax, bx, cx, dx, bp, di
  6882                                  ;	mov	cx, 10
  6883                                  ;	mov	bp, sp
  6884                                  ;wnum_1:
  6885                                  ;	call	div32
  6886                                  ;	push	bx
  6887                                  ;	and	dx, dx
  6888                                  ;	jnz	short wnum_1
  6889                                  ;	or	ax, ax
  6890                                  ;	jnz	short wnum_1
  6891                                  ;wnum_2:	
  6892                                  ;	pop	ax
  6893                                  ;	add	al, '0'
  6894                                  ;	mov	ah, 07h ; color
  6895                                  ;	stosw
  6896                                  ;	cmp	bp, sp
  6897                                  ;	ja	short wnum_2
  6898                                  ;	retn
  6899                                  
  6900                                  write_number:
  6901                                  	; 21/03/2021
  6902                                  	; 09/03/2021 (fdisk4.s)
  6903                                  	; eax = binary number (must be <=
  6904                                  	; di = decimal number/string location
  6905                                  	; modified registers: eax, ecx, edx, bp, di
  6906 00001BFB 66B90A000000            	mov	ecx, 10
  6907 00001C01 6631D2                  	xor	edx, edx
  6908 00001C04 89E5                    	mov	bp, sp
  6909                                  wnum_1:
  6910 00001C06 66F7F1                  	div	ecx
  6911 00001C09 52                      	push	dx ; <= 9
  6912                                  	; 21/03/2021
  6913 00001C0A 6609C0                  	or	eax, eax
  6914 00001C0D 7404                    	jz	short wnum_2
  6915 00001C0F 30D2                    	xor	dl, dl
  6916 00001C11 EBF3                    	jmp	short wnum_1
  6917                                  wnum_2:	
  6918 00001C13 58                      	pop	ax
  6919 00001C14 0430                    	add	al, '0'
  6920 00001C16 B407                    	mov	ah, 07h ; color
  6921 00001C18 AB                      	stosw
  6922 00001C19 39E5                    	cmp	bp, sp
  6923 00001C1B 77F6                    	ja	short wnum_2
  6924 00001C1D C3                      	retn
  6925                                  
  6926                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6927                                  ; partition size input
  6928                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  6929                                  
  6930                                  	; 13/03/2021
  6931                                  	; 12/03/2021 (fdisk4.s, 2TB disk partitioning)
  6932                                  partition_size_input:
  6933                                  	; 23/10/2020 (fdisk3.s modification on hdimage.s source code)
  6934                                  
  6935                                  	; 13/03/2021
  6936 00001C1E 6631C9                  	xor	ecx, ecx
  6937 00001C21 6631D2                  	xor	edx, edx
  6938                                  
  6939                                  	;mov	word [pSize_multiplier+2], 0
  6940 00001C24 890E[CA69]              	mov	[pSize_multiplier+2], cx ; 0 ; 13/03/2021
  6941 00001C28 C606[CF69]42            	mov	byte [msg_psize_unit+1], 'B'
  6942 00001C2D A0[CE69]                	mov	al, [pSize_unit]
  6943 00001C30 3C25                    	cmp	al, '%'
  6944 00001C32 7522                    	jne	short psu_0
  6945                                  	; 08/02/2019
  6946                                  	; calculate sector count for max. available sectors percentage
  6947                                  	;mov	dx, [pp_Sectors+2] ; max. available sectors
  6948                                  	;mov	ax, [pp_Sectors]   ; for a new partition
  6949                                  	;;mov	dx, [total_sectors+2]
  6950                                  	;;mov	ax, [total_sectors]
  6951                                  	;mov	cx, 100
  6952                                  	;call	div32
  6953                                  	;mov	[pSize_multiplier], ax
  6954                                  	; 29/10/2020
  6955                                  	;mov	[pSize_multiplier+2], dx
  6956                                  	; 13/03/2021
  6957                                  	;;mov	ecx, 100
  6958                                  	;mov	cl, 100
  6959 00001C34 B163                    	mov	cl, 99
  6960 00001C36 66A1[BC69]              	mov	eax, [pp_Sectors]  ; > 0
  6961 00001C3A 6601C8                  	add	eax, ecx ; eax = eax + 99
  6962 00001C3D 80D200                  	adc	dl, 0
  6963 00001C40 FEC1                    	inc	cl ; ecx = 100	
  6964 00001C42 66F7F1                  	div	ecx
  6965 00001C45 66A3[C869]              	mov	[pSize_multiplier], eax	; >= 1
  6966                                  	;xor	eax, eax
  6967                                  	;xor	dl, dl
  6968                                  	
  6969                                  	;mov	ah, 0
  6970                                  	;mov	[msg_psize_unit+1], ah ; 0
  6971                                  	; 13/03/2021
  6972 00001C49 882E[CF69]              	mov	[msg_psize_unit+1], ch ; 0
  6973                                  	;mov	byte [pSize_maxdigits], 2
  6974 00001C4D C606[CC69]03            	mov	byte [pSize_maxdigits], 3 ; 29/10/2020
  6975 00001C52 B025                    	mov	al, '%'
  6976 00001C54 EB5D                    	jmp	short psu_6
  6977                                  psu_0:
  6978 00001C56 3C43                    	cmp	al, 'C'
  6979 00001C58 7517                    	jne	short psu_1
  6980 00001C5A A1[A23C]                	mov	ax, [sectors]
  6981 00001C5D F726[A43C]              	mul	word [heads]
  6982 00001C61 A3[C869]                	mov	[pSize_multiplier], ax
  6983                                  	;;mov	byte [pSize_maxdigits], 4 
  6984                                  	;; <= 65535 cylinders
  6985                                  	;mov	byte [pSize_maxdigits], 5 ; 23/10/2020
  6986                                  	; 13/03/2021	
  6987 00001C64 C606[CC69]06            	mov	byte [pSize_maxdigits], 6 ; <= 267349 cylinders
  6988                                  
  6989                                  	;sub	dh, dh
  6990 00001C69 8836[CF69]              	mov	[msg_psize_unit+1], dh ; 0
  6991 00001C6D B043                    	mov	al, 'C'
  6992 00001C6F EB42                    	jmp	short psu_6
  6993                                  psu_1:
  6994 00001C71 3C47                    	cmp	al, 'G'
  6995 00001C73 7510                    	jne	short psu_2
  6996                                  	;mov	word [pSize_multiplier], 2*1024
  6997                                  	;mov	word [pSize_multiplier+2], 1024
  6998                                  	; 13/03/2021
  6999 00001C75 66C706[C869]000020-     	mov	dword [pSize_multiplier], 1024*1024*2
  6999 00001C7D 00                 
  7000                                  
  7001                                  	;;mov	byte [pSize_maxdigits], 1
  7002                                  	;mov	byte [pSize_maxdigits], 3 ; <= 512 GB ; 23/10/2020
  7003                                  	; 12/03/2021
  7004 00001C7E C606[CC69]04            	mov	byte [pSize_maxdigits], 4 ; <= 2048 GB
  7005 00001C83 EB2E                    	jmp	short psu_6
  7006                                  psu_2:
  7007 00001C85 3C4D                    	cmp	al, 'M'
  7008 00001C87 750D                    	jne	short psu_3
  7009 00001C89 C706[C869]0008          	mov	word [pSize_multiplier], 2*1024
  7010                                  	;mov	byte [pSize_maxdigits], 4
  7011                                  	; 13/03/2021
  7012                                  	; <= 2097152 MB 
  7013 00001C8F C606[CC69]07            	mov	byte [pSize_maxdigits], 7 ; 23/10/2020
  7014 00001C94 EB1D                    	jmp	short psu_6
  7015                                  psu_3:
  7016 00001C96 3C4B                    	cmp	al, 'K'
  7017 00001C98 7508                    	jne	short psu_4
  7018 00001C9A C706[C869]0200          	mov	word [pSize_multiplier], 2
  7019 00001CA0 EB0C                    	jmp	short psu_5
  7020                                  psu_4:
  7021                                  	; al = 'S'
  7022 00001CA2 30E4                    	xor	ah, ah
  7023 00001CA4 8826[CF69]              	mov	[msg_psize_unit+1], ah ; 0
  7024 00001CA8 C706[C869]0100          	mov	word [pSize_multiplier], 1
  7025                                  psu_5:
  7026                                  	;mov	byte [pSize_maxdigits], 7
  7027                                  	; 13/03/2021
  7028                                  	; <= 2147483648 KB or <= 4294967296 sectors
  7029 00001CAE C606[CC69]0A            	mov	byte [pSize_maxdigits], 10 ; 23/10/2020
  7030                                  psu_6:
  7031 00001CB3 A2[8D4B]                	mov	[msg_partition_size_x], al
  7032 00001CB6 BE[794B]                	mov	si, msg_partition_size
  7033 00001CB9 E8F4FC                  	call	print_msg
  7034                                  
  7035 00001CBC 89E5                    	mov	bp, sp
  7036                                  	;xor	bx, bx
  7037                                  	;mov	[pSize_temp], bx ; 0
  7038                                  	;;mov	[pSize_temp+2], bx ; 0
  7039                                  	; 13/03/2021
  7040                                  	;xor	ebx, ebx
  7041                                  	;mov	[pSize_temp], ebx ; 0
  7042 00001CBE 31DB                    	xor	bx, bx
  7043                                  
  7044 00001CC0 881E[CD69]              	mov	[pSize_digitpos], bl ; 0
  7045                                  	; bh = 0  ; video page
  7046 00001CC4 B403                    	mov     ah, 3	; get cursor pos
  7047 00001CC6 CD10                    	int     10h
  7048 00001CC8 8916[9551]              	mov	[Cursor_Pos], dx
  7049                                  	; 09/02/2019
  7050 00001CCC B307                    	mov     bl, 7   ; page 0, color 7 (light gray)
  7051                                  psu_7:
  7052 00001CCE 30E4                    	xor	ah, ah
  7053 00001CD0 CD16                    	int	16h
  7054                                  
  7055 00001CD2 3C30                    	cmp	al, '0'
  7056 00001CD4 7223                    	jb	short psu_8
  7057 00001CD6 3C39                    	cmp	al, '9'
  7058 00001CD8 77F4                    	ja	short psu_7
  7059 00001CDA 8A1E[CD69]              	mov	bl, [pSize_digitpos]
  7060 00001CDE 3A1E[CC69]              	cmp	bl, [pSize_maxdigits]
  7061 00001CE2 73EA                    	jnb	short psu_7
  7062 00001CE4 FE06[CD69]              	inc	byte [pSize_digitpos]
  7063 00001CE8 2C30                    	sub	al, '0'
  7064                                  	;xor	ah, ah  ; 13/03/2021 (AH will not be used)
  7065 00001CEA 50                      	push	ax	; (*)
  7066 00001CEB 0430                    	add	al, '0'
  7067 00001CED B40E                    	mov	ah, 0Eh	; write char as tty
  7068                                  	;mov	bx, 7   ; page 0, color 7 (light gray)
  7069 00001CEF CD10                    	int	10h
  7070 00001CF1 EBDB                    	jmp	short psu_7
  7071                                  
  7072                                  psu_8esc:
  7073                                  	; 29/10/2020 (ESCape)
  7074 00001CF3 89EC                    	mov	sp, bp ; clean stack
  7075                                  
  7076 00001CF5 08C0                    	or	al, al ; zf = 0
  7077 00001CF7 F9                      	stc
  7078 00001CF8 C3                      	retn	
  7079                                  psu_8:
  7080 00001CF9 20C0                    	and	al, al
  7081 00001CFB 0F848300                	jz	psu_15 ; check for left arrow key
  7082 00001CFF 3C1B                    	cmp	al, 27
  7083 00001D01 74F0                    	je	short psu_8esc ; ESCAPE key ; 29/10/2020
  7084 00001D03 7777                    	ja	psu_14 ; check for left arrow key
  7085 00001D05 3C0D                    	cmp	al, 13
  7086                                  	;je	short psu_9  ; ENTER key
  7087 00001D07 723D                    	jb	short psu_11 ; check for backspace key
  7088                                  	;jmp	short psu_7
  7089 00001D09 77C3                    	ja	short psu_7
  7090                                  psu_9:
  7091                                  	; 13/03/2021
  7092                                  	;xor	ax, ax
  7093                                  	;mov	[pSize_temp+2], ax ; 0 ; 08/02/2019
  7094                                  
  7095                                  	;cmp	byte [pSize_digitpos], al ; 0
  7096                                  	;jna	psu_16	
  7097                                  	; 13/03/2021
  7098 00001D0B 383E[CD69]              	cmp	byte [pSize_digitpos], bh ; 0
  7099 00001D0F 767E                    	jna	psu_16
  7100                                  
  7101                                  	;xor	bh, bh
  7102 00001D11 8A1E[CD69]              	mov	bl, [pSize_digitpos]
  7103 00001D15 FECB                    	dec	bl
  7104 00001D17 D0E3                    	shl	bl, 1
  7105 00001D19 01E3                    	add	bx, sp
  7106                                  	;mov	ax, [bx]
  7107                                  	;mov	[pSize_temp], ax
  7108                                  	;;mov	word [pSize_temp+2], 0
  7109                                  	; 13/03/2021
  7110 00001D1B 8A0F                    	mov	cl, [bx]
  7111 00001D1D 66890E[C469]            	mov	[pSize_temp], ecx
  7112                                  	; 13/03/2021
  7113                                  	;mov	cx, 10
  7114 00001D22 B10A                    	mov	cl, 10
  7115                                  psu_10:
  7116 00001D24 FE0E[CD69]              	dec	byte [pSize_digitpos]
  7117 00001D28 7465                    	jz	short psu_16
  7118                                  	
  7119                                  	;mov	ax, [pSize_temp]
  7120                                  	;mov	dx, [pSize_temp+2]
  7121                                  	;;mov	cx, 10
  7122                                  	;call	mul32
  7123                                  	;;mov	[pSize_temp], ax
  7124                                  	;;mov	[pSize_temp+2], dx
  7125                                  	; 13/03/2021
  7126 00001D2A 66A1[C469]              	mov	eax, [pSize_temp]
  7127 00001D2E 66F7E1                  	mul	ecx ; * 10
  7128                                  	;mov	[pSize_temp], eax
  7129                                  
  7130                                  	;xor	bh, bh
  7131 00001D31 8A1E[CD69]              	mov	bl, [pSize_digitpos]
  7132 00001D35 FECB                    	dec	bl
  7133 00001D37 D0E3                    	shl	bl, 1
  7134 00001D39 01E3                    	add	bx, sp ; (*)
  7135                                  	;mov	ax, [bx]
  7136                                  	;add	[pSize_temp], ax
  7137                                  	;adc	word [pSize_temp+2], 0
  7138                                  	
  7139                                  	;add	ax, [bx]
  7140                                  	;adc	dx, 0
  7141                                  	; 13/03/2021
  7142 00001D3B 8A0F                    	mov	cl, [bx]
  7143 00001D3D 6601C8                  	add	eax, ecx
  7144                                  	
  7145                                  	;mov	[pSize_temp], ax
  7146                                  	;mov	[pSize_temp+2], dx
  7147                                  	; 13/03/2021
  7148 00001D40 66A3[C469]              	mov	[pSize_temp], eax
  7149                                  
  7150 00001D44 EBDE                    	jmp	short psu_10
  7151                                  	
  7152                                  	; Left arrow, backspace, DEL key checking
  7153                                  psu_11:
  7154 00001D46 3C08                    	cmp	al, 8 ; backspace key
  7155 00001D48 7584                    	jne	psu_7
  7156                                  psu_12:
  7157                                  	;; bh = 0  ; video page
  7158                                  	;mov	ah, 3 ; get cursor pos
  7159                                  	;int	10h
  7160                                  	;cmp	dl, [Cursor_Pos]
  7161                                  	;jna	short psu_13
  7162                                  	;dec	dl
  7163                                  	;dec	byte [pSize_digitpos]
  7164                                  
  7165                                  	; 08/02/2019
  7166 00001D4A 8B16[9551]              	mov	dx, [Cursor_Pos]
  7167 00001D4E 8A1E[CD69]              	mov	bl, [pSize_digitpos]
  7168 00001D52 20DB                    	and	bl, bl
  7169 00001D54 741D                    	jz	short psu_13
  7170                                  
  7171 00001D56 FECB                    	dec	bl 
  7172 00001D58 881E[CD69]              	mov	[pSize_digitpos], bl
  7173                                  	
  7174 00001D5C 00DA                    	add	dl, bl
  7175                                  
  7176                                  	; bh = 0  ; video page
  7177 00001D5E B402                    	mov	ah, 2 ; set cursor pos
  7178 00001D60 CD10                    	int	10h
  7179                                  	;mov	bl, dl
  7180                                  	;sub	bl, [Cursor_Pos] 
  7181 00001D62 B90100                  	mov	cx, 1
  7182 00001D65 B409                    	mov	ah, 9 ; write char at current curs pos
  7183 00001D67 B020                    	mov	al, 20h ; space (blank)
  7184 00001D69 8800                    	mov	[si+bx], al
  7185                                  	; bh = 0 ; video page
  7186 00001D6B B307                    	mov	bl, 7 ; attribute/color (light gray)
  7187 00001D6D CD10                    	int	10h
  7188                                  
  7189                                  	; 09/02/2019
  7190 00001D6F 58                      	pop	ax ; remove last digit on top of stack 
  7191                                  		   ; set sp to correct position for BX (*)
  7192 00001D70 E95BFF                  	jmp	psu_7
  7193                                  psu_13:
  7194 00001D73 B40E                    	mov	ah, 0Eh
  7195 00001D75 B007                    	mov	al, 7
  7196                                  	;mov	bx, 7
  7197 00001D77 CD10                    	int	10h
  7198 00001D79 E952FF                  	jmp	psu_7
  7199                                  psu_14:
  7200 00001D7C 3CE0                    	cmp	al, 0E0h
  7201 00001D7E 0F854CFF                	jne	psu_7
  7202                                  psu_15:    
  7203 00001D82 80FC4B                  	cmp	ah, 4Bh ; left arrow
  7204 00001D85 74C3                    	je	short psu_12
  7205 00001D87 80FC53                  	cmp	ah, 53h ; DEL key (backspace)
  7206 00001D8A 74BE                    	je	short psu_12
  7207 00001D8C E93FFF                  	jmp	psu_7
  7208                                  psu_16:
  7209 00001D8F 89EC                    	mov	sp, bp
  7210                                  
  7211                                  	; 29/10/2020
  7212 00001D91 803E[CE69]25            	cmp	byte [pSize_unit], '%'
  7213 00001D96 751E                    	jne	short psu_23
  7214                                  
  7215 00001D98 B86400                  	mov	ax, 100
  7216 00001D9B 3906[C469]              	cmp	word [pSize_temp], ax ; 100 ; % limit
  7217 00001D9F 7624                    	jna	short psu_17
  7218 00001DA1 A3[C469]                	mov	word [pSize_temp], ax
  7219                                  
  7220                                  	; (re)set asciiz number string to '100'
  7221                                  
  7222 00001DA4 28FF                    	sub	bh, bh ; 0 ; video page 0
  7223 00001DA6 8B16[9551]              	mov	dx, [Cursor_Pos]
  7224 00001DAA B402                    	mov	ah, 2 ; set cursor pos
  7225 00001DAC CD10                    	int	10h
  7226                                  
  7227 00001DAE BE[1E65]                	mov	si, msg_100
  7228 00001DB1 E8FCFB                  	call	print_msg
  7229                                  
  7230 00001DB4 EB0F                    	jmp	short psu_17
  7231                                  psu_23:
  7232 00001DB6 803E[CE69]53            	cmp	byte [pSize_unit], 'S'
  7233 00001DBB 7508                    	jne	short psu_17 
  7234                                  
  7235 00001DBD BE[FC60]                	mov	si, msg_sectors_crlf
  7236 00001DC0 E8EDFB                  	call	print_msg
  7237                                  	;xor	bx, bx
  7238 00001DC3 EB33                    	jmp	short psu_18
  7239                                  psu_17:
  7240 00001DC5 BE[CE69]                	mov	si, msg_psize_unit
  7241 00001DC8 E8E5FB                  	call	print_msg
  7242                                  
  7243 00001DCB BE[5152]                	mov	si, CRLF
  7244 00001DCE E8DFFB                  	call	print_msg
  7245                                  
  7246                                  	; 13/03/2021
  7247 00001DD1 66A1[C469]              	mov	eax, [pSize_temp]
  7248 00001DD5 6621C0                  	and	eax, eax
  7249 00001DD8 7422                    	jz	short psu_21 ; 0%, ZERO !
  7250                                  
  7251 00001DDA 668B16[C869]            	mov	edx, [pSize_multiplier]
  7252                                  
  7253                                  	; 29/10/2020
  7254 00001DDF 803E[CE69]25            	cmp	byte [pSize_unit], '%'
  7255 00001DE4 7512                    	jne	short psu_18
  7256                                  	
  7257                                  	;mov	cx, [pSize_temp]
  7258                                  	;
  7259                                  	;and	cx, cx
  7260                                  	;jz	short psu_21 ; 0%, ZERO !
  7261                                  	
  7262                                  	; 13/03/2021
  7263                                  	;mov	ax, [pSize_temp]
  7264                                  	;and	ax, ax
  7265                                  	;jz	short psu_21 ; 0%, ZERO !
  7266                                  	
  7267                                  	;cmp	cx, 100
  7268                                  	;jna	short psu_24
  7269                                  	; 13/03/2021
  7270                                  	;cmp	eax, 100
  7271 00001DE6 83F864                  	cmp	ax, 100
  7272 00001DE9 720D                    	jb	short psu_18 ; < 100
  7273 00001DEB 7403                    	je	short psu_19 ; = 100
  7274                                  
  7275                                  	; show 100% for 1 second (for >100%)
  7276 00001DED E80E00                  	call	wait1second ; 29/10/2020
  7277                                  	;mov	cx, 100
  7278                                  psu_19: 
  7279                                  	; 13/03/2021
  7280 00001DF0 66A1[BC69]              	mov	eax, [pp_Sectors] ; 100%
  7281 00001DF4 6631D2                  	xor	edx, edx
  7282 00001DF7 C3                      	retn
  7283                                  
  7284                                  ;psu_24:
  7285                                  	;mov	ax, [pSize_multiplier]
  7286                                  	;mov	dx, [pSize_multiplier+2]
  7287                                  	;
  7288                                  	;;mov	cx, [pSize_temp]
  7289                                  	;;and	cx, cx
  7290                                  	;;jz	short psu_21 ; 0%, ZERO !
  7291                                  	;	
  7292                                  	;jmp	mul32
  7293                                  psu_18:
  7294                                  	; 13/03/2021
  7295                                  	; eax = [pSize_temp]
  7296                                  	; edx = [pSize_multiplier]
  7297 00001DF8 66F7E2                  	mul	edx
  7298                                  	; eax = partition size
  7299                                  	; edx = 0 
  7300 00001DFB C3                      	retn
  7301                                  ;psu_18:
  7302                                  	;mov	ax, [pSize_temp]
  7303                                  	;mov	dx, [pSize_temp+2]
  7304                                  	;mov	cx, ax
  7305                                  	;or	cx, dx
  7306                                  	;;jz	short psu_20
  7307                                  	;jz	short psu_21 ; 08/02/2019
  7308                                  	; 13/03/2021
  7309                                  	;mov	eax, [pSize_temp]
  7310                                  	;or	eax, eax
  7311                                  	;jz	short psu_21	
  7312                                  
  7313                                  	;mov	cx, [pSize_multiplier]
  7314                                  	;cmp	byte [pSize_unit], 'C'
  7315                                  	;je	short psu_20 ; 09/02/2019
  7316                                  	;;jne	short psu_19
  7317                                  	;;call	mul32
  7318                                  	;; 08/02/2019
  7319                                  	;; dx:ax = requested partition size in sectors
  7320                                  	;;retn	
  7321                                  ;psu_19:
  7322                                  	;;mov	cx, [pSize_multiplier]
  7323                                  	;cmp	cx, 1
  7324                                  	;;jna	short psu_20
  7325                                  	;ja	short psu_19
  7326                                  	;; 09/02/2019
  7327                                  	;xor	bx, bx
  7328                                  	;retn
  7329                                  
  7330                                  	; 13/03/2021
  7331                                  	; edx = [pSize_multiplier]
  7332                                  	;mul	edx
  7333                                  	; eax = partition size
  7334                                  	; edx = 0 
  7335                                  	;retn
  7336                                  ;psu_19:
  7337                                  ;	call	mul32
  7338                                  ;	;and	bx, bx
  7339                                  ;	;jnz	short psu_22 ; 09/02/2019
  7340                                  ;	mov	cx, [pSize_multiplier+2]
  7341                                  ;	or	cx, cx
  7342                                  ;	;jz	short psu_20
  7343                                  ;	jz	short psu_22 ; 09/02/2019
  7344                                  ;psu_20:
  7345                                  ;	;call	mul32
  7346                                  ;	;retn
  7347                                  ;	jmp	mul32 ; 23/10/2020
  7348                                  
  7349                                  psu_21:
  7350                                  	; 13/03/2021
  7351                                  	;xor	edx, edx
  7352                                  	; zf = 1 ; 29/10/2020
  7353 00001DFC F9                      	stc
  7354                                  psu_22:
  7355 00001DFD C3                      	retn
  7356                                  
  7357                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7358                                  ; wait for 1 second
  7359                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7360                                  
  7361                                  	; 29/10/2020
  7362                                  wait1second:
  7363 00001DFE B402                    	mov	ah, 2
  7364 00001E00 CD1A                    	int	1Ah ; get time of day
  7365 00001E02 720C                    	jc	short w1s_2
  7366                                  w1s_1:
  7367 00001E04 52                      	push	dx
  7368 00001E05 B402                    	mov	ah, 2
  7369 00001E07 CD1A                    	int	1Ah ; get time of day
  7370 00001E09 58                      	pop	ax
  7371 00001E0A 7204                    	jc	short w1s_2
  7372 00001E0C 38E6                    	cmp	dh, ah
  7373 00001E0E 74F4                    	je	short w1s_1 ; same second
  7374                                  w1s_2:
  7375 00001E10 C3                      	retn
  7376                                  
  7377                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7378                                  ; partition type input
  7379                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7380                                  
  7381                                  partition_type_input:
  7382 00001E11 BE[934B]                	mov	si, msg_partition_type	
  7383 00001E14 E899FB                  	call	print_msg
  7384                                  
  7385 00001E17 31DB                    	xor	bx, bx
  7386                                  
  7387 00001E19 881E[DE69]              	mov	[pType_pos], bl ; 0
  7388 00001E1D 891E[DF69]              	mov	[pType_num], bx ; 0
  7389                                  
  7390                                  	; bh = 0  ; video page
  7391 00001E21 B403                    	mov     ah, 3 ; get cursor pos
  7392 00001E23 CD10                    	int     10h
  7393 00001E25 8916[9551]              	mov	[Cursor_Pos], dx
  7394                                  ptu_0:
  7395 00001E29 30E4                    	xor	ah, ah
  7396 00001E2B CD16                    	int	16h
  7397                                  
  7398 00001E2D 803E[DE69]01            	cmp	byte [pType_pos], 1
  7399 00001E32 773F                    	ja	short ptu_5
  7400                                  
  7401 00001E34 3C30                    	cmp	al, '0'
  7402 00001E36 723B                    	jb	short ptu_5
  7403 00001E38 3C39                    	cmp	al, '9'
  7404 00001E3A 7707                    	ja	short ptu_1
  7405 00001E3C 88C4                    	mov	ah, al
  7406 00001E3E 80EC30                  	sub	ah, '0'
  7407 00001E41 EB13                    	jmp	short ptu_2 
  7408                                  ptu_1:
  7409 00001E43 3CE0                    	cmp     al, 0E0h
  7410 00001E45 7473                    	je	short ptu_9
  7411                                  
  7412 00001E47 24DF                    	and	al, 0DFh
  7413 00001E49 3C41                    	cmp	al, 'A'
  7414 00001E4B 72DC                    	jb	short ptu_0
  7415 00001E4D 3C46                    	cmp	al, 'F'
  7416 00001E4F 77D8                    	ja	short ptu_0
  7417 00001E51 88C4                    	mov	ah, al
  7418 00001E53 80EC37                  	sub	ah, 'A'-10
  7419                                  ptu_2:
  7420 00001E56 803E[DE69]00            	cmp	byte [pType_pos], 0
  7421 00001E5B 7606                    	jna	short ptu_3
  7422 00001E5D 8826[E069]              	mov	[pType_num+1], ah
  7423 00001E61 EB04                    	jmp	short ptu_4 
  7424                                  ptu_3:
  7425 00001E63 8826[DF69]              	mov	[pType_num], ah
  7426                                  ptu_4:
  7427 00001E67 B40E                    	mov	ah, 0Eh
  7428 00001E69 B307                    	mov	bl, 7
  7429 00001E6B CD10                    	int	10h
  7430                                  
  7431 00001E6D FE06[DE69]              	inc	byte [pType_pos]
  7432                                  
  7433 00001E71 EBB6                    	jmp	short ptu_0 
  7434                                  ptu_5:
  7435 00001E73 20C0                    	and	al, al
  7436 00001E75 7443                    	jz	short ptu_9 ; check for left arrow key 
  7437 00001E77 3C1B                    	cmp	al, 27
  7438 00001E79 744C                    	je	short ptu_10 ; ESCAPE key
  7439 00001E7B 77AC                    	ja	short ptu_0
  7440 00001E7D 3C0D                    	cmp	al, 13
  7441 00001E7F 744A                    	je	short ptu_11 ; ENTER key
  7442 00001E81 77A6                    	ja	short ptu_0
  7443                                  ptu_6:
  7444                                  	; Left arrow, backspace, DEL key checking
  7445                                  
  7446 00001E83 3C08                    	cmp	al, 8 ; backspace key
  7447 00001E85 75A2                    	jne	short ptu_0
  7448                                  ptu_7:
  7449                                  	; bh = 0 ; video page
  7450 00001E87 B403                    	mov	ah, 3 ; get cursor pos
  7451 00001E89 CD10                    	int	10h
  7452 00001E8B 3A16[9551]              	cmp	dl, [Cursor_Pos]
  7453 00001E8F 7620                    	jna	short ptu_8
  7454 00001E91 FECA                    	dec	dl
  7455 00001E93 FE0E[DE69]              	dec	byte [pType_pos]
  7456                                  	; bh = 0  ; video page
  7457 00001E97 B402                    	mov	ah, 2 ; set cursor pos
  7458 00001E99 CD10                    	int	10h
  7459 00001E9B 88D3                    	mov	bl, dl
  7460 00001E9D 2A1E[9551]              	sub	bl, [Cursor_Pos] 
  7461 00001EA1 B90100                  	mov	cx, 1
  7462 00001EA4 B409                    	mov	ah, 9 ; write char at current curs pos
  7463 00001EA6 B020                    	mov	al, 20h ; space (blank)
  7464 00001EA8 8800                    	mov	[si+bx], al
  7465                                  	; bh = 0 ; video page
  7466 00001EAA B307                    	mov	bl, 7 ; attribute/color (light gray)
  7467 00001EAC CD10                    	int	10h
  7468 00001EAE E978FF                  	jmp	ptu_0
  7469                                  ptu_8:
  7470 00001EB1 B40E                    	mov	ah, 0Eh
  7471 00001EB3 B007                    	mov	al, 7
  7472 00001EB5 CD10                    	int	10h
  7473 00001EB7 E96FFF                  	jmp	ptu_0
  7474                                  ptu_9:    
  7475 00001EBA 80FC4B                  	cmp	ah, 4Bh ; left arrow
  7476 00001EBD 74C8                    	je	short ptu_7
  7477 00001EBF 80FC53                  	cmp	ah, 53h ; DEL key (backspace)
  7478 00001EC2 74C3                    	je	short ptu_7
  7479 00001EC4 E962FF                  	jmp	ptu_0
  7480                                  
  7481                                  ptu_10: ; ESCAPE
  7482                                  	;mov	al, 0
  7483                                  	; 29/10/2020
  7484 00001EC7 28C0                    	sub	al, al ; 0
  7485                                  	; partition type is 0 (none)
  7486 00001EC9 EB12                    	jmp	short ptu_12
  7487                                  ptu_11: ; ENTER
  7488 00001ECB A0[DF69]                	mov	al, [pType_num]
  7489 00001ECE 803E[DE69]01            	cmp	byte [pType_pos], 1
  7490 00001ED3 7608                    	jna	short ptu_12
  7491 00001ED5 B410                    	mov	ah, 16
  7492 00001ED7 F6E4                    	mul	ah
  7493 00001ED9 0206[E069]              	add	al, [pType_num+1]
  7494                                  ptu_12:
  7495 00001EDD 50                      	push	ax
  7496 00001EDE E8A3FB                  	call	bin_to_hex
  7497 00001EE1 A3[A94B]                	mov	[msg_ptype_num], ax
  7498                                  	; bh = 0  ; video page
  7499 00001EE4 B402                    	mov	ah, 2 ; set cursor pos
  7500 00001EE6 8B16[9551]              	mov	dx, [Cursor_Pos]
  7501 00001EEA CD10                    	int	10h
  7502 00001EEC BE[A94B]                	mov	si, msg_ptype_num 
  7503 00001EEF E8BEFA                  	call	print_msg
  7504 00001EF2 58                      	pop	ax
  7505 00001EF3 C3                      	retn
  7506                                  
  7507                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7508                                  ; show selected partition
  7509                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7510                                  
  7511                                  	; 20/03/2021 (fdisk4.s)
  7512                                  show_selected_partition:
  7513                                  	; INPUT ->
  7514                                  	; 	DS:SI = Partition table row address
  7515                                  	
  7516                                  	; 2019 - 2020 (hdimage.s)
  7517                                  	;pt_s_offset	equ 7
  7518                                  	;pt_bh_offset	equ 11
  7519                                  	;pt_bs_offset	equ 15
  7520                                  	;pt_bc_offset	equ 19
  7521                                  	;pt_fs_offset	equ 23
  7522                                  	;pt_eh_offset	equ 27
  7523                                  	;pt_es_offset	equ 31
  7524                                  	;pt_ec_offset	equ 35
  7525                                  	;pt_rs_offset	equ 41
  7526                                  	;pt_ts_offset	equ 52
  7527                                  	;pt_fsn_offset	equ 63
  7528                                  
  7529                                  	; 24/10/2020 (fdisk3.s)
  7530                                  	pt_s_offset	equ 6
  7531                                  	pt_bh_offset	equ 10
  7532                                  	pt_bs_offset	equ 14
  7533                                  	pt_bc_offset	equ 18
  7534                                  	pt_fs_offset	equ 22
  7535                                  	pt_eh_offset	equ 26
  7536                                  	pt_es_offset	equ 30
  7537                                  	pt_ec_offset	equ 34
  7538                                  	pt_rs_offset	equ 40
  7539                                  	pt_ts_offset	equ 51
  7540                                  	pt_fsn_offset	equ 63
  7541                                  
  7542                                  	; 20/03/2021
  7543 00001EF4 6629C0                  	sub	eax, eax
  7544                                  
  7545                                  	; clear screen
  7546                                  	;mov	ax, 3 ; set video mode to 03h (80x25 text)
  7547 00001EF7 B003                    	mov	al, 3 ; 20/03/2021
  7548 00001EF9 CD10                    	int	10h	
  7549                                  
  7550 00001EFB 89F0                    	mov	ax, si
  7551 00001EFD 2D[8A54]                	sub	ax, MasterBootBuff + pTableOffset ; + 446
  7552 00001F00 C0E804                  	shr	al, 4 ; from offset to partition number
  7553 00001F03 0431                    	add	al, '1'  ; 1 based partition number (chr)
  7554                                  	; Write partition number to the header location
  7555 00001F05 A2[694D]                	mov	[msg_selected_partition+43], al ; '1' to '4'
  7556                                  	
  7557                                  	; Partition number will be used at formatting stage
  7558 00001F08 A2[3850]                	mov	[partition_num_chr], al ; number + '0'
  7559                                  
  7560 00001F0B B268                    	mov	dl, 'h'
  7561 00001F0D 8A04                    	mov	al, [si+ptBootable]
  7562 00001F0F E872FB                  	call	bin_to_hex
  7563 00001F12 A3[844E]                	mov	[pt_row+pt_s_offset], ax
  7564 00001F15 8816[864E]              	mov	[pt_row+pt_s_offset+2], dl ; 'h'
  7565 00001F19 8A4401                  	mov	al, [si+ptBeginHead]
  7566 00001F1C E865FB                  	call	bin_to_hex
  7567 00001F1F A3[884E]                	mov	[pt_row+pt_bh_offset], ax
  7568 00001F22 8816[8A4E]              	mov	[pt_row+pt_bh_offset+2], dl ; 'h'
  7569 00001F26 8A4402                  	mov	al, [si+ptBeginSector]
  7570 00001F29 E858FB                  	call	bin_to_hex
  7571 00001F2C A3[8C4E]                	mov	[pt_row+pt_bs_offset], ax
  7572 00001F2F 8816[8E4E]              	mov	[pt_row+pt_bs_offset+2], dl ; 'h'
  7573 00001F33 8A4403                  	mov	al, [si+ptBeginCylinder]
  7574 00001F36 E84BFB                  	call	bin_to_hex
  7575 00001F39 A3[904E]                	mov	[pt_row+pt_bc_offset], ax
  7576 00001F3C 8816[924E]              	mov	[pt_row+pt_bc_offset+2], dl ; 'h'
  7577 00001F40 8A4404                  	mov	al, [si+ptFileSystemID]
  7578                                   	; Partition type will be used at formatting stage
  7579 00001F43 A2[C269]                	mov	[pp_type_user], al
  7580 00001F46 E83BFB                  	call	bin_to_hex
  7581 00001F49 A3[944E]                	mov	[pt_row+pt_fs_offset], ax
  7582 00001F4C 8816[964E]              	mov	[pt_row+pt_fs_offset+2], dl ; 'h'
  7583 00001F50 8A4405                  	mov	al, [si+ptEndHead]
  7584 00001F53 E82EFB                  	call	bin_to_hex
  7585 00001F56 A3[984E]                	mov	[pt_row+pt_eh_offset], ax
  7586 00001F59 8816[9A4E]              	mov	[pt_row+pt_eh_offset+2], dl ; 'h'
  7587 00001F5D 8A4406                  	mov	al, [si+ptEndSector]
  7588 00001F60 E821FB                  	call	bin_to_hex
  7589 00001F63 A3[9C4E]                	mov	[pt_row+pt_es_offset], ax
  7590 00001F66 8816[9E4E]              	mov	[pt_row+pt_es_offset+2], dl ; 'h'
  7591 00001F6A 8A4407                  	mov	al, [si+ptEndCylinder]
  7592 00001F6D E814FB                  	call	bin_to_hex
  7593 00001F70 A3[A04E]                	mov	[pt_row+pt_ec_offset], ax
  7594 00001F73 8816[A24E]              	mov	[pt_row+pt_ec_offset+2], dl ; 'h'
  7595 00001F77 8A4408                  	mov	al, [si+ptStartSector]
  7596 00001F7A E807FB                  	call	bin_to_hex
  7597 00001F7D A3[AC4E]                	mov	[pt_row+pt_rs_offset+6], ax
  7598 00001F80 8816[AE4E]              	mov	[pt_row+pt_rs_offset+8], dl ; 'h'
  7599 00001F84 8A4409                  	mov	al, [si+ptStartSector+1]
  7600 00001F87 E8FAFA                  	call	bin_to_hex
  7601 00001F8A A3[AA4E]                	mov	[pt_row+pt_rs_offset+4], ax
  7602 00001F8D 8A440A                  	mov	al, [si+ptStartSector+2]
  7603 00001F90 E8F1FA                  	call	bin_to_hex
  7604 00001F93 A3[A84E]                	mov	[pt_row+pt_rs_offset+2], ax
  7605 00001F96 8A440B                  	mov	al, [si+ptStartSector+3]
  7606 00001F99 E8E8FA                  	call	bin_to_hex
  7607 00001F9C A3[A64E]                	mov	[pt_row+pt_rs_offset], ax
  7608 00001F9F 8A440C                  	mov	al, [si+ptSectors]
  7609 00001FA2 E8DFFA                  	call	bin_to_hex
  7610 00001FA5 A3[B74E]                	mov	[pt_row+pt_ts_offset+6], ax
  7611 00001FA8 8816[B94E]              	mov	[pt_row+pt_ts_offset+8], dl ; 'h'
  7612 00001FAC 8A440D                  	mov	al, [si+ptSectors+1]
  7613 00001FAF E8D2FA                  	call	bin_to_hex
  7614 00001FB2 A3[B54E]                	mov	[pt_row+pt_ts_offset+4], ax
  7615 00001FB5 8A440E                  	mov	al, [si+ptSectors+2]
  7616 00001FB8 E8C9FA                  	call	bin_to_hex
  7617 00001FBB A3[B34E]                	mov	[pt_row+pt_ts_offset+2], ax
  7618 00001FBE 8A440F                  	mov	al, [si+ptSectors+3]
  7619 00001FC1 E8C0FA                  	call	bin_to_hex
  7620 00001FC4 A3[B14E]                	mov	[pt_row+pt_ts_offset], ax
  7621                                  
  7622 00001FC7 8A4404                  	mov	al, [si+ptFileSystemID]
  7623 00001FCA BF[C23D]                	mov	di, valid_partitions
  7624 00001FCD B91300                  	mov	cx, 19
  7625 00001FD0 F2AE                    	repnz	scasb
  7626 00001FD2 7405                    	jz	short ssp_1
  7627 00001FD4 B8[B43D]                	mov	ax, FS_OTHERS
  7628 00001FD7 EB0C                    	jmp	short ssp_2
  7629                                  ssp_1:
  7630 00001FD9 81EF[C33D]              	sub	di, valid_partitions + 1
  7631 00001FDD B80E00                  	mov	ax, 14
  7632 00001FE0 F7E7                    	mul	di
  7633 00001FE2 05[AA3C]                	add	ax, FileSys_Names
  7634                                  ssp_2:
  7635 00001FE5 96                      	xchg	ax, si 
  7636 00001FE6 B107                    	mov	cl, 7
  7637 00001FE8 BF[BD4E]                	mov	di, pt_row + pt_fsn_offset
  7638 00001FEB F3A5                    	rep	movsw
  7639 00001FED 89C7                    	mov	di, ax ; partition table row address
  7640                                  
  7641 00001FEF BE[3E4D]                	mov	si, msg_selected_partition
  7642 00001FF2 E8BBF9                  	call	print_msg
  7643                                  
  7644 00001FF5 BE[1F4F]                	mov	si, msg_boot_indicator
  7645 00001FF8 E8B5F9                  	call	print_msg
  7646 00001FFB BE[8B59]                	mov	si, msg_YES
  7647 00001FFE F60580                  	test	byte [di+ptBootable], 80h
  7648 00002001 7503                    	jnz	short ssp_3
  7649 00002003 BE[9159]                	mov	si, msg_NO
  7650                                  ssp_3:
  7651 00002006 E8A7F9                  	call	print_msg
  7652                                  
  7653 00002009 BE[374F]                	mov	si, msg_starting_head
  7654 0000200C E8A1F9                  	call	print_msg
  7655 0000200F 8A4501                  	mov	al, [di+ptBeginHead]
  7656 00002012 E8AD00                  	call	write_byte_decimal
  7657 00002015 E898F9                  	call	print_msg
  7658 00002018 BE[4F4F]                	mov	si, msg_starting_sector
  7659 0000201B E892F9                  	call	print_msg
  7660 0000201E 8A4502                  	mov	al, [di+ptBeginSector]
  7661 00002021 88C2                    	mov	dl, al  ; bits 7&8 are bits 8&9 of cyl
  7662 00002023 243F                    	and	al, 3Fh ; sector number, 1 to 63
  7663 00002025 E89A00                  	call	write_byte_decimal
  7664 00002028 E885F9                  	call	print_msg
  7665 0000202B BE[674F]                	mov	si, msg_starting_cylinder
  7666 0000202E E87FF9                  	call	print_msg
  7667 00002031 8A4503                  	mov	al, [di+ptBeginCylinder] ; bits 0to7 of cyl
  7668 00002034 C0EA06                  	shr	dl, 6 ; bits 8&9 of cyl
  7669 00002037 88D4                    	mov	ah, dl
  7670                                  	;xor	dx, dx
  7671                                  	; 20/03/2021
  7672                                  	; eax = binary number
  7673                                  	; 06/11/2020
  7674 00002039 BE[DB69]                	mov	si, msg_partition_sectors + 10 ; max. 11 digits
  7675                                  	; dx_ax: binary number
  7676 0000203C E82AFA                  	call	bin_to_decimal
  7677                                  	; ds:si = decimal number text address
  7678 0000203F E86EF9                  	call	print_msg
  7679 00002042 BE[7F4F]                	mov	si, msg_system_id
  7680 00002045 E868F9                  	call	print_msg
  7681                                  	; Write file system name (again, copy)
  7682 00002048 BE[BD4E]                	mov	si, pt_row + pt_fsn_offset
  7683                                  	;mov	cx, 14
  7684 0000204B B10E                    	mov	cl, 14
  7685 0000204D B40E                    	mov	ah, 0Eh ; write tty
  7686 0000204F BB0700                  	mov	bx, 7
  7687                                  ssp_4:	 
  7688 00002052 AC                      	lodsb
  7689 00002053 CD10                    	int	10h
  7690 00002055 E2FB                    	loop	ssp_4
  7691                                  
  7692 00002057 BE[974F]                	mov	si, msg_ending_head
  7693 0000205A E853F9                  	call	print_msg
  7694 0000205D 8A4505                  	mov	al, [di+ptEndHead]
  7695 00002060 E85F00                  	call	write_byte_decimal
  7696 00002063 E84AF9                  	call	print_msg
  7697 00002066 BE[AF4F]                	mov	si, msg_ending_sector
  7698 00002069 E844F9                  	call	print_msg
  7699 0000206C 8A4506                  	mov	al, [di+ptEndSector]
  7700 0000206F 88C2                    	mov	dl, al  ; bits 7&8 are bits 8&9 of cyl
  7701 00002071 243F                    	and	al, 3Fh ; sector number, 1 to 63
  7702 00002073 E84C00                  	call	write_byte_decimal
  7703 00002076 E837F9                  	call	print_msg	
  7704 00002079 BE[C74F]                	mov	si, msg_ending_cylinder
  7705 0000207C E831F9                  	call	print_msg
  7706 0000207F 8A4507                  	mov	al, [di+ptEndCylinder] ; bits 0to7 of cyl
  7707 00002082 C0EA06                  	shr	dl, 6 ; bits 8&9 of cyl
  7708 00002085 88D4                    	mov	ah, dl
  7709                                  	;xor	dx, dx
  7710                                  	; 20/03/2021
  7711                                  	; eax = binary number
  7712                                  	; 06/11/2020
  7713 00002087 BE[DB69]                	mov	si, msg_partition_sectors + 10 ; max. 11 digits
  7714                                  	; dx_ax: binary number
  7715 0000208A E8DCF9                  	call	bin_to_decimal
  7716                                  	; ds:si = decimal number text address
  7717 0000208D E820F9                  	call	print_msg
  7718                                  
  7719 00002090 BE[DF4F]                	mov	si, msg_relative_sectors
  7720 00002093 E81AF9                  	call	print_msg
  7721                                  	;mov	ax, [di+ptStartSector]
  7722                                  	;mov	dx, [di+ptStartSector+2]
  7723                                  	; 20/03/2021
  7724 00002096 668B4508                	mov	eax, [di+ptStartSector]
  7725                                  
  7726                                  	;;mov	si, msg_partition_sectors + 7 ; max. 8 digits
  7727                                  	;mov	si, reserved_bytes + 10 ; max. 11 digits
  7728                                  	; 06/11/2020
  7729 0000209A BE[DB69]                	mov	si, msg_partition_sectors + 10 ; max. 11 digits
  7730                                  	; eax = binary number ; 20/03/2021
  7731 0000209D E8C9F9                  	call	bin_to_decimal
  7732 000020A0 E80DF9                  	call	print_msg
  7733                                  
  7734 000020A3 BE[F94F]                	mov	si, msg_total_sectors
  7735 000020A6 E807F9                  	call	print_msg
  7736                                  	;mov	ax, [di+ptSectors]
  7737                                  	;mov	dx, [di+ptSectors+2]
  7738                                  	; 20/03/2021
  7739 000020A9 668B450C                	mov	eax, [di+ptSectors]
  7740                                  
  7741                                  	;;mov	si, msg_partition_sectors + 7 ; max. 8 digits
  7742                                  	;mov	si, reserved_bytes + 10 ; max. 11 digits
  7743                                  	; 06/11/2020
  7744 000020AD BE[DB69]                	mov	si, msg_partition_sectors + 10 ; max. 11 digits
  7745                                  	; eax = binary number ; 20/03/2021
  7746 000020B0 E8B6F9                  	call	bin_to_decimal	
  7747 000020B3 E8FAF8                  	call	print_msg
  7748                                  
  7749                                  	; 24/02/2019
  7750 000020B6 BE[5152]                	mov	si, CRLF
  7751 000020B9 E8F4F8                  	call	print_msg
  7752                                  
  7753 000020BC 89FE                    	mov	si, di  ; partition table row address
  7754                                  
  7755                                  	; 20/03/2021
  7756                                  	; (clear hw of eax)
  7757 000020BE 6631C0                  	xor	eax, eax
  7758                                  
  7759 000020C1 C3                      	retn
  7760                                  
  7761                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7762                                  ; write byte as descimal number
  7763                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7764                                  
  7765                                  write_byte_decimal:
  7766                                  	; INPUT ->
  7767                                  	;	AL = binary number
  7768                                  	; OUTPUT ->
  7769                                  	;	DS:SI = decimal number text address
  7770                                  	;	        (ASCIIZ string)
  7771                                  	;
  7772                                  	; (SI, AX, CX will be modified)
  7773                                  
  7774                                  	;mov	si, msg_partition_sectors + 8  ; max. 8 digits
  7775                                  	; 06/11/2020
  7776 000020C2 BE[DC69]                	mov	si, msg_partition_sectors + 11 ; max. 11 digits
  7777 000020C5 B10A                    	mov	cl, 10
  7778                                  wbd_loop:
  7779 000020C7 4E                      	dec	si
  7780 000020C8 30E4                    	xor	ah, ah
  7781 000020CA F6F1                    	div	cl
  7782 000020CC 80C430                  	add	ah, '0'
  7783 000020CF 8824                    	mov	[si], ah
  7784 000020D1 20C0                    	and	al, al
  7785 000020D3 75F2                    	jnz	short wbd_loop
  7786 000020D5 C3                      	retn
  7787                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7788                                  ; init (MBR) partition table
  7789                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7790                                  ; 16/10/2020
  7791                                  
  7792                                  	; 09/03/2021
  7793                                  	; 03/02/2019
  7794                                  init_partition_table:
  7795                                  
  7796                                  	; INPUT -> none
  7797                                  	; OUTPUT -> none
  7798                                  
  7799                                  	; 15/10/2020
  7800                                  	; (If a partition row contains invalid/wrong/defective parameters)
  7801                                  	; (it's active partition flag/byte will be 0FFh, an invalid value!)
  7802                                  
  7803                                  	; 12/02/2019	
  7804                                  	;cmp	word [MBIDCode], 0AA55h
  7805                                  	;jne	ipt_stc ; invalid
  7806                                  
  7807                                  	; 15/02/2019
  7808                                  	; clear primary partition table structure/list
  7809                                  
  7810 000020D6 BF[6A6C]                	mov	di, part_table_boot_ind
  7811                                  	;mov	cx, 36 ; 18*4 = 72 bytes
  7812                                  	; 05/11/2020
  7813 000020D9 B92C00                  	mov	cx, 44 ; 22*4 = 88 bytes
  7814                                  	;xor	ax, ax ; 0
  7815 000020DC 6631C0                  	xor	eax, eax ; 09/03/2021
  7816 000020DF F3AB                    	rep	stosw
  7817                                  
  7818 000020E1 A3[C26C]                	mov	[pcount], ax ; reset (pcount & ppcount)
  7819 000020E4 A3[C46C]                	mov	[apcount], ax ; reset (apcount & epnumber)
  7820                                  
  7821 000020E7 BE[8A54]                	mov	si, MasterBootBuff+446 ; Partition table offset
  7822                                  	;mov	cx, 4
  7823 000020EA B104                    	mov	cl, 4
  7824 000020EC 31FF                    	xor	di, di
  7825                                  ipt_0:
  7826 000020EE 8A6404                  	mov	ah, [si+ptFileSystemID]
  7827                                  
  7828 000020F1 20E4                    	and	ah, ah
  7829 000020F3 0F840D01                	jz	ipt_8 ; empty
  7830                                  
  7831 000020F7 FE06[C26C]              	inc	byte [pcount] ; partition count
  7832                                  
  7833 000020FB 80FC01                  	cmp	ah, 1	; FAT12
  7834 000020FE 7442                    	je	short ipt_2
  7835 00002100 80FC04                  	cmp	ah, 4	; FAT16
  7836 00002103 743D                    	je	short ipt_2
  7837 00002105 723F                    	jb	short ipt_3	
  7838 00002107 80FC06                  	cmp	ah, 6	; FAT16 big
  7839 0000210A 7436                    	je	short ipt_2
  7840 0000210C 7715                    	ja	short ipt_1 ; EXTENDED
  7841                                  
  7842                                  	;cmp	ah, 5 ; EXTENDED
  7843                                  	;jne	short ipt_3
  7844                                  ipt_17:
  7845 0000210E 803E[C56C]00            	cmp	byte [epnumber], 0
  7846                                  	;ja	short ipt_stc ; invalid  (more than 1 extended dos partition)
  7847 00002113 7605                    	jna	short ipt_15
  7848                                  	
  7849 00002115 C685[6A6C]FF            	mov	byte [part_table_boot_ind+di], 0FFh 
  7850                                  				; Invalid/Defective partition flag
  7851                                  ipt_15:	
  7852 0000211A B005                    	mov	al, 5
  7853 0000211C 28C8                    	sub	al, cl ; partition number 1 to 4
  7854 0000211E A2[C56C]                	mov	byte [epnumber], al ; extended partition entry number (1 to 4)
  7855 00002121 EB23                    	jmp	short ipt_3
  7856                                  ipt_1:
  7857                                  	; 26/10/2020
  7858 00002123 80FC07                  	cmp	ah, 07h ; NTFS (Windows FS)
  7859 00002126 741A                    	je	short ipt_2 ; accept NTFS as primary dos partition
  7860                                  			    ; (then, extended partition can be created)	
  7861                                  	; 24/10/2020
  7862 00002128 80FC0C                  	cmp	ah, 0Ch ; FAT32 (LBA)
  7863 0000212B 7415                    	je	short ipt_2
  7864 0000212D 7707                    	ja	short ipt_18
  7865                                  	; 16/10/2020
  7866 0000212F 80FC0B                  	cmp	ah, 0Bh ; FAT32 (CHS)
  7867                                  	;jne	short ipt_3
  7868                                  	; 24/10/2020
  7869 00002132 740E                    	je	short ipt_2
  7870                                  	;jb	short ipt_3 ; non-dos partition (NTFS or unknown fs type)
  7871                                  	; 09/03/2021
  7872 00002134 EB10                    	jmp	short ipt_3 ; non-dos partition (unknown fs type)
  7873                                  ipt_18:
  7874 00002136 80FC0F                  	cmp	ah, 0Fh  ; EXTENDED (LBA)
  7875 00002139 74D3                    	je	short ipt_17
  7876 0000213B 7709                    	ja	short ipt_3 ; non-dos partition 
  7877                                  			    ; (xenix/unix/linux/singlix/runix or unknown)
  7878 0000213D 80FC0E                  	cmp	ah, 0Eh ; FAT16 (LBA)
  7879 00002140 7504                    	jne	short ipt_3 ; 0Dh
  7880                                  	; FAT16 LBA (0Eh)
  7881                                  ipt_2:
  7882 00002142 FE06[C36C]              	inc	byte [ppcount] ; primary dos partition count
  7883                                  ipt_3:
  7884 00002146 88A5[716C]              	mov	[part_table_sys_id+di], ah  ; Partition Type (FS type)
  7885                                  	
  7886 0000214A 8A04                    	mov	al, [si+ptBootable]
  7887                                  
  7888 0000214C 20C0                    	and	al, al
  7889 0000214E 7413                    	jz	short ipt_4
  7890                                  
  7891 00002150 803E[C46C]01            	cmp	byte [apcount], 1 ; check (previous) active partition count
  7892                                  	;jnb	short ipt_stc  ; invalid (if it is not zero here)
  7893 00002155 7304                    	jnb	short ipt_16
  7894                                  
  7895 00002157 3C80                    	cmp	al, 80h  ; active partition sign/flag?
  7896                                  	;jne	short ipt_stc  ; invalid flag
  7897 00002159 7404                    	je	short ipt_11
  7898                                  ipt_16:
  7899                                  	; 15/10/2020
  7900 0000215B B0FF                    	mov	al, 0FFh ; Invalid/Defective partition flag 
  7901 0000215D EB04                    	jmp	short ipt_4
  7902                                  ipt_11:
  7903 0000215F FE06[C46C]              	inc	byte [apcount]  ; active partition count = 1
  7904                                  ipt_4:
  7905 00002163 8885[6A6C]              	mov	[part_table_boot_ind+di], al
  7906                                  
  7907                                  	;mov	al, [heads]
  7908                                  ;ipt_4_fix:
  7909                                  	;dec	al
  7910 00002167 8A6401                  	mov	ah, [si+ptBeginHead]
  7911                                  	;cmp	al, ah
  7912                                  	;;jb	short ipt_retn ; invalid
  7913                                  	;jb	ipt_heads_fix ; 10/02/2019
  7914 0000216A 88A5[6B6C]              	mov	[part_table_start_head+di], ah
  7915 0000216E 8A6405                  	mov	ah, [si+ptEndHead]
  7916                                  	;cmp	al, ah
  7917                                  	;;jb	short ipt_retn ; invalid
  7918                                  	;jb	short ipt_heads_fix ; 10/02/2019
  7919 00002171 88A5[726C]              	mov	[part_table_end_head+di], ah
  7920                                  	;mov	al, [sectors]
  7921 00002175 8A7C02                  	mov	bh, [si+ptBeginSector]
  7922 00002178 88FC                    	mov	ah, bh
  7923 0000217A 80E43F                  	and	ah, 3Fh ; 63
  7924                                  	;cmp	al, ah
  7925                                  	;jb	short ipt_retn ; invalid
  7926 0000217D 88A5[6C6C]              	mov	[part_table_start_sector+di], ah
  7927 00002181 8A7406                  	mov	dh, [si+ptEndSector]
  7928 00002184 88F4                    	mov	ah, dh
  7929 00002186 80E43F                  	and	ah, 3Fh ; 63
  7930                                  	;cmp	al, ah
  7931                                  	;jb	short ipt_retn ; invalid
  7932 00002189 88A5[736C]              	mov	[part_table_end_sector+di], ah
  7933 0000218D C0EF06                  	shr	bh, 6
  7934                                  	;mov	bl, [si+ptBeginCylinder]
  7935 00002190 8A4403                  	mov	al, [si+ptBeginCylinder] ; 09/03/2021
  7936 00002193 88FC                    	mov	ah, bh ; 09/03/2021
  7937                                  	;mov	ax, [cylinders]
  7938                                  	;dec	ax
  7939                                  	;cmp	ax, bx
  7940                                  	;jb	short ipt_retn ; invalid
  7941                                  	;mov	[part_table_start_cyl+di], bx
  7942 00002195 668985[6D6C]            	mov	[part_table_start_cyl+di], eax ; 09/03/2021
  7943 0000219A C0EE06                  	shr	dh, 6
  7944                                  	;mov	dl, [si+ptEndCylinder]
  7945 0000219D 8A4407                  	mov	al, [si+ptEndCylinder] ; 09/03/2021
  7946 000021A0 88F4                    	mov	ah, dh	; 09/03/2021
  7947                                  	;cmp	ax, dx
  7948                                  	;jb	short ipt_retn ; invalid
  7949                                  	;mov	[part_table_end_cyl+di], dx
  7950 000021A2 668985[746C]            	mov	[part_table_end_cyl+di], eax ; 09/03/2021
  7951                                  
  7952                                  	;mov	ax, [si+ptStartSector]
  7953                                  	;mov	dx, [si+ptStartSector+2]
  7954 000021A7 668B4408                	mov	eax, [si+ptStartSector] ; 09/03/2021
  7955                                  
  7956                                  	;mov	[part_table_rel_sec_lw+di], ax
  7957                                  	;mov	[part_table_rel_sec_hw+di], dx
  7958 000021AB 668985[786C]            	mov	[part_table_rel_sec+di], eax ; 09/03/2021
  7959                                  
  7960                                  	;or	ax, dx
  7961                                  	;;jz	short ipt_stc ; invalid (start sector must not be zero)
  7962                                  	;jnz	short ipt_12
  7963                                  	; 09/03/2021
  7964 000021B0 6609C0                  	or	eax, eax
  7965 000021B3 7505                    	jnz	short ipt_12
  7966                                  	; 15/10/2020
  7967 000021B5 C685[6A6C]FF            	mov	byte [part_table_boot_ind+di], 0FFh
  7968                                  				; Invalid/Defective partition flag
  7969                                  ipt_12:
  7970                                  	;mov	ax, [si+ptSectors]
  7971                                  	;mov	dx, [si+ptSectors+2]
  7972 000021BA 668B440C                	mov	eax, [si+ptSectors] ; 09/03/2021
  7973                                  
  7974                                  	;mov	bx, dx
  7975                                  	;or	bx, ax
  7976                                  	;;jz	short ipt_stc	; invalid (zero size of partition)
  7977                                  	;jnz	short ipt_6 ; 10/02/2019
  7978                                  	; 09/03/2021
  7979 000021BE 6609C0                  	or 	eax, eax
  7980 000021C1 7505                    	jnz	short ipt_6
  7981                                  
  7982                                  	; 15/10/2020
  7983 000021C3 C685[6A6C]FF            	mov	byte [part_table_boot_ind+di], 0FFh 
  7984                                  				; Invalid/Defective partition flag
  7985                                  
  7986                                  	;cmp	dx, [total_sectors+2]
  7987                                  	;ja	short ipt_stc	; invalid (partition size > disk capacity)
  7988                                  	;jb	short ipt_6
  7989                                  	;;cmp	ax, [total_sectors] ; (ax + 1) <= total sectors
  7990                                  	;jb	short ipt_6
  7991                                  	
  7992                                  ;ipt_stc:
  7993                                  ;	; invalid MBR data
  7994                                  ;	;stc
  7995                                  ;ipt_retn:
  7996                                  ;	retn
  7997                                  
  7998                                  ;ipt_heads_fix:
  7999                                  	; 10/02/2019
  8000                                  	; AL = [heads] - 1
  8001                                  
  8002                                  	;test	byte [cylinders], 1
  8003                                  	;jnz	short ipt_stc ; odd cylinder count (can not be shifted)
  8004                                  	
  8005                                  	;inc	al ; = [heads]
  8006                                  	;cmp	al, 8
  8007                                  	;ja	short ipt_stc ; this fix is needed for <= 16 heads (& 17 spt)
  8008                                  	;shl	al, 1
  8009                                  	;mov	[heads], al ; heads = heads*2
  8010                                  	;shr	word [cylinders], 1 ; cylinders = cylinders/2
  8011                                  	;jmp	ipt_4_fix
  8012                                  
  8013                                  ipt_6:
  8014                                  	;mov	[part_table_num_sec_lw+di], ax
  8015                                  	;mov	[part_table_num_sec_hw+di], dx
  8016                                  	; 09/03/2021
  8017 000021C8 668985[7C6C]            	mov	[part_table_num_sec+di], eax
  8018                                  
  8019                                  	;add	ax, [part_table_rel_sec_lw+di]
  8020                                  	;adc	dx, [part_table_rel_sec_hw+di]
  8021                                  	;;jc	short ipt_retn  ; invalid
  8022                                  	; 27/10/2020
  8023                                  	;jc	short ipt_13
  8024                                  	; 09/03/2021
  8025 000021CD 660385[786C]            	add	eax, [part_table_rel_sec+di]
  8026 000021D2 7207                    	jc	short ipt_13  ; invalid !
  8027                                  
  8028                                  	;cmp	dx, [total_sectors+2]
  8029                                  	;;ja	short ipt_stc	; invalid (partition end > disk capacity)
  8030                                  	;jb	short ipt_7
  8031                                  	; 27/10/2020
  8032                                  	;ja	short ipt_13
  8033                                  	;cmp	ax, [total_sectors] ; ax <= total sectors
  8034                                  	;;ja	short ipt_stc	; invalid (partition end > disk capacity)
  8035                                  	;jna	short ipt_7
  8036                                  	; 09/03/2011
  8037 000021D4 663B06[2665]            	cmp	eax, [total_sectors]
  8038 000021D9 7605                    	jna	short ipt_7
  8039                                  ipt_13:
  8040                                  	; 15/10/2020
  8041 000021DB C685[6A6C]FF            	mov	byte [part_table_boot_ind+di], 0FFh 
  8042                                  				; Invalid/Defective partition flag 
  8043                                  ipt_7:
  8044                                  	; 27/10/2020
  8045                                  	;mov	ax, 1022 ; CHS cylinder number limit
  8046                                  	;cmp	[part_table_start_cyl+di], ax
  8047                                  	;ja	short ipt_19 ; = 1023
  8048                                  	;inc	ax ; 1023
  8049                                  	;cmp	[part_table_end_cyl+di], ax
  8050                                  	;jb	short ipt_14  ; < 1023
  8051                                  	; 12/03/2021
  8052 000021E0 66B8FE030000            	mov	eax, 1022
  8053 000021E6 663985[6D6C]            	cmp	[part_table_start_cyl+di], eax
  8054 000021EB 7708                    	ja	short ipt_19 ; = 1023
  8055 000021ED 40                      	inc	ax
  8056 000021EE 663985[746C]            	cmp	[part_table_end_cyl+di], eax
  8057 000021F3 7203                    	jb	short ipt_14  ; < 1023
  8058                                  ipt_19:
  8059                                  	; 27/10/2020
  8060                                  	; set cylinder number if the partition's start or end sector is
  8061                                  	; at the beyond of chs limit 
  8062                                  	; ax = 1022 -> set start cylinder
  8063                                  	; ax = 1023 -> set end cylinder
  8064 000021F5 E82600                  	call	cylindernumberfix
  8065                                  ipt_14:
  8066 000021F8 83C610                  	add	si, 16
  8067 000021FB E201                    	loop	ipt_5
  8068                                  	
  8069                                  	; OK!
  8070                                  
  8071                                  	;clc
  8072 000021FD C3                      	retn
  8073                                  
  8074                                  ipt_5:
  8075                                  	;add	di, 18
  8076                                  	; 05/11/2020
  8077 000021FE 83C716                  	add	di, 22
  8078 00002201 E9EAFE                  	jmp	ipt_0
  8079                                  
  8080                                  ipt_8:
  8081                                  	; Empty partition table check (all of 16 bytes must be 0)
  8082 00002204 51                      	push	cx
  8083 00002205 56                      	push	si ; 16/10/2020
  8084                                  	;mov	cl, 8
  8085 00002206 B104                    	mov	cl, 4 ; 12/03/2021
  8086                                  ipt_9:
  8087                                  	;lodsw
  8088                                  	;or	ax, ax
  8089                                  	;jnz	short ipt_10
  8090                                  	; 12/03/2021
  8091 00002208 66AD                    	lodsd
  8092 0000220A 6609C0                  	or	eax, eax
  8093 0000220D 7507                    	jnz	short ipt_10
  8094 0000220F E2F7                    	loop	ipt_9
  8095 00002211 59                      	pop	cx ; 16/10/2020  ; (discard si)
  8096 00002212 59                      	pop	cx
  8097 00002213 E2E9                    	loop	ipt_5
  8098                                  	
  8099                                  	;clc
  8100 00002215 C3                      	retn
  8101                                  ipt_10:
  8102                                  	;pop	cx
  8103                                  	; invalid
  8104                                  	;stc
  8105                                  	; 27/10/2020
  8106                                  	; 15/10/2020
  8107                                  	;mov	byte [part_table_boot_ind+di], 0FFh
  8108                                  				; Invalid/Defective partition flag
  8109                                  	;retn
  8110                                  	; 16/10/2020
  8111                                  	; 31/10/2020
  8112                                  	;mov	byte [part_table_sys_id+di], 0	; Empty partition
  8113                                  	; 12/03/2021
  8114 00002216 6629C0                  	sub	eax, eax
  8115                                  	;
  8116 00002219 5E                      	pop	si
  8117 0000221A 59                      	pop	cx
  8118 0000221B E93DFF                  	jmp	ipt_16
  8119                                  
  8120                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  8121                                  ; set cylinder number to partition's start or end sector 
  8122                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  8123                                  ; 27/10/2020
  8124                                  
  8125                                  	; 09/03/2021
  8126                                  	; 06/11/2020 (32 bit cylinder numbers, upto 267349)
  8127                                  cylindernumberfix:
  8128                                  	; ax = 1022 -> set start cylinder
  8129                                  	; ax = 1023 -> set end cylinder
  8130                                  	; di = partition table structure offset
  8131                                  
  8132                                  	;; modified registers: ax, dx, bx
  8133                                  	; modified registers: eax, edx ; 09/03/2021
  8134                                  	
  8135 0000221E 3DFF03                  	cmp	ax, 1023
  8136 00002221 733D                    	jnb	short cnf_4 ; set end cylinder
  8137                                  	
  8138 00002223 80BD[6B6C]FE            	cmp	byte [part_table_start_head+di], 0FEh ; 254
  8139 00002228 7536                    	jne	short cnf_4 ; no need to fix (start cyl) 
  8140                                  			; 30/10/2020
  8141                                  	; 28/10/2020
  8142 0000222A 80BD[6C6C]3F            	cmp	byte [part_table_start_sector+di], 3Fh ; 63
  8143 0000222F 752F                    	jne	short cnf_4 ; no need to fix (start cyl)
  8144                                  			; 30/10/2020
  8145                                  
  8146                                  	;mov	ax, [part_table_rel_sec_lw+di] ; start sector, lw
  8147                                  	;mov	dx, [part_table_rel_sec_hw+di] ; start sector, hw
  8148                                  	;push	cx
  8149                                  	;mov	cx, [hs] ; [heads*spt]
  8150                                  	;call	div32
  8151                                  	;	; dx:ax = cylinder number, dx = 0, quotient	
  8152                                  	;	; bx = remainder
  8153                                  	;pop	cx
  8154                                  	;or 	dx, dx
  8155                                  	;jnz	short cnf_2 ; invalid
  8156                                  
  8157                                  	; 09/03/2021
  8158 00002231 668B85[786C]            	mov	eax, [part_table_rel_sec+di]
  8159 00002236 6631D2                  	xor	edx, edx
  8160 00002239 66F736[E469]            	div	dword [hs] ; [heads*spt] ; <= 16065
  8161                                  
  8162                                  	;cmp	ax, [part_table_start_cyl+di]
  8163                                  	; 09/03/2021
  8164 0000223E 663B85[6D6C]            	cmp	eax, [part_table_start_cyl+di]
  8165                                  	;je	short cnf_5
  8166 00002243 7407                    	je	short cnf_1
  8167 00002245 7213                    	jb	short cnf_2 ; invalid
  8168                                  	;mov	[part_table_start_cyl+di], ax ; change it
  8169                                  	; 09/03/2021
  8170 00002247 668985[6D6C]            	mov	[part_table_start_cyl+di], eax ; change it
  8171                                  	;jmp	short cnf_5 
  8172                                  cnf_1:
  8173 0000224C 80BD[726C]FE            	cmp	byte [part_table_end_head+di], 0FEh ; 254
  8174 00002251 7507                    	jne	short cnf_2 ; no need to fix (also invalid)
  8175                                  	
  8176                                  	; 28/10/2020
  8177 00002253 80BD[736C]3F            	cmp	byte [part_table_end_sector+di], 3Fh ; 63
  8178 00002258 7414                    	je	short cnf_5 ; fix
  8179                                  	; no need to fix (also invalid)
  8180                                  cnf_2:
  8181 0000225A C685[6A6C]FF            	mov	byte [part_table_boot_ind+di], 0FFh ; invalid PTE
  8182                                  cnf_3:
  8183 0000225F C3                      	retn
  8184                                  cnf_4:
  8185 00002260 80BD[726C]FE            	cmp	byte [part_table_end_head+di], 0FEh ; 254
  8186 00002265 75F8                    	jne	short cnf_3 ; no need to fix (end cyl)
  8187                                  	
  8188                                  	; 28/10/2020
  8189 00002267 80BD[736C]3F            	cmp	byte [part_table_end_sector+di], 3Fh ; 63
  8190 0000226C 75F1                    	jne	short cnf_3 ; no need to fix (end cyl)
  8191                                  cnf_5:
  8192                                  	;mov	ax, [part_table_rel_sec_lw+di] ; start sector, lw
  8193                                  	;mov	dx, [part_table_rel_sec_hw+di] ; start sector, hw
  8194                                  	;
  8195                                  	;add	ax, [part_table_num_sec_lw+di] ; number of sectors, lw 
  8196                                  	;adc	dx, [part_table_num_sec_hw+di] ; number of sectors, hw 
  8197                                  	;;jc	short cnf_2
  8198                                  
  8199                                  	; 09/03/2021
  8200 0000226E 668B85[786C]            	mov	eax, [part_table_rel_sec+di] ; start sector
  8201 00002273 660385[7C6C]            	add	eax, [part_table_num_sec+di] ; number of sectors
  8202                                  	;jc	short cnf_2 
  8203                                  
  8204                                  	;sub	ax, 1
  8205                                  	;sbb	dx, 0
  8206                                  	;	; dx:ax = end sector
  8207                                  	;push	cx
  8208                                  	;mov	cx, [hs] ; [heads*spt]
  8209                                  	;call	div32
  8210                                  	;	; dx:ax = cylinder number, dx = 0, quotient
  8211                                  	;	; bx = remainder
  8212                                  	;pop	cx
  8213                                  	;or 	dx, dx
  8214                                  	;jnz	short cnf_2 ; invalid
  8215                                  
  8216                                  	; 09/03/2021
  8217 00002278 6648                    	dec	eax  ; end sector
  8218 0000227A 6631D2                  	xor	edx, edx ; 12/03/2021
  8219 0000227D 66F736[E469]            	div	dword [hs]  ; [heads*spt] ; <= 16065
  8220                                  
  8221                                  	;cmp	ax, [part_table_end_cyl+di]
  8222                                  	; 09/03/2021
  8223 00002282 663B85[746C]            	cmp	eax, [part_table_end_cyl+di]
  8224 00002287 74D6                    	je	short cnf_3 ; same cylinder number
  8225 00002289 72CF                    	jb	short cnf_2 ; invalid
  8226                                  	;mov	[part_table_end_cyl+di], ax ; change it
  8227                                  	; 09/03/2021
  8228 0000228B 668985[746C]            	mov	[part_table_end_cyl+di], eax ; change it
  8229 00002290 C3                      	retn
  8230                                  
  8231                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  8232                                  ; sort partition table in (ending) cylinder number order
  8233                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  8234                                  ; 25/10/2020 (fdisk3.s)
  8235                                  
  8236                                  	; 10/03/2021 (fdisk4.s)
  8237                                  	; 02/02/2019 (hdimage.s)
  8238                                  	
  8239                                  sort_partition_table:
  8240                                  
  8241                                  	; INPUT -> none
  8242                                  	; OUTPUT -> none
  8243                                  
  8244 00002291 31DB                    	xor	bx, bx
  8245                                  	;jmp	short sortpt_2 ; 25/10/2020
  8246                                  sortpt_1:
  8247 00002293 889F[FA69]              	mov	[bx+sort], bl ; 0
  8248 00002297 FEC3                    	inc	bl
  8249                                  sortpt_2:
  8250 00002299 80FB04                  	cmp	bl, 4 ; number of partition table entries to sort
  8251 0000229C 72F5                    	jb	short sortpt_1
  8252                                  
  8253                                  	; Do a bubble sort
  8254                                  
  8255 0000229E EB04                    	jmp	short sortpt_4
  8256                                  sortpt_3:
  8257                                  	; Sort until we don't do a swap
  8258                                  
  8259 000022A0 08C9                    	or	cl, cl ; sort changed ?
  8260 000022A2 7454                    	jz	short sortpt_8 ; no
  8261                                  sortpt_4:
  8262 000022A4 30C9                    	xor	cl, cl
  8263                                  
  8264 000022A6 B301                    	mov	bl, 1
  8265                                  
  8266                                  	;mov	dl, 18  ; partition table structure size
  8267                                  	; 05/11/2020
  8268 000022A8 B216                    	mov	dl, 22
  8269 000022AA EB07                    	jmp	short sortpt_6
  8270                                  sortpt_5:
  8271 000022AC FEC3                    	inc	bl
  8272                                  
  8273 000022AE 80FB04                  	cmp	bl, 4
  8274 000022B1 73ED                    	jnb	short sortpt_3
  8275                                  
  8276                                  sortpt_6:
  8277 000022B3 8A87[FA69]              	mov	al, [bx+sort]
  8278                                  
  8279 000022B7 F6E2                    	mul	dl
  8280                                  
  8281 000022B9 89C6                    	mov	si, ax
  8282                                  
  8283                                  	;mov	di, [part_table_end_cyl+si]
  8284                                  
  8285 000022BB 8A87[F969]              	mov	al, [bx+sort-1]
  8286                                  
  8287 000022BF F6E2                    	mul	dl ; * 22 ; 05/11/2020
  8288                                  
  8289                                  	;xchg	di, ax
  8290                                  	; 10/03/2021
  8291 000022C1 89C7                    	mov	di, ax
  8292 000022C3 668B84[746C]            	mov	eax, [part_table_end_cyl+si]
  8293                                  
  8294                                  	;cmp	[part_table_end_cyl+di], ax ; previous > current
  8295                                  	; 10/03/2021
  8296 000022C8 663985[746C]            	cmp	[part_table_end_cyl+di], eax ; previous > current
  8297 000022CD 771B                    	ja	short sortpt_7 ; swap order indicators
  8298                                  		; 31/10/2020
  8299                                  		; current end cyl >= previous end cyl
  8300                                  	; 31/10/2020
  8301 000022CF 72DB                    	jb	short sortpt_5  
  8302                                  		; current end cyl > previous end cyl
  8303                                  	
  8304                                  	;and	ax, ax ; cylinder 0 ?
  8305                                  	; 10/03/2021
  8306 000022D1 6621C0                  	and	eax, eax ; cylinder 0 ?
  8307 000022D4 75D6                    	jnz	short sortpt_5 ; no
  8308                                  		; current end cyl = previous end cyl, cyl > 0
  8309                                  	
  8310                                  	; current end cyl = previous end cyl = 0
  8311                                  
  8312                                  	; If current entry is empty partition entry
  8313                                  	; and previous entry is not empty partition entry
  8314                                  	; swap them.
  8315                                  	
  8316                                  	;mov	ax, [part_table_num_sec_hw+di] ; previous entry
  8317                                  	;or	ax, [part_table_num_sec_lw+di]
  8318                                  	;jz	short sortpt_5
  8319                                  	; 10/03/2021
  8320 000022D6 668B85[7C6C]            	mov	eax, [part_table_num_sec+di] 
  8321 000022DB 6609C0                  	or	eax, eax
  8322 000022DE 74CC                    	jz	short sortpt_5
  8323                                  
  8324                                  	;mov	ax, [part_table_num_sec_hw+si] ; current entry
  8325                                  	;or	ax, [part_table_num_sec_lw+si]
  8326                                  	;jnz	short sortpt_5
  8327                                  	; 10/03/2021
  8328 000022E0 668B84[7C6C]            	mov	eax, [part_table_num_sec+si]
  8329 000022E5 6609C0                  	or	eax, eax
  8330 000022E8 75C2                    	jnz	short sortpt_5
  8331                                  sortpt_7:
  8332                                  	; Swap the order indicators
  8333                                  
  8334 000022EA 8B87[F969]              	mov	ax, [bx+sort-1]
  8335 000022EE 86E0                    	xchg	ah, al
  8336 000022F0 8987[F969]              	mov	[bx+sort-1], ax
  8337                                  
  8338 000022F4 B101                    	mov	cl, 1 ; sort changed
  8339 000022F6 EBB4                    	jmp	short sortpt_5
  8340                                  
  8341                                  sortpt_8:
  8342                                  	; 30/10/2020
  8343                                  	;mov 	byte [p_sorted], 1 ; 04/02/2019
  8344                                  
  8345                                  	; 10/03/2021
  8346                                  	;xor	eax, eax
  8347                                  
  8348 000022F8 C3                      	retn
  8349                                  
  8350                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  8351                                  ; find free space before/after/between partitions
  8352                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  8353                                  ; 03/02/2019
  8354                                  
  8355                                  	; 12/03/2021
  8356                                  	; 11/03/2021 (fdisk4.s) -32 bit cylinder numbers-
  8357                                  	;
  8358                                  find_part_free_space:  ; find/calculate free space for partitions
  8359                                  	; 15/02/2019
  8360                                  
  8361                                  	; INPUT -> 
  8362                                  	;	AL = 0 -> calculate for primary/MBR partitions
  8363                                  	;	AL = 5 -> calculate for extended partition
  8364                                  	; OUTPUT ->
  8365                                  	;	CX = the largest free space/cylinders (between partitions)
  8366                                  	;	AX = Free space index (gap number) - from 0 to 4 -
  8367                                  	;	BX = Free space structure offset (for the largest free space)
  8368                                  	;
  8369                                  	;	22/02/2019
  8370                                  	;	[freespace_count] = number of free spaces/gaps
  8371                                  
  8372                                  	; 12/03/2021
  8373                                  	; OUTPUT:
  8374                                  	;   ECX = the largest free space/cylinders (between partitions)
  8375                                  	;    AX = Free space index (gap number) - from 0 to 4 -
  8376                                  	;    BX = Free space structure offset (for the largest free space)
  8377                                  	;   (EDX = 0)
  8378                                  
  8379 000022F9 A2[146C]                	mov	[p_type], al
  8380                                  
  8381                                  	; Sort the partition table
  8382                                  
  8383 000022FC E892FF                  	call	sort_partition_table ; 16/02/2019
  8384                                  
  8385                                  	; Initialize free space to zero
  8386                                  
  8387                                  	; 15/02/2019
  8388 000022FF BF[1E6D]                	mov	di, fspc ; free_space.space
  8389 00002302 B92800                  	mov	cx, 5*8 ; (5*16/2)
  8390                                  	;mov	ecx, 5*8 ; 11/03/2021 
  8391                                  	;xor	ax, ax ; 0
  8392 00002305 6631C0                  	xor	eax, eax ; 11/03/2021
  8393 00002308 F3AB                    	rep	stosw
  8394                                  
  8395 0000230A A2[126C]                	mov	[freespace_count], al ; 0
  8396                                  	; 22/02/2019
  8397                                  	;mov	[last_found_partition], al ; 0
  8398                                  
  8399 0000230D A3[106C]                	mov	[_i_], ax ; 0
  8400                                  	;jmp	short fpfs_2
  8401                                  	; 31/10/020
  8402 00002310 EB0E                    	jmp	short fpfs_3
  8403                                  fpfs_1:	
  8404 00002312 FE06[106C]              	inc	byte [_i_]
  8405                                  ;;fpfs_2:
  8406 00002316 803E[106C]04            	cmp	byte [_i_], 4
  8407 0000231B 7203                    	jb	short fpfs_3
  8408 0000231D E96201                  	jmp	fpfs_13
  8409                                  fpfs_3:
  8410                                  	; Find space between start of disk and first partition
  8411                                  
  8412                                  	;mov	ax, [_i_]
  8413 00002320 8B1E[106C]              	mov	bx, [_i_] ; 31/10/2020
  8414                                  fpfs_2:
  8415                                  	;mov	bx, ax ; 31/10/2020
  8416                                  	;mov	al, [sort+bx]
  8417 00002324 8A8F[FA69]              	mov	cl, [sort+bx] ; 15/02/2019
  8418                                  
  8419                                  	;;mov	cl, 18 ; partition table structure size = 18 bytes
  8420                                  	;mov	al, 18 ; 15/02/2019
  8421                                  	; 05/11/2020
  8422 00002328 B016                    	mov	al, 22 ; partition table structure size = 22 bytes
  8423 0000232A F6E1                    	mul	cl
  8424 0000232C 89C3                    	mov	bx, ax
  8425                                  
  8426 0000232E 80BF[716C]00            	cmp	byte [part_table_sys_id+bx], 0
  8427 00002333 74DD                    	je	short fpfs_1
  8428                                  
  8429 00002335 880E[136C]              	mov	[last_found_partition], cl ; 15/02/2019
  8430                                  
  8431                                  	;xor	cx, cx
  8432 00002339 30C9                    	xor	cl, cl ; 0
  8433                                  	;mov	al, 1 ; LBA = 1 (after MBR) ; ah = 0
  8434                                  	; 03/11/2020
  8435 0000233B A0[A23C]                	mov	al, [sectors] ; 63 or 17 ; 03/11/2020	
  8436                                  
  8437 0000233E 803E[146C]05            	cmp	byte [p_type], 5  ; EXTENDED
  8438 00002343 7506                    	jne	short fpfs_4
  8439                                  
  8440                                  	; This is a special case - the extended partition can not start
  8441                                  	; on cylinder 0 due to its architecture. Protect against that here
  8442                                  
  8443                                  	; 13/02/2019
  8444                                  	; LBA value of free space start
  8445                                  	;mov	al, [sectors] ; 03/11/2020
  8446 00002345 F626[A43C]              	mul	byte [heads]
  8447                                  		; ax = start sector (for Extended Partition)
  8448 00002349 FEC1                    	inc	cl ; 1 ; cx = start cylinder = 1
  8449                                  fpfs_4:
  8450                                  	; Found a partition, get the space
  8451                                  
  8452                                  	; 15/02/2019
  8453                                  	;mov	dx, [part_table_start_cyl+bx] 
  8454                                  	;	       ; Start cylinder of the 1st partition (as sorted)
  8455                                  	;cmp	dx, cx ; (cx=0 for primary partition, cx=1 for extd partition)
  8456                                  	;jna	fpfs_9 ; It is accepted as free (partition) space
  8457                                  	;	       ; if this space between masterboot sector and partition 1
  8458                                  	;	       ; has 1 cylinder (heads*spt) size at least.
  8459                                  	
  8460                                  	; 11/03/2021
  8461 0000234B 668B97[6D6C]            	mov	edx, [part_table_start_cyl+bx]
  8462 00002350 6639CA                  	cmp	edx, ecx
  8463 00002353 0F86B400                	jna	fpfs_9
  8464                                  
  8465                                  	; 22/02/2019
  8466 00002357 31FF                    	xor	di, di  ; 0 ; Reset Free Space Table offset
  8467                                  
  8468 00002359 FE06[126C]              	inc	byte [freespace_count]	; mov byte [freespace_count], 1
  8469                                  
  8470                                  	;mov	[free_space.start], cx ; 0 (for PP) or 1 (for EP)
  8471                                  	; 11/03/2021
  8472 0000235D 66890E[226D]            	mov	[free_space.start], ecx	
  8473                                  
  8474                                  	; non-aligned address of start sector (for the 1st partition as sorted)
  8475                                  	; NOTE: later, start sector will be moved to (chs) head 1 and sector 1
  8476                                  	;	if new partition will be selected as a primary dos partition.
  8477                                  	;	(But, start sector -LBA- will not be changed 
  8478                                  	;	 if it is a non-dos or user input type partition.. unless
  8479                                  	;	 cylinder boundary alignment option is used.)
  8480                                  	 	
  8481 00002362 A3[2E6D]                	mov	[free_space.startsector], ax ; = [sectors]*[heads] (for EP)
  8482                                  					     ; or 1 (for PP)
  8483                                  	;mov	[free_space.startsector+2], 0
  8484                                  
  8485                                  	; free space ends before start of next valid partition
  8486                                  	;mov	ax, dx	; start cylinder of partition 1 (as sorted)
  8487                                  	;sub	dx, cx	; cylinder count of free space 1 (gap 1)
  8488                                  	;dec	ax	; end cylinder of free space 1 (gap 1)
  8489                                  	;mov	[free_space.end], ax
  8490                                  	;mov	[free_space.space], dx
  8491                                  	; 11/03/2021
  8492 00002365 6689D0                  	mov	eax, edx
  8493 00002368 6629CA                  	sub	edx, ecx
  8494 0000236B 6648                    	dec	eax
  8495 0000236D 66A3[266D]              	mov	[free_space.end], eax
  8496 00002371 668916[1E6D]            	mov	[free_space.space], edx
  8497                                  
  8498                                  	; save free space (1) as (non-aligned) sector count
  8499                                  	;mov	ax, [part_table_rel_sec_lw+bx]
  8500                                  	;mov	dx, [part_table_rel_sec_hw+bx]
  8501                                  	;sub	ax, [free_space.startsector]
  8502                                  	;sbb	dx, 0
  8503                                  	;mov	[free_space.sectors_unused], ax
  8504                                  	;mov	[free_space.sectors_unused+2], dx
  8505                                  	; 11/03/2021
  8506 00002376 668B87[786C]            	mov	eax, [part_table_rel_sec+bx]
  8507 0000237B 662B06[2E6D]            	sub	eax, [free_space.startsector]
  8508 00002380 66A3[2A6D]              	mov	[free_space.sectors_unused], eax
  8509                                  
  8510                                  	;mov	ax, [free_space.space]
  8511                                  
  8512                                  	;call	cylinders_to_sectors
  8513                                  
  8514                                  	;mov	[free_space.sectors_unused], ax
  8515                                  	;mov	[free_space.sectors_unused+2], dx
  8516                                  
  8517                                  	;mov	cx, [cylinders]		; Total (disk) cylinders -divisor-
  8518                                  	;mov	bx, [free_space.space]	; Partition cylinders -dividend-
  8519                                  	; 12/03/2021
  8520 00002384 66A1[1E6D]              	mov	eax, [free_space.space]
  8521                                  
  8522 00002388 E8E501                  	call	cylinders_to_percent
  8523                                  
  8524 0000238B A3[326D]                	mov	[free_space.percent_unused], ax
  8525                                  
  8526                                  	; 15/02/2019
  8527                                  	;mov	bl, [_i_]
  8528                                  	;xor	bh, bh
  8529                                  	;mov	al, [sort+bx]
  8530                                  
  8531                                  	;mov	[last_found_partition], al
  8532                                  
  8533                                  	; 31/10/2020
  8534 0000238E EB7B                    	jmp	fpfs_9
  8535                                  
  8536                                  	; Look for space between the rest of the partitions
  8537                                  
  8538                                  fpfs_7:
  8539                                  	; ah = 0
  8540                                  	;mov	al, [_i_]
  8541                                  	;;cbw
  8542                                  	;mov	bx, ax
  8543                                  	; 22/02/2019
  8544 00002390 8B1E[106C]              	mov	bx, [_i_]
  8545                                  
  8546                                  	; 15/02/2019
  8547                                  	;mov	al, [sort+bx]
  8548 00002394 8A8F[FA69]              	mov	cl, [sort+bx]
  8549                                  	;;mov	bl, 18
  8550                                  	;;mul	bl
  8551                                  	;mov	al, 18
  8552                                  	; 05/11/2020
  8553 00002398 B016                    	mov	al, 22
  8554 0000239A F6E1                    	mul	cl
  8555 0000239C 89C6                    	mov	si, ax
  8556                                  	
  8557 0000239E 80BC[716C]00            	cmp	byte [part_table_sys_id+si], 0
  8558 000023A3 7466                    	je	short fpfs_9
  8559                                  
  8560                                  	; 15/02/2019
  8561 000023A5 860E[136C]              	xchg	[last_found_partition], cl
  8562                                  
  8563                                  	; Check to see if more than one partition on a cylinder
  8564                                  	; If so, leave the space at zero */
  8565                                  
  8566                                  	; NOTE:
  8567                                  	; If free space (gap) between partitions
  8568                                  	; has 1 cylinder (heads*spt) size at least..
  8569                                  	; ..It is accepted as valid free (partition) space.
  8570                                  
  8571                                  	;mov	al, 18 ; Partition tables/data structure size = 18 bytes
  8572                                  	; 05/11/2020
  8573 000023A9 B016                    	mov	al, 22 ; Partition tables/data structure size = 22 bytes
  8574 000023AB F6E1                    	mul	cl
  8575 000023AD 89C3                    	mov	bx, ax  ; ah = 0
  8576                                  
  8577                                  	;mov	dx, [part_table_end_cyl+bx]   ; end cyl. of previous partition 
  8578                                  	;mov	ax, [part_table_start_cyl+si] ; start cyl. of current partition
  8579                                  	;
  8580                                  	;inc	dx  ; start cylinder of free space is after the end cylinder of
  8581                                  	;	    ; the previous partition (as sorted)
  8582                                  	;
  8583                                  	;cmp	ax, dx ; and it must be before than the next partition (as sorted)
  8584                                  	;jna	short fpfs_9 ; je short fpfs_9
  8585                                  	
  8586                                  	; 12/03/2021
  8587 000023AF 668B97[746C]            	mov	edx, [part_table_end_cyl+bx]   ; end cyl. of previous partition
  8588 000023B4 668B8C[6D6C]            	mov	ecx, [part_table_start_cyl+si] ; start cyl. of current partition
  8589                                  	
  8590 000023B9 6642                    	inc	edx ; start cylinder of free space is after the end cylinder of
  8591                                  		    ; the previous partition (as sorted)
  8592                                  	
  8593 000023BB 6639D1                  	cmp	ecx, edx ; and it must be before than the next partition (as sorted)
  8594 000023BE 764B                    	jna	short fpfs_9 ; je short fpfs_9
  8595                                  	
  8596                                  	; No, things are normal
  8597                                  	; Get space between the end of the last one and the start of the next one
  8598                                  
  8599                                  	; 22/02/2019
  8600                                  	;;add	di, 16
  8601                                  	;mov	di, [freespace_count]
  8602                                  	;shl	di, 4	; * 16 ; next entry offset (in free space table)
  8603                                  	; 12/03/2021
  8604 000023C0 B016                    	mov	al, 22  ; ah = 0
  8605 000023C2 F626[126C]              	mul	byte [freespace_count]
  8606 000023C6 89C7                    	mov	di, ax
  8607                                  
  8608 000023C8 FE06[126C]              	inc	byte [freespace_count]
  8609                                  
  8610                                  	;mov	cx, ax
  8611 000023CC 6689C8                  	mov	eax, ecx
  8612                                  	;sub	cx, dx
  8613 000023CF 6629D1                  	sub	ecx, edx
  8614                                  	;dec	ax
  8615 000023D2 6648                    	dec	eax
  8616                                  	;mov	[free_space.start+di], dx
  8617                                  	;mov	[free_space.end+di], ax
  8618                                  	;mov	[free_space.space+di], cx
  8619                                  
  8620 000023D4 668995[226D]            	mov	[free_space.start+di], edx
  8621 000023D9 668985[266D]            	mov	[free_space.end+di], eax
  8622 000023DE 66898D[1E6D]            	mov	[free_space.space+di], ecx
  8623                                  
  8624                                  	;mov	ax, [free_space.space+di]
  8625                                  	;call	cylinders_to_sectors
  8626                                  	;mov	[free_space.sectors_unused+di], ax
  8627                                  	;mov	[free_space.sectors_unused+2+di], dx
  8628                                  
  8629                                  	; calculate and save (non-aligned) free sector count between partitions
  8630                                  
  8631                                  	;mov	ax, [part_table_rel_sec_lw+bx]
  8632                                  	;mov	dx, [part_table_rel_sec_hw+bx]
  8633                                  	; 12/03/2021
  8634 000023E3 668B87[786C]            	mov	eax, [part_table_rel_sec+bx]
  8635                                  
  8636                                  	;add	ax, [part_table_num_sec_lw+bx]
  8637                                  	;adc	dx, [part_table_num_sec_hw+bx]
  8638 000023E8 660387[7C6C]            	add	eax, [part_table_num_sec+bx]
  8639                                  
  8640                                  	;mov	cx, [part_table_rel_sec_lw+si]
  8641                                  	;mov	bx, [part_table_rel_sec_hw+si]
  8642 000023ED 668B94[786C]            	mov	edx, [part_table_rel_sec+si]
  8643                                  
  8644                                  	;mov	[free_space.startsector+di], ax
  8645                                  	;mov	[free_space.startsector+2+di], dx
  8646 000023F2 668985[2E6D]            	mov	[free_space.startsector+di], eax
  8647                                  
  8648                                  	;sub	cx, ax
  8649                                  	;sbb	bx, dx
  8650 000023F7 6629C2                  	sub	edx, eax
  8651                                  
  8652                                  	;mov	[free_space.sectors_unused+di], cx
  8653                                  	;mov	[free_space.sectors_unused+2+di], bx
  8654 000023FA 668995[2A6D]            	mov	[free_space.sectors_unused+di], edx
  8655                                  
  8656                                  fpfs_8:
  8657                                  	; NOTE: Percentage is based on cylinder-boundary aligned partition size.
  8658                                  	; (total disk cylinders and partition's cylinder count are used for that)
  8659                                  
  8660                                  	;mov	cx, [cylinders] ; -divisor-
  8661                                  	;mov	bx, [free_space.space+di] ; -dividend-
  8662                                  	; 12/03/2021
  8663 000023FF 668B85[1E6D]            	mov	eax, [free_space.space+di]
  8664                                  
  8665 00002404 E86901                  	call	cylinders_to_percent
  8666                                  	
  8667 00002407 8985[326D]              	mov	[free_space.percent_unused+di], ax
  8668                                  	
  8669                                  	; ah = 0
  8670                                  
  8671                                  	; 15/02/2019
  8672                                  	;mov	bl, [_i_]
  8673                                  	;xor	bh, bh
  8674                                  	;mov	al, [sort+bx]
  8675                                  	;	
  8676                                  	;mov	[last_found_partition], al
  8677                                  
  8678                                  fpfs_9:
  8679 0000240B FE06[106C]              	inc	byte [_i_]
  8680                                  fpfs_10:
  8681 0000240F 803E[106C]04            	cmp	byte [_i_], 4
  8682 00002414 7303                    	jnb	short fpfs_11
  8683                                  
  8684 00002416 E977FF                  	jmp	fpfs_7
  8685                                  
  8686                                  fpfs_11:
  8687                                  	; Find the space between the last partition and the end of the disk
  8688                                  	; Make sure that freespace cannot become negative
  8689                                  
  8690 00002419 A0[136C]                	mov	al, [last_found_partition]
  8691                                  	;mov	cl, 18  ; Partition table structure size = 18 bytes
  8692                                  	; 05/11/2020
  8693 0000241C B116                    	mov	cl, 22  ; Partition table structure size = 22 bytes
  8694 0000241E F6E1                    	mul	cl
  8695 00002420 89C3                    	mov	bx, ax
  8696                                  	;mov	cx, [cylinders]
  8697                                  	;dec	cx ; 15/02/2019 
  8698                                  	;	   ; (min. cylinder count = 1 for a valid/usable free space)
  8699                                  	;;mov	ax, [part_table_end_cyl+bx]
  8700                                  	; 12/03/2021
  8701 00002422 668B0E[A63C]            	mov	ecx, [cylinders]
  8702 00002427 6649                    	dec	ecx 	
  8703                                  
  8704                                  	; 05/11/2020
  8705                                  	;cmp	[part_table_end_cyl+bx], cx
  8706                                  	;;cmp	ax, cx	; cx = end cylinder of the disk
  8707                                  	;jb	short fpfs_12
  8708                                  	; 12/03/2021
  8709 00002429 66398F[746C]            	cmp	[part_table_end_cyl+bx], ecx
  8710 0000242E 7203                    	jb	short fpfs_12
  8711                                  
  8712 00002430 E99E00                  	jmp	fpfs_15
  8713                                  fpfs_12:
  8714                                  	; 22/02/2019
  8715                                  	;mov	di, [freespace_count]
  8716                                  	;;shl	di, 4 ; * 16  ; next entry offset (in free space table)
  8717                                  	; 05/11/2020
  8718                                  	;mov	ax, 22
  8719                                  	;mul	word [freespace_count]
  8720                                  	;mov	di, ax
  8721                                  	; 12/03/2021
  8722 00002433 B016                    	mov	al, 22
  8723 00002435 F626[126C]              	mul	byte [freespace_count]
  8724 00002439 89C7                    	mov	di, ax
  8725                                  
  8726 0000243B FE06[126C]              	inc	byte [freespace_count]
  8727                                  
  8728                                  	;mov	[free_space.end+di], cx	; end cyl. of free space 5 (gap 5) 
  8729                                  	; 12/03/2021
  8730 0000243F 66898D[266D]            	mov	[free_space.end+di], ecx
  8731                                  
  8732                                  	; 05/11/2020
  8733                                  	;mov	ax, [part_table_end_cyl+bx]
  8734                                  	;mov	dx, cx	; cx = end cylinder of the disk
  8735                                  	;sub	dx, ax	; ax = end cylinder of the last partition
  8736                                  	;mov	[free_space.space+di], dx ; di = 4*22 ; 05/11/2020
  8737                                  	;inc	ax
  8738                                  	;mov	[free_space.start+di], ax
  8739                                  	; 12/03/2021
  8740 00002444 668B87[746C]            	mov	eax, [part_table_end_cyl+bx]
  8741                                  	; eax = end cylinder of the last partition
  8742                                  	; ecx = end cylinder of the disk
  8743 00002449 6629C1                  	sub	ecx, eax
  8744 0000244C 66898D[1E6D]            	mov	[free_space.space+di], ecx ; di = 4*22
  8745 00002451 6640                    	inc	eax
  8746 00002453 668985[226D]            	mov	[free_space.start+di], eax
  8747                                  
  8748                                  	;inc	cx ; [cylinders]
  8749                                  	;mov	ax, [free_space.space+si]
  8750                                  	;call	cylinders_to_sectors
  8751                                  	;mov	[free_space.sectors_unused+di], ax
  8752                                  	;mov	[free_space.sectors_unused+2+di], dx
  8753                                  
  8754                                  	; calculate and save (non-aligned) free sector count
  8755                                  
  8756                                  	; 22/02/2019
  8757                                  	;mov	ax, [part_table_rel_sec_lw+bx]
  8758                                  	;mov	dx, [part_table_rel_sec_hw+bx]
  8759                                  	;add	ax, [part_table_num_sec_lw+bx]
  8760                                  	;adc	dx, [part_table_num_sec_hw+bx]
  8761                                  	; 12/03/2021
  8762 00002458 668B87[786C]            	mov	eax, [part_table_rel_sec+bx]
  8763 0000245D 660387[7C6C]            	add	eax, [part_table_num_sec+bx]
  8764                                  
  8765                                  	;mov	[free_space.startsector+di], ax
  8766                                  	;mov	[free_space.startsector+2+di], dx
  8767 00002462 668985[2E6D]            	mov	[free_space.startsector+di], eax
  8768                                  
  8769                                  	;mov	cx, [total_sectors]
  8770                                  	;mov	bx, [total_sectors+2]
  8771                                  	;sub	cx, ax
  8772                                  	;sbb	bx, dx
  8773                                  	; 12/03/2021
  8774 00002467 668B0E[2665]            	mov	ecx, [total_sectors]
  8775 0000246C 6629C1                  	sub	ecx, eax
  8776                                  
  8777                                  	;mov	[free_space.sectors_unused+di], cx
  8778                                  	;mov	[free_space.sectors_unused+2+di], bx
  8779 0000246F 66898D[2A6D]            	mov	[free_space.sectors_unused+di], ecx
  8780                                  
  8781                                  	;mov	cx, [cylinders]
  8782                                  	;mov	bx, [free_space.space+di]
  8783                                  	; 12/03/2021
  8784 00002474 668B85[1E6D]            	mov	eax, [free_space.space+di]
  8785 00002479 E8F400                  	call	cylinders_to_percent
  8786 0000247C 8985[326D]              	mov	[free_space.percent_unused+di], ax
  8787 00002480 EB4F                    	jmp	short fpfs_15
  8788                                  
  8789                                  fpfs_13:
  8790                                  	; No partitions found, show entire space as free
  8791                                  
  8792                                  	; 22/02/2019
  8793 00002482 FE06[126C]              	inc	byte [freespace_count]	; mov byte [freespace_count], 1
  8794                                  	
  8795                                  	; 15/02/2019
  8796                                  	;;sub	ax, ax
  8797                                  	;; ah = 0 ; 31/10/2020
  8798                                  	;sub	dx, dx
  8799                                  	; 12/03/2021
  8800 00002486 6629D2                  	sub	edx, edx
  8801                                  
  8802                                  	;;inc	al ; LBA = 1 (after MBR) ; ah = 0
  8803                                  	;mov	al, 1 ; 25/02/2019
  8804                                  	; 12/03/2021
  8805 00002489 6631C0                  	xor	eax, eax
  8806 0000248C FEC0                    	inc	al ; eax = 1
  8807                                  
  8808                                  	;This is a special case - the extended partition can not start
  8809                                  	;on cylinder 0 due to its architecture. Protect against that here
  8810                                  
  8811 0000248E 803E[146C]05            	cmp	byte [p_type], 5 ; EXTENDED
  8812 00002493 7509                    	jne	short fpfs_14
  8813                                  
  8814 00002495 FEC2                    	inc	dl
  8815                                  
  8816                                  	; 15/02/2019
  8817                                  	; LBA value of free space start
  8818 00002497 A0[A23C]                	mov	al, [sectors]
  8819 0000249A F626[A43C]              	mul	byte [heads]
  8820                                  		; ax = start sector (for Extended Partition)
  8821                                  fpfs_14:
  8822                                  	;mov	[free_space.start], dx ; 0 or 1
  8823                                  	; 12/03/2021
  8824 0000249E 668916[226D]            	mov	[free_space.start], edx ; 0 or 1
  8825                                  
  8826                                  	; non-aligned address of start sector (for the 1st partition as sorted)
  8827                                  	; NOTE: later, start sector will be moved to (chs) head 1 and sector 1
  8828                                  	;	if new partition will be selected as a primary dos partition.
  8829                                  	 	
  8830                                  	;mov	[free_space.startsector], ax ; = [sectors]*[heads] (for EP)
  8831                                  	;				     ; or 1 (for PP)
  8832                                  	;;mov	[free_space.startsector+2], 0
  8833                                  	; 12/03/2021
  8834 000024A3 66A3[2E6D]              	mov	[free_space.startsector], eax
  8835                                  
  8836                                  	;mov	ax, [cylinders] ; disk capacity 
  8837                                  	;mov	cx, ax
  8838                                  	;dec	ax
  8839                                  	;mov	[free_space.end], ax
  8840                                  	;sub	ax, dx
  8841                                  	;inc	ax
  8842                                  	;mov	[free_space.space], ax
  8843                                  	; 12/03/2021
  8844 000024A7 66A1[A63C]              	mov	eax, [cylinders] ; disk capacity 
  8845 000024AB 6648                    	dec	eax
  8846 000024AD 66A3[266D]              	mov	[free_space.end], eax
  8847 000024B1 6629D0                  	sub	eax, edx
  8848 000024B4 6640                    	inc	eax
  8849 000024B6 66A3[1E6D]              	mov	[free_space.space], eax
  8850                                  
  8851                                  	;mov	ax, [total_sectors]
  8852                                  	;mov	dx, [total_sectors+2]
  8853                                  	;sub	ax, [free_space.startsector]
  8854                                  	;sbb	dx, 0
  8855                                  	;mov	[free_space.sectors_unused], ax
  8856                                  	;mov	[free_space.sectors_unused+2], dx
  8857                                  	; 12/03/2021
  8858 000024BA 66A1[2665]              	mov	eax, [total_sectors]
  8859 000024BE 662B06[2E6D]            	sub	eax, [free_space.startsector]
  8860 000024C3 66A3[2A6D]              	mov	[free_space.sectors_unused], eax
  8861                                  
  8862                                  	;;mov	cx, [cylinders]
  8863                                  	;mov	bx, [free_space.space]
  8864                                  	; 12/03/2021
  8865 000024C7 66A1[1E6D]              	mov	eax, [free_space.space]
  8866 000024CB E8A200                  	call	cylinders_to_percent
  8867 000024CE A3[326D]                	mov	[free_space.percent_unused], ax
  8868                                  
  8869                                  fpfs_15:
  8870                                  	; Find largest free space
  8871                                  	;sub	cx, cx
  8872                                  	; 12/03/2021
  8873 000024D1 6629C9                  	sub	ecx, ecx
  8874 000024D4 6629C0                  	sub	eax, eax
  8875                                  
  8876                                  	; 22/02/2019
  8877                                  	;sub	ax, ax
  8878 000024D7 31DB                    	xor	bx, bx
  8879 000024D9 8A16[126C]              	mov	dl, [freespace_count]
  8880 000024DD 08D2                    	or	dl, dl
  8881 000024DF 7423                    	jz	short fpfs_19
  8882 000024E1 8816[106C]              	mov	[_i_], dl
  8883                                  fpfs_16:
  8884                                  	;mov	dx, [free_space.space+bx]
  8885                                  	; 12/03/2021
  8886 000024E5 668B97[1E6D]            	mov	edx, [free_space.space+bx]
  8887                                  	;cmp	dx, cx
  8888 000024EA 6639CA                  	cmp	edx, ecx
  8889 000024ED 7605                    	jbe	short fpfs_17
  8890                                  	; 22/02/2019
  8891                                  	;mov	cx, dx ; Largest free space
  8892                                  	; 12/03/2021
  8893 000024EF 6689D1                  	mov	ecx, edx ; Largest free space
  8894 000024F2 89D8                    	mov	ax, bx
  8895                                  fpfs_17:
  8896 000024F4 FE0E[106C]              	dec	byte [_i_]
  8897 000024F8 7405                    	jz	short fpfs_18
  8898                                  
  8899                                  	;add	bx, 16 ; Free space structure size
  8900                                  	; 12/03/2021
  8901 000024FA 83C316                  	add	bx, 22
  8902 000024FD EBE6                    	jmp	short fpfs_16
  8903                                  fpfs_18:
  8904                                  	; 22/02/2019
  8905 000024FF 89C3                    	mov	bx, ax ; offset (from 0 to 64)
  8906                                  	; bx = offset (from 0 to 88) ; 12/03/2021
  8907 00002501 C0E804                  	shr	al, 4  ; index (from 0 to 4)
  8908                                  fpfs_19:
  8909 00002504 6631D2                  	xor	edx, edx ; 12/03/2021
  8910 00002507 C3                      	retn
  8911                                  
  8912                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  8913                                  ; find enough free space
  8914                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  8915                                  
  8916                                  ;	; 15/02/2019
  8917                                  ;find_enough_free_space:
  8918                                  ;	; Find enough free space
  8919                                  ;	;
  8920                                  ;	; INPUT:
  8921                                  ;	;	AX = Requested space (in cylinders)
  8922                                  ;	;	22/02/2019
  8923                                  ;	;	[freespace_count] = number of free spaces/gaps
  8924                                  ;	; OUTPUT:
  8925                                  ;	;	AX = Available space
  8926                                  	;	DX = Requested space
  8927                                  ;	;	If CF = 0 -> AX >= DX
  8928                                  ;	;	If CF = 1 -> AX < DX
  8929                                  ;	;	CX = Index of available space in free space structure
  8930                                  ;	;	     (GAP number, 0 to 4) - if AX > 0 -
  8931                                  ;
  8932                                  ;	mov	dx, ax ; 22/02/2019
  8933                                  ;	sub	ax, ax
  8934                                  ;	xor	bx, bx
  8935                                  ;	; 22/02/2019
  8936                                  ;	mov	ch, [freespace_count]
  8937                                  ;	mov	[_i_], ax ; 0
  8938                                  ;	jmp	short fefs_1
  8939                                  ;fefs_0:
  8940                                  ;	;mov	al, 16
  8941                                  ;	;mul	byte [_i_]
  8942                                  ;	;mov	bx, ax
  8943                                  ;	mov	bl, [_i_]
  8944                                  ;	shl	bl, 4 ; * 16
  8945                                  ;fefs_1:
  8946                                  ;	mov	ax, [free_space.space+bx]
  8947                                  ;	and	ax, ax
  8948                                  ;	jz	short fefs_2 ; not a free space
  8949                                  ;	mov	cl, [_i_] 
  8950                                  ;	cmp	ax, dx
  8951                                  ;	jnb	short fefs_3 ; enough space
  8952                                  ;fefs_2:
  8953                                  ;	; 22/02/2019
  8954                                  ;	inc	byte [_i_]
  8955                                  ;	cmp	byte [_i_], ch
  8956                                  ;	jb	short fefs_0
  8957                                  ;	sub	ch, ch
  8958                                  ;	stc
  8959                                  ;	retn
  8960                                  ;fefs_3:
  8961                                  ;	xor	ch, ch
  8962                                  ;	retn
  8963                                  
  8964                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  8965                                  ; find enough free sectors
  8966                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  8967                                  
  8968                                  	; 15/03/2021 (fdisk4.s)
  8969                                  	;	((32 bit registers, 32 bit cylinder numbers))
  8970                                  	; 15/02/2019
  8971                                  find_enough_free_sectors:
  8972                                  	; Find (first) enough free space in sectors
  8973                                  	;
  8974                                  	; INPUT:
  8975                                  	;	DX:AX = Requested space (as non-aligned free sectors)
  8976                                  	;	22/02/2019
  8977                                  	;	[freespace_count] = number of free spaces/gaps
  8978                                  	; OUTPUT:
  8979                                  	;	DX:AX = Available space
  8980                                  	;	If CF = 0 -> DX:AX >= Request
  8981                                  	;	If CF = 1 -> DX:AX < Request
  8982                                  	;	CX = Index of available space in free space structure
  8983                                  	;	     (GAP number, 0 to 4) - if DX:AX > 0 -
  8984                                  
  8985                                  	; 15/03/2021
  8986                                  	; INPUT:
  8987                                  	;	EAX = Requested space (as non-aligned free sectors)
  8988                                  	;	[freespace_count] = number of free spaces/gaps
  8989                                  	; OUTPUT:
  8990                                  	;	EAX = Available space
  8991                                  	;	If CF = 0 -> EAX >= Request
  8992                                  	;	If CF = 1 -> EAX < Request
  8993                                  	;	CX = Index of available space in free space structure
  8994                                  	;	     (GAP number, 0 to 4) - if EAX > 0 -
  8995                                  
  8996                                  	;xor	di, di
  8997                                  	;xor	si, si
  8998                                  	; 15/03/2021
  8999 00002508 6631D2                  	xor	edx, edx
  9000                                  
  9001 0000250B 31DB                    	xor	bx, bx
  9002                                  	; 22/02/2019
  9003 0000250D 8A2E[126C]              	mov	ch, [freespace_count]
  9004 00002511 891E[106C]              	mov	[_i_], bx ; 0
  9005 00002515 EB07                    	jmp	short fefss_1
  9006                                  fefss_0:
  9007                                  	;mov	al, 16
  9008                                  	;mul	byte [_i_]
  9009                                  	;mov	bx, ax
  9010 00002517 8B1E[106C]              	mov	bx, [_i_]
  9011 0000251B C0E304                  	shl	bl, 4 ; * 16
  9012                                  fefss_1:
  9013 0000251E 81C3[2A6D]              	add	bx, free_space.sectors_unused
  9014                                  	;cmp	dx, [bx+2]
  9015                                  	;jb	short fefss_7
  9016                                  	;ja	short fefss_2
  9017                                  	;cmp	ax, [bx]
  9018                                  	;je	short fefss_8
  9019                                  	;jb	short fefss_7 ; 18/02/2019
  9020                                  	; 15/03/2021
  9021 00002522 663B07                  	cmp	eax, [bx]
  9022 00002525 7426                    	je	short fefss_8 ; available space
  9023                                  			      ; = requested space
  9024 00002527 7221                    	jb	short fefss_7 ; > requested space
  9025                                  fefss_2:
  9026                                  	; 30/10/2020
  9027                                  	;;cmp	word [bx], 0
  9028                                  	;;jne	short fefss_3
  9029                                  	;;cmp	word [bx+2], 0
  9030                                  	;;je	short fefss_6
  9031                                  fefss_3:
  9032                                  	;cmp	di, [bx+2]
  9033                                  	;ja	short fefss_6
  9034                                  	;je	short fefss_4
  9035                                  	;mov	di, [bx+2]
  9036                                  	;jmp	short fefss_5
  9037                                  fefss_4:
  9038                                  	;cmp	si, [bx]
  9039                                  	;jnb	short fefss_6
  9040                                  	; 15/03/2021
  9041 00002529 66673B3B                	cmp	edi, [ebx]
  9042 0000252D 7307                    	jnb	short fefss_6
  9043                                  fefss_5:
  9044                                  	;mov	si, [bx]
  9045                                  	; 15/03/2021
  9046 0000252F 668B17                  	mov	edx, [bx]
  9047                                  	; 22/02/2019
  9048 00002532 8A0E[106C]              	mov	cl, [_i_]
  9049                                  fefss_6:
  9050 00002536 FE06[106C]              	inc	byte [_i_]
  9051 0000253A 382E[106C]              	cmp	byte [_i_], ch ; [freespace_count]
  9052 0000253E 72D7                    	jb	short fefss_0
  9053                                  	
  9054                                  	;mov	ax, si
  9055                                  	;mov	dx, di
  9056                                  	; 15/03/2021
  9057 00002540 6689D0                  	mov	eax, edx ; (max.) available space
  9058                                  			 ; (< requested space)
  9059 00002543 6629D2                  	sub	edx, edx
  9060                                  	;
  9061 00002546 30ED                    	xor	ch, ch
  9062 00002548 F9                      	stc
  9063 00002549 C3                      	retn
  9064                                  fefss_7:
  9065                                  	;mov	ax, [bx]
  9066                                  	;mov	dx, [bx+2]
  9067                                  	; 15/03/2021
  9068 0000254A 668B07                  	mov	eax, [bx] ; available space
  9069                                  			  ; (> requested space)
  9070                                  fefss_8:
  9071 0000254D 8B0E[106C]              	mov	cx, [_i_]
  9072                                  	; 15/03/2021
  9073 00002551 6631D2                  	xor	edx, edx
  9074                                  	;
  9075 00002554 C3                      	retn
  9076                                  
  9077                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  9078                                  ; get first free partition table entry
  9079                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  9080                                  
  9081                                  	; 16/02/2019
  9082                                  get_first_free_pte:
  9083                                  	; Find free partition table entry
  9084                                  	;
  9085                                  	; INPUT:
  9086                                  	;	none
  9087                                  	; OUTPUT:
  9088                                  	;	If CF = 0 -> CX = partition table entry number
  9089                                  	;	If CF = 1 -> there is not a free entry in partition table
  9090                                  
  9091 00002555 BE[8A54]                	mov	si, MasterBootBuff+pTableOffset
  9092 00002558 31C9                    	xor	cx, cx
  9093                                  gffp_1:
  9094 0000255A 8A4404                  	mov	al, [si+ptFileSystemID] ; 23/02/2019
  9095                                  
  9096 0000255D 20C0                    	and	al, al
  9097 0000255F 740E                    	jz	short gffp_3 ; empty
  9098                                  
  9099 00002561 80F903                  	cmp	cl, 3
  9100 00002564 7307                    	jnb	short gffp_2
  9101                                  
  9102 00002566 FEC1                    	inc	cl
  9103 00002568 83C610                  	add	si, 16 ; Partition table entry size
  9104 0000256B EBED                    	jmp	short gffp_1
  9105                                  gffp_2:
  9106                                  	; CL = 3
  9107 0000256D F9                      	stc
  9108 0000256E C3                      	retn
  9109                                  gffp_3:
  9110                                  	; CL = PTE number (0 to 3)
  9111 0000256F C3                      	retn 	
  9112                                  
  9113                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  9114                                  ; convert cylinder count to sectors
  9115                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  9116                                  ; 03/02/2019
  9117                                  
  9118                                  	; 15/03/2021 (fdisk4.s)
  9119                                  ;cylinders_to_sectors:
  9120                                  	; INPUT:
  9121                                  	;	ax = Cylinders (Total or partition's cylinder count)
  9122                                  	; OUTPUT:
  9123                                  	;	dx:ax = Sectors
  9124                                  
  9125                                  	; 15/03/2021
  9126                                  	; INPUT:
  9127                                  	;	eax = cylinders (Total or partition's cyl count)
  9128                                  	; OUTPUT:
  9129                                  	;	eax = sectors
  9130                                  
  9131                                  	;;mov	dx, [heads]
  9132                                  	;;mul	dx
  9133                                  	;; 30/10/2020
  9134                                  	;mul	word [heads]
  9135                                  	;; dx:ax = Number of tracks (cylinders*heads)
  9136                                  	;mov	cx, [sectors]
  9137                                  	;call	mul32
  9138                                  	;	; dx:ax = Number of sectors
  9139                                  	;retn
  9140                                  
  9141                                  	; 15/03/2021
  9142                                  	;mul	dword [hs] ; [heads] * [sectors]
  9143                                  	;; eax = number of sectors
  9144                                  	;retn
  9145                                  	
  9146                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  9147                                  ; convert cylinder count to percent of disk size (total cylinders)
  9148                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  9149                                  ; 03/02/2019
  9150                                  
  9151                                  	; 12/03/2021
  9152                                  	; 11/03/2021 (fdisk4.s) - 32 bit cylinder count-
  9153                                  	;
  9154                                  cylinders_to_percent:
  9155                                  
  9156                                  	; INPUT:
  9157                                  	;	bx = Number of cylinders (of partition) -dividend-
  9158                                  	;	cx = Total cylinders -divisor-
  9159                                  	; OUTPUT:
  9160                                  	;	ax = Percentage
  9161                                  
  9162                                  	;  if (cylinders_in == 0)
  9163                                  	;	 percentage_out = 0;
  9164                                  	;  else if (total_cylinders == 0)
  9165                                  	;           percentage_out = 0;
  9166                                  	;       else
  9167                                  
  9168                                  	; 11/03/2021
  9169                                  	; INPUT: dword [cylinders] ; number of total disk cylinders
  9170                                  	;	 eax = partition's cylinder count
  9171                                  	; OUTPUT: ax = pencentage
  9172                                  
  9173                                  	;or	bx, bx
  9174                                  	;jz	short ctpc_6 ; ax = 0 = percentage_out
  9175                                  	; 11/03/2021 
  9176 00002570 6609C0                  	or	eax, eax
  9177 00002573 742B                    	jz	short ctpc_6 ; ax = 0 = percentage_out 	
  9178                                  ctpc_1:
  9179                                  	;or	cx, cx
  9180                                  	;jz	short ctpc_6
  9181                                  
  9182 00002575 668B0E[A63C]            	mov	ecx, [cylinders]
  9183 0000257A 6609C9                  	or	ecx, ecx
  9184 0000257D 7421                    	jz	short ctpc_6
  9185                                  
  9186                                  	;mov	ax, 100
  9187                                  	;mul	bx ; [cylinders_in]
  9188                                  	;	; dx:ax = Dividend
  9189                                  	;	
  9190                                  	;mul	edx
  9191                                  	
  9192                                  	;call	div32 ; 100*cylinders_in / total_cylinders
  9193                                  	;	; DX:AX = Quotient
  9194                                  	;	; BX = Remainder
  9195                                  
  9196 0000257F 66BA64000000            	mov	edx, 100
  9197 00002585 66F7E2                  	mul	edx
  9198 00002588 66F7F1                  	div	ecx
  9199                                  
  9200                                  	; ax = percentage_out
  9201                                  
  9202                                  	; 12/03/2021
  9203 0000258B 66D1E9                  	shr	ecx, 1
  9204                                  
  9205                                  	;cmp	bx, cx	; is remainder >= total_cylinders/2 ?
  9206                                  	;jb	short ctpc_5 ; No.
  9207                                  
  9208 0000258E 6639CA                  	cmp	edx, ecx ; is remainder >= total_cylinders/2 ?
  9209 00002591 7201                    	jb	short ctpc_5 ; No.
  9210                                  ctpc_4:
  9211 00002593 40                      	inc	ax
  9212                                  ctpc_5:
  9213                                  	; 12/03/2021
  9214 00002594 66BA64000000            	mov	edx, 100
  9215                                  	;cmp	ax, 100
  9216 0000259A 39D0                    	cmp	ax, dx ; 100
  9217 0000259C 7602                    	jbe	short ctpc_6
  9218                                  	;mov	ax, 100
  9219 0000259E 89D0                    	mov	ax, dx
  9220                                  ctpc_6:
  9221 000025A0 C3                      	retn
  9222                                  
  9223                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  9224                                  ; display partition table
  9225                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  9226                                  ; 04/02/2019
  9227                                  
  9228                                  	; 12/03/2021
  9229                                  display_partition_table_x:
  9230 000025A1 66B805000000            	mov	eax, 5 ; display extended partition table
  9231 000025A7 EB03                    	jmp	short dpt_x
  9232                                  
  9233                                  	; 11/03/2021 (fdisk4.s)
  9234                                  display_partition_table:
  9235                                  
  9236                                  	; INPUT:
  9237                                  	;	al = 0 for MBR
  9238                                  	;	   = 5 for EBR (logical drives in extended partition)
  9239                                  	; OUTPUT:
  9240                                  	;	none
  9241                                  
  9242                                  ;pt_positions:
  9243                                  n_pos	equ 30 ; 1 byte	
  9244                                  
  9245                                  	; 12/03/2021
  9246 000025A9 6631C0                  	xor	eax, eax ; display primary partition table
  9247                                  dpt_x:
  9248 000025AC A2[156C]                	mov	[_e_], al
  9249                                  
  9250                                  	; clear screen
  9251 000025AF B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
  9252 000025B2 CD10                    	int	10h
  9253                                  
  9254 000025B4 803E[156C]05            	cmp	byte [_e_], 5
  9255 000025B9 7507                    	jne	short dpt_1
  9256                                  dpt_0:
  9257 000025BB BD[C66C]                	mov	bp, ext_table_boot_ind
  9258 000025BE B045                    	mov	al, 'E'
  9259 000025C0 EB05                    	jmp	short dpt_4
  9260                                  dpt_1:
  9261 000025C2 BD[6A6C]                	mov	bp, part_table_boot_ind
  9262 000025C5 B04D                    	mov	al, 'M'
  9263                                  dpt_4:
  9264 000025C7 BE[2655]                	mov	si, p_table_header
  9265 000025CA 88441E                  	mov	[si+n_pos], al
  9266 000025CD E8E0F3                         	call 	print_msg
  9267                                     
  9268 000025D0 31DB                    	xor	bx, bx
  9269 000025D2 891E[106C]              	mov	[_i_], bx
  9270                                  dpt_5:
  9271 000025D6 FE06[106C]              	inc	byte [_i_]
  9272                                  
  9273                                  	; BX = partition entry (0 to 3)
  9274                                  	; BP = partition table structure address
  9275                                  
  9276 000025DA E86400                  	call	display_pt_entry  ; display partition table row
  9277                                  
  9278 000025DD 8B1E[106C]              	mov	bx, [_i_]
  9279                                  	
  9280 000025E1 80FB04                  	cmp	bl, 4
  9281 000025E4 72F0                    	jb	short dpt_5
  9282                                  
  9283 000025E6 BE[6756]                	mov	si, p_table_footer
  9284 000025E9 E8C4F3                         	call 	print_msg
  9285                                  
  9286                                  	; 27/02/2019
  9287 000025EC BF[7D52]                	mov	di, str_disk_sectors
  9288                                  
  9289 000025EF 803E[156C]05            	cmp	byte [_e_], 5
  9290 000025F4 741A                    	je	short dpt_9
  9291                                  
  9292                                  	; display total disk sectors
  9293                                  
  9294                                  	;mov	di, str_disk_sectors
  9295                                  
  9296                                  	;cmp	byte [di], '0'
  9297                                  	;jnb	short dpt_8
  9298                                  
  9299                                          ;mov	ax, [total_sectors]
  9300                                          ;mov	dx, [total_sectors+2]
  9301                                  	; 11/03/2021	
  9302 000025F6 66A1[2665]              	mov	eax, [total_sectors]
  9303                                  	
  9304 000025FA E81F00                  	call	dpt_10
  9305                                  dpt_8:
  9306 000025FD BE[6752]                	mov	si, msg_disk_sectors
  9307                                  dpt_11:
  9308 00002600 E8ADF3                  	call	print_msg
  9309                                  
  9310 00002603 BE[7D52]                	mov	si, str_disk_sectors
  9311 00002606 E8A7F3                  	call	print_msg
  9312                                  
  9313 00002609 BE[5152]                	mov	si, CRLF
  9314 0000260C E8A1F3                  	call	print_msg
  9315                                  
  9316 0000260F C3                      	retn
  9317                                  
  9318                                  dpt_9:
  9319                                  	; display extended partition size
  9320                                  
  9321                                  	;mov	ax, [ep_Size]
  9322                                  	;mov	dx, [ep_Size+2]
  9323                                  	; 11/03/2021
  9324 00002610 66A1[086C]              	mov	eax, [ep_Size]
  9325                                  
  9326 00002614 E80500                  	call	dpt_10
  9327                                  
  9328 00002617 BE[8852]                	mov	si, msg_ep_size
  9329 0000261A EBE4                    	jmp	short dpt_11
  9330                                  
  9331                                  dpt_10:
  9332 0000261C 89E6                    	mov	si, sp
  9333                                  	;mov	cx, 10
  9334                                  	; 11/03/2021
  9335 0000261E 66B90A000000            	mov	ecx, 10
  9336                                  dpt_6:
  9337                                  	;call	div32
  9338                                  	
  9339                                  	;add	bl, '0'
  9340                                  	;push	bx
  9341                                  	;and	ax, ax
  9342                                  	;jnz	short dpt_6
  9343                                  	;and	dx, dx
  9344                                  	;jnz	short dpt_6
  9345                                  
  9346 00002624 6631D2                  	xor	edx, edx
  9347 00002627 66F7F1                  	div	ecx
  9348                                  	; 21/03/2021
  9349 0000262A 80C230                  	add	dl, '0' 
  9350 0000262D 52                      	push	dx
  9351 0000262E 6621C0                  	and	eax, eax
  9352 00002631 75F1                    	jnz	short dpt_6
  9353                                  
  9354 00002633 29E6                    	sub	si, sp
  9355 00002635 D1EE                    	shr	si, 1
  9356                                  dpt_7:
  9357 00002637 58                      	pop	ax
  9358 00002638 AA                      	stosb
  9359 00002639 4E                      	dec	si
  9360 0000263A 75FB                    	jnz	short dpt_7
  9361                                  
  9362                                  	;xor	al, al
  9363 0000263C 6631C0                  	xor	eax, eax ; 11/03/2021
  9364 0000263F AA                      	stosb
  9365                                  
  9366                                  	; 27/02/2019
  9367 00002640 C3                      	retn
  9368                                  
  9369                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  9370                                  ; display partition table entry/row
  9371                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  9372                                  ; 04/02/2019
  9373                                  
  9374                                  ; 05/11/2020
  9375                                  
  9376                                  struc ptbl
  9377                                  
  9378 00000000 ??                      .boot_ind:	resb 1
  9379 00000001 ??                      .start_head:	resb 1
  9380 00000002 ??                      .start_sector:	resb 1
  9381                                  ;.start_cyl:	resw 1
  9382 00000003 ????????                .start_cyl:	resd 1
  9383 00000007 ??                      .sys_id:	resb 1
  9384 00000008 ??                      .end_head:	resb 1
  9385 00000009 ??                      .end_sector:	resb 1
  9386                                  ;.end_cyl:	resw 1
  9387 0000000A ????????                .end_cyl:	resd 1
  9388                                  ;.rel_sec_lw:	resw 1
  9389                                  ;.rel_sec_hw:	resw 1
  9390 0000000E ????????                .rel_sec:	resd 1
  9391                                  ;.num_sec_lw:	resw 1
  9392                                  ;.num_sec_hw:	resw 1
  9393 00000012 ????????                .num_sec:	resd 1
  9394                                  .size: ; 22 ; 05/11/2020
  9395                                  
  9396                                  endstruc
  9397                                  
  9398                                  	; 20/03/2021 (fdisk4.s)
  9399                                  display_pt_entry:
  9400                                  	; 24/10/2020 (fdisk3.s)
  9401                                  
  9402                                  	; INPUT:
  9403                                  	;	bl = partition entry
  9404                                  	;	bh = 0
  9405                                  	;	bp = partition table structure address
  9406                                  	; OUTPUT:
  9407                                  	;	none
  9408                                  
  9409                                  ; 24/10/2020 (fdisk3.s)
  9410                                  ;pt_positions:
  9411                                  p_pos	equ 3  ; 1 byte
  9412                                  s_pos	equ 6  ; 2+1 byte
  9413                                  bh_pos	equ 10 ; 2+1 bytes
  9414                                  bs_pos	equ 14 ; 2+1 bytes
  9415                                  bc_pos	equ 18 ; 2+1 bytes
  9416                                  fs_pos  equ 22 ; 2+1 bytes
  9417                                  eh_pos  equ 26 ; 2+1 bytes
  9418                                  es_pos	equ 30 ; 2+1 bytes
  9419                                  ec_pos	equ 34 ; 2+1 bytes
  9420                                  rs_pos	equ 42 ; 10 bytes
  9421                                  ns_pos	equ 53 ; 10 bytes
  9422                                  fsx_pos equ 64 ; 14 bytes
  9423                                  
  9424                                  ; 2019-2020 (hdimage.s)
  9425                                  ;;pt_positions:
  9426                                  ;p_pos	equ 7  ; 1 byte
  9427                                  ;s_pos	equ 9  ; 2+1 byte
  9428                                  ;bh_pos	equ 13 ; 2+1 bytes
  9429                                  ;bs_pos	equ 17 ; 2+1 bytes
  9430                                  ;bc_pos	equ 21 ; 2+1 bytes
  9431                                  ;fs_pos equ 25 ; 2+1 bytes
  9432                                  ;eh_pos equ 29 ; 2+1 bytes
  9433                                  ;es_pos	equ 33 ; 2+1 bytes
  9434                                  ;ec_pos	equ 37 ; 2+1 bytes
  9435                                  ;rs_pos	equ 42 ; 7 bytes
  9436                                  ;ns_pos	equ 52 ; 7 bytes
  9437                                  ;fsx_pos equ 61 ; 14 bytes
  9438                                  
  9439 00002641 55                      	push	 bp ; 23/02/2019
  9440                                  
  9441 00002642 08DB                    	or	bl, bl
  9442 00002644 7406                    	jz	short dpte_0
  9443                                  
  9444                                  	;xor	bh, bh
  9445 00002646 B016                    	mov	al, ptbl.size ; 22 ; 05/11/2020
  9446 00002648 F6E3                    	mul	bl
  9447 0000264A 01C5                    	add	bp, ax
  9448                                  dpte_0:
  9449 0000264C 807E0700                	cmp	byte [bp+ptbl.sys_id], 0
  9450 00002650 0F861501                	jna	dpte_9
  9451                                  
  9452 00002654 B768                    	mov	bh, 'h'
  9453                                  
  9454 00002656 BE[186C]                	mov	si, pte_row
  9455                                  
  9456                                  	; clear partition table display buffer/row
  9457 00002659 89F7                    	mov	di, si
  9458 0000265B B92800                  	mov	cx, 40
  9459 0000265E B82020                  	mov	ax, 2020h
  9460 00002661 F3AB                    	rep	stosw
  9461                                  
  9462 00002663 88D8                    	mov	al, bl
  9463 00002665 0431                    	add	al, '1'
  9464 00002667 884403                  	mov	[si+p_pos], al  ; partition number '1' to '4'
  9465                                  
  9466                                  	; partition status, type and CHS parameters
  9467                                  	; (as hexadecimal number)
  9468                                  
  9469                                  	;mov	al, [bp+ptbl.boot_ind]
  9470 0000266A 8A4600                  	mov	al, [bp]
  9471 0000266D E814F4                  	call	byte_to_hex
  9472                                  
  9473 00002670 894406                  	mov	[si+s_pos], ax
  9474 00002673 887C08                  	mov	[si+s_pos+2], bh ; 'h'
  9475                                  
  9476 00002676 8A4601                  	mov	al, [bp+ptbl.start_head]
  9477 00002679 E808F4                  	call	byte_to_hex
  9478                                  
  9479 0000267C 89440A                  	mov	[si+bh_pos], ax
  9480 0000267F 887C0C                  	mov	[si+bh_pos+2], bh ; 'h'
  9481                                  
  9482 00002682 8B4E03                  	mov	cx, [bp+ptbl.start_cyl]
  9483                                  	; 28/10/2020
  9484 00002685 81F9FF03                	cmp	cx, 1023
  9485 00002689 7603                    	jna	short dpte_10 ; cyl number is in CHS limit
  9486 0000268B B9FF03                  	mov	cx, 1023 ; fix cylinder number (to it's PTE value)
  9487                                  			 ; to correct display PTE (CHS bytes)
  9488                                  dpte_10:
  9489 0000268E C0E506                  	shl	ch, 6
  9490 00002691 8A4602                  	mov	al, [bp+ptbl.start_sector]
  9491 00002694 08E8                    	or	al, ch
  9492 00002696 E8EBF3                  	call	byte_to_hex
  9493                                  
  9494 00002699 89440E                  	mov	[si+bs_pos], ax
  9495 0000269C 887C10                  	mov	[si+bs_pos+2], bh ; 'h'
  9496                                  
  9497                                  	;mov	al, [bp+ptbl.start_cyl]
  9498 0000269F 88C8                    	mov	al, cl
  9499 000026A1 E8E0F3                  	call	byte_to_hex
  9500                                  
  9501 000026A4 894412                  	mov	[si+bc_pos], ax
  9502 000026A7 887C14                  	mov	[si+bc_pos+2], bh ; 'h'
  9503                                  
  9504 000026AA 8A4607                  	mov	al, [bp+ptbl.sys_id]
  9505 000026AD E8D4F3                  	call	byte_to_hex
  9506                                  
  9507 000026B0 894416                  	mov	[si+fs_pos], ax
  9508 000026B3 887C18                  	mov	[si+fs_pos+2], bh ; 'h'
  9509                                  
  9510 000026B6 8A4608                  	mov	al, [bp+ptbl.end_head]
  9511 000026B9 E8C8F3                  	call	byte_to_hex
  9512                                  
  9513 000026BC 89441A                  	mov	[si+eh_pos], ax
  9514 000026BF 887C1C                  	mov	[si+eh_pos+2], bh ; 'h'
  9515                                  
  9516 000026C2 8B4E0A                  	mov	cx, [bp+ptbl.end_cyl]
  9517                                  	; 28/10/2020
  9518 000026C5 81F9FF03                	cmp	cx, 1023
  9519 000026C9 7603                    	jna	short dpte_11 ; cyl number is in CHS limit
  9520 000026CB B9FF03                  	mov	cx, 1023 ; fix cylinder number (to it's PTE value)
  9521                                  			 ; to correct display PTE (CHS bytes)
  9522                                  dpte_11:
  9523 000026CE C0E506                  	shl	ch, 6
  9524 000026D1 8A4609                  	mov	al, [bp+ptbl.end_sector]
  9525 000026D4 08E8                    	or	al, ch
  9526 000026D6 E8ABF3                  	call	byte_to_hex
  9527                                  
  9528 000026D9 89441E                  	mov	[si+es_pos], ax
  9529 000026DC 887C20                  	mov	[si+es_pos+2], bh ; 'h'
  9530                                  
  9531                                  	;mov	al, [bp+ptbl.end_cyl]
  9532 000026DF 88C8                    	mov	al, cl
  9533 000026E1 E8A0F3                  	call	byte_to_hex
  9534                                  
  9535 000026E4 894422                  	mov	[si+ec_pos], ax
  9536 000026E7 887C24                  	mov	[si+ec_pos+2], bh ; 'h'
  9537                                  
  9538                                  	; relative (start) sector address (lba)
  9539                                  	; (as decimal number)
  9540                                  
  9541                                  	;mov	ax, [bp+ptbl.rel_sec_lw]
  9542                                  	;mov	dx, [bp+ptbl.rel_sec_hw]
  9543                                  	; 20/03/2021
  9544 000026EA 668B460E                	mov	eax, [bp+ptbl.rel_sec] 
  9545                                  
  9546 000026EE 89E7                    	mov	di, sp
  9547                                  	; 20/03/2021
  9548                                  	;mov	cx, 10
  9549 000026F0 6631C9                  	xor	ecx, ecx
  9550 000026F3 B10A                    	mov	cl, 10
  9551                                  dpte_1:
  9552                                  	;call	div32
  9553                                  	; 20/03/2021
  9554 000026F5 6631D2                  	xor	edx, edx
  9555 000026F8 66F7F1                  	div	ecx
  9556                                  
  9557                                  	;add	bl, '0'
  9558                                  	;push	bx
  9559                                  	; 20/03/2021
  9560 000026FB 80C230                  	add	dl, '0'
  9561 000026FE 52                      	push	dx ; ++*
  9562                                  
  9563                                  	;and	ax, ax
  9564                                  	;jnz	short dpte_1
  9565                                  	;and	dx, dx
  9566                                  	;jnz	short dpte_1
  9567                                  	; 20/03/2021
  9568 000026FF 6621C0                  	and	eax, eax
  9569 00002702 75F1                    	jnz	short dpte_1
  9570                                  
  9571 00002704 8D5C31                  	lea	bx, [si+rs_pos+7]
  9572                                  
  9573 00002707 29E7                    	sub	di, sp
  9574 00002709 D1EF                    	shr	di, 1
  9575 0000270B 29FB                    	sub	bx, di	
  9576                                  dpte_2:
  9577 0000270D 58                      	pop	ax ; ++*
  9578 0000270E 8807                    	mov	[bx], al
  9579 00002710 4F                      	dec	di
  9580 00002711 7403                    	jz	short dpte_3
  9581                                  	
  9582 00002713 43                      	inc	bx
  9583 00002714 EBF7                    	jmp	short dpte_2
  9584                                  
  9585                                  dpte_3:
  9586                                  	; number of sectors)
  9587                                  	; (as decimal number)
  9588                                  
  9589                                  	;mov	ax, [bp+ptbl.num_sec_lw]
  9590                                  	;mov	dx, [bp+ptbl.num_sec_hw]
  9591                                  	; 20/03/2021
  9592 00002716 668B4612                	mov	eax, [bp+ptbl.num_sec] 
  9593                                  
  9594 0000271A 89E7                    	mov	di, sp
  9595                                  	;mov	cx, 10
  9596                                  dpte_4:
  9597                                  	;call	div32
  9598                                  	; 20/03/2021
  9599 0000271C 31D2                    	xor	dx, dx
  9600 0000271E 66F7F1                  	div	ecx
  9601                                  	
  9602                                  	;add	bl, '0'
  9603                                  	;push	bx
  9604                                  	; 20/03/2021
  9605 00002721 80C230                  	add	dl, '0'
  9606 00002724 52                      	push	dx ; ++**
  9607                                  
  9608                                  	;and	ax, ax
  9609                                  	;jnz	short dpte_4
  9610                                  	;and	dx, dx
  9611                                  	;jnz	short dpte_4
  9612                                  	; 20/03/2021
  9613 00002725 6621C0                  	and	eax, eax
  9614 00002728 75F2                    	jnz	short dpte_4
  9615                                  
  9616 0000272A 8D5C3C                  	lea	bx, [si+ns_pos+7]
  9617                                  
  9618 0000272D 29E7                    	sub	di, sp
  9619 0000272F D1EF                    	shr	di, 1
  9620 00002731 29FB                    	sub	bx, di	
  9621                                  dpte_5:
  9622 00002733 58                      	pop	ax ; ++**
  9623 00002734 8807                    	mov	[bx], al
  9624 00002736 4F                      	dec	di
  9625 00002737 7403                    	jz	short dpte_6
  9626                                  	
  9627 00002739 43                      	inc	bx
  9628 0000273A EBF7                    	jmp	short dpte_5
  9629                                  dpte_6:
  9630                                  	; set file system name
  9631                                  
  9632 0000273C 8A4607                  	mov	al, [bp+ptbl.sys_id]
  9633 0000273F BF[C23D]                	mov	di, valid_partitions
  9634 00002742 B91300                  	mov	cx, 19
  9635 00002745 F2AE                    	repnz	scasb
  9636 00002747 7405                    	jz	short dpte_7
  9637 00002749 B8[B43D]                	mov	ax, FS_OTHERS
  9638 0000274C EB0C                    	jmp	short dpte_8
  9639                                  dpte_7:
  9640 0000274E 81EF[C33D]              	sub	di, valid_partitions + 1
  9641 00002752 B80E00                  	mov	ax, 14
  9642 00002755 F7E7                    	mul	di
  9643 00002757 05[AA3C]                	add	ax, FileSys_Names
  9644                                  dpte_8:
  9645 0000275A 8D7C40                  	lea	di, [si+fsx_pos]
  9646 0000275D 89C6                    	mov	si, ax
  9647 0000275F B107                    	mov	cl, 7
  9648 00002761 F3A5                    	rep	movsw
  9649                                  
  9650 00002763 BE[186C]                	mov	si, pte_row
  9651 00002766 E847F2                  	call	print_msg
  9652                                  dpte_9:
  9653 00002769 5D                      	pop	bp ; 23/02/2019
  9654                                  	
  9655 0000276A C3                      	retn
  9656                                  
  9657                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  9658                                  ; fix partition table
  9659                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  9660                                  ; 24/02/2019
  9661                                  
  9662                                  partition_table_fix:
  9663                                  	; DELETE or EXIT option for Invalid Partition Table Entry
  9664                                  	; INPUT: 
  9665                                  	;	DS:SI = PTE address in MBR buffer
  9666                                  	
  9667 0000276B 56                      	push	si  ; save PTE address
  9668                                  
  9669 0000276C 89F0                    	mov	ax, si
  9670 0000276E 2D[8A54]                	sub	ax, MasterBootBuff+446
  9671 00002771 C0E804                  	shr	al, 4 ; / 16 
  9672 00002774 0431                    	add	al, '1'
  9673 00002776 A2[885B]                	mov	[inv_pte_num], al
  9674                                  
  9675                                  	; DS:SI = PTE address in MBR buffer
  9676 00002779 E878F7                  	call	show_selected_partition
  9677                                  
  9678                                  	;mov	si, CRLF
  9679                                  	;call	print_msg
  9680                                  
  9681                                  	; Warning message...
  9682                                  
  9683 0000277C BE[645B]                	mov	si, msg_inv_pte
  9684 0000277F E82EF2                  	call	print_msg
  9685                                  
  9686 00002782 5F                      	pop	di  ; restore PTE address
  9687                                  ptf_0:	
  9688 00002783 30E4                    	xor	ah, ah
  9689 00002785 CD16                    	int	16h
  9690                                  
  9691 00002787 3C0D                    	cmp	al, 13
  9692 00002789 7406                    	je	short ptf_1
  9693                                  
  9694 0000278B 3C1B                    	cmp	al, 27
  9695 0000278D 75F4                    	jne	short ptf_0
  9696                                  
  9697 0000278F F9                      	stc
  9698 00002790 C3                      	retn
  9699                                  ptf_1:
  9700                                  	; Clear that (invalid) PTE
  9701 00002791 31C0                    	xor	ax, ax	
  9702 00002793 B90800                  	mov	cx, 8
  9703 00002796 F3AB                    	rep	stosw
  9704                                  
  9705                                  	; Clear screen
  9706 00002798 B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
  9707 0000279B CD10                    	int	10h
  9708                                  
  9709 0000279D C3                      	retn
  9710                                  
  9711                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  9712                                  ; display (& edit) EXTENDED (DOS) partition table
  9713                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  9714                                  ; 28/02/2019
  9715                                  
  9716                                  display_extended_pt:
  9717                                  	; 12/03/2021
  9718                                  	;mov	al, 5 ; extended partition (logical drives)
  9719                                  	;call	display_partition_table
  9720 0000279E E800FE                  	call	display_partition_table_x
  9721                                  
  9722 000027A1 BE[5C5D]                	mov	si, ebr_editing_options
  9723 000027A4 E809F2                  	call	print_msg
  9724                                  
  9725 000027A7 BE[115A]                	mov	si, enter_opt_num_cancel_msg
  9726 000027AA E803F2                  	call	print_msg
  9727                                  
  9728 000027AD BE[5152]                	mov	si, CRLF
  9729 000027B0 E8FDF1                  	call	print_msg
  9730                                  dept_1:
  9731 000027B3 30E4                    	xor	ah, ah
  9732 000027B5 CD16                    	int	16h
  9733                                  
  9734 000027B7 3C30                    	cmp	al, '0'
  9735 000027B9 740C                    	je	short dept_2
  9736                                  
  9737 000027BB 3C31                    	cmp	al, '1'
  9738 000027BD 7464                    	je	short edit_ext_table_create
  9739 000027BF 3C32                    	cmp	al, '2'
  9740 000027C1 7407                    	je	short edit_ext_table_delete
  9741                                  		
  9742 000027C3 3C1B                    	cmp	al, 27 ; ESCape
  9743 000027C5 75EC                    	jne	short dept_1
  9744                                  dept_2:
  9745 000027C7 E909DC                  	jmp	A_42
  9746                                  
  9747                                  edit_ext_table_delete:
  9748                                  	; 28/02/2019
  9749                                  	;mov	al, 5 ; extended partition (logical drives)
  9750                                  	;call	display_partition_table
  9751                                  	; 12/03/2021
  9752 000027CA E8D4FD                  	call	display_partition_table_x
  9753                                  
  9754 000027CD BE[DB5D]                	mov	si, msg_delete_ldd_q
  9755 000027D0 E8DDF1                  	call	print_msg
  9756                                  
  9757                                  	;mov	si, CRLF
  9758                                  	;call	print_msg
  9759                                  eetd_1:
  9760 000027D3 30E4                    	xor	ah, ah
  9761 000027D5 CD16                    	int	16h
  9762                                  
  9763 000027D7 3C1B                    	cmp	al, 27
  9764 000027D9 7410                    	je	short eetd_2
  9765                                  
  9766 000027DB 24DF                    	and	al, 0DFh
  9767 000027DD 3C59                    	cmp	al, 'Y'
  9768 000027DF 7412                    	je	short eetd_yes
  9769 000027E1 3C4E                    	cmp	al, 'N'
  9770 000027E3 75EE                    	jne	short eetd_1
  9771                                  eetd_no:
  9772 000027E5 BE[9159]                	mov	si, msg_NO ;  Write 'NO' (it may be shown for a moment)
  9773 000027E8 E8C5F1                  	call	print_msg
  9774                                  eetd_2:	
  9775 000027EB BE[5152]                	mov	si, CRLF  ; Next line
  9776 000027EE E8BFF1                  	call	print_msg
  9777 000027F1 EBAB                    	jmp	short display_extended_pt
  9778                                  eetd_yes:
  9779 000027F3 BE[8B59]                	mov	si, msg_YES ;  Write 'YES' (it may be shown for a moment)
  9780 000027F6 E8B7F1                  	call	print_msg
  9781 000027F9 BE[5152]                	mov	si, CRLF  ; Next line
  9782 000027FC E8B1F1                  	call	print_msg
  9783 000027FF E8F905                  	call	delete_logical_drives
  9784 00002802 803E[F869]00            	cmp	byte [ldrives], 0
  9785 00002807 7795                    	ja	short display_extended_pt
  9786 00002809 E9C7DB                  	jmp	A_42
  9787                                  
  9788                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  9789                                  ; logical drive count limit error 
  9790                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  9791                                  
  9792                                  eetc_2:
  9793 0000280C BE[415E]                	mov	si, msg_create_ldd_max_error
  9794                                  eetc_10:
  9795 0000280F E89EF1                  	call	print_msg
  9796 00002812 BE[AD52]                	mov	si, msg_press_any_key
  9797 00002815 E898F1                  	call	print_msg
  9798 00002818 30E4                    	xor	ah, ah
  9799 0000281A CD16                    	int	16h
  9800 0000281C EB80                    	jmp	display_extended_pt
  9801                                  
  9802                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  9803                                  ; no free space in extended partition
  9804                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  9805                                  	
  9806                                  	; 05/03/2019
  9807                                  eetc_9:
  9808 0000281E BE[7A60]                	mov	si, msg_c_ldd_nofspc_error
  9809 00002821 EBEC                    	jmp	short eetc_10
  9810                                  
  9811                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  9812                                  ; create logical dos drive in EXTENDED (DOS) partition
  9813                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  9814                                  ; 19/10/2020 (fdisk3.s) 
  9815                                  
  9816                                  	; 13/03/2021
  9817                                  	; 12/03/2021 (fdisk4.s)
  9818                                  edit_ext_table_create:	; 01/03/2019 (hdimage.s)
  9819                                  
  9820                                  ; Create Method: ; 04/03/2019
  9821                                  ;LDD 1 <- LDD_START0, ebr 1st entry <- MBR (extended partition) - EBR 0
  9822                                  ;LDD 2 <- LDD_START1, ebr 2nd entry <- EBR 1
  9823                                  ;LDD 3 <- LDD_START2, ebr 2nd entry <- EBR 2
  9824                                  ;LDD 4 <- LDD_START3, ebr 2nd entry <- EBR 3
  9825                                  
  9826                                  	; 01/03/2019
  9827 00002823 803E[C56C]00            	cmp	byte [epnumber], 0 ; check extended partition
  9828 00002828 0F86A4E4                	jna	B_07		; cancel with error message
  9829                                  
  9830                                  	; 05/03/2019
  9831 0000282C E89602                  	call	check_ext_free_space
  9832 0000282F 72ED                    	jc	eetc_9	; error, no free space in extented partition
  9833                                  
  9834                                  	; 30/10/2020
  9835                                  	;mov	[ep_free_sectors], ax
  9836                                  	;mov	[ep_free_sectors+2], dx
  9837                                  	; 12/03/2021
  9838 00002831 66A3[B06D]              	mov	[ep_free_sectors], eax
  9839                                  
  9840 00002835 803E[F869]04            	cmp	byte [ldrives], 4
  9841 0000283A 73D0                    	jnb	eetc_2	; error, write program limit message
  9842                                  
  9843                                  edit_ext_table_create_x: ; 02/03/2019
  9844                                  
  9845                                  	; Get logical drive size/cylinders (request) from user
  9846 0000283C E82903                  	call	get_ldd_size
  9847                                  	;cmp	word [lcylinders], 1 ; at least 1 cylinder
  9848                                  	;jb	display_extended_pt ; cancel
  9849                                  	; 13/03/2021
  9850 0000283F 66833E[B46D]01          	cmp	dword [lcylinders], 1 ; at least 1 cylinder
  9851 00002845 0F8255FF                	jb	display_extended_pt ; cancel
  9852                                  
  9853                                  	; 03/03/2019
  9854 00002849 A0[F869]                	mov	al, [ldrives]
  9855                                  
  9856                                  	;cmp	byte [ldrives], 1
  9857                                  	;jnb	short eetc_3	; skip verify MBR extended partition
  9858                                  
  9859 0000284C 20C0                    	and	al, al
  9860 0000284E 756C                    	jnz	short eetc_3
  9861                                  
  9862 00002850 31ED                    	xor	bp, bp
  9863                                  
  9864                                  	; Read MBR at EBR buffer
  9865                                  	;xor	ah, ah ; 19/10/2020
  9866                                  	;xor	dx, dx
  9867                                  	; 09/03/2021
  9868 00002852 6631C0                  	xor	eax, eax	
  9869                                  
  9870 00002855 BB[FE69]                	mov	bx, ebr_buffer
  9871 00002858 E864F1                  	call	read_hd_sector
  9872 0000285B 7219                    	jc	short eetc_0
  9873                                  
  9874                                  	;mov	al, [epnumber]
  9875                                  	;cbw
  9876                                  	;shl	al, 4 ; * 16
  9877                                  	; 13/03/2021
  9878                                  	; eax = 0
  9879 0000285D 30ED                    	xor	ch, ch
  9880 0000285F 8A0E[C56C]              	mov	cl, [epnumber]
  9881 00002863 C0E104                  	shl	cl, 4 ; * 16
  9882 00002866 BE[BC6B]                	mov	si, ebr_buffer+446
  9883                                  	;add	si, ax
  9884 00002869 01CE                    	add	si, cx
  9885 0000286B BF[8A54]                	mov	di, MasterBootBuff+446
  9886                                  	;add	di, ax
  9887 0000286E 01CF                    	add	di, cx
  9888                                  	;mov	cx, 8
  9889 00002870 B108                    	mov	cl, 8
  9890 00002872 F3A7                    	repe	cmpsw	; repeat comparising while cx > 0 and zf = 1
  9891 00002874 E30A                    	jcxz	eetc_1	; Extended partition entry is not changed 
  9892                                  	; Different PTE (means there is a new extended partition) 
  9893                                  eetc_0:
  9894                                  	; Write current MBR (with modified PT)
  9895 00002876 BB[CC52]                	mov	bx, MasterBootBuff
  9896                                  	;xor	ax, ax
  9897                                  	;;xor	dx, dx
  9898                                  	; eax = 0 ; 13/03/2021
  9899 00002879 E892F1                  	call	write_hd_sector
  9900 0000287C 0F82D9DE                	jc	print_error_code ; ! display error msg and then exit !
  9901                                  eetc_1:
  9902                                  	; clear	EBR buffer
  9903 00002880 BF[FE69]                	mov	di, ebr_buffer
  9904                                  	;xor	ax, ax
  9905                                  	; eax = 0 ; 13/03/2021
  9906                                  	;mov	cx, 255
  9907 00002883 B1FF                    	mov	cl, 255 ; 13/03/2021
  9908 00002885 F3AB                    	rep	stosw
  9909 00002887 C70555AA                	mov	word [di], 0AA55h
  9910                                  
  9911                                  	; Set logical dos drive parameters in it's EBR
  9912 0000288B BF[BC6B]                	mov	di, ebr_buffer+446
  9913                                  
  9914                                  	;mov	cx, [sectors]
  9915                                  	;sub	bx, bx ; 0
  9916                                  	; 13/03/2021
  9917 0000288E 660FB70E[A23C]          	movzx	ecx, word [sectors]
  9918                                  
  9919                                  	;mov	ax, [ep_StartSector]
  9920                                  	;mov	dx, [ep_StartSector+2]
  9921                                  	; 13/03/2021
  9922 00002894 66A1[006C]              	mov	eax, [ep_StartSector]
  9923                                  
  9924                                  	; 03/03/2019
  9925                                  	; set partition start address & size
  9926                                  
  9927                                  	;mov	[ldd_start], ax
  9928                                  	;mov	[ldd_start+2], dx
  9929                                  	; 13/03/2021
  9930 00002898 66A3[906D]              	mov	[ldd_start], eax
  9931                                  
  9932                                  	; 01/11/2020
  9933                                  	;cmp	word [lcylinders], 65535
  9934                                  	;		; sign for using all of available sectors
  9935                                  	;jb	short eetc_11
  9936                                  	; 13/03/2021
  9937 0000289C 66833E[B46D]FF          	cmp	dword [lcylinders], 0FFFFFFFFh
  9938 000028A2 7206                    	jb	short eetc_11
  9939                                  
  9940                                  	;mov	ax, [ep_free_sectors]
  9941                                  	;mov	dx, [ep_free_sectors+2]
  9942                                  	; 13/03/2021
  9943 000028A4 66A1[B06D]              	mov	eax, [ep_free_sectors]
  9944                                  
  9945 000028A8 EB09                    	jmp	short eetc_12
  9946                                  eetc_11:
  9947                                  	;mov	al, [heads]
  9948                                  	;mul	byte [sectors]
  9949                                  	;mul	word [lcylinders]
  9950                                  	; 13/03/2021
  9951 000028AA 66A1[E469]              	mov	eax, [hs] ; [heads] * [sectors]
  9952 000028AE 66F726[B46D]            	mul	dword [lcylinders]
  9953                                  eetc_12:
  9954                                  	; 01/11/2020
  9955 000028B3 31ED                    	xor	bp, bp
  9956                                  	;mov	[ldd_size], ax
  9957                                  	;mov	[ldd_size+2], dx
  9958                                  	; 13/03/2021
  9959 000028B5 66A3[A06D]              	mov	[ldd_size], eax
  9960                                  
  9961                                  	; 1st ldd start sector is always 63 or 17 (= spt)
  9962                                  	;sub	ax, cx ; cx = 63 or 17, [sectors]
  9963                                  	;sbb	dx, bx ; sbb dx, 0
  9964                                  
  9965                                  	; 01/11/2020	
  9966 000028B9 E9B700                  	jmp	eetc_4
  9967                                  
  9968                                  	;mov	[di+ptStartSector], cx
  9969                                  	;mov	[di+ptStartSector+2], bx
  9970                                  	;
  9971                                  	;; 01/11/2020
  9972                                  	;mov	[di+ptSectors], ax
  9973                                  	;mov	[di+ptSectors+2], dx
  9974                                  	;
  9975                                  	;mov	cx, ax
  9976                                  	;mov	bx, dx
  9977                                  	;; cx:bx = volume size of logical -dos- drive
  9978                                  	;
  9979                                  	;pop	ax ; ldd's LBA
  9980                                  	;pop	dx
  9981                                  	;; dx:ax = start sector address of ldd
  9982                                  	;
  9983                                  	;; 01/11/2020
  9984                                  	;add	cx, ax
  9985                                  	;adc	bx, dx
  9986                                  	;sub	cx, 1
  9987                                  	;sbb	bx, 0
  9988                                  	;; bx:cx = end sector address of ldd
  9989                                  	;push	cx
  9990                                  	;push	bx
  9991                                  	;
  9992                                  	;jmp	eetc_4
  9993                                  
  9994                                  eetc_3:
  9995                                  	; [ldrives] >= 1
  9996                                  	; Read EBR
  9997                                  	;mov	al, [ldrives]
  9998 000028BC 30E4                    	xor	ah, ah ; 02/11/2020
  9999 000028BE C0E002                  	shl	al, 2
 10000 000028C1 89C5                    	mov	bp, ax
 10001                                  
 10002                                  	; 03/03/2019
 10003                                  	;mov	ax, [bp+ldd_start-4]
 10004                                  	;mov	dx, [bp+ldd_start-2]
 10005                                  	; 09/03/2021
 10006 000028C3 668B86[8C6D]            	mov	eax, [bp+ldd_start-4]
 10007                                  
 10008 000028C8 BB[FE69]                	mov	bx, ebr_buffer
 10009 000028CB E8F1F0                  	call	read_hd_sector
 10010 000028CE 0F8287DE                	jc	print_error_code ; ! display error msg and then exit !
 10011                                  
 10012                                  	; 04/03/2019
 10013 000028D2 BE[CC6B]                	mov	si, ebr_buffer+446+16 ; 2nd entry (next EBR)
 10014                                  	
 10015                                  	; 03/03/2019
 10016                                  	;mov	ax, [bp+ldd_start-4]
 10017                                  	;mov	dx, [bp+ldd_start-2]
 10018                                  	;add	ax, [bp+ldd_size-4]
 10019                                  	;adc	dx, [bp+ldd_size-2]
 10020                                  	; 13/03/2021
 10021 000028D5 668B86[8C6D]            	mov	eax, [bp+ldd_start-4]
 10022 000028DA 660386[9C6D]            	add	eax, [bp+ldd_size-4]
 10023                                  
 10024                                  	;mov	cx, [ep_StartSector]
 10025                                  	;mov	bx, [ep_StartSector+2]
 10026                                  	; 13/03/2021
 10027 000028DF 668B16[006C]            	mov	edx, [ep_StartSector]
 10028                                  
 10029                                  	;mov	[bp+ldd_start], ax
 10030                                  	;mov	[bp+ldd_start+2], dx
 10031                                  	; 13/03/2021
 10032 000028E4 668986[906D]            	mov	[bp+ldd_start], eax
 10033                                  
 10034                                  	;push	dx ; ldd's start sector LBA
 10035                                  	;push	ax
 10036                                  	; 13/03/2021
 10037 000028E9 6650                    	push	eax ; *	
 10038                                  
 10039                                  	;sub	ax, cx
 10040                                  	;sbb	dx, bx
 10041                                  	;; dx:ax = offset from start of the ep start sector
 10042                                  	; 13/03/2021
 10043 000028EB 6629D0                  	sub	eax, edx
 10044                                  	; eax = offset from start of the ep start sector
 10045                                  
 10046                                  	;mov	[si+ptStartSector], ax
 10047                                  	;mov	[si+ptStartSector+2], dx
 10048                                  	; 13/03/2021
 10049 000028EE 66894408                	mov	[si+ptStartSector], eax
 10050                                  
 10051                                  	; 01/11/2020
 10052                                  	;cmp	word [lcylinders], 65535
 10053                                  	;		; sign for using all of available sectors
 10054                                  	;jb	short eetc_13
 10055                                  	; 13/03/2021
 10056 000028F2 66833E[B46D]FF          	cmp	dword [lcylinders], 0FFFFFFFFh
 10057 000028F8 7206                    	jb	short eetc_13
 10058                                  
 10059                                  	;mov	ax, [ep_free_sectors]
 10060                                  	;mov	dx, [ep_free_sectors+2]
 10061                                  	; 13/03/2021
 10062 000028FA 66A1[B06D]              	mov	eax, [ep_free_sectors]
 10063                                  
 10064 000028FE EB09                    	jmp	short eetc_14
 10065                                  eetc_13:
 10066                                  	;mov	al, [heads]
 10067                                  	;mul	byte [sectors]
 10068                                  	;mul	word [lcylinders]
 10069                                  	; 13/03/2021
 10070 00002900 66A1[E469]              	mov	eax, [hs] ; [heads] * [sectors]
 10071 00002904 66F726[B46D]            	mul	dword [lcylinders]
 10072                                  eetc_14:
 10073                                  	; 01/11/2020
 10074                                  	;mov	[bp+ldd_size], ax
 10075                                  	;mov	[bp+ldd_size+2], dx
 10076                                  	; 13/03/2021
 10077 00002909 668986[A06D]            	mov	[bp+ldd_size], eax
 10078                                  
 10079                                   	;mov	[si+ptSectors], ax
 10080                                  	;mov	[si+ptSectors+2], dx
 10081                                  	; 13/03/2021
 10082 0000290E 6689440C                	mov	[si+ptSectors], eax
 10083                                  
 10084                                  	; 01/11/2020
 10085                                  	;mov	cx, ax
 10086                                  	;mov	bx, dx
 10087                                  	;; cx:bx = volume size of logical -dos- drive
 10088                                  	; 13/03/2021
 10089 00002912 6689C2                  	mov	edx, eax ; ldd's volume size
 10090                                  
 10091                                  	;pop	ax ; ldd's start sector LBA
 10092                                  	;pop	dx
 10093                                  	; 13/03/2021
 10094 00002915 6658                    	pop	eax ; *
 10095                                  
 10096                                  	; 01/11/2020
 10097                                  	;add	cx, ax
 10098                                  	;adc	bx, dx
 10099                                  	; 13/03/2021
 10100 00002917 6601C2                  	add	edx, eax ; ldd's start sector LBA
 10101                                  
 10102                                  	;sub	cx, 1
 10103                                  	;sbb	bx, 0
 10104                                  	;; bx:cx = end sector address of ldd
 10105                                  	; 13/03/2021
 10106 0000291A 664A                    	dec	edx ; end sector address of ldd
 10107                                  
 10108                                  	;push	cx
 10109                                  	;push	bx
 10110                                  	; 13/03/2021
 10111 0000291C 6652                    	push	edx ; **
 10112                                  
 10113                                  	; calculate CHS from LBA
 10114 0000291E E8D801                  	call	lba_to_chs
 10115                                  		; ax = cylinder
 10116                                  		; dl = sector
 10117                                  		; dh = head
 10118                                  
 10119 00002921 C60400                  	mov	byte [si+ptBootable], 0
 10120 00002924 887401                  	mov	[si+ptBeginHead], dh
 10121 00002927 884403                  	mov	[si+ptBeginCylinder], al
 10122 0000292A C0E406                  	shl	ah, 6
 10123 0000292D 08E2                    	or	dl, ah
 10124 0000292F 885402                  	mov	[si+ptBeginSector], dl
 10125                                  
 10126                                   	;;mov	ax, [si+ptSectors]
 10127                                  	;;mov	dx, [si+ptSectors+2]
 10128                                   	;mov	ax, [bp+ldd_size]
 10129                                  	;mov	dx, [bp+ldd_size+2]
 10130                                  	;sub	ax, 1
 10131                                  	;sbb	dx, 0
 10132                                  	;add	ax, [bp+ldd_start]
 10133                                  	;adc	dx, [bp+ldd_start+2]
 10134                                  	;	; dx:ax = end sector
 10135                                  	
 10136                                  	; 01/11/2020
 10137                                  	;pop	ax
 10138                                  	;pop	dx
 10139                                  	;; dx:ax = end sector address of ldd
 10140                                  	; 13/03/2021
 10141 00002932 6658                    	pop	eax ; **
 10142                                  
 10143 00002934 E8C201                  	call	lba_to_chs
 10144                                  		; ax = cylinder
 10145                                  		; dl = sector
 10146                                  		; dh = head
 10147                                  		; 24/10/2020
 10148                                  		; bl = Extended partition ID
 10149                                  
 10150                                  	; 13/03/2021
 10151 00002937 6631C9                  	xor	ecx, ecx
 10152                                  		
 10153                                  	;mov	byte [si+ptFileSystemID], 5 ; EXTENDED
 10154                                  	; 24/10/2020
 10155 0000293A 885C04                  	mov	[si+ptFileSystemID], bl ; EXTENDED ; 05h or 0Fh
 10156                                  	;
 10157 0000293D 887405                  	mov	[si+ptEndHead], dh
 10158 00002940 884407                  	mov	[si+ptEndCylinder], al
 10159 00002943 C0E406                  	shl	ah, 6
 10160 00002946 08D4                    	or	ah, dl	
 10161 00002948 886406                  	mov	[si+ptEndSector], ah
 10162                                  
 10163                                  	; Write EBR
 10164                                  	;mov	ax, [bp+ldd_start-4]
 10165                                  	;mov	dx, [bp+ldd_start-2]
 10166                                  	; 13/03/2021
 10167 0000294B 668B86[8C6D]            	mov	eax, [bp+ldd_start-4]
 10168                                  	
 10169 00002950 BB[FE69]                	mov	bx, ebr_buffer
 10170 00002953 E8B8F0                  	call	write_hd_sector
 10171 00002956 0F82FFDD                	jc	print_error_code ; ! display error msg and then exit !
 10172                                  
 10173                                  	; clear	EBR buffer
 10174 0000295A BF[FE69]                	mov	di, ebr_buffer
 10175 0000295D 31C0                    	xor	ax, ax
 10176                                  	;mov	cx, 255
 10177                                  	; 13/03/2021
 10178 0000295F B1FF                    	mov	cl, 255
 10179 00002961 F3AB                    	rep	stosw
 10180 00002963 C70555AA                	mov	word [di], 0AA55h
 10181                                  
 10182 00002967 BF[BC6B]                	mov	di, ebr_buffer+446 ; 1st entry points to LDD
 10183                                  
 10184                                  	;mov	cx, [sectors]
 10185                                  	;sub	bx, bx ; 0
 10186                                  	; 13/03/2021
 10187 0000296A 8A0E[A23C]              	mov	cl, [sectors]
 10188                                  	; ecx = [sectors]
 10189                                  
 10190                                  	; 01/11/2020
 10191                                  	;mov	ax, [bp+ldd_size]
 10192                                  	;mov	dx, [bp+ldd_size+2]
 10193                                  	; 13/03/2021
 10194 0000296E 668B86[A06D]            	mov	eax, [bp+ldd_size]
 10195                                  
 10196                                  	;sub	ax, cx
 10197                                  	;sbb	dx, bx ; sbb dx, 0
 10198                                  eetc_4:
 10199                                  	;mov	[di+ptStartSector], cx
 10200                                  	;mov	[di+ptStartSector+2], bx
 10201                                  	; 13/03/2021
 10202 00002973 66894D08                	mov	[di+ptStartSector], ecx
 10203                                  
 10204                                  	; 01/11/2020
 10205                                  	; 1st ldd start sector is always 63 or 17 (= spt)
 10206                                  	;sub	ax, cx ; cx = 63 or 17, [sectors]
 10207                                  	;sbb	dx, bx ; sbb dx, 0
 10208                                  	; 13/03/2021
 10209 00002977 6629C8                  	sub	eax, ecx
 10210                                  
 10211                                  	; 01/11/2020
 10212                                  	;mov	[di+ptSectors], ax
 10213                                  	;mov	[di+ptSectors+2], dx
 10214                                  	; 13/03/2021
 10215 0000297A 6689450C                	mov	[di+ptSectors], eax
 10216                                  
 10217                                  	;mov	cx, [bp+ldd_size]
 10218                                  	;mov	bx, [bp+ldd_size+2]
 10219                                  	;; cx:bx = volume size of logical -dos- drive
 10220                                  	; 13/03/2021
 10221 0000297E 668B96[A06D]            	mov	edx, [bp+ldd_size]
 10222                                  
 10223                                  	;mov	ax, [bp+ldd_start]
 10224                                  	;mov	dx, [bp+ldd_start+2]
 10225                                  	;; dx:ax = start sector address of ldd (EBR addr)
 10226                                  	; 13/03/2021
 10227 00002983 668B86[906D]            	mov	eax, [bp+ldd_start]
 10228                                  
 10229                                  	; 01/11/2020
 10230                                  	;add	cx, ax
 10231                                  	;adc	bx, dx
 10232                                  	;sub	cx, 1
 10233                                  	;sbb	bx, 0
 10234                                  	;; bx:cx = end sector address of ldd
 10235                                  	; 13/03/2021
 10236 00002988 6601C2                  	add	edx, eax
 10237 0000298B 664A                    	dec	edx
 10238                                  
 10239                                  	;push	bx
 10240                                  	;push	cx
 10241                                  	; 13/03/2021
 10242 0000298D 6652                    	push	edx ; ***
 10243                                  ;eetc_4:
 10244                                  	; 01/11/2020
 10245                                  	; stack = end sector address of ldd
 10246                                  	; dx:ax = start sector address of ldd
 10247                                  
 10248                                  	; calculate CHS from LBA
 10249                                  
 10250 0000298F E86701                  	call	lba_to_chs
 10251                                  		; ax = cylinder
 10252                                  		; dl = sector
 10253                                  		; dh = head
 10254                                  
 10255                                  	;mov	byte [di+ptBootable], 0
 10256 00002992 887501                  	mov	[di+ptBeginHead], dh
 10257 00002995 884503                  	mov	[di+ptBeginCylinder], al
 10258                                  	;mov	bl, ah
 10259                                  	;shl	bl, 6
 10260                                  	;or	dl, bl
 10261                                  	; 01/11/2020
 10262 00002998 C0E406                  	shl	ah, 6
 10263 0000299B 08E2                    	or	dl, ah
 10264 0000299D 885502                  	mov	[di+ptBeginSector], dl
 10265                                  
 10266                                  	;add	ax, [lcylinders]
 10267                                  	;dec	ax ; end cylinder
 10268                                  	;mov	bx, ax
 10269                                  
 10270                                  	; 01/11/2020
 10271                                  	;pop	ax
 10272                                  	;pop	dx
 10273                                  	;; dx:ax = end sector address of ldd
 10274                                  	; 13/03/2021
 10275 000029A0 6658                    	pop	eax ; ***
 10276                                  
 10277 000029A2 E85401                  	call	lba_to_chs
 10278                                  		; ax = cylinder number (0-1023)
 10279                                  		; dl = sector
 10280                                  		; dh = head
 10281                                  		; 01/11/2020
 10282                                  		; cx = cylinder number (0-65535)
 10283                                  		; 13/03/2021
 10284                                  		; ecx = cylinder number (0-267349)
 10285                                  
 10286                                  	;; 02/11/2020
 10287                                  	;;mov	[endcyl], cx ; 01/11/2020
 10288                                  	;xchg	[endcyl], cx 
 10289                                  		; cx = end cylinder of the ep
 10290                                  		; [endcyl] = end cylinder of the ldd
 10291                                  	; 13/03/2021
 10292 000029A5 66870E[BA6D]            	xchg	[endcyl], ecx
 10293                                  
 10294                                  	;mov	[di+ptFileSystemID], 0
 10295                                  	;mov	cx, [heads]
 10296                                  	;dec	cl
 10297                                  	;mov	[di+ptEndHead], cl
 10298                                  	; 01/11/2020
 10299 000029AA 887505                  	mov	[di+ptEndHead], dh
 10300                                  
 10301 000029AD 884507                  	mov	[di+ptEndCylinder], al
 10302                                  	;mov	dx, [sectors]
 10303 000029B0 C0E406                  	shl	ah, 6
 10304 000029B3 08D4                    	or	ah, dl
 10305 000029B5 886506                  	mov	[di+ptEndSector], ah
 10306                                  
 10307                                  	; 02/03/2019
 10308                                  	; Check unused space if it is 3rd LDD
 10309                                  	; (write message to add unused space.)
 10310                                  
 10311                                  	; 02/11/2020
 10312                                  	;cmp	byte [ldrives], 3
 10313                                  	;jb	eetc_7
 10314                                  
 10315                                  	; 01/11/2020
 10316                                  	;cmp	word [lcylinders], 65535  
 10317                                  	;		; sign for using all of available sectors
 10318                                  	;jnb	eetc_7	; no need to add unused sector 
 10319                                  	;		; (there are not any unused sectors)
 10320                                  	; 13/03/2021
 10321 000029B8 66833E[B46D]FF          	cmp	dword [lcylinders], 0FFFFFFFFh
 10322 000029BE 0F83A200                	jnb	eetc_7	; no need to add unused sector
 10323                                  	
 10324                                  	; cx = cylinder number (0 to 65535)
 10325                                  	; 13/03/2021
 10326                                  	; ecx = cylinder number (0 to 267349)
 10327                                  
 10328                                  	; 02/11/2020
 10329 000029C2 803E[F869]03            	cmp	byte [ldrives], 3 ; is this logical drive 4 ?
 10330 000029C7 730B                    	jnb	short eetc_17
 10331                                  			; force to show unused space message
 10332                                  
 10333                                  	; 02/11/2020
 10334                                  	; (add unused space if cyl nums are same or diff is 1)
 10335                                  	;dec	cx  ; tolerate cylinder numbers n and n-1 
 10336                                  	;cmp	cx, [endcyl]
 10337                                  	;ja	eetc_7  ; the end cyl number of the last ldd
 10338                                  	;		; is 2 or more cyls less than
 10339                                  	;		; the end cyl number of the ep
 10340                                  	;		; (a next ldd can be added to
 10341                                  	;		; extd partition with 2 or more cyls)
 10342                                  	; 13/03/2021
 10343 000029C9 6649                    	dec	ecx
 10344 000029CB 663B0E[BA6D]            	cmp	ecx, [endcyl]
 10345 000029D0 0F879000                	ja	eetc_7
 10346                                  eetc_17:
 10347                                  	; 02/11/2020
 10348 000029D4 A0[F869]                	mov	al, [ldrives]
 10349                                  	;add	al, '0'
 10350 000029D7 0431                    	add	al, '1'	; 03/11/2020
 10351 000029D9 A2[B95E]                	mov	[char_lddn], al
 10352                                  
 10353                                  	;mov	al, [sectors]
 10354                                  	;mov	bh, al
 10355                                  	;mov	bl, [heads]
 10356                                  	;dec	bl
 10357                                  	;mul	bl ; [sectors] * [heads] - 1
 10358                                  	; 13/03/2021
 10359 000029DC 66A1[E469]              	mov	eax, [hs] ; [sectors] * [heads]
 10360 000029E0 6648                    	dec	eax ; [sectors] * [heads] - 1
 10361                                  	
 10362                                  	;push	ax
 10363                                  	; 13/03/2021
 10364 000029E2 6650                    	push	eax ; ****
 10365                                  
 10366                                  	;mov	al, bh  ; [sectors]
 10367                                  	;;mul	byte [heads]
 10368                                  	;inc	bl
 10369                                  	;mul	bl
 10370                                  	;	; ax = heads * sectors
 10371                                  	;;mul	cx ; * end cylinder
 10372                                  	;mul	word [endcyl] ; 02/11/2020
 10373                                  	;	; dx:ax = end cylinder * heads * sectors
 10374                                  	; 13/03/2021
 10375 000029E4 6640                    	inc	eax ; heads * sectors
 10376 000029E6 66F726[BA6D]            	mul	dword [endcyl]
 10377                                  	; eax = ((cylinders-1) * heads * sectors)
 10378                                  	
 10379                                  	;pop	cx
 10380                                  	;add	ax, cx ; + (sectors * (heads - 1))
 10381                                  	;adc	dx, 0	
 10382                                  	; 13/03/2021
 10383 000029EB 665A                    	pop	edx ; ****
 10384 000029ED 6601D0                  	add	eax, edx ; + (sectors * (heads - 1))
 10385                                  
 10386                                  	; 03/03/2019
 10387                                  	;mov	cx, [sectors]
 10388                                  	;dec	cl  ; [sectors] - 1
 10389                                  	;add	ax, cx ; + (sectors - 1)
 10390                                  	;adc	dx, 0
 10391                                  	;	; DX:AX = end LBA
 10392                                  	; 13/03/2021
 10393 000029F0 6631D2                  	xor	edx, edx
 10394 000029F3 8A16[A23C]              	mov	dl, [sectors]
 10395 000029F7 FECA                    	dec	dl ; [sectors] - 1
 10396 000029F9 6601D0                  	add	eax, edx  ; + (sectors - 1)
 10397                                  
 10398                                  	;mov	cx, [ep_EndSector]
 10399                                  	;mov	bx, [ep_EndSector+2]
 10400                                  	; 13/03/2021
 10401 000029FC 668B16[046C]            	mov	edx, [ep_EndSector]
 10402                                  
 10403                                  	;cmp	dx, bx
 10404                                  	;jne	short eetc_5
 10405                                  	;cmp	ax, cx
 10406                                  	;je	short eetc_7 ; 05/03/2019
 10407                                  	; 13/03/2021
 10408 00002A01 6639D0                  	cmp	eax, edx
 10409 00002A04 745E                    	je	short eetc_7
 10410                                  eetc_5:
 10411                                  	;push	bx
 10412 00002A06 BE[765E]                	mov	si, msg_c_ldd_unused_warning
 10413 00002A09 E8A4EF                  	call	print_msg
 10414                                  	;pop	bx
 10415                                  eetc_6:
 10416 00002A0C 28E4                    	sub	ah, ah
 10417 00002A0E CD16                    	int	16h
 10418 00002A10 3C0D                    	cmp	al, 13 ; ENTER
 10419 00002A12 7450                    	je	short eetc_7 ; continue
 10420 00002A14 3C1B                    	cmp	al, 27 ; ESC
 10421 00002A16 75F4                    	jne	short eetc_6
 10422                                  
 10423                                  	; 03/03/2019
 10424                                  	; change end cylinder value
 10425 00002A18 A0[C56C]                	mov	al, [epnumber]
 10426 00002A1B FEC8                    	dec	al
 10427                                  	;mov	ah, 18  ; primary partition table structure size
 10428                                  	; 05/11/2020
 10429 00002A1D B416                    	mov	ah, 22	; primary partition table structure size
 10430 00002A1F F6E4                    	mul	ah
 10431 00002A21 89C6                    	mov	si, ax
 10432                                  	;mov	ax, [si+part_table_end_cyl]
 10433                                  	; 02/11/2020
 10434                                  	;mov	[endcyl], ax ; end cylinder of the ep
 10435                                  	; 13/03/2021
 10436 00002A23 668B84[746C]            	mov	eax, [si+part_table_end_cyl]
 10437 00002A28 66A3[BA6D]              	mov	[endcyl], eax ; end cylinder of the ep
 10438                                  eetc_19:
 10439                                  	; 03/11/2020
 10440                                  	;cmp	ax, 1023 ; overs CHS limit ?
 10441                                  	;jna	short eetc_20 ; no
 10442                                  	;mov	ax, 1023 ; 03FFh ; fix end CHS values of the PTE
 10443                                  	; 13/03/2021
 10444 00002A2C 663DFF030000            	cmp	eax, 1023
 10445 00002A32 7606                    	jna	short eetc_20
 10446 00002A34 66B8FF030000            	mov	eax, 1023
 10447                                  eetc_20:
 10448 00002A3A 884507                  	mov	[di+ptEndCylinder], al
 10449 00002A3D 8A84[736C]              	mov	al, [si+part_table_end_sector]
 10450 00002A41 C0E406                  	shl	ah, 6
 10451 00002A44 08C4                    	or	ah, al	
 10452 00002A46 886506                  	mov	[di+ptEndSector], ah
 10453 00002A49 8A84[726C]              	mov	al, [si+part_table_end_head]
 10454 00002A4D 884505                  	mov	[di+ptEndHead], al
 10455                                  
 10456                                  	;mov	ax, cx
 10457                                  	;mov	dx, bx
 10458                                  	;add	ax, 1
 10459                                  	;adc	dx, 0
 10460                                  	;	; dx:ax = end of extd partition + 1
 10461                                  	; 13/03/2021
 10462 00002A50 6689D0                  	mov	eax, edx
 10463 00002A53 6648                    	dec	eax
 10464                                  
 10465                                  	; 02/11/2020
 10466                                  	;sub	ax, [bp+ldd_start]
 10467                                  	;sbb	dx, [bp+ldd_start+2]
 10468                                  	;sub	ax, [di+ptStartSector]
 10469                                  	;sbb	dx, [di+ptStartSector+2]
 10470                                  	;	; dx:ax = new sector count of the ldd
 10471                                  	; 13/03/2021
 10472 00002A55 662B86[906D]            	sub	eax, [bp+ldd_start]
 10473 00002A5A 662B4508                	sub	eax, [di+ptStartSector]
 10474                                  
 10475                                  	;mov	[di+ptSectors], ax
 10476                                  	;mov	[di+ptSectors+2], dx
 10477                                  	; 13/03/2021
 10478 00002A5E 6689450C                	mov	[di+ptSectors], eax
 10479                                  	
 10480 00002A62 EB04                    	jmp	short eetc_8
 10481                                  eetc_7:
 10482                                  	;mov	ax, [di+ptSectors]
 10483                                  	;mov	dx, [di+ptSectors+2]
 10484                                  	; 13/03/2021
 10485 00002A64 668B450C                	mov	eax, [di+ptSectors]
 10486                                  eetc_8:
 10487                                  	; 13/03/2021
 10488                                  	;xor	edx, edx
 10489                                  	; 01/11/2020
 10490                                  	;cmp	word [endcyl], 1023
 10491                                  	;jna	short eetc_15
 10492                                  	; 13/03/2021
 10493 00002A68 66813E[BA6D]FF0300-     	cmp	dword [endcyl], 1023
 10493 00002A70 00                 
 10494 00002A71 7605                    	jna	short eetc_15
 10495                                  
 10496                                  	; 25/10/2020
 10497                                  	;mov	cx, [bp+ldd_start]
 10498                                  	;mov	bx, [bp+ldd_start+2]
 10499                                  	;; 01/11/2020
 10500                                  	;add	cx, [bp+ldd_size]
 10501                                  	;adc	bx, [bp+ldd_size+2]
 10502                                  	;sub	cx, 1 ; *
 10503                                  	;sbb	bx, 0 ; *
 10504                                  	;cmp	bx, [chs_limit+2]
 10505                                  	;jb	short eetc_15
 10506                                  	;ja	short eetc_19
 10507                                  	;cmp	cx, [chs_limit]
 10508                                  	;jna	short eetc_15
 10509                                  ;eetc_19:
 10510 00002A73 E8D900                  	call	size_to_fat_type_lba ; 25/10/2020
 10511 00002A76 EB03                    	jmp	short eetc_16
 10512                                  eetc_15:
 10513                                  	; Get proper FAT type in [ldd_type]
 10514                                  	; by using DX:AX - size -
 10515 00002A78 E8B500                  	call	size_to_fat_type
 10516                                  eetc_16:
 10517 00002A7B 884504                  	mov	[di+ptFileSystemID], al
 10518                                  
 10519                                  	; 13/03/2021
 10520                                  	; edx < 65536
 10521                                  
 10522                                  	; Write current EBR (with modified PT)
 10523                                  	;mov	ax, [bp+ldd_start]
 10524                                  	;mov	dx, [bp+ldd_start+2]
 10525 00002A7E 668B86[906D]            	mov	eax, [bp+ldd_start]
 10526                                  
 10527                                  	; 01/11/2020
 10528                                  	; ! safety ! (to protect MBR and primary partition)
 10529                                  ;eetc_16:
 10530                                  	;cmp	dx, [ep_StartSector+2]
 10531                                  	;jb	short eetc_18
 10532                                  	;ja	short eetc_17
 10533                                  	;cmp	ax, [ep_StartSector]
 10534                                  	;jna	short eetc_18
 10535                                  ;eetc_17:
 10536                                  	;mov	ah, 0FFh
 10537                                  	;jmp	print_error_code
 10538                                  ;eetc_18:
 10539                                  
 10540 00002A83 BB[FE69]                	mov	bx, ebr_buffer
 10541 00002A86 E885EF                  	call	write_hd_sector
 10542 00002A89 0F82CCDC                	jc	print_error_code ; ! display error msg and then exit !
 10543                                  
 10544 00002A8D A0[F869]                	mov	al, [ldrives]
 10545                                  	;mov	ah, 18 ; extended partition table structure size
 10546                                  	; 05/11/2020
 10547 00002A90 B416                    	mov	ah, 22 ; extended partition table structure size
 10548 00002A92 F6E4                    	mul	ah
 10549                                  
 10550 00002A94 89C6                    	mov	si, ax
 10551 00002A96 81C6[C66C]              	add	si, ext_table_boot_ind
 10552 00002A9A 87F7                    	xchg	si, di
 10553                                  
 10554                                  	; set partition (logical -dos- drive) data
 10555 00002A9C A5                      	movsw	; boot indicator, beginning head
 10556 00002A9D AC                      	lodsb
 10557 00002A9E 88C4                    	mov	ah, al
 10558 00002AA0 243F                    	and	al, 3Fh
 10559 00002AA2 AA                      	stosb	; beginning sector
 10560 00002AA3 C0EC06                  	shr	ah, 6
 10561 00002AA6 AC                      	lodsb	; beginning cylinder
 10562 00002AA7 AB                      	stosw
 10563                                  	; 21/03/2021
 10564 00002AA8 31C0                    	xor	ax, ax
 10565 00002AAA AB                      	stosw
 10566 00002AAB A5                      	movsw	; partition id, end head
 10567 00002AAC AC                      	lodsb
 10568 00002AAD 88C4                    	mov	ah, al
 10569 00002AAF 243F                    	and	al, 3Fh
 10570 00002AB1 AA                      	stosb	; end sector
 10571 00002AB2 C0EC06                  	shr	ah, 6
 10572 00002AB5 AC                      	lodsb	; end cylinder
 10573 00002AB6 AB                      	stosw
 10574                                  	; 21/03/2021
 10575 00002AB7 31C0                    	xor	ax, ax
 10576 00002AB9 AB                      	stosw
 10577                                  
 10578 00002ABA A5                      	movsw	; copy start sector (LBA) and sector count
 10579 00002ABB A5                      	movsw
 10580 00002ABC A5                      	movsw
 10581 00002ABD A5                      	movsw
 10582                                  
 10583 00002ABE FE06[F869]              	inc	byte [ldrives]
 10584                                  
 10585 00002AC2 E9D9FC                  	jmp	display_extended_pt
 10586                                  
 10587                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 10588                                  ; check free space in EXTENDED (DOS) partition
 10589                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 10590                                  ; 05/03/2019
 10591                                  
 10592                                  	; 12/03/2021 (fdisk4.s, 32 bit registers)
 10593                                  check_ext_free_space:
 10594                                  	;mov	ax, [ep_Size]
 10595                                  	;mov	dx, [ep_Size+2]
 10596 00002AC5 66A1[086C]              	mov	eax, [ep_Size]
 10597                                  	; 12/03/2021
 10598 00002AC9 6631DB                  	xor	ebx, ebx
 10599 00002ACC 8A1E[F869]              	mov	bl, [ldrives]
 10600 00002AD0 20DB                    	and	bl, bl
 10601 00002AD2 7421                    	jz	short cefs_1
 10602 00002AD4 80FB04                  	cmp	bl, 4
 10603 00002AD7 7602                    	jna	short cefs_0
 10604 00002AD9 B304                    	mov	bl, 4
 10605                                  cefs_0:
 10606 00002ADB FECB                    	dec	bl
 10607 00002ADD C0E302                  	shl	bl, 2 ; * 4
 10608                                  	;xor	bh, bh
 10609                                  	;mov	si, bx
 10610                                  
 10611                                  	;mov	cx, [si+ldd_start]
 10612                                  	;mov	bx, [si+ldd_start+2]
 10613                                  	;add	cx, [si+ldd_size]
 10614                                  	;adc	bx, [si+ldd_size+2]
 10615                                  	; 12/03/2021
 10616 00002AE0 668B97[906D]            	mov	edx, [bx+ldd_start]
 10617 00002AE5 660397[A06D]            	add	edx, [bx+ldd_size]
 10618                                  
 10619                                  	;add	ax, [ep_StartSector]
 10620                                  	;adc	dx, [ep_StartSector+2]
 10621 00002AEA 660306[006C]            	add	eax, [ep_StartSector]
 10622                                  
 10623                                  	;sub	ax, cx
 10624                                  	;sbb	dx, bx
 10625                                  
 10626 00002AEF 6629D0                  	sub	eax, edx
 10627 00002AF2 7501                    	jnz	short cefs_1
 10628                                  	
 10629                                  	;or	ax, ax
 10630                                  	;jnz	short cefs_1
 10631                                  
 10632                                  	; cf = 0 if the result not negative
 10633                                  
 10634 00002AF4 F9                      	stc
 10635                                  
 10636                                  	; cf = 1 if the result is negative or zero
 10637                                  	 
 10638                                  	; If cf = 0 -> There is free space as in DX:AX
 10639                                  	; NOTE: This calculation is unsafe if
 10640                                  	; logical dos drive count > 4 !	
 10641                                  	; (But still meaningful for creating a new ldd.
 10642                                  	;  Because a new ldd will be created only
 10643                                  	;  if ldd count < 4.)
 10644                                  cefs_1:
 10645                                  	; 12/03/2021
 10646 00002AF5 6689DA                  	mov	edx, ebx ; edx < 65536
 10647                                  	; eax = free space (sectors)
 10648 00002AF8 C3                      	retn
 10649                                  
 10650                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 10651                                  ; convert LBA to CHS parameters (in registers)
 10652                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 10653                                  ; 24/10/2020
 10654                                  
 10655                                  	; 21/03/2021
 10656                                  	; 13/03/2021 (fdisk4.s)
 10657                                  	; 01/03/2019 (hdimage.s)
 10658                                  lba_to_chs:
 10659                                  	; INPUT:
 10660                                  	;	DX:AX = LBA address
 10661                                  	; OUTPUT:
 10662                                  	;	AX = cylinder
 10663                                  	;	DL = sector
 10664                                  	;	DH = head
 10665                                  	; 24/10/2020
 10666                                  	;	BL = extended partition ID (05h, 0Fh)
 10667                                  	;
 10668                                  	; (modified registers: ax, bx, cx, dx)
 10669                                  
 10670                                  	; 13/03/2021
 10671                                  	;
 10672                                  	; INPUT:
 10673                                  	;	EAX = LBA address
 10674                                  	; OUTPUT:
 10675                                  	;	EAX = cylinder (<= 1023)
 10676                                  	;	 DL = sector
 10677                                  	;	 DH = head
 10678                                  	;
 10679                                  	;	ECX = cylinder
 10680                                  
 10681                                  	;mov	cx, [sectors]
 10682                                  	;call	div32
 10683                                  	;inc	bl
 10684                                  	; 13/03/2021
 10685 00002AF9 6629D2                  	sub	edx, edx
 10686 00002AFC 660FB70E[A23C]          	movzx	ecx, word [sectors]
 10687 00002B02 66F7F1                  	div	ecx
 10688 00002B05 FEC2                    	inc	dl
 10689                                  
 10690                                  	;push	bx ; BL = sector
 10691                                  	;mov	cx, [heads]
 10692                                  	;call	div32
 10693                                  	;pop	dx  ; DL = sector
 10694                                  	;mov	dh, bl ; BL = head
 10695                                  	; 13/03/2021
 10696 00002B07 52                      	push	dx
 10697 00002B08 31D2                    	xor	dx, dx ; 21/03/2021
 10698 00002B0A 8B0E[A43C]              	mov	cx, [heads]
 10699 00002B0E 66F7F1                  	div	ecx
 10700                                  	; dl = head
 10701 00002B11 88D3                    	mov	bl, dl
 10702 00002B13 5A                      	pop	dx ; dl = sector
 10703 00002B14 88DE                    	mov	dh, bl ; dh = head
 10704                                  
 10705                                  	; 24/10/2020
 10706                                  	; check cylinder number (CHS) limit
 10707                                  	;mov	bh, 05h ; ENTENTED (LBA)
 10708                                  	; 13/03/2021
 10709 00002B16 B305                    	mov	bl, 05h ; ENTENTED (LBA) 
 10710                                  
 10711                                  	;mov	cx, ax ; 01/11/2020
 10712                                  	; 13/03/2021
 10713 00002B18 6689C1                  	mov	ecx, eax
 10714                                  
 10715                                  	;cmp	ax, 1023
 10716                                  	; 13/03/2021
 10717 00002B1B 663DFF030000            	cmp	eax, 1023
 10718 00002B21 760C                    	jna	short lbatochs_ok
 10719                                  
 10720                                  	;mov	ax, 1023 ; BC/EC = 0FFh
 10721                                  	; 13/03/2021
 10722 00002B23 66B8FF030000            	mov	eax, 1023
 10723 00002B29 B23F                    	mov	dl, 63  ; BS/ES = 0FFh
 10724 00002B2B B6FE                    	mov	dh, 254 ; BH/EH = 0FEh
 10725 00002B2D B30F                    	mov	bl, 0Fh ; EXTENDED (CHS)
 10726                                  lbatochs_ok:
 10727 00002B2F C3                      	retn
 10728                                  
 10729                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 10730                                  ; specify FAT type by using partition/volume size (CHS)
 10731                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 10732                                  ; 02/03/2019
 10733                                  
 10734                                  	; 13/03/2021 (fdisk4.s)
 10735                                  size_to_fat_type:
 10736                                  	; INPUT:
 10737                                  	;	DX:AX = DOS Partition Size in sectors
 10738                                  	; OUTPUT:
 10739                                  	;	AL = Partition type/ID (FAT type)
 10740                                  
 10741                                  	;or	dx, dx
 10742                                  	;jnz	short stft_2
 10743                                  
 10744                                  	; 13/03/2021
 10745 00002B30 6689C2                  	mov	edx, eax
 10746 00002B33 66C1EA10                	shr	edx, 16	
 10747 00002B37 750B                    	jnz	short stft_2
 10748                                  
 10749 00002B39 3DA87F                  	cmp	ax, 32680
 10750 00002B3C 7703                    	ja	short stft_1
 10751                                  stft_0:	
 10752 00002B3E B001                    	mov	al, 1	; FAT12 file system
 10753 00002B40 C3                      	retn
 10754                                  stft_1:
 10755 00002B41 B004                    	mov	al, 4	; FAT16 (< 32MB)
 10756 00002B43 C3                      	retn	
 10757                                  stft_2:
 10758 00002B44 83FA10                  	cmp	dx, 10h
 10759 00002B47 7303                    	jnb	short stft_3 ; FAT32 (CHS) file system	
 10760                                  
 10761 00002B49 B006                    	mov	al, 6	; FAT16 (>= 32MB)
 10762 00002B4B C3                      	retn
 10763                                  stft_3:
 10764 00002B4C B00B                    	mov	al, 0Bh ; FAT32 (CHS)
 10765 00002B4E C3                      	retn
 10766                                  
 10767                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 10768                                  ; specify FAT type by using partition/volume size (LBA)
 10769                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 10770                                  ; 25/10/2020
 10771                                  
 10772                                  	; 13/03/2021 (fdisk4.s)
 10773                                  size_to_fat_type_lba:
 10774                                  	; INPUT:
 10775                                  	;	DX:AX = DOS Partition Size in sectors
 10776                                  	; OUTPUT:
 10777                                  	;	AL = Partition type/ID (FAT type)
 10778                                  
 10779                                  	; 13/03/2021
 10780                                  	; eax = DOS Partition Size in sectors
 10781                                  
 10782                                  	;or	dx, dx
 10783                                  	;jz	short stft_4
 10784                                  
 10785                                  	; 13/03/2021
 10786 00002B4F 6689C2                  	mov	edx, eax
 10787 00002B52 66C1EA10                	shr	edx, 16	
 10788 00002B56 7408                    	jz	short stft_4
 10789                                  
 10790 00002B58 83FA10                  	cmp	dx, 10h
 10791 00002B5B 7208                    	jb	short stft_5 ; FAT16 (LBA) file system	
 10792                                  
 10793 00002B5D B00C                    	mov	al, 0Ch ; FAT32 file system (LBA)
 10794 00002B5F C3                      	retn
 10795                                  stft_4:
 10796 00002B60 3DA87F                  	cmp	ax, 32680
 10797 00002B63 76D9                    	jna	short stft_0  ; FAT12 file system
 10798                                  stft_5:	
 10799 00002B65 B00E                    	mov	al, 0Eh	; FAT16 file system (LBA)
 10800 00002B67 C3                      	retn
 10801                                  
 10802                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 10803                                  ; get requested logical dos drive size (from user)
 10804                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 10805                                  ; 02/03/2019
 10806                                  	
 10807                                  	; 13/03/2021
 10808                                  	; 12/03/2021 (fdisk4.s)
 10809                                  get_ldd_size:
 10810                                  	; INPUT -> none
 10811                                  	;
 10812                                  	; OUTPUT -> 
 10813                                  	;	[lcylinders] = cylinder count
 10814                                  	;
 10815                                  	; (Modified registers: ax, bx, cx, dx, si, di) 
 10816                                  
 10817 00002B68 B80300                  	mov	ax, 3 ; clear screen
 10818 00002B6B CD10                    	int	10h
 10819                                  
 10820 00002B6D BE[F644]                	mov	si, msg_create_dos_partition_h
 10821 00002B70 E83DEE                  	call	print_msg
 10822                                  
 10823                                  	; 03/03/2019
 10824 00002B73 A0[F869]                	mov	al, [ldrives]
 10825 00002B76 08C0                    	or	al, al		; cmp byte [ldrives], 0
 10826 00002B78 7405                    	jz	short gldds_1	; jna short gldds_0
 10827                                  
 10828                                  	;push	ax ; *
 10829                                  
 10830                                  	;dec	al
 10831                                  	;mov	ah, 22 ; 05/11/2020
 10832                                  	;mul	ah
 10833                                  	
 10834                                  	;mov	di, ext_table_rel_sec_lw
 10835                                  	;add	di, ax
 10836                                  
 10837 00002B7A BE[0A4B]                	mov	si, msg_use_all_space
 10838                                  	; 01/11/2020
 10839                                  	;call	print_msg
 10840 00002B7D EB03                    	jmp	short gldds_2
 10841                                  
 10842                                  	; Calculate available space
 10843                                  
 10844                                  	;mov	ax, [ep_Size] ; ext part size in sectors
 10845                                  	;mov	dx, [ep_Size+2]
 10846                                  	
 10847                                  	; 04/03/2019
 10848                                  ;gldds_0:
 10849                                  	;mov	cx, [di]    ; start sector
 10850                                  	;mov	bx, [di+2]
 10851                                  	;add	cx, [di+4]  ; sectors
 10852                                  	;adc	bx, [di+6]
 10853                                  	;	; bx:cx = start of next ldd
 10854                                  	;sub	ax, cx
 10855                                  	;sbb	dx, bx
 10856                                  	;	; dx:ax = free space in sectors
 10857                                  	;
 10858                                  	;pop	cx ; *
 10859                                  	;dec	cl
 10860                                  	;jz	short gldds_2
 10861                                  	;sub	di, 22 ; 05/11/2020
 10862                                  	;push	cx ; *
 10863                                  	;jmp	short gldds_0
 10864                                  
 10865                                  	; 05/03/2019
 10866                                  	;call	check_ext_free_space
 10867                                  	;jc	short gldds_cancel
 10868                                  	
 10869                                  	; 01/11/2020
 10870                                  	; 30/10/2020
 10871                                  	;mov	ax, [ep_free_sectors]
 10872                                  	;mov	dx, [ep_free_sectors+2]
 10873                                  	
 10874                                  		; DX:AX = free sectors in extended partition
 10875                                  	;jmp	short gldds_2
 10876                                  gldds_1:
 10877 00002B7F BE[3D4B]                	mov	si, msg_use_entire_ep_space
 10878                                  	;call	print_msg
 10879                                  	
 10880                                  	; 01/11/2020
 10881                                  	; Calculate free space in extended partition
 10882                                  	;mov	ax, [ep_Size]
 10883                                  	;mov	dx, [ep_Size+2]
 10884                                  gldds_2:
 10885                                  	; 01/11/2020
 10886 00002B82 E82BEE                  	call	print_msg
 10887                                  
 10888                                  	; 13/03/2021
 10889                                  	;mov	al, [heads]
 10890                                  	;mul	byte [sectors]
 10891                                  	;;mov	cx, ax
 10892                                  	;; 12/03/2021
 10893                                  	;movzx	ecx, ax	
 10894                                  	
 10895                                  	;mov	ax, [ep_free_sectors]
 10896                                  	;mov	dx, [ep_free_sectors+2]
 10897                                  	; 12/03/2021
 10898 00002B85 66A1[B06D]              	mov	eax, [ep_free_sectors]
 10899                                  
 10900                                  	;; 01/11/2020
 10901                                  	;; this is needed for partition size input
 10902                                  	;; (maximum available sectors)
 10903                                  	;;mov	[pp_Sectors], ax
 10904                                  	;;mov	[pp_Sectors+2], dx
 10905                                  
 10906                                  	;; 01/11/2020
 10907                                  	;; subtrack start offset (which always equals to spt value)
 10908                                  	;;sub	ax, [sectors]
 10909                                  	;;sbb	dx, 0
 10910                                  
 10911                                  	;;mov	cx, ax
 10912                                  	;;mov	al, [heads]
 10913                                  	;;mul	byte [sectors]
 10914                                  	;;xchg	ax, cx
 10915                                  	;	; dx:ax = sectors
 10916                                  	;	; cx = heads*spt 
 10917                                  	;;call	div32
 10918                                  	;	; ax = cylinders
 10919                                  	;	; bx = remainder
 10920                                   	;	; dx = 0
 10921                                  	;;and	bx, bx
 10922                                  	;;jz	short gldds_3
 10923                                  	;;inc	ax
 10924                                  	; 01/11/2020
 10925                                  	;div	cx
 10926                                  	; 12/03/2021
 10927 00002B89 6631D2                  	xor	edx, edx
 10928                                  	;div	ecx
 10929                                  	; 13/03/2021
 10930 00002B8C 66F736[E469]            	div	dword [hs] ; heads*spt
 10931                                  
 10932                                  	;and	dx, dx
 10933                                  	;jz	short gldds_3
 10934                                  	;inc	ax
 10935                                  gldds_3:
 10936                                  	;mov	[lcylinders], ax ; <= 65535 (< 65535)
 10937                                  	; 12/03/2021
 10938 00002B91 66A3[B46D]              	mov	[lcylinders], eax ; <= 267369
 10939                                  gldds_getchar:
 10940 00002B95 30E4                    	xor	ah, ah
 10941 00002B97 CD16                    	int	16h
 10942                                  
 10943 00002B99 3C1B                    	cmp	al, 27 ; ESCAPE key
 10944 00002B9B 7419                    	je	short gldds_cancel
 10945 00002B9D 24DF                    	and	al, 0DFh
 10946 00002B9F 3C4E                    	cmp	al, 'N'
 10947 00002BA1 741D                    	je	short gldds_4
 10948 00002BA3 3C59                    	cmp	al, 'Y'
 10949 00002BA5 75EE                    	jne	short gldds_getchar
 10950                                  
 10951                                  	; 01/11/2020
 10952                                  	;mov	word [lcylinders], 65535 ; sign for all free sectors
 10953                                  	; 12/03/2021
 10954 00002BA7 66C706[B46D]FFFFFF-     	mov	dword [lcylinders], 0FFFFFFFFh
 10954 00002BAF FF                 
 10955                                  				 ; sign for all free sectors
 10956 00002BB0 BE[8A59]                	mov	si, _msg_YES
 10957                                  	;call	print_msg
 10958                                  	;retn
 10959 00002BB3 E9FAED                  	jmp	print_msg
 10960                                  
 10961                                  gldds_cancel:
 10962                                  	;mov	word [lcylinders], 0
 10963                                  	; 12/03/2021
 10964 00002BB6 66C706[B46D]000000-     	mov	dword [lcylinders], 0
 10964 00002BBE 00                 
 10965                                  gldds_28:
 10966 00002BBF C3                      	retn
 10967                                  gldds_4:
 10968 00002BC0 BE[9059]                	mov	si, _msg_NO
 10969 00002BC3 E8EAED                  	call	print_msg
 10970                                  gldds_26:
 10971 00002BC6 B80300                  	mov	ax, 3 ; clear screen
 10972 00002BC9 CD10                    	int	10h
 10973                                  
 10974 00002BCB BE[F644]                	mov	si, msg_create_dos_partition_h
 10975 00002BCE E8DFED                  	call	print_msg
 10976                                  
 10977 00002BD1 BE[FC5E]                	mov	si, msg_create_ldd_s
 10978 00002BD4 E8D9ED                  	call	print_msg
 10979 00002BD7 BE[C84A]                	mov	si, msg_press_esc_to_cancel
 10980 00002BDA E8D3ED                  	call	print_msg
 10981                                  gldds_25:
 10982 00002BDD 30E4                    	xor	ah, ah
 10983 00002BDF CD16                    	int	16h
 10984                                  
 10985 00002BE1 3C1B                    	cmp	al, 27 ; ESCAPE key
 10986 00002BE3 7502                    	jne	short gldds_5
 10987                                  
 10988 00002BE5 EBCF                    	jmp	short gldds_cancel
 10989                                  gldds_5:
 10990                                  	; 04/03/2019
 10991 00002BE7 3C20                    	cmp	al, 32 ; SPACE key
 10992 00002BE9 74D4                    	je	short gldds_28
 10993                                  	
 10994                                  	; 01/11/2020
 10995                                  	;mov	byte [pSize_unit], '%'
 10996 00002BEB 3C25                    	cmp	al, '%'
 10997 00002BED 7416                    	je	short gldds_6
 10998                                  	;mov	byte [pSize_unit], 'M'
 10999 00002BEF 3C0D                    	cmp	al, 13 ; 0Dh, Carriage Return key
 11000                                  	;je	short gldds_6
 11001 00002BF1 7504                    	jne	short gldds_29
 11002                                  	; 01/11/2020
 11003 00002BF3 B04D                    	mov	al, 'M'
 11004 00002BF5 EB0E                    	jmp	short gldds_6
 11005                                  gldds_29:
 11006 00002BF7 24DF                    	and	al, 0DFh
 11007 00002BF9 3C4D                    	cmp	al, 'M'
 11008 00002BFB 7408                    	je	short gldds_6
 11009                                  	;mov	[pSize_unit], al
 11010 00002BFD 3C47                    	cmp	al, 'G'
 11011 00002BFF 7404                    	je	short gldds_6
 11012 00002C01 3C43                    	cmp	al, 'C'
 11013 00002C03 75D8                    	jne	short gldds_25
 11014                                  gldds_6:
 11015                                  	; 01/11/2020
 11016 00002C05 A2[CE69]                	mov	[pSize_unit], al
 11017                                  
 11018                                  	; Set maximum sector count (all of extended partition)
 11019                                  	;mov	al, [sectors]
 11020                                  	;mul	byte [heads]
 11021                                  	;mul	word [lcylinders]
 11022                                  	; 01/11/2020	
 11023                                  	;mov	ax, [ep_free_sectors]
 11024                                  	;mov	dx, [ep_free_sectors+2]
 11025                                  	;mov	[pp_Sectors], ax
 11026                                  	;mov	[pp_Sectors+2], dx
 11027                                  	; 12/03/2021
 11028 00002C08 66A1[B06D]              	mov	eax, [ep_free_sectors]
 11029 00002C0C 66A3[BC69]              	mov	[pp_Sectors], eax
 11030                                  
 11031 00002C10 E80BF0                   	call	partition_size_input
 11032 00002C13 72A1                    	jc	short gldds_cancel
 11033                                  		; DX:AX = Partition size in sectors
 11034                                  	;or	bx, bx
 11035                                  	;jnz	short gldds_cancel
 11036                                  
 11037                                  	; 01/11/2020
 11038                                  	;mov	[ppn_Sectors], ax
 11039                                  	;mov	[ppn_Sectors+2], dx
 11040                                  	; 12/03/2021
 11041 00002C15 66A3[F069]              	mov	[ppn_Sectors], eax ; edx = 0
 11042                                  		
 11043                                  	;mov	cx, ax
 11044                                  	;mov	al, [heads]
 11045                                  	;mul	byte [sectors]
 11046                                  	;xchg	ax, cx
 11047                                  	;	; dx:ax = sectors
 11048                                  	;	; cx = heads*spt 
 11049                                  	;call	div32
 11050                                  	;	; ax = cylinders
 11051                                  	;	; bx = remainder
 11052                                   	;	; dx = 0
 11053                                  	; 02/11/2020
 11054                                  	;and	bx, bx
 11055                                  	;jz	short gldds_7
 11056                                  	;inc	ax
 11057                                  
 11058                                  	; 13/03/2021
 11059                                  	; eax = partition size input, edx = 0
 11060 00002C19 66F736[E469]            	div	dword [hs] ; heads*sectors  ; <= 16065
 11061                                  	; eax = cylinders, dx = remainder
 11062 00002C1E 09D2                    	or	dx, dx
 11063 00002C20 7402                    	jz	short gldds_7
 11064 00002C22 6640                    	inc	eax ; +1
 11065                                  gldds_7:
 11066                                  	;cmp	ax, [lcylinders]
 11067                                  	; 13/03/2021
 11068 00002C24 663B06[B46D]            	cmp	eax, [lcylinders]
 11069 00002C29 7705                    	ja	short gldds_9
 11070                                  gldds_8:
 11071                                  	; OK
 11072                                  	;mov	[lcylinders], ax
 11073                                  	; 13/03/2021
 11074 00002C2B 66A3[B46D]              	mov	[lcylinders], eax
 11075 00002C2F C3                      	retn
 11076                                  
 11077                                  gldds_9:
 11078                                  	; Partition size limit message
 11079                                  	
 11080 00002C30 803E[CE69]43            	cmp	byte [pSize_unit], 'C'
 11081 00002C35 7415                    	je	short gldds_10
 11082                                  
 11083                                  	; Tolerate 1 cylinder if unit is not cylinder
 11084                                  	;dec	ax
 11085                                  	;cmp	ax, [lcylinders]
 11086                                  	;jna	short gldds_8
 11087                                  
 11088                                  	; 01/11/2020
 11089                                  	; Tolerate sectors if sectorcount doesn't over ep limit
 11090                                  	;mov	ax, [ppn_Sectors]
 11091                                  	;mov	dx, [ppn_Sectors+2]
 11092                                  	;cmp	dx, [ep_free_sectors+2]
 11093                                  	;ja	short gldds_10
 11094                                  	;jb	short gldds_30
 11095                                  	;cmp	ax, [ep_free_sectors]
 11096                                  	;ja	short gldds_10
 11097                                  	; 13/03/2021
 11098 00002C37 66A1[F069]              	mov	eax, [ppn_Sectors]
 11099 00002C3B 663B06[B06D]            	cmp	eax, [ep_free_sectors]
 11100 00002C40 770A                    	ja	short gldds_10
 11101                                  gldds_30:
 11102                                  	;mov	word [lcylinders], 65535 ; sign for all free sectors
 11103                                  	; 13/03/2021
 11104 00002C42 66C706[B46D]FFFFFF-     	mov	dword [lcylinders], 0FFFFFFFFh
 11104 00002C4A FF                 
 11105 00002C4B C3                      	retn
 11106                                  
 11107                                  gldds_10:
 11108                                  	; clear screen
 11109 00002C4C B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
 11110 00002C4F CD10                      	int	10h
 11111                                  
 11112 00002C51 BE[F644]                	mov	si, msg_create_dos_partition_h ; header
 11113 00002C54 E859ED                  	call	print_msg
 11114                                  
 11115 00002C57 BE[A95A]                	mov	si, msg_partition_size_limit
 11116 00002C5A E853ED                  	call	print_msg
 11117                                  
 11118 00002C5D 803E[CE69]4D            	cmp	byte [pSize_unit], 'M'
 11119 00002C62 7414                    	je	short gldds_11
 11120                                  
 11121 00002C64 803E[CE69]25            	cmp	byte [pSize_unit], '%'
 11122 00002C69 745E                    	je	short gldds_22
 11123                                  
 11124 00002C6B 803E[CE69]43            	cmp	byte [pSize_unit], 'C'
 11125 00002C70 7506                    	jne	short gldds_11
 11126                                  
 11127                                  	;mov	ax, [lcylinders]
 11128                                  	; 13/03/2021
 11129 00002C72 66A1[B46D]              	mov	eax, [lcylinders]
 11130 00002C76 EB15                    	jmp	short gldds_12
 11131                                  gldds_11:
 11132                                  	; 'M'
 11133                                  	;mov	ax, [pp_Sectors]
 11134                                  	;mov	dx, [pp_Sectors+2]
 11135                                  	;mov	cx, 2*1024 ; sectors -> MB
 11136                                  	;call	div32
 11137                                  	;	; DX = 0 
 11138                                  	;	; AX = Available space in Megabytes
 11139                                  	; 13/03/2021
 11140 00002C78 31FF                    	xor	di, di ; (**)
 11141 00002C7A 66A1[BC69]              	mov	eax, [pp_Sectors]
 11142                                  	;xor	edx, edx
 11143 00002C7E 31D2                    	xor	dx, dx
 11144                                  	;mov	ecx, 2*1024
 11145 00002C80 B90008                  	mov	cx, 2*1024
 11146 00002C83 66F7F1                  	div	ecx
 11147 00002C86 6683F801                	cmp	eax, 1
 11148 00002C8A 7601                    	jna	short gldds_12
 11149 00002C8C 47                      	inc	di ; (**)
 11150                                  gldds_12:
 11151 00002C8D B90A00                  	mov	cx, 10
 11152 00002C90 89E5                    	mov	bp, sp
 11153                                  gldds_13:
 11154 00002C92 31D2                    	xor	dx, dx
 11155                                  	;mov	cx, 10
 11156 00002C94 F7F1                    	div	cx
 11157 00002C96 52                      	push	dx ; *
 11158 00002C97 83F809                  	cmp	ax, 9
 11159 00002C9A 77F6                    	ja	short gldds_13
 11160                                  gldds_14:
 11161 00002C9C BB0700                  	mov	bx, 07h
 11162 00002C9F 09C0                    	or	ax, ax
 11163 00002CA1 7501                    	jnz	short gldds_16
 11164                                  gldds_15:
 11165 00002CA3 58                      	pop	ax ; *
 11166                                  gldds_16:
 11167 00002CA4 0430                    	add	al, '0'
 11168                                  gldds_17:
 11169 00002CA6 B40E                    	mov	ah, 0Eh
 11170                                  	;mov	bx, 07h
 11171 00002CA8 CD10                    	int	10h  ; write character (as tty)
 11172                                  
 11173 00002CAA 39EC                    	cmp	sp, bp
 11174 00002CAC 72F5                    	jb	short gldds_15
 11175                                  
 11176 00002CAE 803E[CE69]25            	cmp	byte [pSize_unit], '%'
 11177 00002CB3 7508                    	jne	short gldds_18
 11178                                  
 11179 00002CB5 3C25                    	cmp	al, '%'
 11180 00002CB7 743C                    	je	short gldds_21
 11181 00002CB9 B025                    	mov	al, '%'
 11182 00002CBB EBE9                    	jmp	short gldds_17
 11183                                  gldds_18:
 11184 00002CBD 803E[CE69]43            	cmp	byte [pSize_unit], 'C'
 11185 00002CC2 751D                    	jne	short gldds_19
 11186                                  
 11187 00002CC4 BE[455B]                	mov	si, msg_cylinders
 11188 00002CC7 EB29                    	jmp	short gldds_20
 11189                                  
 11190                                  gldds_22:
 11191                                  	; '%'
 11192                                  	; 01/11/2020
 11193                                  	;mov	dx, [ep_Size+2]
 11194                                  	;mov	ax, [ep_Size] ; *
 11195                                  	;and	dx, dx
 11196                                  	;jz	short gldds_33 ; dx = 0
 11197                                  	; 13/03/2021
 11198                                  	;mov	cx, 1
 11199                                  ;gldds_31:
 11200                                  	;shl	cx, 1
 11201                                  	;call	div32
 11202                                  	;or	dx, dx
 11203                                  	;jz	short gldds_32 ; *
 11204                                  	;mov	ax, [ep_Size]
 11205                                  	;mov	dx, [ep_Size+2]
 11206                                  	;jmp	short gldds_31
 11207                                  ;gldds_32:
 11208                                  	;mov	dx, [ep_free_sectors+2]
 11209                                  	; ep free sectors <= ep size
 11210                                  gldds_33:
 11211                                  	;push	ax ; * ; dx = 0 (ep size weight)
 11212                                  	;mov	ax, [ep_free_sectors]
 11213                                  	; 13/03/2021
 11214 00002CC9 66A1[B06D]              	mov	eax, [ep_free_sectors]
 11215                                  	;mov	ecx, 100
 11216 00002CCD B96400                  	mov	cx, 100
 11217                                  	;and	dx, dx
 11218                                  	;jnz	short gldds_34
 11219                                  	;mul	cx
 11220                                  	;jmp	short gldds_35
 11221                                  ;gldds_34:
 11222                                  	;call	mul32
 11223                                  	;	; dx:ax = 100 * ep free sectors weight
 11224                                  	; 13/03/2021
 11225                                  	;xor	edx, edx
 11226 00002CD0 31D2                    	xor	dx, dx
 11227 00002CD2 66F7E1                  	mul	ecx ; 100 * ep free sectors
 11228                                  ;gldds_35:
 11229                                  	;pop	cx ; *
 11230                                  	;call	div32 ; 100 * ep free sectors / ep size
 11231                                  	;	; ax = % value (<= 100)
 11232 00002CD5 66F736[086C]            	div	dword [ep_Size]
 11233                                  	
 11234 00002CDA 09C0                    	or	ax, ax
 11235                                  	;jnz	short gldds_23
 11236 00002CDC 75AF                    	jnz	short gldds_12 ; 13/03/2021
 11237 00002CDE 40                      	inc	ax ; 0 -> 1
 11238                                  	; 13/03/2021
 11239 00002CDF EBAC                    	jmp	short gldds_12
 11240                                  
 11241                                  ;gldds_23:	
 11242                                  	;mov	bp, sp
 11243                                  	;mov	cx, 10
 11244                                  ;gldds_24:	
 11245                                  	;xor	dx, dx
 11246                                  	;div	cx
 11247                                  	;push	dx ; *
 11248                                  	;cmp	ax, 9
 11249                                  	;ja	short gldds_24
 11250                                  	;jmp	short gldds_14
 11251                                  	
 11252                                  gldds_19:
 11253 00002CE1 BE[595B]                	mov	si, msg_megabytes
 11254 00002CE4 C606[625B]73            	mov	byte [msg_megabytes_s], 's'
 11255                                  	;cmp	di, 1
 11256                                  	;ja	short gldds_20
 11257                                  	; 13/03/2021
 11258 00002CE9 09FF                    	or	di, di ; (**)
 11259 00002CEB 7505                    	jnz	short  gldds_20
 11260                                  	; di = 0 -> 1 MB
 11261 00002CED C606[625B]00            	mov	byte [msg_megabytes_s], 0
 11262                                  gldds_20:
 11263 00002CF2 E8BBEC                  	call	print_msg
 11264                                  gldds_21:
 11265 00002CF5 BE[F65A]                	mov	si, msg_partition_size_limit_r
 11266 00002CF8 E8B5EC                  	call	print_msg
 11267                                  gldds_27:
 11268 00002CFB 30E4                    	xor	ah, ah
 11269 00002CFD CD16                    	int	16h
 11270                                  	
 11271 00002CFF 3C1B                    	cmp	al, 27 ; ESCAPE key
 11272 00002D01 0F84C1FE                	je	gldds_26
 11273 00002D05 3C0D                    	cmp	al, 13 ; ENTER (Carriage Return) key
 11274 00002D07 75F2                    	jne	short gldds_27
 11275                                  
 11276                                  	;mov	ax, [lcylinders]
 11277 00002D09 C3                      	retn
 11278                                  	
 11279                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 11280                                  ; initialize extended (dos) partition table 
 11281                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 11282                                  ; 18/10/2020 (fdisk3.s)
 11283                                  ; 26/02/2019 (hdimage.s)
 11284                                  
 11285                                  	; 09/03/2021
 11286                                  	; 05/11/2020 (fdisk4.s)
 11287                                  init_ext_partition_table:
 11288                                  
 11289                                  	; INPUT -> 
 11290                                  	;	[epnumber] = extended partition number
 11291                                  	;
 11292                                  	; OUTPUT -> none
 11293                                  
 11294                                  ; Display Method: ; 04/03/2019
 11295                                  ;LDD 1 <- LDD_START0, ebr 1st entry <- MBR (extended partition) - EBR 0
 11296                                  ;LDD 2 <- LDD_START1, ebr 1st entry <- EBR 1
 11297                                  ;LDD 3 <- LDD_START2, ebr 1st entry <- EBR 2
 11298                                  ;LDD 4 <- LDD_START3, ebr 1st entry <- EBR 3
 11299                                  ;LDD 5 <- LDD_START3, ebr 2nd entry (LDD 5 is not displayed)
 11300                                  
 11301                                  	; 08/03/2019
 11302                                  
 11303                                  	; clear extended partition table structure/list
 11304                                  
 11305 00002D0A BF[C66C]                	mov	di, ext_table_boot_ind
 11306 00002D0D 89FE                    	mov	si, di ; 28/02/2019
 11307                                  	;mov	cx, 36 ; 18*4 = 72 bytes
 11308                                  	; 05/11/2020
 11309 00002D0F B92C00                  	mov	cx, 44 ; 22*4 = 84 bytes
 11310 00002D12 31C0                    	xor	ax, ax ; 0
 11311 00002D14 F3AB                    	rep	stosw
 11312 00002D16 89F7                    	mov	di, si ; 28/02/2019
 11313                                  
 11314                                  	;mov	byte [ldrives], 0
 11315 00002D18 A2[F869]                	mov	[ldrives], al ; 0
 11316                                  
 11317                                  	;cmp	byte [epnumber], 1
 11318                                  	;jb	short iept_0
 11319                                  
 11320 00002D1B A0[C56C]                	mov	al, [epnumber]
 11321 00002D1E FEC8                    	dec	al
 11322                                  	;mov	ah, 18 ; partition table structure size 
 11323                                  	; 05/11/2020
 11324 00002D20 B416                    	mov	ah, 22 ; partition table structure size
 11325 00002D22 F6E4                    	mul	ah
 11326                                  	;mov	si, part_table_rel_sec_lw
 11327 00002D24 BE[786C]                	mov	si, part_table_rel_sec ; 09/03/2021
 11328 00002D27 01C6                    	add	si, ax
 11329                                  
 11330                                  	; 02/11/2020
 11331                                  	;(save end cylinder for comparising later)
 11332 00002D29 8B44FE                  	mov	ax, [si-2] ; part_table_end_cyl 
 11333                                  			; 16 bit cylinder number
 11334 00002D2C A3[BA6D]                	mov	[endcyl], ax
 11335                                  
 11336                                  	;mov	ax, [si]
 11337                                  	;mov	dx, [si+2]
 11338                                  	;mov	[ep_StartSector], ax
 11339                                  	;mov	[ep_StartSector+2], dx
 11340                                  	;mov	cx, [si+4]
 11341                                  	;mov	bx, [si+6]
 11342                                  	;mov	[ep_Size], cx
 11343                                  	;mov	[ep_Size+2], bx
 11344                                  	;sub	cx, 1
 11345                                  	;sbb	bx, 0
 11346                                  	;add	cx, ax
 11347                                  	;adc	bx, dx 
 11348                                  	;mov	[ep_EndSector], cx
 11349                                  	;mov	[ep_EndSector+2], bx
 11350                                  
 11351                                  	; 09/03/2021
 11352 00002D2F 668B04                  	mov	eax, [si]
 11353 00002D32 66A3[006C]              	mov	[ep_StartSector], eax
 11354 00002D36 668B5404                	mov	edx, [si+4]
 11355 00002D3A 668916[086C]            	mov	[ep_Size], edx
 11356 00002D3F 6601C2                  	add	edx, eax
 11357 00002D42 664A                    	dec	edx
 11358 00002D44 668916[046C]            	mov	[ep_EndSector], edx
 11359 00002D49 6631D2                  	xor	edx, edx
 11360                                  
 11361                                  	; 27/02/2019
 11362                                  	;mov	[ldd_start], ax
 11363                                  	;mov	[ldd_start+2], dx
 11364                                  	; 09/03/2021
 11365 00002D4C 66A3[906D]              	mov	[ldd_start], eax
 11366                                  
 11367                                  	; 03/03/2019
 11368                                  	;mov	word [ldd_size], 0
 11369                                  	;mov	word [ldd_size+2], 0
 11370                                  	
 11371 00002D50 BB[FE69]                	mov	bx, ebr_buffer
 11372                                  	; dx:ax = Extended partition address
 11373                                  	; es:bx = Extended partition buffer
 11374                                  	; 09/03/2021
 11375                                  	; eax = Extended partition address 
 11376                                  	; es:bx = Extended partition buffer
 11377                                   
 11378 00002D53 E869EC                  	call	read_hd_sector
 11379 00002D56 7209                    	jc	short iept_0
 11380                                  
 11381                                  	; Check EBR if it is a valid boot record or not
 11382 00002D58 813E[FC6B]55AA          	cmp	word [ebr_buffer+510], 0AA55h
 11383 00002D5E 7402                    	je	short iept_1
 11384                                  iept_stc_retn:
 11385 00002D60 F9                      	stc
 11386                                  iept_0:
 11387 00002D61 C3                      	retn
 11388                                  iept_1:
 11389                                  	; Check PTE 1, if it is valid or not
 11390 00002D62 A0[C06B]                	mov	al, [ebr_buffer+446+ptFileSystemID]
 11391 00002D65 20C0                    	and	al, al
 11392 00002D67 74F7                    	jz	short iept_stc_retn ; empty pte, error
 11393 00002D69 3C05                    	cmp	al, 5
 11394 00002D6B 74F3                    	je	short iept_stc_retn ; extended partition, error
 11395                                  	; 24/10/2020
 11396 00002D6D 3C0F                    	cmp	al, 0Fh
 11397 00002D6F 74EF                    	je	short iept_stc_retn ; extended partition, error
 11398                                  
 11399                                  	;inc	byte [ldrives] ; logical (dos) drive count
 11400                                  
 11401 00002D71 BE[BC6B]                	mov	si, ebr_buffer+446 ; Partition table offset
 11402 00002D74 B90400                  	mov	cx, 4
 11403                                  
 11404                                  	; set partition (logical -dos- drive) data
 11405 00002D77 A5                      	movsw	; boot indicator, beginning head
 11406 00002D78 AC                      	lodsb
 11407 00002D79 88C4                    	mov	ah, al
 11408 00002D7B 243F                    	and	al, 3Fh
 11409 00002D7D AA                      	stosb	; beginning sector
 11410 00002D7E C0EC06                  	shr	ah, 6
 11411 00002D81 AC                      	lodsb	; beginning cylinder
 11412 00002D82 AB                      	stosw
 11413                                  	; 09/03/2021
 11414 00002D83 31C0                    	xor	ax, ax
 11415 00002D85 AB                      	stosw
 11416                                  	;	
 11417 00002D86 A5                      	movsw	; partition id, end head
 11418 00002D87 AC                      	lodsb
 11419 00002D88 88C4                    	mov	ah, al
 11420 00002D8A 243F                    	and	al, 3Fh
 11421 00002D8C AA                      	stosb	; end sector
 11422 00002D8D C0EC06                  	shr	ah, 6
 11423 00002D90 AC                      	lodsb	; end cylinder
 11424 00002D91 AB                      	stosw
 11425                                  	; 09/03/2021
 11426 00002D92 31C0                    	xor	ax, ax
 11427 00002D94 AB                      	stosw
 11428                                  	;
 11429                                  
 11430                                  	; 04/03/2019
 11431 00002D95 8A1E[F869]              	mov	bl, [ldrives]
 11432                                  	;dec 	bl
 11433                                  	;jnz	short iept_2
 11434                                  
 11435                                  	; 05/03/2019
 11436 00002D99 08DB                    	or	bl, bl
 11437 00002D9B 7511                    	jnz	short iept_2
 11438                                  
 11439                                  	;mov	ax, [si]   ; start sector of 1st LDD (offset)
 11440                                  	;mov	dx, [si+2]
 11441                                  	;add	ax, [si+4] ; size of 1st LDD (volume)
 11442                                  	;adc	dx, [si+6]
 11443                                  	; 09/03/2021
 11444 00002D9D 668B04                  	mov	eax, [si]
 11445 00002DA0 66034404                	add	eax, [si+4]
 11446                                  
 11447                                  	;mov	[ldd_size], ax ; size of 1st LDD (partition)
 11448                                  	;mov	[ldd_size+2], dx
 11449                                  	; 09/03/2021
 11450 00002DA4 66A3[A06D]              	mov	[ldd_size], eax
 11451                                  
 11452                                  	; 05/03/2019
 11453 00002DA8 FE06[F869]              	inc	byte [ldrives] ; logical (dos) drive count
 11454 00002DAC FEC3                    	inc	bl
 11455                                  iept_2:
 11456 00002DAE F3A5                    	rep	movsw ; copy start sector (LBA) and sector count
 11457                                  
 11458                                  	; get next extended partition (logical -dos- drive) data
 11459 00002DB0 8A4404                  	mov	al, [si+ptFileSystemID]
 11460 00002DB3 20C0                    	and	al, al ; EMPTY
 11461 00002DB5 74AA                    	jz	short iept_0 ; end of logical -dos- drive chain
 11462                                  
 11463 00002DB7 3C05                    	cmp	al, 5 ; EXTENDED
 11464                                  	;jne	short iept_stc_retn  ; 2nd PTE must have
 11465                                  	;			     ; extended partition ID
 11466 00002DB9 7404                    	je	short iept_4
 11467                                  	; 24/10/2020
 11468 00002DBB 3C0F                    	cmp	al, 0Fh ; EXTENDED (LBA)
 11469 00002DBD 75A1                    	jne	short iept_stc_retn  ; 2nd PTE must have
 11470                                  				     ; extended partition ID
 11471                                  iept_4:
 11472                                  	; 05/03/2019
 11473 00002DBF FE06[F869]              	inc	byte [ldrives] ; logical (dos) drive count
 11474                                  
 11475                                  	;cmp	byte [ldrives], al ; 5
 11476 00002DC3 80FB04                  	cmp	bl, 4 ; number of logical dos drives (till here)
 11477 00002DC6 7332                    	jnb	short iept_3
 11478                                  
 11479 00002DC8 83C608                  	add	si, 8
 11480                                  
 11481                                  	;lodsw	
 11482                                  	;mov	dx, ax	; start sector
 11483                                  	;lodsw
 11484                                  	;xchg	dx, ax	; start sector + 2
 11485                                  	; 09/03/2021
 11486 00002DCB 66AD                    	lodsd
 11487                                  	
 11488                                  	; 04/03/2019
 11489                                  	;add	ax, [ep_StartSector]
 11490                                  	;adc	dx, [ep_StartSector+2]
 11491                                  	; 09/03/2021
 11492 00002DCD 660306[006C]            	add	eax, [ep_StartSector]
 11493                                  
 11494 00002DD2 30FF                    	xor	bh, bh
 11495 00002DD4 C0E302                  	shl	bl, 2 ; *4
 11496                                  
 11497                                  	; 28/02/2019
 11498                                  	;mov	[bx+ldd_start], ax ; start of (next) LDD (partition)
 11499                                  	;mov	[bx+ldd_start+2], dx
 11500                                  	; 09/03/2021
 11501 00002DD7 668987[906D]            	mov	[bx+ldd_start], eax
 11502                                  
 11503                                  	; 03/03/2019
 11504                                  	; set partition size for logical dos drive
 11505                                  	;mov	cx, [si]
 11506                                  	;mov	[bx+ldd_size], cx
 11507                                  	;mov	cx, [si+2]
 11508                                  	;mov	[bx+ldd_size+2], cx
 11509                                  	; 09/03/2021
 11510 00002DDC 668B14                  	mov	edx, [si]
 11511 00002DDF 668997[A06D]            	mov	[bx+ldd_size], edx
 11512 00002DE4 6629D2                  	sub	edx, edx
 11513                                  
 11514 00002DE7 BB[FE69]                	mov	bx, ebr_buffer
 11515                                  
 11516                                  	; dx:ax = Extended partition address
 11517                                  	; es:bx = Extended partition buffer
 11518                                  	; 09/03/2021
 11519                                  	; eax = Extended partition address
 11520                                   
 11521 00002DEA E8D2EB                  	call	read_hd_sector
 11522 00002DED 720B                    	jc	short iept_3 ; 03/03/2019
 11523                                  
 11524                                  	; Check EBR if it is valid or not
 11525 00002DEF 813E[FC6B]55AA          	cmp	word [ebr_buffer+510], 0AA55h
 11526 00002DF5 0F8469FF                	je	iept_1
 11527                                  
 11528 00002DF9 F9                      	stc
 11529                                  iept_3:	
 11530 00002DFA C3                      	retn
 11531                                  
 11532                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 11533                                  ; delete logical -dos- drives in extended partition
 11534                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 11535                                  ; 18/10/2020 (fdisk3.s)
 11536                                  
 11537                                  	; 12/03/2021
 11538                                  	; 09/03/2021 (fdisk4.s)
 11539                                  delete_logical_drives:
 11540                                  		; 27/02/2019 (hdimage.s)
 11541                                  
 11542                                  ; Delete Method: ; 04/03/2019
 11543                                  ;LDD 5 <- LDD_START3, ebr 2nd entry
 11544                                  ;LDD 4 <- LDD_START2, ebr 2nd entry
 11545                                  ;LDD 3 <- LDD_START1, ebr 2nd entry
 11546                                  ;LDD 2 <- LDD_START0, ebr 2nd entry
 11547                                  ;LDD 1 <- LDD_START0, ebr 1st entry
 11548                                  
 11549                                  	;cmp	byte [ldrives], 0
 11550                                  	;jna	short dld_stc
 11551                                  
 11552                                  	;mov	al, 5 ; extended partition (logical drives)
 11553                                  	;call	display_partition_table
 11554                                  	; 12/03/2021
 11555 00002DFB E8A3F7                  	call	display_partition_table_x
 11556                                  
 11557 00002DFE A0[F869]                	mov	al, [ldrives]
 11558 00002E01 0430                    	add	al, '0'
 11559 00002E03 A2[CF5C]                	mov	[lddp_num], al
 11560                                  
 11561 00002E06 BE[7C5C]                	mov	si, msg_delete_ldd
 11562 00002E09 E8A4EB                  	call	print_msg
 11563                                  
 11564 00002E0C BE[C84A]                	mov	si, msg_press_esc_to_cancel
 11565 00002E0F E89EEB                  	call	print_msg
 11566                                  dld_0:
 11567 00002E12 30E4                    	xor	ah, ah
 11568 00002E14 CD16                    	int	16h
 11569                                  
 11570 00002E16 80FC53                  	cmp	ah, 53h  ; DELETE or DEL key
 11571 00002E19 751C                    	jne	short dld_1
 11572                                  
 11573                                  	; Delete PTE 1 & PTE 2 on EBR 1
 11574 00002E1B 30E4                    	xor	ah, ah
 11575 00002E1D A0[F869]                	mov	al, [ldrives]
 11576 00002E20 FEC8                    	dec	al
 11577 00002E22 7518                    	jnz	short dld_2
 11578                                  
 11579 00002E24 BF[BC6B]                	mov	di, ebr_buffer+446
 11580 00002E27 B91000                  	mov	cx, 16
 11581 00002E2A F3AB                    	rep	stosw
 11582                                  
 11583                                  	; 04/03/2019
 11584                                  	; Clear ldd data in extended partition table/structure
 11585 00002E2C BF[C66C]                	mov	di, ext_table_boot_ind
 11586 00002E2F B109                    	mov	cl, 9
 11587 00002E31 F3AB                    	rep	stosw
 11588 00002E33 31F6                    	xor	si, si
 11589 00002E35 EB3D                    	jmp	short dld_3
 11590                                  dld_1:	
 11591 00002E37 3C1B                    	cmp	al, 27 ; ESC key
 11592 00002E39 75D7                    	jne	short dld_0
 11593                                  dld_5:
 11594 00002E3B C3                      	retn
 11595                                  
 11596                                  ;dld_stc:
 11597                                  ;	stc
 11598                                  ;	retn
 11599                                  
 11600                                  dld_2:
 11601                                  	; 04/03/2019
 11602                                  	; Delete 2nd PTE on EBR 2 to 4
 11603 00002E3C FEC8                    	dec	al 
 11604 00002E3E C0E002                  	shl	al, 2 ; * 4
 11605 00002E41 89C6                    	mov	si, ax
 11606                                  
 11607                                  	;mov	ax, [si+ldd_start]
 11608                                  	;mov	dx, [si+ldd_start+2]
 11609                                  	; 09/03/2021
 11610 00002E43 668B84[906D]            	mov	eax, [si+ldd_start]
 11611                                  
 11612 00002E48 BB[FE69]                	mov	bx, ebr_buffer
 11613 00002E4B E871EB                  	call	read_hd_sector
 11614 00002E4E 7235                    	jc	short dld_4
 11615                                  
 11616 00002E50 BF[CC6B]                	mov	di, ebr_buffer+446+16
 11617 00002E53 B90800                  	mov	cx, 8
 11618 00002E56 29C0                    	sub	ax, ax
 11619 00002E58 F3AB                    	rep	stosw
 11620                                  
 11621                                  	; 04/03/2019
 11622                                  	;cmp	byte [ldrives], 5
 11623                                  	;jnb	short dld_3
 11624 00002E5A 8A26[F869]              	mov	ah, [ldrives]
 11625 00002E5E 80FC05                  	cmp	ah, 5
 11626 00002E61 7311                    	jnb	short dld_3
 11627                                  
 11628                                  	; Clear ldd data in extended partition table/structure
 11629                                  	;mov	ah, [ldrives]
 11630 00002E63 FECC                    	dec	ah
 11631                                  	;mov	al, 18
 11632                                  	; 05/11/2020
 11633 00002E65 B016                    	mov	al, 22
 11634 00002E67 F6E4                    	mul	ah
 11635 00002E69 BF[C66C]                	mov	di, ext_table_boot_ind
 11636 00002E6C 01C7                    	add	di, ax
 11637                                  	;;mov	cx, 9
 11638                                  	;mov	cl, 9
 11639                                  	; 05/11/2020
 11640 00002E6E B10B                    	mov	cl, 11
 11641                                  	;xor	ax, ax
 11642 00002E70 30C0                    	xor	al, al
 11643 00002E72 F3AB                    	rep	stosw
 11644                                  dld_3:
 11645                                  	; Write changed EBR
 11646                                  	;mov	ax, [si+ldd_start]
 11647                                  	;mov	dx, [si+ldd_start+2]
 11648                                  	; 09/03/2021
 11649 00002E74 668B84[906D]            	mov	eax, [si+ldd_start]
 11650                                  
 11651 00002E79 BB[FE69]                	mov	bx, ebr_buffer
 11652 00002E7C E88FEB                  	call	write_hd_sector
 11653 00002E7F 7204                    	jc	short dld_4
 11654                                  
 11655                                  	; 28/02/2019
 11656 00002E81 FE0E[F869]              	dec	byte [ldrives]
 11657                                  dld_4:
 11658 00002E85 803E[F869]00            	cmp	byte [ldrives], 0
 11659 00002E8A 0F876DFF                	ja	delete_logical_drives
 11660                                  
 11661 00002E8E C3                      	retn
 11662                                  
 11663                                  ;=============================================================================
 11664                                  ;        	initialized data
 11665                                  ;=============================================================================
 11666                                  
 11667                                  ; 12/10/2020
 11668 00002E8F 00                      int13h_x:	db	0
 11669                                  
 11670                                  TRDOS386_MASTERBOOT_SECTOR:
 11671 00002E90 <bin 200h>              	incbin	'FS1_MBR.BIN' ; Singlix FS1 MBR	
 11672                                  
 11673                                  TRDOS_FAT_hd_bs:
 11674                                  	;incbin 'TRHDBS.BIN'
 11675                                  TRDOS_FAT32_hd_bs:
 11676 00003090 <bin 400h>              	incbin	'FAT32_BS.BIN' ; 27/04/2024
 11677                                  TRDOS_FAT16_hd_bs: 
 11678 00003490 <bin 200h>              	incbin	'FAT16_BS.BIN' ; 26/12/2017
 11679                                  TRDOS_FAT12_hd_bs: 
 11680 00003690 <bin 200h>              	incbin	'FAT12_BS.BIN' ; 26/12/2017
 11681                                  
 11682                                  TRDOS_TRFS1_chs_bs:
 11683 00003890 <bin 200h>              	incbin	'TRFS1CHS.BIN' ; Singlix FS1 (CHS+LBA Disk) BS
 11684                                  TRDOS_TRFS1_lba_bs:
 11685 00003A90 <bin 200h>              	incbin	'TRFS1LBA.BIN' ; Singlix FS1 (LBA Disk) BS
 11686                                  
 11687 00003C90 00                      	db	0
 11688                                  
 11689                                  hexchrs:
 11690 00003C91 303132333435363738-     	db	'0123456789ABCDEF'
 11690 00003C9A 39414243444546     
 11691                                  
 11692                                  ; 05/11/2020
 11693 00003CA1 00                      	db	0
 11694                                  
 11695                                  align 2
 11696                                  
 11697                                  ; (TR-DOS 386 compatible) Hard Disk (image) parameters
 11698                                  
 11699                                  sectors: ; sectors per track (63)
 11700 00003CA2 3F00                    	dw 63
 11701                                  heads:	 ; number of heads (16 or 32 or 64) 
 11702 00003CA4 1000                    	dw 16
 11703                                  cylinders: ; number of cylinders (16 to 1024)
 11704                                  	;dw 1024
 11705                                  	;dw 0 ; 16/10/2020 (double word)
 11706 00003CA6 00040000                	dd 1024 ; 05/11/2020 
 11707                                  
 11708                                  ; 05/11/2020
 11709                                  
 11710                                  ;random:
 11711                                  ;	db 0  ; random write to file (0 = sequental)
 11712                                  ;newdisk:
 11713                                  ;	db 0
 11714                                  
 11715                                  FileSys_Names: ; 2003-2017
 11716                                  ; (Valid FileSystems for TRDOS 386, SINGLIX, RETRO UNIX OS projects in 2017)
 11717 00003CAA 464154313220202020-     FS_FAT12:     db "FAT12         "  ; 01h = FAT12
 11717 00003CB3 2020202020         
 11718 00003CB8 58454E495820202020-     FS_XENIX:     db "XENIX         "  ; 02h , XENIX System V root
 11718 00003CC1 2020202020         
 11719 00003CC6 58454E495820757372-     FS_XENIX_USR: db "XENIX usr     "  ; 03h , XENIX System V user
 11719 00003CCF 2020202020         
 11720 00003CD4 464154313620283034-     FS_FAT16:     db "FAT16 (04h)   "  ; 04h = FAT16 < 32MB
 11720 00003CDD 6829202020         
 11721 00003CE2 455854454E44454420-     FS_EXT_CHS:   db "EXTENDED (CHS)"  ; 05h = Extended DOS Partition
 11721 00003CEB 2843485329         
 11722 00003CF0 464154313620283036-     FS_FAT16_BIG: db "FAT16 (06h)   "  ; 06h = FAT16 > 32MB, CHS mode
 11722 00003CF9 6829202020         
 11723 00003CFE 4E5446532020202020-     FS_NTFS:      db "NTFS          "  ; 07h , WINDOWS NTFS Partition
 11723 00003D07 2020202020         
 11724 00003D0C 464154333220284348-     FS_FAT32_CHS: db "FAT32 (CHS)   "  ; 0Bh = FAT32, CHS mode
 11724 00003D15 5329202020         
 11725 00003D1A 464154333220284C42-     FS_FAT32_LBA: db "FAT32 (LBA)   "  ; 0Ch = FAT32, LBA mode
 11725 00003D23 4129202020         
 11726 00003D28 464154313620284C42-     FS_FAT16_LBA: db "FAT16 (LBA)   "  ; 0Eh = FAT16, LBA mode
 11726 00003D31 4129202020         
 11727 00003D36 455854454E44454420-     FS_EXT_LBA:   db "EXTENDED (LBA)"  ; 0Fh = Extented Partition, LBA mode
 11727 00003D3F 284C424129         
 11728 00003D44 554E49582053595354-     FS_UNIX_SYSV: db "UNIX SYSTEM V "  ; 63h , SCO UNIX, UNIXWARE, OPENSERVER
 11728 00003D4D 454D205620         
 11729 00003D52 524554524F20554E49-     FS_RETROUNIX: db "RETRO UNIX    "  ; 71h , Retro UNIX 386 v2 Partition
 11729 00003D5B 5820202020         
 11730 00003D60 554E49582056372020-     FS_UNIX_V7:   db "UNIX V7       "  ; 72h , UNIX v7 x86 Partition  
 11730 00003D69 2020202020         
 11731 00003D6E 4C494E555820535741-     FS_LINUXSWAP: db "LINUX SWAP    "  ; 82h , LINUX SWAP Partition
 11731 00003D77 5020202020         
 11732 00003D7C 4C494E555820202020-     FS_LINUX:     db "LINUX         "  ; 83h , LINUX NATIVE (ext2) Partition
 11732 00003D85 2020202020         
 11733 00003D8A 4C494E555820455854-     FS_LINUXEXT:  db "LINUX EXTENDED"  ; 85h , LINUX EXTENDED Partition
 11733 00003D93 454E444544         
 11734 00003D98 524444202020202020-     FS_TRDD:      db "RDD           "  ; A0h , (Random Data Disk) LBA
 11734 00003DA1 2020202020         
 11735 00003DA6 53494E474C49582046-     FS_TRFS:      db "SINGLIX FS1   "  ; A1h , (32 bit, 512 bytes per sector)
 11735 00003DAF 5331202020         
 11736 00003DB4 554E4B4E4F574E2046-     FS_OTHERS:    db "UNKNOWN FS    "  ; Another or Unknown File Systems
 11736 00003DBD 5320202020         
 11737                                   
 11738                                  valid_partitions: ; (*)
 11739 00003DC2 01020304050607          	      db 01h, 02h, 03h, 04h, 05h, 06h, 07h
 11740 00003DC9 0B0C0E0F637172          	      db 0Bh, 0Ch, 0Eh, 0Fh, 63h, 71h, 72h
 11741 00003DD0 828385A0A1              	      db 82h, 83h, 85h, 0A0h, 0A1h 			
 11742                                  
 11743                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 11744                                  ;  messages
 11745                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 11746                                  
 11747                                  CHS_msg: ; 80 bytes per row
 11748 00003DD5 507265737320274327-     db  "Press 'C' to set cylinders then press '+,-' keys to change number of cylinders. "
 11748 00003DDE 20746F207365742063-
 11748 00003DE7 796C696E6465727320-
 11748 00003DF0 7468656E2070726573-
 11748 00003DF9 7320272B2C2D27206B-
 11748 00003E02 65797320746F206368-
 11748 00003E0B 616E6765206E756D62-
 11748 00003E14 6572206F662063796C-
 11748 00003E1D 696E646572732E20   
 11749 00003E25 507265737320274827-     db  "Press 'H' to set heads then press '+,-' keys to change number of heads.         "
 11749 00003E2E 20746F207365742068-
 11749 00003E37 65616473207468656E-
 11749 00003E40 20707265737320272B-
 11749 00003E49 2C2D27206B65797320-
 11749 00003E52 746F206368616E6765-
 11749 00003E5B 206E756D626572206F-
 11749 00003E64 662068656164732E20-
 11749 00003E6D 2020202020202020   
 11750 00003E75 507265737320275327-     db  "Press 'S' to set sectors then press '+,-' keys to change numb of sectors/track. "
 11750 00003E7E 20746F207365742073-
 11750 00003E87 6563746F7273207468-
 11750 00003E90 656E20707265737320-
 11750 00003E99 272B2C2D27206B6579-
 11750 00003EA2 7320746F206368616E-
 11750 00003EAB 6765206E756D62206F-
 11750 00003EB4 6620736563746F7273-
 11750 00003EBD 2F747261636B2E20   
 11751 00003EC5 202020202020202020-     db  "                                                                                "
 11751 00003ECE 202020202020202020-
 11751 00003ED7 202020202020202020-
 11751 00003EE0 202020202020202020-
 11751 00003EE9 202020202020202020-
 11751 00003EF2 202020202020202020-
 11751 00003EFB 202020202020202020-
 11751 00003F04 202020202020202020-
 11751 00003F0D 2020202020202020   
 11752 00003F15 202020202020202020-     db  "                                                                                "
 11752 00003F1E 202020202020202020-
 11752 00003F27 202020202020202020-
 11752 00003F30 202020202020202020-
 11752 00003F39 202020202020202020-
 11752 00003F42 202020202020202020-
 11752 00003F4B 202020202020202020-
 11752 00003F54 202020202020202020-
 11752 00003F5D 2020202020202020   
 11753 00003F65 507265737320454E54-     db  "Press ENTER to use current CHS values.                                          "
 11753 00003F6E 455220746F20757365-
 11753 00003F77 2063757272656E7420-
 11753 00003F80 4348532076616C7565-
 11753 00003F89 732E20202020202020-
 11753 00003F92 202020202020202020-
 11753 00003F9B 202020202020202020-
 11753 00003FA4 202020202020202020-
 11753 00003FAD 2020202020202020   
 11754 00003FB5 202020202020202020-     db  "                                                                                "
 11754 00003FBE 202020202020202020-
 11754 00003FC7 202020202020202020-
 11754 00003FD0 202020202020202020-
 11754 00003FD9 202020202020202020-
 11754 00003FE2 202020202020202020-
 11754 00003FEB 202020202020202020-
 11754 00003FF4 202020202020202020-
 11754 00003FFD 2020202020202020   
 11755 00004005 507265737320455343-     db  "Press ESC to cancel.                                                            "
 11755 0000400E 20746F2063616E6365-
 11755 00004017 6C2E20202020202020-
 11755 00004020 202020202020202020-
 11755 00004029 202020202020202020-
 11755 00004032 202020202020202020-
 11755 0000403B 202020202020202020-
 11755 00004044 202020202020202020-
 11755 0000404D 2020202020202020   
 11756 00004055 202020202020202020-     db  "                                                                                "
 11756 0000405E 202020202020202020-
 11756 00004067 202020202020202020-
 11756 00004070 202020202020202020-
 11756 00004079 202020202020202020-
 11756 00004082 202020202020202020-
 11756 0000408B 202020202020202020-
 11756 00004094 202020202020202020-
 11756 0000409D 2020202020202020   
 11757 000040A5 00                      db  0
 11758                                  
 11759                                  TrDOS_Welcome:
 11760 000040A6 0D0A                    	db	0Dh, 0Ah
 11761 000040A8 54522D444F53203338-     	db	'TR-DOS 386 Fixed Disk Partitioning Utility'
 11761 000040B1 362046697865642044-
 11761 000040BA 69736B205061727469-
 11761 000040C3 74696F6E696E672055-
 11761 000040CC 74696C697479       
 11762 000040D2 0D0A                    	db	0Dh, 0Ah
 11763 000040D4 76322E312E32343035-     	db	"v2.1.240504 (c) Erdogan TAN 2021-2024"
 11763 000040DD 303420286329204572-
 11763 000040E6 646F67616E2054414E-
 11763 000040EF 20323032312D323032-
 11763 000040F8 34                 
 11764 000040F9 0D0A                    	db	0Dh,0Ah
 11765 000040FB 0D0A                    	db	0Dh,0Ah
 11766 000040FD 00                      	db	0
 11767                                  TrDOS_Usage:
 11768 000040FE 55736167653A206664-     	db	'Usage: fdisk4 <hard disk name> '
 11768 00004107 69736B34203C686172-
 11768 00004110 64206469736B206E61-
 11768 00004119 6D653E20           
 11769 0000411D 0D0A                    	db	0Dh, 0Ah
 11770 0000411F 0D0A                    	db	0Dh, 0Ah
 11771 00004121 48617264206469736B-     	db	"Hard disk names: "
 11771 0000412A 206E616D65733A20   
 11772 00004132 0D0A                    	db	0Dh, 0Ah
 11773 00004134 0D0A                    	db	0Dh, 0Ah
 11774 00004136 20686430202E2E666F-     	db	" hd0 ..for 1st hard disk "
 11774 0000413F 722031737420686172-
 11774 00004148 64206469736B20     
 11775 0000414F 0D0A                    	db	0Dh, 0Ah
 11776 00004151 20686431202E2E666F-     	db	" hd1 ..for 2nd hard disk "
 11776 0000415A 7220326E6420686172-
 11776 00004163 64206469736B20     
 11777 0000416A 0D0A                    	db	0Dh, 0Ah
 11778 0000416C 20686432202E2E666F-     	db	" hd2 ..for 3rd hard disk "
 11778 00004175 722033726420686172-
 11778 0000417E 64206469736B20     
 11779 00004185 0D0A                    	db	0Dh, 0Ah
 11780 00004187 20686433202E2E666F-     	db	" hd3 ..for 4th hard disk "
 11780 00004190 722034746820686172-
 11780 00004199 64206469736B20     
 11781 000041A0 0D0A00                  	db	0Dh, 0Ah, 0
 11782                                  
 11783                                  TrDOS_Options:
 11784 000041A3 53656C656374206861-     	db	"Select hard disk number (1 to "
 11784 000041AC 7264206469736B206E-
 11784 000041B5 756D62657220283120-
 11784 000041BE 746F20             
 11785                                  TrDOS_dnmax:
 11786 000041C1 3429206F7220707265-     	db	"4) or press ESC to exit ..."
 11786 000041CA 73732045534320746F-
 11786 000041D3 2065786974202E2E2E 
 11787 000041DC 0D0A00                  	db	0Dh, 0Ah, 0
 11788                                  TrDOS_hdrow:
 11789 000041DF 0D0A                    	db	0Dh, 0Ah 
 11790 000041E1 28                      	db	"("
 11791                                  TrDOS_hdrow_n:
 11792 000041E2 3029206864              	db	"0) hd"
 11793                                  TrDOS_hdrow_i:
 11794 000041E7 30202D204361706163-     	db	"0 - Capacity : "
 11794 000041F0 697479203A20       
 11795 000041F6 00                      	db	0
 11796                                  TrDOS_hdrow_unit:
 11797 000041F7 474220                  	db	"GB "
 11798 000041FA 0D0A00                  	db 	0Dh, 0Ah, 0
 11799                                  
 11800                                  TrDOS_hdrow_capacity:
 11801 000041FD 303030302000            	db	"0000 ", 0
 11802 00004203 00                      	db	0
 11803                                  
 11804                                  TrDOS_disksize:
 11805 00004204 0D0A                    	db	0Dh, 0Ah
 11806 00004206 4469736B2073697A65-     	db	"Disk size : "
 11806 0000420F 203A20             
 11807 00004212 00                      	db	0
 11808                                  
 11809                                  ; 05/11/2020
 11810                                  ;msg_fdisk_capacity_err:
 11811                                  ;	db	0Dh, 0Ah
 11812                                  ;	db	"Huge disk !"
 11813                                  ;	db	0Dh, 0Ah
 11814                                  ;	db	"This FDISK version (v3) can work with disk sizes up to "
 11815                                  ;	db	0
 11816                                  
 11817                                  msg_any_key_esc_exit:
 11818 00004213 0D0A                    	db	0Dh, 0Ah
 11819 00004215 507265737320455343-     	db	"Press ESC to exit or press another key to continue..."
 11819 0000421E 20746F206578697420-
 11819 00004227 6F7220707265737320-
 11819 00004230 616E6F74686572206B-
 11819 00004239 657920746F20636F6E-
 11819 00004242 74696E75652E2E2E   
 11820 0000424A 00                      	db	0
 11821                                  
 11822                                  msg_create_partition_h:
 11823 0000424B 0D0A                    	db	0Dh, 0Ah
 11824 0000424D 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"
 11824 00004256 2D2D2D2D2D2D2D2D2D-
 11824 0000425F 2D2D2D2D2D2D2D2D2D-
 11824 00004268 2D2D2D2D2D2D2D2D2D-
 11824 00004271 2D2D2D2D2D2D2D2D2D-
 11824 0000427A 2D2D2D2D2D2D2D2D2D-
 11824 00004283 2D2D2D2D2D2D2D2D2D-
 11824 0000428C 2D2D2D2D2D2D2D2D2D-
 11824 00004295 2D2D2D2D2D2D2D2D   
 11825 0000429D 202020202020202020-     	db	"                               Create Partition                                 "
 11825 000042A6 202020202020202020-
 11825 000042AF 202020202020202020-
 11825 000042B8 202020204372656174-
 11825 000042C1 652050617274697469-
 11825 000042CA 6F6E20202020202020-
 11825 000042D3 202020202020202020-
 11825 000042DC 202020202020202020-
 11825 000042E5 2020202020202020   
 11826 000042ED 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"	
 11826 000042F6 2D2D2D2D2D2D2D2D2D-
 11826 000042FF 2D2D2D2D2D2D2D2D2D-
 11826 00004308 2D2D2D2D2D2D2D2D2D-
 11826 00004311 2D2D2D2D2D2D2D2D2D-
 11826 0000431A 2D2D2D2D2D2D2D2D2D-
 11826 00004323 2D2D2D2D2D2D2D2D2D-
 11826 0000432C 2D2D2D2D2D2D2D2D2D-
 11826 00004335 2D2D2D2D2D2D2D2D   
 11827 0000433D 0D0A00                  	db	0Dh, 0Ah, 0
 11828                                  msg_create_partition_m:
 11829 00004340 53656C65637420616E-     	db	"Select an option: "
 11829 00004349 206F7074696F6E3A20 
 11830 00004352 0D0A                    	db	0Dh, 0Ah
 11831 00004354 0D0A                    	db	0Dh, 0Ah
 11832 00004356 202031292043726561-     	db	"  1) Create DOS partition ", 0Dh, 0Ah
 11832 0000435F 746520444F53207061-
 11832 00004368 72746974696F6E200D-
 11832 00004371 0A                 
 11833 00004372 202032292043726561-     	db	"  2) Create SINGLIX FS partition ", 0Dh, 0Ah
 11833 0000437B 74652053494E474C49-
 11833 00004384 582046532070617274-
 11833 0000438D 6974696F6E200D0A   
 11834 00004395 202033292043726561-     	db	"  3) Create RETRO UNIX partition ", 0Dh, 0Ah
 11834 0000439E 746520524554524F20-
 11834 000043A7 554E49582070617274-
 11834 000043B0 6974696F6E200D0A   
 11835 000043B8 202034292043726561-     	db	"  4) Create another type of partition ", 0Dh, 0Ah
 11835 000043C1 746520616E6F746865-
 11835 000043CA 722074797065206F66-
 11835 000043D3 20706172746974696F-
 11835 000043DC 6E200D0A           
 11836 000043E0 0D0A                    	db	0Dh, 0Ah
 11837 000043E2 507265737320455343-     	db	"Press ESC or 0 to cancel .. "
 11837 000043EB 206F72203020746F20-
 11837 000043F4 63616E63656C202E2E-
 11837 000043FD 20                 
 11838 000043FE 0D0A00                   	db 	0Dh, 0Ah, 0
 11839                                  
 11840                                  msg_create_primary_partition_h:
 11841 00004401 0D0A                    	db	0Dh, 0Ah
 11842 00004403 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"
 11842 0000440C 2D2D2D2D2D2D2D2D2D-
 11842 00004415 2D2D2D2D2D2D2D2D2D-
 11842 0000441E 2D2D2D2D2D2D2D2D2D-
 11842 00004427 2D2D2D2D2D2D2D2D2D-
 11842 00004430 2D2D2D2D2D2D2D2D2D-
 11842 00004439 2D2D2D2D2D2D2D2D2D-
 11842 00004442 2D2D2D2D2D2D2D2D2D-
 11842 0000444B 2D2D2D2D2D2D2D2D   
 11843 00004453 202020202020202020-     	db	"                          Create Primary DOS Partition                          "
 11843 0000445C 202020202020202020-
 11843 00004465 202020202020202043-
 11843 0000446E 726561746520507269-
 11843 00004477 6D61727920444F5320-
 11843 00004480 506172746974696F6E-
 11843 00004489 202020202020202020-
 11843 00004492 202020202020202020-
 11843 0000449B 2020202020202020   
 11844 000044A3 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"
 11844 000044AC 2D2D2D2D2D2D2D2D2D-
 11844 000044B5 2D2D2D2D2D2D2D2D2D-
 11844 000044BE 2D2D2D2D2D2D2D2D2D-
 11844 000044C7 2D2D2D2D2D2D2D2D2D-
 11844 000044D0 2D2D2D2D2D2D2D2D2D-
 11844 000044D9 2D2D2D2D2D2D2D2D2D-
 11844 000044E2 2D2D2D2D2D2D2D2D2D-
 11844 000044EB 2D2D2D2D2D2D2D2D   
 11845 000044F3 0D0A00                  	db	0Dh, 0Ah, 0
 11846                                  
 11847                                  msg_create_dos_partition_h:
 11848 000044F6 0D0A                    	db	0Dh, 0Ah
 11849 000044F8 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"
 11849 00004501 2D2D2D2D2D2D2D2D2D-
 11849 0000450A 2D2D2D2D2D2D2D2D2D-
 11849 00004513 2D2D2D2D2D2D2D2D2D-
 11849 0000451C 2D2D2D2D2D2D2D2D2D-
 11849 00004525 2D2D2D2D2D2D2D2D2D-
 11849 0000452E 2D2D2D2D2D2D2D2D2D-
 11849 00004537 2D2D2D2D2D2D2D2D2D-
 11849 00004540 2D2D2D2D2D2D2D2D   
 11850 00004548 202020202020202020-     	db	"                   Create DOS Partition or Logical DOS Drive                    "
 11850 00004551 202020202020202020-
 11850 0000455A 204372656174652044-
 11850 00004563 4F5320506172746974-
 11850 0000456C 696F6E206F72204C6F-
 11850 00004575 676963616C20444F53-
 11850 0000457E 204472697665202020-
 11850 00004587 202020202020202020-
 11850 00004590 2020202020202020   
 11851 00004598 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"
 11851 000045A1 2D2D2D2D2D2D2D2D2D-
 11851 000045AA 2D2D2D2D2D2D2D2D2D-
 11851 000045B3 2D2D2D2D2D2D2D2D2D-
 11851 000045BC 2D2D2D2D2D2D2D2D2D-
 11851 000045C5 2D2D2D2D2D2D2D2D2D-
 11851 000045CE 2D2D2D2D2D2D2D2D2D-
 11851 000045D7 2D2D2D2D2D2D2D2D2D-
 11851 000045E0 2D2D2D2D2D2D2D2D   
 11852 000045E8 0D0A00                  	db	0Dh, 0Ah, 0
 11853                                  
 11854                                  msg_create_ext_partition_h:
 11855 000045EB 0D0A                    	db	0Dh, 0Ah
 11856 000045ED 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"
 11856 000045F6 2D2D2D2D2D2D2D2D2D-
 11856 000045FF 2D2D2D2D2D2D2D2D2D-
 11856 00004608 2D2D2D2D2D2D2D2D2D-
 11856 00004611 2D2D2D2D2D2D2D2D2D-
 11856 0000461A 2D2D2D2D2D2D2D2D2D-
 11856 00004623 2D2D2D2D2D2D2D2D2D-
 11856 0000462C 2D2D2D2D2D2D2D2D2D-
 11856 00004635 2D2D2D2D2D2D2D2D   
 11857 0000463D 202020202020202020-     	db	"                         Create Extended DOS Partition                          "
 11857 00004646 202020202020202020-
 11857 0000464F 202020202020204372-
 11857 00004658 656174652045787465-
 11857 00004661 6E64656420444F5320-
 11857 0000466A 506172746974696F6E-
 11857 00004673 202020202020202020-
 11857 0000467C 202020202020202020-
 11857 00004685 2020202020202020   
 11858 0000468D 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"
 11858 00004696 2D2D2D2D2D2D2D2D2D-
 11858 0000469F 2D2D2D2D2D2D2D2D2D-
 11858 000046A8 2D2D2D2D2D2D2D2D2D-
 11858 000046B1 2D2D2D2D2D2D2D2D2D-
 11858 000046BA 2D2D2D2D2D2D2D2D2D-
 11858 000046C3 2D2D2D2D2D2D2D2D2D-
 11858 000046CC 2D2D2D2D2D2D2D2D2D-
 11858 000046D5 2D2D2D2D2D2D2D2D   
 11859 000046DD 0D0A00                  	db	0Dh, 0Ah, 0
 11860                                  
 11861                                  msg_create_logical_drive_h:
 11862 000046E0 0D0A                    	db	0Dh, 0Ah
 11863 000046E2 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"
 11863 000046EB 2D2D2D2D2D2D2D2D2D-
 11863 000046F4 2D2D2D2D2D2D2D2D2D-
 11863 000046FD 2D2D2D2D2D2D2D2D2D-
 11863 00004706 2D2D2D2D2D2D2D2D2D-
 11863 0000470F 2D2D2D2D2D2D2D2D2D-
 11863 00004718 2D2D2D2D2D2D2D2D2D-
 11863 00004721 2D2D2D2D2D2D2D2D2D-
 11863 0000472A 2D2D2D2D2D2D2D2D   
 11864 00004732 202020202020202020-     	db	"                            Create Logical DOS Drive                            "
 11864 0000473B 202020202020202020-
 11864 00004744 202020202020202020-
 11864 0000474D 20437265617465204C-
 11864 00004756 6F676963616C20444F-
 11864 0000475F 532044726976652020-
 11864 00004768 202020202020202020-
 11864 00004771 202020202020202020-
 11864 0000477A 2020202020202020   
 11865 00004782 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"
 11865 0000478B 2D2D2D2D2D2D2D2D2D-
 11865 00004794 2D2D2D2D2D2D2D2D2D-
 11865 0000479D 2D2D2D2D2D2D2D2D2D-
 11865 000047A6 2D2D2D2D2D2D2D2D2D-
 11865 000047AF 2D2D2D2D2D2D2D2D2D-
 11865 000047B8 2D2D2D2D2D2D2D2D2D-
 11865 000047C1 2D2D2D2D2D2D2D2D2D-
 11865 000047CA 2D2D2D2D2D2D2D2D   
 11866 000047D2 0D0A00                  	db	0Dh, 0Ah, 0
 11867                                  
 11868                                  msg_create_nondos_partition_h:
 11869 000047D5 0D0A                    	db	0Dh, 0Ah
 11870 000047D7 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"
 11870 000047E0 2D2D2D2D2D2D2D2D2D-
 11870 000047E9 2D2D2D2D2D2D2D2D2D-
 11870 000047F2 2D2D2D2D2D2D2D2D2D-
 11870 000047FB 2D2D2D2D2D2D2D2D2D-
 11870 00004804 2D2D2D2D2D2D2D2D2D-
 11870 0000480D 2D2D2D2D2D2D2D2D2D-
 11870 00004816 2D2D2D2D2D2D2D2D2D-
 11870 0000481F 2D2D2D2D2D2D2D2D   
 11871 00004827 202020202020202020-     	db	"                            Create NON-DOS Partition                            "
 11871 00004830 202020202020202020-
 11871 00004839 202020202020202020-
 11871 00004842 20437265617465204E-
 11871 0000484B 4F4E2D444F53205061-
 11871 00004854 72746974696F6E2020-
 11871 0000485D 202020202020202020-
 11871 00004866 202020202020202020-
 11871 0000486F 2020202020202020   
 11872 00004877 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"
 11872 00004880 2D2D2D2D2D2D2D2D2D-
 11872 00004889 2D2D2D2D2D2D2D2D2D-
 11872 00004892 2D2D2D2D2D2D2D2D2D-
 11872 0000489B 2D2D2D2D2D2D2D2D2D-
 11872 000048A4 2D2D2D2D2D2D2D2D2D-
 11872 000048AD 2D2D2D2D2D2D2D2D2D-
 11872 000048B6 2D2D2D2D2D2D2D2D2D-
 11872 000048BF 2D2D2D2D2D2D2D2D   
 11873 000048C7 0D0A00                  	db	0Dh, 0Ah, 0
 11874                                  
 11875                                  msg_create_dos_partition_m:
 11876 000048CA 53656C65637420616E-     	db	"Select an option: "
 11876 000048D3 206F7074696F6E3A20 
 11877 000048DC 0D0A                    	db	0Dh, 0Ah
 11878 000048DE 0D0A                    	db	0Dh, 0Ah
 11879 000048E0 202031292043726561-     	db	"  1) Create Primary DOS partition ", 0Dh, 0Ah
 11879 000048E9 7465205072696D6172-
 11879 000048F2 7920444F5320706172-
 11879 000048FB 746974696F6E200D0A 
 11880 00004904 202032292043726561-     	db	"  2) Create Extended DOS partition ", 0Dh, 0Ah
 11880 0000490D 746520457874656E64-
 11880 00004916 656420444F53207061-
 11880 0000491F 72746974696F6E200D-
 11880 00004928 0A                 
 11881 00004929 202033292043726561-     	db	"  3) Create Logical DOS drive(s) in Extended DOS partition ", 0Dh, 0Ah
 11881 00004932 7465204C6F67696361-
 11881 0000493B 6C20444F5320647269-
 11881 00004944 766528732920696E20-
 11881 0000494D 457874656E64656420-
 11881 00004956 444F53207061727469-
 11881 0000495F 74696F6E200D0A     
 11882 00004966 0D0A                    	db	0Dh, 0Ah	
 11883 00004968 507265737320455343-     	db	"Press ESC or 0 to cancel .. "
 11883 00004971 206F72203020746F20-
 11883 0000497A 63616E63656C202E2E-
 11883 00004983 20                 
 11884 00004984 0D0A00                   	db 	0Dh, 0Ah, 0
 11885                                  
 11886                                  msg_create_trdos_partition_s:
 11887 00004987 53656C65637420616E-     	db	"Select an option to set partition size: "
 11887 00004990 206F7074696F6E2074-
 11887 00004999 6F2073657420706172-
 11887 000049A2 746974696F6E207369-
 11887 000049AB 7A653A20           
 11888 000049AF 0D0A                    	db	0Dh, 0Ah
 11889 000049B1 0D0A                    	db	0Dh, 0Ah
 11890 000049B3 202043292043796C69-     	db	"  C) Cylinder count", 0Dh, 0Ah
 11890 000049BC 6E64657220636F756E-
 11890 000049C5 740D0A             
 11891 000049C8 2020252920566F6C75-     	db	"  %) Volume percentage (##%)", 0Dh, 0Ah
 11891 000049D1 6D652070657263656E-
 11891 000049DA 746167652028232325-
 11891 000049E3 290D0A             
 11892 000049E6 202053292053656374-     	db	"  S) Sectors (number of 512 bytes)", 0Dh, 0Ah
 11892 000049EF 6F727320286E756D62-
 11892 000049F8 6572206F6620353132-
 11892 00004A01 206279746573290D0A 
 11893 00004A0A 20204B29204B696C6F-     	db	"  K) Kilo bytes (KB, 2*K sectors)", 0Dh, 0Ah
 11893 00004A13 20627974657320284B-
 11893 00004A1C 422C20322A4B207365-
 11893 00004A25 63746F7273290D0A   
 11894 00004A2D 20204D29204D656761-     	db	"  M) Mega bytes (MB, 2*1024*M sectors)", 0Dh, 0Ah
 11894 00004A36 20627974657320284D-
 11894 00004A3F 422C20322A31303234-
 11894 00004A48 2A4D20736563746F72-
 11894 00004A51 73290D0A           
 11895 00004A55 202047292047696761-     	db	"  G) Giga bytes (GB, 2*1024*1024*G sectors)", 0Dh, 0Ah
 11895 00004A5E 206279746573202847-
 11895 00004A67 422C20322A31303234-
 11895 00004A70 2A313032342A472073-
 11895 00004A79 6563746F7273290D0A 
 11896 00004A82 0D0A                    	db	0Dh, 0Ah	
 11897 00004A84 507265737320535041-     	db	"Press SPACE to use whole disk or press ENTER to set sector count .. "
 11897 00004A8D 434520746F20757365-
 11897 00004A96 2077686F6C65206469-
 11897 00004A9F 736B206F7220707265-
 11897 00004AA8 737320454E54455220-
 11897 00004AB1 746F20736574207365-
 11897 00004ABA 63746F7220636F756E-
 11897 00004AC3 74202E2E20         
 11898                                  msg_press_esc_to_cancel:
 11899 00004AC8 0D0A                     	db	0Dh, 0Ah
 11900 00004ACA 285072657373204553-     	db	"(Press ESC to CANCEL) "
 11900 00004AD3 4320746F2043414E43-
 11900 00004ADC 454C2920           
 11901 00004AE0 0D0A00                  	db 	0Dh, 0Ah, 0
 11902                                  
 11903                                  msg_use_whole_disk:
 11904 00004AE3 446F20796F75207761-     	db	"Do you want to use WHOLE disk !? (Y/N)", 0
 11904 00004AEC 6E7420746F20757365-
 11904 00004AF5 2057484F4C45206469-
 11904 00004AFE 736B20213F2028592F-
 11904 00004B07 4E2900             
 11905                                  
 11906                                  msg_use_all_space:
 11907 00004B0A 446F20796F75207761-     	db	"Do you want to use all of available space !? (Y/N)", 0
 11907 00004B13 6E7420746F20757365-
 11907 00004B1C 20616C6C206F662061-
 11907 00004B25 7661696C61626C6520-
 11907 00004B2E 737061636520213F20-
 11907 00004B37 28592F4E2900       
 11908                                  
 11909                                  msg_use_entire_ep_space:
 11910 00004B3D 446F20796F75207761-     	db	"Do you want to use entire extended partition space !? (Y/N)", 0
 11910 00004B46 6E7420746F20757365-
 11910 00004B4F 20656E746972652065-
 11910 00004B58 7874656E6465642070-
 11910 00004B61 6172746974696F6E20-
 11910 00004B6A 737061636520213F20-
 11910 00004B73 28592F4E2900       
 11911                                  
 11912                                  msg_partition_size:
 11913 00004B79 0D0A                    	db	0Dh, 0Ah
 11914 00004B7B 0D0A                    	db	0Dh, 0Ah
 11915 00004B7D 506172746974696F6E-     	db	"Partition size ("
 11915 00004B86 2073697A652028     
 11916                                  msg_partition_size_x:
 11917 00004B8D 3F29203A20              	db	"?) : "
 11918 00004B92 00                      	db	0
 11919                                  
 11920                                  msg_partition_type:
 11921 00004B93 0D0A                    	db	0Dh, 0Ah
 11922 00004B95 0D0A                    	db	0Dh, 0Ah
 11923 00004B97 506172746974696F6E-     	db	"Partition type : "
 11923 00004BA0 2074797065203A20   
 11924 00004BA8 00                      	db	0
 11925                                  
 11926                                  msg_ptype_num:
 11927 00004BA9 3030680D0A00            	db	"00h", 0Dh, 0Ah, 0
 11928                                  
 11929                                  msg_partition_type_error:
 11930 00004BAF 506172746974696F6E-     	db	"Partition size is not proper for selected partition type !"
 11930 00004BB8 2073697A6520697320-
 11930 00004BC1 6E6F742070726F7065-
 11930 00004BCA 7220666F722073656C-
 11930 00004BD3 656374656420706172-
 11930 00004BDC 746974696F6E207479-
 11930 00004BE5 70652021           
 11931 00004BE9 0D0A                    	db	0Dh, 0Ah
 11932                                  msg_any_key_to_retry:
 11933 00004BEB 28507265737320616E-     	db	"(Press any key to retry..)"
 11933 00004BF4 79206B657920746F20-
 11933 00004BFD 72657472792E2E29   
 11934 00004C05 0D0A00                  	db	0Dh, 0Ah, 0
 11935                                  
 11936                                  msg_partition_size_overs:
 11937 00004C08 0D0A                    	db	0Dh, 0Ah
 11938 00004C0A 506172746974696F6E-     	db	"Partition size overs the disk capacity !"
 11938 00004C13 2073697A65206F7665-
 11938 00004C1C 727320746865206469-
 11938 00004C25 736B20636170616369-
 11938 00004C2E 74792021           
 11939 00004C32 0D0A                    	db	0Dh, 0Ah
 11940 00004C34 28507265737320454E-     	db	"(Press ENTER to use WHOLE disk or press ESC key to retry..)" 
 11940 00004C3D 54455220746F207573-
 11940 00004C46 652057484F4C452064-
 11940 00004C4F 69736B206F72207072-
 11940 00004C58 65737320455343206B-
 11940 00004C61 657920746F20726574-
 11940 00004C6A 72792E2E29         
 11941 00004C6F 0D0A00                  	db	0Dh, 0Ah, 0
 11942                                  
 11943                                  msg_ext_partition_error:
 11944 00004C72 457874656E64656420-     	db	"Extended partition must be created after primary partition !"
 11944 00004C7B 706172746974696F6E-
 11944 00004C84 206D75737420626520-
 11944 00004C8D 637265617465642061-
 11944 00004C96 66746572207072696D-
 11944 00004C9F 617279207061727469-
 11944 00004CA8 74696F6E2021       
 11945 00004CAE 0D0A00                  	db	0Dh, 0Ah,0
 11946                                  
 11947                                  msg_logical_drive_error:
 11948 00004CB1 5072696D6172792061-     	db	"Primary and extended partitions must be created before logical drive !"
 11948 00004CBA 6E6420657874656E64-
 11948 00004CC3 656420706172746974-
 11948 00004CCC 696F6E73206D757374-
 11948 00004CD5 206265206372656174-
 11948 00004CDE 6564206265666F7265-
 11948 00004CE7 206C6F676963616C20-
 11948 00004CF0 64726976652021     
 11949 00004CF7 0D0A00                  	db	0Dh, 0Ah,0
 11950                                  
 11951                                  msg_cylinder_boundary_set:
 11952 00004CFA 0D0A                    	db	0Dh, 0Ah
 11953 00004CFC 446F20796F75207761-     	db	"Do you want to adjust partition size to cylinder boundary ? (Y/N)"
 11953 00004D05 6E7420746F2061646A-
 11953 00004D0E 757374207061727469-
 11953 00004D17 74696F6E2073697A65-
 11953 00004D20 20746F2063796C696E-
 11953 00004D29 64657220626F756E64-
 11953 00004D32 617279203F2028592F-
 11953 00004D3B 4E29               
 11954 00004D3D 00                      	db	0
 11955                                  
 11956                                  	; 2019 - 2020 (hdimage.s)
 11957                                  ;msg_selected_partition:
 11958                                  ;	db	"                                 PARTITION 0                                    "
 11959                                  ;	db	"================================================================================"
 11960                                  ;	db	"        S  BH  BS  BC  FS  EH  ES  EC    START SEC   SECTORS   FILE SYSTEM      "
 11961                                  ;	db	"--------------------------------------------------------------------------------"
 11962                                  ;pt_row: db	"                                                                                "
 11963                                  ;	db	"================================================================================"
 11964                                  ;	db	0
 11965                                  
 11966                                  	; 24/10/2020 (fdisk3.s)
 11967                                  msg_selected_partition:
 11968 00004D3E 202020202020202020-     	db	"                                 PARTITION 0                                    "
 11968 00004D47 202020202020202020-
 11968 00004D50 202020202020202020-
 11968 00004D59 202020202020504152-
 11968 00004D62 544954494F4E203020-
 11968 00004D6B 202020202020202020-
 11968 00004D74 202020202020202020-
 11968 00004D7D 202020202020202020-
 11968 00004D86 2020202020202020   
 11969 00004D8E 3D3D3D3D3D3D3D3D3D-     	db	"================================================================================"
 11969 00004D97 3D3D3D3D3D3D3D3D3D-
 11969 00004DA0 3D3D3D3D3D3D3D3D3D-
 11969 00004DA9 3D3D3D3D3D3D3D3D3D-
 11969 00004DB2 3D3D3D3D3D3D3D3D3D-
 11969 00004DBB 3D3D3D3D3D3D3D3D3D-
 11969 00004DC4 3D3D3D3D3D3D3D3D3D-
 11969 00004DCD 3D3D3D3D3D3D3D3D3D-
 11969 00004DD6 3D3D3D3D3D3D3D3D   
 11970 00004DDE 202020202020205320-     	db	"       S  BH  BS  BC  FS  EH  ES  EC   START SECT    SECTORS   FILE SYSTEM      "
 11970 00004DE7 204248202042532020-
 11970 00004DF0 424320204653202045-
 11970 00004DF9 482020455320204543-
 11970 00004E02 202020535441525420-
 11970 00004E0B 534543542020202053-
 11970 00004E14 4543544F5253202020-
 11970 00004E1D 46494C452053595354-
 11970 00004E26 454D202020202020   
 11971 00004E2E 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"
 11971 00004E37 2D2D2D2D2D2D2D2D2D-
 11971 00004E40 2D2D2D2D2D2D2D2D2D-
 11971 00004E49 2D2D2D2D2D2D2D2D2D-
 11971 00004E52 2D2D2D2D2D2D2D2D2D-
 11971 00004E5B 2D2D2D2D2D2D2D2D2D-
 11971 00004E64 2D2D2D2D2D2D2D2D2D-
 11971 00004E6D 2D2D2D2D2D2D2D2D2D-
 11971 00004E76 2D2D2D2D2D2D2D2D   
 11972 00004E7E 202020202020202020-     pt_row:	db	"                                                                                "
 11972 00004E87 202020202020202020-
 11972 00004E90 202020202020202020-
 11972 00004E99 202020202020202020-
 11972 00004EA2 202020202020202020-
 11972 00004EAB 202020202020202020-
 11972 00004EB4 202020202020202020-
 11972 00004EBD 202020202020202020-
 11972 00004EC6 2020202020202020   
 11973 00004ECE 3D3D3D3D3D3D3D3D3D-     	db	"================================================================================"
 11973 00004ED7 3D3D3D3D3D3D3D3D3D-
 11973 00004EE0 3D3D3D3D3D3D3D3D3D-
 11973 00004EE9 3D3D3D3D3D3D3D3D3D-
 11973 00004EF2 3D3D3D3D3D3D3D3D3D-
 11973 00004EFB 3D3D3D3D3D3D3D3D3D-
 11973 00004F04 3D3D3D3D3D3D3D3D3D-
 11973 00004F0D 3D3D3D3D3D3D3D3D3D-
 11973 00004F16 3D3D3D3D3D3D3D3D   
 11974 00004F1E 00                      	db	0
 11975                                  msg_boot_indicator:
 11976 00004F1F 0D0A                    	db	0Dh, 0Ah
 11977 00004F21 20202020426F6F7420-     	db	"    Boot Indicator : ", 0 ; "YES", "NO"
 11977 00004F2A 496E64696361746F72-
 11977 00004F33 203A2000           
 11978                                  msg_starting_head:
 11979 00004F37 0D0A                    	db	0Dh, 0Ah
 11980 00004F39 202020202053746172-     	db 	"     Starting Head : ", 0
 11980 00004F42 74696E672048656164-
 11980 00004F4B 203A2000           
 11981                                  msg_starting_sector:
 11982 00004F4F 0D0A                    	db	0Dh, 0Ah
 11983 00004F51 202020537461727469-     	db	"   Starting Sector : ", 0
 11983 00004F5A 6E6720536563746F72-
 11983 00004F63 203A2000           
 11984                                  msg_starting_cylinder:
 11985 00004F67 0D0A                    	db	0Dh, 0Ah
 11986 00004F69 205374617274696E67-     	db	" Starting Cylinder : ", 0
 11986 00004F72 2043796C696E646572-
 11986 00004F7B 203A2000           
 11987                                  msg_system_id:
 11988 00004F7F 0D0A                    	db	0Dh, 0Ah
 11989 00004F81 202020202020202020-     	db	"         System ID : ", 0
 11989 00004F8A 53797374656D204944-
 11989 00004F93 203A2000           
 11990                                  msg_ending_head:
 11991 00004F97 0D0A                    	db	0Dh, 0Ah
 11992 00004F99 20202020202020456E-     	db 	"       Ending Head : ", 0
 11992 00004FA2 64696E672048656164-
 11992 00004FAB 203A2000           
 11993                                  msg_ending_sector:
 11994 00004FAF 0D0A                    	db	0Dh, 0Ah
 11995 00004FB1 2020202020456E6469-     	db	"     Ending Sector : ", 0
 11995 00004FBA 6E6720536563746F72-
 11995 00004FC3 203A2000           
 11996                                  msg_ending_cylinder:
 11997 00004FC7 0D0A                    	db	0Dh, 0Ah
 11998 00004FC9 202020456E64696E67-     	db	"   Ending Cylinder : ", 0
 11998 00004FD2 2043796C696E646572-
 11998 00004FDB 203A2000           
 11999                                  msg_relative_sectors:
 12000 00004FDF 0D0A                    	db	0Dh, 0Ah
 12001 00004FE1 0D0A                    	db	0Dh, 0Ah
 12002 00004FE3 202052656C61746976-     	db	"  Relative Sectors : ", 0
 12002 00004FEC 6520536563746F7273-
 12002 00004FF5 203A2000           
 12003                                  msg_total_sectors:
 12004 00004FF9 0D0A                    	db	0Dh, 0Ah
 12005 00004FFB 2020202020546F7461-     	db	"     Total Sectors : ", 0
 12005 00005004 6C20536563746F7273-
 12005 0000500D 203A2000           
 12006                                  
 12007                                  msg_format_stage:
 12008 00005011 0D0A                    	db	0Dh, 0Ah
 12009 00005013 507265737320454E54-     	db	"Press ENTER to FORMAT disk partition "
 12009 0000501C 455220746F20464F52-
 12009 00005025 4D4154206469736B20-
 12009 0000502E 706172746974696F6E-
 12009 00005037 20                 
 12010                                  partition_num_chr:
 12011 00005038 30                      	db	"0"
 12012 00005039 206F72207072657373-     	db	" or press ESC to EXIT.."
 12012 00005042 2045534320746F2045-
 12012 0000504B 5849542E2E         
 12013 00005050 00                      	db	0
 12014                                  msg_partition_edit:
 12015 00005051 0D0A                    	db	0Dh, 0Ah
 12016 00005053 2E2E206F7220707265-     	db	".. or press SPACE to EDIT partition table."
 12016 0000505C 737320535041434520-
 12016 00005065 746F20454449542070-
 12016 0000506E 6172746974696F6E20-
 12016 00005077 7461626C652E       
 12017 0000507D 0D0A00                  	db	0Dh, 0Ah, 0
 12018                                  
 12019                                  msg_edit_or_exit:
 12020 00005080 0D0A                    	db 	0Dh, 0Ah
 12021 00005082 507265737320454E54-     	db	"Press ENTER to continue or press ESC to exit.."
 12021 0000508B 455220746F20636F6E-
 12021 00005094 74696E7565206F7220-
 12021 0000509D 707265737320455343-
 12021 000050A6 20746F20657869742E-
 12021 000050AF 2E                 
 12022 000050B0 00                      	db	0
 12023                                  
 12024                                  msg_overwrite_question1:
 12025 000050B1 0D0A                    	db	0Dh, 0Ah
 12026 000050B3 446F20796F75207761-     	db	'Do you want to overwrite '
 12026 000050BC 6E7420746F206F7665-
 12026 000050C5 72777269746520     
 12027 000050CC 27                      	db	27h
 12028 000050CD 00                      	db	0
 12029                                  
 12030                                  msg_overwrite_question2: 
 12031 000050CE 27                      	db	27h
 12032 000050CF 2066696C6520            	db	' file '
 12033 000050D5 00                      	db	0
 12034                                  
 12035                                  msg_format_question:
 12036 000050D6 0D0A                    	db	0Dh, 0Ah
 12037 000050D8 446F20796F75207761-     	db	"Do you want to format partition "
 12037 000050E1 6E7420746F20666F72-
 12037 000050EA 6D6174207061727469-
 12037 000050F3 74696F6E20         
 12038                                  partition_num_txt:
 12039 000050F8 3020                    	db	 "0 "
 12040                                  msg_yes_no:
 12041 000050FA 285965732F4E6F293F-     	db	'(Yes/No)? ', 0
 12041 00005103 2000               
 12042                                  
 12043                                  msg_writing_mbr:
 12044 00005105 57726974696E67206D-     	db	"Writing masterboot sector...", 0
 12044 0000510E 6173746572626F6F74-
 12044 00005117 20736563746F722E2E-
 12044 00005120 2E00               
 12045                                  
 12046                                  msg_writing_disk_sectors:
 12047 00005122 57726974696E672064-     	db	"Writing disk sector: ", 0
 12047 0000512B 69736B20736563746F-
 12047 00005134 723A2000           
 12048                                  
 12049                                  Msg_Writing_Boot_Sector:
 12050 00005138 57726974696E672074-     	db	"Writing trdos boot sector...", 0
 12050 00005141 72646F7320626F6F74-
 12050 0000514A 20736563746F722E2E-
 12050 00005153 2E00               
 12051                                  
 12052                                  Msg_Writing_Root_Dir:
 12053 00005155 57726974696E672072-     	db	"Writing root directory sectors...", 0
 12053 0000515E 6F6F74206469726563-
 12053 00005167 746F72792073656374-
 12053 00005170 6F72732E2E2E00     
 12054                                  
 12055                                  Msg_Writing_Data_Sectors:
 12056 00005177 57726974696E672064-     	db	"Writing data sector: ", 0
 12056 00005180 61746120736563746F-
 12056 00005189 723A2000           
 12057                                  
 12058                                  Sector_Str:
 12059 0000518D 3030303030303000        	db	"0000000", 0
 12060                                  Cursor_Pos:
 12061 00005195 0000                    	dw	0
 12062                                  
 12063                                  Msg_Writing_FAT_Sectors:
 12064 00005197 57726974696E672046-     	db	"Writing FAT sectors...", 0
 12064 000051A0 415420736563746F72-
 12064 000051A9 732E2E2E00         
 12065                                  
 12066                                  StrVolumeName:
 12067                                  	;times 	12 db  0
 12068 000051AE 00<rep 41h>             	times	65 db 0  ; 05/01/2018 (fs1 volume name)	
 12069                                  
 12070                                  Msg_Volume_Name:
 12071 000051EF 0D0A                    	db	0Dh, 0Ah
 12072 000051F1 0D0A                    	db	0Dh, 0Ah
 12073 000051F3 566F6C756D65204E61-     	db	"Volume Name: ", 0
 12073 000051FC 6D653A2000         
 12074                                  
 12075                                  Msg_Volume_Serial:
 12076 00005201 566F6C756D65205365-     	db	"Volume Serial No: "
 12076 0000520A 7269616C204E6F3A20 
 12077                                  Vol_Serial1:
 12078 00005213 30303030                	db	"0000"
 12079 00005217 2D                      	db	"-"
 12080                                  Vol_Serial2:
 12081 00005218 30303030                	db	"0000"
 12082 0000521C 0D0A00                  	db	0Dh, 0Ah, 0
 12083                                  
 12084                                  msg_cluster_count:
 12085 0000521F 436C75737465722043-     	db	"Cluster Count: ", 0
 12085 00005228 6F756E743A2000     
 12086                                  cluster_count_str:
 12087 0000522F 30303030303030          	db	"0000000"
 12088 00005236 0D0A00                  	db	0Dh, 0Ah, 0
 12089                                  msg_formatting:
 12090 00005239 466F726D617474696E-     	db	"Formatting ", 0
 12090 00005242 672000             
 12091                                  format_percent_str:
 12092 00005245 30303025                	db	"000%"
 12093 00005249 00                      	db	0
 12094                                  
 12095                                  Msg_3dot_OK:
 12096 0000524A 2E2E2E                  	db	"..."
 12097                                  Msg_OK:
 12098 0000524D 204F4B2E                	db	' OK.'
 12099                                  CRLF:
 12100 00005251 0D0A00                  	db	0Dh, 0Ah, 0
 12101                                  
 12102                                  Msg_Error:
 12103 00005254 0D0A                    	db	0Dh, 0Ah
 12104 00005256 4572726F72202120        	db	'Error ! '
 12105 0000525E 28                      	db	'('
 12106                                  error_code:
 12107 0000525F 3030                    	dw	3030h
 12108 00005261 68                      	db	'h'
 12109 00005262 2920                    	db	') '
 12110 00005264 0D0A                    	db	0Dh, 0Ah
 12111 00005266 00                      	db	0
 12112                                  
 12113                                  msg_disk_sectors:
 12114 00005267 546F74616C20446973-     	db	"Total Disk Sectors : ", 0
 12114 00005270 6B20536563746F7273-
 12114 00005279 203A2000           
 12115                                  
 12116                                  str_disk_sectors:
 12117                                  	;times	8 db 0
 12118 0000527D 00<rep Bh>              	times	11 db 0 ; 27/10/2020
 12119                                  
 12120                                  msg_ep_size:
 12121 00005288 457874656E64656420-     	db	"Extended Partition Size in Sectors: ", 0
 12121 00005291 506172746974696F6E-
 12121 0000529A 2053697A6520696E20-
 12121 000052A3 536563746F72733A20-
 12121 000052AC 00                 
 12122                                  
 12123                                  msg_press_any_key:
 12124 000052AD 0D0A                    	db	0Dh, 0Ah
 12125 000052AF 50726573732061206B-     	db	"Press a key to continue..."
 12125 000052B8 657920746F20636F6E-
 12125 000052C1 74696E75652E2E2E   
 12126 000052C9 0D0A00                  	db	0Dh, 0Ah, 0
 12127                                  
 12128                                  align 2
 12129                                  
 12130                                  ; Masterboot sector
 12131                                  
 12132                                  MasterBootBuff:
 12133                                  MasterBootCode: 
 12134 000052CC 00<rep 1BEh>            	times	446 db 0
 12135                                  PartitionTable:
 12136 0000548A 00<rep 40h>             	times	64 db 0
 12137                                  MBIDCode:
 12138 000054CA 0000                    	dw	0
 12139                                  
 12140                                  PTable_Buffer:
 12141 000054CC 00<rep 40h>             	times	64 db 0
 12142                                   
 12143 0000550C 286329204572646F67-     	db	'(c) Erdogan TAN 2019-2024'
 12143 00005515 616E2054414E203230-
 12143 0000551E 31392D32303234     
 12144                                  
 12145                                  ; 05/11/2020
 12146 00005525 00                      	db	0
 12147                                  
 12148                                  	; 2019 - 2020 (hdimage.s)
 12149                                  ;p_table_header:
 12150                                  ;	db	"                              ?BR PARTITION TABLE                               "
 12151                                  ;	db	"================================================================================"
 12152                                  ;	db	"       P  S  BH  BS  BC  FS  EH  ES  EC  START SEC  SECTORS  FILE SYSTEM        "
 12153                                  ;	db	"--------------------------------------------------------------------------------"
 12154                                  ;	db	0
 12155                                  ;p_table_footer:
 12156                                  ;	db	"================================================================================"
 12157                                  ;	db	0Dh, 0Ah, 0
 12158                                  
 12159                                  	; 24/10/2020 (fdisk3.s)
 12160                                  p_table_header:
 12161 00005526 202020202020202020-     	db	"                              ?BR PARTITION TABLE                               "
 12161 0000552F 202020202020202020-
 12161 00005538 202020202020202020-
 12161 00005541 2020203F4252205041-
 12161 0000554A 52544954494F4E2054-
 12161 00005553 41424C452020202020-
 12161 0000555C 202020202020202020-
 12161 00005565 202020202020202020-
 12161 0000556E 2020202020202020   
 12162 00005576 3D3D3D3D3D3D3D3D3D-     	db	"================================================================================"
 12162 0000557F 3D3D3D3D3D3D3D3D3D-
 12162 00005588 3D3D3D3D3D3D3D3D3D-
 12162 00005591 3D3D3D3D3D3D3D3D3D-
 12162 0000559A 3D3D3D3D3D3D3D3D3D-
 12162 000055A3 3D3D3D3D3D3D3D3D3D-
 12162 000055AC 3D3D3D3D3D3D3D3D3D-
 12162 000055B5 3D3D3D3D3D3D3D3D3D-
 12162 000055BE 3D3D3D3D3D3D3D3D   
 12163 000055C6 202020502020205320-     	db	"   P   S  BH  BS  BC  FS  EH  ES  EC   START SECT    SECTORS    FILE SYSTEM     "
 12163 000055CF 204248202042532020-
 12163 000055D8 424320204653202045-
 12163 000055E1 482020455320204543-
 12163 000055EA 202020535441525420-
 12163 000055F3 534543542020202053-
 12163 000055FC 4543544F5253202020-
 12163 00005605 2046494C4520535953-
 12163 0000560E 54454D2020202020   
 12164 00005616 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"
 12164 0000561F 2D2D2D2D2D2D2D2D2D-
 12164 00005628 2D2D2D2D2D2D2D2D2D-
 12164 00005631 2D2D2D2D2D2D2D2D2D-
 12164 0000563A 2D2D2D2D2D2D2D2D2D-
 12164 00005643 2D2D2D2D2D2D2D2D2D-
 12164 0000564C 2D2D2D2D2D2D2D2D2D-
 12164 00005655 2D2D2D2D2D2D2D2D2D-
 12164 0000565E 2D2D2D2D2D2D2D2D   
 12165 00005666 00                      	db	0
 12166                                  p_table_footer:
 12167 00005667 3D3D3D3D3D3D3D3D3D-     	db	"================================================================================"
 12167 00005670 3D3D3D3D3D3D3D3D3D-
 12167 00005679 3D3D3D3D3D3D3D3D3D-
 12167 00005682 3D3D3D3D3D3D3D3D3D-
 12167 0000568B 3D3D3D3D3D3D3D3D3D-
 12167 00005694 3D3D3D3D3D3D3D3D3D-
 12167 0000569D 3D3D3D3D3D3D3D3D3D-
 12167 000056A6 3D3D3D3D3D3D3D3D3D-
 12167 000056AF 3D3D3D3D3D3D3D3D   
 12168 000056B7 0D0A00                  	db	0Dh, 0Ah, 0
 12169                                  
 12170                                  mbr_editing_options:
 12171 000056BA 0D0A0D0A                	db	0Dh, 0Ah, 0Dh, 0Ah 
 12172 000056BE 4D4252205061727469-     	db	"MBR Partition Table Editing Options:"
 12172 000056C7 74696F6E205461626C-
 12172 000056D0 652045646974696E67-
 12172 000056D9 204F7074696F6E733A 
 12173 000056E2 0D0A0D0A                	db	0Dh, 0Ah, 0Dh, 0Ah
 12174 000056E6 20202020202020312E-     	db	"       1. Create Partition", 0Dh, 0Ah
 12174 000056EF 204372656174652050-
 12174 000056F8 6172746974696F6E0D-
 12174 00005701 0A                 
 12175 00005702 20202020202020322E-     	db	"       2. Set Active Partition", 0Dh, 0Ah
 12175 0000570B 205365742041637469-
 12175 00005714 766520506172746974-
 12175 0000571D 696F6E0D0A         
 12176 00005722 20202020202020332E-     	db	"       3. Delete Partition", 0Dh, 0Ah  
 12176 0000572B 2044656C6574652050-
 12176 00005734 6172746974696F6E0D-
 12176 0000573D 0A                 
 12177 0000573E 20202020202020342E-     	db	"       4. Write Current Partition Table", 0Dh, 0Ah, 0
 12177 00005747 205772697465204375-
 12177 00005750 7272656E7420506172-
 12177 00005759 746974696F6E205461-
 12177 00005762 626C650D0A00       
 12178                                  
 12179                                  enter_option_number_msg:
 12180 00005768 0D0A                    	db	0Dh, 0Ah
 12181 0000576A 456E74657220746865-     	db	"Enter the option number or press ESC to exit ...", 0Dh, 0Ah
 12181 00005773 206F7074696F6E206E-
 12181 0000577C 756D626572206F7220-
 12181 00005785 707265737320455343-
 12181 0000578E 20746F206578697420-
 12181 00005797 2E2E2E0D0A         
 12182                                  	;db	0Dh, 0Ah, 0
 12183 0000579C 00                      	db	0 
 12184                                  
 12185                                  msg_zero_partition_size:  ; 19/02/2019
 12186 0000579D 0D0A                    	db	0Dh, 0Ah
 12187 0000579F 506172746974696F6E-     	db	"Partition size input must not be ZERO !", 0Dh, 0Ah
 12187 000057A8 2073697A6520696E70-
 12187 000057B1 7574206D757374206E-
 12187 000057BA 6F74206265205A4552-
 12187 000057C3 4F20210D0A         
 12188 000057C8 285072657373204553-     	db	"(Press ESC to exit or press another key to retry..)", 0Dh, 0Ah
 12188 000057D1 4320746F2065786974-
 12188 000057DA 206F72207072657373-
 12188 000057E3 20616E6F7468657220-
 12188 000057EC 6B657920746F207265-
 12188 000057F5 7472792E2E290D0A   
 12189 000057FD 00                      	db	0 
 12190                                  
 12191                                  msg_empty_pt:
 12192 000057FE 0D0A                    	db	0Dh, 0Ah
 12193 00005800 456D70747920706172-     	db	"Empty partition table !", 0Dh, 0Ah
 12193 00005809 746974696F6E207461-
 12193 00005812 626C6520210D0A     
 12194 00005819 28412076616C696420-     	db	"(A valid partition must be created at first..)", 0Dh, 0Ah
 12194 00005822 706172746974696F6E-
 12194 0000582B 206D75737420626520-
 12194 00005834 637265617465642061-
 12194 0000583D 742066697273742E2E-
 12194 00005846 290D0A             
 12195 00005849 00                      	db	0
 12196                                  
 12197                                  msg_full_pt:
 12198 0000584A 0D0A                    	db	0Dh, 0Ah
 12199 0000584C 546865726520697320-     	db	"There is not a free partition table entry ", 0
 12199 00005855 6E6F74206120667265-
 12199 0000585E 652070617274697469-
 12199 00005867 6F6E207461626C6520-
 12199 00005870 656E7472792000     
 12200                                  msg_to_create_new_p: 
 12201 00005877 746F20637265617465-     	db	"to create a new partition !", 0Dh, 0Ah
 12201 00005880 2061206E6577207061-
 12201 00005889 72746974696F6E2021-
 12201 00005892 0D0A               
 12202 00005894 00                      	db	0
 12203                                  msg_no_free_space:
 12204 00005895 0D0A                    	db	0Dh, 0Ah
 12205 00005897 546865726520697320-     	db	"There is not (enough) free space ", 0
 12205 000058A0 6E6F742028656E6F75-
 12205 000058A9 676829206672656520-
 12205 000058B2 73706163652000     
 12206                                  
 12207                                  msg_enter_pn_to_del:
 12208 000058B9 0D0A                    	db	0Dh, 0Ah
 12209 000058BB 456E74657220706172-     	db	"Enter partition number to delete: "
 12209 000058C4 746974696F6E206E75-
 12209 000058CD 6D62657220746F2064-
 12209 000058D6 656C6574653A20     
 12210                                  chr_del_pnum1:
 12211 000058DD 00                      	db	0
 12212 000058DE 0D0A00                  	db	0Dh, 0Ah, 0
 12213                                  
 12214                                  msg_delete_partition_q:
 12215 000058E1 0D0A                    	db 	0Dh, 0Ah
 12216 000058E3 5741524E494E472120-     	db 	"WARNING! All of data in the selected partition will be lost", 0Dh, 0Ah
 12216 000058EC 416C6C206F66206461-
 12216 000058F5 746120696E20746865-
 12216 000058FE 2073656C6563746564-
 12216 00005907 20706172746974696F-
 12216 00005910 6E2077696C6C206265-
 12216 00005919 206C6F73740D0A     
 12217 00005920 202020202020202020-     	db	"         after you write changed partition table to disk !!", 0Dh, 0Ah
 12217 00005929 616674657220796F75-
 12217 00005932 207772697465206368-
 12217 0000593B 616E67656420706172-
 12217 00005944 746974696F6E207461-
 12217 0000594D 626C6520746F206469-
 12217 00005956 736B2021210D0A     
 12218 0000595D 0D0A                    	db	0Dh, 0Ah
 12219 0000595F 446F20796F75207761-     	db	"Do you want to delete PARTITION "
 12219 00005968 6E7420746F2064656C-
 12219 00005971 657465205041525449-
 12219 0000597A 54494F4E20         
 12220                                  chr_del_pnum2:
 12221 0000597F 30                      	db	'0'
 12222 00005980 203F2028592F4E2920-     	db	' ? (Y/N) ', 0
 12222 00005989 00                 
 12223                                  
 12224                                  _msg_YES:
 12225 0000598A 20                      	db	 20h
 12226                                  msg_YES:
 12227 0000598B 5945532000              	db	'YES ', 0
 12228                                  _msg_NO:
 12229 00005990 20                      	db	20h
 12230                                  msg_NO:
 12231 00005991 4E4F2000                	db	'NO ', 0
 12232                                  
 12233                                  ; 11/02/2019
 12234                                  msg_write_masterboot_sector:
 12235 00005995 0D0A                    	db	0Dh, 0Ah 
 12236 00005997 577269746520437572-     	db	"Write Current Partition Table:"
 12236 000059A0 72656E742050617274-
 12236 000059A9 6974696F6E20546162-
 12236 000059B2 6C653A             
 12237 000059B5 0D0A0D0A                	db	0Dh, 0Ah, 0Dh, 0Ah
 12238 000059B9 20312E205772697465-     	db	" 1. Write Partition Table only", 0Dh, 0Ah
 12238 000059C2 20506172746974696F-
 12238 000059CB 6E205461626C65206F-
 12238 000059D4 6E6C790D0A         
 12239 000059D9 20322E205772697465-     	db	" 2. Write Partition Table and Singlix Master Boot Code", 0Dh, 0Ah
 12239 000059E2 20506172746974696F-
 12239 000059EB 6E205461626C652061-
 12239 000059F4 6E642053696E676C69-
 12239 000059FD 78204D617374657220-
 12239 00005A06 426F6F7420436F6465-
 12239 00005A0F 0D0A               
 12240                                  enter_opt_num_cancel_msg:
 12241 00005A11 0D0A                    	db	0Dh, 0Ah
 12242 00005A13 456E74657220746865-     	db	"Enter the option number or press ESC to cancel ...", 0
 12242 00005A1C 206F7074696F6E206E-
 12242 00005A25 756D626572206F7220-
 12242 00005A2E 707265737320455343-
 12242 00005A37 20746F2063616E6365-
 12242 00005A40 6C202E2E2E00       
 12243                                  
 12244                                  msg_writing_ptable:
 12245 00005A46 0D0A0D0A                	db	0Dh, 0Ah, 0Dh, 0Ah
 12246 00005A4A 57726974696E672070-     	db	"Writing partition table on disk ... ", 0
 12246 00005A53 6172746974696F6E20-
 12246 00005A5C 7461626C65206F6E20-
 12246 00005A65 6469736B202E2E2E20-
 12246 00005A6E 00                 
 12247                                  _msg_OK:
 12248                                  	;db	7
 12249 00005A6F 0D0A                    	db	0Dh, 0Ah
 12250 00005A71 4F4B2021                	db	"OK !"
 12251 00005A75 0D0A00                  	db	0Dh, 0Ah, 0
 12252                                  
 12253                                  option_input:
 12254 00005A78 205B205D00              	db	' [ ]', 0
 12255                                  
 12256                                  msg_enter_pn_to_act:
 12257 00005A7D 0D0A                    	db	0Dh, 0Ah
 12258 00005A7F 456E74657220706172-     	db	"Enter partition number to set as active: ", 0
 12258 00005A88 746974696F6E206E75-
 12258 00005A91 6D62657220746F2073-
 12258 00005A9A 657420617320616374-
 12258 00005AA3 6976653A2000       
 12259                                  
 12260                                  ; 04/05/2024
 12261                                  ;trdos386_disk_chs_header:
 12262                                  ;	db	0Dh, 0Ah
 12263                                  ;	db	"                     TRDOS 386 (SINGLIX) HARD DISK IMAGE                        "
 12264                                  ;	db 	0
 12265                                  
 12266                                  ;disk_chs_header:
 12267                                  ;	db	0Dh, 0Ah
 12268                                  ;	db	"                                HARD DISK IMAGE                                 "
 12269                                  ;	db 	0
 12270                                  
 12271                                  msg_partition_size_limit:
 12272 00005AA9 0D0A                    	db	0Dh, 0Ah
 12273 00005AAB 506172746974696F6E-     	db	"Partition size overs available free space !"
 12273 00005AB4 2073697A65206F7665-
 12273 00005ABD 727320617661696C61-
 12273 00005AC6 626C65206672656520-
 12273 00005ACF 73706163652021     
 12274 00005AD6 0D0A                    	db	0Dh, 0Ah
 12275 00005AD8 4D61782E2061766169-     	db 	"Max. available free space is ", 0
 12275 00005AE1 6C61626C6520667265-
 12275 00005AEA 652073706163652069-
 12275 00005AF3 732000             
 12276                                  
 12277                                  msg_partition_size_limit_r:
 12278 00005AF6 0D0A0D0A                	db	0Dh, 0Ah, 0Dh, 0Ah
 12279 00005AFA 28507265737320454E-     	db	"(Press ENTER to use all of available space or press ESC key to retry..) "
 12279 00005B03 54455220746F207573-
 12279 00005B0C 6520616C6C206F6620-
 12279 00005B15 617661696C61626C65-
 12279 00005B1E 207370616365206F72-
 12279 00005B27 207072657373204553-
 12279 00005B30 43206B657920746F20-
 12279 00005B39 72657472792E2E2920 
 12280 00005B42 000A00                  	db	0D, 0Ah, 0
 12281                                  
 12282                                  msg_cylinders:
 12283 00005B45 2063796C696E646572-     	db	" cylinders", 0
 12283 00005B4E 7300               
 12284                                  msg_sectors:
 12285 00005B50 20736563746F727300      	db	" sectors", 0
 12286                                  
 12287                                  ; 02/03/2019
 12288                                  msg_megabytes:
 12289 00005B59 206D65676162797465      	db	" megabyte"
 12290                                  msg_megabytes_s:
 12291 00005B62 0000                    	db	0, 0
 12292                                  
 12293                                  msg_inv_pte:
 12294 00005B64 0D0A                    	db	0Dh, 0Ah
 12295 00005B66 496E76616C69642070-     	db	"Invalid partition table entry ! (P"
 12295 00005B6F 6172746974696F6E20-
 12295 00005B78 7461626C6520656E74-
 12295 00005B81 72792021202850     
 12296 00005B88 3F290D0A                inv_pte_num: db	"?)", 0Dh, 0Ah
 12297 00005B8C 28507265737320454E-     	db	"(Press ENTER to DELETE or press ESC to EXIT..)"
 12297 00005B95 54455220746F204445-
 12297 00005B9E 4C455445206F722070-
 12297 00005BA7 726573732045534320-
 12297 00005BB0 746F20455849542E2E-
 12297 00005BB9 29                 
 12298 00005BBA 0D0A00                  	db	0Dh, 0Ah, 0
 12299                                  
 12300                                  msg_ext_partition_exists:
 12301 00005BBD 457874656E64656420-     	db	"Extended partition already exists !"
 12301 00005BC6 706172746974696F6E-
 12301 00005BCF 20616C726561647920-
 12301 00005BD8 6578697374732021   
 12302 00005BE0 0D0A00                  	db	0Dh, 0Ah, 0
 12303                                  
 12304                                  msg_defective_pt:
 12305 00005BE3 0D0A                    	db	0Dh, 0Ah
 12306 00005BE5 446566656374697665-     	db	"Defective partition table !", 0
 12306 00005BEE 20706172746974696F-
 12306 00005BF7 6E207461626C652021-
 12306 00005C00 00                 
 12307                                  
 12308                                  ; 27/02/2019
 12309                                  msg_ext_part_del_error:
 12310 00005C01 0D0A                    	db	0Dh, 0Ah
 12311 00005C03 457874656E64656420-     	db	"Extended partition must be deleted after logical drive(s) !"
 12311 00005C0C 706172746974696F6E-
 12311 00005C15 206D75737420626520-
 12311 00005C1E 64656C657465642061-
 12311 00005C27 66746572206C6F6769-
 12311 00005C30 63616C206472697665-
 12311 00005C39 2873292021         
 12312 00005C3E 0D0A00                  	db	0Dh, 0Ah, 0
 12313                                  
 12314                                  msg_cancel_continue:
 12315 00005C41 285072657373204553-     	db	"(Press ESC to cancel or press another key to continue..)"
 12315 00005C4A 4320746F2063616E63-
 12315 00005C53 656C206F7220707265-
 12315 00005C5C 737320616E6F746865-
 12315 00005C65 72206B657920746F20-
 12315 00005C6E 636F6E74696E75652E-
 12315 00005C77 2E29               
 12316 00005C79 0D0A00                  	db	0Dh, 0Ah, 0
 12317                                  
 12318                                  msg_delete_ldd:
 12319 00005C7C 0D0A                    	db	0Dh, 0Ah
 12320 00005C7E 0D0A                    	db	0Dh, 0Ah
 12321 00005C80 44656C657465204C6F-     	db	"Delete Logical (DOS) Drive:"
 12321 00005C89 676963616C2028444F-
 12321 00005C92 53292044726976653A 
 12322 00005C9B 0D0A                    	db	0Dh, 0Ah
 12323 00005C9D 50726573732044454C-     	db	"Press DELETE key to delete logical disk partition "
 12323 00005CA6 455445206B65792074-
 12323 00005CAF 6F2064656C65746520-
 12323 00005CB8 6C6F676963616C2064-
 12323 00005CC1 69736B207061727469-
 12323 00005CCA 74696F6E20         
 12324 00005CCF 3F2E                    lddp_num: db	"?."
 12325 00005CD1 0D0A00                  	db	0Dh, 0Ah, 0
 12326                                  
 12327                                  msg_delete_ext_part:
 12328 00005CD4 0D0A                    	db	0Dh, 0Ah
 12329 00005CD6 0D0A                    	db	0Dh, 0Ah
 12330 00005CD8 44656C657465204578-     	db	"Delete Extended (DOS) Partition:"
 12330 00005CE1 74656E646564202844-
 12330 00005CEA 4F5329205061727469-
 12330 00005CF3 74696F6E3A         
 12331 00005CF8 0D0A                    	db	0Dh, 0Ah
 12332 00005CFA 507265737320454E54-     	db	"Press ENTER to delete or press ESC to cancel.."
 12332 00005D03 455220746F2064656C-
 12332 00005D0C 657465206F72207072-
 12332 00005D15 657373204553432074-
 12332 00005D1E 6F2063616E63656C2E-
 12332 00005D27 2E                 
 12333 00005D28 0D0A00                  	db	0Dh, 0Ah, 0
 12334                                  
 12335                                  str_display_ebr_pt:
 12336 00005D2B 285072657373205350-     	db	"(Press SPACE to edit EXTENDED Partition Table)", 0Dh, 0Ah, 0
 12336 00005D34 41434520746F206564-
 12336 00005D3D 697420455854454E44-
 12336 00005D46 454420506172746974-
 12336 00005D4F 696F6E205461626C65-
 12336 00005D58 290D0A00           
 12337                                  
 12338                                  ebr_editing_options:
 12339 00005D5C 0D0A0D0A                	db	0Dh, 0Ah, 0Dh, 0Ah 
 12340 00005D60 457874656E64656420-     	db	"Extended Partition Table Editing Options:" 
 12340 00005D69 506172746974696F6E-
 12340 00005D72 205461626C65204564-
 12340 00005D7B 6974696E67204F7074-
 12340 00005D84 696F6E733A         
 12341 00005D89 0D0A0D0A                	db	0Dh, 0Ah, 0Dh, 0Ah
 12342 00005D8D 20202020202020312E-     	db	"       1. Create Logical DOS Drive", 0Dh, 0Ah
 12342 00005D96 20437265617465204C-
 12342 00005D9F 6F676963616C20444F-
 12342 00005DA8 532044726976650D0A 
 12343 00005DB1 20202020202020322E-     	db	"       2. Delete Logical (DOS) Drive(s)",0Dh, 0Ah, 0
 12343 00005DBA 2044656C657465204C-
 12343 00005DC3 6F676963616C202844-
 12343 00005DCC 4F5329204472697665-
 12343 00005DD5 2873290D0A00       
 12344                                  
 12345                                  msg_delete_ldd_q:
 12346 00005DDB 0D0A                    	db 	0Dh, 0Ah
 12347 00005DDD 5741524E494E47210D-     	db 	"WARNING!", 0Dh, 0Ah 
 12347 00005DE6 0A                 
 12348 00005DE7 416C6C206F66206461-     	db	"All of data in logical (DOS) drive(s) will be lost !!", 0Dh, 0Ah
 12348 00005DF0 746120696E206C6F67-
 12348 00005DF9 6963616C2028444F53-
 12348 00005E02 292064726976652873-
 12348 00005E0B 292077696C6C206265-
 12348 00005E14 206C6F73742021210D-
 12348 00005E1D 0A                 
 12349 00005E1E 0D0A                    	db	0Dh, 0Ah
 12350 00005E20 446F20796F75207761-     	db	"Do you want to continue ? (Y/N) ", 0
 12350 00005E29 6E7420746F20636F6E-
 12350 00005E32 74696E7565203F2028-
 12350 00005E3B 592F4E292000       
 12351                                  
 12352                                  msg_create_ldd_max_error:
 12353 00005E41 0D0A                    	db	0Dh, 0Ah
 12354 00005E43 50726F6772616D206C-     	db	"Program limit for logical dos drive count is 4 !"
 12354 00005E4C 696D697420666F7220-
 12354 00005E55 6C6F676963616C2064-
 12354 00005E5E 6F7320647269766520-
 12354 00005E67 636F756E7420697320-
 12354 00005E70 342021             
 12355 00005E73 0D0A00                  	db 	0Dh, 0Ah, 0
 12356                                  
 12357                                  msg_c_ldd_unused_warning:
 12358 00005E76 0D0A                    	db	0Dh, 0Ah
 12359 00005E78 546865726520697320-     	db	"There is unused extended partition space after logical dos drive "
 12359 00005E81 756E75736564206578-
 12359 00005E8A 74656E646564207061-
 12359 00005E93 72746974696F6E2073-
 12359 00005E9C 706163652061667465-
 12359 00005EA5 72206C6F676963616C-
 12359 00005EAE 20646F732064726976-
 12359 00005EB7 6520               
 12360                                  char_lddn:
 12361 00005EB9 342021                  	db	"4 !"
 12362 00005EBC 0D0A                    	db 	0Dh, 0Ah
 12363 00005EBE 285072657373204553-     	db	"(Press ESC to add unused space or press ENTER to continue.)"	 
 12363 00005EC7 4320746F2061646420-
 12363 00005ED0 756E75736564207370-
 12363 00005ED9 616365206F72207072-
 12363 00005EE2 65737320454E544552-
 12363 00005EEB 20746F20636F6E7469-
 12363 00005EF4 6E75652E29         
 12364 00005EF9 0D0A00                  	db 	0Dh, 0Ah, 0
 12365                                  
 12366                                  msg_create_ldd_s:
 12367 00005EFC 53656C65637420616E-     	db	"Select an option to set logical dos drive size: "
 12367 00005F05 206F7074696F6E2074-
 12367 00005F0E 6F20736574206C6F67-
 12367 00005F17 6963616C20646F7320-
 12367 00005F20 64726976652073697A-
 12367 00005F29 653A20             
 12368 00005F2C 0D0A                    	db	0Dh, 0Ah
 12369 00005F2E 0D0A                    	db	0Dh, 0Ah
 12370 00005F30 202043292043796C69-     	db	"  C) Cylinder count", 0Dh, 0Ah
 12370 00005F39 6E64657220636F756E-
 12370 00005F42 740D0A             
 12371 00005F45 2020252920566F6C75-     	db	"  %) Volume percentage (##%)", 0Dh, 0Ah
 12371 00005F4E 6D652070657263656E-
 12371 00005F57 746167652028232325-
 12371 00005F60 290D0A             
 12372 00005F63 20204D29204D656761-     	db	"  M) Mega bytes (MB, 2*1024*M sectors)", 0Dh, 0Ah
 12372 00005F6C 20627974657320284D-
 12372 00005F75 422C20322A31303234-
 12372 00005F7E 2A4D20736563746F72-
 12372 00005F87 73290D0A           
 12373 00005F8B 202047292047696761-     	db	"  G) Giga bytes (GB, 2*1024*1024*G sectors)", 0Dh, 0Ah
 12373 00005F94 206279746573202847-
 12373 00005F9D 422C20322A31303234-
 12373 00005FA6 2A313032342A472073-
 12373 00005FAF 6563746F7273290D0A 
 12374 00005FB8 0D0A                    	db	0Dh, 0Ah	
 12375 00005FBA 507265737320535041-     	db	"Press SPACE to use entire space or press ENTER to set Megabytes .. ", 0
 12375 00005FC3 434520746F20757365-
 12375 00005FCC 20656E746972652073-
 12375 00005FD5 70616365206F722070-
 12375 00005FDE 7265737320454E5445-
 12375 00005FE7 5220746F2073657420-
 12375 00005FF0 4D6567616279746573-
 12375 00005FF9 202E2E2000         
 12376                                  
 12377                                  msg_c_part_error:
 12378 00005FFE 0D0A                    	db 	0Dh, 0Ah
 12379                                  	;db	"No free space for a new primary partition", 0Dh, 0Ah, 0
 12380                                  	; 21/03/2021
 12381 00006000 4E6F20667265652073-     	db	"No free space for a new primary partition !", 0Dh, 0Ah, 0
 12381 00006009 7061636520666F7220-
 12381 00006012 61206E657720707269-
 12381 0000601B 6D6172792070617274-
 12381 00006024 6974696F6E20210D0A-
 12381 0000602D 00                 
 12382                                  
 12383                                  ; 21/03/2021
 12384                                  ;msg_c_ldd_error: 
 12385                                  ;	db	"and logical dos drives over program limit (4) !", 0Dh, 0Ah, 0
 12386                                  
 12387                                  msg_c_ldd_q:
 12388 0000602E 0D0A                    	db	0Dh, 0Ah
 12389 00006030 446F20796F75207761-     	db	"Do you want to create logical dos drive in extended dos partition "
 12389 00006039 6E7420746F20637265-
 12389 00006042 617465206C6F676963-
 12389 0000604B 616C20646F73206472-
 12389 00006054 69766520696E206578-
 12389 0000605D 74656E64656420646F-
 12389 00006066 732070617274697469-
 12389 0000606F 6F6E20             
 12390 00006072 3F2028592F4E2900        	db	'? (Y/N)', 0
 12391                                  
 12392                                  msg_c_ldd_nofspc_error:
 12393 0000607A 0D0A                    	db 	0Dh, 0Ah
 12394 0000607C 4E6F20667265652073-     	db	"No free space for a new logical dos drive !", 0Dh, 0Ah, 0
 12394 00006085 7061636520666F7220-
 12394 0000608E 61206E6577206C6F67-
 12394 00006097 6963616C20646F7320-
 12394 000060A0 647269766520210D0A-
 12394 000060A9 00                 
 12395                                  
 12396                                  	; 12/10/2020
 12397                                  msg_drv_not_ready:
 12398 000060AA 0D0A                    	db	0Dh, 0Ah
 12399 000060AC 4469736B2064726976-     	db	"Disk drive not ready or read error ! "
 12399 000060B5 65206E6F7420726561-
 12399 000060BE 6479206F7220726561-
 12399 000060C7 64206572726F722021-
 12399 000060D0 20                 
 12400 000060D1 0D0A00                  	db	0Dh, 0Ah, 0
 12401                                  
 12402                                  msg_not_any_disks:
 12403 000060D4 0D0A                    	db	0Dh, 0Ah
 12404 000060D6 546865726520697320-     	db	"There is not a hard disk (ready) ! "
 12404 000060DF 6E6F74206120686172-
 12404 000060E8 64206469736B202872-
 12404 000060F1 6561647929202120   
 12405 000060F9 0D0A00                  	db	0Dh, 0Ah, 0
 12406                                  
 12407                                  align 4
 12408                                  
 12409                                  msg_sectors_crlf:
 12410 000060FC 20736563746F72          	db	" sector"
 12411                                  msg_sectors_crlf_s:
 12412 00006103 73                      	db	"s"
 12413 00006104 0D0A00                  	db	0Dh, 0Ah, 0
 12414                                  
 12415                                  vname_length:
 12416 00006107 00                      	db	0 ; 05/01/2018
 12417                                  
 12418                                  bs_oem_name:
 12419 00006108 5452444F53322E3000      	db	'TRDOS2.0', 0
 12420                                  
 12421 00006111 90                      align 2
 12422                                  
 12423                                  no_name:
 12424 00006112 4E4F204E414D452020-     	db 	'NO NAME    ', 0
 12424 0000611B 202000             
 12425                                  
 12426                                  align 2
 12427                                  
 12428                                  FDFORMAT_SECBUFFER:
 12429                                  HDFORMAT_SECBUFFER:
 12430 0000611E F6<rep 200h>            	times	512 db 0F6h
 12431                                  HDFORMAT_FSINFO_BUFF:
 12432 0000631E 52526141                	dd	41615252h  ; FSI_LeadSig
 12433 00006322 00<rep 1E0h>            	times	480 db 0   ; FSI_Reserved1
 12434 00006502 72724161                	dd	61417272h  ; FSI_StrucSig
 12435 00006506 FFFFFFFF                	dd	0FFFFFFFFh ; FSI_Free_Count
 12436 0000650A 02000000                	dd	000000002h ; FSI_Nxt_Free
 12437 0000650E 00<rep Ch>              	times	12 db 0	   ; FSI_Reserved2
 12438 0000651A 000055AA                	dd	0AA550000h ; FSI_TrailSig
 12439                                  
 12440                                  ; 29/10/2020
 12441                                  msg_100:
 12442 0000651E 31303000                	db	'100', 0
 12443                                  
 12444                                  SizeOfFile equ $-100
 12445                                  
 12446                                  ; 03/02/2019
 12447                                  
 12448                                  ;=============================================================================
 12449                                  ;        	uninitialized data
 12450                                  ;=============================================================================
 12451                                  
 12452                                  bss_start:
 12453                                  
 12454                                  ABSOLUTE bss_start
 12455                                  
 12456                                  ; 12/10/2020
 12457 00006522 ??                      DrvNum:	resb 1
 12458 00006523 ??                      hdc:	resb 1
 12459                                  ;hs:	resw 1 ; (bios/dos virtual) head*sectors ; 16/10/2020
 12460 00006524 ??                      rw:	resb 1 
 12461 00006525 ??                      rcnt:	resb 1 ; 18/10/2020
 12462                                  total_sectors:
 12463 00006526 ????????                disksize: resd 1
 12464 0000652A ????????                chs_limit: resd 1
 12465                                  
 12466                                  ; 16/10/2020
 12467                                  ;lba_cyls: resd 1  ; cylinder count calculated from LBA sectors
 12468 0000652E ????                    lba_chs_remain: resw 1	 ; remain sectors after the last cylinder
 12469                                  
 12470                                  alignb 2
 12471 00006530 ????                    old_sp:	resw 1
 12472                                  
 12473                                  HDFORMAT_FATBUFFER:
 12474                                  HDFORMAT_EMPTY_BUFF:
 12475 00006532 <res 200h>              	resb 512
 12476                                  
 12477 00006732 ????????                data_start: resd 1
 12478 00006736 ????????                data_sectors: resd 1
 12479 0000673A ????????                cluster_count: resd 1
 12480 0000673E ????                    root_dir_secs: resw 1
 12481                                  format_percent: ;resw 1
 12482 00006740 ????????                		resd 1 ; 16/03/2021
 12483 00006744 ??                      prev_percent:	resb 1
 12484 00006745 ??                      rsvdbyte:	resb 1
 12485                                  
 12486 00006746 ????                    alignb 4
 12487                                  
 12488                                  ; 05/01/2018
 12489 00006748 <res 40h>               fs_volume_name: resb 64
 12490 00006788 ????????                fs_volume_serial: resd 1
 12491 0000678C ????                    DAT_FFBit:	resw 1
 12492 0000678E ????                    DAT_FFSector:	resw 1
 12493                                  		;resw 1
 12494 00006790 ????                    DAT_LFBit:	resw 1
 12495 00006792 ????                    DAT_LFSector:	resw 1
 12496                                  		;resw 1
 12497                                  
 12498                                  ;alignb 4
 12499                                  
 12500                                  FS_MAT_Buffer: ; TRFS1 Master Allocation Table (05/01/2018)
 12501 00006794 ??????                  MAT_Sign:		resb    3	; Offset 0  ; 'MAT'
 12502 00006797 ??                      MAT_Version:		resb 	1	; 	 3  ; 0	
 12503 00006798 ????????                MAT_VolumeSize:		resd	1	;	 4  ; FS1 Volume Size
 12504 0000679C ????????                MAT_BeginSector:	resd	1	;	 8  ; FS1 Start Sector
 12505 000067A0 ????????                DAT_Address:		resd	1	;	12  ; Offset (=2)
 12506 000067A4 ????????                DAT_SectorCount:	resd	1	;	16  
 12507 000067A8 ????????                MAT_FreeSectors:	resd 	1	; 	20
 12508 000067AC ????????                MAT_FirstFreeSector:	resd	1	;	24
 12509                                  ;MAT_OS_Reserved:
 12510                                  ;	 		resb	9
 12511                                  ;MAT_Unused:
 12512                                  ;			resb	112
 12513                                  FS_DAT_Buffer: ; TRFS1 Disk Allocation Table (05/01/2018)
 12514                                  FS_RDT_Buffer: ; TRFS1 Root Directory Description Table (05/01/2018)
 12515 000067B0 <res 200h>              			resb	512
 12516                                  ;alignb 4
 12517                                  
 12518                                  ; (TR-DOS 386 compatible) Hard Disk (image) parameters
 12519                                  
 12520                                  ;total_sectors: resd 1
 12521 000069B0 ????????                pType:	       resb 4
 12522 000069B4 ????????                file_size:     resd 1
 12523 000069B8 ????????                pp_StartSector: resd 1
 12524 000069BC ????????                pp_Sectors:	resd 1
 12525 000069C0 ??                      wholedisk:	resb 1
 12526 000069C1 ??                      pp_type: resb 1 ; Primary partition type (for this program)
 12527 000069C2 ??                      pp_type_user: resb 1
 12528 000069C3 ??                      chs_focus: resb 1
 12529 000069C4 ????????                pSize_temp: resd 1
 12530 000069C8 ????????                pSize_multiplier: resd 1
 12531 000069CC ??                      pSize_maxdigits: resb 1
 12532 000069CD ??                      pSize_digitpos: resb 1
 12533                                  msg_psize_unit:
 12534 000069CE ????                    pSize_unit:	resw 1
 12535 000069D0 ??                      		resb 1
 12536                                  ; 06/11/2020
 12537                                  ;reserved_bytes: resb 3 ; for 11 bytes of numbers
 12538                                  msg_partition_sectors:
 12539                                  		;resb 8
 12540 000069D1 <res Bh>                		resb 11 ; 06/11/2020
 12541 000069DC ??                      		resb 1
 12542 000069DD ??                      format_q:	resb 1 ; 03/02/2018
 12543                                  
 12544                                  ;alignb 2
 12545 000069DE ??                      pType_pos:	resb 1
 12546 000069DF ??                      pType_num:	resb 1
 12547 000069E0 ??                      		resb 1
 12548                                  ;cylinder_boundary:
 12549 000069E1 ??                      		resb 1
 12550                                  ; 05/11/2020
 12551                                  
 12552                                  alignb 2
 12553                                  
 12554 000069E2 ??                      GetChar:	resb 1 ; 11/02/2019
 12555 000069E3 ??                      		resb 1 ; 06/11/2020
 12556                                  
 12557                                  hs: ; 17/10/2020 ; (bios/dos virtual) head*sectors
 12558 000069E4 ????                    min_sectors:	resw 1 ; 08/02/2019
 12559 000069E6 ????                    		resw 1 ; 06/11/2020
 12560 000069E8 ????                    pp_StartCylinder: resw 1
 12561 000069EA ????                    		resw 1 ; 06/11/2020
 12562 000069EC ????                    pp_EndCylinder:	resw 1
 12563 000069EE ????                    		resw 1 ; 06/11/2020
 12564                                  
 12565 000069F0 ????????                ppn_Sectors:	resd 1 ; 09/02/2019
 12566                                  
 12567 000069F4 ????                    input_col:	resw 1
 12568 000069F6 ??                      No:		resb 1
 12569 000069F7 ??                      Yes:		resb 1
 12570                                  
 12571                                  ; 26/02/2019
 12572 000069F8 ??                      ldrives:	resb 1
 12573                                  
 12574                                  ;sort_1:	resb 1
 12575 000069F9 ??                      		resb 1 ; 23/10/2020
 12576 000069FA ????????                sort:		resb 4
 12577                                  
 12578                                  ;max_sector:	resb 8
 12579                                  ebr_buffer:		; 26/02/2019
 12580 000069FE <res 200h>              boot_record:	resb 512
 12581                                  
 12582 00006BFE ??                      valid_input:	resb 1
 12583 00006BFF ??                      		resb 1
 12584                                  
 12585                                  ; 26/02/2019
 12586 00006C00 ????????                ep_StartSector:	resd 1
 12587 00006C04 ????????                ep_EndSector:	resd 1
 12588 00006C08 ????????                ep_Size:	resd 1
 12589                                  
 12590                                  ; 10/02/2019
 12591 00006C0C ????????                valid_ppnums:	resb 4
 12592                                  
 12593 00006C10 ????                    _i_:	resw 1
 12594                                  
 12595                                  freespace_count: ; resw 1 
 12596 00006C12 ??                      		resb 1 ; 12/03/2021
 12597                                  
 12598 00006C13 ??                      last_found_partition: resb 1
 12599 00006C14 ??                      p_type: resb 1
 12600                                  
 12601                                  ; 30/10/2020
 12602                                  ;p_sorted:
 12603                                  ;	resb 1
 12604                                  ;ep_sorted:
 12605                                  ;	resb 1
 12606                                  
 12607 00006C15 ??                      _e_:	resb 1
 12608                                  
 12609                                  act_part_num:
 12610                                  cre_part_num:
 12611 00006C16 ??                      del_part_num: resb 1 ; 10/02/2019
 12612                                  
 12613 00006C17 ??                      alignb 2
 12614                                  
 12615 00006C18 <res 50h>               pte_row: resb 80
 12616                                  
 12617 00006C68 ??                      _zero_:	resb 1
 12618                                  
 12619                                  ;alignb 2
 12620                                  
 12621 00006C69 ??                      	resb 1
 12622                                  
 12623                                  bss_clear_end: ; 15/02/2019
 12624                                  
 12625                                  ; 05/11/2020
 12626                                  
 12627                                  ; PARTITION DATA STRUCTURE
 12628                                  ; 4 partitions
 12629                                  ; 22 byte partition data structure per partition
 12630                                  ; 88 bytes (4*22)
 12631                                  
 12632 00006C6A ??                      part_table_boot_ind:	 resb 1
 12633 00006C6B ??                      part_table_start_head:	 resb 1
 12634 00006C6C ??                      part_table_start_sector: resb 1
 12635                                  ;part_table_start_cyl:	 resw 1
 12636 00006C6D ????????                part_table_start_cyl:	 resd 1
 12637 00006C71 ??                      part_table_sys_id:	 resb 1
 12638 00006C72 ??                      part_table_end_head:	 resb 1
 12639 00006C73 ??                      part_table_end_sector:	 resb 1
 12640                                  ;part_table_end_cyl:	 resw 1
 12641 00006C74 ????????                part_table_end_cyl:	 resd 1
 12642                                  ;part_table_rel_sec_lw:	 resw 1
 12643                                  ;part_table_rel_sec_hw:	 resw 1
 12644 00006C78 ????????                part_table_rel_sec:	 resd 1
 12645                                  ;part_table_num_sec_lw:	 resw 1
 12646                                  ;part_table_num_sec_hw:	 resw 1
 12647 00006C7C ????????                part_table_num_sec:	 resd 1
 12648                                  
 12649 00006C80 <res 42h>               			resb 66 ; 3*22 bytes
 12650                                  
 12651 00006CC2 ??                      pcount:		resb 1
 12652 00006CC3 ??                      ppcount:	resb 1
 12653 00006CC4 ??                      apcount:	resb 1
 12654 00006CC5 ??                      epnumber:	resb 1
 12655                                  
 12656                                  ; 05/11/2020
 12657                                  
 12658                                  ; LOGICAL PARTITION DATA STRUCTURE
 12659                                  ; (for logical partitions in extended partition)
 12660                                  
 12661                                  ; 1 extended partition
 12662                                  ; 4 logical drives (22 bytes)
 12663                                  ; 88 bytes (4*22)
 12664                                  
 12665 00006CC6 ??                      ext_table_boot_ind:	resb 1
 12666 00006CC7 ??                      ext_table_start_head:	resb 1
 12667 00006CC8 ??                      ext_table_start_sector: resb 1
 12668                                  ;ext_table_start_cyl:	resw 1
 12669 00006CC9 ????????                ext_table_start_cyl:	resd 1
 12670 00006CCD ??                      ext_table_sys_id:	resb 1
 12671 00006CCE ??                      ext_table_end_head:	resb 1
 12672 00006CCF ??                      ext_table_end_sector:	resb 1
 12673                                  ;ext_table_end_cyl:	resw 1
 12674 00006CD0 ????????                ext_table_end_cyl:	resd 1
 12675                                  ;ext_table_rel_sec_lw:	resw 1
 12676                                  ;ext_table_rel_sec_hw:	resw 1
 12677 00006CD4 ????????                ext_table_rel_sec:	resd 1
 12678                                  ;ext_table_num_sec_lw:	resw 1
 12679                                  ;ext_table_num_sec_hw:	resw 1
 12680 00006CD8 ????????                ext_table_num_sec:	resd 1
 12681                                  
 12682 00006CDC <res 42h>               			resb 66 ; 3*22 bytes
 12683                                  ; 05/11/2020
 12684                                  
 12685                                  fspc:		; 5*11 words (for free space calculations)
 12686                                  
 12687                                  ; Space 1 - unused cylinders before partition 0
 12688                                  ; Space 2 - unused cylinders between partition 0 & 1
 12689                                  ; Space 3 - unused cylinders between partition 1 & 2
 12690                                  ; Space 4 - unused cylinders between partition 2 & 3
 12691                                  ; Space 5 - unused cylinders after partition 3
 12692                                  
 12693 00006D1E ????????                free_space.space:   	   resd 1
 12694 00006D22 ????????                free_space.start:   	   resd 1
 12695 00006D26 ????????                free_space.end:	   	   resd 1
 12696 00006D2A ????????                free_space.sectors_unused: resd 1
 12697 00006D2E ????????                free_space.startsector:   resd 1 ; 13/02/2019
 12698 00006D32 ????                    free_space.percent_unused: resw 1
 12699                                  
 12700 00006D34 <res 58h>               		resw   4*11 ; 4*22 bytes ; 05/11/2020
 12701                                  
 12702                                  ; 05/11/2020
 12703                                  ;c_cylinder:	resd 1
 12704                                  ; 18/02/2019
 12705                                  ;c_cylinder:	resw 1
 12706 00006D8C ????                    c_fspc_offset:	resw 1
 12707 00006D8E ??                      cylinder_boundary: resb 1
 12708                                  ;c_gap:		resb 1
 12709 00006D8F ??                      		resb 1
 12710                                  
 12711                                  ; 27/02/2019
 12712 00006D90 <res 10h>               ldd_start:	resd 4
 12713                                  ; 03/03/2019
 12714 00006DA0 <res 10h>               ldd_size:	resd 4
 12715                                  ; 30/10/2020
 12716 00006DB0 ????????                ep_free_sectors: resd 1
 12717                                  
 12718                                  ; 05/11/2020
 12719 00006DB4 ????????                lcylinders:	resd 1
 12720                                  ; 25/02/2019
 12721 00006DB8 ????                    pte_address:	resw 1
 12722                                  ; 02/03/2019
 12723                                  ;lcylinders:	resw 1
 12724                                  ; 01/11/2020
 12725 00006DBA ????                    endcyl:		resw 1
 12726 00006DBC ????                    		resw 1 ; 13/03/2021
 12727                                  
 12728                                  ;bss_clear_end: ; 18/02/2019
 12729                                  
 12730                                  ; 11/10/2020
 12731                                  ;gdp_buffer:	resb 30 ; buffer for int 13h, ah = 48h
 12732 00006DBE <res 1Ah>               gdp_buffer:	resb 26 ; buffer for int 13h, ah = 48h
 12733                                  
 12734                                  bss_end:
