Vic-20 mouse driver & demo program for NEOS mouse

Basic and Machine Language

Moderator: Moderators

Kakemoms
Vic 20 Nerd
Posts: 740
Joined: Sun Feb 15, 2015 8:45 am

Re: Vic-20 mouse driver & demo program for NEOS mouse

Post by Kakemoms »

Kananga wrote: You don't have to disassemble, just grab the code here and feel free to improve it: http://sourceforge.net/projects/vin20/
(Included is a preview of a dynamic loader called "LibTool65" and tools for the FE3)
There is no code there, only compiled binary?
Kananga
Vic 20 Afficionado
Posts: 317
Joined: Mon Mar 08, 2010 2:11 pm

Re: Vic-20 mouse driver & demo program for NEOS mouse

Post by Kananga »

Kakemoms wrote:
Kananga wrote: You don't have to disassemble, just grab the code here and feel free to improve it: http://sourceforge.net/projects/vin20/
(Included is a preview of a dynamic loader called "LibTool65" and tools for the FE3)
There is no code there, only compiled binary?
I checked permissions, but didnt see anything wrong.
Try this link and send me a pm if it doesnt work:
https://sourceforge.net/p/vin20/code/HEAD/tree/
Buy the new Bug-Wizard, the first 100 bugs are free!
Kakemoms
Vic 20 Nerd
Posts: 740
Joined: Sun Feb 15, 2015 8:45 am

Re: Vic-20 mouse driver & demo program for NEOS mouse

Post by Kakemoms »

Kananga wrote:
Kakemoms wrote:
Kananga wrote: You don't have to disassemble, just grab the code here and feel free to improve it: http://sourceforge.net/projects/vin20/
(Included is a preview of a dynamic loader called "LibTool65" and tools for the FE3)
There is no code there, only compiled binary?
I checked permissions, but didnt see anything wrong.
Try this link and send me a pm if it doesnt work:
https://sourceforge.net/p/vin20/code/HEAD/tree/
Yikes, there it is. Its made in some other programming environment than the neos driver code but if one can get a grip on the irq and structure, it might be possible. I will need to fix the serial interference first though.
User avatar
pixel
Vic 20 Scientist
Posts: 1329
Joined: Fri Feb 28, 2014 3:56 am
Website: http://hugbox.org/
Location: Berlin, Germany
Occupation: Pan–galactic shaman

Re: Vic-20 mouse driver & demo program for NEOS mouse

Post by pixel »

Damn. Ermh… My… the customs stole my web cam and there isn't any broom anyway around here. Maybe later. :p
A man without talent or ambition is most easily pleased. Others set his path and he is content.
https://github.com/SvenMichaelKlose
Kakemoms
Vic 20 Nerd
Posts: 740
Joined: Sun Feb 15, 2015 8:45 am

Re: Vic-20 mouse driver & demo program for NEOS mouse

Post by Kakemoms »

pixel wrote:Damn. Ermh… My… the customs stole my web cam and there isn't any broom anyway around here. Maybe later. :p
Lol. Well, I just ordered a modern memory expansion from dorktronic on ebay. It can be set to 3K-32K expansion mode so I can test different memory configurations. The reason is that the NEOS mouse - VIA interference only happends when I plug in the memory expansion, so I want to see if I can circumvent it or if it is related to my specific expansion.

Now, getting hold of a NEOS mouse is not so easy, so I am thinking of making a PS/2 - NEOS interface so it can be enjoyed by others. Just waiting for some Arduino Nano boards and C64 gameport cables. We'll see were it ends up..

As for the 1351.. well, the sampling rate issue is not so easy to solve.
Kakemoms
Vic 20 Nerd
Posts: 740
Joined: Sun Feb 15, 2015 8:45 am

Re: Vic-20 mouse driver & demo program for NEOS mouse

Post by Kakemoms »

Another update:
I got the dorktronic 3-32K expansion and it did not help. Anyway its a very nice expansion. :wink:

Examining what is actually happening, I have this explanation to the problem:

Once the NEOS mouse has been triggered(via the lightpen output) to start sending data, it just sends, sends and continue to hammer the game port. Since it uses joy1,2,3,4 to transmit the change in mouse position, this is hammering the $9120 (Port B I/O register) of the VIA2 chip. The reason is that bit 7 of this register for some reason also picks up joy 3 on game port pin 4. So when the Vic-20 tries to poll the keyboard, it gets interference from gameport pin 4 (joy3) into bit 7 of $9120. That messes up column 7 data which shows up as mistyped keys ("2","4" + some others). For some reason "6" and "8" keys still work, so this theory may not be entirely correct.

