It is currently Wed Dec 12, 2018 9:28 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 14 posts ] 
Author Message
PostPosted: Sat Dec 30, 2017 2:38 pm 
Offline
User avatar

Joined: Sun Jun 11, 2017 5:39 pm
Posts: 60
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


Top
 Profile  
 
PostPosted: Sat Dec 30, 2017 2:55 pm 
Offline
User avatar

Joined: Thu Aug 13, 2015 4:40 pm
Posts: 325
Location: Rio de Janeiro - Brazil
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.

_________________
https://twitter.com/bitinkstudios <- Follow me on twitter! Thanks!


Top
 Profile  
 
PostPosted: Sat Dec 30, 2017 3:16 pm 
Offline
User avatar

Joined: Sun Jun 11, 2017 5:39 pm
Posts: 60
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.


Top
 Profile  
 
PostPosted: Sat Dec 30, 2017 3:24 pm 
Offline
User avatar

Joined: Thu Aug 13, 2015 4:40 pm
Posts: 325
Location: Rio de Janeiro - Brazil
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.

_________________
https://twitter.com/bitinkstudios <- Follow me on twitter! Thanks!


Top
 Profile  
 
PostPosted: Sat Dec 30, 2017 3:38 pm 
Offline
User avatar

Joined: Sun Jun 11, 2017 5:39 pm
Posts: 60
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...


Top
 Profile  
 
PostPosted: Sat Dec 30, 2017 3:58 pm 
Offline
User avatar

Joined: Thu Aug 13, 2015 4:40 pm
Posts: 325
Location: Rio de Janeiro - Brazil
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.

_________________
https://twitter.com/bitinkstudios <- Follow me on twitter! Thanks!


Top
 Profile  
 
PostPosted: Sat Dec 30, 2017 4:02 pm 
Offline
User avatar

Joined: Sun Jun 11, 2017 5:39 pm
Posts: 60
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


Top
 Profile  
 
PostPosted: Sat Dec 30, 2017 4:07 pm 
Online
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 11011
Location: Rio de Janeiro - Brazil
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.


Top
 Profile  
 
PostPosted: Sat Dec 30, 2017 4:17 pm 
Offline
User avatar

Joined: Sun Jun 11, 2017 5:39 pm
Posts: 60
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?


Top
 Profile  
 
PostPosted: Sat Dec 30, 2017 4:38 pm 
Online
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 11011
Location: Rio de Janeiro - Brazil
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.


Top
 Profile  
 
PostPosted: Sat Dec 30, 2017 4:41 pm 
Offline
User avatar

Joined: Sun Jun 11, 2017 5:39 pm
Posts: 60
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.


Top
 Profile  
 
PostPosted: Sat Dec 30, 2017 4:58 pm 
Online
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 11011
Location: Rio de Janeiro - Brazil
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.


Top
 Profile  
 
PostPosted: Sat Dec 30, 2017 6:13 pm 
Online
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 11011
Location: Rio de Janeiro - Brazil
You might want to check this thread out: viewtopic.php?f=2&t=9272


Top
 Profile  
 
PostPosted: Sat Dec 30, 2017 6:52 pm 
Offline
User avatar

Joined: Sun Jun 11, 2017 5:39 pm
Posts: 60
thanks, I will check it!!


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

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 3 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