Page 1 of 1

ESP32-nesemu, GPIO gamepad ?

Posted: Thu Nov 16, 2017 12:26 pm
by wazounet
Hi!

I'm trying to use the nesemu with a GPIO gamepad I built. Does any of you got this working ?
I've been trying to mess around the current psxcontroller lib but without any success so far and I can't get my hands on one to at least try reverse engineer the current function :

Code: Select all

void osd_getinput(void)
{
	const int ev[16]={
			event_joypad1_select,0,0,event_joypad1_start,event_joypad1_up,event_joypad1_right,event_joypad1_down,event_joypad1_left,
			0,0,0,0,event_soft_reset,event_joypad1_a,event_joypad1_b,event_hard_reset
		};
	static int oldb=0xffff;
	int b=psxReadInput();
	int chg=b^oldb;
	int x;
	oldb=b;
	event_t evh;
//	printf("Input: %x\n", b);
	for (x=0; x<16; x++) {
		if (chg&1) {
			evh=event_get(ev[x]);
			if (evh) evh((b&1)?INP_STATE_BREAK:INP_STATE_MAKE);
		}
		chg>>=1;
		b>>=1;
	}
}
If someone could give me some direction that would be fantastic, because honestly I have time understand how this works with the nofendo nes core functions.

Cheers,

Re: ESP32-nesemu, GPIO gamepad ?

Posted: Thu Nov 16, 2017 4:09 pm
by ESP_Sprite
This essentially is an adapter between the psx driver and the Nofrendo event-based system. Essentially, psxReadInput will return an 16-bit word with data read from the PSX; each bit in this word stands for a button or direction. When the button or direction is pressed, the associated bit will be 0, otherwise it will be 1. The rest of the code essentially squirrels out the changes between this word and the previously saved value (oldb) by xor'ring the two: the resulting value will have an 1 for each bit that is set. The for-loop, finally, iterates over all these bits and will send the associated events to nofrendo.

For customization, suggest you change the psxReadInput call to something you make yourself that also returns a bitmap of buttons.

Re: ESP32-nesemu, GPIO gamepad ?

Posted: Wed Jan 24, 2018 7:22 am
by hex007
Hey I have finished a working GPIO gamepad with nesemu.

I will be pushing changes soon at https://github.com/hex007/esp32-nesemu