ESP32-nesemu, GPIO gamepad ?

wazounet
Posts: 1
Joined: Thu Nov 16, 2017 12:20 pm

ESP32-nesemu, GPIO gamepad ?

Postby wazounet » Thu Nov 16, 2017 12:26 pm

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,

ESP_Sprite
Posts: 9766
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32-nesemu, GPIO gamepad ?

Postby ESP_Sprite » Thu Nov 16, 2017 4:09 pm

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.

User avatar
hex007
Posts: 3
Joined: Wed Jan 17, 2018 3:05 am

Re: ESP32-nesemu, GPIO gamepad ?

Postby hex007 » Wed Jan 24, 2018 7:22 am

Hey I have finished a working GPIO gamepad with nesemu.

I will be pushing changes soon at https://github.com/hex007/esp32-nesemu
Sent from 20,000 leagues under the sea

Who is online

Users browsing this forum: Google [Bot] and 168 guests