Merge pull request #16 from peterferrie/master

support IIGS mouse
This commit is contained in:
blondie7575 2018-03-06 18:04:52 -08:00 committed by GitHub
commit 0f28ef8960
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 137 additions and 7 deletions

40
mouse.s
View File

@ -75,6 +75,14 @@ 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
; Find slot number and calculate the various indirections needed
jsr WGFindMouse
bcs WGEnableMouse_Error
@ -137,6 +145,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 +194,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 +620,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 +627,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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

99
mouse_gs.s Normal file
View File

@ -0,0 +1,99 @@
;===============================
; 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, >MousePixX ;ldx #MousePixX
jsr GS_Mouse_AddDelta ;Cvt to signed word, add to pixPos & range clamp
.byte $95, 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
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
jmp WGDrawPointer ; Redraw the pointer
;-------------------------------
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:
cmp MouseMaxX-MousePixX,x
bcc GS_Mouse_NoMaxClamp
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:
pla
pla ; discard return address
stz WG_MOUSEACTIVE
jsr WGUndrawPointer ; Be nice if we're disabled during a program
pla
rts
;-------------------------------

View File

@ -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

View File

@ -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"