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 {
|
2019-09-28 11:37:42 +00:00
|
|
|
a *Apple2
|
|
|
|
rom *memoryRange
|
|
|
|
romExtra *memoryRange
|
|
|
|
slot int
|
2019-10-20 22:00:42 +00:00
|
|
|
_ssr [16]softSwitchR
|
|
|
|
_ssw [16]softSwitchW
|
|
|
|
_ssrName [16]string
|
|
|
|
_sswName [16]string
|
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 {
|
2019-10-05 23:26:00 +00:00
|
|
|
panic("Assert failed. Rom must be loaded before inserting the card in the slot")
|
2019-05-18 14:43:51 +00:00
|
|
|
}
|
2019-09-28 11:37:42 +00:00
|
|
|
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) {
|
2019-05-10 16:07:36 +00:00
|
|
|
c.a = a
|
2019-03-02 19:41:25 +00:00
|
|
|
c.slot = slot
|
2019-05-16 20:51:04 +00:00
|
|
|
if slot != 0 && c.rom != nil {
|
2019-05-16 20:55:19 +00:00
|
|
|
c.rom.base = uint16(0xc000 + slot*0x100)
|
2019-11-03 17:22:10 +00:00
|
|
|
a.mmu.setCardROM(slot, c.rom)
|
2019-03-02 19:41:25 +00:00
|
|
|
}
|
|
|
|
|
2019-09-28 11:37:42 +00:00
|
|
|
if slot != 0 && c.romExtra != nil {
|
|
|
|
c.romExtra.base = uint16(0xc800)
|
2019-11-03 17:22:10 +00:00
|
|
|
a.mmu.setCardROMExtra(slot, c.romExtra)
|
2019-09-28 11:37:42 +00:00
|
|
|
}
|
|
|
|
|
2019-03-02 19:41:25 +00:00
|
|
|
for i := 0; i < 0x10; i++ {
|
2019-10-20 22:00:42 +00:00
|
|
|
a.io.addSoftSwitchR(uint8(0xC80+slot*0x10+i), c._ssr[i], c._ssrName[i])
|
|
|
|
a.io.addSoftSwitchW(uint8(0xC80+slot*0x10+i), c._ssw[i], c._sswName[i])
|
2019-03-02 19:41:25 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-18 14:43:51 +00:00
|
|
|
|
2019-10-20 22:00:42 +00:00
|
|
|
func (c *cardBase) addCardSoftSwitchR(address uint8, ss softSwitchR, name string) {
|
|
|
|
c._ssr[address] = ss
|
|
|
|
c._ssrName[address] = name
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *cardBase) addCardSoftSwitchW(address uint8, ss softSwitchW, name string) {
|
|
|
|
c._ssw[address] = ss
|
|
|
|
c._sswName[address] = name
|
|
|
|
}
|
|
|
|
|
2019-10-05 23:26:00 +00:00
|
|
|
func (c *cardBase) save(w io.Writer) error {
|
2019-05-18 14:43:51 +00:00
|
|
|
// Empty
|
2019-10-05 23:26:00 +00:00
|
|
|
return nil
|
2019-05-18 14:43:51 +00:00
|
|
|
}
|
|
|
|
|
2019-10-05 23:26:00 +00:00
|
|
|
func (c *cardBase) load(r io.Reader) error {
|
2019-05-18 14:43:51 +00:00
|
|
|
// Empty
|
2019-10-05 23:26:00 +00:00
|
|
|
return nil
|
2019-05-18 14:43:51 +00:00
|
|
|
}
|