tools/adflib: build only host variant which is used by Sam440 target
[AROS.git] / arch / m68k-amiga / hidd / gfx / amigavideogfx.c
blob1c44209742ba1965d2eac9c1d5006fb7f1060bce
1 /*
2 Copyright © 1995-2015, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English.
7 */
9 #include <exec/libraries.h>
10 #include <exec/rawfmt.h>
11 #include <exec/types.h>
12 #include <exec/resident.h>
13 #include <exec/memory.h>
14 #include <graphics/displayinfo.h>
15 #include <aros/libcall.h>
16 #include <proto/alib.h>
17 #include <proto/exec.h>
18 #include <proto/graphics.h>
19 #include <proto/kernel.h>
20 #include <proto/oop.h>
21 #include <proto/utility.h>
22 #include <oop/oop.h>
24 #include <hidd/hidd.h>
25 #include <hidd/graphics.h>
27 #include <aros/symbolsets.h>
29 #include "amigavideogfx.h"
30 #include "amigavideobitmap.h"
32 #include "chipset.h"
33 #include "blitter.h"
35 #include LC_LIBDEFS_FILE
37 #define SDEBUG 0
38 #define DEBUG 0
39 #include <aros/debug.h>
41 #define SPECIALMODES 3
42 #define NATIVEMODES (3 * 4 * SPECIALMODES)
43 static const UWORD widthtable[] = { 320, 640, 1280, 0 };
44 static const UWORD heighttable[] = { 200, 256, 400, 512, 0 };
45 static const ULONG specialmask_aga[] = { 0, EXTRAHALFBRITE_KEY, HAM_KEY, 0xffffffff };
47 #define SPECIAL_MODE_MASK (EXTRAHALFBRITE_KEY | HAM_KEY)
49 VOID AmigaVideoCl__Hidd_Gfx__NominalDimensions(OOP_Class *cl, OOP_Object *o, struct pHidd_Gfx_NominalDimensions *msg)
51 struct amigavideo_staticdata *csd = CSD(cl);
52 struct GfxBase *GfxBase = (struct GfxBase *)csd->cs_GfxBase;
54 DB2(bug("NominalDimensions()\n"));
56 if (msg->width)
57 *(msg->width) = GfxBase->NormalDisplayColumns;
58 if (msg->height)
59 *(msg->height) = GfxBase->NormalDisplayRows;
60 if (msg->depth)
61 *(msg->depth) = 1;
64 ULONG AmigaVideoCl__Hidd_Gfx__ModeProperties(OOP_Class *cl, OOP_Object *o, struct pHidd_Gfx_ModeProperties *msg)
66 ULONG flags = 0;
67 ULONG modeid = msg->modeID;
69 flags = DIPF_IS_SPRITES | DIPF_IS_DRAGGABLE |
70 DIPF_IS_SPRITES_ATT | DIPF_IS_SPRITES_CHNG_BASE | DIPF_IS_SPRITES_CHNG_PRI |
71 DIPF_IS_DBUFFER | DIPF_IS_BEAMSYNC | DIPF_IS_GENLOCK;
72 msg->props->NumHWSprites = 8;
73 if ((modeid & MONITOR_ID_MASK) == PAL_MONITOR_ID)
74 flags |= DIPF_IS_PAL;
75 if (modeid & LORESLACE_KEY)
76 flags |= DIPF_IS_LACE;
77 if (modeid & HAM_KEY) {
78 flags |= DIPF_IS_HAM;
79 if (modeid & SUPER_KEY)
80 flags |= DIPF_IS_AA;
82 if (modeid & EXTRAHALFBRITE_KEY) {
83 flags |= DIPF_IS_EXTRAHALFBRITE;
84 if (modeid & SUPER_KEY)
85 flags |= DIPF_IS_AA;
87 if ((modeid & SUPER_KEY) == SUPER_KEY && !(flags & DIPF_IS_AA))
88 flags |= DIPF_IS_ECS;
89 if (!(modeid & SPECIAL_MODE_MASK))
90 flags |= DIPF_IS_WB;
91 msg->props->DisplayInfoFlags = flags;
92 msg->props->CompositionFlags = COMPF_ABOVE | COMPF_BELOW; // | COMPF_LEFT | COMPF_RIGHT;
93 DB2(bug("ModeProp %08x = %08x\n", modeid, flags));
94 return sizeof(struct HIDD_ModeProperties);
97 HIDDT_ModeID *AmigaVideoCl__Hidd_Gfx__QueryModeIDs(OOP_Class *cl, OOP_Object *o, struct pHidd_Gfx_QueryModeIDs *msg)
99 struct amigavideo_staticdata *csd = CSD(cl);
100 struct NativeChipsetMode *node;
101 struct TagItem *tag, *tstate;
102 ULONG minwidth = 0, maxwidth = 0xFFFFFFFF;
103 ULONG minheight = 0, maxheight = 0xFFFFFFFF;
104 HIDDT_ModeID *modeids;
105 struct Library *UtilityBase = csd->cs_UtilityBase;
106 WORD cnt;
108 if (csd->superforward)
109 return (HIDDT_ModeID*)OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
111 for (tstate = msg->queryTags; (tag = NextTagItem(&tstate)); )
113 switch (tag->ti_Tag)
115 case tHidd_GfxMode_MinWidth:
116 minwidth = (ULONG)tag->ti_Tag;
117 break;
119 case tHidd_GfxMode_MaxWidth:
120 maxwidth = (ULONG)tag->ti_Tag;
121 break;
123 case tHidd_GfxMode_MinHeight:
124 minheight = (ULONG)tag->ti_Tag;
125 break;
127 case tHidd_GfxMode_MaxHeight:
128 maxheight = (ULONG)tag->ti_Tag;
129 break;
131 case tHidd_GfxMode_PixFmts:
132 /* all chipset modes have same pixelformat */
133 break;
137 DB2(bug("QueryModeIDs (%dx%d)-(%dx%d)\n", minwidth, minheight, maxwidth, maxheight));
138 cnt = 0;
139 ForeachNode(&csd->nativemodelist, node) {
140 if (node->width >= minwidth && node->width <= maxwidth && node->height >= minheight && node->height <= maxheight) {
141 cnt++;
144 modeids = AllocVec((cnt + 1) * sizeof(HIDDT_ModeID), MEMF_PUBLIC);
145 if (!modeids)
146 return NULL;
147 cnt = 0;
148 ForeachNode(&csd->nativemodelist, node) {
149 if (node->width >= minwidth && node->width <= maxwidth && node->height >= minheight && node->height <= maxheight) {
150 DB2(bug("%d: %08x\n", cnt, node->modeid));
151 modeids[cnt++] = node->modeid;
154 modeids[cnt] = vHidd_ModeID_Invalid;
155 return modeids;
158 VOID AmigaVideoCl__Hidd_Gfx__ReleaseModeIDs(OOP_Class *cl, OOP_Object *o, struct pHidd_Gfx_ReleaseModeIDs *msg)
160 struct amigavideo_staticdata *csd = CSD(cl);
161 if (csd->superforward)
162 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
163 else
164 FreeVec(msg->modeIDs);
167 HIDDT_ModeID AmigaVideoCl__Hidd_Gfx__NextModeID(OOP_Class *cl, OOP_Object *o, struct pHidd_Gfx_NextModeID *msg)
169 struct amigavideo_staticdata *csd = CSD(cl);
170 struct NativeChipsetMode *node = NULL;
171 HIDDT_ModeID mid = vHidd_ModeID_Invalid;
173 DB2(bug("NextModeID %08x\n", msg->modeID));
174 if (msg->modeID != vHidd_ModeID_Invalid) {
175 ForeachNode(&csd->nativemodelist, node) {
176 if (node->modeid == msg->modeID) {
177 node = (struct NativeChipsetMode*)node->node.ln_Succ;
178 break;
182 if (!node)
183 node = (struct NativeChipsetMode*)csd->nativemodelist.lh_Head;
184 if (node->node.ln_Succ) {
185 mid = node->modeid;
186 *msg->syncPtr = node->sync;
187 *msg->pixFmtPtr = node->pf;
189 DB2(bug("=%08x %p %p\n", mid, *msg->syncPtr, *msg->pixFmtPtr));
190 return mid;
193 BOOL AmigaVideoCl__Hidd_Gfx__GetMode(OOP_Class *cl, OOP_Object *o, struct pHidd_Gfx_GetMode *msg)
195 struct amigavideo_staticdata *csd = CSD(cl);
196 struct NativeChipsetMode *node;
198 if (csd->superforward)
199 return (BOOL)OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
201 DB2(bug("GetMode %08x\n", msg->modeID));
202 ForeachNode(&csd->nativemodelist, node) {
203 if (node->modeid == msg->modeID) {
204 *msg->syncPtr = node->sync;
205 *msg->pixFmtPtr = node->pf;
206 DB2(bug("= %p %p %dx%dx%d %d\n", node->sync, node->pf, node->width, node->height, node->depth, node->special));
207 return TRUE;
210 DB2(bug("= FAIL\n"));
211 return FALSE;
214 #define ADDTAG(tag,data) { *tagptr++ = tag; *tagptr++ = data; }
217 static void makemodename(ULONG modeid, UBYTE *bufptr)
219 BOOL special = FALSE;
221 special = (modeid & SPECIAL_MODE_MASK) != 0;
222 bufptr[0] = 0;
223 if ((modeid & MONITOR_ID_MASK) == PAL_MONITOR_ID)
224 strcat(bufptr, "PAL");
225 else if ((modeid & MONITOR_ID_MASK) == NTSC_MONITOR_ID)
226 strcat (bufptr, "NTSC");
227 strcat(bufptr, ":");
228 if ((modeid & (HIRES_KEY | SUPER_KEY)) == LORES_KEY)
229 strcat(bufptr, special ? "LowRes" : "Low Res");
230 else if ((modeid & (HIRES_KEY | SUPER_KEY)) == HIRES_KEY)
231 strcat(bufptr, special ? "HighRes" : "High Res");
232 else
233 strcat(bufptr, special ? "SuperHighRes" : "Super-High Res");
234 if (modeid & HAM_KEY)
235 strcat(bufptr, " HAM");
236 if (modeid & EXTRAHALFBRITE_KEY)
237 strcat(bufptr, " EHB");
238 if ((modeid & LORESDPF2_KEY) == LORESDPF_KEY)
239 strcat(bufptr, " DualPF");
240 if ((modeid & LORESDPF2_KEY) == LORESDPF2_KEY)
241 strcat(bufptr, " DualPF2");
242 if (modeid & LORESLACE_KEY)
243 strcat(bufptr, special ? " Interlace" : " Laced");
244 DB2(bug("%08x '%s'\n", modeid, bufptr));
247 static struct NativeChipsetMode *addmodeid(struct amigavideo_staticdata *csd, ULONG modeid, WORD w, WORD h, WORD d, UBYTE special)
249 struct NativeChipsetMode *m;
251 m = AllocMem(sizeof(struct NativeChipsetMode), MEMF_CLEAR | MEMF_PUBLIC);
252 DB2(bug("%p %08x %dx%dx%d %d\n", m, modeid, w, h, d, special));
253 m->width = w;
254 m->height = h;
255 m->depth = d;
256 m->special = special;
257 m->modeid = modeid;
258 AddTail(&csd->nativemodelist, &m->node);
259 return m;
262 /* this is SOOO HORRIBLE, do not even attempt to understand it.. */
264 OOP_Object *AmigaVideoCl__Root__New(OOP_Class *cl, OOP_Object *o, struct pRoot_New *msg)
266 struct amigavideo_staticdata *csd = CSD(cl);
267 struct Library *OOPBase = csd->cs_OOPBase;
268 struct TagItem mytags[2];
269 struct pRoot_New mymsg;
270 ULONG allocsize = 3000, allocsizebuf = 1000;
271 WORD x, y, cnt, i, j;
273 UBYTE *buf, *bufptr;
274 ULONG *tags, *tagptr;
275 ULONG *modetags[NATIVEMODES], modeids[NATIVEMODES];
276 ULONG *pftags_aga[SPECIALMODES];
277 ULONG *pftags_ecs_shres = NULL, *pftags_ecs_hires, *pftags_ecs_lores, *pftags_ecs_6;
278 ULONG *mode_tags_aga;
279 ULONG *mode_tags_ecs;
281 if (csd->initialized)
282 return NULL;
284 NewList(&csd->nativemodelist);
285 tags = tagptr = AllocVec(allocsize, MEMF_PUBLIC | MEMF_REVERSE);
286 buf = bufptr = AllocVec(allocsizebuf, MEMF_PUBLIC | MEMF_REVERSE);
288 cnt = 0;
289 for (y = 0; heighttable[y]; y++) {
290 WORD h = heighttable[y];
291 for (x = 0; widthtable[x]; x++) {
292 WORD w = widthtable[x];
293 WORD d, res;
294 ULONG modeid;
296 modeid = 0;
297 if (w == 1280) {
298 res = 2;
299 modeid |= SUPER_KEY;
300 if (!csd->aga && !csd->ecs_denise)
301 continue;
302 d = csd->aga ? 8 : 2;
304 else if (w == 640) {
305 res = 1;
306 modeid |= HIRES_KEY;
307 d = csd->aga ? 8 : 4;
308 } else {
309 res = 0;
310 d = csd->aga ? 8 : 5;
312 if (h >= 400)
313 modeid |= LORESLACE_KEY;
314 if (h == 200 || h == 400)
315 modeid |= NTSC_MONITOR_ID;
316 else
317 modeid |= PAL_MONITOR_ID;
319 for (i = 0; i < SPECIALMODES; i++) {
320 ULONG mid = modeid;
321 UWORD d2 = d;
322 if (i == 1) {
323 if (!csd->aga && (modeid & SUPER_KEY))
324 continue;
325 mid |= EXTRAHALFBRITE_KEY;
326 d2 = 6;
327 } else if (i == 2) {
328 if (!csd->aga && (modeid & SUPER_KEY))
329 continue;
330 mid |= HAM_KEY;
331 d2 = csd->aga ? 8 : 6;
334 addmodeid(csd, mid, w, h, d2, csd->aga ? i : (i == 0 ? res : i - 1 + 3));
335 modetags[cnt] = tagptr;
336 modeids[cnt++] = mid;
338 ADDTAG(aHidd_Sync_HDisp, w);
339 ADDTAG(aHidd_Sync_VDisp, h);
340 ADDTAG(aHidd_Sync_Flags, h >= 400 ? vHidd_Sync_Interlaced : 0);
341 ADDTAG(aHidd_Sync_PixelClock, 1000000000 / (280 >> res));
342 ADDTAG(TAG_DONE, 0);
348 if (csd->aga) {
350 pftags_aga[0] = tagptr;
351 ADDTAG(aHidd_PixFmt_RedShift, 8);
352 ADDTAG(aHidd_PixFmt_GreenShift, 16);
353 ADDTAG(aHidd_PixFmt_BlueShift, 24);
354 ADDTAG(aHidd_PixFmt_AlphaShift, 0);
355 ADDTAG(aHidd_PixFmt_RedMask, 0x00FF0000);
356 ADDTAG(aHidd_PixFmt_GreenMask, 0x0000FF00);
357 ADDTAG(aHidd_PixFmt_BlueMask, 0x000000FF);
358 ADDTAG(aHidd_PixFmt_AlphaMask, 0x00000000);
359 ADDTAG(aHidd_PixFmt_CLUTMask, 0x000000FF);
360 ADDTAG(aHidd_PixFmt_CLUTShift, 0);
361 ADDTAG(aHidd_PixFmt_ColorModel, vHidd_ColorModel_Palette);
362 ADDTAG(aHidd_PixFmt_Depth, 8);
363 ADDTAG(aHidd_PixFmt_BytesPerPixel, 1);
364 ADDTAG(aHidd_PixFmt_BitsPerPixel, 8);
365 ADDTAG(aHidd_PixFmt_StdPixFmt, vHidd_StdPixFmt_Plane);
366 ADDTAG(aHidd_PixFmt_BitMapType, vHidd_BitMapType_Planar);
367 ADDTAG(TAG_DONE, 0);
369 pftags_aga[1] = tagptr;
370 ADDTAG(aHidd_PixFmt_RedShift, 8);
371 ADDTAG(aHidd_PixFmt_GreenShift, 16);
372 ADDTAG(aHidd_PixFmt_BlueShift, 24);
373 ADDTAG(aHidd_PixFmt_AlphaShift, 0);
374 ADDTAG(aHidd_PixFmt_RedMask, 0x00FF0000);
375 ADDTAG(aHidd_PixFmt_GreenMask, 0x0000FF00);
376 ADDTAG(aHidd_PixFmt_BlueMask, 0x000000FF);
377 ADDTAG(aHidd_PixFmt_AlphaMask, 0x00000000);
378 ADDTAG(aHidd_PixFmt_CLUTMask, 0x000000FF);
379 ADDTAG(aHidd_PixFmt_CLUTShift, 0);
380 ADDTAG(aHidd_PixFmt_ColorModel, vHidd_ColorModel_Palette);
381 ADDTAG(aHidd_PixFmt_Depth, 6);
382 ADDTAG(aHidd_PixFmt_BytesPerPixel, 1);
383 ADDTAG(aHidd_PixFmt_BitsPerPixel, 6);
384 ADDTAG(aHidd_PixFmt_StdPixFmt, vHidd_StdPixFmt_Plane);
385 ADDTAG(aHidd_PixFmt_BitMapType, vHidd_BitMapType_Planar);
386 ADDTAG(TAG_DONE, 0);
388 pftags_aga[2] = NULL;
390 mode_tags_aga = tagptr;
391 ADDTAG(aHidd_Sync_HMin, 112);
392 ADDTAG(aHidd_Sync_VMin, 112);
393 ADDTAG(aHidd_Sync_HMax, 16384);
394 ADDTAG(aHidd_Sync_VMax, 16384);
396 for (j = 0; specialmask_aga[j] != 0xffffffff; j++) {
397 if (pftags_aga[j])
398 ADDTAG(aHidd_Gfx_PixFmtTags, (IPTR)pftags_aga[j]);
399 for (i = 0; i < cnt; i++) {
400 ULONG modeid = modeids[i];
401 if ((j == 0 && !(modeid & SPECIAL_MODE_MASK)) || (j > 0 && ((modeid & SPECIAL_MODE_MASK) == specialmask_aga[j]))) {
402 makemodename(modeid, bufptr);
403 ADDTAG(aHidd_Sync_Description, (IPTR)bufptr);
404 bufptr += strlen(bufptr) + 1;
405 ADDTAG(aHidd_Gfx_SyncTags, (IPTR)modetags[i]);
410 ADDTAG(TAG_DONE, 0);
412 mytags[0].ti_Tag = aHidd_Gfx_ModeTags;
413 mytags[0].ti_Data = (IPTR)mode_tags_aga;
414 mytags[1].ti_Tag = TAG_MORE;
415 mytags[1].ti_Data = (IPTR)msg->attrList;
417 } else {
419 pftags_ecs_lores = tagptr;
420 ADDTAG(aHidd_PixFmt_RedShift, 20);
421 ADDTAG(aHidd_PixFmt_GreenShift, 24);
422 ADDTAG(aHidd_PixFmt_BlueShift, 28);
423 ADDTAG(aHidd_PixFmt_AlphaShift, 0);
424 ADDTAG(aHidd_PixFmt_RedMask, 0x00000F00);
425 ADDTAG(aHidd_PixFmt_GreenMask, 0x000000F0);
426 ADDTAG(aHidd_PixFmt_BlueMask, 0x0000000F);
427 ADDTAG(aHidd_PixFmt_AlphaMask, 0x00000000);
428 ADDTAG(aHidd_PixFmt_CLUTMask, 0x0000001F);
429 ADDTAG(aHidd_PixFmt_CLUTShift, 0);
430 ADDTAG(aHidd_PixFmt_ColorModel, vHidd_ColorModel_Palette);
431 ADDTAG(aHidd_PixFmt_Depth, 5);
432 ADDTAG(aHidd_PixFmt_BytesPerPixel, 1);
433 ADDTAG(aHidd_PixFmt_BitsPerPixel, 5);
434 ADDTAG(aHidd_PixFmt_StdPixFmt, vHidd_StdPixFmt_Plane);
435 ADDTAG(aHidd_PixFmt_BitMapType, vHidd_BitMapType_Planar);
436 ADDTAG(TAG_DONE, 0);
438 pftags_ecs_hires = tagptr;
439 ADDTAG(aHidd_PixFmt_RedShift, 20);
440 ADDTAG(aHidd_PixFmt_GreenShift, 24);
441 ADDTAG(aHidd_PixFmt_BlueShift, 28);
442 ADDTAG(aHidd_PixFmt_AlphaShift, 0);
443 ADDTAG(aHidd_PixFmt_RedMask, 0x00000F00);
444 ADDTAG(aHidd_PixFmt_GreenMask, 0x000000F0);
445 ADDTAG(aHidd_PixFmt_BlueMask, 0x0000000F);
446 ADDTAG(aHidd_PixFmt_AlphaMask, 0x00000000);
447 ADDTAG(aHidd_PixFmt_CLUTMask, 0x0000001F);
448 ADDTAG(aHidd_PixFmt_CLUTShift, 0);
449 ADDTAG(aHidd_PixFmt_ColorModel, vHidd_ColorModel_Palette);
450 ADDTAG(aHidd_PixFmt_Depth, 4);
451 ADDTAG(aHidd_PixFmt_BytesPerPixel, 1);
452 ADDTAG(aHidd_PixFmt_BitsPerPixel, 4);
453 ADDTAG(aHidd_PixFmt_StdPixFmt, vHidd_StdPixFmt_Plane);
454 ADDTAG(aHidd_PixFmt_BitMapType, vHidd_BitMapType_Planar);
455 ADDTAG(TAG_DONE, 0);
457 pftags_ecs_shres = tagptr;
458 ADDTAG(aHidd_PixFmt_RedShift, 20);
459 ADDTAG(aHidd_PixFmt_GreenShift, 24);
460 ADDTAG(aHidd_PixFmt_BlueShift, 28);
461 ADDTAG(aHidd_PixFmt_AlphaShift, 0);
462 ADDTAG(aHidd_PixFmt_RedMask, 0x00000F00);
463 ADDTAG(aHidd_PixFmt_GreenMask, 0x000000F0);
464 ADDTAG(aHidd_PixFmt_BlueMask, 0x0000000F);
465 ADDTAG(aHidd_PixFmt_AlphaMask, 0x00000000);
466 ADDTAG(aHidd_PixFmt_CLUTMask, 0x0000001F);
467 ADDTAG(aHidd_PixFmt_CLUTShift, 0);
468 ADDTAG(aHidd_PixFmt_ColorModel, vHidd_ColorModel_Palette);
469 ADDTAG(aHidd_PixFmt_Depth, 2);
470 ADDTAG(aHidd_PixFmt_BytesPerPixel, 1);
471 ADDTAG(aHidd_PixFmt_BitsPerPixel, 2);
472 ADDTAG(aHidd_PixFmt_StdPixFmt, vHidd_StdPixFmt_Plane);
473 ADDTAG(aHidd_PixFmt_BitMapType, vHidd_BitMapType_Planar);
474 ADDTAG(TAG_DONE, 0);
476 pftags_ecs_6 = tagptr;
477 ADDTAG(aHidd_PixFmt_RedShift, 20);
478 ADDTAG(aHidd_PixFmt_GreenShift, 24);
479 ADDTAG(aHidd_PixFmt_BlueShift, 28);
480 ADDTAG(aHidd_PixFmt_AlphaShift, 0);
481 ADDTAG(aHidd_PixFmt_RedMask, 0x00000F00);
482 ADDTAG(aHidd_PixFmt_GreenMask, 0x000000F0);
483 ADDTAG(aHidd_PixFmt_BlueMask, 0x0000000F);
484 ADDTAG(aHidd_PixFmt_AlphaMask, 0x00000000);
485 ADDTAG(aHidd_PixFmt_CLUTMask, 0x0000001F);
486 ADDTAG(aHidd_PixFmt_CLUTShift, 0);
487 ADDTAG(aHidd_PixFmt_ColorModel, vHidd_ColorModel_Palette);
488 ADDTAG(aHidd_PixFmt_Depth, 6);
489 ADDTAG(aHidd_PixFmt_BytesPerPixel, 1);
490 ADDTAG(aHidd_PixFmt_BitsPerPixel, 6);
491 ADDTAG(aHidd_PixFmt_StdPixFmt, vHidd_StdPixFmt_Plane);
492 ADDTAG(aHidd_PixFmt_BitMapType, vHidd_BitMapType_Planar);
493 ADDTAG(TAG_DONE, 0);
495 mode_tags_ecs = tagptr;
496 ADDTAG(aHidd_Sync_HMin, 112);
497 ADDTAG(aHidd_Sync_VMin, 112);
498 ADDTAG(aHidd_Sync_HMax, csd->ecs_agnus ? 16384 : 1008);
499 ADDTAG(aHidd_Sync_VMax, csd->ecs_agnus ? 16384 : 1008);
501 ADDTAG(aHidd_Gfx_PixFmtTags, (IPTR)pftags_ecs_lores);
502 for (i = 0; i < cnt; i++) {
503 if ((modeids[i] & SPECIAL_MODE_MASK) || (modeids[i] & SUPER_KEY) != LORES_KEY)
504 continue;
505 makemodename(modeids[i], bufptr);
506 ADDTAG(aHidd_Sync_Description, (IPTR)bufptr);
507 bufptr += strlen(bufptr) + 1;
508 ADDTAG(aHidd_Gfx_SyncTags, (IPTR)modetags[i]);
511 ADDTAG(aHidd_Gfx_PixFmtTags, (IPTR)pftags_ecs_hires);
512 for (i = 0; i < cnt; i++) {
513 if ((modeids[i] & SPECIAL_MODE_MASK) || (modeids[i] & SUPER_KEY) != HIRES_KEY)
514 continue;
515 makemodename(modeids[i], bufptr);
516 ADDTAG(aHidd_Sync_Description, (IPTR)bufptr);
517 bufptr += strlen(bufptr) + 1;
518 ADDTAG(aHidd_Gfx_SyncTags, (IPTR)modetags[i]);
521 ADDTAG(aHidd_Gfx_PixFmtTags, (IPTR)pftags_ecs_shres);
522 if (csd->ecs_denise) {
523 for (i = 0; i < cnt; i++) {
524 if ((modeids[i] & SPECIAL_MODE_MASK) || (modeids[i] & SUPER_KEY) != SUPER_KEY)
525 continue;
526 makemodename(modeids[i], bufptr);
527 ADDTAG(aHidd_Sync_Description, (IPTR)bufptr);
528 bufptr += strlen(bufptr) + 1;
529 ADDTAG(aHidd_Gfx_SyncTags, (IPTR)modetags[i]);
533 ADDTAG(aHidd_Gfx_PixFmtTags, (IPTR)pftags_ecs_6);
534 for (i = 0; i < cnt; i++) {
535 if (!(modeids[i] & SPECIAL_MODE_MASK))
536 continue;
537 makemodename(modeids[i], bufptr);
538 ADDTAG(aHidd_Sync_Description, (IPTR)bufptr);
539 bufptr += strlen(bufptr) + 1;
540 ADDTAG(aHidd_Gfx_SyncTags, (IPTR)modetags[i]);
543 ADDTAG(TAG_DONE, 0);
545 mytags[0].ti_Tag = aHidd_Gfx_ModeTags;
546 mytags[0].ti_Data = (IPTR)mode_tags_ecs;
547 mytags[1].ti_Tag = TAG_MORE;
548 mytags[1].ti_Data = (IPTR)msg->attrList;
552 D(bug("alloc=%d alloced=%d\n", allocsize, (ULONG)tagptr - (ULONG)tags));
553 D(bug("allocbuf=%d allocedbuf=%d\n", allocsizebuf, bufptr - buf));
555 EnterFunc(bug("AGFX::New()\n"));
557 mymsg.mID = msg->mID;
558 mymsg.attrList = mytags;
559 msg = &mymsg;
561 /* Register gfxmodes */
562 o = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
563 if (NULL != o)
565 struct amigagfx_data *data = OOP_INST_DATA(cl, o);
566 struct NativeChipsetMode *node;
567 HIDDT_ModeID *midp;
568 UWORD pfcnt;
569 OOP_MethodID HiddGfxBase = csd->cs_HiddGfxBase;
570 OOP_Object *pixelformats[8] = { 0 };
572 D(bug("AGFX::New(): Got object from super\n"));
573 NewList((struct List *)&data->bitmaps);
574 csd->initialized = 1;
576 /* this can't be the right way to match modes.. */
577 csd->superforward = TRUE;
578 midp = HIDD_Gfx_QueryModeIDs(o, NULL);
579 for (pfcnt = 0, i = 0; midp[i] != vHidd_ModeID_Invalid; i++) {
580 OOP_Object *sync, *pf;
581 HIDDT_ModeID mid = midp[i];
582 if (!HIDD_Gfx_GetMode(o, mid, &sync, &pf))
583 continue;
584 for (j = 0; j < pfcnt; j++) {
585 if (pf == pixelformats[j])
586 break;
588 if (j < pfcnt)
589 continue;
590 pixelformats[pfcnt++] = pf;
592 while (pfcnt < 8) {
593 if (csd->aga)
594 pixelformats[pfcnt] = pixelformats[0];
595 else
596 pixelformats[pfcnt] = pixelformats[pfcnt - 1];
597 pfcnt++;
599 for (i = 0; i < pfcnt; i++) {
600 DB2(bug("pf %d: %p\n", i, pixelformats[i]));
603 ForeachNode(&csd->nativemodelist, node) {
604 if (!node->pf) {
605 OOP_Object *sync = NULL;
606 for (i = 0; midp[i] != vHidd_ModeID_Invalid; i++) {
607 HIDDT_ModeID mid = midp[i];
608 IPTR dwidth, dheight;
609 OOP_Object *pf;
610 struct NativeChipsetMode *node2;
611 BOOL found = FALSE;
612 if (!HIDD_Gfx_GetMode(o, mid, &sync, &pf))
613 continue;
614 OOP_GetAttr(sync, aHidd_Sync_HDisp, &dwidth);
615 OOP_GetAttr(sync, aHidd_Sync_VDisp, &dheight);
616 if (node->width != dwidth || node->height != dheight)
617 continue;
618 ForeachNode(&csd->nativemodelist, node2) {
619 if (node->width == dwidth && node->height == dheight) {
620 if (node2->sync == sync) {
621 found = TRUE;
622 break;
626 if (!found)
627 break;
629 if (midp[i] == vHidd_ModeID_Invalid) {
630 sync = NULL;
631 D(bug("sync not found!?\n"));
633 node->sync = sync;
634 node->pf = pixelformats[node->special];
635 DB2(bug("%08x %dx%dx%d sync = %p pf = %p\n",
636 node->modeid, node->width, node->height, node->depth, node->sync, node->pf));
639 HIDD_Gfx_ReleaseModeIDs(o, midp);
640 csd->superforward = FALSE;
641 #if 1
642 ForeachNode(&csd->nativemodelist, node) {
643 DB2(bug("%08x %dx%dx%d sync = %p pf = %p\n", node->modeid, node->width, node->height, node->depth, node->sync, node->pf));
645 #endif
648 FreeVec(buf);
649 FreeVec(tags);
650 ReturnPtr("AGFX::New", OOP_Object *, o);
653 /********** GfxHidd::Dispose() ******************************/
654 VOID AmigaVideoCl__Root__Dispose(OOP_Class *cl, OOP_Object *o, OOP_Msg msg)
656 EnterFunc(bug("AGFX::Dispose(o=%p)\n", o));
658 D(bug("AGFX::Dispose: calling super\n"));
659 OOP_DoSuperMethod(cl, o, msg);
661 ReturnVoid("AGFX::Dispose");
665 OOP_Object *AmigaVideoCl__Hidd_Gfx__CreateObject(OOP_Class *cl, OOP_Object *o, struct pHidd_Gfx_CreateObject *msg)
667 OOP_Object *object = NULL;
669 EnterFunc(bug("AGFX::CreateObject()\n"));
671 if (msg->cl == CSD(cl)->cs_basebm)
673 struct amigavideo_staticdata *csd = CSD(cl);
674 struct Library *UtilityBase = csd->cs_UtilityBase;
675 HIDDT_ModeID modeid;
676 struct pHidd_Gfx_CreateObject p;
677 struct TagItem tags[] =
679 { TAG_IGNORE, TAG_IGNORE }, /* Placeholder for aHidd_BitMap_ClassPtr */
680 { TAG_MORE, (IPTR)msg->attrList }
683 modeid = (HIDDT_ModeID)GetTagData(aHidd_BitMap_ModeID, vHidd_ModeID_Invalid, msg->attrList);
684 D(bug("modeid=%08x\n", modeid));
685 if (modeid != vHidd_ModeID_Invalid) {
686 tags[0].ti_Tag = aHidd_BitMap_ClassPtr;
687 tags[0].ti_Data = (IPTR)CSD(cl)->amigabmclass;
690 p.mID = msg->mID;
691 p.cl = msg->cl;
692 p.attrList = tags;
694 object = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg)&p);
696 else
697 object = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
699 ReturnPtr("AGFX::CreateObject", OOP_Object *, object);
702 VOID AmigaVideoCl__Root__Get(OOP_Class *cl, OOP_Object *o, struct pRoot_Get *msg)
704 struct amigavideo_staticdata *csd = CSD(cl);
705 ULONG idx;
707 //bug("AmigaVideoCl__Root__Get %x\n", msg->attrID);
709 if (IS_GFX_ATTR(msg->attrID, idx))
711 //bug("=%x\n", idx);
712 switch (idx)
714 case aoHidd_Gfx_HWSpriteTypes:
715 *msg->storage = vHidd_SpriteType_3Plus1;
716 return;
717 case aoHidd_Gfx_SupportsHWCursor:
718 case aoHidd_Gfx_NoFrameBuffer:
719 *msg->storage = TRUE;
720 return;
721 case aoHidd_Gfx_IsWindowed:
722 *msg->storage = FALSE;
723 return;
724 case aoHidd_Gfx_DriverName:
725 *msg->storage = (IPTR)"AmigaVideo";
726 return;
729 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
732 VOID AmigaVideoCl__Root__Set(OOP_Class *cl, OOP_Object *obj, struct pRoot_Set *msg)
734 struct amigavideo_staticdata *csd = CSD(cl);
735 struct Library *UtilityBase = csd->cs_UtilityBase;
736 struct TagItem *tag, *tstate;
738 tstate = msg->attrList;
739 while((tag = NextTagItem(&tstate)))
741 ULONG idx;
742 D(bug("AmigaVideoCl__Root__Set %x\n", tag->ti_Tag));
743 if (IS_GFX_ATTR(tag->ti_Tag, idx)) {
744 D(bug("->%d\n", idx));
745 switch(idx)
747 case aoHidd_Gfx_ActiveCallBack:
748 csd->acb = (void *)tag->ti_Data;
749 break;
751 case aoHidd_Gfx_ActiveCallBackData:
752 csd->acbdata = (APTR)tag->ti_Data;
753 break;
757 OOP_DoSuperMethod(cl, obj, (OOP_Msg)msg);
760 ULONG AmigaVideoCl__Hidd_Gfx__ShowViewPorts(OOP_Class *cl, OOP_Object *o, struct pHidd_Gfx_ShowViewPorts *msg)
762 struct amigavideo_staticdata *csd = CSD(cl);
763 struct Library *OOPBase = csd->cs_OOPBase;
764 struct HIDD_ViewPortData *vpd = msg->Data;
765 OOP_Object *bm = NULL;
767 if (vpd)
768 bm = vpd->Bitmap;
770 D(bug("AmigaShowViewPorts %p %p\n", vpd, bm));
772 if (bm) {
773 struct amigabm_data *data = OOP_INST_DATA(OOP_OCLASS(bm), bm);
774 IPTR tags[] = {aHidd_BitMap_Visible, TRUE, TAG_DONE};
775 IPTR modeid = vHidd_ModeID_Invalid;
777 OOP_GetAttr(bm, aHidd_BitMap_ModeID , &modeid);
778 csd->modeid = modeid;
779 setmode(csd, data);
780 OOP_SetAttrs(bm, (struct TagItem *)tags);
782 if (csd->acb)
783 csd->acb(csd->acbdata, NULL);
785 } else {
786 resetmode(csd);
789 return TRUE;
792 VOID AmigaVideoCl__Hidd_Gfx__CopyBox(OOP_Class *cl, OOP_Object *o, struct pHidd_Gfx_CopyBox *msg)
794 struct amigavideo_staticdata *csd = CSD(cl);
795 struct Library *OOPBase = csd->cs_OOPBase;
796 HIDDT_DrawMode mode = GC_DRMD(msg->gc);
797 IPTR src, dst;
798 BOOL ok = FALSE;
800 OOP_GetAttr(msg->src, aHidd_AmigaVideoBitMap_Drawable, &src);
801 OOP_GetAttr(msg->dest, aHidd_AmigaVideoBitMap_Drawable, &dst);
802 if (src && dst) {
803 struct amigabm_data *sdata = OOP_INST_DATA(OOP_OCLASS(msg->src), msg->src);
804 struct amigabm_data *ddata = OOP_INST_DATA(OOP_OCLASS(msg->dest), msg->dest);
805 ok = blit_copybox(csd, sdata->pbm, ddata->pbm, msg->srcX, msg->srcY, msg->width, msg->height, msg->destX, msg->destY, mode);
807 if (!ok)
808 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
811 BOOL AmigaVideoCl__Hidd_Gfx__CopyBoxMasked(OOP_Class *cl, OOP_Object *o, struct pHidd_Gfx_CopyBoxMasked *msg)
813 struct amigavideo_staticdata *csd = CSD(cl);
814 struct Library *OOPBase = csd->cs_OOPBase;
815 HIDDT_DrawMode mode = GC_DRMD(msg->gc);
816 IPTR src, dst;
817 BOOL ok = FALSE;
819 OOP_GetAttr(msg->src, aHidd_AmigaVideoBitMap_Drawable, &src);
820 OOP_GetAttr(msg->dest, aHidd_AmigaVideoBitMap_Drawable, &dst);
821 if (src && dst) {
822 struct amigabm_data *sdata = OOP_INST_DATA(OOP_OCLASS(msg->src), msg->src);
823 struct amigabm_data *ddata = OOP_INST_DATA(OOP_OCLASS(msg->dest), msg->dest);
824 ok = blit_copybox_mask(csd, sdata->pbm, ddata->pbm, msg->srcX, msg->srcY, msg->width, msg->height, msg->destX, msg->destY, mode, msg->mask);
826 if (!ok)
827 return OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
829 return TRUE;
832 BOOL AmigaVideoCl__Hidd_Gfx__SetCursorShape(OOP_Class *cl, OOP_Object *shape, struct pHidd_Gfx_SetCursorShape *msg)
834 struct amigavideo_staticdata *csd = CSD(cl);
835 struct Library *OOPBase = csd->cs_OOPBase;
836 IPTR width, height;
837 UWORD maxw, maxh;
839 OOP_GetAttr(msg->shape, aHidd_BitMap_Width, &width);
840 OOP_GetAttr(msg->shape, aHidd_BitMap_Height, &height);
842 maxw = (csd->aga ? 64 : 16);
843 maxh = maxw * 2;
845 if (width > maxw || height > maxh)
846 return FALSE;
848 return setsprite(csd, width, height, msg);
851 BOOL AmigaVideoCl__Hidd_Gfx__GetMaxSpriteSize(OOP_Class *cl, ULONG Type, ULONG *Width, ULONG *Height)
853 struct amigavideo_staticdata *csd = CSD(cl);
854 *Width = csd->aga ? 64 : 16;
855 *Height = *Width * 2;
856 return TRUE;
858 BOOL AmigaVideoCl__Hidd_Gfx__SetCursorPos(OOP_Class *cl, OOP_Object *o, struct pHidd_Gfx_SetCursorPos *msg)
860 struct amigavideo_staticdata *csd = CSD(cl);
861 setspritepos(csd, msg->x, msg->y);
862 return TRUE;
864 VOID AmigaVideoCl__Hidd_Gfx__SetCursorVisible(OOP_Class *cl, OOP_Object *o, struct pHidd_Gfx_SetCursorVisible *msg)
866 struct amigavideo_staticdata *csd = CSD(cl);
867 setspritevisible(csd, msg->visible);
870 ULONG AmigaVideoCl__Hidd_Gfx__MakeViewPort(OOP_Class *cl, OOP_Object *o, struct pHidd_Gfx_MakeViewPort *msg)
872 D(struct HIDD_ViewPortData *vpd = msg->Data);
874 D(bug("AmigaVideoCl__Hidd_Gfx__MakeViewPort vp=%p bm=%p vpe=%p\n", vpd->vpe->ViewPort, vpd->Bitmap, vpd->vpe));
875 /* TODO: implement this correctly */
876 return MVP_OK;
879 void AmigaVideoCl__Hidd_Gfx__CleanViewPort(OOP_Class *cl, OOP_Object *o, struct pHidd_Gfx_CleanViewPort *msg)
881 struct amigavideo_staticdata *csd = CSD(cl);
882 struct Library *GfxBase = csd->cs_GfxBase;
883 struct HIDD_ViewPortData *vpd = msg->Data;
884 struct ViewPort *vp = vpd->vpe->ViewPort;
886 D(bug("AmigaVideoCl__Hidd_Gfx__CleanViewPort vp=%p bm=%p vpe=%p\n", vpd->vpe->ViewPort, vpd->Bitmap, vpd->vpe));
887 /* It's safe to call these functions on NULL pointers */
888 FreeCopList(vp->ClrIns);
889 FreeCopList(vp->DspIns);
890 FreeCopList(vp->SprIns);
892 if (vp->UCopIns)
894 FreeCopList(vp->UCopIns->FirstCopList);
895 FreeMem(vp->UCopIns, sizeof(struct UCopList));
898 /* Everything has been freed */
899 vp->ClrIns = NULL;
900 vp->DspIns = NULL;
901 vp->SprIns = NULL;
902 vp->UCopIns = NULL;
905 static void freeattrbases(struct amigavideo_staticdata *csd)
907 struct Library *OOPBase = csd->cs_OOPBase;
909 OOP_ReleaseAttrBase(IID_Hidd_BitMap);
910 OOP_ReleaseAttrBase(IID_Hidd_PlanarBM);
911 OOP_ReleaseAttrBase(IID_Hidd_AmigaVideoBitMap);
912 OOP_ReleaseAttrBase(IID_Hidd_GC);
913 OOP_ReleaseAttrBase(IID_Hidd_Sync);
914 OOP_ReleaseAttrBase(IID_Hidd_Gfx);
915 OOP_ReleaseAttrBase(IID_Hidd_PixFmt);
916 OOP_ReleaseAttrBase(IID_Hidd_ColorMap);
919 int Init_AmigaVideoClass(LIBBASETYPEPTR LIBBASE)
921 struct amigavideo_staticdata *csd = &LIBBASE->csd;
922 struct Library *OOPBase = csd->cs_OOPBase;
924 D(bug("Init_AmigaVideoClass\n"));
925 __IHidd_BitMap = OOP_ObtainAttrBase(IID_Hidd_BitMap);
926 __IHidd_PlanarBM = OOP_ObtainAttrBase(IID_Hidd_PlanarBM);
927 __IHidd_AmigaVideoBitmap = OOP_ObtainAttrBase(IID_Hidd_AmigaVideoBitMap);
928 __IHidd_GC = OOP_ObtainAttrBase(IID_Hidd_GC);
929 __IHidd_Sync = OOP_ObtainAttrBase(IID_Hidd_Sync);
930 __IHidd_Gfx = OOP_ObtainAttrBase(IID_Hidd_Gfx);
931 __IHidd_PixFmt = OOP_ObtainAttrBase(IID_Hidd_PixFmt);
932 __IHidd_ColorMap = OOP_ObtainAttrBase(IID_Hidd_ColorMap);
934 if (!__IHidd_BitMap || !__IHidd_PlanarBM || !__IHidd_AmigaVideoBitmap || !__IHidd_GC ||
935 !__IHidd_Sync || !__IHidd_Gfx || !__IHidd_PixFmt || !__IHidd_ColorMap)
937 D(bug("Init_AmigaVideoClass fail\n"));
938 freeattrbases(csd);
939 return 0;
941 return TRUE;
945 static int Expunge_AmigaVideoClass(LIBBASETYPEPTR LIBBASE)
947 struct amigavideo_staticdata *csd = &LIBBASE->csd;
948 D(bug("Expunge_AmigaVideoClass\n"));
949 freeattrbases(csd);
950 return TRUE;
953 ADD2EXPUNGELIB(Expunge_AmigaVideoClass, 1)