Skip to content

Instantly share code, notes, and snippets.

View bit-hack's full-sized avatar

Aidan Dodds bit-hack

View GitHub Profile
extern "C" void test();
#pragma comment(linker, "/alternatename:_test=??0CppLibraryClass@@QAE@XZ")
test(); // will call mangled name
@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