Page 1 of 1

How to use ASM6 conditions (IF)?

Posted: Sat Dec 30, 2017 2:38 pm
by MartsINY
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

Re: How to use ASM6 conditions (IF)?

Posted: Sat Dec 30, 2017 2:55 pm
by nesrocks
How about

Code: Select all

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.

Re: How to use ASM6 conditions (IF)?

Posted: Sat Dec 30, 2017 3:16 pm
by MartsINY
nesrocks wrote:How about

Code: Select all

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.

Re: How to use ASM6 conditions (IF)?

Posted: Sat Dec 30, 2017 3:24 pm
by nesrocks
Then shouldn't it be...

Code: Select all

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

Code: Select all

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.

Re: How to use ASM6 conditions (IF)?

Posted: Sat Dec 30, 2017 3:38 pm
by MartsINY
nesrocks wrote:Then shouldn't it be...

Code: Select all

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

Code: Select all

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...

Re: How to use ASM6 conditions (IF)?

Posted: Sat Dec 30, 2017 3:58 pm
by nesrocks
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.

Re: How to use ASM6 conditions (IF)?

Posted: Sat Dec 30, 2017 4:02 pm
by MartsINY
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

Re: How to use ASM6 conditions (IF)?

Posted: Sat Dec 30, 2017 4:07 pm
by tokumaru
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.

Re: How to use ASM6 conditions (IF)?

Posted: Sat Dec 30, 2017 4:17 pm
by MartsINY
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?

Re: How to use ASM6 conditions (IF)?

Posted: Sat Dec 30, 2017 4:38 pm
by tokumaru
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: Select all

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

Code: Select all

.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.

Re: How to use ASM6 conditions (IF)?

Posted: Sat Dec 30, 2017 4:41 pm
by MartsINY
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: Select all

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

Code: Select all

.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.

Re: How to use ASM6 conditions (IF)?

Posted: Sat Dec 30, 2017 4:58 pm
by tokumaru
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.

Re: How to use ASM6 conditions (IF)?

Posted: Sat Dec 30, 2017 6:13 pm
by tokumaru
You might want to check this thread out: viewtopic.php?f=2&t=9272

Re: How to use ASM6 conditions (IF)?

Posted: Sat Dec 30, 2017 6:52 pm
by MartsINY
thanks, I will check it!!