Added support for zig v0.11 #1

Merged
Scribbler merged 1 commits from Dniel97/chuniio-tasoller:main into main 2023-12-21 19:24:19 +00:00
5 changed files with 110 additions and 108 deletions

View File

@ -64,6 +64,6 @@ Custom firmware USB device: 1CCF:2333
```
$ git clone ...
$ git submodule update --init
$ zig build -Drelease-safe=true
$ zig build -Doptimize=ReleaseSafe
$ ls zig-out/lib/chuniio_tasoller.dll
```

View File

@ -1,20 +1,24 @@
const std = @import("std");
const CrossTarget = std.zig.CrossTarget;
const Build = std.build.Builder;
const Step = Build.Step;
pub fn build(b: *std.build.Builder) void {
pub fn build(b: *Build) void {
const mode = b.standardOptimizeOption(.{});
const lib86 = b.addSharedLibrary("chuniio_tasoller", "src/main.zig", .unversioned);
lib86.setBuildMode(b.standardReleaseOptions());
lib86.setTarget(CrossTarget{ .os_tag = .windows, .cpu_arch = .i386, .abi = .msvc });
lib86.install();
const lib86 = b.addSharedLibrary(Build.SharedLibraryOptions{
.name = "chuniio_tasoller",
.root_source_file = .{.path = "src/main.zig"},
.target = CrossTarget{ .os_tag = .windows, .cpu_arch = .x86, .abi = .msvc },
.optimize = mode,
});
b.installArtifact(lib86);
const lib64 = b.addSharedLibrary("chuniio_tasoller_x64", "src/main.zig", .unversioned);
lib64.setBuildMode(b.standardReleaseOptions());
lib64.setTarget(CrossTarget{ .os_tag = .windows, .cpu_arch = .x86_64, .abi = .msvc });
lib64.install();
// const exe = b.addExecutable("tasoller_test", "src/main.zig");
// lib.setBuildMode(b.standardReleaseOptions());
// exe.setTarget(target);
// exe.install();
const lib64 = b.addSharedLibrary(Build.SharedLibraryOptions{
.name = "chuniio_tasoller_x64",
.root_source_file = .{.path = "src/main.zig"},
.target = CrossTarget{ .os_tag = .windows, .cpu_arch = .x86_64, .abi = .msvc },
.optimize = mode,
});
b.installArtifact(lib64);
}

View File

@ -1,4 +1,11 @@
[chuniio]
;; For Chunithm
;path=chuniio_tasoller.dll
;; For Chunithm NEW or newer
path32=chuniio_tasoller.dll
path64=chuniio_tasoller_x64.dll
;; Uncomment for Chunithm NEW or newer
chusan=1
[io3]

View File

@ -68,7 +68,7 @@ pub fn main() !void {
var i: u32 = 0;
try tasoller_init();
while (true) {
if(WinUsb_WritePipe(tasoller, 0x03, @ptrCast(*u8, &usb_out), usb_out.len, &i, null) == 0) {
if (WinUsb_WritePipe(tasoller, 0x03, @as(*u8, @ptrCast(&usb_out)), usb_out.len, &i, null) == 0) {
std.log.warn("[chuniio] WinUsb_WritePipe: {any}", .{GetLastError()});
}
if (WinUsb_ReadPipe(tasoller, 0x84, usb_in.ptr, usb_in.len, &i, null) == 0) {
@ -81,7 +81,6 @@ pub fn main() !void {
// MAIN DRIVER ======================================================================================================
fn tasoller_init() !void {
if (cfg.?.chusan == 1) {
std.log.info("[chuniio] Initializing mode: chusan", .{});
const szName = W("Local\\ChuniioTasoller");
@ -93,7 +92,7 @@ fn tasoller_init() !void {
std.log.err("[chuniio] MapViewOfFile: {any}", .{GetLastError()});
return error.AccessError;
};
usb_in = @ptrCast([*]u8, pBuf)[0..0x24];
usb_in = @as([*]u8, @ptrCast(pBuf))[0..0x24];
if (builtin.cpu.arch == .x86_64) return;
} else {
std.log.info("[chuniio] Initializing mode: chuni", .{});
@ -117,7 +116,7 @@ fn tasoller_init() !void {
while (SetupDiEnumDeviceInterfaces(hDevInfo, null, &GUID_DEVINTERFACE_USB_DEVICE, ifIdx, &devIf) != 0) : (ifIdx += 1) {
var requiredSize: u32 = 0;
var detailBuf align(4) = std.mem.zeroes([512]u8);
var devIfDetail = @ptrCast(*SP_DEVICE_INTERFACE_DETAIL_DATA_A, &detailBuf);
var devIfDetail = @as(*SP_DEVICE_INTERFACE_DETAIL_DATA_A, @ptrCast(&detailBuf));
devIfDetail.cbSize = @sizeOf(SP_DEVICE_INTERFACE_DETAIL_DATA_A);
if (SetupDiGetDeviceInterfaceDetailA(hDevInfo, &devIf, devIfDetail, 263, &requiredSize, null) == 0) {
std.log.err("[chuniio] SetupDiGetDeviceInterfaceDetailA: {any}", .{GetLastError()});
@ -139,25 +138,17 @@ fn tasoller_init() !void {
return error.AccessError;
}
const hDeviceHandle = CreateFileA(
devicePath,
@intToEnum(FILE_ACCESS_FLAGS, GENERIC_READ | GENERIC_WRITE),
@intToEnum(FILE_SHARE_MODE, @enumToInt(FILE_SHARE_READ) | @enumToInt(FILE_SHARE_WRITE)),
null, // Security Attributes
OPEN_EXISTING,
.FILE_FLAG_OVERLAPPED,
null // Template File
) orelse {
std.log.err("[chuniio] CreateFileA {s}: {any}", .{devicePath, GetLastError()});
return error.AccessError;
};
const hDeviceHandle = CreateFileA(devicePath, @as(FILE_ACCESS_FLAGS, @enumFromInt(GENERIC_READ | GENERIC_WRITE)), @as(FILE_SHARE_MODE, @enumFromInt(@intFromEnum(FILE_SHARE_READ) | @intFromEnum(FILE_SHARE_WRITE))), null, // Security Attributes
OPEN_EXISTING, .FILE_FLAG_OVERLAPPED, null // Template File
);
if (hDeviceHandle == INVALID_HANDLE_VALUE) {
std.log.err("[chuniio] CreateFileA {s}: {any}", .{devicePath, GetLastError()});
std.log.err("[chuniio] CreateFileA {any}: {any}\n", .{ devicePath, GetLastError() });
return error.AccessError;
}
if (WinUsb_Initialize(hDeviceHandle, &tasoller) == 0) {
std.log.err("[chuniio] WinUsb_Initialize: {any}", .{GetLastError()});
std.log.err("[chuniio] WinUsb_Initialize: {any}\n", .{ GetLastError() });
return error.AccessError;
}
@ -175,18 +166,18 @@ fn input_thread_proc() void {
std.log.info("[chuniio] Input thread started", .{});
while (true) {
var len: u32 = 0;
if(WinUsb_ReadPipe(tasoller, 0x84, @ptrCast(*u8, usb_in.?.ptr), @intCast(u32, usb_in.?.len), &len, null) == 0) {
if (WinUsb_ReadPipe(tasoller, 0x84, @as(*u8, @ptrCast(usb_in.?.ptr)), @as(u32, @intCast(usb_in.?.len)), &len, null) == 0) {
std.log.warn("[chuniio] WinUsb_ReadPipe: {any}", .{GetLastError()});
}
}
}
const chuni_io_slider_callback_t = ?fn ([*c]const u8) callconv(.C) void;
const chuni_io_slider_callback_t = ?*fn ([*c]const u8) callconv(.C) void;
fn slider_thread_proc(callback: chuni_io_slider_callback_t) void {
var pressure = std.mem.zeroes([32]u8);
while (slider_active) {
for(usb_in.?[4..]) |byte, i| {
for (usb_in.?[4..], 0..) |byte, i| {
// Tasoller order: top->bottom, left->right
// Chunithm order: top->bottom, right->left
pressure[if (i % 2 == 0) 30 - i else 32 - i] = byte;
@ -210,10 +201,10 @@ pub export fn DllMain(hDllHandle: HANDLE, dwReason: DWORD, lpreserved: LPVOID) B
const cfg_file = ".\\segatools.ini";
std.log.info("[chuniio] Loading config from {s}", .{cfg_file});
cfg = .{
.test_key = @intCast(i32, GetPrivateProfileIntA("io3", "test", 0x31, cfg_file)),
.serv_key = @intCast(i32, GetPrivateProfileIntA("io3", "service", 0x32, cfg_file)),
.coin_key = @intCast(i32, GetPrivateProfileIntA("io3", "coin", 0x33, cfg_file)),
.chusan = @intCast(i32, GetPrivateProfileIntA("chuniio", "chusan", 0, cfg_file)),
.test_key = @as(i32, @intCast(GetPrivateProfileIntA("io3", "test", 0x31, cfg_file))),
.serv_key = @as(i32, @intCast(GetPrivateProfileIntA("io3", "service", 0x32, cfg_file))),
.coin_key = @as(i32, @intCast(GetPrivateProfileIntA("io3", "coin", 0x33, cfg_file))),
.chusan = @as(i32, @intCast(GetPrivateProfileIntA("chuniio", "chusan", 0, cfg_file))),
};
return win32.zig.TRUE;
@ -228,9 +219,9 @@ export fn chuni_io_jvs_init() HRESULT {
export fn chuni_io_jvs_poll(opbtn: ?[*]u8, beams: ?[*]u8) void {
if (cfg.?.chusan == 1 and builtin.cpu.arch != .x86_64) return;
if (opbtn == null or beams == null) return;
if(GetAsyncKeyState(cfg.?.test_key) != 0 or (usb_in.?[3] & (1 << 7)) != 0) opbtn.?.* |= (1 << 0);
if(GetAsyncKeyState(cfg.?.serv_key) != 0 or (usb_in.?[3] & (1 << 6)) != 0) opbtn.?.* |= (1 << 1);
beams.?.* |= usb_in.?[3] & 0b111111;
if (GetAsyncKeyState(cfg.?.test_key) != 0 or (usb_in.?[3] & (1 << 7)) != 0) opbtn.?[0] |= (1 << 0);
if (GetAsyncKeyState(cfg.?.serv_key) != 0 or (usb_in.?[3] & (1 << 6)) != 0) opbtn.?[0] |= (1 << 1);
beams.?[0] |= usb_in.?[3] & 0b111111;
}
var coin_conter: c_ushort = 0;
@ -252,7 +243,7 @@ export fn chuni_io_slider_init() HRESULT {
}
export fn chuni_io_slider_start(callback: chuni_io_slider_callback_t) void {
if(cfg.?.chusan == 1 and builtin.cpu.arch != .i386) return;
if (cfg.?.chusan == 1 and builtin.cpu.arch != .x86) return;
if (callback == null) return;
thread_op.lock();
@ -267,7 +258,7 @@ export fn chuni_io_slider_start(callback: chuni_io_slider_callback_t) void {
}
export fn chuni_io_slider_stop() void {
if(cfg.?.chusan == 1 and builtin.cpu.arch != .i386) return;
if (cfg.?.chusan == 1 and builtin.cpu.arch != .x86) return;
thread_op.lock();
defer thread_op.unlock();
@ -279,7 +270,7 @@ export fn chuni_io_slider_stop() void {
}
export fn chuni_io_slider_set_leds(rgb: ?[*]u8) void {
if(cfg.?.chusan == 1 and builtin.cpu.arch != .i386) return;
if (cfg.?.chusan == 1 and builtin.cpu.arch != .x86) return;
if (rgb == null) return;
var n: u32 = 0;
@ -292,7 +283,7 @@ export fn chuni_io_slider_set_leds(rgb: ?[*]u8) void {
usb_out_op.lock();
defer usb_out_op.unlock();
if(WinUsb_WritePipe(tasoller, 0x03, @ptrCast(*u8, &usb_out), usb_out.len, &n, null) == 0) {
if (WinUsb_WritePipe(tasoller, 0x03, @as(*u8, @ptrCast(&usb_out)), usb_out.len, &n, null) == 0) {
std.log.warn("[chuniio] WinUsb_WritePipe: {any}", .{GetLastError()});
}
}
@ -302,7 +293,7 @@ export fn chuni_io_led_init() HRESULT{
}
export fn chuni_io_led_set_colors(board: u8, rgb: ?[*]u8) void {
if(cfg.?.chusan == 1 and builtin.cpu.arch != .i386) return;
if (cfg.?.chusan == 1 and builtin.cpu.arch != .x86) return;
if (rgb == null) return;
var n: u32 = 0;
@ -324,7 +315,7 @@ export fn chuni_io_led_set_colors(board: u8, rgb: ?[*]u8) void {
usb_out_op.lock();
defer usb_out_op.unlock();
if(WinUsb_WritePipe(tasoller, 0x03, @ptrCast(*u8, &usb_out), usb_out.len, &n, null) == 0) {
if (WinUsb_WritePipe(tasoller, 0x03, @as(*u8, @ptrCast(&usb_out)), usb_out.len, &n, null) == 0) {
std.log.warn("[chuniio] WinUsb_WritePipe: {any}", .{GetLastError()});
}
}

@ -1 +1 @@
Subproject commit a74c9dae6a1ccd361eb9a1d146a09c08d22f02b0
Subproject commit 6777f1db221d0cb50322842f558f03e3c3a4099f