cirrus_vga_rop.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*
  2. * QEMU Cirrus CLGD 54xx VGA Emulator.
  3. *
  4. * Copyright (c) 2004 Fabrice Bellard
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. */
  24. static inline void glue(rop_8_, ROP_NAME)(CirrusVGAState *s,
  25. uint32_t dstaddr, uint8_t src)
  26. {
  27. uint8_t *dst = &s->vga.vram_ptr[dstaddr & s->cirrus_addr_mask];
  28. *dst = ROP_FN(*dst, src);
  29. }
  30. static inline void glue(rop_tr_8_, ROP_NAME)(CirrusVGAState *s,
  31. uint32_t dstaddr, uint8_t src,
  32. uint8_t transp)
  33. {
  34. uint8_t *dst = &s->vga.vram_ptr[dstaddr & s->cirrus_addr_mask];
  35. uint8_t pixel = ROP_FN(*dst, src);
  36. if (pixel != transp) {
  37. *dst = pixel;
  38. }
  39. }
  40. static inline void glue(rop_16_, ROP_NAME)(CirrusVGAState *s,
  41. uint32_t dstaddr, uint16_t src)
  42. {
  43. uint16_t *dst = (uint16_t *)
  44. (&s->vga.vram_ptr[dstaddr & s->cirrus_addr_mask & ~1]);
  45. *dst = ROP_FN(*dst, src);
  46. }
  47. static inline void glue(rop_tr_16_, ROP_NAME)(CirrusVGAState *s,
  48. uint32_t dstaddr, uint16_t src,
  49. uint16_t transp)
  50. {
  51. uint16_t *dst = (uint16_t *)
  52. (&s->vga.vram_ptr[dstaddr & s->cirrus_addr_mask & ~1]);
  53. uint16_t pixel = ROP_FN(*dst, src);
  54. if (pixel != transp) {
  55. *dst = pixel;
  56. }
  57. }
  58. static inline void glue(rop_32_, ROP_NAME)(CirrusVGAState *s,
  59. uint32_t dstaddr, uint32_t src)
  60. {
  61. uint32_t *dst = (uint32_t *)
  62. (&s->vga.vram_ptr[dstaddr & s->cirrus_addr_mask & ~3]);
  63. *dst = ROP_FN(*dst, src);
  64. }
  65. #define ROP_OP(st, d, s) glue(rop_8_, ROP_NAME)(st, d, s)
  66. #define ROP_OP_TR(st, d, s, t) glue(rop_tr_8_, ROP_NAME)(st, d, s, t)
  67. #define ROP_OP_16(st, d, s) glue(rop_16_, ROP_NAME)(st, d, s)
  68. #define ROP_OP_TR_16(st, d, s, t) glue(rop_tr_16_, ROP_NAME)(st, d, s, t)
  69. #define ROP_OP_32(st, d, s) glue(rop_32_, ROP_NAME)(st, d, s)
  70. #undef ROP_FN
  71. static void
  72. glue(cirrus_bitblt_rop_fwd_, ROP_NAME)(CirrusVGAState *s,
  73. uint32_t dstaddr,
  74. uint32_t srcaddr,
  75. int dstpitch, int srcpitch,
  76. int bltwidth, int bltheight)
  77. {
  78. int x,y;
  79. dstpitch -= bltwidth;
  80. srcpitch -= bltwidth;
  81. if (bltheight > 1 && (dstpitch < 0 || srcpitch < 0)) {
  82. return;
  83. }
  84. for (y = 0; y < bltheight; y++) {
  85. for (x = 0; x < bltwidth; x++) {
  86. ROP_OP(s, dstaddr, cirrus_src(s, srcaddr));
  87. dstaddr++;
  88. srcaddr++;
  89. }
  90. dstaddr += dstpitch;
  91. srcaddr += srcpitch;
  92. }
  93. }
  94. static void
  95. glue(cirrus_bitblt_rop_bkwd_, ROP_NAME)(CirrusVGAState *s,
  96. uint32_t dstaddr,
  97. uint32_t srcaddr,
  98. int dstpitch, int srcpitch,
  99. int bltwidth, int bltheight)
  100. {
  101. int x,y;
  102. dstpitch += bltwidth;
  103. srcpitch += bltwidth;
  104. for (y = 0; y < bltheight; y++) {
  105. for (x = 0; x < bltwidth; x++) {
  106. ROP_OP(s, dstaddr, cirrus_src(s, srcaddr));
  107. dstaddr--;
  108. srcaddr--;
  109. }
  110. dstaddr += dstpitch;
  111. srcaddr += srcpitch;
  112. }
  113. }
  114. static void
  115. glue(glue(cirrus_bitblt_rop_fwd_transp_, ROP_NAME),_8)(CirrusVGAState *s,
  116. uint32_t dstaddr,
  117. uint32_t srcaddr,
  118. int dstpitch,
  119. int srcpitch,
  120. int bltwidth,
  121. int bltheight)
  122. {
  123. int x,y;
  124. uint8_t transp = s->vga.gr[0x34];
  125. dstpitch -= bltwidth;
  126. srcpitch -= bltwidth;
  127. if (bltheight > 1 && (dstpitch < 0 || srcpitch < 0)) {
  128. return;
  129. }
  130. for (y = 0; y < bltheight; y++) {
  131. for (x = 0; x < bltwidth; x++) {
  132. ROP_OP_TR(s, dstaddr, cirrus_src(s, srcaddr), transp);
  133. dstaddr++;
  134. srcaddr++;
  135. }
  136. dstaddr += dstpitch;
  137. srcaddr += srcpitch;
  138. }
  139. }
  140. static void
  141. glue(glue(cirrus_bitblt_rop_bkwd_transp_, ROP_NAME),_8)(CirrusVGAState *s,
  142. uint32_t dstaddr,
  143. uint32_t srcaddr,
  144. int dstpitch,
  145. int srcpitch,
  146. int bltwidth,
  147. int bltheight)
  148. {
  149. int x,y;
  150. uint8_t transp = s->vga.gr[0x34];
  151. dstpitch += bltwidth;
  152. srcpitch += bltwidth;
  153. for (y = 0; y < bltheight; y++) {
  154. for (x = 0; x < bltwidth; x++) {
  155. ROP_OP_TR(s, dstaddr, cirrus_src(s, srcaddr), transp);
  156. dstaddr--;
  157. srcaddr--;
  158. }
  159. dstaddr += dstpitch;
  160. srcaddr += srcpitch;
  161. }
  162. }
  163. static void
  164. glue(glue(cirrus_bitblt_rop_fwd_transp_, ROP_NAME),_16)(CirrusVGAState *s,
  165. uint32_t dstaddr,
  166. uint32_t srcaddr,
  167. int dstpitch,
  168. int srcpitch,
  169. int bltwidth,
  170. int bltheight)
  171. {
  172. int x,y;
  173. uint16_t transp = s->vga.gr[0x34] | (uint16_t)s->vga.gr[0x35] << 8;
  174. dstpitch -= bltwidth;
  175. srcpitch -= bltwidth;
  176. if (bltheight > 1 && (dstpitch < 0 || srcpitch < 0)) {
  177. return;
  178. }
  179. for (y = 0; y < bltheight; y++) {
  180. for (x = 0; x < bltwidth; x+=2) {
  181. ROP_OP_TR_16(s, dstaddr, cirrus_src16(s, srcaddr), transp);
  182. dstaddr += 2;
  183. srcaddr += 2;
  184. }
  185. dstaddr += dstpitch;
  186. srcaddr += srcpitch;
  187. }
  188. }
  189. static void
  190. glue(glue(cirrus_bitblt_rop_bkwd_transp_, ROP_NAME),_16)(CirrusVGAState *s,
  191. uint32_t dstaddr,
  192. uint32_t srcaddr,
  193. int dstpitch,
  194. int srcpitch,
  195. int bltwidth,
  196. int bltheight)
  197. {
  198. int x,y;
  199. uint16_t transp = s->vga.gr[0x34] | (uint16_t)s->vga.gr[0x35] << 8;
  200. dstpitch += bltwidth;
  201. srcpitch += bltwidth;
  202. for (y = 0; y < bltheight; y++) {
  203. for (x = 0; x < bltwidth; x+=2) {
  204. ROP_OP_TR_16(s, dstaddr - 1, cirrus_src16(s, srcaddr - 1), transp);
  205. dstaddr -= 2;
  206. srcaddr -= 2;
  207. }
  208. dstaddr += dstpitch;
  209. srcaddr += srcpitch;
  210. }
  211. }
  212. #define DEPTH 8
  213. #include "cirrus_vga_rop2.h"
  214. #define DEPTH 16
  215. #include "cirrus_vga_rop2.h"
  216. #define DEPTH 24
  217. #include "cirrus_vga_rop2.h"
  218. #define DEPTH 32
  219. #include "cirrus_vga_rop2.h"
  220. #undef ROP_NAME
  221. #undef ROP_OP
  222. #undef ROP_OP_16
  223. #undef ROP_OP_32