Page 1 of 1

How to use MACROS with OSDK

Posted: Sat May 23, 2020 4:38 pm
by coco.oric
Hello,

I've started a portage (only asm) which needed some macros.
I don't find any sample using macros.h or something like that on the forum or the directories.

I didn't succeeded in the build.
I've put "include macros.h in the define part of my .s
I've errors like "unresolved external" for the macros using parameters.

I forgot to do something or macros are not fine with parameters ?
Thanks. Didier

Re: How to use MACROS with OSDK

Posted: Sat May 23, 2020 4:56 pm
by Chema
I am not sure I understand, Didier. Are you trying to use the macros included with the C compiler? Are you trying to define your own macros (they work the same as in the C preprocessor, using #defines)?

Re: How to use MACROS with OSDK

Posted: Sat May 23, 2020 5:04 pm
by coco.oric
Start trying with a sample .s

Code: Select all

;// --------------------------------------
;// 256b moving backgound (Working title)
;// --------------------------------------
;// (c) 2006 Mickael Pointier
...
#include "ORIC\macros.h"

	.zero
	*= $50
and macros.h coming from osdk (but i've to implement my macros. as i've never used macros, i wanted to try with some definitions already done)

Code: Select all

/* macros v1.33 for the 6502 code generator, F.Frances */
...
#define LEAVEW_C(cte1)\
 ldx #LOW(cte1) :\
 lda #HIGH(cte1) :\
 jmp leave :\
build is generating the unresolved external cte1 ...
I didn't find any osdk macro sample. If i didn't succeed, i'll try with ca65

Re: How to use MACROS with OSDK

Posted: Sat May 23, 2020 5:08 pm
by ibisum
Macro's are processed by a c-pre-processor, which can do the substitutions necessary, but its not clear that the assembler is being made aware of the existence of a c-pre-processor in your example build - or if, indeed, the filename needs to be .c / .h in order to 'trigger' pre-processing.

Re: How to use MACROS with OSDK

Posted: Sat May 23, 2020 5:19 pm
by iss
@coco.oric: The short answer is: don't #include 'macro.h' coming with OSDK. It's used internally by the C compiler.
To experiment simply use #define in your assembler code. And a humble advice: use simple macro definitions because lot of side effects are possible which are very hard to debug. ;)

Re: How to use MACROS with OSDK

Posted: Sat May 23, 2020 5:49 pm
by coco.oric
I tried ... just inserted in the start of the s file (with the others define) with 3 cases :

Code: Select all

;--------------------------------------------
#define LOW <
#define HIGH >
#define STRING .asc :?: 
#define DB(n) .byt n 
#define DW(n) .word n 
#define SPACE(n) .dsb n 
#define ZERO(n) .dsb n
;--------------------------------------------
This include part is working :D

if i add

Code: Select all

#define LEAVER\
 jmp leaver :\
 
I've an error at linking phase "unresolved external leaver" :?:

and if i add

Code: Select all

#define CWB_YD(ptr1,y1,tmp2)\
 ldy #y1 :\
 lda ptr1,y :\
 sta tmp2 :\
I've an error at linking phase "unresolved external ptr1 and tmp2"

Re: How to use MACROS with OSDK

Posted: Sat May 23, 2020 6:22 pm
by Chema
You cannot use macros.h as is... There are many definitions missing.

If you just want an example of a macro with parameters here is one, from the sources of 1337 (multiplication routine http://miniserve.defence-force.org/svn/ ... 3d/lib3d.s)

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 
Of course MultLo1, etc are tables, but you can see how the macro multiplies registers A and Y and store the results in the parameter passed as par (high byte of result) and register A (low part of result).

So, it is the same as what you would use in a C program (using the pre-processor), something as:

Code: Select all

#define MAX(a,b) ( ((a)>(b)) : (a) ? (b) )
With one caveat: apparently the code you write has to be written in a single line as in the example. Maybe it is a limitation of the XA pre-processor... not sure: http://osdk.defence-force.org/index.php ... =assembler

Re: How to use MACROS with OSDK

Posted: Sat May 23, 2020 6:52 pm
by Dbug
As the other said, "osdk\macro\macro.h" is not supposed to be used by anyone other that the C compiler itself.

I guess to avoid problems I could probably rename it to something that makes people not feel like using it, like "osdk_internal_compiler_stuff_do_not_user.dont_touch" :)

"ptr1" and "tmp2" are parts of the stuff defined when you use the OSDK libraries... and since your first message contained "256b moving backgound (Working title)" I believe you had the idea to start from my 256 bytes intro example which defines "SET OSDKLINK=-B" to EXPLICITELY DO NOT DEFINED any of this stuff so it could fit in 256 bytes.

What -B does is to disable the automatic inclusion of header/footer which is why you are missing these.

So your problem is not to use macros with OSDK, but the fact you started from a ultra specific examples designed purely for size :)

