forked from vonj/snippets.org
-
Notifications
You must be signed in to change notification settings - Fork 1
/
absdisk.asm
72 lines (66 loc) · 2.08 KB
/
absdisk.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
page 55, 132
;
; ABSDISK.ASM
;
; Originally published as part of The MicroFirm Function Library
; This version released to the public domain by the author, Bob Stout
;
; Requires MASM 5.1 or later or equivalent
;
; Assemble with: MASM /Mx /z ...
; TASM /jMASM /mx /z ...
;
% .MODEL memodel,C ;Add model support via
;command line macro,
;e.g. MASM /Dmemodel=LARGE ...
extrn _osmajor:BYTE
public absdisk
.DATA
start dw ?
fill dw 0
number dw ?
buf dw ?,?
.CODE
absdisk PROC USES SI DI BP, func:BYTE, drive:WORD, num_sec:WORD, start_sec:WORD, buffer:PTR
mov AX,drive ;Get drive number in AL
mov AH,_osmajor ;Load OS version in AH
mov CX,num_sec ;Set up regs for DOS 3 call
mov DX,start_sec
IF @DataSize
push DS ;Save DS in L & C models
lds BX,buffer
ELSE
mov BX,buffer
ENDIF
cmp AH,4 ;DOS 4+?
jb doint ;No, skip it
mov start,DX ;Yes, fill in DCB structure
mov number,CX
mov buf,BX
mov buf+2,DS
mov cx,-1
IF @DataSize ;Point to DCB
mov BX,@Data
mov DS,BX
ENDIF
mov bx,OFFSET start
doint: mov AH,func ;Read or Write?
cmp AH,25h
jne skip_1
int 25h ;Read sector
jmp skip_3
skip_1: cmp AH,26h
jne skip_2
int 26h ;Write sector
jmp skip_3
skip_2: stc ;Invalid command
mov AX,-1
skip_3: jc bye ;Error?
mov AX,0 ;No, return SUCCESS
bye: add SP,2 ;Int 25h leave the flags on the stack
IF @DataSize
pop DS ;Restore DS in L & C models
ENDIF
ret
absdisk ENDP
end