[src/erc32] Use ncurses instead of termcap on Cygwin too
[binutils-gdb.git] / sim / m32c / misc.c
blob82e2b073a0b5cfab45a7378979b0eead7158a3f1
1 /* misc.c --- miscellaneous utility functions for M32C simulator.
3 Copyright (C) 2005-2018 Free Software Foundation, Inc.
4 Contributed by Red Hat, Inc.
6 This file is part of the GNU simulators.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include <stdio.h>
24 #include "cpu.h"
25 #include "misc.h"
27 int
28 bcd2int (int bcd, int w)
30 int v = 0, m = 1, i;
31 for (i = 0; i < (w ? 4 : 2); i++)
33 v += (bcd % 16) * m;
34 m *= 10;
35 bcd /= 16;
37 return v;
40 int
41 int2bcd (int v, int w)
43 int bcd = 0, m = 1, i;
44 for (i = 0; i < (w ? 4 : 2); i++)
46 bcd += (v % 10) * m;
47 m *= 16;
48 v /= 10;
50 return bcd;
53 char *
54 comma (unsigned int u)
56 static char buf[5][20];
57 static int bi = 0;
58 int comma = 0;
59 char *bp;
61 bi = (bi + 1) % 5;
62 bp = buf[bi] + 19;
63 *--bp = 0;
66 if (comma == 3)
68 *--bp = ',';
69 comma = 0;
71 comma++;
72 *--bp = '0' + (u % 10);
73 u /= 10;
75 while (u);
76 return bp;