Missing Background Column

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

Post Reply
User avatar
Zzap
Posts: 9
Joined: Sun May 27, 2007 3:28 am

Missing Background Column

Post by Zzap »

Hi, I'm having a bit of trouble with my background code and was wondering if someone could help out. When I load all the tile data and attributes, everything seems to work ok, except the right most column is showing as blank instead of the specific tile. A sprite can be drawn in this region so it's not clipping, and looking at the nametable in FCEUXD the tiles just don't appear to be there. Since all the data is loaded sequentially, and the attributes appear to be setting the palette correctly, I don't understand how the column can be missing. Is it something with the way I'm declaring the tile data, or loading the data?

The shape in the column halfway down is a sprite to show that something can be rendered there.

Image

Code: Select all

; Load 1024 bytes into $2000 - 960 for tiles, 64 for attributes
LoadBackgrounds:
  LDA $2002
  LDA #$20
  STA $2006             ; write the high byte of $2000 address
  LDA #$00
  STA $2006             ; write the low byte of $2000 address

  LDA #low(backmap)
  STA AddrLow
  LDA #high(backmap)
  STA AddrHigh

  LDX #$04              ; Loop X 4 times
  LDY #$00              ; Loop Y 256 times
LoadBackgroundsLoop:
  LDA [AddrLow],y
  STA $2007
  INY
  BNE LoadBackgroundsLoop
; Outer loop
  INC AddrHigh           ; increment high byte of address backg to next 256 byte chunk
  DEX                    ; one chunk done so X = X - 1.
  BNE LoadBackgroundsLoop   ; if X isn't zero, do again


  LDA $2002              ; Reset Scroll
  LDA #$00
  STA $2005
  STA $2005

  LDA #%10000000   ; enable NMI, sprites from Pattern Table 1
  STA $2000

  LDA #%00011110   ; enable sprites & background
  STA $2001
In Bank 1 I define backmap as:

Code: Select all

backmap:
; Background 32x30 tiles
  .db $02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02
  .db $02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02
  .db $02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02
  .db $02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02
  .db $02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02
  .db $02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02
  .db $02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02
  .db $02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02
  .db $02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02
  .db $02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02
  .db $02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02
  .db $02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02
  .db $02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02
  .db $02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02
  .db $02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02
  .db $02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02
  .db $02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02
  .db $02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02
  .db $02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02
  .db $02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02
  .db $02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02
  .db $02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02
  .db $02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02
  .db $02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02
  .db $02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02
  .db $02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02
  .db $02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02
  .db $02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02
  .db $02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02
  .db $02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02,$02
; Attributes
  .db %00000011,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000
  .db %00000001,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000
  .db %00000010,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000
  .db %00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000
  .db %00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000
  .db %00000001,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000
  .db %00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000
  .db %00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000
albailey
Posts: 177
Joined: Thu Jul 13, 2006 3:15 pm

Post by albailey »

My compiler doesnt support this syntax:

LDA [AddrLow],y

so I had to change it to
LDA (AddrLow),y

And then when I copied your code into my starting template everything looked fine and all the columns were displayed.


Edit- I should mention that
1) I am using FCE Ultra
2) The screen looks different in PAL mode than NTSC, but both still display all the columns

Al
User avatar
Bregalad
Posts: 8036
Joined: Fri Nov 12, 2004 2:49 pm
Location: Caen, France

Post by Bregalad »

Make sure to clear all your sprites (fior example set the whole OAM buffer to $f0 or something) if you don't use them.
User avatar
Zzap
Posts: 9
Joined: Sun May 27, 2007 3:28 am

Post by Zzap »

Thanks for the response guys :)

My sprites are set up at $0200, so I've also cleared out $0200 to $02FF, no luck there. Is there another region I should be initialising?

I've played around a bit more, and it's actually displaying tile 0 in the right column. I get the same results in FCE Ultra and Nintendulator.

I've put my source code and a compiled .nes file here (compiler is NESASM).

http://home.iprimus.com.au/jamestodd/chunkout.zip

This one's got me stumped since Al got it to work. Must be something I'm doing (or not doing) with the initialisation.

Again, thanks for the help guys, this is a great forum!
User avatar
Zzap
Posts: 9
Joined: Sun May 27, 2007 3:28 am

Post by Zzap »

Note that on the version I've posted I've shortened the background load to only 512 bytes instead of 1024, but it's still showing the right most column incorrectly. I have also changed tile 0 from a blank tile to one with a small square in the middle which shows that it is using tile 0 for the right most column. As shown in the data above, I've loaded tile 2 into the nametable for each tile in the background.

Image
User avatar
Disch
Posts: 1848
Joined: Wed Nov 10, 2004 6:47 pm

Post by Disch »

hrrm.... according to my tracer:

Code: Select all

C07F:B1   LDA  ($10),Y    [E142=02]  02 01 1E [..I.C]  FF --  41, 11 -- <2000,211E>
C081:8D   STA  $2007      [2007=00]  02 01 1E [..I.C]  FF --  41, 26 -- <2000,211E>
C084:C8   INY                        02 01 1E [..I.C]  FF --  41, 38 -- <2000,211F>
C085:D0   BNE  $F8           [C07F]  02 01 1F [..I.C]  FF --  41, 44 -- <2000,211F>
C07F:B1   LDA  ($10),Y    [E143=00]  02 01 1F [..I.C]  FF --  41, 53 -- <2000,211F>
C081:8D   STA  $2007      [2007=00]  00 01 1F [..IZC]  FF --  41, 68 -- <2000,211F>
apparently $E143 is $00 and not the expected $02. This may be your funky column? I noticed the same for $E123, $E0E3, $E0C3 and others. Very first one I noticed was $E043

Looking in the binary... sure enough.... at offset 0x2053 and every $20 bytes after that there's a stray 00 in the middle of those 02s.

Since these 00s obviously aren't in your code -- the only thing I can think of that causes this is:

1) you have since fixed this bug but it didn't assemble because of some error -- and you didn't notice the error so the old (broken) binary remains.

2) assembler error (it is NESASM, after all)
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Post by tokumaru »

I didn't read the whole thread (I'm feelinga bit lazy right now), so I may be completelly wrong, but can't this be related to scrolling? Maybe the column that's zeroed out belongs to the other name table...

UPDATE: I see now that you do reset $2005 properly before enabling rendering, so I really don't know what could be the problem.

About initialization, you should initialize everything you use, and never rely on power-up values. Even relying on the fact that the name tables will contain all 0's on power-up is wrong.
bunnyboy
Posts: 449
Joined: Thu Oct 27, 2005 1:44 pm
Location: CA
Contact:

Post by bunnyboy »

Its actually a line or db length problem with NESASM. If you split each .db line into 2 then it will assemble correctly. Alternatively put it into a binary file and use .incbin like palette and chr. Will have to check the NESASM source to see what it is doing wrong...
User avatar
Zzap
Posts: 9
Joined: Sun May 27, 2007 3:28 am

Post by Zzap »

Damn, thanks Bunny, looks like that was the problem. I thought I wasn't going crazy that my code seemed right, but couldn't pin point it. I guess NESASM lives up to its reputation again...
Post Reply