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 <-|)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.
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.
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.
Thank you qbradq! 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! 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: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
And thank you, qbradq, for continuing tokumaru's thought!qbradq wrote:Wow, I've learned a lot today. Thanks guys!
edit: GOT THE CONTROLLER working again!
Code: Select all
init_sound: ; initialize sound hardware lda #$01 sta $4015 lda #$00 sta $4001 lda #$40 sta $4017 rts
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]
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.