casprog wrote:Code: Select all
LDA #$06
STA $80
LDA #$07
STA $80 + 1
This would load into A the value at memory location $0706+y. Is that what you intended? Unless you're using NESASM, in which case I think the
LDA ($80), y would assemble to
LDA $80, y, so the value at $0080+y would end up in the accumulator.
First question is, by writing to $80 I'm still in Zero Page correct? And am writing into NES RAM?
Yes, zero page is RAM. For the 6502, the 64KB address space is conceptually divided into 256 pages of 256 bytes. Page zero is the first page, where addresses have $00 as the high byte (i.e. $0000-$00FF). The reason the term "zero page" exists is because some instructions only work in that space, and other instructions have faster versions that work in that space. These instructions are faster because don't care about the high byte of the addresses, which is assumed to always be $00.
If nothing else in my code explicitly touches $80 through $80 + 2, can anything else from the NES alter those values in any way?
No. The only memory that's automatically overwritten by the system is the stack, since interrupts and subroutine calls put data there. If you're coding everything yourself, only your own code will touch $0000-$00FF and $0200-$07FF. Be careful if you use someone else's music engine for example, because it will certainly need so use memory somewhere, so be sure not to create conflicts in this case.
Code: Select all
ppuBufferPtr .rs 1
.......
LDA $80
STA ppuBufferPtr
.......
LDA [ppuBufferPtr], y ; also tried LDA (ppuBufferPtr), y
Pointers are always 16-bit, and you're trying to use a single byte as a pointer. A proper pointer to $0080 works like this:
Code: Select all
ppuBufferPtr .rs 2
.......
LDA #$80
STA ppuBufferPtr
LDA #$00
STA ppuBufferPtr+1
.......
LDA [ppuBufferPtr], y ; if NESASM
LDA (ppuBufferPtr), y ; if anything else
Note that you also forgot the # in
LDA #$80, which means you want to put the immediate value $80 into the accumulator.
LDA $80 will get the value at memory location $0080 and put that into the accumulator, which is not what you want if your intention is to create a pointer to $0080.