diff --git a/build.zig b/build.zig index 3626a49..66f9714 100644 --- a/build.zig +++ b/build.zig @@ -28,7 +28,7 @@ pub fn build(b: *Builder) void { //All of the release modes work //Debug Mode can cause issues with trap instructions - use ReleaseSafe for "Debug" builds - const mode = builtin.Mode.ReleaseFast; + const mode = builtin.Mode.ReleaseSmall; const lib = b.addStaticLibrary("zpsp", "src/psp/libzpsp.zig"); lib.setTarget(target); @@ -46,6 +46,8 @@ pub fn build(b: *Builder) void { exe.setLinkerScriptPath("tools/linkfile.ld"); exe.link_eh_frame_hdr = true; exe.link_emit_relocs = true; + exe.strip = true; + exe.single_threaded = true; exe.step.dependOn(&lib.step); //Post-build actions diff --git a/src/main.zig b/src/main.zig new file mode 100644 index 0000000..5e2e5fd --- /dev/null +++ b/src/main.zig @@ -0,0 +1,11 @@ +const psp = @import("psp/pspsdk.zig"); + +comptime{ + asm(psp.module_info("Zig PSP", 0, 1, 0)); +} + +pub fn main() !void { + psp.utils.enableHBCB(); + psp.debug.screenInit(); + psp.debug.print("Hi!"); +} diff --git a/src/psp/include/pspdmac.zig b/src/psp/include/pspdmac.zig new file mode 100644 index 0000000..f0d77ab --- /dev/null +++ b/src/psp/include/pspdmac.zig @@ -0,0 +1,2 @@ +pub usingnamespace @import("../nids/pspdmac.zig"); +pub usingnamespace @import("../sdk/pspdmac.zig"); diff --git a/src/psp/include/pspimpose.zig b/src/psp/include/pspimpose.zig deleted file mode 100644 index 28b6117..0000000 --- a/src/psp/include/pspimpose.zig +++ /dev/null @@ -1,2 +0,0 @@ -pub usingnamespace @import("../nids/pspimpose.zig"); -pub usingnamespace @import("../sdk/pspimpose.zig"); diff --git a/src/psp/libzpsp.zig b/src/psp/libzpsp.zig index c25396d..86efdba 100644 --- a/src/psp/libzpsp.zig +++ b/src/psp/libzpsp.zig @@ -5,10 +5,10 @@ pub usingnamespace @import("nids/pspaudio.zig"); pub usingnamespace @import("nids/pspaudiocodec.zig"); pub usingnamespace @import("nids/pspctrl.zig"); pub usingnamespace @import("nids/pspdisplay.zig"); +pub usingnamespace @import("nids/pspdmac.zig"); pub usingnamespace @import("nids/pspge.zig"); pub usingnamespace @import("nids/psphprm.zig"); pub usingnamespace @import("nids/psphttp.zig"); -pub usingnamespace @import("nids/pspimpose.zig"); pub usingnamespace @import("nids/pspiofilemgr.zig"); pub usingnamespace @import("nids/pspjpeg.zig"); pub usingnamespace @import("nids/psploadexec.zig"); diff --git a/src/psp/nids/pspdmac.zig b/src/psp/nids/pspdmac.zig new file mode 100644 index 0000000..26cbe4d --- /dev/null +++ b/src/psp/nids/pspdmac.zig @@ -0,0 +1,7 @@ +const macro = @import("pspmacros.zig"); + +comptime{ + asm(macro.import_module_start("sceDmac", "0x40010011", "2")); + asm(macro.import_function("sceDmac", "0x617F3FE6", "sceDmacMemcpy")); + asm(macro.import_function("sceDmac", "0xD97F94D8", "sceDmacTryMemcpy")); +} diff --git a/src/psp/nids/pspimpose.zig b/src/psp/nids/pspimpose.zig deleted file mode 100644 index d9d8edf..0000000 --- a/src/psp/nids/pspimpose.zig +++ /dev/null @@ -1,17 +0,0 @@ -const macro = @import("pspmacros.zig"); - -comptime{ - asm(macro.import_module_start("sceImpose", "0x40010011", "15")); - asm(macro.import_function("sceImpose", "0x0F341BE4", "sceImposeGetHomePopup")); - asm(macro.import_function("sceImpose", "0x24FD7BCF", "sceImposeGetLanguageMode")); - asm(macro.import_function("sceImpose", "0x36AA6E91", "sceImposeSetLanguageMode")); - asm(macro.import_function("sceImpose", "0x381BD9E7", "sceImposeHomeButton")); - asm(macro.import_function("sceImpose", "0x5595A71A", "sceImposeSetHomePopup")); - asm(macro.import_function("sceImpose", "0x72189C48", "sceImposeSetUMDPopup")); - asm(macro.import_function("sceImpose", "0x8C943191", "sceImposeBatteryIconStatus")); - asm(macro.import_function("sceImpose", "0x8F6E3518", "sceImposeGetBacklightOffTime")); - asm(macro.import_function("sceImpose", "0x967F6D4A", "sceImposeSetBacklightOffTime")); - asm(macro.import_function("sceImpose", "0x9BA61B49", "sceImpose_9BA61B49")); - asm(macro.import_function("sceImpose", "0xBB3F5DEC", "sceImpose_BB3F5DEC")); - asm(macro.import_function("sceImpose", "0xE0887BC8", "sceImposeGetUMDPopup")); -} diff --git a/src/psp/pspsdk.zig b/src/psp/pspsdk.zig index dba7a08..4dc9981 100644 --- a/src/psp/pspsdk.zig +++ b/src/psp/pspsdk.zig @@ -12,12 +12,12 @@ pub usingnamespace @import("sdk/pspaudio.zig"); pub usingnamespace @import("sdk/pspaudiocodec.zig"); pub usingnamespace @import("sdk/pspctrl.zig"); pub usingnamespace @import("sdk/pspdisplay.zig"); +pub usingnamespace @import("sdk/pspdmac.zig"); pub usingnamespace @import("sdk/pspge.zig"); pub usingnamespace @import("sdk/pspgu.zig"); pub usingnamespace @import("sdk/pspgum.zig"); pub usingnamespace @import("sdk/psphprm.zig"); pub usingnamespace @import("sdk/psphttp.zig"); -pub usingnamespace @import("sdk/pspimpose.zig"); pub usingnamespace @import("sdk/pspiofilemgr.zig"); pub usingnamespace @import("sdk/pspjpeg.zig"); pub usingnamespace @import("sdk/psploadexec.zig"); diff --git a/src/psp/sdk/pspatrac3.zig b/src/psp/sdk/pspatrac3.zig index 1512df8..730d461 100644 --- a/src/psp/sdk/pspatrac3.zig +++ b/src/psp/sdk/pspatrac3.zig @@ -1,6 +1,64 @@ usingnamespace @import("psptypes.zig"); +test "" { @import("std").meta.refAllDecls(@This()); } -const struct_unnamed_5 = extern struct { +pub const AtracError = enum(u32){ + ParamFail = (0x80630001), + ApiFail = (0x80630002), + NoAtracid = (0x80630003), + BadCodectype = (0x80630004), + BadAtracid = (0x80630005), + UnknownFormat = (0x80630006), + UnmatchFormat = (0x80630007), + BadData = (0x80630008), + AlldataIsOnmemory = (0x80630009), + UnsetData = (0x80630010), + ReadsizeIsTooSmall = (0x80630011), + NeedSecondBuffer = (0x80630012), + ReadsizeOverBuffer = (0x80630013), + Not4byteAlignment = (0x80630014), + BadSample = (0x80630015), + WritebyteFirstBuffer = (0x80630016), + WritebyteSecondBuffer = (0x80630017), + AddDataIsTooBig = (0x80630018), + UnsetParam = (0x80630021), + NoneedSecondBuffer = (0x80630022), + NodataInBuffer = (0x80630023), + AlldataWasDecoded = (0x80630024), +}; + +fn intToError(res: c_int) !void{ + @setRuntimeSafety(false); + if(res < 0){ + var translated = @bitCast(u32, res); + switch(@intToEnum(AtracError, res)){ + ParamFail => {return error.ParamFail;}, + ApiFail => {return error.ApiFail;}, + NoAtracid => {return error.NoAtracid;}, + BadCodectype => {return error.BadCodectype;}, + BadAtracid => {return error.BadAtracid;}, + UnknownFormat => {return error.UnknownFormat;}, + UnmatchFormat => {return error.UnmatchFormat;}, + BadData => {return error.BadData;}, + AlldataIsOnmemory => {return error.AlldataIsOnmemory;}, + UnsetData => {return error.UnsetData;}, + ReadSizeIsTooSmall => {return error.ReadSizeIsTooSmall;}, + NeedSecondBuffer => {return error.NeedSecondBuffer;}, + ReadSizeOverBuffer => {return error.ReadSizeOverBuffer;}, + Not4byteAlignment => {return error.Not4byteAlignment;}, + BadSample => {return error.BadSample;}, + WriteByteFirstBuffer => {return error.WriteByteFirstBuffer;}, + WriteByteSecondBuffer => {return error.WriteByteSecondBuffer;}, + AddDataIsTooBig => {return error.AddDataIsTooBig;}, + UnsetParam => {return error.UnsetParam;}, + NoNeedSecondBuffer => {return error.NoNeedSecondBuffer;}, + NoDataInBuffer => {return error.NoDataInBuffer;}, + AllDataWasDecoded => {return error.AllDataWasDecoded;}, + } + } +} + +//Buffer information +pub const PspBufferInfo = extern struct { pucWritePositionFirstBuf: [*c]u8, uiWritableByteFirstBuf: u32, uiMinWriteByteFirstBuf: u32, @@ -10,17 +68,154 @@ const struct_unnamed_5 = extern struct { uiMinWriteByteSecondBuf: u32, uiReadPositionSecondBuf: u32, }; -pub const PspBufferInfo = struct_unnamed_5; + pub extern fn sceAtracGetAtracID(uiCodecType: u32) c_int; + +// Codec ID Enumeration +pub const AtracCodecType = enum(u32){ + At3Plus = 0x1000, + At3 = 0x1001, +}; + +// Gets the ID for a certain codec. +// Can return error for invalid ID. +pub fn atracGetAtracID(uiCodecType: AtracCodecType) !i32 { + var res = sceAtracGetAtracID(@enumToInt(uiCodecType)); + try intToError(res); + return res; +} + +// Creates a new Atrac ID from the specified data +// +// @param buf - the buffer holding the atrac3 data, including the RIFF/WAVE header. +// @param bufsize - the size of the buffer pointed by buf +// +// @return the new atrac ID, or < 0 on error pub extern fn sceAtracSetDataAndGetID(buf: ?*c_void, bufsize: SceSize) c_int; -pub extern fn sceAtracDecodeData(atracID: c_int, outSamples: [*c]u16, outN: [*c]c_int, outEnd: [*c]c_int, outRemainFrame: [*c]c_int) c_int; -pub extern fn sceAtracGetRemainFrame(atracID: c_int, outRemainFrame: [*c]c_int) c_int; -pub extern fn sceAtracGetStreamDataInfo(atracID: c_int, writePointer: [*c][*c]u8, availableBytes: [*c]u32, readOffset: [*c]u32) c_int; -pub extern fn sceAtracAddStreamData(atracID: c_int, bytesToAdd: c_uint) c_int; -pub extern fn sceAtracGetBitrate(atracID: c_int, outBitrate: [*c]c_int) c_int; -pub extern fn sceAtracSetLoopNum(atracID: c_int, nloops: c_int) c_int; -pub extern fn sceAtracReleaseAtracID(atracID: c_int) c_int; -pub extern fn sceAtracGetNextSample(atracID: c_int, outN: [*c]c_int) c_int; + +pub fn atracSetDataAndGetID(buf: *c_void, bufSize: usize) !u32 { + var res = sceAtracSetDataAndGetID(buf, bufSize); + try intToError(res); + return res; +} + + +// Decode a frame of data. +// +// @param atracID - the atrac ID +// @param outSamples - pointer to a buffer that receives the decoded data of the current frame +// @param outN - pointer to a integer that receives the number of audio samples of the decoded frame +// @param outEnd - pointer to a integer that receives a boolean value indicating if the decoded frame is the last one +// @param outRemainFrame - pointer to a integer that receives either -1 if all at3 data is already on memory, +// or the remaining (not decoded yet) frames at memory if not all at3 data is on memory +// +// +// @return < 0 on error, otherwise 0 +pub extern fn sceAtracDecodeData(atracID: u32, outSamples: [*c]u16, outN: [*c]c_int, outEnd: [*c]c_int, outRemainFrame: [*c]c_int) c_int; + +pub fn atracDecodeData(atracID: u32, outSamples: []u16, outN: []i32, outEnd: []i32, outRemainFrame: []i32) !void { + var res = sceAtracDecodeData(atracID, outSamples, outN, outEnd, outRemainFrame); + try intToError(res); +} + + +// Gets the remaining (not decoded) number of frames +// +// @param atracID - the atrac ID +// @param outRemainFrame - pointer to a integer that receives either -1 if all at3 data is already on memory, +// or the remaining (not decoded yet) frames at memory if not all at3 data is on memory +// +// @return < 0 on error, otherwise 0 +pub extern fn sceAtracGetRemainFrame(atracID: u32, outRemainFrame: [*c]c_int) c_int; + +pub fn atracGetRemainFrame(atracID: u32, outRemainFrame: []i32) !void { + var res = sceAtracDecodeData(atracID, outSamples, outN, outEnd, outRemainFrame); + try intToError(res); +} + +// Gets the info of stream data +// @param atracID - the atrac ID +// @param writePointer - Pointer to where to read the atrac data +// @param availableBytes - Number of bytes available at the writePointer location +// @param readOffset - Offset where to seek into the atrac file before reading +// +// @return < 0 on error, otherwise 0 +pub extern fn sceAtracGetStreamDataInfo(atracID: u32, writePointer: [*c][*c]u8, availableBytes: [*c]u32, readOffset: [*c]u32) c_int; + +pub fn atracGetStreamDataInfo(atracID: u32, writePointer: [*c][*c]u8, availableBytes: [*c]u32, readOffset: [*c]u32) !void{ + var res = sceAtracGetStreamDataInfo(atracID, writePointer, availableBytes, readOffset); + try intToError(res); +} + +// Adds to stream data +// @param atracID - the atrac ID +// @param bytesToAdd - Number of bytes read into location given by sceAtracGetStreamDataInfo(). +// +// @return < 0 on error, otherwise 0 +pub extern fn sceAtracAddStreamData(atracID: u32, bytesToAdd: c_uint) c_int; + +pub fn atracAddStreamData(atracID: u32, bytesToAdd: u32) !void { + var res = sceAtracAddStreamData(atracID, bytesToAdd); + try intToError(res); +} + + +// Gets the bitrate. +// +// @param atracID - the atracID +// @param outBitrate - pointer to a integer that receives the bitrate in kbps +// +// @return < 0 on error, otherwise 0 +pub extern fn sceAtracGetBitrate(atracID: u32, outBitrate: [*c]c_int) c_int; + +pub fn atracGetBitrate(atracID: u32, outBitrate: [*c]c_int) !void { + var res = sceAtracGetBitrate(atracID, outBitrate); + try intToError(res); +} + + +// Sets the number of loops for this atrac ID +// +// @param atracID - the atracID +// @param nloops - the number of loops to set +// +// @return < 0 on error, otherwise 0 +pub extern fn sceAtracSetLoopNum(atracID: u32, nloops: c_int) c_int; + +pub fn atracSetLoopNum(atracID: u32, nloops: c_int) !void { + var res = atracSetLoopNum(atracID, nloops); + try intToError(res); +} + + +// Releases an atrac ID +// +// @param atracID - the atrac ID to release +// +// @return < 0 on error +pub extern fn sceAtracReleaseAtracID(atracID: u32) c_int; + +pub fn atracReleaseAtracID(atracID: u32) !i32 { + var res = sceAtracReleaseAtracID(atracID); + try intToError(res); + return res; +} + + +//Gets the number of samples of the next frame to be decoded. +// +//@param atracID - the atrac ID +//@param outN - pointer to receives the number of samples of the next frame. +// +//@return < 0 on error, otherwise 0 +pub extern fn sceAtracGetNextSample(atracID: u32, outN: [*c]c_int) c_int; + +pub fn atracGetNextSample(atracID: u32, outN: [*c]c_int) !void { + var res = sceAtracGetNextSample(atracID, outN); + try intToError(res); +} + +//These are undocumented - thus I cannot wrap them pub extern fn sceAtracGetMaxSample(atracID: c_int, outMax: [*c]c_int) c_int; pub extern fn sceAtracGetBufferInfoForReseting(atracID: c_int, uiSample: u32, pBufferInfo: [*c]PspBufferInfo) c_int; pub extern fn sceAtracGetChannel(atracID: c_int, puiChannel: [*c]u32) c_int; diff --git a/src/psp/sdk/pspaudio.zig b/src/psp/sdk/pspaudio.zig index 6008f7a..0b59629 100644 --- a/src/psp/sdk/pspaudio.zig +++ b/src/psp/sdk/pspaudio.zig @@ -1,9 +1,9 @@ -pub const enum_PspAudioFormats = extern enum(c_int) { - PSP_AUDIO_FORMAT_STEREO = 0, - PSP_AUDIO_FORMAT_MONO = 16, +pub const PspAudioFormats = extern enum(c_int) { + Stereo = 0, + Mono = 16, _, }; -const struct_unnamed_1 = extern struct { +pub const PspAudioInputParams = extern struct { unknown1: c_int, gain: c_int, unknown2: c_int, @@ -11,31 +11,226 @@ const struct_unnamed_1 = extern struct { unknown4: c_int, unknown5: c_int, }; -pub const PspAudioFormats = enum_PspAudioFormats; -pub const pspAudioInputParams = struct_unnamed_1; + +// Allocate and initialize a hardware output channel. +// +// @param channel - Use a value between 0 - 7 to reserve a specific channel. +// Pass PSP_AUDIO_NEXT_CHANNEL to get the first available channel. +// @param samplecount - The number of samples that can be output on the channel per +// output call. It must be a value between ::PSP_AUDIO_SAMPLE_MIN +// and ::PSP_AUDIO_SAMPLE_MAX, and it must be aligned to 64 bytes +// (use the ::PSP_AUDIO_SAMPLE_ALIGN macro to align it). +// @param format - The output format to use for the channel. One of ::PspAudioFormats. +// +// @return The channel number on success, an error code if less than 0. pub extern fn sceAudioChReserve(channel: c_int, samplecount: c_int, format: c_int) c_int; + +// Release a hardware output channel. +// +// @param channel - The channel to release. +// +// @return 0 on success, an error if less than 0. pub extern fn sceAudioChRelease(channel: c_int) c_int; + +// Output audio of the specified channel +// +// @param channel - The channel number. +// +// @param vol - The volume. +// +// @param buf - Pointer to the PCM data to output. +// +// @return 0 on success, an error if less than 0. pub extern fn sceAudioOutput(channel: c_int, vol: c_int, buf: ?*c_void) c_int; + +// Output audio of the specified channel (blocking) +// +// @param channel - The channel number. +// +// @param vol - The volume. +// +// @param buf - Pointer to the PCM data to output. +// +// @return 0 on success, an error if less than 0. pub extern fn sceAudioOutputBlocking(channel: c_int, vol: c_int, buf: ?*c_void) c_int; + +// Output panned audio of the specified channel +// +// @param channel - The channel number. +// +// @param leftvol - The left volume. +// +// @param rightvol - The right volume. +// +// @param buf - Pointer to the PCM data to output. +// +// @return 0 on success, an error if less than 0. pub extern fn sceAudioOutputPanned(channel: c_int, leftvol: c_int, rightvol: c_int, buf: ?*c_void) c_int; + +// Output panned audio of the specified channel (blocking) +// +// @param channel - The channel number. +// +// @param leftvol - The left volume. +// +// @param rightvol - The right volume. +// +// @param buf - Pointer to the PCM data to output. +// +// @return 0 on success, an error if less than 0. pub extern fn sceAudioOutputPannedBlocking(channel: c_int, leftvol: c_int, rightvol: c_int, buf: ?*c_void) c_int; + +// Get count of unplayed samples remaining +// +// @param channel - The channel number. +// +// @return Number of samples to be played, an error if less than 0. pub extern fn sceAudioGetChannelRestLen(channel: c_int) c_int; + +// Get count of unplayed samples remaining +// +// @param channel - The channel number. +// +// @return Number of samples to be played, an error if less than 0. pub extern fn sceAudioGetChannelRestLength(channel: c_int) c_int; + +// Change the output sample count, after it's already been reserved +// +// @param channel - The channel number. +// @param samplecount - The number of samples to output in one output call. +// +// @return 0 on success, an error if less than 0. pub extern fn sceAudioSetChannelDataLen(channel: c_int, samplecount: c_int) c_int; + +// Change the format of a channel +// +// @param channel - The channel number. +// +// @param format - One of ::PspAudioFormats +// +// @return 0 on success, an error if less than 0. pub extern fn sceAudioChangeChannelConfig(channel: c_int, format: c_int) c_int; + +// Change the volume of a channel +// +// @param channel - The channel number. +// +// @param leftvol - The left volume. +// +// @param rightvol - The right volume. +// +// @return 0 on success, an error if less than 0. pub extern fn sceAudioChangeChannelVolume(channel: c_int, leftvol: c_int, rightvol: c_int) c_int; + +// Reserve the audio output and set the output sample count +// +// @param samplecount - The number of samples to output in one output call (min 17, max 4111). +// +// @return 0 on success, an error if less than 0. pub extern fn sceAudioOutput2Reserve(samplecount: c_int) c_int; + +// Release the audio output +// +// @return 0 on success, an error if less than 0. pub extern fn sceAudioOutput2Release() c_int; + +// Change the output sample count, after it's already been reserved +// +// @param samplecount - The number of samples to output in one output call (min 17, max 4111). +// +// @return 0 on success, an error if less than 0. pub extern fn sceAudioOutput2ChangeLength(samplecount: c_int) c_int; + +// Output audio (blocking) +// +// @param vol - The volume. +// +// @param buf - Pointer to the PCM data. +// +// @return 0 on success, an error if less than 0. pub extern fn sceAudioOutput2OutputBlocking(vol: c_int, buf: ?*c_void) c_int; + +// Get count of unplayed samples remaining +// +// @return Number of samples to be played, an error if less than 0. pub extern fn sceAudioOutput2GetRestSample() c_int; + +// Reserve the audio output +// +// @param samplecount - The number of samples to output in one output call (min 17, max 4111). +// +// @param freq - The frequency. One of 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11050, 8000. +// +// @param channels - Number of channels. Pass 2 (stereo). +// +// @return 0 on success, an error if less than 0. pub extern fn sceAudioSRCChReserve(samplecount: c_int, freq: c_int, channels: c_int) c_int; + +// Release the audio output +// +// @return 0 on success, an error if less than 0. pub extern fn sceAudioSRCChRelease() c_int; + +// Output audio +// +// @param vol - The volume. +// +// @param buf - Pointer to the PCM data to output. +// +// @return 0 on success, an error if less than 0. pub extern fn sceAudioSRCOutputBlocking(vol: c_int, buf: ?*c_void) c_int; + +// Init audio input +// +// @param unknown1 - Unknown. Pass 0. +// +// @param gain - Gain. +// +// @param unknown2 - Unknown. Pass 0. +// +// @return 0 on success, an error if less than 0. pub extern fn sceAudioInputInit(unknown1: c_int, gain: c_int, unknown2: c_int) c_int; -pub extern fn sceAudioInputInitEx(params: [*c]pspAudioInputParams) c_int; + +// Init audio input (with extra arguments) +// +// @param params - A pointer to a ::pspAudioInputParams struct. +// +// @return 0 on success, an error if less than 0. +pub extern fn sceAudioInputInitEx(params: [*]PspAudioInputParams) c_int; + +// Perform audio input (blocking) +// +// @param samplecount - Number of samples. +// +// @param freq - Either 44100, 22050 or 11025. +// +// @param buf - Pointer to where the audio data will be stored. +// +// @return 0 on success, an error if less than 0. pub extern fn sceAudioInputBlocking(samplecount: c_int, freq: c_int, buf: ?*c_void) c_int; + +// Perform audio input +// +// @param samplecount - Number of samples. +// +// @param freq - Either 44100, 22050 or 11025. +// +// @param buf - Pointer to where the audio data will be stored. +// +// @return 0 on success, an error if less than 0. pub extern fn sceAudioInput(samplecount: c_int, freq: c_int, buf: ?*c_void) c_int; + +// Get the number of samples that were acquired +// +// @return Number of samples acquired, an error if less than 0. pub extern fn sceAudioGetInputLength() c_int; + +// Wait for non-blocking audio input to complete +// +// @return 0 on success, an error if less than 0. pub extern fn sceAudioWaitInputEnd() c_int; + +// Poll for non-blocking audio input status +// +// @return 0 if input has completed, 1 if not completed or an error if less than 0. pub extern fn sceAudioPollInputEnd() c_int; diff --git a/src/psp/sdk/pspaudiocodec.zig b/src/psp/sdk/pspaudiocodec.zig index 5ce0a2c..a5974fd 100644 --- a/src/psp/sdk/pspaudiocodec.zig +++ b/src/psp/sdk/pspaudiocodec.zig @@ -1,5 +1,12 @@ -pub extern fn sceAudiocodecCheckNeedMem(Buffer: [*c]c_ulong, Type: c_int) c_int; -pub extern fn sceAudiocodecInit(Buffer: [*c]c_ulong, Type: c_int) c_int; -pub extern fn sceAudiocodecDecode(Buffer: [*c]c_ulong, Type: c_int) c_int; -pub extern fn sceAudiocodecGetEDRAM(Buffer: [*c]c_ulong, Type: c_int) c_int; -pub extern fn sceAudiocodecReleaseEDRAM(Buffer: [*c]c_ulong) c_int; +pub const Codec = extern enum(c_int){ + At3Plus = 0x1000, + At3 = 0x1001, + Mp3 = 0x1002, + Aac = 0x1003, +}; + +pub extern fn sceAudiocodecCheckNeedMem(buffer: [*c]c_ulong, typec: c_int) c_int; +pub extern fn sceAudiocodecInit(buffer: [*c]c_ulong, typec: c_int) c_int; +pub extern fn sceAudiocodecDecode(buffer: [*c]c_ulong, typec: c_int) c_int; +pub extern fn sceAudiocodecGetEDRAM(buffer: [*c]c_ulong, typec: c_int) c_int; +pub extern fn sceAudiocodecReleaseEDRAM(buffer: [*c]c_ulong) c_int; diff --git a/src/psp/sdk/pspctrl.zig b/src/psp/sdk/pspctrl.zig index fea87f9..b6f9524 100644 --- a/src/psp/sdk/pspctrl.zig +++ b/src/psp/sdk/pspctrl.zig @@ -1,61 +1,133 @@ -pub const enum_PspCtrlButtons = extern enum(c_int) { - PSP_CTRL_SELECT = 1, - PSP_CTRL_START = 8, - PSP_CTRL_UP = 16, - PSP_CTRL_RIGHT = 32, - PSP_CTRL_DOWN = 64, - PSP_CTRL_LEFT = 128, - PSP_CTRL_LTRIGGER = 256, - PSP_CTRL_RTRIGGER = 512, - PSP_CTRL_TRIANGLE = 4096, - PSP_CTRL_CIRCLE = 8192, - PSP_CTRL_CROSS = 16384, - PSP_CTRL_SQUARE = 32768, - PSP_CTRL_HOME = 65536, - PSP_CTRL_HOLD = 131072, - PSP_CTRL_NOTE = 8388608, - PSP_CTRL_SCREEN = 4194304, - PSP_CTRL_VOLUP = 1048576, - PSP_CTRL_VOLDOWN = 2097152, - PSP_CTRL_WLAN_UP = 262144, - PSP_CTRL_REMOTE = 524288, - PSP_CTRL_DISC = 16777216, - PSP_CTRL_MS = 33554432, - _, +pub const PspCtrlButtons = extern enum(c_int) { + Select = 1, + Start = 8, + Up = 16, + Right = 32, + Down = 64, + Left = 128, + LTrigger = 256, + RTrigger = 512, + Triangle = 4096, + Circle = 8192, + Cross = 16384, + Square = 32768, + Home = 65536, + Hold = 131072, + Note = 8388608, + Screen = 4194304, + VolUp = 1048576, + VolDown = 2097152, + WlanUp = 262144, + Remote = 524288, + Disc = 16777216, + Ms = 33554432, }; -pub const enum_PspCtrlMode = extern enum(c_int) { - PSP_CTRL_MODE_DIGITAL = 0, - PSP_CTRL_MODE_ANALOG = 1, - _, +pub const PspCtrlMode = extern enum(c_int) { + Digital = 0, + Analog = 1, }; -pub const struct_SceCtrlData = extern struct { + +pub const SceCtrlData = extern struct { TimeStamp: c_uint, Buttons: c_uint, Lx: u8, Ly: u8, Rsrv: [6]u8, }; -pub const SceCtrlData = struct_SceCtrlData; -pub const struct_SceCtrlLatch = extern struct { + +pub const SceCtrlLatch = extern struct { uiMake: c_uint, uiBreak: c_uint, uiPress: c_uint, uiRelease: c_uint, }; -pub const SceCtrlLatch = struct_SceCtrlLatch; + + +// Set the controller cycle setting. +// +// @param cycle - Cycle. Normally set to 0. +// +// @return The previous cycle setting. pub extern fn sceCtrlSetSamplingCycle(cycle: c_int) c_int; -pub extern fn sceCtrlGetSamplingCycle(pcycle: [*c]c_int) c_int; + + +// Get the controller current cycle setting. +// +// @param pcycle - Return value. +// +// @return 0. +pub extern fn sceCtrlGetSamplingCycle(pcycle: *c_int) c_int; + + +// Set the controller mode. +// +// @param mode - One of ::PspCtrlMode. +// +// @return The previous mode. pub extern fn sceCtrlSetSamplingMode(mode: c_int) c_int; -pub extern fn sceCtrlGetSamplingMode(pmode: [*c]c_int) c_int; -pub extern fn sceCtrlPeekBufferPositive(pad_data: [*c]SceCtrlData, count: c_int) c_int; -pub extern fn sceCtrlPeekBufferNegative(pad_data: [*c]SceCtrlData, count: c_int) c_int; -pub extern fn sceCtrlReadBufferPositive(pad_data: [*c]SceCtrlData, count: c_int) c_int; -pub extern fn sceCtrlReadBufferNegative(pad_data: [*c]SceCtrlData, count: c_int) c_int; -pub extern fn sceCtrlPeekLatch(latch_data: [*c]SceCtrlLatch) c_int; -pub extern fn sceCtrlReadLatch(latch_data: [*c]SceCtrlLatch) c_int; + +pub fn ctrlSetSamplingMode(mode: PspCtrlMode) PspCtrlMode { + @setRuntimeSafety(false); + var res = sceCtrlSetSamplingMode(@enumToInt(mode)); + return @intToEnum(PspCtrlMode, res); +} + +// Get the current controller mode. +// +// @param pmode - Return value. +// +// @return 0. +pub extern fn sceCtrlGetSamplingMode(pmode: *c_int) c_int; + +pub extern fn sceCtrlPeekBufferPositive(pad_data: *SceCtrlData, count: c_int) c_int; +pub extern fn sceCtrlPeekBufferNegative(pad_data: *SceCtrlData, count: c_int) c_int; + + +// Read buffer positive +// C Example: +// SceCtrlData pad; +// sceCtrlSetSamplingCycle(0); +// sceCtrlSetSamplingMode(1); +// sceCtrlReadBufferPositive(&pad, 1); +// @param pad_data - Pointer to a ::SceCtrlData structure used hold the returned pad data. +// @param count - Number of ::SceCtrlData buffers to read. +pub extern fn sceCtrlReadBufferPositive(pad_data: *SceCtrlData, count: c_int) c_int; + +pub extern fn sceCtrlReadBufferNegative(pad_data: *SceCtrlData, count: c_int) c_int; +pub extern fn sceCtrlPeekLatch(latch_data: *SceCtrlLatch) c_int; +pub extern fn sceCtrlReadLatch(latch_data: *SceCtrlLatch) c_int; + +// Set analog threshold relating to the idle timer. +// +// @param idlereset - Movement needed by the analog to reset the idle timer. +// @param idleback - Movement needed by the analog to bring the PSP back from an idle state. +// +// Set to -1 for analog to not cancel idle timer. +// Set to 0 for idle timer to be cancelled even if the analog is not moved. +// Set between 1 - 128 to specify the movement on either axis needed by the analog to fire the event. +// +// @return < 0 on error. pub extern fn sceCtrlSetIdleCancelThreshold(idlereset: c_int, idleback: c_int) c_int; -pub extern fn sceCtrlGetIdleCancelThreshold(idlerest: [*c]c_int, idleback: [*c]c_int) c_int; +pub fn ctrlSetIdleCancelThreshold(idlereset: c_int, idleback: c_int) !i32 { + var res = sceCtrlSetIdleCancelThreshold(idlereset, idleback); + if(res < 0){ + return error.Unexpected; + } + return res; +} -pub const PspCtrlButtons = enum_PspCtrlButtons; -pub const PspCtrlMode = enum_PspCtrlMode; +// Get the idle threshold values. +// +// @param idlerest - Movement needed by the analog to reset the idle timer. +// @param idleback - Movement needed by the analog to bring the PSP back from an idle state. +// +// @return < 0 on error. +pub extern fn sceCtrlGetIdleCancelThreshold(idlerest: *c_int, idleback: *c_int) c_int; +pub fn ctrlGetIdleCancelThreshold(idlerest: *c_int, idleback: *c_int) !i32 { + var res = sceCtrlGetIdleCancelThreshold(idlereset, idleback); + if(res < 0){ + return error.Unexpected; + } + return res; +} diff --git a/src/psp/sdk/pspdisplay.zig b/src/psp/sdk/pspdisplay.zig index 728e276..a5ec2c0 100644 --- a/src/psp/sdk/pspdisplay.zig +++ b/src/psp/sdk/pspdisplay.zig @@ -1,38 +1,102 @@ -pub const enum_PspDisplayPixelFormats = extern enum(c_int) { +pub const PspDisplayPixelFormats = extern enum(c_int) { Format565 = 0, Format5551 = 1, Format4444 = 2, Format8888 = 3, - _, }; -pub const enum_PspDisplaySetBufSync = extern enum(c_int) { +pub const PspDisplaySetBufSync = extern enum(c_int) { Immediate = 0, Nextframe = 1, - _, }; -pub const enum_PspDisplayErrorCodes = extern enum(c_int) { +pub const PspDisplayErrorCodes = extern enum(c_int) { Ok = 0, Pointer = 2147483907, Argument = 2147483911, - _, }; + + +// Set display mode +// +// @param mode - Display mode, normally 0. +// @param width - Width of screen in pixels. +// @param height - Height of screen in pixels. +// +// @return ??? pub extern fn sceDisplaySetMode(mode: c_int, width: c_int, height: c_int) c_int; -pub extern fn sceDisplayGetMode(pmode: [*c]c_int, pwidth: [*c]c_int, pheight: [*c]c_int) c_int; +pub fn displaySetMode(mode: c_int, width: c_int, height: c_int) void { + _ = sceDisplaySetMode(mode, width, height); +} + + +// Get display mode +// +// @param pmode - Pointer to an integer to receive the current mode. +// @param pwidth - Pointer to an integer to receive the current width. +// @param pheight - Pointer to an integer to receive the current height, +// +// @return 0 on success +pub extern fn sceDisplayGetMode(pmode: *c_int, pwidth: *c_int, pheight: *c_int) c_int; +pub fn displayGetMode(pmode: *c_int, pwidth: *c_int, pheight: *c_int) bool { + var res = sceDisplayGetMode(pmode, pwidth, pheight); + return res == 0; +} + +// Display set framebuf +// +// @param topaddr - address of start of framebuffer +// @param bufferwidth - buffer width (must be power of 2) +// @param pixelformat - One of ::PspDisplayPixelFormats. +// @param sync - One of ::PspDisplaySetBufSync +// +// @return 0 on success pub extern fn sceDisplaySetFrameBuf(topaddr: ?*c_void, bufferwidth: c_int, pixelformat: c_int, sync: c_int) c_int; -pub extern fn sceDisplayGetFrameBuf(topaddr: [*c]?*c_void, bufferwidth: [*c]c_int, pixelformat: [*c]c_int, sync: c_int) c_int; +pub fn displaySetFrameBuf(topaddr: ?*c_void, bufferwidth: c_int, pixelformat: c_int, sync: c_int) bool { + var res = sceDisplaySetFrameBuf(topaddr, bufferwidth, pixelformat, sync); + return res; +} + +// Get Display Framebuffer information +// +// @param topaddr - pointer to void* to receive address of start of framebuffer +// @param bufferwidth - pointer to int to receive buffer width (must be power of 2) +// @param pixelformat - pointer to int to receive one of ::PspDisplayPixelFormats. +// @param sync - One of ::PspDisplaySetBufSync +// +// @return 0 on success +pub extern fn sceDisplayGetFrameBuf(topaddr: **c_void, bufferwidth: *c_int, pixelformat: *c_int, sync: c_int) c_int; +pub fn displayGetFrameBuf(topaddr: **c_void, bufferwidth: *c_int, pixelformat: *c_int, sync: c_int) bool { + var res = sceDisplayGetFrameBuf(topaddr, bufferwidth, pixelformat, sync); + return res == 0; +} + +//Number of vertical blank pulses up to now pub extern fn sceDisplayGetVcount() c_uint; + +//Wait for vertical blank start pub extern fn sceDisplayWaitVblankStart() c_int; + +//Wait for vertical blank start with callback pub extern fn sceDisplayWaitVblankStartCB() c_int; + +//Wait for vertical blank pub extern fn sceDisplayWaitVblank() c_int; + +//Wait for vertical blank with callback pub extern fn sceDisplayWaitVblankCB() c_int; + +//Get accumlated HSYNC count pub extern fn sceDisplayGetAccumulatedHcount() c_int; + +//Get current HSYNC count pub extern fn sceDisplayGetCurrentHcount() c_int; + +//Get number of frames per second pub extern fn sceDisplayGetFramePerSec() f32; + +//Get whether or not frame buffer is being displayed pub extern fn sceDisplayIsForeground() c_int; -pub extern fn sceDisplayIsVblank() c_int; -pub const PspDisplayPixelFormats = enum_PspDisplayPixelFormats; -pub const PspDisplaySetBufSync = enum_PspDisplaySetBufSync; -pub const PspDisplayErrorCodes = enum_PspDisplayErrorCodes; +//Test whether VBLANK is active +pub extern fn sceDisplayIsVblank() c_int; diff --git a/src/psp/sdk/pspdmac.zig b/src/psp/sdk/pspdmac.zig new file mode 100644 index 0000000..9ac763e --- /dev/null +++ b/src/psp/sdk/pspdmac.zig @@ -0,0 +1,12 @@ +usingnamespace @import("psptypes.zig"); + +// Copy data in memory using DMAC +// +// @param dst - The pointer to the destination +// @param src - The pointer to the source +// @param n - The size of data +// +// @return 0 on success; otherwise an error code +pub extern fn sceDmacMemcpy(dst: *c_void, src: *const c_void, n: SceSize) c_int; + +pub extern fn sceDmacTryMemcpy(dst: *c_void, src: *const c_void, n: SceSize) c_int; diff --git a/src/psp/sdk/pspge.zig b/src/psp/sdk/pspge.zig index 7178b93..4b16e60 100644 --- a/src/psp/sdk/pspge.zig +++ b/src/psp/sdk/pspge.zig @@ -1,77 +1,195 @@ -pub const struct_PspGeContext = extern struct { +pub const PspGeContext = extern struct { context: [512]c_uint, }; -pub const PspGeContext = struct_PspGeContext; -const struct_unnamed_5 = extern struct { + +pub const SceGeStack = extern struct { stack: [8]c_uint, }; -pub const SceGeStack = struct_unnamed_5; + pub const PspGeCallback = ?fn (c_int, ?*c_void) callconv(.C) void; -pub const struct_PspGeCallbackData = extern struct { +pub const PspGeCallbackData = extern struct { signal_func: PspGeCallback, signal_arg: ?*c_void, finish_func: PspGeCallback, finish_arg: ?*c_void, }; -pub const PspGeCallbackData = struct_PspGeCallbackData; -pub const struct_PspGeListArgs = extern struct { + +pub const PspGeListArgs = extern struct { size: c_uint, context: [*c]PspGeContext, numStacks: u32, stacks: [*c]SceGeStack, }; -pub const PspGeListArgs = struct_PspGeListArgs; -pub const struct_PspGeBreakParam = extern struct { + +pub const PspGeBreakParam = extern struct { buf: [4]c_uint, }; -pub const PspGeBreakParam = struct_PspGeBreakParam; + +pub const PspGeMatrixTypes = extern enum(c_int) { + Bone0 = 0, + Bone1 = 1, + Bone2 = 2, + Bone3 = 3, + Bone4 = 4, + Bone5 = 5, + Bone6 = 6, + Bone7 = 7, + World = 8, + View = 9, + Projection = 10, + Texgen = 11, +}; + +pub const PspGeStack = extern struct { + stack: [8]c_uint, +}; + +pub const PspGeListState = extern enum(c_int) { + Done = 0, + Queued = 1, + DrawingDone = 2, + StallReached = 3, + CancelDone = 4, +}; + + +// Get the size of VRAM. +// +// @return The size of VRAM (in bytes). pub extern fn sceGeEdramGetSize() c_uint; + +// Get the eDRAM address. +// +// @return A pointer to the base of the eDRAM. pub extern fn sceGeEdramGetAddr() ?*c_void; + + +// Retrieve the current value of a GE command. +// +// @param cmd - The GE command register to retrieve (0 to 0xFF, both included). +// +// @return The value of the GE command, < 0 on error. pub extern fn sceGeGetCmd(cmd: c_int) c_uint; -pub const enum_PspGeMatrixTypes = extern enum(c_int) { - PSP_GE_MATRIX_BONE0 = 0, - PSP_GE_MATRIX_BONE1 = 1, - PSP_GE_MATRIX_BONE2 = 2, - PSP_GE_MATRIX_BONE3 = 3, - PSP_GE_MATRIX_BONE4 = 4, - PSP_GE_MATRIX_BONE5 = 5, - PSP_GE_MATRIX_BONE6 = 6, - PSP_GE_MATRIX_BONE7 = 7, - PSP_GE_MATRIX_WORLD = 8, - PSP_GE_MATRIX_VIEW = 9, - PSP_GE_MATRIX_PROJECTION = 10, - PSP_GE_MATRIX_TEXGEN = 11, - _, -}; -pub const PspGeMatrixTypes = enum_PspGeMatrixTypes; + +// Retrieve a matrix of the given type. +// +// @param type - One of ::PspGeMatrixTypes. +// @param matrix - Pointer to a variable to store the matrix. +// +// @return < 0 on error. pub extern fn sceGeGetMtx(typec: c_int, matrix: ?*c_void) c_int; -const struct_unnamed_6 = extern struct { - stack: [8]c_uint, -}; -pub const PspGeStack = struct_unnamed_6; -pub extern fn sceGeGetStack(stackId: c_int, stack: [*c]PspGeStack) c_int; + + +// Save the GE's current state. +// +// @param context - Pointer to a ::PspGeContext. +// +// @return < 0 on error. pub extern fn sceGeSaveContext(context: [*c]PspGeContext) c_int; + + +// Restore a previously saved GE context. +// +// @param context - Pointer to a ::PspGeContext. +// +// @return < 0 on error. pub extern fn sceGeRestoreContext(context: [*c]const PspGeContext) c_int; + + +// Enqueue a display list at the tail of the GE display list queue. +// +// @param list - The head of the list to queue. +// @param stall - The stall address. +// If NULL then no stall address is set and the list is transferred immediately. +// @param cbid - ID of the callback set by calling sceGeSetCallback +// @param arg - Structure containing GE context buffer address +// +// @return The ID of the queue, < 0 on error. pub extern fn sceGeListEnQueue(list: ?*const c_void, stall: ?*c_void, cbid: c_int, arg: [*c]PspGeListArgs) c_int; + + +// Enqueue a display list at the head of the GE display list queue. +// +// @param list - The head of the list to queue. +// @param stall - The stall address. +// If NULL then no stall address is set and the list is transferred immediately. +// @param cbid - ID of the callback set by calling sceGeSetCallback +// @param arg - Structure containing GE context buffer address +// +// @return The ID of the queue, < 0 on error. pub extern fn sceGeListEnQueueHead(list: ?*const c_void, stall: ?*c_void, cbid: c_int, arg: [*c]PspGeListArgs) c_int; + + +// Cancel a queued or running list. +// +// @param qid - The ID of the queue. +// +// @return < 0 on error. pub extern fn sceGeListDeQueue(qid: c_int) c_int; + + +// Update the stall address for the specified queue. +// +// @param qid - The ID of the queue. +// @param stall - The new stall address. +// +// @return < 0 on error pub extern fn sceGeListUpdateStallAddr(qid: c_int, stall: ?*c_void) c_int; -pub const enum_PspGeListState = extern enum(c_int) { - PSP_GE_LIST_DONE = 0, - PSP_GE_LIST_QUEUED = 1, - PSP_GE_LIST_DRAWING_DONE = 2, - PSP_GE_LIST_STALL_REACHED = 3, - PSP_GE_LIST_CANCEL_DONE = 4, - _, -}; -pub const PspGeListState = enum_PspGeListState; + +// Wait for syncronisation of a list. +// +// @param qid - The queue ID of the list to sync. +// @param syncType - 0 if you want to wait for the list to be completed, or 1 if you just want to peek the actual state. +// +// @return The specified queue status, one of ::PspGeListState. pub extern fn sceGeListSync(qid: c_int, syncType: c_int) c_int; + + +// Wait for drawing to complete. +// +// @param syncType - 0 if you want to wait for the drawing to be completed, or 1 if you just want to peek the state of the display list currently being executed. +// +// @return The current queue status, one of ::PspGeListState. pub extern fn sceGeDrawSync(syncType: c_int) c_int; -pub extern fn sceGeSetCallback(cb: [*c]PspGeCallbackData) c_int; + + +// Register callback handlers for the the GE. +// +// @param cb - Configured callback data structure. +// +// @return The callback ID, < 0 on error. +pub extern fn sceGeSetCallback(cb: *PspGeCallbackData) c_int; + + +// Unregister the callback handlers. +// +// @param cbid - The ID of the callbacks, returned by sceGeSetCallback(). +// +// @return < 0 on error pub extern fn sceGeUnsetCallback(cbid: c_int) c_int; + + +// Interrupt drawing queue. +// +// @param mode - If set to 1, reset all the queues. +// @param pParam - Unused (just K1-checked). +// +// @return The stopped queue ID if mode isn't set to 0, otherwise 0, and < 0 on error. pub extern fn sceGeBreak(mode: c_int, pParam: [*c]PspGeBreakParam) c_int; + + +// Restart drawing queue. +// +// @return < 0 on error. pub extern fn sceGeContinue() c_int; + + +// Set the eDRAM address translation mode. +// +// @param width - 0 to not set the translation width, otherwise 512, 1024, 2048 or 4096. +// +// @return The previous width if it was set, otherwise 0, < 0 on error. pub extern fn sceGeEdramSetAddrTranslation(width: c_int) c_int; diff --git a/src/psp/sdk/psphprm.zig b/src/psp/sdk/psphprm.zig index 069bda4..5a63a6d 100644 --- a/src/psp/sdk/psphprm.zig +++ b/src/psp/sdk/psphprm.zig @@ -1,17 +1,76 @@ -pub const enum_PspHprmKeys = extern enum(c_int) { - PSP_HPRM_PLAYPAUSE = 1, - PSP_HPRM_FORWARD = 4, - PSP_HPRM_BACK = 8, - PSP_HPRM_VOL_UP = 16, - PSP_HPRM_VOL_DOWN = 32, - PSP_HPRM_HOLD = 128, - _, +pub const PspHprmKeys = extern enum(u8) { + Playpause = 1, + Forward = 4, + Back = 8, + VolUp = 16, + VolDown = 32, + Hold = 128, }; -pub extern fn sceHprmPeekCurrentKey(key: [*c]u32) c_int; -pub extern fn sceHprmPeekLatch(latch: [*c]u32) c_int; -pub extern fn sceHprmReadLatch(latch: [*c]u32) c_int; + + +// Peek at the current being pressed on the remote. +// +// @param key - Pointer to the u32 to receive the key bitmap, should be one or +// more of ::PspHprmKeys +// +// @return < 0 on error +pub extern fn sceHprmPeekCurrentKey(key: [*]u32) c_int; +pub fn hprmPeekCurrentKey(latch: [*]u32) !i32 { + var res = sceHprmPeekCurrentKey(latch); + if(res < 0){ + return error.Unexpected; + } + return res; +} + +// Peek at the current latch data. +// +// @param latch - Pointer a to a 4 dword array to contain the latch data. +// +// @return < 0 on error. +pub extern fn sceHprmPeekLatch(latch: [*]u32) c_int; +pub fn hprmPeekLatch(latch: [*]u32) !i32 { + var res = sceHprmPeekLatch(latch); + if(res < 0){ + return error.Unexpected; + } + return res; +} + +// Read the current latch data. +// +// @param latch - Pointer a to a 4 dword array to contain the latch data. +// +// @return < 0 on error. +pub extern fn sceHprmReadLatch(latch: [*]u32) c_int; +pub fn hprmReadLatch(latch: [*]u32) !i32 { + var res = sceHprmReadLatch(latch); + if(res < 0){ + return error.Unexpected; + } + return res; +} + +// Determines whether the headphones are plugged in. +// +// @return 1 if the headphones are plugged in, else 0. pub extern fn sceHprmIsHeadphoneExist() c_int; +pub fn hprmIsHeadphoneExist() bool { + return sceHprmIsHeadphoneExist() == 1; +} + +// Determines whether the remote is plugged in. +// +// @return 1 if the remote is plugged in, else 0. pub extern fn sceHprmIsRemoteExist() c_int; -pub extern fn sceHprmIsMicrophoneExist() c_int; +pub fn hprmIsRemoteExist() bool { + return sceHprmIsRemoteExist() == 1; +} -pub const PspHprmKeys = enum_PspHprmKeys; +// Determines whether the microphone is plugged in. +// +// @return 1 if the microphone is plugged in, else 0. +pub extern fn sceHprmIsMicrophoneExist() c_int; +pub fn hprmIsMicrophoneExist() bool { + return sceHprmIsMicrophoneExist() == 1; +} diff --git a/src/psp/sdk/pspimpose.zig b/src/psp/sdk/pspimpose.zig deleted file mode 100644 index 112b690..0000000 --- a/src/psp/sdk/pspimpose.zig +++ /dev/null @@ -1,12 +0,0 @@ -pub const SceImposeParam = c_int; -pub extern fn sceImposeGetParam(param: SceImposeParam) c_int; -pub extern fn sceImposeSetParam(param: SceImposeParam, value: c_int) c_int; -pub extern fn sceImposeGetBacklightOffTime() c_int; -pub extern fn sceImposeSetBacklightOffTime(value: c_int) c_int; -pub extern fn sceImposeGetLanguageMode(lang: [*c]c_int, button: [*c]c_int) c_int; -pub extern fn sceImposeSetLanguageMode(lang: c_int, button: c_int) c_int; -pub extern fn sceImposeGetUMDPopup() c_int; -pub extern fn sceImposeSetUMDPopup(value: c_int) c_int; -pub extern fn sceImposeGetHomePopup() c_int; -pub extern fn sceImposeSetHomePopup(value: c_int) c_int; -pub extern fn sceImposeCheckVideoOut(value: [*c]c_int) c_int; diff --git a/src/psp/sdk/pspjpeg.zig b/src/psp/sdk/pspjpeg.zig index 4409c69..4769709 100644 --- a/src/psp/sdk/pspjpeg.zig +++ b/src/psp/sdk/pspjpeg.zig @@ -1,7 +1,48 @@ usingnamespace @import("psptypes.zig"); +// Inits the MJpeg library +// +// @return 0 on success, < 0 on error pub extern fn sceJpegInitMJpeg() c_int; +pub fn jpegInitMJpeg() bool { + return sceJpegInitMJpeg() == 0; +} + +// Finishes the MJpeg library +// +// @return 0 on success, < 0 on error pub extern fn sceJpegFinishMJpeg() c_int; +pub fn jpegFinishMJpeg() bool{ + return sceJpegFinishMJpeg() == 0; +} + +// Creates the decoder context. +// +// @param width - The width of the frame +// @param height - The height of the frame +// +// @return 0 on success, < 0 on error pub extern fn sceJpegCreateMJpeg(width: c_int, height: c_int) c_int; +pub fn jpegCreateMJpeg(width: c_int, height: c_int) bool { + return sceJpegCreateMJpeg(width, height) == 0; +} + +// Deletes the current decoder context. +// +// @return 0 on success, < 0 on error pub extern fn sceJpegDeleteMJpeg() c_int; -pub extern fn sceJpegDecodeMJpeg(jpegbuf: [*c]u8, size: SceSize, rgba: ?*c_void, unk: u32) c_int; +pub fn jpegDeleteMJpeg() bool { + return sceJpegDeleteMJpeg == 0; +} + +// +// Decodes a mjpeg frame. +// +// @param jpegbuf - the buffer with the mjpeg frame +// @param size - size of the buffer pointed by jpegbuf +// @param rgba - buffer where the decoded data in RGBA format will be stored. +// It should have a size of (width * height * 4). +// @param unk - Unknown, pass 0 +// +// @return (width * 65536) + height on success, < 0 on error +pub extern fn sceJpegDecodeMJpeg(jpegbuf: []u8, size: SceSize, rgba: ?*c_void, unk: u32) c_int; diff --git a/src/psp/sdk/pspkerror.zig b/src/psp/sdk/pspkerror.zig index 68bd8d8..e8dcf75 100644 --- a/src/psp/sdk/pspkerror.zig +++ b/src/psp/sdk/pspkerror.zig @@ -1,202 +1,200 @@ -pub const enum_PspKernelErrorCodes = extern enum(c_int) { - SCE_KERNEL_ERROR_OK = 0, - SCE_KERNEL_ERROR_ERROR = 2147614721, - SCE_KERNEL_ERROR_NOTIMP = 2147614722, - SCE_KERNEL_ERROR_ILLEGAL_EXPCODE = 2147614770, - SCE_KERNEL_ERROR_EXPHANDLER_NOUSE = 2147614771, - SCE_KERNEL_ERROR_EXPHANDLER_USED = 2147614772, - SCE_KERNEL_ERROR_SYCALLTABLE_NOUSED = 2147614773, - SCE_KERNEL_ERROR_SYCALLTABLE_USED = 2147614774, - SCE_KERNEL_ERROR_ILLEGAL_SYSCALLTABLE = 2147614775, - SCE_KERNEL_ERROR_ILLEGAL_PRIMARY_SYSCALL_NUMBER = 2147614776, - SCE_KERNEL_ERROR_PRIMARY_SYSCALL_NUMBER_INUSE = 2147614777, - SCE_KERNEL_ERROR_ILLEGAL_CONTEXT = 2147614820, - SCE_KERNEL_ERROR_ILLEGAL_INTRCODE = 2147614821, - SCE_KERNEL_ERROR_CPUDI = 2147614822, - SCE_KERNEL_ERROR_FOUND_HANDLER = 2147614823, - SCE_KERNEL_ERROR_NOTFOUND_HANDLER = 2147614824, - SCE_KERNEL_ERROR_ILLEGAL_INTRLEVEL = 2147614825, - SCE_KERNEL_ERROR_ILLEGAL_ADDRESS = 2147614826, - SCE_KERNEL_ERROR_ILLEGAL_INTRPARAM = 2147614827, - SCE_KERNEL_ERROR_ILLEGAL_STACK_ADDRESS = 2147614828, - SCE_KERNEL_ERROR_ALREADY_STACK_SET = 2147614829, - SCE_KERNEL_ERROR_NO_TIMER = 2147614870, - SCE_KERNEL_ERROR_ILLEGAL_TIMERID = 2147614871, - SCE_KERNEL_ERROR_ILLEGAL_SOURCE = 2147614872, - SCE_KERNEL_ERROR_ILLEGAL_PRESCALE = 2147614873, - SCE_KERNEL_ERROR_TIMER_BUSY = 2147614874, - SCE_KERNEL_ERROR_TIMER_NOT_SETUP = 2147614875, - SCE_KERNEL_ERROR_TIMER_NOT_INUSE = 2147614876, - SCE_KERNEL_ERROR_UNIT_USED = 2147614880, - SCE_KERNEL_ERROR_UNIT_NOUSE = 2147614881, - SCE_KERNEL_ERROR_NO_ROMDIR = 2147614882, - SCE_KERNEL_ERROR_IDTYPE_EXIST = 2147614920, - SCE_KERNEL_ERROR_IDTYPE_NOT_EXIST = 2147614921, - SCE_KERNEL_ERROR_IDTYPE_NOT_EMPTY = 2147614922, - SCE_KERNEL_ERROR_UNKNOWN_UID = 2147614923, - SCE_KERNEL_ERROR_UNMATCH_UID_TYPE = 2147614924, - SCE_KERNEL_ERROR_ID_NOT_EXIST = 2147614925, - SCE_KERNEL_ERROR_NOT_FOUND_UIDFUNC = 2147614926, - SCE_KERNEL_ERROR_UID_ALREADY_HOLDER = 2147614927, - SCE_KERNEL_ERROR_UID_NOT_HOLDER = 2147614928, - SCE_KERNEL_ERROR_ILLEGAL_PERM = 2147614929, - SCE_KERNEL_ERROR_ILLEGAL_ARGUMENT = 2147614930, - SCE_KERNEL_ERROR_ILLEGAL_ADDR = 2147614931, - SCE_KERNEL_ERROR_OUT_OF_RANGE = 2147614932, - SCE_KERNEL_ERROR_MEM_RANGE_OVERLAP = 2147614933, - SCE_KERNEL_ERROR_ILLEGAL_PARTITION = 2147614934, - SCE_KERNEL_ERROR_PARTITION_INUSE = 2147614935, - SCE_KERNEL_ERROR_ILLEGAL_MEMBLOCKTYPE = 2147614936, - SCE_KERNEL_ERROR_MEMBLOCK_ALLOC_FAILED = 2147614937, - SCE_KERNEL_ERROR_MEMBLOCK_RESIZE_LOCKED = 2147614938, - SCE_KERNEL_ERROR_MEMBLOCK_RESIZE_FAILED = 2147614939, - SCE_KERNEL_ERROR_HEAPBLOCK_ALLOC_FAILED = 2147614940, - SCE_KERNEL_ERROR_HEAP_ALLOC_FAILED = 2147614941, - SCE_KERNEL_ERROR_ILLEGAL_CHUNK_ID = 2147614942, - SCE_KERNEL_ERROR_NOCHUNK = 2147614943, - SCE_KERNEL_ERROR_NO_FREECHUNK = 2147614944, - SCE_KERNEL_ERROR_LINKERR = 2147615020, - SCE_KERNEL_ERROR_ILLEGAL_OBJECT = 2147615021, - SCE_KERNEL_ERROR_UNKNOWN_MODULE = 2147615022, - SCE_KERNEL_ERROR_NOFILE = 2147615023, - SCE_KERNEL_ERROR_FILEERR = 2147615024, - SCE_KERNEL_ERROR_MEMINUSE = 2147615025, - SCE_KERNEL_ERROR_PARTITION_MISMATCH = 2147615026, - SCE_KERNEL_ERROR_ALREADY_STARTED = 2147615027, - SCE_KERNEL_ERROR_NOT_STARTED = 2147615028, - SCE_KERNEL_ERROR_ALREADY_STOPPED = 2147615029, - SCE_KERNEL_ERROR_CAN_NOT_STOP = 2147615030, - SCE_KERNEL_ERROR_NOT_STOPPED = 2147615031, - SCE_KERNEL_ERROR_NOT_REMOVABLE = 2147615032, - SCE_KERNEL_ERROR_EXCLUSIVE_LOAD = 2147615033, - SCE_KERNEL_ERROR_LIBRARY_NOT_YET_LINKED = 2147615034, - SCE_KERNEL_ERROR_LIBRARY_FOUND = 2147615035, - SCE_KERNEL_ERROR_LIBRARY_NOTFOUND = 2147615036, - SCE_KERNEL_ERROR_ILLEGAL_LIBRARY = 2147615037, - SCE_KERNEL_ERROR_LIBRARY_INUSE = 2147615038, - SCE_KERNEL_ERROR_ALREADY_STOPPING = 2147615039, - SCE_KERNEL_ERROR_ILLEGAL_OFFSET = 2147615040, - SCE_KERNEL_ERROR_ILLEGAL_POSITION = 2147615041, - SCE_KERNEL_ERROR_ILLEGAL_ACCESS = 2147615042, - SCE_KERNEL_ERROR_MODULE_MGR_BUSY = 2147615043, - SCE_KERNEL_ERROR_ILLEGAL_FLAG = 2147615044, - SCE_KERNEL_ERROR_CANNOT_GET_MODULELIST = 2147615045, - SCE_KERNEL_ERROR_PROHIBIT_LOADMODULE_DEVICE = 2147615046, - SCE_KERNEL_ERROR_PROHIBIT_LOADEXEC_DEVICE = 2147615047, - SCE_KERNEL_ERROR_UNSUPPORTED_PRX_TYPE = 2147615048, - SCE_KERNEL_ERROR_ILLEGAL_PERM_CALL = 2147615049, - SCE_KERNEL_ERROR_CANNOT_GET_MODULE_INFORMATION = 2147615050, - SCE_KERNEL_ERROR_ILLEGAL_LOADEXEC_BUFFER = 2147615051, - SCE_KERNEL_ERROR_ILLEGAL_LOADEXEC_FILENAME = 2147615052, - SCE_KERNEL_ERROR_NO_EXIT_CALLBACK = 2147615053, - SCE_KERNEL_ERROR_NO_MEMORY = 2147615120, - SCE_KERNEL_ERROR_ILLEGAL_ATTR = 2147615121, - SCE_KERNEL_ERROR_ILLEGAL_ENTRY = 2147615122, - SCE_KERNEL_ERROR_ILLEGAL_PRIORITY = 2147615123, - SCE_KERNEL_ERROR_ILLEGAL_STACK_SIZE = 2147615124, - SCE_KERNEL_ERROR_ILLEGAL_MODE = 2147615125, - SCE_KERNEL_ERROR_ILLEGAL_MASK = 2147615126, - SCE_KERNEL_ERROR_ILLEGAL_THID = 2147615127, - SCE_KERNEL_ERROR_UNKNOWN_THID = 2147615128, - SCE_KERNEL_ERROR_UNKNOWN_SEMID = 2147615129, - SCE_KERNEL_ERROR_UNKNOWN_EVFID = 2147615130, - SCE_KERNEL_ERROR_UNKNOWN_MBXID = 2147615131, - SCE_KERNEL_ERROR_UNKNOWN_VPLID = 2147615132, - SCE_KERNEL_ERROR_UNKNOWN_FPLID = 2147615133, - SCE_KERNEL_ERROR_UNKNOWN_MPPID = 2147615134, - SCE_KERNEL_ERROR_UNKNOWN_ALMID = 2147615135, - SCE_KERNEL_ERROR_UNKNOWN_TEID = 2147615136, - SCE_KERNEL_ERROR_UNKNOWN_CBID = 2147615137, - SCE_KERNEL_ERROR_DORMANT = 2147615138, - SCE_KERNEL_ERROR_SUSPEND = 2147615139, - SCE_KERNEL_ERROR_NOT_DORMANT = 2147615140, - SCE_KERNEL_ERROR_NOT_SUSPEND = 2147615141, - SCE_KERNEL_ERROR_NOT_WAIT = 2147615142, - SCE_KERNEL_ERROR_CAN_NOT_WAIT = 2147615143, - SCE_KERNEL_ERROR_WAIT_TIMEOUT = 2147615144, - SCE_KERNEL_ERROR_WAIT_CANCEL = 2147615145, - SCE_KERNEL_ERROR_RELEASE_WAIT = 2147615146, - SCE_KERNEL_ERROR_NOTIFY_CALLBACK = 2147615147, - SCE_KERNEL_ERROR_THREAD_TERMINATED = 2147615148, - SCE_KERNEL_ERROR_SEMA_ZERO = 2147615149, - SCE_KERNEL_ERROR_SEMA_OVF = 2147615150, - SCE_KERNEL_ERROR_EVF_COND = 2147615151, - SCE_KERNEL_ERROR_EVF_MULTI = 2147615152, - SCE_KERNEL_ERROR_EVF_ILPAT = 2147615153, - SCE_KERNEL_ERROR_MBOX_NOMSG = 2147615154, - SCE_KERNEL_ERROR_MPP_FULL = 2147615155, - SCE_KERNEL_ERROR_MPP_EMPTY = 2147615156, - SCE_KERNEL_ERROR_WAIT_DELETE = 2147615157, - SCE_KERNEL_ERROR_ILLEGAL_MEMBLOCK = 2147615158, - SCE_KERNEL_ERROR_ILLEGAL_MEMSIZE = 2147615159, - SCE_KERNEL_ERROR_ILLEGAL_SPADADDR = 2147615160, - SCE_KERNEL_ERROR_SPAD_INUSE = 2147615161, - SCE_KERNEL_ERROR_SPAD_NOT_INUSE = 2147615162, - SCE_KERNEL_ERROR_ILLEGAL_TYPE = 2147615163, - SCE_KERNEL_ERROR_ILLEGAL_SIZE = 2147615164, - SCE_KERNEL_ERROR_ILLEGAL_COUNT = 2147615165, - SCE_KERNEL_ERROR_UNKNOWN_VTID = 2147615166, - SCE_KERNEL_ERROR_ILLEGAL_VTID = 2147615167, - SCE_KERNEL_ERROR_ILLEGAL_KTLSID = 2147615168, - SCE_KERNEL_ERROR_KTLS_FULL = 2147615169, - SCE_KERNEL_ERROR_KTLS_BUSY = 2147615170, - SCE_KERNEL_ERROR_PM_INVALID_PRIORITY = 2147615320, - SCE_KERNEL_ERROR_PM_INVALID_DEVNAME = 2147615321, - SCE_KERNEL_ERROR_PM_UNKNOWN_DEVNAME = 2147615322, - SCE_KERNEL_ERROR_PM_PMINFO_REGISTERED = 2147615323, - SCE_KERNEL_ERROR_PM_PMINFO_UNREGISTERED = 2147615324, - SCE_KERNEL_ERROR_PM_INVALID_MAJOR_STATE = 2147615325, - SCE_KERNEL_ERROR_PM_INVALID_REQUEST = 2147615326, - SCE_KERNEL_ERROR_PM_UNKNOWN_REQUEST = 2147615327, - SCE_KERNEL_ERROR_PM_INVALID_UNIT = 2147615328, - SCE_KERNEL_ERROR_PM_CANNOT_CANCEL = 2147615329, - SCE_KERNEL_ERROR_PM_INVALID_PMINFO = 2147615330, - SCE_KERNEL_ERROR_PM_INVALID_ARGUMENT = 2147615331, - SCE_KERNEL_ERROR_PM_ALREADY_TARGET_PWRSTATE = 2147615332, - SCE_KERNEL_ERROR_PM_CHANGE_PWRSTATE_FAILED = 2147615333, - SCE_KERNEL_ERROR_PM_CANNOT_CHANGE_DEVPWR_STATE = 2147615334, - SCE_KERNEL_ERROR_PM_NO_SUPPORT_DEVPWR_STATE = 2147615335, - SCE_KERNEL_ERROR_DMAC_REQUEST_FAILED = 2147615420, - SCE_KERNEL_ERROR_DMAC_REQUEST_DENIED = 2147615421, - SCE_KERNEL_ERROR_DMAC_OP_QUEUED = 2147615422, - SCE_KERNEL_ERROR_DMAC_OP_NOT_QUEUED = 2147615423, - SCE_KERNEL_ERROR_DMAC_OP_RUNNING = 2147615424, - SCE_KERNEL_ERROR_DMAC_OP_NOT_ASSIGNED = 2147615425, - SCE_KERNEL_ERROR_DMAC_OP_TIMEOUT = 2147615426, - SCE_KERNEL_ERROR_DMAC_OP_FREED = 2147615427, - SCE_KERNEL_ERROR_DMAC_OP_USED = 2147615428, - SCE_KERNEL_ERROR_DMAC_OP_EMPTY = 2147615429, - SCE_KERNEL_ERROR_DMAC_OP_ABORTED = 2147615430, - SCE_KERNEL_ERROR_DMAC_OP_ERROR = 2147615431, - SCE_KERNEL_ERROR_DMAC_CHANNEL_RESERVED = 2147615432, - SCE_KERNEL_ERROR_DMAC_CHANNEL_EXCLUDED = 2147615433, - SCE_KERNEL_ERROR_DMAC_PRIVILEGE_ADDRESS = 2147615434, - SCE_KERNEL_ERROR_DMAC_NO_ENOUGHSPACE = 2147615435, - SCE_KERNEL_ERROR_DMAC_CHANNEL_NOT_ASSIGNED = 2147615436, - SCE_KERNEL_ERROR_DMAC_CHILD_OPERATION = 2147615437, - SCE_KERNEL_ERROR_DMAC_TOO_MUCH_SIZE = 2147615438, - SCE_KERNEL_ERROR_DMAC_INVALID_ARGUMENT = 2147615439, - SCE_KERNEL_ERROR_MFILE = 2147615520, - SCE_KERNEL_ERROR_NODEV = 2147615521, - SCE_KERNEL_ERROR_XDEV = 2147615522, - SCE_KERNEL_ERROR_BADF = 2147615523, - SCE_KERNEL_ERROR_INVAL = 2147615524, - SCE_KERNEL_ERROR_UNSUP = 2147615525, - SCE_KERNEL_ERROR_ALIAS_USED = 2147615526, - SCE_KERNEL_ERROR_CANNOT_MOUNT = 2147615527, - SCE_KERNEL_ERROR_DRIVER_DELETED = 2147615528, - SCE_KERNEL_ERROR_ASYNC_BUSY = 2147615529, - SCE_KERNEL_ERROR_NOASYNC = 2147615530, - SCE_KERNEL_ERROR_REGDEV = 2147615531, - SCE_KERNEL_ERROR_NOCWD = 2147615532, - SCE_KERNEL_ERROR_NAMETOOLONG = 2147615533, - SCE_KERNEL_ERROR_NXIO = 2147615720, - SCE_KERNEL_ERROR_IO = 2147615721, - SCE_KERNEL_ERROR_NOMEM = 2147615722, - SCE_KERNEL_ERROR_STDIO_NOT_OPENED = 2147615723, - SCE_KERNEL_ERROR_CACHE_ALIGNMENT = 2147615820, - SCE_KERNEL_ERROR_ERRORMAX = 2147615821, - _, +pub const PspKernelErrorCodes = extern enum(c_int) { + Ok = 0, + Error = 2147614721, + Notimp = 2147614722, + IllegalExpcode = 2147614770, + ExpHandlerNoUse = 2147614771, + ExpHandlerUsed = 2147614772, + SycallTableNoUsed = 2147614773, + SycallTableUsed = 2147614774, + IllegalSyscalltable = 2147614775, + IllegalPrimarySyscallNumber = 2147614776, + PrimarySyscallNumberInUse = 2147614777, + IllegalContext = 2147614820, + IllegalIntrCode = 2147614821, + Cpudi = 2147614822, + FoundHandler = 2147614823, + NotFoundHandler = 2147614824, + IllegalIntrLevel = 2147614825, + IllegalAddress = 2147614826, + IllegalIntrParam = 2147614827, + IllegalStackAddress = 2147614828, + AlreadyStackSet = 2147614829, + NoTimer = 2147614870, + IllegalTimerid = 2147614871, + IllegalSource = 2147614872, + IllegalPrescale = 2147614873, + TimeBusy = 2147614874, + TimerNotSetup = 2147614875, + TimerNotInUse = 2147614876, + UnitUsed = 2147614880, + UnitNoUse = 2147614881, + NoRomDir = 2147614882, + IdTypeXxist = 2147614920, + IdTypeNotExist = 2147614921, + IdTypeNotEmpty = 2147614922, + UnknownUid = 2147614923, + UnmatchUidType = 2147614924, + IdNotExist = 2147614925, + NotFoundUidFunc = 2147614926, + UidAlreadyHolder = 2147614927, + UidNotHolder = 2147614928, + IllegalPerm = 2147614929, + IllegalArgument = 2147614930, + IllegalAddr = 2147614931, + OutOfRange = 2147614932, + MemRangeOverlap = 2147614933, + IllegalPartition = 2147614934, + PartitionInUse = 2147614935, + IllegalMemblockType = 2147614936, + MemblockAllocFailed = 2147614937, + MemblockResizeLocked = 2147614938, + MemblockResizeFailed = 2147614939, + HeapblockAllocFailed = 2147614940, + HeapAllocFailed = 2147614941, + IllegalChunkId = 2147614942, + Nochunk = 2147614943, + NoFreechunk = 2147614944, + Linkerr = 2147615020, + IllegalObject = 2147615021, + UnknownModule = 2147615022, + Nofile = 2147615023, + Fileerr = 2147615024, + Meminuse = 2147615025, + PartitionMismatch = 2147615026, + AlreadyStarted = 2147615027, + NotStarted = 2147615028, + AlreadyStopped = 2147615029, + CanNotStop = 2147615030, + NotStopped = 2147615031, + NotRemovable = 2147615032, + ExclusiveLoad = 2147615033, + LibraryNotYetLinked = 2147615034, + LibraryFound = 2147615035, + LibraryNotFound = 2147615036, + IllegalLibrary = 2147615037, + LibraryInUse = 2147615038, + AlreadyStopping = 2147615039, + IllegalOffset = 2147615040, + IllegalPosition = 2147615041, + IllegalAccess = 2147615042, + ModuleMgrBusy = 2147615043, + IllegalFlag = 2147615044, + CannotGetModulelist = 2147615045, + ProhibitLoadmoduleDevice = 2147615046, + ProhibitLoadexecDevice = 2147615047, + UnsupportedPrxType = 2147615048, + IllegalPermCall = 2147615049, + CannotGetModuleInformation = 2147615050, + IllegalLoadexecBuffer = 2147615051, + IllegalLoadexecFilename = 2147615052, + NoExitCallback = 2147615053, + NoMemory = 2147615120, + IllegalAttr = 2147615121, + IllegalEntry = 2147615122, + IllegalPriority = 2147615123, + IllegalStackSize = 2147615124, + IllegalMode = 2147615125, + IllegalMask = 2147615126, + IllegalThid = 2147615127, + UnknownThid = 2147615128, + UnknownSemid = 2147615129, + UnknownEvfid = 2147615130, + UnknownMbxid = 2147615131, + UnknownVplid = 2147615132, + UnknownFplid = 2147615133, + UnknownMppid = 2147615134, + UnknownAlmid = 2147615135, + UnknownTeid = 2147615136, + UnknownCbid = 2147615137, + Dormant = 2147615138, + Suspend = 2147615139, + NotDormant = 2147615140, + NotSuspend = 2147615141, + NotWait = 2147615142, + CanNotWait = 2147615143, + WaitTimeout = 2147615144, + WaitCancel = 2147615145, + ReleaseWait = 2147615146, + NotifyCallback = 2147615147, + ThreadTerminated = 2147615148, + SemaZero = 2147615149, + SemaOvf = 2147615150, + EvfCond = 2147615151, + EvfMulti = 2147615152, + EvfIlpat = 2147615153, + MboxNomsg = 2147615154, + MppFull = 2147615155, + MppEmpty = 2147615156, + WaitDelete = 2147615157, + IllegalMemblock = 2147615158, + IllegalMemsize = 2147615159, + IllegalSpadaddr = 2147615160, + SpadInUse = 2147615161, + SpadNotInUse = 2147615162, + IllegalType = 2147615163, + IllegalSize = 2147615164, + IllegalCount = 2147615165, + UnknownVtid = 2147615166, + IllegalVtid = 2147615167, + IllegalKtlsid = 2147615168, + KtlsFull = 2147615169, + KtlsBusy = 2147615170, + PmInvalidPriority = 2147615320, + PmInvalidDevname = 2147615321, + PmUnknownDevname = 2147615322, + PmPminfoRegistered = 2147615323, + PmPminfoUnregistered = 2147615324, + PmInvalidMajorState = 2147615325, + PmInvalidRequest = 2147615326, + PmUnknownRequest = 2147615327, + PmInvalidUnit = 2147615328, + PmCannotCancel = 2147615329, + PmInvalidPminfo = 2147615330, + PmInvalidArgument = 2147615331, + PmAlreadyTargetPwrstate = 2147615332, + PmChangePwrstateFailed = 2147615333, + PmCannotChangeDevpwrState = 2147615334, + PmNoSupportDevpwrState = 2147615335, + DmacRequestFailed = 2147615420, + DmacRequestDenied = 2147615421, + DmacOpQueued = 2147615422, + DmacOpNotQueued = 2147615423, + DmacOpRunning = 2147615424, + DmacOpNotAssigned = 2147615425, + DmacOpTimeout = 2147615426, + DmacOpFreed = 2147615427, + DmacOpUsed = 2147615428, + DmacOpEmpty = 2147615429, + DmacOpAborted = 2147615430, + DmacOpError = 2147615431, + DmacChannelReserved = 2147615432, + DmacChannelExcluded = 2147615433, + DmacPrivilegeAddress = 2147615434, + DmacNotEnoughspace = 2147615435, + DmacChannelNotAssigned = 2147615436, + DmacChildOperation = 2147615437, + DmacTooMuchSize = 2147615438, + DmacInvalidArgument = 2147615439, + Mfile = 2147615520, + Nodev = 2147615521, + Xdev = 2147615522, + Badf = 2147615523, + Inval = 2147615524, + Unsup = 2147615525, + AliasUsed = 2147615526, + CannotMount = 2147615527, + DriverDeleted = 2147615528, + AsyncBusy = 2147615529, + Noasync = 2147615530, + Regdev = 2147615531, + Nocwd = 2147615532, + Nametoolong = 2147615533, + Nxio = 2147615720, + Io = 2147615721, + Nomem = 2147615722, + StdioNotOpened = 2147615723, + CacheAlignment = 2147615820, + Errormax = 2147615821, }; -pub const PspKernelErrorCodes = enum_PspKernelErrorCodes; diff --git a/src/psp/sdk/psploadexec.zig b/src/psp/sdk/psploadexec.zig index 2801782..adb1f57 100644 --- a/src/psp/sdk/psploadexec.zig +++ b/src/psp/sdk/psploadexec.zig @@ -1,13 +1,38 @@ usingnamespace @import("psptypes.zig"); -pub extern fn sceKernelRegisterExitCallback(cbid: c_int) c_int; -pub extern fn sceKernelExitGame() void; -pub const struct_SceKernelLoadExecParam = extern struct { +pub const SceKernelLoadExecParam = extern struct { size: SceSize, args: SceSize, argp: ?*c_void, key: [*c]const u8, }; -pub extern fn sceKernelLoadExec(file: [*c]const u8, param: [*c]struct_SceKernelLoadExecParam) c_int; -pub const SceKernelLoadExecParam = struct_SceKernelLoadExecParam; +// Register callback +// +// By installing the exit callback the home button becomes active. However if sceKernelExitGame +// is not called in the callback it is likely that the psp will just crash. +// +// @par Example: +// @code +// int exit_callback(void) { sceKernelExitGame(); } +// +// cbid = sceKernelCreateCallback("ExitCallback", exit_callback, NULL); +// sceKernelRegisterExitCallback(cbid); +// @endcode +// +// @param cbid Callback id +// @return < 0 on error +pub extern fn sceKernelRegisterExitCallback(cbid: c_int) c_int; + +// Execute a new game executable, limited when not running in kernel mode. +// +// @param file - The file to execute. +// @param param - Pointer to a ::SceKernelLoadExecParam structure, or NULL. +// +// @return < 0 on error, probably. +pub extern fn sceKernelLoadExec(file: []const u8, param: ?*SceKernelLoadExecParam) c_int; + +// Exit game and go back to the PSP browser. +// +// @note You need to be in a thread in order for this function to work +pub extern fn sceKernelExitGame() void; diff --git a/src/psp/sdk/pspmodulemgr.zig b/src/psp/sdk/pspmodulemgr.zig index 5a13da8..8ef989f 100644 --- a/src/psp/sdk/pspmodulemgr.zig +++ b/src/psp/sdk/pspmodulemgr.zig @@ -1,6 +1,6 @@ usingnamespace @import("psptypes.zig"); -pub const struct_SceKernelLMOption = extern struct { +pub const SceKernelLMOption = extern struct { size: SceSize, mpidtext: SceUID, mpiddata: SceUID, @@ -9,25 +9,16 @@ pub const struct_SceKernelLMOption = extern struct { access: u8, creserved: [2]u8, }; -pub const SceKernelLMOption = struct_SceKernelLMOption; -pub const struct_SceKernelSMOption = extern struct { + +pub const SceKernelSMOption = extern struct { size: SceSize, mpidstack: SceUID, stacksize: SceSize, priority: c_int, attribute: c_uint, }; -pub const SceKernelSMOption = struct_SceKernelSMOption; -pub extern fn sceKernelLoadModule(path: [*c]const u8, flags: c_int, option: [*c]SceKernelLMOption) SceUID; -pub extern fn sceKernelLoadModuleMs(path: [*c]const u8, flags: c_int, option: [*c]SceKernelLMOption) SceUID; -pub extern fn sceKernelLoadModuleByID(fid: SceUID, flags: c_int, option: [*c]SceKernelLMOption) SceUID; -pub extern fn sceKernelLoadModuleBufferUsbWlan(bufsize: SceSize, buf: ?*c_void, flags: c_int, option: [*c]SceKernelLMOption) SceUID; -pub extern fn sceKernelStartModule(modid: SceUID, argsize: SceSize, argp: ?*c_void, status: [*c]c_int, option: [*c]SceKernelSMOption) c_int; -pub extern fn sceKernelStopModule(modid: SceUID, argsize: SceSize, argp: ?*c_void, status: [*c]c_int, option: [*c]SceKernelSMOption) c_int; -pub extern fn sceKernelUnloadModule(modid: SceUID) c_int; -pub extern fn sceKernelSelfStopUnloadModule(unknown: c_int, argsize: SceSize, argp: ?*c_void) c_int; -pub extern fn sceKernelStopUnloadSelfModule(argsize: SceSize, argp: ?*c_void, status: [*c]c_int, option: [*c]SceKernelSMOption) c_int; -pub const struct_SceKernelModuleInfo = extern struct { + +pub const SceKernelModuleInfo = extern struct { size: SceSize, nsegment: u8, reserved: [3]u8, @@ -43,9 +34,128 @@ pub const struct_SceKernelModuleInfo = extern struct { version: [2]u8, name: [28]u8, }; -pub const SceKernelModuleInfo = struct_SceKernelModuleInfo; -pub extern fn sceKernelQueryModuleInfo(modid: SceUID, info: [*c]SceKernelModuleInfo) c_int; -pub extern fn sceKernelGetModuleIdList(readbuf: [*c]SceUID, readbufsize: c_int, idcount: [*c]c_int) c_int; pub const PSP_MEMORY_PARTITION_KERNEL = 1; pub const PSP_MEMORY_PARTITION_USER = 2; + +// Load a module. +// @note This function restricts where it can load from (such as from flash0) +// unless you call it in kernel mode. It also must be called from a thread. +// +// @param path - The path to the module to load. +// @param flags - Unused, always 0 . +// @param option - Pointer to a mod_param_t structure. Can be NULL. +// +// @return The UID of the loaded module on success, otherwise one of ::PspKernelErrorCodes. +pub extern fn sceKernelLoadModule(path: []const u8, flags: c_int, option: *SceKernelLMOption) SceUID; + + +// Load a module from MS. +// @note This function restricts what it can load, e.g. it wont load plain executables. +// +// @param path - The path to the module to load. +// @param flags - Unused, set to 0. +// @param option - Pointer to a mod_param_t structure. Can be NULL. +// +// @return The UID of the loaded module on success, otherwise one of ::PspKernelErrorCodes. +pub extern fn sceKernelLoadModuleMs(path: []const u8, flags: c_int, option: *SceKernelLMOption) SceUID; + + +// Load a module from the given file UID. +// +// @param fid - The module's file UID. +// @param flags - Unused, always 0. +// @param option - Pointer to an optional ::SceKernelLMOption structure. +// +// @return The UID of the loaded module on success, otherwise one of ::PspKernelErrorCodes. +pub extern fn sceKernelLoadModuleByID(fid: SceUID, flags: c_int, option: *SceKernelLMOption) SceUID; + +// Load a module from a buffer using the USB/WLAN API. +// +// Can only be called from kernel mode, or from a thread that has attributes of 0xa0000000. +// +// @param bufsize - Size (in bytes) of the buffer pointed to by buf. +// @param buf - Pointer to a buffer containing the module to load. The buffer must reside at an +// address that is a multiple to 64 bytes. +// @param flags - Unused, always 0. +// @param option - Pointer to an optional ::SceKernelLMOption structure. +// +// @return The UID of the loaded module on success, otherwise one of ::PspKernelErrorCodes. +pub extern fn sceKernelLoadModuleBufferUsbWlan(bufsize: SceSize, buf: ?*c_void, flags: c_int, option: *SceKernelLMOption) SceUID; + +// Start a loaded module. +// +// @param modid - The ID of the module returned from LoadModule. +// @param argsize - Length of the args. +// @param argp - A pointer to the arguments to the module. +// @param status - Returns the status of the start. +// @param option - Pointer to an optional ::SceKernelSMOption structure. +// +// @return ??? on success, otherwise one of ::PspKernelErrorCodes. +pub extern fn sceKernelStartModule(modid: SceUID, argsize: SceSize, argp: ?*c_void, status: *c_int, option: *SceKernelSMOption) c_int; + +// Stop a running module. +// +// @param modid - The UID of the module to stop. +// @param argsize - The length of the arguments pointed to by argp. +// @param argp - Pointer to arguments to pass to the module's module_stop() routine. +// @param status - Return value of the module's module_stop() routine. +// @param option - Pointer to an optional ::SceKernelSMOption structure. +// +// @return ??? on success, otherwise one of ::PspKernelErrorCodes. +pub extern fn sceKernelStopModule(modid: SceUID, argsize: SceSize, argp: ?*c_void, status: *c_int, option: *SceKernelSMOption) c_int; + +// Unload a stopped module. +// +// @param modid - The UID of the module to unload. +// +// @return ??? on success, otherwise one of ::PspKernelErrorCodes. +pub extern fn sceKernelUnloadModule(modid: SceUID) c_int; + +// Stop and unload the current module. +// +// @param unknown - Unknown (I've seen 1 passed). +// @param argsize - Size (in bytes) of the arguments that will be passed to module_stop(). +// @param argp - Pointer to arguments that will be passed to module_stop(). +// +// @return ??? on success, otherwise one of ::PspKernelErrorCodes. +pub extern fn sceKernelSelfStopUnloadModule(unknown: c_int, argsize: SceSize, argp: ?*c_void) c_int; + +// Stop and unload the current module. +// +// @param argsize - Size (in bytes) of the arguments that will be passed to module_stop(). +// @param argp - Poitner to arguments that will be passed to module_stop(). +// @param status - Return value from module_stop(). +// @param option - Pointer to an optional ::SceKernelSMOption structure. +// +// @return ??? on success, otherwise one of ::PspKernelErrorCodes. +pub extern fn sceKernelStopUnloadSelfModule(argsize: SceSize, argp: ?*c_void, status: *c_int, option: *SceKernelSMOption) c_int; + +// Query the information about a loaded module from its UID. +// @note This fails on v1.0 firmware (and even it worked has a limited structure) +// so if you want to be compatible with both 1.5 and 1.0 (and you are running in +// kernel mode) then call this function first then ::pspSdkQueryModuleInfoV1 +// if it fails, or make separate v1 and v1.5+ builds. +// +// @param modid - The UID of the loaded module. +// @param info - Pointer to a ::SceKernelModuleInfo structure. +// +// @return 0 on success, otherwise one of ::PspKernelErrorCodes. +pub extern fn sceKernelQueryModuleInfo(modid: SceUID, info: *SceKernelModuleInfo) c_int; + +// Get a list of module IDs. NOTE: This is only available on 1.5 firmware +// and above. For V1 use ::pspSdkGetModuleIdList. +// +// @param readbuf - Buffer to store the module list. +// @param readbufsize - Number of elements in the readbuffer. +// @param idcount - Returns the number of module ids +// +// @return >= 0 on success +pub extern fn sceKernelGetModuleIdList(readbuf: *SceUID, readbufsize: c_int, idcount: *c_int) c_int; + +// Get the ID of the module occupying the address +// +// @param moduleAddr - A pointer to the module +// +// @return >= 0 on success, otherwise one of ::PspKernelErrorCodes +pub extern fn sceKernelGetModuleIdByAddress(moduleAddr: ?*c_void) c_int; diff --git a/src/psp/sdk/pspmp3.zig b/src/psp/sdk/pspmp3.zig index 9cafb6e..be5e498 100644 --- a/src/psp/sdk/pspmp3.zig +++ b/src/psp/sdk/pspmp3.zig @@ -1,6 +1,6 @@ usingnamespace @import("psptypes.zig"); -pub const struct_SceMp3InitArg = extern struct { +pub const SceMp3InitArg = extern struct { mp3StreamStart: SceUInt32, unk1: SceUInt32, mp3StreamEnd: SceUInt32, @@ -10,21 +10,186 @@ pub const struct_SceMp3InitArg = extern struct { pcmBuf: ?*SceVoid, pcmBufSize: SceInt32, }; -pub const SceMp3InitArg = struct_SceMp3InitArg; -pub extern fn sceMp3ReserveMp3Handle(args: [*c]SceMp3InitArg) SceInt32; + +// sceMp3ReserveMp3Handle +// +// @param args - Pointer to SceMp3InitArg structure +// +// @return sceMp3 handle on success, < 0 on error. +pub extern fn sceMp3ReserveMp3Handle(args: *SceMp3InitArg) SceInt32; +pub fn mp3ReserveMp3Handle(args: *SceMp3InitArg) !SceInt32 { + var res = sceMp3ReserveMp3Handle(args); + if(res < 0){ + return error.Unexpected; + } + return res; +} + +// sceMp3ReleaseMp3Handle +// +// @param handle - sceMp3 handle +// +// @return 0 if success, < 0 on error. pub extern fn sceMp3ReleaseMp3Handle(handle: SceInt32) SceInt32; -pub extern fn sceMp3InitResource(...) SceInt32; -pub extern fn sceMp3TermResource(...) SceInt32; +pub fn mp3ReleaseMp3Handle(handle: SceInt32) !void { + var res = sceMp3ReleaseMp3Handle(handle); + if(res < 0){ + return error.Unexpected; + } +} + +// sceMp3InitResource +// +// @return 0 if success, < 0 on error. +pub extern fn sceMp3InitResource() SceInt32; +pub fn mp3InitResource() !void { + var res = sceMp3InitResource(); + if(res < 0){ + return error.Unexpected; + } +} + +// sceMp3TermResource +// +// @return 0 if success, < 0 on error. +pub extern fn sceMp3TermResource() SceInt32; +pub fn mp3TermResource() !void { + var res = sceMp3TermResource(); + if(res < 0){ + return error.Unexpected; + } +} + +// sceMp3Init +// +// @param handle - sceMp3 handle +// +// @return 0 if success, < 0 on error. pub extern fn sceMp3Init(handle: SceInt32) SceInt32; -pub extern fn sceMp3Decode(handle: SceInt32, dst: [*c][*c]SceShort16) SceInt32; -pub extern fn sceMp3GetInfoToAddStreamData(handle: SceInt32, dst: [*c][*c]SceUChar8, towrite: [*c]SceInt32, srcpos: [*c]SceInt32) SceInt32; +pub fn mp3Init(handle: SceInt32) !void { + var res = sceMp3Init(handle); + if(res < 0){ + return error.Unexpected; + } +} + +// sceMp3Decode +// +// @param handle - sceMp3 handle +// @param dst - Pointer to destination pcm samples buffer +// +// @return number of bytes in decoded pcm buffer, < 0 on error. +pub extern fn sceMp3Decode(handle: SceInt32, dst: *[]SceShort16) SceInt32; +pub fn mp3Decode(handle: SceInt32, dst: *[]SceShort16) !i32 { + var res = sceMp3Decode(handle, dst); + if(res < 0){ + return error.Unexpected; + } + return res; +} + +// sceMp3GetInfoToAddStreamData +// +// @param handle - sceMp3 handle +// @param dst - Pointer to stream data buffer +// @param towrite - Space remaining in stream data buffer +// @param srcpos - Position in source stream to start reading from +// +// @return 0 if success, < 0 on error. +pub extern fn sceMp3GetInfoToAddStreamData(handle: SceInt32, dst: *[]SceUChar8, towrite: *SceInt32, srcpos: *SceInt32) SceInt32; +pub fn mp3GetInfoToAddStreamData(handle: SceInt32, dst: *[]SceUChar8, towrite: *SceInt32, srcpos: *SceInt32) !void { + var res = sceMp3GetInfoToAddStreamData(handle, dst, towrite, srcpos); + if(res < 0){ + return error.Unexpected; + } +} + +// sceMp3NotifyAddStreamData +// +// @param handle - sceMp3 handle +// @param size - number of bytes added to the stream data buffer +// +// @return 0 if success, < 0 on error. pub extern fn sceMp3NotifyAddStreamData(handle: SceInt32, size: SceInt32) SceInt32; +pub fn mp3NotifyAddStreamData(handle: SceInt32, size: SceInt32) !void { + var res = sceMp3NotifyAddStreamData(handle, size); + if(res < 0){ + return error.Unexpected; + } +} + +// sceMp3CheckStreamDataNeeded +// +// @param handle - sceMp3 handle +// +// @return 1 if more stream data is needed, < 0 on error. pub extern fn sceMp3CheckStreamDataNeeded(handle: SceInt32) SceInt32; + +// sceMp3SetLoopNum +// +// @param handle - sceMp3 handle +// @param loop - Number of loops +// +// @return 0 if success, < 0 on error. pub extern fn sceMp3SetLoopNum(handle: SceInt32, loop: SceInt32) SceInt32; +pub fn mp3SetLoopNum(handle: SceInt32, loop: SceInt32) !void { + var res = sceMp3SetLoopNum(handle, loop); + if(res < 0){ + return error.Unexpected; + } +} + +// sceMp3GetLoopNum +// +// @param handle - sceMp3 handle +// +// @return Number of loops pub extern fn sceMp3GetLoopNum(handle: SceInt32) SceInt32; + +// sceMp3GetSumDecodedSample +// +// @param handle - sceMp3 handle +// +// @return Number of decoded samples pub extern fn sceMp3GetSumDecodedSample(handle: SceInt32) SceInt32; + +// sceMp3GetMaxOutputSample +// +// @param handle - sceMp3 handle +// +// @return Number of max samples to output pub extern fn sceMp3GetMaxOutputSample(handle: SceInt32) SceInt32; + +// sceMp3GetSamplingRate +// +// @param handle - sceMp3 handle +// +// @return Sampling rate of the mp3 pub extern fn sceMp3GetSamplingRate(handle: SceInt32) SceInt32; + +// sceMp3GetBitRate +// +// @param handle - sceMp3 handle +// +// @return Bitrate of the mp3 pub extern fn sceMp3GetBitRate(handle: SceInt32) SceInt32; + +// sceMp3GetMp3ChannelNum +// +// @param handle - sceMp3 handle +// +// @return Number of channels of the mp3 pub extern fn sceMp3GetMp3ChannelNum(handle: SceInt32) SceInt32; + +// sceMp3ResetPlayPosition +// +// @param handle - sceMp3 handle +// +// @return < 0 on error pub extern fn sceMp3ResetPlayPosition(handle: SceInt32) SceInt32; +pub fn mp3ResetPlayPosition(handle: SceInt32) !void { + var res = sceMp3ResetPlayPosition(handle); + if(res < 0){ + return error.Unexpected; + } +} diff --git a/src/psp/sdk/pspmpeg.zig b/src/psp/sdk/pspmpeg.zig index 170336c..84f1e14 100644 --- a/src/psp/sdk/pspmpeg.zig +++ b/src/psp/sdk/pspmpeg.zig @@ -1,13 +1,13 @@ usingnamespace @import("psptypes.zig"); -pub const struct_SceMpegLLI = extern struct { +pub const SceMpegLLI = extern struct { pSrc: ScePVoid, pDst: ScePVoid, Next: ScePVoid, iSize: SceInt32, }; -pub const SceMpegLLI = struct_SceMpegLLI; -pub const struct_SceMpegYCrCbBuffer = extern struct { + +pub const SceMpegYCrCbBuffer = extern struct { iFrameBufferHeight16: SceInt32, iFrameBufferWidth16: SceInt32, iUnknown: SceInt32, @@ -23,15 +23,12 @@ pub const struct_SceMpegYCrCbBuffer = extern struct { iFrameBufferWidth: SceInt32, iUnknown3: [11]SceInt32, }; -pub const SceMpegYCrCbBuffer = struct_SceMpegYCrCbBuffer; -pub extern fn sceMpegBaseYCrCbCopyVme(YUVBuffer: ScePVoid, Buffer: [*c]SceInt32, Type: SceInt32) SceInt32; -pub extern fn sceMpegBaseCscInit(width: SceInt32) SceInt32; -pub extern fn sceMpegBaseCscVme(pRGBbuffer: ScePVoid, pRGBbuffer2: ScePVoid, width: SceInt32, pYCrCbBuffer: [*c]SceMpegYCrCbBuffer) SceInt32; -pub extern fn sceMpegbase_BEA18F91(pLLI: [*c]SceMpegLLI) SceInt32; + pub const SceMpeg = ScePVoid; pub const SceMpegStream = SceVoid; pub const sceMpegRingbufferCB = ?fn (ScePVoid, SceInt32, ScePVoid) callconv(.C) SceInt32; -pub const struct_SceMpegRingbuffer = extern struct { + +pub const SceMpegRingbuffer = extern struct { iPackets: SceInt32, iUnk0: SceUInt32, iUnk1: SceUInt32, @@ -44,8 +41,8 @@ pub const struct_SceMpegRingbuffer = extern struct { iUnk5: SceUInt32, pSceMpeg: SceMpeg, }; -pub const SceMpegRingbuffer = struct_SceMpegRingbuffer; -pub const struct_SceMpegAu = extern struct { + +pub const SceMpegAu = extern struct { iPtsMSB: SceUInt32, iPts: SceUInt32, iDtsMSB: SceUInt32, @@ -53,34 +50,210 @@ pub const struct_SceMpegAu = extern struct { iEsBuffer: SceUInt32, iAuSize: SceUInt32, }; -pub const SceMpegAu = struct_SceMpegAu; -pub const struct_SceMpegAvcMode = extern struct { + +pub const SceMpegAvcMode = extern struct { iUnk0: SceInt32, iPixelFormat: SceInt32, }; -pub const SceMpegAvcMode = struct_SceMpegAvcMode; -pub extern fn sceMpegInit(...) SceInt32; -pub extern fn sceMpegFinish(...) SceVoid; + +//MpegBase +pub extern fn sceMpegBaseYCrCbCopyVme(YUVBuffer: ScePVoid, Buffer: [*c]SceInt32, Type: SceInt32) SceInt32; +pub extern fn sceMpegBaseCscInit(width: SceInt32) SceInt32; +pub extern fn sceMpegBaseCscVme(pRGBbuffer: ScePVoid, pRGBbuffer2: ScePVoid, width: SceInt32, pYCrCbBuffer: [*c]SceMpegYCrCbBuffer) SceInt32; +pub extern fn sceMpegbase_BEA18F91(pLLI: [*c]SceMpegLLI) SceInt32; + + +// sceMpegInit +// +// @return 0 if success. +pub extern fn sceMpegInit() SceInt32; + +//sceMpegFinish +pub extern fn sceMpegFinish() SceVoid; + +// sceMpegRingbufferQueryMemSize +// +// @param iPackets - number of packets in the ringbuffer +// +// @return < 0 if error else ringbuffer data size. pub extern fn sceMpegRingbufferQueryMemSize(iPackets: SceInt32) SceInt32; + + +// sceMpegRingbufferConstruct +// +// @param Ringbuffer - pointer to a sceMpegRingbuffer struct +// @param iPackets - number of packets in the ringbuffer +// @param pData - pointer to allocated memory +// @param iSize - size of allocated memory, shoud be sceMpegRingbufferQueryMemSize(iPackets) +// @param Callback - ringbuffer callback +// @param pCBparam - param passed to callback +// +// @return 0 if success. pub extern fn sceMpegRingbufferConstruct(Ringbuffer: [*c]SceMpegRingbuffer, iPackets: SceInt32, pData: ScePVoid, iSize: SceInt32, Callback: sceMpegRingbufferCB, pCBparam: ScePVoid) SceInt32; + +// sceMpegRingbufferDestruct +// +// @param Ringbuffer - pointer to a sceMpegRingbuffer struct pub extern fn sceMpegRingbufferDestruct(Ringbuffer: [*c]SceMpegRingbuffer) SceVoid; + +// sceMpegQueryMemSize +// +// @param Ringbuffer - pointer to a sceMpegRingbuffer struct +// +// @return < 0 if error else number of free packets in the ringbuffer. pub extern fn sceMpegRingbufferAvailableSize(Ringbuffer: [*c]SceMpegRingbuffer) SceInt32; + +// sceMpegRingbufferPut +// +// @param Ringbuffer - pointer to a sceMpegRingbuffer struct +// @param iNumPackets - num packets to put into the ringbuffer +// @param iAvailable - free packets in the ringbuffer, should be sceMpegRingbufferAvailableSize() +// +// @return < 0 if error else number of packets. pub extern fn sceMpegRingbufferPut(Ringbuffer: [*c]SceMpegRingbuffer, iNumPackets: SceInt32, iAvailable: SceInt32) SceInt32; + +// sceMpegQueryMemSize +// +// @param iUnk - Unknown, set to 0 +// +// @return < 0 if error else decoder data size. pub extern fn sceMpegQueryMemSize(iUnk: c_int) SceInt32; + +// sceMpegCreate +// +// @param Mpeg - will be filled +// @param pData - pointer to allocated memory of size = sceMpegQueryMemSize() +// @param iSize - size of data, should be = sceMpegQueryMemSize() +// @param Ringbuffer - a ringbuffer +// @param iFrameWidth - display buffer width, set to 512 if writing to framebuffer +// @param iUnk1 - unknown, set to 0 +// @param iUnk2 - unknown, set to 0 +// +// @return 0 if success. pub extern fn sceMpegCreate(Mpeg: [*c]SceMpeg, pData: ScePVoid, iSize: SceInt32, Ringbuffer: [*c]SceMpegRingbuffer, iFrameWidth: SceInt32, iUnk1: SceInt32, iUnk2: SceInt32) SceInt32; + +// sceMpegDelete +// +// @param Mpeg - SceMpeg handle pub extern fn sceMpegDelete(Mpeg: [*c]SceMpeg) SceVoid; + +// sceMpegQueryStreamOffset +// +// @param Mpeg - SceMpeg handle +// @param pBuffer - pointer to file header +// @param iOffset - will contain stream offset in bytes, usually 2048 +// +// @return 0 if success. pub extern fn sceMpegQueryStreamOffset(Mpeg: [*c]SceMpeg, pBuffer: ScePVoid, iOffset: [*c]SceInt32) SceInt32; + +// sceMpegQueryStreamSize +// +// @param pBuffer - pointer to file header +// @param iSize - will contain stream size in bytes +// +// @return 0 if success. pub extern fn sceMpegQueryStreamSize(pBuffer: ScePVoid, iSize: [*c]SceInt32) SceInt32; + +// sceMpegRegistStream +// +// @param Mpeg - SceMpeg handle +// @param iStreamID - stream id, 0 for video, 1 for audio +// @param iUnk - unknown, set to 0 +// +// @return 0 if error. pub extern fn sceMpegRegistStream(Mpeg: [*c]SceMpeg, iStreamID: SceInt32, iUnk: SceInt32) ?*SceMpegStream; + +// sceMpegUnRegistStream +// +// @param Mpeg - SceMpeg handle +// @param pStream - pointer to stream pub extern fn sceMpegUnRegistStream(Mpeg: SceMpeg, pStream: ?*SceMpegStream) SceVoid; + +// sceMpegFlushAllStreams +// +// @return 0 if success. pub extern fn sceMpegFlushAllStream(Mpeg: [*c]SceMpeg) SceInt32; + +// sceMpegMallocAvcEsBuf +// +// @return 0 if error else pointer to buffer. pub extern fn sceMpegMallocAvcEsBuf(Mpeg: [*c]SceMpeg) ScePVoid; + +// sceMpegFreeAvcEsBuf pub extern fn sceMpegFreeAvcEsBuf(Mpeg: [*c]SceMpeg, pBuf: ScePVoid) SceVoid; + +// sceMpegQueryAtracEsSize +// +// @param Mpeg - SceMpeg handle +// @param iEsSize - will contain size of Es +// @param iOutSize - will contain size of decoded data +// +// @return 0 if success. pub extern fn sceMpegQueryAtracEsSize(Mpeg: [*c]SceMpeg, iEsSize: [*c]SceInt32, iOutSize: [*c]SceInt32) SceInt32; + +// sceMpegInitAu +// +// @param Mpeg - SceMpeg handle +// @param pEsBuffer - prevously allocated Es buffer +// @param pAu - will contain pointer to Au +// +// @return 0 if success. pub extern fn sceMpegInitAu(Mpeg: [*c]SceMpeg, pEsBuffer: ScePVoid, pAu: [*c]SceMpegAu) SceInt32; + +// sceMpegGetAvcAu +// +// @param Mpeg - SceMpeg handle +// @param pStream - associated stream +// @param pAu - will contain pointer to Au +// @param iUnk - unknown +// +// @return 0 if success. pub extern fn sceMpegGetAvcAu(Mpeg: [*c]SceMpeg, pStream: ?*SceMpegStream, pAu: [*c]SceMpegAu, iUnk: [*c]SceInt32) SceInt32; + +// sceMpegAvcDecodeMode +// +// @param Mpeg - SceMpeg handle +// @param pMode - pointer to SceMpegAvcMode struct defining the decode mode (pixelformat) +// @return 0 if success. pub extern fn sceMpegAvcDecodeMode(Mpeg: [*c]SceMpeg, pMode: [*c]SceMpegAvcMode) SceInt32; + +// sceMpegAvcDecode +// +// @param Mpeg - SceMpeg handle +// @param pAu - video Au +// @param iFrameWidth - output buffer width, set to 512 if writing to framebuffer +// @param pBuffer - buffer that will contain the decoded frame +// @param iInit - will be set to 0 on first call, then 1 +// +// @return 0 if success. pub extern fn sceMpegAvcDecode(Mpeg: [*c]SceMpeg, pAu: [*c]SceMpegAu, iFrameWidth: SceInt32, pBuffer: ScePVoid, iInit: [*c]SceInt32) SceInt32; + +// sceMpegAvcDecodeStop +// +// @param Mpeg - SceMpeg handle +// @param iFrameWidth - output buffer width, set to 512 if writing to framebuffer +// @param pBuffer - buffer that will contain the decoded frame +// @param iStatus - frame number +// +// @return 0 if success. pub extern fn sceMpegAvcDecodeStop(Mpeg: [*c]SceMpeg, iFrameWidth: SceInt32, pBuffer: ScePVoid, iStatus: [*c]SceInt32) SceInt32; + +// sceMpegGetAtracAu +// +// @param Mpeg - SceMpeg handle +// @param pStream - associated stream +// @param pAu - will contain pointer to Au +// @param pUnk - unknown +// +// @return 0 if success. pub extern fn sceMpegGetAtracAu(Mpeg: [*c]SceMpeg, pStream: ?*SceMpegStream, pAu: [*c]SceMpegAu, pUnk: ScePVoid) SceInt32; + +// sceMpegAtracDecode +// +// @param Mpeg - SceMpeg handle +// @param pAu - video Au +// @param pBuffer - buffer that will contain the decoded frame +// @param iInit - set this to 1 on first call +// +// @return 0 if success. pub extern fn sceMpegAtracDecode(Mpeg: [*c]SceMpeg, pAu: [*c]SceMpegAu, pBuffer: ScePVoid, iInit: SceInt32) SceInt32; diff --git a/src/psp/sdk/pspopenpsid.zig b/src/psp/sdk/pspopenpsid.zig index 8426610..963b3e7 100644 --- a/src/psp/sdk/pspopenpsid.zig +++ b/src/psp/sdk/pspopenpsid.zig @@ -1,5 +1,5 @@ -pub const struct_PspOpenPSID = extern struct { +pub const PspOpenPSID = extern struct { data: [16]u8, }; -pub const PspOpenPSID = struct_PspOpenPSID; -pub extern fn sceOpenPSIDGetOpenPSID(openpsid: [*c]PspOpenPSID) c_int; + +pub extern fn sceOpenPSIDGetOpenPSID(openpsid: *PspOpenPSID) c_int; diff --git a/src/psp/sdk/psppower.zig b/src/psp/sdk/psppower.zig index 7a44a7d..4d239d9 100644 --- a/src/psp/sdk/psppower.zig +++ b/src/psp/sdk/psppower.zig @@ -1,51 +1,243 @@ usingnamespace @import("psptypes.zig"); +pub const PSPPowerCB = extern enum(u32){ + Battpower = 0x0000007f, + BatteryExist = 0x00000080, + BatteryLow = 0x00000100, + ACPower = 0x00001000, + Suspending = 0x00010000, + Resuming = 0x00020000, + ResumeComplete = 0x00040000, + Standby = 0x00080000, + HoldSwitch = 0x40000000, + PowerSwitch = 0x80000000, +}; + +pub const PSPPowerTick = extern enum(u32){ + All = 0, + Suspend = 1, + Display = 6 +}; + pub const powerCallback_t = ?fn (c_int, c_int) callconv(.C) void; + +// Register Power Callback Function +// +// @param slot - slot of the callback in the list, 0 to 15, pass -1 to get an auto assignment. +// @param cbid - callback id from calling sceKernelCreateCallback +// +// @return 0 on success, the slot number if -1 is passed, < 0 on error. pub extern fn scePowerRegisterCallback(slot: c_int, cbid: SceUID) c_int; +pub fn powerRegisterCallback(slot: c_int, cbid: SceUID) !i32 { + var res = scePowerRegisterCallback(slot, cbid); + if(res < 0){ + return error.Unexpected; + } + return res; +} + +// Unregister Power Callback Function +// +// @param slot - slot of the callback +// +// @return 0 on success, < 0 on error. pub extern fn scePowerUnregisterCallback(slot: c_int) c_int; +pub fn powerUnregisterCallback(slot: c_int) !void { + var res = scePowerUnregisterCallback(slot); + if(res < 0){ + return error.Unexpected; + } +} + +// Check if unit is plugged in +// +// @return 1 if plugged in, 0 if not plugged in, < 0 on error. pub extern fn scePowerIsPowerOnline() c_int; +pub fn powerIsPowerOnline() !bool { + var res = scePowerIsPowerOnline(); + if(res < 0){ + return error.Unexpected; + } + return res == 1; +} + +// Check if a battery is present +// +// @return 1 if battery present, 0 if battery not present, < 0 on error. pub extern fn scePowerIsBatteryExist() c_int; +pub fn powerIsBatteryExist() !bool { + var res = scePowerIsBatteryExist(); + if(res < 0){ + return error.Unexpected; + } + return res == 1; +} + +// Check if the battery is charging +// +// @return 1 if battery charging, 0 if battery not charging, < 0 on error. pub extern fn scePowerIsBatteryCharging() c_int; +pub fn powerIsBatteryCharging() !bool { + var res = scePowerIsBatteryCharging(); + if(res < 0){ + return error.Unexpected; + } + return res == 1; +} + +// Get the status of the battery charging pub extern fn scePowerGetBatteryChargingStatus() c_int; + + +// Check if the battery is low +// +// @return 1 if the battery is low, 0 if the battery is not low, < 0 on error. pub extern fn scePowerIsLowBattery() c_int; +pub fn powerIsLowBattery() !bool { + var res = scePowerIsLowBattery(); + if(res < 0){ + return error.Unexpected; + } + return res == 1; +} + +// Get battery life as integer percent +// +// @return Battery charge percentage (0-100), < 0 on error. pub extern fn scePowerGetBatteryLifePercent() c_int; +pub fn powerGetBatteryLifePercent() !i32 { + var res = scePowerGetBatteryLifePercent(); + if(res < 0){ + return error.Unexpected; + } + return res; +} + +// Get battery life as time +// +// @return Battery life in minutes, < 0 on error. pub extern fn scePowerGetBatteryLifeTime() c_int; +pub fn powerGetBatteryLifeTime() !i32 { + var res = scePowerGetBatteryLifeTime(); + if(res < 0){ + return error.Unexpected; + } + return res; +} + +// Get temperature of the battery pub extern fn scePowerGetBatteryTemp() c_int; -pub extern fn scePowerGetBatteryElec() c_int; + +// Get battery volt level pub extern fn scePowerGetBatteryVolt() c_int; + +// Set CPU Frequency +// @param cpufreq - new CPU frequency, valid values are 1 - 333 pub extern fn scePowerSetCpuClockFrequency(cpufreq: c_int) c_int; + +// Set Bus Frequency +// @param busfreq - new BUS frequency, valid values are 1 - 167 pub extern fn scePowerSetBusClockFrequency(busfreq: c_int) c_int; + +// Alias for scePowerGetCpuClockFrequencyInt +// @return frequency as int pub extern fn scePowerGetCpuClockFrequency() c_int; + +// Get CPU Frequency as Integer +// @return frequency as int pub extern fn scePowerGetCpuClockFrequencyInt() c_int; + +// Get CPU Frequency as Float +// @return frequency as float pub extern fn scePowerGetCpuClockFrequencyFloat() f32; + +// Alias for scePowerGetBusClockFrequencyInt +// @return frequency as int pub extern fn scePowerGetBusClockFrequency() c_int; + +// Get Bus fequency as Integer +// @return frequency as int pub extern fn scePowerGetBusClockFrequencyInt() c_int; + +// Get Bus frequency as Float +// @return frequency as float pub extern fn scePowerGetBusClockFrequencyFloat() f32; + +// Set Clock Frequencies +// +// @param pllfreq - pll frequency, valid from 19-333 +// @param cpufreq - cpu frequency, valid from 1-333 +// @param busfreq - bus frequency, valid from 1-167 +// +// and: +// +// cpufreq <= pllfreq +// busfreq*2 <= pllfreq +// pub extern fn scePowerSetClockFrequency(pllfreq: c_int, cpufreq: c_int, busfreq: c_int) c_int; + +// Lock power switch +// +// Note: if the power switch is toggled while locked +// it will fire immediately after being unlocked. +// +// @param unknown - pass 0 +// +// @return 0 on success, < 0 on error. pub extern fn scePowerLock(unknown: c_int) c_int; +pub fn powerLock(unknown: c_int) !void { + var res = scePowerLock(unknown); + if(res < 0){ + return error.Unexpected; + } +} + +// Unlock power switch +// +// @param unknown - pass 0 +// +// @return 0 on success, < 0 on error. pub extern fn scePowerUnlock(unknown: c_int) c_int; -pub extern fn scePowerTick(type: c_int) c_int; +pub fn powerUnlock(unknown: c_int) !void { + var res = scePowerUnlock(unknown); + if(res < 0){ + return error.Unexpected; + } +} + +// Generate a power tick, preventing unit from +// powering off and turning off display. +// +// @param type - Either PSP_POWER_TICK_ALL, PSP_POWER_TICK_SUSPEND or PSP_POWER_TICK_DISPLAY +// +// @return 0 on success, < 0 on error. +pub extern fn scePowerTick(typec: c_int) c_int; +pub fn powerTick(typec: PSPPowerTick) !void { + var res = scePowerTick(@enumToInt(typec)); + if(res < 0){ + return error.Unexpected; + } +} + +// Get Idle timer pub extern fn scePowerGetIdleTimer() c_int; + +// Enable Idle timer +// +// @param unknown - pass 0 pub extern fn scePowerIdleTimerEnable(unknown: c_int) c_int; + +// Disable Idle timer +// +// @param unknown - pass 0 pub extern fn scePowerIdleTimerDisable(unknown: c_int) c_int; -pub extern fn scePowerRequestStandby() c_int; -pub extern fn scePowerRequestSuspend() c_int; -pub const PSPPowerCB = extern enum(u32){ - Battpower = 0x0000007f, - BatteryExist = 0x00000080, - BatteryLow = 0x00000100, - ACPower = 0x00001000, - Suspending = 0x00010000, - Resuming = 0x00020000, - ResumeComplete = 0x00040000, - Standby = 0x00080000, - HoldSwitch = 0x40000000, - PowerSwitch = 0x80000000, -}; +// Request the PSP to go into standby +// +// @return 0 always +pub extern fn scePowerRequestStandby() c_int; -pub const PSPPowerTick = extern enum(u32){ - All = 0, - Suspend = 1, - Display = 6 -}; +// Request the PSP to go into suspend +// +// @return 0 always +pub extern fn scePowerRequestSuspend() c_int; diff --git a/src/psp/sdk/pspreg.zig b/src/psp/sdk/pspreg.zig index 8f59d68..ec951c9 100644 --- a/src/psp/sdk/pspreg.zig +++ b/src/psp/sdk/pspreg.zig @@ -1,36 +1,257 @@ usingnamespace @import("psptypes.zig"); -pub const enum_RegKeyTypes = extern enum(c_int) { +pub const RegKeyTypes = extern enum(c_int) { REG_TYPE_DIR = 1, REG_TYPE_INT = 2, REG_TYPE_STR = 3, REG_TYPE_BIN = 4, _, }; -pub const REGHANDLE = c_uint; -pub const struct_RegParam = extern struct { +pub const RegHandle = c_uint; +pub const RegParam = extern struct { regtype: c_uint, name: [256]u8, namelen: c_uint, unk2: c_uint, unk3: c_uint, }; -pub extern fn sceRegOpenRegistry(reg: [*c]struct_RegParam, mode: c_int, h: [*c]REGHANDLE) c_int; -pub extern fn sceRegFlushRegistry(h: REGHANDLE) c_int; -pub extern fn sceRegCloseRegistry(h: REGHANDLE) c_int; -pub extern fn sceRegOpenCategory(h: REGHANDLE, name: [*c]const u8, mode: c_int, hd: [*c]REGHANDLE) c_int; -pub extern fn sceRegRemoveCategory(h: REGHANDLE, name: [*c]const u8) c_int; -pub extern fn sceRegCloseCategory(hd: REGHANDLE) c_int; -pub extern fn sceRegFlushCategory(hd: REGHANDLE) c_int; -pub extern fn sceRegGetKeyInfo(hd: REGHANDLE, name: [*c]const u8, hk: [*c]REGHANDLE, typec: [*c]c_uint, size: [*c]SceSize) c_int; -pub extern fn sceRegGetKeyInfoByName(hd: REGHANDLE, name: [*c]const u8, typec: [*c]c_uint, size: [*c]SceSize) c_int; -pub extern fn sceRegGetKeyValue(hd: REGHANDLE, hk: REGHANDLE, buf: ?*c_void, size: SceSize) c_int; -pub extern fn sceRegGetKeyValueByName(hd: REGHANDLE, name: [*c]const u8, buf: ?*c_void, size: SceSize) c_int; -pub extern fn sceRegSetKeyValue(hd: REGHANDLE, name: [*c]const u8, buf: ?*const c_void, size: SceSize) c_int; -pub extern fn sceRegGetKeysNum(hd: REGHANDLE, num: [*c]c_int) c_int; -pub extern fn sceRegGetKeys(hd: REGHANDLE, buf: [*c]u8, num: c_int) c_int; -pub extern fn sceRegCreateKey(hd: REGHANDLE, name: [*c]const u8, typec: c_int, size: SceSize) c_int; -pub extern fn sceRegRemoveRegistry(reg: [*c]struct_RegParam) c_int; - -pub const RegKeyTypes = enum_RegKeyTypes; -pub const RegParam = struct_RegParam; + + +// Open the registry +// +// @param reg - A filled in ::RegParam structure +// @param mode - Open mode (set to 1) +// @param h - Pointer to a REGHANDLE to receive the registry handle +// +// @return 0 on success, < 0 on error +pub extern fn sceRegOpenRegistry(reg: *RegParam, mode: c_int, h: *RegHandle) c_int; +pub fn regOpenRegistry(reg: *RegParam, mode: c_int, h: *RegHandle) !void { + var res = sceRegOpenRegistry(reg, mode, h); + if(res < 0){ + return error.Unexpected; + } +} + +// Flush the registry to disk +// +// @param h - The open registry handle +// +// @return 0 on success, < 0 on error +pub extern fn sceRegFlushRegistry(h: RegHandle) c_int; +pub fn regFlushRegistry(h: *RegHandle) !void { + var res = sceRegFlushRegistry(h); + if(res < 0){ + return error.Unexpected; + } +} + +// Close the registry +// +// @param h - The open registry handle +// +// @return 0 on success, < 0 on error +pub extern fn sceRegCloseRegistry(h: RegHandle) c_int; +pub fn regCloseRegistry(h: RegHandle) !void{ + var res = sceRegCloseRegistry(h); + if(res < 0){ + return error.Unexpected; + } +} + +// Open a registry directory +// +// @param h - The open registry handle +// @param name - The path to the dir to open (e.g. /CONFIG/SYSTEM) +// @param mode - Open mode (can be 1 or 2, probably read or read/write +// @param hd - Pointer to a REGHANDLE to receive the registry dir handle +// +// @return 0 on success, < 0 on error +pub extern fn sceRegOpenCategory(h: RegHandle, name: []const u8, mode: c_int, hd: *RegHandle) c_int; +pub fn regOpenCategory(h: RegHandle, name: []const u8, mode: c_int, hd: *RegHandle) !void{ + var res = sceRegOpenCategory(h, name, mode, hd); + if(res < 0){ + return error.Unexpected; + } +} + +// Remove a registry dir +// +// @param h - The open registry dir handle +// @param name - The name of the key +// +// @return 0 on success, < 0 on error +pub extern fn sceRegRemoveCategory(h: RegHandle, name: []const u8) c_int; +pub fn regRemoveCategory(h: RegHandle, name: []const u8) !void{ + var res = sceRegRemoveCategory(h, name); + if(res < 0){ + return error.Unexpected; + } +} + +// Close the registry directory +// +// @param hd - The open registry dir handle +// +// @return 0 on success, < 0 on error +pub extern fn sceRegCloseCategory(hd: RegHandle) c_int; +pub fn regCloseCategory(hd: RegHandle) !void{ + var res = sceRegCloseCategory(hd); + if(res < 0){ + return error.Unexpected; + } +} + +// Flush the registry directory to disk +// +// @param hd - The open registry dir handle +// +// @return 0 on success, < 0 on error +pub extern fn sceRegFlushCategory(hd: RegHandle) c_int; +pub fn regFlushCategory(hd: RegHandle) !void{ + var res = sceRegFlushCategory(hd); + if(res < 0){ + return error.Unexpected; + } +} + +// Get a key's information +// +// @param hd - The open registry dir handle +// @param name - Name of the key +// @param hk - Pointer to a REGHANDLE to get registry key handle +// @param type - Type of the key, on of ::RegKeyTypes +// @param size - The size of the key's value in bytes +// +// @return 0 on success, < 0 on error +pub extern fn sceRegGetKeyInfo(hd: RegHandle, name: []const u8, hk: *RegHandle, typec: *c_uint, size: *SceSize) c_int; +pub fn regGetKeyInfo(hd: RegHandle, name: []const u8, hk: *RegHandle, typec: *c_uint, size: *SceSize) !void{ + var res = sceRegGetKeyInfo(hd, name, hk, typec, size); + if(res < 0){ + return error.Unexpected; + } +} + +// Get a key's information by name +// +// @param hd - The open registry dir handle +// @param name - Name of the key +// @param type - Type of the key, on of ::RegKeyTypes +// @param size - The size of the key's value in bytes +// +// @return 0 on success, < 0 on error +pub extern fn sceRegGetKeyInfoByName(hd: RegHandle, name: []const u8, typec: *c_uint, size: *SceSize) c_int; +pub fn regGetKeyInfoByName(hd: RegHandle, name: []const u8, typec: *c_uint, size: *SceSize) !void{ + var res = sceRegGetKeyInfoByName(hd, name, typec, size); + if(res < 0){ + return error.Unexpected; + } +} + + +// Get a key's value +// +// @param hd - The open registry dir handle +// @param hk - The open registry key handler (from ::sceRegGetKeyInfo) +// @param buf - Buffer to hold the value +// @param size - The size of the buffer +// +// @return 0 on success, < 0 on error +pub extern fn sceRegGetKeyValue(hd: RegHandle, hk: RegHandle, buf: ?*c_void, size: SceSize) c_int; +pub fn regGetKeyValue(hd: RegHandle, hk: RegHandle, buf: ?*c_void, size: SceSize) !void{ + var res = sceRegGetKeyValue(hd, hk, buf, size); + if(res < 0){ + return error.Unexpected; + } +} + +// Get a key's value by name +// +// @param hd - The open registry dir handle +// @param name - The key name +// @param buf - Buffer to hold the value +// @param size - The size of the buffer +// +// @return 0 on success, < 0 on error +pub extern fn sceRegGetKeyValueByName(hd: RegHandle, name: []const u8, buf: ?*c_void, size: SceSize) c_int; +pub fn regGetKeyValueByName(hd: RegHandle, name: []const u8, buf: ?*c_void, size: SceSize) !void{ + var res = sceRegGetKeyValueByName(hd, name, buf, size); + if(res < 0){ + return error.Unexpected; + } +} + + +// Set a key's value +// +// @param hd - The open registry dir handle +// @param name - The key name +// @param buf - Buffer to hold the value +// @param size - The size of the buffer +// +// @return 0 on success, < 0 on error +pub extern fn sceRegSetKeyValue(hd: RegHandle, name: []const u8, buf: ?*const c_void, size: SceSize) c_int; +pub fn regSetKeyValue(hd: RegHandle, name: []const u8, buf: ?*const c_void, size: SceSize) !void{ + var res = sceRegSetKeyValue(hd, name, buf, size); + if(res < 0){ + return error.Unexpected; + } +} + +// Get number of subkeys in the current dir +// +// @param hd - The open registry dir handle +// @param num - Pointer to an integer to receive the number +// +// @return 0 on success, < 0 on error +pub extern fn sceRegGetKeysNum(hd: RegHandle, num: *c_int) c_int; +pub fn regGetKeysNum(hd: RegHandle, num: *c_int) !void{ + var res = sceRegGetKeysNum(hd, num); + if(res < 0){ + return error.Unexpected; + } +} + + +// Get the key names in the current directory +// +// @param hd - The open registry dir handle +// @param buf - Buffer to hold the NUL terminated strings, should be num*REG_KEYNAME_SIZE +// @param num - Number of elements in buf +// +// @return 0 on success, < 0 on error +pub extern fn sceRegGetKeys(hd: RegHandle, buf: [*]u8, num: c_int) c_int; +pub fn regGetKeys(hd: RegHandle, buf: [*]u8, num: c_int) !void{ + var res = sceRegGetKeys(hd, buf, num); + if(res < 0){ + return error.Unexpected; + } +} + +// Create a key +// +// @param hd - The open registry dir handle +// @param name - Name of the key to create +// @param type - Type of key (note cannot be a directory type) +// @param size - Size of the allocated value space +// +// @return 0 on success, < 0 on error +pub extern fn sceRegCreateKey(hd: RegHandle, name: []const u8, typec: c_int, size: SceSize) c_int; +pub fn regCreateKey(hd: RegHandle, name: []const u8, typec: c_int, size: SceSize) !void{ + var res = sceRegCreateKey(hd, name, typec, size); + if(res < 0){ + return error.Unexpected; + } +} + +// Remove a registry (HONESTLY, DO NOT USE) +// +// @param reg - Filled out registry parameter +// +// @return 0 on success, < 0 on error +pub extern fn sceRegRemoveRegistry(reg: *RegParam) c_int; +pub fn regRemoveRegistry(reg: *RegParam) !void{ + var res = sceRegRemoveRegistry(reg); + if(res < 0){ + return error.Unexpected; + } +} diff --git a/src/psp/sdk/pspssl.zig b/src/psp/sdk/pspssl.zig index 47e1ed5..9c621da 100644 --- a/src/psp/sdk/pspssl.zig +++ b/src/psp/sdk/pspssl.zig @@ -1,4 +1,39 @@ +// Init the ssl library. +// +// @param unknown1 - Memory size? Pass 0x28000 +// +// @return 0 on success pub extern fn sceSslInit(unknown1: c_int) c_int; + +pub fn sslInit() bool{ + return sceSslInit(0x28000) == 0; +} + +// Terminate the ssl library. +// +// @return 0 on success pub extern fn sceSslEnd() c_int; -pub extern fn sceSslGetUsedMemoryMax(memory: [*c]c_uint) c_int; -pub extern fn sceSslGetUsedMemoryCurrent(memory: [*c]c_uint) c_int; + +pub fn sslEnd() bool{ + return sceSslEnd() == 0; +} + +// Get the maximum memory size used by ssl. +// +// @param memory - Pointer where the maximum memory used value will be stored. +// +// @return 0 on success +pub extern fn sceSslGetUsedMemoryMax(memory: *c_uint) c_int; +pub fn sslGetUsedMemoryMax(memory: *c_uint) bool{ + return sceSslGetUsedMemoryMax(memory) == 0; +} + +// Get the current memory size used by ssl. +// +// @param memory - Pointer where the current memory used value will be stored. +// +// @return 0 on success +pub extern fn sceSslGetUsedMemoryCurrent(memory: *c_uint) c_int; +pub fn sslGetUsedMemoryCurrent (memory: *c_uint) bool { + return sceSslGetUsedMemoryCurrent(memory) == 0; +} diff --git a/src/psp/sdk/pspstdio.zig b/src/psp/sdk/pspstdio.zig index 92efaba..603e94f 100644 --- a/src/psp/sdk/pspstdio.zig +++ b/src/psp/sdk/pspstdio.zig @@ -1,5 +1,16 @@ usingnamespace @import("psptypes.zig"); +// Function to get the current standard in file no +// +// @return The stdin fileno pub extern fn sceKernelStdin() SceUID; + +// Function to get the current standard out file no +// +// @return The stdout fileno pub extern fn sceKernelStdout() SceUID; + +// Function to get the current standard err file no +// +// @return The stderr fileno pub extern fn sceKernelStderr() SceUID; diff --git a/src/psp/sdk/pspsysmem.zig b/src/psp/sdk/pspsysmem.zig index 3f350ca..54c3922 100644 --- a/src/psp/sdk/pspsysmem.zig +++ b/src/psp/sdk/pspsysmem.zig @@ -1,19 +1,83 @@ usingnamespace @import("psptypes.zig"); -pub const enum_PspSysMemBlockTypes = extern enum(c_int) { +pub const PspSysMemBlockTypes = extern enum(c_int) { MemLow = 0, MemHigh = 1, MemAddr = 2, - _, }; pub const SceKernelSysMemAlloc_t = c_int; -pub extern fn sceKernelAllocPartitionMemory(partitionid: SceUID, name: [*c]const u8, type: c_int, size: SceSize, addr: ?*c_void) SceUID; + +// Allocate a memory block from a memory partition. +// +// @param partitionid - The UID of the partition to allocate from. +// @param name - Name assigned to the new block. +// @param type - Specifies how the block is allocated within the partition. One of ::PspSysMemBlockTypes. +// @param size - Size of the memory block, in bytes. +// @param addr - If type is PSP_SMEM_Addr, then addr specifies the lowest address allocate the block from. +// +// @return The UID of the new block, or if less than 0 an error. +pub extern fn sceKernelAllocPartitionMemory(partitionid: SceUID, name: [*c]const u8, typec: c_int, size: SceSize, addr: ?*c_void) SceUID; + +pub fn kernelAllocPartitionMemory(partitionid: SceUID, name: [*c]const u8, typec: c_int, size: SceSize, addr: ?*c_void) !SceUID{ + var res = sceKernelAllocPartitionMemory(partitionid, name, typec, size, addr); + if(res < 0){ + return error.AllocationError; + } + return res; +} + +// Free a memory block allocated with ::sceKernelAllocPartitionMemory. +// +// @param blockid - UID of the block to free. +// +// @return ? on success, less than 0 on error. pub extern fn sceKernelFreePartitionMemory(blockid: SceUID) c_int; + +// Get the address of a memory block. +// +// @param blockid - UID of the memory block. +// +// @return The lowest address belonging to the memory block. pub extern fn sceKernelGetBlockHeadAddr(blockid: SceUID) ?*c_void; + + +// Get the total amount of free memory. +// +// @return The total amount of free memory, in bytes. pub extern fn sceKernelTotalFreeMemSize() SceSize; + +// Get the size of the largest free memory block. +// +// @return The size of the largest free memory block, in bytes. pub extern fn sceKernelMaxFreeMemSize() SceSize; + +// Get the firmware version. +// +// @return The firmware version. +// 0x01000300 on v1.00 unit, +// 0x01050001 on v1.50 unit, +// 0x01050100 on v1.51 unit, +// 0x01050200 on v1.52 unit, +// 0x02000010 on v2.00/v2.01 unit, +// 0x02050010 on v2.50 unit, +// 0x02060010 on v2.60 unit, +// 0x02070010 on v2.70 unit, +// 0x02070110 on v2.71 unit. pub extern fn sceKernelDevkitVersion() c_int; + +// Set the version of the SDK with which the caller was compiled. +// Version numbers are as for sceKernelDevkitVersion(). +// +// @return 0 on success, < 0 on error. pub extern fn sceKernelSetCompiledSdkVersion(version: c_int) c_int; -pub extern fn sceKernelGetCompiledSdkVersion() c_int; +pub fn kernelSetCompiledSdkVersion(version: c_int) !void{ + var res = sceKernelSetCompiledSdkVersion(version); + if(res < 0){ + return error.Unexpected; + } +} -pub const PspSysMemBlockTypes = enum_PspSysMemBlockTypes; +// Get the SDK version set with sceKernelSetCompiledSdkVersion(). +// +// @return Version number, or 0 if unset. +pub extern fn sceKernelGetCompiledSdkVersion() c_int; diff --git a/src/psp/sdk/psptypes.zig b/src/psp/sdk/psptypes.zig index 0cfa262..d0d2af5 100644 --- a/src/psp/sdk/psptypes.zig +++ b/src/psp/sdk/psptypes.zig @@ -52,145 +52,124 @@ pub const SceWChar32 = c_uint; pub const SceBool = c_int; pub const SceVoid = c_void; pub const ScePVoid = ?*c_void; -const struct_ScePspSRect = extern struct { +pub const ScePspSRect = extern struct { x: c_short, y: c_short, w: c_short, h: c_short, }; -pub const ScePspSRect = struct_ScePspSRect; -const struct_ScePspIRect = extern struct { +pub const ScePspIRect = extern struct { x: c_int, y: c_int, w: c_int, h: c_int, }; -pub const ScePspIRect = struct_ScePspIRect; -const struct_ScePspL64Rect = extern struct { +pub const ScePspL64Rect = extern struct { x: SceLong64, y: SceLong64, w: SceLong64, h: SceLong64, }; -pub const ScePspL64Rect = struct_ScePspL64Rect; -const struct_ScePspFRect = extern struct { +pub const ScePspFRect = extern struct { x: f32, y: f32, w: f32, h: f32, }; -pub const ScePspFRect = struct_ScePspFRect; -const struct_ScePspSVector2 = extern struct { +pub const ScePspSVector2 = extern struct { x: c_short, y: c_short, }; -pub const ScePspSVector2 = struct_ScePspSVector2; -const struct_ScePspIVector2 = extern struct { +pub const ScePspIVector2 = extern struct { x: c_int, y: c_int, }; -pub const ScePspIVector2 = struct_ScePspIVector2; -const struct_ScePspL64Vector2 = extern struct { +pub const ScePspL64Vector2 = extern struct { x: SceLong64, y: SceLong64, }; -pub const ScePspL64Vector2 = struct_ScePspL64Vector2; -const struct_ScePspFVector2 = extern struct { +pub const ScePspFVector2 = extern struct { x: f32, y: f32, }; -pub const ScePspFVector2 = struct_ScePspFVector2; -const union_ScePspVector2 = extern union { +pub const ScePspVector2 = extern union { fv: ScePspFVector2, iv: ScePspIVector2, f: [2]f32, i: [2]c_int, }; -pub const ScePspVector2 = union_ScePspVector2; -const struct_ScePspSVector3 = extern struct { +pub const ScePspSVector3 = extern struct { x: c_short, y: c_short, z: c_short, }; -pub const ScePspSVector3 = struct_ScePspSVector3; -const struct_ScePspIVector3 = extern struct { +pub const ScePspIVector3 = extern struct { x: c_int, y: c_int, z: c_int, }; -pub const ScePspIVector3 = struct_ScePspIVector3; -const struct_ScePspL64Vector3 = extern struct { +pub const ScePspL64Vector3 = extern struct { x: SceLong64, y: SceLong64, z: SceLong64, }; -pub const ScePspL64Vector3 = struct_ScePspL64Vector3; -const struct_ScePspFVector3 = extern struct { +pub const ScePspFVector3 = extern struct { x: f32, y: f32, z: f32, }; -pub const ScePspFVector3 = struct_ScePspFVector3; -const union_ScePspVector3 = extern union { + +pub const ScePspVector3 = extern union { fv: ScePspFVector3, iv: ScePspIVector3, f: [3]f32, i: [3]c_int, }; -pub const ScePspVector3 = union_ScePspVector3; -const struct_ScePspSVector4 = extern struct { +pub const ScePspSVector4 = extern struct { x: c_short, y: c_short, z: c_short, w: c_short, }; -pub const ScePspSVector4 = struct_ScePspSVector4; -const struct_ScePspIVector4 = extern struct { +pub const ScePspIVector4 = extern struct { x: c_int, y: c_int, z: c_int, w: c_int, }; -pub const ScePspIVector4 = struct_ScePspIVector4; -const struct_ScePspL64Vector4 = extern struct { +pub const ScePspL64Vector4 = extern struct { x: SceLong64, y: SceLong64, z: SceLong64, w: SceLong64, }; -pub const ScePspL64Vector4 = struct_ScePspL64Vector4; -const struct_ScePspFVector4 = extern struct { +pub const ScePspFVector4 = extern struct { x: f32, y: f32, z: f32, w: f32, }; -pub const ScePspFVector4 = struct_ScePspFVector4; -const struct_ScePspFVector4Unaligned = extern struct { +pub const ScePspFVector4Unaligned = extern struct { x: f32, y: f32, z: f32, w: f32, }; -pub const ScePspFVector4Unaligned = struct_ScePspFVector4Unaligned; -const union_ScePspVector4 = extern union { +pub const ScePspVector4 = extern union { fv: ScePspFVector4, iv: ScePspIVector4, f: [4]f32, i: [4]c_int, }; -pub const ScePspVector4 = union_ScePspVector4; -const struct_ScePspIMatrix2 = extern struct { +pub const ScePspIMatrix2 = extern struct { x: ScePspIVector2, y: ScePspIVector2, }; -pub const ScePspIMatrix2 = struct_ScePspIMatrix2; -const struct_ScePspFMatrix2 = extern struct { +pub const ScePspFMatrix2 = extern struct { x: ScePspFVector2, y: ScePspFVector2, }; -pub const ScePspFMatrix2 = struct_ScePspFMatrix2; -const union_ScePspMatrix2 = extern union { +pub const ScePspMatrix2 = extern union { fm: ScePspFMatrix2, im: ScePspIMatrix2, fv: [2]ScePspFVector2, @@ -199,20 +178,17 @@ const union_ScePspMatrix2 = extern union { f: [2][2]f32, i: [2][2]c_int, }; -pub const ScePspMatrix2 = union_ScePspMatrix2; -const struct_ScePspIMatrix3 = extern struct { +pub const ScePspIMatrix3 = extern struct { x: ScePspIVector3, y: ScePspIVector3, z: ScePspIVector3, }; -pub const ScePspIMatrix3 = struct_ScePspIMatrix3; -const struct_ScePspFMatrix3 = extern struct { +pub const ScePspFMatrix3 = extern struct { x: ScePspFVector3, y: ScePspFVector3, z: ScePspFVector3, }; -pub const ScePspFMatrix3 = struct_ScePspFMatrix3; -const union_ScePspMatrix3 = extern union { +pub const ScePspMatrix3 = extern union { fm: ScePspFMatrix3, im: ScePspIMatrix3, fv: [3]ScePspFVector3, @@ -221,36 +197,34 @@ const union_ScePspMatrix3 = extern union { f: [3][3]f32, i: [3][3]c_int, }; -pub const ScePspMatrix3 = union_ScePspMatrix3; -const struct_ScePspIMatrix4 = extern struct { +pub const ScePspIMatrix4 = extern struct { x: ScePspIVector4, y: ScePspIVector4, z: ScePspIVector4, w: ScePspIVector4, }; -pub const ScePspIMatrix4 = struct_ScePspIMatrix4; -const struct_ScePspIMatrix4Unaligned = extern struct { + +pub const ScePspIMatrix4Unaligned = extern struct { x: ScePspIVector4, y: ScePspIVector4, z: ScePspIVector4, w: ScePspIVector4, }; -pub const ScePspIMatrix4Unaligned = struct_ScePspIMatrix4Unaligned; -const struct_ScePspFMatrix4 = extern struct { + +pub const ScePspFMatrix4 = extern struct { x: ScePspFVector4, y: ScePspFVector4, z: ScePspFVector4, w: ScePspFVector4, }; -pub const ScePspFMatrix4 = struct_ScePspFMatrix4; -const struct_ScePspFMatrix4Unaligned = extern struct { +pub const ScePspFMatrix4Unaligned = extern struct { x: ScePspFVector4, y: ScePspFVector4, z: ScePspFVector4, w: ScePspFVector4, }; -pub const ScePspFMatrix4Unaligned = struct_ScePspFMatrix4Unaligned; -const union_ScePspMatrix4 = extern union { + +pub const ScePspMatrix4 = extern union { fm: ScePspFMatrix4, im: ScePspIMatrix4, fv: [4]ScePspFVector4, @@ -259,40 +233,38 @@ const union_ScePspMatrix4 = extern union { f: [4][4]f32, i: [4][4]c_int, }; -pub const ScePspMatrix4 = union_ScePspMatrix4; -const struct_ScePspFQuaternion = extern struct { +pub const ScePspFQuaternion = extern struct { x: f32, y: f32, z: f32, w: f32, }; -pub const ScePspFQuaternion = struct_ScePspFQuaternion; -const struct_ScePspFQuaternionUnaligned = extern struct { + +pub const ScePspFQuaternionUnaligned = extern struct { x: f32, y: f32, z: f32, w: f32, }; -pub const ScePspFQuaternionUnaligned = struct_ScePspFQuaternionUnaligned; -const struct_ScePspFColor = extern struct { + +pub const ScePspFColor = extern struct { r: f32, g: f32, b: f32, a: f32, }; -pub const ScePspFColor = struct_ScePspFColor; -const struct_ScePspFColorUnaligned = extern struct { +pub const ScePspFColorUnaligned = extern struct { r: f32, g: f32, b: f32, a: f32, }; -pub const ScePspFColorUnaligned = struct_ScePspFColorUnaligned; + pub const ScePspRGBA8888 = c_uint; pub const ScePspRGBA4444 = c_ushort; pub const ScePspRGBA5551 = c_ushort; pub const ScePspRGB565 = c_ushort; -const union_ScePspUnion32 = extern union { +pub const ScePspUnion32 = extern union { ui: c_uint, i: c_int, us: [2]c_ushort, @@ -305,8 +277,8 @@ const union_ScePspUnion32 = extern union { rgba5551: [2]ScePspRGBA5551, rgb565: [2]ScePspRGB565, }; -pub const ScePspUnion32 = union_ScePspUnion32; -const union_ScePspUnion64 = extern union { + +pub const ScePspUnion64 = extern union { ul: SceULong64, l: SceLong64, ui: [2]c_uint, @@ -323,8 +295,8 @@ const union_ScePspUnion64 = extern union { rgba5551: [4]ScePspRGBA5551, rgb565: [4]ScePspRGB565, }; -pub const ScePspUnion64 = union_ScePspUnion64; -const union_ScePspUnion128 = extern union { + +pub const ScePspUnion128 = extern union { ul: [2]SceULong64, l: [2]SceLong64, ui: [4]c_uint, @@ -345,8 +317,8 @@ const union_ScePspUnion128 = extern union { rgba5551: [8]ScePspRGBA5551, rgb565: [8]ScePspRGB565, }; -pub const ScePspUnion128 = union_ScePspUnion128; -const struct_ScePspDateTime = extern struct { + +pub const ScePspDateTime = extern struct { year: c_ushort, month: c_ushort, day: c_ushort, @@ -355,7 +327,6 @@ const struct_ScePspDateTime = extern struct { second: c_ushort, microsecond: c_uint, }; -pub const ScePspDateTime = struct_ScePspDateTime; pub const SceUID = c_int; pub const SceSize = c_uint; diff --git a/src/psp/sdk/pspumd.zig b/src/psp/sdk/pspumd.zig index d280655..75c08f3 100644 --- a/src/psp/sdk/pspumd.zig +++ b/src/psp/sdk/pspumd.zig @@ -1,47 +1,227 @@ -pub const struct_pspUmdInfo = extern struct { +pub const PspUmdInfo = extern struct { size: c_uint, - type: c_uint, + typec: c_uint, }; -pub const pspUmdInfo = struct_pspUmdInfo; -pub const enum_pspUmdTypes = extern enum(c_int) { - PSP_UMD_TYPE_GAME = 16, - PSP_UMD_TYPE_VIDEO = 32, - PSP_UMD_TYPE_AUDIO = 64, - _, +pub const PspUmdTypes = extern enum(c_int) { + Game = 16, + Video = 32, + Audio = 64, }; -pub const enum_pspUmdState = extern enum(c_int) { - PSP_UMD_NOT_PRESENT = 1, - PSP_UMD_PRESENT = 2, - PSP_UMD_CHANGED = 4, - PSP_UMD_INITING = 8, - PSP_UMD_INITED = 16, - PSP_UMD_READY = 32, - _, +pub const PspUmdState = extern enum(c_int) { + NotPresent = 1, + Present = 2, + Changed = 4, + Initing = 8, + Inited = 16, + Ready = 32, }; -pub const enum_UmdDriveStat = extern enum(c_int) { - UMD_WAITFORDISC = 2, - UMD_WAITFORINIT = 32, - _, +pub const UmdDriveStat = extern enum(c_int) { + WaitForDISC = 2, + WaitForINIT = 32, }; pub const UmdCallback = ?fn (c_int, c_int) callconv(.C) c_int; + + +// Check whether there is a disc in the UMD drive +// +// @return 0 if no disc present, anything else indicates a disc is inserted. pub extern fn sceUmdCheckMedium() c_int; -pub extern fn sceUmdGetDiscInfo(info: [*c]pspUmdInfo) c_int; -pub extern fn sceUmdActivate(unit: c_int, drive: [*c]const u8) c_int; -pub extern fn sceUmdDeactivate(unit: c_int, drive: [*c]const u8) c_int; + +// Get the disc info +// +// @param info - A pointer to a ::pspUmdInfo struct +// +// @return < 0 on error +pub extern fn sceUmdGetDiscInfo(info: *PspUmdInfo) c_int; +pub fn umdGetDiscInfo(info: *PspUmdInfo) !i32 { + var res = sceUmdGetDiscInfo(info); + if(res < 0){ + return error.Unexpected; + } + return res; +} + +// Activates the UMD drive +// +// @param unit - The unit to initialise (probably). Should be set to 1. +// +// @param drive - A prefix string for the fs device to mount the UMD on (e.g. "disc0:") +// +// @return < 0 on error +// +// @par Example: +// @code +// // Wait for disc and mount to filesystem +// int i; +// i = sceUmdCheckMedium(); +// if(i == 0) +// { +// sceUmdWaitDriveStat(PSP_UMD_PRESENT); +// } +// sceUmdActivate(1, "disc0:"); // Mount UMD to disc0: file system +// sceUmdWaitDriveStat(PSP_UMD_READY); +// // Now you can access the UMD using standard sceIo functions +// @endcode +pub extern fn sceUmdActivate(unit: c_int, drive: []const u8) c_int; +pub fn umdActivate(unit: c_int, drive: []const u8) !i32 { + var res = sceUmdActivate(unit, drive); + if(res < 0){ + return error.Unexpected; + } + return res; +} + +// Deativates the UMD drive +// +// @param unit - The unit to initialise (probably). Should be set to 1. +// +// @param drive - A prefix string for the fs device to mount the UMD on (e.g. "disc0:") +// +// @return < 0 on error +pub extern fn sceUmdDeactivate(unit: c_int, drive: []const u8) c_int; +pub fn umdDeactivate(unit: c_int, drive: []const u8) !i32 { + var res = sceUmdDeactivate(unit, drive); + if(res < 0){ + return error.Unexpected; + } + return res; +} + +// Wait for the UMD drive to reach a certain state +// +// @param stat - One or more of ::pspUmdState +// +// @return < 0 on error pub extern fn sceUmdWaitDriveStat(stat: c_int) c_int; +pub fn umdWaitDriveStat(stat: c_int) !i32 { + var res = sceUmdWaitDriveStat(stat); + if(res < 0){ + return error.Unexpected; + } + return res; +} + +// Wait for the UMD drive to reach a certain state +// +// @param stat - One or more of ::pspUmdState +// +// @param timeout - Timeout value in microseconds +// +// @return < 0 on error pub extern fn sceUmdWaitDriveStatWithTimer(stat: c_int, timeout: c_uint) c_int; +pub fn umdWaitDriveStatWithTimer(stat: c_int, timeout: c_uint) !i32 { + var res = umdWaitDriveStatWithTimer(stat, timeout); + if(res < 0){ + return error.Unexpected; + } + return res; +} + +// Wait for the UMD drive to reach a certain state (plus callback) +// +// @param stat - One or more of ::pspUmdState +// +// @param timeout - Timeout value in microseconds +// +// @return < 0 on error pub extern fn sceUmdWaitDriveStatCB(stat: c_int, timeout: c_uint) c_int; +pub fn umdWaitDriveStatCB(stat: c_int, timeout: c_uint) !i32 { + var res = sceUmdWaitDriveStatCB(stat, timeout); + if(res < 0){ + return error.Unexpected; + } + return res; +} + +//Cancel a sceUmdWait* call +// +//@return < 0 on error pub extern fn sceUmdCancelWaitDriveStat() c_int; +pub fn umdCancelWaitDriveStat() !i32 { + var res = sceUmdCancelWaitDriveStat(); + if(res < 0){ + return error.Unexpected; + } + return res; +} + +// Get (poll) the current state of the UMD drive +// +// @return < 0 on error, one or more of ::pspUmdState on success pub extern fn sceUmdGetDriveStat() c_int; +pub fn umdGetDriveStat() !i32 { + var res = sceUmdGetDriveStat(); + if(res < 0){ + return error.Unexpected; + } + return res; +} + +// Get the error code associated with a failed event +// +// @return < 0 on error, the error code on success pub extern fn sceUmdGetErrorStat() c_int; + +// Register a callback for the UMD drive +// @note Callback is of type UmdCallback +// +// @param cbid - A callback ID created from sceKernelCreateCallback +// @return < 0 on error +// @par Example: +// @code +// int umd_callback(int unknown, int event) +// { +// //do something +// } +// int cbid = sceKernelCreateCallback("UMD Callback", umd_callback, NULL); +// sceUmdRegisterUMDCallBack(cbid); +// @endcode pub extern fn sceUmdRegisterUMDCallBack(cbid: c_int) c_int; +pub fn umdRegisterUMDCallBack(cbid: c_int) !i32 { + var res = sceUmdRegisterUMDCallBack(cbid); + if(res < 0){ + return error.Unexpected; + } + return res; +} + +// Un-register a callback for the UMD drive +// +// @param cbid - A callback ID created from sceKernelCreateCallback +// +// @return < 0 on error pub extern fn sceUmdUnRegisterUMDCallBack(cbid: c_int) c_int; +pub fn umdUnRegisterUMDCallBack(cbid: c_int) !i32 { + var res = sceUmdUnRegisterUMDCallBack(cbid); + if(res < 0){ + return error.Unexpected; + } + return res; +} + +// Permit UMD disc being replaced +// +// @return < 0 on error pub extern fn sceUmdReplacePermit() c_int; -pub extern fn sceUmdReplaceProhibit() c_int; +pub fn umdReplacePermit() !i32 { + var res = sceUmdReplacePermit(); + if(res < 0){ + return error.Unexpected; + } + return res; +} -pub const pspUmdTypes = enum_pspUmdTypes; -pub const pspUmdState = enum_pspUmdState; -pub const UmdDriveStat = enum_UmdDriveStat; +// Prohibit UMD disc being replaced +// +// @return < 0 on error +pub extern fn sceUmdReplaceProhibit() c_int; +pub fn umdReplaceProhibit() !i32 { + var res = sceUmdReplaceProhibit(); + if(res < 0){ + return error.Unexpected; + } + return res; +} diff --git a/src/psp/sdk/pspusb.zig b/src/psp/sdk/pspusb.zig index c4ecafe..9d5a621 100644 --- a/src/psp/sdk/pspusb.zig +++ b/src/psp/sdk/pspusb.zig @@ -1,15 +1,66 @@ usingnamespace @import("psptypes.zig"); + +// Start a USB driver. +// +// @param driverName - name of the USB driver to start +// @param size - Size of arguments to pass to USB driver start +// @param args - Arguments to pass to USB driver start +// +// @return 0 on success pub extern fn sceUsbStart(driverName: [*c]const u8, size: c_int, args: ?*c_void) c_int; +pub fn usbStart(driverName: [*c]const u8, size: c_int, args: ?*c_void) bool { + return sceUsbStart(driverName, size, args) == 0; +} + +// Stop a USB driver. +// +// @param driverName - name of the USB driver to stop +// @param size - Size of arguments to pass to USB driver start +// @param args - Arguments to pass to USB driver start +// +// @return 0 on success pub extern fn sceUsbStop(driverName: [*c]const u8, size: c_int, args: ?*c_void) c_int; +pub fn usbStop(driverName: [*c]const u8, size: c_int, args: ?*c_void) bool { + return sceUsbStop(driverName, size, args) == 0; +} + +// Activate a USB driver. +// +// @param pid - Product ID for the default USB Driver +// +// @return 0 on success pub extern fn sceUsbActivate(pid: u32) c_int; +pub fn usbActivate(pid: u32) bool { + return sceUsbActivate(pid) == 0; +} + + +// Deactivate USB driver. +// +// @param pid - Product ID for the default USB driver +// +// @return 0 on success pub extern fn sceUsbDeactivate(pid: u32) c_int; +pub fn usbDeactivate(pid: u32) bool { + return sceUsbDeactivate(pid) == 0; +} + +// Get USB state +// +// @return OR'd PSP_USB_* constants pub extern fn sceUsbGetState() c_int; + + +// Get state of a specific USB driver +// +// @param driverName - name of USB driver to get status from +// +// @return 1 if the driver has been started, 2 if it is stopped pub extern fn sceUsbGetDrvState(driverName: [*c]const u8) c_int; pub const PSP_USB_CABLE_CONNECTED = 0x020; pub const PSP_USB_CONNECTION_ESTABLISHED = 0x002; pub const PSP_USB_ACTIVATED = 0x200; pub const PSP_USBBUS_DRIVERNAME = "USBBusDriver"; - pub const PSP_USBACC_DRIVERNAME = "USBAccBaseDriver"; diff --git a/src/psp/sdk/psputility.zig b/src/psp/sdk/psputility.zig index 13c134b..e20de69 100644 --- a/src/psp/sdk/psputility.zig +++ b/src/psp/sdk/psputility.zig @@ -1,4 +1,4 @@ -const struct_unnamed_1 = extern struct { +pub const PspUtilityDialogCommon = extern struct { size: c_uint, language: c_int, buttonSwap: c_int, @@ -9,128 +9,122 @@ const struct_unnamed_1 = extern struct { result: c_int, reserved: [4]c_int, }; -pub const pspUtilityDialogCommon = struct_unnamed_1; -const enum_unnamed_2 = extern enum(c_int) { - PSP_UTILITY_MSGDIALOG_MODE_ERROR = 0, - PSP_UTILITY_MSGDIALOG_MODE_TEXT = 1, - _, -}; -pub const pspUtilityMsgDialogMode = enum_unnamed_2; -const enum_unnamed_3 = extern enum(c_int) { - PSP_UTILITY_MSGDIALOG_OPTION_ERROR = 0, - PSP_UTILITY_MSGDIALOG_OPTION_TEXT = 1, - PSP_UTILITY_MSGDIALOG_OPTION_YESNO_BUTTONS = 16, - PSP_UTILITY_MSGDIALOG_OPTION_DEFAULT_NO = 256, + +pub const PspUtilityMsgDialogMode = extern enum(c_int) { + Error = 0, + Text = 1, _, }; -pub const pspUtilityMsgDialogOption = enum_unnamed_3; -const enum_unnamed_4 = extern enum(c_int) { - PSP_UTILITY_MSGDIALOG_RESULT_UNKNOWN1 = 0, - PSP_UTILITY_MSGDIALOG_RESULT_YES = 1, - PSP_UTILITY_MSGDIALOG_RESULT_NO = 2, - PSP_UTILITY_MSGDIALOG_RESULT_BACK = 3, - _, +const PspUtilityMsgDialogOption = extern enum(c_int) { + Error = 0, + Text = 1, + YesNoButtons = 16, + DefaultNo = 256, }; -pub const pspUtilityMsgDialogPressed = enum_unnamed_4; -pub const struct__pspUtilityMsgDialogParams = extern struct { - base: pspUtilityDialogCommon, + +pub const PspUtilityMsgDialogPressed = extern enum(c_int) { + Unknown1 = 0, + Yes = 1, + No = 2, + Back = 3, +}; +pub const PspUtilityMsgDialogParams = extern struct { + base: PspUtilityDialogCommon, unknown: c_int, - mode: pspUtilityMsgDialogMode, + mode: PspUtilityMsgDialogMode, errorValue: c_uint, message: [512]u8, options: c_int, - buttonPressed: pspUtilityMsgDialogPressed, + buttonPressed: PspUtilityMsgDialogPressed, }; -pub const pspUtilityMsgDialogParams = struct__pspUtilityMsgDialogParams; -pub extern fn sceUtilityMsgDialogInitStart(params: [*c]pspUtilityMsgDialogParams) c_int; +pub extern fn sceUtilityMsgDialogInitStart(params: *PspUtilityMsgDialogParams) c_int; pub extern fn sceUtilityMsgDialogShutdownStart() void; pub extern fn sceUtilityMsgDialogGetStatus() c_int; pub extern fn sceUtilityMsgDialogUpdate(n: c_int) void; pub extern fn sceUtilityMsgDialogAbort() c_int; -pub const enum_pspUtilityNetconfActions = extern enum(c_int) { - PSP_NETCONF_ACTION_CONNECTAP, - PSP_NETCONF_ACTION_DISPLAYSTATUS, - PSP_NETCONF_ACTION_CONNECT_ADHOC, - _, +pub const PspUtilityNetconfActions = extern enum(c_int) { + ConnectAp, + DisplayStatus, + ConnectAdhoc, }; -pub const struct_pspUtilityNetconfAdhoc = extern struct { +pub const PspUtilityNetconfAdhoc = extern struct { name: [8]u8, timeout: c_uint, }; -pub const struct__pspUtilityNetconfData = extern struct { - base: pspUtilityDialogCommon, +pub const PspUtilityNetconfData = extern struct { + base: PspUtilityDialogCommon, action: c_int, - adhocparam: [*c]struct_pspUtilityNetconfAdhoc, + adhocparam: *PspUtilityNetconfAdhoc, hotspot: c_int, hotspot_connected: c_int, wifisp: c_int, }; -pub const pspUtilityNetconfData = struct__pspUtilityNetconfData; -pub extern fn sceUtilityNetconfInitStart(data: [*c]pspUtilityNetconfData) c_int; + +pub extern fn sceUtilityNetconfInitStart(data: *PspUtilityNetconfData) c_int; pub extern fn sceUtilityNetconfShutdownStart() c_int; pub extern fn sceUtilityNetconfUpdate(unknown: c_int) c_int; pub extern fn sceUtilityNetconfGetStatus() c_int; -const union_unnamed_9 = extern union { +const NetData = extern union { asUint: u32_7, asString: [128]u8, }; -pub const netData = union_unnamed_9; + pub extern fn sceUtilityCheckNetParam(id: c_int) c_int; -pub extern fn sceUtilityGetNetParam(conf: c_int, param: c_int, data: [*c]netData) c_int; +pub extern fn sceUtilityGetNetParam(conf: c_int, param: c_int, data: *NetData) c_int; pub extern fn sceUtilityCreateNetParam(conf: c_int) c_int; pub extern fn sceUtilitySetNetParam(param: c_int, val: ?*const c_void) c_int; pub extern fn sceUtilityCopyNetParam(src: c_int, dest: c_int) c_int; pub extern fn sceUtilityDeleteNetParam(conf: c_int) c_int; -const enum_unnamed_10 = extern enum(c_int) { - PSP_UTILITY_SAVEDATA_AUTOLOAD = 0, - PSP_UTILITY_SAVEDATA_AUTOSAVE = 1, - PSP_UTILITY_SAVEDATA_LOAD = 2, - PSP_UTILITY_SAVEDATA_SAVE = 3, - PSP_UTILITY_SAVEDATA_LISTLOAD = 4, - PSP_UTILITY_SAVEDATA_LISTSAVE = 5, - PSP_UTILITY_SAVEDATA_LISTDELETE = 6, - PSP_UTILITY_SAVEDATADELETE = 7, +const PspUtilitySavedataMode = extern enum(c_int) { + Autoload = 0, + Autosave = 1, + Load = 2, + Save = 3, + ListLoad = 4, + ListSave = 5, + ListDelete = 6, + Delete = 7, _, }; -pub const PspUtilitySavedataMode = enum_unnamed_10; -const enum_unnamed_11 = extern enum(c_int) { - PSP_UTILITY_SAVEDATA_FOCUS_UNKNOWN = 0, - PSP_UTILITY_SAVEDATA_FOCUS_FIRSTLIST = 1, - PSP_UTILITY_SAVEDATA_FOCUS_LASTLIST = 2, - PSP_UTILITY_SAVEDATA_FOCUS_LATEST = 3, - PSP_UTILITY_SAVEDATA_FOCUS_OLDEST = 4, - PSP_UTILITY_SAVEDATA_FOCUS_UNKNOWN2 = 5, - PSP_UTILITY_SAVEDATA_FOCUS_UNKNOWN3 = 6, - PSP_UTILITY_SAVEDATA_FOCUS_FIRSTEMPTY = 7, - PSP_UTILITY_SAVEDATA_FOCUS_LASTEMPTY = 8, + +const PspUtilitySavedataFocus = extern enum(c_int) { + Unknown = 0, + FirstList = 1, + LastList = 2, + Latest = 3, + Oldest = 4, + Unknown2 = 5, + Unknown3 = 6, + FirstEmpty = 7, + LastEmpty = 8, _, }; -pub const PspUtilitySavedataFocus = enum_unnamed_11; -pub const struct_PspUtilitySavedataSFOParam = extern struct { + +pub const PspUtilitySavedataSFOParam = extern struct { title: [128]u8, savedataTitle: [128]u8, detail: [1024]u8, parentalLevel: u8, unknown: [3]u8, }; -pub const PspUtilitySavedataSFOParam = struct_PspUtilitySavedataSFOParam; -pub const struct_PspUtilitySavedataFileData = extern struct { + +pub const PspUtilitySavedataFileData = extern struct { buf: ?*c_void, bufSize: SceSize, size: SceSize, unknown: c_int, }; -pub const PspUtilitySavedataFileData = struct_PspUtilitySavedataFileData; -pub const struct_PspUtilitySavedataListSaveNewData = extern struct { + +pub const PspUtilitySavedataListSaveNewData = extern struct { icon0: PspUtilitySavedataFileData, title: [*c]u8, }; -pub const PspUtilitySavedataListSaveNewData = struct_PspUtilitySavedataListSaveNewData; -pub const struct_SceUtilitySavedataParam = extern struct { - base: pspUtilityDialogCommon, + +pub const SceUtilitySavedataParam = extern struct { + base: PspUtilityDialogCommon, mode: PspUtilitySavedataMode, unknown1: c_int, overwrite: c_int, @@ -152,25 +146,126 @@ pub const struct_SceUtilitySavedataParam = extern struct { focus: PspUtilitySavedataFocus, unknown2: [4]c_int, }; -pub const SceUtilitySavedataParam = struct_SceUtilitySavedataParam; -pub extern fn sceUtilitySavedataInitStart(params: [*c]SceUtilitySavedataParam) c_int; +pub extern fn sceUtilitySavedataInitStart(params: *SceUtilitySavedataParam) c_int; pub extern fn sceUtilitySavedataGetStatus() c_int; pub extern fn sceUtilitySavedataShutdownStart() c_int; pub extern fn sceUtilitySavedataUpdate(unknown: c_int) void; -const enum_unnamed_12 = extern enum(c_int) { - PSP_UTILITY_GAMESHARING_MODE_SINGLE = 1, - PSP_UTILITY_GAMESHARING_MODE_MULTIPLE = 2, + +pub extern fn sceUtilityGameSharingInitStart(params: *PspUtilityGameSharingParams) c_int; +pub extern fn sceUtilityGameSharingShutdownStart() void; +pub extern fn sceUtilityGameSharingGetStatus() c_int; +pub extern fn sceUtilityGameSharingUpdate(n: c_int) void; + +pub extern fn sceUtilityHtmlViewerInitStart(params: *PspUtilityHtmlViewerParam) c_int; +pub extern fn sceUtilityHtmlViewerShutdownStart() c_int; +pub extern fn sceUtilityHtmlViewerUpdate(n: c_int) c_int; +pub extern fn sceUtilityHtmlViewerGetStatus() c_int; +pub extern fn sceUtilitySetSystemParamInt(id: c_int, value: c_int) c_int; +pub extern fn sceUtilitySetSystemParamString(id: c_int, str: [*c]const u8) c_int; +pub extern fn sceUtilityGetSystemParamInt(id: c_int, value: [*c]c_int) c_int; +pub extern fn sceUtilityGetSystemParamString(id: c_int, str: [*c]u8, len: c_int) c_int; + +pub extern fn sceUtilityOskInitStart(params: *SceUtilityOskParams) c_int; +pub extern fn sceUtilityOskShutdownStart() c_int; +pub extern fn sceUtilityOskUpdate(n: c_int) c_int; +pub extern fn sceUtilityOskGetStatus() c_int; +pub extern fn sceUtilityLoadNetModule(module: c_int) c_int; +pub extern fn sceUtilityUnloadNetModule(module: c_int) c_int; +pub extern fn sceUtilityLoadAvModule(module: c_int) c_int; +pub extern fn sceUtilityUnloadAvModule(module: c_int) c_int; +pub extern fn sceUtilityLoadUsbModule(module: c_int) c_int; +pub extern fn sceUtilityUnloadUsbModule(module: c_int) c_int; +pub extern fn sceUtilityLoadModule(module: c_int) c_int; +pub extern fn sceUtilityUnloadModule(module: c_int) c_int; + +pub const PspUtilityDialogState = extern enum(c_int) { + None = 0, + Init = 1, + Visible = 2, + Quit = 3, + Finished = 4, +}; + +pub const SceUtilityOskInputType = extern enum(c_int) { + All = 0, + LatinDigit = 1, + LatinSymbol = 2, + LatinLowercase = 4, + LatinUppercase = 8, + JapaneseDigit = 256, + JapaneseSymbol = 512, + JapaneseLowercase = 1024, + JapaneseUppercase = 2048, + JapaneseHiragana = 4096, + JapaneseHalfKatakana = 8192, + JapaneseKatakana = 16384, + JapaneseKanji = 32768, + RussianLowercase = 65536, + RussianUppercase = 131072, + Korean = 262144, + Url = 524288, +}; + +pub const SceUtilityOskInputLanguage = extern enum(c_int) { + Default = 0, + Japanese = 1, + English = 2, + French = 3, + Spanish = 4, + German = 5, + Italian = 6, + Dutch = 7, + Portugese = 8, + Russian = 9, + Korean = 10, +}; +pub const SceUtilityOskState = extern enum(c_int) { + None = 0, + Initing = 1, + Inited = 2, + Visible = 3, + Quit = 4, + Finished = 5, +}; +pub const SceUtilityOskResult = extern enum(c_int) { + Unchanged = 0, + Cancelled = 1, + Changed = 2, +}; + +pub const PspUtilityHtmlViewerDisconnectModes = extern enum(c_int) { + Enable = 0, + Disable = 1, + Confirm = 2, + _, +}; +pub const PspUtilityHtmlViewerInterfaceModes = extern enum(c_int) { + Full = 0, + Limited = 1, + None = 2, + _, +}; +pub const PspUtilityHtmlViewerCookieModes = extern enum(c_int) { + Disabled = 0, + Enabled = 1, + Confirm = 2, + Default = 3, _, }; -pub const pspUtilityGameSharingMode = enum_unnamed_12; -const enum_unnamed_13 = extern enum(c_int) { - PSP_UTILITY_GAMESHARING_DATA_TYPE_FILE = 1, - PSP_UTILITY_GAMESHARING_DATA_TYPE_MEMORY = 2, +pub const PspUtilityGameSharingMode = extern enum(c_int) { + Single = 1, + Multiple = 2, _, }; -pub const pspUtilityGameSharingDataType = enum_unnamed_13; -pub const struct__pspUtilityGameSharingParams = extern struct { - base: pspUtilityDialogCommon, + +pub const PspUtilityGameSharingDataType = extern enum(c_int) { + File = 1, + Memory = 2, + _, +}; + +pub const PspUtilityGameSharingParams = extern struct { + base: PspUtilityDialogCommon, unknown1: c_int, unknown2: c_int, name: [8]u8, @@ -179,70 +274,46 @@ pub const struct__pspUtilityGameSharingParams = extern struct { unknown5: c_int, result: c_int, filepath: [*c]u8, - mode: pspUtilityGameSharingMode, - datatype: pspUtilityGameSharingDataType, + mode: PspUtilityGameSharingMode, + datatype: PspUtilityGameSharingDataType, data: ?*c_void, datasize: c_uint, }; -pub const pspUtilityGameSharingParams = struct__pspUtilityGameSharingParams; -pub extern fn sceUtilityGameSharingInitStart(params: [*c]pspUtilityGameSharingParams) c_int; -pub extern fn sceUtilityGameSharingShutdownStart() void; -pub extern fn sceUtilityGameSharingGetStatus() c_int; -pub extern fn sceUtilityGameSharingUpdate(n: c_int) void; -pub const enum_pspUtilityHtmlViewerDisconnectModes = extern enum(c_int) { - PSP_UTILITY_HTMLVIEWER_DISCONNECTMODE_ENABLE = 0, - PSP_UTILITY_HTMLVIEWER_DISCONNECTMODE_DISABLE = 1, - PSP_UTILITY_HTMLVIEWER_DISCONNECTMODE_CONFIRM = 2, - _, -}; -pub const enum_pspUtilityHtmlViewerInterfaceModes = extern enum(c_int) { - PSP_UTILITY_HTMLVIEWER_INTERFACEMODE_FULL = 0, - PSP_UTILITY_HTMLVIEWER_INTERFACEMODE_LIMITED = 1, - PSP_UTILITY_HTMLVIEWER_INTERFACEMODE_NONE = 2, - _, -}; -pub const enum_pspUtilityHtmlViewerCookieModes = extern enum(c_int) { - PSP_UTILITY_HTMLVIEWER_COOKIEMODE_DISABLED = 0, - PSP_UTILITY_HTMLVIEWER_COOKIEMODE_ENABLED = 1, - PSP_UTILITY_HTMLVIEWER_COOKIEMODE_CONFIRM = 2, - PSP_UTILITY_HTMLVIEWER_COOKIEMODE_DEFAULT = 3, - _, -}; -pub const enum_pspUtilityHtmlViewerTextSizes = extern enum(c_int) { - PSP_UTILITY_HTMLVIEWER_TEXTSIZE_LARGE = 0, - PSP_UTILITY_HTMLVIEWER_TEXTSIZE_NORMAL = 1, - PSP_UTILITY_HTMLVIEWER_TEXTSIZE_SMALL = 2, - _, -}; -pub const enum_pspUtilityHtmlViewerDisplayModes = extern enum(c_int) { - PSP_UTILITY_HTMLVIEWER_DISPLAYMODE_NORMAL = 0, - PSP_UTILITY_HTMLVIEWER_DISPLAYMODE_FIT = 1, - PSP_UTILITY_HTMLVIEWER_DISPLAYMODE_SMART_FIT = 2, + +pub const PspUtilityHtmlViewerTextSizes = extern enum(c_int) { + Large = 0, + Normal = 1, + Small = 2, _, }; -pub const enum_pspUtilityHtmlViewerConnectModes = extern enum(c_int) { - PSP_UTILITY_HTMLVIEWER_CONNECTMODE_LAST = 0, - PSP_UTILITY_HTMLVIEWER_CONNECTMODE_MANUAL_ONCE = 1, - PSP_UTILITY_HTMLVIEWER_CONNECTMODE_MANUAL_ALL = 2, +pub const PspUtilityHtmlViewerDisplayModes = extern enum(c_int) { + Normal = 0, + Fit = 1, + SmartFit = 2, _, }; -pub const enum_pspUtilityHtmlViewerOptions = extern enum(c_int) { - PSP_UTILITY_HTMLVIEWER_OPEN_SCE_START_PAGE = 1, - PSP_UTILITY_HTMLVIEWER_DISABLE_STARTUP_LIMITS = 2, - PSP_UTILITY_HTMLVIEWER_DISABLE_EXIT_DIALOG = 4, - PSP_UTILITY_HTMLVIEWER_DISABLE_CURSOR = 8, - PSP_UTILITY_HTMLVIEWER_DISABLE_DOWNLOAD_COMPLETE_DIALOG = 16, - PSP_UTILITY_HTMLVIEWER_DISABLE_DOWNLOAD_START_DIALOG = 32, - PSP_UTILITY_HTMLVIEWER_DISABLE_DOWNLOAD_DESTINATION_DIALOG = 64, - PSP_UTILITY_HTMLVIEWER_LOCK_DOWNLOAD_DESTINATION_DIALOG = 128, - PSP_UTILITY_HTMLVIEWER_DISABLE_TAB_DISPLAY = 256, - PSP_UTILITY_HTMLVIEWER_ENABLE_ANALOG_HOLD = 512, - PSP_UTILITY_HTMLVIEWER_ENABLE_FLASH = 1024, - PSP_UTILITY_HTMLVIEWER_DISABLE_LRTRIGGER = 2048, +pub const PspUtilityHtmlViewerConnectModes = extern enum(c_int) { + Last = 0, + ManualOnce = 1, + ManualAll = 2, _, }; -pub const struct_pspUtilityHtmlViewerParam = extern struct { - base: pspUtilityDialogCommon, +pub const PspUtilityHtmlViewerOptions = extern enum(c_int) { + OpenSceStartPage = 1, + DisableStartupLimits = 2, + DisableExitDialog = 4, + DisableCursor = 8, + DisableDownloadCompleteDialog = 16, + DisableDownloadStartDialog = 32, + DisableDownloadDestinationDialog = 64, + LockDownloadDestinationDialog = 128, + DisableTabDisplay = 256, + EnableAnalogHold = 512, + EnableFlash = 1024, + DisableLRTrigger = 2048, +}; +pub const PspUtilityHtmlViewerParam = extern struct { + base: PspUtilityDialogCommon, memaddr: ?*c_void, memsize: c_uint, unknown1: c_int, @@ -265,65 +336,9 @@ pub const struct_pspUtilityHtmlViewerParam = extern struct { memused: c_uint, unknown4: [10]c_int, }; -pub const pspUtilityHtmlViewerParam = struct_pspUtilityHtmlViewerParam; -pub extern fn sceUtilityHtmlViewerInitStart(params: [*c]pspUtilityHtmlViewerParam) c_int; -pub extern fn sceUtilityHtmlViewerShutdownStart() c_int; -pub extern fn sceUtilityHtmlViewerUpdate(n: c_int) c_int; -pub extern fn sceUtilityHtmlViewerGetStatus() c_int; -pub extern fn sceUtilitySetSystemParamInt(id: c_int, value: c_int) c_int; -pub extern fn sceUtilitySetSystemParamString(id: c_int, str: [*c]const u8) c_int; -pub extern fn sceUtilityGetSystemParamInt(id: c_int, value: [*c]c_int) c_int; -pub extern fn sceUtilityGetSystemParamString(id: c_int, str: [*c]u8, len: c_int) c_int; -pub const enum_SceUtilityOskInputLanguage = extern enum(c_int) { - PSP_UTILITY_OSK_LANGUAGE_DEFAULT = 0, - PSP_UTILITY_OSK_LANGUAGE_JAPANESE = 1, - PSP_UTILITY_OSK_LANGUAGE_ENGLISH = 2, - PSP_UTILITY_OSK_LANGUAGE_FRENCH = 3, - PSP_UTILITY_OSK_LANGUAGE_SPANISH = 4, - PSP_UTILITY_OSK_LANGUAGE_GERMAN = 5, - PSP_UTILITY_OSK_LANGUAGE_ITALIAN = 6, - PSP_UTILITY_OSK_LANGUAGE_DUTCH = 7, - PSP_UTILITY_OSK_LANGUAGE_PORTUGESE = 8, - PSP_UTILITY_OSK_LANGUAGE_RUSSIAN = 9, - PSP_UTILITY_OSK_LANGUAGE_KOREAN = 10, - _, -}; -pub const enum_SceUtilityOskState = extern enum(c_int) { - PSP_UTILITY_OSK_DIALOG_NONE = 0, - PSP_UTILITY_OSK_DIALOG_INITING = 1, - PSP_UTILITY_OSK_DIALOG_INITED = 2, - PSP_UTILITY_OSK_DIALOG_VISIBLE = 3, - PSP_UTILITY_OSK_DIALOG_QUIT = 4, - PSP_UTILITY_OSK_DIALOG_FINISHED = 5, - _, -}; -pub const enum_SceUtilityOskResult = extern enum(c_int) { - PSP_UTILITY_OSK_RESULT_UNCHANGED = 0, - PSP_UTILITY_OSK_RESULT_CANCELLED = 1, - PSP_UTILITY_OSK_RESULT_CHANGED = 2, - _, -}; -pub const enum_SceUtilityOskInputType = extern enum(c_int) { - PSP_UTILITY_OSK_INPUTTYPE_ALL = 0, - PSP_UTILITY_OSK_INPUTTYPE_LATIN_DIGIT = 1, - PSP_UTILITY_OSK_INPUTTYPE_LATIN_SYMBOL = 2, - PSP_UTILITY_OSK_INPUTTYPE_LATIN_LOWERCASE = 4, - PSP_UTILITY_OSK_INPUTTYPE_LATIN_UPPERCASE = 8, - PSP_UTILITY_OSK_INPUTTYPE_JAPANESE_DIGIT = 256, - PSP_UTILITY_OSK_INPUTTYPE_JAPANESE_SYMBOL = 512, - PSP_UTILITY_OSK_INPUTTYPE_JAPANESE_LOWERCASE = 1024, - PSP_UTILITY_OSK_INPUTTYPE_JAPANESE_UPPERCASE = 2048, - PSP_UTILITY_OSK_INPUTTYPE_JAPANESE_HIRAGANA = 4096, - PSP_UTILITY_OSK_INPUTTYPE_JAPANESE_HALF_KATAKANA = 8192, - PSP_UTILITY_OSK_INPUTTYPE_JAPANESE_KATAKANA = 16384, - PSP_UTILITY_OSK_INPUTTYPE_JAPANESE_KANJI = 32768, - PSP_UTILITY_OSK_INPUTTYPE_RUSSIAN_LOWERCASE = 65536, - PSP_UTILITY_OSK_INPUTTYPE_RUSSIAN_UPPERCASE = 131072, - PSP_UTILITY_OSK_INPUTTYPE_KOREAN = 262144, - PSP_UTILITY_OSK_INPUTTYPE_URL = 524288, - _, -}; -pub const struct__SceUtilityOskData = extern struct { + + +pub const SceUtilityOskData = extern struct { unk_00: c_int, unk_04: c_int, language: c_int, @@ -338,55 +353,14 @@ pub const struct__SceUtilityOskData = extern struct { result: c_int, outtextlimit: c_int, }; -pub const SceUtilityOskData = struct__SceUtilityOskData; -pub const struct__SceUtilityOskParams = extern struct { - base: pspUtilityDialogCommon, + +pub const SceUtilityOskParams = extern struct { + base: PspUtilityDialogCommon, datacount: c_int, data: [*c]SceUtilityOskData, state: c_int, unk_60: c_int, }; -pub const SceUtilityOskParams = struct__SceUtilityOskParams; -pub extern fn sceUtilityOskInitStart(params: [*c]SceUtilityOskParams) c_int; -pub extern fn sceUtilityOskShutdownStart() c_int; -pub extern fn sceUtilityOskUpdate(n: c_int) c_int; -pub extern fn sceUtilityOskGetStatus() c_int; -pub extern fn sceUtilityLoadNetModule(module: c_int) c_int; -pub extern fn sceUtilityUnloadNetModule(module: c_int) c_int; -pub extern fn sceUtilityLoadAvModule(module: c_int) c_int; -pub extern fn sceUtilityUnloadAvModule(module: c_int) c_int; -pub extern fn sceUtilityLoadUsbModule(module: c_int) c_int; -pub extern fn sceUtilityUnloadUsbModule(module: c_int) c_int; -pub extern fn sceUtilityLoadModule(module: c_int) c_int; -pub extern fn sceUtilityUnloadModule(module: c_int) c_int; -const enum_unnamed_14 = extern enum(c_int) { - PSP_UTILITY_DIALOG_NONE = 0, - PSP_UTILITY_DIALOG_INIT = 1, - PSP_UTILITY_DIALOG_VISIBLE = 2, - PSP_UTILITY_DIALOG_QUIT = 3, - PSP_UTILITY_DIALOG_FINISHED = 4, - _, -}; -pub const pspUtilityDialogState = enum_unnamed_14; - -pub const _pspUtilityMsgDialogParams = struct__pspUtilityMsgDialogParams; -pub const pspUtilityNetconfActions = enum_pspUtilityNetconfActions; -pub const pspUtilityNetconfAdhoc = struct_pspUtilityNetconfAdhoc; -pub const _pspUtilityNetconfData = struct__pspUtilityNetconfData; -pub const _pspUtilityGameSharingParams = struct__pspUtilityGameSharingParams; -pub const pspUtilityHtmlViewerDisconnectModes = enum_pspUtilityHtmlViewerDisconnectModes; -pub const pspUtilityHtmlViewerInterfaceModes = enum_pspUtilityHtmlViewerInterfaceModes; -pub const pspUtilityHtmlViewerCookieModes = enum_pspUtilityHtmlViewerCookieModes; -pub const pspUtilityHtmlViewerTextSizes = enum_pspUtilityHtmlViewerTextSizes; -pub const pspUtilityHtmlViewerDisplayModes = enum_pspUtilityHtmlViewerDisplayModes; -pub const pspUtilityHtmlViewerConnectModes = enum_pspUtilityHtmlViewerConnectModes; -pub const pspUtilityHtmlViewerOptions = enum_pspUtilityHtmlViewerOptions; -pub const SceUtilityOskInputLanguage = enum_SceUtilityOskInputLanguage; -pub const SceUtilityOskState = enum_SceUtilityOskState; -pub const SceUtilityOskResult = enum_SceUtilityOskResult; -pub const SceUtilityOskInputType = enum_SceUtilityOskInputType; -pub const _SceUtilityOskData = struct__SceUtilityOskData; -pub const _SceUtilityOskParams = struct__SceUtilityOskParams; pub const ModuleNet = extern enum(c_int){ Common = 1, diff --git a/src/psp/sdk/psputils.zig b/src/psp/sdk/psputils.zig index a6090e3..ee25458 100644 --- a/src/psp/sdk/psputils.zig +++ b/src/psp/sdk/psputils.zig @@ -2,32 +2,21 @@ usingnamespace @import("psptypes.zig"); pub const clock_t = u32; pub const suseconds_t = u32; -pub const struct_timeval = extern struct { +pub const timeval = extern struct { tv_sec: time_t, tv_usec: suseconds_t, }; -pub const struct_timezone = extern struct { +pub const timezone = extern struct { tz_minuteswest: c_int, tz_dsttime: c_int, }; -pub extern fn sceKernelLibcTime(t: [*c]time_t) time_t; -pub extern fn sceKernelLibcClock() clock_t; -pub extern fn sceKernelLibcGettimeofday(tp: [*c]struct_timeval, tzp: [*c]struct_timezone) c_int; -pub extern fn sceKernelDcacheWritebackAll() void; -pub extern fn sceKernelDcacheWritebackInvalidateAll() void; -pub extern fn sceKernelDcacheWritebackRange(p: ?*const c_void, size: c_uint) void; -pub extern fn sceKernelDcacheWritebackInvalidateRange(p: ?*const c_void, size: c_uint) void; -pub extern fn sceKernelDcacheInvalidateRange(p: ?*const c_void, size: c_uint) void; -pub extern fn sceKernelIcacheInvalidateAll() void; -pub extern fn sceKernelIcacheInvalidateRange(p: ?*const c_void, size: c_uint) void; -pub const struct__SceKernelUtilsMt19937Context = extern struct { + +pub const SceKernelUtilsMt19937Context = extern struct { count: c_uint, state: [624]c_uint, }; -pub const SceKernelUtilsMt19937Context = struct__SceKernelUtilsMt19937Context; -pub extern fn sceKernelUtilsMt19937Init(ctx: [*c]SceKernelUtilsMt19937Context, seed: u32) c_int; -pub extern fn sceKernelUtilsMt19937UInt(ctx: [*c]SceKernelUtilsMt19937Context) u32; -pub const struct__SceKernelUtilsMd5Context = extern struct { + +pub const SceKernelUtilsMd5Context = extern struct { h: [4]c_uint, pad: c_uint, usRemains: SceUShort16, @@ -35,25 +24,211 @@ pub const struct__SceKernelUtilsMd5Context = extern struct { ullTotalLen: SceULong64, buf: [64]u8, }; -pub const SceKernelUtilsMd5Context = struct__SceKernelUtilsMd5Context; -pub extern fn sceKernelUtilsMd5Digest(data: [*c]u8, size: u32, digest: [*c]u8) c_int; -pub extern fn sceKernelUtilsMd5BlockInit(ctx: [*c]SceKernelUtilsMd5Context) c_int; -pub extern fn sceKernelUtilsMd5BlockUpdate(ctx: [*c]SceKernelUtilsMd5Context, data: [*c]u8, size: u32) c_int; -pub extern fn sceKernelUtilsMd5BlockResult(ctx: [*c]SceKernelUtilsMd5Context, digest: [*c]u8) c_int; -pub const struct__SceKernelUtilsSha1Context = extern struct { + +pub const SceKernelUtilsSha1Context = extern struct { h: [5]c_uint, usRemains: SceUShort16, usComputed: SceUShort16, ullTotalLen: SceULong64, buf: [64]u8, }; -pub const SceKernelUtilsSha1Context = struct__SceKernelUtilsSha1Context; -pub extern fn sceKernelUtilsSha1Digest(data: [*c]u8, size: u32, digest: [*c]u8) c_int; -pub extern fn sceKernelUtilsSha1BlockInit(ctx: [*c]SceKernelUtilsSha1Context) c_int; -pub extern fn sceKernelUtilsSha1BlockUpdate(ctx: [*c]SceKernelUtilsSha1Context, data: [*c]u8, size: u32) c_int; -pub extern fn sceKernelUtilsSha1BlockResult(ctx: [*c]SceKernelUtilsSha1Context, digest: [*c]u8) c_int; -pub const timeval = struct_timeval; -pub const timezone = struct_timezone; -pub const _SceKernelUtilsMt19937Context = struct__SceKernelUtilsMt19937Context; -pub const _SceKernelUtilsMd5Context = struct__SceKernelUtilsMd5Context; -pub const _SceKernelUtilsSha1Context = struct__SceKernelUtilsSha1Context; + + +// Function to initialise a mersenne twister context. +// +// @param ctx - Pointer to a context +// @param seed - A seed for the random function. +// +// @par Example: +// @code +// SceKernelUtilsMt19937Context ctx; +// sceKernelUtilsMt19937Init(&ctx, time(NULL)); +// u23 rand_val = sceKernelUtilsMt19937UInt(&ctx); +// @endcode +// +// @return < 0 on error. +pub extern fn sceKernelUtilsMt19937Init(ctx: *SceKernelUtilsMt19937Context, seed: u32) c_int; +pub fn kernelUtilsMt19937Init(ctx: *SceKernelUtilsMt19937Context, seed: u32) !i32 { + var res = sceKernelUtilsMt19937Init(ctx, seed); + if(res < 0){ + return error.Unexpected; + } + return res; +} + + +// Function to return a new psuedo random number. +// +// @param ctx - Pointer to a pre-initialised context. +// @return A pseudo random number (between 0 and MAX_INT). +pub extern fn sceKernelUtilsMt19937UInt(ctx: *SceKernelUtilsMt19937Context) u32; + + +// Function to perform an MD5 digest of a data block. +// +// @param data - Pointer to a data block to make a digest of. +// @param size - Size of the data block. +// @param digest - Pointer to a 16byte buffer to store the resulting digest +// +// @return < 0 on error. +pub extern fn sceKernelUtilsMd5Digest(data: [*]u8, size: u32, digest: [*]u8) c_int; +pub fn kernelUtilsMd5Digest(data: [*]u8, size: u32, digest: [*]u8) !i32 { + var res = sceKernelUtilsMd5Digest(data, size, digest); + if(res < 0){ + return error.Unexpected; + } + return res; +} + +// Function to initialise a MD5 digest context +// +// @param ctx - A context block to initialise +// +// @return < 0 on error. + +// C Example +// SceKernelUtilsMd5Context ctx; +// u8 digest[16]; +// sceKernelUtilsMd5BlockInit(&ctx); +// sceKernelUtilsMd5BlockUpdate(&ctx, (u8*) "Hello", 5); +// sceKernelUtilsMd5BlockResult(&ctx, digest); +pub extern fn sceKernelUtilsMd5BlockInit(ctx: *SceKernelUtilsMd5Context) c_int; +pub fn kernelUtilsMd5BlockInit(ctx: *SceKernelUtilsMd5Context) !i32{ + var res = sceKernelUtilsMd5BlockInit(ctx); + if(res < 0){ + return error.Unexpected; + } + return res; +} + + +// Function to update the MD5 digest with a block of data. +// +// @param ctx - A filled in context block. +// @param data - The data block to hash. +// @param size - The size of the data to hash +// +// @return < 0 on error. +pub extern fn sceKernelUtilsMd5BlockUpdate(ctx: *SceKernelUtilsMd5Context, data: [*]u8, size: u32) c_int; +pub fn kernelUtilsMd5BlockUpdate(ctx: *SceKernelUtilsMd5Context, data: [*]u8, size: u32) !i32 { + var res = sceKernelUtilsMd5BlockUpdate(ctx, data, size); + if (res < 0){ + return error.Unexpected; + } + return res; +} + + +// Function to get the digest result of the MD5 hash. +// +// @param ctx - A filled in context block. +// @param digest - A 16 byte array to hold the digest. +// +// @return < 0 on error. +pub extern fn sceKernelUtilsMd5BlockResult(ctx: *SceKernelUtilsMd5Context, digest: [*]u8) c_int; +pub fn kernelUtilsMd5BlockResult(ctx: *SceKernelUtilsMd5Context, digest: [*]u8) !i32 { + var res = sceKernelUtilsMd5BlockResult(ctx, digest); + if(res < 0){ + return error.Unexpected; + } + return res; +} + + +// Function to SHA1 hash a data block. +// +// @param data - The data to hash. +// @param size - The size of the data. +// @param digest - Pointer to a 20 byte array for storing the digest +// +// @return < 0 on error. +pub extern fn sceKernelUtilsSha1Digest(data: [*]u8, size: u32, digest: [*]u8) c_int; +pub fn kernelUtilsSha1Digest(data: [*]u8, size: u32, digest: [*]u8) !i32{ + var res = sceKernelUtilsSha1Digest(data, size, digest); + if(res < 0){ + return error.Unexpected; + } + return res; +} + +// Function to initialise a context for SHA1 hashing. +// +// @param ctx - Pointer to a context. +// +// @return < 0 on error. + +// C Code Example +// SceKernelUtilsSha1Context ctx; +// u8 digest[20]; +// sceKernelUtilsSha1BlockInit(&ctx); +// sceKernelUtilsSha1BlockUpdate(&ctx, (u8*) "Hello", 5); +// sceKernelUtilsSha1BlockResult(&ctx, digest); +pub extern fn sceKernelUtilsSha1BlockInit(ctx: *SceKernelUtilsSha1Context) c_int; +pub fn kernelUtilsSha1BlockInit(ctx: *SceKernelUtilsSha1Context) !i32{ + var res = sceKernelUtilsSha1BlockInit(ctx); + if(res < 0){ + return error.Unexpected; + } + return res; +} + +// Function to update the current hash. +// +// @param ctx - Pointer to a prefilled context. +// @param data - The data block to hash. +// @param size - The size of the data block +// +// @return < 0 on error. +pub extern fn sceKernelUtilsSha1BlockUpdate(ctx: *SceKernelUtilsSha1Context, data: [*]u8, size: u32) c_int; +pub fn kernelUtilsSha1BlockUpdate(ctx: *SceKernelUtilsSha1Context, data: [*]u8, size: u32) !i32{ + var res = sceKernelUtilsSha1BlockUpdate(ctx, data, size); + if(res < 0){ + return error.Unexpected; + } + return res; +} + +// Function to get the result of the SHA1 hash. +// +// @param ctx - Pointer to a prefilled context. +// @param digest - A pointer to a 20 byte array to contain the digest. +// +// @return < 0 on error. +pub extern fn sceKernelUtilsSha1BlockResult(ctx: *SceKernelUtilsSha1Context, digest: [*]u8) c_int; +pub fn kernelUtilsSha1BlockResult(ctx: *SceKernelUtilsSha1Context, digest: [*]u8) !i32{ + var res = sceKernelUtilsSha1BlockResult(ctx, digest); + if(res < 0){ + return error.Unexpected; + } + return res; +} + +// Get the time in seconds since the epoc (1st Jan 1970) +pub extern fn sceKernelLibcTime(t: *time_t) time_t; + +// Get the processor clock used since the start of the process +pub extern fn sceKernelLibcClock() clock_t; + +// Get the current time of time and time zone information +pub extern fn sceKernelLibcGettimeofday(tp: *timeval, tzp: *timezone) c_int; + +//Write back the data cache to memory +pub extern fn sceKernelDcacheWritebackAll() void; + +//Write back and invalidate the data cache +pub extern fn sceKernelDcacheWritebackInvalidateAll() void; + +//Write back a range of addresses from the data cache to memory +pub extern fn sceKernelDcacheWritebackRange(p: ?*const c_void, size: c_uint) void; + +//Write back and invalidate a range of addresses in the data cache +pub extern fn sceKernelDcacheWritebackInvalidateRange(p: ?*const c_void, size: c_uint) void; + +//Invalidate a range of addresses in data cache +pub extern fn sceKernelDcacheInvalidateRange(p: ?*const c_void, size: c_uint) void; + +//Invalidate the instruction cache +pub extern fn sceKernelIcacheInvalidateAll() void; + +//Invalidate a range of addresses in the instruction cache +pub extern fn sceKernelIcacheInvalidateRange(p: ?*const c_void, size: c_uint) void; diff --git a/src/psp/sdk/pspwlan.zig b/src/psp/sdk/pspwlan.zig index b2217b1..dfbbdc5 100644 --- a/src/psp/sdk/pspwlan.zig +++ b/src/psp/sdk/pspwlan.zig @@ -1,3 +1,34 @@ + +// Determine if the wlan device is currently powered on +// +// @return 0 if off, 1 if on pub extern fn sceWlanDevIsPowerOn() c_int; + +pub fn wlanDevIsPowerOn() bool { + return sceWlanDevIsPowerOn() == 1; +} + + +// Determine the state of the Wlan power switch +// +// @return 0 if off, 1 if on pub extern fn sceWlanGetSwitchState() c_int; + +pub fn wlanGetSwitchState() bool { + return sceWlanGetSwitchState() == 1; +} + + +// Get the Ethernet Address of the wlan controller +// +// @param etherAddr - pointer to a buffer of u8 (NOTE: it only writes to 6 bytes, but +// requests 8 so pass it 8 bytes just in case) +// @return 0 on success, < 0 on error pub extern fn sceWlanGetEtherAddr(etherAddr: [*c]u8) c_int; + +pub fn wlanGetEtherAddr(etherAddr: []u8) !void { + var res = sceWlanGetEtherAddr(etherAddr); + if(res < 0){ + return error.Unexpected; + } +} diff --git a/src/psp/utils/module.zig b/src/psp/utils/module.zig index d24133d..4bc8ee8 100644 --- a/src/psp/utils/module.zig +++ b/src/psp/utils/module.zig @@ -15,9 +15,13 @@ pub fn exitErr() void { sceKernelExitGame(); } +const has_std_os = if(@hasDecl(root, "os")) true else false; + //This calls your main function as a thread. pub fn _module_main_thread(argc: SceSize, argv: ?*c_void) callconv(.C) c_int { - pspos.system.__pspOsInit(argv); + if(has_std_os){ + pspos.system.__pspOsInit(argv); + } switch (@typeInfo(@typeInfo(@TypeOf(root.main)).Fn.return_type.?)) { .NoReturn => {