PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
primitives.c
1/*
2# _____ ___ ____ ___ ____
3# ____| | ____| | | |____|
4# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5#-----------------------------------------------------------------------
6# (c) 2009 Lion
7# Licenced under Academic Free License version 2.0
8# Review ps2sdk README & LICENSE files for further details.
9*/
10
11#include <errno.h>
12#include <stdio.h>
13#include <kernel.h>
14#include <libgs.h>
15
16#include "internal.h"
17
18extern QWORD GsPrimWorkArea[];
19
20static GS_TEST GSGLOBAL_TEST1;
21static GS_TEST GSGLOBAL_TEST2;
22
23void GsOverridePrimAttributes(s8 override, s8 iip, s8 tme, s8 fge, s8 abe, s8 aa1, s8 fst, s8 ctxt, s8 fix)
24{
25 QWORD *p;
26
27 p=UNCACHED_SEG(GsPrimWorkArea);
28 gs_setGIF_TAG(((GS_GIF_TAG *)&p[0]), 2,1,0,0,GS_GIF_PACKED,1,gif_rd_ad);
29
30 //override. (0 = use PRIM)(1 = use PRMODE)
31 if(override)
32 {
33 gs_setR_PRMODECONT(((GS_R_PRMODECONT *)&p[1]), 0);
34 }
35 else
36 {
37 gs_setR_PRMODECONT(((GS_R_PRMODECONT *)&p[1]), 1);
38 }
39
40 gs_setR_PRMODE(((GS_R_PRMODE *)&p[2]), iip,tme,fge,abe,aa1,fst,ctxt,fix);
41
42 GsDmaSend(GsPrimWorkArea, 3);
43 GsDmaWait();
44}
45
46void GsEnableDithering(u8 enable, int mode)
47{
48 QWORD *p;
49
50 (void)mode;
51
52 p=UNCACHED_SEG(GsPrimWorkArea);
53 if(enable)
54 {
55 gs_setGIF_TAG(((GS_GIF_TAG *)&p[0]), 3,1,0,0,GS_GIF_PACKED,1,gif_rd_ad);
56 gs_setR_DTHE(((GS_R_DTHE *)&p[1]), 1);
57 gs_setR_DIMX(((GS_R_DIMX *)&p[2]), 4,2,5,3,0,6,1,7,5,3,4,2,1,7,0,6); //thanks to:"Maximus32" on ps2dev.org
58 gs_setR_COLCLAMP(((GS_R_COLCLAMP *)&p[3]), 1);
59
60 GsDmaSend(GsPrimWorkArea, 4);
61 }
62 else
63 {
64 gs_setGIF_TAG(((GS_GIF_TAG *)&p[0]), 2,1,0,0,GS_GIF_PACKED,1,gif_rd_ad);
65 gs_setR_DTHE(((GS_R_DTHE *)&p[1]), 0);
66 gs_setR_DIMX(((GS_R_DIMX *)&p[2]), 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
67
68 GsDmaSend(GsPrimWorkArea, 3);
69 }
70
71 GsDmaWait();
72}
73
74void GsEnableAlphaTransparency1(u16 enable,u16 method,u8 alpha_ref,u16 fail_method)
75{
76 QWORD *p;
77
78 p=UNCACHED_SEG(GsPrimWorkArea);
79 GSGLOBAL_TEST1.atest_enable = enable;
80 GSGLOBAL_TEST1.atest_method = method;
81 GSGLOBAL_TEST1.atest_reference = alpha_ref;
82 GSGLOBAL_TEST1.atest_fail_method = fail_method;
83
84 GsSetPixelTest1(GSGLOBAL_TEST1.atest_enable, GSGLOBAL_TEST1.atest_method, GSGLOBAL_TEST1.atest_reference, GSGLOBAL_TEST1.atest_fail_method,
85 GSGLOBAL_TEST1.datest_enable, GSGLOBAL_TEST1.datest_mode,
86 GSGLOBAL_TEST1.ztest_enable, GSGLOBAL_TEST1.ztest_method);
87
88 // tell GS in 16bit texture 1=transparent,0=solid
89 gs_setGIF_TAG(((GS_GIF_TAG *)&p[0]), 1,1,0,0,GS_GIF_PACKED,1,gif_rd_ad);
90 gs_setR_TEXA(((GS_R_TEXA *)&p[1]), 0x80, 0, 0x00);
91
92 GsDmaSend(GsPrimWorkArea, 2);
93 GsDmaWait();
94}
95
96void GsEnableAlphaTransparency2(u16 enable,u16 method,u8 alpha_ref,u16 fail_method)
97{
98 QWORD *p;
99
100 p=UNCACHED_SEG(GsPrimWorkArea);
101 GSGLOBAL_TEST2.atest_enable = enable;
102 GSGLOBAL_TEST2.atest_method = method;
103 GSGLOBAL_TEST2.atest_reference = alpha_ref;
104 GSGLOBAL_TEST2.atest_fail_method = fail_method;
105
106 GsSetPixelTest2(GSGLOBAL_TEST2.atest_enable, GSGLOBAL_TEST2.atest_method, GSGLOBAL_TEST2.atest_reference, GSGLOBAL_TEST2.atest_fail_method,
107 GSGLOBAL_TEST2.datest_enable, GSGLOBAL_TEST2.datest_mode,
108 GSGLOBAL_TEST2.ztest_enable, GSGLOBAL_TEST2.ztest_method);
109
110 // tell GS in 16bit texture 1=transparent,0=solid
111 gs_setGIF_TAG(((GS_GIF_TAG *)&p[0]), 1,1,0,0,GS_GIF_PACKED,1,gif_rd_ad);
112 gs_setR_TEXA(((GS_R_TEXA *)&p[1]), 0x80, 0, 0x00);
113
114 GsDmaSend(GsPrimWorkArea, 2);
115 GsDmaWait();
116}
117
118void GsEnableZbuffer1(u16 enable,u16 test_method)
119{
120 GSGLOBAL_TEST1.ztest_enable = enable;
121 GSGLOBAL_TEST1.ztest_method = test_method;
122
123 GsSetPixelTest1(GSGLOBAL_TEST1.atest_enable, GSGLOBAL_TEST1.atest_method, GSGLOBAL_TEST1.atest_reference, GSGLOBAL_TEST1.atest_fail_method,
124 GSGLOBAL_TEST1.datest_enable, GSGLOBAL_TEST1.datest_mode,
125 GSGLOBAL_TEST1.ztest_enable, GSGLOBAL_TEST1.ztest_method);
126}
127
128void GsEnableZbuffer2(u16 enable,u16 test_method)
129{
130 GSGLOBAL_TEST2.ztest_enable = enable;
131 GSGLOBAL_TEST2.ztest_method = test_method;
132
133 GsSetPixelTest2(GSGLOBAL_TEST2.atest_enable, GSGLOBAL_TEST2.atest_method, GSGLOBAL_TEST2.atest_reference, GSGLOBAL_TEST2.atest_fail_method,
134 GSGLOBAL_TEST2.datest_enable, GSGLOBAL_TEST2.datest_mode,
135 GSGLOBAL_TEST2.ztest_enable, GSGLOBAL_TEST2.ztest_method);
136
137}
138
139void GsEnableAlphaBlending1(u16 enable)
140{
141 QWORD *p;
142
143 p=UNCACHED_SEG(GsPrimWorkArea);
144 gs_setGIF_TAG(((GS_GIF_TAG *)&p[0]), 4,1,0,0,GS_GIF_PACKED,1,gif_rd_ad);
145
146 if(enable)
147 {
148 gs_setR_ALPHA_1(((GS_R_ALPHA *)&p[1]), 0,1,0,1,0x00); //last arg(0x00) is not used bceause of other settings
149 }
150 else
151 {
152 gs_setR_ALPHA_1(((GS_R_ALPHA *)&p[1]), 0,0,0,0,0x80);
153 }
154 gs_setR_PABE(((GS_R_PABE *)&p[2]), 0);
155 gs_setR_FBA_1(((GS_R_FBA *)&p[3]), 0);
156 gs_setR_TEXA(((GS_R_TEXA *)&p[4]), 0x80, 0, 0x00);
157
158 GsDmaSend(GsPrimWorkArea, 5);
159 GsDmaWait();
160}
161
162void GsEnableAlphaBlending2(u16 enable)
163{
164 QWORD *p;
165
166 p=UNCACHED_SEG(GsPrimWorkArea);
167 gs_setGIF_TAG(((GS_GIF_TAG*)&p[0]), 4,1,0,0,GS_GIF_PACKED,1,gif_rd_ad);
168
169 if(enable)
170 {
171 gs_setR_ALPHA_2(((GS_R_ALPHA*)&p[1]), 0,1,0,1,0x00); //last arg(0x00) is not used bceause of other settings
172 }
173 else
174 {
175 gs_setR_ALPHA_2(((GS_R_ALPHA *)&p[1]), 0,0,0,0,0x80);
176 }
177 gs_setR_PABE(((GS_R_PABE *)&p[2]), 0);
178 gs_setR_FBA_2(((GS_R_FBA *)&p[3]), 0);
179 gs_setR_TEXA(((GS_R_TEXA *)&p[4]), 0x80, 0, 0x00);
180
181 GsDmaSend(GsPrimWorkArea, 5);
182 GsDmaWait();
183}
#define gif_rd_ad
Definition libgs.h:326
Definition libgs.h:333