BUTTONS
Moderator: Moderators
Re: BUTTONS
Yes, Famicom controllers that connect to the expansion port. Another common technique to read them is to AND the byte with %00000011 to keeo only the bits that matter and CMP the result to 1, setting the carry for values 1 (button pressed on regular controller only), 2 (pressed on expansion port controller only) and 3 (pressed on both controllers). The carry can then be shifted into the final byte.
Re: BUTTONS
Indeed, it's not ideal (even bunnyboy would agree with that, I believe), but as long as nobody steps up to write a better one, we're going to be pointing newcomers to it.tokumaru wrote:Yeah, it definitely has its merits, I just can't help noticing that a lot of people come here having trouble with the far from ideal program structure used in that tutorial.Pokun wrote:Having learned from Nerdy Nights myself I both agree and disagree with you. It's not ideal but it's the best newbie tutorials I found for making NES games.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
Re: BUTTONS
The last snippet at Gamepad code is what I use in my own games. It reads bit 1 and 0 of both controller ports using the AND/CMP/ROL technique that tokumaru described. It also uses a trick called a "ring counter", where the result variable doubles as a loop counter. If I initialize the result variable to $01 and shift it left once each loop, the 1 comes out into the carry once the loop has run eight times, and then the subroutine can loop based on whether the carry has been set yet.tokumaru wrote:Yes, Famicom controllers that connect to the expansion port. Another common technique to read them is to AND the byte with %00000011 to keeo only the bits that matter and CMP the result to 1, setting the carry for values 1 (button pressed on regular controller only), 2 (pressed on expansion port controller only) and 3 (pressed on both controllers). The carry can then be shifted into the final byte.
If there's anything in this code that you want me to explain further, I'm ready to do so.
Code: Select all
JOYPAD1 = $4016
JOYPAD2 = $4017
.zeropage
buttons1: .res 1
buttons2: .res 1
.code
readjoy:
lda #$01
sta JOYPAD1
sta buttons2 ; player 2's buttons double as a ring counter
lsr a ; now A is 0
sta JOYPAD1
@loop:
lda JOYPAD1
and #$03 ; ignore bits other than controller
cmp #$01 ; Set carry if and only if nonzero
rol buttons1 ; Carry -> bit0; bit 7 -> Carry
lda JOYPAD2 ; Repeat
and #$03
cmp #$01
rol buttons2 ; Carry -> bit0; bit 7 -> Carry
bcc @loop
rts
-
- Posts: 120
- Joined: Sat Apr 12, 2014 12:11 pm
- Location: Gothenburg, Sweden
Re: BUTTONS
I agree. Like I wrote in my previous post, a code snippet fixing this would require a bit more knowledge which in turn means to redo the whole structure if it is going to work as intended. Not that I am assembler/NES guru or anything but my experience tells me what NOT to do. If you want to do anything else with this code and still maintain some form of understandability, you pretty soon realize there needs to be de-spaghettification. Like you wrote, mixing all kinds of tasks that does not belong together in your NMI is not a good way of building a game. This ofcourse is a flaw of the NN tutorials and not the newbie trying to learn.tokumaru wrote:I'm starting to think that the way these beginner tutorials approach such basic tasks does more harm
I´ve got %01100011 problems but the BITs aint one.
- rainwarrior
- Posts: 8732
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: BUTTONS
Nerdy Nights neglects to read $2002 before it begins its first vblank wait, so it's not a totally robust init example either.Pokun wrote:Another flaw of Nerdy Nights is that he doesn't say a word about the init code he puts in each program you write. This makes you wonder if you missed something.
Re: BUTTONS
Before anyone gets offended, I want to make it clear that my intention is not to bash the Nerdy Nights or any other tutorial. In this regard, the expression "doing more harm than good" was probably exaggerated, but english is not my first language and sometimes things don't come off as I intended.
It's good to know we have something that newbies can use to get started, and we have a lot to thank to the people who dedicate their time to creating tutorials to help others. I know Nerdy Nights is indeed the best option for now. It may use some questionable program structures, but at least it's not full of program breaking mistakes and bad understanding of the platform in general.
Still, even though I don't have the time or competence (I see myself as a good coder, but a terrible teacher) to create something better, I think it's important for us to discuss and point out the shortcomings of the existing materials, so that newbies can know what to expect and how to proceed after the tutorials, and so that anyone that might decide to write a tutorial in the future keeps the issues in mind.
It's good to know we have something that newbies can use to get started, and we have a lot to thank to the people who dedicate their time to creating tutorials to help others. I know Nerdy Nights is indeed the best option for now. It may use some questionable program structures, but at least it's not full of program breaking mistakes and bad understanding of the platform in general.
Still, even though I don't have the time or competence (I see myself as a good coder, but a terrible teacher) to create something better, I think it's important for us to discuss and point out the shortcomings of the existing materials, so that newbies can know what to expect and how to proceed after the tutorials, and so that anyone that might decide to write a tutorial in the future keeps the issues in mind.