2019-02-16 19:15:41 +00:00
|
|
|
package apple2
|
2019-02-16 16:32:06 +00:00
|
|
|
|
2019-02-17 23:01:48 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
2019-02-16 16:32:06 +00:00
|
|
|
|
|
|
|
type ioC0Page struct {
|
2019-02-23 23:41:32 +00:00
|
|
|
softSwitches [128]softSwitch
|
|
|
|
softSwitchesData [128]uint8
|
|
|
|
keyboard keyboardProvider
|
|
|
|
mmu *memoryManager
|
2019-02-20 22:51:47 +00:00
|
|
|
}
|
|
|
|
|
2019-02-23 23:41:32 +00:00
|
|
|
type softSwitch func(io *ioC0Page, isWrite bool, value uint8) uint8
|
|
|
|
|
2019-02-20 22:51:47 +00:00
|
|
|
type keyboardProvider interface {
|
|
|
|
getKey() (key uint8, ok bool)
|
2019-02-16 16:32:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// See https://www.kreativekorp.com/miscpages/a2info/iomemory.shtml
|
|
|
|
// See https://stason.org/TULARC/pc/apple2/programmer/004-I-d-like-to-do-some-serious-Apple-II-programming-Whe.html
|
|
|
|
|
|
|
|
const (
|
2019-02-24 13:37:10 +00:00
|
|
|
ssOn uint8 = 0x80
|
|
|
|
ssOff uint8 = 0x00
|
|
|
|
)
|
|
|
|
|
2019-02-24 14:05:50 +00:00
|
|
|
func newIoC0Page(mmu *memoryManager) *ioC0Page {
|
|
|
|
var io ioC0Page
|
|
|
|
io.mmu = mmu
|
2019-02-16 16:32:06 +00:00
|
|
|
|
2019-02-24 14:05:50 +00:00
|
|
|
addApple2SoftSwitches(&io)
|
|
|
|
if mmu.isApple2e {
|
|
|
|
addApple2ESoftSwitches(&io)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &io
|
2019-02-23 23:41:32 +00:00
|
|
|
}
|
|
|
|
|
2019-02-24 14:05:50 +00:00
|
|
|
func (p *ioC0Page) isSoftSwitchExtActive(ioFlag uint8) bool {
|
|
|
|
return (p.softSwitchesData[ioFlag] & ssOn) == ssOn
|
2019-02-16 16:32:06 +00:00
|
|
|
}
|
|
|
|
|
2019-02-23 23:41:32 +00:00
|
|
|
func (p *ioC0Page) setKeyboardProvider(kb keyboardProvider) {
|
|
|
|
p.keyboard = kb
|
2019-02-16 16:32:06 +00:00
|
|
|
}
|
|
|
|
|
2019-02-16 19:15:41 +00:00
|
|
|
func (p *ioC0Page) Peek(address uint8) uint8 {
|
2019-02-16 16:32:06 +00:00
|
|
|
//fmt.Printf("Peek on $C0%02x ", address)
|
|
|
|
return p.access(address, false, 0)
|
|
|
|
}
|
|
|
|
|
2019-02-16 19:15:41 +00:00
|
|
|
func (p *ioC0Page) Poke(address uint8, value uint8) {
|
2019-02-16 16:32:06 +00:00
|
|
|
//fmt.Printf("Poke on $C0%02x with %02x ", address, value)
|
|
|
|
p.access(address, true, value)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *ioC0Page) access(address uint8, isWrite bool, value uint8) uint8 {
|
2019-02-24 13:37:10 +00:00
|
|
|
// The second half of the pages is reserved for slots
|
|
|
|
if address >= 0x90 {
|
2019-02-23 23:41:32 +00:00
|
|
|
// TODO reserved slots data
|
|
|
|
return 0
|
|
|
|
}
|
2019-02-16 16:32:06 +00:00
|
|
|
|
2019-02-23 23:41:32 +00:00
|
|
|
ss := p.softSwitches[address]
|
|
|
|
if ss == nil {
|
|
|
|
panic(fmt.Sprintf("Unknown softswitch 0xC0%02x", address))
|
|
|
|
}
|
|
|
|
|
|
|
|
return ss(p, isWrite, value)
|
|
|
|
}
|