Skip to content

Instantly share code, notes, and snippets.

View bit-hack's full-sized avatar

Aidan Dodds bit-hack

View GitHub Profile
@bit-hack
bit-hack / keyboard_decode.v
Created October 4, 2018 22:46
Verilog - simple PS/2 keyboad decoder
// PS/2 keyboard decoder for Altera DE1 Kit
// decode 7 seg
module decode_seven_seg(
input [3:0] dec,
output [6:0] out);
reg [6:0] val;
initial val = 0;
@bit-hack
bit-hack / decode_7_seg.v
Last active October 3, 2018 22:06
decode seven segment display for Altera DE1 kit
// decode 7 seg on DE1 kit
module decode_seven_seg(
input clk,
input [3:0] dec,
output [6:0] out);
reg [6:0] val;
initial val = 0;
always @(posedge clk) begin
case (dec)
@bit-hack
bit-hack / 8086.c
Created September 27, 2018 09:12
8086 cpu emulator
/*
Fake86: A portable, open-source 8086 PC emulator.
Copyright (C)2010-2013 Mike Chambers
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
@bit-hack
bit-hack / pi_calc.cpp
Created September 27, 2018 00:20
Taylor seried to calculate pi in fixed point
#include <stdint.h>
int main() {
const int32_t fx = 1048576;
int32_t z = 4 * fx;
int32_t j = -1;
for (int32_t i = 3; i < 4096; i += 2) {
@bit-hack
bit-hack / mandelbrot.cpp
Last active September 25, 2018 10:30
Mandelbrot set
// from http://blog.nothinguntoward.eu/?p=38
#include <cstdio>
#include <cmath>
using namespace std;
int main() {
const int width = 80;
@bit-hack
bit-hack / ccml_peep_hole_spans.txt
Created September 12, 2018 08:57
Peephole spans for CCML
This file has been truncated, but you can view the full file.
---- ---- ---- ----
INS_CONST 0016
---- ---- ---- ----
INS_CONST 0101
INS_CONST 0037
INS_CONST 0008
INS_CALL 0000
INS_CALL 0000
INS_POP 0001
INS_CONST 0107
@bit-hack
bit-hack / vm.cpp
Last active August 17, 2018 08:20
A small weakly typed virtual machine core in c++
#include <assert.h>
#include <list>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
enum object_type_t { e_none, e_integer, e_string, e_boolean, e_array };
@bit-hack
bit-hack / rtti.cpp
Created July 27, 2018 00:12
Very simple rtti
#include <assert.h>
struct rtti_t {
template <typename type_t>
bool is_a() const {
return _tag == type_t::tag;
}
@bit-hack
bit-hack / dct.py
Created July 4, 2018 22:40
a small example of the discrete cosine transform
import math
def _dct(octave, t):
return math.cos(math.pi * octave * t)
def _product(func, width, accum, octave):
''' compute the contribution of an octave '''
p = 0.0
@bit-hack
bit-hack / int_band_lim_wave.c
Last active July 3, 2018 08:49
16bit signed band limited dithered waveform data
static const int16_t bl_sqr_1024[] = {
0x063e, 0x1288, 0x1e3e, 0x2909, 0x32a0, 0x3ac3, 0x414d, 0x462e,
0x496a, 0x4b1c, 0x4b6b, 0x4a92, 0x48d7, 0x467f, 0x43d9, 0x4128,
0x3eaa, 0x3c8f, 0x3b00, 0x3a0f, 0x39c2, 0x3a10, 0x3ae4, 0x3c20,
0x3da1, 0x3f39, 0x40c8, 0x4228, 0x433c, 0x43f2, 0x443f, 0x4421,
0x43a6, 0x42da, 0x41d6, 0x40b4, 0x3f92, 0x3e88, 0x3db0, 0x3d16,
0x3cca, 0x3ccc, 0x3d1c, 0x3dab, 0x3e6a, 0x3f46, 0x402c, 0x4104,
0x41ba, 0x4240, 0x428d, 0x429a, 0x4269, 0x4200, 0x416b, 0x40bb,
0x3fff, 0x3f47, 0x3eaa, 0x3e2f, 0x3de3, 0x3dcb, 0x3de7, 0x3e36,
0x3eac, 0x3f3d, 0x3fde, 0x407b, 0x4108, 0x417b, 0x41c5, 0x41e6,