Step, reset, tick_timer proc and struct cleanup.

Added a tick_timer proc so the code handles the step neatly.
Added some new struct fields to accomodate this and moved danglings
struct defs into the simulator definition.
This commit is contained in:
2026-06-19 12:33:47 +02:00
parent e9cf387640
commit 0b5006f985
5 changed files with 55 additions and 28 deletions
+17 -14
View File
@@ -67,23 +67,19 @@ run_gui :: proc(sim: ^Simulator) {
layout := calc_layout(screen_width, screen_height)
rl.BeginDrawing()
rl.ClearBackground(rl.BLACK)
rl.ClearBackground(rl.Color{0x18, 0x18, 0x18, 0xFF})
if (!sim.paused) {
// Cycle the machine to update memory etc
emu.run_machine(sim.machine, 12)
tick_timers(sim, beep)
}
// Handle delay timer
if sim.machine.delay_timer > 0 do sim.machine.delay_timer -= 1
// Current sound file is around 1s so stop
// immediately when timer is 0
if sim.machine.sound_timer > 0 {
sim.machine.sound_timer -= 1
if !rl.IsSoundPlaying(beep) do rl.PlaySound(beep)
} else {
rl.StopSound(beep)
}
if(sim.paused && sim.step) {
// Cycle the machine to update memory etc
emu.run_machine(sim.machine, 1)
tick_timers(sim, beep)
sim.step = false
}
// Top
@@ -115,9 +111,16 @@ run_gui :: proc(sim: ^Simulator) {
rl.UnloadSound(beep)
rl.CloseAudioDevice()
rl.CloseWindow()
}
// Free any allocated memory for the simulator
delete(sim.disasm)
tick_timers :: proc(sim: ^Simulator, beep: rl.Sound) {
if sim.machine.delay_timer > 0 do sim.machine.delay_timer -= 1
if sim.machine.sound_timer > 0 {
sim.machine.sound_timer -= 1
if !rl.IsSoundPlaying(beep) do rl.PlaySound(beep)
} else {
rl.StopSound(beep)
}
}
calc_layout :: proc(screen_width: f32, screen_height: f32) -> Layout {