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

Re: 8x16 and whatever else unreg wants to know

Post by unregistered »

I'm stumped. After drawing and coloring the nametables correctly after going "upstairs" the lines on FCEUX`s Name Table Viewer show that nametable 03 is being shown. And that still happens after adding this short amount of code to the end of see2vi

Code: Select all

lda my_copy_of_last_write_to_PPUCTRL
and #11111101b
sta $2000
sta my_copy_of_last_write_to_PPUCTRL
see2vi runs while rendering is disabled. After checking the code in a tracelog file, my_copy_of_last_write_to_PPUCTRL holds #$8D; that's the correct nametable! What other things could affect what nametable is being shown? :?

edit: just read that I'm not to write $2000 outside vertical blanking, on the wiki, so I'm going to change that. Fixed that and it is still showing nametable 03.
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Re: 8x16 and whatever else unreg wants to know

Post by unregistered »

After removing my turning off scrolling when in a certain mode the new screen is displayed correctly now!! :mrgreen: :D I had turned off scrolling because I thought that it would be less for the game to worry about when in that mode, but I guess turning off scrolling while in the mode that happens when going upstairs or downstairs is not good; or, maybe, it was because needscroll was disabled twice in the same frame. In my tracelog file it was evident that needscroll was 00 when being assigned 00 and so we fixed that!! :mrgreen:

edit: already removed my code from the previous post. Wasn't needed. :)

edit2: in my scrolling code $2000 is set. It must be good to set $2000, at most, once per frame, right?

edit3: nvrmnd, I think one of you has already tried to teach me this. I know setting $2000 more than once in the same frame causes tiles to be drawn incorrectly. I think that $2000 has to be set each frame to prevent nametable weirdness. :)
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Re: 8x16 and whatever else unreg wants to know

Post by unregistered »

Maybe $2000 needs to be set after drawing the nametables. It wasn't being set because I had turned it off in a certain mode. But, as soon as I exited the mode the two bars of black tiles at the top of the screen disappeared. Maybe $2000 just needs to be set once after drawing the nametables. :)
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: 8x16 and whatever else unreg wants to know

Post by tepples »

unregistered wrote:Maybe $2000 just needs to be set once after drawing the nametables.
That is correct. When you use $2006/$2007 to update video memory, the top-left pointer t gets clobbered. This is important because t controls the horizontal and initial vertical scroll position. To reset t, you need to rewrite the scroll position through $2000 and $2005.
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Re: 8x16 and whatever else unreg wants to know

Post by unregistered »

tepples wrote: That is correct. When you use $2006/$2007 to update video memory, the top-left pointer t gets clobbered. This is important because t controls the horizontal and initial vertical scroll position. To reset t, you need to rewrite the scroll position through $2000 and $2005.
Thank you so much tepples for this info and for agreeing with me!! :D
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Re: 8x16 and whatever else unreg wants to know

Post by unregistered »

Just want to send some love to php and plp. They push the processor flags to the stack and then pull them back! That's outstanding and exciting to me because they allowed me to

Code: Select all

lda FORWARD_last
php
sta tA+1
iny ;it is 01 now
sty FORWARD_last
lda CurrentColumn
and #11110000b
plp
beq +
sec
sbc #16
+ sta t18
That runs before the main loop of see2vi. It fixes the colors and the screens from messing up when she turns around.

Those two instructions allow for the flags to be recorded, load the accumulator, and then branch according to the recorded flags! Awesome!! :mrgreen:

edit: php and plp use the stack so you should read tokumaru's stack explaination on page 31 of this thread :) https://forums.nesdev.com/viewtopic.php ... &start=454. 1.) Make sure everything you push on the stack inside of a function is pulled from the stack before the rts at the end of the function. 2.) Since jsring pushes 2 bytes on the stack and rts pulls two bytes from the stack, you shouldn't ever try to do something like

Code: Select all

function1:
lda variable
php
jsr function2
rts ;end of function1

function2:
plp
bne +
  ;other code here
+ rts ;end of function2
That would mess up your game considerably because after a jsr function1 it would push 2 bytes on the stack for its rts to use, then the php would push a third byte, then the jsr function2 would push a fourth and fifth byte on the stack to be used by function2's rts, and the plp would pull the fifth byte pushed on the stack in this example. Your game would perish.

Hopefully that will help you to fully understand tokumaru's explaination. The stack is fun and helpful; just be cautious. :)

edit: added "a" before "jsr function1"; hopefully you can understand this easier. :)
Last edited by unregistered on Fri Dec 29, 2017 11:30 am, edited 1 time in total.
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Re: 8x16 and whatever else unreg wants to know

Post by unregistered »

