izapple2/apple2Setup.go

286 lines
6.6 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"
"github.com/ivanizag/iz6502"
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 = iz6502.NewNMOS6502(a.mmu)
2020-08-30 19:11:43 +00:00
addApple2SoftSwitches(a.io)
}
func setApple2e(a *Apple2) {
a.Name = "Apple IIe"
a.isApple2e = true
a.cpu = iz6502.NewNMOS6502(a.mmu)
2020-08-30 19:11:43 +00:00
a.mmu.initExtendedRAM(1)
addApple2SoftSwitches(a.io)
addApple2ESoftSwitches(a.io)
}
func setApple2eEnhanced(a *Apple2) {
a.Name = "Apple //e"
a.isApple2e = true
a.cpu = iz6502.NewCMOS65c02(a.mmu)
2020-08-30 19:11:43 +00:00
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 {
2022-01-28 18:25:52 +00:00
data, _, err := LoadResource(filename)
2019-10-05 23:26:00 +00:00
if err != nil {
return err
}
size := len(data)
if size != apple2RomSize && size != apple2eRomSize {
2021-08-05 19:12:52 +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
2022-02-25 23:05:09 +00:00
func (a *Apple2) AddDisk2(slot int, diskImage, diskBImage string, trackTracer trackTracer) error {
c := NewCardDisk2(trackTracer)
2020-10-14 19:54:51 +00:00
a.insertCard(c, slot)
if diskImage != "" {
2022-01-28 18:25:52 +00:00
diskette, err := 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 != "" {
2022-01-28 18:25:52 +00:00
diskette, err := 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
2022-02-25 23:05:09 +00:00
func (a *Apple2) AddDisk2Sequencer(slot int, diskImage, diskBImage string, trackTracer trackTracer) error {
c := NewCardDisk2Sequencer(trackTracer)
2021-05-09 17:48:54 +00:00
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
2022-10-24 21:09:06 +00:00
func (a *Apple2) AddSmartPortDisk(slot int, hdImage string, traceHD bool, traceSP bool) error {
c := NewCardSmartPort()
c.trace = traceSP
2020-10-13 22:26:47 +00:00
a.insertCard(c, slot)
2022-10-24 21:09:06 +00:00
err := c.LoadImage(hdImage, traceHD)
return err
2019-10-02 21:39:39 +00:00
}
2022-10-24 21:09:06 +00:00
// AddSmartPortDisk adds a smart port card and image
func (a *Apple2) AddFujinet(slot int, trace bool) {
c := NewCardSmartPort()
c.trace = trace
a.insertCard(c, slot)
2022-11-01 15:57:45 +00:00
net := NewSmartPortFujinetNetwork(c)
net.trace = trace
c.AddDevice(net)
clock := NewSmartPortFujinetClock(c)
clock.trace = trace
c.AddDevice(clock)
2022-10-24 21:09:06 +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)
}
// AddParallelPrinter inserts an Apple II Parallel Printer card
func (a *Apple2) AddParallelPrinter(slot int) {
a.insertCard(NewCardParallelPrinter(), 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)
}
2022-03-08 19:11:26 +00:00
// AddSwyftCard inserts a Swyft card in slot 3
func (a *Apple2) AddSwyftCard() {
c := NewCardSwyft()
a.insertCard(c, 3)
}
// 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
2021-10-12 10:26:40 +00:00
func (a *Apple2) AddRomX() error {
rx, err := newRomX(a, a.mmu)
if err != nil {
return err
}
2020-10-24 22:22:52 +00:00
a.cpu.SetMemory(rx)
2021-10-12 10:26:40 +00:00
return nil
2020-10-24 22:22:52 +00:00
}
// 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 {
2021-08-05 19:12:52 +00:00
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)
}