Skip to content

Commit 6c66a81

Browse files
committed
Saving progress
1 parent 91bf529 commit 6c66a81

File tree

4 files changed

+37
-10
lines changed

4 files changed

+37
-10
lines changed

cmd/package/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import (
1212
func main() {
1313
gb := system.NewGameBoy()
1414

15-
// romData, err := os.ReadFile("tetris.gb")
15+
romData, err := os.ReadFile("tetris.gb")
1616
// romData, err := os.ReadFile("./tests/blargg/cpu_instrs/cpu_instrs.gb")
17-
romData, err := os.ReadFile("./tests/blargg/instr_timing/instr_timing.gb")
17+
// romData, err := os.ReadFile("./tests/blargg/instr_timing/instr_timing.gb")
1818
// romData, err := os.ReadFile("./tests/blargg/interrupt_time/interrupt_time.gb")
1919
if err != nil {
2020
log.Fatalln(err)

private/processor/cpu/lr35902/lr35902.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,13 @@ func (c *LR35902) MClock() {
9494

9595
c.lastPC = c.registers.PC
9696

97-
if c.registers.PC == 0x29e2 {
97+
if c.registers.PC == 0x29d0 {
98+
if c.registers.A&0b1111 != 0b1111 {
99+
fmt.Printf("")
100+
}
101+
}
102+
103+
if c.registers.PC == 0x03a0 {
98104
fmt.Printf("")
99105
}
100106

private/processor/cpu/lr35902/lr35902_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package lr35902
22

33
import (
44
"testing"
5+
6+
"github.com/colecrouter/gameboy-go/private/processor/cpu"
57
)
68

79
func TestByteLengths(t *testing.T) {
@@ -115,3 +117,22 @@ func TestCyclesCB(t *testing.T) {
115117
})
116118
}
117119
}
120+
121+
func TestJPHL(t *testing.T) {
122+
c, mem, _ := newTestCPU()
123+
jumpTarget := uint16(0x1234)
124+
c.registers.H, c.registers.L = cpu.FromRegisterPair(jumpTarget)
125+
mem.Write(0, 0xE9) // JP (HL) opcode
126+
127+
// Preload clock with enough ticks (assume 1 tick is sufficient)
128+
manualClock := make(chan struct{}, 1)
129+
manualClock <- struct{}{}
130+
close(manualClock)
131+
c.clock = manualClock
132+
133+
c.MClock()
134+
135+
if c.registers.PC != jumpTarget {
136+
t.Errorf("JP (HL) failed: got PC %d, want %d", c.registers.PC, jumpTarget)
137+
}
138+
}

private/system/broadcaster.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func (b *Broadcaster) Subscribe(c ClockType) <-chan struct{} {
3030
return ch
3131
}
3232

33-
func (b *Broadcaster) Broadcast(c ClockType) {
33+
func (b *Broadcaster) broadcast(c ClockType) {
3434
b.mu.Lock()
3535
defer b.mu.Unlock()
3636

@@ -46,14 +46,14 @@ func (b *Broadcaster) Broadcast(c ClockType) {
4646

4747
func (b *Broadcaster) TClock() {
4848
if b.count%4 == 0 {
49-
b.Broadcast(MRisingEdge)
50-
b.Broadcast(TRisingEdge)
49+
b.broadcast(MRisingEdge)
50+
b.broadcast(TRisingEdge)
5151

52-
b.Broadcast(MFallingEdge)
53-
b.Broadcast(TFallingEdge)
52+
b.broadcast(MFallingEdge)
53+
b.broadcast(TFallingEdge)
5454
} else {
55-
b.Broadcast(TRisingEdge)
56-
b.Broadcast(TFallingEdge)
55+
b.broadcast(TRisingEdge)
56+
b.broadcast(TFallingEdge)
5757
}
5858

5959
b.count++

0 commit comments

Comments
 (0)