diff options
Diffstat (limited to 'x68')
-rw-r--r-- | x68/_dtos18.c | 250 | ||||
-rw-r--r-- | x68/_round.c | 45 | ||||
-rw-r--r-- | x68/fconvert.c | 81 | ||||
-rw-r--r-- | x68/select.c | 167 |
4 files changed, 543 insertions, 0 deletions
diff --git a/x68/_dtos18.c b/x68/_dtos18.c new file mode 100644 index 0000000000..67656486ec --- /dev/null +++ b/x68/_dtos18.c @@ -0,0 +1,250 @@ +/* + * PROJECT C Library, X68000 PROGRAMMING INTERFACE DEFINITION + * -------------------------------------------------------------------- + * This file is written by the Project C Library Group, and completely + * in public domain. You can freely use, copy, modify, and redistribute + * the whole contents, without this notice. + * -------------------------------------------------------------------- + * $Id: _dtos18.c,v 1.2 1994/11/27 13:05:20 mura Exp $ + */ + +/* System headers */ +#include <stdlib.h> +#include <sys/xstdlib.h> + +/* +** �ܴؿ�����ư���������������������Ѵ����Ƥ���ʸ����ˤ��뤿�ᡢ����Ū�ˤ� +** �����������˳�Ǽ�Ǥ������ޤǤ����������Ȥ��Ǥ��ʤ����������äƺǹ����� +** ��18��Ǥ��롣 +*/ + +/* File scope variables */ +static double _pos1[32] = { + 1.0e+17, /* + 0 */ + 1.0e+18, /* + 1 */ + 1.0e+19, /* + 2 */ + 1.0e+20, /* + 3 */ + 1.0e+21, /* + 4 */ + 1.0e+22, /* + 5 */ + 1.0e+23, /* + 6 */ + 1.0e+24, /* + 7 */ + 1.0e+25, /* + 8 */ + 1.0e+26, /* + 9 */ + 1.0e+27, /* +10 */ + 1.0e+28, /* +11 */ + 1.0e+29, /* +12 */ + 1.0e+30, /* +13 */ + 1.0e+31, /* +14 */ + 1.0e+32, /* +15 */ + 1.0e+33, /* +16 */ + 1.0e+34, /* +17 */ + 1.0e+35, /* +18 */ + 1.0e+36, /* +19 */ + 1.0e+37, /* +20 */ + 1.0e+38, /* +21 */ + 1.0e+39, /* +22 */ + 1.0e+40, /* +23 */ + 1.0e+41, /* +24 */ + 1.0e+42, /* +25 */ + 1.0e+43, /* +26 */ + 1.0e+44, /* +27 */ + 1.0e+45, /* +28 */ + 1.0e+46, /* +29 */ + 1.0e+47, /* +30 */ + 1.0e+48, /* +31 */ +}; + +/* File scope variables */ +static double _neg1[32] = { + 1.0e+17, /* - 0 */ + 1.0e+16, /* - 1 */ + 1.0e+15, /* - 2 */ + 1.0e+14, /* - 3 */ + 1.0e+13, /* - 4 */ + 1.0e+12, /* - 5 */ + 1.0e+11, /* - 6 */ + 1.0e+10, /* - 7 */ + 1.0e+9, /* - 8 */ + 1.0e+8, /* - 9 */ + 1.0e+7, /* -10 */ + 1.0e+6, /* -11 */ + 1.0e+5, /* -12 */ + 1.0e+4, /* -13 */ + 1.0e+3, /* -14 */ + 1.0e+2, /* -15 */ + 1.0e+1, /* -16 */ + 1.0e+0, /* -17 */ + 1.0e-1, /* -18 */ + 1.0e-2, /* -19 */ + 1.0e-3, /* -20 */ + 1.0e-4, /* -21 */ + 1.0e-5, /* -22 */ + 1.0e-6, /* -23 */ + 1.0e-7, /* -24 */ + 1.0e-8, /* -25 */ + 1.0e-9, /* -26 */ + 1.0e-10, /* -27 */ + 1.0e-11, /* -28 */ + 1.0e-12, /* -29 */ + 1.0e-13, /* -30 */ + 1.0e-14, /* -31 */ +}; + +/* File scope variables */ +static double _pos2[10] = { + 1.0e+0, /* 000 */ + 1.0e+32, /* 001 */ + 1.0e+64, /* 010 */ + 1.0e+96, /* 011 */ + 1.0e+128, /* 100 */ + 1.0e+160, /* 101 */ + 1.0e+192, /* 110 */ + 1.0e+224, /* 111 */ + 1.0e+256, /* 1000 */ + 1.0e+288, /* 1001 */ +}; + +/* File scope variables */ +static double _neg2[10] = { + 1.0e-0, /* 000 */ + 1.0e-32, /* 001 */ + 1.0e-64, /* 010 */ + 1.0e-96, /* 011 */ + 1.0e-128, /* 100 */ + 1.0e-160, /* 101 */ + 1.0e-192, /* 110 */ + 1.0e-224, /* 111 */ + 1.0e-256, /* 1000 */ + 1.0e-288, /* 1001 */ +}; + +/* File scope functions */ +static int _cmpd (double x, double y) +{ + unsigned long vx, vy, rc; + unsigned long *x_ptr = (unsigned long *) &x; + unsigned long *y_ptr = (unsigned long *) &y; + + /* x�λؿ��ӥåȤ���Ф� */ + vx = x_ptr[0] & 0x7FF00000; + + /* y�λؿ��ӥåȤ���Ф� */ + vy = y_ptr[0] & 0x7FF00000; + + /* �ؿ��ӥåȤ�����Ƚ�Ǥ��� */ + if ((rc = vy - vx) != 0) + return rc; + + /* x��ͭ�������ξ�̥ӥåȤ���Ф� */ + vx = x_ptr[0] & 0x000FFFFF; + + /* y��ͭ�������ξ�̥ӥåȤ���Ф� */ + vy = y_ptr[0] & 0x000FFFFF; + + /* ��̥ӥåȤ�����Ƚ�Ǥ��� */ + if ((rc = vy - vx) != 0) + return rc; + + /* x��ͭ�������β��̥ӥåȤ���Ф� */ + vx = x_ptr[1]; + + /* y��ͭ�������β��̥ӥåȤ���Ф� */ + vy = y_ptr[1]; + + /* �ǽ�Ƚ�� */ + return vy - vx; +} + +/* Functions */ +void _dtos18 (double x, int *decpt, int *sign, char *buffer) +{ + short e2; + int e, n; + + /* ���2�λؿ������(�Х������ʤ��ξ���) */ + e2 = (((unsigned short *) &x)[0] & 0x7FF0U) >> 4; + + /* �ؿ���0�ξ��ϡ�0.0�����å� */ + if (e2 == 0) { + + unsigned long hi = ((unsigned long *) &x)[0] & 0xFFFFF; + unsigned long lo = ((unsigned long *) &x)[1]; + + /* ͭ������������0���ɤ��� */ + if (hi == 0 && lo == 0) { + + /* ʸ��������� */ + buffer[0] = '0'; + + /* NUL������ */ + buffer[1] = '\0'; + + /* ���������֤�� */ + *decpt = 1; + + /* ����� */ + /* *sign = hi & 0x80000000UL; */ + *sign = 0; + + /* ���� */ + return; + + } + + } + + /* 2�λؿ��˥Х��������Ƥ���10�λؿ��� (approx. log10(2)) */ + e = ((int) ((e2 - 1023) * 77)) >> 8; + + /* �ؿ������ξ�� */ + if (e >= 0) { + + /* �ؿ���32��꾮�������ϥơ��֥�1���� */ + if (e < 32) + x *= _neg1[e]; + + /* �ؿ���32����礭�����ϥơ��֥�1,2���� */ + else + x *= _neg1[e & 31] * _neg2[e >> 5]; + + } + + /* �ؿ�����ξ�� */ + else { + + /* �����ͤ�� */ + n = -e; + + /* �����ͤ�32��꾮�������ϥơ��֥�1���� */ + if (n < 32) + x *= _pos1[n]; + + /* �����ͤ�32����礭�����ϥơ��֥�1,2���� */ + else { + x *= _pos1[n & 31]; + x *= _pos2[n >> 5]; + } + + } + + /* ��������������������᤹ */ + if (_cmpd (1.0e+18, x) >= 0) { + e++; + x *= 1.0e-1; + } + + /* �����������ʤ������ɲ� */ + else if (_cmpd (1.0e+17, x) < 0) { + e--; + x *= 1.0e+1; + } + + /* ���������֤�� */ + *decpt = e + 1; + + /* ����� */ + *sign = ((unsigned char *) &x)[0] & 0x80U; + + /* ʸ������Ѵ� */ + _ulltoa ((unsigned long long) x, buffer); +} diff --git a/x68/_round.c b/x68/_round.c new file mode 100644 index 0000000000..73e44ca966 --- /dev/null +++ b/x68/_round.c @@ -0,0 +1,45 @@ +/* + * PROJECT C Library, X68000 PROGRAMMING INTERFACE DEFINITION + * -------------------------------------------------------------------- + * This file is written by the Project C Library Group, and completely + * in public domain. You can freely use, copy, modify, and redistribute + * the whole contents, without this notice. + * -------------------------------------------------------------------- + * $Id: _round.c,v 1.1 1994/11/27 13:05:36 mura Exp $ + */ +/* changed 1997.2.2 by K.Okabe */ + +/* System headers */ +#include <stdlib.h> +#include <sys/xstdlib.h> + +/* Functions */ +int _round (char *top, char *cur, int undig) +{ + char *ptr; + + /* �Ǹ夬5̤���ʤ�ݤ��ɬ�פʤ� */ + if (undig < '5') + return 0; + + /* �ݥ������� */ + ptr = cur - 1; + + /* ��Ƭ�ޤ����ʤ���ݤ���� */ + while (ptr >= top) { + + /* ����夬��ʤ���Ф���ǽ���� */ + if (++(*ptr) <= '9') + return 0; + + /* ���η��0���᤹ */ + *ptr-- = '0'; + + } + + /* ��Ƭ��1�ˤ��� */ + *++ptr = '1'; + + /* ����夬��餻�� */ + return 1; +} diff --git a/x68/fconvert.c b/x68/fconvert.c new file mode 100644 index 0000000000..05ff1fbd1a --- /dev/null +++ b/x68/fconvert.c @@ -0,0 +1,81 @@ +/* + * PROJECT C Library, X68000 PROGRAMMING INTERFACE DEFINITION + * -------------------------------------------------------------------- + * This file is written by the Project C Library Group, and completely + * in public domain. You can freely use, copy, modify, and redistribute + * the whole contents, without this notice. + * -------------------------------------------------------------------- + * $Id: fconvert.c,v 1.2 1994/11/27 13:06:19 mura Exp $ + */ +/* changed 1997.2.3 by K.Okabe */ + +/* System headers */ +#include <stdlib.h> +#include <sys/xstdlib.h> + +/* Functions */ +char *fconvert (double x, int ndigit, int *decpt, int *sign, char *buffer) +{ + int pos, n; + char *src, *dst; + char string[24]; + int figup; + + /* 18���ʸ������Ѵ� */ + _dtos18 (x, decpt, sign, string); + + /* ���ԡ������ɥ쥹������ */ + src = string; + + /* ���ԡ��襢�ɥ쥹������ */ + dst = buffer; + + /* ���������֤����� */ + pos = *decpt; + + /* ���������֤���ʤ� */ + if (pos < 0) { + + /* ��������� */ + n = min (-pos, ndigit); + + /* ��Ƭ��0������ */ + while (n-- > 0) + *dst++ = '0'; + + /* ���������֤�0�ˤʤ� */ + *decpt = 0; + + } + + /* �Ĥ�Υ��ԡ���� */ + n = ndigit + pos; + + /* ��Ǽ��˥��ԡ� */ + while (n-- > 0) { + + /* ��ʤ���ʬ��0������ */ + if (*src == '\0') { + while (n-- >= 0) + *dst++ = '0'; + break; + } + + /* �Ѵ�ʸ���饳�ԡ� */ + *dst++ = *src++; + + } + + /* �ݤ�� */ + *decpt += (figup = _round (buffer, dst, *src)); + + /* ����夬�꤬�����������0���ɲä��� */ + if (figup) + *dst++ = '0'; + + /* ��ü�� NUL ���Ǥ� */ + *dst = '\0'; + + /* ���ɥ쥹���֤� */ + return buffer; +} diff --git a/x68/select.c b/x68/select.c new file mode 100644 index 0000000000..b4bf464032 --- /dev/null +++ b/x68/select.c @@ -0,0 +1,167 @@ +/* + * PROJECT C Library, X68000 PROGRAMMING INTERFACE DEFINITION + * -------------------------------------------------------------------- + * This file is written by the Project C Library Group, and completely + * in public domain. You can freely use, copy, modify, and redistribute + * the whole contents, without this notice. + * -------------------------------------------------------------------- + * $Id$ + */ + +#ifndef __IOCS_INLINE__ +#define __IOCS_INLINE__ +#define __DOS_INLINE__ +#define __DOS_DOSCALL__ +#endif + +/* System headers */ +#include <errno.h> +#include <fcntl.h> +#include <string.h> +#include <sys/dos.h> +#include <sys/iocs.h> +#include <sys/time.h> +#include <sys/types.h> +#if 0 +#include <sys/select.h> +#include <sys/xsocket.h> +#endif +#include <sys/xunistd.h> + +/* Macros */ +#define XFD_ISSET(fd,fds) ((fds) && FD_ISSET ((fd), (fds))) +#define isreadable(mode) ((mode) == O_RDONLY || (mode) == O_RDWR) +#define iswritable(mode) ((mode) == O_WRONLY || (mode) == O_RDWR) +#ifndef _POSIX_FD_SETSIZE +#define _POSIX_FD_SETSIZE OPEN_MAX +#endif + +/* Functions */ +int +select (int fds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *timeout) +{ + fd_set oread, owrite, oexcept; + int ticks, start; + int nfds; + + if (fds > _POSIX_FD_SETSIZE) + { + errno = EINVAL; + return -1; + } + + FD_ZERO (&oread); + FD_ZERO (&owrite); + FD_ZERO (&oexcept); + + nfds = 0; + ticks = -1; + + if (timeout) + { + ticks = timeout->tv_sec * 100 + timeout->tv_usec / 10000; + if (ticks < 0) + { + errno = EINVAL; + return -1; + } + } + + start = _iocs_ontime (); + for (;;) + { + { + int fd; + + for (fd = 0; fd < fds; fd++) + { + int accmode; + + if (_fddb[fd].inuse == _FD_NOTUSED) + continue; + + accmode = _fddb[fd].oflag & O_ACCMODE; + + if (isatty (fd)) + { + if (XFD_ISSET (fd, rfds) && isreadable (accmode) && _dos_k_keysns ()) + { + FD_SET (fd, &oread); + nfds++; + } + + if (XFD_ISSET (fd, wfds) && iswritable (accmode)) + { + FD_SET (fd, &owrite); + nfds++; + } + } +#if 0 + else if (_fddb[fd].sockno >= 0) + { + if (XFD_ISSET (fd, rfds) && _socklen (_fddb[fd].sockno, 0)) + { + FD_SET (fd, &oread); + nfds++; + } + + if (XFD_ISSET (fd, wfds) /* && _socklen (_fddb[fd].sockno, 1) == 0 */) + { + FD_SET (fd, &owrite); + nfds++; + } + } +#endif + else + { + if (XFD_ISSET (fd, rfds) && isreadable (accmode) && _dos_ioctrlis (fd)) + { + FD_SET (fd, &oread); + nfds++; + } + + if (XFD_ISSET (fd, wfds) && iswritable (accmode) && _dos_ioctrlos (fd)) + { + FD_SET (fd, &owrite); + nfds++; + } + } + } + } + + { + int rest; + + if ((rest = (_iocs_ontime () - start) % 8640000) < 0) + rest += 8640000; + + if (nfds != 0) + { + if (ticks >= 0) + { + int left; + + if ((left = ticks - rest) < 0) + left = 0; + + timeout->tv_sec = left / 100; + timeout->tv_usec = (left % 100) * 10000; + } + + if (rfds) + *rfds = oread; + if (wfds) + *wfds = owrite; + if (efds) + *efds = oexcept; + + return nfds; + } + + if (ticks >= 0 && rest > ticks) + return 0; + } + + _dos_change_pr (); + } +} |