2020-10-24 22:22:52 +00:00
|
|
|
package izapple2
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2022-01-28 17:09:59 +00:00
|
|
|
"github.com/ivanizag/iz6502"
|
2020-10-24 22:22:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
/*
|
|
|
|
RomX from https://theromexchange.com/
|
|
|
|
This complement uses the RomX API spec to switch main ROM and character generator ROM
|
|
|
|
|
2021-10-12 10:26:40 +00:00
|
|
|
Only the font switch is implemented
|
|
|
|
|
2020-10-24 22:22:52 +00:00
|
|
|
See:
|
|
|
|
https://theromexchange.com/documentation/ROM%20X%20API%20Reference.pdf
|
|
|
|
https://theromexchange.com/downloads/ROM%20X%2020-10-22.zip
|
2021-10-12 10:26:40 +00:00
|
|
|
https://theromexchange.com/documentation/romxce/ROMXce%20API%20Reference.pdf
|
2020-10-24 22:22:52 +00:00
|
|
|
|
2021-10-12 10:26:40 +00:00
|
|
|
For romX:
|
2020-10-24 22:22:52 +00:00
|
|
|
It is not enough to intercept the ROM accesses. RomX intercept the 74LS138 in
|
|
|
|
position F12, that has access to the full 0xc000-0xf000 on the Apple II+
|
2020-10-27 23:43:33 +00:00
|
|
|
|
|
|
|
Firmware:
|
|
|
|
- It first copies $D000-$DFFF to $6000 and runs there.
|
|
|
|
|
|
|
|
go run *.go -rom ROMX.FIRM.dump -disk ROM\ X\ 20-10-22.dsk
|
|
|
|
|
|
|
|
|
2020-10-24 22:22:52 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
type romX struct {
|
|
|
|
a *Apple2
|
2022-01-28 17:09:59 +00:00
|
|
|
memory iz6502.Memory
|
2020-10-24 22:22:52 +00:00
|
|
|
activationStep int
|
|
|
|
systemBank uint8
|
2021-10-12 10:26:40 +00:00
|
|
|
mainBank uint8
|
|
|
|
tempBank uint8
|
2020-10-24 22:22:52 +00:00
|
|
|
textBank uint8
|
2021-10-12 10:26:40 +00:00
|
|
|
debug bool
|
2020-10-24 22:22:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var romXActivationSequence = []uint16{0xcaca, 0xcaca, 0xcafe}
|
2021-10-12 10:26:40 +00:00
|
|
|
var romXceActivationSequence = []uint16{0xfaca, 0xfaca, 0xfafe}
|
2020-10-24 22:22:52 +00:00
|
|
|
|
|
|
|
const (
|
2021-10-12 10:26:40 +00:00
|
|
|
romxSetupBank = uint8(0)
|
|
|
|
romXPlusSetSystemBankBaseAddress = uint16(0xcef0)
|
|
|
|
romXPlusSetTextBankBaseAddress = uint16(0xcfd0)
|
2020-10-24 22:22:52 +00:00
|
|
|
|
|
|
|
// Unknown
|
2021-10-12 10:26:40 +00:00
|
|
|
//romXFirmwareMark0Address = uint16(0xdffe)
|
|
|
|
//romXFirmwareMark0Value = uint8(0x4a)
|
|
|
|
//romXFirmwareMark1Address = uint16(0xdfff)
|
|
|
|
//romXFirmwareMark1Value = uint8(0xcd)
|
|
|
|
|
|
|
|
romXceSelectTempBank = uint16(0xf850)
|
|
|
|
romXceSelectMainBank = uint16(0xf851)
|
|
|
|
romXceSetTempBank = uint16(0xf830) // 16 positions
|
|
|
|
romXceSetMainBank = uint16(0xf800) // 16 positions
|
|
|
|
romXcePresetTextBank = uint16(0xf810) // 16 positions
|
|
|
|
romXceMCP7940SDC = uint16(0xf860) // 16 positions
|
|
|
|
romXceLowerUpperBanks = uint16(0xf820) // 16 positions
|
|
|
|
|
|
|
|
romXGetDefaultSystemBank = uint16(0xd034) // $00 to $0f
|
|
|
|
romXGetDefaultTextBank = uint16(0xd02e) // $10 to $1f
|
|
|
|
romXGetCurrentBootDelay = uint16(0xdeca) // $00 to $0f
|
|
|
|
|
|
|
|
/*
|
|
|
|
romXceEntryPointSetClock = uint16(0xc803)
|
|
|
|
romXceEntryPointReadClock = uint16(0xc803)
|
|
|
|
romXceEntryPointLauncherToRam = uint16(0xdfd9)
|
|
|
|
romXceEntryPointLauncher = uint16(0xdfd0)
|
|
|
|
*/
|
2020-10-24 22:22:52 +00:00
|
|
|
)
|
|
|
|
|
2024-01-06 20:48:23 +00:00
|
|
|
func newRomX(a *Apple2) (*romX, error) {
|
2020-10-24 22:22:52 +00:00
|
|
|
var rx romX
|
|
|
|
rx.a = a
|
2024-01-06 20:48:23 +00:00
|
|
|
rx.memory = a.mmu
|
2021-10-12 10:26:40 +00:00
|
|
|
rx.systemBank = 1
|
|
|
|
rx.mainBank = 1
|
|
|
|
rx.tempBank = 1
|
2020-10-24 22:22:52 +00:00
|
|
|
rx.textBank = 0
|
2021-10-12 10:26:40 +00:00
|
|
|
rx.debug = true
|
|
|
|
|
|
|
|
if a.isApple2e {
|
|
|
|
err := a.cg.load("<internal>/ROMXce Production 1Mb Text ROM V5.bin")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-06 20:48:23 +00:00
|
|
|
// Intercept all memory accesses
|
|
|
|
a.cpu.SetMemory(&rx)
|
2021-10-12 10:26:40 +00:00
|
|
|
return &rx, nil
|
2020-10-24 22:22:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (rx *romX) Peek(address uint16) uint8 {
|
|
|
|
intercepted, value := rx.interceptAccess(address)
|
|
|
|
if intercepted {
|
|
|
|
return value
|
|
|
|
}
|
|
|
|
return rx.memory.Peek(address)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rx *romX) PeekCode(address uint16) uint8 {
|
2021-10-12 10:26:40 +00:00
|
|
|
intercepted, value := rx.interceptAccess(address)
|
|
|
|
if intercepted {
|
|
|
|
return value
|
|
|
|
}
|
2020-10-24 22:22:52 +00:00
|
|
|
return rx.memory.PeekCode(address)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rx *romX) Poke(address uint16, value uint8) {
|
|
|
|
rx.interceptAccess(address)
|
|
|
|
rx.memory.Poke(address, value)
|
|
|
|
}
|
|
|
|
|
2021-10-12 10:26:40 +00:00
|
|
|
func (rx *romX) logf(format string, a ...interface{}) {
|
|
|
|
msg := fmt.Sprintf(format, a...)
|
|
|
|
fmt.Printf("[romX]%s\n", msg)
|
|
|
|
}
|
|
|
|
|
2020-10-24 22:22:52 +00:00
|
|
|
func (rx *romX) interceptAccess(address uint16) (bool, uint8) {
|
|
|
|
// Intercept only $C080 to $FFFF as seen by the F12 chip
|
|
|
|
if address < 0xc080 {
|
|
|
|
return false, 0
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup mode when the setup bank is active
|
2021-10-12 10:26:40 +00:00
|
|
|
if rx.systemBank == romxSetupBank {
|
|
|
|
|
|
|
|
// Range commands
|
|
|
|
nibble := uint8(address & 0xf)
|
|
|
|
switch address & 0xfff0 {
|
|
|
|
case romXceSetMainBank:
|
|
|
|
rx.mainBank = nibble
|
|
|
|
rx.logf("Main bank set to $%x", nibble)
|
|
|
|
case romXcePresetTextBank:
|
|
|
|
textBank := int(nibble)
|
|
|
|
rx.a.cg.setPage(textBank)
|
|
|
|
rx.logf("[romX]Text bank set to $%x", nibble)
|
|
|
|
case romXceLowerUpperBanks:
|
|
|
|
rx.logf("Configure lower upper banks $%x", address)
|
|
|
|
case romXceSetTempBank:
|
|
|
|
rx.tempBank = nibble
|
|
|
|
rx.logf("Temp bank set to $%x", nibble)
|
|
|
|
case romXceMCP7940SDC:
|
|
|
|
rx.logf("Configure MCP7940 $%x", address)
|
|
|
|
}
|
|
|
|
|
|
|
|
// More commands
|
2020-10-24 22:22:52 +00:00
|
|
|
switch address {
|
2021-10-12 10:26:40 +00:00
|
|
|
case romXceSelectTempBank:
|
|
|
|
rx.systemBank = rx.tempBank
|
|
|
|
rx.logf("System bank set to temp bank $%x", rx.systemBank)
|
|
|
|
case romXceSelectMainBank:
|
|
|
|
rx.systemBank = rx.mainBank
|
|
|
|
rx.logf("System bank set to main bank $%x", rx.systemBank)
|
2020-10-24 22:22:52 +00:00
|
|
|
}
|
|
|
|
|
2021-10-12 10:26:40 +00:00
|
|
|
// Queries
|
|
|
|
switch address {
|
|
|
|
case romXGetDefaultSystemBank:
|
|
|
|
bank := rx.systemBank
|
|
|
|
rx.logf("Peek in $%04x, current system bank %v", address, bank)
|
|
|
|
return true, bank
|
|
|
|
case romXGetDefaultTextBank:
|
|
|
|
page := uint8(rx.a.cg.getPage() & 0xf)
|
|
|
|
rx.logf("PeeK in $%04x, current text bank %v", address, page)
|
|
|
|
return true, 0x10 + page
|
|
|
|
case romXGetCurrentBootDelay:
|
|
|
|
delay := uint8(5) // We don't care
|
|
|
|
rx.logf("PeeK in $%04x, current boot delay %v", address, delay)
|
|
|
|
return true, delay
|
2020-10-24 22:22:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false, 0
|
|
|
|
}
|
|
|
|
|
|
|
|
// Activation sequence detection
|
2021-10-12 10:26:40 +00:00
|
|
|
if address == romXceActivationSequence[rx.activationStep] {
|
2020-10-24 22:22:52 +00:00
|
|
|
rx.activationStep++
|
2021-10-12 10:26:40 +00:00
|
|
|
rx.logf("Activation step %v", rx.activationStep)
|
2020-10-24 22:22:52 +00:00
|
|
|
if rx.activationStep == len(romXActivationSequence) {
|
|
|
|
// Activation sequence completed
|
2021-10-12 10:26:40 +00:00
|
|
|
rx.systemBank = romxSetupBank
|
2020-10-24 22:22:52 +00:00
|
|
|
rx.activationStep = 0
|
2021-10-12 10:26:40 +00:00
|
|
|
rx.logf("System bank set to 0, %v", rx.systemBank)
|
2020-10-24 22:22:52 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
rx.activationStep = 0
|
|
|
|
}
|
|
|
|
|
|
|
|
return false, 0
|
|
|
|
}
|
2024-01-06 20:48:23 +00:00
|
|
|
|
|
|
|
func setupRomX(a *Apple2) error {
|
|
|
|
_, err := newRomX(a)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|