Nugget
Bare-metal libraries and examples for the original PlayStation
Loading...
Searching...
No Matches
gte-gpf-gpl.c
Go to the documentation of this file.
1// GPF: general purpose interpolation (IR0 * IR -> MAC/IR, push color)
2// GPL: general purpose interpolation with base (MAC + IR0 * IR -> MAC/IR, push color)
3
4// clang-format off
5
6CESTER_TEST(gpf_shifted_unity, gte_tests,
7 cop2_put(8, 0x1000); // IR0 = 1.0
8 cop2_put(9, 100);
9 cop2_put(10, 200);
10 cop2_put(11, 300);
11 cop2_put(6, 0x00204060); // RGBC
13 cop2_cmd(COP2_GPF(1, 0));
14 int32_t mac1, mac2, mac3;
15 cop2_get(25, mac1);
16 cop2_get(26, mac2);
17 cop2_get(27, mac3);
21)
22
23CESTER_TEST(gpf_shifted_half, gte_tests,
24 cop2_put(8, 0x0800); // IR0 = 0.5
25 cop2_put(9, 1000);
26 cop2_put(10, 2000);
27 cop2_put(11, 4000);
28 cop2_put(6, 0x00808080);
31 int32_t mac1, mac2, mac3;
35 // IR0*IR >> 12 = 0x800*IR >> 12 = IR/2
39)
40
41// GPF pushes color FIFO
42CESTER_TEST(gpf_color_fifo_push, gte_tests,
43 cop2_put(8, 0x1000); // IR0 = 1.0
44 cop2_put(9, 0x0800); // IR1 -> MAC1=0x800, /16=128
45 cop2_put(10, 0x0400); // IR2 -> MAC2=0x400, /16=64
46 cop2_put(11, 0x0200); // IR3 -> MAC3=0x200, /16=32
47 cop2_put(6, 0xaa000000); // RGBC: CODE=0xaa
49 cop2_cmd(COP2_GPF(1, 0));
50 uint32_t rgb2;
51 cop2_get(22, rgb2);
52 uint8_t r = rgb2 & 0xff;
53 uint8_t g = (rgb2 >> 8) & 0xff;
54 uint8_t b = (rgb2 >> 16) & 0xff;
55 uint8_t cd = (rgb2 >> 24) & 0xff;
56 ramsyscall_printf("GPF color: R=%u G=%u B=%u CD=0x%02x\n", r, g, b, cd);
57 cester_assert_uint_eq(0xaa, cd); // CODE byte preserved
58 // R = MAC1/16 = 0x800/16 = 128
62)
63
64// GPF unshifted (sf=0)
65CESTER_TEST(gpf_unshifted, gte_tests,
66 cop2_put(8, 2); // IR0 = 2
67 cop2_put(9, 100);
68 cop2_put(10, 200);
69 cop2_put(11, 300);
70 cop2_put(6, 0x00808080);
73 int32_t mac1, mac2, mac3;
74 cop2_get(25, mac1);
75 cop2_get(26, mac2);
76 cop2_get(27, mac3);
77 // sf=0: no shift, MAC = IR0*IR
81)
82
83// GPL shifted with base
85 cop2_put(25, 1000); // MAC1 base
86 cop2_put(26, 2000); // MAC2 base
87 cop2_put(27, 3000); // MAC3 base
88 cop2_put(8, 0x1000); // IR0 = 1.0
89 cop2_put(9, 100);
90 cop2_put(10, 200);
91 cop2_put(11, 300);
92 cop2_put(6, 0x00808080);
94 cop2_cmd(COP2_GPL(1, 0));
95 int32_t mac1, mac2, mac3;
96 cop2_get(25, mac1);
97 cop2_get(26, mac2);
98 cop2_get(27, mac3);
99 // GPL sf=1: MAC_new = (MAC_old << 12 + IR0 * IR) >> 12
100 // = ((1000<<12) + 4096*100) >> 12 = (4096000+409600)>>12 = 1100
104)
105
106// GPL unshifted (sf=0): MAC base used as-is, no shift
107CESTER_TEST(gpl_unshifted, gte_tests,
108 cop2_put(25, 100);
109 cop2_put(26, 200);
110 cop2_put(27, 300);
111 cop2_put(8, 3); // IR0 = 3
112 cop2_put(9, 10);
113 cop2_put(10, 20);
114 cop2_put(11, 30);
115 cop2_put(6, 0x00808080);
118 int32_t mac1, mac2, mac3;
119 cop2_get(25, mac1);
120 cop2_get(26, mac2);
121 cop2_get(27, mac3);
122 // sf=0: MAC_new = MAC_old + IR0*IR = 100+30=130, 200+60=260, 300+90=390
126)
127
128// GPL pushes color FIFO
129CESTER_TEST(gpl_color_fifo, gte_tests,
130 cop2_put(25, 0);
131 cop2_put(26, 0);
132 cop2_put(27, 0);
133 cop2_put(8, 0x1000);
134 cop2_put(9, 0x0ff0); // /16 = 255
135 cop2_put(10, 0x0800); // /16 = 128
136 cop2_put(11, 0x0010); // /16 = 1
137 cop2_put(6, 0x55000000); // CODE=0x55
139 cop2_cmd(COP2_GPL(1, 0));
140 uint32_t rgb2;
141 cop2_get(22, rgb2);
142 uint8_t r = rgb2 & 0xff;
143 uint8_t g = (rgb2 >> 8) & 0xff;
144 uint8_t b = (rgb2 >> 16) & 0xff;
145 uint8_t cd = (rgb2 >> 24) & 0xff;
150)
cester_assert_uint_eq(5, cause1)
ramsyscall_printf("T21 phase=%s t=%u v=%02x cause=%u size=%u stat=%02x\n", phase, t/1000, response[0], cause, size,(nopCause==3 &&nopSize >=1) ? stat[0] :0xff)
#define cop2_cmd(op)
Definition cop2.h:175
#define COP2_GPL(sf, lm)
Definition cop2.h:169
#define cop2_put(reg, val)
Definition cop2.h:191
#define COP2_GPF(sf, lm)
Definition cop2.h:168
#define cop2_get(reg, dest)
Definition cop2.h:198
uint32_t r
Definition cpu.c:310
uint8_t g
Definition gte-depthcue.c:40
uint8_t cd
Definition gte-depthcue.c:208
uint8_t b
Definition gte-depthcue.c:41
uint32_t rgb2
Definition gte-depthcue.c:37
int32_t mac1
Definition gte-gpf-gpl.c:31
CESTER_TEST(gpf_shifted_unity, gte_tests, cop2_put(8, 0x1000);cop2_put(9, 100);cop2_put(10, 200);cop2_put(11, 300);cop2_put(6, 0x00204060);gte_clear_flag();cop2_cmd(COP2_GPF(1, 0));int32_t mac1, mac2, mac3;cop2_get(25, mac1);cop2_get(26, mac2);cop2_get(27, mac3);cester_assert_int_eq(100, mac1);cester_assert_int_eq(200, mac2);cester_assert_int_eq(300, mac3);) CESTER_TEST(gpf_shifted_half
cester_assert_int_eq(500, mac1)
gte_tests
Definition gte-gpf-gpl.c:23
int32_t mac2
Definition gte-gpf-gpl.c:31
gte_clear_flag()
int32_t mac3
Definition gte-gpf-gpl.c:31