Skip to content

Macro: parameter types and variadic arguments #150

@NYYR1KK1

Description

@NYYR1KK1

Hi,

First of all I must say SjASMPlus is currently my favorite assembler. It can compile a lot of existing sources and it has even some quite unique features I enjoy... How ever it does not mean that I don't still keep dreaming about new stuff. :)

I've been wondering that it would be really nice, if the macros could have free amount of parameters (I believe this has been requested already) and they could behave differently based on parameter types given...

I did put most of my dreams to this one over complicated pseudo code macro... I know it is a bit tall order, but maybe something to think about:

      MACRO PRINT 1..2 ; (parameter format loaned from Sjasm)

        IF TYPE(@1)==FLAG
          JP NOT(@1),.SKIP
          ROTATE 1 ; from Sjasm (@1=@2)
        ENDIF

        IF TYPE(@1)==STRING
          IF LEN(@1)==1
            LD A,@1
            CALL CHRPUT
          ELSE
            CALL PRINT_PC
            DB @1, 0
          ENDIF
        ENDIF

        IF TYPE(@1)==REGISTER
          IF @1 <> A
            LD A,@1
          ENDIF
          CALL CHRPUT
        ENDIF

        IF TYPE(@1)==REGISTERPAIR
          IF @1 == IX | @1 == IY
            PUSH @1
            POP HL
          ELSE
            IF @1 <> HL
              LD L,@1.LOW
              LD H,@1.HIGH
            ENDIF
          ENDIF
          CALL PRINT_HL
        ENDIF

        IF TYPE(@1)==REGISTERPAIRPOINTER ; () automatically removed
          IF @1 == HL
            LD A,(HL)
            INC HL
            LD H,(HL)
            LD L,A
            CALL PRINT_HL
          ELSE
            LD A,(@1)
            LD L,A
            INC @1
            LD A,(@1)
            LD H,A
            DEC @1
            CALL PRINT_HL
          ENDIF
        ENDIF

        IF TYPE(@1)==POINTER ; () automatically removed
          LD HL,(@1)
          CALL PRINT_HL
        ENDIF

        IF TYPE(@1)==NUMBER
          IF @1 > 255
            LD HL,@1
            CALL PRINT_HL
          ELSE
            IF @1 <> 0
              LD A,@1
            ELSE
              XOR A
            ENDIF
            CALL CHRPUT
          ENDIF
        ENDIF

 .SKIP:
      ENDM

PRINT_PC:
        POP HL
        LD A,(HL)
        INC HL
        PUSH HL
        AND A
        RET Z
        CALL CHRPUT
        JP PRINT_PC

PRINT_HL:
        LD A,(HL)
        INC HL
        AND A
        RET Z
        CALL CHRPUT
        JP PRINT_HL 

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions