Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > NEOS mouse, losing my hair...
2018-09-30 11:57
jamiefuller
Account closed

Registered: Mar 2018
Posts: 25
NEOS mouse, losing my hair...

Hi All,

Please can anyone help, I am trying to read the signal from the NEOS mouse, I have this bit working based on some code from the c64-wiki and a working mouse pointer.
But no matter what I do it massively interferes with the keyboard.

I have heard the mouse works with GEOS so it must be theoretically possible (unless the NEOS only works with GEOS in joystick mode).

The source code is below and also on pastebin, I've tried to make it as readable as possible but my code isn't always the tidiest. :)

https://pastebin.com/SSbUbvhx

basically it runs every frame to poll the mouse, it puts the values into some variables (set to the screen in this example to make it visible)

the background colour should only change if the W key is being pressed, but it triggers even when not pressing due to the mouse.

Would be grateful of any advice.

Thanks
Jamie


VIC_SPRITE_MSB=$D010
VIC_SPRITE_ENABLE=$D015
VIC_SPRITE_YEXPAND=$D017
VIC_SPRITE_PRIORITY=$D01B
VIC_SPRITE_MULTICOLOUR=$D01C
VIC_SPRITE_XEXPAND=$D01D
VIC_BORDERCOLOUR=$D020
VIC_BGCOLOUR=   $D021
VIC_BGCOLOUR_MC1=$D022
VIC_BGCOLOUR_MC2=$D023

VIC_SPRITE_MC1= $D025
VIC_SPRITE_MC2= $D026

CIA_1  =        $dc00            ; CIA#1 (Port Register A)
CIA_2  =        $dc01            ; CIA#2 (Port Register B)

CIA_ddra =      $dc02            ; CIA#1 (Data Direction Register A)
CIA_ddrb =      $dc03            ; CIA#2 (Data Direction Register B)
XPADDLE=        $d419
MOUSEX=         $0400
MOUSEY=         $0401
MOUSEX_SPEED=   $0428 ;$19
MOUSEY_SPEED=   $0429 ;$1a
MDBUTTON=       $0459

; 10 SYS2064

*=$0801

        BYTE    $0B, $08, $0A, $00, $9E, $32, $30, $36, $34, $00, $00, $00



*=$0810



init    

        ; copy sprite data to sprite location
        ldy     #$3F
@in10   lda     spritedata,y
        sta     $0340,y
        dey
        bpl     @in10

        lda     #$0D    ;set sprite pointer
        sta     $07F8
        lda     #$01    ;switch on sprite 1
        sta     VIC_SPRITE_ENABLE
        lda     #$07    ;set sprite colour to yellow
        sta     $D027


        lda     #%01111111
        sta     $DC0D       ;"Switch off" interrupts signals from CIA-1
        and     $D011
        sta     $D011       ;Clear most significant bit in VIC's raster register

        lda     #$51         
        sta     $D012       ; set raster to occour 1 lines down

        lda     #<irq_handler
        sta     $0314       ; set low bit of start
        lda     #>irq_handler
        sta     $0315       ; set high bit of start

        lda     #%00000001
        sta     $D01A
@endloop
        jmp @endloop


irq_handler
        LDA     #$00
        STA     VIC_BORDERCOLOUR
        jsr     handlekeyboard
        jsr     handlemouseneos
        JSR     DRAWSPRITE
        INC     VIC_BORDERCOLOUR

        asl     $D019
        JMP     $EA31


DRAWSPRITE
        lda     MOUSEX
        clc
        adc     #$0C
        asl     a
        pha
        bcc     @ds10
        lda     VIC_SPRITE_MSB
        ora     #$01
        bne     @ds20
@ds10   lda     VIC_SPRITE_MSB
        and     #$FE
@ds20   sta     VIC_SPRITE_MSB
        pla
        sta     $D000   ; sprite X
        clc
        lda     MOUSEY
        adc     #$32
        sta     $D001   ; sprite y
        rts





