From 800bf36803cff839d953491a6fc708847e931fa0 Mon Sep 17 00:00:00 2001 From: Matthew Berry Date: Sun, 4 Oct 2020 00:18:23 -0700 Subject: [PATCH] remove hot .to_u8 call in bus, add fps to display title --- src/crab/bus.cr | 6 +++--- src/crab/display.cr | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/crab/bus.cr b/src/crab/bus.cr index dd50c27..9ba4944 100644 --- a/src/crab/bus.cr +++ b/src/crab/bus.cr @@ -28,9 +28,9 @@ class Bus when PPU_IO then @gba.ppu[index] when PPU then @gba.ppu[index] when CARTRIDGE then @gba.cartridge[index - CARTRIDGE.begin] - when UNUSED then 0xFF - else 0xFF - end.to_u8 + when UNUSED then 0xFF_u8 + else 0xFF_u8 + end end def read_word(index : Int) : Word diff --git a/src/crab/display.cr b/src/crab/display.cr index 0c63a82..ff50f83 100644 --- a/src/crab/display.cr +++ b/src/crab/display.cr @@ -14,10 +14,22 @@ class Display @texture = LibSDL.create_texture @renderer, PIXELFORMAT_BGR555, TEXTUREACCESS_STREAMING, WIDTH, HEIGHT end + def window_title : String + "crab - #{@fps} fps" + end + + @fps = 30 + @seconds : Int32 = Time.utc.second def draw(framebuffer : Bytes) : Nil LibSDL.update_texture @texture, nil, framebuffer, WIDTH * 2 @renderer.clear @renderer.copy @texture @renderer.present + @fps += 1 + if Time.utc.second != @seconds + @window.title = window_title + @fps = 0 + @seconds = Time.utc.second + end end end