It is currently Tue Nov 13, 2018 8:46 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: Fri Oct 19, 2018 8:29 am 
Offline

Joined: Sat May 26, 2018 6:14 am
Posts: 49
Location: Italy
Hello to everyone,
I'm implementing a Macro that put an enemy on the screen in this way:

Code:
MACROPutEnemyOnScene .macro
  lda $2002             
  lda #$20
  sta $2006             
  lda #$00
  sta $2006

  ldy #$00
LoadTargetSpriteLoop:
  lda \1, y
  sta \2, y
  iny
  cpy #$08
  bne LoadTargetSpriteLoop
  .endm


And i use it like this:

Code:
lda #LOW( target_up )
  sta TARGET_TO_LOAD + 0
  lda #HIGH( target_up )
  sta TARGET_TO_LOAD + 1

  MACROPutEnemyOnScene [TARGET_TO_LOAD], RAM_TARGET_UP



The problem, if I try to use the macro again, for example:

Code:
lda #LOW( target_down )
  sta TARGET_TO_LOAD + 0
  lda #HIGH( target_down )
  sta TARGET_TO_LOAD + 1

  MACROPutEnemyOnScene [TARGET_TO_LOAD], RAM_TARGET_DOWN


The compiler give me an error of duplicate label, it seems it "copy" the label everytime the macro is called. There is a way to put "generic" label or something like that to use the macro with a label inside? Because macros allow me to reduce a lot of duplicate code.

Thanks.


Top
 Profile  
 
PostPosted: Fri Oct 19, 2018 8:35 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 20761
Location: NE Indiana, USA (NTSC)
Which assembler is this for? The answer might be in the assembler's man page. In ca65, you can use .scope or .local to create macro-local labels, but this doesn't look like ca65.


Top
 Profile  
 
PostPosted: Fri Oct 19, 2018 8:36 am 
Offline

Joined: Sat May 26, 2018 6:14 am
Posts: 49
Location: Italy
tepples wrote:
Which assembler is this for? The answer might be in the assembler's man page.


NesAsm 3.1 .


Top
 Profile  
 
PostPosted: Fri Oct 19, 2018 8:38 am 
Offline

Joined: Sat May 26, 2018 6:14 am
Posts: 49
Location: Italy
The documentation ( https://github.com/thentenaar/nesasm/bl ... /usage.txt ) say:

Symbols
-------

Two types of symbol are supported, global symbols and local
symbols. Local symbols are preceded by a dot '.' and are valid
only between two global symbols. A symbol can be followed by
a colon ':' but this is not necessary.


Top
 Profile  
 
PostPosted: Fri Oct 19, 2018 8:40 am 
Offline

Joined: Sat May 26, 2018 6:14 am
Posts: 49
Location: Italy
If I put a dot before the label, it seems working:

Code:
MACROPutEnemyOnScene .macro
  lda $2002             
  lda #$20
  sta $2006             
  lda #$00
  sta $2006

  ldy #$00
.LoadTargetSpriteLoop:
  lda \1, y
  sta \2, y
  iny
  cpy #$08
  bne .LoadTargetSpriteLoop
  .endm


Top
 Profile  
 
PostPosted: Fri Oct 19, 2018 8:43 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 20761
Location: NE Indiana, USA (NTSC)
From usage.txt in camsaul/nesasm:
\@
Special parameter that returns a different number for each macro; can be used to define local symbols inside macros:
Code:
abs .macro
  lda \1
  bpl .x\@
  eor #$FF
  clc
  adc #1
  sta \1
.x\@:
  .endm


It turns out to be the same syntax used in RGBASM, which targets the Game Boy CPU. From man 5 rgbasm:
To get around this problem there is a special label string equate called \@ that you can append to your labels and it will then expand to a unique string. \@ also works in REPT-blocks should you have any loops there.
Code:
LoopyMacro: MACRO
  xor a,a
.loop\@
  ld [hl+],a
  dec c
  jr nz,.loop\@
  ENDM


Top
 Profile  
 
PostPosted: Fri Oct 19, 2018 3:55 pm 
Offline

Joined: Tue Jun 28, 2011 2:39 pm
Posts: 192
I'd strongly advise switching to ASM6 (or ASM6f if you need Mesen labels for debugging), syntax is much simpler (NESASM does several things very weirdly compared to most assemblers).


Top
 Profile  
 
PostPosted: Sun Oct 21, 2018 6:34 am 
Offline

Joined: Sat May 26, 2018 6:14 am
Posts: 49
Location: Italy
Ok, where I can find some documentation about ASM6 and Nes?


Top
 Profile  
 
PostPosted: Sun Oct 21, 2018 10:59 am 
Offline
User avatar

Joined: Thu Mar 31, 2016 11:15 am
Posts: 415
https://github.com/freem/asm6f

Checkout readme-original.txt


Top
 Profile  
 
PostPosted: Sun Oct 21, 2018 1:18 pm 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10959
Location: Rio de Janeiro - Brazil
I think he meant ASM6 applied specially to NES programming.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 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