adapt all gfx drivers to use the new gfx.hidd CreateObject API.
[AROS.git] / workbench / hidds / sm502 / sm502gfxclass.c
blob9570e4b0a1804edf95cf4f5818a50d13a0ef7a0c
1 /*
2 Copyright © 1995-2015, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Class for SM502.
6 Lang: English.
7 */
9 #define __OOP_NOATTRBASES__
11 #include <aros/debug.h>
13 #include <aros/asmcall.h>
14 #include <proto/exec.h>
15 #include <proto/oop.h>
16 #include <proto/utility.h>
17 #include <aros/symbolsets.h>
18 #include <devices/inputevent.h>
19 #include <exec/alerts.h>
20 #include <exec/memory.h>
21 #include <hardware/custom.h>
22 #include <hidd/hidd.h>
23 #include <hidd/graphics.h>
24 #include <oop/oop.h>
25 #include <clib/alib_protos.h>
26 #include <string.h>
28 #include "sm502gfxclass.h"
29 #include "bitmap.h"
30 #include "hardware.h"
32 #include LC_LIBDEFS_FILE
34 static AROS_INTH1(ResetHandler, struct SM502_HWData *, hwdata)
36 AROS_INTFUNC_INIT
38 ClearBuffer(hwdata);
40 return FALSE;
42 AROS_INTFUNC_EXIT
45 OOP_Object *SM502__Root__New(OOP_Class *cl, OOP_Object *o, struct pRoot_New *msg)
47 struct TagItem pftags[] =
49 {aHidd_PixFmt_RedShift, 0}, /* 0 */
50 {aHidd_PixFmt_GreenShift, 0}, /* 1 */
51 {aHidd_PixFmt_BlueShift, 0}, /* 2 */
52 {aHidd_PixFmt_AlphaShift, 0}, /* 3 */
53 {aHidd_PixFmt_RedMask, 0}, /* 4 */
54 {aHidd_PixFmt_GreenMask, 0}, /* 5 */
55 {aHidd_PixFmt_BlueMask, 0}, /* 6 */
56 {aHidd_PixFmt_AlphaMask, 0}, /* 7 */
57 {aHidd_PixFmt_ColorModel, 0}, /* 8 */
58 {aHidd_PixFmt_Depth, 0}, /* 9 */
59 {aHidd_PixFmt_BytesPerPixel,0}, /* 10 */
60 {aHidd_PixFmt_BitsPerPixel, 0}, /* 11 */
61 {aHidd_PixFmt_StdPixFmt, vHidd_StdPixFmt_Native}, /* 12 */
62 {aHidd_PixFmt_CLUTShift, 0}, /* 13 */
63 {aHidd_PixFmt_CLUTMask, 0}, /* 14 */
64 {aHidd_PixFmt_BitMapType, vHidd_BitMapType_Chunky}, /* 15 */
65 {TAG_DONE, 0UL }
67 struct TagItem sync_mode[] =
69 {aHidd_Sync_HDisp, 0},
70 {aHidd_Sync_VDisp, 0},
71 {aHidd_Sync_HMax, 16384},
72 {aHidd_Sync_VMax, 16384},
73 {aHidd_Sync_Description, (IPTR)"SM502:%hx%v"},
74 {TAG_DONE, 0UL}
76 struct TagItem modetags[] =
78 {aHidd_Gfx_PixFmtTags, (IPTR)pftags},
79 {aHidd_Gfx_SyncTags, (IPTR)sync_mode},
80 {TAG_DONE, 0UL}
82 struct TagItem yourtags[] =
84 {aHidd_Gfx_ModeTags, (IPTR)modetags},
85 {TAG_MORE, 0UL}
87 struct pRoot_New yourmsg;
89 /* Protect against some stupid programmer wishing to
90 create one more SM502 driver */
91 if (XSD(cl)->sm502gfxhidd)
92 return NULL;
94 pftags[0].ti_Data = XSD(cl)->data.redshift;
95 pftags[1].ti_Data = XSD(cl)->data.greenshift;
96 pftags[2].ti_Data = XSD(cl)->data.blueshift;
97 pftags[4].ti_Data = XSD(cl)->data.redmask;
98 pftags[5].ti_Data = XSD(cl)->data.greenmask;
99 pftags[6].ti_Data = XSD(cl)->data.bluemask;
100 pftags[8].ti_Data = (XSD(cl)->data.depth > 8) ? vHidd_ColorModel_TrueColor : vHidd_ColorModel_Palette;
101 pftags[9].ti_Data = (XSD(cl)->data.depth > 24) ? 24 : XSD(cl)->data.depth;
102 pftags[10].ti_Data = XSD(cl)->data.bytesperpixel;
103 pftags[11].ti_Data = (XSD(cl)->data.bitsperpixel > 24) ? 24 : XSD(cl)->data.bitsperpixel;
104 pftags[14].ti_Data = (1 << XSD(cl)->data.depth) - 1;
106 sync_mode[0].ti_Data = XSD(cl)->data.width;
107 sync_mode[1].ti_Data = XSD(cl)->data.height;
109 yourtags[1].ti_Data = (IPTR)msg->attrList;
110 yourmsg.mID = msg->mID;
111 yourmsg.attrList = yourtags;
112 msg = &yourmsg;
113 EnterFunc(bug("SM502Gfx::New()\n"));
114 o = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
115 if (o)
117 struct SM502Gfx_data *data = OOP_INST_DATA(cl, o);
119 D(bug("Got object from super\n"));
120 XSD(cl)->sm502gfxhidd = o;
122 data->ResetInterrupt.is_Code = (APTR)ResetHandler;
123 data->ResetInterrupt.is_Data = &XSD(cl)->data;
124 AddResetCallback(&data->ResetInterrupt);
126 ReturnPtr("SM502Gfx::New", OOP_Object *, o);
129 VOID SM502__Root__Dispose(OOP_Class *cl, OOP_Object *o, OOP_Msg msg)
131 struct SM502Gfx_data *data = OOP_INST_DATA(cl, o);
133 RemResetCallback(&data->ResetInterrupt);
134 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
135 XSD(cl)->sm502gfxhidd = NULL;
138 VOID SM502__Root__Get(OOP_Class *cl, OOP_Object *o, struct pRoot_Get *msg)
140 ULONG idx;
142 if (IS_GFX_ATTR(msg->attrID, idx))
144 switch (idx)
146 case aoHidd_Gfx_NoFrameBuffer:
147 *msg->storage = TRUE;
148 return;
151 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
154 OOP_Object *SM502__Hidd_Gfx__CreateObject(OOP_Class *cl, OOP_Object *o, struct pHidd_Gfx_CreateObject *msg)
156 OOP_Object *object = NULL;
158 EnterFunc(bug("SM502Gfx::CreateObject()\n"));
160 if (msg->cl == XSD(cl)->basebm)
162 BOOL displayable;
163 struct TagItem tags[2] =
165 {TAG_IGNORE, 0 },
166 {TAG_MORE , (IPTR)msg->attrList}
168 struct pHidd_Gfx_CreateObject p;
170 displayable = GetTagData(aHidd_BitMap_Displayable, FALSE, msg->attrList);
171 if (displayable)
173 /* Only displayable bitmaps are bitmaps of our class */
174 tags[0].ti_Tag = aHidd_BitMap_ClassPtr;
175 tags[0].ti_Data = (IPTR)XSD(cl)->bmclass;
177 else
179 /* Non-displayable friends of our bitmaps are plain chunky bitmaps */
180 OOP_Object *friend = (OOP_Object *)GetTagData(aHidd_BitMap_Friend, 0, msg->attrList);
182 if (friend && (OOP_OCLASS(friend) == XSD(cl)->bmclass))
184 tags[0].ti_Tag = aHidd_BitMap_ClassID;
185 tags[0].ti_Data = (IPTR)CLID_Hidd_ChunkyBM;
189 p.mID = msg->mID;
190 p.cl = msg->cl;
191 p.attrList = tags;
193 object = OOP_DoSuperMethod(cl, o, (OOP_Msg)&p);
195 else
196 object = OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
198 ReturnPtr("SM502Gfx::CreateObject", OOP_Object *, object);
201 /********* GfxHidd::Show() ***************************/
203 OOP_Object *SM502__Hidd_Gfx__Show(OOP_Class *cl, OOP_Object *o, struct pHidd_Gfx_Show *msg)
205 struct SM502Gfx_staticdata *data = XSD(cl);
206 struct TagItem tags[] = {
207 {aHidd_BitMap_Visible, FALSE},
208 {TAG_DONE , 0 }
211 D(bug("[SM502Gfx] Show(0x%p), old visible 0x%p\n", msg->bitMap, data->visible));
213 LOCK_FRAMEBUFFER(data);
215 /* Remove old bitmap from the screen */
216 if (data->visible)
218 D(bug("[SM502Gfx] Hiding old bitmap\n"));
219 OOP_SetAttrs(data->visible, tags);
222 if (msg->bitMap)
224 /* If we have a bitmap to show, set it as visible */
225 D(bug("[SM502Gfx] Showing new bitmap\n"));
226 tags[0].ti_Data = TRUE;
227 OOP_SetAttrs(msg->bitMap, tags);
229 else
231 D(bug("[SM502Gfx] Blanking screen\n"));
232 /* Otherwise simply clear the framebuffer */
233 ClearBuffer(&data->data);
236 data->visible = msg->bitMap;
237 UNLOCK_FRAMEBUFFER(data);
239 D(bug("[SM502Gfx] Show() done\n"));
240 return msg->bitMap;