8x16 and whatever else unreg wants to know

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Post by unregistered »

3gengames, thank you for helping me. Now your code makes sense to me! :D (Please answer tokumaru's question to you at the bottom of page 8.)
tokumaru wrote:"LDA $4016" puts the state of the current button into the accumulator; "LSR A" (or simply "LSR", depending on the assembler) shifts the bit out of the accumulator and into the carry flag; "ROL ControllerButtons" shifts the carry flag into ControllerButtons. Do this 8 times in a row and each bit of "ControllerButtons" will indicate the state of a buttom.
Thank you for explaining all of that! (glad I asked!) "LSR SomeMemory" will move/write SomeMemory's LSB into the Carry bit. (The operation of LSR is Operation: 0 -> byte ->C) Will it write the bit shift to that memory location as well? Is ROL read-modify-write too? (The operation of ROL is Operation: |-<- byte <- C <-|)
Last edited by unregistered on Wed Jun 15, 2011 8:54 pm, edited 1 time in total.
3gengames
Formerly 65024U
Posts: 2284
Joined: Sat Mar 27, 2010 12:57 pm

Post by 3gengames »

Yeah, it will ROL the memory. The MSB on the memory will go to the carry. The LSB will turn into the carry. After 8 loops, all bits [Which represent button presses] will be updated. Far easier to check then instead of hardcoding it in. :)
User avatar
qbradq
Posts: 972
Joined: Wed Oct 15, 2008 11:50 am

Post by qbradq »

tokumaru wrote:
3gengames wrote:

Code: Select all

LSR $4016; Put the player 1 controller value into the CARRY bit.[/quote]
Does this really work? I mean, LSR absolute is a read-modify-write instruction, so you're effectively writing something back to $4016... Doesn't this interfere with the reading process?[/quote]

Good call-out Tokumaru. This is not something I would have done in my own code, but once you think about this should not interfere with the reading process.

The only significant bit of $4016 when writing is bit 0, which controls the logic level on both of the controller port's OUT pins (the Strobe signal). So your read-modify-write looks like this:

1. Read $4016, A=%00000001, C=Don't Care
2. Logic Shift Right, A=%00000000, C=1
3. Write %00000000 to $4016

This will just keep the Strobe signal low, which it should normally be. This will not even interfere with other controllers as the logic level simply does not change.

Even if you are using something that uses the D3 and D4 lines it is still not a problem. You're RMW cycle looks like this instead:


1. Read $4016, A=%00011001, C=Don't Care
2. Logic Shift Right, A=%00001100, C=1
3. Write %00001100 to $4016

In the above bit 0 still isn't set. Even though bits 2 and 3 are it does not matter because they don't do anything on a write.

When using this on $4017 to read the state of controller port 2 this entire discussion is moot. $4017 does nothing on a write.

All of that said, this is how the hardware works (it's just a 4021 shift register after all). Emulators may do something entirely different, especially when input movie playback is involved. Use with caution.
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

qbradq wrote:$4017 does nothing on a write.
Except reconfigure the APU Frame Counter.

Besides, if you LSR $4016, how will you read the expansion controllers on a Famicom?
User avatar
Memblers
Site Admin
Posts: 4044
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Post by Memblers »

I wouldn't use $4016 like that. There's more than D3 and D4, there is also D1 and D2 that exist on the NES and FC expansion port. So you might not see a glitch yourself, but it's possible that someone could. Safer to just LDA $4016 then LSR A.

And a RMW instruction actually does 2 writes. It writes back the original value before writing back the changed value. Sounds strange, but that's what it does (6502 reads or writes on every cycle, even if it's basically garbage). So depending on the state of D0 and D1, I can see how an LSR $4016 could actually end up strobing the controller.
User avatar
qbradq
Posts: 972
Joined: Wed Oct 15, 2008 11:50 am

Post by qbradq »

Wow, I've learned a lot today. Thanks guys!
3gengames
Formerly 65024U
Posts: 2284
Joined: Sat Mar 27, 2010 12:57 pm

Post by 3gengames »

Edit: I see what you're saying, sorry. Yeah, use the earlier I guess. I'll edit the old post too. You probably shouldn't use the shift then, I never did either, just thought it'd be optimal. I was just ignorant of the other bits. Whoops! :oops:
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Post by unregistered »

