Skip to content

Instantly share code, notes, and snippets.

@averne
averne / patching.md
Created August 19, 2020 11:05
Patching nxmtp

Patching nxmtp to receive input on 9.0.0+

On firmwares 9.0.0+, the HID shared memory won't update values for the controller libnx uses, unless it is explicitely specified as supported. The fix is as simple as changing the bitflag passed to nn::hid::SetSupportedNpadStyleSet, from 0x1f to 0x6000001f (see here).

Aarch64 doesn't allow loading immediate values of size bigger than 16-bit unsigned, so we need to split the loading into two instructions:

becomes:

.PHONY: all
CFLAGS := -O2 -g -std=gnu11 -flto
CXXFLAGS := -O2 -g -std=gnu++2a -flto
CC := gcc-10
CXX := g++-10
TARGETS := bench-stbi bench-tj bench-nj bench-tvmr bench-nvjpg
@averne
averne / main.c
Last active November 30, 2021 20:38
#include <switch.h>
void __libnx_initheap(void) { }
void __appInit(void) { }
void __appExit(void) { }
#define DISP_IO_BASE 0x54200000
#define DISP_IO_SIZE (8 * 0x1000)
#define DC_CMD_INT_ENABLE 0xe4
@averne
averne / dksh.py
Created January 16, 2022 11:49
Parser for deko3d shader files
#!/usr/bin/env python3
# See https://github.com/devkitPro/deko3d/blob/master/source/dksh.h
import os, sys
import ctypes, enum
class DkProgramType(enum.Enum):
Vertex = 0
Fragment = 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <switch.h>
#include <deko3d.h>
int main(int argc, char **argv) {
consoleInit(NULL);
padConfigureInput(1, HidNpadStyleSet_NpadStandard);
@averne
averne / nvdec_deko3d.c
Last active August 28, 2023 08:50
NVDEC/deko3d interop
// Sample code (untested) for interop between NVDEC and deko3d
// * This only maps the luma plane, as an R8 texture (thus assuming 8-bit data),
// for 10+ bit you would need R16
// * For the chroma plane, the memblock can be shared with the luma plane,
// but you would need a new layout using R8G8 (R16G16 for 10+ bit),
// to adjust the width and height for subsampling,
// and to use (frame->data[1] - frame->data[0]) as offset into the memblock
// * Note that hardware decoding backbuffers are issued (and reused) from a pool,
// thus for efficient use you can cache images/buffer mappings.
// The map handle (ff_tx1_map_get_handle(map)) can be used a key for this.