Fixed compatibility of output.
[AROS.git] / arch / .unmaintained / m68k-pp-native / Drivers / display.hidd / bitmap_common.c
blob60fe737de07f9de07f17203e780f8f562f34b312
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English.
7 */
9 #include <exec/alerts.h>
10 #include <asm/registers.h>
12 #include <string.h>
14 #undef DEBUG
15 #define DEBUG 0
16 #include <aros/debug.h>
19 /********* BitMap::Clear() *************************************/
20 static VOID MNAME(clear)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_Clear *msg)
22 ULONG width, height;
23 struct bitmap_data *data = OOP_INST_DATA(cl, o);
24 struct Box box = {0, 0, 0, 0};
26 /* Get width & height from bitmap superclass */
27 #define xsd XSD(cl)
28 OOP_GetAttr(o, aHidd_BitMap_Width, &width);
29 OOP_GetAttr(o, aHidd_BitMap_Height, &height);
30 #undef xsd
31 box.x2 = width - 1;
32 box.y2 = height - 1;
34 memset(data->VideoData, GC_BG(msg->gc), width*height);
36 #ifdef OnBitmap
37 ObtainSemaphore(&XSD(cl)->HW_acc);
38 DisplayRefreshArea(data, 1, &box);
39 ReleaseSemaphore(&XSD(cl)->HW_acc);
40 #endif /* OnBitmap */
42 return;
45 //void vgaRestore(struct vgaHWRec *, BOOL onlyDAC);
47 static BOOL MNAME(setcolors)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_SetColors *msg)
49 struct bitmap_data *data = OOP_INST_DATA(cl, o);
50 HIDDT_PixelFormat *pf;
52 ULONG xc_i, col_i;
54 HIDDT_Pixel red, green, blue;
56 pf = BM_PIXFMT(o);
58 if ( vHidd_ColorModel_StaticPalette == HIDD_PF_COLMODEL(pf)
59 || vHidd_ColorModel_TrueColor == HIDD_PF_COLMODEL(pf) ) {
61 /* Superclass takes care of this case */
63 return OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
66 /* We have a vHidd_GT_Palette bitmap */
68 if (!OOP_DoSuperMethod(cl, o, (OOP_Msg)msg)) return FALSE;
70 if ((msg->firstColor + msg->numColors) > (1 << data->bpp))
71 return FALSE;
73 for ( xc_i = msg->firstColor, col_i = 0;
74 col_i < msg->numColors;
75 xc_i ++, col_i ++ )
77 red = msg->colors[col_i].red >> 8;
78 green = msg->colors[col_i].green >> 8;
79 blue = msg->colors[col_i].blue >> 8;
81 /* Set given color as allocated */
82 data->cmap[xc_i] = 0x01000000 | red | (green << 8) | (blue << 16);
84 msg->colors[col_i].pixval = xc_i;
87 /* Restore palette if OnBitmap */
88 #ifdef OnBitmap
89 ObtainSemaphore(&XSD(cl)->HW_acc);
90 DisplayRestore((struct DisplayHWRec *)data->Regs, TRUE);
91 ReleaseSemaphore(&XSD(cl)->HW_acc);
92 #endif /* OnBitmap */
94 return TRUE;
97 /********* BitMap::PutPixel() ***************************/
99 static VOID MNAME(putpixel)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_PutPixel *msg)
101 struct bitmap_data *data = OOP_INST_DATA(cl, o);
102 HIDDT_Pixel fg;
103 unsigned char *ptr;
105 #ifdef OnBitmap
106 int pix;
107 unsigned char *ptr2;
108 #endif /* OnBitmap */
110 fg = msg->pixel;
111 ptr = (char *)(data->VideoData + msg->x + (msg->y * data->width));
113 *ptr = (char) fg;
115 #ifdef OnBitmap
117 ptr2 = (unsigned char *)(RREG_L(LSSA) + (msg->y * RREG_B(LVPW) * 2) + msg->x / 8);
118 pix = 0x80 >> (msg->x % 8);
119 if (fg)
121 *ptr2 |= pix;
123 else
125 *ptr2 &= ~pix;
128 /* ptr2 = (char *)(0xa0000 + (msg->x + (msg->y * data->width)) / 8);
129 pix = 0x8000 >> (msg->x % 8);
130 ObtainSemaphore(&XSD(cl)->HW_acc);
133 *ptr2 |= 1; // This or'ed value isn't important
135 ReleaseSemaphore(&XSD(cl)->HW_acc);
138 #endif /* OnBitmap */
140 return;
143 /********* BitMap::GetPixel() *********************************/
144 static HIDDT_Pixel MNAME(getpixel)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_GetPixel *msg)
146 HIDDT_Pixel pixel=0;
147 struct bitmap_data *data = OOP_INST_DATA(cl, o);
149 unsigned char *ptr;
151 ptr = (char *)(data->VideoData + msg->x + (msg->y * data->width));
153 pixel = *(char*)ptr;
155 /* Get pen number from colortab */
156 return pixel;
159 /********* BitMap::PutImage() ***************************/
161 static VOID MNAME(putimage)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_PutImage *msg)
163 struct bitmap_data *data = OOP_INST_DATA(cl, o);
164 struct Box box = {0, 0, 0, 0};
165 UBYTE *buff = data->VideoData + msg->x + (msg->y * data->width);
166 ULONG add = data->width - msg->width;
167 ULONG cnt = msg->height;
168 UBYTE *s_start = (UBYTE *)msg->pixels;
169 BOOL done_by_superclass = FALSE;
170 int i;
172 EnterFunc(bug("DisplayGfx.BitMap::PutImage(pa=%p, x=%d, y=%d, w=%d, h=%d)\n",
173 msg->pixels, msg->x, msg->y, msg->width, msg->height));
175 switch(msg->pixFmt)
177 case vHidd_StdPixFmt_Native:
178 while (cnt > 0)
180 UBYTE *p = s_start;
182 i = msg->width;
183 while (i)
185 *buff++ = *p++;
186 i--;
188 buff += add;
189 s_start += msg->modulo;
190 cnt--;
192 break;
194 case vHidd_StdPixFmt_Native32:
195 while (cnt > 0)
197 HIDDT_Pixel *p = (HIDDT_Pixel *)s_start;
199 i = msg->width;
200 while (i)
202 *buff++ = (UBYTE)*p++;
203 i--;
205 buff += add;
206 s_start += msg->modulo;
207 cnt--;
209 break;
211 default:
212 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
213 done_by_superclass = TRUE;
214 break;
218 if (data->disp && !done_by_superclass)
220 box.x1 = msg->x;
221 box.y1 = msg->y;
222 box.x2 = box.x1 + msg->width - 1;
223 box.y2 = box.y1 + msg->height - 1;
225 ObtainSemaphore(&XSD(cl)->HW_acc);
227 DisplayRefreshArea(data, 1, &box);
229 ReleaseSemaphore(&XSD(cl)->HW_acc);
233 ReturnVoid("DisplayGfx.BitMap::PutImage");
236 /********* BitMap::GetImage() ***************************/
238 static VOID MNAME(getimage)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_GetImage *msg)
240 struct bitmap_data *data = OOP_INST_DATA(cl, o);
241 UBYTE *buff = data->VideoData + msg->x + (msg->y * data->width);
242 ULONG add = data->width - msg->width;
243 ULONG cnt = msg->height;
244 UBYTE *s_start = (UBYTE *)msg->pixels;
245 int i;
247 switch(msg->pixFmt)
249 case vHidd_StdPixFmt_Native:
250 while (cnt > 0)
252 UBYTE *p = s_start;
254 i = msg->width;
255 while (i)
257 *p++ = *buff++;
258 i--;
260 buff += add;
261 s_start += msg->modulo;
262 cnt--;
264 break;
266 case vHidd_StdPixFmt_Native32:
267 while (cnt > 0)
269 HIDDT_Pixel *p = (HIDDT_Pixel *)s_start;
271 i = msg->width;
272 while (i)
274 *p++ = (HIDDT_Pixel)*buff++;
275 i--;
277 buff += add;
278 s_start += msg->modulo;
279 cnt--;
281 break;
284 default:
285 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
286 break;
288 } /* switch(msg->pixFmt) */
292 /********* BitMap::PutImageLUT() ***************************/
294 static VOID MNAME(putimagelut)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_PutImageLUT *msg)
296 struct bitmap_data *data = OOP_INST_DATA(cl, o);
297 struct Box box = {0, 0, 0, 0};
299 int i;
301 // start of Source data
302 unsigned char *buff = data->VideoData +
303 msg->x + (msg->y * data->width);
304 // adder for each line
305 ULONG add = data->width - msg->width;
306 ULONG cnt = msg->height;
308 unsigned char *s_start = msg->pixels;
310 EnterFunc(bug("DisplayGfx.BitMap::PutImageLUT(pa=%p, x=%d, y=%d, w=%d, h=%d)\n",
311 msg->pixels, msg->x, msg->y, msg->width, msg->height));
313 while (cnt > 0)
315 i = msg->width;
316 while (i)
318 *buff++ = *s_start++;
319 i--;
321 buff += add;
322 s_start += (msg->modulo - msg->width);
323 cnt--;
325 if (data->disp)
327 box.x1 = msg->x;
328 box.y1 = msg->y;
329 box.x2 = box.x1 + msg->width - 1;
330 box.y2 = box.y1 + msg->height - 1;
332 ObtainSemaphore(&XSD(cl)->HW_acc);
334 DisplayRefreshArea(data, 1, &box);
336 ReleaseSemaphore(&XSD(cl)->HW_acc);
339 ReturnVoid("DisplayGfx.BitMap::PutImageLUT");
342 /********* BitMap::GetImageLUT() ***************************/
344 static VOID MNAME(getimagelut)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_GetImageLUT *msg)
346 struct bitmap_data *data = OOP_INST_DATA(cl, o);
348 int i;
350 // start of Source data
351 unsigned char *buff = data->VideoData +
352 msg->x + (msg->y * data->width);
353 // adder for each line
354 ULONG add = data->width - msg->width;
355 ULONG cnt = msg->height;
357 unsigned char *s_start = msg->pixels;
359 while (cnt > 0)
361 i = msg->width;
362 while (i)
364 *s_start++ = *buff++;
365 i--;
367 buff += add;
368 cnt--;
372 /********* BitMap::FillRect() ***************************/
374 static VOID MNAME(fillrect)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_DrawRect *msg)
376 struct bitmap_data *data =OOP_INST_DATA(cl, o);
377 struct Box box = {0, 0, 0, 0};
378 HIDDT_Pixel fg = GC_FG(msg->gc);
379 HIDDT_DrawMode mode = GC_DRMD(msg->gc);
380 int i, phase, j;
382 ULONG width = msg->maxX - msg->minX + 1;
384 // start of video data
385 unsigned char *s_start = data->VideoData +
386 msg->minX + (msg->minY * data->width);
388 // adder for each line
389 ULONG s_add = data->width - width;
390 ULONG cnt = msg->maxY - msg->minY + 1;
392 EnterFunc(bug("DisplayGfx.BitMap::FillRect(%d,%d,%d,%d)\n",
393 msg->minX, msg->minY, msg->maxX, msg->maxY));
395 if ((phase = (long)s_start & 3L))
397 phase = 4 - phase;
398 if (phase > width) phase = width;
399 width -= phase;
402 switch(mode)
404 case vHidd_GC_DrawMode_Copy:
405 fg |= ((char)fg) << 8;
406 fg |= ((short)fg) << 16;
408 while (cnt--)
410 i = width;
411 j = phase;
412 while (j--)
414 *(unsigned char*)s_start++ = (char)fg;
416 while (i >= 4)
418 *((unsigned long*)s_start) = fg;
419 s_start += 4;
420 i -= 4;
422 while (i--)
424 *(unsigned char*)s_start++ = (char)fg;
426 s_start += s_add;
428 break;
430 case vHidd_GC_DrawMode_Invert:
431 while (cnt--)
433 unsigned char bg;
434 unsigned long bglong;
436 i = width;
437 j = phase;
438 while (j--)
440 bg = *s_start;
441 *(unsigned char*)s_start++ = ~bg;
443 while (i >= 4)
445 bglong = *(unsigned long *)s_start;
446 *((unsigned long*)s_start) = ~bglong;
447 s_start += 4;
448 i -= 4;
450 while (i--)
452 bg = *s_start;
453 *(unsigned char*)s_start++ = ~bg;
455 s_start += s_add;
457 break;
459 default:
460 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
461 break;
463 } /* switch(mode) */
466 if (data->disp)
468 box.x1 = msg->minX;
469 box.y1 = msg->minY;
470 box.x2 = msg->maxX;
471 box.y2 = msg->maxY;
473 ObtainSemaphore(&XSD(cl)->HW_acc);
475 DisplayRefreshArea(data, 1, &box);
477 ReleaseSemaphore(&XSD(cl)->HW_acc);
481 ReturnVoid("DisplayGfx.BitMap::FillRect");
484 /*** BitMap::BlitColorExpansion() **********************************************/
485 static VOID MNAME(blitcolorexpansion)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_BlitColorExpansion *msg)
487 ULONG cemd;
488 struct bitmap_data *data = OOP_INST_DATA(cl, o);
489 struct Box box;
490 HIDDT_Pixel fg, bg;
491 LONG x, y;
493 EnterFunc(bug("DisplayGfx.BitMap::BlitColorExpansion(%p, %d, %d, %d, %d, %d, %d)\n"
494 , msg->srcBitMap, msg->srcX, msg->srcY, msg->destX, msg->destY, msg->width, msg->height));
496 fg = GC_FG(msg->gc);
497 bg = GC_BG(msg->gc);
498 cemd = GC_COLEXP(msg->gc);
500 if (cemd & vHidd_GC_ColExp_Opaque)
502 for (y = 0; y < msg->height; y ++)
504 for (x = 0; x < msg->width; x ++)
506 ULONG is_set;
508 is_set = HIDD_BM_GetPixel(msg->srcBitMap, x + msg->srcX, y + msg->srcY);
510 *(data->VideoData + x + msg->destX + ((y + msg->destY) * data->width)) = is_set ? fg : bg;
512 } /* for (each x) */
514 } /* for (each y) */
517 else
519 for (y = 0; y < msg->height; y ++)
521 for (x = 0; x < msg->width; x ++)
523 ULONG is_set;
525 is_set = HIDD_BM_GetPixel(msg->srcBitMap, x + msg->srcX, y + msg->srcY);
527 if (is_set)
528 *(data->VideoData + x + msg->destX + ((y + msg->destY) * data->width)) = fg;
530 } /* for (each x) */
532 } /* for (each y) */
535 if (data->disp)
537 box.x1 = msg->destX;
538 box.y1 = msg->destY;
539 box.x2 = box.x1 + msg->width - 1;
540 box.y2 = box.y1 + msg->height - 1;
542 ObtainSemaphore(&XSD(cl)->HW_acc);
544 DisplayRefreshArea(data, 1, &box);
546 ReleaseSemaphore(&XSD(cl)->HW_acc);
549 ReturnVoid("DisplayGfx.BitMap::BlitColorExpansion");
552 /*** BitMap::Get() *******************************************/
554 static VOID MNAME(get)(OOP_Class *cl, OOP_Object *o, struct pRoot_Get *msg)
556 struct bitmap_data *data = OOP_INST_DATA(cl, o);
557 ULONG idx;
558 #define xsd XSD(cl)
559 if (IS_DisplayBM_ATTR(msg->attrID, idx))
561 switch (idx)
563 case aoHidd_DisplayBitMap_Drawable:
564 *msg->storage = (ULONG)data->VideoData;
565 break;
567 default:
568 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
569 break;
572 else
574 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
576 #undef xsd
577 return;