izapple2/softSwitches2e.go

90 lines
2.9 KiB
Go
Raw Normal View History

package apple2
2019-10-20 22:00:42 +00:00
/*
See:
https://www.apple.asimov.net/documentation/hardware/machines/APPLE%20IIe%20Auxiliary%20Memory%20Softswitches.pdf
*/
const (
2019-11-03 23:23:03 +00:00
ioFlagAltChar uint8 = 0x1E
ioFlag80Col uint8 = 0x1F
2019-11-11 21:58:42 +00:00
)
const (
screenDrawCycles = uint64(12480 + 4550)
screenVertBlankingCycles = uint64(4550)
)
2019-02-24 14:05:50 +00:00
func addApple2ESoftSwitches(io *ioC0Page) {
2019-10-12 19:37:37 +00:00
// New MMU read softswithes
2019-11-03 23:23:03 +00:00
mmu := io.apple2.mmu
addSoftSwitchesMmu(io, 0x02, 0x03, 0x13, &mmu.altMainRAMActiveRead, "RAMRD")
addSoftSwitchesMmu(io, 0x04, 0x05, 0x14, &mmu.altMainRAMActiveWrite, "RAMWRT")
2019-11-05 23:02:03 +00:00
addSoftSwitchesMmu(io, 0x06, 0x07, 0x15, &mmu.intCxROMActive, "INTCXROM")
2019-11-03 23:23:03 +00:00
addSoftSwitchesMmu(io, 0x08, 0x09, 0x16, &mmu.altZeroPage, "ALTZP")
2019-11-05 23:02:03 +00:00
addSoftSwitchesMmu(io, 0x0a, 0x0b, 0x17, &mmu.slotC3ROMActive, "SLOTC3ROM")
2019-11-08 22:56:54 +00:00
addSoftSwitchesMmu(io, 0x00, 0x01, 0x18, &mmu.store80Active, "80STORE")
2019-10-20 22:00:42 +00:00
2019-11-03 23:23:03 +00:00
// New IOU read softswithes
addSoftSwitchesIou(io, 0x0c, 0x0d, 0x1f, ioFlag80Col, "80COL")
addSoftSwitchesIou(io, 0x0e, 0x0f, 0x1e, ioFlagAltChar, "ALTCHARSET")
2019-10-12 19:37:37 +00:00
// Previous read softswithes
2019-10-20 22:00:42 +00:00
io.addSoftSwitchR(0x1A, getStatusSoftSwitch(ioFlagText), "TEXT")
io.addSoftSwitchR(0x1B, getStatusSoftSwitch(ioFlagMixed), "MIXED")
io.addSoftSwitchR(0x1C, getStatusSoftSwitch(ioFlagSecondPage), "PAGE2")
io.addSoftSwitchR(0x1D, getStatusSoftSwitch(ioFlagHiRes), "HIRES")
2019-10-12 19:37:37 +00:00
2019-11-05 23:02:03 +00:00
io.addSoftSwitchR(0x11, func(_ *ioC0Page) uint8 {
return ssFromBool(mmu.lcAltBank)
}, "BSRBANK2")
io.addSoftSwitchR(0x12, func(_ *ioC0Page) uint8 {
return ssFromBool(mmu.lcActiveRead)
}, "BSRREADRAM")
2019-11-11 21:58:42 +00:00
io.addSoftSwitchR(0x19, func(_ *ioC0Page) uint8 {
// See "Inside Apple IIe", page 268
// See http://rich12345.tripod.com/aiivideo/vbl.html
// For each screen draw:
// 12480 cycles drawing lines, VERTBLANK = $00
// 4550 cycles doing the return to position (0,0), VERTBLANK = $80
// Vert blank takes 12480 cycles every page redraw
cycles := io.apple2.cpu.GetCycles() % screenDrawCycles
if cycles <= screenVertBlankingCycles {
return ssOn
}
return ssOff
}, "VERTBLANK")
2019-10-12 19:37:37 +00:00
//io.softSwitchesData[ioFlagAltChar] = ssOn // Not sure about this.
}
2019-11-03 23:23:03 +00:00
func addSoftSwitchesMmu(io *ioC0Page, addressClear uint8, addressSet uint8, AddressGet uint8, flag *bool, name string) {
io.addSoftSwitchW(addressClear, func(_ *ioC0Page, _ uint8) {
*flag = false
}, name+"OFF")
2019-11-03 23:23:03 +00:00
io.addSoftSwitchW(addressSet, func(_ *ioC0Page, _ uint8) {
*flag = true
}, name+"ON")
io.addSoftSwitchR(AddressGet, func(_ *ioC0Page) uint8 {
2019-11-05 23:02:03 +00:00
return ssFromBool(*flag)
2019-11-03 23:23:03 +00:00
}, name)
}
2019-11-03 23:23:03 +00:00
func addSoftSwitchesIou(io *ioC0Page, addressClear uint8, addressSet uint8, AddressGet uint8, ioFlag uint8, name string) {
io.addSoftSwitchW(addressClear, func(_ *ioC0Page, _ uint8) {
io.softSwitchesData[ioFlag] = ssOff
}, name+"OFF")
2019-11-03 23:23:03 +00:00
io.addSoftSwitchW(addressSet, func(_ *ioC0Page, _ uint8) {
io.softSwitchesData[ioFlag] = ssOn
}, name+"ON")
2019-11-03 23:23:03 +00:00
io.addSoftSwitchR(AddressGet, func(_ *ioC0Page) uint8 {
return io.softSwitchesData[ioFlag]
}, name)
}