     1                                  ; ****************************************************************************
     2                                  ; FDIMAGE.ASM (FDIMAGE.COM) - TRDOS 386 Floppy Disk Image Formatting Utility
     3                                  ; 						      (for MSDOS/WINDOWS)
     4                                  ; ----------------------------------------------------------------------------
     5                                  ; Only for 1.44MB (3.5") Floppy Disks
     6                                  ; ****************************************************************************
     7                                  ; Last Update: 12/02/2018
     8                                  ; ----------------------------------------------------------------------------
     9                                  ; Beginning: 01/12/2017
    10                                  ; ----------------------------------------------------------------------------
    11                                  ; Assembler: NASM version 2.11
    12                                  ; ----------------------------------------------------------------------------
    13                                  ; Turkish Rational DOS
    14                                  ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
    15                                  ;
    16                                  ; Derived from 'fdformat.s'(FDFORMAT.COM) source code by Erdogan Tan
    17                                  ; (29/11/2017)
    18                                  ;
    19                                  ; Derived from 'UNIXCOPY.ASM' (UNIXCOPY.COM) source code by Erdogan Tan
    20                                  ; (04/12/2015)
    21                                  ; ****************************************************************************
    22                                  ; nasm fdimage.asm -l fdimage.lst -o FDIMAGE.COM
    23                                  
    24                                  bsDriveNumber   equ TRDOS_FAT12_fd_bs + 36
    25                                  bsVolumeID      equ TRDOS_FAT12_fd_bs + 39
    26                                  bsVolumeLabel   equ TRDOS_FAT12_fd_bs + 43
    27                                  
    28                                  ; DTA (PSP+80h= Offset 128)
    29                                  DTA_Attrib equ 149 ; PDP+21
    30                                  DTA_Time equ 150 ; PSP+22
    31                                  DTA_Date equ 152 ; PSP 24
    32                                  DTA_FileSize equ 154 ; PSP + 26
    33                                  DTA_FileName equ 158 ; PSP + 30
    34                                  
    35                                  [BITS 16]
    36                                  [ORG 100h]
    37                                  
    38                                  	;cli
    39                                  	;cld
    40                                  	;push	cs
    41                                  	;pop	ss
    42                                  	;mov	sp, 0FFFEh
    43                                  	;sti
    44                                  	
    45 00000000 BB[620B]                	mov	bx, SizeOfFile+100
    46 00000003 83C30F                          add	bx, 15
    47 00000006 D1EB                            shr	bx, 1
    48 00000008 D1EB                            shr	bx, 1
    49 0000000A D1EB                    	shr	bx, 1
    50 0000000C D1EB                    	shr	bx, 1
    51 0000000E B44A                            mov	ah, 4Ah ; modify memory allocation
    52                                          ;push	cs
    53                                          ;pop	es
    54 00000010 CD21                            int	21h 
    55                                  
    56                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    57                                  ; get fd image file name
    58                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    59                                  
    60 00000012 BE8000                  	mov	si, 80h			; PSP command tail
    61 00000015 AC                       	lodsb
    62 00000016 08C0                    	or	al, al 			; command tail length                            
    63 00000018 0F84C700                	jz	R_17			; jump if zero
    64                                  R_01:
    65 0000001C AC                      	lodsb
    66 0000001D 3C20                    	cmp	al, ' '			; is it SPACE ?
    67 0000001F 74FB                    	je	short R_01 		
    68 00000021 0F82BE00                	jb	R_17
    69                                  	
    70                                  	; check fd image file name
    71                                  R_02:
    72 00000025 BF[550B]                       	mov	di, img_file_name
    73 00000028 AA                      	stosb
    74                                  R_03:
    75 00000029 AC                      	lodsb
    76                                  	;cmp	al, 0Dh ; ENTER (CR) key
    77 0000002A 3C20                    	cmp	al, 20h ; ' '
    78 0000002C 760C                    	jna	short R_04
    79 0000002E AA                      	stosb
    80 0000002F 81FF[610B]              	cmp	di, img_file_name + 12
    81 00000033 72F4                    	jb	short R_03
    82 00000035 803C20                  	cmp	byte [si], 20h 
    83 00000038 773F                    	ja	short R_11
    84                                  R_04:
    85                                  	;sub	al, al
    86                                  	;stosb
    87                                  
    88                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    89                                  ; File name capitalization
    90                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    91                                  
    92 0000003A BE[550B]                	mov	si, img_file_name
    93 0000003D 89F7                    	mov	di, si
    94 0000003F 89F3                    	mov	bx, si
    95                                  R_05:
    96 00000041 AC                      	lodsb
    97 00000042 3C61                    	cmp	al, 'a'
    98 00000044 730D                    	jnb	short R_07
    99 00000046 20C0                    	and	al, al
   100 00000048 7412                    	jz	short R_08
   101 0000004A 3C2E                    	cmp	al, '.'
   102 0000004C 7502                    	jne	short R_06
   103 0000004E 89FB                    	mov	bx, di ; dot position	
   104                                  R_06:
   105 00000050 AA                      	stosb
   106 00000051 EBEE                    	jmp	short R_05 		
   107                                  R_07:
   108 00000053 3C7A                    	cmp	al, 'z'
   109 00000055 77F9                    	ja	short R_06
   110 00000057 24DF                    	and	al, 0DFh ; NOT 32
   111 00000059 AA                      	stosb
   112 0000005A EBE5                    	jmp	short R_05	
   113                                  R_08:
   114 0000005C 8805                    	mov	[di], al
   115 0000005E 4F                      	dec	di
   116 0000005F 39FB                    	cmp	bx, di
   117 00000061 7316                    	jnb	short R_11
   118 00000063 29DF                    	sub	di, bx
   119 00000065 81EB[550B]              	sub	bx, img_file_name
   120 00000069 83FF03                  	cmp	di, 3
   121 0000006C 7606                    	jna	short R_09
   122 0000006E 21DB                    	and	bx, bx
   123 00000070 7507                    	jnz	short R_11
   124 00000072 EB0D                    	jmp	short R_10		
   125                                  R_09:
   126 00000074 83FB08                  	cmp	bx, 8
   127 00000077 7608                    	jna	short R_10
   128                                  R_11:
   129 00000079 BE[CC05]                	mov	si, msg_inv_file_name
   130                                  R_12:	
   131 0000007C E8B201                  	call	print_msg
   132 0000007F EB57                    	jmp	short R_16
   133                                  
   134                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   135                                  ; Find image file
   136                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   137                                  	
   138                                  R_10:
   139 00000081 BA[550B]                	mov	dx, img_file_name
   140 00000084 B93F00                  	mov	cx, 3Fh ; File Attributes
   141 00000087 B44E                    	mov	ah, 4Eh ; MS-DOS Function = Find First File
   142 00000089 CD21                    	int	21h
   143 0000008B 726B                    	jc	R_20
   144                                  
   145                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   146                                  ; Check image file features
   147                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   148                                  
   149                                  R_14:
   150 0000008D BE9500                  	mov	si, DTA_Attrib
   151 00000090 8A04                    	mov	al, [si]
   152 00000092 241F                    	and	al, 1Fh ; directory, volume label, system, hidden, read only
   153 00000094 755D                    	jnz	short R_19     
   154 00000096 BE9A00                  	mov	si, DTA_FileSize
   155 00000099 AD                      	lodsw
   156 0000009A 833C16                  	cmp	word [SI], 16h
   157 0000009D 7554                    	jne	short R_19
   158 0000009F 3D0080                  	cmp	ax, 8000h ; 1.44 MB floppy disk image (168000h bytes)
   159 000000A2 754F                    	jne	short R_19
   160                                  
   161                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   162                                  ; Overwrite question
   163                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   164                                  
   165 000000A4 BE[5806]                	mov	si, msg_overwrite_question1
   166 000000A7 E88701                  	call	print_msg
   167 000000AA BE9E00                  	mov	si, DTA_FileName
   168 000000AD E88101                  	call	print_msg
   169 000000B0 BE[7506]                	mov	si, msg_overwrite_question2
   170 000000B3 E87B01                  	call	print_msg
   171 000000B6 BE[7D06]                	mov	si, msg_yes_no
   172 000000B9 E87501                  	call	print_msg
   173                                  
   174                                  	; get answer
   175                                  R_15:
   176 000000BC 31C0                    	xor	ax, ax
   177 000000BE CD16                    	int	16h			; wait for keyboard command
   178 000000C0 3C03                    	cmp	al, 'C'-40h
   179 000000C2 7414                    	je	short R_16 ; Exit                   
   180 000000C4 3C1B                    	cmp	al, 27
   181 000000C6 7410                    	je	short R_16 ; Exit
   182 000000C8 24DF                    	and	al, 0DFh
   183 000000CA 3C59                    	cmp	al, 'Y'			; Yes?
   184 000000CC 741D                    	je	short R_18		; write
   185 000000CE 3C4E                    	cmp	al, 'N'			; No?
   186 000000D0 75EA                    	jne	short R_15      
   187                                  					; no write (exit)  
   188 000000D2 BE[2407]                	mov	si, Msg_NO
   189 000000D5 E85901                  	call	print_msg 
   190                                  
   191                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   192                                  ; Nextline & Exit
   193                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   194                                  
   195                                  R_16:
   196 000000D8 BE[1C07]                	mov	si, CRLF
   197 000000DB E85301                  	call	print_msg
   198 000000DE B8004C                  	mov	ax, 4C00h		; terminate
   199 000000E1 CD21                    	int	21h
   200                                  
   201                                  R_17:
   202 000000E3 BE[4705]                	mov	si, TrDOS_Welcome
   203 000000E6 E84801                  	call	print_msg
   204 000000E9 EBED                    	jmp	short R_16 ; Exit
   205                                  
   206                                  R_18:
   207 000000EB BE[1F07]                	mov	si, Msg_YES
   208 000000EE E84001                  	call	print_msg
   209 000000F1 EB10                    	jmp	short R_21
   210                                  
   211                                  R_19:
   212 000000F3 BE[0E06]                	mov	si, msg_inv_image_file
   213 000000F6 EB84                    	jmp	short R_12
   214                                  
   215                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   216                                  ; Create image file
   217                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   218                                  
   219                                  R_20:
   220                                  	; create a new fd image file
   221                                  	;mov	dx, img_file_name
   222 000000F8 B90000                  	mov	cx, 0 ; File Attributes
   223 000000FB B43C                    	mov	ah, 3Ch ; MS-DOS Function = Create File
   224 000000FD CD21                    	int	21h
   225 000000FF 0F8276FF                	jc	R_11
   226                                  
   227                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   228                                  ; writing root directory sectors
   229                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   230                                  
   231                                  R_21:
   232 00000103 BE[1C07]                	mov	si, CRLF
   233 00000106 E82801                  	call	print_msg
   234                                  
   235                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   236                                  ; Open image file for writing
   237                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   238                                  
   239 00000109 B002                    	mov	al, 2 ; open for reading and writing
   240                                  	;mov	dx, img_file_name
   241 0000010B B43D                    	mov	ah, 3Dh ; open file
   242 0000010D CD21                    	int	21h
   243 0000010F 0F8266FF                	jc	R_11
   244                                  
   245 00000113 A3[4505]                	mov	[img_file_handle], ax
   246                                  
   247 00000116 BE[A506]                	mov	si, Msg_Writing_Root_Dir
   248 00000119 E81501                  	call	print_msg
   249                                  
   250 0000011C B81300                  	mov	ax, 19  ; Root Directory Address
   251 0000011F BB[3C09]                	mov	bx, FDFORMAT_FATBUFFER_S9
   252                                  R_22:
   253 00000122 E81B01                  	call	write_fd_sector
   254 00000125 0F82E500                	jc	R_29
   255 00000129 40                      	inc	ax
   256 0000012A 83F820                   	cmp	ax, 32
   257 0000012D 76F3                    	jna	short R_22
   258                                  
   259 0000012F BE[1807]                	mov	si, Msg_OK
   260 00000132 E8FC00                  	call	print_msg
   261                                  
   262                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   263                                  ; writing data sectors
   264                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   265                                  
   266 00000135 BE[C706]                	mov	si, Msg_Writing_Data_Sectors
   267 00000138 E8F600                  	call	print_msg
   268 0000013B B403                    	mov	ah, 3
   269 0000013D BB0700                  	mov	bx, 7
   270 00000140 CD10                    	int	10h ; Return Cursor Position
   271                                  	; DL = Column, DH= Line
   272 00000142 8916[E206]              	mov	[Cursor_Pos], dx
   273 00000146 B82100                  	mov	ax, 33  ; First Data Sector
   274                                  R_23:
   275 00000149 50                      	push	ax
   276 0000014A 40                      	inc	ax ; 1 based printing of 0 based sectors
   277 0000014B BE[E006]                	mov	si, Sector_Str + 3
   278 0000014E E81401                  	call	bin_to_decimal
   279 00000151 8B16[E206]              	mov	dx, [Cursor_Pos]
   280 00000155 B402                    	mov	ah, 2
   281 00000157 CD10                    	int	10h  ; Set Cursor Position
   282 00000159 E8D500                  	call	print_msg
   283 0000015C 58                      	pop	ax
   284 0000015D BB[3907]                	mov	bx, FDFORMAT_SECBUFFER
   285 00000160 E8DD00                  	call	write_fd_sector
   286 00000163 0F82A700                	jc	R_29
   287                                  
   288 00000167 BB0700                  	mov	bx, 7
   289 0000016A 40                      	inc	ax
   290 0000016B 3D400B                  	cmp	ax, 2880
   291 0000016E 72D9                    	jb	short R_23
   292                                  
   293 00000170 BE[1507]                	mov	si, Msg_3dot_OK
   294 00000173 E8BB00                  	call	print_msg
   295                                  
   296                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   297                                  ; writing FAT sectors
   298                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   299                                  
   300 00000176 BE[E406]                	mov	si, Msg_Writing_FAT_Sectors
   301 00000179 E8B500                  	call	print_msg
   302 0000017C B80100                  	mov	ax, 1  ; FAT Beginning Address
   303 0000017F BB[3909]                	mov	bx, FDFORMAT_FATBUFFER
   304 00000182 E8BB00                  	call	write_fd_sector
   305 00000185 0F828500                	jc	R_29
   306 00000189 BB[3C09]                	mov	bx, FDFORMAT_FATBUFFER_S9
   307                                  R_24:
   308 0000018C 40                      	inc	ax
   309 0000018D E8B000                  	call	write_fd_sector
   310 00000190 727C                     	jc	short R_29
   311 00000192 83F809                  	cmp	ax, 9
   312 00000195 72F5                    	jb	short R_24
   313 00000197 BB[3909]                	mov	bx, FDFORMAT_FATBUFFER
   314 0000019A 40                      	inc	ax
   315 0000019B E8A200                  	call	write_fd_sector
   316 0000019E 726E                    	jc	short R_29
   317 000001A0 BB[3C09]                	mov	bx, FDFORMAT_FATBUFFER_S9
   318                                  R_25:
   319 000001A3 40                      	inc	ax 
   320 000001A4 E89900                          call	write_fd_sector
   321 000001A7 7265                    	jc	short R_29
   322 000001A9 83F812                  	cmp	ax, 18
   323 000001AC 72F5                    	jb	short R_25
   324                                  
   325 000001AE BE[1807]                	mov	si, Msg_OK
   326 000001B1 E87D00                  	call	print_msg
   327                                  
   328 000001B4 BE[0707]                	mov	si, Msg_Volume_Name
   329 000001B7 E87700                  	call	print_msg
   330 000001BA E8DD00                  	call	rw_char
   331 000001BD 7219                    	jc	short R_28
   332 000001BF 8A04                    	mov	al, [si]
   333 000001C1 3C20                    	cmp	al, 20h
   334 000001C3 7613                    	jna	short R_28
   335 000001C5 BF[5F03]                	mov	di, bsVolumeLabel
   336 000001C8 B90B00                  	mov	cx, 11
   337 000001CB 46                      	inc	si  
   338 000001CC EB06                    	jmp	short R_27  
   339                                  
   340                                  R_26:
   341 000001CE AC                      	lodsb
   342 000001CF 47                      	inc	di
   343 000001D0 3C20                    	cmp	al, 20h
   344 000001D2 7655                    	jna	short R_32
   345                                  R_27:
   346 000001D4 8805                    	mov 	[di], al
   347 000001D6 E2F6                    	loop	R_26
   348                                  
   349                                  R_28:
   350 000001D8 BE[8806]                	mov	si, Msg_Writing_Boot_Sector
   351 000001DB E85300                  	call	print_msg
   352                                  
   353 000001DE BE[5B03]                	mov	si, bsVolumeID
   354                                  
   355 000001E1 31C0                    	xor	ax, ax
   356 000001E3 CD1A                    	int	1Ah			; get time of day
   357 000001E5 8914                    	mov	[si], dx
   358 000001E7 894C02                  	mov	[si+2], cx		; set unique volume ID
   359                                  
   360 000001EA B402                    	mov	ah, 02h			; Return Current Time
   361 000001EC CD1A                    	int	1Ah
   362 000001EE 86E9                    	xchg	ch, cl
   363 000001F0 86F2                    	xchg	dh, dl
   364                                  
   365 000001F2 01D1                    	add	cx, dx  
   366 000001F4 014C02                  	add	[si+2], cx
   367                                                 
   368 000001F7 B404                    	mov	ah, 04h			; Return Current Date
   369 000001F9 CD1A                    	int	1Ah
   370 000001FB 86E9                    	xchg	ch,cl
   371 000001FD 86F2                    	xchg	dh,dl
   372                                  
   373 000001FF 01D1                    	add	cx, dx  
   374 00000201 014C02                  	add	[si+2], cx
   375                                  
   376 00000204 31C0                    	xor	ax, ax ; Boot sector
   377 00000206 BB[3403]                	mov	bx, TRDOS_FAT12_fd_bs	; location of boot code
   378                                  
   379 00000209 E83400                  	call	write_fd_sector
   380 0000020C 7313                    	jnc	short R_30
   381                                  R_29:
   382 0000020E 88E0                    	mov	al, ah ;  error code
   383 00000210 E86700                  	call	bin_to_hex
   384 00000213 A3[3307]                	mov 	[error_code], ax
   385                                  
   386 00000216 BE[1C07]                	mov	si, CRLF
   387 00000219 E81500                  	call	print_msg
   388                                  
   389 0000021C BE[2807]                	mov	si, Msg_Error
   390 0000021F EB03                    	jmp	short R_31
   391                                  
   392                                  R_30:
   393 00000221 BE[1807]                	mov	si, Msg_OK
   394                                  R_31:
   395 00000224 E80A00                  	call	print_msg
   396                                  
   397 00000227 CD20                    	int	20h	; Exit
   398                                  
   399                                  R_32:
   400 00000229 C60520                  	mov	byte [di], 20h
   401 0000022C 47                      	inc	di
   402 0000022D E2FA                    	loop	R_32
   403 0000022F EBA7                    	jmp	short R_28
   404                                  
   405                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   406                                  ; Print messages
   407                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   408                                  
   409                                  print_msg:
   410                                  
   411                                  print_msg_LOOP:
   412 00000231 AC                      	lodsb                           ; Load byte at DS:SI to AL
   413 00000232 20C0                    	and     al, al            
   414 00000234 7409                    	jz      short print_msg_OK       
   415 00000236 B40E                    	mov	ah, 0Eh			
   416 00000238 BB0700                  	mov     bx, 07h             
   417 0000023B CD10                    	int	10h			; BIOS Service func ( ah ) = 0Eh
   418                                  					; Write char as TTY
   419                                  					; AL-char BH-page BL-color
   420 0000023D EBF2                    	jmp     short print_msg_LOOP           
   421                                  
   422                                  print_msg_OK:
   423 0000023F C3                      	retn
   424                                  
   425                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   426                                  ; Writing a block (sector) to floppy disk image file
   427                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   428                                  
   429                                  write_fd_sector:
   430                                  	; writing a block (sector) to floppy disk image file
   431                                  	; Only for 1.44 MB FAT12 Floppy Disks
   432                                  	; INPUT -> AX = Logical Block (Sector) Address
   433                                  	; ES:BX = Sector Buffer
   434                                  	; OUTPUT ->
   435                                  	; cf = 0 -> AX = Logical Block (Sector) Address
   436                                  	; cf = 1 -> AH = Error Number
   437                                  	;
   438 00000240 50                      	push	ax ; sector
   439 00000241 53                      	push	bx ; buffer
   440 00000242 BA0002                  	mov	dx, 512
   441 00000245 F7E2                    	mul	dx
   442 00000247 89D1                    	mov	cx, dx
   443 00000249 89C2                    	mov	dx, ax
   444 0000024B 28C0                    	sub	al, al ; specified offset is from the beginning of the file
   445 0000024D B442                    	mov	ah, 42h ; seek (move file pointer)
   446 0000024F 8B1E[4505]              	mov 	bx, [img_file_handle]
   447 00000253 CD21                    	int	21h
   448                                  	;mov	bx, [img_file_handle]
   449 00000255 B90002                  	mov	cx, 512
   450 00000258 5A                      	pop	dx  ; buffer address
   451 00000259 B440                    	mov	ah, 40h ; write to file	
   452 0000025B CD21                    	int	21h
   453 0000025D 89D3                    	mov	bx, dx
   454 0000025F 7202                    	jc	short image_file_wr_err
   455 00000261 58                      	pop	ax ; sector
   456 00000262 C3                      	retn
   457                                  	
   458                                  image_file_wr_err:
   459 00000263 5A                      	pop	dx ; sector
   460 00000264 C3                      	retn
   461                                  	
   462                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   463                                  ; Convert byte to decimal number
   464                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   465                                  
   466                                  bin_to_decimal:
   467                                  	; INPUT: DS:SI = Target location
   468                                  	;        AX= Binary Number (Integer)
   469                                  	; OUTPUT: Decimal char at DS:SI
   470                                  	; SI decremented after every division
   471                                  	; till AX<10.
   472                                  	; CX, DX will be changed.
   473                                  	;
   474 00000265 B90A00                  	mov	cx, 10
   475                                  loc_btd_re_divide:
   476 00000268 31D2                    	xor	dx, dx
   477 0000026A F7F1                    	div	cx
   478 0000026C 80C230                  	add	dl,"0"
   479 0000026F 8814                    	mov	[si], dl
   480 00000271 83F800                  	cmp	ax, 0
   481 00000274 7603                    	jna	short pass_btd_re_divide
   482 00000276 4E                      	dec	si
   483 00000277 EBEF                    	jmp	short loc_btd_re_divide
   484                                  pass_btd_re_divide:
   485 00000279 C3                      	retn
   486                                  
   487                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   488                                  ; Convert byte to hexadecimal number
   489                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   490                                  
   491                                  bin_to_hex:
   492                                  	; INPUT ->
   493                                  	; 	AL = byte (binary number)
   494                                  	; OUTPUT ->
   495                                  	;	AX = hexadecimal string
   496                                  	;
   497 0000027A 6653                    	push	ebx
   498 0000027C 6631DB                  	xor	ebx, ebx
   499 0000027F 88C3                    	mov	bl, al
   500 00000281 C0EB04                  	shr	bl, 4
   501 00000284 678A9B[35050000]        	mov	bl, [ebx+hexchrs] 	 	
   502 0000028B 86D8                    	xchg	bl, al
   503 0000028D 80E30F                  	and	bl, 0Fh
   504 00000290 678AA3[35050000]        	mov	ah, [ebx+hexchrs] 
   505 00000297 665B                    	pop	ebx	
   506 00000299 C3                      	retn
   507                                  
   508                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   509                                  ; Read & Write characters
   510                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   511                                  
   512                                  rw_char:
   513                                  	; OUTPUT -> DS:SI = Entered String (ASCIIZ)
   514 0000029A BE[FB06]                	mov     si, StrVolumeName
   515 0000029D BB0700                  	mov     bx, 7
   516 000002A0 B403                    	mov     ah, 3
   517 000002A2 CD10                    	int     10h
   518 000002A4 8916[E206]              	mov     [Cursor_Pos], dx
   519                                  read_next_char:
   520 000002A8 30E4                    	xor     ah, ah
   521 000002AA CD16                    	int     16h
   522 000002AC 20C0                    	and     al, al
   523 000002AE 7439                    	jz      short loc_arrow    
   524 000002B0 3CE0                    	cmp     al, 0E0h          
   525 000002B2 7435                    	je      short loc_arrow
   526 000002B4 3C08                    	cmp     al, 8
   527 000002B6 753D                    	jne     short char_return
   528                                  loc_back:
   529 000002B8 B403                    	mov     ah, 3
   530 000002BA CD10                    	int     10h
   531 000002BC 3A16[E206]              	cmp     dl, byte [Cursor_Pos]
   532 000002C0 761F                    	jna     short loc_beep
   533                                  prev_column:
   534 000002C2 FECA                    	dec     dl
   535                                  set_cursor_pos:
   536 000002C4 B402                    	mov     ah, 2
   537 000002C6 CD10                    	int     10h
   538 000002C8 88D3                    	mov     bl, dl
   539 000002CA 2A1E[E206]              	sub     bl, byte [Cursor_Pos] 
   540 000002CE B90100                  	mov     cx,1
   541 000002D1 B409                    	mov     ah, 9
   542 000002D3 B020                    	mov     al, 20h
   543 000002D5 8800                    	mov     [si+bx], al
   544                                  loc_write_it:
   545 000002D7 B307                    	mov     bl, 7
   546 000002D9 CD10                    	int     10h
   547 000002DB 8B16[E206]              	mov     dx, [Cursor_Pos]
   548 000002DF EBC7                    	jmp     short read_next_char
   549                                  loc_beep:
   550 000002E1 B40E                    	mov     ah, 0Eh
   551 000002E3 B007                    	mov     al, 7
   552 000002E5 CD10                    	int     10h
   553 000002E7 EBBF                    	jmp     short read_next_char
   554                                  loc_arrow:    
   555 000002E9 80FC4B                  	cmp     ah, 4Bh
   556 000002EC 74CA                    	je      short loc_back
   557 000002EE 80FC53                  	cmp     ah, 53h
   558 000002F1 74C5                    	je      short loc_back
   559 000002F3 EBB3                    	jmp     short read_next_char
   560                                  char_return:
   561 000002F5 B403                    	mov     ah, 3
   562 000002F7 CD10                    	int     10h
   563                                  check_char_type:
   564 000002F9 3C20                    	cmp     al, 20h
   565 000002FB 7230                    	jb      short loc_escape
   566 000002FD 88D4                    	mov     ah, dl
   567 000002FF 2A26[E206]              	sub     ah, byte [Cursor_Pos] 
   568 00000303 80FC0A                  	cmp     ah, 10
   569 00000306 77D9                    	ja      short loc_beep
   570 00000308 3C7A                    	cmp     al, "z"
   571 0000030A 779C                    	ja      short read_next_char
   572 0000030C 3C61                    	cmp     al, "a"
   573 0000030E 7202                    	jb      short pass_capitalize
   574 00000310 24DF                    	and     al, 0DFh
   575                                  pass_capitalize:
   576 00000312 88E3                    	mov     bl, ah  ; 30/07/2011
   577 00000314 30E4                    	xor     ah, ah
   578 00000316 8900                    	mov     [si+bx], ax
   579 00000318 B307                    	mov     bl, 7
   580 0000031A B40E                    	mov     ah, 0Eh
   581 0000031C CD10                    	int     10h
   582 0000031E EB88                    	jmp     short read_next_char
   583                                  pass_escape:
   584 00000320 3C0D                    	cmp     al, 0Dh
   585 00000322 7584                    	jne     short read_next_char
   586 00000324 B40E                    	mov     ah, 0Eh
   587 00000326 CD10                    	int     10h
   588 00000328 B00A                    	mov     al, 0Ah
   589 0000032A CD10                    	int     10h
   590 0000032C C3                      	retn
   591                                  loc_escape:
   592 0000032D 3C1B                    	cmp     al, 1Bh
   593 0000032F 75EF                    	jne     short pass_escape
   594 00000331 F9                      	stc
   595 00000332 C3                      	retn
   596                                  
   597                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   598                                  ;  Data
   599                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   600                                  
   601 00000333 00                      	db	0
   602                                  
   603                                  TRDOS_FAT12_fd_bs:
   604 00000334 <incbin>                	incbin 'TRFDBS.BIN' ; 12/02/2018
   605                                  
   606 00000534 00                      	db	0
   607                                  
   608                                  hexchrs:
   609 00000535 303132333435363738-     	db	'0123456789ABCDEF'
   610 0000053E 39414243444546     
   611                                  
   612                                  img_file_handle:
   613 00000545 0000                    	dw	0
   614                                  
   615                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   616                                  ;  Messages
   617                                  ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   618                                  
   619                                  TrDOS_Welcome:
   620 00000547 0D0A                    	db	0Dh, 0Ah
   621 00000549 54522D444F5320312E-     	db	'TR-DOS 1.44 MB FAT12 Floppy Disk Image Format Utility'
   622 00000552 3434204D4220464154-
   623 0000055B 313220466C6F707079-
   624 00000564 204469736B20496D61-
   625 0000056D 676520466F726D6174-
   626 00000576 205574696C697479   
   627 0000057E 0D0A                    	db	0Dh, 0Ah
   628 00000580 76322E302E31323032-     	db	"v2.0.120218  (c) Erdogan TAN 2005-2018"
   629 00000589 313820202863292045-
   630 00000592 72646F67616E205441-
   631 0000059B 4E20323030352D3230-
   632 000005A4 3138               
   633 000005A6 0D0A                    	db	0Dh,0Ah
   634 000005A8 0D0A                    	db	0Dh,0Ah
   635 000005AA 55736167653A206664-     	db	'Usage: fdimage <image file name> '
   636 000005B3 696D616765203C696D-
   637 000005BC 6167652066696C6520-
   638 000005C5 6E616D653E20       
   639 000005CB 00                      	db	0
   640                                  
   641                                  msg_inv_file_name: 
   642 000005CC 0D0A                    	db	0Dh, 0Ah
   643 000005CE 496E76616C69642066-     	db	"Invalid file name !", 0Dh, 0Ah
   644 000005D7 696C65206E616D6520-
   645 000005E0 210D0A             
   646 000005E3 2846696C65206E616D-     	db	"(File name must fit to 8.3 DOS format) !"
   647 000005EC 65206D757374206669-
   648 000005F5 7420746F20382E3320-
   649 000005FE 444F5320666F726D61-
   650 00000607 74292021           
   651 0000060B 0D0A00                  	db	0Dh, 0Ah, 0
   652                                  
   653                                  msg_inv_image_file:
   654 0000060E 0D0A                    	db	0Dh, 0Ah
   655 00000610 496E76616C69642066-     	db	"Invalid floppy disk image file !", 0Dh, 0Ah
   656 00000619 6C6F70707920646973-
   657 00000622 6B20696D6167652066-
   658 0000062B 696C6520210D0A     
   659 00000632 2846696C652073697A-     	db	"(File size must be 1474560 bytes) !"
   660 0000063B 65206D757374206265-
   661 00000644 203134373435363020-
   662 0000064D 6279746573292021   
   663 00000655 0D0A00                  	db	0Dh, 0Ah, 0  
   664                                  
   665                                  msg_overwrite_question1:
   666 00000658 0D0A                    	db	0Dh, 0Ah
   667 0000065A 446F20796F75207761-     	db	'Do you want to overwrite '
   668 00000663 6E7420746F206F7665-
   669 0000066C 72777269746520     
   670 00000673 27                      	db	27h
   671 00000674 00                      	db	0
   672                                  
   673                                  msg_overwrite_question2: 
   674 00000675 27                      	db	27h
   675 00000676 2066696C6520            	db	' file '
   676 0000067C 00                      	db	0
   677                                  
   678                                  msg_yes_no:
   679 0000067D 285965732F4E6F293F-     	db	'(Yes/No)? ', 0		
   680 00000686 2000               
   681                                  
   682                                  Msg_Writing_Boot_Sector:
   683 00000688 57726974696E672074-     	db	"Writing trdos boot sector...", 0
   684 00000691 72646F7320626F6F74-
   685 0000069A 20736563746F722E2E-
   686 000006A3 2E00               
   687                                  
   688                                  Msg_Writing_Root_Dir:
   689 000006A5 57726974696E672072-     	db	"Writing root directory sectors...", 0
   690 000006AE 6F6F74206469726563-
   691 000006B7 746F72792073656374-
   692 000006C0 6F72732E2E2E00     
   693                                  
   694                                  Msg_Writing_Data_Sectors:
   695 000006C7 57726974696E672064-     	db	"Writing data sector: ", 0
   696 000006D0 61746120736563746F-
   697 000006D9 723A2000           
   698                                  
   699                                  Sector_Str:
   700 000006DD 3030303000              	db	"0000", 0
   701                                  Cursor_Pos:
   702 000006E2 0000                    	dw	0
   703                                  
   704                                  Msg_Writing_FAT_Sectors:
   705 000006E4 57726974696E672046-     	db	"Writing FAT sectors...", 0
   706 000006ED 415420736563746F72-
   707 000006F6 732E2E2E00         
   708                                  
   709                                  StrVolumeName:
   710 000006FB 00<rept>                	times 	12 db  0
   711                                  
   712                                  Msg_Volume_Name:
   713 00000707 566F6C756D65204E61-     	db	"Volume Name: ", 0
   714 00000710 6D653A2000         
   715                                  
   716                                  Msg_3dot_OK:
   717 00000715 2E2E2E                  	db	"..."
   718                                  Msg_OK:
   719 00000718 204F4B2E                	db	' OK.'
   720                                  CRLF:
   721 0000071C 0D0A00                  	db	0Dh, 0Ah, 0
   722                                  Msg_YES:
   723 0000071F 2059455300              	db	' YES', 0
   724                                  Msg_NO:
   725 00000724 204E4F00                	db	' NO', 0
   726                                  
   727                                  Msg_Error:
   728 00000728 0D0A                    	db	0Dh, 0Ah
   729 0000072A 4572726F72202120        	db	'Error ! '
   730 00000732 28                      	db	'('
   731                                  error_code:
   732 00000733 3030                    	dw	3030h
   733 00000735 68                      	db	'h'
   734 00000736 2920                    	db	') '
   735 00000738 00                      	db	0
   736                                  
   737                                  FDFORMAT_SECBUFFER:
   738 00000739 F6<rept>                	times	512 db 0F6h
   739                                  FDFORMAT_FATBUFFER:
   740 00000939 F0                      	db	0F0h
   741 0000093A FF                      	db	0FFh
   742 0000093B FF                      	db	0FFh
   743                                  FDFORMAT_FATBUFFER_S9:
   744 0000093C 00<rept>                	times	512 db 0
   745                                   
   746 00000B3C 286329204572646F67-     	db	'(c) Erdogan TAN 1998-2018'
   747 00000B45 616E2054414E203139-
   748 00000B4E 39382D32303138     
   749                                  
   750                                  img_file_name:  
   751 00000B55 00<rept>                	times	13 db 0
   752                                  
   753                                  SizeOfFile equ $-100
