It is currently Sat Aug 18, 2018 7:12 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Noob question about .db
PostPosted: Thu Aug 02, 2018 9:00 am 
Offline

Joined: Sat May 26, 2018 6:14 am
Posts: 39
Location: Italy
Hello again!

I've two declarations like this:

Code:
an_player_idle:
  .db $00,$01,$10,$11,$20,$21,$30,$31,$40,$41

an_player_walk:
  .db $04,$05,$14,$15,$24,$25,$34,$35,$44,$45


So I can set the idle animation in this way:

Code:
SetAnIdle:
  LDX #$01
  LDY #$00
SetAnIdleLoop:
  LDA an_player_idle, y
  STA SPRITE_RAM, x
  INY
  INX
  INX
  INX
  INX
  CPX #$2D
  BNE SetAnIdleLoop


Now, there is a way to put the address of "an_player_idle" in a variable so I can change it at runtime and so doing something like this:

Code:

  LDA an_player_idle
  STA MY_VARIABLE

SetAnIdleLoop:
  LDA MY_VARIABLE, y
  STA SPRITE_RAM, x


Thanks!


Top
 Profile  
 
PostPosted: Thu Aug 02, 2018 9:05 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 20417
Location: NE Indiana, USA (NTSC)
You can allocate a 2-byte variable in zero page to hold a pointer to the start of the table and then use the indirect indexed addressing mode (dd),Y to read through the pointer.
Code:
  ; Fill the pointer
  lda #<an_player_idle
  sta myvariable+0
  lda #>an_player_idle
  sta myvariable+1
  ; Index from the pointer
  lda (myvariable),y

Operators < and > extract the low byte (bits 7-0) and the high byte (bits 15-8) of the address used with them.

In NESASM (only), the (dd),Y mode is instead spelled [dd],Y with square brackets.


Top
 Profile  
 
PostPosted: Thu Aug 02, 2018 9:29 am 
Offline

Joined: Sat May 26, 2018 6:14 am
Posts: 39
Location: Italy
Great! It works! :) Thanks

In NESASM
Code:
; Fill the pointer
  LDA #LOW(an_player_walk)
  STA AN_PLAYER_TO_LOAD+0
  LDA #HIGH(an_player_walk)
  STA AN_PLAYER_TO_LOAD+1

  LDA [AN_PLAYER_TO_LOAD],y


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group