background displaying only purple
Moderator: Moderators
- Kitty_Space_Program
- Posts: 50
- Joined: Mon Sep 21, 2020 7:42 am
background displaying only purple
So I'm trying to learn learn how to add a background. And when I start the rom, everything is purple. There isn't any color like it in the color palette and editing the color palette does nothing. turning off background rendering and sprite rendering does nothing. never turning nmi back on does nothing, nor does turning on grey scale. it covers up the sprite which I know is there, and if I jump over the load background code, it just loads the spite with white background (as is to be expected). the only way I've gotten a different result besides a purple background is if I turn the nmi on before loading the nametable, and obviously its extremely glitchy and it loops, but you can at least see the sprite. anyone got any ideas on whats happening?
heres the code I'm using if thats any help (note that for some reason the website won't show indents but they are there):
loadbackground: ;#LOW(worlddata) into wrold and #HIGH(world) into world +1
lda #low(worlddata) ;lowbyte of adress world data remebr little endian
sta world
lda #high(worlddata)
sta world+1
;nametabe population
bit $2002
lda #$20; sets 2000 as the name table were using
sta $2006
lda #$00
sta $2006
ldy #$00
ldx #$00
populatenametable:
lda (world),y
sta $2007
iny
cpx #$03
bne notdonewithnametable
cpy #$0c0
beq donewithnametable
notdonewithnametable:
cpy #$00
bne populatenametable
inx
inc world+1
jmp populatenametable
donewithnametable:
ldx #$00
heres the code I'm using if thats any help (note that for some reason the website won't show indents but they are there):
loadbackground: ;#LOW(worlddata) into wrold and #HIGH(world) into world +1
lda #low(worlddata) ;lowbyte of adress world data remebr little endian
sta world
lda #high(worlddata)
sta world+1
;nametabe population
bit $2002
lda #$20; sets 2000 as the name table were using
sta $2006
lda #$00
sta $2006
ldy #$00
ldx #$00
populatenametable:
lda (world),y
sta $2007
iny
cpx #$03
bne notdonewithnametable
cpy #$0c0
beq donewithnametable
notdonewithnametable:
cpy #$00
bne populatenametable
inx
inc world+1
jmp populatenametable
donewithnametable:
ldx #$00
-
- Posts: 1126
- Joined: Thu Apr 23, 2009 11:21 pm
- Location: cypress, texas
Re: background displaying only purple
There’s your post with your code surrounded by the code tags... quote this post to see what those tags look like.Kitty_Space_Program wrote: ↑Sun Dec 06, 2020 12:17 pmSo I'm trying to learn learn how to add a background. And when I start the rom, everything is purple. There isn't any color like it in the color palette and editing the color palette does nothing. turning off background rendering and sprite rendering does nothing. never turning nmi back on does nothing, nor does turning on grey scale. it covers up the sprite which I know is there, and if I jump over the load background code, it just loads the spite with white background (as is to be expected). the only way I've gotten a different result besides a purple background is if I turn the nmi on before loading the nametable, and obviously its extremely glitchy and it loops, but you can at least see the sprite. anyone got any ideas on whats happening?
heres the code I'm using if thats any help (note that for some reason the website won't show indents but they are there):
Code: Select all
loadbackground: ;#LOW(worlddata) into wrold and #HIGH(world) into world +1 lda #low(worlddata) ;lowbyte of adress world data remebr little endian sta world lda #high(worlddata) sta world+1 ;nametabe population bit $2002 lda #$20; sets 2000 as the name table were using sta $2006 lda #$00 sta $2006 ldy #$00 ldx #$00 populatenametable: lda (world),y sta $2007 iny cpx #$03 bne notdonewithnametable cpy #$0c0 beq donewithnametable notdonewithnametable: cpy #$00 bne populatenametable inx inc world+1 jmp populatenametable donewithnametable: ldx #$00

Note: Without those code tags surrounding code, the text of posts is processed like basic text on a webpage. HTML defaultly removes all “unnecessary” spacing from its text it displays in a browser. Therefore, all of your extra spaces, in front of your code, vanish; unless the code is wrapped in code tags.

