1 ; **************************************************************************** 2 ; R5HDBOOT.ASM (R5HDBOOT.COM) - Retro DOS v5 Hard Disk Boot Sector Utility 3 ; (for MSDOS/WINDOWS) 4 ; ---------------------------------------------------------------------------- 5 ; Last Update: 29/01/2026 6 ; ---------------------------------------------------------------------------- 7 ; Beginning: 03/05/2024 8 ; ---------------------------------------------------------------------------- 9 ; Assembler: NASM version 2.15 (r5hdboot.s) 10 ; ---------------------------------------------------------------------------- 11 ; Modified from 'trhdboot.s'(TRHDBOOT.COM) source code by Erdogan Tan 12 ; (12/09/2020) - TRDOS 386 v2 hard disk boot sector modification utility - 13 ; **************************************************************************** 14 ; assembling: nasm r5hdboot.s -l r5hdboot.txt -o R5HDBOOT.COM -Z error.txt 15 16 ; ---------------------------------------------------------------------------- 17 ; equations 18 ; ---------------------------------------------------------------------------- 19 20 ; boot sector parameters 21 22 bsOemName equ 3 ; ('MSWIN4.1') --> 'RETRODOS' ; 03/05/2024 23 bsBytesPerSec equ 11 ; 512 (word) 24 bsSecPerClust equ 13 25 bsResSectors equ 14 26 bsFATs equ 16 27 bsRootDirEnts equ 17 28 bsSectors equ 19 29 bsMedia equ 21 ; 0F8h 30 bsFATsecs equ 22 31 bsSecPerTrack equ 24 32 bsHeads equ 26 33 bsHidden1 equ 28 34 bsHidden2 equ 30 35 bsHugeSectors equ 32 36 ; FAT 16 bs & FAT 12 bs 37 bsDriveNumber equ 36 ; 80h 38 bsReserved1 equ 37 39 bsBpbSignature equ 38 ; 29h (byte) 40 bsVolumeID equ 39 41 bsVolumeLabel equ 43 42 bsFileSysType equ 54 ; 'FAT16 ' (8 bytes) 43 ; FAT 32 bs 44 BPB_FATSz32 equ 36 45 BPB_ExtFlags equ 40 46 BPB_FSVer equ 42 47 BPB_RootClus equ 44 48 BPB_FSInfo equ 48 49 BPB_BkBootSec equ 50 50 BPB_Reserved equ 52 51 BS_DrvNum equ 64 ; 80h 52 BS_Reserved1 equ 65 53 BS_BootSig equ 66 ; 29h (byte) 54 BS_VolID equ 67 55 BS_VolLab equ 71 56 BS_FilSysType equ 82 ; 'FAT32 ' (8 bytes) 57 58 ; Masterboot / Partition Table at Beginning+1BEh 59 ptBootable equ 0 60 ptBeginHead equ 1 61 ptBeginSector equ 2 62 ptBeginCylinder equ 3 63 ptFileSystemID equ 4 64 ptEndHead equ 5 65 ptEndSector equ 6 66 ptEndCylinder equ 7 67 ptStartSector equ 8 68 ptSectors equ 12 69 70 partition_table equ 1BEh 71 72 ; ---------------------------------------------------------------------------- 73 ; code 74 ; ---------------------------------------------------------------------------- 75 76 [BITS 16] 77 [ORG 100h] 78 79 00000000 FA cli 80 00000001 FC cld 81 00000002 0E push cs 82 00000003 17 pop ss 83 00000004 BCFEFF mov sp, 0FFFEh 84 00000007 FB sti 85 86 ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 87 ; see if drive specified 88 ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 89 90 00000008 BE8000 mov si, 80h ; PSP command tail 91 0000000B 8A0C mov cl, [si] 92 0000000D 08C9 or cl, cl 93 0000000F 7457 jz short T_9 ; jump if zero 94 T_1: 95 00000011 46 inc si 96 97 00000012 8A04 mov al, [si] 98 00000014 3C20 cmp al, ' ' ; is it SPACE ? 99 00000016 7506 jne short T_2 100 101 00000018 FEC9 dec cl 102 0000001A 75F5 jnz short T_1 103 0000001C EB4A jmp short T_9 104 T_2: 105 0000001E 46 inc si 106 0000001F 803C3A cmp byte [si], ':' 107 00000022 741D je short T_3 108 00000024 803C20 cmp byte [si], ' ' 109 00000027 7618 jna short T_3 110 111 00000029 3C68 cmp al, 'h' 112 0000002B 753B jne short T_9 113 0000002D 803C64 cmp byte [si], 'd' 114 00000030 7536 jne short T_9 115 00000032 46 inc si 116 00000033 8A04 mov al, [si] 117 00000035 3C30 cmp al, '0' 118 00000037 7429 je short T_8 119 00000039 722D jb short T_9 120 0000003B 3C33 cmp al, '3' 121 0000003D 7623 jna short T_8 122 0000003F EB27 jmp short T_9 123 T_3: 124 00000041 3C43 cmp al, 'C' 125 00000043 7223 jb short T_9 126 00000045 7414 je short T_6 127 ;cmp al, 'Z' ; A - Z 128 ;jna short T_6 129 00000047 3C44 cmp al, 'D' 130 00000049 7610 jna short T_6 131 0000004B 3C5A cmp al, 'Z' 132 0000004D 7619 jna short T_9 133 T_4: 134 0000004F 3C63 cmp al, 'c' ; a - z 135 00000051 7215 jb short T_9 136 00000053 7404 je short T_5 137 ;cmp al, 'z' 138 ;ja short T_9 139 00000055 3C64 cmp al, 'd' 140 00000057 770F ja short T_9 141 T_5: 142 00000059 2C20 sub al, 'a'-'A' ; to upper case 143 144 ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 145 ; get drive code 146 ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 147 148 T_6: 149 0000005B 2C13 sub al, 'C'-'0' 150 T_7: 151 0000005D A2[F10D] mov [RD5_Drive], al ; '0' .. '4' 152 00000060 EB0F jmp short T_10 153 T_8: 154 00000062 46 inc si 155 00000063 803C20 cmp byte [si], ' ' 156 00000066 76F5 jna short T_7 157 158 ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 159 ; Write message 160 ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 161 162 T_9: 163 00000068 BE[A40B] mov si, RD5_Welcome 164 0000006B E86C02 call print_msg 165 ;cmp cl, 0 166 ;ja short T_35 167 0000006E E95202 jmp T_35 168 169 ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 170 ; get drive parameters 171 ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 172 173 T_10: 174 00000071 B408 mov ah, 08h 175 ;mov dl, [RD5_Drive] ; drive 176 00000073 88C2 mov dl, al 177 00000075 80C250 add dl, 80h -'0' ; make it 80h based 178 00000078 8816[A00B] mov [drv], dl 179 0000007C CD13 int 13h ; return disk parameters 180 181 0000007E 0E push cs 182 0000007F 07 pop es ; restore es 183 184 00000080 08E4 or ah, ah 185 00000082 753B jnz short T_12 ; error 186 187 00000084 88C8 mov al, cl 188 00000086 243F and al, 63 189 00000088 A2[D80E] mov [sectors], al 190 0000008B C0E906 shr cl, 6 191 0000008E 86E9 xchg ch, cl 192 00000090 41 inc cx 193 00000091 890E[DA0E] mov [cylinders], cx 194 00000095 FEC6 inc dh 195 00000097 8836[D90E] mov [heads], dh 196 0000009B F6E6 mul dh 197 ; ax = heads * spt 198 0000009D F7E1 mul cx ; * cylinders 199 ; dx:ax = chs limit 200 0000009F A3[D40E] mov [CHS_limit], ax 201 000000A2 8916[D60E] mov [CHS_limit+2], dx 202 203 ; check for (valid) primary dos partition 204 205 ;mov byte [RetryCount], 4 206 207 ;mov ax, 0201h ; read disk 208 000000A6 BB[E40E] mov bx, MBR ; location of masterboot code 209 210 000000A9 B90100 mov cx, 1 ; cylinder = 0 211 ; sector = 1 212 000000AC B600 mov dh, 0 ; head = 0 213 ;mov dl, [RD5_Drive] ; drive 214 ;add dl, 80h -'0' ; make it 80h based 215 000000AE 8A16[A00B] mov dl, [drv] 216 T_11: 217 000000B2 B80102 mov ax, 0201h 218 000000B5 CD13 int 13h 219 ;jc short T_12 220 000000B7 7311 jnc short T_13 ; read masterboot sector, OK 221 222 000000B9 FE0E[D00E] dec byte [RetryCount] 223 000000BD 75F3 jnz short T_11 224 T_12: 225 000000BF C606[560E]00 mov byte [zbyte], 0 226 000000C4 E81002 call T_37 ; write error message 227 000000C7 E9F901 jmp T_35 ; terminate 228 229 T_13: 230 000000CA 813E[E210]55AA cmp word [MBR+510], 0AA55h 231 000000D0 75ED jne short T_12 232 233 000000D2 BE[A610] mov si, MBR+(partition_table+ptFileSystemID) 234 T_14: 235 000000D5 E89102 call validate_primary_dos_partition 236 000000D8 7312 jnc short T_15 237 238 000000DA 83C610 add si, 16 239 000000DD 81FE[E610] cmp si, MBR+partition_table+ptFileSystemID+64 240 000000E1 72F2 jb short T_14 241 242 000000E3 BE[9E0E] mov si, RD5_fatp_notfound 243 000000E6 E8F101 call print_msg 244 000000E9 E9D701 jmp T_35 245 246 T_15: 247 ; valid primary dos partition 248 ; al = FAT type (1,2,3) 249 ; ah = partition type 250 251 000000EC A2[CF0E] mov byte [fattype], al 252 000000EF 3C02 cmp al, 2 253 000000F1 741B je short T_17 ; FAT16 BS (default offset addr) 254 000000F3 720E jb short T_16 255 ; set Retro DOS v5 BS pointer for FAT32 BS 256 000000F5 C706[9C03][A003] mov word [retrodosv5bs], RD5_FAT32_hd_bs 257 ; set FS type string 258 000000FB C706[8F0E]3332 mov word [fattype_str],'32' ; 'FAT32' 259 ; ok.. read boot sector 260 00000101 EB0B jmp short T_17 261 T_16: 262 ; set Retro DOS v5 BS pointer for FAT12 BS 263 00000103 C706[9C03][A009] mov word [retrodosv5bs], RD5_FAT12_hd_bs 264 00000109 C606[900E]32 mov byte [fattype_str+1],'2' ; 'FAT12' 265 T_17: 266 0000010E C606[D00E]05 mov byte [RetryCount], 5 267 268 00000113 83C604 add si, ptStartSector-ptFileSystemID 269 00000116 8B04 mov ax, [si] 270 00000118 8B5402 mov dx, [si+2] 271 0000011B A3[DC0E] mov [dosp_start], ax 272 0000011E 8916[DE0E] mov [dosp_start+2], dx 273 00000122 83C604 add si, ptSectors-ptStartSector 274 00000125 8B0C mov cx, [si] 275 00000127 8B5C02 mov bx, [si+2] 276 0000012A 890E[E00E] mov [dosp_size], cx 277 0000012E 891E[E20E] mov [dosp_size+2], bx 278 00000132 01C1 add cx, ax 279 00000134 11D3 adc bx, dx 280 00000136 7287 jc short T_12 281 282 00000138 3B1E[D60E] cmp bx, [CHS_limit+2] 283 0000013C BB[E40E] mov bx, bootsector 284 0000013F 772C ja short T_20 ; LBA read/write 285 00000141 7206 jb short T_18 286 00000143 3B0E[D40E] cmp cx, [CHS_limit] 287 00000147 7724 ja short T_20 288 T_18: 289 ; CHS read 290 291 00000149 83EE0B sub si, ptSectors-ptBeginHead 292 293 0000014C 8A34 mov dh, [si] ; head 294 0000014E 46 inc si 295 0000014F 8B0C mov cx, [si] ; sector 296 ; cl = sector, ch = cylinder 297 ;mov bx, bootsector 298 00000151 8A16[A00B] mov dl, [drv] 299 300 00000155 8836[A10B] mov [_dh], dh 301 00000159 890E[A20B] mov [_cx], cx 302 T_19: 303 0000015D B80102 mov ax, 0201h ; read one sector 304 00000160 CD13 int 13h 305 00000162 733A jnc short T_22 ; OK 306 00000164 FE0E[D00E] dec byte [RetryCount] 307 00000168 75F3 jnz short T_19 308 0000016A E952FF jmp T_12 309 T_20: 310 ; LBA read 311 0000016D C606[D10E]01 mov byte [lba], 1 312 ;mov ax, [dosp_start] 313 ;mov dx, [dosp_start+2] 314 T_21: 315 ;pusha ; db 60h 316 00000172 60 db 60h 317 ;push 0 ; db 6Ah, 00h 318 00000173 6A00 db 6Ah, 0 319 ;push 0 ; db 6Ah, 00h 320 00000175 6A00 db 6Ah, 0 321 00000177 52 push dx 322 00000178 50 push ax 323 00000179 06 push es 324 0000017A 53 push bx 325 ;push 1 ; db 6Ah, 01h 326 0000017B 6A01 db 6Ah, 01h 327 ;push 10h ; db 6Ah, 10h 328 0000017D 6A10 db 6Ah, 10h 329 330 0000017F 8A16[A00B] mov dl, [drv] 331 00000183 B442 mov ah, 42h 332 00000185 89E6 mov si, sp 333 00000187 CD13 int 13h 334 335 ;popa 336 00000189 61 db 61h 337 ;popa 338 0000018A 61 db 61h 339 0000018B 7311 jnc short T_22 340 341 0000018D FE0E[D00E] dec byte [RetryCount] 342 00000191 0F842AFF jz T_12 343 344 00000195 A1[DC0E] mov ax, [dosp_start] 345 00000198 8B16[DE0E] mov dx, [dosp_start+2] 346 0000019C EBD4 jmp short T_21 347 348 T_22: 349 0000019E 813E[E210]55AA cmp word [bootsector+510], 0AA55h 350 000001A4 7536 jne short T_23 351 352 000001A6 813E[EF0E]0002 cmp word [bootsector+bsBytesPerSec], 512 353 000001AC 752E jne short T_23 354 355 000001AE 803E[F90E]F8 cmp byte [bootsector+bsMedia], 0F8h 356 000001B3 7527 jne short T_23 357 358 000001B5 803E[CF0E]02 cmp byte [fattype], 2 359 000001BA 7729 ja short T_24 360 361 000001BC 803E[0A0F]29 cmp byte [bootsector+bsBpbSignature], 29h 362 000001C1 7519 jne short T_23 363 000001C3 66813E[1A0F]464154- cmp dword [bootsector+bsFileSysType], 'FAT1' 363 000001CB 31 364 000001CC 750E jne short T_23 365 366 000001CE B92B00 mov cx, 54-11 ; byte count to be copied 367 368 000001D1 A0[1E0F] mov al, [bootsector+bsFileSysType+4] 369 000001D4 3C36 cmp al, '6' 370 000001D6 7430 je short T_25 371 372 000001D8 3C32 cmp al, '2' 373 000001DA 742C je short T_25 374 T_23: 375 000001DC BE[690E] mov si, RD5_invalid_bootsector 376 000001DF E8F800 call print_msg 377 000001E2 E9DE00 jmp T_35 378 T_24: 379 ; 03/05/2024 380 000001E5 833E[FA0E]00 cmp word [bootsector+bsFATsecs], 0 381 000001EA 77F0 ja short T_23 ; not FAT32 fs 382 383 000001EC 803E[260F]29 cmp byte [bootsector+BS_BootSig], 29h 384 000001F1 75E9 jne short T_23 385 000001F3 66813E[360F]464154- cmp dword [bootsector+BS_FilSysType], 'FAT3' 385 000001FB 33 386 000001FC 75DE jne short T_23 387 000001FE 803E[3A0F]32 cmp byte [bootsector+BS_FilSysType+4], '2' 388 00000203 75D7 jne short T_23 389 390 00000205 B94700 mov cx, 82-11 ; byte count to be copied 391 T_25: 392 00000208 BE[1A0D] mov si, RD5_Do_you_want 393 0000020B E8CC00 call print_msg 394 T_26: 395 ;xor ax, ax 396 ;int 16h ; wait for keyboard command 397 ;cmp al, 'y' 398 ;je short T_27 ; retry 399 ;cmp al, 'Y' 400 ;je short T_27 401 ;cmp al, 'n' 402 ;je short T_35 ; exit 403 ;cmp al, 'N' 404 ;je short T_35 405 ;cmp al, 'C'-40h 406 ;je short T_35 407 ;cmp al, 27 408 ;je short T_35 409 ;jmp short T_26 410 411 0000020E E8D800 call get_answer 412 00000211 3C59 cmp al, 'Y' 413 00000213 7409 je short T_27 414 415 00000215 BE[BE0D] mov si, _no_str 416 00000218 E8BF00 call print_msg 417 0000021B E9A500 jmp T_35 418 419 T_27: 420 0000021E BE[B70D] mov si, _yes_str 421 00000221 E8B600 call print_msg 422 423 ;mov si, RD5_CRLF 424 ;call print_msg 425 426 ; set 'RETRODOS' as OEM name 427 00000224 8B3E[9C03] mov di, [retrodosv5bs] 428 00000228 83C703 add di, bsOemName 429 0000022B B85245 mov ax, 'RE' 430 0000022E AB stosw 431 0000022F B85452 mov ax, 'TR' 432 00000232 AB stosw 433 00000233 B84F44 mov ax, 'OD' 434 00000236 AB stosw 435 00000237 B84F53 mov ax, 'OS' 436 0000023A AB stosw 437 438 ; DI points to retrodosv5bs+bsBytesPerSec 439 0000023B BE[EF0E] mov si, bootsector+bsBytesPerSec 440 441 0000023E F3A4 rep movsb 442 443 00000240 BE[C40D] mov si, RD5_PressKeyWhenReady 444 00000243 E89400 call print_msg 445 T_28: 446 00000246 31C0 xor ax, ax 447 00000248 CD16 int 16h ; wait for keyboard command 448 0000024A 3C0D cmp al, 'M'-40h ; Enter (OK) key 449 0000024C 740A je short T_29 ; write 450 0000024E 3C03 cmp al, 'C'-40h 451 00000250 7471 je short T_35 ; no write (exit) 452 00000252 3C1B cmp al, 27 453 00000254 746D je short T_35 454 00000256 EBEE jmp short T_28 455 456 T_29: 457 00000258 BE[310E] mov si, RD5_CRLF 458 0000025B E87C00 call print_msg 459 T_30: 460 ;xor ax, ax 461 ;int 1Ah ; get time of day 462 463 ;mov si, volume_id 464 465 ;mov [si], dx 466 ;mov [si+2], cx ; set unique volume ID 467 468 ;mov ah, 02h ; Return Current Time 469 ;int 1Ah 470 ;xchg ch, cl 471 ;xchg dh, dl 472 473 ;add cx, dx 474 ;add [si+2], cx 475 476 ;mov ah, 04h ; Return Current Date 477 ;int 1Ah 478 ;xchg ch, cl 479 ;xchg dh, dl 480 481 ;add cx, dx 482 ;add [si+2], cx 483 484 ;mov ax, [vol_id] 485 ;mov dx, [vol_id+2] 486 487 0000025E 8B1E[9C03] mov bx, [retrodosv5bs] ; location of boot code 488 ; es: bx = boot sector buffer address 489 490 ;mov si, bx 491 ;add si, bsVolumeID 492 493 ;cmp byte [fattype], 3 494 ;jne short T_31 495 496 ;add si, BS_VolID-bsVolumeID 497 ;T_31: 498 ;mov [si], ax 499 ;mov [si+2], dx 500 501 00000262 803E[D10E]01 cmp byte [lba], 1 502 00000267 731E jnb short T_32 ; LBA write 503 504 00000269 8A16[A00B] mov dl, [drv] ; drive 505 0000026D 8A36[A10B] mov dh, [_dh] ; head 506 00000271 8B0E[A20B] mov cx, [_cx] ; cl = sector, ch = cylinder (low 8 bits) 507 T_31: 508 00000275 B80103 mov ax, 0301h ; write to disk 509 ; es: bx = boot sector buffer address 510 511 00000278 CD13 int 13h 512 0000027A 733A jnc short T_34 ; ok 513 514 ; error 515 516 0000027C FE0E[D00E] dec byte [RetryCount] 517 00000280 75F3 jnz short T_31 518 00000282 E85200 call T_37 519 00000285 EB47 jmp short T_36 520 521 T_32: 522 00000287 A1[DC0E] mov ax, [dosp_start] 523 0000028A 8B16[DE0E] mov dx, [dosp_start+2] 524 T_33: 525 ;pusha ; db 60h 526 0000028E 60 db 60h 527 ;push 0 ; db 6Ah, 00h 528 0000028F 6A00 db 6Ah, 0 529 ;push 0 ; db 6Ah, 00h 530 00000291 6A00 db 6Ah, 0 531 00000293 52 push dx 532 00000294 50 push ax 533 00000295 06 push es 534 00000296 53 push bx 535 ;push 1 ; db 6Ah, 01h 536 00000297 6A01 db 6Ah, 01h 537 ;push 10h ; db 6Ah, 10h 538 00000299 6A10 db 6Ah, 10h 539 540 0000029B 8A16[A00B] mov dl, [drv] 541 0000029F B443 mov ah, 43h ; LBA write 542 000002A1 30C0 xor al, al ; verify off 543 000002A3 89E6 mov si, sp 544 000002A5 CD13 int 13h 545 546 ;popa 547 000002A7 61 db 61h 548 ;popa 549 000002A8 61 db 61h 550 000002A9 730B jnc short T_34 551 552 000002AB FE0E[D00E] dec byte [RetryCount] 553 000002AF 75D6 jnz short T_32 554 000002B1 E82300 call T_37 555 000002B4 EB18 jmp short T_36 556 557 ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 558 ; success. try again ? 559 ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 560 561 T_34: 562 000002B6 803E[CF0E]03 cmp byte [fattype], 3 ; FAT32 563 000002BB 744D je short T_40 564 565 000002BD BE[F50D] mov si, RD5_disk_WrittenSuccesfully 566 000002C0 E81700 call print_msg 567 T_35: 568 000002C3 BE[310E] mov si, RD5_CRLF 569 000002C6 E81100 call print_msg 570 000002C9 B8004C mov ax, 4C00h ; terminate 571 000002CC CD21 int 21h 572 T_36: 573 ;xor ax, ax 574 ;int 16h ; wait for keyboard command 575 ;cmp al, 'y' 576 ;je short TX_15 ; retry 577 ;cmp al, 'Y' 578 ;je short TX_15 579 ;cmp al, 'n' 580 ;je short T_35 ; exit 581 ;cmp al, 'N' 582 ;je short T_35 583 ;cmp al, 'C'-40h 584 ;je short T_35 585 ;cmp al, 27 586 ;je short T_35 587 ;jmp short T_36 588 589 000002CE E81800 call get_answer 590 000002D1 3C59 cmp al, 'Y' 591 000002D3 7483 je short T_29 592 000002D5 EBEC jmp short T_35 593 594 T_37: 595 000002D7 BE[340E] mov si, RD5_disk_NotReadyOrError 596 ;;call print_msg 597 ;;jmp short T_36 598 ;jmp short print_msg 599 600 print_msg: 601 T_38: 602 000002DA AC lodsb ; Load byte at DS:SI to AL 603 000002DB 20C0 and al, al 604 000002DD 7409 jz short T_39 605 000002DF B40E mov ah, 0Eh 606 000002E1 BB0700 mov bx, 07h 607 000002E4 CD10 int 10h ; BIOS Service func ( ah ) = 0Eh 608 ; Write char as TTY 609 ; AL-char BH-page BL-color 610 000002E6 EBF2 jmp short T_38 611 T_39: 612 _NO_: 613 000002E8 C3 retn 614 615 get_answer: 616 000002E9 31C0 xor ax, ax 617 000002EB CD16 int 16h ; wait for keyboard command 618 000002ED 3C79 cmp al, 'y' 619 000002EF 7416 je short _yes ; retry 620 000002F1 3C59 cmp al, 'Y' 621 000002F3 7414 je short _YES_ 622 000002F5 3C6E cmp al, 'n' 623 000002F7 74EF je short _NO_ ; exit 624 000002F9 3C4E cmp al, 'N' 625 000002FB 74EB je short _NO_ 626 000002FD 3C03 cmp al, 'C'-40h 627 000002FF 74E7 je short _NO_ 628 00000301 3C1B cmp al, 27 629 00000303 74E3 je short _NO_ 630 00000305 EBE2 jmp short get_answer 631 _yes: 632 00000307 B059 mov al, 'Y' 633 _YES_: 634 00000309 C3 retn 635 636 T_40: 637 ; write 2nd sector of FAT32 bs code (1024 bytes) 638 639 0000030A C606[D00E]04 mov byte [RetryCount], 4 640 0000030F C606[CF0E]00 mov byte [fattype], 0 641 642 00000314 BB[A005] mov bx, RD5_FAT32_hd_bs+512 643 644 00000317 803E[D10E]00 cmp byte [lba], 0 645 0000031C 7610 jna short T_41 646 647 0000031E A1[DC0E] mov ax, [dosp_start] 648 00000321 8B16[DE0E] mov dx, [dosp_start+2] 649 00000325 83C002 add ax, 2 ; sector 2 in the partition (after FSINFO sector) 650 00000328 83D200 adc dx, 0 651 0000032B E960FF jmp T_33 652 T_41: 653 ; convert FAT32 bootsector+2 address to CHS 654 ;mov dl, [drv] ; drive 655 ;mov dh, [_dh] ; head 656 ;mov cx, [_cx] ; cl = sector, ch = cylinder (low 8 bits) 657 0000032E 89C8 mov ax, cx 658 00000330 243F and al, 63 659 00000332 3A06[D80E] cmp al, [sectors] 660 00000336 7313 jnb short T_43 661 00000338 FEC0 inc al 662 0000033A 3A06[D80E] cmp al, [sectors] 663 0000033E 7307 jnb short T_42 664 00000340 FEC1 inc cl 665 00000342 FEC1 inc cl 666 00000344 E92EFF jmp T_31 667 T_42: 668 00000347 B001 mov al, 1 ; sector 1 669 00000349 EB02 jmp short T_44 670 T_43: 671 0000034B B002 mov al, 2 ; sector 2 672 T_44: 673 0000034D FEC6 inc dh 674 0000034F 3A36[D90E] cmp dh, [heads] 675 00000353 0F821EFF jb T_31 676 00000357 28F6 sub dh, dh ; head 0 677 00000359 C0E906 shr cl, 6 678 0000035C 86E9 xchg ch, cl 679 0000035E 41 inc cx ; next cylinder 680 ;and cx, 1023 681 ;cmp cx, [cylinders] 682 ;jnb short T_37 683 0000035F 86CD xchg cl, ch 684 00000361 C0E106 shl cl, 6 685 00000364 08C1 or cl, al 686 00000366 E90CFF jmp T_31 687 688 validate_primary_dos_partition: 689 690 ; INPUT: 691 ; si = partition table entry offset + file system ID 692 ; OUTPUT: 693 ; cf = 0 -> ah = primary DOS partition ID 694 ; (01h,04h,06h,0Bh,0Ch,0Eh) 695 ; al = FAT type 696 ; 1 = FAT12 697 ; 2 = FAT16 698 ; 3 = FAT32 699 ; 700 ; cf = 1 -> not a primary DOS partition 701 702 00000369 28C0 sub al, al ; mov al, 0 703 704 0000036B 8A24 mov ah, [si] 705 706 0000036D 80FC01 cmp ah, 01h ; FAT12 partition 707 00000370 7228 jb short V_5 ; 0 708 00000372 741E je short V_3 709 V_0: 710 00000374 FEC0 inc al ; mov al, 1 711 712 00000376 80FC06 cmp ah, 06h ; FAT16 CHS partition (>=32MB) 713 00000379 7709 ja short V_2 714 0000037B 7415 je short V_3 715 716 0000037D 80FC04 cmp ah, 04h ; FAT16 CHS partition (< 32MB) 717 00000380 7410 je short V_3 718 V_1: 719 00000382 F9 stc 720 00000383 C3 retn 721 V_2: 722 00000384 FEC0 inc al ; mov al, 2 723 724 00000386 80FC0C cmp ah, 0Ch ; FAT32 LBA partition 725 00000389 7407 je short V_3 726 0000038B 7708 ja short V_4 727 728 0000038D 80FC0B cmp ah, 0Bh ; FAT32 CHS partition 729 00000390 7208 jb short V_5 730 V_3: 731 00000392 FEC0 inc al ; 0->1, 1->2, 2->3 732 00000394 C3 retn 733 V_4: 734 00000395 80FC0E cmp ah, 0Eh ; FAT16 LBA partition 735 00000398 75E8 jne short V_1 736 ;mov al, 2 737 V_5: 738 0000039A C3 retn 739 740 ; ---------------------------------------------------------------------------- 741 ; initialized data 742 ; ---------------------------------------------------------------------------- 743 744 0000039B 90 align 2 745 746 retrodosv5bs: 747 0000039C [A007] dw RD5_FAT16_hd_bs 748 0000039E 0000 dw 0 749 750 ;volume_id: 751 ; dd 0 752 753 ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 754 ; FAT boot sector code 755 ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 756 757 ; 03/05/2024 758 RD5_FAT32_hd_bs: 759 000003A0 incbin 'RD5HDBS3.BIN' ; 29/01/2026 760 RD5_FAT16_hd_bs: 761 000007A0 incbin 'RD5HDBS2.BIN' ; 20/04/2024 762 RD5_FAT12_hd_bs: 763 000009A0 incbin 'RD5HDBS1.BIN' ; 20/04/2024 764 765 ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 766 ; messages 767 ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 768 769 00000BA0 00 drv: db 0 770 771 ;sectors: db 0 772 ;heads : db 0 773 ;cylinders: dw 0 774 775 00000BA1 00 _dh: db 0 776 00000BA2 0000 _cx: dw 0 777 778 RD5_Welcome: 779 00000BA4 0D0A db 0Dh, 0Ah 780 00000BA6 526574726F20444F53- db 'Retro DOS v5.0 Hard Disk Boot Sector Update Utility ' 780 00000BAF 2076352E3020486172- 780 00000BB8 64204469736B20426F- 780 00000BC1 6F7420536563746F72- 780 00000BCA 205570646174652055- 780 00000BD3 74696C69747920 781 00000BDA 0D0A db 0Dh, 0Ah 782 00000BDC 52444844424F4F5420- db 'RDHDBOOT v5.0.260129 (c) Erdogan TAN 2018-2026' 782 00000BE5 76352E302E32363031- 782 00000BEE 323920202863292045- 782 00000BF7 72646F67616E205441- 782 00000C00 4E20323031382D3230- 782 00000C09 3236 783 00000C0B 0D0A db 0Dh,0Ah 784 00000C0D 0D0A db 0Dh,0Ah 785 00000C0F 55736167653A207235- db 'Usage: r5hdboot ' 785 00000C18 6864626F6F74203C64- 785 00000C21 726976653E20 786 00000C27 0D0A0D0A db 0Dh,0Ah, 0Dh, 0Ah 787 00000C2B 4472697665206E616D- db 'Drive names: ' 787 00000C34 65733A20 788 00000C38 0D0A db 0Dh, 0Ah 789 00000C3A 20686430206F722043- db ' hd0 or C: ..for primary dos partition on 1st disk ' 789 00000C43 3A202E2E666F722070- 789 00000C4C 72696D61727920646F- 789 00000C55 732070617274697469- 789 00000C5E 6F6E206F6E20317374- 789 00000C67 206469736B20 790 00000C6D 0D0A db 0Dh, 0Ah 791 00000C6F 20686431206F722044- db ' hd1 or D: ..for primary dos partition on 2nd disk ' 791 00000C78 3A202E2E666F722070- 791 00000C81 72696D61727920646F- 791 00000C8A 732070617274697469- 791 00000C93 6F6E206F6E20326E64- 791 00000C9C 206469736B20 792 00000CA2 0D0A db 0Dh, 0Ah 793 00000CA4 206864322020202020- db ' hd2 ..for primary dos partition on 3rd disk ' 793 00000CAD 20202E2E666F722070- 793 00000CB6 72696D61727920646F- 793 00000CBF 732070617274697469- 793 00000CC8 6F6E206F6E20337264- 793 00000CD1 206469736B20 794 00000CD7 0D0A db 0Dh, 0Ah 795 00000CD9 206864332020202020- db ' hd3 ..for primary dos partition on 4th disk ' 795 00000CE2 20202E2E666F722070- 795 00000CEB 72696D61727920646F- 795 00000CF4 732070617274697469- 795 00000CFD 6F6E206F6E20347468- 795 00000D06 206469736B20 796 00000D0C 0D0A00 db 0Dh, 0Ah, 0 797 798 00000D0F 30332F30352F323032- db '03/05/2024' 798 00000D18 34 799 00000D19 00 db 0 800 801 RD5_Do_you_want: 802 00000D1A 0D0A db 0Dh, 0Ah 803 00000D1C 5741524E494E472021- db "WARNING ! ", 0Dh, 0Ah 803 00000D25 200D0A 804 00000D28 28496620796F752073- db "(If you say 'Yes', MSDOS or WINDOWS will not be bootable on this disk !) " 804 00000D31 61792027596573272C- 804 00000D3A 204D53444F53206F72- 804 00000D43 2057494E444F575320- 804 00000D4C 77696C6C206E6F7420- 804 00000D55 626520626F6F746162- 804 00000D5E 6C65206F6E20746869- 804 00000D67 73206469736B202129- 804 00000D70 20 805 00000D71 0D0A0D0A db 0Dh, 0Ah, 0Dh, 0Ah 806 ;db "Do you want to update boot sector to TRDOS 386 v2 format ? (Y/N) " 807 ; 03/05/2024 808 00000D75 446F20796F75207761- db "Do you want to update boot sector to Retro DOS v5 format ? (Y/N) " 808 00000D7E 6E7420746F20757064- 808 00000D87 61746520626F6F7420- 808 00000D90 736563746F7220746F- 808 00000D99 20526574726F20444F- 808 00000DA2 5320763520666F726D- 808 00000DAB 6174203F2028592F4E- 808 00000DB4 2920 809 00000DB6 00 db 0 810 811 _yes_str: 812 00000DB7 59455320 db 'YES ' 813 00000DBB 0D0A00 db 0Dh, 0Ah, 0 814 _no_str: 815 00000DBE 4E4F20 db 'NO ' 816 00000DC1 0D0A00 db 0Dh, 0Ah, 0 817 818 RD5_PressKeyWhenReady: 819 00000DC4 0D0A db 0Dh, 0Ah 820 00000DC6 507265737320456E74- db 'Press Enter to write boot sector on disk hd' 820 00000DCF 657220746F20777269- 820 00000DD8 746520626F6F742073- 820 00000DE1 6563746F72206F6E20- 820 00000DEA 6469736B206864 821 RD5_Drive: 822 00000DF1 3F2E2000 db '?. ', 0 823 824 RD5_disk_WrittenSuccesfully: 825 00000DF5 0D0A db 0Dh, 0Ah 826 ;db 'Boot sector successfully updated to TRDOS 386 v2 format...' 827 ; 03/05/2024 828 00000DF7 426F6F742073656374- db 'Boot sector successfully updated to Retro DOS v5 format...' 828 00000E00 6F7220737563636573- 828 00000E09 7366756C6C79207570- 828 00000E12 646174656420746F20- 828 00000E1B 526574726F20444F53- 828 00000E24 20763520666F726D61- 828 00000E2D 742E2E2E 829 RD5_CRLF: 830 00000E31 0D0A00 db 0Dh, 0Ah, 0 831 832 RD5_disk_NotReadyOrError: 833 00000E34 0D0A db 0Dh, 0Ah 834 00000E36 4469736B206572726F- db 'Disk error or drive not ready ! ' 834 00000E3F 72206F722064726976- 834 00000E48 65206E6F7420726561- 834 00000E51 6479202120 835 00000E56 54727920616761696E- zbyte: db 'Try again ? (Y/N) ' 835 00000E5F 203F2028592F4E2920 836 00000E68 00 db 0 837 838 RD5_invalid_bootsector: 839 00000E69 0D0A db 0Dh, 0Ah 840 00000E6B 496E76616C69642062- db 'Invalid boot sector (not a valid FAT' 840 00000E74 6F6F7420736563746F- 840 00000E7D 7220286E6F74206120- 840 00000E86 76616C696420464154 841 fattype_str: 842 00000E8F 313620667320646973- db '16 fs disk) ! ' 842 00000E98 6B29202120 843 00000E9D 00 db 0 844 845 RD5_fatp_notfound: 846 00000E9E 0D0A db 0Dh, 0Ah 847 00000EA0 4D425220646F657320- db 'MBR does not contain a primary DOS partition ! ' 847 00000EA9 6E6F7420636F6E7461- 847 00000EB2 696E2061207072696D- 847 00000EBB 61727920444F532070- 847 00000EC4 6172746974696F6E20- 847 00000ECD 2120 848 fattype: 849 00000ECF 00 db 0 850 RetryCount: 851 00000ED0 04 db 4 852 853 00000ED1 00 lba: db 0 854 855 00000ED2 90 align 4 856 857 CHS_limit: 858 00000ED4 0000 dw 0 859 ;dw 0 860 861 00000ED6 A101 sign: dw 417 862 863 ; ---------------------------------------------------------------------------- 864 ; uninitialized data 865 ; ---------------------------------------------------------------------------- 866 867 bss_start: 868 869 ABSOLUTE bss_start 870 871 alignb 4 872 873 00000ED8 ?? sectors: resb 1 874 00000ED9 ?? heads: resb 1 875 00000EDA ???? cylinders: resw 1 876 877 00000EDC ???????? dosp_start: resd 1 878 00000EE0 ???????? dosp_size: resd 1 879 880 MBR: 881 bootsector: 882 00000EE4 resb 512 883 884 end_bss: