Jump to content
IGNORED

Indirect reference using Atasm


Recommended Posts

How to store a value in memory at an address stored in a variable in Atasm? I tried various things to no avail:

 

player_ptr
    .ds 2

; set the value of player_ptr
...

; Try to modify the address stored in player_ptr
lda #$ff
sta *player_ptr     ; no-op?
sta (player_ptr)    ; the compiler complains of an Illegal indirect reference

 

Link to comment
Share on other sites

7 hours ago, l12n said:

OK, so after further research it appears the only way to do an indirect reference is by 1) using a X or Y register and 2) using a zero-page address

You could use this type of method :)

Output screen shot shown

 

 

    ; pseudo pointer demo NOT using Page zero
    ; ptr is the pointer which will update each time the routine is called
player=$1ff0    ; where we want the data put, ensure we cross a boundary to check increment works ok

    org $600
    ldx #0
loop    jsr pointer
    inx
    cpx #[tabend-table] 
    bne loop
    rts

    ; this is where we update the ptr address

pointer inc ptr+1    ; increment lo byte
    bne ok
    inc ptr+2        ; increment hi byte if crossed a page
ok    lda table,x
ptr   sta player-1    ; ensure we get the first byte correct @$1ff0
    rts
    ; dummy data
table    .byte 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0
tabend

 

image.thumb.png.798a1060d6194f1ef3e83aded557a853.png

Link to comment
Share on other sites

Not really an assembler limitation but the CPU itself.

 

I used AtAsm - firstly, though it's fairly close to Mac-65 there's at least a couple way better cross-assemblers in common use (ie MADS)

Next up - make sure you're using a later less buggy version, I remember having problems with an earlier one some time back.

Link to comment
Share on other sites

On 1/17/2024 at 8:21 PM, l12n said:

How to store a value in memory at an address stored in a variable in Atasm? I tried various things to no avail:

 

player_ptr
    .ds 2

; set the value of player_ptr
...

; Try to modify the address stored in player_ptr
lda #$ff
sta *player_ptr     ; no-op?
sta (player_ptr)    ; the compiler complains of an Illegal indirect reference

 

Not sure what you are trying to do but you can always use self-modifying code as a pseudo-pointer.

 

Similar to this simple byte copy routine:

 

 

; set source = $1000 and
; destination = $2000
; in the $FFFF bytes below
LDA #$10
STA SOURCE+2
LDA #$20
STA DESTINATION+2

 

LDA #$00
STA SOURCE+1       ; +1 to skip over LDA OP code byte
STA DESTINATION+1  ; +1 to skip over STA OP code byte

 

LDX #$0

 

LOOP

 

; the following $FFFF bytes to be set by the code above
; and updated by the code below
SOURCE LDA $FFFF
DESTINATION STA $FFFF

 

; modify the $FFFF bytes above to point to next locations
INC SOURCE+1
BNE NOOVER1
INC SOURCE+2
NOOVER1

 

INC DESTINATION+1
BNE NOOVER2
INC DESTINATION+2
NOOVER2

 

INX

 

BNE LOOP

 

Link to comment
Share on other sites

8 hours ago, Qwe said:

indirect addressing on the 6502 is only possible if the variable that acts as a pointer is on page 0.

In terms of load/store, yes. Indexed Indirect (using X) and Indirect Indexed (using Y) are both 2 byte instructions, the second being the zero-page address.

Indirect JMP however is a 3 byte instruction using a word address, a pointer to the address holding the word address loaded to the PC.  

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...