izapple2/cardBase.go

60 lines
1.1 KiB
Go
Raw Normal View History

2019-03-02 19:41:25 +00:00
package apple2
2019-05-18 14:43:51 +00:00
import (
"io"
)
type card interface {
2019-10-02 21:39:39 +00:00
loadRom(data []uint8)
2019-05-18 14:43:51 +00:00
assign(a *Apple2, slot int)
persistent
}
2019-03-02 19:41:25 +00:00
type cardBase struct {
a *Apple2
rom *memoryRange
romExtra *memoryRange
slot int
ssr [16]softSwitchR
ssw [16]softSwitchW
2019-03-02 19:41:25 +00:00
}
2019-10-02 21:39:39 +00:00
func (c *cardBase) loadRom(data []uint8) {
2019-05-18 14:43:51 +00:00
if c.a != nil {
panic("Rom must be loaded before inserting the card in the slot")
}
if len(data) >= 0x100 {
c.rom = newMemoryRange(0, data)
}
if len(data) >= 0x800 {
c.romExtra = newMemoryRange(0, data)
}
2019-05-18 14:43:51 +00:00
}
func (c *cardBase) assign(a *Apple2, slot int) {
c.a = a
2019-03-02 19:41:25 +00:00
c.slot = slot
if slot != 0 && c.rom != nil {
2019-05-16 20:55:19 +00:00
c.rom.base = uint16(0xc000 + slot*0x100)
a.mmu.setPagesRead(uint8(0xc0+slot), uint8(0xc0+slot), c.rom)
2019-03-02 19:41:25 +00:00
}
if slot != 0 && c.romExtra != nil {
c.romExtra.base = uint16(0xc800)
a.mmu.prepareCardExtraRom(slot, c.romExtra)
}
2019-03-02 19:41:25 +00:00
for i := 0; i < 0x10; i++ {
a.io.addSoftSwitchR(uint8(0xC80+slot*0x10+i), c.ssr[i])
a.io.addSoftSwitchW(uint8(0xC80+slot*0x10+i), c.ssw[i])
}
}
2019-05-18 14:43:51 +00:00
func (c *cardBase) save(w io.Writer) {
// Empty
}
func (c *cardBase) load(r io.Reader) {
// Empty
}