handlekeyboard
        lda     #$0
        sta     CIA_ddra   ;Port A data direction register.
        lda     #$0
        sta     CIA_ddrb   ;Port B data direction register.
@up   
        lda     #%11111101  ;
        sta     CIA_1 
        lda     CIA_2       ; load column information
        and     #%00000010  ; test 'w' key  
        bne     @noup       ; zero flag is not set -> skip next command
        inc     VIC_BGCOLOUR
@noup    
        rts





handlemouseneos
@LC020  jsr     @LC100
        lda     #$00
        bcc     @LC029
        lda     #$02
@LC029  sta     MDBUTTON
        jsr     @LC190
        lda     CIA_2 ; left button
        and     #$10
        BNE     @RT
        INC     MDBUTTON
@RT
        rts

@LC100   ; READ MOUSE
        lda     #$10 
        sta     CIA_ddrb   ;Port B data direction register.
        LDA     #$ef   
        sta     CIA_2   ;PORT B
        lda     CIA_2   ;PORT B, read 4 bits
        asl     a
        asl     a
        asl     a
        asl     a
        sta     MOUSEX_SPEED     ; TIMES BY 16 AND STORE AT $19
        LDA     #$10
        sta     CIA_2
        lda     CIA_2   ; read 4 bits
        and     #$0F
        ora     MOUSEX_SPEED
        sta     MOUSEX_SPEED
        LDA     #$EF
        sta     CIA_2
        lda     CIA_2
        asl     a
        asl     a
        asl     a
        asl     a
        sta     MOUSEY_SPEED
        LDA     #$10
        sta     CIA_2
        lda     CIA_2
        and     #$0F
        ora     MOUSEY_SPEED
        sta     MOUSEY_SPEED
        lda     XPADDLE
        cmp     #$FF
        rts


@LC190   ; TRANSLATE BASED ON SPEED
        lda     MOUSEX_SPEED
        bmi     @LC1A2
        sec
        lda     MOUSEX
        sbc     MOUSEX_SPEED
        bcs     @LC1AF
        lda     #$00
        beq     @LC1AF
@LC1A2  sec
        lda     MOUSEX
        sbc     MOUSEX_SPEED
        bcs     @LC1AD
        cmp     #$A0
        bcc     @LC1AF
@LC1AD  lda     #$9F
@LC1AF  sta     MOUSEX
        lda     MOUSEY_SPEED
        bmi     @LC1C0
        sec
        lda     MOUSEY
        sbc     MOUSEY_SPEED
        bcs     @LC1CD
        lda     #$00
        beq    @LC1CD
@LC1C0  sec
        lda     MOUSEY
        sbc     MOUSEY_SPEED
        bcs     @LC1CB
        cmp     #$C8
        bcc     @LC1CD
@LC1CB  lda     #$C7
@LC1CD  sta     MOUSEY
        rts



spritedata
        byte    $FC,$00,$00,$F0,$00,$00,$F0,$00,$00,$D8,$00,$00,$8C,$00,$00,$86,$00,$00,$03
        bytes   63

 
... 41 posts hidden. Click here to view all posts....
 
2018-10-01 14:35
JackAsser

Registered: Jun 2002
Posts: 1989
Quote: it actually makes sense to get a +/- 1 additive jitter due to how the ADC works.(*) and i really wonder now why i never saw this happen :)

(*) actually due to how the ADC _and_ the mouse works... you'd expect it to get even worse. which probably is the reason for why bit 0 is undefined for the mouse data. but... but... *shrug*


