Skip to content

Commit 92d44c7

Browse files
authored
Make LoadRGB4 more 1.3 and 3.1 compatible
1 parent f9c17a9 commit 92d44c7

File tree

1 file changed

+125
-1
lines changed

1 file changed

+125
-1
lines changed

rom/graphics/loadrgb4.c

+125-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,92 @@
88
#include <aros/debug.h>
99
#include "graphics_intern.h"
1010

11+
static void pokeCL(UWORD *ci, UWORD target, UWORD table)
12+
{
13+
ULONG targ = (ULONG)target;
14+
if(!ci) return;
15+
targ &= 0x1fe;
16+
for(;ci;ci+=2)
17+
{
18+
if( ((*ci)==0xffff) && ((*(ci+1) == 0xfffe))) return;
19+
if(*ci == targ) break;
20+
}
21+
if (((*ci) == 0xffff) && ((*(ci+1)==0xfffe))) return;
22+
if(*ci == targ)
23+
{
24+
ci++;
25+
*ci++ = table;
26+
}
27+
}
28+
29+
static struct CopIns *pokeCI(struct CopIns *ci, UWORD *field1, short field2)
30+
{
31+
struct CopIns *c;
32+
c = ci;
33+
if(c)
34+
{
35+
short out = FALSE;
36+
while(!out)
37+
{
38+
switch(c->OpCode & 3)
39+
{
40+
case COPPER_MOVE:
41+
{
42+
if(c->DESTADDR == (((UWORD)field1) & 0x1fe))
43+
{
44+
short mask;
45+
if((mask = op&0xC000))
46+
{
47+
if(c->OpCode & mask)
48+
{
49+
c->DESTDATA = field2;
50+
return c;
51+
}
52+
}
53+
else
54+
{
55+
c->DESTDATA = field2;
56+
return c;
57+
}
58+
}
59+
c++;
60+
break;
61+
}
62+
case COPPER_WAIT:
63+
{
64+
if(c->HWAITPOS == 255)
65+
{
66+
return 0;
67+
}
68+
else c++;
69+
break;
70+
}
71+
case CPRNXTBUF:
72+
{
73+
if(c->NXTLIST == NULL)
74+
{
75+
out = TRUE;
76+
}
77+
else
78+
{
79+
if((c = c->NXTLIST->CopIns) == NULL)
80+
{
81+
out = TRUE;
82+
}
83+
}
84+
break;
85+
}
86+
default:
87+
{
88+
out=TRUE;
89+
break;
90+
}
91+
}
92+
}
93+
}
94+
return 0;
95+
}
96+
1197
/*****************************************************************************
1298
1399
NAME */
@@ -55,14 +141,35 @@
55141
AROS_LIBFUNC_INIT
56142

57143
WORD t;
144+
int i;
145+
volatile struct Custom *custom = (struct Custom *)0xdff000;
58146

59147
if (!vp)
148+
{
149+
// No ViewPort? Then alter the colors directly
150+
for (i = 0; i < count ; i++)
151+
custom->color[i] = *colors++;
60152
return;
61-
153+
}
62154
ASSERT_VALID_PTR(vp);
63155
ASSERT_VALID_PTR(colors);
64156

65157
/* TODO: Optimization */
158+
struct ColorMap *cm;
159+
UWORD *ct;
160+
161+
// Why do we need this? Answer: For non hidd screens SetRGB32 might fail to fill the color table. This is a good place, I think
162+
if(vp->ColorMap)
163+
{
164+
cm = vp->ColorMap;
165+
ct = cm->ColorTable;
166+
if(count > cm->Count) count = cm->Count;
167+
for(i = 0; i<count; i++)
168+
{
169+
*ct++ = *colors++;
170+
}
171+
colors -= count; // back to first color
172+
}
66173

67174
for (t = 0; t < count; t ++ )
68175
{
@@ -79,6 +186,23 @@
79186

80187
SetRGB32( vp, t, r, g, b );
81188
}
189+
190+
ObtainSemaphore(GfxBase->ActiViewCprSemaphore);
191+
for (t = 0; t < count; t ++ )
192+
{
193+
// Remaining question: Do we need to check VP_HIDE?
194+
if(vp->DspIns)
195+
{
196+
// we need to store it into the intermediate CopperList too
197+
pokeCL(vp->DspIns->CopLStart, &custom->color[t], colors[t]);
198+
pokeCL(vp->DspIns->CopSStart, &custom->color[t], colors[t]);
199+
pokeCI(vp->DspIns->CopIns, &custom->color[t], colors[t]);
200+
}
201+
}
202+
ReleaseSemaphore(GfxBase->ActiViewCprSemaphore);
203+
204+
// To make it visible immediately we need to update the view. To simplify it, we call MrgCop
205+
MrgCop(GfxBase->ActiView);
82206

83207
AROS_LIBFUNC_EXIT
84208

0 commit comments

Comments
 (0)