diff --git a/build-psp.zig b/build-psp.zig index 8105087..ba37fc6 100644 --- a/build-psp.zig +++ b/build-psp.zig @@ -1,115 +1,138 @@ -const Builder = @import("std").build.Builder; const z = @import("std").zig; const std = @import("std"); const builtin = std.builtin; -pub const PSPBuildInfo = struct{ +pub const PSPBuildInfo = struct { //SDK Path path_to_sdk: []const u8, src_file: []const u8, //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){ +const append: []const u8 = switch (builtin.os.tag) { .windows => ".exe", else => "", }; -pub fn build_psp(b: *Builder, comptime build_info: PSPBuildInfo) !void { - var feature_set : std.Target.Cpu.Feature.Set = std.Target.Cpu.Feature.Set.empty; - feature_set.addFeature(@enumToInt(std.Target.mips.Feature.single_float)); +pub fn build_psp(b: *std.Build, comptime build_info: PSPBuildInfo) !void { + var feature_set: std.Target.Cpu.Feature.Set = std.Target.Cpu.Feature.Set.empty; + feature_set.addFeature(@intFromEnum(std.Target.mips.Feature.single_float)); //PSP-Specific Build Options - const target = z.CrossTarget{ + // const target = z.CrossTarget{}; + // const target = b.standardTargetOptions(.{ .whitelist = &.{.{ + // }} }); + const target = b.resolveTargetQuery(.{ .cpu_arch = .mipsel, .os_tag = .freestanding, .cpu_model = .{ .explicit = &std.Target.mips.cpu.mips2 }, - .cpu_features_add = feature_set - }; + .cpu_features_add = feature_set, + }); //All of the release modes work //Debug Mode can cause issues with trap instructions - use ReleaseSafe for "Debug" builds - const mode = builtin.Mode.ReleaseSmall; + const optimize = builtin.Mode.ReleaseSmall; //Build from your main file! - const exe = b.addExecutable("main", build_info.src_file); + const exe = b.addExecutable(.{ + .name = "main", + .root_source_file = b.path(build_info.src_file), + .target = target, + .optimize = optimize, + .strip = false, // disable as cannot be used with "link_emit_relocs = true" + // .single_threaded = true, + }); + + exe.setLinkerScriptPath(b.path(build_info.path_to_sdk ++ "tools/linkfile.ld")); - //Set mode & target - exe.setTarget(target); - exe.setBuildMode(mode); - exe.setLinkerScriptPath(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(); - exe.setOutputDir("zig-cache/"); + // exe.install(); + // b.installArtifact(exe); + + // exe.setOutputDir("zig-cache/"); //Post-build actions const hostTarget = b.standardTargetOptions(.{}); - const prx = b.addExecutable("prxgen", build_info.path_to_sdk ++ "tools/prxgen/stub.zig"); - prx.setTarget(hostTarget); - prx.addCSourceFile(build_info.path_to_sdk ++ "tools/prxgen/psp-prxgen.c", &[_][]const u8{"-std=c99", "-Wno-address-of-packed-member", "-D_CRT_SECURE_NO_WARNINGS"}); - prx.linkLibC(); - prx.setBuildMode(builtin.Mode.ReleaseFast); - prx.setOutputDir(build_info.path_to_sdk ++ "tools/bin"); - prx.install(); - prx.step.dependOn(&exe.step); - - const generate_prx = b.addSystemCommand(&[_][]const u8{ - build_info.path_to_sdk ++ "tools/bin/prxgen" ++ append, - "zig-cache/main", - "app.prx" + const hostOptimize = b.standardOptimizeOption(.{}); + const prx = b.addExecutable(.{ + .name = "prxgen", + .root_source_file = b.path(build_info.path_to_sdk ++ "tools/prxgen/stub.zig"), + .link_libc = true, + .target = hostTarget, + .optimize = .ReleaseFast, }); - generate_prx.step.dependOn(&prx.step); + prx.addCSourceFile(.{ + .file = b.path(build_info.path_to_sdk ++ "tools/prxgen/psp-prxgen.c"), + .flags = &[_][]const u8{ + "-std=c99", + "-Wno-address-of-packed-member", + "-D_CRT_SECURE_NO_WARNINGS", + }, + }); + b.installArtifact(prx); + // prx.setOutputDir(build_info.path_to_sdk ++ "tools/bin"); + // prx.install(); + // prx.step.dependOn(&exe.step); - //Build SFO - const sfo = b.addExecutable("sfotool", build_info.path_to_sdk ++ "tools/sfo/src/main.zig"); - sfo.setTarget(hostTarget); - sfo.setBuildMode(builtin.Mode.ReleaseFast); - sfo.setOutputDir(build_info.path_to_sdk ++ "tools/bin"); - sfo.install(); - sfo.step.dependOn(&generate_prx.step); + // const generate_prx = b.addSystemCommand(&[_][]const u8{ build_info.path_to_sdk ++ "tools/bin/prxgen" ++ append, "zig-cache/main", "app.prx" }); + // generate_prx.step.dependOn(&prx.step); - //Make the SFO file - const mk_sfo = b.addSystemCommand(&[_][]const u8{ - build_info.path_to_sdk ++ "tools/bin/sfotool" ++ append, "write", - build_info.title, - "PARAM.SFO" + const generate_prx_step = b.addRunArtifact(prx); + generate_prx_step.addArtifactArg(exe); + const prx_file = generate_prx_step.addOutputFileArg("app.prx"); + + //Build SFO + const sfo = b.addExecutable(.{ + .name = "sfotool", + .root_source_file = b.path(build_info.path_to_sdk ++ "tools/sfo/src/main.zig"), + .target = hostTarget, + .optimize = hostOptimize, }); - mk_sfo.step.dependOn(&sfo.step); + // sfo.setOutputDir(build_info.path_to_sdk ++ "tools/bin"); + b.installArtifact(sfo); + //Make the SFO file + // const mk_sfo = b.addSystemCommand(&[_][]const u8{ build_info.path_to_sdk ++ "tools/bin/sfotool" ++ append, "write", build_info.title, "PARAM.SFO" }); + const mk_sfo = b.addRunArtifact(sfo); + mk_sfo.addArg("write"); + mk_sfo.addArg(build_info.title); + const sfo_file = mk_sfo.addOutputFileArg("PARAM.SFO"); + // mk_sfo.step.dependOn(&sfo.step); //Build PBP - const PBP = b.addExecutable("pbptool", build_info.path_to_sdk ++ "tools/pbp/src/main.zig"); - PBP.setTarget(hostTarget); - PBP.setBuildMode(builtin.Mode.ReleaseFast); - PBP.setOutputDir(build_info.path_to_sdk ++ "tools/bin"); - PBP.install(); - PBP.step.dependOn(&mk_sfo.step); - - //Pack the PBP executable - const pack_pbp = b.addSystemCommand(&[_][]const u8{ - build_info.path_to_sdk ++ "tools/bin/pbptool" ++ append, "pack", - "EBOOT.PBP", - "PARAM.SFO", - build_info.icon0, - build_info.icon1, - build_info.pic0, - build_info.pic1, - build_info.snd0, - "app.prx", - "NULL" //DATA.PSAR not necessary. + const PBP = b.addExecutable(.{ + .name = "pbptool", + .root_source_file = b.path(build_info.path_to_sdk ++ "tools/pbp/src/main.zig"), + .target = hostTarget, + .optimize = hostOptimize, }); - pack_pbp.step.dependOn(&PBP.step); + // 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); + 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"); //DATA.PSAR not necessary. + + const install_file = b.addInstallBinFile(eboot_file, "EBOOT.PBP"); + b.getInstallStep().dependOn(&install_file.step); //Enable the build - b.default_step.dependOn(&pack_pbp.step); + // const install = b.getInstallStep(); + // install.dependOn(&pack_pbp.step); + //b.default_step.dependOn(&pack_pbp.step); } diff --git a/build.zig b/build.zig index 9847511..4429025 100644 --- a/build.zig +++ b/build.zig @@ -1,7 +1,7 @@ -const Builder = @import("std").build.Builder; +const std = @import("std"); const psp = @import("build-psp.zig"); -pub fn build(b: *Builder) void { +pub fn build(b: *std.Build) void { psp.build_psp(b, psp.PSPBuildInfo{ .path_to_sdk = "", .src_file = "src/main.zig", diff --git a/examples/allocator.zig b/examples/allocator.zig index 04851f8..e620eac 100644 --- a/examples/allocator.zig +++ b/examples/allocator.zig @@ -7,7 +7,7 @@ const std = @import("std"); const fmt = std.fmt; comptime { - asm(psp.module_info("Zig PSP App", 0, 1, 0)); + asm (psp.module_info("Zig PSP App", 0, 1, 0)); } fn printFreeMem(alloc: *std.mem.Allocator) void { @@ -25,17 +25,17 @@ pub fn main() !void { printFreeMem(psp_allocator); - const string : []const u8 = try std.fmt.allocPrint( + const string: []const u8 = try std.fmt.allocPrint( psp_allocator, "{} {} {}\n", .{ "Hello", "from", "Zig!" }, ); - + psp.debug.print(string); - + printFreeMem(psp_allocator); psp_allocator.free(string); //Explicit free - + printFreeMem(psp_allocator); psp.debug.print("\nKTHXBYE!"); diff --git a/examples/clearScreen.zig b/examples/clearScreen.zig index 4b6d357..a1bcc7d 100644 --- a/examples/clearScreen.zig +++ b/examples/clearScreen.zig @@ -2,46 +2,42 @@ const psp = @import("psp/pspsdk.zig"); comptime { - asm(psp.module_info("Zig PSP App", 0, 1, 0)); + asm (psp.module_info("Zig PSP App", 0, 1, 0)); } -var display_list : [0x40000]u32 align(16) = [_]u32{0} ** 0x40000; +var display_list: [0x40000]u32 align(16) = [_]u32{0} ** 0x40000; pub fn main() !void { psp.utils.enableHBCB(); - + var fbp0 = psp.vram.allocVramRelative(psp.SCR_BUF_WIDTH, psp.SCREEN_HEIGHT, psp.GuPixelMode.Psm8888); var fbp1 = psp.vram.allocVramRelative(psp.SCR_BUF_WIDTH, psp.SCREEN_HEIGHT, psp.GuPixelMode.Psm8888); var zbp = psp.vram.allocVramRelative(psp.SCR_BUF_WIDTH, psp.SCREEN_HEIGHT, psp.GuPixelMode.Psm4444); psp.sceGuInit(); - psp.sceGuStart(psp.GuContextType.Direct, @ptrCast(*c_void, &display_list)); + psp.sceGuStart(psp.GuContextType.Direct, @as(*c_void, @ptrCast(&display_list))); psp.sceGuDrawBuffer(psp.GuPixelMode.Psm8888, fbp0, psp.SCR_BUF_WIDTH); psp.sceGuDispBuffer(psp.SCREEN_WIDTH, psp.SCREEN_HEIGHT, fbp1, psp.SCR_BUF_WIDTH); psp.sceGuDepthBuffer(zbp, psp.SCR_BUF_WIDTH); - psp.sceGuOffset(2048 - (psp.SCREEN_WIDTH/2), 2048 - (psp.SCREEN_HEIGHT/2)); + psp.sceGuOffset(2048 - (psp.SCREEN_WIDTH / 2), 2048 - (psp.SCREEN_HEIGHT / 2)); psp.sceGuViewport(2048, 2048, psp.SCREEN_WIDTH, psp.SCREEN_HEIGHT); psp.sceGuDepthRange(65535, 0); psp.sceGuScissor(0, 0, psp.SCREEN_WIDTH, psp.SCREEN_HEIGHT); psp.sceGuEnable(psp.GuState.ScissorTest); - + psp.guFinish(); psp.guSync(psp.GuSyncMode.Finish, psp.GuSyncBehavior.Wait); psp.displayWaitVblankStart(); psp.sceGuDisplay(true); - var i : u32 = 0; - while(true) : (i += 1) { - psp.sceGuStart(psp.GuContextType.Direct, @ptrCast(*c_void, &display_list)); - + var i: u32 = 0; + while (true) : (i += 1) { + psp.sceGuStart(psp.GuContextType.Direct, @as(*c_void, @ptrCast(&display_list))); + psp.sceGuClearColor(psp.rgba(0xFF, 0xFF, 0, 0xFF)); psp.sceGuClearDepth(0); - psp.sceGuClear( - @enumToInt(psp.ClearBitFlags.ColorBuffer) | - @enumToInt(psp.ClearBitFlags.DepthBuffer) - ); - - + psp.sceGuClear(@intFromEnum(psp.ClearBitFlags.ColorBuffer) | + @intFromEnum(psp.ClearBitFlags.DepthBuffer)); psp.guFinish(); psp.guSync(psp.GuSyncMode.Finish, psp.GuSyncBehavior.Wait); diff --git a/examples/cube.zig b/examples/cube.zig index a11efbf..e64fc1e 100644 --- a/examples/cube.zig +++ b/examples/cube.zig @@ -65,7 +65,7 @@ pub fn main() !void { var zbp = psp.vram.allocVramRelative(psp.SCR_BUF_WIDTH, psp.SCREEN_HEIGHT, psp.GuPixelMode.Psm4444); psp.sceGuInit(); - psp.sceGuStart(psp.GuContextType.Direct, @ptrCast(*c_void, &display_list)); + psp.sceGuStart(psp.GuContextType.Direct, @as(*c_void, @ptrCast(&display_list))); psp.sceGuDrawBuffer(psp.GuPixelMode.Psm8888, fbp0, psp.SCR_BUF_WIDTH); psp.sceGuDispBuffer(psp.SCREEN_WIDTH, psp.SCREEN_HEIGHT, fbp1, psp.SCR_BUF_WIDTH); psp.sceGuDepthBuffer(zbp, psp.SCR_BUF_WIDTH); @@ -89,12 +89,12 @@ pub fn main() !void { var i: u32 = 0; while (true) : (i += 1) { - psp.sceGuStart(psp.GuContextType.Direct, @ptrCast(*c_void, &display_list)); + psp.sceGuStart(psp.GuContextType.Direct, @as(*c_void, @ptrCast(&display_list))); psp.sceGuClearColor(psp.rgba(32, 32, 32, 0xFF)); psp.sceGuClearDepth(0); - psp.sceGuClear(@enumToInt(psp.ClearBitFlags.ColorBuffer) | - @enumToInt(psp.ClearBitFlags.DepthBuffer)); + psp.sceGuClear(@intFromEnum(psp.ClearBitFlags.ColorBuffer) | + @intFromEnum(psp.ClearBitFlags.DepthBuffer)); psp.sceGumMatrixMode(psp.MatrixMode.Projection); psp.sceGumLoadIdentity(); @@ -108,7 +108,7 @@ pub fn main() !void { //Rotate var pos: psp.ScePspFVector3 = psp.ScePspFVector3{ .x = 0, .y = 0, .z = -2.5 }; - var rot: psp.ScePspFVector3 = psp.ScePspFVector3{ .x = @intToFloat(f32, i) * 0.79 * (3.14159 / 180.0), .y = @intToFloat(f32, i) * 0.98 * (3.14159 / 180.0), .z = @intToFloat(f32, i) * 1.32 * (3.14159 / 180.0) }; + var rot: psp.ScePspFVector3 = psp.ScePspFVector3{ .x = @as(f32, @floatFromInt(i)) * 0.79 * (3.14159 / 180.0), .y = @as(f32, @floatFromInt(i)) * 0.98 * (3.14159 / 180.0), .z = @as(f32, @floatFromInt(i)) * 1.32 * (3.14159 / 180.0) }; psp.sceGumTranslate(&pos); psp.sceGumRotateXYZ(&rot); @@ -122,7 +122,7 @@ pub fn main() !void { // draw cube - psp.sceGumDrawArray(psp.GuPrimitive.Triangles, @enumToInt(psp.VertexTypeFlags.Texture32Bitf) | @enumToInt(psp.VertexTypeFlags.Color8888) | @enumToInt(psp.VertexTypeFlags.Vertex32Bitf) | @enumToInt(psp.VertexTypeFlags.Transform3D), 12 * 3, null, @ptrCast(*c_void, &vertices)); + psp.sceGumDrawArray(psp.GuPrimitive.Triangles, @intFromEnum(psp.VertexTypeFlags.Texture32Bitf) | @intFromEnum(psp.VertexTypeFlags.Color8888) | @intFromEnum(psp.VertexTypeFlags.Vertex32Bitf) | @intFromEnum(psp.VertexTypeFlags.Transform3D), 12 * 3, null, @as(*c_void, @ptrCast(&vertices))); psp.guFinish(); psp.guSync(psp.GuSyncMode.Finish, psp.GuSyncBehavior.Wait); diff --git a/examples/error.zig b/examples/error.zig index 92e8abb..364924f 100644 --- a/examples/error.zig +++ b/examples/error.zig @@ -5,7 +5,7 @@ const std = @import("std"); const fmt = std.fmt; comptime { - asm(psp.module_info("Zig PSP App", 0, 1, 0)); + asm (psp.module_info("Zig PSP App", 0, 1, 0)); } const MyTestErrors = error{ @@ -17,6 +17,6 @@ pub fn main() !void { psp.debug.screenInit(); try psp.debug.printFormat("Hello {}!\n", .{"world"}); - + return MyTestErrors.TestError; } diff --git a/examples/hello-min.zig b/examples/hello-min.zig index cf4b8fa..ddd014f 100644 --- a/examples/hello-min.zig +++ b/examples/hello-min.zig @@ -9,7 +9,7 @@ usingnamespace @import("psp/utils/mem-fix.zig"); const utils = @import("psp/utils/utils.zig"); comptime { - asm(mod.module_info("Zig PSP App", 0, 1, 0)); + asm (mod.module_info("Zig PSP App", 0, 1, 0)); } pub fn main() !void { diff --git a/examples/hello.zig b/examples/hello.zig index 5f587ae..ce5ca8d 100644 --- a/examples/hello.zig +++ b/examples/hello.zig @@ -6,7 +6,7 @@ const psp = @import("psp/pspsdk.zig"); comptime { - asm(psp.module_info("Zig PSP App", 0, 1, 0)); + asm (psp.module_info("Zig PSP App", 0, 1, 0)); } pub fn main() !void { diff --git a/examples/panic.zig b/examples/panic.zig index 90ed72f..f3eb022 100644 --- a/examples/panic.zig +++ b/examples/panic.zig @@ -4,7 +4,7 @@ const psp = @import("psp/utils/psp.zig"); pub const panic = psp.debug.panic; comptime { - asm(psp.module_info("Zig PSP App", 0, 1, 0)); + asm (psp.module_info("Zig PSP App", 0, 1, 0)); } fn addOne(x: u8) u8 { diff --git a/examples/print.zig b/examples/print.zig index f1a74b1..bd1ea0c 100644 --- a/examples/print.zig +++ b/examples/print.zig @@ -3,7 +3,7 @@ const psp = @import("psp/utils/psp.zig"); comptime { - asm(psp.module_info("Zig PSP App", 0, 1, 0)); + asm (psp.module_info("Zig PSP App", 0, 1, 0)); } pub fn main() !void { diff --git a/src/main.zig b/src/main.zig index a11efbf..7436f6f 100644 --- a/src/main.zig +++ b/src/main.zig @@ -60,12 +60,12 @@ pub fn main() !void { psp.utils.enableHBCB(); psp.debug.screenInit(); - var fbp0 = psp.vram.allocVramRelative(psp.SCR_BUF_WIDTH, psp.SCREEN_HEIGHT, psp.GuPixelMode.Psm8888); - var fbp1 = psp.vram.allocVramRelative(psp.SCR_BUF_WIDTH, psp.SCREEN_HEIGHT, psp.GuPixelMode.Psm8888); - var zbp = psp.vram.allocVramRelative(psp.SCR_BUF_WIDTH, psp.SCREEN_HEIGHT, psp.GuPixelMode.Psm4444); + const fbp0 = psp.vram.allocVramRelative(psp.SCR_BUF_WIDTH, psp.SCREEN_HEIGHT, psp.GuPixelMode.Psm8888); + const fbp1 = psp.vram.allocVramRelative(psp.SCR_BUF_WIDTH, psp.SCREEN_HEIGHT, psp.GuPixelMode.Psm8888); + const zbp = psp.vram.allocVramRelative(psp.SCR_BUF_WIDTH, psp.SCREEN_HEIGHT, psp.GuPixelMode.Psm4444); psp.sceGuInit(); - psp.sceGuStart(psp.GuContextType.Direct, @ptrCast(*c_void, &display_list)); + psp.sceGuStart(psp.GuContextType.Direct, @as(*anyopaque, @ptrCast(&display_list))); psp.sceGuDrawBuffer(psp.GuPixelMode.Psm8888, fbp0, psp.SCR_BUF_WIDTH); psp.sceGuDispBuffer(psp.SCREEN_WIDTH, psp.SCREEN_HEIGHT, fbp1, psp.SCR_BUF_WIDTH); psp.sceGuDepthBuffer(zbp, psp.SCR_BUF_WIDTH); @@ -89,12 +89,12 @@ pub fn main() !void { var i: u32 = 0; while (true) : (i += 1) { - psp.sceGuStart(psp.GuContextType.Direct, @ptrCast(*c_void, &display_list)); + psp.sceGuStart(psp.GuContextType.Direct, @as(*anyopaque, @ptrCast(&display_list))); psp.sceGuClearColor(psp.rgba(32, 32, 32, 0xFF)); psp.sceGuClearDepth(0); - psp.sceGuClear(@enumToInt(psp.ClearBitFlags.ColorBuffer) | - @enumToInt(psp.ClearBitFlags.DepthBuffer)); + psp.sceGuClear(@intFromEnum(psp.ClearBitFlags.ColorBuffer) | + @intFromEnum(psp.ClearBitFlags.DepthBuffer)); psp.sceGumMatrixMode(psp.MatrixMode.Projection); psp.sceGumLoadIdentity(); @@ -108,7 +108,7 @@ pub fn main() !void { //Rotate var pos: psp.ScePspFVector3 = psp.ScePspFVector3{ .x = 0, .y = 0, .z = -2.5 }; - var rot: psp.ScePspFVector3 = psp.ScePspFVector3{ .x = @intToFloat(f32, i) * 0.79 * (3.14159 / 180.0), .y = @intToFloat(f32, i) * 0.98 * (3.14159 / 180.0), .z = @intToFloat(f32, i) * 1.32 * (3.14159 / 180.0) }; + var rot: psp.ScePspFVector3 = psp.ScePspFVector3{ .x = @as(f32, @floatFromInt(i)) * 0.79 * (3.14159 / 180.0), .y = @as(f32, @floatFromInt(i)) * 0.98 * (3.14159 / 180.0), .z = @as(f32, @floatFromInt(i)) * 1.32 * (3.14159 / 180.0) }; psp.sceGumTranslate(&pos); psp.sceGumRotateXYZ(&rot); @@ -122,7 +122,7 @@ pub fn main() !void { // draw cube - psp.sceGumDrawArray(psp.GuPrimitive.Triangles, @enumToInt(psp.VertexTypeFlags.Texture32Bitf) | @enumToInt(psp.VertexTypeFlags.Color8888) | @enumToInt(psp.VertexTypeFlags.Vertex32Bitf) | @enumToInt(psp.VertexTypeFlags.Transform3D), 12 * 3, null, @ptrCast(*c_void, &vertices)); + psp.sceGumDrawArray(psp.GuPrimitive.Triangles, @intFromEnum(psp.VertexTypeFlags.Texture32Bitf) | @intFromEnum(psp.VertexTypeFlags.Color8888) | @intFromEnum(psp.VertexTypeFlags.Vertex32Bitf) | @intFromEnum(psp.VertexTypeFlags.Transform3D), 12 * 3, null, @as(*anyopaque, @ptrCast(&vertices))); psp.guFinish(); psp.guSync(psp.GuSyncMode.Finish, psp.GuSyncBehavior.Wait); diff --git a/src/psp/nids/pspmacros.zig b/src/psp/nids/pspmacros.zig index a3a1cfe..f7f6cc6 100644 --- a/src/psp/nids/pspmacros.zig +++ b/src/psp/nids/pspmacros.zig @@ -6,57 +6,58 @@ pub fn import_module_start(comptime module: []const u8, comptime flags_ver: []co \\.set noreorder \\.section .rodata.sceResident, "a" \\__stub_modulestr_ - ++ module ++ ":\n" ++ + ++ module ++ ":\n" ++ \\.asciz " - ++ module ++ "\"\n" ++ + ++ module ++ "\"\n" ++ \\.align 2 \\.section .lib.stub, "a", @progbits \\.global __stub_module_ - ++ module ++ "\n" ++ + ++ module ++ "\n" ++ \\__stub_module_ - ++ module ++ ":\n" ++ + ++ module ++ ":\n" ++ \\.word __stub_modulestr_ - ++ module ++ "\n" ++ + ++ module ++ "\n" ++ \\.word - ++ flags_ver ++ "\n" ++ + ++ flags_ver ++ "\n" ++ \\.hword 0x5 \\.hword - ++ count ++ "\n" ++ + ++ count ++ "\n" ++ \\.word __stub_idtable_ - ++ module ++ "\n" ++ + ++ module ++ "\n" ++ \\.word __stub_text_ - ++ module ++ "\n" ++ + ++ module ++ "\n" ++ \\.section .rodata.sceNid, "a" \\__stub_idtable_ - ++ module ++ ":\n" ++ + ++ module ++ ":\n" ++ \\.section .sceStub.text, "ax", @progbits \\__stub_text_ - ++ module ++ ":\n" ++ + ++ module ++ ":\n" ++ \\.set pop ); } pub fn import_function(comptime module: []const u8, comptime func_id: []const u8, comptime funcname: []const u8) []const u8 { + _ = module; return ( \\.set push \\.set noreorder \\.section .sceStub.text, "ax", @progbits \\.globl - ++ funcname ++ "\n" ++ + ++ funcname ++ "\n" ++ \\.type - ++ funcname ++ ", @function\n" ++ + ++ funcname ++ ", @function\n" ++ \\.ent - ++ funcname ++ ", 0\n" ++ + ++ funcname ++ ", 0\n" ++ funcname ++ ":\n" ++ \\jr $ra \\nop \\.end - ++ funcname ++ "\n" ++ + ++ funcname ++ "\n" ++ \\.size - ++ funcname ++ ", .-" ++ funcname ++ "\n" ++ + ++ funcname ++ ", .-" ++ funcname ++ "\n" ++ \\.section .rodata.sceNid, "a" \\.word - ++ func_id ++ "\n" ++ + ++ func_id ++ "\n" ++ \\.set pop ); } @@ -121,15 +122,15 @@ pub fn generic_abi_wrapper(comptime funcname: []const u8, comptime argc: u8) []c return ( \\.section .text, "a" \\.global - ++ funcname ++ "\n" ++ funcname ++ ":\n" ++ regLoad ++ "\n" ++ stackAlloc ++ + ++ funcname ++ "\n" ++ funcname ++ ":\n" ++ regLoad ++ "\n" ++ stackAlloc ++ //Preserve return \\sw $ra,0($sp) \\jal //Call the alias - ++ funcname ++ "_stub\n" ++ "\n" ++ + ++ funcname ++ "_stub\n" ++ "\n" ++ //Set correct return address \\lw $ra, 0($sp) - ++ "\n" ++ stackFree ++ + ++ "\n" ++ stackFree ++ //Return \\jr $ra ); diff --git a/src/psp/os/bits.zig b/src/psp/os/bits.zig index cd9d6e6..3f918be 100644 --- a/src/psp/os/bits.zig +++ b/src/psp/os/bits.zig @@ -212,26 +212,26 @@ pub const AT_STATX_DONT_SYNC = 0x4000; /// Apply to the entire subtree pub const AT_RECURSIVE = 0x8000; -usingnamespace @import("../sdk/pspiofilemgr.zig"); -usingnamespace @import("../sdk/psptypes.zig"); +const pspiofilemgr = @import("../sdk/pspiofilemgr.zig"); +const psptypes = @import("../sdk/psptypes.zig"); pub const Stat = struct { mode: u32, st_attr: c_uint, size: u64, - st_ctime: ScePspDateTime, - st_atime: ScePspDateTime, - st_mtime: ScePspDateTime, + st_ctime: psptypes.ScePspDateTime, + st_atime: psptypes.ScePspDateTime, + st_mtime: psptypes.ScePspDateTime, st_private: [6]c_uint, ino: ino_t, pub fn atime(self: Stat) timespec { - return timespec{ .tv_sec = self.st_atime.second, .tv_nsec = @bitCast(isize, self.st_atime.microsecond) * 1000 }; + return timespec{ .tv_sec = self.st_atime.second, .tv_nsec = @as(isize, @bitCast(self.st_atime.microsecond)) * 1000 }; } pub fn mtime(self: Stat) timespec { - return timespec{ .tv_sec = self.st_mtime.second, .tv_nsec = @bitCast(isize, self.st_mtime.microsecond) * 1000 }; + return timespec{ .tv_sec = self.st_mtime.second, .tv_nsec = @as(isize, @bitCast(self.st_mtime.microsecond)) * 1000 }; } pub fn ctime(self: Stat) timespec { - return timespec{ .tv_sec = self.st_ctime.second, .tv_nsec = @bitCast(isize, self.st_ctime.microsecond) * 1000 }; + return timespec{ .tv_sec = self.st_ctime.second, .tv_nsec = @as(isize, @bitCast(self.st_ctime.microsecond)) * 1000 }; } }; diff --git a/src/psp/os/cwd.zig b/src/psp/os/cwd.zig index f8b96a1..cb54b07 100644 --- a/src/psp/os/cwd.zig +++ b/src/psp/os/cwd.zig @@ -1,16 +1,16 @@ -usingnamespace @import("bits.zig"); -usingnamespace @import("system.zig"); +const bits = @import("bits.zig"); +const system = @import("system.zig"); -var __psp_cwd: [PATH_MAX + 1]u8 = [_]u8{0} ** (PATH_MAX + 1); +var __psp_cwd: [bits.PATH_MAX + 1]u8 = [_]u8{0} ** (bits.PATH_MAX + 1); -pub fn __psp_init_cwd(path: ?*c_void) void { +pub fn __psp_init_cwd(path: ?*anyopaque) void { if (path != null) { - var base_path: [PATH_MAX + 1]u8 = undefined; + var base_path: [bits.PATH_MAX + 1]u8 = undefined; var end: ?[*]u8 = null; - _ = strncpy(@ptrCast(?[*]u8, &base_path), @ptrCast([*]const u8, path), PATH_MAX); - base_path[PATH_MAX] = 0; - end = strrchr(@ptrCast([*]u8, base_path[0..]), '/'); + _ = strncpy(@as(?[*]u8, @ptrCast(&base_path)), @as([*]const u8, @ptrCast(path)), bits.PATH_MAX); + base_path[bits.PATH_MAX] = 0; + end = strrchr(@as([*]u8, @ptrCast(base_path[0..])), '/'); if (end != null) { (end.? + 1).* = 0; _ = chdir(base_path[0..]); @@ -26,7 +26,7 @@ pub fn strncpy(dest: ?[*]u8, src: [*]const u8, num: usize) ?[*]u8 { var ptr = dest.?; var ptr2 = src; - var i: isize = @intCast(isize, num); + var i: isize = @as(isize, @intCast(num)); while (ptr[0] != 0 and i >= 0) : (i -= 1) { ptr[0] = ptr2[0]; ptr += 1; @@ -40,37 +40,35 @@ pub fn strncpy(dest: ?[*]u8, src: [*]const u8, num: usize) ?[*]u8 { pub fn strrchr(c: [*]u8, tbf: u8) ?[*]u8 { var found: ?[*]u8 = null; - var ptr = c; - var i: usize = 0; while (c[i] != 0) : (i += 1) { if (c[i] == tbf) { - found = @ptrCast([*]u8, &c[i]); + found = @as([*]u8, @ptrCast(&c[i])); } } return found; } -usingnamespace @import("../sdk/pspiofilemgr.zig"); +const pspiofilemgr = @import("../sdk/pspiofilemgr.zig"); pub fn chdir(path: [*]const u8) c_int { - var dest: [PATH_MAX + 1]u8 = undefined; + var dest: [bits.PATH_MAX + 1]u8 = undefined; var uid: c_int = 0; - if (__psp_path_absolute(path, dest[0..], PATH_MAX) < 0) { - errno = ENAMETOOLONG; + if (__psp_path_absolute(path, dest[0..], bits.PATH_MAX) < 0) { + pspiofilemgr.errno = bits.ENAMETOOLONG; return -1; } - uid = sceIoDopen(dest[0..]); + uid = pspiofilemgr.sceIoDopen(dest[0..]); if (uid < 0) { - errno = ENOTDIR; + pspiofilemgr.errno = bits.ENOTDIR; return -1; } - _ = sceIoDclose(uid); + _ = pspiofilemgr.sceIoDclose(uid); - _ = sceIoChdir(dest[0..]); + _ = pspiofilemgr.sceIoChdir(dest[0..]); _ = strcpy(__psp_cwd[0..], dest[0..]); return 0; } @@ -99,7 +97,7 @@ pub fn __psp_path_absolute(in: [*]const u8, out: [*]u8, len: usize) c_int { // See what the relative URL starts with dr = __psp_get_drive(in); - if (dr > 0 and in[@intCast(usize, dr)] == '/') { + if (dr > 0 and in[@as(usize, @intCast(dr))] == '/') { //It starts with "drive:/", so it's already absolute if (__psp_safe_strcpy(out, in, len) == 0) return -1; @@ -109,7 +107,7 @@ pub fn __psp_path_absolute(in: [*]const u8, out: [*]u8, len: usize) c_int { return -2; _ = strcpy(out, __psp_cwd[0..]); dr = __psp_get_drive(out); - out[@intCast(usize, dr)] = 0; + out[@as(usize, @intCast(dr))] = 0; if (__psp_safe_strcat(out, in, len) == 0) return -3; } else { @@ -118,7 +116,7 @@ pub fn __psp_path_absolute(in: [*]const u8, out: [*]u8, len: usize) c_int { return -4; _ = strcpy(out, __psp_cwd[0..]); - var stat = __psp_safe_strcat(out, "/", len); + const stat = __psp_safe_strcat(out, "/", len); if (stat == 0) { return -6; } @@ -129,7 +127,7 @@ pub fn __psp_path_absolute(in: [*]const u8, out: [*]u8, len: usize) c_int { // Now normalize the pathname portion dr = __psp_get_drive(out); if (dr < 0) dr = 0; - return __psp_path_normalize(out + @intCast(usize, dr), @intCast(usize, @intCast(isize, len) - dr)); + return __psp_path_normalize(out + @as(usize, @intCast(dr)), @as(usize, @intCast(@as(isize, @intCast(len)) - dr))); } pub fn __psp_get_drive(d: [*]const u8) c_int { @@ -139,7 +137,7 @@ pub fn __psp_get_drive(d: [*]const u8) c_int { if (!((d[i] >= 'a' and d[i] <= 'z') or (d[i] >= '0' and d[i] <= '9'))) break; } - if (d[i] == ':') return @intCast(c_int, i + 1); + if (d[i] == ':') return @as(c_int, @intCast(i + 1)); return -1; } @@ -194,11 +192,11 @@ pub fn __psp_path_normalize(out: [*]u8, len: usize) c_int { if (__psp_safe_strcat(out, "/", len) == 0) return -10; // Convert "//" to "/" */ - while (out[@intCast(usize, i) + 1] != 0) : (i += 1) { - if (out[@intCast(usize, i)] == '/' and out[@intCast(usize, i) + 1] == '/') { + while (out[@as(usize, @intCast(i)) + 1] != 0) : (i += 1) { + if (out[@as(usize, @intCast(i))] == '/' and out[@as(usize, @intCast(i)) + 1] == '/') { j = i + 1; - while (out[@intCast(usize, j)] != 0) : (j += 1) { - out[@intCast(usize, j)] = out[@intCast(usize, j + 1)]; + while (out[@as(usize, @intCast(j))] != 0) : (j += 1) { + out[@as(usize, @intCast(j))] = out[@as(usize, @intCast(j + 1))]; } i -= 1; } @@ -206,11 +204,11 @@ pub fn __psp_path_normalize(out: [*]u8, len: usize) c_int { // Convert "/./" to "/" */ i = 0; - while (out[@intCast(usize, i)] != 0 and out[@intCast(usize, i + 1)] != 0 and out[@intCast(usize, i + 2)] != 0) : (i += 1) { - if (out[@intCast(usize, i)] == '/' and out[@intCast(usize, i + 1)] == '.' and out[@intCast(usize, i + 2)] == '/') { + while (out[@as(usize, @intCast(i))] != 0 and out[@as(usize, @intCast(i + 1))] != 0 and out[@as(usize, @intCast(i + 2))] != 0) : (i += 1) { + if (out[@as(usize, @intCast(i))] == '/' and out[@as(usize, @intCast(i + 1))] == '.' and out[@as(usize, @intCast(i + 2))] == '/') { j = i + 1; - while (out[@intCast(usize, j)] != 0) : (j += 1) { - out[@intCast(usize, j)] = out[@intCast(usize, j + 2)]; + while (out[@as(usize, @intCast(j))] != 0) : (j += 1) { + out[@as(usize, @intCast(j))] = out[@as(usize, @intCast(j + 2))]; } i -= 1; } @@ -228,8 +226,8 @@ pub fn __psp_path_normalize(out: [*]u8, len: usize) c_int { out[next + 3] != 0 and out[next + 3] == '/') { j = 0; - while (out[first + @intCast(usize, j + 1)] != 0) : (j += 1) { - out[first + @intCast(usize, j + 1)] = out[next + @intCast(usize, j + 4)]; + while (out[first + @as(usize, @intCast(j + 1))] != 0) : (j += 1) { + out[first + @as(usize, @intCast(j + 1))] = out[next + @as(usize, @intCast(j + 4))]; } first = 0; next = 0; @@ -247,12 +245,12 @@ pub fn __psp_path_normalize(out: [*]u8, len: usize) c_int { // Remove trailing "/" */ i = 1; - while (out[@intCast(usize, i)] != 0) : (i += 1) { + while (out[@as(usize, @intCast(i))] != 0) : (i += 1) { continue; } - if (i >= 1 and out[@intCast(usize, i - 1)] == '/') - out[@intCast(usize, i - 1)] = 0; + if (i >= 1 and out[@as(usize, @intCast(i - 1))] == '/') + out[@as(usize, @intCast(i - 1))] = 0; return 0; } diff --git a/src/psp/os/fdman.zig b/src/psp/os/fdman.zig index fdc601b..5884471 100644 --- a/src/psp/os/fdman.zig +++ b/src/psp/os/fdman.zig @@ -1,4 +1,5 @@ -usingnamespace @import("bits.zig"); +const bits = @import("bits.zig"); +const fd_t = bits.fd_t; pub const __psp_max_fd = 1024; pub const __psp_fdman_type = enum(u8) { @@ -34,32 +35,32 @@ extern fn pspEnableInterrupts(en: u32) void; pub var __psp_descriptor_data_pool: [__psp_max_fd]__psp_fdman_descriptor = undefined; pub var __psp_descriptormap: [__psp_max_fd]?*__psp_fdman_descriptor = undefined; -usingnamespace @import("../include/pspiofilemgr.zig"); -usingnamespace @import("../include/pspstdio.zig"); -usingnamespace @import("system.zig"); +const pspiofilemgr = @import("../include/pspiofilemgr.zig"); +const pspstdio = @import("../include/pspstdio.zig"); +const system = @import("system.zig"); pub fn __psp_fdman_init() void { - @memset(@ptrCast([*]u8, &__psp_descriptor_data_pool), 0, __psp_max_fd * @sizeOf(__psp_fdman_descriptor)); - @memset(@ptrCast([*]u8, &__psp_descriptormap), 0, __psp_max_fd * @sizeOf(?*__psp_fdman_descriptor)); + @memset(@as([*]u8, @ptrCast(&__psp_descriptor_data_pool))[__psp_max_fd * @sizeOf(__psp_fdman_descriptor)], 0); + @memset(@as([*]u8, @ptrCast(&__psp_descriptormap))[__psp_max_fd * @sizeOf(?*__psp_fdman_descriptor)], 0); - var scefd = sceKernelStdin(); + var scefd = pspstdio.sceKernelStdin(); if (scefd >= 0) { __psp_descriptormap[0] = &__psp_descriptor_data_pool[0]; - __psp_descriptormap[0].?.sce_descriptor = @bitCast(u32, scefd); + __psp_descriptormap[0].?.sce_descriptor = @as(u32, @bitCast(scefd)); __psp_descriptormap[0].?.ftype = __psp_fdman_type.Tty; } - scefd = sceKernelStdout(); + scefd = pspstdio.sceKernelStdout(); if (scefd >= 0) { __psp_descriptormap[1] = &__psp_descriptor_data_pool[1]; - __psp_descriptormap[1].?.sce_descriptor = @bitCast(u32, scefd); + __psp_descriptormap[1].?.sce_descriptor = @as(u32, @bitCast(scefd)); __psp_descriptormap[1].?.ftype = __psp_fdman_type.Tty; } - scefd = sceKernelStderr(); + scefd = pspstdio.sceKernelStderr(); if (scefd >= 0) { __psp_descriptormap[2] = &__psp_descriptor_data_pool[2]; - __psp_descriptormap[2].?.sce_descriptor = @bitCast(u32, scefd); + __psp_descriptormap[2].?.sce_descriptor = @as(u32, @bitCast(scefd)); __psp_descriptormap[2].?.ftype = __psp_fdman_type.Tty; } } @@ -78,13 +79,13 @@ pub fn __psp_fdman_get_new_descriptor() i32 { __psp_descriptormap[i] = &__psp_descriptor_data_pool[i]; __psp_descriptormap[i].?.ref_count += 1; pspEnableInterrupts(inten); - return @intCast(i32, i); + return @as(i32, @intCast(i)); } } //Unlock pspEnableInterrupts(inten); - errno = ENOMEM; + pspiofilemgr.errno = bits.ENOMEM; return -1; } @@ -92,14 +93,14 @@ pub fn __psp_fdman_get_dup_descriptor(fd: fd_t) i32 { var i: usize = 0; var inten: u32 = 0; - if (!__PSP_IS_FD_VALID(fd)) { - errno = EBADF; + if (!pspiofilemgr.__PSP_IS_FD_VALID(fd)) { + pspiofilemgr.errno = bits.EBADF; return -1; } inten = pspDisableInterrupts(); while (i < __psp_max_fd) : (i += 1) { - if (__psp_descriptormap[i] == NULL) { + if (__psp_descriptormap[i] == null) { __psp_descriptormap[i] = &__psp_descriptor_data_pool[fd]; __psp_descriptormap[i].?.ref_count += 1; pspEnableInterrupts(inten); @@ -108,13 +109,13 @@ pub fn __psp_fdman_get_dup_descriptor(fd: fd_t) i32 { } pspEnableInterrupts(inten); - errno = ENOMEM; + pspiofilemgr.errno = bits.ENOMEM; return -1; } pub fn __psp_fdman_release_descriptor(fd: fd_t) void { if (!__psp_fdman_fdValid(fd)) { - errno = EBADF; + pspiofilemgr.errno = bits.EBADF; return; } @@ -123,7 +124,7 @@ pub fn __psp_fdman_release_descriptor(fd: fd_t) void { if (__psp_descriptormap[fd].?.ref_count == 0) { __psp_descriptormap[fd].?.sce_descriptor = 0; __psp_descriptormap[fd].?.filename = null; - __psp_descriptormap[fd].?.ftype = @intToEnum(__psp_fdman_type, 0); + __psp_descriptormap[fd].?.ftype = @as(__psp_fdman_type, @enumFromInt(0)); __psp_descriptormap[fd].?.flags = 0; } __psp_descriptormap[fd] = null; diff --git a/src/psp/os/system.zig b/src/psp/os/system.zig index 068a371..f9befd5 100644 --- a/src/psp/os/system.zig +++ b/src/psp/os/system.zig @@ -1,33 +1,36 @@ -usingnamespace @import("bits.zig"); -usingnamespace @import("fdman.zig"); -usingnamespace @import("cwd.zig"); +const bits = @import("bits.zig"); +const fdman = @import("fdman.zig"); +const cwd = @import("cwd.zig"); pub var errno: u32 = 0; fn pspErrToErrno(code: u64) i32 { if ((code & 0x80010000) == 0x80010000) { - errno = @truncate(u32, code & 0xFFFF); + errno = @as(u32, @truncate(code & 0xFFFF)); return -1; } - return @bitCast(i32, @truncate(u32, code)); + return @as(i32, @bitCast(@as(u32, @truncate(code)))); } pub fn getErrno(r: c_int) usize { + _ = r; return errno; } -usingnamespace @import("../include/pspiofilemgr.zig"); -usingnamespace @import("../include/pspstdio.zig"); -usingnamespace @import("../include/psprtc.zig"); +const pspiofilemgr = @import("../include/pspiofilemgr.zig"); +const pspstdio = @import("../include/pspstdio.zig"); +const psprtc = @import("../include/psprtc.zig"); + +const fd_t = psprtc; pub fn read(fd: fd_t, ptr: [*]u8, len: usize) i32 { - if (!__psp_fdman_fdValid(fd)) { - errno = EBADF; + if (!fdman.__psp_fdman_fdValid(fd)) { + errno = bits.EBADF; return -1; } - switch (__psp_descriptormap[fd].?.ftype) { + switch (fdman.__psp_descriptormap[fd].?.ftype) { .File, .Tty => { - return pspErrToErrno(@bitCast(u32, sceIoRead(__psp_descriptormap[fd].?.sce_descriptor, ptr, len))); + return pspErrToErrno(@as(u32, @bitCast(pspiofilemgr.sceIoRead(fdman.__psp_descriptormap[fd].?.sce_descriptor, ptr, len)))); }, else => { @@ -35,22 +38,19 @@ pub fn read(fd: fd_t, ptr: [*]u8, len: usize) i32 { }, } - errno = EBADF; - return -1; - - errno = EBADF; + errno = bits.EBADF; return -1; } pub fn write(fd: fd_t, ptr: [*]const u8, len: usize) i32 { - if (!__psp_fdman_fdValid(fd)) { - errno = EBADF; + if (!fdman.__psp_fdman_fdValid(fd)) { + errno = bits.EBADF; return -1; } - switch (__psp_descriptormap[fd].?.ftype) { + switch (fdman.__psp_descriptormap[fd].?.ftype) { .File, .Tty => { - return pspErrToErrno(@bitCast(u32, sceIoWrite(__psp_descriptormap[fd].?.sce_descriptor, ptr, len))); + return pspErrToErrno(@as(u32, @bitCast(pspiofilemgr.sceIoWrite(fdman.__psp_descriptormap[fd].?.sce_descriptor, ptr, len)))); }, else => { @@ -58,65 +58,68 @@ pub fn write(fd: fd_t, ptr: [*]const u8, len: usize) i32 { }, } - errno = EBADF; + errno = bits.EBADF; return -1; } -pub fn __pspOsInit(arg: ?*c_void) void { - __psp_fdman_init(); - __psp_init_cwd(arg); +pub fn __pspOsInit(arg: ?*anyopaque) void { + fdman.__psp_fdman_init(); + fdman.__psp_init_cwd(arg); } -usingnamespace @import("../include/pspthreadman.zig"); -pub fn nanosleep(req: *const timespec, rem: ?*timespec) c_int { - _ = sceKernelDelayThread(@intCast(c_uint, 1000 * 1000 * req.tv_sec + @divTrunc(req.tv_nsec, 1000))); +const pspthreadman = @import("../include/pspthreadman.zig"); +pub fn nanosleep(req: *const bits.timespec, rem: ?*bits.timespec) c_int { + _ = rem; + _ = pspthreadman.sceKernelDelayThread(@as(c_uint, @intCast(1000 * 1000 * req.tv_sec + @divTrunc(req.tv_nsec, 1000)))); return 0; } -usingnamespace @import("../include/psputils.zig"); -pub fn _times(t: *time_t) time_t { - return pspErrToErrno(sceKernelLibcTime(t)); +const psputils = @import("../include/psputils.zig"); +pub fn _times(t: *bits.time_t) bits.time_t { + return pspErrToErrno(psputils.sceKernelLibcTime(t)); } -pub fn flock(f: fd_t, op: c_int) c_int { +pub fn flock(f: fdman.fd_t, op: c_int) c_int { + _ = f; + _ = op; return 0; } const std = @import("std"); pub fn openat(dir: fd_t, path: [*:0]const u8, flags: u32, mode: u32) c_int { - if (dir != AT_FDCWD) { + if (dir != bits.AT_FDCWD) { @panic("Non-FDCWD Not Supported"); } else { //Do stuff; var scefd: c_int = 0; var fd: c_int = 0; - var dest: [PATH_MAX + 1]u8 = undefined; + var dest: [bits.PATH_MAX + 1]u8 = undefined; - var stat = __psp_path_absolute(path, dest[0..], PATH_MAX); + const stat = fdman.__psp_path_absolute(path, dest[0..], bits.PATH_MAX); if (stat < 0) { - errno = ENAMETOOLONG; + errno = bits.ENAMETOOLONG; return -1; } - scefd = sceIoOpen(dest[0..], @bitCast(c_int, flags), mode); + scefd = pspiofilemgr.sceIoOpen(dest[0..], @as(c_int, @bitCast(flags)), mode); if (scefd >= 0) { - fd = __psp_fdman_get_new_descriptor(); + fd = fdman.__psp_fdman_get_new_descriptor(); if (fd != -1) { - __psp_descriptormap[@intCast(usize, fd)].?.sce_descriptor = scefd; - __psp_descriptormap[@intCast(usize, fd)].?.ftype = __psp_fdman_type.File; - __psp_descriptormap[@intCast(usize, fd)].?.flags = flags; - __psp_descriptormap[@intCast(usize, fd)].?.filename = dest[0..]; + fdman.__psp_descriptormap[@as(usize, @intCast(fd))].?.sce_descriptor = scefd; + fdman.__psp_descriptormap[@as(usize, @intCast(fd))].?.ftype = fdman.__psp_fdman_type.File; + fdman.__psp_descriptormap[@as(usize, @intCast(fd))].?.flags = flags; + fdman.__psp_descriptormap[@as(usize, @intCast(fd))].?.filename = dest[0..]; return fd; } else { - _ = sceIoClose(scefd); - errno = ENOMEM; + _ = pspiofilemgr.sceIoClose(scefd); + errno = bits.ENOMEM; return -1; } } else { - return pspErrToErrno(@bitCast(u32, scefd)); + return pspErrToErrno(@as(u32, @bitCast(scefd))); } - errno = EBADF; + errno = bits.EBADF; return -1; } } @@ -124,17 +127,17 @@ pub fn openat(dir: fd_t, path: [*:0]const u8, flags: u32, mode: u32) c_int { pub fn close(fd: fd_t) c_int { var ret: c_int = 0; - if (!__psp_fdman_fdValid(fd)) { - errno = EBADF; + if (!fdman.__psp_fdman_fdValid(fd)) { + errno = bits.EBADF; return -1; } - switch (__psp_descriptormap[fd].?.ftype) { + switch (fdman.__psp_descriptormap[fd].?.ftype) { .File, .Tty => { - if (__psp_descriptormap[fd].?.ref_count == 1) { - ret = pspErrToErrno(@bitCast(u32, sceIoClose(__psp_descriptormap[fd].?.sce_descriptor))); + if (fdman.__psp_descriptormap[fd].?.ref_count == 1) { + ret = pspErrToErrno(@as(u32, @bitCast(pspiofilemgr.sceIoClose(fdman.__psp_descriptormap[fd].?.sce_descriptor)))); } - __psp_fdman_release_descriptor(fd); + fdman.__psp_fdman_release_descriptor(fd); return ret; }, @@ -143,68 +146,69 @@ pub fn close(fd: fd_t) c_int { }, } - errno = EBADF; + errno = bits.EBADF; return -1; } pub fn unlinkat(dir: fd_t, path: [*:0]const u8, flags: u32) c_int { - if (dir != AT_FDCWD) { + _ = flags; + if (dir != bits.AT_FDCWD) { @panic("Non-FDCWD Not Supported"); } - var dest: [PATH_MAX + 1]u8 = undefined; + var dest: [bits.PATH_MAX + 1]u8 = undefined; - var stat = __psp_path_absolute(path, dest[0..], PATH_MAX); + const stat = fdman.__psp_path_absolute(path, dest[0..], bits.PATH_MAX); if (stat < 0) { - errno = ENAMETOOLONG; + errno = bits.ENAMETOOLONG; return -1; } - var fdStat: SceIoStat = undefined; - _ = sceIoGetstat(dest[0..], &fdStat); + var fdStat: pspiofilemgr.SceIoStat = undefined; + _ = pspiofilemgr.sceIoGetstat(dest[0..], &fdStat); - if (fdStat.st_mode & @enumToInt(IOAccessModes.FIO_S_IFDIR) != 0) { - return pspErrToErrno(@bitCast(u32, sceIoRmdir(dest[0..]))); + if (fdStat.st_mode & @intFromEnum(pspiofilemgr.IOAccessModes.FIO_S_IFDIR) != 0) { + return pspErrToErrno(@as(u32, @bitCast(pspiofilemgr.sceIoRmdir(dest[0..])))); } else { - return pspErrToErrno(@bitCast(u32, sceIoRemove(dest[0..]))); + return pspErrToErrno(@as(u32, @bitCast(pspiofilemgr.sceIoRemove(dest[0..])))); } } pub fn mkdirat(dir: fd_t, path: [*:0]const u8, mode: u32) c_int { - if (dir != AT_FDCWD) { + if (dir != bits.AT_FDCWD) { @panic("Non-FDCWD Not Supported"); } - var dest: [PATH_MAX + 1]u8 = undefined; - var stat = __psp_path_absolute(path, dest[0..], PATH_MAX); + var dest: [bits.PATH_MAX + 1]u8 = undefined; + const stat = fdman.__psp_path_absolute(path, dest[0..], bits.PATH_MAX); if (stat < 0) { - errno = ENAMETOOLONG; + errno = bits.ENAMETOOLONG; return -1; } - return pspErrToErrno(@bitCast(u32, sceIoMkdir(dest[0..], mode))); + return pspErrToErrno(@as(u32, @bitCast(pspiofilemgr.sceIoMkdir(dest[0..], mode)))); } -pub fn fstat(fd: fd_t, stat: *Stat) c_int { - var psp_stat: SceIoStat = undefined; - var dest: [PATH_MAX + 1]u8 = undefined; +pub fn fstat(fd: fd_t, stat: *pspiofilemgr.Stat) c_int { + var psp_stat: pspiofilemgr.SceIoStat = undefined; + var dest: [bits.PATH_MAX + 1]u8 = undefined; var ret: i32 = 0; - var status = __psp_path_absolute(@ptrCast([*]const u8, &__psp_descriptormap[fd].?.filename.?), dest[0..], PATH_MAX); + const status = fdman.__psp_path_absolute(@as([*]const u8, @ptrCast(&fdman.__psp_descriptormap[fd].?.filename.?)), dest[0..], bits.PATH_MAX); if (status < 0) { - errno = ENAMETOOLONG; + errno = pspiofilemgr.ENAMETOOLONG; return -1; } - @memset(@ptrCast([*]u8, stat), 0, @sizeOf(Stat)); - ret = sceIoGetstat(dest[0..], &psp_stat); + @memset(@as([*]u8, @ptrCast(stat))[0..@sizeOf(stat)], 0); + ret = pspiofilemgr.sceIoGetstat(dest[0..], &psp_stat); if (ret < 0) { - return pspErrToErrno(@bitCast(u32, ret)); + return pspErrToErrno(@as(u32, @bitCast(ret))); } - stat.mode = @bitCast(u32, psp_stat.st_mode); + stat.mode = @as(u32, @bitCast(psp_stat.st_mode)); stat.st_attr = @as(u64, psp_stat.st_attr); - stat.size = @bitCast(u64, psp_stat.st_size); + stat.size = @as(u64, @bitCast(psp_stat.st_size)); stat.st_ctime = psp_stat.st_ctime; stat.st_atime = psp_stat.st_atime; stat.st_mtime = psp_stat.st_mtime; @@ -214,59 +218,60 @@ pub fn fstat(fd: fd_t, stat: *Stat) c_int { } pub fn faccessat(dir: fd_t, path: [*:0]const u8, mode: u32, flags: u32) c_int { - if (dir != AT_FDCWD) { + _ = mode; + if (dir != bits.AT_FDCWD) { @panic("Non-FDCWD Not Supported"); } - var dest: [PATH_MAX + 1]u8 = undefined; - var stat = __psp_path_absolute(path, dest[0..], PATH_MAX); + var dest: [bits.PATH_MAX + 1]u8 = undefined; + const stat = fdman.__psp_path_absolute(path, dest[0..], bits.PATH_MAX); if (stat < 0) { - errno = ENAMETOOLONG; + errno = bits.ENAMETOOLONG; return -1; } - var fdStat: SceIoStat = undefined; - var v = sceIoGetstat(dest[0..], &fdStat); + var fdStat: pspiofilemgr.SceIoStat = undefined; + const v = pspiofilemgr.sceIoGetstat(dest[0..], &fdStat); if (v != 0) { - return pspErrToErrno(@bitCast(u32, v)); + return pspErrToErrno(@as(u32, @bitCast(v))); } - if (fdStat.st_mode & S_IFDIR != 0) { + if (fdStat.st_mode & pspiofilemgr.S_IFDIR != 0) { return 0; } - if (flags & W_OK == 0) { + if (flags & bits.W_OK == 0) { return 0; } - errno = EACCES; + errno = bits.EACCES; return -1; } pub fn lseek(fd: fd_t, off: i64, whence: c_int) c_int { - if (!__psp_fdman_fdValid(fd)) { - errno = EBADF; + if (!fdman.__psp_fdman_fdValid(fd)) { + errno = bits.EBADF; return -1; } - switch (__psp_descriptormap[fd].?.ftype) { + 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(@bitCast(u32, sceIoLseek32(__psp_descriptormap[fd].?.sce_descriptor, @truncate(c_int, off), whence))); + return pspErrToErrno(@as(u32, @bitCast(pspiofilemgr.sceIoLseek32(fdman.__psp_descriptormap[fd].?.sce_descriptor, @as(c_int, @truncate(off)), whence)))); }, else => { - errno = EBADF; + errno = bits.EBADF; return -1; }, } } pub fn isatty(fd: fd_t) c_int { - if (!__psp_fdman_fdValid(fd)) { - errno = EBADF; + if (!fdman.__psp_fdman_fdValid(fd)) { + errno = bits.EBADF; return -1; } - return @intCast(c_int, @boolToInt(__psp_fdman_fdType(fd, __psp_fdman_type.Tty))); + return @as(c_int, @intCast(@intFromBool(fdman.__psp_fdman_fdType(fd, fdman.__psp_fdman_type.Tty)))); } diff --git a/src/psp/os/time.zig b/src/psp/os/time.zig index 60baf6e..4c1623a 100644 --- a/src/psp/os/time.zig +++ b/src/psp/os/time.zig @@ -15,7 +15,7 @@ usingnamespace @import("../include/pspthreadman.zig"); /// Spurious wakeups are possible and no precision of timing is guaranteed. /// TODO integrate with evented I/O pub fn sleep(nanoseconds: u64) void { - _ = sceKernelDelayThread(@truncate(u32, nanoseconds / 1000)); + _ = sceKernelDelayThread(@as(u32, @truncate(nanoseconds / 1000))); } /// Get a calendar timestamp, in seconds, relative to UTC 1970-01-01. @@ -26,7 +26,7 @@ pub fn sleep(nanoseconds: u64) void { pub fn timestamp() i64 { var r: u64 = 0; _ = sceRtcGetCurrentTick(&r); - return @intCast(i64, r / sceRtcGetTickResolution()); + return @as(i64, @intCast(r / sceRtcGetTickResolution())); } /// Get a calendar timestamp, in milliseconds, relative to UTC 1970-01-01. @@ -37,7 +37,7 @@ pub fn timestamp() i64 { pub fn milliTimestamp() i64 { var r: u64 = 0; _ = sceRtcGetCurrentTick(&r); - return @intCast(i64, r / 1000); + return @as(i64, @intCast(r / 1000)); } /// Get a calendar timestamp, in nanoseconds, relative to UTC 1970-01-01. @@ -49,7 +49,7 @@ pub fn milliTimestamp() i64 { pub fn nanoTimestamp() i128 { var r: u64 = 0; _ = sceRtcGetCurrentTick(&r); - return @intCast(i64, r * 1000); + return @as(i64, @intCast(r * 1000)); } // Divisions of a nanosecond. diff --git a/src/psp/sdk/cos.zig b/src/psp/sdk/cos.zig index 093feb1..99a897e 100644 --- a/src/psp/sdk/cos.zig +++ b/src/psp/sdk/cos.zig @@ -58,10 +58,10 @@ 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 = @floatToInt(I, y); + var j = @as(I, @intFromFloat(y)); if (j & 1 == 1) { j += 1; diff --git a/src/psp/sdk/pspatrac3.zig b/src/psp/sdk/pspatrac3.zig index c247757..dbf5cff 100644 --- a/src/psp/sdk/pspatrac3.zig +++ b/src/psp/sdk/pspatrac3.zig @@ -1,5 +1,5 @@ -usingnamespace @import("psptypes.zig"); -test "" { +const psptypes = @import("psptypes.zig"); +test { @import("std").meta.refAllDecls(@This()); } @@ -31,72 +31,73 @@ pub const AtracError = enum(u32) { fn intToError(res: c_int) !void { @setRuntimeSafety(false); if (res < 0) { - var translated = @bitCast(u32, res); - switch (@intToEnum(AtracError, res)) { - ParamFail => { + const translated = @as(u32, @bitCast(res)); + _ = translated; + switch (@as(AtracError, @enumFromInt(res))) { + psptypes.ParamFail => { return error.ParamFail; }, - ApiFail => { + psptypes.ApiFail => { return error.ApiFail; }, - NoAtracid => { + psptypes.NoAtracid => { return error.NoAtracid; }, - BadCodectype => { + psptypes.BadCodectype => { return error.BadCodectype; }, - BadAtracid => { + psptypes.BadAtracid => { return error.BadAtracid; }, - UnknownFormat => { + psptypes.UnknownFormat => { return error.UnknownFormat; }, - UnmatchFormat => { + psptypes.UnmatchFormat => { return error.UnmatchFormat; }, - BadData => { + psptypes.BadData => { return error.BadData; }, - AlldataIsOnmemory => { + psptypes.AlldataIsOnmemory => { return error.AlldataIsOnmemory; }, - UnsetData => { + psptypes.UnsetData => { return error.UnsetData; }, - ReadSizeIsTooSmall => { + psptypes.ReadSizeIsTooSmall => { return error.ReadSizeIsTooSmall; }, - NeedSecondBuffer => { + psptypes.NeedSecondBuffer => { return error.NeedSecondBuffer; }, - ReadSizeOverBuffer => { + psptypes.ReadSizeOverBuffer => { return error.ReadSizeOverBuffer; }, - Not4byteAlignment => { + psptypes.Not4byteAlignment => { return error.Not4byteAlignment; }, - BadSample => { + psptypes.BadSample => { return error.BadSample; }, - WriteByteFirstBuffer => { + psptypes.WriteByteFirstBuffer => { return error.WriteByteFirstBuffer; }, - WriteByteSecondBuffer => { + psptypes.WriteByteSecondBuffer => { return error.WriteByteSecondBuffer; }, - AddDataIsTooBig => { + psptypes.AddDataIsTooBig => { return error.AddDataIsTooBig; }, - UnsetParam => { + psptypes.UnsetParam => { return error.UnsetParam; }, - NoNeedSecondBuffer => { + psptypes.NoNeedSecondBuffer => { return error.NoNeedSecondBuffer; }, - NoDataInBuffer => { + psptypes.NoDataInBuffer => { return error.NoDataInBuffer; }, - AllDataWasDecoded => { + psptypes.AllDataWasDecoded => { return error.AllDataWasDecoded; }, } @@ -126,7 +127,7 @@ pub const AtracCodecType = enum(u32) { // Gets the ID for a certain codec. // Can return error for invalid ID. pub fn atracGetAtracID(uiCodecType: AtracCodecType) !i32 { - var res = sceAtracGetAtracID(@enumToInt(uiCodecType)); + const res = sceAtracGetAtracID(@intFromEnum(uiCodecType)); try intToError(res); return res; } @@ -137,10 +138,10 @@ pub fn atracGetAtracID(uiCodecType: AtracCodecType) !i32 { // @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 sceAtracSetDataAndGetID(buf: ?*anyopaque, bufsize: psptypes.SceSize) c_int; -pub fn atracSetDataAndGetID(buf: *c_void, bufSize: usize) !u32 { - var res = sceAtracSetDataAndGetID(buf, bufSize); +pub fn atracSetDataAndGetID(buf: *anyopaque, bufSize: usize) !u32 { + const res = sceAtracSetDataAndGetID(buf, bufSize); try intToError(res); return res; } @@ -159,7 +160,7 @@ pub fn atracSetDataAndGetID(buf: *c_void, bufSize: usize) !u32 { 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); + const res = sceAtracDecodeData(atracID, outSamples, outN, outEnd, outRemainFrame); try intToError(res); } @@ -173,7 +174,7 @@ pub fn atracDecodeData(atracID: u32, outSamples: []u16, outN: []i32, outEnd: []i 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); + const res = sceAtracDecodeData(atracID, psptypes.outSamples, psptypes.outN, psptypes.outEnd, outRemainFrame); try intToError(res); } @@ -187,7 +188,7 @@ pub fn atracGetRemainFrame(atracID: u32, outRemainFrame: []i32) !void { 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); + const res = sceAtracGetStreamDataInfo(atracID, writePointer, availableBytes, readOffset); try intToError(res); } @@ -199,7 +200,7 @@ pub fn atracGetStreamDataInfo(atracID: u32, writePointer: [*c][*c]u8, availableB pub extern fn sceAtracAddStreamData(atracID: u32, bytesToAdd: c_uint) c_int; pub fn atracAddStreamData(atracID: u32, bytesToAdd: u32) !void { - var res = sceAtracAddStreamData(atracID, bytesToAdd); + const res = sceAtracAddStreamData(atracID, bytesToAdd); try intToError(res); } @@ -212,7 +213,7 @@ pub fn atracAddStreamData(atracID: u32, bytesToAdd: u32) !void { 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); + const res = sceAtracGetBitrate(atracID, outBitrate); try intToError(res); } @@ -225,7 +226,7 @@ pub fn atracGetBitrate(atracID: u32, outBitrate: [*c]c_int) !void { 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); + const res = atracSetLoopNum(atracID, nloops); try intToError(res); } @@ -237,7 +238,7 @@ pub fn atracSetLoopNum(atracID: u32, nloops: c_int) !void { pub extern fn sceAtracReleaseAtracID(atracID: u32) c_int; pub fn atracReleaseAtracID(atracID: u32) !i32 { - var res = sceAtracReleaseAtracID(atracID); + const res = sceAtracReleaseAtracID(atracID); try intToError(res); return res; } @@ -251,7 +252,7 @@ pub fn atracReleaseAtracID(atracID: u32) !i32 { 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); + const res = sceAtracGetNextSample(atracID, outN); try intToError(res); } diff --git a/src/psp/sdk/pspaudio.zig b/src/psp/sdk/pspaudio.zig index 0b59629..6c1265a 100644 --- a/src/psp/sdk/pspaudio.zig +++ b/src/psp/sdk/pspaudio.zig @@ -1,4 +1,4 @@ -pub const PspAudioFormats = extern enum(c_int) { +pub const PspAudioFormats = enum(c_int) { Stereo = 0, Mono = 16, _, @@ -41,7 +41,7 @@ pub extern fn sceAudioChRelease(channel: c_int) c_int; // @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; +pub extern fn sceAudioOutput(channel: c_int, vol: c_int, buf: ?*anyopaque) c_int; // Output audio of the specified channel (blocking) // @@ -52,7 +52,7 @@ pub extern fn sceAudioOutput(channel: c_int, vol: c_int, buf: ?*c_void) c_int; // @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; +pub extern fn sceAudioOutputBlocking(channel: c_int, vol: c_int, buf: ?*anyopaque) c_int; // Output panned audio of the specified channel // @@ -65,7 +65,7 @@ pub extern fn sceAudioOutputBlocking(channel: c_int, vol: c_int, buf: ?*c_void) // @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; +pub extern fn sceAudioOutputPanned(channel: c_int, leftvol: c_int, rightvol: c_int, buf: ?*anyopaque) c_int; // Output panned audio of the specified channel (blocking) // @@ -78,7 +78,7 @@ pub extern fn sceAudioOutputPanned(channel: c_int, leftvol: c_int, rightvol: c_i // @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; +pub extern fn sceAudioOutputPannedBlocking(channel: c_int, leftvol: c_int, rightvol: c_int, buf: ?*anyopaque) c_int; // Get count of unplayed samples remaining // @@ -148,7 +148,7 @@ pub extern fn sceAudioOutput2ChangeLength(samplecount: c_int) c_int; // @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; +pub extern fn sceAudioOutput2OutputBlocking(vol: c_int, buf: ?*anyopaque) c_int; // Get count of unplayed samples remaining // @@ -178,7 +178,7 @@ pub extern fn sceAudioSRCChRelease() c_int; // @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; +pub extern fn sceAudioSRCOutputBlocking(vol: c_int, buf: ?*anyopaque) c_int; // Init audio input // @@ -207,7 +207,7 @@ pub extern fn sceAudioInputInitEx(params: [*]PspAudioInputParams) c_int; // @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; +pub extern fn sceAudioInputBlocking(samplecount: c_int, freq: c_int, buf: ?*anyopaque) c_int; // Perform audio input // @@ -218,7 +218,7 @@ pub extern fn sceAudioInputBlocking(samplecount: c_int, freq: c_int, buf: ?*c_vo // @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; +pub extern fn sceAudioInput(samplecount: c_int, freq: c_int, buf: ?*anyopaque) c_int; // Get the number of samples that were acquired // diff --git a/src/psp/sdk/pspaudiocodec.zig b/src/psp/sdk/pspaudiocodec.zig index 385a28c..46742cf 100644 --- a/src/psp/sdk/pspaudiocodec.zig +++ b/src/psp/sdk/pspaudiocodec.zig @@ -1,4 +1,4 @@ -pub const Codec = extern enum(c_int) { +pub const Codec = enum(c_int) { At3Plus = 0x1000, At3 = 0x1001, Mp3 = 0x1002, diff --git a/src/psp/sdk/pspctrl.zig b/src/psp/sdk/pspctrl.zig index 4dec57f..1cf6c44 100644 --- a/src/psp/sdk/pspctrl.zig +++ b/src/psp/sdk/pspctrl.zig @@ -1,4 +1,4 @@ -pub const PspCtrlButtons = extern enum(c_uint) { +pub const PspCtrlButtons = enum(c_uint) { Select = 1, Start = 8, Up = 16, @@ -23,7 +23,7 @@ pub const PspCtrlButtons = extern enum(c_uint) { Ms = 33554432, }; -pub const PspCtrlMode = extern enum(c_int) { +pub const PspCtrlMode = enum(c_int) { Digital = 0, Analog = 1, }; @@ -66,8 +66,8 @@ pub extern fn sceCtrlSetSamplingMode(mode: c_int) c_int; pub fn ctrlSetSamplingMode(mode: PspCtrlMode) PspCtrlMode { @setRuntimeSafety(false); - var res = sceCtrlSetSamplingMode(@enumToInt(mode)); - return @intToEnum(PspCtrlMode, res); + const res = sceCtrlSetSamplingMode(@intFromEnum(mode)); + return @as(PspCtrlMode, @enumFromInt(res)); } // Get the current controller mode. @@ -106,7 +106,7 @@ pub extern fn sceCtrlReadLatch(latch_data: *SceCtrlLatch) c_int; // @return < 0 on error. pub extern fn sceCtrlSetIdleCancelThreshold(idlereset: c_int, idleback: c_int) c_int; pub fn ctrlSetIdleCancelThreshold(idlereset: c_int, idleback: c_int) !i32 { - var res = sceCtrlSetIdleCancelThreshold(idlereset, idleback); + const res = sceCtrlSetIdleCancelThreshold(idlereset, idleback); if (res < 0) { return error.Unexpected; } @@ -121,7 +121,7 @@ pub fn ctrlSetIdleCancelThreshold(idlereset: c_int, idleback: c_int) !i32 { // @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); + const res = sceCtrlGetIdleCancelThreshold(idlerest, idleback); if (res < 0) { return error.Unexpected; } diff --git a/src/psp/sdk/pspdisplay.zig b/src/psp/sdk/pspdisplay.zig index 55d58e8..9f70957 100644 --- a/src/psp/sdk/pspdisplay.zig +++ b/src/psp/sdk/pspdisplay.zig @@ -1,16 +1,16 @@ -pub const PspDisplayPixelFormats = extern enum(c_int) { +pub const PspDisplayPixelFormats = enum(c_int) { Format565 = 0, Format5551 = 1, Format4444 = 2, Format8888 = 3, }; -pub const PspDisplaySetBufSync = extern enum(c_int) { +pub const PspDisplaySetBufSync = enum(c_int) { Immediate = 0, Nextframe = 1, }; -pub const PspDisplayErrorCodes = extern enum(c_int) { +pub const PspDisplayErrorCodes = enum(c_int) { Ok = 0, Pointer = 2147483907, Argument = 2147483911, @@ -37,7 +37,7 @@ pub fn displaySetMode(mode: c_int, width: c_int, height: c_int) void { // @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); + const res = sceDisplayGetMode(pmode, pwidth, pheight); return res == 0; } @@ -49,9 +49,9 @@ pub fn displayGetMode(pmode: *c_int, pwidth: *c_int, pheight: *c_int) bool { // @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 fn displaySetFrameBuf(topaddr: ?*c_void, bufferwidth: c_int, pixelformat: c_int, sync: c_int) bool { - var res = sceDisplaySetFrameBuf(topaddr, bufferwidth, pixelformat, sync); +pub extern fn sceDisplaySetFrameBuf(topaddr: ?*anyopaque, bufferwidth: c_int, pixelformat: c_int, sync: c_int) c_int; +pub fn displaySetFrameBuf(topaddr: ?*anyopaque, bufferwidth: c_int, pixelformat: c_int, sync: c_int) bool { + const res = sceDisplaySetFrameBuf(topaddr, bufferwidth, pixelformat, sync); return res; } @@ -63,9 +63,9 @@ pub fn displaySetFrameBuf(topaddr: ?*c_void, bufferwidth: c_int, pixelformat: c_ // @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); +pub extern fn sceDisplayGetFrameBuf(topaddr: **anyopaque, bufferwidth: *c_int, pixelformat: *c_int, sync: c_int) c_int; +pub fn displayGetFrameBuf(topaddr: **anyopaque, bufferwidth: *c_int, pixelformat: *c_int, sync: c_int) bool { + const res = sceDisplayGetFrameBuf(topaddr, bufferwidth, pixelformat, sync); return res == 0; } diff --git a/src/psp/sdk/pspdmac.zig b/src/psp/sdk/pspdmac.zig index 9ac763e..231093f 100644 --- a/src/psp/sdk/pspdmac.zig +++ b/src/psp/sdk/pspdmac.zig @@ -1,4 +1,5 @@ -usingnamespace @import("psptypes.zig"); +const psptypes = @import("psptypes.zig"); +const SceSize = psptypes.SceSize; // Copy data in memory using DMAC // @@ -7,6 +8,6 @@ usingnamespace @import("psptypes.zig"); // @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 sceDmacMemcpy(dst: *anyopaque, src: *const anyopaque, n: SceSize) c_int; -pub extern fn sceDmacTryMemcpy(dst: *c_void, src: *const c_void, n: SceSize) c_int; +pub extern fn sceDmacTryMemcpy(dst: *anyopaque, src: *const anyopaque, n: SceSize) c_int; diff --git a/src/psp/sdk/pspge.zig b/src/psp/sdk/pspge.zig index 06fc8e6..b85d5c2 100644 --- a/src/psp/sdk/pspge.zig +++ b/src/psp/sdk/pspge.zig @@ -6,12 +6,12 @@ pub const SceGeStack = extern struct { stack: [8]c_uint, }; -pub const PspGeCallback = ?fn (c_int, ?*c_void) callconv(.C) void; +pub const PspGeCallback = ?*const fn (c_int, ?*anyopaque) callconv(.C) void; pub const PspGeCallbackData = extern struct { signal_func: PspGeCallback, - signal_arg: ?*c_void, + signal_arg: ?*anyopaque, finish_func: PspGeCallback, - finish_arg: ?*c_void, + finish_arg: ?*anyopaque, }; pub const PspGeListArgs = extern struct { @@ -25,7 +25,7 @@ pub const PspGeBreakParam = extern struct { buf: [4]c_uint, }; -pub const PspGeMatrixTypes = extern enum(c_int) { +pub const PspGeMatrixTypes = enum(c_int) { Bone0 = 0, Bone1 = 1, Bone2 = 2, @@ -44,7 +44,7 @@ pub const PspGeStack = extern struct { stack: [8]c_uint, }; -pub const PspGeListState = extern enum(c_int) { +pub const PspGeListState = enum(c_int) { Done = 0, Queued = 1, DrawingDone = 2, @@ -60,7 +60,7 @@ 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; +pub extern fn sceGeEdramGetAddr() ?*anyopaque; // Retrieve the current value of a GE command. // @@ -75,7 +75,7 @@ pub extern fn sceGeGetCmd(cmd: c_int) c_uint; // @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; +pub extern fn sceGeGetMtx(typec: c_int, matrix: ?*anyopaque) c_int; // Save the GE's current state. // @@ -100,7 +100,7 @@ pub extern fn sceGeRestoreContext(context: [*c]const PspGeContext) c_int; // @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; +pub extern fn sceGeListEnQueue(list: ?*const anyopaque, stall: ?*anyopaque, cbid: c_int, arg: [*c]PspGeListArgs) c_int; // Enqueue a display list at the head of the GE display list queue. // @@ -111,7 +111,7 @@ pub extern fn sceGeListEnQueue(list: ?*const c_void, stall: ?*c_void, cbid: c_in // @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; +pub extern fn sceGeListEnQueueHead(list: ?*const anyopaque, stall: ?*anyopaque, cbid: c_int, arg: [*c]PspGeListArgs) c_int; // Cancel a queued or running list. // @@ -126,7 +126,7 @@ pub extern fn sceGeListDeQueue(qid: c_int) c_int; // @param stall - The new stall address. // // @return < 0 on error -pub extern fn sceGeListUpdateStallAddr(qid: c_int, stall: ?*c_void) c_int; +pub extern fn sceGeListUpdateStallAddr(qid: c_int, stall: ?*anyopaque) c_int; // Wait for syncronisation of a list. // diff --git a/src/psp/sdk/pspguimpl.zig b/src/psp/sdk/pspguimpl.zig index eb155e0..35bf7d6 100644 --- a/src/psp/sdk/pspguimpl.zig +++ b/src/psp/sdk/pspguimpl.zig @@ -1,14 +1,14 @@ -usingnamespace @import("pspge.zig"); -usingnamespace @import("pspgutypes.zig"); -usingnamespace @import("psptypes.zig"); -usingnamespace @import("pspdisplay.zig"); +const pspge = @import("pspge.zig"); +const pspgutypes = @import("pspgutypes.zig"); +const psptypes = @import("psptypes.zig"); +const display = @import("pspdisplay.zig"); -test "" { +test { @import("std").meta.refAllDecls(@This()); } //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, @@ -18,7 +18,7 @@ const GuSettings = struct { kernel_event_flag: i32, ge_callback_id: i32, - swapBuffersCallback: GuSwapBuffersCallback, + swapBuffersCallback: pspgutypes.GuSwapBuffersCallback, swapBuffersBehaviour: i32, }; @@ -50,9 +50,9 @@ const GuContext = struct { const GuDrawBuffer = struct { pixel_size: i32, frame_width: i32, - frame_buffer: ?*c_void, - disp_buffer: ?*c_void, - depth_buffer: ?*c_void, + frame_buffer: ?*anyopaque, + disp_buffer: ?*anyopaque, + depth_buffer: ?*anyopaque, depth_width: i32, width: i32, height: i32, @@ -80,7 +80,7 @@ const GuLightSettings = struct { var gu_current_frame: u32 = 0; var gu_contexts: [3]GuContext = undefined; var ge_list_executed: [2]i32 = undefined; -var ge_edram_address: ?*c_void = null; +var ge_edram_address: ?*anyopaque = null; var gu_settings: GuSettings = undefined; var gu_list: ?*GuDisplayList = null; var gu_curr_context: i32 = 0; @@ -171,22 +171,22 @@ var light_settings: [4]GuLightSettings = [_]GuLightSettings{ }, }; -usingnamespace @import("pspthreadman.zig"); -pub export fn callbackSig(id: c_int, arg: ?*c_void) void { +const pspthreadman = @import("pspthreadman.zig"); +pub export fn callbackSig(id: c_int, arg: ?*anyopaque) void { @setRuntimeSafety(false); - var settings: ?*GuSettings = @intToPtr(?*GuSettings, @ptrToInt(arg)); - settings.?.signal_history[@intCast(usize, (settings.?.signal_offset)) & 15] = @intCast(u16, id) & 0xffff; + var settings: ?*GuSettings = @as(?*GuSettings, @ptrFromInt(@intFromPtr(arg))); + settings.?.signal_history[@as(usize, @intCast((settings.?.signal_offset))) & 15] = @as(u16, @intCast(id)) & 0xffff; settings.?.signal_offset += 1; if (settings.?.sig != null) settings.?.sig.?(id & 0xffff); - _ = sceKernelSetEventFlag(settings.?.kernel_event_flag, 1); + _ = pspthreadman.sceKernelSetEventFlag(settings.?.kernel_event_flag, 1); } -pub export fn callbackFin(id: c_int, arg: ?*c_void) void { +pub export fn callbackFin(id: c_int, arg: ?*anyopaque) void { @setRuntimeSafety(false); - var settings: ?*GuSettings = @intToPtr(?*GuSettings, @ptrToInt(arg)); + const settings: ?*GuSettings = @as(?*GuSettings, @ptrFromInt(@intFromPtr(arg))); if (settings.?.fin != null) { settings.?.fin.?(id & 0xffff); } @@ -243,7 +243,7 @@ pub fn resetValues() void { pub fn sendCommandi(cmd: c_int, argument: c_int) void { @setRuntimeSafety(false); - gu_list.?.current[0] = (@intCast(u32, cmd) << 24) | (@intCast(u32, argument) & 0xffffff); + gu_list.?.current[0] = (@as(u32, @intCast(cmd)) << 24) | (@as(u32, @intCast(argument)) & 0xffffff); gu_list.?.current += 1; } @@ -251,20 +251,20 @@ pub fn sendCommandiStall(cmd: c_int, argument: c_int) void { @setRuntimeSafety(false); sendCommandi(cmd, argument); if (gu_object_stack_depth == 0 and gu_curr_context == 0) { - _ = sceGeListUpdateStallAddr(ge_list_executed[0], @ptrCast(*c_void, gu_list.?.current)); + _ = pspge.sceGeListUpdateStallAddr(ge_list_executed[0], @as(*anyopaque, @ptrCast(gu_list.?.current))); } } pub fn sendCommandf(cmd: c_int, argument: f32) void { @setRuntimeSafety(false); - sendCommandi(cmd, @bitCast(c_int, argument) >> 8); + sendCommandi(cmd, @as(c_int, @bitCast(argument)) >> 8); } //GU IMPLEMENTATION -pub fn sceGuAlphaFunc(func: AlphaFunc, value: c_int, mask: c_int) void { +pub fn sceGuAlphaFunc(func: pspgutypes.AlphaFunc, value: c_int, mask: c_int) void { @setRuntimeSafety(false); - var arg: c_int = @enumToInt(func) | ((value & 0xff) << 8) | ((mask & 0xff) << 16); + const arg: c_int = @intFromEnum(func) | ((value & 0xff) << 8) | ((mask & 0xff) << 16); sendCommandi(219, arg); } pub fn sceGuAmbient(col: u32) void { @@ -274,15 +274,15 @@ pub fn sceGuAmbient(col: u32) void { } pub fn sceGuAmbientColor(col: u32) void { @setRuntimeSafety(false); - sendCommandi(85, @intCast(c_int, col) & 0xffffff); - sendCommandi(88, @intCast(c_int, col) >> 24); + sendCommandi(85, @as(c_int, @intCast(col)) & 0xffffff); + sendCommandi(88, @as(c_int, @intCast(col)) >> 24); } -pub fn sceGuBlendFunc(bop: BlendOp, sc: BlendArg, dst: BlendArg, srcfix: c_int, destfix: c_int) void { - var op: c_int = @enumToInt(bop); +pub fn sceGuBlendFunc(bop: pspgutypes.BlendOp, sc: pspgutypes.BlendArg, dst: pspgutypes.BlendArg, srcfix: c_int, destfix: c_int) void { + const op: c_int = @intFromEnum(bop); - var src: c_int = @enumToInt(sc); - var dest: c_int = @enumToInt(dst); + const src: c_int = @intFromEnum(sc); + const dest: c_int = @intFromEnum(dst); @setRuntimeSafety(false); sendCommandi(223, src | (dest << 4) | (op << 8)); @@ -291,6 +291,7 @@ pub fn sceGuBlendFunc(bop: BlendOp, sc: BlendArg, dst: BlendArg, srcfix: c_int, } pub fn sceGuBreak(a0: c_int) void { + _ = a0; @setRuntimeSafety(false); //Does nothing or is broken? } @@ -300,9 +301,9 @@ pub fn sceGuContinue() void { //Does nothing or is broken? } -pub fn sceGuCallList(list: ?*const c_void) void { +pub fn sceGuCallList(list: ?*const anyopaque) void { @setRuntimeSafety(false); - var list_addr: c_int = @intCast(c_int, @ptrToInt(list)); + const list_addr: c_int = @as(c_int, @intCast(@intFromPtr(list))); if (gu_call_mode == 1) { sendCommandi(14, (list_addr >> 16) | 0x110000); @@ -320,35 +321,35 @@ pub fn sceGuCallMode(mode: c_int) void { } pub fn sceGuCheckList() c_int { - return @intCast(c_int, (@ptrToInt(gu_list.?.current) - @ptrToInt(gu_list.?.start))); + return @as(c_int, @intCast((@intFromPtr(gu_list.?.current) - @intFromPtr(gu_list.?.start)))); } pub fn sceGuClearColor(col: c_uint) void { @setRuntimeSafety(false); - gu_contexts[@intCast(usize, gu_curr_context)].clear_color = col; + gu_contexts[@as(usize, @intCast(gu_curr_context))].clear_color = col; } pub fn sceGuClearDepth(depth: c_uint) void { @setRuntimeSafety(false); - gu_contexts[@intCast(usize, gu_curr_context)].clear_depth = depth; + gu_contexts[@as(usize, @intCast(gu_curr_context))].clear_depth = depth; } pub fn sceGuClearStencil(stencil: c_uint) void { @setRuntimeSafety(false); - gu_contexts[@intCast(usize, gu_curr_context)].clear_stencil = stencil; + gu_contexts[@as(usize, @intCast(gu_curr_context))].clear_stencil = stencil; } -pub fn sceGuClutLoad(num_blocks: c_int, cbp: ?*const c_void) void { +pub fn sceGuClutLoad(num_blocks: c_int, cbp: ?*const anyopaque) void { @setRuntimeSafety(false); - var a = @intCast(c_int, @ptrToInt(cbp)); + const a = @as(c_int, @intCast(@intFromPtr(cbp))); sendCommandi(176, (a) & 0xffffff); sendCommandi(177, ((a) >> 8) & 0xf0000); sendCommandi(196, num_blocks); } -pub fn sceGuClutMode(cpsm: GuPixelMode, shift: c_int, mask: c_int, a3: c_int) void { +pub fn sceGuClutMode(cpsm: pspgutypes.GuPixelMode, shift: c_int, mask: c_int, a3: c_int) void { @setRuntimeSafety(false); - var argument: c_int = @enumToInt(cpsm) | (shift << 2) | (mask << 8) | (a3 << 16); + const argument: c_int = @intFromEnum(cpsm) | (shift << 2) | (mask << 8) | (a3 << 16); sendCommandi(197, argument); } @@ -371,9 +372,9 @@ pub fn sceGuMaterial(mode: c_int, col: c_int) void { sendCommandi(87, col & 0xffffff); } -pub fn sceGuColorFunc(func: ColorFunc, color: c_int, mask: c_int) void { +pub fn sceGuColorFunc(func: pspgutypes.ColorFunc, color: c_int, mask: c_int) void { @setRuntimeSafety(false); - sendCommandi(216, @enumToInt(func) & 0x03); + sendCommandi(216, @intFromEnum(func) & 0x03); sendCommandi(217, color & 0xffffff); sendCommandi(218, mask); } @@ -383,38 +384,38 @@ pub fn sceGuColorMaterial(components: c_int) void { sendCommandi(83, components); } -pub fn sceGuCopyImage(psm: GuPixelMode, sx: c_int, sy: c_int, width: c_int, height: c_int, srcw: c_int, src: ?*c_void, dx: c_int, dy: c_int, destw: c_int, dest: ?*c_void) void { +pub fn sceGuCopyImage(psm: pspgutypes.GuPixelMode, sx: c_int, sy: c_int, width: c_int, height: c_int, srcw: c_int, src: ?*anyopaque, dx: c_int, dy: c_int, destw: c_int, dest: ?*anyopaque) void { @setRuntimeSafety(false); - var sr = @intCast(c_uint, @ptrToInt(src)); - var ds = @intCast(c_uint, @ptrToInt(dest)); - sendCommandi(178, @intCast(c_int, (sr) & 0xffffff)); - sendCommandi(179, @intCast(c_int, (((sr) & 0xff000000) >> 8)) | srcw); + const sr = @as(c_uint, @intCast(@intFromPtr(src))); + const ds = @as(c_uint, @intCast(@intFromPtr(dest))); + sendCommandi(178, @as(c_int, @intCast((sr) & 0xffffff))); + sendCommandi(179, @as(c_int, @intCast((((sr) & 0xff000000) >> 8))) | srcw); sendCommandi(235, (sy << 10) | sx); - sendCommandi(180, @intCast(c_int, (ds) & 0xffffff)); - sendCommandi(181, @intCast(c_int, (((ds) & 0xff000000) >> 8)) | destw); + sendCommandi(180, @as(c_int, @intCast((ds) & 0xffffff))); + sendCommandi(181, @as(c_int, @intCast((((ds) & 0xff000000) >> 8))) | destw); sendCommandi(236, (dy << 10) | dx); sendCommandi(238, ((height - 1) << 10) | (width - 1)); - if (@enumToInt(psm) ^ 0x03 != 0) { + if (@intFromEnum(psm) ^ 0x03 != 0) { sendCommandi(234, 0); } else { sendCommandi(234, 1); } } -pub fn sceGuDepthBuffer(zbp: ?*c_void, zbw: c_int) void { +pub fn sceGuDepthBuffer(zbp: ?*anyopaque, zbw: c_int) void { @setRuntimeSafety(false); gu_draw_buffer.depth_buffer = zbp; if (gu_draw_buffer.depth_width != 0 or (gu_draw_buffer.depth_width != zbw)) gu_draw_buffer.depth_width = zbw; - sendCommandi(158, @intCast(c_int, (@ptrToInt(zbp))) & 0xffffff); - sendCommandi(159, @intCast(c_int, ((@intCast(c_uint, (@ptrToInt(zbp))) & 0xff000000) >> 8)) | zbw); + sendCommandi(158, @as(c_int, @intCast((@intFromPtr(zbp)))) & 0xffffff); + sendCommandi(159, @as(c_int, @intCast(((@as(c_uint, @intCast((@intFromPtr(zbp)))) & 0xff000000) >> 8))) | zbw); } -pub fn sceGuDepthFunc(function: DepthFunc) void { +pub fn sceGuDepthFunc(function: pspgutypes.DepthFunc) void { @setRuntimeSafety(false); - sendCommandi(222, @enumToInt(function)); + sendCommandi(222, @intFromEnum(function)); } pub fn sceGuDepthMask(mask: c_int) void { @@ -424,21 +425,21 @@ pub fn sceGuDepthMask(mask: c_int) void { pub fn sceGuDepthOffset(offset: c_uint) void { @setRuntimeSafety(false); - gu_contexts[@intCast(usize, gu_curr_context)].depth_offset = @intCast(i32, offset); - sceGuDepthRange(gu_contexts[@intCast(usize, gu_curr_context)].near_plane, gu_contexts[@intCast(usize, gu_curr_context)].far_plane); + gu_contexts[@as(usize, @intCast(gu_curr_context))].depth_offset = @as(i32, @intCast(offset)); + sceGuDepthRange(gu_contexts[@as(usize, @intCast(gu_curr_context))].near_plane, gu_contexts[@as(usize, @intCast(gu_curr_context))].far_plane); } pub fn sceGuDepthRange(near: c_int, far: c_int) void { @setRuntimeSafety(false); - var max = near + far; - var val = ((max >> 31) + max); - var z: f32 = @bitCast(f32, (val >> 1)); + const max = near + far; + const val = ((max >> 31) + max); + const z: f32 = @as(f32, @bitCast((val >> 1))); - gu_contexts[@intCast(usize, gu_curr_context)].near_plane = near; - gu_contexts[@intCast(usize, gu_curr_context)].far_plane = far; + gu_contexts[@as(usize, @intCast(gu_curr_context))].near_plane = near; + gu_contexts[@as(usize, @intCast(gu_curr_context))].far_plane = far; - sendCommandf(68, z - (@bitCast(f32, near))); - sendCommandf(71, z + (@bitCast(f32, gu_contexts[@intCast(usize, gu_curr_context)].depth_offset))); + sendCommandf(68, z - (@as(f32, @bitCast(near)))); + sendCommandf(71, z + (@as(f32, @bitCast(gu_contexts[@as(usize, @intCast(gu_curr_context))].depth_offset)))); if (near > far) { sendCommandi(214, far); @@ -449,7 +450,7 @@ pub fn sceGuDepthRange(near: c_int, far: c_int) void { } } -pub fn sceGuDisable(state: GuState) void { +pub fn sceGuDisable(state: pspgutypes.GuState) void { @setRuntimeSafety(false); switch (state) { .AlphaTest => { @@ -459,7 +460,7 @@ pub fn sceGuDisable(state: GuState) void { sendCommandi(35, 0); }, .ScissorTest => { - gu_contexts[@intCast(usize, gu_curr_context)].scissor_enable = 0; + gu_contexts[@as(usize, @intCast(gu_curr_context))].scissor_enable = 0; sendCommandi(212, 0); sendCommandi(213, ((gu_draw_buffer.height - 1) << 10) | (gu_draw_buffer.width - 1)); }, @@ -518,15 +519,15 @@ pub fn sceGuDisable(state: GuState) void { sendCommandi(56, 0); }, .Fragment2X => { - gu_contexts[@intCast(usize, gu_curr_context)].fragment_2x = 0; - sendCommandi(201, gu_contexts[@intCast(usize, gu_curr_context)].texture_function); + gu_contexts[@as(usize, @intCast(gu_curr_context))].fragment_2x = 0; + sendCommandi(201, gu_contexts[@as(usize, @intCast(gu_curr_context))].texture_function); }, } - var one: u32 = 1; + const one: u32 = 1; - if (@enumToInt(state) < 22) - gu_states &= @intCast(i32, ~(one << @intCast(u5, @enumToInt(state)))); + if (@intFromEnum(state) < 22) + gu_states &= @as(i32, @intCast(~(one << @as(u5, @intCast(@intFromEnum(state)))))); } fn drawRegion(x: c_int, y: c_int, width: c_int, height: c_int) void { @@ -534,7 +535,7 @@ fn drawRegion(x: c_int, y: c_int, width: c_int, height: c_int) void { sendCommandi(22, (((y + height) - 1) << 10) | ((x + width) - 1)); } -pub fn sceGuDispBuffer(width: c_int, height: c_int, dispbp: ?*c_void, dispbw: c_int) void { +pub fn sceGuDispBuffer(width: c_int, height: c_int, dispbp: ?*anyopaque, dispbw: c_int) void { @setRuntimeSafety(false); gu_draw_buffer.width = width; gu_draw_buffer.height = height; @@ -544,128 +545,128 @@ pub fn sceGuDispBuffer(width: c_int, height: c_int, dispbp: ?*c_void, dispbw: c_ gu_draw_buffer.frame_width = dispbw; drawRegion(0, 0, gu_draw_buffer.width, gu_draw_buffer.height); - _ = sceDisplaySetMode(0, gu_draw_buffer.width, gu_draw_buffer.height); + _ = display.sceDisplaySetMode(0, gu_draw_buffer.width, gu_draw_buffer.height); if (gu_display_on != 0) - _ = sceDisplaySetFrameBuf(@intToPtr(*c_void, @ptrToInt(ge_edram_address) + @ptrToInt(gu_draw_buffer.disp_buffer)), dispbw, gu_draw_buffer.pixel_size, @enumToInt(PspDisplaySetBufSync.Nextframe)); + _ = display.sceDisplaySetFrameBuf(@as(*anyopaque, @ptrFromInt(@intFromPtr(ge_edram_address) + @intFromPtr(gu_draw_buffer.disp_buffer))), dispbw, gu_draw_buffer.pixel_size, @intFromEnum(display.PspDisplaySetBufSync.Nextframe)); } pub fn sceGuDisplay(state: bool) void { if (state) { - _ = sceDisplaySetFrameBuf(@intToPtr(*c_void, @ptrToInt(ge_edram_address) + @ptrToInt(gu_draw_buffer.disp_buffer)), gu_draw_buffer.frame_width, gu_draw_buffer.pixel_size, @enumToInt(PspDisplaySetBufSync.Nextframe)); + _ = 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, @intFromEnum(display.PspDisplaySetBufSync.Nextframe)); } else { - _ = sceDisplaySetFrameBuf(null, 0, 0, @enumToInt(PspDisplaySetBufSync.Nextframe)); + _ = display.sceDisplaySetFrameBuf(null, 0, 0, @intFromEnum(display.PspDisplaySetBufSync.Nextframe)); } - gu_display_on = @boolToInt(state); + gu_display_on = @intFromBool(state); } -pub fn sceGuDrawArray(prim: GuPrimitive, vtype: c_int, count: c_int, indices: ?*const c_void, vertices: ?*const c_void) void { +pub fn sceGuDrawArray(prim: pspgutypes.GuPrimitive, vtype: c_int, count: c_int, indices: ?*const anyopaque, vertices: ?*const anyopaque) void { @setRuntimeSafety(false); if (vtype != 0) sendCommandi(18, vtype); if (indices != null) { - sendCommandi(16, @intCast(c_int, (@ptrToInt(indices) >> 8)) & 0xf0000); - sendCommandi(2, @intCast(c_int, @ptrToInt(indices)) & 0xffffff); + sendCommandi(16, @as(c_int, @intCast((@intFromPtr(indices) >> 8))) & 0xf0000); + sendCommandi(2, @as(c_int, @intCast(@intFromPtr(indices))) & 0xffffff); } if (vertices != null) { - sendCommandi(16, @intCast(c_int, (@ptrToInt(vertices) >> 8)) & 0xf0000); - sendCommandi(1, @intCast(c_int, @ptrToInt(vertices)) & 0xffffff); + sendCommandi(16, @as(c_int, @intCast((@intFromPtr(vertices) >> 8))) & 0xf0000); + sendCommandi(1, @as(c_int, @intCast(@intFromPtr(vertices))) & 0xffffff); } - sendCommandiStall(4, (@enumToInt(prim) << 16) | count); + sendCommandiStall(4, (@intFromEnum(prim) << 16) | count); } -pub fn sceGuDrawArrayN(primitive_type: GuPrimitive, vertex_type: c_int, count: c_int, a3: c_int, indices: ?*const c_void, vertices: ?*const c_void) void { +pub fn sceGuDrawArrayN(primitive_type: pspgutypes.GuPrimitive, vertex_type: c_int, count: c_int, a3: c_int, indices: ?*const anyopaque, vertices: ?*const anyopaque) void { @setRuntimeSafety(false); if (vertex_type != 0) sendCommandi(18, vertex_type); if (indices != null) { - sendCommandi(16, @intCast(c_int, (@ptrToInt(indices) >> 8)) & 0xf0000); - sendCommandi(2, @intCast(c_int, @ptrToInt(indices)) & 0xffffff); + sendCommandi(16, @as(c_int, @intCast((@intFromPtr(indices) >> 8))) & 0xf0000); + sendCommandi(2, @as(c_int, @intCast(@intFromPtr(indices))) & 0xffffff); } if (vertices != null) { - sendCommandi(16, @intCast(c_int, (@ptrToInt(vertices) >> 8)) & 0xf0000); - sendCommandi(1, @intCast(c_int, @ptrToInt(vertices)) & 0xffffff); + sendCommandi(16, @as(c_int, @intCast((@intFromPtr(vertices) >> 8))) & 0xf0000); + sendCommandi(1, @as(c_int, @intCast(@intFromPtr(vertices))) & 0xffffff); } if (a3 > 0) { - var i: usize = @intCast(usize, a3) - 1; + var i: usize = @as(usize, @intCast(a3)) - 1; while (i >= 0) : (i -= 1) { - sendCommandi(4, (@enumToInt(primitive_type) << 16) | count); + sendCommandi(4, (@intFromEnum(primitive_type) << 16) | count); } - sendCommandiStall(4, (@enumToInt(primitive_type) << 16) | count); + sendCommandiStall(4, (@intFromEnum(primitive_type) << 16) | count); } } -pub fn sceGuDrawBezier(vtype: c_int, ucount: c_int, vcount: c_int, indices: ?*const c_void, vertices: ?*const c_void) void { +pub fn sceGuDrawBezier(vtype: c_int, ucount: c_int, vcount: c_int, indices: ?*const anyopaque, vertices: ?*const anyopaque) void { @setRuntimeSafety(false); if (vtype != 0) sendCommandi(18, vtype); if (indices != null) { - sendCommandi(16, @intCast(c_int, (@ptrToInt(indices) >> 8)) & 0xf0000); - sendCommandi(2, @intCast(c_int, @ptrToInt(indices)) & 0xffffff); + sendCommandi(16, @as(c_int, @intCast((@intFromPtr(indices) >> 8))) & 0xf0000); + sendCommandi(2, @as(c_int, @intCast(@intFromPtr(indices))) & 0xffffff); } if (vertices != null) { - sendCommandi(16, @intCast(c_int, (@ptrToInt(vertices) >> 8)) & 0xf0000); - sendCommandi(1, @intCast(c_int, @ptrToInt(vertices)) & 0xffffff); + sendCommandi(16, @as(c_int, @intCast((@intFromPtr(vertices) >> 8))) & 0xf0000); + sendCommandi(1, @as(c_int, @intCast(@intFromPtr(vertices))) & 0xffffff); } sendCommandi(5, (vcount << 8) | ucount); } -pub fn sceGuDrawBuffer(pix: GuPixelMode, fbp: ?*c_void, fbw: c_int) void { +pub fn sceGuDrawBuffer(pix: pspgutypes.GuPixelMode, fbp: ?*anyopaque, fbw: c_int) void { @setRuntimeSafety(false); - var psm = @enumToInt(pix); + const psm = @intFromEnum(pix); gu_draw_buffer.pixel_size = psm; gu_draw_buffer.frame_width = fbw; gu_draw_buffer.frame_buffer = fbp; if (gu_draw_buffer.depth_buffer != null and gu_draw_buffer.height != 0) - gu_draw_buffer.depth_buffer = @intToPtr(*c_void, (@ptrToInt(fbp) + @intCast(usize, ((gu_draw_buffer.height * fbw) << 2)))); + gu_draw_buffer.depth_buffer = @as(*anyopaque, @ptrFromInt((@intFromPtr(fbp) + @as(usize, @intCast(((gu_draw_buffer.height * fbw) << 2)))))); if (gu_draw_buffer.depth_width != 0) gu_draw_buffer.depth_width = fbw; sendCommandi(210, psm); - sendCommandi(156, @intCast(c_int, @intCast(c_uint, @ptrToInt(gu_draw_buffer.frame_buffer)) & 0xffffff)); - sendCommandi(157, @intCast(c_int, ((@intCast(c_uint, @ptrToInt(gu_draw_buffer.frame_buffer)) & 0xff000000) >> 8)) | gu_draw_buffer.frame_width); - sendCommandi(158, @intCast(c_int, @intCast(c_uint, @ptrToInt(gu_draw_buffer.depth_buffer)) & 0xffffff)); - sendCommandi(159, @intCast(c_int, ((@intCast(c_uint, @ptrToInt(gu_draw_buffer.depth_buffer)) & 0xff000000) >> 8)) | gu_draw_buffer.depth_width); + sendCommandi(156, @as(c_int, @intCast(@as(c_uint, @intCast(@intFromPtr(gu_draw_buffer.frame_buffer))) & 0xffffff))); + sendCommandi(157, @as(c_int, @intCast(((@as(c_uint, @intCast(@intFromPtr(gu_draw_buffer.frame_buffer))) & 0xff000000) >> 8))) | gu_draw_buffer.frame_width); + sendCommandi(158, @as(c_int, @intCast(@as(c_uint, @intCast(@intFromPtr(gu_draw_buffer.depth_buffer))) & 0xffffff))); + sendCommandi(159, @as(c_int, @intCast(((@as(c_uint, @intCast(@intFromPtr(gu_draw_buffer.depth_buffer))) & 0xff000000) >> 8))) | gu_draw_buffer.depth_width); } -pub fn sceGuDrawBufferList(psm: GuPixelMode, fbp: ?*c_void, fbw: c_int) void { +pub fn sceGuDrawBufferList(psm: pspgutypes.GuPixelMode, fbp: ?*anyopaque, fbw: c_int) void { @setRuntimeSafety(false); - sendCommandi(210, @enumToInt(psm)); - sendCommandi(156, @intCast(c_int, @ptrToInt(fbp)) & 0xffffff); - sendCommandi(157, @intCast(c_int, (@intCast(c_uint, @ptrToInt(fbp)) & 0xff000000) >> 8) | fbw); + sendCommandi(210, @intFromEnum(psm)); + sendCommandi(156, @as(c_int, @intCast(@intFromPtr(fbp))) & 0xffffff); + sendCommandi(157, @as(c_int, @intCast((@as(c_uint, @intCast(@intFromPtr(fbp))) & 0xff000000) >> 8)) | fbw); } -pub fn sceGuDrawSpline(vtype: c_int, ucount: c_int, vcount: c_int, uedge: c_int, vedge: c_int, indices: ?*const c_void, vertices: ?*const c_void) void { +pub fn sceGuDrawSpline(vtype: c_int, ucount: c_int, vcount: c_int, uedge: c_int, vedge: c_int, indices: ?*const anyopaque, vertices: ?*const anyopaque) void { @setRuntimeSafety(false); if (vtype != 0) sendCommandi(18, vtype); if (indices != null) { - sendCommandi(16, @intCast(c_int, (@ptrToInt(indices) >> 8)) & 0xf0000); - sendCommandi(2, @intCast(c_int, @ptrToInt(indices)) & 0xffffff); + sendCommandi(16, @as(c_int, @intCast((@intFromPtr(indices) >> 8))) & 0xf0000); + sendCommandi(2, @as(c_int, @intCast(@intFromPtr(indices))) & 0xffffff); } if (vertices != null) { - sendCommandi(16, @intCast(c_int, (@ptrToInt(vertices) >> 8)) & 0xf0000); - sendCommandi(1, @intCast(c_int, @ptrToInt(vertices)) & 0xffffff); + sendCommandi(16, @as(c_int, @intCast((@intFromPtr(vertices) >> 8))) & 0xf0000); + sendCommandi(1, @as(c_int, @intCast(@intFromPtr(vertices))) & 0xffffff); } sendCommandi(6, (vedge << 18) | (uedge << 16) | (vcount << 8) | ucount); } -pub fn sceGuEnable(state: GuState) void { +pub fn sceGuEnable(state: pspgutypes.GuState) void { @setRuntimeSafety(false); switch (state) { .AlphaTest => { @@ -675,9 +676,9 @@ pub fn sceGuEnable(state: GuState) void { sendCommandi(35, 1); }, .ScissorTest => { - gu_contexts[@intCast(usize, gu_curr_context)].scissor_enable = 1; - sendCommandi(212, (gu_contexts[@intCast(usize, gu_curr_context)].scissor_start[1] << 10) | gu_contexts[@intCast(usize, gu_curr_context)].scissor_start[0]); - sendCommandi(213, (gu_contexts[@intCast(usize, gu_curr_context)].scissor_end[1] << 10) | gu_contexts[@intCast(usize, gu_curr_context)].scissor_end[0]); + gu_contexts[@as(usize, @intCast(gu_curr_context))].scissor_enable = 1; + sendCommandi(212, (gu_contexts[@as(usize, @intCast(gu_curr_context))].scissor_start[1] << 10) | gu_contexts[@as(usize, @intCast(gu_curr_context))].scissor_start[0]); + sendCommandi(213, (gu_contexts[@as(usize, @intCast(gu_curr_context))].scissor_end[1] << 10) | gu_contexts[@as(usize, @intCast(gu_curr_context))].scissor_end[0]); }, .StencilTest => { sendCommandi(36, 1); @@ -734,46 +735,46 @@ pub fn sceGuEnable(state: GuState) void { sendCommandi(56, 1); }, .Fragment2X => { - gu_contexts[@intCast(usize, gu_curr_context)].fragment_2x = 0x10000; - sendCommandi(201, 0x10000 | gu_contexts[@intCast(usize, gu_curr_context)].texture_function); + gu_contexts[@as(usize, @intCast(gu_curr_context))].fragment_2x = 0x10000; + sendCommandi(201, 0x10000 | gu_contexts[@as(usize, @intCast(gu_curr_context))].texture_function); }, } - var one: u32 = 1; - if (@enumToInt(state) < 22) - gu_states |= @intCast(i32, (one << @intCast(u5, @enumToInt(state)))); + const one: u32 = 1; + if (@intFromEnum(state) < 22) + gu_states |= @as(i32, @intCast((one << @as(u5, @intCast(@intFromEnum(state)))))); } pub fn sceGuEndObject() void { @setRuntimeSafety(false); - var current: [*]u32 = gu_list.?.current; - gu_list.?.current = @ptrCast([*]u32, &gu_object_stack[@intCast(usize, gu_object_stack_depth) - 1]); + const current: [*]u32 = gu_list.?.current; + gu_list.?.current = @as([*]u32, @ptrCast(&gu_object_stack[@as(usize, @intCast(gu_object_stack_depth)) - 1])); - sendCommandi(16, @intCast(c_int, (@ptrToInt(current) >> 8)) & 0xf0000); - sendCommandi(9, @intCast(c_int, @ptrToInt(current)) & 0xffffff); + sendCommandi(16, @as(c_int, @intCast((@intFromPtr(current) >> 8))) & 0xf0000); + sendCommandi(9, @as(c_int, @intCast(@intFromPtr(current))) & 0xffffff); gu_list.?.current = current; gu_object_stack_depth -= 1; } -pub fn sceGuBeginObject(vtype: c_int, count: c_int, indices: ?*const c_void, vertices: ?*const c_void) void { +pub fn sceGuBeginObject(vtype: c_int, count: c_int, indices: ?*const anyopaque, vertices: ?*const anyopaque) void { @setRuntimeSafety(false); if (vtype != 0) sendCommandi(18, vtype); if (indices != null) { - sendCommandi(16, @intCast(c_int, (@ptrToInt(indices) >> 8)) & 0xf0000); - sendCommandi(2, @intCast(c_int, @ptrToInt(indices)) & 0xffffff); + sendCommandi(16, @as(c_int, @intCast((@intFromPtr(indices) >> 8))) & 0xf0000); + sendCommandi(2, @as(c_int, @intCast(@intFromPtr(indices))) & 0xffffff); } if (vertices != null) { - sendCommandi(16, @intCast(c_int, (@ptrToInt(vertices) >> 8)) & 0xf0000); - sendCommandi(1, @intCast(c_int, @ptrToInt(vertices)) & 0xffffff); + sendCommandi(16, @as(c_int, @intCast((@intFromPtr(vertices) >> 8))) & 0xf0000); + sendCommandi(1, @as(c_int, @intCast(@intFromPtr(vertices))) & 0xffffff); } sendCommandi(7, count); - gu_object_stack[@intCast(usize, gu_object_stack_depth)] = @intCast(u32, @ptrToInt(gu_list.?.current)); + gu_object_stack[@as(usize, @intCast(gu_object_stack_depth))] = @as(u32, @intCast(@intFromPtr(gu_list.?.current))); gu_object_stack_depth += 1; sendCommandi(16, 0); @@ -781,7 +782,7 @@ pub fn sceGuBeginObject(vtype: c_int, count: c_int, indices: ?*const c_void, ver } pub fn sceGuFinish() c_int { - switch (@intToEnum(GuContextType, gu_curr_context)) { + switch (@as(pspgutypes.GuContextType, @enumFromInt(gu_curr_context))) { .Direct, .Send => { sendCommandi(15, 0); sendCommandiStall(12, 0); @@ -798,12 +799,12 @@ pub fn sceGuFinish() c_int { }, } - var size: u32 = @ptrToInt(gu_list.?.current) - @ptrToInt(gu_list.?.start); + const size: u32 = @intFromPtr(gu_list.?.current) - @intFromPtr(gu_list.?.start); // go to parent list gu_curr_context = gu_list.?.parent_context; - gu_list = &gu_contexts[@intCast(usize, gu_curr_context)].list; - return @intCast(c_int, size); + gu_list = &gu_contexts[@as(usize, @intCast(gu_curr_context))].list; + return @as(c_int, @intCast(size)); } pub fn guFinish() void { @@ -811,7 +812,7 @@ pub fn guFinish() void { } pub fn sceGuFinishId(id: c_int) c_int { - switch (@intToEnum(GuContextType, gu_curr_context)) { + switch (@as(pspgutypes.GuContextType, @enumFromInt(gu_curr_context))) { .Direct, .Send => { sendCommandi(15, id & 0xffff); sendCommandiStall(12, 0); @@ -828,12 +829,12 @@ pub fn sceGuFinishId(id: c_int) c_int { }, } - var size: u32 = @ptrToInt(gu_list.?.current) - @ptrToInt(gu_list.?.start); + const size: u32 = @intFromPtr(gu_list.?.current) - @intFromPtr(gu_list.?.start); // go to parent list gu_curr_context = gu_list.?.parent_context; - gu_list = &gu_contexts[@intCast(usize, gu_curr_context)].list; - return @intCast(c_int, size); + gu_list = &gu_contexts[@as(usize, @intCast(gu_curr_context))].list; + return @as(c_int, @intCast(size)); } pub fn sceGuFog(near: f32, far: f32, col: c_uint) void { @@ -842,14 +843,14 @@ pub fn sceGuFog(near: f32, far: f32, col: c_uint) void { if (distance > 0) distance = 1.0 / distance; - sendCommandi(207, @intCast(c_int, col & 0xffffff)); + sendCommandi(207, @as(c_int, @intCast(col & 0xffffff))); sendCommandf(205, far); sendCommandf(206, distance); } -pub fn sceGuFrontFace(order: FrontFaceDirection) void { +pub fn sceGuFrontFace(order: pspgutypes.FrontFaceDirection) void { @setRuntimeSafety(false); - if (order != FrontFaceDirection.Clockwise) { + if (order != pspgutypes.FrontFaceDirection.Clockwise) { sendCommandi(155, 0); } else { sendCommandi(155, 1); @@ -860,13 +861,13 @@ pub fn sceGuGetAllStatus() c_int { return gu_states; } -pub fn sceGuGetStatus(state: GuState) c_int { +pub fn sceGuGetStatus(state: pspgutypes.GuState) c_int { if (state < 22) - return (@enumToInt(gu_states) >> @intCast(u5, state)) & 1; + return (@intFromEnum(gu_states) >> @as(u5, @intCast(state))) & 1; return 0; } -pub fn sceGuLight(light: c_int, typec: GuLightType, components: GuLightBitFlags, position: [*c]const ScePspFVector3) void { +pub fn sceGuLight(light: c_int, typec: pspgutypes.GuLightType, components: pspgutypes.GuLightBitFlags, position: [*c]const pspgutypes.ScePspFVector3) void { @setRuntimeSafety(false); sendCommandf(light_settings[light].xpos, position.*.x); @@ -874,8 +875,8 @@ pub fn sceGuLight(light: c_int, typec: GuLightType, components: GuLightBitFlags, sendCommandf(light_settings[light].zpos, position.*.z); var kind: c_int = 2; - if (@enumToInt(components) != 8) { - if ((@enumToInt(components) ^ 6) < 1) { + if (@intFromEnum(components) != 8) { + if ((@intFromEnum(components) ^ 6) < 1) { kind = 1; } else { kind = 0; @@ -892,9 +893,9 @@ pub fn sceGuLightAtt(light: usize, atten0: f32, atten1: f32, atten2: f32) void { sendCommandf(light_settings[light].quadratic, atten2); } -pub fn sceGuLightColor(light: usize, component: GuLightBitFlags, col: c_int) void { +pub fn sceGuLightColor(light: usize, component: pspgutypes.GuLightBitFlags, col: c_int) void { @setRuntimeSafety(false); - switch (@intToEnum(GuLightBitFlags, component)) { + switch (@as(pspgutypes.GuLightBitFlags, @enumFromInt(component))) { .Ambient => { sendCommandi(light_settings[light].ambient, col & 0xffffff); }, @@ -921,7 +922,7 @@ pub fn sceGuLightMode(mode: c_int) void { sendCommandi(94, mode); } -pub fn sceGuLightSpot(light: usize, direction: [*c]const ScePspFVector3, exponent: f32, cutoff: f32) void { +pub fn sceGuLightSpot(light: usize, direction: [*c]const pspgutypes.ScePspFVector3, exponent: f32, cutoff: f32) void { @setRuntimeSafety(false); sendCommandf(light_settings[light].exponent, exponent); sendCommandf(light_settings[light].cutoff, cutoff); @@ -930,9 +931,9 @@ pub fn sceGuLightSpot(light: usize, direction: [*c]const ScePspFVector3, exponen sendCommandf(light_settings[light].zdir, direction.*.z); } -pub fn sceGuLogicalOp(op: GuLogicalOperation) void { +pub fn sceGuLogicalOp(op: pspgutypes.GuLogicalOperation) void { @setRuntimeSafety(false); - sendCommandi(230, @enumToInt(op) & 0x0f); + sendCommandi(230, @intFromEnum(op) & 0x0f); } pub fn sceGuModelColor(emissive: c_int, ambient: c_int, diffuse: c_int, specular: c_int) void { @@ -964,7 +965,7 @@ pub fn sceGuPatchFrontFace(a0: c_int) void { sendCommandi(56, a0); } -pub fn sceGuPatchPrim(prim: GuPrimitive) void { +pub fn sceGuPatchPrim(prim: pspgutypes.GuPrimitive) void { @setRuntimeSafety(false); switch (prim) { .Points => { @@ -988,14 +989,14 @@ pub fn sceGuPixelMask(mask: c_int) void { pub fn sceGuScissor(x: c_int, y: c_int, w: c_int, h: c_int) void { @setRuntimeSafety(false); - gu_contexts[@intCast(usize, gu_curr_context)].scissor_start[0] = x; - gu_contexts[@intCast(usize, gu_curr_context)].scissor_start[1] = y; - gu_contexts[@intCast(usize, gu_curr_context)].scissor_end[0] = w - 1; - gu_contexts[@intCast(usize, gu_curr_context)].scissor_end[1] = h - 1; + gu_contexts[@as(usize, @intCast(gu_curr_context))].scissor_start[0] = x; + gu_contexts[@as(usize, @intCast(gu_curr_context))].scissor_start[1] = y; + gu_contexts[@as(usize, @intCast(gu_curr_context))].scissor_end[0] = w - 1; + gu_contexts[@as(usize, @intCast(gu_curr_context))].scissor_end[1] = h - 1; - if (gu_contexts[@intCast(usize, gu_curr_context)].scissor_enable != 0) { - sendCommandi(212, (gu_contexts[@intCast(usize, gu_curr_context)].scissor_start[1] << 10) | gu_contexts[@intCast(usize, gu_curr_context)].scissor_start[0]); - sendCommandi(213, (gu_contexts[@intCast(usize, gu_curr_context)].scissor_end[1] << 10) | gu_contexts[@intCast(usize, gu_curr_context)].scissor_end[0]); + if (gu_contexts[@as(usize, @intCast(gu_curr_context))].scissor_enable != 0) { + sendCommandi(212, (gu_contexts[@as(usize, @intCast(gu_curr_context))].scissor_start[1] << 10) | gu_contexts[@as(usize, @intCast(gu_curr_context))].scissor_start[0]); + sendCommandi(213, (gu_contexts[@as(usize, @intCast(gu_curr_context))].scissor_end[1] << 10) | gu_contexts[@as(usize, @intCast(gu_curr_context))].scissor_end[0]); } } @@ -1009,22 +1010,22 @@ pub fn sceGuSendCommandi(cmd: c_int, argument: c_int) void { sendCommandi(cmd, argument); } -pub fn sceGuSendList(mode: c_int, list: ?*const c_void, context: [*c]PspGeContext) void { +pub fn sceGuSendList(mode: c_int, list: ?*const anyopaque, context: [*c]pspgutypes.PspGeContext) void { @setRuntimeSafety(false); gu_settings.signal_offset = 0; - var args: PspGeListArgs = undefined; + var args: pspgutypes.PspGeListArgs = undefined; args.size = 8; args.context = context; var list_id: i32 = 0; - var callback = gu_settings.ge_callback_id; + const callback = gu_settings.ge_callback_id; - switch (@intToEnum(GuQueueMode, mode)) { + switch (@as(pspgutypes.GuQueueMode, @enumFromInt(mode))) { .Head => { - list_id = sceGeListEnQueueHead(list, null, callback, &args); + list_id = pspge.sceGeListEnQueueHead(list, null, callback, &args); }, .Tail => { - list_id = sceGeListEnQueue(list, null, callback, &args); + list_id = pspge.sceGeListEnQueue(list, null, callback, &args); }, } @@ -1035,7 +1036,7 @@ pub fn sceGuSetAllStatus(status: c_int) void { @setRuntimeSafety(false); var i: c_int = 0; while (i < 22) : (i += 1) { - if ((status >> @intCast(u5, i)) & 1 != 0) { + if ((status >> @as(u5, @intCast(i))) & 1 != 0) { sceGuEnable(i); } else { sceGuDisable(i); @@ -1043,10 +1044,10 @@ 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 (@intToEnum(GuCallbackId, signal)) { + switch (@as(pspgutypes.GuCallbackId, @enumFromInt(signal))) { .Signal => { old_callback = gu_settings.sig; gu_settings.sig = callback; @@ -1061,7 +1062,7 @@ pub fn sceGuSetCallback(signal: c_int, callback: ?fn (c_int) callconv(.C) void) return old_callback; } -pub fn sceGuSetDither(matrix: *const 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)); @@ -1069,10 +1070,10 @@ pub fn sceGuSetDither(matrix: *const 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]ScePspFMatrix4) void { +pub fn sceGuSetMatrix(typec: c_int, matrix: [*c]psptypes.ScePspFMatrix4) void { @setRuntimeSafety(false); - const fmatrix: [*]f32 = @ptrCast([*]f32, matrix); + const fmatrix: [*]f32 = @as([*]f32, @ptrCast(matrix)); switch (typec) { 0 => { @@ -1126,27 +1127,27 @@ pub fn sceGuSetMatrix(typec: c_int, matrix: [*c]ScePspFMatrix4) void { } } -pub fn sceGuSetStatus(state: GuState, status: bool) void { +pub fn sceGuSetStatus(state: pspgutypes.GuState, status: bool) void { @setRuntimeSafety(false); if (status) { - sceGuEnable(@enumToInt(state)); + sceGuEnable(@intFromEnum(state)); } else { - sceGuDisable(@enumToInt(state)); + sceGuDisable(@intFromEnum(state)); } } -pub fn sceGuShadeModel(mode: ShadeModel) void { +pub fn sceGuShadeModel(mode: pspgutypes.ShadeModel) void { @setRuntimeSafety(false); - if (mode == ShadeModel.Smooth) { + if (mode == pspgutypes.ShadeModel.Smooth) { sendCommandi(80, 1); } else { sendCommandi(80, 0); } } -pub fn sceGuSignal(signal: c_int, behavior: GuSignalBehavior) void { +pub fn sceGuSignal(signal: c_int, behavior: pspgutypes.GuSignalBehavior) void { @setRuntimeSafety(false); - sendCommandi(14, ((signal & 0xff) << 16) | (@enumToInt(behavior) & 0xffff)); + sendCommandi(14, ((signal & 0xff) << 16) | (@intFromEnum(behavior) & 0xffff)); sendCommandi(12, 0); if (signal == 3) { @@ -1162,28 +1163,28 @@ pub fn sceGuSpecular(power: f32) void { sendCommandf(91, power); } -pub fn sceGuStencilFunc(func: StencilFunc, ref: c_int, mask: c_int) void { +pub fn sceGuStencilFunc(func: pspgutypes.StencilFunc, ref: c_int, mask: c_int) void { @setRuntimeSafety(false); - sendCommandi(220, @enumToInt(func) | ((ref & 0xff) << 8) | ((mask & 0xff) << 16)); + sendCommandi(220, @intFromEnum(func) | ((ref & 0xff) << 8) | ((mask & 0xff) << 16)); } -pub fn sceGuStencilOp(fail: StencilOperation, zfail: StencilOperation, zpass: StencilOperation) void { +pub fn sceGuStencilOp(fail: pspgutypes.StencilOperation, zfail: pspgutypes.StencilOperation, zpass: pspgutypes.StencilOperation) void { @setRuntimeSafety(false); - sendCommandi(221, @enumToInt(fail) | (@enumToInt(zfail) << 8) | (@enumToInt(zpass) << 16)); + sendCommandi(221, @intFromEnum(fail) | (@intFromEnum(zfail) << 8) | (@intFromEnum(zpass) << 16)); } -pub fn sceGuSwapBuffers() ?*c_void { +pub fn sceGuSwapBuffers() ?*anyopaque { @setRuntimeSafety(false); if (gu_settings.swapBuffersCallback != null) { gu_settings.swapBuffersCallback.?(&gu_draw_buffer.disp_buffer, &gu_draw_buffer.frame_buffer); } else { - var temp = gu_draw_buffer.disp_buffer; + const temp = gu_draw_buffer.disp_buffer; gu_draw_buffer.disp_buffer = gu_draw_buffer.frame_buffer; gu_draw_buffer.frame_buffer = temp; } if (gu_display_on != 0) { - _ = sceDisplaySetFrameBuf(@intToPtr(*c_void, @ptrToInt(ge_edram_address) + @ptrToInt(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; @@ -1199,35 +1200,35 @@ pub fn guSwapBuffersBehaviour(behaviour: c_int) void { gu_settings.swapBuffersBehaviour = behaviour; } -pub fn guSwapBuffersCallback(callback: GuSwapBuffersCallback) void { +pub fn guSwapBuffersCallback(callback: pspgutypes.GuSwapBuffersCallback) void { @setRuntimeSafety(false); gu_settings.swapBuffersCallback = callback; } -pub fn sceGuSync(mode: GuSyncMode, what: GuSyncBehavior) c_int { +pub fn sceGuSync(mode: pspgutypes.GuSyncMode, what: pspgutypes.GuSyncBehavior) c_int { switch (mode) { .Finish => { - return sceGeDrawSync(@enumToInt(what)); + return pspge.sceGeDrawSync(@intFromEnum(what)); }, .List => { - return sceGeListSync(ge_list_executed[0], @enumToInt(what)); + return pspge.sceGeListSync(ge_list_executed[0], @intFromEnum(what)); }, .Send => { - return sceGeListSync(ge_list_executed[1], @enumToInt(what)); + return pspge.sceGeListSync(ge_list_executed[1], @intFromEnum(what)); }, else => { return 0; }, } } -pub fn guSync(mode: GuSyncMode, what: GuSyncBehavior) void { +pub fn guSync(mode: pspgutypes.GuSyncMode, what: pspgutypes.GuSyncBehavior) void { _ = sceGuSync(mode, what); } pub fn sceGuTerm() void { @setRuntimeSafety(false); - _ = sceKernelDeleteEventFlag(gu_settings.kernel_event_flag); - _ = sceGeUnsetCallback(gu_settings.ge_callback_id); + _ = pspge.sceKernelDeleteEventFlag(gu_settings.kernel_event_flag); + _ = pspge.sceGeUnsetCallback(gu_settings.ge_callback_id); } pub fn sceGuTexEnvColor(color: c_int) void { @@ -1235,9 +1236,9 @@ pub fn sceGuTexEnvColor(color: c_int) void { sendCommandi(202, color & 0xffffff); } -pub fn sceGuTexFilter(min: TextureFilter, mag: TextureFilter) void { +pub fn sceGuTexFilter(min: pspgutypes.TextureFilter, mag: pspgutypes.TextureFilter) void { @setRuntimeSafety(false); - sendCommandi(198, (@enumToInt(mag) << 8) | @enumToInt(min)); + sendCommandi(198, (@intFromEnum(mag) << 8) | @intFromEnum(min)); } pub fn sceGuTexFlush() void { @@ -1245,10 +1246,10 @@ pub fn sceGuTexFlush() void { sendCommandf(203, 0.0); } -pub fn sceGuTexFunc(tfx: TextureEffect, tcc: TextureColorComponent) void { +pub fn sceGuTexFunc(tfx: pspgutypes.TextureEffect, tcc: pspgutypes.TextureColorComponent) void { @setRuntimeSafety(false); - gu_contexts[@intCast(usize, gu_curr_context)].texture_function = (@enumToInt(tcc) << 8) | @enumToInt(tfx); - sendCommandi(201, ((@enumToInt(tcc) << 8) | @enumToInt(tfx)) | gu_contexts[@intCast(usize, gu_curr_context)].fragment_2x); + gu_contexts[@as(usize, @intCast(gu_curr_context))].texture_function = (@intFromEnum(tcc) << 8) | @intFromEnum(tfx); + sendCommandi(201, ((@intFromEnum(tcc) << 8) | @intFromEnum(tfx)) | gu_contexts[@as(usize, @intCast(gu_curr_context))].fragment_2x); } const tbpcmd_tbl = [_]u8{ 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7 }; @@ -1257,54 +1258,54 @@ const tsizecmd_tbl = [_]u8{ 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf }; fn getExp(val: c_int) c_int { @setRuntimeSafety(false); - var v: c_uint = @intCast(c_uint, val); + var v: c_uint = @as(c_uint, @intCast(val)); var r: c_uint = ((0xFFFF - v) >> 31) << 4; - v >>= @intCast(u5, r); + v >>= @as(u5, @intCast(r)); var shift: c_uint = ((0xFF - v) >> 31) << 3; - v >>= @intCast(u5, shift); + v >>= @as(u5, @intCast(shift)); r |= shift; shift = ((0xF - v) >> 31) << 2; - v >>= @intCast(u5, shift); + v >>= @as(u5, @intCast(shift)); r |= shift; shift = ((0x3 - v) >> 31) << 1; - return @intCast(c_int, r) | @intCast(c_int, shift) | @intCast(c_int, (v >> @intCast(u5, (shift + 1)))); + return @as(c_int, @intCast(r)) | @as(c_int, @intCast(shift)) | @as(c_int, @intCast((v >> @as(u5, @intCast((shift + 1)))))); } -pub fn sceGuTexImage(mipmap: c_int, width: c_int, height: c_int, tbw: c_int, tbp: ?*const c_void) void { +pub fn sceGuTexImage(mipmap: c_int, width: c_int, height: c_int, tbw: c_int, tbp: ?*const anyopaque) void { @setRuntimeSafety(false); - sendCommandi(tbpcmd_tbl[@intCast(usize, mipmap)], @intCast(c_int, @ptrToInt(tbp)) & 0xffffff); - sendCommandi(tbwcmd_tbl[@intCast(usize, mipmap)], @intCast(c_int, ((@ptrToInt(tbp) >> 8) & 0x0f0000)) | tbw); - sendCommandi(tsizecmd_tbl[@intCast(usize, mipmap)], getExp(height) << 8 | getExp(width)); + sendCommandi(tbpcmd_tbl[@as(usize, @intCast(mipmap))], @as(c_int, @intCast(@intFromPtr(tbp))) & 0xffffff); + sendCommandi(tbwcmd_tbl[@as(usize, @intCast(mipmap))], @as(c_int, @intCast(((@intFromPtr(tbp) >> 8) & 0x0f0000))) | tbw); + sendCommandi(tsizecmd_tbl[@as(usize, @intCast(mipmap))], getExp(height) << 8 | getExp(width)); sceGuTexFlush(); } -pub fn sceGuTexLevelMode(mode: TextureLevelMode, bias: f32) void { +pub fn sceGuTexLevelMode(mode: pspgutypes.TextureLevelMode, bias: f32) void { @setRuntimeSafety(false); - var offset: c_int = @floatToInt(c_int, bias * 16.0); + var offset: c_int = @as(c_int, @intFromFloat(bias * 16.0)); if (offset >= 128) { offset = 128; } else if (offset < -128) { offset = -128; } - sendCommandi(200, ((offset) << 16) | @enumToInt(mode)); + sendCommandi(200, ((offset) << 16) | @intFromEnum(mode)); } pub fn sceGuTexMapMode(mode: c_int, a1: c_int, a2: c_int) void { @setRuntimeSafety(false); - gu_contexts[@intCast(usize, gu_curr_context)].texture_map_mode = mode & 0x03; - sendCommandi(192, gu_contexts[@intCast(usize, gu_curr_context)].texture_proj_map_mode | (mode & 0x03)); + gu_contexts[@as(usize, @intCast(gu_curr_context))].texture_map_mode = mode & 0x03; + sendCommandi(192, gu_contexts[@as(usize, @intCast(gu_curr_context))].texture_proj_map_mode | (mode & 0x03)); sendCommandi(193, (a2 << 8) | (a1 & 0x03)); } -pub fn sceGuTexMode(tpsm: GuPixelMode, maxmips: c_int, a2: c_int, swizzle: c_int) void { +pub fn sceGuTexMode(tpsm: pspgutypes.GuPixelMode, maxmips: c_int, a2: c_int, swizzle: c_int) void { @setRuntimeSafety(false); - gu_contexts[@intCast(usize, gu_curr_context)].texture_mode = @enumToInt(tpsm); + gu_contexts[@as(usize, @intCast(gu_curr_context))].texture_mode = @intFromEnum(tpsm); sendCommandi(194, (maxmips << 16) | (a2 << 8) | (swizzle)); - sendCommandi(195, @enumToInt(tpsm)); + sendCommandi(195, @intFromEnum(tpsm)); sceGuTexFlush(); } @@ -1316,8 +1317,8 @@ pub fn sceGuTexOffset(u: f32, v: f32) void { pub fn sceGuTexProjMapMode(mode: c_int) void { @setRuntimeSafety(false); - gu_contexts[@intCast(usize, gu_curr_context)].texture_proj_map_mode = ((mode & 0x03) << 8); - sendCommandi(192, ((mode & 0x03) << 8) | gu_contexts[@intCast(usize, gu_curr_context)].texture_map_mode); + gu_contexts[@as(usize, @intCast(gu_curr_context))].texture_proj_map_mode = ((mode & 0x03) << 8); + sendCommandi(192, ((mode & 0x03) << 8) | gu_contexts[@as(usize, @intCast(gu_curr_context))].texture_map_mode); } pub fn sceGuTexScale(u: f32, v: f32) void { @@ -1336,17 +1337,17 @@ pub fn sceGuTexSync() void { sendCommandi(204, 0); } -pub fn sceGuTexWrap(u: GuTexWrapMode, v: GuTexWrapMode) void { +pub fn sceGuTexWrap(u: pspgutypes.GuTexWrapMode, v: pspgutypes.GuTexWrapMode) void { @setRuntimeSafety(false); - sendCommandi(199, (@enumToInt(v) << 8) | (@enumToInt(u))); + sendCommandi(199, (@intFromEnum(v) << 8) | (@intFromEnum(u))); } pub fn sceGuViewport(cx: c_int, cy: c_int, width: c_int, height: c_int) void { @setRuntimeSafety(false); - sendCommandf(66, @intToFloat(f32, width >> 1)); - sendCommandf(67, @intToFloat(f32, (-height) >> 1)); - sendCommandf(69, @intToFloat(f32, cx)); - sendCommandf(70, @intToFloat(f32, cy)); + sendCommandf(66, @as(f32, @floatFromInt(width >> 1))); + sendCommandf(67, @as(f32, @floatFromInt((-height) >> 1))); + sendCommandf(69, @as(f32, @floatFromInt(cx))); + sendCommandf(70, @as(f32, @floatFromInt(cy))); } const ge_init_list = [_]c_uint{ @@ -1382,41 +1383,41 @@ const ge_init_list = [_]c_uint{ pub fn sceGuInit() void { @setRuntimeSafety(false); - var callback: PspGeCallbackData = undefined; + var callback: pspge.PspGeCallbackData = undefined; callback.signal_func = callbackSig; callback.signal_arg = &gu_settings; callback.finish_func = callbackFin; callback.finish_arg = &gu_settings; - gu_settings.ge_callback_id = sceGeSetCallback(&callback); + gu_settings.ge_callback_id = pspge.sceGeSetCallback(&callback); gu_settings.swapBuffersCallback = null; gu_settings.swapBuffersBehaviour = 1; - ge_edram_address = sceGeEdramGetAddr(); + ge_edram_address = pspge.sceGeEdramGetAddr(); - ge_list_executed[0] = sceGeListEnQueue((@intToPtr(*c_void, @ptrToInt(&ge_init_list) & 0x1fffffff)), null, gu_settings.ge_callback_id, 0); + 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 = sceKernelCreateEventFlag("SceGuSignal", 512, 3, 0); + gu_settings.kernel_event_flag = pspthreadman.sceKernelCreateEventFlag("SceGuSignal", 512, 3, 0); - _ = sceGeListSync(ge_list_executed[0], 0); + _ = pspge.sceGeListSync(ge_list_executed[0], 0); } -pub fn sceGuStart(cont: GuContextType, list: ?*c_void) void { +pub fn sceGuStart(cont: pspgutypes.GuContextType, list: ?*anyopaque) void { @setRuntimeSafety(false); - var local_list: [*]u32 = @intToPtr([*]u32, (@intCast(usize, @ptrToInt(list)) | 0x40000000)); + const local_list: [*]u32 = @as([*]u32, @ptrFromInt((@as(usize, @intCast(@intFromPtr(list))) | 0x40000000))); - var cid: c_int = @enumToInt(cont); + const cid: c_int = @intFromEnum(cont); - gu_contexts[@intCast(usize, cid)].list.start = local_list; - gu_contexts[@intCast(usize, cid)].list.current = local_list; - gu_contexts[@intCast(usize, cid)].list.parent_context = gu_curr_context; - gu_list = &gu_contexts[@intCast(usize, cid)].list; + gu_contexts[@as(usize, @intCast(cid))].list.start = local_list; + gu_contexts[@as(usize, @intCast(cid))].list.current = local_list; + gu_contexts[@as(usize, @intCast(cid))].list.parent_context = gu_curr_context; + gu_list = &gu_contexts[@as(usize, @intCast(cid))].list; gu_curr_context = cid; if (cid == 0) { - ge_list_executed[0] = sceGeListEnQueue(local_list, local_list, gu_settings.ge_callback_id, 0); + ge_list_executed[0] = pspge.sceGeListEnQueue(local_list, local_list, gu_settings.ge_callback_id, 0); gu_settings.signal_offset = 0; } @@ -1428,9 +1429,9 @@ pub fn sceGuStart(cont: GuContextType, list: ?*c_void) void { 3, -1, 2, -2, }; - sceGuSetDither(@ptrCast(*ScePspIMatrix4, &dither_matrix)); + sceGuSetDither(@as(*psptypes.ScePspIMatrix4, @ptrCast(&dither_matrix))); sceGuPatchDivide(16, 16); - sceGuColorMaterial(@enumToInt(GuLightBitFlags.Ambient) | @enumToInt(GuLightBitFlags.Diffuse) | @enumToInt(GuLightBitFlags.Specular)); + sceGuColorMaterial(@intFromEnum(pspgutypes.GuLightBitFlags.Ambient) | @intFromEnum(pspgutypes.GuLightBitFlags.Diffuse) | @intFromEnum(pspgutypes.GuLightBitFlags.Specular)); sceGuSpecular(1.0); sceGuTexScale(1.0, 1.0); @@ -1439,19 +1440,17 @@ pub fn sceGuStart(cont: GuContextType, list: ?*c_void) void { if (gu_curr_context == 0) { if (gu_draw_buffer.frame_width != 0) { - sendCommandi(156, @intCast(c_int, @ptrToInt(gu_draw_buffer.frame_buffer)) & 0xffffff); - sendCommandi(157, (@intCast(c_int, (@ptrToInt(gu_draw_buffer.frame_buffer) & 0xff000000)) >> 8) | gu_draw_buffer.frame_width); + sendCommandi(156, @as(c_int, @intCast(@intFromPtr(gu_draw_buffer.frame_buffer))) & 0xffffff); + sendCommandi(157, (@as(c_int, @intCast((@intFromPtr(gu_draw_buffer.frame_buffer) & 0xff000000))) >> 8) | gu_draw_buffer.frame_width); } } } -const Vertex = packed struct { - color: u32, x: u16, y: u16, z: u16, pad: u16 -}; +const Vertex = packed struct { color: u32, x: u16, y: u16, z: u16, pad: u16 }; pub fn sceGuClear(flags: c_int) void { @setRuntimeSafety(false); - var context: *GuContext = &gu_contexts[@intCast(usize, gu_curr_context)]; + const context: *GuContext = &gu_contexts[@as(usize, @intCast(gu_curr_context))]; var filter: u32 = 0; switch (gu_draw_buffer.pixel_size) { @@ -1472,8 +1471,8 @@ pub fn sceGuClear(flags: c_int) void { }, } - var count: i32 = @divTrunc(gu_draw_buffer.width + 63, 64) * 2; - var vertices: [*]Vertex = @ptrCast([*]Vertex, sceGuGetMemory(@intCast(c_uint, count) * @sizeOf(Vertex))); + const count: i32 = @divTrunc(gu_draw_buffer.width + 63, 64) * 2; + const vertices: [*]Vertex = @ptrCast(@alignCast(sceGuGetMemory(@as(c_uint, @intCast(count)) * @sizeOf(Vertex)))); var i: usize = 0; var curr: [*]Vertex = vertices; @@ -1482,21 +1481,25 @@ pub fn sceGuClear(flags: c_int) void { var j: u16 = 0; var k: u16 = 0; - j = @intCast(u16, i) >> 1; - k = (@intCast(u16, i) & 1); + j = @as(u16, @intCast(i)) >> 1; + k = (@as(u16, @intCast(i)) & 1); curr[i].color = filter; curr[i].x = (j + k) * 64; - curr[i].y = k * @intCast(u16, gu_draw_buffer.height); - curr[i].z = @intCast(u16, context.clear_depth); + curr[i].y = k * @as(u16, @intCast(gu_draw_buffer.height)); + curr[i].z = @as(u16, @intCast(context.clear_depth)); } - sendCommandi(211, ((flags & (@enumToInt(ClearBitFlags.ColorBuffer) | @enumToInt(ClearBitFlags.StencilBuffer) | @enumToInt(ClearBitFlags.DepthBuffer))) << 8) | 0x01); - sceGuDrawArray(GuPrimitive.Sprites, @enumToInt(VertexTypeFlags.Color8888) | @enumToInt(VertexTypeFlags.Vertex16Bit) | @enumToInt(VertexTypeFlags.Transform2D), @intCast(c_int, count), null, vertices); + const ClearBitFlags = pspgutypes.ClearBitFlags; + const VertexTypeFlags = pspgutypes.VertexTypeFlags; + const GuPrimitive = pspgutypes.GuPrimitive; + + 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) *c_void { +pub fn sceGuGetMemory(size: c_uint) *anyopaque { @setRuntimeSafety(false); var siz = size; @@ -1504,11 +1507,11 @@ pub fn sceGuGetMemory(size: c_uint) *c_void { siz += (siz >> 31) >> 30; siz = (siz >> 2) << 2; - var orig_ptr: [*]u32 = @ptrCast([*]u32, gu_list.?.current); - var new_ptr: [*]u32 = @intToPtr([*]u32, (@intCast(c_uint, @ptrToInt(orig_ptr)) + siz + 8)); + var orig_ptr: [*]u32 = @as([*]u32, @ptrCast(gu_list.?.current)); + const new_ptr: [*]u32 = @as([*]u32, @ptrFromInt((@as(c_uint, @intCast(@intFromPtr(orig_ptr))) + siz + 8))); - var lo = (8 << 24) | (@ptrToInt(new_ptr) & 0xffffff); - var hi = (16 << 24) | ((@ptrToInt(new_ptr) >> 8) & 0xf0000); + const lo = (8 << 24) | (@intFromPtr(new_ptr) & 0xffffff); + const hi = (16 << 24) | ((@intFromPtr(new_ptr) >> 8) & 0xf0000); orig_ptr[0] = hi; orig_ptr[1] = lo; @@ -1516,7 +1519,7 @@ pub fn sceGuGetMemory(size: c_uint) *c_void { gu_list.?.current = new_ptr; if (gu_curr_context == 0) { - _ = sceGeListUpdateStallAddr(ge_list_executed[0], new_ptr); + _ = pspge.sceGeListUpdateStallAddr(ge_list_executed[0], new_ptr); } - return @intToPtr(*c_void, @ptrToInt(orig_ptr + 2)); + return @as(*anyopaque, @ptrFromInt(@intFromPtr(orig_ptr + 2))); } diff --git a/src/psp/sdk/pspgumimpl.zig b/src/psp/sdk/pspgumimpl.zig index b325e4c..1280817 100644 --- a/src/psp/sdk/pspgumimpl.zig +++ b/src/psp/sdk/pspgumimpl.zig @@ -1,34 +1,34 @@ -usingnamespace @import("psptypes.zig"); -usingnamespace @import("pspgu.zig"); +const psptypes = @import("psptypes.zig"); +const pspgu = @import("pspgu.zig"); //Internal var gum_current_mode: u8 = 0; var gum_matrix_update: [4]u8 = [_]u8{0} ** 4; var gum_current_matrix_update: u8 = 0; -var gum_current_matrix: *ScePspFMatrix4 = @ptrCast(*ScePspFMatrix4, &gum_matrix_stack[0]); -var gum_stack_depth: [4][*]ScePspFMatrix4 = [_][*]ScePspFMatrix4{ @ptrCast([*]ScePspFMatrix4, &gum_matrix_stack[0]), @ptrCast([*]ScePspFMatrix4, &gum_matrix_stack[1]), @ptrCast([*]ScePspFMatrix4, &gum_matrix_stack[2]), @ptrCast([*]ScePspFMatrix4, &gum_matrix_stack[3]) }; +var gum_current_matrix: *psptypes.ScePspFMatrix4 = @as(*psptypes.ScePspFMatrix4, @ptrCast(&gum_matrix_stack[0])); +var gum_stack_depth: [4][*]psptypes.ScePspFMatrix4 = [_][*]psptypes.ScePspFMatrix4{ @as([*]psptypes.ScePspFMatrix4, @ptrCast(&gum_matrix_stack[0])), @as([*]psptypes.ScePspFMatrix4, @ptrCast(&gum_matrix_stack[1])), @as([*]psptypes.ScePspFMatrix4, @ptrCast(&gum_matrix_stack[2])), @as([*]psptypes.ScePspFMatrix4, @ptrCast(&gum_matrix_stack[3])) }; -var gum_matrix_stack: [4][32]ScePspFMatrix4 = undefined; +var gum_matrix_stack: [4][32]psptypes.ScePspFMatrix4 = undefined; -pub fn sceGumDrawArray(prim: GuPrimitive, vtype: c_int, count: c_int, indices: ?*const c_void, vertices: ?*const c_void) void { +pub fn sceGumDrawArray(prim: pspgu.GuPrimitive, vtype: c_int, count: c_int, indices: ?*const anyopaque, vertices: ?*const anyopaque) void { sceGumUpdateMatrix(); - sceGuDrawArray(prim, vtype, count, indices, vertices); + pspgu.sceGuDrawArray(prim, vtype, count, indices, vertices); } -pub fn sceGumDrawArrayN(prim: c_int, vtype: c_int, count: c_int, a3: c_int, indices: ?*const c_void, vertices: ?*const c_void) void { +pub fn sceGumDrawArrayN(prim: c_int, vtype: c_int, count: c_int, a3: c_int, indices: ?*const anyopaque, vertices: ?*const anyopaque) void { sceGumUpdateMatrix(); - sceGuDrawArrayN(prim, vtype, count, a3, indices, vertices); + pspgu.sceGuDrawArrayN(prim, vtype, count, a3, indices, vertices); } -pub fn sceGumDrawBezier(vtype: c_int, ucount: c_int, vcount: c_int, indices: ?*const c_void, vertices: ?*const c_void) void { +pub fn sceGumDrawBezier(vtype: c_int, ucount: c_int, vcount: c_int, indices: ?*const anyopaque, vertices: ?*const anyopaque) void { sceGumUpdateMatrix(); - sceGuDrawBezier(vtype, ucount, vcount, indices, vertices); + 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 c_void, vertices: ?*const c_void) void { +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 { sceGumUpdateMatrix(); - sceGuDrawSpline(vtype, ucount, vcount, uedge, vedge, indices, vertices); + pspgu.sceGuDrawSpline(vtype, ucount, vcount, uedge, vedge, indices, vertices); } extern fn memset(ptr: [*]u8, value: u32, num: usize) [*]u8; @@ -36,78 +36,78 @@ extern fn memcpy(dst: [*]u8, src: [*]const u8, num: isize) [*]u8; extern fn memcmp(ptr1: [*]u8, ptr2: [*]u8, num: isize) i32; pub fn sceGumLoadIdentity() void { - _ = memset(@ptrCast([*]u8, gum_current_matrix), 0, @sizeOf(ScePspFMatrix4)); + _ = memset(@as([*]u8, @ptrCast(gum_current_matrix)), 0, @sizeOf(psptypes.ScePspFMatrix4)); var i: usize = 0; while (i < 4) : (i += 1) { - @ptrCast([*]f32, gum_current_matrix)[(i << 2) + i] = 1.0; + @as([*]f32, @ptrCast(gum_current_matrix))[(i << 2) + i] = 1.0; } gum_current_matrix_update = 1; } -pub fn sceGumLoadMatrix(m: [*c]ScePspFMatrix4) void { - _ = memcpy(@ptrCast([*]u8, gum_current_matrix), @ptrCast([*]u8, m), @sizeOf(ScePspFMatrix4)); +pub fn sceGumLoadMatrix(m: [*c]psptypes.ScePspFMatrix4) void { + _ = memcpy(@as([*]u8, @ptrCast(gum_current_matrix)), @as([*]u8, @ptrCast(m)), @sizeOf(psptypes.ScePspFMatrix4)); gum_current_matrix_update = 1; } pub fn sceGumUpdateMatrix() void { - gum_stack_depth[gum_current_mode] = @ptrCast([*]ScePspFMatrix4, gum_current_matrix); + gum_stack_depth[gum_current_mode] = @as([*]psptypes.ScePspFMatrix4, @ptrCast(gum_current_matrix)); gum_matrix_update[gum_current_mode] = gum_current_matrix_update; gum_current_matrix_update = 0; var i: usize = 0; while (i < 4) : (i += 1) { if (gum_matrix_update[i] != 0) { - sceGuSetMatrix(@intCast(c_int, i), gum_stack_depth[i]); + pspgu.sceGuSetMatrix(@as(c_int, @intCast(i)), gum_stack_depth[i]); gum_matrix_update[i] = 0; } } } pub fn sceGumPopMatrix() void { - var t = @ptrCast([*]ScePspFMatrix4, gum_current_matrix); + var t = @as([*]psptypes.ScePspFMatrix4, @ptrCast(gum_current_matrix)); t -= 1; - gum_current_matrix = @ptrCast(*ScePspFMatrix4, t); + gum_current_matrix = @as(*psptypes.ScePspFMatrix4, @ptrCast(t)); gum_current_matrix_update = 1; } pub fn sceGumPushMatrix() void { - _ = memcpy(@ptrCast([*]u8, @ptrCast([*]ScePspFMatrix4, gum_current_matrix) + 1), @ptrCast([*]u8, @ptrCast([*]ScePspFMatrix4, gum_current_matrix)), @sizeOf(ScePspFMatrix4)); - var t = @ptrCast([*]ScePspFMatrix4, gum_current_matrix); + _ = memcpy(@as([*]u8, @ptrCast(@as([*]psptypes.ScePspFMatrix4, @ptrCast(gum_current_matrix)) + 1)), @as([*]u8, @ptrCast(@as([*]psptypes.ScePspFMatrix4, @ptrCast(gum_current_matrix)))), @sizeOf(psptypes.ScePspFMatrix4)); + var t = @as([*]psptypes.ScePspFMatrix4, @ptrCast(gum_current_matrix)); t += 1; - gum_current_matrix = @ptrCast(*ScePspFMatrix4, t); + gum_current_matrix = @as(*psptypes.ScePspFMatrix4, @ptrCast(t)); } -pub fn sceGumRotateXYZ(v: *ScePspFVector3) void { +pub fn sceGumRotateXYZ(v: *psptypes.ScePspFVector3) void { sceGumRotateX(v.x); sceGumRotateY(v.y); sceGumRotateZ(v.z); } -pub fn sceGumRotateZYX(v: *ScePspFVector3) void { +pub fn sceGumRotateZYX(v: *psptypes.ScePspFVector3) void { sceGumRotateZ(v.z); sceGumRotateY(v.y); sceGumRotateX(v.x); } -pub fn sceGumStoreMatrix(m: [*c]ScePspFMatrix4) void { - _ = memcpy(@ptrCast([*]u8, m), @ptrCast([*]u8, gum_current_matrix), @sizeOf(ScePspFMatrix4)); +pub fn sceGumStoreMatrix(m: [*c]psptypes.ScePspFMatrix4) void { + _ = memcpy(@as([*]u8, @ptrCast(m)), @as([*]u8, @ptrCast(gum_current_matrix)), @sizeOf(psptypes.ScePspFMatrix4)); } const std = @import("std"); pub fn sceGumRotateX(angle: f32) void { - var t: ScePspFMatrix4 = undefined; + var t: psptypes.ScePspFMatrix4 = undefined; - _ = memset(@ptrCast([*]u8, &t), 0, @sizeOf(ScePspFMatrix4)); + _ = memset(@as([*]u8, @ptrCast(&t)), 0, @sizeOf(psptypes.ScePspFMatrix4)); var i: usize = 0; while (i < 4) : (i += 1) { - @ptrCast([*]f32, &t)[(i << 2) + i] = 1.0; + @as([*]f32, @ptrCast(&t))[(i << 2) + i] = 1.0; } - var c: f32 = @import("cos.zig").cos(angle); - var s: f32 = @import("sin.zig").sin(angle); + const c: f32 = @import("cos.zig").cos(angle); + const s: f32 = @import("sin.zig").sin(angle); t.y.y = c; t.y.z = s; @@ -118,17 +118,17 @@ pub fn sceGumRotateX(angle: f32) void { } pub fn sceGumRotateY(angle: f32) void { - var t: ScePspFMatrix4 = undefined; + var t: psptypes.ScePspFMatrix4 = undefined; - _ = memset(@ptrCast([*]u8, &t), 0, @sizeOf(ScePspFMatrix4)); + _ = memset(@as([*]u8, @ptrCast(&t)), 0, @sizeOf(psptypes.ScePspFMatrix4)); var i: usize = 0; while (i < 4) : (i += 1) { - @ptrCast([*]f32, &t)[(i << 2) + i] = 1.0; + @as([*]f32, @ptrCast(&t))[(i << 2) + i] = 1.0; } - var c: f32 = @import("cos.zig").cos(angle); - var s: f32 = @import("sin.zig").sin(angle); + const c: f32 = @import("cos.zig").cos(angle); + const s: f32 = @import("sin.zig").sin(angle); t.x.x = c; t.x.z = -s; @@ -139,17 +139,17 @@ pub fn sceGumRotateY(angle: f32) void { } pub fn sceGumRotateZ(angle: f32) void { - var t: ScePspFMatrix4 = undefined; + var t: psptypes.ScePspFMatrix4 = undefined; - _ = memset(@ptrCast([*]u8, &t), 0, @sizeOf(ScePspFMatrix4)); + _ = memset(@as([*]u8, @ptrCast(&t)), 0, @sizeOf(psptypes.ScePspFMatrix4)); var i: usize = 0; while (i < 4) : (i += 1) { - @ptrCast([*]f32, &t)[(i << 2) + i] = 1.0; + @as([*]f32, @ptrCast(&t))[(i << 2) + i] = 1.0; } - var c: f32 = @import("cos.zig").cos(angle); - var s: f32 = @import("sin.zig").sin(angle); + const c: f32 = @import("cos.zig").cos(angle); + const s: f32 = @import("sin.zig").sin(angle); t.x.x = c; t.x.y = s; @@ -159,12 +159,12 @@ pub fn sceGumRotateZ(angle: f32) void { gumMultMatrix(gum_current_matrix, gum_current_matrix, &t); } -fn gumMultMatrix(result: [*c]ScePspFMatrix4, a: [*c]const ScePspFMatrix4, b: [*c]const ScePspFMatrix4) void { - var t: ScePspFMatrix4 = undefined; +fn gumMultMatrix(result: [*c]psptypes.ScePspFMatrix4, a: [*c]const psptypes.ScePspFMatrix4, b: [*c]const psptypes.ScePspFMatrix4) void { + var t: psptypes.ScePspFMatrix4 = undefined; - const ma: [*]const f32 = @ptrCast([*]const f32, a); - const mb: [*]const f32 = @ptrCast([*]const f32, b); - var mr: [*]f32 = @ptrCast([*]f32, &t); + const ma: [*]const f32 = @as([*]const f32, @ptrCast(a)); + const mb: [*]const f32 = @as([*]const f32, @ptrCast(b)); + var mr: [*]f32 = @as([*]f32, @ptrCast(&t)); var i: usize = 0; while (i < 4) : (i += 1) { @@ -180,27 +180,27 @@ fn gumMultMatrix(result: [*c]ScePspFMatrix4, a: [*c]const ScePspFMatrix4, b: [*c } } - _ = memcpy(@ptrCast([*]u8, result), @ptrCast([*]u8, &t), @sizeOf(ScePspFMatrix4)); + _ = memcpy(@as([*]u8, @ptrCast(result)), @as([*]u8, @ptrCast(&t)), @sizeOf(psptypes.ScePspFMatrix4)); } -pub fn sceGumMatrixMode(mm: MatrixMode) void { +pub fn sceGumMatrixMode(mm: pspgu.MatrixMode) void { @setRuntimeSafety(false); - var mode: c_int = @enumToInt(mm); + const mode: c_int = @intFromEnum(mm); gum_matrix_update[gum_current_mode] = gum_current_matrix_update; - gum_stack_depth[gum_current_mode] = @ptrCast([*]ScePspFMatrix4, gum_current_matrix); - var t = @ptrCast([*]ScePspFMatrix4, gum_current_matrix); - t = gum_stack_depth[@intCast(usize, mode)]; - gum_current_matrix = @ptrCast(*ScePspFMatrix4, t); - gum_current_mode = @intCast(u8, mode); + gum_stack_depth[gum_current_mode] = @as([*]psptypes.ScePspFMatrix4, @ptrCast(gum_current_matrix)); + var t = @as([*]psptypes.ScePspFMatrix4, @ptrCast(gum_current_matrix)); + t = gum_stack_depth[@as(usize, @intCast(mode))]; + gum_current_matrix = @as(*psptypes.ScePspFMatrix4, @ptrCast(t)); + gum_current_mode = @as(u8, @intCast(mode)); gum_current_matrix_update = gum_matrix_update[gum_current_mode]; } -pub fn sceGumMultMatrix(m: [*c]const ScePspFMatrix4) void { +pub fn sceGumMultMatrix(m: [*c]const psptypes.ScePspFMatrix4) void { gumMultMatrix(gum_current_matrix, gum_current_matrix, m); gum_current_matrix_update = 1; } -pub fn sceGumScale(v: *const ScePspFVector3) void { +pub fn sceGumScale(v: *const psptypes.ScePspFVector3) void { var x: f32 = 0; var y: f32 = 0; var z: f32 = 0; @@ -221,13 +221,13 @@ pub fn sceGumScale(v: *const ScePspFVector3) void { gum_current_matrix_update = 1; } -pub fn sceGumTranslate(v: *const ScePspFVector3) void { - var t: ScePspFMatrix4 = undefined; - _ = memset(@ptrCast([*]u8, &t), 0, @sizeOf(ScePspFMatrix4)); +pub fn sceGumTranslate(v: *const psptypes.ScePspFVector3) void { + var t: psptypes.ScePspFMatrix4 = undefined; + _ = memset(@as([*]u8, @ptrCast(&t)), 0, @sizeOf(psptypes.ScePspFMatrix4)); var i: usize = 0; while (i < 4) : (i += 1) { - @ptrCast([*]f32, &t)[(i << 2) + i] = 1.0; + @as([*]f32, @ptrCast(&t))[(i << 2) + i] = 1.0; } t.w.x = v.x; @@ -238,12 +238,12 @@ pub fn sceGumTranslate(v: *const ScePspFVector3) void { } pub fn sceGumOrtho(left: f32, right: f32, bottom: f32, top: f32, near: f32, far: f32) void { - var dx: f32 = right - left; - var dy: f32 = top - bottom; - var dz: f32 = far - near; + const dx: f32 = right - left; + const dy: f32 = top - bottom; + const dz: f32 = far - near; - var t: ScePspFMatrix4 = undefined; - _ = memset(@ptrCast([*]u8, &t), 0, @sizeOf(ScePspFMatrix4)); + var t: psptypes.ScePspFMatrix4 = undefined; + _ = memset(@as([*]u8, @ptrCast(&t)), 0, @sizeOf(psptypes.ScePspFMatrix4)); t.x.x = 2.0 / dx; t.w.x = -(right + left) / dx; @@ -257,12 +257,12 @@ pub fn sceGumOrtho(left: f32, right: f32, bottom: f32, top: f32, near: f32, far: } pub fn sceGumPerspective(fovy: f32, aspect: f32, near: f32, far: f32) void { - var angle: f32 = (fovy / 2) * (3.14159 / 180.0); - var cotangent: f32 = std.math.cos(angle) / std.math.sin(angle); - var delta_z: f32 = near - far; + const angle: f32 = (fovy / 2) * (3.14159 / 180.0); + const cotangent: f32 = std.math.cos(angle) / std.math.sin(angle); + const delta_z: f32 = near - far; - var t: ScePspFMatrix4 = undefined; - _ = memset(@ptrCast([*]u8, &t), 0, @sizeOf(ScePspFMatrix4)); + var t: psptypes.ScePspFMatrix4 = undefined; + _ = memset(@as([*]u8, @ptrCast(&t)), 0, @sizeOf(psptypes.ScePspFMatrix4)); t.x.x = cotangent / aspect; t.y.y = cotangent; @@ -276,9 +276,9 @@ pub fn sceGumPerspective(fovy: f32, aspect: f32, near: f32, far: f32) void { //Maybe... I kinda just hate this function... it's pointless in most apps //Feel free to make a PR -//pub fn sceGumLookAt(eye: *ScePspFVector3, center: *ScePspFVector3, up: *ScePspFVector3) void{ +//pub fn sceGumLookAt(eye: *psptypes.ScePspFVector3, center: *psptypes.ScePspFVector3, up: *psptypes.ScePspFVector3) void{ // -// var forward : ScePspFVector3 = undefined; +// var forward : psptypes.ScePspFVector3 = undefined; // forward.x = center.x - eye.x; // forward.y = center.y - eye.y; // forward.z = center.z - eye.z; @@ -290,10 +290,10 @@ pub fn sceGumPerspective(fovy: f32, aspect: f32, near: f32, far: f32) void { // forward.x *= il; forward.y *= il; forward.z *= il; // } // -// var side : ScePspFVector3 = undefined; -// var lup : ScePspFVector3 = undefined; -// var ieye : ScePspFVector3 = undefined; -// var t : ScePspFMatrix4 = undefined; +// var side : psptypes.ScePspFVector3 = undefined; +// var lup : psptypes.ScePspFVector3 = undefined; +// var ieye : psptypes.ScePspFVector3 = undefined; +// var t : psptypes.ScePspFMatrix4 = undefined; // // gumCrossProduct(&side,&forward,up); // gumNormalize(&side); @@ -322,7 +322,7 @@ pub fn sceGumPerspective(fovy: f32, aspect: f32, near: f32, far: f32) void { //} pub fn sceGumFullInverse() void { - var t: ScePspFMatrix4 = undefined; + var t: psptypes.ScePspFMatrix4 = undefined; var d0: f32 = 0; var d1: f32 = 0; var d2: f32 = 0; @@ -335,12 +335,12 @@ 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) { - _ = memset(@ptrCast([*]u8, gum_current_matrix), 0, @sizeOf(ScePspFMatrix4)); + if (@abs(d) < 0.000001) { + _ = memset(@as([*]u8, @ptrCast(gum_current_matrix)), 0, @sizeOf(psptypes.ScePspFMatrix4)); var i: usize = 0; while (i < 4) : (i += 1) { - @ptrCast([*]f32, gum_current_matrix)[(i << 2) + i] = 1.0; + @as([*]f32, @ptrCast(gum_current_matrix))[(i << 2) + i] = 1.0; } return; } @@ -367,18 +367,18 @@ pub fn sceGumFullInverse() void { t.w.z = -d * (gum_current_matrix.x.x * gum_current_matrix.y.y * gum_current_matrix.w.z + gum_current_matrix.x.y * gum_current_matrix.y.z * gum_current_matrix.w.x + gum_current_matrix.x.z * gum_current_matrix.y.x * gum_current_matrix.w.y - gum_current_matrix.w.x * gum_current_matrix.y.y * gum_current_matrix.x.z - gum_current_matrix.w.y * gum_current_matrix.y.z * gum_current_matrix.x.x - gum_current_matrix.w.z * gum_current_matrix.y.x * gum_current_matrix.x.y); t.w.w = d * (gum_current_matrix.x.x * gum_current_matrix.y.y * gum_current_matrix.z.z + gum_current_matrix.x.y * gum_current_matrix.y.z * gum_current_matrix.z.x + gum_current_matrix.x.z * gum_current_matrix.y.x * gum_current_matrix.z.y - gum_current_matrix.z.x * gum_current_matrix.y.y * gum_current_matrix.x.z - gum_current_matrix.z.y * gum_current_matrix.y.z * gum_current_matrix.x.x - gum_current_matrix.z.z * gum_current_matrix.y.x * gum_current_matrix.x.y); - _ = memcpy(@ptrCast([*]u8, gum_current_matrix), @ptrCast([*]u8, &t), @sizeOf(ScePspFMatrix4)); + _ = memcpy(@as([*]u8, @ptrCast(gum_current_matrix)), @as([*]u8, @ptrCast(&t)), @sizeOf(psptypes.ScePspFMatrix4)); gum_current_matrix_update = 1; } -fn gumDotProduct(a: *ScePspFVector3, b: *ScePspFVector3) f32 { +fn gumDotProduct(a: *psptypes.ScePspFVector3, b: *psptypes.ScePspFVector3) f32 { return (a.x * b.x) + (a.y * b.y) + (a.z * b.z); } pub fn sceGumFastInverse() void { - var t: ScePspFMatrix4 = undefined; - var negPos: ScePspFVector3 = ScePspFVector3{ .x = -gum_current_matrix.w.x, .y = -gum_current_matrix.w.y, .z = -gum_current_matrix.w.z }; + var t: psptypes.ScePspFMatrix4 = undefined; + var negPos: psptypes.ScePspFVector3 = psptypes.ScePspFVector3{ .x = -gum_current_matrix.w.x, .y = -gum_current_matrix.w.y, .z = -gum_current_matrix.w.z }; // transpose rotation t.x.x = gum_current_matrix.x.x; @@ -397,11 +397,11 @@ pub fn sceGumFastInverse() void { t.z.w = 0; // compute inverse position - t.w.x = gumDotProduct(&negPos, @ptrCast(*ScePspFVector3, &gum_current_matrix.x)); - t.w.y = gumDotProduct(&negPos, @ptrCast(*ScePspFVector3, &gum_current_matrix.y)); - t.w.z = gumDotProduct(&negPos, @ptrCast(*ScePspFVector3, &gum_current_matrix.z)); + t.w.x = gumDotProduct(&negPos, @as(*psptypes.ScePspFVector3, @ptrCast(&gum_current_matrix.x))); + t.w.y = gumDotProduct(&negPos, @as(*psptypes.ScePspFVector3, @ptrCast(&gum_current_matrix.y))); + t.w.z = gumDotProduct(&negPos, @as(*psptypes.ScePspFVector3, @ptrCast(&gum_current_matrix.z))); t.w.w = 1; - _ = memcpy(@ptrCast([*]u8, gum_current_matrix), @ptrCast([*]u8, &t), @sizeOf(ScePspFMatrix4)); + _ = memcpy(@as([*]u8, @ptrCast(gum_current_matrix)), @as([*]u8, @ptrCast(&t)), @sizeOf(psptypes.ScePspFMatrix4)); gum_current_matrix_update = 1; } diff --git a/src/psp/sdk/pspgutypes.zig b/src/psp/sdk/pspgutypes.zig index 8a4f41a..9ad4fad 100644 --- a/src/psp/sdk/pspgutypes.zig +++ b/src/psp/sdk/pspgutypes.zig @@ -1,4 +1,4 @@ -pub const GuPixelMode = extern enum(c_int) { +pub const GuPixelMode = enum(c_int) { Psm5650 = 0, Psm5551 = 1, Psm4444 = 2, @@ -12,7 +12,7 @@ pub const GuPixelMode = extern enum(c_int) { PsmDXT5 = 10, }; -pub const GuPrimitive = extern enum(c_int) { +pub const GuPrimitive = enum(c_int) { Points = 0, Lines = 1, LineStrip = 2, @@ -22,13 +22,13 @@ pub const GuPrimitive = extern enum(c_int) { Sprites = 6, }; -pub const PatchPrimitive = extern enum(c_int) { +pub const PatchPrimitive = enum(c_int) { Points = 0, LineStrip = 2, TriangleStrip = 4, }; -pub const GuState = extern enum(c_int) { +pub const GuState = enum(c_int) { AlphaTest = 0, DepthTest = 1, ScissorTest = 2, @@ -53,26 +53,26 @@ pub const GuState = extern enum(c_int) { Fragment2X = 21, }; -pub const MatrixMode = extern enum(c_int) { +pub const MatrixMode = enum(c_int) { Projection = 0, View = 1, Model = 2, Texture = 3, }; -pub const SplineMode = extern enum(c_int) { +pub const SplineMode = enum(c_int) { FillFill = 0, OpenFill = 1, FillOpen = 2, OpenOpen = 3, }; -pub const ShadeModel = extern enum(c_int) { +pub const ShadeModel = enum(c_int) { Flat = 0, Smooth = 1, }; -pub const GuLogicalOperation = extern enum(c_int) { +pub const GuLogicalOperation = enum(c_int) { Clear = 0, And = 1, AndReverse = 2, @@ -91,7 +91,7 @@ pub const GuLogicalOperation = extern enum(c_int) { Set = 15, }; -pub const TextureFilter = extern enum(c_int) { +pub const TextureFilter = enum(c_int) { Nearest = 0, Linear = 1, NearestMipmapNearest = 4, @@ -100,36 +100,36 @@ pub const TextureFilter = extern enum(c_int) { LinearMipmapLinear = 7, }; -pub const TextureMapMode = extern enum(c_int) { +pub const TextureMapMode = enum(c_int) { Coords = 0, Matrix = 1, EnvironmentMap = 2, }; -pub const TextureLevelMode = extern enum(c_int) { +pub const TextureLevelMode = enum(c_int) { Auto = 0, Const = 1, Slope = 2, }; -pub const TextureProjectionMapMode = extern enum(c_int) { +pub const TextureProjectionMapMode = enum(c_int) { Position = 0, Uv = 1, NormalizedNormal = 2, Normal = 3, }; -pub const GuTexWrapMode = extern enum(c_int) { +pub const GuTexWrapMode = enum(c_int) { Repeat = 0, Clamp = 1, }; -pub const FrontFaceDirection = extern enum(c_int) { +pub const FrontFaceDirection = enum(c_int) { Clockwise = 0, CounterClockwise = 1, }; -pub const AlphaFunc = extern enum(c_int) { +pub const AlphaFunc = enum(c_int) { Never = 0, Always, Equal, @@ -140,7 +140,7 @@ pub const AlphaFunc = extern enum(c_int) { GreaterOrEqual, }; -pub const StencilFunc = extern enum(c_int) { +pub const StencilFunc = enum(c_int) { Never = 0, Always, Equal, @@ -151,14 +151,14 @@ pub const StencilFunc = extern enum(c_int) { GreaterOrEqual, }; -pub const ColorFunc = extern enum(c_int) { +pub const ColorFunc = enum(c_int) { Never = 0, Always, Equal, NotEqual, }; -pub const DepthFunc = extern enum(c_int) { +pub const DepthFunc = enum(c_int) { Never = 0, Always, Equal, @@ -169,7 +169,7 @@ pub const DepthFunc = extern enum(c_int) { GreaterOrEqual, }; -pub const TextureEffect = extern enum(c_int) { +pub const TextureEffect = enum(c_int) { Modulate = 0, Decal = 1, Blend = 2, @@ -177,12 +177,12 @@ pub const TextureEffect = extern enum(c_int) { Add = 4, }; -pub const TextureColorComponent = extern enum(c_int) { +pub const TextureColorComponent = enum(c_int) { Rgb = 0, Rgba = 1, }; -pub const MipmapLevel = extern enum(c_int) { +pub const MipmapLevel = enum(c_int) { None = 0, Level1, Level2, @@ -193,7 +193,7 @@ pub const MipmapLevel = extern enum(c_int) { Level7, }; -pub const BlendOp = extern enum(c_int) { +pub const BlendOp = enum(c_int) { Add = 0, Subtract = 1, ReverseSubtract = 2, @@ -202,7 +202,7 @@ pub const BlendOp = extern enum(c_int) { Abs = 5, }; -pub const BlendArg = extern enum(c_int) { +pub const BlendArg = enum(c_int) { SrcColor = 0, OneMinusSrcColor = 1, SrcAlpha = 2, @@ -214,7 +214,7 @@ pub const BlendArg = extern enum(c_int) { Fix = 10, }; -pub const StencilOperation = extern enum(c_int) { +pub const StencilOperation = enum(c_int) { Keep = 0, Zero = 1, Replace = 2, @@ -223,29 +223,29 @@ pub const StencilOperation = extern enum(c_int) { Decr = 5, }; -pub const LightMode = extern enum(c_int) { +pub const LightMode = enum(c_int) { SingleColor = 0, SeparateSpecularColor = 1, }; -pub const GuLightType = extern enum(c_int) { +pub const GuLightType = enum(c_int) { Directional = 0, Pointlight = 1, Spotlight = 2, }; -pub const GuContextType = extern enum(c_int) { +pub const GuContextType = enum(c_int) { Direct = 0, Call = 1, Send = 2, }; -pub const GuQueueMode = extern enum(c_int) { +pub const GuQueueMode = enum(c_int) { Tail = 0, Head = 1, }; -pub const GuSyncMode = extern enum(c_int) { +pub const GuSyncMode = enum(c_int) { Finish = 0, Signal = 1, Done = 2, @@ -253,28 +253,28 @@ pub const GuSyncMode = extern enum(c_int) { Send = 4, }; -pub const GuSyncBehavior = extern enum(c_int) { +pub const GuSyncBehavior = enum(c_int) { Wait = 0, NoWait = 1, }; -pub const GuCallbackId = extern enum(c_int) { +pub const GuCallbackId = enum(c_int) { Signal = 1, Finish = 4, }; -pub const GuSignalBehavior = extern enum(c_int) { +pub const GuSignalBehavior = enum(c_int) { Suspend = 1, Continue = 2, }; -pub const ClearBitFlags = extern enum(c_int) { +pub const ClearBitFlags = enum(c_int) { ColorBuffer = 1, StencilBuffer = 2, DepthBuffer = 4, }; -pub const GuLightBitFlags = extern enum(c_int) { +pub const GuLightBitFlags = enum(c_int) { Ambient = 1, Diffuse = 2, AmbientDiffuse = 3, @@ -283,7 +283,7 @@ pub const GuLightBitFlags = extern enum(c_int) { Unknown = 8, }; -pub const VertexTypeFlags = extern enum(c_int) { +pub const VertexTypeFlags = enum(c_int) { Texture8Bit = 1, Texture16Bit = 2, Texture32Bitf = 3, @@ -306,4 +306,4 @@ pub const VertexTypeFlags = extern enum(c_int) { Transform3D = 0, }; -pub const GuSwapBuffersCallback = ?fn ([*c]?*c_void, [*c]?*c_void) callconv(.C) void; +pub const GuSwapBuffersCallback = ?*const fn ([*c]?*anyopaque, [*c]?*anyopaque) callconv(.C) void; diff --git a/src/psp/sdk/psphprm.zig b/src/psp/sdk/psphprm.zig index b44009d..ed2e6d3 100644 --- a/src/psp/sdk/psphprm.zig +++ b/src/psp/sdk/psphprm.zig @@ -1,4 +1,4 @@ -pub const PspHprmKeys = extern enum(u8) { +pub const PspHprmKeys = enum(u8) { Playpause = 1, Forward = 4, Back = 8, @@ -15,7 +15,7 @@ pub const PspHprmKeys = extern enum(u8) { // @return < 0 on error pub extern fn sceHprmPeekCurrentKey(key: [*]u32) c_int; pub fn hprmPeekCurrentKey(latch: [*]u32) !i32 { - var res = sceHprmPeekCurrentKey(latch); + const res = sceHprmPeekCurrentKey(latch); if (res < 0) { return error.Unexpected; } @@ -29,7 +29,7 @@ pub fn hprmPeekCurrentKey(latch: [*]u32) !i32 { // @return < 0 on error. pub extern fn sceHprmPeekLatch(latch: [*]u32) c_int; pub fn hprmPeekLatch(latch: [*]u32) !i32 { - var res = sceHprmPeekLatch(latch); + const res = sceHprmPeekLatch(latch); if (res < 0) { return error.Unexpected; } @@ -43,7 +43,7 @@ pub fn hprmPeekLatch(latch: [*]u32) !i32 { // @return < 0 on error. pub extern fn sceHprmReadLatch(latch: [*]u32) c_int; pub fn hprmReadLatch(latch: [*]u32) !i32 { - var res = sceHprmReadLatch(latch); + const res = sceHprmReadLatch(latch); if (res < 0) { return error.Unexpected; } diff --git a/src/psp/sdk/psphttp.zig b/src/psp/sdk/psphttp.zig index b40b75d..889d8a2 100644 --- a/src/psp/sdk/psphttp.zig +++ b/src/psp/sdk/psphttp.zig @@ -1,13 +1,16 @@ -usingnamespace @import("psptypes.zig"); +const psptypes = @import("psptypes.zig"); +const SceSize = psptypes.SceSize; +const SceBool = psptypes.SceBool; +const SceULong64 = psptypes.SceULong64; -const enum_unnamed_5 = extern enum(c_int) { +const enum_unnamed_5 = enum(c_int) { PSP_HTTP_VERSION_1_0, PSP_HTTP_VERSION_1_1, _, }; pub const PspHttpHttpVersion = enum_unnamed_5; -const enum_unnamed_6 = extern enum(c_int) { +const enum_unnamed_6 = enum(c_int) { PSP_HTTP_METHOD_GET, PSP_HTTP_METHOD_POST, PSP_HTTP_METHOD_HEAD, @@ -15,30 +18,30 @@ const enum_unnamed_6 = extern enum(c_int) { }; pub const PspHttpMethod = enum_unnamed_6; -const enum_unnamed_7 = extern enum(c_int) { +const enum_unnamed_7 = enum(c_int) { PSP_HTTP_AUTH_BASIC, PSP_HTTP_AUTH_DIGEST, _, }; pub const PspHttpAuthType = enum_unnamed_7; -const enum_unnamed_8 = extern enum(c_int) { +const enum_unnamed_8 = enum(c_int) { PSP_HTTP_PROXY_AUTO, PSP_HTTP_PROXY_MANUAL, _, }; pub const PspHttpProxyMode = enum_unnamed_8; -const enum_unnamed_9 = extern enum(c_int) { +const enum_unnamed_9 = enum(c_int) { PSP_HTTP_HEADER_OVERWRITE, PSP_HTTP_HEADER_ADD, _, }; pub const PspHttpAddHeaderMode = enum_unnamed_9; -pub const PspHttpMallocFunction = ?fn (SceSize) callconv(.C) ?*c_void; -pub const PspHttpReallocFunction = ?fn (?*c_void, SceSize) callconv(.C) ?*c_void; -pub const PspHttpFreeFunction = ?fn (?*c_void) 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 PspHttpMallocFunction = ?*const fn (SceSize) callconv(.C) ?*anyopaque; +pub const PspHttpReallocFunction = ?*const fn (?*anyopaque, SceSize) callconv(.C) ?*anyopaque; +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; @@ -49,9 +52,9 @@ pub extern fn sceHttpDeleteConnection(connectionid: c_int) c_int; pub extern fn sceHttpCreateRequest(connectionid: c_int, method: PspHttpMethod, path: [*c]u8, contentlength: SceULong64) c_int; pub extern fn sceHttpCreateRequestWithURL(connectionid: c_int, method: PspHttpMethod, url: [*c]u8, contentlength: SceULong64) c_int; pub extern fn sceHttpDeleteRequest(requestid: c_int) c_int; -pub extern fn sceHttpSendRequest(requestid: c_int, data: ?*c_void, datasize: c_uint) c_int; +pub extern fn sceHttpSendRequest(requestid: c_int, data: ?*anyopaque, datasize: c_uint) c_int; pub extern fn sceHttpAbortRequest(requestid: c_int) c_int; -pub extern fn sceHttpReadData(requestid: c_int, data: ?*c_void, datasize: c_uint) c_int; +pub extern fn sceHttpReadData(requestid: c_int, data: ?*anyopaque, datasize: c_uint) c_int; pub extern fn sceHttpGetContentLength(requestid: c_int, contentlength: [*c]SceULong64) c_int; pub extern fn sceHttpGetStatusCode(requestid: c_int, statuscode: [*c]c_int) c_int; pub extern fn sceHttpSetResolveTimeOut(id: c_int, timeout: c_uint) c_int; diff --git a/src/psp/sdk/pspiofilemgr.zig b/src/psp/sdk/pspiofilemgr.zig index 90c015d..1b7394e 100644 --- a/src/psp/sdk/pspiofilemgr.zig +++ b/src/psp/sdk/pspiofilemgr.zig @@ -1,6 +1,12 @@ -usingnamespace @import("psptypes.zig"); +const psptypes = @import("psptypes.zig"); +const SceUID = psptypes.SceUID; +const SceSize = psptypes.SceSize; +const SceMode = psptypes.SceMode; +const SceOff = psptypes.SceOff; +const ScePspDateTime = psptypes.ScePspDateTime; +const SceInt64 = psptypes.SceInt64; -pub const enum_IOAccessModes = extern enum(c_int) { +pub const enum_IOAccessModes = enum(c_int) { FIO_S_IFMT = 61440, FIO_S_IFLNK = 16384, FIO_S_IFDIR = 4096, @@ -23,7 +29,7 @@ pub const enum_IOAccessModes = extern enum(c_int) { _, }; -pub const enum_IOFileModes = extern enum(c_int) { +pub const enum_IOFileModes = enum(c_int) { FIO_SO_IFMT = 56, FIO_SO_IFLNK = 8, FIO_SO_IFDIR = 16, @@ -61,12 +67,12 @@ pub const SceIoStat = extern struct { pub const struct_SceIoDirent = extern struct { d_stat: SceIoStat, d_name: [256]u8, - d_private: ?*c_void, + d_private: ?*anyopaque, dummy: c_int, }; pub const SceIoDirent = struct_SceIoDirent; -pub const enum_IoAssignPerms = extern enum(c_int) { +pub const enum_IoAssignPerms = enum(c_int) { IOASSIGN_RDWR = 0, IOASSIGN_RDONLY = 1, _, @@ -75,10 +81,10 @@ pub extern fn sceIoOpen(file: [*c]const u8, flags: c_int, mode: u32) SceUID; pub extern fn sceIoOpenAsync(file: [*c]const u8, flags: c_int, mode: u32) SceUID; pub extern fn sceIoClose(fd: SceUID) c_int; pub extern fn sceIoCloseAsync(fd: SceUID) c_int; -pub extern fn sceIoRead(fd: SceUID, data: ?*c_void, size: SceSize) c_int; -pub extern fn sceIoReadAsync(fd: SceUID, data: ?*c_void, size: SceSize) c_int; -pub extern fn sceIoWrite(fd: SceUID, data: ?*const c_void, size: SceSize) c_int; -pub extern fn sceIoWriteAsync(fd: SceUID, data: ?*const c_void, size: SceSize) c_int; +pub extern fn sceIoRead(fd: SceUID, data: ?*anyopaque, size: SceSize) c_int; +pub extern fn sceIoReadAsync(fd: SceUID, data: ?*anyopaque, size: SceSize) c_int; +pub extern fn sceIoWrite(fd: SceUID, data: ?*const anyopaque, size: SceSize) c_int; +pub extern fn sceIoWriteAsync(fd: SceUID, data: ?*const anyopaque, size: SceSize) c_int; pub extern fn sceIoLseek(fd: SceUID, offset: SceOff, whence: c_int) i64; pub extern fn sceIoLseekAsync(fd: SceUID, offset: SceOff, whence: c_int) c_int; pub extern fn sceIoLseek32(fd: SceUID, offset: c_int, whence: c_int) c_int; @@ -91,13 +97,13 @@ pub extern fn sceIoRename(oldname: [*c]const u8, newname: [*c]const u8) c_int; pub extern fn sceIoDopen(dirname: [*c]const u8) SceUID; pub extern fn sceIoDread(fd: SceUID, dir: [*c]SceIoDirent) c_int; pub extern fn sceIoDclose(fd: SceUID) c_int; -pub extern fn sceIoDevctl(dev: [*c]const u8, cmd: c_uint, indata: ?*c_void, inlen: c_int, outdata: ?*c_void, outlen: c_int) c_int; -pub extern fn sceIoAssign(dev1: [*c]const u8, dev2: [*c]const u8, dev3: [*c]const u8, mode: c_int, unk1: ?*c_void, unk2: c_long) c_int; +pub extern fn sceIoDevctl(dev: [*c]const u8, cmd: c_uint, indata: ?*anyopaque, inlen: c_int, outdata: ?*anyopaque, outlen: c_int) c_int; +pub extern fn sceIoAssign(dev1: [*c]const u8, dev2: [*c]const u8, dev3: [*c]const u8, mode: c_int, unk1: ?*anyopaque, unk2: c_long) c_int; pub extern fn sceIoUnassign(dev: [*c]const u8) c_int; pub extern fn sceIoGetstat(file: [*c]const u8, stat: [*c]SceIoStat) c_int; pub extern fn sceIoChstat(file: [*c]const u8, stat: [*c]SceIoStat, bits: c_int) c_int; -pub extern fn sceIoIoctl(fd: SceUID, cmd: c_uint, indata: ?*c_void, inlen: c_int, outdata: ?*c_void, outlen: c_int) c_int; -pub extern fn sceIoIoctlAsync(fd: SceUID, cmd: c_uint, indata: ?*c_void, inlen: c_int, outdata: ?*c_void, outlen: c_int) c_int; +pub extern fn sceIoIoctl(fd: SceUID, cmd: c_uint, indata: ?*anyopaque, inlen: c_int, outdata: ?*anyopaque, outlen: c_int) c_int; +pub extern fn sceIoIoctlAsync(fd: SceUID, cmd: c_uint, indata: ?*anyopaque, inlen: c_int, outdata: ?*anyopaque, outlen: c_int) c_int; pub extern fn sceIoSync(device: [*c]const u8, unk: c_uint) c_int; pub extern fn sceIoWaitAsync(fd: SceUID, res: [*c]SceInt64) c_int; pub extern fn sceIoWaitAsyncCB(fd: SceUID, res: [*c]SceInt64) c_int; @@ -106,7 +112,7 @@ pub extern fn sceIoGetAsyncStat(fd: SceUID, poll: c_int, res: [*c]SceInt64) c_in pub extern fn sceIoCancel(fd: SceUID) c_int; pub extern fn sceIoGetDevType(fd: SceUID) c_int; pub extern fn sceIoChangeAsyncPriority(fd: SceUID, pri: c_int) c_int; -pub extern fn sceIoSetAsyncCallback(fd: SceUID, cb: SceUID, argp: ?*c_void) c_int; +pub extern fn sceIoSetAsyncCallback(fd: SceUID, cb: SceUID, argp: ?*anyopaque) c_int; pub const struct_PspIoDrv = extern struct { name: [*c]const u8, dev_type: u32, @@ -116,7 +122,7 @@ pub const struct_PspIoDrv = extern struct { }; pub const struct_PspIoDrvArg = extern struct { drv: [*c]struct_PspIoDrv, - arg: ?*c_void, + arg: ?*anyopaque, }; pub const PspIoDrvArg = struct_PspIoDrvArg; pub const struct_PspIoDrvFileArg = extern struct { @@ -124,32 +130,32 @@ pub const struct_PspIoDrvFileArg = extern struct { fs_num: u32, drv: [*c]PspIoDrvArg, unk2: u32, - arg: ?*c_void, + arg: ?*anyopaque, }; 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, ?*c_void, c_int, ?*c_void, 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, ?*c_void, c_int, ?*c_void, 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/pspjpeg.zig b/src/psp/sdk/pspjpeg.zig index 7f5c38b..c1e287e 100644 --- a/src/psp/sdk/pspjpeg.zig +++ b/src/psp/sdk/pspjpeg.zig @@ -1,4 +1,5 @@ -usingnamespace @import("psptypes.zig"); +const psptypes = @import("psptypes.zig"); +const SceSize = psptypes.SceSize; // Inits the MJpeg library // @@ -43,4 +44,4 @@ pub fn jpegDeleteMJpeg() bool { // @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; +pub extern fn sceJpegDecodeMJpeg(jpegbuf: []u8, size: SceSize, rgba: ?*anyopaque, unk: u32) c_int; diff --git a/src/psp/sdk/pspkerror.zig b/src/psp/sdk/pspkerror.zig index 98c9061..5131d7e 100644 --- a/src/psp/sdk/pspkerror.zig +++ b/src/psp/sdk/pspkerror.zig @@ -1,4 +1,4 @@ -pub const PspKernelErrorCodes = extern enum(c_int) { +pub const PspKernelErrorCodes = enum(c_int) { Ok = 0, Error = 2147614721, Notimp = 2147614722, diff --git a/src/psp/sdk/psploadexec.zig b/src/psp/sdk/psploadexec.zig index c56f397..12b974c 100644 --- a/src/psp/sdk/psploadexec.zig +++ b/src/psp/sdk/psploadexec.zig @@ -1,9 +1,10 @@ -usingnamespace @import("psptypes.zig"); +const psptypes = @import("psptypes.zig"); +const SceSize = psptypes.SceSize; pub const SceKernelLoadExecParam = extern struct { size: SceSize, args: SceSize, - argp: ?*c_void, + argp: ?*anyopaque, key: [*c]const u8, }; diff --git a/src/psp/sdk/pspmodulemgr.zig b/src/psp/sdk/pspmodulemgr.zig index de66bc2..0a4b9cc 100644 --- a/src/psp/sdk/pspmodulemgr.zig +++ b/src/psp/sdk/pspmodulemgr.zig @@ -1,4 +1,6 @@ -usingnamespace @import("psptypes.zig"); +const psptypes = @import("psptypes.zig"); +const SceSize = psptypes.SceSize; +const SceUID = psptypes.SceUID; pub const SceKernelLMOption = extern struct { size: SceSize, @@ -79,7 +81,7 @@ pub extern fn sceKernelLoadModuleByID(fid: SceUID, flags: c_int, option: *SceKer // @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; +pub extern fn sceKernelLoadModuleBufferUsbWlan(bufsize: SceSize, buf: ?*anyopaque, flags: c_int, option: *SceKernelLMOption) SceUID; // Start a loaded module. // @@ -90,7 +92,7 @@ pub extern fn sceKernelLoadModuleBufferUsbWlan(bufsize: SceSize, buf: ?*c_void, // @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; +pub extern fn sceKernelStartModule(modid: SceUID, argsize: SceSize, argp: ?*anyopaque, status: *c_int, option: *SceKernelSMOption) c_int; // Stop a running module. // @@ -101,7 +103,7 @@ pub extern fn sceKernelStartModule(modid: SceUID, argsize: SceSize, argp: ?*c_vo // @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; +pub extern fn sceKernelStopModule(modid: SceUID, argsize: SceSize, argp: ?*anyopaque, status: *c_int, option: *SceKernelSMOption) c_int; // Unload a stopped module. // @@ -117,7 +119,7 @@ pub extern fn sceKernelUnloadModule(modid: SceUID) c_int; // @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; +pub extern fn sceKernelSelfStopUnloadModule(unknown: c_int, argsize: SceSize, argp: ?*anyopaque) c_int; // Stop and unload the current module. // @@ -127,7 +129,7 @@ pub extern fn sceKernelSelfStopUnloadModule(unknown: c_int, argsize: SceSize, ar // @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; +pub extern fn sceKernelStopUnloadSelfModule(argsize: SceSize, argp: ?*anyopaque, 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) @@ -156,4 +158,4 @@ pub extern fn sceKernelGetModuleIdList(readbuf: *SceUID, readbufsize: c_int, idc // @param moduleAddr - A pointer to the module // // @return >= 0 on success, otherwise one of ::PspKernelErrorCodes -pub extern fn sceKernelGetModuleIdByAddress(moduleAddr: ?*c_void) c_int; +pub extern fn sceKernelGetModuleIdByAddress(moduleAddr: ?*anyopaque) c_int; diff --git a/src/psp/sdk/pspmp3.zig b/src/psp/sdk/pspmp3.zig index a4965cd..5df49f2 100644 --- a/src/psp/sdk/pspmp3.zig +++ b/src/psp/sdk/pspmp3.zig @@ -1,4 +1,11 @@ -usingnamespace @import("psptypes.zig"); +const psptypes = @import("psptypes.zig"); +const SceUID = psptypes.SceUID; +const SceSize = psptypes.SceSize; +const SceVoid = psptypes.SceVoid; +const SceInt32 = psptypes.SceInt32; +const SceUInt32 = psptypes.SceUInt32; +const SceShort16 = psptypes.SceShort16; +const SceUChar8 = psptypes.SceUChar8; pub const SceMp3InitArg = extern struct { mp3StreamStart: SceUInt32, @@ -18,7 +25,7 @@ pub const SceMp3InitArg = extern struct { // @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); + const res = sceMp3ReserveMp3Handle(args); if (res < 0) { return error.Unexpected; } @@ -32,7 +39,7 @@ pub fn mp3ReserveMp3Handle(args: *SceMp3InitArg) !SceInt32 { // @return 0 if success, < 0 on error. pub extern fn sceMp3ReleaseMp3Handle(handle: SceInt32) SceInt32; pub fn mp3ReleaseMp3Handle(handle: SceInt32) !void { - var res = sceMp3ReleaseMp3Handle(handle); + const res = sceMp3ReleaseMp3Handle(handle); if (res < 0) { return error.Unexpected; } @@ -43,7 +50,7 @@ pub fn mp3ReleaseMp3Handle(handle: SceInt32) !void { // @return 0 if success, < 0 on error. pub extern fn sceMp3InitResource() SceInt32; pub fn mp3InitResource() !void { - var res = sceMp3InitResource(); + const res = sceMp3InitResource(); if (res < 0) { return error.Unexpected; } @@ -54,7 +61,7 @@ pub fn mp3InitResource() !void { // @return 0 if success, < 0 on error. pub extern fn sceMp3TermResource() SceInt32; pub fn mp3TermResource() !void { - var res = sceMp3TermResource(); + const res = sceMp3TermResource(); if (res < 0) { return error.Unexpected; } @@ -67,7 +74,7 @@ pub fn mp3TermResource() !void { // @return 0 if success, < 0 on error. pub extern fn sceMp3Init(handle: SceInt32) SceInt32; pub fn mp3Init(handle: SceInt32) !void { - var res = sceMp3Init(handle); + const res = sceMp3Init(handle); if (res < 0) { return error.Unexpected; } @@ -81,7 +88,7 @@ pub fn mp3Init(handle: SceInt32) !void { // @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); + const res = sceMp3Decode(handle, dst); if (res < 0) { return error.Unexpected; } @@ -98,7 +105,7 @@ pub fn mp3Decode(handle: SceInt32, dst: *[]SceShort16) !i32 { // @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); + const res = sceMp3GetInfoToAddStreamData(handle, dst, towrite, srcpos); if (res < 0) { return error.Unexpected; } @@ -112,7 +119,7 @@ pub fn mp3GetInfoToAddStreamData(handle: SceInt32, dst: *[]SceUChar8, towrite: * // @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); + const res = sceMp3NotifyAddStreamData(handle, size); if (res < 0) { return error.Unexpected; } @@ -133,7 +140,7 @@ pub extern fn sceMp3CheckStreamDataNeeded(handle: SceInt32) SceInt32; // @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); + const res = sceMp3SetLoopNum(handle, loop); if (res < 0) { return error.Unexpected; } @@ -188,7 +195,7 @@ pub extern fn sceMp3GetMp3ChannelNum(handle: SceInt32) SceInt32; // @return < 0 on error pub extern fn sceMp3ResetPlayPosition(handle: SceInt32) SceInt32; pub fn mp3ResetPlayPosition(handle: SceInt32) !void { - var res = sceMp3ResetPlayPosition(handle); + const res = sceMp3ResetPlayPosition(handle); if (res < 0) { return error.Unexpected; } diff --git a/src/psp/sdk/pspmpeg.zig b/src/psp/sdk/pspmpeg.zig index a53b2b0..487b702 100644 --- a/src/psp/sdk/pspmpeg.zig +++ b/src/psp/sdk/pspmpeg.zig @@ -1,4 +1,9 @@ -usingnamespace @import("psptypes.zig"); +const psptypes = @import("psptypes.zig"); +const SceUID = psptypes.SceUID; +const SceVoid = psptypes.SceVoid; +const ScePVoid = psptypes.ScePVoid; +const SceInt32 = psptypes.SceInt32; +const SceUInt32 = psptypes.SceUInt32; pub const SceMpegLLI = extern struct { pSrc: ScePVoid, @@ -26,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 adfdb00..db6ed8f 100644 --- a/src/psp/sdk/pspnet.zig +++ b/src/psp/sdk/pspnet.zig @@ -17,8 +17,8 @@ pub extern fn sceNetAdhocInit() c_int; pub extern fn sceNetAdhocTerm() c_int; pub extern fn sceNetAdhocPdpCreate(mac: [*c]u8, port: c_ushort, bufsize: c_uint, unk1: c_int) c_int; pub extern fn sceNetAdhocPdpDelete(id: c_int, unk1: c_int) c_int; -pub extern fn sceNetAdhocPdpSend(id: c_int, destMacAddr: [*c]u8, port: c_ushort, data: ?*c_void, len: c_uint, timeout: c_uint, nonblock: c_int) c_int; -pub extern fn sceNetAdhocPdpRecv(id: c_int, srcMacAddr: [*c]u8, port: [*c]c_ushort, data: ?*c_void, dataLength: ?*c_void, timeout: c_uint, nonblock: c_int) c_int; +pub extern fn sceNetAdhocPdpSend(id: c_int, destMacAddr: [*c]u8, port: c_ushort, data: ?*anyopaque, len: c_uint, timeout: c_uint, nonblock: c_int) c_int; +pub extern fn sceNetAdhocPdpRecv(id: c_int, srcMacAddr: [*c]u8, port: [*c]c_ushort, data: ?*anyopaque, dataLength: ?*anyopaque, timeout: c_uint, nonblock: c_int) c_int; pub const struct_pdpStatStruct = extern struct { next: [*c]struct_pdpStatStruct, pdpId: c_int, @@ -28,8 +28,8 @@ pub const struct_pdpStatStruct = extern struct { }; pub const pdpStatStruct = struct_pdpStatStruct; pub extern fn sceNetAdhocGetPdpStat(size: [*c]c_int, stat: [*c]pdpStatStruct) c_int; -pub extern fn sceNetAdhocGameModeCreateMaster(data: ?*c_void, size: c_int) c_int; -pub extern fn sceNetAdhocGameModeCreateReplica(mac: [*c]u8, data: ?*c_void, size: c_int) c_int; +pub extern fn sceNetAdhocGameModeCreateMaster(data: ?*anyopaque, size: c_int) c_int; +pub extern fn sceNetAdhocGameModeCreateReplica(mac: [*c]u8, data: ?*anyopaque, size: c_int) c_int; pub extern fn sceNetAdhocGameModeUpdateMaster() c_int; pub extern fn sceNetAdhocGameModeUpdateReplica(id: c_int, unk1: c_int) c_int; pub extern fn sceNetAdhocGameModeDeleteMaster() c_int; @@ -38,8 +38,8 @@ pub extern fn sceNetAdhocPtpOpen(srcmac: [*c]u8, srcport: c_ushort, destmac: [*c pub extern fn sceNetAdhocPtpConnect(id: c_int, timeout: c_uint, nonblock: c_int) c_int; pub extern fn sceNetAdhocPtpListen(srcmac: [*c]u8, srcport: c_ushort, bufsize: c_uint, delay: c_uint, count: c_int, queue: c_int, unk1: c_int) c_int; pub extern fn sceNetAdhocPtpAccept(id: c_int, mac: [*c]u8, port: [*c]c_ushort, timeout: c_uint, nonblock: c_int) c_int; -pub extern fn sceNetAdhocPtpSend(id: c_int, data: ?*c_void, datasize: [*c]c_int, timeout: c_uint, nonblock: c_int) c_int; -pub extern fn sceNetAdhocPtpRecv(id: c_int, data: ?*c_void, datasize: [*c]c_int, timeout: c_uint, nonblock: c_int) c_int; +pub extern fn sceNetAdhocPtpSend(id: c_int, data: ?*anyopaque, datasize: [*c]c_int, timeout: c_uint, nonblock: c_int) c_int; +pub extern fn sceNetAdhocPtpRecv(id: c_int, data: ?*anyopaque, datasize: [*c]c_int, timeout: c_uint, nonblock: c_int) c_int; pub extern fn sceNetAdhocPtpFlush(id: c_int, timeout: c_uint, nonblock: c_int) c_int; pub extern fn sceNetAdhocPtpClose(id: c_int, unk1: c_int) c_int; pub const struct_ptpStatStruct = extern struct { @@ -98,18 +98,18 @@ pub extern fn sceNetAdhocctlCreateEnterGameMode(name: [*c]const u8, unknown: c_i pub extern fn sceNetAdhocctlJoinEnterGameMode(name: [*c]const u8, hostmac: [*c]u8, timeout: c_uint, unknown: c_int) c_int; pub extern fn sceNetAdhocctlGetGameModeInfo(gamemodeinfo: [*c]struct_SceNetAdhocctlGameModeInfo) c_int; pub extern fn sceNetAdhocctlExitGameMode() c_int; -pub extern fn sceNetAdhocctlGetPeerList(length: [*c]c_int, buf: ?*c_void) c_int; +pub extern fn sceNetAdhocctlGetPeerList(length: [*c]c_int, buf: ?*anyopaque) c_int; 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: ?*c_void) c_int; -pub const sceNetAdhocctlHandler = ?fn (c_int, c_int, ?*c_void) callconv(.C) void; -pub extern fn sceNetAdhocctlAddHandler(handler: sceNetAdhocctlHandler, unknown: ?*c_void) c_int; +pub extern fn sceNetAdhocctlGetScanInfo(length: [*c]c_int, buf: ?*anyopaque) c_int; +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; -pub extern fn sceNetAdhocctlGetAddrByName(nickname: [*c]u8, length: [*c]c_int, buf: ?*c_void) c_int; +pub extern fn sceNetAdhocctlGetAddrByName(nickname: [*c]u8, length: [*c]c_int, buf: ?*anyopaque) c_int; pub extern fn sceNetAdhocctlGetParameter(params: [*c]struct_SceNetAdhocctlParams) c_int; -pub const enum_pspAdhocMatchingEvents = extern enum(c_int) { +pub const enum_pspAdhocMatchingEvents = enum(c_int) { PSP_ADHOC_MATCHING_EVENT_HELLO = 1, PSP_ADHOC_MATCHING_EVENT_JOIN = 2, PSP_ADHOC_MATCHING_EVENT_LEFT = 3, @@ -126,7 +126,7 @@ pub const enum_pspAdhocMatchingEvents = extern enum(c_int) { _, }; -pub const enum_pspAdhocMatchingModes = extern enum(c_int) { +pub const enum_pspAdhocMatchingModes = enum(c_int) { PSP_ADHOC_MATCHING_MODE_HOST = 1, PSP_ADHOC_MATCHING_MODE_CLIENT = 2, PSP_ADHOC_MATCHING_MODE_PTP = 3, @@ -144,19 +144,19 @@ 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, ?*c_void) 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: ?*c_void) 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; pub extern fn sceNetAdhocMatchingStop(matchingid: c_int) c_int; -pub extern fn sceNetAdhocMatchingSelectTarget(matchingid: c_int, mac: [*c]u8, optlen: c_int, optdata: ?*c_void) c_int; +pub extern fn sceNetAdhocMatchingSelectTarget(matchingid: c_int, mac: [*c]u8, optlen: c_int, optdata: ?*anyopaque) c_int; pub extern fn sceNetAdhocMatchingCancelTarget(matchingid: c_int, mac: [*c]u8) c_int; -pub extern fn sceNetAdhocMatchingCancelTargetWithOpt(matchingid: c_int, mac: [*c]u8, optlen: c_int, optdata: ?*c_void) c_int; -pub extern fn sceNetAdhocMatchingSendData(matchingid: c_int, mac: [*c]u8, datalen: c_int, data: ?*c_void) c_int; +pub extern fn sceNetAdhocMatchingCancelTargetWithOpt(matchingid: c_int, mac: [*c]u8, optlen: c_int, optdata: ?*anyopaque) c_int; +pub extern fn sceNetAdhocMatchingSendData(matchingid: c_int, mac: [*c]u8, datalen: c_int, data: ?*anyopaque) c_int; pub extern fn sceNetAdhocMatchingAbortSendData(matchingid: c_int, mac: [*c]u8) c_int; -pub extern fn sceNetAdhocMatchingSetHelloOpt(matchingid: c_int, optlen: c_int, optdata: ?*c_void) c_int; -pub extern fn sceNetAdhocMatchingGetHelloOpt(matchingid: c_int, optlen: [*c]c_int, optdata: ?*c_void) c_int; -pub extern fn sceNetAdhocMatchingGetMembers(matchingid: c_int, length: [*c]c_int, buf: ?*c_void) c_int; +pub extern fn sceNetAdhocMatchingSetHelloOpt(matchingid: c_int, optlen: c_int, optdata: ?*anyopaque) c_int; +pub extern fn sceNetAdhocMatchingGetHelloOpt(matchingid: c_int, optlen: [*c]c_int, optdata: ?*anyopaque) c_int; +pub extern fn sceNetAdhocMatchingGetMembers(matchingid: c_int, length: [*c]c_int, buf: ?*anyopaque) c_int; pub extern fn sceNetAdhocMatchingGetPoolMaxAlloc() c_int; pub extern fn sceNetAdhocMatchingGetPoolStat(poolstat: [*c]struct_pspAdhocPoolStat) c_int; @@ -181,11 +181,11 @@ pub const union_SceNetApctlInfo = extern union { startBrowser: c_uint, wifisp: c_uint, }; -pub const sceNetApctlHandler = ?fn (c_int, c_int, c_int, c_int, ?*c_void) 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; -pub extern fn sceNetApctlAddHandler(handler: sceNetApctlHandler, pArg: ?*c_void) c_int; +pub extern fn sceNetApctlAddHandler(handler: sceNetApctlHandler, pArg: ?*anyopaque) c_int; pub extern fn sceNetApctlDelHandler(handlerId: c_int) c_int; pub extern fn sceNetApctlConnect(connIndex: c_int) c_int; pub extern fn sceNetApctlDisconnect() c_int; @@ -194,7 +194,7 @@ pub extern fn sceNetApctlGetState(pState: [*c]c_int) c_int; pub extern fn sceNetInetInit() c_int; pub extern fn sceNetInetTerm() c_int; -pub const ApctlState = extern enum(c_int) { +pub const ApctlState = enum(c_int) { Disconnected, Scanning, Joining, @@ -204,7 +204,7 @@ pub const ApctlState = extern enum(c_int) { KeyExchange, }; -pub const ApctlEvent = extern enum(c_int) { +pub const ApctlEvent = enum(c_int) { ConnectRequest, ScanRequest, ScanComplete, @@ -218,7 +218,7 @@ pub const ApctlEvent = extern enum(c_int) { Reconnect, }; -pub const ApctlInfo = extern enum(c_int) { +pub const ApctlInfo = enum(c_int) { ProfileName, Bssid, Ssid, @@ -240,7 +240,7 @@ pub const ApctlInfo = extern enum(c_int) { Wifisp, }; -pub const ApctlInfoSecurityType = extern enum(c_int) { +pub const ApctlInfoSecurityType = enum(c_int) { None, Wep, Wpa, @@ -270,13 +270,13 @@ pub const sockaddr = struct_sockaddr; pub extern fn sceNetInetAccept(s: c_int, addr: [*c]struct_sockaddr, addrlen: [*c]socklen_t) c_int; pub extern fn sceNetInetBind(s: c_int, my_addr: [*c]const struct_sockaddr, addrlen: socklen_t) c_int; pub extern fn sceNetInetConnect(s: c_int, serv_addr: [*c]const struct_sockaddr, addrlen: socklen_t) c_int; -pub extern fn sceNetInetGetsockopt(s: c_int, level: c_int, optname: c_int, optval: ?*c_void, optlen: [*c]socklen_t) c_int; +pub extern fn sceNetInetGetsockopt(s: c_int, level: c_int, optname: c_int, optval: ?*anyopaque, optlen: [*c]socklen_t) c_int; pub extern fn sceNetInetListen(s: c_int, backlog: c_int) c_int; -pub extern fn sceNetInetRecv(s: c_int, buf: ?*c_void, len: u32, flags: c_int) u32; -pub extern fn sceNetInetRecvfrom(s: c_int, buf: ?*c_void, flags: u32, c_int, from: [*c]struct_sockaddr, fromlen: [*c]socklen_t) u32; -pub extern fn sceNetInetSend(s: c_int, buf: ?*const c_void, len: u32, flags: c_int) u32; -pub extern fn sceNetInetSendto(s: c_int, buf: ?*const c_void, len: u32, flags: c_int, to: [*c]const struct_sockaddr, tolen: socklen_t) u32; -pub extern fn sceNetInetSetsockopt(s: c_int, level: c_int, optname: c_int, optval: ?*const c_void, optlen: socklen_t) c_int; +pub extern fn sceNetInetRecv(s: c_int, buf: ?*anyopaque, len: u32, flags: c_int) u32; +pub extern fn sceNetInetRecvfrom(s: c_int, buf: ?*anyopaque, flags: u32, c_int, from: [*c]struct_sockaddr, fromlen: [*c]socklen_t) u32; +pub extern fn sceNetInetSend(s: c_int, buf: ?*const anyopaque, len: u32, flags: c_int) u32; +pub extern fn sceNetInetSendto(s: c_int, buf: ?*const anyopaque, len: u32, flags: c_int, to: [*c]const struct_sockaddr, tolen: socklen_t) u32; +pub extern fn sceNetInetSetsockopt(s: c_int, level: c_int, optname: c_int, optval: ?*const anyopaque, optlen: socklen_t) c_int; pub extern fn sceNetInetShutdown(s: c_int, how: c_int) c_int; pub extern fn sceNetInetSocket(domain: c_int, type: c_int, protocol: c_int) c_int; pub extern fn sceNetInetClose(s: c_int) c_int; @@ -287,8 +287,10 @@ pub const struct_in_addr = packed struct { s_addr: in_addr_t, }; +const SceSize = @import("psptypes.zig").SceSize; + pub extern fn sceNetResolverInit() c_int; -pub extern fn sceNetResolverCreate(rid: [*c]c_int, buf: ?*c_void, buflen: SceSize) c_int; +pub extern fn sceNetResolverCreate(rid: [*c]c_int, buf: ?*anyopaque, buflen: SceSize) c_int; pub extern fn sceNetResolverDelete(rid: c_int) c_int; pub extern fn sceNetResolverStartNtoA(rid: c_int, hostname: [*c]const u8, addr: [*c]struct_in_addr, timeout: c_uint, retry: c_int) c_int; pub extern fn sceNetResolverStartAtoN(rid: c_int, addr: [*c]const struct_in_addr, hostname: [*c]u8, hostname_len: SceSize, timeout: c_uint, retry: c_int) c_int; diff --git a/src/psp/sdk/psppower.zig b/src/psp/sdk/psppower.zig index c9fb836..f23fa17 100644 --- a/src/psp/sdk/psppower.zig +++ b/src/psp/sdk/psppower.zig @@ -1,6 +1,11 @@ -usingnamespace @import("psptypes.zig"); - -pub const PSPPowerCB = extern enum(u32) { +const psptypes = @import("psptypes.zig"); +const SceUID = psptypes.SceUID; +const SceSize = psptypes.SceSize; +const SceVoid = psptypes.SceVoid; +const SceInt32 = psptypes.SceInt32; +const SceUInt32 = psptypes.SceUInt32; + +pub const PSPPowerCB = enum(u32) { Battpower = 0x0000007f, BatteryExist = 0x00000080, BatteryLow = 0x00000100, @@ -13,11 +18,9 @@ pub const PSPPowerCB = extern enum(u32) { PowerSwitch = 0x80000000, }; -pub const PSPPowerTick = extern enum(u32) { - All = 0, Suspend = 1, Display = 6 -}; +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 // @@ -27,7 +30,7 @@ pub const powerCallback_t = ?fn (c_int, c_int) callconv(.C) void; // @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); + const res = scePowerRegisterCallback(slot, cbid); if (res < 0) { return error.Unexpected; } @@ -41,7 +44,7 @@ pub fn powerRegisterCallback(slot: c_int, cbid: SceUID) !i32 { // @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); + const res = scePowerUnregisterCallback(slot); if (res < 0) { return error.Unexpected; } @@ -52,7 +55,7 @@ pub fn powerUnregisterCallback(slot: c_int) !void { // @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(); + const res = scePowerIsPowerOnline(); if (res < 0) { return error.Unexpected; } @@ -64,7 +67,7 @@ pub fn powerIsPowerOnline() !bool { // @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(); + const res = scePowerIsBatteryExist(); if (res < 0) { return error.Unexpected; } @@ -76,7 +79,7 @@ pub fn powerIsBatteryExist() !bool { // @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(); + const res = scePowerIsBatteryCharging(); if (res < 0) { return error.Unexpected; } @@ -91,7 +94,7 @@ pub extern fn scePowerGetBatteryChargingStatus() c_int; // @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(); + const res = scePowerIsLowBattery(); if (res < 0) { return error.Unexpected; } @@ -103,7 +106,7 @@ pub fn powerIsLowBattery() !bool { // @return Battery charge percentage (0-100), < 0 on error. pub extern fn scePowerGetBatteryLifePercent() c_int; pub fn powerGetBatteryLifePercent() !i32 { - var res = scePowerGetBatteryLifePercent(); + const res = scePowerGetBatteryLifePercent(); if (res < 0) { return error.Unexpected; } @@ -115,7 +118,7 @@ pub fn powerGetBatteryLifePercent() !i32 { // @return Battery life in minutes, < 0 on error. pub extern fn scePowerGetBatteryLifeTime() c_int; pub fn powerGetBatteryLifeTime() !i32 { - var res = scePowerGetBatteryLifeTime(); + const res = scePowerGetBatteryLifeTime(); if (res < 0) { return error.Unexpected; } @@ -183,7 +186,7 @@ pub extern fn scePowerSetClockFrequency(pllfreq: c_int, cpufreq: c_int, busfreq: // @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); + const res = scePowerLock(unknown); if (res < 0) { return error.Unexpected; } @@ -196,7 +199,7 @@ pub fn powerLock(unknown: c_int) !void { // @return 0 on success, < 0 on error. pub extern fn scePowerUnlock(unknown: c_int) c_int; pub fn powerUnlock(unknown: c_int) !void { - var res = scePowerUnlock(unknown); + const res = scePowerUnlock(unknown); if (res < 0) { return error.Unexpected; } @@ -210,7 +213,7 @@ pub fn powerUnlock(unknown: c_int) !void { // @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)); + const res = scePowerTick(@intFromEnum(typec)); if (res < 0) { return error.Unexpected; } diff --git a/src/psp/sdk/pspreg.zig b/src/psp/sdk/pspreg.zig index 0134052..0a163fd 100644 --- a/src/psp/sdk/pspreg.zig +++ b/src/psp/sdk/pspreg.zig @@ -1,6 +1,7 @@ -usingnamespace @import("psptypes.zig"); +const psptypes = @import("psptypes.zig"); +const SceSize = psptypes.SceSize; -pub const RegKeyTypes = extern enum(c_int) { +pub const RegKeyTypes = enum(c_int) { REG_TYPE_DIR = 1, REG_TYPE_INT = 2, REG_TYPE_STR = 3, @@ -25,7 +26,7 @@ pub const RegParam = extern struct { // @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); + const res = sceRegOpenRegistry(reg, mode, h); if (res < 0) { return error.Unexpected; } @@ -38,7 +39,7 @@ pub fn regOpenRegistry(reg: *RegParam, mode: c_int, h: *RegHandle) !void { // @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); + const res = sceRegFlushRegistry(h); if (res < 0) { return error.Unexpected; } @@ -51,7 +52,7 @@ pub fn regFlushRegistry(h: *RegHandle) !void { // @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); + const res = sceRegCloseRegistry(h); if (res < 0) { return error.Unexpected; } @@ -67,7 +68,7 @@ pub fn regCloseRegistry(h: RegHandle) !void { // @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); + const res = sceRegOpenCategory(h, name, mode, hd); if (res < 0) { return error.Unexpected; } @@ -81,7 +82,7 @@ pub fn regOpenCategory(h: RegHandle, name: []const u8, mode: c_int, hd: *RegHand // @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); + const res = sceRegRemoveCategory(h, name); if (res < 0) { return error.Unexpected; } @@ -94,7 +95,7 @@ pub fn regRemoveCategory(h: RegHandle, name: []const u8) !void { // @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); + const res = sceRegCloseCategory(hd); if (res < 0) { return error.Unexpected; } @@ -107,7 +108,7 @@ pub fn regCloseCategory(hd: RegHandle) !void { // @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); + const res = sceRegFlushCategory(hd); if (res < 0) { return error.Unexpected; } @@ -124,7 +125,7 @@ pub fn regFlushCategory(hd: RegHandle) !void { // @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); + const res = sceRegGetKeyInfo(hd, name, hk, typec, size); if (res < 0) { return error.Unexpected; } @@ -140,7 +141,7 @@ pub fn regGetKeyInfo(hd: RegHandle, name: []const u8, hk: *RegHandle, typec: *c_ // @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); + const res = sceRegGetKeyInfoByName(hd, name, typec, size); if (res < 0) { return error.Unexpected; } @@ -154,9 +155,9 @@ pub fn regGetKeyInfoByName(hd: RegHandle, name: []const u8, typec: *c_uint, size // @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); +pub extern fn sceRegGetKeyValue(hd: RegHandle, hk: RegHandle, buf: ?*anyopaque, size: SceSize) c_int; +pub fn regGetKeyValue(hd: RegHandle, hk: RegHandle, buf: ?*anyopaque, size: SceSize) !void { + const res = sceRegGetKeyValue(hd, hk, buf, size); if (res < 0) { return error.Unexpected; } @@ -170,9 +171,9 @@ pub fn regGetKeyValue(hd: RegHandle, hk: RegHandle, buf: ?*c_void, size: SceSize // @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); +pub extern fn sceRegGetKeyValueByName(hd: RegHandle, name: []const u8, buf: ?*anyopaque, size: SceSize) c_int; +pub fn regGetKeyValueByName(hd: RegHandle, name: []const u8, buf: ?*anyopaque, size: SceSize) !void { + const res = sceRegGetKeyValueByName(hd, name, buf, size); if (res < 0) { return error.Unexpected; } @@ -186,9 +187,9 @@ pub fn regGetKeyValueByName(hd: RegHandle, name: []const u8, buf: ?*c_void, size // @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); +pub extern fn sceRegSetKeyValue(hd: RegHandle, name: []const u8, buf: ?*const anyopaque, size: SceSize) c_int; +pub fn regSetKeyValue(hd: RegHandle, name: []const u8, buf: ?*const anyopaque, size: SceSize) !void { + const res = sceRegSetKeyValue(hd, name, buf, size); if (res < 0) { return error.Unexpected; } @@ -202,7 +203,7 @@ pub fn regSetKeyValue(hd: RegHandle, name: []const u8, buf: ?*const c_void, size // @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); + const res = sceRegGetKeysNum(hd, num); if (res < 0) { return error.Unexpected; } @@ -217,7 +218,7 @@ pub fn regGetKeysNum(hd: RegHandle, num: *c_int) !void { // @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); + const res = sceRegGetKeys(hd, buf, num); if (res < 0) { return error.Unexpected; } @@ -233,7 +234,7 @@ pub fn regGetKeys(hd: RegHandle, buf: [*]u8, num: c_int) !void { // @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); + const res = sceRegCreateKey(hd, name, typec, size); if (res < 0) { return error.Unexpected; } @@ -246,7 +247,7 @@ pub fn regCreateKey(hd: RegHandle, name: []const u8, typec: c_int, size: SceSize // @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); + const res = sceRegRemoveRegistry(reg); if (res < 0) { return error.Unexpected; } diff --git a/src/psp/sdk/psprtc.zig b/src/psp/sdk/psprtc.zig index b75fc17..68dafe5 100644 --- a/src/psp/sdk/psprtc.zig +++ b/src/psp/sdk/psprtc.zig @@ -12,7 +12,7 @@ const struct_unnamed_5 = extern struct { }; pub const pspTime = struct_unnamed_5; -pub const enum_pspRtcCheckValidErrors = extern enum(c_int) { +pub const enum_pspRtcCheckValidErrors = enum(c_int) { PSP_TIME_INVALID_YEAR = -1, PSP_TIME_INVALID_MONTH = -2, PSP_TIME_INVALID_DAY = -3, diff --git a/src/psp/sdk/pspstdio.zig b/src/psp/sdk/pspstdio.zig index e2a43e5..8a70f27 100644 --- a/src/psp/sdk/pspstdio.zig +++ b/src/psp/sdk/pspstdio.zig @@ -1,4 +1,5 @@ -usingnamespace @import("psptypes.zig"); +const psptypes = @import("psptypes.zig"); +const SceUID = psptypes.SceUID; // Function to get the current standard in file no // diff --git a/src/psp/sdk/pspsysmem.zig b/src/psp/sdk/pspsysmem.zig index 9ad06ec..e7ee7ac 100644 --- a/src/psp/sdk/pspsysmem.zig +++ b/src/psp/sdk/pspsysmem.zig @@ -1,6 +1,12 @@ -usingnamespace @import("psptypes.zig"); +const psptypes = @import("psptypes.zig"); +const SceUID = psptypes.SceUID; +const SceSize = psptypes.SceSize; +const SceVoid = psptypes.SceVoid; +const ScePVoid = psptypes.ScePVoid; +const SceInt32 = psptypes.SceInt32; +const SceUInt32 = psptypes.SceUInt32; -pub const PspSysMemBlockTypes = extern enum(c_int) { +pub const PspSysMemBlockTypes = enum(c_int) { MemLow = 0, MemHigh = 1, MemAddr = 2, @@ -16,10 +22,10 @@ pub const SceKernelSysMemAlloc_t = c_int; // @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 extern fn sceKernelAllocPartitionMemory(partitionid: SceUID, name: [*c]const u8, typec: c_int, size: SceSize, addr: ?*anyopaque) 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); +pub fn kernelAllocPartitionMemory(partitionid: SceUID, name: [*c]const u8, typec: c_int, size: SceSize, addr: ?*anyopaque) !SceUID { + const res = sceKernelAllocPartitionMemory(partitionid, name, typec, size, addr); if (res < 0) { return error.AllocationError; } @@ -38,7 +44,7 @@ pub extern fn sceKernelFreePartitionMemory(blockid: SceUID) c_int; // @param blockid - UID of the memory block. // // @return The lowest address belonging to the memory block. -pub extern fn sceKernelGetBlockHeadAddr(blockid: SceUID) ?*c_void; +pub extern fn sceKernelGetBlockHeadAddr(blockid: SceUID) ?*anyopaque; // Get the total amount of free memory. // @@ -70,7 +76,7 @@ pub extern fn sceKernelDevkitVersion() c_int; // @return 0 on success, < 0 on error. pub extern fn sceKernelSetCompiledSdkVersion(version: c_int) c_int; pub fn kernelSetCompiledSdkVersion(version: c_int) !void { - var res = sceKernelSetCompiledSdkVersion(version); + const res = sceKernelSetCompiledSdkVersion(version); if (res < 0) { return error.Unexpected; } diff --git a/src/psp/sdk/pspthreadman.zig b/src/psp/sdk/pspthreadman.zig index f5aefe3..8bd3afe 100644 --- a/src/psp/sdk/pspthreadman.zig +++ b/src/psp/sdk/pspthreadman.zig @@ -1,4 +1,14 @@ -usingnamespace @import("psptypes.zig"); +const psptypes = @import("psptypes.zig"); +const SceUID = psptypes.SceUID; +const SceSize = psptypes.SceSize; +const SceVoid = psptypes.SceVoid; +const SceUInt = psptypes.SceUInt; +const SceInt32 = psptypes.SceInt32; +const SceInt64 = psptypes.SceInt64; +const SceUInt32 = psptypes.SceUInt32; +const SceShort16 = psptypes.SceShort16; +const SceUChar = psptypes.SceUChar; +const SceUChar8 = psptypes.SceUChar8; pub const struct_SceKernelSysClock = extern struct { low: SceUInt32, @@ -6,7 +16,7 @@ pub const struct_SceKernelSysClock = extern struct { }; pub const SceKernelSysClock = struct_SceKernelSysClock; -pub const enum_PspThreadAttributes = extern enum(u32) { +pub const enum_PspThreadAttributes = enum(u32) { PSP_THREAD_ATTR_VFPU = 16384, PSP_THREAD_ATTR_USER = 2147483648, PSP_THREAD_ATTR_USBWLAN = 2684354560, @@ -16,7 +26,7 @@ pub const enum_PspThreadAttributes = extern enum(u32) { PSP_THREAD_ATTR_CLEAR_STACK = 2097152, _, }; -pub const SceKernelThreadEntry = ?fn (SceSize, ?*c_void) callconv(.C) c_int; +pub const SceKernelThreadEntry = ?*const fn (SceSize, ?*anyopaque) callconv(.C) c_int; pub const struct_SceKernelThreadOptParam = extern struct { size: SceSize, stackMpid: SceUID, @@ -28,9 +38,9 @@ pub const struct_SceKernelThreadInfo = extern struct { attr: SceUInt, status: c_int, entry: SceKernelThreadEntry, - stack: ?*c_void, + stack: ?*anyopaque, stackSize: c_int, - gpReg: ?*c_void, + gpReg: ?*anyopaque, initPriority: c_int, currentPriority: c_int, waitType: c_int, @@ -56,7 +66,7 @@ pub const struct_SceKernelThreadRunStatus = extern struct { releaseCount: SceUInt, }; pub const SceKernelThreadRunStatus = struct_SceKernelThreadRunStatus; -pub const enum_PspThreadStatus = extern enum(c_int) { +pub const enum_PspThreadStatus = enum(c_int) { PSP_THREAD_RUNNING = 1, PSP_THREAD_READY = 2, PSP_THREAD_WAITING = 4, @@ -65,8 +75,9 @@ pub const enum_PspThreadStatus = extern enum(c_int) { PSP_THREAD_KILLED = 32, _, }; + pub extern fn sceKernelDeleteThread(thid: SceUID) c_int; -pub extern fn sceKernelStartThread(thid: SceUID, arglen: SceSize, argp: ?*c_void) c_int; +pub extern fn sceKernelStartThread(thid: SceUID, arglen: SceSize, argp: ?*anyopaque) c_int; pub extern fn sceKernelExitThread(status: c_int) c_int; pub extern fn sceKernelExitDeleteThread(status: c_int) c_int; pub extern fn sceKernelTerminateThread(thid: SceUID) c_int; @@ -130,11 +141,11 @@ pub const struct_SceKernelEventFlagOptParam = extern struct { size: SceSize, }; pub const SceKernelEventFlagOptParam = struct_SceKernelEventFlagOptParam; -pub const enum_PspEventFlagAttributes = extern enum(c_int) { +pub const enum_PspEventFlagAttributes = enum(c_int) { PSP_EVENT_WAITMULTIPLE = 512, _, }; -pub const enum_PspEventFlagWaitTypes = extern enum(c_int) { +pub const enum_PspEventFlagWaitTypes = enum(c_int) { PSP_EVENT_WAITAND = 0, PSP_EVENT_WAITOR = 1, PSP_EVENT_WAITCLEAR = 32, @@ -158,7 +169,7 @@ pub const struct_SceKernelMbxInfo = extern struct { attr: SceUInt, numWaitThreads: c_int, numMessages: c_int, - firstMessage: ?*c_void, + firstMessage: ?*anyopaque, }; pub const SceKernelMbxInfo = struct_SceKernelMbxInfo; pub const struct_SceKernelMsgPacket = extern struct { @@ -169,43 +180,43 @@ pub const struct_SceKernelMsgPacket = extern struct { pub const SceKernelMsgPacket = struct_SceKernelMsgPacket; pub extern fn sceKernelCreateMbx(name: [*c]const u8, attr: SceUInt, option: [*c]SceKernelMbxOptParam) SceUID; pub extern fn sceKernelDeleteMbx(mbxid: SceUID) c_int; -pub extern fn sceKernelSendMbx(mbxid: SceUID, message: ?*c_void) c_int; -pub extern fn sceKernelReceiveMbx(mbxid: SceUID, pmessage: [*c]?*c_void, timeout: [*c]SceUInt) c_int; -pub extern fn sceKernelReceiveMbxCB(mbxid: SceUID, pmessage: [*c]?*c_void, timeout: [*c]SceUInt) c_int; -pub extern fn sceKernelPollMbx(mbxid: SceUID, pmessage: [*c]?*c_void) c_int; +pub extern fn sceKernelSendMbx(mbxid: SceUID, message: ?*anyopaque) c_int; +pub extern fn sceKernelReceiveMbx(mbxid: SceUID, pmessage: [*c]?*anyopaque, timeout: [*c]SceUInt) c_int; +pub extern fn sceKernelReceiveMbxCB(mbxid: SceUID, pmessage: [*c]?*anyopaque, timeout: [*c]SceUInt) c_int; +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 (?*c_void) callconv(.C) SceUInt; +pub const SceKernelAlarmHandler = ?*const fn (?*anyopaque) callconv(.C) SceUInt; pub const struct_SceKernelAlarmInfo = extern struct { size: SceSize, schedule: SceKernelSysClock, handler: SceKernelAlarmHandler, - common: ?*c_void, + common: ?*anyopaque, }; pub const SceKernelAlarmInfo = struct_SceKernelAlarmInfo; -pub extern fn sceKernelSetAlarm(clock: SceUInt, handler: SceKernelAlarmHandler, common: ?*c_void) SceUID; -pub extern fn sceKernelSetSysClockAlarm(clock: [*c]SceKernelSysClock, handler: SceKernelAlarmHandler, common: ?*c_void) SceUID; +pub extern fn sceKernelSetAlarm(clock: SceUInt, handler: SceKernelAlarmHandler, common: ?*anyopaque) SceUID; +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, ?*c_void) 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, threadId: SceUID, callback: SceKernelCallbackFunction, - common: ?*c_void, + common: ?*anyopaque, notifyCount: c_int, notifyArg: c_int, }; pub const SceKernelCallbackInfo = struct_SceKernelCallbackInfo; -pub extern fn sceKernelCreateCallback(name: [*c]const u8, func: SceKernelCallbackFunction, arg: ?*c_void) c_int; +pub extern fn sceKernelCreateCallback(name: [*c]const u8, func: SceKernelCallbackFunction, arg: ?*anyopaque) c_int; pub extern fn sceKernelReferCallbackStatus(cb: SceUID, status: [*c]SceKernelCallbackInfo) c_int; pub extern fn sceKernelDeleteCallback(cb: SceUID) c_int; pub extern fn sceKernelNotifyCallback(cb: SceUID, arg2: c_int) c_int; pub extern fn sceKernelCancelCallback(cb: SceUID) c_int; pub extern fn sceKernelGetCallbackCount(cb: SceUID) c_int; pub extern fn sceKernelCheckCallback() c_int; -pub const enum_SceKernelIdListType = extern enum(c_int) { +pub const enum_SceKernelIdListType = enum(c_int) { SCE_KERNEL_TMID_Thread = 1, SCE_KERNEL_TMID_Semaphore = 2, SCE_KERNEL_TMID_EventFlag = 3, @@ -234,14 +245,14 @@ pub const struct_SceKernelSystemStatus = extern struct { }; pub const SceKernelSystemStatus = struct_SceKernelSystemStatus; pub extern fn sceKernelReferSystemStatus(status: [*c]SceKernelSystemStatus) c_int; -pub extern fn sceKernelCreateMsgPipe(name: [*c]const u8, part: c_int, attr: c_int, unk1: ?*c_void, opt: ?*c_void) SceUID; +pub extern fn sceKernelCreateMsgPipe(name: [*c]const u8, part: c_int, attr: c_int, unk1: ?*anyopaque, opt: ?*anyopaque) SceUID; pub extern fn sceKernelDeleteMsgPipe(uid: SceUID) c_int; -pub extern fn sceKernelSendMsgPipe(uid: SceUID, message: ?*c_void, size: c_uint, unk1: c_int, unk2: ?*c_void, timeout: [*c]c_uint) c_int; -pub extern fn sceKernelSendMsgPipeCB(uid: SceUID, message: ?*c_void, size: c_uint, unk1: c_int, unk2: ?*c_void, timeout: [*c]c_uint) c_int; -pub extern fn sceKernelTrySendMsgPipe(uid: SceUID, message: ?*c_void, size: c_uint, unk1: c_int, unk2: ?*c_void) c_int; -pub extern fn sceKernelReceiveMsgPipe(uid: SceUID, message: ?*c_void, size: c_uint, unk1: c_int, unk2: ?*c_void, timeout: [*c]c_uint) c_int; -pub extern fn sceKernelReceiveMsgPipeCB(uid: SceUID, message: ?*c_void, size: c_uint, unk1: c_int, unk2: ?*c_void, timeout: [*c]c_uint) c_int; -pub extern fn sceKernelTryReceiveMsgPipe(uid: SceUID, message: ?*c_void, size: c_uint, unk1: c_int, unk2: ?*c_void) c_int; +pub extern fn sceKernelSendMsgPipe(uid: SceUID, message: ?*anyopaque, size: c_uint, unk1: c_int, unk2: ?*anyopaque, timeout: [*c]c_uint) c_int; +pub extern fn sceKernelSendMsgPipeCB(uid: SceUID, message: ?*anyopaque, size: c_uint, unk1: c_int, unk2: ?*anyopaque, timeout: [*c]c_uint) c_int; +pub extern fn sceKernelTrySendMsgPipe(uid: SceUID, message: ?*anyopaque, size: c_uint, unk1: c_int, unk2: ?*anyopaque) c_int; +pub extern fn sceKernelReceiveMsgPipe(uid: SceUID, message: ?*anyopaque, size: c_uint, unk1: c_int, unk2: ?*anyopaque, timeout: [*c]c_uint) c_int; +pub extern fn sceKernelReceiveMsgPipeCB(uid: SceUID, message: ?*anyopaque, size: c_uint, unk1: c_int, unk2: ?*anyopaque, timeout: [*c]c_uint) c_int; +pub extern fn sceKernelTryReceiveMsgPipe(uid: SceUID, message: ?*anyopaque, size: c_uint, unk1: c_int, unk2: ?*anyopaque) c_int; pub extern fn sceKernelCancelMsgPipe(uid: SceUID, psend: [*c]c_int, precv: [*c]c_int) c_int; pub const struct_SceKernelMppInfo = extern struct { size: SceSize, @@ -259,10 +270,10 @@ pub const struct_SceKernelVplOptParam = extern struct { }; pub extern fn sceKernelCreateVpl(name: [*c]const u8, part: c_int, attr: c_int, size: c_uint, opt: [*c]struct_SceKernelVplOptParam) SceUID; pub extern fn sceKernelDeleteVpl(uid: SceUID) c_int; -pub extern fn sceKernelAllocateVpl(uid: SceUID, size: c_uint, data: [*c]?*c_void, timeout: [*c]c_uint) c_int; -pub extern fn sceKernelAllocateVplCB(uid: SceUID, size: c_uint, data: [*c]?*c_void, timeout: [*c]c_uint) c_int; -pub extern fn sceKernelTryAllocateVpl(uid: SceUID, size: c_uint, data: [*c]?*c_void) c_int; -pub extern fn sceKernelFreeVpl(uid: SceUID, data: ?*c_void) c_int; +pub extern fn sceKernelAllocateVpl(uid: SceUID, size: c_uint, data: [*c]?*anyopaque, timeout: [*c]c_uint) c_int; +pub extern fn sceKernelAllocateVplCB(uid: SceUID, size: c_uint, data: [*c]?*anyopaque, timeout: [*c]c_uint) c_int; +pub extern fn sceKernelTryAllocateVpl(uid: SceUID, size: c_uint, data: [*c]?*anyopaque) c_int; +pub extern fn sceKernelFreeVpl(uid: SceUID, data: ?*anyopaque) c_int; pub extern fn sceKernelCancelVpl(uid: SceUID, pnum: [*c]c_int) c_int; pub const struct_SceKernelVplInfo = extern struct { size: SceSize, @@ -279,10 +290,10 @@ pub const struct_SceKernelFplOptParam = extern struct { }; pub extern fn sceKernelCreateFpl(name: [*c]const u8, part: c_int, attr: c_int, size: c_uint, blocks: c_uint, opt: [*c]struct_SceKernelFplOptParam) c_int; pub extern fn sceKernelDeleteFpl(uid: SceUID) c_int; -pub extern fn sceKernelAllocateFpl(uid: SceUID, data: [*c]?*c_void, timeout: [*c]c_uint) c_int; -pub extern fn sceKernelAllocateFplCB(uid: SceUID, data: [*c]?*c_void, timeout: [*c]c_uint) c_int; -pub extern fn sceKernelTryAllocateFpl(uid: SceUID, data: [*c]?*c_void) c_int; -pub extern fn sceKernelFreeFpl(uid: SceUID, data: ?*c_void) c_int; +pub extern fn sceKernelAllocateFpl(uid: SceUID, data: [*c]?*anyopaque, timeout: [*c]c_uint) c_int; +pub extern fn sceKernelAllocateFplCB(uid: SceUID, data: [*c]?*anyopaque, timeout: [*c]c_uint) c_int; +pub extern fn sceKernelTryAllocateFpl(uid: SceUID, data: [*c]?*anyopaque) c_int; +pub extern fn sceKernelFreeFpl(uid: SceUID, data: ?*anyopaque) c_int; pub extern fn sceKernelCancelFpl(uid: SceUID, pnum: [*c]c_int) c_int; pub const struct_SceKernelFplInfo = extern struct { size: SceSize, @@ -317,10 +328,10 @@ 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, ?*c_void) callconv(.C) SceUInt; -pub const SceKernelVTimerHandlerWide = ?fn (SceUID, SceInt64, SceInt64, ?*c_void) callconv(.C) SceUInt; -pub extern fn sceKernelSetVTimerHandler(uid: SceUID, time: [*c]SceKernelSysClock, handler: SceKernelVTimerHandler, common: ?*c_void) c_int; -pub extern fn sceKernelSetVTimerHandlerWide(uid: SceUID, time: SceInt64, handler: SceKernelVTimerHandlerWide, common: ?*c_void) c_int; +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; pub const struct_SceKernelVTimerInfo = extern struct { size: SceSize, @@ -330,44 +341,44 @@ pub const struct_SceKernelVTimerInfo = extern struct { current: SceKernelSysClock, schedule: SceKernelSysClock, handler: SceKernelVTimerHandler, - common: ?*c_void, + common: ?*anyopaque, }; 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, ?*c_void) 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, threadId: SceUID, mask: c_int, handler: SceKernelThreadEventHandler, - common: ?*c_void, + common: ?*anyopaque, }; pub const SceKernelThreadEventHandlerInfo = struct_SceKernelThreadEventHandlerInfo; -pub const enum_ThreadEventIds = extern enum(c_int) { +pub const enum_ThreadEventIds = enum(c_int) { THREADEVENT_ALL = 4294967295, THREADEVENT_KERN = 4294967288, THREADEVENT_USER = 4294967280, THREADEVENT_CURRENT = 0, _, }; -pub const enum_ThreadEvents = extern enum(c_int) { +pub const enum_ThreadEvents = enum(c_int) { THREAD_CREATE = 1, THREAD_START = 2, THREAD_EXIT = 4, THREAD_DELETE = 8, _, }; -pub extern fn sceKernelRegisterThreadEventHandler(name: [*c]const u8, threadID: SceUID, mask: c_int, handler: SceKernelThreadEventHandler, common: ?*c_void) SceUID; +pub extern fn sceKernelRegisterThreadEventHandler(name: [*c]const u8, threadID: SceUID, mask: c_int, handler: SceKernelThreadEventHandler, common: ?*anyopaque) SceUID; pub extern fn sceKernelReleaseThreadEventHandler(uid: SceUID) c_int; pub extern fn sceKernelReferThreadEventHandlerStatus(uid: SceUID, info: [*c]struct_SceKernelThreadEventHandlerInfo) c_int; -pub extern fn sceKernelReferThreadProfiler() [*c]PspDebugProfilerRegs; -pub extern fn sceKernelReferGlobalProfiler() [*c]PspDebugProfilerRegs; +pub extern fn sceKernelReferThreadProfiler() [*c]psptypes.PspDebugProfilerRegs; +pub extern fn sceKernelReferGlobalProfiler() [*c]psptypes.PspDebugProfilerRegs; pub extern fn sceKernelCreateThread(name: [*c]const u8, entry: SceKernelThreadEntry, initPriority: c_int, stackSize: c_int, attr: SceUInt, option: [*c]SceKernelThreadOptParam) SceUID; -pub const PspModuleInfoAttr = enum_PspModuleInfoAttr; +pub const PspModuleInfoAttr = psptypes.enum_PspModuleInfoAttr; pub const PspThreadAttributes = enum_PspThreadAttributes; pub const PspThreadStatus = enum_PspThreadStatus; pub const PspEventFlagAttributes = enum_PspEventFlagAttributes; diff --git a/src/psp/sdk/psptypes.zig b/src/psp/sdk/psptypes.zig index c754547..62b84fb 100644 --- a/src/psp/sdk/psptypes.zig +++ b/src/psp/sdk/psptypes.zig @@ -1,38 +1,38 @@ pub fn _lb(arg_addr: u32) callconv(.C) u8 { - var addr = arg_addr; - return @intToPtr([*c]volatile vu8, addr).?.*; + const addr = arg_addr; + return @as([*c]volatile u8, @ptrFromInt(addr)).?.*; } pub fn _lh(arg_addr: u32) callconv(.C) u16 { - var addr = arg_addr; - return @intToPtr([*c]volatile vu16, addr).?.*; + const addr = arg_addr; + return @as([*c]volatile u16, @ptrFromInt(addr)).?.*; } pub fn _lw(arg_addr: u32) callconv(.C) u32 { - var addr = arg_addr; - return @intToPtr([*c]volatile vu32, addr).?.*; + const addr = arg_addr; + return @as([*c]volatile u32, @ptrFromInt(addr)).?.*; } pub fn _ld(arg_addr: u32) callconv(.C) u64 { - var addr = arg_addr; - return @intToPtr([*c]volatile vu64, addr).?.*; + const addr = arg_addr; + return @as([*c]volatile u64, @ptrFromInt(addr)).?.*; } pub fn _sb(arg_val: u8, arg_addr: u32) callconv(.C) void { - var val = arg_val; - var addr = arg_addr; - @intToPtr([*c]volatile vu8, addr).?.* = val; + const val = arg_val; + const addr = arg_addr; + @as([*c]volatile u8, @ptrFromInt(addr)).?.* = val; } pub fn _sh(arg_val: u16, arg_addr: u32) callconv(.C) void { - var val = arg_val; - var addr = arg_addr; - @intToPtr([*c]volatile vu16, addr).?.* = val; + const val = arg_val; + const addr = arg_addr; + @as([*c]volatile u16, @ptrFromInt(addr)).?.* = val; } pub fn _sw(arg_val: u32, arg_addr: u32) callconv(.C) void { - var val = arg_val; - var addr = arg_addr; - @intToPtr([*c]volatile vu32, addr).?.* = val; + const val = arg_val; + const addr = arg_addr; + @as([*c]volatile u32, @ptrFromInt(addr)).?.* = val; } pub fn _sd(arg_val: u64, arg_addr: u32) callconv(.C) void { - var val = arg_val; - var addr = arg_addr; - @intToPtr([*c]volatile vu64, addr).?.* = val; + const val = arg_val; + const addr = arg_addr; + @as([*c]volatile u64, @ptrFromInt(addr)).?.* = val; } pub const SceUChar8 = u8; @@ -50,8 +50,8 @@ pub const SceFloat32 = f32; pub const SceWChar16 = c_ushort; pub const SceWChar32 = c_uint; pub const SceBool = c_int; -pub const SceVoid = c_void; -pub const ScePVoid = ?*c_void; +pub const SceVoid = anyopaque; +pub const ScePVoid = ?*anyopaque; pub const ScePspSRect = extern struct { x: c_short, y: c_short, diff --git a/src/psp/sdk/pspumd.zig b/src/psp/sdk/pspumd.zig index 2e7d6e0..864e12f 100644 --- a/src/psp/sdk/pspumd.zig +++ b/src/psp/sdk/pspumd.zig @@ -3,13 +3,13 @@ pub const PspUmdInfo = extern struct { typec: c_uint, }; -pub const PspUmdTypes = extern enum(c_int) { +pub const PspUmdTypes = enum(c_int) { Game = 16, Video = 32, Audio = 64, }; -pub const PspUmdState = extern enum(c_int) { +pub const PspUmdState = enum(c_int) { NotPresent = 1, Present = 2, Changed = 4, @@ -18,11 +18,11 @@ pub const PspUmdState = extern enum(c_int) { Ready = 32, }; -pub const UmdDriveStat = extern enum(c_int) { +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 // @@ -36,7 +36,7 @@ pub extern fn sceUmdCheckMedium() c_int; // @return < 0 on error pub extern fn sceUmdGetDiscInfo(info: *PspUmdInfo) c_int; pub fn umdGetDiscInfo(info: *PspUmdInfo) !i32 { - var res = sceUmdGetDiscInfo(info); + const res = sceUmdGetDiscInfo(info); if (res < 0) { return error.Unexpected; } @@ -66,7 +66,7 @@ pub fn umdGetDiscInfo(info: *PspUmdInfo) !i32 { // @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); + const res = sceUmdActivate(unit, drive); if (res < 0) { return error.Unexpected; } @@ -82,7 +82,7 @@ pub fn umdActivate(unit: c_int, drive: []const u8) !i32 { // @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); + const res = sceUmdDeactivate(unit, drive); if (res < 0) { return error.Unexpected; } @@ -96,7 +96,7 @@ pub fn umdDeactivate(unit: c_int, drive: []const u8) !i32 { // @return < 0 on error pub extern fn sceUmdWaitDriveStat(stat: c_int) c_int; pub fn umdWaitDriveStat(stat: c_int) !i32 { - var res = sceUmdWaitDriveStat(stat); + const res = sceUmdWaitDriveStat(stat); if (res < 0) { return error.Unexpected; } @@ -112,7 +112,7 @@ pub fn umdWaitDriveStat(stat: c_int) !i32 { // @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); + const res = umdWaitDriveStatWithTimer(stat, timeout); if (res < 0) { return error.Unexpected; } @@ -128,7 +128,7 @@ pub fn umdWaitDriveStatWithTimer(stat: c_int, timeout: c_uint) !i32 { // @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); + const res = sceUmdWaitDriveStatCB(stat, timeout); if (res < 0) { return error.Unexpected; } @@ -140,7 +140,7 @@ pub fn umdWaitDriveStatCB(stat: c_int, timeout: c_uint) !i32 { //@return < 0 on error pub extern fn sceUmdCancelWaitDriveStat() c_int; pub fn umdCancelWaitDriveStat() !i32 { - var res = sceUmdCancelWaitDriveStat(); + const res = sceUmdCancelWaitDriveStat(); if (res < 0) { return error.Unexpected; } @@ -152,7 +152,7 @@ pub fn umdCancelWaitDriveStat() !i32 { // @return < 0 on error, one or more of ::pspUmdState on success pub extern fn sceUmdGetDriveStat() c_int; pub fn umdGetDriveStat() !i32 { - var res = sceUmdGetDriveStat(); + const res = sceUmdGetDriveStat(); if (res < 0) { return error.Unexpected; } @@ -180,7 +180,7 @@ pub extern fn sceUmdGetErrorStat() c_int; // @endcode pub extern fn sceUmdRegisterUMDCallBack(cbid: c_int) c_int; pub fn umdRegisterUMDCallBack(cbid: c_int) !i32 { - var res = sceUmdRegisterUMDCallBack(cbid); + const res = sceUmdRegisterUMDCallBack(cbid); if (res < 0) { return error.Unexpected; } @@ -194,7 +194,7 @@ pub fn umdRegisterUMDCallBack(cbid: c_int) !i32 { // @return < 0 on error pub extern fn sceUmdUnRegisterUMDCallBack(cbid: c_int) c_int; pub fn umdUnRegisterUMDCallBack(cbid: c_int) !i32 { - var res = sceUmdUnRegisterUMDCallBack(cbid); + const res = sceUmdUnRegisterUMDCallBack(cbid); if (res < 0) { return error.Unexpected; } @@ -206,7 +206,7 @@ pub fn umdUnRegisterUMDCallBack(cbid: c_int) !i32 { // @return < 0 on error pub extern fn sceUmdReplacePermit() c_int; pub fn umdReplacePermit() !i32 { - var res = sceUmdReplacePermit(); + const res = sceUmdReplacePermit(); if (res < 0) { return error.Unexpected; } @@ -218,7 +218,7 @@ pub fn umdReplacePermit() !i32 { // @return < 0 on error pub extern fn sceUmdReplaceProhibit() c_int; pub fn umdReplaceProhibit() !i32 { - var res = sceUmdReplaceProhibit(); + const res = sceUmdReplaceProhibit(); if (res < 0) { return error.Unexpected; } diff --git a/src/psp/sdk/pspusb.zig b/src/psp/sdk/pspusb.zig index 3adc0df..1285338 100644 --- a/src/psp/sdk/pspusb.zig +++ b/src/psp/sdk/pspusb.zig @@ -7,8 +7,8 @@ usingnamespace @import("psptypes.zig"); // @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 { +pub extern fn sceUsbStart(driverName: [*c]const u8, size: c_int, args: ?*anyopaque) c_int; +pub fn usbStart(driverName: [*c]const u8, size: c_int, args: ?*anyopaque) bool { return sceUsbStart(driverName, size, args) == 0; } @@ -19,8 +19,8 @@ pub fn usbStart(driverName: [*c]const u8, size: c_int, args: ?*c_void) bool { // @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 { +pub extern fn sceUsbStop(driverName: [*c]const u8, size: c_int, args: ?*anyopaque) c_int; +pub fn usbStop(driverName: [*c]const u8, size: c_int, args: ?*anyopaque) bool { return sceUsbStop(driverName, size, args) == 0; } diff --git a/src/psp/sdk/psputility.zig b/src/psp/sdk/psputility.zig index 71a502d..1c8b158 100644 --- a/src/psp/sdk/psputility.zig +++ b/src/psp/sdk/psputility.zig @@ -1,3 +1,7 @@ +const psptypes = @import("psptypes.zig"); +const SceUID = psptypes.SceUID; +const SceSize = psptypes.SceSize; + pub const PspUtilityDialogCommon = extern struct { size: c_uint, language: c_int, @@ -10,19 +14,19 @@ pub const PspUtilityDialogCommon = extern struct { reserved: [4]c_int, }; -pub const PspUtilityMsgDialogMode = extern enum(c_int) { +pub const PspUtilityMsgDialogMode = enum(c_int) { Error = 0, Text = 1, _, }; -const PspUtilityMsgDialogOption = extern enum(c_int) { +const PspUtilityMsgDialogOption = enum(c_int) { Error = 0, Text = 1, YesNoButtons = 16, DefaultNo = 256, }; -pub const PspUtilityMsgDialogPressed = extern enum(c_int) { +pub const PspUtilityMsgDialogPressed = enum(c_int) { Unknown1 = 0, Yes = 1, No = 2, @@ -43,7 +47,7 @@ pub extern fn sceUtilityMsgDialogGetStatus() c_int; pub extern fn sceUtilityMsgDialogUpdate(n: c_int) void; pub extern fn sceUtilityMsgDialogAbort() c_int; -pub const PspUtilityNetconfActions = extern enum(c_int) { +pub const PspUtilityNetconfActions = enum(c_int) { ConnectAp, DisplayStatus, ConnectAdhoc, @@ -66,18 +70,18 @@ pub extern fn sceUtilityNetconfShutdownStart() c_int; pub extern fn sceUtilityNetconfUpdate(unknown: c_int) c_int; pub extern fn sceUtilityNetconfGetStatus() c_int; const NetData = extern union { - asUint: u32_7, + asUint: u32, asString: [128]u8, }; pub extern fn sceUtilityCheckNetParam(id: c_int) 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 sceUtilitySetNetParam(param: c_int, val: ?*const anyopaque) c_int; pub extern fn sceUtilityCopyNetParam(src: c_int, dest: c_int) c_int; pub extern fn sceUtilityDeleteNetParam(conf: c_int) c_int; -const PspUtilitySavedataMode = extern enum(c_int) { +const PspUtilitySavedataMode = enum(c_int) { Autoload = 0, Autosave = 1, Load = 2, @@ -89,7 +93,7 @@ const PspUtilitySavedataMode = extern enum(c_int) { _, }; -const PspUtilitySavedataFocus = extern enum(c_int) { +const PspUtilitySavedataFocus = enum(c_int) { Unknown = 0, FirstList = 1, LastList = 2, @@ -111,7 +115,7 @@ pub const PspUtilitySavedataSFOParam = extern struct { }; pub const PspUtilitySavedataFileData = extern struct { - buf: ?*c_void, + buf: ?*anyopaque, bufSize: SceSize, size: SceSize, unknown: c_int, @@ -133,7 +137,7 @@ pub const SceUtilitySavedataParam = extern struct { saveNameList: [*c][20]u8, fileName: [13]u8, reserved1: [3]u8, - dataBuf: ?*c_void, + dataBuf: ?*anyopaque, dataBufSize: SceSize, dataSize: SceSize, sfoParam: PspUtilitySavedataSFOParam, @@ -177,7 +181,7 @@ 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) { +pub const PspUtilityDialogState = enum(c_int) { None = 0, Init = 1, Visible = 2, @@ -185,7 +189,7 @@ pub const PspUtilityDialogState = extern enum(c_int) { Finished = 4, }; -pub const SceUtilityOskInputType = extern enum(c_int) { +pub const SceUtilityOskInputType = enum(c_int) { All = 0, LatinDigit = 1, LatinSymbol = 2, @@ -205,7 +209,7 @@ pub const SceUtilityOskInputType = extern enum(c_int) { Url = 524288, }; -pub const SceUtilityOskInputLanguage = extern enum(c_int) { +pub const SceUtilityOskInputLanguage = enum(c_int) { Default = 0, Japanese = 1, English = 2, @@ -218,7 +222,7 @@ pub const SceUtilityOskInputLanguage = extern enum(c_int) { Russian = 9, Korean = 10, }; -pub const SceUtilityOskState = extern enum(c_int) { +pub const SceUtilityOskState = enum(c_int) { None = 0, Initing = 1, Inited = 2, @@ -226,38 +230,38 @@ pub const SceUtilityOskState = extern enum(c_int) { Quit = 4, Finished = 5, }; -pub const SceUtilityOskResult = extern enum(c_int) { +pub const SceUtilityOskResult = enum(c_int) { Unchanged = 0, Cancelled = 1, Changed = 2, }; -pub const PspUtilityHtmlViewerDisconnectModes = extern enum(c_int) { +pub const PspUtilityHtmlViewerDisconnectModes = enum(c_int) { Enable = 0, Disable = 1, Confirm = 2, _, }; -pub const PspUtilityHtmlViewerInterfaceModes = extern enum(c_int) { +pub const PspUtilityHtmlViewerInterfaceModes = enum(c_int) { Full = 0, Limited = 1, None = 2, _, }; -pub const PspUtilityHtmlViewerCookieModes = extern enum(c_int) { +pub const PspUtilityHtmlViewerCookieModes = enum(c_int) { Disabled = 0, Enabled = 1, Confirm = 2, Default = 3, _, }; -pub const PspUtilityGameSharingMode = extern enum(c_int) { +pub const PspUtilityGameSharingMode = enum(c_int) { Single = 1, Multiple = 2, _, }; -pub const PspUtilityGameSharingDataType = extern enum(c_int) { +pub const PspUtilityGameSharingDataType = enum(c_int) { File = 1, Memory = 2, _, @@ -275,29 +279,29 @@ pub const PspUtilityGameSharingParams = extern struct { filepath: [*c]u8, mode: PspUtilityGameSharingMode, datatype: PspUtilityGameSharingDataType, - data: ?*c_void, + data: ?*anyopaque, datasize: c_uint, }; -pub const PspUtilityHtmlViewerTextSizes = extern enum(c_int) { +pub const PspUtilityHtmlViewerTextSizes = enum(c_int) { Large = 0, Normal = 1, Small = 2, _, }; -pub const PspUtilityHtmlViewerDisplayModes = extern enum(c_int) { +pub const PspUtilityHtmlViewerDisplayModes = enum(c_int) { Normal = 0, Fit = 1, SmartFit = 2, _, }; -pub const PspUtilityHtmlViewerConnectModes = extern enum(c_int) { +pub const PspUtilityHtmlViewerConnectModes = enum(c_int) { Last = 0, ManualOnce = 1, ManualAll = 2, _, }; -pub const PspUtilityHtmlViewerOptions = extern enum(c_int) { +pub const PspUtilityHtmlViewerOptions = enum(c_int) { OpenSceStartPage = 1, DisableStartupLimits = 2, DisableExitDialog = 4, @@ -313,7 +317,7 @@ pub const PspUtilityHtmlViewerOptions = extern enum(c_int) { }; pub const PspUtilityHtmlViewerParam = extern struct { base: PspUtilityDialogCommon, - memaddr: ?*c_void, + memaddr: ?*anyopaque, memsize: c_uint, unknown1: c_int, unknown2: c_int, @@ -360,11 +364,9 @@ pub const SceUtilityOskParams = extern struct { unk_60: c_int, }; -pub const ModuleNet = extern enum(c_int) { - Common = 1, Adhoc = 2, Inet = 3, Parseuri = 4, Parsehttp = 5, Http = 6, Ssl = 7 -}; +pub const ModuleNet = enum(c_int) { Common = 1, Adhoc = 2, Inet = 3, Parseuri = 4, Parsehttp = 5, Http = 6, Ssl = 7 }; -pub const ModuleUSB = extern enum(c_int) { +pub const ModuleUSB = enum(c_int) { Pspcm = 1, Acc = 2, Mic = 3, @@ -372,19 +374,13 @@ pub const ModuleUSB = extern enum(c_int) { Gps = 5, }; -pub const NetParam = extern enum(c_int) { - Name = 0, Ssid = 1, Secure = 2, Wepkey = 3, IsStaticIp = 4, Ip = 5, Netmask = 6, Route = 7, ManualDns = 8, Primarydns = 9, Secondarydns = 10, ProxyUser = 11, ProxyPass = 12, UseProxy = 13, ProxyServer = 14, ProxyPort = 15, Unknown1 = 16, Unknown2 = 17 -}; +pub const NetParam = enum(c_int) { Name = 0, Ssid = 1, Secure = 2, Wepkey = 3, IsStaticIp = 4, Ip = 5, Netmask = 6, Route = 7, ManualDns = 8, Primarydns = 9, Secondarydns = 10, ProxyUser = 11, ProxyPass = 12, UseProxy = 13, ProxyServer = 14, ProxyPort = 15, Unknown1 = 16, Unknown2 = 17 }; -pub const SystemParamID = extern enum(c_int) { - StringNickname = 1, IntAdhocChannel = 2, IntWlanPowersave = 3, IntDateFormat = 4, IntTimeFormat = 5, IntTimezone = 6, IntDaylightsavings = 7, IntLanguage = 8, IntUnknown = 9 -}; +pub const SystemParamID = enum(c_int) { StringNickname = 1, IntAdhocChannel = 2, IntWlanPowersave = 3, IntDateFormat = 4, IntTimeFormat = 5, IntTimezone = 6, IntDaylightsavings = 7, IntLanguage = 8, IntUnknown = 9 }; -pub const ModuleAV = extern enum(c_int) { - Avcodec = 0, Sascore = 1, Atrac3plus = 2, Mpegbase = 3, Mp3 = 4, Vaudio = 5, Aac = 6, G729 = 7 -}; +pub const ModuleAV = enum(c_int) { Avcodec = 0, Sascore = 1, Atrac3plus = 2, Mpegbase = 3, Mp3 = 4, Vaudio = 5, Aac = 6, G729 = 7 }; -pub const SystemParamLanguage = extern enum(c_int) { +pub const SystemParamLanguage = enum(c_int) { Japanese = 0, English = 1, French = 2, @@ -399,41 +395,25 @@ pub const SystemParamLanguage = extern enum(c_int) { ChineseSimplified = 11, }; -pub const SystemParamTime = extern enum(c_int) { - Format24Hr = 0, Format12Hr = 1 -}; +pub const SystemParamTime = enum(c_int) { Format24Hr = 0, Format12Hr = 1 }; -pub const UtilityAccept = extern enum(c_int) { - Circle = 0, Cross = 1 -}; +pub const UtilityAccept = enum(c_int) { Circle = 0, Cross = 1 }; -pub const SystemParamAdhoc = extern enum(c_int) { +pub const SystemParamAdhoc = enum(c_int) { ChannelAutomatic = 0, Channel1 = 1, Channel6 = 6, Channel11 = 11, }; -pub const NetParamError = extern enum(c_int) { - BadNetconf = 0x80110601, BadParam = 0x80110604 -}; +pub const NetParamError = enum(c_int) { BadNetconf = 0x80110601, BadParam = 0x80110604 }; -pub const SystemParamWlanPowerSave = extern enum(c_int) { - Off = 0, On = 1 -}; +pub const SystemParamWlanPowerSave = enum(c_int) { Off = 0, On = 1 }; -pub const SystemParamDaylightSavings = extern enum(c_int) { - Std = 0, Saving = 1 -}; +pub const SystemParamDaylightSavings = enum(c_int) { Std = 0, Saving = 1 }; -pub const SystemParamDateFormat = extern enum(c_int) { - YYYYMMDD = 0, MMDDYYYY = 1, DDMMYYYY = 2 -}; +pub const SystemParamDateFormat = enum(c_int) { YYYYMMDD = 0, MMDDYYYY = 1, DDMMYYYY = 2 }; -pub const SystemParamRetVal = extern enum(c_int) { - Ok = 0, Fail = 0x80110103 -}; +pub const SystemParamRetVal = enum(c_int) { Ok = 0, Fail = 0x80110103 }; -pub const ModuleNP = extern enum(c_int) { - Common = 0x0400, Service = 0x0401, Matching2 = 0x0402, Drm = 0x0500, Irda = 0x0600 -}; +pub const ModuleNP = enum(c_int) { Common = 0x0400, Service = 0x0401, Matching2 = 0x0402, Drm = 0x0500, Irda = 0x0600 }; diff --git a/src/psp/sdk/psputils.zig b/src/psp/sdk/psputils.zig index 3242208..1f6173c 100644 --- a/src/psp/sdk/psputils.zig +++ b/src/psp/sdk/psputils.zig @@ -1,4 +1,8 @@ -usingnamespace @import("psptypes.zig"); +const psptypes = @import("psptypes.zig"); +const psprtc = @import("psptypes.zig"); +const SceUShort16 = psptypes.SceUShort16; +const SceULong64 = psptypes.SceULong64; +const time_t = psprtc.time_t; pub const clock_t = u32; pub const suseconds_t = u32; @@ -48,7 +52,7 @@ pub const SceKernelUtilsSha1Context = extern struct { // @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); + const res = sceKernelUtilsMt19937Init(ctx, seed); if (res < 0) { return error.Unexpected; } @@ -70,7 +74,7 @@ pub extern fn sceKernelUtilsMt19937UInt(ctx: *SceKernelUtilsMt19937Context) u32; // @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); + const res = sceKernelUtilsMd5Digest(data, size, digest); if (res < 0) { return error.Unexpected; } @@ -91,7 +95,7 @@ pub fn kernelUtilsMd5Digest(data: [*]u8, size: u32, digest: [*]u8) !i32 { // sceKernelUtilsMd5BlockResult(&ctx, digest); pub extern fn sceKernelUtilsMd5BlockInit(ctx: *SceKernelUtilsMd5Context) c_int; pub fn kernelUtilsMd5BlockInit(ctx: *SceKernelUtilsMd5Context) !i32 { - var res = sceKernelUtilsMd5BlockInit(ctx); + const res = sceKernelUtilsMd5BlockInit(ctx); if (res < 0) { return error.Unexpected; } @@ -107,7 +111,7 @@ pub fn kernelUtilsMd5BlockInit(ctx: *SceKernelUtilsMd5Context) !i32 { // @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); + const res = sceKernelUtilsMd5BlockUpdate(ctx, data, size); if (res < 0) { return error.Unexpected; } @@ -122,7 +126,7 @@ pub fn kernelUtilsMd5BlockUpdate(ctx: *SceKernelUtilsMd5Context, data: [*]u8, si // @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); + const res = sceKernelUtilsMd5BlockResult(ctx, digest); if (res < 0) { return error.Unexpected; } @@ -138,7 +142,7 @@ pub fn kernelUtilsMd5BlockResult(ctx: *SceKernelUtilsMd5Context, digest: [*]u8) // @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); + const res = sceKernelUtilsSha1Digest(data, size, digest); if (res < 0) { return error.Unexpected; } @@ -159,7 +163,7 @@ pub fn kernelUtilsSha1Digest(data: [*]u8, size: u32, digest: [*]u8) !i32 { // sceKernelUtilsSha1BlockResult(&ctx, digest); pub extern fn sceKernelUtilsSha1BlockInit(ctx: *SceKernelUtilsSha1Context) c_int; pub fn kernelUtilsSha1BlockInit(ctx: *SceKernelUtilsSha1Context) !i32 { - var res = sceKernelUtilsSha1BlockInit(ctx); + const res = sceKernelUtilsSha1BlockInit(ctx); if (res < 0) { return error.Unexpected; } @@ -175,7 +179,7 @@ pub fn kernelUtilsSha1BlockInit(ctx: *SceKernelUtilsSha1Context) !i32 { // @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); + const res = sceKernelUtilsSha1BlockUpdate(ctx, data, size); if (res < 0) { return error.Unexpected; } @@ -190,7 +194,7 @@ pub fn kernelUtilsSha1BlockUpdate(ctx: *SceKernelUtilsSha1Context, data: [*]u8, // @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); + const res = sceKernelUtilsSha1BlockResult(ctx, digest); if (res < 0) { return error.Unexpected; } @@ -213,16 +217,16 @@ pub extern fn sceKernelDcacheWritebackAll() void; 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; +pub extern fn sceKernelDcacheWritebackRange(p: ?*const anyopaque, 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; +pub extern fn sceKernelDcacheWritebackInvalidateRange(p: ?*const anyopaque, size: c_uint) void; //Invalidate a range of addresses in data cache -pub extern fn sceKernelDcacheInvalidateRange(p: ?*const c_void, size: c_uint) void; +pub extern fn sceKernelDcacheInvalidateRange(p: ?*const anyopaque, 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; +pub extern fn sceKernelIcacheInvalidateRange(p: ?*const anyopaque, size: c_uint) void; diff --git a/src/psp/sdk/pspwlan.zig b/src/psp/sdk/pspwlan.zig index c38b775..72efddd 100644 --- a/src/psp/sdk/pspwlan.zig +++ b/src/psp/sdk/pspwlan.zig @@ -24,7 +24,7 @@ pub fn wlanGetSwitchState() bool { pub extern fn sceWlanGetEtherAddr(etherAddr: [*c]u8) c_int; pub fn wlanGetEtherAddr(etherAddr: []u8) !void { - var res = sceWlanGetEtherAddr(etherAddr); + const res = sceWlanGetEtherAddr(etherAddr); if (res < 0) { return error.Unexpected; } diff --git a/src/psp/sdk/sin.zig b/src/psp/sdk/sin.zig index 9d6da2f..7fa39d7 100644 --- a/src/psp/sdk/sin.zig +++ b/src/psp/sdk/sin.zig @@ -62,10 +62,10 @@ 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 = @floatToInt(I, y); + var j = @as(I, @intFromFloat(y)); if (j & 1 == 1) { j += 1; diff --git a/src/psp/utils/allocator.zig b/src/psp/utils/allocator.zig index f08d925..ab35b83 100644 --- a/src/psp/utils/allocator.zig +++ b/src/psp/utils/allocator.zig @@ -3,9 +3,12 @@ const mem = std.mem; const debug = std.debug; const assert = debug.assert; -usingnamespace @import("../include/psptypes.zig"); -usingnamespace @import("../include/pspsysmem.zig"); -usingnamespace @import("../include/psploadexec.zig"); +const psptypes = @import("../include/psptypes.zig"); +const pspsysmem = @import("../include/pspsysmem.zig"); +const psploadexec = @import("../include/psploadexec.zig"); + +const SceSize = psptypes.SceSize; +const SceUID = psptypes.SceUID; const Allocator = mem.Allocator; @@ -27,6 +30,9 @@ pub const PSPAllocator = struct { //Our Allocator fn psp_realloc(allocator: *Allocator, len: usize, alignment: u29, len_align: u29, ra: usize) std.mem.Allocator.Error![]u8 { + _ = allocator; + _ = len_align; + _ = ra; //Assume alignment is less than double aligns assert(len > 0); assert(alignment <= @alignOf(c_longdouble)); @@ -35,7 +41,7 @@ pub const PSPAllocator = struct { if (len > 0) { //Gets a block of memory - var id: SceUID = sceKernelAllocPartitionMemory(2, "block", @enumToInt(PspSysMemBlockTypes.MemLow), len + @sizeOf(SceUID), null); + const id: SceUID = psploadexec.sceKernelAllocPartitionMemory(2, "block", @intFromEnum(psploadexec.PspSysMemBlockTypes.MemLow), len + @sizeOf(SceUID), null); if (id < 0) { //TODO: Handle error cases that aren't out of memory... @@ -43,13 +49,13 @@ pub const PSPAllocator = struct { } //Get the head address - var ptr = @ptrCast([*]u32, @alignCast(4, sceKernelGetBlockHeadAddr(id))); + const ptr = @as([*]u32, @ptrCast(@alignCast(psploadexec.sceKernelGetBlockHeadAddr(id)))); //Store our ID to free - @ptrCast(*c_int, ptr).* = id; + @as(*c_int, @ptrCast(ptr)).* = id; //Convert and return - var ptr2 = @ptrCast([*]u8, ptr); + var ptr2 = @as([*]u8, @ptrCast(ptr)); ptr2 += @sizeOf(SceUID); return ptr2[0..len]; @@ -60,16 +66,22 @@ pub const PSPAllocator = struct { //Our de-allocator fn psp_shrink(allocator: *Allocator, buf_unaligned: []u8, buf_align: u29, new_size: usize, len_align: u29, return_address: usize) std.mem.Allocator.Error!usize { + _ = allocator; + _ = buf_align; + _ = new_size; + _ = len_align; + _ = return_address; //Get ptr - var ptr = @ptrCast([*]u8, buf_unaligned); + var ptr = @as([*]u8, @ptrCast(buf_unaligned)); //Go back to our ID ptr -= @sizeOf(SceUID); - var id = @ptrCast(*c_int, @alignCast(4, ptr)).*; + const id = @as(*c_int, @ptrCast(@alignCast(ptr))).*; //Free the ID - var s = sceKernelFreePartitionMemory(id); + const s = psploadexec.sceKernelFreePartitionMemory(id); + _ = s; //Return 0 return 0; diff --git a/src/psp/utils/benchmark.zig b/src/psp/utils/benchmark.zig index 7a1691f..4bd67ee 100644 --- a/src/psp/utils/benchmark.zig +++ b/src/psp/utils/benchmark.zig @@ -16,8 +16,8 @@ pub fn benchmark_end() !u64 { var delta = current_time - oldTime; - var deltaF = @intToFloat(f64, delta); - var tickRF = @intToFloat(f32, tickRate); + var deltaF = @as(f64, @floatFromInt(delta)); + var tickRF = @as(f32, @floatFromInt(tickRate)); try printFormat("Method took {} ticks. ({d} ms)\n", .{ delta, deltaF / tickRF * 1000 }); diff --git a/src/psp/utils/debug.zig b/src/psp/utils/debug.zig index 9317abd..1f05346 100644 --- a/src/psp/utils/debug.zig +++ b/src/psp/utils/debug.zig @@ -1,8 +1,8 @@ -usingnamespace @import("constants.zig"); -usingnamespace @import("../include/pspge.zig"); -usingnamespace @import("../include/pspdisplay.zig"); -usingnamespace @import("../include/pspthreadman.zig"); -usingnamespace @import("../include/psploadexec.zig"); +const constants = @import("constants.zig"); +const pspge = @import("../include/pspge.zig"); +const pspdisplay = @import("../include/pspdisplay.zig"); +const pspthreadman = @import("../include/pspthreadman.zig"); +const psploadexec = @import("../include/psploadexec.zig"); const builtin = @import("builtin"); @@ -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 < SCR_BUF_WIDTH * SCREEN_HEIGHT) : (i += 1) { + while (i < constants.SCR_BUF_WIDTH * constants.SCREEN_HEIGHT) : (i += 1) { vram_base.?[i] = cl_col; } } @@ -72,10 +72,10 @@ pub fn screenInit() void { x = 0; y = 0; - vram_base = @intToPtr(?[*]u32, 0x40000000 | @ptrToInt(sceGeEdramGetAddr())); + vram_base = @as(?[*]u32, @ptrFromInt(0x40000000 | @intFromPtr(pspge.sceGeEdramGetAddr()))); - _ = sceDisplaySetMode(0, SCREEN_WIDTH, SCREEN_HEIGHT); - _ = sceDisplaySetFrameBuf(vram_base, SCR_BUF_WIDTH, @enumToInt(PspDisplayPixelFormats.Format8888), 1); + _ = pspdisplay.sceDisplaySetMode(0, constants.SCREEN_WIDTH, constants.SCREEN_HEIGHT); + _ = pspdisplay.sceDisplaySetFrameBuf(vram_base, constants.SCR_BUF_WIDTH, @intFromEnum(pspdisplay.PspDisplayPixelFormats.Format8888), 1); screenClear(); } @@ -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"); @@ -125,7 +125,7 @@ pub fn printFormat(comptime fmt: []const u8, args: anytype) !void { const alloc = @import("allocator.zig"); var psp_allocator = &alloc.PSPAllocator.init().allocator; - var string = try std.fmt.allocPrint(psp_allocator, fmt, args); + const string = try std.fmt.allocPrint(psp_allocator, fmt, args); defer psp_allocator.free(string); print(string); @@ -136,7 +136,7 @@ pub const msxFont = @embedFile("./msxfont2.bin"); //Puts a character to screen fn internal_putchar(cx: u32, cy: u32, ch: u8) void { - var off: usize = cx + (cy * SCR_BUF_WIDTH); + const off: usize = cx + (cy * constants.SCR_BUF_WIDTH); var i: usize = 0; while (i < 8) : (i += 1) { @@ -145,26 +145,28 @@ fn internal_putchar(cx: u32, cy: u32, ch: u8) void { while (j < 8) : (j += 1) { const mask: u32 = 128; - var idx: u32 = @as(u32, ch - 32) * 8 + i; - var glyph: u8 = msxFont[idx]; + const idx: u32 = @as(u32, ch - 32) * 8 + i; + const glyph: u8 = msxFont[idx]; - if ((glyph & (mask >> @intCast(@import("std").math.Log2Int(c_int), j))) != 0) { - vram_base.?[j + i * SCR_BUF_WIDTH + off] = fg_col; + if ((glyph & (mask >> @as(@import("std").math.Log2Int(c_int), @intCast(j)))) != 0) { + vram_base.?[j + i * constants.SCR_BUF_WIDTH + off] = fg_col; } else if (back_col_enable) { - vram_base.?[j + i * SCR_BUF_WIDTH + off] = bg_col; + vram_base.?[j + i * constants.SCR_BUF_WIDTH + off] = bg_col; } } } } -usingnamespace @import("module.zig"); +const module = @import("module.zig"); //Meme panic 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(); if (pancakeMode) { @@ -182,6 +184,6 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noretur //} print("\nExiting in 10 seconds..."); - exitErr(); + module.exitErr(); while (true) {} } diff --git a/src/psp/utils/mem-fix.zig b/src/psp/utils/mem-fix.zig index fd9d979..374bfd1 100644 --- a/src/psp/utils/mem-fix.zig +++ b/src/psp/utils/mem-fix.zig @@ -4,7 +4,7 @@ export fn memset(ptr: [*]u8, value: u32, num: usize) [*]u8 { var i: usize = 0; while (i < num) : (i += 1) { - ptr[i] = @as(u8, @truncate(u8, value)); + ptr[i] = @as(u8, @as(u8, @truncate(value))); } return ptr; } diff --git a/src/psp/utils/module.zig b/src/psp/utils/module.zig index 44f0175..9ec7c6b 100644 --- a/src/psp/utils/module.zig +++ b/src/psp/utils/module.zig @@ -1,26 +1,31 @@ -test "" { +test { @import("std").meta.refAllDecls(@This()); } -usingnamespace @import("../include/psploadexec.zig"); -usingnamespace @import("../include/pspthreadman.zig"); -usingnamespace @import("../include/psptypes.zig"); -usingnamespace @import("debug.zig"); +const psploadexec = @import("../include/psploadexec.zig"); +const pspthreadman = @import("../include/pspthreadman.zig"); +const psptypes = @import("../include/psptypes.zig"); +const debug = @import("debug.zig"); const root = @import("root"); +const SceUID = psptypes.SceUID; + //If there's an issue this is the internal exit (wait 10 seconds and exit). pub fn exitErr() void { //Hang for 10 seconds for error reporting - var stat = sceKernelDelayThread(10 * 1000 * 1000); + const stat = pspthreadman.sceKernelDelayThread(10 * 1000 * 1000); + _ = stat; //Exit out. - sceKernelExitGame(); + psploadexec.sceKernelExitGame(); } const has_std_os = if (@hasDecl(root, "os")) true else false; +const bad_main_ret = @compileError("Where is this from?!"); //This calls your main function as a thread. -pub fn _module_main_thread(argc: SceSize, argv: ?*c_void) callconv(.C) c_int { +pub fn _module_main_thread(argc: psptypes.SceSize, argv: ?*anyopaque) callconv(.C) c_int { + _ = argc; if (has_std_os) { pspos.system.__pspOsInit(argv); } @@ -41,9 +46,9 @@ pub fn _module_main_thread(argc: SceSize, argv: ?*c_void) callconv(.C) c_int { }, .ErrorUnion => { const result = root.main() catch |err| { - print("ERROR CAUGHT: "); - print(@errorName(err)); - print("\nExiting in 10 seconds..."); + debug.print("ERROR CAUGHT: "); + debug.print(@errorName(err)); + debug.print("\nExiting in 10 seconds..."); exitErr(); return 1; @@ -62,8 +67,8 @@ pub fn _module_main_thread(argc: SceSize, argv: ?*c_void) callconv(.C) c_int { else => @compileError(bad_main_ret), } - if (exitOnEnd) { - sceKernelExitGame(); + if (debug.exitOnEnd) { + psploadexec.sceKernelExitGame(); } return 0; } @@ -172,15 +177,15 @@ pub fn module_info(comptime name: []const u8, comptime attrib: u16, comptime maj \\module_info: \\.align 5 \\.hword - ++ attr ++ "\n" ++ + ++ attr ++ "\n" ++ \\.byte - ++ maj ++ "\n" ++ + ++ maj ++ "\n" ++ \\.byte - ++ min ++ "\n" ++ + ++ min ++ "\n" ++ \\.ascii " - ++ name ++ "\"\n" ++ + ++ name ++ "\"\n" ++ \\.space - ++ count ++ "\n" ++ + ++ count ++ "\n" ++ \\.byte 0 \\.word _gp \\.word __lib_ent_top @@ -192,7 +197,7 @@ pub fn module_info(comptime name: []const u8, comptime attrib: u16, comptime maj const pspos = @import("../pspos.zig"); //Entry point - launches main through the thread above. -pub export fn module_start(argc: c_uint, argv: ?*c_void) c_int { - var thid: SceUID = sceKernelCreateThread("zig_user_main", _module_main_thread, 0x20, 256 * 1024, 0b10000000000000000100000000000000, 0); - return sceKernelStartThread(thid, argc, argv); +pub export fn module_start(argc: c_uint, argv: ?*anyopaque) c_int { + const thid: SceUID = pspthreadman.sceKernelCreateThread("zig_user_main", _module_main_thread, 0x20, 256 * 1024, 0b10000000000000000100000000000000, 0); + return pspthreadman.sceKernelStartThread(thid, argc, argv); } diff --git a/src/psp/utils/utils.zig b/src/psp/utils/utils.zig index 12d834d..72639b9 100644 --- a/src/psp/utils/utils.zig +++ b/src/psp/utils/utils.zig @@ -1,6 +1,6 @@ -usingnamespace @import("../include/pspthreadman.zig"); -usingnamespace @import("../include/psploadexec.zig"); -usingnamespace @import("../include/psptypes.zig"); +const pspthreadman = @import("../include/pspthreadman.zig"); +const psploadexec = @import("../include/psploadexec.zig"); +const psptypes = @import("../include/psptypes.zig"); var requestedExit: bool = false; @@ -10,33 +10,39 @@ pub fn isRunning() bool { } //Exit -export fn exitCB(arg1: c_int, arg2: c_int, common: ?*c_void) c_int { +export fn exitCB(arg1: c_int, arg2: c_int, common: ?*anyopaque) c_int { + _ = arg1; + _ = arg2; + _ = common; requestedExit = true; - sceKernelExitGame(); + psploadexec.sceKernelExitGame(); return 0; } //Thread for home button exit thread. -export fn cbThread(args: SceSize, argp: ?*c_void) c_int { +export fn cbThread(args: psptypes.SceSize, argp: ?*anyopaque) c_int { + _ = args; + _ = argp; var cbID: i32 = -1; - cbID = sceKernelCreateCallback("zig_exit_callback", exitCB, null); - var status = sceKernelRegisterExitCallback(cbID); + 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 = sceKernelSleepThreadCB(); + status = pspthreadman.sceKernelSleepThreadCB(); return 0; } //This enables the home button exit callback above pub fn enableHBCB() void { - var threadID: i32 = sceKernelCreateThread("zig_callback_updater", cbThread, 0x11, 0xFA0, @enumToInt(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) { - var stat: i32 = 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!"); } diff --git a/src/psp/utils/vram.zig b/src/psp/utils/vram.zig index ebbd196..999881d 100644 --- a/src/psp/utils/vram.zig +++ b/src/psp/utils/vram.zig @@ -1,6 +1,6 @@ //This is probably broken -usingnamespace @import("../include/pspdisplay.zig"); -usingnamespace @import("../include/pspgu.zig"); +const display = @import("../include/pspdisplay.zig"); +const gu = @import("../include/pspgu.zig"); //This isn't an actual "allocator" per se //It allocates static chunks of VRAM @@ -9,7 +9,7 @@ usingnamespace @import("../include/pspgu.zig"); var vramOff: usize = 0; //Get the amount of memory needed -fn getMemSize(width: u32, height: u32, format: GuPixelMode) c_uint { +fn getMemSize(width: u32, height: u32, format: gu.GuPixelMode) c_uint { switch (format) { .PsmT4 => { return width * height / 2; @@ -32,13 +32,13 @@ fn getMemSize(width: u32, height: u32, format: GuPixelMode) c_uint { } //Allocate a buffer of VRAM in VRAM-Relative pointers (0 is 0x04000000) -pub fn allocVramRelative(width: u32, height: u32, format: GuPixelMode) ?*c_void { - var res = vramOff; +pub fn allocVramRelative(width: u32, height: u32, format: gu.GuPixelMode) ?*anyopaque { + const res = vramOff; vramOff += getMemSize(width, height, format); - return @intToPtr(?*c_void, res); + return @as(?*anyopaque, @ptrFromInt(res)); } //Allocate a buffer of VRAM in VRAM-Absolute pointers (0x04000000 start) -pub fn allocVramAbsolute(width: u32, height: u32, format: GuPixelMode) ?*c_void { - return @intToPtr(?*c_void, @ptrToInt(allocVramDirect(width, height, format)) + @ptrToInt(sceGeEdramGetAddr)); +pub fn allocVramAbsolute(width: u32, height: u32, format: gu.GuPixelMode) ?*anyopaque { + return @as(?*anyopaque, @ptrFromInt(@intFromPtr(display.allocVramDirect(width, height, format)) + @intFromPtr(display.sceGeEdramGetAddr))); } diff --git a/tools/prxgen/stub.zig b/tools/prxgen/stub.zig index a45db09..28b317a 100644 --- a/tools/prxgen/stub.zig +++ b/tools/prxgen/stub.zig @@ -1 +1 @@ -pub extern fn main(argc : c_int, argv : [*c][*c]u8) c_int; \ No newline at end of file +pub extern fn main(argc: c_int, argv: [*c][*c]u8) c_int;