atafb_iplan2p4.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /*
  2. * linux/drivers/video/iplan2p4.c -- Low level frame buffer operations for
  3. * interleaved bitplanes à la Atari (4
  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 4
  17. #include "atafb_utils.h"
  18. void atafb_iplan2p4_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. pval[1] = (*src32++ << 8) & mask;
  117. } else {
  118. pval[0] = dst32[0] & mask;
  119. pval[1] = dst32[1] & mask;
  120. }
  121. for (j = w; j > 0; j--) {
  122. v = *src32++;
  123. v1 = v & mask;
  124. *dst32++ = pval[0] | (v1 >> 8);
  125. pval[0] = (v ^ v1) << 8;
  126. v = *src32++;
  127. v1 = v & mask;
  128. *dst32++ = pval[1] | (v1 >> 8);
  129. pval[1] = (v ^ v1) << 8;
  130. }
  131. if (f & 2) {
  132. dst32[0] = (dst32[0] & mask) | pval[0];
  133. dst32[1] = (dst32[1] & mask) | pval[1];
  134. }
  135. src += next_line;
  136. dst += next_line;
  137. }
  138. } else {
  139. u32 *src32, *dst32;
  140. u32 pval[4], v, v1, mask;
  141. int i, j, w, f;
  142. src = (u8 *)info->screen_base + (sy - 1) * next_line + ((sx + width + 8) & ~15) / (8 / BPL);
  143. dst = (u8 *)info->screen_base + (dy - 1) * next_line + ((dx + width + 8) & ~15) / (8 / BPL);
  144. mask = 0xff00ff;
  145. f = 0;
  146. w = width;
  147. if ((dx + width) & 15)
  148. f = 1;
  149. if (sx & 15) {
  150. f |= 2;
  151. w += 8;
  152. }
  153. w >>= 4;
  154. for (i = height; i; i--) {
  155. src32 = (u32 *)src;
  156. dst32 = (u32 *)dst;
  157. if (f & 1) {
  158. pval[0] = dst32[-1] & mask;
  159. pval[1] = dst32[-2] & mask;
  160. } else {
  161. pval[0] = (*--src32 >> 8) & mask;
  162. pval[1] = (*--src32 >> 8) & mask;
  163. }
  164. for (j = w; j > 0; j--) {
  165. v = *--src32;
  166. v1 = v & mask;
  167. *--dst32 = pval[0] | (v1 << 8);
  168. pval[0] = (v ^ v1) >> 8;
  169. v = *--src32;
  170. v1 = v & mask;
  171. *--dst32 = pval[1] | (v1 << 8);
  172. pval[1] = (v ^ v1) >> 8;
  173. }
  174. if (!(f & 2)) {
  175. dst32[-1] = (dst32[-1] & mask) | pval[0];
  176. dst32[-2] = (dst32[-2] & mask) | pval[1];
  177. }
  178. src -= next_line;
  179. dst -= next_line;
  180. }
  181. }
  182. }
  183. }
  184. void atafb_iplan2p4_fillrect(struct fb_info *info, u_long next_line, u32 color,
  185. int sy, int sx, int height, int width)
  186. {
  187. u32 *dest;
  188. int rows, i;
  189. u32 cval[4];
  190. dest = (u32 *)(info->screen_base + sy * next_line + (sx & ~15) / (8 / BPL));
  191. if (sx & 15) {
  192. u8 *dest8 = (u8 *)dest + 1;
  193. expand8_col2mask(color, cval);
  194. for (i = height; i; i--) {
  195. fill8_col(dest8, cval);
  196. dest8 += next_line;
  197. }
  198. dest += BPL / 2;
  199. width -= 8;
  200. }
  201. expand16_col2mask(color, cval);
  202. rows = width >> 4;
  203. if (rows) {
  204. u32 *d = dest;
  205. u32 off = next_line - rows * BPL * 2;
  206. for (i = height; i; i--) {
  207. d = fill16_col(d, rows, cval);
  208. d = (u32 *)((long)d + off);
  209. }
  210. dest += rows * BPL / 2;
  211. width &= 15;
  212. }
  213. if (width) {
  214. u8 *dest8 = (u8 *)dest;
  215. expand8_col2mask(color, cval);
  216. for (i = height; i; i--) {
  217. fill8_col(dest8, cval);
  218. dest8 += next_line;
  219. }
  220. }
  221. }
  222. void atafb_iplan2p4_linefill(struct fb_info *info, u_long next_line,
  223. int dy, int dx, u32 width,
  224. const u8 *data, u32 bgcolor, u32 fgcolor)
  225. {
  226. u32 *dest;
  227. const u16 *data16;
  228. int rows;
  229. u32 fgm[4], bgm[4], m;
  230. dest = (u32 *)(info->screen_base + dy * next_line + (dx & ~15) / (8 / BPL));
  231. if (dx & 15) {
  232. fill8_2col((u8 *)dest + 1, fgcolor, bgcolor, *data++);
  233. dest += BPL / 2;
  234. width -= 8;
  235. }
  236. if (width >= 16) {
  237. data16 = (const u16 *)data;
  238. expand16_2col2mask(fgcolor, bgcolor, fgm, bgm);
  239. for (rows = width / 16; rows; rows--) {
  240. u16 d = *data16++;
  241. m = d | ((u32)d << 16);
  242. *dest++ = (m & fgm[0]) ^ bgm[0];
  243. *dest++ = (m & fgm[1]) ^ bgm[1];
  244. }
  245. data = (const u8 *)data16;
  246. width &= 15;
  247. }
  248. if (width)
  249. fill8_2col((u8 *)dest, fgcolor, bgcolor, *data);
  250. }