Skip to content

Instantly share code, notes, and snippets.

@nurpax
nurpax / test_runner.zig
Created January 1, 2024 10:30
zig test runner
// Modded from from https://gist.github.com/karlseguin/c6bea5b35e4e8d26af6f81c22cb5d76b
// in your build.zig, you can specify a custom test runner:
// const tests = b.addTest(.{
// .target = target,
// .optimize = optimize,
// .test_runner = "test_runner.zig", // add this line
// .root_source_file = .{ .path = "src/main.zig" },
// });
@nurpax
nurpax / README.md
Last active March 1, 2024 10:30
c64 size optimization -- lines

C64 "lines" size optimization contents

Deadline: midnight Finnish time on Monday, Aug 12, 2019.

Problem: make a PRG file that draws two crossing lines in C64 text mode in as few bytes as possible. The output should look exactly like this:

reference_output.png

(Note: the reference includes the black border. See the reference code for details.)

@nurpax
nurpax / main.asm
Created February 17, 2021 17:30
text example
!use "./text" as text
!byte text("testing 123")
@nurpax
nurpax / romfont_to_64c.py
Created November 29, 2020 22:03
64c from C64 ROM font binary with some chars X'd out
import numpy as np
import sys
# C64 ROM font:
# https://github.com/nurpax/petmate/raw/master/assets/system-charset.bin
unallowed_pattern = np.array([
[1, 0, 0, 0, 0, 0, 1, 0],
[1, 1, 0, 0, 0, 1, 1, 0],
@nurpax
nurpax / customop.py
Last active November 27, 2020 22:09
nvcc problem
import torch
import torch.utils.cpp_extension
def compile():
ext_name = 'ext1'
torch.utils.cpp_extension.load(name=ext_name, sources=['ext1.cpp', 'ext1cuda.cu'], with_cuda=True, verbose=True)
def main():
compile()
#include "sokol_gfx.h"
#include <assert.h>
#include "mui_renderer.h"
#include "mui_atlas.inl"
#include "HandmadeMath.h"
#include <string.h>
#define BUFFER_SIZE 16384
import numpy as np
import math
import functools
import torch
import torch.nn as nn
from torch.nn import init
import torch.optim as optim
import torch.nn.functional as F
from torch.nn import Parameter as P
!filescope c64
!macro basic_start(addr) {
* = $801
!byte $0c, $08, $00, $00, $9e
!for d in [10000, 1000, 100, 10, 1] {
!if (addr >= d) {
!byte $30 + (addr/d)%10
}
}
@nurpax
nurpax / context.js
Last active August 10, 2019 20:39
zero page allocation context example for c64jasm
module.exports = {
create: ({}, initial) => {
const stack = [initial];
return {
push: (elt) => {
stack.push(elt)
},
pop: () => stack.pop(),
top: () => {
return stack[stack.length-1];
@nurpax
nurpax / main.asm
Last active August 3, 2019 21:42
6502 lines size optimization
!include "c64.asm"
+c64::basic_start(entry)
entry: {
lda #0
sta $d020
sta $d021