feat(bus): implement IWRAM and EWRAM
This commit is contained in:
46
src/bus/Ewram.zig
Normal file
46
src/bus/Ewram.zig
Normal file
@@ -0,0 +1,46 @@
|
||||
const std = @import("std");
|
||||
|
||||
const Allocator = std.mem.Allocator;
|
||||
const Self = @This();
|
||||
|
||||
buf: []u8,
|
||||
alloc: Allocator,
|
||||
|
||||
pub fn init(alloc: Allocator) !Self {
|
||||
return Self{
|
||||
.buf = try alloc.alloc(u8, 0x8000),
|
||||
.alloc = alloc,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn deinit(self: Self) void {
|
||||
self.alloc.free(self.buf);
|
||||
}
|
||||
|
||||
pub fn get32(self: *const Self, idx: usize) u32 {
|
||||
return (@as(u32, self.buf[idx + 3]) << 24) | (@as(u32, self.buf[idx + 2]) << 16) | (@as(u32, self.buf[idx + 1]) << 8) | (@as(u32, self.buf[idx]));
|
||||
}
|
||||
|
||||
pub fn set32(self: *Self, idx: usize, word: u32) void {
|
||||
self.buf[idx + 3] = @truncate(u8, word >> 24);
|
||||
self.buf[idx + 2] = @truncate(u8, word >> 16);
|
||||
self.buf[idx + 1] = @truncate(u8, word >> 8);
|
||||
self.buf[idx] = @truncate(u8, word);
|
||||
}
|
||||
|
||||
pub fn get16(self: *const Self, idx: usize) u16 {
|
||||
return (@as(u16, self.buf[idx + 1]) << 8) | @as(u16, self.buf[idx]);
|
||||
}
|
||||
|
||||
pub fn set16(self: *Self, idx: usize, halfword: u16) void {
|
||||
self.buf[idx + 1] = @truncate(u8, halfword >> 8);
|
||||
self.buf[idx] = @truncate(u8, halfword);
|
||||
}
|
||||
|
||||
pub fn get8(self: *const Self, idx: usize) u8 {
|
||||
return self.buf[idx];
|
||||
}
|
||||
|
||||
pub fn set8(self: *Self, idx: usize, byte: u8) void {
|
||||
self.buf[idx] = byte;
|
||||
}
|
44
src/bus/Iwram.zig
Normal file
44
src/bus/Iwram.zig
Normal file
@@ -0,0 +1,44 @@
|
||||
const std = @import("std");
|
||||
|
||||
const Allocator = std.mem.Allocator;
|
||||
const Self = @This();
|
||||
|
||||
buf: []u8,
|
||||
alloc: Allocator,
|
||||
|
||||
pub fn init(alloc: Allocator) !Self {
|
||||
return Self{
|
||||
.buf = try alloc.alloc(u8, 0x40000),
|
||||
.alloc = alloc,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn deinit(self: Self) void {
|
||||
self.alloc.free(self.buf);
|
||||
}
|
||||
|
||||
pub fn get32(self: *const Self, idx: usize) u32 {
|
||||
return (@as(u32, self.get16(idx + 2)) << 16) | @as(u32, self.get16(idx));
|
||||
}
|
||||
|
||||
pub fn set32(self: *Self, idx: usize, word: u32) void {
|
||||
self.set16(idx + 2, @truncate(u16, word >> 16));
|
||||
self.set16(idx, @truncate(u16, word));
|
||||
}
|
||||
|
||||
pub fn get16(self: *const Self, idx: usize) u16 {
|
||||
return (@as(u16, self.buf[idx + 1]) << 8) | @as(u16, self.buf[idx]);
|
||||
}
|
||||
|
||||
pub fn set16(self: *Self, idx: usize, halfword: u16) void {
|
||||
self.buf[idx + 1] = @truncate(u8, halfword >> 8);
|
||||
self.buf[idx] = @truncate(u8, halfword);
|
||||
}
|
||||
|
||||
pub fn get8(self: *const Self, idx: usize) u8 {
|
||||
return self.buf[idx];
|
||||
}
|
||||
|
||||
pub fn set8(self: *Self, idx: usize, byte: u8) void {
|
||||
self.buf[idx] = byte;
|
||||
}
|
@@ -52,6 +52,10 @@ pub const Io = struct {
|
||||
else => std.debug.panic("[I/O:8] tried to read from {X:}", .{addr}),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn set8(_: *Self, addr: u32, byte: u8) void {
|
||||
std.debug.panic("[I/0:8] tried to write 0x{X:} to 0x{X:}", .{ byte, addr });
|
||||
}
|
||||
};
|
||||
|
||||
const DispCnt = extern union {
|
||||
|
Reference in New Issue
Block a user