     1                                  ; ****************************************************************************
     2                                  ; HDIMAGE.ASM (HDIMAGE.COM) - TRDOS 386 Hard Disk Image Formatting Utility
     3                                  ; 						      (for MSDOS/WINDOWS)
     4                                  ; ****************************************************************************
     5                                  ; Last Update: 03/05/2024 (Previous: 26/10/2020)
     6                                  ; ----------------------------------------------------------------------------
     7                                  ; Beginning: 03/12/2017
     8                                  ; ----------------------------------------------------------------------------
     9                                  ; Assembler: NASM version 2.15
    10                                  ; ----------------------------------------------------------------------------
    11                                  ; Turkish Rational DOS
    12                                  ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
    13                                  ;
    14                                  ; Derived from 'fdisk2.s' (FDISK2.COM) source code by Erdogan Tan
    15                                  ; (03/02/2019)
    16                                  ;
    17                                  ; Derived from 'fdimage.s' (FDIMAGE.COM) source code by Erdogan Tan
    18                                  ; (02/12/2017)
    19                                  ;
    20                                  ; Derived from 'fdformat.s' (FDFORMAT.COM) source code by Erdogan Tan
    21                                  ; (29/11/2017)
    22                                  ;
    23                                  ; Derived from 'FSFDISK.ASM' (FSFDISK.COM) source code by Erdogan Tan
    24                                  ; (27/04/2009)
    25                                  ;
    26                                  ; Derived from 'UNIXCOPY.ASM' (UNIXCOPY.COM) source code by Erdogan Tan
    27                                  ; (04/12/2015)
    28                                  ; ****************************************************************************
    29                                  ; nasm hdimage.s -l hdimage.txt -o HDIMAGE.COM
    30                                  
    31                                  ; DTA (PSP+80h= Offset 128)
    32                                  DTA_Attrib equ 149 ; PDP+21
    33                                  DTA_Time equ 150 ; PSP+22
    34                                  DTA_Date equ 152 ; PSP 24
    35                                  DTA_FileSize equ 154 ; PSP + 26
    36                                  DTA_FileName equ 158 ; PSP + 30
    37                                  
    38                                  ; Masterboot / Partition Table at Beginning+1BEh
    39                                  ptBootable      equ 0
    40                                  ptBeginHead     equ 1
    41                                  ptBeginSector   equ 2
    42                                  ptBeginCylinder equ 3
    43                                  ptFileSystemID	equ 4
    44                                  ptEndHead       equ 5
    45                                  ptEndSector     equ 6
    46                                  ptEndCylinder   equ 7
    47                                  ptStartSector   equ 8
    48                                  ptSectors       equ 12
    49                                  
    50                                  ; BIOS Disk Parameters
    51                                  DPDiskNumber  equ 0h
    52                                  DPDType       equ 1h
    53                                  DPReturn      equ 2h
    54                                  DPHeads       equ 3h
    55                                  DPCylinders   equ 4h
    56                                  DPSecPerTrack equ 6h
    57                                  DPDisks       equ 7h
    58                                  DPTableOff    equ 8h
    59                                  DPTableSeg    equ 0Ah
    60                                  DPNumOfSecs   equ 0Ch
    61                                  
    62                                  ; BIOS INT 13h Extensions (LBA extensions)
    63                                  ; Just After DP Data (DPDiskNumber+)
    64                                  DAP_PacketSize equ 10h  ; If extensions present, this byte will be >=10h
    65                                  DAP_Reserved1 equ 11h   ; Reserved Byte 
    66                                  DAP_NumOfBlocks equ 12h ; Value of this byte must be 0 to 127
    67                                  DAP_Reserved2 equ 13h   ; Reserved Byte
    68                                  DAP_Destination equ 14h ; Address of Transfer Buffer as SEGMENT:OFFSET
    69                                  DAP_LBA_Address equ 18h ; LBA=(C1*H0+H1)*S0+S1-1
    70                                                          ; C1= Selected Cylinder Number
    71                                                          ; H0= Number Of Heads (Maximum Head Number + 1)
    72                                                          ; H1= Selected Head Number
    73                                                          ; S0= Maximum Sector Number
    74                                                          ; S1= Selected Sector Number
    75                                                          ; QUAD WORD
    76                                  ; DAP_Flat_Destination equ 20h ; 64 bit address, if value in 4h is FFFF:FFFFh
    77                                                               ; QUAD WORD (Also, value in 0h must be 18h) 
    78                                                               ; TR-DOS will not use 64 bit Flat Address
    79                                  
    80                                  ; INT 13h Function 48h "Get Enhanced Disk Drive Parameters"
    81                                  ; Just After DP Data (DPDiskNumber+)
    82                                  GetDParams_48h equ 20h ; Word. Data Lenght, must be 26 (1Ah) for short data.
    83                                  GDP_48h_InfoFlag equ 22h ; Word
    84                                  ; Bit 1 = 1 -> The geometry returned in bytes 4-15 is valid.
    85                                  GDP_48h_NumOfPCyls equ 24h ; Double Word. Number physical cylinders.
    86                                  GDP_48h_NumOfPHeads equ 28h ; Double Word. Number of physical heads.
    87                                  GDP_48h_NumOfPSpT equ 2Ch ; Double word. Num of physical sectors per track.
    88                                  GDP_48h_LBA_Sectors equ 30h ; 8 bytes. Number of physical/LBA sectors.
    89                                  GDP_48h_BytesPerSec equ 38h ; Word. Number of bytes in a sector.
    90                                  
    91                                  ; Cursor Location
    92                                  CCCpointer equ  0450h   ; BIOS data, current cursor column
    93                                  
    94                                  ; MINIMUM & MAXIMUM SECTORS (partition and disk size limits in sectors)
    95                                  MINPARTSIZE equ 4096 ; 2MB
    96                                  MAXPARTSIZE equ 4128768 - 1 ; 2GB - masterboot sector	
    97                                  MINDISKSIZE equ 16384 ; 8MB
    98                                  MAXDISKSIZE equ 4128768 ; 2GB
    99                                  
   100                                  pTableOffset equ 1BEh ; 446
   101                                  
   102                                  	; Convert LBA to CHS
   103                                  	; 08/02/2019
   104                                  
   105                                  	; LBA = ((C1*H0+H1)*S0)+S1-1
   106                                  	;
   107                                  	; C1 = Selected Cylinder Number
   108                                  	; H0 = Number of Heads (Maximum Head Number + 1)
   109                                  	; H1 = Selected Head Number
   110                                  	; S0 = Maximum Sector Number
   111                                  	; S1 = Selected Sector Number
   112                                  	;
   113                                  	; Phoenix, Enchanced Disk Drive Specicifications, v1.1, Page 8)
   114                                  		
   115                                  
   116                                  [BITS 16]
   117                                  [ORG 100h]
   118                                  
   119                                  	;cli
   120                                  	;cld
   121                                  	;push	cs
   122                                  	;pop	ss
   123                                  	;mov	sp, 0FFFEh
   124                                  	;sti
   125                                  	
   126                                  	;mov	bx, SizeOfFile+100
   127                                  	
   128 00000000 BB[5472]                	mov	bx, bss_end
   129                                  
   130 00000003 83C30F                          add	bx, 15
   131 00000006 D1EB                            shr	bx, 1
   132 00000008 D1EB                            shr	bx, 1
   133 0000000A D1EB                    	shr	bx, 1
   134 0000000C D1EB                    	shr	bx, 1
   135 0000000E B44A                            mov	ah, 4Ah ; modify memory allocation
   136                                          ;push	cs
   137                                          ;pop	es
   138 00000010 CD21                            int	21h
   139                                  
   140                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   141                                  ; clear BSS
   142                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   143                                  ; 03/02/2019
   144                                  
   145                                  	;mov	cx, bss_end
   146 00000012 B9[4671]                	mov	cx, bss_clear_end ; 15/02/2019
   147                                  
   148 00000015 BF[0A6A]                	mov	di, bss_start
   149 00000018 29F9                    	sub	cx, di
   150 0000001A 41                      	inc	cx
   151 0000001B D1E9                    	shr	cx, 1
   152 0000001D 31C0                    	xor	ax, ax
   153 0000001F F3AB                    	rep	stosw 
   154                                  
   155                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   156                                  ; get hd image file name
   157                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   158                                  
   159 00000021 BE8000                  	mov	si, 80h			; PSP command tail
   160 00000024 AC                       	lodsb
   161 00000025 08C0                    	or	al, al 			; command tail length                            
   162 00000027 0F845B07                	jz	B_01			; jump if zero
   163                                  A_01:
   164 0000002B AC                      	lodsb
   165 0000002C 3C20                    	cmp	al, ' '			; is it SPACE ?
   166 0000002E 74FB                    	je	short A_01 		
   167 00000030 0F825207                	jb	B_01
   168                                  	
   169                                  	; check hd image file name
   170                                  A_02:
   171 00000034 BF[8159]                       	mov	di, img_file_name
   172 00000037 AA                      	stosb
   173                                  A_03:
   174 00000038 AC                      	lodsb
   175                                  	;cmp	al, 0Dh ; ENTER (CR) key
   176 00000039 3C20                    	cmp	al, 20h ; ' '
   177 0000003B 760C                    	jna	short A_04
   178 0000003D AA                      	stosb
   179 0000003E 81FF[8D59]              	cmp	di, img_file_name + 12
   180 00000042 72F4                    	jb	short A_03
   181 00000044 803C20                  	cmp	byte [si], 20h 
   182 00000047 773F                    	ja	short A_10
   183                                  A_04:
   184                                  	;sub	al, al
   185                                  	;stosb
   186                                  
   187                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   188                                  ; File name capitalization
   189                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   190                                  
   191 00000049 BE[8159]                	mov	si, img_file_name
   192 0000004C 89F7                    	mov	di, si
   193 0000004E 89F3                    	mov	bx, si
   194                                  A_05:
   195 00000050 AC                      	lodsb
   196 00000051 3C61                    	cmp	al, 'a'
   197 00000053 730D                    	jnb	short A_07
   198 00000055 20C0                    	and	al, al
   199 00000057 7412                    	jz	short A_08
   200 00000059 3C2E                    	cmp	al, '.'
   201 0000005B 7502                    	jne	short A_06
   202 0000005D 89FB                    	mov	bx, di ; dot position	
   203                                  A_06:
   204 0000005F AA                      	stosb
   205 00000060 EBEE                    	jmp	short A_05 		
   206                                  A_07:
   207 00000062 3C7A                    	cmp	al, 'z'
   208 00000064 77F9                    	ja	short A_06
   209 00000066 24DF                    	and	al, 0DFh ; NOT 32
   210 00000068 AA                      	stosb
   211 00000069 EBE5                    	jmp	short A_05	
   212                                  A_08:
   213 0000006B 8805                    	mov	[di], al
   214 0000006D 4F                      	dec	di
   215 0000006E 39FB                    	cmp	bx, di
   216 00000070 7316                    	jnb	short A_10
   217 00000072 29DF                    	sub	di, bx
   218 00000074 81EB[8159]              	sub	bx, img_file_name
   219 00000078 83FF03                  	cmp	di, 3
   220 0000007B 7606                    	jna	short A_09
   221 0000007D 21DB                    	and	bx, bx
   222 0000007F 7507                    	jnz	short A_10
   223 00000081 EB0E                    	jmp	short A_11		
   224                                  A_09:
   225 00000083 83FB08                  	cmp	bx, 8
   226 00000086 7609                    	jna	short A_11
   227                                  A_10:
   228 00000088 BE[1345]                	mov	si, msg_inv_file_name
   229 0000008B E8A71D                  	call	print_msg
   230 0000008E E9FB06                  	jmp	B_02
   231                                  
   232                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   233                                  ; Find image file
   234                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   235                                  	
   236                                  A_11:
   237 00000091 BA[8159]                	mov	dx, img_file_name
   238 00000094 B93F00                  	mov	cx, 3Fh ; File Attributes
   239 00000097 B44E                    	mov	ah, 4Eh ; MS-DOS Function = Find First File
   240 00000099 CD21                    	int	21h
   241                                  	;jc	B_05
   242 0000009B 0F82F20A                	jc	new_image ; 07/03/2019
   243                                  
   244                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   245                                  ; Check image file features
   246                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   247                                  
   248                                  A_12:
   249 0000009F BE9500                  	mov	si, DTA_Attrib
   250 000000A2 8A04                    	mov	al, [si]
   251 000000A4 241F                    	and	al, 1Fh ; directory, volume label, system, hidden, read only
   252 000000A6 0F85ED06                	jnz	B_04     
   253 000000AA BE9A00                  	mov	si, DTA_FileSize
   254 000000AD AD                      	lodsw
   255                                  	; max. size of hard disk image = 63sectors*64heads*1024cylinders
   256 000000AE 8B14                    	mov	dx, [si]
   257 000000B0 81FA007E                	cmp	dx, 7E00h ; 2GB upper limit (7E000000h)
   258 000000B4 0F87DF06                	ja	B_04
   259 000000B8 7208                    	jb	short A_13
   260 000000BA 21C0                    	and	ax, ax
   261 000000BC 0F85D706                	jnz	B_04
   262                                  	; 20/09/2020
   263                                  	;mov	ax, 1024
   264                                  	;jmp	A_24
   265 000000C0 EB0E                    	jmp	short A_14
   266                                  A_13:
   267 000000C2 A9FF01                  	test	ax, 511 ; check file size for sector boundary
   268 000000C5 0F85CE06                	jnz	B_04
   269 000000C9 83FA7E                  	cmp	dx, 7Eh  ; 8MB lower limit  (7E0000h)
   270 000000CC 0F82C706                	jb	B_04
   271                                  A_14:
   272 000000D0 A3[906E]                	mov	[file_size], ax
   273 000000D3 8916[926E]              	mov	[file_size+2], dx
   274                                  
   275                                  	; convert (disk image) file size to sector count (disk size)
   276                                  	; (dx:ax)/512
   277                                  	
   278 000000D7 B90002                  	mov	cx, 512
   279 000000DA E8590D                  	call	div32
   280                                  
   281                                  	; 12/02/2019
   282 000000DD A3[886E]                	mov	[total_sectors], ax
   283 000000E0 8916[8A6E]              	mov	[total_sectors+2], dx
   284                                  
   285                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   286                                  ; Load masterboot sector of HD image file
   287                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   288                                  
   289 000000E4 BA[8159]                	mov	dx, img_file_name
   290 000000E7 B8023D                  	mov	ax, 3D02h ; open for reading and writing
   291 000000EA CD21                    	int	21h
   292 000000EC 0F822F1D                	jc	D_02
   293                                  
   294                                  	;mov	[img_file_handle], ax
   295 000000F0 89C3                    	mov	bx, ax
   296                                  
   297 000000F2 B43F                    	mov	ah, 3Fh ; read file
   298 000000F4 B90002                  	mov	cx, 512
   299 000000F7 BA[2857]                	mov	dx, MasterBootBuff
   300 000000FA CD21                    	int	21h
   301 000000FC 9C                      	pushf
   302 000000FD 50                      	push	ax
   303 000000FE B43E                    	mov	ah, 3Eh ; close file
   304                                  	;mov	bx, [img_file_handle]
   305 00000100 CD21                    	int	21h
   306 00000102 58                      	pop	ax
   307 00000103 9D                      	popf
   308 00000104 0F82171D                	jc	D_02
   309                                  
   310                                  	; 11/02/2019
   311                                  	;mov	word [img_file_handle], 0 ; disk image file is not open	
   312                                  
   313                                  	; 12/02/2019
   314                                  
   315 00000108 813E[2659]55AA          	cmp 	word [MBIDCode], 0AA55h
   316 0000010E 0F858506                	jne	B_04 ; invalid disk image file !
   317                                  
   318                                  	; clear screen
   319 00000112 B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
   320 00000115 CD10                    	int	10h
   321                                  
   322 00000117 C606[C16E]01            	mov	byte [existingfile], 1 ; we are using existing disk image file
   323                                  				       ; (not a new file) flag
   324                                  
   325                                  	; Check for Singlix Master Boot code
   326 0000011C 813E[E458]BE07          	cmp	word [MasterBootBuff+444], 7BEh
   327 00000122 7540                    	jne	short A_15 ; no ..
   328                                  	
   329                                  	; It is seen as singlix MBR
   330                                  	; Let's check for disk size words (CHS record)
   331 00000124 8B0E[CC58]              	mov	cx, [MasterBootBuff+420] ; cylinders
   332 00000128 83F910                  	cmp	cx, 16
   333 0000012B 7237                    	jb	short A_15 ; invalid
   334 0000012D A1[CE58]                	mov	ax, [MasterBootBuff+422] ; heads
   335 00000130 83F802                  	cmp	ax, 2
   336 00000133 722F                    	jb	short A_15 ; invalid
   337 00000135 8B16[D058]              	mov	dx, [MasterBootBuff+424] ; sectors
   338 00000139 83FA11                  	cmp	dx, 17
   339 0000013C 7226                    	jb	short A_15 ; invalid
   340 0000013E 890E[9A40]              	mov	[cylinders], cx
   341 00000142 A3[9840]                	mov	[heads], ax
   342 00000145 8916[9640]              	mov	[sectors], dx
   343 00000149 F7E2                    	mul	dx
   344 0000014B E8F60C                  	call	mul32
   345 0000014E 09DB                    	or	bx, bx
   346 00000150 7512                    	jnz	short A_15 ; invalid
   347 00000152 3B16[8A6E]              	cmp	dx, [total_sectors+2]
   348 00000156 750C                    	jne	short A_15
   349 00000158 3B06[886E]              	cmp	ax, [total_sectors]
   350 0000015C 7506                    	jne	short A_15 ; invalid 
   351                                  
   352                                  	; valid singlix MBR & disk image file
   353                                  
   354                                  	; Display disk geometry
   355                                  
   356 0000015E BE[115F]                	mov	si, trdos386_disk_chs_header
   357                                  	;call	print_msg
   358                                  	;
   359                                  	;jmp	A_27
   360                                  	; 20/09/2020
   361 00000161 E9D300                  	jmp	A_24
   362                                  
   363                                  A_15:
   364                                  	; 17/10/2020
   365                                  	;mov	ax, [file_size]
   366                                  	;mov	dx, [file_size+2]
   367                                  
   368                                  	;shr	dx, 1
   369                                  	;rcr	ax, 1 ; / 2
   370                                  		      ; / 256	
   371                                  	;mov	al, ah
   372                                  	;mov	ah, dl
   373                                  	;mov	dl, dh
   374                                  	;xor	dh, dh
   375                                  	
   376                                  ;	mov	cl, 9 ; / 512
   377                                  ;A_15shr32:
   378                                  ;	shr	dx,1
   379                                  ;	rcr	ax,1
   380                                  ;	dec	cl
   381                                  ;	jnz	short A_15shr32
   382                                  
   383                                  	; 17/10/2020
   384 00000164 A1[886E]                	mov	ax, [total_sectors]
   385 00000167 8B16[8A6E]              	mov	dx, [total_sectors+2]
   386                                  
   387                                  	; cylinders*63sectors*16heads (<=528MB)
   388                                  	;cmp	dx, 1F80h ; 1024*16*63 (1F800000h)
   389 0000016B 83FA0F                  	cmp	dx, 0Fh ; 17/10/2020
   390 0000016E 7774                    	ja	short A_21
   391 00000170 7213                    	jb	short A_16
   392                                  	;and	ax, ax
   393                                  	;jnz	A_22
   394 00000172 3D00C0                  	cmp	ax, 0C000h ; 17/10/2020
   395 00000175 0F878200                	ja	A_22
   396                                  	; = 528MB (1024*16*63*512)
   397 00000179 C706[9840]1000          	mov	word [heads], 16
   398 0000017F B80004                  	mov	ax, 1024
   399 00000182 E99C00                  	jmp	A_25	
   400                                  A_16:
   401                                  	; < 528MB
   402 00000185 B9F003                  	mov	cx, 63*16 ; 1008
   403                                  	;div	cx
   404                                  	;and	dx, dx
   405 00000188 E8AB0C                  	call	div32 ; 16/10/2020
   406 0000018B 21DB                    	and	bx, bx ; remainder
   407                                  	;jnz	B_04
   408                                  	; 10/02/2019
   409 0000018D 7509                    	jnz	short A_17 ; 17 spt disk image check
   410 0000018F C706[9840]1000          	mov	word [heads], 16
   411 00000195 E98900                  	jmp	A_25
   412                                  A_17:
   413                                  	; 12/02/2019
   414                                  	;mov	ax, [file_size]
   415                                  	;mov	dx, [file_size+2]
   416                                  
   417                                  	; 17/10/2020
   418 00000198 A1[886E]                	mov	ax, [total_sectors]
   419 0000019B 8B16[8A6E]              	mov	dx, [total_sectors+2]
   420                                  
   421                                  	;; 10/02/2019
   422                                  	;; Check 17 spt disk image
   423                                  	;mov	si, DTA_FileSize
   424                                  	;lodsw
   425                                  	;; max. size of hard disk image = 17sectors*16heads*1024cylinders
   426                                  	;mov	dx, [si]
   427                                  	
   428                                  	;cmp	dx, 880h ; 136MB upper limit (8800000h)
   429 0000019F 83FA04                  	cmp	dx, 04h  ;17/10/2020
   430 000001A2 0F87F105                	ja	B_04
   431 000001A6 7207                    	jb	short A_49
   432                                  
   433 000001A8 3D0040                  	cmp	ax, 4000h ; 17/10/2020
   434 000001AB 0F87E805                	ja	B_04
   435                                  A_49:
   436                                  	; 17/10/2020
   437                                  	;mov	cx, 512
   438                                  	;call	div32
   439                                  
   440                                  	;mov	[pp_Sectors], ax
   441                                  	;mov	[pp_Sectors+2], dx
   442                                  	
   443                                  	; Calculate with increased heads (count) order
   444                                  	; (For example cyls = 1024 & heads = 8 is better than
   445                                  	;      cyls = 512 & heads = 16, for 17 SPT.v)
   446                                  
   447 000001AF B92200                  	mov	cx, 17*2 ; 34 ; heads = 2
   448                                  A_18:
   449 000001B2 E8810C                  	call	div32
   450                                  		; If remainder = 0
   451                                  		;    it is 17 spt hard disk image file
   452 000001B5 21DB                    	and	bx, bx
   453 000001B7 7414                    	jz	short A_20
   454                                  A_19:	
   455 000001B9 83C111                  	add	cx, 17
   456 000001BC 81F91001                	cmp	cx, 17*16 ; 272 ; heads = 16
   457 000001C0 0F87D305                	ja	B_04 ; invalid image file !
   458                                  
   459                                  	;mov	ax, [pp_Sectors]
   460                                  	;mov	dx, [pp_Sectors+2]
   461                                  
   462                                  	; 17/10/2020
   463 000001C4 A1[886E]                	mov	ax, [total_sectors]
   464 000001C7 8B16[8A6E]              	mov	dx, [total_sectors+2]
   465                                  	 	
   466 000001CB EBE5                    	jmp	short A_18
   467                                  
   468                                  A_20:
   469 000001CD 3D0004                  	cmp	ax, 1024
   470 000001D0 77E7                    	ja	short A_19
   471                                  
   472 000001D2 B311                    	mov	bl, 17
   473 000001D4 881E[9640]              	mov	[sectors], bl ; 17
   474 000001D8 A3[9A40]                	mov	[cylinders], ax
   475                                  
   476 000001DB 89C8                    	mov	ax, cx
   477 000001DD F6F3                    	div	bl
   478                                  	;xor	ah, ah
   479 000001DF A3[9840]                	mov	[heads], ax
   480                                  
   481 000001E2 EB46                    	jmp	short A_26
   482                                  
   483                                  A_21:
   484                                  	; cylinders*63sectors*32heads (>528MB, <=1GB)
   485                                  	;cmp	dx, 3F00h ; 1024*32*63 (3F000000h)
   486 000001E4 83FA1F                  	cmp	dx, 1Fh ; 17/10/2020
   487 000001E7 7726                    	ja	short A_23
   488 000001E9 7210                    	jb	short A_22
   489                                  	;and	ax, ax
   490                                  	;jnz	short A_23
   491 000001EB 3D0080                  	cmp	ax, 8000h ; 17/10/2020
   492 000001EE 771F                    	ja	short A_23
   493                                  	; = 1GB (1024*32*63*512)
   494 000001F0 C706[9840]1000          	mov	word [heads], 16
   495 000001F6 B80004                  	mov	ax, 1024
   496 000001F9 EB26                    	jmp	short A_25	
   497                                  A_22:
   498 000001FB B9E007                  	mov	cx, 63*32
   499                                  	;div	cx
   500                                  	;and	dx, dx
   501 000001FE E8350C                  	call	div32 ; 16/10/2020
   502 00000201 21DB                    	and	bx, bx ; remainder
   503 00000203 0F859005                	jnz	B_04
   504 00000207 C706[9840]2000          	mov	word [heads], 32
   505 0000020D EB12                    	jmp	short A_25
   506                                  A_23:
   507                                  	; cylinders*63sectors*64heads (>1GB, <=2GB)
   508 0000020F B9C00F                  	mov	cx, 63*64
   509                                  	;div	cx
   510                                  	;and	dx, dx
   511 00000212 E8210C                  	call	div32 ; 16/10/2020
   512 00000215 21DB                    	and	bx, bx ; remainder
   513 00000217 0F857C05                	jnz	B_04
   514                                  ;A_24:
   515 0000021B C706[9840]4000          	mov	word [heads], 64
   516                                  A_25:
   517 00000221 C706[9640]3F00          	mov	word [sectors], 63
   518 00000227 A3[9A40]                	mov	[cylinders], ax
   519                                  A_26:
   520                                  	; 08/02/2019
   521                                  
   522                                  	; calculate total sectors (by using CHS values)
   523 0000022A A1[9640]                	mov	ax, [sectors]
   524 0000022D F726[9840]              	mul	word [heads]
   525 00000231 A3[C26E]                	mov	[min_sectors], ax ; Minimum sectors
   526                                  	
   527                                  	; 17/10/2020
   528                                  	;mov	dx, [cylinders]
   529                                  	;mul	dx
   530                                  	;mov	[total_sectors], ax
   531                                  	;mov	[total_sectors+2], dx
   532                                  
   533                                  	; 12/02/2019
   534 00000234 BE[645F]                	mov	si, disk_chs_header
   535                                  A_24:			; 20/09/2020	
   536 00000237 E8FB1B                  	call	print_msg
   537                                  A_27:
   538 0000023A E8DE22                  	call	init_partition_tables
   539 0000023D 7307                    	jnc	short A_28
   540                                  
   541                                  	; 24/02/2019
   542 0000023F E8FD28                  	call	partition_table_fix
   543 00000242 73F6                    	jnc	short A_27
   544                                  
   545 00000244 CD20                    	int 	20h
   546                                  A_28:
   547                                  	; 26/02/2019
   548 00000246 803E[9171]00            	cmp	byte [epnumber], 0
   549 0000024B 7623                    	jna	short A_29
   550                                  
   551                                  	; Enable random access to disk image file
   552 0000024D C606[9C40]01            	mov	byte [random], 1
   553                                  
   554                                  	;mov	byte [ldrives], 255 ; invalid value
   555                                  	;			    ; to prevent deleting
   556                                  	;			    ; extended partition
   557                                  
   558                                  	; Open disk image file again.
   559 00000252 BA[8159]                	mov	dx, img_file_name
   560 00000255 B8023D                  	mov	ax, 3D02h ; open for reading and writing
   561 00000258 CD21                    	int	21h
   562 0000025A 7214                    	jc	short A_29
   563                                  
   564 0000025C A3[9440]                	mov	[img_file_handle], ax
   565                                  
   566 0000025F E8692E                  	call	init_ext_partition_tables
   567                                  
   568                                  	; Close file
   569 00000262 8B1E[9440]              	mov	bx, [img_file_handle]
   570 00000266 B43E                    	mov	ah, 3Eh ; close file
   571 00000268 CD21                    	int	21h
   572                                  	
   573                                  	; 28/02/2019
   574 0000026A C706[9440]0000          	mov	word [img_file_handle], 0
   575                                  A_29:
   576                                  	; 08/03/2019
   577 00000270 803E[C16E]00            	cmp	byte [existingfile], 0
   578 00000275 7743                    	ja	short A_32
   579                                  
   580 00000277 B80300                  	mov	ax, 3  ; clear screen
   581 0000027A CD10                    	int	10h
   582                                  
   583 0000027C E8FE1C                  	call	display_chs_table
   584                                  
   585 0000027F BE[5056]                	mov	si, CRLF
   586 00000282 E8B01B                  	call	print_msg
   587                                  
   588                                  	; 08/03/2019
   589 00000285 C606[C16E]01            	mov	byte [existingfile], 1
   590                                  
   591 0000028A E81627                  	call	dpt_1
   592                                  
   593 0000028D BE[5056]                	mov	si, CRLF
   594 00000290 E8A21B                  	call	print_msg
   595                                  
   596 00000293 BE[7F54]                	mov	si, msg_edit_or_exit
   597 00000296 E89C1B                  	call	print_msg
   598                                  A_30:
   599 00000299 30E4                    	xor	ah, ah
   600 0000029B CD16                    	int	16h
   601                                  
   602 0000029D 3C0D                    	cmp	al, 13 ; CR (ENTER) key
   603 0000029F 7426                    	je	short A_33 
   604                                  
   605 000002A1 3C1B                    	cmp	al, 27 ; ESCape key
   606 000002A3 740D                    	je	short A_31
   607                                  
   608 000002A5 3C20                    	cmp	al, 32 ; SPACE key
   609 000002A7 741E                    	je	short A_33 
   610                                  
   611 000002A9 3C03                    	cmp	al, 3 ; CTRL+C
   612 000002AB 7405                    	je	short A_31
   613                                  
   614 000002AD 83F800                  	cmp	ax, 0 ; CTRL+BREAK
   615 000002B0 77E7                    	ja	short A_30
   616                                  A_31:
   617 000002B2 BE[5056]                	mov	si, CRLF
   618 000002B5 E87D1B                  	call	print_msg
   619                                  
   620 000002B8 CD20                    	int	20h
   621                                  
   622                                  A_32:
   623                                  	; initialize primary partition tables
   624                                  
   625 000002BA E85E22                  	call	init_partition_tables
   626 000002BD 7308                    	jnc	short A_33  ; 24/02/2019
   627                                  
   628                                  	; 24/02/2019
   629 000002BF E87D28                  	call	partition_table_fix
   630 000002C2 73F6                    	jnc	short A_32
   631                                  	; ESC key has been pressed for EXIT
   632 000002C4 E9C504                  	jmp	B_02  ; Terminate program
   633                                  A_33:
   634                                  	; 04/02/2019
   635 000002C7 30C0                    	xor	al, al  ; MBR/PRIMARY PARTITIONS
   636 000002C9 E8C126                  	call	display_partition_table
   637                                  A_34:
   638 000002CC 30C0                    	xor	al, al ; 11/02/2019
   639 000002CE 3806[8E71]              	cmp	byte [pcount], al ; 0
   640                                  	;jna	A_44 ; empty partition table
   641 000002D2 7703                    	ja	short A_35
   642                                  	;inc	al ; 11/02/2019
   643                                  	; 10/02/2019
   644                                  	;mov	[newdisk], al ; 1 ; Continue as new disk image (with empty pt)
   645                                  	;mov	[random], al ; 1 ; next r/w is not sequental
   646 000002D4 E9EF00                  	jmp	A_44
   647                                  A_35:
   648                                  	; Check disk parameters with current CHS settings
   649 000002D7 31DB                    	xor	bx, bx
   650 000002D9 31C9                    	xor	cx, cx
   651                                  A_36:
   652 000002DB 80BF[4B71]00            	cmp	byte [part_table_sys_id+bx], 0
   653 000002E0 767C                    	jna	A_37
   654                                  
   655 000002E2 A1[9640]                	mov	ax, [sectors]
   656 000002E5 F726[9840]              	mul	word [heads]
   657                                  	; dx = 0, ax = heads*sectors
   658 000002E9 8B97[4971]              	mov	dx, [part_table_start_cyl+bx]
   659 000002ED F7E2                    	mul	dx
   660 000002EF 89C6                    	mov	si, ax
   661 000002F1 89D7                    	mov	di, dx
   662 000002F3 8A87[4771]              	mov	al, [part_table_start_head+bx]
   663 000002F7 F626[9640]              	mul	byte [sectors]
   664 000002FB 01C6                    	add	si, ax
   665 000002FD 83D700                  	adc	di, 0
   666 00000300 8A87[4871]              	mov	al, [part_table_start_sector+bx]
   667 00000304 30E4                    	xor	ah, ah
   668 00000306 FEC8                    	dec	al ; 1 -> 0
   669 00000308 01C6                    	add	si, ax
   670 0000030A 83D700                  	adc	di, 0
   671                                  
   672 0000030D 3BBF[5271]              	cmp	di, [part_table_rel_sec_hw+bx]
   673                                  	;jne	B_04 ; invalid
   674 00000311 7558                    	jne	short A_38
   675 00000313 3BB7[5071]              	cmp	si, [part_table_rel_sec_lw+bx]
   676                                  	;jne	B_04 ; invalid
   677 00000317 7552                    	jne	short A_38
   678                                  
   679 00000319 A1[9640]                	mov	ax, [sectors]
   680 0000031C F726[9840]              	mul	word [heads]
   681                                  	; dx = 0, ax = heads*sectors
   682 00000320 8B97[4E71]              	mov	dx, [part_table_end_cyl+bx]
   683 00000324 F7E2                    	mul	dx
   684 00000326 89C6                    	mov	si, ax
   685 00000328 89D7                    	mov	di, dx
   686 0000032A 8A87[4C71]              	mov	al, [part_table_end_head+bx]
   687 0000032E F626[9640]              	mul	byte [sectors]
   688 00000332 01C6                    	add	si, ax
   689 00000334 83D700                  	adc	di, 0
   690 00000337 8A87[4D71]              	mov	al, [part_table_end_sector+bx]
   691 0000033B 30E4                    	xor	ah, ah
   692                                  	;dec	al ; 63 -> 62
   693 0000033D 01C6                    	add	si, ax
   694 0000033F 83D700                  	adc	di, 0
   695                                  
   696 00000342 8B87[5471]              	mov	ax, [part_table_num_sec_lw+bx]
   697 00000346 8B97[5671]              	mov	dx, [part_table_num_sec_hw+bx]
   698                                  	
   699 0000034A 0387[5071]              	add	ax, [part_table_rel_sec_lw+bx]
   700 0000034E 1397[5271]              	adc	dx, [part_table_rel_sec_hw+bx]
   701                                  
   702 00000352 39F0                    	cmp	ax, si
   703                                  	;jne	B_04 ; invalid
   704 00000354 7515                    	jne	short A_38
   705                                  
   706 00000356 39FA                    	cmp	dx, di
   707                                  	;jne	B_04 ; invalid
   708 00000358 7511                    	jne	short A_38
   709                                  
   710 0000035A FE06[4471]              	inc	byte [goodpte]	
   711                                  A_37:
   712 0000035E FEC1                    	inc	cl
   713                                  
   714 00000360 80F904                  	cmp	cl, 4
   715 00000363 7316                    	jnb	short A_39
   716                                  
   717 00000365 83C312                  	add	bx, 18  ; partition table structure size
   718                                  	
   719 00000368 E970FF                  	jmp	A_36
   720                                  A_38:
   721                                  	; 24/02/2019 
   722                                  	; If defective pte count > 1 do not tolerate MBR.
   723 0000036B B001                    	mov 	al, 1
   724 0000036D 3806[4571]              	cmp	[badpte], al ; 1
   725 00000371 0F872204                	ja	B_04
   726 00000375 FE06[4571]              	inc	byte [badpte]
   727 00000379 EBE3                    	jmp	short A_37 
   728                                  A_39:
   729                                  	; If defective pte count > good pte, we must not continue
   730 0000037B A0[4571]                	mov	al, [badpte]	
   731 0000037E 20C0                    	and	al, al
   732 00000380 7410                    	jz	short A_41
   733                                  
   734 00000382 3A06[4471]              	cmp	al, [goodpte]
   735 00000386 0F870D04                	ja	B_04
   736                                  
   737                                  	; 24/02/2019
   738                                  A_40:
   739 0000038A BE[F160]                	mov	si, msg_defective_pt
   740 0000038D E8A51A                  	call	print_msg
   741 00000390 EB34                    	jmp	short A_44
   742                                  
   743                                  A_41:
   744                                  	; LBA and CHS values of all partitions are OK (here)
   745                                  
   746                                  	; sort MBR (primary) partitions
   747                                  
   748 00000392 E8CF22                  	call	sort_partition_table
   749                                  
   750                                  	; Checking partition overlaps (via start and end cylinders)
   751                                  
   752 00000395 31DB                    	xor	bx, bx
   753 00000397 BA1200                  	mov	dx, 18
   754                                  A_42:
   755 0000039A FEC3                    	inc	bl
   756                                  
   757 0000039C 8A87[D26E]              	mov	al, [bx+sort]
   758 000003A0 F6E2                    	mul	dl
   759 000003A2 89C6                    	mov	si, ax	; current
   760                                  
   761 000003A4 80BC[4B71]00            	cmp	byte [part_table_sys_id+si], 0
   762 000003A9 7616                    	jna	short A_43
   763                                  
   764 000003AB 8A87[D16E]              	mov	al, [bx+sort-1]
   765 000003AF F6E2                    	mul	dl
   766 000003B1 89C7                    	mov	di, ax  ; previous
   767                                  
   768 000003B3 8B85[4E71]              	mov	ax, [part_table_end_cyl+di]
   769 000003B7 3B84[4971]              	cmp	ax, [part_table_start_cyl+si]
   770 000003BB 7204                    	jb	short A_43
   771                                  
   772 000003BD 21C0                    	and	ax, ax
   773                                  	;jnz	B_04  ; overlap error (except empty entries)
   774                                  	; 24/02/2019
   775 000003BF 75C9                    	jnz	short A_40
   776                                  
   777                                  A_43:
   778 000003C1 80FB03                  	cmp	bl, 3
   779 000003C4 72D4                    	jb	short A_42
   780                                  
   781                                  A_44:
   782 000003C6 BE[225B]                	mov	si, mbr_editing_options
   783 000003C9 E8691A                  	call	print_msg
   784                                  
   785 000003CC BE[D05B]                	mov	si, enter_option_number_msg
   786 000003CF E8631A                  	call	print_msg
   787                                  
   788 000003D2 803E[D06E]00            	cmp	byte [ldrives], 0
   789 000003D7 760C                    	jna	short A_45
   790                                  
   791 000003D9 BE[5056]                	mov	si, CRLF
   792 000003DC E8561A                  	call	print_msg
   793                                  
   794 000003DF BE[3962]                	mov	si, str_display_ebr_pt
   795 000003E2 E8501A                  	call	print_msg
   796                                  A_45:	
   797                                  	;mov	si, CRLF
   798                                  	;call	print_msg
   799                                  
   800                                  A_46:
   801 000003E5 30E4                    	xor	ah, ah
   802 000003E7 CD16                    	int	16h
   803                                  
   804 000003E9 3C30                    	cmp	al, '0'
   805 000003EB 7428                    	je	short A_47
   806                                  
   807 000003ED 3C31                    	cmp	al, '1'
   808 000003EF 742D                    	je	short create_partition	
   809 000003F1 3C32                    	cmp	al, '2'
   810 000003F3 0F84F300                	je	activate_partition
   811 000003F7 3C33                    	cmp	al, '3'
   812 000003F9 0F849001                	je	delete_partition
   813 000003FD 3C34                    	cmp	al, '4'
   814 000003FF 0F849602                	je	write_pt_mbr
   815                                  	
   816 00000403 3C1B                    	cmp	al, 27 ; ESCape
   817 00000405 740E                    	je	short A_47
   818                                  
   819                                  	; 28/02/2019
   820 00000407 803E[D06E]00            	cmp	byte [ldrives], 0
   821 0000040C 76D7                    	jna	short A_46
   822                                  
   823 0000040E 3C20                    	cmp	al, 20h ; SPACE
   824 00000410 75D3                    	jne	short A_46
   825                                  
   826 00000412 E95D27                  	jmp	display_extended_pt
   827                                  A_47:
   828                                  	; terminate
   829 00000415 CD20                    	int	20h
   830                                  
   831                                  A_48:
   832                                  	; 24/02/2019
   833 00000417 30C0                    	xor	al, al  ; MBR/PRIMARY PARTITIONS
   834 00000419 E87125                  	call	display_partition_table
   835 0000041C EBA8                    	jmp	short A_44
   836                                  
   837                                  ;-----------------------------------------------------------------------------
   838                                  
   839                                  create_partition:
   840                                  	; 10/02/2019
   841 0000041E 31C0                    	xor	ax, ax
   842 00000420 A2[9C6E]                	mov	byte [wholedisk], al ; 0 ; Reset wholedisk flag
   843                                  
   844                                  	; 13/02/2019
   845 00000423 3806[9D40]              	cmp	byte [newdisk], al ; 0
   846 00000427 772E                    	ja	short cp_2 ; New disk image, continue
   847                                  
   848 00000429 3806[8E71]              	cmp	byte [pcount], al ; 0 ; number of (valid) partitions
   849 0000042D 7707                    	ja	short cp_1
   850                                  
   851 0000042F C606[9D40]01            	mov	byte [newdisk], 1
   852 00000434 EB21                    	jmp	short cp_2
   853                                  cp_1:
   854 00000436 803E[8E71]04            	cmp	byte [pcount], 4
   855 0000043B 7339                    	jnb	short cp_3 ; full pt !		
   856                                  
   857                                  	; al = 0
   858 0000043D E88722                  	call	find_part_free_space
   859                                  		 ; Following values are for the max. free space on disk
   860                                  
   861 00000440 21C9                    	and	cx, cx
   862 00000442 7445                    	jz	short cp_4 ; there is not free space on disk
   863                                  
   864                                  	;mov	[c_cylinders], cx  ; count of free cylinders in the gap
   865 00000444 891E[2C72]              	mov	[c_fspc_offset], bx  ; offset from beginning of 'fspc:'
   866                                  	;mov	[c_gap], al ; gap (space index) number of this free space
   867                                  	;		    ; 0 -> before partition 1 (as PTE)
   868                                  	;		    ; 1-2-3 -> between partitions 1 to 4
   869                                  	;		    ; 4 -> after partition 4 (as PTE)
   870                                  
   871                                  	; Start to job with non-aligned (full) free sectors of this max. space
   872                                  	
   873 00000448 8B87[E271]              	mov	ax, [free_space.sectors_unused+bx]
   874 0000044C 8B97[E471]              	mov	dx, [free_space.sectors_unused+2+bx]	
   875                                  
   876 00000450 A3[986E]                	mov	[pp_Sectors], ax
   877 00000453 8916[9A6E]              	mov	[pp_Sectors+2], dx
   878                                  cp_2:
   879 00000457 C606[9C40]01            	mov	byte [random], 1  ; random access (use seek before reading)
   880                                  
   881 0000045C 3906[9440]              	cmp	[img_file_handle], ax ; 0
   882 00000460 0F87000B                	ja	B_49
   883                                  
   884                                  	; Open disk image file again.
   885                                  
   886                                  	; 25/02/2019 (Random access to disk image sectors must be enabled)
   887                                  	;dec	byte [random] ; 0 ; masterboot sector will be written		 
   888                                  	;		  	  ; no need to seek file pointer
   889                                  
   890 00000464 BA[8159]                	mov	dx, img_file_name
   891 00000467 B8023D                  	mov	ax, 3D02h ; open file for reading and writing
   892 0000046A CD21                    	int	21h
   893 0000046C 0F82AF19                	jc	D_02
   894                                  
   895 00000470 A3[9440]                	mov	[img_file_handle], ax
   896                                  
   897 00000473 E9EE0A                  	jmp	B_49 ; New/Empty disk, create partition menu
   898                                  
   899                                  cp_3:
   900                                  	; 13/02/2019
   901                                  	; There is not a free pt entry to create a new partition
   902                                  
   903 00000476 30C0                    	xor	al, al  ; MBR/PRIMARY PARTITIONS
   904 00000478 E81225                  	call	display_partition_table
   905                                  
   906 0000047B BE[B25C]                	mov	si, msg_full_pt
   907 0000047E E8B419                  	call	print_msg
   908 00000481 BE[DF5C]                	mov	si, msg_to_create_new_p
   909 00000484 E8AE19                  	call	print_msg
   910                                  
   911 00000487 EB73                    	jmp	ap_0
   912                                  cp_4:
   913                                  	; 02/03/2019
   914 00000489 803E[9171]00            	cmp	byte [epnumber], 0
   915 0000048E 7602                    	jna	short cp_5
   916                                  
   917 00000490 EB08                    	jmp	short create_logical_drives
   918                                  cp_5:
   919                                  	; 15/02/2019
   920                                  	; There is not (enough) free space to create a new partition
   921                                  
   922 00000492 BE[FD5C]                	mov	si, msg_no_free_space
   923 00000495 E89D19                  	call	print_msg
   924 00000498 EB62                    	jmp	ap_0
   925                                  
   926                                  ;-----------------------------------------------------------------------------
   927                                  
   928                                  create_logical_drives:
   929                                  	; 05/03/2019
   930 0000049A E80C2A                  	call	check_ext_free_space
   931 0000049D 7236                    	jc	short cld_5 ; 19/10/2020
   932                                  cld_1:
   933                                  	; 05/03/2019
   934 0000049F 803E[D06E]04            	cmp	byte [ldrives], 4
   935 000004A4 7203                    	jb	short cld_2
   936 000004A6 E93B27                  	jmp	eetc_2
   937                                  cld_2:
   938 000004A9 BE[6C65]                	mov	si, msg_c_ldd_q
   939 000004AC E88619                  	call	print_msg
   940                                  cld_3:	
   941 000004AF 28E4                    	sub	ah, ah
   942 000004B1 CD16                    	int	16h
   943                                  
   944 000004B3 3C1B                    	cmp	al, 27 ; ESCAPE key
   945 000004B5 0F846501                	je	cp_esc
   946 000004B9 24DF                    	and	al, 0DFh
   947 000004BB 3C4E                    	cmp	al, 'N'
   948 000004BD 740D                    	je	short cld_4
   949 000004BF 3C59                    	cmp	al, 'Y'
   950 000004C1 75EC                    	jne	short cld_3
   951 000004C3 BE[F25D]                	mov	si, _msg_YES
   952 000004C6 E86C19                  	call	print_msg
   953                                  
   954 000004C9 E94527                  	jmp	edit_ext_table_create_x
   955                                  cld_4:	
   956 000004CC BE[F85D]                	mov	si, _msg_NO
   957 000004CF E86319                  	call	print_msg
   958                                  
   959 000004D2 E94901                  	jmp	cp_esc
   960                                  cld_5:	
   961 000004D5 BE[0C65]                	mov	si, msg_c_part_error
   962 000004D8 E85A19                  	call	print_msg
   963                                  
   964 000004DB 803E[D06E]03            	cmp	byte [ldrives], 3
   965 000004E0 76C7                    	jna	short cld_2
   966                                  
   967 000004E2 BE[3A65]                	mov	si, msg_c_ldd_error
   968 000004E5 E84D19                  	call	print_msg
   969                                  
   970 000004E8 EB12                    	jmp	short ap_0
   971                                  
   972                                  ;-----------------------------------------------------------------------------
   973                                   	
   974                                  activate_partition:
   975                                  	; 12/02/2019
   976 000004EA 30C0                    	xor	al, al  ; MBR/PRIMARY PARTITIONS
   977 000004EC E89E24                  	call	display_partition_table
   978                                  
   979 000004EF 803E[8E71]00            	cmp	byte [pcount], 0
   980 000004F4 7713                    	ja	short ap_1
   981                                  
   982 000004F6 BE[665C]                	mov	si, msg_empty_pt
   983 000004F9 E83919                  	call	print_msg
   984                                  
   985                                  ap_0:
   986 000004FC BE[0957]                	mov	si, msg_press_any_key
   987 000004FF E83319                  	call	print_msg
   988                                  
   989 00000502 30E4                    	xor	ah, ah
   990 00000504 CD16                    	int	16h
   991                                  
   992 00000506 E91501                  	jmp	ap_esc
   993                                  
   994                                  ap_1:
   995                                  	; Set valid_ppnums (MBR partition IDs) list
   996 00000509 BE[E658]                	mov	si, MasterBootBuff+pTableOffset ; MasterBootBuff+446
   997 0000050C BB[E470]                	mov	bx, valid_ppnums
   998 0000050F B104                    	mov	cl, 4
   999                                  ap_2:
  1000 00000511 8A4404                  	mov	al, [si+ptFileSystemID]
  1001 00000514 8807                    	mov	[bx], al
  1002 00000516 FEC9                    	dec	cl
  1003 00000518 7406                    	jz	short ap_3
  1004 0000051A 43                      	inc	bx
  1005 0000051B 83C610                  	add	si, 16
  1006 0000051E EBF1                    	jmp	short ap_2
  1007                                  ap_3:
  1008 00000520 BE[E55E]                	mov	si, msg_enter_pn_to_act
  1009 00000523 E80F19                  	call	print_msg
  1010                                  ap_getchar:
  1011 00000526 30E4                    	xor	ah, ah
  1012 00000528 CD16                    	int	16h
  1013                                  	
  1014                                  	; 19/10/2020
  1015 0000052A 3C1B                    	cmp	al, 27
  1016 0000052C 0F84EE00                	je	ap_esc
  1017                                  
  1018                                  	;cmp	al, '0'
  1019                                  	;je	ap_esc
  1020                                  	
  1021 00000530 3C31                    	cmp	al, '1'
  1022 00000532 72F2                    	jb	short ap_getchar
  1023 00000534 3C34                    	cmp	al, '4'
  1024 00000536 77EE                    	ja	short ap_getchar
  1025                                  
  1026 00000538 30E4                    	xor	ah, ah
  1027 0000053A 89C2                    	mov	dx, ax
  1028                                  	
  1029 0000053C 80EA31                  	sub	dl, '1'
  1030 0000053F 89D6                    	mov	si, dx
  1031 00000541 38A4[E470]              	cmp	byte [si+valid_ppnums], ah  ; 0
  1032 00000545 76DF                    	jna	short ap_getchar ; Empty partition table entry, it is not shown
  1033                                  
  1034 00000547 BB0700                  	mov	bx, 07h
  1035 0000054A B409                    	mov	ah, 09h
  1036 0000054C B90100                  	mov	cx, 1
  1037 0000054F CD10                    	int	10h
  1038                                  
  1039 00000551 BE[E658]                	mov	si, MasterBootBuff+pTableOffset
  1040 00000554 BF[4671]                	mov	di, part_table_boot_ind ; (**)
  1041                                  
  1042                                  	; Clear all of possible active partition flags
  1043 00000557 8834                    	mov	[si], dh ; 0	
  1044 00000559 887410                  	mov	[si+16], dh ; 0
  1045 0000055C 887420                  	mov	[si+32], dh ; 0
  1046 0000055F 887430                  	mov	[si+48], dh ; 0
  1047                                  
  1048                                  	; This may not be needed !? 
  1049                                  	; (**) (Primary partitions structure/list)
  1050 00000562 8835                    	mov	[di], dh ; 0	
  1051 00000564 887512                  	mov	[di+18], dh ; 0
  1052 00000567 887524                  	mov	[di+36], dh ; 0
  1053 0000056A 887536                  	mov	[di+54], dh ; 0
  1054                                  
  1055 0000056D 20D2                    	and 	dl, dl
  1056 0000056F 740D                    	jz	short ap_4
  1057                                  
  1058 00000571 89D0                    	mov	ax, dx
  1059                                  
  1060 00000573 C0E004                  	shl	al, 4 ; * 16
  1061 00000576 01C6                    	add	si, ax
  1062                                  
  1063 00000578 B012                    	mov	al, 18
  1064 0000057A F6E2                    	mul	dl ; 1 to 3
  1065 0000057C 01C7                    	add	di, ax
  1066                                  ap_4:
  1067                                  	; Then	set active partition as requested by user
  1068 0000057E C60480                  	mov	byte [si], 80h
  1069 00000581 C60580                  	mov	byte [di], 80h ; (**)
  1070                                  
  1071 00000584 BE[5056]                	mov	si, CRLF ; Next line	
  1072 00000587 E8AB18                  	call	print_msg
  1073                                  
  1074                                  	; NOTE: Only the MBR buffer has been changed
  1075                                  	; (Masterboot sector will not be updated unless/till
  1076                                  	;  MBR partition table -and MBR code- will be written
  1077                                  	;  to disk image as result of 'write part. table' command.)
  1078                                  
  1079                                  	;; wait for 1 second
  1080                                  	;mov	ah, 02h
  1081                                  	;int	1Ah
  1082                                  	;mov	[GetChar], dh
  1083                                  ;ap_wait:
  1084                                  	;mov	ah, 02h
  1085                                  	;int	1Ah
  1086                                  	;cmp	dh, [GetChar]
  1087                                  	;je	short ap_wait
  1088                                  
  1089                                  	;jmp	A_33 ; display partition table again
  1090 0000058A E98AFE                  	jmp	A_48 ; 25/02/2019
  1091                                  
  1092                                  ;----------------------------------------------------------------------------- 	 
  1093                                  
  1094                                  delete_partition:
  1095                                  	; 19/10/2020
  1096                                  	; 10/02/2019
  1097 0000058D 30C0                    	xor	al, al  ; MBR/PRIMARY PARTITIONS
  1098 0000058F E8FB23                  	call	display_partition_table
  1099                                  
  1100 00000592 803E[8E71]00            	cmp	byte [pcount], 0
  1101 00000597 7712                    	ja	short dp_1
  1102                                  
  1103 00000599 BE[665C]                	mov	si, msg_empty_pt
  1104 0000059C E89618                  	call	print_msg
  1105                                  
  1106 0000059F BE[0957]                	mov	si, msg_press_any_key
  1107 000005A2 E89018                  	call	print_msg
  1108                                  
  1109 000005A5 30E4                    	xor	ah, ah
  1110 000005A7 CD16                    	int	16h
  1111                                  
  1112 000005A9 EB73                    	jmp	short dp_esc
  1113                                  
  1114                                  dp_1:
  1115                                  	; Set valid_ppnums (MBR partition IDs) list
  1116 000005AB BE[E658]                	mov	si, MasterBootBuff+pTableOffset ; MasterBootBuff+446
  1117 000005AE BB[E470]                	mov	bx, valid_ppnums
  1118 000005B1 B104                    	mov	cl, 4
  1119                                  dp_2:
  1120 000005B3 8A4404                  	mov	al, [si+ptFileSystemID]
  1121 000005B6 8807                    	mov	[bx], al
  1122 000005B8 FEC9                    	dec	cl
  1123 000005BA 7406                    	jz	short dp_3
  1124 000005BC 43                      	inc	bx
  1125 000005BD 83C610                  	add	si, 16
  1126 000005C0 EBF1                    	jmp	short dp_2
  1127                                  dp_3:
  1128 000005C2 BE[215D]                	mov	si, msg_enter_pn_to_del
  1129 000005C5 E86D18                  	call	print_msg
  1130                                  dp_getchar1:
  1131 000005C8 30E4                    	xor	ah, ah
  1132 000005CA CD16                    	int	16h
  1133                                  	
  1134                                  	; 19/10/2020
  1135 000005CC 3C1B                    	cmp	al, 27
  1136 000005CE 744E                    	je	short dp_esc
  1137 000005D0 3C30                    	cmp	al, '0'
  1138 000005D2 744A                    	je	short dp_esc
  1139                                  	;cmp	al, '1'
  1140 000005D4 72F2                    	jb	short dp_getchar1
  1141 000005D6 3C34                    	cmp	al, '4'
  1142 000005D8 77EE                    	ja	short dp_getchar1
  1143                                  
  1144                                  	;sub	al, '0'
  1145 000005DA 30FF                    	xor	bh, bh
  1146 000005DC 88C3                    	mov	bl, al
  1147                                  	;dec	bl
  1148 000005DE 80EB31                  	sub	bl, '1'
  1149 000005E1 38BF[E470]              	cmp	byte [bx+valid_ppnums], bh ; 0 ; 12/02/2019
  1150 000005E5 76E1                    	jna	short dp_getchar1  ; Empty partition table entry, it is not shown
  1151                                  	
  1152 000005E7 881E[F170]              	mov	[del_part_num], bl ; Selected partition number to be deleted.
  1153                                  	;add	al, '0'
  1154 000005EB A2[455D]                	mov	[chr_del_pnum1], al ; Partition number for "Enter ..." text
  1155 000005EE A2[E75D]                	mov	[chr_del_pnum2], al ; Partition number for "Do you want ..." text
  1156                                  
  1157 000005F1 BE[455D]                	mov	si, chr_del_pnum1 ; write partition number (user input)
  1158 000005F4 E83E18                  	call	print_msg
  1159                                  
  1160                                  	;xor	al, al
  1161 000005F7 A2[455D]                	mov	[chr_del_pnum1], al ; 0 ; reset
  1162                                  
  1163 000005FA BE[495D]                	mov	si, msg_delete_partition_q ; question for deleting (with warning)
  1164 000005FD E83518                  	call	print_msg
  1165                                  
  1166                                  dp_getchar2:
  1167 00000600 30E4                    	xor	ah, ah
  1168 00000602 CD16                    	int	16h
  1169                                  
  1170 00000604 3C1B                    	cmp	al, 27
  1171 00000606 7416                    	je	short dp_esc
  1172                                  
  1173 00000608 24DF                    	and	al, 0DFh
  1174 0000060A 3C59                    	cmp	al, 'Y'
  1175 0000060C 7418                    	je	short dp_yes
  1176 0000060E 3C4E                    	cmp	al, 'N'
  1177 00000610 75EE                    	jne	short dp_getchar2
  1178                                  dp_no:
  1179 00000612 BE[F95D]                	mov	si, msg_NO ;  Write 'NO' (it may be shown for a moment)
  1180 00000615 E81D18                  	call	print_msg
  1181                                  	
  1182 00000618 BE[5056]                	mov	si, CRLF  ; Next line
  1183 0000061B E81718                  	call	print_msg
  1184                                  	
  1185                                  	;jmp	short dp_esc
  1186                                  
  1187                                  cp_esc:
  1188                                  ap_esc:
  1189                                  wptmbr_esc:
  1190                                  dp_esc:
  1191 0000061E 30C0                    	xor	al, al  ; MBR/PRIMARY PARTITIONS
  1192 00000620 E86A23                  	call	display_partition_table
  1193 00000623 E9A0FD                  	jmp	A_44
  1194                                  
  1195                                  dp_yes:
  1196 00000626 BE[F35D]                	mov	si, msg_YES ;  Write 'YES' (it may be shown for a moment)
  1197 00000629 E80918                  	call	print_msg
  1198                                  
  1199 0000062C BF[E658]                	mov	di, MasterBootBuff+pTableOffset
  1200 0000062F A0[F170]                	mov	al, [del_part_num]
  1201 00000632 20C0                    	and 	al, al
  1202 00000634 7406                    	jz	short dp_4
  1203 00000636 98                      	cbw
  1204                                  	;xor	ah, ah
  1205 00000637 C0E004                  	shl	al, 4 ; * 16
  1206 0000063A 01C7                    	add	di, ax
  1207                                  dp_4:
  1208 0000063C BE[5056]                	mov	si, CRLF ; Next line	
  1209 0000063F E8F317                  	call	print_msg
  1210                                  
  1211                                  	; 27/02/2019
  1212 00000642 807D0405                	cmp	byte [di+ptFileSystemID], 5
  1213 00000646 7547                    	jne	short dp_5
  1214                                  
  1215 00000648 3806[D06E]              	cmp	byte [ldrives], al ; 0
  1216 0000064C 7641                    	jna	short dp_5
  1217                                  
  1218 0000064E BE[0F61]                	mov	si, msg_ext_part_del_error	
  1219 00000651 E8E117                  	call	print_msg
  1220 00000654 BE[4F61]                	mov	si, msg_cancel_continue
  1221 00000657 E8DB17                  	call	print_msg
  1222                                       	
  1223 0000065A 30E4                    	xor	ah, ah
  1224 0000065C CD16                    	int	16h
  1225                                  	
  1226 0000065E 3C1B                    	cmp	al, 27 ; ESCape
  1227 00000660 74BC                    	je	short dp_esc
  1228                                  
  1229 00000662 E8672B                  	call	delete_logical_drives
  1230                                  	
  1231                                  	; 28/02/2019
  1232 00000665 803E[D06E]01            	cmp	byte [ldrives], 1
  1233 0000066A 73B2                    	jnb	short dp_esc
  1234                                  
  1235 0000066C 30C0                    	xor	al, al  ; MBR/PRIMARY PARTITIONS
  1236 0000066E E81C23                  	call	display_partition_table
  1237                                  
  1238 00000671 BE[E261]                	mov	si, msg_delete_ext_part
  1239 00000674 E8BE17                  	call	print_msg
  1240                                  
  1241                                  dp_ask_again:
  1242 00000677 28E4                    	sub	ah, ah
  1243 00000679 CD16                    	int	16h
  1244                                  
  1245 0000067B 3C1B                    	cmp	al, 27 ; ESCape
  1246 0000067D 749F                    	je	short dp_esc	
  1247                                  
  1248 0000067F 3C0D                    	cmp	al, 13 ; ENTER/CR
  1249 00000681 75F4                    	jne	short dp_ask_again
  1250                                  
  1251 00000683 BF[E658]                	mov	di, MasterBootBuff+pTableOffset
  1252 00000686 A0[F170]                	mov	al, [del_part_num]
  1253 00000689 98                      	cbw
  1254 0000068A C0E004                  	shl	al, 4 ; * 16
  1255 0000068D 01C7                    	add	di, ax
  1256                                  dp_5:
  1257 0000068F 31C0                    	xor	ax, ax
  1258                                  
  1259                                  	; clear partition table entry in MBR buffer
  1260 00000691 B90800                  	mov	cx, 8
  1261 00000694 F3AB                    	rep	stosw
  1262                                  	
  1263                                  	; NOTE: Only the MBR buffer will be cleared
  1264                                  	; (Masterboot sector will not be updated unless/till
  1265                                  	;  MBR partition table -and MBR code- will be written
  1266                                  	;  to disk image as result of 'write part. table' command.)
  1267                                  
  1268 00000696 E9A1FB                  	jmp	A_27 ; 08/03/2019
  1269                                   	 
  1270                                  ;-----------------------------------------------------------------------------
  1271                                  
  1272                                  write_pt_mbr:
  1273                                  	; 11/02/2019
  1274 00000699 30C0                    	xor	al, al  ; MBR/PRIMARY PARTITIONS
  1275 0000069B E8EF22                  	call	display_partition_table
  1276                                  
  1277 0000069E BE[FD5D]                	mov	si, msg_write_masterboot_sector
  1278 000006A1 E89117                  	call	print_msg
  1279                                  
  1280 000006A4 A2[C06E]                	mov	[GetChar], al ; 0
  1281                                  
  1282 000006A7 BE[E05E]                	mov	si, option_input
  1283 000006AA E88817                  	call	print_msg
  1284                                  
  1285 000006AD B403                    	mov	ah, 3
  1286                                  	;mov	bx, 7
  1287 000006AF CD10                    	int	10h ; Return Cursor Position
  1288                                  	; DL = Column
  1289                                  	
  1290 000006B1 FECA                    	dec	dl ; previous char ; ']'
  1291 000006B3 FECA                    	dec	dl ; previous char ; '[ ]'
  1292                                  
  1293 000006B5 B402                    	mov	ah, 2
  1294                                  	;mov	bx, 7
  1295 000006B7 CD10                    	int	10h ; Set Cursor Position
  1296                                  
  1297                                  	; write char at current cursor position
  1298                                  
  1299 000006B9 B030                    	mov	al, '0' ; Write default char
  1300                                  
  1301                                  	;;mov	bx, 07h
  1302 000006BB B409                    	mov	ah, 09h
  1303 000006BD B90100                  	mov	cx, 1
  1304 000006C0 CD10                    	int	10h
  1305                                  
  1306                                  wptmbr_getchar:
  1307 000006C2 30E4                    	xor	ah, ah              
  1308 000006C4 CD16                    	int	16h
  1309                                  
  1310 000006C6 3C1B                    	cmp	al, 1Bh ; 27
  1311 000006C8 0F8452FF                	je	wptmbr_esc ; 19/10/2020
  1312                                  
  1313 000006CC 3C0D                    	cmp	al, 0Dh ; 13
  1314 000006CE 7414                    	je	short wptmbr_1
  1315                                                  
  1316 000006D0 3C31                    	cmp	al, '1'
  1317 000006D2 72EE                    	jb	short wptmbr_getchar
  1318                                  
  1319 000006D4 3C32                    	cmp	al, '2'
  1320 000006D6 77EA                    	ja 	short wptmbr_getchar
  1321                                  
  1322 000006D8 A2[C06E]                	mov	[GetChar], al
  1323                                  
  1324                                  	;;mov	bx, 07h
  1325 000006DB B409                    	mov	ah, 09h
  1326 000006DD B90100                  	mov	cx, 1
  1327 000006E0 CD10                    	int	10h
  1328 000006E2 EBDE                    	jmp	short wptmbr_getchar
  1329                                  
  1330                                  wptmbr_1:
  1331 000006E4 803E[C06E]00            	cmp	byte [GetChar], 0
  1332 000006E9 76D7                    	jna	short wptmbr_getchar
  1333                                  
  1334 000006EB BE[AE5E]                	mov	si, msg_writing_ptable
  1335 000006EE E84417                  	call	print_msg
  1336                                  
  1337 000006F1 803E[C06E]32            	cmp	byte [GetChar], '2'
  1338 000006F6 7471                    	je	short wptmbr_5
  1339                                  
  1340                                  wptmbr_2:
  1341                                  	; this may not be needed here (?)
  1342                                  	; ('seek' file pointer is needed flag)
  1343 000006F8 C606[9C40]01            	mov 	byte [random], 1
  1344                                  
  1345 000006FD 833E[9440]00            	cmp	word [img_file_handle], 0
  1346 00000702 7713                    	ja	short wptmbr_3
  1347                                  
  1348                                  	; Open disk image file again.
  1349                                  
  1350 00000704 FE0E[9C40]              	dec	byte [random] ; 0 ; masteeboot sector will be written		 
  1351                                  			  	  ; no need to seek file pointer
  1352                                  
  1353 00000708 BA[8159]                	mov	dx, img_file_name
  1354 0000070B B8023D                  	mov	ax, 3D02h ; open file for reading and writing
  1355 0000070E CD21                    	int	21h
  1356 00000710 0F820B17                	jc	D_02
  1357                                  
  1358 00000714 A3[9440]                	mov	[img_file_handle], ax
  1359                                  wptmbr_3:
  1360 00000717 31C0                    	xor	ax, ax ; 0
  1361 00000719 31D2                    	xor	dx, dx ; 0
  1362                                  	; DX_AX = Masterboot Sector = 0
  1363 0000071B BB[2857]                	mov	bx, MasterBootBuff
  1364                                  	; ES:BX = Sector Buffer
  1365 0000071E E82317                  	call	write_hd_sector
  1366 00000721 0F82F016                	jc	D_01 ; ! display error msg and then exit !
  1367                                  
  1368 00000725 BE[D75E]                	mov	si, _msg_OK
  1369 00000728 E80A17                  	call	print_msg
  1370                                  
  1371 0000072B 803E[9C40]00            	cmp	byte [random], 0
  1372 00000730 7712                    	ja	short wptmbr_4
  1373                                  
  1374                                  	;mov	byte [random], 1
  1375                                  
  1376 00000732 8B1E[9440]              	mov	bx, [img_file_handle]
  1377 00000736 B43E                    	mov	ah, 3Eh ; close file
  1378 00000738 CD21                    	int	21h
  1379 0000073A 0F82E116                	jc	D_02
  1380                                  
  1381 0000073E C706[9440]0000          	mov	word [img_file_handle], 0
  1382                                  
  1383                                  wptmbr_4:
  1384                                  	; wait for 1 second
  1385 00000744 B402                    	mov	ah, 02h
  1386 00000746 CD1A                    	int	1Ah
  1387 00000748 8836[C06E]              	mov	[GetChar], dh
  1388                                  wptmbr_wait:
  1389 0000074C B402                    	mov	ah, 02h
  1390 0000074E CD1A                    	int	1Ah
  1391 00000750 3A36[C06E]              	cmp	dh, [GetChar]
  1392 00000754 74F6                    	je	short wptmbr_wait
  1393                                  	
  1394 00000756 BE[0957]                	mov	si, msg_press_any_key
  1395 00000759 E8D916                  	call	print_msg
  1396                                                  
  1397 0000075C 30E4                    	xor	ah, ah	; "Press any key to continue"
  1398 0000075E CD16                    	int	16h
  1399                                  
  1400 00000760 BE[5056]                	mov	si, CRLF
  1401 00000763 E8CF16                  	call	print_msg
  1402                                  
  1403 00000766 E9B5FE                  	jmp	wptmbr_esc
  1404                                  
  1405                                  wptmbr_5:
  1406 00000769 BE[8232]                	mov	si, TRDOS386_MASTERBOOT_SECTOR
  1407 0000076C B9DF00                  	mov	cx, 446/2 ; Copy Singlix FS 1 MBR code
  1408                                  			  ; except Partition Table
  1409 0000076F BF[2857]                	mov	di, MasterBootBuff
  1410 00000772 F3A5                    	rep	movsw
  1411                                  	
  1412                                  	; This (Below) is not needed; because, if MBR magicword
  1413                                  	; would not be 0AA55h, we would not be able to come here!
  1414                                  	;;add	di, 64  ; skip partition table	
  1415                                  	;;mov	ax, 0AA55h
  1416                                  	;;stosw
  1417                                  	;mov 	word [MBIDCode], 0AA55h
  1418                                  
  1419                                  	; 12/02/2019
  1420                                  	; Copy CHS parameters to Singlix MBR (on disk)
  1421                                  	
  1422 00000774 BF[CC58]                	mov	di, MasterBootBuff+420
  1423                                  
  1424 00000777 A1[9A40]                	mov	ax, [cylinders]
  1425 0000077A AB                      	stosw 			; cylinders
  1426 0000077B A1[9840]                	mov	ax, [heads]
  1427 0000077E AB                      	stosw 			; heads
  1428 0000077F A1[9640]                	mov	ax, [sectors]
  1429 00000782 AB                      	stosw 			; sectors
  1430                                  
  1431 00000783 E972FF                  	jmp	wptmbr_2
  1432                                  
  1433                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1434                                  ; Nextline & Exit
  1435                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1436                                  ; 25/02/2019
  1437                                  
  1438                                  B_01:
  1439 00000786 BE[9A44]                	mov	si, TrDOS_Welcome
  1440 00000789 E8A916                  	call	print_msg
  1441                                  B_02:
  1442 0000078C BE[5056]                	mov	si, CRLF
  1443                                  B_03:
  1444 0000078F E8A316                  	call	print_msg
  1445 00000792 B8004C                  	mov	ax, 4C00h		; terminate
  1446 00000795 CD21                    	int	21h
  1447                                  B_04:
  1448 00000797 BE[5545]                	mov	si, msg_inv_image_file
  1449 0000079A EBF3                    	jmp	short B_03 ; 03/10/2020 (short jump)
  1450                                  
  1451                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1452                                  ; Display create partition menu & get partition type input
  1453                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1454                                  
  1455                                  create_partition_input:
  1456                                  	; 15/02/2019
  1457                                  	; clear screen
  1458 0000079C B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
  1459 0000079F CD10                    	int	10h
  1460                                  	
  1461 000007A1 BE[4A46]                	mov	si, msg_create_partition_h ; header
  1462 000007A4 E88E16                  	call	print_msg
  1463 000007A7 BE[3F47]                	mov	si, msg_create_partition_m ; menu
  1464 000007AA E88816                  	call	print_msg
  1465                                  cpi_1:
  1466 000007AD 30E4                    	xor	ah, ah
  1467 000007AF CD16                    	int	16h
  1468 000007B1 3C1B                    	cmp	al, 27 ; ESC key	
  1469                                  	;;je	B_47
  1470                                  	;je	A_48 ; A_33
  1471 000007B3 7445                    	je	short cpi_4  ; 25/02/2019
  1472 000007B5 3C30                    	cmp	al, '0'
  1473                                  	;;je	B_47
  1474                                  	;je	A_48 ; A_33
  1475 000007B7 7441                    	je	short cpi_4  ; 25/02/2019
  1476 000007B9 72F2                    	jb	short cpi_1
  1477 000007BB 3C34                    	cmp	al, '4'
  1478 000007BD 77EE                    	ja	short cpi_1
  1479                                  
  1480 000007BF 30E4                    	xor	ah, ah
  1481 000007C1 2C30                    	sub	al, '0'
  1482                                  
  1483                                  	;mov	[pp_type], al
  1484                                  
  1485                                  	;mov	byte [pp_type_user], 0
  1486                                  
  1487 000007C3 3C01                    	cmp	al, 1 ; DOS partition
  1488 000007C5 7536                    	jne	short cpi_5 ; ah = 0 
  1489                                  			    ; (al = 2 -> singlix, al = 3 -> retro unix)
  1490                                  cpi_2:
  1491                                  	; clear screen
  1492 000007C7 B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
  1493 000007CA CD10                    	int	10h
  1494                                  	
  1495 000007CC BE[F548]                	mov	si, msg_create_dos_partition_h ; header
  1496 000007CF E86316                  	call	print_msg
  1497 000007D2 BE[C94C]                	mov	si, msg_create_dos_partition_m ; menu
  1498 000007D5 E85D16                  	call	print_msg
  1499                                  cpi_3:
  1500 000007D8 30E4                    	xor	ah, ah
  1501 000007DA CD16                    	int	16h
  1502 000007DC 3C1B                    	cmp	al, 27 ; ESC key	
  1503                                  	;je	short B_47
  1504 000007DE 741A                    	je	short cpi_4
  1505 000007E0 3C30                    	cmp	al, '0'
  1506                                  	;je	short B_47
  1507 000007E2 7416                    	je	short cpi_4
  1508 000007E4 72F2                    	jb	short cpi_3
  1509 000007E6 3C33                    	cmp	al, '3'
  1510 000007E8 77EE                    	ja	short cpi_3
  1511                                  	
  1512 000007EA 30E4                    	xor	ah, ah
  1513 000007EC 2C30                    	sub	al, '0'
  1514 000007EE 3C01                    	cmp	al, 1
  1515 000007F0 7420                    	je	short cpi_6  ;	ah = 0 (al = primary dos partition)
  1516                                  
  1517                                  	;mov	byte [pp_type], 5
  1518                                  
  1519 000007F2 3C02                    	cmp	al, 2
  1520 000007F4 761D                    	jna	short cpi_7
  1521                                  
  1522 000007F6 B80600                  	mov	ax, 6	; ah = 0 (al = logical dos drive/partition)
  1523 000007F9 C3                      	retn
  1524                                  
  1525                                  cpi_4:
  1526 000007FA 31C0                    	xor	ax, ax	; ah = 0 (al = 0 -> ESCape/Cancel)
  1527 000007FC C3                      	retn
  1528                                  cpi_5:
  1529 000007FD 3C04                    	cmp	al, 4	 ; option num. for partition type (user) input
  1530 000007FF 7511                    	jne	short cpi_6
  1531                                  
  1532 00000801 E84F1A                  	call	partition_type_input
  1533                                  
  1534 00000804 B404                    	mov	ah, 4 ; user/another type partition flag
  1535                                  	; al = Partition ID	
  1536 00000806 50                      	push	ax
  1537 00000807 BE[0957]                	mov	si, msg_press_any_key 
  1538 0000080A E82816                  	call	print_msg
  1539 0000080D 28E4                    	sub	ah, ah
  1540 0000080F CD16                    	int	16h
  1541 00000811 58                      	pop	ax
  1542                                  cpi_6:
  1543 00000812 C3                      	retn
  1544                                  cpi_7:
  1545 00000813 B80500                  	mov	ax, 5	; ah = 0 (al = extended dos partition)
  1546 00000816 C3                      	retn
  1547                                  
  1548                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1549                                  ; Create primary (dos or non-dos) partition
  1550                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1551                                  ; 16/02/2019 
  1552                                  ;	(This procedure must be called after 'find_part_free_space')
  1553                                  
  1554                                  create_primary_partition:  
  1555                                  	; 16/02/2019
  1556                                  
  1557                                  	; INPUT:
  1558                                  	;	none 
  1559                                  	;  (CHS parameters and free space calculation result will be used.) 
  1560                                  	;
  1561                                  	; OUTPUT:
  1562                                  	;	Partition table in MBR buffer will be updated.
  1563                                  	;
  1564                                  	; (Modified registers: ax, bx, cx, dx, si, di)
  1565                                  
  1566                                  	; Create primary dos or non-dos partition,
  1567                                  	; make partition table entry
  1568                                  
  1569 00000817 803E[9D40]00            	cmp	byte [newdisk], 0
  1570 0000081C 760A                    	jna	short cpp_0
  1571                                  
  1572                                  	; cylinder = 0, head = 1, sector = 1
  1573                                  	; LBA = (((cylinder*heads)+head)*sectors)+sector-1
  1574                                  
  1575 0000081E BE[E658]                	mov	si, MasterBootBuff+pTableOffset
  1576                                  
  1577 00000821 A1[9640]                	mov	ax, [sectors] ; LBA = 17 or 63
  1578 00000824 31D2                    	xor	dx, dx
  1579 00000826 EB56                    	jmp	short cpp_4
  1580                                  cpp_0:
  1581                                  	; 16/02/2019
  1582 00000828 E81B21                  	call	get_first_free_pte
  1583                                  		 ; CX = First free PTE number, 0 to 3 
  1584                                  		 ;    (CX = 3 if there is not a free PTE, and CF = 1)
  1585                                  		 ;    ((But CF = 1 is not possible here because pcount < 4))
  1586                                   	 	 ; SI = PTE address/offset in MBR buffer
  1587                                  
  1588                                  	;mov	si, MasterBootBuff+pTableOffset
  1589                                  	;shl	cl, 4 ; * 16
  1590                                  	;add	si, cx
  1591                                  
  1592                                  	; 18/02/2019
  1593 0000082B 8B3E[2C72]              	mov	di, [c_fspc_offset]
  1594 0000082F 8B9D[DC71]              	mov	bx, [di+free_space.start]
  1595 00000833 A0[9840]                	mov	al, [heads]
  1596 00000836 F626[9640]              	mul	byte [sectors]
  1597 0000083A F7E3                    	mul	bx
  1598                                  		; DX:AX = LBA of start cylinder, head 0, sector 1
  1599                                  	
  1600 0000083C 8A0E[2E72]              	mov	cl, [cylinder_boundary]
  1601                                  
  1602                                  	;cmp	cl, 0 ; Default (partition size unit is one of C, G, M)
  1603                                  		      ; boundary alignment is forced as default
  1604                                  	;je	short cpp_4
  1605                                  
  1606                                  	; 20/02/2019
  1607                                  	;and	cl, cl
  1608                                  	;jz 	short cpp_1
  1609                                  
  1610 00000840 80F959                  	cmp	cl, 'Y'
  1611 00000843 7439                    	je	short cpp_4 ; cylinder boundary option (answer) = YES
  1612                                  
  1613 00000845 80F94E                  	cmp	cl, 'N'
  1614 00000848 750A                    	jne	short cpp_1 ; cylinder boundary option (answer) = YES/NO
  1615                                  
  1616                                  	; cylinder boundary option (answer) = NO 
  1617 0000084A 8B85[E671]              	mov	ax, [di+free_space.startsector]
  1618 0000084E 8B95[E871]              	mov	dx, [di+free_space.startsector+2]
  1619 00000852 EB2A                    	jmp	short cpp_4
  1620                                  cpp_1:
  1621                                  	;cmp	cl, 27 ; ESCape
  1622                                  	;jne	short cpp_4 ; 'Y'
  1623                                  
  1624                                  	; check	cylinder boundary alignment of the start sector
  1625                                  
  1626                                  	; if start sector is not aligned, end sector must not be aligned
  1627                                  	; (this rule is valid for ESCape key from the user) 
  1628                                  
  1629 00000854 C606[2E72]59            	mov	byte [cylinder_boundary], 'Y' ; YES for end sector check
  1630                                  
  1631 00000859 8B8D[E671]              	mov	cx, [di+free_space.startsector]
  1632                                  
  1633 0000085D 09DB                    	or	bx, bx
  1634                                  
  1635 0000085F 8B9D[E871]              	mov	bx, [di+free_space.startsector+2]
  1636                                  
  1637 00000863 7508                    	jnz	short cpp_2 ; start cylinder > 0
  1638                                  
  1639                                  	;and	bx, bx
  1640                                  	;jnz	short cpp_3
  1641                                  
  1642 00000865 3B0E[9640]              	cmp	cx, [sectors]
  1643 00000869 7413                    	je	short cpp_4 ; start sector is as aligned 
  1644 0000086B EB08                    	jmp	short cpp_3
  1645                                  cpp_2:
  1646 0000086D 39C8                    	cmp	ax, cx
  1647 0000086F 7504                    	jne	short cpp_3
  1648 00000871 39DA                    	cmp	dx, bx
  1649 00000873 7409                    	je	short cpp_4 
  1650                                  cpp_3:
  1651 00000875 89C8                    	mov	ax, cx
  1652 00000877 89DA                    	mov	dx, bx
  1653 00000879 C606[2E72]4E            	mov	byte [cylinder_boundary], 'N'
  1654                                  cpp_4:
  1655 0000087E 894408                  	mov	[si+ptStartSector], ax
  1656 00000881 89540A                  	mov	[si+ptStartSector+2], dx
  1657                                  
  1658                                  	; save start sector (for partition formatting procedure)
  1659 00000884 A3[946E]                	mov	[pp_StartSector], ax
  1660 00000887 8916[966E]              	mov	[pp_StartSector+2], dx
  1661                                  
  1662 0000088B 803E[9D40]00            	cmp	byte [newdisk], 0
  1663 00000890 763F                    	jna	short cpp_5
  1664                                  
  1665 00000892 31C9                    	xor	cx, cx
  1666 00000894 894C03                  	mov	[si+ptBeginCylinder], cx ; 0
  1667 00000897 FEC1                    	inc	cl  ; 1
  1668 00000899 884C02                  	mov	[si+ptBeginSector], cl ; 1
  1669 0000089C 884C01                  	mov	[si+ptBeginHead], cl ; 1
  1670                                  
  1671                                  	; set active partition flag
  1672                                  	;mov	byte [si+ptBootable], 80h ; bootable/active partition
  1673 0000089F C60480                  	mov	byte [si], 80h ; bootable/active partition
  1674                                  
  1675                                  	; 18/02/2019
  1676                                  
  1677 000008A2 8B0E[C86E]              	mov	cx, [ppn_Sectors]
  1678 000008A6 8B1E[CA6E]              	mov	bx, [ppn_Sectors+2]
  1679                                  
  1680 000008AA 803E[9C6E]00            	cmp	byte [wholedisk], 0
  1681 000008AF 0F86FE00                	jna	cpp_12
  1682                                  
  1683 000008B3 A0[9840]                	mov	al, [heads]
  1684 000008B6 FEC8                    	dec	al
  1685 000008B8 884405                  	mov	[si+ptEndHead], al
  1686 000008BB A0[9640]                	mov	al, [sectors]
  1687 000008BE 884406                  	mov	[si+ptEndSector], al
  1688 000008C1 A1[9A40]                	mov	ax, [cylinders]
  1689 000008C4 48                      	dec	ax
  1690 000008C5 884407                  	mov	[si+ptEndCylinder], al
  1691 000008C8 C0E406                  	shl	ah, 6
  1692 000008CB 086406                  	or	[si+ptEndSector], ah		
  1693                                  
  1694                                  	;jmp	cpp_16
  1695 000008CE E95501                  	jmp	cpp_15 ; 06/03/2019	
  1696                                  cpp_5:
  1697                                  	; 18/02/2019
  1698                                  		
  1699 000008D1 803E[2E72]59            	cmp	byte [cylinder_boundary], 'Y'
  1700 000008D6 7525                    	jne	short cpp_7
  1701                                  
  1702 000008D8 30DB                    	xor	bl, bl ; head  = 0
  1703                                  
  1704 000008DA 8B8D[DC71]              	mov	cx, [di+free_space.start]
  1705                                  
  1706                                  	; 06/03/2019
  1707                                  	;or	ax, ax
  1708                                  	;jnz	short cpp_6
  1709                                  
  1710                                  	;and	cx, cx  ; start cylinder = 0 ?
  1711                                  	;jnz	short cpp_6
  1712                                  
  1713 000008DE 09C8                    	or	ax, cx
  1714 000008E0 7513                    	jnz	short cpp_6
  1715                                  
  1716 000008E2 A1[9640]                	mov	ax, [sectors]
  1717                                  	
  1718 000008E5 894408                  	mov	[si+ptStartSector], ax
  1719                                  	;mov	[si+ptStartSector+2], cx ; 0
  1720                                  
  1721 000008E8 A3[946E]                	mov	[pp_StartSector], ax
  1722                                  	;mov	[pp_StartSector+2], cx
  1723                                  
  1724 000008EB 2906[986E]              	sub	[pp_Sectors], ax
  1725 000008EF 190E[9A6E]              	sbb	[pp_Sectors+2], cx ; 0	
  1726                                  	
  1727                                  	; cylinder 0, head 1, sector 1 (LBA = 17 or 63)
  1728 000008F3 FEC3                    	inc	bl  ; head = 1
  1729                                  cpp_6:
  1730 000008F5 89C8                    	mov	ax, cx
  1731 000008F7 C6440201                	mov	byte [si+ptBeginSector], 1 ; sector = 1		
  1732 000008FB EB16                    	jmp	short cpp_8		
  1733                                  cpp_7:
  1734                                  	; 18/02/2019
  1735                                  
  1736                                  	; [wholedisk] = 0
  1737                                  
  1738                                  	; Fix partition size for MSDOS 3.3 (Retro DOS 3.0) compatibility.
  1739                                  	; (DOS partition size will be changed -down- to 65535 sectors,
  1740                                  	; if it is 65536 sectors.)
  1741                                  	
  1742 000008FD E83601                  	call	fix_32mb_dos_psize
  1743                                  
  1744                                  	;cylinder = LBA / (heads_per_cylinder * sectors_per_track)
  1745                                  	;temp = LBA % (heads_per_cylinder * sectors_per_track)
  1746                                  	;head = temp / sectors_per_track
  1747                                  	;sector = temp % sectors_per_track + 1
  1748                                  	
  1749                                  	; Convert LBA sector address to CHS parameters
  1750 00000900 8B0E[9640]              	mov	cx, [sectors]
  1751 00000904 E82F05                  	call	div32
  1752                                  	; BX = Sector number - 1
  1753 00000907 FEC3                    	inc	bl ; sector number (1 based)
  1754 00000909 885C02                  	mov	[si+ptBeginSector], bl	
  1755                                  	; DX_AX = cylinders * heads + head
  1756 0000090C 8B0E[9840]              	mov	cx, [heads]
  1757 00000910 E82305                  	call	div32
  1758                                  cpp_8:
  1759                                  	; BX = Head number
  1760 00000913 885C01                  	mov	[si+ptBeginHead], bl
  1761                                  	; AX = Cylinder number
  1762                                  	;and	ax, 1023
  1763 00000916 884403                  	mov	[si+ptBeginCylinder], al
  1764 00000919 C0E406                  	shl	ah, 6
  1765 0000091C 086402                  	or	[si+ptBeginSector], ah
  1766                                  
  1767                                  	; clear active partition flag (for now)
  1768                                  	;mov	byte [si+ptBootable], 0 ; not bootable/active partition
  1769 0000091F C60400                  	mov	byte [si], 0 ; not bootable/active partition
  1770                                  
  1771                                  	;mov	di, [c_fspc_offset]
  1772                                  
  1773 00000922 803E[2E72]59            	cmp	byte [cylinder_boundary], 'Y'
  1774 00000927 7579                    	jne	short cpp_11
  1775                                  
  1776 00000929 8A0E[9840]              	mov	cl, [heads]
  1777 0000092D A0[9640]                	mov	al, [sectors]
  1778 00000930 88C5                    	mov	ch, al
  1779 00000932 F6E1                    	mul	cl	
  1780                                  	; ax = heads*sectors
  1781                                  
  1782 00000934 8B9D[DE71]              	mov	bx, [di+free_space.end]  ; end cylinder of the partition
  1783                                  
  1784 00000938 803E[9C6E]00            	cmp	byte [wholedisk], 0 ; entire free space ?
  1785 0000093D 7726                    	ja	short cpp_10
  1786                                  
  1787 0000093F 89C3                    	mov	bx, ax
  1788 00000941 A1[C86E]                	mov	ax, [ppn_Sectors]
  1789 00000944 8B16[CA6E]              	mov	dx, [ppn_Sectors+2]
  1790 00000948 0306[946E]              	add	ax, [pp_StartSector]
  1791 0000094C 1316[966E]              	adc	dx, [pp_StartSector+2]
  1792 00000950 83E801                  	sub	ax, 1
  1793 00000953 83DA00                  	sbb	dx, 0
  1794                                  		; dx:ax = end sector
  1795 00000956 F7F3                    	div	bx
  1796                                  		; ax = cylinder count
  1797 00000958 21D2                    	and	dx, dx
  1798 0000095A 7401                    	jz	short cpp_9
  1799 0000095C 40                      	inc	ax ; + 1 (because of remainder > 0)
  1800                                  cpp_9:	
  1801 0000095D 93                      	xchg	ax, bx
  1802                                  		; bx = end cylinder
  1803                                  		; ax = heads*sectors
  1804                                  	; free space limit check
  1805 0000095E 3B9D[DE71]              	cmp	bx, [di+free_space.end]
  1806 00000962 7601                    	jna	short cpp_10 ; ok
  1807                                  	; end cylinder is out of free space	
  1808 00000964 4B                      	dec	bx  ; decrease end cylinder number
  1809                                  cpp_10: 
  1810 00000965 F7E3                    	mul	bx
  1811                                  		 ; dx:ax = (end cylinder)*heads*sectors
  1812 00000967 52                      	push	dx ; **
  1813 00000968 50                      	push	ax ; *
  1814 00000969 FEC9                    	dec	cl ; heads - 1 = end head
  1815                                  
  1816 0000096B 884C05                  	mov	[si+ptEndHead], cl
  1817                                  		
  1818                                  	;mov	al, [sectors]
  1819 0000096E 88E8                    	mov	al, ch
  1820 00000970 885C07                  	mov	[si+ptEndCylinder], bl
  1821 00000973 88C3                    	mov	bl, al
  1822 00000975 C0E706                  	shl	bh, 6 ; shift high bytes (2 bits) of end cyl num
  1823                                  		      ; to 6 bits left	
  1824 00000978 08DF                    	or	bh, bl ; combine high bits of end cyl num and end sector		
  1825 0000097A 887C06                  	mov	[si+ptEndSector], bh
  1826 0000097D 30FF                    	xor	bh, bh ; clear bh
  1827 0000097F FECB                    	dec	bl ; sectors - 1 ; 22/02/2019
  1828 00000981 F6E1                    	mul	cl
  1829 00000983 5A                      	pop	dx ; *
  1830                                  	; 22/02/2019
  1831 00000984 31C9                    	xor	cx, cx
  1832 00000986 01D0                    	add	ax, dx
  1833 00000988 5A                      	pop	dx ; **
  1834 00000989 11CA                    	adc	dx, cx ; 0
  1835 0000098B 01D8                    	add	ax, bx
  1836 0000098D 11CA                    	adc	dx, cx ; 0
  1837                                  	; dx:ax = ((([end cylinder]*heads)+[end head])*sectors)+sectors-1
  1838                                  
  1839                                  	; calculate aligned partition size in sectors
  1840 0000098F 89C1                    	mov	cx, ax
  1841 00000991 89D3                    	mov	bx, dx
  1842 00000993 83C101                  	add	cx, 1
  1843 00000996 83D300                  	adc	bx, 0	
  1844 00000999 2B4C08                  	sub	cx, [si+ptStartSector]
  1845 0000099C 1B5C0A                  	sbb	bx, [si+ptStartSector+2]
  1846                                  		; bx:cx = partition size
  1847                                  	;mov	[ppn_Sectors], cx
  1848                                  	;mov	[ppn_Sectors+2], bx
  1849                                  	;jmp	cpp_16
  1850 0000099F E98400                  	jmp	cpp_15 ; 06/03/2019
  1851                                  cpp_11:
  1852                                  	; 20/02/2019
  1853 000009A2 8B0E[C86E]              	mov	cx, [ppn_Sectors]
  1854 000009A6 8B1E[CA6E]              	mov	bx, [ppn_Sectors+2]
  1855                                  
  1856                                  	;;mov	ax, [di+free_space.startsector]
  1857                                  	;;mov	ax, [di+free_space.startsector+2]
  1858                                  	;mov	ax, [si+ptStartSector]
  1859                                  	;mov	dx, [si+ptStartSector+2]
  1860 000009AA A1[946E]                	mov	ax, [pp_StartSector]
  1861 000009AD 8B16[966E]              	mov	dx, [pp_StartSector+2]
  1862                                  cpp_12:	
  1863                                  	; 18/02/2019
  1864                                  
  1865                                  	; [wholedisk] = 0
  1866                                  
  1867                                  	; Fix partition size for MSDOS 3.3 (Retro DOS 3.0) compatibility.
  1868                                  	; (DOS partition size will be changed -down- to 65535 sectors,
  1869                                  	; if it is 65536 sectors.)
  1870                                  
  1871 000009B1 E88200                  	call	fix_32mb_dos_psize
  1872                                  
  1873 000009B4 01C8                    	add	ax, cx
  1874 000009B6 11DA                    	adc	dx, bx
  1875                                  
  1876                                  	; Convert LBA sector address to CHS parameters
  1877 000009B8 83E801                  	sub	ax, 1 ; locate on to end sector of the partition
  1878 000009BB 83DA00                  	sbb	dx, 0
  1879                                  	
  1880                                  	; 06/03/2019
  1881 000009BE 803E[2E72]59            	cmp	byte [cylinder_boundary],'Y'
  1882                                  	;jne	short cpp_15
  1883 000009C3 753A                    	jne	short cpp_14
  1884                                  
  1885 000009C5 89C1                    	mov	cx, ax
  1886 000009C7 A0[9840]                	mov	al, [heads]
  1887 000009CA F626[9640]              	mul	byte [sectors]
  1888 000009CE 89C7                    	mov	di, ax ; [heads]*[sectors]
  1889 000009D0 91                      	xchg	ax, cx
  1890                                  		; cx = heads*spt
  1891 000009D1 E86204                  	call	div32
  1892                                  		; dx = 0
  1893                                  		; ax = end cylinder
  1894                                  		; bx = remainder	
  1895                                  	;and	bx, bx
  1896                                  	;jz	short cpp_13
  1897                                  	;inc	ax
  1898                                  ;cpp_13:
  1899                                  	;cmp	ax, [cylinders]
  1900                                  	;jb	short cpp_14
  1901                                  	;dec	ax
  1902                                  ;cpp_14:
  1903 000009D4 8B1E[9840]              	mov	bx, [heads]
  1904 000009D8 FECB                    	dec	bl
  1905 000009DA 885C05                  	mov	[si+ptEndHead], bl
  1906 000009DD 8B0E[9640]              	mov	cx, [sectors]
  1907 000009E1 88E2                    	mov	dl, ah
  1908 000009E3 C0E206                  	shl	dl, 6
  1909 000009E6 08CA                    	or	dl, cl
  1910 000009E8 885406                  	mov	[si+ptEndSector], dl
  1911 000009EB 884407                  	mov	[si+ptEndCylinder], al	
  1912                                  	;mul	di ; [cylinders]*[heads]*[sectors]
  1913                                  	;;sub	di, cx ; ([heads] - 1) * [sectors]
  1914                                  	;add	ax, di
  1915                                  	;adc	dx, 0
  1916                                  	;;add	ax, cx
  1917                                  	;;adc	dx, 0
  1918 000009EE 40                      	inc	ax
  1919 000009EF F7E7                    	mul	di  ; result = start LBA of next cylinder
  1920                                  	; dx:ax = end sector LBA + 1 (as cyl. boundary aligned)
  1921 000009F1 2B06[946E]              	sub	ax, [pp_StartSector]
  1922 000009F5 1B16[966E]              	sbb	dx, [pp_StartSector+2] ; 26/10/2020
  1923                                  
  1924 000009F9 89C1                    	mov	cx, ax
  1925 000009FB 89D3                    	mov	bx, dx
  1926                                  	;jmp	short cpp_16
  1927 000009FD EB27                    	jmp	short cpp_15
  1928                                  ;cpp_15:
  1929                                  cpp_14:
  1930 000009FF 8B0E[9640]              	mov	cx, [sectors]
  1931 00000A03 E83004                  	call	div32
  1932                                  	; BX = Sector number - 1
  1933 00000A06 FEC3                    	inc	bl ; sector number (1 based)
  1934 00000A08 885C06                  	mov	[si+ptEndSector], bl	
  1935                                  	; DX_AX = cylinders * heads + head
  1936 00000A0B 8B0E[9840]              	mov	cx, [heads]
  1937 00000A0F E82404                  	call	div32
  1938                                  	; BX = Head number
  1939 00000A12 885C05                  	mov	[si+ptEndHead], bl
  1940                                  	; AX = Cylinder number
  1941                                  	;and	ax, 1023
  1942 00000A15 884407                  	mov	[si+ptEndCylinder], al
  1943                                  	; 18/02/2019
  1944 00000A18 C0E406                  	shl	ah, 6
  1945 00000A1B 086406                  	or	[si+ptEndSector], ah
  1946                                  
  1947 00000A1E 8B0E[C86E]              	mov	cx, [ppn_Sectors]
  1948 00000A22 8B1E[CA6E]              	mov	bx, [ppn_Sectors+2]
  1949                                  ;cpp_16:
  1950                                  cpp_15:
  1951 00000A26 894C0C                  	mov	[si+ptSectors], cx
  1952 00000A29 895C0E                  	mov	[si+ptSectors+2], bx
  1953                                  
  1954                                  	; set partition ID after checking DOS FAT limits
  1955 00000A2C E8CD00                  	call	set_partition_id
  1956                                  	; al = partition ID
  1957                                  
  1958 00000A2F A2[9D6E]                	mov	[pp_type], al
  1959                                  
  1960 00000A32 884404                  	mov	[si+ptFileSystemID], al
  1961                                  
  1962 00000A35 C3                      	retn
  1963                                  
  1964                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1965                                  ; Decrease DOS partition size when it is (exact) 65536 sectors
  1966                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1967                                  ; 18/02/2019
  1968                                  
  1969                                  fix_32mb_dos_psize:	; call this if [wholedisk] = 0
  1970                                  
  1971                                  ; Purpose: 
  1972                                  ;	If a DOS partition's size is 65536 sectors
  1973                                  ;	MSDOS 3.3 can not use it. (FAT 16 partition ID = 06h)
  1974                                  ;	Decreasing partition size to 65535 sectors will ensure
  1975                                  ;	MSDOS 3.3 compatibility (FAT 16 partition ID will be 04h).			
  1976                                  
  1977                                  	; INPUT:
  1978                                  	;    BX:CX = partition size in sectors
  1979                                  	;    [pp_type] = partition type dos, non-dos, user input
  1980                                  	;
  1981                                  	; OUTPUT:
  1982                                  	;    Partition size will be changed to 65535 sectors, if
  1983                                  	;    	- partition size is 65536 sectors and
  1984                                  	; 	- [pp_type] is 1 (DOS)
  1985                                  	;
  1986                                  	;    [ppn_Sectors] = 65535 (if it will be changed)
  1987                                  	;
  1988                                  	; (Modified registers: cx, bx) 
  1989                                  
  1990                                  	;mov	cx, [ppn_Sectors]
  1991                                  	;mov	bx, [ppn_Sectors+2]
  1992                                  
  1993 00000A36 803E[9D6E]01            	cmp	byte [pp_type], 1 ;  DOS partition
  1994 00000A3B 7513                    	jne	short psfx_0  ; non-dos partition or user input
  1995                                  			      ; nothing to do ! 	
  1996 00000A3D 09C9                    	or	cx, cx
  1997 00000A3F 750F                    	jnz	short psfx_0 ; <> 65536 sectors
  1998 00000A41 83FB01                  	cmp	bx, 1
  1999 00000A44 750A                    	jne	short psfx_0
  2000 00000A46 4B                      	dec	bx
  2001                                  	;mov	[wholedisk], bx ; 0
  2002 00000A47 49                      	dec	cx  ; bx:cx = 65535
  2003 00000A48 890E[C86E]              	mov	[ppn_Sectors], cx
  2004 00000A4C 891E[CA6E]              	mov	[ppn_Sectors+2], bx
  2005                                  psfx_0:
  2006 00000A50 C3                      	retn
  2007                                  
  2008                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2009                                  ; Create extended dos partition
  2010                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2011                                  ; 16/02/2019 
  2012                                  ;	(This procedure must be called after 'find_part_free_space')
  2013                                  
  2014                                  create_extended_partition:  
  2015                                  	; 15/02/2019
  2016                                  
  2017                                  	; INPUT:
  2018                                  	;	none 
  2019                                  	;  (CHS parameters and free space calculation result will be used.) 
  2020                                  	;
  2021                                  	; OUTPUT:
  2022                                  	;	Partition table in MBR buffer will be updated.
  2023                                  	;
  2024                                  	; (Modified registers: ax, bx, cx, dx, si, di)
  2025                                  
  2026                                  	; Create extended dos partition, make partition table entry
  2027                                  	; (Extended partition will be created on cylinder bounds.)
  2028                                  
  2029                                  	; 16/02/2019
  2030 00000A51 E8F21E                  	call	get_first_free_pte
  2031                                  		 ; CX = First free PTE number, 0 to 3 
  2032                                  		 ;    (CX = 3 if there is not a free PTE, and CF = 1)
  2033                                  		 ;    ((But CF = 1 is not possible here because pcount < 4))
  2034                                   	 	 ; SI = PTE addres/offset in MBR buffer
  2035                                  
  2036                                  	;mov	si, MasterBootBuff+pTableOffset
  2037                                  	;shl	cl, 4 ; * 16
  2038                                  	;add	si, cx
  2039                                  	
  2040 00000A54 8B1E[2C72]              	mov	bx, [c_fspc_offset]
  2041                                  	
  2042 00000A58 8B87[DC71]              	mov	ax, [bx+free_space.start]
  2043 00000A5C 89C7                    	mov	di, ax
  2044                                  
  2045                                  	;mov	cx, 1
  2046 00000A5E B101                    	mov	cl, 1
  2047                                  
  2048                                  	;mov	byte [si+ptBootable], 0 ; not bootable/active partition
  2049 00000A60 882C                    	mov	[si], ch ; 0 ; not bootable/active partition
  2050 00000A62 886C01                  	mov	[si+ptBeginHead], ch ; Head 0 
  2051 00000A65 C0E406                  	shl	ah, 6
  2052 00000A68 08E1                    	or	cl, ah
  2053 00000A6A 884C02                  	mov	[si+ptBeginSector], cl ; Sector 1 
  2054 00000A6D 884403                  	mov	[si+ptBeginCylinder], al
  2055                                  
  2056 00000A70 A0[9840]                	mov	al, [heads]
  2057 00000A73 F626[9640]              	mul	byte [sectors]
  2058                                  		; ax = heads*sectors
  2059 00000A77 F7E7                    	mul	di  ; AX * cylinder count before start cylinder
  2060                                  		; DX:AX = LBA of cylinder DI, head 0, sector 1 
  2061                                  
  2062 00000A79 894408                  	mov	[si+ptStartSector], ax
  2063 00000A7C 89540A                  	mov	[si+ptStartSector+2], dx
  2064                                  
  2065                                  	; This is not needed for extended partition.
  2066                                  	; 16/02/2019
  2067                                  	;mov	[pp_StartSector], ax
  2068                                  	;mov	[pp_StartSector+2], dx
  2069                                  
  2070                                  	; 16/02/2019
  2071 00000A7F 803E[9C6E]00            	cmp	byte [wholedisk], 0
  2072 00000A84 772A                    	ja	short cep_2 ; all of free space will be used
  2073                                  			    ; ([bx+free_space.end] will be end cyl)	
  2074                                  
  2075                                  	; calculate cylinder count (from partition size input)
  2076 00000A86 A0[9840]                	mov	al, [heads]
  2077 00000A89 F626[9640]              	mul	byte [sectors]
  2078 00000A8D 89C1                    	mov	cx, ax
  2079 00000A8F A1[C86E]                	mov	ax, [ppn_Sectors]
  2080 00000A92 8B16[CA6E]              	mov	dx, [ppn_Sectors+2]
  2081 00000A96 E89D03                  	call	div32
  2082                                  		; ax = cylinders
  2083                                  		; bx = remainder
  2084 00000A99 21DB                    	and	bx, bx
  2085 00000A9B 7401                    	jz	short cep_1
  2086                                  
  2087 00000A9D 40                      	inc	ax  ; round up
  2088                                  cep_1:
  2089                                  	; 16/02/2019
  2090                                  	; DI  = extended partition's start cylinder
  2091 00000A9E 89C2                    	mov	dx, ax ; cylinder count
  2092 00000AA0 01FA                    	add	dx, di ; result is end cyl + 1
  2093 00000AA2 4A                      	dec	dx ; decrease number for current end cylinder
  2094 00000AA3 8B1E[2C72]              	mov	bx, [c_fspc_offset]
  2095 00000AA7 3B97[DE71]              	cmp	dx, [bx+free_space.end]
  2096 00000AAB 7607                    	jna	short cep_3
  2097                                  	; 24/10/2020
  2098                                  	;dec	ax ; decrease cylinder count down to the limit
  2099 00000AAD 4A                      	dec	dx ; decrease end cylinder down to the limit		  
  2100 00000AAE EB04                    	jmp	short cep_3 	
  2101                                  cep_2:
  2102 00000AB0 8B97[DE71]              	mov	dx, [bx+free_space.end]
  2103                                  	; 24/10/2020
  2104                                  	;mov	ax, [bx+free_space.space]
  2105                                  cep_3:
  2106 00000AB4 8A2E[9840]              	mov	ch, [heads]
  2107 00000AB8 FECD                    	dec	ch 
  2108 00000ABA 8A0E[9640]              	mov	cl, [sectors]
  2109 00000ABE 886C05                  	mov	[si+ptEndHead], ch
  2110                                  	; 23/02/2019
  2111 00000AC1 88F3                    	mov	bl, dh
  2112 00000AC3 C0E306                  	shl	bl, 6
  2113 00000AC6 08CB                    	or	bl, cl
  2114                                  	;or	[si+ptEndSector], bl
  2115                                  	; 24/10/2020
  2116 00000AC8 885C06                  	mov	[si+ptEndSector], bl
  2117 00000ACB 885407                  	mov	[si+ptEndCylinder], dl
  2118                                  
  2119 00000ACE A0[9840]                	mov	al, [heads]
  2120                                  	;mul	byte [sectors]
  2121 00000AD1 F6E1                    	mul	cl
  2122                                  		; ax = heads*sectors	
  2123 00000AD3 F7E2                    	mul	dx ; AX * cylinder count before end cylinder
  2124                                  		; DX:AX = LBA of cylinder DX, head 0, sector 1 		
  2125 00000AD5 52                      	push	dx
  2126 00000AD6 50                      	push	ax
  2127 00000AD7 88E8                    	mov	al, ch ; [heads] - 1
  2128 00000AD9 8B0E[9640]              	mov	cx, [sectors]  ; 63 or 17	 	
  2129 00000ADD F6E1                    	mul	cl
  2130                                  		; ax = (heads-1)*sectors
  2131 00000ADF 5A                      	pop	dx
  2132 00000AE0 01D0                    	add	ax, dx
  2133 00000AE2 5A                      	pop	dx
  2134 00000AE3 83D200                  	adc	dx, 0
  2135                                  		; dx:ax = ((end cylinder)*heads)+(heads-1)*sectors
  2136 00000AE6 01C8                    	add	ax, cx
  2137 00000AE8 83D200                  	adc	dx, 0
  2138                                  	; dx:ax = (((end cylinder)*heads)+(heads-1)*sectors) + sectors
  2139                                  	; dx:ax = LBA of the partition's end sector + 1
  2140 00000AEB 2B4408                  	sub	ax, [si+ptStartSector]
  2141 00000AEE 1B540A                  	sbb	dx, [si+ptStartSector+2] 
  2142                                  
  2143 00000AF1 89440C                  	mov	[si+ptSectors], ax
  2144 00000AF4 89540E                  	mov	[si+ptSectors+2], dx
  2145                                  
  2146                                  	;mov	[pp_type], al
  2147                                  
  2148 00000AF7 C6440405                	mov	byte [si+ptFileSystemID], 5
  2149                                  
  2150 00000AFB C3                      	retn
  2151                                  
  2152                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2153                                  ; Set DOS (and non-dos) partition ID according to partition size
  2154                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2155                                  ; 18/02/2019
  2156                                  
  2157                                  set_partition_id: 
  2158                                  	; 18/02/2019
  2159                                  	;mov	cx, [ppn_Sectors]
  2160                                  	;mov	bx, [ppn_Sectors+2]
  2161                                  
  2162 00000AFC A0[9D6E]                	mov	al, [pp_type]
  2163                                  
  2164                                  	;cmp	byte [pp_type], 1
  2165 00000AFF 3C01                    	cmp	al, 1 ; primary DOS (FAT12, FAT16, FAT32)
  2166 00000B01 7519                    	jne	short spid_2
  2167                                  
  2168                                  	;mov	al, 1	; FAT12
  2169                                  
  2170 00000B03 09DB                    	or	bx, bx
  2171 00000B05 750A                    	jnz	short spid_1
  2172                                  
  2173 00000B07 81F9A87F                	cmp	cx, 32680
  2174 00000B0B 763A                    	jna	short spid_8	; FAT12 file system
  2175                                  
  2176 00000B0D B004                    	mov	al, 4	; FAT16 (< 32MB)
  2177                                  
  2178 00000B0F EB36                    	jmp	short spid_8	; FAT16 (CHS) file system
  2179                                  
  2180                                  spid_1:
  2181 00000B11 B00B                    	mov	al, 0Bh ; FAT32 (CHS)
  2182                                  
  2183 00000B13 83FB10                  	cmp	bx, 10h
  2184 00000B16 732F                    	jnb	short spid_8	; FAT32 (CHS) file system	
  2185                                  
  2186 00000B18 B006                    	mov	al, 6	; FAT16 (>= 32MB)
  2187                                  
  2188 00000B1A EB2B                    	jmp	short spid_8	; FAT16 big (CHS) file system
  2189                                  
  2190                                  spid_2:
  2191                                  	;cmp	byte [pp_type], 2 ; Singlix FS
  2192 00000B1C 3C02                    	cmp	al, 2
  2193 00000B1E 7504                    	jne	short spid_3
  2194 00000B20 B0A1                    	mov	al, 0A1h
  2195 00000B22 EB23                    	jmp	short spid_8
  2196                                  spid_3:
  2197                                  	;cmp	byte [pp_type], 3 ; Retro Unix FS
  2198 00000B24 3C03                    	cmp	al, 3
  2199 00000B26 7504                    	jne	short spid_4
  2200 00000B28 B071                    	mov	al, 71h
  2201 00000B2A EB1B                    	jmp	short spid_8
  2202                                  
  2203                                  spid_4:
  2204                                  	; another partition type (user input)
  2205                                  	
  2206                                  	; [pp_type] = 4
  2207                                  
  2208 00000B2C A0[9E6E]                	mov	al, [pp_type_user]
  2209                                  
  2210                                  	; Check FAT12 fs size validation
  2211                                  
  2212 00000B2F 3C01                    	cmp	al, 1 ; FAT12
  2213 00000B31 7715                    	ja	short spid_9
  2214                                  
  2215 00000B33 21DB                    	and	bx, bx
  2216 00000B35 750A                    	jnz	short spid_6
  2217                                  
  2218 00000B37 81F9A87F                	cmp	cx, 32680
  2219 00000B3B 760A                    	jna	short spid_8
  2220                                  spid_5:
  2221 00000B3D B004                    	mov	al, 4 ; FAT16 (<= 32MB) 
  2222 00000B3F EB06                    	jmp	short spid_8
  2223                                  spid_6:
  2224                                  	;;cmp	bx, 10h	; 512MB (16*32MB)
  2225                                  	;cmp	bx, 40h ; 2GB (64*32MB)
  2226                                  	;jnb	short spid_7
  2227                                  	
  2228 00000B41 B006                    	mov	al, 6
  2229 00000B43 EB02                    	jmp	short spid_8
  2230                                  spid_7:
  2231 00000B45 B00B                    	mov	al, 0Bh ; FAT32 (CHS) partition
  2232                                  spid_8:
  2233 00000B47 C3                      	retn
  2234                                  spid_9:
  2235 00000B48 3C04                    	cmp	al, 4 ; FAT16 (< 32 MB)
  2236 00000B4A 7505                    	jne	short spid_10
  2237                                  
  2238 00000B4C 09DB                    	or	bx, bx
  2239 00000B4E 75F1                    	jnz	short spid_6
  2240                                  	
  2241 00000B50 C3                      	retn	; FAT16 (< 32 MB) partition
  2242                                  spid_10:
  2243 00000B51 3C06                    	cmp	al, 6 ; FAT 16 big partition
  2244 00000B53 750E                    	jne	short spid_13 ; Extended partition or another type
  2245                                  	
  2246 00000B55 21DB                    	and	bx, bx
  2247 00000B57 7401                    	jz	short spid_11
  2248                                  
  2249                                  	;;cmp	bx, 10h	; 512MB (16*32MB)
  2250                                  	;cmp	bx, 40h ; 2GB (64*32MB)
  2251                                  	;jnb	short spid_7
  2252                                  	
  2253 00000B59 C3                      	retn
  2254                                  spid_11:
  2255                                  	;cmp	ax, 4150 ; 4085 + 32 + 32 + 1
  2256 00000B5A 81F93610                	cmp	cx, 4150 ; 14/09/2020 (BugFix)
  2257 00000B5E 73DD                    	jnb	short spid_5
  2258                                  spid_12:
  2259 00000B60 B001                    	mov	al, 1 ;  FAT12 partition
  2260 00000B62 C3                      	retn
  2261                                  spid_13:
  2262                                  	; 14/09/2020
  2263 00000B63 3C0B                    	cmp	al, 0Bh ; FAT 32 (CHS) partition
  2264 00000B65 7419                    	je	short spid_15 ; FAT 32 CHS
  2265 00000B67 3C0C                    	cmp	al, 0Ch	 
  2266 00000B69 750C                    	jne	short spid_14 
  2267                                  	; FAT 32 LBA
  2268 00000B6B 21DB                    	and	bx, bx	; < 33 MB
  2269 00000B6D 74EB                    	jz	short spid_11 ; force to FAT 16 CHS or FAT 12
  2270 00000B6F 83FB10                  	cmp	bx, 10h ; 512 MB
  2271 00000B72 73D3                    	jnb	short spid_8  ; OK, FAT 32 LBA has been confirmed
  2272 00000B74 B00E                    	mov	al, 0Eh ; force to FAT 16 LBA
  2273 00000B76 C3                      	retn
  2274                                  spid_14:
  2275                                  	; 14/09/2020
  2276 00000B77 3C0E                    	cmp	al, 0Eh
  2277 00000B79 75CC                    	jne	short spid_8 ; non-dos or extended partition
  2278                                  	; FAT 16 LBA
  2279 00000B7B 09DB                    	or	bx, bx
  2280 00000B7D 74DB                    	jz	short spid_11
  2281                                  	;cmp	bx, 20h ; 1 GB
  2282                                  	;jb	short spid_8
  2283                                  	;mov	al, 0Ch	; FAT 32 LBA
  2284 00000B7F C3                      	retn
  2285                                  spid_15:
  2286                                  	; Minimum size of FAT 32 FS = 65525 + 512 + 512 + 32
  2287                                   	; >= 66581 sectors (or >= 65525 data clusters)
  2288 00000B80 83FB01                  	cmp	bx, 1
  2289 00000B83 72D5                    	jb	short spid_11  ; invalid! (< 33 MB)
  2290 00000B85 77C0                    	ja	short spid_8
  2291 00000B87 81F91504                	cmp	cx, 1045
  2292 00000B8B 7201                    	jb	short spid_16  ; invalid! (< 33 MB)
  2293 00000B8D C3                      	retn
  2294                                  spid_16:
  2295 00000B8E B006                    	mov	al, 6
  2296 00000B90 C3                      	retn
  2297                                  
  2298                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2299                                  ; Set disk size before creating hd image file
  2300                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2301                                  
  2302                                  new_image:
  2303                                  	; 07/03/2019
  2304 00000B91 B80300                  	mov	ax, 3 ; set video mode to 3 (clear video page)
  2305 00000B94 CD10                    	int	10h
  2306                                  B_05:
  2307                                  	;mov	byte [existingfile], 0 ; 12/02/2019
  2308 00000B96 E8E413                  	call	display_chs_table
  2309                                  B_06:
  2310 00000B99 30E4                    	xor	ah, ah
  2311 00000B9B CD16                    	int	16h
  2312 00000B9D 3C61                    	cmp	al, 'a'
  2313 00000B9F 7206                    	jb	short B_07
  2314 00000BA1 3C7A                    	cmp	al, 'z'
  2315 00000BA3 7702                    	ja	short B_07	
  2316 00000BA5 24DF                    	and	al, 0DFh
  2317                                  B_07:
  2318 00000BA7 3C43                    	cmp	al, 'C'
  2319 00000BA9 752C                    	jne	short B_12
  2320                                  B_08:
  2321 00000BAB 833E[9A40]00            	cmp	word [cylinders], 0
  2322 00000BB0 7706                    	ja	short B_09
  2323 00000BB2 C706[9A40]0004          	mov	word [cylinders], 1024
  2324                                  B_09:
  2325 00000BB8 833E[9840]00            	cmp	word [heads], 0
  2326 00000BBD 7706                    	ja	short B_10
  2327 00000BBF C706[9840]1000          	mov	word [heads], 16
  2328                                  B_10:
  2329 00000BC5 833E[9640]00            	cmp	word [sectors], 0
  2330 00000BCA 7706                    	ja	short B_11
  2331 00000BCC C706[9640]3F00          	mov	word [sectors], 63
  2332                                  B_11:
  2333 00000BD2 A2[9F6E]                	mov	byte [chs_focus], al
  2334 00000BD5 EBBF                    	jmp	short B_05
  2335                                  B_12:
  2336 00000BD7 3C48                    	cmp	al, 'H'
  2337 00000BD9 74D0                    	je	short B_08
  2338 00000BDB 3C53                    	cmp	al, 'S'
  2339 00000BDD 74CC                    	je	short B_08
  2340 00000BDF 3C1B                    	cmp	al, 27 ; ESC key
  2341 00000BE1 0F848D00                	je	B_18	
  2342 00000BE5 3C0D                    	cmp	al, 13 ; ENTER key
  2343 00000BE7 0F85EF00                	jne	B_21
  2344                                  
  2345 00000BEB 833E[9640]3F            	cmp	word [sectors], 63
  2346 00000BF0 730D                    	jnb	short B_13
  2347 00000BF2 833E[9840]10            	cmp	word [heads], 16
  2348 00000BF7 7606                    	jna	short B_13
  2349 00000BF9 C706[9840]1000          	mov	word [heads], 16
  2350                                  B_13:
  2351 00000BFF A1[9640]                	mov	ax, [sectors]
  2352 00000C02 F726[9840]              	mul	word [heads]
  2353 00000C06 A3[C26E]                	mov	[min_sectors], ax  ; 08/02/2019
  2354 00000C09 8B16[9A40]              	mov	dx, [cylinders]
  2355 00000C0D F7E2                    	mul	dx
  2356 00000C0F A3[886E]                	mov	[total_sectors], ax
  2357 00000C12 8916[8A6E]              	mov	[total_sectors+2], dx
  2358                                  
  2359                                  	; 05/02/2019
  2360 00000C16 BF[7C56]                	mov	di, str_disk_sectors
  2361                                  
  2362 00000C19 89E5                    	mov	bp, sp
  2363 00000C1B B90A00                  	mov	cx, 10
  2364                                  B_14:
  2365 00000C1E E81502                  	call	div32
  2366                                  	
  2367 00000C21 80C330                  	add	bl, '0'
  2368 00000C24 53                      	push	bx
  2369 00000C25 21C0                    	and	ax, ax
  2370 00000C27 75F5                    	jnz	short B_14
  2371 00000C29 21D2                    	and	dx, dx
  2372 00000C2B 75F1                    	jnz	short B_14
  2373                                  
  2374 00000C2D 29E5                    	sub	bp, sp
  2375 00000C2F D1ED                    	shr	bp, 1
  2376                                  B_15:
  2377 00000C31 58                      	pop	ax
  2378 00000C32 AA                      	stosb
  2379 00000C33 4D                      	dec	bp
  2380 00000C34 75FB                    	jnz	short B_15
  2381                                  
  2382 00000C36 30C0                    	xor	al, al
  2383 00000C38 AA                      	stosb
  2384                                  
  2385 00000C39 A1[886E]                	mov	ax, [total_sectors]
  2386 00000C3C 8B16[8A6E]              	mov	dx, [total_sectors+2]
  2387 00000C40 B90002                  	mov	cx, 512
  2388 00000C43 E8FE01                  	call	mul32
  2389 00000C46 A3[906E]                	mov	[file_size], ax
  2390 00000C49 8916[926E]              	mov	[file_size+2], dx
  2391                                  	
  2392 00000C4D BF[BF56]                	mov	di, str_file_size
  2393                                  
  2394 00000C50 89E5                    	mov	bp, sp
  2395 00000C52 B90A00                  	mov	cx, 10
  2396                                  B_16:
  2397 00000C55 E8DE01                  	call	div32
  2398                                  
  2399 00000C58 80C330                  	add	bl, '0'
  2400 00000C5B 53                      	push	bx
  2401 00000C5C 21C0                    	and	ax, ax
  2402 00000C5E 75F5                    	jnz	short B_16
  2403 00000C60 21D2                    	and	dx, dx
  2404 00000C62 75F1                    	jnz	short B_16
  2405                                  
  2406 00000C64 29E5                    	sub	bp, sp
  2407 00000C66 D1ED                    	shr	bp, 1
  2408                                  B_17:
  2409 00000C68 58                      	pop	ax
  2410 00000C69 AA                      	stosb
  2411 00000C6A 4D                      	dec	bp
  2412 00000C6B 75FB                    	jnz	short B_17
  2413                                  
  2414 00000C6D 30C0                    	xor	al, al
  2415 00000C6F AA                      	stosb
  2416                                  
  2417 00000C70 B00D                    	mov	al, 13 ; ENTER (Carriage Return) key	
  2418                                  B_18:
  2419 00000C72 50                      	push	ax
  2420                                  
  2421 00000C73 C606[9F6E]00            	mov	byte [chs_focus], 0
  2422 00000C78 E80213                  	call	display_chs_table
  2423                                  
  2424 00000C7B 58                      	pop	ax
  2425                                  
  2426 00000C7C 3C0D                    	cmp	al, 13 ; CR ?
  2427 00000C7E 7402                    	je	short B_20 ; print total sectors and file size..
  2428                                  B_19:
  2429 00000C80 CD20                    	int	20h
  2430                                  B_20:
  2431 00000C82 BE[6656]                	mov	si, msg_disk_sectors
  2432 00000C85 E8AD11                  	call	print_msg
  2433 00000C88 BE[7C56]                	mov	si, str_disk_sectors
  2434 00000C8B E8A711                  	call	print_msg
  2435 00000C8E BE[5056]                	mov	si, CRLF
  2436 00000C91 E8A111                  	call	print_msg
  2437 00000C94 BE[A956]                	mov	si, msg_file_size
  2438 00000C97 E89B11                  	call	print_msg
  2439 00000C9A BE[BF56]                	mov	si, str_file_size
  2440 00000C9D E89511                  	call	print_msg
  2441 00000CA0 BE[CA56]                	mov	si, msg_bytes
  2442 00000CA3 E88F11                  	call	print_msg
  2443 00000CA6 BE[D356]                	mov	si, msg_enter_cancel
  2444 00000CA9 E88911                  	call	print_msg
  2445 00000CAC 30E4                    	xor	ah, ah
  2446 00000CAE CD16                    	int	16h
  2447 00000CB0 3C1B                    	cmp	al, 1Bh ; ESC key
  2448 00000CB2 74CC                    	je	short B_19
  2449 00000CB4 3C0D                    	cmp	al, 0Dh ; Enter key
  2450 00000CB6 0F85DCFE                	jne	B_05
  2451                                  
  2452 00000CBA 833E[8A6E]00            	cmp	word [total_sectors+2], 0
  2453 00000CBF 0F879501                	ja	B_42
  2454                                  
  2455 00000CC3 813E[886E]003F          	cmp	word [total_sectors], 16128  ; 63*16*16
  2456 00000CC9 0F838B01                	jnb	B_42
  2457                                  
  2458 00000CCD BE[AF45]                	mov	si, msg_min_8mb_disk 
  2459 00000CD0 E86211                  	call	print_msg
  2460                                  
  2461 00000CD3 30E4                    	xor	ah, ah
  2462 00000CD5 CD16                    	int	16h
  2463                                  
  2464 00000CD7 E9BCFE                  	jmp	B_05
  2465                                  	
  2466                                  B_21:
  2467 00000CDA 3C20                    	cmp	al, 20h
  2468 00000CDC 745A                    	je	short B_25
  2469 00000CDE 3C2D                    	cmp	al, '-'
  2470 00000CE0 0F84E200                	je	B_34
  2471 00000CE4 3C2B                    	cmp	al, '+'
  2472 00000CE6 7450                    	je	short B_25
  2473 00000CE8 80FC51                  	cmp	ah, 51h ; Pg Down
  2474 00000CEB 7416                    	je	short B_23
  2475 00000CED 80FC49                  	cmp	ah, 49h ; Pg Up
  2476 00000CF0 742F                    	je	short B_24  
  2477                                  B_22:
  2478 00000CF2 803E[9F6E]00            	cmp	byte [chs_focus], 0
  2479 00000CF7 0F869EFE                	jna	B_06
  2480 00000CFB C606[9F6E]00            	mov	byte [chs_focus], 0
  2481 00000D00 E993FE                  	jmp	B_05
  2482                                  B_23:
  2483 00000D03 803E[9F6E]43            	cmp	byte [chs_focus], 'C'
  2484                                  	;jne	short B_22
  2485 00000D08 0F85BA00                	jne	B_34 ; 10/02/2019
  2486 00000D0C 832E[9A40]10            	sub	word [cylinders], 16
  2487 00000D11 0F82C500                	jc	B_35
  2488 00000D15 833E[9A40]10            	cmp	word [cylinders], 16
  2489 00000D1A 0F82BC00                	jb	B_35
  2490 00000D1E E975FE                  	jmp	B_05
  2491                                  B_24:
  2492 00000D21 803E[9F6E]43            	cmp	byte [chs_focus], 'C'
  2493                                  	;jne	short B_22
  2494 00000D26 752E                    	jne	short B_27 ; 10/02/2019
  2495 00000D28 8306[9A40]10            	add	word [cylinders], 16
  2496 00000D2D 813E[9A40]0004          	cmp	word [cylinders], 1024
  2497 00000D33 7718                    	ja	short B_26
  2498 00000D35 E95EFE                  	jmp	B_05
  2499                                  B_25:
  2500 00000D38 803E[9F6E]43            	cmp	byte [chs_focus], 'C'
  2501 00000D3D 7517                    	jne	short B_27
  2502 00000D3F FF06[9A40]              	inc	word [cylinders]
  2503 00000D43 813E[9A40]0004          	cmp	word [cylinders], 1024
  2504 00000D49 0F8649FE                	jna	B_05
  2505                                  B_26:
  2506 00000D4D C706[9A40]1000          	mov	word [cylinders], 16 ; minimum cylinders
  2507 00000D53 E940FE                  	jmp	B_05	
  2508                                  B_27:
  2509 00000D56 803E[9F6E]48            	cmp	byte [chs_focus], 'H'
  2510 00000D5B 7547                    	jne	short B_32
  2511 00000D5D 833E[9840]10            	cmp	word [heads], 16
  2512 00000D62 7307                    	jnb	short B_28
  2513 00000D64 FF06[9840]              	inc	word [heads]
  2514 00000D68 E92BFE                  	jmp	B_05
  2515                                  B_28:
  2516 00000D6B 833E[9640]3F            	cmp	word [sectors], 63
  2517 00000D70 7212                    	jb	short B_29
  2518 00000D72 833E[9840]20            	cmp	word [heads], 32
  2519 00000D77 7722                    	ja	short B_31
  2520 00000D79 7217                    	jb	short B_30
  2521 00000D7B C706[9840]4000          	mov	word [heads], 64
  2522 00000D81 E912FE                  	jmp	B_05
  2523                                  B_29:
  2524 00000D84 833E[9840]10            	cmp	word [heads], 16
  2525 00000D89 7310                    	jnb	short B_31
  2526 00000D8B FF06[9840]              	inc	word [heads]
  2527 00000D8F E904FE                  	jmp	B_05
  2528                                  B_30:
  2529 00000D92 C706[9840]2000          	mov	word [heads], 32
  2530 00000D98 E9FBFD                  	jmp	B_05
  2531                                  B_31:
  2532 00000D9B C706[9840]0200          	mov	word [heads], 2
  2533 00000DA1 E9F2FD                  	jmp	B_05
  2534                                  B_32:
  2535 00000DA4 803E[9F6E]53            	cmp	byte [chs_focus], 'S'
  2536 00000DA9 0F85E9FD                	jne	B_05
  2537 00000DAD 833E[9640]3F            	cmp	word [sectors], 63
  2538 00000DB2 7509                    	jne	short B_33
  2539 00000DB4 C706[9640]1100          	mov	word [sectors], 17
  2540 00000DBA E9D9FD                  	jmp	B_05
  2541                                  B_33:
  2542 00000DBD C706[9640]3F00          	mov	word [sectors], 63
  2543 00000DC3 E9D0FD                  	jmp	B_05
  2544                                  B_34:
  2545 00000DC6 803E[9F6E]43            	cmp	byte [chs_focus], 'C'
  2546 00000DCB 7516                    	jne	short B_36
  2547 00000DCD FF0E[9A40]              	dec	word [cylinders]
  2548 00000DD1 833E[9A40]10            	cmp	word [cylinders], 16
  2549 00000DD6 0F83BCFD                	jnb	B_05
  2550                                  B_35:
  2551 00000DDA C706[9A40]0004          	mov	word [cylinders], 1024
  2552 00000DE0 E9B3FD                  	jmp	B_05	
  2553                                  B_36:
  2554 00000DE3 803E[9F6E]48            	cmp	byte [chs_focus], 'H'
  2555 00000DE8 75BA                    	jne	short B_32
  2556                                  
  2557 00000DEA 833E[9640]3F            	cmp	word [sectors], 63
  2558 00000DEF 721E                    	jb	short B_38
  2559                                  
  2560 00000DF1 833E[9840]02            	cmp	word [heads], 2
  2561 00000DF6 760E                    	jna	short B_37
  2562 00000DF8 833E[9840]10            	cmp	word [heads], 16
  2563 00000DFD 771E                    	ja	short B_39
  2564 00000DFF FF0E[9840]              	dec	word [heads]
  2565 00000E03 E990FD                  	jmp	B_05
  2566                                  B_37:
  2567 00000E06 C706[9840]4000          	mov	word [heads], 64
  2568 00000E0C E987FD                  	jmp	B_05
  2569                                  B_38:
  2570 00000E0F 833E[9840]02            	cmp	word [heads], 2
  2571 00000E14 760E                    	jna	short B_40
  2572 00000E16 FF0E[9840]              	dec	word [heads]
  2573 00000E1A E979FD                  	jmp	B_05
  2574                                  B_39:
  2575 00000E1D 833E[9840]20            	cmp	word [heads], 32
  2576 00000E22 7709                    	ja	short B_41
  2577                                  B_40:
  2578 00000E24 C706[9840]1000          	mov	word [heads], 16
  2579 00000E2A E969FD                  	jmp	B_05
  2580                                  B_41:
  2581 00000E2D C706[9840]2000          	mov	word [heads], 32
  2582 00000E33 E960FD                  	jmp	B_05
  2583                                  
  2584                                  ;-----------------------------------------------------------------------------
  2585                                  
  2586                                  div32:
  2587                                  	; DX_AX/CX
  2588                                  	; Result: DX_AX, BX (remainder) 
  2589 00000E36 89C3                    	mov	bx, ax
  2590                                  	;or	dx, ax ; * DX_AX = 0 ?       
  2591                                  	;jz	short div32_retn ; yes, do not divide! 
  2592 00000E38 89D0                    	mov	ax, dx
  2593 00000E3A 31D2                            xor	dx, dx
  2594 00000E3C F7F1                            div	cx	; at first, divide DX
  2595                                  			; remainder is in DX 
  2596 00000E3E 93                      	xchg	ax, bx	; now quotient is in BX
  2597                                    			; and initial AX value is in AX
  2598 00000E3F F7F1                    	div	cx	; now, DX_AX has been divided and
  2599                                  			; AX has quotient
  2600                                  			; DX has remainder
  2601 00000E41 87D3                    	xchg	dx, bx	; finally, BX has remainder
  2602                                  ;div32_retn:
  2603 00000E43 C3                              retn
  2604                                  
  2605                                  ;-----------------------------------------------------------------------------
  2606                                  
  2607                                  mul32:
  2608                                  	; DX_AX*CX
  2609                                  	; Result: BX_DX_AX 
  2610 00000E44 51                      	push	cx
  2611 00000E45 89D3                    	mov	bx, dx
  2612 00000E47 F7E1                    	mul	cx
  2613 00000E49 93                       	xchg	ax, bx
  2614 00000E4A 52                      	push	dx
  2615 00000E4B F7E1                    	mul	cx 
  2616 00000E4D 59                      	pop	cx 
  2617 00000E4E 01C8                    	add	ax, cx 
  2618 00000E50 83D200                  	adc	dx, 0
  2619 00000E53 93                      	xchg	bx, ax
  2620 00000E54 87D3                    	xchg	dx, bx
  2621 00000E56 59                      	pop	cx
  2622 00000E57 C3                      	retn
  2623                                  
  2624                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2625                                  ; Create a new hard disk image file
  2626                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2627                                  		
  2628                                  B_42:
  2629 00000E58 BA[8159]                	mov	dx, img_file_name
  2630 00000E5B B90000                  	mov	cx, 0 ; File Attributes
  2631 00000E5E B43C                    	mov	ah, 3Ch ; MS-DOS Function = Create File
  2632 00000E60 CD21                    	int	21h
  2633 00000E62 0F8222F2                	jc	A_10
  2634                                  
  2635 00000E66 BE[5056]                	mov	si, CRLF
  2636 00000E69 E8C90F                  	call	print_msg
  2637                                  
  2638                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2639                                  ; Open image file for writing
  2640                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2641                                  
  2642 00000E6C B002                    	mov	al, 2 ; open for reading and writing
  2643                                  	;mov	dx, img_file_name
  2644 00000E6E B43D                    	mov	ah, 3Dh ; open file
  2645 00000E70 CD21                    	int	21h
  2646 00000E72 0F82A90F                	jc	D_02
  2647                                  
  2648 00000E76 A3[9440]                	mov	[img_file_handle], ax
  2649                                  
  2650 00000E79 BE[0455]                	mov	si, msg_writing_mbr
  2651 00000E7C E8B60F                  	call	print_msg
  2652                                  
  2653                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2654                                  ; Writing/Saving CHS parameters into (Singlix FS1) MBR
  2655                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2656                                  ; Note: Partition Table will be left empty at this stage
  2657                                  
  2658                                  	;cmp	word [TRDOS386_MASTERBOOT_SECTOR+417], 417
  2659                                  	;jne	short B_43
  2660                                  
  2661 00000E7F 8B0E[9A40]              	mov	cx, [cylinders]
  2662 00000E83 890E[2634]              	mov	[TRDOS386_MASTERBOOT_SECTOR+420], cx ; pt_cylinders
  2663 00000E87 8B0E[9840]              	mov	cx, [heads]
  2664 00000E8B 890E[2834]              	mov	[TRDOS386_MASTERBOOT_SECTOR+422], cx ; pt_heads
  2665 00000E8F 8B0E[9640]              	mov	cx, [sectors]
  2666 00000E93 890E[2A34]              	mov	[TRDOS386_MASTERBOOT_SECTOR+424], cx ; pt_sectors	 	 
  2667                                  
  2668                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2669                                  ; writing masterboot sector
  2670                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2671                                  
  2672                                  B_43:
  2673 00000E97 8B1E[9440]              	mov	bx, [img_file_handle]
  2674 00000E9B BA[8232]                	mov	dx, TRDOS386_MASTERBOOT_SECTOR ; Singlix FS1 MBR
  2675 00000E9E B90002                  	mov	cx, 512
  2676 00000EA1 B440                    	mov	ah, 40h ; write to file	
  2677 00000EA3 CD21                    	int	21h
  2678 00000EA5 0F826C0F                	jc	D_01
  2679                                  
  2680 00000EA9 BE[4C56]                	mov	si, Msg_OK
  2681 00000EAC E8860F                  	call	print_msg
  2682                                  
  2683 00000EAF BE[2155]                	mov	si, msg_writing_disk_sectors
  2684 00000EB2 E8800F                  	call	print_msg
  2685 00000EB5 B403                    	mov	ah, 3
  2686 00000EB7 BB0700                  	mov	bx, 7
  2687 00000EBA CD10                    	int	10h ; Return Cursor Position
  2688                                  	; DL = Column, DH = Line
  2689 00000EBC 8916[9455]              	mov	[Cursor_Pos], dx
  2690                                  
  2691                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2692                                  ; writing disk sectors (with F6h -format- bytes)
  2693                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  2694                                  
  2695 00000EC0 31D2                    	xor	dx, dx
  2696 00000EC2 B80100                  	mov	ax, 1
  2697                                  
  2698                                  	; 63 (17) sectors (after MBR) will be filled with ZERO 
  2699                                  B_44:
  2700 00000EC5 52                      	push	dx
  2701 00000EC6 50                      	push	ax
  2702 00000EC7 BE[9255]                	mov	si, Sector_Str + 6
  2703 00000ECA E8F00F                  	call	bin_to_decimal
  2704 00000ECD 8B16[9455]              	mov	dx, [Cursor_Pos]
  2705 00000ED1 BB0700                  	mov	bx, 7
  2706 00000ED4 B402                    	mov	ah, 2
  2707 00000ED6 CD10                    	int	10h  ; Set Cursor Position
  2708 00000ED8 E85A0F                  	call	print_msg
  2709 00000EDB 58                      	pop	ax
  2710 00000EDC 5A                      	pop	dx
  2711 00000EDD BB[0C6A]                	mov	bx, HDFORMAT_FATBUFFER ; Empty Sector
  2712 00000EE0 E8610F                  	call	write_hd_sector
  2713 00000EE3 0F822E0F                	jc	D_01
  2714                                  	;inc	ax
  2715 00000EE7 FEC0                    	inc	al
  2716 00000EE9 3B06[9640]              	cmp	ax, [sectors] ; 63 or 17
  2717 00000EED 76D6                    	jna	short B_44
  2718                                  
  2719                                  	; writing other sectors upto [total sectors] - 1 
  2720                                  B_45:
  2721 00000EEF 52                      	push	dx
  2722 00000EF0 50                      	push	ax
  2723 00000EF1 BE[9255]                	mov	si, Sector_Str + 6
  2724 00000EF4 E8C60F                  	call	bin_to_decimal
  2725 00000EF7 8B16[9455]              	mov	dx, [Cursor_Pos]
  2726 00000EFB BB0700                  	mov	bx, 7
  2727 00000EFE B402                    	mov	ah, 2
  2728 00000F00 CD10                    	int	10h  ; Set Cursor Position
  2729 00000F02 E8300F                  	call	print_msg
  2730 00000F05 58                      	pop	ax
  2731 00000F06 5A                      	pop	dx
  2732 00000F07 BB[0A66]                	mov	bx, HDFORMAT_SECBUFFER ; F6h filled sectors
  2733 00000F0A E8370F                  	call	write_hd_sector
  2734 00000F0D 0F82040F                	jc	D_01
  2735 00000F11 83C001                  	add	ax, 1
  2736 00000F14 83D200                  	adc	dx, 0
  2737 00000F17 3B16[8A6E]              	cmp	dx, [total_sectors+2]
  2738 00000F1B 72D2                    	jb	short B_45
  2739 00000F1D 7706                    	ja	short B_46
  2740 00000F1F 3B06[886E]              	cmp	ax, [total_sectors]
  2741 00000F23 72CA                    	jb	short B_45
  2742                                  B_46:
  2743 00000F25 BE[4956]                	mov	si, Msg_3dot_OK
  2744 00000F28 E80A0F                  	call	print_msg
  2745                                  
  2746 00000F2B BE[1246]                	mov	si, msg_any_key_esc_exit
  2747 00000F2E E8040F                  	call	print_msg
  2748                                  	
  2749 00000F31 30E4                    	xor	ah, ah
  2750 00000F33 CD16                    	int	16h	
  2751                                  
  2752 00000F35 3C1B                    	cmp	al, 27 ; 1Bh, ESC key
  2753 00000F37 7508                    	jne	short B_48
  2754                                  B_47:
  2755 00000F39 BE[5056]                	mov	si, CRLF
  2756 00000F3C E8F60E                  	call	print_msg
  2757                                  	
  2758 00000F3F CD20                    	int	20h
  2759                                  B_48:
  2760 00000F41 FE06[9C40]              	inc	byte [random] ; next r/w is not sequental 
  2761 00000F45 FE06[9D40]              	inc	byte [newdisk] ; will be used by partitioning
  2762                                  
  2763                                  	; 11/02/2019
  2764                                  	; Copy Singlix FS (TRDOS 386) MBR to MasterBoot buffer
  2765 00000F49 B90001                  	mov	cx, 256
  2766 00000F4C BE[8232]                	mov	si, TRDOS386_MASTERBOOT_SECTOR ; Singlix FS1 MBR
  2767 00000F4F BF[2857]                	mov	di, MasterBootBuff
  2768 00000F52 F3A5                    	rep	movsw
  2769                                  
  2770                                  	; 26/02/2019
  2771                                  	; Clear partition table structure
  2772                                  	; (for preventing wrong partition data display for new disk image)
  2773 00000F54 BF[4671]                	mov	di, part_table_boot_ind
  2774 00000F57 31C0                    	xor	ax, ax
  2775 00000F59 B92400                  	mov	cx, 4*18/2
  2776 00000F5C F3AB                    	rep	stosw
  2777                                  
  2778                                  	; 08/03/2019
  2779                                  	; Clear pcount, epnumber values
  2780 00000F5E A3[8E71]                	mov	[pcount], ax ; reset (pcount & ppcount)
  2781 00000F61 A3[9071]                	mov	[apcount], ax ; reset (apcount & epnumber)
  2782                                  B_49:
  2783                                  	; 06/03/2019
  2784 00000F64 C606[AA6E]4D            	mov	byte [pSize_unit], 'M' ; default (for 'whole' disk/space)
  2785                                  	; 15/02/2019
  2786 00000F69 E830F8                  	call	create_partition_input
  2787                                  B_50:		
  2788 00000F6C 21C0                    	and	ax, ax
  2789                                  	;jz	short B_47 ; 0 = none or not a valid input
  2790 00000F6E 0F84A5F4                	jz	A_48 ; 25/02/2019
  2791                                  
  2792                                  	;or	ah, ah
  2793                                  	;jz	short B_51
  2794                                  
  2795                                  	; 23/02/2019
  2796 00000F72 80FC04                  	cmp	ah, 4  ; user's partition type input ?
  2797 00000F75 7505                    	jne	short B_51 ; no
  2798                                  
  2799                                  	; user type input
  2800 00000F77 A2[9E6E]                	mov	[pp_type_user], al
  2801 00000F7A 88E0                    	mov	al, ah ; mov al, 4
  2802                                  B_51:
  2803 00000F7C A2[9D6E]                	mov	[pp_type], al
  2804                                  
  2805                                  	; clear screen
  2806 00000F7F B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
  2807 00000F82 CD10                    	int	10h
  2808                                  
  2809 00000F84 A0[9D6E]                	mov	al, [pp_type]
  2810 00000F87 3C01                    	cmp	al, 1
  2811 00000F89 7705                    	ja	short B_52
  2812                                  
  2813 00000F8B BE[F548]                	mov	si,  msg_create_dos_partition_h ; header
  2814 00000F8E EB69                    	jmp	short B_57
  2815                                  B_52:
  2816 00000F90 3C05                    	cmp	al, 5
  2817 00000F92 7262                    	jb	short B_56
  2818                                  	;ja	short B_55
  2819 00000F94 7741                    	ja	short B_106 ; 26/10/2020
  2820                                  
  2821                                  	; 23/02/2019
  2822 00000F96 BE[EA49]                	mov	si, msg_create_ext_partition_h
  2823 00000F99 E8990E                  	call	print_msg
  2824                                  
  2825                                  	; 24/02/2019
  2826 00000F9C 803E[9171]00            	cmp	byte [epnumber], 0
  2827 00000FA1 7613                    	jna	short B_53	
  2828                                  
  2829 00000FA3 BE[CB60]                	mov	si, msg_ext_partition_exists
  2830 00000FA6 E88C0E                  	call 	print_msg
  2831                                  
  2832 00000FA9 BE[0957]                	mov	si, msg_press_any_key
  2833 00000FAC E8860E                  	call	print_msg
  2834                                  
  2835 00000FAF 30E4                    	xor	ah, ah
  2836 00000FB1 CD16                    	int	16h
  2837                                  
  2838                                  	;jmp	A_33
  2839 00000FB3 E961F4                  	jmp	A_48
  2840                                  B_53:
  2841 00000FB6 803E[8F71]00            	cmp	byte [ppcount], 0  ; primary partition count
  2842 00000FBB 773F                    	ja	short B_58
  2843                                  
  2844                                  	; 09/02/2019
  2845 00000FBD BE[7150]                	mov	si, msg_ext_partition_error
  2846 00000FC0 E8720E                  	call	print_msg
  2847                                  B_54:	
  2848 00000FC3 BE[0957]                	mov	si, msg_press_any_key
  2849 00000FC6 E86C0E                  	call	print_msg
  2850                                  
  2851 00000FC9 30E4                    	xor	ah, ah
  2852 00000FCB CD16                    	int	16h
  2853                                  
  2854 00000FCD C606[9D6E]01            	mov	byte [pp_type], 1
  2855                                  
  2856 00000FD2 E8F2F7                  	call	cpi_2 ; 15/02/2019
  2857 00000FD5 EB95                    	jmp	B_50
  2858                                  B_106:
  2859                                  	; 26/10/2020
  2860 00000FD7 803E[8F71]00            	cmp	byte [ppcount], 0  ; primary partition count
  2861 00000FDC 760A                    	jna	short B_55
  2862 00000FDE 803E[9171]00            	cmp	byte [epnumber], 0  
  2863                                  			; is there an extended partition ? 	
  2864 00000FE3 7603                    	jna	short B_55
  2865 00000FE5 E9B2F4                  	jmp	create_logical_drives
  2866                                  B_55:
  2867 00000FE8 BE[DF4A]                	mov	si, msg_create_logical_drive_h
  2868 00000FEB E8470E                  	call	print_msg
  2869                                  
  2870 00000FEE BE[B050]                	mov	si, msg_logical_drive_error
  2871 00000FF1 E8410E                  	call	print_msg
  2872 00000FF4 EBCD                    	jmp	short B_54
  2873                                  
  2874                                  ;	mov	si, msg_use_entire_ep_space
  2875                                  ;	jmp	short B_60
  2876                                  	
  2877                                  B_56:
  2878 00000FF6 BE[D44B]                	mov	si, msg_create_nondos_partition_h
  2879                                  B_57:
  2880 00000FF9 E8390E                  	call	print_msg
  2881                                  B_58:
  2882                                  	; 15/02/2019
  2883 00000FFC 803E[9D40]00            	cmp	byte [newdisk], 0
  2884 00001001 7705                    	ja	short B_59
  2885                                  
  2886 00001003 BE[094F]                	mov	si, msg_use_all_space
  2887 00001006 EB03                    	jmp	short B_60
  2888                                  B_59:
  2889 00001008 BE[E24E]                	mov	si, msg_use_whole_disk ; partition size: whole disk
  2890                                  B_60:
  2891 0000100B E8270E                  	call	print_msg
  2892                                  B_61:
  2893 0000100E 30E4                    	xor	ah, ah
  2894 00001010 CD16                    	int	16h
  2895                                  
  2896 00001012 3C1B                    	cmp	al, 27 ; ESCAPE key
  2897                                  	;;je	B_47
  2898                                  	;je	A_33
  2899 00001014 0F84FFF3                	je	A_48 ; 25/02/2019
  2900 00001018 24DF                    	and	al, 0DFh
  2901 0000101A 3C4E                    	cmp	al, 'N'
  2902 0000101C 740D                    	je	short B_62  ;02/03/2019
  2903 0000101E 3C59                    	cmp	al, 'Y'
  2904 00001020 75EC                    	jne	short B_61
  2905                                  	
  2906 00001022 FE06[9C6E]              	inc	byte [wholedisk]
  2907                                  	
  2908                                  	; 02/03/2019
  2909 00001026 BE[F25D]                	mov	si, _msg_YES
  2910                                  	;call	print_msg
  2911 00001029 EB03                    	jmp	short B_63	
  2912                                  B_62:
  2913 0000102B BE[F85D]                	mov	si, _msg_NO
  2914                                  B_63:	; 06/03/2019
  2915 0000102E E8040E                  	call	print_msg
  2916                                  
  2917                                  	; 15/02/2019
  2918 00001031 29DB                    	sub	bx, bx
  2919 00001033 381E[9D40]              	cmp	byte [newdisk], bl ; 0
  2920 00001037 7708                    	ja	short B_64 ; 23/02/2019
  2921 00001039 381E[9C6E]              	cmp	byte [wholedisk], bl ; 0
  2922 0000103D 0F870E01                	ja	B_75 ; 23/02/2019
  2923                                  B_64:
  2924                                  	; 08/02/2019
  2925                                  	;sub	bx, bx
  2926 00001041 A1[886E]                	mov	ax, [total_sectors]
  2927 00001044 8B16[8A6E]              	mov	dx, [total_sectors+2]
  2928 00001048 2B06[9640]              	sub	ax, [sectors]
  2929 0000104C 19DA                    	sbb	dx, bx ; sbb dx, 0
  2930                                  
  2931 0000104E A3[986E]                	mov	[pp_Sectors], ax   ; = [total_sectors] - [sectors]
  2932 00001051 8916[9A6E]              	mov	[pp_Sectors+2], dx ; = [total_sectors+2] - carry bit
  2933                                  B_65:
  2934 00001055 381E[9C6E]              	cmp	byte [wholedisk], bl ; 0
  2935 00001059 0F87F900                	ja	B_76 ; 09/02/2019
  2936                                  B_66:
  2937                                  	; clear screen
  2938 0000105D B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
  2939 00001060 CD10                    	int	10h
  2940                                  
  2941 00001062 BE[F548]                	mov	si, msg_create_dos_partition_h ; header
  2942 00001065 E8CD0D                  	call	print_msg
  2943 00001068 BE[864D]                	mov	si, msg_create_trdos_partition_s ; size options
  2944 0000106B E8C70D                  	call	print_msg	
  2945                                  B_67:	
  2946 0000106E 30E4                    	xor	ah, ah
  2947 00001070 CD16                    	int	16h
  2948                                  
  2949                                  	; 24/02/2019
  2950 00001072 3C1B                    	cmp	al, 27	; ESCAPE key 
  2951 00001074 0F849FF3                	je	A_48	; Cancel
  2952                                  
  2953 00001078 3C20                    	cmp	al, 32	; SPACE key
  2954 0000107A 751F                    	jne	short B_69
  2955                                  
  2956                                  		; Entire space
  2957 0000107C A1[986E]                	mov	ax, [pp_Sectors]
  2958 0000107F 8B16[9A6E]              	mov	dx, [pp_Sectors+2]
  2959                                  
  2960 00001083 C606[9C6E]01            	mov 	byte [wholedisk], 1 ; 09/02/2019
  2961 00001088 EB58                    	jmp	short B_71
  2962                                  
  2963                                  B_68:
  2964                                  	; ZERO partition size message
  2965 0000108A BE[055C]                	mov	si, msg_zero_partition_size
  2966 0000108D E8A50D                  	call	print_msg
  2967                                  	
  2968 00001090 30E4                    	xor	ah, ah
  2969 00001092 CD16                    	int	16h
  2970 00001094 3C1B                    	cmp	al, 27 ; ESCAPE key
  2971 00001096 75C5                    	jne	short B_66 ; Retry
  2972                                  
  2973 00001098 E99EFE                  	jmp	B_47 ; exit
  2974                                  
  2975                                  B_69:
  2976 0000109B C606[AA6E]25            	mov	byte [pSize_unit], '%'
  2977 000010A0 3C25                    	cmp	al, '%'
  2978 000010A2 7422                    	je	short B_70
  2979 000010A4 C606[AA6E]53            	mov	byte [pSize_unit], 'S'
  2980 000010A9 3C0D                    	cmp	al, 13 ; 0Dh, Carriage Return key
  2981 000010AB 7419                    	je	short B_70
  2982 000010AD 24DF                    	and	al, 0DFh
  2983 000010AF 3C53                    	cmp	al, 'S'
  2984 000010B1 7413                    	je	short B_70
  2985 000010B3 A2[AA6E]                	mov	[pSize_unit], al
  2986 000010B6 3C4B                    	cmp	al, 'K'
  2987 000010B8 740C                    	je	short B_70
  2988 000010BA 3C4D                    	cmp	al, 'M'
  2989 000010BC 7408                    	je	short B_70
  2990 000010BE 3C47                    	cmp	al, 'G'
  2991 000010C0 7404                    	je	short B_70
  2992 000010C2 3C43                    	cmp	al, 'C'
  2993 000010C4 75A8                    	jne	short B_67
  2994                                  B_70:
  2995 000010C6 C606[EF65]73            	mov	byte [msg_sectors_crlf_s], 's' ; " sectors"
  2996                                  
  2997 000010CB E8AE0F                  	call	partition_size_input
  2998                                  	;jc	B_47 ; exit if partition size input is 0
  2999 000010CE 72BA                    	jc	short B_68
  3000                                  
  3001 000010D0 21DB                    	and	bx, bx ; bx_dx_ax = partition size
  3002                                  	;jnz	short B_77
  3003                                  	; 23/02/2019 
  3004 000010D2 7540                    	jnz	short B_72 ; invalid! (use maximum available sectors)
  3005                                  
  3006                                  	; 08/02/2019
  3007 000010D4 09D2                    	or	dx, dx
  3008 000010D6 750A                    	jnz	short B_71 ; proper size (for now)
  3009                                  
  3010 000010D8 8B1E[C26E]              	mov	bx, [min_sectors] ; minimum sectors
  3011 000010DC 39C3                    	cmp	bx, ax
  3012 000010DE 7602                    	jna	short B_71 ; proper size (for now)	 
  3013                                  
  3014                                  	; invalid! (use minimum sectors or sectors per cylinder)
  3015 000010E0 89D8                    	mov	ax, bx
  3016                                  B_71:
  3017                                  	; 09/02/2019
  3018                                  	; save dx,ax
  3019 000010E2 8916[CA6E]              	mov	[ppn_Sectors+2], dx
  3020 000010E6 A3[C86E]                	mov	[ppn_Sectors], ax
  3021                                  
  3022                                  	; write partition size
  3023                                  	;push	dx
  3024                                  	;push	ax
  3025 000010E9 BE[B76E]                	mov	si, msg_partition_sectors + 7 ; max. 7 digits
  3026 000010EC E8CE0D                  	call	bin_to_decimal
  3027                                  	; ds:si = beginning of decimal number text
  3028 000010EF E8430D                  	call	print_msg
  3029 000010F2 BE[E865]                	mov	si, msg_sectors_crlf
  3030 000010F5 E83D0D                  	call	print_msg
  3031                                  	;pop	ax
  3032                                  	;pop	dx
  3033                                  
  3034 000010F8 803E[9C6E]00            	cmp	byte [wholedisk], 0
  3035 000010FD 775E                    	ja	short B_77 ; 09/02/2019
  3036                                  
  3037                                  	; restore ax,dx
  3038 000010FF A1[C86E]                	mov	ax, [ppn_Sectors]
  3039 00001102 8B16[CA6E]              	mov	dx, [ppn_Sectors+2]
  3040                                  
  3041                                  	; select whole disk 
  3042                                  	;   if partition size > disk size
  3043 00001106 3B16[9A6E]              	cmp	dx, [pp_Sectors+2]
  3044 0000110A 7708                    	ja	short B_72
  3045 0000110C 724F                    	jb	short B_77
  3046 0000110E 3B06[986E]              	cmp	ax, [pp_Sectors]
  3047 00001112 7649                    	jna	short B_77
  3048                                  B_72:
  3049 00001114 803E[9D40]00            	cmp	byte [newdisk], 0
  3050 00001119 7667                    	jna	short B_78
  3051                                  
  3052                                  	; "use whole disk or go to back" question
  3053 0000111B BE[0750]                	mov	si, msg_partition_size_overs
  3054                                  B_73:
  3055 0000111E E8140D                  	call	print_msg
  3056                                  B_74:
  3057 00001121 30E4                    	xor	ah, ah
  3058 00001123 CD16                    	int	16h
  3059                                  	
  3060 00001125 3C1B                    	cmp	al, 27 ; ESCAPE key
  3061                                  	;je	B_49
  3062 00001127 0F8432FF                	je	B_66 ; 09/02/2019
  3063 0000112B 3C0D                    	cmp	al, 13 ; ENTER (Carriage Return) key
  3064 0000112D 75F2                    	jne	short B_74
  3065                                  
  3066 0000112F FE06[9C6E]              	inc	byte [wholedisk]
  3067                                  
  3068                                  	; 24/02/2019
  3069 00001133 803E[9D40]00            	cmp	byte [newdisk], 0
  3070 00001138 7715                    	ja	short B_75
  3071                                  
  3072 0000113A 8B1E[2C72]              	mov	bx, [c_fspc_offset]
  3073 0000113E 8B87[E271]              	mov	ax, [free_space.sectors_unused+bx]
  3074 00001142 8B97[E471]              	mov	dx, [free_space.sectors_unused+bx+2]
  3075 00001146 A3[986E]                	mov	[pp_Sectors], ax
  3076 00001149 8916[9A6E]              	mov	[pp_Sectors+2], dx
  3077 0000114D EB07                    	jmp	short B_76 
  3078                                  B_75:
  3079                                  	; 09/02/2019
  3080 0000114F 8B16[9A6E]              	mov	dx, [pp_Sectors+2]
  3081 00001153 A1[986E]                	mov	ax, [pp_Sectors]
  3082                                  B_76:
  3083 00001156 8916[CA6E]              	mov	[ppn_Sectors+2], dx
  3084 0000115A A3[C86E]                	mov	[ppn_Sectors], ax
  3085                                  B_77:
  3086 0000115D 803E[9D6E]05            	cmp	byte [pp_type], 5
  3087 00001162 0F853601                	jne	B_99
  3088                                  
  3089 00001166 803E[8F71]00            	cmp	byte [ppcount], 0  ; primary partition count
  3090 0000116B 0F87C500                	ja	B_93
  3091                                  
  3092 0000116F BE[7150]                	mov	si, msg_ext_partition_error
  3093 00001172 E8C00C                  	call	print_msg
  3094 00001175 BE[EA4F]                	mov	si, msg_any_key_to_retry
  3095 00001178 E8BA0C                  	call	print_msg
  3096                                  
  3097                                  	; 09/02/2019
  3098 0000117B 30E4                    	xor	ah, ah
  3099 0000117D CD16                    	int	16h
  3100                                  
  3101                                  	;jmp	B_49
  3102 0000117F E945F6                  	jmp	cpi_2 
  3103                                  
  3104                                  B_78:
  3105                                  	; clear screen
  3106 00001182 B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
  3107 00001185 CD10                    	int	10h
  3108                                  
  3109 00001187 BE[F548]                	mov	si, msg_create_dos_partition_h ; header
  3110 0000118A E8A80C                  	call	print_msg
  3111                                  
  3112 0000118D BE[B75F]                	mov	si, msg_partition_size_limit
  3113 00001190 E8A20C                  	call	print_msg
  3114                                  
  3115 00001193 8B1E[2C72]              	mov	bx, [c_fspc_offset]
  3116                                  
  3117 00001197 803E[AA6E]53            	cmp	byte [pSize_unit], 'S'
  3118 0000119C 7415                    	je	short B_79
  3119 0000119E 803E[AA6E]4B            	cmp	byte [pSize_unit], 'K'
  3120 000011A3 740E                    	je	short B_79
  3121                                  
  3122 000011A5 803E[AA6E]25            	cmp	byte [pSize_unit], '%'
  3123 000011AA 7469                    	je	short B_89
  3124                                  
  3125 000011AC 803E[AA6E]43            	cmp	byte [pSize_unit], 'C'
  3126 000011B1 7479                    	je	B_92
  3127                                  B_79:
  3128                                  	; 'S', 'K'
  3129 000011B3 81C3[E271]              	add	bx, free_space.sectors_unused	
  3130 000011B7 8B07                    	mov	ax, [bx]
  3131 000011B9 8B5702                  	mov	dx, [bx+2]
  3132                                  		
  3133 000011BC B90A00                  	mov	cx, 10
  3134 000011BF 89E5                    	mov	bp, sp
  3135                                  B_80:
  3136 000011C1 E872FC                  	call	div32
  3137 000011C4 53                      	push	bx
  3138 000011C5 09D2                    	or	dx, dx
  3139 000011C7 75F8                    	jnz	short B_80
  3140 000011C9 83F809                  	cmp	ax, 9
  3141 000011CC 77F3                    	ja	short B_80
  3142                                  B_81:
  3143 000011CE BB0700                  	mov	bx, 07h
  3144 000011D1 09C0                    	or	ax, ax
  3145 000011D3 7501                    	jnz	short B_83
  3146                                  B_82:
  3147 000011D5 58                      	pop	ax
  3148                                  B_83:
  3149 000011D6 0430                    	add	al, '0'
  3150                                  B_84:
  3151 000011D8 B40E                    	mov	ah, 0Eh
  3152                                  	;mov	bx, 07h
  3153 000011DA CD10                    	int	10h	; write character (as tty)
  3154                                  
  3155 000011DC 39EC                    	cmp	sp, bp			
  3156 000011DE 72F5                    	jb	short B_82
  3157                                  
  3158 000011E0 803E[AA6E]53            	cmp	byte [pSize_unit], 'S'
  3159 000011E5 7422                    	je	short B_86
  3160 000011E7 803E[AA6E]4B            	cmp	byte [pSize_unit], 'K'
  3161 000011EC 741B                    	je	short B_86
  3162                                  
  3163 000011EE 803E[AA6E]25            	cmp	byte [pSize_unit], '%'
  3164 000011F3 7508                    	jne	short B_85
  3165                                  
  3166                                  	; 24/02/2019
  3167 000011F5 3C25                    	cmp	al, '%'
  3168 000011F7 7416                    	je	short B_88
  3169 000011F9 B025                    	mov	al, '%'
  3170 000011FB EBDB                    	jmp	short B_84 
  3171                                  B_85:
  3172 000011FD 803E[AA6E]43            	cmp	byte [pSize_unit], 'C'
  3173 00001202 7505                    	jne	short B_86
  3174                                  
  3175 00001204 BE[5360]                	mov	si, msg_cylinders
  3176 00001207 EB03                    	jmp	short B_87
  3177                                  B_86:
  3178 00001209 BE[5E60]                	mov	si, msg_sectors
  3179                                  B_87:
  3180 0000120C E8260C                  	call	print_msg
  3181                                  B_88:
  3182 0000120F BE[0460]                	mov	si, msg_partition_size_limit_r
  3183                                  	;call	print_msg
  3184                                  
  3185 00001212 E909FF                  	jmp	B_73
  3186                                  
  3187                                  B_89:
  3188                                  	; '%'
  3189 00001215 81C3[E071]              	add	bx, free_space.percent_unused
  3190 00001219 8B07                    	mov	ax, [bx]
  3191                                  B_90:	
  3192 0000121B 89E5                    	mov	bp, sp
  3193                                  B_91:	
  3194 0000121D 31D2                    	xor	dx, dx
  3195 0000121F B90A00                  	mov	cx, 10
  3196 00001222 F7F1                    	div	cx
  3197 00001224 52                      	push	dx
  3198 00001225 83F809                  	cmp	ax, 9
  3199 00001228 77F3                    	ja	short B_91	
  3200 0000122A EBA2                    	jmp	short B_81
  3201                                  B_92:
  3202                                  	; 'C'
  3203 0000122C 81C3[DA71]              	add	bx, free_space.space
  3204 00001230 8B07                    	mov	ax, [bx]
  3205 00001232 EBE7                    	jmp	short B_90
  3206                                  
  3207                                  B_93:
  3208                                  	; 23/02/2019
  3209 00001234 8B1E[2C72]              	mov	bx, [c_fspc_offset]
  3210 00001238 8B87[DC71]              	mov	ax, [bx+free_space.start]
  3211                                  
  3212                                  	; set free space start cylinder to 1 if it is 0
  3213 0000123C 09C0                    	or	ax, ax
  3214 0000123E 750F                    	jnz	short B_94
  3215                                  
  3216 00001240 B005                    	mov	al, 5	; Get free space for extended partition
  3217 00001242 E88214                  	call	find_part_free_space
  3218                                  
  3219 00001245 891E[2C72]              	mov	[c_fspc_offset], bx
  3220                                  
  3221 00001249 21C9                    	and	cx, cx
  3222 0000124B 0F843AF2                	jz	cp_4	; there is not free space on disk
  3223                                  B_94:
  3224                                  	; 24/02/2019
  3225 0000124F E81100                  	call	partition_size_fixup_x
  3226 00001252 0F822CFF                	jc	B_78
  3227                                  
  3228                                  	; 16/02/2019
  3229 00001256 E8F8F7                  	call	create_extended_partition 
  3230                                  			; must be called after 'find_part_free_space'.
  3231                                  	; 24/02/2019
  3232 00001259 E8DA10                  	call	show_selected_partition
  3233 0000125C E9BE00                  	jmp	C_02
  3234                                  
  3235                                  partition_size_fixup:
  3236                                  	; 24/02/2019
  3237 0000125F 8B1E[2C72]              	mov	bx, [c_fspc_offset]
  3238                                  partition_size_fixup_x:
  3239                                  	; 25/02/2019 
  3240 00001263 803E[9D40]00            	cmp	byte [newdisk], 0
  3241 00001268 7731                    	ja	short B_98
  3242                                  
  3243 0000126A 81C3[E271]              	add	bx, free_space.sectors_unused	
  3244 0000126E 8B07                    	mov	ax, [bx]
  3245 00001270 8B5702                  	mov	dx, [bx+2]
  3246                                  
  3247 00001273 3B16[CA6E]              	cmp	dx, [ppn_Sectors+2]
  3248 00001277 7222                    	jb	short B_98 ; 24/02/2019
  3249 00001279 7708                    	ja	short B_95
  3250 0000127B 3B06[C86E]              	cmp	ax, [ppn_Sectors]
  3251 0000127F 721A                    	jb	short B_98 ; 24/02/2019
  3252 00001281 7411                    	je	short B_97
  3253                                  
  3254                                  B_95:
  3255                                  	; 19/02/2019
  3256 00001283 A1[C86E]                	mov	ax, [ppn_Sectors]
  3257                                  B_96:
  3258 00001286 8B16[CA6E]              	mov	dx, [ppn_Sectors+2]
  3259                                  
  3260                                  	; 18/02/2019
  3261                                  
  3262                                  	; check for best fit
  3263                                  	; (leave max. available space to next time if 
  3264                                  	;  another space/gap fits to partition size request.)
  3265                                  
  3266 0000128A E85416                  	call	find_enough_free_sectors
  3267                                  		; CX = Free space index (0 to 4)
  3268                                  		; DX:AX = First available space which fits to request
  3269                                  	;mov	bx, cx
  3270                                  	;shl	bl, 4 ; * 16  ; * Free space structure size
  3271                                  	;mov	[c_fspc_offset], bx
  3272                                  	
  3273                                  	; 22/02/2019
  3274 0000128D C0E104                  	shl	cl, 4
  3275 00001290 890E[2C72]              	mov	[c_fspc_offset], cx 
  3276                                  
  3277                                  	;add	bx, free_space.sectors_unused	
  3278                                  	;mov	ax, [bx]
  3279                                  	;mov	dx, [bx+2]
  3280                                  B_97:		
  3281                                  	; Save max. available space
  3282 00001294 A3[986E]                	mov	[pp_Sectors], ax
  3283 00001297 8916[9A6E]              	mov	[pp_Sectors+2], dx
  3284                                  B_98:
  3285 0000129B C3                      	retn
  3286                                  
  3287                                  B_99:
  3288                                  	; 24/02/2019
  3289 0000129C E8C0FF                  	call	partition_size_fixup
  3290 0000129F 0F82DFFE                	jc	B_78
  3291                                  
  3292                                  	 ; 16/02/2019
  3293                                  	; Force cylinder boundary alignment except
  3294                                  	;   sectors ('S') and kilobytes ('K') as sizing unit.
  3295                                  
  3296 000012A3 C606[2E72]59            	mov	byte [cylinder_boundary], 'Y' ; Default
  3297                                  				; sizing unit is one of
  3298                                  				; 'cylinders','megabytes','gigabytes'
  3299                                  				; and boundary alignment is yes for them.
  3300 000012A8 A0[AA6E]                	mov	al, [pSize_unit]
  3301                                  
  3302                                  	;cmp	byte [pSize_unit], 'S' ; Sectors
  3303 000012AB 3C53                    	cmp	al, 'S'
  3304 000012AD 7404                    	je	short B_100
  3305                                  
  3306                                  	;cmp	byte [pSize_unit], 'K' ; Kilobytes
  3307 000012AF 3C4B                    	cmp	al, 'K'
  3308 000012B1 752F                    	jne	short B_104
  3309                                  B_100:
  3310                                  	; Sizing unit is one of 'sectors' and/or 'kilobytes'
  3311                                  	; and bound aligment will be applied if the answer will be yes. 
  3312                                  
  3313 000012B3 BE[F950]                	mov	si, msg_cylinder_boundary_set
  3314 000012B6 E87C0B                  	call	print_msg
  3315                                  B_101:
  3316 000012B9 30E4                    	xor	ah, ah
  3317 000012BB CD16                    	int	16h
  3318                                  	; Cylinder boundary adjusting
  3319 000012BD 3C0D                    	cmp	al, 13 ; ENTER key
  3320 000012BF 74F2                    	je	short B_100
  3321 000012C1 3C1B                    	cmp	al, 27 ; ESCAPE key
  3322 000012C3 741A                    	je	short B_103	; Align end of the partition only
  3323                                  				; if start of the partition is aligned
  3324                                  				; or it starts at cyl 0, head 1, sect 17 or 63.
  3325                                  				; (End of the partition will be extended to
  3326                                  				; end sector of it's last cylinder if the size
  3327                                  				; will not over [pp_Sectors] value.)  	 
  3328 000012C5 24DF                    	and	al, 0DFh
  3329                                  
  3330                                  	; 22/02/2019
  3331 000012C7 3C59                    	cmp	al, 'Y'
  3332 000012C9 7508                    	jne	short B_102
  3333                                  
  3334 000012CB BE[F25D]                	mov	si, _msg_YES
  3335 000012CE E8640B                  	call	print_msg
  3336                                  
  3337                                  	;mov	al, 'Y'
  3338                                  	;jmp	short B_103
  3339 000012D1 EB0F                    	jmp	short B_104
  3340                                  B_102:
  3341 000012D3 3C4E                    	cmp	al, 'N'
  3342 000012D5 75E2                    	jne	short B_101
  3343                                  
  3344 000012D7 BE[F85D]                	mov	si, _msg_NO
  3345 000012DA E8580B                  	call	print_msg
  3346                                  
  3347 000012DD B04E                    	mov	al, 'N'
  3348                                  		; do not align partition to cylinder boundary 
  3349                                  B_103:
  3350 000012DF A2[2E72]                	mov	[cylinder_boundary], al
  3351                                  B_104:
  3352 000012E2 E832F5                  	call	create_primary_partition
  3353                                  	
  3354                                  	; 18/02/2019
  3355 000012E5 803E[9D40]00            	cmp	byte [newdisk], 0
  3356 000012EA 760E                    	jna	short B_105
  3357                                  
  3358 000012EC 31C0                    	xor	ax, ax ; 0
  3359 000012EE 31D2                    	xor	dx, dx ; 0
  3360                                  	; DX_AX = Masterboot Sector = 0
  3361 000012F0 BB[2857]                	mov	bx, MasterBootBuff
  3362                                  	; ES:BX = Sector Buffer
  3363 000012F3 E84E0B                  	call	write_hd_sector
  3364 000012F6 0F821B0B                	jc	D_01
  3365                                  
  3366                                  B_105:
  3367                                  	; DS:SI = Partition Table Entry address
  3368                                  	; 25/02/2019
  3369 000012FA 8936[5072]              	mov	[pte_address], si  ; save PTE address
  3370 000012FE E83510                  	call	show_selected_partition
  3371                                  
  3372                                  	;jmp	C_01
  3373                                  
  3374                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3375                                  ; Format question
  3376                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3377                                  
  3378                                  C_01:
  3379                                  	;mov	si, CRLF
  3380                                  	;call	print_msg
  3381                                  
  3382 00001301 C606[B96E]01            	mov	byte [format_q], 1
  3383                                  
  3384 00001306 A0[9D6E]                	mov	al, [pp_type]
  3385 00001309 3C01                    	cmp	al, 1		; FAT12 (CHS)
  3386 0000130B 741D                    	je	short C_03
  3387 0000130D 3C04                    	cmp	al, 4		; FAT16 CHS
  3388 0000130F 7419                    	je	short C_03
  3389 00001311 3C06                    	cmp	al, 6		; FAT16 BIG CHS
  3390 00001313 7415                    	je	short C_03
  3391 00001315 3C0B                    	cmp	al, 0Bh		; FAT32 CHS
  3392 00001317 7411                    	je	short C_03
  3393 00001319 3CA1                    	cmp	al, 0A1h	; SINGLIX FS1
  3394 0000131B 740D                    	je	short C_03
  3395                                  
  3396                                  	;cmp	al, 71h
  3397                                  	;je	short C_03	; RETRO UNIX 386
  3398                                  
  3399                                  	;dec	byte [format_q] ; 0		
  3400                                  C_02:
  3401 0000131D C606[B96E]00            	mov	byte [format_q], 0 ; 24/02/2019
  3402                                  
  3403                                  	; NON-DOS partition!
  3404                                  	; Ask for editing PT or exit (continue without formatting)
  3405 00001322 BE[7F54]                	mov	si, msg_edit_or_exit
  3406 00001325 E80D0B                  	call	print_msg
  3407 00001328 EB06                    	jmp	short C_04
  3408                                  C_03:
  3409                                  	; Ask for formatting, editing PT or exit
  3410 0000132A BE[1054]                	mov	si, msg_format_stage
  3411 0000132D E8050B                  	call	print_msg
  3412                                  C_04:
  3413 00001330 BE[5054]                	mov	si, msg_partition_edit
  3414 00001333 E8FF0A                  	call	print_msg
  3415                                  C_05:
  3416 00001336 28E4                    	sub	ah, ah
  3417 00001338 CD16                    	int	16h
  3418                                  
  3419 0000133A 3C0D                    	cmp	al, 13
  3420 0000133C 7452                    	je	short C_08
  3421                                  
  3422                                  	;; 07/03/2019
  3423 0000133E 3C20                    	cmp	al, 20h ; SPACE
  3424                                  	;je	A_27 ; edit partition table option is selected
  3425 00001340 7406                    	je	short C_06 ; 08/03/2019	
  3426                                  
  3427 00001342 3C1B                    	cmp	al, 27 ; ESCAPE
  3428 00001344 75F0                    	jne	short C_05
  3429                                  	
  3430 00001346 30C0                    	xor	al, al ; 08/03/2019 
  3431                                  Exit:
  3432                                  C_06:
  3433 00001348 50                      	push	ax ; 08/03/2019
  3434 00001349 B43E                    	mov	ah, 3Eh ; close file
  3435 0000134B 8B1E[9440]              	mov	bx, [img_file_handle]
  3436 0000134F CD21                    	int	21h
  3437                                  	; 08/03/2019
  3438 00001351 58                      	pop	ax
  3439                                  	;cmp	al, 27
  3440                                  	;je	short C_06_exit
  3441 00001352 08C0                    	or	al, al
  3442 00001354 7409                    	jz	short C_06_exit
  3443 00001356 C706[9440]0000          	mov 	word [img_file_handle], 0
  3444 0000135C E9DBEE                  	jmp	A_27
  3445                                  
  3446                                  C_06_exit:
  3447 0000135F BE[5056]                	mov	si, CRLF
  3448 00001362 E8D00A                  	call	print_msg
  3449                                  
  3450                                  	; 11/02/2019
  3451                                   
  3452                                  	; Exit	
  3453 00001365 CD20                    	int	20h
  3454                                  
  3455                                  save_mbr_exit:
  3456                                  	; 24/02/2019
  3457 00001367 E8B111                  	call	init_partition_tables
  3458                                  
  3459 0000136A E82016                  	call	display_partition_table
  3460                                  
  3461 0000136D BE[5056]                	mov	si, CRLF
  3462 00001370 E8C20A                  	call	print_msg
  3463                                  
  3464 00001373 BE[0455]                	mov	si, msg_writing_mbr
  3465 00001376 E8BC0A                  	call	print_msg
  3466                                  
  3467 00001379 31C0                    	xor	ax, ax ; 0
  3468 0000137B 31D2                    	xor	dx, dx ; 0
  3469                                  	; DX_AX = Masterboot Sector = 0
  3470 0000137D BB[2857]                	mov	bx, MasterBootBuff
  3471                                  	; ES:BX = Sector Buffer
  3472 00001380 E8C10A                  	call	write_hd_sector
  3473 00001383 7303                    	jnc	short C_07
  3474 00001385 E98D0A                  	jmp	D_01
  3475                                  C_07:
  3476 00001388 BE[4C56]                	mov	si, Msg_OK
  3477 0000138B E8A70A                  	call	print_msg
  3478 0000138E EBB8                    	jmp	short Exit
  3479                                  
  3480                                  C_08:
  3481 00001390 803E[B96E]01            	cmp	byte [format_q], 1
  3482 00001395 72D0                    	jb	short save_mbr_exit
  3483                                  
  3484                                  	; 25/02/2019
  3485                                  	; Write MBR without writing message
  3486                                  	
  3487                                  	; NOTE: This may be second time of MBR writing...
  3488                                  	;	but, if partition table is modified,
  3489                                  	;	we need to write MBR to disk, here.
  3490                                  	;
  3491                                  	; (Otherwise.. the last created partition would not be recorded.) 	
  3492                                  
  3493 00001397 31C0                    	xor	ax, ax ; 0
  3494 00001399 31D2                    	xor	dx, dx ; 0
  3495                                  	; DX_AX = Masterboot Sector = 0
  3496 0000139B BB[2857]                	mov	bx, MasterBootBuff
  3497                                  	; ES:BX = Sector Buffer
  3498 0000139E E8A30A                  	call	write_hd_sector
  3499 000013A1 0F82700A                	jc	D_01
  3500                                  
  3501                                  	;; clear screen
  3502                                  	;mov	ax, 3 ; set video mode to 03h (80x25 text)
  3503                                  	;int	10h
  3504                                  
  3505                                  	; 25/02/2019
  3506 000013A5 8B36[5072]              	mov	si, [pte_address]
  3507                                  
  3508                                  	; 18/02/2019
  3509 000013A9 E88A0F                  	call	show_selected_partition	
  3510                                  
  3511 000013AC A0[3754]                	mov	al, [partition_num_chr]
  3512 000013AF A2[F754]                	mov	[partition_num_txt], al
  3513                                  
  3514 000013B2 BE[D554]                	mov	si, msg_format_question
  3515 000013B5 E87D0A                  	call	print_msg
  3516                                  C_09:
  3517 000013B8 30E4                    	xor	ah, ah
  3518 000013BA CD16                    	int	16h
  3519                                  
  3520 000013BC 3C1B                    	cmp	al, 1Bh ; ESCAPE
  3521 000013BE 7488                    	je	short C_06
  3522                                  
  3523 000013C0 24DF                    	and	al, 0DFh ; capitalization
  3524 000013C2 3C59                    	cmp	al, 'Y'
  3525 000013C4 740C                    	je	short C_10
  3526 000013C6 3C4E                    	cmp	al, 'N'
  3527 000013C8 75EE                    	jne	short C_09
  3528 000013CA BE[F85D]                	mov	si, _msg_NO 
  3529 000013CD E8650A                  	call	print_msg
  3530                                  	;jmp	short C_06
  3531                                  	; 24/02/2019
  3532 000013D0 EB95                    	jmp	short save_mbr_exit 
  3533                                  C_10:
  3534 000013D2 BE[F25D]                	mov	si, _msg_YES
  3535 000013D5 E85D0A                  	call	print_msg
  3536                                  
  3537                                  	; [pp_StartSector] = partition's start sector
  3538                                  	; [pp_Sectors] = partition size including start & end sector	
  3539                                  	; [partition_num_chr] = partition number + '0'
  3540                                  	; [pp_type] = partition type (for TRDOS 386 boot sector) 
  3541                                  
  3542 000013D8 8926[0A6A]              	mov	[old_sp], sp
  3543                                  	
  3544 000013DC 8A16[9D6E]              	mov	dl, [pp_type]
  3545                                  	; DL = partition type (file system ID)
  3546                                  	;dec	dl
  3547                                  	;jz	FAT12_hdi_format
  3548 000013E0 80FA01                  	cmp	dl, 1 ; 14/09/2020 (BugFix)
  3549 000013E3 0F86D805                	jna	FAT12_hdi_format
  3550                                  	;cmp	dl, 4
  3551                                  	;je	FAT16_hdi_format
  3552                                  	;cmp	dl, 6
  3553                                  	;je	FAT16_hdi_format
  3554 000013E7 80FA0B                  	cmp	dl, 0Bh 
  3555 000013EA 0F82D503                	jb	FAT16_hdi_format
  3556                                  	;je	short FAT32_hdi_format	
  3557                                  	;cmp	dl, 0Ch ; 14/09/2020
  3558 000013EE 0F876507                	ja	SINGLIX_hdi_format
  3559                                  
  3560                                  	;cmp	dl, 0A1h
  3561                                  	;je	SINGLIX_hdi_format
  3562                                  	;jb	RUNIX386_hdi_format ; dl = 071h
  3563                                  
  3564                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3565                                  ; FAT32 FORMATTING
  3566                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 	
  3567                                  	
  3568                                  	; 08/02/2019 (Modified for -only- FAT32 CHS partitions) 
  3569                                  FAT32_hdi_format:
  3570                                  	;mov	ax, 000Ch ; db 0Ch, 00h ; 'or al, 0'
  3571                                  	;cmp	dl, al ; 0Ch
  3572                                  	;je	short FAT32_lba_format
  3573                                  	;mov	ax, 0C00Bh ; db 0Bh, 0C0h ; 'or ax, ax'
  3574                                  ;FAT32_lba_format:
  3575                                  	; Put TRDOS 386 FAT32 partition magic word 
  3576                                  	; at offset 5Ah, in TRDOS386 FAT32 boot sector 0.
  3577 000013F2 BD[8234]                	mov	bp, TRDOS_FAT32_hd_bs
  3578 000013F5 8D7E03                  	lea	di, [bp+3]
  3579 000013F8 BE[F465]                	mov	si, bs_oem_name
  3580 000013FB B90400                  	mov	cx, 4
  3581 000013FE F3A5                    	rep	movsw 
  3582                                  	;mov	[bp+5Ah], ax	; [loc_5A]
  3583 00001400 C7465A0BC0              	mov	word [bp+5Ah], 0C00Bh ; 08/02/2019
  3584 00001405 A1[9640]                	mov	ax, [sectors]
  3585 00001408 894618                  	mov	[bp+18h], ax	; [BPB_SecPerTrk]
  3586 0000140B A1[9840]                	mov	ax, [heads]
  3587 0000140E 89461A                  	mov	[bp+1Ah], ax	; [BPB_NumHeads]
  3588 00001411 A1[946E]                	mov	ax, [pp_StartSector]
  3589 00001414 89461C                  	mov	[bp+1Ch], ax	; [BPB_HiddSec]
  3590 00001417 A1[966E]                	mov	ax, [pp_StartSector+2]
  3591 0000141A 89461E                  	mov	[bp+1Eh], ax	; [BPB_HiddSec+2]
  3592                                  	;mov	ax, [pp_Sectors]
  3593 0000141D A1[C86E]                	mov	ax, [ppn_Sectors] ; 16/02/2019
  3594 00001420 894620                  	mov	[bp+20h], ax	; [BPB_TotSec32]
  3595                                  	;mov	dx, [pp_Sectors+2]
  3596 00001423 8B16[CA6E]              	mov	dx, [ppn_Sectors+2] ; 16/02/2019
  3597 00001427 895622                  	mov	[bp+22h], dx	; [BPB_TotSec32+2]
  3598                                  	
  3599                                  	; Sectors per cluster calculation
  3600                                  	; (According to MS FAT32 FS specification.)
  3601 0000142A B108                    	mov	cl, 8  ; 8 sectors per cluster
  3602 0000142C 83FA08                  	cmp	dx, 8  ; >= 532480 sectors
  3603 0000142F 7709                    	ja	short FAT32_f_2 ; 8 sectors per cluster
  3604 00001431 7205                    	jb	short FAT32_f_1 ; 1 sector per cluster	
  3605 00001433 3D0020                  	cmp	ax, 2000h ; dx_ax = (8*65536)+8192
  3606 00001436 7302                    	jnb	short FAT32_f_2 ; 12/09/2020 (BugFix)
  3607                                  FAT32_f_1:
  3608 00001438 B101                    	mov	cl, 1	; 1 sector per cluster		
  3609                                  FAT32_f_2:
  3610 0000143A 884E0D                  	mov	[bp+0Dh], cl	 ; [BPB_SecPerClus]
  3611                                  	;mov	byte [bp+10h], 2 ; [BPB_NumFATs] 
  3612                                  	;mov	word [bp+0Eh], 32 ; [BPB_RsvdSecCnt] 
  3613                                  
  3614                                  	; Calculating FAT size in sectors
  3615                                  	; (According to MS FAT32 FS Specification, 2000)
  3616                                  
  3617                                  	; DX_AX = partition (volume) size in sectors
  3618 0000143D 2B460E                  	sub	ax, [bp+0Eh]	; [BPB_RsvdSecCnt] ; 32
  3619 00001440 83DA00                  	sbb	dx, 0
  3620                                  		; TmpVal1 = DiskSize - (BPB_ResvdSecCnt +
  3621                                  		;	     		RootDirsectors)
  3622                                  		; RootDirSectors = 0 (for FAT32 FS)
  3623 00001443 89CB                    	mov	bx, cx ; ch = 0
  3624 00001445 C1E308                  	shl	bx, 8 ; * 256
  3625 00001448 8A4E10                  	mov	cl, [bp+10h] ; [BPB_NumFATs] 
  3626 0000144B 01CB                    	add	bx, cx	
  3627                                  		; TmpVal2 = (256*BPB_SecPerClus)+BPB_NumFATs
  3628 0000144D D1EB                    	shr	bx, 1
  3629                                  		; TmpVal2 = TmpVal2/2
  3630 0000144F 89D9                    	mov	cx, bx
  3631 00001451 4B                      	dec	bx  ; TmpVal2-1
  3632 00001452 01D8                    	add	ax, bx
  3633 00001454 83D200                  	adc	dx, 0
  3634 00001457 E8DCF9                  	call	div32
  3635                                  		; FATSz = (TmpVal1+(TmpVal2-1))/TmpVal2
  3636                                  	; DX_AX = FAT size in sectors
  3637 0000145A 894624                  	mov	[bp+24h], ax	; [BPB_FATSz32]
  3638 0000145D 895626                  	mov	[bp+26h], dx	; [BPB_FATSz32+2]
  3639                                  	; * 2
  3640 00001460 89D3                    	mov	bx, dx
  3641 00001462 01C0                    	add	ax, ax
  3642 00001464 11D3                    	adc	bx, dx
  3643                                  	; BX_AX = [BPB_NumFATs] * [BPB_FATSz32]
  3644 00001466 8B4E0E                  	mov	cx, [bp+0Eh]	; [BPB_RsvdSecCnt] ; 32
  3645 00001469 01C1                    	add	cx, ax
  3646 0000146B 83D300                  	adc	bx, 0
  3647                                  	; BX_CX = [BPB_RsvdSecCnt]+[BPB_NumFATs]*[BPB_FATSz32]
  3648 0000146E 8B4620                  	mov	ax, [bp+20h]	; [BPB_TotSec32]
  3649 00001471 8B5622                  	mov	dx, [bp+22h]	; [BPB_TotSec32+2]
  3650 00001474 29C8                    	sub	ax, cx
  3651 00001476 19DA                    	sbb	dx, bx
  3652 00001478 890E[0C6C]              	mov	[data_start], cx
  3653 0000147C 891E[0E6C]              	mov	[data_start+2], bx
  3654                                  	; DX_AX = Data sectors
  3655 00001480 A3[106C]                	mov	[data_sectors], ax
  3656 00001483 8916[126C]              	mov	[data_sectors+2], dx
  3657 00001487 8A4E0D                  	mov	cl, [bp+0Dh]	 ; [BPB_SecPerClus]
  3658 0000148A 30ED                    	xor	ch, ch
  3659 0000148C E8A7F9                  	call	div32 ; DX_AX/CX
  3660                                  	; DX_AX = Count of clusters (rounded down)
  3661 0000148F A3[146C]                	mov	[cluster_count], ax
  3662 00001492 8916[166C]              	mov	[cluster_count+2], dx
  3663                                  		
  3664 00001496 8D7E47                  	lea	di, [bp+71] ; [BS_VolLab]
  3665 00001499 E89E01                  	call	write_volume_name
  3666 0000149C 8D7643                  	lea	si, [bp+67] ; [BS_VolID]
  3667 0000149F E8F701                  	call	write_volume_serial
  3668 000014A2 E80703                  	call	write_cluster_count
  3669                                  
  3670 000014A5 E87802                  	call	write_formatting_msg
  3671 000014A8 B000                    	mov	al, 0
  3672 000014AA E8D002                  	call	write_format_percent_x
  3673                                  
  3674 000014AD 8B461C                  	mov	ax, [bp+1Ch]	; [BPB_HiddSec]
  3675 000014B0 8B561E                  	mov	dx, [bp+1Eh]	; [BPB_HiddSec+2]
  3676 000014B3 0106[0C6C]              	add	[data_start], ax
  3677 000014B7 1116[0E6C]              	adc	[data_start+2], dx
  3678                                  FAT32_f_3:
  3679                                  	; DX_AX = FAT32 Boot Sector address
  3680 000014BB BB[8234]                	mov	bx, TRDOS_FAT32_hd_bs
  3681                                  	; ES:BX = Boot Sector 1 Buffer
  3682 000014BE E88309                  	call	write_hd_sector
  3683 000014C1 0F82CC02                	jc	formatting_error
  3684 000014C5 E87C02                  	call	write_format_percent
  3685 000014C8 83C001                  	add	ax, 1
  3686 000014CB 83D200                  	adc	dx, 0
  3687 000014CE BB[0A68]                	mov	bx, HDFORMAT_FSINFO_BUFF
  3688                                  	; ES:BX = FS INFO Sector Buffer (= BS+1)
  3689 000014D1 E87009                  	call	write_hd_sector
  3690 000014D4 0F82B902                	jc	formatting_error
  3691 000014D8 E86902                  	call	write_format_percent	
  3692 000014DB 83C001                  	add	ax, 1
  3693 000014DE 83D200                  	adc	dx, 0	
  3694 000014E1 BB[8236]                	mov	bx, TRDOS_FAT32_hd_bs + 512
  3695                                  	; ES:BX = Boot Sector 2 Buffer
  3696 000014E4 E85D09                  	call	write_hd_sector
  3697 000014E7 0F82A602                	jc	formatting_error
  3698 000014EB E85602                  	call	write_format_percent
  3699 000014EE B90300                  	mov	cx, 3
  3700                                  FAT32_f_4:
  3701 000014F1 51                      	push	cx
  3702 000014F2 83C001                  	add	ax, 1
  3703 000014F5 83D200                  	adc	dx, 0
  3704 000014F8 BB[0C6A]                	mov	bx, HDFORMAT_EMPTY_BUFF
  3705 000014FB E84609                  	call	write_hd_sector
  3706 000014FE 0F828F02                	jc	formatting_error
  3707 00001502 E83F02                  	call	write_format_percent
  3708 00001505 59                      	pop	cx
  3709 00001506 FEC9                    	dec	cl
  3710 00001508 75E7                    	jnz	short FAT32_f_4
  3711 0000150A 83C001                  	add	ax, 1
  3712 0000150D 83D200                  	adc	dx, 0
  3713 00001510 8B4E1C                  	mov	cx, [bp+1Ch]	; [BPB_HiddSec]
  3714 00001513 8B5E1E                  	mov	bx, [bp+1Eh]	; [BPB_HiddSec+2]
  3715 00001516 83C10C                  	add	cx, 12
  3716 00001519 83D300                  	adc	bx, 0
  3717                                  	; write BACKUP sectors
  3718                                  	; (6,7,8 boot+fsi and 9,10,11 empty sectors) 
  3719 0000151C 39DA                    	cmp	dx, bx
  3720 0000151E 729B                    	jb	short FAT32_f_3
  3721 00001520 39C8                    	cmp	ax, cx
  3722 00001522 7297                    	jb	short FAT32_f_3
  3723                                  	; write remain part of reserved sectors
  3724 00001524 8B4E0E                  	mov	cx, [bp+0Eh]	; [BPB_RsvdSecCnt]
  3725 00001527 83E90C                  	sub	cx, 12
  3726 0000152A 7618                    	jna	short FAT32_f_6
  3727                                  FAT32_f_5:
  3728 0000152C 51                      	push	cx
  3729 0000152D BB[0C6A]                	mov	bx, HDFORMAT_EMPTY_BUFF
  3730 00001530 E81109                  	call	write_hd_sector
  3731 00001533 0F825A02                	jc	formatting_error
  3732 00001537 E80A02                  	call	write_format_percent
  3733 0000153A 83C001                  	add	ax, 1
  3734 0000153D 83D200                  	adc	dx, 0
  3735 00001540 59                      	pop	cx
  3736 00001541 49                      	dec	cx
  3737 00001542 75E8                    	jnz	short FAT32_f_5
  3738                                  FAT32_f_6:
  3739                                  	; write FAT sectors
  3740 00001544 8B0E[0C6C]              	mov	cx, [data_start] ; lba/abs addr
  3741 00001548 8B1E[0E6C]              	mov	bx, [data_start+2] ; lba/abs addr
  3742 0000154C 53                      	push	bx
  3743 0000154D 51                      	push	cx
  3744 0000154E BB[0C6A]                	mov	bx, HDFORMAT_FATBUFFER
  3745                                  	; ES:BX = FAT Sector Buffer
  3746 00001551 8A4E15                  	mov	cl, [bp+15h] ; [BPB_Media]
  3747 00001554 B5FF                    	mov	ch, 0FFh
  3748 00001556 890F                    	mov	[bx], cx
  3749 00001558 88E9                    	mov	cl, ch ; cx = 0FFFFh
  3750 0000155A 894F02                  	mov	[bx+2], cx
  3751 0000155D 894F04                  	mov	[bx+4], cx
  3752 00001560 894F06                  	mov	[bx+6], cx
  3753                                  	; Root dir cluster number = 2
  3754                                  	; 0FFFFFFFh = end of cluster chain 
  3755 00001563 894F08                  	mov	[bx+8], cx  ; 0FFFFh
  3756 00001566 80E50F                  	and	ch, 0Fh
  3757 00001569 894F0A                  	mov	[bx+10], cx ; 0FFFh
  3758                                  	;inc	cx
  3759 0000156C E8D508                  	call	write_hd_sector
  3760 0000156F 0F821E02                	jc	formatting_error
  3761 00001573 E8CE01                  	call	write_format_percent
  3762                                  	;mov	bx, HDFORMAT_FATBUFFER
  3763 00001576 B90000                  	mov	cx, 0
  3764 00001579 890F                    	mov	[bx], cx
  3765 0000157B 894F02                  	mov	[bx+2], cx
  3766 0000157E 894F04                  	mov	[bx+4], cx
  3767 00001581 894F06                  	mov	[bx+6], cx
  3768 00001584 894F08                  	mov	[bx+8], cx
  3769 00001587 894F0A                  	mov	[bx+10], cx
  3770 0000158A EB0F                    	jmp	short FAT32_f_8
  3771                                  FAT32_f_7:	
  3772 0000158C 53                      	push	bx
  3773 0000158D 51                      	push	cx	
  3774 0000158E BB[0C6A]                	mov	bx, HDFORMAT_FATBUFFER
  3775 00001591 E8B008                  	call	write_hd_sector
  3776 00001594 0F82F901                	jc	formatting_error
  3777 00001598 E8A901                  	call	write_format_percent
  3778                                  FAT32_f_8:	
  3779 0000159B 59                      	pop	cx
  3780 0000159C 5B                      	pop	bx
  3781 0000159D 83C001                  	add	ax, 1
  3782 000015A0 83D200                  	adc	dx, 0
  3783 000015A3 39DA                    	cmp	dx, bx
  3784 000015A5 72E5                    	jb	short FAT32_f_7
  3785 000015A7 39C8                    	cmp	ax, cx
  3786 000015A9 72E1                    	jb	short FAT32_f_7
  3787                                  
  3788                                  	; write	root directory (1st cluster)
  3789                                  	; as empty sectors
  3790 000015AB 8A4E0D                  	mov	cl, [bp+0Dh]	 ; [BPB_SecPerClus]
  3791 000015AE 30ED                    	xor	ch, ch
  3792 000015B0 290E[106C]              	sub	[data_sectors], cx
  3793 000015B4 831E[126C]00            	sbb	word [data_sectors+2], 0
  3794                                  FAT32_f_9:
  3795 000015B9 51                      	push	cx
  3796 000015BA BB[0C6A]                	mov	bx, HDFORMAT_EMPTY_BUFF
  3797 000015BD E88408                  	call	write_hd_sector
  3798 000015C0 0F82CD01                	jc	formatting_error
  3799 000015C4 E87D01                  	call	write_format_percent
  3800 000015C7 83C001                  	add	ax, 1
  3801 000015CA 83D200                  	adc	dx, 0
  3802 000015CD 59                      	pop	cx
  3803 000015CE FEC9                    	dec	cl
  3804 000015D0 75E7                    	jnz	short FAT32_f_9
  3805                                  
  3806                                  	; write DATA sectors 
  3807                                  	; (after root directory 1st cluster)
  3808 000015D2 8B0E[106C]              	mov	cx, [data_sectors]
  3809 000015D6 8B1E[126C]              	mov	bx, [data_sectors+2] 
  3810                                  			; NOTE: Partition size must be >= 512 MB
  3811                                  			;	for FAT32 FS  ((BX >= 15))		
  3812                                  FAT32_f_10:	
  3813 000015DA 53                      	push	bx
  3814 000015DB 51                      	push	cx	
  3815 000015DC BB[0A66]                	mov	bx, HDFORMAT_SECBUFFER
  3816 000015DF E86208                  	call	write_hd_sector
  3817 000015E2 0F82AB01                	jc	formatting_error
  3818 000015E6 E85B01                  	call	write_format_percent
  3819 000015E9 59                      	pop	cx
  3820 000015EA 5B                      	pop	bx
  3821 000015EB 83C001                  	add	ax, 1
  3822 000015EE 83D200                  	adc	dx, 0
  3823 000015F1 49                      	dec	cx
  3824 000015F2 75E6                    	jnz	short FAT32_f_10
  3825 000015F4 4B                      	dec	bx
  3826 000015F5 75E3                    	jnz	short FAT32_f_10
  3827                                  
  3828                                  	; If there are, format remain sectors which are
  3829                                  	; at beyond of data clusters, with zero bytes.
  3830                                  	
  3831 000015F7 8B4E1C                  	mov	cx, [bp+1Ch]	; [BPB_HiddSec]
  3832 000015FA 8B5E1E                  	mov	bx, [bp+1Eh]	; [BPB_HiddSec+2]
  3833                                  FAT16_f_18:	
  3834 000015FD 034E20                  	add	cx, [bp+20h]	; [BPB_TotSec32]
  3835 00001600 135E22                  	adc	bx, [bp+22h]	; [BPB_TotSec32+2]
  3836                                  FAT16_f_19:
  3837                                  FAT12_f_8:
  3838                                  	; are there remain sectors (in partition) ?
  3839 00001603 29C1                    	sub	cx, ax
  3840 00001605 19D3                    	sbb	bx, dx
  3841                                  	; 11/02/2019
  3842                                  	; BX must be 0 (Because, 1 cluster <= 32KB. So, 
  3843                                  	;	        remain sectors must not be more than 32K)
  3844 00001607 751C                    	jnz	short FAT32_f_12 ; There is a wrong thing !!!
  3845                                  				 ; If BX is not zero,	
  3846                                  				 ; it is better to skip this stage...)
  3847 00001609 09C9                    	or	cx, cx		
  3848 0000160B 7418                    	jz	short FAT32_f_12 ; no.. 
  3849                                  				 ; (good! FAT contains all data sectors)
  3850                                  FAT32_f_11:
  3851 0000160D 51                      	push	cx
  3852 0000160E BB[0C6A]                	mov	bx, HDFORMAT_EMPTY_BUFF
  3853 00001611 E83008                  	call	write_hd_sector
  3854 00001614 0F827901                	jc	formatting_error
  3855 00001618 E82901                  	call	write_format_percent
  3856 0000161B 59                      	pop	cx
  3857 0000161C 83C001                  	add	ax, 1
  3858 0000161F 83D200                  	adc	dx, 0
  3859 00001622 49                      	dec	cx
  3860 00001623 75E8                    	jnz	short FAT32_f_11
  3861                                  
  3862                                  FAT32_f_12:
  3863                                  SINGLIX_fs1_f_12:
  3864                                  	; End of FAT format routine...
  3865                                  end_of_formatting:
  3866 00001625 B064                    	mov	al, 100
  3867 00001627 E85301                  	call	write_format_percent_x
  3868                                  	;mov	si, CRLF
  3869                                  	;call	print_msg
  3870 0000162A BE[4C56]                	mov	si, Msg_OK
  3871 0000162D E80508                  	call	print_msg
  3872 00001630 E915FD                  	jmp	Exit
  3873                                  
  3874                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3875                                  ; set & write volume name
  3876                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3877                                  
  3878                                  write_fs_volume_name:
  3879 00001633 C606[F365]40            	mov	byte [vname_length], 64
  3880 00001638 EB05                    	jmp	short svn_fs
  3881                                  
  3882                                  write_volume_name:
  3883 0000163A C606[F365]0B            	mov	byte [vname_length], 11
  3884                                  svn_fs:
  3885                                  	; DI = (BS) Volume Label address
  3886 0000163F BE[EE55]                	mov	si, Msg_Volume_Name
  3887 00001642 E8F007                  	call	print_msg
  3888                                  
  3889                                  	; get cursor position
  3890                                  	; bh = 0  ; video page
  3891 00001645 B403                    	mov     ah, 3 ; get cursor pos
  3892 00001647 CD10                    	int     10h
  3893 00001649 8916[9455]              	mov	[Cursor_Pos], dx
  3894                                  
  3895 0000164D E89B08                  	call	rw_char
  3896 00001650 7207                    	jc	short svn_1
  3897                                  svn_0:
  3898 00001652 AC                      	lodsb
  3899 00001653 3C20                    	cmp	al, 20h
  3900 00001655 7706                    	ja	short svn_2
  3901 00001657 74F9                    	je	short svn_0 
  3902                                  svn_1:
  3903 00001659 BE[FE65]                	mov	si, no_name
  3904 0000165C AC                      	lodsb
  3905                                  svn_2:
  3906                                  	;mov	di, [bp+47h) ; [BS_VolLab] ; FAT32
  3907                                  	;mov	di, [bp+2Bh) ; [BS_VolLab] ; FAT16 (&FAT12)
  3908 0000165D 89FB                    	mov	bx, di ; *
  3909 0000165F 30ED                    	xor	ch, ch
  3910 00001661 8A0E[F365]              	mov	cl, [vname_length] ; 11
  3911 00001665 EB05                    	jmp	short svn_4
  3912                                  svn_3:
  3913 00001667 AC                      	lodsb
  3914 00001668 3C20                    	cmp	al, 20h
  3915 0000166A 7226                    	jb	short svn_6
  3916                                  svn_4:
  3917 0000166C AA                      	stosb
  3918 0000166D E2F8                    	loop	svn_3
  3919                                  svn_5:
  3920 0000166F 8A0E[F365]              	mov	cl, [vname_length] ; 11
  3921 00001673 89DE                    	mov	si, bx ; *
  3922 00001675 BF[AD55]                	mov	di, StrVolumeName
  3923 00001678 F3A4                    	rep	movsb
  3924                                  	;mov	byte [di], 0
  3925                                  
  3926 0000167A 8B16[9455]              	mov	dx, [Cursor_Pos]
  3927 0000167E BB0700                  	mov	bx, 7
  3928 00001681 B402                    	mov	ah, 2
  3929 00001683 CD10                    	int	10h  ; Set Cursor Position
  3930                                  
  3931 00001685 BE[AD55]                	mov	si, StrVolumeName
  3932 00001688 E8AA07                  	call	print_msg
  3933 0000168B BE[5056]                	mov	si, CRLF
  3934 0000168E E8A407                  	call	print_msg
  3935 00001691 C3                      	retn
  3936                                  svn_6:
  3937 00001692 B020                    	mov	al, 20h
  3938                                  svn_7:
  3939 00001694 AA                      	stosb
  3940 00001695 E2FD                    	loop	svn_7
  3941 00001697 EBD6                    	jmp	short svn_5
  3942                                  
  3943                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3944                                  ; set & write volume serial number (volume ID)
  3945                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3946                                  
  3947                                  write_volume_serial:
  3948                                  	; SI = (BS) Volume Serial Number (binary) address
  3949                                  
  3950                                  	;xor	ax, ax
  3951                                  	;int	1Ah			; get time of day
  3952                                  
  3953                                  	;mov	[si], dx
  3954                                  	;mov	[si+2], cx		; set unique volume ID
  3955                                  
  3956                                  	;mov	ah, 02h			; Return Current Time
  3957                                  	;int	1Ah
  3958                                  	;xchg	ch, cl
  3959                                  	;xchg	dh, dl
  3960                                  
  3961                                  	;add	cx, dx  
  3962                                  	;add	[si+2], cx
  3963                                                 
  3964                                  	;mov	ah, 04h			; Return Current Date
  3965                                  	;int	1Ah
  3966                                  
  3967                                  	;xchg	ch,cl
  3968                                  	;xchg	dh,dl
  3969                                  
  3970                                  	;add	cx, dx  
  3971                                  	;add	[si+2], cx
  3972                                  
  3973                                  	; According to Microsoft DOS 6.0 serial number
  3974                                  	; production method...
  3975                                  	; < Create unique 32 bit serial number >
  3976                                  
  3977                                  	; Create_Serial_ID (MSDOS 6.0 Source code, MSFOR.ASM)
  3978                                  	; (20/04/1987)
  3979                                  	;
  3980                                  	;  Get date (INT 21h, AH=2Bh)
  3981                                  	;  Get time (INT 21h, AH=2Ch)
  3982                                  	;  Serial_ID+0 = DX reg date + DX reg time
  3983                                  	;  Serial_ID+2 = CX reg date + CX reg time
  3984                                  	;  Serial_Num_Low = Serial_ID+2
  3985                                  	;  Serial_Num_High = Serial_ID+0
  3986                                  
  3987 00001699 B404                    	mov	ah, 04h		; Return Current Date
  3988 0000169B CD1A                    	int	1Ah
  3989                                  
  3990                                  	; DL = Day (BCD)	(20h) 	
  3991                                  	; DH = Month (BCD)	(12h)
  3992                                  	; CH = Century (BCD)	(20h)
  3993                                  	; CL = Year (BCD) 	(17h)
  3994                                  
  3995 0000169D 88D0                    	mov	al, dl
  3996 0000169F E87100                  	call	bcd_to_bin
  3997 000016A2 88C2                    	mov	dl, al 
  3998 000016A4 88F0                    	mov	al, dh
  3999 000016A6 E86A00                  	call	bcd_to_bin
  4000 000016A9 88C6                    	mov	dh, al 
  4001 000016AB 88C8                    	mov	al, cl
  4002 000016AD E86300                  	call	bcd_to_bin
  4003 000016B0 88C1                    	mov	cl, al 
  4004 000016B2 88E8                    	mov	al, ch
  4005 000016B4 E85C00                  	call	bcd_to_bin
  4006 000016B7 88C5                    	mov	ch, al
  4007                                  
  4008                                  	; DH = Month (1-10)
  4009                                  	; DL = Day (1-31)
  4010                                  	; CX = Year (1900-2099)
  4011                                  
  4012 000016B9 52                      	push	dx 
  4013 000016BA 51                      	push	cx
  4014                                  
  4015 000016BB B402                    	mov	ah, 02h		; Return Current Time
  4016 000016BD CD1A                    	int	1Ah
  4017                                  	
  4018                                  	; DH = Seconds (BCD)	(59h) 	
  4019                                  	; CL = Minutes (BCD)	(59h)
  4020                                  	; CH = Hours (BCD)	(23h)
  4021                                  	; DL = Daylight savings time option (1=yes)
  4022                                  
  4023 000016BF 88F0                    	mov	al, dh
  4024 000016C1 E84F00                  	call	bcd_to_bin
  4025 000016C4 88C6                    	mov	dh, al 
  4026 000016C6 88C8                    	mov	al, cl
  4027 000016C8 E84800                  	call	bcd_to_bin
  4028 000016CB 88C1                    	mov	cl, al 
  4029 000016CD 88E8                    	mov	al, ch
  4030 000016CF E84100                  	call	bcd_to_bin
  4031 000016D2 88C5                    	mov	ch, al 
  4032                                  
  4033                                  	; CH = Hour (0-23)
  4034                                  	; CL = Minutes (0-59)
  4035                                  	; DH = Seconds (0-59)
  4036                                  	; ((DL = Hundredths (0-99) - MSDOS!))
  4037                                  	; DL = 0 or 1 (here!)
  4038                                  
  4039 000016D4 89C8                    	mov	ax, cx
  4040 000016D6 59                      	pop	cx
  4041 000016D7 01C8                    	add	ax, cx
  4042                                  
  4043 000016D9 894402                  	mov	[si+2], ax
  4044                                  
  4045 000016DC 89D0                    	mov	ax, dx
  4046 000016DE 5A                      	pop	dx
  4047 000016DF 01D0                    	add	ax, dx
  4048                                  
  4049 000016E1 8904                    	mov	[si], ax
  4050                                  
  4051 000016E3 30E4                    	xor	ah, ah		; Read time counter
  4052 000016E5 CD1A                    	int	1Ah
  4053                                  
  4054                                  	; CX = High word of clock count
  4055                                  	; DX = Low word of clock count
  4056                                  	; AL = 0 if 24 hours has not passed, else 1
  4057                                  
  4058                                  	; NOTES: 
  4059                                  	; (Ref: vitaly_filatov.tripod.com/ng/asm/asm_029.1.html)
  4060                                  	;
  4061                                     	; Following formulas convert the clock count to
  4062                                          ; the time of day:
  4063                                   	;	Hour      = Clock / 65543 (1007h)
  4064                                  	;	Remainder = Clock MOD 65543
  4065                                   	;
  4066                                  	;	Minutes   = Remainder / 1092 (444h)
  4067                                  	;	Remainder = Remainder MOD 1092
  4068                                  	;
  4069                                  	;	Second    = Remainder / 18.21
  4070                                  	;	Remainder = Remainder MOD 18.21
  4071                                  	;
  4072                                  	;	Hundredths = CINT(Remainder * 100)
  4073                                  
  4074 000016E7 0014                    	add	[si], dl
  4075                                  
  4076                                  	; SI = Volume serial number address (4 bytes) 
  4077 000016E9 8A04                    	mov	al, [si]
  4078 000016EB E8E607                  	call	bin_to_hex
  4079 000016EE A3[1956]                	mov	[Vol_Serial2+2], ax	
  4080 000016F1 8A4401                  	mov	al, [si+1]
  4081 000016F4 E8DD07                  	call	bin_to_hex
  4082 000016F7 A3[1756]                	mov	[Vol_Serial2], ax
  4083 000016FA 8A4402                  	mov	al, [si+2]
  4084 000016FD E8D407                  	call	bin_to_hex
  4085 00001700 A3[1456]                	mov	[Vol_Serial1+2], ax	
  4086 00001703 8A4403                  	mov	al, [si+3]
  4087 00001706 E8CB07                  	call	bin_to_hex
  4088 00001709 A3[1256]                	mov	[Vol_Serial1], ax
  4089                                  
  4090 0000170C BE[0056]                	mov	si, Msg_Volume_Serial
  4091 0000170F E82307                  	call	print_msg
  4092                                  
  4093 00001712 C3                      	retn
  4094                                  
  4095                                  bcd_to_bin:
  4096 00001713 53                      	push	bx
  4097 00001714 D410                    	db	0D4h,10h  ; Undocumented inst. AAM
  4098                                  			  ; AH = AL / 10h
  4099                                  			  ; AL = AL MOD 10h
  4100 00001716 88C3                    	mov	bl, al
  4101 00001718 B00A                    	mov	al, 10
  4102 0000171A F6E4                    	mul	ah
  4103 0000171C 00D8                    	add	al, bl
  4104 0000171E 5B                      	pop	bx
  4105 0000171F C3                      	retn
  4106                                  
  4107                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4108                                  ; write formatting percentage
  4109                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4110                                  
  4111                                  write_formatting_msg:
  4112                                  	;mov	ax, [pp_Sectors]
  4113                                  	;mov	dx, [pp_Sectors+2]
  4114                                  	; 16/02/2019
  4115 00001720 A1[C86E]                	mov	ax, [ppn_Sectors]
  4116 00001723 8B16[CA6E]              	mov	dx, [ppn_Sectors+2]
  4117                                  
  4118                                  	; DX_AX = Total sectors for percentage  
  4119 00001727 B96400                  	mov	cx, 100	
  4120 0000172A E809F7                  	call	div32
  4121 0000172D A3[1A6C]                	mov	[format_percent], ax
  4122                                  
  4123 00001730 BE[3856]                	mov	si, msg_formatting
  4124 00001733 E8FF06                  	call	print_msg
  4125                                  
  4126                                  	; get cursor position
  4127                                  	; bh = 0  ; video page
  4128 00001736 B403                    	mov     ah, 3 ; get cursor pos
  4129 00001738 CD10                    	int     10h
  4130 0000173A 8916[9455]              	mov	[Cursor_Pos], dx
  4131                                  
  4132 0000173E C606[1C6C]FF            	mov	byte [prev_percent], 255
  4133                                  
  4134 00001743 C3                      	retn
  4135                                  
  4136                                  write_format_percent:
  4137                                  	; DX_AX = Current sector (which has been written)
  4138                                  
  4139 00001744 50                      	push	ax
  4140 00001745 52                      	push	dx
  4141 00001746 53                      	push	bx
  4142 00001747 51                      	push	cx
  4143 00001748 56                      	push	si
  4144                                  
  4145 00001749 2B461C                  	sub	ax, [bp+1Ch]	; [BPB_HiddSec]
  4146 0000174C 1B561E                  	sbb	dx, [bp+1Eh]	; [BPB_HiddSec+2]
  4147                                  wpc_t:
  4148 0000174F 8B0E[1A6C]              	mov	cx, [format_percent]
  4149 00001753 E8E0F6                  	call	div32
  4150                                  	; AL = percentage value between 1 to 100
  4151                                  wpc_x:
  4152 00001756 3A06[1C6C]              	cmp	al, [prev_percent]
  4153 0000175A 741B                    	je	short wpc_y
  4154 0000175C A2[1C6C]                	mov	[prev_percent], al
  4155 0000175F 8B16[9455]              	mov	dx, [Cursor_Pos]
  4156 00001763 BB0700                  	mov	bx, 7
  4157 00001766 B402                    	mov	ah, 2
  4158 00001768 CD10                    	int	10h  ; Set Cursor Position
  4159 0000176A 31D2                    	xor	dx, dx
  4160 0000176C 30E4                    	xor	ah, ah
  4161                                  	;mov	al, [prev_percent]
  4162 0000176E BE[4656]                	mov	si, format_percent_str + 2
  4163 00001771 E84907                  	call	bin_to_decimal
  4164 00001774 E8BE06                  	call	print_msg
  4165                                  wpc_y:
  4166 00001777 5E                      	pop	si
  4167 00001778 59                      	pop	cx
  4168 00001779 5B                      	pop	bx
  4169 0000177A 5A                      	pop	dx
  4170 0000177B 58                      	pop	ax
  4171 0000177C C3                      	retn
  4172                                  
  4173                                  write_format_percent_x:
  4174                                  	; AL = % number
  4175                                  
  4176 0000177D 50                      	push	ax
  4177 0000177E 52                      	push	dx
  4178 0000177F 53                      	push	bx
  4179 00001780 51                      	push	cx
  4180 00001781 56                      	push	si
  4181                                  
  4182 00001782 EBD2                    	jmp	short wpc_x
  4183                                  
  4184                                  write_fs_format_percent:
  4185                                  	; DX_AX = Current sector (which has been written)
  4186                                  
  4187 00001784 50                      	push	ax
  4188 00001785 52                      	push	dx
  4189 00001786 53                      	push	bx
  4190 00001787 51                      	push	cx
  4191 00001788 56                      	push	si
  4192                                  
  4193 00001789 2B460C                  	sub	ax, [bp+0Ch]	; [bsBeginSector]
  4194 0000178C 1B560E                  	sbb	dx, [bp+0Eh]	; [bsBeginSector+2]
  4195 0000178F EBBE                    	jmp	short wpc_t	
  4196                                  	
  4197                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4198                                  ; format error 
  4199                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4200                                  
  4201                                  formatting_error:
  4202 00001791 8B26[0A6A]              	mov	sp, [old_sp]
  4203                                  
  4204 00001795 88E0                    	mov	al, ah ;  error code
  4205 00001797 E83A07                  	call	bin_to_hex
  4206 0000179A A3[5E56]                	mov 	[error_code], ax
  4207                                  
  4208 0000179D BE[5056]                	mov	si, CRLF
  4209 000017A0 E89206                  	call	print_msg
  4210                                  
  4211 000017A3 BE[5356]                	mov	si, Msg_Error
  4212 000017A6 E88C06                  	call	print_msg
  4213 000017A9 E99CFB                  	jmp	Exit
  4214                                  
  4215                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4216                                  ; write cluster count
  4217                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4218                                  
  4219                                  write_cluster_count:
  4220 000017AC BE[1E56]                	mov	si, msg_cluster_count
  4221 000017AF E88306                  	call	print_msg
  4222 000017B2 A1[146C]                	mov	ax, [cluster_count]
  4223 000017B5 8B16[166C]              	mov	dx, [cluster_count+2]
  4224 000017B9 BE[3456]                	mov	si, cluster_count_str+6
  4225 000017BC E8FE06                  	call	bin_to_decimal
  4226 000017BF E87306                  	call	print_msg
  4227 000017C2 C3                      	retn 
  4228                                  
  4229                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4230                                  ; FAT16 FORMATTING
  4231                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4232                                  	; 08/02/2019 (Modified for -only- FAT16 CHS partitions) 
  4233                                  FAT16_hdi_format:
  4234 000017C3 B80607                  	mov	ax, 0706h ; db 06h, 07h ; 'push es, pop es'
  4235 000017C6 38C2                    	cmp	dl, al ; 06h ; Big CHS partition (>= 32MB)
  4236 000017C8 7403                    	je	short FAT16_big_chs_format
  4237                                  	;mov	ax, 070Eh ; db 0Eh, 07h	; 'push cs, pop es'
  4238                                  	;cmp	dl, al ; 0Eh ; LBA partition
  4239                                  	;je	short FAT16_lba_format
  4240                                  FAT16_chs_format:  
  4241                                  	; Partition Type: 04h, CHS (<32 MB) partition
  4242 000017CA B80400                  	mov	ax, 0004h ; db 04h, 00h ; 'add al, 0'
  4243                                  FAT16_big_chs_format:
  4244                                  ;FAT16_lba_format:
  4245                                  	; Put TRDOS 386 FAT16 partition magic word 
  4246                                  	; at offset 3Eh, in TRDOS386 FAT16 boot sector.
  4247 000017CD BD[8238]                	mov	bp, TRDOS_FAT16_hd_bs
  4248 000017D0 8D7E03                  	lea	di, [bp+3]
  4249 000017D3 BE[F465]                	mov	si, bs_oem_name
  4250 000017D6 B90400                  	mov	cx, 4
  4251 000017D9 F3A5                    	rep	movsw 
  4252 000017DB 89463E                  	mov	[bp+3Eh], ax	; [loc_3E]
  4253                                  
  4254 000017DE A1[9640]                	mov	ax, [sectors]
  4255 000017E1 894618                  	mov	[bp+18h], ax	; [BPB_SecPerTrk]
  4256 000017E4 A1[9840]                	mov	ax, [heads]
  4257 000017E7 89461A                  	mov	[bp+1Ah], ax	; [BPB_NumHeads]
  4258 000017EA A1[946E]                	mov	ax, [pp_StartSector]
  4259 000017ED 89461C                  	mov	[bp+1Ch], ax	; [BPB_HiddSec]
  4260 000017F0 A1[966E]                	mov	ax, [pp_StartSector+2]
  4261 000017F3 89461E                  	mov	[bp+1Eh], ax	; [BPB_HiddSec+2]
  4262                                  	;mov	ax, [pp_Sectors]
  4263 000017F6 A1[C86E]                	mov	ax, [ppn_Sectors] ; 16/02/2019
  4264                                  	;mov	dx, [pp_Sectors+2]
  4265 000017F9 8B16[CA6E]              	mov	dx, [ppn_Sectors+2] ; 16/02/2019
  4266 000017FD 21D2                    	and	dx, dx
  4267 000017FF 7505                    	jnz	short FAT16_f_0
  4268 00001801 894613                  	mov	[bp+13h], ax	; [BPB_TotSec16]
  4269                                  	; CX = 0
  4270                                  	;mov	[bp+20h], cx	; [BPB_TotSec32] =  0
  4271                                  	;mov	[bp+22h], cx	; [BPB_TotSec32+2] = 0
  4272 00001804 EB06                    	jmp	short FAT16_f_1
  4273                                  FAT16_f_0:
  4274 00001806 894620                  	mov	[bp+20h], ax	; [BPB_TotSec32]
  4275                                  	;;mov	dx, [pp_Sectors+2]
  4276                                  	;mov	dx, [ppn_Sectors+2] ; 16/02/2019 
  4277 00001809 895622                  	mov	[bp+22h], dx	; [BPB_TotSec32+2]
  4278                                  	; CX = 0
  4279                                  	;mov	[bp+13h], cx ; [BPB_TotSec16] = 0
  4280                                  FAT16_f_1:
  4281                                  	; Sectors per cluster calculation
  4282                                  	; (According to MS FAT32 FS specification.)
  4283 0000180C B102                    	mov	cl, 2  ; 2 sectors per cluster
  4284 0000180E 09D2                    	or	dx, dx
  4285 00001810 7507                    	jnz	short FAT16_f_2 ; >2 sectors (>16MB)
  4286 00001812 3DA87F                  	cmp	ax, 32680
  4287 00001815 763C                    	jna	short FAT16_f_10 ; 2 sectors, <=16MB
  4288                                  	; > 16MB
  4289 00001817 EB38                    	jmp	short FAT16_f_9 ; 4 sectors per cluster
  4290                                  FAT16_f_2:
  4291 00001819 83FA04                  	cmp	dx, 4  ; >= 262144 sectors ; >=128MB
  4292 0000181C 7708                    	ja	short FAT16_f_3 ; >4 sectors per cluster
  4293 0000181E 7231                    	jb	short FAT16_f_9 ; 4 sectors per cluster	
  4294 00001820 09C0                    	or	ax, ax ; dx_ax = (4*65536)+0
  4295 00001822 742D                    	jz	short FAT16_f_9 ; 4 sectors per cluster
  4296 00001824 EB29                    	jmp	short FAT16_f_8 ; 8 sectors per cluster
  4297                                  FAT16_f_3:
  4298 00001826 83FA08                  	cmp	dx, 8  ; >= 524288 sectors ; >=256MB
  4299 00001829 7708                    	ja	short FAT16_f_4 ; >8 sectors per cluster
  4300 0000182B 7222                    	jb	short FAT16_f_8 ; 8 sectors per cluster	
  4301 0000182D 21C0                    	and	ax, ax ; dx_ax = (8*65536)+0
  4302 0000182F 741E                    	jz	short FAT16_f_8 ; 8 sectors per cluster
  4303 00001831 EB1A                    	jmp	short FAT16_f_7 ; 16 sectors per cluster
  4304                                  FAT16_f_4:
  4305 00001833 83FA10                  	cmp	dx, 16 ; >= 1048576 sectors ; >=512MB
  4306 00001836 7708                    	ja	short FAT16_f_5 ; >16 sectors per cluster
  4307 00001838 7213                    	jb	short FAT16_f_7 ; 16 sectors per cluster	
  4308 0000183A 21C0                    	and	ax, ax ; dx_ax = (16*65536)+0
  4309 0000183C 740F                    	jz	short FAT16_f_7 ; 16 sectors per cluster
  4310 0000183E EB0B                    	jmp	short FAT16_f_6 ; 32 sectors per cluster
  4311                                  FAT16_f_5:
  4312 00001840 83FA20                  	cmp	dx, 32 ; >= 2097152 sectors ; >=1GB
  4313 00001843 7206                    	jb	short FAT16_f_6 ; 32 sectors per cluster
  4314 00001845 09C0                    	or	ax, ax		; dx_ax = (32*65536)+0
  4315 00001847 7402                    	jz	short FAT16_f_6 ; 32 sectors per cluster
  4316                                  	; >1GB (<=2GB)
  4317                                  	; 64 sectors per cluster
  4318 00001849 D0E1                    	shl	cl, 1
  4319                                  FAT16_f_6:
  4320                                  	; 32 sectors per cluster (for <= 2GB volumes)
  4321 0000184B D0E1                    	shl	cl, 1	
  4322                                  FAT16_f_7:
  4323                                  	; 16 sectors per cluster (for <= 1GB volumes)
  4324 0000184D D0E1                    	shl	cl, 1
  4325                                  FAT16_f_8:
  4326                                  	; 8 sectors per cluster (for <= 512MB volumes)
  4327 0000184F D0E1                    	shl	cl, 1	
  4328                                  FAT16_f_9:
  4329                                  	; 4 sectors per cluster (for <= 256MB volumes)
  4330 00001851 D0E1                    	shl	cl, 1	
  4331                                  FAT16_f_10:	
  4332                                  	; 2 sectors per cluster (for <= 128MB volumes)
  4333 00001853 884E0D                  	mov	[bp+0Dh], cl	 ; [BPB_SecPerClus]
  4334                                  	;mov	byte [bp+10h], 2 ; [BPB_NumFATs] 
  4335                                  	;mov	word [bp+0Eh], 1 ; [BPB_RsvdSecCnt] 
  4336                                  	;mov	word [bp+11h], 512 ; [BPB_RootEntCnt]
  4337                                  	
  4338                                  	; Calculating FAT size in sectors
  4339                                  	; (According to MS FAT32 FS Specification, 2000)
  4340                                  
  4341                                  	; DX_AX = partition (volume) size in sectors
  4342 00001856 8B5E11                  	mov	bx, [bp+11h]	; [BPB_RootEntCnt] = 512
  4343 00001859 83C30F                  	add	bx, 15 ; bx = 527
  4344 0000185C C1EB04                  	shr	bx, 4 ; /16 = 527/16 = 32
  4345                                  		; ((32*BX)+511)/512
  4346 0000185F 891E[186C]              	mov	[root_dir_secs], bx
  4347 00001863 035E0E                  	add	bx, [bp+0Eh]	; [BPB_RsvdSecCnt] ; 1
  4348 00001866 29D8                    	sub	ax, bx
  4349 00001868 83DA00                  	sbb	dx, 0
  4350                                  		; TmpVal1 = DiskSize - (BPB_ResvdSecCnt +
  4351                                  		;	     		RootDirsectors)
  4352                                  	;mov	bx, cx ; ch = 0
  4353                                  	;shl	bx, 8 ; * 256
  4354                                  	; 11/02/2019
  4355 0000186B 88CF                    	mov	bh, cl
  4356 0000186D 30DB                    	xor	bl, bl
  4357 0000186F B102                    	mov	cl, 2 ; [BPB_NumFATs] 
  4358 00001871 01CB                    	add	bx, cx	
  4359                                  		; TmpVal2 = (256*BPB_SecPerClus)+BPB_NumFATs
  4360 00001873 89D9                    	mov	cx, bx
  4361 00001875 4B                      	dec	bx  ; TmpVal2-1
  4362 00001876 01D8                    	add	ax, bx
  4363 00001878 83D200                  	adc	dx, 0
  4364 0000187B E8B8F5                  	call	div32
  4365                                  		; FATSz = (TmpVal1+(TmpVal2-1))/TmpVal2
  4366                                  	; AX = FAT size in sectors
  4367                                  	; DX = 0
  4368 0000187E 894616                  	mov	[bp+16h], ax	; [BPB_FATSz16]
  4369                                  	; * 2
  4370 00001881 D1E0                    	shl	ax, 1
  4371                                  	; AX = [BPB_NumFATs] * [BPB_FATSz16]
  4372 00001883 8B4E0E                  	mov	cx, [bp+0Eh]	; [BPB_RsvdSecCnt] ; 1
  4373 00001886 01C1                    	add	cx, ax
  4374                                  	; CX = [BPB_RsvdSecCnt]+([BPB_NumFATs]*[BPB_FATSz16])
  4375 00001888 030E[186C]              	add	cx, [root_dir_secs] ; + RootDirsectors
  4376 0000188C 29DB                    	sub	bx, bx ; BX = 0
  4377                                  	; BX_CX = [BPB_RsvdSecCnt]+([BPB_NumFATs]*[BPB_FATSz16])
  4378                                  	;	  + RootDirSectors
  4379 0000188E 8B4613                  	mov	ax, [bp+13h]	; [BPB_TotSec16]
  4380                                  	;sub	dx, dx 
  4381                                  	; DX = 0
  4382 00001891 21C0                    	and	ax, ax
  4383 00001893 7506                    	jnz	short FAT16_f_11
  4384 00001895 8B4620                  	mov	ax, [bp+20h]	; [BPB_TotSec32]
  4385 00001898 8B5622                  	mov	dx, [bp+22h]	; [BPB_TotSec32+2]
  4386                                  FAT16_f_11:
  4387 0000189B 29C8                    	sub	ax, cx
  4388 0000189D 19DA                    	sbb	dx, bx
  4389 0000189F 890E[0C6C]              	mov	[data_start], cx
  4390 000018A3 891E[0E6C]              	mov	[data_start+2], bx
  4391                                  	; DX_AX = Data sectors
  4392 000018A7 A3[106C]                	mov	[data_sectors], ax
  4393 000018AA 8916[126C]              	mov	[data_sectors+2], dx
  4394 000018AE 8A4E0D                  	mov	cl, [bp+0Dh]	 ; [BPB_SecPerClus]
  4395 000018B1 30ED                    	xor	ch, ch
  4396 000018B3 E880F5                  	call	div32 ; DX_AX/CX
  4397                                  	; AX = Count of clusters (rounded down)
  4398                                  	; DX = 0
  4399 000018B6 A3[146C]                	mov	[cluster_count], ax
  4400 000018B9 8916[166C]              	mov	[cluster_count+2], dx
  4401                                  
  4402 000018BD 8D7E2B                  	lea	di, [bp+43] ; [BS_VolLab]
  4403 000018C0 E877FD                  	call	write_volume_name
  4404 000018C3 8D7627                  	lea	si, [bp+39] ; [BS_VolID]
  4405 000018C6 E8D0FD                  	call	write_volume_serial
  4406 000018C9 E8E0FE                  	call	write_cluster_count	
  4407                                  
  4408 000018CC E851FE                  	call	write_formatting_msg
  4409 000018CF B000                    	mov	al, 0
  4410 000018D1 E8A9FE                  	call	write_format_percent_x
  4411                                  
  4412 000018D4 8B461C                  	mov	ax, [bp+1Ch]	; [BPB_HiddSec]
  4413 000018D7 8B561E                  	mov	dx, [bp+1Eh]	; [BPB_HiddSec+2]
  4414                                  
  4415 000018DA 0106[0C6C]              	add	[data_start], ax
  4416 000018DE 1116[0E6C]              	adc	[data_start+2], dx
  4417                                  
  4418                                  	; DX_AX = FAT16 Boot Sector address
  4419 000018E2 BB[8238]                	mov	bx, TRDOS_FAT16_hd_bs
  4420                                  	; ES:BX = Boot Sector Buffer
  4421 000018E5 E85C05                  	call	write_hd_sector
  4422 000018E8 0F82A5FE                	jc	formatting_error
  4423 000018EC E855FE                  	call	write_format_percent
  4424 000018EF 83C001                  	add	ax, 1
  4425 000018F2 83D200                  	adc	dx, 0
  4426                                  	; write remain part of reserved sectors
  4427 000018F5 8B4E0E                  	mov	cx, [bp+0Eh] ; [BPB_RsvdSecCnt]
  4428                                  	;sub	cx, 1
  4429                                  	;jna	short FAT16_f_13
  4430                                  	; 11/02/2019
  4431 000018F8 49                      	dec	cx
  4432 000018F9 7418                    	jz	short FAT16_f_13
  4433                                  FAT16_f_12:
  4434 000018FB 51                      	push	cx
  4435 000018FC BB[0C6A]                	mov	bx, HDFORMAT_EMPTY_BUFF
  4436 000018FF E84205                  	call	write_hd_sector
  4437 00001902 0F828BFE                	jc	formatting_error
  4438 00001906 E83BFE                  	call	write_format_percent
  4439 00001909 83C001                  	add	ax, 1
  4440 0000190C 83D200                  	adc	dx, 0
  4441 0000190F 59                      	pop	cx
  4442 00001910 49                      	dec	cx ; dec cl
  4443 00001911 75E8                    	jnz	short FAT16_f_12
  4444                                  FAT16_f_13:
  4445                                  	; write FAT sectors
  4446 00001913 8B0E[0C6C]              	mov	cx, [data_start] ; lba/abs addr
  4447 00001917 8B1E[0E6C]              	mov	bx, [data_start+2] ; lba/abs addr
  4448                                  
  4449                                  	; 11/02/2019
  4450 0000191B 2B0E[186C]              	sub	cx, [root_dir_secs]
  4451 0000191F 83DB00                  	sbb	bx, 0
  4452                                  
  4453 00001922 53                      	push	bx
  4454 00001923 51                      	push	cx
  4455 00001924 BB[0C6A]                	mov	bx, HDFORMAT_FATBUFFER
  4456                                  	; ES:BX = FAT Sector Buffer
  4457 00001927 8A4E15                  	mov	cl, [bp+15h] ; [BPB_Media]
  4458 0000192A B5FF                    	mov	ch, 0FFh
  4459 0000192C 890F                    	mov	[bx], cx ; 0FFF8h
  4460 0000192E 88E9                    	mov	cl, ch ; cx = 0FFFFh
  4461 00001930 894F02                  	mov	[bx+2], cx
  4462                                  	;inc	cx
  4463 00001933 E80E05                  	call	write_hd_sector
  4464 00001936 0F8257FE                	jc	formatting_error
  4465 0000193A E807FE                  	call	write_format_percent
  4466                                  	;mov	bx, HDFORMAT_FATBUFFER
  4467 0000193D B90000                  	mov	cx, 0
  4468 00001940 890F                    	mov	[bx], cx
  4469 00001942 894F02                  	mov	[bx+2], cx
  4470 00001945 EB0F                    	jmp	short FAT16_f_15
  4471                                  FAT16_f_14:	
  4472 00001947 53                      	push	bx
  4473 00001948 51                      	push	cx	
  4474 00001949 BB[0C6A]                	mov	bx, HDFORMAT_FATBUFFER
  4475 0000194C E8F504                  	call	write_hd_sector
  4476 0000194F 0F823EFE                	jc	formatting_error
  4477 00001953 E8EEFD                  	call	write_format_percent
  4478                                  FAT16_f_15:	
  4479 00001956 59                      	pop	cx
  4480 00001957 5B                      	pop	bx
  4481 00001958 83C001                  	add	ax, 1
  4482 0000195B 83D200                  	adc	dx, 0
  4483 0000195E 39DA                    	cmp	dx, bx
  4484 00001960 72E5                    	jb	short FAT16_f_14
  4485 00001962 39C8                    	cmp	ax, cx
  4486 00001964 72E1                    	jb	short FAT16_f_14
  4487                                  
  4488                                  	; write	root directory sectors
  4489                                  	; as empty sectors
  4490 00001966 8B0E[186C]              	mov	cx, [root_dir_secs]
  4491                                  FAT16_f_16:
  4492 0000196A 51                      	push	cx
  4493 0000196B BB[0C6A]                	mov	bx, HDFORMAT_EMPTY_BUFF
  4494 0000196E E8D304                  	call	write_hd_sector
  4495 00001971 0F821CFE                	jc	formatting_error
  4496 00001975 E8CCFD                  	call	write_format_percent
  4497 00001978 83C001                  	add	ax, 1
  4498 0000197B 83D200                  	adc	dx, 0
  4499 0000197E 59                      	pop	cx
  4500 0000197F 49                      	dec	cx
  4501 00001980 75E8                    	jnz	short FAT16_f_16	
  4502                                  
  4503                                  	; write DATA sectors 
  4504                                  	; (after root directory sectors)
  4505 00001982 8B0E[106C]              	mov	cx, [data_sectors]
  4506 00001986 8B1E[126C]              	mov	bx, [data_sectors+2]
  4507                                  	; 11/02/2019
  4508 0000198A 43                      	inc	bx ; 0 -> 1, 1-> 2
  4509                                  FAT16_f_17:	
  4510 0000198B 53                      	push	bx
  4511 0000198C 51                      	push	cx	
  4512 0000198D BB[0A66]                	mov	bx, HDFORMAT_SECBUFFER
  4513 00001990 E8B104                  	call	write_hd_sector
  4514 00001993 0F82FAFD                	jc	formatting_error
  4515 00001997 E8AAFD                  	call	write_format_percent
  4516 0000199A 59                      	pop	cx
  4517 0000199B 5B                      	pop	bx
  4518 0000199C 83C001                  	add	ax, 1
  4519 0000199F 83D200                  	adc	dx, 0
  4520 000019A2 49                      	dec	cx
  4521 000019A3 75E6                    	jnz	short FAT16_f_17
  4522 000019A5 4B                      	dec	bx
  4523 000019A6 75E3                    	jnz	short FAT16_f_17
  4524                                  
  4525                                  	; If there are, format remain sectors which are
  4526                                  	; at beyond of data clusters, with zero bytes.
  4527                                  	
  4528 000019A8 8B4E1C                  	mov	cx, [bp+1Ch]	; [BPB_HiddSec]
  4529 000019AB 8B5E1E                  	mov	bx, [bp+1Eh]	; [BPB_HiddSec+2]
  4530                                  
  4531 000019AE 837E1300                	cmp	word [bp+13h], 0 ; [BPB_TotSec16]
  4532 000019B2 0F8447FC                	jz	FAT16_f_18
  4533 000019B6 034E13                  	add	cx, [bp+13h]	; [BPB_TotSec16]
  4534 000019B9 83D300                  	adc	bx, 0
  4535 000019BC E944FC                  	jmp	FAT16_f_19
  4536                                  
  4537                                  FAT12_hdi_format:
  4538 000019BF BD[823A]                	mov	bp, TRDOS_FAT12_hd_bs
  4539 000019C2 8D7E03                  	lea	di, [bp+3]
  4540 000019C5 BE[F465]                	mov	si, bs_oem_name
  4541 000019C8 B90400                  	mov	cx, 4
  4542 000019CB F3A5                    	rep	movsw 
  4543 000019CD A1[9640]                	mov	ax, [sectors]
  4544 000019D0 894618                  	mov	[bp+18h], ax	; [BPB_SecPerTrk]
  4545 000019D3 A1[9840]                	mov	ax, [heads]
  4546 000019D6 89461A                  	mov	[bp+1Ah], ax	; [BPB_NumHeads]
  4547 000019D9 A1[946E]                	mov	ax, [pp_StartSector]
  4548 000019DC 89461C                  	mov	[bp+1Ch], ax	; [BPB_HiddSec]
  4549 000019DF A1[966E]                	mov	ax, [pp_StartSector+2]
  4550 000019E2 89461E                  	mov	[bp+1Eh], ax	; [BPB_HiddSec+2]
  4551                                  	;mov	ax, [pp_Sectors]
  4552 000019E5 A1[C86E]                	mov	ax, [ppn_Sectors] ; 16/02/2019
  4553 000019E8 894613                  	mov	[bp+13h], ax	; [BPB_TotSec16]
  4554                                  
  4555                                  	; 11/02/2019
  4556 000019EB 31F6                    	xor	si, si ; reset (FAT size fix) flag
  4557 000019ED 8B4E0E                  	mov	cx, [bp+0Eh]	; [BPB_RsvdSecCnt] ; 1
  4558 000019F0 8B5611                  	mov	dx, [bp+11h]	; [BPB_RootEntCnt] = 512
  4559 000019F3 83C20F                  	add	dx, 15	; (16-1) (512-1)
  4560 000019F6 C1EA04                  	shr	dx, 4	; /16  (*32/512)
  4561                                  	; AX = Root dir sectors
  4562                                  	; CX = [BPB_RsvdSecCnt]+([BPB_NumFATs]*[BPB_FATSz16])
  4563 000019F9 01D1                    	add	cx, dx ; + RootDirsectors ; + 32
  4564 000019FB 890E[186C]              	mov	[root_dir_secs], cx ; = 33
  4565                                  
  4566                                  	; 11/02/2019
  4567                                  	;sub	ax, 33  ; 1 reserved sector, 32 root dir sectors
  4568                                  			; .. now AX has number of data sectors
  4569                                  			;	 		+ 2* (FAT sectors)
  4570 000019FF 29C8                    	sub	ax, cx	
  4571                                  FAT12_f_10:	; 11/02/2019
  4572                                  	; Sectors per cluster calculation
  4573                                  	; (According to MS FAT32 FS specification.)
  4574                                  	;mov	cx, 1  ; 1 sector per cluster
  4575 00001A01 B101                    	mov	cl, 1  ; CH = 0
  4576                                  FAT12_f_0:
  4577 00001A03 3DF50F                  	cmp	ax, 4085 ; Max. cluster count for FAT12
  4578 00001A06 7206                    	jb	short FAT12_f_1
  4579 00001A08 D0E1                    	shl	cl, 1 ; *2
  4580 00001A0A D1E8                    	shr	ax, 1 ; /2
  4581 00001A0C EBF5                    	jmp	short FAT12_f_0
  4582                                  FAT12_f_1:
  4583 00001A0E 884E0D                  	mov	[bp+0Dh], cl	 ; [BPB_SecPerClus]
  4584                                  	;mov	byte [bp+10h], 2 ; [BPB_NumFATs] 
  4585                                  	;mov	word [bp+0Eh], 1 ; [BPB_RsvdSecCnt] 
  4586                                  	;mov	word [bp+11h], 512 ; [BPB_RootEntCnt]
  4587                                  	
  4588                                  	; Calculating FAT size in sectors
  4589                                  	; AX = partition (volume) size in sectors
  4590                                  	; CX = sectors per clusters
  4591 00001A11 31D2                    	xor	dx, dx
  4592 00001A13 F7F1                    	div	cx
  4593                                  	; AX = cluster count (only for FAT size calc)
  4594                                  	; DX = 0
  4595 00001A15 83C002                  	add	ax, 2  ; cluster 2 to ...
  4596 00001A18 89C2                    	mov	dx, ax
  4597 00001A1A D1E2                    	shl	dx, 1
  4598 00001A1C 01D0                    	add	ax, dx ; *3
  4599 00001A1E D1E8                    	shr	ax, 1  ; /2
  4600 00001A20 83D000                  	adc	ax, 0  ; +0.5 -> +1
  4601                                  
  4602                                  	; AX = FAT bytes for 12 bit cluster numbers
  4603                                  	
  4604 00001A23 B90002                  	mov	cx, 512		; [BPB_BytesPerSec]
  4605 00001A26 01C8                    	add	ax, cx		
  4606 00001A28 48                      	dec	ax		; [BPB_BytesPerSec] - 1
  4607 00001A29 29D2                    	sub	dx, dx
  4608 00001A2B F7F1                    	div	cx
  4609 00001A2D 894616                  	mov	[bp+16h], ax	; [BPB_FATSz16]
  4610                                  	; * 2
  4611 00001A30 D1E0                    	shl	ax, 1
  4612                                  	; AX = [BPB_NumFATs] * [BPB_FATSz16]
  4613                                  
  4614                                  	;mov	cx, [bp+0Eh]	; [BPB_RsvdSecCnt] ; 1
  4615                                  	;add	cx, ax
  4616                                  	;mov	ax, [bp+11h]	; [BPB_RootEntCnt] = 512
  4617                                  	;add	ax, 15	; (16-1) (512-1)
  4618                                  	;shr	ax, 4	; /16  (*32/512)
  4619                                  	;; AX = Root dir sectors
  4620                                  	;; CX = [BPB_RsvdSecCnt]+([BPB_NumFATs]*[BPB_FATSz16])
  4621                                  	;add	cx, ax ; + RootDirsectors
  4622                                  	;mov	[root_dir_secs], ax
  4623                                  
  4624                                  	; 11/02/2019
  4625                                  	;mov	cx, 33
  4626 00001A32 8B0E[186C]              	mov	cx, [root_dir_secs]
  4627 00001A36 034E0E                  	add	cx, [bp+0Eh]	; [BPB_RsvdSecCnt] ; 1
  4628                                  		; cx = root directory sectors + reserved sectors
  4629 00001A39 01C1                    	add	cx, ax
  4630                                  	; CX = [BPB_RsvdSecCnt]+([BPB_NumFATs]*[BPB_FATSz16])
  4631                                  	;	  + RootDirSectors
  4632 00001A3B 8B4613                  	mov	ax, [bp+13h]	; [BPB_TotSec16]
  4633 00001A3E 29C8                    	sub	ax, cx
  4634                                  		 ; AX = data sectors
  4635                                  		 ; cH = 0
  4636                                  
  4637                                  	; 11/02/2019 - fix FAT size (better method)
  4638 00001A40 09F6                    	or	si, si
  4639 00001A42 7504                    	jnz	short FAT12_f_9
  4640                                  
  4641 00001A44 89C6                    	mov	si, ax  ; ax = data sectors
  4642 00001A46 EBB9                    	jmp	short FAT12_f_10
  4643                                  
  4644                                  FAT12_f_9:
  4645 00001A48 31D2                    	xor	dx, dx
  4646 00001A4A 890E[0C6C]              	mov	[data_start], cx
  4647 00001A4E 8916[0E6C]              	mov	[data_start+2], dx ; 0
  4648                                  	; DX_AX = Data sectors
  4649 00001A52 A3[106C]                	mov	[data_sectors], ax
  4650 00001A55 8916[126C]              	mov	[data_sectors+2], dx ; 0
  4651 00001A59 8A4E0D                  	mov	cl, [bp+0Dh]	 ; [BPB_SecPerClus]
  4652 00001A5C 28ED                    	sub	ch, ch
  4653 00001A5E F7F1                    	div	cx
  4654                                  	; AX = Count of clusters (rounded down)
  4655 00001A60 29D2                    	sub	dx, dx ; 0
  4656 00001A62 A3[146C]                	mov	[cluster_count], ax
  4657 00001A65 8916[166C]              	mov	[cluster_count+2], dx ; 0
  4658                                  
  4659 00001A69 8D7E2B                  	lea	di, [bp+43] ; [BS_VolLab]
  4660 00001A6C E8CBFB                  	call	write_volume_name
  4661 00001A6F 8D7627                  	lea	si, [bp+39] ; [BS_VolID]
  4662 00001A72 E824FC                  	call	write_volume_serial
  4663 00001A75 E834FD                  	call	write_cluster_count	
  4664                                  
  4665 00001A78 E8A5FC                  	call	write_formatting_msg
  4666 00001A7B B000                    	mov	al, 0
  4667 00001A7D E8FDFC                  	call	write_format_percent_x
  4668                                  
  4669 00001A80 8B461C                  	mov	ax, [bp+1Ch]	; [BPB_HiddSec]
  4670 00001A83 8B561E                  	mov	dx, [bp+1Eh]	; [BPB_HiddSec+2]
  4671                                  
  4672 00001A86 0106[0C6C]              	add	[data_start], ax
  4673 00001A8A 1116[0E6C]              	adc	[data_start+2], dx
  4674                                  
  4675                                  	; DX_AX = FAT12 Boot Sector address
  4676 00001A8E BB[823A]                	mov	bx, TRDOS_FAT12_hd_bs
  4677                                  	; ES:BX = Boot Sector Buffer
  4678 00001A91 E8B003                  	call	write_hd_sector
  4679 00001A94 0F82F9FC                	jc	formatting_error
  4680 00001A98 E8A9FC                  	call	write_format_percent
  4681 00001A9B 83C001                  	add	ax, 1
  4682 00001A9E 83D200                  	adc	dx, 0
  4683                                  	; write remain part of reserved sectors
  4684 00001AA1 8B4E0E                  	mov	cx, [bp+0Eh] ; [BPB_RsvdSecCnt]
  4685                                  	;sub	cx, 1
  4686                                  	;jna	short FAT12_f_3
  4687                                  	; 11/02/2019
  4688 00001AA4 49                      	dec	cx
  4689 00001AA5 7418                    	jz	short FAT12_f_3
  4690                                  FAT12_f_2:
  4691 00001AA7 51                      	push	cx
  4692 00001AA8 BB[0C6A]                	mov	bx, HDFORMAT_EMPTY_BUFF
  4693 00001AAB E89603                  	call	write_hd_sector
  4694 00001AAE 0F82DFFC                	jc	formatting_error
  4695 00001AB2 E88FFC                  	call	write_format_percent
  4696 00001AB5 83C001                  	add	ax, 1
  4697 00001AB8 83D200                  	adc	dx, 0
  4698 00001ABB 59                      	pop	cx
  4699 00001ABC 49                      	dec	cx ; dec cl
  4700 00001ABD 75E8                    	jnz	short FAT12_f_2
  4701                                  FAT12_f_3:
  4702                                  	; write FAT sectors
  4703 00001ABF 8B0E[0C6C]              	mov	cx, [data_start] ; lba/abs addr
  4704 00001AC3 8B1E[0E6C]              	mov	bx, [data_start+2] ; lba/abs addr
  4705                                  
  4706                                  	; 11/02/2019
  4707 00001AC7 2B0E[186C]              	sub	cx, [root_dir_secs]
  4708 00001ACB 83DB00                  	sbb	bx, 0
  4709                                  
  4710 00001ACE 53                      	push	bx
  4711 00001ACF 51                      	push	cx
  4712 00001AD0 BB[0C6A]                	mov	bx, HDFORMAT_FATBUFFER
  4713                                  	; ES:BX = FAT Sector Buffer
  4714 00001AD3 8A4E15                  	mov	cl, [bp+15h] ; [BPB_Media]
  4715 00001AD6 B5FF                    	mov	ch, 0FFh
  4716 00001AD8 890F                    	mov	[bx], cx ; 0FFF8h
  4717 00001ADA 886F02                  	mov	[bx+2], ch ; 0FFFFF8h
  4718                                  	;xor	cx, cx
  4719 00001ADD E86403                  	call	write_hd_sector
  4720 00001AE0 0F82ADFC                	jc	formatting_error
  4721 00001AE4 E85DFC                  	call	write_format_percent
  4722                                  	;mov	bx, HDFORMAT_FATBUFFER
  4723 00001AE7 B90000                  	mov	cx, 0
  4724 00001AEA 890F                    	mov	[bx], cx
  4725 00001AEC 884F02                  	mov	[bx+2], cl
  4726 00001AEF EB0F                    	jmp	short FAT12_f_5
  4727                                  FAT12_f_4:	
  4728 00001AF1 53                      	push	bx
  4729 00001AF2 51                      	push	cx	
  4730 00001AF3 BB[0C6A]                	mov	bx, HDFORMAT_FATBUFFER
  4731 00001AF6 E84B03                  	call	write_hd_sector
  4732 00001AF9 0F8294FC                	jc	formatting_error
  4733 00001AFD E844FC                  	call	write_format_percent
  4734                                  FAT12_f_5:	
  4735 00001B00 59                      	pop	cx
  4736 00001B01 5B                      	pop	bx
  4737 00001B02 83C001                  	add	ax, 1
  4738 00001B05 83D200                  	adc	dx, 0
  4739 00001B08 39DA                    	cmp	dx, bx
  4740 00001B0A 72E5                    	jb	short FAT12_f_4
  4741 00001B0C 39C8                    	cmp	ax, cx
  4742 00001B0E 72E1                    	jb	short FAT12_f_4
  4743                                  
  4744                                  	; write	root directory sectors
  4745                                  	; as empty sectors
  4746 00001B10 8B0E[186C]              	mov	cx, [root_dir_secs]
  4747                                  FAT12_f_6:
  4748 00001B14 51                      	push	cx
  4749 00001B15 BB[0C6A]                	mov	bx, HDFORMAT_EMPTY_BUFF
  4750 00001B18 E82903                  	call	write_hd_sector
  4751 00001B1B 0F8272FC                	jc	formatting_error
  4752 00001B1F E822FC                  	call	write_format_percent
  4753 00001B22 83C001                  	add	ax, 1
  4754 00001B25 83D200                  	adc	dx, 0
  4755 00001B28 59                      	pop	cx
  4756 00001B29 49                      	dec	cx ; dec cl
  4757 00001B2A 75E8                    	jnz	short FAT12_f_6
  4758                                  
  4759                                  	; write DATA sectors 
  4760                                  	; (after root directory sectors)
  4761 00001B2C 8B0E[106C]              	mov	cx, [data_sectors]
  4762                                  	;mov	bx, [data_sectors+2]
  4763                                  	;inc	bx ; 11/02/2019
  4764                                  FAT12_f_7:	
  4765                                  	;push	bx
  4766 00001B30 51                      	push	cx	
  4767 00001B31 BB[0A66]                	mov	bx, HDFORMAT_SECBUFFER
  4768 00001B34 E80D03                  	call	write_hd_sector
  4769 00001B37 0F8256FC                	jc	formatting_error
  4770 00001B3B E806FC                  	call	write_format_percent
  4771 00001B3E 59                      	pop	cx
  4772                                  	;pop	bx
  4773 00001B3F 83C001                  	add	ax, 1
  4774 00001B42 83D200                  	adc	dx, 0
  4775 00001B45 49                      	dec	cx
  4776 00001B46 75E8                    	jnz	short FAT12_f_7
  4777                                  	;dec	bx
  4778                                  	;jnz	short FAT12_f_7
  4779                                  
  4780                                  	; If there are, format remain sectors which are
  4781                                  	; at beyond of data clusters, with zero bytes.
  4782                                  	
  4783 00001B48 8B4E1C                  	mov	cx, [bp+1Ch]	; [BPB_HiddSec]
  4784 00001B4B 8B5E1E                  	mov	bx, [bp+1Eh]	; [BPB_HiddSec+2]
  4785                                  
  4786 00001B4E 034E13                  	add	cx, [bp+13h]	; [BPB_TotSec16]
  4787 00001B51 83D300                  	adc	bx, 0
  4788 00001B54 E9ACFA                  	jmp	FAT12_f_8
  4789                                  
  4790                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4791                                  ; SINGLIX FS FORMATTING
  4792                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4793                                  
  4794                                  SINGLIX_hdi_format:
  4795                                  	; 06/01/2018
  4796                                  	; 05/01/2018
  4797                                  	; If Sectors/Track = 17, use CHS+LBA type boot sector
  4798 00001B57 8B1E[9640]              	mov	bx, [sectors]
  4799 00001B5B 83FB11                  	cmp	bx, 17
  4800 00001B5E 7711                    	ja	short SINGLIX_fs1_f_1
  4801                                  SINGLIX_fs1_f_0:
  4802 00001B60 BD[823C]                	mov	bp, TRDOS_TRFS1_chs_bs
  4803 00001B63 887E2D                  	mov	[bp+45], bh ; 0 ; [bs_LBA_Ready] = 0
  4804 00001B66 885E2E                  	mov	[bp+46], bl	; [bs_Disk_SecPerTrack]
  4805 00001B69 A0[9840]                	mov	al, [heads]
  4806 00001B6C 88462F                  	mov	[bp+47], al	; [bs_Disk_Heads]
  4807 00001B6F EB15                    	jmp	short SINGLIX_fs1_f_3
  4808                                  SINGLIX_fs1_f_1:
  4809                                  	; Sectors per Track = 63
  4810                                  	; If disk capacity >= 63*16*1024 use LBA type boot sector
  4811 00001B71 8B0E[9840]              	mov	cx, [heads]
  4812 00001B75 A1[9A40]                	mov	ax, [cylinders]
  4813 00001B78 F7E1                    	mul	cx
  4814 00001B7A 21D2                    	and	dx, dx
  4815 00001B7C 7505                    	jnz	short SINGLIX_fs1_f_2
  4816 00001B7E 3D0040                  	cmp	ax, 16384
  4817 00001B81 72DD                    	jb	short SINGLIX_fs1_f_0
  4818                                  SINGLIX_fs1_f_2:	
  4819 00001B83 BD[823E]                	mov	bp, TRDOS_TRFS1_lba_bs
  4820                                  	;mov	byte [bp+45], 1 ; [bs_LBA_Ready] = 1
  4821                                  SINGLIX_fs1_f_3:	
  4822                                  	;mov	ax, [pp_Sectors]
  4823                                  	;mov	dx, [pp_Sectors+2]
  4824                                  	; 16/02/2019
  4825 00001B86 A1[C86E]                	mov	ax, [ppn_Sectors]
  4826 00001B89 8B16[CA6E]              	mov	dx, [ppn_Sectors+2]
  4827 00001B8D 894610                  	mov	[bp+16], ax	; [bsVolumeSize]
  4828 00001B90 895612                  	mov	[bp+18], dx	; [bsVolumeSize+2]
  4829 00001B93 8B0E[946E]              	mov	cx, [pp_StartSector]
  4830 00001B97 8B1E[966E]              	mov	bx, [pp_StartSector+2]
  4831 00001B9B 894E0C                  	mov	[bp+12], cx	; [bsBeginSector]
  4832 00001B9E 895E0E                  	mov	[bp+14], bx	; [bsBeginSector+2]
  4833 00001BA1 C6462C80                	mov	byte [bp+44], 80h ; [bsDriveNumber]  ; hd0
  4834                                  
  4835                                  	; Prepare MAT
  4836 00001BA5 A3[706C]                	mov	[MAT_VolumeSize], ax ; Total Sectors of the FS
  4837 00001BA8 8916[726C]              	mov	[MAT_VolumeSize+2], dx
  4838 00001BAC 890E[746C]              	mov	[MAT_BeginSector], cx ; Beginning Sector of the FS
  4839 00001BB0 891E[766C]              	mov	[MAT_BeginSector+2], bx
  4840                                  	;mov	cx, [bp+24]	; [bsMATLocation]
  4841                                  	;mov	bx, [bp+26]	; [bsMATLocation+2]
  4842                                  	;add	cx, 1
  4843                                  	;adc	bx, 0
  4844                                  	; Note: (as Default) MAT Address = 1, DAT Address = 2 
  4845 00001BB4 B90200                  	mov	cx, 2
  4846                                  	;xor	bx, bx ; 0
  4847                                  	;mov	[bp+24], cx	; [bsMATLocation]
  4848                                  	;mov	[bp+26], bx	; [bsMATLocation+2]
  4849 00001BB7 890E[786C]              	mov	[DAT_Address], cx
  4850                                  	;mov	[DAT_Address+2], bx
  4851                                  	; DX_AX = FS1 Volume Size
  4852 00001BBB 83C007                  	add	ax, 7 ; 7 bits more (for round up)
  4853 00001BBE 83D200                  	adc	dx, 0
  4854 00001BC1 B90800                  	mov	cx, 8 ;  1 DAT byte == 8 sectors 
  4855 00001BC4 E86FF2                  	call	div32
  4856                                  	; DX_AX = DAT bytes
  4857 00001BC7 B9FF01                  	mov	cx, 511
  4858 00001BCA 01C8                    	add	ax, cx
  4859 00001BCC 83D200                  	adc	dx, 0
  4860 00001BCF 41                      	inc	cx ; 512
  4861 00001BD0 E863F2                  	call	div32
  4862                                  	; DX_AX = DAT sectors (DX must be 0 for volume sizes < 128GB)
  4863 00001BD3 A3[7C6C]                	mov	[DAT_SectorCount], ax
  4864                                  	;mov	[DAT_SectorCount+2], dx ; 0
  4865                                  
  4866 00001BD6 83C002                  	add	ax, 2  ; BS + MAT
  4867                                  	;adc	dx, 0
  4868 00001BD9 89461C                  	mov	[bp+28], ax  ; [bsRootDirDT] ; RDT address (offset)
  4869                                  	;mov	[bp+30], dx
  4870                                  
  4871                                  	; Free Sectors = Total Sectors - (BS+MAT+DATsects+RDT+4)	 
  4872 00001BDC 83C005                  	add	ax, 5 ; DATsects + (BS+MAT+RDT+4)
  4873 00001BDF 89C2                    	mov	dx, ax
  4874 00001BE1 8B0E[706C]              	mov	cx, [MAT_VolumeSize]
  4875 00001BE5 8B1E[726C]              	mov	bx, [MAT_VolumeSize+2]
  4876 00001BE9 29C1                    	sub	cx, ax
  4877 00001BEB 83DB00                  	sbb	bx, 0
  4878 00001BEE 890E[806C]              	mov	[MAT_FreeSectors], cx
  4879 00001BF2 891E[826C]              	mov	[MAT_FreeSectors+2], bx
  4880 00001BF6 A3[846C]                	mov	[MAT_FirstFreeSector], ax
  4881                                  	;mov	word [MAT_FirstFreesector+2] , 0
  4882                                  
  4883 00001BF9 BF[206C]                	mov	di, fs_volume_name
  4884 00001BFC E834FA                  	call	write_fs_volume_name
  4885 00001BFF BE[606C]                	mov	si, fs_volume_serial
  4886 00001C02 E894FA                  	call	write_volume_serial
  4887                                  
  4888                                  	; Modify FS volume name
  4889                                  	; (Convert 20h tail bytes to 0)
  4890 00001C05 B94000                  	mov	cx, 64 
  4891 00001C08 BE[206C]                	mov	si, fs_volume_name
  4892 00001C0B 31DB                    	xor	bx, bx
  4893 00001C0D B0FF                    	mov	al, 0FFh
  4894                                  modify_fs_vname_1:	
  4895 00001C0F 88C4                    	mov	ah, al
  4896 00001C11 AC                      	lodsb
  4897 00001C12 3C20                    	cmp	al, 20h
  4898 00001C14 7708                    	ja	short modify_fs_vname_2
  4899 00001C16 80FC20                  	cmp	ah, 20h
  4900 00001C19 7603                    	jna	short modify_fs_vname_2
  4901 00001C1B 89F3                    	mov	bx, si
  4902 00001C1D 4B                      	dec	bx
  4903                                  modify_fs_vname_2:
  4904 00001C1E E2EF                    	loop	modify_fs_vname_1		
  4905 00001C20 09DB                    	or	bx, bx
  4906 00001C22 740B                    	jz	short modify_fs_vname_3
  4907 00001C24 89DF                    	mov	di, bx
  4908 00001C26 B9[606C]                	mov	cx, fs_volume_name+64
  4909 00001C29 29D9                    	sub	cx, bx
  4910 00001C2B 30C0                    	xor	al, al
  4911 00001C2D F3AA                    	rep	stosb 
  4912                                  
  4913                                  modify_fs_vname_3:
  4914 00001C2F E8EEFA                  	call	write_formatting_msg
  4915 00001C32 B000                    	mov	al, 0
  4916 00001C34 E846FB                  	call	write_format_percent_x
  4917                                  
  4918 00001C37 8B460C                  	mov	ax, [bp+12]	; [bsBeginSector]
  4919 00001C3A 8B560E                  	mov	dx, [bp+14]	; [bsBeginSector+2]
  4920                                  
  4921                                  	; DX_AX = TRFS1 Boot Sector address
  4922 00001C3D 89EB                    	mov	bx, bp
  4923                                  	; ES:BX = Boot Sector Buffer
  4924 00001C3F E80202                  	call	write_hd_sector
  4925 00001C42 0F824BFB                	jc	formatting_error
  4926                                  	
  4927 00001C46 83C001                  	add	ax, 1
  4928 00001C49 83D200                  	adc	dx, 0
  4929                                  
  4930                                  	; DX_AX = MAT (DAT header) sector address
  4931 00001C4C BB[6C6C]                	mov	bx, FS_MAT_Buffer
  4932                                  	; 16/02/2019
  4933 00001C4F C7074D41                	mov	word [bx],'MA'
  4934 00001C53 C6470254                	mov	byte [bx+2],'T'
  4935 00001C57 E8EA01                  	call	write_hd_sector
  4936 00001C5A 0F8233FB                	jc	formatting_error
  4937 00001C5E E823FB                  	call	write_fs_format_percent
  4938                                  
  4939                                  	; Calculate DAT bits 
  4940                                  	; NOTE: 4096 bits per DAT sector
  4941 00001C61 A1[846C]                	mov	ax, [MAT_FirstFreeSector]
  4942                                  	;mov	dx, [MAT_FirstFreeSector+2]
  4943 00001C64 31D2                    	xor	dx, dx
  4944 00001C66 52                      	push	dx
  4945 00001C67 50                      	push	ax
  4946 00001C68 B90010                  	mov	cx, 4096
  4947 00001C6B E8C8F1                  	call	div32
  4948 00001C6E 891E[646C]              	mov	[DAT_FFBit], bx
  4949 00001C72 A3[666C]                	mov	[DAT_FFSector], ax
  4950 00001C75 58                      	pop	ax
  4951 00001C76 5A                      	pop	dx
  4952 00001C77 83E801                  	sub	ax, 1
  4953 00001C7A 83DA00                  	sbb	dx, 0
  4954 00001C7D 0306[806C]              	add	ax, [MAT_FreeSectors]
  4955 00001C81 1316[826C]              	adc	dx, [MAT_FreeSectors+2]
  4956 00001C85 E8AEF1                  	call	div32
  4957 00001C88 891E[686C]              	mov	[DAT_LFBit], bx
  4958 00001C8C A3[6A6C]                	mov	[DAT_LFSector], ax
  4959                                  
  4960 00001C8F 31F6                    	xor	si, si ; 0
  4961                                  SINGLIX_fs1_f_4:
  4962                                  	; calculate free bits for current DAT sector
  4963                                  	;			(to be written)
  4964 00001C91 BF[886C]                	mov	di, FS_DAT_Buffer
  4965 00001C94 3B36[666C]              	cmp	si, [DAT_FFSector]
  4966 00001C98 7431                    	je	short SINGLIX_fs1_f_7
  4967 00001C9A 724D                    	jb	short SINGLIX_fs1_f_9
  4968 00001C9C 3B36[6A6C]              	cmp	si, [DAT_LFSector]
  4969 00001CA0 7224                    	jb	short SINGLIX_fs1_f_6
  4970 00001CA2 7745                    	ja	short SINGLIX_fs1_f_9
  4971 00001CA4 8B1E[686C]              	mov	bx, [DAT_LFBit]
  4972 00001CA8 B0FF                    	mov	al, 0FFh
  4973 00001CAA 88DC                    	mov	ah, bl
  4974 00001CAC C1EB03                  	shr	bx, 3 ; bit count to byte count
  4975 00001CAF 7409                    	jz	short SINGLIX_fs1_f_5
  4976 00001CB1 89D9                    	mov	cx, bx
  4977 00001CB3 F3AA                    	rep	stosb
  4978 00001CB5 BF[886C]                	mov	di, FS_DAT_Buffer
  4979 00001CB8 01DF                    	add	di, bx
  4980                                  SINGLIX_fs1_f_5:
  4981 00001CBA 80E407                  	and	ah, 7
  4982 00001CBD 88E1                    	mov	cl, ah 
  4983 00001CBF D2E0                    	shl	al, cl
  4984 00001CC1 F6D0                    	not	al
  4985 00001CC3 AA                      	stosb
  4986                                  	;mov	cx, 511
  4987                                  	;sub	cx, bx
  4988                                  	;jna	short SINGLIX_fs1_f_9
  4989                                  	;mov	al, 0 ; out of volume bits (=0)
  4990                                  	;rep	stosb
  4991 00001CC4 EB23                    	jmp	short SINGLIX_fs1_f_9
  4992                                  SINGLIX_fs1_f_6:
  4993 00001CC6 B90002                  	mov	cx, 512
  4994 00001CC9 EB1A                    	jmp	short SINGLIX_fs1_f_8
  4995                                  SINGLIX_fs1_f_7:
  4996 00001CCB 8B1E[646C]              	mov	bx, [DAT_FFBit]
  4997 00001CCF 88D9                    	mov	cl, bl
  4998 00001CD1 80E107                  	and	cl, 7
  4999 00001CD4 C1EB03                  	shr	bx, 3 ; from bits to bytes
  5000 00001CD7 01DF                    	add	di, bx
  5001 00001CD9 B0FF                    	mov	al, 0FFh
  5002 00001CDB D2E0                    	shl	al, cl
  5003 00001CDD AA                      	stosb
  5004 00001CDE B9FF01                  	mov	cx, 511
  5005 00001CE1 29D9                    	sub	cx, bx
  5006 00001CE3 7604                    	jna	short SINGLIX_fs1_f_9
  5007                                  SINGLIX_fs1_f_8:
  5008 00001CE5 B0FF                    	mov	al, 0FFh ; Free sector bits (=1)
  5009 00001CE7 F3AA                    	rep	stosb
  5010                                  SINGLIX_fs1_f_9:
  5011 00001CE9 A1[746C]                	mov	ax, [MAT_BeginSector]
  5012 00001CEC 8B16[766C]              	mov	dx, [MAT_BeginSector+2]
  5013                                  	;add	ax, [DAT_Address] ; = 2
  5014                                  	;adc	dx, [DAT_Address+2]
  5015 00001CF0 83C002                  	add	ax, 2
  5016 00001CF3 83D200                  	adc	dx, 0
  5017 00001CF6 01F0                    	add	ax, si
  5018 00001CF8 83D200                  	adc	dx, 0
  5019                                  	; Write DAT sector(s)
  5020                                  	; DX_AX = Disk Allocation Table sector address
  5021 00001CFB BB[886C]                	mov	bx, FS_DAT_Buffer
  5022 00001CFE E84301                  	call	write_hd_sector
  5023 00001D01 0F828CFA                	jc	formatting_error
  5024 00001D05 E87CFA                  	call	write_fs_format_percent
  5025                                  	; Clear DAT buffer again (for next stage)
  5026 00001D08 B90001                  	mov	cx, 256
  5027 00001D0B BF[886C]                	mov	di, FS_DAT_Buffer
  5028 00001D0E 29C0                    	sub	ax, ax
  5029 00001D10 F3AB                    	rep	stosw
  5030                                  
  5031 00001D12 46                      	inc	si
  5032                                  
  5033 00001D13 3B36[7C6C]              	cmp	si, [DAT_SectorCount]
  5034 00001D17 0F8676FF                	jna	SINGLIX_fs1_f_4
  5035                                  
  5036                                  	; ;;;
  5037                                  	
  5038                                  	; DAT sectors has been written..
  5039                                  	; Now, Root Directory Description Table is in order
  5040                                  
  5041 00001D1B BF[886C]                	mov	di, FS_RDT_Buffer
  5042 00001D1E B84444                  	mov	ax, 'DD' 
  5043 00001D21 AB                      	stosw
  5044 00001D22 30E4                    	xor	ah, ah
  5045 00001D24 B054                    	mov	al, 'T'
  5046 00001D26 AB                      	stosw
  5047 00001D27 B80002                  	mov	ax, 512 ; Sector size (Bytes per sector)	
  5048 00001D2A AB                      	stosw
  5049 00001D2B 31C0                    	xor	ax, ax ; RDT sequence number (= 0, section 1)
  5050 00001D2D AB                      	stosw	
  5051                                  	; RDT address
  5052 00001D2E A1[7C6C]                	mov	ax, [DAT_SectorCount]
  5053 00001D31 8B16[7E6C]              	mov	dx, [DAT_SectorCount+2]
  5054 00001D35 83C002                  	add	ax, 2 ; BS + MAT
  5055 00001D38 83D200                  	adc	dx, 0
  5056 00001D3B AB                      	stosw
  5057 00001D3C 89D0                    	mov	ax, dx
  5058 00001D3E AB                      	stosw
  5059 00001D3F 29C0                    	sub	ax, ax ; Next RDT number
  5060 00001D41 AB                      	stosw
  5061 00001D42 AB                      	stosw
  5062 00001D43 B80400                  	mov	ax, 4 ; Sector count of this section	
  5063                                  		      ; (4*512)/4 = 512 root dir entries
  5064 00001D46 AB                      	stosw
  5065 00001D47 30C0                    	xor	al, al
  5066 00001D49 AB                      	stosw
  5067                                  	; Volume beginning sector
  5068 00001D4A 8B460C                  	mov	ax, [bp+12]	; [bsBeginSector]
  5069 00001D4D 8B560E                  	mov	dx, [bp+14]	; [bsBeginSector+2]
  5070 00001D50 AB                      	stosw
  5071 00001D51 89D0                    	mov	ax, dx
  5072 00001D53 AB                      	stosw
  5073 00001D54 31C0                    	xor	ax, ax
  5074 00001D56 48                      	dec	ax ; 0FFFFh
  5075                                  	; Parent Dir Serial (= FFFFFFFFh for root dir)
  5076 00001D57 AB                      	stosw
  5077 00001D58 AB                      	stosw
  5078                                  
  5079                                  set_fs_volume_serial_number:
  5080 00001D59 BE[606C]                	mov	si, fs_volume_serial
  5081 00001D5C A5                      	movsw
  5082 00001D5D A5                      	movsw
  5083                                  
  5084 00001D5E 29C0                    	sub	ax, ax
  5085 00001D60 AA                      	stosb	; sub directory level = 0
  5086 00001D61 AA                      	stosb	; 0, reverved
  5087 00001D62 B004                    	mov	al, 00000100b ;  (DOS) System attribute
  5088 00001D64 AA                      	stosb	; (DOS) Basic attributes
  5089 00001D65 28C0                    	sub	al, al ; Extended attributes (0 for TRDOS 386)
  5090 00001D67 AA                      	stosb
  5091 00001D68 29C0                    	sub	ax, ax ; reserved (8) bytes for TR-MULTIX
  5092 00001D6A AB                      	stosw
  5093 00001D6B AB                      	stosw
  5094 00001D6C AB                      	stosw
  5095 00001D6D AB                      	stosw
  5096 00001D6E B85254                  	mov	ax, 'RT' ; TRFS Root directory signature
  5097 00001D71 AB                      	stosw
  5098 00001D72 31C0                    	xor	ax, ax ; Country (language, date, text format)
  5099                                  		       ; (0 = Default, 1 = USA, 90 = Turkiye)
  5100 00001D74 AA                      	stosb
  5101 00001D75 AA                      	stosb	; Time Zone (0 = GMT = default ; -11 to +12)
  5102                                  
  5103 00001D76 89FE                    	mov	si, di
  5104                                  	; get the date (from RTC)
  5105 00001D78 B404                    	mov	ah, 4
  5106 00001D7A CD1A                    	int	1Ah
  5107                                  	; Creating Date (of root directory)
  5108 00001D7C 86E9                    	xchg	ch, cl ; 07/01/2018
  5109 00001D7E 89C8                    	mov	ax, cx ; cl = century (BCD), ch = year (BCD)
  5110 00001D80 AB                      	stosw
  5111 00001D81 88F0                    	mov	al, dh  ; month (BCD)
  5112 00001D83 AA                      	stosb
  5113 00001D84 88D0                    	mov	al, dl  ; day (BCD)
  5114 00001D86 AA                      	stosb
  5115                                  	; get the time (from RTC)
  5116 00001D87 B402                    	mov	ah, 2
  5117 00001D89 CD1A                    	int	1Ah
  5118                                  	; Creating Time (of root directory)
  5119 00001D8B 86CD                    	xchg	cl, ch ; ch = hour (BCD), cl = minute (BSD)
  5120 00001D8D 89C8                    	mov	ax, cx ; al = hour, ah = minute
  5121 00001D8F AB                      	stosw
  5122 00001D90 88F0                    	mov	al, dh ; seconds (BCD)
  5123 00001D92 AA                      	stosb
  5124 00001D93 88D0                    	mov	al, dl ; daylight savings time option 
  5125 00001D95 AA                      	stosb
  5126                                  	; Set Last Modification Date&Time
  5127 00001D96 B90400                  	mov	cx, 4
  5128 00001D99 F3A5                    	rep	movsw ; copy creating date&time values to
  5129                                  		; last modification date time values	
  5130                                  		; (last modif date&time = creating date&time)
  5131                                  
  5132                                  set_fs_volume_name:
  5133 00001D9B BE[206C]                	mov	si, fs_volume_name
  5134 00001D9E B120                    	mov	cl, 32 
  5135 00001DA0 F3A5                    	rep	movsw
  5136                                  
  5137                                  	; Fill remain bytes (of this RDT) with zero
  5138 00001DA2 B9C000                  	mov	cx, (128+256)/2
  5139 00001DA5 31C0                    	xor	ax, ax
  5140 00001DA7 F3AB                    	rep	stosw
  5141                                  
  5142                                  	; RDT is ready here...
  5143                                  
  5144 00001DA9 8B461C                  	mov	ax, [bp+28]	; [bsRootDirDT]
  5145                                  	;mov	dx, [bp+30]	; [bsRootDirDT+2]
  5146 00001DAC 31D2                    	xor	dx, dx
  5147 00001DAE 03460C                  	add	ax, [bp+12]	; [bsBeginSector]
  5148 00001DB1 13560E                  	adc	dx, [bp+14]	; [bsBeginSector+2]
  5149                                  
  5150                                  	; Write RDT sector
  5151                                  	; DX_AX = Root Directory Description Table address
  5152 00001DB4 BB[886C]                	mov	bx, FS_RDT_Buffer
  5153 00001DB7 E88A00                  	call	write_hd_sector
  5154 00001DBA 0F82D3F9                	jc	formatting_error
  5155 00001DBE E8C3F9                  	call	write_fs_format_percent
  5156                                  
  5157 00001DC1 83C001                  	add	ax, 1
  5158 00001DC4 83D200                  	adc	dx, 0
  5159                                  
  5160                                  	; write root directory data sectors
  5161 00001DC7 B90400                  	mov	cx, 4
  5162                                  
  5163                                  SINGLIX_fs1_f_10:
  5164 00001DCA 51                      	push	cx
  5165                                  	; Write root directory sector(s)
  5166                                  	; DX_AX = Root Directory Sector address
  5167 00001DCB BB[0C6A]                	mov	bx, HDFORMAT_EMPTY_BUFF
  5168 00001DCE E87300                  	call	write_hd_sector
  5169 00001DD1 0F82BCF9                	jc	formatting_error
  5170 00001DD5 E8ACF9                  	call	write_fs_format_percent
  5171 00001DD8 83C001                  	add	ax, 1
  5172 00001DDB 83D200                  	adc	dx, 0
  5173 00001DDE 59                      	pop	cx
  5174 00001DDF FEC9                    	dec	cl
  5175 00001DE1 75E7                    	jnz	short SINGLIX_fs1_f_10
  5176                                  
  5177                                  	; Fill remain sectors with 'F6h' bytes
  5178 00001DE3 8B4E10                  	mov	cx, [bp+16]	; [bsVolumeSize]
  5179 00001DE6 8B5E12                  	mov	bx, [bp+18]	; [bsVolumeSize+2]
  5180 00001DE9 034E0C                  	add	cx, [bp+12]	; [bsBeginSector]
  5181 00001DEC 135E0E                  	adc	bx, [bp+14]	; [bsBeginSector+2]
  5182                                  
  5183                                  	; write DATA sectors 
  5184                                  	; (after root directory sectors)
  5185                                  SINGLIX_fs1_f_11:
  5186 00001DEF 53                      	push	bx
  5187 00001DF0 51                      	push	cx
  5188 00001DF1 BB[0A66]                	mov	bx, HDFORMAT_SECBUFFER
  5189 00001DF4 E84D00                  	call	write_hd_sector
  5190 00001DF7 0F8296F9                	jc	formatting_error
  5191 00001DFB E846F9                  	call	write_format_percent
  5192 00001DFE 59                      	pop	cx
  5193 00001DFF 5B                      	pop	bx
  5194 00001E00 83C001                  	add	ax, 1
  5195 00001E03 83D200                  	adc	dx, 0
  5196 00001E06 39DA                    	cmp	dx, bx
  5197 00001E08 72E5                    	jb	short SINGLIX_fs1_f_11
  5198 00001E0A 0F8717F8                	ja	SINGLIX_fs1_f_12
  5199 00001E0E 39C8                    	cmp	ax, cx
  5200 00001E10 72DD                    	jb	short SINGLIX_fs1_f_11
  5201 00001E12 E910F8                  	jmp	SINGLIX_fs1_f_12	
  5202                                  
  5203                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5204                                  ; Print error message and exit
  5205                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5206                                  ; 25/02/2019
  5207                                  	
  5208                                  D_01:
  5209 00001E15 50                      	push	ax
  5210 00001E16 8B1E[9440]              	mov	bx, [img_file_handle]
  5211 00001E1A B43E                    	mov	ah, 3Eh ; close file
  5212 00001E1C CD21                    	int	21h
  5213 00001E1E 58                      	pop	ax
  5214                                  
  5215                                  	; 11/02/2019
  5216                                  	;mov 	word [img_file_handle], 0
  5217                                  D_02:
  5218 00001E1F 88E0                    	mov	al, ah ;  error code
  5219 00001E21 E8B000                  	call	bin_to_hex
  5220 00001E24 A3[5E56]                	mov 	[error_code], ax
  5221                                  
  5222 00001E27 BE[5056]                	mov	si, CRLF
  5223 00001E2A E80800                  	call	print_msg
  5224                                  
  5225 00001E2D BE[5356]                	mov	si, Msg_Error
  5226                                  
  5227 00001E30 E80200                  	call	print_msg
  5228                                  
  5229 00001E33 CD20                    	int	20h	; Exit
  5230                                  
  5231                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5232                                  ; Print messages
  5233                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5234                                  
  5235                                  print_msg:
  5236                                  
  5237                                  print_msg_LOOP:
  5238 00001E35 AC                      	lodsb                           ; Load byte at DS:SI to AL
  5239 00001E36 20C0                    	and     al, al            
  5240 00001E38 7409                    	jz      short print_msg_OK       
  5241 00001E3A B40E                    	mov	ah, 0Eh			
  5242 00001E3C BB0700                  	mov     bx, 07h             
  5243 00001E3F CD10                    	int	10h			; BIOS Service func ( ah ) = 0Eh
  5244                                  					; Write char as TTY
  5245                                  					; AL-char BH-page BL-color
  5246 00001E41 EBF2                    	jmp     short print_msg_LOOP           
  5247                                  
  5248                                  print_msg_OK:
  5249 00001E43 C3                      	retn
  5250                                  
  5251                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5252                                  ; Writing a block (sector) to hard disk disk image file
  5253                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5254                                  
  5255                                  write_hd_sector:
  5256                                  	; INPUT -> DX_AX = Logical Block Address
  5257                                  	; 	   ES:BX = Sector Buffer
  5258                                  	; OUTPUT ->
  5259                                  	;  cf = 0 -> DX_AX = Logical Block Adress
  5260                                  	;	     ES:BX = Sector Buffer
  5261                                  	;  cf = 1 -> AH = Error Number
  5262                                  	;
  5263 00001E44 52                      	push	dx ; sector (hw)
  5264 00001E45 50                      	push	ax ; sector (lw)
  5265 00001E46 53                      	push	bx ; buffer
  5266 00001E47 B90002                  	mov	cx, 512
  5267                                  	; DX_AX: Multiplicand
  5268                                  	; CX = Multiplier
  5269 00001E4A E8F7EF                  	call	mul32
  5270                                  	; BX_DX_AX = result of multiplication (product)
  5271 00001E4D 21DB                    	and	bx, bx
  5272 00001E4F 7529                    	jnz	short image_file_size_err
  5273 00001E51 F6C680                  	test	dh, 80h
  5274 00001E54 7524                    	jnz	short image_file_size_err	
  5275 00001E56 8B1E[9440]              	mov 	bx, [img_file_handle]
  5276 00001E5A 803E[9C40]00            	cmp	byte [random], 0
  5277 00001E5F 760A                    	jna	short whds
  5278 00001E61 89D1                    	mov	cx, dx
  5279 00001E63 89C2                    	mov	dx, ax
  5280 00001E65 28C0                    	sub	al, al ; specified offset is from the beginning of the file
  5281 00001E67 B442                    	mov	ah, 42h ; seek (move file pointer)
  5282 00001E69 CD21                    	int	21h
  5283                                  whds:
  5284                                  	;mov	bx, [img_file_handle]
  5285 00001E6B B90002                  	mov	cx, 512
  5286 00001E6E 5A                      	pop	dx  ; buffer address
  5287 00001E6F B440                    	mov	ah, 40h ; write to file	
  5288 00001E71 CD21                    	int	21h
  5289 00001E73 89D3                    	mov	bx, dx
  5290 00001E75 7209                    	jc	short image_file_rw_err
  5291 00001E77 58                      	pop	ax ; sector (lw)
  5292 00001E78 5A                      	pop	dx ; sector (hw) 
  5293 00001E79 C3                      	retn
  5294                                  
  5295                                  image_file_size_err:
  5296 00001E7A 5B                      	pop	bx
  5297 00001E7B 30C0                    	xor	al, al
  5298                                  	;mov	ah, 1Bh ; sector not found error
  5299 00001E7D B419                    	mov	ah, 19h ; Seek error
  5300 00001E7F F9                      	stc
  5301                                  
  5302                                  image_file_rw_err:
  5303 00001E80 5A                      	pop	dx ; sector (lw)
  5304 00001E81 5A                      	pop	dx ; sector (hw)
  5305 00001E82 C3                      	retn
  5306                                  
  5307                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5308                                  ; Reading a block (sector) from hard disk disk image file
  5309                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5310                                  
  5311                                  read_hd_sector:
  5312                                  	; INPUT -> DX_AX = Logical Block Address
  5313                                  	; 	   ES:BX = Sector Buffer
  5314                                  	; OUTPUT ->
  5315                                  	;  cf = 0 -> DX_AX = Logical Block Adress
  5316                                  	;	     ES:BX = Sector Buffer
  5317                                  	;  cf = 1 -> AH = Error Number
  5318                                  	;
  5319 00001E83 52                      	push	dx ; sector (hw)
  5320 00001E84 50                      	push	ax ; sector (lw)
  5321 00001E85 53                      	push	bx ; buffer
  5322 00001E86 B90002                  	mov	cx, 512
  5323                                  	; DX_AX: Multiplicand
  5324                                  	; CX = Multiplier
  5325 00001E89 E8B8EF                  	call	mul32
  5326                                  	; BX_DX_AX = result of multiplication (product)
  5327 00001E8C 21DB                    	and	bx, bx
  5328 00001E8E 75EA                    	jnz	short image_file_size_err
  5329 00001E90 F6C680                  	test	dh, 80h
  5330 00001E93 75E5                    	jnz	short image_file_size_err	
  5331 00001E95 8B1E[9440]              	mov 	bx, [img_file_handle]
  5332 00001E99 803E[9C40]00            	cmp	byte [random], 0
  5333 00001E9E 760A                    	jna	short rhds
  5334 00001EA0 89D1                    	mov	cx, dx
  5335 00001EA2 89C2                    	mov	dx, ax
  5336 00001EA4 28C0                    	sub	al, al ; specified offset is from the beginning of the file
  5337 00001EA6 B442                    	mov	ah, 42h ; seek (move file pointer)
  5338 00001EA8 CD21                    	int	21h
  5339                                  rhds:
  5340                                  	;mov	bx, [img_file_handle]
  5341 00001EAA B90002                  	mov	cx, 512
  5342 00001EAD 5A                      	pop	dx  ; buffer address
  5343 00001EAE B43F                    	mov	ah, 3Fh ; read from file	
  5344 00001EB0 CD21                    	int	21h
  5345 00001EB2 89D3                    	mov	bx, dx
  5346 00001EB4 72CA                    	jc	short image_file_rw_err
  5347 00001EB6 39C8                    	cmp	ax, cx
  5348 00001EB8 75C0                    	jne	short image_file_size_err
  5349 00001EBA 58                      	pop	ax ; sector (lw)
  5350 00001EBB 5A                      	pop	dx ; sector (hw) 
  5351 00001EBC C3                      	retn
  5352                                  	
  5353                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5354                                  ; Convert byte to decimal number
  5355                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5356                                  
  5357                                  bin_to_decimal:
  5358                                  	; INPUT: DS:SI = Target location
  5359                                  	;        DX_AX = Binary Number (Integer)
  5360                                  	; OUTPUT: Decimal char at DS:SI
  5361                                  	; 	 SI decremented after every division
  5362                                  	; 	 till AX<10.
  5363                                  	; CX, DX, BX will be changed.
  5364                                  	;
  5365 00001EBD B90A00                  	mov	cx, 10
  5366                                  btd_0:
  5367                                  	; DX_AX = Dividend
  5368                                  	; CX = Divisor
  5369 00001EC0 E873EF                  	call	div32
  5370                                  	; DX_AX = Quotient
  5371                                  	; BX = remainder
  5372 00001EC3 80C330                  	add	bl, '0'
  5373 00001EC6 881C                    	mov	[si], bl
  5374 00001EC8 21D2                    	and	dx, dx
  5375 00001ECA 7403                    	jz	short btd_2
  5376                                  btd_1:
  5377 00001ECC 4E                      	dec	si
  5378 00001ECD EBF1                    	jmp	short btd_0
  5379                                  btd_2:
  5380 00001ECF 09C0                    	or	ax, ax
  5381 00001ED1 75F9                    	jnz	short btd_1
  5382                                  
  5383 00001ED3 C3                      	retn
  5384                                  
  5385                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5386                                  ; Convert byte to hexadecimal number
  5387                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5388                                  
  5389                                  byte_to_hex: ; 04/02/2019
  5390                                  bin_to_hex:
  5391                                  	; INPUT ->
  5392                                  	; 	AL = byte (binary number)
  5393                                  	; OUTPUT ->
  5394                                  	;	AX = hexadecimal string
  5395                                  	;
  5396 00001ED4 53                      	push	bx
  5397 00001ED5 31DB                    	xor	bx, bx
  5398 00001ED7 88C3                    	mov	bl, al
  5399 00001ED9 C0EB04                  	shr	bl, 4
  5400 00001EDC 8A9F[8340]              	mov	bl, [bx+hexchrs] 	 	
  5401 00001EE0 86D8                    	xchg	bl, al
  5402 00001EE2 80E30F                  	and	bl, 0Fh
  5403 00001EE5 8AA7[8340]              	mov	ah, [bx+hexchrs] 
  5404 00001EE9 5B                      	pop	bx	
  5405 00001EEA C3                      	retn
  5406                                  
  5407                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5408                                  ; Read & Write characters
  5409                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5410                                  
  5411                                  rw_char:
  5412                                  	; OUTPUT -> DS:SI = Entered String (ASCIIZ)
  5413 00001EEB BE[AD55]                	mov     si, StrVolumeName
  5414 00001EEE BB0700                  	mov     bx, 7
  5415 00001EF1 B403                    	mov     ah, 3
  5416 00001EF3 CD10                    	int     10h
  5417 00001EF5 8916[9455]              	mov     [Cursor_Pos], dx
  5418                                  read_next_char:
  5419 00001EF9 30E4                    	xor     ah, ah
  5420 00001EFB CD16                    	int     16h
  5421 00001EFD 20C0                    	and     al, al
  5422 00001EFF 7439                    	jz      short loc_arrow    
  5423 00001F01 3CE0                    	cmp     al, 0E0h          
  5424 00001F03 7435                    	je      short loc_arrow
  5425 00001F05 3C08                    	cmp     al, 8
  5426 00001F07 753D                    	jne     short char_return
  5427                                  loc_back:
  5428 00001F09 B403                    	mov     ah, 3
  5429 00001F0B CD10                    	int     10h
  5430 00001F0D 3A16[9455]              	cmp     dl, byte [Cursor_Pos]
  5431 00001F11 761F                    	jna     short loc_beep
  5432                                  prev_column:
  5433 00001F13 FECA                    	dec     dl
  5434                                  set_cursor_pos:
  5435 00001F15 B402                    	mov     ah, 2
  5436 00001F17 CD10                    	int     10h
  5437 00001F19 88D3                    	mov     bl, dl
  5438 00001F1B 2A1E[9455]              	sub     bl, byte [Cursor_Pos] 
  5439 00001F1F B90100                  	mov     cx, 1
  5440 00001F22 B409                    	mov     ah, 9
  5441 00001F24 B020                    	mov     al, 20h
  5442 00001F26 8800                    	mov     [si+bx], al
  5443                                  loc_write_it:
  5444 00001F28 B307                    	mov     bl, 7
  5445 00001F2A CD10                    	int     10h
  5446 00001F2C 8B16[9455]              	mov     dx, [Cursor_Pos]
  5447 00001F30 EBC7                    	jmp     short read_next_char
  5448                                  loc_beep:
  5449 00001F32 B40E                    	mov     ah, 0Eh
  5450 00001F34 B007                    	mov     al, 7
  5451 00001F36 CD10                    	int     10h
  5452 00001F38 EBBF                    	jmp     short read_next_char
  5453                                  loc_arrow:    
  5454 00001F3A 80FC4B                  	cmp     ah, 4Bh
  5455 00001F3D 74CA                    	je      short loc_back
  5456 00001F3F 80FC53                  	cmp     ah, 53h
  5457 00001F42 74C5                    	je      short loc_back
  5458 00001F44 EBB3                    	jmp     short read_next_char
  5459                                  char_return:
  5460 00001F46 B403                    	mov     ah, 3
  5461 00001F48 CD10                    	int     10h
  5462                                  check_char_type:
  5463 00001F4A 3C20                    	cmp     al, 20h
  5464 00001F4C 7229                    	jb      short loc_escape
  5465 00001F4E 88D4                    	mov     ah, dl
  5466 00001F50 2A26[9455]              	sub     ah, byte [Cursor_Pos]
  5467                                  	;cmp	ah, 10 
  5468                                  	;ja	short loc_beep
  5469 00001F54 3A26[F365]              	cmp     ah, [vname_length] ; 05/01/2018
  5470 00001F58 73D8                    	jnb	short loc_beep
  5471 00001F5A 3C7A                    	cmp     al, 'z'
  5472 00001F5C 779B                    	ja      short read_next_char
  5473 00001F5E 3C61                    	cmp     al, 'a'
  5474 00001F60 7202                    	jb      short pass_capitalize
  5475 00001F62 24DF                    	and     al, 0DFh
  5476                                  pass_capitalize:
  5477 00001F64 88E3                    	mov     bl, ah 
  5478 00001F66 30E4                    	xor     ah, ah
  5479 00001F68 8900                    	mov     [si+bx], ax
  5480 00001F6A B307                    	mov     bl, 7
  5481 00001F6C B40E                    	mov     ah, 0Eh
  5482 00001F6E CD10                    	int     10h
  5483 00001F70 EB87                    	jmp     short read_next_char
  5484                                  pass_escape:
  5485 00001F72 3C0D                    	cmp     al, 0Dh	; 13 ; ENTER
  5486 00001F74 7583                    	jne     short read_next_char
  5487                                  	;mov	ah, 0Eh
  5488                                  	;int	10h
  5489                                  	;mov	al, 0Ah
  5490                                  	;int	10h
  5491 00001F76 C3                      	retn
  5492                                  loc_escape:
  5493 00001F77 3C1B                    	cmp     al, 1Bh	; 27 ; ESC
  5494 00001F79 75F7                    	jne     short pass_escape
  5495 00001F7B F9                      	stc
  5496 00001F7C C3                      	retn
  5497                                  
  5498                                  ;-----------------------------------------------------------------------------
  5499                                  
  5500                                  display_chs_table:
  5501 00001F7D 06                      	push	es
  5502 00001F7E BF00B8                  	mov	di, 0B800h
  5503 00001F81 8EC7                    	mov	es, di
  5504 00001F83 31FF                    	xor	di, di
  5505                                  	; 12/02/2019
  5506                                  	; new file ?
  5507 00001F85 803E[C16E]00            	cmp	byte [existingfile], 0
  5508 00001F8A 7604                    	jna	short dchstbl_1
  5509 00001F8C 81C74001                	add	di, 320 ; skip 2 rows (for the header)
  5510                                  dchstbl_1:
  5511 00001F90 B95000                  	mov	cx, 80
  5512 00001F93 B82007                  	mov	ax, 0720h
  5513 00001F96 F3AB                    	rep	stosw
  5514 00001F98 B150                    	mov	cl, 80 
  5515 00001F9A B02D                    	mov	al, "-"
  5516 00001F9C F3AB                    	rep	stosw
  5517 00001F9E B113                    	mov	cl, 19
  5518 00001FA0 B020                    	mov	al, 20h
  5519 00001FA2 F3AB                    	rep	stosw
  5520 00001FA4 B043                    	mov	al, 'C'
  5521 00001FA6 AB                      	stosw
  5522 00001FA7 B079                    	mov	al, 'y'
  5523 00001FA9 AB                      	stosw
  5524 00001FAA B06C                    	mov	al, 'l'
  5525 00001FAC AB                      	stosw
  5526 00001FAD B069                    	mov	al, 'i'
  5527 00001FAF AB                       	stosw
  5528 00001FB0 B06E                    	mov	al, 'n'
  5529 00001FB2 AB                      	stosw	
  5530 00001FB3 B064                    	mov	al, 'd'
  5531 00001FB5 AB                      	stosw
  5532 00001FB6 B065                    	mov	al, 'e'
  5533 00001FB8 AB                      	stosw
  5534 00001FB9 B072                    	mov	al, 'r'
  5535 00001FBB AB                       	stosw
  5536 00001FBC B073                    	mov	al, 's'
  5537 00001FBE AB                       	stosw
  5538 00001FBF B03A                    	mov	al, ':'
  5539 00001FC1 AB                      	stosw
  5540 00001FC2 B020                    	mov	al, 20h
  5541 00001FC4 AB                      	stosw
  5542                                  	;mov	[cylnumpos], di
  5543 00001FC5 A1[9A40]                	mov	ax, [cylinders]
  5544 00001FC8 B104                    	mov	cl, 4
  5545 00001FCA B543                    	mov	ch, 'C'
  5546 00001FCC E88400                  	call	write_number
  5547                                  	
  5548 00001FCF B82007                  	mov	ax, 0720h
  5549 00001FD2 AB                      	stosw
  5550 00001FD3 AB                      	stosw
  5551 00001FD4 B048                    	mov	al, 'H'
  5552 00001FD6 AB                      	stosw
  5553 00001FD7 B065                    	mov	al, 'e'
  5554 00001FD9 AB                      	stosw
  5555 00001FDA B061                    	mov	al, 'a'
  5556 00001FDC AB                      	stosw
  5557 00001FDD B064                    	mov	al, 'd'
  5558 00001FDF AB                       	stosw
  5559 00001FE0 B073                    	mov	al, 's'
  5560 00001FE2 AB                       	stosw
  5561 00001FE3 B03A                    	mov	al, ':'
  5562 00001FE5 AB                      	stosw
  5563 00001FE6 B020                    	mov	al, 20h
  5564 00001FE8 AB                      	stosw
  5565                                  	;mov	[hednumpos], di
  5566 00001FE9 A1[9840]                	mov	ax, [heads]
  5567 00001FEC B102                    	mov	cl, 2
  5568 00001FEE B548                    	mov	ch, 'H'
  5569 00001FF0 E86000                  	call	write_number
  5570                                  
  5571 00001FF3 B82007                  	mov	ax, 0720h
  5572 00001FF6 AB                      	stosw
  5573 00001FF7 AB                      	stosw
  5574 00001FF8 B053                    	mov	al, 'S'
  5575 00001FFA AB                      	stosw
  5576 00001FFB B065                    	mov	al, 'e'
  5577 00001FFD AB                      	stosw
  5578 00001FFE B063                    	mov	al, 'c'
  5579 00002000 AB                      	stosw
  5580 00002001 B074                    	mov	al, 't'
  5581 00002003 AB                       	stosw
  5582 00002004 B06F                    	mov	al, 'o'
  5583 00002006 AB                      	stosw
  5584 00002007 B072                    	mov	al, 'r'
  5585 00002009 AB                       	stosw
  5586 0000200A B073                    	mov	al, 's'
  5587 0000200C AB                       	stosw
  5588 0000200D B03A                    	mov	al, ':'
  5589 0000200F AB                      	stosw
  5590 00002010 B020                    	mov	al, 20h
  5591 00002012 AB                      	stosw
  5592                                  	;mov	[secnumpos], di
  5593 00002013 A1[9640]                	mov	ax, [sectors]
  5594 00002016 B102                    	mov	cl, 2
  5595 00002018 B553                    	mov	ch, 'S'
  5596 0000201A E83600                  	call	write_number
  5597                                  
  5598 0000201D B116                    	mov	cl, 22
  5599 0000201F B82007                  	mov	ax, 0720h
  5600 00002022 F3AB                    	rep	stosw
  5601                                  	
  5602 00002024 B150                    	mov	cl, 80 
  5603 00002026 B02D                    	mov	al, "-"
  5604 00002028 F3AB                    	rep	stosw
  5605                                  
  5606                                  	;mov	cl, 80
  5607 0000202A B1A0                    	mov	cl, 160 ; 11/02/2019
  5608 0000202C B020                    	mov	al, 20h
  5609 0000202E F3AB                    	rep	stosw
  5610                                  
  5611 00002030 BA0006                  	mov	dx, 0600h ; DH = row, DL = 0 column
  5612 00002033 31DB                    	xor	bx, bx ; BH = video page (0)
  5613 00002035 B402                    	mov	ah, 02h ; set cursor position
  5614 00002037 CD10                    	int	10h
  5615                                  
  5616                                  	; 12/02/2019
  5617                                  	; new file ?
  5618 00002039 380E[C16E]              	cmp	byte [existingfile], cl ; 0
  5619 0000203D 7712                    	ja	short dchstbl_2
  5620                                  
  5621 0000203F 81C7A005                	add	di, 9*160 ; 9 rows (CHS_msg)
  5622                                  
  5623 00002043 BE[C941]                	mov	si, CHS_msg
  5624 00002046 E8ECFD                  	call	print_msg
  5625                                  
  5626 00002049 B92003                  	mov	cx, 10*80
  5627 0000204C B82007                  	mov	ax, 0720h
  5628 0000204F F3AB                    	rep	stosw
  5629                                  dchstbl_2:
  5630 00002051 07                      	pop	es
  5631 00002052 C3                      	retn
  5632                                  
  5633                                  ;-----------------------------------------------------------------------------
  5634                                  
  5635                                  write_number:
  5636 00002053 89CE                    	mov	si, cx
  5637 00002055 31D2                    	xor	dx, dx
  5638 00002057 BB0A00                  	mov	bx, 10
  5639                                  wnum_1:
  5640 0000205A F7F3                    	div	bx
  5641 0000205C 52                      	push	dx
  5642 0000205D 31D2                    	xor	dx, dx
  5643 0000205F FEC9                    	dec	cl
  5644 00002061 75F7                    	jnz	short wnum_1
  5645 00002063 89F1                    	mov	cx, si
  5646 00002065 B407                    	mov	ah, 07h
  5647 00002067 88E8                    	mov	al, ch
  5648 00002069 30ED                    	xor	ch, ch
  5649 0000206B 3806[9F6E]              	cmp	byte [chs_focus], al
  5650 0000206F 7502                    	jne	short wnum_2
  5651 00002071 B40F                    	mov	ah, 0Fh
  5652                                  wnum_2:
  5653 00002073 5A                      	pop	dx
  5654 00002074 88D0                    	mov	al, dl
  5655 00002076 0430                    	add	al, '0'
  5656 00002078 AB                      	stosw
  5657 00002079 E2F8                    	loop	wnum_2
  5658 0000207B C3                      	retn
  5659                                  
  5660                                  ;-----------------------------------------------------------------------------
  5661                                  
  5662                                  partition_size_input:
  5663 0000207C C706[A66E]0000          	mov	word [pSize_multiplier+2], 0
  5664 00002082 C606[AB6E]42            	mov	byte [msg_psize_unit+1], 'B'
  5665 00002087 A0[AA6E]                	mov	al, [pSize_unit]
  5666 0000208A 3C25                    	cmp	al, '%'
  5667 0000208C 751F                    	jne	short psu_0
  5668                                  	; 08/02/2019
  5669                                  	; calculate sector count for max. available sectors percentage
  5670 0000208E 8B16[9A6E]              	mov	dx, [pp_Sectors+2] ; max. available sectors
  5671 00002092 A1[986E]                	mov	ax, [pp_Sectors]   ; for a new partition
  5672                                  	;mov	dx, [total_sectors+2]
  5673                                  	;mov	ax, [total_sectors]	
  5674 00002095 B96400                  	mov	cx, 100
  5675 00002098 E89BED                  	call	div32
  5676 0000209B A3[A46E]                	mov	[pSize_multiplier], ax
  5677 0000209E B400                    	mov	ah, 0
  5678 000020A0 8826[AB6E]              	mov	[msg_psize_unit+1], ah
  5679 000020A4 C606[A86E]02            	mov	byte [pSize_maxdigits], 2
  5680 000020A9 B025                    	mov	al, '%'
  5681 000020AB EB60                    	jmp	short psu_6
  5682                                  psu_0:
  5683 000020AD 3C43                    	cmp	al, 'C'
  5684 000020AF 7517                    	jne	short psu_1
  5685 000020B1 A1[9640]                	mov	ax, [sectors]
  5686 000020B4 F726[9840]              	mul	word [heads]
  5687 000020B8 A3[A46E]                	mov	[pSize_multiplier], ax	
  5688 000020BB C606[A86E]04            	mov	byte [pSize_maxdigits], 4
  5689                                  	;sub	dh, dh
  5690 000020C0 8836[AB6E]              	mov	[msg_psize_unit+1], dh
  5691 000020C4 B043                    	mov	al, 'C'
  5692 000020C6 EB45                    	jmp	short psu_6	
  5693                                  psu_1:
  5694 000020C8 3C47                    	cmp	al, 'G'
  5695 000020CA 7513                    	jne	short psu_2
  5696 000020CC C706[A46E]0008          	mov	word [pSize_multiplier], 2*1024
  5697 000020D2 C706[A66E]0004          	mov	word [pSize_multiplier+2], 1024
  5698 000020D8 C606[A86E]01            	mov	byte [pSize_maxdigits], 1
  5699 000020DD EB2E                    	jmp	short psu_6
  5700                                  psu_2:
  5701 000020DF 3C4D                    	cmp	al, 'M'
  5702 000020E1 750D                    	jne	short psu_3
  5703 000020E3 C706[A46E]0008          	mov	word [pSize_multiplier], 2*1024
  5704 000020E9 C606[A86E]04            	mov	byte [pSize_maxdigits], 4
  5705 000020EE EB1D                    	jmp	short psu_6
  5706                                  psu_3:
  5707 000020F0 3C4B                    	cmp	al, 'K'
  5708 000020F2 7508                    	jne	short psu_4
  5709 000020F4 C706[A46E]0200          	mov	word [pSize_multiplier], 2
  5710 000020FA EB0C                    	jmp	short psu_5	
  5711                                  psu_4:
  5712                                  	; al = 'S'
  5713 000020FC 30E4                    	xor	ah, ah
  5714 000020FE 8826[AB6E]              	mov	[msg_psize_unit+1], ah
  5715 00002102 C706[A46E]0100          	mov	word [pSize_multiplier], 1
  5716                                  psu_5:
  5717 00002108 C606[A86E]07            	mov	byte [pSize_maxdigits], 7
  5718                                  psu_6:
  5719 0000210D A2[8C4F]                	mov	[msg_partition_size_x], al
  5720 00002110 BE[784F]                	mov	si, msg_partition_size	
  5721 00002113 E81FFD                  	call	print_msg
  5722                                  
  5723 00002116 89E5                    	mov	bp, sp
  5724 00002118 31DB                    	xor	bx, bx
  5725 0000211A 891E[A06E]              	mov	[pSize_temp], bx ; 0
  5726                                  	;mov	[pSize_temp+2], bx ; 0
  5727 0000211E 881E[A96E]              	mov	[pSize_digitpos], bl ; 0
  5728                                  	; bh = 0  ; video page
  5729 00002122 B403                    	mov     ah, 3 ; get cursor pos
  5730 00002124 CD10                    	int     10h
  5731 00002126 8916[9455]              	mov	[Cursor_Pos], dx
  5732                                  	; 09/02/2019
  5733 0000212A B307                    	mov     bl, 7   ; page 0, color 7 (light gray)   
  5734                                  psu_7:
  5735 0000212C 30E4                    	xor	ah, ah
  5736 0000212E CD16                    	int	16h
  5737                                  
  5738 00002130 3C30                    	cmp	al, '0'
  5739 00002132 721F                    	jb	short psu_8
  5740 00002134 3C39                    	cmp	al, '9'
  5741 00002136 77F4                    	ja	short psu_7
  5742 00002138 8A1E[A96E]              	mov	bl, [pSize_digitpos]
  5743 0000213C 3A1E[A86E]              	cmp	bl, [pSize_maxdigits]
  5744 00002140 73EA                    	jnb	short psu_7
  5745 00002142 FE06[A96E]              	inc	byte [pSize_digitpos]
  5746 00002146 2C30                    	sub	al, '0'
  5747 00002148 30E4                    	xor	ah, ah
  5748 0000214A 50                      	push	ax
  5749 0000214B 0430                    	add	al, '0'
  5750 0000214D B40E                    	mov	ah, 0Eh	; write char as tty		
  5751                                  	;mov	bx, 7   ; page 0, color 7 (light gray)         
  5752 0000214F CD10                    	int	10h
  5753 00002151 EBD9                    	jmp	short psu_7	
  5754                                  psu_8:
  5755 00002153 20C0                    	and	al, al
  5756 00002155 0F849500                	jz	psu_15 ; check for left arrow key 
  5757 00002159 3C1B                    	cmp	al, 27
  5758 0000215B 0F849C00                	je	psu_16esc ; ESCAPE key
  5759 0000215F 0F878500                	ja	psu_14 ; check for left arrow key
  5760 00002163 3C0D                    	cmp	al, 13
  5761                                  	;je	short psu_9  ; ENTER key
  5762 00002165 7249                    	jb	short psu_11 ; check for backspace key
  5763                                  	;jmp	short psu_7
  5764 00002167 77C3                    	ja	short psu_7
  5765                                  psu_9:
  5766 00002169 31C0                    	xor	ax, ax
  5767 0000216B A3[A26E]                	mov	[pSize_temp+2], ax ; 0 ; 08/02/2019
  5768 0000216E 3806[A96E]              	cmp	byte [pSize_digitpos], al ; 0
  5769 00002172 0F868F00                	jna	psu_16		
  5770                                  	;xor	bh, bh
  5771 00002176 8A1E[A96E]              	mov	bl, [pSize_digitpos]
  5772 0000217A FECB                    	dec	bl
  5773 0000217C D0E3                    	shl	bl, 1
  5774 0000217E 01E3                    	add	bx, sp
  5775 00002180 8B07                    	mov	ax, [bx]
  5776 00002182 A3[A06E]                	mov	[pSize_temp], ax
  5777                                  	;mov	word [pSize_temp+2], 0
  5778 00002185 B90A00                  	mov	cx, 10
  5779                                  psu_10:
  5780 00002188 FE0E[A96E]              	dec	byte [pSize_digitpos]
  5781 0000218C 7477                    	jz	short psu_16
  5782                                  	
  5783 0000218E A1[A06E]                	mov	ax, [pSize_temp]
  5784 00002191 8B16[A26E]              	mov	dx, [pSize_temp+2]
  5785                                  	;mov	cx, 10
  5786 00002195 E8ACEC                  	call	mul32
  5787                                  	;mov	[pSize_temp], ax
  5788                                  	;mov	[pSize_temp+2], dx
  5789                                  	;xor	bh, bh
  5790 00002198 8A1E[A96E]              	mov	bl, [pSize_digitpos]
  5791 0000219C FECB                    	dec	bl
  5792 0000219E D0E3                    	shl	bl, 1
  5793 000021A0 01E3                    	add	bx, sp ; (*)
  5794                                  	;mov	ax, [bx]
  5795                                  	;add	[pSize_temp], ax
  5796                                  	;adc	word [pSize_temp+2], 0
  5797 000021A2 0307                    	add	ax, [bx]
  5798 000021A4 83D200                  	adc	dx, 0
  5799 000021A7 A3[A06E]                	mov	[pSize_temp], ax
  5800 000021AA 8916[A26E]              	mov	[pSize_temp+2], dx
  5801 000021AE EBD8                    	jmp	short psu_10
  5802                                  	
  5803                                  	; Left arrow, backspace, DEL key checking
  5804                                  psu_11:
  5805 000021B0 3C08                    	cmp	al, 8 ; backspace key
  5806 000021B2 0F8576FF                	jne	psu_7
  5807                                  psu_12:
  5808                                  	;; bh = 0  ; video page
  5809                                  	;mov	ah, 3 ; get cursor pos
  5810                                  	;int	10h
  5811                                  	;cmp	dl, [Cursor_Pos]
  5812                                  	;jna	short psu_13
  5813                                  	;dec	dl
  5814                                  	;dec	byte [pSize_digitpos]
  5815                                  
  5816                                  	; 08/02/2019
  5817 000021B6 8B16[9455]              	mov	dx, [Cursor_Pos]
  5818 000021BA 8A1E[A96E]              	mov	bl, [pSize_digitpos]
  5819 000021BE 20DB                    	and	bl, bl
  5820 000021C0 741D                    	jz	short psu_13	
  5821                                  
  5822 000021C2 FECB                    	dec	bl 
  5823 000021C4 881E[A96E]              	mov	[pSize_digitpos], bl
  5824                                  	
  5825 000021C8 00DA                    	add	dl, bl
  5826                                  
  5827                                  	; bh = 0  ; video page
  5828 000021CA B402                    	mov	ah, 2 ; set cursor pos
  5829 000021CC CD10                    	int	10h
  5830                                  	;mov	bl, dl
  5831                                  	;sub	bl, [Cursor_Pos] 
  5832 000021CE B90100                  	mov	cx, 1
  5833 000021D1 B409                    	mov	ah, 9 ; write char at current curs pos
  5834 000021D3 B020                    	mov	al, 20h ; space (blank)
  5835 000021D5 8800                    	mov	[si+bx], al
  5836                                  	; bh = 0 ; video page
  5837 000021D7 B307                    	mov	bl, 7 ; attribute/color (light gray)
  5838 000021D9 CD10                    	int	10h
  5839                                  
  5840                                  	; 09/02/2019
  5841 000021DB 58                      	pop	ax ; remove last digit on top of stack 
  5842                                  		   ; set sp to correct position for BX (*)	
  5843 000021DC E94DFF                  	jmp	psu_7
  5844                                  psu_13:
  5845 000021DF B40E                    	mov	ah, 0Eh
  5846 000021E1 B007                    	mov	al, 7
  5847                                  	;mov	bx, 7
  5848 000021E3 CD10                    	int	10h
  5849 000021E5 E944FF                  	jmp	psu_7
  5850                                  psu_14:
  5851 000021E8 3CE0                    	cmp	al, 0E0h          
  5852 000021EA 0F853EFF                	jne	psu_7
  5853                                  psu_15:    
  5854 000021EE 80FC4B                  	cmp	ah, 4Bh ; left arrow
  5855 000021F1 74C3                    	je	short psu_12
  5856 000021F3 80FC53                  	cmp	ah, 53h ; DEL key (backspace)
  5857 000021F6 74BE                    	je	short psu_12
  5858 000021F8 E931FF                  	jmp	psu_7
  5859                                  
  5860                                  psu_16esc:
  5861 000021FB 31C9                    	xor	cx, cx ; 0
  5862 000021FD 890E[A06E]              	mov	[pSize_temp], cx
  5863 00002201 890E[A26E]              	mov	[pSize_temp+2], cx
  5864                                  psu_16:
  5865 00002205 89EC                    	mov	sp, bp
  5866                                  
  5867 00002207 803E[AA6E]53            	cmp	byte [pSize_unit], 'S'
  5868 0000220C 7508                    	jne	short psu_17 
  5869                                  
  5870 0000220E BE[E865]                	mov	si, msg_sectors_crlf
  5871 00002211 E821FC                  	call	print_msg
  5872                                  	;xor	bx, bx
  5873 00002214 EB0C                    	jmp	short psu_18
  5874                                  psu_17:
  5875 00002216 BE[AA6E]                	mov	si, msg_psize_unit
  5876 00002219 E819FC                  	call	print_msg
  5877                                  
  5878 0000221C BE[5056]                	mov	si, CRLF
  5879 0000221F E813FC                  	call	print_msg
  5880                                  psu_18:
  5881 00002222 A1[A06E]                	mov	ax, [pSize_temp]
  5882 00002225 8B16[A26E]              	mov	dx, [pSize_temp+2]
  5883 00002229 89C1                    	mov	cx, ax
  5884 0000222B 09D1                    	or	cx, dx
  5885                                  	;jz	short psu_20
  5886 0000222D 7422                    	jz	short psu_21 ; 08/02/2019
  5887 0000222F 8B0E[A46E]              	mov	cx, [pSize_multiplier]
  5888 00002233 803E[AA6E]43            	cmp	byte [pSize_unit], 'C'
  5889 00002238 7413                    	je	short psu_20 ; 09/02/2019
  5890                                  	;jne	short psu_19
  5891                                  	;call	mul32
  5892                                  	; 08/02/2019
  5893                                  	; dx:ax = requested partition size in sectors
  5894                                  	;retn	
  5895                                  ;psu_19:
  5896                                  	;mov	cx, [pSize_multiplier]
  5897 0000223A 83F901                  	cmp	cx, 1
  5898                                  	;jna	short psu_20
  5899 0000223D 7703                    	ja	short psu_19
  5900                                  	; 09/02/2019
  5901 0000223F 31DB                    	xor	bx, bx
  5902 00002241 C3                      	retn
  5903                                  psu_19:
  5904 00002242 E8FFEB                  	call	mul32
  5905                                  	;and	bx, bx
  5906                                  	;jnz	short psu_22 ; 09/02/2019	
  5907 00002245 8B0E[A66E]              	mov	cx, [pSize_multiplier+2]
  5908 00002249 09C9                    	or	cx, cx
  5909                                  	;jz	short psu_20
  5910 0000224B 7405                    	jz	short psu_22 ; 09/02/2019
  5911                                  psu_20:
  5912 0000224D E8F4EB                  	call	mul32
  5913 00002250 C3                      	retn
  5914                                  psu_21:
  5915 00002251 F9                      	stc
  5916                                  psu_22:
  5917 00002252 C3                      	retn
  5918                                  
  5919                                  ;-----------------------------------------------------------------------------
  5920                                  
  5921                                  partition_type_input:
  5922 00002253 BE[924F]                	mov	si, msg_partition_type	
  5923 00002256 E8DCFB                  	call	print_msg
  5924                                  
  5925 00002259 31DB                    	xor	bx, bx
  5926                                  
  5927 0000225B 881E[BA6E]              	mov	[pType_pos], bl ; 0
  5928 0000225F 891E[BB6E]              	mov	[pType_num], bx ; 0
  5929                                  
  5930                                  	; bh = 0  ; video page
  5931 00002263 B403                    	mov     ah, 3 ; get cursor pos
  5932 00002265 CD10                    	int     10h
  5933 00002267 8916[9455]              	mov	[Cursor_Pos], dx
  5934                                  ptu_0:
  5935 0000226B 30E4                    	xor	ah, ah
  5936 0000226D CD16                    	int	16h
  5937                                  
  5938 0000226F 803E[BA6E]01            	cmp	byte [pType_pos], 1
  5939 00002274 773F                    	ja	short ptu_5	
  5940                                  
  5941 00002276 3C30                    	cmp	al, '0'
  5942 00002278 723B                    	jb	short ptu_5
  5943 0000227A 3C39                    	cmp	al, '9'
  5944 0000227C 7707                    	ja	short ptu_1
  5945 0000227E 88C4                    	mov	ah, al
  5946 00002280 80EC30                  	sub	ah, '0'
  5947 00002283 EB13                    	jmp	short ptu_2 
  5948                                  ptu_1:
  5949 00002285 3CE0                    	cmp     al, 0E0h          
  5950 00002287 7473                    	je	short ptu_9
  5951                                  
  5952 00002289 24DF                    	and	al, 0DFh
  5953 0000228B 3C41                    	cmp	al, 'A'
  5954 0000228D 72DC                    	jb	short ptu_0
  5955 0000228F 3C46                    	cmp	al, 'F'
  5956 00002291 77D8                    	ja	short ptu_0
  5957 00002293 88C4                    	mov	ah, al
  5958 00002295 80EC37                  	sub	ah, 'A'-10
  5959                                  ptu_2:
  5960 00002298 803E[BA6E]00            	cmp	byte [pType_pos], 0
  5961 0000229D 7606                    	jna	short ptu_3
  5962 0000229F 8826[BC6E]              	mov	[pType_num+1], ah
  5963 000022A3 EB04                    	jmp	short ptu_4 
  5964                                  ptu_3:
  5965 000022A5 8826[BB6E]              	mov	[pType_num], ah
  5966                                  ptu_4:
  5967 000022A9 B40E                    	mov	ah, 0Eh
  5968 000022AB B307                    	mov	bl, 7
  5969 000022AD CD10                    	int	10h
  5970                                  
  5971 000022AF FE06[BA6E]              	inc	byte [pType_pos]
  5972                                  
  5973 000022B3 EBB6                    	jmp	short ptu_0 
  5974                                  ptu_5:
  5975 000022B5 20C0                    	and	al, al
  5976 000022B7 7443                    	jz	short ptu_9 ; check for left arrow key 
  5977 000022B9 3C1B                    	cmp	al, 27
  5978 000022BB 744C                    	je	short ptu_10 ; ESCAPE key
  5979 000022BD 77AC                    	ja	short ptu_0
  5980 000022BF 3C0D                    	cmp	al, 13
  5981 000022C1 744A                    	je	short ptu_11  ; ENTER key
  5982 000022C3 77A6                    	ja	short ptu_0
  5983                                  ptu_6:
  5984                                  	; Left arrow, backspace, DEL key checking
  5985                                  
  5986 000022C5 3C08                    	cmp	al, 8 ; backspace key
  5987 000022C7 75A2                    	jne	short ptu_0
  5988                                  ptu_7:
  5989                                  	; bh = 0  ; video page
  5990 000022C9 B403                    	mov	ah, 3 ; get cursor pos
  5991 000022CB CD10                    	int	10h
  5992 000022CD 3A16[9455]              	cmp	dl, [Cursor_Pos]
  5993 000022D1 7620                    	jna	short ptu_8
  5994 000022D3 FECA                    	dec	dl
  5995 000022D5 FE0E[BA6E]              	dec	byte [pType_pos]
  5996                                  	; bh = 0  ; video page
  5997 000022D9 B402                    	mov	ah, 2 ; set cursor pos
  5998 000022DB CD10                    	int	10h
  5999 000022DD 88D3                    	mov	bl, dl
  6000 000022DF 2A1E[9455]              	sub	bl, [Cursor_Pos] 
  6001 000022E3 B90100                  	mov	cx, 1
  6002 000022E6 B409                    	mov	ah, 9 ; write char at current curs pos
  6003 000022E8 B020                    	mov	al, 20h ; space (blank)
  6004 000022EA 8800                    	mov	[si+bx], al
  6005                                  	; bh = 0 ; video page
  6006 000022EC B307                    	mov	bl, 7 ; attribute/color (light gray)
  6007 000022EE CD10                    	int	10h
  6008 000022F0 E978FF                  	jmp	ptu_0
  6009                                  ptu_8:
  6010 000022F3 B40E                    	mov	ah, 0Eh
  6011 000022F5 B007                    	mov	al, 7
  6012 000022F7 CD10                    	int	10h
  6013 000022F9 E96FFF                  	jmp	ptu_0
  6014                                  ptu_9:    
  6015 000022FC 80FC4B                  	cmp	ah, 4Bh ; left arrow
  6016 000022FF 74C8                    	je	short ptu_7
  6017 00002301 80FC53                  	cmp	ah, 53h ; DEL key (backspace)
  6018 00002304 74C3                    	je	short ptu_7
  6019 00002306 E962FF                  	jmp	ptu_0
  6020                                  
  6021                                  ptu_10: ; ESCAPE
  6022 00002309 B000                    	mov	al, 0
  6023                                  	; partition type is 0 (none)
  6024 0000230B EB12                    	jmp	short ptu_12
  6025                                  ptu_11: ; ENTER
  6026 0000230D A0[BB6E]                	mov	al, [pType_num]
  6027 00002310 803E[BA6E]01            	cmp	byte [pType_pos], 1
  6028 00002315 7608                    	jna	short ptu_12
  6029 00002317 B410                    	mov	ah, 16
  6030 00002319 F6E4                    	mul	ah
  6031 0000231B 0206[BC6E]              	add	al, [pType_num+1]
  6032                                  ptu_12:
  6033 0000231F 50                      	push	ax
  6034 00002320 E8B1FB                  	call	bin_to_hex
  6035 00002323 A3[A84F]                	mov	[msg_ptype_num], ax
  6036                                  	; bh = 0  ; video page
  6037 00002326 B402                    	mov	ah, 2 ; set cursor pos
  6038 00002328 8B16[9455]              	mov	dx, [Cursor_Pos]
  6039 0000232C CD10                    	int	10h
  6040 0000232E BE[A84F]                	mov	si, msg_ptype_num 
  6041 00002331 E801FB                  	call	print_msg
  6042 00002334 58                      	pop	ax
  6043 00002335 C3                      	retn
  6044                                  
  6045                                  ;-----------------------------------------------------------------------------
  6046                                  
  6047                                  show_selected_partition:
  6048                                  	; INPUT ->
  6049                                  	; 	DS:SI = Partition table row address
  6050                                  		
  6051                                  	pt_s_offset	equ 7
  6052                                  	pt_bh_offset	equ 11
  6053                                  	pt_bs_offset	equ 15
  6054                                  	pt_bc_offset	equ 19
  6055                                  	pt_fs_offset	equ 23
  6056                                  	pt_eh_offset	equ 27
  6057                                  	pt_es_offset	equ 31
  6058                                  	pt_ec_offset	equ 35
  6059                                  	pt_rs_offset	equ 41
  6060                                  	pt_ts_offset	equ 52
  6061                                  	pt_fsn_offset	equ 63
  6062                                  
  6063                                  	; clear screen
  6064 00002336 B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
  6065 00002339 CD10                    	int	10h	
  6066                                  
  6067 0000233B 89F0                    	mov	ax, si
  6068 0000233D 2D[E658]                	sub	ax, MasterBootBuff + pTableOffset ; + 446
  6069 00002340 C0E804                  	shr	al, 4 ; from offset to partition number
  6070 00002343 0431                    	add	al, '1'  ; 1 based partition number (chr)
  6071                                  	; Write partition number to the header location
  6072 00002345 A2[6851]                	mov	[msg_selected_partition+43], al ; '1' to '4'
  6073                                  	
  6074                                  	; Partition number will be used at formatting stage
  6075 00002348 A2[3754]                	mov	[partition_num_chr], al ; number + '0'
  6076                                  
  6077 0000234B B268                    	mov	dl, 'h'
  6078 0000234D 8A04                    	mov	al, [si+ptBootable]
  6079 0000234F E882FB                  	call	bin_to_hex
  6080 00002352 A3[8452]                	mov	[pt_row+pt_s_offset], ax
  6081 00002355 8816[8652]              	mov	[pt_row+pt_s_offset+2], dl ; 'h'	
  6082 00002359 8A4401                  	mov	al, [si+ptBeginHead]
  6083 0000235C E875FB                  	call	bin_to_hex
  6084 0000235F A3[8852]                	mov	[pt_row+pt_bh_offset], ax
  6085 00002362 8816[8A52]              	mov	[pt_row+pt_bh_offset+2], dl ; 'h'
  6086 00002366 8A4402                  	mov	al, [si+ptBeginSector]
  6087 00002369 E868FB                  	call	bin_to_hex
  6088 0000236C A3[8C52]                	mov	[pt_row+pt_bs_offset], ax
  6089 0000236F 8816[8E52]              	mov	[pt_row+pt_bs_offset+2], dl ; 'h'
  6090 00002373 8A4403                  	mov	al, [si+ptBeginCylinder]
  6091 00002376 E85BFB                  	call	bin_to_hex
  6092 00002379 A3[9052]                	mov	[pt_row+pt_bc_offset], ax
  6093 0000237C 8816[9252]              	mov	[pt_row+pt_bc_offset+2], dl ; 'h'
  6094 00002380 8A4404                  	mov	al, [si+ptFileSystemID]
  6095                                   	; Partition type will be used at formatting stage
  6096 00002383 A2[9E6E]                	mov	[pp_type_user], al
  6097 00002386 E84BFB                  	call	bin_to_hex
  6098 00002389 A3[9452]                	mov	[pt_row+pt_fs_offset], ax
  6099 0000238C 8816[9652]              	mov	[pt_row+pt_fs_offset+2], dl ; 'h'
  6100 00002390 8A4405                  	mov	al, [si+ptEndHead]
  6101 00002393 E83EFB                  	call	bin_to_hex
  6102 00002396 A3[9852]                	mov	[pt_row+pt_eh_offset], ax
  6103 00002399 8816[9A52]              	mov	[pt_row+pt_eh_offset+2], dl ; 'h'
  6104 0000239D 8A4406                  	mov	al, [si+ptEndSector]
  6105 000023A0 E831FB                  	call	bin_to_hex
  6106 000023A3 A3[9C52]                	mov	[pt_row+pt_es_offset], ax
  6107 000023A6 8816[9E52]              	mov	[pt_row+pt_es_offset+2], dl ; 'h'
  6108 000023AA 8A4407                  	mov	al, [si+ptEndCylinder]
  6109 000023AD E824FB                  	call	bin_to_hex
  6110 000023B0 A3[A052]                	mov	[pt_row+pt_ec_offset], ax
  6111 000023B3 8816[A252]              	mov	[pt_row+pt_ec_offset+2], dl ; 'h'
  6112 000023B7 8A4408                  	mov	al, [si+ptStartSector]
  6113 000023BA E817FB                  	call	bin_to_hex
  6114 000023BD A3[AC52]                	mov	[pt_row+pt_rs_offset+6], ax
  6115 000023C0 8816[AE52]              	mov	[pt_row+pt_rs_offset+8], dl ; 'h'
  6116 000023C4 8A4409                  	mov	al, [si+ptStartSector+1]
  6117 000023C7 E80AFB                  	call	bin_to_hex
  6118 000023CA A3[AA52]                	mov	[pt_row+pt_rs_offset+4], ax
  6119 000023CD 8A440A                  	mov	al, [si+ptStartSector+2]
  6120 000023D0 E801FB                  	call	bin_to_hex
  6121 000023D3 A3[A852]                	mov	[pt_row+pt_rs_offset+2], ax
  6122 000023D6 8A440B                  	mov	al, [si+ptStartSector+3]
  6123 000023D9 E8F8FA                  	call	bin_to_hex
  6124 000023DC A3[A652]                	mov	[pt_row+pt_rs_offset], ax
  6125 000023DF 8A440C                  	mov	al, [si+ptSectors]
  6126 000023E2 E8EFFA                  	call	bin_to_hex
  6127 000023E5 A3[B752]                	mov	[pt_row+pt_ts_offset+6], ax
  6128 000023E8 8816[B952]              	mov	[pt_row+pt_ts_offset+8], dl ; 'h'
  6129 000023EC 8A440D                  	mov	al, [si+ptSectors+1]
  6130 000023EF E8E2FA                  	call	bin_to_hex
  6131 000023F2 A3[B552]                	mov	[pt_row+pt_ts_offset+4], ax
  6132 000023F5 8A440E                  	mov	al, [si+ptSectors+2]
  6133 000023F8 E8D9FA                  	call	bin_to_hex
  6134 000023FB A3[B352]                	mov	[pt_row+pt_ts_offset+2], ax
  6135 000023FE 8A440F                  	mov	al, [si+ptSectors+3]
  6136 00002401 E8D0FA                  	call	bin_to_hex
  6137 00002404 A3[B152]                	mov	[pt_row+pt_ts_offset], ax
  6138                                  
  6139 00002407 8A4404                  	mov	al, [si+ptFileSystemID]
  6140 0000240A BF[B641]                	mov	di, valid_partitions
  6141 0000240D B91300                  	mov	cx, 19
  6142 00002410 F2AE                    	repnz	scasb
  6143 00002412 7405                    	jz	short ssp_1
  6144 00002414 B8[A841]                	mov	ax, FS_OTHERS	 
  6145 00002417 EB0C                    	jmp	short ssp_2
  6146                                  ssp_1:
  6147 00002419 81EF[B741]              	sub	di, valid_partitions + 1
  6148 0000241D B80E00                  	mov	ax, 14
  6149 00002420 F7E7                    	mul	di
  6150 00002422 05[9E40]                	add	ax, FileSys_Names
  6151                                  ssp_2:
  6152 00002425 96                      	xchg	ax, si 
  6153 00002426 B107                    	mov	cl, 7
  6154 00002428 BF[BC52]                	mov	di, pt_row + pt_fsn_offset
  6155 0000242B F3A5                    	rep	movsw
  6156 0000242D 89C7                    	mov	di, ax ; partition table row address
  6157                                  
  6158 0000242F BE[3D51]                	mov	si, msg_selected_partition
  6159 00002432 E800FA                  	call	print_msg
  6160                                  
  6161 00002435 BE[1E53]                	mov	si, msg_boot_indicator
  6162 00002438 E8FAF9                  	call	print_msg
  6163 0000243B BE[F35D]                	mov	si, msg_YES
  6164 0000243E F60580                  	test	byte [di+ptBootable], 80h
  6165 00002441 7503                    	jnz	short ssp_3
  6166 00002443 BE[F95D]                	mov	si, msg_NO
  6167                                  ssp_3:
  6168 00002446 E8ECF9                  	call	print_msg
  6169                                  
  6170 00002449 BE[3653]                	mov	si, msg_starting_head
  6171 0000244C E8E6F9                  	call	print_msg
  6172 0000244F 8A4501                  	mov	al, [di+ptBeginHead]
  6173 00002452 E8B200                  	call	write_byte_decimal
  6174 00002455 E8DDF9                  	call	print_msg
  6175 00002458 BE[4E53]                	mov	si, msg_starting_sector
  6176 0000245B E8D7F9                  	call	print_msg
  6177 0000245E 8A4502                  	mov	al, [di+ptBeginSector]
  6178 00002461 88C2                    	mov	dl, al  ; bits 7&8 are bits 8&9 of cyl
  6179 00002463 243F                    	and	al, 3Fh ; sector number, 1 to 63
  6180 00002465 E89F00                  	call	write_byte_decimal			
  6181 00002468 E8CAF9                  	call	print_msg	
  6182 0000246B BE[6653]                	mov	si, msg_starting_cylinder
  6183 0000246E E8C4F9                  	call	print_msg
  6184 00002471 8A4503                  	mov	al, [di+ptBeginCylinder] ; bits 0to7 of cyl
  6185 00002474 C0EA06                  	shr	dl, 6 ; bits 8&9 of cyl
  6186 00002477 88D4                    	mov	ah, dl
  6187 00002479 31D2                    	xor	dx, dx
  6188 0000247B BE[B76E]                	mov	si, msg_partition_sectors + 7 ; max. 7 digits
  6189                                  	; dx_ax: binary number
  6190 0000247E E83CFA                  	call	bin_to_decimal
  6191                                  	; ds:si = decimal number text address		
  6192 00002481 E8B1F9                  	call	print_msg
  6193 00002484 BE[7E53]                	mov	si, msg_system_id
  6194 00002487 E8ABF9                  	call	print_msg
  6195                                  	; Write file system name (again, copy)
  6196 0000248A BE[BC52]                	mov	si, pt_row + pt_fsn_offset
  6197                                  	;mov	cx, 14
  6198 0000248D B10E                    	mov	cl, 14
  6199 0000248F B40E                    	mov	ah, 0Eh ; write tty
  6200 00002491 BB0700                  	mov	bx, 7
  6201                                  ssp_4:	 
  6202 00002494 AC                      	lodsb
  6203 00002495 CD10                    	int	10h
  6204 00002497 E2FB                    	loop	ssp_4
  6205                                  
  6206 00002499 BE[9653]                	mov	si, msg_ending_head
  6207 0000249C E896F9                  	call	print_msg
  6208 0000249F 8A4505                  	mov	al, [di+ptEndHead]
  6209 000024A2 E86200                  	call	write_byte_decimal
  6210 000024A5 E88DF9                  	call	print_msg
  6211 000024A8 BE[AE53]                	mov	si, msg_ending_sector
  6212 000024AB E887F9                  	call	print_msg
  6213 000024AE 8A4506                  	mov	al, [di+ptEndSector]
  6214 000024B1 88C2                    	mov	dl, al  ; bits 7&8 are bits 8&9 of cyl
  6215 000024B3 243F                    	and	al, 3Fh ; sector number, 1 to 63
  6216 000024B5 E84F00                  	call	write_byte_decimal			
  6217 000024B8 E87AF9                  	call	print_msg	
  6218 000024BB BE[C653]                	mov	si, msg_ending_cylinder
  6219 000024BE E874F9                  	call	print_msg
  6220 000024C1 8A4507                  	mov	al, [di+ptEndCylinder] ; bits 0to7 of cyl
  6221 000024C4 C0EA06                  	shr	dl, 6 ; bits 8&9 of cyl
  6222 000024C7 88D4                    	mov	ah, dl
  6223 000024C9 31D2                    	xor	dx, dx
  6224 000024CB BE[B76E]                	mov	si, msg_partition_sectors + 7 ; max. 7 digits
  6225                                  	; dx_ax: binary number
  6226 000024CE E8ECF9                  	call	bin_to_decimal
  6227                                  	; ds:si = decimal number text address		
  6228 000024D1 E861F9                  	call	print_msg
  6229                                  
  6230 000024D4 BE[DE53]                	mov	si, msg_relative_sectors
  6231 000024D7 E85BF9                  	call	print_msg
  6232 000024DA 8B4508                  	mov	ax, [di+ptStartSector]
  6233 000024DD 8B550A                  	mov	dx, [di+ptStartSector+2]
  6234                                  	;mov	si, msg_partition_sectors + 7 ; max. 11 digits
  6235 000024E0 BE[B76E]                	mov	si, reserved_bytes + 10 ; max. 11 digits
  6236 000024E3 E8D7F9                  	call	bin_to_decimal
  6237 000024E6 E84CF9                  	call	print_msg
  6238                                  
  6239 000024E9 BE[F853]                	mov	si, msg_total_sectors
  6240 000024EC E846F9                  	call	print_msg
  6241 000024EF 8B450C                  	mov	ax, [di+ptSectors]
  6242 000024F2 8B550E                  	mov	dx, [di+ptSectors+2]
  6243                                  	;mov	si, msg_partition_sectors + 7 ; max. 11 digits
  6244 000024F5 BE[B76E]                	mov	si, reserved_bytes + 10 ; max. 11 digits
  6245 000024F8 E8C2F9                  	call	bin_to_decimal	
  6246 000024FB E837F9                  	call	print_msg
  6247                                  
  6248                                  	; 24/02/2019
  6249 000024FE BE[5056]                	mov	si, CRLF
  6250 00002501 E831F9                  	call	print_msg
  6251                                  
  6252 00002504 89FE                    	mov	si, di  ; partition table row address
  6253                                  
  6254 00002506 C3                      	retn
  6255                                  
  6256                                  ;-----------------------------------------------------------------------------
  6257                                  
  6258                                  write_byte_decimal:
  6259                                  	; INPUT ->
  6260                                  	;	AL = binary number
  6261                                  	; OUTPUT ->
  6262                                  	;	DS:SI = decimal number text address
  6263                                  	;	        (ASCIIZ string)
  6264                                  	;
  6265                                  	; (SI, AX, CX will me modified)	
  6266                                  
  6267 00002507 BE[B86E]                	mov	si, msg_partition_sectors + 8
  6268 0000250A B10A                    	mov	cl, 10
  6269                                  wbd_loop:
  6270 0000250C 4E                      	dec	si
  6271 0000250D 30E4                    	xor	ah, ah
  6272 0000250F F6F1                    	div	cl
  6273 00002511 80C430                  	add	ah, '0'
  6274 00002514 8824                    	mov	[si], ah
  6275 00002516 20C0                    	and	al, al
  6276 00002518 75F2                    	jnz	short wbd_loop
  6277 0000251A C3                      	retn
  6278                                  
  6279                                  ;-----------------------------------------------------------------------------
  6280                                  ; 03/02/2019
  6281                                  ; 16/10/2020
  6282                                  
  6283                                  init_partition_tables:
  6284                                  
  6285                                  	; INPUT -> none
  6286                                  	; OUTPUT -> none
  6287                                  	 
  6288                                  	; 12/02/2019	
  6289                                  	;cmp	word [MBIDCode], 0AA55h
  6290                                  	;jne	ipt_stc ; invalid
  6291                                  
  6292                                  	; 15/02/2019
  6293                                  	; clear primary partition tables structure/list
  6294                                  
  6295 0000251B BF[4671]                	mov	di, part_table_boot_ind
  6296 0000251E B92400                  	mov	cx, 36 ; 18*4 = 72 bytes
  6297 00002521 31C0                    	xor	ax, ax ; 0
  6298 00002523 F3AB                    	rep	stosw
  6299                                  
  6300 00002525 A3[8E71]                	mov	[pcount], ax ; reset (pcount & ppcount)
  6301 00002528 A3[9071]                	mov	[apcount], ax ; reset (apcount & epnumber)
  6302                                  
  6303 0000252B BE[E658]                	mov	si, MasterBootBuff+446 ; Partition table offset
  6304                                  	;mov	cx, 4
  6305 0000252E B104                    	mov	cl, 4
  6306 00002530 31FF                    	xor	di, di
  6307                                  ipt_0:
  6308 00002532 8A6404                  	mov	ah, [si+ptFileSystemID]
  6309                                  
  6310 00002535 20E4                    	and	ah, ah
  6311 00002537 0F841801                	jz	ipt_8 ; empty
  6312                                  
  6313 0000253B FE06[8E71]              	inc	byte [pcount] ; partition count
  6314                                  
  6315 0000253F 80FC01                  	cmp	ah, 1	; FAT12
  6316 00002542 7427                    	je	short ipt_2
  6317 00002544 80FC04                  	cmp	ah, 4	; FAT16
  6318 00002547 7422                    	je	short ipt_2
  6319 00002549 7224                    	jb	short ipt_3	
  6320 0000254B 80FC06                  	cmp	ah, 6	; FAT16 big
  6321 0000254E 741B                    	je	short ipt_2
  6322 00002550 7712                    	ja	short ipt_1 ; EXTENDED
  6323                                  
  6324                                  	;cmp	ah, 5 ; EXTENDED
  6325                                  	;jne	short ipt_3
  6326                                  
  6327 00002552 803E[9171]00            	cmp	byte [epnumber], 0
  6328 00002557 0F87B100                	ja	ipt_stc ; invalid  (more than 1 extended dos partition)
  6329                                  	
  6330 0000255B B005                    	mov	al, 5
  6331 0000255D 28C8                    	sub	al, cl ; partition number 1 to 4
  6332 0000255F A2[9171]                	mov	byte [epnumber], al ; extended partition entry number (1 to 4)
  6333 00002562 EB0B                    	jmp	short ipt_3
  6334                                  ipt_1:
  6335 00002564 80FC0B                  	cmp	ah, 0Bh ; FAT32 (CHS)
  6336 00002567 7506                    	jne	short ipt_3 ; 16/10/2020
  6337                                  	; 26/10/2020
  6338 00002569 7400                    	je	short ipt_2
  6339                                  	;cmp	ah, 07h ; NTFS (Windows FS)
  6340                                  	;jne	short ipt_3 ; accept NTFS as primary dos partition
  6341                                  	;		    ; (then, extended partition can be created)		
  6342                                  ipt_2:
  6343 0000256B FE06[8F71]              	inc	byte [ppcount] ; primary dos partition count
  6344                                  ipt_3:
  6345 0000256F 88A5[4B71]              	mov	[part_table_sys_id+di], ah  ; Partition Type (FS type)
  6346                                  	
  6347 00002573 8A04                    	mov	al, [si+ptBootable]
  6348                                  
  6349 00002575 20C0                    	and	al, al
  6350 00002577 7413                    	jz	short ipt_4
  6351                                  
  6352 00002579 803E[9071]01            	cmp	byte [apcount], 1 ; check (previous) active partition count
  6353 0000257E 0F838A00                	jnb	ipt_stc  ; invalid (if it is not zero here)
  6354                                  
  6355 00002582 3C80                    	cmp	al, 80h  ; active partition sign/flag?
  6356 00002584 0F858400                	jne	ipt_stc  ; invalid flag
  6357                                  
  6358 00002588 FE06[9071]              	inc	byte [apcount]  ; active partition count  = 1
  6359                                  ipt_4:
  6360 0000258C 8885[4671]              	mov	[part_table_boot_ind+di], al
  6361                                  
  6362 00002590 A0[9840]                	mov	al, [heads]
  6363                                  ipt_4_fix:
  6364 00002593 FEC8                    	dec	al
  6365 00002595 8A6401                  	mov	ah, [si+ptBeginHead]
  6366 00002598 38E0                    	cmp	al, ah
  6367                                  	;jb	short ipt_retn ; invalid
  6368 0000259A 7272                    	jb	ipt_heads_fix ; 10/02/2019
  6369 0000259C 88A5[4771]              	mov	[part_table_start_head+di], ah
  6370 000025A0 8A6405                  	mov	ah, [si+ptEndHead]
  6371 000025A3 38E0                    	cmp	al, ah
  6372                                  	;jb	short ipt_retn ; invalid
  6373 000025A5 7267                    	jb	short ipt_heads_fix ; 10/02/2019
  6374 000025A7 88A5[4C71]              	mov	[part_table_end_head+di], ah
  6375 000025AB A0[9640]                	mov	al, [sectors]
  6376 000025AE 8A7C02                  	mov	bh, [si+ptBeginSector]
  6377 000025B1 88FC                    	mov	ah, bh
  6378 000025B3 80E43F                  	and	ah, 3Fh ; 63
  6379 000025B6 38E0                    	cmp	al, ah
  6380 000025B8 7253                    	jb	short ipt_retn ; invalid
  6381 000025BA 88A5[4871]              	mov	[part_table_start_sector+di], ah
  6382 000025BE 8A7406                  	mov	dh, [si+ptEndSector]
  6383 000025C1 88F4                    	mov	ah, dh
  6384 000025C3 80E43F                  	and	ah, 3Fh ; 63
  6385 000025C6 38E0                    	cmp	al, ah
  6386 000025C8 7243                    	jb	short ipt_retn ; invalid
  6387 000025CA 88A5[4D71]              	mov	[part_table_end_sector+di], ah
  6388 000025CE C0EF06                  	shr	bh, 6
  6389 000025D1 8A5C03                  	mov	bl, [si+ptBeginCylinder]
  6390 000025D4 A1[9A40]                	mov	ax, [cylinders]
  6391 000025D7 48                      	dec	ax	
  6392 000025D8 39D8                    	cmp	ax, bx
  6393 000025DA 7231                    	jb	short ipt_retn ; invalid
  6394 000025DC 899D[4971]              	mov	[part_table_start_cyl+di], bx
  6395 000025E0 C0EE06                  	shr	dh, 6
  6396 000025E3 8A5407                  	mov	dl, [si+ptEndCylinder]
  6397 000025E6 39D0                    	cmp	ax, dx
  6398 000025E8 7223                    	jb	short ipt_retn ; invalid
  6399 000025EA 8995[4E71]              	mov	[part_table_end_cyl+di], dx
  6400                                  
  6401 000025EE 8B4408                  	mov	ax, [si+ptStartSector]
  6402 000025F1 8B540A                  	mov	dx, [si+ptStartSector+2]
  6403                                  
  6404 000025F4 8985[5071]              	mov	[part_table_rel_sec_lw+di], ax
  6405 000025F8 8995[5271]              	mov	[part_table_rel_sec_hw+di], dx
  6406                                  
  6407 000025FC 09D0                    	or	ax, dx
  6408 000025FE 740C                    	jz	short ipt_stc ; invalid (start sector must not be zero)
  6409                                  
  6410 00002600 8B440C                  	mov	ax, [si+ptSectors]
  6411 00002603 8B540E                  	mov	dx, [si+ptSectors+2]
  6412                                  
  6413 00002606 89D3                    	mov	bx, dx
  6414 00002608 09C3                    	or	bx, ax
  6415                                  	;jz	short ipt_stc	; invalid (zero size of partition)
  6416 0000260A 7521                    	jnz	short ipt_6 ; 10/02/2019
  6417                                  
  6418                                  	;cmp	dx, [total_sectors+2]
  6419                                  	;ja	short ipt_stc	; invalid (partition size > disk capacity)
  6420                                  	;jb	short ipt_6
  6421                                  	;;cmp	ax, [total_sectors] ; (ax + 1) <= total sectors
  6422                                  	;jb	short ipt_6
  6423                                  	
  6424                                  ipt_stc:
  6425                                  	; invalid MBR data
  6426 0000260C F9                      	stc
  6427                                  ipt_retn:
  6428 0000260D C3                      	retn
  6429                                  
  6430                                  ipt_heads_fix:
  6431                                  	; 10/02/2019
  6432                                  	; AL = [heads] - 1
  6433                                  
  6434 0000260E F606[9A40]01            	test	byte [cylinders], 1
  6435 00002613 75F7                    	jnz	short ipt_stc ; odd cylinder count (can not be shifted)
  6436                                  	
  6437 00002615 FEC0                    	inc	al ; = [heads]
  6438 00002617 3C08                    	cmp	al, 8
  6439 00002619 77F1                    	ja	short ipt_stc ; this fix is needed for <= 16 heads (& 17 spt)
  6440 0000261B D0E0                    	shl	al, 1
  6441 0000261D A2[9840]                	mov	[heads], al ; heads = heads*2
  6442 00002620 D12E[9A40]              	shr	word [cylinders], 1 ; cylinders = cylinders/2
  6443 00002624 E96CFF                  	jmp	ipt_4_fix
  6444                                  
  6445                                  ipt_5:
  6446 00002627 83C712                  	add	di, 18
  6447 0000262A E905FF                  	jmp	ipt_0
  6448                                  
  6449                                  ipt_6:
  6450 0000262D 8985[5471]              	mov	[part_table_num_sec_lw+di], ax
  6451 00002631 8995[5671]              	mov	[part_table_num_sec_hw+di], dx
  6452                                  
  6453 00002635 0385[5071]              	add	ax, [part_table_rel_sec_lw+di]
  6454 00002639 1395[5271]              	adc	dx, [part_table_rel_sec_hw+di]
  6455 0000263D 72CE                    	jc	short ipt_retn  ; invalid
  6456                                  
  6457 0000263F 3B16[8A6E]              	cmp	dx, [total_sectors+2]
  6458 00002643 77C7                    	ja	short ipt_stc	; invalid (partition end > disk capacity)
  6459 00002645 7206                    	jb	short ipt_7
  6460 00002647 3B06[886E]              	cmp	ax, [total_sectors] ; ax <= total sectors
  6461 0000264B 77BF                    	ja	short ipt_stc	; invalid (partition end > disk capacity)
  6462                                  ipt_7:
  6463 0000264D 83C610                  	add	si, 16
  6464 00002650 E2D5                    	loop	ipt_5
  6465                                  	
  6466                                  	; OK!
  6467                                  
  6468                                  	;clc
  6469 00002652 C3                      	retn
  6470                                  
  6471                                  ipt_8:
  6472                                  	; Empty partition table check (all of 16 bytes must be 0)
  6473 00002653 51                      	push	cx
  6474 00002654 B108                    	mov	cl, 8
  6475                                  ipt_9:
  6476 00002656 AD                      	lodsw
  6477 00002657 09C0                    	or	ax, ax
  6478 00002659 7506                    	jnz	short ipt_10
  6479 0000265B E2F9                    	loop	ipt_9
  6480 0000265D 59                      	pop	cx
  6481 0000265E E2C7                    	loop	ipt_5
  6482                                  	
  6483                                  	;clc
  6484 00002660 C3                      	retn
  6485                                  ipt_10:
  6486 00002661 59                      	pop	cx
  6487                                  	; invalid
  6488 00002662 F9                      	stc	
  6489 00002663 C3                      	retn
  6490                                  
  6491                                  ;-----------------------------------------------------------------------------
  6492                                  ; 25/10/2020
  6493                                  
  6494                                  	; 02/02/2019
  6495                                  	
  6496                                  sort_partition_table:
  6497                                  
  6498                                  	; INPUT -> none
  6499                                  	; OUTPUT -> none
  6500                                  
  6501 00002664 31DB                    	xor	bx, bx
  6502                                  	;jmp	short sortpt_2 ; 25/10/2020
  6503                                  sortpt_1:
  6504 00002666 889F[D26E]              	mov	[bx+sort], bl ; 0	
  6505 0000266A FEC3                    	inc	bl
  6506                                  sortpt_2:
  6507 0000266C 80FB04                  	cmp	bl, 4 ; number of partition table entries to sort
  6508 0000266F 72F5                    	jb	short sortpt_1
  6509                                  
  6510                                  	; Do a bubble sort
  6511                                  
  6512 00002671 EB04                    	jmp	short sortpt_4
  6513                                  sortpt_3:
  6514                                  	; Sort until we don't do a swap
  6515                                  
  6516 00002673 08C9                    	or	cl, cl ; sort changed ?
  6517 00002675 744A                    	jz	short sortpt_8 ; no.
  6518                                  sortpt_4:
  6519 00002677 30C9                    	xor	cl, cl
  6520                                  
  6521 00002679 B301                    	mov	bl, 1
  6522                                  
  6523 0000267B B212                    	mov	dl, 18  ; partition table structure size
  6524 0000267D EB07                    	jmp	short sortpt_6
  6525                                  sortpt_5:
  6526 0000267F FEC3                    	inc	bl
  6527                                  
  6528 00002681 80FB04                  	cmp	bl, 4
  6529 00002684 73ED                    	jnb	short sortpt_3
  6530                                  
  6531                                  sortpt_6:
  6532 00002686 8A87[D26E]              	mov	al, [bx+sort]
  6533                                  
  6534 0000268A F6E2                    	mul	dl
  6535                                  
  6536 0000268C 89C6                    	mov	si, ax
  6537                                  
  6538 0000268E 8BBC[4E71]              	mov	di, [part_table_end_cyl+si]
  6539                                  
  6540 00002692 8A87[D16E]              	mov	al, [bx+sort-1]
  6541                                  
  6542 00002696 F6E2                    	mul	dl ; * 18
  6543                                  
  6544 00002698 97                      	xchg	di, ax
  6545                                  
  6546 00002699 3985[4E71]              	cmp	[part_table_end_cyl+di], ax ; previous > current
  6547 0000269D 7714                    	ja	short sortpt_7 ; swap order indicators
  6548                                  
  6549                                  	; If current entry is empty partition entry
  6550                                  	; and previous entry is not empty partition entry
  6551                                  	; swap them.
  6552                                  
  6553 0000269F 8B84[5671]              	mov	ax, [part_table_num_sec_hw+si] ; current entry
  6554 000026A3 0B84[5471]              	or	ax, [part_table_num_sec_lw+si]
  6555 000026A7 75D6                    	jnz	short sortpt_5
  6556                                  
  6557 000026A9 8B85[5671]              	mov	ax, [part_table_num_sec_hw+di] ; previous entry
  6558 000026AD 0B85[5471]              	or	ax, [part_table_num_sec_lw+di]
  6559 000026B1 74CC                    	jz	short sortpt_5
  6560                                  sortpt_7:
  6561                                  	; Swap the order indicators
  6562                                  
  6563 000026B3 8B87[D16E]              	mov	ax, [bx+sort-1]
  6564 000026B7 86E0                    	xchg	ah, al
  6565 000026B9 8987[D16E]              	mov	[bx+sort-1], ax
  6566                                  
  6567 000026BD B101                    	mov	cl, 1 ; sort changed
  6568 000026BF EBBE                    	jmp	short sortpt_5
  6569                                  sortpt_8:
  6570 000026C1 C606[EE70]01            	mov 	byte [p_sorted], 1 ; 04/02/2019
  6571                                  
  6572 000026C6 C3                      	retn
  6573                                  
  6574                                  ;-----------------------------------------------------------------------------
  6575                                  ; 03/02/2019
  6576                                  
  6577                                  find_part_free_space:  ; find/calculate free space for partitions
  6578                                  	; 15/02/2019
  6579                                  
  6580                                  	; INPUT -> 
  6581                                  	;	AL = 0 -> calculate for primary/MBR partitions 
  6582                                  	;	AL = 5 -> calculate for extended partition
  6583                                  	; OUTPUT ->
  6584                                  	;	CX = the largest free space/cylinders (between partitions)
  6585                                  	;	AX = Free space index (gap number) - from 0 to 4 -
  6586                                  	;	BX = Free space structure offset (for the largest free space)
  6587                                  	;
  6588                                  	;	22/02/2019
  6589                                  	;	[freespace_count] = number of free spaces/gaps
  6590                                  
  6591 000026C7 A2[ED70]                	mov	[p_type], al
  6592                                  
  6593                                  	; Sort the partition table
  6594                                  
  6595 000026CA E897FF                  	call	sort_partition_table ; 16/02/2019
  6596                                  
  6597                                  	; Initialize free space to zero
  6598                                  
  6599                                  	; 15/02/2019
  6600 000026CD BF[DA71]                	mov	di, fspc ; free_space.space
  6601 000026D0 B92800                  	mov	cx, 5*8 ; (5*16/2)
  6602 000026D3 31C0                    	xor	ax, ax ; 0
  6603 000026D5 F3AB                    	rep	stosw
  6604                                  
  6605 000026D7 A2[EA70]                	mov	[freespace_count], al ; 0
  6606                                  	; 22/02/2019
  6607                                  	;mov	[last_found_partition], al ; 0
  6608                                  
  6609 000026DA A3[E870]                	mov	[_i_], ax ; 0
  6610 000026DD EB11                    	jmp	short fpfs_2
  6611                                  fpfs_1:	
  6612 000026DF FE06[E870]              	inc	byte [_i_]
  6613                                  ;;fpfs_2:
  6614 000026E3 803E[E870]04            	cmp	byte [_i_], 4
  6615 000026E8 7203                    	jb	short fpfs_3
  6616 000026EA E97801                  	jmp	fpfs_13
  6617                                  fpfs_3:
  6618                                  	; Find space between start of disk and first partition
  6619                                  
  6620 000026ED A1[E870]                	mov	ax, [_i_]
  6621                                  fpfs_2:
  6622 000026F0 89C3                    	mov	bx, ax
  6623                                  	;mov	al, [sort+bx]
  6624 000026F2 8A8F[D26E]              	mov	cl, [sort+bx] ; 15/02/2019
  6625                                  
  6626                                  	;mov	cl, 18 ; partition table structure size = 18 bytes
  6627 000026F6 B012                    	mov	al, 18 ; 15/02/2019
  6628 000026F8 F6E1                    	mul	cl
  6629 000026FA 89C3                    	mov	bx, ax
  6630                                  
  6631 000026FC 80BF[4B71]00            	cmp	byte [part_table_sys_id+bx], 0
  6632 00002701 74DC                    	je	short fpfs_1
  6633                                  
  6634 00002703 880E[EC70]              	mov	[last_found_partition], cl ; 15/02/2019
  6635                                  
  6636 00002707 30C9                    	xor	cl, cl ; 0 	
  6637 00002709 B001                    	mov	al, 1 ; LBA = 1 (after MBR) ; ah = 0
  6638                                  	
  6639 0000270B 803E[ED70]05            	cmp	byte [p_type], 5  ; EXTENDED
  6640 00002710 7509                    	jne	short fpfs_4
  6641                                  
  6642                                  	; This is a special case - the extended partition can not start
  6643                                  	; on cylinder 0 due to its architecture. Protect against that here
  6644                                  
  6645                                  	; 13/02/2019
  6646                                  	; LBA value of free space start
  6647 00002712 A0[9640]                	mov	al, [sectors]
  6648 00002715 F626[9840]              	mul	byte [heads]
  6649                                  		; ax = start sector (for Extended Partition)
  6650 00002719 FEC1                    	inc	cl ; 1  ; cx = start cylinder = 1
  6651                                  fpfs_4:
  6652                                  	; Found a partition, get the space
  6653                                  
  6654                                  	; 15/02/2019
  6655 0000271B 8B97[4971]              	mov	dx, [part_table_start_cyl+bx]
  6656 0000271F 39CA                    	cmp	dx, cx
  6657 00002721 0F86C000                	jna	fpfs_9 ; It is accepted as free (partition) space
  6658                                  		       ; if this space between masterboot sector and partition 1
  6659                                  		       ; has 1 cylinder (heads*spt) size at least.
  6660                                  	; 22/02/2019
  6661 00002725 31FF                    	xor	di, di  ; 0 ; Reset Free Space Table offset
  6662                                  
  6663 00002727 FE06[EA70]              	inc	byte [freespace_count]	; mov byte [freespace_count], 1
  6664                                  
  6665 0000272B 890E[DC71]              	mov	[free_space.start], cx ; 0 (for PP) or 1 (for EP)
  6666                                  	
  6667                                  	; non-aligned address of start sector (for the 1st partition as sorted)
  6668                                  	; NOTE: later, start sector will be moved to (chs) head 1 and sector 1
  6669                                  	;	if new partition will be selected as a primary dos partition.
  6670                                  	;	(But, start sector -LBA- will not be changed 
  6671                                  	;	 if it is a non-dos or user input type partition.. unless
  6672                                  	;	 cylinder boundary alignment option is used.)
  6673                                  	 	
  6674 0000272F A3[E671]                	mov	[free_space.startsector], ax ; = [sectors]*[heads] (for EP)
  6675                                  					     ; or 1 (for PP)
  6676                                  	;mov	[free_space.startsector+2], 0
  6677                                  
  6678                                  	; free space ends before start of next valid partition
  6679 00002732 89D0                    	mov	ax, dx	; start cylinder of partition 1 (as sorted)
  6680 00002734 29CA                    	sub	dx, cx	; cylinder count of free space 1 (gap 1)
  6681 00002736 48                      	dec	ax	; end cylinder of free space 1 (gap 1)
  6682 00002737 A3[DE71]                	mov	[free_space.end], ax 
  6683 0000273A 8916[DA71]              	mov	[free_space.space], dx
  6684                                  
  6685                                  	; save free space (1) as (non-aligned) sector count
  6686 0000273E 8B87[5071]              	mov	ax, [part_table_rel_sec_lw+bx]
  6687 00002742 8B97[5271]              	mov	dx, [part_table_rel_sec_hw+bx]
  6688 00002746 2B06[E671]              	sub	ax, [free_space.startsector]
  6689 0000274A 83DA00                  	sbb	dx, 0
  6690 0000274D A3[E271]                	mov	[free_space.sectors_unused], ax
  6691 00002750 8916[E471]              	mov	[free_space.sectors_unused+2], dx
  6692                                  
  6693                                  	;mov	ax, [free_space.space]
  6694                                  
  6695                                  	;call	cylinders_to_sectors
  6696                                  
  6697                                  	;mov	[free_space.sectors_unused], ax
  6698                                  	;mov	[free_space.sectors_unused+2], dx
  6699                                  
  6700 00002754 8B0E[9A40]              	mov	cx, [cylinders]		; Total (disk) cylinders -divisor-
  6701 00002758 8B1E[DA71]              	mov	bx, [free_space.space]	; Partition cylinders -dividend-
  6702                                  
  6703 0000275C E81002                  	call	cylinders_to_percent
  6704                                  
  6705 0000275F A3[E071]                	mov	[free_space.percent_unused], ax
  6706                                  
  6707                                  	; 15/02/2019
  6708                                  	;mov	bl, [_i_]
  6709                                  	;xor	bh, bh
  6710                                  	;mov	al, [sort+bx]
  6711                                  
  6712                                  	;mov	[last_found_partition], al
  6713                                  
  6714                                  	; Look for space between the rest of the partitions
  6715                                  
  6716                                  fpfs_7:
  6717                                  	; ah = 0
  6718                                  	;mov	al, [_i_]
  6719                                  	;;cbw
  6720                                  	;mov	bx, ax
  6721                                  	; 22/02/2019
  6722 00002762 8B1E[E870]              	mov	bx, [_i_]
  6723                                  
  6724                                  	; 15/02/2019
  6725                                  	;mov	al, [sort+bx]
  6726 00002766 8A8F[D26E]              	mov	cl, [sort+bx]
  6727                                  	;mov	bl, 18
  6728                                  	;mul	bl
  6729 0000276A B012                    	mov	al, 18
  6730 0000276C F6E1                    	mul	cl
  6731 0000276E 89C6                    	mov	si, ax
  6732                                  	
  6733 00002770 80BC[4B71]00            	cmp	byte [part_table_sys_id+si], 0
  6734 00002775 746E                    	je	short fpfs_9
  6735                                  
  6736                                  	; 15/02/2019
  6737 00002777 860E[EC70]              	xchg	[last_found_partition], cl
  6738                                  
  6739                                  	; Check to see if more than one partition on a cylinder
  6740                                  	; If so, leave the space at zero */
  6741                                  
  6742                                  	; NOTE:
  6743                                  	; It is accepted as valid free (partition) space
  6744                                  	; if free space (gap) between partitions
  6745                                  	; has 1 cylinder (heads*spt) size at least.
  6746                                  
  6747 0000277B B012                    	mov	al, 18 ; Partition tables/data structure size = 18 bytes
  6748 0000277D F6E1                    	mul	cl
  6749 0000277F 89C3                    	mov	bx, ax  ; ah = 0
  6750                                  
  6751 00002781 8B97[4E71]              	mov	dx, [part_table_end_cyl+bx]   ; end cyl. of previous partition 
  6752 00002785 8B84[4971]              	mov	ax, [part_table_start_cyl+si] ; start cyl. of current partition
  6753                                  
  6754 00002789 42                      	inc	dx  ; start cylinder of free space is after the end cylinder of
  6755                                  		    ; the previous partition (as sorted)
  6756                                  
  6757 0000278A 39D0                    	cmp	ax, dx ; and it must be before than the next partition (as sorted)
  6758 0000278C 7657                    	jna	short fpfs_9 ; je short fpfs_9
  6759                                  		
  6760                                  	; No, things are normal
  6761                                  	; Get space between the end of the last one and the start of the next one
  6762                                  
  6763                                  	; 22/02/2019
  6764                                  	;add	di, 16
  6765 0000278E 8B3E[EA70]              	mov	di, [freespace_count] 
  6766 00002792 C1E704                  	shl	di, 4	; * 16 ; next entry offset (in free space table)
  6767                                  
  6768 00002795 FE06[EA70]              	inc	byte [freespace_count]
  6769                                  
  6770 00002799 89C1                    	mov	cx, ax
  6771 0000279B 29D1                    	sub	cx, dx
  6772 0000279D 48                      	dec	ax
  6773 0000279E 8995[DC71]              	mov	[free_space.start+di], dx
  6774 000027A2 8985[DE71]              	mov	[free_space.end+di], ax
  6775 000027A6 898D[DA71]              	mov	[free_space.space+di], cx
  6776                                  
  6777                                  	;mov	ax, [free_space.space+di]
  6778                                  	;call	cylinders_to_sectors
  6779                                  	;mov	[free_space.sectors_unused+di], ax
  6780                                  	;mov	[free_space.sectors_unused+2+di], dx
  6781                                  
  6782                                  	; calculate and save (non-aligned) free sector count between partitions
  6783                                  
  6784 000027AA 8B87[5071]              	mov	ax, [part_table_rel_sec_lw+bx]
  6785 000027AE 8B97[5271]              	mov	dx, [part_table_rel_sec_hw+bx]
  6786 000027B2 0387[5471]              	add	ax, [part_table_num_sec_lw+bx]
  6787 000027B6 1397[5671]              	adc	dx, [part_table_num_sec_hw+bx]
  6788                                  
  6789 000027BA 8B8C[5071]              	mov	cx, [part_table_rel_sec_lw+si]
  6790 000027BE 8B9C[5271]              	mov	bx, [part_table_rel_sec_hw+si]
  6791                                  
  6792 000027C2 8985[E671]              	mov	[free_space.startsector+di], ax
  6793 000027C6 8995[E871]              	mov	[free_space.startsector+2+di], dx
  6794                                  
  6795 000027CA 29C1                    	sub	cx, ax
  6796 000027CC 19D3                    	sbb	bx, dx
  6797                                  
  6798 000027CE 898D[E271]              	mov	[free_space.sectors_unused+di], cx
  6799 000027D2 899D[E471]              	mov	[free_space.sectors_unused+2+di], bx
  6800                                  
  6801                                  fpfs_8:
  6802                                  	; NOTE: Percentage is based on cylinder-boundary aligned partition size.
  6803                                  	; (total disk cylinders and partition's cylinder count are used for that)
  6804                                  
  6805 000027D6 8B0E[9A40]              	mov	cx, [cylinders] ; -divisor-
  6806 000027DA 8B9D[DA71]              	mov	bx, [free_space.space+di] ; -dividend-
  6807 000027DE E88E01                  	call	cylinders_to_percent
  6808                                  	
  6809 000027E1 8985[E071]              	mov	[free_space.percent_unused+di], ax 
  6810                                  	
  6811                                  	; ah = 0
  6812                                  
  6813                                  	; 15/02/2019
  6814                                  	;mov	bl, [_i_]
  6815                                  	;xor	bh, bh
  6816                                  	;mov	al, [sort+bx]
  6817                                  	;	
  6818                                  	;mov	[last_found_partition], al
  6819                                  
  6820                                  fpfs_9:
  6821 000027E5 FE06[E870]              	inc	byte [_i_]
  6822                                  fpfs_10:
  6823 000027E9 803E[E870]04            	cmp	byte [_i_], 4
  6824 000027EE 7303                    	jnb	short fpfs_11
  6825                                  
  6826 000027F0 E96FFF                  	jmp	fpfs_7
  6827                                  
  6828                                  fpfs_11:
  6829                                  	; Find the space between the last partition and the end of the disk
  6830                                  	; Make sure that freespace cannot become negative
  6831                                  
  6832 000027F3 A0[EC70]                	mov	al, [last_found_partition]
  6833 000027F6 B112                    	mov	cl, 18  ; Partition table structure size = 18 bytes
  6834 000027F8 F6E1                    	mul	cl
  6835 000027FA 89C3                    	mov	bx, ax
  6836 000027FC 8B0E[9A40]              	mov	cx, [cylinders]
  6837 00002800 49                      	dec	cx ; 15/02/2019 
  6838                                  		   ; (min. cylinder count = 1 for a valid/usable free space)
  6839 00002801 8B87[4E71]              	mov	ax, [part_table_end_cyl+bx]
  6840                                  	;cmp	[part_table_end_cyl+bx], cx
  6841 00002805 39C8                    	cmp	ax, cx
  6842 00002807 7203                    	jb	short fpfs_12
  6843 00002809 E9A600                  	jmp	fpfs_15
  6844                                  fpfs_12:
  6845                                  	; 22/02/2019
  6846 0000280C 8B3E[EA70]              	mov	di, [freespace_count]
  6847 00002810 C1E704                  	shl	di, 4 ; * 16  ; next entry offset (in free space table)
  6848                                  
  6849 00002813 FE06[EA70]              	inc	byte [freespace_count]
  6850                                  
  6851 00002817 898D[DE71]              	mov	[free_space.end+di], cx  ; end cyl. of free space 5 (gap 5) 
  6852                                  	;mov	ax, [part_table_end_cyl+bx]
  6853 0000281B 89CA                    	mov	dx, cx
  6854 0000281D 29C2                    	sub	dx, ax
  6855 0000281F 8995[DA71]              	mov	[free_space.space+di], dx ; di = 4*16
  6856 00002823 40                      	inc	ax
  6857 00002824 8985[DC71]              	mov	[free_space.start+di], ax
  6858                                  	
  6859                                  	;inc	cx ; [cylinders]
  6860                                  	;mov	ax, [free_space.space+si]
  6861                                  	;call	cylinders_to_sectors
  6862                                  	;mov	[free_space.sectors_unused+di], ax
  6863                                  	;mov	[free_space.sectors_unused+2+di], dx
  6864                                  
  6865                                  	; calculate and save (non-aligned) free sector count
  6866                                  
  6867                                  	; 22/02/2019
  6868 00002828 8B87[5071]              	mov	ax, [part_table_rel_sec_lw+bx]
  6869 0000282C 8B97[5271]              	mov	dx, [part_table_rel_sec_hw+bx]
  6870 00002830 0387[5471]              	add	ax, [part_table_num_sec_lw+bx]
  6871 00002834 1397[5671]              	adc	dx, [part_table_num_sec_hw+bx]
  6872                                  
  6873 00002838 8985[E671]              	mov	[free_space.startsector+di], ax
  6874 0000283C 8995[E871]              	mov	[free_space.startsector+2+di], dx
  6875                                  
  6876 00002840 8B0E[886E]              	mov	cx, [total_sectors]
  6877 00002844 8B1E[8A6E]              	mov	bx, [total_sectors+2]
  6878 00002848 29C1                    	sub	cx, ax
  6879 0000284A 19D3                    	sbb	bx, dx
  6880 0000284C 898D[E271]              	mov	[free_space.sectors_unused+di], cx
  6881 00002850 899D[E471]              	mov	[free_space.sectors_unused+2+di], bx
  6882                                  
  6883 00002854 8B0E[9A40]              	mov	cx, [cylinders]
  6884 00002858 8B9D[DA71]              	mov	bx, [free_space.space+di]
  6885 0000285C E81001                  	call	cylinders_to_percent
  6886 0000285F 8985[E071]              	mov	[free_space.percent_unused+di], ax
  6887 00002863 EB4D                    	jmp	short fpfs_15
  6888                                  
  6889                                  fpfs_13:
  6890                                  	; No partitions found, show entire space as free
  6891                                  
  6892                                  	; 22/02/2019
  6893 00002865 FE06[EA70]              	inc	byte [freespace_count]	; mov byte [freespace_count], 1
  6894                                  	
  6895                                  	; 15/02/2019
  6896                                  	;sub	ax, ax
  6897 00002869 29D2                    	sub	dx, dx
  6898                                  
  6899                                  	;inc	al ; LBA = 1 (after MBR) ; ah = 0
  6900 0000286B B001                    	mov	al, 1 ; 25/02/2019
  6901                                  
  6902                                  	;This is a special case - the extended partition can not start
  6903                                  	;on cylinder 0 due to its architecture. Protect against that here
  6904                                  
  6905 0000286D 803E[ED70]05            	cmp	byte [p_type], 5 ; EXTENDED
  6906 00002872 7509                    	jne	short fpfs_14
  6907                                  		
  6908 00002874 FEC2                    	inc	dl
  6909                                  
  6910                                  	; 15/02/2019
  6911                                  	; LBA value of free space start
  6912 00002876 A0[9640]                	mov	al, [sectors]
  6913 00002879 F626[9840]              	mul	byte [heads]
  6914                                  		; ax = start sector (for Extended Partition)
  6915                                  fpfs_14:
  6916 0000287D 8916[DC71]              	mov	[free_space.start], dx ; 0 or 1
  6917                                  
  6918                                  	; non-aligned address of start sector (for the 1st partition as sorted)
  6919                                  	; NOTE: later, start sector will be moved to (chs) head 1 and sector 1
  6920                                  	;	if new partition will be selected as a primary dos partition.
  6921                                  	 	
  6922 00002881 A3[E671]                	mov	[free_space.startsector], ax ; = [sectors]*[heads] (for EP)
  6923                                  					     ; or 1 (for PP)
  6924                                  	;mov	[free_space.startsector+2], 0
  6925                                  
  6926 00002884 A1[9A40]                	mov	ax, [cylinders] ; disk capacity 
  6927 00002887 89C1                    	mov	cx, ax
  6928 00002889 48                      	dec	ax
  6929 0000288A A3[DE71]                	mov	[free_space.end], ax
  6930 0000288D 29D0                    	sub	ax, dx
  6931 0000288F 40                      	inc	ax
  6932 00002890 A3[DA71]                	mov	[free_space.space], ax
  6933                                  
  6934 00002893 A1[886E]                	mov	ax, [total_sectors]
  6935 00002896 8B16[8A6E]              	mov	dx, [total_sectors+2]
  6936 0000289A 2B06[E671]              	sub	ax, [free_space.startsector]
  6937 0000289E 83DA00                  	sbb	dx, 0
  6938 000028A1 A3[E271]                	mov	[free_space.sectors_unused], ax
  6939 000028A4 8916[E471]              	mov	[free_space.sectors_unused+2], dx
  6940                                  
  6941                                  	;mov	cx, [cylinders] 
  6942 000028A8 8B1E[DA71]              	mov	bx, [free_space.space]
  6943 000028AC E8C000                  	call	cylinders_to_percent
  6944 000028AF A3[E071]                	mov	[free_space.percent_unused], ax
  6945                                  
  6946                                  fpfs_15:
  6947                                  	; Find largest free space
  6948 000028B2 29C9                    	sub	cx, cx
  6949                                  	; 22/02/2019
  6950 000028B4 29C0                    	sub	ax, ax
  6951 000028B6 31DB                    	xor	bx, bx
  6952 000028B8 8A16[EA70]              	mov	dl, [freespace_count]
  6953 000028BC 08D2                    	or	dl, dl
  6954 000028BE 7420                    	jz	short fpfs_19
  6955 000028C0 8816[E870]              	mov	[_i_], dl
  6956                                  fpfs_16:
  6957 000028C4 8B97[DA71]              	mov	dx, [free_space.space+bx] 
  6958 000028C8 39CA                    	cmp	dx, cx
  6959 000028CA 7604                    	jbe	short fpfs_17
  6960                                  	; 22/02/2019
  6961 000028CC 89D1                    	mov	cx, dx ; Largest free space
  6962 000028CE 89D8                    	mov	ax, bx
  6963                                  fpfs_17:
  6964 000028D0 FE0E[E870]              	dec	byte [_i_]
  6965 000028D4 7405                    	jz	short fpfs_18
  6966                                  
  6967 000028D6 83C310                  	add	bx, 16 ; Free space structure size
  6968 000028D9 EBE9                    	jmp	short fpfs_16
  6969                                  fpfs_18:
  6970                                  	; 22/02/2019
  6971 000028DB 89C3                    	mov	bx, ax ; offset (from 0 to 64)
  6972 000028DD C0E804                  	shr	al, 4  ; index (from 0 to 4)
  6973                                  fpfs_19:
  6974 000028E0 C3                      	retn
  6975                                  
  6976                                  ;-----------------------------------------------------------------------------
  6977                                  
  6978                                  ;	; 15/02/2019
  6979                                  ;find_enough_free_space:
  6980                                  ;	; Find enough free space
  6981                                  ;	;
  6982                                  ;	; INPUT:
  6983                                  ;	;	AX = Requested space (in cylinders)
  6984                                  ;	;	22/02/2019
  6985                                  ;	;	[freespace_count] = number of free spaces/gaps
  6986                                  ;	; OUTPUT:
  6987                                  ;	;	AX = Available space
  6988                                  	;	DX = Requested space
  6989                                  ;	;	If CF = 0 -> AX >= DX
  6990                                  ;	;	If CF = 1 -> AX < DX
  6991                                  ;	;	CX = Index of available space in free space structure
  6992                                  ;	;	     (GAP number, 0 to 4) - if AX > 0 -	
  6993                                  ;
  6994                                  ;	mov	dx, ax ; 22/02/2019
  6995                                  ;	sub	ax, ax
  6996                                  ;	xor	bx, bx
  6997                                  ;	; 22/02/2019
  6998                                  ;	mov	ch, [freespace_count]
  6999                                  ;	mov	[_i_], ax ; 0
  7000                                  ;	jmp	short fefs_1
  7001                                  ;fefs_0:
  7002                                  ;	;mov	al, 16
  7003                                  ;	;mul	byte [_i_]
  7004                                  ;	;mov	bx, ax
  7005                                  ;	mov	bl, [_i_]
  7006                                  ;	shl	bl, 4 ; * 16
  7007                                  ;fefs_1:
  7008                                  ;	mov	ax, [free_space.space+bx]
  7009                                  ;	and	ax, ax
  7010                                  ;	jz	short fefs_2 ; not a free space
  7011                                  ;	mov	cl, [_i_] 
  7012                                  ;	cmp	ax, dx
  7013                                  ;	jnb	short fefs_3 ; enough space
  7014                                  ;fefs_2:
  7015                                  ;	; 22/02/2019
  7016                                  ;	inc	byte [_i_]
  7017                                  ;	cmp	byte [_i_], ch	
  7018                                  ;	jb	short fefs_0
  7019                                  ;	sub	ch, ch
  7020                                  ;	stc
  7021                                  ;	retn
  7022                                  ;fefs_3:
  7023                                  ;	xor	ch, ch
  7024                                  ;	retn
  7025                                  
  7026                                  ;-----------------------------------------------------------------------------
  7027                                  
  7028                                  	; 15/02/2019
  7029                                  find_enough_free_sectors:
  7030                                  	; Find (first) enough free space in sectors
  7031                                  	;
  7032                                  	; INPUT:
  7033                                  	;	DX:AX = Requested space (as non-aligned free sectors)
  7034                                  	;	22/02/2019
  7035                                  	;	[freespace_count] = number of free spaces/gaps
  7036                                  	; OUTPUT:
  7037                                  	;	DX:AX = AX = Available space
  7038                                  	;	If CF = 0 -> DX:AX >= Request
  7039                                  	;	If CF = 1 -> DX:AX < Request
  7040                                  	;	CX = Index of available space in free space structure
  7041                                  	;	     (GAP number, 0 to 4) - if DX:AX > 0 -
  7042                                  
  7043 000028E1 31FF                    	xor	di, di
  7044 000028E3 31F6                    	xor	si, si
  7045 000028E5 31DB                    	xor	bx, bx
  7046                                  	; 22/02/2019
  7047 000028E7 8A2E[EA70]              	mov	ch, [freespace_count]
  7048 000028EB 891E[E870]              	mov	[_i_], bx ; 0
  7049 000028EF EB07                    	jmp	short fefss_1
  7050                                  fefss_0:
  7051                                  	;mov	al, 16
  7052                                  	;mul	byte [_i_]
  7053                                  	;mov	bx, ax
  7054 000028F1 8B1E[E870]              	mov	bx, [_i_]
  7055 000028F5 C0E304                  	shl	bl, 4 ; * 16
  7056                                  fefss_1:
  7057 000028F8 81C3[E271]              	add	bx, free_space.sectors_unused
  7058 000028FC 3B5702                  	cmp	dx, [bx+2]
  7059 000028FF 723B                    	jb	short fefss_7
  7060 00002901 7706                    	ja	short fefss_2
  7061 00002903 3B07                    	cmp	ax, [bx]
  7062 00002905 743A                    	je	short fefss_8
  7063 00002907 7233                    	jb	short fefss_7 ; 18/02/2019
  7064                                  fefss_2:
  7065 00002909 833F00                  	cmp	word [bx], 0
  7066 0000290C 7506                    	jne	short fefss_3
  7067 0000290E 837F0200                	cmp	word [bx+2], 0
  7068 00002912 7416                    	je	short fefss_6	
  7069                                  fefss_3:
  7070 00002914 3B7F02                  	cmp	di, [bx+2]
  7071 00002917 7711                    	ja	short fefss_6
  7072 00002919 7405                    	je	short fefss_4
  7073 0000291B 8B7F02                  	mov	di, [bx+2]
  7074 0000291E EB04                    	jmp	short fefss_5
  7075                                  fefss_4:
  7076 00002920 3B37                    	cmp	si, [bx]
  7077 00002922 7306                    	jnb	short fefss_6
  7078                                  fefss_5:
  7079 00002924 8B37                    	mov	si, [bx]
  7080                                  	; 22/02/2019
  7081 00002926 8A0E[E870]              	mov	cl, [_i_]
  7082                                  fefss_6:
  7083 0000292A FE06[E870]              	inc	byte [_i_]
  7084 0000292E 382E[E870]              	cmp	byte [_i_], ch ; [freespace_count]
  7085 00002932 72BD                    	jb	short fefss_0
  7086                                  	
  7087 00002934 89F0                    	mov	ax, si
  7088 00002936 89FA                    	mov	dx, di
  7089 00002938 30ED                    	xor	ch, ch
  7090 0000293A F9                      	stc
  7091 0000293B C3                      	retn
  7092                                  fefss_7:
  7093 0000293C 8B07                    	mov	ax, [bx]
  7094 0000293E 8B5702                  	mov	dx, [bx+2]
  7095                                  fefss_8:
  7096 00002941 8B0E[E870]              	mov	cx, [_i_]
  7097 00002945 C3                      	retn
  7098                                  
  7099                                  ;-----------------------------------------------------------------------------
  7100                                  
  7101                                  	; 16/02/2019
  7102                                  get_first_free_pte:
  7103                                  	; Find free partition table entry
  7104                                  	;
  7105                                  	; INPUT:
  7106                                  	;	none
  7107                                  	; OUTPUT:
  7108                                  	;	If CF = 0 -> CX = partition table entry number
  7109                                  	;	If CF = 1 -> there is not a free entry in partition table
  7110                                  
  7111 00002946 BE[E658]                	mov	si, MasterBootBuff+pTableOffset
  7112 00002949 31C9                    	xor	cx, cx
  7113                                  gffp_1:
  7114 0000294B 8A4404                  	mov	al, [si+ptFileSystemID] ; 23/02/2019
  7115                                  
  7116 0000294E 20C0                    	and	al, al
  7117 00002950 740E                    	jz	short gffp_3 ; empty
  7118                                  
  7119 00002952 80F903                  	cmp	cl, 3
  7120 00002955 7307                    	jnb	short gffp_2
  7121                                  
  7122 00002957 FEC1                    	inc	cl
  7123 00002959 83C610                  	add	si, 16 ; Partition table entry size
  7124 0000295C EBED                    	jmp	short gffp_1
  7125                                  gffp_2:
  7126                                  	; CL = 3
  7127 0000295E F9                      	stc
  7128 0000295F C3                      	retn
  7129                                  gffp_3:
  7130                                  	; CL = PTE number (0 to 3)
  7131 00002960 C3                      	retn 	
  7132                                  	
  7133                                  ;-----------------------------------------------------------------------------
  7134                                  ; 03/02/2019
  7135                                  
  7136                                  cylinders_to_sectors:
  7137                                  	; INPUT:
  7138                                  	;	ax = Cylinders (Total or partition's cylinder count)
  7139                                  	; OUTPUT:
  7140                                  	;	dx:ax = Sectors
  7141                                  
  7142 00002961 8B16[9840]              	mov	dx,[heads]
  7143 00002965 F7E2                    	mul	dx
  7144                                  		; dx:ax = Number of tracks (cylinders*heads)
  7145 00002967 8B0E[9640]              	mov	cx,[sectors]
  7146 0000296B E8D6E4                  	call	mul32
  7147                                  		; dx:ax = Number of sectors 
  7148 0000296E C3                      	retn
  7149                                  		
  7150                                  ;-----------------------------------------------------------------------------
  7151                                  ; 03/02/2019
  7152                                  
  7153                                  cylinders_to_percent:
  7154                                  
  7155                                  	; INPUT:
  7156                                  	;	bx = Number of cylinders (of partition) -dividend-
  7157                                  	;	cx = Total cylinders -divisor-
  7158                                  	; OUTPUT:
  7159                                  	;	ax = Percentage
  7160                                  
  7161                                  	;  if (cylinders_in == 0)
  7162                                  	;	 percentage_out = 0;
  7163                                  	;  else if (total_cylinders == 0)
  7164                                  	;           percentage_out = 0;
  7165                                  	;       else
  7166                                  
  7167 0000296F 09DB                    	or	bx, bx
  7168 00002971 7419                    	jz	short ctpc_6 ; ax = 0 = percentage_out 
  7169                                  ctpc_1:
  7170 00002973 09C9                    	or	cx, cx
  7171 00002975 7415                    	jz	short ctpc_6
  7172                                  
  7173 00002977 B86400                  	mov	ax, 100
  7174 0000297A F7E3                    	mul	bx ; [cylinders_in] 
  7175                                  
  7176                                  		; dx:ax = Dividend
  7177                                  
  7178 0000297C E8B7E4                  	call	div32 ; 100*cylinders_in / total_cylinders
  7179                                  		; DX:AX = Quotient
  7180                                  		; BX = Remainder
  7181                                  
  7182                                  	; ax = percentage_out	
  7183                                  
  7184 0000297F 39CB                    	cmp	bx, cx	; is remainder >= total_cylinders/2 ?
  7185 00002981 7201                    	jb	short ctpc_5 ; No. 
  7186                                  ctpc_4:
  7187 00002983 40                      	inc	ax
  7188                                  ctpc_5:
  7189 00002984 83F864                  	cmp	ax, 100
  7190 00002987 7603                    	jbe	short ctpc_6
  7191 00002989 B86400                  	mov	ax, 100
  7192                                  ctpc_6:
  7193 0000298C C3                      	retn
  7194                                  
  7195                                  ;-----------------------------------------------------------------------------
  7196                                  ; 04/02/2019
  7197                                  
  7198                                  display_partition_table:
  7199                                  
  7200                                  	; INPUT:
  7201                                  	;	al = 0 for MBR
  7202                                  	;	   = 5 for EBR (logical drives in extended partition)
  7203                                  	; OUTPUT:
  7204                                  	;	none
  7205                                  
  7206                                  ;pt_positions:
  7207                                  n_pos	equ 30 ; 1 byte	
  7208                                  
  7209 0000298D A2[F070]                	mov	[_e_], al	
  7210                                  
  7211                                  	; clear screen
  7212 00002990 B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
  7213 00002993 CD10                    	int	10h
  7214                                  
  7215 00002995 803E[F070]05            	cmp	byte [_e_], 5
  7216 0000299A 7507                    	jne	short dpt_1
  7217                                  dpt_0:
  7218 0000299C BD[9271]                	mov	bp, ext_table_boot_ind
  7219 0000299F B045                    	mov	al, 'E'
  7220 000029A1 EB05                    	jmp	short dpt_4
  7221                                  dpt_1:
  7222 000029A3 BD[4671]                	mov	bp, part_table_boot_ind
  7223 000029A6 B04D                    	mov	al, 'M'
  7224                                  dpt_4:
  7225 000029A8 BE[8E59]                	mov	si, p_table_header
  7226 000029AB 88441E                  	mov	[si+n_pos], al
  7227 000029AE E884F4                         	call 	print_msg
  7228                                     
  7229 000029B1 31DB                    	xor	bx, bx
  7230 000029B3 891E[E870]              	mov	[_i_], bx
  7231                                  dpt_5:
  7232 000029B7 FE06[E870]              	inc	byte [_i_]
  7233                                  
  7234                                  	; BX = partition entry (0 to 3)
  7235                                  	; BP = partition table structure address
  7236                                  
  7237 000029BB E86600                  	call	display_pt_entry  ; display partition table row
  7238                                  
  7239 000029BE 8B1E[E870]              	mov	bx, [_i_] 
  7240                                  	
  7241 000029C2 80FB04                  	cmp	bl, 4
  7242 000029C5 72F0                    	jb	short dpt_5
  7243                                  
  7244 000029C7 BE[CF5A]                	mov	si, p_table_footer
  7245 000029CA E868F4                         	call 	print_msg
  7246                                  
  7247                                  	; 27/02/2019
  7248 000029CD BF[7C56]                	mov	di, str_disk_sectors
  7249                                  
  7250 000029D0 803E[F070]05            	cmp	byte [_e_], 5
  7251 000029D5 741D                    	je	short dpt_9 
  7252                                  
  7253                                  	; display total disk sectors
  7254                                  
  7255                                  	;mov	di, str_disk_sectors
  7256                                  
  7257                                  	;cmp	byte [di], '0'
  7258                                  	;jnb	short dpt_8	
  7259                                  
  7260 000029D7 A1[886E]                        mov	ax, [total_sectors]
  7261 000029DA 8B16[8A6E]                      mov	dx, [total_sectors+2]
  7262                                  
  7263 000029DE E82200                  	call	dpt_10
  7264                                  dpt_8:
  7265 000029E1 BE[6656]                	mov	si, msg_disk_sectors
  7266                                  dpt_11:
  7267 000029E4 E84EF4                  	call	print_msg
  7268                                  
  7269 000029E7 BE[7C56]                	mov	si, str_disk_sectors
  7270 000029EA E848F4                  	call	print_msg
  7271                                  
  7272 000029ED BE[5056]                	mov	si, CRLF
  7273 000029F0 E842F4                  	call	print_msg
  7274                                  
  7275 000029F3 C3                      	retn
  7276                                  
  7277                                  dpt_9:
  7278                                  	; display extended partition size
  7279                                  
  7280 000029F4 A1[E070]                	mov	ax, [ep_Size]
  7281 000029F7 8B16[E270]                      mov	dx, [ep_Size+2]
  7282                                  
  7283 000029FB E80500                  	call	dpt_10
  7284                                  
  7285 000029FE BE[8456]                	mov	si, msg_ep_size
  7286 00002A01 EBE1                    	jmp	short dpt_11
  7287                                  
  7288                                  dpt_10:
  7289 00002A03 89E6                    	mov	si, sp
  7290 00002A05 B90A00                  	mov	cx, 10
  7291                                  dpt_6:
  7292 00002A08 E82BE4                  	call	div32
  7293                                  	
  7294 00002A0B 80C330                  	add	bl, '0'
  7295 00002A0E 53                      	push	bx
  7296 00002A0F 21C0                    	and	ax, ax
  7297 00002A11 75F5                    	jnz	short dpt_6
  7298 00002A13 21D2                    	and	dx, dx
  7299 00002A15 75F1                    	jnz	short dpt_6
  7300                                  
  7301 00002A17 29E6                    	sub	si, sp
  7302 00002A19 D1EE                    	shr	si, 1
  7303                                  dpt_7:
  7304 00002A1B 58                      	pop	ax
  7305 00002A1C AA                      	stosb
  7306 00002A1D 4E                      	dec	si
  7307 00002A1E 75FB                    	jnz	short dpt_7
  7308                                  
  7309 00002A20 30C0                    	xor	al, al
  7310 00002A22 AA                      	stosb
  7311                                  
  7312                                  	; 27/02/2019
  7313 00002A23 C3                      	retn
  7314                                  
  7315                                  ;-----------------------------------------------------------------------------
  7316                                  ; 04/02/2019
  7317                                  
  7318                                  struc ptbl
  7319                                  
  7320 00000000 ??                      .boot_ind:	resb 1
  7321 00000001 ??                      .start_head:	resb 1
  7322 00000002 ??                      .start_sector:	resb 1
  7323 00000003 ????                    .start_cyl:	resw 1
  7324 00000005 ??                      .sys_id:	resb 1
  7325 00000006 ??                      .end_head:	resb 1
  7326 00000007 ??                      .end_sector:	resb 1
  7327 00000008 ????                    .end_cyl:	resw 1
  7328 0000000A ????                    .rel_sec_lw:	resw 1
  7329 0000000C ????                    .rel_sec_hw:	resw 1
  7330 0000000E ????                    .num_sec_lw:	resw 1
  7331 00000010 ????                    .num_sec_hw:	resw 1	
  7332                                  .size:
  7333                                  
  7334                                  endstruc
  7335                                  
  7336                                  display_pt_entry:
  7337                                  
  7338                                  	; INPUT:
  7339                                  	;	bl = partition entry
  7340                                  	;	bh = 0
  7341                                  	;	bp = partition table structure address
  7342                                  	; OUTPUT:
  7343                                  	;	none
  7344                                  
  7345                                  ;pt_positions:
  7346                                  p_pos	equ 7  ; 1 byte	hdi
  7347                                  s_pos	equ 9  ; 2+1 byte
  7348                                  bh_pos	equ 13 ; 2+1 bytes
  7349                                  bs_pos	equ 17 ; 2+1 bytes
  7350                                  bc_pos	equ 21 ; 2+1 bytes
  7351                                  fs_pos  equ 25 ; 2+1 bytes
  7352                                  eh_pos  equ 29 ; 2+1 bytes
  7353                                  es_pos	equ 33 ; 2+1 bytes
  7354                                  ec_pos	equ 37 ; 2+1 bytes
  7355                                  rs_pos	equ 42 ; 7 bytes
  7356                                  ns_pos	equ 52 ; 7 bytes
  7357                                  fsx_pos equ 61 ; 14 bytes
  7358                                  
  7359 00002A24 55                      	push	 bp ; 23/02/2019
  7360                                  
  7361 00002A25 08DB                    	or	bl, bl
  7362 00002A27 7406                    	jz	short dpte_0
  7363                                  
  7364                                  	;xor	bh, bh
  7365 00002A29 B012                    	mov	al, ptbl.size ; 18
  7366 00002A2B F6E3                    	mul	bl
  7367 00002A2D 01C5                    	add	bp, ax
  7368                                  dpte_0:
  7369 00002A2F 807E0500                	cmp	byte [bp+ptbl.sys_id], 0
  7370 00002A33 0F860601                	jna	dpte_9
  7371                                  
  7372 00002A37 B768                    	mov	bh, 'h'
  7373                                  
  7374 00002A39 BE[F270]                	mov	si, pte_row
  7375                                  
  7376                                  	; clear partition table display buffer/row
  7377 00002A3C 89F7                    	mov	di, si
  7378 00002A3E B92800                  	mov	cx, 40
  7379 00002A41 B82020                  	mov	ax, 2020h
  7380 00002A44 F3AB                    	rep	stosw
  7381                                  
  7382 00002A46 88D8                    	mov	al, bl
  7383 00002A48 0431                    	add	al, '1'
  7384 00002A4A 884407                  	mov	[si+p_pos], al  ; partition number '1' to '4'
  7385                                  
  7386                                  	; partition status, type and CHS parameters
  7387                                  	; (as hexadecimal number)
  7388                                  
  7389                                  	;mov	al, [bp+ptbl.boot_ind]
  7390 00002A4D 8A4600                  	mov	al, [bp]
  7391 00002A50 E881F4                  	call	byte_to_hex
  7392                                  
  7393 00002A53 894409                  	mov	[si+s_pos], ax
  7394 00002A56 887C0B                  	mov	[si+s_pos+2], bh ; 'h'
  7395                                  
  7396 00002A59 8A4601                  	mov	al, [bp+ptbl.start_head]
  7397 00002A5C E875F4                  	call	byte_to_hex
  7398                                  
  7399 00002A5F 89440D                  	mov	[si+bh_pos], ax
  7400 00002A62 887C0F                  	mov	[si+bh_pos+2], bh ; 'h'
  7401                                  
  7402 00002A65 8B4E03                  	mov	cx, [bp+ptbl.start_cyl]
  7403 00002A68 C0E506                  	shl	ch, 6
  7404 00002A6B 8A4602                  	mov	al, [bp+ptbl.start_sector]
  7405 00002A6E 08E8                    	or	al, ch
  7406 00002A70 E861F4                  	call	byte_to_hex
  7407                                  
  7408 00002A73 894411                  	mov	[si+bs_pos], ax
  7409 00002A76 887C13                  	mov	[si+bs_pos+2], bh ; 'h'
  7410                                  
  7411                                  	;mov	al, [bp+ptbl.start_cyl]
  7412 00002A79 88C8                    	mov	al, cl
  7413 00002A7B E856F4                  	call	byte_to_hex
  7414                                  
  7415 00002A7E 894415                  	mov	[si+bc_pos], ax
  7416 00002A81 887C17                  	mov	[si+bc_pos+2], bh ; 'h'
  7417                                  
  7418 00002A84 8A4605                  	mov	al, [bp+ptbl.sys_id]
  7419 00002A87 E84AF4                  	call	byte_to_hex
  7420                                  
  7421 00002A8A 894419                  	mov	[si+fs_pos], ax
  7422 00002A8D 887C1B                  	mov	[si+fs_pos+2], bh ; 'h'
  7423                                  
  7424 00002A90 8A4606                  	mov	al, [bp+ptbl.end_head]
  7425 00002A93 E83EF4                  	call	byte_to_hex
  7426                                  
  7427 00002A96 89441D                  	mov	[si+eh_pos], ax
  7428 00002A99 887C1F                  	mov	[si+eh_pos+2], bh ; 'h'
  7429                                  
  7430 00002A9C 8B4E08                  	mov	cx, [bp+ptbl.end_cyl]
  7431 00002A9F C0E506                  	shl	ch, 6
  7432 00002AA2 8A4607                  	mov	al, [bp+ptbl.end_sector]
  7433 00002AA5 08E8                    	or	al, ch
  7434 00002AA7 E82AF4                  	call	byte_to_hex
  7435                                  
  7436 00002AAA 894421                  	mov	[si+es_pos], ax
  7437 00002AAD 887C23                  	mov	[si+es_pos+2], bh ; 'h'
  7438                                  
  7439                                  	;mov	al, [bp+ptbl.end_cyl]
  7440 00002AB0 88C8                    	mov	al, cl
  7441 00002AB2 E81FF4                  	call	byte_to_hex
  7442                                  
  7443 00002AB5 894425                  	mov	[si+ec_pos], ax
  7444 00002AB8 887C27                  	mov	[si+ec_pos+2], bh ; 'h'
  7445                                  
  7446                                  	; relative (start) sector address (lba)
  7447                                  	; (as decimal number)
  7448                                  
  7449 00002ABB 8B460A                          mov	ax, [bp+ptbl.rel_sec_lw]
  7450 00002ABE 8B560C                          mov	dx, [bp+ptbl.rel_sec_hw]
  7451                                  
  7452 00002AC1 89E7                    	mov	di, sp
  7453 00002AC3 B90A00                  	mov	cx, 10
  7454                                  dpte_1:
  7455 00002AC6 E86DE3                  	call	div32
  7456                                  	
  7457 00002AC9 80C330                  	add	bl, '0'
  7458 00002ACC 53                      	push	bx
  7459 00002ACD 21C0                    	and	ax, ax
  7460 00002ACF 75F5                    	jnz	short dpte_1
  7461 00002AD1 21D2                    	and	dx, dx
  7462 00002AD3 75F1                    	jnz	short dpte_1
  7463                                  
  7464 00002AD5 8D5C31                  	lea	bx, [si+rs_pos+7]
  7465                                  
  7466 00002AD8 29E7                    	sub	di, sp
  7467 00002ADA D1EF                    	shr	di, 1
  7468 00002ADC 29FB                    	sub	bx, di	
  7469                                  dpte_2:
  7470 00002ADE 58                      	pop	ax
  7471 00002ADF 8807                    	mov	[bx], al
  7472 00002AE1 4F                      	dec	di
  7473 00002AE2 7403                    	jz	short dpte_3
  7474                                  	
  7475 00002AE4 43                      	inc	bx
  7476 00002AE5 EBF7                    	jmp	short dpte_2
  7477                                  
  7478                                  dpte_3:
  7479                                  	; number of sectors)
  7480                                  	; (as decimal number)
  7481                                  
  7482 00002AE7 8B460E                          mov	ax, [bp+ptbl.num_sec_lw]
  7483 00002AEA 8B5610                          mov	dx, [bp+ptbl.num_sec_hw]
  7484                                  
  7485 00002AED 89E7                    	mov	di, sp
  7486                                  	;mov	cx, 10
  7487                                  dpte_4:
  7488 00002AEF E844E3                  	call	div32
  7489                                  	
  7490 00002AF2 80C330                  	add	bl, '0'
  7491 00002AF5 53                      	push	bx
  7492 00002AF6 21C0                    	and	ax, ax
  7493 00002AF8 75F5                    	jnz	short dpte_4
  7494 00002AFA 21D2                    	and	dx, dx
  7495 00002AFC 75F1                    	jnz	short dpte_4
  7496                                  
  7497 00002AFE 8D5C3B                  	lea	bx, [si+ns_pos+7]
  7498                                  
  7499 00002B01 29E7                    	sub	di, sp
  7500 00002B03 D1EF                    	shr	di, 1
  7501 00002B05 29FB                    	sub	bx, di	
  7502                                  dpte_5:
  7503 00002B07 58                      	pop	ax
  7504 00002B08 8807                    	mov	[bx], al
  7505 00002B0A 4F                      	dec	di
  7506 00002B0B 7403                    	jz	short dpte_6
  7507                                  	
  7508 00002B0D 43                      	inc	bx
  7509 00002B0E EBF7                    	jmp	short dpte_5
  7510                                  dpte_6:
  7511                                  	; set file system name
  7512                                  
  7513 00002B10 8A4605                  	mov	al, [bp+ptbl.sys_id]
  7514 00002B13 BF[B641]                	mov	di, valid_partitions
  7515 00002B16 B91300                  	mov	cx, 19
  7516 00002B19 F2AE                    	repnz	scasb
  7517 00002B1B 7405                    	jz	short dpte_7
  7518 00002B1D B8[A841]                	mov	ax, FS_OTHERS	 
  7519 00002B20 EB0C                    	jmp	short dpte_8
  7520                                  dpte_7:
  7521 00002B22 81EF[B741]              	sub	di, valid_partitions + 1
  7522 00002B26 B80E00                  	mov	ax, 14
  7523 00002B29 F7E7                    	mul	di
  7524 00002B2B 05[9E40]                	add	ax, FileSys_Names
  7525                                  dpte_8:
  7526 00002B2E 8D7C3D                  	lea	di, [si+fsx_pos]
  7527 00002B31 89C6                    	mov	si, ax
  7528 00002B33 B107                    	mov	cl, 7
  7529 00002B35 F3A5                    	rep	movsw
  7530                                  
  7531 00002B37 BE[F270]                	mov	si, pte_row
  7532 00002B3A E8F8F2                  	call	print_msg
  7533                                  dpte_9:
  7534 00002B3D 5D                      	pop	bp ; 23/02/2019
  7535                                  	
  7536 00002B3E C3                      	retn
  7537                                  
  7538                                  ;-----------------------------------------------------------------------------
  7539                                  ; 24/02/2019
  7540                                  
  7541                                  partition_table_fix:
  7542                                  	; DELETE or EXIT option for Invalid Partition Table Entry
  7543                                  	; INPUT: 
  7544                                  	;	DS:SI = PTE address in MBR buffer
  7545                                  	
  7546 00002B3F 56                      	push	si  ; save PTE address
  7547                                  
  7548 00002B40 89F0                    	mov	ax, si
  7549 00002B42 2D[E658]                	sub	ax, MasterBootBuff+446
  7550 00002B45 C0E804                  	shr	al, 4 ; / 16 
  7551 00002B48 0431                    	add	al, '1'
  7552 00002B4A A2[9660]                	mov	[inv_pte_num], al
  7553                                  
  7554                                  	; DS:SI = PTE address in MBR buffer
  7555 00002B4D E8E6F7                  	call	show_selected_partition
  7556                                  
  7557                                  	;mov	si, CRLF
  7558                                  	;call	print_msg
  7559                                  
  7560                                  	; Warning message...
  7561                                  
  7562 00002B50 BE[7260]                	mov	si, msg_inv_pte
  7563 00002B53 E8DFF2                  	call	print_msg
  7564                                  
  7565 00002B56 5F                      	pop	di  ; restore PTE address
  7566                                  ptf_0:	
  7567 00002B57 30E4                    	xor	ah, ah
  7568 00002B59 CD16                    	int	16h
  7569                                  
  7570 00002B5B 3C0D                    	cmp	al, 13
  7571 00002B5D 7406                    	je	short ptf_1
  7572                                  
  7573 00002B5F 3C1B                    	cmp	al, 27
  7574 00002B61 75F4                    	jne	short ptf_0
  7575                                  
  7576 00002B63 F9                      	stc
  7577 00002B64 C3                      	retn
  7578                                  ptf_1:
  7579                                  	; Clear that (invalid) PTE
  7580 00002B65 31C0                    	xor	ax, ax	
  7581 00002B67 B90800                  	mov	cx, 8
  7582 00002B6A F3AB                    	rep	stosw
  7583                                  
  7584                                  	; Clear screen
  7585 00002B6C B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
  7586 00002B6F CD10                    	int	10h
  7587                                  
  7588 00002B71 C3                      	retn
  7589                                  
  7590                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7591                                  ; Display (& Edit) EXTENDED (DOS) Partition Table
  7592                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  7593                                  ; 28/02/2019
  7594                                  
  7595                                  display_extended_pt:
  7596 00002B72 B005                    	mov	al, 5 ; extended partition (logical drives)
  7597 00002B74 E816FE                  	call	display_partition_table
  7598                                  
  7599 00002B77 BE[6A62]                	mov	si, ebr_editing_options
  7600 00002B7A E8B8F2                  	call	print_msg
  7601                                  
  7602 00002B7D BE[795E]                	mov	si, enter_opt_num_cancel_msg
  7603 00002B80 E8B2F2                  	call	print_msg
  7604                                  
  7605 00002B83 BE[5056]                	mov	si, CRLF
  7606 00002B86 E8ACF2                  	call	print_msg
  7607                                  dept_1:
  7608 00002B89 30E4                    	xor	ah, ah
  7609 00002B8B CD16                    	int	16h
  7610                                  
  7611 00002B8D 3C30                    	cmp	al, '0'
  7612 00002B8F 740C                    	je	short dept_2
  7613                                  
  7614 00002B91 3C31                    	cmp	al, '1'
  7615 00002B93 7467                    	je	short edit_ext_table_create
  7616 00002B95 3C32                    	cmp	al, '2'
  7617 00002B97 7407                    	je	short edit_ext_table_delete
  7618                                  		
  7619 00002B99 3C1B                    	cmp	al, 27 ; ESCape
  7620 00002B9B 75EC                    	jne	short dept_1
  7621                                  dept_2:
  7622 00002B9D E977D8                  	jmp	A_48
  7623                                  
  7624                                  edit_ext_table_delete:
  7625                                  	; 28/02/2019
  7626 00002BA0 B005                    	mov	al, 5 ; extended partition (logical drives)
  7627 00002BA2 E8E8FD                  	call	display_partition_table
  7628                                  
  7629 00002BA5 BE[E962]                	mov	si, msg_delete_ldd_q
  7630 00002BA8 E88AF2                  	call	print_msg
  7631                                  
  7632                                  	;mov	si, CRLF
  7633                                  	;call	print_msg
  7634                                  eetd_1:
  7635 00002BAB 30E4                    	xor	ah, ah
  7636 00002BAD CD16                    	int	16h
  7637                                  
  7638 00002BAF 3C1B                    	cmp	al, 27
  7639 00002BB1 7410                    	je	short eetd_2
  7640                                  
  7641 00002BB3 24DF                    	and	al, 0DFh
  7642 00002BB5 3C59                    	cmp	al, 'Y'
  7643 00002BB7 7412                    	je	short eetd_yes
  7644 00002BB9 3C4E                    	cmp	al, 'N'
  7645 00002BBB 75EE                    	jne	short eetd_1
  7646                                  eetd_no:
  7647 00002BBD BE[F95D]                	mov	si, msg_NO ;  Write 'NO' (it may be shown for a moment)
  7648 00002BC0 E872F2                  	call	print_msg
  7649                                  eetd_2:	
  7650 00002BC3 BE[5056]                	mov	si, CRLF  ; Next line
  7651 00002BC6 E86CF2                  	call	print_msg
  7652 00002BC9 EBA7                    	jmp	short display_extended_pt
  7653                                  eetd_yes:
  7654 00002BCB BE[F35D]                	mov	si, msg_YES ;  Write 'YES' (it may be shown for a moment)
  7655 00002BCE E864F2                  	call	print_msg
  7656 00002BD1 BE[5056]                	mov	si, CRLF  ; Next line
  7657 00002BD4 E85EF2                  	call	print_msg
  7658 00002BD7 E8F205                  	call	delete_logical_drives
  7659 00002BDA 803E[D06E]00            	cmp	byte [ldrives], 0
  7660 00002BDF 7791                    	ja	short display_extended_pt
  7661 00002BE1 E933D8                  	jmp	A_48
  7662                                  
  7663                                  ;-----------------------------------------------------------------------------
  7664                                  
  7665                                  eetc_2:
  7666 00002BE4 BE[4F63]                	mov	si, msg_create_ldd_max_error
  7667                                  eetc_10:
  7668 00002BE7 E84BF2                  	call	print_msg
  7669 00002BEA BE[0957]                	mov	si, msg_press_any_key
  7670 00002BED E845F2                  	call	print_msg
  7671 00002BF0 30E4                    	xor	ah, ah
  7672 00002BF2 CD16                    	int	16h
  7673 00002BF4 E97BFF                  	jmp	display_extended_pt
  7674                                  	
  7675                                  	; 05/03/2019
  7676                                  eetc_9:
  7677 00002BF7 BE[B865]                	mov	si, msg_c_ldd_nofspc_error
  7678 00002BFA EBEB                    	jmp	short eetc_10
  7679                                  
  7680                                  ;-----------------------------------------------------------------------------
  7681                                  ; 01/03/2019
  7682                                  
  7683                                  edit_ext_table_create:
  7684                                  
  7685                                  ; Create Method: ; 04/03/2019
  7686                                  ;LDD 1 <- LDD_START0, ebr 1st entry <- MBR (extended partition) - EBR 0
  7687                                  ;LDD 2 <- LDD_START1, ebr 2nd entry <- EBR 1
  7688                                  ;LDD 3 <- LDD_START2, ebr 2nd entry <- EBR 2
  7689                                  ;LDD 4 <- LDD_START3, ebr 2nd entry <- EBR 3
  7690                                  
  7691                                  	; 01/03/2019
  7692 00002BFC 803E[9171]00            	cmp	byte [epnumber], 0 ; check extended partition
  7693 00002C01 0F86E3E3                	jna	B_55		; cancel with error message
  7694                                  
  7695                                  	; 05/03/2019
  7696 00002C05 E8A102                  	call	check_ext_free_space
  7697 00002C08 72ED                    	jc	eetc_9	; error, no free space in extented partition
  7698                                  
  7699 00002C0A 803E[D06E]04            	cmp	byte [ldrives], 4
  7700 00002C0F 73D3                    	jnb	eetc_2	; error, write program limit message
  7701                                  
  7702                                  edit_ext_table_create_x: ; 02/03/2019
  7703                                  
  7704                                  	; Get logical drive size/cylinders (request) from user
  7705 00002C11 E80703                  	call	get_ldd_size
  7706 00002C14 833E[5272]01            	cmp	word [lcylinders], 1  ; at least 1 cylinder
  7707 00002C19 0F8255FF                	jb	display_extended_pt ; cancel
  7708                                  
  7709                                  	; Open hard disk image file
  7710 00002C1D BA[8159]                	mov	dx, img_file_name
  7711 00002C20 B8023D                  	mov	ax, 3D02h ; open for reading and writing
  7712 00002C23 CD21                    	int	21h
  7713 00002C25 0F82F6F1                	jc	D_02
  7714                                  
  7715 00002C29 A3[9440]                	mov	[img_file_handle], ax
  7716                                  
  7717                                  	; 03/03/2019
  7718 00002C2C A0[D06E]                	mov	al, [ldrives]
  7719                                  
  7720                                  	;cmp	byte [ldrives], 1
  7721                                  	;jnb	short eetc_3	; skip verify MBR extended partition
  7722                                  
  7723 00002C2F 20C0                    	and	al, al
  7724 00002C31 7578                    	jnz	short eetc_3
  7725                                  
  7726 00002C33 31ED                    	xor	bp, bp
  7727                                  
  7728                                  	; Read MBR at EBR buffer
  7729                                  	;xor	ax, ax
  7730 00002C35 31D2                    	xor	dx, dx
  7731 00002C37 BB[D66E]                	mov	bx, ebr_buffer
  7732 00002C3A E846F2                  	call	read_hd_sector
  7733 00002C3D 7218                    	jc	short eetc_0
  7734                                  
  7735 00002C3F A0[9171]                	mov	al, [epnumber]
  7736 00002C42 98                      	cbw
  7737 00002C43 C0E004                  	shl	al, 4 ; * 16	
  7738 00002C46 BE[9470]                	mov	si, ebr_buffer+446
  7739 00002C49 01C6                    	add	si, ax
  7740 00002C4B BF[E658]                	mov	di, MasterBootBuff+446
  7741 00002C4E 01C7                    	add	di, ax
  7742 00002C50 B90800                  	mov	cx, 8
  7743 00002C53 F3A7                    	repe	cmpsw	; repeat comparising while cx > 0 and zf = 1
  7744 00002C55 E30C                    	jcxz	eetc_1	; Extended partition entry is not changed 
  7745                                  	; Different PTE (means there is a new extended partition) 
  7746                                  eetc_0:
  7747                                  	; Write current MBR (with modified PT)
  7748 00002C57 BB[2857]                	mov	bx, MasterBootBuff
  7749 00002C5A 31C0                    	xor	ax, ax
  7750                                  	; 25/10/2020
  7751                                  	;xor	dx, dx
  7752 00002C5C E8E5F1                  	call	write_hd_sector
  7753 00002C5F 0F82B2F1                	jc	D_01 ; ! display error msg and then exit !
  7754                                  eetc_1:
  7755                                  	; clear	EBR buffer
  7756 00002C63 BF[D66E]                	mov	di, ebr_buffer
  7757 00002C66 31C0                    	xor	ax, ax
  7758 00002C68 B9FF00                  	mov	cx, 255
  7759 00002C6B F3AB                    	rep	stosw
  7760 00002C6D C70555AA                	mov	word [di], 0AA55h
  7761                                  
  7762                                  	; Set logical dos drive parameters in it's EBR
  7763 00002C71 BF[9470]                	mov	di, ebr_buffer+446
  7764                                  
  7765 00002C74 8B0E[9640]              	mov	cx, [sectors]
  7766 00002C78 29DB                    	sub	bx, bx ; 0
  7767 00002C7A A1[D870]                	mov	ax, [ep_StartSector]
  7768 00002C7D 8B16[DA70]              	mov	dx, [ep_StartSector+2]
  7769                                  
  7770                                  	; 03/03/2019
  7771                                  	; set partition start address & size
  7772                                  
  7773 00002C81 A3[3072]                	mov	[ldd_start], ax
  7774 00002C84 8916[3272]              	mov	[ldd_start+2], dx
  7775                                  
  7776                                  	; 04/03/2019
  7777 00002C88 01C8                    	add	ax, cx
  7778 00002C8A 11DA                    	adc	dx, bx
  7779                                  
  7780 00002C8C 52                      	push	dx
  7781 00002C8D 50                      	push	ax	
  7782                                  
  7783 00002C8E A0[9840]                	mov	al, [heads]
  7784 00002C91 F626[9640]              	mul	byte [sectors]
  7785 00002C95 F726[5272]              	mul	word [lcylinders]
  7786                                  
  7787 00002C99 A3[4072]                	mov	[ldd_size], ax
  7788 00002C9C 8916[4272]              	mov	[ldd_size+2], dx
  7789                                  
  7790 00002CA0 894D08                  	mov	[di+ptStartSector], cx
  7791 00002CA3 895D0A                  	mov	[di+ptStartSector+2], bx
  7792                                  
  7793 00002CA6 58                      	pop	ax
  7794 00002CA7 5A                      	pop	dx
  7795                                  
  7796 00002CA8 E9DB00                  	jmp	eetc_4
  7797                                  
  7798                                  eetc_3:
  7799                                  	; [ldrives] >= 1
  7800                                  	; Read EBR
  7801                                  	;mov	al, [ldrives]
  7802                                  	;;xor	ah, ah
  7803 00002CAB C0E002                  	shl	al, 2
  7804 00002CAE 89C5                    	mov	bp, ax
  7805                                  
  7806                                  	; 03/03/2019
  7807 00002CB0 8B86[2C72]              	mov	ax, [bp+ldd_start-4]
  7808 00002CB4 8B96[2E72]              	mov	dx, [bp+ldd_start-2]
  7809 00002CB8 BB[D66E]                	mov	bx, ebr_buffer
  7810 00002CBB E8C5F1                  	call	read_hd_sector
  7811 00002CBE 0F8253F1                	jc	D_01 ; ! display error msg and then exit !
  7812                                  
  7813                                  	; 04/03/2019
  7814 00002CC2 BE[A470]                	mov	si, ebr_buffer+446+16 ; 2nd entry (next EBR)
  7815                                  	
  7816                                  	; 03/03/2019
  7817 00002CC5 8B86[2C72]              	mov	ax, [bp+ldd_start-4]
  7818 00002CC9 8B96[2E72]              	mov	dx, [bp+ldd_start-2]
  7819 00002CCD 0386[3C72]              	add	ax, [bp+ldd_size-4]
  7820 00002CD1 1396[3E72]              	adc	dx, [bp+ldd_size-2]
  7821                                  
  7822 00002CD5 8B0E[D870]              	mov	cx, [ep_StartSector]
  7823 00002CD9 8B1E[DA70]              	mov	bx, [ep_StartSector+2]
  7824                                  
  7825 00002CDD 8986[3072]              	mov	[bp+ldd_start], ax
  7826 00002CE1 8996[3272]              	mov	[bp+ldd_start+2], dx
  7827                                  
  7828 00002CE5 52                      	push	dx
  7829 00002CE6 50                      	push	ax
  7830                                  	
  7831 00002CE7 29C8                    	sub	ax, cx
  7832 00002CE9 19DA                    	sbb	dx, bx
  7833                                  
  7834 00002CEB 894408                  	mov	[si+ptStartSector], ax
  7835 00002CEE 89540A                  	mov	[si+ptStartSector+2], dx
  7836                                  
  7837 00002CF1 A0[9840]                	mov	al, [heads]
  7838 00002CF4 F626[9640]              	mul	byte [sectors]
  7839 00002CF8 F726[5272]              	mul	word [lcylinders]
  7840                                  
  7841 00002CFC 8986[4072]              	mov	[bp+ldd_size], ax
  7842 00002D00 8996[4272]              	mov	[bp+ldd_size+2], dx
  7843                                  
  7844 00002D04 89440C                   	mov	[si+ptSectors], ax
  7845 00002D07 89540E                  	mov	[si+ptSectors+2], dx
  7846                                  
  7847 00002D0A 58                      	pop	ax
  7848 00002D0B 5A                      	pop	dx
  7849                                  
  7850                                  	; calculate CHS from LBA
  7851 00002D0C E8DD01                  	call	lba_to_chs
  7852                                  		; ax = cylinder
  7853                                  		; dl = sector
  7854                                  		; dh = head
  7855                                  
  7856 00002D0F C60400                  	mov	byte [si+ptBootable], 0
  7857 00002D12 887401                  	mov	[si+ptBeginHead], dh
  7858 00002D15 884403                  	mov	[si+ptBeginCylinder], al
  7859 00002D18 C0E406                  	shl	ah, 6
  7860 00002D1B 08E2                    	or	dl, ah		
  7861 00002D1D 885402                  	mov	[si+ptBeginSector], dl
  7862                                  
  7863                                   	;mov	ax, [si+ptSectors]
  7864                                  	;mov	dx, [si+ptSectors+2]
  7865 00002D20 8B86[4072]               	mov	ax, [bp+ldd_size]
  7866 00002D24 8B96[4272]              	mov	dx, [bp+ldd_size+2]
  7867 00002D28 83E801                  	sub	ax, 1
  7868 00002D2B 83DA00                  	sbb	dx, 0
  7869 00002D2E 0386[3072]              	add	ax, [bp+ldd_start]
  7870 00002D32 1396[3272]              	adc	dx, [bp+ldd_start+2]
  7871                                  		; dx:ax = end sector
  7872                                  
  7873 00002D36 E8B301                  	call	lba_to_chs
  7874                                  		; ax = cylinder
  7875                                  		; dl = sector
  7876                                  		; dh = head
  7877                                  		
  7878 00002D39 C6440405                	mov	byte [si+ptFileSystemID], 5 ; EXTENDED
  7879 00002D3D 887405                  	mov	[si+ptEndHead], dh
  7880 00002D40 884407                  	mov	[si+ptEndCylinder], al
  7881 00002D43 C0E406                  	shl	ah, 6
  7882 00002D46 08D4                    	or	ah, dl	
  7883 00002D48 886406                  	mov	[si+ptEndSector], ah
  7884                                  
  7885                                  	; Write EBR
  7886 00002D4B 8B86[2C72]              	mov	ax, [bp+ldd_start-4]
  7887 00002D4F 8B96[2E72]              	mov	dx, [bp+ldd_start-2]
  7888 00002D53 BB[D66E]                	mov	bx, ebr_buffer
  7889 00002D56 E8EBF0                  	call	write_hd_sector
  7890 00002D59 0F82B8F0                	jc	D_01 ; ! display error msg and then exit !
  7891                                  
  7892                                  	; clear	EBR buffer
  7893 00002D5D BF[D66E]                	mov	di, ebr_buffer
  7894 00002D60 31C0                    	xor	ax, ax
  7895 00002D62 B9FF00                  	mov	cx, 255
  7896 00002D65 F3AB                    	rep	stosw
  7897 00002D67 C70555AA                	mov	word [di], 0AA55h
  7898                                  
  7899 00002D6B BF[9470]                	mov	di, ebr_buffer+446 ; 1st entry points to LDD
  7900                                  
  7901 00002D6E 8B0E[9640]              	mov	cx, [sectors]
  7902 00002D72 29DB                    	sub	bx, bx ; 0
  7903 00002D74 8B86[3072]              	mov	ax, [bp+ldd_start]
  7904 00002D78 8B96[3272]              	mov	dx, [bp+ldd_start+2]
  7905 00002D7C 01C8                    	add	ax, cx
  7906 00002D7E 11DA                    	adc	dx, bx
  7907 00002D80 894D08                  	mov	[di+ptStartSector], cx
  7908 00002D83 895D0A                  	mov	[di+ptStartSector+2], bx
  7909                                  eetc_4:	
  7910                                  	; calculate CHS from LBA
  7911                                  
  7912 00002D86 E86301                  	call	lba_to_chs
  7913                                  		; ax = cylinder
  7914                                  		; dl = sector
  7915                                  		; dh = head
  7916                                  
  7917                                  	;mov	byte [di+ptBootable], 0
  7918 00002D89 887501                  	mov	[di+ptBeginHead], dh
  7919 00002D8C 884503                  	mov	[di+ptBeginCylinder], al
  7920 00002D8F 88E3                    	mov	bl, ah
  7921 00002D91 C0E306                  	shl	bl, 6
  7922 00002D94 08DA                    	or	dl, bl		
  7923 00002D96 885502                  	mov	[di+ptBeginSector], dl
  7924                                  
  7925 00002D99 0306[5272]              	add	ax, [lcylinders]
  7926 00002D9D 48                      	dec	ax ; end cylinder
  7927 00002D9E 89C3                    	mov	bx, ax
  7928                                  		
  7929                                  	;mov	[di+ptFileSystemID], 0
  7930 00002DA0 8B0E[9840]              	mov	cx, [heads]
  7931 00002DA4 FEC9                    	dec	cl
  7932 00002DA6 884D05                  	mov	[di+ptEndHead], cl
  7933 00002DA9 884507                  	mov	[di+ptEndCylinder], al
  7934 00002DAC 8B16[9640]              	mov	dx, [sectors]
  7935 00002DB0 C0E406                  	shl	ah, 6
  7936 00002DB3 08D4                    	or	ah, dl	
  7937 00002DB5 886506                  	mov	[di+ptEndSector], ah
  7938                                  	
  7939                                  	; 02/03/2019
  7940                                  	; Check unused space if it is 3rd LDD
  7941                                  	; (write message to add unused space.)
  7942                                  
  7943 00002DB8 803E[D06E]03            	cmp	byte [ldrives], 3
  7944 00002DBD 727D                    	jb	eetc_7
  7945                                  
  7946 00002DBF 89D0                    	mov	ax, dx ; sectors
  7947 00002DC1 F7E1                    	mul	cx ; * [heads] - 1
  7948                                  
  7949 00002DC3 52                      	push	dx
  7950 00002DC4 50                      	push	ax
  7951                                  
  7952 00002DC5 A0[9640]                	mov	al, [sectors]
  7953 00002DC8 F626[9840]              	mul	byte [heads]
  7954 00002DCC F7E3                    	mul	bx ; * end cylinder
  7955                                  	
  7956 00002DCE 59                      	pop	cx
  7957 00002DCF 01C8                    	add	ax, cx
  7958 00002DD1 59                      	pop	cx
  7959 00002DD2 11CA                    	adc	dx, cx	
  7960                                  
  7961                                  	; 03/03/2019
  7962 00002DD4 8B0E[9640]              	mov	cx, [sectors]
  7963 00002DD8 FEC9                    	dec	cl	; [sectors] - 1
  7964 00002DDA 01C8                    	add	ax, cx
  7965 00002DDC 83D200                  	adc	dx, 0
  7966                                  		; DX:AX = end LBA
  7967                                  	
  7968 00002DDF 8B0E[DC70]              	mov	cx, [ep_EndSector]
  7969 00002DE3 8B1E[DE70]              	mov	bx, [ep_EndSector+2]
  7970                                  
  7971 00002DE7 39DA                      	cmp	dx, bx
  7972 00002DE9 7504                    	jne	short eetc_5
  7973 00002DEB 39C8                    	cmp	ax, cx
  7974 00002DED 744D                    	je	short eetc_7 ; 05/03/2019
  7975                                  eetc_5:
  7976 00002DEF 53                      	push	bx
  7977 00002DF0 BE[8463]                	mov	si, msg_c_ldd_unused_warning
  7978 00002DF3 E83FF0                  	call	print_msg
  7979 00002DF6 5B                      	pop	bx
  7980                                  eetc_6:
  7981 00002DF7 28E4                    	sub	ah, ah
  7982 00002DF9 CD16                    	int	16h
  7983 00002DFB 3C0D                    	cmp	al, 13 ; ENTER
  7984 00002DFD 743D                    	je	short eetc_7 ; continue
  7985 00002DFF 3C1B                    	cmp	al, 27 ; ESC
  7986 00002E01 75F4                    	jne	short eetc_6
  7987                                  
  7988                                  	; 03/03/2019
  7989                                  	; change end cylinder value
  7990 00002E03 A0[9171]                	mov	al, [epnumber]
  7991 00002E06 FEC8                    	dec	al
  7992 00002E08 B412                    	mov	ah, 18  ; primary partition table structure size
  7993 00002E0A F6E4                    	mul	ah
  7994 00002E0C 89C6                    	mov	si, ax
  7995 00002E0E 8B84[4E71]              	mov	ax, [si+part_table_end_cyl]
  7996 00002E12 884507                  	mov	[di+ptEndCylinder], al
  7997 00002E15 8A84[4D71]              	mov	al, [si+part_table_end_sector]
  7998 00002E19 C0E406                  	shl	ah, 6
  7999 00002E1C 08C4                    	or	ah, al	
  8000 00002E1E 886506                  	mov	[di+ptEndSector], ah
  8001 00002E21 8A84[4C71]              	mov	al, [si+part_table_end_head]
  8002 00002E25 884505                  	mov	[di+ptEndHead], al
  8003                                  
  8004 00002E28 89C8                    	mov	ax, cx
  8005 00002E2A 89DA                    	mov	dx, bx
  8006 00002E2C 83C001                  	add	ax, 1
  8007 00002E2F 83D200                  	adc	dx, 0
  8008                                  		; dx:ax = end of ext partition + 1 
  8009 00002E32 2B86[3072]              	sub	ax, [bp+ldd_start]
  8010 00002E36 1B96[3272]              	sbb	dx, [bp+ldd_start+2]
  8011                                  		; dx:ax = new sector count of the ldd
  8012                                  	;mov	[bp+ldd_size], ax
  8013                                  	;mov	[bp+ldd_size+2], dx	
  8014 00002E3A EB08                    	jmp	short eetc_8
  8015                                  eetc_7:
  8016 00002E3C 8B86[4072]              	mov	ax, [bp+ldd_size]
  8017 00002E40 8B96[4272]              	mov	dx, [bp+ldd_size+2]
  8018                                  		; dx:ax = sector count	
  8019                                  eetc_8:
  8020 00002E44 2B06[9640]              	sub	ax, [sectors]
  8021 00002E48 83DA00                  	sbb	dx, 0	
  8022 00002E4B 89450C                  	mov	[di+ptSectors], ax
  8023 00002E4E 89550E                  	mov	[di+ptSectors+2], dx
  8024                                  
  8025                                  	; Get proper FAT type in [ldd_type]
  8026                                  	; by using DX:AX - size -
  8027 00002E51 E8AD00                  	call	size_to_fat_type
  8028                                  
  8029 00002E54 884504                  	mov	[di+ptFileSystemID], al
  8030                                  
  8031                                  	; Write current EBR (with modified PT)
  8032 00002E57 8B86[3072]              	mov	ax, [bp+ldd_start]
  8033 00002E5B 8B96[3272]              	mov	dx, [bp+ldd_start+2]
  8034 00002E5F BB[D66E]                	mov	bx, ebr_buffer
  8035 00002E62 E8DFEF                  	call	write_hd_sector
  8036 00002E65 0F82ACEF                	jc	D_01 ; ! display error msg and then exit !
  8037                                  
  8038 00002E69 A0[D06E]                	mov	al, [ldrives]
  8039 00002E6C B412                    	mov	ah, 18 ; extended partition table structure size 	
  8040 00002E6E F6E4                    	mul	ah
  8041                                  
  8042 00002E70 89C6                    	mov	si, ax
  8043 00002E72 81C6[9271]              	add	si, ext_table_boot_ind
  8044 00002E76 87F7                    	xchg	si, di
  8045                                  
  8046                                  	; set partition (logical -dos- drive) data
  8047 00002E78 A5                      	movsw	; boot indicator, beginning head
  8048 00002E79 AC                      	lodsb
  8049 00002E7A 88C4                    	mov	ah, al
  8050 00002E7C 243F                    	and	al, 3Fh
  8051 00002E7E AA                      	stosb	; beginning sector
  8052 00002E7F C0EC06                  	shr	ah, 6
  8053 00002E82 AC                      	lodsb	; beginning cylinder
  8054 00002E83 AB                      	stosw	
  8055 00002E84 A5                      	movsw	; partition id, end head
  8056 00002E85 AC                      	lodsb
  8057 00002E86 88C4                    	mov	ah, al
  8058 00002E88 243F                    	and	al, 3Fh
  8059 00002E8A AA                      	stosb	; end sector
  8060 00002E8B C0EC06                  	shr	ah, 6
  8061 00002E8E AC                      	lodsb	; end cylinder
  8062 00002E8F AB                      	stosw
  8063                                  
  8064 00002E90 A5                      	movsw	; copy start sector (LBA) and sector count
  8065 00002E91 A5                      	movsw
  8066 00002E92 A5                      	movsw
  8067 00002E93 A5                      	movsw
  8068                                  
  8069 00002E94 FE06[D06E]              	inc	byte [ldrives]
  8070                                  
  8071                                  	; Close hard disk image file
  8072                                  
  8073 00002E98 B43E                    	mov	ah, 3Eh ; close file
  8074 00002E9A 8B1E[9440]              	mov	bx, [img_file_handle]
  8075 00002E9E CD21                    	int	21h
  8076                                  
  8077 00002EA0 C706[9440]0000          	mov	word [img_file_handle], 0
  8078                                  	
  8079 00002EA6 E9C9FC                  	jmp	display_extended_pt
  8080                                  
  8081                                  ;-----------------------------------------------------------------------------
  8082                                  ; 05/03/2019
  8083                                  
  8084                                  check_ext_free_space:
  8085 00002EA9 A1[E070]                	mov	ax, [ep_Size]
  8086 00002EAC 8B16[E270]              	mov	dx, [ep_Size+2]
  8087                                  
  8088 00002EB0 8A1E[D06E]              	mov	bl, [ldrives]
  8089 00002EB4 20DB                    	and	bl, bl
  8090 00002EB6 7433                    	jz	short cefs_1
  8091 00002EB8 80FB04                  	cmp	bl, 4
  8092 00002EBB 7602                    	jna	short cefs_0
  8093 00002EBD B304                    	mov	bl, 4
  8094                                  cefs_0:
  8095 00002EBF FECB                    	dec	bl	
  8096 00002EC1 C0E302                  	shl	bl, 2 ; *4
  8097 00002EC4 30FF                    	xor	bh, bh
  8098 00002EC6 89DE                    	mov	si, bx
  8099                                  
  8100 00002EC8 8B8C[3072]              	mov	cx, [si+ldd_start]
  8101 00002ECC 8B9C[3272]              	mov	bx, [si+ldd_start+2]
  8102 00002ED0 038C[4072]              	add	cx, [si+ldd_size]
  8103 00002ED4 139C[4272]              	adc	bx, [si+ldd_size+2]
  8104                                  
  8105 00002ED8 0306[D870]              	add	ax, [ep_StartSector]
  8106 00002EDC 1316[DA70]              	adc	dx, [ep_StartSector+2]
  8107                                  
  8108 00002EE0 29C8                    	sub	ax, cx
  8109 00002EE2 19DA                    	sbb	dx, bx
  8110 00002EE4 7505                    	jnz	short cefs_1
  8111                                  	
  8112 00002EE6 09C0                    	or	ax, ax
  8113 00002EE8 7501                    	jnz	short cefs_1
  8114                                  
  8115                                  	; cf = 0 if the result not negative
  8116                                  
  8117 00002EEA F9                      	stc	
  8118                                  
  8119                                  	; cf = 1 if the result is negative or zero
  8120                                  	 
  8121                                  	; If cf = 0 -> There is free space as in DX:AX
  8122                                  	; NOTE: This calculation is unsafe if
  8123                                  	; logical dos drive count > 4 !	
  8124                                  	; (But still meaningful for creating a new ldd.
  8125                                  	;  Because a new ldd will be created only
  8126                                  	;  if ldd count < 4.)
  8127                                  cefs_1:
  8128 00002EEB C3                      	retn
  8129                                  
  8130                                  ;-----------------------------------------------------------------------------
  8131                                  ; 01/03/2019
  8132                                  
  8133                                  lba_to_chs:
  8134                                  	; INPUT:
  8135                                  	;	DX:AX = LBA address
  8136                                  	; OUTPUT:
  8137                                  	;	AX = cylinder
  8138                                  	;	DL = sector
  8139                                  	;	DH = head
  8140                                  	;
  8141                                  	; (modified registers: ax, bx, cx, dx)
  8142                                  
  8143 00002EEC 8B0E[9640]              	mov	cx, [sectors]
  8144 00002EF0 E843DF                  	call	div32
  8145 00002EF3 FEC3                    	inc	bl
  8146 00002EF5 53                      	push	bx ; BL = sector
  8147 00002EF6 8B0E[9840]              	mov	cx, [heads]
  8148 00002EFA E839DF                  	call	div32
  8149 00002EFD 5A                      	pop	dx  ; DL = sector	
  8150 00002EFE 88DE                    	mov	dh, bl ; BL = head
  8151 00002F00 C3                      	retn
  8152                                  
  8153                                  ;-----------------------------------------------------------------------------
  8154                                  ; 02/03/2019
  8155                                  
  8156                                  size_to_fat_type:
  8157                                  	; INPUT:
  8158                                  	;	DX:AX = DOS Partitition Size in sectors
  8159                                  	; OUTPUT:
  8160                                  	;	AL = Partition type/ID (FAT type)
  8161                                  
  8162 00002F01 09D2                    	or	dx, dx
  8163 00002F03 750B                    	jnz	short stft_2
  8164                                  
  8165 00002F05 3DA87F                  	cmp	ax, 32680
  8166 00002F08 7703                    	ja	short stft_1	
  8167                                  	
  8168 00002F0A B001                    	mov	al, 1	; FAT12 file system
  8169 00002F0C C3                      	retn
  8170                                  stft_1:
  8171 00002F0D B004                    	mov	al, 4	; FAT16 (< 32MB)
  8172 00002F0F C3                      	retn	
  8173                                  stft_2:
  8174 00002F10 83FA10                  	cmp	dx, 10h
  8175 00002F13 7303                    	jnb	short stft_3 ; FAT32 (CHS) file system	
  8176                                  
  8177 00002F15 B006                    	mov	al, 6	; FAT16 (>= 32MB)
  8178 00002F17 C3                      	retn
  8179                                  stft_3:
  8180 00002F18 B00B                    	mov	al, 0Bh ; FAT32 (CHS)
  8181 00002F1A C3                      	retn
  8182                                  
  8183                                  ;-----------------------------------------------------------------------------
  8184                                  ; 02/03/2019
  8185                                  
  8186                                  get_ldd_size:	; Get requested logical dos drive size (from user)
  8187                                  	; INPUT -> none
  8188                                  	;
  8189                                  	; OUTPUT -> 
  8190                                  	;	[lcylinders] = cylinder count
  8191                                  	;
  8192                                  	; (Modified registers: ax, bx, cx, dx, si, di) 
  8193                                  
  8194 00002F1B B80300                  	mov	ax, 3 ; clear screen
  8195 00002F1E CD10                    	int	10h
  8196                                  
  8197 00002F20 BE[F548]                	mov	si, msg_create_dos_partition_h
  8198 00002F23 E80FEF                  	call	print_msg
  8199                                  
  8200                                  	; 03/03/2019
  8201 00002F26 A0[D06E]                	mov	al, [ldrives]
  8202 00002F29 08C0                    	or	al, al		; cmp byte [ldrives], 0
  8203 00002F2B 740D                    	jz	short gldds_1	; jna short gldds_0
  8204                                  
  8205                                  	;push	ax ; *	
  8206                                  
  8207                                  	;dec	al
  8208                                  	;mov	ah, 18
  8209                                  	;mul	ah
  8210                                  	
  8211                                  	;mov	di, ext_table_rel_sec_lw
  8212                                  	;add	di, ax
  8213                                  
  8214 00002F2D BE[094F]                	mov	si, msg_use_all_space
  8215 00002F30 E802EF                  	call	print_msg
  8216                                  
  8217                                  	; Calculate available space
  8218                                  
  8219                                  	;mov	ax, [ep_Size] ; ext part size in sectors
  8220                                  	;mov	dx, [ep_Size+2]
  8221                                  	
  8222                                  	; 04/03/2019
  8223                                  ;gldds_0:
  8224                                  	;mov	cx, [di]    ; start sector			
  8225                                  	;mov	bx, [di+2]
  8226                                  	;add	cx, [di+4]  ; sectors
  8227                                  	;adc	bx, [di+6]
  8228                                  	;	; bx:cx = start of next ldd
  8229                                  	;sub	ax, cx
  8230                                  	;sbb	dx, bx
  8231                                  	;	; dx:ax = free space in sectors
  8232                                  	;
  8233                                  	;pop	cx ; *
  8234                                  	;dec	cl
  8235                                  	;jz	short gldds_2
  8236                                  	;sub	di, 18
  8237                                  	;push	cx ; *
  8238                                  	;jmp	short gldds_0
  8239                                  
  8240                                  	; 05/03/2019
  8241 00002F33 E873FF                  	call	check_ext_free_space
  8242 00002F36 7243                    	jc	short gldds_cancel
  8243                                  		; DX:AX = free sectors in extended partition
  8244 00002F38 EB0D                    	jmp	short gldds_2
  8245                                  gldds_1:
  8246 00002F3A BE[3C4F]                	mov	si, msg_use_entire_ep_space
  8247 00002F3D E8F5EE                  	call	print_msg
  8248                                  
  8249                                  	; Calculate free space in extended partition
  8250 00002F40 A1[E070]                	mov	ax, [ep_Size]
  8251 00002F43 8B16[E270]              	mov	dx, [ep_Size+2]
  8252                                  gldds_2:
  8253                                  	; subtrack start offset (which always equals to spt value)
  8254 00002F47 2B06[9640]              	sub	ax, [sectors]
  8255 00002F4B 83DA00                  	sbb	dx, 0
  8256                                  
  8257 00002F4E 89C1                    	mov	cx, ax
  8258 00002F50 A0[9840]                	mov	al, [heads]
  8259 00002F53 F626[9640]              	mul	byte [sectors]
  8260 00002F57 91                      	xchg	ax, cx
  8261                                  		; dx:ax = sectors
  8262                                  		; cx = heads*spt 
  8263 00002F58 E8DBDE                  	call	div32
  8264                                  		; ax = cylinders
  8265                                  		; bx = remainder
  8266                                   		; dx = 0
  8267 00002F5B 21DB                    	and	bx, bx
  8268 00002F5D 7401                    	jz	short gldds_3
  8269 00002F5F 40                      	inc	ax
  8270                                  gldds_3:
  8271 00002F60 A3[5272]                	mov	[lcylinders], ax
  8272                                  gldds_getchar:
  8273 00002F63 30E4                    	xor	ah, ah
  8274 00002F65 CD16                    	int	16h
  8275                                  
  8276 00002F67 3C1B                    	cmp	al, 27 ; ESCAPE key
  8277 00002F69 7410                    	je	short gldds_cancel
  8278 00002F6B 24DF                    	and	al, 0DFh
  8279 00002F6D 3C4E                    	cmp	al, 'N'
  8280 00002F6F 7411                    	je	short gldds_4
  8281 00002F71 3C59                    	cmp	al, 'Y'
  8282 00002F73 75EE                    	jne	short gldds_getchar
  8283 00002F75 BE[F25D]                	mov	si, _msg_YES
  8284                                  	;call	print_msg
  8285                                  	;retn
  8286 00002F78 E9BAEE                  	jmp	print_msg
  8287                                  
  8288                                  gldds_cancel:
  8289 00002F7B C706[5272]0000          	mov	word [lcylinders], 0
  8290                                  gldds_28:
  8291 00002F81 C3                      	retn
  8292                                  gldds_4:	
  8293 00002F82 BE[F85D]                	mov	si, _msg_NO
  8294 00002F85 E8ADEE                  	call	print_msg
  8295                                  gldds_26:
  8296 00002F88 B80300                  	mov	ax, 3 ; clear screen
  8297 00002F8B CD10                    	int	10h
  8298                                  
  8299 00002F8D BE[F548]                	mov	si, msg_create_dos_partition_h
  8300 00002F90 E8A2EE                  	call	print_msg
  8301                                  
  8302 00002F93 BE[0A64]                	mov	si, msg_create_ldd_s
  8303 00002F96 E89CEE                  	call	print_msg
  8304 00002F99 BE[C74E]                	mov	si, msg_press_esc_to_cancel
  8305 00002F9C E896EE                  	call	print_msg
  8306                                  gldds_25:
  8307 00002F9F 30E4                    	xor	ah, ah
  8308 00002FA1 CD16                    	int	16h
  8309                                  
  8310 00002FA3 3C1B                    	cmp	al, 27 ; ESCAPE key
  8311 00002FA5 7502                    	jne	short gldds_5
  8312                                  
  8313 00002FA7 EBD2                    	jmp	short gldds_cancel
  8314                                  gldds_5:
  8315                                  	; 04/03/2019
  8316 00002FA9 3C20                    	cmp	al, 32 ; SPACE key
  8317 00002FAB 74D4                    	je	short gldds_28
  8318                                  	
  8319 00002FAD C606[AA6E]25            	mov	byte [pSize_unit], '%'
  8320 00002FB2 3C25                    	cmp	al, '%'
  8321 00002FB4 741A                    	je	short gldds_6
  8322 00002FB6 C606[AA6E]4D            	mov	byte [pSize_unit], 'M'
  8323 00002FBB 3C0D                    	cmp	al, 13 ; 0Dh, Carriage Return key
  8324 00002FBD 7411                    	je	short gldds_6
  8325 00002FBF 24DF                    	and	al, 0DFh
  8326 00002FC1 3C4D                    	cmp	al, 'M'
  8327 00002FC3 740B                    	je	short gldds_6
  8328 00002FC5 A2[AA6E]                	mov	[pSize_unit], al
  8329 00002FC8 3C47                    	cmp	al, 'G'
  8330 00002FCA 7404                    	je	short gldds_6
  8331 00002FCC 3C43                    	cmp	al, 'C'
  8332 00002FCE 75CF                    	jne	short gldds_25
  8333                                  gldds_6:
  8334                                  	; Set maximum sector count (all of extended partition)
  8335 00002FD0 A0[9640]                	mov	al, [sectors]
  8336 00002FD3 F626[9840]              	mul	byte [heads]
  8337 00002FD7 F726[5272]              	mul	word [lcylinders]
  8338 00002FDB A3[986E]                	mov	[pp_Sectors], ax
  8339 00002FDE 8916[9A6E]              	mov	[pp_Sectors+2], dx
  8340                                  	
  8341 00002FE2 E897F0                   	call	partition_size_input
  8342 00002FE5 7294                    	jc	short gldds_cancel
  8343                                  		; DX:AX = Partition size in sectors
  8344                                  	;or	bx, bx
  8345                                  	;jnz	short gldds_cancel		
  8346 00002FE7 89C1                    	mov	cx, ax
  8347 00002FE9 A0[9840]                	mov	al, [heads]
  8348 00002FEC F626[9640]              	mul	byte [sectors]
  8349 00002FF0 91                      	xchg	ax, cx
  8350                                  		; dx:ax = sectors
  8351                                  		; cx = heads*spt 
  8352 00002FF1 E842DE                  	call	div32
  8353                                  		; ax = cylinders
  8354                                  		; bx = remainder
  8355                                   		; dx = 0
  8356 00002FF4 21DB                    	and	bx, bx
  8357 00002FF6 7401                    	jz	short gldds_7
  8358 00002FF8 40                      	inc	ax
  8359                                  gldds_7:
  8360 00002FF9 3B06[5272]              	cmp	ax, [lcylinders]
  8361 00002FFD 7704                    	ja	short gldds_9
  8362                                  gldds_8:
  8363                                  	; OK
  8364 00002FFF A3[5272]                	mov	[lcylinders], ax
  8365 00003002 C3                      	retn
  8366                                  
  8367                                  gldds_9:
  8368                                  	; Partition size limit message
  8369                                  	
  8370 00003003 803E[AA6E]43            	cmp	byte [pSize_unit], 'C'
  8371 00003008 7407                    	je	short gldds_10
  8372                                  
  8373                                  	; Tolerate 1 cylinder if unit is not cylinder
  8374 0000300A 48                      	dec	ax
  8375 0000300B 3B06[5272]              	cmp	ax, [lcylinders]
  8376 0000300F 76EE                    	jna	short gldds_8
  8377                                  gldds_10:
  8378                                  	; clear screen
  8379 00003011 B80300                  	mov	ax, 3 ; set video mode to 03h (80x25 text)
  8380 00003014 CD10                    	int	10h
  8381                                  
  8382 00003016 BE[F548]                	mov	si, msg_create_dos_partition_h ; header
  8383 00003019 E819EE                  	call	print_msg
  8384                                  
  8385 0000301C BE[B75F]                	mov	si, msg_partition_size_limit
  8386 0000301F E813EE                  	call	print_msg
  8387                                  
  8388 00003022 803E[AA6E]4D            	cmp	byte [pSize_unit], 'M'
  8389 00003027 7413                    	je	short gldds_11
  8390                                  
  8391 00003029 803E[AA6E]25            	cmp	byte [pSize_unit], '%'
  8392 0000302E 745A                    	je	short gldds_22
  8393                                  
  8394 00003030 803E[AA6E]43            	cmp	byte [pSize_unit], 'C'
  8395 00003035 7505                    	jne	short gldds_11
  8396                                  
  8397 00003037 A1[5272]                	mov	ax, [lcylinders]
  8398 0000303A EB0F                    	jmp	short gldds_12
  8399                                  gldds_11:
  8400                                  	; 'M'
  8401 0000303C A1[986E]                	mov	ax, [pp_Sectors]
  8402 0000303F 8B16[9A6E]              	mov	dx, [pp_Sectors+2]
  8403 00003043 B90008                  	mov	cx, 2*1024 ; sectors -> MB
  8404 00003046 E8EDDD                  	call	div32
  8405                                  		; DX = 0 
  8406                                  		; AX = Available space in Megabytes
  8407 00003049 89C7                    	mov	di, ax		
  8408                                  gldds_12:	
  8409 0000304B B90A00                  	mov	cx, 10
  8410 0000304E 89E5                    	mov	bp, sp
  8411                                  gldds_13:
  8412 00003050 31D2                    	xor	dx, dx
  8413 00003052 B90A00                  	mov	cx, 10
  8414 00003055 F7F1                    	div	cx
  8415 00003057 52                      	push	dx
  8416 00003058 83F809                  	cmp	ax, 9
  8417 0000305B 77F3                    	ja	short gldds_13
  8418                                  gldds_14:
  8419 0000305D BB0700                  	mov	bx, 07h
  8420 00003060 09C0                    	or	ax, ax
  8421 00003062 7501                    	jnz	short gldds_16
  8422                                  gldds_15:
  8423 00003064 58                      	pop	ax
  8424                                  gldds_16:
  8425 00003065 0430                    	add	al, '0'
  8426                                  gldds_17:
  8427 00003067 B40E                    	mov	ah, 0Eh
  8428                                  	;mov	bx, 07h
  8429 00003069 CD10                    	int	10h	; write character (as tty)
  8430                                  
  8431 0000306B 39EC                    	cmp	sp, bp			
  8432 0000306D 72F5                    	jb	short gldds_15
  8433                                  
  8434 0000306F 803E[AA6E]25            	cmp	byte [pSize_unit], '%'
  8435 00003074 7508                    	jne	short gldds_18
  8436                                  
  8437 00003076 3C25                    	cmp	al, '%'
  8438 00003078 743C                    	je	short gldds_21
  8439 0000307A B025                    	mov	al, '%'
  8440 0000307C EBE9                    	jmp	short gldds_17
  8441                                  gldds_18:
  8442 0000307E 803E[AA6E]43            	cmp	byte [pSize_unit], 'C'
  8443 00003083 751C                    	jne	short gldds_19
  8444                                  
  8445 00003085 BE[5360]                	mov	si, msg_cylinders
  8446 00003088 EB29                    	jmp	short gldds_20
  8447                                  
  8448                                  gldds_22:
  8449                                  	; '%'
  8450 0000308A 81C3[E071]              	add	bx, free_space.percent_unused
  8451 0000308E 8B07                    	mov	ax, [bx]
  8452                                  gldds_23:	
  8453 00003090 89E5                    	mov	bp, sp
  8454                                  gldds_24:	
  8455 00003092 31D2                    	xor	dx, dx
  8456 00003094 B90A00                  	mov	cx, 10
  8457 00003097 F7F1                    	div	cx
  8458 00003099 52                      	push	dx
  8459 0000309A 83F809                  	cmp	ax, 9
  8460 0000309D 77F3                    	ja	short gldds_24
  8461 0000309F EBBC                    	jmp	short gldds_14
  8462                                  
  8463                                  gldds_19:
  8464 000030A1 BE[6760]                	mov	si, msg_megabytes
  8465 000030A4 C606[7060]73            	mov	byte [msg_megabytes_s], 's'
  8466 000030A9 83FF01                  	cmp	di, 1
  8467 000030AC 7705                    	ja	short gldds_20
  8468 000030AE C606[7060]00            	mov	byte [msg_megabytes_s], 0	
  8469                                  gldds_20:
  8470 000030B3 E87FED                  	call	print_msg
  8471                                  gldds_21:
  8472 000030B6 BE[0460]                	mov	si, msg_partition_size_limit_r
  8473 000030B9 E879ED                  	call	print_msg
  8474                                  gldds_27:
  8475 000030BC 30E4                    	xor	ah, ah
  8476 000030BE CD16                    	int	16h
  8477                                  	
  8478 000030C0 3C1B                    	cmp	al, 27 ; ESCAPE key
  8479 000030C2 0F84C2FE                	je	gldds_26
  8480 000030C6 3C0D                    	cmp	al, 13 ; ENTER (Carriage Return) key
  8481 000030C8 75F2                    	jne	short gldds_27
  8482                                  
  8483                                  	;mov	ax, [lcylinders]
  8484 000030CA C3                      	retn
  8485                                  	
  8486                                  ;-----------------------------------------------------------------------------
  8487                                  ; 26/02/2019
  8488                                  
  8489                                  init_ext_partition_tables:
  8490                                  
  8491                                  	; INPUT -> 
  8492                                  	;	[epnumber] = extended partition number
  8493                                  	;
  8494                                  	; OUTPUT -> none
  8495                                  
  8496                                  ; Display Method: ; 04/03/2019
  8497                                  ;LDD 1 <- LDD_START0, ebr 1st entry <- MBR (extended partition) - EBR 0
  8498                                  ;LDD 2 <- LDD_START1, ebr 1st entry <- EBR 1
  8499                                  ;LDD 3 <- LDD_START2, ebr 1st entry <- EBR 2
  8500                                  ;LDD 4 <- LDD_START3, ebr 1st entry <- EBR 3
  8501                                  ;LDD 5 <- LDD_START3, ebr 2nd entry (LDD 5 is not diplayed)
  8502                                  
  8503                                  	; 08/03/2019
  8504                                  
  8505                                  	; clear extended partition tables structure/list
  8506                                  
  8507 000030CB BF[9271]                	mov	di, ext_table_boot_ind
  8508 000030CE 89FE                    	mov	si, di ; 28/02/2019
  8509 000030D0 B92400                  	mov	cx, 36 ; 18*4 = 72 bytes
  8510 000030D3 31C0                    	xor	ax, ax ; 0
  8511 000030D5 F3AB                    	rep	stosw
  8512 000030D7 89F7                    	mov	di, si ; 28/02/2019	
  8513                                  
  8514                                  	;mov	byte [ldrives], 0
  8515 000030D9 A2[D06E]                	mov	[ldrives], al ; 0
  8516                                  
  8517                                  	;cmp	byte [epnumber], 1
  8518                                  	;jb	short iept_0
  8519                                  
  8520 000030DC A0[9171]                	mov	al, [epnumber]
  8521 000030DF FEC8                    	dec	al
  8522 000030E1 B412                    	mov	ah, 18  ; partition table structure size 
  8523 000030E3 F6E4                    	mul	ah
  8524 000030E5 BE[5071]                	mov	si, part_table_rel_sec_lw
  8525 000030E8 01C6                    	add	si, ax
  8526 000030EA 8B04                    	mov	ax, [si]
  8527 000030EC 8B5402                  	mov	dx, [si+2]
  8528 000030EF A3[D870]                	mov	[ep_StartSector], ax
  8529 000030F2 8916[DA70]              	mov	[ep_StartSector+2], dx
  8530 000030F6 8B4C04                  	mov	cx, [si+4]
  8531 000030F9 8B5C06                  	mov	bx, [si+6]
  8532 000030FC 890E[E070]              	mov	[ep_Size], cx
  8533 00003100 891E[E270]              	mov	[ep_Size+2], bx
  8534 00003104 83E901                  	sub	cx, 1
  8535 00003107 83DB00                  	sbb	bx, 0
  8536 0000310A 01C1                    	add	cx, ax
  8537 0000310C 11D3                    	adc	bx, dx 
  8538 0000310E 890E[DC70]              	mov	[ep_EndSector], cx
  8539 00003112 891E[DE70]              	mov	[ep_EndSector+2], bx
  8540                                  
  8541                                  	; 27/02/2019
  8542 00003116 A3[3072]                	mov	[ldd_start], ax
  8543 00003119 8916[3272]              	mov	[ldd_start+2], dx
  8544                                  
  8545                                  	; 03/03/2019
  8546                                  	;mov	word [ldd_size], 0
  8547                                  	;mov	word [ldd_size+2], 0
  8548                                  	
  8549 0000311D BB[D66E]                	mov	bx, ebr_buffer
  8550                                  	; dx:ax = Extended partition address
  8551                                  	; es:bx = Extended partition buffer 
  8552 00003120 E860ED                  	call	read_hd_sector
  8553 00003123 7209                    	jc	short iept_0
  8554                                  
  8555                                  	; Check EBR if it is a valid boot record or not
  8556 00003125 813E[D470]55AA          	cmp	word [ebr_buffer+510], 0AA55h
  8557 0000312B 7402                    	je	short iept_1
  8558                                  iept_stc_retn:
  8559 0000312D F9                      	stc
  8560                                  iept_0:
  8561 0000312E C3                      	retn
  8562                                  iept_1:
  8563                                  	; Check PTE 1, if it is valid or not
  8564 0000312F A0[9870]                	mov	al, [ebr_buffer+446+ptFileSystemID]
  8565 00003132 20C0                    	and	al, al
  8566 00003134 74F7                    	jz	short iept_stc_retn ; empty pte, error
  8567 00003136 3C05                    	cmp	al, 5
  8568 00003138 74F3                    	je	short iept_stc_retn ; extended partition, error
  8569                                  
  8570                                  	;inc	byte [ldrives] ; logical (dos) drive count
  8571                                  
  8572 0000313A BE[9470]                	mov	si, ebr_buffer+446 ; Partition table offset
  8573 0000313D B90400                  	mov	cx, 4
  8574                                  
  8575                                  	; set partition (logical -dos- drive) data
  8576 00003140 A5                      	movsw	; boot indicator, beginning head
  8577 00003141 AC                      	lodsb
  8578 00003142 88C4                    	mov	ah, al
  8579 00003144 243F                    	and	al, 3Fh
  8580 00003146 AA                      	stosb	; beginning sector
  8581 00003147 C0EC06                  	shr	ah, 6
  8582 0000314A AC                      	lodsb	; beginning cylinder
  8583 0000314B AB                      	stosw	
  8584 0000314C A5                      	movsw	; partition id, end head
  8585 0000314D AC                      	lodsb
  8586 0000314E 88C4                    	mov	ah, al
  8587 00003150 243F                    	and	al, 3Fh
  8588 00003152 AA                      	stosb	; end sector
  8589 00003153 C0EC06                  	shr	ah, 6
  8590 00003156 AC                      	lodsb	; end cylinder
  8591 00003157 AB                      	stosw
  8592                                  
  8593                                  	; 04/03/2019
  8594 00003158 8A1E[D06E]              	mov	bl, [ldrives]
  8595                                  	;dec 	bl
  8596                                  	;jnz	short iept_2
  8597                                  
  8598                                  	; 05/03/2019
  8599 0000315C 08DB                    	or	bl, bl 
  8600 0000315E 7518                    	jnz	short iept_2
  8601                                  
  8602 00003160 8B04                    	mov	ax, [si]   ; start sector of 1st LDD (offset)	
  8603 00003162 8B5402                  	mov	dx, [si+2]
  8604 00003165 034404                  	add	ax, [si+4] ; size of 1st LDD (volume)
  8605 00003168 135406                  	adc	dx, [si+6]
  8606                                  
  8607 0000316B A3[4072]                	mov	[ldd_size], ax ; size of 1st LDD (partition)
  8608 0000316E 8916[4272]              	mov	[ldd_size+2], dx
  8609                                  	; 05/03/2019
  8610 00003172 FE06[D06E]              	inc	byte [ldrives] ; logical (dos) drive count
  8611 00003176 FEC3                    	inc	bl
  8612                                  iept_2:
  8613 00003178 F3A5                    	rep	movsw ; copy start sector (LBA) and sector count
  8614                                  
  8615                                  	; get next extended partition (logical -dos- drive) data 
  8616 0000317A 8A4404                  	mov	al, [si+ptFileSystemID]
  8617 0000317D 20C0                    	and	al, al ; EMPTY
  8618 0000317F 74AD                    	jz	short iept_0 ; end of logical -dos- drive chain	
  8619                                  
  8620 00003181 3C05                    	cmp	al, 5 ; EXTENDED
  8621 00003183 75A8                    	jne	short iept_stc_retn  ; 2nd PTE must have
  8622                                  				     ; extended partition ID
  8623                                  
  8624                                  	; 05/03/2019
  8625 00003185 FE06[D06E]              	inc	byte [ldrives] ; logical (dos) drive count
  8626                                  
  8627                                  	;cmp	byte [ldrives], al ; 5
  8628 00003189 80FB04                  	cmp	bl, 4 ; number of logical dos drives (till here)
  8629 0000318C 733D                    	jnb	short iept_3
  8630                                  
  8631 0000318E 83C608                  	add	si, 8
  8632                                  
  8633 00003191 AD                      	lodsw	
  8634 00003192 89C2                    	mov	dx, ax	; start sector
  8635 00003194 AD                      	lodsw
  8636 00003195 92                      	xchg	dx, ax	; start sector + 2
  8637                                  
  8638                                  	; 04/03/2019
  8639 00003196 0306[D870]              	add	ax, [ep_StartSector]
  8640 0000319A 1316[DA70]              	adc	dx, [ep_StartSector+2]
  8641                                  	
  8642 0000319E 30FF                    	xor	bh, bh
  8643 000031A0 C0E302                  	shl	bl, 2 ; *4
  8644                                  
  8645                                  	; 28/02/2019
  8646 000031A3 8987[3072]              	mov	[bx+ldd_start], ax ; start of (next) LDD (partition)
  8647 000031A7 8997[3272]              	mov	[bx+ldd_start+2], dx
  8648                                  
  8649                                  	; 03/03/2019
  8650                                  	; set partition size for logical dos drive
  8651 000031AB 8B0C                    	mov	cx, [si]
  8652 000031AD 898F[4072]              	mov	[bx+ldd_size], cx
  8653 000031B1 8B4C02                  	mov	cx, [si+2]
  8654 000031B4 898F[4272]              	mov	[bx+ldd_size+2], cx
  8655                                  
  8656 000031B8 BB[D66E]                	mov	bx, ebr_buffer
  8657                                  	; dx:ax = Extended partition address
  8658                                  	; es:bx = Extended partition buffer 
  8659 000031BB E8C5EC                  	call	read_hd_sector
  8660 000031BE 720B                    	jc	short iept_3 ; 03/03/2019
  8661                                  
  8662                                  	; Check EBR if it is valid or not
  8663 000031C0 813E[D470]55AA          	cmp	word [ebr_buffer+510], 0AA55h
  8664 000031C6 0F8465FF                	je	iept_1
  8665                                  
  8666 000031CA F9                      	stc
  8667                                  iept_3:	
  8668 000031CB C3                      	retn
  8669                                  
  8670                                  ;-----------------------------------------------------------------------------
  8671                                  ; 27/02/2019
  8672                                  
  8673                                  delete_logical_drives:
  8674                                  
  8675                                  ; Delete Method: ; 04/03/2019
  8676                                  ;LDD 5 <- LDD_START3, ebr 2nd entry
  8677                                  ;LDD 4 <- LDD_START2, ebr 2nd entry
  8678                                  ;LDD 3 <- LDD_START1, ebr 2nd entry
  8679                                  ;LDD 2 <- LDD_START0, ebr 2nd entry
  8680                                  ;LDD 1 <- LDD_START0, ebr 1st entry
  8681                                  
  8682                                  	;cmp	byte [ldrives], 0
  8683                                  	;jna	short dld_stc
  8684                                  
  8685 000031CC B005                    	mov	al, 5 ; extended partition (logical drives)
  8686 000031CE E8BCF7                  	call	display_partition_table
  8687                                  
  8688 000031D1 A0[D06E]                	mov	al, [ldrives]
  8689 000031D4 0430                    	add	al, '0'
  8690 000031D6 A2[DD61]                	mov	[lddp_num], al
  8691                                  
  8692 000031D9 BE[8A61]                	mov	si, msg_delete_ldd
  8693 000031DC E856EC                  	call	print_msg
  8694                                  
  8695 000031DF BE[C74E]                	mov	si, msg_press_esc_to_cancel
  8696 000031E2 E850EC                  	call	print_msg
  8697                                  dld_0:
  8698 000031E5 30E4                    	xor	ah, ah
  8699 000031E7 CD16                    	int	16h
  8700                                  
  8701 000031E9 80FC53                  	cmp	ah, 53h  ; DELETE or DEL key
  8702 000031EC 7527                    	jne	short dld_1
  8703                                  
  8704                                  	; Open disk image file again.
  8705 000031EE BA[8159]                	mov	dx, img_file_name
  8706 000031F1 B8023D                  	mov	ax, 3D02h ; open for reading and writing
  8707 000031F4 CD21                    	int	21h
  8708 000031F6 7221                    	jc	short dld_5
  8709                                  
  8710 000031F8 A3[9440]                	mov	[img_file_handle], ax
  8711                                  
  8712                                  	; Delete PTE 1 & PTE 2 on EBR 1
  8713                                  	;xor	ah, ah
  8714 000031FB A0[D06E]                	mov	al, [ldrives]
  8715 000031FE FEC8                    	dec	al
  8716 00003200 7518                    	jnz	short dld_2
  8717                                  
  8718 00003202 BF[9470]                	mov	di, ebr_buffer+446
  8719 00003205 B91000                  	mov	cx, 16
  8720 00003208 F3AB                    	rep	stosw
  8721                                  
  8722                                  	; 04/03/2019
  8723                                  	; Clear ldd data in extended partition table/structure
  8724 0000320A BF[9271]                	mov	di, ext_table_boot_ind
  8725 0000320D B109                    	mov	cl, 9
  8726 0000320F F3AB                    	rep	stosw
  8727 00003211 31F6                    	xor	si, si
  8728 00003213 EB40                    	jmp	short dld_3
  8729                                  dld_1:	
  8730 00003215 3C1B                    	cmp	al, 27 ; ESC key
  8731 00003217 75CC                    	jne	short dld_0
  8732                                  dld_5:
  8733 00003219 C3                      	retn
  8734                                  
  8735                                  ;dld_stc:
  8736                                  ;	stc
  8737                                  ;	retn	
  8738                                  
  8739                                  dld_2:
  8740                                  	; 04/03/2019
  8741                                  	; Delete 2nd PTE on EBR 2 to 4
  8742 0000321A FEC8                    	dec	al 
  8743 0000321C C0E002                  	shl	al, 2 ; *4
  8744 0000321F 89C6                    	mov	si, ax
  8745                                  
  8746 00003221 8B84[3072]              	mov	ax, [si+ldd_start]
  8747 00003225 8B94[3272]              	mov	dx, [si+ldd_start+2]
  8748 00003229 BB[D66E]                	mov	bx, ebr_buffer
  8749 0000322C E854EC                  	call	read_hd_sector
  8750 0000322F 7238                    	jc	short dld_4
  8751                                  
  8752 00003231 BF[A470]                	mov	di, ebr_buffer+446+16
  8753 00003234 B90800                  	mov	cx, 8
  8754 00003237 29C0                    	sub	ax, ax
  8755 00003239 F3AB                    	rep	stosw
  8756                                  
  8757                                  	; 04/03/2019
  8758                                  	;cmp	byte [ldrives], 5
  8759                                  	;jnb	short dld_3
  8760 0000323B 8A26[D06E]              	mov	ah, [ldrives]
  8761 0000323F 80FC05                  	cmp	ah, 5
  8762 00003242 7311                    	jnb	short dld_3
  8763                                  
  8764                                  	; Clear ldd data in extended partition table/structure
  8765                                  	;mov	ah, [ldrives]
  8766 00003244 FECC                    	dec	ah
  8767 00003246 B012                    	mov	al, 18
  8768 00003248 F6E4                    	mul	ah
  8769 0000324A BF[9271]                	mov	di, ext_table_boot_ind
  8770 0000324D 01C7                    	add	di, ax
  8771                                  	;mov	cx, 9
  8772 0000324F B109                    	mov	cl, 9
  8773                                  	;xor	ax, ax
  8774 00003251 30C0                    	xor	al, al
  8775 00003253 F3AB                    	rep	stosw
  8776                                  dld_3:
  8777                                  	; Write changed EBR
  8778 00003255 8B84[3072]              	mov	ax, [si+ldd_start]
  8779 00003259 8B94[3272]              	mov	dx, [si+ldd_start+2]
  8780 0000325D BB[D66E]                	mov	bx, ebr_buffer
  8781 00003260 E8E1EB                  	call	write_hd_sector
  8782 00003263 7204                    	jc	short dld_4
  8783                                  
  8784                                  	; 28/02/2019
  8785 00003265 FE0E[D06E]              	dec	byte [ldrives]
  8786                                  dld_4:
  8787                                  	; Close file
  8788 00003269 8B1E[9440]              	mov	bx, [img_file_handle]
  8789 0000326D B43E                    	mov	ah, 3Eh ; close file
  8790 0000326F CD21                    	int	21h
  8791                                  
  8792 00003271 C706[9440]0000          	mov	word [img_file_handle], 0
  8793                                  
  8794 00003277 803E[D06E]00            	cmp	byte [ldrives], 0
  8795 0000327C 0F874CFF                	ja	delete_logical_drives
  8796                                  
  8797 00003280 C3                      	retn
  8798                                  
  8799                                  ;=============================================================================
  8800                                  ;        	initialized data
  8801                                  ;=============================================================================
  8802                                  
  8803 00003281 00                      	db	0
  8804                                  
  8805                                  TRDOS386_MASTERBOOT_SECTOR:
  8806 00003282 <bin 200h>              	incbin	'FS1_MBR.BIN' ; Singlix FS1 MBR	
  8807                                  
  8808                                  TRDOS_FAT_hd_bs:
  8809                                  	;incbin 'TRHDBS.BIN'
  8810                                  TRDOS_FAT32_hd_bs:
  8811 00003482 <bin 400h>              	incbin	'FAT32_BS.BIN' ; 27/04/2024
  8812                                  TRDOS_FAT16_hd_bs: 
  8813 00003882 <bin 200h>              	incbin	'FAT16_BS.BIN' ; 26/12/2017
  8814                                  TRDOS_FAT12_hd_bs: 
  8815 00003A82 <bin 200h>              	incbin	'FAT12_BS.BIN' ; 26/12/2017
  8816                                  
  8817                                  TRDOS_TRFS1_chs_bs:
  8818 00003C82 <bin 200h>              	incbin	'TRFS1CHS.BIN' ; Singlix FS1 (CHS+LBA Disk) BS		
  8819                                  TRDOS_TRFS1_lba_bs:
  8820 00003E82 <bin 200h>              	incbin	'TRFS1LBA.BIN' ; Singlix FS1 (LBA Disk) BS	
  8821                                  
  8822 00004082 00                      	db	0
  8823                                  
  8824                                  hexchrs:
  8825 00004083 303132333435363738-     	db	'0123456789ABCDEF'
  8825 0000408C 39414243444546     
  8826                                  
  8827 00004093 90                      align 2
  8828                                  
  8829                                  img_file_handle:
  8830 00004094 0000                    	dw	0
  8831                                  
  8832                                  ; (TR-DOS 386 compatible) Hard Disk (image) parameters
  8833                                  
  8834                                  sectors: ; sectors per track (63)
  8835 00004096 3F00                    	dw 63
  8836                                  heads:	 ; number of heads (16 or 32 or 64) 
  8837 00004098 1000                    	dw 16
  8838                                  cylinders: ; number of cylinders (16 to 1024)
  8839 0000409A 0004                    	dw 1024
  8840                                  
  8841                                  random:
  8842 0000409C 00                      	db	0  ; random write to file (0 = sequental)
  8843                                  newdisk:
  8844 0000409D 00                      	db	0
  8845                                  
  8846                                  FileSys_Names: ; 2003-2017
  8847                                  ; (Valid FileSystems for TRDOS 386, SINGLIX, RETRO UNIX OS projects in 2017)
  8848 0000409E 464154313220202020-     FS_FAT12:     db "FAT12         "  ; 01h = FAT12
  8848 000040A7 2020202020         
  8849 000040AC 58454E495820202020-     FS_XENIX:     db "XENIX         "  ; 02h , XENIX System V root
  8849 000040B5 2020202020         
  8850 000040BA 58454E495820757372-     FS_XENIX_USR: db "XENIX usr     "  ; 03h , XENIX System V user
  8850 000040C3 2020202020         
  8851 000040C8 464154313620283034-     FS_FAT16:     db "FAT16 (04h)   "  ; 04h = FAT16 < 32MB
  8851 000040D1 6829202020         
  8852 000040D6 455854454E44454420-     FS_EXT_CHS:   db "EXTENDED (CHS)"  ; 05h = Extended DOS Partition
  8852 000040DF 2843485329         
  8853 000040E4 464154313620283036-     FS_FAT16_BIG: db "FAT16 (06h)   "  ; 06h = FAT16 > 32MB, CHS mode
  8853 000040ED 6829202020         
  8854 000040F2 4E5446532020202020-     FS_NTFS:      db "NTFS          "  ; 07h , WINDOWS NTFS Partition
  8854 000040FB 2020202020         
  8855 00004100 464154333220284348-     FS_FAT32_CHS: db "FAT32 (CHS)   "  ; 0Bh = FAT32, CHS mode
  8855 00004109 5329202020         
  8856 0000410E 464154333220284C42-     FS_FAT32_LBA: db "FAT32 (LBA)   "  ; 0Ch = FAT32, LBA mode
  8856 00004117 4129202020         
  8857 0000411C 464154313620284C42-     FS_FAT16_LBA: db "FAT16 (LBA)   "  ; 0Eh = FAT16, LBA mode
  8857 00004125 4129202020         
  8858 0000412A 455854454E44454420-     FS_EXT_LBA:   db "EXTENDED (LBA)"  ; 0Fh = Extented Partition, LBA mode
  8858 00004133 284C424129         
  8859 00004138 554E49582053595354-     FS_UNIX_SYSV: db "UNIX SYSTEM V "  ; 63h , SCO UNIX, UNIXWARE, OPENSERVER
  8859 00004141 454D205620         
  8860 00004146 524554524F20554E49-     FS_RETROUNIX: db "RETRO UNIX    "  ; 71h , Retro UNIX 386 v2 Partition
  8860 0000414F 5820202020         
  8861 00004154 554E49582056372020-     FS_UNIX_V7:   db "UNIX V7       "  ; 72h , UNIX v7 x86 Partition  
  8861 0000415D 2020202020         
  8862 00004162 4C494E555820535741-     FS_LINUXSWAP: db "LINUX SWAP    "  ; 82h , LINUX SWAP Partition
  8862 0000416B 5020202020         
  8863 00004170 4C494E555820202020-     FS_LINUX:     db "LINUX         "  ; 83h , LINUX NATIVE (ext2) Partition
  8863 00004179 2020202020         
  8864 0000417E 4C494E555820455854-     FS_LINUXEXT:  db "LINUX EXTENDED"  ; 85h , LINUX EXTENDED Partition
  8864 00004187 454E444544         
  8865 0000418C 524444202020202020-     FS_TRDD:      db "RDD           "  ; A0h , (Random Data Disk) LBA
  8865 00004195 2020202020         
  8866 0000419A 53494E474C49582046-     FS_TRFS:      db "SINGLIX FS1   "  ; A1h , (32 bit, 512 bytes per sector)
  8866 000041A3 5331202020         
  8867 000041A8 554E4B4E4F574E2046-     FS_OTHERS:    db "UNKNOWN FS    "  ; Another or Unknown File Systems
  8867 000041B1 5320202020         
  8868                                   
  8869                                  valid_partitions: ; (*)
  8870 000041B6 01020304050607          	      db 01h, 02h, 03h, 04h, 05h, 06h, 07h
  8871 000041BD 0B0C0E0F637172          	      db 0Bh, 0Ch, 0Eh, 0Fh, 63h, 71h, 72h
  8872 000041C4 828385A0A1              	      db 82h, 83h, 85h, 0A0h, 0A1h 			
  8873                                  
  8874                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  8875                                  ;  Messages
  8876                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  8877                                  
  8878                                  CHS_msg: ; 80 bytes per row
  8879 000041C9 507265737320274327-     db  "Press 'C' to set cylinders then press '+,-' keys to change number of cylinders. " 
  8879 000041D2 20746F207365742063-
  8879 000041DB 796C696E6465727320-
  8879 000041E4 7468656E2070726573-
  8879 000041ED 7320272B2C2D27206B-
  8879 000041F6 65797320746F206368-
  8879 000041FF 616E6765206E756D62-
  8879 00004208 6572206F662063796C-
  8879 00004211 696E646572732E20   
  8880 00004219 507265737320274827-     db  "Press 'H' to set heads then press '+,-' keys to change number of heads.         " 
  8880 00004222 20746F207365742068-
  8880 0000422B 65616473207468656E-
  8880 00004234 20707265737320272B-
  8880 0000423D 2C2D27206B65797320-
  8880 00004246 746F206368616E6765-
  8880 0000424F 206E756D626572206F-
  8880 00004258 662068656164732E20-
  8880 00004261 2020202020202020   
  8881 00004269 507265737320275327-     db  "Press 'S' to set sectors then press '+,-' keys to change numb of sectors/track. " 
  8881 00004272 20746F207365742073-
  8881 0000427B 6563746F7273207468-
  8881 00004284 656E20707265737320-
  8881 0000428D 272B2C2D27206B6579-
  8881 00004296 7320746F206368616E-
  8881 0000429F 6765206E756D62206F-
  8881 000042A8 6620736563746F7273-
  8881 000042B1 2F747261636B2E20   
  8882 000042B9 202020202020202020-     db  "                                                                                " 
  8882 000042C2 202020202020202020-
  8882 000042CB 202020202020202020-
  8882 000042D4 202020202020202020-
  8882 000042DD 202020202020202020-
  8882 000042E6 202020202020202020-
  8882 000042EF 202020202020202020-
  8882 000042F8 202020202020202020-
  8882 00004301 2020202020202020   
  8883 00004309 202020202020202020-     db  "                                                                                " 
  8883 00004312 202020202020202020-
  8883 0000431B 202020202020202020-
  8883 00004324 202020202020202020-
  8883 0000432D 202020202020202020-
  8883 00004336 202020202020202020-
  8883 0000433F 202020202020202020-
  8883 00004348 202020202020202020-
  8883 00004351 2020202020202020   
  8884 00004359 507265737320454E54-     db  "Press ENTER to use current CHS values.                                          "
  8884 00004362 455220746F20757365-
  8884 0000436B 2063757272656E7420-
  8884 00004374 4348532076616C7565-
  8884 0000437D 732E20202020202020-
  8884 00004386 202020202020202020-
  8884 0000438F 202020202020202020-
  8884 00004398 202020202020202020-
  8884 000043A1 2020202020202020   
  8885 000043A9 202020202020202020-     db  "                                                                                " 
  8885 000043B2 202020202020202020-
  8885 000043BB 202020202020202020-
  8885 000043C4 202020202020202020-
  8885 000043CD 202020202020202020-
  8885 000043D6 202020202020202020-
  8885 000043DF 202020202020202020-
  8885 000043E8 202020202020202020-
  8885 000043F1 2020202020202020   
  8886 000043F9 507265737320455343-     db  "Press ESC to cancel.                                                            "
  8886 00004402 20746F2063616E6365-
  8886 0000440B 6C2E20202020202020-
  8886 00004414 202020202020202020-
  8886 0000441D 202020202020202020-
  8886 00004426 202020202020202020-
  8886 0000442F 202020202020202020-
  8886 00004438 202020202020202020-
  8886 00004441 2020202020202020   
  8887 00004449 202020202020202020-     db  "                                                                                " 
  8887 00004452 202020202020202020-
  8887 0000445B 202020202020202020-
  8887 00004464 202020202020202020-
  8887 0000446D 202020202020202020-
  8887 00004476 202020202020202020-
  8887 0000447F 202020202020202020-
  8887 00004488 202020202020202020-
  8887 00004491 2020202020202020   
  8888 00004499 00                      db  0
  8889                                  
  8890                                  TrDOS_Welcome:
  8891 0000449A 0D0A                    	db	0Dh, 0Ah
  8892 0000449C 54522D444F53203338-     	db	'TR-DOS 386 Fixed Disk Image Format Utility'
  8892 000044A5 362046697865642044-
  8892 000044AE 69736B20496D616765-
  8892 000044B7 20466F726D61742055-
  8892 000044C0 74696C697479       
  8893 000044C6 0D0A                    	db	0Dh, 0Ah
  8894 000044C8 76312E312E32343035-     	db	"v1.1.240503 (c) Erdogan TAN 2019-2024"
  8894 000044D1 303320286329204572-
  8894 000044DA 646F67616E2054414E-
  8894 000044E3 20323031392D323032-
  8894 000044EC 34                 
  8895 000044ED 0D0A                    	db	0Dh,0Ah
  8896 000044EF 0D0A                    	db	0Dh,0Ah
  8897 000044F1 55736167653A206864-     	db	'Usage: hdimage <image file name> '
  8897 000044FA 696D616765203C696D-
  8897 00004503 6167652066696C6520-
  8897 0000450C 6E616D653E20       
  8898 00004512 00                      	db	0
  8899                                  
  8900                                  msg_inv_file_name: 
  8901 00004513 0D0A                    	db	0Dh, 0Ah
  8902 00004515 496E76616C69642066-     	db	"Invalid file name !", 0Dh, 0Ah
  8902 0000451E 696C65206E616D6520-
  8902 00004527 210D0A             
  8903 0000452A 2846696C65206E616D-     	db	"(File name must fit to 8.3 DOS format) !"
  8903 00004533 65206D757374206669-
  8903 0000453C 7420746F20382E3320-
  8903 00004545 444F5320666F726D61-
  8903 0000454E 74292021           
  8904 00004552 0D0A00                  	db	0Dh, 0Ah, 0
  8905                                  
  8906                                  msg_inv_image_file:
  8907 00004555 0D0A                    	db	0Dh, 0Ah
  8908 00004557 496E76616C69642066-     	db	"Invalid fixed disk image file !", 0Dh, 0Ah
  8908 00004560 69786564206469736B-
  8908 00004569 20696D616765206669-
  8908 00004572 6C6520210D0A       
  8909 00004578 2846696C652073697A-     	db	"(File size or masterboot sector is not compatible) !"
  8909 00004581 65206F72206D617374-
  8909 0000458A 6572626F6F74207365-
  8909 00004593 63746F72206973206E-
  8909 0000459C 6F7420636F6D706174-
  8909 000045A5 69626C65292021     
  8910 000045AC 0D0A00                  	db	0Dh, 0Ah, 0  
  8911                                  
  8912                                  msg_min_8mb_disk:
  8913 000045AF 0D0A                    	db	0Dh, 0Ah
  8914 000045B1 4D696E696D756D2038-     	db	"Minimum 8 MB disk size is needed for a proper hard disk image !"
  8914 000045BA 204D42206469736B20-
  8914 000045C3 73697A65206973206E-
  8914 000045CC 656564656420666F72-
  8914 000045D5 20612070726F706572-
  8914 000045DE 206861726420646973-
  8914 000045E7 6B20696D6167652021 
  8915 000045F0 0D0A                    	db	0Dh, 0Ah
  8916 000045F2 28507265737320616E-     	db	"(Press any key to continue..)" 
  8916 000045FB 79206B657920746F20-
  8916 00004604 636F6E74696E75652E-
  8916 0000460D 2E29               
  8917 0000460F 0D0A00                  	db	0Dh, 0Ah, 0
  8918                                  
  8919                                  msg_any_key_esc_exit:
  8920 00004612 0D0A                    	db	0Dh, 0Ah
  8921 00004614 507265737320455343-     	db	"Press ESC to exit or press another key to continue..."
  8921 0000461D 20746F206578697420-
  8921 00004626 6F7220707265737320-
  8921 0000462F 616E6F74686572206B-
  8921 00004638 657920746F20636F6E-
  8921 00004641 74696E75652E2E2E   
  8922 00004649 00                      	db	0
  8923                                  
  8924                                  msg_create_partition_h:
  8925 0000464A 0D0A                    	db	0Dh, 0Ah
  8926 0000464C 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"
  8926 00004655 2D2D2D2D2D2D2D2D2D-
  8926 0000465E 2D2D2D2D2D2D2D2D2D-
  8926 00004667 2D2D2D2D2D2D2D2D2D-
  8926 00004670 2D2D2D2D2D2D2D2D2D-
  8926 00004679 2D2D2D2D2D2D2D2D2D-
  8926 00004682 2D2D2D2D2D2D2D2D2D-
  8926 0000468B 2D2D2D2D2D2D2D2D2D-
  8926 00004694 2D2D2D2D2D2D2D2D   
  8927 0000469C 202020202020202020-     	db	"                               Create Partition                                 "
  8927 000046A5 202020202020202020-
  8927 000046AE 202020202020202020-
  8927 000046B7 202020204372656174-
  8927 000046C0 652050617274697469-
  8927 000046C9 6F6E20202020202020-
  8927 000046D2 202020202020202020-
  8927 000046DB 202020202020202020-
  8927 000046E4 2020202020202020   
  8928 000046EC 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"	
  8928 000046F5 2D2D2D2D2D2D2D2D2D-
  8928 000046FE 2D2D2D2D2D2D2D2D2D-
  8928 00004707 2D2D2D2D2D2D2D2D2D-
  8928 00004710 2D2D2D2D2D2D2D2D2D-
  8928 00004719 2D2D2D2D2D2D2D2D2D-
  8928 00004722 2D2D2D2D2D2D2D2D2D-
  8928 0000472B 2D2D2D2D2D2D2D2D2D-
  8928 00004734 2D2D2D2D2D2D2D2D   
  8929 0000473C 0D0A00                  	db	0Dh, 0Ah, 0
  8930                                  msg_create_partition_m:
  8931 0000473F 53656C65637420616E-     	db	"Select an option: "
  8931 00004748 206F7074696F6E3A20 
  8932 00004751 0D0A                    	db	0Dh, 0Ah
  8933 00004753 0D0A                    	db	0Dh, 0Ah
  8934 00004755 202031292043726561-     	db	"  1) Create DOS partition ", 0Dh, 0Ah
  8934 0000475E 746520444F53207061-
  8934 00004767 72746974696F6E200D-
  8934 00004770 0A                 
  8935 00004771 202032292043726561-     	db	"  2) Create SINGLIX FS partition ", 0Dh, 0Ah			
  8935 0000477A 74652053494E474C49-
  8935 00004783 582046532070617274-
  8935 0000478C 6974696F6E200D0A   
  8936 00004794 202033292043726561-     	db	"  3) Create RETRO UNIX partition ", 0Dh, 0Ah
  8936 0000479D 746520524554524F20-
  8936 000047A6 554E49582070617274-
  8936 000047AF 6974696F6E200D0A   
  8937 000047B7 202034292043726561-     	db	"  4) Create another type of partition ", 0Dh, 0Ah 		
  8937 000047C0 746520616E6F746865-
  8937 000047C9 722074797065206F66-
  8937 000047D2 20706172746974696F-
  8937 000047DB 6E200D0A           
  8938 000047DF 0D0A                    	db	0Dh, 0Ah	
  8939 000047E1 507265737320455343-     	db	"Press ESC or 0 to cancel .. "
  8939 000047EA 206F72203020746F20-
  8939 000047F3 63616E63656C202E2E-
  8939 000047FC 20                 
  8940 000047FD 0D0A00                   	db 	0Dh, 0Ah, 0	
  8941                                  
  8942                                  msg_create_primary_partition_h:
  8943 00004800 0D0A                    	db	0Dh, 0Ah
  8944 00004802 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"
  8944 0000480B 2D2D2D2D2D2D2D2D2D-
  8944 00004814 2D2D2D2D2D2D2D2D2D-
  8944 0000481D 2D2D2D2D2D2D2D2D2D-
  8944 00004826 2D2D2D2D2D2D2D2D2D-
  8944 0000482F 2D2D2D2D2D2D2D2D2D-
  8944 00004838 2D2D2D2D2D2D2D2D2D-
  8944 00004841 2D2D2D2D2D2D2D2D2D-
  8944 0000484A 2D2D2D2D2D2D2D2D   
  8945 00004852 202020202020202020-     	db	"                          Create Primary DOS Partition                          "
  8945 0000485B 202020202020202020-
  8945 00004864 202020202020202043-
  8945 0000486D 726561746520507269-
  8945 00004876 6D61727920444F5320-
  8945 0000487F 506172746974696F6E-
  8945 00004888 202020202020202020-
  8945 00004891 202020202020202020-
  8945 0000489A 2020202020202020   
  8946 000048A2 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"	
  8946 000048AB 2D2D2D2D2D2D2D2D2D-
  8946 000048B4 2D2D2D2D2D2D2D2D2D-
  8946 000048BD 2D2D2D2D2D2D2D2D2D-
  8946 000048C6 2D2D2D2D2D2D2D2D2D-
  8946 000048CF 2D2D2D2D2D2D2D2D2D-
  8946 000048D8 2D2D2D2D2D2D2D2D2D-
  8946 000048E1 2D2D2D2D2D2D2D2D2D-
  8946 000048EA 2D2D2D2D2D2D2D2D   
  8947 000048F2 0D0A00                  	db	0Dh, 0Ah, 0	
  8948                                  
  8949                                  msg_create_dos_partition_h:
  8950 000048F5 0D0A                    	db	0Dh, 0Ah
  8951 000048F7 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"
  8951 00004900 2D2D2D2D2D2D2D2D2D-
  8951 00004909 2D2D2D2D2D2D2D2D2D-
  8951 00004912 2D2D2D2D2D2D2D2D2D-
  8951 0000491B 2D2D2D2D2D2D2D2D2D-
  8951 00004924 2D2D2D2D2D2D2D2D2D-
  8951 0000492D 2D2D2D2D2D2D2D2D2D-
  8951 00004936 2D2D2D2D2D2D2D2D2D-
  8951 0000493F 2D2D2D2D2D2D2D2D   
  8952 00004947 202020202020202020-     	db	"                   Create DOS Partition or Logical DOS Drive                    "
  8952 00004950 202020202020202020-
  8952 00004959 204372656174652044-
  8952 00004962 4F5320506172746974-
  8952 0000496B 696F6E206F72204C6F-
  8952 00004974 676963616C20444F53-
  8952 0000497D 204472697665202020-
  8952 00004986 202020202020202020-
  8952 0000498F 2020202020202020   
  8953 00004997 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"	
  8953 000049A0 2D2D2D2D2D2D2D2D2D-
  8953 000049A9 2D2D2D2D2D2D2D2D2D-
  8953 000049B2 2D2D2D2D2D2D2D2D2D-
  8953 000049BB 2D2D2D2D2D2D2D2D2D-
  8953 000049C4 2D2D2D2D2D2D2D2D2D-
  8953 000049CD 2D2D2D2D2D2D2D2D2D-
  8953 000049D6 2D2D2D2D2D2D2D2D2D-
  8953 000049DF 2D2D2D2D2D2D2D2D   
  8954 000049E7 0D0A00                  	db	0Dh, 0Ah, 0	
  8955                                  
  8956                                  msg_create_ext_partition_h:
  8957 000049EA 0D0A                    	db	0Dh, 0Ah
  8958 000049EC 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"
  8958 000049F5 2D2D2D2D2D2D2D2D2D-
  8958 000049FE 2D2D2D2D2D2D2D2D2D-
  8958 00004A07 2D2D2D2D2D2D2D2D2D-
  8958 00004A10 2D2D2D2D2D2D2D2D2D-
  8958 00004A19 2D2D2D2D2D2D2D2D2D-
  8958 00004A22 2D2D2D2D2D2D2D2D2D-
  8958 00004A2B 2D2D2D2D2D2D2D2D2D-
  8958 00004A34 2D2D2D2D2D2D2D2D   
  8959 00004A3C 202020202020202020-     	db	"                         Create Extended DOS Partition                          "
  8959 00004A45 202020202020202020-
  8959 00004A4E 202020202020204372-
  8959 00004A57 656174652045787465-
  8959 00004A60 6E64656420444F5320-
  8959 00004A69 506172746974696F6E-
  8959 00004A72 202020202020202020-
  8959 00004A7B 202020202020202020-
  8959 00004A84 2020202020202020   
  8960 00004A8C 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"	
  8960 00004A95 2D2D2D2D2D2D2D2D2D-
  8960 00004A9E 2D2D2D2D2D2D2D2D2D-
  8960 00004AA7 2D2D2D2D2D2D2D2D2D-
  8960 00004AB0 2D2D2D2D2D2D2D2D2D-
  8960 00004AB9 2D2D2D2D2D2D2D2D2D-
  8960 00004AC2 2D2D2D2D2D2D2D2D2D-
  8960 00004ACB 2D2D2D2D2D2D2D2D2D-
  8960 00004AD4 2D2D2D2D2D2D2D2D   
  8961 00004ADC 0D0A00                  	db	0Dh, 0Ah, 0
  8962                                  
  8963                                  msg_create_logical_drive_h:
  8964 00004ADF 0D0A                    	db	0Dh, 0Ah
  8965 00004AE1 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"
  8965 00004AEA 2D2D2D2D2D2D2D2D2D-
  8965 00004AF3 2D2D2D2D2D2D2D2D2D-
  8965 00004AFC 2D2D2D2D2D2D2D2D2D-
  8965 00004B05 2D2D2D2D2D2D2D2D2D-
  8965 00004B0E 2D2D2D2D2D2D2D2D2D-
  8965 00004B17 2D2D2D2D2D2D2D2D2D-
  8965 00004B20 2D2D2D2D2D2D2D2D2D-
  8965 00004B29 2D2D2D2D2D2D2D2D   
  8966 00004B31 202020202020202020-     	db	"                            Create Logical DOS Drive                            "
  8966 00004B3A 202020202020202020-
  8966 00004B43 202020202020202020-
  8966 00004B4C 20437265617465204C-
  8966 00004B55 6F676963616C20444F-
  8966 00004B5E 532044726976652020-
  8966 00004B67 202020202020202020-
  8966 00004B70 202020202020202020-
  8966 00004B79 2020202020202020   
  8967 00004B81 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"	
  8967 00004B8A 2D2D2D2D2D2D2D2D2D-
  8967 00004B93 2D2D2D2D2D2D2D2D2D-
  8967 00004B9C 2D2D2D2D2D2D2D2D2D-
  8967 00004BA5 2D2D2D2D2D2D2D2D2D-
  8967 00004BAE 2D2D2D2D2D2D2D2D2D-
  8967 00004BB7 2D2D2D2D2D2D2D2D2D-
  8967 00004BC0 2D2D2D2D2D2D2D2D2D-
  8967 00004BC9 2D2D2D2D2D2D2D2D   
  8968 00004BD1 0D0A00                  	db	0Dh, 0Ah, 0	
  8969                                  
  8970                                  msg_create_nondos_partition_h:
  8971 00004BD4 0D0A                    	db	0Dh, 0Ah
  8972 00004BD6 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"
  8972 00004BDF 2D2D2D2D2D2D2D2D2D-
  8972 00004BE8 2D2D2D2D2D2D2D2D2D-
  8972 00004BF1 2D2D2D2D2D2D2D2D2D-
  8972 00004BFA 2D2D2D2D2D2D2D2D2D-
  8972 00004C03 2D2D2D2D2D2D2D2D2D-
  8972 00004C0C 2D2D2D2D2D2D2D2D2D-
  8972 00004C15 2D2D2D2D2D2D2D2D2D-
  8972 00004C1E 2D2D2D2D2D2D2D2D   
  8973 00004C26 202020202020202020-     	db	"                            Create NON-DOS Partition                            "
  8973 00004C2F 202020202020202020-
  8973 00004C38 202020202020202020-
  8973 00004C41 20437265617465204E-
  8973 00004C4A 4F4E2D444F53205061-
  8973 00004C53 72746974696F6E2020-
  8973 00004C5C 202020202020202020-
  8973 00004C65 202020202020202020-
  8973 00004C6E 2020202020202020   
  8974 00004C76 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"	
  8974 00004C7F 2D2D2D2D2D2D2D2D2D-
  8974 00004C88 2D2D2D2D2D2D2D2D2D-
  8974 00004C91 2D2D2D2D2D2D2D2D2D-
  8974 00004C9A 2D2D2D2D2D2D2D2D2D-
  8974 00004CA3 2D2D2D2D2D2D2D2D2D-
  8974 00004CAC 2D2D2D2D2D2D2D2D2D-
  8974 00004CB5 2D2D2D2D2D2D2D2D2D-
  8974 00004CBE 2D2D2D2D2D2D2D2D   
  8975 00004CC6 0D0A00                  	db	0Dh, 0Ah, 0		
  8976                                  
  8977                                  msg_create_dos_partition_m:
  8978 00004CC9 53656C65637420616E-     	db	"Select an option: "
  8978 00004CD2 206F7074696F6E3A20 
  8979 00004CDB 0D0A                    	db	0Dh, 0Ah
  8980 00004CDD 0D0A                    	db	0Dh, 0Ah
  8981 00004CDF 202031292043726561-     	db	"  1) Create Primary DOS partition ", 0Dh, 0Ah
  8981 00004CE8 7465205072696D6172-
  8981 00004CF1 7920444F5320706172-
  8981 00004CFA 746974696F6E200D0A 
  8982 00004D03 202032292043726561-     	db	"  2) Create Extended DOS partition ", 0Dh, 0Ah			
  8982 00004D0C 746520457874656E64-
  8982 00004D15 656420444F53207061-
  8982 00004D1E 72746974696F6E200D-
  8982 00004D27 0A                 
  8983 00004D28 202033292043726561-     	db	"  3) Create Logical DOS drive(s) in Extended DOS partition ", 0Dh, 0Ah
  8983 00004D31 7465204C6F67696361-
  8983 00004D3A 6C20444F5320647269-
  8983 00004D43 766528732920696E20-
  8983 00004D4C 457874656E64656420-
  8983 00004D55 444F53207061727469-
  8983 00004D5E 74696F6E200D0A     
  8984 00004D65 0D0A                    	db	0Dh, 0Ah	
  8985 00004D67 507265737320455343-     	db	"Press ESC or 0 to cancel .. "
  8985 00004D70 206F72203020746F20-
  8985 00004D79 63616E63656C202E2E-
  8985 00004D82 20                 
  8986 00004D83 0D0A00                   	db 	0Dh, 0Ah, 0
  8987                                  
  8988                                  msg_create_trdos_partition_s:
  8989 00004D86 53656C65637420616E-     	db	"Select an option to set partition size: "
  8989 00004D8F 206F7074696F6E2074-
  8989 00004D98 6F2073657420706172-
  8989 00004DA1 746974696F6E207369-
  8989 00004DAA 7A653A20           
  8990 00004DAE 0D0A                    	db	0Dh, 0Ah
  8991 00004DB0 0D0A                    	db	0Dh, 0Ah
  8992 00004DB2 202043292043796C69-     	db	"  C) Cylinder count", 0Dh, 0Ah   
  8992 00004DBB 6E64657220636F756E-
  8992 00004DC4 740D0A             
  8993 00004DC7 2020252920566F6C75-     	db	"  %) Volume percentage (##%)", 0Dh, 0Ah
  8993 00004DD0 6D652070657263656E-
  8993 00004DD9 746167652028232325-
  8993 00004DE2 290D0A             
  8994 00004DE5 202053292053656374-     	db	"  S) Sectors (number of 512 bytes)", 0Dh, 0Ah
  8994 00004DEE 6F727320286E756D62-
  8994 00004DF7 6572206F6620353132-
  8994 00004E00 206279746573290D0A 
  8995 00004E09 20204B29204B696C6F-     	db	"  K) Kilo bytes (KB, 2*K sectors)", 0Dh, 0Ah
  8995 00004E12 20627974657320284B-
  8995 00004E1B 422C20322A4B207365-
  8995 00004E24 63746F7273290D0A   
  8996 00004E2C 20204D29204D656761-     	db	"  M) Mega bytes (MB, 2*1024*M sectors)", 0Dh, 0Ah
  8996 00004E35 20627974657320284D-
  8996 00004E3E 422C20322A31303234-
  8996 00004E47 2A4D20736563746F72-
  8996 00004E50 73290D0A           
  8997 00004E54 202047292047696761-     	db	"  G) Giga bytes (GB, 2*1024*1024*G sectors)", 0Dh, 0Ah			
  8997 00004E5D 206279746573202847-
  8997 00004E66 422C20322A31303234-
  8997 00004E6F 2A313032342A472073-
  8997 00004E78 6563746F7273290D0A 
  8998 00004E81 0D0A                    	db	0Dh, 0Ah	
  8999 00004E83 507265737320535041-     	db	"Press SPACE to use whole disk or press ENTER to set sector count .. "
  8999 00004E8C 434520746F20757365-
  8999 00004E95 2077686F6C65206469-
  8999 00004E9E 736B206F7220707265-
  8999 00004EA7 737320454E54455220-
  8999 00004EB0 746F20736574207365-
  8999 00004EB9 63746F7220636F756E-
  8999 00004EC2 74202E2E20         
  9000                                  msg_press_esc_to_cancel:
  9001 00004EC7 0D0A                     	db	0Dh, 0Ah
  9002 00004EC9 285072657373204553-     	db	"(Press ESC to CANCEL) "
  9002 00004ED2 4320746F2043414E43-
  9002 00004EDB 454C2920           
  9003 00004EDF 0D0A00                  	db 	0Dh, 0Ah, 0
  9004                                  
  9005                                  msg_use_whole_disk:
  9006 00004EE2 446F20796F75207761-     	db	"Do you want to use WHOLE disk !? (Y/N)", 0
  9006 00004EEB 6E7420746F20757365-
  9006 00004EF4 2057484F4C45206469-
  9006 00004EFD 736B20213F2028592F-
  9006 00004F06 4E2900             
  9007                                  
  9008                                  msg_use_all_space:
  9009 00004F09 446F20796F75207761-     	db	"Do you want to use all of available space !? (Y/N)", 0
  9009 00004F12 6E7420746F20757365-
  9009 00004F1B 20616C6C206F662061-
  9009 00004F24 7661696C61626C6520-
  9009 00004F2D 737061636520213F20-
  9009 00004F36 28592F4E2900       
  9010                                  
  9011                                  msg_use_entire_ep_space:
  9012 00004F3C 446F20796F75207761-     	db	"Do you want to use entire extended partition space !? (Y/N)", 0
  9012 00004F45 6E7420746F20757365-
  9012 00004F4E 20656E746972652065-
  9012 00004F57 7874656E6465642070-
  9012 00004F60 6172746974696F6E20-
  9012 00004F69 737061636520213F20-
  9012 00004F72 28592F4E2900       
  9013                                  
  9014                                  msg_partition_size:
  9015 00004F78 0D0A                    	db	0Dh, 0Ah
  9016 00004F7A 0D0A                    	db	0Dh, 0Ah
  9017 00004F7C 506172746974696F6E-     	db	"Partition size ("
  9017 00004F85 2073697A652028     
  9018                                  msg_partition_size_x:
  9019 00004F8C 3F29203A20              	db	"?) : "
  9020 00004F91 00                      	db	0
  9021                                  
  9022                                  msg_partition_type:
  9023 00004F92 0D0A                    	db	0Dh, 0Ah
  9024 00004F94 0D0A                    	db	0Dh, 0Ah
  9025 00004F96 506172746974696F6E-     	db	"Partition type : "
  9025 00004F9F 2074797065203A20   
  9026 00004FA7 00                      	db	0
  9027                                  
  9028                                  msg_ptype_num:
  9029 00004FA8 3030680D0A00            	db	"00h", 0Dh, 0Ah, 0
  9030                                  
  9031                                  msg_partition_type_error:
  9032 00004FAE 506172746974696F6E-     	db	"Partition size is not proper for selected partition type !"
  9032 00004FB7 2073697A6520697320-
  9032 00004FC0 6E6F742070726F7065-
  9032 00004FC9 7220666F722073656C-
  9032 00004FD2 656374656420706172-
  9032 00004FDB 746974696F6E207479-
  9032 00004FE4 70652021           
  9033 00004FE8 0D0A                    	db	0Dh, 0Ah
  9034                                  msg_any_key_to_retry:
  9035 00004FEA 28507265737320616E-     	db	"(Press any key to retry..)" 
  9035 00004FF3 79206B657920746F20-
  9035 00004FFC 72657472792E2E29   
  9036 00005004 0D0A00                  	db	0Dh, 0Ah, 0
  9037                                  
  9038                                  msg_partition_size_overs:
  9039 00005007 0D0A                    	db	0Dh, 0Ah
  9040 00005009 506172746974696F6E-     	db	"Partition size overs the disk capacity !"
  9040 00005012 2073697A65206F7665-
  9040 0000501B 727320746865206469-
  9040 00005024 736B20636170616369-
  9040 0000502D 74792021           
  9041 00005031 0D0A                    	db	0Dh, 0Ah
  9042 00005033 28507265737320454E-     	db	"(Press ENTER to use WHOLE disk or press ESC key to retry..)" 
  9042 0000503C 54455220746F207573-
  9042 00005045 652057484F4C452064-
  9042 0000504E 69736B206F72207072-
  9042 00005057 65737320455343206B-
  9042 00005060 657920746F20726574-
  9042 00005069 72792E2E29         
  9043 0000506E 0D0A00                  	db	0Dh, 0Ah, 0
  9044                                  
  9045                                  msg_ext_partition_error:
  9046 00005071 457874656E64656420-     	db	"Extended partition must be created after primary partition !"
  9046 0000507A 706172746974696F6E-
  9046 00005083 206D75737420626520-
  9046 0000508C 637265617465642061-
  9046 00005095 66746572207072696D-
  9046 0000509E 617279207061727469-
  9046 000050A7 74696F6E2021       
  9047 000050AD 0D0A00                  	db	0Dh, 0Ah,0
  9048                                  
  9049                                  msg_logical_drive_error:
  9050 000050B0 5072696D6172792061-     	db	"Primary and extended partitions must be created before logical drive !"
  9050 000050B9 6E6420657874656E64-
  9050 000050C2 656420706172746974-
  9050 000050CB 696F6E73206D757374-
  9050 000050D4 206265206372656174-
  9050 000050DD 6564206265666F7265-
  9050 000050E6 206C6F676963616C20-
  9050 000050EF 64726976652021     
  9051 000050F6 0D0A00                  	db	0Dh, 0Ah,0
  9052                                  
  9053                                  msg_cylinder_boundary_set:
  9054 000050F9 0D0A                    	db	0Dh, 0Ah
  9055 000050FB 446F20796F75207761-     	db	"Do you want to adjust partition size to cylinder boundary ? (Y/N)"
  9055 00005104 6E7420746F2061646A-
  9055 0000510D 757374207061727469-
  9055 00005116 74696F6E2073697A65-
  9055 0000511F 20746F2063796C696E-
  9055 00005128 64657220626F756E64-
  9055 00005131 617279203F2028592F-
  9055 0000513A 4E29               
  9056 0000513C 00                      	db	0
  9057                                  
  9058                                  msg_selected_partition:
  9059 0000513D 202020202020202020-     	db	"                                 PARTITION 0                                    "
  9059 00005146 202020202020202020-
  9059 0000514F 202020202020202020-
  9059 00005158 202020202020504152-
  9059 00005161 544954494F4E203020-
  9059 0000516A 202020202020202020-
  9059 00005173 202020202020202020-
  9059 0000517C 202020202020202020-
  9059 00005185 2020202020202020   
  9060 0000518D 3D3D3D3D3D3D3D3D3D-     	db	"================================================================================"
  9060 00005196 3D3D3D3D3D3D3D3D3D-
  9060 0000519F 3D3D3D3D3D3D3D3D3D-
  9060 000051A8 3D3D3D3D3D3D3D3D3D-
  9060 000051B1 3D3D3D3D3D3D3D3D3D-
  9060 000051BA 3D3D3D3D3D3D3D3D3D-
  9060 000051C3 3D3D3D3D3D3D3D3D3D-
  9060 000051CC 3D3D3D3D3D3D3D3D3D-
  9060 000051D5 3D3D3D3D3D3D3D3D   
  9061 000051DD 202020202020202053-     	db	"        S  BH  BS  BC  FS  EH  ES  EC    START SEC   SECTORS   FILE SYSTEM      "
  9061 000051E6 202042482020425320-
  9061 000051EF 204243202046532020-
  9061 000051F8 454820204553202045-
  9061 00005201 432020202053544152-
  9061 0000520A 542053454320202053-
  9061 00005213 4543544F5253202020-
  9061 0000521C 46494C452053595354-
  9061 00005225 454D202020202020   
  9062 0000522D 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"
  9062 00005236 2D2D2D2D2D2D2D2D2D-
  9062 0000523F 2D2D2D2D2D2D2D2D2D-
  9062 00005248 2D2D2D2D2D2D2D2D2D-
  9062 00005251 2D2D2D2D2D2D2D2D2D-
  9062 0000525A 2D2D2D2D2D2D2D2D2D-
  9062 00005263 2D2D2D2D2D2D2D2D2D-
  9062 0000526C 2D2D2D2D2D2D2D2D2D-
  9062 00005275 2D2D2D2D2D2D2D2D   
  9063 0000527D 202020202020202020-     pt_row:	db	"                                                                                "
  9063 00005286 202020202020202020-
  9063 0000528F 202020202020202020-
  9063 00005298 202020202020202020-
  9063 000052A1 202020202020202020-
  9063 000052AA 202020202020202020-
  9063 000052B3 202020202020202020-
  9063 000052BC 202020202020202020-
  9063 000052C5 2020202020202020   
  9064 000052CD 3D3D3D3D3D3D3D3D3D-     	db	"================================================================================"
  9064 000052D6 3D3D3D3D3D3D3D3D3D-
  9064 000052DF 3D3D3D3D3D3D3D3D3D-
  9064 000052E8 3D3D3D3D3D3D3D3D3D-
  9064 000052F1 3D3D3D3D3D3D3D3D3D-
  9064 000052FA 3D3D3D3D3D3D3D3D3D-
  9064 00005303 3D3D3D3D3D3D3D3D3D-
  9064 0000530C 3D3D3D3D3D3D3D3D3D-
  9064 00005315 3D3D3D3D3D3D3D3D   
  9065 0000531D 00                      	db	0
  9066                                  msg_boot_indicator:
  9067 0000531E 0D0A                    	db	0Dh, 0Ah
  9068 00005320 20202020426F6F7420-     	db	"    Boot Indicator : ", 0 ; "YES", "NO"
  9068 00005329 496E64696361746F72-
  9068 00005332 203A2000           
  9069                                  msg_starting_head:
  9070 00005336 0D0A                    	db	0Dh, 0Ah
  9071 00005338 202020202053746172-     	db 	"     Starting Head : ", 0
  9071 00005341 74696E672048656164-
  9071 0000534A 203A2000           
  9072                                  msg_starting_sector:
  9073 0000534E 0D0A                    	db	0Dh, 0Ah
  9074 00005350 202020537461727469-     	db	"   Starting Sector : ", 0
  9074 00005359 6E6720536563746F72-
  9074 00005362 203A2000           
  9075                                  msg_starting_cylinder:
  9076 00005366 0D0A                    	db	0Dh, 0Ah
  9077 00005368 205374617274696E67-     	db	" Starting Cylinder : ", 0
  9077 00005371 2043796C696E646572-
  9077 0000537A 203A2000           
  9078                                  msg_system_id:
  9079 0000537E 0D0A                    	db	0Dh, 0Ah
  9080 00005380 202020202020202020-     	db	"         System ID : ", 0
  9080 00005389 53797374656D204944-
  9080 00005392 203A2000           
  9081                                  msg_ending_head:
  9082 00005396 0D0A                    	db	0Dh, 0Ah
  9083 00005398 20202020202020456E-     	db 	"       Ending Head : ", 0
  9083 000053A1 64696E672048656164-
  9083 000053AA 203A2000           
  9084                                  msg_ending_sector:
  9085 000053AE 0D0A                    	db	0Dh, 0Ah
  9086 000053B0 2020202020456E6469-     	db	"     Ending Sector : ", 0
  9086 000053B9 6E6720536563746F72-
  9086 000053C2 203A2000           
  9087                                  msg_ending_cylinder:
  9088 000053C6 0D0A                    	db	0Dh, 0Ah
  9089 000053C8 202020456E64696E67-     	db	"   Ending Cylinder : ", 0
  9089 000053D1 2043796C696E646572-
  9089 000053DA 203A2000           
  9090                                  msg_relative_sectors:
  9091 000053DE 0D0A                    	db	0Dh, 0Ah
  9092 000053E0 0D0A                    	db	0Dh, 0Ah
  9093 000053E2 202052656C61746976-     	db	"  Relative Sectors : ", 0
  9093 000053EB 6520536563746F7273-
  9093 000053F4 203A2000           
  9094                                  msg_total_sectors:
  9095 000053F8 0D0A                    	db	0Dh, 0Ah
  9096 000053FA 2020202020546F7461-     	db	"     Total Sectors : ", 0
  9096 00005403 6C20536563746F7273-
  9096 0000540C 203A2000           
  9097                                  
  9098                                  msg_format_stage:
  9099 00005410 0D0A                    	db	0Dh, 0Ah
  9100 00005412 507265737320454E54-     	db	"Press ENTER to FORMAT disk partition "
  9100 0000541B 455220746F20464F52-
  9100 00005424 4D4154206469736B20-
  9100 0000542D 706172746974696F6E-
  9100 00005436 20                 
  9101                                  partition_num_chr:
  9102 00005437 30                      	db	"0"
  9103 00005438 206F72207072657373-     	db	" or press ESC to EXIT.."
  9103 00005441 2045534320746F2045-
  9103 0000544A 5849542E2E         
  9104 0000544F 00                      	db	0
  9105                                  msg_partition_edit:
  9106 00005450 0D0A                    	db	0Dh, 0Ah
  9107 00005452 2E2E206F7220707265-     	db	".. or press SPACE to EDIT partition table."
  9107 0000545B 737320535041434520-
  9107 00005464 746F20454449542070-
  9107 0000546D 6172746974696F6E20-
  9107 00005476 7461626C652E       
  9108 0000547C 0D0A00                  	db	0Dh, 0Ah, 0
  9109                                  
  9110                                  msg_edit_or_exit:
  9111 0000547F 0D0A                    	db 	0Dh, 0Ah
  9112 00005481 507265737320454E54-     	db	"Press ENTER to continue or press ESC to exit.."
  9112 0000548A 455220746F20636F6E-
  9112 00005493 74696E7565206F7220-
  9112 0000549C 707265737320455343-
  9112 000054A5 20746F20657869742E-
  9112 000054AE 2E                 
  9113 000054AF 00                      	db	0
  9114                                  
  9115                                  msg_overwrite_question1:
  9116 000054B0 0D0A                    	db	0Dh, 0Ah
  9117 000054B2 446F20796F75207761-     	db	'Do you want to overwrite '
  9117 000054BB 6E7420746F206F7665-
  9117 000054C4 72777269746520     
  9118 000054CB 27                      	db	27h
  9119 000054CC 00                      	db	0
  9120                                  
  9121                                  msg_overwrite_question2: 
  9122 000054CD 27                      	db	27h
  9123 000054CE 2066696C6520            	db	' file '
  9124 000054D4 00                      	db	0
  9125                                  
  9126                                  msg_format_question:
  9127 000054D5 0D0A                    	db	0Dh, 0Ah
  9128 000054D7 446F20796F75207761-     	db	"Do you want to format partition "
  9128 000054E0 6E7420746F20666F72-
  9128 000054E9 6D6174207061727469-
  9128 000054F2 74696F6E20         
  9129                                  partition_num_txt:
  9130 000054F7 3020                    	db	 "0 "
  9131                                  msg_yes_no:
  9132 000054F9 285965732F4E6F293F-     	db	'(Yes/No)? ', 0		
  9132 00005502 2000               
  9133                                  
  9134                                  msg_writing_mbr:
  9135 00005504 57726974696E67206D-     	db	"Writing masterboot sector...", 0
  9135 0000550D 6173746572626F6F74-
  9135 00005516 20736563746F722E2E-
  9135 0000551F 2E00               
  9136                                  
  9137                                  msg_writing_disk_sectors:
  9138 00005521 57726974696E672064-     	db	"Writing disk sector: ", 0
  9138 0000552A 69736B20736563746F-
  9138 00005533 723A2000           
  9139                                  
  9140                                  Msg_Writing_Boot_Sector:
  9141 00005537 57726974696E672074-     	db	"Writing trdos boot sector...", 0
  9141 00005540 72646F7320626F6F74-
  9141 00005549 20736563746F722E2E-
  9141 00005552 2E00               
  9142                                  
  9143                                  Msg_Writing_Root_Dir:
  9144 00005554 57726974696E672072-     	db	"Writing root directory sectors...", 0
  9144 0000555D 6F6F74206469726563-
  9144 00005566 746F72792073656374-
  9144 0000556F 6F72732E2E2E00     
  9145                                  
  9146                                  Msg_Writing_Data_Sectors:
  9147 00005576 57726974696E672064-     	db	"Writing data sector: ", 0
  9147 0000557F 61746120736563746F-
  9147 00005588 723A2000           
  9148                                  
  9149                                  Sector_Str:
  9150 0000558C 3030303030303000        	db	"0000000", 0
  9151                                  Cursor_Pos:
  9152 00005594 0000                    	dw	0
  9153                                  
  9154                                  Msg_Writing_FAT_Sectors:
  9155 00005596 57726974696E672046-     	db	"Writing FAT sectors...", 0
  9155 0000559F 415420736563746F72-
  9155 000055A8 732E2E2E00         
  9156                                  
  9157                                  StrVolumeName:
  9158                                  	;times 	12 db  0
  9159 000055AD 00<rep 41h>             	times	65 db 0  ; 05/01/2018 (fs1 volume name)	
  9160                                  
  9161                                  Msg_Volume_Name:
  9162 000055EE 0D0A                    	db	0Dh, 0Ah
  9163 000055F0 0D0A                    	db	0Dh, 0Ah
  9164 000055F2 566F6C756D65204E61-     	db	"Volume Name: ", 0
  9164 000055FB 6D653A2000         
  9165                                  
  9166                                  Msg_Volume_Serial:
  9167 00005600 566F6C756D65205365-     	db	"Volume Serial No: "
  9167 00005609 7269616C204E6F3A20 
  9168                                  Vol_Serial1:
  9169 00005612 30303030                	db	"0000"
  9170 00005616 2D                      	db	"-"
  9171                                  Vol_Serial2:
  9172 00005617 30303030                	db	"0000"
  9173 0000561B 0D0A00                  	db	0Dh, 0Ah, 0
  9174                                  
  9175                                  msg_cluster_count:
  9176 0000561E 436C75737465722043-     	db	"Cluster Count: ", 0
  9176 00005627 6F756E743A2000     
  9177                                  cluster_count_str:
  9178 0000562E 30303030303030          	db	"0000000"
  9179 00005635 0D0A00                  	db	0Dh, 0Ah, 0
  9180                                  msg_formatting:
  9181 00005638 466F726D617474696E-     	db	"Formatting ", 0
  9181 00005641 672000             
  9182                                  format_percent_str:
  9183 00005644 30303025                	db	"000%"
  9184 00005648 00                      	db	0					
  9185                                  
  9186                                  Msg_3dot_OK:
  9187 00005649 2E2E2E                  	db	"..."
  9188                                  Msg_OK:
  9189 0000564C 204F4B2E                	db	' OK.'
  9190                                  CRLF:
  9191 00005650 0D0A00                  	db	0Dh, 0Ah, 0
  9192                                  
  9193                                  Msg_Error:
  9194 00005653 0D0A                    	db	0Dh, 0Ah
  9195 00005655 4572726F72202120        	db	'Error ! '
  9196 0000565D 28                      	db	'('
  9197                                  error_code:
  9198 0000565E 3030                    	dw	3030h
  9199 00005660 68                      	db	'h'
  9200 00005661 2920                    	db	') '
  9201 00005663 0D0A                    	db	0Dh, 0Ah
  9202 00005665 00                      	db	0
  9203                                  
  9204                                  msg_disk_sectors:
  9205 00005666 546F74616C20446973-     	db	"Total Disk Sectors : ", 0
  9205 0000566F 6B20536563746F7273-
  9205 00005678 203A2000           
  9206                                  
  9207                                  str_disk_sectors:
  9208 0000567C 00<rep 8h>              	times	8 db 0
  9209                                  
  9210                                  msg_ep_size:
  9211 00005684 457874656E64656420-     	db	"Extended Partition Size in Sectors: ", 0
  9211 0000568D 506172746974696F6E-
  9211 00005696 2053697A6520696E20-
  9211 0000569F 536563746F72733A20-
  9211 000056A8 00                 
  9212                                  
  9213                                  msg_file_size:
  9214 000056A9 484420496D61676520-     	db	"HD Image File Size : ", 0
  9214 000056B2 46696C652053697A65-
  9214 000056BB 203A2000           
  9215                                  
  9216                                  str_file_size:
  9217 000056BF 00<rep Bh>              	times	11 db 0
  9218                                  
  9219                                  msg_bytes:
  9220 000056CA 206279746573            	db	" bytes"
  9221 000056D0 0D0A00                  	db	0Dh, 0Ah, 0
  9222                                  
  9223                                  msg_enter_cancel:
  9224 000056D3 0D0A                    	db	0Dh, 0Ah
  9225 000056D5 507265737320454E54-     	db	"Press ENTER to write file or press ESC to cancel." 
  9225 000056DE 455220746F20777269-
  9225 000056E7 74652066696C65206F-
  9225 000056F0 722070726573732045-
  9225 000056F9 534320746F2063616E-
  9225 00005702 63656C2E           
  9226 00005706 0D0A00                  	db	0Dh, 0Ah, 0
  9227                                  
  9228                                  msg_press_any_key:
  9229 00005709 0D0A                    	db	0Dh, 0Ah
  9230 0000570B 50726573732061206B-     	db	"Press a key to continue..." 
  9230 00005714 657920746F20636F6E-
  9230 0000571D 74696E75652E2E2E   
  9231 00005725 0D0A00                  	db	0Dh, 0Ah, 0
  9232                                  
  9233                                  align 2
  9234                                  
  9235                                  ; Masterboot sector
  9236                                  
  9237                                  MasterBootBuff:
  9238                                  MasterBootCode: 
  9239 00005728 00<rep 1BEh>            	times	446 db 0
  9240                                  PartitionTable:
  9241 000058E6 00<rep 40h>             	times	64 db 0
  9242                                  MBIDCode:
  9243 00005926 0000                    	dw	0
  9244                                  
  9245                                  PTable_Buffer:
  9246 00005928 00<rep 40h>             	times	64 db 0
  9247                                   
  9248 00005968 286329204572646F67-     	db	'(c) Erdogan TAN 2019-2024'
  9248 00005971 616E2054414E203230-
  9248 0000597A 31392D32303234     
  9249                                  
  9250                                  img_file_name:  
  9251 00005981 00<rep Dh>              	times	13 db 0
  9252                                  
  9253                                  p_table_header:
  9254 0000598E 202020202020202020-     	db	"                              ?BR PARTITION TABLE                               "
  9254 00005997 202020202020202020-
  9254 000059A0 202020202020202020-
  9254 000059A9 2020203F4252205041-
  9254 000059B2 52544954494F4E2054-
  9254 000059BB 41424C452020202020-
  9254 000059C4 202020202020202020-
  9254 000059CD 202020202020202020-
  9254 000059D6 2020202020202020   
  9255 000059DE 3D3D3D3D3D3D3D3D3D-     	db	"================================================================================"
  9255 000059E7 3D3D3D3D3D3D3D3D3D-
  9255 000059F0 3D3D3D3D3D3D3D3D3D-
  9255 000059F9 3D3D3D3D3D3D3D3D3D-
  9255 00005A02 3D3D3D3D3D3D3D3D3D-
  9255 00005A0B 3D3D3D3D3D3D3D3D3D-
  9255 00005A14 3D3D3D3D3D3D3D3D3D-
  9255 00005A1D 3D3D3D3D3D3D3D3D3D-
  9255 00005A26 3D3D3D3D3D3D3D3D   
  9256 00005A2E 202020202020205020-     	db	"       P  S  BH  BS  BC  FS  EH  ES  EC  START SEC  SECTORS  FILE SYSTEM        "
  9256 00005A37 205320204248202042-
  9256 00005A40 532020424320204653-
  9256 00005A49 202045482020455320-
  9256 00005A52 204543202053544152-
  9256 00005A5B 542053454320205345-
  9256 00005A64 43544F525320204649-
  9256 00005A6D 4C452053595354454D-
  9256 00005A76 2020202020202020   
  9257 00005A7E 2D2D2D2D2D2D2D2D2D-     	db	"--------------------------------------------------------------------------------"
  9257 00005A87 2D2D2D2D2D2D2D2D2D-
  9257 00005A90 2D2D2D2D2D2D2D2D2D-
  9257 00005A99 2D2D2D2D2D2D2D2D2D-
  9257 00005AA2 2D2D2D2D2D2D2D2D2D-
  9257 00005AAB 2D2D2D2D2D2D2D2D2D-
  9257 00005AB4 2D2D2D2D2D2D2D2D2D-
  9257 00005ABD 2D2D2D2D2D2D2D2D2D-
  9257 00005AC6 2D2D2D2D2D2D2D2D   
  9258 00005ACE 00                      	db	0
  9259                                  p_table_footer:
  9260 00005ACF 3D3D3D3D3D3D3D3D3D-     	db	"================================================================================"
  9260 00005AD8 3D3D3D3D3D3D3D3D3D-
  9260 00005AE1 3D3D3D3D3D3D3D3D3D-
  9260 00005AEA 3D3D3D3D3D3D3D3D3D-
  9260 00005AF3 3D3D3D3D3D3D3D3D3D-
  9260 00005AFC 3D3D3D3D3D3D3D3D3D-
  9260 00005B05 3D3D3D3D3D3D3D3D3D-
  9260 00005B0E 3D3D3D3D3D3D3D3D3D-
  9260 00005B17 3D3D3D3D3D3D3D3D   
  9261 00005B1F 0D0A00                  	db	0Dh,0Ah,0
  9262                                  
  9263                                  mbr_editing_options:
  9264 00005B22 0D0A0D0A                	db 0Dh, 0Ah, 0Dh, 0Ah 
  9265 00005B26 4D4252205061727469-     	db "MBR Partition Table Editing Options:" 
  9265 00005B2F 74696F6E205461626C-
  9265 00005B38 652045646974696E67-
  9265 00005B41 204F7074696F6E733A 
  9266 00005B4A 0D0A0D0A                	db 0Dh, 0Ah, 0Dh, 0Ah
  9267 00005B4E 20202020202020312E-     	db "       1. Create Partition", 0Dh, 0Ah
  9267 00005B57 204372656174652050-
  9267 00005B60 6172746974696F6E0D-
  9267 00005B69 0A                 
  9268 00005B6A 20202020202020322E-     	db "       2. Set Active Partition", 0Dh, 0Ah
  9268 00005B73 205365742041637469-
  9268 00005B7C 766520506172746974-
  9268 00005B85 696F6E0D0A         
  9269 00005B8A 20202020202020332E-     	db "       3. Delete Partition", 0Dh, 0Ah  
  9269 00005B93 2044656C6574652050-
  9269 00005B9C 6172746974696F6E0D-
  9269 00005BA5 0A                 
  9270 00005BA6 20202020202020342E-     	db "       4. Write Current Partition Table", 0Dh, 0Ah, 0
  9270 00005BAF 205772697465204375-
  9270 00005BB8 7272656E7420506172-
  9270 00005BC1 746974696F6E205461-
  9270 00005BCA 626C650D0A00       
  9271                                  
  9272                                  enter_option_number_msg:
  9273 00005BD0 0D0A                    	db 0Dh, 0Ah
  9274 00005BD2 456E74657220746865-     	db "Enter the option number or press ESC to exit ...", 0Dh, 0Ah
  9274 00005BDB 206F7074696F6E206E-
  9274 00005BE4 756D626572206F7220-
  9274 00005BED 707265737320455343-
  9274 00005BF6 20746F206578697420-
  9274 00005BFF 2E2E2E0D0A         
  9275                                  	;db 0Dh, 0Ah, 0
  9276 00005C04 00                      	db 0 
  9277                                  
  9278                                  msg_zero_partition_size:  ; 19/02/2019
  9279 00005C05 0D0A                    	db	0Dh, 0Ah
  9280 00005C07 506172746974696F6E-     	db	"Partition size input must not be ZERO !", 0Dh, 0Ah
  9280 00005C10 2073697A6520696E70-
  9280 00005C19 7574206D757374206E-
  9280 00005C22 6F74206265205A4552-
  9280 00005C2B 4F20210D0A         
  9281 00005C30 285072657373204553-     	db	"(Press ESC to exit or press another key to retry..)", 0Dh, 0Ah
  9281 00005C39 4320746F2065786974-
  9281 00005C42 206F72207072657373-
  9281 00005C4B 20616E6F7468657220-
  9281 00005C54 6B657920746F207265-
  9281 00005C5D 7472792E2E290D0A   
  9282 00005C65 00                      	db	0 
  9283                                  
  9284                                  msg_empty_pt:
  9285 00005C66 0D0A                    	db	0Dh, 0Ah
  9286 00005C68 456D70747920706172-     	db	"Empty partition table !", 0Dh, 0Ah
  9286 00005C71 746974696F6E207461-
  9286 00005C7A 626C6520210D0A     
  9287 00005C81 28412076616C696420-     	db	"(A valid partition must be created at first..)", 0Dh, 0Ah
  9287 00005C8A 706172746974696F6E-
  9287 00005C93 206D75737420626520-
  9287 00005C9C 637265617465642061-
  9287 00005CA5 742066697273742E2E-
  9287 00005CAE 290D0A             
  9288 00005CB1 00                      	db	0
  9289                                  
  9290                                  msg_full_pt:
  9291 00005CB2 0D0A                    	db	0Dh, 0Ah
  9292 00005CB4 546865726520697320-     	db	"There is not a free partition table entry ", 0
  9292 00005CBD 6E6F74206120667265-
  9292 00005CC6 652070617274697469-
  9292 00005CCF 6F6E207461626C6520-
  9292 00005CD8 656E7472792000     
  9293                                  msg_to_create_new_p: 
  9294 00005CDF 746F20637265617465-     	db	"to create a new partition !", 0Dh, 0Ah
  9294 00005CE8 2061206E6577207061-
  9294 00005CF1 72746974696F6E2021-
  9294 00005CFA 0D0A               
  9295 00005CFC 00                      	db	0
  9296                                  msg_no_free_space:
  9297 00005CFD 0D0A                    	db	0Dh, 0Ah
  9298 00005CFF 546865726520697320-     	db	"There is not (enough) free space ", 0
  9298 00005D08 6E6F742028656E6F75-
  9298 00005D11 676829206672656520-
  9298 00005D1A 73706163652000     
  9299                                  
  9300                                  msg_enter_pn_to_del:
  9301 00005D21 0D0A                    	db	0Dh, 0Ah
  9302 00005D23 456E74657220706172-     	db	"Enter partition number to delete: " 
  9302 00005D2C 746974696F6E206E75-
  9302 00005D35 6D62657220746F2064-
  9302 00005D3E 656C6574653A20     
  9303                                  chr_del_pnum1:
  9304 00005D45 00                      	db	0       
  9305 00005D46 0D0A00                  	db	0Dh, 0Ah, 0
  9306                                  
  9307                                  msg_delete_partition_q:
  9308 00005D49 0D0A                    	db 	0Dh, 0Ah
  9309 00005D4B 5741524E494E472120-     	db 	"WARNING! All of data in the selected partition will be lost", 0Dh, 0Ah
  9309 00005D54 416C6C206F66206461-
  9309 00005D5D 746120696E20746865-
  9309 00005D66 2073656C6563746564-
  9309 00005D6F 20706172746974696F-
  9309 00005D78 6E2077696C6C206265-
  9309 00005D81 206C6F73740D0A     
  9310 00005D88 202020202020202020-     	db	"         after you write changed partition table to disk !!", 0Dh, 0Ah
  9310 00005D91 616674657220796F75-
  9310 00005D9A 207772697465206368-
  9310 00005DA3 616E67656420706172-
  9310 00005DAC 746974696F6E207461-
  9310 00005DB5 626C6520746F206469-
  9310 00005DBE 736B2021210D0A     
  9311 00005DC5 0D0A                    	db	0Dh, 0Ah
  9312 00005DC7 446F20796F75207761-     	db	"Do you want to delete PARTITION " 
  9312 00005DD0 6E7420746F2064656C-
  9312 00005DD9 657465205041525449-
  9312 00005DE2 54494F4E20         
  9313                                  chr_del_pnum2:
  9314 00005DE7 30                      	db	'0'
  9315 00005DE8 203F2028592F4E2920-     	db	' ? (Y/N) ', 0
  9315 00005DF1 00                 
  9316                                  
  9317                                  _msg_YES:
  9318 00005DF2 20                      	db	 20h
  9319                                  msg_YES:
  9320 00005DF3 5945532000              	db	'YES ', 0
  9321                                  _msg_NO:
  9322 00005DF8 20                      	db	20h
  9323                                  msg_NO:
  9324 00005DF9 4E4F2000                	db	'NO ', 0
  9325                                  
  9326                                  ; 11/02/2019
  9327                                  msg_write_masterboot_sector:
  9328 00005DFD 0D0A                    	db	0Dh, 0Ah 
  9329 00005DFF 577269746520437572-     	db	"Write Current Partition Table:" 
  9329 00005E08 72656E742050617274-
  9329 00005E11 6974696F6E20546162-
  9329 00005E1A 6C653A             
  9330 00005E1D 0D0A0D0A                	db	0Dh, 0Ah, 0Dh, 0Ah
  9331 00005E21 20312E205772697465-     	db	" 1. Write Partition Table only", 0Dh, 0Ah
  9331 00005E2A 20506172746974696F-
  9331 00005E33 6E205461626C65206F-
  9331 00005E3C 6E6C790D0A         
  9332 00005E41 20322E205772697465-     	db	" 2. Write Partition Table and Singlix Master Boot Code", 0Dh, 0Ah
  9332 00005E4A 20506172746974696F-
  9332 00005E53 6E205461626C652061-
  9332 00005E5C 6E642053696E676C69-
  9332 00005E65 78204D617374657220-
  9332 00005E6E 426F6F7420436F6465-
  9332 00005E77 0D0A               
  9333                                  enter_opt_num_cancel_msg:
  9334 00005E79 0D0A                    	db	0Dh, 0Ah
  9335 00005E7B 456E74657220746865-     	db	"Enter the option number or press ESC to cancel ...", 0           
  9335 00005E84 206F7074696F6E206E-
  9335 00005E8D 756D626572206F7220-
  9335 00005E96 707265737320455343-
  9335 00005E9F 20746F2063616E6365-
  9335 00005EA8 6C202E2E2E00       
  9336                                  
  9337                                  msg_writing_ptable:
  9338 00005EAE 0D0A0D0A                	db	0Dh, 0Ah, 0Dh, 0Ah  
  9339 00005EB2 57726974696E672070-     	db	"Writing partition table on disk ... ", 0
  9339 00005EBB 6172746974696F6E20-
  9339 00005EC4 7461626C65206F6E20-
  9339 00005ECD 6469736B202E2E2E20-
  9339 00005ED6 00                 
  9340                                  _msg_OK:
  9341                                  	;db	7
  9342 00005ED7 0D0A                    	db	0Dh, 0Ah
  9343 00005ED9 4F4B2021                	db	"OK !"
  9344 00005EDD 0D0A00                  	db	0Dh, 0Ah, 0
  9345                                  
  9346                                  option_input:
  9347 00005EE0 205B205D00              	db	' [ ]', 0
  9348                                  
  9349                                  msg_enter_pn_to_act:
  9350 00005EE5 0D0A                    	db	0Dh, 0Ah
  9351 00005EE7 456E74657220706172-     	db	"Enter partition number to set as active: ", 0 
  9351 00005EF0 746974696F6E206E75-
  9351 00005EF9 6D62657220746F2073-
  9351 00005F02 657420617320616374-
  9351 00005F0B 6976653A2000       
  9352                                  
  9353                                  trdos386_disk_chs_header:
  9354 00005F11 0D0A                    	db	0Dh, 0Ah
  9355 00005F13 202020202020202020-     	db	"                     TRDOS 386 (SINGLIX) HARD DISK IMAGE                        "
  9355 00005F1C 202020202020202020-
  9355 00005F25 2020205452444F5320-
  9355 00005F2E 333836202853494E47-
  9355 00005F37 4C4958292048415244-
  9355 00005F40 204449534B20494D41-
  9355 00005F49 474520202020202020-
  9355 00005F52 202020202020202020-
  9355 00005F5B 2020202020202020   
  9356 00005F63 00                      	db 	0
  9357                                  
  9358                                  disk_chs_header:
  9359 00005F64 0D0A                    	db	0Dh, 0Ah
  9360 00005F66 202020202020202020-     	db	"                                HARD DISK IMAGE                                 "
  9360 00005F6F 202020202020202020-
  9360 00005F78 202020202020202020-
  9360 00005F81 202020202048415244-
  9360 00005F8A 204449534B20494D41-
  9360 00005F93 474520202020202020-
  9360 00005F9C 202020202020202020-
  9360 00005FA5 202020202020202020-
  9360 00005FAE 2020202020202020   
  9361 00005FB6 00                      	db 	0
  9362                                  
  9363                                  msg_partition_size_limit:
  9364 00005FB7 0D0A                    	db	0Dh, 0Ah
  9365 00005FB9 506172746974696F6E-     	db	"Partition size overs available free space !"
  9365 00005FC2 2073697A65206F7665-
  9365 00005FCB 727320617661696C61-
  9365 00005FD4 626C65206672656520-
  9365 00005FDD 73706163652021     
  9366 00005FE4 0D0A                    	db	0Dh, 0Ah
  9367 00005FE6 4D61782E2061766169-     	db 	"Max. available free space is ", 0
  9367 00005FEF 6C61626C6520667265-
  9367 00005FF8 652073706163652069-
  9367 00006001 732000             
  9368                                  
  9369                                  msg_partition_size_limit_r:
  9370 00006004 0D0A0D0A                	db	0Dh, 0Ah, 0Dh, 0Ah
  9371 00006008 28507265737320454E-     	db	"(Press ENTER to use all of available space or press ESC key to retry..) " 
  9371 00006011 54455220746F207573-
  9371 0000601A 6520616C6C206F6620-
  9371 00006023 617661696C61626C65-
  9371 0000602C 207370616365206F72-
  9371 00006035 207072657373204553-
  9371 0000603E 43206B657920746F20-
  9371 00006047 72657472792E2E2920 
  9372 00006050 000A00                  	db	0D, 0Ah, 0
  9373                                  
  9374                                  msg_cylinders:
  9375 00006053 2063796C696E646572-     	db	" cylinders", 0
  9375 0000605C 7300               
  9376                                  msg_sectors:
  9377 0000605E 20736563746F727300      	db	" sectors", 0
  9378                                  
  9379                                  ; 02/03/2019
  9380                                  msg_megabytes:
  9381 00006067 206D65676162797465      	db	" megabyte"
  9382                                  msg_megabytes_s:
  9383 00006070 0000                    	db	0, 0
  9384                                  
  9385                                  msg_inv_pte:
  9386 00006072 0D0A                    	db	0Dh, 0Ah
  9387 00006074 496E76616C69642070-     	db	"Invalid partition table entry ! (P"
  9387 0000607D 6172746974696F6E20-
  9387 00006086 7461626C6520656E74-
  9387 0000608F 72792021202850     
  9388 00006096 3F290D0A                inv_pte_num: db	"?)", 0Dh, 0Ah
  9389 0000609A 28507265737320454E-     	db	"(Press ENTER to DELETE or press ESC to EXIT..)"
  9389 000060A3 54455220746F204445-
  9389 000060AC 4C455445206F722070-
  9389 000060B5 726573732045534320-
  9389 000060BE 746F20455849542E2E-
  9389 000060C7 29                 
  9390 000060C8 0D0A00                  	db	0Dh, 0Ah, 0
  9391                                  
  9392                                  msg_ext_partition_exists:
  9393 000060CB 457874656E64656420-     	db	"Extended partition already exists !"
  9393 000060D4 706172746974696F6E-
  9393 000060DD 20616C726561647920-
  9393 000060E6 6578697374732021   
  9394 000060EE 0D0A00                  	db	0Dh, 0Ah, 0
  9395                                  
  9396                                  msg_defective_pt:
  9397 000060F1 0D0A                    	db	0Dh, 0Ah
  9398 000060F3 446566656374697665-     	db	"Defective partition table !", 0
  9398 000060FC 20706172746974696F-
  9398 00006105 6E207461626C652021-
  9398 0000610E 00                 
  9399                                  
  9400                                  ; 27/02/2019
  9401                                  msg_ext_part_del_error:
  9402 0000610F 0D0A                    	db	0Dh, 0Ah
  9403 00006111 457874656E64656420-     	db	"Extended partition must be deleted after logical drive(s) !"
  9403 0000611A 706172746974696F6E-
  9403 00006123 206D75737420626520-
  9403 0000612C 64656C657465642061-
  9403 00006135 66746572206C6F6769-
  9403 0000613E 63616C206472697665-
  9403 00006147 2873292021         
  9404 0000614C 0D0A00                  	db	0Dh, 0Ah, 0
  9405                                  
  9406                                  msg_cancel_continue:
  9407 0000614F 285072657373204553-     	db	"(Press ESC to cancel or press another key to continue..)"
  9407 00006158 4320746F2063616E63-
  9407 00006161 656C206F7220707265-
  9407 0000616A 737320616E6F746865-
  9407 00006173 72206B657920746F20-
  9407 0000617C 636F6E74696E75652E-
  9407 00006185 2E29               
  9408 00006187 0D0A00                  	db	0Dh, 0Ah, 0
  9409                                  
  9410                                  msg_delete_ldd:
  9411 0000618A 0D0A                    	db	0Dh, 0Ah
  9412 0000618C 0D0A                    	db	0Dh, 0Ah
  9413 0000618E 44656C657465204C6F-     	db	"Delete Logical (DOS) Drive:"
  9413 00006197 676963616C2028444F-
  9413 000061A0 53292044726976653A 
  9414 000061A9 0D0A                    	db	0Dh, 0Ah
  9415 000061AB 50726573732044454C-     	db	"Press DELETE key to delete logical disk partition "
  9415 000061B4 455445206B65792074-
  9415 000061BD 6F2064656C65746520-
  9415 000061C6 6C6F676963616C2064-
  9415 000061CF 69736B207061727469-
  9415 000061D8 74696F6E20         
  9416 000061DD 3F2E                    lddp_num: db	"?."
  9417 000061DF 0D0A00                  	db	0Dh, 0Ah, 0
  9418                                  
  9419                                  msg_delete_ext_part:
  9420 000061E2 0D0A                    	db	0Dh, 0Ah
  9421 000061E4 0D0A                    	db	0Dh, 0Ah
  9422 000061E6 44656C657465204578-     	db	"Delete Extended (DOS) Partition:"
  9422 000061EF 74656E646564202844-
  9422 000061F8 4F5329205061727469-
  9422 00006201 74696F6E3A         
  9423 00006206 0D0A                    	db	0Dh, 0Ah
  9424 00006208 507265737320454E54-     	db	"Press ENTER to delete or press ESC to cancel.."
  9424 00006211 455220746F2064656C-
  9424 0000621A 657465206F72207072-
  9424 00006223 657373204553432074-
  9424 0000622C 6F2063616E63656C2E-
  9424 00006235 2E                 
  9425 00006236 0D0A00                  	db	0Dh, 0Ah, 0
  9426                                  
  9427                                  str_display_ebr_pt:
  9428 00006239 285072657373205350-     	db	"(Press SPACE to edit EXTENDED Partition Table)", 0Dh, 0Ah, 0
  9428 00006242 41434520746F206564-
  9428 0000624B 697420455854454E44-
  9428 00006254 454420506172746974-
  9428 0000625D 696F6E205461626C65-
  9428 00006266 290D0A00           
  9429                                  
  9430                                  ebr_editing_options:
  9431 0000626A 0D0A0D0A                	db 0Dh, 0Ah, 0Dh, 0Ah 
  9432 0000626E 457874656E64656420-     	db "Extended Partition Table Editing Options:" 
  9432 00006277 506172746974696F6E-
  9432 00006280 205461626C65204564-
  9432 00006289 6974696E67204F7074-
  9432 00006292 696F6E733A         
  9433 00006297 0D0A0D0A                	db 0Dh, 0Ah, 0Dh, 0Ah
  9434 0000629B 20202020202020312E-     	db "       1. Create Logical DOS Drive", 0Dh, 0Ah
  9434 000062A4 20437265617465204C-
  9434 000062AD 6F676963616C20444F-
  9434 000062B6 532044726976650D0A 
  9435 000062BF 20202020202020322E-     	db "       2. Delete Logical (DOS) Drive(s)",0Dh, 0Ah, 0
  9435 000062C8 2044656C657465204C-
  9435 000062D1 6F676963616C202844-
  9435 000062DA 4F5329204472697665-
  9435 000062E3 2873290D0A00       
  9436                                  
  9437                                  msg_delete_ldd_q:
  9438 000062E9 0D0A                    	db 	0Dh, 0Ah
  9439 000062EB 5741524E494E47210D-     	db 	"WARNING!", 0Dh, 0Ah 
  9439 000062F4 0A                 
  9440 000062F5 416C6C206F66206461-     	db	"All of data in logical (DOS) drive(s) will be lost !!", 0Dh, 0Ah
  9440 000062FE 746120696E206C6F67-
  9440 00006307 6963616C2028444F53-
  9440 00006310 292064726976652873-
  9440 00006319 292077696C6C206265-
  9440 00006322 206C6F73742021210D-
  9440 0000632B 0A                 
  9441 0000632C 0D0A                    	db	0Dh, 0Ah
  9442 0000632E 446F20796F75207761-     	db	"Do you want to continue ? (Y/N) ", 0
  9442 00006337 6E7420746F20636F6E-
  9442 00006340 74696E7565203F2028-
  9442 00006349 592F4E292000       
  9443                                  
  9444                                  msg_create_ldd_max_error:
  9445 0000634F 0D0A                    	db	0Dh, 0Ah
  9446 00006351 50726F6772616D206C-     	db	"Program limit for logical dos drive count is 4 !"
  9446 0000635A 696D697420666F7220-
  9446 00006363 6C6F676963616C2064-
  9446 0000636C 6F7320647269766520-
  9446 00006375 636F756E7420697320-
  9446 0000637E 342021             
  9447 00006381 0D0A00                  	db 	0Dh, 0Ah, 0
  9448                                  
  9449                                  msg_c_ldd_unused_warning:
  9450 00006384 0D0A                    	db	0Dh, 0Ah
  9451 00006386 546865726520697320-     	db	"There is unused extended partition space after logical dos drive 4 !"
  9451 0000638F 756E75736564206578-
  9451 00006398 74656E646564207061-
  9451 000063A1 72746974696F6E2073-
  9451 000063AA 706163652061667465-
  9451 000063B3 72206C6F676963616C-
  9451 000063BC 20646F732064726976-
  9451 000063C5 6520342021         
  9452 000063CA 0D0A                    	db 	0Dh, 0Ah
  9453 000063CC 285072657373204553-     	db	"(Press ESC to add unused space or press ENTER to continue.)"	 
  9453 000063D5 4320746F2061646420-
  9453 000063DE 756E75736564207370-
  9453 000063E7 616365206F72207072-
  9453 000063F0 65737320454E544552-
  9453 000063F9 20746F20636F6E7469-
  9453 00006402 6E75652E29         
  9454 00006407 0D0A00                  	db 	0Dh, 0Ah, 0
  9455                                  
  9456                                  msg_create_ldd_s:
  9457 0000640A 53656C65637420616E-     	db	"Select an option to set logical dos drive size: "
  9457 00006413 206F7074696F6E2074-
  9457 0000641C 6F20736574206C6F67-
  9457 00006425 6963616C20646F7320-
  9457 0000642E 64726976652073697A-
  9457 00006437 653A20             
  9458 0000643A 0D0A                    	db	0Dh, 0Ah
  9459 0000643C 0D0A                    	db	0Dh, 0Ah
  9460 0000643E 202043292043796C69-     	db	"  C) Cylinder count", 0Dh, 0Ah   
  9460 00006447 6E64657220636F756E-
  9460 00006450 740D0A             
  9461 00006453 2020252920566F6C75-     	db	"  %) Volume percentage (##%)", 0Dh, 0Ah
  9461 0000645C 6D652070657263656E-
  9461 00006465 746167652028232325-
  9461 0000646E 290D0A             
  9462 00006471 20204D29204D656761-     	db	"  M) Mega bytes (MB, 2*1024*M sectors)", 0Dh, 0Ah
  9462 0000647A 20627974657320284D-
  9462 00006483 422C20322A31303234-
  9462 0000648C 2A4D20736563746F72-
  9462 00006495 73290D0A           
  9463 00006499 202047292047696761-     	db	"  G) Giga bytes (GB, 2*1024*1024*G sectors)", 0Dh, 0Ah			
  9463 000064A2 206279746573202847-
  9463 000064AB 422C20322A31303234-
  9463 000064B4 2A313032342A472073-
  9463 000064BD 6563746F7273290D0A 
  9464 000064C6 0D0A                    	db	0Dh, 0Ah	
  9465 000064C8 507265737320535041-     	db	"Press SPACE to use entire space or press ENTER to set Megabytes .. ", 0
  9465 000064D1 434520746F20757365-
  9465 000064DA 20656E746972652073-
  9465 000064E3 70616365206F722070-
  9465 000064EC 7265737320454E5445-
  9465 000064F5 5220746F2073657420-
  9465 000064FE 4D6567616279746573-
  9465 00006507 202E2E2000         
  9466                                  
  9467                                  msg_c_part_error:
  9468 0000650C 0D0A                    	db 	0Dh, 0Ah
  9469 0000650E 4E6F20667265652073-     	db	"No free space for a new primary partition", 0Dh, 0Ah, 0
  9469 00006517 7061636520666F7220-
  9469 00006520 61206E657720707269-
  9469 00006529 6D6172792070617274-
  9469 00006532 6974696F6E0D0A00   
  9470                                  msg_c_ldd_error: 
  9471 0000653A 616E64206C6F676963-     	db	"and logical dos drives over program limit (4) !", 0Dh, 0Ah, 0
  9471 00006543 616C20646F73206472-
  9471 0000654C 69766573206F766572-
  9471 00006555 2070726F6772616D20-
  9471 0000655E 6C696D697420283429-
  9471 00006567 20210D0A00         
  9472                                  msg_c_ldd_q:
  9473 0000656C 0D0A                    	db	0Dh, 0Ah
  9474 0000656E 446F20796F75207761-     	db	"Do you want to create logical dos drive in extended dos partition " 
  9474 00006577 6E7420746F20637265-
  9474 00006580 617465206C6F676963-
  9474 00006589 616C20646F73206472-
  9474 00006592 69766520696E206578-
  9474 0000659B 74656E64656420646F-
  9474 000065A4 732070617274697469-
  9474 000065AD 6F6E20             
  9475 000065B0 3F2028592F4E2900        	db	'? (Y/N)', 0
  9476                                  
  9477                                  msg_c_ldd_nofspc_error:
  9478 000065B8 0D0A                    	db 	0Dh, 0Ah
  9479 000065BA 4E6F20667265652073-     	db	"No free space for a new logical dos drive !", 0Dh, 0Ah, 0
  9479 000065C3 7061636520666F7220-
  9479 000065CC 61206E6577206C6F67-
  9479 000065D5 6963616C20646F7320-
  9479 000065DE 647269766520210D0A-
  9479 000065E7 00                 
  9480                                  
  9481                                  ;pt_positions:
  9482                                  ;n_pos:	 dw	30 ; 1 byte	
  9483                                  ;p_pos:	 dw	7  ; 1 byte	
  9484                                  ;s_pos:	 dw	9  ; 2+1 bytes
  9485                                  ;bh_pos: dw 	13 ; 2+1 bytes
  9486                                  ;bs_pos: dw	17 ; 2+1 bytes
  9487                                  ;bc_pos: dw  	21 ; 2+1 bytes
  9488                                  ;fs_pos: dw 	25 ; 2+1 bytes
  9489                                  ;eh_pos: dw 	29 ; 2+1 bytes
  9490                                  ;es_pos: dw	33 ; 2+1 bytes
  9491                                  ;ec_pos: dw	37 ; 2+1 bytes
  9492                                  ;rs_pos: dw	42 ; 7 bytes
  9493                                  ;ns_pos: dw	52 ; 7 bytes
  9494                                  ;fsx_pos: dw	61 ; 14 bytes
  9495                                  
  9496                                  align 4
  9497                                  
  9498                                  msg_sectors_crlf:
  9499 000065E8 20736563746F72          	db	" sector"
  9500                                  msg_sectors_crlf_s:
  9501 000065EF 73                      	db	"s"
  9502 000065F0 0D0A00                  	db	0Dh, 0Ah, 0
  9503                                  
  9504                                  vname_length:
  9505 000065F3 00                      	db	0 ; 05/01/2018
  9506                                  
  9507                                  bs_oem_name:
  9508 000065F4 5452444F53322E3000      	db	'TRDOS2.0', 0
  9509                                  
  9510 000065FD 90                      align 2
  9511                                  
  9512                                  no_name:
  9513 000065FE 4E4F204E414D452020-     	db 	'NO NAME    ', 0
  9513 00006607 202000             
  9514                                  
  9515                                  align 2
  9516                                  
  9517                                  FDFORMAT_SECBUFFER:
  9518                                  HDFORMAT_SECBUFFER:
  9519 0000660A F6<rep 200h>            	times	512 db 0F6h
  9520                                  HDFORMAT_FSINFO_BUFF:
  9521 0000680A 52526141                	dd	41615252h  ; FSI_LeadSig
  9522 0000680E 00<rep 1E0h>            	times	480 db 0   ; FSI_Reserved1
  9523 000069EE 72724161                	dd	61417272h  ; FSI_StrucSig
  9524 000069F2 FFFFFFFF                	dd	0FFFFFFFFh ; FSI_Free_Count
  9525 000069F6 02000000                	dd	000000002h ; FSI_Nxt_Free
  9526 000069FA 00<rep Ch>              	times	12 db 0	   ; FSI_Reserved2
  9527 00006A06 000055AA                	dd	0AA550000h ; FSI_TrailSig	  		
  9528                                  
  9529                                  SizeOfFile equ $-100
  9530                                  
  9531                                  ; 03/02/2019
  9532                                  
  9533                                  ;=============================================================================
  9534                                  ;        	uninitialized data
  9535                                  ;=============================================================================
  9536                                  
  9537                                  bss_start:
  9538                                  
  9539                                  ABSOLUTE bss_start
  9540                                  
  9541                                  alignb 2
  9542 00006A0A ????                    old_sp:		resw 1
  9543                                  
  9544                                  HDFORMAT_FATBUFFER:
  9545                                  FDFORMAT_FATBUFFER:
  9546                                  FDFORMAT_FATBUFFER_S9: ; temporary !
  9547                                  HDFORMAT_EMPTY_BUFF:
  9548 00006A0C <res 200h>              	resb 512
  9549                                  
  9550 00006C0C ????????                data_start: resd 1
  9551 00006C10 ????????                data_sectors: resd 1
  9552 00006C14 ????????                cluster_count: resd 1
  9553 00006C18 ????                    root_dir_secs: resw 1
  9554 00006C1A ????                    format_percent: resw 1
  9555 00006C1C ??                      prev_percent:	resb 1
  9556 00006C1D ??                      rsvdbyte:	resb 1
  9557                                  
  9558 00006C1E ????                    alignb 4
  9559                                  
  9560                                  ; 05/01/2018
  9561 00006C20 <res 40h>               fs_volume_name: resb 64
  9562 00006C60 ????????                fs_volume_serial: resd 1
  9563 00006C64 ????                    DAT_FFBit:	resw 1
  9564 00006C66 ????                    DAT_FFSector:	resw 1
  9565                                  		;resw 1
  9566 00006C68 ????                    DAT_LFBit:	resw 1
  9567 00006C6A ????                    DAT_LFSector:	resw 1
  9568                                  		;resw 1
  9569                                  
  9570                                  ;alignb 4
  9571                                  
  9572                                  FS_MAT_Buffer: ; TRFS1 Master Allocation Table (05/01/2018)
  9573 00006C6C ??????                  MAT_Sign:		resb    3	; Offset 0  ; 'MAT' 
  9574 00006C6F ??                      MAT_Version:		resb 	1	; 	 3  ; 0	
  9575 00006C70 ????????                MAT_VolumeSize:		resd	1	;	 4  ; FS1 Volume Size	
  9576 00006C74 ????????                MAT_BeginSector:	resd	1	;	 8  ; FS1 Start Sector
  9577 00006C78 ????????                DAT_Address:		resd	1	;	12  ; Offset (=2)	
  9578 00006C7C ????????                DAT_SectorCount:	resd	1	;	16  
  9579 00006C80 ????????                MAT_FreeSectors:	resd 	1	; 	20
  9580 00006C84 ????????                MAT_FirstFreeSector:	resd	1	;	24
  9581                                  ;MAT_OS_Reserved:
  9582                                  ;	 		resb	9
  9583                                  ;MAT_Unused:
  9584                                  ;			resb	112
  9585                                  FS_DAT_Buffer: ; TRFS1 Disk Allocation Table (05/01/2018)
  9586                                  FS_RDT_Buffer: ; TRFS1 Root Directory Description Table (05/01/2018)		 
  9587 00006C88 <res 200h>              			resb	512		
  9588                                  ;alignb 4
  9589                                  
  9590                                  ; (TR-DOS 386 compatible) Hard Disk (image) parameters
  9591                                  
  9592 00006E88 ????????                total_sectors: resd 1
  9593 00006E8C ????????                pType:	       resb 4 		
  9594 00006E90 ????????                file_size:     resd 1
  9595 00006E94 ????????                pp_StartSector: resd 1
  9596 00006E98 ????????                pp_Sectors:	resd 1
  9597 00006E9C ??                      wholedisk:	resb 1
  9598 00006E9D ??                      pp_type: resb 1 ; Primary partition type (for this program)	
  9599 00006E9E ??                      pp_type_user: resb 1
  9600 00006E9F ??                      chs_focus: resb 1
  9601 00006EA0 ????????                pSize_temp: resd 1
  9602 00006EA4 ????????                pSize_multiplier: resd 1
  9603 00006EA8 ??                      pSize_maxdigits: resb 1
  9604 00006EA9 ??                      pSize_digitpos: resb 1
  9605                                  msg_psize_unit:
  9606 00006EAA ????                    pSize_unit:	resw 1
  9607 00006EAC ??                      		resb 1
  9608 00006EAD ??????                  reserved_bytes: resb 3 ; for 11 bytes of numbers
  9609                                  msg_partition_sectors:
  9610 00006EB0 ????????????????        		resb 8
  9611 00006EB8 ??                      		resb 1
  9612 00006EB9 ??                      format_q:	resb 1 ; 03/02/2018
  9613                                  
  9614                                  ;alignb 2
  9615 00006EBA ??                      pType_pos:	resb 1
  9616 00006EBB ??                      pType_num:	resb 1
  9617 00006EBC ??                      		resb 1
  9618                                  ;cylinder_boundary:
  9619 00006EBD ??                      		resb 1
  9620 00006EBE ????                    last_cylinder:	resw 1
  9621                                  
  9622                                  alignb 2
  9623                                  
  9624 00006EC0 ??                      GetChar:	resb 1 ; 11/02/2019
  9625 00006EC1 ??                      existingfile:	resb 1 ; 12/02/2019
  9626                                  
  9627 00006EC2 ????                    min_sectors:	resw 1 ; 08/02/2019
  9628 00006EC4 ????                    pp_StartCylinder: resw 1
  9629 00006EC6 ????                    pp_EndCylinder:	resw 1
  9630                                  
  9631 00006EC8 ????????                ppn_Sectors:	resd 1 ; 09/02/2019
  9632                                  
  9633 00006ECC ????                    input_col:	resw 1
  9634 00006ECE ??                      No:		resb 1
  9635 00006ECF ??                      Yes:		resb 1
  9636                                  
  9637                                  ; 26/02/2019
  9638 00006ED0 ??                      ldrives:	resb 1	
  9639                                  
  9640 00006ED1 ??                      sort_1:		resb 1
  9641 00006ED2 ????????                sort:		resb 4
  9642                                  
  9643                                  ;max_sector:	resb 8
  9644                                  ebr_buffer:		; 26/02/2019
  9645 00006ED6 <res 200h>              boot_record:	resb 512
  9646                                  
  9647 000070D6 ??                      valid_input:	resb 1
  9648 000070D7 ??                      		resb 1
  9649                                  
  9650                                  ; 26/02/2019
  9651 000070D8 ????????                ep_StartSector:	resd 1
  9652 000070DC ????????                ep_EndSector:	resd 1
  9653 000070E0 ????????                ep_Size:	resd 1
  9654                                  
  9655                                  ; 10/02/2019
  9656 000070E4 ????????                valid_ppnums:	resb 4	
  9657                                  
  9658 000070E8 ????                    _i_:	resw 1
  9659                                  
  9660 000070EA ????                    freespace_count: resw 1
  9661 000070EC ??                      last_found_partition: resb 1
  9662 000070ED ??                      p_type: resb 1	
  9663                                  
  9664                                  p_sorted:
  9665 000070EE ??                      	resb 1
  9666                                  ep_sorted:
  9667 000070EF ??                      	resb 1
  9668                                  
  9669 000070F0 ??                      _e_:	resb 1
  9670                                  
  9671                                  act_part_num:
  9672                                  cre_part_num:
  9673 000070F1 ??                      del_part_num: resb 1 ; 10/02/2019
  9674                                  
  9675                                  alignb 2
  9676                                  
  9677 000070F2 <res 50h>               pte_row: resb 80
  9678                                  
  9679 00007142 ??                      _zero_:	resb 1
  9680                                  
  9681                                  ;alignb 2
  9682                                  
  9683 00007143 ??                      	resb 1
  9684                                  
  9685                                  ; 24/02/2019
  9686                                  goodpte:
  9687 00007144 ??                      	resb 1
  9688 00007145 ??                      badpte:	resb 1
  9689                                  
  9690                                  bss_clear_end: ; 15/02/2019
  9691                                  
  9692                                  ; PARTITION DATA STRUCTURE
  9693                                  ; 4 partitions
  9694                                  ; 18 byte partition data structure per partition
  9695                                  ; 72 bytes (4*18)
  9696                                  
  9697 00007146 ??                      part_table_boot_ind:	 resb 1
  9698 00007147 ??                      part_table_start_head:	 resb 1
  9699 00007148 ??                      part_table_start_sector: resb 1
  9700 00007149 ????                    part_table_start_cyl:	 resw 1
  9701 0000714B ??                      part_table_sys_id:	 resb 1
  9702 0000714C ??                      part_table_end_head:	 resb 1
  9703 0000714D ??                      part_table_end_sector:	 resb 1
  9704 0000714E ????                    part_table_end_cyl:	 resw 1
  9705 00007150 ????                    part_table_rel_sec_lw:	 resw 1
  9706 00007152 ????                    part_table_rel_sec_hw:	 resw 1
  9707 00007154 ????                    part_table_num_sec_lw:	 resw 1
  9708 00007156 ????                    part_table_num_sec_hw:	 resw 1
  9709                                  
  9710 00007158 <res 36h>               			resb 54 ; 3*18 
  9711                                  
  9712 0000718E ??                      pcount:		resb 1
  9713 0000718F ??                      ppcount:	resb 1
  9714 00007190 ??                      apcount:	resb 1 
  9715 00007191 ??                      epnumber:	resb 1
  9716                                  
  9717                                  ; LOGICAL PARTITION DATA STRUCTURE
  9718                                  ; (for logical partitions in extended partition)
  9719                                  
  9720                                  ; 1 extended partition
  9721                                  ; 4 logical drives (18 bytes)
  9722                                  ; 72 bytes (4*18)
  9723                                  
  9724 00007192 ??                      ext_table_boot_ind:	resb 1
  9725 00007193 ??                      ext_table_start_head:	resb 1
  9726 00007194 ??                      ext_table_start_sector: resb 1
  9727 00007195 ????                    ext_table_start_cyl:	resw 1
  9728 00007197 ??                      ext_table_sys_id:	resb 1
  9729 00007198 ??                      ext_table_end_head:	resb 1
  9730 00007199 ??                      ext_table_end_sector:	resb 1
  9731 0000719A ????                    ext_table_end_cyl:	resw 1
  9732 0000719C ????                    ext_table_rel_sec_lw:	resw 1
  9733 0000719E ????                    ext_table_rel_sec_hw:	resw 1
  9734 000071A0 ????                    ext_table_num_sec_lw:	resw 1
  9735 000071A2 ????                    ext_table_num_sec_hw:	resw 1
  9736                                  
  9737 000071A4 <res 36h>               			resb 54 ; 3*18
  9738                                  
  9739                                  fspc:		; 5*8 words (for free space calculations)
  9740                                  
  9741                                  ; Space 1 - unused cylinders before partition 0
  9742                                  ; Space 2 - unused cylinders between partition 0 & 1 
  9743                                  ; Space 3 - unused cylinders between partition 1 & 2 
  9744                                  ; Space 4 - unused cylinders between partition 2 & 3 
  9745                                  ; Space 5 - unused cylinders after partition 3
  9746                                  
  9747 000071DA ????                    free_space.space:   	   resw 1
  9748 000071DC ????                    free_space.start:   	   resw 1
  9749 000071DE ????                    free_space.end:	   	   resw 1
  9750 000071E0 ????                    free_space.percent_unused: resw 1
  9751 000071E2 ????????                free_space.sectors_unused: resd 1
  9752 000071E6 ????????                free_space.startsector:   resd 1 ; 13/02/2019
  9753                                  		;resw  4*6 
  9754 000071EA <res 40h>               		resw   4*8 ; 13/02/2019
  9755                                  
  9756                                  ; 18/02/2019
  9757 0000722A ????                    c_cylinder:	resw 1
  9758 0000722C ????                    c_fspc_offset:	resw 1
  9759 0000722E ??                      cylinder_boundary: resb 1
  9760                                  ;c_gap:		resb 1
  9761 0000722F ??                      		resb 1
  9762                                  
  9763                                  ; 27/02/2019
  9764 00007230 <res 10h>               ldd_start:	resd 4
  9765                                  ; 03/03/2019
  9766 00007240 <res 10h>               ldd_size:	resd 4
  9767                                  
  9768                                  ; 25/02/2019
  9769 00007250 ????                    pte_address:	resw 1
  9770                                  ; 02/03/2019
  9771 00007252 ????                    lcylinders:	resw 1
  9772                                  
  9773                                  ;bss_clear_end: ; 18/02/2019  ; temporary
  9774                                  
  9775                                  bss_end:	 	
