     1                                  ; ****************************************************************************
     2                                  ; TRDOS386.ASM (TRDOS 386 Kernel) - v2.0.0 - fat12_bs.s - FAT12 BOOT SECTOR
     3                                  ; ----------------------------------------------------------------------------
     4                                  ; Last Update: 26/12/2017
     5                                  ; ----------------------------------------------------------------------------
     6                                  ; Beginning: 24/12/2017
     7                                  ; ----------------------------------------------------------------------------
     8                                  ; Assembler: NASM version 2.11  
     9                                  ; ----------------------------------------------------------------------------
    10                                  ;	    ((nasm fat12_bs.s -l fat12_bs.lst -o FAT12_BS.BIN)) 	
    11                                  ; ----------------------------------------------------------------------------
    12                                  ; Turkish Rational DOS
    13                                  ; Operating System Project v2.0 by ERDOGAN TAN (Beginning: 04/01/2016)
    14                                  ;
    15                                  ; NOTE:	This code has some tricks and TRDOS 386 specific modifications
    16                                  ; which are not a part of original Microsoft Windows (XP) FAT12 BS code.
    17                                  ; (Purpose of TRDOS 386 specific modifications and tricks is to load
    18                                  ; 'TRDOS386.SYS' kernel file as easy and as correct, without affecting
    19                                  ; FAT12 FS recognization for other operating systems.) 
    20                                  ;
    21                                  ; Derived from Microsoft WINDOWS XP FAT (FAT16&FAT12) boot sector code
    22                                  ; which is edited/disassembled by Erdogan Tan (17/12/2017), 
    23                                  ; by using BINFILEHEX (Erdogan Tan) & IDA PRO FREE (Hex-Rays SA) programs.	
    24                                  ;
    25                                  ; Derived from 'fat16_bs.s' TRDOS 386 FAT16 boot sector source code
    26                                  ; by Erdogan Tan (24/12/2017).
    27                                  ; ****************************************************************************
    28                                  ; incbin "FAT12_BS.BIN" (in 'hdimage.s' & 'hdformat.s')
    29                                  
    30                                  rts_segment     equ	1000h
    31                                  
    32                                  [BITS 16]
    33                                  [ORG 7C00h]
    34                                  BS_jmpBoot:
    35 00000000 EB3C                                    jmp     short loc_3E	; jmp short start
    36                                  BS_jmpBoot_nop:
    37 00000002 90                                      nop
    38                                  
    39                                  ; BootSector Identification (Data) Block
    40                                  BS_OEMName:
    41 00000003 4D53444F53352E30        		db	'MSDOS5.0'	; bp+3
    42 0000000B 0002                    BPB_BytesPerSec: dw	512		; bp+11
    43 0000000D 08                      BPB_SecPerClus:	db	8		; bp+13
    44 0000000E 0100                    BPB_RsvdSecCnt: dw	1		; bp+14
    45 00000010 02                      BPB_NumFATs:	db	2		; bp+16
    46 00000011 0002                    BPB_RootEntCnt:	dw	512		; bp+17
    47 00000013 0000                    BPB_TotSec16:	dw	0		; bp+19
    48 00000015 F8                      BPB_Media:	db	0F8h		; bp+21
    49 00000016 0000                    BPB_FATSz16:	dw	0		; bp+22
    50 00000018 3F00                    BPB_SecPerTrk:	dw	63		; bp+24
    51 0000001A 1000                    BPB_NumHeads:	dw	16		; bp+26
    52 0000001C 01000000                BPB_HiddSec:	dd	1		; bp+28
    53 00000020 00000000                BPB_TotSec32:	dd	0		; bp+32
    54 00000024 80                      BS_DrvNum:	db	80h		; bp+36
    55 00000025 00                      BS_Reserved1:	db	0		; bp+37
    56 00000026 29                      BS_BootSig:	db	29h		; bp+38
    57 00000027 00000000                BS_VolID:	dd	0		; bp+39
    58 0000002B 5452444F5333383620-     BS_VolLab:	db	'TRDOS386   '	; bp+43
    58 00000034 2020               
    59 00000036 4641543132202020        BS_FilSysType:	db	'FAT12   '	; bp+54
    60                                  
    61                                  start:
    62                                  loc_3E:
    63 0000003E 01FF                    		add	di, di ; db 01h, 0FFh -> FAT 12
    64                                  			 ; TRDOS 386 (FAT12 BS) identifier/trick!
    65                                  
    66 00000040 BD007C                  		mov	bp, 7C00h
    67                                  
    68 00000043 3DA101                  		cmp	ax, 417  ; If AX=417, the masterboot sector
    69                                  				 ; has a SINGLIX FS (& TRDOS 386)
    70                                  				 ; masterboot code; and...  
    71                                  				 ; DX=ES=SS=0, BP=7C00h
    72                                  				 ; SP=7C00h ... masterboot sector has
    73                                  				 ; been loaded at 0:600h, it has
    74                                  				 ; CHS parameters at offset 600h+420.
    75                                  				 ; (There is a 01A1h in offset 600h+417)
    76                                  	
    77 00000046 740D                    		je	short bs_01 ; no need to following assignments !
    78                                  
    79                                  		;xor	ax, ax
    80                                  		;mov	ds, ax
    81                                  		;mov	es, ax
    82 00000048 0E                      		push	cs
    83 00000049 1F                      		pop	ds
    84 0000004A 1E                      		push	ds
    85 0000004B 07                      		pop	es
    86 0000004C FA                      		cli
    87                                  		;mov	ss, ax
    88                                  		;mov	sp, bp
    89 0000004D 0E                      		push	cs
    90 0000004E 17                      		pop	ss
    91 0000004F 89EC                    		mov	sp, bp
    92 00000051 FB                      		sti
    93 00000052 8A5624                  		mov	dl, [bp+24h] ; [BS_DrvNum]
    94                                  bs_01:
    95 00000055 8936[FC01]              		mov	[bsReserved1], si ; Partition entry address..
    96                                  					  ; (from Singlix FS MBR)
    97                                  					  ; (7BEh,7CEh,7DEh,7EEh) 
    98                                  
    99                                  		; Check Bytes/Sector value
   100                                  		; It must be 512 !? (at least, for TRDOS386) 
   101                                  		;cmp	word [bp+0Bh], 512 ; [BPB_BytesPerSec]
   102                                  		;cmp	byte [bp+0Ch], 2
   103                                  		;jne	short invalid_system_disk
   104                                  
   105                                  		; Check Extended Boot Signature (It must be 29h)
   106                                  		;cmp	byte [bp+26h], 29h ; [BS_BootSig]
   107                                  		;jne	short invalid_system_disk
   108                                  
   109                                  		; overwrite hd drive number !
   110                                                  ;mov	[BS_DrvNum], dl	; drive number from INT 19h
   111 00000059 885624                  		mov	[bp+24h], dl
   112                                  		;mov	[bp+25h], dh	; [BS_Reserved1] = Partition ID !!!
   113                                  		;mov	[bp+24h], dx	
   114                                  
   115                                  		; reset address pointers and set SP
   116                                  		;xor	cx, cx ; 0
   117                                  		;push	cx ; [bp-2] ; Cluster 2 address (high word)
   118                                  		;push	cx ; [bp-4] ; Cluster 2 address (low word)
   119                                  		;push	cx ; [bp-6] ; FAT (0) address (high word)
   120                                  		;push	cx ; [bp-8] ; FAT (0) address (low word)
   121 0000005C 83EC08                  		sub	sp, 8
   122                                  		;dec	cx ; 0FFFFh
   123                                  		;push	cx ; [bp-10] ; FAT sector buffer address reset (-1)
   124                                  		;inc	cx ; 0
   125 0000005F 6AFF                    		push	0FFFFh
   126 00000061 680010                  		push	rts_segment ; Kernel loading segment in 7BF4h
   127                                  
   128                                  		; SP = 7BF4h	
   129                                  
   130                                  		; calculate cluster 2 address
   131 00000064 31C9                    		xor	cx, cx
   132 00000066 8B461C                  		mov	ax, [bp+1Ch]	; word [BPB_HiddSec]
   133 00000069 8B561E                  		mov	dx, [bp+1Eh]	; word [BPB_HiddSec+2]
   134 0000006C 03460E                  		add	ax, [bp+0Eh]	; [BPB_RsvdSecCnt]
   135 0000006F 11CA                    		adc	dx, cx ; 0
   136                                  
   137 00000071 8946F8                  		mov	[bp-8], ax	; FAT beginning sector (lw)		
   138 00000074 8956FA                  		mov	[bp-6], dx	; FAT beginning sector (hw)
   139                                  		
   140 00000077 8A4610                  		mov	al, [bp+10h]	; [BPB_NumFATs]
   141 0000007A 98                      		cbw
   142 0000007B F76616                  		mul	word [bp+16h]	; [BPB_FATSz16]
   143                                  
   144 0000007E 0346F8                  		add	ax, [bp-8]
   145 00000081 1356FA                  		adc	dx, [bp-6]
   146                                  
   147 00000084 8B7611                  		mov	si, [bp+11h]	; [BPB_RootEntCnt]
   148 00000087 BB0002                  		mov	bx, 512
   149 0000008A 60                      		pusha
   150 0000008B 8946FC                  		mov	[bp-4],	ax	; [7BFCh] = Root Dir address
   151 0000008E 8956FE                  		mov	[bp-2],	dx
   152 00000091 B82000                  		mov	ax, 20h	; 32	; Directory Entry Size
   153 00000094 F7E6                    		mul	si
   154                                  		;mov	bx, [bp+0Bh]	; [BPB_BytesPerSec] =  512
   155                                  		;mov	bx, 512
   156 00000096 01D8                    		add	ax, bx		
   157 00000098 48                      		dec	ax
   158 00000099 F7F3                    		div	bx
   159                                  		; AX =	Root directory sectors
   160 0000009B 0146FC                  		add	[bp-4],	ax	; [7BFCh]  = Start of Data area 
   161 0000009E 114EFE                  		adc	[bp-2],	cx  	; adc [bp-2], 0
   162                                  		;popa
   163                                  
   164                                  		;; check for ROMBIOS INT 13h extensions
   165                                  		;mov	ah, 41h
   166                                  		;mov	bx, 55AAh
   167                                  		;;mov	dl, [BS_DrvNum]
   168                                  		;;mov	dl, [bp+40h]
   169                                  		;int	13h
   170                                  		;jc	short bs_02
   171                                  		;cmp	bx, 0AA55h
   172                                  		;jne	short bs_02
   173                                  		;test	cl, 1
   174                                  		;jz	short bs_02
   175                                  
   176                                  		; ROMBIOS INT 13h extentions are present...
   177                                  
   178                                  		;;mov	al, [loc_3E]
   179                                  		;mov	al, [bp+62]
   180                                  		;;mov	[BS_jmpBoot+2], al ; 'LBA mode is available'
   181                                  		;mov	[bp+2], al ; 0Eh (LBA) or 06h (CHS) or 04h (CHS)
   182                                  bs_02:
   183 000000A1 61                      		popa
   184 000000A2 EB07                    		jmp	short load_root_dir_sector
   185                                  
   186                                  check_next_dir_entry:
   187 000000A4 83C720                  		add	di, 32	; next dir entry
   188 000000A7 39DF                    		cmp	di, bx	; end of root dir buffer
   189 000000A9 7209                    		jb	short search_startup_file
   190                                  
   191                                  load_root_dir_sector:
   192                                  		; load root directory and check directory entries 
   193                                  		; 25/12/2017
   194                                  		;mov	bx, 7E00h	; Root dir buffer (1 sector)
   195 000000AB B77E                    		mov	bh, 7Eh 
   196 000000AD 89DF                    		mov	di, bx		; Root dir entry offset
   197                                  		; DX_AX = root dir sector address (DX = 0)
   198                                  		;mov	cl, 1
   199 000000AF E8BD00                  		call	Read1Sector	; Read 1 sector (CL=1)
   200 000000B2 721E                    		jc	short disk_io_error
   201                                  
   202                                  		; BX = 8000h
   203                                  search_startup_file: 
   204                                  		; check/compare root dir entry for/with kernel file
   205 000000B4 382D                    		cmp	[di], ch ; 0
   206 000000B6 740E                    		je	invalid_system_disk ; kernel not found!
   207 000000B8 60                      		pusha
   208 000000B9 B10B                    		mov	cl, 11 ; 0Bh
   209 000000BB BE[F001]                		mov	si, rtsfilename ; Run Time System file name
   210                                  					; or Kernel file name
   211                                  					; (or Startup file name)
   212                                  					; (or Standalone file name)
   213                                  					; in MSDOS directory entry
   214                                  					; format. ('TRDOS386SYS')
   215                                  					; It is 'TRDOS386.SYS'
   216                                  					; for TRDOS 386 OS.
   217 000000BE F3A6                    		repe	cmpsb ; compare dir entry and kernel's name
   218 000000C0 61                      		popa
   219 000000C1 7414                    		jz	short load_startup_file ; kernel is there!
   220 000000C3 4E                      		dec	si ; countdown from Root dir entry count
   221 000000C4 75DE                    		jnz	short check_next_dir_entry
   222                                  
   223                                  invalid_system_disk: 
   224                                  		; 'Replace Disk & Press Any Key' message (24/12/2017)
   225 000000C6 BE[BE01]                		mov	si, Inv_disk_Msg
   226                                  write_disk_io_err_msg:
   227 000000C9 E89500                  		call	print_msg
   228                                  getchar_reboot:
   229                                  		; Wait for a keystroke just before reboot
   230 000000CC 30E4                    		xor	ah, ah
   231 000000CE CD16                    		int	16h
   232                                  		
   233 000000D0 CD19                    		int	19h	; disk boot	
   234                                  				; causes reboot of disk system
   235                                  disk_io_error:
   236 000000D2 BE[B101]                		mov	si, Diskio_err_Msg
   237                                  		;call	print_msg
   238 000000D5 EBF2                    		jmp	short write_disk_io_err_msg ; 24/12/2017
   239                                  ;replace_disk:		
   240                                  ;		mov	si, Replace_Msg	
   241                                  ;replace_disk:	
   242                                  ;		mov	si, Disk_err_replace_Msg
   243                                  ;		call	print_msg
   244                                  ;		jmp	short getchar_reboot
   245                                  
   246                                  load_startup_file:
   247                                  		; DI = directory entry offset
   248                                  		; Get the First Cluster (Dir entry offset 26)
   249 000000D7 8B451A                  		mov	ax, [di+1Ah] ; [di+DIR_FstClusLO]
   250                                  ReadCluster:
   251 000000DA 50                      		push	ax ; cluster number
   252                                  		
   253 000000DB 48                      		dec	ax
   254 000000DC 48                      		dec	ax ; cluster number - 2
   255                                  		
   256                                  		;xor	ch, ch 
   257 000000DD 8A4E0D                  		mov	cl, [bp+0Dh]	; [BPB_SecPerClus]
   258 000000E0 F7E1                    		mul	cx
   259                                  
   260 000000E2 0346FC                  		add	ax, [bp-4] ; [7CFCh], Start of FAT FS data area
   261 000000E5 1356FE                  		adc	dx, [bp-2]	
   262                                  
   263                                  		;mov	bx, [next_segment]
   264 000000E8 8B5EF4                  		mov	bx, [bp-12] ; Kernel loading segment (in 7BF4h)
   265 000000EB 06                      		push	es
   266 000000EC 8EC3                    		mov	es, bx ; segment = 1000h +
   267 000000EE 31DB                    		xor	bx, bx ; offset = 0 
   268                                  		; CL = num of sectors to read (= sectors/cluster)
   269 000000F0 E87E00                  		call	ReadSector
   270 000000F3 07                      		pop	es
   271 000000F4 58                      		pop	ax ; cluster number
   272 000000F5 72DB                    		jc	short disk_io_error	
   273 000000F7 C1EB04                  		shr	bx, 4 ; from byte count to paragraph count
   274                                  		;add	[next_segment], bx
   275 000000FA 015EF4                  		add	[bp-12], bx ; Next segment (in 7BF4h)
   276                                  
   277                                  		;call	get_next_cluster
   278                                  		;jc	short disk_io_error
   279                                  
   280                                  get_next_cluster:	; get next (FAT12) file cluster
   281                                  		; AX = current cluster number
   282                                  		;call	get_fat12_entry
   283                                  		;jc	short disk_io_error
   284                                  
   285                                  get_fat12_entry:
   286                                  		; AX = 12 bit cluster number
   287 000000FD 50                      		push	ax ; *
   288 000000FE B90300                  		mov	cx, 3 ; 1 cluster = 3/2 bytes
   289 00000101 F7E1                    		mul	cx
   290 00000103 D1E8                    		shr	ax, 1
   291                                  		
   292                                  		; AX = byte offset in FAT
   293 00000105 BB0006                  		mov	bx, 512*3  ; 3 sectors
   294                                  		;xor	dx, dx
   295 00000108 F7F3                    		div	bx
   296 0000010A 89D3                    		mov	bx, dx  ; offset (0 to 1534)
   297 0000010C F7E1                    		mul	cx ; *3 (0,3,6,9)
   298                                  		; AX = FAT sector number (as offset)
   299                                  		;      (the 1st sector of 3 sectors
   300                                  		;	in the FAT buffer)
   301                                  		
   302 0000010E BF0080                  		mov	di, 8000h ; FAT buffer address	
   303                                  				  ; (8000h to 8600h)
   304                                  		; AX = FAT sector number (relative)
   305                                  		; Check FAT sector number if it is already
   306                                  		; in FAT buffer at 8000h.
   307                                  		; Current FAT sector is in 7BF6h. 
   308                                  		; (Note: initial FAT sector value in 7BF6h is
   309                                  		; 0FFFFh which means the buff is not loaded yet.)
   310 00000111 3B46F6                  		cmp	ax, [bp-10] ; [7BF6h]
   311 00000114 7416                    		je	short bs_03 ; same sector in FAT buffer
   312 00000116 8946F6                  		mov	[bp-10], ax ; save FAT sector number
   313                                  
   314 00000119 53                      		push	bx ; ** ; 0 to 1534 (clust entry offset)
   315                                  
   316                                  		; Calculate absolute (LBA) address of FAT sector
   317                                  		; by adding hidden (partition's start sector)
   318                                  		; and reserved sectors (between BS and FAT).
   319                                  		; (Note: FAT copy 0 address is stored in 7BF8h)
   320 0000011A 31D2                    		xor	dx, dx
   321 0000011C 0346F8                  		add	ax, [bp-8] ; FAT (0) sector addr (lw)
   322 0000011F 1356FA                  		adc	dx, [bp-6] ; FAT (0) sector addr (hw)
   323                                  
   324                                  		;push	bx
   325 00000122 89FB                    		mov	bx, di
   326                                  		; 24/12/2017
   327                                  		; Load 3 consecutive sectors into FAT buffer 
   328                                  		;mov	cx, 3
   329 00000124 E84A00                  		call	ReadSector
   330                                  		; If cf = 1 -> Disk I/O err, not invalid sys disk!
   331 00000127 5B                      		pop	bx ; ** ; FAT buffer entry offset (0-1534)
   332 00000128 5A                      		pop	dx ; *	; Cluster number 
   333 00000129 72A7                    		jc	short disk_io_error
   334                                  		; 25/12/2017
   335 0000012B 52                      		push	dx ; *
   336                                  		;jmp	short end_of_get_fat12_entry
   337                                  bs_03:
   338 0000012C 5A                      		pop	dx ; *
   339                                  ;		retn
   340                                  
   341                                  end_of_get_fat12_entry:
   342 0000012D 8B01                    		mov	ax, [bx+di] ; 16 bit cluster number
   343                                  
   344                                  		; If current cluster number is odd number ..
   345 0000012F 80E201                  		and	dl, 1 ; *
   346 00000132 7403                    		jz	short bs_04 ; even cluster number
   347                                  		; .. shift next cluster number to 4 bits right
   348 00000134 C1E804                  		shr	ax, 4
   349                                  bs_04:
   350 00000137 25FF0F                  		and	ax, 0FFFh
   351                                  		;and	ah, 0Fh
   352                                  		;;cmp	ax, 0FF7h
   353                                  		;;cmc
   354                                  ;;		retn
   355                                  
   356                                  end_of_get_next_cluster:
   357                                  		; 24/12/2017
   358 0000013A 83F802                  		cmp	ax, 2
   359 0000013D 7287                    		jb	short invalid_system_disk 
   360                                  
   361 0000013F 3DF70F                  		cmp	ax, 0FF7h
   362                                  		;jnb	short bs_05 ; Startup file has been loaded.
   363 00000142 7296                    		jb	short ReadCluster ; load/read next cluster
   364                                  
   365                                  end_of_ReadCluster:
   366                                  bs_05:
   367                                  		; Set TRDOS 386 kernel specific parameters (& signs)
   368                                  		; and
   369                                  		; Launch TRDOS 386 Kernel (Startup/RTS file)
   370                                  
   371                                  		;mov	dl, [BS_DrvNum]
   372 00000144 8B5624                                  mov	dx, [bp+24h] ; DL = Drive number, DH = 0 
   373 00000147 FEC6                    		inc	dh  ; TRDOS 386 FAT12 BS major version = 1
   374                                  
   375                                  		;mov	ax, [next_segment] ; 16 paragraphs after the
   376                                  					  ; start of the last segment
   377                                  					  ; of the kernel file loading
   378                                  					  ; space.
   379                                  					  ; So, (top of) stack will have
   380                                  					  ; 256 bytes or more distance
   381                                  					  ; from the last byte
   382                                  					  ; of the kernel file.	 							
   383                                  					  ; (This will be enough for
   384                                  					  ; TRDOS 386 kernel before 
   385                                  					  ; entering protected mode.)
   386                                  
   387 00000149 8B46F4                  		mov	ax, [bp-12] ; [7BF4h] ; the last segment		
   388                                  					      ; which is the kernel file
   389                                  					      ; has been loaded in.	
   390 0000014C FA                      		cli
   391 0000014D 8ED0                    		mov	ss, ax
   392 0000014F BCFEFF                  		mov	sp, 0FFFEh			
   393 00000152 FB                      		sti
   394                                  
   395 00000153 BB0010                  		mov     bx, rts_segment ; 1000h
   396 00000156 8EDB                                    mov	ds, bx
   397 00000158 8EC3                                    mov	es, bx
   398                                  
   399                                  		; bp = 7C00h
   400                                                  
   401 0000015A B8A101                                  mov     ax, 417 ; TRDOS boot sector sign for TRDOS386.SYS
   402                                  		
   403                                  		;jmp	rts_segment:0
   404                                  		
   405 0000015D 06                      		push	es
   406 0000015E 6A00                    		push	0
   407 00000160 CB                      		retf
   408                                  
   409                                  print_msg:
   410                                  		; DS:SI = Error message address (ASCIIZ string)	
   411 00000161 B40E                    		mov	ah, 0Eh
   412 00000163 BB0700                  		mov	bx, 7
   413                                  bs_06:
   414 00000166 AC                      		lodsb
   415 00000167 84C0                    		test	al, al
   416                                  		;jz	short bs_07
   417 00000169 743D                    		jz	short bs_09
   418 0000016B CD10                    		int	10h
   419 0000016D EBF7                    		jmp	short bs_06
   420                                  bs_07:
   421                                  ;		retn
   422                                  
   423                                  Read1Sector:	; 25/12/2017
   424 0000016F B101                    		mov	cl, 1
   425                                  ReadSector:
   426 00000171 B504                    		mov	ch, 4 ; retry count
   427                                  ReadSector_retry:
   428 00000173 60                      		pusha
   429 00000174 91                      		xchg	ax, cx
   430 00000175 8B4618                  		mov	ax, [bp+18h] ; [BPB_SecPerTrk]
   431 00000178 96                      		xchg	ax, si
   432 00000179 92                      		xchg	ax, dx
   433 0000017A 31D2                    		xor	dx, dx
   434 0000017C F7F6                    		div	si
   435 0000017E 91                      		xchg	ax, cx
   436 0000017F F7F6                    		div	si
   437 00000181 42                      		inc	dx
   438 00000182 87CA                    		xchg	cx, dx
   439 00000184 F7761A                  		div	word [bp+1Ah] ; [BPB_NumHeads]
   440 00000187 88D6                    		mov	dh, dl
   441 00000189 88C5                    		mov	ch, al
   442 0000018B C0CC02                  		ror	ah, 2
   443 0000018E 08E1                    		or	cl, ah
   444                                  
   445 00000190 B80102                  		mov	ax, 201h
   446 00000193 8A5624                  		mov	dl, [bp+24h]	; [BS_DrvNum]
   447 00000196 CD13                    		int	13h		; DISK - read
   448 00000198 61                      		popa
   449 00000199 720E                    		jc	short bs_10	; return with error
   450                                  
   451 0000019B 40                      		inc	ax
   452 0000019C 7501                    		jnz	short bs_08
   453 0000019E 42                      		inc	dx
   454                                  bs_08:
   455                                  		;add	bx, [bp+0Bh]	; [BPB_BytesPerSec] = 512
   456                                  		;add	bx, 512
   457 0000019F 80C702                  		add	bh, 2
   458                                  		;dec	cx
   459 000001A2 FEC9                    		dec	cl
   460 000001A4 75CB                    		jnz	short ReadSector
   461                                  		;clc
   462 000001A6 30ED                    		xor	ch, ch
   463                                  bs_09:
   464 000001A8 C3                      		retn
   465                                  bs_10:
   466 000001A9 FECD                    		dec	ch
   467 000001AB 75C6                    		jnz	short ReadSector_retry
   468 000001AD C3                      		retn
   469                                  
   470                                  ;next_segment:
   471                                  ;		dw	rts_segment
   472                                  
   473 000001AE 04                      		db	04
   474 000001AF 01                      		db	01
   475 000001B0 07                      		db	07h ; filler
   476                                  
   477                                  Diskio_err_Msg:
   478 000001B1 0D0A                                    db	0Dh, 0Ah
   479 000001B3 4469736B206572726F-     		db	'Disk error!'
   479 000001BC 7221               
   480                                  		;db	0
   481                                  Inv_disk_Msg:   
   482                                  ;		db	0Dh, 0Ah
   483                                  ;		db	'Invalid system disk'
   484                                  ;Disk_err_replace_Msg:
   485                                  ;		db	'!'
   486                                  Replace_Msg:    
   487 000001BE 0D0A                    		db	0Dh, 0Ah
   488 000001C0 5265706C6163652074-     		db	'Replace the disk and press any key to reboot.'
   488 000001C9 6865206469736B2061-
   488 000001D2 6E6420707265737320-
   488 000001DB 616E79206B65792074-
   488 000001E4 6F207265626F6F742E 
   489 000001ED 0D0A00                  		db	0Dh, 0Ah, 0
   490                                  
   491                                  		;times	(508+rtsfilename-bsReserved1) - ($ - $$) db 0
   492                                  rtsfilename:
   493 000001F0 5452444F5333383653-                     db      'TRDOS386SYS'
   493 000001F9 5953               
   494 000001FB 00                                      db      0
   495                                  next_segment:
   496                                  		;org	7C00h+1FCh ; BS offset 508 (bp+508)
   497                                  bsReserved1:
   498 000001FC 5452                    		db	'TR'  ; 'Turkish Rational DOS' feature identifier.
   499                                  bootsignature1:
   500 000001FE 55AA                    		db	55h, 0AAh
