izapple2/core6502/memory.go

44 lines
995 B
Go
Raw Normal View History

package core6502
2019-01-26 16:05:51 +00:00
2019-05-15 14:01:04 +00:00
import "io/ioutil"
2019-02-09 23:15:14 +00:00
// Memory represents the addressable space of the processor
type Memory interface {
Peek(address uint16) uint8
Poke(address uint16, value uint8)
}
func getWord(m Memory, address uint16) uint16 {
return uint16(m.Peek(address)) + 0x100*uint16(m.Peek(address+1))
}
func getZeroPageWord(m Memory, address uint8) uint16 {
return uint16(m.Peek(uint16(address))) + 0x100*uint16(m.Peek(uint16(address+1)))
}
2019-05-15 14:01:04 +00:00
// FlatMemory puts RAM on the 64Kb addressable by the processor
type FlatMemory struct {
data [65536]uint8
}
// Peek returns the data on the given address
func (m *FlatMemory) Peek(address uint16) uint8 {
return m.data[address]
}
// Poke sets the data at the given address
func (m *FlatMemory) Poke(address uint16, value uint8) {
m.data[address] = value
}
2019-02-09 23:15:14 +00:00
func (m *FlatMemory) loadBinary(filename string) {
2019-05-15 14:01:04 +00:00
bytes, err := ioutil.ReadFile(filename)
2019-02-09 23:15:14 +00:00
if err != nil {
panic(err)
}
for i, v := range bytes {
m.Poke(uint16(i), uint8(v))
2019-02-09 23:15:14 +00:00
}
}