Skip to content

Commit

Permalink
Pass all timer test (akatsuki105#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
akatsuki105 authored Jul 20, 2020
1 parent ddc3d42 commit 274b93c
Show file tree
Hide file tree
Showing 13 changed files with 148 additions and 49 deletions.
3 changes: 2 additions & 1 deletion README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Go言語で書かれたゲームボーイカラーエミュレータです。

ほぼ全てのROMが問題なく動作し、サウンド機能やセーブ機能、一部通信機能など幅広い機能を備えたエミュレータです。

<img src="https://imgur.com/rCduRUc.gif">
<img src="https://imgur.com/RrOKzJB.png" width="320px"> <img src="https://imgur.com/yIIlkKq.png" width="320px"><br/>
<img src="https://imgur.com/02YAzow.png" width="320px"> <img src="https://imgur.com/QCXeV3B.png" width="320px">

## 🚩 このエミュレータの特徴 & 今後実装予定の機能
- [x] 60fpsで動作
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ GameBoyColor emulator written in golang.
This emulator can play almost all ROMs work without problems and has many features.


<img src="https://imgur.com/rCduRUc.gif">
<img src="https://imgur.com/RrOKzJB.png" width="320px"> <img src="https://imgur.com/yIIlkKq.png" width="320px"><br/>
<img src="https://imgur.com/02YAzow.png" width="320px"> <img src="https://imgur.com/QCXeV3B.png" width="320px">


## 🚩 Features & TODO list
- [x] 60fps
Expand Down
18 changes: 18 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,18 @@ TEST22=mooneye-gb/halt_ime0_ei/
TEST23=mooneye-gb/halt_ime1_timing/

TIM_TEST0=mooneye-gb/timer/div_write/
TIM_TEST1=mooneye-gb/timer/rapid_toggle/
TIM_TEST2=mooneye-gb/timer/tim00/
TIM_TEST3=mooneye-gb/timer/tim00_div_trigger/
TIM_TEST4=mooneye-gb/timer/tim01/
TIM_TEST5=mooneye-gb/timer/tim01_div_trigger/
TIM_TEST6=mooneye-gb/timer/tim10/
TIM_TEST7=mooneye-gb/timer/tim10_div_trigger/
TIM_TEST8=mooneye-gb/timer/tim11/
TIM_TEST9=mooneye-gb/timer/tim11_div_trigger/
TIM_TEST10=mooneye-gb/timer/tima_reload/
TIM_TEST11=mooneye-gb/timer/tima_write_reloading/
TIM_TEST12=mooneye-gb/timer/tma_write_reloading/

define compare
go run ./cmd/ --test="./test/$1actual.jpg" ./test/$1rom.gb
Expand Down Expand Up @@ -115,17 +121,29 @@ test:
.SILENT:
timer-test:
-$(call compare,$(TIM_TEST0))
-$(call compare,$(TIM_TEST1))
-$(call compare,$(TIM_TEST2))
-$(call compare,$(TIM_TEST3))
-$(call compare,$(TIM_TEST4))
-$(call compare,$(TIM_TEST5))
-$(call compare,$(TIM_TEST6))
-$(call compare,$(TIM_TEST7))
-$(call compare,$(TIM_TEST8))
-$(call compare,$(TIM_TEST9))
-$(call compare,$(TIM_TEST10))
-$(call compare,$(TIM_TEST11))
-$(call compare,$(TIM_TEST12))

-rm -f ./test/$(TIM_TEST0)actual.jpg \
./test/$(TIM_TEST1)actual.jpg \
./test/$(TIM_TEST2)actual.jpg \
./test/$(TIM_TEST3)actual.jpg \
./test/$(TIM_TEST4)actual.jpg \
./test/$(TIM_TEST5)actual.jpg \
./test/$(TIM_TEST6)actual.jpg \
./test/$(TIM_TEST7)actual.jpg \
./test/$(TIM_TEST8)actual.jpg \
./test/$(TIM_TEST9)actual.jpg \
./test/$(TIM_TEST10)actual.jpg \
./test/$(TIM_TEST11)actual.jpg \
./test/$(TIM_TEST12)actual.jpg \
24 changes: 13 additions & 11 deletions pkg/emulator/opcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -1509,7 +1509,9 @@ func (cpu *CPU) PREFIXCB(operand1, operand2 int) {
panic(errMsg)
}

cpu.timer(cycle - 1)
if cycle > 1 {
cpu.timer(cycle - 1)
}
} else {
errMsg := fmt.Sprintf("Error: PREFIXCB %s %s", operand1, operand2)
panic(errMsg)
Expand Down Expand Up @@ -1591,7 +1593,7 @@ func (cpu *CPU) RLC(operand1, operand2 int) {
value &= 0xfe
}
cpu.SetMemory8(cpu.Reg.HL, value)
cpu.timer(3)
cpu.timer(2)
} else if operand1 == OPERAND_A && operand2 == OPERAND_NONE {
value = cpu.getAReg()
bit7 = value >> 7
Expand Down Expand Up @@ -1718,7 +1720,7 @@ func (cpu *CPU) RRC(operand1, operand2 int) {
value &= 0x7f
}
cpu.SetMemory8(cpu.Reg.HL, value)
cpu.timer(3)
cpu.timer(2)
} else if operand1 == OPERAND_A && operand2 == OPERAND_NONE {
value = cpu.getAReg()
bit0 = value % 2
Expand Down Expand Up @@ -1858,7 +1860,7 @@ func (cpu *CPU) RL(operand1, operand2 int) {
value &= 0xfe
}
cpu.SetMemory8(cpu.Reg.HL, value)
cpu.timer(3)
cpu.timer(2)
default:
errMsg := fmt.Sprintf("Error: RL %s %s", operand1, operand2)
panic(errMsg)
Expand Down Expand Up @@ -1990,7 +1992,7 @@ func (cpu *CPU) RR(operand1, operand2 int) {
value &= 0x7f
}
cpu.SetMemory8(cpu.Reg.HL, value)
cpu.timer(3)
cpu.timer(2)
default:
errMsg := fmt.Sprintf("Error: RR %s %s", operand1, operand2)
panic(errMsg)
Expand Down Expand Up @@ -2047,7 +2049,7 @@ func (cpu *CPU) SLA(operand1, operand2 int) {
bit7 = value >> 7
value = (value << 1)
cpu.SetMemory8(cpu.Reg.HL, value)
cpu.timer(3)
cpu.timer(2)
} else if operand1 == OPERAND_A && operand2 == OPERAND_NONE {
value = cpu.getAReg()
bit7 = value >> 7
Expand Down Expand Up @@ -2151,7 +2153,7 @@ func (cpu *CPU) SRA(operand1, operand2 int) {
value &= 0x7f
}
cpu.SetMemory8(cpu.Reg.HL, value)
cpu.timer(3)
cpu.timer(2)
} else if operand1 == OPERAND_A && operand2 == OPERAND_NONE {
value = cpu.getAReg()
bit0 = value % 2
Expand Down Expand Up @@ -2227,7 +2229,7 @@ func (cpu *CPU) SWAP(operand1, operand2 int) {
data47 := data >> 4
value = (data03 << 4) | data47
cpu.SetMemory8(cpu.Reg.HL, value)
cpu.timer(3)
cpu.timer(2)
case OPERAND_A:
A := cpu.getAReg()
A03 := A & 0x0f
Expand Down Expand Up @@ -2288,7 +2290,7 @@ func (cpu *CPU) SRL(operand1, operand2 int) {
bit0 = value % 2
value = (value >> 1)
cpu.SetMemory8(cpu.Reg.HL, value)
cpu.timer(3)
cpu.timer(2)
case OPERAND_A:
value = cpu.getAReg()
bit0 = value % 2
Expand Down Expand Up @@ -2412,7 +2414,7 @@ func (cpu *CPU) RES(operand1, operand2 int) {
value := cpu.FetchMemory8(cpu.Reg.HL) & mask
cpu.timer(1)
cpu.SetMemory8(cpu.Reg.HL, value)
cpu.timer(3)
cpu.timer(2)
case OPERAND_A:
mask := ^(byte(1) << targetBit)
A := cpu.getAReg() & mask
Expand Down Expand Up @@ -2474,7 +2476,7 @@ func (cpu *CPU) SET(operand1, operand2 int) {
value := cpu.FetchMemory8(cpu.Reg.HL) | mask
cpu.timer(1)
cpu.SetMemory8(cpu.Reg.HL, value)
cpu.timer(3)
cpu.timer(2)
case OPERAND_A:
mask := byte(1) << targetBit
A := cpu.getAReg() | mask
Expand Down
25 changes: 24 additions & 1 deletion pkg/emulator/ram.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,30 @@ func (cpu *CPU) setIO(addr uint16, value byte) {
}

case addr == DIVIO:
cpu.resetTimer()
cpu.Timer.ResetAll = true

case addr == TIMAIO:
if cpu.TIMAReload.flag {
cpu.TIMAReload.flag = false
cpu.RAM[TIMAIO] = value
} else if cpu.TIMAReload.after {
cpu.RAM[TIMAIO] = cpu.TIMAReload.value
} else {
cpu.RAM[TIMAIO] = value
}

case addr == TMAIO:
if cpu.TIMAReload.flag {
cpu.TIMAReload.value = value
} else if cpu.TIMAReload.after {
cpu.RAM[TIMAIO] = value
}
cpu.RAM[TMAIO] = value

case addr == TACIO:
cpu.Timer.TAC.Change = true
cpu.Timer.TAC.Old = cpu.RAM[TACIO]
cpu.RAM[TACIO] = value

case addr == IFIO:
cpu.RAM[IFIO] = value | 0xe0 // IF[4-7]は常に1
Expand Down
Loading

0 comments on commit 274b93c

Please sign in to comment.