2018-02-24 03:19:29 +00:00
|
|
|
#include "defs.h"
|
|
|
|
#include "io.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
void
|
2018-02-25 06:35:58 +00:00
|
|
|
write_num(IO *interface, KF_INT n)
|
2018-02-24 03:19:29 +00:00
|
|
|
{
|
2018-03-01 00:44:43 +00:00
|
|
|
static constexpr size_t nbuflen = 11;
|
2018-02-24 05:15:33 +00:00
|
|
|
char buf[nbuflen];
|
2018-02-28 03:59:29 +00:00
|
|
|
uint8_t i = nbuflen - 1;
|
|
|
|
memset(buf, 0, nbuflen);
|
2018-02-24 05:15:33 +00:00
|
|
|
|
2018-02-24 03:19:29 +00:00
|
|
|
if (n < 0) {
|
2018-02-25 06:35:58 +00:00
|
|
|
interface->wrch('-');
|
2018-02-24 03:19:29 +00:00
|
|
|
}
|
2018-02-27 16:04:17 +00:00
|
|
|
else if (n == 0) {
|
|
|
|
interface->wrch('0');
|
|
|
|
return;
|
|
|
|
}
|
2018-02-24 03:19:29 +00:00
|
|
|
|
|
|
|
while (n != 0) {
|
2018-02-28 03:59:29 +00:00
|
|
|
char x = n % 10;
|
|
|
|
x = x < 0 ? -x : x;
|
|
|
|
x += '0';
|
|
|
|
buf[i--] = x;
|
2018-02-24 03:19:29 +00:00
|
|
|
n /= 10;
|
|
|
|
}
|
|
|
|
|
2018-02-28 03:59:29 +00:00
|
|
|
interface->wrbuf(buf+i, nbuflen - i);
|
|
|
|
}
|
|
|
|
|
2018-03-02 00:09:06 +00:00
|
|
|
void
|
|
|
|
write_unum(IO *interface, KF_UINT n)
|
|
|
|
{
|
|
|
|
static constexpr size_t nbuflen = 11;
|
|
|
|
char buf[nbuflen];
|
|
|
|
uint8_t i = nbuflen - 1;
|
|
|
|
memset(buf, 0, nbuflen);
|
|
|
|
|
|
|
|
if (n == 0) {
|
|
|
|
interface->wrch('0');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (n != 0) {
|
|
|
|
char x = n % 10;
|
|
|
|
x += '0';
|
|
|
|
buf[i--] = x;
|
|
|
|
n /= 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface->wrbuf(buf+i, nbuflen - i);
|
|
|
|
}
|
|
|
|
|
2018-03-01 00:44:43 +00:00
|
|
|
void
|
|
|
|
write_dnum(IO *interface, KF_LONG n)
|
|
|
|
{
|
|
|
|
static constexpr size_t dnbuflen = 21;
|
|
|
|
char buf[dnbuflen];
|
|
|
|
uint8_t i = dnbuflen - 1;
|
|
|
|
memset(buf, 0, dnbuflen);
|
|
|
|
|
|
|
|
if (n < 0) {
|
|
|
|
interface->wrch('-');
|
|
|
|
}
|
|
|
|
else if (n == 0) {
|
|
|
|
interface->wrch('0');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (n != 0) {
|
|
|
|
char x = n % 10;
|
|
|
|
x = x < 0 ? -x : x;
|
|
|
|
x += '0';
|
|
|
|
buf[i--] = x;
|
|
|
|
n /= 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface->wrbuf(buf+i, dnbuflen - i);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-28 03:59:29 +00:00
|
|
|
void
|
|
|
|
write_dstack(IO *interface, Stack<KF_INT> dstack)
|
|
|
|
{
|
|
|
|
KF_INT tmp;
|
|
|
|
interface->wrch('<');
|
|
|
|
for (size_t i = 0; i < dstack.size(); i++) {
|
|
|
|
if (i > 0) {
|
|
|
|
interface->wrch(' ');
|
|
|
|
}
|
|
|
|
|
|
|
|
dstack.get(i, tmp);
|
|
|
|
write_num(interface, tmp);
|
|
|
|
}
|
|
|
|
interface->wrch('>');
|
|
|
|
}
|