-
Notifications
You must be signed in to change notification settings - Fork 6
/
sprintf.h
104 lines (82 loc) · 1.67 KB
/
sprintf.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**
* @file sprintf.h
* @brief Library for sprintf() function.
* @author Miguel I. Garcia Lopez / FloppySoftware
*
* Implementation of sprintf() function, for MESCC (Mike's Enhanced
* Small C Compiler for Z80 & CP/M).
*
* Revisions:
* - 20 Oct 2000 : Last revision.
* - 16 Apr 2007 : GPL'd.
* - 14 Apr 2015 : Ammended a bad closed comment.
* - 25 Aug 2016 : Documented. GPL v3.
*
* Copyright (c) 1999-2016 Miguel I. Garcia Lopez / FloppySoftware.
*
* Licensed under the GNU General Public License v3.
*
* http://www.floppysoftware.es
* floppysoftware@gmail.com
*/
#ifndef SPRINTF_H
#define SPRINTF_H
// Dependencies
// ------------
#ifndef XPRINTF_H
#include <xprintf.h>
#endif
/**
* @fn int sprintf(char *dst, char *fmt, arg1, arg2, ...)
* @brief Formatted output to memory.
*
* See the documentation for xprintf.h to learn about the string format.
*
* @param dst - destination
* @param fmt - string format
* @param arg1 - argument #1
* @param arg? - argument #?
* @return number or characters written, or -1 on failure (currently always #).
*/
#asm
sprintf:
ADD HL,HL
ADD HL,SP ;HL=Adr. fmt
LD DE,xspfout
PUSH DE
LD DE,xspfend
PUSH DE
PUSH HL
INC HL
INC HL ;HL=Adr. dst
LD A,(HL)
INC HL
LD H,(HL)
LD L,A
LD (xspfout+2),HL
CALL xprintf
POP BC
POP BC
POP BC
RET
#endasm
// int xspfout(char ch) : output ch to memory; return 0 on success, !=0 on failure (currently always returns 0).
#asm
xspfout:
LD A,L
LD HL,0 ;Adr.
LD (HL),A
INC HL
LD (xspfout+2),HL
LD HL,0
RET
#endasm
// void xspfend(void) : end formatted output; writes a trailing zero byte.
#asm
xspfend:
LD HL,(xspfout+2)
LD (HL),0
RET
#endasm
#endif