l12n Posted January 18 Share Posted January 18 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 Quote Link to comment Share on other sites More sharing options...
l12n Posted January 18 Author Share Posted January 18 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 Quote Link to comment Share on other sites More sharing options...
Wrathchild Posted January 18 Share Posted January 18 (edited) [misread] Edited January 18 by Wrathchild Quote Link to comment Share on other sites More sharing options...
sanny Posted January 18 Share Posted January 18 5 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 Indeed http://6502.org/tutorials/ Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted January 18 Share Posted January 18 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 Quote Link to comment Share on other sites More sharing options...
Rybags Posted January 18 Share Posted January 18 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. Quote Link to comment Share on other sites More sharing options...
EddyFree Posted January 22 Share Posted January 22 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 Quote Link to comment Share on other sites More sharing options...
Qwe Posted January 29 Share Posted January 29 If I remember correctly, indirect addressing on the 6502 is only possible if the variable that acts as a pointer is on page 0. Quote Link to comment Share on other sites More sharing options...
Wrathchild Posted January 30 Share Posted January 30 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.