Preserve uSrc MSB across lighting and blending
[pcsx_rearmed.git] / plugins / gpu_unai / gpu_inner_light_arm.h
CommitLineData
788f5e89
JW
1#ifndef _OP_LIGHT_ARM_H_
2#define _OP_LIGHT_ARM_H_
3
4////////////////////////////////////////////////////////////////////////////////
5// Extract bgr555 color from Gouraud u32 fixed-pt 8.3:8.3:8.2 rgb triplet
6//
7// INPUT:
8// 'gCol' input: rrrrrrrrXXXggggggggXXXbbbbbbbbXX
9// ^ bit 31
10// RETURNS:
11// u16 output: 0bbbbbgggggrrrrr
12// ^ bit 16
13// Where 'r,g,b' are integer bits of colors, 'X' fixed-pt, and '0' zero
14////////////////////////////////////////////////////////////////////////////////
92eab56a 15GPU_INLINE uint_fast16_t gpuLightingRGBARM(u32 gCol)
788f5e89 16{
92eab56a 17 uint_fast16_t out = 0x03E0; // don't need the mask after starting to write output
788f5e89
JW
18 u32 tmp;
19
20 asm ("and %[tmp], %[gCol], %[out]\n\t" // tmp holds 0x000000bbbbb00000
21 "and %[out], %[out], %[gCol], lsr #0x0B\n\t" // out holds 0x000000ggggg00000
22 "orr %[tmp], %[out], %[tmp], lsl #0x05\n\t" // tmp holds 0x0bbbbbggggg00000
23 "orr %[out], %[tmp], %[gCol], lsr #0x1B\n\t" // out holds 0x0bbbbbgggggrrrrr
24 : [out] "+&r" (out), [tmp] "=&r" (tmp)
25 : [gCol] "r" (gCol)
26 );
27
28 return out;
29}
30
31
92eab56a 32GPU_INLINE uint_fast16_t gpuLightingTXTARM(uint_fast16_t uSrc, u8 r5, u8 g5, u8 b5)
788f5e89 33{
92eab56a 34 uint_fast16_t out = 0x03E0;
788f5e89
JW
35 u32 db, dg;
36 asm ("and %[dg], %[out], %[src] \n\t"
37 "orr %[dg], %[dg], %[g5] \n\t"
38 "and %[db], %[out], %[src], lsr #0x05 \n\t"
39 "ldrb %[dg], [%[lut], %[dg]] \n\t"
40 "and %[out], %[out], %[src], lsl #0x05 \n\t"
41 "orr %[out], %[out], %[r5] \n\t"
42 "orr %[db], %[db], %[b5] \n\t"
43 "ldrb %[out], [%[lut], %[out]] \n\t"
44 "ldrb %[db], [%[lut], %[db]] \n\t"
92eab56a 45 "tst %[src], #0x8000\n\t"
788f5e89 46 "orr %[out], %[out], %[dg], lsl #0x05 \n\t"
92eab56a 47 "orrne %[out], %[out], #0x8000\n\t"
788f5e89
JW
48 "orr %[out], %[out], %[db], lsl #0x0A \n\t"
49 : [out] "=&r" (out), [db] "=&r" (db), [dg] "=&r" (dg)
50 : [r5] "r" (r5), [g5] "r" (g5), [b5] "r" (b5),
51 [lut] "r" (gpu_unai.LightLUT), [src] "r" (uSrc), "0" (out)
52 : "cc");
53 return out;
54}
55
92eab56a 56GPU_INLINE uint_fast16_t gpuLightingTXTGouraudARM(uint_fast16_t uSrc, u32 gCol)
788f5e89 57{
92eab56a 58 uint_fast16_t out = 0x03E0; // don't need the mask after starting to write output
788f5e89
JW
59 u32 db,dg,gtmp;
60 asm ("and %[dg], %[out], %[src] \n\t"
61 "and %[gtmp],%[out], %[gCol], lsr #0x0B \n\t"
62 "and %[db], %[out], %[src], lsr #0x05 \n\t"
63 "orr %[dg], %[dg], %[gtmp], lsr #0x05 \n\t"
64 "and %[gtmp],%[out], %[gCol] \n\t"
65 "ldrb %[dg], [%[lut], %[dg]] \n\t"
66 "and %[out], %[out], %[src], lsl #0x05 \n\t"
67 "orr %[out], %[out], %[gCol], lsr #0x1B \n\t"
68 "orr %[db], %[db], %[gtmp], lsr #0x05 \n\t"
69 "ldrb %[out], [%[lut], %[out]] \n\t"
70 "ldrb %[db], [%[lut], %[db]] \n\t"
92eab56a 71 "tst %[src], #0x8000\n\t"
788f5e89 72 "orr %[out], %[out], %[dg], lsl #0x05 \n\t"
92eab56a 73 "orrne %[out], %[out], #0x8000\n\t"
788f5e89
JW
74 "orr %[out], %[out], %[db], lsl #0x0A \n\t"
75 : [out] "=&r" (out), [db] "=&r" (db), [dg] "=&r" (dg),
76 [gtmp] "=&r" (gtmp) \
77 : [gCol] "r" (gCol), [lut] "r" (gpu_unai.LightLUT), "0" (out), [src] "r" (uSrc)
78 : "cc");
79
80 return out;
81}
82
83#endif //_OP_LIGHT_ARM_H_