mirror of
https://github.com/ivanizag/izapple2.git
synced 2025-01-10 12:30:17 +00:00
Mouse access with IN# and PR#
This commit is contained in:
parent
55ca1df967
commit
0c150c3ecf
@ -30,7 +30,7 @@ Portable emulator of an Apple II+ or //e. Written in Go.
|
|||||||
- Bootable Smartport / ProDOS card
|
- Bootable Smartport / ProDOS card
|
||||||
- VidHd, limited to the ROM signature and SHR as used by Total Replay, only for //e models with 128Kb
|
- VidHd, limited to the ROM signature and SHR as used by Total Replay, only for //e models with 128Kb
|
||||||
- FASTChip, limited to what Total Replay needs to set and clear fast mode
|
- FASTChip, limited to what Total Replay needs to set and clear fast mode
|
||||||
- Mouse Card, emulates the entry points, not the softswitches. Experimental.
|
- Mouse Card, emulates the entry points, not the softswitches.
|
||||||
- Host console card. Maps the host STDIN and STDOUT to PR# and IN#
|
- Host console card. Maps the host STDIN and STDOUT to PR# and IN#
|
||||||
|
|
||||||
- Graphic modes:
|
- Graphic modes:
|
||||||
|
87
cardMouse.go
87
cardMouse.go
@ -26,8 +26,9 @@ type CardMouse struct {
|
|||||||
minX, minY, maxX, maxY uint16
|
minX, minY, maxX, maxY uint16
|
||||||
mode uint8
|
mode uint8
|
||||||
|
|
||||||
iIn int
|
response string
|
||||||
i int
|
iOut int
|
||||||
|
iIn int
|
||||||
|
|
||||||
trace bool
|
trace bool
|
||||||
}
|
}
|
||||||
@ -36,10 +37,9 @@ type CardMouse struct {
|
|||||||
func NewCardMouse() *CardMouse {
|
func NewCardMouse() *CardMouse {
|
||||||
var c CardMouse
|
var c CardMouse
|
||||||
c.name = "Mouse Card"
|
c.name = "Mouse Card"
|
||||||
c.trace = true
|
c.trace = false
|
||||||
c.maxX = 0x3ff
|
c.maxX = 0x3ff
|
||||||
c.maxY = 0x3ff
|
c.maxY = 0x3ff
|
||||||
//c.loadRomFromResource("<internal>//Apple Mouse Interface Card ROM - 342-0270-C.bin")
|
|
||||||
return &c
|
return &c
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,10 +60,12 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (c *CardMouse) set(field uint16, value uint8) {
|
func (c *CardMouse) set(field uint16, value uint8) {
|
||||||
|
// Update the card screen-holes
|
||||||
c.a.mmu.Poke(field+uint16(c.slot), value)
|
c.a.mmu.Poke(field+uint16(c.slot), value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CardMouse) get(field uint16) uint8 {
|
func (c *CardMouse) get(field uint16) uint8 {
|
||||||
|
// Read from the card screen-holes
|
||||||
return c.a.mmu.Peek(field /*+ uint16(c.slot)*/)
|
return c.a.mmu.Peek(field /*+ uint16(c.slot)*/)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,26 +84,53 @@ func (c *CardMouse) setMode(mode uint8) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *CardMouse) readMouse() (uint16, uint16, bool) {
|
||||||
|
x, y, pressed := c.a.io.mouse.ReadMouse()
|
||||||
|
xTrans := uint16(uint64(c.maxX-c.minX) * uint64(x) / 65536)
|
||||||
|
yTrans := uint16(uint64(c.maxY-c.minY) * uint64(y) / 65536)
|
||||||
|
return xTrans, yTrans, pressed
|
||||||
|
}
|
||||||
|
|
||||||
const mouseReponse = "10,10,+4\n"
|
const mouseReponse = "10,10,+4\n"
|
||||||
|
|
||||||
func (c *CardMouse) assign(a *Apple2, slot int) {
|
func (c *CardMouse) assign(a *Apple2, slot int) {
|
||||||
c.addCardSoftSwitchR(0, func(*ioC0Page) uint8 {
|
c.addCardSoftSwitchR(0, func(*ioC0Page) uint8 {
|
||||||
// TODO
|
if c.iOut == 0 {
|
||||||
value := uint8(mouseReponse[c.i])
|
// Create a new response
|
||||||
c.i = (c.i + 1) % len(mouseReponse)
|
x, y, pressed := c.readMouse()
|
||||||
value += 0x80
|
|
||||||
if value&0x7f == 10 {
|
button := 1
|
||||||
value = 13 + 0x80
|
if !pressed {
|
||||||
|
button += 2
|
||||||
|
}
|
||||||
|
if !c.lastPressed {
|
||||||
|
button++
|
||||||
|
}
|
||||||
|
|
||||||
|
keyboard := "+"
|
||||||
|
strobed := (c.a.io.softSwitchesData[ioDataKeyboard] & (1 << 7)) == 0
|
||||||
|
if !strobed {
|
||||||
|
keyboard = "-"
|
||||||
|
}
|
||||||
|
|
||||||
|
c.response = fmt.Sprintf("%v,%v,%v%v\r", x, y, keyboard, button)
|
||||||
}
|
}
|
||||||
|
value := uint8(c.response[c.iOut])
|
||||||
|
c.iOut++
|
||||||
|
if c.iOut == len(c.response) {
|
||||||
|
c.iOut = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
value += 0x80
|
||||||
if c.trace {
|
if c.trace {
|
||||||
fmt.Printf("[cardMouse] Read access to softswith 0x%x for slot %v, value %x.\n", 0, slot, value)
|
fmt.Printf("[cardMouse] IN#%v -> %02x.\n", slot, value)
|
||||||
}
|
}
|
||||||
return value
|
return value
|
||||||
}, "MOUSEOUT")
|
}, "MOUSEOUT")
|
||||||
|
|
||||||
c.addCardSoftSwitchW(1, func(_ *ioC0Page, value uint8) {
|
c.addCardSoftSwitchW(1, func(_ *ioC0Page, value uint8) {
|
||||||
if c.trace {
|
if c.trace {
|
||||||
fmt.Printf("[cardMouse] Write access to softswith 0x%x for slot %v, value 0x%x: %v, %v.\n", 1, slot, value, value&0x7f, string(value&0x7f))
|
fmt.Printf("[cardMouse] PR#%v <- %02x\n", slot, value)
|
||||||
}
|
}
|
||||||
if c.iIn == 0 {
|
if c.iIn == 0 {
|
||||||
// We care only about the first byte
|
// We care only about the first byte
|
||||||
@ -122,16 +151,14 @@ func (c *CardMouse) assign(a *Apple2, slot int) {
|
|||||||
|
|
||||||
c.addCardSoftSwitchW(3, func(_ *ioC0Page, value uint8) {
|
c.addCardSoftSwitchW(3, func(_ *ioC0Page, value uint8) {
|
||||||
if c.trace {
|
if c.trace {
|
||||||
fmt.Printf("[cardMouse] ServeMouse(0x%02v)\n", value)
|
fmt.Printf("[cardMouse] ServeMouse() NOT IMPLEMENTED\n")
|
||||||
}
|
}
|
||||||
|
panic("Mouse interrupts not implemented")
|
||||||
}, "SERVEMOUSE")
|
}, "SERVEMOUSE")
|
||||||
|
|
||||||
c.addCardSoftSwitchW(4, func(_ *ioC0Page, value uint8) {
|
c.addCardSoftSwitchW(4, func(_ *ioC0Page, value uint8) {
|
||||||
if c.mode&mouseModeEnabled == 1 {
|
if c.mode&mouseModeEnabled == 1 {
|
||||||
x, y, pressed := a.io.mouse.ReadMouse()
|
x, y, pressed := c.readMouse()
|
||||||
|
|
||||||
xTrans := uint16(uint64(c.maxX-c.minX) * uint64(x) / 65536)
|
|
||||||
yTrans := uint16(uint64(c.maxY-c.minY) * uint64(y) / 65536)
|
|
||||||
|
|
||||||
status := uint8(0)
|
status := uint8(0)
|
||||||
if pressed {
|
if pressed {
|
||||||
@ -140,30 +167,30 @@ func (c *CardMouse) assign(a *Apple2, slot int) {
|
|||||||
if c.lastPressed {
|
if c.lastPressed {
|
||||||
status |= 1 << 6
|
status |= 1 << 6
|
||||||
}
|
}
|
||||||
if (xTrans != c.lastX) || (yTrans != c.lastY) {
|
if (x != c.lastX) || (y != c.lastY) {
|
||||||
status |= 1 << 5
|
status |= 1 << 5
|
||||||
}
|
}
|
||||||
|
|
||||||
c.set(mouseXHi, uint8(xTrans>>8))
|
c.set(mouseXHi, uint8(x>>8))
|
||||||
c.set(mouseYHi, uint8(yTrans>>8))
|
c.set(mouseYHi, uint8(y>>8))
|
||||||
c.set(mouseXLo, uint8(xTrans))
|
c.set(mouseXLo, uint8(x))
|
||||||
c.set(mouseYLo, uint8(yTrans))
|
c.set(mouseYLo, uint8(y))
|
||||||
c.set(mouseStatus, status)
|
c.set(mouseStatus, status)
|
||||||
c.set(mouseMode, c.mode)
|
c.set(mouseMode, c.mode)
|
||||||
if c.trace && ((status&(1<<5) != 0) || (pressed != c.lastPressed)) {
|
if c.trace && ((status&(1<<5) != 0) || (pressed != c.lastPressed)) {
|
||||||
fmt.Printf("[cardMouse] ReadMouse(): x: %v, y: %v, pressed: %v\n",
|
fmt.Printf("[cardMouse] ReadMouse(): x: %v, y: %v, pressed: %v\n",
|
||||||
xTrans, yTrans, pressed)
|
x, y, pressed)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.lastX = xTrans
|
c.lastX = x
|
||||||
c.lastY = yTrans
|
c.lastY = y
|
||||||
c.lastPressed = pressed
|
c.lastPressed = pressed
|
||||||
}
|
}
|
||||||
}, "READMOUSE")
|
}, "READMOUSE")
|
||||||
|
|
||||||
c.addCardSoftSwitchW(5, func(_ *ioC0Page, value uint8) {
|
c.addCardSoftSwitchW(5, func(_ *ioC0Page, value uint8) {
|
||||||
if c.trace {
|
if c.trace {
|
||||||
fmt.Printf("[cardMouse] ClearMouse()\n")
|
fmt.Printf("[cardMouse] ClearMouse() NOT IMPLEMENTED\n")
|
||||||
}
|
}
|
||||||
c.set(mouseXHi, 0)
|
c.set(mouseXHi, 0)
|
||||||
c.set(mouseYHi, 0)
|
c.set(mouseYHi, 0)
|
||||||
@ -172,7 +199,7 @@ func (c *CardMouse) assign(a *Apple2, slot int) {
|
|||||||
}, "CLEARMOUSE")
|
}, "CLEARMOUSE")
|
||||||
c.addCardSoftSwitchW(6, func(_ *ioC0Page, value uint8) {
|
c.addCardSoftSwitchW(6, func(_ *ioC0Page, value uint8) {
|
||||||
if c.trace {
|
if c.trace {
|
||||||
fmt.Printf("[cardMouse] PosMouse(0x%02v)\n", value)
|
fmt.Printf("[cardMouse] PosMouse() NOT IMPLEMENTED\n")
|
||||||
}
|
}
|
||||||
}, "POSMOUSE")
|
}, "POSMOUSE")
|
||||||
|
|
||||||
@ -182,11 +209,9 @@ func (c *CardMouse) assign(a *Apple2, slot int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if value == 0 {
|
if value == 0 {
|
||||||
//c.a.cpu.SetTrace(false)
|
|
||||||
c.minX = uint16(c.get(mouseXLo)) + uint16(c.get(mouseXHi))<<8
|
c.minX = uint16(c.get(mouseXLo)) + uint16(c.get(mouseXHi))<<8
|
||||||
c.maxX = uint16(c.get(mouseYLo)) + uint16(c.get(mouseYHi))<<8
|
c.maxX = uint16(c.get(mouseYLo)) + uint16(c.get(mouseYHi))<<8
|
||||||
} else if value == 1 {
|
} else if value == 1 {
|
||||||
//c.a.cpu.SetTrace(true)
|
|
||||||
c.minY = uint16(c.get(mouseXLo)) + uint16(c.get(mouseXHi))<<8
|
c.minY = uint16(c.get(mouseXLo)) + uint16(c.get(mouseXHi))<<8
|
||||||
c.maxY = uint16(c.get(mouseYLo)) + uint16(c.get(mouseYHi))<<8
|
c.maxY = uint16(c.get(mouseYLo)) + uint16(c.get(mouseYHi))<<8
|
||||||
}
|
}
|
||||||
@ -198,7 +223,7 @@ func (c *CardMouse) assign(a *Apple2, slot int) {
|
|||||||
|
|
||||||
c.addCardSoftSwitchW(8, func(_ *ioC0Page, value uint8) {
|
c.addCardSoftSwitchW(8, func(_ *ioC0Page, value uint8) {
|
||||||
if c.trace {
|
if c.trace {
|
||||||
fmt.Printf("[cardMouse] HomeMouse(0x%02x)\n", value)
|
fmt.Printf("[cardMouse] HomeMouse() NOT IMPLEMENTED\n")
|
||||||
}
|
}
|
||||||
}, "HOMEMOUSE")
|
}, "HOMEMOUSE")
|
||||||
|
|
||||||
@ -215,7 +240,7 @@ func (c *CardMouse) assign(a *Apple2, slot int) {
|
|||||||
|
|
||||||
c.addCardSoftSwitchW(8, func(_ *ioC0Page, value uint8) {
|
c.addCardSoftSwitchW(8, func(_ *ioC0Page, value uint8) {
|
||||||
if c.trace {
|
if c.trace {
|
||||||
fmt.Printf("[cardMouse] TimeData(%v)\n", value)
|
fmt.Printf("[cardMouse] TimeData(%v) NOT IMPLEMENTED\n", value)
|
||||||
}
|
}
|
||||||
}, "TIMEDATEMOUSE")
|
}, "TIMEDATEMOUSE")
|
||||||
|
|
||||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user