summaryrefslogtreecommitdiff
path: root/drive/drive.ha
blob: 42cef4381739f03e9aaf09654593e2dd806b07cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use bios;
use bios::drive;

fn lba_to_chs(lba: u16) (u16, u16, u16) = {
	let temp = lba / bios::drive::drive_spt;
	let sector = (lba % bios::drive::drive_spt) + 1;
	let head = temp % bios::drive::drive_heads;
	let cylinder = temp / bios::drive::drive_heads;
	
	return (cylinder, head, sector);
};

export fn read(sector: u16, dest: uintptr) void = {
	let chs = lba_to_chs(sector);

	bios::regs.eax = 1 | 0x2 << 8;
	bios::regs.ebx = ws;
	bios::regs.ecx = chs.2 | chs.0 << 8;
	bios::regs.edx = bios::drive::drive_no | chs.1 << 8;
};