-
- Posts: 1126
- Joined: Thu Apr 23, 2009 11:21 pm
- Location: cypress, texas
Re: background displaying only purple
Here, I’ll try to edit your code using “;;”
Hmmm, it seems to me that this code should work so:
1.) Are PPU writes incrementing horizontally (“horizontally” means: after every $2007 write the PPU address does +1, instead of writing vertically +32)?
(i.e. With $2000 set for horizontal PPU writes, after writing to PPU’s $2000, the next write to $2007 will write to PPU’s $2001; vertical PPU writing is for if you want to draw columns of tiles on the screen, instead of horizontal rows.)
I seem to remember experiencing your purple screen and learning from tokumaru about needing to change $2000 so horizontal writes were enabled.
2.) Your code can probably be simplified in some ways bc, for instance, you have a cpy #$00. After your iny, the zero flag is set appropriately; so, if your code can be rearranged so that:then, you can eliminate cpy #$00 since the zero flag is already adjusted.
(bne always branches if the zero flag is clear)
But, don’t worry about this now, just work on checking to see if $2000 has been adjusted appropriately.
edit: Emulators, with great debuggers, like Mesen can make finding out NES states relating to the last value written to $2000 quite easy.
Code: Select all
loadbackground: ;#LOW(worlddata) into wrold and #HIGH(world) into world +1
lda #low(worlddata) ;lowbyte of adress world data remebr little endian
sta world
lda #high(worlddata)
sta world+1
;nametabe population
bit $2002
lda #$20; sets 2000 as the name table were using
sta $2006
lda #$00
sta $2006
;;since, the accumulator is set to 0 above, you can save space below :)
tay;;ldy #$00
tax;;ldx #$00
populatenametable:
lda (world),y
sta $2007
iny
cpx #$03
bne notdonewithnametable
cpy #$0c0
beq donewithnametable
notdonewithnametable:
cpy #$00
bne populatenametable
inx
inc world+1
jmp populatenametable
donewithnametable:
ldx #$00
1.) Are PPU writes incrementing horizontally (“horizontally” means: after every $2007 write the PPU address does +1, instead of writing vertically +32)?
(i.e. With $2000 set for horizontal PPU writes, after writing to PPU’s $2000, the next write to $2007 will write to PPU’s $2001; vertical PPU writing is for if you want to draw columns of tiles on the screen, instead of horizontal rows.)
I seem to remember experiencing your purple screen and learning from tokumaru about needing to change $2000 so horizontal writes were enabled.
2.) Your code can probably be simplified in some ways bc, for instance, you have a cpy #$00. After your iny, the zero flag is set appropriately; so, if your code can be rearranged so that:
Code: Select all
iny;<sets zero flag if result is 0; otherwise the zero flag is cleared
cpy #$00
bne populatenametable
(bne always branches if the zero flag is clear)

But, don’t worry about this now, just work on checking to see if $2000 has been adjusted appropriately.

edit: Emulators, with great debuggers, like Mesen can make finding out NES states relating to the last value written to $2000 quite easy.

- Kitty_Space_Program
- Posts: 50
- Joined: Mon Sep 21, 2020 7:42 am
Re: background displaying only purple
Thank you for the help. It is using horizontal, not vertical, loading. I removed the part where I write the attribute table and the purple went away, now it just has the first sprite in the chr looped over and over. The bin I'm using works perfect in my name table editor, so I can only imagine there's a problem with sending the data to the 2007, not sure though.
edit: Also, I've found id I remove the incbin with the name table, nothing changes. also, to clarify, I'm using nesasm as my assembler
I have a mac, and all the mac debuggers I could find either didn't have an old enough version for the computer I am using (c. 2016) or they required building and I have found that I have never been angrier than when I build stuff since it always fails and I can't do high level computer stuff.unregistered wrote: ↑Mon Dec 07, 2020 2:52 amEmulators, with great debuggers, like Mesen can make finding out NES states relating to the last value written to $2000 quite easy.![]()
edit: Also, I've found id I remove the incbin with the name table, nothing changes. also, to clarify, I'm using nesasm as my assembler
- Kitty_Space_Program
- Posts: 50
- Joined: Mon Sep 21, 2020 7:42 am
Re: background displaying only purple
Update, figured it out. Apparently I needed to use
not
Code: Select all
lda [world],y
Code: Select all
lda (world),y
-
- Posts: 1126
- Joined: Thu Apr 23, 2009 11:21 pm
- Location: cypress, texas
Re: background displaying only purple
Congratulations!Kitty_Space_Program wrote: ↑Mon Dec 07, 2020 11:10 amUpdate, figured it out. Apparently I needed to usenotCode: Select all
lda [world],y
Code: Select all
lda (world),y


