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.
Post Reply
User avatar
ry755
Posts: 157
Joined: Mon May 22, 2017 6:01 am

Hyperkin SNES mouse issues

Post by ry755 » Fri May 01, 2020 6:51 am

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: 157
Joined: Mon May 22, 2017 6:01 am

Re: Hyperkin SNES mouse issues

Post by ry755 » Sat May 02, 2020 4:09 am

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: 2424
Joined: Wed Apr 29, 2009 10:00 am
Location: Minneapolis, United States

Re: Hyperkin SNES mouse issues

Post by D3thAdd3r » Wed May 06, 2020 1:00 pm

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?

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests