Becouse of memory map, that separate ROM and RAM too far of each other, I use this method:
1. When I need some constant in ROM area, I use DC.x directive, like this:
Code: Select all
Text: dc.b 'Some text',0 ;You should watch out odd count of chars (with break one)! It must be even, or when you try to access to next one you will get an Address Error exception.
Word: dc.w $0000
Long: dc.l $00000000
2. When I need some RAM variables, I use this:
Code: Select all
BaseAddr equ $FF0000
SomeVar1 equ BaseAddr
SomeVar2 equ SomeVar1+2 ;SomeVar1 is WORD, so next one must skip 2 bytes
SomeVar3 equ SomeVar2+1 ;SomeVar2 is BYTE.
SomeVar4 equ SomeVar3+1
SomeVar5 equ SomeVar4+2
FreeMem equ SomeVar5+4 ;FreeMem pointer to free location.
You can set any BaseAddr value and move your variable file anywhere in RAM. And when you will assemble your ROM, it will consist only actual ROM data.
And ofcourse this is assembler. there are no restrictions to data type. Both cases used pointer to data. So, two byte variables SomeVar2 and SomeVar3 can be read as single word at pointer SomeVar2. It's very usefull when you using, for exsample, X and Y coordinates.
Code: Select all
move.b SomeVar2,d0 ; d0 will contain the X at lower byte
move.b SomeVar3,d1 ; d1 will contain the Y at lower byte
move.w SomeVar2,d2 ; d2 will contain the X and Y at lower word and X will placed to high byte, Y placed to low byte of word
Ofcourse, we can use pointer as number and use this method:
Code: Select all
move.l #SomeVar2,d0 ; We placed address (not value! using #) of variable to d0 register
move.l d0,a0 ; Then moved this address to a0 register
move.b (a0)+,d0 ; And then get access to our variables
move.b (a0)+,d1
That is enough?