Rewrite Subor Mouse code, fixed latch updating outside of strobe.
This commit is contained in:
parent
ce4221c425
commit
9d9eb868bc
|
@ -18,64 +18,59 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
// implementation of Subor Mouse
|
||||
// used in Educational Computer 2000
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "share.h"
|
||||
|
||||
typedef struct {
|
||||
int32 mzx, mzy, mzxold, mzyold;
|
||||
uint32 readbit;
|
||||
uint32 data;
|
||||
uint8 latch;
|
||||
int32 mx,my;
|
||||
int32 lmx,lmy;
|
||||
uint32 mb;
|
||||
} MOUSE;
|
||||
|
||||
static MOUSE Mouse;
|
||||
|
||||
static void StrobeMOUSE(int w)
|
||||
{
|
||||
Mouse.readbit=0;
|
||||
Mouse.latch = Mouse.mb & 0x03;
|
||||
|
||||
int32 dx = Mouse.mx - Mouse.lmx;
|
||||
int32 dy = Mouse.my - Mouse.lmy;
|
||||
|
||||
Mouse.lmx = Mouse.mx;
|
||||
Mouse.lmy = Mouse.my;
|
||||
|
||||
if (dx > 0) Mouse.latch |= (0x2 << 2);
|
||||
else if (dx < 0) Mouse.latch |= (0x3 << 2);
|
||||
if (dy > 0) Mouse.latch |= (0x2 << 4);
|
||||
else if (dy < 0) Mouse.latch |= (0x3 << 4);
|
||||
|
||||
//FCEU_printf("Subor Mouse: %02X\n",Mouse.latch);
|
||||
}
|
||||
|
||||
static uint8 ReadMOUSE(int w)
|
||||
{
|
||||
uint8 ret=0;
|
||||
if(Mouse.readbit>=8)
|
||||
ret|=1;
|
||||
else
|
||||
{
|
||||
ret|=(Mouse.data>>Mouse.readbit)&1;
|
||||
if(!fceuindbg)
|
||||
Mouse.readbit++;
|
||||
}
|
||||
return(ret);
|
||||
uint8 result = Mouse.latch & 0x01;
|
||||
Mouse.latch = (Mouse.latch >> 1) | 0x80;
|
||||
return result;
|
||||
}
|
||||
|
||||
static void UpdateMOUSE(int w, void *data, int arg)
|
||||
{
|
||||
uint32 *ptr=(uint32*)data;
|
||||
Mouse.data=0;
|
||||
Mouse.mzxold=Mouse.mzx;
|
||||
Mouse.mzyold=Mouse.mzy;
|
||||
Mouse.mzx=ptr[0];
|
||||
Mouse.mzy=ptr[1];
|
||||
Mouse.data|=ptr[2];
|
||||
if((Mouse.mzxold-Mouse.mzx)>0)
|
||||
Mouse.data|=0x0C;
|
||||
else if((Mouse.mzxold-Mouse.mzx)<0)
|
||||
Mouse.data|=0x04;
|
||||
if((Mouse.mzyold-Mouse.mzy)>0)
|
||||
Mouse.data|=0x30;
|
||||
else if((Mouse.mzyold-Mouse.mzy)<0)
|
||||
Mouse.data|=0x10;
|
||||
uint32 *ptr=(uint32*)data;
|
||||
Mouse.mx = ptr[0];
|
||||
Mouse.my = ptr[1];
|
||||
Mouse.mb = ptr[2];
|
||||
}
|
||||
|
||||
static INPUTC MOUSEC={ReadMOUSE,0,StrobeMOUSE,UpdateMOUSE,0,0};
|
||||
|
||||
INPUTC *FCEU_InitMouse(int w)
|
||||
{
|
||||
Mouse.mzx=0;
|
||||
Mouse.mzy=0;
|
||||
Mouse.mzxold=0;
|
||||
Mouse.mzyold=0;
|
||||
Mouse.data=0;
|
||||
return(&MOUSEC);
|
||||
memset(&Mouse,0,sizeof(Mouse));
|
||||
return(&MOUSEC);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue