Hello!
I've been writing and studying basic SNES/65816 examples that I can look at in a debugger since visually analyzing things enables me to learn better. One of the more basic concepts which I thought I fully understood but apparently don't is tables.
My main question is: Is it up to the programmer to specify which bank the table is stored in when trying to access it?
Yesterday I was writing a very simple program that accessed, read and stored a value from a table. For the fun of it I specified a different bank since I figured in larger programs you might be required to do that anyways. Little did I know this would cause quite a bit of confusion for myself. My table looked like this (Note: I am using WLA-DX and the .BANK directive to specify bank 1 instead of bank 0):
Then i had a small snippet of code that loaded Y with a value, and I accessed MyTable with the index and stored it in $10 (Another note: I have ldx $77 in there so that I could set a breakpoint on 'read' on 7E0077 to see the execution of everything afterwards):
In this instance I expected to see the value #$15 stored at RAM location 7E0010. Instead I was seeing the value #$A2 being stored. This confused me and I scratched my head for a couple hours. When I debugged the program I would see this:
When I looked in ROM at 80811C+5 the value there was indeed #$A2. I kept looking back and forth, re-running, tracing until finally after about half an hour it hit me. My table is in bank 1, but the program is looking at bank 0.
I looked at bank 1 instead and sure enough my correct table values were there. I modified my program to have the table in bank 0 and it stored the proper values. All that being said I learned a good lesson out of it. I suppose I incorrectly assumed that by specifying the table is in bank 1 that the main code where I do lda MyTable,y it would know to look in bank 1 rather than default to bank 0.
Looping back to my original question of Is it up to the programmer to specify which bank the table is stored in when trying to access it? I am guessing the answer is yes? I am re-reviewing addressing modes but if anyone has any insight or examples I would appreciate it.
I've been writing and studying basic SNES/65816 examples that I can look at in a debugger since visually analyzing things enables me to learn better. One of the more basic concepts which I thought I fully understood but apparently don't is tables.
My main question is: Is it up to the programmer to specify which bank the table is stored in when trying to access it?
Yesterday I was writing a very simple program that accessed, read and stored a value from a table. For the fun of it I specified a different bank since I figured in larger programs you might be required to do that anyways. Little did I know this would cause quite a bit of confusion for myself. My table looked like this (Note: I am using WLA-DX and the .BANK directive to specify bank 1 instead of bank 0):
Code:
.BANK 1 SLOT 0
MyTable:
.db $10,$11,$12,$13,$14,$15,$16,17,$18,$19,$1A,$1B,$1C,$1D,$1E,$1F
MyTable:
.db $10,$11,$12,$13,$14,$15,$16,17,$18,$19,$1A,$1B,$1C,$1D,$1E,$1F
Then i had a small snippet of code that loaded Y with a value, and I accessed MyTable with the index and stored it in $10 (Another note: I have ldx $77 in there so that I could set a breakpoint on 'read' on 7E0077 to see the execution of everything afterwards):
Code:
ldy #$05
ldx $77
lda MyTable,y
sta $10
ldx $77
lda MyTable,y
sta $10
In this instance I expected to see the value #$15 stored at RAM location 7E0010. Instead I was seeing the value #$A2 being stored. This confused me and I scratched my head for a couple hours. When I debugged the program I would see this:
Code:
$00/8148 A6 77 LDX $77 [$00:0077] A:5BA2 X:0000 Y:0005 P:envMxdizC
$00/814A B9 1C 81 LDA $811C,y[$00:8121] A:5BA2 X:0000 Y:0005 P:envMxdiZC
$00/814D 85 10 STA $10 [$00:0010] A:5BA2 X:0000 Y:0005 P:eNvMxdizC
$00/814A B9 1C 81 LDA $811C,y[$00:8121] A:5BA2 X:0000 Y:0005 P:envMxdiZC
$00/814D 85 10 STA $10 [$00:0010] A:5BA2 X:0000 Y:0005 P:eNvMxdizC
When I looked in ROM at 80811C+5 the value there was indeed #$A2. I kept looking back and forth, re-running, tracing until finally after about half an hour it hit me. My table is in bank 1, but the program is looking at bank 0.
I looked at bank 1 instead and sure enough my correct table values were there. I modified my program to have the table in bank 0 and it stored the proper values. All that being said I learned a good lesson out of it. I suppose I incorrectly assumed that by specifying the table is in bank 1 that the main code where I do lda MyTable,y it would know to look in bank 1 rather than default to bank 0.
Looping back to my original question of Is it up to the programmer to specify which bank the table is stored in when trying to access it? I am guessing the answer is yes? I am re-reviewing addressing modes but if anyone has any insight or examples I would appreciate it.