How to use MACROS with OSDK

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.

Post Reply
User avatar
coco.oric
Squad Leader
Posts: 548
Joined: Tue Aug 11, 2009 9:50 am
Location: North of France
Contact:

How to use MACROS with OSDK

Post 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
coco.oric as DidierV, CEO Member
Historic owner of Oric, Apple II, Atari ST, Amiga

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

Re: How to use MACROS with OSDK

Post 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)?

User avatar
coco.oric
Squad Leader
Posts: 548
Joined: Tue Aug 11, 2009 9:50 am
Location: North of France
Contact:

Re: How to use MACROS with OSDK

Post 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
coco.oric as DidierV, CEO Member
Historic owner of Oric, Apple II, Atari ST, Amiga

User avatar
ibisum
Wing Commander
Posts: 1278
Joined: Fri Apr 03, 2009 8:56 am
Location: Vienna, Austria
Contact:

Re: How to use MACROS with OSDK

Post 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.

User avatar
iss
Wing Commander
Posts: 1059
Joined: Sat Apr 03, 2010 5:43 pm
Location: Bulgaria
Contact:

Re: How to use MACROS with OSDK

Post 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. ;)

User avatar
coco.oric
Squad Leader
Posts: 548
Joined: Tue Aug 11, 2009 9:50 am
Location: North of France
Contact:

Re: How to use MACROS with OSDK

Post 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"
coco.oric as DidierV, CEO Member
Historic owner of Oric, Apple II, Atari ST, Amiga

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

Re: How to use MACROS with OSDK

Post 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

User avatar
Dbug
Site Admin
Posts: 3332
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: How to use MACROS with OSDK

Post 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

User avatar
mikeb
Flying Officer
Posts: 217
Joined: Wed Sep 05, 2018 8:03 pm
Location: West Midlands, UK
Contact:

Re: How to use MACROS with OSDK

Post 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 :(

User avatar
coco.oric
Squad Leader
Posts: 548
Joined: Tue Aug 11, 2009 9:50 am
Location: North of France
Contact:

Re: How to use MACROS with OSDK

Post by coco.oric »

Thanks for all your help, i'll try with ca65 which seems to have some macros with parameters allowed
coco.oric as DidierV, CEO Member
Historic owner of Oric, Apple II, Atari ST, Amiga

User avatar
Dbug
Site Admin
Posts: 3332
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: How to use MACROS with OSDK

Post 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.

User avatar
coco.oric
Squad Leader
Posts: 548
Joined: Tue Aug 11, 2009 9:50 am
Location: North of France
Contact:

Re: How to use MACROS with OSDK

Post 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.
coco.oric as DidierV, CEO Member
Historic owner of Oric, Apple II, Atari ST, Amiga

User avatar
Dbug
Site Admin
Posts: 3332
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: How to use MACROS with OSDK

Post 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 :)

jbperin
Pilot Officer
Posts: 81
Joined: Wed Nov 06, 2019 11:00 am

Re: How to use MACROS with OSDK

Post 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 ..

Post Reply