Skip to content

Instantly share code, notes, and snippets.

@exelotl
exelotl / gba_save_type_checker.nim
Created July 3, 2020 19:20
GBA program that detects its own save type by searching for magic strings in ROM
asm """
.balign 4
.string \"SRAM_Vnnn\"
"""
import natu
irqInit()
irqEnable(II_VBLANK)
@exelotl
exelotl / mut.nim
Created June 28, 2020 00:06
idea for a macro that lets you safely mutate some deep field access
import macros
iterator mutIter[T](a: var T): var T =
yield a
macro mut(a, body: untyped) =
if a.kind != nnkInfix or a[0].strVal != "as":
error("Invalid first parameter to `mut`. Usage: `mut <expression> as <name>: <block>`", a)
let exp = a[1]
let name = a[2]
@exelotl
exelotl / gba_elf_map.txt
Last active March 8, 2022 22:25
Analysing the GBA .elf.map
Analysing the GBA .elf.map
--------------------------
The gba linker script can be found under
/opt/devkitPro/devkitARM/arm-none-eabi/lib/gba_cart.ld
This can be used to see which sections in the .elf go into which parts of memory on the GBA
ROM:
@exelotl
exelotl / gltfstrip.nim
Created March 12, 2020 14:49
Remove materials, textures and images from GLTF files
import docopt
import json
let doc = """
gltfstrip
Remove materials, textures and images from GLTF files
Usage:
gltfstrip [-b] <file>...
// ==UserScript==
// @name Nim Redirect to Latest Docs
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Redirect from "nim-lang.org" to the corresponding page on "nim-lang.github.io"
// @author exelotl
// @match https://nim-lang.org/docs/*
// @grant none
// ==/UserScript==
@exelotl
exelotl / watcher.nims
Created February 28, 2020 01:00
NimScript to rebuild JS on save and report errors in the browser.
import strformat, strutils
const main = "dlghelper.nim" # file to watch
const mainHtml = "index.html" # source web page
const outputHtml = "debug.html" # receive the contents of source web page, only if nothing went wrong.
proc sleep(seconds: float) =
exec("sleep {seconds}".fmt)
proc lastModified(file: string): float =
@exelotl
exelotl / compose.nim
Last active July 19, 2020 16:22
Macro to expose `foo.x` as a shorthand for `foo.bar.x`
import macros
macro compose*(t:typedesc, field:untyped) =
##
## Composition helper to expose subfields as if they belonged to the root type.
##
## E.g. allow `foo.x` as a shorthand for `foo.bar.x`
##
## **Parameters:**
##
@exelotl
exelotl / tonc-dark.user.css
Last active June 4, 2023 21:09
Dark theme for the Tonc GBA tutorial
/* ==UserStyle==
@name Tonc Dark
@namespace exelo.tl
@version 1.0.4
@description A dark theme for the Tonc GBA tutorial, based on Water.css
@updateURL https://gist.githubusercontent.com/exelotl/b6b1592a910ae7914e48fda14c593cd3/raw/tonc-dark.user.css
@author exelotl
==/UserStyle== */
@-moz-document url-prefix("https://www.coranac.com/tonc/text/"), url-prefix("https://coranac.com/tonc/text/"), url-prefix("http://www.coranac.com/tonc/text/"), url-prefix("http://coranac.com/tonc/text/") {
@exelotl
exelotl / gbatek-dark.user.css
Last active June 4, 2023 21:09
GBATEK dark theme
/* ==UserStyle==
@name GBATEK Dark
@namespace exelo.tl
@version 1.0.2
@description GBATEK dark userstyle based on Water.css
@updateURL https://gist.githubusercontent.com/exelotl/8bdb37470e16174f668a54be62094cef/raw/gbatek-dark.user.css
@author exelotl
==/UserStyle== */
@-moz-document url("http://problemkaputt.de/gbatek.htm"),
url("https://problemkaputt.de/gbatek.htm"),
@exelotl
exelotl / cgltf.nim
Created November 16, 2019 17:22
Nim bindings for cgltf - a single-file glTF 2.0 parser written in C99
# Nim bindings for cgltf - a single-file glTF 2.0 parser written in C99.
# Version: 1.3
# Website: https://github.com/jkuhlmann/cgltf
# See cgltf.h for license information
type
FileType* {.size: sizeof(cint), pure.} = enum
invalid
gltf