diff --git a/beep.wav b/beep.wav new file mode 100644 index 0000000..c44e1e3 Binary files /dev/null and b/beep.wav differ diff --git a/src/machine/display.odin b/src/machine/display.odin index 6636f95..45ba122 100644 --- a/src/machine/display.odin +++ b/src/machine/display.odin @@ -4,7 +4,6 @@ import rl "vendor:raylib" // Handle the "display" and all of its required functions // raylib window, rendering, scale constants - SCALE :: 20 SCREEN_WITDH :: 64 * SCALE SCREEN_HEIGHT :: 32 * SCALE @@ -12,10 +11,13 @@ CYCLES_PER_FRAME :: 12 // Display will handle all the screen drawing with raylib etc run_system :: proc(s: ^System) { - rl.InitWindow(SCREEN_WITDH, SCREEN_HEIGHT, "chip8") + rl.InitWindow(SCREEN_WITDH, SCREEN_HEIGHT, "raylib") + rl.InitAudioDevice() rl.SetTargetFPS(60) + beep := rl.LoadSound("./beep.wav") + for !rl.WindowShouldClose() { rl.BeginDrawing() rl.ClearBackground(rl.BLACK) @@ -26,14 +28,26 @@ run_system :: proc(s: ^System) { handle_input(s) cycle(s) } - if s.delay_timer > 0 { s.delay_timer -= 1 } - if s.sound_timer > 0 { s.sound_timer -= 1 } + + // Handle delay timer + if s.delay_timer > 0 do s.delay_timer -= 1 + + // Current sound file is around 1s so stop + // immediately when timer is 0 + if s.sound_timer > 0 { + s.sound_timer -= 1 + if !rl.IsSoundPlaying(beep) do rl.PlaySound(beep) + } else { + rl.StopSound(beep) + } render_display_buffer(&s.display) rl.EndDrawing() } + rl.UnloadSound(beep) + rl.CloseAudioDevice() rl.CloseWindow() } diff --git a/test_roms/3-corax+.ch8 b/test_roms/3-corax+.ch8 new file mode 100644 index 0000000..9fc874c Binary files /dev/null and b/test_roms/3-corax+.ch8 differ diff --git a/test_roms/5-quirks.ch8 b/test_roms/5-quirks.ch8 new file mode 100644 index 0000000..1c87f6c Binary files /dev/null and b/test_roms/5-quirks.ch8 differ diff --git a/test_roms/7-beep.ch8 b/test_roms/7-beep.ch8 new file mode 100644 index 0000000..27c205f Binary files /dev/null and b/test_roms/7-beep.ch8 differ