- Kitty_Space_Program
- Posts: 50
- Joined: Mon Sep 21, 2020 7:42 am
Re: background displaying only purple
Thanks, I wish I could find a list of nesasm macros and "syntax". this kind of stuff gets me all the time, especially since I've been following a tutorial written for another assembler completely. I think doing think that doing that does actually help me learn the syntax, eventually.
-
- Posts: 1126
- Joined: Thu Apr 23, 2009 11:21 pm
- Location: cypress, texas
Re: background displaying only purple
Hmmm... if NESASM is like asm6, it would have come with a README.txt kind of file that describes ALL syntax; and it also explains how to write a macro. Did you check for that type of file, where NESASM is installed, on your Mac?Kitty_Space_Program wrote: ↑Mon Dec 07, 2020 5:52 pmThanks, I wish I could find a list of nesasm macros and "syntax".
Re: background displaying only purple
The documentation for NESASM is a little on the short side, but the syntax is at least mostly documented in the "cpu_inst.txt" file.
Zero page addressing must be explicitly stated using the "<" operator. Otherwise it will always use absolute addressing.
The "usage.txt" file has the syntax of the built-in functions and assembler directives.
Code: Select all
-*[ NES ASM v2.51 ]*-
---------------
Instructions set
----------------
+------+----------+-----------------------------+
| | NVTBDIZC | Description |
+------+----------+-----------------------------+
| ADC | XX0---XX | Add with Carry |
| AND | X-0---X- | Logical AND |
| ASL | X-0---XX | Arithmetic Shift left |
| BCC | --0----- | Branch if Carry Clear |
| BCS | --0----- | Branch if Carry Set |
| BEQ | --0----- | Branch if Equal |
| BIT | XX0---X- | Bit Test |
| BMI | --0----- | Branch if Minus |
| BNE | --0----- | Branch if Not Equal |
| BPL | --0----- | Branch if Plus |
| BRA | --0----- | Branch Always |
| BRK | --0----- | Break |
| BVC | --0----- | Branch if Overflow Clear |
| BVS | --0----- | Branch if Overflow Set |
| CLC | --0----0 | Clear Carry flag |
| CLD | --0-0--- | Clear Decimal flag |
| CLI | --0--0-- | Clear Interrupt disable |
| CLV | -00----- | Clear Overflow flag |
| CMP | X-0---XX | Compare A with source |
| CPX | X-0---XX | Compare X with source |
| CPY | X-0---XX | Compare Y with source |
| DEC | X-0---X- | Decrement |
| DEX | X-0---X- | Decrement X |
| DEY | X-0---X- | Decrement Y |
| EOR | X-0---X- | Logical Exclusive OR |
| INC | X-0---X- | Increment |
| INX | X-0---X- | Increment X |
| INY | X-0---X- | Increment Y |
| JMP | --0----- | Jump |
| JSR | --0----- | Jump to Sub Routine |
| LDA | X-0---X- | Load A |
| LDX | X-0---X- | Load X |
| LDY | X-0---X- | Load Y |
| LSR | 0-0---XX | Logical Shift Right |
| NOP | --0----- | No Operation |
| ORA | X-0---X- | Logical inclusive OR |
| PHA | --0----- | Push A |
| PHP | --0----- | Push P |
| PLA | X-0---X- | Pull A |
| PLP | XXXXXXXX | Pull P |
| ROL | X-0---XX | Rotate Left |
| ROR | X-0---XX | Rotate Right |
| RTI | XXXXXXXX | Return from Interrupt |
| RTS | --0----- | Return from Sub Routine |
| SBC | XX0---XX | Substract with Carry |
| SEC | --0----1 | Set Carry flag |
| SED | --0-1--- | Set Decimal flag |
| SEI | --0--1-- | Set Interrupt disable |
| STA | --0----- | Store A |
| STX | --0----- | Store X |
| STY | --0----- | Store Y |
| TAX | X-0---X- | Transfer A to X |
| TAY | X-0---X- | Transfer A to Y |
| TSX | X-0---X- | Transfer S to X |
| TXA | X-0---X- | Transfer X to A |
| TXS | --0----- | Transfer X to S |
| TYA | X-0---X- | Transfer Y to A |
+------+----------+-----------------------------+
Operand syntax
--------------
A accumulator
#i immediate
<n zero page
<n,X zero page indexed by X
<n,Y zero page indexed by Y
[n] indirect (*)
[n,X] indirect pre-indexed by X (*)
[n],Y indirect zero page post-indexed by Y
r relative
n absolute
n,X absolute indexed by X
n,Y absolute indexed by Y
(*) can be zero page or absolute
--
The "usage.txt" file has the syntax of the built-in functions and assembler directives.
- Kitty_Space_Program
- Posts: 50
- Joined: Mon Sep 21, 2020 7:42 am
Re: background displaying only purple
ow thank you!
does that thing about the zero page apply to variables as well?
does that thing about the zero page apply to variables as well?
-
- Posts: 1126
- Joined: Thu Apr 23, 2009 11:21 pm
- Location: cypress, texas
Re: background displaying only purple
Cool, thank you Pokun! 
—-
To access zeropage cycle/byte reduction:
If a variable zp has been set to describe, say, byte $0001, then this is how it seems you’d have to write your zeropage-use to take advantage of zeropage efficiency:
It seems: the reason for the needed < is that NESASM was written in a manner where a syntax addition is needed to force zeropage efficiency; rather than newer assemblers that spend more cycles reading each instruction to and apply zeropage-use whenever it’s possible.
NESASM is still useable
; you just have to pay more attention to writing each line of zeropage-use code.
edit: Sorry, I don’t know what word to use so I made up “zeropage-use”
final-edit.
correction-edit: After noticing that the NESASM instructions lack a (*) following [n],y and researching a bit, MOS technology, the 6502’s creator, wrote:

