Compare commits

..

15 Commits

Author SHA1 Message Date
Rekai Nyangadzayi Musuka a17d7e6d41 fix(window): proper inRange impl for window
window wrap now works (it's pretty slow though?)
2022-11-11 00:26:10 -04:00
Rekai Nyangadzayi Musuka c73966135c chore: improve readability of sprite drawing code a bit 2022-11-11 00:26:10 -04:00
Rekai Nyangadzayi Musuka be4396fb0d style: remove unused imports 2022-11-11 00:26:10 -04:00
Rekai Nyangadzayi Musuka 5c7cd72bbb chore: dont allocate not-small ?Sprite array on stack
use memset like most other allocations in this emu
2022-11-11 00:26:10 -04:00
Rekai Nyangadzayi Musuka 628b7688cc chore: move FrameBuffer struct to util.zig 2022-11-11 00:26:10 -04:00
Rekai Nyangadzayi Musuka 56029c5a1e chore: move OAM, PALRAM and VRAM structs to separate files 2022-11-11 00:26:10 -04:00
Rekai Nyangadzayi Musuka a156a8763d fix: 8-bit writes to WIN PPU registers
Advance Wars depends on these registers similar to Mario Kart's 8-bit
writes to Affine Background registers:
2022-11-11 00:26:09 -04:00
Rekai Nyangadzayi Musuka 131d3fd6bd chore: refactor window 2022-11-11 00:26:09 -04:00
Rekai Nyangadzayi Musuka 9992acfb55 chore: crude background window impl (no affine) 2022-11-11 00:26:09 -04:00
Rekai Nyangadzayi Musuka a2e93b98ce chore: rename function (misspelt until now somehow) 2022-11-11 00:26:09 -04:00
Rekai Nyangadzayi Musuka accecb3350 chore(ci): rename CI workflow 2022-11-10 11:58:47 -04:00
Rekai Nyangadzayi Musuka 1e0ade8f55 chore: update depdendencies 2022-11-07 00:54:35 -04:00
Rekai Nyangadzayi Musuka 429676ad43 feat(config): write config.toml to config dir, not data dir 2022-11-03 09:45:57 -03:00
Rekai Nyangadzayi Musuka ef39d9a7b8 chore(ci): only run for .zig files, name workflow
Also enabled workflow dispatch
2022-11-03 08:56:14 -03:00
Rekai Nyangadzayi Musuka 986bc9448e fix(bus): account for read_table being the first table when freeing 2022-11-03 07:50:12 -03:00
7 changed files with 42 additions and 22 deletions

View File

@ -1,9 +1,14 @@
name: Nightly
on: on:
push: push:
paths:
- "**.zig"
branches: branches:
- main - main
schedule: schedule:
- cron: '0 0 * * *' - cron: '0 0 * * *'
workflow_dispatch:
jobs: jobs:
build: build:

@ -1 +1 @@
Subproject commit e5d09c4b2d121025ad7195b2de704451e6306807 Subproject commit 749c43f1f846adc950a5920ed61b40cbc3ec2c54

@ -1 +1 @@
Subproject commit 5ec1c36cf3791b3c6c5b330357bdb6feb93979ba Subproject commit 932d2845210644ca736faf35f5bea31eb1a15465

@ -1 +1 @@
Subproject commit 5dfa919e03b446c66b295c04bef9bdecabd4276f Subproject commit be26d500917b5b3af4708f62ce22b990032a0ad3

View File

@ -49,11 +49,11 @@ pub fn config() *const Config {
} }
/// Reads a config file and then loads it into the global state /// Reads a config file and then loads it into the global state
pub fn load(allocator: Allocator, config_path: []const u8) !void { pub fn load(allocator: Allocator, file_path: []const u8) !void {
var config_file = try std.fs.cwd().openFile(config_path, .{}); var config_file = try std.fs.cwd().openFile(file_path, .{});
defer config_file.close(); defer config_file.close();
log.info("loaded from {s}", .{config_path}); log.info("loaded from {s}", .{file_path});
const contents = try config_file.readToEndAlloc(allocator, try config_file.getEndPos()); const contents = try config_file.readToEndAlloc(allocator, try config_file.getEndPos());
defer allocator.free(contents); defer allocator.free(contents);

View File

@ -102,7 +102,7 @@ pub fn deinit(self: *Self) void {
// This is so I can deallocate the original `allocator.alloc`. I have to re-make the type // This is so I can deallocate the original `allocator.alloc`. I have to re-make the type
// since I'm not keeping it around, This is very jank and bad though // since I'm not keeping it around, This is very jank and bad though
// FIXME: please figure out another way // FIXME: please figure out another way
self.allocator.free(@ptrCast([*]const ?*anyopaque, self.write_tables[0][0..])[0 .. 3 * table_len]); self.allocator.free(@ptrCast([*]const ?*anyopaque, self.read_table[0..])[0 .. 3 * table_len]);
self.* = undefined; self.* = undefined;
} }

View File

@ -26,33 +26,44 @@ const params = clap.parseParamsComptime(
\\ \\
); );
pub fn main() anyerror!void { pub fn main() void {
// Main Allocator for ZBA // Main Allocator for ZBA
var gpa = std.heap.GeneralPurposeAllocator(.{}){}; var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer std.debug.assert(!gpa.deinit()); defer std.debug.assert(!gpa.deinit());
const allocator = gpa.allocator(); const allocator = gpa.allocator();
// Determine the Data Directory (stores saves, config file, etc.) // Determine the Data Directory (stores saves)
const data_path = blk: { const data_path = blk: {
const result = known_folders.getPath(allocator, .data); const result = known_folders.getPath(allocator, .data);
const option = result catch |e| exitln("interrupted while attempting to find a data directory: {}", .{e}); const option = result catch |e| exitln("interrupted while determining the data folder: {}", .{e});
const path = option orelse exitln("no valid data directory could be found", .{}); const path = option orelse exitln("no valid data folder found", .{});
ensureDirectoriesExist(path) catch |e| exitln("failed to create directories under \"{s}\": {}", .{ path, e }); ensureDataDirsExist(path) catch |e| exitln("failed to create folders under \"{s}\": {}", .{ path, e });
break :blk path; break :blk path;
}; };
defer allocator.free(data_path); defer allocator.free(data_path);
// Determine the Config Directory
const config_path = blk: {
const result = known_folders.getPath(allocator, .roaming_configuration);
const option = result catch |e| exitln("interreupted while determining the config folder: {}", .{e});
const path = option orelse exitln("no valid config folder found", .{});
ensureConfigDirExists(path) catch |e| exitln("failed to create required folder \"{s}\": {}", .{ path, e });
break :blk path;
};
defer allocator.free(config_path);
// Parse CLI // Parse CLI
const result = clap.parse(clap.Help, &params, clap.parsers.default, .{}) catch |e| exitln("failed to parse cli: {}", .{e}); const result = clap.parse(clap.Help, &params, clap.parsers.default, .{}) catch |e| exitln("failed to parse cli: {}", .{e});
defer result.deinit(); defer result.deinit();
// TODO: Move config file to XDG Config directory? // TODO: Move config file to XDG Config directory?
const config_path = configFilePath(allocator, data_path) catch |e| exitln("failed to determine the config file path for ZBA: {}", .{e}); const cfg_file_path = configFilePath(allocator, config_path) catch |e| exitln("failed to ready config file for access: {}", .{e});
defer allocator.free(config_path); defer allocator.free(cfg_file_path);
config.load(allocator, config_path) catch |e| exitln("failed to read config file: {}", .{e}); config.load(allocator, cfg_file_path) catch |e| exitln("failed to load config file: {}", .{e});
const paths = handleArguments(allocator, data_path, &result) catch |e| exitln("failed to handle cli arguments: {}", .{e}); const paths = handleArguments(allocator, data_path, &result) catch |e| exitln("failed to handle cli arguments: {}", .{e});
defer if (paths.save) |path| allocator.free(path); defer if (paths.save) |path| allocator.free(path);
@ -99,8 +110,8 @@ pub fn handleArguments(allocator: Allocator, data_path: []const u8, result: *con
}; };
} }
fn configFilePath(allocator: Allocator, data_path: []const u8) ![]const u8 { fn configFilePath(allocator: Allocator, config_path: []const u8) ![]const u8 {
const path = try std.fs.path.join(allocator, &[_][]const u8{ data_path, "zba", "config.toml" }); const path = try std.fs.path.join(allocator, &[_][]const u8{ config_path, "zba", "config.toml" });
errdefer allocator.free(path); errdefer allocator.free(path);
// We try to create the file exclusively, meaning that we err out if the file already exists. // We try to create the file exclusively, meaning that we err out if the file already exists.
@ -109,7 +120,7 @@ fn configFilePath(allocator: Allocator, data_path: []const u8) ![]const u8 {
std.fs.accessAbsolute(path, .{}) catch |e| { std.fs.accessAbsolute(path, .{}) catch |e| {
if (e != error.FileNotFound) return e; if (e != error.FileNotFound) return e;
const config_file = try std.fs.createFileAbsolute(path, .{}); const config_file = std.fs.createFileAbsolute(path, .{}) catch |err| exitln("failed to create \"{s}\": {}", .{ path, err });
defer config_file.close(); defer config_file.close();
try config_file.writeAll(@embedFile("../example.toml")); try config_file.writeAll(@embedFile("../example.toml"));
@ -118,17 +129,21 @@ fn configFilePath(allocator: Allocator, data_path: []const u8) ![]const u8 {
return path; return path;
} }
fn ensureDirectoriesExist(data_path: []const u8) !void { fn ensureDataDirsExist(data_path: []const u8) !void {
var dir = try std.fs.openDirAbsolute(data_path, .{}); var dir = try std.fs.openDirAbsolute(data_path, .{});
defer dir.close(); defer dir.close();
// We want to make sure: %APPDATA%/zba and %APPDATA%/zba/save exist
// (~/.local/share/zba/save for linux, ??? for macOS)
// Will recursively create directories // Will recursively create directories
try dir.makePath("zba" ++ std.fs.path.sep_str ++ "save"); try dir.makePath("zba" ++ std.fs.path.sep_str ++ "save");
} }
fn ensureConfigDirExists(config_path: []const u8) !void {
var dir = try std.fs.openDirAbsolute(config_path, .{});
defer dir.close();
try dir.makePath("zba");
}
fn romPath(result: *const clap.Result(clap.Help, &params, clap.parsers.default)) []const u8 { fn romPath(result: *const clap.Result(clap.Help, &params, clap.parsers.default)) []const u8 {
return switch (result.positionals.len) { return switch (result.positionals.len) {
1 => result.positionals[0], 1 => result.positionals[0],