mirror of
https://github.com/macocianradu/goboy.git
synced 2026-03-18 21:10:07 +00:00
added half carry flags
This commit is contained in:
@@ -6,8 +6,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type op_context struct {
|
type op_context struct {
|
||||||
cpu CPU_struct
|
cpu CPU_struct
|
||||||
addr uint
|
immediate byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func Noop(context op_context) {
|
func Noop(context op_context) {
|
||||||
@@ -16,8 +16,8 @@ func Noop(context op_context) {
|
|||||||
|
|
||||||
// LDBCd16 Load the 2 bytes of immediate data into register pair BC.
|
// LDBCd16 Load the 2 bytes of immediate data into register pair BC.
|
||||||
func LDBCd16(context op_context) {
|
func LDBCd16(context op_context) {
|
||||||
operations.LD(&context.cpu.C, memory.Read8(context.addr))
|
operations.LD(&context.cpu.C, memory.Read8(uint(context.immediate)))
|
||||||
operations.LD(&context.cpu.B, memory.Read8(context.addr+8))
|
operations.LD(&context.cpu.B, memory.Read8(uint(context.immediate)+8))
|
||||||
}
|
}
|
||||||
|
|
||||||
// LDBCa Store the contents of register A in the memory location specified by register pair BC.
|
// LDBCa Store the contents of register A in the memory location specified by register pair BC.
|
||||||
@@ -34,6 +34,11 @@ func INCBC(context op_context) {
|
|||||||
|
|
||||||
// INCB Increment the contents of register B by 1.
|
// INCB Increment the contents of register B by 1.
|
||||||
func INCB(context op_context) {
|
func INCB(context op_context) {
|
||||||
|
if context.cpu.B&0x0F == 0x0F {
|
||||||
|
context.cpu.SetHF(true)
|
||||||
|
} else {
|
||||||
|
context.cpu.SetHF(false)
|
||||||
|
}
|
||||||
operations.INC(&context.cpu.B)
|
operations.INC(&context.cpu.B)
|
||||||
|
|
||||||
context.cpu.SetZF(context.cpu.B == byte(0))
|
context.cpu.SetZF(context.cpu.B == byte(0))
|
||||||
@@ -42,6 +47,11 @@ func INCB(context op_context) {
|
|||||||
|
|
||||||
// DECB Decrement the contents of register B by 1.
|
// DECB Decrement the contents of register B by 1.
|
||||||
func DECB(context op_context) {
|
func DECB(context op_context) {
|
||||||
|
if context.cpu.B&0x0F == 0x00 {
|
||||||
|
context.cpu.SetHF(true)
|
||||||
|
} else {
|
||||||
|
context.cpu.SetHF(false)
|
||||||
|
}
|
||||||
operations.DEC(&context.cpu.B)
|
operations.DEC(&context.cpu.B)
|
||||||
|
|
||||||
context.cpu.SetZF(context.cpu.B == byte(0))
|
context.cpu.SetZF(context.cpu.B == byte(0))
|
||||||
@@ -50,7 +60,7 @@ func DECB(context op_context) {
|
|||||||
|
|
||||||
// LD8B Load the 8-bit immediate operand d8 into register B.
|
// LD8B Load the 8-bit immediate operand d8 into register B.
|
||||||
func LD8B(context op_context) {
|
func LD8B(context op_context) {
|
||||||
operations.LD(&context.cpu.B, memory.Read8(context.addr))
|
operations.LD(&context.cpu.B, memory.Read8(uint(context.immediate)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// RLCA Rotate the contents of register A to the left. The contents of bit 7 are placed in both the CY flag and bit 0 of register A.
|
// RLCA Rotate the contents of register A to the left. The contents of bit 7 are placed in both the CY flag and bit 0 of register A.
|
||||||
@@ -66,5 +76,6 @@ func RLCA(context op_context) {
|
|||||||
|
|
||||||
// LDA16 Store the lower byte of stack pointer SP at the address specified by the 16-bit immediate operand a16, and store the upper byte of SP at address a16 + 1.
|
// LDA16 Store the lower byte of stack pointer SP at the address specified by the 16-bit immediate operand a16, and store the upper byte of SP at address a16 + 1.
|
||||||
func LDA16(context op_context) {
|
func LDA16(context op_context) {
|
||||||
|
operations.LDInMemory8(uint16(context.immediate), operations.GetLowerByte(context.cpu.SP))
|
||||||
|
operations.LDInMemory8(uint16(context.immediate+1), operations.GetHigherByte(context.cpu.SP))
|
||||||
}
|
}
|
||||||
|
|||||||
10
cpu/operations/read_byte.go
Normal file
10
cpu/operations/read_byte.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package operations
|
||||||
|
|
||||||
|
func GetLowerByte(value uint16) byte {
|
||||||
|
return (byte)(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetHigherByte(value uint16) byte {
|
||||||
|
return (byte)(value >> 8)
|
||||||
|
}
|
||||||
|
|
||||||
25
cpu/operations/read_byte_test.go
Normal file
25
cpu/operations/read_byte_test.go
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package operations
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestReadLowerByte(t *testing.T) {
|
||||||
|
SP := uint16(0x1234)
|
||||||
|
|
||||||
|
actual := GetLowerByte(SP)
|
||||||
|
|
||||||
|
if actual != 0x34 {
|
||||||
|
t.Errorf("actual %v != expected %v", actual, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestReadUpperByte(t *testing.T) {
|
||||||
|
SP := uint16(0x1234)
|
||||||
|
|
||||||
|
actual := GetHigherByte(SP)
|
||||||
|
|
||||||
|
if actual != 0x12 {
|
||||||
|
t.Errorf("actual %v != expected %v", actual, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1 +1,5 @@
|
|||||||
[Opcodes Table](https://meganesulli.com/blog/game-boy-opcodes/)
|
[Opcodes Table](https://meganesulli.com/blog/game-boy-opcodes/)
|
||||||
|
[Registers & Flags](https://gbdev.io/pandocs/CPU_Registers_and_Flags.html)
|
||||||
|
|
||||||
|
- run command: go run . roms/rom.gb
|
||||||
|
- test command: go test ./...
|
||||||
|
|||||||
Reference in New Issue
Block a user