Jump to content
IGNORED

Mad-Assembler (MADS)


Gury

Recommended Posts

  • 4 months later...

Not sure if this is the right topic for questions about MADS, so if not please move it to wherever it fits..

 

My question is about if it's possible to iterate through those indexed arrays. Or the indexed structs.

I mean, it's really nice to have these structures and arrays, yet I somehow cannot find anything about how to iterate through these with MADS.

 

Maybe someone can give me a pointer (pun intended) on how to accomplish this.

  • Like 1
Link to comment
Share on other sites

  • 4 months later...

In an experiment with a nested .REPT I see unexpected behaviour.

 

    org $2000
    
    .rept 4, #    
;    .byte :1
    .rept 4, :1, #
    .byte :1, :2
    .endr
    .endr

 

With the line commented out the output is:

 

 mads 2.1.5 build 3 (21 Feb 22)
Source: test.asm
     1                     org $2000
     2                     
     3                     .rept 4, #    
     6                     .BYTE :1, :2
     8                     .endr
Source: REPT
     8                     .endr
Source: REPT
     6 FFFF> 2000-201F> 00 00        .BYTE 0, 0
     6 2002 00 01            .BYTE 0, 1
     6 2004 00 02            .BYTE 0, 2
     6 2006 00 03            .BYTE 0, 3
Source: test.asm
     6                     .endr
Source: REPT
     6 2008 00 00            .BYTE 0, 0
     6 200A 00 01            .BYTE 0, 1
     6 200C 00 02            .BYTE 0, 2
     6 200E 00 03            .BYTE 0, 3
Source: test.asm
     6                     .endr
Source: REPT
     6 2010 00 00            .BYTE 0, 0
     6 2012 00 01            .BYTE 0, 1
     6 2014 00 02            .BYTE 0, 2
     6 2016 00 03            .BYTE 0, 3
Source: test.asm
     6                     .endr
Source: REPT
     6 2018 00 00            .BYTE 0, 0
     6 201A 00 01            .BYTE 0, 1
     6 201C 00 02            .BYTE 0, 2
     6 201E 00 03            .BYTE 0, 3
Source: test.asm
Source: test.asm

 

But with the line included it becomes:

 

mads 2.1.5 build 3 (21 Feb 22)
Source: test.asm
     1                     org $2000
     2                     
     3                     .rept 4, #    
     4                     .BYTE :1
     6                     .BYTE :1, :2
     8                     .endr
Source: REPT
     4 FFFF> 2000-2023> 00        .BYTE 0
     4                     .endr
Source: REPT
     6 2001 00 00            .BYTE 0, 0
     6 2003 00 01            .BYTE 0, 1
     6 2005 00 02            .BYTE 0, 2
     6 2007 00 03            .BYTE 0, 3
Source: test.asm
     4 2009 01                .BYTE 1
     4                     .endr
Source: REPT
     6 200A 01 00            .BYTE 1, 0
     6 200C 01 01            .BYTE 1, 1
     6 200E 01 02            .BYTE 1, 2
     6 2010 01 03            .BYTE 1, 3
Source: test.asm
     4 2012 02                .BYTE 2
     4                     .endr
Source: REPT
     6 2013 02 00            .BYTE 2, 0
     6 2015 02 01            .BYTE 2, 1
     6 2017 02 02            .BYTE 2, 2
     6 2019 02 03            .BYTE 2, 3
Source: test.asm
     4 201B 03                .BYTE 3
     4                     .endr
Source: REPT
     6 201C 03 00            .BYTE 3, 0
     6 201E 03 01            .BYTE 3, 1
     6 2020 03 02            .BYTE 3, 2
     6 2022 03 03            .BYTE 3, 3
Source: test.asm
Source: test.asm

 

Is this a bug? I can use this as an alternative way to reference the outer variable for it to be passed correctly to the inner but not produce code:
 

    org $2000
    
    .rept 4, #    
@myvar:1 equ :1
    .rept 4, @myvar:1, #
    .byte :1, :2
    .endr
    .endr

 

Producing:

 

mads 2.1.5 build 3 (21 Feb 22)
Source: test.asm
     1                     org $2000
     2                     
     3                     .rept 4, #    
     4                 @MYVAR:1 EQU :1
     6                     .BYTE :1, :2
     8                     .endr
Source: REPT
     4 = 0000            @MYVAR0 EQU 0
     4                     .endr
Source: REPT
     6 FFFF> 2000-201F> 00 00        .BYTE 0, 0
     6 2002 00 01            .BYTE 0, 1
     6 2004 00 02            .BYTE 0, 2
     6 2006 00 03            .BYTE 0, 3
Source: test.asm
     4 = 0001            @MYVAR1 EQU 1
     4                     .endr
Source: REPT
     6 2008 01 00            .BYTE 1, 0
     6 200A 01 01            .BYTE 1, 1
     6 200C 01 02            .BYTE 1, 2
     6 200E 01 03            .BYTE 1, 3
Source: test.asm
     4 = 0002            @MYVAR2 EQU 2
     4                     .endr
Source: REPT
     6 2010 02 00            .BYTE 2, 0
     6 2012 02 01            .BYTE 2, 1
     6 2014 02 02            .BYTE 2, 2
     6 2016 02 03            .BYTE 2, 3
Source: test.asm
     4 = 0003            @MYVAR3 EQU 3
     4                     .endr
Source: REPT
     6 2018 03 00            .BYTE 3, 0
     6 201A 03 01            .BYTE 3, 1
     6 201C 03 02            .BYTE 3, 2
     6 201E 03 03            .BYTE 3, 3
Source: test.asm
Source: test.asm

 

Link to comment
Share on other sites

@Wrathchild these nested loops are not behaving good, I had an issue and got elegant solution directly in this very thread:

 

it is using the temporary labels (those with questionmarks)... it is well readable and what is important is that it is forward compatible (not relying on nested loop behavior of particular mads release)

 

  • Like 1
Link to comment
Share on other sites

  • 3 months later...
  • 1 month later...

Anybody know how to build a macro that will repeat over a variable number of args?

 

I'd like to call it thusly:

      SetTabs %00001000

or

      SetTabs %00001000 %00100001 %00000010

 

Something like:

.macro SetTabs

.rept :0
?i=#+1
        lda #:?i
        sta TABMAP+#
.endr

.endm

 

That fails because it's looking for the global label ?i on the LDA and not finding it.

 

I've also tried it with %%?i and it assembles but results in the raw index value. The %% seems to be ignored.

 

I'll probably just use a bunch of ".if :0 > x" lines to check each arg index for now.

Link to comment
Share on other sites

Thanks @tebe

 

I'll just have to make a long .put line. And put a :0 check to catch when there's too many args.

 

You should add a description of that .put usage in the docs.

 

I also see .wget (etc) got added. Any chance of matching .wput (etc) for this kind of usage?

 

Link to comment
Share on other sites

  • 1 month later...
ins "filename.dat"*

it does not invert the bytes, it only inverts the highest bit (like when used with strings in dta d'xx'*)  - is that intentional or bug? Documentation says it inverts bytes.

Edited by matosimi
Link to comment
Share on other sites

50 minutes ago, matosimi said:
ins "filename.dat"*

it does not invert the bytes, it only inverts the highest bit (like when used with strings in dta d'xx'*)  - is that intentional or bug? Documentation says it inverts bytes.

'*' invert bit 7

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...