Page 1 of 4

General ASM6 Questions

Posted: Sun Mar 15, 2009 12:24 am
by frantik
If you try to define the same memory location (using .org, .pad, or .align) more than once, ASM6 doesn't like it

how do you write code for memory banks, where each bank expects to be at the same location?

the only way I can see now would be to build each bank separately and .incbin them, but perhaps there is a better way?

Posted: Sun Mar 15, 2009 7:15 am
by loopy
You can use .base to move the PC around. For example, this makes two adjacent 8KB banks destined for the same location:

Code: Select all

.align $2000
.base $c000

   .. code ..

.align $2000
.base $c000

   .. morecode ..

.align $2000

Posted: Sun Mar 15, 2009 7:46 am
by frantik
thanks I just noticed the base command in the readme after checking it again :)

Posted: Sun Mar 15, 2009 5:27 pm
by frantik
I'm trying to set up macros which can accept multiple parameters, but i'm getting unexpected actions

Code: Select all

macro test (testvar, testvar2)

	ifdef testvar
	nop
	endif
	ifdef testvar2
	nop
	endif

endm


test
test $00
test $00 $00
gives me:

Code: Select all

pass 1..
test.asm(14):test(2): Illegal instruction.
test.asm(15):test(2): Illegal instruction.
test.asm(15):test(5): Illegal instruction.
it seems like ifdef works if something isn't defined, but if the variable is defined, i get an illegal instruction. i'm guessing ASM6 doesn't like me using if def with macro variables, but is there a way to determine if a marco variable is used?

i also tried using "if testvar" but then i get an "unknown label" error when the label isn't defined

Posted: Sun Mar 15, 2009 6:08 pm
by loopy
I see the problem. The listing shows this:

Code: Select all

                                macro test (testvar, testvar2)

                                   ifdef testvar
                                   nop
                                   endif
                                   ifdef testvar2
                                   nop
                                   endif

                                endm


                                test

                                   ifdef testvar
                                   nop
                                   endif
                                   ifdef testvar2
                                   nop
                                   endif

                                test $00

                                   ifdef $00
*** Illegal instruction.
                                   nop
                                   endif
                                   ifdef testvar2
                                   nop
                                   endif

                                test $00 $00
                                   ifdef $00
*** Illegal instruction.
                                   nop
                                   endif
                                   ifdef $00
*** Illegal instruction.
                                   nop
                                   endif
testvars are replaced by $00 before they get to ifdef. I'll try to come up with a fix...
"Illegal instruction" isn't really an appropriate message for this either. Hrm.

Posted: Sun Mar 15, 2009 6:29 pm
by frantik
if you made it so IFDEF returned true (and IFNDEF false) whenever it was passed a constant value, then it would work as expected inside of the macro definition

i don't know if that would mess up other stuff or be too much of a "hack" though.


an alternative might be to make

Code: Select all

macro test (testvar)
   ifdef testvar 
      nop
   endif
endm

test TESTVALUE
replace itself with

Code: Select all

macrovar_test_testvar = TESTVALUE  
ifdef macrovar_test_testvar
  nop
endif
you could also add a large random string or something to macrovar_test_testvar to ensure it's never going to be used in an actual program. the macrovar_test_testvar definition would only occur if the test macro was called with a parameter. if no parameter is used, then the definition isn't made and ifdef works correctly



edit: oh also, i don't know if this is a bug or not, but single quotes don't seem work with .include which is unexpected

Posted: Mon Mar 16, 2009 3:56 pm
by frantik
is there a way to use expressions in macro calls?

Code: Select all

macro setPPUCTRL (value)
	lda v2000
	and value
	sta v2000
	sta PPUCTRL
endm

setPPUCTRL #PPUCTRL_NTABLE_0 | PPUCTRL_HORIZONTAL | PPUCTRL_SPR_PTABLE_1 | PPUCTRL_BG_PTABLE_0 | PPUCTRL_SPR_8X8 | PPUCTRL_VBLANK_NMI_ON
gives me

"extra characters on line"

putting quotes around it

Code: Select all

setPPUCTRL #(PPUCTRL_NTABLE_0 | PPUCTRL_HORIZONTAL | PPUCTRL_SPR_PTABLE_1 | PPUCTRL_BG_PTABLE_0 | PPUCTRL_SPR_8X8 | PPUCTRL_VBLANK_NMI_ON) 
gives me
"Incomplete expression." and "Extra characters on line"

Posted: Tue Mar 17, 2009 8:08 pm
by loopy
frantik wrote:I'm trying to set up macros which can accept multiple parameters, but i'm getting unexpected actions
frantik wrote:is there a way to use expressions in macro calls?
Both problems should be fixed now. Download it and give it a try.
I changed the macro syntax to be less ambiguous (no parentheses around arg list, and args must be comma separated).

Posted: Wed Mar 18, 2009 12:51 am
by frantik
yep, they're both working now :D thanks! Now i can write a 'callfunction' macro which can take multiple parameters

Posted: Wed Mar 18, 2009 5:48 pm
by tokumaru
Wow, so many changes to ASM6 lately... Well, it's good to know the program is evolving, as I like this assembler very much.

Posted: Wed Mar 18, 2009 11:02 pm
by baisoku
loopy wrote:Both problems should be fixed now. Download it and give it a try.
I changed the macro syntax to be less ambiguous (no parentheses around arg list, and args must be comma separated).
Loopy, any reason you haven't integrated the ASM6 changes for other architectures (e.g. Mac) that someone posted a couple weeks ago?
EDIT: ah, by beneficii, here.

Posted: Thu Mar 19, 2009 1:34 am
by loopy
Yes, his changes have been integrated with asm6 (mods to make asm6 portable to bigendian systems).

Posted: Thu Mar 19, 2009 2:41 am
by baisoku
loopy wrote:Yes, his changes have been integrated with asm6 (mods to make asm6 portable to bigendian systems).
Fantastic, then. ;)

Posted: Thu Mar 19, 2009 11:46 am
by blargg
tokumaru wrote:Wow, so many changes to ASM6 lately... Well, it's good to know the program is evolving
Are these changes backwards-compatible, or do they require changes to user code each time?

Posted: Thu Mar 19, 2009 3:09 pm
by frantik
blargg wrote:
tokumaru wrote:Wow, so many changes to ASM6 lately... Well, it's good to know the program is evolving
Are these changes backwards-compatible, or do they require changes to user code each time?
the changes to the macro code are not 100% backwards compatible because he make the syntax more strict. depending on your code you might have to update the macro calls