revert between 56095 -> 55830 in arch
[AROS.git] / arch / m68k-amiga / hidd / amigavideo / amigavideo_hiddclass.c
blobc93d1abc4ca1fbc2add59243de7d380045b88c84
1 /*
2 Copyright © 1995-2017, 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>
26 #include <aros/symbolsets.h>
28 #include LC_LIBDEFS_FILE
30 #include "chipset.h"
31 #include "blitter.h"
33 #define SDEBUG 0
34 #define DEBUG 0
35 #include <aros/debug.h>
37 #define SPECIALMODES 3
38 #define NATIVEMODES (3 * 4 * SPECIALMODES)
39 static const UWORD widthtable[] = { 320, 640, 1280, 0 };
40 static const UWORD heighttable[] = { 200, 256, 400, 512, 0 };
41 static const ULONG specialmask_aga[] = { 0, EXTRAHALFBRITE_KEY, HAM_KEY, 0xffffffff };
43 #define SPECIAL_MODE_MASK (EXTRAHALFBRITE_KEY | HAM_KEY)
45 VOID AmigaVideoCl__Hidd_Gfx__NominalDimensions(OOP_Class *cl, OOP_Object *o, struct pHidd_Gfx_NominalDimensions *msg)
47 struct amigavideo_staticdata *csd = CSD(cl);
48 struct GfxBase *GfxBase = (struct GfxBase *)csd->cs_GfxBase;
50 DB2(bug("NominalDimensions()\n"));
52 if (msg->width)
53 *(msg->width) = GfxBase->NormalDisplayColumns;
54 if (msg->height)
55 *(msg->height) = GfxBase->NormalDisplayRows;
56 if (msg->depth)
57 *(msg->depth) = 1;
60 ULONG AmigaVideoCl__Hidd_Gfx__ModeProperties(OOP_Class *cl, OOP_Object *o, struct pHidd_Gfx_ModeProperties *msg)
62 ULONG flags = 0;
63 ULONG modeid = msg->modeID;
65 flags = DIPF_IS_SPRITES | DIPF_IS_DRAGGABLE |
66 DIPF_IS_SPRITES_ATT | DIPF_IS_SPRITES_CHNG_BASE | DIPF_IS_SPRITES_CHNG_PRI |
67 DIPF_IS_DBUFFER | DIPF_IS_BEAMSYNC | DIPF_IS_GENLOCK;
68 msg->props->NumHWSprites = 8;
69 if ((modeid & MONITOR_ID_MASK) == PAL_MONITOR_ID)
70 flags |= DIPF_IS_PAL;
71 if (modeid & LORESLACE_KEY)
72 flags |= DIPF_IS_LACE;
73 if (modeid & HAM_KEY) {
74 flags |= DIPF_IS_HAM;
75 if (modeid & SUPER_KEY)
76 flags |= DIPF_IS_AA;
78 if (modeid & EXTRAHALFBRITE_KEY) {
79 flags |= DIPF_IS_EXTRAHALFBRITE;
80 if (modeid & SUPER_KEY)
81 flags |= DIPF_IS_AA;
83 if ((modeid & SUPER_KEY) == SUPER_KEY && !(flags & DIPF_IS_AA))
84 flags |= DIPF_IS_ECS;
85 if (!(modeid & SPECIAL_MODE_MASK))
86 flags |= DIPF_IS_WB;
87 msg->props->DisplayInfoFlags = flags;
88 msg->props->CompositionFlags = COMPF_ABOVE | COMPF_BELOW; // | COMPF_LEFT | COMPF_RIGHT;
89 DB2(bug("ModeProp %08x = %08x\n", modeid, flags));
90 return sizeof(struct HIDD_ModeProperties);
93 HIDDT_ModeID *AmigaVideoCl__Hidd_Gfx__QueryModeIDs(OOP_Class *cl, OOP_Object *o, struct pHidd_Gfx_QueryModeIDs *msg)
95 struct amigavideo_staticdata *csd = CSD(cl);
96 struct NativeChipsetMode *node;
97 struct TagItem *tag, *tstate;
98 ULONG minwidth = 0, maxwidth = 0xFFFFFFFF;
99 ULONG minheight = 0, maxheight = 0xFFFFFFFF;
100 HIDDT_ModeID *modeids;
101 struct Library *UtilityBase = csd->cs_UtilityBase;
102 WORD cnt;
104 if (csd->superforward)
105 return (HIDDT_ModeID*)OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
107 for (tstate = msg->queryTags; (tag = NextTagItem(&tstate)); )
109 switch (tag->ti_Tag)
111 case tHidd_GfxMode_MinWidth:
112 minwidth = (ULONG)tag->ti_Tag;
113 break;
115 case tHidd_GfxMode_MaxWidth:
116 maxwidth = (ULONG)tag->ti_Tag;
117 break;
119 case tHidd_GfxMode_MinHeight:
120 minheight = (ULONG)tag->ti_Tag;
121 break;
123 case tHidd_GfxMode_MaxHeight:
124 maxheight = (ULONG)tag->ti_Tag;
125 break;
127 case tHidd_GfxMode_PixFmts:
128 /* all chipset modes have same pixelformat */
129 break;
133 DB2(bug("QueryModeIDs (%dx%d)-(%dx%d)\n", minwidth, minheight, maxwidth, maxheight));
134 cnt = 0;
135 ForeachNode(&csd->nativemodelist, node) {
136 if (node->width >= minwidth && node->width <= maxwidth && node->height >= minheight && node->height <= maxheight) {
137 cnt++;
140 modeids = AllocVec((cnt + 1) * sizeof(HIDDT_ModeID), MEMF_PUBLIC);
141 if (!modeids)
142 return NULL;
143 cnt = 0;
144 ForeachNode(&csd->nativemodelist, node) {
145 if (node->width >= minwidth && node->width <= maxwidth && node->height >= minheight && node->height <= maxheight) {
146 DB2(bug("%d: %08x\n", cnt, node->modeid));
147 modeids[cnt++] = node->modeid;
150 modeids[cnt] = vHidd_ModeID_Invalid;
151 return modeids;
154 VOID AmigaVideoCl__Hidd_Gfx__ReleaseModeIDs(OOP_Class *cl, OOP_Object *o, struct pHidd_Gfx_ReleaseModeIDs *msg)
156 struct amigavideo_staticdata *csd = CSD(cl);
157 if (csd->superforward)
158 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
159 else
160 FreeVec(msg->modeIDs);
163 HIDDT_ModeID AmigaVideoCl__Hidd_Gfx__NextModeID(OOP_Class *cl, OOP_Object *o, struct pHidd_Gfx_NextModeID *msg)
165 struct amigavideo_staticdata *csd = CSD(cl);
166 struct NativeChipsetMode *node = NULL;
167 HIDDT_ModeID mid = vHidd_ModeID_Invalid;
169 DB2(bug("NextModeID %08x\n", msg->modeID));
170 if (msg->modeID != vHidd_ModeID_Invalid) {
171 ForeachNode(&csd->nativemodelist, node) {
172 if (node->modeid == msg->modeID) {
173 node = (struct NativeChipsetMode*)node->node.ln_Succ;
174 break;
178 if (!node)
179 node = (struct NativeChipsetMode*)csd->nativemodelist.lh_Head;
180 if (node->node.ln_Succ) {
181 mid = node->modeid;
182 *msg->syncPtr = node->sync;
183 *msg->pixFmtPtr = node->pf;
185 DB2(bug("=%08x %p %p\n", mid, *msg->syncPtr, *msg->pixFmtPtr));
186 return mid;
189 BOOL AmigaVideoCl__Hidd_Gfx__GetMode(OOP_Class *cl, OOP_Object *o, struct pHidd_Gfx_GetMode *msg)
191 struct amigavideo_staticdata *csd = CSD(cl);
192 struct NativeChipsetMode *node;
194 if (csd->superforward)
195 return (BOOL)OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
197 DB2(bug("GetMode %08x\n", msg->modeID));
198 ForeachNode(&csd->nativemodelist, node) {
199 if (node->modeid == msg->modeID) {
200 *msg->syncPtr = node->sync;
201 *msg->pixFmtPtr = node->pf;
202 DB2(bug("= %p %p %dx%dx%d %d\n", node->sync, node->pf, node->width, node->height, node->depth, node->special));
203 return TRUE;
206 DB2(bug("= FAIL\n"));
207 return FALSE;
210 #define ADDTAG(tag,data) { *tagptr++ = tag; *tagptr++ = data; }
213 static void makemodename(ULONG modeid, UBYTE *bufptr)
215 BOOL special = FALSE;
217 special = (modeid & SPECIAL_MODE_MASK) != 0;
218 bufptr[0] = 0;
219 if ((modeid & MONITOR_ID_MASK) == PAL_MONITOR_ID)
220 strcat(bufptr, "PAL");
221 else if ((modeid & MONITOR_ID_MASK) == NTSC_MONITOR_ID)
222 strcat (bufptr, "NTSC");
223 strcat(bufptr, ":");
224 if ((modeid & (HIRES_KEY | SUPER_KEY)) == LORES_KEY)
225 strcat(bufptr, special ? "LowRes" : "Low Res");
226 else if ((modeid & (HIRES_KEY | SUPER_KEY)) == HIRES_KEY)
227 strcat(bufptr, special ? "HighRes" : "High Res");
228 else
229 strcat(bufptr, special ? "SuperHighRes" : "Super-High Res");
230 if (modeid & HAM_KEY)
231 strcat(bufptr, " HAM");
232 if (modeid & EXTRAHALFBRITE_KEY)
233 strcat(bufptr, " EHB");
234 if ((modeid & LORESDPF2_KEY) == LORESDPF_KEY)
235 strcat(bufptr, " DualPF");
236 if ((modeid & LORESDPF2_KEY) == LORESDPF2_KEY)
237 strcat(bufptr, " DualPF2");
238 if (modeid & LORESLACE_KEY)
239 strcat(bufptr, special ? " Interlace" : " Laced");
240 DB2(bug("%08x '%s'\n", modeid, bufptr));
243 static struct NativeChipsetMode *addmodeid(struct amigavideo_staticdata *csd, ULONG modeid, WORD w, WORD h, WORD d, UBYTE special)
245 struct NativeChipsetMode *m;
247 m = AllocMem(sizeof(struct NativeChipsetMode), MEMF_CLEAR | MEMF_PUBLIC);
248 DB2(bug("%p %08x %dx%dx%d %d\n", m, modeid, w, h, d, special));
249 m->width = w;
250 m->height = h;
251 m->depth = d;
252 m->special = special;
253 m->modeid = modeid;
254 AddTail(&csd->nativemodelist, &m->node);
255 return m;
258 /* this is SOOO HORRIBLE, do not even attempt to understand it.. */
260 OOP_Object *AmigaVideoCl__Root__New(OOP_Class *cl, OOP_Object *o, struct pRoot_New *msg)
262 struct amigavideo_staticdata *csd = CSD(cl);
263 struct Library *OOPBase = csd->cs_OOPBase;
264 struct TagItem mytags[] =
266 { aHidd_Gfx_ModeTags , (IPTR)NULL },
267 { aHidd_Name , (IPTR)"amigavideo.hidd" },
268 { aHidd_HardwareName , (IPTR)"Amiga Native Display Hardware" },
269 { aHidd_ProducerName , (IPTR)"Commodore International" },
270 { TAG_MORE , (IPTR)msg->attrList }
272 struct pRoot_New mymsg;
273 ULONG allocsize = 3000, allocsizebuf = 1000;
274 WORD x, y, cnt, i, j;
276 UBYTE *buf, *bufptr;
277 ULONG *tags, *tagptr;
278 ULONG *modetags[NATIVEMODES], modeids[NATIVEMODES];
279 ULONG *pftags_aga[SPECIALMODES];
280 ULONG *pftags_ecs_shres = NULL, *pftags_ecs_hires, *pftags_ecs_lores, *pftags_ecs_6;
281 ULONG *mode_tags_aga;
282 ULONG *mode_tags_ecs;
284 if (csd->initialized)
285 return NULL;
287 NewList(&csd->nativemodelist);
288 tags = tagptr = AllocVec(allocsize, MEMF_PUBLIC | MEMF_REVERSE);
289 buf = bufptr = AllocVec(allocsizebuf, MEMF_PUBLIC | MEMF_REVERSE);
291 cnt = 0;
292 for (y = 0; heighttable[y]; y++) {
293 WORD h = heighttable[y];
294 for (x = 0; widthtable[x]; x++) {
295 WORD w = widthtable[x];
296 WORD d, res;
297 ULONG modeid;
299 modeid = 0;
300 if (w == 1280) {
301 res = 2;
302 modeid |= SUPER_KEY;
303 if (!csd->aga && !csd->ecs_denise)
304 continue;
305 d = csd->aga ? 8 : 2;
307 else if (w == 640) {
308 res = 1;
309 modeid |= HIRES_KEY;
310 d = csd->aga ? 8 : 4;
311 } else {
312 res = 0;
313 d = csd->aga ? 8 : 5;
315 if (h >= 400)
316 modeid |= LORESLACE_KEY;
317 if (h == 200 || h == 400)
318 modeid |= NTSC_MONITOR_ID;
319 else
320 modeid |= PAL_MONITOR_ID;
322 for (i = 0; i < SPECIALMODES; i++) {
323 ULONG mid = modeid;
324 UWORD d2 = d;
325 if (i == 1) {
326 if (!csd->aga && (modeid & SUPER_KEY))
327 continue;
328 mid |= EXTRAHALFBRITE_KEY;
329 d2 = 6;
330 } else if (i == 2) {
331 if (!csd->aga && (modeid & SUPER_KEY))
332 continue;
333 mid |= HAM_KEY;
334 d2 = csd->aga ? 8 : 6;
337 addmodeid(csd, mid, w, h, d2, csd->aga ? i : (i == 0 ? res : i - 1 + 3));
338 modetags[cnt] = tagptr;
339 modeids[cnt++] = mid;
341 ADDTAG(aHidd_Sync_HDisp, w);
342 ADDTAG(aHidd_Sync_VDisp, h);
343 ADDTAG(aHidd_Sync_Flags, h >= 400 ? vHidd_Sync_Interlaced : 0);
344 ADDTAG(aHidd_Sync_PixelClock, 1000000000 / (280 >> res));
345 ADDTAG(TAG_DONE, 0);
351 if (csd->aga) {
353 pftags_aga[0] = tagptr;
354 ADDTAG(aHidd_PixFmt_RedShift, 8);
355 ADDTAG(aHidd_PixFmt_GreenShift, 16);
356 ADDTAG(aHidd_PixFmt_BlueShift, 24);
357 ADDTAG(aHidd_PixFmt_AlphaShift, 0);
358 ADDTAG(aHidd_PixFmt_RedMask, 0x00FF0000);
359 ADDTAG(aHidd_PixFmt_GreenMask, 0x0000FF00);
360 ADDTAG(aHidd_PixFmt_BlueMask, 0x000000FF);
361 ADDTAG(aHidd_PixFmt_AlphaMask, 0x00000000);
362 ADDTAG(aHidd_PixFmt_CLUTMask, 0x000000FF);
363 ADDTAG(aHidd_PixFmt_CLUTShift, 0);
364 ADDTAG(aHidd_PixFmt_ColorModel, vHidd_ColorModel_Palette);
365 ADDTAG(aHidd_PixFmt_Depth, 8);
366 ADDTAG(aHidd_PixFmt_BytesPerPixel, 1);
367 ADDTAG(aHidd_PixFmt_BitsPerPixel, 8);
368 ADDTAG(aHidd_PixFmt_StdPixFmt, vHidd_StdPixFmt_Plane);
369 ADDTAG(aHidd_PixFmt_BitMapType, vHidd_BitMapType_Planar);
370 ADDTAG(TAG_DONE, 0);
372 pftags_aga[1] = tagptr;
373 ADDTAG(aHidd_PixFmt_RedShift, 8);
374 ADDTAG(aHidd_PixFmt_GreenShift, 16);
375 ADDTAG(aHidd_PixFmt_BlueShift, 24);
376 ADDTAG(aHidd_PixFmt_AlphaShift, 0);
377 ADDTAG(aHidd_PixFmt_RedMask, 0x00FF0000);
378 ADDTAG(aHidd_PixFmt_GreenMask, 0x0000FF00);
379 ADDTAG(aHidd_PixFmt_BlueMask, 0x000000FF);
380 ADDTAG(aHidd_PixFmt_AlphaMask, 0x00000000);
381 ADDTAG(aHidd_PixFmt_CLUTMask, 0x000000FF);
382 ADDTAG(aHidd_PixFmt_CLUTShift, 0);
383 ADDTAG(aHidd_PixFmt_ColorModel, vHidd_ColorModel_Palette);
384 ADDTAG(aHidd_PixFmt_Depth, 6);
385 ADDTAG(aHidd_PixFmt_BytesPerPixel, 1);
386 ADDTAG(aHidd_PixFmt_BitsPerPixel, 6);
387 ADDTAG(aHidd_PixFmt_StdPixFmt, vHidd_StdPixFmt_Plane);
388 ADDTAG(aHidd_PixFmt_BitMapType, vHidd_BitMapType_Planar);
389 ADDTAG(TAG_DONE, 0);
391 pftags_aga[2] = NULL;
393 mode_tags_aga = tagptr;
394 ADDTAG(aHidd_Sync_HMin, 112);
395 ADDTAG(aHidd_Sync_VMin, 112);
396 ADDTAG(aHidd_Sync_HMax, 16384);
397 ADDTAG(aHidd_Sync_VMax, 16384);
399 for (j = 0; specialmask_aga[j] != 0xffffffff; j++) {
400 if (pftags_aga[j])
401 ADDTAG(aHidd_Gfx_PixFmtTags, (IPTR)pftags_aga[j]);
402 for (i = 0; i < cnt; i++) {
403 ULONG modeid = modeids[i];
404 if ((j == 0 && !(modeid & SPECIAL_MODE_MASK)) || (j > 0 && ((modeid & SPECIAL_MODE_MASK) == specialmask_aga[j]))) {
405 makemodename(modeid, bufptr);
406 ADDTAG(aHidd_Sync_Description, (IPTR)bufptr);
407 bufptr += strlen(bufptr) + 1;
408 ADDTAG(aHidd_Gfx_SyncTags, (IPTR)modetags[i]);
413 ADDTAG(TAG_DONE, 0);
415 mytags[0].ti_Data = (IPTR)mode_tags_aga;
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_Data = (IPTR)mode_tags_ecs;
548 D(bug("alloc=%d alloced=%d\n", allocsize, (ULONG)tagptr - (ULONG)tags));
549 D(bug("allocbuf=%d allocedbuf=%d\n", allocsizebuf, bufptr - buf));
551 EnterFunc(bug("AGFX::New()\n"));
553 mymsg.mID = msg->mID;
554 mymsg.attrList = mytags;
555 msg = &mymsg;
557 /* Register gfxmodes */
558 o = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
559 if (NULL != o)
561 struct amigagfx_data *data = OOP_INST_DATA(cl, o);
562 struct NativeChipsetMode *node;
563 HIDDT_ModeID *midp;
564 UWORD pfcnt;
565 OOP_MethodID HiddGfxBase = csd->cs_HiddGfxBase;
566 OOP_Object *pixelformats[8] = { 0 };
568 D(bug("AGFX::New(): Got object from super\n"));
569 NewList((struct List *)&data->bitmaps);
570 csd->initialized = 1;
572 /* this can't be the right way to match modes.. */
573 csd->superforward = TRUE;
574 midp = HIDD_Gfx_QueryModeIDs(o, NULL);
575 for (pfcnt = 0, i = 0; midp[i] != vHidd_ModeID_Invalid; i++) {
576 OOP_Object *sync, *pf;
577 HIDDT_ModeID mid = midp[i];
578 if (!HIDD_Gfx_GetMode(o, mid, &sync, &pf))
579 continue;
580 for (j = 0; j < pfcnt; j++) {
581 if (pf == pixelformats[j])
582 break;
584 if (j < pfcnt)
585 continue;
586 pixelformats[pfcnt++] = pf;
588 while (pfcnt < 8) {
589 if (csd->aga)
590 pixelformats[pfcnt] = pixelformats[0];
591 else
592 pixelformats[pfcnt] = pixelformats[pfcnt - 1];
593 pfcnt++;
595 for (i = 0; i < pfcnt; i++) {
596 DB2(bug("pf %d: %p\n", i, pixelformats[i]));
599 ForeachNode(&csd->nativemodelist, node) {
600 if (!node->pf) {
601 OOP_Object *sync = NULL;
602 for (i = 0; midp[i] != vHidd_ModeID_Invalid; i++) {
603 HIDDT_ModeID mid = midp[i];
604 IPTR dwidth, dheight;
605 OOP_Object *pf;
606 struct NativeChipsetMode *node2;
607 BOOL found = FALSE;
608 if (!HIDD_Gfx_GetMode(o, mid, &sync, &pf))
609 continue;
610 OOP_GetAttr(sync, aHidd_Sync_HDisp, &dwidth);
611 OOP_GetAttr(sync, aHidd_Sync_VDisp, &dheight);
612 if (node->width != dwidth || node->height != dheight)
613 continue;
614 ForeachNode(&csd->nativemodelist, node2) {
615 if (node->width == dwidth && node->height == dheight) {
616 if (node2->sync == sync) {
617 found = TRUE;
618 break;
622 if (!found)
623 break;
625 if (midp[i] == vHidd_ModeID_Invalid) {
626 sync = NULL;
627 D(bug("sync not found!?\n"));
629 node->sync = sync;
630 node->pf = pixelformats[node->special];
631 DB2(bug("%08x %dx%dx%d sync = %p pf = %p\n",
632 node->modeid, node->width, node->height, node->depth, node->sync, node->pf));
635 HIDD_Gfx_ReleaseModeIDs(o, midp);
636 csd->superforward = FALSE;
637 #if 1
638 ForeachNode(&csd->nativemodelist, node) {
639 DB2(bug("%08x %dx%dx%d sync = %p pf = %p\n", node->modeid, node->width, node->height, node->depth, node->sync, node->pf));
641 #endif
644 FreeVec(buf);
645 FreeVec(tags);
646 ReturnPtr("AGFX::New", OOP_Object *, o);
649 /********** GfxHidd::Dispose() ******************************/
650 VOID AmigaVideoCl__Root__Dispose(OOP_Class *cl, OOP_Object *o, OOP_Msg msg)
652 EnterFunc(bug("AGFX::Dispose(o=%p)\n", o));
654 D(bug("AGFX::Dispose: calling super\n"));
655 OOP_DoSuperMethod(cl, o, msg);
657 ReturnVoid("AGFX::Dispose");
661 OOP_Object *AmigaVideoCl__Hidd_Gfx__CreateObject(OOP_Class *cl, OOP_Object *o, struct pHidd_Gfx_CreateObject *msg)
663 OOP_Object *object = NULL;
665 EnterFunc(bug("AGFX::CreateObject()\n"));
667 if (msg->cl == CSD(cl)->cs_basebm)
669 struct amigavideo_staticdata *csd = CSD(cl);
670 struct Library *UtilityBase = csd->cs_UtilityBase;
671 HIDDT_ModeID modeid;
672 struct pHidd_Gfx_CreateObject p;
673 struct TagItem tags[] =
675 { TAG_IGNORE, TAG_IGNORE }, /* Placeholder for aHidd_BitMap_ClassPtr */
676 { TAG_MORE, (IPTR)msg->attrList }
679 modeid = (HIDDT_ModeID)GetTagData(aHidd_BitMap_ModeID, vHidd_ModeID_Invalid, msg->attrList);
680 D(bug("modeid=%08x\n", modeid));
681 if (modeid != vHidd_ModeID_Invalid) {
682 tags[0].ti_Tag = aHidd_BitMap_ClassPtr;
683 tags[0].ti_Data = (IPTR)CSD(cl)->amigabmclass;
686 p.mID = msg->mID;
687 p.cl = msg->cl;
688 p.attrList = tags;
690 object = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg)&p);
692 else
693 object = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
695 ReturnPtr("AGFX::CreateObject", OOP_Object *, object);
698 VOID AmigaVideoCl__Root__Get(OOP_Class *cl, OOP_Object *o, struct pRoot_Get *msg)
700 struct amigavideo_staticdata *csd = CSD(cl);
701 ULONG idx;
703 //bug("AmigaVideoCl__Root__Get %x\n", msg->attrID);
705 if (IS_GFX_ATTR(msg->attrID, idx))
707 //bug("=%x\n", idx);
708 switch (idx)
710 case aoHidd_Gfx_HWSpriteTypes:
711 *msg->storage = vHidd_SpriteType_3Plus1;
712 return;
713 case aoHidd_Gfx_SupportsHWCursor:
714 case aoHidd_Gfx_NoFrameBuffer:
715 *msg->storage = TRUE;
716 return;
717 case aoHidd_Gfx_IsWindowed:
718 *msg->storage = FALSE;
719 return;
720 case aoHidd_Gfx_DriverName:
721 *msg->storage = (IPTR)"AmigaVideo";
722 return;
725 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
728 VOID AmigaVideoCl__Root__Set(OOP_Class *cl, OOP_Object *obj, struct pRoot_Set *msg)
730 struct amigavideo_staticdata *csd = CSD(cl);
731 struct Library *UtilityBase = csd->cs_UtilityBase;
732 struct TagItem *tag, *tstate;
734 tstate = msg->attrList;
735 while((tag = NextTagItem(&tstate)))
737 ULONG idx;
738 D(bug("AmigaVideoCl__Root__Set %x\n", tag->ti_Tag));
739 if (IS_GFX_ATTR(tag->ti_Tag, idx)) {
740 D(bug("->%d\n", idx));
741 switch(idx)
743 case aoHidd_Gfx_ActiveCallBack:
744 csd->acb = (void *)tag->ti_Data;
745 break;
747 case aoHidd_Gfx_ActiveCallBackData:
748 csd->acbdata = (APTR)tag->ti_Data;
749 break;
753 OOP_DoSuperMethod(cl, obj, (OOP_Msg)msg);
756 ULONG AmigaVideoCl__Hidd_Gfx__ShowViewPorts(OOP_Class *cl, OOP_Object *o, struct pHidd_Gfx_ShowViewPorts *msg)
758 struct amigavideo_staticdata *csd = CSD(cl);
759 struct Library *OOPBase = csd->cs_OOPBase;
760 struct HIDD_ViewPortData *vpd = msg->Data;
761 OOP_Object *bm = NULL;
763 if (vpd)
764 bm = vpd->Bitmap;
766 D(bug("AmigaShowViewPorts %p %p\n", vpd, bm));
768 if (bm) {
769 struct amigabm_data *data = OOP_INST_DATA(OOP_OCLASS(bm), bm);
770 IPTR tags[] = {aHidd_BitMap_Visible, TRUE, TAG_DONE};
771 IPTR modeid = vHidd_ModeID_Invalid;
773 OOP_GetAttr(bm, aHidd_BitMap_ModeID , &modeid);
774 csd->modeid = modeid;
775 setmode(csd, data);
776 OOP_SetAttrs(bm, (struct TagItem *)tags);
778 if (csd->acb)
779 csd->acb(csd->acbdata, NULL);
781 } else {
782 resetmode(csd);
785 return TRUE;
788 VOID AmigaVideoCl__Hidd_Gfx__CopyBox(OOP_Class *cl, OOP_Object *o, struct pHidd_Gfx_CopyBox *msg)
790 struct amigavideo_staticdata *csd = CSD(cl);
791 struct Library *OOPBase = csd->cs_OOPBase;
792 HIDDT_DrawMode mode = GC_DRMD(msg->gc);
793 IPTR src, dst;
794 BOOL ok = FALSE;
796 OOP_GetAttr(msg->src, aHidd_BitMap_AmigaVideo_Drawable, &src);
797 OOP_GetAttr(msg->dest, aHidd_BitMap_AmigaVideo_Drawable, &dst);
798 if (src && dst) {
799 struct amigabm_data *sdata = OOP_INST_DATA(OOP_OCLASS(msg->src), msg->src);
800 struct amigabm_data *ddata = OOP_INST_DATA(OOP_OCLASS(msg->dest), msg->dest);
801 ok = blit_copybox(csd, sdata->pbm, ddata->pbm, msg->srcX, msg->srcY, msg->width, msg->height, msg->destX, msg->destY, mode);
803 if (!ok)
804 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
807 BOOL AmigaVideoCl__Hidd_Gfx__CopyBoxMasked(OOP_Class *cl, OOP_Object *o, struct pHidd_Gfx_CopyBoxMasked *msg)
809 struct amigavideo_staticdata *csd = CSD(cl);
810 struct Library *OOPBase = csd->cs_OOPBase;
811 HIDDT_DrawMode mode = GC_DRMD(msg->gc);
812 IPTR src, dst;
813 BOOL ok = FALSE;
815 OOP_GetAttr(msg->src, aHidd_BitMap_AmigaVideo_Drawable, &src);
816 OOP_GetAttr(msg->dest, aHidd_BitMap_AmigaVideo_Drawable, &dst);
817 if (src && dst) {
818 struct amigabm_data *sdata = OOP_INST_DATA(OOP_OCLASS(msg->src), msg->src);
819 struct amigabm_data *ddata = OOP_INST_DATA(OOP_OCLASS(msg->dest), msg->dest);
820 ok = blit_copybox_mask(csd, sdata->pbm, ddata->pbm, msg->srcX, msg->srcY, msg->width, msg->height, msg->destX, msg->destY, mode, msg->mask);
822 if (!ok)
823 return OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
825 return TRUE;
828 BOOL AmigaVideoCl__Hidd_Gfx__SetCursorShape(OOP_Class *cl, OOP_Object *shape, struct pHidd_Gfx_SetCursorShape *msg)
830 struct amigavideo_staticdata *csd = CSD(cl);
831 struct Library *OOPBase = csd->cs_OOPBase;
832 IPTR width, height;
833 UWORD maxw, maxh;
835 OOP_GetAttr(msg->shape, aHidd_BitMap_Width, &width);
836 OOP_GetAttr(msg->shape, aHidd_BitMap_Height, &height);
838 maxw = (csd->aga ? 64 : 16);
839 maxh = maxw * 2;
841 if (width > maxw || height > maxh)
842 return FALSE;
844 return setsprite(csd, width, height, msg);
847 BOOL AmigaVideoCl__Hidd_Gfx__GetMaxSpriteSize(OOP_Class *cl, ULONG Type, ULONG *Width, ULONG *Height)
849 struct amigavideo_staticdata *csd = CSD(cl);
850 *Width = csd->aga ? 64 : 16;
851 *Height = *Width * 2;
852 return TRUE;
854 BOOL AmigaVideoCl__Hidd_Gfx__SetCursorPos(OOP_Class *cl, OOP_Object *o, struct pHidd_Gfx_SetCursorPos *msg)
856 struct amigavideo_staticdata *csd = CSD(cl);
857 setspritepos(csd, msg->x, msg->y);
858 return TRUE;
860 VOID AmigaVideoCl__Hidd_Gfx__SetCursorVisible(OOP_Class *cl, OOP_Object *o, struct pHidd_Gfx_SetCursorVisible *msg)
862 struct amigavideo_staticdata *csd = CSD(cl);
863 setspritevisible(csd, msg->visible);
866 ULONG AmigaVideoCl__Hidd_Gfx__MakeViewPort(OOP_Class *cl, OOP_Object *o, struct pHidd_Gfx_MakeViewPort *msg)
868 D(struct HIDD_ViewPortData *vpd = msg->Data);
870 D(bug("AmigaVideoCl__Hidd_Gfx__MakeViewPort vp=%p bm=%p vpe=%p\n", vpd->vpe->ViewPort, vpd->Bitmap, vpd->vpe));
871 /* TODO: implement this correctly */
872 return MVP_OK;
875 void AmigaVideoCl__Hidd_Gfx__CleanViewPort(OOP_Class *cl, OOP_Object *o, struct pHidd_Gfx_CleanViewPort *msg)
877 struct amigavideo_staticdata *csd = CSD(cl);
878 struct Library *GfxBase = csd->cs_GfxBase;
879 struct HIDD_ViewPortData *vpd = msg->Data;
880 struct ViewPort *vp = vpd->vpe->ViewPort;
882 D(bug("AmigaVideoCl__Hidd_Gfx__CleanViewPort vp=%p bm=%p vpe=%p\n", vpd->vpe->ViewPort, vpd->Bitmap, vpd->vpe));
883 /* It's safe to call these functions on NULL pointers */
884 FreeCopList(vp->ClrIns);
885 FreeCopList(vp->DspIns);
886 FreeCopList(vp->SprIns);
888 if (vp->UCopIns)
890 FreeCopList(vp->UCopIns->FirstCopList);
891 FreeMem(vp->UCopIns, sizeof(struct UCopList));
894 /* Everything has been freed */
895 vp->ClrIns = NULL;
896 vp->DspIns = NULL;
897 vp->SprIns = NULL;
898 vp->UCopIns = NULL;
901 static void freeattrbases(struct amigavideo_staticdata *csd)
903 struct Library *OOPBase = csd->cs_OOPBase;
905 OOP_ReleaseAttrBase(IID_Hidd);
906 OOP_ReleaseAttrBase(IID_Hidd_BitMap);
907 OOP_ReleaseAttrBase(IID_Hidd_PlanarBM);
908 OOP_ReleaseAttrBase(IID_Hidd_BitMap_AmigaVideo);
909 OOP_ReleaseAttrBase(IID_Hidd_GC);
910 OOP_ReleaseAttrBase(IID_Hidd_Sync);
911 OOP_ReleaseAttrBase(IID_Hidd_Gfx);
912 OOP_ReleaseAttrBase(IID_Hidd_PixFmt);
913 OOP_ReleaseAttrBase(IID_Hidd_ColorMap);
916 int Init_AmigaVideoClass(LIBBASETYPEPTR LIBBASE)
918 struct amigavideo_staticdata *csd = &LIBBASE->csd;
919 struct Library *OOPBase = csd->cs_OOPBase;
921 D(bug("Init_AmigaVideoClass\n"));
922 __IHidd = OOP_ObtainAttrBase(IID_Hidd);
923 __IHidd_BitMap = OOP_ObtainAttrBase(IID_Hidd_BitMap);
924 __IHidd_PlanarBM = OOP_ObtainAttrBase(IID_Hidd_PlanarBM);
925 __IHidd_BitMap_AmigaVideo = OOP_ObtainAttrBase(IID_Hidd_BitMap_AmigaVideo);
926 __IHidd_GC = OOP_ObtainAttrBase(IID_Hidd_GC);
927 __IHidd_Sync = OOP_ObtainAttrBase(IID_Hidd_Sync);
928 __IHidd_Gfx = OOP_ObtainAttrBase(IID_Hidd_Gfx);
929 __IHidd_PixFmt = OOP_ObtainAttrBase(IID_Hidd_PixFmt);
930 __IHidd_ColorMap = OOP_ObtainAttrBase(IID_Hidd_ColorMap);
932 if (!__IHidd || !__IHidd_BitMap || !__IHidd_PlanarBM || !__IHidd_BitMap_AmigaVideo ||
933 !__IHidd_GC || !__IHidd_Sync || !__IHidd_Gfx || !__IHidd_PixFmt || !__IHidd_ColorMap)
935 D(bug("Init_AmigaVideoClass fail\n"));
936 freeattrbases(csd);
937 return 0;
939 return TRUE;
943 static int Expunge_AmigaVideoClass(LIBBASETYPEPTR LIBBASE)
945 struct amigavideo_staticdata *csd = &LIBBASE->csd;
946 D(bug("Expunge_AmigaVideoClass\n"));
947 freeattrbases(csd);
948 return TRUE;
951 ADD2EXPUNGELIB(Expunge_AmigaVideoClass, 1)