—-
It seems to me that:Kitty_Space_Program wrote: ↑Tue Dec 08, 2020 2:27 pmdoes that thing about the zero page apply to variables as well?
hmmm... NESASM zeropage-use is a tad annoying...Pokun wrote: ↑Tue Dec 08, 2020 1:47 pmZero page addressing must be explicitly stated using the "<" operator. Otherwise it will always use absolute addressing.Code: Select all
-*[ NES ASM v2.51 ]*- --------------- ... Operand syntax -------------- A accumulator #i immediate <n zero page <n,X zero page indexed by X <n,Y zero page indexed by Y [n] indirect (*) [n,X] indirect pre-indexed by X (*) [n],Y indirect zero page post-indexed by Y r relative n absolute n,X absolute indexed by X n,Y absolute indexed by Y (*) can be zero page or absolute --
To access zeropage cycle/byte reduction:
If a variable zp has been set to describe, say, byte $0001, then this is how it seems you’d have to write your zeropage-use to take advantage of zeropage efficiency:
Code: Select all
lda <zp
lda <zp,x
lda <zp,y
lda [<zp]
lda [<zp,x]
lda [<zp],y ;maybe this line doesn’t need the < see
;correction-edit note below
;Note that the NESASM documentation doesn’t specify
;an instruction. lda was just used as an example of
;an instance where the < would be necessary to denote
;zeropage-use. :)
NESASM is still useable

edit: Sorry, I don’t know what word to use so I made up “zeropage-use”
final-edit.
correction-edit: After noticing that the NESASM instructions lack a (*) following [n],y and researching a bit, MOS technology, the 6502’s creator, wrote:
therefore, it seems that it should be impossible to access absolute addressing when using [n],y; so maybe the lack of that (*) is not an oversight. I bet the < isn’t needed in the [n],y to enable zero-page addressing bc that may be always enabled there anyway.The use of the Indirect Addressing mode is to give the user a location in Page Zero which can be put the calculated address.

Last edited by unregistered on Thu Dec 10, 2020 2:42 pm, edited 1 time in total.
Re: background displaying only purple
The phrase you are looking for is zero-page addressing.
When assembling it will be calculated and turned into the address of the variable by NESASM.
Yeah that "n" means any number expression. It can be a number literal, a label ("variable") or a mathematical expression combining all of that.Kitty_Space_Program wrote: ↑Tue Dec 08, 2020 2:27 pmow thank you!
does that thing about the zero page apply to variables as well?
When assembling it will be calculated and turned into the address of the variable by NESASM.
Yeah, besides easily forgetting that you need to use "<" whenever you use a zero-page address to gain the benefits of zero-page addressing, if you ever move a variable out of the zero-page, you must remove all references to it that is using "<" to make it use absolute addressing.