psp/sys/
ge.rs

1use core::ffi::c_void;
2
3/// Stores the state of the GE.
4#[repr(C)]
5pub struct GeContext {
6    pub context: [u32; 512],
7}
8
9#[repr(C)]
10/// Structure storing a stack (for CALL/RET)
11pub struct GeStack {
12    pub stack: [u32; 8],
13}
14
15#[repr(C)]
16/// Structure to hold the callback data
17pub struct GeCallbackData {
18    pub signal_func: Option<extern "C" fn(id: i32, arg: *mut c_void)>,
19    pub signal_arg: *mut c_void,
20    pub finish_func: Option<extern "C" fn(id: i32, arg: *mut c_void)>,
21    pub finish_arg: *mut c_void,
22}
23
24#[repr(C)]
25pub struct GeListArgs {
26    pub size: u32,
27    pub context: *mut GeContext,
28    pub num_stacks: u32,
29    pub stacks: *mut GeStack,
30}
31
32impl Default for GeListArgs {
33    #[inline(always)]
34    fn default() -> Self {
35        Self {
36            size: 0,
37            context: core::ptr::null_mut(),
38            num_stacks: 0,
39            stacks: core::ptr::null_mut(),
40        }
41    }
42}
43
44#[repr(C)]
45/// Drawing queue interruption parameter
46pub struct GeBreakParam {
47    pub buf: [u32; 4],
48}
49
50/// GE matrix types.
51#[repr(i32)]
52pub enum GeMatrixType {
53    /// Bone matrices.
54    Bone0 = 0,
55    Bone1,
56    Bone2,
57    Bone3,
58    Bone4,
59    Bone5,
60    Bone6,
61    Bone7,
62    /// World matrix
63    World,
64    /// View matrix
65    View,
66    /// Projection Matrix
67    Projection,
68    TexGen,
69}
70
71/// List status for `sceGeListSync` and `sceGeDrawSync`.
72#[repr(i32)]
73pub enum GeListState {
74    Done = 0,
75    Queued,
76    DrawingDone,
77    StallReached,
78    CancelDone,
79}
80
81#[repr(u8)]
82#[derive(Copy, Clone, Debug)]
83pub enum GeCommand {
84    Nop = 0,
85    Vaddr = 0x1,
86    Iaddr = 0x2,
87    Prim = 0x4,
88    Bezier = 0x5,
89    Spline = 0x6,
90    BoundingBox = 0x7,
91    Jump = 0x8,
92    BJump = 0x9,
93    Call = 0xa,
94    Ret = 0xb,
95    End = 0xc,
96    Signal = 0xe,
97    Finish = 0xf,
98    Base = 0x10,
99    VertexType = 0x12,
100    OffsetAddr = 0x13,
101    Origin = 0x14,
102    Region1 = 0x15,
103    Region2 = 0x16,
104    LightingEnable = 0x17,
105    LightEnable0 = 0x18,
106    LightEnable1 = 0x19,
107    LightEnable2 = 0x1a,
108    LightEnable3 = 0x1b,
109    DepthClampEnable = 0x1c,
110    CullFaceEnable = 0x1d,
111    TextureMapEnable = 0x1e,
112    FogEnable = 0x1f,
113    DitherEnable = 0x20,
114    AlphaBlendEnable = 0x21,
115    AlphaTestEnable = 0x22,
116    ZTestEnable = 0x23,
117    StencilTestEnable = 0x24,
118    AntiAliasEnable = 0x25,
119    PatchCullEnable = 0x26,
120    ColorTestEnable = 0x27,
121    LogicOpEnable = 0x28,
122    BoneMatrixNumber = 0x2a,
123    BoneMatrixData = 0x2b,
124    MorphWeight0 = 0x2c,
125    MorphWeight1 = 0x2d,
126    MorphWeight2 = 0x2e,
127    MorphWeight3 = 0x2f,
128    MorphWeight4 = 0x30,
129    MorphWeight5 = 0x31,
130    MorphWeight6 = 0x32,
131    MorphWeight7 = 0x33,
132    PatchDivision = 0x36,
133    PatchPrimitive = 0x37,
134    PatchFacing = 0x38,
135    WorldMatrixNumber = 0x3a,
136    WorldMatrixData = 0x3b,
137    ViewMatrixNumber = 0x3c,
138    ViewMatrixData = 0x3d,
139    ProjMatrixNumber = 0x3e,
140    ProjMatrixData = 0x3f,
141    TGenMatrixNumber = 0x40,
142    TGenMatrixData = 0x41,
143    ViewportXScale = 0x42,
144    ViewportYScale = 0x43,
145    ViewportZScale = 0x44,
146    ViewportXCenter = 0x45,
147    ViewportYCenter = 0x46,
148    ViewportZCenter = 0x47,
149    TexScaleU = 0x48,
150    TexScaleV = 0x49,
151    TexOffsetU = 0x4a,
152    TexOffsetV = 0x4b,
153    OffsetX = 0x4c,
154    OffsetY = 0x4d,
155    /// Flat or gouraud.
156    ShadeMode = 0x50,
157    ReverseNormal = 0x51,
158    MaterialUpdate = 0x53,
159    MaterialEmissive = 0x54, // not sure about these but this makes sense
160    MaterialAmbient = 0x55,  // gotta try enabling lighting and check :)
161    MaterialDiffuse = 0x56,
162    MaterialSpecular = 0x57,
163    MaterialAlpha = 0x58,
164    MaterialSpecularCoef = 0x5b,
165    AmbientColor = 0x5c,
166    AmbientAlpha = 0x5d,
167    LightMode = 0x5e,
168    LightType0 = 0x5f,
169    LightType1 = 0x60,
170    LightType2 = 0x61,
171    LightType3 = 0x62,
172    Light0X = 0x63,
173    Light0Y,
174    Light0Z,
175    Light1X,
176    Light1Y,
177    Light1Z,
178    Light2X,
179    Light2Y,
180    Light2Z,
181    Light3X,
182    Light3Y,
183    Light3Z,
184    Light0DirectionX = 0x6f,
185    Light0DirectionY,
186    Light0DirectionZ,
187    Light1DirectionX,
188    Light1DirectionY,
189    Light1DirectionZ,
190    Light2DirectionX,
191    Light2DirectionY,
192    Light2DirectionZ,
193    Light3DirectionX,
194    Light3DirectionY,
195    Light3DirectionZ,
196    Light0ConstantAtten = 0x7b,
197    Light0LinearAtten,
198    Light0QuadtraticAtten,
199    Light1ConstantAtten,
200    Light1LinearAtten,
201    Light1QuadtraticAtten,
202    Light2ConstantAtten,
203    Light2LinearAtten,
204    Light2QuadtraticAtten,
205    Light3ConstantAtten,
206    Light3LinearAtten,
207    Light3QuadtraticAtten,
208    Light0ExponentAtten = 0x87,
209    Light1ExponentAtten,
210    Light2ExponentAtten,
211    Light3ExponentAtten,
212    Light0CutoffAtten = 0x8b,
213    Light1CutoffAtten,
214    Light2CutoffAtten,
215    Light3CutoffAtten,
216    Light0Ambient = 0x8f,
217    Light0Diffuse,
218    Light0Specular,
219    Light1Ambient,
220    Light1Diffuse,
221    Light1Specular,
222    Light2Ambient,
223    Light2Diffuse,
224    Light2Specular,
225    Light3Ambient,
226    Light3Diffuse,
227    Light3Specular,
228    Cull = 0x9b,
229    FrameBufPtr = 0x9c,
230    FrameBufWidth = 0x9d,
231    ZBufPtr = 0x9e,
232    ZBufWidth = 0x9f,
233    TexAddr0 = 0xa0,
234    TexAddr1,
235    TexAddr2,
236    TexAddr3,
237    TexAddr4,
238    TexAddr5,
239    TexAddr6,
240    TexAddr7,
241    TexBufWidth0 = 0xa8,
242    TexBufWidth1,
243    TexBufWidth2,
244    TexBufWidth3,
245    TexBufWidth4,
246    TexBufWidth5,
247    TexBufWidth6,
248    TexBufWidth7,
249    ClutAddr = 0xb0,
250    ClutAddrUpper = 0xb1,
251    TransferSrc,
252    TransferSrcW,
253    TransferDst,
254    TransferDstW,
255    TexSize0 = 0xb8,
256    TexSize1,
257    TexSize2,
258    TexSize3,
259    TexSize4,
260    TexSize5,
261    TexSize6,
262    TexSize7,
263    TexMapMode = 0xc0,
264    TexShadeLs = 0xc1,
265    TexMode = 0xc2,
266    TexFormat = 0xc3,
267    LoadClut = 0xc4,
268    ClutFormat = 0xc5,
269    TexFilter = 0xc6,
270    TexWrap = 0xc7,
271    TexLevel = 0xc8,
272    TexFunc = 0xc9,
273    TexEnvColor = 0xca,
274    TexFlush = 0xcb,
275    TexSync = 0xcc,
276    Fog1 = 0xcd,
277    Fog2 = 0xce,
278    FogColor = 0xcf,
279    TexLodSlope = 0xd0,
280    FramebufPixFormat = 0xd2,
281    ClearMode = 0xd3,
282    Scissor1 = 0xd4,
283    Scissor2 = 0xd5,
284    MinZ = 0xd6,
285    MaxZ = 0xd7,
286    ColorTest = 0xd8,
287    ColorRef = 0xd9,
288    ColorTestmask = 0xda,
289    AlphaTest = 0xdb,
290    StencilTest = 0xdc,
291    StencilOp = 0xdd,
292    ZTest = 0xde,
293    BlendMode = 0xdf,
294    BlendFixedA = 0xe0,
295    BlendFixedB = 0xe1,
296    Dith0 = 0xe2,
297    Dith1,
298    Dith2,
299    Dith3,
300    LogicOp = 0xe6,
301    ZWriteDisable = 0xe7,
302    MaskRgb = 0xe8,
303    MaskAlpha = 0xe9,
304    TransferStart = 0xea,
305    TransferSrcPos = 0xeb,
306    TransferDstPos = 0xec,
307    TransferSize = 0xee,
308
309    /// Vertex Screen/Texture/Color
310    Vscx = 0xf0,
311    Vscy = 0xf1,
312    Vscz = 0xf2,
313    Vtcs = 0xf3,
314    Vtct = 0xf4,
315    Vtcq = 0xf5,
316    Vcv = 0xf6,
317    Vap = 0xf7,
318    Vfc = 0xf8,
319    Vscv = 0xf9,
320
321    Unknown03 = 0x03,
322    Unknown0D = 0x0d,
323    Unknown11 = 0x11,
324    Unknown29 = 0x29,
325    Unknown34 = 0x34,
326    Unknown35 = 0x35,
327    Unknown39 = 0x39,
328    Unknown4E = 0x4e,
329    Unknown4F = 0x4f,
330    Unknown52 = 0x52,
331    Unknown59 = 0x59,
332    Unknown5A = 0x5a,
333    UnknownB6 = 0xb6,
334    UnknownB7 = 0xb7,
335    UnknownD1 = 0xd1,
336    UnknownED = 0xed,
337    UnknownEF = 0xef,
338    UnknownFA = 0xfa,
339    UnknownFB = 0xfb,
340    UnknownFC = 0xfc,
341    UnknownFD = 0xfd,
342    UnknownFE = 0xfe,
343    NopFF = 0xff,
344}
345
346psp_extern! {
347    #![name = "sceGe_user"]
348    #![flags = 0x4001]
349    #![version = (0, 0)]
350
351    #[psp(0x1F6752AD)]
352    /// Get the size of VRAM.
353    ///
354    /// # Return value
355    ///
356    /// The size of VRAM (in bytes).
357    pub fn sceGeEdramGetSize() -> u32;
358
359    #[psp(0xE47E40E4)]
360    /// Get the eDRAM address.
361    ///
362    /// # Return value
363    ///
364    /// A pointer to the base of the eDRAM.
365    pub fn sceGeEdramGetAddr() -> *mut u8;
366
367    #[psp(0xB77905EA)]
368    /// Set the eDRAM address translation mode.
369    ///
370    /// # Parameters
371    ///
372    /// - `width`: 0 to not set the translation width, otherwise 512, 1024, 2048 or 4096.
373    ///
374    /// # Return value
375    ///
376    /// The previous width if it was set, otherwise 0, <0 on error.
377    pub fn sceGeEdramSetAddrTranslation(width: i32) -> i32;
378
379    #[psp(0xDC93CFEF)]
380    /// Retrieve the current value of a GE command.
381    ///
382    /// # Parameters
383    ///
384    /// - `cmd`: The GE command register to retrieve (0 to 0xFF, both included).
385    ///
386    /// # Return value
387    ///
388    /// The value of the GE command, < 0 on error.
389    pub fn sceGeGetCmd(cmd: i32) -> u32;
390
391    #[psp(0x57C8945B)]
392    /// Retrieve a matrix of the given type.
393    ///
394    /// # Parameters
395    ///
396    /// - `type_`: One of MatrixTypes.
397    /// - `matrix`: Pointer to a variable to store the matrix.
398    ///
399    /// # Return value
400    ///
401    /// < 0 on error.
402    pub fn sceGeGetMtx(type_: GeMatrixType, matrix: *mut c_void) -> i32;
403
404    #[psp(0xE66CB92E)]
405    /// Retrieve the stack of the display list currently being executed.
406    ///
407    /// # Parameters
408    ///
409    /// - `stack_id`: The ID of the stack to retrieve.
410    /// - `stack`: Pointer to a structure to store the stack, or NULL to not store it.
411    ///
412    /// # Return value
413    ///
414    /// The number of stacks of the current display list, < 0 on error.
415    pub fn sceGeGetStack(stack_id: i32, stack: *mut GeStack) -> i32;
416
417    #[psp(0x438A385A)]
418    /// Save the GE's current state.
419    ///
420    /// # Parameters
421    ///
422    /// - `context`: Pointer to a GeContext.
423    ///
424    /// # Return value
425    ///
426    /// < 0 on error.
427    pub fn sceGeSaveContext(context: *mut GeContext) -> i32;
428
429    #[psp(0x0BF608FB)]
430    /// Restore a previously saved GE context.
431    ///
432    /// # Parameters
433    ///
434    /// - `context`: Pointer to a GeContext.
435    ///
436    /// # Return value
437    ///
438    /// < 0 on error.
439    pub fn sceGeRestoreContext(context: *const GeContext) -> i32;
440
441    #[psp(0xAB49E76A)]
442    /// Enqueue a display list at the tail of the GE display list queue.
443    ///
444    /// # Parameters
445    ///
446    /// - `list`: The head of the list to queue.
447    /// - `stall`: The stall address. If NULL then no stall address is set and the list is
448    /// transferred  immediately.
449    /// - `cbid`: ID of the callback set by calling sceGeSetCallback
450    /// - `arg`: Structure containing GE context buffer address
451    ///
452    /// # Return value
453    ///
454    /// ID of the queue, < 0 on error.
455    pub fn sceGeListEnQueue(
456       list: *const c_void,
457       stall: *mut c_void,
458       cbid: i32,
459       arg: *mut GeListArgs,
460    ) -> i32;
461
462    #[psp(0x1C0D95A6)]
463    /// Enqueue a display list at the head of the GE display list queue.
464    ///
465    /// # Parameters
466    ///
467    /// - `list`: The head of the list to queue.
468    /// - `stall`: The stall address. If NULL then no stall address is set and
469    ///   the list is transferred  immediately.
470    /// - `cbid`: ID of the callback set by calling sceGeSetCallback
471    /// - `arg`: Structure containing GE context buffer address
472    ///
473    /// # Return value
474    ///
475    /// ID of the queue, < 0 on error.
476    pub fn sceGeListEnQueueHead(list: *const c_void, stall: *mut c_void, cbid: i32, arg: *mut GeListArgs) -> i32;
477
478   #[psp(0x5FB86AB0)]
479    /// Cancel a queued or running list.
480    ///
481    /// # Parameters
482    ///
483    /// - `qid`: The ID of the queue.
484    ///
485    /// # Return value
486    ///
487    /// < 0 on error.
488    pub fn sceGeListDeQueue(qid: i32) -> i32;
489
490    #[psp(0xE0D68148)]
491    /// Update the stall address for the specified queue.
492    ///
493    /// # Parameters
494    ///
495    /// - `qid`: The ID of the queue.
496    /// - `stall`: The new stall address.
497    ///
498    /// # Return value
499    ///
500    /// < 0 on error
501    pub fn sceGeListUpdateStallAddr(qid: i32, stall: *mut c_void) -> i32;
502
503    #[psp(0x03444EB4)]
504    /// Wait for synchronisation of a list.
505    ///
506    /// # Parameters
507    ///
508    /// - `qid`: The queue ID of the list to sync.
509    /// - `sync_type`: 0 if you want to wait for the list to be completed, or 1
510    ///   if you just want to peek the actual state.
511    ///
512    /// # Return value
513    ///
514    /// The specified queue status, one of `GeListState`.
515    pub fn sceGeListSync(qid: i32, sync_type: i32) -> GeListState;
516
517    #[psp(0xB287BD61)]
518    /// Wait for drawing to complete.
519    ///
520    /// # Parameters
521    ///
522    /// - `sync_type`: 0 if you want to wait for the drawing to be completed, or
523    ///   1 if you just want to peek the actual state.
524    ///
525    /// # Return value
526    ///
527    /// The current queue status, one of GeListState.
528    pub fn sceGeDrawSync(sync_type: i32) -> GeListState;
529
530    #[psp(0xB448EC0D)]
531    /// Interrupt drawing queue.
532    ///
533    /// # Parameters
534    ///
535    /// - `mode`: If set to 1, reset all the queues.
536    /// - `p_param`: Unused (just K1-checked).
537    ///
538    /// # Return value
539    ///
540    /// The stopped queue ID if mode isnt set to 0, otherwise 0, and < 0 on error.
541    pub fn sceGeBreak(mode: i32, p_param: *mut GeBreakParam) -> i32;
542
543    #[psp(0x4C06E472)]
544    /// Restart drawing queue.
545    ///
546    /// # Return value
547    ///
548    /// < 0 on error.
549    pub fn sceGeContinue() -> i32;
550
551    #[psp(0xA4FC06A4)]
552    /// Register callback handlers for the GE.
553    ///
554    /// # Parameters
555    ///
556    /// - `cb`: Configured callback data structure.
557    ///
558    /// # Return value
559    ///
560    /// The callback ID, < 0 on error.
561    pub fn sceGeSetCallback(cb: *mut GeCallbackData) -> i32;
562
563    #[psp(0x05DB22CE)]
564    /// Unregister the callback handlers.
565    ///
566    /// # Parameters
567    ///
568    /// - `cbid`: The ID of the callbacks, returned by `sceGeSetCallback()`.
569    ///
570    /// # Return value
571    ///
572    /// < 0 on error.
573    pub fn sceGeUnsetCallback(cbid: i32) -> i32;
574}