News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_Rabs

Passing strings into a RASM macro

Started by Rabs, 22:02, 30 June 23

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Rabs

Hi, bit of help please before I spend too much more time on this.

I am using RASM and would like to pass strings into a macro to make the code more readable, something like;

Def_WR4 'NOPARITY'

Then test the strings in the macro and convert to a number, something like;

macro Def_WR4 PARITY

    parity_value=0

    if {PARITY}=='NOPARITY'
        parity_value=0
    elseif {PARITY}=='EVEN'
        parity_value=1
    elseif {PARITY}=='ODD'
        parity_value=3
    else
        print 'ERROR Bad Parity Definition'
    endif

But even though {PARITY} is being passed through correctly the test keeps dropping down to the else statement and an error.

I guess I am doing something daft and the "==" expression can only be used on numbers (maybe)?

Any ideas?

roudoudou

yep, rasm is not supposed to compare strings but hey...

you may use variables or aliases for this

PARITY_NONE equ 0
PARITY_EVEN equ 1
PARITY_ODD equ 2

you call your macro like this: Def_WR4 PARITY_EVEN

then in your macro you may use switch (nicer and more readable than elseif list...)

switch {parity}
case parity_none : blablabla : break
case parity_even : blablabla : break
case parity_odd : blablabla : break
default : blablabla : break
endswitch
My pronouns are RASM and ACE

Rabs

Quote from: roudoudou on 10:28, 01 July 23yep, rasm is not supposed to compare strings but hey...

you may use variables or aliases for this

PARITY_NONE equ 0
PARITY_EVEN equ 1
PARITY_ODD equ 2

you call your macro like this: Def_WR4 PARITY_EVEN

then in your macro you may use switch (nicer and more readable than elseif list...)

switch {parity}
case parity_none : blablabla : break
case parity_even : blablabla : break
case parity_odd : blablabla : break
default : blablabla : break
endswitch

Excellent thanks, guessed as much on the string compare and changed to variables but the switch is a nice idea.

Really like RASM  thanks for the work.

Rabs

Thanks, that is much neater;

; Parity Definitions in WR4
DRT_WR4_NO_PARITY=0
DRT_WR4_EVEN_PARITY=1
DRT_WR4_ODD_PARITY=3

; Stop Bit Definitions in WR4
DRT_WR4_1_STOP_BIT=0
DRT_WR4_1_PLUS_HALF_STOP_BITS=2
DRT_WR4_2_STOP_BITS=3

; Clock Mode Definitions in WR4
DRT_WR4_X1=0
DRT_WR4_X16=1
DRT_WR4_X32=2
DRT_WR4_X64=3

; DRT_Def_WR4
;
; Description: Defines Write Register 4
;
; IN:
;  PARITY 
;  STOP  
;  CLOCK    
;   
macro DRT_Def_WR4 PARITY,STOP,CLOCK_MODE

    DRT_WR4 = ({CLOCK_MODE}<<6)+({STOP}<<2)+{PARITY}

    print "DRT INF WR4",{hex2}DRT_WR4

    switch {PARITY}
        case DRT_WR4_NO_PARITY     : print "DRT INF WR4 NO PARITY"     : break
        case DRT_WR4_EVEN_PARITY   : print "DRT INF WR4 EVEN PARITY"   : break
        case DRT_WR4_ODD_PARITY    : print "DRT INF WR4 ODD PARITY"    : break
        default                    : print "DRT ERR WR4 Bad Parity Definition"
    endswitch

    switch {STOP}
        case DRT_WR4_1_STOP_BIT             : print "DRT INF WR4 1 STOP BIT"        : break
        case DRT_WR4_1_PLUS_HALF_STOP_BITS  : print "DRT INF WR4 1 1/2 STOP BITS"   : break
        case DRT_WR4_2_STOP_BITS            : print "DRT INF WR4 2 STOP BITS"       : break
        default                             : print "DRT ERR WR4 Bad Stop Bit Definition"
    endswitch
   
    switch {CLOCK_MODE}
        case DRT_WR4_X1     : print "DRT INF WR4 CLOCK MODE X1"     : break
        case DRT_WR4_X16    : print "DRT INF WR4 CLOCK MODE X16"    : break
        case DRT_WR4_X32    : print "DRT INF WR4 CLOCK MODE X32"    : break
        case DRT_WR4_X64    : print "DRT INF WR4 CLOCK MODE X64"    : break
        default             : print "DRT ERR WR4 Bad Clock Mode Definiton"
    endswitch

mend

Powered by SMFPacks Menu Editor Mod