Skip to content

Commit

Permalink
Add a fake vblank to avoid drawing every step
Browse files Browse the repository at this point in the history
  • Loading branch information
maxfierke committed May 21, 2024
1 parent 86df388 commit fd95e5d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions hardware/dmg.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package hardware
import (
"fmt"
"log"
"time"

"github.com/maxfierke/gogo-gb/cart"
"github.com/maxfierke/gogo-gb/cpu"
Expand Down Expand Up @@ -127,18 +128,20 @@ func (dmg *DMG) Run(host devices.HostInterface) error {

hostExit := host.Exited()

fakeVBlank := time.NewTicker(time.Second / 60)

for {
select {
case <-hostExit:
return nil
case <-fakeVBlank.C:
framebuffer <- dmg.lcd.Draw()
default:
// Do nothing
}

if err := dmg.Step(); err != nil {
return err
}

framebuffer <- dmg.lcd.Draw()
}
}

0 comments on commit fd95e5d

Please sign in to comment.