I haven't got a clue what most of that means, but I'll just take it as read that I should use LDA.w anytime I run into trouble!There's no need really. Using .w just tells WLA that you want to use the absolute-addressed version of the instruction, so it can use a full 16-bit operand. Using direct page would be slightly faster, but unless you want to figure out how to tell WLA to only use the bottom half of the label, you'd need to use page zero, and unless your data bank is a HiROM region (it shouldn't be), page zero is in shadow RAM, so you'd have to spend more effort loading the table into RAM at boot. Furthermore, you'd need to be sure the direct page register was pointing at page zero before using this subroutine, since in general it's not.
Less trouble to just use absolute addressing.
I've reorganised the code to now be like this:
Code: Select all
; TABLE EXAMPLE.
.include ".\SNESfiles\Header.inc" ; Include SNES header information.
.include ".\SNESfiles\Snes_Init.asm" ; Include SNES initialisation code.
; Needed to satisfy interrupt definition in "Header.inc".
VBlank:
RTI
.bank 0
.section "MainCode"
Start: ; Start of the program.
Snes_Init ; Initialize the SNES. This resets the SNES to a known state.
STZ $19
LDX $19 ; Mario's power-up state.
LDA.w Table,x ; Load the table, indexed by power-up ($19)
STA $09 ; get the value into $9.
RTL ; Return
Table:
.db $08,$1C,$24,$48 ; Table of timer values. Value can't go beyond #$FF unless in 16-bit mode.
; 00 01 02 03
; Loop forever.
Forever:
JMP Forever
.ends