Hyperkin SNES mouse issues

Topics regarding the Uzebox hardware/AVCore/BaseBoard (i.e: PCB, resistors, connectors, part list, schematics, hardware issues, etc.) should go here.
User avatar
ry755
Posts: 226
Joined: Mon May 22, 2017 6:01 am

Hyperkin SNES mouse issues

Post by ry755 »

I'm currently working on a Uzebox project which requires a mouse, so I bought this 3rd party SNES mouse hoping it would work with Uzebox: https://www.amazon.com/Hyperkin-Hyper-C ... B0734BCWS1
Unfortunately it doesn't get detected, I tried Whack-a-Mole and the controller tester but it didn't seem to be detected at all. This mouse uses an optical sensor instead of a ball like the original SNES mouse so it probably doesn't like the Uzebox's faster timing. I don't have a real SNES to test it with, so for all I know this mouse could be defective. But most likely the Uzebox is just too fast for it, probably the same issue as in the wireless controller thread: http://uzebox.org/forums/viewtopic.php?f=4&t=1887

So what I'm wondering is, would it be possible to slow down the mouse polling just enough to fix this, without messing up the timing for other things? Or maybe this isn't worth it since I saw some discussion about possibly using PS/2 mice, but I don't know if anyone ever got that working.
User avatar
ry755
Posts: 226
Joined: Mon May 22, 2017 6:01 am

Re: Hyperkin SNES mouse issues

Post by ry755 »

I messed around with the timing in ReadButtons() and was able to make it kinda work:



But there's obviously still something wrong as it keeps resetting and sometimes randomly jumps around. Here's my modified version:
(I tried multiple different ways and this was the only one that made the mouse get detected at all)

Code: Select all

void ReadButtons(){
	unsigned int p1ButtonsLo=0,p2ButtonsLo=0;
	unsigned char i;

	//latch controllers
	JOYPAD_OUT_PORT|=_BV(JOYPAD_LATCH_PIN);
	#if SNES_MOUSE == 1
		if(snesMouseEnabled){
				WaitUs(1);
		}else{
			Wait200ns();
			Wait200ns();
		}	
	#else
		Wait200ns();
		Wait200ns();
	#endif
	JOYPAD_OUT_PORT&=~(_BV(JOYPAD_LATCH_PIN));

	//read button states
	for(i=0;i<16;i++){

		p1ButtonsLo>>=1;
		p2ButtonsLo>>=1;

		#if SNES_MOUSE == 1
			if(snesMouseEnabled){
				WaitUs(5);
			}else{
				Wait200ns();
				Wait200ns();
			}
		#else
			Wait200ns();
			Wait200ns();
		#endif
			
		//pulse clock pin		
		JOYPAD_OUT_PORT&=~(_BV(JOYPAD_CLOCK_PIN));
		
		// NEW *******************************************
		#if SNES_MOUSE == 1
			WaitUs(16); // wait for mouse
		#endif
		// *************************************************
		
		if((JOYPAD_IN_PORT&(1<<JOYPAD_DATA1_PIN))==0) p1ButtonsLo|=(1<<15);
		if((JOYPAD_IN_PORT&(1<<JOYPAD_DATA2_PIN))==0) p2ButtonsLo|=(1<<15);

		JOYPAD_OUT_PORT|=_BV(JOYPAD_CLOCK_PIN);
		
		#if SNES_MOUSE == 1
			if(snesMouseEnabled){
				WaitUs(5);
			}else{
				Wait200ns();
				Wait200ns();
			}
		#else
			Wait200ns();
			Wait200ns();
		#endif

	}

	#if JOYSTICK==TYPE_SNES
		joypad1_status_lo=p1ButtonsLo;
		joypad2_status_lo=p2ButtonsLo;
	#else
		joypad1_status_lo=p1ButtonsLo&0xff;
		joypad2_status_lo=p2ButtonsLo&0xff;	
	#endif

	if(joypad1_status_lo==(BTN_START+BTN_SELECT+BTN_Y+BTN_B) || joypad2_status_lo==(BTN_START+BTN_SELECT+BTN_Y+BTN_B)){
		SoftReset();
	}

}
This page has some info about the Hyperkin mouse: https://wiki.nesdev.com/w/index.php/Mouse
User avatar
D3thAdd3r
Posts: 3221
Joined: Wed Apr 29, 2009 10:00 am
Location: Minneapolis, United States

