Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
akatsuki105 committed Oct 28, 2024
1 parent 456aff9 commit 51246c9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
11 changes: 1 addition & 10 deletions core/gb/gb.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,6 @@ const KB, MB = 1024, 1024 * 1024

var buttons = [8]string{"A", "B", "SELECT", "START", "RIGHT", "LEFT", "UP", "DOWN"}

type peripheral interface {
Reset(hasBIOS bool)
Read(addr uint16) uint8
Write(addr uint16, val uint8)

Serialize(state io.Writer)
Deserialize(state io.Reader)
}

type oamDmaController struct {
active bool
src uint16
Expand All @@ -37,7 +28,7 @@ type GB struct {
m *Memory
video *video.Video
cartridge *cartridge.Cartridge
input peripheral
input *input
timer *timer
serial *serial
dmac *dmaController
Expand Down
18 changes: 9 additions & 9 deletions core/gb/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ import (
"github.com/akatsuki105/dawngb/util"
)

type Input struct {
type input struct {
g *GB
p14, p15 bool
joyp uint8
}

func newInput(g *GB) *Input {
return &Input{
func newInput(g *GB) *input {
return &input{
g: g,
}
}

func (i *Input) Reset(hasBIOS bool) {
func (i *input) Reset(hasBIOS bool) {
i.p14, i.p15 = false, false
i.joyp = 0x0F
if !hasBIOS {
Expand All @@ -27,7 +27,7 @@ func (i *Input) Reset(hasBIOS bool) {
}
}

func (i *Input) poll() {
func (i *input) poll() {
dpad := uint8(0x0)
dpad = util.SetBit(dpad, 0, !i.g.inputs[4+0])
dpad = util.SetBit(dpad, 1, !i.g.inputs[4+1])
Expand All @@ -53,7 +53,7 @@ func (i *Input) poll() {
}
}

func (i *Input) Read(addr uint16) uint8 {
func (i *input) Read(addr uint16) uint8 {
i.poll()
val := i.joyp
val = util.SetBit(val, 4, i.p14)
Expand All @@ -68,16 +68,16 @@ func (i *Input) Read(addr uint16) uint8 {
return val
}

func (i *Input) Write(addr uint16, val uint8) {
func (i *input) Write(addr uint16, val uint8) {
i.p14 = util.Bit(val, 4)
i.p15 = util.Bit(val, 5)
}

func (i *Input) Serialize(s io.Writer) {
func (i *input) Serialize(s io.Writer) {
s.Write([]byte{util.Btou8(i.p14), util.Btou8(i.p15), i.joyp})
}

func (i *Input) Deserialize(s io.Reader) {
func (i *input) Deserialize(s io.Reader) {
buf := make([]byte, 3)
s.Read(buf)
i.p14, i.p15 = buf[0] != 0, buf[1] != 0
Expand Down

0 comments on commit 51246c9

Please sign in to comment.