No need for display file in machine, gui handles it.
This commit is contained in:
@@ -1,66 +0,0 @@
|
|||||||
package machine
|
|
||||||
|
|
||||||
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
|
|
||||||
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, "raylib")
|
|
||||||
rl.InitAudioDevice()
|
|
||||||
|
|
||||||
rl.SetTargetFPS(60)
|
|
||||||
|
|
||||||
beep := rl.LoadSound("./beep.wav")
|
|
||||||
|
|
||||||
for !rl.WindowShouldClose() {
|
|
||||||
rl.BeginDrawing()
|
|
||||||
rl.ClearBackground(rl.BLACK)
|
|
||||||
|
|
||||||
// Do a cpu cycle
|
|
||||||
// Cap at 60hz/60fps
|
|
||||||
for _ in 0..<CYCLES_PER_FRAME {
|
|
||||||
handle_input(s)
|
|
||||||
cycle(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// update display with display buffer bits
|
|
||||||
render_display_buffer :: proc(display_buffer: ^[32][64]u8) {
|
|
||||||
// get row
|
|
||||||
for y in 0..<len(display_buffer) {
|
|
||||||
// get cols
|
|
||||||
for x in 0..<len(display_buffer[0]) {
|
|
||||||
if display_buffer[y][x] == 0x01 {
|
|
||||||
rl.DrawRectangle(i32(x * SCALE), i32(y * SCALE), SCALE, SCALE, rl.WHITE)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user