The only thing that seems to "prevent" this is when the NEOS mouse is actually moved (e.g. one can type "2" and "4"). It may be that the interfered bit switches from 1 to 0 (or vice versa) by the mouse, which would indicate that bit 7 of $9120 is completely hijacked by the NEOS mouse as long as it is connected.

I haven't found ways to get the NEOS mouse to stop hammering data yet as there is no way to switch it off. I will continue to look for a solution even if it may require some delicate timing relation between reading/triggering the NEOS and reading the keyboard (if possible).

Edit: A quick & dirty solution is to disconnect the wire in the NEOS mouse that is connected to "joy3" (left) pin on the Vic-20 control port. This should remove the keyboard interference without affecting the operation of the mouse (if you trigger it once per screen update). The reason is that joy3 is used for bit3 and bit7 of the communication, but even fast mouse movements seldom go above +7 or -7 in delta x or delta y (7*50=350 pixels/second). For bit7 one can easily copy bit6 as it would only indicate the sign of the delta number. I need to test this to confirm, plus it may not help for the serial port interference in which you may need to remove the mouse or put in a switch (to switch it off when loading or using the keyboard).

I will continue to look for alternate solutions, but as this looks like a hardware problem it will probably require some fiddiling with the mouse itself.

Most interesting I found this on another forum which claims that the first 1351 were in fact NEOS mouses. You can even see the NEOS MB88201 chip inside: http://www.retrocomputacion.com/e107_pl ... .php?80555
Kakemoms
Vic 20 Nerd
Posts: 740
Joined: Sun Feb 15, 2015 8:45 am

Re: Vic-20 mouse driver & demo program for NEOS mouse

Post by Kakemoms »

I updated the NM.PRG demo, removed the LOAD bug and removed JOY3 utilization (so you can cut the wire going to pin4 if you want to, its not used anymore).
Kakemoms
Vic 20 Nerd
Posts: 740
Joined: Sun Feb 15, 2015 8:45 am

Re: Vic-20 mouse driver & demo program for NEOS mouse

Post by Kakemoms »

Updated to work without pin4:Here is a bare version of the NEOS mouse driver which shows x-coordinate and y-coordinate on screen, but no pointer/gfx. Its 360 bytes (from 7320). Source code is here. It also shifts basic memory end to 7368, leaving you with 3272 bytes free basic mem..

Some of the code is actually the drawing routine for the coordinates, so if you dont need it you can delete the section "showmouse" and "mouseprint".

Edit: You can also remove the screen raster sync in the irq init section++, plus you can remove the mouseinit section once the irq is initialized. I managed to get the whole code down to about 200 bytes quite easily by condensing it a little further. Of this only about 150 bytes is the actual irq reading the mouse, so you end up with 3431 bytes free. HERE is a minimized code (you need to use print peek(5) ; peek(6) to see x & y-values after you run it).

Edit: Forgot to put in the pin4-cut update in this one. You can do so yourself by correcting the code by using this routine instead:

Code: Select all

        LDA     #0
        STA     $3
        STA     $4
        STA     $0

        LDA     $9113           ; Set direction
        AND     #%11000000      ; Bit 5 output
        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     #0 ;#$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

        LDX     #$FF
        STX     $9122   ; Set VIA2 to listen for keyboard again

        LDA     $9111
        ORA     #%00100000      ; set bit 5
        STA     $9111           ; Trigger NEOS mouse
        LDX     #8
        JSR     waitsome

        LDX     #$7F
        STX     $9122   ; Set VIA2 to listen for joystickport
        LDA     $9120
        AND     #0 ;#$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
; set negative bit without joy3 signal:
        asl
        clc
        bpl     *+5
        sec                ;compensate for missing bit7
        ora     #%00010000 ;compensate for missing bit3
        ror
        sta     $3

        LDX     #$FF
        STX     $9122   ; Set VIA2 to listen for keyboard again
 
        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
Happy coding!
Last edited by Kakemoms on Fri Dec 04, 2015 12:26 pm, edited 2 times in total.
blackystardust
Vic 20 Newbie
Posts: 12
Joined: Sat Jan 14, 2006 6:31 pm

Re: Vic-20 mouse driver & demo program for NEOS mouse

Post by blackystardust »

The issue of the neos mouse not working is xvic (VICE) has been fixed in rev. 30232.
Kakemoms
Vic 20 Nerd
Posts: 740
Joined: Sun Feb 15, 2015 8:45 am

