-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.asm
84 lines (65 loc) · 1.49 KB
/
utils.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
73
74
75
76
77
78
79
80
81
82
83
84
.8086
; I'm guessing because WASM is hard to find example code for in real mode
_TEXT SEGMENT 'CODE'
ASSUME CS:_TEXT
; Returns the number of HDDs seen by the system
PUBLIC _get_disk_geometry
; get_disk_geometry(int disk_id, int *cylinders, int *heads, int *sectors, int *num_of_disks)
_get_disk_geometry PROC NEAR
_disk_id$ = 4
_cylinders$ = 6
_heads$ = 8
_sectors$ = 10
_num_of_disks$ = 12
push bp
mov bp, sp
; Setup for int 13h call
; Start with first fixed disk, we'll work from there
push es
xor ax, ax
xor dx, dx
mov ah, 08h
mov dx, [bp+_disk_id$]
mov es, ax
xor di, 0h
int 13h
; if an error was returned in CF
jc error1
; Return number of heads
mov bx, WORD PTR [bp+_heads$]
mov WORD PTR [bx], 0
mov BYTE PTR [bx], dh
; Return number of disks
mov bx, WORD PTR [bp+_num_of_disks$]
mov WORD PTR [bx], 0
mov BYTE PTR [bx], dl
; Cylinders and sectors share cx, get each value and seperate them out
push cx ; make a copy
and cx, 3fh
mov bx, WORD PTR [bp+_sectors$]
mov WORD PTR [bx], 0
mov BYTE PTR [bx], cl
pop cx
; Now get cylinders
and cl, 0c0h
shr cl, 1
shr cl, 1
shr cl, 1
shr cl, 1
shr cl, 1
shr cl, 1
xchg ch, cl
mov bx, WORD PTR [bp+_cylinders$]
mov WORD PTR[bx], cx
pop es
pop bp
mov ax, 0
ret
error1:
pop es
pop bp
mov ax, -1
ret
_get_disk_geometry ENDP
_TEXT ENDS
END