0

我有一个关于如何使用汇编语言检查软盘驱动器是否可用的问题。我检查了 RAM 内存是否足够,但我不知道如何检查软驱是否可用。我试过这个:CMP AH,0 JNE disk_error,但是当我在检查 RAM 之后放这个时,什么也没有发生。当我输入continueToLoad :CMP AX,0 JNE fatal_disk_error时,它工作正常,但加载栏后出现错误消息。Loader 我需要在加载栏之前显示该错误消息。 错误

main:
    MOV DS,AX 
    PUSH CS
    POP DS
    MOV AH,0x00 
    MOV AL,0x03
    INT 0x10    
    CALL ClearScreen

    MOV BL,1010b        
    MOV BP,StrLoadKernel    
    MOV CX,length   
    MOV DH,13       
    MOV DL,30           
    CALL PrintString

    MOV BL,1010b        
    MOV BP,StrReboot    
    MOV CX,length2      
    MOV DH,14       
    MOV DL,30           
    CALL PrintString

readKeys:
    CALL PressKey
    CMP AL,00011011b ; ESC binary code
    JE Reboot
    CMP AL,00001101b ; ENTER binary code
        
    CALL ClearScreen
        
    MOV BL,1010b        
    MOV BP,StrLoading   
    MOV CX,length4      
    MOV DH,14       
    MOV DL,35           
    CALL PrintString    
      
    JE LoadKernel
    loop readKeys

    jmp $

LoadKernel:
    ;CHECK IF RAM MEMORY > 64MB
    MOV AH,0x88
    INT 0x15            
    CLC  
    CMP AX,0xFA00  
    MOV BL,0011b                         
    JNC printLoader
     CALL ClearScreen 
        MOV BL,1100b        
        MOV BP,StrErrorRAM  
        MOV CX,length3      
        MOV DH,13       
        MOV DL,25               
        CALL PrintString  
        
        MOV BL,1100b        
        MOV BP,press_key    
        MOV CX,length6      
        MOV DH,14       
        MOV DL,25                  
        CALL PrintString
        
        CALL PressKey
        CALL Reboot     
      JMP readKeys 
    JMP printLoader 

changeToBlue: 
MOV BL,1001b    

JMP printLoader

changeToGreen:
MOV BL,1010b    
    
JMP printLoader

changeToRed:
MOV BL,0100b    
    
JMP printLoader

continueToLoad: 
        MOV AX,0
        MOV DL,0
        INT 0x13         
        
    ;load kernel
        MOV AX,kernel 
        MOV ES,AX
        MOV BX,0        
        
        MOV AH,02h 
        MOV AL,01h 
        MOV CH,0h  
        MOV CL,02  
        MOV DH,0   
        MOV DL,0   
        INT 0x13   
           
        CMP AH, 0                     
        jne fatal_disk_error

jmp kernel:0

RET

CALL printLoader

printLoader:   
        MOV BP,symbol       ; stringul care dorim sa il afisam
        MOV CX,symbolLength ; marimea stringului
        MOV DH,16       ; randul (x)
        MOV DL,[count]      ; coloana (y)
        
        CALL PrintString
        
        INC DL
        INC DL
        INC DL
        MOV [count],DL
        
        CALL wait2sec
        
        MOV AL,[pas]
        INC AL
        MOV [pas],AL

        CMP AL,3
        JE changeToBlue
    
        CMP AL,6
        JE changeToGreen

        CMP AL,9
        JE changeToRed 
                
        CMP AL,10
        JE continueToLoad

    loop printLoader

ClearScreen:
    MOV AX,0600h 
    MOV CX,0000h
    MOV BH,0Ah
    MOV DX,1850h
    int 0x10    
RET

PressKey:
    ;read a key
    MOV AH,0
    INT 0x16
RET

PrintString:
    MOV AH, 0x13
    MOV AL,0
    MOV BH,0    
    INT 0x10
    ; hide cursor
    mov AH,0x01
    MOV CX,2607h
    INT 0x10
RET

Reboot:
    db 0x0ea
    dw 0x0000
    dw 0xffff
RET

wait2sec:
    MOV AH,0x86
    MOV CX,0008h
    MOV DX,6480h
    int 0x15
RET

fatal_disk_error:
    CALL ClearScreen 
    MOV AX,0  
    MOV ES,AX 
    
    MOV BL,1100b        
    MOV BP,disk_error   
    MOV CX,length5      
    MOV DH,16       
    MOV DL,30
    call PrintString
    CALL wait2sec
    CALL PressKey
    CMP AL,00011011b ; ESC binary code
    jmp Reboot
RET

StrLoadKernel: db "Press ENTER to load the KERNEL "
length equ $-StrLoadKernel

StrReboot: db "Press ESC to restart "
length2 equ $-StrReboot
                                                        
StrErrorRAM: db "Loading cancelled! ERROR : RAM < 64mb."
length3 equ $-StrErrorRAM    

StrLoading: db "Loading... "
length4 equ $-StrLoading  

disk_error: db "Floppy error! Press any key... "
length5 equ $-disk_error   

press_key: db "Press any key to restart!" 
length6 equ $-press_key

kernel equ 1000h

symbol: db 219 
symbolLength equ $-symbol

count db 25

pas  db 0

 510-($-$$) db 0

DW 0xAA55
4

3 回答 3

3

要确定您是否有软盘驱动器,请使用GetEquipmentStatus BIOS 功能。

int 11h

它在 AX 寄存器中返回一个值。第 6 位和第 7 位一起告诉您有多少软盘驱动器连接到系统。

00 = 1 drive
01 = 2 drives
10 = 3 drives
11 = 4 drives

如果位 0 为 ON ,则仅使用位 6 和 7

另一种方法是通过 BIOS 函数 01h 看能否成功获取软驱的状态int 13h

mov dl, 0
mov ah, 01h
int 13h
cmp ah, 0
jne disk_error

一定要查阅DiskControllerStatusBits的完整列表,因为这cmp ah, 0可能会被证明有点简单。

于 2015-10-18T15:22:01.900 回答
2

In addition to the GetEquipmentStatus BIOS function mentionned by @user3144770 there's another BIOS function GetDiskType you can use.

mov dl, 0
mov ah, 15h
int 13h

If the carry flag is set there was an error. (Status in AH) If the carry flag is clear you get a value in AH that informs you about the drive specified in the DL argument.

AH=0 no drive
AH=1 floppy without change-line support
AH=2 floppy with change-line support
AH=3 hard disk
于 2015-10-22T10:38:27.703 回答
2

您不需要知道是否存在软盘驱动器。

您只需要知道设备 0(或者可能是 BIOS 告诉您从中引导的设备)是否像软盘驱动器一样运行;如果该设备恰好是(例如)USB 闪存或模拟软盘驱动器的 CD/DVD,那很好。为此,请使用int 0x13,ah = 0x08,获取驱动器参数并检查结果。

如果您确实需要知道是否存在软盘驱动器;那么整个世界都是痛苦的。BIOS 可能配置错误(并且其 CMOS 错误),可能存在 BIOS 不知道和/或甚至不支持的 USB 软盘驱动器等。

于 2015-10-17T18:48:30.747 回答