Updated PCI IDs to latest snapshot.
[tangerine.git] / arch / i386-pc / drivers / vga.hidd / bitmap_common.c
blob3dd21a76bcb9e11f88929995185fea97d4a25bde
1 /*
2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English.
7 */
9 #include <exec/alerts.h>
10 #include <string.h> // memset() prototype
12 #undef DEBUG
13 #define DEBUG 0
14 #include <aros/debug.h>
17 /********* BitMap::Clear() *************************************/
18 VOID MNAME_BM(Clear)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_Clear *msg)
20 IPTR width, height;
21 struct bitmap_data *data = OOP_INST_DATA(cl, o);
22 struct Box box = {0, 0, 0, 0};
24 /* Get width & height from bitmap superclass */
26 OOP_GetAttr(o, aHidd_BitMap_Width, &width);
27 OOP_GetAttr(o, aHidd_BitMap_Height, &height);
29 box.x2 = width - 1;
30 box.y2 = height - 1;
32 memset(data->VideoData, GC_BG(msg->gc), width*height);
34 #ifdef OnBitmap
35 ObtainSemaphore(&XSD(cl)->HW_acc);
36 vgaRefreshArea(data, 1, &box);
37 draw_mouse(XSD(cl));
38 ReleaseSemaphore(&XSD(cl)->HW_acc);
39 #endif /* OnBitmap */
41 return;
44 void vgaDACLoad(struct vgaHWRec *, unsigned char, int);
46 BOOL MNAME_BM(SetColors)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_SetColors *msg)
48 struct bitmap_data *data = OOP_INST_DATA(cl, o);
49 HIDDT_PixelFormat *pf;
51 ULONG xc_i, col_i;
53 HIDDT_Pixel red, green, blue;
55 pf = BM_PIXFMT(o);
57 if ( vHidd_ColorModel_StaticPalette == HIDD_PF_COLMODEL(pf)
58 || vHidd_ColorModel_TrueColor == HIDD_PF_COLMODEL(pf) ) {
60 /* Superclass takes care of this case */
62 return OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
65 /* We have a vHidd_GT_Palette bitmap */
67 if (!OOP_DoSuperMethod(cl, o, (OOP_Msg)msg)) return FALSE;
69 if ((msg->firstColor + msg->numColors) > (1 << data->bpp))
70 return FALSE;
72 for ( xc_i = msg->firstColor, col_i = 0;
73 col_i < msg->numColors;
74 xc_i ++, col_i ++ )
76 red = msg->colors[col_i].red >> 8;
77 green = msg->colors[col_i].green >> 8;
78 blue = msg->colors[col_i].blue >> 8;
80 /* Set given color as allocated */
81 data->cmap[xc_i] = 0x01000000 | red | (green << 8) | (blue << 16);
83 /* Update DAC registers */
84 data->Regs->DAC[xc_i*3] = red >> 2;
85 data->Regs->DAC[xc_i*3+1] = green >> 2;
86 data->Regs->DAC[xc_i*3+2] = blue >> 2;
88 msg->colors[col_i].pixval = xc_i;
91 /* Restore palette if OnBitmap */
92 #ifdef OnBitmap
93 ObtainSemaphore(&XSD(cl)->HW_acc);
94 vgaDACLoad(data->Regs, msg->firstColor, msg->numColors);
95 ReleaseSemaphore(&XSD(cl)->HW_acc);
96 #endif /* OnBitmap */
98 return TRUE;
101 /********* BitMap::PutPixel() ***************************/
103 VOID MNAME_BM(PutPixel)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_PutPixel *msg)
105 struct bitmap_data *data = OOP_INST_DATA(cl, o);
106 HIDDT_Pixel fg;
107 unsigned char *ptr;
109 #ifdef OnBitmap
110 int pix;
111 int i;
112 unsigned char *ptr2;
113 #endif /* OnBitmap */
115 fg = msg->pixel;
116 ptr = (char *)(data->VideoData + msg->x + (msg->y * data->width));
118 *ptr = (char) fg;
120 #ifdef OnBitmap
121 ptr2 = (char *)(0xa0000 + (msg->x + (msg->y * data->width)) / 8);
122 pix = 0x8000 >> (msg->x % 8);
123 ObtainSemaphore(&XSD(cl)->HW_acc);
125 outw(0x3c4,0x0f02);
126 outw(0x3ce,pix | 8);
127 outw(0x3ce,0x0005);
128 outw(0x3ce,0x0003);
129 outw(0x3ce,(fg << 8));
130 outw(0x3ce,0x0f01);
132 *ptr2 |= 1; // This or'ed value isn't important
134 if (((msg->x >= XSD(cl)->mouseX) && (msg->x < (XSD(cl)->mouseX + XSD(cl)->mouseW))) ||
135 ((msg->y >= XSD(cl)->mouseY) && (msg->y < (XSD(cl)->mouseY + XSD(cl)->mouseH))))
136 draw_mouse(XSD(cl));
138 ReleaseSemaphore(&XSD(cl)->HW_acc);
140 #endif /* OnBitmap */
142 return;
145 /********* BitMap::GetPixel() *********************************/
146 HIDDT_Pixel MNAME_BM(GetPixel)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_GetPixel *msg)
148 HIDDT_Pixel pixel=0;
149 struct bitmap_data *data = OOP_INST_DATA(cl, o);
151 unsigned char *ptr;
153 ptr = (char *)(data->VideoData + msg->x + (msg->y * data->width));
155 pixel = *(char*)ptr;
157 /* Get pen number from colortab */
158 return pixel;
161 /********* BitMap::PutImage() ***************************/
163 VOID MNAME_BM(PutImage)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_PutImage *msg)
165 struct bitmap_data *data = OOP_INST_DATA(cl, o);
166 struct Box box = {0, 0, 0, 0};
167 BOOL done_by_superclass = FALSE;
168 int i;
170 EnterFunc(bug("VGAGfx.BitMap::PutImage(pa=%p, x=%d, y=%d, w=%d, h=%d)\n",
171 msg->pixels, msg->x, msg->y, msg->width, msg->height));
173 switch(msg->pixFmt)
175 case vHidd_StdPixFmt_Native:
176 HIDD_BM_CopyMemBox8(o,
177 msg->pixels,
180 data->VideoData,
181 msg->x,
182 msg->y,
183 msg->width,
184 msg->height,
185 msg->modulo,
186 data->width);
187 break;
189 case vHidd_StdPixFmt_Native32:
190 HIDD_BM_PutMem32Image8(o,
191 msg->pixels,
192 data->VideoData,
193 msg->x,
194 msg->y,
195 msg->width,
196 msg->height,
197 msg->modulo,
198 data->width);
199 break;
201 default:
202 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
203 done_by_superclass = TRUE;
204 break;
208 if (data->disp && !done_by_superclass)
210 box.x1 = msg->x;
211 box.y1 = msg->y;
212 box.x2 = box.x1 + msg->width - 1;
213 box.y2 = box.y1 + msg->height - 1;
215 ObtainSemaphore(&XSD(cl)->HW_acc);
217 vgaRefreshArea(data, 1, &box);
219 if ( ( (XSD(cl)->mouseX + XSD(cl)->mouseW - 1 >= box.x1) &&
220 (XSD(cl)->mouseX <= box.x2) ) ||
221 ( (XSD(cl)->mouseY + XSD(cl)->mouseH - 1 >= box.y1) &&
222 (XSD(cl)->mouseY <= box.y2) ) )
223 draw_mouse(XSD(cl));
225 ReleaseSemaphore(&XSD(cl)->HW_acc);
229 ReturnVoid("VGAGfx.BitMap::PutImage");
232 /********* BitMap::GetImage() ***************************/
234 VOID MNAME_BM(GetImage)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_GetImage *msg)
236 struct bitmap_data *data = OOP_INST_DATA(cl, o);
237 int i;
239 switch(msg->pixFmt)
241 case vHidd_StdPixFmt_Native:
242 HIDD_BM_CopyMemBox8(o,
243 data->VideoData,
244 msg->x,
245 msg->y,
246 msg->pixels,
249 msg->width,
250 msg->height,
251 data->width,
252 msg->modulo);
253 break;
255 case vHidd_StdPixFmt_Native32:
256 HIDD_BM_GetMem32Image8(o,
257 data->VideoData,
258 msg->x,
259 msg->y,
260 msg->pixels,
261 msg->width,
262 msg->height,
263 data->width,
264 msg->modulo);
265 break;
268 default:
269 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
270 break;
272 } /* switch(msg->pixFmt) */
276 /********* BitMap::PutImageLUT() ***************************/
278 VOID MNAME_BM(PutImageLUT)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_PutImageLUT *msg)
280 struct bitmap_data *data = OOP_INST_DATA(cl, o);
281 struct Box box = {0, 0, 0, 0};
283 EnterFunc(bug("VGAGfx.BitMap::PutImageLUT(pa=%p, x=%d, y=%d, w=%d, h=%d)\n",
284 msg->pixels, msg->x, msg->y, msg->width, msg->height));
286 HIDD_BM_CopyMemBox8(o,
287 msg->pixels,
290 data->VideoData,
291 msg->x,
292 msg->y,
293 msg->width,
294 msg->height,
295 msg->modulo,
296 data->width);
298 if (data->disp)
300 box.x1 = msg->x;
301 box.y1 = msg->y;
302 box.x2 = box.x1 + msg->width - 1;
303 box.y2 = box.y1 + msg->height - 1;
305 ObtainSemaphore(&XSD(cl)->HW_acc);
307 vgaRefreshArea(data, 1, &box);
309 if ( ( (XSD(cl)->mouseX + XSD(cl)->mouseW - 1 >= box.x1) &&
310 (XSD(cl)->mouseX <= box.x2) ) ||
311 ( (XSD(cl)->mouseY + XSD(cl)->mouseH - 1 >= box.y1) &&
312 (XSD(cl)->mouseY <= box.y2) ) )
313 draw_mouse(XSD(cl));
315 ReleaseSemaphore(&XSD(cl)->HW_acc);
318 ReturnVoid("VGAGfx.BitMap::PutImageLUT");
321 /********* BitMap::GetImageLUT() ***************************/
323 VOID MNAME_BM(GetImageLUT)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_GetImageLUT *msg)
325 struct bitmap_data *data = OOP_INST_DATA(cl, o);
327 HIDD_BM_CopyMemBox8(o,
328 data->VideoData,
329 msg->x,
330 msg->y,
331 msg->pixels,
334 msg->width,
335 msg->height,
336 data->width,
337 msg->modulo);
341 /********* BitMap::FillRect() ***************************/
343 VOID MNAME_BM(FillRect)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_DrawRect *msg)
345 struct bitmap_data *data =OOP_INST_DATA(cl, o);
346 struct Box box = {0, 0, 0, 0};
347 HIDDT_Pixel fg = GC_FG(msg->gc);
348 HIDDT_DrawMode mode = GC_DRMD(msg->gc);
350 EnterFunc(bug("VGAGfx.BitMap::FillRect(%d,%d,%d,%d)\n",
351 msg->minX, msg->minY, msg->maxX, msg->maxY));
353 switch(mode)
355 case vHidd_GC_DrawMode_Copy:
356 HIDD_BM_FillMemRect8(o,
357 data->VideoData,
358 msg->minX,
359 msg->minY,
360 msg->maxX,
361 msg->maxY,
362 data->width,
363 fg);
364 break;
366 case vHidd_GC_DrawMode_Invert:
367 HIDD_BM_InvertMemRect(o,
368 data->VideoData,
369 msg->minX,
370 msg->minY,
371 msg->maxX,
372 msg->maxY,
373 data->width);
374 break;
376 default:
377 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
378 break;
380 } /* switch(mode) */
383 if (data->disp)
385 box.x1 = msg->minX;
386 box.y1 = msg->minY;
387 box.x2 = msg->maxX;
388 box.y2 = msg->maxY;
390 ObtainSemaphore(&XSD(cl)->HW_acc);
392 vgaRefreshArea(data, 1, &box);
393 if ( ( (XSD(cl)->mouseX + XSD(cl)->mouseW - 1 >= box.x1) &&
394 (XSD(cl)->mouseX <= box.x2) ) ||
395 ( (XSD(cl)->mouseY + XSD(cl)->mouseH - 1 >= box.y1) &&
396 (XSD(cl)->mouseY <= box.y2) ) )
397 draw_mouse(XSD(cl));
399 ReleaseSemaphore(&XSD(cl)->HW_acc);
403 ReturnVoid("VGAGfx.BitMap::FillRect");
406 /*** BitMap::BlitColorExpansion() **********************************************/
407 VOID MNAME_BM(BlitColorExpansion)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_BlitColorExpansion *msg)
409 ULONG cemd;
410 struct bitmap_data *data = OOP_INST_DATA(cl, o);
411 struct Box box;
412 HIDDT_Pixel fg, bg;
413 LONG x, y;
415 EnterFunc(bug("VGAGfx.BitMap::BlitColorExpansion(%p, %d, %d, %d, %d, %d, %d)\n"
416 , msg->srcBitMap, msg->srcX, msg->srcY, msg->destX, msg->destY, msg->width, msg->height));
418 fg = GC_FG(msg->gc);
419 bg = GC_BG(msg->gc);
420 cemd = GC_COLEXP(msg->gc);
422 if (cemd & vHidd_GC_ColExp_Opaque)
424 for (y = 0; y < msg->height; y ++)
426 for (x = 0; x < msg->width; x ++)
428 ULONG is_set;
430 is_set = HIDD_BM_GetPixel(msg->srcBitMap, x + msg->srcX, y + msg->srcY);
432 *(data->VideoData + x + msg->destX + ((y + msg->destY) * data->width)) = is_set ? fg : bg;
434 } /* for (each x) */
436 } /* for (each y) */
439 else
441 for (y = 0; y < msg->height; y ++)
443 for (x = 0; x < msg->width; x ++)
445 ULONG is_set;
447 is_set = HIDD_BM_GetPixel(msg->srcBitMap, x + msg->srcX, y + msg->srcY);
449 if (is_set)
450 *(data->VideoData + x + msg->destX + ((y + msg->destY) * data->width)) = fg;
452 } /* for (each x) */
454 } /* for (each y) */
457 if (data->disp)
459 box.x1 = msg->destX;
460 box.y1 = msg->destY;
461 box.x2 = box.x1 + msg->width - 1;
462 box.y2 = box.y1 + msg->height - 1;
464 ObtainSemaphore(&XSD(cl)->HW_acc);
466 vgaRefreshArea(data, 1, &box);
467 if ( ( (XSD(cl)->mouseX + XSD(cl)->mouseW - 1 >= box.x1) &&
468 (XSD(cl)->mouseX <= box.x2) ) ||
469 ( (XSD(cl)->mouseY + XSD(cl)->mouseH - 1 >= box.y1) &&
470 (XSD(cl)->mouseY <= box.y2) ) )
471 draw_mouse(XSD(cl));
473 ReleaseSemaphore(&XSD(cl)->HW_acc);
476 ReturnVoid("VGAGfx.BitMap::BlitColorExpansion");
479 /*** BitMap::Get() *******************************************/
481 VOID MNAME_ROOT(Get)(OOP_Class *cl, OOP_Object *o, struct pRoot_Get *msg)
483 struct bitmap_data *data = OOP_INST_DATA(cl, o);
484 ULONG idx;
485 if (IS_VGABM_ATTR(msg->attrID, idx))
487 switch (idx)
489 case aoHidd_VGABitMap_Drawable:
490 *msg->storage = (ULONG)data->VideoData;
491 break;
493 default:
494 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
495 break;
498 else
500 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
503 return;