1 Commits

Author SHA1 Message Date
宋文武
3633516f62 programs: Add Uxn emulator.
All checks were successful
Build system / Check kernel codestyle (pull_request) Successful in 36s
Build system / Build (pull_request) Successful in 8m47s
2025-07-20 22:59:22 +08:00
2 changed files with 16 additions and 1 deletions

View File

@@ -538,6 +538,20 @@ pub fn writeFile(pathname: [*:0]const u8, offset: u64, buffer: []u8) !u32 {
};
}
pub fn fileGetSize(pathname: [*:0]const u8) !u64 {
var ret: [10]u32 = undefined;
const info: FileInfo = .{
.subfn = 5,
.offset = 0,
.size = 0,
.buffer = @intFromPtr(&ret),
.pathptr = @ptrCast(pathname),
};
if (syscall1(SYS.file, @intFromPtr(&info)) != 0)
return error.Unexpected;
return ret[8] | (@as(u64, ret[9]) << 32);
}
pub fn deleteFile(pathname: [*:0]const u8) !void {
const info: FileInfo = .{
.subfn = 8,

View File

@@ -98,7 +98,8 @@ const emu = struct {
const buffer = getFilePortSlice(dev, ports.write);
var ret: u32 = 0;
if (append) {
ret = kos.writeFile(pathname, file_offsets[idx], buffer) catch |err| blk: {
const offset: u32 = @intCast(kos.fileGetSize(pathname) catch 0);
ret = kos.writeFile(pathname, offset, buffer) catch |err| blk: {
if (err == error.FileNotFound) {
break :blk kos.createFile(pathname, buffer) catch 0;
} else {