Permalink
Browse files

Add a flag to control the screen refresh rate

  • Loading branch information...
1 parent ddf8d1f commit 59f1b3bfdd317cf121a072d863c74d7f7ef6c018 @kballard committed Apr 16, 2012
Showing with 13 additions and 3 deletions.
  1. +5 −1 dcpu/machine.go
  2. +5 −2 dcpu/video.go
  3. +3 −0 main.go
View
6 dcpu/machine.go
@@ -63,7 +63,11 @@ func (m *Machine) Start(rate ClockRate) (err error) {
// So lets instead switch to running as many cycles as we need before using any
// timed delays
cycleChan := make(chan time.Time, 1)
- scanrate := time.NewTicker(time.Second / 60) // 60Hz
+ refreshRate := m.Video.RefreshRate
+ if refreshRate == 0 {
+ refreshRate = DefaultScreenRefreshRate
+ }
+ scanrate := time.NewTicker(refreshRate.ToDuration())
var stoperr error
nextTime := time.Now()
period := rate.ToDuration()
View
7 dcpu/video.go
@@ -21,6 +21,8 @@ const (
backgroundColorAddress = 0x0280
)
+const DefaultScreenRefreshRate ClockRate = 60 // 60Hz
+
var supportsXterm256 bool
// colorToAnsi maps the 4-bit DCPU-16 colors to xterm-256 colors
@@ -40,8 +42,9 @@ var colorToAnsi [16]byte = [...]byte{
}
type Video struct {
- words [0x400]core.Word
- mapped bool
+ RefreshRate ClockRate // the refresh rate of the screen
+ words [0x400]core.Word
+ mapped bool
}
func (v *Video) Init() error {
View
3 main.go
@@ -12,10 +12,12 @@ import (
var requestedRate dcpu.ClockRate = dcpu.DefaultClockRate
var printRate *bool = flag.Bool("printRate", false, "Print the effective clock rate at termination")
+var screenRefreshRate dcpu.ClockRate = dcpu.DefaultScreenRefreshRate
func main() {
// command-line flags
flag.Var(&requestedRate, "rate", "Clock rate to run the machine at")
+ flag.Var(&screenRefreshRate, "screenRefreshRate", "Clock rate to refresh the screen at")
// update usage
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "usage: %s [flags] program\n", os.Args[0])
@@ -41,6 +43,7 @@ func main() {
// Set up a machine
machine := new(dcpu.Machine)
+ machine.Video.RefreshRate = screenRefreshRate
if err := machine.State.LoadProgram(words, 0); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)

0 comments on commit 59f1b3b

Please sign in to comment.