izapple2/apple2Setup.go

259 lines
5.9 KiB
Go
Raw Normal View History

2020-10-03 21:38:26 +00:00
package izapple2
2019-10-05 23:26:00 +00:00
import (
"errors"
2020-10-03 21:38:26 +00:00
"github.com/ivanizag/izapple2/core6502"
"github.com/ivanizag/izapple2/storage"
2019-10-05 23:26:00 +00:00
)
2020-08-30 19:11:43 +00:00
func newApple2() *Apple2 {
var a Apple2
2019-10-12 19:37:37 +00:00
2020-08-30 19:11:43 +00:00
a.Name = "Pending"
2019-10-20 22:06:28 +00:00
a.mmu = newMemoryManager(&a)
2019-10-12 19:37:37 +00:00
a.io = newIoC0Page(&a)
return &a
}
2021-04-02 18:39:37 +00:00
func (a *Apple2) setup(clockMhz float64, fastMode bool) {
a.commandChannel = make(chan int, 100)
a.fastMode = fastMode
if clockMhz <= 0 {
// Full speed
a.cycleDurationNs = 0
} else {
a.cycleDurationNs = 1000.0 / clockMhz
}
}
2020-08-30 19:11:43 +00:00
func setApple2plus(a *Apple2) {
a.Name = "Apple ][+"
a.cpu = core6502.NewNMOS6502(a.mmu)
addApple2SoftSwitches(a.io)
}
func setApple2e(a *Apple2) {
a.Name = "Apple IIe"
a.isApple2e = true
a.cpu = core6502.NewNMOS6502(a.mmu)
a.mmu.initExtendedRAM(1)
addApple2SoftSwitches(a.io)
addApple2ESoftSwitches(a.io)
}
func setApple2eEnhanced(a *Apple2) {
a.Name = "Apple //e"
a.isApple2e = true
a.cpu = core6502.NewCMOS65c02(a.mmu)
a.mmu.initExtendedRAM(1)
addApple2SoftSwitches(a.io)
addApple2ESoftSwitches(a.io)
}
2021-04-02 18:39:37 +00:00
func (a *Apple2) addTracer(tracer executionTracer) {
if a.tracers == nil {
a.tracers = make([]executionTracer, 0)
}
a.tracers = append(a.tracers, tracer)
}
2020-10-13 22:26:47 +00:00
func (a *Apple2) insertCard(c Card, slot int) {
2019-05-18 14:43:51 +00:00
c.assign(a, slot)
a.cards[slot] = c
}
2020-10-13 22:26:47 +00:00
// GetCards returns the array of inserted cards
func (a *Apple2) GetCards() [8]Card {
return a.cards
}
const (
apple2RomSize = 12 * 1024
apple2eRomSize = 16 * 1024
)
// LoadRom loads a standard Apple2+ or 2e ROM
2019-10-05 23:26:00 +00:00
func (a *Apple2) LoadRom(filename string) error {
data, _, err := storage.LoadResource(filename)
2019-10-05 23:26:00 +00:00
if err != nil {
return err
}
size := len(data)
if size != apple2RomSize && size != apple2eRomSize {
2019-10-05 23:26:00 +00:00
return errors.New("Rom size not supported")
}
romBase := 0x10000 - size
2020-09-23 16:19:15 +00:00
a.mmu.physicalROM[0] = newMemoryRangeROM(uint16(romBase), data, "Main ROM")
2019-10-05 23:26:00 +00:00
return nil
}
2019-10-02 21:39:39 +00:00
// AddDisk2 inserts a DiskII controller
2020-10-14 19:54:51 +00:00
func (a *Apple2) AddDisk2(slot int, diskImage, diskBImage string) error {
c := NewCardDisk2()
a.insertCard(c, slot)
if diskImage != "" {
diskette, err := storage.LoadDiskette(diskImage)
2019-10-05 23:26:00 +00:00
if err != nil {
return err
}
2020-10-14 19:54:51 +00:00
c.drive[0].insertDiskette(diskImage, diskette)
}
2019-10-05 23:26:00 +00:00
2020-04-12 23:29:04 +00:00
if diskBImage != "" {
diskette, err := storage.LoadDiskette(diskBImage)
2020-04-12 23:29:04 +00:00
if err != nil {
return err
}
2020-10-14 19:54:51 +00:00
c.drive[1].insertDiskette(diskImage, diskette)
2020-04-12 23:29:04 +00:00
}
2019-10-05 23:26:00 +00:00
return nil
}
2021-05-09 17:48:54 +00:00
// AddDisk2 inserts a DiskII controller
func (a *Apple2) AddDisk2Sequencer(slot int, diskImage, diskBImage string) error {
c := NewCardDisk2Sequencer()
a.insertCard(c, slot)
if diskImage != "" {
err := c.drive[0].insertDiskette(diskImage)
if err != nil {
return err
}
}
if diskBImage != "" {
err := c.drive[0].insertDiskette(diskBImage)
if err != nil {
return err
}
}
return nil
}
// AddSmartPortDisk adds a smart port card and image
func (a *Apple2) AddSmartPortDisk(slot int, hdImage string, trace bool) error {
2020-10-13 22:26:47 +00:00
c := NewCardHardDisk()
c.trace = trace
err := c.LoadImage(hdImage)
2019-10-05 23:26:00 +00:00
if err != nil {
return err
}
2020-10-13 22:26:47 +00:00
a.insertCard(c, slot)
2019-10-05 23:26:00 +00:00
return nil
2019-10-02 21:39:39 +00:00
}
// AddVidHD adds a card with the signature of VidHD
func (a *Apple2) AddVidHD(slot int) {
2020-10-14 19:54:51 +00:00
a.insertCard(NewCardVidHD(), slot)
}
2019-11-12 22:47:48 +00:00
// AddFastChip adds a card with the signature of VidHD
func (a *Apple2) AddFastChip(slot int) {
2020-10-14 19:54:51 +00:00
a.insertCard(NewCardFastChip(), slot)
2019-11-12 22:47:48 +00:00
}
// AddLanguageCard inserts a 16Kb card
func (a *Apple2) AddLanguageCard(slot int) {
2020-10-14 19:54:51 +00:00
a.insertCard(NewCardLanguage(), slot)
}
// AddSaturnCard inserts a 128Kb card
func (a *Apple2) AddSaturnCard(slot int) {
2020-10-14 19:54:51 +00:00
a.insertCard(NewCardSaturn(), slot)
}
// AddMemoryExpansionCard inserts an Apple II Memory Expansion card with 1GB
2020-10-14 19:54:51 +00:00
func (a *Apple2) AddMemoryExpansionCard(slot int) {
a.insertCard(NewCardMemoryExpansion(), slot)
}
// AddThunderClockPlusCard inserts a ThunderClock Plus clock card
func (a *Apple2) AddThunderClockPlusCard(slot int) {
a.insertCard(NewCardThunderClockPlus(), slot)
}
2021-01-24 22:25:52 +00:00
// AddMouseCard inserts a Mouse card
func (a *Apple2) AddMouseCard(slot int) {
a.insertCard(NewCardMouse(), slot)
}
// AddVidexCard inserts a Videx card
func (a *Apple2) AddVidexCard(slot int) {
c := NewCardVidex()
a.insertCard(c, slot)
a.softVideoSwitch = NewSoftVideoSwitch(c)
}
// AddRGBCard inserts an RBG option to the Apple IIe 80 col 64KB card
func (a *Apple2) AddRGBCard() {
setupRGBCard(a)
}
// AddRAMWorks inserts adds RAMWorks style RAM to the Apple IIe 80 col 64KB card
func (a *Apple2) AddRAMWorks(banks int) {
setupRAMWorksCard(a, banks)
}
// AddNoSlotClock inserts a DS1215 no slot clock under the main ROM
func (a *Apple2) AddNoSlotClock() {
nsc := newNoSlotClockDS1216(a, a.mmu.physicalROM[0])
a.mmu.physicalROM[0] = nsc
}
2020-10-24 22:22:52 +00:00
// AddRomX inserts a RomX. It intercepts all memory accesses
func (a *Apple2) AddRomX() {
rx := newRomX(a, a.mmu)
a.cpu.SetMemory(rx)
}
// AddNoSlotClockInCard inserts a DS1215 no slot clock under a card ROM
func (a *Apple2) AddNoSlotClockInCard(slot int) error {
cardRom := a.mmu.cardsROM[slot]
if cardRom == nil {
return errors.New("No ROM available on the slot to add a no slot clock")
}
nsc := newNoSlotClockDS1216(a, cardRom)
a.mmu.cardsROM[slot] = nsc
return nil
}
2019-05-18 21:40:59 +00:00
// AddCardLogger inserts a fake card that logs accesses
func (a *Apple2) AddCardLogger(slot int) {
2020-10-14 19:54:51 +00:00
c := NewCardLogger()
a.insertCard(c, slot)
2019-05-18 21:40:59 +00:00
}
// AddCardInOut inserts a fake card that interfaces with the emulator host
func (a *Apple2) AddCardInOut(slot int) {
2020-10-14 19:54:51 +00:00
c := NewCardInOut()
a.insertCard(c, slot)
2019-05-18 21:40:59 +00:00
}
// SetKeyboardProvider attaches an external keyboard provider
func (a *Apple2) SetKeyboardProvider(kb KeyboardProvider) {
a.io.setKeyboardProvider(kb)
}
// SetSpeakerProvider attaches an external keyboard provider
func (a *Apple2) SetSpeakerProvider(s SpeakerProvider) {
a.io.setSpeakerProvider(s)
}
2019-08-05 22:37:27 +00:00
// SetJoysticksProvider attaches an external joysticks provider
func (a *Apple2) SetJoysticksProvider(j JoysticksProvider) {
a.io.setJoysticksProvider(j)
}
2021-01-24 22:25:52 +00:00
// SetMouseProvider attaches an external joysticks provider
func (a *Apple2) SetMouseProvider(m MouseProvider) {
a.io.setMouseProvider(m)
}