DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/hardware/snd_pc98/common/parts.c
00001 #include    "np2glue.h"
00002 
00003 //#include      "compiler.h"
00004 #include        "parts.h"
00005 
00006 
00007 static  SINT32  randseed = 1;
00008 
00009 
00010 void PARTSCALL rand_setseed(SINT32 seed) {
00011 
00012         randseed = seed;
00013 }
00014 
00015 SINT32 PARTSCALL rand_get(void) {
00016 
00017         randseed = (randseed * 0x343fd) + 0x269ec3;
00018         return(randseed >> 16);
00019 }
00020 
00021 UINT8 PARTSCALL AdjustAfterMultiply(UINT8 value) {
00022 
00023         return((UINT8)(((value / 10) << 4) + (value % 10)));
00024 }
00025 
00026 UINT8 PARTSCALL AdjustBeforeDivision(UINT8 value) {
00027 
00028         return((UINT8)(((value >> 4) * 10) + (value & 0xf)));
00029 }
00030 
00031 UINT PARTSCALL sjis2jis(UINT sjis) {
00032 
00033         UINT    ret;
00034 
00035         ret = sjis & 0xff;
00036         ret -= (ret >> 7);
00037         ret += 0x62;
00038         if (ret < 256) {
00039                 ret = (ret - 0xa2) & 0x1ff;
00040         }
00041         ret += 0x1f21;
00042         ret += (sjis & 0x3f00) << 1;
00043         return(ret);
00044 }
00045 
00046 UINT PARTSCALL jis2sjis(UINT jis) {
00047 
00048         UINT    high;
00049         UINT    low;
00050 
00051         low = jis & 0x7f;
00052         high = (jis >> 8) & 0x7f;
00053         low += ((high & 1) - 1) & 0x5e;
00054         if (low >= 0x60) {
00055                 low++;
00056         }
00057         high += 0x121;
00058         low += 0x1f;
00059         high >>= 1;
00060         high ^= 0x20;
00061         return((high << 8) | low);
00062 }
00063 
00064 void PARTSCALL satuation_s16(SINT16 *dst, const SINT32 *src, UINT size) {
00065 
00066         size >>= 1;
00067         while(size--) {
00068                 SINT32 data = *src++;
00069                 if (data > 32767) {
00070                         data = 32767;
00071                 }
00072                 else if (data < -32768) {
00073                         data = -32768;
00074                 }
00075                 *dst++ = (SINT16)data;
00076         }
00077 }
00078 
00079 void PARTSCALL satuation_s16x(SINT16 *dst, const SINT32 *src, UINT size) {
00080 
00081         size >>= 2;
00082         while(size--) {
00083                 SINT32 data = src[0];
00084                 if (data > 32767) {
00085                         data = 32767;
00086                 }
00087                 else if (data < -32768) {
00088                         data = -32768;
00089                 }
00090                 dst[1] = (SINT16)data;
00091                 data = src[1];
00092                 if (data > 32767) {
00093                         data = 32767;
00094                 }
00095                 else if (data < -32768) {
00096                         data = -32768;
00097                 }
00098                 dst[0] = (SINT16)data;
00099                 src += 2;
00100                 dst += 2;
00101         }
00102 }
00103