XA: macros with parameters

Questions, bug reports, features requests, ... about the Oric Software Development Kit. Please indicate clearly in the title the related element (OSDK for generic questions, PictConv, FilePack, XA, Euphoric, etc...) to make it easy to locate messages.

User avatar
Chema
Game master
Posts: 3020
Joined: Tue Jan 17, 2006 10:55 am
Location: Gijón, SPAIN
Contact:

XA: macros with parameters

Post by Chema »

I thought it would be a good idea to share it here:

Defining macros with parameters XA can be quite tricky. Let me share with you how I solved it.

Particularly I am trying to define a macro for multiplying the contets of regs A and Y and store the 16-bit result in a temporary variable (low) and reg A (high). Something like:

Code: Select all

#define MULTAY(par)  sta MultLo1  :\
                sta MultHi1 :\
                eor #$ff :\
                clc :\
                adc #1 :\
                sta MultLo2  :\
                sta MultHi2  :\
                sec :\
                lda (MultLo1),y :\
                sbc (MultLo2),y :\
                sta par :\
                lda (MultHi1),y :\
                sbc (MultHi2),y 
Ok. When I try to use the macro I allways get a linker error "Unresolved external : par".

This happens even if I do not use the macro... just keep it defined. I have tried everyting I imagined (surely everything *but* the correct option), but still had the problem.

In fact something like #define mult(o1,o2) (o1*o2) does work (at least defining it does not give any error) so I supposed that it was related to the multiple line thing and the fact that the parameter is used inside asm code...

Well. To solve this issue, it is enough to keep the definition in one line, such as:

Code: Select all

#define MULTAY(par)  sta MultLo1 : sta MultHi1 : ... : sta par: ...
This might be cumbersome with long macros, but at least it works.

So we can have quick asm inlined code in an easy way at last!

Cheers.
User avatar
waskol
Flight Lieutenant
Posts: 415
Joined: Wed Jun 13, 2007 8:20 pm
Location: FRANCE, Paris

Post by waskol »

that is very interesting (On the moment I though about the routine for the PASE Joysticks I was dealing with a while ago)
Post Reply