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 / x86_branch.c
Created October 24, 2017 15:11
x86 branch emulation and fuzz test code
// ______ ________ __________,_ ___________
// ___ ___/ __ \/ _____/ \_ _____/ | _____ ____ ______\_ _____/_____ __ __
// \ \/ /> / __ \ | __)| | \__ \ / ___\/ ___/ | __)_/ \| | \
// > </ -- \ |__\ \ | | | |__/ __ \_/ /_/ >___ \ | \ Y Y \ | /
// / /\ \_______/\_______/ \____/ |____(______/\___ /_____/ /_________/_|_|__/____/
// \_/ \_/ ..:: x86 flags emulator ::.. /_____/
// '' Aidan Dodds 2017 ''
#include <assert.h>
#include <stdint.h>
@bit-hack
bit-hack / cparser_ra.cpp
Created September 25, 2017 13:16
Auto generated recursive ascent parser skeleton
// Auto Generated From ANSI C BNF using grammar adapted from Section A13 of The
// C programming language, 2nd edition, by Brian W. Kernighan and Dennis M.
// Ritchie, Prentice Hall, 1988.
#include <cassert>
#include <array>
#include <vector>
struct ast_node_t {};
bool match(int index, int token);
@bit-hack
bit-hack / cparser.cpp
Last active September 21, 2017 09:25
ANSI C Recursive Decent Parser generated from BNF
// Auto Generated From ANSI C BNF using grammar adapted from Section A13 of The
// C programming language, 2nd edition, by Brian W. Kernighan and Dennis M.
// Ritchie, Prentice Hall, 1988.
struct state_t {};
bool lexer_found(const char *);
state_t state_save();
void state_restore(state_t&);
bool parse_integer_constant();
bool parse_character_constant();
@bit-hack
bit-hack / sdl_framework.cpp
Last active August 1, 2017 11:33
Minimal SDL 1 app skeleton
struct Framework {
Framework()
: _screen(NULL)
{
}
bool init(uint32_t w, uint32_t h)
{
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
@bit-hack
bit-hack / tagval.h
Created July 28, 2017 16:48
Example tagged type structure
#ifndef TAGVAL_H__
#define TAGVAL_T__
#include <typeinfo>
struct tagval_t {
tagval_t(int v): type_(typeid(int)), int_(v) {}
tagval_t(float v): type_(typeid(float)), float_(v) {}
tagval_t(const char *v): type_(typeid(const char *)), cstr_(v) {}
@bit-hack
bit-hack / thread-winmm.cpp
Created July 27, 2017 09:41
Threaded winmm audio playback
#include <array>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <Windows.h>
#define MMOK(EXP) ((EXP) == MMSYSERR_NOERROR)
struct WaveInfo {
@bit-hack
bit-hack / poll-winmm.cpp
Created July 27, 2017 00:14
polling winmm playback
#include <array>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <Windows.h>
#define WAVE_RATE 44100
#define WAVE_SAMPLES 1024
#define WAVE_CHANNELS 2
@bit-hack
bit-hack / Win32Blit.cpp
Last active July 25, 2017 20:53
Direct Window Pixel Blitting
#include <cassert>
#include <string>
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
typedef unsigned int uint;
struct GDIDetail {
@bit-hack
bit-hack / CMakeLists.txt
Last active July 23, 2017 23:02
Nice Recursive CMake globbing
project(residualvm)
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
# recursively glob files
#
file(GLOB_RECURSE _FILES "*.cpp" "*.h")
# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
# file exclusion step
#
@bit-hack
bit-hack / heaparray.cpp
Created July 22, 2017 00:52
heap allocated array wrapper
#pragma once
#include <memory>
#include <cstddef>
template <typename type_t>
struct dynarray_t {
dynarray_t(size_t elements)
: _elements(elements)
, _array(std::move(std::make_unique<type_t[]>(elements)))
{