Skip to content

Commit

Permalink
Merge pull request #5 from maxfierke/mf-debugger
Browse files Browse the repository at this point in the history
Implement a basic interactive debugger
  • Loading branch information
maxfierke authored Sep 8, 2024
2 parents b582311 + a2a47c9 commit f7afbb6
Show file tree
Hide file tree
Showing 8 changed files with 485 additions and 28 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
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 f7afbb6

Please sign in to comment.