So each pointer variable must be 2 bytes long? I'm guessing you have already said yes to this, but I'd like confirmation... please.
It says exactly this in the quote. He said it must be, and he said why.
If I have a variable called rowPointer that's a size of 2 bytes, then do I have to use the indirect index addressing to read rowPointer as a pointer? Is indirect index addressing the only way to use pointers in assembly language?
Edit: On second thought, It is more or less the only way to read from rowPointer as a pointer. You will want to use indirect indexed for what you're trying now.
For question two: This is not the only way to use pointers in 6502. There's also indexed indirect, but people don't generally use that because it is a very indirect way to get data from an address. As well, you can jmp to a pointer which is just called indirect to my knowledge, and you can do creative things with the stack and RTS. But none of that matters for what you're doing right now.
I remember I could put a dot in front of a pointer's name to use it... maybe... in a language like c++?
6502 assembly isn't "type safe" like C is. What this means is your program/assembler doesn't know or care what you are using your variables for. C will actually fix how operations work on a variable based on what you're using that variable for. For instance, pointer++; could increase the address the pointer is holding by 1, 2 or any other number depending on how large the type of data is that the pointer is supposed to point to. Assembly doesn't care, so it's up to you to keep track.
I just want to say "Go to rowPointer's row." How can I say that in assembly 6502.
Edit 2: After writing this post, I realize I may have misunderstood your question. Assuming rowPointer and rowPointer+1 already contain the low and high bytes of the address you want to point to, it's as easy as
where y contains how many places to add to that address to get the byte you want.
The below examples may still be helpful, though.
Code: Select all
row:
.db $whatever, $whatever, $whatever; i.e. your data.
lda #low(row);Syntax for how to get the high and low part of an address may vary based on your assembler
sta $00;Store in a RAM location.
lda #high(row)
sta $01;Store in a RAM location.
lda ($00),y;This now gets the same result in A that lda row,y would.
$00, and $01 are your pointer variables.
;Note that the variable that holds the LOW BYTE of the pointer's address goes in between the paranthesis.
;Note: To use this addressing mode, the low byte of the address MUST BE stored in a RAM location that is EXACTLY one byte before the RAM location where the high byte is stored.
;$00 = low
;$01 = high; is fine.
;$01 = low
;$02 = high; is fine.
;F1 = low
;F2 = high; is fine.
;$01 = low
;$00 = high; is NOT fine.
Naturally the above code is pretty useless. You could use lda rowPointer,y instead. So here's something useful.
Code: Select all
Row0:
.db $00, $00;Your data
Row1:
.db $FF, $FE; $50;Your data
Row2:
.db $05;You get the point.
;etc
;Now you keep two separate lists of the high and low byte for this data.
RowLow:
.db low(Row0);As said before, syntax for this may vary
.db low(Row1)
.db low(Row2);etc
RowHigh:
.db high(Row0)
.db high(Row1)
.db high(Row2)
ldy rownumber
lda RowLow,y
sta $00
lda RowHigh,y
sta $01
ldy #$00
lda ($00),y;Depending on what "rownumber" is you will load from a different address.
;if rownumber was 0:
;You load #$00 which is the first byte of data after the Row0 label.
;if rownumber was 1:
;You load #$FF which is the first byte of data after the Row1 label.
;if rownumber was 2:
;You load #$05 which is the first byte of data after the Row2 label.
That's how you do it. (Provided I didn't make a stupid mistake like saying $2000 instead of $2001.)