Bug when using the int 21h to read files

376 views Asked by At

I'm trying to use the int 21h command to read files and carry flag CF turns on and AX = 6 which means my file handler is invalid.
Any chance you guys know why it's not working. Here are my procedures:

proc openFile
    call xorAll
    mov ah,0Fh
    mov al,0
    mov dx, offset fileName
    int 21h
    jc error                    
    mov fileHandler, ax
    ret
endp openFile

proc closeFile
    call xorAll
    mov ah,10h
    mov bx, fileHandler
    int 21h
    ret
endp closeFile 

proc failOpenFile 
    mov ah,09
    int 21h
    ret
endp failOpenFile

proc xorAll
    xor ax,ax
    xor bx,bx
    xor cx,cx
    xor dx,dx
    ret
endp xorAll 

proc waitForClick
    mov ah,0
    int 16h
    ret
endp waitForClick

proc readBytes
    call xorAll
    mov ah,3Fh
    mov bx,fileHandler
    mov cl,bytesToRead 
    mov dx,offset readInfo
    int 21h 
    jc error
    ret
endp readBytes

I just don't understand why it's not working. FYI fileHandler is in a dw.

1

There are 1 answers

0
Tommylee2k On BEST ANSWER

DOS functions 0Fh and 10h use FCBs (file control blocks, old relicts from CP/M-times). These are outdated.

You should use 3Dh (open file) and 3Eh (close file) instead, those use handles.