Mouse
Jump to navigation
Jump to search
Contents
NEOS driver
By "Kakemoms"
; Mouse driver *=9999 JMP mouseinit mouseirq LDA $9111 PHA LDA $9113 PHA LDA #0 STA $3 STA $4 STA $0 LDA $9113 AND #%11000000 ; Retain bit 6&7 ORA #%00100000 ; Bit 5 output STA $9113 ; Set direction LDX #8 mouseloop LDA $9111 AND #%11011111 ; Clear bit 5 STA $9111 ; Trigger NEOS mouse JSR waitsome LDX #$7F STX $9122 ; Set VIA2 to listen for joystickport LDA $9120 AND #$80 ; S3 LDX #$FF STX $9122 ; Set VIA2 to listen for keyboard again STA $3 LDA $9111 AND #%00011100 ; S2, S1, S0 ASL ASL ORA $3 ; Add bit 7 STA $3 LDA $9111 ORA #%00100000 ; set bit 5 STA $9111 ; Trigger NEOS mouse LDX #5 JSR waitsome LDX #$7F STX $9122 ; Set VIA2 to listen for joystickport LDA $9120 AND #$80 ; S3 LDX #$FF STX $9122 ; Set VIA2 to listen for keyboard again LSR LSR LSR LSR ORA $3 STA $3 LDA $9111 AND #%00011100 ; S2, S1, S0 LSR LSR ORA $3 ; Add other bits STA $3 LDX $0 CPX #0 BNE mousecalc INC $0 STA $4 ; x-value here LDX #5 JMP mouseloop mousecalc ; use delta values to calculate new postitions PLA STA $9113 PLA STA $9111 sec lda xval ; low byte sbc $4 ; add delta x (signed) sta xval sec lda yval ; low byte sbc $3 ; add delta x (signed) sta yval mouseprint LDA xval STA sval LDA #0 STA star LDA #24 ; "X" JSR showvalue LDA yval STA sval LDA #6 STA star LDA #25 ; "Y" JSR showvalue mouseirqend JMP $eabf ; return to normal IRQ xval word 0 yval word 0 waitsome NOP NOP NOP DEX BNE waitsome RTS showvalue ; shows an integer value LDX star STA $1000,X LDA #"=" STA $1001,X LDA sval JSR div10 TAY JSR div10 TAX JSR mult10 STA $6 TYA SEC SBC $6 ; tenths CLC ADC #48 STA $0 ; temp storage TXA ADC #48 LDX star STA $1002,X ; hundreds LDA $0 STA $1003,X ; hundreds TYA JSR mult10 STA $6 LDA sval SEC SBC $6 CLC ADC #48 LDX star STA $1004,X ; 0-9 LDA #2 STA $9400,X STA $9401,X STA $9402,X STA $9403,X STA $9404,X RTS sval byte 0 star byte 0 div10 lsr sta $5 lsr adc $5 ror lsr lsr adc $5 ror adc $5 ror lsr lsr rts mult10 asl sta $5 asl asl clc adc $5 rts mouseinit lda #$7f sta $912e ; disable and acknowledge interrupts sta $912d sync ; synchronize with the screen ldx #28 ; wait for this raster line (times 2) resync cpx $9004 bne resync timers lda #$40 ; enable Timer A free run of both VIAs sta $911b sta $912b lda timerv ; length of timer low byte ldx timerv+1 ; length of timer high byte sta $9116 ; load the timer 1 low byte sta $9126 ; load the timer low byte counter stx $9125 ; start the IRQ timer A (high byte latch) ldy #10 ; spend some time dey ; before starting the reference timer bne *-1 stx $9115 ; start the reference timer pointers lda #<mouseirq; set the raster IRQ routine pointer sta $314 lda #>mouseirq sta $315 lda #$c0 sta $912e ; enable Timer A underflow interrupts rts ; return timerv word 21849 ; once per screen update
Amiga mouse, Atari ST mouse and Atari CX22/CX80 trackball drivers
http://hem.bredband.net/magli143/vic20/prop.zip
C1351
impossible http://cbm-hackers.2304266.n4.nabble.com/1351-mouse-and-the-VIC20-td4662788.html
Serial mouse
requires RS-232 interface