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
|
/// BIOS starts with video mode 0h.
/// * 80x25 text mode
/// * 16 colors (4bit)
/// http://www.ctyme.com/intr/rb-0069.htm
pub const COLS = 80;
pub const ROWS = 25;
/// BIOS CALL - video teletype output.
/// http://www.ctyme.com/intr/rb-0106.htm
pub fn putc(c: u8) void {
// ah=0eh (call nr)
// al=c (ascii char to write)
const ax = (@as(u16, 0xe) << 8) | c;
_ = asm volatile (
\\int $0x10
: // No outputs.
: [a] "{ax}" (ax), // BIOS call number + char to write.
: "cc"
);
// On linefeed also write a carriage return to move to column 0.
if (c == '\n') {
putc('\r');
}
}
/// BIOS CALL - video set cursor position.
/// http://www.ctyme.com/intr/rb-0087.htm
pub fn set_pos(r: u8) void {
// dh=r (cursor row)
// dl=0 (cursor col)
const dx = @as(u16, r) << 8 | 0;
_ = asm volatile (
\\int $0x10
: // No outputs.
: [a] "{ax}" (0x200), // BIOS call number.
[b] "{bx}" (0x0), // Page number.
[d] "{dx}" (dx), // Position.
: "cc"
);
}
/// BIOS CALL - video scroll up
/// http://www.ctyme.com/intr/rb-0096.htm
pub fn scroll_up() void {
// ah=06h (call nr)
// al=1 (rows to scroll)
const ax = (@as(u16, 0x6) << 8) | 1;
// dh=ROWS-1 (row lower right corner)
// dl=COLS-1 (col lower right corner)
const dx = (@as(u16, ROWS - 1) << 8) | (COLS - 1);
_ = asm volatile (
\\int $0x10
: // No outputs.
: [a] "{ax}" (ax), // BIOS call number + rows to scroll.
[p] "{dx}" (dx), // Row + col lower right corner.
[b] "{bx}" (0x0700), // Attribute, dark bg, white fg.
[c] "{cx}" (0), // Row + col upper left corner.
: "cc"
);
}
|