-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
"cSpell.words": [ | ||
"bdizc", | ||
"NMOS", | ||
"NROM", | ||
"toggleable" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package mm | ||
|
||
import "xubiod/6502-experiment/cpu" | ||
|
||
type MemMapper interface { | ||
SwapCpu(on *cpu.Core) bool | ||
StepCpu(along *cpu.Core) bool | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package mm | ||
|
||
import "xubiod/6502-experiment/cpu" | ||
|
||
// https://www.nesdev.org/wiki/NROM | ||
type MemMapperNROM128 struct { | ||
PrgRam []byte | ||
PrgRom0 [0x4000]byte | ||
} | ||
|
||
func (m *MemMapperNROM128) SwapCpu(on *cpu.Core) bool { | ||
copy(on.Memory[0x8000:0xC000], m.PrgRom0[:]) | ||
copy(on.Memory[0xC000:], m.PrgRom0[:]) | ||
return true | ||
} | ||
|
||
func (*MemMapperNROM128) StepCpu(along *cpu.Core) bool { return true } | ||
|
||
// https://www.nesdev.org/wiki/NROM | ||
type MemMapperNROM256 struct { | ||
PrgRam []byte | ||
PrgRom0 [0x4000]byte | ||
PrgRom1 [0x4000]byte | ||
} | ||
|
||
func (m *MemMapperNROM256) SwapCpu(on *cpu.Core) bool { | ||
copy(on.Memory[0x8000:0xC000], m.PrgRom0[:]) | ||
copy(on.Memory[0xC000:], m.PrgRom1[:]) | ||
return true | ||
} | ||
|
||
func (*MemMapperNROM256) StepCpu(along *cpu.Core) bool { return true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,34 @@ | ||
package experiment | ||
|
||
import ( | ||
"errors" | ||
"xubiod/6502-experiment/cpu" | ||
"xubiod/6502-experiment/mm" | ||
) | ||
|
||
// A Runner has a CPU Core (cpu.Core) and a memory mapper (an implementation of | ||
// mm.MemMapper) and runs them together in such a way to ensure they are synced | ||
// together. | ||
type Runner struct { | ||
CPU *cpu.Core // The CPU core to use | ||
MemMapper *mm.MemMapper // The memory manager implementation to use | ||
} | ||
|
||
func New(cpu *cpu.Core, mm *mm.MemMapper) (*Runner, error) { | ||
if cpu == nil { | ||
err := errors.New("core cannot be nil") | ||
return nil, err | ||
} | ||
return &Runner{CPU: cpu, MemMapper: mm}, nil | ||
} | ||
|
||
func (r *Runner) StepOnce() (valid bool) { | ||
if r.CPU != nil { | ||
valid, _, _ = r.CPU.StepOnce() | ||
} | ||
if valid && r.MemMapper != nil { | ||
valid = valid && (*r.MemMapper).StepCpu(r.CPU) | ||
valid = valid && (*r.MemMapper).SwapCpu(r.CPU) | ||
} | ||
return | ||
} |