|
|
|
@@ -1,5 +1,6 @@
|
|
|
|
|
package simulator
|
|
|
|
|
|
|
|
|
|
import "core:strings"
|
|
|
|
|
import "core:fmt"
|
|
|
|
|
import "core:log"
|
|
|
|
|
import rl "vendor:raylib"
|
|
|
|
@@ -32,18 +33,7 @@ gui_file_loader :: proc(rect: rl.Rectangle, sim: ^Simulator) {
|
|
|
|
|
ret := tfd.openFileDialog("Open File Dialog", nil, 0, nil, nil, 0,)
|
|
|
|
|
rom_path := string(ret)
|
|
|
|
|
if rom_path == "" do return
|
|
|
|
|
|
|
|
|
|
// Reset machine state
|
|
|
|
|
emu.reset_machine(sim.machine)
|
|
|
|
|
|
|
|
|
|
// load new rom
|
|
|
|
|
rom_size, err := emu.load_rom(sim.machine, rom_path)
|
|
|
|
|
if err != nil {
|
|
|
|
|
// @TODO: update status bar here
|
|
|
|
|
panic("failed to load rom!")
|
|
|
|
|
}
|
|
|
|
|
sim.rom_loaded = true
|
|
|
|
|
sim.disasm_count = disassemble_rom_n(sim.machine.memory[:], 0x200, 0x200 + u16(rom_size), sim.disasm[:])
|
|
|
|
|
load_selected_rom(sim, rom_path)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// drop-zone occupies the panel's content area, minus space for the button
|
|
|
|
@@ -78,7 +68,7 @@ gui_file_loader :: proc(rect: rl.Rectangle, sim: ^Simulator) {
|
|
|
|
|
rl.UnloadDroppedFiles(dropped_file)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// FOLDER SECTION:
|
|
|
|
|
// Embedded Rom Section:
|
|
|
|
|
// ---------------------------------------------
|
|
|
|
|
bottom_bounds := rl.Rectangle {
|
|
|
|
|
x = bounds.x,
|
|
|
|
@@ -86,16 +76,82 @@ gui_file_loader :: proc(rect: rl.Rectangle, sim: ^Simulator) {
|
|
|
|
|
width = rect.width - (PADDING_X * 2),
|
|
|
|
|
height = rect.height - top_bounds_height - (PADDING_X * 2)
|
|
|
|
|
}
|
|
|
|
|
rl.GuiPanel(bottom_bounds, nil)
|
|
|
|
|
rl.GuiPanel(bottom_bounds, "ROM List")
|
|
|
|
|
|
|
|
|
|
bottom_btn_rect := rl.Rectangle {
|
|
|
|
|
bottom_bounds.x,
|
|
|
|
|
bottom_bounds.y,
|
|
|
|
|
rect.width - (PADDING_X * 2),
|
|
|
|
|
BUTTON_HEIGHT,
|
|
|
|
|
panel_rect := rl.Rectangle {
|
|
|
|
|
x = bottom_bounds.x,
|
|
|
|
|
y = bottom_bounds.y + PANEL_HEADER,
|
|
|
|
|
width = rect.width - (PADDING_X * 2),
|
|
|
|
|
height = rect.height - top_bounds_height - (PADDING_X * 2) - PANEL_HEADER
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rl.GuiButton(bottom_btn_rect, "Open ROM Folder")
|
|
|
|
|
content_rect := rl.Rectangle {
|
|
|
|
|
x = panel_rect.x,
|
|
|
|
|
y = panel_rect.y - PANEL_HEADER,
|
|
|
|
|
width = panel_rect.width + PANEL_HEADER,
|
|
|
|
|
height = f32(len(roms)) * LINE_HEIGHT
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
view: rl.Rectangle
|
|
|
|
|
rl.GuiScrollPanel(panel_rect, nil, content_rect, &sim.rompick_scroll, &view)
|
|
|
|
|
|
|
|
|
|
rl.BeginScissorMode(i32(view.x), i32(view.y), i32(view.width), i32(view.height))
|
|
|
|
|
defer rl.EndScissorMode()
|
|
|
|
|
|
|
|
|
|
for path, index in roms {
|
|
|
|
|
y_pos := panel_rect.y + f32(index * LINE_HEIGHT) + sim.rompick_scroll.y
|
|
|
|
|
|
|
|
|
|
row_rect := rl.Rectangle {
|
|
|
|
|
x = view.x,
|
|
|
|
|
y = y_pos,
|
|
|
|
|
width = view.width,
|
|
|
|
|
height = LINE_HEIGHT,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// make selected visible
|
|
|
|
|
if path.name == sim.selected_rom {
|
|
|
|
|
rl.DrawRectangleRec(row_rect, rl.ColorAlpha(rl.SKYBLUE, 0.25))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// hover rows
|
|
|
|
|
mouse := rl.GetMousePosition()
|
|
|
|
|
if rl.CheckCollisionPointRec(mouse, row_rect) {
|
|
|
|
|
rl.DrawRectangleRec(row_rect, rl.ColorAlpha(rl.WHITE, 0.08))
|
|
|
|
|
if rl.IsMouseButtonPressed(.LEFT) {
|
|
|
|
|
sim.selected_rom = path.name
|
|
|
|
|
load_embedded_rom(sim, path.name, roms[index].data)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
txt := fmt.tprintf("%v: %v", (index + 1), path.name)
|
|
|
|
|
rl.DrawTextEx(
|
|
|
|
|
sim.font,
|
|
|
|
|
strings.clone_to_cstring(txt, context.temp_allocator),
|
|
|
|
|
{panel_rect.x + PADDING_X + sim.rompick_scroll.x, y_pos + (LINE_HEIGHT - 18) * 0.5},
|
|
|
|
|
18, 1,
|
|
|
|
|
rl.WHITE
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
load_selected_rom :: proc(sim: ^Simulator, rom_path: string) {
|
|
|
|
|
emu.reset_machine(sim.machine)
|
|
|
|
|
rom_size, err := emu.load_rom(sim.machine, rom_path)
|
|
|
|
|
if err != nil {
|
|
|
|
|
// @TODO: update status bar here
|
|
|
|
|
panic("failed to load rom!")
|
|
|
|
|
}
|
|
|
|
|
sim.rom_loaded = true
|
|
|
|
|
sim.paused = true
|
|
|
|
|
sim.disasm_count = disassemble_rom_n(sim.machine.memory[:], 0x200, 0x200 + u16(rom_size), sim.disasm[:])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
load_embedded_rom :: proc(sim: ^Simulator, path: string, data: []byte) {
|
|
|
|
|
emu.reset_machine(sim.machine)
|
|
|
|
|
copy(sim.machine.memory[0x200:], data)
|
|
|
|
|
sim.rom_loaded = true
|
|
|
|
|
sim.paused = true
|
|
|
|
|
sim.disasm_count = disassemble_rom_n(sim.machine.memory[:], 0x200, 0x200 + u16(len(data)), sim.disasm[:])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
disassemble_rom_n :: proc(memory: []u8, start_addr: u16, end_addr: u16, out: []Instruction) -> int {
|
|
|
|
|