const std = @import("std");
const pio = @import("pio.zig");
const arch = @import("arch.zig");
const term = @import("term.zig");
const mem = std.mem;
pub const com1 = 0x3F8;
var _wait = true;
var _read: usize = 0;
var _write: usize = 0;
pub var wait: *volatile bool = &_wait;
pub var read: *volatile usize = &_read;
pub var write: *volatile usize = &_write;
pub var buffer = [_]u8{0} ** 0x10000;
pub fn init() void {
pio.outb(com1 + 1, 0x00);
pio.outb(com1 + 3, 0x80);
pio.outb(com1 + 0, 0x03);
pio.outb(com1 + 1, 0x00);
pio.outb(com1 + 3, 0x03);
pio.outb(com1 + 2, 0xC7);
pio.outb(com1 + 4, 0x0B);
pio.outb(com1 + 4, 0x1E);
pio.outb(com1 + 0, 0xAE);
if (pio.inb(com1 + 0) != 0xAE) {
@panic("faulty serial");
}
pio.outb(com1 + 4, 0x0F);
pio.outb(com1 + 3, 0x00);
pio.outb(com1 + 1, 0x01);
}
pub fn send(msg: []const u8) void {
for (msg) |byte| {
putchar(byte);
}
}
pub fn putchar(byte: u8) void {
while (pio.inb(com1 + 5) & 0x20 == 0) {}
pio.outb(com1 + 0, byte);
}
pub fn getchar() u8 {
const idx = read.*;
while (idx == write.*) {}
defer read.* += 1;
return buffer[idx];
}