Skip to content

Instantly share code, notes, and snippets.

@SonoSooS
SonoSooS / DMGCPU.MD
Last active June 12, 2024 02:17
Game Boy CPU internals

This document is intended to document certain inner workings of the CPU.

There have been efforts by emu-russia and gekkio to have the CPU decapped, and so we have the decode ROM accessible to us. This means, that we know exactly what each opcode does (besides some nuanced behavior related to HALT, STOP, and some state management related to interrupts and power saving which are hard to untangle).

Table of contents

@Random832
Random832 / dither.py
Created April 23, 2021 20:38
bayer dithering experiment
import numpy as np
from PIL import Image
import sys
im = Image.open('chart.png')
im2 = np.array(im)
factor = 127 # 84
@whitequark
whitequark / jt51_player.cc
Last active January 22, 2021 02:22
JT51 + CXXRTL + VGM = <3 <3
// Step 1: Obtain Yosys from git.
// Step 2: Download jt51 from https://github.com/jotego/jt51.
// Step 3: Build as follows:
// $ yosys jt51/hdl/*.v -b 'cxxrtl -header' -o jt51_core.cc
// $ CFLAGS="-fbracket-depth=2048 -I$(yosys-config --datdir/include)"
// $ clang++ -O3 $CFLAGS jt51_core.cc jt51_player.cc -o jt51_play
// Step 4: Convert as follows:
// $ python3 vgm2tsv.py music.vgm music.tsv
// Step 5: Play as follows (assuming YM2151 clocked at 4 MHz):
// $ ./jt51_play music.tsv music.wav 4000000
@abarisani
abarisani / usb_fingerprinting.md
Last active May 5, 2022 11:47
Fingerprinting USB enumeration from different hosts

Introduction

The following information illustrates the differences between macOS, Windows and Linux in USB device enumeration sequence.

Specifically the comparison covers USB Mass Storage device enumeration, implemented with the TamaGo USB driver on a USB armory Mk II running armory-ums.

// The MIT License (MIT)
//
// Copyright (c) 2018 Darrell Wright
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files( the "Software" ), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
@withoutboats
withoutboats / constraint-kinds.md
Last active January 9, 2023 17:14
Constraint Kinds in Rust

Notes on adding Constraint Kinds to Rust

Background: Constraint Kinds

a trait can be thought of as a type operator generating a "constraint" - what in Rust would usually be called a bound. For example:

// Declares a new item `Foo` with kind `type -> constraint`
trait Foo { }
@evanw
evanw / 0_stackify.ts
Last active June 11, 2024 21:18
Example "stackify" algorithm for turning SSA into WASM
// This code demonstrates a simplified "stackification" algorithm to turn
// instructions in a basic block back into a tree. This is useful when
// generating WebAssembly code from assembly instructions in SSA form.
//
// It's the algorithm used by LLVM's WebAssembly backend, viewable here:
// https://github.com/llvm-mirror/llvm/blob/master/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp
type InsKind =
'Add' |
'LocalSet' |
@berk76
berk76 / memory_model.md
Last active June 18, 2024 19:32
DOS: Choosing a memory model
C News  Vol. 1  Issue 11                         Sept 15, 1988


        CHOOSING A MEMORY MODEL by Bill Mayne

        ABSTRACT:   The  meaning  of  the  "near",  "far",  and  "huge"
        keywords specifying pointer types and how these are related  to
        the  various memory models available to C programmers using the
        80x86 family of processors used in IBM and compatible  PCs  and
@mithro
mithro / merge-migen+misoc.sh
Last active May 17, 2018 04:25
Prepare an upstream migen/misoc for merging into litex
#! /bin/bash
set -x
set -e
function git_commit {
git commit -a -m"litex import: $1"
}
mkdir -p repos
@lynn
lynn / miscellany.v
Created October 7, 2017 15:19
Old Coq proofs from my hard drive
(* CanHalveEven.v *)
Inductive Even : nat -> Prop :=
| Even_base : Even 0
| Even_step : forall n, Even n -> Even (S (S n)).
Check Even_ind.
Theorem can_halve_even :
forall n, Even n -> (exists k, k + k = n).