2020-10-03 21:38:26 +00:00
|
|
|
package izapple2
|
2019-05-16 20:51:04 +00:00
|
|
|
|
2020-09-23 16:19:15 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2019-05-16 20:51:04 +00:00
|
|
|
type memoryRange struct {
|
2021-03-14 17:46:52 +00:00
|
|
|
base uint16
|
|
|
|
data []uint8
|
|
|
|
name string
|
2020-08-14 15:19:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type memoryRangeROM struct {
|
|
|
|
memoryRange
|
2019-05-16 20:51:04 +00:00
|
|
|
}
|
|
|
|
|
2020-09-23 16:19:15 +00:00
|
|
|
func newMemoryRange(base uint16, data []uint8, name string) *memoryRange {
|
2019-05-16 20:51:04 +00:00
|
|
|
var m memoryRange
|
|
|
|
m.base = base
|
|
|
|
m.data = data
|
2020-08-14 15:19:24 +00:00
|
|
|
m.setBase(base)
|
2020-09-23 16:19:15 +00:00
|
|
|
|
|
|
|
m.name = name
|
2020-08-14 15:19:24 +00:00
|
|
|
return &m
|
|
|
|
}
|
|
|
|
|
2020-09-23 16:19:15 +00:00
|
|
|
func newMemoryRangeROM(base uint16, data []uint8, name string) *memoryRangeROM {
|
2020-08-14 15:19:24 +00:00
|
|
|
var m memoryRangeROM
|
|
|
|
m.base = base
|
|
|
|
m.data = data
|
2020-09-23 16:19:15 +00:00
|
|
|
m.name = name
|
2019-05-16 20:51:04 +00:00
|
|
|
return &m
|
|
|
|
}
|
|
|
|
|
2020-08-14 15:19:24 +00:00
|
|
|
func (m *memoryRange) setBase(base uint16) {
|
|
|
|
m.base = base
|
|
|
|
}
|
|
|
|
|
2019-05-16 20:51:04 +00:00
|
|
|
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]
|
|
|
|
}
|
2020-08-14 15:19:24 +00:00
|
|
|
|
|
|
|
func (m *memoryRangeROM) poke(address uint16, value uint8) {
|
|
|
|
// Ignore
|
|
|
|
}
|
2020-09-23 16:19:15 +00:00
|
|
|
|
2021-08-05 19:12:52 +00:00
|
|
|
//lint:ignore U1000 this is used to write debug code
|
2020-09-23 16:19:15 +00:00
|
|
|
func identifyMemory(m memoryHandler) string {
|
|
|
|
ram, ok := m.(*memoryRange)
|
|
|
|
if ok {
|
2021-03-14 17:46:52 +00:00
|
|
|
return fmt.Sprintf("RAM 0x%04x %s", ram.base, ram.name)
|
2020-09-23 16:19:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rom, ok := m.(*memoryRangeROM)
|
|
|
|
if ok {
|
2021-03-14 17:46:52 +00:00
|
|
|
return fmt.Sprintf("ROM 0x%04x %s", rom.base, ram.name)
|
2020-09-23 16:19:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ("Unknown memory")
|
|
|
|
}
|