~euhmeuh/ferale

60f8c722d267fcb60f4d8e025585eb354cc1b3ff — Zoé Martin 6 months ago d124fba
limite le nombre d'images par seconde à 60
2 files changed, 28 insertions(+), 6 deletions(-)

M emu/alosa.fs
M emu/main.fs
M emu/alosa.fs => emu/alosa.fs +3 -0
@@ 21,6 21,9 @@
%00000100 constant SCR-MODE-TILE
%00001000 constant SCR-MODE-CURS

320 constant SCR-WIDTH
240 constant SCR-HEIGHT

create SCR-NAMETABLE   1200 cells allot
create SCR-PALETTES      64 cells allot
create SCR-TILESET    32768 cells allot

M emu/main.fs => emu/main.fs +25 -6
@@ 160,24 160,43 @@ cpu-loop

\ ==== Main emulator loop ====

0 value FRAME-COUNT
0 value TICKS
0 value LAST-SECOND-TICKS
0 value LAST-FRAME-TICKS

: show-framerate { ticks -- }
  ticks LAST-SECOND-TICKS - 1000 > if
    ." FPS: " FRAME-COUNT . cr
    ticks to LAST-SECOND-TICKS
    0 to FRAME-COUNT
  then
;

: main-loop ( -- )
  init-palettes
  init-tileset
  init-nametable

  4 to DRAW-PIXEL-SIZE
  320 240 draw-init
  SCR-WIDTH SCR-HEIGHT draw-init

  begin
    quit? 0=
  while
    process-input
    render
    draw-flip
    draw-clean
    \ 10 sdl-delay

    sdl-get-ticks to TICKS

    TICKS LAST-FRAME-TICKS - 16 >= if
      render
      draw-flip
      FRAME-COUNT 1+ to FRAME-COUNT
      TICKS to LAST-FRAME-TICKS
    then

    TICKS show-framerate
  repeat

  draw-shutdown
;