Hint added.
[AROS.git] / workbench / hidds / sm502 / bitmap.c
blobc820a668a66f0554332726d5cf653cd3058fa56a
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Bitmap class for SM502 hidd.
6 Lang: English.
7 */
9 #define __OOP_NOATTRBASES__
11 #include <proto/oop.h>
12 #include <proto/utility.h>
13 #include <assert.h>
14 #include <exec/memory.h>
15 #include <exec/lists.h>
16 #include <graphics/rastport.h>
17 #include <graphics/gfx.h>
18 #include <hidd/graphics.h>
19 #include <oop/oop.h>
20 #include <aros/symbolsets.h>
21 #include <aros/debug.h>
23 #include <string.h>
25 #include "bitmap.h"
26 #include "sm502gfxclass.h"
28 #include LC_LIBDEFS_FILE
30 #define MNAME_ROOT(x) SM502BM__Root__ ## x
31 #define MNAME_BM(x) SM502BM__Hidd_BitMap__ ## x
33 /*********** BitMap::New() *************************************/
34 OOP_Object *MNAME_ROOT(New)(OOP_Class *cl, OOP_Object *o, struct pRoot_New *msg)
36 EnterFunc(bug("SM502Gfx.BitMap::New()\n"));
38 o = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg) msg);
39 if (o)
41 OOP_MethodID disp_mid;
42 struct BitmapData *data;
43 HIDDT_ModeID modeid;
44 OOP_Object *sync, *pf;
46 data = OOP_INST_DATA(cl, o);
48 /* Get attr values */
49 OOP_GetAttr(o, aHidd_BitMap_GfxHidd , (APTR)&data->gfxhidd);
50 OOP_GetAttr(o, aHidd_BitMap_PixFmt , (APTR)&data->pixfmtobj);
51 OOP_GetAttr(o, aHidd_BitMap_ModeID , &modeid);
52 OOP_GetAttr(o, aHidd_ChunkyBM_Buffer, (IPTR *)&data->VideoData);
54 HIDD_Gfx_GetMode(data->gfxhidd, modeid, &sync, &pf);
56 data->width = OOP_GET(o, aHidd_BitMap_Width);
57 data->height = OOP_GET(o, aHidd_BitMap_Height);
58 data->bytesperline = OOP_GET(o, aHidd_BitMap_BytesPerRow);
59 data->bytesperpix = OOP_GET(data->pixfmtobj, aHidd_PixFmt_BytesPerPixel);
60 data->disp_width = OOP_GET(sync, aHidd_Sync_HDisp);
61 data->disp_height = OOP_GET(sync, aHidd_Sync_VDisp);
63 D(bug("[SM502BitMap] Bitmap %ld x % ld, %u bytes per pixel, %u bytes per line\n",
64 data->width, data->height, data->bytesperpix, data->bytesperline));
65 D(bug("[SM502BitMap] Video data at 0x%p (%u bytes)\n", data->VideoData, data->bytesperline * data->height));
67 if (OOP_GET(data->pixfmtobj, aHidd_PixFmt_ColorModel) != vHidd_ColorModel_Palette)
68 ReturnPtr("SM502Gfx.BitMap::New()", OOP_Object *, o);
70 data->DAC = AllocMem(768, MEMF_ANY);
71 D(bug("[SM502BitMap] Palette data at 0x%p\n", data->DAC));
72 if (data->DAC)
73 ReturnPtr("SM502Gfx.BitMap::New()", OOP_Object *, o);
75 disp_mid = OOP_GetMethodID(IID_Root, moRoot_Dispose);
77 OOP_CoerceMethod(cl, o, (OOP_Msg) &disp_mid);
78 o = NULL;
79 } /* if created object */
81 ReturnPtr("SM502Gfx.BitMap::New()", OOP_Object *, o);
84 /********** Bitmap::Dispose() ***********************************/
85 VOID MNAME_ROOT(Dispose)(OOP_Class *cl, OOP_Object *o, OOP_Msg msg)
87 struct BitmapData *data = OOP_INST_DATA(cl, o);
89 D(bug("[SM502BitMap] Dispose(0x%p)\n", o));
91 if (data->DAC)
92 FreeMem(data->DAC, 768);
94 OOP_DoSuperMethod(cl, o, msg);
96 ReturnVoid("SM502Gfx.BitMap::Dispose");
99 /*** BitMap::Get() *******************************************/
101 VOID MNAME_ROOT(Get)(OOP_Class *cl, OOP_Object *o, struct pRoot_Get *msg)
103 struct BitmapData *data = OOP_INST_DATA(cl, o);
104 ULONG idx;
106 if (IS_BM_ATTR(msg->attrID, idx))
108 switch (idx)
110 case aoHidd_BitMap_Visible:
111 *msg->storage = data->disp;
112 return;
114 case aoHidd_BitMap_LeftEdge:
115 *msg->storage = data->xoffset;
116 return;
118 case aoHidd_BitMap_TopEdge:
119 *msg->storage = data->yoffset;
120 return;
123 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
126 /*** BitMap::Set() *******************************************/
128 VOID MNAME_ROOT(Set)(OOP_Class *cl, OOP_Object *o, struct pRoot_Set *msg)
130 struct BitmapData *data = OOP_INST_DATA(cl, o);
131 struct TagItem *tag, *tstate;
132 ULONG idx;
133 LONG xoffset = data->xoffset;
134 LONG yoffset = data->yoffset;
135 LONG limit;
137 tstate = msg->attrList;
138 while((tag = NextTagItem(&tstate)))
140 if(IS_BM_ATTR(tag->ti_Tag, idx))
142 switch(idx)
144 case aoHidd_BitMap_Visible:
145 D(bug("[SM502BitMap] Setting Visible to %d\n", tag->ti_Data));
146 data->disp = tag->ti_Data;
147 if (data->disp) {
148 if (data->DAC)
149 DACLoad(XSD(cl), data->DAC, 0, 256);
151 break;
152 case aoHidd_BitMap_LeftEdge:
153 xoffset = tag->ti_Data;
154 /* Our bitmap can not be smaller than display size
155 because of fakegfx.hidd limitations (it can't place
156 cursor beyond bitmap edges). Otherwize Intuition
157 will provide strange user experience (mouse cursor will
158 disappear) */
159 limit = data->disp_width - data->width;
160 if (xoffset > 0)
161 xoffset = 0;
162 else if (xoffset < limit)
163 xoffset = limit;
164 break;
165 case aoHidd_BitMap_TopEdge:
166 yoffset = tag->ti_Data;
167 limit = data->disp_height - data->height;
168 if (yoffset > 0)
169 yoffset = 0;
170 else if (yoffset < limit)
171 yoffset = limit;
172 break;
177 if ((xoffset != data->xoffset) || (yoffset != data->yoffset))
179 D(bug("[SM502BitMap] Scroll to (%d, %d)\n", xoffset, yoffset));
180 data->xoffset = xoffset;
181 data->yoffset = yoffset;
183 if (data->disp)
185 LOCK_FRAMEBUFFER(XSD(cl));
186 sm502DoRefreshArea(&XSD(cl)->data, data, 0, 0, data->width, data->height);
187 UNLOCK_FRAMEBUFFER(XSD(cl));
191 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
194 /*** BitMap::SetColors() *************************************/
196 BOOL MNAME_BM(SetColors)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_SetColors *msg)
198 struct BitmapData *data = OOP_INST_DATA(cl, o);
199 struct SM502_HWData *hwdata = &XSD(cl)->data;
200 ULONG xc_i, col_i;
201 UBYTE p_shift;
202 UWORD red, green, blue;
204 D(bug("[SM502BitMap] SetColors(%u, %u)\n", msg->firstColor, msg->numColors));
206 if (!OOP_DoSuperMethod(cl, o, (OOP_Msg)msg)) {
207 D(bug("[SM502BitMap] DoSuperMethod() failed\n"));
208 return FALSE;
211 if ((msg->firstColor + msg->numColors) > (1 << data->bpp))
212 return FALSE;
214 if (data->DAC) {
215 for ( xc_i = msg->firstColor, col_i = 0;
216 col_i < msg->numColors;
217 xc_i ++, col_i ++) {
218 red = msg->colors[col_i].red >> 8;
219 green = msg->colors[col_i].green >> 8;
220 blue = msg->colors[col_i].blue >> 8;
222 /* Update DAC registers */
223 p_shift = 8 - hwdata->palettewidth;
224 data->DAC[xc_i*3] = red >> p_shift;
225 data->DAC[xc_i*3+1] = green >> p_shift;
226 data->DAC[xc_i*3+2] = blue >> p_shift;
229 /* Upload palette to the DAC if the current bitmap is on display */
230 if (data->disp)
231 DACLoad(XSD(cl), data->DAC, msg->firstColor, msg->numColors);
233 return TRUE;
236 VOID MNAME_BM(UpdateRect)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_UpdateRect *msg)
238 struct BitmapData *data = OOP_INST_DATA(cl, o);
240 D(bug("[SM502BitMap] UpdateRect(%d, %d, %d, %d), bitmap 0x%p\n", msg->x, msg->y, msg->width, msg->height, o));
241 if (data->disp) {
242 LOCK_FRAMEBUFFER(XSD(cl));
243 sm502DoRefreshArea(&XSD(cl)->data, data, msg->x, msg->y, msg->x + msg->width, msg->y + msg->height);
244 UNLOCK_FRAMEBUFFER(XSD(cl));