From 20d9b2ed10986e10d86357b459586e122b5a06b2 Mon Sep 17 00:00:00 2001 From: Ivan Izaguirre Date: Tue, 12 Nov 2019 23:47:48 +0100 Subject: [PATCH] Partial FASTChip emulation. --- README.md | 1 + apple2Setup.go | 7 +++++ apple2main.go | 17 ++++++++---- cardFastChip.go | 72 +++++++++++++++++++++++++++++++++++++++++++++++++ cardVidHD.go | 2 +- 5 files changed, 93 insertions(+), 6 deletions(-) create mode 100644 cardFastChip.go diff --git a/README.md b/README.md index d72b559..6bab768 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ Portable emulator of an Apple II+ or //e. Written in Go. - Bootable hard disk card - Apple //e 80 columns with 64Kb extra RAM - VidHd, limited to the ROM signature and SHR as used by Total Replay + - FASTChip, limited to what Total Replay needs to set and clear fast mode - Graphic modes: - Text 40 columns - text 80 columns (Apple //e only) diff --git a/apple2Setup.go b/apple2Setup.go index 0aa0072..735b31e 100644 --- a/apple2Setup.go +++ b/apple2Setup.go @@ -137,6 +137,13 @@ func (a *Apple2) AddVidHD(slot int) { a.insertCard(&c, slot) } +// AddFastChip adds a card with the signature of VidHD +func (a *Apple2) AddFastChip(slot int) { + var c cardFastChip + c.loadRom(buildFastChipRom()) + a.insertCard(&c, slot) +} + // AddLanguageCard inserts a 16Kb card func (a *Apple2) AddLanguageCard(slot int) { a.insertCard(&cardLanguage{}, slot) diff --git a/apple2main.go b/apple2main.go index 95a8b20..f504b2c 100644 --- a/apple2main.go +++ b/apple2main.go @@ -49,14 +49,18 @@ func MainApple() *Apple2 { "saturnCardSlot", -1, "slot for the 256kb Saturn card. -1 for none") - thunderClockCardSlot := flag.Int( - "thunderClockCardSlot", - 4, - "slot for the ThunderClock Plus card. -1 for none") vidHDCardSlot := flag.Int( "vidHDSlot", 2, "slot for the VidHD card, -1 for none") + fastChipCardSlot := flag.Int( + "fastChipSlot", + 3, + "slot for the FASTChip accelerator card, -1 for none") + thunderClockCardSlot := flag.Int( + "thunderClockCardSlot", + 4, + "slot for the ThunderClock Plus card. -1 for none") mono := flag.Bool( "mono", false, @@ -185,9 +189,12 @@ func MainApple() *Apple2 { panic(err) } } - if *vidHDCardSlot > 0 { + if *vidHDCardSlot >= 0 { a.AddVidHD(*vidHDCardSlot) } + if *fastChipCardSlot >= 0 { + a.AddFastChip(*fastChipCardSlot) + } if *disk2Slot > 0 { err := a.AddDisk2(*disk2Slot, *disk2RomFile, *diskImage) if err != nil { diff --git a/cardFastChip.go b/cardFastChip.go new file mode 100644 index 0000000..23415b4 --- /dev/null +++ b/cardFastChip.go @@ -0,0 +1,72 @@ +package apple2 + +/* +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. + +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 + +*/ + +type cardFastChip struct { + cardBase + unlocked bool + unlockCounter uint8 + enabled bool + accelerated bool +} + +func buildFastChipRom() []uint8 { + data := make([]uint8, 256) + return data +} + +const ( + fastChipUnlockToken = 0x6a + fastChipUnlockRepeats = 4 + fastChipNormalSpeed = uint8(9) +) + +func (c *cardFastChip) assign(a *Apple2, slot int) { + // The softswitches are outside the card reserved ss + // Only writes are implemented to avoid conflicts with the joysticks + a.io.addSoftSwitchW(0x6a, func(_ *ioC0Page, value uint8) { + if value == fastChipUnlockToken { + c.unlockCounter++ + if c.unlockCounter >= fastChipUnlockRepeats { + c.unlocked = true + } + } else { + c.unlockCounter = 0 + c.unlocked = false + } + }, "FASTCHIP-LOCK") + + a.io.addSoftSwitchW(0x6b, func(_ *ioC0Page, _ uint8) { + if c.unlocked { + c.enabled = true + } + }, "FASTCHIP-ENABLE") + + a.io.addSoftSwitchW(0x6d, func(_ *ioC0Page, value uint8) { + if c.unlocked && c.enabled { + newAccelerated := (value > fastChipNormalSpeed) + if newAccelerated == c.accelerated { + // No change requested + return + } + if newAccelerated { + a.requestFastMode() + } else { + a.releaseFastMode() + } + c.accelerated = newAccelerated + } + }, "FASTCHIP-SPEED") + + c.cardBase.assign(a, slot) +} diff --git a/cardVidHD.go b/cardVidHD.go index 7658003..f262fae 100644 --- a/cardVidHD.go +++ b/cardVidHD.go @@ -27,7 +27,7 @@ const ( ) func (c *cardVidHD) assign(a *Apple2, slot int) { - // The softswitches are outside the card reverded ss + // The softswitches are outside the card reserved ss a.io.addSoftSwitchR(0x22, notImplementedSoftSwitchR, "VIDHD-TBCOLOR") a.io.addSoftSwitchW(0x22, notImplementedSoftSwitchW, "VIDHD-TBCOLOR") a.io.addSoftSwitchR(0x29, getStatusSoftSwitch(ioDataNewVideo), "VIDHD-NEWVIDEO")