Mice and mouse queues...

Anything QL Software or Programming Related.
User avatar
mk79
QL Wafer Drive
Posts: 1349
Joined: Sun Feb 02, 2014 10:54 am
Location: Esslingen/Germany
Contact:

Mice and mouse queues...

Post by mk79 »

Peter wrote:How can non-SMSQ/E pointer environment run on Atari?
http://qlwiki.qlforum.co.uk/doku.php?id ... l_emulator
There were QL emulators for Atari long before the development of SMSQ/E. I'd even venture the guess that SMS2 and subsequently SMSQ/E were developed on an Atari.


User avatar
Peter
QL Wafer Drive
Posts: 1953
Joined: Sat Jan 22, 2011 8:47 am

Re: Mice and mouse queues...

Post by Peter »

mk79 wrote:
Peter wrote:How can non-SMSQ/E pointer environment run on Atari?
http://qlwiki.qlforum.co.uk/doku.php?id ... l_emulator
There were QL emulators for Atari long before the development of SMSQ/E. I'd even venture the guess that SMS2 and subsequently SMSQ/E were developed on an Atari.
...which may explain why Tony Tebby used the Atari partition scheme for IDE harddisks on the Q40, although the PC partition scheme was just as simple, und more widely used.


User avatar
Peter
QL Wafer Drive
Posts: 1953
Joined: Sat Jan 22, 2011 8:47 am

Re: Mice and mouse queues...

Post by Peter »

mk79 wrote:
Peter wrote:By the way, which mouse interfaces are supported by the non-SMSQ/E pointer environment?
viewtopic.php?t=2282#p21392 :-P
Since then only support for QemuLator has been added.
I was wondering about the best way for mouse support under Q68 Minerva/QDOS Classic. Getting the mouse data is trivial, since the loader configures everything. Only the simple PS/2 stream needs to be read. And it is sufficient to poll the mouse at 50 Hz without separate interrupt (although it is available). This does not really justify a separate driver like Sermouse, moreover I don't know how Sermouse passes the data to the PE, not sure there is a defined interface for that task.
Last edited by Peter on Fri Feb 12, 2021 9:36 am, edited 1 time in total.


User avatar
Peter
QL Wafer Drive
Posts: 1953
Joined: Sat Jan 22, 2011 8:47 am

Re: Mice and mouse queues...

Post by Peter »

Here's a C code snipped showing how to read Q68 mouse data.
Of course it works only, if the OS is not also polling the mouse.

Code: Select all

#define MOUSE_CODE (* (volatile unsigned char*) 0x1C160)
#define MOUSE_UNLOCK (* (volatile unsigned char*) 0x1C164)
#define MOUSE_STATUS (* (volatile unsigned char*) 0x1C168)

// Read movement data from PS/2 mouse in stream mode
// Requires previously initialized mouse (done by bootloader)
//
// Polling routine, does not wait if no new movement data available
//
// Receiving further mouse data is held back until next call,
// so a slow polling rate of about 50 Hz should be fine
//
// Note: It seems wrong information that movement values are 9 bit,
// where the most significant bit appears as sign bit in the status byte!
// 
// X and Y movement appeared 8 bit signed, the sign bit in status was 
// only a copy of the MSB
//
// Output data (must be kept between calls):
// stat  Bit 7..3 not needed (Y overflow,	X overflow, Y sign bit, X sign bit, 1)
//       Bit 2: Middle button, Bit 1:Right Button, Bit 0:Left Button
// dx    Relative X movement of mouse since last report (8 bit signed)
// dy    Relative Y movement of mouse since last report (8 bit signed)
//
// Return value:
// 0=More bytes need to be received, output data is invalid
// 1=Movement Data Packet complete, output data for stat, dx, dy is valid

unsigned char GetPS2MouseMove(char id, unsigned char* stat, signed char* dx, signed char*dy, signed char*dz)
{
  static short stream_state = 0;
  if(MOUSE_STATUS & 0x01) // Bit 0 high: Mouse code received
  {
    if (stream_state == 0)
      *stat = MOUSE_CODE;
    else if (stream_state == 1)
      *dx = MOUSE_CODE;
    else if (stream_state == 2)
      *dy = MOUSE_CODE;
    else // stream_state == 3
      *dz = MOUSE_CODE;
    MOUSE_UNLOCK = 0x01; // Unlock PS/2 receive
    if ((stream_state < 2) || ((id > 0) && (stream_state < 3)))
      stream_state++;
    else
    {
      stream_state = 0;
      return 1; // Movement data complete
    }
  }
  return 0; // More bytes required to complete packet from host
}


