I am going through some code that is a tutorial for 6502 Assembly NES game programming called "Nerdy Nights". In it there is a piece of code that I am having trouble understanding, which uses a 2 byte lookup table for indexing.
Here is part of the lookup table and the code;
Code: Select all
note_table:
.word $07F1, $0780, $0713
.word $06AD, $064D, $05F3, $059D, $054D, $0500, $04B8, $0475, $0435, $03F8, $03BF, $0389
lda #$0C ;the 13th entry in the table (A2)
asl a ;multiply by 2 because we are indexing into a table of words
tay
lda note_table, y ;read the low byte of the period
sta $4002 ;write to SQ1_LO
lda note_table+1, y ;read the high byte of the period
sta $4003 ;write to SQ1_HI
In the code above, why can't we just load the y register with the value #$18 (24 decimal), rather than;
lda #$0C ;load a with 12
asl a ;shift left to multiple by 2, now A contains 24 dec (#$18)
tay
lda note_table, y ;read the low byte of the period, y = 24 and loads the value $03 from the note table above
sta $4002 ;write to SQ1_LO, write $03 to $4002
lda note_table+1, y ;read the high byte of the period
sta $4003 ;write to SQ1_HI, write second byte $f8 (from note table) to $4003
Thanks for any help anyone might be able to offer.
TonyAme