DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
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         SINT32  data;
00067 
00068         size >>= 1;
00069         while(size--) {
00070                 data = *src++;
00071                 if (data > 32767) {
00072                         data = 32767;
00073                 }
00074                 else if (data < -32768) {
00075                         data = -32768;
00076                 }
00077                 *dst++ = (SINT16)data;
00078         }
00079 }
00080 
00081 void PARTSCALL satuation_s16x(SINT16 *dst, const SINT32 *src, UINT size) {
00082 
00083         SINT32  data;
00084 
00085         size >>= 2;
00086         while(size--) {
00087                 data = src[0];
00088                 if (data > 32767) {
00089                         data = 32767;
00090                 }
00091                 else if (data < -32768) {
00092                         data = -32768;
00093                 }
00094                 dst[1] = (SINT16)data;
00095                 data = src[1];
00096                 if (data > 32767) {
00097                         data = 32767;
00098                 }
00099                 else if (data < -32768) {
00100                         data = -32768;
00101                 }
00102                 dst[0] = (SINT16)data;
00103                 src += 2;
00104                 dst += 2;
00105         }
00106 }
00107