izapple2/cardFastChip.go

98 lines
2.2 KiB
Go
Raw Normal View History

2020-10-03 21:38:26 +00:00
package izapple2
2019-11-12 22:47:48 +00:00
/*
Simulates just what is needed to make Total Replay use fast mode. Can change
from controlled speed to max speed the emulator can do.
Note: It ends up not being useful for Total Replay as loading from HD is already
very fast. HD blocks are loaded directly on the emulated RAM.
Note that it doesn't intefere with the Apple IIe 80 columns in slot 3. It doesn't
have ROM or slot specific sofswitches.
2019-11-12 22:47:48 +00:00
See:
https://github.com/a2-4am/4cade/blob/master/src/hw.accel.a
http://www.a2heaven.com/webshop/resources/pdf_document/18/82/c.pdf
*/
2020-10-14 19:54:51 +00:00
// CardFastChip represents a
type CardFastChip struct {
2019-11-12 22:47:48 +00:00
cardBase
2020-04-02 19:50:01 +00:00
unlocked bool
unlockCounter uint8
enabled bool
accelerated bool
configRegister uint8
2019-11-12 22:47:48 +00:00
}
2020-10-14 19:54:51 +00:00
// NewCardFastChip creates a new CardFastChip
func NewCardFastChip() *CardFastChip {
var c CardFastChip
c.name = "FASTChip IIe Card - limited"
return &c
}
2019-11-12 22:47:48 +00:00
const (
fastChipUnlockToken = 0x6a
fastChipUnlockRepeats = 4
fastChipNormalSpeed = uint8(9)
)
2020-10-14 19:54:51 +00:00
func (c *CardFastChip) assign(a *Apple2, slot int) {
2019-11-12 22:47:48 +00:00
// The softswitches are outside the card reserved ss
// Only writes are implemented to avoid conflicts with the joysticks
2022-08-05 17:43:17 +00:00
a.io.addSoftSwitchW(0x6a, func(value uint8) {
2019-11-12 22:47:48 +00:00
if value == fastChipUnlockToken {
c.unlockCounter++
if c.unlockCounter >= fastChipUnlockRepeats {
c.unlocked = true
}
} else {
c.unlockCounter = 0
c.unlocked = false
2020-04-02 19:50:01 +00:00
c.enabled = false
2019-11-12 22:47:48 +00:00
}
}, "FASTCHIP-LOCK")
2022-08-05 17:43:17 +00:00
a.io.addSoftSwitchW(0x6b, func(uint8) {
2019-11-12 22:47:48 +00:00
if c.unlocked {
c.enabled = true
}
}, "FASTCHIP-ENABLE")
2022-08-05 17:43:17 +00:00
a.io.addSoftSwitchW(0x6d, func(value uint8) {
2020-04-02 19:50:01 +00:00
if c.enabled {
c.setSpeed(a, value)
2019-11-12 22:47:48 +00:00
}
}, "FASTCHIP-SPEED")
2022-08-05 17:43:17 +00:00
a.io.addSoftSwitchW(0x6e, func(value uint8) {
2020-04-02 19:50:01 +00:00
if c.enabled {
c.configRegister = value
}
}, "FASTCHIP-CONFIG")
2022-08-05 17:43:17 +00:00
a.io.addSoftSwitchW(0x6f, func(value uint8) {
2020-04-02 19:50:01 +00:00
if c.enabled && c.configRegister == 0 {
c.setSpeed(a, value)
}
}, "FASTCHIP-CONFIG")
2019-11-12 22:47:48 +00:00
c.cardBase.assign(a, slot)
}
2020-04-02 19:50:01 +00:00
2020-10-14 19:54:51 +00:00
func (c *CardFastChip) setSpeed(a *Apple2, value uint8) {
2020-04-02 19:50:01 +00:00
newAccelerated := (value > fastChipNormalSpeed)
if newAccelerated == c.accelerated {
// No change requested
return
}
if newAccelerated {
2022-05-10 11:40:17 +00:00
a.RequestFastMode()
2020-04-02 19:50:01 +00:00
} else {
2022-05-10 11:40:17 +00:00
a.ReleaseFastMode()
2020-04-02 19:50:01 +00:00
}
c.accelerated = newAccelerated
}