Skip to content

Instantly share code, notes, and snippets.

@bryc
bryc / Adler-32.js
Last active July 11, 2024 11:22
legit checksums
// Adler-32
// Appears simpler than Fletcher, yet even better (possibly due to a = 1).
function adler32(data) {
var a = 1, b = 0;
for (var i = 0; i < data.length; i++) {
a = (a + data[i]) % 65521;
b = (b + a) % 65521;
}
return a | (b << 16);
}

DX7

image

These are the original 32 algorithms as used in Yamaha DX7.

The later Yamaha FS1R and Yamaha SY77 may have compatibility with these algorithms, but that's beyond the current scope. The FS1R contains 88 algorithms, while the SY77 contains 45 algorithms.

DX9

image

@bryc
bryc / YamahaFM.md
Last active April 17, 2026 03:27
Collecting info on Yamaha FM soundchips
@bryc
bryc / alea.js
Last active July 24, 2024 00:18
PRNGs
/*
Optimized Alea
----------------------
Based on Alea by Johannes Baagøe (2010) which is based on MWC by George Marsaglia and Arif Zaman (1991).
Should be fast and pass BigCrush statistical test suite. It's quite fast but the quality is unverified.
Used like so:
var rand = Alea("test123");
rand(); // 0.7390809920616448
rand(); // 0.3916741746943444
@bryc
bryc / rc4.js
Last active March 6, 2021 11:26
RC4
function rc4(key, data) {
var output = [], S = [], tmp, i, j = 0;
for (i = 0; i < 256; i++) {
S[i] = i;
}
for (i = 0; i < 256; i++) {
j = (j + S[i] + key[i % key.length]) % 256;
tmp = S[i];
S[i] = S[j];
S[j] = tmp;
@bryc
bryc / crc.js
Last active July 18, 2022 13:13
CRC
/*
Cyclic redundancy check (CRC-4, CRC-8, CRC-16, CRC-32)
Common CRC implementation supporting wide range of configurations:
http://reveng.sourceforge.net/crc-catalogue/all.htm
NOTE: These common polynomials are likely suboptimal.
In the future I should make a page of Koopman's best general purpose polynomials.
http://github.com/bryc
@bryc
bryc / cyrb32.c
Last active February 9, 2018 00:27
A simple but usable checksum/hash algorithm, in C.
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
unsigned char *data;
int len = 0;
int cyrb32() {
uint32_t i, tmp, sum = 0xbf3931a8;
for(i = 32; i < len; i++) {
var p = ["RHYDON","KANGASKHAN","NIDORAN_M","CLEFAIRY","SPEAROW","VOLTORB","NIDOKING","SLOWBRO","IVYSAUR","EXEGGUTOR","LICKITUNG","EXEGGCUTE","GRIMER","GENGAR","NIDORAN_F","NIDOQUEEN","CUBONE","RHYHORN","LAPRAS","ARCANINE","MEW","GYARADOS","SHELLDER","TENTACOOL","GASTLY","SCYTHER","STARYU","BLASTOISE","PINSIR","TANGELA","MISSINGNO_1F","MISSINGNO_20","GROWLITHE","ONIX","FEAROW","PIDGEY","SLOWPOKE","KADABRA","GRAVELER","CHANSEY","MACHOKE","MR_MIME","HITMONLEE","HITMONCHAN","ARBOK","PARASECT","PSYDUCK","DROWZEE","GOLEM","MISSINGNO_32","MAGMAR","MISSINGNO_34","ELECTABUZZ","MAGNETON","KOFFING","MISSINGNO_38","MANKEY","SEEL","DIGLETT","TAUROS","MISSINGNO_3D","MISSINGNO_3E","MISSINGNO_3F","FARFETCHD","VENONAT","DRAGONITE","MISSINGNO_43","MISSINGNO_44","MISSINGNO_45","DODUO","POLIWAG","JYNX","MOLTRES","ARTICUNO","ZAPDOS","DITTO","MEOWTH","KRABBY","MISSINGNO_4F","MISSINGNO_50","MISSINGNO_51","VULPIX","NINETALES","PIKACHU","RAICHU","MISSINGNO_56","MISSINGNO_57","DRATINI","DRAGONAIR","KABUTO","KABUTOPS","HORSEA","SEADRA"
function noteFromKey(keyCode) {
var char = String.fromCharCode(keyCode).toUpperCase();
if(pianoMap[char]) {
return pianoMap[char];
}
else {
return false;
}
}
/*
@bryc
bryc / !info.txt
Last active November 19, 2025 03:52
ultraSMS/MSX2 rom inserters
Original process:
ultraSMS and ultraMSX2 both have a rominserter.exe file which insert a ROM into
the respective v64 (byteswapped) emulator at a specific offset. It actually inserts the ROM byteswapped,
allowing the V64jr or other to re-swap it when loading on the N64. This is quite stupid.
The filesize of the output ROM appears to be incompatible with 64drive, and must be 1052672 bytes.
Also, to run on 64drive's USB mode, they must not be in v64 format, and must be in the original z64 format.
TODO: Load large ROMs into the rominserter and see exactly where it stops writing at. Should shed light