Skip to content

Commit

Permalink
Merge branch 'main' into mf-load_bootroms
Browse files Browse the repository at this point in the history
  • Loading branch information
maxfierke committed Oct 9, 2024
2 parents 0995a76 + 4cde17b commit 043f1bc
Show file tree
Hide file tree
Showing 9 changed files with 523 additions and 32 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ a gameboy emulator for funsies
- [X] Implement timer
- [X] Pass Blargg's `cpu_instrs`/`02-interrupts.gb` ROM (manually verified)
- [X] Pass Blargg's `instr_timing.gb` ROM (manually verified)
- [X] Implement a basic interactive debugger
- [ ] Pass Blargg's `mem_timing.gb` ROM (manually verified)
- [ ] Implement LCD
- [ ] Implement PPU, VRAM, OAM, etc.
Expand Down
2 changes: 1 addition & 1 deletion cart/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type Reader struct {
// The Reader.Metadata fields will be valid in the Reader returned.
func NewReader(r io.Reader) (*Reader, error) {
cartReader := new(Reader)
if err := cartReader.Reset(r); err == ErrHeader {
if err := cartReader.Reset(r); errors.Is(err, ErrHeader) {
// Pass header checksum errors onto caller and let them handle appropriately
return cartReader, err
} else if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions cpu/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (cpu *CPU) Step(mmu *mem.MMU) (uint8, error) {
return 4, nil
}

inst, err := cpu.fetchAndDecode(mmu)
inst, err := cpu.FetchAndDecode(mmu, cpu.PC.Read())
if err != nil {
return 0, err
}
Expand All @@ -54,9 +54,8 @@ func (cpu *CPU) Step(mmu *mem.MMU) (uint8, error) {
return cycles, err
}

func (cpu *CPU) fetchAndDecode(mmu *mem.MMU) (*isa.Instruction, error) {
func (cpu *CPU) FetchAndDecode(mmu *mem.MMU, addr uint16) (*isa.Instruction, error) {
// Fetch :)
addr := cpu.PC.Read()
opcodeByte := mmu.Read8(addr)
prefixed := opcodeByte == 0xCB

Expand Down
12 changes: 2 additions & 10 deletions cpu/isa/opcodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ func (operand *Operand) String() string {
type Opcode struct {
Addr uint8
CbPrefixed bool
Mnemonic string `json:"mnemonic"`
Comment string
Mnemonic string `json:"mnemonic"`
Bytes int `json:"bytes"`
Cycles []int `json:"cycles"`
Operands []Operand `json:"operands"`
Expand All @@ -60,18 +59,11 @@ func (opcode *Opcode) String() string {
operands = append(operands, operandText)
}

var comment string

if opcode.Comment != "" {
comment = fmt.Sprintf("; %s", opcode.Comment)
}

return fmt.Sprintf(
"0x%02X %s %s %s",
"0x%02X %s %s",
opcode.Addr,
opcode.Mnemonic,
strings.Join(operands, ", "),
comment,
)
}

Expand Down
2 changes: 2 additions & 0 deletions debug/debugger.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ func NewDebugger(name string) (Debugger, error) {
switch name {
case "gameboy-doctor":
return NewGBDoctorDebugger(), nil
case "interactive":
return NewInteractiveDebugger()
case "none":
return NewNullDebugger(), nil
default:
Expand Down
Loading

0 comments on commit 043f1bc

Please sign in to comment.