idk
This commit is contained in:
parent
0e5ca8a574
commit
b7057bfabe
3 changed files with 46 additions and 63 deletions
30
src/main.zig
30
src/main.zig
|
@ -1,4 +1,5 @@
|
|||
const std = @import("std");
|
||||
const silkdot = @import("silkdot");
|
||||
|
||||
pub fn main() !void {
|
||||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||
|
@ -16,9 +17,9 @@ pub fn main() !void {
|
|||
const rom = try file.readToEndAlloc(allocator, 0xFFFF);
|
||||
defer allocator.free(rom);
|
||||
|
||||
const mem: [0xFFFF]u8 = undefined;
|
||||
const ws: [0xFF]u8 = undefined;
|
||||
const rs: [0xFF]u8 = undefined;
|
||||
const mem: [0x10000]u8 = undefined;
|
||||
const ws: [0x100]u8 = undefined;
|
||||
const rs: [0x100]u8 = undefined;
|
||||
var uxn = Uxn{
|
||||
.mem = .{ .m = mem },
|
||||
.ws = .{ .s = ws },
|
||||
|
@ -27,7 +28,22 @@ pub fn main() !void {
|
|||
};
|
||||
@memcpy(uxn.mem.m[0x100 .. 0x100 + rom.len], rom);
|
||||
|
||||
while (true) uxn.loop();
|
||||
var term = try silkdot.Terminal.init(allocator);
|
||||
defer term.deinit();
|
||||
|
||||
var running = true;
|
||||
while (running) {
|
||||
const events = try term.getEvents();
|
||||
defer allocator.free(events);
|
||||
for (events) |ev| switch (ev) {
|
||||
.keyboard => {
|
||||
if (ev.keyboard.code == 'q') running = false;
|
||||
},
|
||||
else => {},
|
||||
};
|
||||
uxn.loop();
|
||||
try term.draw();
|
||||
}
|
||||
} else return error.NoRom;
|
||||
}
|
||||
|
||||
|
@ -38,7 +54,7 @@ pub const Uxn = struct {
|
|||
pc: u16,
|
||||
|
||||
const Memory = struct {
|
||||
m: [0xFFFF]u8,
|
||||
m: [0x10000]u8,
|
||||
|
||||
pub fn peek(self: *Memory, comptime T: type, idx: u16) T {
|
||||
return switch (T) {
|
||||
|
@ -58,7 +74,7 @@ pub const Uxn = struct {
|
|||
};
|
||||
|
||||
const Stack = struct {
|
||||
s: [0xFF]u8,
|
||||
s: [0x100]u8,
|
||||
sp: u8 = 0,
|
||||
|
||||
pub fn peek(self: *Stack, comptime T: type) T {
|
||||
|
@ -372,6 +388,8 @@ pub const Uxn = struct {
|
|||
0xFE => eor(&self.rs, u16, true), // EOR2kr
|
||||
0xFF => sft(&self.rs, u16, true), // SFT2kr
|
||||
}
|
||||
|
||||
self.pc +%= 1;
|
||||
}
|
||||
|
||||
fn brk() void {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue