From 784d6bc98427b34104b3326d9e016929237a4918 Mon Sep 17 00:00:00 2001 From: Peter Ferrie Date: Mon, 5 Mar 2018 22:00:06 -0800 Subject: [PATCH 1/2] support IIGS mouse --- mouse.gs.s | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++ mouse.s | 36 +++++++++++++++---- views.s | 2 ++ weegui.s | 3 +- 4 files changed, 134 insertions(+), 7 deletions(-) create mode 100644 mouse.gs.s diff --git a/mouse.gs.s b/mouse.gs.s new file mode 100644 index 0000000..1f0f75d --- /dev/null +++ b/mouse.gs.s @@ -0,0 +1,100 @@ +;=============================== +; Polled GS Mouse driver +; by John Brooks 3/6/1988 +; +; Modified 3/4/2018 for: +; 1) 65816 emulation mode +; 2) Cvt pixel pos to 80-col txt pos +; 3) Add comments +; +; Modified 2018/05/03 +; by Peter Ferrie for: +; 1) CC65 compatible +; 2) extensions for WeeGUI +;=============================== + +IoMouseStatus = $C027 +IoMouseData = $C024 + +;------------------------------- +; If GS mouse state has changed +; then update: +; MousePixX,Y +; MouseTxtX,Y +; MouseDownX,Y +; +; Entry: e=1, DP=$0000 +; Exit: e=1, DP=$0000, AXY=? +;------------------------------- +GsPollMouse: + lda IoMouseStatus ;Any new mouse data? + bpl GS_Mouse_Exit + and #2 ;If data reg is misaligned, realign with deltaX=2 + bne GS_Mouse_OnlyY + lda IoMouseData ;Read deltaX +GS_Mouse_OnlyY: + jsr WGUndrawPointer ; Erase the old mouse pointer + ldy IoMouseData ;Read deltaY + clc + .byte $FB ;xce ;65816 native mode +GS_Mouse_CheckX: + .byte $C2, $30 ;rep #$30 ;16-bit A,X,Y + .byte $A2, MousePixX ;ldx #MousePixX + jsr GS_Mouse_AddDelta ;Cvt to signed word, add to pixPos & range clamp + .byte $9D, <(MouseTxtX-MousePixX), >(MouseTxtX-MousePixX) ;sta MouseTxtX-MousePixX,x ;16-bit store overwrites Y +GS_Mouse_CheckY: + tya ;a=DeltaY + inx + inx ;x=MousePixY ptr + jsr GS_Mouse_AddDelta ;Cvt to signed word, add to pixPos & range clamp + .byte $E2, $21 ;sep #$21 ;8-bit acc, set carry + sta MouseTxtY-MousePixY,x + + tya + eor MouseBtn0-MousePixY,x ;Detect button0 up/down + bpl GS_Mouse_NoDownEdge + eor MouseBtn0-MousePixY,x ;Remove old button0 + sta MouseBtn0-MousePixY,x ;Save new button0 + bmi GS_Mouse_NoDownEdge + .byte $BC, <(MouseTxtX-MousePixY), >(MouseTxtX-MousePixY) ;ldy MouseTxtX-MousePixY,x + sty MouseDownX ;Set WG_MOUSECLICK_X & WG_MOUSECLICK_Y +GS_Mouse_NoDownEdge: + .byte $FB ;xce ;65816 emulation mode: 8-bit A,X,Y + jsr WGDrawPointer ; Redraw the pointer +GS_Mouse_Exit: + rts + +;------------------------------- + +GS_Mouse_AddDelta: + .byte $09, $80, $FF ;ora #$ff80 ;Extend neg 6-bit delta in anticipation of delta + .byte $89, $40, $00 ;bit #$0040 ;Check sign of delta + bne GS_Mouse_GotDelta +GS_Mouse_Pos: + .byte $29, $3F, $00 ;and #$003f ;Strip b7 button state from positive 6-bit delta +GS_Mouse_GotDelta: + clc + adc 0,x ;Apply delta to X or Y pixel position + bpl GS_Mouse_NoMinClamp + .byte $7B ;tdc ;Clamp neg position to zero +GS_Mouse_NoMinClamp: + .byte $DD, <(MouseMaxX-MousePixX), >(MouseMaxX-MousePixX) ;cmp MouseMaxX-MousePixX,x + bcc GS_Mouse_NoMaxClamp + .byte $BD, <(MouseMaxX-MousePixX), >(MouseMaxX-MousePixX) ;lda MouseMaxX-MousePixX,x + dec +GS_Mouse_NoMaxClamp: + sta 0,x ;Store mouse pixel position + lsr ;TextPos = PixelPos / 8 + lsr + lsr + rts + +GsDisableMouse: + pla + pla ; discard return address + stz WG_MOUSEACTIVE + jsr WGUndrawPointer ; Be nice if we're disabled during a program + pla + rts + +;------------------------------- diff --git a/mouse.s b/mouse.s index f4d232f..2269eec 100644 --- a/mouse.s +++ b/mouse.s @@ -75,6 +75,10 @@ WGEnableMouse: SETSWITCH PAGE2OFF + sec + .byte $C2, $01 ;REP #$01 ; clear carry flag on 65816 + bcc WGEnableMouse_IIGS + ; Find slot number and calculate the various indirections needed jsr WGFindMouse bcs WGEnableMouse_Error @@ -137,6 +141,12 @@ WGEnableMouse_IIe: CALLMOUSE CLAMPMOUSE bra WGEnableMouse_Activate +WGEnableMouse_IIGS: + lda #$20 ; JSR + sta WGEnableGSMouse + sta WGDisableGSMouse + bra WGEnableMouse_Activate + WGEnableMouse_Error: stz WG_MOUSEACTIVE @@ -180,6 +190,9 @@ WGDisableMouse: lda WG_MOUSEACTIVE ; Never activated the mouse beq WGDisableMouse_done +WGDisableGSMouse: + bit GsDisableMouse ; self-modified to JSR when appropriate + lda MOUSEMODE_OFF CALLMOUSE SETMOUSE @@ -603,10 +616,6 @@ renderPointerMode: WG_MOUSEACTIVE: .byte 0 -WG_MOUSEPOS_X: -.byte 39 -WG_MOUSEPOS_Y: -.byte 11 WG_MOUSE_STAT: .byte 0 WG_MOUSEBG: @@ -614,20 +623,35 @@ WG_MOUSEBG: WG_APPLEIIC: .byte 0 WG_MOUSE_JUMPL: +MousePixX: ;(GS-overload) Mouse pixel position 0-639 (word) .byte 0 WG_MOUSE_JUMPH: .byte 0 WG_MOUSE_SLOT: +MousePixY: ;(GS-overload) Mouse pixel position 0-191 (word) .byte 0 WG_MOUSE_SLOTSHIFTED: .byte 0 +WG_MOUSE_BUTTON_DOWN: +MouseBtn0: ;(GS-overload) Previous btn0 state used for edge detect +.byte 0 +WG_MOUSEPOS_X: +MouseTxtX: ;(GS-overload) Mouse text position 0-79 +.byte 39 +WG_MOUSEPOS_Y: +MouseTxtY: ;(GS-overload) Mouse text position 0-23 +.byte 11 WG_MOUSECLICK_X: +MouseDownX: ;(GS-overload) Mouse click pos 0-79 .byte $ff WG_MOUSECLICK_Y: +MouseDownY: ;(GS-overload) Mouse click pos 0-23 .byte 0 -WG_MOUSE_BUTTON_DOWN: -.byte 0 +MouseMaxX: +.word 80*8 ;(GS-extension) Mouse max X = 640 +MouseMaxY: +.word 24*8 ;(GS-extension) Mouse max Y = 192 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/views.s b/views.s index 1d02ea6..8641046 100644 --- a/views.s +++ b/views.s @@ -1067,6 +1067,8 @@ WGViewFocusAction_knownRTS: WGPendingViewAction: SAVE_AY +WGEnableGSMouse: + bit GsPollMouse ; self-modified to JSR when appropriate lda WG_MOUSECLICK_X bmi WGPendingViewAction_done diff --git a/weegui.s b/weegui.s index 7f5d04b..2c44dde 100644 --- a/weegui.s +++ b/weegui.s @@ -182,6 +182,7 @@ WG80: .include "rects.s" .include "views.s" .include "mouse.s" +.include "mouse.gs.s" .include "applesoft.s" .include "memory.s" @@ -193,4 +194,4 @@ WG80: .SEGMENT "STARTUP" .SEGMENT "INIT" .SEGMENT "LOWCODE" - +.SEGMENT "ONCE" From 91515d510db77ab3c0d29f08606238625e3da20e Mon Sep 17 00:00:00 2001 From: Peter Ferrie Date: Tue, 6 Mar 2018 15:13:14 -0800 Subject: [PATCH 2/2] rename file and document 65816 detection --- mouse.s | 4 ++++ mouse.gs.s => mouse_gs.s | 13 ++++++------- weegui.s | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) rename mouse.gs.s => mouse_gs.s (85%) diff --git a/mouse.s b/mouse.s index 2269eec..96bf2e6 100644 --- a/mouse.s +++ b/mouse.s @@ -75,6 +75,10 @@ WGEnableMouse: SETSWITCH PAGE2OFF + ; Warning! + ; We're relying on the fact that the 65C02 treats undefined opcodes as NOPs here! + ; (in the same way that ProDOS 2.4.2 does) + sec .byte $C2, $01 ;REP #$01 ; clear carry flag on 65816 bcc WGEnableMouse_IIGS diff --git a/mouse.gs.s b/mouse_gs.s similarity index 85% rename from mouse.gs.s rename to mouse_gs.s index 1f0f75d..e88a500 100644 --- a/mouse.gs.s +++ b/mouse_gs.s @@ -41,7 +41,7 @@ GS_Mouse_CheckX: .byte $C2, $30 ;rep #$30 ;16-bit A,X,Y .byte $A2, MousePixX ;ldx #MousePixX jsr GS_Mouse_AddDelta ;Cvt to signed word, add to pixPos & range clamp - .byte $9D, <(MouseTxtX-MousePixX), >(MouseTxtX-MousePixX) ;sta MouseTxtX-MousePixX,x ;16-bit store overwrites Y + .byte $95, MouseTxtX-MousePixX ;sta MouseTxtX-MousePixX,x ;16-bit store overwrites Y GS_Mouse_CheckY: tya ;a=DeltaY inx @@ -56,13 +56,11 @@ GS_Mouse_CheckY: eor MouseBtn0-MousePixY,x ;Remove old button0 sta MouseBtn0-MousePixY,x ;Save new button0 bmi GS_Mouse_NoDownEdge - .byte $BC, <(MouseTxtX-MousePixY), >(MouseTxtX-MousePixY) ;ldy MouseTxtX-MousePixY,x + ldy MouseTxtX-MousePixY,x sty MouseDownX ;Set WG_MOUSECLICK_X & WG_MOUSECLICK_Y GS_Mouse_NoDownEdge: .byte $FB ;xce ;65816 emulation mode: 8-bit A,X,Y - jsr WGDrawPointer ; Redraw the pointer -GS_Mouse_Exit: - rts + jmp WGDrawPointer ; Redraw the pointer ;------------------------------- @@ -78,15 +76,16 @@ GS_Mouse_GotDelta: bpl GS_Mouse_NoMinClamp .byte $7B ;tdc ;Clamp neg position to zero GS_Mouse_NoMinClamp: - .byte $DD, <(MouseMaxX-MousePixX), >(MouseMaxX-MousePixX) ;cmp MouseMaxX-MousePixX,x + cmp MouseMaxX-MousePixX,x bcc GS_Mouse_NoMaxClamp - .byte $BD, <(MouseMaxX-MousePixX), >(MouseMaxX-MousePixX) ;lda MouseMaxX-MousePixX,x + lda MouseMaxX-MousePixX,x dec GS_Mouse_NoMaxClamp: sta 0,x ;Store mouse pixel position lsr ;TextPos = PixelPos / 8 lsr lsr +GS_Mouse_Exit: rts GsDisableMouse: diff --git a/weegui.s b/weegui.s index 2c44dde..33f697e 100644 --- a/weegui.s +++ b/weegui.s @@ -182,7 +182,7 @@ WG80: .include "rects.s" .include "views.s" .include "mouse.s" -.include "mouse.gs.s" +.include "mouse_gs.s" .include "applesoft.s" .include "memory.s"