It is currently Sun Jul 22, 2018 1:42 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 1451 posts ]  Go to page Previous  1 ... 6, 7, 8, 9, 10, 11, 12 ... 97  Next
Author Message
 Post subject:
PostPosted: Wed Jun 15, 2011 8:28 pm 
Offline
User avatar

Joined: Thu Apr 23, 2009 11:21 pm
Posts: 898
Location: cypress, texas
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.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 15, 2011 8:50 pm 
Offline
Formerly 65024U

Joined: Sat Mar 27, 2010 12:57 pm
Posts: 2261
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. :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 16, 2011 6:32 am 
Offline
User avatar

Joined: Wed Oct 15, 2008 11:50 am
Posts: 939
tokumaru wrote:
3gengames wrote:
[code]LSR $4016; Put the player 1 controller value into the CARRY bit.

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?


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.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 16, 2011 7:10 am 
Online

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 20287
Location: NE Indiana, USA (NTSC)
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?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 16, 2011 7:17 am 
Offline
Site Admin
User avatar

Joined: Mon Sep 20, 2004 6:04 am
Posts: 3530
Location: Indianapolis
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.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 16, 2011 7:30 am 
Offline
User avatar

Joined: Wed Oct 15, 2008 11:50 am
Posts: 939
Wow, I've learned a lot today. Thanks guys!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 16, 2011 12:13 pm 
Offline
Formerly 65024U

Joined: Sat Mar 27, 2010 12:57 pm
Posts: 2261
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:


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 17, 2011 1:05 pm 
Offline
User avatar

Joined: Thu Apr 23, 2009 11:21 pm
Posts: 898
Location: cypress, texas
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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 17, 2011 7:55 pm 
Offline
User avatar

Joined: Thu Apr 23, 2009 11:21 pm
Posts: 898
Location: cypress, texas
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:
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?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 17, 2011 8:14 pm 
Offline
Formerly 65024U

Joined: Sat Mar 27, 2010 12:57 pm
Posts: 2261
To disable or what? If you want to disable, clear all the appropriate bits in $4015.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 17, 2011 8:24 pm 
Offline
User avatar

Joined: Thu Apr 23, 2009 11:21 pm
Posts: 898
Location: cypress, texas
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. :(


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 17, 2011 8:36 pm 
Offline
Formerly 65024U

Joined: Sat Mar 27, 2010 12:57 pm
Posts: 2261
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]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 17, 2011 9:07 pm 
Offline
User avatar

Joined: Thu Apr 23, 2009 11:21 pm
Posts: 898
Location: cypress, texas
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.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 18, 2011 8:34 am 
Online

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 20287
Location: NE Indiana, USA (NTSC)
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.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 20, 2011 11:05 pm 
Offline
User avatar

Joined: Thu Apr 23, 2009 11:21 pm
Posts: 898
Location: cypress, texas
.............................................................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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1451 posts ]  Go to page Previous  1 ... 6, 7, 8, 9, 10, 11, 12 ... 97  Next

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group