Skip to content

Commit

Permalink
Reg, UMD, OS Switch
Browse files Browse the repository at this point in the history
  • Loading branch information
IridescentRose committed Oct 15, 2020
1 parent 510623a commit 09e3a0d
Show file tree
Hide file tree
Showing 10 changed files with 461 additions and 65 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
4 changes: 1 addition & 3 deletions src/main.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const psp = @import("psp/pspsdk.zig");
pub const panic = psp.debug.panic;
const psp = @import("psp/utils/psp.zig");

comptime{
asm(psp.module_info("Zig PSP", 0, 1, 0));
Expand All @@ -8,6 +7,5 @@ comptime{
pub fn main() !void {
psp.utils.enableHBCB();
psp.debug.screenInit();

psp.debug.print("Hi!");
}
2 changes: 0 additions & 2 deletions src/psp/include/pspimpose.zig

This file was deleted.

1 change: 0 additions & 1 deletion src/psp/libzpsp.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ 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
1 change: 0 additions & 1 deletion src/psp/pspsdk.zig
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ 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
4 changes: 2 additions & 2 deletions src/psp/sdk/pspmp3.zig
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -10,7 +10,7 @@ pub const struct_SceMp3InitArg = extern struct {
pcmBuf: ?*SceVoid,
pcmBufSize: SceInt32,
};
pub const SceMp3InitArg = struct_SceMp3InitArg;

pub extern fn sceMp3ReserveMp3Handle(args: [*c]SceMp3InitArg) SceInt32;
pub extern fn sceMp3ReleaseMp3Handle(handle: SceInt32) SceInt32;
pub extern fn sceMp3InitResource(...) SceInt32;
Expand Down
265 changes: 243 additions & 22 deletions src/psp/sdk/pspreg.zig
Original file line number Diff line number Diff line change
@@ -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;
}
}
Loading

0 comments on commit 09e3a0d

Please sign in to comment.