gfxd_sys/
settings.rs

1/* SPDX-FileCopyrightText: © 2025 Decompollaborate */
2/* SPDX-License-Identifier: MIT */
3
4//! These functions control general input and output settings.
5
6use crate::ffi;
7
8use crate::ptr::{NonNullConst, NonNullMut, Opaque};
9
10extern "C" {
11    /// Select `ucode` as the target microcode.
12    ///
13    /// `ucode` can be `gfxd_f3d`, `gfxd_f3db`, `gfxd_f3dex`, `gfxd_f3dexb`, or
14    /// `gfxd_f3dex2`.
15    ///
16    /// The microcode must be selected before `gfxd_execute`, as no microcode
17    /// is selected by default.
18    pub fn gfxd_target(ucode: Option<gfxd_ucode_t>);
19
20    /// Select `endian` as the endianness of the input, and `wordsize` as the
21    /// size of each word in number of bytes.
22    ///
23    /// `endian` can be [`gfxd_endian_big`], [`gfxd_endian_little`], or
24    /// [`gfxd_endian_host`] (the endianness of the host machine).
25    ///
26    /// `wordsize` can be 1, 2, 4, or 8. Big endian is selected by default,
27    /// with a word size of 4.
28    pub fn gfxd_endian(endian: Endian, wordsize: ffi::c_int);
29
30    /// Enable or disable the use of dynamic `g` macros instead of static `gs`
31    /// macros, and select the dynamic display list pointer argument to be
32    /// used.
33    ///
34    /// `arg` will be used by `gfxd_macro_dflt` as the first argument to
35    /// dynamic macros.
36    ///
37    /// If `arg` is `null`, dynamic macros are disabled, and `gs` macros are
38    /// used.
39    ///
40    /// Also affects the result of `gfxd_macro_name`, as it will return either
41    /// the dynamic or static version of the macro name as selected by this
42    /// setting.
43    pub fn gfxd_dynamic(arg: Option<NonNullConst<ffi::c_char>>);
44
45    /// Enable or disable the feature specified by `cap`.
46    ///
47    /// Can be one of the following;
48    /// - [`gfxd_stop_on_invalid`]: Stop execution when encountering an invalid
49    ///   macro.
50    ///
51    ///   Enabled by default.
52    ///
53    /// - [`gfxd_stop_on_end`]: Stop execution when encountering a `SPBranchList`
54    ///   or `SPEndDisplayList`.
55    ///
56    ///   Enabled by default.
57    ///
58    /// - [`gfxd_emit_dec_color`]: Print color components as decimal instead of
59    ///   hexadecimal.
60    ///
61    ///   Disabled by default.
62    ///
63    /// - [`gfxd_emit_q_macro`]: Print fixed-point conversion `q` macros for
64    ///   fixed-point values.
65    ///
66    ///   Disabled by default.
67    ///
68    /// - [`gfxd_emit_ext_macro`]: Emit non-standard macros.
69    ///
70    ///   Some commands are valid (though possibly meaningless), but have no
71    ///   macros associated with them, such as a standalone `G_RDPHALF_1`. When
72    ///   this feature is enabled, such a command will produce a non-standard
73    ///   `gsDPHalf1` macro instead of a raw hexadecimal command.
74    ///
75    ///   Also enables some non-standard multi-packet texture loading macros.
76    ///
77    ///   Disabled by default.
78    pub fn gfxd_enable(cap: FeatureOption);
79
80    /// Enable or disable the feature specified by `cap`.
81    ///
82    /// See [`gfxd_enable`] for possible values.
83    pub fn gfxd_disable(cap: FeatureOption);
84
85    /// Set or get a generic pointer that can be used to pass user-defined data
86    /// in and out of callback functions.
87    pub fn gfxd_udata_set(ptr: Option<NonNullMut<ffi::c_void>>);
88
89    /// Set or get a generic pointer that can be used to pass user-defined data
90    /// in and out of callback functions.
91    pub fn gfxd_udata_get() -> Option<NonNullMut<ffi::c_void>>;
92}
93
94#[repr(C)]
95pub struct gfxd_ucode {
96    _data: Opaque,
97}
98pub type gfxd_ucode_t = NonNullConst<gfxd_ucode>;
99
100extern "C" {
101    pub static gfxd_f3d: gfxd_ucode_t;
102    pub static gfxd_f3db: gfxd_ucode_t;
103    pub static gfxd_f3dex: gfxd_ucode_t;
104    pub static gfxd_f3dexb: gfxd_ucode_t;
105    pub static gfxd_f3dex2: gfxd_ucode_t;
106}
107
108pub const gfxd_endian_big: Endian = Endian::gfxd_endian_big;
109pub const gfxd_endian_little: Endian = Endian::gfxd_endian_little;
110pub const gfxd_endian_host: Endian = Endian::gfxd_endian_host;
111#[repr(u32)]
112#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
113pub enum Endian {
114    gfxd_endian_big = 0,
115    gfxd_endian_little = 1,
116    gfxd_endian_host = 2,
117}
118
119/// Stop execution when encountering an invalid macro.
120///
121/// Enabled by default.
122pub const gfxd_stop_on_invalid: FeatureOption = FeatureOption::gfxd_stop_on_invalid;
123
124/// Stop execution when encountering a `SPBranchList` or
125/// `SPEndDisplayList`.
126///
127/// Enabled by default.
128pub const gfxd_stop_on_end: FeatureOption = FeatureOption::gfxd_stop_on_end;
129
130/// Print color components as decimal instead of hexadecimal.
131///
132/// Disabled by default.
133pub const gfxd_emit_dec_color: FeatureOption = FeatureOption::gfxd_emit_dec_color;
134
135/// Print fixed-point conversion `q` macros for fixed-point values.
136///
137/// Disabled by default.
138pub const gfxd_emit_q_macro: FeatureOption = FeatureOption::gfxd_emit_q_macro;
139
140/// Emit non-standard macros.
141///
142/// Some commands are valid (though possibly meaningless), but have no
143/// macros associated with them, such as a standalone `G_RDPHALF_1`. When
144/// this feature is enabled, such a command will produce a non-standard
145/// `gsDPHalf1` macro instead of a raw hexadecimal command.
146///
147/// Also enables some non-standard multi-packet texture loading macros.
148///
149/// Disabled by default.
150pub const gfxd_emit_ext_macro: FeatureOption = FeatureOption::gfxd_emit_ext_macro;
151
152#[repr(u32)]
153#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
154pub enum FeatureOption {
155    /// Stop execution when encountering an invalid macro.
156    ///
157    /// Enabled by default.
158    gfxd_stop_on_invalid = 0,
159
160    /// Stop execution when encountering a `SPBranchList` or
161    /// `SPEndDisplayList`.
162    ///
163    /// Enabled by default.
164    gfxd_stop_on_end = 1,
165
166    /// Print color components as decimal instead of hexadecimal.
167    ///
168    /// Disabled by default.
169    gfxd_emit_dec_color = 2,
170
171    /// Print fixed-point conversion `q` macros for fixed-point values.
172    ///
173    /// Disabled by default.
174    gfxd_emit_q_macro = 3,
175
176    /// Emit non-standard macros.
177    ///
178    /// Some commands are valid (though possibly meaningless), but have no
179    /// macros associated with them, such as a standalone `G_RDPHALF_1`. When
180    /// this feature is enabled, such a command will produce a non-standard
181    /// `gsDPHalf1` macro instead of a raw hexadecimal command.
182    ///
183    /// Also enables some non-standard multi-packet texture loading macros.
184    ///
185    /// Disabled by default.
186    gfxd_emit_ext_macro = 4,
187}