#define PXMASKH 0x39ce39ce // 0x3def3def, all but MSB for all colours\r
#elif defined(USE_BGR565)\r
#define PXCONV(t) ((t & 0x000e000e)<< 1) | ((t & 0x00e000e0)<<3) | ((t & 0x0e000e00)<<4)\r
-#define PXMASKL 0x08610861 // 0x18e318e3\r
+#define PXMASKL 0x08410841 // 0x18e318e3\r
#define PXMASKH 0x738e738e // 0x7bef7bef\r
#else // RGB565\r
#define PXCONV(t) ((t & 0x000e000e)<<12) | ((t & 0x00e000e0)<<3) | ((t & 0x0e000e00)>>7)\r
-#define PXMASKL 0x08610861 // 0x18e318e3\r
+#define PXMASKL 0x08410841 // 0x18e318e3\r
#define PXMASKH 0x738e738e // 0x7bef7bef\r
#endif\r
\r
// otherwise intensity difference between this and s/h will be wrong\r
t = PXCONV(t);\r
t |= (t >> 4) & PXMASKL;\r
+ // take into account that MegaDrive RGB output isn't linear, there is a larger\r
+ // step for 0->1 and 6->7. While the latter isn't obviously noticeable, the\r
+ // former is clearly visible (see color test in Knuckles Chaotix)\r
+ t |= ((t ^ PXMASKL) & (/*t>>4|*/t>>3|t>>2) & PXMASKL) << 1;\r
dpal[i] = t;\r
}\r
\r
// norm: xxx0, sh: 0xxx, hi: 0xxx + 7\r
if (sh)\r
{\r
- // shadowed pixels\r
+ // normal and shadowed pixels\r
for (i = 0; i < 0x40 / 2; i++) {\r
dpal[0xc0/2 + i] = dpal[i];\r
- dpal[0x80/2 + i] = (dpal[i] >> 1) & PXMASKH;\r
+ // take into account that MegaDrive RGB output isn't linear, see above\r
+ t = (dpal[i] >> 1) & PXMASKH;\r
+ dpal[0x80/2 + i] = t + ((t>>2|t>>1|t>>0) & (PXMASKL<<1));\r
}\r
// hilighted pixels\r
for (i = 0; i < 0x40 / 2; i++) {\r
- t = ((dpal[i] >> 1) & PXMASKH) + PXMASKH;\r
- t |= (t >> 4) & PXMASKL;\r
- dpal[0x40/2 + i] = t;\r
+ t = (dpal[i] >> 1) & PXMASKH;\r
+ dpal[0x40/2 + i] = t + PXMASKH + PXMASKL;\r
}\r
}\r
}\r
// otherwise intensity difference between this and s/h will be wrong\r
t = PXCONV(t);\r
t |= (t >> 4) & PXMASKL;\r
+ // take into account that MegaDrive RGB output isn't linear, see above\r
+ t |= ((t ^ PXMASKL) & (/*t>>4|*/t>>3|t>>2) & PXMASKL) << 1;\r
dpal[i] = dpal[0xc0/2 + i] = t;\r
}\r
\r
if (sh)\r
{\r
// shadowed pixels\r
- for (i = 0; i < 0x40 / 2; i++)\r
- dpal[0x80/2 + i] = (dpal[i] >> 1) & PXMASKH;\r
+ for (i = 0; i < 0x40 / 2; i++) {\r
+ // take into account that MegaDrive RGB output isn't linear, see above\r
+ t = (dpal[i] >> 1) & PXMASKH;\r
+ dpal[0x80/2 + i] = t + ((t>>2|t>>1|t>>0) & (PXMASKL<<1));\r
+ }\r
// hilighted pixels\r
for (i = 0; i < 0x40 / 2; i++) {\r
- t = ((dpal[i] >> 1) & PXMASKH) + PXMASKH;\r
- t |= (t >> 4) & PXMASKL;\r
- dpal[0x40/2 + i] = t;\r
+ t = (dpal[i] >> 1) & PXMASKH;\r
+ dpal[0x40/2 + i] = t + PXMASKH + PXMASKL;\r
}\r
}\r
}\r
\r
and r2, r8, \reg,lsr #4\r
orr \reg, \reg, r2\r
+\r
+ orr r3, \reg, \reg,lsr #1\r
+ and r3, r3, r8,lsl #2\r
+ bic r3, r3, r2,lsl #2\r
+ orr \reg, \reg, r3,lsr #1\r
.endm\r
\r
@ trashes: r2-r8,r12,lr; r8 = 0x08610861; r0,r1 are advanced\r
\r
@ hilighted pixels (0x40-0x7f):\r
@ t = ((dpal[i] >> 1) & 0x738e738e) + 0x738e738e;\r
- @ t |= (t >> 4) & 0x08610861;\r
+ @ t += 0x08610861;\r
@ r8=0x08610861\r
mov r12, #0x008e\r
orr r12,r12,#0x7300\r
orr r12,r12,r12,lsl #16\r
+ add r10,r12,r8\r
mov lr, #0x40/4\r
.fl_loopcpRGB555_hi:\r
ldmia r3!, {r1,r6}\r
and r1, r12, r1, lsr #1\r
and r6, r12, r6, lsr #1\r
- add r1, r12, r1\r
- add r6, r12, r6\r
- and r5, r8, r1, lsr #4\r
- and r7, r8, r6, lsr #4\r
- orr r1, r1, r5\r
- orr r6, r6, r7\r
+ add r1, r10, r1\r
+ add r6, r10, r6\r
stmia r4!, {r1,r6}\r
subs lr, lr, #1\r
bne .fl_loopcpRGB555_hi\r
\r
sub r3, r3, #0x40*2\r
@ shadowed (0x80-0xbf), shadow|hilight (aka normal, 0xc0-0xff) pixels:\r
+ @ t = (dpal[i] >> 1) & 0x738e738e;\r
+ @ t += ((t>>2|t>>1|t>>0) & (0x08610861<<1));\r
add r5, r3, #0xc0*2\r
mov lr, #0x40/4\r
.fl_loopcpRGB555_sh:\r
subs lr, lr, #1\r
stmia r5!, {r1,r6} @ 0xc0, normal\r
and r1, r12, r1, lsr #1\r
+ orr r0, r1, r1, lsr #1\r
+ orr r0, r0, r1, lsr #2\r
+ and r0, r0, r8, lsl #1\r
+ add r1, r1, r0\r
and r6, r12, r6, lsr #1\r
+ orr r0, r6, r6, lsr #1\r
+ orr r0, r0, r6, lsr #2\r
+ and r0, r0, r8, lsl #1\r
+ add r6, r6, r0\r
stmia r4!, {r1,r6}\r
bne .fl_loopcpRGB555_sh\r
\r