PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
lowlevel.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
20/* Miscellaneous */
21
22static s8 twh(s16 val)
23{
24 s8 res;
25
26 asm volatile ("plzcw %0, %1\n": "=r" (res) : "r" (val));
27 res = 31 - (res + 1);
28 if(val > res)
29 res++;
30
31 return res;
32}
33
34/* LOW LEVEL FUNCTIONS */
35
36int GsSetXYOffset1(u16 x, u16 y)
37{
38 QWORD *p;
39 p=UNCACHED_SEG(GsPrimWorkArea);
40 gs_setGIF_TAG(((GS_GIF_TAG *)&p[0]), 1,1,0,0,GS_GIF_PACKED,1,gif_rd_ad);
41 gs_setR_XYOFFSET_1(((GS_R_XYOFFSET *)&p[1]), x,y);
42
43 GsDmaSend(GsPrimWorkArea, 2);
44 GsDmaWait();
45
46 return 0;
47}
48
49int GsSetXYOffset2(u16 x, u16 y)
50{
51 QWORD *p;
52 p=UNCACHED_SEG(GsPrimWorkArea);
53 gs_setGIF_TAG(((GS_GIF_TAG *)&p[0]), 1,1,0,0,GS_GIF_PACKED,1,gif_rd_ad);
54 gs_setR_XYOFFSET_2(((GS_R_XYOFFSET *)&p[1]), x,y);
55
56 GsDmaSend(GsPrimWorkArea, 2);
57 GsDmaWait();
58
59 return 0;
60}
61
62int GsSetScissor1(u16 upper_x, u16 upper_y, u16 lower_x, u16 lower_y)
63{
64 QWORD *p;
65 p=UNCACHED_SEG(GsPrimWorkArea);
66 gs_setGIF_TAG(((GS_GIF_TAG *)&p[0]), 1,1,0,0,GS_GIF_PACKED,1,gif_rd_ad);
67 gs_setR_SCISSOR_1(((GS_R_SCISSOR *)&p[1]), upper_x,lower_x,upper_y,lower_y);
68
69 GsDmaSend(GsPrimWorkArea, 2);
70 GsDmaWait();
71
72 return 0;
73}
74
75int GsSetScissor2(u16 upper_x, u16 upper_y, u16 lower_x, u16 lower_y)
76{
77 QWORD *p;
78 p=UNCACHED_SEG(GsPrimWorkArea);
79 gs_setGIF_TAG(((GS_GIF_TAG *)&p[0]), 1,1,0,0,GS_GIF_PACKED,1,gif_rd_ad);
80 gs_setR_SCISSOR_2(((GS_R_SCISSOR *)&p[1]), upper_x,lower_x,upper_y,lower_y);
81
82 GsDmaSend(GsPrimWorkArea, 2);
83 GsDmaWait();
84
85 return 0;
86}
87
88int GsSetFrame1(u16 framebuffer_addr, u8 framebuffer_width, u8 psm, u32 draw_mask)
89{
90 QWORD *p;
91 p=UNCACHED_SEG(GsPrimWorkArea);
92 gs_setGIF_TAG(((GS_GIF_TAG *)&p[0]), 1,1,0,0,GS_GIF_PACKED,1,gif_rd_ad);
93 gs_setR_FRAME_1(((GS_R_FRAME *)&p[1]), framebuffer_addr,framebuffer_width,psm,draw_mask);
94
95 GsDmaSend(GsPrimWorkArea, 2);
96 GsDmaWait();
97
98 return 0;
99}
100
101int GsSetFrame2(u16 framebuffer_addr, u8 framebuffer_width, u8 psm, u32 draw_mask)
102{
103 QWORD *p;
104 p=UNCACHED_SEG(GsPrimWorkArea);
105 gs_setGIF_TAG(((GS_GIF_TAG *)&p[0]), 1,1,0,0,GS_GIF_PACKED,1,gif_rd_ad);
106 gs_setR_FRAME_2(((GS_R_FRAME *)&p[1]), framebuffer_addr,framebuffer_width,psm,draw_mask);
107
108 GsDmaSend(GsPrimWorkArea, 2);
109 GsDmaWait();
110
111 return 0;
112}
113
114int GsTextureFlush(void)
115{
116 QWORD *p;
117 p=UNCACHED_SEG(GsPrimWorkArea);
118 gs_setGIF_TAG(((GS_GIF_TAG *)&p[0]), 1,1,0,0,GS_GIF_PACKED,1,gif_rd_ad);
119 gs_setR_TEXFLUSH(((GS_R_TEXFLUSH *)&p[1]));
120
121 GsDmaSend(GsPrimWorkArea,2);
122 GsDmaWait();
123
124 return 0;
125}
126
127int GsSetPixelTest1(u8 enable_alpha_test, u8 alpha_test_method, u8 alpha_reference, u8 alpha_fail_method, u8 enable_dest_alpha_test, u8 dest_alpha_test_mode, u8 enable_zbuff_test, u8 alpha_zbuff_method)
128{
129 QWORD *p;
130 p=UNCACHED_SEG(GsPrimWorkArea);
131 gs_setGIF_TAG(((GS_GIF_TAG *)&p[0]), 1,1,0,0,GS_GIF_PACKED,1,gif_rd_ad);
132 gs_setR_TEST_1(((GS_R_TEST *)&p[1]), enable_alpha_test, alpha_test_method, alpha_reference, alpha_fail_method, enable_dest_alpha_test, dest_alpha_test_mode, enable_zbuff_test, alpha_zbuff_method);
133
134 GsDmaSend(GsPrimWorkArea, 2);
135 GsDmaWait();
136
137 return 0;
138}
139
140int GsSetPixelTest2(u8 enable_alpha_test, u8 alpha_test_method, u8 alpha_reference, u8 alpha_fail_method, u8 enable_dest_alpha_test, u8 dest_alpha_test_mode, u8 enable_zbuff_test, u8 alpha_zbuff_method)
141{
142 QWORD *p;
143 p=UNCACHED_SEG(GsPrimWorkArea);
144 gs_setGIF_TAG(((GS_GIF_TAG *)&p[0]), 1,1,0,0,GS_GIF_PACKED,1,gif_rd_ad);
145 gs_setR_TEST_2(((GS_R_TEST *)&p[1]), enable_alpha_test, alpha_test_method, alpha_reference, alpha_fail_method, enable_dest_alpha_test, dest_alpha_test_mode, enable_zbuff_test, alpha_zbuff_method);
146
147 GsDmaSend(GsPrimWorkArea, 2);
148 GsDmaWait();
149
150 return 0;
151}
152
153int GsSelectTexure1(u16 tex_addr, u8 addr_width, u8 tex_pixmode, u16 tex_width, u16 tex_height, u16 clut_addr, u8 clut_pixmode, u8 clut_storagemode,u8 clut_offset)
154{
155 QWORD *p;
156 p=UNCACHED_SEG(GsPrimWorkArea);
157 gs_setGIF_TAG(((GS_GIF_TAG *)&p[0]), 1,1,0,0,GS_GIF_PACKED,1,gif_rd_ad);
158 gs_setR_TEX0_1(((GS_R_TEX0 *)&p[1]), tex_addr,addr_width,tex_pixmode, twh(tex_width), twh(tex_height),1,0,clut_addr,clut_pixmode,clut_storagemode,clut_offset,4); /*4 load contex 0*/
159
160 GsDmaSend(GsPrimWorkArea, 2);
161 GsDmaWait();
162
163 return 0;
164}
165
166int GsSelectTexure2(u16 tex_addr, u8 addr_width, u8 tex_pixmode, u16 tex_width, u16 tex_height, u16 clut_addr, u8 clut_pixmode, u8 clut_storagemode,u8 clut_offset)
167{
168 QWORD *p;
169 p=UNCACHED_SEG(GsPrimWorkArea);
170 gs_setGIF_TAG(((GS_GIF_TAG *)&p[0]), 1,1,0,0,GS_GIF_PACKED,1,gif_rd_ad);
171 gs_setR_TEX0_2(((GS_R_TEX0 *)&p[1]), tex_addr, addr_width, tex_pixmode, twh(tex_width), twh(tex_height), 1, 0, clut_addr, clut_pixmode, clut_storagemode,clut_offset,5);/*5 load contex 2*/
172
173 GsDmaSend(GsPrimWorkArea, 2);
174 GsDmaWait();
175
176 return 0;
177}
178
179void GsSetFogColor(u8 r, u8 g, u8 b)
180{
181 QWORD *p;
182 p=UNCACHED_SEG(GsPrimWorkArea);
183 gs_setGIF_TAG(((GS_GIF_TAG*)&p[0]), 1,1,0,0,GS_GIF_PACKED,1,gif_rd_ad);
184 gs_setR_FOGCOLOR(((GS_R_FOGCOLOR*)&p[1]), r,g,b);
185
186 GsDmaSend(GsPrimWorkArea, 2);
187 GsDmaWait();
188}
189
190void GsEnableColorClamp(u16 enable)
191{
192 QWORD *p;
193 p=UNCACHED_SEG(GsPrimWorkArea);
194 gs_setGIF_TAG(((GS_GIF_TAG *)&p[0]), 1,1,0,0,GS_GIF_PACKED,1,gif_rd_ad);
195 gs_setR_COLCLAMP(((GS_R_COLCLAMP *)&p[1]), enable);
196
197 GsDmaSend(GsPrimWorkArea, 2);
198 GsDmaWait();
199}
#define gif_rd_ad
Definition libgs.h:326
Definition libgs.h:333