Jump to content

Open Club  ·  61 members

DASM
IGNORED

Using MAC for multiple table generation (e.g., LO/HI)


Andrew Davie

Recommended Posts

I posted this elsewhere before remembering we have a group for this.

I recently "discovered" a neat way to use macros to define tables of related items.

For example, a LO/HI table can be defined like this...

    MAC POSTAB
    .byte {1}PositionalValue_PAWN
    .byte {1}PositionalValue_PAWN
    .byte {1}PositionalValue_KNIGHT
    .byte {1}PositionalValue_BISHOP
    .byte {1}PositionalValue_ROOK
    .byte {1}PositionalValue_QUEEN
    .byte {1}PositionalValue_KING_MIDGAME
    ENDM


PosValVecLO POSTAB <
PosValVecHI POSTAB >

 

 

You can pass the name of a macro to a macro, and the macro you pass will be evaluated (eventually).

This means you can do stuff like this...

 

    MAC LO
    .byte <{1}
    ENDM
               
    MAC HI
    .byte >{1}
    ENDM
      
    MAC SP
    .byte {2}
    ENDM

    MAC TAB
    {1} Func1, 10
    {1} Func2, 20
    {1} Func3, 2
    ENDM

LoTable TAB LO
HiTable TAB HI
SpeedTable TAB SP

 

A walkthrough:

LoTable defines a label.
It calls the macro TAB, passing it the parameter "LO"

The macro replaces all the {1} on each line with "LO", which the become calls to the macro "LO" with two parameters

The LO macro puts the low byte of the 1st parameter.

For all lines in the TAB macro.

So, the last three lines define three separate tables, one for low bytes, one for high bytes, and one for "speed" just to show as an example.

Perhaps we could document these "tricks" somehow in a DASM tips'n'tricks or addendum to the manual?

Personally I think this one is pretty useful, as it prevents you getting the values in the different tables out of order - you only need to define the "contents" once inside the TAB macro, instead of three times, in three tables.

 

  • Like 3
Link to comment
Share on other sites

  • Recently Browsing   0 members

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