#if !defined(SY__H) #define SY__H #include "symbol_set.base.h" /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~ Copy-Pastable Setup ~~~~~~~~~~~~~~~~~~~~~~~~~ ~~ To define a Symbol Set: ~~ copy the code below ~~ replace ZZZ: to name the symbol set ~~ replace Typezz: to set the type of the symbol set ~~ replace secz: to name of the data section of the symbol set ~~ pick and complete the sections with "..."s */ #if 0 #define SYMBOL_SET_DEFINE ZZZ #define ZZZ_Type Typezz #define ZZZ_section ".sy.secz" #define ZZZ_marker secz #include "symbol_set.define.h" // basic struct def with a name #define ZZZ_DEF(N,...) SyDefine(ZZZ, N) = { ... } // def with attached function body // replace funczz: to prefix namespace unique functions // fill ... sections appropriately #define ZZZ_DEF(N,...) \ static void funczz##N(void*); \ SyDefine(ZZZ, N) = { funczz##N, ... }; \ static void funczz##N(void *ptr) // nameless def #define ZZZ_DEF(...) SyDefineUnnamed(ZZZ) = { ... } #endif /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~ Loop Boilerplates ~~~~~~~~~~~~~~~~~*/ #if 0 { for (SyEach(ZZZ, zzz_ptr)){ zzz_ptr-> } } { for (SyEachID(ZZZ, zzz_id)){ [zzz_id] } } #endif /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~ User Primitives ~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ #define SyType(S) SY__GLUE(S,_Type) #define SyDeclare(S,N) SY__ALIGN_AS_LIT(8) SY__SEC_RW(S##_section) SyType(S) SY__SYMBOL(S,N) #define SyDefine(S,N) SY__DO_NOT_ELIMINATE(SY__SYMBOL(S,N)) SyDeclare(S,N) #define SyDefineUnnamed(S) SyDefine(S,SY__GLUE(unnamed,__COUNTER__)) #define SyAddress(S,N) (&SY__SYMBOL(S,N)) #define SyID(S,N) SyIDFromAddress_Unchecked(S,SyAddress(S,N)) #define SyRaw(S,N) (SY__UAddr)(SyAddress(S,N)) #if SY__OS_WINDOWS # define SyFirst(S) SY__FIRST(S) # define SyOpl(S) SY__OPL(S) #elif SY__OS_LINUX # define SyFirst(S) (&SY__FIRST(S)) # define SyOpl(S) (&SY__OPL(S)) #else # error missing implementation set locator for this OS #endif #define SyStride(S) SY__ROUND_UP_POW2(sizeof(SyType(S)), 8) #define SyCount(S) (((SY__U8*)SyOpl(S) - (SY__U8*)SyFirst(S))/SyStride(S)) #define SyNext(S,addr) (SyType(S)*)((SY__U8*)addr + SyStride(S)) #define SyEach(S,var) SyType(S)*var=SyFirst(S); varmagic == SY__PE_MSDOS_MAGIC){ SY__U32 *pe_signature = (SY__U32*)(base + dos->coff_file_offset); if (*pe_signature == SY__PE_SIGNATURE){ struct SY__PE_CoffHeader *coff = (struct SY__PE_CoffHeader*)(pe_signature + 1); SY__U32 sections_offset = (dos->coff_file_offset + sizeof(*pe_signature) + sizeof(*coff) + coff->optional_header_size); SY__U32 section_count = coff->section_count; struct SY__PE_SectionHeader* section = (struct SY__PE_SectionHeader*)(base + sections_offset); for (SY__U32 i = 0; i < section_count; i += 1, section += 1){ SY__B32 match = 1; for (SY__U32 j = 0; j < 8; j += 1){ if (name[j] != section->name[j]){ match = 0; break; } if (name[j] == 0){ break; } } if (match){ *first_out = base + section->voff; *opl_out = base + section->voff + section->vsize; break; } } } } } } #endif /* SY__OS_WINDOWS */ #endif //SY__MAIN_DEFINITIONS