I'm trying to define my memory space for all of my variables in the following way currently.
RAM8_0 = $0300
RAM8_1 = $0300
RAM16_0 = $0310
...ettc
later in code I'll do something like
offset_counter = RAM8_0
byte_count = RAM8_1
index_ptr = RAM16_0
My problem is when I want to define a 2 byte variable for use as an indirect pointer I get an overflow error because the instruction doesn't know to treat the variable as 2 bytes. If i define the variable in the following way it works.
index_ptr: .res 2
My question is how do I assign a specific address for index_ptr AND let the compiler know to treat it as a two byte address. Thank you.
defining memory space
Moderator: Moderators
Re: defining memory space
On 6502, pointers can only be in zeropage.
(Exception: pointers for indirect jumps)
(Exception: pointers for indirect jumps)
-
- Posts: 1313
- Joined: Thu Apr 23, 2009 11:21 pm
- Location: cypress, texas
Re: defining memory space
ummm… well,
(I’m using asm6; whatever I write should be translatable, I think, into a form for your assembler. Though, you are using a compiler; so, I’m honestly unsure how 6502 math works in a compiler.)
Pointers can be used to point to any location; though, they usually must sit in zero page so that:
works; that instruction is always assembled into 2 bytes. The first byte becomes $B1 and the second byte always addresses a zero page address bc it’s just 1 byte.
Symbols, assigned with =, can hold 16bit values, like you’ve written. However, most all variables on the 6502 are byte size. The symbols aren’t variables; and so, they CAN’T be written to during the game. They are sections of memory in your CPU that you’ve assigned for use only during your game’s assembly. i.e.:
The assembler, for the most part, uses 8bit addresses exclusively. Therefore, both bytes of a 16bit variable need to be accessed during an addition. i.e.:
6502 assemblers’ variables have to be accessed in a byte-manner, like above. And since a nes compiler translates written high level language into 6502 assembly, I believe there isn’t a way to use actual 16bit variables, in a 16bit form, when writing high level language for the NES.
I’m clearly not certain of that; I’ve always used assembly bc a compiler’s translationlooses speed reduces the speed of your code and it’s not a direct way to access the NES’es 2A03 (or 6502). 
(I’m using asm6; whatever I write should be translatable, I think, into a form for your assembler. Though, you are using a compiler; so, I’m honestly unsure how 6502 math works in a compiler.)
Pointers can be used to point to any location; though, they usually must sit in zero page so that:
Code: Select all
lda (ptr1), y
Symbols, assigned with =, can hold 16bit values, like you’ve written. However, most all variables on the 6502 are byte size. The symbols aren’t variables; and so, they CAN’T be written to during the game. They are sections of memory in your CPU that you’ve assigned for use only during your game’s assembly. i.e.:
Code: Select all
RAM8_0 = $0300
lda #18
sta RAM8_0 ;<Error
The assembler, for the most part, uses 8bit addresses exclusively. Therefore, both bytes of a 16bit variable need to be accessed during an addition. i.e.:
Code: Select all
clc ;clears carry
lda low_byte
adc #49 ;this instruction may set the carry
sta low_byte
lda high_byte
adc #00 ;is added to the accumulator with value of carry
sta high_byte
6502 assemblers’ variables have to be accessed in a byte-manner, like above. And since a nes compiler translates written high level language into 6502 assembly, I believe there isn’t a way to use actual 16bit variables, in a 16bit form, when writing high level language for the NES.
I’m clearly not certain of that; I’ve always used assembly bc a compiler’s translation
