📄 dsp1emu.c
字号:
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;short Nx, Ny, Nz;short Gx, Gy, Gz;short C_Les, E_Les, G_Les;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, MaxAZS, Aux; short LfeNx, LfeNy, LfeNz; short LesNx, LesNy, LesNz; short CentreZ; // Copy Zenith angle for clipping short AZS = Azs; // Store Sine and Cosine of Azimuth and Zenith angle SinAas = DSP1_Sin(Aas); CosAas = DSP1_Cos(Aas); SinAzs = DSP1_Sin(Azs); CosAzs = DSP1_Cos(Azs); Nx = SinAzs * -SinAas >> 15; Ny = SinAzs * CosAas >> 15; Nz = CosAzs * 0x7fff >> 15; LfeNx = Lfe*Nx>>15; LfeNy = Lfe*Ny>>15; LfeNz = Lfe*Nz>>15; // Center of Projection CentreX = Fx+LfeNx; CentreY = Fy+LfeNy; CentreZ = Fz+LfeNz; LesNx = Les*Nx>>15; LesNy = Les*Ny>>15; LesNz = Les*Nz>>15; Gx=CentreX-LesNx; Gy=CentreY-LesNy; Gz=CentreZ-LesNz; E_Les=0; DSP1_Normalize(Les, &C_Les, &E_Les); G_Les = Les; E = 0; DSP1_Normalize(CentreZ, &C, &E); VPlane_C = C; VPlane_E = E; // Determine clip boundary and clip Zenith angle if necessary MaxAZS = MaxAZS_Exp[-E]; if (AZS < 0) { MaxAZS = -MaxAZS; if (AZS < MaxAZS + 1) AZS = MaxAZS + 1; } else { if (AZS > MaxAZS) AZS = MaxAZS; } // Store Sine and Cosine 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--; 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 Secant 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 DSP1_ShiftR(short C, short E){ return (C * DSP1ROM[0x0031 + E] >> 15);}void DSP1_Project(short X, short Y, short Z, short *H, short *V, short *M){ int aux, aux4; short E, E2, E3, E4, E5, refE, E6, E7; short C2, C4, C6, C8, C9, C10, C11, C12, C16, C17, C18, C19, C20, C21, C22, C23, C24, C25, C26; short Px, Py, Pz; E4=E3=E2=E=E5=0; DSP1_NormalizeDouble((int)X-Gx, &Px, &E4); DSP1_NormalizeDouble((int)Y-Gy, &Py, &E); DSP1_NormalizeDouble((int)Z-Gz, &Pz, &E3); Px>>=1; E4--; // to avoid overflows when calculating the scalar products Py>>=1; E--; Pz>>=1; E3--; refE = (E<E3)?E:E3; refE = (refE<E4)?refE:E4; Px=DSP1_ShiftR(Px,E4-refE); // normalize them to the same exponent Py=DSP1_ShiftR(Py,E-refE); Pz=DSP1_ShiftR(Pz,E3-refE); C11=- (Px*Nx>>15); C8=- (Py*Ny>>15); C9=- (Pz*Nz>>15); C12=C11+C8+C9; // this cannot overflow! aux4=C12; // de-normalization with 32-bits arithmetic refE = 16-refE; // refE can be up to 3 if (refE>=0) aux4 <<=(refE); else aux4 >>=-(refE); if (aux4==-1) aux4 = 0; // why? aux4>>=1; aux = ((unsigned short)G_Les) + aux4; // Les - the scalar product of P with the normal vector of the screen DSP1_NormalizeDouble(aux, &C10, &E2); E2 = 15-E2; DSP1_Inverse(C10, 0, &C4, &E4); C2=C4*C_Les>>15; // scale factor // H E7=0; C16= (Px*(CosAas*0x7fff>>15)>>15); C20= (Py*(SinAas*0x7fff>>15)>>15); C17=C16+C20; // scalar product of P with the normalized horizontal vector of the screen... C18=C17*C2>>15; // ... multiplied by the scale factor DSP1_Normalize(C18, &C19, &E7); *H=DSP1_Truncate(C19, E_Les-E2+refE+E7); // V E6=0; C21 = Px*(CosAzs*-SinAas>>15)>>15; C22 = Py*(CosAzs*CosAas>>15)>>15; C23 = Pz*(-SinAzs*0x7fff>>15)>>15; C24=C21+C22+C23; // scalar product of P with the normalized vertical vector of the screen... C26=C24*C2>>15; // ... multiplied by the scale factor DSP1_Normalize(C26, &C25, &E6); *V=DSP1_Truncate(C25, E_Les-E2+refE+E6); // M DSP1_Normalize(C2, &C6, &E4); *M=DSP1_Truncate(C6, E4+E_Les-E2-7); // M is the scale factor divided by 2^7}short Op06X;short Op06Y;short Op06Z;short Op06H;short Op06V;short Op06M;void DSPOp06(){ DSP1_Project(Op06X, Op06Y, Op06Z, &Op06H, &Op06V, &Op06M);}short matrixC[3][3];short matrixB[3][3];short matrixA[3][3];short Op01m;short Op01Zr;short Op01Xr;short Op01Yr;short Op11m;short Op11Zr;short Op11Xr;short Op11Yr;short Op21m;short Op21Zr;short Op21Xr;short Op21Yr;void DSPOp01(){ short SinAz = DSP1_Sin(Op01Zr); short CosAz = DSP1_Cos(Op01Zr); short SinAy = DSP1_Sin(Op01Yr); short CosAy = DSP1_Cos(Op01Yr); short SinAx = DSP1_Sin(Op01Xr); short CosAx = DSP1_Cos(Op01Xr); Op01m >>= 1; matrixA[0][0] = (Op01m * CosAz >> 15) * CosAy >> 15;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -