timers countdown

This commit is contained in:
Jairinho 2022-02-23 16:54:12 -03:00
parent 80ff284c0d
commit 9930d1666c
No known key found for this signature in database
GPG Key ID: 954589B18A21D5B6

View File

@ -1,6 +1,9 @@
package chip8
import "encoding/binary"
import (
"encoding/binary"
"math"
)
const (
MemorySize = 4096 // 4KB of memory
@ -45,6 +48,9 @@ func (emulator *Emulator) Reset() {
}
func (emulator *Emulator) Step() {
emulator.Timer.Delay = uint8(math.Max(0, float64(emulator.Timer.Delay)-1))
emulator.Timer.Sound = uint8(math.Max(0, float64(emulator.Timer.Sound)-1))
instruction := binary.BigEndian.Uint16(emulator.Memory[emulator.PC:])
switch instruction & 0xF000 {