I only observe a 0/+1 jitter. If I poll POTX and output the value to screen I can see it wiggle between say $12 and $13. If I move the mouse ever so slightly it will wiggle between $13 and $14. Also the jitter is not everywhere but only between frequent spans within the valid values perfectly repetitive. I can f.e. have it rock solid between say (values just made up here because I don't know the exact value) 10-17, the jitterish numbers between 18-1f, then stable again between 20-27 etc.
2019-04-17 17:29
JackAsser

Registered: Jun 2002
Posts: 1989
@jamie: Did you ever found the cause of the problem?

I’m having the same issue..
2019-04-17 17:32
jamiefuller
Account closed

Registered: Mar 2018
Posts: 25
Quote: @jamie: Did you ever found the cause of the problem?

I’m having the same issue..


Sorry but I didn't. I believe there is no reliable way. And have never seen anything actually work with both keyboard and neos mouse. I gave up eventually and.restricted the game (portal) to 1351 mouse only which works much happier with the keyboard.
2019-04-17 17:34
JackAsser

Registered: Jun 2002
Posts: 1989
Quote: Sorry but I didn't. I believe there is no reliable way. And have never seen anything actually work with both keyboard and neos mouse. I gave up eventually and.restricted the game (portal) to 1351 mouse only which works much happier with the keyboard.

Was this behaviour confirmed on real HW? I’m inches away from testing myself.
2019-04-17 17:43
JackAsser

Registered: Jun 2002
Posts: 1989
Confirmed here @5:45: https://youtu.be/z5znM56lgGw
2019-04-17 19:32
JackAsser

Registered: Jun 2002
Posts: 1989
I really don't get NEOS. Toggling clk to get higher and lower nibbles, that's fine. But how do you know if you're reading X or Y?
2019-04-17 20:34
JackAsser

Registered: Jun 2002
Posts: 1989
Quote: I really don't get NEOS. Toggling clk to get higher and lower nibbles, that's fine. But how do you know if you're reading X or Y?

Fyi:

”you know what
you are reading because the state machine in the neos mouse resets when you
dont toggle clk for a couple hundred cycles or so. and yeah, it interfers with
the keyboard. and you can only use the right button as intended. it sux :)
guess thats why it never became popular =)”

I’ll drop support for it. Sorry NEOS-users.

It will support joy-mode though.
2019-04-19 08:26
Oswald

Registered: Apr 2002
Posts: 5017
well, you could make a cia timer interrupt to poke the mice every couple hundred cycles :P :) but I havent even heard of this mouse so far, so I guess its not so important.
2019-04-19 12:49
ChristopherJam

Registered: Aug 2004
Posts: 1378
Quoting Oswald
I havent even heard of this mouse so far, so I guess its not so important.


It's the only c64 mouse I have :''''(


(but seriously, nice work on the port thus far Jackie - totally understand the need for triage!)
2019-04-19 19:13
JackAsser

Registered: Jun 2002
Posts: 1989
Quote: well, you could make a cia timer interrupt to poke the mice every couple hundred cycles :P :) but I havent even heard of this mouse so far, so I guess its not so important.

The problem is not reading the mouse. That works very well. The problem is the mouse driving random crap on the bus. When it's deactive, i.e. timeouted in the internal state machine it should release the bus, but it doesn't. Hence it will always intefere with the keyboard no matter what. It's even stated in the user manual that you must LOAD+RUN _before_ plugging_ in the mouse because the keyboard is destroyed.

So no, there are limits to what crap I will support. :D
Previous - 1 | 2 | 3 | 4 | 5 | 6 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Andy/AEG
Krill/Plush
Black/Angels
neoman/titan
Mason/Unicess
Hihot/Skylight Designs
t0m3000/ibex-crew
Grue/Extend
Mythus/Delysid
Guests online: 125
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Comaland 100%  (9.6)
6 No Bounds  (9.6)
7 Uncensored  (9.6)
8 Wonderland XIV  (9.6)
9 Bromance  (9.6)
10 Memento Mori  (9.6)
Top onefile Demos
1 It's More Fun to Com..  (9.7)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 TRSAC, Gabber & Pebe..  (9.5)
6 Rainbow Connection  (9.5)
7 Onscreen 5k  (9.5)
8 Wafer Demo  (9.5)
9 Dawnfall V1.1  (9.5)
10 Quadrants  (9.5)
Top Groups
1 Oxyron  (9.3)
2 Nostalgia  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Logo Graphicians
1 Sander  (10)
2 Facet  (9.7)
3 Mermaid  (9.4)
4 Pal  (9.4)
5 Shine  (9.3)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.048 sec.