It is currently Mon May 22, 2017 6:17 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Sat Jan 28, 2017 1:09 am 
Offline

Joined: Sat Jan 28, 2017 12:25 am
Posts: 2
An image, to illustrate what I am talking about:

Image

I am also not sure what the solid blue rectangle is doing at the top. Perhaps it is related, but I have only been doing NES programming for about three days so have no clue. The hollow blue square is a sprite that is being drawn as expected, the yellow filled square and the rest of the green grid are the background. As far as I understand my code, the green grid should be aligned with the top of the screen, instead of that empty black space that is occupying its position. As you can see it is running on Nestopia. I also ran it on nesDS (a NES emulator for the Nintendo DS) and it gave the same problem, except the grid was not pushed down as far.

My background drawing code:
Code:
        lda $2002             ; read PPU status to reset the high/low latch
        lda #$20
        sta $2006             ; write the high byte of $2000 address
        sta pattern
        ldy #$00
        sty $2006             ; write the low byte of $2000 address
        lda #<background                                         
        sta base
        lda #>background
        sta base+1                                             
        ldx #$04
*       lda (base),y          ; load data from address (background + the value in x)
        sta $2007             ; write to PPU
        iny
        bne -                 ; Branch to LoadBackgroundLoop if compare was Not Equal to zero
        dex
        beq +
        inc base+1
        inc pattern
        lda pattern
        sta $2006
        sty $2006
        jmp -

I am using the Ophis assembler. I am not sure how common its syntax is, so *'s are anonymous labels, - references the nearest previous label, + the next nearest label. Example programs that I have assembled and run (though with a different assembler) have been able to display backgrounds aligned correctly. Is there anything obviously wrong with my code? Should I include some other code? Has anybody come across this before?


Top
 Profile  
 
PostPosted: Sat Jan 28, 2017 1:14 am 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5169
Location: Canada
Scrolling position on the NES usually takes a few attempts to understand.

I am not sure exactly what your problem is from the information you've given, but perhaps this article from our wiki will help:
http://wiki.nesdev.com/w/index.php/PPU_scrolling


Top
 Profile  
 
PostPosted: Sat Jan 28, 2017 1:31 am 
Offline

Joined: Sat Jan 28, 2017 12:25 am
Posts: 2
rainwarrior wrote:
Scrolling position on the NES usually takes a few attempts to understand.

I am not sure exactly what your problem is from the information you've given, but perhaps this article from our wiki will help:
http://wiki.nesdev.com/w/index.php/PPU_scrolling

It did help! I was turning off scrolling before drawing the background and I guess you cannot do that. Thank you very much.


Top
 Profile  
 
PostPosted: Sat Jan 28, 2017 4:13 am 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 9636
Location: Rio de Janeiro - Brazil
rodroddy wrote:
I was turning off scrolling

Scrolling is not something you turn on and off. On the NES, "the scroll" is nothing more than the point at which rendering starts, i.e. the part of the name tables that will show up at the top left corner of the screen. Scrolling animations are created by changing that point over time (which the NES doesn't do automatically, the programmer has to do it step by step) and updating the name tables so new content is displayed as the screen moves.

That being said, the scroll has another important role on the NES. To simplify the design of the hardware, the PPU uses the same register (i.e. small amount of internal memory) to control the scroll and the VRAM address. So every time you use $2006 to set the VRAM address and write to (or read from) VRAM, you're messing up the scroll. For this reason, after every screen update, you're required to reset the scroll to the point you want, using PPU registers $2000 (the lower 2 bits select a name table) and $2005 (2 consecutive writes select the horizontal and vertical scroll, respectively). If you don't do that, rendering will start from a messed up location related to the state you left the PPU address register in after writing to VRAM.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 6 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