1 /* 2 * A nice old stdarg.h 3 * 4 * djm 28/2/2000 5 * 6 * Will this work? Who knows! 7 * 8 * NB. va_start must be called immediately after calling 9 * the function - i.e. no auto variables can be initialised 10 * (except to constants) 11 * 12 * NB2. The first call to va_next returns with the value 13 * of the first named argument, the 2nd call returns the 14 * value of the 2nd named argument etc etc 15 * 16 * I've only tested this with 2 byte arguments but it 17 * seems to work... 18 * 19 * $Id: stdarg.h,v 1.4 2016-03-07 20:25:48 dom Exp $ 20 */ 21 22 #ifndef __STDARG_H__ 23 #define __STDARG_H__ 24 25 26 #ifdef __Z88DK_R2L_CALLING_CONVENTION 27 28 /* sdcc/sccz80 in r2l mode is a lot more standard */ 29 typedef unsigned char * va_list; 30 31 #define va_start(marker, last) { marker = (va_list)&last + sizeof(last); } 32 #define va_arg(marker, type) *((type *)((marker += sizeof(type)) - sizeof(type))) 33 #define va_copy(dest, src) { dest = src; } 34 #define va_end(marker) { marker = (va_list) 0; }; 35 36 #define va_ptr(marker, type) *((type *)(marker - sizeof(type))) 37 38 #else 39 40 /* sccz80 (l2r) variant*/ 41 #ifndef DEF_GETARG 42 #define DEF_GETARG 43 extern int __LIB__ getarg(void); 44 #endif 45 46 #define va_list unsigned char * 47 #define va_start(ap,last) ap=(getarg()*2)+&last-5 48 #define va_arg(ap,type) (*(type*)(ap-=sizeof(type),ap+1)) 49 #define va_copy(dst, src) dst = src 50 #define va_end(ap) 51 52 #define va_ptr(ap,type) (*(type*)(ap+1)) 53 54 55 /* 56 * This (non-standard) macro could be used by routines 57 * with a similar setup to the library printf routines 58 */ 59 #define va_addr(ap,type) (ap-=sizeof(type)) 60 #endif 61 62 63 #endif /* _STDARG_H */ 64 65