Skip to content

Instantly share code, notes, and snippets.


whitequark whitequark

View GitHub Profile
whitequark /
Last active Jan 22, 2021
JT51 + CXXRTL + VGM = <3 <3
// Step 1: Obtain Yosys from git.
// Step 2: Download jt51 from
// Step 3: Build as follows:
// $ yosys jt51/hdl/*.v -b 'cxxrtl -header' -o
// $ CFLAGS="-fbracket-depth=2048 -I$(yosys-config --datdir/include)"
// $ clang++ -O3 $CFLAGS -o jt51_play
// Step 4: Convert as follows:
// $ python3 music.vgm music.tsv
// Step 5: Play as follows (assuming YM2151 clocked at 4 MHz):
// $ ./jt51_play music.tsv music.wav 4000000
whitequark /
Last active Dec 22, 2020
JT51 + CXXRTL = <3
// Step 1: Obtain latest Yosys from
// Step 2: Download jt51 from
// Step 3: Build as follows:
// $ yosys jt51/hdl/*.v -b 'cxxrtl -header' -o
// $ CFLAGS="-fbracket-depth=2048 -I$(yosys-config --datdir/include)"
// $ clang++ -O3 $CFLAGS -o jt51_sim
// Step 4: Enjoy!
#include <fstream>
#include <backends/cxxrtl/cxxrtl_vcd.h>
View magpie.rkt
#lang rosette/safe
(require rosette/lib/angelic
(only-in racket/base syntax->datum))
(define-syntax-rule (define-distinct v x ...)
(define x v) ...
(assert (distinct? x ...))))
(define-syntax-rule (list-choices x ... sol)
(list (list (evaluate x sol) (syntax->datum #'x)) ...))
whitequark / minlogic.rkt
Last active Apr 12, 2020
Logic minimizer with a configurable cost function in 50 lines of Rosette (
View minlogic.rkt
#lang rosette/safe
(require rosette/lib/angelic
(define (^^ x y) (|| (&& x (! y)) (&& (! x) y)))
(struct lnot (a) #:transparent)
(struct land (a b) #:transparent)
(struct lor (a b) #:transparent)
(struct lxor (a b) #:transparent)
(struct lvar (v) #:transparent)
View synth51.rkt
#lang rosette/safe
(require rosette/lib/angelic
(current-bitwidth #f)
(require (only-in racket list*))
; bit operations
(define (rotate-right i x)
whitequark /
Created Oct 14, 2019
file transfer via `echo -ne`
#!/usr/bin/env python3
import argparse
parser = argparse.ArgumentParser()
"file", metavar="FILE", type=argparse.FileType("rb"),
help="source file")
View _delay_4c.asm
lcall _delay_4c
sjmp .
; (ljmp delay_4c) ; 0c > 4c
mov acc, dph ; 3c
cjne a, #0, 00000$ ; 4c > 11c [A]
mov acc, dpl ; 3c
subb a, #(24/4+1) ; 2c
inc a ; 1c
whitequark / glasgow-applet-taxonomy.txt
Created Mar 3, 2019
See files in subdirectories of for details, including specific examples and counterexamples.
View glasgow-applet-taxonomy.txt
The ``interface`` taxon is the most fundamental and generic applet taxon. It groups applets
implementing interfaces that are used for purposes that do not fit into any single other taxon.
Because the ``interface`` taxon is so important, the applet names in this taxon are not prefixed
with the taxon name.
The ``memory`` taxon groups applets implementing interfaces to memory technology devices (volatile
and non-volatile) that include no functionality beyond manipulating data.
View gist:0451b9f1848c24fcfae383df12136ed2
# Macronix 25L6473E
$ glasgow run spi-flash-25c -V 3.3 --pin-ss 0 --pin-miso 1 --pin-mosi 2 --pin-sck 3 --pin-hold 4 identify
I: glasgow.device.hardware: device already has bitstream ID fd8d97b20930df7f44ace0a704c715e6
I: glasgow.cli: running handler for applet 'spi-flash-25c'
I: glasgow.applet.spi_flash_25c: port(s) A, B voltage set to 3.3 V
I: glasgow.applet.spi_flash_25c: JEDEC manufacturer 0xc2 (Macronix) device 0x2017
I: glasgow.applet.spi_flash_25c: device has valid SFDP 1.0 (JESD216) descriptor
I: glasgow.applet.spi_flash_25c: SFDP table #0: JEDEC, Flash Parameter Table 1.0 (JESD216)
I: glasgow.applet.spi_flash_25c: density (Mbits) : 64
I: glasgow.applet.spi_flash_25c: density (Mbytes) : 8