tepples wrote:
unregistered wrote:Maybe $2000 just needs to be set once after drawing the nametables.
That is correct. When you use $2006/$2007 to update video memory, the top-left pointer t gets clobbered. This is important because t controls the horizontal and initial vertical scroll position. To reset t, you need to rewrite the scroll position through $2000 and $2005.
tepples, is there any other reason t can get clobbered? (A few times, after our lady attaches to a certain object, the ground has lowered and random tiles appear at the top of the screen. So t must be getting clobbered sometimes. Maybe $2006/$2007 are being used incorrectly... will look into that now. :))
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Re: 8x16 and whatever else unreg wants to know

Post by unregistered »

It was because scrolling is disabled everytime she attaches to that object... and the $2005 updates are performed at the end of my scroll_screen methods. So the fix required:

Code: Select all

lda needscroll
beq +end
lda needppu2005reg
beq +end
bi-directional_scrolling ; <I`m a macro too! runs draw_our_columns and update_colors
But, changed the 4 lines I added to

Code: Select all

lda needscroll
and needppu2005reg
beq +end
needscroll and needppu2005reg are both absolute, non zero page, values so the lda and and both take 4 cycles. Changing lda to and didn't slow it down and we saved a beq!! :mrgreen: :D

I'm pretty sure that will work. They are both 1 when activated and so it will only run bi-directional scrolling if they are both 1. 1 and 1 == 1. beq will fail cause 1 <> 0. :)
User avatar
rainwarrior
Posts: 8731
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: 8x16 and whatever else unreg wants to know

Post by rainwarrior »

unregistered wrote:tepples, is there any other reason t can get clobbered? (A few times, after our lady attaches to a certain object, the ground has lowered and random tiles appear at the top of the screen. So t must be getting clobbered sometimes. Maybe $2006/$2007 are being used incorrectly... will look into that now. :))
If the Y scroll is >= 240 you can get "garbage" at the top of the screen. Instead of wrapping to the next nametable it'll render the 64 bytes of attribute as if it was tiles.
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Re: 8x16 and whatever else unreg wants to know

Post by unregistered »

^Thank you rainwarrior!! :D
unregistered wrote:They are both 1 when activated and so it will only run bi-directional scrolling if they are both 1.
needscroll is actually #$ff when activated because that's non-zero and the xregister is always #$ff where stx needscroll was placed. And the ff is ok because bit 0 is set in #$ff (#11111111b) and the and with needppu2005reg, #$01 when activated, will work the same. :mrgreen: :)
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Re: 8x16 and whatever else unreg wants to know

Post by unregistered »

Now, after redrawing both nametables, it displays nametable 00 for one frame despite me waiting until the next vblank to set $2000 to nametable 01. Why does this happen? tepples said that t gets clobbered after writing $2006 and $2007 and that that messes up the scrolling. On the nesdev wiki it lists bit 0 of $2000 as incrementing the X scroll value by 256. I am missing something. :oops: Does writing $2000 twice in the same vblank cause problems like this? :)
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Re: 8x16 and whatever else unreg wants to know

Post by unregistered »

Forcing $2000 to be written to only once per vblank took away the two 16bit columns of random tiles drawn between two of the screens on floor 3; but, the one frame of the wrong nametable shown still happens. I understand you don't have any code so I'll have to figure this one out myself. :)

edit: No, see this post for a good correction to the first sentence of what I wrote here.
Last edited by unregistered on Thu Sep 28, 2017 4:32 pm, edited 1 time in total.
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Re: 8x16 and whatever else unreg wants to know

Post by unregistered »

Writing $2000 twice in one vblank causes the screen to slightly shudder. It's smooth now. :mrgreen: :D
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: 8x16 and whatever else unreg wants to know

Post by tokumaru »

unregistered wrote:Writing $2000 twice in one vblank causes the screen to slightly shudder.
That shouldn't happen. The problem was probably something else about the second write (wrong time, wrong value, whatever), not the fact that there were 2 of them.
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Re: 8x16 and whatever else unreg wants to know

Post by unregistered »

tokumaru wrote:
unregistered wrote:Writing $2000 twice in one vblank causes the screen to slightly shudder.
That shouldn't happen. The problem was probably something else about the second write (wrong time, wrong value, whatever), not the fact that there were 2 of them.
Ok, thank you tokumaru. :)
unregistered wrote:Forcing $2000 to be written to only once per vblank took away the two 16bit columns of random tiles drawn between two of the screens on floor 3
No, the two incorrect columns of 16bit tiles were there because valid_left was incorrect so it wasn't drawing the new columns of tiles at the correct time. Near the end of see2vi, which redraws both screens when changing floors, there's

Code: Select all

lda visible_left
and #11111100b;10b
sta valid_left ; <this fixes the screen so it always works :mrgreen: :D
Without that code scrolling left is broken for about a screen. When bit1 was 1 it missed drawing two 16bit columns when scrolling right. Scrolling left wasn't broken, I think, when I posted my incorrect post that's quoted. :)
Post Reply