-
Notifications
You must be signed in to change notification settings - Fork 6
/
c_iocon.c
162 lines (124 loc) · 2.52 KB
/
c_iocon.c
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/* c_iocon.c
Mike's Enhanced Small C Compiler for Z80 & CP/M
I/O console module.
Copyright (c) 1999-2016 Miguel I. Garcia Lopez, FloppySoftware.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
Revisions:
16 Jan 2001 : Last revision.
16 Apr 2007 : GPL'd.
26 Oct 2015 : Cleaned.
11 Oct 2016 : Documented and slightly optimized.
21 Oct 2016 : Modified co_dec() an co_dec_5().
*/
// Print a character
// out: character value
co_ch(c)
char c;
{
putchar(c); return c;
}
// Print a string
// out: string address
co_str(s)
char *s;
{
#if C_USEPRINTF
printf("%s", s);
#else
/********************
char *p;
p = s;
while(*p)
co_ch(*p++);
*********************/
putstr(s);
#endif
return s;
}
// Print a string + '\n'
// out: string address
co_line(s)
char *s;
{
#if C_USEPRINTF
printf("%s\n", s);
#else
/***********************
co_str(s); co_ch('\n');
***********************/
puts(s);
#endif
return s;
}
// Print '\n'
co_nl()
{
co_ch('\n');
}
// Print signed decimal number
// out: value
co_dec(n)
int n;
{
#ifdef C_USEPRINTF
printf("%d", n);
#else
/********************************************************************
int i;
if(n < 0)
{
// Possible $8000 can't be negatived
// if((number^0xFFFF)==0x7FFF){outstr("0-32768");return;}
co_ch('-');
if(n == -32768)
{
co_str("32768"); return;
}
n = -n;
}
if(i = n / 10)
co_dec(i);
co_ch(n % 10 + '0');
*********************************************************************/
co_str(int2str(n));
#endif
return n;
}
// Print signed decimal number
co_dec_5(n)
int n;
{
#ifdef C_USEPRINTF
printf("%05d", n);
#else
/********************************************************************
if(n < 10000)
{
co_ch('0');
if(n < 1000)
{
co_ch('0');
if(n < 100)
{
co_ch('0');
if(n < 10)
co_ch('0');
}
}
}
co_dec(n);
*********************************************************************/
co_str(int2str_5(n));
#endif
}