-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisk.asm
More file actions
78 lines (64 loc) · 1015 Bytes
/
disk.asm
File metadata and controls
78 lines (64 loc) · 1015 Bytes
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
; Disk I/O routines
; Convert LBA to CHS
; Input: AX = LBA
; Output: CX, DH = CHS values
lba_to_chs:
push ax
push dx
xor dx, dx
div word [bdb_sectors_per_track]
inc dx
mov cx, dx
xor dx, dx
div word [bdb_heads]
mov dh, dl
mov ch, al
shl ah, 6
or cl, ah
pop ax
mov dl, al
pop ax
ret
; Read sectors from disk
; Input: AX = LBA, CL = sector count, DL = drive, ES:BX = buffer
disk_read:
push ax
push bx
push cx
push dx
push di
call lba_to_chs
mov ah, 0x02
mov di, 3
.retry:
stc
int 0x13
jnc .done
call disk_reset
dec di
test di, di
jnz .retry
.failed:
mov si, disk_error_msg
call print
jmp halt
.done:
pop di
pop dx
pop cx
pop bx
pop ax
ret
disk_reset:
pusha
mov ah, 0
stc
int 0x13
jc .failed
popa
ret
.failed:
mov si, disk_error_msg
call print
jmp halt
disk_error_msg: db "Disk error!", 0x0D, 0x0A, 0