formatin.inc
Original include source with line numbers.
| 1 | #if defined _formatin_included |
| 2 | #endinput |
| 3 | #endif |
| 4 | |
| 5 | #if defined fmt |
| 6 | #define formatin fmt |
| 7 | #endinput |
| 8 | #endif |
| 9 | |
| 10 | #define _formatin_included |
| 11 | |
| 12 | #if !defined MAX_FMT_LENTH |
| 13 | #define MAX_FMT_LENGTH 256 |
| 14 | #endif |
| 15 | |
| 16 | #if !defined __vformat_allower |
| 17 | #define __vformat_allower __vformat_allower_ |
| 18 | |
| 19 | __vformat_allower_() |
| 20 | { |
| 21 | vformat("", 0, "", 0) |
| 22 | } |
| 23 | #endif |
| 24 | |
| 25 | formatin(const format[], any:...) |
| 26 | { |
| 27 | static formatted[MAX_FMT_LENGTH] |
| 28 | #emit PUSH.C 0x2 |
| 29 | #emit PUSH.S format |
| 30 | const FORMATTED_CHARSMAX = charsmax(formatted) |
| 31 | #emit PUSH.C FORMATTED_CHARSMAX |
| 32 | #emit LOAD.S.PRI 0x8 // Get size of arguments (count of arguments multiply by sizeof(cell)) |
| 33 | #emit ADDR.ALT 0xC // This is the pointer to first argument |
| 34 | #emit ADD // Now in PRI we have the pointer to hidden return argument |
| 35 | #emit LOAD.I // Now in PRI we have the pointer to return buffer |
| 36 | #emit PUSH.PRI |
| 37 | #emit PUSH.C 0x10 |
| 38 | #emit SYSREQ.C vformat |
| 39 | #emit STACK 0x14 |
| 40 | #emit RETN // Don't execute the code for copy return generated by compiler |
| 41 | __vformat_allower() |
| 42 | return formatted |
| 43 | } |