Skip to content

Instantly share code, notes, and snippets.

@EllipticEllipsis
EllipticEllipsis / make_file_function_calls_graph.sh
Last active July 30, 2021 23:42
Finds all mentions of functions in z_sub_s in code. Can easily modify it to look at overlays or other directories, and use other files, and makes graphviz-compatible output
#!/bin/bash
# with quotes
while read line ; do grep -Fr "$line" asm/non_matchings/code ; done < <(find asm/non_matchings/code/z_sub_s/ -type f -exec basename {} .s \;) | grep -v 'glabel' | awk -F':|\\s+' '/%lo/ { next } /%hi/ { type="hilo" } /jal/ { type="jal" } { filefunc=gensub(/.*\/(.*)\/(.*)\.s/,"\\1,\\2","g",$1) ; gsub(/%hi\(|\)/,"") ; print filefunc","$NF","type } ' | awk -F, 'BEGIN { printf "digraph {\ncompound=true;\n\n" } { arr[$1] = arr[$1]" \""$2"\"" ; print "\""$2"\" -> \""$3"\"" } END { print "" ; for (file in arr) { print "subgraph cluster_"file" {" ; print arr[file]";" ; printf " style = filled;\n label = \"%s\";\n}\n\n" , file } print "}" }'
# without quotes
# while read line ; do grep -Fr "$line" asm/non_matchings/code ; done < <(find asm/non_matchings/code/z_sub_s/ -type f -exec basename {} .s \;) | grep -v 'glabel' | awk -F':|\\s+' '/%lo/ { next } /%hi/ { type="hilo" } /jal/ { type="jal" } { filefunc=gensub(/.*\/(.*)\/(.*)\.s/,"\\1,\\2","g",$1) ; gsub(/%hi\(|\)/,"") ; print filefunc","$NF
while read version ; do xxd -u -c4 -ps $version/ovl_Bg_Spot17_Bakudankabe | awk -v version=$version 'BEGIN { gsub(/baserom_/,"",version) ; printf("%12s\t",version) ; flag=2} flag && /^0C/ { printf("%X ",lshift(strtonum("0x"$0)-0x0C000000,2)+0x80000000) ; flag-- } END { print"" }' ; done < <( find baserom_* -type d )
@EllipticEllipsis
EllipticEllipsis / boot_bss_reorder_check
Created August 8, 2021 21:20
Check for reorderings in MM boot bss
echo "Symbol Name,Build,Expected,Status,Difference" ; awk 'NF==2 && 0x80099500 <= strtonum($1) && strtonum($1) < 0x8009f8b0 { arr[$2]=arr[$2]","strtonum($1) } END { for ( i in arr ) { printf "%s%s\n", i,arr[i] } }' build/mm.map expected/build/mm.map | sort -t , -k 3,3 | awk -F',' 'NF!=3 {print $0,"Symbol missing: renamed?"} NF==3 { printf "%s,%X,%X,%s,%s0x%X\n", $1,$2,$3,( $2==$3 ? "GOOD" : "BAD" ),( $2<$3 ? "-" : "" ), ( $2 < $3 ? $3-$2 : $2-$3 ) }'
@EllipticEllipsis
EllipticEllipsis / float_conv.c
Last active August 17, 2021 16:50
Converts a float representation to its internal IEEE-754 hex representation, or a hex representation to its least precise accurate decimal float representation ("accurate" meaning that it translates back to the correct hex)
#include <stdio.h>
#include <stdint.h>
#include <math.h>
#include <assert.h>
typedef union {
float f;
int32_t h;
} FloatHex;
@EllipticEllipsis
EllipticEllipsis / smAll dungeons.md
Last active February 24, 2022 21:11
A brief(ish) introduction to the default actor scaling code used in OoT that is edited using SRM to produce a smaller Link.

A very brief introduction to OoT's actor scaling code

We would like to understand this snippet of assembly code from OoT 1.2, in which we change the second 3C to a 3B to make Link small for smAll dungeons shenanigans:

...
/* 00FF78 80021658 3C053C23 */  lui         $a1, (0x3C23D70A >> 16)
/* 00FF7C 8002165C 34A5D70A */  ori         $a1, $a1, (0x3C23D70A & 0xFFFF)
/* 00FF80 80021660 0C008572 */  jal         Actor_SetScale
/* 00FF84 80021664 02002025 */   move       $a0, $s0
@EllipticEllipsis
EllipticEllipsis / osteologist.py
Created February 26, 2022 00:26
Tool for viewing limb details and tree structure for Zelda64 skeletons. Supports all currently understood types
#!/usr/bin/env python3
import argparse
import dataclasses
import struct
import sys
import typing
@dataclasses.dataclass
class StandardLimb:
jointPosX: int
@EllipticEllipsis
EllipticEllipsis / scale_floats.c
Created March 16, 2022 23:29
Program to attempt to figure out the multiplication by a power of 10 that gives a particular float.
#include <stdint.h>
#include <stdio.h>
#define ARRAY_COUNT(arr) (sizeof(arr) / sizeof(arr[0]))
// Test values for 0.05f
// float test_mult[] = {
// 5.0e-06f * 10000.0f, 5.0e-05f * 1000.0f, 0.0005f * 100.0f, 0.005f * 10.0f, 0.05f * 1.0f,
// 0.5f * 0.1f, 5.0f * 0.01f, 50.0f * 0.001f, 500.0f * 0.0001f,
// };
@EllipticEllipsis
EllipticEllipsis / flags.py
Created March 19, 2022 01:29
Convert a raw number into flag defines
#!/usr/bin/env python3
import argparse
from typing import List
import dataclasses # cursed
@dataclasses.dataclass
class Flag:
mask: int
@EllipticEllipsis
EllipticEllipsis / converting.md
Last active January 21, 2023 01:10
Converting a MIPS decompilation project to ABI FPR names

Converting a MIPS decompilation project to ABI FPR names

What?

If you've worked on a Nintendo 64 project, you're probably used to the floating-point registers in MIPS assembly being numbered, in a rather random-looking way, as the even numbers from 0-30. Some seem to be used for returns, some for arguments, some for temps, but there doesn't seem to be any much logic to it. And indeed there isn't, especially for the temp registers:

  • f0,f2 are return values (like v0,v1)
  • f12,f14 are function arguments (like a0,a1,...)
  • The other even-numbered ones are temporary and saved registers
  • Odd-numbered ones show up occasionally if doubles are about
@EllipticEllipsis
EllipticEllipsis / anglediv.md
Last active March 27, 2023 22:44
Integer division of 0x10000 by numbers up to 0x100
i 0x10000 / i
1 0x10000
2 0x8000
3 0x5555
4 0x4000
5 0x3333
6 0x2AAA
7 0x2492