2020-10-03 21:38:26 +00:00
|
|
|
package izapple2
|
2019-05-17 07:54:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
RAM card with 128Kb. It's like 8 language cards.
|
|
|
|
|
2020-08-13 14:50:48 +00:00
|
|
|
See:
|
|
|
|
http://www.applelogic.org/files/SATURN128MAN.pdf
|
2019-05-17 07:54:49 +00:00
|
|
|
*/
|
|
|
|
|
2020-10-14 19:54:51 +00:00
|
|
|
// CardSaturn is a Saturn128 card
|
|
|
|
type CardSaturn struct {
|
2019-05-17 07:54:49 +00:00
|
|
|
cardBase
|
|
|
|
readState bool
|
2019-10-20 22:00:42 +00:00
|
|
|
writeState uint8
|
2019-11-03 17:22:10 +00:00
|
|
|
altBank bool
|
2019-10-20 22:00:42 +00:00
|
|
|
activeBlock uint8
|
2019-05-17 07:54:49 +00:00
|
|
|
}
|
|
|
|
|
2020-10-14 19:54:51 +00:00
|
|
|
// NewCardSaturn creates a new CardSaturn
|
|
|
|
func NewCardSaturn() *CardSaturn {
|
|
|
|
var c CardSaturn
|
|
|
|
c.name = "Saturn 128KB Ram Card"
|
|
|
|
return &c
|
|
|
|
}
|
|
|
|
|
2019-05-17 21:28:20 +00:00
|
|
|
const (
|
|
|
|
saturnBlocks = 8
|
|
|
|
)
|
|
|
|
|
2020-10-14 19:54:51 +00:00
|
|
|
func (c *CardSaturn) assign(a *Apple2, slot int) {
|
2019-05-17 07:54:49 +00:00
|
|
|
c.readState = false
|
|
|
|
c.writeState = lcWriteEnabled
|
2019-11-03 17:22:10 +00:00
|
|
|
c.altBank = true
|
|
|
|
c.activeBlock = 0
|
|
|
|
a.mmu.initLanguageRAM(saturnBlocks)
|
2019-05-17 07:54:49 +00:00
|
|
|
|
2021-05-09 17:48:54 +00:00
|
|
|
// TODO: use addCardSoftSwitches()
|
2019-10-20 22:00:42 +00:00
|
|
|
for i := uint8(0x0); i <= 0xf; i++ {
|
2019-05-17 07:54:49 +00:00
|
|
|
iCopy := i
|
2019-10-20 22:00:42 +00:00
|
|
|
c.addCardSoftSwitchR(iCopy, func(*ioC0Page) uint8 {
|
2020-04-04 18:15:32 +00:00
|
|
|
c.ssAction(iCopy)
|
2019-05-17 07:54:49 +00:00
|
|
|
return 0
|
2019-10-20 22:00:42 +00:00
|
|
|
}, "SATURNR")
|
|
|
|
c.addCardSoftSwitchW(iCopy, func(*ioC0Page, uint8) {
|
2020-04-04 18:15:32 +00:00
|
|
|
c.ssAction(iCopy)
|
2019-10-20 22:00:42 +00:00
|
|
|
}, "SATURNW")
|
2019-05-17 07:54:49 +00:00
|
|
|
}
|
2019-05-18 14:43:51 +00:00
|
|
|
c.cardBase.assign(a, slot)
|
|
|
|
c.applyState()
|
2019-05-17 07:54:49 +00:00
|
|
|
}
|
|
|
|
|
2020-10-14 19:54:51 +00:00
|
|
|
func (c *CardSaturn) ssAction(ss uint8) {
|
2019-05-17 07:54:49 +00:00
|
|
|
switch ss {
|
|
|
|
case 0:
|
|
|
|
// RAM read, no writes
|
2019-11-03 17:22:10 +00:00
|
|
|
c.altBank = false
|
2019-05-17 07:54:49 +00:00
|
|
|
c.readState = true
|
|
|
|
c.writeState = lcWriteDisabled
|
|
|
|
case 1:
|
|
|
|
// ROM read, RAM write
|
2019-11-03 17:22:10 +00:00
|
|
|
c.altBank = false
|
2019-05-17 07:54:49 +00:00
|
|
|
c.readState = false
|
|
|
|
c.writeState++
|
|
|
|
case 2:
|
|
|
|
// ROM read, no writes
|
2019-11-03 17:22:10 +00:00
|
|
|
c.altBank = false
|
2019-05-17 07:54:49 +00:00
|
|
|
c.readState = false
|
|
|
|
c.writeState = lcWriteDisabled
|
|
|
|
case 3:
|
|
|
|
//RAM read, RAM write
|
2019-11-03 17:22:10 +00:00
|
|
|
c.altBank = false
|
2019-05-17 07:54:49 +00:00
|
|
|
c.readState = true
|
|
|
|
c.writeState++
|
|
|
|
case 4:
|
|
|
|
c.activeBlock = 0
|
|
|
|
case 5:
|
|
|
|
c.activeBlock = 1
|
|
|
|
case 6:
|
|
|
|
c.activeBlock = 2
|
|
|
|
case 7:
|
|
|
|
c.activeBlock = 3
|
|
|
|
case 8:
|
|
|
|
// RAM read, no writes
|
2019-11-03 17:22:10 +00:00
|
|
|
c.altBank = true
|
2019-05-17 07:54:49 +00:00
|
|
|
c.readState = true
|
|
|
|
c.writeState = lcWriteDisabled
|
|
|
|
case 9:
|
|
|
|
// ROM read, RAM write
|
2019-11-03 17:22:10 +00:00
|
|
|
c.altBank = true
|
2019-05-17 07:54:49 +00:00
|
|
|
c.readState = false
|
|
|
|
c.writeState++
|
|
|
|
case 10:
|
|
|
|
// ROM read, no writes
|
2019-11-03 17:22:10 +00:00
|
|
|
c.altBank = true
|
2019-05-17 07:54:49 +00:00
|
|
|
c.readState = false
|
|
|
|
c.writeState = lcWriteDisabled
|
|
|
|
case 11:
|
|
|
|
//RAM read, RAM write
|
2019-11-03 17:22:10 +00:00
|
|
|
c.altBank = true
|
2019-05-17 07:54:49 +00:00
|
|
|
c.readState = true
|
|
|
|
c.writeState++
|
|
|
|
case 12:
|
2019-05-17 21:28:20 +00:00
|
|
|
c.activeBlock = 4
|
2019-05-17 07:54:49 +00:00
|
|
|
case 13:
|
2019-05-17 21:28:20 +00:00
|
|
|
c.activeBlock = 5
|
2019-05-17 07:54:49 +00:00
|
|
|
case 14:
|
2019-05-17 21:28:20 +00:00
|
|
|
c.activeBlock = 6
|
2019-05-17 07:54:49 +00:00
|
|
|
case 15:
|
2019-05-17 21:28:20 +00:00
|
|
|
c.activeBlock = 7
|
2019-05-17 07:54:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if c.writeState > lcWriteEnabled {
|
|
|
|
c.writeState = lcWriteEnabled
|
|
|
|
}
|
|
|
|
|
|
|
|
c.applyState()
|
|
|
|
}
|
|
|
|
|
2020-10-14 19:54:51 +00:00
|
|
|
func (c *CardSaturn) applyState() {
|
2020-08-10 18:52:17 +00:00
|
|
|
c.a.mmu.setLanguageRAMActiveBlock(c.activeBlock)
|
2019-11-03 17:22:10 +00:00
|
|
|
c.a.mmu.setLanguageRAM(c.readState, c.writeState == lcWriteEnabled, c.altBank)
|
2019-05-17 21:28:20 +00:00
|
|
|
}
|