Skip to content

Commit

Permalink
Merge pull request #4 from zPSP-Dev/zSafe
Browse files Browse the repository at this point in the history
Z safe
  • Loading branch information
IridescentRose authored Oct 15, 2020
2 parents d0bdc45 + 147bd16 commit cca6463
Show file tree
Hide file tree
Showing 36 changed files with 2,978 additions and 844 deletions.
4 changes: 3 additions & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/main.zig
Original file line number Diff line number Diff line change
@@ -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!");
}
2 changes: 2 additions & 0 deletions src/psp/include/pspdmac.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub usingnamespace @import("../nids/pspdmac.zig");
pub usingnamespace @import("../sdk/pspdmac.zig");
2 changes: 0 additions & 2 deletions src/psp/include/pspimpose.zig

This file was deleted.

2 changes: 1 addition & 1 deletion src/psp/libzpsp.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
7 changes: 7 additions & 0 deletions src/psp/nids/pspdmac.zig
Original file line number Diff line number Diff line change
@@ -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"));
}
17 changes: 0 additions & 17 deletions src/psp/nids/pspimpose.zig

This file was deleted.

2 changes: 1 addition & 1 deletion src/psp/pspsdk.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
215 changes: 205 additions & 10 deletions src/psp/sdk/pspatrac3.zig
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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;
Expand Down
Loading

0 comments on commit cca6463

Please sign in to comment.