Skip to content

Commit

Permalink
Start executing some code!
Browse files Browse the repository at this point in the history
  • Loading branch information
maxfierke committed Dec 19, 2023
1 parent 0fecd70 commit d9fce3e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cpu/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ type CPU struct {
opcodes *isa.Opcodes
}

func (cpu *CPU) Step(mmu *mem.MMU) {
func (cpu *CPU) Step(mmu *mem.MMU) uint8 {
inst := cpu.fetchAndDecode(mmu)
nextPc, _ := cpu.Execute(mmu, inst)
nextPc, cycles := cpu.Execute(mmu, inst)

cpu.PC.Write(nextPc)

return cycles
}

func (cpu *CPU) fetchAndDecode(mmu *mem.MMU) *isa.Instruction {
Expand Down
14 changes: 14 additions & 0 deletions hardware/dmg.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ func NewDMG() (*DMG, error) {
ram := make([]byte, 0xFFFF)
mmu := mem.NewMMU(ram)

cpu.ResetToBootROM() // TODO: Load an actual boot ROOM

return &DMG{
cpu: cpu,
mmu: mmu,
Expand Down Expand Up @@ -55,3 +57,15 @@ func (dmg *DMG) DebugPrint() {
dmg.cartridge.DebugPrint()
}
}

func (dmg *DMG) Step() bool {
dmg.cpu.Step(dmg.mmu)

return true
}

func (dmg *DMG) Run() {
for dmg.Step() {

}
}
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,6 @@ func main() {

log.Println("Loaded cartridge successfully")
dmg.DebugPrint()
dmg.Run()
}
}

0 comments on commit d9fce3e

Please sign in to comment.