Skip to content

Instantly share code, notes, and snippets.

View mlarouche's full-sized avatar

Michaël Larouche mlarouche

View GitHub Profile
@mlarouche
mlarouche / actraiser_wip_msu1.asm
Created December 21, 2015 04:31
ActRaiser MSU-1 WIP Code
arch snes.cpu
// MSU memory map I/O
constant MSU_STATUS($2000)
constant MSU_ID($2002)
constant MSU_AUDIO_TRACK_LO($2004)
constant MSU_AUDIO_TRACK_HI($2005)
constant MSU_AUDIO_VOLUME($2006)
constant MSU_AUDIO_CONTROL($2007)
@mlarouche
mlarouche / rawobjcopy.zig
Created January 24, 2020 03:11
objcopy -O binary clone in Zig
const Allocator = @import("std").mem.Allocator;
const ArenaAllocator = @import("std").heap.ArenaAllocator;
const ArrayList = @import("std").ArrayList;
const File = @import("std").fs.File;
const HeapAllocator = @import("std").heap.HeapAllocator;
const elf = @import("std").elf;
const fs = @import("std").fs;
const io = @import("std").io;
const sort = @import("std").sort;
@mlarouche
mlarouche / Result_PC
Created February 9, 2020 14:56
__divsi3 and __udivsi3 issues on Thumb1
fixed=2048
fixed2=640
result=3.51 / 819
@mlarouche
mlarouche / win32_helloworld.zig
Created February 22, 2020 18:34
win32 hello world
usingnamespace @import("std").os.windows;
extern "user32" fn MessageBoxA(hWnd: ?HANDLE, lpText: ?LPCTSTR, lpCaption: ?LPCTSTR, uType: UINT) callconv(.Stdcall) c_int;
pub export fn WinMain(hInstance: ?HINSTANCE, hPrevInstance: ?HINSTANCE, lpCmdLine: ?LPWSTR, nShowCmd: INT) callconv(.Stdcall) INT {
_ = MessageBoxA(null, "Zig is pretty great!", "Wow much exposure", 4);
return 0;
}
@mlarouche
mlarouche / com_call.zig
Last active February 24, 2020 04:46
Generic COM call
fn comFindReturnType(comptime vTableType: type, comptime name: []const u8) type {
for (@typeInfo(vTableType).Struct.fields) |field| {
if (std.mem.eql(u8, field.name, name)) {
const funcType = @typeInfo(@typeInfo(field.field_type).Optional.child);
return funcType.Fn.return_type.?;
}
}
return void;
}
@mlarouche
mlarouche / final_result.zig
Last active February 26, 2020 04:03
How to call a function via reflection?
fn findImageFormat(inStream: *ImageInStream, seekStream: *ImageSeekStream) !ImageFormat {
const allFuncs = comptime blk: {
// TODO: Use ArrayList when Zig support compile-time allocator
var result:[16]fn(inStream: *ImageInStream, seekStream: *ImageSeekStream) anyerror!ImageFormat = undefined;
var index:usize = 0;
inline for (std.meta.declarations(AllImageFormats)) |decl| {
switch(decl.data) {
.Type => |entryType| {
const entryTypeInfo = @typeInfo(entryType);
if (entryTypeInfo== .Struct) {
@mlarouche
mlarouche / debug_ir.log
Created March 6, 2020 20:53
zigimg test Debug IR crash Linux
This file has been truncated, but you can view the full file.
; ModuleID = 'test'
source_filename = "test"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
%"[]u8" = type { i8*, i64 }
%std.builtin.StackTrace = type { i64, %"[]usize" }
%"[]usize" = type { i64*, i64 }
%std.target.LinuxVersionRange = type { %std.builtin.Range, %std.builtin.Version }
@mlarouche
mlarouche / build.json
Created August 15, 2020 22:58
Build platform optionally
{
"os": "windows",
"libraries": [
"c",
"d3d12",
"dxgi",
"d3dcompiler",
"dxguid"
],
"include_dirs": [],
@mlarouche
mlarouche / zig_d3d12.zig
Last active September 14, 2020 21:28
Direct3D12 Sample in Zig
const std = @import("std");
const win32 = @import("win32.zig");
const d3d12 = @import("d3d12.zig");
const dxgi = @import("dxgi1_4.zig");
const d3dcompiler = @import("d3dcompiler.zig");
const windows = std.os.windows;
const L = std.unicode.utf8ToUtf16LeStringLiteral;
@mlarouche
mlarouche / command_list.zig
Last active March 13, 2022 12:27
free function to Self wrapper
const std = @import("std");
const platform = @import("../platforms/platform.zig").platform;
const GpuResource = @import("gpu_resource.zig").GpuResource;
pub const CommandListKind = enum {
Graphics,
Compute,
Copy,
};