Skip to content

Commit

Permalink
Limit DMG run loop to DMG CPU speed
Browse files Browse the repository at this point in the history
Ticker is not the most accurate or flexible, but good enough for now
  • Loading branch information
maxfierke committed May 21, 2024
1 parent 698ebad commit f859671
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion hardware/dmg.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import (
"github.com/maxfierke/gogo-gb/mem"
)

const DMG_RAM_SIZE = 0xFFFF + 1
const (
DMG_CPU_HZ = 4194304
DMG_RAM_SIZE = 0xFFFF + 1
)

type DMGOption func(dmg *DMG)

Expand Down Expand Up @@ -128,7 +131,11 @@ func (dmg *DMG) Run(host devices.HostInterface) error {

hostExit := host.Exited()

clockRate := time.NewTicker(time.Second / DMG_CPU_HZ)
defer clockRate.Stop()

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

for {
select {
Expand All @@ -143,5 +150,6 @@ func (dmg *DMG) Run(host devices.HostInterface) error {
if err := dmg.Step(); err != nil {
return err
}
<-clockRate.C
}
}

0 comments on commit f859671

Please sign in to comment.