Files
totk-pc-recomp/runtime/nvn_procs.c
T
Valiantsin DzerakhandClaude Opus 5.5 ce150130df Make code comments say what they mean instead of pointing at things a reader cannot follow
Comments cited codes from local notes (port-lessons P1, backlog), task labels (T6c1-T6c3, M4), bare upstream commit
hashes and issue numbers, a file that no longer exists (nvn_api.c, now nvn_api_*.c), a generated file (main_0103.c)
and line numbers into upstream files that refs/ has moved past, so they pointed at unrelated code. Those now name the
file, function or project and say what the cited code does. Attribution of copied code keeps its pinned commits.

Corrected facts: TOTK_REPLAY_ASYNC defaults to 0, and the shader cache, pipeline cache and pipeline keys live next to
totk.exe, not in build/v121.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 12:58:01 +03:00

79 lines
2.9 KiB
C

// NVN proc table. Every name the game's proc loader asks for gets a synthetic host
// address through hostfn_register before hostfn_seal; nvnBootstrapLoader and nvnDeviceGetProcAddress hand them out.
// nvnp_<name> is the implementation of one proc: the weak definitions here stop with the proc's name, nvn_api_*.c
// and nvn_ext.c define the strong ones. The name list is runtime/nvn_procs.inc (tools/gen_nvn_procs.py).
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#include "gfx.h"
#include "host.h"
// The strong nvnp_nvnDeviceGetProcAddress below replaces the stand-in generated for the same row.
#define nvnp_nvnDeviceGetProcAddress nvnp_stub_nvnDeviceGetProcAddress
#define NVN_PROC(n) void nvnp_##n(Cpu *c);
#include "nvn_procs.inc"
#undef NVN_PROC
#define NVN_PROC(n) \
__attribute__((weak)) void nvnp_##n(Cpu *c) { \
(void)c; \
rt_fatal("NVN " #n " is not implemented"); \
}
#include "nvn_procs.inc"
#undef NVN_PROC
#undef nvnp_nvnDeviceGetProcAddress
void nvnp_nvnDeviceGetProcAddress(Cpu *c);
typedef struct { const char *name; uint64_t addr; } Proc;
#define NVN_PROC(n) +1
enum { PROC_COUNT = 0
#include "nvn_procs.inc"
};
#undef NVN_PROC
static Proc procs[PROC_COUNT];
static int nprocs;
static int by_name(const void *a, const void *b) { return strcmp(((const Proc *)a)->name, ((const Proc *)b)->name); }
void nvn_procs_register(void) {
if (nprocs) return;
#define NVN_PROC(n) procs[nprocs++] = (Proc){#n, hostfn_register("nvn:" #n, nvnp_##n)};
#include "nvn_procs.inc"
#undef NVN_PROC
qsort(procs, (size_t)nprocs, sizeof *procs, by_name);
}
uint64_t nvn_proc_address(const char *name) {
if (!name) return 0;
const Proc *p = bsearch(&(Proc){name, 0}, procs, (size_t)nprocs, sizeof *procs, by_name);
if (p) return p->addr;
// Unknown names get NULL, as on hardware; each distinct one is logged once.
static SRWLOCK lock = SRWLOCK_INIT;
static char seen[32][96];
static int nseen;
AcquireSRWLockExclusive(&lock);
int fresh = 1;
for (int i = 0; i < nseen; i++)
if (!strncmp(seen[i], name, sizeof seen[i] - 1)) fresh = 0;
if (fresh && nseen < 32) {
strncpy(seen[nseen], name, sizeof seen[0] - 1);
nseen++;
} else {
fresh = 0;
}
ReleaseSRWLockExclusive(&lock);
if (fresh) rt_log("nvn: no such proc \"%s\", returning NULL", name);
return 0;
}
// PFNNVNGENERICFUNC nvnDeviceGetProcAddress(const NVNdevice *device, const char *name)
void nvnp_nvnDeviceGetProcAddress(Cpu *c) {
const char *name = arg_p(c, 1);
ret_x(c, nvn_proc_address(name));
}