Skip to content

Instantly share code, notes, and snippets.

Avatar

Ken Shirriff shirriff

View GitHub Profile
@shirriff
shirriff / days-in-month
Last active Aug 31, 2020
HP Nanoprocessor code to determine the number of days in a month
View days-in-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 / tan.py
Created May 14, 2020
Demo of the 8087's CORDIC tangent algorithm
View tan.py
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 / music_1401.txt
Created Sep 7, 2019
Music program for the IBM 1401, along with frequency cards. Courtesy of Ron Mak.
View music_1401.txt
,008015,022033L067135,1050291001/099H104C104135B101/,0011/001199199 0001MUSIC
,109116,121125,126133/101099 0002MUSIC
,008015,022029,036040,047054,061068,072/061039 ,00100110400003MUSIC
0000000000000,001/000H099L/49089 L032118,092097,100104,10811210400004MUSIC
L/490941C003/53B334SM0996J5B165DL/54354L039157,126127,134139,14615110400005MUSIC
M0756J1A/56094M0660?0H0991L0660?0H099 L037194,165172,179183,18419110400006MUSIC
A/57089C089/59B126U.100 L023217,202209,214040,04004010400007MUSIC
M585099/332/,0052011N372M002005 L031364,341345,346353,35435810400008MUSIC
M/60002B564001XB353001 B503001RL/49089 L038402,372380,388396,04004010400009MUSIC
C0036/1B438SA/56089C089094B403U.100 L035437,410415,422429,43404010400010MUSIC
@shirriff
shirriff / music-1403.txt
Created Sep 2, 2019
Disassembly of a vintage program to generate music on an IBM 1403 line printer.
View music-1403.txt
87 00000 # X0
92 00000 # X1
97 000 # X2
100 ,001 set wordmark 1 # Start
104 /000 clear storage 0 # Wraps to top of memory?
108 H099 store B* 99 # Top of memory - 100? into X2
112 L/49089 load 1149 89 # X1 = 0
119 L/49094 load 1149 94 # X2 = 0
126 1 read # READNOTE: Read first card
127 C003/53 compare 3 1153 # Card has END?
@shirriff
shirriff / prime1.s
Created Jun 21, 2018
Generate primes up to 255 on the IBM 1401
View prime1.s
job prime1.s
* Compute primes 2-255 for toggle challenge
* Ken Shirriff http://righto.com
ctl 6641
org 201 * Start of print buffer
num dcw 002 * Current number
org 333 * Start of code memory
outer mcw @002@, factor * Start with factor 2
@shirriff
shirriff / fpga-font.py
Created Apr 4, 2018
Generate FPGA code to implement a character set
View fpga-font.py
# 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:
@shirriff
shirriff / fpga-font.py
Created Apr 4, 2018
Generate FPGA code to implement a character set
View fpga-font.py
# 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:
@shirriff
shirriff / edid.py
Created Mar 25, 2018
Parse VGA configuration data (EDID) accessed from I2C device 0x50
View edid.py
# 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 / PRU code
Last active Jan 8, 2018
Fragment of PRU code to output Manchester-encoded data.
View PRU code
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 / password.c
Created Jan 4, 2018
Use brute force to crack the password on a Xerox Alto disk.
View password.c
#include <stdint.h>
#include <stdlib.h>
#include <strings.h>
#include <stdio.h>
int64_t count = 0;
// Password vector from sys.boot. Must be big-endian.
// Disk 47
uint16_t passvec[] = {0xffff, 0xcfa7, 0x9f3d, 0x669a, 0xf2bb, 0xf193, 0x6d09, 0x4571, 0xe1d1};
You can’t perform that action at this time.