Jakt toolchain for TempleOS development
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
unholy-jakt/os.jakt

56 lines
1.8 KiB

import extern c "os.h" {
extern function os_blink(frequency: raw c_char) -> bool
extern function os_exit()
extern function os_file_picker(path: raw c_char, glob: raw c_char)
extern function os_pc_speaker(frequency: raw c_char)
}
struct OS {
function blink(frequency: f64 = 2.5) throws -> bool {
let frequency_as_string = String::format("{}", frequency)
return os_blink(frequency: frequency_as_string.c_string())
}
function exit() {
os_exit()
}
function file_picker(path: String, glob: String) throws -> String {
mut s = StringBuilder::create()
unsafe {
cpp {
"char const *chars = os_file_picker(path.c_string(), glob.c_string());
TRY(s.append_c_string(chars));
delete(chars);"
}
}
return s.to_string()
}
function pc_speaker(frequency: f64) throws {
let frequency_as_string = String::format("{}", frequency)
os_pc_speaker(frequency: frequency_as_string.c_string())
}
function read_entire_file(anon filename: String) throws -> [u8] {
mut size = 0
mut buffer: [u8] = []
unsafe {
cpp {
"u8 *data = os_read_entire_file(filename.c_string(), &size);
for (int i = 0; i < size; i++)
TRY(buffer.push(data[i]));
free(data);"
}
}
return buffer
}
function write_entire_file(filename: String, buffer: [u8]) {
mut size = buffer.size()
unsafe {
cpp {
"unsigned char *data = (unsigned char *)malloc(size);
for (int i = 0; i < size; i++)
data[i] = buffer[i];
os_write_entire_file(filename.c_string(), data, size);
free(data);"
}
}
}
}