Skip to content

Instantly share code, notes, and snippets.

View adamsmasher's full-sized avatar

Adam Smith adamsmasher

View GitHub Profile
@adamsmasher
adamsmasher / reduce.py
Created April 11, 2016 22:14
The tokumaru reduction
import sys
from PIL import Image
# attempts to convert an image into a format that makes the most of the Sega Genesis graphics hardware
# i.e. 64 colours organized into 4 16-colour palettes, with each 8x8 tile using one palette
# based on an algorithm described by tokumaru on the NESdev forums
# see here: http://forums.nesdev.com/viewtopic.php?f=23&t=14073
BLOCK_SIZE = 8
PALETTE_COUNT = 4
(* based on Pottier and Conchon, Information
Flow Inference for Free *)
Require Import Autosubst.
(* as in the original paper, for now we leave
the set of labels entirely abstract *)
Inductive term {label : Set} : Type :=
| Const (k : nat)
@adamsmasher
adamsmasher / gist:1c5d779e37078f24d682
Last active August 29, 2015 14:04
LZSS (Sharp LR35902 ASM)
;; HL = src
;; DE = dest
Decompress::
.chunk LD A, [HLI] ; get flags
LD B, A ; put flags in B
LD C, 8 ; 8 commands per chunk
.command LD A, [HLI] ; get next byte
BIT 0, B ; is this flag hi?
JR NZ, .literal ; if so, we have a literal
AND A ; otherwise, check for EOF
@adamsmasher
adamsmasher / gist:5332949
Created April 7, 2013 22:55
Haskell Regex - Backtracking (...?)
import Control.Applicative
data Regex =
Literal Char
| Concat Regex Regex
| Altern Regex Regex
| Star Regex
match :: Regex -> String -> Bool
match r s = "" `elem` (consume r s)
@adamsmasher
adamsmasher / gist:5332909
Created April 7, 2013 22:48
Haskell Regex (NFA)
{-# LANGUAGE DoRec #-}
import Control.Monad.State
import Data.Set (Set)
import qualified Data.Set as Set
data Regex =
Literal Char
| Concat Regex Regex
| Altern Regex Regex
| Star Regex