Skip to content

Instantly share code, notes, and snippets.

@floooh
floooh / gfx.json
Created November 7, 2023 10:10
sokol_gfx.h auto-generated API JSON
{
"module": "gfx",
"prefix": "sg_",
"dep_prefixes": [],
"decls": [
{
"kind": "struct",
"name": "sg_buffer",
"fields": [
{
@floooh
floooh / CMakeUserPresets.json
Created January 6, 2023 19:48
my generated cmake presets file
{
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 21,
"patch": 0
},
"configurePresets": [
{
"name": "default",
@floooh
floooh / project.pbxproj
Created February 27, 2022 11:46
Fixed Xcode project file for DeferredLighting sample
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objects = {
/* Begin PBXBuildFile section */
3A2F3F23226FE35A000FACA9 /* AAPLRenderer_TraditionalDeferred.m in Sources */ = {isa = PBXBuildFile; fileRef = 3AE0241720584D0F00D9006B /* AAPLRenderer_TraditionalDeferred.m */; };
@floooh
floooh / vscode_wasm_async.ts
Last active November 16, 2021 16:30
WASM in VSCode Extension
import * as vscode from 'vscode';
import {promises as fs} from 'fs';
import * as path from 'path';
export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(vscode.commands.registerCommand('wasmtest.helloWorld', async () => {
const wasm = await load_wasm(path.join(context.extensionPath, 'media', 'bla.wasm'));
const exports: any = wasm.exports; // not sure how static typing is supposed to work here
const c_str = exports.greeting();
const js_str = c_to_js_string(c_str, exports.memory.buffer);
// PSEUDOCODE!
fn imm8(pins: u64, ticks: u64, pc: u16, tick_func: TickFunc) pins: u64, ticks: usize, pc: u16, data: u8 {
pins, ticks, data = memRead(pins, ticks, pc, tick_func);
return pins, ticks, pc +% 1, data;
}
fn memRead(pins: u64, ticks: u64, addr: u16, tick_func: TickFunc) pins: u64, ticks: usize, data: u8 {
pins, ticks = tick(setAddr(pins, addr), ticks, 3, MREQ|RD, tick_func);
return pins, ticks, getData(pins);
@floooh
floooh / zig_test_debugging_vscode.md
Last active February 5, 2024 23:46
How to debug Zig tests in VSCode

Tested on macOS:

  1. Install the CodeLLDB VSCode extension. Unlike the debugger in the C/C++ extension, this allows to set breakpoints inside Zig "test" blocks (in the MS C/C++ extension debugger, breakpoints inside test blocks will be disabled once the debugger starts for unknown reasons.
  2. When compiling the test, tell it to also emit a binary: zig test -femit-bin=zig-out/bin/my-test src/bla.zig, otherwise there will be no executable to debug.
  3. The compiled test executable expects the path to the Zig executable as first command line argument, the launch.json file needs to be setup accordingly (note the args item):
@floooh
floooh / hello.c
Created March 7, 2021 17:56
C-on-ObjC experiments...
// which is then used like this
// (helper functions like oc_alloc() and oc_alloc_init() will move into a header later)
#include <stdio.h>
#include <assert.h>
#include "hello_macos.h"
Class app_delegate_class;
id app_delegate;
@floooh
floooh / gist:f81b8ab22382dc8edbe7a45af88ae344
Created March 1, 2021 18:31
Extracting Objective-C APIs with clang -ast-dump
ENUM MTLResourceOptions
MTLResourceCPUCacheModeDefaultCache
MTLResourceCPUCacheModeWriteCombined
MTLResourceStorageModeShared
MTLResourceStorageModeManaged
MTLResourceStorageModePrivate
MTLResourceStorageModeMemoryless
MTLResourceHazardTrackingModeDefault
MTLResourceHazardTrackingModeUntracked
MTLResourceHazardTrackingModeTracked
@floooh
floooh / build.zig
Created January 14, 2021 15:12
build.zig for hello.c
const bld = @import("std").build;
pub fn build(b: *bld.Builder) void {
const exe = b.addExecutable("hello", null);
exe.addCSourceFile("hello.c", &[_][]const u8 { "" });
exe.linkLibC();
exe.install();
b.step("run", "Run hello").dependOn(&exe.run().step);
}
wasm-ninja-release ➤ ninja -v kc85
[1/8] cd /Users/floh/projects/chips-test && /usr/bin/python /Users/floh/projects/fips-build/chips-test/wasm-ninja-release/fips-gen.py /Users/floh/projects/fips-build/chips-test/wasm-ninja-release/fips_codegen.yml
[2/8] /Users/floh/projects/fips-sdks/emsdk/upstream/emscripten/emcc -I/Users/floh/projects/chips -I/Users/floh/projects/fips-imgui/imgui -I/Users/floh/projects/sokol -I/Users/floh/projects/sokol/util -I/Users/floh/projects/chips-test/examples/common -I/Users/floh/projects/chips-test/examples/roms -s DISABLE_EXCEPTION_CATCHING=1 -fstrict-aliasing -Wall -Wextra -Wno-multichar -Wno-unknown-pragmas -Wno-ignored-qualifiers -Wno-long-long -Wno-overloaded-virtual -Wno-deprecated-writable-strings -Wno-unused-volatile-lvalue -Wno-warn-absolute-paths -Wno-expansion-to-defined -Wno-missing-field-initializers -O3 -flto -s ASSERTIONS=0 -DNDEBUG -MD -MT examples/roms/CMakeFiles/roms.dir/dummy.c.obj -MF examples/roms/CMakeFiles/roms.dir/dummy.c.obj.d -o examples/roms/CMakeFiles/