Re: Vic-20 mouse driver & demo program for NEOS mouse

Post by Kakemoms »

blackystardust wrote:The issue of the neos mouse not working is xvic (VICE) has been fixed in rev. 30232.
Yes and no. It works, mostly. There are some issues with the timing of the interpretation in VICE vs the real hardware, so in some instances the VICE emulation misses the opportunity to sync its mouse emulation with the program and it results in the x- and y- axis being interchanged.

A quick fix in the different NEOS driver programs is to add a "NOP" under the "waitsome" routine to get it to work under VICE (works in some instances at least).
Last edited by Kakemoms on Mon Nov 30, 2015 2:44 pm, edited 1 time in total.
groepaz
Vic 20 Scientist
Posts: 1180
Joined: Wed Aug 25, 2010 5:30 pm

Re: Vic-20 mouse driver & demo program for NEOS mouse

Post by groepaz »

you must "plug in" the mouse before starting the program - else the axis may be swapped.... and the same happens on the real machine!
I'm just a Software Guy who has no Idea how the Hardware works. Don't listen to me.
Kakemoms
Vic 20 Nerd
Posts: 740
Joined: Sun Feb 15, 2015 8:45 am

Re: Vic-20 mouse driver & demo program for NEOS mouse

Post by Kakemoms »

groepaz wrote:you must "plug in" the mouse before starting the program - else the axis may be swapped.... and the same happens on the real machine!
Are you sure? I have never seen that happen on a real machine. E.g at first trigger the mouse always starts with the x-axis, then the y-axis. If you wait for a while, it will always start with the x-axis again, even if you don't read the y-axis.

I will go and test it on real hardware to see if I can replicate the swap.

Test result: I can't replicate the swap on a real Vic-20 with a NEOS mouse. I also tested with the pin 4 removed and it still shows the correct axis behavior.
Last edited by Kakemoms on Mon Nov 30, 2015 3:40 pm, edited 1 time in total.
blackystardust
Vic 20 Newbie
Posts: 12
Joined: Sat Jan 14, 2006 6:31 pm

Re: Vic-20 mouse driver & demo program for NEOS mouse

Post by blackystardust »

For proper emulation I need to know the following:

How many cycles does it take (minimum) for the y axis data to be skipped ??

In a test program you can do the following:
1- read x
2- nop (2 cycle wait)
3- read y and compare to x, if they are not the same increase wait time by another 2 cycles
Kakemoms
Vic 20 Nerd
Posts: 740
Joined: Sun Feb 15, 2015 8:45 am

Re: Vic-20 mouse driver & demo program for NEOS mouse

Post by Kakemoms »

blackystardust wrote:For proper emulation I need to know the following:

How many cycles does it take (minimum) for the y axis data to be skipped ??

In a test program you can do the following:
1- read x
2- nop (2 cycle wait)
3- read y and compare to x, if they are not the same increase wait time by another 2 cycles
Well, there are alot of instructions to actually read x. You first read 4 bits, then another 4 bits and put them together to form 8-bits of delta-x/y value (change in position since last reading).

I have changed the sourcecode of Neostext.asm in which I insterted a new "LDX #value" + "JSR waitsome" (8 cycles). The waitsome is a loop that takes "DEX+BNE" (5 cycles)*value + "rts" (6 cycles).

What I found is that if value=18 I still get the Y value from the second reading 4bits+4bits. If value=19 it looks like its reading the first Y in some instances, but if value=20 it only reads X value (e.g. twice, even if the second reading is only catching 4 bits). E.g. the threshold timing is about 114 cycles + 118 cycles (other stuff) from the last TRIGGER of the second 4 bits of the X-value (e.g. STA $9111) until the first TRIGGER of the first 4 bits of the Y-value. E.g. if there is a total of 232 cycles between these, you will not get the Y-value, while a total of 222 cycles between them will give you all Y-values and smooth mouse reading. Since 227 cycles between them seems to give some Y-values, it shows how unsyncronized the NEOS clock is with the Vic-20. It is probably a little temperature dependent as well for that reason, so I wonder if one could use it to actually measure the temperature.. :lol:
blackystardust
Vic 20 Newbie
Posts: 12
Joined: Sat Jan 14, 2006 6:31 pm

Re: Vic-20 mouse driver & demo program for NEOS mouse

Post by blackystardust »

Thank you for investigating and timing results, thanks to you the neos mouse emulation in vice should now be working as it should.
Post Reply