2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
5 Desc: Bitmap class for SM502 hidd.
9 #define __OOP_NOATTRBASES__
11 #include <proto/oop.h>
12 #include <proto/utility.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>
20 #include <aros/symbolsets.h>
21 #include <aros/debug.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
);
41 OOP_MethodID disp_mid
;
42 struct BitmapData
*data
;
44 OOP_Object
*sync
, *pf
;
46 data
= OOP_INST_DATA(cl
, o
);
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
));
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
);
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
));
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
);
106 if (IS_BM_ATTR(msg
->attrID
, idx
))
110 case aoHidd_BitMap_Visible
:
111 *msg
->storage
= data
->disp
;
114 case aoHidd_BitMap_LeftEdge
:
115 *msg
->storage
= data
->xoffset
;
118 case aoHidd_BitMap_TopEdge
:
119 *msg
->storage
= data
->yoffset
;
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
;
133 LONG xoffset
= data
->xoffset
;
134 LONG yoffset
= data
->yoffset
;
137 tstate
= msg
->attrList
;
138 while((tag
= NextTagItem(&tstate
)))
140 if(IS_BM_ATTR(tag
->ti_Tag
, idx
))
144 case aoHidd_BitMap_Visible
:
145 D(bug("[SM502BitMap] Setting Visible to %d\n", tag
->ti_Data
));
146 data
->disp
= tag
->ti_Data
;
149 DACLoad(XSD(cl
), data
->DAC
, 0, 256);
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
159 limit
= data
->disp_width
- data
->width
;
162 else if (xoffset
< limit
)
165 case aoHidd_BitMap_TopEdge
:
166 yoffset
= tag
->ti_Data
;
167 limit
= data
->disp_height
- data
->height
;
170 else if (yoffset
< limit
)
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
;
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
;
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"));
211 if ((msg
->firstColor
+ msg
->numColors
) > (1 << data
->bpp
))
215 for ( xc_i
= msg
->firstColor
, col_i
= 0;
216 col_i
< msg
->numColors
;
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 */
231 DACLoad(XSD(cl
), data
->DAC
, msg
->firstColor
, msg
->numColors
);
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
));
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
));