For the purposes of disassembling a rom;
I am able to reference a table and create a jump table using .word and the label for the table.
However, sometimes, only the low byte (and separately the high byte) is referenced in code.
How do I get the bytes separately using labels?
For example
some_table: ; starting at $8050
Lda #$50 ; low byte of address I want to refernce
Sta $00 ; store low byte in $00
Lda #80 ; high byte of address I want to reference
Sta $01 ; store high byte in $01
Lda ($00),y ; get stuff from the table
I want to remove the hard coded address, ultimately.
Can I do something like this:
Lda #<some_table ; to get the low byte of tbl addr
Sta $00
Lda #>some_table ; for the high byte
Sta $01
Lda ($00),y
How do I get the low byte of a data table address?
Moderator: Moderators
Re: How do I get the low byte of a data table address?
You can have a table of words where elements are accessed using even indices (0 = first element, 2 = second element, 4 = third element, etc.):
Using even indices can be inconvenient sometimes, so programmers may choose to use 2 separate tables, one for the low bytes and one for the high bytes:
Code: Select all
AddressTable:
.word Address0, Address1, Address2, Address3
ldx #$02 ;prepares to access the second element
lda AddressTable+0, x
sta $00
lda AddressTable+1, x
sta $01
Code: Select all
AddressTableLow:
.byte <Address0, <Address1, <Address2, <Address3
AddressTableHigh:
.byte >Address0, >Address1, >Address2, >Address3
ldx #$01 ;prepares to access the second element
lda AddressTableLow, x
sta $00
lda AddressTableHigh, x
sta $01
Re: How do I get the low byte of a data table address?
I've seen this used in other games, thanks for explaining why thats used.
My problem is the addresses are sometimes hard coded, I was wondering if there was a shorthand to address them directly without a table in the source code.
I should've mentioned that I'm using cl65.
I'll check the documentation
Re: How do I get the low byte of a data table address?
I checked the documentation for cc65:
10.9 .HIBYTE
The function returns the high byte (that is, bits 8-15) of its argument. It works identical to the '>' operator.
See: .LOBYTE, .BANKBYTE
Although, using .hibyte (and .lobytr) sprung an error on compiling, using <some_table and >some_table worked exactly like I expected it to.
10.9 .HIBYTE
The function returns the high byte (that is, bits 8-15) of its argument. It works identical to the '>' operator.
See: .LOBYTE, .BANKBYTE
Although, using .hibyte (and .lobytr) sprung an error on compiling, using <some_table and >some_table worked exactly like I expected it to.
Re: How do I get the low byte of a data table address?
Being functions, .hibyte and .lobyte probably require the argument to be placed between parentheses (e.g. .lobyte(Label)). I personally don't see much reason to use these functions, seeing as < and > are so much more compact.