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 / perlin.cpp
Created January 9, 2018 00:45
Perlin noise generator
#include <SDL/SDL.h>
#include <array>
#include <memory>
#include <assert.h>
namespace {
// min value
template <typename type_t>
constexpr type_t minv(type_t a, type_t b)
{
@bit-hack
bit-hack / intersect.c
Last active January 15, 2018 00:11
2d interval insersection for isometric water-land computation
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
float constexpr lerp(float a0, float a1, float i) {
return a0 + (a1 - a0) * i;
}
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
void intersect(float a0, float a1, float b0, float b1, vec2f_t &out) {
#if 1
const float i = (a0 - b0) / (a0 - a1 - b0 + b1);
@bit-hack
bit-hack / bit_get_set.cpp
Created January 3, 2018 17:33
Helpers for getting and setting bit ranges
#include <cstdint>
namespace {
template <int hi, int lo>
constexpr uint32_t mask() {
// hi_mask xor lo_mask
return ((1u << hi) | ((1u << hi) - 1u)) ^ ((1u << lo) - 1u);
}
template <int hi, int lo>
@bit-hack
bit-hack / devirtual.cpp
Created December 20, 2017 14:45
de-virtual
#include <stdlib.h>
struct base_t {
const int type;
base_t() : type(0) {}
base_t(int type) : type(type) {}
virtual int call() { return 1; }
};
struct derived_t : public base_t {
@bit-hack
bit-hack / 80186.txt
Last active November 23, 2017 00:32
80186 instruction description file
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
# DATA TRANSFER
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
#
@ MOV, Move
/ Register to Register/Memory
% 2/12 + 4*w
$ 1000100w | mod reg r/m
/ Register/memory to register
@bit-hack
bit-hack / asm6502.cpp
Created November 11, 2017 22:26
6502 assembly tables
#include <stdint.h>
// operand format
enum {
OPR_IMM = 0,
OPR_ZP,
OPR_ZPX,
OPR_ZPY,
OPR_ABS,
OPR_ABSX,
@bit-hack
bit-hack / 6502.h
Created November 11, 2017 00:41
6502 tables for emulation / disassembly / assembly
#include <stdint.h>
// fourcc function
static constexpr
uint32_t fourcc(const char (&in)[4]) {
return ((in[0]<<24) | (in[1]<<16) | (in[3]<<8) | ' ');
}
// addressing mode types
enum {
@bit-hack
bit-hack / 6502net.h
Created November 8, 2017 23:13
Clean 6502 netlist for C++
/*
* 6502 netlist and pin descriptions
*
* Original author: Greg James
* Original source material: www.visual6502.org
**/
#pragma once
#include <cstdint>
@bit-hack
bit-hack / 6502.txt
Last active March 2, 2021 18:09
6502 - map of documented opcodes
OPCODE MNEMONIC OPERANDS FLAGS CYCLES LENGTH
0x00 BRK B 7 1
0x01 ORA (ind,X) SZ 6 2
0x05 ORA zpg SZ 3 2
0x06 ASL zpg SZC 5 2
0x08 PHP 3 1
0x09 ORA # SZ 2 2
0x0a ASL A SZC 2 1
0x0d ORA abs SZ 4 3
@bit-hack
bit-hack / xtea.h
Created October 31, 2017 13:44
xtea
#pragma once
#include <cstdint>
struct xtea_t
{
static const uint32_t _delta = 0x9E3779B9;
typedef uint32_t key_t[4];
template <uint32_t num_rounds>