User avatar
mk79
QL Wafer Drive
Posts: 1349
Joined: Sun Feb 02, 2014 10:54 am
Location: Esslingen/Germany
Contact:

Re: Mice and mouse queues...

Post by mk79 »

Generally there is not a huge difference between an external mouse driver and one integrated into PTR_GEN, the latter just has the added convenience of not having to load a second file but also the inconvenience of being dead code to all other platforms, though if it's small enough there is no reason not to include it. In any case it probably makes sense to write an external driver first and then think about integrating it. Of course one additional requirement for an integrated driver is a 100% reliable way of detecting the platform at hand. How would you check for a Q68?

Also, what is the "id" parameter?


User avatar
Peter
QL Wafer Drive
Posts: 1953
Joined: Sat Jan 22, 2011 8:47 am

Re: Mice and mouse queues...

Post by Peter »

I think Minerva and QDOS Classic are (by far) not used as much as SMSQ/E on the Q68, so maybe better if the PE is not bloated with support for Q68.
I simply don't know how to "feed" the pointer data into the PE, nor if there is a defined interface to do that in a clean manner.
Is there documentation to look at?

Sorry for forgetting to comment the "id" parameter, it is 0 for standard PS/2 mouse and 3 for Intellimouse.
Bit 4 of the MOUSE_STATUS register can tell which one: 0 for standard mouse, 1 for Intellimouse.
(And since hardware registers are faster than SDRAM, it makes sense to remove the "id" parameter and check the register bit inside the mouse polling routine.)


User avatar
ppe
Trump Card
Posts: 171
Joined: Tue Dec 14, 2010 10:48 am
Location: Espoo, Finland

Re: Mice and mouse queues...

Post by ppe »

mk79 wrote:The mouse directly reports the increments it measured (by adding/subtracting to a central variable pt_inc)
I'm quite ignorant in all things PE so very sorry if this is a stupid question but what is the correct procedure (in ASM) for obtaining the address of this variable in PE running on QDOS?


User avatar
mk79
QL Wafer Drive
Posts: 1349
Joined: Sun Feb 02, 2014 10:54 am
Location: Esslingen/Germany
Contact:

Re: Mice and mouse queues...

Post by mk79 »

Peter wrote:I think Minerva and QDOS Classic are (by far) not used as much as SMSQ/E on the Q68, so maybe better if the PE is not bloated with support for Q68.
I simply don't know how to "feed" the pointer data into the PE, nor if there is a defined interface to do that in a clean manner.
Is there documentation to look at?
There is no defined interface nor documentation, drivers write directly into the driver variables. I can hack something together when I find a little bit of time.


User avatar
mk79
QL Wafer Drive
Posts: 1349
Joined: Sun Feb 02, 2014 10:54 am
Location: Esslingen/Germany
Contact:

Re: Mice and mouse queues...

Post by mk79 »

ppe wrote:I'm quite ignorant in all things PE so very sorry if this is a stupid question but what is the correct procedure (in ASM) for obtaining the address of this variable in PE running on QDOS?
Open CON channel, find channel definition block of channel, get driver definition block out of it. I'll write something up.


User avatar
Peter
QL Wafer Drive
Posts: 1953
Joined: Sat Jan 22, 2011 8:47 am

Re: Mice and mouse queues...

Post by Peter »

mk79 wrote:There is no defined interface nor documentation, drivers write directly into the driver variables.
I think it would be of general interest where to find those variables within the driver definition block.
Can the PE variables be updated any time, or is there a synchronisation?
mk79 wrote: I can hack something together when I find a little bit of time.
That's kind but I think you have more important QL work.
If I can find the variables, I hope my rusted assembler knowledge is still sufficient.
(Maybe it can also be seen in the Sermouse sources, if they are available somewhere?)


Post Reply