qbradq wrote:You might also want to consider releasing your current ROM in the Homebrew Forum for others to comment on. I know that always gives me a lot of insight and motivation. Plus I'd love to see what you're working on :D
Thank you qbradq! :D That's very helpfull for me. :) I don't think now would be a good time release the rom because I'm stuck... and my sister wouldn't let me do that. But, she might be ok with a video... maybe. She has completed a couple of the levels - the graphics are awesome, I think! :D Once I can finally get the music to play and also get my controller to work again, and then I would be estatic to work on scrolling. After all of that, a video could be made, that's a fun and helpfull idea! :)
qbradq wrote:Wow, I've learned a lot today. Thanks guys!
And thank you, qbradq, for continuing tokumaru's thought! :)

edit: GOT THE CONTROLLER working again! :D
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Post by unregistered »

It's almost working. I'm getting a bunch of beeps and beats and other high notes. And the screen is bumping up and down with a beat... kind of. It sometimes sounds like a music file is being played; rarely though. I found my init_sound part

Code: Select all

init_sound:
        ; initialize sound hardware
        lda #$01
        sta $4015
        lda #$00
        sta $4001
	lda #$40
	sta $4017
        rts
Are those the right inits? Why did he (the nes 101 tutorial guy ... Michael Martin) store #$40 into $4017... :? and #$01 into $4015 and #$00 into $4001?
3gengames
Formerly 65024U
Posts: 2284
Joined: Sat Mar 27, 2010 12:57 pm

Post by 3gengames »

To disable or what? If you want to disable, clear all the appropriate bits in $4015.
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Post by unregistered »

3gengames wrote:To disable or what? If you want to disable, clear all the appropriate bits in $4015.
I want to know what has been set up for me by those three lda+stas. Maybe a setting is wrong... there's something wrong... somewhere. :(
3gengames
Formerly 65024U
Posts: 2284
Joined: Sat Mar 27, 2010 12:57 pm

Post by 3gengames »

Well try to understand all the code you have since you're just blindly storing to registers, understand the registers [See the wiki: http://wiki.nesdev.com/w/index.php/APU] and then try again. That's what I'd do. You can silence all channels by doing a $4015 store I think, but other than that I won't be of much help, I haven't touched sound yet either. :oops: It's difficult.

Go. To. The. Wiki. It's the best resource on the site.


[You mean the wiki, not Wikipedia. Wikipedia is only one of several wikis; our wiki is another. --MOD]
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Post by unregistered »

That's the same page I'm on... in another tab. Yes it is very helpfull. :) And I just undersand, now, :D that writing #$40 to $4017 is setting the Mode to 1... it, "selects 5-step sequence." :? And then after more reading I understand that "In this mode, the frame interupt flag is never set." Which, I guess, might mean :? that setting timed events is not possible. ... and well thanks for the wiki recommendation (I remember tepples was the first to recommend the wiki to me) and, I agree with you, sound is difficult.
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

Ordinarily, games time their music engines off the vertical blanking NMI, not the APU Frame IRQ. I think only about two games actually use the APU Frame IRQ. As I understand it, the APU Frame IRQ isn't really for the NES as much as for other applications of a 2A03 CPU with no other source of periodic interrupts.
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Post by unregistered »

.............................................................this is what happens

I have set the controller so that
1.) Pressing a direction increments or decrements the oX or oY values that represent the x and y location of our meta-sprite.
2.) Pressing select "starts" my song.
3.) Pressing start "stops" my song.
4.) Pressing A simply displays the next meta-sprite.
5.) Pressing B simply returns our meta-sprite back to what it originally looked like.

So, when starting the game our meta-sprite begins in the upper left corner. Pressing left or right moves our sprite either left or right one pixel. Upon releasing that left or right press our meta-sprite returns back a pixel right or left to its origin. Pressing up or down works like "normal"; our meta-sprite ascends or descends until the up or down press is released. Most recently I pressed A twice and then pressed select and the screen began to gyrate around between two or three screens over and over again with the sound of beeps and other non musical stuff... then I pressed A and the screen changed its gyrate to a different pattern and the half-music/noise changed also... along with the screen... :? And so I pressed A again and the noise-screen gyration changed again. Remember how our meta-sprite had problems moving left and right... well as the A button was pressed the sprite also returned to its origin and became unmoveable up and down and left and right beyond the one pixel reach from before.

As I think about this it seems that the problem is solveable and I hope that you have an idea-fix or helpfull thoughts to share with us.

edit: When the game starts our screen, from above, scrolls down into the screen area. It has like an upper floor part and that floor part is raised and lowered very randomly in its pattern pieced gyrations.
Post Reply