diff --git a/input/pcanalog.s b/input/pcanalog.s index 8fedb292..812000b2 100644 --- a/input/pcanalog.s +++ b/input/pcanalog.s @@ -1,29 +1,207 @@ -; GEOS by Berkeley Softworks -; reverse engineered by Maciej Witkowiak, Michael Steil -; ; pcanalog input driver +.include "const.inc" +.include "geossym.inc" +.include "geosmac.inc" +.include "jumptab.inc" +.include "c64.inc" + .segment "inputdrv" -.byte $4c, $94, $fe, $4c, $a0, $fe, $4c, $a1, $fe, $00, $2d, $33, $39, $07, $05, $39 -.byte $3e, $43, $08, $04, $a9, $00, $85, $3b, $a9, $00, $85, $3a, $a9, $00, $85, $3c -.byte $60, $24, $30, $10, $fb, $a5, $01, $48, $a9, $35, $85, $01, $ad, $00, $dc, $48 -.byte $ad, $02, $dc, $48, $ad, $03, $dc, $48, $a9, $ff, $8d, $02, $dc, $a9, $40, $8d -.byte $00, $dc, $a2, $66, $ea, $ea, $ea, $ca, $d0, $fa, $ad, $19, $d4, $cd, $8a, $fe -.byte $30, $08, $cd, $8c, $fe, $10, $3a, $4c, $42, $ff, $85, $02, $ad, $8b, $fe, $38 -.byte $e5, $02, $85, $02, $ad, $8d, $fe, $85, $04, $a9, $00, $85, $03, $85, $05, $a2 -.byte $02, $a0, $04, $20, $69, $c1, $a5, $3a, $38, $e5, $02, $85, $3a, $a5, $3b, $f0 -.byte $07, $e9, $00, $85, $3b, $4c, $42, $ff, $b0, $fb, $a9, $00, $85, $3a, $4c, $42 -.byte $ff, $38, $ed, $8b, $fe, $85, $02, $ad, $8e, $fe, $85, $04, $a9, $00, $85, $03 -.byte $85, $05, $a2, $02, $a0, $04, $20, $69, $c1, $a5, $3a, $18, $65, $02, $85, $3a -.byte $a5, $3b, $69, $00, $85, $3b, $f0, $cd, $a5, $3a, $c9, $40, $30, $c7, $a9, $3f -.byte $85, $3a, $ad, $1a, $d4, $cd, $8f, $fe, $30, $08, $cd, $91, $fe, $10, $32, $4c -.byte $ab, $ff, $85, $02, $ad, $90, $fe, $38, $e5, $02, $85, $02, $ad, $92, $fe, $85 -.byte $04, $a9, $00, $85, $03, $85, $05, $a2, $02, $a0, $04, $20, $69, $c1, $a5, $3c -.byte $38, $e5, $02, $90, $05, $85, $3c, $4c, $ab, $ff, $a9, $00, $85, $3c, $4c, $ab -.byte $ff, $38, $ed, $90, $fe, $85, $02, $ad, $93, $fe, $85, $04, $a9, $00, $85, $03 -.byte $85, $05, $a2, $02, $a0, $04, $20, $69, $c1, $a5, $3c, $18, $65, $02, $c9, $c7 -.byte $b0, $05, $85, $3c, $4c, $ab, $ff, $a9, $c7, $85, $3c, $a9, $00, $8d, $02, $dc -.byte $8d, $03, $dc, $ad, $01, $dc, $29, $0c, $cd, $89, $fe, $f0, $13, $8d, $89, $fe -.byte $0a, $0a, $0a, $0a, $10, $01, $0a, $8d, $05, $85, $a5, $39, $09, $20, $85, $39 -.byte $68, $8d, $03, $dc, $68, $8d, $02, $dc, $68, $8d, $00, $dc, $68, $85, $01, $60 +; Analog PC joystick input driver by Maciej Witkowiak + +; original comment header - 1999-06-23 +; +;Input driver for analogue PC joystick connected to C64/128 Control Port #1 +;as paddles +;it could be fairly optimized, I must have been blind when I +;coded this :) +;screen ranges checking are unnecessary - Kernal does it + +;this code is for GEOS 64 v2.0 + +;Maciej 'YTM/Alliance' Witkowiak +;back in '97 +;rewritten for GNU, TASM version with macros +;I hope that it still works +;23.6.99 + +; end of original comment header +; +; adapted for cc65 on 2021-06-03 by Maciej Witkowiak + + +MouseInit: + jmp Init ;MOUSE_JMP +SlowMouse: + jmp Exit ;SlowMouse +UpdateMouse: + jmp Update ;UpdateMouse + +.ifdef bsw128 +SetMouse: + jmp Exit + jmp Exit ; ??? why it's here? +.endif + +lastF: .byte 0 ;last status of Fire + +; calibration values +; [xlow,xav] and [xav,xhigh] are ignored, this is center joystick jitter +xlow: .byte $2d ;less than this are 'left' +xav: .byte $33 ;middle POTX +xhigh: .byte $39 ;higher than this are 'right' +xlostp: .byte $07 ;step in middle-low X +xhstep: .byte $05 ;step in middle-high X +ylow: .byte $39 ;same as x but for POTY +yav: .byte $3e +yhigh: .byte $43 +ylstep: .byte $08 +yhstep: .byte $04 + +Init: LoadW mouseXPos, 0 ;init mouse=init position + sta mouseYPos +Exit: rts + +;UpdateMouse is called by IRQ routine + +Update: bbrf MOUSEON_BIT, mouseOn, Exit + START_IO + PushB cia1base+0 ;preserve keyboard port + PushB cia1base+2 + PushB cia1base+3 + LoadB cia1base+2, $ff + LoadB cia1base+0, %01000000 ;select paddle 1 (out of 4) + + ldx #$66 +: nop ;delay for SID for loading + nop ;POT capacitors + nop + dex + bne :- + + CmpB sidbase+$19, xlow ;read X register + bmi XLO + cmp xhigh + bpl XHI + jmp ReadY + +XLO: sta r0L ;proceed with left + lda xav + sub r0L + sta r0L + MoveB xlostp, r1L + LoadB r0H, 0 + sta r1H + + ldx #r0L + ldy #r1L + jsr Ddiv + + SubB r0L, mouseXPos + lda mouseXPos+1 + beq Hi0 + sbc #0 + sta mouseXPos+1 + +yread: jmp ReadY +Hi0: bcs yread + LoadB mouseXPos, 0 + jmp ReadY + +XHI: sub xav ;proceed with right + sta r0L + lda xhstep +.ifdef bsw128 + bbrf 7, graphMode, XHok ;check 40/80 mode + lsr +XHok: +.endif + sta r1L + LoadB r0H, 0 + sta r1H + ldx #r0L + ldy #r1L + jsr Ddiv + + AddB r0L, mouseXPos + lda mouseXPos+1 + adc #0 + sta mouseXPos+1 + beq yread +.ifndef bsw128 + CmpBI mouseXPos, (320-256) + bmi yread + LoadB mouseXPos, (319-256) +.endif + +ReadY: CmpB sidbase+$1a, ylow ;read Y register + bmi YLO + cmp yhigh + bpl YHI + jmp ReadF + +YLO: sta r0L ;proceed with up + lda yav + sub r0L + sta r0L + MoveB ylstep, r1L + LoadB r0H, 0 + sta r1H + ldx #r0L + ldy #r1L + jsr Ddiv + + lda mouseYPos + sub r0L + bcc YZe + sta mouseYPos + jmp ReadF + +YZe: LoadB mouseYPos, 0 + jmp ReadF + +YHI: sub yav ;proceed with down + sta r0L + MoveB yhstep, r1L + LoadB r0H, 0 + sta r1H + ldx #r0L + ldy #r1L + jsr Ddiv + + lda mouseYPos + add r0L +.ifdef bsw128 + sta mouseYPos +.else + cmp #199 + bcs YMax + sta mouseYPos + jmp ReadF + +YMax: LoadB mouseYPos, 199 +.endif + +ReadF: LoadB cia1base+2, 0 ;read fire status + sta cia1base+3 + lda cia1base+1 + and #%00001100 ;read both fire buttons + cmp lastF + beq Finish + sta lastF + asl a + asl a + asl a + asl a + bpl Fire2 + asl a +Fire2: sta mouseData + smbf MOUSE_BIT, pressFlag + +Finish: PopB cia1base+3 + PopB cia1base+2 + PopB cia1base+0 + END_IO + rts +