From 141aea0fc4ff720e0c81704f7a3e18e12d825b7f Mon Sep 17 00:00:00 2001 From: Jason Hilder Date: Fri, 5 Jun 2026 08:10:24 +0200 Subject: [PATCH] Small cleanup with new run machine proc. --- src/gui/gui.odin | 57 ++++++++++++++++++---------------------- src/machine/cpu.odin | 3 +-- src/machine/machine.odin | 8 ++++++ 3 files changed, 35 insertions(+), 33 deletions(-) diff --git a/src/gui/gui.odin b/src/gui/gui.odin index f180f10..4df9ae5 100644 --- a/src/gui/gui.odin +++ b/src/gui/gui.odin @@ -7,16 +7,16 @@ import rl "vendor:raylib" WINDOW_WIDTH :: 1920 WINDOW_HEIGHT :: 1080 -// TODO: If this grows lets move it into its own file +// @TODO: If this grows lets move it into its own file SIDEBAR_PERCENT :: 0.20 DISPLAY_PERCENT :: 0.30 CONTROLBAR_PERCENT :: 0.05 Layout :: struct { - left_panel : rl.Rectangle, - right_panel : rl.Rectangle, - display : rl.Rectangle, control_bar : rl.Rectangle, + left_panel : rl.Rectangle, + display : rl.Rectangle, + right_panel : rl.Rectangle, } // Initialize main the gui 'window' @@ -34,20 +34,16 @@ init_gui :: proc(s: ^m.System) { screen_height := f32(rl.GetScreenHeight()) sidebar_width := screen_width * 0.20 + // set all the layout structs dynamically with the screen size layout := calc_layout(screen_width, screen_height) rl.BeginDrawing() rl.ClearBackground(rl.BLACK) - // TODO: move this out / make better - // -------------------------------------- - // CPU cycles - for _ in 0..<12 { - m.handle_input(s) - m.cycle(s) - } - // -------------------------------------- + // Cycle the machine to update memory etc + m.run_machine(s) + // Now draw the update data gui_left_panel(layout.left_panel, s) gui_right_panel(layout.right_panel, s) gui_screen(layout.display, s) @@ -60,38 +56,37 @@ init_gui :: proc(s: ^m.System) { rl.CloseWindow() } -// TODO: If this grows lets move it into its own file +// @TODO: If this grows lets move it into its own file calc_layout :: proc(screen_width: f32, screen_height: f32) -> Layout { + control_bar_height := screen_height * CONTROLBAR_PERCENT sidebar_width := screen_width * SIDEBAR_PERCENT - display_height := screen_height * DISPLAY_PERCENT + sidebar_height := screen_height - control_bar_height + display_height := screen_height * DISPLAY_PERCENT - control_bar_height return Layout { - left_panel = rl.Rectangle { + control_bar = rl.Rectangle { x = 0, y = 0, - width = sidebar_width, - height = screen_height + width = screen_width, + height = control_bar_height }, - - right_panel = rl.Rectangle { - x = screen_width - sidebar_width, - y = 0, + left_panel = rl.Rectangle { + x = 0, + y = control_bar_height, width = sidebar_width, - height = screen_height + height = sidebar_height }, - display = rl.Rectangle { x = sidebar_width, - y = 0, + y = control_bar_height, width = screen_width - (sidebar_width * 2), height = display_height }, - - control_bar = rl.Rectangle { - x = sidebar_width, - y = display_height, - width = screen_width - (sidebar_width * 2), - height = (screen_height * 0.05) - } + right_panel = rl.Rectangle { + x = screen_width - sidebar_width, + y = control_bar_height, + width = sidebar_width, + height = sidebar_height + }, } } diff --git a/src/machine/cpu.odin b/src/machine/cpu.odin index 5fea854..e371a2d 100644 --- a/src/machine/cpu.odin +++ b/src/machine/cpu.odin @@ -333,5 +333,4 @@ op_mem_get :: proc(s: ^System, vx_idx: u16) { for loop_idx in 0..=vx_idx { s.v[loop_idx] = s.memory[s.i + loop_idx] } -} - +} \ No newline at end of file diff --git a/src/machine/machine.odin b/src/machine/machine.odin index 69a926c..544d4e9 100644 --- a/src/machine/machine.odin +++ b/src/machine/machine.odin @@ -60,3 +60,11 @@ init :: proc() -> System { return s } + +run_machine :: proc(s: ^System) { + // CPU cycles + for _ in 0..<12 { + handle_input(s) + cycle(s) + } +}