Skip to content

Instantly share code, notes, and snippets.

@thentenaar
thentenaar / geos6fix.asm
Last active Aug 31, 2021
DOS 6+ Fix for PC/GEOS 1.x (and an example of an extremely simply file patcher.)
View geos6fix.asm
;
; 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 / gist:5227554
Last active Sep 12, 2017
Script for controlling the backlight in the ASUS G74SX
View gist:5227554
#!/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 / gist:4143585
Created Nov 25, 2012
C Implementatation of TI BASIC's RND function
View gist:4143585
/* 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 Nov 25, 2012
C Implementation of the TI's GPL RAND function
View gist:4143575
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 / gist:4142031
Created Nov 25, 2012
Disassembly of TI BASIC's RND function
View gist:4142031
4F00: ST @>834A,>3F ; Zero loop counter: >3F (63)
4F03: ST @>8310,>4B ; Number buffer address: >834B
4F06: RAND >63 ; Get a pseudo-random number (using 100 as the divisor)
4F08: CZ @>8378 ; If then number isn't zero, goto >4F16
4F0A: BR >4F16
4F0C: DEC @>834A ; Decrement the zero loop counter
4F0E: CZ @>834A ; If the zero loop counter is 0, goto >4F23 (return 0)
4F10: BS >4F23
4F12: BR >4F06 ; Otherwise, continue the loop
4F14: RAND >63 ; Get the next pseudo-random number
@thentenaar
thentenaar / gist:4142008
Created Nov 25, 2012
Disassembly of the TI's GPL RAND command
View gist:4142008
RAND:
LI R4,>6FE5 ; R4 = >6fe5
MPY @>83C0,R4 ; R4,R5 = R4 × @>83C0 (initially >3567 when BASIC loads)
AI R5,>7AB9 ; R5 += >7ab9
MOV *R5,@>83C0 ; R5 -> @>83C0
MOVB R13,R6 ; 'm' (>64 when called from BASIC) -> R6
SRL R6,8 ; R6 & 0xff
INC R6 ; R6++ (prevent division by zero)
CLR R4 ; R4 = 0
@thentenaar
thentenaar / ti-prng.c
Created Nov 25, 2012
Implementation of TI Basic's PRNG
View ti-prng.c
/**
* 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