Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added functions for distinguishing gamepad button presses, also fix gamepad data persisting #2571

Closed
wants to merge 6 commits into from

Conversation

LettucePie
Copy link
Contributor

Hello again!

This fixes issue 2561 (#2561) which is an issue I inadvertently created, familiar territory for most of us here I'm sure lol.

I am still not very experienced with C and memory management, and while fixing this I found some security messages and other questions within core.c. While it seems like I didn't violate any security issues, it might be best if someone who understands this better checks in. I separated my changes to core.c in two commits. My attempt to solve 2561 requires those changes.

  • 817e09c3299306c9ce88ac7fa6ad1607dfe0367f before touching core.c
  • c3328075aa3d2bd1697f362a7cc340f473d4615f after

To easily test the issue, I made a new lua cart called "breaktest"

x = 1
function TIC()
	if btn(6) then
		trace("breaking") 
		x = x + y 
	end
	cls(0)
end

@LettucePie
Copy link
Contributor Author

Some builds failed... Looks like I need to add my new functions to a header file I'm guessing? I can't seem to find where the other functions on io.c are hanging out. There isn't even an io.h file...

@LettucePie
Copy link
Contributor Author

emerging from the trees and brush, covered in dirt and wounds while hyperventilating

Okay! So it turns out you don't just simply add functions to io and api!

I was confused why some platforms weren't building properly and noticed the only place where tic_api_btn and btnp were addressed was the api.h file in a big weird list of other api functions...

Anyways, here's btnd and btnu working in all available langs except wasm. I just didn't test it because I don't entirely understand what it wants me to do.
btnd-btnu-tests.zip

@nesbox
Copy link
Owner

nesbox commented May 9, 2024

I have serious doubts that we should bloat the API for these functions when user can always read the current state of the gamepad buttons using peek(0x0FF80)

@LettucePie
Copy link
Contributor Author

It's ultimately up to you. I personally feel like the btnu call has a bit of value as being generally accessible, and doesn't require users to form variables to compare against.

If you read issue 2561 you'll find I originally made these functions to solve a bug where users who crash their game from pressing button 6 get warped to Surf. It was my changes to core.c that ultimately corrects this. btnd and btnu are sort of convenient byproducts. The original api call using btnp along with the changes to core.c should suffice (I haven't tested that scenario).

@LettucePie
Copy link
Contributor Author

@nesbox I tested my hypothesis from earlier now that I'm back home. The changes to core.c were all that are required for fixing issue 2561. I already setup the fix at Pull Request 2579 (#2579).

I don't know if you plan on asking for more opinions on btnd and btnu so I'll leave this open. It's no disrespect to me if you chose to close it. Now that I have an idea of what it takes to expand and adjust the api though, I'm excited to check out the issues and todo for some challenges to tackle lol.

@nesbox
Copy link
Owner

nesbox commented May 11, 2024

@LettucePie thank you for your help, I merged the pull request regarding the bug in the core, but as for the new API, I suggest closing this part, sorry.

@nesbox nesbox closed this May 11, 2024
@LettucePie LettucePie deleted the btnd-btnu branch May 14, 2024 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants