Beruflich Dokumente
Kultur Dokumente
page 60,132
;---------------------------------------------------------------------------
;FORMAT.ASM DATE: 12-15-91 © 1991 Pierre R. Desloover for Ataspec Software
;PURPOSE: Demonstrate successful MISC. MS-DOS 5.0 IOCTL Int 21H, 440DH
; functions (CL=40H, 42H, 47H, 60H, 67H) in order to FORMAT 1
; TRACK of a 1.2Mb diskette.
;NOTES:
;Current test set up for 1.2Mb drive and disk in Drive A: or B:. To
;accommodate other drive and/or media types, this test code needs to be
;modified slightly. Also, Int 21h, 440dH, FCN 42H (FORMAT TRK & Verify)
;is hard coded to format the first TRACK: HEAD #0, CYLINDER #0.
;
;1. MS-DOS version 4.x and greater.
;2. Command line input arg is operand logical drive LETTER and can be
;Drive A: or B: ONLY in order to protect from accidently formatting hard
;drives C:, D:, etc. Example: FORMAT A: <CR>. (Formats media in Drive A:)
;3. MASM 5.0+, LINK to program .EXE image.
;---------------------------------------------------------------------------
DOSSEG
.MODEL SMALL
.DATA
;*** Do not declare any vars from HERE end _BPB to TrkLayOut structure below
TRACKINF MACRO
N=1
REPT SECS_TRK
DW N
DW BYTES_SECT
N=N+1
ENDM
ENDM
;Invoke trackinfo macro to build rest of fields for track layout structure.
;(Format.exe allocates and initializes dynamically.)
TRACKINF <>
.CODE
START_TEST:
mov ax,@DATA
mov ds,ax ;Note: it is assumed that DS is not changed
;for the remainder of this test code.
parse_cmdtail:
;Perform simple parsing of command tail
mov al,es:[82h]
cmp al,'A'
jb usage_error
cmp al,'Z'
jbe have_upper
cmp al,'a'
jb usage_error
cmp al,'z'
jbe have_lower
usage_error:
mov dx,offset usage_msg
jmp term_test
have_lower:
;convert to upper
and al,0dfh
have_upper:
;make 1 based logical drive number
sub al,'@'
set_drvno:
mov [drive],al
;safety check in this test program so don't format drive C:, D:, etc.
cmp al,3
jb _OK_proceed ;Drive A: or B: only
mov dx,offset wrong_drive
jmp term_test
;END PARSE COMMAND TAIL
_OK_proceed:
;Issue function 60H (Get Device Parameters) to use with function 40H
;(Set Device Parameters) which is necessary prior to function 42H.
mov bx,offset PARMBLOCK
mov byte ptr [bx],00000000B ;init to zero ;this is what FORMAT does
_issue_40h:
;We will assume that the Device parameter block returned via CL=60H
;contains valid info although some info may need to be altered to
;match the actual MEDIA in target drive before CL=40H.
mov bx,offset PARMBLOCK
mov byte ptr [bx],00000101B ;set bit 2=1 and bit 0=1 ;FORMAT does this
mov byte ptr [bx][6],00000000B ;set Media type, bit 0=0 (DD,1.2Mb)
;;;mov byte ptr [bx][6],00000001B ;set Media type, bit 0=1 (DD,360kb)
_issue_67h:
;Accordying to FORMAT.EXE, need to get, set Disk Access flag for HARD only.
;(documented in Advanced MS-DOS Programming)
;Get disk access flag before set disk access flag so can save and restore.
COMMENT | Non functional for floppy (removable media) test
mov bx,offset ACCESSBLOCK
mov byte ptr [bx],00000000B ;special, must be zero
;error happened
mov dx,offset error_67h
;convert error# in AL to one's digit ascii for display
add al,48
mov bx,dx
mov byte ptr [bx][37],al
jmp term_test
_issue_47h:
;first save returned disk access flag
mov bx,offset ACCESSBLOCK
mov al,byte ptr [bx][1]
mov [saved_access],al
;error happened
mov dx,offset error_47h
;convert error# in AL to one's digit ascii for display
add al,48
mov bx,dx
mov byte ptr [bx][37],al
jmp short term_test
| ;;;END COMMENT
_issue_42h:
;(MS-DOS 4.0 or greater) first issue with special functions=1 so can see
;if specified number of tracks and cylinders are supported by BIOS.
;(documented in Advanced MS-DOS Programming)
mov bx,offset FVBLOCK
mov byte ptr [bx],00000001B ;special, 1= format status call
mov bl,[drive] ;logical drive into BL
mov ch,8 ;disk category
mov cl,42h ;Format and Verify Track
mov dx,offset FVBLOCK ;DS:DX
mov ax,440dh
int 21h
jc _error_42h
;test returned status
mov bx,offset FVBLOCK
cmp byte ptr [bx],0 ;special functions?, 0= supported
jz format_track
;Format status says not supported or other error (consult Advanced MS-DOS
;Programming for exact meaning of values).
mov dx,offset not_supp
;convert error status# in structure to one's digit ascii for display
mov al,byte ptr [bx] ;get error status#
add al,48
mov bx,dx
mov byte ptr [bx][55],al
jmp short term_test
format_track:
;attempt to format one track
mov bx,offset FVBLOCK
mov byte ptr [bx],0 ;special, must be zero (FORMAT.exe)
no_error:
mov dx,offset no_errors
jmp short term_test
_error_42h:
;IMPORTANT TO GET EXTENDED ERROR HERE FOR EXACT EXPLANATION OF
ERROR
;AND DO APPROPRIATE ACTIONS HERE. (For example: FORMAT.exe marks
whole
;TRACK BAD in FAT if "sector not found" (or other HW errors) occurs here
;and then proceeds on to attempt to format next TRACK.)
;In this test program, all we do is report the Extended Error Value,
;and abort attempt to format the track.
mov ah,59h
xor bx,bx
int 21h
term_test:
;display message on exit, DX has ptr to text string
mov ah,9
int 21h
END START