Added sound checks, instructions and timers.
Also added some more test roms for later checks.
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user