From 89e3a380db11d1edc0476c79ada866cb3c59bd79 Mon Sep 17 00:00:00 2001 From: Jae B Date: Mon, 27 May 2024 09:27:56 +1000 Subject: [PATCH 1/5] update to zig 0.13 --- build-psp.zig | 26 +++++++++++++------------- src/psp/os/system.zig | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/build-psp.zig b/build-psp.zig index c656012..5faa9be 100644 --- a/build-psp.zig +++ b/build-psp.zig @@ -43,17 +43,17 @@ pub fn build_psp(b: *std.Build, comptime build_info: PSPBuildInfo) !void { //Build from your main file! const exe = b.addExecutable(.{ .name = "main", - .root_source_file = .{ .path = build_info.src_file }, + .root_source_file = b.path(build_info.src_file), .target = target, .optimize = optimize, + // .strip = true, + // .single_threaded = true, }); - exe.setLinkerScriptPath(.{ .path = build_info.path_to_sdk ++ "tools/linkfile.ld" }); + exe.setLinkerScriptPath(b.path(build_info.path_to_sdk ++ "tools/linkfile.ld")); exe.link_eh_frame_hdr = true; exe.link_emit_relocs = true; - // exe.strip = true; - // exe.single_threaded = true; // exe.install(); // b.installArtifact(exe); @@ -63,13 +63,13 @@ pub fn build_psp(b: *std.Build, comptime build_info: PSPBuildInfo) !void { const hostTarget = b.standardTargetOptions(.{}); const prx = b.addExecutable(.{ .name = "prxgen", - .root_source_file = .{ .path = build_info.path_to_sdk ++ "tools/prxgen/stub.zig" }, + .root_source_file = b.path(build_info.path_to_sdk ++ "tools/prxgen/stub.zig"), .link_libc = true, .target = hostTarget, .optimize = .ReleaseFast, }); prx.addCSourceFile(.{ - .file = .{ .path = build_info.path_to_sdk ++ "tools/prxgen/psp-prxgen.c" }, + .file = b.path(build_info.path_to_sdk ++ "tools/prxgen/psp-prxgen.c"), .flags = &[_][]const u8{ "-std=c99", "-Wno-address-of-packed-member", @@ -91,7 +91,7 @@ pub fn build_psp(b: *std.Build, comptime build_info: PSPBuildInfo) !void { //Build SFO const sfo = b.addExecutable(.{ .name = "sfotool", - .root_source_file = .{ .path = build_info.path_to_sdk ++ "tools/sfo/src/main.zig" }, + .root_source_file = b.path(build_info.path_to_sdk ++ "tools/sfo/src/main.zig"), .target = hostTarget, .optimize = optimize, }); @@ -109,7 +109,7 @@ pub fn build_psp(b: *std.Build, comptime build_info: PSPBuildInfo) !void { //Build PBP const PBP = b.addExecutable(.{ .name = "pbptool", - .root_source_file = .{ .path = build_info.path_to_sdk ++ "tools/pbp/src/main.zig" }, + .root_source_file = b.path(build_info.path_to_sdk ++ "tools/pbp/src/main.zig"), .target = hostTarget, .optimize = .ReleaseFast, }); @@ -120,11 +120,11 @@ pub fn build_psp(b: *std.Build, comptime build_info: PSPBuildInfo) !void { pack_pbp.addArg("pack"); const eboot_file = pack_pbp.addOutputFileArg("EBOOT.PBP"); pack_pbp.addFileArg(sfo_file); - pack_pbp.addFileArg(.{ .path = build_info.icon0 }); - pack_pbp.addFileArg(.{ .path = build_info.icon1 }); - pack_pbp.addFileArg(.{ .path = build_info.pic0 }); - pack_pbp.addFileArg(.{ .path = build_info.pic1 }); - pack_pbp.addFileArg(.{ .path = build_info.snd0 }); + pack_pbp.addFileArg(b.path(build_info.icon0)); + pack_pbp.addFileArg(b.path(build_info.icon1)); + pack_pbp.addFileArg(b.path(build_info.pic0)); + pack_pbp.addFileArg(b.path(build_info.pic1)); + pack_pbp.addFileArg(b.path(build_info.snd0)); pack_pbp.addFileArg(prx_file); pack_pbp.addArg("NULL"); diff --git a/src/psp/os/system.zig b/src/psp/os/system.zig index 90131d2..f9befd5 100644 --- a/src/psp/os/system.zig +++ b/src/psp/os/system.zig @@ -255,7 +255,7 @@ pub fn lseek(fd: fd_t, off: i64, whence: c_int) c_int { switch (fdman.__psp_descriptormap[fd].?.ftype) { .File => { - std.debug.warn("{}", .{whence}); + std.log.warn("{}", .{whence}); //If you need to seek past 4GB, you have a real problem. return pspErrToErrno(@as(u32, @bitCast(pspiofilemgr.sceIoLseek32(fdman.__psp_descriptormap[fd].?.sce_descriptor, @as(c_int, @truncate(off)), whence)))); }, From 869087053a1bcf1f0730b2222fbaff09334649fd Mon Sep 17 00:00:00 2001 From: Jae B Date: Tue, 28 May 2024 09:37:15 +1000 Subject: [PATCH 2/5] update "?fn (" to "?*const fn (" Fixes issue at: https://github.com/ziglang/zig/issues/20083 --- src/psp/sdk/pspge.zig | 2 +- src/psp/sdk/pspguimpl.zig | 4 ++-- src/psp/sdk/psphttp.zig | 4 ++-- src/psp/sdk/pspiofilemgr.zig | 44 ++++++++++++++++++------------------ src/psp/sdk/pspmpeg.zig | 2 +- src/psp/sdk/pspnet.zig | 6 ++--- src/psp/sdk/psppower.zig | 2 +- src/psp/sdk/pspthreadman.zig | 10 ++++---- src/psp/sdk/pspumd.zig | 2 +- 9 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/psp/sdk/pspge.zig b/src/psp/sdk/pspge.zig index 3f592f1..b85d5c2 100644 --- a/src/psp/sdk/pspge.zig +++ b/src/psp/sdk/pspge.zig @@ -6,7 +6,7 @@ pub const SceGeStack = extern struct { stack: [8]c_uint, }; -pub const PspGeCallback = ?fn (c_int, ?*anyopaque) callconv(.C) void; +pub const PspGeCallback = ?*const fn (c_int, ?*anyopaque) callconv(.C) void; pub const PspGeCallbackData = extern struct { signal_func: PspGeCallback, signal_arg: ?*anyopaque, diff --git a/src/psp/sdk/pspguimpl.zig b/src/psp/sdk/pspguimpl.zig index b835002..c5a8527 100644 --- a/src/psp/sdk/pspguimpl.zig +++ b/src/psp/sdk/pspguimpl.zig @@ -8,7 +8,7 @@ test { } //Internals -pub const GuCallback = ?fn (c_int) callconv(.C) void; +pub const GuCallback = ?*const fn (c_int) callconv(.C) void; const GuSettings = struct { sig: GuCallback, @@ -1044,7 +1044,7 @@ pub fn sceGuSetAllStatus(status: c_int) void { } } -pub fn sceGuSetCallback(signal: c_int, callback: ?fn (c_int) callconv(.C) void) GuCallback { +pub fn sceGuSetCallback(signal: c_int, callback: ?*const fn (c_int) callconv(.C) void) GuCallback { var old_callback: GuCallback = undefined; switch (@as(pspgutypes.GuCallbackId, @enumFromInt(signal))) { diff --git a/src/psp/sdk/psphttp.zig b/src/psp/sdk/psphttp.zig index 3ffa559..889d8a2 100644 --- a/src/psp/sdk/psphttp.zig +++ b/src/psp/sdk/psphttp.zig @@ -40,8 +40,8 @@ const enum_unnamed_9 = enum(c_int) { pub const PspHttpAddHeaderMode = enum_unnamed_9; pub const PspHttpMallocFunction = ?*const fn (SceSize) callconv(.C) ?*anyopaque; pub const PspHttpReallocFunction = ?*const fn (?*anyopaque, SceSize) callconv(.C) ?*anyopaque; -pub const PspHttpFreeFunction = ?fn (?*anyopaque) callconv(.C) void; -pub const PspHttpPasswordCB = ?fn (c_int, PspHttpAuthType, [*c]const u8, [*c]u8, [*c]u8, SceBool, [*c][*c]u8, [*c]SceSize, [*c]SceBool) callconv(.C) c_int; +pub const PspHttpFreeFunction = ?*const fn (?*anyopaque) callconv(.C) void; +pub const PspHttpPasswordCB = ?*const fn (c_int, PspHttpAuthType, [*c]const u8, [*c]u8, [*c]u8, SceBool, [*c][*c]u8, [*c]SceSize, [*c]SceBool) callconv(.C) c_int; pub extern fn sceHttpInit(unknown1: c_uint) c_int; pub extern fn sceHttpEnd() c_int; pub extern fn sceHttpCreateTemplate(agent: [*c]u8, unknown1: c_int, unknown2: c_int) c_int; diff --git a/src/psp/sdk/pspiofilemgr.zig b/src/psp/sdk/pspiofilemgr.zig index 76931b2..1b7394e 100644 --- a/src/psp/sdk/pspiofilemgr.zig +++ b/src/psp/sdk/pspiofilemgr.zig @@ -134,28 +134,28 @@ pub const struct_PspIoDrvFileArg = extern struct { }; pub const PspIoDrvFileArg = struct_PspIoDrvFileArg; pub const struct_PspIoDrvFuncs = extern struct { - IoInit: ?fn ([*c]PspIoDrvArg) callconv(.C) c_int, - IoExit: ?fn ([*c]PspIoDrvArg) callconv(.C) c_int, - IoOpen: ?fn ([*c]PspIoDrvFileArg, [*c]u8, c_int, SceMode) callconv(.C) c_int, - IoClose: ?fn ([*c]PspIoDrvFileArg) callconv(.C) c_int, - IoRead: ?fn ([*c]PspIoDrvFileArg, [*c]u8, c_int) callconv(.C) c_int, - IoWrite: ?fn ([*c]PspIoDrvFileArg, [*c]const u8, c_int) callconv(.C) c_int, - IoLseek: ?fn ([*c]PspIoDrvFileArg, SceOff, c_int) callconv(.C) SceOff, - IoIoctl: ?fn ([*c]PspIoDrvFileArg, c_uint, ?*anyopaque, c_int, ?*anyopaque, c_int) callconv(.C) c_int, - IoRemove: ?fn ([*c]PspIoDrvFileArg, [*c]const u8) callconv(.C) c_int, - IoMkdir: ?fn ([*c]PspIoDrvFileArg, [*c]const u8, SceMode) callconv(.C) c_int, - IoRmdir: ?fn ([*c]PspIoDrvFileArg, [*c]const u8) callconv(.C) c_int, - IoDopen: ?fn ([*c]PspIoDrvFileArg, [*c]const u8) callconv(.C) c_int, - IoDclose: ?fn ([*c]PspIoDrvFileArg) callconv(.C) c_int, - IoDread: ?fn ([*c]PspIoDrvFileArg, [*c]SceIoDirent) callconv(.C) c_int, - IoGetstat: ?fn ([*c]PspIoDrvFileArg, [*c]const u8, [*c]SceIoStat) callconv(.C) c_int, - IoChstat: ?fn ([*c]PspIoDrvFileArg, [*c]const u8, [*c]SceIoStat, c_int) callconv(.C) c_int, - IoRename: ?fn ([*c]PspIoDrvFileArg, [*c]const u8, [*c]const u8) callconv(.C) c_int, - IoChdir: ?fn ([*c]PspIoDrvFileArg, [*c]const u8) callconv(.C) c_int, - IoMount: ?fn ([*c]PspIoDrvFileArg) callconv(.C) c_int, - IoUmount: ?fn ([*c]PspIoDrvFileArg) callconv(.C) c_int, - IoDevctl: ?fn ([*c]PspIoDrvFileArg, [*c]const u8, c_uint, ?*anyopaque, c_int, ?*anyopaque, c_int) callconv(.C) c_int, - IoUnk21: ?fn ([*c]PspIoDrvFileArg) callconv(.C) c_int, + IoInit: ?*const fn ([*c]PspIoDrvArg) callconv(.C) c_int, + IoExit: ?*const fn ([*c]PspIoDrvArg) callconv(.C) c_int, + IoOpen: ?*const fn ([*c]PspIoDrvFileArg, [*c]u8, c_int, SceMode) callconv(.C) c_int, + IoClose: ?*const fn ([*c]PspIoDrvFileArg) callconv(.C) c_int, + IoRead: ?*const fn ([*c]PspIoDrvFileArg, [*c]u8, c_int) callconv(.C) c_int, + IoWrite: ?*const fn ([*c]PspIoDrvFileArg, [*c]const u8, c_int) callconv(.C) c_int, + IoLseek: ?*const fn ([*c]PspIoDrvFileArg, SceOff, c_int) callconv(.C) SceOff, + IoIoctl: ?*const fn ([*c]PspIoDrvFileArg, c_uint, ?*anyopaque, c_int, ?*anyopaque, c_int) callconv(.C) c_int, + IoRemove: ?*const fn ([*c]PspIoDrvFileArg, [*c]const u8) callconv(.C) c_int, + IoMkdir: ?*const fn ([*c]PspIoDrvFileArg, [*c]const u8, SceMode) callconv(.C) c_int, + IoRmdir: ?*const fn ([*c]PspIoDrvFileArg, [*c]const u8) callconv(.C) c_int, + IoDopen: ?*const fn ([*c]PspIoDrvFileArg, [*c]const u8) callconv(.C) c_int, + IoDclose: ?*const fn ([*c]PspIoDrvFileArg) callconv(.C) c_int, + IoDread: ?*const fn ([*c]PspIoDrvFileArg, [*c]SceIoDirent) callconv(.C) c_int, + IoGetstat: ?*const fn ([*c]PspIoDrvFileArg, [*c]const u8, [*c]SceIoStat) callconv(.C) c_int, + IoChstat: ?*const fn ([*c]PspIoDrvFileArg, [*c]const u8, [*c]SceIoStat, c_int) callconv(.C) c_int, + IoRename: ?*const fn ([*c]PspIoDrvFileArg, [*c]const u8, [*c]const u8) callconv(.C) c_int, + IoChdir: ?*const fn ([*c]PspIoDrvFileArg, [*c]const u8) callconv(.C) c_int, + IoMount: ?*const fn ([*c]PspIoDrvFileArg) callconv(.C) c_int, + IoUmount: ?*const fn ([*c]PspIoDrvFileArg) callconv(.C) c_int, + IoDevctl: ?*const fn ([*c]PspIoDrvFileArg, [*c]const u8, c_uint, ?*anyopaque, c_int, ?*anyopaque, c_int) callconv(.C) c_int, + IoUnk21: ?*const fn ([*c]PspIoDrvFileArg) callconv(.C) c_int, }; pub const PspIoDrvFuncs = struct_PspIoDrvFuncs; pub const PspIoDrv = struct_PspIoDrv; diff --git a/src/psp/sdk/pspmpeg.zig b/src/psp/sdk/pspmpeg.zig index c50ae9d..487b702 100644 --- a/src/psp/sdk/pspmpeg.zig +++ b/src/psp/sdk/pspmpeg.zig @@ -31,7 +31,7 @@ pub const SceMpegYCrCbBuffer = extern struct { pub const SceMpeg = ScePVoid; pub const SceMpegStream = SceVoid; -pub const sceMpegRingbufferCB = ?fn (ScePVoid, SceInt32, ScePVoid) callconv(.C) SceInt32; +pub const sceMpegRingbufferCB = ?*const fn (ScePVoid, SceInt32, ScePVoid) callconv(.C) SceInt32; pub const SceMpegRingbuffer = extern struct { iPackets: SceInt32, diff --git a/src/psp/sdk/pspnet.zig b/src/psp/sdk/pspnet.zig index fc2d6a3..db6ed8f 100644 --- a/src/psp/sdk/pspnet.zig +++ b/src/psp/sdk/pspnet.zig @@ -102,7 +102,7 @@ pub extern fn sceNetAdhocctlGetPeerList(length: [*c]c_int, buf: ?*anyopaque) c_i pub extern fn sceNetAdhocctlGetPeerInfo(mac: [*c]u8, size: c_int, peerinfo: [*c]struct_SceNetAdhocctlPeerInfo) c_int; pub extern fn sceNetAdhocctlScan() c_int; pub extern fn sceNetAdhocctlGetScanInfo(length: [*c]c_int, buf: ?*anyopaque) c_int; -pub const sceNetAdhocctlHandler = ?fn (c_int, c_int, ?*anyopaque) callconv(.C) void; +pub const sceNetAdhocctlHandler = ?*const fn (c_int, c_int, ?*anyopaque) callconv(.C) void; pub extern fn sceNetAdhocctlAddHandler(handler: sceNetAdhocctlHandler, unknown: ?*anyopaque) c_int; pub extern fn sceNetAdhocctlDelHandler(id: c_int) c_int; pub extern fn sceNetAdhocctlGetNameByAddr(mac: [*c]u8, nickname: [*c]u8) c_int; @@ -144,7 +144,7 @@ pub const struct_pspAdhocPoolStat = extern struct { }; pub extern fn sceNetAdhocMatchingInit(memsize: c_int) c_int; pub extern fn sceNetAdhocMatchingTerm() c_int; -pub const pspAdhocMatchingCallback = ?fn (c_int, c_int, [*c]u8, c_int, ?*anyopaque) callconv(.C) void; +pub const pspAdhocMatchingCallback = ?*const fn (c_int, c_int, [*c]u8, c_int, ?*anyopaque) callconv(.C) void; pub extern fn sceNetAdhocMatchingCreate(mode: c_int, maxpeers: c_int, port: c_ushort, bufsize: c_int, hellodelay: c_uint, pingdelay: c_uint, initcount: c_int, msgdelay: c_uint, callback: pspAdhocMatchingCallback) c_int; pub extern fn sceNetAdhocMatchingDelete(matchingid: c_int) c_int; pub extern fn sceNetAdhocMatchingStart(matchingid: c_int, evthpri: c_int, evthstack: c_int, inthpri: c_int, inthstack: c_int, optlen: c_int, optdata: ?*anyopaque) c_int; @@ -181,7 +181,7 @@ pub const union_SceNetApctlInfo = extern union { startBrowser: c_uint, wifisp: c_uint, }; -pub const sceNetApctlHandler = ?fn (c_int, c_int, c_int, c_int, ?*anyopaque) callconv(.C) void; +pub const sceNetApctlHandler = ?*const fn (c_int, c_int, c_int, c_int, ?*anyopaque) callconv(.C) void; pub extern fn sceNetApctlInit(stackSize: c_int, initPriority: c_int) c_int; pub extern fn sceNetApctlTerm() c_int; pub extern fn sceNetApctlGetInfo(code: c_int, pInfo: [*c]union_SceNetApctlInfo) c_int; diff --git a/src/psp/sdk/psppower.zig b/src/psp/sdk/psppower.zig index 10659d0..f23fa17 100644 --- a/src/psp/sdk/psppower.zig +++ b/src/psp/sdk/psppower.zig @@ -20,7 +20,7 @@ pub const PSPPowerCB = enum(u32) { pub const PSPPowerTick = enum(u32) { All = 0, Suspend = 1, Display = 6 }; -pub const powerCallback_t = ?fn (c_int, c_int) callconv(.C) void; +pub const powerCallback_t = ?*const fn (c_int, c_int) callconv(.C) void; // Register Power Callback Function // diff --git a/src/psp/sdk/pspthreadman.zig b/src/psp/sdk/pspthreadman.zig index 7b59cf7..b06c3c9 100644 --- a/src/psp/sdk/pspthreadman.zig +++ b/src/psp/sdk/pspthreadman.zig @@ -185,7 +185,7 @@ pub extern fn sceKernelReceiveMbxCB(mbxid: SceUID, pmessage: [*c]?*anyopaque, ti pub extern fn sceKernelPollMbx(mbxid: SceUID, pmessage: [*c]?*anyopaque) c_int; pub extern fn sceKernelCancelReceiveMbx(mbxid: SceUID, pnum: [*c]c_int) c_int; pub extern fn sceKernelReferMbxStatus(mbxid: SceUID, info: [*c]SceKernelMbxInfo) c_int; -pub const SceKernelAlarmHandler = ?fn (?*anyopaque) callconv(.C) SceUInt; +pub const SceKernelAlarmHandler = ?*const fn (?*anyopaque) callconv(.C) SceUInt; pub const struct_SceKernelAlarmInfo = extern struct { size: SceSize, schedule: SceKernelSysClock, @@ -197,7 +197,7 @@ pub extern fn sceKernelSetAlarm(clock: SceUInt, handler: SceKernelAlarmHandler, pub extern fn sceKernelSetSysClockAlarm(clock: [*c]SceKernelSysClock, handler: SceKernelAlarmHandler, common: ?*anyopaque) SceUID; pub extern fn sceKernelCancelAlarm(alarmid: SceUID) c_int; pub extern fn sceKernelReferAlarmStatus(alarmid: SceUID, info: [*c]SceKernelAlarmInfo) c_int; -pub const SceKernelCallbackFunction = ?fn (c_int, c_int, ?*anyopaque) callconv(.C) c_int; +pub const SceKernelCallbackFunction = ?*const fn (c_int, c_int, ?*anyopaque) callconv(.C) c_int; pub const struct_SceKernelCallbackInfo = extern struct { size: SceSize, name: [32]u8, @@ -327,8 +327,8 @@ pub extern fn sceKernelSetVTimerTime(uid: SceUID, time: [*c]SceKernelSysClock) c pub extern fn sceKernelSetVTimerTimeWide(uid: SceUID, time: SceInt64) SceInt64; pub extern fn sceKernelStartVTimer(uid: SceUID) c_int; pub extern fn sceKernelStopVTimer(uid: SceUID) c_int; -pub const SceKernelVTimerHandler = ?fn (SceUID, [*c]SceKernelSysClock, [*c]SceKernelSysClock, ?*anyopaque) callconv(.C) SceUInt; -pub const SceKernelVTimerHandlerWide = ?fn (SceUID, SceInt64, SceInt64, ?*anyopaque) callconv(.C) SceUInt; +pub const SceKernelVTimerHandler = ?*const fn (SceUID, [*c]SceKernelSysClock, [*c]SceKernelSysClock, ?*anyopaque) callconv(.C) SceUInt; +pub const SceKernelVTimerHandlerWide = ?*const fn (SceUID, SceInt64, SceInt64, ?*anyopaque) callconv(.C) SceUInt; pub extern fn sceKernelSetVTimerHandler(uid: SceUID, time: [*c]SceKernelSysClock, handler: SceKernelVTimerHandler, common: ?*anyopaque) c_int; pub extern fn sceKernelSetVTimerHandlerWide(uid: SceUID, time: SceInt64, handler: SceKernelVTimerHandlerWide, common: ?*anyopaque) c_int; pub extern fn sceKernelCancelVTimerHandler(uid: SceUID) c_int; @@ -346,7 +346,7 @@ pub const SceKernelVTimerInfo = struct_SceKernelVTimerInfo; pub extern fn sceKernelReferVTimerStatus(uid: SceUID, info: [*c]SceKernelVTimerInfo) c_int; pub extern fn _sceKernelExitThread() void; pub extern fn sceKernelGetThreadmanIdType(uid: SceUID) enum_SceKernelIdListType; -pub const SceKernelThreadEventHandler = ?fn (c_int, SceUID, ?*anyopaque) callconv(.C) c_int; +pub const SceKernelThreadEventHandler = ?*const fn (c_int, SceUID, ?*anyopaque) callconv(.C) c_int; pub const struct_SceKernelThreadEventHandlerInfo = extern struct { size: SceSize, name: [32]u8, diff --git a/src/psp/sdk/pspumd.zig b/src/psp/sdk/pspumd.zig index 651784a..864e12f 100644 --- a/src/psp/sdk/pspumd.zig +++ b/src/psp/sdk/pspumd.zig @@ -22,7 +22,7 @@ pub const UmdDriveStat = enum(c_int) { WaitForDISC = 2, WaitForINIT = 32, }; -pub const UmdCallback = ?fn (c_int, c_int) callconv(.C) c_int; +pub const UmdCallback = ?*const fn (c_int, c_int) callconv(.C) c_int; // Check whether there is a disc in the UMD drive // From 6ca31ee65aa5d4f898ed672840d194fc2109abe4 Mon Sep 17 00:00:00 2001 From: Jae B Date: Tue, 28 May 2024 10:26:05 +1000 Subject: [PATCH 3/5] update and fix various compilation errors --- build-psp.zig | 2 +- src/psp/sdk/cos.zig | 2 +- src/psp/sdk/pspguimpl.zig | 30 +++++++++++++++--------------- src/psp/sdk/pspgumimpl.zig | 10 +++++----- src/psp/sdk/pspthreadman.zig | 1 + src/psp/sdk/sin.zig | 2 +- src/psp/utils/debug.zig | 7 ++++--- src/psp/utils/utils.zig | 8 ++++---- 8 files changed, 32 insertions(+), 30 deletions(-) diff --git a/build-psp.zig b/build-psp.zig index 5faa9be..dd6d832 100644 --- a/build-psp.zig +++ b/build-psp.zig @@ -46,7 +46,7 @@ pub fn build_psp(b: *std.Build, comptime build_info: PSPBuildInfo) !void { .root_source_file = b.path(build_info.src_file), .target = target, .optimize = optimize, - // .strip = true, + .strip = false, // disable as cannot be used with "link_emit_relocs = true" // .single_threaded = true, }); diff --git a/src/psp/sdk/cos.zig b/src/psp/sdk/cos.zig index 2e15e8e..99a897e 100644 --- a/src/psp/sdk/cos.zig +++ b/src/psp/sdk/cos.zig @@ -58,7 +58,7 @@ fn cos_(comptime T: type, x_: T) T { } var sign = false; - x = math.fabs(x); + x = @abs(x); var y = math.floor(x * m4pi); var j = @as(I, @intFromFloat(y)); diff --git a/src/psp/sdk/pspguimpl.zig b/src/psp/sdk/pspguimpl.zig index c5a8527..9d4bbba 100644 --- a/src/psp/sdk/pspguimpl.zig +++ b/src/psp/sdk/pspguimpl.zig @@ -1062,7 +1062,7 @@ pub fn sceGuSetCallback(signal: c_int, callback: ?*const fn (c_int) callconv(.C) return old_callback; } -pub fn sceGuSetDither(matrix: *const pspgutypes.ScePspIMatrix4) void { +pub fn sceGuSetDither(matrix: *const psptypes.ScePspIMatrix4) void { @setRuntimeSafety(false); sendCommandi(226, (matrix.x.x & 0x0f) | ((matrix.x.y & 0x0f) << 4) | ((matrix.x.z & 0x0f) << 8) | ((matrix.x.w & 0x0f) << 12)); sendCommandi(227, (matrix.y.x & 0x0f) | ((matrix.y.y & 0x0f) << 4) | ((matrix.y.z & 0x0f) << 8) | ((matrix.y.w & 0x0f) << 12)); @@ -1070,7 +1070,7 @@ pub fn sceGuSetDither(matrix: *const pspgutypes.ScePspIMatrix4) void { sendCommandi(229, (matrix.w.x & 0x0f) | ((matrix.w.y & 0x0f) << 4) | ((matrix.w.z & 0x0f) << 8) | ((matrix.w.w & 0x0f) << 12)); } -pub fn sceGuSetMatrix(typec: c_int, matrix: [*c]pspgutypes.ScePspFMatrix4) void { +pub fn sceGuSetMatrix(typec: c_int, matrix: [*c]psptypes.ScePspFMatrix4) void { @setRuntimeSafety(false); const fmatrix: [*]f32 = @as([*]f32, @ptrCast(matrix)); @@ -1184,7 +1184,7 @@ pub fn sceGuSwapBuffers() ?*anyopaque { } if (gu_display_on != 0) { - _ = pspge.sceDisplaySetFrameBuf(@as(*anyopaque, @ptrFromInt(@intFromPtr(ge_edram_address) + @intFromPtr(gu_draw_buffer.disp_buffer))), gu_draw_buffer.frame_width, gu_draw_buffer.pixel_size, gu_settings.swapBuffersBehaviour); + _ = display.sceDisplaySetFrameBuf(@as(*anyopaque, @ptrFromInt(@intFromPtr(ge_edram_address) + @intFromPtr(gu_draw_buffer.disp_buffer))), gu_draw_buffer.frame_width, gu_draw_buffer.pixel_size, gu_settings.swapBuffersBehaviour); } gu_current_frame ^= 1; @@ -1383,7 +1383,7 @@ const ge_init_list = [_]c_uint{ pub fn sceGuInit() void { @setRuntimeSafety(false); - var callback: pspgutypes.PspGeCallbackData = undefined; + var callback: pspge.PspGeCallbackData = undefined; callback.signal_func = callbackSig; callback.signal_arg = &gu_settings; callback.finish_func = callbackFin; @@ -1398,7 +1398,7 @@ pub fn sceGuInit() void { ge_list_executed[0] = pspge.sceGeListEnQueue((@as(*anyopaque, @ptrFromInt(@intFromPtr(&ge_init_list) & 0x1fffffff))), null, gu_settings.ge_callback_id, 0); resetValues(); - gu_settings.kernel_event_flag = pspge.sceKernelCreateEventFlag("SceGuSignal", 512, 3, 0); + gu_settings.kernel_event_flag = pspthreadman.sceKernelCreateEventFlag("SceGuSignal", 512, 3, 0); _ = pspge.sceGeListSync(ge_list_executed[0], 0); } @@ -1429,12 +1429,12 @@ pub fn sceGuStart(cont: pspgutypes.GuContextType, list: ?*anyopaque) void { 3, -1, 2, -2, }; - display.sceGuSetDither(@as(*pspgutypes.ScePspIMatrix4, @ptrCast(&dither_matrix))); - display.sceGuPatchDivide(16, 16); - display.sceGuColorMaterial(@intFromEnum(pspgutypes.GuLightBitFlags.Ambient) | @intFromEnum(pspgutypes.GuLightBitFlags.Diffuse) | @intFromEnum(pspgutypes.GuLightBitFlags.Specular)); + sceGuSetDither(@as(*psptypes.ScePspIMatrix4, @ptrCast(&dither_matrix))); + sceGuPatchDivide(16, 16); + sceGuColorMaterial(@intFromEnum(pspgutypes.GuLightBitFlags.Ambient) | @intFromEnum(pspgutypes.GuLightBitFlags.Diffuse) | @intFromEnum(pspgutypes.GuLightBitFlags.Specular)); - display.sceGuSpecular(1.0); - display.sceGuTexScale(1.0, 1.0); + sceGuSpecular(1.0); + sceGuTexScale(1.0, 1.0); gu_init = 1; } @@ -1472,7 +1472,7 @@ pub fn sceGuClear(flags: c_int) void { } const count: i32 = @divTrunc(gu_draw_buffer.width + 63, 64) * 2; - const vertices: [*]Vertex = @as([*]Vertex, @ptrCast(sceGuGetMemory(@as(c_uint, @intCast(count)) * @sizeOf(Vertex)))); + const vertices: [*]Vertex = @as([*]Vertex, @alignCast(@ptrCast(sceGuGetMemory(@as(c_uint, @intCast(count)) * @sizeOf(Vertex))))); var i: usize = 0; var curr: [*]Vertex = vertices; @@ -1494,9 +1494,9 @@ pub fn sceGuClear(flags: c_int) void { const VertexTypeFlags = pspgutypes.VertexTypeFlags; const GuPrimitive = pspgutypes.GuPrimitive; - display.sendCommandi(211, ((flags & (@intFromEnum(ClearBitFlags.ColorBuffer) | @intFromEnum(ClearBitFlags.StencilBuffer) | @intFromEnum(ClearBitFlags.DepthBuffer))) << 8) | 0x01); - display.sceGuDrawArray(GuPrimitive.Sprites, @intFromEnum(VertexTypeFlags.Color8888) | @intFromEnum(VertexTypeFlags.Vertex16Bit) | @intFromEnum(VertexTypeFlags.Transform2D), @as(c_int, @intCast(count)), null, vertices); - display.sendCommandi(211, 0); + sendCommandi(211, ((flags & (@intFromEnum(ClearBitFlags.ColorBuffer) | @intFromEnum(ClearBitFlags.StencilBuffer) | @intFromEnum(ClearBitFlags.DepthBuffer))) << 8) | 0x01); + sceGuDrawArray(GuPrimitive.Sprites, @intFromEnum(VertexTypeFlags.Color8888) | @intFromEnum(VertexTypeFlags.Vertex16Bit) | @intFromEnum(VertexTypeFlags.Transform2D), @as(c_int, @intCast(count)), null, vertices); + sendCommandi(211, 0); } pub fn sceGuGetMemory(size: c_uint) *anyopaque { @@ -1519,7 +1519,7 @@ pub fn sceGuGetMemory(size: c_uint) *anyopaque { gu_list.?.current = new_ptr; if (gu_curr_context == 0) { - _ = display.sceGeListUpdateStallAddr(ge_list_executed[0], new_ptr); + _ = pspge.sceGeListUpdateStallAddr(ge_list_executed[0], new_ptr); } return @as(*anyopaque, @ptrFromInt(@intFromPtr(orig_ptr + 2))); } diff --git a/src/psp/sdk/pspgumimpl.zig b/src/psp/sdk/pspgumimpl.zig index 028a71e..1280817 100644 --- a/src/psp/sdk/pspgumimpl.zig +++ b/src/psp/sdk/pspgumimpl.zig @@ -12,22 +12,22 @@ var gum_stack_depth: [4][*]psptypes.ScePspFMatrix4 = [_][*]psptypes.ScePspFMatri var gum_matrix_stack: [4][32]psptypes.ScePspFMatrix4 = undefined; pub fn sceGumDrawArray(prim: pspgu.GuPrimitive, vtype: c_int, count: c_int, indices: ?*const anyopaque, vertices: ?*const anyopaque) void { - pspgu.sceGumUpdateMatrix(); + sceGumUpdateMatrix(); pspgu.sceGuDrawArray(prim, vtype, count, indices, vertices); } pub fn sceGumDrawArrayN(prim: c_int, vtype: c_int, count: c_int, a3: c_int, indices: ?*const anyopaque, vertices: ?*const anyopaque) void { - pspgu.sceGumUpdateMatrix(); + sceGumUpdateMatrix(); pspgu.sceGuDrawArrayN(prim, vtype, count, a3, indices, vertices); } pub fn sceGumDrawBezier(vtype: c_int, ucount: c_int, vcount: c_int, indices: ?*const anyopaque, vertices: ?*const anyopaque) void { - pspgu.sceGumUpdateMatrix(); + sceGumUpdateMatrix(); pspgu.sceGuDrawBezier(vtype, ucount, vcount, indices, vertices); } pub fn sceGumDrawSpline(vtype: c_int, ucount: c_int, vcount: c_int, uedge: c_int, vedge: c_int, indices: ?*const anyopaque, vertices: ?*const anyopaque) void { - pspgu.sceGumUpdateMatrix(); + sceGumUpdateMatrix(); pspgu.sceGuDrawSpline(vtype, ucount, vcount, uedge, vedge, indices, vertices); } @@ -335,7 +335,7 @@ pub fn sceGumFullInverse() void { d3 = gum_current_matrix.y.x * gum_current_matrix.z.y * gum_current_matrix.w.z + gum_current_matrix.y.y * gum_current_matrix.z.z * gum_current_matrix.w.x + gum_current_matrix.y.z * gum_current_matrix.z.x * gum_current_matrix.w.y - gum_current_matrix.w.x * gum_current_matrix.z.y * gum_current_matrix.y.z - gum_current_matrix.w.y * gum_current_matrix.z.z * gum_current_matrix.y.x - gum_current_matrix.w.z * gum_current_matrix.z.x * gum_current_matrix.y.y; d = gum_current_matrix.x.x * d0 - gum_current_matrix.x.y * d1 + gum_current_matrix.x.z * d2 - gum_current_matrix.x.w * d3; - if (std.math.fabs(d) < 0.000001) { + if (@abs(d) < 0.000001) { _ = memset(@as([*]u8, @ptrCast(gum_current_matrix)), 0, @sizeOf(psptypes.ScePspFMatrix4)); var i: usize = 0; diff --git a/src/psp/sdk/pspthreadman.zig b/src/psp/sdk/pspthreadman.zig index b06c3c9..8bd3afe 100644 --- a/src/psp/sdk/pspthreadman.zig +++ b/src/psp/sdk/pspthreadman.zig @@ -75,6 +75,7 @@ pub const enum_PspThreadStatus = enum(c_int) { PSP_THREAD_KILLED = 32, _, }; + pub extern fn sceKernelDeleteThread(thid: SceUID) c_int; pub extern fn sceKernelStartThread(thid: SceUID, arglen: SceSize, argp: ?*anyopaque) c_int; pub extern fn sceKernelExitThread(status: c_int) c_int; diff --git a/src/psp/sdk/sin.zig b/src/psp/sdk/sin.zig index eb3b206..7fa39d7 100644 --- a/src/psp/sdk/sin.zig +++ b/src/psp/sdk/sin.zig @@ -62,7 +62,7 @@ fn sin_(comptime T: type, x_: T) T { } var sign = x < 0; - x = math.fabs(x); + x = @abs(x); var y = math.floor(x * m4pi); var j = @as(I, @intFromFloat(y)); diff --git a/src/psp/utils/debug.zig b/src/psp/utils/debug.zig index 88e46c7..1f05346 100644 --- a/src/psp/utils/debug.zig +++ b/src/psp/utils/debug.zig @@ -30,7 +30,7 @@ pub fn screenSetXY(sX: u8, sY: u8) void { //Clears the screen to the clear color (default is black) pub fn screenClear() void { var i: usize = 0; - while (i < constants.constants.SCR_BUF_WIDTH * constants.constants.SCREEN_HEIGHT) : (i += 1) { + while (i < constants.SCR_BUF_WIDTH * constants.SCREEN_HEIGHT) : (i += 1) { vram_base.?[i] = cl_col; } } @@ -115,7 +115,7 @@ export fn pspDebugScreenClear(color: u32) void { } export fn pspDebugScreenPrint(text: [*c]const u8) void { - print(std.mem.spanZ(text)); + print(std.mem.span(text)); } const std = @import("std"); @@ -164,7 +164,8 @@ pub var pancakeMode: bool = false; //Panic handler //Import this in main to use! -pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn { +pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, size: ?usize) noreturn { + _ = size; // autofix _ = stack_trace; screenInit(); diff --git a/src/psp/utils/utils.zig b/src/psp/utils/utils.zig index fe14ae6..72639b9 100644 --- a/src/psp/utils/utils.zig +++ b/src/psp/utils/utils.zig @@ -25,23 +25,23 @@ export fn cbThread(args: psptypes.SceSize, argp: ?*anyopaque) c_int { _ = argp; var cbID: i32 = -1; - cbID = psploadexec.sceKernelCreateCallback("zig_exit_callback", exitCB, null); + cbID = pspthreadman.sceKernelCreateCallback("zig_exit_callback", exitCB, null); var status = psploadexec.sceKernelRegisterExitCallback(cbID); if (status < 0) { @panic("Could not setup a home button callback!"); } - status = psploadexec.sceKernelSleepThreadCB(); + status = pspthreadman.sceKernelSleepThreadCB(); return 0; } //This enables the home button exit callback above pub fn enableHBCB() void { - const threadID: i32 = psploadexec.sceKernelCreateThread("zig_callback_updater", cbThread, 0x11, 0xFA0, @intFromEnum(pspthreadman.PspThreadAttributes.PSP_THREAD_ATTR_USER), null); + const threadID: i32 = pspthreadman.sceKernelCreateThread("zig_callback_updater", cbThread, 0x11, 0xFA0, @intFromEnum(pspthreadman.PspThreadAttributes.PSP_THREAD_ATTR_USER), null); if (threadID >= 0) { - const stat: i32 = psploadexec.sceKernelStartThread(threadID, 0, null); //We don't know what stat does. + const stat: i32 = pspthreadman.sceKernelStartThread(threadID, 0, null); //We don't know what stat does. _ = stat; } else { @panic("Could not setup a home button callback thread!"); From de05ff9346a3cc3835863508f3c8f3a51b0a1e2f Mon Sep 17 00:00:00 2001 From: Jae B Date: Tue, 28 May 2024 11:29:55 +1000 Subject: [PATCH 4/5] get compilation working --- build-psp.zig | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/build-psp.zig b/build-psp.zig index dd6d832..ba37fc6 100644 --- a/build-psp.zig +++ b/build-psp.zig @@ -9,11 +9,11 @@ pub const PSPBuildInfo = struct { //Title title: []const u8, //Optional customizations - icon0: []const u8 = "NULL", - icon1: []const u8 = "NULL", - pic0: []const u8 = "NULL", - pic1: []const u8 = "NULL", - snd0: []const u8 = "NULL", + icon0: []const u8 = &[0]u8{}, + icon1: []const u8 = &[0]u8{}, + pic0: []const u8 = &[0]u8{}, + pic1: []const u8 = &[0]u8{}, + snd0: []const u8 = &[0]u8{}, }; const append: []const u8 = switch (builtin.os.tag) { @@ -61,6 +61,7 @@ pub fn build_psp(b: *std.Build, comptime build_info: PSPBuildInfo) !void { //Post-build actions const hostTarget = b.standardTargetOptions(.{}); + const hostOptimize = b.standardOptimizeOption(.{}); const prx = b.addExecutable(.{ .name = "prxgen", .root_source_file = b.path(build_info.path_to_sdk ++ "tools/prxgen/stub.zig"), @@ -93,7 +94,7 @@ pub fn build_psp(b: *std.Build, comptime build_info: PSPBuildInfo) !void { .name = "sfotool", .root_source_file = b.path(build_info.path_to_sdk ++ "tools/sfo/src/main.zig"), .target = hostTarget, - .optimize = optimize, + .optimize = hostOptimize, }); // sfo.setOutputDir(build_info.path_to_sdk ++ "tools/bin"); b.installArtifact(sfo); @@ -111,22 +112,21 @@ pub fn build_psp(b: *std.Build, comptime build_info: PSPBuildInfo) !void { .name = "pbptool", .root_source_file = b.path(build_info.path_to_sdk ++ "tools/pbp/src/main.zig"), .target = hostTarget, - .optimize = .ReleaseFast, + .optimize = hostOptimize, }); // PBP.setOutputDir(build_info.path_to_sdk ++ "tools/bin"); - //Pack the PBP executable const pack_pbp = b.addRunArtifact(PBP); pack_pbp.addArg("pack"); const eboot_file = pack_pbp.addOutputFileArg("EBOOT.PBP"); pack_pbp.addFileArg(sfo_file); - pack_pbp.addFileArg(b.path(build_info.icon0)); - pack_pbp.addFileArg(b.path(build_info.icon1)); - pack_pbp.addFileArg(b.path(build_info.pic0)); - pack_pbp.addFileArg(b.path(build_info.pic1)); - pack_pbp.addFileArg(b.path(build_info.snd0)); + if (build_info.icon0.len > 0) pack_pbp.addFileArg(b.path(build_info.icon0)) else pack_pbp.addArg("NULL"); + if (build_info.icon1.len > 0) pack_pbp.addFileArg(b.path(build_info.icon1)) else pack_pbp.addArg("NULL"); + if (build_info.pic0.len > 0) pack_pbp.addFileArg(b.path(build_info.pic0)) else pack_pbp.addArg("NULL"); + if (build_info.pic1.len > 0) pack_pbp.addFileArg(b.path(build_info.pic1)) else pack_pbp.addArg("NULL"); + if (build_info.snd0.len > 0) pack_pbp.addFileArg(b.path(build_info.snd0)) else pack_pbp.addArg("NULL"); pack_pbp.addFileArg(prx_file); - pack_pbp.addArg("NULL"); + pack_pbp.addArg("NULL"); //DATA.PSAR not necessary. const install_file = b.addInstallBinFile(eboot_file, "EBOOT.PBP"); b.getInstallStep().dependOn(&install_file.step); From b6c21affe183681bdb26cd334ddc067ddbcfa14c Mon Sep 17 00:00:00 2001 From: Jae B Date: Tue, 28 May 2024 11:37:24 +1000 Subject: [PATCH 5/5] update alignCast to be inner --- src/psp/sdk/pspguimpl.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/psp/sdk/pspguimpl.zig b/src/psp/sdk/pspguimpl.zig index 9d4bbba..35bf7d6 100644 --- a/src/psp/sdk/pspguimpl.zig +++ b/src/psp/sdk/pspguimpl.zig @@ -1472,7 +1472,7 @@ pub fn sceGuClear(flags: c_int) void { } const count: i32 = @divTrunc(gu_draw_buffer.width + 63, 64) * 2; - const vertices: [*]Vertex = @as([*]Vertex, @alignCast(@ptrCast(sceGuGetMemory(@as(c_uint, @intCast(count)) * @sizeOf(Vertex))))); + const vertices: [*]Vertex = @ptrCast(@alignCast(sceGuGetMemory(@as(c_uint, @intCast(count)) * @sizeOf(Vertex)))); var i: usize = 0; var curr: [*]Vertex = vertices;