Skip to content

Instantly share code, notes, and snippets.

@thentenaar
thentenaar / ti-prng.c
Created November 25, 2012 01:12
Implementation of TI Basic's PRNG
/**
* Implementation of the TI BASIC PRNG
*
* Copyright (C) 2009, Tim Hentenaar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
@thentenaar
thentenaar / gist:4143585
Created November 25, 2012 13:52
C Implementatation of TI BASIC's RND function
/* Equivalent to PRINT RND in TI Basic */
char *rnd() {
uint8_t rnds[7]; int i; char *n;
/* Try up to 64 times to come up with a non-zero pseudo-random integer */
for (i=0;i<63;i++) if ((rnds[0] = gpl_rand(100)) != 0) break;
if (rnds[0] == 0) return strdup("0");
/* Generate the rest of the set */
for (i=1;i<7;i++) rnds[i] = gpl_rand(100);
@thentenaar
thentenaar / gist:4143575
Created November 25, 2012 13:49
C Implementation of the TI's GPL RAND function
static uint16_t seed;
/* RAND: Generate an 8-bit pseudo-random number */
uint8_t gpl_rand(uint8_t divisor) {
/* Update the seed */
seed = ((uint32_t)(seed * 0x6fe5) & 0xffff) + 0x7ab9;
/* Swap bytes, and compute modulus */
return ((((seed & 0xff00) >> 8 ) | ((seed & 0x00ff) << 8 )) % (!divisor ? 1 : divisor));
}
@thentenaar
thentenaar / dn3dwt-eduke32.patch
Last active October 14, 2016 20:47
eDuke32 Patch for Duke Nukem 3D: World Tour
This patches the config files shipped with Duke Nukem World Tour so that
the levels should be playable with eduke32. There don't seem to be any
ogg sound effects for Duke's breathing, or the turret sounds, so I've
restored the original filename from Atomic Edition.
I've corrected the pathnames to use '/' as a separator, and altered the
case so that the filenames coincide with the actual filenames in the
sound directory.
I've removed the stuff specific to the 'playback' functionality as
@thentenaar
thentenaar / gist:5227554
Last active September 12, 2017 14:16
Script for controlling the backlight in the ASUS G74SX
#!/bin/bash
#
# Brightness script for the ASUS G74SX
#
# Arguments:
# up - increase brightness by 1
# down - decrease brightness by 1
#
BRIGHTNESS=`cat /sys/devices/platform/asus-nb-wmi/leds/asus\:\:kbd_backlight/brightness`
@thentenaar
thentenaar / add_to_calcurse.sh
Last active April 8, 2020 20:14
A simple script for importing text/calendar files into calcurse
#!/bin/bash
#
# Import text/calendar files from mutt
# to calcurse.
#
# Make sure calcurse is running
if [ ! -f "$HOME/.calcurse/.calcurse.pid" ]; then
exit 1
fi
@thentenaar
thentenaar / geos6fix.asm
Last active August 31, 2021 09:41
DOS 6+ Fix for PC/GEOS 1.x (and an example of an extremely simply file patcher.)
;
; DOS 6+ Fix for PC/GEOS 1.x
; (and an example of an extremely simply file patcher)
;
; Copyright (C) 2013 Tim Hentenaar, http://hentenaar.com
; All rights reserved.
;
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions are met:
;
@thentenaar
thentenaar / lmc.bas
Last active March 27, 2024 14:54
Simple TI 99/4a XB Little Man Computer + Line Assembler
1 REM Simple XB Little Man Computer + Line Assembler
2 REM Copyright (C) 2021 Tim Hentenaar.
3 REM This code is licenced under the Simplified BSD License.
4 REM https://opensource.org/license/bsd-2-clause
10 DIM MEM(100) ! Mailboxes (memory)
20 DIM MPOS(100,2) ! Screen positions for mailbox values
30 PC,IR,AR,A,N,H,IN,OUT=0
40 GOTO 50 :: I :: K :: S :: OP :: L$ :: CALL CLEAR :: CALL HCHAR :: CALL VCHAR :: CALL KEY :: CALL COLOR :: !@P-
50 FOR I = 0 TO 99