Compare commits
No commits in common. "79514b0cd0b00613818b6b88169e8ac1c9eedcf5" and "21295b8d03f3cef4cd7ed659c12f29a88a3f7d2d" have entirely different histories.
79514b0cd0
...
21295b8d03
|
@ -96,7 +96,7 @@ pub fn read(bus: *const Bus, comptime T: type, address: u32) ?T {
|
|||
0x0400_0128 => util.io.read.todo(log, "Read {} from SIOCNT", .{T}),
|
||||
|
||||
// Keypad Input
|
||||
0x0400_0130 => bus.io.keyinput.load(.Monotonic),
|
||||
0x0400_0130 => bus.io.keyinput.load(.Monotonic).raw,
|
||||
|
||||
// Serial Communication 2
|
||||
0x0400_0134 => util.io.read.todo(log, "Read {} from RCNT", .{T}),
|
||||
|
@ -366,7 +366,7 @@ const InterruptEnable = extern union {
|
|||
|
||||
/// Read Only
|
||||
/// 0 = Pressed, 1 = Released
|
||||
pub const KeyInput = extern union {
|
||||
const KeyInput = extern union {
|
||||
a: Bit(u16, 0),
|
||||
b: Bit(u16, 1),
|
||||
select: Bit(u16, 2),
|
||||
|
@ -390,19 +390,18 @@ const AtomicKeyInput = struct {
|
|||
return .{ .inner = value };
|
||||
}
|
||||
|
||||
pub inline fn load(self: *const Self, comptime ordering: Ordering) u16 {
|
||||
return switch (ordering) {
|
||||
pub inline fn load(self: *const Self, comptime ordering: Ordering) KeyInput {
|
||||
return .{ .raw = switch (ordering) {
|
||||
.AcqRel, .Release => @compileError("not supported for atomic loads"),
|
||||
else => @atomicLoad(u16, &self.inner.raw, ordering),
|
||||
};
|
||||
} };
|
||||
}
|
||||
|
||||
pub inline fn fetchOr(self: *Self, value: u16, comptime ordering: Ordering) void {
|
||||
_ = @atomicRmw(u16, &self.inner.raw, .Or, value, ordering);
|
||||
}
|
||||
|
||||
pub inline fn fetchAnd(self: *Self, value: u16, comptime ordering: Ordering) void {
|
||||
_ = @atomicRmw(u16, &self.inner.raw, .And, value, ordering);
|
||||
pub inline fn store(self: *Self, value: u16, comptime ordering: Ordering) void {
|
||||
switch (ordering) {
|
||||
.AcqRel, .Acquire => @compileError("not supported for atomic stores"),
|
||||
else => @atomicStore(u16, &self.inner.raw, value, ordering),
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -140,10 +140,6 @@ fn audioSync(audio_sync: bool, stream: *SDL.SDL_AudioStream, is_buffer_full: *bo
|
|||
// If Busy is false, there's no need to sync here
|
||||
if (!still_full) return;
|
||||
|
||||
// TODO: Refactor!!!!
|
||||
// while (SDL.SDL_AudioStreamAvailable(stream) > sample_size * max_buf_size >> 1)
|
||||
// std.atomic.spinLoopHint();
|
||||
|
||||
while (true) {
|
||||
still_full = SDL.SDL_AudioStreamAvailable(stream) > sample_size * max_buf_size >> 1;
|
||||
if (!audio_sync or !still_full) break;
|
||||
|
@ -188,8 +184,7 @@ fn sleep(timer: *Timer, wake_time: u64) ?u64 {
|
|||
}
|
||||
|
||||
fn spinLoop(timer: *Timer, wake_time: u64) void {
|
||||
while (timer.read() < wake_time)
|
||||
std.atomic.spinLoopHint();
|
||||
while (true) if (timer.read() > wake_time) break;
|
||||
}
|
||||
|
||||
pub const EmuThing = struct {
|
||||
|
|
|
@ -12,7 +12,6 @@ const emu = @import("core/emu.zig");
|
|||
const Gui = @import("platform.zig").Gui;
|
||||
const Arm7tdmi = @import("core/cpu.zig").Arm7tdmi;
|
||||
const RingBuffer = @import("zba-util").RingBuffer;
|
||||
const Dimensions = @import("platform.zig").Dimensions;
|
||||
|
||||
const Allocator = std.mem.Allocator;
|
||||
const GLuint = gl.GLuint;
|
||||
|
@ -67,10 +66,8 @@ pub const State = struct {
|
|||
}
|
||||
};
|
||||
|
||||
pub fn draw(state: *State, win_dim: Dimensions, tex_id: GLuint, cpu: *Arm7tdmi) bool {
|
||||
const scn_scale = config.config().host.win_scale;
|
||||
|
||||
zgui.backend.newFrame(@intToFloat(f32, win_dim.width), @intToFloat(f32, win_dim.height));
|
||||
pub fn draw(state: *State, tex_id: GLuint, cpu: *Arm7tdmi) void {
|
||||
const win_scale = config.config().host.win_scale;
|
||||
|
||||
{
|
||||
_ = zgui.beginMainMenuBar();
|
||||
|
@ -145,8 +142,8 @@ pub fn draw(state: *State, win_dim: Dimensions, tex_id: GLuint, cpu: *Arm7tdmi)
|
|||
}
|
||||
|
||||
{
|
||||
const w = @intToFloat(f32, gba_width * scn_scale);
|
||||
const h = @intToFloat(f32, gba_height * scn_scale);
|
||||
const w = @intToFloat(f32, gba_width * win_scale);
|
||||
const h = @intToFloat(f32, gba_height * win_scale);
|
||||
|
||||
const window_title = std.mem.sliceTo(&state.title, 0);
|
||||
_ = zgui.begin(window_title, .{ .flags = .{ .no_resize = true, .always_auto_resize = true } });
|
||||
|
@ -321,8 +318,6 @@ pub fn draw(state: *State, win_dim: Dimensions, tex_id: GLuint, cpu: *Arm7tdmi)
|
|||
{
|
||||
zgui.showDemoWindow(null);
|
||||
}
|
||||
|
||||
return true; // request redraw
|
||||
}
|
||||
|
||||
const widgets = struct {
|
||||
|
|
|
@ -12,7 +12,6 @@ const Arm7tdmi = @import("core/cpu.zig").Arm7tdmi;
|
|||
const Scheduler = @import("core/scheduler.zig").Scheduler;
|
||||
const FpsTracker = @import("util.zig").FpsTracker;
|
||||
const TwoWayChannel = @import("zba-util").TwoWayChannel;
|
||||
const KeyInput = @import("core/bus/io.zig").KeyInput;
|
||||
|
||||
const gba_width = @import("core/ppu.zig").width;
|
||||
const gba_height = @import("core/ppu.zig").height;
|
||||
|
@ -22,7 +21,7 @@ const GLsizei = gl.GLsizei;
|
|||
const SDL_GLContext = *anyopaque;
|
||||
const Allocator = std.mem.Allocator;
|
||||
|
||||
pub const Dimensions = struct { width: u32, height: u32 };
|
||||
const Dimensions = struct { width: u32, height: u32 };
|
||||
const default_dim: Dimensions = .{ .width = 1280, .height = 720 };
|
||||
|
||||
pub const sample_rate = 1 << 15;
|
||||
|
@ -135,30 +134,28 @@ pub const Gui = struct {
|
|||
switch (event.type) {
|
||||
SDL.SDL_QUIT => break :emu_loop,
|
||||
SDL.SDL_KEYDOWN => {
|
||||
// TODO: Make use of compare_and_xor?
|
||||
const key_code = event.key.keysym.sym;
|
||||
var keyinput: KeyInput = .{ .raw = 0x0000 };
|
||||
var keyinput = cpu.bus.io.keyinput.load(.Monotonic);
|
||||
|
||||
switch (key_code) {
|
||||
SDL.SDLK_UP => keyinput.up.set(),
|
||||
SDL.SDLK_DOWN => keyinput.down.set(),
|
||||
SDL.SDLK_LEFT => keyinput.left.set(),
|
||||
SDL.SDLK_RIGHT => keyinput.right.set(),
|
||||
SDL.SDLK_x => keyinput.a.set(),
|
||||
SDL.SDLK_z => keyinput.b.set(),
|
||||
SDL.SDLK_a => keyinput.shoulder_l.set(),
|
||||
SDL.SDLK_s => keyinput.shoulder_r.set(),
|
||||
SDL.SDLK_RETURN => keyinput.start.set(),
|
||||
SDL.SDLK_RSHIFT => keyinput.select.set(),
|
||||
SDL.SDLK_UP => keyinput.up.unset(),
|
||||
SDL.SDLK_DOWN => keyinput.down.unset(),
|
||||
SDL.SDLK_LEFT => keyinput.left.unset(),
|
||||
SDL.SDLK_RIGHT => keyinput.right.unset(),
|
||||
SDL.SDLK_x => keyinput.a.unset(),
|
||||
SDL.SDLK_z => keyinput.b.unset(),
|
||||
SDL.SDLK_a => keyinput.shoulder_l.unset(),
|
||||
SDL.SDLK_s => keyinput.shoulder_r.unset(),
|
||||
SDL.SDLK_RETURN => keyinput.start.unset(),
|
||||
SDL.SDLK_RSHIFT => keyinput.select.unset(),
|
||||
else => {},
|
||||
}
|
||||
|
||||
cpu.bus.io.keyinput.fetchAnd(~keyinput.raw, .Monotonic);
|
||||
cpu.bus.io.keyinput.store(keyinput.raw, .Monotonic);
|
||||
},
|
||||
SDL.SDL_KEYUP => {
|
||||
// TODO: Make use of compare_and_xor?
|
||||
const key_code = event.key.keysym.sym;
|
||||
var keyinput: KeyInput = .{ .raw = 0x0000 };
|
||||
var keyinput = cpu.bus.io.keyinput.load(.Monotonic);
|
||||
|
||||
switch (key_code) {
|
||||
SDL.SDLK_UP => keyinput.up.set(),
|
||||
|
@ -174,7 +171,7 @@ pub const Gui = struct {
|
|||
else => {},
|
||||
}
|
||||
|
||||
cpu.bus.io.keyinput.fetchOr(keyinput.raw, .Monotonic);
|
||||
cpu.bus.io.keyinput.store(keyinput.raw, .Monotonic);
|
||||
},
|
||||
SDL.SDL_WINDOWEVENT => {
|
||||
if (event.window.event == SDL.SDL_WINDOWEVENT_RESIZED) {
|
||||
|
@ -188,7 +185,7 @@ pub const Gui = struct {
|
|||
}
|
||||
}
|
||||
|
||||
var zgui_redraw: bool = false;
|
||||
zgui.backend.newFrame(@intToFloat(f32, win_dim.width), @intToFloat(f32, win_dim.height));
|
||||
|
||||
switch (self.state.emulation) {
|
||||
.Transition => |inner| switch (inner) {
|
||||
|
@ -207,28 +204,19 @@ pub const Gui = struct {
|
|||
self.state.emulation = .Inactive;
|
||||
},
|
||||
},
|
||||
.Active => skip_draw: {
|
||||
.Active => {
|
||||
const is_std = mode == .Standard;
|
||||
|
||||
if (is_std) channel.emu.push(.Pause);
|
||||
defer if (is_std) channel.emu.push(.Resume);
|
||||
|
||||
switch (mode) {
|
||||
.Standard => blk: {
|
||||
const limit = 15; // TODO: What should this be?
|
||||
|
||||
// TODO: learn more about std.atomic.spinLoopHint();
|
||||
for (0..limit) |_| {
|
||||
const message = channel.gui.pop() orelse continue;
|
||||
|
||||
switch (message) {
|
||||
.Paused => break :blk,
|
||||
.Quit => unreachable,
|
||||
}
|
||||
}
|
||||
|
||||
log.info("timed out waiting for emu thread to pause (limit: {})", .{limit});
|
||||
break :skip_draw;
|
||||
.Standard => {
|
||||
// TODO: add timeout
|
||||
while (true) switch (channel.gui.pop() orelse continue) {
|
||||
.Paused => break,
|
||||
.Quit => unreachable, // only signaled in debug mode
|
||||
};
|
||||
},
|
||||
.Debug => blk: {
|
||||
switch (channel.gui.pop() orelse break :blk) {
|
||||
|
@ -251,20 +239,18 @@ pub const Gui = struct {
|
|||
opengl_impl.drawScreenTexture(emu_tex, prog_id, objects, buf);
|
||||
}
|
||||
|
||||
zgui_redraw = imgui.draw(&self.state, win_dim, out_tex, cpu);
|
||||
imgui.draw(&self.state, out_tex, cpu);
|
||||
},
|
||||
.Inactive => zgui_redraw = imgui.draw(&self.state, win_dim, out_tex, cpu),
|
||||
.Inactive => imgui.draw(&self.state, out_tex, cpu),
|
||||
}
|
||||
|
||||
if (zgui_redraw) {
|
||||
// Background Colour
|
||||
const size = zgui.io.getDisplaySize();
|
||||
gl.viewport(0, 0, @floatToInt(GLsizei, size[0]), @floatToInt(GLsizei, size[1]));
|
||||
gl.clearColor(0, 0, 0, 1.0);
|
||||
gl.clear(gl.COLOR_BUFFER_BIT);
|
||||
// Background Colour
|
||||
const size = zgui.io.getDisplaySize();
|
||||
gl.viewport(0, 0, @floatToInt(GLsizei, size[0]), @floatToInt(GLsizei, size[1]));
|
||||
gl.clearColor(0, 0, 0, 1.0);
|
||||
gl.clear(gl.COLOR_BUFFER_BIT);
|
||||
|
||||
zgui.backend.draw();
|
||||
}
|
||||
zgui.backend.draw();
|
||||
|
||||
SDL.SDL_GL_SwapWindow(self.window);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue