Skip to content

Instantly share code, notes, and snippets.

View shirriff's full-sized avatar

Ken Shirriff shirriff

View GitHub Profile
@shirriff
shirriff / PRU-GPIO-EXAMPLE-00A0.dts
Created August 23, 2016 05:33
Device Tree file to enable BeagleBone PRU and pin P8_11. File from https://credentiality2.blogspot.com/2015/09/beaglebone-pru-gpio-example.html
// This DTS overlay sets up one input and one output pin for use by
// PRU0 via its Enhanced GPIO mode, which will let us access those pins
// by writing to R30 bit 15 or reading from R31 bit 14.
// Save this file wherever you want (but I recommend /lib/firmware), as
// "PRU-GPIO-EXAMPLE-00A0.dts".
// Compile with:
// dtc -O dtb -I dts -o /lib/firmware/PRU-GPIO-EXAMPLE-00A0.dtbo -b 0 -@ PRU-GPIO-EXAMPLE-00A0.dts
@shirriff
shirriff / tan.py
Created May 14, 2020 01:04
Demo of the 8087's CORDIC tangent algorithm
import math
# 8087 tangent algorithm, from Implementing Transcendental Functions, R. Nave
atan_table = [math.atan(2 ** -i) for i in range(0, 17)]
def cordic_tan(z):
# Compute tan of angle z, using CORDIC
q = []
# Break down z into sum of angles, where each angle is 0 or atan(2**-i)
@shirriff
shirriff / mathcrack.py
Last active January 21, 2025 00:10
Rapidly crack Xerox Alto disk passwords using a mathematical formula that reverses the password hash
# Crack Xerox Alto disk passwords using math.
import sys
def findPasswd(passvec):
# a and b are the salt values
a = (passvec[1] << 16) + passvec[2]
b = (passvec[3] << 16) + passvec[4]
if a == 0 or b == 0:
print 'No password'
@shirriff
shirriff / christmas_card.txt
Created December 7, 2017 20:05
Text file to generate a Christmas card on the IBM 1401
-
- *
- + XX
- + X XXXX
- + XXX XXXXX
- * XXXXXX XXXXXXX
- XX XXXXXXXXXXXXXXXXX
- XXXX XXXXXXXXXXXXXXXXXX
- * XXXXXX XXXXXXXXXXXXXXXXXXX
- XX XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
@shirriff
shirriff / puzzle.py
Created December 22, 2024 06:10
Solve Reddit tile puzzle
# https://www.reddit.com/r/puzzles/comments/1hjpd63/comment/m38k73k
# Port of my Arc program at https://www.righto.com/2010/12/solving-edge-match-puzzles-with-arc-and.html
# Ken Shirriff righto.com
import math
# Symbols
menorah = 1
dreidel = 2
gift = 3
@shirriff
shirriff / days-in-month
Last active June 8, 2024 14:45
HP Nanoprocessor code to determine the number of days in a month
d0 STR-0 Store the next byte (7) in register 0.
07
0c SLE Skip two instructions if accumulator <= register 0.
03 DED Decrement the accumulator in decimal mode
5f NOP No operation
d0 STR-0 Store the next byte (0x31) in register 0
31
30 SBZ-0 Skip two instruction bytes if accumulator bit 0 is zero
81 JMP-1 Jump to 0x1c9 (end of this code block)
c9
@shirriff
shirriff / edid.py
Created March 25, 2018 15:58
Parse VGA configuration data (EDID) accessed from I2C device 0x50
# Program to parse VGA data (EDID) accessed from I2C device 0x50
#
# This is a quick demo not a supported program, so don't expect
# correctness from it.
#
# Edid format from:
# https://en.wikipedia.org/wiki/Extended_Display_Identification_Data#EDID_1.4_data_format
#
# Ken Shirriff http://righto.com
@shirriff
shirriff / main.c
Last active March 16, 2024 13:51
Example code using a timer with the BeagleBone Black's PRU microcontroller. This code generates 5 pulses with 100ns width.
/*
* Demonstration of the BeagleBone's PRU, using a timer.
* Ken Shirriff, http://righto.com
*/
#include <stdint.h>
#define DELAY_NS 100 // Use 500000000 for 0.5 second delay
#define WRITE_PIN 15 /* P8_11, Ethernet output data, pr1_PRU0_pru_r30_15 */
// PRU Interrupt control registers
@shirriff
shirriff / notes.py
Last active December 23, 2021 21:13
UM66T sound chip analysis program
# This code prints out the melody in the UM66T sound chip's ROM.
# The ROM holds Jingle Bells, Santa Claus is Coming to Town, and We Wish You a Merry Christmas.
# See this Twitter thread for details: https://twitter.com/kenshirriff/status/1472297415201869831
from collections import defaultdict
notes = ['X', 'X', 'G4', 'A5', 'B5', 'C5', 'D5', 'E5', 'F5', 'G5', 'A6', 'B6', 'C6', 'X', 'X', 'X']
# Hard-coded ROM contents.
bits = {"24,1":0,"15,0":1,"15,1":0,"15,3":1,"15,4":0,"14,4":1,"13,4":0,"12,4":1,"11,4":0,"10,4":1,"9,4":1,"8,4":0,"7,4":0,"6,4":1,"5,4":1,"4,4":0,"0,4":0,"1,4":1,"2,4":1,"3,4":0,"0,1":1,"0,0":1,"3,0":1,"4,0":1,"7,0":1,"8,0":1,"11,0":1,"12,0":1,"17,0":1,"19,0":1,"20,0":1,"23,0":1,"25,0":1,"26,0":1,"29,0":1,"31,0":1,"30,1":1,"28,1":1,"26,1":1,"25,1":1,"22,1":1,"21,1":1,"18,1":1,"17,1":1,"30,5":1,"31,6":1,"30,8":1,"30,9":1,"30,10":1,"31,11":1,"31,13":1,"31,14":1,"30,15":1,"31,16":1,"30,18":1,"30,19":1,"31,20":1,"31,21":1,"30,23":1,"31,24":1,"31,25":1,"31,26":1,"31,28":1,"30,29":1,"30,28":0,"29,
#!/usr/bin/python
""" Download an IR remote signal from a Rigol DS1052E and
analyze it for a NEC protocol signal.
Ken Shirriff
http://righto.com
"""
import array
import sys