Skip to content

Instantly share code, notes, and snippets.

View shirriff's full-sized avatar

Ken Shirriff shirriff

View GitHub Profile
@shirriff
shirriff / bin.cmd
Created September 19, 2016 17:15
Linker file for BeagleBone Black PRU code. This creates loadable image files text.bin and data.bin.
-b
-image
ROMS {
PAGE 0:
text: o = 0x0, l = 0x1000, files={text.bin}
PAGE 1:
data: o = 0x0, l = 0x1000, files={data.bin}
}
@shirriff
shirriff / loader.c
Created September 19, 2016 21:07
Loads a PRU text.bin (and optionally data.bin) file, executes it, and waits for completion. This version enables timer interrupt 15 for the PRU.
// Loads a PRU text.bin (and optionally data.bin) file,
// executes it, and waits for completion.
// This version enables interrupt event 15 (ecap timer)
//
// Usage:
// $ ./loader text.bin [data.bin]
//
// Compile with:
// gcc -o loader loader.c -lprussdrv
//
@shirriff
shirriff / main.c
Last active September 19, 2016 22:18
C code to blink an LED on the BeagleBone, using the PRU microcontroller.
/*
* blink demo: blink LED ten times
* LED should be connected to P8_11 (pr1_pru0_pru_r30_15)
*
*/
volatile register unsigned int __R31, __R30;
int main(void) {
unsigned int loops, delay;
for (loops = 0; loops < 10; loops++) {
@shirriff
shirriff / mandel.bcpl
Last active June 18, 2017 16:25
Mandelbrot set code for the Xerox Alto, written in BCPL.
get "streams.d"
external
[
Ws;
Wns;
MulFull;
DoubleAdd;
keys;
Gets;
]
@shirriff
shirriff / ac2.py
Created December 7, 2017 18:37
Analyze air conditioner checksum by reversing bytes and summing nibbles.
import re
data="""\
10100001 10010011 01100011 => 01110111
10100001 10010011 01100100 => 01110001
10100001 10010011 01100101 => 01110000
10100001 10010011 01100110 => 01110010
10100001 10010011 01100111 => 01110011
10100001 10010011 01101000 => 01111001
10100001 10010011 01101001 => 01111000
@shirriff
shirriff / ac3.py
Created December 7, 2017 18:38
Create checksums for an air conditioner remote control
import re
# Each line is 3 bytes of input and the observed 1-byte checksum
data="""\
10100001 10010011 01100011 => 01110111
10100001 10010011 01100100 => 01110001
10100001 10010011 01100101 => 01110000
10100001 10010011 01100110 => 01110010
10100001 10010011 01100111 => 01110011
10100001 10010011 01101000 => 01111001
@shirriff
shirriff / ac.py
Created December 7, 2017 18:31
Process air conditioner remote control data: find inputs differing in one bit and print the difference in the output.
import re
data="""\
10100001 10010011 01100011 => 01110111
10100001 10010011 01100100 => 01110001
10100001 10010011 01100101 => 01110000
10100001 10010011 01100110 => 01110010
10100001 10010011 01100111 => 01110011
10100001 10010011 01101000 => 01111001
10100001 10010011 01101001 => 01111000
@shirriff
shirriff / PRU code
Last active January 8, 2018 21:33
Fragment of PRU code to output Manchester-encoded data.
for (bit_count = 0; bit_count < 8; bit_count++) {
if (byte & 0x80) {
wait_for_pwm_timer();
__R30 = HIGH << WRITE_PIN;
wait_for_pwm_timer();
__R30 = LOW << WRITE_PIN;
} else {
wait_for_pwm_timer();
__R30 = LOW << WRITE_PIN;
wait_for_pwm_timer();
@shirriff
shirriff / nopassword.py
Created January 4, 2018 02:31
Disable password protection on an Alto disk by zeroing out the password flag in sys.boot
# Disable password protection on an Alto disk by zeroing out the password flag in sys.boot
import sys
import subprocess
diskContents = None
# Get word at the word offset in the disk file
def getWord(wordOffset):
return ord(diskContents[2 * wordOffset]) + ord(diskContents[2 * wordOffset + 1]) * 256
@shirriff
shirriff / fpga-font.py
Created April 4, 2018 03:36
Generate FPGA code to implement a character set
# Process font file to generate FPGA code
# Font from https://github.com/dhepper/font8x8/blob/master/font8x8_basic.h
import re
chars = []
for line in open('font8x8_basic.h').readlines():
m = re.search('{([\s0-9A-Fa-fx,]*)}', line)
if m: