nesdev.com
https://forums.nesdev.com/

8x16 and whatever else unreg wants to know
https://forums.nesdev.com/viewtopic.php?f=10&t=7451
Page 90 of 93

Author:  unregistered [ Wed Jun 21, 2017 1:32 pm ]
Post subject:  Re: 8x16 and whatever else unreg wants to know

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:
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.

Author:  unregistered [ Thu Jun 29, 2017 3:20 pm ]
Post subject:  Re: 8x16 and whatever else unreg wants to know

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. :)

Author:  unregistered [ Fri Jun 30, 2017 9:48 am ]
Post subject:  Re: 8x16 and whatever else unreg wants to know

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. :)

Author:  tepples [ Fri Jun 30, 2017 10:48 am ]
Post subject:  Re: 8x16 and whatever else unreg wants to know

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.

Author:  unregistered [ Fri Jun 30, 2017 12:46 pm ]
Post subject:  Re: 8x16 and whatever else unreg wants to know

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

Author:  unregistered [ Tue Jul 04, 2017 9:14 am ]
Post subject:  Re: 8x16 and whatever else unreg wants to know

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:
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?f=10&t=7451&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:
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 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. :)

Author:  unregistered [ Thu Aug 03, 2017 2:47 pm ]
Post subject:  Re: 8x16 and whatever else unreg wants to know

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. :))

Author:  unregistered [ Thu Aug 03, 2017 4:39 pm ]
Post subject:  Re: 8x16 and whatever else unreg wants to know

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:
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:
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. :)

Author:  rainwarrior [ Thu Aug 03, 2017 6:32 pm ]
Post subject:  Re: 8x16 and whatever else unreg wants to know

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.

Author:  unregistered [ Fri Aug 04, 2017 8:32 am ]
Post subject:  Re: 8x16 and whatever else unreg wants to know

^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: :)

Author:  unregistered [ Fri Sep 08, 2017 2:46 pm ]
Post subject:  Re: 8x16 and whatever else unreg wants to know

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? :)

Author:  unregistered [ Fri Sep 08, 2017 4:48 pm ]
Post subject:  Re: 8x16 and whatever else unreg wants to know

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.

Author:  unregistered [ Wed Sep 13, 2017 8:19 am ]
Post subject:  Re: 8x16 and whatever else unreg wants to know

Writing $2000 twice in one vblank causes the screen to slightly shudder. It's smooth now. :mrgreen: :D

Author:  tokumaru [ Wed Sep 13, 2017 8:42 am ]
Post subject:  Re: 8x16 and whatever else unreg wants to know

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.

Author:  unregistered [ Wed Sep 13, 2017 9:41 am ]
Post subject:  Re: 8x16 and whatever else unreg wants to know

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:
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. :)

Page 90 of 93 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/