From 047d9abc6886dfb14f9d6d9bdbd4ff003bbcae80 Mon Sep 17 00:00:00 2001 From: Greg King Date: Mon, 5 May 2014 04:16:04 -0400 Subject: [PATCH 1/4] Added the long-missing driver-flags byte to the potentiometer (mouse) drivers. --- libsrc/c128/mou/c128-pot.s | 6 +++++- libsrc/c64/mou/c64-pot.s | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/libsrc/c128/mou/c128-pot.s b/libsrc/c128/mou/c128-pot.s index 4e549cc6d..f760d6b62 100644 --- a/libsrc/c128/mou/c128-pot.s +++ b/libsrc/c128/mou/c128-pot.s @@ -3,7 +3,7 @@ ; ; 2006-08-20, Stefan Haubenthal ; 2009-09-26, Ullrich von Bassewitz -; 2014-03-17, Greg King +; 2014-05-05, Greg King ; .include "zeropage.inc" @@ -43,6 +43,10 @@ HEADER: .addr IOCTL .addr IRQ +; Mouse driver flags + + .byte MOUSE_FLAG_LATE_IRQ + ; Callback table, set by the kernel before INSTALL is called CHIDE: jmp $0000 ; Hide the cursor diff --git a/libsrc/c64/mou/c64-pot.s b/libsrc/c64/mou/c64-pot.s index 17308f6ac..1ebbd26e2 100644 --- a/libsrc/c64/mou/c64-pot.s +++ b/libsrc/c64/mou/c64-pot.s @@ -3,7 +3,7 @@ ; ; 2006-08-20, Stefan Haubenthal ; 2009-09-26, Ullrich von Bassewitz -; 2014-03-17, Greg King +; 2014-05-05, Greg King ; .include "zeropage.inc" @@ -43,6 +43,10 @@ HEADER: .addr IOCTL .addr IRQ +; Mouse driver flags + + .byte MOUSE_FLAG_LATE_IRQ + ; Callback table, set by the kernel before INSTALL is called CHIDE: jmp $0000 ; Hide the cursor From 667f8229c02ceaaf94c2c2b169079e0eddea3ef0 Mon Sep 17 00:00:00 2001 From: Greg King Date: Mon, 5 May 2014 05:30:31 -0400 Subject: [PATCH 2/4] Migrated the phantom-key exorcism code to the other C128 mouse drivers. --- asminc/c128.inc | 1 + libsrc/c128/irq.s | 2 - libsrc/c128/mou/c128-inkwell.s | 88 ++++++++++++++++++++++++++------ libsrc/c128/mou/c128-pot.s | 92 ++++++++++++++++++++++++++++------ 4 files changed, 150 insertions(+), 33 deletions(-) diff --git a/asminc/c128.inc b/asminc/c128.inc index aac8678bf..6e3078297 100644 --- a/asminc/c128.inc +++ b/asminc/c128.inc @@ -32,6 +32,7 @@ FETCH := $2A2 ; Fetch subroutine in RAM FETVEC := $2AA ; Vector patch location for FETCH STASH := $2AF ; Stash routine in RAM STAVEC := $2B9 ; Vector patch location for STASH +IRQInd := $2FD ; JMP $0000 -- used as indirect IRQ vector PALFLAG := $A03 ; $FF=PAL, $00=NTSC INIT_STATUS := $A04 ; Flags: Reset/Restore initiation status FKEY_LEN := $1000 ; Function key lengths diff --git a/libsrc/c128/irq.s b/libsrc/c128/irq.s index aed1f3a25..79aa8faaa 100644 --- a/libsrc/c128/irq.s +++ b/libsrc/c128/irq.s @@ -7,8 +7,6 @@ .include "c128.inc" -IRQInd = $2FD ; JMP $0000 - used as indirect IRQ vector - ; ------------------------------------------------------------------------ .segment "INIT" diff --git a/libsrc/c128/mou/c128-inkwell.s b/libsrc/c128/mou/c128-inkwell.s index e74cacfc3..1e2f19844 100644 --- a/libsrc/c128/mou/c128-inkwell.s +++ b/libsrc/c128/mou/c128-inkwell.s @@ -1,7 +1,8 @@ ; ; Driver for the Inkwell Systems 170-C and 184-C lightpens. ; -; 2013-07-01, Greg King +; 2014-04-26, Christian Groessler +; 2014-05-01, Greg King ; .include "zeropage.inc" @@ -24,7 +25,7 @@ HEADER: ; Library reference -LIBREF: .addr $0000 +libref: .addr $0000 ; Jump table @@ -102,6 +103,14 @@ OldPenY: .res 1 INIT_save: .res 1 +; Keyboard buffer fill level at start of interrupt + +old_key_count: .res 1 + +; Original IRQ vector + +old_irq: .res 2 + .data ; Default Inkwell calibration. @@ -131,7 +140,7 @@ INSTALL: lda #%11000000 sta INIT_STATUS -; Initiate variables. Just copy the default stuff over. +; Initiate some variables. Just copy the default stuff over. ldx #.sizeof (DefVars) - 1 @L0: lda DefVars,x @@ -144,18 +153,57 @@ INSTALL: stx OldPenX sty OldPenY +; Initiate our IRQ magic. + + ; Remember the ROM IRQ continuation address. + ldx IRQInd+2 + lda IRQInd+1 + stx old_irq+1 + sta old_irq + + lda libref + ldx libref+1 + sta ptr3 ; Point to mouse_adjuster + stx ptr3+1 + + ; Set the ROM IRQ continuation address to point to the provided routine. + ldy #2 + lda (ptr3),y + iny + sei + sta IRQInd+1 + lda (ptr3),y + sta IRQInd+2 + + ; Set the address of our IRQ callback routine. + ; Because it's called via "rts", we must use "address-1". + iny + lda #<(callback-1) + sta (ptr3),y + iny + lda #>(callback-1) + sta (ptr3),y + + ; Set the ROM entry-point vector. + ; Because it's called via "rts", we must decrement it by one. + iny + lda old_irq + sub #<1 + sta (ptr3),y + iny + lda old_irq+1 + sbc #>1 + sta (ptr3),y + cli + ; Call a calibration function through the library-reference. - lda LIBREF - ldx LIBREF+1 - sta ptr1 ; Point to mouse_adjuster - stx ptr1+1 ldy #1 - lda (ptr1),y + lda (ptr3),y bze @L1 ; Don't call pointer if it's NULL sta Calibrate+2 ; Point to function dey - lda (ptr1),y + lda (ptr3),y sta Calibrate+1 lda #XOffset @@ -187,6 +235,13 @@ INSTALL: ; No return code required (the driver is removed from memory on return). UNINSTALL: + lda old_irq + ldx old_irq+1 + sei + sta IRQInd+1 + stx IRQInd+2 + ;cli + jsr HIDE ; Hide cursor on exit lda INIT_save sta INIT_STATUS @@ -346,6 +401,8 @@ IOCTL: lda #(callback-1) + sta (ptr3),y + + ; Set the ROM entry-point vector. + ; Because it's called via "rts", we must decrement it by one. + iny + lda old_irq + sub #<1 + sta (ptr3),y + iny + lda old_irq+1 + sbc #>1 + sta (ptr3),y cli ; Done, return zero (= MOUSE_ERR_OK) @@ -158,6 +204,13 @@ INSTALL: ; No return code required (the driver is removed from memory on return). UNINSTALL: + lda old_irq + ldx old_irq+1 + sei + sta IRQInd+1 + stx IRQInd+2 + ;cli + jsr HIDE ; Hide cursor on exit lda INIT_save sta INIT_STATUS @@ -259,6 +312,15 @@ MOVE: sei ; No interrupts BUTTONS: lda Buttons ldx #$00 + +; Make the buttons look like a 1351 mouse. + + and #JOY::LEFT | JOY::RIGHT + lsr a + lsr a + ;clc + adc #%00001110 + and #MOUSE_BTN_LEFT | MOUSE_BTN_RIGHT rts ;---------------------------------------------------------------------------- @@ -297,7 +359,7 @@ INFO: jsr POS ; Fill in the button state - lda Buttons + jsr BUTTONS ldy #MOUSE_INFO::BUTTONS sta (ptr1),y @@ -309,7 +371,7 @@ INFO: jsr POS ; Must return an error code in a/x. ; -IOCTL: lda #MOUSE_ERR_INV_IOCTL rts @@ -319,22 +381,17 @@ IOCTL: lda # Date: Mon, 5 May 2014 06:28:19 -0400 Subject: [PATCH 3/4] Back-migrated some phantom-key rejection optimizations. --- libsrc/c128/mou/c128-1351.s | 14 ++++++-------- libsrc/c128/mou/c128-joy.s | 34 ++++++++++------------------------ libsrc/c128/mou/callback.inc | 2 +- libsrc/c128/mouseref.s | 7 ++++++- 4 files changed, 23 insertions(+), 34 deletions(-) diff --git a/libsrc/c128/mou/c128-1351.s b/libsrc/c128/mou/c128-1351.s index e55c1d01b..89a32bbd5 100644 --- a/libsrc/c128/mou/c128-1351.s +++ b/libsrc/c128/mou/c128-1351.s @@ -3,7 +3,8 @@ ; the Commodore 1351 mouse users guide. ; ; 2009-09-26, Ullrich von Bassewitz -; 2014-03-17, Greg King +; 2014-04-26, Christian Groessler +; 2014-04-30, Greg King ; .include "zeropage.inc" @@ -12,8 +13,6 @@ .macpack generic -IRQInd = $2FD - ; ------------------------------------------------------------------------ ; Header. Includes jump table @@ -28,8 +27,7 @@ HEADER: ; Library reference -libref: - .addr $0000 +libref: .addr $0000 ; Jump table @@ -210,7 +208,7 @@ UNINSTALL: sta IRQInd+1 lda old_irq+1 sta IRQInd+2 - cli + ;cli jsr HIDE ; Hide cursor on exit lda INIT_save @@ -351,7 +349,7 @@ INFO: jsr POS ; Fill in the button state - jsr BUTTONS ; Will not touch ptr1 + lda Buttons ldy #MOUSE_INFO::BUTTONS sta (ptr1),y @@ -363,7 +361,7 @@ INFO: jsr POS ; Must return an error code in a/x. ; -IOCTL: lda #MOUSE_ERR_INV_IOCTL rts diff --git a/libsrc/c128/mou/c128-joy.s b/libsrc/c128/mou/c128-joy.s index c1dc2e019..2426ebd69 100644 --- a/libsrc/c128/mou/c128-joy.s +++ b/libsrc/c128/mou/c128-joy.s @@ -2,7 +2,8 @@ ; Driver for a "joystick mouse". ; ; 2009-09-26, Ullrich von Bassewitz -; 2014-03-17, Greg King +; 2014-04-26, Christian Groessler +; 2014-05-01, Greg King ; .include "zeropage.inc" @@ -11,8 +12,6 @@ .macpack generic -IRQInd = $2FD - ; ------------------------------------------------------------------------ ; Header. Includes jump table @@ -27,8 +26,7 @@ HEADER: ; Library reference -libref: - .addr $0000 +libref: .addr $0000 ; Jump table @@ -91,10 +89,6 @@ Buttons: .res 1 ; Button mask INIT_save: .res 1 -; Temporary value used in the int handler - -Temp: .res 1 - ; Keyboard buffer fill level at start of interrupt old_key_count: .res 1 @@ -215,7 +209,7 @@ UNINSTALL: sta IRQInd+1 lda old_irq+1 sta IRQInd+2 - cli + ;cli jsr HIDE ; Hide cursor on exit lda INIT_save @@ -318,6 +312,7 @@ MOVE: sei ; No interrupts BUTTONS: lda Buttons ldx #$00 + and #MOUSE_BTN_LEFT ; Left button -- same as JOY::FIRE rts ;---------------------------------------------------------------------------- @@ -356,7 +351,7 @@ INFO: jsr POS ; Fill in the button state - lda Buttons + jsr BUTTONS ldy #MOUSE_INFO::BUTTONS sta (ptr1),y @@ -368,7 +363,7 @@ INFO: jsr POS ; Must return an error code in a/x. ; -IOCTL: lda #MOUSE_ERR_INV_IOCTL rts @@ -387,19 +382,10 @@ IRQ: jsr CPREP lda CIA1_PRB ; Read joystick #0 and #$1F eor #$1F ; Make all bits active high - sta Temp - -; Check for a pressed button and place the result into Buttons - - ldx #$00 ; Assume no button pressed - and #JOY::FIRE ; Check fire button - beq @L0 ; Jump if not pressed - ldx #MOUSE_BTN_LEFT ; Left (only) button is pressed -@L0: stx Buttons + sta Buttons ; Check left/right - lda Temp ; Read joystick #0 and #(JOY::LEFT | JOY::RIGHT) beq @SkipX ; @@ -447,7 +433,7 @@ IRQ: jsr CPREP ; Calculate the Y movement vector -@SkipX: lda Temp ; Read joystick #0 +@SkipX: lda Buttons ; Read joystick #0 and #(JOY::UP | JOY::DOWN) ; Check up/down beq @SkipY ; @@ -499,5 +485,5 @@ IRQ: jsr CPREP clc ; Interrupt not "handled" rts -.define OLD_BUTTONS Temp ; tells callback.inc where the old port status is stored +.define OLD_BUTTONS Buttons ; tells callback.inc where the old port status is stored .include "callback.inc" diff --git a/libsrc/c128/mou/callback.inc b/libsrc/c128/mou/callback.inc index ea64b8913..9f1d749a7 100644 --- a/libsrc/c128/mou/callback.inc +++ b/libsrc/c128/mou/callback.inc @@ -4,7 +4,7 @@ ; ; Christian Groessler, 24.04.2014 ; -; Check if there was joystick activity before and/or after the ROM handler. +; Check if there was button/joystick activity before and/or after the ROM handler. ; If there was activity, discard the key presses since they are most ; probably "phantom" key presses. diff --git a/libsrc/c128/mouseref.s b/libsrc/c128/mouseref.s index 630ff573f..243eda804 100644 --- a/libsrc/c128/mouseref.s +++ b/libsrc/c128/mouseref.s @@ -1,7 +1,11 @@ ; ; Pointer for library references by device drivers. ; +; Helper-routines for the interrupt handler that rejects bogus keypresses +; that are caused by mouse-like devices. +; ; 2013-07-25, Greg King +; 2014-04-26, Christian Groessler ; .include "c128.inc" @@ -23,6 +27,7 @@ mouse_libref: ; generic label for mouse-kernel ; _pen_adjuster: .addr $0000 + .addr IRQStub2 callback: ; callback into mouse driver after ROM IRQ handler has been run .addr $0000 ; (filled in by mouse driver) @@ -83,7 +88,7 @@ IRQStub2: rts ; jump to callback routine @IRQCont2: - + ; return from interrupt ; We could just jump to $FF33, but since I don't know whether this address is valid in all ; ROM versions, duplicate that code here. From a27e7562fd04567f608606bd1b3dde566e792f93 Mon Sep 17 00:00:00 2001 From: Greg King Date: Mon, 5 May 2014 13:45:34 -0400 Subject: [PATCH 4/4] Added comments that explain why some instructions are implied. --- libsrc/c128/mou/c128-1351.s | 2 +- libsrc/c128/mou/c128-inkwell.s | 4 ++-- libsrc/c128/mou/c128-joy.s | 2 +- libsrc/c128/mou/c128-pot.s | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libsrc/c128/mou/c128-1351.s b/libsrc/c128/mou/c128-1351.s index 89a32bbd5..298cf9e13 100644 --- a/libsrc/c128/mou/c128-1351.s +++ b/libsrc/c128/mou/c128-1351.s @@ -208,7 +208,7 @@ UNINSTALL: sta IRQInd+1 lda old_irq+1 sta IRQInd+2 - ;cli + ;cli ; This will be done at end of HIDE jsr HIDE ; Hide cursor on exit lda INIT_save diff --git a/libsrc/c128/mou/c128-inkwell.s b/libsrc/c128/mou/c128-inkwell.s index 1e2f19844..0e45046e8 100644 --- a/libsrc/c128/mou/c128-inkwell.s +++ b/libsrc/c128/mou/c128-inkwell.s @@ -240,7 +240,7 @@ UNINSTALL: sei sta IRQInd+1 stx IRQInd+2 - ;cli + ;cli ; This will be done at end of HIDE jsr HIDE ; Hide cursor on exit lda INIT_save @@ -410,7 +410,7 @@ IRQ: jsr CPREP ldy #%00000000 ; Set ports A and B to input sty CIA1_DDRB sty CIA1_DDRA ; Keyboard won't look like buttons - ;lda #%01111111 + ;lda #%01111111 ; (Keyboard scan leaves this in port A) ;sta CIA1_PRA lda CIA1_PRB ; Read Control Port 1 dec CIA1_DDRA ; Set port A back to output diff --git a/libsrc/c128/mou/c128-joy.s b/libsrc/c128/mou/c128-joy.s index 2426ebd69..47a73c877 100644 --- a/libsrc/c128/mou/c128-joy.s +++ b/libsrc/c128/mou/c128-joy.s @@ -209,7 +209,7 @@ UNINSTALL: sta IRQInd+1 lda old_irq+1 sta IRQInd+2 - ;cli + ;cli ; This will be done at end of HIDE jsr HIDE ; Hide cursor on exit lda INIT_save diff --git a/libsrc/c128/mou/c128-pot.s b/libsrc/c128/mou/c128-pot.s index 0a3ed6051..43a4b40e9 100644 --- a/libsrc/c128/mou/c128-pot.s +++ b/libsrc/c128/mou/c128-pot.s @@ -209,7 +209,7 @@ UNINSTALL: sei sta IRQInd+1 stx IRQInd+2 - ;cli + ;cli ; This will be done at end of HIDE jsr HIDE ; Hide cursor on exit lda INIT_save @@ -318,8 +318,8 @@ BUTTONS: and #JOY::LEFT | JOY::RIGHT lsr a lsr a - ;clc - adc #%00001110 + ;clc ; ("lsr" shifted zero into carry flag) + adc #%00001110 ; Shift bit 1 over to bit 4 and #MOUSE_BTN_LEFT | MOUSE_BTN_RIGHT rts