General ASM6 Questions

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

frantik
Posts: 370
Joined: Tue Mar 03, 2009 3:56 pm

Post by frantik »

I dunno if this is even doable, but it would be awesome if macros could accept a block of code as a "virtual macro".. maybe something like this:

Code: Select all

macro repeat times, {code}
   stx times
 - txa
   pha
  {code}
   pla
   tax
   dex
   bne -
endm

repeat 10
{
  ... code, 'n stuff ...
}
then it'd be super easy to create different kinds of control structures.

ideally multiple virtual macros could be passed. i'm just using the braces as an idea for syntax but they could be dropped in the macros definition probably. for the macro call, perhaps make a comma or newline before { acceptable?

Code: Select all

macro FOR {init}, {test}, {incr}, {loopcode}
...
endm

FOR { ... } , { ... }, { ... }
{ ... }
User avatar
loopy
Posts: 403
Joined: Sun Sep 19, 2004 10:52 pm
Location: UT

Post by loopy »

This might be macro abuse, but you can get what you want by sticking code blocks in other macros.

Code: Select all

macro stuff
   nop
   nop
   nop
endm

macro repeat times, code
   stx times
-  txa
   pha
   code
   pla
   tax
   dex
   bne -
endm

repeat 5, stuff
frantik
Posts: 370
Joined: Tue Mar 03, 2009 3:56 pm

Post by frantik »

well it's good to know you can pass a macro with a symbol .. that's about 1/2 of what I'm envisioning, and i can see it being useful :)

though it's still a bit cumbersome having to define and name the macro every time before the code which uses it. it would still be a cool feature if you could define a temporary macro without a name, but i don't know if that is something totally non-standard with assemblers or what
User avatar
blargg
Posts: 3717
Joined: Mon Sep 27, 2004 8:33 am
Location: Central Texas, USA
Contact:

Post by blargg »

Code: Select all

macro repeat n
   lda #n 
-  pha 
endm

macro repeat_end
   pla 
   sec
   sbc #1 
   bne - 
endm
frantik
Posts: 370
Joined: Tue Mar 03, 2009 3:56 pm

Post by frantik »

cool i will try that out.. i thought relative labels couldn't be used across macros but I dunno why i thought that.

one disadvantage to that method is that the ending macro doesn't have access to the starting macro's variables
User avatar
blargg
Posts: 3717
Joined: Mon Sep 27, 2004 8:33 am
Location: Central Texas, USA
Contact:

Post by blargg »

ca65 allows one to pass arbitrary things to macros using { }. For example,

Code: Select all

.macro foo arg
    ...
    arg
    ...
.endm

foo {bar: .byte $12}

; expands to
...
bar: .byte $12
...
I doubt ca65 allows it, but asm6 could use an extended syntax that allows newlines in the { } string (and after a comma), allowing the original desired behavior, as long as a comma is inserted:

Code: Select all

.macro repeat_n_times iter, body
    lda #iter
    ...
    body
    ...
.endm

repeat_n_times 10,
{
    tax
    sta table,x
}
This might pose some issues if the macro syntax allows empty arguments, where a comma at the end of a line would already mean simply that the last argument was empty. A workaround would be to write repeat_n_times 10,{ all on the same line, though forcing the K&R brace style would be kind of annoying. :)
frantik
Posts: 370
Joined: Tue Mar 03, 2009 3:56 pm

Post by frantik »

using the new macro variable ifdef/ifndef functionality for iNes header macro

Code: Select all

macro iNES_header prg, chr, mapper1, mapper2
	
	ifndef prg
		prg = #$01
	endif
	ifndef chr
		chr = #$01
	endif		
	ifndef mapper1
		mapper1 = #$00
	endif
	ifndef mapper2
		mapper2 = #$00
	endif

	byte "NES",$1a
	byte prg ; PRG-ROM block
	byte chr ; CHR-ROM block
	byte mapper1 ; mapper info 
	byte mapper2 ; mapper info
	byte 0,0,0,0,0,0,0,0  ; pad header to 16 bytes
endm

; all of these are valid

iNES_header
iNES_header 01
iNES_header 01, 01, 10
; etc

:)
frantik
Posts: 370
Joined: Tue Mar 03, 2009 3:56 pm

Post by frantik »

ooo another bug/unexpected problem i ran into while trying to set up a vector macro

Code: Select all

macro test testvar
	byte testvar 
endm

;works fine
test othervar   

; gives "Recursive EQU not allowed."
test testvar 
perhaps a workaround would be to add a random string to the macro variable names during one of the assembler passes? in the meantime it seems like it would be good coding practice to adopt some kind of macro variable naming scheme.. like @testvar or something similar..


edit: interestingly, this bug made me think of a way to pass code to variables, and code with spaces are possible with the new stricter syntax. it seems like it might not be that hard to extend the macro syntax to accept and pass line breaks as well

Code: Select all

macro test macroabuse
	macroabuse
endm

; both work
test word #$ffff
test nop
frantik
Posts: 370
Joined: Tue Mar 03, 2009 3:56 pm

Post by frantik »

hey anybody know what compiler is used to compile ASM6?
User avatar
beneficii
Posts: 127
Joined: Tue Jul 12, 2005 4:37 pm

Post by beneficii »

frantik wrote:hey anybody know what compiler is used to compile ASM6?
A C Compiler. The only I've seen it tested on is the GNU C Compiler, but ASM6 is meant to be cross-compatible.
frantik
Posts: 370
Joined: Tue Mar 03, 2009 3:56 pm

Post by frantik »

i meant the specific one being used by Loopy.. so i don't have to worry about making some little changes which always seem to be required when moving from compiler to compiler :)

I'm going to try gcc from MiniGW.. hopefully it will work.
User avatar
loopy
Posts: 403
Joined: Sun Sep 19, 2004 10:52 pm
Location: UT

Post by loopy »

The asm6.exe I provide is compiled with MSVC6.
frantik
Posts: 370
Joined: Tue Mar 03, 2009 3:56 pm

Post by frantik »

thanks :)
User avatar
beneficii
Posts: 127
Joined: Tue Jul 12, 2005 4:37 pm

Post by beneficii »

frantik wrote:i meant the specific one being used by Loopy.. so i don't have to worry about making some little changes which always seem to be required when moving from compiler to compiler :)

I'm going to try gcc from MiniGW.. hopefully it will work.
Does it matter?
frantik
Posts: 370
Joined: Tue Mar 03, 2009 3:56 pm

Post by frantik »

i just wanted to know which compiler to look into to have the easiest time compiling the source as is :)
Post Reply