Skip to content

Instantly share code, notes, and snippets.

Avatar

whitequark whitequark

View GitHub Profile
@whitequark
whitequark / jt51_player.cc
Last active Jan 22, 2021
JT51 + CXXRTL + VGM = <3 <3
View jt51_player.cc
// 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
@whitequark
whitequark / jt51_driver.cc
Last active Dec 22, 2020
JT51 + CXXRTL = <3
View jt51_driver.cc
// Step 1: Obtain latest Yosys from https://github.com/YosysHQ/yosys/.
// 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_driver.cc -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 ...)
(begin
(define x v) ...
(assert (distinct? x ...))))
(define-syntax-rule (list-choices x ... sol)
(list (list (evaluate x sol) (syntax->datum #'x)) ...))
@whitequark
whitequark / minlogic.rkt
Last active Apr 12, 2020
Logic minimizer with a configurable cost function in 50 lines of Rosette (https://github.com/emina/rosette)
View minlogic.rkt
#lang rosette/safe
(require rosette/lib/angelic
rosette/lib/match)
(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
rosette/lib/match)
(current-bitwidth #f)
(require (only-in racket list*))
; bit operations
(define (rotate-right i x)
@whitequark
whitequark / echofile.py
Created Oct 14, 2019
file transfer via `echo -ne`
View echofile.py
#!/usr/bin/env python3
import argparse
parser = argparse.ArgumentParser()
parser.add_argument(
"file", metavar="FILE", type=argparse.FileType("rb"),
help="source file")
parser.add_argument(
View _delay_4c.asm
lcall _delay_4c
sjmp .
_delay_4c::
; (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
whitequark / glasgow-applet-taxonomy.txt
Created Mar 3, 2019
See __init__.py files in subdirectories of https://github.com/whitequark/Glasgow/tree/master/software/glasgow/applet 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