1
0

cfunc.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901
  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <math.h>
  4. #include "Compiler.h"
  5. #include "eval.h"
  6. // these are used by our assembly code
  7. static float g_cmpaddtab[2]={0.0,1.0};
  8. static float g_signs[2]={1.0,-1.0};
  9. static double g_closefact = 0.00001;
  10. static float g_half=0.5;
  11. static float negativezeropointfive=-0.5f;
  12. static float onepointfive=1.5f;
  13. /// functions called by built code
  14. #define SHITCALL __fastcall
  15. #define isnonzero(x) (fabs(x) > g_closefact)
  16. //---------------------------------------------------------------------------------------------------------------
  17. static double SHITCALL _rand(double *x)
  18. {
  19. if (*x < 1.0) *x=1.0;
  20. return (double)(rand()%(int)max(*x,1.0));
  21. }
  22. //---------------------------------------------------------------------------------------------------------------
  23. static double SHITCALL _band(double *var, double *var2)
  24. {
  25. return isnonzero(*var) && isnonzero(*var2) ? 1 : 0;
  26. }
  27. //---------------------------------------------------------------------------------------------------------------
  28. static double SHITCALL _bor(double *var, double *var2)
  29. {
  30. return isnonzero(*var) || isnonzero(*var2) ? 1 : 0;
  31. }
  32. //---------------------------------------------------------------------------------------------------------------
  33. static double SHITCALL _sig(double *x, double *constraint)
  34. {
  35. double t = (1+exp(-*x * (*constraint)));
  36. return isnonzero(t) ? 1.0/t : 0;
  37. }
  38. extern char *g_evallib_visdata;
  39. static double SHITCALL getvis(unsigned char *visdata, int bc, int bw, int ch, int xorv)
  40. {
  41. int x;
  42. int accum=0;
  43. if (ch && ch != 1 && ch != 2) return 0.0;
  44. if (bw < 1) bw=1;
  45. bc-=bw/2;
  46. if (bc < 0)
  47. {
  48. bw+=bc;
  49. bc=0;
  50. }
  51. if (bc > 575) bc=575;
  52. if (bc+bw > 576) bw=576-bc;
  53. if (!ch)
  54. {
  55. for (x = 0; x < bw; x ++)
  56. {
  57. accum+=(visdata[bc]^xorv)-xorv;
  58. accum+=(visdata[bc+576]^xorv)-xorv;
  59. bc++;
  60. }
  61. return (double)accum / ((double)bw*255.0);
  62. }
  63. else
  64. {
  65. if (ch == 2) visdata+=576;
  66. for (x = 0; x < bw; x ++) accum+=(visdata[bc++]^xorv)-xorv;
  67. return (double)accum / ((double)bw*127.5);
  68. }
  69. }
  70. static double SHITCALL getspec_(double *band, double *bandw, double *chan)
  71. {
  72. if (!g_evallib_visdata) return 0.0;
  73. return getvis((unsigned char *)g_evallib_visdata,(int)(*band*576.0),(int)(*bandw*576.0),(int)(*chan+0.5),0)*0.5;
  74. }
  75. static double SHITCALL getosc_(double *band, double *bandw, double *chan)
  76. {
  77. if (!g_evallib_visdata) return 0.0;
  78. return getvis((unsigned char *)g_evallib_visdata+576*2,(int)(*band*576.0),(int)(*bandw*576.0),(int)(*chan+0.5),128);
  79. }
  80. static double SHITCALL gettime_(double *sc)
  81. {
  82. int ispos;
  83. if ((ispos=(*sc > -1.001 && *sc < -0.999)) || (*sc > -2.001 && *sc < -1.999))
  84. {
  85. int pos=0;
  86. extern HWND hwnd_WinampParent;
  87. if (IsWindow(hwnd_WinampParent))
  88. {
  89. if (!SendMessageTimeout( hwnd_WinampParent, WM_USER,(WPARAM)!ispos,(LPARAM)105,SMTO_BLOCK,50,(LPDWORD)&pos)) pos=0;
  90. }
  91. if (!ispos) return (double)pos;
  92. return pos / 1000.0;
  93. }
  94. return GetTickCount()/1000.0 - *sc;
  95. }
  96. static double SHITCALL setmousepos_(double *x, double *y)
  97. {
  98. //fucko: implement me
  99. return 0.0;
  100. }
  101. static double SHITCALL getmouse_(double *which)
  102. {
  103. int w=(int)(*which+0.5);
  104. if (w > 5)
  105. return (GetAsyncKeyState(w)&0x8000)?1.0:0.0;
  106. if (w == 1 || w == 2)
  107. {
  108. double DDraw_translatePoint(POINT p, int isY);
  109. POINT p;
  110. GetCursorPos(&p);
  111. return DDraw_translatePoint(p,w==2);
  112. }
  113. if (w == 3) return (GetAsyncKeyState(MK_LBUTTON)&0x8000)?1.0:0.0;
  114. if (w == 4) return (GetAsyncKeyState(MK_RBUTTON)&0x8000)?1.0:0.0;
  115. if (w == 5) return (GetAsyncKeyState(MK_MBUTTON)&0x8000)?1.0:0.0;
  116. return 0.0;
  117. }
  118. // end functions called by inline code
  119. // these make room on the stack for local variables, but do not need to
  120. // worry about trashing ebp, since none of our code uses ebp and there's
  121. // a pushad+popad surrounding the call
  122. #if 0 // dont seem to need to do this
  123. #define CF_PUSHREGS __asm { push esi } __asm { push edi }
  124. #define CF_POPREGS __asm { pop edi } __asm { pop esi }
  125. #else
  126. #define CF_PUSHREGS
  127. #define CF_POPREGS
  128. #endif
  129. #define FUNC1_ENTER \
  130. double *parm_a, *__nextBlock; \
  131. __asm { mov ebp, esp } \
  132. __asm { sub esp, __LOCAL_SIZE } \
  133. __asm { mov dword ptr parm_a, eax } \
  134. __asm { mov __nextBlock, esi } \
  135. CF_PUSHREGS
  136. #define FUNC2_ENTER \
  137. double *parm_a,*parm_b,*__nextBlock; \
  138. __asm { mov ebp, esp } \
  139. __asm { sub esp, __LOCAL_SIZE } \
  140. __asm { mov dword ptr parm_a, eax } \
  141. __asm { mov dword ptr parm_b, ebx } \
  142. __asm { mov __nextBlock, esi } \
  143. CF_PUSHREGS
  144. #define FUNC3_ENTER \
  145. double *parm_a,*parm_b,*parm_c,*__nextBlock; \
  146. __asm { mov ebp, esp } \
  147. __asm { sub esp, __LOCAL_SIZE } \
  148. __asm { mov dword ptr parm_a, eax } \
  149. __asm { mov dword ptr parm_b, ebx } \
  150. __asm { mov dword ptr parm_c, ecx } \
  151. __asm { mov __nextBlock, esi } \
  152. CF_PUSHREGS
  153. #define FUNC_LEAVE \
  154. __asm { mov eax, esi } \
  155. __asm { add esi, 8 } \
  156. __asm { mov esp, ebp } \
  157. CF_POPREGS
  158. static double (*__asin)(double) = &asin;
  159. //---------------------------------------------------------------------------------------------------------------
  160. __declspec ( naked ) void _asm_asin(void)
  161. {
  162. FUNC1_ENTER
  163. *__nextBlock = __asin(*parm_a);
  164. FUNC_LEAVE
  165. }
  166. __declspec ( naked ) void _asm_asin_end(void) {}
  167. static double (*__acos)(double) = &acos;
  168. //---------------------------------------------------------------------------------------------------------------
  169. __declspec ( naked ) void _asm_acos(void)
  170. {
  171. FUNC1_ENTER
  172. *__nextBlock = __acos(*parm_a);
  173. FUNC_LEAVE
  174. }
  175. __declspec ( naked ) void _asm_acos_end(void) {}
  176. //---------------------------------------------------------------------------------------------------------------
  177. static double (*__atan)(double) = &atan;
  178. __declspec ( naked ) void _asm_atan(void)
  179. {
  180. FUNC1_ENTER
  181. *__nextBlock = __atan(*parm_a);
  182. FUNC_LEAVE
  183. }
  184. __declspec ( naked ) void _asm_atan_end(void) {}
  185. //---------------------------------------------------------------------------------------------------------------
  186. static double (*__atan2)(double,double) = &atan2;
  187. __declspec ( naked ) void _asm_atan2(void)
  188. {
  189. FUNC2_ENTER
  190. *__nextBlock = __atan2(*parm_b, *parm_a);
  191. FUNC_LEAVE
  192. }
  193. __declspec ( naked ) void _asm_atan2_end(void) {}
  194. //---------------------------------------------------------------------------------------------------------------
  195. static double (SHITCALL * __sig)(double *,double *) = &_sig;
  196. __declspec ( naked ) void _asm_sig(void)
  197. {
  198. FUNC2_ENTER
  199. *__nextBlock = __sig(parm_b, parm_a);
  200. FUNC_LEAVE
  201. }
  202. __declspec ( naked ) void _asm_sig_end(void) {}
  203. //---------------------------------------------------------------------------------------------------------------
  204. static double (SHITCALL *__rand)(double *) = &_rand;
  205. __declspec ( naked ) void _asm_rand(void)
  206. {
  207. FUNC1_ENTER
  208. *__nextBlock = __rand(parm_a);
  209. FUNC_LEAVE
  210. }
  211. __declspec ( naked ) void _asm_rand_end(void) {}
  212. //---------------------------------------------------------------------------------------------------------------
  213. static double (SHITCALL *__band)(double *,double *) = &_band;
  214. __declspec ( naked ) void _asm_band(void)
  215. {
  216. FUNC2_ENTER
  217. *__nextBlock = __band(parm_b, parm_a);
  218. FUNC_LEAVE
  219. }
  220. __declspec ( naked ) void _asm_band_end(void) {}
  221. //---------------------------------------------------------------------------------------------------------------
  222. static double ( SHITCALL *__bor)(double *,double *) = &_bor;
  223. __declspec ( naked ) void _asm_bor(void)
  224. {
  225. FUNC2_ENTER
  226. *__nextBlock = __bor(parm_b, parm_a);
  227. FUNC_LEAVE
  228. }
  229. __declspec ( naked ) void _asm_bor_end(void) {}
  230. //---------------------------------------------------------------------------------------------------------------
  231. static double (* __pow)(double,double) = &pow;
  232. __declspec ( naked ) void _asm_pow(void)
  233. {
  234. FUNC2_ENTER
  235. *__nextBlock = __pow(*parm_b, *parm_a);
  236. FUNC_LEAVE
  237. }
  238. __declspec ( naked ) void _asm_pow_end(void) {}
  239. //---------------------------------------------------------------------------------------------------------------
  240. static double (*__exp)(double) = &exp;
  241. __declspec ( naked ) void _asm_exp(void)
  242. {
  243. FUNC1_ENTER
  244. *__nextBlock = __exp(*parm_a);
  245. FUNC_LEAVE
  246. }
  247. __declspec ( naked ) void _asm_exp_end(void) {}
  248. //---------------------------------------------------------------------------------------------------------------
  249. static double (*__floor)(double) = &floor;
  250. __declspec ( naked ) void _asm_floor(void)
  251. {
  252. FUNC1_ENTER
  253. *__nextBlock = __floor(*parm_a);
  254. FUNC_LEAVE
  255. }
  256. __declspec ( naked ) void _asm_floor_end(void) {}
  257. //---------------------------------------------------------------------------------------------------------------
  258. static double (*__ceil)(double) = &ceil;
  259. __declspec ( naked ) void _asm_ceil(void)
  260. {
  261. FUNC1_ENTER
  262. *__nextBlock = __ceil(*parm_a);
  263. FUNC_LEAVE
  264. }
  265. __declspec ( naked ) void _asm_ceil_end(void) {}
  266. //---------------------------------------------------------------------------------------------------------------
  267. static double (SHITCALL *__getosc)(double *,double *,double *) = &getosc_;
  268. __declspec ( naked ) void _asm_getosc(void)
  269. {
  270. FUNC3_ENTER
  271. *__nextBlock = __getosc(parm_c,parm_b,parm_a);
  272. FUNC_LEAVE
  273. }
  274. __declspec ( naked ) void _asm_getosc_end(void) {}
  275. static double (SHITCALL *__getspec)(double *,double *,double *) = &getspec_;
  276. __declspec ( naked ) void _asm_getspec(void)
  277. {
  278. FUNC3_ENTER
  279. *__nextBlock = __getspec(parm_c,parm_b,parm_a);
  280. FUNC_LEAVE
  281. }
  282. __declspec ( naked ) void _asm_getspec_end(void) {}
  283. static double (SHITCALL *__gettime)(double *) = &gettime_;
  284. __declspec ( naked ) void _asm_gettime(void)
  285. {
  286. FUNC1_ENTER
  287. *__nextBlock = __gettime(parm_a);
  288. FUNC_LEAVE
  289. }
  290. __declspec ( naked ) void _asm_gettime_end(void) {}
  291. // do nothing, eh
  292. __declspec ( naked ) void _asm_exec2(void)
  293. {
  294. }
  295. __declspec ( naked ) void _asm_exec2_end(void) { }
  296. static double (SHITCALL *__getmouse)(double *) = &getmouse_;
  297. __declspec ( naked ) void _asm_getmouse(void)
  298. {
  299. FUNC1_ENTER
  300. *__nextBlock = __getmouse(parm_a);
  301. FUNC_LEAVE
  302. }
  303. __declspec ( naked ) void _asm_getmouse_end(void) {}
  304. static double (SHITCALL *__setmousepos)(double *,double *) = &setmousepos_;
  305. __declspec ( naked ) void _asm_setmousepos(void)
  306. {
  307. FUNC2_ENTER
  308. *__nextBlock = __setmousepos(parm_a,parm_b);
  309. FUNC_LEAVE
  310. }
  311. __declspec ( naked ) void _asm_setmousepos_end(void) {}
  312. __declspec ( naked ) void _asm_invsqrt(void)
  313. {
  314. __asm
  315. {
  316. fld qword ptr [eax]
  317. mov edx, 0x5f3759df
  318. fst dword ptr [esi]
  319. // floating point stack has input, as does [eax]
  320. fmul dword ptr [negativezeropointfive]
  321. mov ecx, [esi]
  322. sar ecx, 1
  323. sub edx, ecx
  324. mov [esi], edx
  325. // st(0) = input, [eax] has x
  326. fmul dword ptr [esi]
  327. fmul dword ptr [esi]
  328. fadd dword ptr [onepointfive]
  329. fmul dword ptr [esi]
  330. mov eax, esi
  331. fstp qword ptr [esi]
  332. add esi, 8
  333. }
  334. }
  335. __declspec ( naked ) void _asm_invsqrt_end(void) {}
  336. //---------------------------------------------------------------------------------------------------------------
  337. __declspec ( naked ) void _asm_sin(void)
  338. {
  339. __asm
  340. {
  341. fld qword ptr [eax]
  342. fsin
  343. mov eax, esi
  344. fstp qword ptr [esi]
  345. add esi, 8
  346. }
  347. }
  348. __declspec ( naked ) void _asm_sin_end(void) {}
  349. //---------------------------------------------------------------------------------------------------------------
  350. __declspec ( naked ) void _asm_cos(void)
  351. {
  352. __asm
  353. {
  354. fld qword ptr [eax]
  355. fcos
  356. mov eax, esi
  357. fstp qword ptr [esi]
  358. add esi, 8
  359. }
  360. }
  361. __declspec ( naked ) void _asm_cos_end(void) {}
  362. //---------------------------------------------------------------------------------------------------------------
  363. __declspec ( naked ) void _asm_tan(void)
  364. {
  365. __asm
  366. {
  367. fld qword ptr [eax]
  368. fsincos
  369. fdiv
  370. mov eax, esi
  371. fstp qword ptr [esi]
  372. add esi, 8
  373. }
  374. }
  375. __declspec ( naked ) void _asm_tan_end(void) {}
  376. //---------------------------------------------------------------------------------------------------------------
  377. __declspec ( naked ) void _asm_sqr(void)
  378. {
  379. __asm
  380. {
  381. fld qword ptr [eax]
  382. fmul st(0), st(0)
  383. mov eax, esi
  384. fstp qword ptr [esi]
  385. add esi, 8
  386. }
  387. }
  388. __declspec ( naked ) void _asm_sqr_end(void) {}
  389. //---------------------------------------------------------------------------------------------------------------
  390. __declspec ( naked ) void _asm_sqrt(void)
  391. {
  392. __asm
  393. {
  394. fld qword ptr [eax]
  395. fabs
  396. fsqrt
  397. mov eax, esi
  398. fstp qword ptr [esi]
  399. add esi, 8
  400. }
  401. }
  402. __declspec ( naked ) void _asm_sqrt_end(void) {}
  403. //---------------------------------------------------------------------------------------------------------------
  404. __declspec ( naked ) void _asm_log(void)
  405. {
  406. __asm
  407. {
  408. fld1
  409. fldl2e
  410. fdiv
  411. fld qword ptr [eax]
  412. mov eax, esi
  413. fyl2x
  414. fstp qword ptr [esi]
  415. add esi, 8
  416. }
  417. }
  418. __declspec ( naked ) void _asm_log_end(void) {}
  419. //---------------------------------------------------------------------------------------------------------------
  420. __declspec ( naked ) void _asm_log10(void)
  421. {
  422. __asm
  423. {
  424. fld1
  425. fldl2t
  426. fdiv
  427. fld qword ptr [eax]
  428. mov eax, esi
  429. fyl2x
  430. fstp qword ptr [esi]
  431. add esi, 8
  432. }
  433. }
  434. __declspec ( naked ) void _asm_log10_end(void) {}
  435. //---------------------------------------------------------------------------------------------------------------
  436. __declspec ( naked ) void _asm_abs(void)
  437. {
  438. __asm
  439. {
  440. fld qword ptr [eax]
  441. fabs
  442. mov eax, esi
  443. fstp qword ptr [esi]
  444. add esi, 8
  445. }
  446. }
  447. __declspec ( naked ) void _asm_abs_end(void) {}
  448. //---------------------------------------------------------------------------------------------------------------
  449. __declspec ( naked ) void _asm_assign(void)
  450. {
  451. __asm
  452. {
  453. fld qword ptr [eax]
  454. fstp qword ptr [ebx]
  455. }
  456. }
  457. __declspec ( naked ) void _asm_assign_end(void) {}
  458. //---------------------------------------------------------------------------------------------------------------
  459. __declspec ( naked ) void _asm_add(void)
  460. {
  461. __asm
  462. {
  463. fld qword ptr [eax]
  464. fadd qword ptr [ebx]
  465. mov eax, esi
  466. fstp qword ptr [esi]
  467. add esi, 8
  468. }
  469. }
  470. __declspec ( naked ) void _asm_add_end(void) {}
  471. //---------------------------------------------------------------------------------------------------------------
  472. __declspec ( naked ) void _asm_sub(void)
  473. {
  474. __asm
  475. {
  476. fld qword ptr [ebx]
  477. fsub qword ptr [eax]
  478. mov eax, esi
  479. fstp qword ptr [esi]
  480. add esi, 8
  481. }
  482. }
  483. __declspec ( naked ) void _asm_sub_end(void) {}
  484. //---------------------------------------------------------------------------------------------------------------
  485. __declspec ( naked ) void _asm_mul(void)
  486. {
  487. __asm
  488. {
  489. fld qword ptr [ebx]
  490. fmul qword ptr [eax]
  491. mov eax, esi
  492. fstp qword ptr [esi]
  493. add esi, 8
  494. }
  495. }
  496. __declspec ( naked ) void _asm_mul_end(void) {}
  497. //---------------------------------------------------------------------------------------------------------------
  498. __declspec ( naked ) void _asm_div(void)
  499. {
  500. __asm
  501. {
  502. fld qword ptr [ebx]
  503. fdiv qword ptr [eax]
  504. mov eax, esi
  505. fstp qword ptr [esi]
  506. add esi, 8
  507. }
  508. }
  509. __declspec ( naked ) void _asm_div_end(void) {}
  510. //---------------------------------------------------------------------------------------------------------------
  511. __declspec ( naked ) void _asm_mod(void)
  512. {
  513. __asm
  514. {
  515. fld qword ptr [ebx]
  516. fld qword ptr [eax]
  517. fsub dword ptr [g_cmpaddtab+4]
  518. fabs
  519. fadd qword ptr [eax]
  520. fadd dword ptr [g_cmpaddtab+4]
  521. fmul dword ptr [g_half]
  522. fistp dword ptr [esi]
  523. fistp dword ptr [esi+4]
  524. mov eax, [esi+4]
  525. xor edx, edx
  526. div dword ptr [esi]
  527. mov [esi], edx
  528. fild dword ptr [esi]
  529. mov eax, esi
  530. fstp qword ptr [esi]
  531. add esi, 8
  532. }
  533. }
  534. __declspec ( naked ) void _asm_mod_end(void) {}
  535. //---------------------------------------------------------------------------------------------------------------
  536. __declspec ( naked ) void _asm_or(void)
  537. {
  538. __asm
  539. {
  540. fld qword ptr [ebx]
  541. fld qword ptr [eax]
  542. fistp qword ptr [esi]
  543. fistp qword ptr [esi+8]
  544. mov ebx, [esi+8]
  545. or [esi], ebx
  546. mov ebx, [esi+12]
  547. or [esi+4], ebx
  548. fild qword ptr [esi]
  549. fstp qword ptr [esi]
  550. mov eax, esi
  551. add esi, 8
  552. }
  553. }
  554. __declspec ( naked ) void _asm_or_end(void) {}
  555. //---------------------------------------------------------------------------------------------------------------
  556. __declspec ( naked ) void _asm_and(void)
  557. {
  558. __asm
  559. {
  560. fld qword ptr [ebx]
  561. fld qword ptr [eax]
  562. fistp qword ptr [esi]
  563. fistp qword ptr [esi+8]
  564. mov ebx, [esi+8]
  565. and [esi], ebx
  566. mov ebx, [esi+12]
  567. and [esi+4], ebx
  568. fild qword ptr [esi]
  569. fstp qword ptr [esi]
  570. mov eax, esi
  571. add esi, 8
  572. }
  573. }
  574. __declspec ( naked ) void _asm_and_end(void) {}
  575. //---------------------------------------------------------------------------------------------------------------
  576. __declspec ( naked ) void _asm_uplus(void) // this is the same as doing nothing, it seems
  577. {
  578. #if 0
  579. __asm
  580. {
  581. mov ebx, nextBlock
  582. mov ecx, [eax]
  583. mov [ebx], ecx
  584. mov ecx, [eax+4]
  585. mov [ebx+4], ecx
  586. mov eax, ebx
  587. add ebx, 8
  588. mov nextBlock, ebx
  589. }
  590. #endif
  591. }
  592. __declspec ( naked ) void _asm_uplus_end(void) {}
  593. //---------------------------------------------------------------------------------------------------------------
  594. __declspec ( naked ) void _asm_uminus(void)
  595. {
  596. __asm
  597. {
  598. mov ecx, [eax]
  599. mov ebx, [eax+4]
  600. xor ebx, 0x80000000
  601. mov [esi], ecx
  602. mov [esi+4], ebx
  603. mov eax, esi
  604. add esi, 8
  605. }
  606. }
  607. __declspec ( naked ) void _asm_uminus_end(void) {}
  608. //---------------------------------------------------------------------------------------------------------------
  609. __declspec ( naked ) void _asm_sign(void)
  610. {
  611. __asm
  612. {
  613. mov ecx, [eax+4]
  614. shr ecx, 31
  615. fld dword ptr [g_signs+ecx*4]
  616. fstp qword ptr [esi]
  617. mov eax, esi
  618. add esi, 8
  619. }
  620. }
  621. __declspec ( naked ) void _asm_sign_end(void) {}
  622. //---------------------------------------------------------------------------------------------------------------
  623. __declspec ( naked ) void _asm_bnot(void)
  624. {
  625. __asm
  626. {
  627. fld qword ptr [eax]
  628. fabs
  629. fcomp qword ptr [g_closefact]
  630. fstsw ax
  631. shr eax, 6
  632. and eax, (1<<2)
  633. fld dword ptr [g_cmpaddtab+eax]
  634. fstp qword ptr [esi]
  635. mov eax, esi
  636. add esi, 8
  637. }
  638. }
  639. __declspec ( naked ) void _asm_bnot_end(void) {}
  640. //---------------------------------------------------------------------------------------------------------------
  641. __declspec ( naked ) void _asm_if(void)
  642. {
  643. __asm
  644. {
  645. fld qword ptr [eax]
  646. fabs
  647. fcomp qword ptr [g_closefact]
  648. fstsw ax
  649. shr eax, 6
  650. mov dword ptr [esi], 0FFFFFFFFh
  651. mov dword ptr [esi+4], 0FFFFFFFFh
  652. and eax, (1<<2)
  653. mov eax, [esi+eax]
  654. call eax // call the proper function
  655. // at this point, the return value will be in eax, as desired
  656. }
  657. }
  658. __declspec ( naked ) void _asm_if_end(void) {}
  659. //---------------------------------------------------------------------------------------------------------------
  660. __declspec ( naked ) void _asm_equal(void)
  661. {
  662. __asm
  663. {
  664. fld qword ptr [eax]
  665. fsub qword ptr [ebx]
  666. fabs
  667. fcomp qword ptr [g_closefact]
  668. fstsw ax
  669. shr eax, 6
  670. and eax, (1<<2)
  671. fld dword ptr [g_cmpaddtab+eax]
  672. fstp qword ptr [esi]
  673. mov eax, esi
  674. add esi, 8
  675. }
  676. }
  677. __declspec ( naked ) void _asm_equal_end(void) {}
  678. //---------------------------------------------------------------------------------------------------------------
  679. __declspec ( naked ) void _asm_below(void)
  680. {
  681. __asm
  682. {
  683. fld qword ptr [ebx]
  684. fcomp qword ptr [eax]
  685. fstsw ax
  686. shr eax, 6
  687. and eax, (1<<2)
  688. fld dword ptr [g_cmpaddtab+eax]
  689. fstp qword ptr [esi]
  690. mov eax, esi
  691. add esi, 8
  692. }
  693. }
  694. __declspec ( naked ) void _asm_below_end(void) {}
  695. //---------------------------------------------------------------------------------------------------------------
  696. __declspec ( naked ) void _asm_above(void)
  697. {
  698. __asm
  699. {
  700. fld qword ptr [eax]
  701. fcomp qword ptr [ebx]
  702. fstsw ax
  703. shr eax, 6
  704. and eax, (1<<2)
  705. fld dword ptr [g_cmpaddtab+eax]
  706. fstp qword ptr [esi]
  707. mov eax, esi
  708. add esi, 8
  709. }
  710. }
  711. __declspec ( naked ) void _asm_above_end(void) {}
  712. __declspec ( naked ) void _asm_min(void)
  713. {
  714. __asm
  715. {
  716. fld qword ptr [eax]
  717. fld qword ptr [ebx]
  718. fld st(1)
  719. fsub st(0), st(1)
  720. fabs // stack contains fabs(1-2),1,2
  721. fchs
  722. fadd
  723. fadd
  724. fmul dword ptr [g_half]
  725. fstp qword ptr [esi]
  726. mov eax, esi
  727. add esi, 8
  728. }
  729. }
  730. __declspec ( naked ) void _asm_min_end(void) {}
  731. __declspec ( naked ) void _asm_max(void)
  732. {
  733. __asm
  734. {
  735. fld qword ptr [eax]
  736. fld qword ptr [ebx]
  737. fld st(1)
  738. fsub st(0), st(1)
  739. fabs // stack contains fabs(1-2),1,2
  740. fadd
  741. fadd
  742. fmul dword ptr [g_half]
  743. fstp qword ptr [esi]
  744. mov eax, esi
  745. add esi, 8
  746. }
  747. }
  748. __declspec ( naked ) void _asm_max_end(void) {}