[392] | 1 | ; Project name : XTIDE Universal BIOS
|
---|
| 2 | ; Description : Reading and jumping to boot sector.
|
---|
| 3 |
|
---|
| 4 | ;
|
---|
[505] | 5 | ; XTIDE Universal BIOS and Associated Tools
|
---|
[630] | 6 | ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2024 by XTIDE Universal BIOS Team.
|
---|
[392] | 7 | ;
|
---|
| 8 | ; This program is free software; you can redistribute it and/or modify
|
---|
| 9 | ; it under the terms of the GNU General Public License as published by
|
---|
| 10 | ; the Free Software Foundation; either version 2 of the License, or
|
---|
| 11 | ; (at your option) any later version.
|
---|
[505] | 12 | ;
|
---|
[392] | 13 | ; This program is distributed in the hope that it will be useful,
|
---|
| 14 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 15 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 16 | ; GNU General Public License for more details.
|
---|
[505] | 17 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
---|
| 18 | ;
|
---|
[392] | 19 |
|
---|
| 20 | ; Section containing code
|
---|
| 21 | SECTION .text
|
---|
| 22 |
|
---|
| 23 | ;--------------------------------------------------------------------
|
---|
[505] | 24 | ; BootSector_TryToLoadFromDriveDL_AndBoot
|
---|
[392] | 25 | ; Parameters:
|
---|
| 26 | ; DL: Drive to boot from (translated, 00h or 80h)
|
---|
| 27 | ; DS: RAMVARS segment
|
---|
| 28 | ; Returns:
|
---|
| 29 | ; ES:BX: Ptr to boot sector (if successful)
|
---|
[630] | 30 | ; CF: Cleared if boot sector loaded successfully
|
---|
| 31 | ; (only matters when jumping to
|
---|
| 32 | ; Int19h_JumpToBootSectorInESBXOrRomBoot)
|
---|
[392] | 33 | ; Corrupts registers:
|
---|
[630] | 34 | ; AX, CX, DH, SI, DI
|
---|
[392] | 35 | ;--------------------------------------------------------------------
|
---|
[492] | 36 | BootSector_TryToLoadFromDriveDL_AndBoot:
|
---|
[392] | 37 | call DetectPrint_TryToBootFromDL
|
---|
[595] | 38 | call BootSector_LoadFirstSectorFromDriveDL
|
---|
[630] | 39 | inc dx ; Determine if hard drive or floppy drive without changing the CF
|
---|
| 40 | dec dl
|
---|
[521] | 41 | jnc SHORT .FirstSectorLoadedToESBX
|
---|
| 42 |
|
---|
| 43 | ; Do not display timeout error (80h) for floppy drives since
|
---|
| 44 | ; it most likely mean no diskette in drive. This way we do not
|
---|
| 45 | ; display error code every time user intends to boot from hard disk
|
---|
| 46 | ; when A then C boot order is used.
|
---|
[630] | 47 | js SHORT .PrintFailedToLoadErrorCode ; Hard Drive
|
---|
[521] | 48 | cmp ah, RET_HD_TIMEOUT
|
---|
[630] | 49 | je SHORT BootSector_LoadFirstSectorFromDriveDL.Return
|
---|
[521] | 50 | cmp ah, RET_HD_NOMEDIA
|
---|
[630] | 51 | je SHORT BootSector_LoadFirstSectorFromDriveDL.Return
|
---|
[521] | 52 | .PrintFailedToLoadErrorCode:
|
---|
[630] | 53 | jmp DetectPrint_FailedToLoadFirstSector
|
---|
[392] | 54 |
|
---|
[521] | 55 | .FirstSectorLoadedToESBX:
|
---|
[630] | 56 | jns SHORT Int19h_JumpToBootSectorInESBXOrRomBoot ; Don't check for boot sector signature for floppy booter games
|
---|
| 57 | cmp WORD [es:bx+510], 0AA55h ; Valid boot sector?
|
---|
| 58 | je SHORT Int19h_JumpToBootSectorInESBXOrRomBoot ; With CF cleared
|
---|
[392] | 59 | mov si, g_szBootSectorNotFound
|
---|
[630] | 60 | jmp DetectPrint_NullTerminatedStringFromCSSI
|
---|
[392] | 61 |
|
---|
[492] | 62 |
|
---|
[392] | 63 | ;--------------------------------------------------------------------
|
---|
[595] | 64 | ; BootSector_LoadFirstSectorFromDriveDL
|
---|
[392] | 65 | ; Parameters:
|
---|
| 66 | ; DL: Drive to boot from (translated, 00h or 80h)
|
---|
| 67 | ; Returns:
|
---|
| 68 | ; AH: INT 13h error code
|
---|
| 69 | ; ES:BX: Ptr to boot sector (if successful)
|
---|
| 70 | ; CF: Cleared if read successful
|
---|
| 71 | ; Set if any error
|
---|
| 72 | ; Corrupts registers:
|
---|
| 73 | ; AL, CX, DH, DI
|
---|
| 74 | ;--------------------------------------------------------------------
|
---|
[595] | 75 | BootSector_LoadFirstSectorFromDriveDL:
|
---|
[392] | 76 | LOAD_BDA_SEGMENT_TO es, bx ; ES:BX now points to...
|
---|
| 77 | mov bx, BOOTVARS.rgbBootSect ; ...boot sector location
|
---|
| 78 | mov di, BOOT_READ_RETRY_TIMES ; Initialize retry counter
|
---|
| 79 |
|
---|
| 80 | .ReadRetryLoop:
|
---|
[505] | 81 | mov ax, 0201h ; Read 1 sector
|
---|
| 82 | mov cx, 1 ; Cylinder 0, Sector 1
|
---|
| 83 | xor dh, dh ; Head 0
|
---|
| 84 | int BIOS_DISK_INTERRUPT_13h
|
---|
| 85 | jc SHORT .FailedToLoadFirstSector
|
---|
| 86 | .Return:
|
---|
| 87 | ret
|
---|
| 88 |
|
---|
| 89 | .FailedToLoadFirstSector:
|
---|
[428] | 90 | dec di ; Decrement retry counter (preserve CF)
|
---|
| 91 | jz SHORT .Return ; Loop while retries left
|
---|
[392] | 92 |
|
---|
[428] | 93 | ; Reset drive and retry
|
---|
[505] | 94 | xor ax, ax ; AH=00h, Disk Controller Reset
|
---|
[392] | 95 | test dl, dl ; Floppy drive?
|
---|
[505] | 96 | eCMOVS ah, RESET_HARD_DISK ; AH=0Dh, Reset Hard Disk (Alternate reset)
|
---|
[392] | 97 | int BIOS_DISK_INTERRUPT_13h
|
---|
[428] | 98 | jmp SHORT .ReadRetryLoop
|
---|
[392] | 99 |
|
---|