r_multiplier.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. /*
  2. LICENSE
  3. -------
  4. Copyright 2005 Nullsoft, Inc.
  5. All rights reserved.
  6. Redistribution and use in source and binary forms, with or without modification,
  7. are permitted provided that the following conditions are met:
  8. * Redistributions of source code must retain the above copyright notice,
  9. this list of conditions and the following disclaimer.
  10. * Redistributions in binary form must reproduce the above copyright notice,
  11. this list of conditions and the following disclaimer in the documentation
  12. and/or other materials provided with the distribution.
  13. * Neither the name of Nullsoft nor the names of its contributors may be used to
  14. endorse or promote products derived from this software without specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  16. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  19. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  20. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  21. IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  22. OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. #include <windows.h>
  25. #include <commctrl.h>
  26. #include "resource.h"
  27. #include "r_defs.h"
  28. #include "../Agave/Language/api_language.h"
  29. #ifndef LASER
  30. #define MD_XI 0
  31. #define MD_X8 1
  32. #define MD_X4 2
  33. #define MD_X2 3
  34. #define MD_X05 4
  35. #define MD_X025 5
  36. #define MD_X0125 6
  37. #define MD_XS 7
  38. // this will be the directory and APE name displayed in the AVS Editor
  39. #define MOD_NAME "Trans / Multiplier"
  40. #define C_THISCLASS C_MultiplierClass
  41. typedef struct {
  42. int ml;
  43. } apeconfig;
  44. class C_THISCLASS : public C_RBASE
  45. {
  46. protected:
  47. public:
  48. C_THISCLASS();
  49. virtual ~C_THISCLASS();
  50. virtual int render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h);
  51. virtual HWND conf(HINSTANCE hInstance, HWND hwndParent);
  52. virtual char *get_desc();
  53. virtual void load_config(unsigned char *data, int len);
  54. virtual int save_config(unsigned char *data);
  55. apeconfig config;
  56. HWND hwndDlg;
  57. };
  58. // global configuration dialog pointer
  59. static C_THISCLASS *g_ConfigThis;
  60. static HINSTANCE g_hDllInstance;
  61. // this is where we deal with the configuration screen
  62. static BOOL CALLBACK g_DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  63. {
  64. int id;
  65. switch (uMsg)
  66. {
  67. case WM_COMMAND:
  68. if (HIWORD(wParam) == BN_CLICKED) {
  69. id = LOWORD(wParam);
  70. switch (id) {
  71. case IDC_XI:
  72. g_ConfigThis->config.ml = MD_XI;
  73. break;
  74. case IDC_X8:
  75. g_ConfigThis->config.ml = MD_X8;
  76. break;
  77. case IDC_X4:
  78. g_ConfigThis->config.ml = MD_X4;
  79. break;
  80. case IDC_X2:
  81. g_ConfigThis->config.ml = MD_X2;
  82. break;
  83. case IDC_X05:
  84. g_ConfigThis->config.ml = MD_X05;
  85. break;
  86. case IDC_X025:
  87. g_ConfigThis->config.ml = MD_X025;
  88. break;
  89. case IDC_X0125:
  90. g_ConfigThis->config.ml = MD_X0125;
  91. break;
  92. case IDC_XS:
  93. g_ConfigThis->config.ml = MD_XS;
  94. break;
  95. }
  96. }
  97. return 0;
  98. case WM_INITDIALOG:
  99. g_ConfigThis->hwndDlg = hwndDlg;
  100. switch (g_ConfigThis->config.ml) {
  101. case MD_XI:
  102. id = IDC_XI;
  103. break;
  104. case MD_X8:
  105. id = IDC_X8;
  106. break;
  107. case MD_X4:
  108. id = IDC_X4;
  109. break;
  110. case MD_X2:
  111. id = IDC_X2;
  112. break;
  113. case MD_X05:
  114. id = IDC_X05;
  115. break;
  116. case MD_X025:
  117. id = IDC_X025;
  118. break;
  119. case MD_X0125:
  120. id = IDC_X0125;
  121. break;
  122. case MD_XS:
  123. id = IDC_XS;
  124. break;
  125. }
  126. SendMessage(GetDlgItem(hwndDlg, id), BM_SETCHECK, BST_CHECKED, 0);
  127. return 1;
  128. case WM_DESTROY:
  129. return 1;
  130. }
  131. return 0;
  132. }
  133. // set up default configuration
  134. C_THISCLASS::C_THISCLASS()
  135. {
  136. memset(&config, 0, sizeof(apeconfig));
  137. config.ml = MD_X2;
  138. }
  139. // virtual destructor
  140. C_THISCLASS::~C_THISCLASS()
  141. {
  142. }
  143. int C_THISCLASS::render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h)
  144. {
  145. if (isBeat&0x80000000) return 0;
  146. int b,c;
  147. __int64 mask;
  148. c = w*h;
  149. switch (config.ml) {
  150. case MD_XI:
  151. __asm {
  152. mov ebx, framebuffer;
  153. mov ecx, c;
  154. mov edx, b;
  155. lp0:
  156. xor eax, eax;
  157. dec ecx;
  158. test ecx, ecx;
  159. jz end;
  160. mov eax, dword ptr [ebx+ecx*4];
  161. test eax, eax;
  162. jz sk0;
  163. mov eax, 0xFFFFFF;
  164. sk0:
  165. mov [ebx+ecx*4], eax;
  166. jmp lp0;
  167. }
  168. break;
  169. case MD_XS:
  170. __asm {
  171. mov ebx, framebuffer;
  172. mov ecx, c;
  173. mov edx, b;
  174. lp9:
  175. xor eax, eax;
  176. dec ecx;
  177. test ecx, ecx;
  178. jz end;
  179. mov eax, dword ptr [ebx+ecx*4];
  180. cmp eax, 0xFFFFFF;
  181. je sk9;
  182. mov eax, 0x000000;
  183. sk9:
  184. mov [ebx+ecx*4], eax;
  185. jmp lp9;
  186. }
  187. break;
  188. case MD_X8:
  189. c = w*h/2;
  190. __asm {
  191. mov ebx, framebuffer;
  192. mov ecx, c;
  193. lp1:
  194. movq mm0, [ebx];
  195. paddusb mm0, mm0;
  196. paddusb mm0, mm0;
  197. paddusb mm0, mm0;
  198. movq [ebx], mm0;
  199. add ebx, 8;
  200. dec ecx;
  201. test ecx, ecx;
  202. jz end;
  203. jmp lp1;
  204. }
  205. break;
  206. case MD_X4:
  207. c = w*h/2;
  208. __asm {
  209. mov ebx, framebuffer;
  210. mov ecx, c;
  211. lp2:
  212. movq mm0, [ebx];
  213. paddusb mm0, mm0;
  214. paddusb mm0, mm0;
  215. movq [ebx], mm0;
  216. add ebx, 8;
  217. dec ecx;
  218. test ecx, ecx;
  219. jz end;
  220. jmp lp2;
  221. }
  222. break;
  223. case MD_X2:
  224. c = w*h/2;
  225. __asm {
  226. mov ebx, framebuffer;
  227. mov ecx, c;
  228. lp3:
  229. movq mm0, [ebx];
  230. paddusb mm0, mm0;
  231. movq [ebx], mm0;
  232. add ebx, 8;
  233. dec ecx;
  234. test ecx, ecx;
  235. jz end;
  236. jmp lp3;
  237. }
  238. break;
  239. case MD_X05:
  240. c = w*h/2;
  241. mask = 0x7F7F7F7F7F7F7F7F;
  242. __asm {
  243. mov ebx, framebuffer;
  244. mov ecx, c;
  245. movq mm1, mask;
  246. lp4:
  247. movq mm0, [ebx];
  248. psrlq mm0, 1;
  249. pand mm0, mm1;
  250. movq [ebx], mm0;
  251. add ebx, 8;
  252. dec ecx;
  253. test ecx, ecx;
  254. jz end;
  255. jmp lp4;
  256. }
  257. break;
  258. case MD_X025:
  259. c = w*h/2;
  260. mask = 0x3F3F3F3F3F3F3F3F;
  261. __asm {
  262. mov ebx, framebuffer;
  263. mov ecx, c;
  264. movq mm1, mask;
  265. lp5:
  266. movq mm0, [ebx];
  267. psrlq mm0, 2;
  268. pand mm0, mm1;
  269. movq [ebx], mm0;
  270. add ebx, 8;
  271. dec ecx;
  272. test ecx, ecx;
  273. jz end;
  274. jmp lp5;
  275. }
  276. break;
  277. case MD_X0125:
  278. c = w*h/2;
  279. mask = 0x1F1F1F1F1F1F1F1F;
  280. __asm {
  281. mov ebx, framebuffer;
  282. mov ecx, c;
  283. movq mm1, mask;
  284. lp6:
  285. movq mm0, [ebx];
  286. psrlq mm0, 3;
  287. pand mm0, mm1;
  288. movq [ebx], mm0;
  289. add ebx, 8;
  290. dec ecx;
  291. test ecx, ecx;
  292. jz end;
  293. jmp lp6;
  294. }
  295. break;
  296. }
  297. end:
  298. __asm emms;
  299. return 0;
  300. }
  301. HWND C_THISCLASS::conf(HINSTANCE hInstance, HWND hwndParent)
  302. {
  303. g_ConfigThis = this;
  304. return WASABI_API_CREATEDIALOG(IDD_CFG_MULT, hwndParent, (DLGPROC)g_DlgProc);
  305. }
  306. char *C_THISCLASS::get_desc(void)
  307. {
  308. static char desc[128]; return (!desc[0]?WASABI_API_LNGSTRING_BUF(IDS_TRANS_MULTIPLIER,desc,128):desc);
  309. }
  310. void C_THISCLASS::load_config(unsigned char *data, int len)
  311. {
  312. if (len == sizeof(apeconfig))
  313. memcpy(&this->config, data, len);
  314. else
  315. memset(&this->config, 0, sizeof(apeconfig));
  316. }
  317. int C_THISCLASS::save_config(unsigned char *data)
  318. {
  319. memcpy(data, &this->config, sizeof(apeconfig));
  320. return sizeof(apeconfig);
  321. }
  322. C_RBASE *R_Multiplier(char *desc)
  323. {
  324. if (desc) {
  325. strcpy(desc,MOD_NAME);
  326. return NULL;
  327. }
  328. return (C_RBASE *) new C_THISCLASS();
  329. }
  330. #endif