Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Zig 0.12.0 Nightly #8

Merged
merged 8 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 95 additions & 72 deletions build-psp.zig
Original file line number Diff line number Diff line change
@@ -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);
}
4 changes: 2 additions & 2 deletions build.zig
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
10 changes: 5 additions & 5 deletions examples/allocator.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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!");
Expand Down
28 changes: 12 additions & 16 deletions examples/clearScreen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions examples/cube.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand All @@ -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);

Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions examples/error.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -17,6 +17,6 @@ pub fn main() !void {
psp.debug.screenInit();

try psp.debug.printFormat("Hello {}!\n", .{"world"});

return MyTestErrors.TestError;
}
2 changes: 1 addition & 1 deletion examples/hello-min.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion examples/hello.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion examples/panic.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading