mirror of
https://github.com/ivanizag/izapple2.git
synced 2024-11-20 00:32:05 +00:00
41 lines
766 B
Go
41 lines
766 B
Go
package apple2
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"io"
|
|
)
|
|
|
|
type memoryRange struct {
|
|
base uint16
|
|
data []uint8
|
|
}
|
|
|
|
func newMemoryRange(base uint16, data []uint8) *memoryRange {
|
|
var m memoryRange
|
|
m.base = base
|
|
m.data = data
|
|
return &m
|
|
}
|
|
|
|
func (m *memoryRange) peek(address uint16) uint8 {
|
|
return m.data[address-m.base]
|
|
}
|
|
|
|
func (m *memoryRange) poke(address uint16, value uint8) {
|
|
m.data[address-m.base] = value
|
|
}
|
|
|
|
func (m *memoryRange) subRange(a, b uint16) []uint8 {
|
|
return m.data[a-m.base : b-m.base]
|
|
}
|
|
|
|
func (m *memoryRange) save(w io.Writer) {
|
|
binary.Write(w, binary.BigEndian, m.base)
|
|
binary.Write(w, binary.BigEndian, m.data)
|
|
}
|
|
|
|
func (m *memoryRange) load(r io.Reader) {
|
|
binary.Read(r, binary.BigEndian, &m.base)
|
|
binary.Read(r, binary.BigEndian, &m.data)
|
|
}
|