It is currently Sat Oct 21, 2017 5:26 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 18 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: Thu Jun 01, 2017 8:01 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5728
Location: Canada
Yeah, that builds.


Top
 Profile  
 
PostPosted: Thu Jun 01, 2017 10:12 pm 
Offline
User avatar

Joined: Sat Jan 09, 2016 9:21 pm
Posts: 213
Location: Central Illinois, USA
rainwarrior wrote:

You could also make a separate structure definitions header file with just the C or assembly structures in it and write a little parser utility to convert it to the other. You don't need a very complicated parser just to translate a struct definition.


That would be my recommendation. Have your makefile (or whatever build system) run a script to auto-create the assembly struct file from the C.

_________________
My games: http://www.bitethechili.com


Top
 Profile  
 
PostPosted: Fri Jun 02, 2017 1:09 am 
Offline
User avatar

Joined: Sat Sep 07, 2013 2:59 pm
Posts: 1402
A parser would be a bit overkill for me. But maybe I'll give it another try to create a code that can be parsed on the source level for both languages.

I'm already using this for constant values that I need in Assembly and in C:

Code:
#ifdef COMPILE_FOR_ASSEMBLY
#define DeclareConstant(name, value) name = value
#else
#define DeclareConstant(name, value) enum { name = value };
#endif


Maybe I can do a similar thing for the struct:
Code:
#ifdef COMPILE_FOR_ASSEMBLY
#define TypeByte byte
#define TypeUint word
#define DeclareStructStart(name) .struct name
#define DeclareStructEnd() .endstruct
#define DeclareMember(type, name) name: .type
#else
#define TypeByte unsigned char
#define TypeUint unsigned int
#define DeclareStructStart(name) struct name {
#define DeclareStructEnd() };
#define DeclareMember(type, name) type name;
#endif

DeclareStructStart(Character)
    DeclareMember(TypeByte, Energy)
DeclareStructEnd()

etc.

And then you call cc65 with that one specific command line parameter that only preprocesses the file instead of compiling it, so that it outputs a valid Assembly file if you define COMPILE_FOR_ASSEMBLY.
This file can be used in your code then. (The C file itself can be used anyway since it is already a valid C file if you don't define COMPILE_FOR_ASSEMBLY.)

_________________
Available now: My game "City Trouble".
Website: https://megacatstudios.com/products/city-trouble
Trailer: https://youtu.be/IYXpP59qSxA
Gameplay: https://youtu.be/Eee0yurkIW4
German Retro Gamer article: http://i67.tinypic.com/345o108.jpg


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page Previous  1, 2

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group