Skip to content

Instantly share code, notes, and snippets.

View bvibber's full-sized avatar

Brooke Vibber bvibber

View GitHub Profile
; Round top 16 bits of 32-bit fixed-point number in-place with with the 17th bit down
; Note: does not shift! The top bits remain in the top two bytes.
;
; If 0 bit: 5 + 12 = 5 cycles
; If 1 bit: 5 + 5 + 21 + 3? = 28 cycles for positive, 31 for negative
;
; Average given even distribution of data:
; 5 / 2 + 28 / 4 + 31 / 4 = 2.5 + 7 + 7.75 = 17.25 cycles
;
; Note a 16-bit copy is:
@bvibber
bvibber / imul16.s
Last active December 31, 2022 02:24
imul16 for 6502
; Lightly tested work in progress; imul16 for 6502
; two 16-bit inputs, one 32-bit output
; using the Atari floating point registers as argument placeholders
; ca65 syntax
; brion vibber, 2022
; FP registers in zero page
FR0 = $d4
FRE = $da
FR1 = $e0
@bvibber
bvibber / Makefile
Last active September 26, 2022 16:44
F16C test code from gtk4
.PHONY : clean
borf : borf.c Makefile
gcc -o borf -mf16c borf.c
clean :
rm -f borf
@bvibber
bvibber / monitor.js
Created August 12, 2022 15:17
Calculate ideal viewing distance such that in-game FOV matches angular size in player's vision
// Calculate ideal viewing distance such that
// in-game FOV matches angular size in player's
// vision.
// 34" 21:9 "ultrawide"
// approx 90-degree horizontal FOV in MSFS
distance({
h_px: 3440,
v_px: 1440,
diagonal_in: 34,
@rem Tone-map HDR game captures to SDR suitable for further processing or posting.
@rem Input file: something.mp4 (HEVC HDR 10-bit BT2020)
@rem Output file: something-sdr.mp4 (H.264 SDR 8-bit BT709)
ffmpeg -i "%~f1" ^
-vf "zscale=t=linear:p=bt709,tonemap=hable,zscale=t=bt709:m=bt709:r=tv,format=yuv420p" ^
-crf 12 ^
-y "%~n1-sdr.mp4"

Integer-indexed arrays:

This is an in-order binary tree, where the tree nodes directly contain the items.

The bigger an array gets, the slower lookups will get in it but they'll be fairly consistent for a given size. Iterating the tree is faster than individually looking up indexes in turn.

The array-bits is the number of "hash" bits used to traverse the tree with 16-bit integer index keys. The array-length is the highest index inserted so far plus one; when it exceeds 2^array-bits, add a layer to the tree and move the old tree into the left hand. Start traversals with the most significant bit within the hash size for proper ordering.

Note that the object exposes a string-indexed property tree too, here elided into a single property descriptor for length, which mirrors the internal 16-bit length with a JS number.

diff --git a/resources/ext.tmh.OgvJsSupport.js b/resources/ext.tmh.OgvJsSupport.js
index 3ee84110..827ba16d 100644
--- a/resources/ext.tmh.OgvJsSupport.js
+++ b/resources/ext.tmh.OgvJsSupport.js
@@ -86,21 +86,28 @@
* @return {boolean}
*/
isMediaNativelySupported: function ( mediaElement ) {
- var mediaType;
var supportedNatively = false;
@bvibber
bvibber / gc-sweep.s
Last active May 9, 2022 08:16
Quick sketch of a minimal sweep function for a 6502 retro computing GC implementation with fixed-size LISP-style nodes
; Note fixed addresses are illustrative, not real
.org $4000
; Zero page variables
scratch1 = $80
scratch2 = $82
freelist = $84 ; ref to next free node
gc_color = $86 ; current representation of "white" for tricolor marking
heap_start = $8000
@bvibber
bvibber / run-rav1e.sh
Created February 9, 2022 21:57
run-rav1e.sh
# currently broken in the 2-pass settings?
INFILE="$1"
FILE_HEIGHT=`ffprobe -hide_banner -show_entries stream=height -of csv=p=0:s=x "$INFILE"`
function ffmpeg() {
LD_LIBRARY_PATH=/opt/ffmpeg/lib /opt/ffmpeg/bin/ffmpeg "$@"
}
function run() {
@bvibber
bvibber / cursed-switch.js
Created December 29, 2021 01:13
cursed-switch.js
var key = true;
switch ( key ){ // Earth
case ( altitude <= 36152. ): // Altitude is in feet // Troposphere
temperature = 518.6 - 3.56 * ( altitude / 1000. );
break;
case ( altitude >= 36152. && altitude <= 82345. ): // Stratosphere
temperature = 389.98;
break;