Kempston Mouse - how to read?

ZX80, ZX 81, ZX Spectrum, TS2068 and other clones
Post Reply
rkd77
Member
Posts: 50
Joined: Sun May 04, 2008 10:35 am

Kempston Mouse - how to read?

Post by rkd77 »

Hello,
I wanted to write a program using Kempston Mouse.

Code: Select all

/* zcc +zxansi -vn -lndos -create-app -o kemp.bin kemp.c */
#include <input.h>
#include <stdio.h>
#include <graphics.h>
#include <games.h>

uchar in_KempcoordX, in_KempcoordY, in_KemprawX, in_KemprawY;

static void
move_cursor(unsigned char y, unsigned char x)
{
        printf("\033[%u;%uH", y + 1, x + 1);
}

static uchar spr[] = { 8,8,255,127,63,31,15,7,3,1};

int
main(void)
{
        void *sp = spr;
        unsigned char but;
        unsigned int x, y, x1, y1;
        x = 0;
        y = 0;
        in_MouseKempInit();
        in_MouseKempSetPos(x, y);
        clg();
        putsprite(SPR_XOR, x, y, sp);
        while (1)
        {
                in_MouseKemp(&but, &x1, &y1);

                if (x != x1 || y != y1)
                {
                        putsprite(SPR_XOR, x, y, sp);
                        x = x1;
                        y = y1;
                        putsprite(SPR_XOR, x, y, sp);
                        move_cursor(0, 0);
                        printf("%d %d    ", x, y);
                }
        }
        return 0;
}
I run it in fuse. The mouse can be moved in xrange(128, 255), but when I tried to move it left below 128, the mouse cursor jumps to 0 or 255. Is it a bug in the z88dk or in the fuse?
Could you show a snippet how to use Kempston Mouse in z88dk?
Timmy
Well known member
Posts: 393
Joined: Sat Mar 10, 2012 4:18 pm

Post by Timmy »

I just wrote my own test program too, and I've tested it in Fuse as well as in some other emulator, and I get also only get mouse_x between 128 and 255.

So I guess it's not a bug in fuse, but likely in INMouseKemp.asm. (which I'm unfortunately not good enough to fix it.)
Last edited by Timmy on Tue Jan 21, 2014 9:41 pm, edited 1 time in total.
Timmy
Well known member
Posts: 393
Joined: Sat Mar 10, 2012 4:18 pm

Post by Timmy »

Oh. I've actually figured out what the problem was.

There is a part in INMouseKemp.asm that caused this:

Code: Select all

.negdx
   add a,b
   jp po, Xok
   xor a
I've tested it by swapping it with something awful:

Code: Select all

  .negdx
    ld c,a
    add a,b
    cp c
    jp c, Xok
    xor a
This one works. Definitely not the best solution, and I'm sure Alvin will have a better one later on. :)
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

A fix is committed.. you can pick up new zx clibs from the nightly build starting from Jan 22 or have a look at the changed files, documented at http://z88dk.cvs.sourceforge.net/viewvc ... /spectrum/ (look at the files changed recently) . The build should be made in a few hours.

There are two fixes:

* changes to set mouse position -- setting the y coordinate was not correct

* changes to INMouseKemp as Timmy pointed out. In addition to the problem around 128, I've also limited the maximum x coordinate change to 80 pixels. This is because modern mice have much finer steps than the original Kempston mouse had so on emulators it is possible to move a modern mouse quickly enough that the program confuses right movement with left movement and vice versa. Hopefully, limiting delta to 80 pixels will make it harder for this to happen. Velesoft's moden kempston mouse interface actually has a switch to slow down modern mice and emulators should really supply the same.
Definitely not the best solution, and I'm sure Alvin will have a better one later on
Well not really :D but I will leave it like that for now and do something better in the new libraries instead. There are spectrum models with > 256 pixels resolution so state needs to be integer rather than char.
rkd77
Member
Posts: 50
Joined: Sun May 04, 2008 10:35 am

Post by rkd77 »

Thanks, zxvnc is ready, but performance is poor.
stefano
Well known member
Posts: 2151
Joined: Mon Jul 16, 2007 7:39 pm

Post by stefano »

I'm curious now.. what zxvnc is ?
rkd77
Member
Posts: 50
Joined: Sun May 04, 2008 10:35 am

Post by rkd77 »

github.com/rkd77/zxvnc
Spectrum (spectranet,kempston mouse) <-> zxvnc <-> vncserver
stefano
Well known member
Posts: 2151
Joined: Mon Jul 16, 2007 7:39 pm

Post by stefano »

Very interesting,I though the mouse was needed for a vnc client, but I supposed it was a server...
Post Reply