Now, regarding macros, I had an article about that:
http://osdk.defence-force.org/index.php ... s&ref=ART7

Re: How to use MACROS with OSDK

Posted: Sun May 24, 2020 8:48 pm
by mikeb
Dbug wrote: Sat May 23, 2020 6:52 pm I guess to avoid problems I could probably rename it to something that makes people not feel like using it, like "osdk_internal_compiler_stuff_do_not_user.dont_touch" :)
Maybe :-

"osdk_internal_compiler_stuff_do_not_user.dont_touc.h"

It's a nice idea, but someone will just go "OK, I make a copy!" and create their own version.h

I came across a rather rude side-step for some C++ once.

#define private public
#include <ThingThatDidntWork.H>

"Because we kept getting errors about non being able to access private member variables? Now it works!"

Do not do this :(

Re: How to use MACROS with OSDK

Posted: Thu May 28, 2020 6:23 am
by coco.oric
Thanks for all your help, i'll try with ca65 which seems to have some macros with parameters allowed

Re: How to use MACROS with OSDK

Posted: Thu May 28, 2020 7:19 am
by Dbug
coco.oric wrote: Thu May 28, 2020 6:23 am Thanks for all your help, i'll try with ca65 which seems to have some macros with parameters allowed
I really don't understand what your problem was: Both the OSDK C Compiler and Assembler support macros with or without parameters, so your issue is not with macros, it has to be something in your setup/project configuration.

Could you attach the complete OSDK project you tried to get working so I can see what's wrong?

I'm fine with people moving to CC65 because of some inherent feature not supported by the OSDK, but having people trying to do something on the OSDK that is supposed to work, fail, and then move to something else... that's frustrating.

Re: How to use MACROS with OSDK

Posted: Thu May 28, 2020 4:38 pm
by coco.oric
Thanks dbug.
but please answer in french, sometimes, i'm not sure to have read and understand clearly some foreign language ... ;)
i saw that taking this sample project, configuration isn't the same than the one i take for mines. I'll try another one before sending you the test files.

Re: How to use MACROS with OSDK

Posted: Thu May 28, 2020 8:37 pm
by Dbug
coco.oric wrote: Thu May 28, 2020 4:38 pm Thanks dbug.
but please answer in french, sometimes, i'm not sure to have read and understand clearly some foreign language ... ;)
i saw that taking this sample project, configuration isn't the same than the one i take for mines. I'll try another one before sending you the test files.
Si tu peux m'envoyer un zip complet avec les sources, fichiers de config, etc... que je puisse reproduire l'erreur et soit fixer si c'est un bug, soit t'indiquer comment faire :)

Re: How to use MACROS with OSDK

Posted: Sat May 30, 2020 12:25 pm
by jbperin
coco.oric wrote: Thu May 28, 2020 6:23 am Thanks for all your help, i'll try with ca65 which seems to have some macros with parameters allowed
Personnellement, j'ai utilisé les deux .. xa65 (dans OSDK) et ca65 et je peux témoigner que les macros dans xa65 me semblent beaucoup plus pratiques que celles dans ca65. Essentiellement parcequ'elles peuvent être partagées entre le code C et le code assembleur. C'est tellement pratique !!
Et aussi parceque le préprocesseur C qui est utilisé est un standard.

Mais je suis encore plus débutant en ca65 qu'en xa65 .. donc mon commentaire ne vaut que ce qu'il vaut ..