mirror of
https://github.com/irmen/ksim65.git
synced 2024-06-14 13:29:35 +00:00
fixed mouse handling
This commit is contained in:
parent
a40e545f61
commit
448d74baac
|
@ -342,37 +342,46 @@ class MainWindow(title: String) : JFrame(title), KeyListener, MouseInputListener
|
|||
}
|
||||
|
||||
// keyboard events:
|
||||
override fun keyTyped(p0: KeyEvent) {
|
||||
println(p0)
|
||||
println("[${p0.keyChar}]")
|
||||
keyboardBuffer.add(p0.keyChar)
|
||||
override fun keyTyped(event: KeyEvent) {
|
||||
println(event)
|
||||
println("[${event.keyChar}]")
|
||||
keyboardBuffer.add(event.keyChar)
|
||||
while (keyboardBuffer.size > 8)
|
||||
keyboardBuffer.pop()
|
||||
}
|
||||
|
||||
override fun keyPressed(p0: KeyEvent) {}
|
||||
override fun keyReleased(p0: KeyEvent) {}
|
||||
override fun keyPressed(event: KeyEvent) {}
|
||||
override fun keyReleased(event: KeyEvent) {}
|
||||
|
||||
// mouse events:
|
||||
override fun mousePressed(p0: MouseEvent) {}
|
||||
|
||||
override fun mouseReleased(p0: MouseEvent) {}
|
||||
override fun mouseEntered(p0: MouseEvent) {}
|
||||
override fun mouseExited(p0: MouseEvent) {}
|
||||
override fun mouseDragged(p0: MouseEvent) {}
|
||||
override fun mouseClicked(p0: MouseEvent) {
|
||||
override fun mousePressed(event: MouseEvent) {
|
||||
val pos = canvas.mousePixelPosition()
|
||||
if (pos == null)
|
||||
return
|
||||
else {
|
||||
mousePos = pos
|
||||
leftButton = SwingUtilities.isLeftMouseButton(p0)
|
||||
rightButton = SwingUtilities.isRightMouseButton(p0)
|
||||
middleButton = SwingUtilities.isMiddleMouseButton(p0)
|
||||
leftButton = leftButton or SwingUtilities.isLeftMouseButton(event)
|
||||
rightButton = rightButton or SwingUtilities.isRightMouseButton(event)
|
||||
middleButton = middleButton or SwingUtilities.isMiddleMouseButton(event)
|
||||
}
|
||||
}
|
||||
override fun mouseReleased(event: MouseEvent) {
|
||||
val pos = canvas.mousePixelPosition()
|
||||
if (pos == null)
|
||||
return
|
||||
else {
|
||||
mousePos = pos
|
||||
leftButton = leftButton xor SwingUtilities.isLeftMouseButton(event)
|
||||
rightButton = rightButton xor SwingUtilities.isRightMouseButton(event)
|
||||
middleButton = middleButton xor SwingUtilities.isMiddleMouseButton(event)
|
||||
}
|
||||
}
|
||||
override fun mouseEntered(event: MouseEvent) {}
|
||||
override fun mouseExited(event: MouseEvent) {}
|
||||
override fun mouseDragged(event: MouseEvent) = mouseMoved(event)
|
||||
override fun mouseClicked(event: MouseEvent) {}
|
||||
|
||||
override fun mouseMoved(p0: MouseEvent) {
|
||||
override fun mouseMoved(event: MouseEvent) {
|
||||
val pos = canvas.mousePixelPosition()
|
||||
if (pos == null)
|
||||
return
|
||||
|
|
|
@ -23,7 +23,7 @@ class VirtualMachine(title: String) {
|
|||
private val display = Display(0xd000, 0xd00a, hostDisplay,
|
||||
ScreenDefs.SCREEN_WIDTH_CHARS, ScreenDefs.SCREEN_HEIGHT_CHARS,
|
||||
ScreenDefs.SCREEN_WIDTH, ScreenDefs.SCREEN_HEIGHT)
|
||||
private val mouse = Mouse(0xd300, 0xd304, hostDisplay)
|
||||
private val mouse = Mouse(0xd300, 0xd305, hostDisplay)
|
||||
private val keyboard = Keyboard(0xd400, 0xd400, hostDisplay)
|
||||
|
||||
init {
|
||||
|
|
|
@ -3,7 +3,7 @@ package razorvine.ksim65.components
|
|||
import razorvine.ksim65.IHostInterface
|
||||
|
||||
/**
|
||||
* An analog mouse or paddle input device, with 2 buttons.
|
||||
* A mouse or tablet absolute position input device, with 2 buttons.
|
||||
*
|
||||
* reg. value
|
||||
* ---- ---------
|
||||
|
@ -12,19 +12,21 @@ import razorvine.ksim65.IHostInterface
|
|||
* 02 mouse pixel pos Y (lsb)
|
||||
* 03 mouse pixel pos Y (msb)
|
||||
* 04 buttons, bit 0 = left button, bit 1 = right button, bit 2 = middle button
|
||||
* 05 latch: when written, samples the current mouse position and button state.
|
||||
*/
|
||||
class Mouse(startAddress: Address, endAddress: Address, private val host: IHostInterface) :
|
||||
MemMappedComponent(startAddress, endAddress) {
|
||||
|
||||
init {
|
||||
require(endAddress - startAddress + 1 == 5) { "mouse needs exactly 5 memory bytes" }
|
||||
require(endAddress - startAddress + 1 == 6) { "mouse needs exactly 6 memory bytes" }
|
||||
}
|
||||
|
||||
override fun clock() {}
|
||||
override fun reset() {}
|
||||
|
||||
private var mouse = host.mouse()
|
||||
|
||||
override operator fun get(address: Address): UByte {
|
||||
val mouse = host.mouse()
|
||||
return when (address - startAddress) {
|
||||
0x00 -> (mouse.x and 0xff).toShort()
|
||||
0x01 -> (mouse.x ushr 8).toShort()
|
||||
|
@ -40,5 +42,8 @@ class Mouse(startAddress: Address, endAddress: Address, private val host: IHostI
|
|||
}
|
||||
}
|
||||
|
||||
override operator fun set(address: Address, data: UByte) { /* read-only device */ }
|
||||
override operator fun set(address: Address, data: UByte) {
|
||||
if (address - startAddress == 0x05)
|
||||
mouse = host.mouse()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,66 +35,47 @@ start
|
|||
sta DISPLAY+8
|
||||
lda #1
|
||||
sta DISPLAY+9
|
||||
ldy #0
|
||||
- lda _title1,y
|
||||
beq +
|
||||
sta DISPLAY+10
|
||||
iny
|
||||
bne -
|
||||
beq +
|
||||
lda #<_title1
|
||||
ldy #>_title1
|
||||
jsr print
|
||||
jmp +
|
||||
|
||||
_title1 .text "**** COMMODORE 64 BASIC V2 ****", 10, 10, " 64K RAM SYSTEM 38911 BASIC BYTES FREE", 10, 10, "READY.",10,0
|
||||
_text2 .text 10,"Nah, only joking, this is not a weird C-64.",10,"This is a working fantasy virtual 8-bit 6502 machine though!",10
|
||||
.text "Type some stuff on the keyboard, use the mouse (with Left button/Right button)", 10, "to draw/erase pixels.",10,10,0
|
||||
_text3 .text "Mouse drawing and keyboard scanning: done in main program loop.",10
|
||||
.text "Time displayed at the bottom of the screen: done in timer IRQ.",10,10,0
|
||||
|
||||
|
||||
+
|
||||
|
||||
; ------- draw pixel line
|
||||
pixelline
|
||||
ldx pix_x
|
||||
stx DISPLAY+3
|
||||
ldx pix_x+1
|
||||
stx DISPLAY+4
|
||||
ldx pix_y
|
||||
stx DISPLAY+5
|
||||
ldx pix_y+1
|
||||
stx DISPLAY+6
|
||||
lda #1
|
||||
sta DISPLAY+7 ; plot
|
||||
lda pix_x
|
||||
clc
|
||||
adc #2
|
||||
sta pix_x
|
||||
bcc +
|
||||
inc pix_x+1
|
||||
+ inc pix_y
|
||||
bne +
|
||||
inc pix_y+1
|
||||
+ lda pix_x+1
|
||||
cmp #>SCREEN_WIDTH
|
||||
bcc pixelline
|
||||
bne stop1
|
||||
lda pix_x
|
||||
cmp #<SCREEN_WIDTH
|
||||
bcc pixelline
|
||||
bcs stop1
|
||||
pix_x .word 0
|
||||
pix_y .word 0
|
||||
|
||||
stop1
|
||||
+ jsr delay
|
||||
lda #<_text2
|
||||
ldy #>_text2
|
||||
jsr print
|
||||
lda #<_text3
|
||||
ldy #>_text3
|
||||
jsr print
|
||||
|
||||
;--------- draw with mouse
|
||||
mousedraw
|
||||
ldx MOUSE+0
|
||||
ldy MOUSE+2
|
||||
stx DISPLAY+3
|
||||
sty DISPLAY+5
|
||||
ldx MOUSE+1
|
||||
ldy MOUSE+3
|
||||
stx DISPLAY+4
|
||||
sty DISPLAY+6
|
||||
sta MOUSE+5 ; sample position and buttons
|
||||
lda MOUSE+0
|
||||
sta DISPLAY+3
|
||||
lda MOUSE+1
|
||||
sta DISPLAY+4
|
||||
lda MOUSE+2
|
||||
sta DISPLAY+5
|
||||
lda MOUSE+3
|
||||
sta DISPLAY+6
|
||||
lda MOUSE+4 ; buttons
|
||||
lsr a
|
||||
bcc +
|
||||
lda #1
|
||||
sta DISPLAY+7 ; plot pixel
|
||||
jmp mousedraw
|
||||
sta DISPLAY+7 ; plot pixel with LMB
|
||||
bne mousedraw
|
||||
+ lsr a
|
||||
bcc mousedraw
|
||||
lda #0
|
||||
sta DISPLAY+7 ; erase pixel with RMB
|
||||
beq mousedraw
|
||||
|
||||
|
||||
character .byte 0
|
||||
|
@ -199,6 +180,25 @@ _time_msg .text "The current date and time is: ",0
|
|||
|
||||
|
||||
; ----- routines
|
||||
delay ldx #50
|
||||
- ldy #0
|
||||
- nop
|
||||
dey
|
||||
bne -
|
||||
dex
|
||||
bne --
|
||||
rts
|
||||
|
||||
print sta _mod+1
|
||||
sty _mod+2
|
||||
ldy #0
|
||||
_mod lda $ffff,y ; modified
|
||||
beq +
|
||||
sta DISPLAY+$0a
|
||||
iny
|
||||
bne _mod
|
||||
+ rts
|
||||
|
||||
textout
|
||||
sta _mod+1
|
||||
sty _mod+2
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user