ac99cf32fc6feab15aab643f47259c14eeed5667
[pcsx_rearmed.git] / plugins / gpu_unai / gpu_inner_light_arm.h
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 ////////////////////////////////////////////////////////////////////////////////
15 GPU_INLINE u16 gpuLightingRGBARM(u32 gCol)
16 {
17   u16 out = 0x03E0; // don't need the mask after starting to write output
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
32 GPU_INLINE u16 gpuLightingTXTARM(u16 uSrc, u8 r5, u8 g5, u8 b5)
33 {
34   u16 out = 0x03E0;
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"
45        "orr    %[out], %[out],  %[dg],  lsl #0x05   \n\t"
46        "orr    %[out], %[out],  %[db],  lsl #0x0A   \n\t"
47     : [out] "=&r" (out), [db] "=&r" (db), [dg] "=&r" (dg)
48     : [r5] "r" (r5), [g5] "r" (g5),  [b5] "r" (b5),
49       [lut] "r" (gpu_unai.LightLUT), [src] "r" (uSrc), "0" (out)
50     : "cc");
51   return out;
52 }
53
54 GPU_INLINE u16 gpuLightingTXTGouraudARM(u16 uSrc, u32 gCol)
55 {
56   u16 out = 0x03E0; // don't need the mask after starting to write output
57   u32 db,dg,gtmp;
58   asm ("and    %[dg],  %[out],  %[src]   \n\t"
59        "and    %[gtmp],%[out],  %[gCol], lsr #0x0B \n\t"
60        "and    %[db],  %[out],  %[src],  lsr #0x05 \n\t"
61        "orr    %[dg],  %[dg],   %[gtmp], lsr #0x05 \n\t"
62        "and    %[gtmp],%[out],  %[gCol]  \n\t"
63        "ldrb   %[dg],  [%[lut], %[dg]]   \n\t"
64        "and    %[out], %[out],  %[src],  lsl #0x05 \n\t"
65        "orr    %[out], %[out],  %[gCol], lsr #0x1B \n\t"
66        "orr    %[db],  %[db],   %[gtmp], lsr #0x05 \n\t"
67        "ldrb   %[out], [%[lut], %[out]]  \n\t"
68        "ldrb   %[db],  [%[lut], %[db]]   \n\t"
69        "orr    %[out], %[out],  %[dg],   lsl #0x05 \n\t"
70        "orr    %[out], %[out],  %[db],   lsl #0x0A \n\t"
71        : [out] "=&r" (out), [db] "=&r" (db), [dg] "=&r" (dg),
72          [gtmp] "=&r" (gtmp) \
73        : [gCol] "r" (gCol), [lut] "r" (gpu_unai.LightLUT), "0" (out), [src] "r" (uSrc)
74        : "cc");
75
76   return out;
77 }
78
79 #endif  //_OP_LIGHT_ARM_H_