cc65 / cc65

cc65 - a freeware C compiler for 6502 based systems

Home Page:https://cc65.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Wishlist: a __CPU__ macro

colinleroy opened this issue · comments

It would be nice to have a CPU macro that does the same as .if (.cpu .bitand ::CPU_ISET_65SC02) for C files with inline asm.

For exemple, we could cut down on two bytes of ntohs:

#ifdef __CPU__65SC02__
#define ntohs(x)                \
    (                           \
        __AX__=(x),             \
        asm("pha"),        \
        asm("txa"),             \
        asm("plx"),        \
        __AX__                  \
    )#else
#define ntohs(x)                \
    (                           \
        __AX__=(x),             \
        asm("sta tmp1"),        \
        asm("txa"),             \
        asm("ldx tmp1"),        \
        __AX__                  \
    )
#endif

#ifdef __CPU__65SC02__

maybe a form like this would be more versatile: #if __CPU__ >= __CPU_65C02__
or even #if (__CPU__ < __CPU_65C02__) && (__CPU__ & __CPU_ILLEGAL_OPCODES_ENABLED__ != 0)

maybe a form like this would be more versatile: #if CPU >= CPU_65C02
or even #if (CPU < CPU_65C02) && (CPU & CPU_ILLEGAL_OPCODES_ENABLED != 0)

That makes no sense at all. (Neither does the bitfield)

maybe it makes sense if you view it in ascending order of capabilities, such as in my 6502 emulator: https://github.com/rofl0r/jg6502/blob/master/cpu65.c#L15-L19
0 = 2a03, base 6502 without BCD, 1 = 6502, base 6502 with illegal opcodes, and so forth.

maybe it makes sense if you view it in ascending order of capabilities

thats exactly what doesn't make sense

That said, a macro that tells you what CPU the target uses makes a lot of sense. I am surprised it doesn't exist :)

I may add it myself at some point :) (but not right now, right now I'm having too much pending branches, it's getting difficult to remember which version I last built)