X-Git-Url: http://4ch.mooo.com/gitweb/?a=blobdiff_plain;f=16%2Fw_modex%2FFIXED32.HPP;fp=16%2Fw_modex%2FFIXED32.HPP;h=49a084fed42da5d4f0d9b3c2f405e74dd839a515;hb=fc7d63d3fc9f520cbd6c95ef2e070733dae4400d;hp=0000000000000000000000000000000000000000;hpb=ec9980912cecfec9f20e6b41fb86c6af6af51b0f;p=16.git diff --git a/16/w_modex/FIXED32.HPP b/16/w_modex/FIXED32.HPP new file mode 100644 index 00000000..49a084fe --- /dev/null +++ b/16/w_modex/FIXED32.HPP @@ -0,0 +1,41 @@ +#ifndef FIXEDPOINT_HPP + #define FIXEDPOINT_HPP + +typedef long Fixed32; // 16.16 FixedPoint +typedef unsigned char Iangle; // Integer angle (0..255) + +/* Macros for Type Conversion */ +#define INT_TO_FIXED(x) ((x) << 16) +#define FIXED_TO_INT(x) ((x) >> 16) +#define ROUND_FIXED_TO_INT(x) (((x) + 0x8000) >> 16) + +// Loads Fixed32 datafiles +void initFixed32(void); + +// Common math functions +Fixed32 FixedMul(Fixed32 num1, Fixed32 num2); +Fixed32 FixedDiv(Fixed32 numer, Fixed32 denom); +void CosSin(Iangle theta, Fixed32 *Cos, Fixed32 *Sin); + +Fixed32 FixedMulASM(Fixed32 num1, Fixed32 num2); +#pragma aux FixedMulASM = \ + "imul edx" \ + "add eax, 8000h" \ + "adc edx, 0" \ + "shrd eax, edx, 16" \ + parm caller [eax] [edx] \ + value [eax] \ + modify [eax edx]; + +Fixed32 FixedDivASM(Fixed32 numer, Fixed32 denom); // No rounding! +#pragma aux FixedDivASM = \ + "xor eax, eax" \ + "shrd eax, edx, 16" \ + "sar edx, 16" \ + "idiv ebx" \ + parm caller [edx] [ebx] \ + value [eax] \ + modify [eax ebx edx]; + +#endif +