added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / arch / i386-pc / Drivers / vmwaregfx.hidd / bitmap_common.c
blob155d70fb5153d0758697ec68dba6ce027a56a00e
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
11 #include "svga_reg.h"
12 #include "hardware.h"
14 #undef DEBUG
15 #define DEBUG 0
16 #include <aros/debug.h>
19 /********* BitMap::Clear() *************************************/
20 VOID MNAME_BM(Clear)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_Clear *msg) {
21 D(bug("Clear\n"));
22 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
25 #if 0
27 /* this function does not really make sense for LUT bitmaps */
29 HIDDT_Pixel MNAME_BM(MapColor)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_MapColor *msg)
31 return i;
34 #endif
36 #if 0
38 /* this function does not really make sense for LUT bitmaps */
40 VOID MNAME_BM(UnMapPixel)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_UnmapPixel *msg)
44 #endif
46 BOOL MNAME_BM(SetColors)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_SetColors *msg) {
47 struct BitmapData *data = OOP_INST_DATA(cl, o);
48 HIDDT_PixelFormat *pf;
49 HIDDT_Pixel red;
50 HIDDT_Pixel green;
51 HIDDT_Pixel blue;
52 ULONG xc_i;
53 ULONG col_i;
55 pf = BM_PIXFMT(o);
56 if (
57 (vHidd_ColorModel_StaticPalette == HIDD_PF_COLMODEL(pf)) ||
58 (vHidd_ColorModel_TrueColor == HIDD_PF_COLMODEL(pf))
60 return OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
61 if (!OOP_DoSuperMethod(cl, o, (OOP_Msg)msg))
62 return FALSE;
63 if ((msg->firstColor + msg->numColors) > (1<<data->bpp))
64 return FALSE;
65 for (xc_i = msg->firstColor, col_i = 0; col_i < msg->numColors; xc_i++, col_i++)
67 red = msg->colors[col_i].red >> 8;
68 green = msg->colors[col_i].green >> 8;
69 blue = msg->colors[col_i].blue >> 8;
70 data->cmap[xc_i] = 0x01000000 | red | (green << 8) | (blue << 16);
71 #ifdef OnBitmap
72 vmwareWriteReg(data->data, SVGA_PALETTE_BASE + xc_i*3+0, msg->colors[col_i].red);
73 vmwareWriteReg(data->data, SVGA_PALETTE_BASE + xc_i*3+1, msg->colors[col_i].green);
74 vmwareWriteReg(data->data, SVGA_PALETTE_BASE + xc_i*3+2, msg->colors[col_i].blue);
75 #endif
76 msg->colors[col_i].pixval = xc_i;
78 return TRUE;
81 /********* BitMap::PutPixel() ***************************/
83 STATIC VOID putpixel(struct BitmapData *data, LONG x, LONG y, HIDDT_Pixel pixel) {
84 ULONG offset;
86 #ifdef OnBitmap
87 offset = (x*data->bytesperpix)+(y*data->data->bytesperline);
88 if (
89 (x>=data->mouse->x) && (x<(data->mouse->x+data->mouse->width)) &&
90 (y>=data->mouse->y) && (y<(data->mouse->y+data->mouse->height))
93 displayCursorVMWareGfx(data->data, 0);
94 data->mouse->visible = 0;
96 #else
97 offset = (x + (y*data->width))*data->bytesperpix;
98 #endif
99 if (data->bytesperpix == 1)
100 *((UBYTE*)(data->VideoData + offset)) = pixel;
101 else if (data->bytesperpix == 2)
102 *((UWORD*)(data->VideoData + offset)) = pixel;
103 else if (data->bytesperpix == 4)
104 *((ULONG*)(data->VideoData + offset)) = pixel;
105 #ifdef OnBitmap
106 if (data->mouse->visible == 0)
108 displayCursorVMWareGfx(data->data, 1);
109 data->mouse->visible = 1;
111 #endif
114 VOID MNAME_BM(PutPixel)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_PutPixel *msg) {
115 struct BitmapData *data = OOP_INST_DATA(cl, o);
116 struct Box box;
118 putpixel(data, msg->x, msg->y, msg->pixel);
119 #ifdef OnBitmap
120 box.x1 = box.x2 = msg->x;
121 box.y1 = box.y2 = msg->y;
122 refreshAreaVMWareGfx(data->data, &box);
123 #endif
124 return;
127 /********* BitMap::GetPixel() *********************************/
128 HIDDT_Pixel MNAME_BM(GetPixel)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_GetPixel *msg) {
129 HIDDT_Pixel pixel;
130 struct BitmapData *data = OOP_INST_DATA(cl, o);
131 ULONG offset;
133 #ifdef OnBitmap
134 offset = (msg->x*data->bytesperpix)+(msg->y*data->data->bytesperline);
135 #else
136 offset = (msg->x + (msg->y*data->width))*data->bytesperpix;
137 #endif
138 if (data->bytesperpix == 1)
139 pixel = *((UBYTE*)(data->VideoData + offset));
140 else if (data->bytesperpix == 2)
141 pixel = *((UWORD*)(data->VideoData + offset));
142 else if (data->bytesperpix == 4)
143 pixel = *((ULONG*)(data->VideoData + offset));
144 return pixel;
147 #if 0
149 /********* BitMap::DrawPixel() ***************************/
151 VOID MNAME_BM(DrawPixel)(OOP_Class *cl,OOP_ Object *o, struct pHidd_BitMap_DrawPixel *msg)
153 return;
156 #endif
158 /********* BitMap::PutImage() ***************************/
160 VOID MNAME_BM(PutImage)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_PutImage *msg) {
161 struct BitmapData *data = OOP_INST_DATA(cl, o);
162 struct Box box;
163 ULONG offset;
164 ULONG restadd;
165 UBYTE *buffer;
166 ULONG ycnt;
167 LONG xcnt;
168 UBYTE *src=(UBYTE *)msg->pixels;
170 if (msg->pixFmt == vHidd_StdPixFmt_Native32)
172 #ifdef OnBitmap
173 offset = (msg->x*data->bytesperpix)+(msg->y*data->data->bytesperline);
174 restadd = (data->data->bytesperline - (msg->width*data->bytesperpix));
175 #else
176 offset = (msg->x + (msg->y*data->width))*data->bytesperpix;
177 restadd = (data->width-msg->width)*data->bytesperpix;
178 #endif
179 buffer = data->VideoData+offset;
180 ycnt = msg->height;
181 while (ycnt>0)
183 HIDDT_Pixel *p = (HIDDT_Pixel *)src;
184 xcnt = msg->width;
185 while (xcnt)
187 if (data->bytesperpix == 1)
189 *((UBYTE *)buffer) = (UBYTE)*p++;
190 buffer++;
192 else if (data->bytesperpix == 2)
194 *((UWORD *)buffer) = (UWORD)*p++;
195 buffer += 2;
197 else if (data->bytesperpix == 4)
199 *((ULONG *)buffer) = (ULONG)*p++;
200 buffer += 4;
202 xcnt--;
204 buffer += restadd;
205 src += msg->modulo;
206 ycnt--;
208 #ifdef OnBitmap
209 box.x1 = msg->x;
210 box.y1 = msg->y;
211 box.x2 = box.x1+msg->width-1;
212 box.y2 = box.y1+msg->height-1;
213 refreshAreaVMWareGfx(data->data, &box);
214 #endif
216 else
218 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
222 /********* BitMap::GetImage() ***************************/
224 VOID MNAME_BM(GetImage)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_GetImage *msg) {
225 struct BitmapData *data = OOP_INST_DATA(cl, o);
226 ULONG offset;
227 ULONG restadd;
228 UBYTE *buffer;
229 ULONG ycnt;
230 LONG xcnt;
231 UBYTE *src=msg->pixels;
233 if (msg->pixFmt == vHidd_StdPixFmt_Native32)
235 #ifdef OnBitmap
236 offset = (msg->x*data->bytesperpix)+(msg->y*data->data->bytesperline);
237 restadd = (data->data->bytesperline - (msg->width*data->bytesperpix));
238 #else
239 offset = (msg->x + (msg->y*data->width))*data->bytesperpix;
240 restadd = (data->width-msg->width)*data->bytesperpix;
241 #endif
242 buffer = data->VideoData+offset;
243 ycnt = msg->height;
244 while (ycnt>0)
246 HIDDT_Pixel *p = (HIDDT_Pixel *)src;
247 xcnt = msg->width;
248 while (xcnt)
250 if (data->bytesperpix == 1)
252 *p++ = (HIDDT_Pixel)*((UBYTE *)buffer);
253 buffer++;
255 else if (data->bytesperpix == 2)
257 *p++ = (HIDDT_Pixel)*((UWORD *)buffer);
258 buffer += 2;
260 else if (data->bytesperpix == 4)
262 *p++ = (HIDDT_Pixel)*((ULONG *)buffer);
263 buffer += 4;
265 xcnt--;
267 buffer += restadd;
268 src += msg->modulo;
269 ycnt--;
272 else
274 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
278 /********* BitMap::PutImageLUT() ***************************/
280 VOID MNAME_BM(PutImageLUT)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_PutImageLUT *msg) {
281 struct BitmapData *data = OOP_INST_DATA(cl, o);
282 struct Box box;
283 ULONG offset;
284 ULONG restadd;
285 UBYTE *buffer;
286 ULONG ycnt;
287 LONG xcnt;
288 UBYTE *src=msg->pixels;
290 #ifdef OnBitmap
291 offset = (msg->x*data->bytesperpix)+(msg->y*data->data->bytesperline);
292 restadd = (data->data->bytesperline - (msg->width*data->bytesperpix));
293 #else
294 offset = (msg->x + (msg->y*data->width))*data->bytesperpix;
295 restadd = (data->width-msg->width)*data->bytesperpix;
296 #endif
297 buffer = data->VideoData+offset;
298 ycnt = msg->height;
299 while (ycnt>0)
301 xcnt = msg->width;
302 while (xcnt)
304 if (data->bytesperpix == 1)
306 *((UBYTE *)buffer) = (UBYTE)msg->pixlut->pixels[*src++];
307 buffer++;
309 else if (data->bytesperpix == 2)
311 *((UWORD *)buffer) = (UWORD)msg->pixlut->pixels[*src++];
312 buffer += 2;
314 else if (data->bytesperpix == 4)
316 *((ULONG *)buffer) = (ULONG)msg->pixlut->pixels[*src++];
317 buffer += 4;
319 xcnt--;
321 buffer += restadd;
322 src += (msg->modulo - msg->width);
323 ycnt--;
325 #ifdef OnBitmap
326 box.x1 = msg->x;
327 box.y1 = msg->y;
328 box.x2 = box.x1+msg->width-1;
329 box.y2 = box.y1+msg->height-1;
330 refreshAreaVMWareGfx(data->data, &box);
331 #endif
334 /********* BitMap::GetImageLUT() ***************************/
336 VOID MNAME_BM(GetImageLUT)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_GetImageLUT *msg)
338 D(bug("get image lut\n"));
339 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
342 /********* BitMap::FillRect() ***************************/
344 VOID MNAME_BM(FillRect)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_DrawRect *msg)
346 struct BitmapData *data =OOP_INST_DATA(cl, o);
347 struct HWData *hw;
348 HIDDT_Pixel pixel;
349 HIDDT_DrawMode mode;
351 #ifdef OnBitmap
352 pixel = GC_FG(msg->gc);
353 mode = GC_DRMD(msg->gc);
354 hw = data->data;
355 if (hw->capabilities & SVGA_CAP_RASTER_OP)
357 switch (mode)
359 case vHidd_GC_DrawMode_Clear:
360 clearFillVMWareGfx(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
361 break;
362 case vHidd_GC_DrawMode_And:
363 andFillVMWareGfx(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
364 break;
365 case vHidd_GC_DrawMode_AndReverse:
366 andReverseFillVMWareGfx(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
367 break;
368 case vHidd_GC_DrawMode_Copy:
369 copyFillVMWareGfx(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
370 break;
371 case vHidd_GC_DrawMode_AndInverted:
372 andInvertedFillVMWareGfx(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
373 break;
374 case vHidd_GC_DrawMode_NoOp:
375 noOpFillVMWareGfx(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
376 break;
377 case vHidd_GC_DrawMode_Xor:
378 xorFillVMWareGfx(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
379 break;
380 case vHidd_GC_DrawMode_Or:
381 orFillVMWareGfx(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
382 break;
383 case vHidd_GC_DrawMode_Nor:
384 norFillVMWareGfx(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
385 break;
386 case vHidd_GC_DrawMode_Equiv:
387 equivFillVMWareGfx(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
388 break;
389 case vHidd_GC_DrawMode_Invert:
390 invertFillVMWareGfx(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
391 break;
392 case vHidd_GC_DrawMode_OrReverse:
393 orReverseFillVMWareGfx(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
394 break;
395 case vHidd_GC_DrawMode_CopyInverted:
396 copyInvertedFillVMWareGfx(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
397 break;
398 case vHidd_GC_DrawMode_OrInverted:
399 orInvertedFillVMWareGfx(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
400 break;
401 case vHidd_GC_DrawMode_Nand:
402 nandFillVMWareGfx(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
403 break;
404 case vHidd_GC_DrawMode_Set:
405 setFillVMWareGfx(data->data, pixel, msg->minX, msg->minY, msg->maxX-msg->minX+1, msg->maxY-msg->minY+1);
406 break;
407 default:
408 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
409 break;
412 else
414 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
416 #else
417 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
418 #endif
421 /*** BitMap::BlitColorExpansion() **********************************************/
422 VOID MNAME_BM(BlitColorExpansion)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_BlitColorExpansion *msg) {
423 struct BitmapData *data = OOP_INST_DATA(cl, o);
424 struct Box box;
425 ULONG cemd;
426 HIDDT_Pixel fg;
427 HIDDT_Pixel bg;
428 LONG x;
429 LONG y;
431 fg = GC_FG(msg->gc);
432 bg = GC_BG(msg->gc);
433 cemd = GC_COLEXP(msg->gc);
434 if (cemd & vHidd_GC_ColExp_Opaque)
436 for (y=0; y<msg->height; y++)
438 for (x=0;x<msg->width;x++)
440 ULONG is_set;
441 is_set = HIDD_BM_GetPixel(msg->srcBitMap, x+msg->srcX, y+msg->srcY);
442 putpixel(data, x+msg->destX, y+msg->destY, is_set ? fg : bg);
446 else
448 for (y=0; y<msg->height; y++)
450 for (x=0;x<msg->width; x++)
452 if (HIDD_BM_GetPixel(msg->srcBitMap, x+msg->srcX, y+msg->srcY))
453 putpixel(data, x+msg->destX, y+msg->destY, fg);
457 #ifdef OnBitmap
458 box.x1 = msg->destX;
459 box.y1 = msg->destY;
460 box.x2 = msg->destX+msg->width-1;
461 box.y2 = msg->destY+msg->height-1;
462 refreshAreaVMWareGfx(data->data, &box);
463 #endif
466 /*** BitMap::Get() *******************************************/
468 VOID MNAME_ROOT(Get)(OOP_Class *cl, OOP_Object *o, struct pRoot_Get *msg) {
469 struct BitmapData *data = OOP_INST_DATA(cl, o);
470 ULONG idx;
472 if (IS_VMWareGfxBM_ATTR(msg->attrID, idx))
474 switch (idx)
476 case aoHidd_VMWareGfxBitMap_Drawable:
477 *msg->storage = (ULONG)data->VideoData;
478 break;
479 default:
480 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
483 else
485 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);