atafb_iplan2p2.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /*
  2. * linux/drivers/video/iplan2p2.c -- Low level frame buffer operations for
  3. * interleaved bitplanes à la Atari (2
  4. * planes, 2 bytes interleave)
  5. *
  6. * Created 5 Apr 1997 by Geert Uytterhoeven
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file COPYING in the main directory of this archive for
  10. * more details.
  11. */
  12. #include <linux/string.h>
  13. #include <linux/fb.h>
  14. #include <asm/setup.h>
  15. #include "atafb.h"
  16. #define BPL 2
  17. #include "atafb_utils.h"
  18. void atafb_iplan2p2_copyarea(struct fb_info *info, u_long next_line,
  19. int sy, int sx, int dy, int dx,
  20. int height, int width)
  21. {
  22. /* bmove() has to distinguish two major cases: If both, source and
  23. * destination, start at even addresses or both are at odd
  24. * addresses, just the first odd and last even column (if present)
  25. * require special treatment (memmove_col()). The rest between
  26. * then can be copied by normal operations, because all adjacent
  27. * bytes are affected and are to be stored in the same order.
  28. * The pathological case is when the move should go from an odd
  29. * address to an even or vice versa. Since the bytes in the plane
  30. * words must be assembled in new order, it seems wisest to make
  31. * all movements by memmove_col().
  32. */
  33. u8 *src, *dst;
  34. u32 *s, *d;
  35. int w, l , i, j;
  36. u_int colsize;
  37. u_int upwards = (dy < sy) || (dy == sy && dx < sx);
  38. colsize = height;
  39. if (!((sx ^ dx) & 15)) {
  40. /* odd->odd or even->even */
  41. if (upwards) {
  42. src = (u8 *)info->screen_base + sy * next_line + (sx & ~15) / (8 / BPL);
  43. dst = (u8 *)info->screen_base + dy * next_line + (dx & ~15) / (8 / BPL);
  44. if (sx & 15) {
  45. memmove32_col(dst, src, 0xff00ff, height, next_line - BPL * 2);
  46. src += BPL * 2;
  47. dst += BPL * 2;
  48. width -= 8;
  49. }
  50. w = width >> 4;
  51. if (w) {
  52. s = (u32 *)src;
  53. d = (u32 *)dst;
  54. w *= BPL / 2;
  55. l = next_line - w * 4;
  56. for (j = height; j > 0; j--) {
  57. for (i = w; i > 0; i--)
  58. *d++ = *s++;
  59. s = (u32 *)((u8 *)s + l);
  60. d = (u32 *)((u8 *)d + l);
  61. }
  62. }
  63. if (width & 15)
  64. memmove32_col(dst + width / (8 / BPL), src + width / (8 / BPL),
  65. 0xff00ff00, height, next_line - BPL * 2);
  66. } else {
  67. src = (u8 *)info->screen_base + (sy - 1) * next_line + ((sx + width + 8) & ~15) / (8 / BPL);
  68. dst = (u8 *)info->screen_base + (dy - 1) * next_line + ((dx + width + 8) & ~15) / (8 / BPL);
  69. if ((sx + width) & 15) {
  70. src -= BPL * 2;
  71. dst -= BPL * 2;
  72. memmove32_col(dst, src, 0xff00ff00, colsize, -next_line - BPL * 2);
  73. width -= 8;
  74. }
  75. w = width >> 4;
  76. if (w) {
  77. s = (u32 *)src;
  78. d = (u32 *)dst;
  79. w *= BPL / 2;
  80. l = next_line - w * 4;
  81. for (j = height; j > 0; j--) {
  82. for (i = w; i > 0; i--)
  83. *--d = *--s;
  84. s = (u32 *)((u8 *)s - l);
  85. d = (u32 *)((u8 *)d - l);
  86. }
  87. }
  88. if (sx & 15)
  89. memmove32_col(dst - (width - 16) / (8 / BPL),
  90. src - (width - 16) / (8 / BPL),
  91. 0xff00ff, colsize, -next_line - BPL * 2);
  92. }
  93. } else {
  94. /* odd->even or even->odd */
  95. if (upwards) {
  96. u32 *src32, *dst32;
  97. u32 pval[4], v, v1, mask;
  98. int i, j, w, f;
  99. src = (u8 *)info->screen_base + sy * next_line + (sx & ~15) / (8 / BPL);
  100. dst = (u8 *)info->screen_base + dy * next_line + (dx & ~15) / (8 / BPL);
  101. mask = 0xff00ff00;
  102. f = 0;
  103. w = width;
  104. if (sx & 15) {
  105. f = 1;
  106. w += 8;
  107. }
  108. if ((sx + width) & 15)
  109. f |= 2;
  110. w >>= 4;
  111. for (i = height; i; i--) {
  112. src32 = (u32 *)src;
  113. dst32 = (u32 *)dst;
  114. if (f & 1) {
  115. pval[0] = (*src32++ << 8) & mask;
  116. } else {
  117. pval[0] = dst32[0] & mask;
  118. }
  119. for (j = w; j > 0; j--) {
  120. v = *src32++;
  121. v1 = v & mask;
  122. *dst32++ = pval[0] | (v1 >> 8);
  123. pval[0] = (v ^ v1) << 8;
  124. }
  125. if (f & 2) {
  126. dst32[0] = (dst32[0] & mask) | pval[0];
  127. }
  128. src += next_line;
  129. dst += next_line;
  130. }
  131. } else {
  132. u32 *src32, *dst32;
  133. u32 pval[4], v, v1, mask;
  134. int i, j, w, f;
  135. src = (u8 *)info->screen_base + (sy - 1) * next_line + ((sx + width + 8) & ~15) / (8 / BPL);
  136. dst = (u8 *)info->screen_base + (dy - 1) * next_line + ((dx + width + 8) & ~15) / (8 / BPL);
  137. mask = 0xff00ff;
  138. f = 0;
  139. w = width;
  140. if ((dx + width) & 15)
  141. f = 1;
  142. if (sx & 15) {
  143. f |= 2;
  144. w += 8;
  145. }
  146. w >>= 4;
  147. for (i = height; i; i--) {
  148. src32 = (u32 *)src;
  149. dst32 = (u32 *)dst;
  150. if (f & 1) {
  151. pval[0] = dst32[-1] & mask;
  152. } else {
  153. pval[0] = (*--src32 >> 8) & mask;
  154. }
  155. for (j = w; j > 0; j--) {
  156. v = *--src32;
  157. v1 = v & mask;
  158. *--dst32 = pval[0] | (v1 << 8);
  159. pval[0] = (v ^ v1) >> 8;
  160. }
  161. if (!(f & 2)) {
  162. dst32[-1] = (dst32[-1] & mask) | pval[0];
  163. }
  164. src -= next_line;
  165. dst -= next_line;
  166. }
  167. }
  168. }
  169. }
  170. void atafb_iplan2p2_fillrect(struct fb_info *info, u_long next_line, u32 color,
  171. int sy, int sx, int height, int width)
  172. {
  173. u32 *dest;
  174. int rows, i;
  175. u32 cval[4];
  176. dest = (u32 *)(info->screen_base + sy * next_line + (sx & ~15) / (8 / BPL));
  177. if (sx & 15) {
  178. u8 *dest8 = (u8 *)dest + 1;
  179. expand8_col2mask(color, cval);
  180. for (i = height; i; i--) {
  181. fill8_col(dest8, cval);
  182. dest8 += next_line;
  183. }
  184. dest += BPL / 2;
  185. width -= 8;
  186. }
  187. expand16_col2mask(color, cval);
  188. rows = width >> 4;
  189. if (rows) {
  190. u32 *d = dest;
  191. u32 off = next_line - rows * BPL * 2;
  192. for (i = height; i; i--) {
  193. d = fill16_col(d, rows, cval);
  194. d = (u32 *)((long)d + off);
  195. }
  196. dest += rows * BPL / 2;
  197. width &= 15;
  198. }
  199. if (width) {
  200. u8 *dest8 = (u8 *)dest;
  201. expand8_col2mask(color, cval);
  202. for (i = height; i; i--) {
  203. fill8_col(dest8, cval);
  204. dest8 += next_line;
  205. }
  206. }
  207. }
  208. void atafb_iplan2p2_linefill(struct fb_info *info, u_long next_line,
  209. int dy, int dx, u32 width,
  210. const u8 *data, u32 bgcolor, u32 fgcolor)
  211. {
  212. u32 *dest;
  213. const u16 *data16;
  214. int rows;
  215. u32 fgm[4], bgm[4], m;
  216. dest = (u32 *)(info->screen_base + dy * next_line + (dx & ~15) / (8 / BPL));
  217. if (dx & 15) {
  218. fill8_2col((u8 *)dest + 1, fgcolor, bgcolor, *data++);
  219. dest += BPL / 2;
  220. width -= 8;
  221. }
  222. if (width >= 16) {
  223. data16 = (const u16 *)data;
  224. expand16_2col2mask(fgcolor, bgcolor, fgm, bgm);
  225. for (rows = width / 16; rows; rows--) {
  226. u16 d = *data16++;
  227. m = d | ((u32)d << 16);
  228. *dest++ = (m & fgm[0]) ^ bgm[0];
  229. }
  230. data = (const u8 *)data16;
  231. width &= 15;
  232. }
  233. if (width)
  234. fill8_2col((u8 *)dest, fgcolor, bgcolor, *data);
  235. }