# C API: Xbox 360 homebrew module (sona_xsdk.h)

In the `xbox360` download only, inside `libsona.a` for xsdk: the calls a title needs to put avatars on the TV. Include `sona_xsdk.h`. The guide: [Xbox 360 homebrew](../../guides/xbox360.md).

## sona_xsdk_defaults

```c
void sona_xsdk_defaults(sona_xsdk_config *c);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `c` | `sona_xsdk_config *` | The [`sona_xsdk_config`](../fields.md#sona_xsdk_config) to fill with the defaults | required |

**Returns** Nothing.

`size` set; `folder` `"game:/"`, `tv` 1, `max_avatars` 64, `memory_mb` 160, `workers` 5, `log_level` `SONA_LOG_WARN`, a dark blue `clear`.

## sona_xsdk_open

```c
sona_result sona_xsdk_open(const sona_xsdk_config *c, sona_xsdk **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `c` | `const sona_xsdk_config *` | The options, a [`sona_xsdk_config`](../fields.md#sona_xsdk_config) | required |
| `out` | `sona_xsdk **` | Receives the new Xbox 360 title | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_NOT_FOUND` ([what each means](../../troubleshooting.md#error-codes)).

Takes the licence built into the title (`samples/x360/embed-licence.cmake`), else `sona-licence.json` from `folder`, and opens the core with two sources: `folder`'s `360sona/` when there is one, then the gate. Starts the workers on hardware threads 1 to 5, opens xsdk's present at 720p when `tv` is 1 and a display opens, and blocks until the Xenos renderer is ready, at most 60 s. Each failure is written to the title's log. `SONA_E_NOT_FOUND` when the title has no licence built in and there is no `sona-licence.json` in `folder`.

## sona_xsdk_add_player

```c
sona_result sona_xsdk_add_player(sona_xsdk *sx, uint32_t user_index, const sona_add_options *opts,
                                   sona_avatar **out);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `sx` | `sona_xsdk *` | The Xbox 360 title | required |
| `user_index` | `uint32_t` | The signed-in user, 0 to 3, one per controller | - |
| `opts` | `const sona_add_options *` | The options, a [`sona_add_options`](../fields.md#sona_add_options) | `NULL`: the defaults |
| `out` | `sona_avatar **` | Receives the new avatar | required |

**Returns** `SONA_OK`. **Errors** `SONA_E_ARGUMENT` ([what each means](../../troubleshooting.md#error-codes)).

The signed-in player in their own avatar, in the middle of the stage facing the camera. It tries the profile on this console first, then 360sona's lookup by the profile's gamertag, then the gamertag in `sona-player.txt` in `folder`. The neutral figure stands there until one answers, and `*out` keeps the same handle when it does. `opts` NULL: the defaults, idling. `SONA_E_ARGUMENT` for a fifth player or a `user_index` past 3.

## sona_xsdk_view

```c
void sona_xsdk_view(const sona_xsdk *sx, sona_view *view);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `sx` | `const sona_xsdk *` | The Xbox 360 title | required |
| `view` | `sona_view *` | Receives the camera, a [`sona_view`](../fields.md#sona_view) | required |

**Returns** Nothing.

The stage at 1280 by 720: 40 degrees, from 1.35 m up and 5.2 m back. `sona_camera_preset` frames one avatar instead.

## sona_xsdk_frame

```c
int sona_xsdk_frame(sona_xsdk *sx, const sona_view *view);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `sx` | `sona_xsdk *` | The Xbox 360 title | required |
| `view` | `const sona_view *` | The camera, a [`sona_view`](../fields.md#sona_view) | required |

**Returns** `int`.

Returns 1 while the title should go on, and 0 for BACK on the first controller or when the display is gone. Reads the first controller (nothing while the Guide is open) and takes the players' lookups. Calls `sona_update` with the time since the last frame, draws `view` and presents it on vblank. Off screen it draws into a target of its own. It never takes the context's events: `sona_poll_event` on `sona_xsdk_ctx(sx)` still gives them.

## sona_xsdk_dt

```c
double sona_xsdk_dt(const sona_xsdk *sx);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `sx` | `const sona_xsdk *` | The Xbox 360 title | required |

**Returns** `double`.

The seconds between the last two frames, for moving things.

## sona_xsdk_time

```c
double sona_xsdk_time(const sona_xsdk *sx);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `sx` | `const sona_xsdk *` | The Xbox 360 title | required |

**Returns** `double`.

The seconds since `sona_xsdk_open`.

## sona_xsdk_held

```c
uint16_t sona_xsdk_held(const sona_xsdk *sx);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `sx` | `const sona_xsdk *` | The Xbox 360 title | required |

**Returns** `uint16_t`.

The first controller's buttons held at the last frame, as `INPUT_GAMEPAD_*` bits.

## sona_xsdk_pressed

```c
uint16_t sona_xsdk_pressed(const sona_xsdk *sx);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `sx` | `const sona_xsdk *` | The Xbox 360 title | required |

**Returns** `uint16_t`.

The buttons pressed since the frame before, as `INPUT_GAMEPAD_*` bits.

## sona_xsdk_stick

```c
void sona_xsdk_stick(const sona_xsdk *sx, float *x, float *y);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `sx` | `const sona_xsdk *` | The Xbox 360 title | required |
| `x` | `float *` | Receives the stick across, -1 left to 1 right; may be NULL | `NULL` allowed (below) |
| `y` | `float *` | Receives the stick up and down, -1 down to 1 up; may be NULL | `NULL` allowed (below) |

**Returns** Nothing.

The first controller's left stick at the last frame, each axis -1 to 1 with up as +y, and 0 inside the usual dead
zone (7,849 of 32,767). `x` and `y` may be NULL.

## sona_xsdk_on_tv

```c
int sona_xsdk_on_tv(const sona_xsdk *sx);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `sx` | `const sona_xsdk *` | The Xbox 360 title | required |

**Returns** `int`.

1 when frames go to the TV; 0 when they are drawn off screen (no display, as in Xenia, or `tv` 0).

## sona_xsdk_settled

```c
int sona_xsdk_settled(const sona_xsdk *sx);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `sx` | `const sona_xsdk *` | The Xbox 360 title | required |

**Returns** `int`.

1 when every player's avatar is known and nothing is still loading.

## sona_xsdk_snapshot

```c
sona_result sona_xsdk_snapshot(sona_xsdk *sx, const sona_view *view, const char *name);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `sx` | `sona_xsdk *` | The Xbox 360 title | required |
| `view` | `const sona_view *` | The camera, a [`sona_view`](../fields.md#sona_view) | required |
| `name` | `const char *` | The file's name, ending `.png` or `.ppm` | required |

**Returns** `SONA_OK`.

Draws `view` once more, reads it back and writes it to `folder`, or to `cache:\` where `folder` is read-only (Xenia).

## sona_xsdk_ctx

```c
sona_ctx *sona_xsdk_ctx(sona_xsdk *sx);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `sx` | `sona_xsdk *` | The Xbox 360 title | required |

**Returns** `sona_ctx *`.

The context, for every other call of `sona.h`.

## sona_xsdk_renderer

```c
sona_renderer *sona_xsdk_renderer(sona_xsdk *sx);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `sx` | `sona_xsdk *` | The Xbox 360 title | required |

**Returns** `sona_renderer *`.

The Xenos renderer, for `sona_draw` and `sona_snapshot` of your own.

## sona_xsdk_close

```c
void sona_xsdk_close(sona_xsdk *sx);
```

| Parameter | Type | Meaning | Default |
|---|---|---|---|
| `sx` | `sona_xsdk *` | The Xbox 360 title | required |

**Returns** Nothing.

Closes the lookups, the renderer, the context and the display. The worker threads stay for a later `sona_xsdk_open`.
