Skip to content

Instantly share code, notes, and snippets.

View Bananattack's full-sized avatar

Andrew G. Crowell Bananattack

View GitHub Profile
@Bananattack
Bananattack / variant.h
Last active February 27, 2016 22:17
a C++14 single-header variant type. Allows defining type-safe tagged unions with pattern-matching/visiting. probably has some implementation mistakes. Might use this for wiz, my high-level assembly language project.
#ifndef WIZ_VARIANT_H
#define WIZ_VARIANT_H
#include <cstddef>
#include <type_traits>
#include <utility>
namespace wiz {
template<std::size_t... Ns>
struct max_value;
@Bananattack
Bananattack / Instructions - Pico8 Sublime.md
Last active February 5, 2021 19:36
PICO-8 syntax highlighting and theme in Sublime Text 2.

PICO-8 in Sublime Text 2

Syntax Highlighting

  1. Open up your Packages folder by going Preferences >> Browse Packages...
  2. Create a new folder named "Pico8"
  3. Save the Pico8.tmLanguage file there.

Color Scheme

@Bananattack
Bananattack / readme_zoom2x.md
Last active May 21, 2016 21:13
A two-pass paletted pixel-scaling algorithm that uses weighting counting of adjacent colors and a fitness function (for tie-breaking) to create a 2x scale image. This is not an efficient implementation, just a quick-and-dirty proof of concept.

The "zoom2x" algorithm

by Andrew G. Crowell

A two-pass paletted pixel-scaling algorithm that uses weighting counting of adjacent colors and a fitness function (for tie-breaking) to create a 2x scale image.

This is not an efficient implementation, just a quick-and-dirty proof of concept. So it is mainly useful for offline rendering right now, but a few optimizations to create less temporary memory and it could be made pretty quick. In particular, the best_sample function will create a dictionary every call, resulting in a lot of garbage. This algorithm could directly work on an indexed image instead and then the weight array be a fixed-length array that is the size of the image color palette (possibly 16 or 256-color or whatever) that's shared between calls and just cleared before use, and then this should result in way fewer allocations. Also somebody could write it in a systems language like C++ or Rust instead of Python -- which would also help a lot, and hopefully wouldn't be too bad to port.

Tu

@Bananattack
Bananattack / inputdemo.asm
Created June 24, 2016 07:00
p80 - A virtual machine for pico8. Mainly just a proof of concept to test ideas to get around pico-8 size limitations.
; Example: move a sprite with buttons (drawn externally during yield)
b0 EQU $0000
b1 EQU $0001
b2 EQU $0002
b3 EQU $0003
b4 EQU $0004
b5 EQU $0005
b6 EQU $0006
b7 EQU $0007
b8 EQU $0008
@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>
@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 / 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 / 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 / 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 / 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>