Skip to content

Instantly share code, notes, and snippets.

View Bananattack's full-sized avatar

Andrew G. Crowell Bananattack

View GitHub Profile
@Bananattack
Bananattack / CASTLEVANIA2 BELMONTS REVENGE.txt
Created July 9, 2019 00:39
wavedumper script for VBA-rr, along with some samples captured with it (incomplete dumps). public domain, use for whatever you want, no warranty/liability/etc.
CASTLEVANIA2 BEL
----------------
5 sample(s) captured.
Sample #1
---------
HEX:
@Bananattack
Bananattack / unique_ptr.h
Created May 22, 2019 18:10
A Unique Pointer-like type that gets ensures inlining of most operations, so they work much closer in performance to a raw pointer.
#ifndef WIZ_UNIQUE_PTR_H
#define WIZ_UNIQUE_PTR_H
#include <cstddef>
#include <type_traits>
#ifdef _MSC_VER
#define WIZ_FORCE_INLINE __forceinline
#elif defined(__clang__) || defined(__GNUC__)
#define WIZ_FORCE_INLINE __attribute__((always_inline))
// Linearly interpolate between two values using progress as weight between them.
//
// Arguments:
// b = start (0 .. 255)
// c = end (0 .. 255)
// e = progress (0 .. 64),
// 0 = 100% start, 0% end
// 32 = 50% start, 50% end
// 64 = 0% start; 100% end
//
@Bananattack
Bananattack / ai_wander.wiz
Last active April 17, 2018 04:36
Top-down NES demo in Wiz, using the current work-in-progress of the language. There are some weird things in here, but hopefully some revisions will iron out some of the strange stuff.
import "ram";
import "entity";
import "directions";
import "random";
namespace ai_wander {
const direction_wait_base : [u8] = [60];
const direction_wait_random : [u8] = [60];
const wander_speed_lo : [u8] = [128];
const wander_speed_hi : [u8] = [0];
@Bananattack
Bananattack / int128.h
Last active February 2, 2022 16:24
A signed 128-bit integer type. Internally stores its data in Two's Complement within two unsigned 64-bit integer parts. Still needs more testing, but basic implementation is fairly complete.
#ifndef WIZ_UTILITY_INT128_H
#define WIZ_UTILITY_INT128_H
#include <cassert>
#include <cstdint>
#include <cstddef>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <string>
@Bananattack
Bananattack / variant.h
Last active August 31, 2017 06:06
C++14 variant type. Table-based visitor dispatch with O(1) time complexity. Improvement over previous tail-recursive version https://gist.github.com/Bananattack/1e2d3bbbf80f9ab63779 -- Probably not as useful in C++17 which has std::variant, but still nice for slightly older compilers.
#ifndef WIZ_UTILITY_VARIANT_H
#define WIZ_UTILITY_VARIANT_H
#include <cstddef>
#include <cassert>
#include <type_traits>
#include <utility>
namespace wiz {
namespace detail {
@Bananattack
Bananattack / typechecker.hs
Last active April 24, 2017 02:39
dumping ground for compiler prototyping
-- This is a dumping ground for some ideas on how to implement compiler internals for wiz.
-- Right now does various transformations + checks on statements and expression trees.
-- It's mostly for me to prototype the type-checking and code-generation stuff.
-- I want to dig myself out of a corner with the language, and writing this in a high-level declarative way is kinda nice.
-- After I'm satisfied with how it roughly works, I want to port the implementation in C++
--
-- In particular, I wanted to know how to handle translating expression trees into
-- accumulated/in-place operations on registers, and forbidding any expressions with temporaries.
--
-- It turns out if an expression tree of left-associative operations branches only on the left side,
@Bananattack
Bananattack / vwf.asm
Created December 29, 2016 03:20
Game Boy variable width font library. Include and assemble in RGBDS homebrew projects. MIT license.
; Variable Width Font Library
;
; by Andrew G. Crowell (@eggboycolor)
;
; --
;
; Copyright (c) 2016 Andrew G. Crowell
;
; Permission is hereby granted, free of charge, to any person obtaining a copy of
; this software and associated documentation files (the "Software"), to deal in
@Bananattack
Bananattack / Arduboy Platformer Map Format.md
Created October 29, 2016 14:40
Map format for arduboy

Arduboy Platformer Map Format

braindump for planning a little sidescroller on the Arduboy

System Specs

  • 128x64 px screen
  • monochrome 1-bit color (strictly black and white)
  • ATmega32u4 16 MHz cpu
  • 2.5K RAM (~50% reserved by runtime libraries, huge chunk is screen buffer AFAICT, so we have less than NES)
@Bananattack
Bananattack / class_registry.h
Created October 10, 2016 02:43
class binding + deserialization
#ifndef CLASS_REGISTRY_H
#define CLASS_REGISTRY_H
// Uses sajson: https://github.com/chadaustin/sajson
#include "sajson.h"
#include <unordered_map>
#include <memory>
#include <limits>
#include <functional>