It is currently Sun Oct 22, 2017 8:50 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 23 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Sun Jun 05, 2005 2:17 pm 
Offline
User avatar

Joined: Sun Jun 05, 2005 2:04 pm
Posts: 2131
Location: Minneapolis, Minnesota, United States
I am not sure how to do BG scrolling! I know that you write variables to $2005, but I don't know what to write! I don't know how write the most simple instruction ever: If this is here, do this. I can't even make it scroll on its own, let alone tell it when to scroll! I'm probably not making sense... But please answer this if anyone reads this within the next thousand years. I am using NESASM, for anyone that cares...


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 05, 2005 2:30 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19115
Location: NE Indiana, USA (NTSC)
If you already know how to display a non-scrolling background, then try doing this during vertical blank:
Code:
; global variables in zero page
x_scroll_distance = $ee
y_scroll_distance = $ef


  ; reset $2005 latch and wait for vblank
  ; (pedagogic spinning method, not production nmi method)
@loop:
  bit $2002
  bpl @loop

  ; set scroll register
  lda x_scroll_distance
  sta $2005
  lda y_scroll_distance
  sta $2005

  ; turn on background
  lda #$0A
  sta $2001

  inc x_scroll_distance
  jmp @loop



Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 05, 2005 2:36 pm 
Offline
User avatar

Joined: Wed Nov 10, 2004 6:47 pm
Posts: 1845
Well this probably should've been in nesdev (as opposed to nesemdev) -- but whatever ^^

Anyway, Scrolling is suprisingly simple from a game developer standpoint. It involves two writes to $2005, and possibly a write to $2000.

First write to $2005 will be your X scroll (in pixels... 0-255)
Second write to $2005 will be your Y scroll (in pixels... 0-239)

The low two bits of $2000 pick which nametable to start drawing from. $2000.1 is the Y nametable (flipping this bit on would be like adding an additional 240 to your Y scroll). $2000.0 is the X nametable (flipping it on is like adding an additional 256 to your X scroll)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 05, 2005 2:54 pm 
Offline
User avatar

Joined: Sun Jun 05, 2005 2:04 pm
Posts: 2131
Location: Minneapolis, Minnesota, United States
Yeah, I realized that after I typed this message. I didn't know people still like replied on this website. Posting this message was my only hope to finding out how to do BG scrolling. Well, it scrolls, and thank you, but, is there a way to to make it scroll continuosly? because it scrolls left, and then pops back up in the middle of the screen, and scrolls left. Is there a way to make it then come from the right, and go left? do you know what I mean? Sorry, I use alot of commas and question marks.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 05, 2005 3:04 pm 
Offline
User avatar

Joined: Wed Nov 10, 2004 6:47 pm
Posts: 1845
That's what the low bits of $2000 are for. Once you scroll 256 pixels, you're into the next nametable. So once your X scroll goes past 256, toggle $2000.0 (assuming vertical mirroring)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 05, 2005 3:30 pm 
Offline
User avatar

Joined: Sun Jun 05, 2005 2:04 pm
Posts: 2131
Location: Minneapolis, Minnesota, United States
I tried toggling them, and it doesn't change anything. You're talking about the PPU right? I followed the code that the other guy posted below my first message, and I tried changing these two bits:

#%000010 :arrow: 00
sta $2000

like you said. It doesn't do anything! Are you talking about the Name Tables when you say 2000? because the NES's in the US skip a line, or something dumb like that, so they start at 2020. So could you re-explain that to me? thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 05, 2005 3:41 pm 
Offline
User avatar

Joined: Wed Nov 10, 2004 6:47 pm
Posts: 1845
-- snip -- I misread your above code. Nevermind what was here before. The below code still applies.

To add on to tepples' code:

Code:
  ; set scroll register
  lda x_scroll_distance
  sta $2005
  lda y_scroll_distance
  sta $2005

  lda name_table_status
  sta $2000

  ; turn on background
  lda #$0A
  sta $2001

  inc x_scroll_distance
  bne @skip
  lda name_table_status
  eor #$01
  sta name_table_status

@skip:
  jmp @loop


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 05, 2005 3:53 pm 
Offline
User avatar

Joined: Sun Jun 05, 2005 2:04 pm
Posts: 2131
Location: Minneapolis, Minnesota, United States
I'm sure that would work, but what should I put for name_table_status? should I put that on top under the x_scroll_distance stuff? what would I write to it? :?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 05, 2005 4:05 pm 
Offline
User avatar

Joined: Wed Nov 10, 2004 6:47 pm
Posts: 1845
It's just a variable. Just stick it somewhere in RAM. The whole point is to keep track of the low bit to write to $2000 (since you can't read $2000, it helps to keep track of it in RAM somewhere, hence the use of that variable).

As for what you set it to -- set it to whatever you want to write to $2000. I won't get into what each bit does -- check nestech for that.

You don't have to do things this way -- it was just an example.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 05, 2005 4:28 pm 
Offline
User avatar

Joined: Sun Jun 05, 2005 2:04 pm
Posts: 2131
Location: Minneapolis, Minnesota, United States
Okay, so I put name_table_status up under the x_scroll_distance stuff, and I set it to $FF, and it scrolls across the two name tables exactly how I wanted them to! thanks! and you can just write something to $2400 and have it be in the Second Name Table, and it will scroll right after the first name table?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 05, 2005 4:35 pm 
Offline
User avatar

Joined: Wed Nov 10, 2004 6:47 pm
Posts: 1845
Yes -- assuming Vertical mirroring.

The nametables will alternate like:

A B A B A B

'A' being accessable via ppu$2000
'B' being accessable via ppu$2400

When you scroll right off nametable A, you'll move into nametable B. Likewise when you scroll right from nametable B, you'll scroll into nametable A.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 05, 2005 5:38 pm 
Offline
User avatar

Joined: Sun Jun 05, 2005 2:04 pm
Posts: 2131
Location: Minneapolis, Minnesota, United States
To write stuff to Name Table 2, do you have to set up PPU and all that again to a different adress? If so, what adresses? :shock:


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 05, 2005 6:07 pm 
Offline
User avatar

Joined: Wed Nov 10, 2004 6:47 pm
Posts: 1845
Assuming Vertical mirroring, Nametable B is accessable at ppu$2400-27FF. So to write to that nametable you set the ppu address to ppu$2400 with dual $2006 writes:

LDA #$24
STA $2006
LDA #$00
STA $2006


Then you write to $2007 to send the data to the PPU. Exact same way you write to nametable A, only it's at a different PPU address.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 05, 2005 6:50 pm 
Offline
User avatar

Joined: Sun Jun 05, 2005 2:04 pm
Posts: 2131
Location: Minneapolis, Minnesota, United States
Okay, Thanks! One last question, how do you get it to stop and start when you want it to? sorry... :(


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 05, 2005 7:04 pm 
Offline
User avatar

Joined: Wed Nov 10, 2004 6:47 pm
Posts: 1845
You control the X and Y scroll with writes to $2005, and you control nametable scrolling with the low 2 bits of $2000. You can control exactly where and when the screen scrolls by writing the desired values to those registers at the desired times.

Don't try to build off that above pasted code -- it was just an example. Write your own scrolling code. Then you're in control of how it scrolls.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 23 posts ]  Go to page 1, 2  Next

All times are UTC - 7 hours


Who is online

Users browsing this forum: Bing [Bot] and 4 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