Re: Hyperkin SNES mouse issues

Post by D3thAdd3r »

From the information on that Wiki you need 8*14 SNES cycles=112 Uzebox cycles=~3.4us between bits, and then 8*28 SNES cycles=224 Uzebox cycles=~7.4us between the 3rd and 4th bytes. My early morning math might suck, but it seems like you have things right except maybe there is too short of delay between 2nd and 3rd bytes/subsequent call. If I remember the mouse routine just calls ReadButtons() twice in succession which would not meet the 7.4us requirement?
User avatar
uze6666
Site Admin
Posts: 4801
Joined: Tue Aug 12, 2008 9:13 pm
Location: Montreal, Canada
Contact:

Re: Hyperkin SNES mouse issues

Post by uze6666 »

I though I was on spec, but may have overlooked something and my Nintendo mouse could cope with it. Have you tested your Hyperkin mouse on a real SNES?
User avatar
ry755
Posts: 226
Joined: Mon May 22, 2017 6:01 am

Re: Hyperkin SNES mouse issues

Post by ry755 »

uze6666 wrote: Thu Feb 09, 2023 10:14 pm I though I was on spec, but may have overlooked something and my Nintendo mouse could cope with it. Have you tested your Hyperkin mouse on a real SNES?
Unfortunately I don't have a real SNES to test with :(
User avatar
uze6666
Site Admin
Posts: 4801
Joined: Tue Aug 12, 2008 9:13 pm
Location: Montreal, Canada
Contact:

Re: Hyperkin SNES mouse issues

Post by uze6666 »

I have one but will have to dig in my storage unit for it!
User avatar
danboid
Posts: 1937
Joined: Sun Jun 14, 2020 12:14 am

Re: Hyperkin SNES mouse issues

Post by danboid »

I've tried ry755's patch and can confirm what he reports about it mostly working under controller tester but it doesn't fix anything for Whack-a-mole.

Did you try DA's suggestion ry755?

Why is the mouse only supported in port 2?
User avatar
danboid
Posts: 1937
Joined: Sun Jun 14, 2020 12:14 am

Re: Hyperkin SNES mouse issues

Post by danboid »

I have updated/rewritten the wiki mouse page:

https://uzebox.org/wiki/Uzebox_Mouse
User avatar
danboid
Posts: 1937
Joined: Sun Jun 14, 2020 12:14 am

Re: Hyperkin SNES mouse issues

Post by danboid »

The Hyper Click seems to be detected by Solitaire and the left click works but I cannot move the cursor properly, which is stuck to moving erratically horizontally across the top of the screen.

Unlike the other apps, you need to plug the mouse into the first controller port to use the calculator but again I can only move the mouse horizontally. I'm not sure if the mouse buttons work as I can't move the cursor over a button and the cursor doesn't change when I click.
User avatar
uze6666
Site Admin
Posts: 4801
Joined: Tue Aug 12, 2008 9:13 pm
Location: Montreal, Canada
Contact:

Re: Hyperkin SNES mouse issues

Post by uze6666 »

Some gentleman on nesdev.org seems to have found a solution to this issue. As many, I implemented the read code based on the official mouse specs. But apparently Hyperkin implemented the timing based on how Mario Paint was actually polling the mouse (and hence every other game following it that probably copied it's timing). Seems Mario Paint added some additional and specific timing delay between the polling of bytes 2 and 3 for whatever reasons? Anybody tested this already?
Post Reply