📄 dsp1emu.c
字号:
short Op04Radius;short Op04Sin;short Op04Cos;const short DSP1_MulTable[256] = { 0x0000, 0x0003, 0x0006, 0x0009, 0x000c, 0x000f, 0x0012, 0x0015, 0x0019, 0x001c, 0x001f, 0x0022, 0x0025, 0x0028, 0x002b, 0x002f, 0x0032, 0x0035, 0x0038, 0x003b, 0x003e, 0x0041, 0x0045, 0x0048, 0x004b, 0x004e, 0x0051, 0x0054, 0x0057, 0x005b, 0x005e, 0x0061, 0x0064, 0x0067, 0x006a, 0x006d, 0x0071, 0x0074, 0x0077, 0x007a, 0x007d, 0x0080, 0x0083, 0x0087, 0x008a, 0x008d, 0x0090, 0x0093, 0x0096, 0x0099, 0x009d, 0x00a0, 0x00a3, 0x00a6, 0x00a9, 0x00ac, 0x00af, 0x00b3, 0x00b6, 0x00b9, 0x00bc, 0x00bf, 0x00c2, 0x00c5, 0x00c9, 0x00cc, 0x00cf, 0x00d2, 0x00d5, 0x00d8, 0x00db, 0x00df, 0x00e2, 0x00e5, 0x00e8, 0x00eb, 0x00ee, 0x00f1, 0x00f5, 0x00f8, 0x00fb, 0x00fe, 0x0101, 0x0104, 0x0107, 0x010b, 0x010e, 0x0111, 0x0114, 0x0117, 0x011a, 0x011d, 0x0121, 0x0124, 0x0127, 0x012a, 0x012d, 0x0130, 0x0133, 0x0137, 0x013a, 0x013d, 0x0140, 0x0143, 0x0146, 0x0149, 0x014d, 0x0150, 0x0153, 0x0156, 0x0159, 0x015c, 0x015f, 0x0163, 0x0166, 0x0169, 0x016c, 0x016f, 0x0172, 0x0175, 0x0178, 0x017c, 0x017f, 0x0182, 0x0185, 0x0188, 0x018b, 0x018e, 0x0192, 0x0195, 0x0198, 0x019b, 0x019e, 0x01a1, 0x01a4, 0x01a8, 0x01ab, 0x01ae, 0x01b1, 0x01b4, 0x01b7, 0x01ba, 0x01be, 0x01c1, 0x01c4, 0x01c7, 0x01ca, 0x01cd, 0x01d0, 0x01d4, 0x01d7, 0x01da, 0x01dd, 0x01e0, 0x01e3, 0x01e6, 0x01ea, 0x01ed, 0x01f0, 0x01f3, 0x01f6, 0x01f9, 0x01fc, 0x0200, 0x0203, 0x0206, 0x0209, 0x020c, 0x020f, 0x0212, 0x0216, 0x0219, 0x021c, 0x021f, 0x0222, 0x0225, 0x0228, 0x022c, 0x022f, 0x0232, 0x0235, 0x0238, 0x023b, 0x023e, 0x0242, 0x0245, 0x0248, 0x024b, 0x024e, 0x0251, 0x0254, 0x0258, 0x025b, 0x025e, 0x0261, 0x0264, 0x0267, 0x026a, 0x026e, 0x0271, 0x0274, 0x0277, 0x027a, 0x027d, 0x0280, 0x0284, 0x0287, 0x028a, 0x028d, 0x0290, 0x0293, 0x0296, 0x029a, 0x029d, 0x02a0, 0x02a3, 0x02a6, 0x02a9, 0x02ac, 0x02b0, 0x02b3, 0x02b6, 0x02b9, 0x02bc, 0x02bf, 0x02c2, 0x02c6, 0x02c9, 0x02cc, 0x02cf, 0x02d2, 0x02d5, 0x02d8, 0x02db, 0x02df, 0x02e2, 0x02e5, 0x02e8, 0x02eb, 0x02ee, 0x02f1, 0x02f5, 0x02f8, 0x02fb, 0x02fe, 0x0301, 0x0304, 0x0307, 0x030b, 0x030e, 0x0311, 0x0314, 0x0317, 0x031a, 0x031d, 0x0321};const short DSP1_SinTable[256] = { 0x0000, 0x0324, 0x0647, 0x096a, 0x0c8b, 0x0fab, 0x12c8, 0x15e2, 0x18f8, 0x1c0b, 0x1f19, 0x2223, 0x2528, 0x2826, 0x2b1f, 0x2e11, 0x30fb, 0x33de, 0x36ba, 0x398c, 0x3c56, 0x3f17, 0x41ce, 0x447a, 0x471c, 0x49b4, 0x4c3f, 0x4ebf, 0x5133, 0x539b, 0x55f5, 0x5842, 0x5a82, 0x5cb4, 0x5ed7, 0x60ec, 0x62f2, 0x64e8, 0x66cf, 0x68a6, 0x6a6d, 0x6c24, 0x6dca, 0x6f5f, 0x70e2, 0x7255, 0x73b5, 0x7504, 0x7641, 0x776c, 0x7884, 0x798a, 0x7a7d, 0x7b5d, 0x7c29, 0x7ce3, 0x7d8a, 0x7e1d, 0x7e9d, 0x7f09, 0x7f62, 0x7fa7, 0x7fd8, 0x7ff6, 0x7fff, 0x7ff6, 0x7fd8, 0x7fa7, 0x7f62, 0x7f09, 0x7e9d, 0x7e1d, 0x7d8a, 0x7ce3, 0x7c29, 0x7b5d, 0x7a7d, 0x798a, 0x7884, 0x776c, 0x7641, 0x7504, 0x73b5, 0x7255, 0x70e2, 0x6f5f, 0x6dca, 0x6c24, 0x6a6d, 0x68a6, 0x66cf, 0x64e8, 0x62f2, 0x60ec, 0x5ed7, 0x5cb4, 0x5a82, 0x5842, 0x55f5, 0x539b, 0x5133, 0x4ebf, 0x4c3f, 0x49b4, 0x471c, 0x447a, 0x41ce, 0x3f17, 0x3c56, 0x398c, 0x36ba, 0x33de, 0x30fb, 0x2e11, 0x2b1f, 0x2826, 0x2528, 0x2223, 0x1f19, 0x1c0b, 0x18f8, 0x15e2, 0x12c8, 0x0fab, 0x0c8b, 0x096a, 0x0647, 0x0324, -0x0000, -0x0324, -0x0647, -0x096a, -0x0c8b, -0x0fab, -0x12c8, -0x15e2, -0x18f8, -0x1c0b, -0x1f19, -0x2223, -0x2528, -0x2826, -0x2b1f, -0x2e11, -0x30fb, -0x33de, -0x36ba, -0x398c, -0x3c56, -0x3f17, -0x41ce, -0x447a, -0x471c, -0x49b4, -0x4c3f, -0x4ebf, -0x5133, -0x539b, -0x55f5, -0x5842, -0x5a82, -0x5cb4, -0x5ed7, -0x60ec, -0x62f2, -0x64e8, -0x66cf, -0x68a6, -0x6a6d, -0x6c24, -0x6dca, -0x6f5f, -0x70e2, -0x7255, -0x73b5, -0x7504, -0x7641, -0x776c, -0x7884, -0x798a, -0x7a7d, -0x7b5d, -0x7c29, -0x7ce3, -0x7d8a, -0x7e1d, -0x7e9d, -0x7f09, -0x7f62, -0x7fa7, -0x7fd8, -0x7ff6, -0x7fff, -0x7ff6, -0x7fd8, -0x7fa7, -0x7f62, -0x7f09, -0x7e9d, -0x7e1d, -0x7d8a, -0x7ce3, -0x7c29, -0x7b5d, -0x7a7d, -0x798a, -0x7884, -0x776c, -0x7641, -0x7504, -0x73b5, -0x7255, -0x70e2, -0x6f5f, -0x6dca, -0x6c24, -0x6a6d, -0x68a6, -0x66cf, -0x64e8, -0x62f2, -0x60ec, -0x5ed7, -0x5cb4, -0x5a82, -0x5842, -0x55f5, -0x539b, -0x5133, -0x4ebf, -0x4c3f, -0x49b4, -0x471c, -0x447a, -0x41ce, -0x3f17, -0x3c56, -0x398c, -0x36ba, -0x33de, -0x30fb, -0x2e11, -0x2b1f, -0x2826, -0x2528, -0x2223, -0x1f19, -0x1c0b, -0x18f8, -0x15e2, -0x12c8, -0x0fab, -0x0c8b, -0x096a, -0x0647, -0x0324};short DSP1_Sin(short Angle){ if (Angle < 0) { if (Angle == -32768) return 0; return -DSP1_Sin(-Angle); } int S = DSP1_SinTable[Angle >> 8] + (DSP1_MulTable[Angle & 0xff] * DSP1_SinTable[0x40 + (Angle >> 8)] >> 15); if (S > 32767) S = 32767; return (short) S;}short DSP1_Cos(short Angle){ if (Angle < 0) { if (Angle == -32768) return -32768; Angle = -Angle; } int S = DSP1_SinTable[0x40 + (Angle >> 8)] - (DSP1_MulTable[Angle & 0xff] * DSP1_SinTable[Angle >> 8] >> 15); if (S < -32768) S = -32767; return (short) S;}void DSP1_Normalize(short m, short *Coefficient, short *Exponent){ short i = 0x4000; short e = 0; if (m < 0) while ((m & i) && i) { i >>= 1; e++; } else while (!(m & i) && i) { i >>= 1; e++; } if (e > 0) *Coefficient = m * DSP1ROM[0x21 + e] << 1; else *Coefficient = m; *Exponent -= e;}void DSP1_NormalizeDouble(int Product, short *Coefficient, short *Exponent){ short n = Product & 0x7fff; short m = Product >> 15; short i = 0x4000; short e = 0; if (m < 0) while ((m & i) && i) { i >>= 1; e++; } else while (!(m & i) && i) { i >>= 1; e++; } if (e > 0) { *Coefficient = m * DSP1ROM[0x0021 + e] << 1; if (e < 15) *Coefficient += n * DSP1ROM[0x0040 - e] >> 15; else { i = 0x4000; if (m < 0) while ((n & i) && i) { i >>= 1; e++; } else while (!(n & i) && i) { i >>= 1; e++; } if (e > 15) *Coefficient = n * DSP1ROM[0x0012 + e] << 1; else *Coefficient += n; } } else *Coefficient = m; *Exponent = e;}short DSP1_Truncate(short C, short E){ if (E > 0) { if (C > 0) return 32767; else if (C < 0) return -32767; } else { if (E < 0) return C * DSP1ROM[0x0031 + E] >> 15; } return C;}void DSPOp04(){ Op04Sin = DSP1_Sin(Op04Angle) * Op04Radius >> 15; Op04Cos = DSP1_Cos(Op04Angle) * Op04Radius >> 15;}short Op0CA;short Op0CX1;short Op0CY1;short Op0CX2;short Op0CY2;void DSPOp0C(){ Op0CX2 = (Op0CY1 * DSP1_Sin(Op0CA) >> 15) + (Op0CX1 * DSP1_Cos(Op0CA) >> 15); Op0CY2 = (Op0CY1 * DSP1_Cos(Op0CA) >> 15) - (Op0CX1 * DSP1_Sin(Op0CA) >> 15);}short CentreX;short CentreY;short VOffset;short VPlane_C;short VPlane_E;// Azimuth and Zenith anglesshort SinAas;short CosAas;short SinAzs;short CosAzs;// Clipped Zenith angleshort SinAZS; short CosAZS;short SecAZS_C1;short SecAZS_E1;short SecAZS_C2;short SecAZS_E2;const short MaxAZS_Exp[16] = { 0x38b4, 0x38b7, 0x38ba, 0x38be, 0x38c0, 0x38c4, 0x38c7, 0x38ca, 0x38ce, 0x38d0, 0x38d4, 0x38d7, 0x38da, 0x38dd, 0x38e0, 0x38e4};void DSP1_Parameter(short Fx, short Fy, short Fz, short Lfe, short Les, short Aas, short Azs, short *Vof, short *Vva, short *Cx, short *Cy){ short CSec, C, E; // Copy Zenith angle for clipping short AZS = Azs; // Store Sin and Cos of Azimuth and Zenith angles SinAas = DSP1_Sin(Aas); CosAas = DSP1_Cos(Aas); SinAzs = DSP1_Sin(Azs); CosAzs = DSP1_Cos(Azs); // Center of Projection CentreX = Fx + (Lfe * (SinAzs * -SinAas >> 15) >> 15); CentreY = Fy + (Lfe * (SinAzs * CosAas >> 15) >> 15); E = 0; DSP1_Normalize(Fz + (Lfe * (CosAzs * 0x7fff >> 15) >> 15), &C, &E); VPlane_C = C; VPlane_E = E; // Determine clip boundary and clip Zenith angle if necessary short MaxAZS = MaxAZS_Exp[-E]; if (AZS < 0) { MaxAZS = -MaxAZS; if (AZS < MaxAZS + 1) AZS = MaxAZS + 1; } else { if (AZS > MaxAZS) AZS = MaxAZS; } // Store Sin and Cos of clipped Zenith angle SinAZS = DSP1_Sin(AZS); CosAZS = DSP1_Cos(AZS); DSP1_Inverse(CosAZS, 0, &SecAZS_C1, &SecAZS_E1); DSP1_Normalize(C * SecAZS_C1 >> 15, &C, &E); E += SecAZS_E1; C = DSP1_Truncate(C, E) * SinAZS >> 15; CentreX += C * SinAas >> 15; CentreY -= C * CosAas >> 15; *Cx = CentreX; *Cy = CentreY; // Raster number of imaginary center and horizontal line *Vof = 0; if ((Azs != AZS) || (Azs == MaxAZS)) { if (Azs == -32768) Azs = -32767; C = Azs - MaxAZS; if (C >= 0) C--; short Aux = ~(C << 2); C = Aux * DSP1ROM[0x0328] >> 15; C = (C * Aux >> 15) + DSP1ROM[0x0327]; *Vof -= (C * Aux >> 15) * Les >> 15; C = Aux * Aux >> 15; Aux = (C * DSP1ROM[0x0324] >> 15) + DSP1ROM[0x0325]; CosAZS += (C * Aux >> 15) * CosAZS >> 15; } VOffset = Les * CosAZS >> 15; DSP1_Inverse(SinAZS, 0, &CSec, &E); DSP1_Normalize(VOffset, &C, &E); DSP1_Normalize(C * CSec >> 15, &C, &E); if (C == -32768) { C >>= 1; E++; } *Vva = DSP1_Truncate(-C, E); // Store Sec of clipped Zenith angle DSP1_Inverse(CosAZS, 0, &SecAZS_C2, &SecAZS_E2);}void DSP1_Raster(short Vs, short *An, short *Bn, short *Cn, short *Dn){ short C, E, C1, E1; DSP1_Inverse((Vs * SinAzs >> 15) + VOffset, 7, &C, &E); E += VPlane_E; C1 = C * VPlane_C >> 15; E1 = E + SecAZS_E2; DSP1_Normalize(C1, &C, &E); C = DSP1_Truncate(C, E); *An = C * CosAas >> 15; *Cn = C * SinAas >> 15; DSP1_Normalize(C1 * SecAZS_C2 >> 15, &C, &E1); C = DSP1_Truncate(C, E1); *Bn = C * -SinAas >> 15; *Dn = C * CosAas >> 15;}short Op02FX;short Op02FY;short Op02FZ;short Op02LFE;short Op02LES;short Op02AAS;short Op02AZS;short Op02VOF;short Op02VVA;short Op02CX;short Op02CY;void DSPOp02(){ DSP1_Parameter(Op02FX, Op02FY, Op02FZ, Op02LFE, Op02LES, Op02AAS, Op02AZS, &Op02VOF, &Op02VVA, &Op02CX, &Op02CY);}short Op0AVS;short Op0AA;short Op0AB;short Op0AC;short Op0AD;void DSPOp0A(){ DSP1_Raster(Op0AVS, &Op0AA, &Op0AB, &Op0AC, &Op0AD); Op0AVS++;}short Op06X;short Op06Y;short Op06Z;short Op06H;short Op06V;unsigned short Op06S;double ObjPX;double ObjPY;double ObjPZ;double ObjPX1;double ObjPY1;double ObjPZ1;double ObjPX2;double ObjPY2;double ObjPZ2;double DivideOp06;int Temp;int tanval2;#ifdef __OPT06__void DSPOp06(){ ObjPX=Op06X-Op02FX; ObjPY=Op06Y-Op02FY; ObjPZ=Op06Z-Op02FZ; // rotate around Z tanval2 = Angle(-Op02AAS+32768);// tanval2 = (-Op02AAS+32768)/(65536/INCR); ObjPX1=(ObjPX*Cos(tanval2)+ObjPY*-Sin(tanval2)); ObjPY1=(ObjPX*Sin(tanval2)+ObjPY*Cos(tanval2)); ObjPZ1=ObjPZ; // rotate around X// tanval2 = (-Op02AZS/(65536/INCR)) & 1023; tanval2 = Angle(-Op02AZS);// tanval2 = (-Op02AZS)/256; ObjPX2=ObjPX1; ObjPY2=(ObjPY1*Cos(tanval2)+ObjPZ1*-Sin(tanval2)); ObjPZ2=(ObjPY1*Sin(tanval2)+ObjPZ1*Cos(tanval2)); #ifdef debug06 Log_Message("ObjPX2: %f ObjPY2: %f ObjPZ2: %f\n",ObjPX2,ObjPY2,ObjPZ2); #endif ObjPZ2=ObjPZ2-Op02LFE; if (ObjPZ2<0) { double d; Op06H=(short)(-ObjPX2*Op02LES/-(ObjPZ2)); //-ObjPX2*256/-ObjPZ2; Op06V=(short)(-ObjPY2*Op02LES/-(ObjPZ2)); //-ObjPY2*256/-ObjPZ2; d=(double)Op02LES; d*=256.0; d/=(-ObjPZ2); if(d>65535.0) d=65535.0; else if(d<0.0) d=0.0; Op06S=(unsigned short)d; //Op06S=(unsigned short)(256*(double)Op02LES/-ObjPZ2); //Op06S=(unsigned short)((double)(256.0*((double)Op02LES)/(-ObjPZ2))); } else { Op06H=0; Op06V=14*16; Op06S=0xFFFF; } #ifdef DebugDSP1 Log_Message("OP06 X:%d Y:%d Z:%d",Op06X,Op06Y,Op06Z); Log_Message("OP06 H:%d V:%d S:%d",Op06H,Op06V,Op06S); #endif}#elsevoid DSPOp06(){ ObjPX=Op06X-Op02FX; ObjPY=Op06Y-Op02FY; ObjPZ=Op06Z-Op02FZ; // rotate around Z tanval = (-Op02AAS+32768)/65536.0*6.2832; ObjPX1=(ObjPX*cos(tanval)+ObjPY*-sin(tanval)); ObjPY1=(ObjPX*sin(tanval)+ObjPY*cos(tanval)); ObjPZ1=ObjPZ; #ifdef debug06 Log_Message("Angle : %f", tanval); Log_Message("ObjPX1: %f ObjPY1: %f ObjPZ1: %f\n",ObjPX1,ObjPY1,ObjPZ1); Log_Message("cos(tanval) : %f sin(tanval) : %f", cos(tanval), sin(tanval)); #endif // rotate around X tanval = (-Op02AZS)/65536.0*6.2832; ObjPX2=ObjPX1; ObjPY2=(ObjPY1*cos(tanval)+ObjPZ1*-sin(tanval)); ObjPZ2=(ObjPY1*sin(tanval)+ObjPZ1*cos(tanval)); #ifdef debug06 Log_Message("ObjPX2: %f ObjPY2: %f ObjPZ2: %f\n",ObjPX2,ObjPY2,ObjPZ2); #endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -