;; ERRMSG.ASM--two procedures for checking for errors on DOS commands. ;; ;; CCheck checks for CFlag set and if so, prints error whose ;; number is is in ax. Not all messages available ;; (Should contain those for I/O, EXEC, and Mem Alloc) ;; _Exits with code 1 if error ;; WCheck Used for _Write command. First does CCheck and if ;; that returns, compares ax = number of bytes written ;; to cx = number of bytes requested to write and ;; prints message and _Exits with code 2 ;; ;; Library source text from "Assembly Language for the IBM PC Family" by ;; William B. Jones, (c) Copyright 1992, 1997, Scott/Jones Inc. ;; .MODEL SMALL INCLUDE PCMAC.INC .DATA ;*** first, as list of messages: Inval DB 'Invalid function number$' NotFnd DB 'File not found$' Path DB 'Path not found$' TooMany DB 'Too many open files$' Access DB 'Access denied$' Handle DB 'Invalid handle$' Corrupt DB 'Memory control blocks destroyed$' NoMem DB 'Insufficient memory$' Block DB 'Invalid memory block address$' Envir DB 'Invalid environment$' Format DB 'Invalid format$' ACode DB 'Invalid access code$' Drive DB 'Invalid drive specified$' Device DB 'Not same device$' Files DB 'No more files$' Unk DB 'Unknown error number$' ;*** Then, an array Msg of pointers such that Msg[n] = offset of ;*** message for error n Msg DW ?, Inval, NotFnd, Path, TooMany, Access, Handle, Corrupt DW NoMem, Block, Envir, Format, ACode, Unk, Unk, Drive, Unk DW Device, Files MSGLIM EQU ($ - Msg - 2) /2 ;*** Message for write count error WrtCnt DB 'Different number of bytes written than requested$' Err1 DB '*** DOS call ERROR at $' Err2 DB 'h *** $' CRLF DB 13, 10, '$' .CODE PUBLIC CCheck, WCheck EXTRN PutHex : NEAR CCheck PROC jc DoMessage ret DoMessage: mov bx, @data mov ds, bx ; Just in case mov bx, ax _PutStr Err1 pop ax ; Return address is location of error call PutHex ; (Don't need it any more) _PutStr Err2 cmp bx, 1 jl DispUnk ; Just in case cmp bx, MSGLIM jg DispUnk shl bx, 1 add bx, OFFSET Msg ; bx --> appropriate error message mov dx, [bx] mov ah, 09h int 21h Finish: _PutStr CRLF _Exit 1 DispUnk: _PutStr Unk jmp Finish CCheck ENDP WCheck PROC jnc NoDOSErr jmp CCheck ; Don't destroy original return address! NoDOSErr: cmp ax, cx jne WErr ret WErr: _PutStr Err1, @data pop ax call PutHex _PutStr Err2 _PutStr WrtCnt _PutStr CRLF _Exit 2 WCheck ENDP END