diff --git a/src/simulator/gui.odin b/src/simulator/gui.odin index c0761fd..1c94298 100644 --- a/src/simulator/gui.odin +++ b/src/simulator/gui.odin @@ -115,6 +115,9 @@ run_gui :: proc(sim: ^Simulator) { rl.UnloadSound(beep) rl.CloseAudioDevice() rl.CloseWindow() + + // Free any allocated memory for the simulator + delete(sim.disasm) } // @TODO: If this grows lets move it into its own file @@ -128,6 +131,7 @@ calc_layout :: proc(screen_width: f32, screen_height: f32) -> Layout { sidebar_width := screen_width * SIDEBAR_PERCENT display_width := screen_width - (sidebar_width * 2) - sidebar_width display_height := visible_height * DISPLAY_V_RATIO + keypad_height := (y_pos + visible_height - visible_height / 2) x_center := sidebar_width y_center := screen_width - sidebar_width * 2 @@ -144,11 +148,11 @@ calc_layout :: proc(screen_width: f32, screen_height: f32) -> Layout { x = 0, y = y_pos, width = sidebar_width, - height = visible_height / 3 + height = keypad_height - y_pos }, keypad = rl.Rectangle{ x = 0, - y = (y_pos + visible_height - visible_height / 2), + y = keypad_height, width = sidebar_width, height = visible_height / 2 }, diff --git a/src/simulator/gui_file_loader.odin b/src/simulator/gui_file_loader.odin index 75fe88d..730ac43 100644 --- a/src/simulator/gui_file_loader.odin +++ b/src/simulator/gui_file_loader.odin @@ -16,15 +16,17 @@ Instruction :: struct { gui_file_loader :: proc(rect: rl.Rectangle, sim: ^Simulator) { rl.DrawRectangleLinesEx(rect, 1, rl.GRAY) + // FILE SECTION: + // --------------------------------------------- + top_bounds_height := (rect.height - (PADDING_Y * 2)) / 3 bounds := rl.Rectangle { x = rect.x + PADDING_X, y = rect.y + PADDING_Y, width = rect.width - (PADDING_X * 2), - height = rect.height - (PADDING_Y * 2), + height = top_bounds_height } - rl.GuiPanel(bounds, "Rom / File") + rl.GuiPanel(bounds, nil) - // open rom button below drop-zone btn_rect := rl.Rectangle { bounds.x, bounds.y, @@ -48,6 +50,9 @@ gui_file_loader :: proc(rect: rl.Rectangle, sim: ^Simulator) { } sim.rom_loaded = true + + // Free old instructions on sim + delete(sim.disasm) sim.disasm = disassemble_rom(sim.machine.memory[:], 0x200, 0x200 + u16(rom_size)) } @@ -63,7 +68,7 @@ gui_file_loader :: proc(rect: rl.Rectangle, sim: ^Simulator) { // centered drop-zone text text: cstring = "Drop a CHIP-8 ROM here" text_width := rl.MeasureText(text, BIG_FONT_SIZE) - text_x := drop_zone.x + (drop_zone.width - f32(text_width)) / 2 + text_x := drop_zone.x + (drop_zone.width - f32(text_width)) text_y := drop_zone.y + (drop_zone.height - f32(BIG_FONT_SIZE)) / 2 rl.DrawTextEx(sim.font, text, {text_x, text_y}, BIG_FONT_SIZE, 1, rl.WHITE) @@ -76,13 +81,31 @@ gui_file_loader :: proc(rect: rl.Rectangle, sim: ^Simulator) { if rl.CheckCollisionPointRec(mouse, drop_zone) { path_str := string(dropped_file.paths[0]) log.info("file dropped: ", path_str) - // @TODO: Stop sim, reset mem etc, load new rom } else { log.info("File dropped outside drop zone, ignoring") } } rl.UnloadDroppedFiles(dropped_file) } + + // FOLDER SECTION: + // --------------------------------------------- + bottom_bounds := rl.Rectangle { + x = bounds.x, + y = bounds.y + top_bounds_height, + width = rect.width - (PADDING_X * 2), + height = rect.height - top_bounds_height - (PADDING_X * 2) + } + rl.GuiPanel(bottom_bounds, nil) + + bottom_btn_rect := rl.Rectangle { + bottom_bounds.x, + bottom_bounds.y, + rect.width - (PADDING_X * 2), + BUTTON_HEIGHT, + } + + rl.GuiButton(bottom_btn_rect, "Open ROM Folder") } disassemble_rom :: proc(memory: []u8, start: u16, end_addr: u16) -> []Instruction { @@ -167,28 +190,3 @@ disassemble_rom :: proc(memory: []u8, start: u16, end_addr: u16) -> []Instructio return entries[:] } - - - - - - - - - - - - - - - - - - - - - - - - -