Skip to content

Instantly share code, notes, and snippets.

@bryc
bryc / sum1.a80
Created March 31, 2026 06:25
Checksums written in 8-bit Assembly
.cpu 8080
; 8-bit Modulo-255 checksum (aka end-around-carry) - Null terminator version
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
start:
mvi C, $00 ; Initialize checksum value to zero
lxi H, data ; Store the RAM address of our input data, in register HL
csum:
mov A, M ; Get next input byte (Accumulator = RAM at address HL)
cpi 0 ; If Accumulator is zero, enable zero flag
jz done ; If zero flag is set, break out of loop
// Optimal version of the XS1 checksum function.
function xs1cksm(data) {
let sum = [0, 0];
for(let i = 0, tmp; i < data.length; i++) {
tmp = (Math.imul(data[i], i) + sum[0] + 1994) >>> 0;
sum[1] = (sum[1] + (tmp < sum[0] ? 1 : 0)) >>> 0;
sum[0] = tmp;
}
return sum;
// some color conversion code i didnt end up using but might as well put somewhere
function hcl2rgb(arr) {
function lab2xyz(t){return t>6/29?t*t*t:6/29*3*(6/29)*(t-4/29)}
function xyz2rgb(x){return 255*(x<=.0031308?12.92*x:1.055*Math.pow(x,1/2.4)-.055)}
var h = arr[0], c = arr[1], l = arr[2];
y = (l+16)/116,
a = Math.cos(h)*c, b = Math.sin(h)*c,
x = isNaN(a)?y:y+a/500, z = isNaN(b)?y:y-b/200;
<script>
for(rnd=w=>'#'+Math.random().toString(16).slice(-6),i=0;i<99;i++)
document.write(`<div style=background:linear-gradient(0.25turn,${rnd()},${rnd()},${rnd()},${rnd()})></div>`)
</script>
<style>body{background:#222;column-count:3;column-gap:6px}div{height:48;break-inside:avoid}</style>
<!--
background: repeating-linear-gradient(45deg, #3f87a6, #ebf8e1 5%, #f69d3c 20%);
clip-path: polygon(5% 5%, 100% 0%, 100% 75%, 75% 75%, 75% 100%, 50% 75%, 0% 75%);
-->
@bryc
bryc / st.txt
Created November 20, 2019 22:47
Scream Tracker Manual (1990)
Scream Tracker
<<<<< USERS MANUAL >>>>>
(C) 1990 Sami Tammilehto
==============================================================================
@bryc
bryc / VRC7_patch_guesses.txt
Last active February 3, 2020 06:02
not mine, just a collection
// Patch names
1 Buzzy Bell
2 Guitar
3 Wurly
4 Flute
5 Clarinet
6 Synth
7 Trumpet
8 Organ
9 Bells
@bryc
bryc / crc16.js
Last active May 8, 2023 03:15
Optimized CRC implementations in JavaScript
/*
Optimized CRC-16 for 0x1021 (unreflected)
----
With this code, (5) CRC-16 variants can be modelled:
crc=0x0000, xorout=0x0000 = CRC-16/XMODEM (default)
crc=0xFFFF, xorout=0x0000 = CRC-16/IBM-3740
crc=0xFFFF, xorout=0xFFFF = CRC-16/GENIBUS
crc=0x0000, xorout=0xFFFF = CRC-16/GSM
@bryc
bryc / lzjb.js
Last active October 18, 2019 08:22
proof of concept tiny compression
// tiny simple hash (TSH)
TSH=s=>{for(var i=0,h=6,c=5;i<s.length;)h=Math.imul(h^s[i],9**9),c=Math.imul(c^s[i++],7**9);return 2**32*(2097151&(c^c>>>9))+(h^h>>>9)}
// LZB minified 512 bytes.
LZB={e:(e,f)=>{for(var r,l,o,i,s,a=0,g=0,h=128,n=[],t=e.length;a<t;)if(256==(h<<=1)&&(h=1,l=g,f[g++]=0),a>t-3)f[g++]=e[a++];else if(i=a-n[s=66*e[a]^33*e[a+1]^e[a+2]]&1023,n[s]=a,(r=a-i)!=a&&e[a]==e[r]&&e[a+1]==e[r+1]&&e[a+2]==e[r+2]){for(o=3;o<66&&e[a+o]==e[r+o];o++);a+=o,f[l]|=h,f[g++]=o-3<<2|i>>8,f[g++]=i&255}else f[g++]=e[a++]},d:(e,f)=>{for(var r,l,o,i=0,s=0,a=128;i<e.length;)if(256==(a<<=1)&&(a=1,l=e[i++]),l&a)for(r=s-(1023&(e[i]<<8|e[i+1])),o=3+(e[i]>>2),i+=2;o>0;o--)f[s++]=f[r++];else f[s++]=e[i++]}}
var sum = [], packed = [], unpacked = [], data = [0,0,0,0,0,0,0,0,9,0,255,79,127,191,191,191,143,5,4,7,129,0,0,0,0,0,0,0,0,0,3,1,0,0,0,1,0,103,60,84,47,53,27,26,30,2,0,0,0,0,0,0,68,65,7,109,0,0,0,0,0,0,0,0,9,0,255,79,127,191,191,191,143,5,4,7,129,0,0,0,0,0,0,0,0,0,3,1,0,0,0,1,0,103,60,84,47,53,27,26,30,2,0,0,0,0,0,0,68,
@bryc
bryc / base.js
Last active December 13, 2018 08:16
// Arbitrary precision base conversion, WIP
function baxx(str, src_base, dst_base) {
var number = [], output = "", res = [], quotient, remainder;
var charset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
//decode
for(var i = 0; i < str.length; i++) number[i] = charset.indexOf(str[i]);
while (number.length) {
// divide successive powers of dst_base
quotient = [], remainder = 0;
/*
a mockup of a fileformat with a 8 byte header. 56-bit magic, 8-bit version code, and 64-bit hash.
*/
var data = [250,222,222,175,98,83,80,0,149,227,98,114,223,2,65,139,212,54,64,54,169,172,160,90,58,126,203,87,217,240,53,186,160,226,221,133,70,56,95,24,49,66,201,41,182,75,120,164,236,222,80,145,147,117,15,88,219,136,158,2,20,70,140,78,163,103,32,199,173,219,175,24,97,78,33,93,215,188,212,50,218,155,63,171,40,68,17,134,244,173,170,70,180,159,32,245,135,233,57,203,196,84,18,249,120,73,72,71,223,101,226,87,42,132,104,173,25,242,197,218,55,191,232,94,192,124,90,38,130,209,31,191,73,175,162,149,144,23,144,228,157,185,200,43,59,215,220,70,173,60,188,142,168,51,132,136,82,197,155,28,157,175,122,82,138,217,234,9,24,64,128,54,248,145,159,140,63,244,94,168,188,196,252,32,159,36,223,9,154,195,52,215,181,53,168,184,107,167,233,180,210,240,211,64,230,41,117,26,64,97,101,137,182,14,0,84,201,78,142,38,219,37,110,27,125,58,187,170,101,208,21,58,211,245,119,11,118,33,74,61,23,197,29,34,155,132,182,48,37,20,89,44,106,253,1