Firmware for MNT ZZ9000 graphics and ARM coprocessor card for Amiga computers.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gfx.h 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. /*
  2. * MNT ZZ9000 Amiga Graphics and Coprocessor Card Operating System (ZZ9000OS)
  3. *
  4. * Copyright (C) 2019, Lukas F. Hartmann <lukas@mntre.com>
  5. * MNT Research GmbH, Berlin
  6. * https://mntre.com
  7. *
  8. * More Info: https://mntre.com/zz9000
  9. *
  10. * SPDX-License-Identifier: GPL-3.0-or-later
  11. * GNU General Public License v3.0 or later
  12. *
  13. * https://spdx.org/licenses/GPL-3.0-or-later.html
  14. *
  15. */
  16. #include <stdint.h>
  17. typedef struct Vec2 {
  18. float x;
  19. float y;
  20. } Vec2;
  21. void set_fb(uint32_t* fb_, uint32_t pitch);
  22. void update_hw_sprite(uint8_t *data, uint32_t *colors, uint16_t w, uint16_t h);
  23. void clip_hw_sprite(int16_t offset_x, int16_t offset_y);
  24. void clear_hw_sprite();
  25. void horizline(uint16_t x1, uint16_t x2, uint16_t y, uint32_t color);
  26. void fill_rect(uint16_t rect_x1, uint16_t rect_y1, uint16_t w, uint16_t h, uint32_t rect_rgb, uint32_t color_format, uint8_t mask);
  27. void fill_rect_solid(uint16_t rect_x1, uint16_t rect_y1, uint16_t w, uint16_t h, uint32_t rect_rgb, uint32_t color_format);
  28. void fill_rect8(uint16_t rect_x1, uint16_t rect_y1, uint16_t rect_x2, uint16_t rect_y2, uint8_t rect_rgb);
  29. void fill_rect16(uint16_t rect_x1, uint16_t rect_y1, uint16_t rect_x2, uint16_t rect_y2, uint16_t rect_rgb);
  30. void fill_rect32(uint16_t rect_x1, uint16_t rect_y1, uint16_t rect_x2, uint16_t rect_y2, uint32_t rect_rgb);
  31. void copy_rect(uint16_t rect_x1, uint16_t rect_y1, uint16_t w, uint16_t h, uint16_t rect_sx, uint16_t rect_sy, uint32_t color_format, uint32_t* sp_src, uint32_t src_pitch, uint8_t mask);
  32. void copy_rect_nomask(uint16_t rect_x1, uint16_t rect_y1, uint16_t w, uint16_t h, uint16_t rect_sx, uint16_t rect_sy, uint32_t color_format, uint32_t* sp_src, uint32_t src_pitch, uint8_t draw_mode);
  33. void copy_rect8(uint16_t rect_x1, uint16_t rect_y1, uint16_t rect_x2, uint16_t rect_y2, uint16_t rect_sx, uint16_t rect_sy);
  34. void copy_rect16(uint16_t rect_x1, uint16_t rect_y1, uint16_t rect_x2, uint16_t rect_y2, uint16_t rect_sx, uint16_t rect_sy);
  35. void copy_rect32(uint16_t rect_x1, uint16_t rect_y1, uint16_t rect_x2, uint16_t rect_y2, uint16_t rect_sx, uint16_t rect_sy);
  36. void fill_template(uint32_t bpp, uint16_t rect_x1, uint16_t rect_y1, uint16_t rect_x2, uint16_t rect_y2,
  37. uint8_t draw_mode, uint8_t mask, uint32_t fg_color, uint32_t bg_color, uint16_t x_offset, uint16_t y_offset, uint8_t* tmpl_data, uint16_t templ_pitch, uint16_t loop_rows);
  38. void template_fill_rect(uint32_t color_format, uint16_t rect_x1, uint16_t rect_y1, uint16_t w, uint16_t h,
  39. uint8_t draw_mode, uint8_t mask, uint32_t fg_color, uint32_t bg_color,
  40. uint16_t x_offset, uint16_t y_offset,
  41. uint8_t *tmpl_data, uint16_t tmpl_pitch);
  42. void pattern_fill_rect(uint32_t color_format, uint16_t rect_x1, uint16_t rect_y1, uint16_t w, uint16_t h,
  43. uint8_t draw_mode, uint8_t mask, uint32_t fg_color, uint32_t bg_color,
  44. uint16_t x_offset, uint16_t y_offset,
  45. uint8_t *tmpl_data, uint16_t tmpl_pitch, uint16_t loop_rows);
  46. void draw_line(int16_t rect_x1, int16_t rect_y1, int16_t rect_x2, int16_t rect_y2, uint16_t len, uint16_t pattern, uint16_t pattern_offset, uint32_t fg_color, uint32_t bg_color, uint32_t color_format, uint8_t mask, uint8_t draw_mode);
  47. void draw_line_solid(int16_t rect_x1, int16_t rect_y1, int16_t rect_x2, int16_t rect_y2, uint16_t len, uint32_t fg_color, uint32_t color_format);
  48. void p2c_rect(int16_t sx, int16_t sy, int16_t dx, int16_t dy, int16_t w, int16_t h, uint16_t sh, uint8_t draw_mode, uint8_t planes, uint8_t mask, uint8_t layer_mask, uint16_t src_line_pitch, uint8_t *bmp_data_src);
  49. void p2d_rect(int16_t sx, int16_t sy, int16_t dx, int16_t dy, int16_t w, int16_t h, uint16_t sh, uint8_t draw_mode, uint8_t planes, uint8_t mask, uint8_t layer_mask, uint32_t color_mask, uint16_t src_line_pitch, uint8_t *bmp_data_src, uint32_t color_format);
  50. void invert_rect(uint16_t rect_x1, uint16_t rect_y1, uint16_t w, uint16_t h, uint8_t mask, uint32_t color_format);
  51. #define MNTVA_COLOR_8BIT 0
  52. #define MNTVA_COLOR_16BIT565 1
  53. #define MNTVA_COLOR_32BIT 2
  54. #define MNTVA_COLOR_1BIT 3
  55. #define MNTVA_COLOR_15BIT 4
  56. // see http://amigadev.elowar.com/read/ADCD_2.1/Libraries_Manual_guide/node0351.html
  57. #define JAM1 0 /* jam 1 color into raster */
  58. #define JAM2 1 /* jam 2 colors into raster */
  59. #define COMPLEMENT 2 /* XOR bits into raster */
  60. #define INVERSVID 4 /* inverse video for drawing modes */
  61. // Graphics minterm drawing modes
  62. enum gfx_minterm_modes {
  63. MINTERM_FALSE,
  64. MINTERM_NOR,
  65. MINTERM_ONLYDST,
  66. MINTERM_NOTSRC,
  67. MINTERM_ONLYSRC,
  68. MINTERM_INVERT,
  69. MINTERM_EOR,
  70. MINTERM_NAND,
  71. MINTERM_AND,
  72. MINTERM_NEOR,
  73. MINTERM_DST,
  74. MINTERM_NOTONLYSRC,
  75. MINTERM_SRC,
  76. MINTERM_NOTONLYDST,
  77. MINTERM_OR,
  78. MINTERM_TRUE,
  79. };
  80. /* Macros for keeping gfx.c a bit more tidy */
  81. #define SET_FG_PIXEL8(a) \
  82. ((uint8_t *)dp)[x+a] = u8_fg;
  83. #define SET_FG_PIXEL16(a) \
  84. ((uint16_t *)dp)[x+a] = fg_color;
  85. #define SET_FG_PIXEL32(a) \
  86. dp[x+a] = fg_color;
  87. #define SET_BG_PIXEL8(a) \
  88. ((uint8_t *)dp)[x+a] = u8_bg;
  89. #define SET_BG_PIXEL16(a) \
  90. ((uint16_t *)dp)[x+a] = bg_color;
  91. #define SET_BG_PIXEL32(a) \
  92. dp[x+a] = bg_color;
  93. #define SET_FG_PIXEL8_MASK(a) \
  94. ((uint8_t *)dp)[x + a] = u8_fg ^ (((uint8_t *)dp)[x + a] & (mask ^ 0xFF));
  95. #define SET_BG_PIXEL8_MASK(a) \
  96. ((uint8_t *)dp)[x + a] = u8_bg ^ (((uint8_t *)dp)[x + a] & (mask ^ 0xFF));
  97. #define SET_FG_PIXEL16_MASK(a) \
  98. ((uint16_t *)dp)[x + a] = fg_color ^ (((uint16_t *)dp)[x + a] & (color_mask ^ 0xFFFF));
  99. #define SET_FG_PIXEL32_MASK(a) \
  100. dp[x + a] = fg_color ^ (dp[x + a] & (color_mask ^ 0xFFFFFFFF));
  101. #define SET_FG_PIXEL \
  102. switch (color_format) { \
  103. case MNTVA_COLOR_8BIT: \
  104. SET_FG_PIXEL8(0); break; \
  105. case MNTVA_COLOR_16BIT565: \
  106. SET_FG_PIXEL16(0); break; \
  107. case MNTVA_COLOR_32BIT: \
  108. SET_FG_PIXEL32(0); break; \
  109. }
  110. #define SET_FG_PIXEL_MASK \
  111. switch (color_format) { \
  112. case MNTVA_COLOR_8BIT: \
  113. SET_FG_PIXEL8_MASK(0); break; \
  114. case MNTVA_COLOR_16BIT565: \
  115. SET_FG_PIXEL16(0); break; \
  116. case MNTVA_COLOR_32BIT: \
  117. SET_FG_PIXEL32(0); break; \
  118. }
  119. #define SET_BG_PIXEL \
  120. switch (color_format) { \
  121. case MNTVA_COLOR_8BIT: \
  122. SET_BG_PIXEL8(0); break; \
  123. case MNTVA_COLOR_16BIT565: \
  124. SET_BG_PIXEL16(0); break; \
  125. case MNTVA_COLOR_32BIT: \
  126. SET_BG_PIXEL32(0); break; \
  127. }
  128. #define SET_BG_PIXEL_MASK \
  129. switch (color_format) { \
  130. case MNTVA_COLOR_8BIT: \
  131. SET_BG_PIXEL8_MASK(0); break; \
  132. case MNTVA_COLOR_16BIT565: \
  133. SET_BG_PIXEL16(0); break; \
  134. case MNTVA_COLOR_32BIT: \
  135. SET_BG_PIXEL32(0); break; \
  136. }
  137. #define SET_FG_PIXELS \
  138. switch (color_format) { \
  139. case MNTVA_COLOR_8BIT: \
  140. if (cur_byte & 0x80) SET_FG_PIXEL8(0); \
  141. if (cur_byte & 0x40) SET_FG_PIXEL8(1); \
  142. if (cur_byte & 0x20) SET_FG_PIXEL8(2); \
  143. if (cur_byte & 0x10) SET_FG_PIXEL8(3); \
  144. if (cur_byte & 0x08) SET_FG_PIXEL8(4); \
  145. if (cur_byte & 0x04) SET_FG_PIXEL8(5); \
  146. if (cur_byte & 0x02) SET_FG_PIXEL8(6); \
  147. if (cur_byte & 0x01) SET_FG_PIXEL8(7); \
  148. break; \
  149. case MNTVA_COLOR_16BIT565: \
  150. if (cur_byte & 0x80) SET_FG_PIXEL16(0); \
  151. if (cur_byte & 0x40) SET_FG_PIXEL16(1); \
  152. if (cur_byte & 0x20) SET_FG_PIXEL16(2); \
  153. if (cur_byte & 0x10) SET_FG_PIXEL16(3); \
  154. if (cur_byte & 0x08) SET_FG_PIXEL16(4); \
  155. if (cur_byte & 0x04) SET_FG_PIXEL16(5); \
  156. if (cur_byte & 0x02) SET_FG_PIXEL16(6); \
  157. if (cur_byte & 0x01) SET_FG_PIXEL16(7); \
  158. break; \
  159. case MNTVA_COLOR_32BIT: \
  160. if (cur_byte & 0x80) SET_FG_PIXEL32(0); \
  161. if (cur_byte & 0x40) SET_FG_PIXEL32(1); \
  162. if (cur_byte & 0x20) SET_FG_PIXEL32(2); \
  163. if (cur_byte & 0x10) SET_FG_PIXEL32(3); \
  164. if (cur_byte & 0x08) SET_FG_PIXEL32(4); \
  165. if (cur_byte & 0x04) SET_FG_PIXEL32(5); \
  166. if (cur_byte & 0x02) SET_FG_PIXEL32(6); \
  167. if (cur_byte & 0x01) SET_FG_PIXEL32(7); \
  168. break; \
  169. }
  170. #define SET_FG_PIXELS_MASK \
  171. switch (color_format) { \
  172. case MNTVA_COLOR_8BIT: \
  173. if (cur_byte & 0x80) SET_FG_PIXEL8_MASK(0); \
  174. if (cur_byte & 0x40) SET_FG_PIXEL8_MASK(1); \
  175. if (cur_byte & 0x20) SET_FG_PIXEL8_MASK(2); \
  176. if (cur_byte & 0x10) SET_FG_PIXEL8_MASK(3); \
  177. if (cur_byte & 0x08) SET_FG_PIXEL8_MASK(4); \
  178. if (cur_byte & 0x04) SET_FG_PIXEL8_MASK(5); \
  179. if (cur_byte & 0x02) SET_FG_PIXEL8_MASK(6); \
  180. if (cur_byte & 0x01) SET_FG_PIXEL8_MASK(7); \
  181. break; \
  182. case MNTVA_COLOR_16BIT565: \
  183. if (cur_byte & 0x80) SET_FG_PIXEL16(0); \
  184. if (cur_byte & 0x40) SET_FG_PIXEL16(1); \
  185. if (cur_byte & 0x20) SET_FG_PIXEL16(2); \
  186. if (cur_byte & 0x10) SET_FG_PIXEL16(3); \
  187. if (cur_byte & 0x08) SET_FG_PIXEL16(4); \
  188. if (cur_byte & 0x04) SET_FG_PIXEL16(5); \
  189. if (cur_byte & 0x02) SET_FG_PIXEL16(6); \
  190. if (cur_byte & 0x01) SET_FG_PIXEL16(7); \
  191. break; \
  192. case MNTVA_COLOR_32BIT: \
  193. if (cur_byte & 0x80) SET_FG_PIXEL32(0); \
  194. if (cur_byte & 0x40) SET_FG_PIXEL32(1); \
  195. if (cur_byte & 0x20) SET_FG_PIXEL32(2); \
  196. if (cur_byte & 0x10) SET_FG_PIXEL32(3); \
  197. if (cur_byte & 0x08) SET_FG_PIXEL32(4); \
  198. if (cur_byte & 0x04) SET_FG_PIXEL32(5); \
  199. if (cur_byte & 0x02) SET_FG_PIXEL32(6); \
  200. if (cur_byte & 0x01) SET_FG_PIXEL32(7); \
  201. break; \
  202. }
  203. #define SET_FG_OR_BG_PIXELS \
  204. switch (color_format) { \
  205. case MNTVA_COLOR_8BIT: \
  206. if (cur_byte & 0x80) SET_FG_PIXEL8(0) else SET_BG_PIXEL8(0) \
  207. if (cur_byte & 0x40) SET_FG_PIXEL8(1) else SET_BG_PIXEL8(1) \
  208. if (cur_byte & 0x20) SET_FG_PIXEL8(2) else SET_BG_PIXEL8(2) \
  209. if (cur_byte & 0x10) SET_FG_PIXEL8(3) else SET_BG_PIXEL8(3) \
  210. if (cur_byte & 0x08) SET_FG_PIXEL8(4) else SET_BG_PIXEL8(4) \
  211. if (cur_byte & 0x04) SET_FG_PIXEL8(5) else SET_BG_PIXEL8(5) \
  212. if (cur_byte & 0x02) SET_FG_PIXEL8(6) else SET_BG_PIXEL8(6) \
  213. if (cur_byte & 0x01) SET_FG_PIXEL8(7) else SET_BG_PIXEL8(7) \
  214. break; \
  215. case MNTVA_COLOR_16BIT565: \
  216. if (cur_byte & 0x80) SET_FG_PIXEL16(0) else SET_BG_PIXEL16(0) \
  217. if (cur_byte & 0x40) SET_FG_PIXEL16(1) else SET_BG_PIXEL16(1) \
  218. if (cur_byte & 0x20) SET_FG_PIXEL16(2) else SET_BG_PIXEL16(2) \
  219. if (cur_byte & 0x10) SET_FG_PIXEL16(3) else SET_BG_PIXEL16(3) \
  220. if (cur_byte & 0x08) SET_FG_PIXEL16(4) else SET_BG_PIXEL16(4) \
  221. if (cur_byte & 0x04) SET_FG_PIXEL16(5) else SET_BG_PIXEL16(5) \
  222. if (cur_byte & 0x02) SET_FG_PIXEL16(6) else SET_BG_PIXEL16(6) \
  223. if (cur_byte & 0x01) SET_FG_PIXEL16(7) else SET_BG_PIXEL16(7) \
  224. break; \
  225. case MNTVA_COLOR_32BIT: \
  226. if (cur_byte & 0x80) SET_FG_PIXEL32(0) else SET_BG_PIXEL32(0) \
  227. if (cur_byte & 0x40) SET_FG_PIXEL32(1) else SET_BG_PIXEL32(1) \
  228. if (cur_byte & 0x20) SET_FG_PIXEL32(2) else SET_BG_PIXEL32(2) \
  229. if (cur_byte & 0x10) SET_FG_PIXEL32(3) else SET_BG_PIXEL32(3) \
  230. if (cur_byte & 0x08) SET_FG_PIXEL32(4) else SET_BG_PIXEL32(4) \
  231. if (cur_byte & 0x04) SET_FG_PIXEL32(5) else SET_BG_PIXEL32(5) \
  232. if (cur_byte & 0x02) SET_FG_PIXEL32(6) else SET_BG_PIXEL32(6) \
  233. if (cur_byte & 0x01) SET_FG_PIXEL32(7) else SET_BG_PIXEL32(7) \
  234. break; \
  235. }
  236. #define SET_FG_OR_BG_PIXELS_MASK \
  237. switch (color_format) { \
  238. case MNTVA_COLOR_8BIT: \
  239. if (cur_byte & 0x80) SET_FG_PIXEL8_MASK(0) else SET_BG_PIXEL8_MASK(0) \
  240. if (cur_byte & 0x40) SET_FG_PIXEL8_MASK(1) else SET_BG_PIXEL8_MASK(1) \
  241. if (cur_byte & 0x20) SET_FG_PIXEL8_MASK(2) else SET_BG_PIXEL8_MASK(2) \
  242. if (cur_byte & 0x10) SET_FG_PIXEL8_MASK(3) else SET_BG_PIXEL8_MASK(3) \
  243. if (cur_byte & 0x08) SET_FG_PIXEL8_MASK(4) else SET_BG_PIXEL8_MASK(4) \
  244. if (cur_byte & 0x04) SET_FG_PIXEL8_MASK(5) else SET_BG_PIXEL8_MASK(5) \
  245. if (cur_byte & 0x02) SET_FG_PIXEL8_MASK(6) else SET_BG_PIXEL8_MASK(6) \
  246. if (cur_byte & 0x01) SET_FG_PIXEL8_MASK(7) else SET_BG_PIXEL8_MASK(7) \
  247. break; \
  248. case MNTVA_COLOR_16BIT565: \
  249. if (cur_byte & 0x80) SET_FG_PIXEL16(0) else SET_BG_PIXEL16(0) \
  250. if (cur_byte & 0x40) SET_FG_PIXEL16(1) else SET_BG_PIXEL16(1) \
  251. if (cur_byte & 0x20) SET_FG_PIXEL16(2) else SET_BG_PIXEL16(2) \
  252. if (cur_byte & 0x10) SET_FG_PIXEL16(3) else SET_BG_PIXEL16(3) \
  253. if (cur_byte & 0x08) SET_FG_PIXEL16(4) else SET_BG_PIXEL16(4) \
  254. if (cur_byte & 0x04) SET_FG_PIXEL16(5) else SET_BG_PIXEL16(5) \
  255. if (cur_byte & 0x02) SET_FG_PIXEL16(6) else SET_BG_PIXEL16(6) \
  256. if (cur_byte & 0x01) SET_FG_PIXEL16(7) else SET_BG_PIXEL16(7) \
  257. break; \
  258. case MNTVA_COLOR_32BIT: \
  259. if (cur_byte & 0x80) SET_FG_PIXEL32(0) else SET_BG_PIXEL32(0) \
  260. if (cur_byte & 0x40) SET_FG_PIXEL32(1) else SET_BG_PIXEL32(1) \
  261. if (cur_byte & 0x20) SET_FG_PIXEL32(2) else SET_BG_PIXEL32(2) \
  262. if (cur_byte & 0x10) SET_FG_PIXEL32(3) else SET_BG_PIXEL32(3) \
  263. if (cur_byte & 0x08) SET_FG_PIXEL32(4) else SET_BG_PIXEL32(4) \
  264. if (cur_byte & 0x04) SET_FG_PIXEL32(5) else SET_BG_PIXEL32(5) \
  265. if (cur_byte & 0x02) SET_FG_PIXEL32(6) else SET_BG_PIXEL32(6) \
  266. if (cur_byte & 0x01) SET_FG_PIXEL32(7) else SET_BG_PIXEL32(7) \
  267. break; \
  268. }
  269. #define INVERT_PIXEL \
  270. switch (color_format) { \
  271. case MNTVA_COLOR_8BIT: \
  272. ((uint8_t *)dp)[x] ^= mask; break; \
  273. case MNTVA_COLOR_16BIT565: \
  274. ((uint16_t *)dp)[x] ^= 0xFFFF; break; \
  275. case MNTVA_COLOR_32BIT: \
  276. dp[x] ^= 0xFFFFFFFF; break; \
  277. }
  278. #define INVERT_PIXEL_FG \
  279. switch (color_format) { \
  280. case MNTVA_COLOR_8BIT: \
  281. ((uint8_t *)dp)[x] = u8_fg ^ 0xFF; break; \
  282. case MNTVA_COLOR_16BIT565: \
  283. ((uint16_t *)dp)[x] ^= fg_color; break; \
  284. case MNTVA_COLOR_32BIT: \
  285. dp[x] ^= fg_color; break; \
  286. }
  287. #define INVERT_PIXEL_BG \
  288. switch (color_format) { \
  289. case MNTVA_COLOR_8BIT: \
  290. ((uint8_t *)dp)[x] ^= u8_bg; break; \
  291. case MNTVA_COLOR_16BIT565: \
  292. ((uint16_t *)dp)[x] ^= bg_color; break; \
  293. case MNTVA_COLOR_32BIT: \
  294. dp[x] ^= bg_color; break; \
  295. }
  296. #define INVERT_PIXELS \
  297. switch (color_format) { \
  298. case MNTVA_COLOR_8BIT: \
  299. if (cur_byte & 0x80) ((uint8_t *)dp)[x] ^= mask; \
  300. if (cur_byte & 0x40) ((uint8_t *)dp)[x+1] ^= mask; \
  301. if (cur_byte & 0x20) ((uint8_t *)dp)[x+2] ^= mask; \
  302. if (cur_byte & 0x10) ((uint8_t *)dp)[x+3] ^= mask; \
  303. if (cur_byte & 0x08) ((uint8_t *)dp)[x+4] ^= mask; \
  304. if (cur_byte & 0x04) ((uint8_t *)dp)[x+5] ^= mask; \
  305. if (cur_byte & 0x02) ((uint8_t *)dp)[x+6] ^= mask; \
  306. if (cur_byte & 0x01) ((uint8_t *)dp)[x+7] ^= mask; \
  307. break; \
  308. case MNTVA_COLOR_16BIT565: \
  309. if (cur_byte & 0x80) ((uint16_t *)dp)[x] ^= 0xFFFF; \
  310. if (cur_byte & 0x40) ((uint16_t *)dp)[x+1] ^= 0xFFFF; \
  311. if (cur_byte & 0x20) ((uint16_t *)dp)[x+2] ^= 0xFFFF; \
  312. if (cur_byte & 0x10) ((uint16_t *)dp)[x+3] ^= 0xFFFF; \
  313. if (cur_byte & 0x08) ((uint16_t *)dp)[x+4] ^= 0xFFFF; \
  314. if (cur_byte & 0x04) ((uint16_t *)dp)[x+5] ^= 0xFFFF; \
  315. if (cur_byte & 0x02) ((uint16_t *)dp)[x+6] ^= 0xFFFF; \
  316. if (cur_byte & 0x01) ((uint16_t *)dp)[x+7] ^= 0xFFFF; \
  317. break; \
  318. case MNTVA_COLOR_32BIT: \
  319. if (cur_byte & 0x80) dp[x] ^= 0xFFFFFFFF; \
  320. if (cur_byte & 0x40) dp[x+1] ^= 0xFFFFFFFF; \
  321. if (cur_byte & 0x20) dp[x+2] ^= 0xFFFFFFFF; \
  322. if (cur_byte & 0x10) dp[x+3] ^= 0xFFFFFFFF; \
  323. if (cur_byte & 0x08) dp[x+4] ^= 0xFFFFFFFF; \
  324. if (cur_byte & 0x04) dp[x+5] ^= 0xFFFFFFFF; \
  325. if (cur_byte & 0x02) dp[x+6] ^= 0xFFFFFFFF; \
  326. if (cur_byte & 0x01) dp[x+7] ^= 0xFFFFFFFF; \
  327. break; \
  328. }
  329. #define HANDLE_MINTERM_PIXEL_8(s, d) \
  330. switch(draw_mode) {\
  331. case MINTERM_NOR: \
  332. s &= ~(d); \
  333. SET_FG_PIXEL8_MASK(0); break; \
  334. case MINTERM_ONLYDST: \
  335. d = d & ~(s); break; \
  336. case MINTERM_NOTSRC: \
  337. SET_FG_PIXEL8_MASK(0); break; \
  338. case MINTERM_ONLYSRC: \
  339. s &= (d ^ 0xFF); \
  340. SET_FG_PIXEL8_MASK(0); break; \
  341. case MINTERM_INVERT: \
  342. d ^= 0xFF; break; \
  343. case MINTERM_EOR: \
  344. d ^= s; break; \
  345. case MINTERM_NAND: \
  346. s = ~(d & ~(s)) & mask; \
  347. SET_FG_PIXEL8_MASK(0); break; \
  348. case MINTERM_AND: \
  349. s &= d; \
  350. SET_FG_PIXEL8_MASK(0); break; \
  351. case MINTERM_NEOR: \
  352. d ^= (s & mask); break; \
  353. case MINTERM_DST: /* This one does nothing. */ \
  354. return; break; \
  355. case MINTERM_NOTONLYSRC: \
  356. d |= (s & mask); break; \
  357. case MINTERM_SRC: \
  358. SET_FG_PIXEL8_MASK(0); break; \
  359. case MINTERM_NOTONLYDST: \
  360. s = ~(d & s) & mask; \
  361. SET_FG_PIXEL8_MASK(0); break; \
  362. case MINTERM_OR: \
  363. d |= (s & mask); break; \
  364. }
  365. #define HANDLE_MINTERM_PIXEL_16_32(s, d) \
  366. switch (draw_mode) { \
  367. case MINTERM_NOR: \
  368. switch (color_format) { \
  369. case MNTVA_COLOR_16BIT565: \
  370. s &= ~(((uint16_t *)d)[x]); \
  371. SET_FG_PIXEL16_MASK(0); break; \
  372. case MNTVA_COLOR_32BIT: \
  373. s &= ~(d[x]); \
  374. SET_FG_PIXEL32_MASK(0); break; \
  375. } break; \
  376. case MINTERM_ONLYDST: \
  377. switch (color_format) { \
  378. case MNTVA_COLOR_16BIT565: \
  379. ((uint16_t *)d)[x] = ((uint16_t *)d)[x] & ~(s); break; \
  380. case MNTVA_COLOR_32BIT: \
  381. d[x] = d[x] & ~(s); break; \
  382. } break; \
  383. case MINTERM_ONLYSRC: \
  384. switch (color_format) { \
  385. case MNTVA_COLOR_16BIT565: \
  386. s &= (((uint16_t *)d)[x] ^ 0xFFFF); \
  387. SET_FG_PIXEL16_MASK(0); break; \
  388. case MNTVA_COLOR_32BIT: \
  389. s &= (d[x] ^ 0x00FFFFFF); \
  390. SET_FG_PIXEL32_MASK(0); break; \
  391. } break; \
  392. case MINTERM_INVERT: \
  393. switch (color_format) { \
  394. case MNTVA_COLOR_16BIT565: \
  395. ((uint16_t *)d)[x] ^= 0xFFFF; break; \
  396. case MNTVA_COLOR_32BIT: \
  397. d[x] ^= 0x00FFFFFF; break; \
  398. } break; \
  399. case MINTERM_EOR: \
  400. switch (color_format) { \
  401. case MNTVA_COLOR_16BIT565: \
  402. ((uint16_t *)d)[x] ^= s; break; \
  403. case MNTVA_COLOR_32BIT: \
  404. d[x] ^= s; break; \
  405. } break; \
  406. case MINTERM_NAND: \
  407. switch (color_format) { \
  408. case MNTVA_COLOR_16BIT565: \
  409. s = ~(((uint16_t *)d)[x] | ~(s)) & color_mask; \
  410. SET_FG_PIXEL16_MASK(0); break; \
  411. case MNTVA_COLOR_32BIT: \
  412. s = ~(d[x] | ~(s)) & color_mask; \
  413. SET_FG_PIXEL32_MASK(0); break; \
  414. } break; \
  415. case MINTERM_AND: \
  416. switch (color_format) { \
  417. case MNTVA_COLOR_16BIT565: \
  418. s &= ((uint16_t *)d)[x]; \
  419. SET_FG_PIXEL16_MASK(0); break; \
  420. case MNTVA_COLOR_32BIT: \
  421. s &= d[x]; \
  422. SET_FG_PIXEL32_MASK(0); break; \
  423. } break; \
  424. case MINTERM_NEOR: \
  425. switch (color_format) { \
  426. case MNTVA_COLOR_16BIT565: \
  427. ((uint16_t *)d)[x] ^= (s & color_mask); break; \
  428. case MNTVA_COLOR_32BIT: \
  429. d[x] ^= (s & color_mask); break; \
  430. } break; \
  431. case MINTERM_DST: /* This one does nothing. */ \
  432. return; break; \
  433. case MINTERM_NOTONLYSRC: \
  434. switch (color_format) { \
  435. case MNTVA_COLOR_16BIT565: \
  436. ((uint16_t *)d)[x] |= (s & color_mask); break; \
  437. case MNTVA_COLOR_32BIT: \
  438. d[x] |= (s & color_mask); break; \
  439. } break; \
  440. case MINTERM_NOTSRC: \
  441. case MINTERM_SRC: \
  442. switch (color_format) { \
  443. case MNTVA_COLOR_16BIT565: \
  444. SET_FG_PIXEL16_MASK(0); break; \
  445. case MNTVA_COLOR_32BIT: \
  446. SET_FG_PIXEL32_MASK(0); break; \
  447. } break; \
  448. case MINTERM_NOTONLYDST: \
  449. switch (color_format) { \
  450. case MNTVA_COLOR_16BIT565: \
  451. ((uint16_t *)d)[x] = ~(((uint16_t *)d)[x] & s) & color_mask; \
  452. SET_FG_PIXEL16_MASK(0); break; \
  453. case MNTVA_COLOR_32BIT: \
  454. d[x] = ~(d[x] & s) & color_mask; \
  455. SET_FG_PIXEL32_MASK(0); break; \
  456. } break; \
  457. case MINTERM_OR: \
  458. switch (color_format) { \
  459. case MNTVA_COLOR_16BIT565: \
  460. ((uint16_t *)d)[x] |= (s & color_mask); break; \
  461. case MNTVA_COLOR_32BIT: \
  462. d[x] |= (s & color_mask); break; \
  463. } break; \
  464. }