nesdev.com
http://forums.nesdev.com/

How to use ASM6 conditions (IF)?
http://forums.nesdev.com/viewtopic.php?f=2&t=16878
Page 1 of 1

Author:  MartsINY [ Sat Dec 30, 2017 2:38 pm ]
Post subject:  How to use ASM6 conditions (IF)?

Simple,

IF are simple to use (from README):

IF j>0

However I have something more complex:

IF (OBJ_Dir_Bits,X AND #$01 == #$00)

How should I write this

Author:  nesrocks [ Sat Dec 30, 2017 2:55 pm ]
Post subject:  Re: How to use ASM6 conditions (IF)?

How about
Code:
LDA OBJ_Dir_Bits,X
AND #$01
BEQ resultiszerolabel
notzero:
...
resultiszerolabel:
...


edit: actually your code didn't make much sense, if 1 == 0? Why not give a more concrete example?
If you just want a generic code to check if two conditions are true I guess you don't have much choice, do one and then do the other.

Author:  MartsINY [ Sat Dec 30, 2017 3:16 pm ]
Post subject:  Re: How to use ASM6 conditions (IF)?

nesrocks wrote:
How about
Code:
LDA OBJ_Dir_Bits,X
AND #$01
BEQ resultiszerolabel
notzero:
...
resultiszerolabel:
...


edit: actually your code didn't make much sense, if 1 == 0? Why not give a more concrete example?
If you just want a generic code to check if two conditions are true I guess you don't have much choice, do one and then do the other.


Thanks for your answer.
However I know full well how to do the condition with BEQ and such. However, ASM6 allow the use of IF, which is easier to read. I would prefer to use them.

About the condition I do not understand why it doesn't make sense? I want to ensure BIT 0 if to 0. It's a flag. So let's say my variable has the value FF
then AND #$01 return #$01. I then want to branch according to the value.

On the opposite, if its value is #$FE, AND #$01 will return #$00.

Author:  nesrocks [ Sat Dec 30, 2017 3:24 pm ]
Post subject:  Re: How to use ASM6 conditions (IF)?

Then shouldn't it be...
Code:
IF (OBJ_Dir_Bits,X AND #$01) == #$00

Better yet:
Code:
IF !(OBJ_Dir_Bits,X AND #$01)

I'm not sure about the order in which asm6 processes the operators, but it just may be that it would do the == comparator before everything else.

Author:  MartsINY [ Sat Dec 30, 2017 3:38 pm ]
Post subject:  Re: How to use ASM6 conditions (IF)?

nesrocks wrote:
Then shouldn't it be...
Code:
IF (OBJ_Dir_Bits,X AND #$01) == #$00

Better yet:
Code:
IF !(OBJ_Dir_Bits,X AND #$01)

I'm not sure about the order in which asm6 processes the operators, but it just may be that it would do the == comparator before everything else.



Thanks, you are right about the way I wrote it. However it seems that syntax is not accepted by ASM6, and the Readme is far to be detailed about this...

Author:  nesrocks [ Sat Dec 30, 2017 3:58 pm ]
Post subject:  Re: How to use ASM6 conditions (IF)?

Maybe it's the addressing mode. Can you see if this works?

IF !(OBJ_Dir_Bits AND #$01)

If this works I don't know, I guess you're gonna have to store it in A and then do the IF using A instead.

Author:  MartsINY [ Sat Dec 30, 2017 4:02 pm ]
Post subject:  Re: How to use ASM6 conditions (IF)?

nesrocks wrote:
Maybe it's the addressing mode. Can you see if this works?

IF !(OBJ_Dir_Bits AND #$01)

If this works I don't know, I guess you're gonna have to store it in A and then do the IF using A instead.


unfortunately this doesn't work either... incorrect expression

Author:  tokumaru [ Sat Dec 30, 2017 4:07 pm ]
Post subject:  Re: How to use ASM6 conditions (IF)?

Assembler conditionals are for assembly-time decisions, not run-time decisions. You can't check the values of game variables or do any game logic with them.

Author:  MartsINY [ Sat Dec 30, 2017 4:17 pm ]
Post subject:  Re: How to use ASM6 conditions (IF)?

tokumaru wrote:
Assembler conditionals are for assembly-time decisions, not run-time decisions. You can't check the values of game variables or do any game logic with them.


Ah so it's not a way to convert a IF to conditions with BEQ, etc?

Author:  tokumaru [ Sat Dec 30, 2017 4:38 pm ]
Post subject:  Re: How to use ASM6 conditions (IF)?

Nope. It's for testing conditions that affect how the program is assembled. You can test variable addresses, the value of the PC, symbols used for settings, things like that.

You can for example define a PAL/NTSC symbol that you check whenever the program needs to assemble something different for each of these versions, so you can generate either a PAL or NTSC ROM just by changing the value of this symbol.

What you want to do (make conditional branches more readable) can kinda be accomplished with macros. ASM6's macro system isn't the most advanced, but you should be able to do something like this:

Code:
  lda OBJ_Dir_Bits,X
  and #$01
  IFEQ
    ;"if equal" code here
  ELSE
    ;"if not equal" code here
  ENDIF

Using these macros:

Code:
.macro IFEQ
  bne +Else
.endm

.macro ELSE
  jmp +End
  +Else:
.endm

.macro ENDIF
  +End:
.endm

There are probably better "IF" implementations out there, but I'm not sure how far you can get with ASM6.

Author:  MartsINY [ Sat Dec 30, 2017 4:41 pm ]
Post subject:  Re: How to use ASM6 conditions (IF)?

tokumaru wrote:
Nope. It's for testing conditions that affect how the program is assembled. You can test variable addresses, the value of the PC, symbols used for settings, things like that.

You can for example define a PAL/NTSC symbol that you check whenever the program needs to assemble something different for each of these versions, so you can generate either a PAL or NTSC ROM just by changing the value of this symbol.

What you want to do (make conditional branches more readable) can kinda be accomplished with macros. ASM6's macro system isn't the most advanced, but you should be able to do something like this:

Code:
  lda OBJ_Dir_Bits,X
  and #$01
  IFEQ
    ;"if equal" code here
  ELSE
    ;"if not equal" code here
  ENDIF

Using these macros:

Code:
.macro IFEQ
  bne +Else
.endm

.macro ELSE
  jmp +End
  +Else:
.endm

.macro ENDIF
  +End:
.endm

There are probably better "IF" implementations out there, but I'm not sure how far you can get with ASM6.



thanks a lot for your answer!! Since you mentionned it's not the best for macro, is there a better program than ASM6? This is the first I used, so far I like it but if there are better I'd be interested to learn them.

Author:  tokumaru [ Sat Dec 30, 2017 4:58 pm ]
Post subject:  Re: How to use ASM6 conditions (IF)?

CA65's macro system if extremely powerful. People have implemented entirely new instruction sets using CA65 macros. IIRC, tepples reimplemented 6502 from scratch (as a proof of concept) and blargg did GBZ80, on a 6502 assembler... that's impressive!

ASM6 is great for getting a quick ROM ready, and is very easy to pick up and use, but it doesn't offer much to help manage larger projects. Not that you can't use it for larger projects, but you'll have to handle banking, pointers, memory allocation and stuff more actively, instead of using built-in functionality or your own macros to manage some of this stuff automatically. That being said, CA65 has a much steeper learning curve.

Author:  tokumaru [ Sat Dec 30, 2017 6:13 pm ]
Post subject:  Re: How to use ASM6 conditions (IF)?

You might want to check this thread out: viewtopic.php?f=2&t=9272

Author:  MartsINY [ Sat Dec 30, 2017 6:52 pm ]
Post subject:  Re: How to use ASM6 conditions (IF)?

thanks, I will check it!!

Page 1 of 1 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/